summaryrefslogtreecommitdiffstats
path: root/tests/compute/generic-interface-method-simple.slang
blob: 0e20947d16a48bfb6ff2c9e2af4cf202154d5991 (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
//TEST(compute):COMPARE_COMPUTE: -shaderobj
//TEST(compute):COMPARE_COMPUTE:-cpu -shaderobj

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

interface IVertexInterpolant
{
    float2 getUV();
}

interface IBRDFPattern
{
    __generic<TVertexInterpolant:IVertexInterpolant>
    float evalPattern(TVertexInterpolant interpolants);
}

struct StandardVertexInterpolant : IVertexInterpolant
{
    float2 getUV() { return float2(0.5); }
};

struct MaterialPattern1 : IBRDFPattern
{
    float base;
    __generic<TVertexInterpolant:IVertexInterpolant>
    float evalPattern(TVertexInterpolant interpolants)
    {
        float rs = base + interpolants.getUV().x;
        return rs;
    }
};

__generic<TPattern : IBRDFPattern, TInterpolant: IVertexInterpolant>
float test(TPattern pattern, TInterpolant vertInterps)
{
    float rs = pattern.evalPattern<TInterpolant>(vertInterps);    
    return rs;
}

[numthreads(4, 1, 1)]
void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
{
    StandardVertexInterpolant vertInterp;
    MaterialPattern1 mp1;
    mp1.base = 0.5;
	float outVal = test<MaterialPattern1, StandardVertexInterpolant>(mp1, vertInterp);
	outputBuffer[dispatchThreadID.x] = outVal;
}