yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
d10732742
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:-cuda -compute -shaderobj -output-using-type 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 f(float x) 13{ 14 float k = x > 1e-8 ? atan2(x, x) : 0.0; 15 return k; 16} 17 18[numthreads(1, 1, 1)] 19void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) 20{ 21 { 22 dpfloat dpa = diffPair(2.0); 23 24 __bwd_diff(f)(dpa, 1.0); 25 26 outputBuffer[0] = dpa.d; // Expect: 0.0 27 } 28 29 { 30 dpfloat dpa = diffPair(0.0,); 31 32 __bwd_diff(f)(dpa, 1.0); 33 34 outputBuffer[1] = dpa.d; // Expect: 0.0, but if select is not turned into if-else, 35 // this will be 'inf' or 'nan' 36 } 37}