yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
71efd949f
master
1//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type 2//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type 3//TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -output-using-type -shaderobj 4 5//TEST_INPUT:ubuffer(data=[0 0 0 0 0], stride=4):out,name=outputBuffer 6RWStructuredBuffer<float> outputBuffer; 7 8struct D : IDifferentiable 9{ 10 float n; 11 float m; 12} 13 14[BackwardDifferentiable] 15void g(no_diff float p, inout float x) 16{ 17 x = p * ((x+1)*(x+1)); 18} 19 20[BackwardDifferentiable] 21void f(no_diff float p, inout float x) 22{ 23 g(p, x); 24 g(p, x); 25} 26[BackwardDifferentiable] 27float f_ref(no_diff float p, float x) 28{ 29 float y1 = p * (x+1)*(x+1); 30 float y2 = p * (y1+1)*(y1+1); 31 return y2; 32} 33 34[numthreads(1, 1, 1)] 35void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) 36{ 37 var x = diffPair(2.0, 1.0); 38 39 __bwd_diff(f)(3.0, x); 40 41 outputBuffer[0] = x.p; // should be 2, since bwd_diff does not write back new primal val. 42 outputBuffer[1] = x.d; // 3024 43 44 var refVal = __fwd_diff(f_ref)(3.0, diffPair(2.0, 1.0)).d; 45 outputBuffer[2] = refVal; // 3024 46 47}