diff options
Diffstat (limited to 'tests/compute/mutating-methods.slang')
| -rw-r--r-- | tests/compute/mutating-methods.slang | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/compute/mutating-methods.slang b/tests/compute/mutating-methods.slang new file mode 100644 index 000000000..736d4f7e0 --- /dev/null +++ b/tests/compute/mutating-methods.slang @@ -0,0 +1,51 @@ +// mutating-methods.slang +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 +//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute + +interface IAccumulator +{ + [mutating] void accumulate(int v); +} + +struct Accumulator : IAccumulator +{ + int state; + + [mutating] void accumulate(int v) + { + state += v; + } + + [mutating] void accumulateMore(int v) + { + this.state += v; + } +} + +void doStuff<A : IAccumulator>(inout A a) +{ + a.accumulate(16); +} + +int test(int x) +{ + Accumulator a; + a.state = 0; + + a.accumulate(x); + a.accumulateMore(x); + doStuff(a); + + return a.state; +} + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):dxbinding(0),glbinding(0),out +RWStructuredBuffer<int> outputBuffer; + +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + int tid = dispatchThreadID.x; + outputBuffer[tid] = test(tid); +} |
