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
2.4 KiB104 linesraw
1// interface-shader-param2.slang
2
3// This test builds on `interface-shader-param.slang` by using
4// concrete types that have data within them, instead of
5// just empty types.
6
7//DISABLED_TEST(compute):COMPARE_COMPUTE_EX:-slang -compute
8
9//DISABLED_TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -profile sm_6_0
10//DISABLED_TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute
11
12// A lot of the setup is the same as for `interface-shader-param`,
13// so look there if you want the comments.
14
15interface IRandomNumberGenerator
16{
17    [mutating]
18    int randomInt();
19}
20
21interface IRandomNumberGenerationStrategy
22{
23    associatedtype Generator : IRandomNumberGenerator;
24    Generator makeGenerator(int seed);
25}
26
27interface IModifier
28{
29    int modify(int val);
30}
31
32int test(
33    int                             seed,
34    IRandomNumberGenerationStrategy inStrategy,
35    IModifier                       modifier)
36{
37    let strategy = inStrategy;
38    var generator = strategy.makeGenerator(seed);
39    let unused = generator.randomInt();
40    let val = generator.randomInt();
41    let modifiedVal = modifier.modify(val);
42    return modifiedVal;
43}
44
45
46//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out
47RWStructuredBuffer<int> gOutputBuffer;
48
49//TEST_INPUT:cbuffer(data=[0 0 0 0 1 0 0 0], stride=4):
50ConstantBuffer<IRandomNumberGenerationStrategy> gStrategy;
51
52[numthreads(4, 1, 1)]
53void computeMain(
54
55//TEST_INPUT:root_constants(data=[0 0 0 0 8 0 0 0], stride=4):
56    uniform IModifier   modifier,
57            uint3       dispatchThreadID : SV_DispatchThreadID)
58{
59    let tid = dispatchThreadID.x;
60
61    let inputVal : int = tid;
62    let outputVal = test(inputVal, gStrategy, modifier);
63
64    gOutputBuffer[tid] = outputVal;
65}
66
67// Okay, now we get to the part that is unique starting
68// in this test: we add data to the concrete types
69// that we will use as parameters.
70
71struct MyStrategy : IRandomNumberGenerationStrategy
72{
73    int globalSeed;
74
75    struct Generator : IRandomNumberGenerator
76    {
77        int state;
78
79        [mutating]
80        int randomInt()
81        {
82            return state++;
83        }
84    }
85
86    Generator makeGenerator(int seed)
87    {
88        Generator generator = { seed ^ globalSeed };
89        return generator;
90    }
91}
92
93struct MyModifier : IModifier
94{
95    int localModifier;
96
97    int modify(int val)
98    {
99        return val ^ localModifier;
100    }
101}
102
103//TEST_INPUT: globalExistentialType MyStrategy
104//TEST_INPUT: entryPointExistentialType MyModifier