summaryrefslogtreecommitdiffstats
path: root/tests/experiments/generic/explicit-specialization-3.slang
blob: e53f971582dfc46e217e29197c622af52ebf8569 (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:SIMPLE:-target hlsl -entry computeMain -profile cs_6_2

/* 
In C++ we are able to explicitly specialize over more than one type/value. Here we try to use a 'dummy' generic 
type such that an extension can be applied to it.

I can't just specialize a function also complicating things. 

If I try explicit function specialization in C++. In g++11.1 it will complain if there isn't a specialition visible. 
Visual studio it seems to assume it is available for import and doesn't complain.
*/

RWStructuredBuffer<float> outputBuffer;

interface IDoThing
{
    static float doThing(float v);
};

struct Combination<T, let V : int> {};

extension Combination<int, 10> : IDoThing
{
    static float doThing(float v)
    {
        return int(v) + 10;
    }
};

extension Combination<float, 20> : IDoThing
{
    static float doThing(float v)
    {
        return float(v) + 20;
    }
};


[numthreads(4, 1, 1)]
void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
{
    uint tid = dispatchThreadID.x;

    let v = Combination<float, 20>::doThing(tid) + 
        Combination<int, 10>::doThing(tid);
    
    // Produces an error - although the error message of typeof(Combination)
    // is probably not great.
    // 
    // slang(35): error 30027: 'doThing' is not a member of 'typeof(Combination)'.
    //
    //let y = Combination<int, 20>::doThing(tid);
    
    outputBuffer[tid] = v;
}