yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
10e2d9c7c
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 8typedef DifferentialPair<float> dpfloat; 9typedef float.Differential dfloat; 10 11[BackwardDifferentiable] 12float test_simple_nested_loop(float y) 13{ 14 float t = y; 15 16 for (int i = 0; i < 2; i++) 17 { 18 for (int j = 0; j < 2; j++) 19 { 20 t = t * (i + j + 1); 21 } 22 } 23 24 return t; 25} 26 27[numthreads(1, 1, 1)] 28void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) 29{ 30 { 31 dpfloat dpa = dpfloat(1.0, 0.0); 32 33 __bwd_diff(test_simple_nested_loop)(dpa, 1.0f); 34 outputBuffer[0] = dpa.d; // Expect: 12.0 * 1 35 } 36 37 { 38 dpfloat dpa = dpfloat(1.0, 0.0); 39 40 __bwd_diff(test_simple_nested_loop)(dpa, 0.4f); 41 outputBuffer[1] = dpa.d; // Expect: 12 * 0.4 = 4.8 42 } 43}