From e7b6de334f320429462a0257e2191ccf3cbc9a0d Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 24 Jan 2024 15:36:49 -0800 Subject: [SPIRV] Support `globallycoherent` and `[vk::index()]`. (#3488) * [SPIRV] Support `globallycoherent` modifier. * Fix. * Disable executable cooperative vector tests. * Update expected failure. * [SPIRV] Emit varying output index decoration. * Add test. * Update tests. * Fix test. * Emit `SpvExecutionModeEarlyFragmentTests`. * Lower `StructuredBuffer`. * Support globallycoherent on ByteAddressBuffer. --------- Co-authored-by: Yong He --- tests/spirv/coherent-2.slang | 15 +++++++++++++++ tests/spirv/coherent.slang | 20 ++++++++++++++++++++ tests/spirv/varying-out-index.slang | 25 +++++++++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 tests/spirv/coherent-2.slang create mode 100644 tests/spirv/coherent.slang create mode 100644 tests/spirv/varying-out-index.slang (limited to 'tests/spirv') diff --git a/tests/spirv/coherent-2.slang b/tests/spirv/coherent-2.slang new file mode 100644 index 000000000..cd7eab8c3 --- /dev/null +++ b/tests/spirv/coherent-2.slang @@ -0,0 +1,15 @@ +// Test that globallycoherent works on arrays of uavs. + +//TEST:SIMPLE(filecheck=CHECK): -target spirv -stage compute -entry main -emit-spirv-directly + +globallycoherent RWByteAddressBuffer buffer[]; + +RWStructuredBuffer output; +[numthreads(4,1,1)] +void main(int tid : SV_DispatchThreadID) +{ + buffer[NonUniformResourceIndex(0)].InterlockedAdd(0, 1); + AllMemoryBarrier(); + output[tid] = buffer[0].Load(0); + // CHECK-DAG: OpDecorate %buffer Coherent +} diff --git a/tests/spirv/coherent.slang b/tests/spirv/coherent.slang new file mode 100644 index 000000000..ba58b713b --- /dev/null +++ b/tests/spirv/coherent.slang @@ -0,0 +1,20 @@ +// Test that globallycoherent works. + +//TEST:SIMPLE(filecheck=CHECK): -target spirv -stage compute -entry main -emit-spirv-directly + +struct S +{ + globallycoherent int member; +} +globallycoherent RWStructuredBuffer buffer; + +RWStructuredBuffer output; +[numthreads(4,1,1)] +void main(int tid : SV_DispatchThreadID) +{ + InterlockedAdd(buffer[0].member, 1); + AllMemoryBarrier(); + output[tid] = buffer[0].member; + // CHECK-DAG: OpMemberDecorate {{.*}} 0 Coherent + // CHECK-DAG: OpDecorate %buffer Coherent +} diff --git a/tests/spirv/varying-out-index.slang b/tests/spirv/varying-out-index.slang new file mode 100644 index 000000000..6448f2266 --- /dev/null +++ b/tests/spirv/varying-out-index.slang @@ -0,0 +1,25 @@ +// Test that explicit binding of varying output works. + +//TEST:SIMPLE(filecheck=CHECK): -stage fragment -entry MainPS -target spirv -emit-spirv-directly + +struct PS_OUTPUT +{ + [[vk::location(0) vk::index(0)]] + float4 vColor : SV_Target0 ; + + [[vk::location(0) vk::index(1)]] + float4 vColor2 : SV_Target1 ; + +}; + +// CHECK: OpDecorate %MainPS_vColor Location 0 +// CHECK: OpDecorate %MainPS_vColor2 Location 0 +// CHECK: OpDecorate %MainPS_vColor2 Index 1 + +PS_OUTPUT MainPS() +{ + PS_OUTPUT output; + output.vColor = float4(1.0f, 0.0f, 0.0f, 1.0f); + output.vColor2 = float4(0.0f, 1.0f, 0.0f, 1.0f); + return output; +} -- cgit v1.2.3