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 8struct B : IDifferentiable 9{ 10 typedef B Differential; 11 12 float z; 13}; 14 15struct A : IDifferentiable 16{ 17 typedef B Differential; 18 19 [DerivativeMember(B.z)] 20 float x; 21 no_diff float y; 22 23 [__unsafeForceInlineEarly] 24 static Differential dzero() 25 { 26 B b = {0.0}; 27 return b; 28 } 29 30 [__unsafeForceInlineEarly] 31 static Differential dadd(Differential a, Differential b) 32 { 33 B o = {a.z + b.z}; 34 return o; 35 } 36 37 [__unsafeForceInlineEarly] 38 static Differential dmul<T : __BuiltinRealType>(T a, Differential b) 39 { 40 B o = {__realCast<float, T>(a) * b.z}; 41 return o; 42 } 43}; 44 45typedef DifferentialPair<A> dpA; 46 47[ForwardDifferentiable] 48A f(A a) 49{ 50 A aout; 51 aout.y = detach(2 * a.x); 52 aout.x = 5 * a.x; 53 54 return aout; 55} 56 57[numthreads(1, 1, 1)] 58void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) 59{ 60 { 61 A a = {1.0, 2.0}; 62 B b = {0.2}; 63 64 dpA dpa = dpA(a, b); 65 66 outputBuffer[0] = __fwd_diff(f)(dpa).d.z; // Expect: 1 67 } 68}