summaryrefslogtreecommitdiffstats
path: root/tests/compute/generic-interface-method.slang
blob: 47fa94f8976ca09f10c61c7f74fbbba4c45c191c (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//TEST(compute):COMPARE_COMPUTE:
//TEST(compute):COMPARE_COMPUTE:-cpu

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

struct DisneyBRDFPattern
{
    float3 baseColor;
    float3 normal;
    float specular, metallic, roughness;
    float opacity;
    float3 emmissive;
    float ambientOcclusion;  
};

struct VertexPosition
{
    float3 pos;
    float3 normal;
    float2 uv;
};

struct CameraView
{
    float3 camPos;
    float3 camDir;
};

interface IVertexInterpolant
{
    float4 getVertexColor(int index);
    int getVertexColorCount();
    float2 getUV(int index);
    int getUVCount();
}

interface IDisneyBRDFPattern
{
    __generic<TVertexInterpolant:IVertexInterpolant>
    DisneyBRDFPattern evalPattern(
        CameraView cam, 
        VertexPosition vWorld,  
        VertexPosition vObject, 
        TVertexInterpolant interpolants);
}

struct StandardVertexInterpolant : IVertexInterpolant
{
    float4 getVertexColor(int index) { return float4(0.0); }
    int getVertexColorCount() { return 0;}
    float2 getUV(int index) { return float2(0.0); }
    int getUVCount() {return 1; }
};

struct MaterialPattern1 : IDisneyBRDFPattern
{
    __generic<TVertexInterpolant:IVertexInterpolant>
    DisneyBRDFPattern evalPattern(
        CameraView cam, 
        VertexPosition vWorld,  
        VertexPosition vObject, 
        TVertexInterpolant interpolants)
    {
        DisneyBRDFPattern rs;
        rs.baseColor = float3(0.5);
        rs.opacity = 1.0;
        return rs;
    }
};

__generic<TVertexInterpolant:IVertexInterpolant, TPattern : IDisneyBRDFPattern>
float test(TVertexInterpolant vertInterps, TPattern pattern)
{
    CameraView cam;
    VertexPosition vW, vO;
    DisneyBRDFPattern rs = pattern.evalPattern(cam, vW, vO, vertInterps);    
    return rs.baseColor.x;
}
[numthreads(4, 1, 1)]
void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
{
    StandardVertexInterpolant vertInterp;
    MaterialPattern1 mp1;
	float outVal = test<StandardVertexInterpolant, MaterialPattern1>(vertInterp, mp1);
	outputBuffer[dispatchThreadID.x] = outVal;
}