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<float2> dpfloat2; 9typedef DifferentialPair<float3> dpfloat3; 10typedef DifferentialPair<float4> dpfloat4; 11 12[Differentiable] 13float4 f(float4 x) 14{ 15 return float4(x.rgb, x.a * x.a); 16} 17 18[numthreads(1, 1, 1)] 19void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID) 20{ 21 { 22 float4 a = float4(1.0, 2.0, 3.0, 4.0); 23 float4 da = float4(1.0, 0.5, 1.5, 2.5); 24 25 outputBuffer[0] = fwd_diff(f)(dpfloat4(a, da)).d.x; 26 } 27 28 { 29 float4 a = float4(1.0, 2.0, 3.0, 4.0); 30 31 var dpa = diffPair(a); 32 33 bwd_diff(f)(dpa, float4(1.0, 0.5, 1.5, 2.5)); 34 35 outputBuffer[1] = dpa.d.x; // 1.0 36 outputBuffer[2] = dpa.d.y; // 0.5 37 outputBuffer[3] = dpa.d.z; // 0.0 38 outputBuffer[4] = dpa.d.a; // 0.0 39 } 40}