yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
86fc50c50
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:-cpu -compute -output-using-type -shaderobj 4 5//TEST_INPUT:ubuffer(data=[0 0 0 0 0], stride=4):out,name=outputBuffer 6RWStructuredBuffer<float> outputBuffer; 7 8float original(float x) 9{ 10 return x * x; 11} 12 13[PrimalSubstituteOf(original)] 14[BackwardDifferentiable] 15float primalSubst(float x) 16{ 17 return 2.0f * x * x; 18} 19 20[BackwardDifferentiable] 21float caller(float x) 22{ 23 return original(x); 24} 25 26[numthreads(1, 1, 1)] 27void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) 28{ 29 var a = diffPair(3.0, 1.0); 30 __bwd_diff(caller)(a, 1.0); 31 outputBuffer[0] = a.d; // Expect: 12.0 32 outputBuffer[1] = __fwd_diff(caller)(diffPair(3.0, 1.0)).p; // Expect: 18.0 33 outputBuffer[2] = caller(3.0); // Expect: 9.0 34}