diff options
| author | Yong He <yonghe@outlook.com> | 2023-09-03 12:56:31 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-09-03 12:56:31 -0700 |
| commit | 1d4b5b6fd2433a10cc7ab87626cb560f54b0acbb (patch) | |
| tree | 6196d519190720fd2968ac7d4b373e3c967d5fe6 /tests | |
| parent | 355bb4287861f96082751042f4e58ff3598b4e5e (diff) | |
Proper lowering of functiosn that returns NonCopyable values. (#3179)
* Proper lowering of functiosn that returns NonCopyable values.
* Fix tests.
* Fix clang errors.
* Fix.
* Fix clang error.
---------
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'tests')
11 files changed, 110 insertions, 66 deletions
diff --git a/tests/bindings/hlsl-to-vulkan-shift-rw-structured.hlsl b/tests/bindings/hlsl-to-vulkan-shift-rw-structured.hlsl index 2fcbdf77c..17d2036e7 100644 --- a/tests/bindings/hlsl-to-vulkan-shift-rw-structured.hlsl +++ b/tests/bindings/hlsl-to-vulkan-shift-rw-structured.hlsl @@ -1,10 +1,10 @@ //TEST:SIMPLE(filecheck=CHECK):-target glsl -profile glsl_450 -entry MainCs -stage compute -fvk-b-shift 0 0 -fvk-s-shift 14 0 -fvk-t-shift 30 0 -fvk-u-shift 158 0 -// CHECK: layout(std430, binding = 159) buffer -// CHECK: } g_ByteBuffer +// CHECK-DAG: layout(std430, binding = 159) buffer +// CHECK-DAG: } g_ByteBuffer -// CHECK: layout(std430, binding = 158) buffer +// CHECK-DAG: layout(std430, binding = 158) buffer RWStructuredBuffer<uint> g_OutputCullBits; RWByteAddressBuffer g_ByteBuffer; diff --git a/tests/hlsl-intrinsic/shader-execution-reordering/hit-object-assign.slang b/tests/hlsl-intrinsic/shader-execution-reordering/hit-object-assign.slang index 7f5be6243..49fef7a4c 100644 --- a/tests/hlsl-intrinsic/shader-execution-reordering/hit-object-assign.slang +++ b/tests/hlsl-intrinsic/shader-execution-reordering/hit-object-assign.slang @@ -1,7 +1,7 @@ // hit-object-assign.slang //TEST:SIMPLE: -target dxil -entry rayGenerationMain -stage raygeneration -profile sm_6_5 -DNV_SHADER_EXTN_SLOT=u0 -//TEST:SIMPLE: -target glsl -entry rayGenerationMain -stage raygeneration -profile glsl_460+GL_EXT_ray_tracing -O0 -line-directive-mode none +//TEST:SIMPLE(filecheck=SPIRV): -target spirv -entry rayGenerationMain -stage raygeneration -profile glsl_460+GL_EXT_ray_tracing -O0 -line-directive-mode none //DISABLE_TEST:COMPARE_COMPUTE_EX:-slang -compute -dx12 -output-using-type -profile sm_6_5 -nvapi-slot u0 //DISABLE_TEST(compute):COMPARE_COMPUTE:-d3d12 -output-using-type -use-dxil -profile sm_6_5 -render-feature ray-query @@ -10,6 +10,9 @@ //TEST_INPUT:ubuffer(data=[0 0 0 0 0], stride=4):out,name=outputBuffer RWStructuredBuffer<uint> outputBuffer; +// SPIRV: OpHitObjectRecordMissNV +// SPIRV: OpHitObjectIsMissNV + void rayGenerationMain() { int2 launchID = int2(DispatchRaysIndex().xy); diff --git a/tests/hlsl-intrinsic/shader-execution-reordering/hit-object-make-hit.slang b/tests/hlsl-intrinsic/shader-execution-reordering/hit-object-make-hit.slang index e38b29446..8fea9cf67 100644 --- a/tests/hlsl-intrinsic/shader-execution-reordering/hit-object-make-hit.slang +++ b/tests/hlsl-intrinsic/shader-execution-reordering/hit-object-make-hit.slang @@ -1,7 +1,7 @@ // hit-object-make-hit.slang //TEST:SIMPLE: -target dxil -entry rayGenerationMain -stage raygeneration -profile sm_6_5 -DNV_SHADER_EXTN_SLOT=u0 -//TEST:SIMPLE: -target glsl -entry rayGenerationMain -stage raygeneration -profile sm_6_5 -line-directive-mode none +//TEST:SIMPLE(filecheck=SPIRV): -target spirv -entry rayGenerationMain -stage raygeneration -profile sm_6_5 -line-directive-mode none //DISABLE_TEST(compute):COMPARE_COMPUTE:-d3d12 -output-using-type -use-dxil -profile sm_6_5 -render-feature ray-query //DISABLE_TEST(compute):COMPARE_COMPUTE:-vk -output-using-type -render-feature ray-query @@ -18,8 +18,16 @@ struct SomeValues float b; }; + uint calcValue(HitObject hit) { + // SPIRV-DAG: OpHitObjectIsHitNV + // SPIRV: OpHitObjectGetInstanceCustomIndexNV + // SPIRV: OpHitObjectGetInstanceIdNV + // SPIRV: OpHitObjectGetGeometryIndexNV + // SPIRV: OpHitObjectGetPrimitiveIndexNV + // SPIRV: OpHitObjectGetHitKindNV + // SPIRV: OpHitObjectIsMissNV uint r = 0; if (hit.IsHit()) @@ -72,6 +80,7 @@ void rayGenerationMain() uint r = 0; { + // SPIRV-DAG: OpHitObjectRecordHitNV HitObject hit = HitObject::MakeHit(0, scene, idx, idx * 2, idx * 3, hitKind, ray, someValues); r = calcValue(hit); diff --git a/tests/hlsl-intrinsic/shader-execution-reordering/hit-object-make-miss.slang b/tests/hlsl-intrinsic/shader-execution-reordering/hit-object-make-miss.slang index 421063987..9aea89573 100644 --- a/tests/hlsl-intrinsic/shader-execution-reordering/hit-object-make-miss.slang +++ b/tests/hlsl-intrinsic/shader-execution-reordering/hit-object-make-miss.slang @@ -1,7 +1,7 @@ // hit-object-make-miss.slang -//TEST:SIMPLE: -target dxil -entry computeMain -stage compute -profile sm_6_5 -DNV_SHADER_EXTN_SLOT=u0 -//TEST:SIMPLE: -target glsl -entry computeMain -stage compute -profile sm_6_5 -line-directive-mode none +//TEST:SIMPLE: -target dxil -entry rayGenerationMain -stage raygeneration -profile sm_6_5 -DNV_SHADER_EXTN_SLOT=u0 +//TEST:SIMPLE(filecheck=SPIRV): -target spirv -entry rayGenerationMain -stage raygeneration -profile sm_6_5 -line-directive-mode none //DISABLE_TEST:COMPARE_COMPUTE_EX:-slang -compute -dx12 -output-using-type -profile sm_6_5 -nvapi-slot u0 //DISABLE_TEST(compute):COMPARE_COMPUTE:-d3d12 -output-using-type -use-dxil -profile sm_6_5 -render-feature ray-query @@ -10,19 +10,19 @@ //TEST_INPUT:ubuffer(data=[0 0 0 0 0], stride=4):out,name=outputBuffer RWStructuredBuffer<uint> outputBuffer; -[numthreads(4, 1, 1)] -void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) -{ - int idx = int(dispatchThreadID.x); +void rayGenerationMain() +{ + int idx = DispatchRaysIndex().x; RayDesc ray; ray.Origin = float3(idx, 0, 0); ray.TMin = 0.01f; ray.Direction = float3(0, 1, 0); ray.TMax = 1e4f; - + // SPIRV: OpHitObjectRecordMissNV HitObject hit = HitObject::MakeMiss(idx, ray); - + + // SPIRV: OpHitObjectIsMissNV int r = int(hit.IsMiss()); outputBuffer[idx] = r; diff --git a/tests/hlsl-intrinsic/shader-execution-reordering/hit-object-make-nop.slang b/tests/hlsl-intrinsic/shader-execution-reordering/hit-object-make-nop.slang index b1d72c47e..e8c88e1ad 100644 --- a/tests/hlsl-intrinsic/shader-execution-reordering/hit-object-make-nop.slang +++ b/tests/hlsl-intrinsic/shader-execution-reordering/hit-object-make-nop.slang @@ -1,7 +1,7 @@ // hit-object-make-nop.slang //TEST:SIMPLE: -target dxil -entry rayGenerationMain -stage raygeneration -profile sm_6_5 -DNV_SHADER_EXTN_SLOT=u0 -//TEST:SIMPLE: -target glsl -entry rayGenerationMain -stage raygeneration -profile sm_6_5 -line-directive-mode none +//TEST:SIMPLE(filecheck=SPIRV): -target spirv -entry rayGenerationMain -stage raygeneration -profile sm_6_5 -line-directive-mode none //DISABLE_TEST(compute):COMPARE_COMPUTE:-d3d12 -output-using-type -use-dxil -profile sm_6_5 -render-feature ray-query //DISABLE_TEST(compute):COMPARE_COMPUTE:-vk -output-using-type -render-feature ray-query @@ -16,6 +16,7 @@ void rayGenerationMain() int idx = launchID.x; + // SPIRV: OpHitObjectRecordEmptyNV HitObject hit = HitObject::MakeNop(); outputBuffer[idx] = uint(hit.IsNop()); diff --git a/tests/hlsl-intrinsic/shader-execution-reordering/hit-object-output.slang b/tests/hlsl-intrinsic/shader-execution-reordering/hit-object-output.slang index e8afaf217..e06e63693 100644 --- a/tests/hlsl-intrinsic/shader-execution-reordering/hit-object-output.slang +++ b/tests/hlsl-intrinsic/shader-execution-reordering/hit-object-output.slang @@ -4,7 +4,7 @@ // as function results (including `out` parameters) //TEST:SIMPLE: -target dxil -entry rayGenerationMain -stage raygeneration -profile sm_6_5 -DNV_SHADER_EXTN_SLOT=u0 -//TEST:SIMPLE: -target glsl -entry rayGenerationMain -stage raygeneration -profile sm_6_5 -line-directive-mode none +//TEST:SIMPLE(filecheck=SPIRV): -target spirv -entry rayGenerationMain -stage raygeneration -profile sm_6_5 -line-directive-mode none //DISABLE_TEST(compute):COMPARE_COMPUTE:-d3d12 -output-using-type -use-dxil -profile sm_6_5 -render-feature ray-query //DISABLE_TEST(compute):COMPARE_COMPUTE:-vk -output-using-type -render-feature ray-query @@ -57,7 +57,8 @@ HitObject myTraceRay(uint idx) uint multiplierForGeometryContributionToHitGroupIndex = 4; uint missShaderIndex = 0; - HitObject hit = HitObject::TraceRay(scene, + // SPIRV-DAG: OpHitObjectTraceRayNV + return HitObject::TraceRay(scene, rayFlags, instanceInclusionMask, rayContributionToHitGroupIndex, @@ -65,8 +66,6 @@ HitObject myTraceRay(uint idx) missShaderIndex, ray, payload); - - return hit; } void copyHitObjectHandle( @@ -94,16 +93,20 @@ void rayGenerationMain() accumulate(r, hit); +#if 0 // cannot support this right now HitObject hit2; copyHitObjectHandle(hit2, hit); accumulate(r, hit2); +#else + accumulate(r, hit); + +#endif - HitObject hitBackup = hit; myMakeMiss(idx, hit); accumulate(r, hit); - accumulate(r, hitBackup); + accumulate(r, hit); outputBuffer[idx] = r; } diff --git a/tests/hlsl-intrinsic/shader-execution-reordering/hit-object-reorder-thread.slang b/tests/hlsl-intrinsic/shader-execution-reordering/hit-object-reorder-thread.slang index ed83b8d47..8498b9304 100644 --- a/tests/hlsl-intrinsic/shader-execution-reordering/hit-object-reorder-thread.slang +++ b/tests/hlsl-intrinsic/shader-execution-reordering/hit-object-reorder-thread.slang @@ -1,7 +1,7 @@ // hit-object-reorder-thread.slang //TEST:SIMPLE: -target dxil -entry rayGenerationMain -stage raygeneration -profile sm_6_5 -DNV_SHADER_EXTN_SLOT=u0 -//TEST:SIMPLE: -target glsl -entry rayGenerationMain -stage raygeneration -profile sm_6_5 -line-directive-mode none +//TEST:SIMPLE(filecheck=SPIRV): -target spirv -entry rayGenerationMain -stage raygeneration -profile sm_6_5 -line-directive-mode none //DISABLE_TEST(compute):COMPARE_COMPUTE:-d3d12 -output-using-type -use-dxil -profile sm_6_5 -render-feature ray-query //DISABLE_TEST(compute):COMPARE_COMPUTE:-vk -output-using-type -render-feature ray-query @@ -62,6 +62,7 @@ void rayGenerationMain() uint multiplierForGeometryContributionToHitGroupIndex = 4; uint missShaderIndex = 0; + // SPIRV: OpHitObjectTraceRayNV HitObject hit = HitObject::TraceRay(scene, rayFlags, instanceInclusionMask, @@ -70,42 +71,47 @@ void rayGenerationMain() missShaderIndex, ray, someValues); - + uint r = calcValue(hit); - + // SPIRV: OpReorderThreadWithHitObjectNV ReorderThread( hit ); // Change the payload SomeValues otherValues = { idx * -1, idx * 4.0f }; - + // Now Invoke to cast another ray, with the new payload + // SPIRV: OpHitObjectExecuteShaderNV HitObject::Invoke( scene, hit, otherValues ); r += calcValue(hit); // !!! TODO(JS) !!! // NOTE! If I enable this I end up with a recursive failure in AST traversal, if - // otherValues is redefined. - - // Reorder + // otherValues is redefined. + + // Reorder + // SPIRV: OpReorderThreadWithHitObjectNV ReorderThread(hit, uint(idx & 3), 2); // Change the payload otherValues = { idx * -2, idx * 8.0f }; - + // Now Invoke to cast another ray, with the new payload + // SPIRV: OpHitObjectExecuteShaderNV HitObject::Invoke( scene, hit, otherValues ); r += calcValue(hit); - // Reorder + // Reorder + // SPIRV: OpReorderThreadWithHintNV ReorderThread(uint(idx & 1), 1); // Change the payload otherValues = { idx * -4, idx * 16.0f }; - + // Now Invoke to cast another ray, with the new payload + // SPIRV: OpHitObjectExecuteShaderNV HitObject::Invoke( scene, hit, otherValues ); r += calcValue(hit); diff --git a/tests/hlsl-intrinsic/shader-execution-reordering/hit-object-trace-motion-ray.slang b/tests/hlsl-intrinsic/shader-execution-reordering/hit-object-trace-motion-ray.slang index f57ecf02a..4e8d52e10 100644 --- a/tests/hlsl-intrinsic/shader-execution-reordering/hit-object-trace-motion-ray.slang +++ b/tests/hlsl-intrinsic/shader-execution-reordering/hit-object-trace-motion-ray.slang @@ -2,7 +2,7 @@ // Motion rays not supported on HLSL impl currently //DISABLE_TEST:SIMPLE: -target dxil -entry rayGenerationMain -stage raygeneration -profile sm_6_5 -DNV_SHADER_EXTN_SLOT=u0 -//TEST:SIMPLE: -target glsl -entry rayGenerationMain -stage raygeneration -profile sm_6_5 -line-directive-mode none +//TEST:SIMPLE(filecheck=SPIRV): -target spirv -entry rayGenerationMain -stage raygeneration -profile sm_6_5 -line-directive-mode none //DISABLE_TEST(compute):COMPARE_COMPUTE:-d3d12 -output-using-type -use-dxil -profile sm_6_6 -render-feature ray-query //DISABLE_TEST(compute):COMPARE_COMPUTE:-vk -output-using-type -render-feature ray-query @@ -64,7 +64,7 @@ void rayGenerationMain() uint rayContributionToHitGroupIndex = 0; uint multiplierForGeometryContributionToHitGroupIndex = 4; uint missShaderIndex = 0; - + // SPIRV: OpHitObjectTraceRayMotionNV HitObject hit = HitObject::TraceMotionRay(scene, rayFlags, instanceInclusionMask, diff --git a/tests/hlsl-intrinsic/shader-execution-reordering/hit-object-trace-ray.slang b/tests/hlsl-intrinsic/shader-execution-reordering/hit-object-trace-ray.slang index 63ae4c957..c1a29d647 100644 --- a/tests/hlsl-intrinsic/shader-execution-reordering/hit-object-trace-ray.slang +++ b/tests/hlsl-intrinsic/shader-execution-reordering/hit-object-trace-ray.slang @@ -1,7 +1,7 @@ // hit-object-trace-ray.slang //TEST:SIMPLE: -target dxil -entry rayGenerationMain -stage raygeneration -profile sm_6_5 -DNV_SHADER_EXTN_SLOT=u0 -//TEST:SIMPLE: -target glsl -entry rayGenerationMain -stage raygeneration -profile sm_6_5 -line-directive-mode none +//TEST:SIMPLE(filecheck=SPIRV): -target spirv -entry rayGenerationMain -stage raygeneration -profile sm_6_5 -line-directive-mode none //DISABLE_TEST(compute):COMPARE_COMPUTE:-d3d12 -output-using-type -use-dxil -profile sm_6_6 -render-feature ray-query //DISABLE_TEST(compute):COMPARE_COMPUTE:-vk -output-using-type -render-feature ray-query @@ -61,7 +61,7 @@ void rayGenerationMain() uint rayContributionToHitGroupIndex = 0; uint multiplierForGeometryContributionToHitGroupIndex = 4; uint missShaderIndex = 0; - + // SPIRV: OpHitObjectTraceRayNV HitObject hit = HitObject::TraceRay(scene, rayFlags, instanceInclusionMask, diff --git a/tests/language-feature/non-copyable-return.slang b/tests/language-feature/non-copyable-return.slang new file mode 100644 index 000000000..20330c5f9 --- /dev/null +++ b/tests/language-feature/non-copyable-return.slang @@ -0,0 +1,37 @@ +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -shaderobj -output-using-type +//TEST(compute):SIMPLE(filecheck=GLSL): -stage compute -entry computeMain -target glsl + +// Note: spirv_by_reference is only supported for passing opaque types, so this test won't produce +// expected result on vulkan. +//DISABLED_TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -vk -shaderobj -output-using-type + +[__NonCopyableType] +struct MyType +{ + float x; + __init() { x = 1.0; } +} + +MyType myFunc1(float y) +{ + __return_val = MyType(); + __return_val.x += y; +} + +MyType myFunc0(float x) +{ + return myFunc1(x + 1.0); +} + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer<float> outputBuffer; + +[numthreads(1, 1, 1)] +void computeMain(int3 dispatchThreadID: SV_DispatchThreadID) +{ + let f = myFunc0(2.0); + // CHECK: 4.0 + // GLSL: void myFunc1_0(float y{{.*}}, spirv_by_reference MyType_0 {{.*}}) + // GLSL: void myFunc0_0(float x{{.*}}, spirv_by_reference MyType_0 {{.*}}) + outputBuffer[0] = f.x; +} diff --git a/tests/pipeline/ray-tracing/trace-ray-inline.slang.hlsl b/tests/pipeline/ray-tracing/trace-ray-inline.slang.hlsl index bf10cc2e1..4ed4c9966 100644 --- a/tests/pipeline/ray-tracing/trace-ray-inline.slang.hlsl +++ b/tests/pipeline/ray-tracing/trace-ray-inline.slang.hlsl @@ -1,4 +1,8 @@ #pragma pack_matrix(column_major) +#ifdef SLANG_HLSL_ENABLE_NVAPI +#include "nvHLSLExtns.h" +#endif +#pragma warning(disable: 3557) struct SLANG_ParameterGroup_C_0 { @@ -15,7 +19,6 @@ cbuffer C_0 : register(b0) { SLANG_ParameterGroup_C_0 C_0; } - RaytracingAccelerationStructure myAccelerationStructure_0 : register(t0); RWStructuredBuffer<int > resultBuffer_0 : register(u0); @@ -67,53 +70,41 @@ void myMiss_0(inout MyRayPayload_0 payload_4) void main(uint3 tid_0 : SV_DISPATCHTHREADID) { uint index_0 = tid_0.x; - RayQuery<int(512) > query_0; - MyRayPayload_0 payload_5; payload_5.value_1 = int(-1); - RayDesc ray_0 = { C_0.origin_0, C_0.tMin_0, C_0.direction_0, C_0.tMax_0 }; - + RayQuery<512U > query_0; query_0.TraceRayInline(myAccelerationStructure_0, C_0.rayFlags_0, C_0.instanceMask_0, ray_0); - MyProceduralHitAttrs_0 committedProceduralAttrs_0; - for(;;) { - bool _S1 = query_0.Proceed(); - if(!_S1) { - break; } - + uint _S2 = query_0.CandidateType(); MyProceduralHitAttrs_0 committedProceduralAttrs_1; - switch(query_0.CandidateType()) + switch(_S2) { case 1U: { MyProceduralHitAttrs_0 candidateProceduralAttrs_0; candidateProceduralAttrs_0.value_0 = int(0); - float tHit_1 = 0.0; - bool _S2 = myProceduralIntersection_0(tHit_1, candidateProceduralAttrs_0); - if(_S2) + bool _S3 = myProceduralIntersection_0(tHit_1, candidateProceduralAttrs_0); + if(_S3) { - bool _S3 = myProceduralAnyHit_0(payload_5); - if(_S3) + bool _S4 = myProceduralAnyHit_0(payload_5); + if(_S4) { query_0.CommitProceduralPrimitiveHit(tHit_1); - MyProceduralHitAttrs_0 _S4 = candidateProceduralAttrs_0; + MyProceduralHitAttrs_0 _S5 = candidateProceduralAttrs_0; if(C_0.shouldStopAtFirstHit_0 != 0U) { query_0.Abort(); } - else - {} - - committedProceduralAttrs_1 = _S4; + committedProceduralAttrs_1 = _S5; } else { @@ -128,20 +119,15 @@ void main(uint3 tid_0 : SV_DISPATCHTHREADID) } case 0U: { - bool _S5 = myTriangleAnyHit_0(payload_5); - if(_S5) + bool _S6 = myTriangleAnyHit_0(payload_5); + if(_S6) { query_0.CommitNonOpaqueTriangleHit(); if(C_0.shouldStopAtFirstHit_0 != 0U) { query_0.Abort(); } - else - {} } - else - {} - committedProceduralAttrs_1 = committedProceduralAttrs_0; break; } @@ -151,11 +137,10 @@ void main(uint3 tid_0 : SV_DISPATCHTHREADID) break; } } - committedProceduralAttrs_0 = committedProceduralAttrs_1; } - - switch(query_0.CommittedStatus()) + uint _S7 = query_0.CommittedStatus(); + switch(_S7) { case 1U: { |
