summaryrefslogtreecommitdiff
path: root/tests/pipeline/ray-tracing/ray-query-subroutine.slang
blob: 122a2c966ca945f7405ae5316e61348889cf9992 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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;

float3 helper<let N : uint>(inout 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 q.WorldRayDirection();
}

[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] = int(result.x);
}