yum-mirror/slang

Making it easier to work with shaders

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

Darren WihandiAdd full support for SPV_NV_shader_subgroup_partitioned (#7103)0476b57fa

master
3.9 KiB114 linesraw
1//TEST_CATEGORY(wave, compute)
2//TEST:COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-vk -compute -shaderobj -emit-spirv-directly
3//TEST:COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-vk -compute -shaderobj -emit-spirv-via-glsl
4//TEST:COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-cuda -compute  -shaderobj -xslang -DCUDA
5
6//TEST:COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-vk -compute -shaderobj -emit-spirv-directly -xslang -DUSE_GLSL_SYNTAX -allow-glsl
7
8//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
9RWStructuredBuffer<uint> outputBuffer;
10
11#if defined(USE_GLSL_SYNTAX)
12#define __partitionedSum subgroupPartitionedAddNV
13#define __partitionedProduct subgroupPartitionedMulNV
14#else
15#define __partitionedSum WaveMultiSum
16#define __partitionedProduct WaveMultiProduct
17#endif
18
19static uint gSumResult = 0;
20
21__generic<T : __BuiltinArithmeticType>
22bool test1SumProduct(uint4 mask)
23{
24    let sumResult = T(gSumResult);
25
26    return true
27        & (__partitionedSum(T(1), mask) == sumResult)
28        & (__partitionedProduct(T(1), mask) == T(1))
29        ;
30}
31
32__generic<T : __BuiltinArithmeticType, let N : int>
33bool testVSumProduct(uint4 mask) {
34    typealias GVec = vector<T, N>;
35
36    let sumResult = GVec(T(gSumResult));
37
38    return true
39        & all(__partitionedSum(GVec(T(1)), mask) == sumResult)
40        & all(__partitionedProduct(GVec(T(1)), mask) == GVec(T(1)))
41        ;
42}
43
44bool testSumProduct(uint4 mask)
45{
46    return true
47        & test1SumProduct<int>(mask)
48        & testVSumProduct<int, 2>(mask)
49        & testVSumProduct<int, 3>(mask)
50        & testVSumProduct<int, 4>(mask)
51        & test1SumProduct<uint>(mask)
52        & testVSumProduct<uint, 2>(mask)
53        & testVSumProduct<uint, 3>(mask)
54        & testVSumProduct<uint, 4>(mask)
55        & test1SumProduct<float>(mask)
56        & testVSumProduct<float, 2>(mask)
57        & testVSumProduct<float, 3>(mask)
58        & testVSumProduct<float, 4>(mask)
59        & test1SumProduct<double>(mask)
60        & testVSumProduct<double, 2>(mask)
61        & testVSumProduct<double, 3>(mask)
62        & testVSumProduct<double, 4>(mask)
63
64#if !defined(CUDA)
65        & test1SumProduct<int8_t>(mask)
66        & testVSumProduct<int8_t, 2>(mask)
67        & testVSumProduct<int8_t, 3>(mask)
68        & testVSumProduct<int8_t, 4>(mask)
69        & test1SumProduct<int16_t>(mask)
70        & testVSumProduct<int16_t, 2>(mask)
71        & testVSumProduct<int16_t, 3>(mask)
72        & testVSumProduct<int16_t, 4>(mask)
73        & test1SumProduct<int64_t>(mask)
74        & testVSumProduct<int64_t, 2>(mask)
75        & testVSumProduct<int64_t, 3>(mask)
76        & testVSumProduct<int64_t, 4>(mask)
77        & test1SumProduct<uint8_t>(mask)
78        & testVSumProduct<uint8_t, 2>(mask)
79        & testVSumProduct<uint8_t, 3>(mask)
80        & testVSumProduct<uint8_t, 4>(mask)
81        & test1SumProduct<uint16_t>(mask)
82        & testVSumProduct<uint16_t, 2>(mask)
83        & testVSumProduct<uint16_t, 3>(mask)
84        & testVSumProduct<uint16_t, 4>(mask)
85        & test1SumProduct<uint64_t>(mask)
86        & testVSumProduct<uint64_t, 2>(mask)
87        & testVSumProduct<uint64_t, 3>(mask)
88        & testVSumProduct<uint64_t, 4>(mask)
89        & test1SumProduct<half>(mask)
90        & testVSumProduct<half, 2>(mask)
91        & testVSumProduct<half, 3>(mask)
92        & testVSumProduct<half, 4>(mask)
93#endif
94        ;
95}
96
97[numthreads(32, 1, 1)]
98[shader("compute")]
99void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
100{
101    uint index = dispatchThreadID.x;
102
103    // Split into two groups, first group has 15 invocations/lanes and second group has 17.
104    let isSecondGroup = index >= 15;
105    uint4 mask = isSecondGroup ? uint4(0xFFFF8000, 0, 0, 0) : uint4(0x0007FFF, 0, 0, 0);
106    gSumResult = isSecondGroup ? uint(17) : uint(15);
107
108    bool result = true
109            & testSumProduct(mask)
110            ;
111
112    // CHECK-COUNT-32: 1
113    outputBuffer[index] = uint(result);
114}