yum-mirror/slang

Making it easier to work with shaders

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

Yong HeDon't treat StrcturedBuffer<IFoo> as a specializable param. (#5645)43728fbda

master
1.3 KiB52 linesraw
1// Test using interface typed shader parameters wrapped inside a `StructuredBuffer`.
2
3//TEST(compute):COMPARE_COMPUTE:-cpu -shaderobj
4//TEST(compute):COMPARE_COMPUTE:-dx11
5//TEST(compute):COMPARE_COMPUTE:-vk
6//TEST(compute):COMPARE_COMPUTE:-cuda -shaderobj
7
8[anyValueSize(8)]
9interface IInterface
10{
11    int run(int input);
12}
13
14// Specialize gCb1, but not gCb2
15
16//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=gOutputBuffer
17RWStructuredBuffer<int> gOutputBuffer;
18//TEST_INPUT: set gCb = new StructuredBuffer<IInterface>{new MyImpl{1}};
19RWStructuredBuffer<IInterface> gCb;
20//TEST_INPUT: set gCb1 = new StructuredBuffer<IInterface>{new MyImpl{1}, new MyImpl2{2}};
21RWStructuredBuffer<IInterface> gCb1;
22
23[numthreads(4, 1, 1)]
24void computeMain(int3       dispatchThreadID : SV_DispatchThreadID)
25{
26    let tid = dispatchThreadID.x;
27
28    let inputVal : int = tid;
29    IInterface v0 = gCb.Load(0);
30    IInterface v1 = gCb1[0];
31    let outputVal = v0.run(inputVal) + v1.run(inputVal);
32
33    gOutputBuffer[tid] = outputVal;
34}
35
36// Type must be marked `public` to ensure it is visible in the generated DLL.
37export struct MyImpl : IInterface
38{
39    int val;
40    int run(int input)
41    {
42        return input + val;
43    }
44};
45export struct MyImpl2 : IInterface
46{
47    int val;
48    int run(int input)
49    {
50        return input - val;
51    }
52};