summaryrefslogtreecommitdiff
path: root/tests/compute/mutating-methods.slang
blob: 8192acd827f369ffc66b7e10eafa094e7d771a8a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// mutating-methods.slang
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -xslang -serial-ir
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -xslang -serial-ir
//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -xslang -serial-ir

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);
}