yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
9ec6b9168
master
1// interface-extension.slang 2 3// Test that an `extension` applied to an interface type works as users expect 4 5//TEST(compute):COMPARE_COMPUTE: -shaderobj 6//TEST(compute):COMPARE_COMPUTE: -vk -shaderobj 7 8interface ICounter 9{ 10 [mutating] void add(int value); 11} 12 13struct MyCounter : ICounter 14{ 15 int _state = 0; 16 17 [mutating] void add(int value) { _state += value; } 18} 19 20__generic<T : ICounter> 21extension T 22{ 23 [mutating] void increment() 24 { 25 this.add(1); 26 } 27} 28 29void helper<T : ICounter>(in out T counter) 30{ 31 counter.increment(); 32} 33 34int test(int value) 35{ 36 MyCounter counter = { value }; 37 counter.increment(); 38 helper(counter); 39 return counter._state; 40} 41 42//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer 43RWStructuredBuffer<int> outputBuffer; 44 45[numthreads(4, 1, 1)] 46void computeMain(int3 dispatchThreadID : SV_DispatchThreadID) 47{ 48 int tid = dispatchThreadID.x; 49 int inVal = tid; 50 int outVal = test(inVal); 51 outputBuffer[tid] = outVal; 52}