summaryrefslogtreecommitdiffstats
path: root/tests/language-feature/interfaces/optional-none.slang
blob: 04bb8f83ea1620507c0d593ac2a8d64c61d0051c (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
// Test that the size of an optional interface type is the same as the existential box.

//TEST:SIMPLE(filecheck=CHECK): -target hlsl -conformance "Impl1:IFoo=1" -entry computeMain -profile cs_6_0
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=BUFFER): -output-using-type
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=BUFFER): -vk -shaderobj -output-using-type

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

interface IFoo
{
    int method();
}

//TEST_INPUT: type_conformance Impl1:IFoo = 0
struct Impl1 : IFoo
{
    int data;
    int method() { return data + 1; }
}

struct MyType
{
    Optional<IFoo> foo;
}

Optional<T> process<T>(Optional<T> opt)
{
    return opt;
}

[numthreads(1, 1, 1)]
void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID)
{
    MyType t = {};
    t.foo = process(t.foo);

    // BUFFER: 100
    if (let f = t.foo)
        outputBuffer[0] = f.method();
    else
        outputBuffer[0] = 100;
}

// CHECK: struct MyType
// CHECK-NEXT: {
// CHECK-NEXT: Tuple{{.*}} foo{{.*}};