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], stride=4):out,name=outputBuffer 6RWStructuredBuffer<float> outputBuffer; 7 8struct A 9{ 10 float x; 11 12 [ForwardDerivative(diff_f)] 13 float f(float v) 14 { 15 return v * v; 16 } 17 18 DifferentialPair<float> diff_f(DifferentialPair<float> v) 19 { 20 return diffPair(v.p * v.p, v.p * v.d * 2.0); 21 } 22} 23 24[ForwardDifferentiable] 25float test(A obj, float v) 26{ 27 return obj.f(v); 28} 29 30[numthreads(1, 1, 1)] 31void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) 32{ 33 A a = {0.0}; 34 var p = diffPair(3.0, 1.0); 35 let rs = __fwd_diff(test)(a, p); 36 outputBuffer[0] = rs.d; 37}