summaryrefslogtreecommitdiffstats
path: root/tests/language-feature/cond-field.slang
blob: 5e9f4a06e49edf882025c38e9320f4468e4218a6 (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
62
63
64
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -vk

interface IVertex
{
    property float3 position{get;}
    property Optional<float3> normal{get;}
    property Optional<float3> color{get;}
}

struct Vertex<bool hasNormal, bool hasColor> : IVertex
{
    private float3 m_position;
    private Conditional<float3, hasNormal> m_normal;
    private Conditional<float3, hasColor> m_color;

    __init(float3 position, float3 normal, float3 color)
    {
        m_position = position;
        m_normal = normal;
        m_color = color;
    }

    property float3 position
    {
        get { return m_position; }
    }
    property Optional<float3> normal
    {
        get { return m_normal; }
    }
    property Optional<float3> color
    {
        get { return m_color; }
    }
}

//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
RWStructuredBuffer<int> outputBuffer;

void test<V:IVertex>(V vert)
{
    // CHECK: 0
    // CHECK: 0
    // CHECK: 1
    // CHECK: 3
    if (let normal = vert.normal)
    {
         outputBuffer[0] = 1;
         outputBuffer[1] = (int)normal.x;
    }

    if (let color = vert.color)
    {
        outputBuffer[2] = 1;
        outputBuffer[3] = (int)color.x;
    }
}

[numthreads(1,1,1)]
void computeMain()
{
    test<Vertex<false, true>>(Vertex<false, true>(1.0, 2.0, 3.0));
}