diff options
| author | ArielG-NV <159081215+ArielG-NV@users.noreply.github.com> | 2024-07-30 23:04:08 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-30 20:04:08 -0700 |
| commit | 04e7327a2067c82db3eaef51955f211e148ac933 (patch) | |
| tree | 8a8320db5165e280efb2fdb9aa4ecd078d380c72 /tests | |
| parent | fef0a87ddee9c0f252a6625395b684b1cb5d85e0 (diff) | |
Move SPIRV global variables into a context variable (#4741)
Diffstat (limited to 'tests')
9 files changed, 292 insertions, 4 deletions
diff --git a/tests/bugs/spirv-opt-SROA-of-globals.slang b/tests/bugs/spirv-opt-SROA-of-globals.slang new file mode 100644 index 000000000..140559b4f --- /dev/null +++ b/tests/bugs/spirv-opt-SROA-of-globals.slang @@ -0,0 +1,37 @@ +//TEST:SIMPLE(filecheck=CHECK): -target spirv -fvk-use-entrypoint-name -enable-experimental-passes + +// This test checks that spirv-opt is running SROA (scalar replacement of aggregates) to +// hoist out all member variables of a struct. If this sucsessfully runs, we should not see +// any `OpCompositeConstruct` of our `%Data` struct. +// Note: SROA will only run for 100 elements if spirv-opt does not manually set the spirv-opt `scalar-replacement` option + +//CHECK-NOT: OpCompositeConstruct %Data +struct Data +{ + uint data0; + uint data1; + uint data2; +}; + +static Data globalVar; +ByteAddressBuffer bab; +RWStructuredBuffer<uint> outputBuffer; + +struct Payload_t +{ + uint dataOut; +}; + +[shader("anyhit")] +void main1(inout Payload_t payload) +{ + globalVar = bab.Load<Data>(0); + payload.dataOut = globalVar.data0; +} + +[shader("anyhit")] +void main2(inout Payload_t payload) +{ + globalVar = bab.Load<Data>(0); + payload.dataOut = globalVar.data0; +}
\ No newline at end of file diff --git a/tests/spirv/address-space-specialize.slang b/tests/spirv/address-space-specialize.slang index e2b48489a..f8201838b 100644 --- a/tests/spirv/address-space-specialize.slang +++ b/tests/spirv/address-space-specialize.slang @@ -1,3 +1,4 @@ +//TEST:SIMPLE(filecheck=CHECK_EXPERIMENTAL):-target spirv -entry main -stage compute -emit-spirv-directly -O0 -enable-experimental-passes //TEST:SIMPLE(filecheck=CHECK):-target spirv -entry main -stage compute -emit-spirv-directly -O0 // Test that we can pass arguments in different address space to an `inout` parameter, and have @@ -7,6 +8,12 @@ static int gArray0[2]; groupshared int gArray1[2]; +// Note: static globals are inside a context variable +// CHECK_EXPERIMENTAL: OpTypeArray %int %int_2 +// CHECK_EXPERIMENTAL: OpVariable %_ptr_Function__arr_int_int_2 Function +// CHECK_EXPERIMENTAL: %array_0 = OpFunctionParameter %_ptr_Workgroup__arr_int_int_2 + + // CHECK: %array = OpFunctionParameter %_ptr_Private__arr_int_int_2 // CHECK: %array_0 = OpFunctionParameter %_ptr_Workgroup__arr_int_int_2 diff --git a/tests/spirv/explicit-context-validation-builtin-compute-glsl.slang b/tests/spirv/explicit-context-validation-builtin-compute-glsl.slang new file mode 100644 index 000000000..9fb0947ae --- /dev/null +++ b/tests/spirv/explicit-context-validation-builtin-compute-glsl.slang @@ -0,0 +1,19 @@ +//TEST:SIMPLE(filecheck=CHECK): -allow-glsl -target spirv -emit-spirv-directly -stage compute -entry computeMain -enable-experimental-passes + +// Check to ensure builtin is not moved into a kernelContext (part of entry-point). Ensure builtin is referenced directly. + +// CHECK: OpEntryPoint {{.*}} %gl_NumWorkGroups +// CHECK: OpDecorate %gl_NumWorkGroups BuiltIn NumWorkgroups +// CHECK: %gl_NumWorkGroups = OpVariable {{.*}} Input +// CHECK: %[[NUM_WORK_GROUP_LOAD:[A-Za-z0-9_]+]] = OpLoad %v3uint %gl_NumWorkGroups +// CHECK: OpCompositeExtract %uint %[[NUM_WORK_GROUP_LOAD]] 0 + +RWStructuredBuffer<uint> outputBuffer; + +layout(local_size_x = 32, local_size_y = 1, local_size_z = 1) in; +void computeMain() +{ + outputBuffer[0] = gl_NumWorkGroups.x; + outputBuffer[1] = gl_NumWorkGroups.y; + outputBuffer[2] = gl_NumWorkGroups.z; +}
\ No newline at end of file diff --git a/tests/spirv/explicit-context-validation-builtin-compute-hlsl.slang b/tests/spirv/explicit-context-validation-builtin-compute-hlsl.slang new file mode 100644 index 000000000..24184c9f4 --- /dev/null +++ b/tests/spirv/explicit-context-validation-builtin-compute-hlsl.slang @@ -0,0 +1,16 @@ +//TEST:SIMPLE(filecheck=CHECK): -target spirv -emit-spirv-directly -stage compute -entry computeMain -enable-experimental-passes + +// Check to ensure builtin is not moved into a kernelContext (part of entry-point). Ensure builtin is referenced directly. + +// CHECK: OpEntryPoint {{.*}} %gl_GlobalInvocationID +// CHECK: OpDecorate %gl_GlobalInvocationID BuiltIn GlobalInvocationId +// CHECK: %gl_GlobalInvocationID = OpVariable {{.*}} Input +// CHECK: %[[NUM_WORK_GROUP_LOAD:[A-Za-z0-9_]+]] = OpLoad %v3uint %gl_GlobalInvocationID +// CHECK: OpCompositeExtract %uint %[[NUM_WORK_GROUP_LOAD]] 0 + +RWStructuredBuffer<uint> outputBuffer; +[numthreads(1, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + outputBuffer[dispatchThreadID.x] = 1; +}
\ No newline at end of file diff --git a/tests/spirv/explicit-context-validation-builtin-vertex-glsl.slang b/tests/spirv/explicit-context-validation-builtin-vertex-glsl.slang new file mode 100644 index 000000000..8e37d4814 --- /dev/null +++ b/tests/spirv/explicit-context-validation-builtin-vertex-glsl.slang @@ -0,0 +1,35 @@ +//TEST:SIMPLE(filecheck=CHECK): -allow-glsl -target spirv -emit-spirv-directly -stage vertex -entry vertexMain -enable-experimental-passes + +// Check to ensure varying output/input and builtin is not moved into a kernelContext (part of entry-point). Ensure varying output/input and builtin is referenced directly. + +// CHECK: OpEntryPoint{{((.*)(%.*data1In|%.*data2In|%.*data1Out)(.*))|((.*)(%.*data1In|%.*data2In|%.*data1Out)(.*))|((.*)(%.*data1In|%.*data2In|%.*data1Out)(.*))}} + +//CHECK-DAG: OpDecorate %[[DATA_IN_1:.*data1In]] Location 1 +//CHECK-DAG: OpDecorate %[[DATA_IN_2:.*data2In]] Location 2 +//CHECK-DAG: OpDecorate %[[DATA_OUT_1:.*data1Out]] Location 0 +//CHECK-DAG: OpDecorate %gl_Position BuiltIn Position + +//CHECK-DAG: %[[DATA_IN_1]] = OpVariable{{.*}} Input +//CHECK-DAG: %[[DATA_IN_2]] = OpVariable{{.*}} Input +//CHECK-DAG: %[[DATA_OUT_1]] = OpVariable{{.*}} Output + +//CHECK-DAG: OpLoad{{.*}} %[[DATA_IN_1]] +//CHECK-DAG: OpLoad{{.*}} %[[DATA_IN_2]] + +//CHECK-DAG: OpStore %gl_Position +//CHECK-DAG: OpStore %[[DATA_OUT_1]] + +layout(location = 1) in vec4 data1In; +layout(location = 2) in int data2In; +layout(location = 0) out int data1Out; + +void nestedCall() +{ + gl_Position = data1In; + data1Out = data2In; +} + +void vertexMain() +{ + nestedCall(); +} diff --git a/tests/spirv/explicit-context-validation-groupshared.slang b/tests/spirv/explicit-context-validation-groupshared.slang new file mode 100644 index 000000000..7fb27377d --- /dev/null +++ b/tests/spirv/explicit-context-validation-groupshared.slang @@ -0,0 +1,30 @@ +//TEST:SIMPLE(filecheck=CHECK): -target spirv -emit-spirv-directly -stage compute -entry computeMain -enable-experimental-passes + +// Check to ensure builtin is not moved into a kernelContext (part of entry-point). Ensure builtin is referenced directly. + +// CHECK: OpEntryPoint{{.*}} %val +// CHECK: %[[GROUP_SHARED_VAR:(.*)]] = OpVariable{{.*}} Workgroup + +// CHECK: OpControlBarrier +// CHECK: OpControlBarrier +// CHECK-DAG: %[[GROUP_SHARED_VAL:(.*)]] = OpLoad{{.*}} %[[GROUP_SHARED_VAR]] +// CHECK-DAG: %[[OUTPUT_BUFFER_LOC:(.*)]] = OpAccessChain{{.*}} %outputBuffer +// CHECK: OpStore %[[OUTPUT_BUFFER_LOC]] %[[GROUP_SHARED_VAL]] + +groupshared uint val; +RWStructuredBuffer<uint> outputBuffer; + +void nestedCall(uint index) +{ + val += 1; + GroupMemoryBarrierWithGroupSync(); + outputBuffer[index] = val; +} + +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + val = 0; + GroupMemoryBarrierWithGroupSync(); + nestedCall(dispatchThreadID.x); +}
\ No newline at end of file diff --git a/tests/spirv/explicit-context-validation-raytracing-glsl.slang b/tests/spirv/explicit-context-validation-raytracing-glsl.slang new file mode 100644 index 000000000..1e7b56a9f --- /dev/null +++ b/tests/spirv/explicit-context-validation-raytracing-glsl.slang @@ -0,0 +1,78 @@ +//TEST:SIMPLE(filecheck=CHECK): -allow-glsl -target spirv -emit-spirv-directly -stage raygeneration -entry main -enable-experimental-passes + +// Check to ensure we make global ray-tracing objects. Ensure we store into these variables directly and not through a context-pointer. + +// CHECK-DAG: %[[RAYTRACING_AS_TYPE:[A-Za-z0-9_]+]] = OpTypeAccelerationStructureKHR +// CHECK-DAG: %[[RAYTRACING_AS_PTR_TYPE:[A-Za-z0-9_]+]] = OpTypePointer UniformConstant %[[RAYTRACING_AS_TYPE]] +// CHECK-DAG: %[[RAYTRACING_AS:[A-Za-z0-9_]+]] = OpVariable %[[RAYTRACING_AS_PTR_TYPE]] UniformConstant + +// CHECK-DAG: %[[RAY_PAYLOAD:[A-Za-z0-9_]+]] = OpVariable %{{.*}} RayPayloadKHR +// CHECK-DAG: %[[HIT_ATTR:[A-Za-z0-9_]+]] = OpVariable %{{.*}} HitObjectAttributeNV +// CHECK-DAG: %[[CALL_DATA:[A-Za-z0-9_]+]] = OpVariable %{{.*}} CallableDataKHR + + +// CHECK: OpLoad {{.*}} %[[RAYTRACING_AS]] +// CHECK: OpStore %[[RAY_PAYLOAD]] +// CHECK: OpStore %[[HIT_ATTR]] +// CHECK: OpStore %[[CALL_DATA]] + +layout(binding = 0) uniform accelerationStructureEXT as; + +buffer MyBlockName +{ + uint data[]; +} outputBuffer; +layout(location = 2) rayPayloadEXT vec4 payload; +layout(location = 2) hitObjectAttributeNV vec4 attrMain; +layout(location = 0) callableDataEXT vec4 outcall; + +bool testHitObjectTraceRay() { + hitObjectNV hit; + + + hitObjectTraceRayNV(hit, as, gl_RayFlagsNoneEXT, 0xff, 0, 0, 0, vec3(0.1, 0.1, 0.0), 0.01f, vec3(0, 0, 1), 1e4f, 2); + return true + && hitObjectIsHitNV(hit) == true + ; +} + + +bool testPayloadReadWrite() { + payload = vec4(2); + vec4 read = payload; + return true + && read != vec4(0) + ; +} + +bool testAttributeReadWrite() { + attrMain = vec4(2); + vec4 read = attrMain; + return true + && read != vec4(0) + ; +} + +bool testCallableReadWrite() { + outcall = vec4(2); + vec4 read = outcall; + return true + && read != vec4(0) + ; +} + +bool testReadWriteOfObjects(){ + return true + && testPayloadReadWrite() + && testAttributeReadWrite() + && testCallableReadWrite(); + ; +} + +void main() +{ + outputBuffer.data[0] = true + && testHitObjectTraceRay() + && testReadWriteOfObjects() + ; +} diff --git a/tests/spirv/explicit-context-validation-raytracing-hlsl.slang b/tests/spirv/explicit-context-validation-raytracing-hlsl.slang new file mode 100644 index 000000000..28420eeec --- /dev/null +++ b/tests/spirv/explicit-context-validation-raytracing-hlsl.slang @@ -0,0 +1,53 @@ +//TEST:SIMPLE(filecheck=CHECK): -target spirv -emit-spirv-directly -stage raygeneration -entry main -enable-experimental-passes + +// Check to ensure we make global ray-tracing objects. Ensure we store into these variables directly and not through a context-pointer. + +// CHECK-DAG: %[[RAYTRACING_AS_TYPE:[A-Za-z0-9_]+]] = OpTypeAccelerationStructureKHR +// CHECK-DAG: %[[RAYTRACING_AS_PTR_TYPE:[A-Za-z0-9_]+]] = OpTypePointer UniformConstant %[[RAYTRACING_AS_TYPE]] +// CHECK-DAG: %[[RAYTRACING_AS:[A-Za-z0-9_]+]] = OpVariable %[[RAYTRACING_AS_PTR_TYPE]] UniformConstant + +// CHECK-DAG: %[[RAY_PAYLOAD:[A-Za-z0-9_]+]] = OpVariable %{{.*}} RayPayloadKHR + +// CHECK: OpLoad {{.*}} %[[RAYTRACING_AS]] +// CHECK: OpTraceRayKHR{{.*}} %[[RAY_PAYLOAD]] + +RaytracingAccelerationStructure as; + +struct ShadowRay +{ + float hitDistance; +}; + +void nestedNestedCall() +{ + RayDesc ray = {}; + + ShadowRay shadowRay; + shadowRay.hitDistance = 0; + + TraceRay(as, + // ray flags + 1, + // cull mask + 0xff, + // sbt record offset + 0, + // sbt record stride + 0, + // missIndex + 2, + // ray + ray, + // payload + shadowRay); +} + +void nestedCall() +{ + nestedNestedCall(); +} + +void main() +{ + nestedCall(); +}
\ No newline at end of file diff --git a/tests/spirv/subgroup-size-2.slang b/tests/spirv/subgroup-size-2.slang index bd5ae5eec..500bd63c8 100644 --- a/tests/spirv/subgroup-size-2.slang +++ b/tests/spirv/subgroup-size-2.slang @@ -1,8 +1,11 @@ // Test that using workgroup size from more than one entrypoint result in // correct lowering into global variable. +//TEST:SIMPLE(filecheck=CHECK_EXPERIMENTAL): -target spirv -emit-spirv-directly -fvk-use-entrypoint-name -O0 -enable-experimental-passes //TEST:SIMPLE(filecheck=CHECK): -target spirv -emit-spirv-directly -fvk-use-entrypoint-name -O0 + + RWStructuredBuffer<int> outputBuffer; uint3 f() { return WorkgroupSize(); } @@ -11,16 +14,26 @@ uint3 f() { return WorkgroupSize(); } [numthreads(1u, 2u, 3)] void compute1() { + // CHECK_EXPERIMENTAL-DAG: %[[VAR:[A-Za-z0-9_]+]] = OpTypePointer Function %v3int + // CHECK_EXPERIMENTAL: OpAccessChain %[[VAR]] + // + // CHECK_EXPERIMENTAL-DAG: %[[CALL_RS:[A-Za-z0-9_]+]] = OpFunctionCall %v3uint %f + // CHECK_EXPERIMENTAL: OpCompositeExtract %uint %[[CALL_RS]] 0 + // + // CHECK_EXPERIMENTAL-DAG: %[[PTR:[A-Za-z0-9_]+]] = OpAccessChain %_ptr_StorageBuffer_int %outputBuffer %int_0 %int_1 + // CHECK_EXPERIMENTAL: OpStore %[[PTR]] %int_2 + // CHECK-DAG: %[[VAR:[A-Za-z0-9_]+]] = OpVariable %_ptr_Private_v3int Private // CHECK: OpStore %[[VAR]] - + // // CHECK-DAG: %[[CALL_RS:[A-Za-z0-9_]+]] = OpFunctionCall %v3uint %f // CHECK: OpCompositeExtract %uint %[[CALL_RS]] 0 - const int x = f().x; - outputBuffer[0] = x; - + // // CHECK-DAG: %[[PTR:[A-Za-z0-9_]+]] = OpAccessChain %_ptr_StorageBuffer_int %outputBuffer %int_0 %int_1 // CHECK: OpStore %[[PTR]] %int_2 + + const int x = f().x; + outputBuffer[0] = x; outputBuffer[1] = WorkgroupSize().y; } |
