yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
d10732742
master
1//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type 2//TEST(compute):COMPARE_COMPUTE_EX:-slang -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 0 0 0 0], stride=4):out,name=outputBuffer 6RWStructuredBuffer<float> outputBuffer; 7 8typedef DifferentialPair<float> dpfloat; 9 10[BackwardDifferentiable] 11float f(float x) 12{ 13 return exp(x); 14} 15 16[BackwardDifferentiable] 17float g(float x) 18{ 19 return sin(x); 20} 21 22[BackwardDifferentiable] 23float h(float x) 24{ 25 return cos(x); 26} 27 28[numthreads(1, 1, 1)] 29void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID) 30{ 31 { 32 dpfloat dpa = dpfloat(2.0, 1.0); 33 34 outputBuffer[0] = f(dpa.p); // Expect: 7.389056 35 outputBuffer[1] = __fwd_diff(f)(dpa).d; // Expect: 7.389056 36 outputBuffer[2] = g(dpa.p); // Expect: 0.909297 37 outputBuffer[3] = __fwd_diff(g)(dpa).d; // Expect: -0.416146 38 outputBuffer[4] = h(dpa.p); // Expect: -0.416146 39 outputBuffer[5] = __fwd_diff(h)(dpa).d; // Expect: -0.909297 40 } 41 42 { 43 dpfloat dpa = dpfloat(2.0, 0.0); 44 __bwd_diff(f)(dpa, 1.0); 45 outputBuffer[6] = dpa.d; // Expect: 7.389056 46 __bwd_diff(g)(dpa, 1.0); 47 outputBuffer[7] = dpa.d; // Expect: -0.416146 48 __bwd_diff(h)(dpa, 1.0); 49 outputBuffer[8] = dpa.d; // Expect: -0.909297 50 } 51}