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 DifferentialPair<float3> dpfloat3; 10 11[ForwardDifferentiable] 12float f(float a) 13{ 14 return a * a + a; 15} 16 17[ForwardDifferentiable] 18float f(float3 a) 19{ 20 return a.x * a.y + a.z; 21} 22 23[ForwardDifferentiable] 24float g(float a) 25{ 26 // df((2.0, 4.0, 6.0), (1.0, 2.0, 3.0)) 27 // 2.0 * 2.0 + 4.0 * 1.0 + 3.0 = 11.0 28 return f(float3(a, 2*a, 3*a)); 29} 30 31[numthreads(1, 1, 1)] 32void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) 33{ 34 { 35 dpfloat dpa = dpfloat(2.0, 1.0); 36 dpfloat3 dpf3 = dpfloat3(float3(1.0, 3.0, 5.0), float3(0.5, 1.5, 2.5)); 37 38 outputBuffer[0] = f(dpa.p); // Expect: 6 39 outputBuffer[1] = f(dpf3.p); // Expect: 8 40 outputBuffer[2] = __fwd_diff(f)(dpf3).d; // Expect: 5.5 41 outputBuffer[3] = __fwd_diff(f)(dpa).d; // Expect: 5 42 outputBuffer[4] = __fwd_diff(g)(dpa).d; // Expect: 11.0 43 } 44}