yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
228e71dab
master
1 2//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type 3//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type 4//TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -output-using-type -shaderobj 5 6//TEST_INPUT:ubuffer(data=[0 0 0 0 0], stride=4):out,name=outputBuffer 7RWStructuredBuffer<float> outputBuffer; 8 9struct A : IDifferentiable 10{ 11 float x; 12 float y; 13}; 14 15[BackwardDifferentiable] 16A f(A a) 17{ 18 // Read/writes to local struct variables won't be SSA'd out by default. 19 // The backward diff preparation pass will kick in to create temp vars for them. 20 A aout; 21 aout.y = 2 * a.x; 22 aout.y = aout.y + 2 * a.x; 23 aout.x = aout.y + 5 * a.x; 24 25 // The result should be equivalent to: 26 /* 27 A aout; 28 var tmp = 2 * a.x; 29 tmp = tmp + 2 * a.x; 30 aout.y = tmp; 31 aout.x = tmp + 5 * a.x; 32 */ 33 return aout; 34 35} 36 37[numthreads(1, 1, 1)] 38void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) 39{ 40 A a = {1.0, 2.0}; 41 42 var dpa = diffPair(a); 43 44 A.Differential dout = {1.0, 1.0}; 45 46 __bwd_diff(f)(dpa, dout); 47 outputBuffer[0] = dpa.d.x; // Expect: 13 48 outputBuffer[1] = dpa.d.y; // Expect: 0 49}