summaryrefslogtreecommitdiffstats
path: root/tests/language-feature/generics/generic-shader-object.slang
blob: 06c817e3306525d4a8fa2af7513c0c5bd52f6be3 (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(filecheck-buffer=CHECK): -d3d11 -shaderobj -output-using-type
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -d3d12 -shaderobj -output-using-type
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -vk -shaderobj -output-using-type
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -cpu -shaderobj -output-using-type

interface IFoo
{
    float getVal();
}
interface IElement
{
    float getElementVal();
}

struct Elem : IElement
{
    float x;
    float getElementVal()
    {
        return x;
    }
}

struct Impl<T1:IElement, T2:IElement> : IFoo
{
    RWStructuredBuffer<T1> buffer0;
    RWStructuredBuffer<T2> buffer1;

    float getVal()
    {
        return buffer0[0].getElementVal() + buffer1[0].getElementVal();
    }
}

//TEST_INPUT:set gFoo = new Impl<Elem,Elem>{ubuffer(data=[1.0], stride = 4), ubuffer(data=[2.0], stride = 4)}
//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
//TEST_INPUT:set v = 1.0;

[numthreads(1, 1, 1)]
void computeMain(
    uniform ParameterBlock<Impl<Elem, Elem>> gFoo,
    uniform float v,
    uniform RWStructuredBuffer<float> outputBuffer
)
{
    // CHECK: 4.0
    outputBuffer[0] = gFoo.getVal() + v;
}