summaryrefslogtreecommitdiffstats
path: root/tests/bugs/specialize-existential-in-generic.slang
blob: cb05aea1467bcaae3b1e1448c9def0e354b95434 (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
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj

[Specialize]
interface IAssoc
{
    int getInner();
}

interface IFoo
{
    associatedtype Assoc : IAssoc;
    Assoc getValue();
}

struct Impl : IFoo
{
    struct Assoc : IAssoc { int getInner() { return 1; } }
    Assoc getValue() { Assoc r; return r; }
}

struct GenType<T : IFoo> : IDefaultInitializable
{
    T obj;
    int doThing()
    {
        IAssoc soc = obj.getValue(); // "boxing" into an existential

        // a specialized version of this function should call specialized method instead of going through dynamic dispatch.
        return soc.getInner();
    }
}

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

[numthreads(4, 1, 1)]
void computeMain(int3 dispatchThreadID: SV_DispatchThreadID)
{
    int tid = dispatchThreadID.x;
    GenType<Impl> val;
    gOutputBuffer[tid] = val.doThing();
}