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], stride=4):out,name=outputBuffer 6RWStructuredBuffer<float> outputBuffer; 7 8typedef DifferentialPair<float> dpfloat; 9typedef DifferentialPair<float2> dpfloat2; 10 11[BackwardDifferentiable] 12float diffLog(float x) 13{ 14 return log(x); 15} 16 17[BackwardDifferentiable] 18float2 diffLog(float2 x) 19{ 20 return log(x); 21} 22 23[numthreads(1, 1, 1)] 24void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID) 25{ 26 { 27 dpfloat dpa = dpfloat(10.0, 0.0); 28 __bwd_diff(diffLog)(dpa, 3.0); 29 outputBuffer[0] = dpa.d; // Expect: 0.300000 30 } 31 32 { 33 dpfloat2 dpx = dpfloat2(float2(2.0, 5.0), float2(0.0, 0.0)); 34 __bwd_diff(diffLog)(dpx, float2(1.0, 1.0)); 35 outputBuffer[1] = dpx.d[0]; // Expect: 0.500000 36 outputBuffer[2] = dpx.d[1]; // Expect: 0.200000 37 } 38}