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(filecheck-buffer=CHECK):-slang -compute -shaderobj -output-using-type 2//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-cuda -compute -shaderobj -output-using-type 3 4//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer 5RWStructuredBuffer<float> outputBuffer; 6 7[Differentiable] 8float h_outer(float a, float b, float c) 9{ 10 const float3x2 m2 = float3x2(2 * a, 0.0, 11 0.0, 3 * b, 12 0.0, 5 * c); 13 14 const float3x3 m1 = float3x3(1.f); 15 return h(m1, m2); 16} 17 18[Differentiable] 19float h(float3x3 x, float3x2 y) 20{ 21 let res = mul(x, y); 22 return dot(mul(res, float2(1.0)), float3(1.0)); 23} 24 25[numthreads(1, 1, 1)] 26void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) 27{ 28 // Do a bwd_diff test for h_outer 29 var dpa = diffPair(1.f, 0.f); 30 var dpb = diffPair(1.f, 0.f); 31 var dpc = diffPair(1.f, 0.f); 32 bwd_diff(h_outer)(dpa, dpb, dpc, 1.f); 33 34 outputBuffer[1] = dpa.d; 35 outputBuffer[2] = dpb.d; 36 outputBuffer[3] = dpc.d; 37 38 // CHECK: type: float 39 // CHECK: 6.0 40 // CHECK: 9.0 41 // CHECK: 15.0 42}