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], stride=4):out,name=outputBuffer 6RWStructuredBuffer<float> outputBuffer; 7 8typedef DifferentialPair<float> dpfloat; 9 10float f(float x) 11{ 12 return x*x; 13} 14 15[ForwardDerivativeOf(f)] 16DifferentialPair<float> df(DifferentialPair<float> x) 17{ 18 var primal = x.p * x.p; 19 var diff = 2 * x.p * x.d; 20 return DifferentialPair<float>(primal, diff); 21} 22 23[ForwardDifferentiable] 24float g(float x) 25{ 26 return f(x); 27} 28 29[numthreads(1, 1, 1)] 30void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID) 31{ 32 { 33 dpfloat dpa = dpfloat(3.0, 1.0); 34 35 outputBuffer[0] = f(dpa.p); // Expect: 9.0 36 outputBuffer[1] = __fwd_diff(g)(dpa).d; // Expect: 6.0 37 } 38}