summaryrefslogtreecommitdiff
path: root/tests/compute/generic-list.slang
blob: 118cbaed6b8785d771bb6c61783088ef959a519b (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
//TEST(compute):COMPARE_COMPUTE:
//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):dxbinding(0),glbinding(0),out
// Confirm that generics syntax can be used in user
// code and generates valid output.

RWStructuredBuffer<float4> outputBuffer;

interface IElement
{
    float4 getValue();
};

struct SingleElement : IElement
{
    float4 value;
    float4 getValue()
    {
        return value;
    }
};

struct ListElement<THead : IElement, TTail : IElement> : IElement
{
    THead head;
    TTail tail;
    float4 getValue()
    {
        return head.getValue() + tail.getValue();
    }
};

float4 test<T : IElement>(T val)
{
    return val.getValue();
}


[numthreads(1, 1, 1)]
void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
{
    ListElement<SingleElement, ListElement<SingleElement, ListElement<SingleElement, SingleElement> > > list;
    list.head.value = float4(1.0);
    list.tail.head.value = float4(2.0);
    list.tail.tail.head.value = float4(3.0);
    list.tail.tail.tail.value = float4(4.0);
    float4 outVal = test(list);
    outputBuffer[0] = outVal;
}