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