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, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-vk -compute -shaderobj -output-using-type 3//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-cuda -compute -shaderobj -output-using-type 4 5//TEST_INPUT:ubuffer(data=[0], stride=4):out,name=outputBuffer 6RWStructuredBuffer<float> outputBuffer; 7 8interface IFoo : IDifferentiable 9{ 10 [Differentiable] 11 __init<T:IFoo>(T d); 12 13 [Differentiable] 14 static This create(Differential d); 15 16 [Differentiable] 17 float getVal(); 18} 19 20struct Impl : IFoo 21{ 22 float x; 23 [Differentiable] 24 __init<T : IFoo>(T d) 25 { 26 this = (Impl)d; 27 } 28 29 [Differentiable] 30 static This create(Differential d) 31 { 32 This v; 33 v.x = d.x * d.x; 34 return v; 35 } 36 37 [Differentiable] 38 float getVal() { return x; } 39} 40 41[Differentiable] 42float test<T:IFoo>(T.Differential d) 43{ 44 return T.create(d).getVal(); 45} 46 47[numthreads(1,1,1)] 48void computeMain(uint threadId: SV_DispatchThreadID) 49{ 50 Impl.Differential d; 51 d.x = 3.0; 52 Impl.Differential dd; 53 dd.x = 1.0; 54 outputBuffer[0] = fwd_diff(test<Impl>)(diffPair(d, dd)).d; 55 // CHECK: 6.0 56}