summaryrefslogtreecommitdiffstats
path: root/tests/language-feature/inheritance/struct-inheritance.slang
blob: 046a3f6b260f90ba7e57b21db8367631ad4c15ae (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
53
54
55
56
57
58
59
60
61
// struct-inheritance.slang

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

// Test that we can define a `struct` type
// that inherits from another `struct`.

#pragma warning(disable:30816)

struct Base
{
	int a;

	int tweakBase(int val) { return val ^ a; }
}

struct Derived : Base
{
	int b;

	int tweakDerived(int val) { return tweakBase(val) + b; }
}

int tweak(Base b, int v)
{
	return b.tweakBase(v);
}

//TEST_INPUT:cbuffer(data=[1 2]):name=C
cbuffer C
{
	int x;
	int y;
}

int test(int val)
{
	Derived d;// = { x, y };
	d.a = x;
	d.b = y;

	int result = 0;
	result = result*16 + d.a;
	result = result*16 + d.tweakBase(val);
	result = result*16 + tweak(d, val);
	result = result*16 + d.tweakDerived(val);
	return result;
}

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