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 float calc<T:IFoo>(T t, float x); 18} 19 20struct A : IFoo 21{ 22 float f() { return 1.0; } 23}; 24 25struct B : IInterface 26{ 27 float calc<T : IFoo>(T t, float x) 28 { 29 return t.f() * x; 30 } 31}; 32 33[BackwardDifferentiable] 34float test(IInterface obj, float x) 35{ 36 A objA; 37 return no_diff(obj.calc(objA, x)) * x; 38} 39 40//TEST_INPUT: type_conformance A:IFoo = 0 41//TEST_INPUT: type_conformance B:IInterface = 1 42 43[numthreads(1, 1, 1)] 44void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) 45{ 46 var obj = createDynamicObject<IInterface>(dispatchThreadID.x, 1); // B 47 var p = diffPair(3.0); 48 __bwd_diff(test)(obj, p, 1.0); 49 outputBuffer[0] = p.d; 50}