yum-mirror/slang

Making it easier to work with shaders

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

Harsh Aggarwal (NVIDIA)Enable CUDA support for additional HLSL intrinsic tests (#8293)5ec41675d

master
4.2 KiB135 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):-cuda -compute -shaderobj -emit-spirv-directly
4// TEST:COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-slang -compute -vk -shaderobj -emit-spirv-via-glsl -profile sm_6_0 -Xslang... -capability GL_KHR_shader_subgroup_rotate -X.
5//TEST:COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-metal -compute -shaderobj -xslang -DMETAL
6
7
8//TEST:COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-vk -compute -shaderobj -emit-spirv-directly -xslang -DUSE_GLSL_SYNTAX -allow-glsl
9//TEST:COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-slang -compute -vk -shaderobj -emit-spirv-via-glsl -allow-glsl -profile sm_6_0 -Xslang... -DUSE_GLSL_SYNTAX -capability GL_KHR_shader_subgroup_rotate -X.
10//TEST:COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-metal -compute -shaderobj -xslang -DMETAL -xslang -DUSE_GLSL_SYNTAX -allow-glsl
11
12
13#if defined(USE_GLSL_SYNTAX)
14#define __rotate subgroupRotate
15#else
16#define __rotate WaveRotate
17#endif
18
19//TEST_INPUT:ubuffer(data=[0], stride=4):out,name=outputBuffer
20RWStructuredBuffer<uint> outputBuffer;
21
22#define SUBGROUP_SIZE 32
23#define DELTA 3
24
25static uint threadIndex;
26static uint rotatedValue;
27
28__generic<T : __BuiltinArithmeticType>
29bool test1Rotate()
30{
31    return __rotate(T(threadIndex), DELTA) == T(rotatedValue);
32}
33
34__generic<T : __BuiltinArithmeticType, let N : int>
35bool testVRotate()
36{
37    typealias gvec = vector<T, N>;
38
39#if defined(USE_GLSL_SYNTAX)
40    return (__rotate(gvec(T(threadIndex)), DELTA) == gvec(T(rotatedValue)));
41#else
42    return (__rotate(gvec(T(threadIndex)), DELTA) == gvec(T(rotatedValue)))[0];
43#endif
44}
45
46bool test1RotateBool()
47{
48    bool currentValue = (threadIndex % 2 == 0) ? true : false;
49    bool rotatedValueBool = (threadIndex % 2 == 0) ? false : true;
50    return __rotate(currentValue, DELTA) == rotatedValueBool;
51}
52
53__generic<let N : int>
54bool testVRotateBool()
55{
56    typealias gvec = vector<bool, N>;
57    bool currentValue = (threadIndex % 2 == 0) ? true : false;
58    bool rotatedValueBool = (threadIndex % 2 == 0) ? false : true;
59
60#if defined(USE_GLSL_SYNTAX)
61    return (__rotate(gvec(currentValue), DELTA) == gvec(rotatedValueBool));
62#else
63    return (__rotate(gvec(currentValue), DELTA) == gvec(rotatedValueBool))[0];
64#endif
65}
66
67bool testRotate()
68{
69    return true
70        & test1Rotate<float>()
71        & testVRotate<float, 2>()
72        & testVRotate<float, 3>()
73        & testVRotate<float, 4>()
74        & test1Rotate<half>()
75        & testVRotate<half, 2>()
76        & testVRotate<half, 3>()
77        & testVRotate<half, 4>()
78        & test1Rotate<uint>()
79        & testVRotate<uint, 2>()
80        & testVRotate<uint, 3>()
81        & testVRotate<uint, 4>()
82        & test1Rotate<uint16_t>()
83        & testVRotate<uint16_t, 2>()
84        & testVRotate<uint16_t, 3>()
85        & testVRotate<uint16_t, 4>()
86        & test1Rotate<int>()
87        & testVRotate<int, 2>()
88        & testVRotate<int, 3>()
89        & testVRotate<int, 4>()
90        & test1Rotate<int16_t>()
91        & testVRotate<int16_t, 2>()
92        & testVRotate<int16_t, 3>()
93        & testVRotate<int16_t, 4>()
94
95        // Subgroup rotate operations on these builtin types are not supported on Metal.
96#if !defined(METAL)
97        & test1Rotate<uint8_t>()
98        & testVRotate<uint8_t, 2>()
99        & testVRotate<uint8_t, 3>()
100        & testVRotate<uint8_t, 4>()
101        & test1Rotate<uint64_t>()
102        & testVRotate<uint64_t, 2>()
103        & testVRotate<uint64_t, 3>()
104        & testVRotate<uint64_t, 4>()
105        & test1Rotate<int8_t>()
106        & testVRotate<int8_t, 2>()
107        & testVRotate<int8_t, 3>()
108        & testVRotate<int8_t, 4>()
109        & test1Rotate<int64_t>()
110        & testVRotate<int64_t, 2>()
111        & testVRotate<int64_t, 3>()
112        & testVRotate<int64_t, 4>()
113        & test1RotateBool()
114        & testVRotateBool<2>()
115        & testVRotateBool<3>()
116        & testVRotateBool<4>()
117#endif
118        ;
119}
120
121[shader("compute")]
122[numthreads(SUBGROUP_SIZE, 1, 1)]
123void computeMain(uint3 dispatchID : SV_DispatchThreadID)
124{
125    threadIndex = dispatchID.x;
126    rotatedValue = (threadIndex + DELTA) % SUBGROUP_SIZE;
127
128    bool result = true
129            & testRotate()
130            ;
131
132    // CHECK: 1
133    outputBuffer[0] = uint(result);
134}
135