yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
712ce653d
master
1// mutating-methods.slang 2//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -xslang -serial-ir -shaderobj 3//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -xslang -serial-ir -shaderobj 4//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -xslang -serial-ir -shaderobj 5//TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -xslang -serial-ir -shaderobj 6 7interface IAccumulator 8{ 9 [mutating] void accumulate(int v); 10} 11 12struct Accumulator : IAccumulator 13{ 14 int state; 15 16 [mutating] void accumulate(int v) 17 { 18 state += v; 19 } 20 21 [mutating] void accumulateMore(int v) 22 { 23 this.state += v; 24 } 25} 26 27void doStuff<A : IAccumulator>(inout A a) 28{ 29 a.accumulate(16); 30} 31 32int test(int x) 33{ 34 Accumulator a; 35 a.state = 0; 36 37 a.accumulate(x); 38 a.accumulateMore(x); 39 doStuff(a); 40 41 return a.state; 42} 43 44//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer 45RWStructuredBuffer<int> outputBuffer; 46 47[numthreads(4, 1, 1)] 48void computeMain(int3 dispatchThreadID : SV_DispatchThreadID) 49{ 50 int tid = dispatchThreadID.x; 51 outputBuffer[tid] = test(tid); 52}