yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
d10732742
master
1// Test calling dynamic dispatched generic function from differentiable function. 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], stride=4):out,name=outputBuffer 8RWStructuredBuffer<float> outputBuffer; 9 10interface IFoo 11{ 12 float f(); 13} 14 15interface IInterface 16{ 17 [BackwardDifferentiable] 18 float calc<T:IFoo>(T t, float x); 19} 20 21struct A : IFoo 22{ 23 float f() { return 5.0; } 24}; 25 26struct B : IInterface 27{ 28 [BackwardDifferentiable] 29 float calc<T : IFoo>(T t, float x) 30 { 31 return t.f() * x; 32 } 33}; 34 35[BackwardDifferentiable] 36float test(IFoo foo, IInterface obj, float x) 37{ 38 return obj.calc(foo, x) * x; 39} 40 41//TEST_INPUT: type_conformance A:IFoo = 0 42//TEST_INPUT: type_conformance B:IInterface = 1 43 44[numthreads(1, 1, 1)] 45void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) 46{ 47 var obj = createDynamicObject<IInterface>(dispatchThreadID.x, 1); // B 48 var foo = createDynamicObject<IFoo>(0, 0); // A 49 var p = diffPair(3.0); 50 __bwd_diff(test)(foo, obj, p, 1.0); 51 outputBuffer[0] = p.d; 52}