yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
271dc1b98
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[PreferRecompute] 15[BackwardDifferentiable] 16void g(no_diff float p, inout float x) 17{ 18 x = p * ((x+1)*(x+1)); 19} 20 21[PreferRecompute] 22[BackwardDifferentiable] 23void f(no_diff float p, inout float x) 24{ 25 g(p, x); 26 g(p, x); 27} 28[BackwardDifferentiable] 29float f_ref(no_diff float p, float x) 30{ 31 float y1 = p * (x+1)*(x+1); 32 float y2 = p * (y1+1)*(y1+1); 33 return y2; 34} 35 36[numthreads(1, 1, 1)] 37void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) 38{ 39 var x = diffPair(2.0, 1.0); 40 41 __bwd_diff(f)(3.0, x); 42 43 outputBuffer[0] = x.p; // should be 2, since bwd_diff does not write back new primal val. 44 outputBuffer[1] = x.d; // 3024 45 46 var refVal = __fwd_diff(f_ref)(3.0, diffPair(2.0, 1.0)).d; 47 outputBuffer[2] = refVal; // 3024 48 49}