yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
f02b08490
master
1//TEST(compute):COMPARE_COMPUTE:-d3d12 -output-using-type -profile sm_6_5 -render-feature ray-query 2//TEST(compute):COMPARE_COMPUTE:-vk -output-using-type -render-feature ray-query 3 4//TEST_INPUT: set scene = AccelerationStructure 5uniform RaytracingAccelerationStructure scene; 6 7//TEST_INPUT:set outputBuffer = out ubuffer(data=[0], stride=4) 8RWStructuredBuffer<float> outputBuffer; 9 10bool traceRayClosestHit( 11 float3 rayOrigin, 12 float3 rayDir, 13 out float t) 14{ 15 RayDesc ray; 16 ray.Origin = rayOrigin; 17 ray.TMin = 0.01f; 18 ray.Direction = rayDir; 19 ray.TMax = 1e4f; 20 RayQuery<RAY_FLAG_NONE> q; 21 let rayFlags = RAY_FLAG_NONE; 22 23 q.TraceRayInline( 24 scene, 25 rayFlags, 26 0xff, 27 ray); 28 29 q.Proceed(); 30 if(q.CommittedStatus() == COMMITTED_TRIANGLE_HIT) 31 { 32 t = q.CommittedRayT(); 33 //primitiveIndex = q.CommittedPrimitiveIndex(); 34 return true; 35 } 36 unused(t); 37 return false; 38} 39 40[shader("compute")] 41[numthreads(1,1,1)] 42void computeMain( 43 uint3 threadIdx : SV_DispatchThreadID) 44{ 45 float t = 0.0; 46 traceRayClosestHit(float3(0.1, 0.1, 0.0), float3(0,0,1), t); 47 outputBuffer[threadIdx.x] = t; 48}