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:-slang -compute -shaderobj -output-using-type 3//TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute -shaderobj -output-using-type 4 5//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0], stride=4):out,name=outputBuffer 6RWStructuredBuffer<float> outputBuffer; 7 8typedef DifferentialPair<float2x2> dpmat2; 9 10[BackwardDifferentiable] 11float2x2 diffMul(float2x2 a, float2x2 b) 12{ 13 return mul(a, b); 14} 15 16[numthreads(1, 1, 1)] 17void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID) 18{ 19 dpmat2 dpa = dpmat2(float2x2(1.0, 2.0, 3.0, 4.0), float2x2(0.0, 0.0, 0.0, 0.0)); 20 dpmat2 dpb = dpmat2(float2x2(5.0, 6.0, 7.0, 8.0), float2x2(0.0, 0.0, 0.0, 0.0)); 21 float2x2 dOut = float2x2(1.0, -2.0, -3.0, 4.0); 22 __bwd_diff(diffMul)(dpa, dpb, dOut); 23 outputBuffer[0] = dpa.d[0][0]; // Expect: -7.000000 24 outputBuffer[1] = dpa.d[0][1]; // Expect: -9.000000 25 outputBuffer[2] = dpa.d[1][0]; // Expect: 9.000000 26 outputBuffer[3] = dpa.d[1][1]; // Expect: 11.000000 27 outputBuffer[4] = dpb.d[0][0]; // Expect: -8.000000 28 outputBuffer[5] = dpb.d[0][1]; // Expect: 10.000000 29 outputBuffer[6] = dpb.d[1][0]; // Expect: -10.000000 30 outputBuffer[7] = dpb.d[1][1]; // Expect: 12.000000 31}