summaryrefslogtreecommitdiffstats
path: root/tests/language-feature/shader-params/interface-shader-param-ordinary.slang
blob: 6edc9435f0ec76c44a5aa3db6e23bd2908539432 (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
// interface-shader-param-ordinary.slang

// This test is for interface-type shader parameters that
// get specialized to types that include "ordinary" data
// but also don't fit into the allocation provided for
// them in the existential-type field itself.

//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -profile sm_6_0
//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute
//DISABLE_TEST(compute):COMPARE_COMPUTE:-slang -shaderobj -mtl
// Slang-RHI/WGPU: Too small buffer is bound #5604
//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-wgpu

interface IModifier
{
    int modify(int value);
}

//TEST_INPUT:set gOutputBuffer = out ubuffer(data=[0 0 0 0], stride=4)
RWStructuredBuffer<int> gOutputBuffer;

//TEST_INPUT:set delta = 65536
uniform int delta;

//TEST_INPUT: globalSpecializationArg MyModifier
//TEST_INPUT:set gModifier = new MyModifier{ ubuffer(data=[4 3 2 1], stride=4), 3 } }
uniform IModifier gModifier;

int test(int val)
{
    return gModifier.modify(val) + delta;
}


[numthreads(4, 1, 1)]
void computeMain(
    int3       dispatchThreadID : SV_DispatchThreadID)
{
    let tid = dispatchThreadID.x;

    let inputVal : int = tid;
    let outputVal = test(inputVal);

    gOutputBuffer[tid] = outputVal;
}

struct MyModifier : IModifier
{
    RWStructuredBuffer<int> data;
    int extra;

    int modify(int val)
    {
        return val*65536 + data[val]*256 + val*extra;
    }
}