yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
d10732742
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:-cuda -compute -shaderobj -output-using-type 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 15struct B : IDifferentiable 16{ 17 float x; 18 float y; 19}; 20 21typedef DifferentialPair<A> dpA; 22 23float id(float x) 24{ 25 return x; 26} 27 28[BackwardDifferentiable] 29void f(A input, out B rs) 30{ 31 rs.x = input.x * input.x; 32 // Derivative of rs.x should still propagate through this no_diff call. 33 rs.y = no_diff id(input.y); 34} 35 36[numthreads(1, 1, 1)] 37void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) 38{ 39 { 40 A a = {3.0, 2.0}; 41 A.Differential azero = {0.0, 0.0}; 42 43 dpA dpa = dpA(a, azero); 44 45 B.Differential dout = {1.0, 1.0}; 46 47 __bwd_diff(f)(dpa, dout); 48 outputBuffer[0] = dpa.d.x; // Expect: 6 49 outputBuffer[1] = dpa.d.y; // Expect: 0 50 } 51}