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 -render-features half 2//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type -render-features half 3//TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute -shaderobj -output-using-type 4// Not supported in WGSL: Double and other unsupported scalar types 5//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-wgpu 6 7//TEST_INPUT:ubuffer(data=[0 0 0 0 0], stride=4):out,name=outputBuffer 8RWStructuredBuffer<float> outputBuffer; 9 10typedef DifferentialPair<float> dpfloat; 11typedef DifferentialPair<double> dpdouble; 12typedef DifferentialPair<half> dphalf; 13typedef float.Differential dfloat; 14typedef double.Differential ddouble; 15typedef half.Differential dhalf; 16 17[BackwardDifferentiable] 18float f(double x) 19{ 20 return (float)x; 21} 22 23[BackwardDifferentiable] 24float h(float x, float y) 25{ 26 float m = x + y; 27 float n = x - y; 28 return m * n + 2 * x * y; 29} 30 31[BackwardDifferentiable] 32float j(half x, half y) 33{ 34 float m = x / y; 35 return m * y; 36} 37 38[numthreads(1, 1, 1)] 39void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID) 40{ 41 { 42 dpdouble dpa = dpdouble(2.0, 1.0); 43 44 __bwd_diff(f)(dpa, 1.0); 45 46 outputBuffer[0] = (float)dpa.d; // Expect: 1 47 } 48 49 { 50 dpfloat dpa = dpfloat(2.0, 1.0); 51 dpfloat dpb = dpfloat(1.5, 1.0); 52 53 __bwd_diff(h)(dpa, dpb, 1.0); 54 55 outputBuffer[1] = dpa.d; // Expect: (2 * 2.0) + (2 * 1.5) = 7.0 56 outputBuffer[2] = dpb.d; // Expect: -(2 * 1.5) + (2 * 2.0) = 1.0 57 } 58 59 { 60 dphalf dpa = dphalf((half)2.0, (half)1.0); 61 dphalf dpb = dphalf((half)1.5, (half)1.0); 62 63 __bwd_diff(j)(dpa, dpb, 1.0); 64 65 outputBuffer[3] = dpa.d; // Expect: 1 66 outputBuffer[4] = dpb.d; // Expect: 0 67 } 68 69}