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

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

This does work. 

Note that it *requires* the getType<T> function as if we try to call say int.getType(), we get an error around
swizzling.
*/

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

enum class Type
{
    Unknown,
    Float,
    Int,
};

interface IHasType
{
    static Type getType();
};

extension int : IHasType
{
    static Type getType() { return Type::Int; }
};

extension float : IHasType
{
    static Type getType() { return Type::Float; }
};

Type getType<T : IHasType>() { return T::getType(); }

[numthreads(4, 1, 1)]
void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
{    
    int index = dispatchThreadID.x;
    
    let type = getType<float>();
    
    outputBuffer[dispatchThreadID.x] = int(type);
}