summaryrefslogtreecommitdiff
path: root/tests/hlsl-intrinsic/wave-multi/wave-multi-prefix-min.slang
blob: 321b99a0e5ea9914dc6aeea1d7243bb5200f73ba (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
//TEST_CATEGORY(wave, compute)
//TEST:COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-vk -compute -shaderobj -emit-spirv-directly
//TEST:COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-vk -compute -shaderobj -emit-spirv-via-glsl
//TEST:COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-cuda -capability cuda_sm_7_0 -compute -shaderobj
//TEST:COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-vk -compute -shaderobj -emit-spirv-directly -xslang -DUSE_GLSL_SYNTAX -allow-glsl

//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0], stride=4):out,name outputBuffer
RWStructuredBuffer<uint> outputBuffer;

#if defined(USE_GLSL_SYNTAX)
#define __partitionedInclusiveMin subgroupPartitionedInclusiveMinNV
#define __partitionedExclusiveMin subgroupPartitionedExclusiveMinNV
#else
#define __partitionedInclusiveMin WaveMultiPrefixInclusiveMin
#define __partitionedExclusiveMin WaveMultiPrefixExclusiveMin
#endif

static bool isFirstInPartition = false;
static uint gSmaller = 0;
static uint gLarger = 0;
static uint gMaxValue = 0;

__generic<T : __BuiltinArithmeticType>
bool test1Min(uint4 mask)
{
    let larger = T(gLarger);
    let minValue = T(gMaxValue);

    // The smaller values are set to be the last in the partition, exclusive variants will never get these values.
    bool exclusiveRes = true
                        & (__partitionedExclusiveMin(minValue, mask) == larger)
                        ;
    // Do not check exclusive prefix for the first invocation in partition as their values(identity values) depend on the builtin type `T`. It would be
    // nice to have something like T::min or T::max.
    if (isFirstInPartition)
    {
        exclusiveRes = true;
    }

    return true
        & (__partitionedInclusiveMin(minValue, mask) == minValue)
        & exclusiveRes
        ;
}

__generic<T : __BuiltinArithmeticType, let N : int>
bool testVMin(uint4 mask) {
    typealias GVec = vector<T, N>;

    let larger = GVec(T(gLarger));
    let minValue = GVec(T(gMaxValue));

    // The smaller values are set to be the last in the partition, exclusive variants will never get these values.
    bool exclusiveRes = true
                        & all(__partitionedExclusiveMin(minValue, mask) == larger)
                        ;
    // Do not check exclusive prefix for the first invocation in partition as their values(identity values) depend on the builtin type `T`. It would be
    // nice to have something like T::min or T::max.
    if (isFirstInPartition)
    {
        exclusiveRes = true;
    }

    return true
        & all(__partitionedInclusiveMin(minValue, mask) == minValue)
        & exclusiveRes
        ;
}

bool testMin(uint4 mask)
{
    return true
        & test1Min<int>(mask)
        & testVMin<int, 2>(mask)
        & testVMin<int, 3>(mask)
        & testVMin<int, 4>(mask)
        & test1Min<uint>(mask)
        & testVMin<uint, 2>(mask)
        & testVMin<uint, 3>(mask)
        & testVMin<uint, 4>(mask)
        & test1Min<float>(mask)
        & testVMin<float, 2>(mask)
        & testVMin<float, 3>(mask)
        & testVMin<float, 4>(mask)
        & test1Min<double>(mask)
        & testVMin<double, 2>(mask)
        & testVMin<double, 3>(mask)
        & testVMin<double, 4>(mask)
        & test1Min<int8_t>(mask)
        & testVMin<int8_t, 2>(mask)
        & testVMin<int8_t, 3>(mask)
        & testVMin<int8_t, 4>(mask)
        & test1Min<int16_t>(mask)
        & testVMin<int16_t, 2>(mask)
        & testVMin<int16_t, 3>(mask)
        & testVMin<int16_t, 4>(mask)
        & test1Min<int64_t>(mask)
        & testVMin<int64_t, 2>(mask)
        & testVMin<int64_t, 3>(mask)
        & testVMin<int64_t, 4>(mask)
        & test1Min<uint8_t>(mask)
        & testVMin<uint8_t, 2>(mask)
        & testVMin<uint8_t, 3>(mask)
        & testVMin<uint8_t, 4>(mask)
        & test1Min<uint16_t>(mask)
        & testVMin<uint16_t, 2>(mask)
        & testVMin<uint16_t, 3>(mask)
        & testVMin<uint16_t, 4>(mask)
        & test1Min<uint64_t>(mask)
        & testVMin<uint64_t, 2>(mask)
        & testVMin<uint64_t, 3>(mask)
        & testVMin<uint64_t, 4>(mask)
        & test1Min<half>(mask)
        & testVMin<half, 2>(mask)
        & testVMin<half, 3>(mask)
        & testVMin<half, 4>(mask)
        ;
}

[numthreads(32, 1, 1)]
[shader("compute")]
[MaximallyReconverges]
void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
{
    let index = dispatchThreadID.x;

    // Split into two groups, first group has 15 invocations/lanes and second group has 17.
    let isSecondGroup = index >= 15;
    uint4 mask = isSecondGroup ? uint4(0xFFFF8000, 0, 0, 0) : uint4(0x0007FFF, 0, 0, 0);

    isFirstInPartition = (index == 0) || (index == 15);
    let isLastInPartition = (index == 14) || (index == 31);

    bool result = true
            & testMin(mask)
            ;

    gSmaller = isSecondGroup ? 2 : 0;
    gLarger = isSecondGroup ? 3 : 1;
    gMaxValue = isLastInPartition ? gLarger : gSmaller;

    // CHECK-COUNT-32: 1
    outputBuffer[index] = uint(result);
}