yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
739c3a7b5
master
1//TEST:SIMPLE(filecheck=CHECK): -target hlsl -profile cs_5_0 -entry computeMain -line-directive-mode none 2 3// Check that user code can declare and use a generic 4// `struct` type. 5 6//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer 7RWStructuredBuffer<int> outputBuffer; 8 9interface ITest 10{ 11 int doThing(int x); 12}; 13 14struct Impl1 : ITest 15{ 16 int doThing(int x) 17 { 18 return x * 2; 19 } 20}; 21 22struct Impl2 23{ 24 int doSomethingElse(int x) 25 { 26 return x * 3; 27 } 28}; 29 30__generic<T : ITest = Impl2> 31// CHECK: tests/diagnostics/generic-incorrect-default-arg.slang([[@LINE-1]]): error 38029: type argument 'Impl2' does not conform to the required interface 'ITest' 32struct GenStruct 33{ 34 T obj; 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}