summaryrefslogtreecommitdiffstats
path: root/tests/language-feature/extensions/interface-extension.slang
blob: 88ef908d8577c01b6efc3e342bcbeb0f6c8d2f6c (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
52
// interface-extension.slang

// Test that an `extension` applied to an interface type works as users expect

//TEST(compute):COMPARE_COMPUTE: -shaderobj
//TEST(compute):COMPARE_COMPUTE: -vk -shaderobj

interface ICounter
{
	[mutating] void add(int value);
}

struct MyCounter : ICounter
{
	int _state = 0;

	[mutating] void add(int value) { _state += value; }
}

__generic<T : ICounter>
extension T
{
	[mutating] void increment()
	{
	    this.add(1);
	}
}

void helper<T : ICounter>(in out T counter)
{
	counter.increment();
}

int test(int value)
{
	MyCounter counter = { value };
	counter.increment();
	helper(counter);
	return counter._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;
    int inVal = tid;
    int outVal = test(inVal);
    outputBuffer[tid] = outVal;
}