yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
7349dc5cf
master
1//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -shaderobj 2//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -vk -shaderobj 3//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -cpu -shaderobj 4 5//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0], stride=4):out,name=outputBuffer 6RWStructuredBuffer<int> outputBuffer; 7 8interface IThing 9{ 10 [mutating] 11 int thing(int index); 12} 13 14struct MyThing: IThing 15{ 16 int val; 17 18 [mutating] 19 int thing(int index) 20 { 21 val++; 22 outputBuffer[index] = val; 23 return val; 24 } 25} 26 27struct NotMyThing 28{ 29 int val; 30} 31 32void f<T>(inout T t, int index) where optional T: IThing 33{ 34 if (T is IThing) 35 { 36 outputBuffer[index+1] = 2 * t.thing(index); 37 } 38 else 39 { 40 outputBuffer[index] = 0; 41 outputBuffer[index+1] = 0; 42 } 43} 44 45[numthreads(1, 1, 1)] 46void computeMain(int3 dispatchThreadID: SV_DispatchThreadID) 47{ 48 MyThing mt = MyThing(0); 49 NotMyThing nt = NotMyThing(1); 50 51 // CHECK: 1 52 // CHECK-NEXT: 2 53 f<MyThing>(mt, 0); 54 // CHECK-NEXT: 0 55 // CHECK-NEXT: 0 56 f<NotMyThing>(nt, 2); 57 // CHECK: 2 58 // CHECK-NEXT: 4 59 f(mt, 4); 60 // CHECK-NEXT: 0 61 // CHECK-NEXT: 0 62 f(nt, 6); 63}