yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

James Helferty (NVIDIA)render-test: Change D3D12 default to sm_6_5 (#8320)f02b08490

master
1.7 KiB76 linesraw
1// Test using interface typed shader parameters with associated types.
2
3//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -profile sm_6_0
4//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx11 -profile sm_5_0
5//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -vk -profile glsl_440
6//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -cpu
7
8
9
10[anyValueSize(8)]
11interface IAssoc
12{
13    int eval();
14}
15
16[anyValueSize(8)]
17interface IInterface
18{
19    associatedtype TAssoc : IAssoc;
20    TAssoc run(int input);
21}
22
23//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=gOutputBuffer
24RWStructuredBuffer<int> gOutputBuffer;
25
26//TEST_INPUT: set gCb = new StructuredBuffer<IInterface>{new MyImpl{1}};
27RWStructuredBuffer<IInterface> gCb;
28
29//TEST_INPUT: set gCb1 = new StructuredBuffer<IInterface>{new MyImpl{1}}
30RWStructuredBuffer<IInterface> gCb1;
31
32[numthreads(4, 1, 1)]
33void computeMain(int3       dispatchThreadID : SV_DispatchThreadID)
34{
35    let tid = dispatchThreadID.x;
36
37    let inputVal : int = tid;
38    IInterface v0 = gCb.Load(0);
39    IInterface v1 = gCb1[0];
40    let outputVal = v0.run(inputVal).eval() + v1.run(inputVal).eval();
41
42    gOutputBuffer[tid] = outputVal;
43}
44
45// Type must be marked `public` to ensure it is visible in the generated DLL.
46export struct MyImpl : IInterface
47{
48    int val;
49    export struct TAssoc : IAssoc
50    {
51        int val;
52        int eval() { return val; }
53    }
54    TAssoc run(int input)
55    {
56        TAssoc rs;
57        rs.val = input + val;
58        return rs;
59    }
60};
61
62export struct MyImpl2 : IInterface
63{
64    int val;
65    export struct TAssoc : IAssoc
66    {
67        int val;
68        int eval() { return val; }
69    }
70    TAssoc run(int input)
71    {
72        TAssoc rs;
73        rs.val = input - val;
74        return rs;
75    }
76};