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:-cuda -compute -shaderobj -output-using-type 3 4//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer 5 6RWStructuredBuffer<float> outputBuffer; 7 8[BackwardDifferentiable] 9float bsdf() 10{ 11 return 0.5; 12} 13 14[ForwardDerivativeOf(bsdf)] 15DifferentialPair<float> d_bsdf() 16{ 17 return diffPair(0.5f, 1.0f); 18} 19 20[BackwardDerivativeOf(bsdf)] 21void d_bsdf(float dOut) 22{ 23 outputBuffer[0] += dOut; 24} 25 26[BackwardDifferentiable] 27float tracePath() 28{ 29 float thp = 1.0; 30 float L = 0.0; 31 32 uint depth = 0; 33 34 for (int i = 0; i < 3; ++i) 35 { 36 if (depth <= 2) 37 { 38 thp = thp * bsdf(); 39 40 L = thp * 1.0; 41 42 if (depth >= 2) break; 43 44 depth = depth + 1; 45 } 46 else 47 { 48 L = 0.0; 49 } 50 } 51 52 return L; 53} 54 55[numthreads(1, 1, 1)] 56void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID) 57{ 58 { 59 __bwd_diff(tracePath)(1.0); // Expect: 1.0 in outputBuffer[0] 60 } 61}