summaryrefslogtreecommitdiffstats
path: root/tests/experiments/generic/type-to-value-5.slang
blob: ce3271d476b0110a847d68e01c9579ab6c44287c (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
//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj

/* Test here is to try and associate a value with a type

Here we try to associate by having a value defined on the type, and then set the type
on the associated type.

Doesn't work because ...

.slang(29): error 30027: 'Type' is not a member of '.This'.
    return e::Type::kE;
    
*/

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

enum class Enum
{
    A, B
};

interface IHasType
{
    associatedtype Type;   
};

// This is a little perverse, because I'm defining as an associated type that is
// the same as itself
struct A : IHasType
{
    typedef A Type;
    static const Enum kE = Enum::A;
};

struct B : IHasType
{
    typedef B Type;
    static const Enum kE = Enum::B;
};

Enum getType(IHasType e)
{
    return e::Type::kE;
}

[numthreads(4, 1, 1)]
void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
{    
    int index = dispatchThreadID.x;
   
    B b;
    let e = getType(b);
    
    outputBuffer[dispatchThreadID.x] = int(e);
}