yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
05547e253
master
1//TEST(compute):COMPARE_COMPUTE: -shaderobj 2//TEST(compute):COMPARE_COMPUTE:-cpu -shaderobj 3 4// Check that user code can declare and use a generic 5// `struct` type. 6 7//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer 8RWStructuredBuffer<int> outputBuffer; 9 10interface ITest 11{ 12 int doThing(int x); 13}; 14 15struct Impl1 : ITest 16{ 17 int doThing(int x) 18 { 19 return x * 2; 20 } 21}; 22 23struct Impl2 : ITest 24{ 25 int doThing(int x) 26 { 27 return x * 3; 28 } 29}; 30 31__generic<T : ITest = Impl1> 32struct GenStruct 33{ 34 T obj = T(); 35}; 36 37int test(GenStruct gs, int val) 38{ 39 return gs.obj.doThing(val); 40} 41 42[numthreads(4, 1, 1)] 43void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) 44{ 45 int tid = dispatchThreadID.x; 46 47 int outVal = 0; 48 49 GenStruct<Impl1> gs; 50 outVal += test(gs, tid); 51 52 outputBuffer[tid] = outVal; 53}