yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Jay KwakPrepare VulkanSDK release Oct 2025 (#8525)db44c1b73

master
2.2 KiB80 linesraw
1//TEST:SIMPLE(filecheck=CHECK_GLSL): -entry computeMain -target glsl -profile cs_6_5
2//TEST:SIMPLE(filecheck=CHECK_SPV): -entry computeMain -target spirv-assembly -profile cs_6_5
3
4//CHECK_GLSL:rayQueryGetIntersectionClusterIdNV
5//CHECK_SPV:OpRayQueryGetIntersectionClusterIdNV
6
7uniform RaytracingAccelerationStructure accelStruct;
8
9float GetRayT<let RAY_QUERY_FLAGS: uint>(uint rayInlineFlags)
10{
11    RayDesc ray;
12    ray.Origin = float3(0.1f, 0.1f, 0.0f);
13    ray.Direction = float3(0.0f, 0.0f, 1.0f);
14    ray.TMin = 0.01f;
15    ray.TMax = 1e4f;
16
17    RayQuery<RAY_QUERY_FLAGS> rq;
18    rq.TraceRayInline(accelStruct, rayInlineFlags, 0xff, ray);
19    bool proceed = rq.Proceed();
20
21    if( proceed )
22    {
23        switch( rq.CandidateType() )
24        {
25            case CANDIDATE_NON_OPAQUE_TRIANGLE:
26                int candidateClusterId = rq.CandidateClusterID();
27                if (candidateClusterId >= 0)
28                {
29                    rq.CommitNonOpaqueTriangleHit();
30                }
31                rq.Abort();
32                return rq.CommittedRayT();
33
34            case CANDIDATE_PROCEDURAL_PRIMITIVE:
35                rq.CommitProceduralPrimitiveHit(0.5f);
36                rq.Abort();
37                return rq.CommittedRayT();
38
39            default:
40                rq.Abort();
41                return 0.0f;
42        }
43    }
44    else
45    {
46        if( rq.CommittedStatus() == COMMITTED_TRIANGLE_HIT )
47        {
48            rq.Abort();
49            return rq.CommittedRayT();
50        }
51    }
52
53    int committedClusterId = rq.CommittedClusterID();
54    ray.TMin = 0.01f + committedClusterId;
55    return 0.0f;
56}
57
58//TEST_INPUT: ubuffer(data=[0], stride=4):out,name outputBuffer
59RWStructuredBuffer<float> outputBuffer;
60
61[shader("compute")]
62[numthreads(1, 1, 1)]
63void computeMain(int3 dispatchThreadID: SV_DispatchThreadID)
64{
65    int idx = dispatchThreadID.x;
66    float val = 0.0f;
67
68    const uint rayFlags[] = {
69        RAY_FLAG_NONE,
70    };
71    const uint numRayFlags = sizeof(rayFlags) / sizeof(uint);
72
73    // RAY_FLAG_FORCE_NON_OPAQUE, RAY_FLAG_CULL_OPAQUE, RAY_FLAG_SKIP_TRIANGLES returns 0 instead of 0.5
74    for( uint i = 0; i < numRayFlags; ++i )
75    {
76        val += GetRayT<RAY_FLAG_NONE>(rayFlags[i]);
77    }
78
79    outputBuffer[idx] = val;
80}