diff options
| -rw-r--r-- | source/slang/slang-emit-c-like.cpp | 6 | ||||
| -rw-r--r-- | tests/pipeline/ray-tracing/ray-query-subroutine.slang | 40 | ||||
| -rw-r--r-- | tests/pipeline/ray-tracing/ray-query-subroutine.slang.hlsl | 26 |
3 files changed, 72 insertions, 0 deletions
diff --git a/source/slang/slang-emit-c-like.cpp b/source/slang/slang-emit-c-like.cpp index 009ca17f9..d21e16186 100644 --- a/source/slang/slang-emit-c-like.cpp +++ b/source/slang/slang-emit-c-like.cpp @@ -894,6 +894,12 @@ bool CLikeSourceEmitter::shouldFoldInstIntoUseSites(IRInst* inst) case kIROp_Alloca: return false; + // Never fold these, because their result cannot be computed + // as a sub-expression (they must be emitted as a declaration + // or statement). + case kIROp_DefaultConstruct: + return false; + // Always fold these in, because they are trivial // case kIROp_IntLit: diff --git a/tests/pipeline/ray-tracing/ray-query-subroutine.slang b/tests/pipeline/ray-tracing/ray-query-subroutine.slang new file mode 100644 index 000000000..501071717 --- /dev/null +++ b/tests/pipeline/ray-tracing/ray-query-subroutine.slang @@ -0,0 +1,40 @@ +// ray-query-subroutine.slang + +// Regression test for passing a `RayQuery` value into a subroutine. + +//TEST:CROSS_COMPILE: -profile sm_6_5 -stage compute -entry computeMain -target dxil-assembly + +RWStructuredBuffer<int> gOutput; +RaytracingAccelerationStructure gScene; + +int helper<let N : int>(RayQuery<N> q) +{ + RayDesc ray; + ray.Origin = 0; + ray.Direction = 0; + ray.TMin = 0; + ray.TMax = 1000.0; + q.TraceRayInline( + /* accellerationStructure: */ gScene, + /* rayFlags: */ N, + /* instanceInclusionmask: */ 0xFFFFFFFF, + /* ray: */ ray ); + + return 1; +} + +[shader("compute")] +void computeMain(uint tid : SV_DispatchThreadID) +{ + // Note: The original issue was due to "folding" of an instruction + // into use sites as part of emitting high-level-language code. + // + // In this case, the initial value of `rayQuery` has only a single + // use (in the call to `helper()`) and as a result was subject to + // "folding" during emit, because it had no side-effects. + + RayQuery<0> rayQuery; + let result = helper(rayQuery); + + gOutput[tid.x] = result; +} diff --git a/tests/pipeline/ray-tracing/ray-query-subroutine.slang.hlsl b/tests/pipeline/ray-tracing/ray-query-subroutine.slang.hlsl new file mode 100644 index 000000000..5906823e5 --- /dev/null +++ b/tests/pipeline/ray-tracing/ray-query-subroutine.slang.hlsl @@ -0,0 +1,26 @@ +//TEST_IGNORE_FILE: + +RaytracingAccelerationStructure gScene_0 : register(t0); + +int helper_0(RayQuery<int(0) > q_0) +{ + RayDesc ray_0; + ray_0.Origin = (vector<float,3>) int(0); + ray_0.Direction = (vector<float,3>) int(0); + ray_0.TMin = (float) int(0); + ray_0.TMax = 1000.00000000000000000000; + q_0.TraceRayInline(gScene_0, (uint) int(0), (uint) int(-1), ray_0); + return int(1); +} + +RWStructuredBuffer<int > gOutput_0 : register(u0); + +[shader("compute")][numthreads(1, 1, 1)] +void computeMain(uint tid_0 : SV_DISPATCHTHREADID) +{ + RayQuery<int(0) > rayQuery_0; + int _S1 = helper_0(rayQuery_0); + + gOutput_0[tid_0.x] = _S1; + return; +} |
