yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
639978008
master
1// mutating-and-inout.slang 2 3// Test that calling a `[mutating]` method on an `inout` function parameter works. 4 5//TEST(compute):COMPARE_COMPUTE: -cuda 6//TEST(compute):COMPARE_COMPUTE: -vk 7 8//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer 9RWStructuredBuffer<int> outputBuffer; 10 11struct A 12{ 13 int x; 14 15 [mutating] void doThings(inout int y) 16 { 17 int tmp = x; 18 x = y; 19 y = tmp; 20 } 21} 22 23int doThings(inout A a, int val) 24{ 25 a.doThings(val); 26 return val; 27} 28 29int test(int val) 30{ 31 A a = { val }; 32 int b = val ^ 3; 33 34 int c = doThings(a, b); 35 36 int result = 0; 37 result = result*16 + a.x; 38 result = result*16 + b; 39 result = result*16 + c; 40 41 return result; 42} 43 44[numthreads(4, 1, 1)] 45void computeMain(int3 tid : SV_DispatchThreadID) 46{ 47 int val = tid.x; 48 val = test(val); 49 outputBuffer[tid.x] = val; 50}