yum-mirror/slang

Making it easier to work with shaders

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

Yong HeSupport visibility control and default to `internal`. (#3380)11111e573

master
1.1 KiB48 linesraw
1// Test using existential shader parameter that is an interface array.
2
3//TEST(compute):COMPARE_COMPUTE:-cpu
4//TEST(compute):COMPARE_COMPUTE:-cuda
5
6[anyValueSize(8)]
7interface IInterface
8{
9    int run(int input);
10}
11
12//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=gOutputBuffer
13RWStructuredBuffer<int> gOutputBuffer;
14
15struct Params
16{
17    IInterface values[2];
18};
19
20//TEST_INPUT:set gCb = new{ values: [ new MyImpl{ val: 1 } ] }
21ConstantBuffer<Params> gCb;
22
23//TEST_INPUT:set gCb2 = new{ values: [ new MyImpl{ val: 1 } ] }
24ConstantBuffer<Params> gCb2;
25
26[numthreads(4, 1, 1)]
27void computeMain(uint3       dispatchThreadID : SV_DispatchThreadID)
28{
29    let tid = dispatchThreadID.x;
30
31    let inputVal : int = int(tid);
32    let outputVal = gCb.values[0].run(inputVal) + gCb2.values[0].run(inputVal);
33
34    gOutputBuffer[tid] = outputVal;
35}
36
37//TEST_INPUT: globalExistentialType MyImpl
38//TEST_INPUT: globalExistentialType __Dynamic
39
40// Type must be marked `public` to ensure it is visible in the generated DLL.
41export struct MyImpl : IInterface
42{
43    int val;
44    int run(int input)
45    {
46        return input + val;
47    }
48};