yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
6a23949f0
master
1//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -shaderobj -output-using-type 2 3// Test that a default interface method can be differentiable. 4 5interface IFoo<int v> 6{ 7 [Differentiable] 8 float getVal(float x); 9 10 [Differentiable] 11 float getGreaterVal<int y>(float x) 12 { 13 return getVal(x) + y + v; 14 } 15} 16 17struct Impl : IFoo<2> 18{ 19 [Differentiable] 20 float getVal(float x) 21 { 22 return x*x; 23 } 24 25 // Using the default implementation for getGreaterVal. 26} 27 28[Differentiable] 29float test<int y, T:IFoo<y>>(T v, float x) { return v.getGreaterVal<1>(x); } 30 31//TEST_INPUT: set resultBuffer = out ubuffer(data=[0 0 0 0], stride=4) 32RWStructuredBuffer<float> resultBuffer; 33 34[numthreads(1,1,1)] 35void computeMain() 36{ 37 Impl impl = {}; 38 var dpx = diffPair(3.0); 39 bwd_diff(test)(impl, dpx, 1.0f); 40 resultBuffer[0] = dpx.d; 41 // CHECK: 6.0 42}