forked from shader-slang/slang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmutating-methods.slang
52 lines (42 loc) · 1.04 KB
/
mutating-methods.slang
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
52
// mutating-methods.slang
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -xslang -serial-ir -shaderobj
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -xslang -serial-ir -shaderobj
//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -xslang -serial-ir -shaderobj
//TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -xslang -serial-ir -shaderobj
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):out,name=outputBuffer
RWStructuredBuffer<int> outputBuffer;
[numthreads(4, 1, 1)]
void computeMain(int3 dispatchThreadID : SV_DispatchThreadID)
{
int tid = dispatchThreadID.x;
outputBuffer[tid] = test(tid);
}