yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
d10732742
master
1// Test calling backward differentiable function through dynamic dispatch. 2 3//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type 4//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type 5//TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute -shaderobj -output-using-type 6 7//TEST_INPUT:ubuffer(data=[0 0 0 0 0], stride=4):out,name=outputBuffer 8RWStructuredBuffer<float> outputBuffer; 9 10[anyValueSize(16)] 11interface IInterface 12{ 13 [BackwardDifferentiable] 14 float calc(float x); 15} 16 17struct A : IInterface 18{ 19 float a; 20 [BackwardDifferentiable] 21 [NoDiffThis] 22 float calc(float x) { return a*x*x; } 23}; 24 25struct B : IInterface 26{ 27 float a; 28 [BackwardDifferentiable] 29 [NoDiffThis] 30 float calc(float x) { return a*x*x*x; } 31}; 32 33[BackwardDifferentiable] 34float run(IInterface obj, float x) 35{ 36 return obj.calc(x); 37} 38 39//TEST_INPUT: type_conformance A:IInterface = 0 40//TEST_INPUT: type_conformance B:IInterface = 1 41 42[numthreads(1, 1, 1)] 43void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) 44{ 45 var obj = createDynamicObject<IInterface>(dispatchThreadID.x, 0.5f); // A 46 var p = diffPair(3.0); 47 48 __bwd_diff(run)(obj, p, 1.0f); 49 outputBuffer[0] = p.d; // A.calc, expect 3 50 51 obj = createDynamicObject<IInterface>(dispatchThreadID.x + 1, 1.5f); // B 52 p = diffPair(3.0); 53 __bwd_diff(run)(obj, p, 1.0f); 54 outputBuffer[1] = p.d; // B.calc, expect 40.5 55}