yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
d10732742
master
1//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type 2//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type 3//TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute -shaderobj -output-using-type 4 5//TEST_INPUT:ubuffer(data=[0 0 0], stride=4):out,name=outputBuffer 6RWStructuredBuffer<float> outputBuffer; 7 8static const uint kMaxSurfaceBounces = 2; 9 10[BackwardDifferentiable] 11void updatePathContrib(inout float3 result, float3 val) 12{ 13 result = result + val; 14} 15 16[BackwardDifferentiable] 17float3 evalPath(uint2 pixel) 18{ 19 float3 result = float3(0.f); 20 float3 thp = float3(1.f); 21 22 [MaxIters(kMaxSurfaceBounces)] 23 for (int i = 0; i < kMaxSurfaceBounces; i++) 24 { 25 float3 neeContrib = float3(1.f); 26 updatePathContrib(result, thp * neeContrib); 27 thp = thp * float3(0.9f); 28 } 29 return result; 30} 31 32void execute(const uint2 pixel) 33{ 34 float3 dColor = float3(1.f); 35 __bwd_diff(evalPath)(pixel, dColor); 36} 37 38[numthreads(64, 1, 1)] 39void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) 40{ 41 execute(dispatchThreadID.xy); 42}