yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
228e71dab
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 0], stride=4):out,name=outputBuffer 6RWStructuredBuffer<float> outputBuffer; 7 8typedef DifferentialPair<float> dpfloat; 9typedef float.Differential dfloat; 10 11[BackwardDifferentiable] 12float test_multi_return(float y) 13{ 14 if (y > 0.6) 15 { 16 if (y > 0.8) 17 { 18 return y * 10.0f; 19 } 20 else 21 { 22 return y * 4.0f; 23 } 24 } 25 return y * 6.0f; 26} 27 28[numthreads(1, 1, 1)] 29void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) 30{ 31 { 32 dpfloat dpa = dpfloat(1.0, 0.0); 33 34 __bwd_diff(test_multi_return)(dpa, 1.0f); 35 outputBuffer[0] = dpa.d; // Expect: 10.0 36 } 37 38 { 39 dpfloat dpa = dpfloat(0.4, 0.0); 40 41 __bwd_diff(test_multi_return)(dpa, 1.0f); 42 outputBuffer[1] = dpa.d; // Expect: 6.0 43 } 44 45 { 46 dpfloat dpa = dpfloat(0.7, 0.0); 47 48 __bwd_diff(test_multi_return)(dpa, 1.0f); 49 outputBuffer[2] = dpa.d; // Expect: 4.0 50 } 51}