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, float y) 13{ 14 return x > 0.0 ? sqrt(x)*sqrt(x) : y; 15} 16 17[numthreads(1, 1, 1)] 18void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) 19{ 20 { 21 dpfloat dpa = dpfloat(2.0, 1.0); 22 dpfloat dpb = dpfloat(0.5, 1.0); 23 24 __bwd_diff(f)(dpa, dpb, 1.0); 25 26 outputBuffer[0] = dpa.d; // Expect: 1.0 27 outputBuffer[1] = dpb.d; // Expect: 0.0 28 } 29 30 { 31 dpfloat dpa = dpfloat(-0.3, 1.0); 32 dpfloat dpb = dpfloat(0.3, 1.0); 33 34 __bwd_diff(f)(dpa, dpb, 1.0); 35 36 outputBuffer[2] = dpa.d; // Expect: 0.0 37 outputBuffer[3] = dpb.d; // Expect: 1.0 38 } 39}