1 /*-------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
5 * Copyright (c) 2015 Google Inc.
6 * Copyright (c) 2016 The Khronos Group Inc.
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
22 * \brief SPIR-V Assembly Tests for Instructions (special opcode/operand)
23 *//*--------------------------------------------------------------------*/
25 #include "vktSpvAsmInstructionTests.hpp"
27 #include "tcuCommandLine.hpp"
28 #include "tcuFormatUtil.hpp"
29 #include "tcuFloat.hpp"
30 #include "tcuFloatFormat.hpp"
31 #include "tcuRGBA.hpp"
32 #include "tcuStringTemplate.hpp"
33 #include "tcuTestLog.hpp"
34 #include "tcuVectorUtil.hpp"
35 #include "tcuInterval.hpp"
38 #include "vkDeviceUtil.hpp"
39 #include "vkMemUtil.hpp"
40 #include "vkPlatform.hpp"
41 #include "vkPrograms.hpp"
42 #include "vkQueryUtil.hpp"
44 #include "vkRefUtil.hpp"
45 #include "vkStrUtil.hpp"
46 #include "vkTypeUtil.hpp"
48 #include "deStringUtil.hpp"
49 #include "deUniquePtr.hpp"
51 #include "deRandom.hpp"
52 #include "tcuStringTemplate.hpp"
54 #include "vktSpvAsmCrossStageInterfaceTests.hpp"
55 #include "vktSpvAsm8bitStorageTests.hpp"
56 #include "vktSpvAsm16bitStorageTests.hpp"
57 #include "vktSpvAsmUboMatrixPaddingTests.hpp"
58 #include "vktSpvAsmConditionalBranchTests.hpp"
59 #include "vktSpvAsmIndexingTests.hpp"
60 #include "vktSpvAsmImageSamplerTests.hpp"
61 #include "vktSpvAsmComputeShaderCase.hpp"
62 #include "vktSpvAsmComputeShaderTestUtil.hpp"
63 #include "vktSpvAsmFloatControlsTests.hpp"
64 #include "vktSpvAsmFromHlslTests.hpp"
65 #include "vktSpvAsmGraphicsShaderTestUtil.hpp"
66 #include "vktSpvAsmVariablePointersTests.hpp"
67 #include "vktSpvAsmVariableInitTests.hpp"
68 #include "vktSpvAsmPointerParameterTests.hpp"
69 #include "vktSpvAsmSpirvVersion1p4Tests.hpp"
70 #include "vktSpvAsmSpirvVersionTests.hpp"
71 #include "vktTestCaseUtil.hpp"
72 #include "vktSpvAsmLoopDepLenTests.hpp"
73 #include "vktSpvAsmLoopDepInfTests.hpp"
74 #include "vktSpvAsmCompositeInsertTests.hpp"
75 #include "vktSpvAsmVaryingNameTests.hpp"
76 #include "vktSpvAsmWorkgroupMemoryTests.hpp"
77 #include "vktSpvAsmSignedIntCompareTests.hpp"
78 #include "vktSpvAsmPtrAccessChainTests.hpp"
79 #include "vktSpvAsm64bitCompareTests.hpp"
91 namespace SpirVAssembly
105 using tcu::TestStatus;
108 using tcu::StringTemplate;
111 const bool TEST_WITH_NAN = true;
112 const bool TEST_WITHOUT_NAN = false;
114 const string loadScalarF16FromUint =
115 "%ld_arg_${var} = OpFunction %f16 None %f16_i32_fn\n"
116 "%ld_arg_${var}_param = OpFunctionParameter %i32\n"
117 "%ld_arg_${var}_entry = OpLabel\n"
118 "%ld_arg_${var}_conv = OpBitcast %u32 %ld_arg_${var}_param\n"
119 "%ld_arg_${var}_div = OpUDiv %u32 %ld_arg_${var}_conv %c_u32_2\n"
120 "%ld_arg_${var}_and_low = OpBitwiseAnd %u32 %ld_arg_${var}_param %c_u32_1\n"
121 "%ld_arg_${var}_gep = OpAccessChain %up_u32 %${var} %c_u32_0 %ld_arg_${var}_div\n"
122 "%ld_arg_${var}_ld = OpLoad %u32 %ld_arg_${var}_gep\n"
123 "%ld_arg_${var}_unpack = OpBitcast %v2f16 %ld_arg_${var}_ld\n"
124 "%ld_arg_${var}_ex = OpVectorExtractDynamic %f16 %ld_arg_${var}_unpack %ld_arg_${var}_and_low\n"
125 "OpReturnValue %ld_arg_${var}_ex\n"
128 const string loadV2F16FromUint =
129 "%ld_arg_${var} = OpFunction %v2f16 None %v2f16_i32_fn\n"
130 "%ld_arg_${var}_param = OpFunctionParameter %i32\n"
131 "%ld_arg_${var}_entry = OpLabel\n"
132 "%ld_arg_${var}_gep = OpAccessChain %up_u32 %${var} %c_u32_0 %ld_arg_${var}_param\n"
133 "%ld_arg_${var}_ld = OpLoad %u32 %ld_arg_${var}_gep\n"
134 "%ld_arg_${var}_cast = OpBitcast %v2f16 %ld_arg_${var}_ld\n"
135 "OpReturnValue %ld_arg_${var}_cast\n"
138 const string loadV3F16FromUints =
139 // Since we allocate a vec4 worth of values, this case is almost the
140 // same as that case.
141 "%ld_arg_${var} = OpFunction %v3f16 None %v3f16_i32_fn\n"
142 "%ld_arg_${var}_param = OpFunctionParameter %i32\n"
143 "%ld_arg_${var}_entry = OpLabel\n"
144 "%ld_arg_${var}_gep0 = OpAccessChain %up_u32 %${var} %c_u32_0 %ld_arg_${var}_param %c_u32_0\n"
145 "%ld_arg_${var}_ld0 = OpLoad %u32 %ld_arg_${var}_gep0\n"
146 "%ld_arg_${var}_bc0 = OpBitcast %v2f16 %ld_arg_${var}_ld0\n"
147 "%ld_arg_${var}_gep1 = OpAccessChain %up_u32 %${var} %c_u32_0 %ld_arg_${var}_param %c_u32_1\n"
148 "%ld_arg_${var}_ld1 = OpLoad %u32 %ld_arg_${var}_gep1\n"
149 "%ld_arg_${var}_bc1 = OpBitcast %v2f16 %ld_arg_${var}_ld1\n"
150 "%ld_arg_${var}_shuffle = OpVectorShuffle %v3f16 %ld_arg_${var}_bc0 %ld_arg_${var}_bc1 0 1 2\n"
151 "OpReturnValue %ld_arg_${var}_shuffle\n"
154 const string loadV4F16FromUints =
155 "%ld_arg_${var} = OpFunction %v4f16 None %v4f16_i32_fn\n"
156 "%ld_arg_${var}_param = OpFunctionParameter %i32\n"
157 "%ld_arg_${var}_entry = OpLabel\n"
158 "%ld_arg_${var}_gep0 = OpAccessChain %up_u32 %${var} %c_u32_0 %ld_arg_${var}_param %c_u32_0\n"
159 "%ld_arg_${var}_ld0 = OpLoad %u32 %ld_arg_${var}_gep0\n"
160 "%ld_arg_${var}_bc0 = OpBitcast %v2f16 %ld_arg_${var}_ld0\n"
161 "%ld_arg_${var}_gep1 = OpAccessChain %up_u32 %${var} %c_u32_0 %ld_arg_${var}_param %c_u32_1\n"
162 "%ld_arg_${var}_ld1 = OpLoad %u32 %ld_arg_${var}_gep1\n"
163 "%ld_arg_${var}_bc1 = OpBitcast %v2f16 %ld_arg_${var}_ld1\n"
164 "%ld_arg_${var}_shuffle = OpVectorShuffle %v4f16 %ld_arg_${var}_bc0 %ld_arg_${var}_bc1 0 1 2 3\n"
165 "OpReturnValue %ld_arg_${var}_shuffle\n"
168 const string loadM2x2F16FromUints =
169 "%ld_arg_${var} = OpFunction %m2x2f16 None %m2x2f16_i32_fn\n"
170 "%ld_arg_${var}_param = OpFunctionParameter %i32\n"
171 "%ld_arg_${var}_entry = OpLabel\n"
172 "%ld_arg_${var}_gep0 = OpAccessChain %up_u32 %${var} %c_u32_0 %ld_arg_${var}_param %c_u32_0\n"
173 "%ld_arg_${var}_ld0 = OpLoad %u32 %ld_arg_${var}_gep0\n"
174 "%ld_arg_${var}_bc0 = OpBitcast %v2f16 %ld_arg_${var}_ld0\n"
175 "%ld_arg_${var}_gep1 = OpAccessChain %up_u32 %${var} %c_u32_0 %ld_arg_${var}_param %c_u32_1\n"
176 "%ld_arg_${var}_ld1 = OpLoad %u32 %ld_arg_${var}_gep1\n"
177 "%ld_arg_${var}_bc1 = OpBitcast %v2f16 %ld_arg_${var}_ld1\n"
178 "%ld_arg_${var}_cons = OpCompositeConstruct %m2x2f16 %ld_arg_${var}_bc0 %ld_arg_${var}_bc1\n"
179 "OpReturnValue %ld_arg_${var}_cons\n"
182 const string loadM2x3F16FromUints =
183 "%ld_arg_${var} = OpFunction %m2x3f16 None %m2x3f16_i32_fn\n"
184 "%ld_arg_${var}_param = OpFunctionParameter %i32\n"
185 "%ld_arg_${var}_entry = OpLabel\n"
186 "%ld_arg_${var}_gep00 = OpAccessChain %up_u32 %${var} %c_u32_0 %ld_arg_${var}_param %c_u32_0\n"
187 "%ld_arg_${var}_gep01 = OpAccessChain %up_u32 %${var} %c_u32_0 %ld_arg_${var}_param %c_u32_1\n"
188 "%ld_arg_${var}_gep10 = OpAccessChain %up_u32 %${var} %c_u32_0 %ld_arg_${var}_param %c_u32_2\n"
189 "%ld_arg_${var}_gep11 = OpAccessChain %up_u32 %${var} %c_u32_0 %ld_arg_${var}_param %c_u32_3\n"
190 "%ld_arg_${var}_ld00 = OpLoad %u32 %ld_arg_${var}_gep00\n"
191 "%ld_arg_${var}_ld01 = OpLoad %u32 %ld_arg_${var}_gep01\n"
192 "%ld_arg_${var}_ld10 = OpLoad %u32 %ld_arg_${var}_gep10\n"
193 "%ld_arg_${var}_ld11 = OpLoad %u32 %ld_arg_${var}_gep11\n"
194 "%ld_arg_${var}_bc00 = OpBitcast %v2f16 %ld_arg_${var}_ld00\n"
195 "%ld_arg_${var}_bc01 = OpBitcast %v2f16 %ld_arg_${var}_ld01\n"
196 "%ld_arg_${var}_bc10 = OpBitcast %v2f16 %ld_arg_${var}_ld10\n"
197 "%ld_arg_${var}_bc11 = OpBitcast %v2f16 %ld_arg_${var}_ld11\n"
198 "%ld_arg_${var}_vec0 = OpVectorShuffle %v3f16 %ld_arg_${var}_bc00 %ld_arg_${var}_bc01 0 1 2\n"
199 "%ld_arg_${var}_vec1 = OpVectorShuffle %v3f16 %ld_arg_${var}_bc10 %ld_arg_${var}_bc11 0 1 2\n"
200 "%ld_arg_${var}_mat = OpCompositeConstruct %m2x3f16 %ld_arg_${var}_vec0 %ld_arg_${var}_vec1\n"
201 "OpReturnValue %ld_arg_${var}_mat\n"
204 const string loadM2x4F16FromUints =
205 "%ld_arg_${var} = OpFunction %m2x4f16 None %m2x4f16_i32_fn\n"
206 "%ld_arg_${var}_param = OpFunctionParameter %i32\n"
207 "%ld_arg_${var}_entry = OpLabel\n"
208 "%ld_arg_${var}_gep00 = OpAccessChain %up_u32 %${var} %c_u32_0 %ld_arg_${var}_param %c_u32_0\n"
209 "%ld_arg_${var}_gep01 = OpAccessChain %up_u32 %${var} %c_u32_0 %ld_arg_${var}_param %c_u32_1\n"
210 "%ld_arg_${var}_gep10 = OpAccessChain %up_u32 %${var} %c_u32_0 %ld_arg_${var}_param %c_u32_2\n"
211 "%ld_arg_${var}_gep11 = OpAccessChain %up_u32 %${var} %c_u32_0 %ld_arg_${var}_param %c_u32_3\n"
212 "%ld_arg_${var}_ld00 = OpLoad %u32 %ld_arg_${var}_gep00\n"
213 "%ld_arg_${var}_ld01 = OpLoad %u32 %ld_arg_${var}_gep01\n"
214 "%ld_arg_${var}_ld10 = OpLoad %u32 %ld_arg_${var}_gep10\n"
215 "%ld_arg_${var}_ld11 = OpLoad %u32 %ld_arg_${var}_gep11\n"
216 "%ld_arg_${var}_bc00 = OpBitcast %v2f16 %ld_arg_${var}_ld00\n"
217 "%ld_arg_${var}_bc01 = OpBitcast %v2f16 %ld_arg_${var}_ld01\n"
218 "%ld_arg_${var}_bc10 = OpBitcast %v2f16 %ld_arg_${var}_ld10\n"
219 "%ld_arg_${var}_bc11 = OpBitcast %v2f16 %ld_arg_${var}_ld11\n"
220 "%ld_arg_${var}_vec0 = OpVectorShuffle %v4f16 %ld_arg_${var}_bc00 %ld_arg_${var}_bc01 0 1 2 3\n"
221 "%ld_arg_${var}_vec1 = OpVectorShuffle %v4f16 %ld_arg_${var}_bc10 %ld_arg_${var}_bc11 0 1 2 3\n"
222 "%ld_arg_${var}_mat = OpCompositeConstruct %m2x4f16 %ld_arg_${var}_vec0 %ld_arg_${var}_vec1\n"
223 "OpReturnValue %ld_arg_${var}_mat\n"
226 const string loadM3x2F16FromUints =
227 "%ld_arg_${var} = OpFunction %m3x2f16 None %m3x2f16_i32_fn\n"
228 "%ld_arg_${var}_param = OpFunctionParameter %i32\n"
229 "%ld_arg_${var}_entry = OpLabel\n"
230 "%ld_arg_${var}_gep0 = OpAccessChain %up_u32 %${var} %c_u32_0 %ld_arg_${var}_param %c_u32_0\n"
231 "%ld_arg_${var}_gep1 = OpAccessChain %up_u32 %${var} %c_u32_0 %ld_arg_${var}_param %c_u32_1\n"
232 "%ld_arg_${var}_gep2 = OpAccessChain %up_u32 %${var} %c_u32_0 %ld_arg_${var}_param %c_u32_2\n"
233 "%ld_arg_${var}_ld0 = OpLoad %u32 %ld_arg_${var}_gep0\n"
234 "%ld_arg_${var}_ld1 = OpLoad %u32 %ld_arg_${var}_gep1\n"
235 "%ld_arg_${var}_ld2 = OpLoad %u32 %ld_arg_${var}_gep2\n"
236 "%ld_arg_${var}_bc0 = OpBitcast %v2f16 %ld_arg_${var}_ld0\n"
237 "%ld_arg_${var}_bc1 = OpBitcast %v2f16 %ld_arg_${var}_ld1\n"
238 "%ld_arg_${var}_bc2 = OpBitcast %v2f16 %ld_arg_${var}_ld2\n"
239 "%ld_arg_${var}_mat = OpCompositeConstruct %m3x2f16 %ld_arg_${var}_bc0 %ld_arg_${var}_bc1 %ld_arg_${var}_bc2\n"
240 "OpReturnValue %ld_arg_${var}_mat\n"
243 const string loadM3x3F16FromUints =
244 "%ld_arg_${var} = OpFunction %m3x3f16 None %m3x3f16_i32_fn\n"
245 "%ld_arg_${var}_param = OpFunctionParameter %i32\n"
246 "%ld_arg_${var}_entry = OpLabel\n"
247 "%ld_arg_${var}_gep00 = OpAccessChain %up_u32 %${var} %c_u32_0 %ld_arg_${var}_param %c_u32_0\n"
248 "%ld_arg_${var}_gep01 = OpAccessChain %up_u32 %${var} %c_u32_0 %ld_arg_${var}_param %c_u32_1\n"
249 "%ld_arg_${var}_gep10 = OpAccessChain %up_u32 %${var} %c_u32_0 %ld_arg_${var}_param %c_u32_2\n"
250 "%ld_arg_${var}_gep11 = OpAccessChain %up_u32 %${var} %c_u32_0 %ld_arg_${var}_param %c_u32_3\n"
251 "%ld_arg_${var}_gep20 = OpAccessChain %up_u32 %${var} %c_u32_0 %ld_arg_${var}_param %c_u32_4\n"
252 "%ld_arg_${var}_gep21 = OpAccessChain %up_u32 %${var} %c_u32_0 %ld_arg_${var}_param %c_u32_5\n"
253 "%ld_arg_${var}_ld00 = OpLoad %u32 %ld_arg_${var}_gep00\n"
254 "%ld_arg_${var}_ld01 = OpLoad %u32 %ld_arg_${var}_gep01\n"
255 "%ld_arg_${var}_ld10 = OpLoad %u32 %ld_arg_${var}_gep10\n"
256 "%ld_arg_${var}_ld11 = OpLoad %u32 %ld_arg_${var}_gep11\n"
257 "%ld_arg_${var}_ld20 = OpLoad %u32 %ld_arg_${var}_gep20\n"
258 "%ld_arg_${var}_ld21 = OpLoad %u32 %ld_arg_${var}_gep21\n"
259 "%ld_arg_${var}_bc00 = OpBitcast %v2f16 %ld_arg_${var}_ld00\n"
260 "%ld_arg_${var}_bc01 = OpBitcast %v2f16 %ld_arg_${var}_ld01\n"
261 "%ld_arg_${var}_bc10 = OpBitcast %v2f16 %ld_arg_${var}_ld10\n"
262 "%ld_arg_${var}_bc11 = OpBitcast %v2f16 %ld_arg_${var}_ld11\n"
263 "%ld_arg_${var}_bc20 = OpBitcast %v2f16 %ld_arg_${var}_ld20\n"
264 "%ld_arg_${var}_bc21 = OpBitcast %v2f16 %ld_arg_${var}_ld21\n"
265 "%ld_arg_${var}_vec0 = OpVectorShuffle %v3f16 %ld_arg_${var}_bc00 %ld_arg_${var}_bc01 0 1 2\n"
266 "%ld_arg_${var}_vec1 = OpVectorShuffle %v3f16 %ld_arg_${var}_bc10 %ld_arg_${var}_bc11 0 1 2\n"
267 "%ld_arg_${var}_vec2 = OpVectorShuffle %v3f16 %ld_arg_${var}_bc20 %ld_arg_${var}_bc21 0 1 2\n"
268 "%ld_arg_${var}_mat = OpCompositeConstruct %m3x3f16 %ld_arg_${var}_vec0 %ld_arg_${var}_vec1 %ld_arg_${var}_vec2\n"
269 "OpReturnValue %ld_arg_${var}_mat\n"
272 const string loadM3x4F16FromUints =
273 "%ld_arg_${var} = OpFunction %m3x4f16 None %m3x4f16_i32_fn\n"
274 "%ld_arg_${var}_param = OpFunctionParameter %i32\n"
275 "%ld_arg_${var}_entry = OpLabel\n"
276 "%ld_arg_${var}_gep00 = OpAccessChain %up_u32 %${var} %c_u32_0 %ld_arg_${var}_param %c_u32_0\n"
277 "%ld_arg_${var}_gep01 = OpAccessChain %up_u32 %${var} %c_u32_0 %ld_arg_${var}_param %c_u32_1\n"
278 "%ld_arg_${var}_gep10 = OpAccessChain %up_u32 %${var} %c_u32_0 %ld_arg_${var}_param %c_u32_2\n"
279 "%ld_arg_${var}_gep11 = OpAccessChain %up_u32 %${var} %c_u32_0 %ld_arg_${var}_param %c_u32_3\n"
280 "%ld_arg_${var}_gep20 = OpAccessChain %up_u32 %${var} %c_u32_0 %ld_arg_${var}_param %c_u32_4\n"
281 "%ld_arg_${var}_gep21 = OpAccessChain %up_u32 %${var} %c_u32_0 %ld_arg_${var}_param %c_u32_5\n"
282 "%ld_arg_${var}_ld00 = OpLoad %u32 %ld_arg_${var}_gep00\n"
283 "%ld_arg_${var}_ld01 = OpLoad %u32 %ld_arg_${var}_gep01\n"
284 "%ld_arg_${var}_ld10 = OpLoad %u32 %ld_arg_${var}_gep10\n"
285 "%ld_arg_${var}_ld11 = OpLoad %u32 %ld_arg_${var}_gep11\n"
286 "%ld_arg_${var}_ld20 = OpLoad %u32 %ld_arg_${var}_gep20\n"
287 "%ld_arg_${var}_ld21 = OpLoad %u32 %ld_arg_${var}_gep21\n"
288 "%ld_arg_${var}_bc00 = OpBitcast %v2f16 %ld_arg_${var}_ld00\n"
289 "%ld_arg_${var}_bc01 = OpBitcast %v2f16 %ld_arg_${var}_ld01\n"
290 "%ld_arg_${var}_bc10 = OpBitcast %v2f16 %ld_arg_${var}_ld10\n"
291 "%ld_arg_${var}_bc11 = OpBitcast %v2f16 %ld_arg_${var}_ld11\n"
292 "%ld_arg_${var}_bc20 = OpBitcast %v2f16 %ld_arg_${var}_ld20\n"
293 "%ld_arg_${var}_bc21 = OpBitcast %v2f16 %ld_arg_${var}_ld21\n"
294 "%ld_arg_${var}_vec0 = OpVectorShuffle %v4f16 %ld_arg_${var}_bc00 %ld_arg_${var}_bc01 0 1 2 3\n"
295 "%ld_arg_${var}_vec1 = OpVectorShuffle %v4f16 %ld_arg_${var}_bc10 %ld_arg_${var}_bc11 0 1 2 3\n"
296 "%ld_arg_${var}_vec2 = OpVectorShuffle %v4f16 %ld_arg_${var}_bc20 %ld_arg_${var}_bc21 0 1 2 3\n"
297 "%ld_arg_${var}_mat = OpCompositeConstruct %m3x4f16 %ld_arg_${var}_vec0 %ld_arg_${var}_vec1 %ld_arg_${var}_vec2\n"
298 "OpReturnValue %ld_arg_${var}_mat\n"
301 const string loadM4x2F16FromUints =
302 "%ld_arg_${var} = OpFunction %m4x2f16 None %m4x2f16_i32_fn\n"
303 "%ld_arg_${var}_param = OpFunctionParameter %i32\n"
304 "%ld_arg_${var}_entry = OpLabel\n"
305 "%ld_arg_${var}_gep0 = OpAccessChain %up_u32 %${var} %c_u32_0 %ld_arg_${var}_param %c_u32_0\n"
306 "%ld_arg_${var}_gep1 = OpAccessChain %up_u32 %${var} %c_u32_0 %ld_arg_${var}_param %c_u32_1\n"
307 "%ld_arg_${var}_gep2 = OpAccessChain %up_u32 %${var} %c_u32_0 %ld_arg_${var}_param %c_u32_2\n"
308 "%ld_arg_${var}_gep3 = OpAccessChain %up_u32 %${var} %c_u32_0 %ld_arg_${var}_param %c_u32_3\n"
309 "%ld_arg_${var}_ld0 = OpLoad %u32 %ld_arg_${var}_gep0\n"
310 "%ld_arg_${var}_ld1 = OpLoad %u32 %ld_arg_${var}_gep1\n"
311 "%ld_arg_${var}_ld2 = OpLoad %u32 %ld_arg_${var}_gep2\n"
312 "%ld_arg_${var}_ld3 = OpLoad %u32 %ld_arg_${var}_gep3\n"
313 "%ld_arg_${var}_bc0 = OpBitcast %v2f16 %ld_arg_${var}_ld0\n"
314 "%ld_arg_${var}_bc1 = OpBitcast %v2f16 %ld_arg_${var}_ld1\n"
315 "%ld_arg_${var}_bc2 = OpBitcast %v2f16 %ld_arg_${var}_ld2\n"
316 "%ld_arg_${var}_bc3 = OpBitcast %v2f16 %ld_arg_${var}_ld3\n"
317 "%ld_arg_${var}_mat = OpCompositeConstruct %m4x2f16 %ld_arg_${var}_bc0 %ld_arg_${var}_bc1 %ld_arg_${var}_bc2 %ld_arg_${var}_bc3\n"
318 "OpReturnValue %ld_arg_${var}_mat\n"
321 const string loadM4x3F16FromUints =
322 "%ld_arg_${var} = OpFunction %m4x3f16 None %m4x3f16_i32_fn\n"
323 "%ld_arg_${var}_param = OpFunctionParameter %i32\n"
324 "%ld_arg_${var}_entry = OpLabel\n"
325 "%ld_arg_${var}_gep00 = OpAccessChain %up_u32 %${var} %c_u32_0 %ld_arg_${var}_param %c_u32_0\n"
326 "%ld_arg_${var}_gep01 = OpAccessChain %up_u32 %${var} %c_u32_0 %ld_arg_${var}_param %c_u32_1\n"
327 "%ld_arg_${var}_gep10 = OpAccessChain %up_u32 %${var} %c_u32_0 %ld_arg_${var}_param %c_u32_2\n"
328 "%ld_arg_${var}_gep11 = OpAccessChain %up_u32 %${var} %c_u32_0 %ld_arg_${var}_param %c_u32_3\n"
329 "%ld_arg_${var}_gep20 = OpAccessChain %up_u32 %${var} %c_u32_0 %ld_arg_${var}_param %c_u32_4\n"
330 "%ld_arg_${var}_gep21 = OpAccessChain %up_u32 %${var} %c_u32_0 %ld_arg_${var}_param %c_u32_5\n"
331 "%ld_arg_${var}_gep30 = OpAccessChain %up_u32 %${var} %c_u32_0 %ld_arg_${var}_param %c_u32_6\n"
332 "%ld_arg_${var}_gep31 = OpAccessChain %up_u32 %${var} %c_u32_0 %ld_arg_${var}_param %c_u32_7\n"
333 "%ld_arg_${var}_ld00 = OpLoad %u32 %ld_arg_${var}_gep00\n"
334 "%ld_arg_${var}_ld01 = OpLoad %u32 %ld_arg_${var}_gep01\n"
335 "%ld_arg_${var}_ld10 = OpLoad %u32 %ld_arg_${var}_gep10\n"
336 "%ld_arg_${var}_ld11 = OpLoad %u32 %ld_arg_${var}_gep11\n"
337 "%ld_arg_${var}_ld20 = OpLoad %u32 %ld_arg_${var}_gep20\n"
338 "%ld_arg_${var}_ld21 = OpLoad %u32 %ld_arg_${var}_gep21\n"
339 "%ld_arg_${var}_ld30 = OpLoad %u32 %ld_arg_${var}_gep30\n"
340 "%ld_arg_${var}_ld31 = OpLoad %u32 %ld_arg_${var}_gep31\n"
341 "%ld_arg_${var}_bc00 = OpBitcast %v2f16 %ld_arg_${var}_ld00\n"
342 "%ld_arg_${var}_bc01 = OpBitcast %v2f16 %ld_arg_${var}_ld01\n"
343 "%ld_arg_${var}_bc10 = OpBitcast %v2f16 %ld_arg_${var}_ld10\n"
344 "%ld_arg_${var}_bc11 = OpBitcast %v2f16 %ld_arg_${var}_ld11\n"
345 "%ld_arg_${var}_bc20 = OpBitcast %v2f16 %ld_arg_${var}_ld20\n"
346 "%ld_arg_${var}_bc21 = OpBitcast %v2f16 %ld_arg_${var}_ld21\n"
347 "%ld_arg_${var}_bc30 = OpBitcast %v2f16 %ld_arg_${var}_ld30\n"
348 "%ld_arg_${var}_bc31 = OpBitcast %v2f16 %ld_arg_${var}_ld31\n"
349 "%ld_arg_${var}_vec0 = OpVectorShuffle %v3f16 %ld_arg_${var}_bc00 %ld_arg_${var}_bc01 0 1 2\n"
350 "%ld_arg_${var}_vec1 = OpVectorShuffle %v3f16 %ld_arg_${var}_bc10 %ld_arg_${var}_bc11 0 1 2\n"
351 "%ld_arg_${var}_vec2 = OpVectorShuffle %v3f16 %ld_arg_${var}_bc20 %ld_arg_${var}_bc21 0 1 2\n"
352 "%ld_arg_${var}_vec3 = OpVectorShuffle %v3f16 %ld_arg_${var}_bc30 %ld_arg_${var}_bc31 0 1 2\n"
353 "%ld_arg_${var}_mat = OpCompositeConstruct %m4x3f16 %ld_arg_${var}_vec0 %ld_arg_${var}_vec1 %ld_arg_${var}_vec2 %ld_arg_${var}_vec3\n"
354 "OpReturnValue %ld_arg_${var}_mat\n"
357 const string loadM4x4F16FromUints =
358 "%ld_arg_${var} = OpFunction %m4x4f16 None %m4x4f16_i32_fn\n"
359 "%ld_arg_${var}_param = OpFunctionParameter %i32\n"
360 "%ld_arg_${var}_entry = OpLabel\n"
361 "%ld_arg_${var}_gep00 = OpAccessChain %up_u32 %${var} %c_u32_0 %ld_arg_${var}_param %c_u32_0\n"
362 "%ld_arg_${var}_gep01 = OpAccessChain %up_u32 %${var} %c_u32_0 %ld_arg_${var}_param %c_u32_1\n"
363 "%ld_arg_${var}_gep10 = OpAccessChain %up_u32 %${var} %c_u32_0 %ld_arg_${var}_param %c_u32_2\n"
364 "%ld_arg_${var}_gep11 = OpAccessChain %up_u32 %${var} %c_u32_0 %ld_arg_${var}_param %c_u32_3\n"
365 "%ld_arg_${var}_gep20 = OpAccessChain %up_u32 %${var} %c_u32_0 %ld_arg_${var}_param %c_u32_4\n"
366 "%ld_arg_${var}_gep21 = OpAccessChain %up_u32 %${var} %c_u32_0 %ld_arg_${var}_param %c_u32_5\n"
367 "%ld_arg_${var}_gep30 = OpAccessChain %up_u32 %${var} %c_u32_0 %ld_arg_${var}_param %c_u32_6\n"
368 "%ld_arg_${var}_gep31 = OpAccessChain %up_u32 %${var} %c_u32_0 %ld_arg_${var}_param %c_u32_7\n"
369 "%ld_arg_${var}_ld00 = OpLoad %u32 %ld_arg_${var}_gep00\n"
370 "%ld_arg_${var}_ld01 = OpLoad %u32 %ld_arg_${var}_gep01\n"
371 "%ld_arg_${var}_ld10 = OpLoad %u32 %ld_arg_${var}_gep10\n"
372 "%ld_arg_${var}_ld11 = OpLoad %u32 %ld_arg_${var}_gep11\n"
373 "%ld_arg_${var}_ld20 = OpLoad %u32 %ld_arg_${var}_gep20\n"
374 "%ld_arg_${var}_ld21 = OpLoad %u32 %ld_arg_${var}_gep21\n"
375 "%ld_arg_${var}_ld30 = OpLoad %u32 %ld_arg_${var}_gep30\n"
376 "%ld_arg_${var}_ld31 = OpLoad %u32 %ld_arg_${var}_gep31\n"
377 "%ld_arg_${var}_bc00 = OpBitcast %v2f16 %ld_arg_${var}_ld00\n"
378 "%ld_arg_${var}_bc01 = OpBitcast %v2f16 %ld_arg_${var}_ld01\n"
379 "%ld_arg_${var}_bc10 = OpBitcast %v2f16 %ld_arg_${var}_ld10\n"
380 "%ld_arg_${var}_bc11 = OpBitcast %v2f16 %ld_arg_${var}_ld11\n"
381 "%ld_arg_${var}_bc20 = OpBitcast %v2f16 %ld_arg_${var}_ld20\n"
382 "%ld_arg_${var}_bc21 = OpBitcast %v2f16 %ld_arg_${var}_ld21\n"
383 "%ld_arg_${var}_bc30 = OpBitcast %v2f16 %ld_arg_${var}_ld30\n"
384 "%ld_arg_${var}_bc31 = OpBitcast %v2f16 %ld_arg_${var}_ld31\n"
385 "%ld_arg_${var}_vec0 = OpVectorShuffle %v4f16 %ld_arg_${var}_bc00 %ld_arg_${var}_bc01 0 1 2 3\n"
386 "%ld_arg_${var}_vec1 = OpVectorShuffle %v4f16 %ld_arg_${var}_bc10 %ld_arg_${var}_bc11 0 1 2 3\n"
387 "%ld_arg_${var}_vec2 = OpVectorShuffle %v4f16 %ld_arg_${var}_bc20 %ld_arg_${var}_bc21 0 1 2 3\n"
388 "%ld_arg_${var}_vec3 = OpVectorShuffle %v4f16 %ld_arg_${var}_bc30 %ld_arg_${var}_bc31 0 1 2 3\n"
389 "%ld_arg_${var}_mat = OpCompositeConstruct %m4x4f16 %ld_arg_${var}_vec0 %ld_arg_${var}_vec1 %ld_arg_${var}_vec2 %ld_arg_${var}_vec3\n"
390 "OpReturnValue %ld_arg_${var}_mat\n"
393 const string storeScalarF16AsUint =
394 // This version is sensitive to the initial value in the output buffer.
395 // The infrastructure sets all output buffer bits to one before invoking
396 // the shader so this version uses an atomic and to generate the correct
398 "%st_fn_${var} = OpFunction %void None %void_f16_i32_fn\n"
399 "%st_fn_${var}_param1 = OpFunctionParameter %f16\n"
400 "%st_fn_${var}_param2 = OpFunctionParameter %i32\n"
401 "%st_fn_${var}_entry = OpLabel\n"
402 "%st_fn_${var}_and_low = OpBitwiseAnd %u32 %st_fn_${var}_param2 %c_u32_1\n"
403 "%st_fn_${var}_zero_vec = OpBitcast %v2f16 %c_u32_0\n"
404 "%st_fn_${var}_insert = OpVectorInsertDynamic %v2f16 %st_fn_${var}_zero_vec %st_fn_${var}_param1 %st_fn_${var}_and_low\n"
405 "%st_fn_${var}_odd = OpIEqual %bool %st_fn_${var}_and_low %c_u32_1\n"
406 // Or 16 bits of ones into the half that was not populated with the result.
407 "%st_fn_${var}_sel = OpSelect %u32 %st_fn_${var}_odd %c_u32_low_ones %c_u32_high_ones\n"
408 "%st_fn_${var}_cast = OpBitcast %u32 %st_fn_${var}_insert\n"
409 "%st_fn_${var}_or = OpBitwiseOr %u32 %st_fn_${var}_cast %st_fn_${var}_sel\n"
410 "%st_fn_${var}_conv = OpBitcast %u32 %st_fn_${var}_param2\n"
411 "%st_fn_${var}_div = OpUDiv %u32 %st_fn_${var}_conv %c_u32_2\n"
412 "%st_fn_${var}_gep = OpAccessChain %up_u32 %${var} %c_u32_0 %st_fn_${var}_div\n"
413 "%st_fn_${var}_and = OpAtomicAnd %u32 %st_fn_${var}_gep %c_u32_1 %c_u32_0 %st_fn_${var}_or\n"
417 const string storeV2F16AsUint =
418 "%st_fn_${var} = OpFunction %void None %void_v2f16_i32_fn\n"
419 "%st_fn_${var}_param1 = OpFunctionParameter %v2f16\n"
420 "%st_fn_${var}_param2 = OpFunctionParameter %i32\n"
421 "%st_fn_${var}_entry = OpLabel\n"
422 "%st_fn_${var}_cast = OpBitcast %u32 %st_fn_${var}_param1\n"
423 "%st_fn_${var}_gep = OpAccessChain %up_u32 %${var} %c_u32_0 %st_fn_${var}_param2\n"
424 "OpStore %st_fn_${var}_gep %st_fn_${var}_cast\n"
428 const string storeV3F16AsUints =
429 // Since we allocate a vec4 worth of values, this case can be treated
430 // almost the same as a vec4 case. We will store some extra data that
431 // should not be compared.
432 "%st_fn_${var} = OpFunction %void None %void_v3f16_i32_fn\n"
433 "%st_fn_${var}_param1 = OpFunctionParameter %v3f16\n"
434 "%st_fn_${var}_param2 = OpFunctionParameter %i32\n"
435 "%st_fn_${var}_entry = OpLabel\n"
436 "%st_fn_${var}_shuffle0 = OpVectorShuffle %v2f16 %st_fn_${var}_param1 %st_fn_${var}_param1 0 1\n"
437 "%st_fn_${var}_shuffle1 = OpVectorShuffle %v2f16 %st_fn_${var}_param1 %st_fn_${var}_param1 2 3\n"
438 "%st_fn_${var}_bc0 = OpBitcast %u32 %st_fn_${var}_shuffle0\n"
439 "%st_fn_${var}_bc1 = OpBitcast %u32 %st_fn_${var}_shuffle1\n"
440 "%st_fn_${var}_gep0 = OpAccessChain %up_u32 %${var} %c_u32_0 %st_fn_${var}_param2 %c_u32_0\n"
441 "%st_fn_${var}_gep1 = OpAccessChain %up_u32 %${var} %c_u32_0 %st_fn_${var}_param2 %c_u32_1\n"
442 "OpStore %st_fn_${var}_gep0 %st_fn_${var}_bc0\n"
443 "OpStore %st_fn_${var}_gep1 %st_fn_${var}_bc1\n"
447 const string storeV4F16AsUints =
448 "%st_fn_${var} = OpFunction %void None %void_v4f16_i32_fn\n"
449 "%st_fn_${var}_param1 = OpFunctionParameter %v4f16\n"
450 "%st_fn_${var}_param2 = OpFunctionParameter %i32\n"
451 "%st_fn_${var}_entry = OpLabel\n"
452 "%st_fn_${var}_shuffle0 = OpVectorShuffle %v2f16 %st_fn_${var}_param1 %st_fn_${var}_param1 0 1\n"
453 "%st_fn_${var}_shuffle1 = OpVectorShuffle %v2f16 %st_fn_${var}_param1 %st_fn_${var}_param1 2 3\n"
454 "%st_fn_${var}_bc0 = OpBitcast %u32 %st_fn_${var}_shuffle0\n"
455 "%st_fn_${var}_bc1 = OpBitcast %u32 %st_fn_${var}_shuffle1\n"
456 "%st_fn_${var}_gep0 = OpAccessChain %up_u32 %${var} %c_u32_0 %st_fn_${var}_param2 %c_u32_0\n"
457 "%st_fn_${var}_gep1 = OpAccessChain %up_u32 %${var} %c_u32_0 %st_fn_${var}_param2 %c_u32_1\n"
458 "OpStore %st_fn_${var}_gep0 %st_fn_${var}_bc0\n"
459 "OpStore %st_fn_${var}_gep1 %st_fn_${var}_bc1\n"
463 const string storeM2x2F16AsUints =
464 "%st_fn_${var} = OpFunction %void None %void_m2x2f16_i32_fn\n"
465 "%st_fn_${var}_param1 = OpFunctionParameter %m2x2f16\n"
466 "%st_fn_${var}_param2 = OpFunctionParameter %i32\n"
467 "%st_fn_${var}_entry = OpLabel\n"
468 "%st_fn_${var}_ex0 = OpCompositeExtract %v2f16 %st_fn_${var}_param1 0\n"
469 "%st_fn_${var}_ex1 = OpCompositeExtract %v2f16 %st_fn_${var}_param1 1\n"
470 "%st_fn_${var}_bc0 = OpBitcast %u32 %st_fn_${var}_ex0\n"
471 "%st_fn_${var}_bc1 = OpBitcast %u32 %st_fn_${var}_ex1\n"
472 "%st_fn_${var}_gep0 = OpAccessChain %up_u32 %${var} %c_u32_0 %st_fn_${var}_param2 %c_u32_0\n"
473 "%st_fn_${var}_gep1 = OpAccessChain %up_u32 %${var} %c_u32_0 %st_fn_${var}_param2 %c_u32_1\n"
474 "OpStore %st_fn_${var}_gep0 %st_fn_${var}_bc0\n"
475 "OpStore %st_fn_${var}_gep1 %st_fn_${var}_bc1\n"
479 const string storeM2x3F16AsUints =
480 // In the extracted elements for 01 and 11 the second element doesn't
482 "%st_fn_${var} = OpFunction %void None %void_m2x3f16_i32_fn\n"
483 "%st_fn_${var}_param1 = OpFunctionParameter %m2x3f16\n"
484 "%st_fn_${var}_param2 = OpFunctionParameter %i32\n"
485 "%st_fn_${var}_entry = OpLabel\n"
486 "%st_fn_${var}_ex0 = OpCompositeExtract %v3f16 %st_fn_${var}_param1 0\n"
487 "%st_fn_${var}_ex1 = OpCompositeExtract %v3f16 %st_fn_${var}_param1 1\n"
488 "%st_fn_${var}_ele00 = OpVectorShuffle %v2f16 %st_fn_${var}_ex0 %st_fn_${var}_ex0 0 1\n"
489 "%st_fn_${var}_ele01 = OpVectorShuffle %v2f16 %st_fn_${var}_ex0 %st_fn_${var}_ex0 2 3\n"
490 "%st_fn_${var}_ele10 = OpVectorShuffle %v2f16 %st_fn_${var}_ex1 %st_fn_${var}_ex1 0 1\n"
491 "%st_fn_${var}_ele11 = OpVectorShuffle %v2f16 %st_fn_${var}_ex1 %st_fn_${var}_ex1 2 3\n"
492 "%st_fn_${var}_bc00 = OpBitcast %u32 %st_fn_${var}_ele00\n"
493 "%st_fn_${var}_bc01 = OpBitcast %u32 %st_fn_${var}_ele01\n"
494 "%st_fn_${var}_bc10 = OpBitcast %u32 %st_fn_${var}_ele10\n"
495 "%st_fn_${var}_bc11 = OpBitcast %u32 %st_fn_${var}_ele11\n"
496 "%st_fn_${var}_gep00 = OpAccessChain %up_u32 %${var} %c_u32_0 %st_fn_${var}_param2 %c_u32_0\n"
497 "%st_fn_${var}_gep01 = OpAccessChain %up_u32 %${var} %c_u32_0 %st_fn_${var}_param2 %c_u32_1\n"
498 "%st_fn_${var}_gep10 = OpAccessChain %up_u32 %${var} %c_u32_0 %st_fn_${var}_param2 %c_u32_2\n"
499 "%st_fn_${var}_gep11 = OpAccessChain %up_u32 %${var} %c_u32_0 %st_fn_${var}_param2 %c_u32_3\n"
500 "OpStore %st_fn_${var}_gep00 %st_fn_${var}_bc00\n"
501 "OpStore %st_fn_${var}_gep01 %st_fn_${var}_bc01\n"
502 "OpStore %st_fn_${var}_gep10 %st_fn_${var}_bc10\n"
503 "OpStore %st_fn_${var}_gep11 %st_fn_${var}_bc11\n"
507 const string storeM2x4F16AsUints =
508 "%st_fn_${var} = OpFunction %void None %void_m2x4f16_i32_fn\n"
509 "%st_fn_${var}_param1 = OpFunctionParameter %m2x4f16\n"
510 "%st_fn_${var}_param2 = OpFunctionParameter %i32\n"
511 "%st_fn_${var}_entry = OpLabel\n"
512 "%st_fn_${var}_ex0 = OpCompositeExtract %v4f16 %st_fn_${var}_param1 0\n"
513 "%st_fn_${var}_ex1 = OpCompositeExtract %v4f16 %st_fn_${var}_param1 1\n"
514 "%st_fn_${var}_ele00 = OpVectorShuffle %v2f16 %st_fn_${var}_ex0 %st_fn_${var}_ex0 0 1\n"
515 "%st_fn_${var}_ele01 = OpVectorShuffle %v2f16 %st_fn_${var}_ex0 %st_fn_${var}_ex0 2 3\n"
516 "%st_fn_${var}_ele10 = OpVectorShuffle %v2f16 %st_fn_${var}_ex1 %st_fn_${var}_ex1 0 1\n"
517 "%st_fn_${var}_ele11 = OpVectorShuffle %v2f16 %st_fn_${var}_ex1 %st_fn_${var}_ex1 2 3\n"
518 "%st_fn_${var}_bc00 = OpBitcast %u32 %st_fn_${var}_ele00\n"
519 "%st_fn_${var}_bc01 = OpBitcast %u32 %st_fn_${var}_ele01\n"
520 "%st_fn_${var}_bc10 = OpBitcast %u32 %st_fn_${var}_ele10\n"
521 "%st_fn_${var}_bc11 = OpBitcast %u32 %st_fn_${var}_ele11\n"
522 "%st_fn_${var}_gep00 = OpAccessChain %up_u32 %${var} %c_u32_0 %st_fn_${var}_param2 %c_u32_0\n"
523 "%st_fn_${var}_gep01 = OpAccessChain %up_u32 %${var} %c_u32_0 %st_fn_${var}_param2 %c_u32_1\n"
524 "%st_fn_${var}_gep10 = OpAccessChain %up_u32 %${var} %c_u32_0 %st_fn_${var}_param2 %c_u32_2\n"
525 "%st_fn_${var}_gep11 = OpAccessChain %up_u32 %${var} %c_u32_0 %st_fn_${var}_param2 %c_u32_3\n"
526 "OpStore %st_fn_${var}_gep00 %st_fn_${var}_bc00\n"
527 "OpStore %st_fn_${var}_gep01 %st_fn_${var}_bc01\n"
528 "OpStore %st_fn_${var}_gep10 %st_fn_${var}_bc10\n"
529 "OpStore %st_fn_${var}_gep11 %st_fn_${var}_bc11\n"
533 const string storeM3x2F16AsUints =
534 "%st_fn_${var} = OpFunction %void None %void_m3x2f16_i32_fn\n"
535 "%st_fn_${var}_param1 = OpFunctionParameter %m3x2f16\n"
536 "%st_fn_${var}_param2 = OpFunctionParameter %i32\n"
537 "%st_fn_${var}_entry = OpLabel\n"
538 "%st_fn_${var}_ex0 = OpCompositeExtract %v2f16 %st_fn_${var}_param1 0\n"
539 "%st_fn_${var}_ex1 = OpCompositeExtract %v2f16 %st_fn_${var}_param1 1\n"
540 "%st_fn_${var}_ex2 = OpCompositeExtract %v2f16 %st_fn_${var}_param1 2\n"
541 "%st_fn_${var}_bc0 = OpBitcast %u32 %st_fn_${var}_ex0\n"
542 "%st_fn_${var}_bc1 = OpBitcast %u32 %st_fn_${var}_ex1\n"
543 "%st_fn_${var}_bc2 = OpBitcast %u32 %st_fn_${var}_ex2\n"
544 "%st_fn_${var}_gep0 = OpAccessChain %up_u32 %${var} %c_u32_0 %st_fn_${var}_param2 %c_u32_0\n"
545 "%st_fn_${var}_gep1 = OpAccessChain %up_u32 %${var} %c_u32_0 %st_fn_${var}_param2 %c_u32_1\n"
546 "%st_fn_${var}_gep2 = OpAccessChain %up_u32 %${var} %c_u32_0 %st_fn_${var}_param2 %c_u32_2\n"
547 "OpStore %st_fn_${var}_gep0 %st_fn_${var}_bc0\n"
548 "OpStore %st_fn_${var}_gep1 %st_fn_${var}_bc1\n"
549 "OpStore %st_fn_${var}_gep2 %st_fn_${var}_bc2\n"
553 const string storeM3x3F16AsUints =
554 // The second element of the each broken down vec3 doesn't matter.
555 "%st_fn_${var} = OpFunction %void None %void_m3x3f16_i32_fn\n"
556 "%st_fn_${var}_param1 = OpFunctionParameter %m3x3f16\n"
557 "%st_fn_${var}_param2 = OpFunctionParameter %i32\n"
558 "%st_fn_${var}_entry = OpLabel\n"
559 "%st_fn_${var}_ex0 = OpCompositeExtract %v3f16 %st_fn_${var}_param1 0\n"
560 "%st_fn_${var}_ex1 = OpCompositeExtract %v3f16 %st_fn_${var}_param1 1\n"
561 "%st_fn_${var}_ex2 = OpCompositeExtract %v3f16 %st_fn_${var}_param1 2\n"
562 "%st_fn_${var}_ele00 = OpVectorShuffle %v2f16 %st_fn_${var}_ex0 %st_fn_${var}_ex0 0 1\n"
563 "%st_fn_${var}_ele01 = OpVectorShuffle %v2f16 %st_fn_${var}_ex0 %st_fn_${var}_ex0 2 3\n"
564 "%st_fn_${var}_ele10 = OpVectorShuffle %v2f16 %st_fn_${var}_ex1 %st_fn_${var}_ex1 0 1\n"
565 "%st_fn_${var}_ele11 = OpVectorShuffle %v2f16 %st_fn_${var}_ex1 %st_fn_${var}_ex1 2 3\n"
566 "%st_fn_${var}_ele20 = OpVectorShuffle %v2f16 %st_fn_${var}_ex2 %st_fn_${var}_ex2 0 1\n"
567 "%st_fn_${var}_ele21 = OpVectorShuffle %v2f16 %st_fn_${var}_ex2 %st_fn_${var}_ex2 2 3\n"
568 "%st_fn_${var}_bc00 = OpBitcast %u32 %st_fn_${var}_ele00\n"
569 "%st_fn_${var}_bc01 = OpBitcast %u32 %st_fn_${var}_ele01\n"
570 "%st_fn_${var}_bc10 = OpBitcast %u32 %st_fn_${var}_ele10\n"
571 "%st_fn_${var}_bc11 = OpBitcast %u32 %st_fn_${var}_ele11\n"
572 "%st_fn_${var}_bc20 = OpBitcast %u32 %st_fn_${var}_ele20\n"
573 "%st_fn_${var}_bc21 = OpBitcast %u32 %st_fn_${var}_ele21\n"
574 "%st_fn_${var}_gep00 = OpAccessChain %up_u32 %${var} %c_u32_0 %st_fn_${var}_param2 %c_u32_0\n"
575 "%st_fn_${var}_gep01 = OpAccessChain %up_u32 %${var} %c_u32_0 %st_fn_${var}_param2 %c_u32_1\n"
576 "%st_fn_${var}_gep10 = OpAccessChain %up_u32 %${var} %c_u32_0 %st_fn_${var}_param2 %c_u32_2\n"
577 "%st_fn_${var}_gep11 = OpAccessChain %up_u32 %${var} %c_u32_0 %st_fn_${var}_param2 %c_u32_3\n"
578 "%st_fn_${var}_gep20 = OpAccessChain %up_u32 %${var} %c_u32_0 %st_fn_${var}_param2 %c_u32_4\n"
579 "%st_fn_${var}_gep21 = OpAccessChain %up_u32 %${var} %c_u32_0 %st_fn_${var}_param2 %c_u32_5\n"
580 "OpStore %st_fn_${var}_gep00 %st_fn_${var}_bc00\n"
581 "OpStore %st_fn_${var}_gep01 %st_fn_${var}_bc01\n"
582 "OpStore %st_fn_${var}_gep10 %st_fn_${var}_bc10\n"
583 "OpStore %st_fn_${var}_gep11 %st_fn_${var}_bc11\n"
584 "OpStore %st_fn_${var}_gep20 %st_fn_${var}_bc20\n"
585 "OpStore %st_fn_${var}_gep21 %st_fn_${var}_bc21\n"
589 const string storeM3x4F16AsUints =
590 "%st_fn_${var} = OpFunction %void None %void_m3x4f16_i32_fn\n"
591 "%st_fn_${var}_param1 = OpFunctionParameter %m3x4f16\n"
592 "%st_fn_${var}_param2 = OpFunctionParameter %i32\n"
593 "%st_fn_${var}_entry = OpLabel\n"
594 "%st_fn_${var}_ex0 = OpCompositeExtract %v4f16 %st_fn_${var}_param1 0\n"
595 "%st_fn_${var}_ex1 = OpCompositeExtract %v4f16 %st_fn_${var}_param1 1\n"
596 "%st_fn_${var}_ex2 = OpCompositeExtract %v4f16 %st_fn_${var}_param1 2\n"
597 "%st_fn_${var}_ele00 = OpVectorShuffle %v2f16 %st_fn_${var}_ex0 %st_fn_${var}_ex0 0 1\n"
598 "%st_fn_${var}_ele01 = OpVectorShuffle %v2f16 %st_fn_${var}_ex0 %st_fn_${var}_ex0 2 3\n"
599 "%st_fn_${var}_ele10 = OpVectorShuffle %v2f16 %st_fn_${var}_ex1 %st_fn_${var}_ex1 0 1\n"
600 "%st_fn_${var}_ele11 = OpVectorShuffle %v2f16 %st_fn_${var}_ex1 %st_fn_${var}_ex1 2 3\n"
601 "%st_fn_${var}_ele20 = OpVectorShuffle %v2f16 %st_fn_${var}_ex2 %st_fn_${var}_ex2 0 1\n"
602 "%st_fn_${var}_ele21 = OpVectorShuffle %v2f16 %st_fn_${var}_ex2 %st_fn_${var}_ex2 2 3\n"
603 "%st_fn_${var}_bc00 = OpBitcast %u32 %st_fn_${var}_ele00\n"
604 "%st_fn_${var}_bc01 = OpBitcast %u32 %st_fn_${var}_ele01\n"
605 "%st_fn_${var}_bc10 = OpBitcast %u32 %st_fn_${var}_ele10\n"
606 "%st_fn_${var}_bc11 = OpBitcast %u32 %st_fn_${var}_ele11\n"
607 "%st_fn_${var}_bc20 = OpBitcast %u32 %st_fn_${var}_ele20\n"
608 "%st_fn_${var}_bc21 = OpBitcast %u32 %st_fn_${var}_ele21\n"
609 "%st_fn_${var}_gep00 = OpAccessChain %up_u32 %${var} %c_u32_0 %st_fn_${var}_param2 %c_u32_0\n"
610 "%st_fn_${var}_gep01 = OpAccessChain %up_u32 %${var} %c_u32_0 %st_fn_${var}_param2 %c_u32_1\n"
611 "%st_fn_${var}_gep10 = OpAccessChain %up_u32 %${var} %c_u32_0 %st_fn_${var}_param2 %c_u32_2\n"
612 "%st_fn_${var}_gep11 = OpAccessChain %up_u32 %${var} %c_u32_0 %st_fn_${var}_param2 %c_u32_3\n"
613 "%st_fn_${var}_gep20 = OpAccessChain %up_u32 %${var} %c_u32_0 %st_fn_${var}_param2 %c_u32_4\n"
614 "%st_fn_${var}_gep21 = OpAccessChain %up_u32 %${var} %c_u32_0 %st_fn_${var}_param2 %c_u32_5\n"
615 "OpStore %st_fn_${var}_gep00 %st_fn_${var}_bc00\n"
616 "OpStore %st_fn_${var}_gep01 %st_fn_${var}_bc01\n"
617 "OpStore %st_fn_${var}_gep10 %st_fn_${var}_bc10\n"
618 "OpStore %st_fn_${var}_gep11 %st_fn_${var}_bc11\n"
619 "OpStore %st_fn_${var}_gep20 %st_fn_${var}_bc20\n"
620 "OpStore %st_fn_${var}_gep21 %st_fn_${var}_bc21\n"
624 const string storeM4x2F16AsUints =
625 "%st_fn_${var} = OpFunction %void None %void_m4x2f16_i32_fn\n"
626 "%st_fn_${var}_param1 = OpFunctionParameter %m4x2f16\n"
627 "%st_fn_${var}_param2 = OpFunctionParameter %i32\n"
628 "%st_fn_${var}_entry = OpLabel\n"
629 "%st_fn_${var}_ex0 = OpCompositeExtract %v2f16 %st_fn_${var}_param1 0\n"
630 "%st_fn_${var}_ex1 = OpCompositeExtract %v2f16 %st_fn_${var}_param1 1\n"
631 "%st_fn_${var}_ex2 = OpCompositeExtract %v2f16 %st_fn_${var}_param1 2\n"
632 "%st_fn_${var}_ex3 = OpCompositeExtract %v2f16 %st_fn_${var}_param1 3\n"
633 "%st_fn_${var}_bc0 = OpBitcast %u32 %st_fn_${var}_ex0\n"
634 "%st_fn_${var}_bc1 = OpBitcast %u32 %st_fn_${var}_ex1\n"
635 "%st_fn_${var}_bc2 = OpBitcast %u32 %st_fn_${var}_ex2\n"
636 "%st_fn_${var}_bc3 = OpBitcast %u32 %st_fn_${var}_ex3\n"
637 "%st_fn_${var}_gep0 = OpAccessChain %up_u32 %${var} %c_u32_0 %st_fn_${var}_param2 %c_u32_0\n"
638 "%st_fn_${var}_gep1 = OpAccessChain %up_u32 %${var} %c_u32_0 %st_fn_${var}_param2 %c_u32_1\n"
639 "%st_fn_${var}_gep2 = OpAccessChain %up_u32 %${var} %c_u32_0 %st_fn_${var}_param2 %c_u32_2\n"
640 "%st_fn_${var}_gep3 = OpAccessChain %up_u32 %${var} %c_u32_0 %st_fn_${var}_param2 %c_u32_3\n"
641 "OpStore %st_fn_${var}_gep0 %st_fn_${var}_bc0\n"
642 "OpStore %st_fn_${var}_gep1 %st_fn_${var}_bc1\n"
643 "OpStore %st_fn_${var}_gep2 %st_fn_${var}_bc2\n"
644 "OpStore %st_fn_${var}_gep3 %st_fn_${var}_bc3\n"
648 const string storeM4x3F16AsUints =
649 // The last element of each decomposed vec3 doesn't matter.
650 "%st_fn_${var} = OpFunction %void None %void_m4x3f16_i32_fn\n"
651 "%st_fn_${var}_param1 = OpFunctionParameter %m4x3f16\n"
652 "%st_fn_${var}_param2 = OpFunctionParameter %i32\n"
653 "%st_fn_${var}_entry = OpLabel\n"
654 "%st_fn_${var}_ex0 = OpCompositeExtract %v3f16 %st_fn_${var}_param1 0\n"
655 "%st_fn_${var}_ex1 = OpCompositeExtract %v3f16 %st_fn_${var}_param1 1\n"
656 "%st_fn_${var}_ex2 = OpCompositeExtract %v3f16 %st_fn_${var}_param1 2\n"
657 "%st_fn_${var}_ex3 = OpCompositeExtract %v3f16 %st_fn_${var}_param1 3\n"
658 "%st_fn_${var}_ele00 = OpVectorShuffle %v2f16 %st_fn_${var}_ex0 %st_fn_${var}_ex0 0 1\n"
659 "%st_fn_${var}_ele01 = OpVectorShuffle %v2f16 %st_fn_${var}_ex0 %st_fn_${var}_ex0 2 3\n"
660 "%st_fn_${var}_ele10 = OpVectorShuffle %v2f16 %st_fn_${var}_ex1 %st_fn_${var}_ex1 0 1\n"
661 "%st_fn_${var}_ele11 = OpVectorShuffle %v2f16 %st_fn_${var}_ex1 %st_fn_${var}_ex1 2 3\n"
662 "%st_fn_${var}_ele20 = OpVectorShuffle %v2f16 %st_fn_${var}_ex2 %st_fn_${var}_ex2 0 1\n"
663 "%st_fn_${var}_ele21 = OpVectorShuffle %v2f16 %st_fn_${var}_ex2 %st_fn_${var}_ex2 2 3\n"
664 "%st_fn_${var}_ele30 = OpVectorShuffle %v2f16 %st_fn_${var}_ex3 %st_fn_${var}_ex3 0 1\n"
665 "%st_fn_${var}_ele31 = OpVectorShuffle %v2f16 %st_fn_${var}_ex3 %st_fn_${var}_ex3 2 3\n"
666 "%st_fn_${var}_bc00 = OpBitcast %u32 %st_fn_${var}_ele00\n"
667 "%st_fn_${var}_bc01 = OpBitcast %u32 %st_fn_${var}_ele01\n"
668 "%st_fn_${var}_bc10 = OpBitcast %u32 %st_fn_${var}_ele10\n"
669 "%st_fn_${var}_bc11 = OpBitcast %u32 %st_fn_${var}_ele11\n"
670 "%st_fn_${var}_bc20 = OpBitcast %u32 %st_fn_${var}_ele20\n"
671 "%st_fn_${var}_bc21 = OpBitcast %u32 %st_fn_${var}_ele21\n"
672 "%st_fn_${var}_bc30 = OpBitcast %u32 %st_fn_${var}_ele30\n"
673 "%st_fn_${var}_bc31 = OpBitcast %u32 %st_fn_${var}_ele31\n"
674 "%st_fn_${var}_gep00 = OpAccessChain %up_u32 %${var} %c_u32_0 %st_fn_${var}_param2 %c_u32_0\n"
675 "%st_fn_${var}_gep01 = OpAccessChain %up_u32 %${var} %c_u32_0 %st_fn_${var}_param2 %c_u32_1\n"
676 "%st_fn_${var}_gep10 = OpAccessChain %up_u32 %${var} %c_u32_0 %st_fn_${var}_param2 %c_u32_2\n"
677 "%st_fn_${var}_gep11 = OpAccessChain %up_u32 %${var} %c_u32_0 %st_fn_${var}_param2 %c_u32_3\n"
678 "%st_fn_${var}_gep20 = OpAccessChain %up_u32 %${var} %c_u32_0 %st_fn_${var}_param2 %c_u32_4\n"
679 "%st_fn_${var}_gep21 = OpAccessChain %up_u32 %${var} %c_u32_0 %st_fn_${var}_param2 %c_u32_5\n"
680 "%st_fn_${var}_gep30 = OpAccessChain %up_u32 %${var} %c_u32_0 %st_fn_${var}_param2 %c_u32_6\n"
681 "%st_fn_${var}_gep31 = OpAccessChain %up_u32 %${var} %c_u32_0 %st_fn_${var}_param2 %c_u32_7\n"
682 "OpStore %st_fn_${var}_gep00 %st_fn_${var}_bc00\n"
683 "OpStore %st_fn_${var}_gep01 %st_fn_${var}_bc01\n"
684 "OpStore %st_fn_${var}_gep10 %st_fn_${var}_bc10\n"
685 "OpStore %st_fn_${var}_gep11 %st_fn_${var}_bc11\n"
686 "OpStore %st_fn_${var}_gep20 %st_fn_${var}_bc20\n"
687 "OpStore %st_fn_${var}_gep21 %st_fn_${var}_bc21\n"
688 "OpStore %st_fn_${var}_gep30 %st_fn_${var}_bc30\n"
689 "OpStore %st_fn_${var}_gep31 %st_fn_${var}_bc31\n"
693 const string storeM4x4F16AsUints =
694 "%st_fn_${var} = OpFunction %void None %void_m4x4f16_i32_fn\n"
695 "%st_fn_${var}_param1 = OpFunctionParameter %m4x4f16\n"
696 "%st_fn_${var}_param2 = OpFunctionParameter %i32\n"
697 "%st_fn_${var}_entry = OpLabel\n"
698 "%st_fn_${var}_ex0 = OpCompositeExtract %v4f16 %st_fn_${var}_param1 0\n"
699 "%st_fn_${var}_ex1 = OpCompositeExtract %v4f16 %st_fn_${var}_param1 1\n"
700 "%st_fn_${var}_ex2 = OpCompositeExtract %v4f16 %st_fn_${var}_param1 2\n"
701 "%st_fn_${var}_ex3 = OpCompositeExtract %v4f16 %st_fn_${var}_param1 3\n"
702 "%st_fn_${var}_ele00 = OpVectorShuffle %v2f16 %st_fn_${var}_ex0 %st_fn_${var}_ex0 0 1\n"
703 "%st_fn_${var}_ele01 = OpVectorShuffle %v2f16 %st_fn_${var}_ex0 %st_fn_${var}_ex0 2 3\n"
704 "%st_fn_${var}_ele10 = OpVectorShuffle %v2f16 %st_fn_${var}_ex1 %st_fn_${var}_ex1 0 1\n"
705 "%st_fn_${var}_ele11 = OpVectorShuffle %v2f16 %st_fn_${var}_ex1 %st_fn_${var}_ex1 2 3\n"
706 "%st_fn_${var}_ele20 = OpVectorShuffle %v2f16 %st_fn_${var}_ex2 %st_fn_${var}_ex2 0 1\n"
707 "%st_fn_${var}_ele21 = OpVectorShuffle %v2f16 %st_fn_${var}_ex2 %st_fn_${var}_ex2 2 3\n"
708 "%st_fn_${var}_ele30 = OpVectorShuffle %v2f16 %st_fn_${var}_ex3 %st_fn_${var}_ex3 0 1\n"
709 "%st_fn_${var}_ele31 = OpVectorShuffle %v2f16 %st_fn_${var}_ex3 %st_fn_${var}_ex3 2 3\n"
710 "%st_fn_${var}_bc00 = OpBitcast %u32 %st_fn_${var}_ele00\n"
711 "%st_fn_${var}_bc01 = OpBitcast %u32 %st_fn_${var}_ele01\n"
712 "%st_fn_${var}_bc10 = OpBitcast %u32 %st_fn_${var}_ele10\n"
713 "%st_fn_${var}_bc11 = OpBitcast %u32 %st_fn_${var}_ele11\n"
714 "%st_fn_${var}_bc20 = OpBitcast %u32 %st_fn_${var}_ele20\n"
715 "%st_fn_${var}_bc21 = OpBitcast %u32 %st_fn_${var}_ele21\n"
716 "%st_fn_${var}_bc30 = OpBitcast %u32 %st_fn_${var}_ele30\n"
717 "%st_fn_${var}_bc31 = OpBitcast %u32 %st_fn_${var}_ele31\n"
718 "%st_fn_${var}_gep00 = OpAccessChain %up_u32 %${var} %c_u32_0 %st_fn_${var}_param2 %c_u32_0\n"
719 "%st_fn_${var}_gep01 = OpAccessChain %up_u32 %${var} %c_u32_0 %st_fn_${var}_param2 %c_u32_1\n"
720 "%st_fn_${var}_gep10 = OpAccessChain %up_u32 %${var} %c_u32_0 %st_fn_${var}_param2 %c_u32_2\n"
721 "%st_fn_${var}_gep11 = OpAccessChain %up_u32 %${var} %c_u32_0 %st_fn_${var}_param2 %c_u32_3\n"
722 "%st_fn_${var}_gep20 = OpAccessChain %up_u32 %${var} %c_u32_0 %st_fn_${var}_param2 %c_u32_4\n"
723 "%st_fn_${var}_gep21 = OpAccessChain %up_u32 %${var} %c_u32_0 %st_fn_${var}_param2 %c_u32_5\n"
724 "%st_fn_${var}_gep30 = OpAccessChain %up_u32 %${var} %c_u32_0 %st_fn_${var}_param2 %c_u32_6\n"
725 "%st_fn_${var}_gep31 = OpAccessChain %up_u32 %${var} %c_u32_0 %st_fn_${var}_param2 %c_u32_7\n"
726 "OpStore %st_fn_${var}_gep00 %st_fn_${var}_bc00\n"
727 "OpStore %st_fn_${var}_gep01 %st_fn_${var}_bc01\n"
728 "OpStore %st_fn_${var}_gep10 %st_fn_${var}_bc10\n"
729 "OpStore %st_fn_${var}_gep11 %st_fn_${var}_bc11\n"
730 "OpStore %st_fn_${var}_gep20 %st_fn_${var}_bc20\n"
731 "OpStore %st_fn_${var}_gep21 %st_fn_${var}_bc21\n"
732 "OpStore %st_fn_${var}_gep30 %st_fn_${var}_bc30\n"
733 "OpStore %st_fn_${var}_gep31 %st_fn_${var}_bc31\n"
738 static void fillRandomScalars (de::Random& rnd, T minValue, T maxValue, void* dst, int numValues, int offset = 0)
740 T* const typedPtr = (T*)dst;
741 for (int ndx = 0; ndx < numValues; ndx++)
742 typedPtr[offset + ndx] = de::randomScalar<T>(rnd, minValue, maxValue);
745 // Filter is a function that returns true if a value should pass, false otherwise.
746 template<typename T, typename FilterT>
747 static void fillRandomScalars (de::Random& rnd, T minValue, T maxValue, void* dst, int numValues, FilterT filter, int offset = 0)
749 T* const typedPtr = (T*)dst;
751 for (int ndx = 0; ndx < numValues; ndx++)
754 value = de::randomScalar<T>(rnd, minValue, maxValue);
755 while (!filter(value));
757 typedPtr[offset + ndx] = value;
761 // Gets a 64-bit integer with a more logarithmic distribution
762 deInt64 randomInt64LogDistributed (de::Random& rnd)
764 deInt64 val = rnd.getUint64();
765 val &= (1ull << rnd.getInt(1, 63)) - 1;
771 static void fillRandomInt64sLogDistributed (de::Random& rnd, vector<deInt64>& dst, int numValues)
773 for (int ndx = 0; ndx < numValues; ndx++)
774 dst[ndx] = randomInt64LogDistributed(rnd);
777 template<typename FilterT>
778 static void fillRandomInt64sLogDistributed (de::Random& rnd, vector<deInt64>& dst, int numValues, FilterT filter)
780 for (int ndx = 0; ndx < numValues; ndx++)
784 value = randomInt64LogDistributed(rnd);
785 } while (!filter(value));
790 inline bool filterNonNegative (const deInt64 value)
795 inline bool filterPositive (const deInt64 value)
800 inline bool filterNotZero (const deInt64 value)
805 static void floorAll (vector<float>& values)
807 for (size_t i = 0; i < values.size(); i++)
808 values[i] = deFloatFloor(values[i]);
811 static void floorAll (vector<Vec4>& values)
813 for (size_t i = 0; i < values.size(); i++)
814 values[i] = floor(values[i]);
822 CaseParameter (const char* case_, const string& param_) : name(case_), param(param_) {}
825 // Assembly code used for testing LocalSize, OpNop, OpConstant{Null|Composite}, Op[No]Line, OpSource[Continued], OpSourceExtension, OpUndef is based on GLSL source code:
829 // layout(std140, set = 0, binding = 0) readonly buffer Input {
832 // layout(std140, set = 0, binding = 1) writeonly buffer Output {
836 // layout (local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
839 // uint x = gl_GlobalInvocationID.x;
840 // output_data.elements[x] = -input_data.elements[x];
843 static string getAsmForLocalSizeTest(bool useLiteralLocalSize, bool useSpecConstantWorkgroupSize, IVec3 workGroupSize, deUint32 ndx)
845 std::ostringstream out;
846 out << getComputeAsmShaderPreambleWithoutLocalSize();
848 if (useLiteralLocalSize)
850 out << "OpExecutionMode %main LocalSize "
851 << workGroupSize.x() << " " << workGroupSize.y() << " " << workGroupSize.z() << "\n";
854 out << "OpSource GLSL 430\n"
855 "OpName %main \"main\"\n"
856 "OpName %id \"gl_GlobalInvocationID\"\n"
857 "OpDecorate %id BuiltIn GlobalInvocationId\n";
859 if (useSpecConstantWorkgroupSize)
861 out << "OpDecorate %spec_0 SpecId 100\n"
862 << "OpDecorate %spec_1 SpecId 101\n"
863 << "OpDecorate %spec_2 SpecId 102\n"
864 << "OpDecorate %gl_WorkGroupSize BuiltIn WorkgroupSize\n";
867 out << getComputeAsmInputOutputBufferTraits()
868 << getComputeAsmCommonTypes()
869 << getComputeAsmInputOutputBuffer()
870 << "%id = OpVariable %uvec3ptr Input\n"
871 << "%zero = OpConstant %i32 0 \n";
873 if (useSpecConstantWorkgroupSize)
875 out << "%spec_0 = OpSpecConstant %u32 "<< workGroupSize.x() << "\n"
876 << "%spec_1 = OpSpecConstant %u32 "<< workGroupSize.y() << "\n"
877 << "%spec_2 = OpSpecConstant %u32 "<< workGroupSize.z() << "\n"
878 << "%gl_WorkGroupSize = OpSpecConstantComposite %uvec3 %spec_0 %spec_1 %spec_2\n";
881 out << "%main = OpFunction %void None %voidf\n"
882 << "%label = OpLabel\n"
883 << "%idval = OpLoad %uvec3 %id\n"
884 << "%ndx = OpCompositeExtract %u32 %idval " << ndx << "\n"
886 "%inloc = OpAccessChain %f32ptr %indata %zero %ndx\n"
887 "%inval = OpLoad %f32 %inloc\n"
888 "%neg = OpFNegate %f32 %inval\n"
889 "%outloc = OpAccessChain %f32ptr %outdata %zero %ndx\n"
890 " OpStore %outloc %neg\n"
896 tcu::TestCaseGroup* createLocalSizeGroup (tcu::TestContext& testCtx)
898 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "localsize", ""));
899 ComputeShaderSpec spec;
900 de::Random rnd (deStringHash(group->getName()));
901 const deUint32 numElements = 64u;
902 vector<float> positiveFloats (numElements, 0);
903 vector<float> negativeFloats (numElements, 0);
905 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
907 for (size_t ndx = 0; ndx < numElements; ++ndx)
908 negativeFloats[ndx] = -positiveFloats[ndx];
910 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
911 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
913 spec.numWorkGroups = IVec3(numElements, 1, 1);
915 spec.assembly = getAsmForLocalSizeTest(true, false, IVec3(1, 1, 1), 0u);
916 group->addChild(new SpvAsmComputeShaderCase(testCtx, "literal_localsize", "", spec));
918 spec.assembly = getAsmForLocalSizeTest(true, true, IVec3(1, 1, 1), 0u);
919 group->addChild(new SpvAsmComputeShaderCase(testCtx, "literal_and_specid_localsize", "", spec));
921 spec.assembly = getAsmForLocalSizeTest(false, true, IVec3(1, 1, 1), 0u);
922 group->addChild(new SpvAsmComputeShaderCase(testCtx, "specid_localsize", "", spec));
924 spec.numWorkGroups = IVec3(1, 1, 1);
926 spec.assembly = getAsmForLocalSizeTest(true, false, IVec3(numElements, 1, 1), 0u);
927 group->addChild(new SpvAsmComputeShaderCase(testCtx, "literal_localsize_x", "", spec));
929 spec.assembly = getAsmForLocalSizeTest(true, true, IVec3(numElements, 1, 1), 0u);
930 group->addChild(new SpvAsmComputeShaderCase(testCtx, "literal_and_specid_localsize_x", "", spec));
932 spec.assembly = getAsmForLocalSizeTest(false, true, IVec3(numElements, 1, 1), 0u);
933 group->addChild(new SpvAsmComputeShaderCase(testCtx, "specid_localsize_x", "", spec));
935 spec.assembly = getAsmForLocalSizeTest(true, false, IVec3(1, numElements, 1), 1u);
936 group->addChild(new SpvAsmComputeShaderCase(testCtx, "literal_localsize_y", "", spec));
938 spec.assembly = getAsmForLocalSizeTest(true, true, IVec3(1, numElements, 1), 1u);
939 group->addChild(new SpvAsmComputeShaderCase(testCtx, "literal_and_specid_localsize_y", "", spec));
941 spec.assembly = getAsmForLocalSizeTest(false, true, IVec3(1, numElements, 1), 1u);
942 group->addChild(new SpvAsmComputeShaderCase(testCtx, "specid_localsize_y", "", spec));
944 spec.assembly = getAsmForLocalSizeTest(true, false, IVec3(1, 1, numElements), 2u);
945 group->addChild(new SpvAsmComputeShaderCase(testCtx, "literal_localsize_z", "", spec));
947 spec.assembly = getAsmForLocalSizeTest(true, true, IVec3(1, 1, numElements), 2u);
948 group->addChild(new SpvAsmComputeShaderCase(testCtx, "literal_and_specid_localsize_z", "", spec));
950 spec.assembly = getAsmForLocalSizeTest(false, true, IVec3(1, 1, numElements), 2u);
951 group->addChild(new SpvAsmComputeShaderCase(testCtx, "specid_localsize_z", "", spec));
953 return group.release();
956 tcu::TestCaseGroup* createOpNopGroup (tcu::TestContext& testCtx)
958 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opnop", "Test the OpNop instruction"));
959 ComputeShaderSpec spec;
960 de::Random rnd (deStringHash(group->getName()));
961 const int numElements = 100;
962 vector<float> positiveFloats (numElements, 0);
963 vector<float> negativeFloats (numElements, 0);
965 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
967 for (size_t ndx = 0; ndx < numElements; ++ndx)
968 negativeFloats[ndx] = -positiveFloats[ndx];
971 string(getComputeAsmShaderPreamble()) +
973 "OpSource GLSL 430\n"
974 "OpName %main \"main\"\n"
975 "OpName %id \"gl_GlobalInvocationID\"\n"
977 "OpDecorate %id BuiltIn GlobalInvocationId\n"
979 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes())
981 + string(getComputeAsmInputOutputBuffer()) +
983 "%id = OpVariable %uvec3ptr Input\n"
984 "%zero = OpConstant %i32 0\n"
986 "%main = OpFunction %void None %voidf\n"
988 "%idval = OpLoad %uvec3 %id\n"
989 "%x = OpCompositeExtract %u32 %idval 0\n"
991 " OpNop\n" // Inside a function body
993 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
994 "%inval = OpLoad %f32 %inloc\n"
995 "%neg = OpFNegate %f32 %inval\n"
996 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
997 " OpStore %outloc %neg\n"
1000 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
1001 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
1002 spec.numWorkGroups = IVec3(numElements, 1, 1);
1004 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "OpNop appearing at different places", spec));
1006 return group.release();
1009 tcu::TestCaseGroup* createUnusedVariableComputeTests (tcu::TestContext& testCtx)
1011 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "unused_variables", "Compute shaders with unused variables"));
1012 de::Random rnd (deStringHash(group->getName()));
1013 const int numElements = 100;
1014 vector<float> positiveFloats (numElements, 0);
1015 vector<float> negativeFloats (numElements, 0);
1017 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
1019 for (size_t ndx = 0; ndx < numElements; ++ndx)
1020 negativeFloats[ndx] = -positiveFloats[ndx];
1022 const VariableLocation testLocations[] =
1029 for (size_t locationNdx = 0; locationNdx < DE_LENGTH_OF_ARRAY(testLocations); ++locationNdx)
1031 const VariableLocation& location = testLocations[locationNdx];
1035 ComputeShaderSpec spec;
1038 string(getComputeAsmShaderPreamble()) +
1040 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1042 + getUnusedDecorations(location)
1044 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes())
1046 + getUnusedTypesAndConstants()
1048 + string(getComputeAsmInputOutputBuffer())
1050 + getUnusedBuffer() +
1052 "%id = OpVariable %uvec3ptr Input\n"
1053 "%zero = OpConstant %i32 0\n"
1055 "%main = OpFunction %void None %voidf\n"
1056 "%label = OpLabel\n"
1057 "%idval = OpLoad %uvec3 %id\n"
1058 "%x = OpCompositeExtract %u32 %idval 0\n"
1060 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
1061 "%inval = OpLoad %f32 %inloc\n"
1062 "%neg = OpFNegate %f32 %inval\n"
1063 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
1064 " OpStore %outloc %neg\n"
1067 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
1068 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
1069 spec.numWorkGroups = IVec3(numElements, 1, 1);
1071 std::string testName = "variable_" + location.toString();
1072 std::string testDescription = "Unused variable test with " + location.toDescription();
1074 group->addChild(new SpvAsmComputeShaderCase(testCtx, testName.c_str(), testDescription.c_str(), spec));
1079 ComputeShaderSpec spec;
1082 string(getComputeAsmShaderPreamble("", "", "", getUnusedEntryPoint())) +
1084 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1086 + getUnusedDecorations(location)
1088 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes())
1090 + getUnusedTypesAndConstants() +
1092 "%c_i32_0 = OpConstant %i32 0\n"
1093 "%c_i32_1 = OpConstant %i32 1\n"
1095 + string(getComputeAsmInputOutputBuffer())
1097 + getUnusedBuffer() +
1099 "%id = OpVariable %uvec3ptr Input\n"
1100 "%zero = OpConstant %i32 0\n"
1102 "%main = OpFunction %void None %voidf\n"
1103 "%label = OpLabel\n"
1104 "%idval = OpLoad %uvec3 %id\n"
1105 "%x = OpCompositeExtract %u32 %idval 0\n"
1107 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
1108 "%inval = OpLoad %f32 %inloc\n"
1109 "%neg = OpFNegate %f32 %inval\n"
1110 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
1111 " OpStore %outloc %neg\n"
1115 + getUnusedFunctionBody();
1117 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
1118 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
1119 spec.numWorkGroups = IVec3(numElements, 1, 1);
1121 std::string testName = "function_" + location.toString();
1122 std::string testDescription = "Unused function test with " + location.toDescription();
1124 group->addChild(new SpvAsmComputeShaderCase(testCtx, testName.c_str(), testDescription.c_str(), spec));
1128 return group.release();
1131 template<bool nanSupported>
1132 bool compareFUnord (const std::vector<Resource>& inputs, const vector<AllocationSp>& outputAllocs, const std::vector<Resource>& expectedOutputs, TestLog& log)
1134 if (outputAllocs.size() != 1)
1137 vector<deUint8> input1Bytes;
1138 vector<deUint8> input2Bytes;
1139 vector<deUint8> expectedBytes;
1141 inputs[0].getBytes(input1Bytes);
1142 inputs[1].getBytes(input2Bytes);
1143 expectedOutputs[0].getBytes(expectedBytes);
1145 const deInt32* const expectedOutputAsInt = reinterpret_cast<const deInt32*>(&expectedBytes.front());
1146 const deInt32* const outputAsInt = static_cast<const deInt32*>(outputAllocs[0]->getHostPtr());
1147 const float* const input1AsFloat = reinterpret_cast<const float*>(&input1Bytes.front());
1148 const float* const input2AsFloat = reinterpret_cast<const float*>(&input2Bytes.front());
1149 bool returnValue = true;
1151 for (size_t idx = 0; idx < expectedBytes.size() / sizeof(deInt32); ++idx)
1153 if (!nanSupported && (tcu::Float32(input1AsFloat[idx]).isNaN() || tcu::Float32(input2AsFloat[idx]).isNaN()))
1156 if (outputAsInt[idx] != expectedOutputAsInt[idx])
1158 log << TestLog::Message << "ERROR: Sub-case failed. inputs: " << input1AsFloat[idx] << "," << input2AsFloat[idx] << " output: " << outputAsInt[idx]<< " expected output: " << expectedOutputAsInt[idx] << TestLog::EndMessage;
1159 returnValue = false;
1165 typedef VkBool32 (*compareFuncType) (float, float);
1171 compareFuncType compareFunc;
1173 OpFUnordCase (const char* _name, const char* _opCode, compareFuncType _compareFunc)
1176 , compareFunc (_compareFunc) {}
1179 #define ADD_OPFUNORD_CASE(NAME, OPCODE, OPERATOR) \
1181 struct compare_##NAME { static VkBool32 compare(float x, float y) { return (x OPERATOR y) ? VK_TRUE : VK_FALSE; } }; \
1182 cases.push_back(OpFUnordCase(#NAME, OPCODE, compare_##NAME::compare)); \
1183 } while (deGetFalse())
1185 tcu::TestCaseGroup* createOpFUnordGroup (tcu::TestContext& testCtx, const bool testWithNan)
1187 const string nan = testWithNan ? "_nan" : "";
1188 const string groupName = "opfunord" + nan;
1189 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, groupName.c_str(), "Test the OpFUnord* opcodes"));
1190 de::Random rnd (deStringHash(group->getName()));
1191 const int numElements = 100;
1192 vector<OpFUnordCase> cases;
1193 string extensions = testWithNan ? "OpExtension \"SPV_KHR_float_controls\"\n" : "";
1194 string capabilities = testWithNan ? "OpCapability SignedZeroInfNanPreserve\n" : "";
1195 string exeModes = testWithNan ? "OpExecutionMode %main SignedZeroInfNanPreserve 32\n" : "";
1196 const StringTemplate shaderTemplate (
1197 string(getComputeAsmShaderPreamble(capabilities, extensions, exeModes)) +
1198 "OpSource GLSL 430\n"
1199 "OpName %main \"main\"\n"
1200 "OpName %id \"gl_GlobalInvocationID\"\n"
1202 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1204 "OpDecorate %buf BufferBlock\n"
1205 "OpDecorate %buf2 BufferBlock\n"
1206 "OpDecorate %indata1 DescriptorSet 0\n"
1207 "OpDecorate %indata1 Binding 0\n"
1208 "OpDecorate %indata2 DescriptorSet 0\n"
1209 "OpDecorate %indata2 Binding 1\n"
1210 "OpDecorate %outdata DescriptorSet 0\n"
1211 "OpDecorate %outdata Binding 2\n"
1212 "OpDecorate %f32arr ArrayStride 4\n"
1213 "OpDecorate %i32arr ArrayStride 4\n"
1214 "OpMemberDecorate %buf 0 Offset 0\n"
1215 "OpMemberDecorate %buf2 0 Offset 0\n"
1217 + string(getComputeAsmCommonTypes()) +
1219 "%buf = OpTypeStruct %f32arr\n"
1220 "%bufptr = OpTypePointer Uniform %buf\n"
1221 "%indata1 = OpVariable %bufptr Uniform\n"
1222 "%indata2 = OpVariable %bufptr Uniform\n"
1224 "%buf2 = OpTypeStruct %i32arr\n"
1225 "%buf2ptr = OpTypePointer Uniform %buf2\n"
1226 "%outdata = OpVariable %buf2ptr Uniform\n"
1228 "%id = OpVariable %uvec3ptr Input\n"
1229 "%zero = OpConstant %i32 0\n"
1230 "%consti1 = OpConstant %i32 1\n"
1231 "%constf1 = OpConstant %f32 1.0\n"
1233 "%main = OpFunction %void None %voidf\n"
1234 "%label = OpLabel\n"
1235 "%idval = OpLoad %uvec3 %id\n"
1236 "%x = OpCompositeExtract %u32 %idval 0\n"
1238 "%inloc1 = OpAccessChain %f32ptr %indata1 %zero %x\n"
1239 "%inval1 = OpLoad %f32 %inloc1\n"
1240 "%inloc2 = OpAccessChain %f32ptr %indata2 %zero %x\n"
1241 "%inval2 = OpLoad %f32 %inloc2\n"
1242 "%outloc = OpAccessChain %i32ptr %outdata %zero %x\n"
1244 "%result = ${OPCODE} %bool %inval1 %inval2\n"
1245 "%int_res = OpSelect %i32 %result %consti1 %zero\n"
1246 " OpStore %outloc %int_res\n"
1249 " OpFunctionEnd\n");
1251 ADD_OPFUNORD_CASE(equal, "OpFUnordEqual", ==);
1252 ADD_OPFUNORD_CASE(less, "OpFUnordLessThan", <);
1253 ADD_OPFUNORD_CASE(lessequal, "OpFUnordLessThanEqual", <=);
1254 ADD_OPFUNORD_CASE(greater, "OpFUnordGreaterThan", >);
1255 ADD_OPFUNORD_CASE(greaterequal, "OpFUnordGreaterThanEqual", >=);
1256 ADD_OPFUNORD_CASE(notequal, "OpFUnordNotEqual", !=);
1258 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
1260 map<string, string> specializations;
1261 ComputeShaderSpec spec;
1262 const float NaN = std::numeric_limits<float>::quiet_NaN();
1263 vector<float> inputFloats1 (numElements, 0);
1264 vector<float> inputFloats2 (numElements, 0);
1265 vector<deInt32> expectedInts (numElements, 0);
1267 specializations["OPCODE"] = cases[caseNdx].opCode;
1268 spec.assembly = shaderTemplate.specialize(specializations);
1270 fillRandomScalars(rnd, 1.f, 100.f, &inputFloats1[0], numElements);
1271 for (size_t ndx = 0; ndx < numElements; ++ndx)
1275 case 0: inputFloats2[ndx] = inputFloats1[ndx] + 1.0f; break;
1276 case 1: inputFloats2[ndx] = inputFloats1[ndx] - 1.0f; break;
1277 case 2: inputFloats2[ndx] = inputFloats1[ndx]; break;
1278 case 3: inputFloats2[ndx] = NaN; break;
1279 case 4: inputFloats2[ndx] = inputFloats1[ndx]; inputFloats1[ndx] = NaN; break;
1280 case 5: inputFloats2[ndx] = NaN; inputFloats1[ndx] = NaN; break;
1282 expectedInts[ndx] = tcu::Float32(inputFloats1[ndx]).isNaN() || tcu::Float32(inputFloats2[ndx]).isNaN() || cases[caseNdx].compareFunc(inputFloats1[ndx], inputFloats2[ndx]);
1285 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats1)));
1286 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
1287 spec.outputs.push_back(BufferSp(new Int32Buffer(expectedInts)));
1288 spec.numWorkGroups = IVec3(numElements, 1, 1);
1289 spec.verifyIO = testWithNan ? &compareFUnord<true> : &compareFUnord<false>;
1293 spec.extensions.push_back("VK_KHR_shader_float_controls");
1294 spec.requestedVulkanFeatures.floatControlsProperties.shaderSignedZeroInfNanPreserveFloat32 = DE_TRUE;
1297 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
1300 return group.release();
1306 const char* assembly;
1307 const char* retValAssembly;
1308 OpAtomicType opAtomic;
1309 deInt32 numOutputElements;
1311 OpAtomicCase(const char* _name, const char* _assembly, const char* _retValAssembly, OpAtomicType _opAtomic, deInt32 _numOutputElements)
1313 , assembly (_assembly)
1314 , retValAssembly (_retValAssembly)
1315 , opAtomic (_opAtomic)
1316 , numOutputElements (_numOutputElements) {}
1319 tcu::TestCaseGroup* createOpAtomicGroup (tcu::TestContext& testCtx, bool useStorageBuffer, int numElements = 65535, bool verifyReturnValues = false, bool volatileAtomic = false)
1321 std::string groupName ("opatomic");
1322 if (useStorageBuffer)
1323 groupName += "_storage_buffer";
1324 if (verifyReturnValues)
1325 groupName += "_return_values";
1327 groupName += "_volatile";
1328 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, groupName.c_str(), "Test the OpAtomic* opcodes"));
1329 vector<OpAtomicCase> cases;
1331 const StringTemplate shaderTemplate (
1333 string("OpCapability Shader\n") +
1334 (volatileAtomic ? "OpCapability VulkanMemoryModelKHR\n" : "") +
1335 (useStorageBuffer ? "OpExtension \"SPV_KHR_storage_buffer_storage_class\"\n" : "") +
1336 (volatileAtomic ? "OpExtension \"SPV_KHR_vulkan_memory_model\"\n" : "") +
1337 (volatileAtomic ? "OpMemoryModel Logical VulkanKHR\n" : "OpMemoryModel Logical GLSL450\n") +
1338 "OpEntryPoint GLCompute %main \"main\" %id\n"
1339 "OpExecutionMode %main LocalSize 1 1 1\n" +
1341 "OpSource GLSL 430\n"
1342 "OpName %main \"main\"\n"
1343 "OpName %id \"gl_GlobalInvocationID\"\n"
1345 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1347 "OpDecorate %buf ${BLOCK_DECORATION}\n"
1348 "OpDecorate %indata DescriptorSet 0\n"
1349 "OpDecorate %indata Binding 0\n"
1350 "OpDecorate %i32arr ArrayStride 4\n"
1351 "OpMemberDecorate %buf 0 Offset 0\n"
1353 "OpDecorate %sumbuf ${BLOCK_DECORATION}\n"
1354 "OpDecorate %sum DescriptorSet 0\n"
1355 "OpDecorate %sum Binding 1\n"
1356 "OpMemberDecorate %sumbuf 0 Offset 0\n"
1358 "${RETVAL_BUF_DECORATE}"
1360 + getComputeAsmCommonTypes("${BLOCK_POINTER_TYPE}") +
1362 "%buf = OpTypeStruct %i32arr\n"
1363 "%bufptr = OpTypePointer ${BLOCK_POINTER_TYPE} %buf\n"
1364 "%indata = OpVariable %bufptr ${BLOCK_POINTER_TYPE}\n"
1366 "%sumbuf = OpTypeStruct %i32arr\n"
1367 "%sumbufptr = OpTypePointer ${BLOCK_POINTER_TYPE} %sumbuf\n"
1368 "%sum = OpVariable %sumbufptr ${BLOCK_POINTER_TYPE}\n"
1370 "${RETVAL_BUF_DECL}"
1372 "%id = OpVariable %uvec3ptr Input\n"
1373 "%minusone = OpConstant %i32 -1\n"
1374 "%zero = OpConstant %i32 0\n"
1375 "%one = OpConstant %u32 1\n"
1376 "%two = OpConstant %i32 2\n"
1377 "%five = OpConstant %i32 5\n"
1378 "%volbit = OpConstant %i32 32768\n"
1380 "%main = OpFunction %void None %voidf\n"
1381 "%label = OpLabel\n"
1382 "%idval = OpLoad %uvec3 %id\n"
1383 "%x = OpCompositeExtract %u32 %idval 0\n"
1385 "%inloc = OpAccessChain %i32ptr %indata %zero %x\n"
1386 "%inval = OpLoad %i32 %inloc\n"
1388 "%outloc = OpAccessChain %i32ptr %sum %zero ${INDEX}\n"
1390 "${RETVAL_ASSEMBLY}"
1393 " OpFunctionEnd\n");
1395 #define ADD_OPATOMIC_CASE(NAME, ASSEMBLY, RETVAL_ASSEMBLY, OPATOMIC, NUM_OUTPUT_ELEMENTS) \
1397 DE_ASSERT((NUM_OUTPUT_ELEMENTS) == 1 || (NUM_OUTPUT_ELEMENTS) == numElements); \
1398 cases.push_back(OpAtomicCase(#NAME, ASSEMBLY, RETVAL_ASSEMBLY, OPATOMIC, NUM_OUTPUT_ELEMENTS)); \
1399 } while (deGetFalse())
1400 #define ADD_OPATOMIC_CASE_1(NAME, ASSEMBLY, RETVAL_ASSEMBLY, OPATOMIC) ADD_OPATOMIC_CASE(NAME, ASSEMBLY, RETVAL_ASSEMBLY, OPATOMIC, 1)
1401 #define ADD_OPATOMIC_CASE_N(NAME, ASSEMBLY, RETVAL_ASSEMBLY, OPATOMIC) ADD_OPATOMIC_CASE(NAME, ASSEMBLY, RETVAL_ASSEMBLY, OPATOMIC, numElements)
1403 ADD_OPATOMIC_CASE_1(iadd, "%retv = OpAtomicIAdd %i32 %outloc ${SCOPE} ${SEMANTICS} %inval\n",
1404 " OpStore %retloc %retv\n", OPATOMIC_IADD );
1405 ADD_OPATOMIC_CASE_1(isub, "%retv = OpAtomicISub %i32 %outloc ${SCOPE} ${SEMANTICS} %inval\n",
1406 " OpStore %retloc %retv\n", OPATOMIC_ISUB );
1407 ADD_OPATOMIC_CASE_1(iinc, "%retv = OpAtomicIIncrement %i32 %outloc ${SCOPE} ${SEMANTICS}\n",
1408 " OpStore %retloc %retv\n", OPATOMIC_IINC );
1409 ADD_OPATOMIC_CASE_1(idec, "%retv = OpAtomicIDecrement %i32 %outloc ${SCOPE} ${SEMANTICS}\n",
1410 " OpStore %retloc %retv\n", OPATOMIC_IDEC );
1411 if (!verifyReturnValues)
1413 ADD_OPATOMIC_CASE_N(load, "%inval2 = OpAtomicLoad %i32 %inloc ${SCOPE} ${SEMANTICS}\n"
1414 " OpStore %outloc %inval2\n", "", OPATOMIC_LOAD );
1415 ADD_OPATOMIC_CASE_N(store, " OpAtomicStore %outloc ${SCOPE} ${SEMANTICS} %inval\n", "", OPATOMIC_STORE );
1418 ADD_OPATOMIC_CASE_N(compex, "%even = OpSMod %i32 %inval %two\n"
1419 " OpStore %outloc %even\n"
1420 "%retv = OpAtomicCompareExchange %i32 %outloc ${SCOPE} ${SEMANTICS} ${SEMANTICS} %minusone %zero\n",
1421 " OpStore %retloc %retv\n", OPATOMIC_COMPEX );
1424 #undef ADD_OPATOMIC_CASE
1425 #undef ADD_OPATOMIC_CASE_1
1426 #undef ADD_OPATOMIC_CASE_N
1428 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
1430 map<string, string> specializations;
1431 ComputeShaderSpec spec;
1432 vector<deInt32> inputInts (numElements, 0);
1433 vector<deInt32> expected (cases[caseNdx].numOutputElements, -1);
1437 spec.extensions.push_back("VK_KHR_vulkan_memory_model");
1438 // volatile, queuefamily scope
1439 specializations["SEMANTICS"] = "%volbit";
1440 specializations["SCOPE"] = "%five";
1444 // non-volatile, device scope
1445 specializations["SEMANTICS"] = "%zero";
1446 specializations["SCOPE"] = "%one";
1448 specializations["INDEX"] = (cases[caseNdx].numOutputElements == 1) ? "%zero" : "%x";
1449 specializations["INSTRUCTION"] = cases[caseNdx].assembly;
1450 specializations["BLOCK_DECORATION"] = useStorageBuffer ? "Block" : "BufferBlock";
1451 specializations["BLOCK_POINTER_TYPE"] = useStorageBuffer ? "StorageBuffer" : "Uniform";
1453 if (verifyReturnValues)
1455 const StringTemplate blockDecoration (
1457 "OpDecorate %retbuf ${BLOCK_DECORATION}\n"
1458 "OpDecorate %ret DescriptorSet 0\n"
1459 "OpDecorate %ret Binding 2\n"
1460 "OpMemberDecorate %retbuf 0 Offset 0\n\n");
1462 const StringTemplate blockDeclaration (
1464 "%retbuf = OpTypeStruct %i32arr\n"
1465 "%retbufptr = OpTypePointer ${BLOCK_POINTER_TYPE} %retbuf\n"
1466 "%ret = OpVariable %retbufptr ${BLOCK_POINTER_TYPE}\n\n");
1468 specializations["RETVAL_ASSEMBLY"] =
1469 "%retloc = OpAccessChain %i32ptr %ret %zero %x\n"
1470 + std::string(cases[caseNdx].retValAssembly);
1472 specializations["RETVAL_BUF_DECORATE"] = blockDecoration.specialize(specializations);
1473 specializations["RETVAL_BUF_DECL"] = blockDeclaration.specialize(specializations);
1477 specializations["RETVAL_ASSEMBLY"] = "";
1478 specializations["RETVAL_BUF_DECORATE"] = "";
1479 specializations["RETVAL_BUF_DECL"] = "";
1482 spec.assembly = shaderTemplate.specialize(specializations);
1484 // Specialize one more time, to catch things that were in a template parameter
1485 const StringTemplate assemblyTemplate(spec.assembly);
1486 spec.assembly = assemblyTemplate.specialize(specializations);
1488 if (useStorageBuffer)
1489 spec.extensions.push_back("VK_KHR_storage_buffer_storage_class");
1491 spec.inputs.push_back(BufferSp(new OpAtomicBuffer(numElements, cases[caseNdx].numOutputElements, cases[caseNdx].opAtomic, BUFFERTYPE_INPUT)));
1492 spec.outputs.push_back(BufferSp(new OpAtomicBuffer(numElements, cases[caseNdx].numOutputElements, cases[caseNdx].opAtomic, BUFFERTYPE_EXPECTED)));
1493 if (verifyReturnValues)
1494 spec.outputs.push_back(BufferSp(new OpAtomicBuffer(numElements, cases[caseNdx].numOutputElements, cases[caseNdx].opAtomic, BUFFERTYPE_ATOMIC_RET)));
1495 spec.numWorkGroups = IVec3(numElements, 1, 1);
1497 if (verifyReturnValues)
1499 switch (cases[caseNdx].opAtomic)
1502 spec.verifyIO = OpAtomicBuffer::compareWithRetvals<OPATOMIC_IADD>;
1505 spec.verifyIO = OpAtomicBuffer::compareWithRetvals<OPATOMIC_ISUB>;
1508 spec.verifyIO = OpAtomicBuffer::compareWithRetvals<OPATOMIC_IINC>;
1511 spec.verifyIO = OpAtomicBuffer::compareWithRetvals<OPATOMIC_IDEC>;
1513 case OPATOMIC_COMPEX:
1514 spec.verifyIO = OpAtomicBuffer::compareWithRetvals<OPATOMIC_COMPEX>;
1517 DE_FATAL("Unsupported OpAtomic type for return value verification");
1520 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
1523 return group.release();
1526 tcu::TestCaseGroup* createOpLineGroup (tcu::TestContext& testCtx)
1528 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opline", "Test the OpLine instruction"));
1529 ComputeShaderSpec spec;
1530 de::Random rnd (deStringHash(group->getName()));
1531 const int numElements = 100;
1532 vector<float> positiveFloats (numElements, 0);
1533 vector<float> negativeFloats (numElements, 0);
1535 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
1537 for (size_t ndx = 0; ndx < numElements; ++ndx)
1538 negativeFloats[ndx] = -positiveFloats[ndx];
1541 string(getComputeAsmShaderPreamble()) +
1543 "%fname1 = OpString \"negateInputs.comp\"\n"
1544 "%fname2 = OpString \"negateInputs\"\n"
1546 "OpSource GLSL 430\n"
1547 "OpName %main \"main\"\n"
1548 "OpName %id \"gl_GlobalInvocationID\"\n"
1550 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1552 + string(getComputeAsmInputOutputBufferTraits()) +
1554 "OpLine %fname1 0 0\n" // At the earliest possible position
1556 + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
1558 "OpLine %fname1 0 1\n" // Multiple OpLines in sequence
1559 "OpLine %fname2 1 0\n" // Different filenames
1560 "OpLine %fname1 1000 100000\n"
1562 "%id = OpVariable %uvec3ptr Input\n"
1563 "%zero = OpConstant %i32 0\n"
1565 "OpLine %fname1 1 1\n" // Before a function
1567 "%main = OpFunction %void None %voidf\n"
1568 "%label = OpLabel\n"
1570 "OpLine %fname1 1 1\n" // In a function
1572 "%idval = OpLoad %uvec3 %id\n"
1573 "%x = OpCompositeExtract %u32 %idval 0\n"
1574 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
1575 "%inval = OpLoad %f32 %inloc\n"
1576 "%neg = OpFNegate %f32 %inval\n"
1577 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
1578 " OpStore %outloc %neg\n"
1581 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
1582 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
1583 spec.numWorkGroups = IVec3(numElements, 1, 1);
1585 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "OpLine appearing at different places", spec));
1587 return group.release();
1590 bool veryfiBinaryShader (const ProgramBinary& binary)
1592 const size_t paternCount = 3u;
1593 bool paternsCheck[paternCount] =
1597 const string patersns[paternCount] =
1603 size_t paternNdx = 0u;
1605 for (size_t ndx = 0u; ndx < binary.getSize(); ++ndx)
1607 if (false == paternsCheck[paternNdx] &&
1608 patersns[paternNdx][0] == static_cast<char>(binary.getBinary()[ndx]) &&
1609 deMemoryEqual((const char*)&binary.getBinary()[ndx], &patersns[paternNdx][0], patersns[paternNdx].length()))
1611 paternsCheck[paternNdx]= true;
1613 if (paternNdx == paternCount)
1618 for (size_t ndx = 0u; ndx < paternCount; ++ndx)
1620 if (!paternsCheck[ndx])
1627 tcu::TestCaseGroup* createOpModuleProcessedGroup (tcu::TestContext& testCtx)
1629 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opmoduleprocessed", "Test the OpModuleProcessed instruction"));
1630 ComputeShaderSpec spec;
1631 de::Random rnd (deStringHash(group->getName()));
1632 const int numElements = 10;
1633 vector<float> positiveFloats (numElements, 0);
1634 vector<float> negativeFloats (numElements, 0);
1636 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
1638 for (size_t ndx = 0; ndx < numElements; ++ndx)
1639 negativeFloats[ndx] = -positiveFloats[ndx];
1642 string(getComputeAsmShaderPreamble()) +
1643 "%fname = OpString \"negateInputs.comp\"\n"
1645 "OpSource GLSL 430\n"
1646 "OpName %main \"main\"\n"
1647 "OpName %id \"gl_GlobalInvocationID\"\n"
1648 "OpModuleProcessed \"VULKAN CTS\"\n" //OpModuleProcessed;
1649 "OpModuleProcessed \"Negative values\"\n"
1650 "OpModuleProcessed \"Date: 2017/09/21\"\n"
1651 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1653 + string(getComputeAsmInputOutputBufferTraits())
1655 + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
1657 "OpLine %fname 0 1\n"
1659 "OpLine %fname 1000 1\n"
1661 "%id = OpVariable %uvec3ptr Input\n"
1662 "%zero = OpConstant %i32 0\n"
1663 "%main = OpFunction %void None %voidf\n"
1665 "%label = OpLabel\n"
1666 "%idval = OpLoad %uvec3 %id\n"
1667 "%x = OpCompositeExtract %u32 %idval 0\n"
1669 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
1670 "%inval = OpLoad %f32 %inloc\n"
1671 "%neg = OpFNegate %f32 %inval\n"
1672 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
1673 " OpStore %outloc %neg\n"
1676 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
1677 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
1678 spec.numWorkGroups = IVec3(numElements, 1, 1);
1679 spec.verifyBinary = veryfiBinaryShader;
1680 spec.spirvVersion = SPIRV_VERSION_1_3;
1682 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "OpModuleProcessed Tests", spec));
1684 return group.release();
1687 tcu::TestCaseGroup* createOpNoLineGroup (tcu::TestContext& testCtx)
1689 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opnoline", "Test the OpNoLine instruction"));
1690 ComputeShaderSpec spec;
1691 de::Random rnd (deStringHash(group->getName()));
1692 const int numElements = 100;
1693 vector<float> positiveFloats (numElements, 0);
1694 vector<float> negativeFloats (numElements, 0);
1696 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
1698 for (size_t ndx = 0; ndx < numElements; ++ndx)
1699 negativeFloats[ndx] = -positiveFloats[ndx];
1702 string(getComputeAsmShaderPreamble()) +
1704 "%fname = OpString \"negateInputs.comp\"\n"
1706 "OpSource GLSL 430\n"
1707 "OpName %main \"main\"\n"
1708 "OpName %id \"gl_GlobalInvocationID\"\n"
1710 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1712 + string(getComputeAsmInputOutputBufferTraits()) +
1714 "OpNoLine\n" // At the earliest possible position, without preceding OpLine
1716 + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
1718 "OpLine %fname 0 1\n"
1719 "OpNoLine\n" // Immediately following a preceding OpLine
1721 "OpLine %fname 1000 1\n"
1723 "%id = OpVariable %uvec3ptr Input\n"
1724 "%zero = OpConstant %i32 0\n"
1726 "OpNoLine\n" // Contents after the previous OpLine
1728 "%main = OpFunction %void None %voidf\n"
1729 "%label = OpLabel\n"
1730 "%idval = OpLoad %uvec3 %id\n"
1731 "%x = OpCompositeExtract %u32 %idval 0\n"
1733 "OpNoLine\n" // Multiple OpNoLine
1737 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
1738 "%inval = OpLoad %f32 %inloc\n"
1739 "%neg = OpFNegate %f32 %inval\n"
1740 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
1741 " OpStore %outloc %neg\n"
1744 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
1745 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
1746 spec.numWorkGroups = IVec3(numElements, 1, 1);
1748 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "OpNoLine appearing at different places", spec));
1750 return group.release();
1753 // Compare instruction for the contraction compute case.
1754 // Returns true if the output is what is expected from the test case.
1755 bool compareNoContractCase(const std::vector<Resource>&, const vector<AllocationSp>& outputAllocs, const std::vector<Resource>& expectedOutputs, TestLog&)
1757 if (outputAllocs.size() != 1)
1760 // Only size is needed because we are not comparing the exact values.
1761 size_t byteSize = expectedOutputs[0].getByteSize();
1763 const float* outputAsFloat = static_cast<const float*>(outputAllocs[0]->getHostPtr());
1765 for(size_t i = 0; i < byteSize / sizeof(float); ++i) {
1766 if (outputAsFloat[i] != 0.f &&
1767 outputAsFloat[i] != -ldexp(1, -24)) {
1775 tcu::TestCaseGroup* createNoContractionGroup (tcu::TestContext& testCtx)
1777 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "nocontraction", "Test the NoContraction decoration"));
1778 vector<CaseParameter> cases;
1779 const int numElements = 100;
1780 vector<float> inputFloats1 (numElements, 0);
1781 vector<float> inputFloats2 (numElements, 0);
1782 vector<float> outputFloats (numElements, 0);
1783 const StringTemplate shaderTemplate (
1784 string(getComputeAsmShaderPreamble()) +
1786 "OpName %main \"main\"\n"
1787 "OpName %id \"gl_GlobalInvocationID\"\n"
1789 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1793 "OpDecorate %buf BufferBlock\n"
1794 "OpDecorate %indata1 DescriptorSet 0\n"
1795 "OpDecorate %indata1 Binding 0\n"
1796 "OpDecorate %indata2 DescriptorSet 0\n"
1797 "OpDecorate %indata2 Binding 1\n"
1798 "OpDecorate %outdata DescriptorSet 0\n"
1799 "OpDecorate %outdata Binding 2\n"
1800 "OpDecorate %f32arr ArrayStride 4\n"
1801 "OpMemberDecorate %buf 0 Offset 0\n"
1803 + string(getComputeAsmCommonTypes()) +
1805 "%buf = OpTypeStruct %f32arr\n"
1806 "%bufptr = OpTypePointer Uniform %buf\n"
1807 "%indata1 = OpVariable %bufptr Uniform\n"
1808 "%indata2 = OpVariable %bufptr Uniform\n"
1809 "%outdata = OpVariable %bufptr Uniform\n"
1811 "%id = OpVariable %uvec3ptr Input\n"
1812 "%zero = OpConstant %i32 0\n"
1813 "%c_f_m1 = OpConstant %f32 -1.\n"
1815 "%main = OpFunction %void None %voidf\n"
1816 "%label = OpLabel\n"
1817 "%idval = OpLoad %uvec3 %id\n"
1818 "%x = OpCompositeExtract %u32 %idval 0\n"
1819 "%inloc1 = OpAccessChain %f32ptr %indata1 %zero %x\n"
1820 "%inval1 = OpLoad %f32 %inloc1\n"
1821 "%inloc2 = OpAccessChain %f32ptr %indata2 %zero %x\n"
1822 "%inval2 = OpLoad %f32 %inloc2\n"
1823 "%mul = OpFMul %f32 %inval1 %inval2\n"
1824 "%add = OpFAdd %f32 %mul %c_f_m1\n"
1825 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
1826 " OpStore %outloc %add\n"
1828 " OpFunctionEnd\n");
1830 cases.push_back(CaseParameter("multiplication", "OpDecorate %mul NoContraction"));
1831 cases.push_back(CaseParameter("addition", "OpDecorate %add NoContraction"));
1832 cases.push_back(CaseParameter("both", "OpDecorate %mul NoContraction\nOpDecorate %add NoContraction"));
1834 for (size_t ndx = 0; ndx < numElements; ++ndx)
1836 inputFloats1[ndx] = 1.f + std::ldexp(1.f, -23); // 1 + 2^-23.
1837 inputFloats2[ndx] = 1.f - std::ldexp(1.f, -23); // 1 - 2^-23.
1838 // Result for (1 + 2^-23) * (1 - 2^-23) - 1. With NoContraction, the multiplication will be
1839 // conducted separately and the result is rounded to 1, or 0x1.fffffcp-1
1840 // So the final result will be 0.f or 0x1p-24.
1841 // If the operation is combined into a precise fused multiply-add, then the result would be
1842 // 2^-46 (0xa8800000).
1843 outputFloats[ndx] = 0.f;
1846 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
1848 map<string, string> specializations;
1849 ComputeShaderSpec spec;
1851 specializations["DECORATION"] = cases[caseNdx].param;
1852 spec.assembly = shaderTemplate.specialize(specializations);
1853 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats1)));
1854 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
1855 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
1856 spec.numWorkGroups = IVec3(numElements, 1, 1);
1857 // Check against the two possible answers based on rounding mode.
1858 spec.verifyIO = &compareNoContractCase;
1860 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
1862 return group.release();
1865 bool compareFRem(const std::vector<Resource>&, const vector<AllocationSp>& outputAllocs, const std::vector<Resource>& expectedOutputs, TestLog&)
1867 if (outputAllocs.size() != 1)
1870 vector<deUint8> expectedBytes;
1871 expectedOutputs[0].getBytes(expectedBytes);
1873 const float* expectedOutputAsFloat = reinterpret_cast<const float*>(&expectedBytes.front());
1874 const float* outputAsFloat = static_cast<const float*>(outputAllocs[0]->getHostPtr());
1876 for (size_t idx = 0; idx < expectedBytes.size() / sizeof(float); ++idx)
1878 const float f0 = expectedOutputAsFloat[idx];
1879 const float f1 = outputAsFloat[idx];
1880 // \todo relative error needs to be fairly high because FRem may be implemented as
1881 // (roughly) frac(a/b)*b, so LSB errors can be magnified. But this should be fine for now.
1882 if (deFloatAbs((f1 - f0) / f0) > 0.02)
1889 tcu::TestCaseGroup* createOpFRemGroup (tcu::TestContext& testCtx)
1891 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opfrem", "Test the OpFRem instruction"));
1892 ComputeShaderSpec spec;
1893 de::Random rnd (deStringHash(group->getName()));
1894 const int numElements = 200;
1895 vector<float> inputFloats1 (numElements, 0);
1896 vector<float> inputFloats2 (numElements, 0);
1897 vector<float> outputFloats (numElements, 0);
1899 fillRandomScalars(rnd, -10000.f, 10000.f, &inputFloats1[0], numElements);
1900 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats2[0], numElements);
1902 for (size_t ndx = 0; ndx < numElements; ++ndx)
1904 // Guard against divisors near zero.
1905 if (std::fabs(inputFloats2[ndx]) < 1e-3)
1906 inputFloats2[ndx] = 8.f;
1908 // The return value of std::fmod() has the same sign as its first operand, which is how OpFRem spec'd.
1909 outputFloats[ndx] = std::fmod(inputFloats1[ndx], inputFloats2[ndx]);
1913 string(getComputeAsmShaderPreamble()) +
1915 "OpName %main \"main\"\n"
1916 "OpName %id \"gl_GlobalInvocationID\"\n"
1918 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1920 "OpDecorate %buf BufferBlock\n"
1921 "OpDecorate %indata1 DescriptorSet 0\n"
1922 "OpDecorate %indata1 Binding 0\n"
1923 "OpDecorate %indata2 DescriptorSet 0\n"
1924 "OpDecorate %indata2 Binding 1\n"
1925 "OpDecorate %outdata DescriptorSet 0\n"
1926 "OpDecorate %outdata Binding 2\n"
1927 "OpDecorate %f32arr ArrayStride 4\n"
1928 "OpMemberDecorate %buf 0 Offset 0\n"
1930 + string(getComputeAsmCommonTypes()) +
1932 "%buf = OpTypeStruct %f32arr\n"
1933 "%bufptr = OpTypePointer Uniform %buf\n"
1934 "%indata1 = OpVariable %bufptr Uniform\n"
1935 "%indata2 = OpVariable %bufptr Uniform\n"
1936 "%outdata = OpVariable %bufptr Uniform\n"
1938 "%id = OpVariable %uvec3ptr Input\n"
1939 "%zero = OpConstant %i32 0\n"
1941 "%main = OpFunction %void None %voidf\n"
1942 "%label = OpLabel\n"
1943 "%idval = OpLoad %uvec3 %id\n"
1944 "%x = OpCompositeExtract %u32 %idval 0\n"
1945 "%inloc1 = OpAccessChain %f32ptr %indata1 %zero %x\n"
1946 "%inval1 = OpLoad %f32 %inloc1\n"
1947 "%inloc2 = OpAccessChain %f32ptr %indata2 %zero %x\n"
1948 "%inval2 = OpLoad %f32 %inloc2\n"
1949 "%rem = OpFRem %f32 %inval1 %inval2\n"
1950 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
1951 " OpStore %outloc %rem\n"
1955 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats1)));
1956 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
1957 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
1958 spec.numWorkGroups = IVec3(numElements, 1, 1);
1959 spec.verifyIO = &compareFRem;
1961 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "", spec));
1963 return group.release();
1966 bool compareNMin (const std::vector<Resource>&, const vector<AllocationSp>& outputAllocs, const std::vector<Resource>& expectedOutputs, TestLog&)
1968 if (outputAllocs.size() != 1)
1971 const BufferSp& expectedOutput (expectedOutputs[0].getBuffer());
1972 std::vector<deUint8> data;
1973 expectedOutput->getBytes(data);
1975 const float* const expectedOutputAsFloat = reinterpret_cast<const float*>(&data.front());
1976 const float* const outputAsFloat = static_cast<const float*>(outputAllocs[0]->getHostPtr());
1978 for (size_t idx = 0; idx < expectedOutput->getByteSize() / sizeof(float); ++idx)
1980 const float f0 = expectedOutputAsFloat[idx];
1981 const float f1 = outputAsFloat[idx];
1983 // For NMin, we accept NaN as output if both inputs were NaN.
1984 // Otherwise the NaN is the wrong choise, as on architectures that
1985 // do not handle NaN, those are huge values.
1986 if (!(tcu::Float32(f1).isNaN() && tcu::Float32(f0).isNaN()) && deFloatAbs(f1 - f0) > 0.00001f)
1993 tcu::TestCaseGroup* createOpNMinGroup (tcu::TestContext& testCtx)
1995 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opnmin", "Test the OpNMin instruction"));
1996 ComputeShaderSpec spec;
1997 de::Random rnd (deStringHash(group->getName()));
1998 const int numElements = 200;
1999 vector<float> inputFloats1 (numElements, 0);
2000 vector<float> inputFloats2 (numElements, 0);
2001 vector<float> outputFloats (numElements, 0);
2003 fillRandomScalars(rnd, -10000.f, 10000.f, &inputFloats1[0], numElements);
2004 fillRandomScalars(rnd, -10000.f, 10000.f, &inputFloats2[0], numElements);
2006 // Make the first case a full-NAN case.
2007 inputFloats1[0] = TCU_NAN;
2008 inputFloats2[0] = TCU_NAN;
2010 for (size_t ndx = 0; ndx < numElements; ++ndx)
2012 // By default, pick the smallest
2013 outputFloats[ndx] = std::min(inputFloats1[ndx], inputFloats2[ndx]);
2015 // Make half of the cases NaN cases
2018 // Alternate between the NaN operand
2021 outputFloats[ndx] = inputFloats2[ndx];
2022 inputFloats1[ndx] = TCU_NAN;
2026 outputFloats[ndx] = inputFloats1[ndx];
2027 inputFloats2[ndx] = TCU_NAN;
2033 "OpCapability Shader\n"
2034 "%std450 = OpExtInstImport \"GLSL.std.450\"\n"
2035 "OpMemoryModel Logical GLSL450\n"
2036 "OpEntryPoint GLCompute %main \"main\" %id\n"
2037 "OpExecutionMode %main LocalSize 1 1 1\n"
2039 "OpName %main \"main\"\n"
2040 "OpName %id \"gl_GlobalInvocationID\"\n"
2042 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2044 "OpDecorate %buf BufferBlock\n"
2045 "OpDecorate %indata1 DescriptorSet 0\n"
2046 "OpDecorate %indata1 Binding 0\n"
2047 "OpDecorate %indata2 DescriptorSet 0\n"
2048 "OpDecorate %indata2 Binding 1\n"
2049 "OpDecorate %outdata DescriptorSet 0\n"
2050 "OpDecorate %outdata Binding 2\n"
2051 "OpDecorate %f32arr ArrayStride 4\n"
2052 "OpMemberDecorate %buf 0 Offset 0\n"
2054 + string(getComputeAsmCommonTypes()) +
2056 "%buf = OpTypeStruct %f32arr\n"
2057 "%bufptr = OpTypePointer Uniform %buf\n"
2058 "%indata1 = OpVariable %bufptr Uniform\n"
2059 "%indata2 = OpVariable %bufptr Uniform\n"
2060 "%outdata = OpVariable %bufptr Uniform\n"
2062 "%id = OpVariable %uvec3ptr Input\n"
2063 "%zero = OpConstant %i32 0\n"
2065 "%main = OpFunction %void None %voidf\n"
2066 "%label = OpLabel\n"
2067 "%idval = OpLoad %uvec3 %id\n"
2068 "%x = OpCompositeExtract %u32 %idval 0\n"
2069 "%inloc1 = OpAccessChain %f32ptr %indata1 %zero %x\n"
2070 "%inval1 = OpLoad %f32 %inloc1\n"
2071 "%inloc2 = OpAccessChain %f32ptr %indata2 %zero %x\n"
2072 "%inval2 = OpLoad %f32 %inloc2\n"
2073 "%rem = OpExtInst %f32 %std450 NMin %inval1 %inval2\n"
2074 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2075 " OpStore %outloc %rem\n"
2079 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats1)));
2080 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
2081 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
2082 spec.numWorkGroups = IVec3(numElements, 1, 1);
2083 spec.verifyIO = &compareNMin;
2085 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "", spec));
2087 return group.release();
2090 bool compareNMax (const std::vector<Resource>&, const vector<AllocationSp>& outputAllocs, const std::vector<Resource>& expectedOutputs, TestLog&)
2092 if (outputAllocs.size() != 1)
2095 const BufferSp& expectedOutput = expectedOutputs[0].getBuffer();
2096 std::vector<deUint8> data;
2097 expectedOutput->getBytes(data);
2099 const float* const expectedOutputAsFloat = reinterpret_cast<const float*>(&data.front());
2100 const float* const outputAsFloat = static_cast<const float*>(outputAllocs[0]->getHostPtr());
2102 for (size_t idx = 0; idx < expectedOutput->getByteSize() / sizeof(float); ++idx)
2104 const float f0 = expectedOutputAsFloat[idx];
2105 const float f1 = outputAsFloat[idx];
2107 // For NMax, NaN is considered acceptable result, since in
2108 // architectures that do not handle NaNs, those are huge values.
2109 if (!tcu::Float32(f1).isNaN() && deFloatAbs(f1 - f0) > 0.00001f)
2116 tcu::TestCaseGroup* createOpNMaxGroup (tcu::TestContext& testCtx)
2118 de::MovePtr<tcu::TestCaseGroup> group(new tcu::TestCaseGroup(testCtx, "opnmax", "Test the OpNMax instruction"));
2119 ComputeShaderSpec spec;
2120 de::Random rnd (deStringHash(group->getName()));
2121 const int numElements = 200;
2122 vector<float> inputFloats1 (numElements, 0);
2123 vector<float> inputFloats2 (numElements, 0);
2124 vector<float> outputFloats (numElements, 0);
2126 fillRandomScalars(rnd, -10000.f, 10000.f, &inputFloats1[0], numElements);
2127 fillRandomScalars(rnd, -10000.f, 10000.f, &inputFloats2[0], numElements);
2129 // Make the first case a full-NAN case.
2130 inputFloats1[0] = TCU_NAN;
2131 inputFloats2[0] = TCU_NAN;
2133 for (size_t ndx = 0; ndx < numElements; ++ndx)
2135 // By default, pick the biggest
2136 outputFloats[ndx] = std::max(inputFloats1[ndx], inputFloats2[ndx]);
2138 // Make half of the cases NaN cases
2141 // Alternate between the NaN operand
2144 outputFloats[ndx] = inputFloats2[ndx];
2145 inputFloats1[ndx] = TCU_NAN;
2149 outputFloats[ndx] = inputFloats1[ndx];
2150 inputFloats2[ndx] = TCU_NAN;
2156 "OpCapability Shader\n"
2157 "%std450 = OpExtInstImport \"GLSL.std.450\"\n"
2158 "OpMemoryModel Logical GLSL450\n"
2159 "OpEntryPoint GLCompute %main \"main\" %id\n"
2160 "OpExecutionMode %main LocalSize 1 1 1\n"
2162 "OpName %main \"main\"\n"
2163 "OpName %id \"gl_GlobalInvocationID\"\n"
2165 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2167 "OpDecorate %buf BufferBlock\n"
2168 "OpDecorate %indata1 DescriptorSet 0\n"
2169 "OpDecorate %indata1 Binding 0\n"
2170 "OpDecorate %indata2 DescriptorSet 0\n"
2171 "OpDecorate %indata2 Binding 1\n"
2172 "OpDecorate %outdata DescriptorSet 0\n"
2173 "OpDecorate %outdata Binding 2\n"
2174 "OpDecorate %f32arr ArrayStride 4\n"
2175 "OpMemberDecorate %buf 0 Offset 0\n"
2177 + string(getComputeAsmCommonTypes()) +
2179 "%buf = OpTypeStruct %f32arr\n"
2180 "%bufptr = OpTypePointer Uniform %buf\n"
2181 "%indata1 = OpVariable %bufptr Uniform\n"
2182 "%indata2 = OpVariable %bufptr Uniform\n"
2183 "%outdata = OpVariable %bufptr Uniform\n"
2185 "%id = OpVariable %uvec3ptr Input\n"
2186 "%zero = OpConstant %i32 0\n"
2188 "%main = OpFunction %void None %voidf\n"
2189 "%label = OpLabel\n"
2190 "%idval = OpLoad %uvec3 %id\n"
2191 "%x = OpCompositeExtract %u32 %idval 0\n"
2192 "%inloc1 = OpAccessChain %f32ptr %indata1 %zero %x\n"
2193 "%inval1 = OpLoad %f32 %inloc1\n"
2194 "%inloc2 = OpAccessChain %f32ptr %indata2 %zero %x\n"
2195 "%inval2 = OpLoad %f32 %inloc2\n"
2196 "%rem = OpExtInst %f32 %std450 NMax %inval1 %inval2\n"
2197 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2198 " OpStore %outloc %rem\n"
2202 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats1)));
2203 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
2204 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
2205 spec.numWorkGroups = IVec3(numElements, 1, 1);
2206 spec.verifyIO = &compareNMax;
2208 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "", spec));
2210 return group.release();
2213 bool compareNClamp (const std::vector<Resource>&, const vector<AllocationSp>& outputAllocs, const std::vector<Resource>& expectedOutputs, TestLog&)
2215 if (outputAllocs.size() != 1)
2218 const BufferSp& expectedOutput = expectedOutputs[0].getBuffer();
2219 std::vector<deUint8> data;
2220 expectedOutput->getBytes(data);
2222 const float* const expectedOutputAsFloat = reinterpret_cast<const float*>(&data.front());
2223 const float* const outputAsFloat = static_cast<const float*>(outputAllocs[0]->getHostPtr());
2225 for (size_t idx = 0; idx < expectedOutput->getByteSize() / sizeof(float) / 2; ++idx)
2227 const float e0 = expectedOutputAsFloat[idx * 2];
2228 const float e1 = expectedOutputAsFloat[idx * 2 + 1];
2229 const float res = outputAsFloat[idx];
2231 // For NClamp, we have two possible outcomes based on
2232 // whether NaNs are handled or not.
2233 // If either min or max value is NaN, the result is undefined,
2234 // so this test doesn't stress those. If the clamped value is
2235 // NaN, and NaNs are handled, the result is min; if NaNs are not
2236 // handled, they are big values that result in max.
2237 // If all three parameters are NaN, the result should be NaN.
2238 if (!((tcu::Float32(e0).isNaN() && tcu::Float32(res).isNaN()) ||
2239 (deFloatAbs(e0 - res) < 0.00001f) ||
2240 (deFloatAbs(e1 - res) < 0.00001f)))
2247 tcu::TestCaseGroup* createOpNClampGroup (tcu::TestContext& testCtx)
2249 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opnclamp", "Test the OpNClamp instruction"));
2250 ComputeShaderSpec spec;
2251 de::Random rnd (deStringHash(group->getName()));
2252 const int numElements = 200;
2253 vector<float> inputFloats1 (numElements, 0);
2254 vector<float> inputFloats2 (numElements, 0);
2255 vector<float> inputFloats3 (numElements, 0);
2256 vector<float> outputFloats (numElements * 2, 0);
2258 fillRandomScalars(rnd, -10000.f, 10000.f, &inputFloats1[0], numElements);
2259 fillRandomScalars(rnd, -10000.f, 10000.f, &inputFloats2[0], numElements);
2260 fillRandomScalars(rnd, -10000.f, 10000.f, &inputFloats3[0], numElements);
2262 for (size_t ndx = 0; ndx < numElements; ++ndx)
2264 // Results are only defined if max value is bigger than min value.
2265 if (inputFloats2[ndx] > inputFloats3[ndx])
2267 float t = inputFloats2[ndx];
2268 inputFloats2[ndx] = inputFloats3[ndx];
2269 inputFloats3[ndx] = t;
2272 // By default, do the clamp, setting both possible answers
2273 float defaultRes = std::min(std::max(inputFloats1[ndx], inputFloats2[ndx]), inputFloats3[ndx]);
2275 float maxResA = std::max(inputFloats1[ndx], inputFloats2[ndx]);
2276 float maxResB = maxResA;
2278 // Alternate between the NaN cases
2281 inputFloats1[ndx] = TCU_NAN;
2282 // If NaN is handled, the result should be same as the clamp minimum.
2283 // If NaN is not handled, the result should clamp to the clamp maximum.
2284 maxResA = inputFloats2[ndx];
2285 maxResB = inputFloats3[ndx];
2289 // Not a NaN case - only one legal result.
2290 maxResA = defaultRes;
2291 maxResB = defaultRes;
2294 outputFloats[ndx * 2] = maxResA;
2295 outputFloats[ndx * 2 + 1] = maxResB;
2298 // Make the first case a full-NAN case.
2299 inputFloats1[0] = TCU_NAN;
2300 inputFloats2[0] = TCU_NAN;
2301 inputFloats3[0] = TCU_NAN;
2302 outputFloats[0] = TCU_NAN;
2303 outputFloats[1] = TCU_NAN;
2306 "OpCapability Shader\n"
2307 "%std450 = OpExtInstImport \"GLSL.std.450\"\n"
2308 "OpMemoryModel Logical GLSL450\n"
2309 "OpEntryPoint GLCompute %main \"main\" %id\n"
2310 "OpExecutionMode %main LocalSize 1 1 1\n"
2312 "OpName %main \"main\"\n"
2313 "OpName %id \"gl_GlobalInvocationID\"\n"
2315 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2317 "OpDecorate %buf BufferBlock\n"
2318 "OpDecorate %indata1 DescriptorSet 0\n"
2319 "OpDecorate %indata1 Binding 0\n"
2320 "OpDecorate %indata2 DescriptorSet 0\n"
2321 "OpDecorate %indata2 Binding 1\n"
2322 "OpDecorate %indata3 DescriptorSet 0\n"
2323 "OpDecorate %indata3 Binding 2\n"
2324 "OpDecorate %outdata DescriptorSet 0\n"
2325 "OpDecorate %outdata Binding 3\n"
2326 "OpDecorate %f32arr ArrayStride 4\n"
2327 "OpMemberDecorate %buf 0 Offset 0\n"
2329 + string(getComputeAsmCommonTypes()) +
2331 "%buf = OpTypeStruct %f32arr\n"
2332 "%bufptr = OpTypePointer Uniform %buf\n"
2333 "%indata1 = OpVariable %bufptr Uniform\n"
2334 "%indata2 = OpVariable %bufptr Uniform\n"
2335 "%indata3 = OpVariable %bufptr Uniform\n"
2336 "%outdata = OpVariable %bufptr Uniform\n"
2338 "%id = OpVariable %uvec3ptr Input\n"
2339 "%zero = OpConstant %i32 0\n"
2341 "%main = OpFunction %void None %voidf\n"
2342 "%label = OpLabel\n"
2343 "%idval = OpLoad %uvec3 %id\n"
2344 "%x = OpCompositeExtract %u32 %idval 0\n"
2345 "%inloc1 = OpAccessChain %f32ptr %indata1 %zero %x\n"
2346 "%inval1 = OpLoad %f32 %inloc1\n"
2347 "%inloc2 = OpAccessChain %f32ptr %indata2 %zero %x\n"
2348 "%inval2 = OpLoad %f32 %inloc2\n"
2349 "%inloc3 = OpAccessChain %f32ptr %indata3 %zero %x\n"
2350 "%inval3 = OpLoad %f32 %inloc3\n"
2351 "%rem = OpExtInst %f32 %std450 NClamp %inval1 %inval2 %inval3\n"
2352 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2353 " OpStore %outloc %rem\n"
2357 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats1)));
2358 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
2359 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats3)));
2360 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
2361 spec.numWorkGroups = IVec3(numElements, 1, 1);
2362 spec.verifyIO = &compareNClamp;
2364 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "", spec));
2366 return group.release();
2369 tcu::TestCaseGroup* createOpSRemComputeGroup (tcu::TestContext& testCtx, qpTestResult negFailResult)
2371 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opsrem", "Test the OpSRem instruction"));
2372 de::Random rnd (deStringHash(group->getName()));
2373 const int numElements = 200;
2375 const struct CaseParams
2378 const char* failMessage; // customized status message
2379 qpTestResult failResult; // override status on failure
2380 int op1Min, op1Max; // operand ranges
2384 { "positive", "Output doesn't match with expected", QP_TEST_RESULT_FAIL, 0, 65536, 0, 100 },
2385 { "all", "Inconsistent results, but within specification", negFailResult, -65536, 65536, -100, 100 }, // see below
2387 // If either operand is negative the result is undefined. Some implementations may still return correct values.
2389 for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(cases); ++caseNdx)
2391 const CaseParams& params = cases[caseNdx];
2392 ComputeShaderSpec spec;
2393 vector<deInt32> inputInts1 (numElements, 0);
2394 vector<deInt32> inputInts2 (numElements, 0);
2395 vector<deInt32> outputInts (numElements, 0);
2397 fillRandomScalars(rnd, params.op1Min, params.op1Max, &inputInts1[0], numElements);
2398 fillRandomScalars(rnd, params.op2Min, params.op2Max, &inputInts2[0], numElements, filterNotZero);
2400 for (int ndx = 0; ndx < numElements; ++ndx)
2402 // The return value of std::fmod() has the same sign as its first operand, which is how OpFRem spec'd.
2403 outputInts[ndx] = inputInts1[ndx] % inputInts2[ndx];
2407 string(getComputeAsmShaderPreamble()) +
2409 "OpName %main \"main\"\n"
2410 "OpName %id \"gl_GlobalInvocationID\"\n"
2412 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2414 "OpDecorate %buf BufferBlock\n"
2415 "OpDecorate %indata1 DescriptorSet 0\n"
2416 "OpDecorate %indata1 Binding 0\n"
2417 "OpDecorate %indata2 DescriptorSet 0\n"
2418 "OpDecorate %indata2 Binding 1\n"
2419 "OpDecorate %outdata DescriptorSet 0\n"
2420 "OpDecorate %outdata Binding 2\n"
2421 "OpDecorate %i32arr ArrayStride 4\n"
2422 "OpMemberDecorate %buf 0 Offset 0\n"
2424 + string(getComputeAsmCommonTypes()) +
2426 "%buf = OpTypeStruct %i32arr\n"
2427 "%bufptr = OpTypePointer Uniform %buf\n"
2428 "%indata1 = OpVariable %bufptr Uniform\n"
2429 "%indata2 = OpVariable %bufptr Uniform\n"
2430 "%outdata = OpVariable %bufptr Uniform\n"
2432 "%id = OpVariable %uvec3ptr Input\n"
2433 "%zero = OpConstant %i32 0\n"
2435 "%main = OpFunction %void None %voidf\n"
2436 "%label = OpLabel\n"
2437 "%idval = OpLoad %uvec3 %id\n"
2438 "%x = OpCompositeExtract %u32 %idval 0\n"
2439 "%inloc1 = OpAccessChain %i32ptr %indata1 %zero %x\n"
2440 "%inval1 = OpLoad %i32 %inloc1\n"
2441 "%inloc2 = OpAccessChain %i32ptr %indata2 %zero %x\n"
2442 "%inval2 = OpLoad %i32 %inloc2\n"
2443 "%rem = OpSRem %i32 %inval1 %inval2\n"
2444 "%outloc = OpAccessChain %i32ptr %outdata %zero %x\n"
2445 " OpStore %outloc %rem\n"
2449 spec.inputs.push_back (BufferSp(new Int32Buffer(inputInts1)));
2450 spec.inputs.push_back (BufferSp(new Int32Buffer(inputInts2)));
2451 spec.outputs.push_back (BufferSp(new Int32Buffer(outputInts)));
2452 spec.numWorkGroups = IVec3(numElements, 1, 1);
2453 spec.failResult = params.failResult;
2454 spec.failMessage = params.failMessage;
2456 group->addChild(new SpvAsmComputeShaderCase(testCtx, params.name, "", spec));
2459 return group.release();
2462 tcu::TestCaseGroup* createOpSRemComputeGroup64 (tcu::TestContext& testCtx, qpTestResult negFailResult)
2464 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opsrem64", "Test the 64-bit OpSRem instruction"));
2465 de::Random rnd (deStringHash(group->getName()));
2466 const int numElements = 200;
2468 const struct CaseParams
2471 const char* failMessage; // customized status message
2472 qpTestResult failResult; // override status on failure
2476 { "positive", "Output doesn't match with expected", QP_TEST_RESULT_FAIL, true },
2477 { "all", "Inconsistent results, but within specification", negFailResult, false }, // see below
2479 // If either operand is negative the result is undefined. Some implementations may still return correct values.
2481 for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(cases); ++caseNdx)
2483 const CaseParams& params = cases[caseNdx];
2484 ComputeShaderSpec spec;
2485 vector<deInt64> inputInts1 (numElements, 0);
2486 vector<deInt64> inputInts2 (numElements, 0);
2487 vector<deInt64> outputInts (numElements, 0);
2489 if (params.positive)
2491 fillRandomInt64sLogDistributed(rnd, inputInts1, numElements, filterNonNegative);
2492 fillRandomInt64sLogDistributed(rnd, inputInts2, numElements, filterPositive);
2496 fillRandomInt64sLogDistributed(rnd, inputInts1, numElements);
2497 fillRandomInt64sLogDistributed(rnd, inputInts2, numElements, filterNotZero);
2500 for (int ndx = 0; ndx < numElements; ++ndx)
2502 // The return value of std::fmod() has the same sign as its first operand, which is how OpFRem spec'd.
2503 outputInts[ndx] = inputInts1[ndx] % inputInts2[ndx];
2507 "OpCapability Int64\n"
2509 + string(getComputeAsmShaderPreamble()) +
2511 "OpName %main \"main\"\n"
2512 "OpName %id \"gl_GlobalInvocationID\"\n"
2514 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2516 "OpDecorate %buf BufferBlock\n"
2517 "OpDecorate %indata1 DescriptorSet 0\n"
2518 "OpDecorate %indata1 Binding 0\n"
2519 "OpDecorate %indata2 DescriptorSet 0\n"
2520 "OpDecorate %indata2 Binding 1\n"
2521 "OpDecorate %outdata DescriptorSet 0\n"
2522 "OpDecorate %outdata Binding 2\n"
2523 "OpDecorate %i64arr ArrayStride 8\n"
2524 "OpMemberDecorate %buf 0 Offset 0\n"
2526 + string(getComputeAsmCommonTypes())
2527 + string(getComputeAsmCommonInt64Types()) +
2529 "%buf = OpTypeStruct %i64arr\n"
2530 "%bufptr = OpTypePointer Uniform %buf\n"
2531 "%indata1 = OpVariable %bufptr Uniform\n"
2532 "%indata2 = OpVariable %bufptr Uniform\n"
2533 "%outdata = OpVariable %bufptr Uniform\n"
2535 "%id = OpVariable %uvec3ptr Input\n"
2536 "%zero = OpConstant %i64 0\n"
2538 "%main = OpFunction %void None %voidf\n"
2539 "%label = OpLabel\n"
2540 "%idval = OpLoad %uvec3 %id\n"
2541 "%x = OpCompositeExtract %u32 %idval 0\n"
2542 "%inloc1 = OpAccessChain %i64ptr %indata1 %zero %x\n"
2543 "%inval1 = OpLoad %i64 %inloc1\n"
2544 "%inloc2 = OpAccessChain %i64ptr %indata2 %zero %x\n"
2545 "%inval2 = OpLoad %i64 %inloc2\n"
2546 "%rem = OpSRem %i64 %inval1 %inval2\n"
2547 "%outloc = OpAccessChain %i64ptr %outdata %zero %x\n"
2548 " OpStore %outloc %rem\n"
2552 spec.inputs.push_back (BufferSp(new Int64Buffer(inputInts1)));
2553 spec.inputs.push_back (BufferSp(new Int64Buffer(inputInts2)));
2554 spec.outputs.push_back (BufferSp(new Int64Buffer(outputInts)));
2555 spec.numWorkGroups = IVec3(numElements, 1, 1);
2556 spec.failResult = params.failResult;
2557 spec.failMessage = params.failMessage;
2559 spec.requestedVulkanFeatures.coreFeatures.shaderInt64 = VK_TRUE;
2561 group->addChild(new SpvAsmComputeShaderCase(testCtx, params.name, "", spec));
2564 return group.release();
2567 tcu::TestCaseGroup* createOpSModComputeGroup (tcu::TestContext& testCtx, qpTestResult negFailResult)
2569 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opsmod", "Test the OpSMod instruction"));
2570 de::Random rnd (deStringHash(group->getName()));
2571 const int numElements = 200;
2573 const struct CaseParams
2576 const char* failMessage; // customized status message
2577 qpTestResult failResult; // override status on failure
2578 int op1Min, op1Max; // operand ranges
2582 { "positive", "Output doesn't match with expected", QP_TEST_RESULT_FAIL, 0, 65536, 0, 100 },
2583 { "all", "Inconsistent results, but within specification", negFailResult, -65536, 65536, -100, 100 }, // see below
2585 // If either operand is negative the result is undefined. Some implementations may still return correct values.
2587 for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(cases); ++caseNdx)
2589 const CaseParams& params = cases[caseNdx];
2591 ComputeShaderSpec spec;
2592 vector<deInt32> inputInts1 (numElements, 0);
2593 vector<deInt32> inputInts2 (numElements, 0);
2594 vector<deInt32> outputInts (numElements, 0);
2596 fillRandomScalars(rnd, params.op1Min, params.op1Max, &inputInts1[0], numElements);
2597 fillRandomScalars(rnd, params.op2Min, params.op2Max, &inputInts2[0], numElements, filterNotZero);
2599 for (int ndx = 0; ndx < numElements; ++ndx)
2601 deInt32 rem = inputInts1[ndx] % inputInts2[ndx];
2604 outputInts[ndx] = 0;
2606 else if ((inputInts1[ndx] >= 0) == (inputInts2[ndx] >= 0))
2608 // They have the same sign
2609 outputInts[ndx] = rem;
2613 // They have opposite sign. The remainder operation takes the
2614 // sign inputInts1[ndx] but OpSMod is supposed to take ths sign
2615 // of inputInts2[ndx]. Adding inputInts2[ndx] will ensure that
2616 // the result has the correct sign and that it is still
2617 // congruent to inputInts1[ndx] modulo inputInts2[ndx]
2619 // See also http://mathforum.org/library/drmath/view/52343.html
2620 outputInts[ndx] = rem + inputInts2[ndx];
2625 string(getComputeAsmShaderPreamble()) +
2627 "OpName %main \"main\"\n"
2628 "OpName %id \"gl_GlobalInvocationID\"\n"
2630 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2632 "OpDecorate %buf BufferBlock\n"
2633 "OpDecorate %indata1 DescriptorSet 0\n"
2634 "OpDecorate %indata1 Binding 0\n"
2635 "OpDecorate %indata2 DescriptorSet 0\n"
2636 "OpDecorate %indata2 Binding 1\n"
2637 "OpDecorate %outdata DescriptorSet 0\n"
2638 "OpDecorate %outdata Binding 2\n"
2639 "OpDecorate %i32arr ArrayStride 4\n"
2640 "OpMemberDecorate %buf 0 Offset 0\n"
2642 + string(getComputeAsmCommonTypes()) +
2644 "%buf = OpTypeStruct %i32arr\n"
2645 "%bufptr = OpTypePointer Uniform %buf\n"
2646 "%indata1 = OpVariable %bufptr Uniform\n"
2647 "%indata2 = OpVariable %bufptr Uniform\n"
2648 "%outdata = OpVariable %bufptr Uniform\n"
2650 "%id = OpVariable %uvec3ptr Input\n"
2651 "%zero = OpConstant %i32 0\n"
2653 "%main = OpFunction %void None %voidf\n"
2654 "%label = OpLabel\n"
2655 "%idval = OpLoad %uvec3 %id\n"
2656 "%x = OpCompositeExtract %u32 %idval 0\n"
2657 "%inloc1 = OpAccessChain %i32ptr %indata1 %zero %x\n"
2658 "%inval1 = OpLoad %i32 %inloc1\n"
2659 "%inloc2 = OpAccessChain %i32ptr %indata2 %zero %x\n"
2660 "%inval2 = OpLoad %i32 %inloc2\n"
2661 "%rem = OpSMod %i32 %inval1 %inval2\n"
2662 "%outloc = OpAccessChain %i32ptr %outdata %zero %x\n"
2663 " OpStore %outloc %rem\n"
2667 spec.inputs.push_back (BufferSp(new Int32Buffer(inputInts1)));
2668 spec.inputs.push_back (BufferSp(new Int32Buffer(inputInts2)));
2669 spec.outputs.push_back (BufferSp(new Int32Buffer(outputInts)));
2670 spec.numWorkGroups = IVec3(numElements, 1, 1);
2671 spec.failResult = params.failResult;
2672 spec.failMessage = params.failMessage;
2674 group->addChild(new SpvAsmComputeShaderCase(testCtx, params.name, "", spec));
2677 return group.release();
2680 tcu::TestCaseGroup* createOpSModComputeGroup64 (tcu::TestContext& testCtx, qpTestResult negFailResult)
2682 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opsmod64", "Test the OpSMod instruction"));
2683 de::Random rnd (deStringHash(group->getName()));
2684 const int numElements = 200;
2686 const struct CaseParams
2689 const char* failMessage; // customized status message
2690 qpTestResult failResult; // override status on failure
2694 { "positive", "Output doesn't match with expected", QP_TEST_RESULT_FAIL, true },
2695 { "all", "Inconsistent results, but within specification", negFailResult, false }, // see below
2697 // If either operand is negative the result is undefined. Some implementations may still return correct values.
2699 for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(cases); ++caseNdx)
2701 const CaseParams& params = cases[caseNdx];
2703 ComputeShaderSpec spec;
2704 vector<deInt64> inputInts1 (numElements, 0);
2705 vector<deInt64> inputInts2 (numElements, 0);
2706 vector<deInt64> outputInts (numElements, 0);
2709 if (params.positive)
2711 fillRandomInt64sLogDistributed(rnd, inputInts1, numElements, filterNonNegative);
2712 fillRandomInt64sLogDistributed(rnd, inputInts2, numElements, filterPositive);
2716 fillRandomInt64sLogDistributed(rnd, inputInts1, numElements);
2717 fillRandomInt64sLogDistributed(rnd, inputInts2, numElements, filterNotZero);
2720 for (int ndx = 0; ndx < numElements; ++ndx)
2722 deInt64 rem = inputInts1[ndx] % inputInts2[ndx];
2725 outputInts[ndx] = 0;
2727 else if ((inputInts1[ndx] >= 0) == (inputInts2[ndx] >= 0))
2729 // They have the same sign
2730 outputInts[ndx] = rem;
2734 // They have opposite sign. The remainder operation takes the
2735 // sign inputInts1[ndx] but OpSMod is supposed to take ths sign
2736 // of inputInts2[ndx]. Adding inputInts2[ndx] will ensure that
2737 // the result has the correct sign and that it is still
2738 // congruent to inputInts1[ndx] modulo inputInts2[ndx]
2740 // See also http://mathforum.org/library/drmath/view/52343.html
2741 outputInts[ndx] = rem + inputInts2[ndx];
2746 "OpCapability Int64\n"
2748 + string(getComputeAsmShaderPreamble()) +
2750 "OpName %main \"main\"\n"
2751 "OpName %id \"gl_GlobalInvocationID\"\n"
2753 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2755 "OpDecorate %buf BufferBlock\n"
2756 "OpDecorate %indata1 DescriptorSet 0\n"
2757 "OpDecorate %indata1 Binding 0\n"
2758 "OpDecorate %indata2 DescriptorSet 0\n"
2759 "OpDecorate %indata2 Binding 1\n"
2760 "OpDecorate %outdata DescriptorSet 0\n"
2761 "OpDecorate %outdata Binding 2\n"
2762 "OpDecorate %i64arr ArrayStride 8\n"
2763 "OpMemberDecorate %buf 0 Offset 0\n"
2765 + string(getComputeAsmCommonTypes())
2766 + string(getComputeAsmCommonInt64Types()) +
2768 "%buf = OpTypeStruct %i64arr\n"
2769 "%bufptr = OpTypePointer Uniform %buf\n"
2770 "%indata1 = OpVariable %bufptr Uniform\n"
2771 "%indata2 = OpVariable %bufptr Uniform\n"
2772 "%outdata = OpVariable %bufptr Uniform\n"
2774 "%id = OpVariable %uvec3ptr Input\n"
2775 "%zero = OpConstant %i64 0\n"
2777 "%main = OpFunction %void None %voidf\n"
2778 "%label = OpLabel\n"
2779 "%idval = OpLoad %uvec3 %id\n"
2780 "%x = OpCompositeExtract %u32 %idval 0\n"
2781 "%inloc1 = OpAccessChain %i64ptr %indata1 %zero %x\n"
2782 "%inval1 = OpLoad %i64 %inloc1\n"
2783 "%inloc2 = OpAccessChain %i64ptr %indata2 %zero %x\n"
2784 "%inval2 = OpLoad %i64 %inloc2\n"
2785 "%rem = OpSMod %i64 %inval1 %inval2\n"
2786 "%outloc = OpAccessChain %i64ptr %outdata %zero %x\n"
2787 " OpStore %outloc %rem\n"
2791 spec.inputs.push_back (BufferSp(new Int64Buffer(inputInts1)));
2792 spec.inputs.push_back (BufferSp(new Int64Buffer(inputInts2)));
2793 spec.outputs.push_back (BufferSp(new Int64Buffer(outputInts)));
2794 spec.numWorkGroups = IVec3(numElements, 1, 1);
2795 spec.failResult = params.failResult;
2796 spec.failMessage = params.failMessage;
2798 spec.requestedVulkanFeatures.coreFeatures.shaderInt64 = VK_TRUE;
2800 group->addChild(new SpvAsmComputeShaderCase(testCtx, params.name, "", spec));
2803 return group.release();
2806 // Copy contents in the input buffer to the output buffer.
2807 tcu::TestCaseGroup* createOpCopyMemoryGroup (tcu::TestContext& testCtx)
2809 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opcopymemory", "Test the OpCopyMemory instruction"));
2810 de::Random rnd (deStringHash(group->getName()));
2811 const int numElements = 100;
2813 // The following case adds vec4(0., 0.5, 1.5, 2.5) to each of the elements in the input buffer and writes output to the output buffer.
2814 ComputeShaderSpec spec1;
2815 vector<Vec4> inputFloats1 (numElements);
2816 vector<Vec4> outputFloats1 (numElements);
2818 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats1[0], numElements * 4);
2820 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
2821 floorAll(inputFloats1);
2823 for (size_t ndx = 0; ndx < numElements; ++ndx)
2824 outputFloats1[ndx] = inputFloats1[ndx] + Vec4(0.f, 0.5f, 1.5f, 2.5f);
2827 string(getComputeAsmShaderPreamble()) +
2829 "OpName %main \"main\"\n"
2830 "OpName %id \"gl_GlobalInvocationID\"\n"
2832 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2833 "OpDecorate %vec4arr ArrayStride 16\n"
2835 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
2837 "%vec4 = OpTypeVector %f32 4\n"
2838 "%vec4ptr_u = OpTypePointer Uniform %vec4\n"
2839 "%vec4ptr_f = OpTypePointer Function %vec4\n"
2840 "%vec4arr = OpTypeRuntimeArray %vec4\n"
2841 "%buf = OpTypeStruct %vec4arr\n"
2842 "%bufptr = OpTypePointer Uniform %buf\n"
2843 "%indata = OpVariable %bufptr Uniform\n"
2844 "%outdata = OpVariable %bufptr Uniform\n"
2846 "%id = OpVariable %uvec3ptr Input\n"
2847 "%zero = OpConstant %i32 0\n"
2848 "%c_f_0 = OpConstant %f32 0.\n"
2849 "%c_f_0_5 = OpConstant %f32 0.5\n"
2850 "%c_f_1_5 = OpConstant %f32 1.5\n"
2851 "%c_f_2_5 = OpConstant %f32 2.5\n"
2852 "%c_vec4 = OpConstantComposite %vec4 %c_f_0 %c_f_0_5 %c_f_1_5 %c_f_2_5\n"
2854 "%main = OpFunction %void None %voidf\n"
2855 "%label = OpLabel\n"
2856 "%v_vec4 = OpVariable %vec4ptr_f Function\n"
2857 "%idval = OpLoad %uvec3 %id\n"
2858 "%x = OpCompositeExtract %u32 %idval 0\n"
2859 "%inloc = OpAccessChain %vec4ptr_u %indata %zero %x\n"
2860 "%outloc = OpAccessChain %vec4ptr_u %outdata %zero %x\n"
2861 " OpCopyMemory %v_vec4 %inloc\n"
2862 "%v_vec4_val = OpLoad %vec4 %v_vec4\n"
2863 "%add = OpFAdd %vec4 %v_vec4_val %c_vec4\n"
2864 " OpStore %outloc %add\n"
2868 spec1.inputs.push_back(BufferSp(new Vec4Buffer(inputFloats1)));
2869 spec1.outputs.push_back(BufferSp(new Vec4Buffer(outputFloats1)));
2870 spec1.numWorkGroups = IVec3(numElements, 1, 1);
2872 group->addChild(new SpvAsmComputeShaderCase(testCtx, "vector", "OpCopyMemory elements of vector type", spec1));
2874 // The following case copies a float[100] variable from the input buffer to the output buffer.
2875 ComputeShaderSpec spec2;
2876 vector<float> inputFloats2 (numElements);
2877 vector<float> outputFloats2 (numElements);
2879 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats2[0], numElements);
2881 for (size_t ndx = 0; ndx < numElements; ++ndx)
2882 outputFloats2[ndx] = inputFloats2[ndx];
2885 string(getComputeAsmShaderPreamble()) +
2887 "OpName %main \"main\"\n"
2888 "OpName %id \"gl_GlobalInvocationID\"\n"
2890 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2891 "OpDecorate %f32arr100 ArrayStride 4\n"
2893 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
2895 "%hundred = OpConstant %u32 100\n"
2896 "%f32arr100 = OpTypeArray %f32 %hundred\n"
2897 "%f32arr100ptr_f = OpTypePointer Function %f32arr100\n"
2898 "%f32arr100ptr_u = OpTypePointer Uniform %f32arr100\n"
2899 "%buf = OpTypeStruct %f32arr100\n"
2900 "%bufptr = OpTypePointer Uniform %buf\n"
2901 "%indata = OpVariable %bufptr Uniform\n"
2902 "%outdata = OpVariable %bufptr Uniform\n"
2904 "%id = OpVariable %uvec3ptr Input\n"
2905 "%zero = OpConstant %i32 0\n"
2907 "%main = OpFunction %void None %voidf\n"
2908 "%label = OpLabel\n"
2909 "%var = OpVariable %f32arr100ptr_f Function\n"
2910 "%inarr = OpAccessChain %f32arr100ptr_u %indata %zero\n"
2911 "%outarr = OpAccessChain %f32arr100ptr_u %outdata %zero\n"
2912 " OpCopyMemory %var %inarr\n"
2913 " OpCopyMemory %outarr %var\n"
2917 spec2.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
2918 spec2.outputs.push_back(BufferSp(new Float32Buffer(outputFloats2)));
2919 spec2.numWorkGroups = IVec3(1, 1, 1);
2921 group->addChild(new SpvAsmComputeShaderCase(testCtx, "array", "OpCopyMemory elements of array type", spec2));
2923 // The following case copies a struct{vec4, vec4, vec4, vec4} variable from the input buffer to the output buffer.
2924 ComputeShaderSpec spec3;
2925 vector<float> inputFloats3 (16);
2926 vector<float> outputFloats3 (16);
2928 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats3[0], 16);
2930 for (size_t ndx = 0; ndx < 16; ++ndx)
2931 outputFloats3[ndx] = inputFloats3[ndx];
2934 string(getComputeAsmShaderPreamble()) +
2936 "OpName %main \"main\"\n"
2937 "OpName %id \"gl_GlobalInvocationID\"\n"
2939 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2940 //"OpMemberDecorate %buf 0 Offset 0\n" - exists in getComputeAsmInputOutputBufferTraits
2941 "OpMemberDecorate %buf 1 Offset 16\n"
2942 "OpMemberDecorate %buf 2 Offset 32\n"
2943 "OpMemberDecorate %buf 3 Offset 48\n"
2945 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
2947 "%vec4 = OpTypeVector %f32 4\n"
2948 "%buf = OpTypeStruct %vec4 %vec4 %vec4 %vec4\n"
2949 "%bufptr = OpTypePointer Uniform %buf\n"
2950 "%indata = OpVariable %bufptr Uniform\n"
2951 "%outdata = OpVariable %bufptr Uniform\n"
2952 "%vec4stptr = OpTypePointer Function %buf\n"
2954 "%id = OpVariable %uvec3ptr Input\n"
2955 "%zero = OpConstant %i32 0\n"
2957 "%main = OpFunction %void None %voidf\n"
2958 "%label = OpLabel\n"
2959 "%var = OpVariable %vec4stptr Function\n"
2960 " OpCopyMemory %var %indata\n"
2961 " OpCopyMemory %outdata %var\n"
2965 spec3.inputs.push_back(BufferSp(new Float32Buffer(inputFloats3)));
2966 spec3.outputs.push_back(BufferSp(new Float32Buffer(outputFloats3)));
2967 spec3.numWorkGroups = IVec3(1, 1, 1);
2969 group->addChild(new SpvAsmComputeShaderCase(testCtx, "struct", "OpCopyMemory elements of struct type", spec3));
2971 // The following case negates multiple float variables from the input buffer and stores the results to the output buffer.
2972 ComputeShaderSpec spec4;
2973 vector<float> inputFloats4 (numElements);
2974 vector<float> outputFloats4 (numElements);
2976 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats4[0], numElements);
2978 for (size_t ndx = 0; ndx < numElements; ++ndx)
2979 outputFloats4[ndx] = -inputFloats4[ndx];
2982 string(getComputeAsmShaderPreamble()) +
2984 "OpName %main \"main\"\n"
2985 "OpName %id \"gl_GlobalInvocationID\"\n"
2987 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2989 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
2991 "%f32ptr_f = OpTypePointer Function %f32\n"
2992 "%id = OpVariable %uvec3ptr Input\n"
2993 "%zero = OpConstant %i32 0\n"
2995 "%main = OpFunction %void None %voidf\n"
2996 "%label = OpLabel\n"
2997 "%var = OpVariable %f32ptr_f Function\n"
2998 "%idval = OpLoad %uvec3 %id\n"
2999 "%x = OpCompositeExtract %u32 %idval 0\n"
3000 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3001 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3002 " OpCopyMemory %var %inloc\n"
3003 "%val = OpLoad %f32 %var\n"
3004 "%neg = OpFNegate %f32 %val\n"
3005 " OpStore %outloc %neg\n"
3009 spec4.inputs.push_back(BufferSp(new Float32Buffer(inputFloats4)));
3010 spec4.outputs.push_back(BufferSp(new Float32Buffer(outputFloats4)));
3011 spec4.numWorkGroups = IVec3(numElements, 1, 1);
3013 group->addChild(new SpvAsmComputeShaderCase(testCtx, "float", "OpCopyMemory elements of float type", spec4));
3015 return group.release();
3018 tcu::TestCaseGroup* createOpCopyObjectGroup (tcu::TestContext& testCtx)
3020 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opcopyobject", "Test the OpCopyObject instruction"));
3021 ComputeShaderSpec spec;
3022 de::Random rnd (deStringHash(group->getName()));
3023 const int numElements = 100;
3024 vector<float> inputFloats (numElements, 0);
3025 vector<float> outputFloats (numElements, 0);
3027 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats[0], numElements);
3029 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
3030 floorAll(inputFloats);
3032 for (size_t ndx = 0; ndx < numElements; ++ndx)
3033 outputFloats[ndx] = inputFloats[ndx] + 7.5f;
3036 string(getComputeAsmShaderPreamble()) +
3038 "OpName %main \"main\"\n"
3039 "OpName %id \"gl_GlobalInvocationID\"\n"
3041 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3043 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
3045 "%fmat = OpTypeMatrix %fvec3 3\n"
3046 "%three = OpConstant %u32 3\n"
3047 "%farr = OpTypeArray %f32 %three\n"
3048 "%fst = OpTypeStruct %f32 %f32\n"
3050 + string(getComputeAsmInputOutputBuffer()) +
3052 "%id = OpVariable %uvec3ptr Input\n"
3053 "%zero = OpConstant %i32 0\n"
3054 "%c_f = OpConstant %f32 1.5\n"
3055 "%c_fvec3 = OpConstantComposite %fvec3 %c_f %c_f %c_f\n"
3056 "%c_fmat = OpConstantComposite %fmat %c_fvec3 %c_fvec3 %c_fvec3\n"
3057 "%c_farr = OpConstantComposite %farr %c_f %c_f %c_f\n"
3058 "%c_fst = OpConstantComposite %fst %c_f %c_f\n"
3060 "%main = OpFunction %void None %voidf\n"
3061 "%label = OpLabel\n"
3062 "%c_f_copy = OpCopyObject %f32 %c_f\n"
3063 "%c_fvec3_copy = OpCopyObject %fvec3 %c_fvec3\n"
3064 "%c_fmat_copy = OpCopyObject %fmat %c_fmat\n"
3065 "%c_farr_copy = OpCopyObject %farr %c_farr\n"
3066 "%c_fst_copy = OpCopyObject %fst %c_fst\n"
3067 "%fvec3_elem = OpCompositeExtract %f32 %c_fvec3_copy 0\n"
3068 "%fmat_elem = OpCompositeExtract %f32 %c_fmat_copy 1 2\n"
3069 "%farr_elem = OpCompositeExtract %f32 %c_farr_copy 2\n"
3070 "%fst_elem = OpCompositeExtract %f32 %c_fst_copy 1\n"
3071 // Add up. 1.5 * 5 = 7.5.
3072 "%add1 = OpFAdd %f32 %c_f_copy %fvec3_elem\n"
3073 "%add2 = OpFAdd %f32 %add1 %fmat_elem\n"
3074 "%add3 = OpFAdd %f32 %add2 %farr_elem\n"
3075 "%add4 = OpFAdd %f32 %add3 %fst_elem\n"
3077 "%idval = OpLoad %uvec3 %id\n"
3078 "%x = OpCompositeExtract %u32 %idval 0\n"
3079 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3080 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3081 "%inval = OpLoad %f32 %inloc\n"
3082 "%add = OpFAdd %f32 %add4 %inval\n"
3083 " OpStore %outloc %add\n"
3086 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
3087 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
3088 spec.numWorkGroups = IVec3(numElements, 1, 1);
3090 group->addChild(new SpvAsmComputeShaderCase(testCtx, "spotcheck", "OpCopyObject on different types", spec));
3092 return group.release();
3094 // Assembly code used for testing OpUnreachable is based on GLSL source code:
3098 // layout(std140, set = 0, binding = 0) readonly buffer Input {
3099 // float elements[];
3101 // layout(std140, set = 0, binding = 1) writeonly buffer Output {
3102 // float elements[];
3105 // void not_called_func() {
3106 // // place OpUnreachable here
3109 // uint modulo4(uint val) {
3110 // switch (val % uint(4)) {
3111 // case 0: return 3;
3112 // case 1: return 2;
3113 // case 2: return 1;
3114 // case 3: return 0;
3115 // default: return 100; // place OpUnreachable here
3121 // // place OpUnreachable here
3125 // uint x = gl_GlobalInvocationID.x;
3126 // if (const5() > modulo4(1000)) {
3127 // output_data.elements[x] = -input_data.elements[x];
3129 // // place OpUnreachable here
3130 // output_data.elements[x] = input_data.elements[x];
3134 tcu::TestCaseGroup* createOpUnreachableGroup (tcu::TestContext& testCtx)
3136 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opunreachable", "Test the OpUnreachable instruction"));
3137 ComputeShaderSpec spec;
3138 de::Random rnd (deStringHash(group->getName()));
3139 const int numElements = 100;
3140 vector<float> positiveFloats (numElements, 0);
3141 vector<float> negativeFloats (numElements, 0);
3143 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
3145 for (size_t ndx = 0; ndx < numElements; ++ndx)
3146 negativeFloats[ndx] = -positiveFloats[ndx];
3149 string(getComputeAsmShaderPreamble()) +
3151 "OpSource GLSL 430\n"
3152 "OpName %main \"main\"\n"
3153 "OpName %func_not_called_func \"not_called_func(\"\n"
3154 "OpName %func_modulo4 \"modulo4(u1;\"\n"
3155 "OpName %func_const5 \"const5(\"\n"
3156 "OpName %id \"gl_GlobalInvocationID\"\n"
3158 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3160 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
3162 "%u32ptr = OpTypePointer Function %u32\n"
3163 "%uintfuint = OpTypeFunction %u32 %u32ptr\n"
3164 "%unitf = OpTypeFunction %u32\n"
3166 "%id = OpVariable %uvec3ptr Input\n"
3167 "%zero = OpConstant %u32 0\n"
3168 "%one = OpConstant %u32 1\n"
3169 "%two = OpConstant %u32 2\n"
3170 "%three = OpConstant %u32 3\n"
3171 "%four = OpConstant %u32 4\n"
3172 "%five = OpConstant %u32 5\n"
3173 "%hundred = OpConstant %u32 100\n"
3174 "%thousand = OpConstant %u32 1000\n"
3176 + string(getComputeAsmInputOutputBuffer()) +
3179 "%main = OpFunction %void None %voidf\n"
3180 "%main_entry = OpLabel\n"
3181 "%v_thousand = OpVariable %u32ptr Function %thousand\n"
3182 "%idval = OpLoad %uvec3 %id\n"
3183 "%x = OpCompositeExtract %u32 %idval 0\n"
3184 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3185 "%inval = OpLoad %f32 %inloc\n"
3186 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3187 "%ret_const5 = OpFunctionCall %u32 %func_const5\n"
3188 "%ret_modulo4 = OpFunctionCall %u32 %func_modulo4 %v_thousand\n"
3189 "%cmp_gt = OpUGreaterThan %bool %ret_const5 %ret_modulo4\n"
3190 " OpSelectionMerge %if_end None\n"
3191 " OpBranchConditional %cmp_gt %if_true %if_false\n"
3192 "%if_true = OpLabel\n"
3193 "%negate = OpFNegate %f32 %inval\n"
3194 " OpStore %outloc %negate\n"
3195 " OpBranch %if_end\n"
3196 "%if_false = OpLabel\n"
3197 " OpUnreachable\n" // Unreachable else branch for if statement
3198 "%if_end = OpLabel\n"
3202 // not_called_function()
3203 "%func_not_called_func = OpFunction %void None %voidf\n"
3204 "%not_called_func_entry = OpLabel\n"
3205 " OpUnreachable\n" // Unreachable entry block in not called static function
3209 "%func_modulo4 = OpFunction %u32 None %uintfuint\n"
3210 "%valptr = OpFunctionParameter %u32ptr\n"
3211 "%modulo4_entry = OpLabel\n"
3212 "%val = OpLoad %u32 %valptr\n"
3213 "%modulo = OpUMod %u32 %val %four\n"
3214 " OpSelectionMerge %switch_merge None\n"
3215 " OpSwitch %modulo %default 0 %case0 1 %case1 2 %case2 3 %case3\n"
3216 "%case0 = OpLabel\n"
3217 " OpReturnValue %three\n"
3218 "%case1 = OpLabel\n"
3219 " OpReturnValue %two\n"
3220 "%case2 = OpLabel\n"
3221 " OpReturnValue %one\n"
3222 "%case3 = OpLabel\n"
3223 " OpReturnValue %zero\n"
3224 "%default = OpLabel\n"
3225 " OpUnreachable\n" // Unreachable default case for switch statement
3226 "%switch_merge = OpLabel\n"
3227 " OpUnreachable\n" // Unreachable merge block for switch statement
3231 "%func_const5 = OpFunction %u32 None %unitf\n"
3232 "%const5_entry = OpLabel\n"
3233 " OpReturnValue %five\n"
3234 "%unreachable = OpLabel\n"
3235 " OpUnreachable\n" // Unreachable block in function
3237 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
3238 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
3239 spec.numWorkGroups = IVec3(numElements, 1, 1);
3241 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "OpUnreachable appearing at different places", spec));
3243 return group.release();
3246 // Assembly code used for testing decoration group is based on GLSL source code:
3250 // layout(std140, set = 0, binding = 0) readonly buffer Input0 {
3251 // float elements[];
3253 // layout(std140, set = 0, binding = 1) readonly buffer Input1 {
3254 // float elements[];
3256 // layout(std140, set = 0, binding = 2) readonly buffer Input2 {
3257 // float elements[];
3259 // layout(std140, set = 0, binding = 3) readonly buffer Input3 {
3260 // float elements[];
3262 // layout(std140, set = 0, binding = 4) readonly buffer Input4 {
3263 // float elements[];
3265 // layout(std140, set = 0, binding = 5) writeonly buffer Output {
3266 // float elements[];
3270 // uint x = gl_GlobalInvocationID.x;
3271 // output_data.elements[x] = input_data0.elements[x] + input_data1.elements[x] + input_data2.elements[x] + input_data3.elements[x] + input_data4.elements[x];
3273 tcu::TestCaseGroup* createDecorationGroupGroup (tcu::TestContext& testCtx)
3275 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "decoration_group", "Test the OpDecorationGroup & OpGroupDecorate instruction"));
3276 ComputeShaderSpec spec;
3277 de::Random rnd (deStringHash(group->getName()));
3278 const int numElements = 100;
3279 vector<float> inputFloats0 (numElements, 0);
3280 vector<float> inputFloats1 (numElements, 0);
3281 vector<float> inputFloats2 (numElements, 0);
3282 vector<float> inputFloats3 (numElements, 0);
3283 vector<float> inputFloats4 (numElements, 0);
3284 vector<float> outputFloats (numElements, 0);
3286 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats0[0], numElements);
3287 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats1[0], numElements);
3288 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats2[0], numElements);
3289 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats3[0], numElements);
3290 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats4[0], numElements);
3292 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
3293 floorAll(inputFloats0);
3294 floorAll(inputFloats1);
3295 floorAll(inputFloats2);
3296 floorAll(inputFloats3);
3297 floorAll(inputFloats4);
3299 for (size_t ndx = 0; ndx < numElements; ++ndx)
3300 outputFloats[ndx] = inputFloats0[ndx] + inputFloats1[ndx] + inputFloats2[ndx] + inputFloats3[ndx] + inputFloats4[ndx];
3303 string(getComputeAsmShaderPreamble()) +
3305 "OpSource GLSL 430\n"
3306 "OpName %main \"main\"\n"
3307 "OpName %id \"gl_GlobalInvocationID\"\n"
3309 // Not using group decoration on variable.
3310 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3311 // Not using group decoration on type.
3312 "OpDecorate %f32arr ArrayStride 4\n"
3314 "OpDecorate %groups BufferBlock\n"
3315 "OpDecorate %groupm Offset 0\n"
3316 "%groups = OpDecorationGroup\n"
3317 "%groupm = OpDecorationGroup\n"
3319 // Group decoration on multiple structs.
3320 "OpGroupDecorate %groups %outbuf %inbuf0 %inbuf1 %inbuf2 %inbuf3 %inbuf4\n"
3321 // Group decoration on multiple struct members.
3322 "OpGroupMemberDecorate %groupm %outbuf 0 %inbuf0 0 %inbuf1 0 %inbuf2 0 %inbuf3 0 %inbuf4 0\n"
3324 "OpDecorate %group1 DescriptorSet 0\n"
3325 "OpDecorate %group3 DescriptorSet 0\n"
3326 "OpDecorate %group3 NonWritable\n"
3327 "OpDecorate %group3 Restrict\n"
3328 "%group0 = OpDecorationGroup\n"
3329 "%group1 = OpDecorationGroup\n"
3330 "%group3 = OpDecorationGroup\n"
3332 // Applying the same decoration group multiple times.
3333 "OpGroupDecorate %group1 %outdata\n"
3334 "OpGroupDecorate %group1 %outdata\n"
3335 "OpGroupDecorate %group1 %outdata\n"
3336 "OpDecorate %outdata DescriptorSet 0\n"
3337 "OpDecorate %outdata Binding 5\n"
3338 // Applying decoration group containing nothing.
3339 "OpGroupDecorate %group0 %indata0\n"
3340 "OpDecorate %indata0 DescriptorSet 0\n"
3341 "OpDecorate %indata0 Binding 0\n"
3342 // Applying decoration group containing one decoration.
3343 "OpGroupDecorate %group1 %indata1\n"
3344 "OpDecorate %indata1 Binding 1\n"
3345 // Applying decoration group containing multiple decorations.
3346 "OpGroupDecorate %group3 %indata2 %indata3\n"
3347 "OpDecorate %indata2 Binding 2\n"
3348 "OpDecorate %indata3 Binding 3\n"
3349 // Applying multiple decoration groups (with overlapping).
3350 "OpGroupDecorate %group0 %indata4\n"
3351 "OpGroupDecorate %group1 %indata4\n"
3352 "OpGroupDecorate %group3 %indata4\n"
3353 "OpDecorate %indata4 Binding 4\n"
3355 + string(getComputeAsmCommonTypes()) +
3357 "%id = OpVariable %uvec3ptr Input\n"
3358 "%zero = OpConstant %i32 0\n"
3360 "%outbuf = OpTypeStruct %f32arr\n"
3361 "%outbufptr = OpTypePointer Uniform %outbuf\n"
3362 "%outdata = OpVariable %outbufptr Uniform\n"
3363 "%inbuf0 = OpTypeStruct %f32arr\n"
3364 "%inbuf0ptr = OpTypePointer Uniform %inbuf0\n"
3365 "%indata0 = OpVariable %inbuf0ptr Uniform\n"
3366 "%inbuf1 = OpTypeStruct %f32arr\n"
3367 "%inbuf1ptr = OpTypePointer Uniform %inbuf1\n"
3368 "%indata1 = OpVariable %inbuf1ptr Uniform\n"
3369 "%inbuf2 = OpTypeStruct %f32arr\n"
3370 "%inbuf2ptr = OpTypePointer Uniform %inbuf2\n"
3371 "%indata2 = OpVariable %inbuf2ptr Uniform\n"
3372 "%inbuf3 = OpTypeStruct %f32arr\n"
3373 "%inbuf3ptr = OpTypePointer Uniform %inbuf3\n"
3374 "%indata3 = OpVariable %inbuf3ptr Uniform\n"
3375 "%inbuf4 = OpTypeStruct %f32arr\n"
3376 "%inbufptr = OpTypePointer Uniform %inbuf4\n"
3377 "%indata4 = OpVariable %inbufptr Uniform\n"
3379 "%main = OpFunction %void None %voidf\n"
3380 "%label = OpLabel\n"
3381 "%idval = OpLoad %uvec3 %id\n"
3382 "%x = OpCompositeExtract %u32 %idval 0\n"
3383 "%inloc0 = OpAccessChain %f32ptr %indata0 %zero %x\n"
3384 "%inloc1 = OpAccessChain %f32ptr %indata1 %zero %x\n"
3385 "%inloc2 = OpAccessChain %f32ptr %indata2 %zero %x\n"
3386 "%inloc3 = OpAccessChain %f32ptr %indata3 %zero %x\n"
3387 "%inloc4 = OpAccessChain %f32ptr %indata4 %zero %x\n"
3388 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3389 "%inval0 = OpLoad %f32 %inloc0\n"
3390 "%inval1 = OpLoad %f32 %inloc1\n"
3391 "%inval2 = OpLoad %f32 %inloc2\n"
3392 "%inval3 = OpLoad %f32 %inloc3\n"
3393 "%inval4 = OpLoad %f32 %inloc4\n"
3394 "%add0 = OpFAdd %f32 %inval0 %inval1\n"
3395 "%add1 = OpFAdd %f32 %add0 %inval2\n"
3396 "%add2 = OpFAdd %f32 %add1 %inval3\n"
3397 "%add = OpFAdd %f32 %add2 %inval4\n"
3398 " OpStore %outloc %add\n"
3401 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats0)));
3402 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats1)));
3403 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
3404 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats3)));
3405 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats4)));
3406 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
3407 spec.numWorkGroups = IVec3(numElements, 1, 1);
3409 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "decoration group cases", spec));
3411 return group.release();
3414 struct SpecConstantTwoIntCase
3416 const char* caseName;
3417 const char* scDefinition0;
3418 const char* scDefinition1;
3419 const char* scResultType;
3420 const char* scOperation;
3421 deInt32 scActualValue0;
3422 deInt32 scActualValue1;
3423 const char* resultOperation;
3424 vector<deInt32> expectedOutput;
3425 deInt32 scActualValueLength;
3427 SpecConstantTwoIntCase (const char* name,
3428 const char* definition0,
3429 const char* definition1,
3430 const char* resultType,
3431 const char* operation,
3434 const char* resultOp,
3435 const vector<deInt32>& output,
3436 const deInt32 valueLength = sizeof(deInt32))
3438 , scDefinition0 (definition0)
3439 , scDefinition1 (definition1)
3440 , scResultType (resultType)
3441 , scOperation (operation)
3442 , scActualValue0 (value0)
3443 , scActualValue1 (value1)
3444 , resultOperation (resultOp)
3445 , expectedOutput (output)
3446 , scActualValueLength (valueLength)
3450 tcu::TestCaseGroup* createSpecConstantGroup (tcu::TestContext& testCtx)
3452 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opspecconstantop", "Test the OpSpecConstantOp instruction"));
3453 vector<SpecConstantTwoIntCase> cases;
3454 de::Random rnd (deStringHash(group->getName()));
3455 const int numElements = 100;
3456 const deInt32 p1AsFloat16 = 0x3c00; // +1(fp16) == 0 01111 0000000000 == 0011 1100 0000 0000
3457 vector<deInt32> inputInts (numElements, 0);
3458 vector<deInt32> outputInts1 (numElements, 0);
3459 vector<deInt32> outputInts2 (numElements, 0);
3460 vector<deInt32> outputInts3 (numElements, 0);
3461 vector<deInt32> outputInts4 (numElements, 0);
3462 const StringTemplate shaderTemplate (
3463 "${CAPABILITIES:opt}"
3464 + string(getComputeAsmShaderPreamble()) +
3466 "OpName %main \"main\"\n"
3467 "OpName %id \"gl_GlobalInvocationID\"\n"
3469 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3470 "OpDecorate %sc_0 SpecId 0\n"
3471 "OpDecorate %sc_1 SpecId 1\n"
3472 "OpDecorate %i32arr ArrayStride 4\n"
3474 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
3476 "${OPTYPE_DEFINITIONS:opt}"
3477 "%buf = OpTypeStruct %i32arr\n"
3478 "%bufptr = OpTypePointer Uniform %buf\n"
3479 "%indata = OpVariable %bufptr Uniform\n"
3480 "%outdata = OpVariable %bufptr Uniform\n"
3482 "%id = OpVariable %uvec3ptr Input\n"
3483 "%zero = OpConstant %i32 0\n"
3485 "%sc_0 = OpSpecConstant${SC_DEF0}\n"
3486 "%sc_1 = OpSpecConstant${SC_DEF1}\n"
3487 "%sc_final = OpSpecConstantOp ${SC_RESULT_TYPE} ${SC_OP}\n"
3489 "%main = OpFunction %void None %voidf\n"
3490 "%label = OpLabel\n"
3491 "${TYPE_CONVERT:opt}"
3492 "%idval = OpLoad %uvec3 %id\n"
3493 "%x = OpCompositeExtract %u32 %idval 0\n"
3494 "%inloc = OpAccessChain %i32ptr %indata %zero %x\n"
3495 "%inval = OpLoad %i32 %inloc\n"
3496 "%final = ${GEN_RESULT}\n"
3497 "%outloc = OpAccessChain %i32ptr %outdata %zero %x\n"
3498 " OpStore %outloc %final\n"
3500 " OpFunctionEnd\n");
3502 fillRandomScalars(rnd, -65536, 65536, &inputInts[0], numElements);
3504 for (size_t ndx = 0; ndx < numElements; ++ndx)
3506 outputInts1[ndx] = inputInts[ndx] + 42;
3507 outputInts2[ndx] = inputInts[ndx];
3508 outputInts3[ndx] = inputInts[ndx] - 11200;
3509 outputInts4[ndx] = inputInts[ndx] + 1;
3512 const char addScToInput[] = "OpIAdd %i32 %inval %sc_final";
3513 const char addSc32ToInput[] = "OpIAdd %i32 %inval %sc_final32";
3514 const char selectTrueUsingSc[] = "OpSelect %i32 %sc_final %inval %zero";
3515 const char selectFalseUsingSc[] = "OpSelect %i32 %sc_final %zero %inval";
3517 cases.push_back(SpecConstantTwoIntCase("iadd", " %i32 0", " %i32 0", "%i32", "IAdd %sc_0 %sc_1", 62, -20, addScToInput, outputInts1));
3518 cases.push_back(SpecConstantTwoIntCase("isub", " %i32 0", " %i32 0", "%i32", "ISub %sc_0 %sc_1", 100, 58, addScToInput, outputInts1));
3519 cases.push_back(SpecConstantTwoIntCase("imul", " %i32 0", " %i32 0", "%i32", "IMul %sc_0 %sc_1", -2, -21, addScToInput, outputInts1));
3520 cases.push_back(SpecConstantTwoIntCase("sdiv", " %i32 0", " %i32 0", "%i32", "SDiv %sc_0 %sc_1", -126, -3, addScToInput, outputInts1));
3521 cases.push_back(SpecConstantTwoIntCase("udiv", " %i32 0", " %i32 0", "%i32", "UDiv %sc_0 %sc_1", 126, 3, addScToInput, outputInts1));
3522 cases.push_back(SpecConstantTwoIntCase("srem", " %i32 0", " %i32 0", "%i32", "SRem %sc_0 %sc_1", 7, 3, addScToInput, outputInts4));
3523 cases.push_back(SpecConstantTwoIntCase("smod", " %i32 0", " %i32 0", "%i32", "SMod %sc_0 %sc_1", 7, 3, addScToInput, outputInts4));
3524 cases.push_back(SpecConstantTwoIntCase("umod", " %i32 0", " %i32 0", "%i32", "UMod %sc_0 %sc_1", 342, 50, addScToInput, outputInts1));
3525 cases.push_back(SpecConstantTwoIntCase("bitwiseand", " %i32 0", " %i32 0", "%i32", "BitwiseAnd %sc_0 %sc_1", 42, 63, addScToInput, outputInts1));
3526 cases.push_back(SpecConstantTwoIntCase("bitwiseor", " %i32 0", " %i32 0", "%i32", "BitwiseOr %sc_0 %sc_1", 34, 8, addScToInput, outputInts1));
3527 cases.push_back(SpecConstantTwoIntCase("bitwisexor", " %i32 0", " %i32 0", "%i32", "BitwiseXor %sc_0 %sc_1", 18, 56, addScToInput, outputInts1));
3528 cases.push_back(SpecConstantTwoIntCase("shiftrightlogical", " %i32 0", " %i32 0", "%i32", "ShiftRightLogical %sc_0 %sc_1", 168, 2, addScToInput, outputInts1));
3529 cases.push_back(SpecConstantTwoIntCase("shiftrightarithmetic", " %i32 0", " %i32 0", "%i32", "ShiftRightArithmetic %sc_0 %sc_1", 168, 2, addScToInput, outputInts1));
3530 cases.push_back(SpecConstantTwoIntCase("shiftleftlogical", " %i32 0", " %i32 0", "%i32", "ShiftLeftLogical %sc_0 %sc_1", 21, 1, addScToInput, outputInts1));
3531 cases.push_back(SpecConstantTwoIntCase("slessthan", " %i32 0", " %i32 0", "%bool", "SLessThan %sc_0 %sc_1", -20, -10, selectTrueUsingSc, outputInts2));
3532 cases.push_back(SpecConstantTwoIntCase("ulessthan", " %i32 0", " %i32 0", "%bool", "ULessThan %sc_0 %sc_1", 10, 20, selectTrueUsingSc, outputInts2));
3533 cases.push_back(SpecConstantTwoIntCase("sgreaterthan", " %i32 0", " %i32 0", "%bool", "SGreaterThan %sc_0 %sc_1", -1000, 50, selectFalseUsingSc, outputInts2));
3534 cases.push_back(SpecConstantTwoIntCase("ugreaterthan", " %i32 0", " %i32 0", "%bool", "UGreaterThan %sc_0 %sc_1", 10, 5, selectTrueUsingSc, outputInts2));
3535 cases.push_back(SpecConstantTwoIntCase("slessthanequal", " %i32 0", " %i32 0", "%bool", "SLessThanEqual %sc_0 %sc_1", -10, -10, selectTrueUsingSc, outputInts2));
3536 cases.push_back(SpecConstantTwoIntCase("ulessthanequal", " %i32 0", " %i32 0", "%bool", "ULessThanEqual %sc_0 %sc_1", 50, 100, selectTrueUsingSc, outputInts2));
3537 cases.push_back(SpecConstantTwoIntCase("sgreaterthanequal", " %i32 0", " %i32 0", "%bool", "SGreaterThanEqual %sc_0 %sc_1", -1000, 50, selectFalseUsingSc, outputInts2));
3538 cases.push_back(SpecConstantTwoIntCase("ugreaterthanequal", " %i32 0", " %i32 0", "%bool", "UGreaterThanEqual %sc_0 %sc_1", 10, 10, selectTrueUsingSc, outputInts2));
3539 cases.push_back(SpecConstantTwoIntCase("iequal", " %i32 0", " %i32 0", "%bool", "IEqual %sc_0 %sc_1", 42, 24, selectFalseUsingSc, outputInts2));
3540 cases.push_back(SpecConstantTwoIntCase("inotequal", " %i32 0", " %i32 0", "%bool", "INotEqual %sc_0 %sc_1", 42, 24, selectTrueUsingSc, outputInts2));
3541 cases.push_back(SpecConstantTwoIntCase("logicaland", "True %bool", "True %bool", "%bool", "LogicalAnd %sc_0 %sc_1", 0, 1, selectFalseUsingSc, outputInts2));
3542 cases.push_back(SpecConstantTwoIntCase("logicalor", "False %bool", "False %bool", "%bool", "LogicalOr %sc_0 %sc_1", 1, 0, selectTrueUsingSc, outputInts2));
3543 cases.push_back(SpecConstantTwoIntCase("logicalequal", "True %bool", "True %bool", "%bool", "LogicalEqual %sc_0 %sc_1", 0, 1, selectFalseUsingSc, outputInts2));
3544 cases.push_back(SpecConstantTwoIntCase("logicalnotequal", "False %bool", "False %bool", "%bool", "LogicalNotEqual %sc_0 %sc_1", 1, 0, selectTrueUsingSc, outputInts2));
3545 cases.push_back(SpecConstantTwoIntCase("snegate", " %i32 0", " %i32 0", "%i32", "SNegate %sc_0", -42, 0, addScToInput, outputInts1));
3546 cases.push_back(SpecConstantTwoIntCase("not", " %i32 0", " %i32 0", "%i32", "Not %sc_0", -43, 0, addScToInput, outputInts1));
3547 cases.push_back(SpecConstantTwoIntCase("logicalnot", "False %bool", "False %bool", "%bool", "LogicalNot %sc_0", 1, 0, selectFalseUsingSc, outputInts2));
3548 cases.push_back(SpecConstantTwoIntCase("select", "False %bool", " %i32 0", "%i32", "Select %sc_0 %sc_1 %zero", 1, 42, addScToInput, outputInts1));
3549 cases.push_back(SpecConstantTwoIntCase("sconvert", " %i32 0", " %i32 0", "%i16", "SConvert %sc_0", -11200, 0, addSc32ToInput, outputInts3));
3550 // -969998336 stored as 32-bit two's complement is the binary representation of -11200 as IEEE-754 Float
3551 cases.push_back(SpecConstantTwoIntCase("fconvert", " %f32 0", " %f32 0", "%f64", "FConvert %sc_0", -969998336, 0, addSc32ToInput, outputInts3));
3552 cases.push_back(SpecConstantTwoIntCase("fconvert16", " %f16 0", " %f16 0", "%f32", "FConvert %sc_0", p1AsFloat16, 0, addSc32ToInput, outputInts4, sizeof(deFloat16)));
3554 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
3556 map<string, string> specializations;
3557 ComputeShaderSpec spec;
3559 specializations["SC_DEF0"] = cases[caseNdx].scDefinition0;
3560 specializations["SC_DEF1"] = cases[caseNdx].scDefinition1;
3561 specializations["SC_RESULT_TYPE"] = cases[caseNdx].scResultType;
3562 specializations["SC_OP"] = cases[caseNdx].scOperation;
3563 specializations["GEN_RESULT"] = cases[caseNdx].resultOperation;
3565 // Special SPIR-V code for SConvert-case
3566 if (strcmp(cases[caseNdx].caseName, "sconvert") == 0)
3568 spec.requestedVulkanFeatures.coreFeatures.shaderInt16 = VK_TRUE;
3569 specializations["CAPABILITIES"] = "OpCapability Int16\n"; // Adds 16-bit integer capability
3570 specializations["OPTYPE_DEFINITIONS"] = "%i16 = OpTypeInt 16 1\n"; // Adds 16-bit integer type
3571 specializations["TYPE_CONVERT"] = "%sc_final32 = OpSConvert %i32 %sc_final\n"; // Converts 16-bit integer to 32-bit integer
3574 // Special SPIR-V code for FConvert-case
3575 if (strcmp(cases[caseNdx].caseName, "fconvert") == 0)
3577 spec.requestedVulkanFeatures.coreFeatures.shaderFloat64 = VK_TRUE;
3578 specializations["CAPABILITIES"] = "OpCapability Float64\n"; // Adds 64-bit float capability
3579 specializations["OPTYPE_DEFINITIONS"] = "%f64 = OpTypeFloat 64\n"; // Adds 64-bit float type
3580 specializations["TYPE_CONVERT"] = "%sc_final32 = OpConvertFToS %i32 %sc_final\n"; // Converts 64-bit float to 32-bit integer
3583 // Special SPIR-V code for FConvert-case for 16-bit floats
3584 if (strcmp(cases[caseNdx].caseName, "fconvert16") == 0)
3586 spec.extensions.push_back("VK_KHR_shader_float16_int8");
3587 spec.requestedVulkanFeatures.extFloat16Int8 = EXTFLOAT16INT8FEATURES_FLOAT16;
3588 specializations["CAPABILITIES"] = "OpCapability Float16\n"; // Adds 16-bit float capability
3589 specializations["OPTYPE_DEFINITIONS"] = "%f16 = OpTypeFloat 16\n"; // Adds 16-bit float type
3590 specializations["TYPE_CONVERT"] = "%sc_final32 = OpConvertFToS %i32 %sc_final\n"; // Converts 16-bit float to 32-bit integer
3593 spec.assembly = shaderTemplate.specialize(specializations);
3594 spec.inputs.push_back(BufferSp(new Int32Buffer(inputInts)));
3595 spec.outputs.push_back(BufferSp(new Int32Buffer(cases[caseNdx].expectedOutput)));
3596 spec.numWorkGroups = IVec3(numElements, 1, 1);
3597 spec.specConstants.append(&cases[caseNdx].scActualValue0, cases[caseNdx].scActualValueLength);
3598 spec.specConstants.append(&cases[caseNdx].scActualValue1, cases[caseNdx].scActualValueLength);
3600 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].caseName, cases[caseNdx].caseName, spec));
3603 ComputeShaderSpec spec;
3606 string(getComputeAsmShaderPreamble()) +
3608 "OpName %main \"main\"\n"
3609 "OpName %id \"gl_GlobalInvocationID\"\n"
3611 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3612 "OpDecorate %sc_0 SpecId 0\n"
3613 "OpDecorate %sc_1 SpecId 1\n"
3614 "OpDecorate %sc_2 SpecId 2\n"
3615 "OpDecorate %i32arr ArrayStride 4\n"
3617 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
3619 "%ivec3 = OpTypeVector %i32 3\n"
3620 "%buf = OpTypeStruct %i32arr\n"
3621 "%bufptr = OpTypePointer Uniform %buf\n"
3622 "%indata = OpVariable %bufptr Uniform\n"
3623 "%outdata = OpVariable %bufptr Uniform\n"
3625 "%id = OpVariable %uvec3ptr Input\n"
3626 "%zero = OpConstant %i32 0\n"
3627 "%ivec3_0 = OpConstantComposite %ivec3 %zero %zero %zero\n"
3628 "%vec3_undef = OpUndef %ivec3\n"
3630 "%sc_0 = OpSpecConstant %i32 0\n"
3631 "%sc_1 = OpSpecConstant %i32 0\n"
3632 "%sc_2 = OpSpecConstant %i32 0\n"
3633 "%sc_vec3_0 = OpSpecConstantOp %ivec3 CompositeInsert %sc_0 %ivec3_0 0\n" // (sc_0, 0, 0)
3634 "%sc_vec3_1 = OpSpecConstantOp %ivec3 CompositeInsert %sc_1 %ivec3_0 1\n" // (0, sc_1, 0)
3635 "%sc_vec3_2 = OpSpecConstantOp %ivec3 CompositeInsert %sc_2 %ivec3_0 2\n" // (0, 0, sc_2)
3636 "%sc_vec3_0_s = OpSpecConstantOp %ivec3 VectorShuffle %sc_vec3_0 %vec3_undef 0 0xFFFFFFFF 2\n" // (sc_0, ???, 0)
3637 "%sc_vec3_1_s = OpSpecConstantOp %ivec3 VectorShuffle %sc_vec3_1 %vec3_undef 0xFFFFFFFF 1 0\n" // (???, sc_1, 0)
3638 "%sc_vec3_2_s = OpSpecConstantOp %ivec3 VectorShuffle %vec3_undef %sc_vec3_2 5 0xFFFFFFFF 5\n" // (sc_2, ???, sc_2)
3639 "%sc_vec3_01 = OpSpecConstantOp %ivec3 VectorShuffle %sc_vec3_0_s %sc_vec3_1_s 1 0 4\n" // (0, sc_0, sc_1)
3640 "%sc_vec3_012 = OpSpecConstantOp %ivec3 VectorShuffle %sc_vec3_01 %sc_vec3_2_s 5 1 2\n" // (sc_2, sc_0, sc_1)
3641 "%sc_ext_0 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 0\n" // sc_2
3642 "%sc_ext_1 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 1\n" // sc_0
3643 "%sc_ext_2 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 2\n" // sc_1
3644 "%sc_sub = OpSpecConstantOp %i32 ISub %sc_ext_0 %sc_ext_1\n" // (sc_2 - sc_0)
3645 "%sc_final = OpSpecConstantOp %i32 IMul %sc_sub %sc_ext_2\n" // (sc_2 - sc_0) * sc_1
3647 "%main = OpFunction %void None %voidf\n"
3648 "%label = OpLabel\n"
3649 "%idval = OpLoad %uvec3 %id\n"
3650 "%x = OpCompositeExtract %u32 %idval 0\n"
3651 "%inloc = OpAccessChain %i32ptr %indata %zero %x\n"
3652 "%inval = OpLoad %i32 %inloc\n"
3653 "%final = OpIAdd %i32 %inval %sc_final\n"
3654 "%outloc = OpAccessChain %i32ptr %outdata %zero %x\n"
3655 " OpStore %outloc %final\n"
3658 spec.inputs.push_back(BufferSp(new Int32Buffer(inputInts)));
3659 spec.outputs.push_back(BufferSp(new Int32Buffer(outputInts3)));
3660 spec.numWorkGroups = IVec3(numElements, 1, 1);
3661 spec.specConstants.append<deInt32>(123);
3662 spec.specConstants.append<deInt32>(56);
3663 spec.specConstants.append<deInt32>(-77);
3665 group->addChild(new SpvAsmComputeShaderCase(testCtx, "vector_related", "VectorShuffle, CompositeExtract, & CompositeInsert", spec));
3667 return group.release();
3670 void createOpPhiVartypeTests (de::MovePtr<tcu::TestCaseGroup>& group, tcu::TestContext& testCtx)
3672 ComputeShaderSpec specInt;
3673 ComputeShaderSpec specFloat;
3674 ComputeShaderSpec specFloat16;
3675 ComputeShaderSpec specVec3;
3676 ComputeShaderSpec specMat4;
3677 ComputeShaderSpec specArray;
3678 ComputeShaderSpec specStruct;
3679 de::Random rnd (deStringHash(group->getName()));
3680 const int numElements = 100;
3681 vector<float> inputFloats (numElements, 0);
3682 vector<float> outputFloats (numElements, 0);
3683 vector<deFloat16> inputFloats16 (numElements, 0);
3684 vector<deFloat16> outputFloats16 (numElements, 0);
3686 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats[0], numElements);
3688 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
3689 floorAll(inputFloats);
3691 for (size_t ndx = 0; ndx < numElements; ++ndx)
3693 // Just check if the value is positive or not
3694 outputFloats[ndx] = (inputFloats[ndx] > 0) ? 1.0f : -1.0f;
3697 for (size_t ndx = 0; ndx < numElements; ++ndx)
3699 inputFloats16[ndx] = tcu::Float16(inputFloats[ndx]).bits();
3700 outputFloats16[ndx] = tcu::Float16(outputFloats[ndx]).bits();
3703 // All of the tests are of the form:
3707 // if (inputdata > 0)
3714 specFloat.assembly =
3715 string(getComputeAsmShaderPreamble()) +
3717 "OpSource GLSL 430\n"
3718 "OpName %main \"main\"\n"
3719 "OpName %id \"gl_GlobalInvocationID\"\n"
3721 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3723 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
3725 "%id = OpVariable %uvec3ptr Input\n"
3726 "%zero = OpConstant %i32 0\n"
3727 "%float_0 = OpConstant %f32 0.0\n"
3728 "%float_1 = OpConstant %f32 1.0\n"
3729 "%float_n1 = OpConstant %f32 -1.0\n"
3731 "%main = OpFunction %void None %voidf\n"
3732 "%entry = OpLabel\n"
3733 "%idval = OpLoad %uvec3 %id\n"
3734 "%x = OpCompositeExtract %u32 %idval 0\n"
3735 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3736 "%inval = OpLoad %f32 %inloc\n"
3738 "%comp = OpFOrdGreaterThan %bool %inval %float_0\n"
3739 " OpSelectionMerge %cm None\n"
3740 " OpBranchConditional %comp %tb %fb\n"
3746 "%res = OpPhi %f32 %float_1 %tb %float_n1 %fb\n"
3748 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3749 " OpStore %outloc %res\n"
3753 specFloat.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
3754 specFloat.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
3755 specFloat.numWorkGroups = IVec3(numElements, 1, 1);
3757 specFloat16.assembly =
3758 "OpCapability Shader\n"
3759 "OpCapability StorageUniformBufferBlock16\n"
3760 "OpCapability Float16\n"
3761 "OpExtension \"SPV_KHR_16bit_storage\"\n"
3762 "OpMemoryModel Logical GLSL450\n"
3763 "OpEntryPoint GLCompute %main \"main\" %id\n"
3764 "OpExecutionMode %main LocalSize 1 1 1\n"
3766 "OpSource GLSL 430\n"
3767 "OpName %main \"main\"\n"
3768 "OpName %id \"gl_GlobalInvocationID\"\n"
3770 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3772 "OpDecorate %buf BufferBlock\n"
3773 "OpDecorate %indata DescriptorSet 0\n"
3774 "OpDecorate %indata Binding 0\n"
3775 "OpDecorate %outdata DescriptorSet 0\n"
3776 "OpDecorate %outdata Binding 1\n"
3777 "OpDecorate %f16arr ArrayStride 2\n"
3778 "OpMemberDecorate %buf 0 Offset 0\n"
3780 "%f16 = OpTypeFloat 16\n"
3781 "%f16ptr = OpTypePointer Uniform %f16\n"
3782 "%f16arr = OpTypeRuntimeArray %f16\n"
3784 + string(getComputeAsmCommonTypes()) +
3786 "%buf = OpTypeStruct %f16arr\n"
3787 "%bufptr = OpTypePointer Uniform %buf\n"
3788 "%indata = OpVariable %bufptr Uniform\n"
3789 "%outdata = OpVariable %bufptr Uniform\n"
3791 "%id = OpVariable %uvec3ptr Input\n"
3792 "%zero = OpConstant %i32 0\n"
3793 "%float_0 = OpConstant %f32 0.0\n"
3794 "%float_1 = OpConstant %f32 1.0\n"
3795 "%float_n1 = OpConstant %f32 -1.0\n"
3797 "%main = OpFunction %void None %voidf\n"
3798 "%entry = OpLabel\n"
3799 "%idval = OpLoad %uvec3 %id\n"
3800 "%x = OpCompositeExtract %u32 %idval 0\n"
3801 "%inloc = OpAccessChain %f16ptr %indata %zero %x\n"
3802 "%inval = OpLoad %f16 %inloc\n"
3803 "%f32_inval = OpFConvert %f32 %inval\n"
3805 "%comp = OpFOrdGreaterThan %bool %f32_inval %float_0\n"
3806 " OpSelectionMerge %cm None\n"
3807 " OpBranchConditional %comp %tb %fb\n"
3813 "%res = OpPhi %f32 %float_1 %tb %float_n1 %fb\n"
3814 "%f16_res = OpFConvert %f16 %res\n"
3816 "%outloc = OpAccessChain %f16ptr %outdata %zero %x\n"
3817 " OpStore %outloc %f16_res\n"
3821 specFloat16.inputs.push_back(BufferSp(new Float16Buffer(inputFloats16)));
3822 specFloat16.outputs.push_back(BufferSp(new Float16Buffer(outputFloats16)));
3823 specFloat16.numWorkGroups = IVec3(numElements, 1, 1);
3824 specFloat16.requestedVulkanFeatures.ext16BitStorage = EXT16BITSTORAGEFEATURES_UNIFORM_BUFFER_BLOCK;
3825 specFloat16.requestedVulkanFeatures.extFloat16Int8 = EXTFLOAT16INT8FEATURES_FLOAT16;
3828 string(getComputeAsmShaderPreamble()) +
3830 "OpSource GLSL 430\n"
3831 "OpName %main \"main\"\n"
3832 "OpName %id \"gl_GlobalInvocationID\"\n"
3834 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3836 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
3838 "%id = OpVariable %uvec3ptr Input\n"
3839 "%v4f32 = OpTypeVector %f32 4\n"
3840 "%mat4v4f32 = OpTypeMatrix %v4f32 4\n"
3841 "%zero = OpConstant %i32 0\n"
3842 "%float_0 = OpConstant %f32 0.0\n"
3843 "%float_1 = OpConstant %f32 1.0\n"
3844 "%float_n1 = OpConstant %f32 -1.0\n"
3845 "%m11 = OpConstantComposite %v4f32 %float_1 %float_0 %float_0 %float_0\n"
3846 "%m12 = OpConstantComposite %v4f32 %float_0 %float_1 %float_0 %float_0\n"
3847 "%m13 = OpConstantComposite %v4f32 %float_0 %float_0 %float_1 %float_0\n"
3848 "%m14 = OpConstantComposite %v4f32 %float_0 %float_0 %float_0 %float_1\n"
3849 "%m1 = OpConstantComposite %mat4v4f32 %m11 %m12 %m13 %m14\n"
3850 "%m21 = OpConstantComposite %v4f32 %float_n1 %float_0 %float_0 %float_0\n"
3851 "%m22 = OpConstantComposite %v4f32 %float_0 %float_n1 %float_0 %float_0\n"
3852 "%m23 = OpConstantComposite %v4f32 %float_0 %float_0 %float_n1 %float_0\n"
3853 "%m24 = OpConstantComposite %v4f32 %float_0 %float_0 %float_0 %float_n1\n"
3854 "%m2 = OpConstantComposite %mat4v4f32 %m21 %m22 %m23 %m24\n"
3856 "%main = OpFunction %void None %voidf\n"
3857 "%entry = OpLabel\n"
3858 "%idval = OpLoad %uvec3 %id\n"
3859 "%x = OpCompositeExtract %u32 %idval 0\n"
3860 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3861 "%inval = OpLoad %f32 %inloc\n"
3863 "%comp = OpFOrdGreaterThan %bool %inval %float_0\n"
3864 " OpSelectionMerge %cm None\n"
3865 " OpBranchConditional %comp %tb %fb\n"
3871 "%mres = OpPhi %mat4v4f32 %m1 %tb %m2 %fb\n"
3872 "%res = OpCompositeExtract %f32 %mres 2 2\n"
3874 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3875 " OpStore %outloc %res\n"
3879 specMat4.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
3880 specMat4.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
3881 specMat4.numWorkGroups = IVec3(numElements, 1, 1);
3884 string(getComputeAsmShaderPreamble()) +
3886 "OpSource GLSL 430\n"
3887 "OpName %main \"main\"\n"
3888 "OpName %id \"gl_GlobalInvocationID\"\n"
3890 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3892 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
3894 "%id = OpVariable %uvec3ptr Input\n"
3895 "%zero = OpConstant %i32 0\n"
3896 "%float_0 = OpConstant %f32 0.0\n"
3897 "%float_1 = OpConstant %f32 1.0\n"
3898 "%float_n1 = OpConstant %f32 -1.0\n"
3899 "%v1 = OpConstantComposite %fvec3 %float_1 %float_1 %float_1\n"
3900 "%v2 = OpConstantComposite %fvec3 %float_n1 %float_n1 %float_n1\n"
3902 "%main = OpFunction %void None %voidf\n"
3903 "%entry = OpLabel\n"
3904 "%idval = OpLoad %uvec3 %id\n"
3905 "%x = OpCompositeExtract %u32 %idval 0\n"
3906 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3907 "%inval = OpLoad %f32 %inloc\n"
3909 "%comp = OpFOrdGreaterThan %bool %inval %float_0\n"
3910 " OpSelectionMerge %cm None\n"
3911 " OpBranchConditional %comp %tb %fb\n"
3917 "%vres = OpPhi %fvec3 %v1 %tb %v2 %fb\n"
3918 "%res = OpCompositeExtract %f32 %vres 2\n"
3920 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3921 " OpStore %outloc %res\n"
3925 specVec3.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
3926 specVec3.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
3927 specVec3.numWorkGroups = IVec3(numElements, 1, 1);
3930 string(getComputeAsmShaderPreamble()) +
3932 "OpSource GLSL 430\n"
3933 "OpName %main \"main\"\n"
3934 "OpName %id \"gl_GlobalInvocationID\"\n"
3936 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3938 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
3940 "%id = OpVariable %uvec3ptr Input\n"
3941 "%zero = OpConstant %i32 0\n"
3942 "%float_0 = OpConstant %f32 0.0\n"
3943 "%i1 = OpConstant %i32 1\n"
3944 "%i2 = OpConstant %i32 -1\n"
3946 "%main = OpFunction %void None %voidf\n"
3947 "%entry = OpLabel\n"
3948 "%idval = OpLoad %uvec3 %id\n"
3949 "%x = OpCompositeExtract %u32 %idval 0\n"
3950 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3951 "%inval = OpLoad %f32 %inloc\n"
3953 "%comp = OpFOrdGreaterThan %bool %inval %float_0\n"
3954 " OpSelectionMerge %cm None\n"
3955 " OpBranchConditional %comp %tb %fb\n"
3961 "%ires = OpPhi %i32 %i1 %tb %i2 %fb\n"
3962 "%res = OpConvertSToF %f32 %ires\n"
3964 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3965 " OpStore %outloc %res\n"
3969 specInt.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
3970 specInt.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
3971 specInt.numWorkGroups = IVec3(numElements, 1, 1);
3973 specArray.assembly =
3974 string(getComputeAsmShaderPreamble()) +
3976 "OpSource GLSL 430\n"
3977 "OpName %main \"main\"\n"
3978 "OpName %id \"gl_GlobalInvocationID\"\n"
3980 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3982 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
3984 "%id = OpVariable %uvec3ptr Input\n"
3985 "%zero = OpConstant %i32 0\n"
3986 "%u7 = OpConstant %u32 7\n"
3987 "%float_0 = OpConstant %f32 0.0\n"
3988 "%float_1 = OpConstant %f32 1.0\n"
3989 "%float_n1 = OpConstant %f32 -1.0\n"
3990 "%f32a7 = OpTypeArray %f32 %u7\n"
3991 "%a1 = OpConstantComposite %f32a7 %float_1 %float_1 %float_1 %float_1 %float_1 %float_1 %float_1\n"
3992 "%a2 = OpConstantComposite %f32a7 %float_n1 %float_n1 %float_n1 %float_n1 %float_n1 %float_n1 %float_n1\n"
3993 "%main = OpFunction %void None %voidf\n"
3994 "%entry = OpLabel\n"
3995 "%idval = OpLoad %uvec3 %id\n"
3996 "%x = OpCompositeExtract %u32 %idval 0\n"
3997 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3998 "%inval = OpLoad %f32 %inloc\n"
4000 "%comp = OpFOrdGreaterThan %bool %inval %float_0\n"
4001 " OpSelectionMerge %cm None\n"
4002 " OpBranchConditional %comp %tb %fb\n"
4008 "%ares = OpPhi %f32a7 %a1 %tb %a2 %fb\n"
4009 "%res = OpCompositeExtract %f32 %ares 5\n"
4011 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
4012 " OpStore %outloc %res\n"
4016 specArray.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
4017 specArray.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
4018 specArray.numWorkGroups = IVec3(numElements, 1, 1);
4020 specStruct.assembly =
4021 string(getComputeAsmShaderPreamble()) +
4023 "OpSource GLSL 430\n"
4024 "OpName %main \"main\"\n"
4025 "OpName %id \"gl_GlobalInvocationID\"\n"
4027 "OpDecorate %id BuiltIn GlobalInvocationId\n"
4029 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
4031 "%id = OpVariable %uvec3ptr Input\n"
4032 "%zero = OpConstant %i32 0\n"
4033 "%float_0 = OpConstant %f32 0.0\n"
4034 "%float_1 = OpConstant %f32 1.0\n"
4035 "%float_n1 = OpConstant %f32 -1.0\n"
4037 "%v2f32 = OpTypeVector %f32 2\n"
4038 "%Data2 = OpTypeStruct %f32 %v2f32\n"
4039 "%Data = OpTypeStruct %Data2 %f32\n"
4041 "%in1a = OpConstantComposite %v2f32 %float_1 %float_1\n"
4042 "%in1b = OpConstantComposite %Data2 %float_1 %in1a\n"
4043 "%s1 = OpConstantComposite %Data %in1b %float_1\n"
4044 "%in2a = OpConstantComposite %v2f32 %float_n1 %float_n1\n"
4045 "%in2b = OpConstantComposite %Data2 %float_n1 %in2a\n"
4046 "%s2 = OpConstantComposite %Data %in2b %float_n1\n"
4048 "%main = OpFunction %void None %voidf\n"
4049 "%entry = OpLabel\n"
4050 "%idval = OpLoad %uvec3 %id\n"
4051 "%x = OpCompositeExtract %u32 %idval 0\n"
4052 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
4053 "%inval = OpLoad %f32 %inloc\n"
4055 "%comp = OpFOrdGreaterThan %bool %inval %float_0\n"
4056 " OpSelectionMerge %cm None\n"
4057 " OpBranchConditional %comp %tb %fb\n"
4063 "%sres = OpPhi %Data %s1 %tb %s2 %fb\n"
4064 "%res = OpCompositeExtract %f32 %sres 0 0\n"
4066 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
4067 " OpStore %outloc %res\n"
4071 specStruct.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
4072 specStruct.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
4073 specStruct.numWorkGroups = IVec3(numElements, 1, 1);
4075 group->addChild(new SpvAsmComputeShaderCase(testCtx, "vartype_int", "OpPhi with int variables", specInt));
4076 group->addChild(new SpvAsmComputeShaderCase(testCtx, "vartype_float", "OpPhi with float variables", specFloat));
4077 group->addChild(new SpvAsmComputeShaderCase(testCtx, "vartype_float16", "OpPhi with 16bit float variables", specFloat16));
4078 group->addChild(new SpvAsmComputeShaderCase(testCtx, "vartype_vec3", "OpPhi with vec3 variables", specVec3));
4079 group->addChild(new SpvAsmComputeShaderCase(testCtx, "vartype_mat4", "OpPhi with mat4 variables", specMat4));
4080 group->addChild(new SpvAsmComputeShaderCase(testCtx, "vartype_array", "OpPhi with array variables", specArray));
4081 group->addChild(new SpvAsmComputeShaderCase(testCtx, "vartype_struct", "OpPhi with struct variables", specStruct));
4084 string generateConstantDefinitions (int count)
4086 std::ostringstream r;
4087 for (int i = 0; i < count; i++)
4088 r << "%cf" << (i * 10 + 5) << " = OpConstant %f32 " <<(i * 10 + 5) << ".0\n";
4093 string generateSwitchCases (int count)
4095 std::ostringstream r;
4096 for (int i = 0; i < count; i++)
4097 r << " " << i << " %case" << i;
4102 string generateSwitchTargets (int count)
4104 std::ostringstream r;
4105 for (int i = 0; i < count; i++)
4106 r << "%case" << i << " = OpLabel\n OpBranch %phi\n";
4111 string generateOpPhiParams (int count)
4113 std::ostringstream r;
4114 for (int i = 0; i < count; i++)
4115 r << " %cf" << (i * 10 + 5) << " %case" << i;
4120 string generateIntWidth (int value)
4122 std::ostringstream r;
4127 // Expand input string by injecting "ABC" between the input
4128 // string characters. The acc/add/treshold parameters are used
4129 // to skip some of the injections to make the result less
4130 // uniform (and a lot shorter).
4131 string expandOpPhiCase5 (const string& s, int &acc, int add, int treshold)
4133 std::ostringstream res;
4134 const char* p = s.c_str();
4150 // Calculate expected result based on the code string
4151 float calcOpPhiCase5 (float val, const string& s)
4153 const char* p = s.c_str();
4156 const float tv[8] = { 0.5f, 1.5f, 3.5f, 7.5f, 15.5f, 31.5f, 63.5f, 127.5f };
4157 const float v = deFloatAbs(val);
4162 for (int i = 7; i >= 0; --i)
4163 x[i] = std::fmod((float)v, (float)(2 << i));
4164 for (int i = 7; i >= 0; --i)
4165 b[i] = x[i] > tv[i];
4172 if (skip == 0 && b[depth])
4183 if (b[depth] || skip)
4197 // In the code string, the letters represent the following:
4200 // if (certain bit is set)
4211 // AABCBC leads to if(){r++;if(){r++;}else{}}else{}
4212 // ABABCC leads to if(){r++;}else{if(){r++;}else{}}
4213 // ABCABC leads to if(){r++;}else{}if(){r++;}else{}
4215 // Code generation gets a bit complicated due to the else-branches,
4216 // which do not generate new values. Thus, the generator needs to
4217 // keep track of the previous variable change seen by the else
4219 string generateOpPhiCase5 (const string& s)
4221 std::stack<int> idStack;
4222 std::stack<std::string> value;
4223 std::stack<std::string> valueLabel;
4224 std::stack<std::string> mergeLeft;
4225 std::stack<std::string> mergeRight;
4226 std::ostringstream res;
4227 const char* p = s.c_str();
4233 value.push("%f32_0");
4234 valueLabel.push("%f32_0 %entry");
4242 idStack.push(currId);
4243 res << "\tOpSelectionMerge %m" << currId << " None\n";
4244 res << "\tOpBranchConditional %b" << depth << " %t" << currId << " %f" << currId << "\n";
4245 res << "%t" << currId << " = OpLabel\n";
4246 res << "%rt" << currId << " = OpFAdd %f32 " << value.top() << " %f32_1\n";
4247 std::ostringstream tag;
4248 tag << "%rt" << currId;
4249 value.push(tag.str());
4250 tag << " %t" << currId;
4251 valueLabel.push(tag.str());
4256 mergeLeft.push(valueLabel.top());
4259 res << "\tOpBranch %m" << currId << "\n";
4260 res << "%f" << currId << " = OpLabel\n";
4261 std::ostringstream tag;
4262 tag << value.top() << " %f" << currId;
4264 valueLabel.push(tag.str());
4269 mergeRight.push(valueLabel.top());
4270 res << "\tOpBranch %m" << currId << "\n";
4271 res << "%m" << currId << " = OpLabel\n";
4273 res << "%res"; // last result goes to %res
4275 res << "%rm" << currId;
4276 res << " = OpPhi %f32 " << mergeLeft.top() << " " << mergeRight.top() << "\n";
4277 std::ostringstream tag;
4278 tag << "%rm" << currId;
4280 value.push(tag.str());
4281 tag << " %m" << currId;
4283 valueLabel.push(tag.str());
4288 currId = idStack.top();
4296 tcu::TestCaseGroup* createOpPhiGroup (tcu::TestContext& testCtx)
4298 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opphi", "Test the OpPhi instruction"));
4299 ComputeShaderSpec spec1;
4300 ComputeShaderSpec spec2;
4301 ComputeShaderSpec spec3;
4302 ComputeShaderSpec spec4;
4303 ComputeShaderSpec spec5;
4304 de::Random rnd (deStringHash(group->getName()));
4305 const int numElements = 100;
4306 vector<float> inputFloats (numElements, 0);
4307 vector<float> outputFloats1 (numElements, 0);
4308 vector<float> outputFloats2 (numElements, 0);
4309 vector<float> outputFloats3 (numElements, 0);
4310 vector<float> outputFloats4 (numElements, 0);
4311 vector<float> outputFloats5 (numElements, 0);
4312 std::string codestring = "ABC";
4313 const int test4Width = 1024;
4315 // Build case 5 code string. Each iteration makes the hierarchy more complicated.
4316 // 9 iterations with (7, 24) parameters makes the hierarchy 8 deep with about 1500 lines of
4318 for (int i = 0, acc = 0; i < 9; i++)
4319 codestring = expandOpPhiCase5(codestring, acc, 7, 24);
4321 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats[0], numElements);
4323 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
4324 floorAll(inputFloats);
4326 for (size_t ndx = 0; ndx < numElements; ++ndx)
4330 case 0: outputFloats1[ndx] = inputFloats[ndx] + 5.5f; break;
4331 case 1: outputFloats1[ndx] = inputFloats[ndx] + 20.5f; break;
4332 case 2: outputFloats1[ndx] = inputFloats[ndx] + 1.75f; break;
4335 outputFloats2[ndx] = inputFloats[ndx] + 6.5f * 3;
4336 outputFloats3[ndx] = 8.5f - inputFloats[ndx];
4338 int index4 = (int)deFloor(deAbs((float)ndx * inputFloats[ndx]));
4339 outputFloats4[ndx] = (float)(index4 % test4Width) * 10.0f + 5.0f;
4341 outputFloats5[ndx] = calcOpPhiCase5(inputFloats[ndx], codestring);
4345 string(getComputeAsmShaderPreamble()) +
4347 "OpSource GLSL 430\n"
4348 "OpName %main \"main\"\n"
4349 "OpName %id \"gl_GlobalInvocationID\"\n"
4351 "OpDecorate %id BuiltIn GlobalInvocationId\n"
4353 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
4355 "%id = OpVariable %uvec3ptr Input\n"
4356 "%zero = OpConstant %i32 0\n"
4357 "%three = OpConstant %u32 3\n"
4358 "%constf5p5 = OpConstant %f32 5.5\n"
4359 "%constf20p5 = OpConstant %f32 20.5\n"
4360 "%constf1p75 = OpConstant %f32 1.75\n"
4361 "%constf8p5 = OpConstant %f32 8.5\n"
4362 "%constf6p5 = OpConstant %f32 6.5\n"
4364 "%main = OpFunction %void None %voidf\n"
4365 "%entry = OpLabel\n"
4366 "%idval = OpLoad %uvec3 %id\n"
4367 "%x = OpCompositeExtract %u32 %idval 0\n"
4368 "%selector = OpUMod %u32 %x %three\n"
4369 " OpSelectionMerge %phi None\n"
4370 " OpSwitch %selector %default 0 %case0 1 %case1 2 %case2\n"
4372 // Case 1 before OpPhi.
4373 "%case1 = OpLabel\n"
4376 "%default = OpLabel\n"
4380 "%operand = OpPhi %f32 %constf1p75 %case2 %constf20p5 %case1 %constf5p5 %case0\n" // not in the order of blocks
4381 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
4382 "%inval = OpLoad %f32 %inloc\n"
4383 "%add = OpFAdd %f32 %inval %operand\n"
4384 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
4385 " OpStore %outloc %add\n"
4388 // Case 0 after OpPhi.
4389 "%case0 = OpLabel\n"
4393 // Case 2 after OpPhi.
4394 "%case2 = OpLabel\n"
4398 spec1.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
4399 spec1.outputs.push_back(BufferSp(new Float32Buffer(outputFloats1)));
4400 spec1.numWorkGroups = IVec3(numElements, 1, 1);
4402 group->addChild(new SpvAsmComputeShaderCase(testCtx, "block", "out-of-order and unreachable blocks for OpPhi", spec1));
4405 string(getComputeAsmShaderPreamble()) +
4407 "OpName %main \"main\"\n"
4408 "OpName %id \"gl_GlobalInvocationID\"\n"
4410 "OpDecorate %id BuiltIn GlobalInvocationId\n"
4412 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
4414 "%id = OpVariable %uvec3ptr Input\n"
4415 "%zero = OpConstant %i32 0\n"
4416 "%one = OpConstant %i32 1\n"
4417 "%three = OpConstant %i32 3\n"
4418 "%constf6p5 = OpConstant %f32 6.5\n"
4420 "%main = OpFunction %void None %voidf\n"
4421 "%entry = OpLabel\n"
4422 "%idval = OpLoad %uvec3 %id\n"
4423 "%x = OpCompositeExtract %u32 %idval 0\n"
4424 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
4425 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
4426 "%inval = OpLoad %f32 %inloc\n"
4430 "%step = OpPhi %i32 %zero %entry %step_next %phi\n"
4431 "%accum = OpPhi %f32 %inval %entry %accum_next %phi\n"
4432 "%step_next = OpIAdd %i32 %step %one\n"
4433 "%accum_next = OpFAdd %f32 %accum %constf6p5\n"
4434 "%still_loop = OpSLessThan %bool %step %three\n"
4435 " OpLoopMerge %exit %phi None\n"
4436 " OpBranchConditional %still_loop %phi %exit\n"
4439 " OpStore %outloc %accum\n"
4442 spec2.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
4443 spec2.outputs.push_back(BufferSp(new Float32Buffer(outputFloats2)));
4444 spec2.numWorkGroups = IVec3(numElements, 1, 1);
4446 group->addChild(new SpvAsmComputeShaderCase(testCtx, "induction", "The usual way induction variables are handled in LLVM IR", spec2));
4449 string(getComputeAsmShaderPreamble()) +
4451 "OpName %main \"main\"\n"
4452 "OpName %id \"gl_GlobalInvocationID\"\n"
4454 "OpDecorate %id BuiltIn GlobalInvocationId\n"
4456 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
4458 "%f32ptr_f = OpTypePointer Function %f32\n"
4459 "%id = OpVariable %uvec3ptr Input\n"
4460 "%true = OpConstantTrue %bool\n"
4461 "%false = OpConstantFalse %bool\n"
4462 "%zero = OpConstant %i32 0\n"
4463 "%constf8p5 = OpConstant %f32 8.5\n"
4465 "%main = OpFunction %void None %voidf\n"
4466 "%entry = OpLabel\n"
4467 "%b = OpVariable %f32ptr_f Function %constf8p5\n"
4468 "%idval = OpLoad %uvec3 %id\n"
4469 "%x = OpCompositeExtract %u32 %idval 0\n"
4470 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
4471 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
4472 "%a_init = OpLoad %f32 %inloc\n"
4473 "%b_init = OpLoad %f32 %b\n"
4477 "%still_loop = OpPhi %bool %true %entry %false %phi\n"
4478 "%a_next = OpPhi %f32 %a_init %entry %b_next %phi\n"
4479 "%b_next = OpPhi %f32 %b_init %entry %a_next %phi\n"
4480 " OpLoopMerge %exit %phi None\n"
4481 " OpBranchConditional %still_loop %phi %exit\n"
4484 "%sub = OpFSub %f32 %a_next %b_next\n"
4485 " OpStore %outloc %sub\n"
4488 spec3.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
4489 spec3.outputs.push_back(BufferSp(new Float32Buffer(outputFloats3)));
4490 spec3.numWorkGroups = IVec3(numElements, 1, 1);
4492 group->addChild(new SpvAsmComputeShaderCase(testCtx, "swap", "Swap the values of two variables using OpPhi", spec3));
4495 "OpCapability Shader\n"
4496 "%ext = OpExtInstImport \"GLSL.std.450\"\n"
4497 "OpMemoryModel Logical GLSL450\n"
4498 "OpEntryPoint GLCompute %main \"main\" %id\n"
4499 "OpExecutionMode %main LocalSize 1 1 1\n"
4501 "OpSource GLSL 430\n"
4502 "OpName %main \"main\"\n"
4503 "OpName %id \"gl_GlobalInvocationID\"\n"
4505 "OpDecorate %id BuiltIn GlobalInvocationId\n"
4507 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
4509 "%id = OpVariable %uvec3ptr Input\n"
4510 "%zero = OpConstant %i32 0\n"
4511 "%cimod = OpConstant %u32 " + generateIntWidth(test4Width) + "\n"
4513 + generateConstantDefinitions(test4Width) +
4515 "%main = OpFunction %void None %voidf\n"
4516 "%entry = OpLabel\n"
4517 "%idval = OpLoad %uvec3 %id\n"
4518 "%x = OpCompositeExtract %u32 %idval 0\n"
4519 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
4520 "%inval = OpLoad %f32 %inloc\n"
4521 "%xf = OpConvertUToF %f32 %x\n"
4522 "%xm = OpFMul %f32 %xf %inval\n"
4523 "%xa = OpExtInst %f32 %ext FAbs %xm\n"
4524 "%xi = OpConvertFToU %u32 %xa\n"
4525 "%selector = OpUMod %u32 %xi %cimod\n"
4526 " OpSelectionMerge %phi None\n"
4527 " OpSwitch %selector %default "
4529 + generateSwitchCases(test4Width) +
4531 "%default = OpLabel\n"
4534 + generateSwitchTargets(test4Width) +
4537 "%result = OpPhi %f32"
4539 + generateOpPhiParams(test4Width) +
4541 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
4542 " OpStore %outloc %result\n"
4546 spec4.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
4547 spec4.outputs.push_back(BufferSp(new Float32Buffer(outputFloats4)));
4548 spec4.numWorkGroups = IVec3(numElements, 1, 1);
4550 group->addChild(new SpvAsmComputeShaderCase(testCtx, "wide", "OpPhi with a lot of parameters", spec4));
4553 "OpCapability Shader\n"
4554 "%ext = OpExtInstImport \"GLSL.std.450\"\n"
4555 "OpMemoryModel Logical GLSL450\n"
4556 "OpEntryPoint GLCompute %main \"main\" %id\n"
4557 "OpExecutionMode %main LocalSize 1 1 1\n"
4558 "%code = OpString \"" + codestring + "\"\n"
4560 "OpSource GLSL 430\n"
4561 "OpName %main \"main\"\n"
4562 "OpName %id \"gl_GlobalInvocationID\"\n"
4564 "OpDecorate %id BuiltIn GlobalInvocationId\n"
4566 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
4568 "%id = OpVariable %uvec3ptr Input\n"
4569 "%zero = OpConstant %i32 0\n"
4570 "%f32_0 = OpConstant %f32 0.0\n"
4571 "%f32_0_5 = OpConstant %f32 0.5\n"
4572 "%f32_1 = OpConstant %f32 1.0\n"
4573 "%f32_1_5 = OpConstant %f32 1.5\n"
4574 "%f32_2 = OpConstant %f32 2.0\n"
4575 "%f32_3_5 = OpConstant %f32 3.5\n"
4576 "%f32_4 = OpConstant %f32 4.0\n"
4577 "%f32_7_5 = OpConstant %f32 7.5\n"
4578 "%f32_8 = OpConstant %f32 8.0\n"
4579 "%f32_15_5 = OpConstant %f32 15.5\n"
4580 "%f32_16 = OpConstant %f32 16.0\n"
4581 "%f32_31_5 = OpConstant %f32 31.5\n"
4582 "%f32_32 = OpConstant %f32 32.0\n"
4583 "%f32_63_5 = OpConstant %f32 63.5\n"
4584 "%f32_64 = OpConstant %f32 64.0\n"
4585 "%f32_127_5 = OpConstant %f32 127.5\n"
4586 "%f32_128 = OpConstant %f32 128.0\n"
4587 "%f32_256 = OpConstant %f32 256.0\n"
4589 "%main = OpFunction %void None %voidf\n"
4590 "%entry = OpLabel\n"
4591 "%idval = OpLoad %uvec3 %id\n"
4592 "%x = OpCompositeExtract %u32 %idval 0\n"
4593 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
4594 "%inval = OpLoad %f32 %inloc\n"
4596 "%xabs = OpExtInst %f32 %ext FAbs %inval\n"
4597 "%x8 = OpFMod %f32 %xabs %f32_256\n"
4598 "%x7 = OpFMod %f32 %xabs %f32_128\n"
4599 "%x6 = OpFMod %f32 %xabs %f32_64\n"
4600 "%x5 = OpFMod %f32 %xabs %f32_32\n"
4601 "%x4 = OpFMod %f32 %xabs %f32_16\n"
4602 "%x3 = OpFMod %f32 %xabs %f32_8\n"
4603 "%x2 = OpFMod %f32 %xabs %f32_4\n"
4604 "%x1 = OpFMod %f32 %xabs %f32_2\n"
4606 "%b7 = OpFOrdGreaterThanEqual %bool %x8 %f32_127_5\n"
4607 "%b6 = OpFOrdGreaterThanEqual %bool %x7 %f32_63_5\n"
4608 "%b5 = OpFOrdGreaterThanEqual %bool %x6 %f32_31_5\n"
4609 "%b4 = OpFOrdGreaterThanEqual %bool %x5 %f32_15_5\n"
4610 "%b3 = OpFOrdGreaterThanEqual %bool %x4 %f32_7_5\n"
4611 "%b2 = OpFOrdGreaterThanEqual %bool %x3 %f32_3_5\n"
4612 "%b1 = OpFOrdGreaterThanEqual %bool %x2 %f32_1_5\n"
4613 "%b0 = OpFOrdGreaterThanEqual %bool %x1 %f32_0_5\n"
4615 + generateOpPhiCase5(codestring) +
4617 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
4618 " OpStore %outloc %res\n"
4622 spec5.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
4623 spec5.outputs.push_back(BufferSp(new Float32Buffer(outputFloats5)));
4624 spec5.numWorkGroups = IVec3(numElements, 1, 1);
4626 group->addChild(new SpvAsmComputeShaderCase(testCtx, "nested", "Stress OpPhi with a lot of nesting", spec5));
4628 createOpPhiVartypeTests(group, testCtx);
4630 return group.release();
4633 // Assembly code used for testing block order is based on GLSL source code:
4637 // layout(std140, set = 0, binding = 0) readonly buffer Input {
4638 // float elements[];
4640 // layout(std140, set = 0, binding = 1) writeonly buffer Output {
4641 // float elements[];
4645 // uint x = gl_GlobalInvocationID.x;
4646 // output_data.elements[x] = input_data.elements[x];
4647 // if (x > uint(50)) {
4648 // switch (x % uint(3)) {
4649 // case 0: output_data.elements[x] += 1.5f; break;
4650 // case 1: output_data.elements[x] += 42.f; break;
4651 // case 2: output_data.elements[x] -= 27.f; break;
4655 // output_data.elements[x] = -input_data.elements[x];
4658 tcu::TestCaseGroup* createBlockOrderGroup (tcu::TestContext& testCtx)
4660 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "block_order", "Test block orders"));
4661 ComputeShaderSpec spec;
4662 de::Random rnd (deStringHash(group->getName()));
4663 const int numElements = 100;
4664 vector<float> inputFloats (numElements, 0);
4665 vector<float> outputFloats (numElements, 0);
4667 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats[0], numElements);
4669 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
4670 floorAll(inputFloats);
4672 for (size_t ndx = 0; ndx <= 50; ++ndx)
4673 outputFloats[ndx] = -inputFloats[ndx];
4675 for (size_t ndx = 51; ndx < numElements; ++ndx)
4679 case 0: outputFloats[ndx] = inputFloats[ndx] + 1.5f; break;
4680 case 1: outputFloats[ndx] = inputFloats[ndx] + 42.f; break;
4681 case 2: outputFloats[ndx] = inputFloats[ndx] - 27.f; break;
4687 string(getComputeAsmShaderPreamble()) +
4689 "OpSource GLSL 430\n"
4690 "OpName %main \"main\"\n"
4691 "OpName %id \"gl_GlobalInvocationID\"\n"
4693 "OpDecorate %id BuiltIn GlobalInvocationId\n"
4695 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
4697 "%u32ptr = OpTypePointer Function %u32\n"
4698 "%u32ptr_input = OpTypePointer Input %u32\n"
4700 + string(getComputeAsmInputOutputBuffer()) +
4702 "%id = OpVariable %uvec3ptr Input\n"
4703 "%zero = OpConstant %i32 0\n"
4704 "%const3 = OpConstant %u32 3\n"
4705 "%const50 = OpConstant %u32 50\n"
4706 "%constf1p5 = OpConstant %f32 1.5\n"
4707 "%constf27 = OpConstant %f32 27.0\n"
4708 "%constf42 = OpConstant %f32 42.0\n"
4710 "%main = OpFunction %void None %voidf\n"
4713 "%entry = OpLabel\n"
4715 // Create a temporary variable to hold the value of gl_GlobalInvocationID.x.
4716 "%xvar = OpVariable %u32ptr Function\n"
4717 "%xptr = OpAccessChain %u32ptr_input %id %zero\n"
4718 "%x = OpLoad %u32 %xptr\n"
4719 " OpStore %xvar %x\n"
4721 "%cmp = OpUGreaterThan %bool %x %const50\n"
4722 " OpSelectionMerge %if_merge None\n"
4723 " OpBranchConditional %cmp %if_true %if_false\n"
4725 // False branch for if-statement: placed in the middle of switch cases and before true branch.
4726 "%if_false = OpLabel\n"
4727 "%x_f = OpLoad %u32 %xvar\n"
4728 "%inloc_f = OpAccessChain %f32ptr %indata %zero %x_f\n"
4729 "%inval_f = OpLoad %f32 %inloc_f\n"
4730 "%negate = OpFNegate %f32 %inval_f\n"
4731 "%outloc_f = OpAccessChain %f32ptr %outdata %zero %x_f\n"
4732 " OpStore %outloc_f %negate\n"
4733 " OpBranch %if_merge\n"
4735 // Merge block for if-statement: placed in the middle of true and false branch.
4736 "%if_merge = OpLabel\n"
4739 // True branch for if-statement: placed in the middle of swtich cases and after the false branch.
4740 "%if_true = OpLabel\n"
4741 "%xval_t = OpLoad %u32 %xvar\n"
4742 "%mod = OpUMod %u32 %xval_t %const3\n"
4743 " OpSelectionMerge %switch_merge None\n"
4744 " OpSwitch %mod %default 0 %case0 1 %case1 2 %case2\n"
4746 // Merge block for switch-statement: placed before the case
4747 // bodies. But it must follow OpSwitch which dominates it.
4748 "%switch_merge = OpLabel\n"
4749 " OpBranch %if_merge\n"
4751 // Case 1 for switch-statement: placed before case 0.
4752 // It must follow the OpSwitch that dominates it.
4753 "%case1 = OpLabel\n"
4754 "%x_1 = OpLoad %u32 %xvar\n"
4755 "%inloc_1 = OpAccessChain %f32ptr %indata %zero %x_1\n"
4756 "%inval_1 = OpLoad %f32 %inloc_1\n"
4757 "%addf42 = OpFAdd %f32 %inval_1 %constf42\n"
4758 "%outloc_1 = OpAccessChain %f32ptr %outdata %zero %x_1\n"
4759 " OpStore %outloc_1 %addf42\n"
4760 " OpBranch %switch_merge\n"
4762 // Case 2 for switch-statement.
4763 "%case2 = OpLabel\n"
4764 "%x_2 = OpLoad %u32 %xvar\n"
4765 "%inloc_2 = OpAccessChain %f32ptr %indata %zero %x_2\n"
4766 "%inval_2 = OpLoad %f32 %inloc_2\n"
4767 "%subf27 = OpFSub %f32 %inval_2 %constf27\n"
4768 "%outloc_2 = OpAccessChain %f32ptr %outdata %zero %x_2\n"
4769 " OpStore %outloc_2 %subf27\n"
4770 " OpBranch %switch_merge\n"
4772 // Default case for switch-statement: placed in the middle of normal cases.
4773 "%default = OpLabel\n"
4774 " OpBranch %switch_merge\n"
4776 // Case 0 for switch-statement: out of order.
4777 "%case0 = OpLabel\n"
4778 "%x_0 = OpLoad %u32 %xvar\n"
4779 "%inloc_0 = OpAccessChain %f32ptr %indata %zero %x_0\n"
4780 "%inval_0 = OpLoad %f32 %inloc_0\n"
4781 "%addf1p5 = OpFAdd %f32 %inval_0 %constf1p5\n"
4782 "%outloc_0 = OpAccessChain %f32ptr %outdata %zero %x_0\n"
4783 " OpStore %outloc_0 %addf1p5\n"
4784 " OpBranch %switch_merge\n"
4787 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
4788 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
4789 spec.numWorkGroups = IVec3(numElements, 1, 1);
4791 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "various out-of-order blocks", spec));
4793 return group.release();
4796 tcu::TestCaseGroup* createMultipleShaderGroup (tcu::TestContext& testCtx)
4798 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "multiple_shaders", "Test multiple shaders in the same module"));
4799 ComputeShaderSpec spec1;
4800 ComputeShaderSpec spec2;
4801 de::Random rnd (deStringHash(group->getName()));
4802 const int numElements = 100;
4803 vector<float> inputFloats (numElements, 0);
4804 vector<float> outputFloats1 (numElements, 0);
4805 vector<float> outputFloats2 (numElements, 0);
4806 fillRandomScalars(rnd, -500.f, 500.f, &inputFloats[0], numElements);
4808 for (size_t ndx = 0; ndx < numElements; ++ndx)
4810 outputFloats1[ndx] = inputFloats[ndx] + inputFloats[ndx];
4811 outputFloats2[ndx] = -inputFloats[ndx];
4814 const string assembly(
4815 "OpCapability Shader\n"
4816 "OpMemoryModel Logical GLSL450\n"
4817 "OpEntryPoint GLCompute %comp_main1 \"entrypoint1\" %id\n"
4818 "OpEntryPoint GLCompute %comp_main2 \"entrypoint2\" %id\n"
4819 // A module cannot have two OpEntryPoint instructions with the same Execution Model and the same Name string.
4820 "OpEntryPoint Vertex %vert_main \"entrypoint2\" %vert_builtins %vertexIndex %instanceIndex\n"
4821 "OpExecutionMode %comp_main1 LocalSize 1 1 1\n"
4822 "OpExecutionMode %comp_main2 LocalSize 1 1 1\n"
4824 "OpName %comp_main1 \"entrypoint1\"\n"
4825 "OpName %comp_main2 \"entrypoint2\"\n"
4826 "OpName %vert_main \"entrypoint2\"\n"
4827 "OpName %id \"gl_GlobalInvocationID\"\n"
4828 "OpName %vert_builtin_st \"gl_PerVertex\"\n"
4829 "OpName %vertexIndex \"gl_VertexIndex\"\n"
4830 "OpName %instanceIndex \"gl_InstanceIndex\"\n"
4831 "OpMemberName %vert_builtin_st 0 \"gl_Position\"\n"
4832 "OpMemberName %vert_builtin_st 1 \"gl_PointSize\"\n"
4833 "OpMemberName %vert_builtin_st 2 \"gl_ClipDistance\"\n"
4835 "OpDecorate %id BuiltIn GlobalInvocationId\n"
4836 "OpDecorate %vertexIndex BuiltIn VertexIndex\n"
4837 "OpDecorate %instanceIndex BuiltIn InstanceIndex\n"
4838 "OpDecorate %vert_builtin_st Block\n"
4839 "OpMemberDecorate %vert_builtin_st 0 BuiltIn Position\n"
4840 "OpMemberDecorate %vert_builtin_st 1 BuiltIn PointSize\n"
4841 "OpMemberDecorate %vert_builtin_st 2 BuiltIn ClipDistance\n"
4843 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
4845 "%zero = OpConstant %i32 0\n"
4846 "%one = OpConstant %u32 1\n"
4847 "%c_f32_1 = OpConstant %f32 1\n"
4849 "%i32inputptr = OpTypePointer Input %i32\n"
4850 "%vec4 = OpTypeVector %f32 4\n"
4851 "%vec4ptr = OpTypePointer Output %vec4\n"
4852 "%f32arr1 = OpTypeArray %f32 %one\n"
4853 "%vert_builtin_st = OpTypeStruct %vec4 %f32 %f32arr1\n"
4854 "%vert_builtin_st_ptr = OpTypePointer Output %vert_builtin_st\n"
4855 "%vert_builtins = OpVariable %vert_builtin_st_ptr Output\n"
4857 "%id = OpVariable %uvec3ptr Input\n"
4858 "%vertexIndex = OpVariable %i32inputptr Input\n"
4859 "%instanceIndex = OpVariable %i32inputptr Input\n"
4860 "%c_vec4_1 = OpConstantComposite %vec4 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_1\n"
4862 // gl_Position = vec4(1.);
4863 "%vert_main = OpFunction %void None %voidf\n"
4864 "%vert_entry = OpLabel\n"
4865 "%position = OpAccessChain %vec4ptr %vert_builtins %zero\n"
4866 " OpStore %position %c_vec4_1\n"
4871 "%comp_main1 = OpFunction %void None %voidf\n"
4872 "%comp1_entry = OpLabel\n"
4873 "%idval1 = OpLoad %uvec3 %id\n"
4874 "%x1 = OpCompositeExtract %u32 %idval1 0\n"
4875 "%inloc1 = OpAccessChain %f32ptr %indata %zero %x1\n"
4876 "%inval1 = OpLoad %f32 %inloc1\n"
4877 "%add = OpFAdd %f32 %inval1 %inval1\n"
4878 "%outloc1 = OpAccessChain %f32ptr %outdata %zero %x1\n"
4879 " OpStore %outloc1 %add\n"
4884 "%comp_main2 = OpFunction %void None %voidf\n"
4885 "%comp2_entry = OpLabel\n"
4886 "%idval2 = OpLoad %uvec3 %id\n"
4887 "%x2 = OpCompositeExtract %u32 %idval2 0\n"
4888 "%inloc2 = OpAccessChain %f32ptr %indata %zero %x2\n"
4889 "%inval2 = OpLoad %f32 %inloc2\n"
4890 "%neg = OpFNegate %f32 %inval2\n"
4891 "%outloc2 = OpAccessChain %f32ptr %outdata %zero %x2\n"
4892 " OpStore %outloc2 %neg\n"
4894 " OpFunctionEnd\n");
4896 spec1.assembly = assembly;
4897 spec1.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
4898 spec1.outputs.push_back(BufferSp(new Float32Buffer(outputFloats1)));
4899 spec1.numWorkGroups = IVec3(numElements, 1, 1);
4900 spec1.entryPoint = "entrypoint1";
4902 spec2.assembly = assembly;
4903 spec2.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
4904 spec2.outputs.push_back(BufferSp(new Float32Buffer(outputFloats2)));
4905 spec2.numWorkGroups = IVec3(numElements, 1, 1);
4906 spec2.entryPoint = "entrypoint2";
4908 group->addChild(new SpvAsmComputeShaderCase(testCtx, "shader1", "multiple shaders in the same module", spec1));
4909 group->addChild(new SpvAsmComputeShaderCase(testCtx, "shader2", "multiple shaders in the same module", spec2));
4911 return group.release();
4914 inline std::string makeLongUTF8String (size_t num4ByteChars)
4916 // An example of a longest valid UTF-8 character. Be explicit about the
4917 // character type because Microsoft compilers can otherwise interpret the
4918 // character string as being over wide (16-bit) characters. Ideally, we
4919 // would just use a C++11 UTF-8 string literal, but we want to support older
4920 // Microsoft compilers.
4921 const std::basic_string<char> earthAfrica("\xF0\x9F\x8C\x8D");
4922 std::string longString;
4923 longString.reserve(num4ByteChars * 4);
4924 for (size_t count = 0; count < num4ByteChars; count++)
4926 longString += earthAfrica;
4931 tcu::TestCaseGroup* createOpSourceGroup (tcu::TestContext& testCtx)
4933 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opsource", "Tests the OpSource & OpSourceContinued instruction"));
4934 vector<CaseParameter> cases;
4935 de::Random rnd (deStringHash(group->getName()));
4936 const int numElements = 100;
4937 vector<float> positiveFloats (numElements, 0);
4938 vector<float> negativeFloats (numElements, 0);
4939 const StringTemplate shaderTemplate (
4940 "OpCapability Shader\n"
4941 "OpMemoryModel Logical GLSL450\n"
4943 "OpEntryPoint GLCompute %main \"main\" %id\n"
4944 "OpExecutionMode %main LocalSize 1 1 1\n"
4948 "OpName %main \"main\"\n"
4949 "OpName %id \"gl_GlobalInvocationID\"\n"
4951 "OpDecorate %id BuiltIn GlobalInvocationId\n"
4953 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
4955 "%id = OpVariable %uvec3ptr Input\n"
4956 "%zero = OpConstant %i32 0\n"
4958 "%main = OpFunction %void None %voidf\n"
4959 "%label = OpLabel\n"
4960 "%idval = OpLoad %uvec3 %id\n"
4961 "%x = OpCompositeExtract %u32 %idval 0\n"
4962 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
4963 "%inval = OpLoad %f32 %inloc\n"
4964 "%neg = OpFNegate %f32 %inval\n"
4965 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
4966 " OpStore %outloc %neg\n"
4968 " OpFunctionEnd\n");
4970 cases.push_back(CaseParameter("unknown_source", "OpSource Unknown 0"));
4971 cases.push_back(CaseParameter("wrong_source", "OpSource OpenCL_C 210"));
4972 cases.push_back(CaseParameter("normal_filename", "%fname = OpString \"filename\"\n"
4973 "OpSource GLSL 430 %fname"));
4974 cases.push_back(CaseParameter("empty_filename", "%fname = OpString \"\"\n"
4975 "OpSource GLSL 430 %fname"));
4976 cases.push_back(CaseParameter("normal_source_code", "%fname = OpString \"filename\"\n"
4977 "OpSource GLSL 430 %fname \"#version 430\nvoid main() {}\""));
4978 cases.push_back(CaseParameter("empty_source_code", "%fname = OpString \"filename\"\n"
4979 "OpSource GLSL 430 %fname \"\""));
4980 cases.push_back(CaseParameter("long_source_code", "%fname = OpString \"filename\"\n"
4981 "OpSource GLSL 430 %fname \"" + makeLongUTF8String(65530) + "ccc\"")); // word count: 65535
4982 cases.push_back(CaseParameter("utf8_source_code", "%fname = OpString \"filename\"\n"
4983 "OpSource GLSL 430 %fname \"\xE2\x98\x82\xE2\x98\x85\"")); // umbrella & black star symbol
4984 cases.push_back(CaseParameter("normal_sourcecontinued", "%fname = OpString \"filename\"\n"
4985 "OpSource GLSL 430 %fname \"#version 430\nvo\"\n"
4986 "OpSourceContinued \"id main() {}\""));
4987 cases.push_back(CaseParameter("empty_sourcecontinued", "%fname = OpString \"filename\"\n"
4988 "OpSource GLSL 430 %fname \"#version 430\nvoid main() {}\"\n"
4989 "OpSourceContinued \"\""));
4990 cases.push_back(CaseParameter("long_sourcecontinued", "%fname = OpString \"filename\"\n"
4991 "OpSource GLSL 430 %fname \"#version 430\nvoid main() {}\"\n"
4992 "OpSourceContinued \"" + makeLongUTF8String(65533) + "ccc\"")); // word count: 65535
4993 cases.push_back(CaseParameter("utf8_sourcecontinued", "%fname = OpString \"filename\"\n"
4994 "OpSource GLSL 430 %fname \"#version 430\nvoid main() {}\"\n"
4995 "OpSourceContinued \"\xE2\x98\x8E\xE2\x9A\x91\"")); // white telephone & black flag symbol
4996 cases.push_back(CaseParameter("multi_sourcecontinued", "%fname = OpString \"filename\"\n"
4997 "OpSource GLSL 430 %fname \"#version 430\n\"\n"
4998 "OpSourceContinued \"void\"\n"
4999 "OpSourceContinued \"main()\"\n"
5000 "OpSourceContinued \"{}\""));
5001 cases.push_back(CaseParameter("empty_source_before_sourcecontinued", "%fname = OpString \"filename\"\n"
5002 "OpSource GLSL 430 %fname \"\"\n"
5003 "OpSourceContinued \"#version 430\nvoid main() {}\""));
5005 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
5007 for (size_t ndx = 0; ndx < numElements; ++ndx)
5008 negativeFloats[ndx] = -positiveFloats[ndx];
5010 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
5012 map<string, string> specializations;
5013 ComputeShaderSpec spec;
5015 specializations["SOURCE"] = cases[caseNdx].param;
5016 spec.assembly = shaderTemplate.specialize(specializations);
5017 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
5018 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
5019 spec.numWorkGroups = IVec3(numElements, 1, 1);
5021 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
5024 return group.release();
5027 tcu::TestCaseGroup* createOpSourceExtensionGroup (tcu::TestContext& testCtx)
5029 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opsourceextension", "Tests the OpSource instruction"));
5030 vector<CaseParameter> cases;
5031 de::Random rnd (deStringHash(group->getName()));
5032 const int numElements = 100;
5033 vector<float> inputFloats (numElements, 0);
5034 vector<float> outputFloats (numElements, 0);
5035 const StringTemplate shaderTemplate (
5036 string(getComputeAsmShaderPreamble()) +
5038 "OpSourceExtension \"${EXTENSION}\"\n"
5040 "OpName %main \"main\"\n"
5041 "OpName %id \"gl_GlobalInvocationID\"\n"
5043 "OpDecorate %id BuiltIn GlobalInvocationId\n"
5045 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
5047 "%id = OpVariable %uvec3ptr Input\n"
5048 "%zero = OpConstant %i32 0\n"
5050 "%main = OpFunction %void None %voidf\n"
5051 "%label = OpLabel\n"
5052 "%idval = OpLoad %uvec3 %id\n"
5053 "%x = OpCompositeExtract %u32 %idval 0\n"
5054 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
5055 "%inval = OpLoad %f32 %inloc\n"
5056 "%neg = OpFNegate %f32 %inval\n"
5057 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
5058 " OpStore %outloc %neg\n"
5060 " OpFunctionEnd\n");
5062 cases.push_back(CaseParameter("empty_extension", ""));
5063 cases.push_back(CaseParameter("real_extension", "GL_ARB_texture_rectangle"));
5064 cases.push_back(CaseParameter("fake_extension", "GL_ARB_im_the_ultimate_extension"));
5065 cases.push_back(CaseParameter("utf8_extension", "GL_ARB_\xE2\x98\x82\xE2\x98\x85"));
5066 cases.push_back(CaseParameter("long_extension", makeLongUTF8String(65533) + "ccc")); // word count: 65535
5068 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats[0], numElements);
5070 for (size_t ndx = 0; ndx < numElements; ++ndx)
5071 outputFloats[ndx] = -inputFloats[ndx];
5073 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
5075 map<string, string> specializations;
5076 ComputeShaderSpec spec;
5078 specializations["EXTENSION"] = cases[caseNdx].param;
5079 spec.assembly = shaderTemplate.specialize(specializations);
5080 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
5081 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
5082 spec.numWorkGroups = IVec3(numElements, 1, 1);
5084 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
5087 return group.release();
5090 // Checks that a compute shader can generate a constant null value of various types, without exercising a computation on it.
5091 tcu::TestCaseGroup* createOpConstantNullGroup (tcu::TestContext& testCtx)
5093 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opconstantnull", "Tests the OpConstantNull instruction"));
5094 vector<CaseParameter> cases;
5095 de::Random rnd (deStringHash(group->getName()));
5096 const int numElements = 100;
5097 vector<float> positiveFloats (numElements, 0);
5098 vector<float> negativeFloats (numElements, 0);
5099 const StringTemplate shaderTemplate (
5100 string(getComputeAsmShaderPreamble()) +
5102 "OpSource GLSL 430\n"
5103 "OpName %main \"main\"\n"
5104 "OpName %id \"gl_GlobalInvocationID\"\n"
5106 "OpDecorate %id BuiltIn GlobalInvocationId\n"
5108 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
5109 "%uvec2 = OpTypeVector %u32 2\n"
5110 "%bvec3 = OpTypeVector %bool 3\n"
5111 "%fvec4 = OpTypeVector %f32 4\n"
5112 "%fmat33 = OpTypeMatrix %fvec3 3\n"
5113 "%const100 = OpConstant %u32 100\n"
5114 "%uarr100 = OpTypeArray %i32 %const100\n"
5115 "%struct = OpTypeStruct %f32 %i32 %u32\n"
5116 "%pointer = OpTypePointer Function %i32\n"
5117 + string(getComputeAsmInputOutputBuffer()) +
5119 "%null = OpConstantNull ${TYPE}\n"
5121 "%id = OpVariable %uvec3ptr Input\n"
5122 "%zero = OpConstant %i32 0\n"
5124 "%main = OpFunction %void None %voidf\n"
5125 "%label = OpLabel\n"
5126 "%idval = OpLoad %uvec3 %id\n"
5127 "%x = OpCompositeExtract %u32 %idval 0\n"
5128 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
5129 "%inval = OpLoad %f32 %inloc\n"
5130 "%neg = OpFNegate %f32 %inval\n"
5131 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
5132 " OpStore %outloc %neg\n"
5134 " OpFunctionEnd\n");
5136 cases.push_back(CaseParameter("bool", "%bool"));
5137 cases.push_back(CaseParameter("sint32", "%i32"));
5138 cases.push_back(CaseParameter("uint32", "%u32"));
5139 cases.push_back(CaseParameter("float32", "%f32"));
5140 cases.push_back(CaseParameter("vec4float32", "%fvec4"));
5141 cases.push_back(CaseParameter("vec3bool", "%bvec3"));
5142 cases.push_back(CaseParameter("vec2uint32", "%uvec2"));
5143 cases.push_back(CaseParameter("matrix", "%fmat33"));
5144 cases.push_back(CaseParameter("array", "%uarr100"));
5145 cases.push_back(CaseParameter("struct", "%struct"));
5146 cases.push_back(CaseParameter("pointer", "%pointer"));
5148 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
5150 for (size_t ndx = 0; ndx < numElements; ++ndx)
5151 negativeFloats[ndx] = -positiveFloats[ndx];
5153 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
5155 map<string, string> specializations;
5156 ComputeShaderSpec spec;
5158 specializations["TYPE"] = cases[caseNdx].param;
5159 spec.assembly = shaderTemplate.specialize(specializations);
5160 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
5161 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
5162 spec.numWorkGroups = IVec3(numElements, 1, 1);
5164 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
5167 return group.release();
5170 // Checks that a compute shader can generate a constant composite value of various types, without exercising a computation on it.
5171 tcu::TestCaseGroup* createOpConstantCompositeGroup (tcu::TestContext& testCtx)
5173 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opconstantcomposite", "Tests the OpConstantComposite instruction"));
5174 vector<CaseParameter> cases;
5175 de::Random rnd (deStringHash(group->getName()));
5176 const int numElements = 100;
5177 vector<float> positiveFloats (numElements, 0);
5178 vector<float> negativeFloats (numElements, 0);
5179 const StringTemplate shaderTemplate (
5180 string(getComputeAsmShaderPreamble()) +
5182 "OpSource GLSL 430\n"
5183 "OpName %main \"main\"\n"
5184 "OpName %id \"gl_GlobalInvocationID\"\n"
5186 "OpDecorate %id BuiltIn GlobalInvocationId\n"
5188 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
5190 "%id = OpVariable %uvec3ptr Input\n"
5191 "%zero = OpConstant %i32 0\n"
5195 "%main = OpFunction %void None %voidf\n"
5196 "%label = OpLabel\n"
5197 "%idval = OpLoad %uvec3 %id\n"
5198 "%x = OpCompositeExtract %u32 %idval 0\n"
5199 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
5200 "%inval = OpLoad %f32 %inloc\n"
5201 "%neg = OpFNegate %f32 %inval\n"
5202 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
5203 " OpStore %outloc %neg\n"
5205 " OpFunctionEnd\n");
5207 cases.push_back(CaseParameter("vector", "%five = OpConstant %u32 5\n"
5208 "%const = OpConstantComposite %uvec3 %five %zero %five"));
5209 cases.push_back(CaseParameter("matrix", "%m3fvec3 = OpTypeMatrix %fvec3 3\n"
5210 "%ten = OpConstant %f32 10.\n"
5211 "%fzero = OpConstant %f32 0.\n"
5212 "%vec = OpConstantComposite %fvec3 %ten %fzero %ten\n"
5213 "%mat = OpConstantComposite %m3fvec3 %vec %vec %vec"));
5214 cases.push_back(CaseParameter("struct", "%m2vec3 = OpTypeMatrix %fvec3 2\n"
5215 "%struct = OpTypeStruct %i32 %f32 %fvec3 %m2vec3\n"
5216 "%fzero = OpConstant %f32 0.\n"
5217 "%one = OpConstant %f32 1.\n"
5218 "%point5 = OpConstant %f32 0.5\n"
5219 "%vec = OpConstantComposite %fvec3 %one %one %fzero\n"
5220 "%mat = OpConstantComposite %m2vec3 %vec %vec\n"
5221 "%const = OpConstantComposite %struct %zero %point5 %vec %mat"));
5222 cases.push_back(CaseParameter("nested_struct", "%st1 = OpTypeStruct %u32 %f32\n"
5223 "%st2 = OpTypeStruct %i32 %i32\n"
5224 "%struct = OpTypeStruct %st1 %st2\n"
5225 "%point5 = OpConstant %f32 0.5\n"
5226 "%one = OpConstant %u32 1\n"
5227 "%ten = OpConstant %i32 10\n"
5228 "%st1val = OpConstantComposite %st1 %one %point5\n"
5229 "%st2val = OpConstantComposite %st2 %ten %ten\n"
5230 "%const = OpConstantComposite %struct %st1val %st2val"));
5232 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
5234 for (size_t ndx = 0; ndx < numElements; ++ndx)
5235 negativeFloats[ndx] = -positiveFloats[ndx];
5237 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
5239 map<string, string> specializations;
5240 ComputeShaderSpec spec;
5242 specializations["CONSTANT"] = cases[caseNdx].param;
5243 spec.assembly = shaderTemplate.specialize(specializations);
5244 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
5245 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
5246 spec.numWorkGroups = IVec3(numElements, 1, 1);
5248 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
5251 return group.release();
5254 // Creates a floating point number with the given exponent, and significand
5255 // bits set. It can only create normalized numbers. Only the least significant
5256 // 24 bits of the significand will be examined. The final bit of the
5257 // significand will also be ignored. This allows alignment to be written
5258 // similarly to C99 hex-floats.
5259 // For example if you wanted to write 0x1.7f34p-12 you would call
5260 // constructNormalizedFloat(-12, 0x7f3400)
5261 float constructNormalizedFloat (deInt32 exponent, deUint32 significand)
5265 for (deInt32 idx = 0; idx < 23; ++idx)
5267 f += ((significand & 0x800000) == 0) ? 0.f : std::ldexp(1.0f, -(idx + 1));
5271 return std::ldexp(f, exponent);
5274 // Compare instruction for the OpQuantizeF16 compute exact case.
5275 // Returns true if the output is what is expected from the test case.
5276 bool compareOpQuantizeF16ComputeExactCase (const std::vector<Resource>&, const vector<AllocationSp>& outputAllocs, const std::vector<Resource>& expectedOutputs, TestLog&)
5278 if (outputAllocs.size() != 1)
5281 // Only size is needed because we cannot compare Nans.
5282 size_t byteSize = expectedOutputs[0].getByteSize();
5284 const float* outputAsFloat = static_cast<const float*>(outputAllocs[0]->getHostPtr());
5286 if (byteSize != 4*sizeof(float)) {
5290 if (*outputAsFloat != constructNormalizedFloat(8, 0x304000) &&
5291 *outputAsFloat != constructNormalizedFloat(8, 0x300000)) {
5296 if (*outputAsFloat != -constructNormalizedFloat(-7, 0x600000) &&
5297 *outputAsFloat != -constructNormalizedFloat(-7, 0x604000)) {
5302 if (*outputAsFloat != constructNormalizedFloat(2, 0x01C000) &&
5303 *outputAsFloat != constructNormalizedFloat(2, 0x020000)) {
5308 if (*outputAsFloat != constructNormalizedFloat(1, 0xFFC000) &&
5309 *outputAsFloat != constructNormalizedFloat(2, 0x000000)) {
5316 // Checks that every output from a test-case is a float NaN.
5317 bool compareNan (const std::vector<Resource>&, const vector<AllocationSp>& outputAllocs, const std::vector<Resource>& expectedOutputs, TestLog&)
5319 if (outputAllocs.size() != 1)
5322 // Only size is needed because we cannot compare Nans.
5323 size_t byteSize = expectedOutputs[0].getByteSize();
5325 const float* const output_as_float = static_cast<const float*>(outputAllocs[0]->getHostPtr());
5327 for (size_t idx = 0; idx < byteSize / sizeof(float); ++idx)
5329 if (!deFloatIsNaN(output_as_float[idx]))
5338 // Checks that a compute shader can generate a constant composite value of various types, without exercising a computation on it.
5339 tcu::TestCaseGroup* createOpQuantizeToF16Group (tcu::TestContext& testCtx)
5341 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opquantize", "Tests the OpQuantizeToF16 instruction"));
5343 const std::string shader (
5344 string(getComputeAsmShaderPreamble()) +
5346 "OpSource GLSL 430\n"
5347 "OpName %main \"main\"\n"
5348 "OpName %id \"gl_GlobalInvocationID\"\n"
5350 "OpDecorate %id BuiltIn GlobalInvocationId\n"
5352 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
5354 "%id = OpVariable %uvec3ptr Input\n"
5355 "%zero = OpConstant %i32 0\n"
5357 "%main = OpFunction %void None %voidf\n"
5358 "%label = OpLabel\n"
5359 "%idval = OpLoad %uvec3 %id\n"
5360 "%x = OpCompositeExtract %u32 %idval 0\n"
5361 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
5362 "%inval = OpLoad %f32 %inloc\n"
5363 "%quant = OpQuantizeToF16 %f32 %inval\n"
5364 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
5365 " OpStore %outloc %quant\n"
5367 " OpFunctionEnd\n");
5370 ComputeShaderSpec spec;
5371 const deUint32 numElements = 100;
5372 vector<float> infinities;
5373 vector<float> results;
5375 infinities.reserve(numElements);
5376 results.reserve(numElements);
5378 for (size_t idx = 0; idx < numElements; ++idx)
5383 infinities.push_back(std::numeric_limits<float>::infinity());
5384 results.push_back(std::numeric_limits<float>::infinity());
5387 infinities.push_back(-std::numeric_limits<float>::infinity());
5388 results.push_back(-std::numeric_limits<float>::infinity());
5391 infinities.push_back(std::ldexp(1.0f, 16));
5392 results.push_back(std::numeric_limits<float>::infinity());
5395 infinities.push_back(std::ldexp(-1.0f, 32));
5396 results.push_back(-std::numeric_limits<float>::infinity());
5401 spec.assembly = shader;
5402 spec.inputs.push_back(BufferSp(new Float32Buffer(infinities)));
5403 spec.outputs.push_back(BufferSp(new Float32Buffer(results)));
5404 spec.numWorkGroups = IVec3(numElements, 1, 1);
5406 group->addChild(new SpvAsmComputeShaderCase(
5407 testCtx, "infinities", "Check that infinities propagated and created", spec));
5411 ComputeShaderSpec spec;
5413 const deUint32 numElements = 100;
5415 nans.reserve(numElements);
5417 for (size_t idx = 0; idx < numElements; ++idx)
5421 nans.push_back(std::numeric_limits<float>::quiet_NaN());
5425 nans.push_back(-std::numeric_limits<float>::quiet_NaN());
5429 spec.assembly = shader;
5430 spec.inputs.push_back(BufferSp(new Float32Buffer(nans)));
5431 spec.outputs.push_back(BufferSp(new Float32Buffer(nans)));
5432 spec.numWorkGroups = IVec3(numElements, 1, 1);
5433 spec.verifyIO = &compareNan;
5435 group->addChild(new SpvAsmComputeShaderCase(
5436 testCtx, "propagated_nans", "Check that nans are propagated", spec));
5440 ComputeShaderSpec spec;
5441 vector<float> small;
5442 vector<float> zeros;
5443 const deUint32 numElements = 100;
5445 small.reserve(numElements);
5446 zeros.reserve(numElements);
5448 for (size_t idx = 0; idx < numElements; ++idx)
5453 small.push_back(0.f);
5454 zeros.push_back(0.f);
5457 small.push_back(-0.f);
5458 zeros.push_back(-0.f);
5461 small.push_back(std::ldexp(1.0f, -16));
5462 zeros.push_back(0.f);
5465 small.push_back(std::ldexp(-1.0f, -32));
5466 zeros.push_back(-0.f);
5469 small.push_back(std::ldexp(1.0f, -127));
5470 zeros.push_back(0.f);
5473 small.push_back(-std::ldexp(1.0f, -128));
5474 zeros.push_back(-0.f);
5479 spec.assembly = shader;
5480 spec.inputs.push_back(BufferSp(new Float32Buffer(small)));
5481 spec.outputs.push_back(BufferSp(new Float32Buffer(zeros)));
5482 spec.numWorkGroups = IVec3(numElements, 1, 1);
5484 group->addChild(new SpvAsmComputeShaderCase(
5485 testCtx, "flush_to_zero", "Check that values are zeroed correctly", spec));
5489 ComputeShaderSpec spec;
5490 vector<float> exact;
5491 const deUint32 numElements = 200;
5493 exact.reserve(numElements);
5495 for (size_t idx = 0; idx < numElements; ++idx)
5496 exact.push_back(static_cast<float>(static_cast<int>(idx) - 100));
5498 spec.assembly = shader;
5499 spec.inputs.push_back(BufferSp(new Float32Buffer(exact)));
5500 spec.outputs.push_back(BufferSp(new Float32Buffer(exact)));
5501 spec.numWorkGroups = IVec3(numElements, 1, 1);
5503 group->addChild(new SpvAsmComputeShaderCase(
5504 testCtx, "exact", "Check that values exactly preserved where appropriate", spec));
5508 ComputeShaderSpec spec;
5509 vector<float> inputs;
5510 const deUint32 numElements = 4;
5512 inputs.push_back(constructNormalizedFloat(8, 0x300300));
5513 inputs.push_back(-constructNormalizedFloat(-7, 0x600800));
5514 inputs.push_back(constructNormalizedFloat(2, 0x01E000));
5515 inputs.push_back(constructNormalizedFloat(1, 0xFFE000));
5517 spec.assembly = shader;
5518 spec.verifyIO = &compareOpQuantizeF16ComputeExactCase;
5519 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs)));
5520 spec.outputs.push_back(BufferSp(new Float32Buffer(inputs)));
5521 spec.numWorkGroups = IVec3(numElements, 1, 1);
5523 group->addChild(new SpvAsmComputeShaderCase(
5524 testCtx, "rounded", "Check that are rounded when needed", spec));
5527 return group.release();
5530 tcu::TestCaseGroup* createSpecConstantOpQuantizeToF16Group (tcu::TestContext& testCtx)
5532 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opspecconstantop_opquantize", "Tests the OpQuantizeToF16 opcode for the OpSpecConstantOp instruction"));
5534 const std::string shader (
5535 string(getComputeAsmShaderPreamble()) +
5537 "OpName %main \"main\"\n"
5538 "OpName %id \"gl_GlobalInvocationID\"\n"
5540 "OpDecorate %id BuiltIn GlobalInvocationId\n"
5542 "OpDecorate %sc_0 SpecId 0\n"
5543 "OpDecorate %sc_1 SpecId 1\n"
5544 "OpDecorate %sc_2 SpecId 2\n"
5545 "OpDecorate %sc_3 SpecId 3\n"
5546 "OpDecorate %sc_4 SpecId 4\n"
5547 "OpDecorate %sc_5 SpecId 5\n"
5549 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
5551 "%id = OpVariable %uvec3ptr Input\n"
5552 "%zero = OpConstant %i32 0\n"
5553 "%c_u32_6 = OpConstant %u32 6\n"
5555 "%sc_0 = OpSpecConstant %f32 0.\n"
5556 "%sc_1 = OpSpecConstant %f32 0.\n"
5557 "%sc_2 = OpSpecConstant %f32 0.\n"
5558 "%sc_3 = OpSpecConstant %f32 0.\n"
5559 "%sc_4 = OpSpecConstant %f32 0.\n"
5560 "%sc_5 = OpSpecConstant %f32 0.\n"
5562 "%sc_0_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_0\n"
5563 "%sc_1_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_1\n"
5564 "%sc_2_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_2\n"
5565 "%sc_3_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_3\n"
5566 "%sc_4_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_4\n"
5567 "%sc_5_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_5\n"
5569 "%main = OpFunction %void None %voidf\n"
5570 "%label = OpLabel\n"
5571 "%idval = OpLoad %uvec3 %id\n"
5572 "%x = OpCompositeExtract %u32 %idval 0\n"
5573 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
5574 "%selector = OpUMod %u32 %x %c_u32_6\n"
5575 " OpSelectionMerge %exit None\n"
5576 " OpSwitch %selector %exit 0 %case0 1 %case1 2 %case2 3 %case3 4 %case4 5 %case5\n"
5578 "%case0 = OpLabel\n"
5579 " OpStore %outloc %sc_0_quant\n"
5582 "%case1 = OpLabel\n"
5583 " OpStore %outloc %sc_1_quant\n"
5586 "%case2 = OpLabel\n"
5587 " OpStore %outloc %sc_2_quant\n"
5590 "%case3 = OpLabel\n"
5591 " OpStore %outloc %sc_3_quant\n"
5594 "%case4 = OpLabel\n"
5595 " OpStore %outloc %sc_4_quant\n"
5598 "%case5 = OpLabel\n"
5599 " OpStore %outloc %sc_5_quant\n"
5605 " OpFunctionEnd\n");
5608 ComputeShaderSpec spec;
5609 const deUint8 numCases = 4;
5610 vector<float> inputs (numCases, 0.f);
5611 vector<float> outputs;
5613 spec.assembly = shader;
5614 spec.numWorkGroups = IVec3(numCases, 1, 1);
5616 spec.specConstants.append<deInt32>(bitwiseCast<deUint32>(std::numeric_limits<float>::infinity()));
5617 spec.specConstants.append<deInt32>(bitwiseCast<deUint32>(-std::numeric_limits<float>::infinity()));
5618 spec.specConstants.append<deInt32>(bitwiseCast<deUint32>(std::ldexp(1.0f, 16)));
5619 spec.specConstants.append<deInt32>(bitwiseCast<deUint32>(std::ldexp(-1.0f, 32)));
5621 outputs.push_back(std::numeric_limits<float>::infinity());
5622 outputs.push_back(-std::numeric_limits<float>::infinity());
5623 outputs.push_back(std::numeric_limits<float>::infinity());
5624 outputs.push_back(-std::numeric_limits<float>::infinity());
5626 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs)));
5627 spec.outputs.push_back(BufferSp(new Float32Buffer(outputs)));
5629 group->addChild(new SpvAsmComputeShaderCase(
5630 testCtx, "infinities", "Check that infinities propagated and created", spec));
5634 ComputeShaderSpec spec;
5635 const deUint8 numCases = 2;
5636 vector<float> inputs (numCases, 0.f);
5637 vector<float> outputs;
5639 spec.assembly = shader;
5640 spec.numWorkGroups = IVec3(numCases, 1, 1);
5641 spec.verifyIO = &compareNan;
5643 outputs.push_back(std::numeric_limits<float>::quiet_NaN());
5644 outputs.push_back(-std::numeric_limits<float>::quiet_NaN());
5646 for (deUint8 idx = 0; idx < numCases; ++idx)
5647 spec.specConstants.append<deInt32>(bitwiseCast<deUint32>(outputs[idx]));
5649 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs)));
5650 spec.outputs.push_back(BufferSp(new Float32Buffer(outputs)));
5652 group->addChild(new SpvAsmComputeShaderCase(
5653 testCtx, "propagated_nans", "Check that nans are propagated", spec));
5657 ComputeShaderSpec spec;
5658 const deUint8 numCases = 6;
5659 vector<float> inputs (numCases, 0.f);
5660 vector<float> outputs;
5662 spec.assembly = shader;
5663 spec.numWorkGroups = IVec3(numCases, 1, 1);
5665 spec.specConstants.append<deInt32>(bitwiseCast<deUint32>(0.f));
5666 spec.specConstants.append<deInt32>(bitwiseCast<deUint32>(-0.f));
5667 spec.specConstants.append<deInt32>(bitwiseCast<deUint32>(std::ldexp(1.0f, -16)));
5668 spec.specConstants.append<deInt32>(bitwiseCast<deUint32>(std::ldexp(-1.0f, -32)));
5669 spec.specConstants.append<deInt32>(bitwiseCast<deUint32>(std::ldexp(1.0f, -127)));
5670 spec.specConstants.append<deInt32>(bitwiseCast<deUint32>(-std::ldexp(1.0f, -128)));
5672 outputs.push_back(0.f);
5673 outputs.push_back(-0.f);
5674 outputs.push_back(0.f);
5675 outputs.push_back(-0.f);
5676 outputs.push_back(0.f);
5677 outputs.push_back(-0.f);
5679 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs)));
5680 spec.outputs.push_back(BufferSp(new Float32Buffer(outputs)));
5682 group->addChild(new SpvAsmComputeShaderCase(
5683 testCtx, "flush_to_zero", "Check that values are zeroed correctly", spec));
5687 ComputeShaderSpec spec;
5688 const deUint8 numCases = 6;
5689 vector<float> inputs (numCases, 0.f);
5690 vector<float> outputs;
5692 spec.assembly = shader;
5693 spec.numWorkGroups = IVec3(numCases, 1, 1);
5695 for (deUint8 idx = 0; idx < 6; ++idx)
5697 const float f = static_cast<float>(idx * 10 - 30) / 4.f;
5698 spec.specConstants.append<deInt32>(bitwiseCast<deUint32>(f));
5699 outputs.push_back(f);
5702 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs)));
5703 spec.outputs.push_back(BufferSp(new Float32Buffer(outputs)));
5705 group->addChild(new SpvAsmComputeShaderCase(
5706 testCtx, "exact", "Check that values exactly preserved where appropriate", spec));
5710 ComputeShaderSpec spec;
5711 const deUint8 numCases = 4;
5712 vector<float> inputs (numCases, 0.f);
5713 vector<float> outputs;
5715 spec.assembly = shader;
5716 spec.numWorkGroups = IVec3(numCases, 1, 1);
5717 spec.verifyIO = &compareOpQuantizeF16ComputeExactCase;
5719 outputs.push_back(constructNormalizedFloat(8, 0x300300));
5720 outputs.push_back(-constructNormalizedFloat(-7, 0x600800));
5721 outputs.push_back(constructNormalizedFloat(2, 0x01E000));
5722 outputs.push_back(constructNormalizedFloat(1, 0xFFE000));
5724 for (deUint8 idx = 0; idx < numCases; ++idx)
5725 spec.specConstants.append<deInt32>(bitwiseCast<deUint32>(outputs[idx]));
5727 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs)));
5728 spec.outputs.push_back(BufferSp(new Float32Buffer(outputs)));
5730 group->addChild(new SpvAsmComputeShaderCase(
5731 testCtx, "rounded", "Check that are rounded when needed", spec));
5734 return group.release();
5737 // Checks that constant null/composite values can be used in computation.
5738 tcu::TestCaseGroup* createOpConstantUsageGroup (tcu::TestContext& testCtx)
5740 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opconstantnullcomposite", "Spotcheck the OpConstantNull & OpConstantComposite instruction"));
5741 ComputeShaderSpec spec;
5742 de::Random rnd (deStringHash(group->getName()));
5743 const int numElements = 100;
5744 vector<float> positiveFloats (numElements, 0);
5745 vector<float> negativeFloats (numElements, 0);
5747 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
5749 for (size_t ndx = 0; ndx < numElements; ++ndx)
5750 negativeFloats[ndx] = -positiveFloats[ndx];
5753 "OpCapability Shader\n"
5754 "%std450 = OpExtInstImport \"GLSL.std.450\"\n"
5755 "OpMemoryModel Logical GLSL450\n"
5756 "OpEntryPoint GLCompute %main \"main\" %id\n"
5757 "OpExecutionMode %main LocalSize 1 1 1\n"
5759 "OpSource GLSL 430\n"
5760 "OpName %main \"main\"\n"
5761 "OpName %id \"gl_GlobalInvocationID\"\n"
5763 "OpDecorate %id BuiltIn GlobalInvocationId\n"
5765 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
5767 "%fmat = OpTypeMatrix %fvec3 3\n"
5768 "%ten = OpConstant %u32 10\n"
5769 "%f32arr10 = OpTypeArray %f32 %ten\n"
5770 "%fst = OpTypeStruct %f32 %f32\n"
5772 + string(getComputeAsmInputOutputBuffer()) +
5774 "%id = OpVariable %uvec3ptr Input\n"
5775 "%zero = OpConstant %i32 0\n"
5777 // Create a bunch of null values
5778 "%unull = OpConstantNull %u32\n"
5779 "%fnull = OpConstantNull %f32\n"
5780 "%vnull = OpConstantNull %fvec3\n"
5781 "%mnull = OpConstantNull %fmat\n"
5782 "%anull = OpConstantNull %f32arr10\n"
5783 "%snull = OpConstantComposite %fst %fnull %fnull\n"
5785 "%main = OpFunction %void None %voidf\n"
5786 "%label = OpLabel\n"
5787 "%idval = OpLoad %uvec3 %id\n"
5788 "%x = OpCompositeExtract %u32 %idval 0\n"
5789 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
5790 "%inval = OpLoad %f32 %inloc\n"
5791 "%neg = OpFNegate %f32 %inval\n"
5793 // Get the abs() of (a certain element of) those null values
5794 "%unull_cov = OpConvertUToF %f32 %unull\n"
5795 "%unull_abs = OpExtInst %f32 %std450 FAbs %unull_cov\n"
5796 "%fnull_abs = OpExtInst %f32 %std450 FAbs %fnull\n"
5797 "%vnull_0 = OpCompositeExtract %f32 %vnull 0\n"
5798 "%vnull_abs = OpExtInst %f32 %std450 FAbs %vnull_0\n"
5799 "%mnull_12 = OpCompositeExtract %f32 %mnull 1 2\n"
5800 "%mnull_abs = OpExtInst %f32 %std450 FAbs %mnull_12\n"
5801 "%anull_3 = OpCompositeExtract %f32 %anull 3\n"
5802 "%anull_abs = OpExtInst %f32 %std450 FAbs %anull_3\n"
5803 "%snull_1 = OpCompositeExtract %f32 %snull 1\n"
5804 "%snull_abs = OpExtInst %f32 %std450 FAbs %snull_1\n"
5807 "%add1 = OpFAdd %f32 %neg %unull_abs\n"
5808 "%add2 = OpFAdd %f32 %add1 %fnull_abs\n"
5809 "%add3 = OpFAdd %f32 %add2 %vnull_abs\n"
5810 "%add4 = OpFAdd %f32 %add3 %mnull_abs\n"
5811 "%add5 = OpFAdd %f32 %add4 %anull_abs\n"
5812 "%final = OpFAdd %f32 %add5 %snull_abs\n"
5814 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
5815 " OpStore %outloc %final\n" // write to output
5818 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
5819 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
5820 spec.numWorkGroups = IVec3(numElements, 1, 1);
5822 group->addChild(new SpvAsmComputeShaderCase(testCtx, "spotcheck", "Check that values constructed via OpConstantNull & OpConstantComposite can be used", spec));
5824 return group.release();
5827 // Assembly code used for testing loop control is based on GLSL source code:
5830 // layout(std140, set = 0, binding = 0) readonly buffer Input {
5831 // float elements[];
5833 // layout(std140, set = 0, binding = 1) writeonly buffer Output {
5834 // float elements[];
5838 // uint x = gl_GlobalInvocationID.x;
5839 // output_data.elements[x] = input_data.elements[x];
5840 // for (uint i = 0; i < 4; ++i)
5841 // output_data.elements[x] += 1.f;
5843 tcu::TestCaseGroup* createLoopControlGroup (tcu::TestContext& testCtx)
5845 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "loop_control", "Tests loop control cases"));
5846 vector<CaseParameter> cases;
5847 de::Random rnd (deStringHash(group->getName()));
5848 const int numElements = 100;
5849 vector<float> inputFloats (numElements, 0);
5850 vector<float> outputFloats (numElements, 0);
5851 const StringTemplate shaderTemplate (
5852 string(getComputeAsmShaderPreamble()) +
5854 "OpSource GLSL 430\n"
5855 "OpName %main \"main\"\n"
5856 "OpName %id \"gl_GlobalInvocationID\"\n"
5858 "OpDecorate %id BuiltIn GlobalInvocationId\n"
5860 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
5862 "%u32ptr = OpTypePointer Function %u32\n"
5864 "%id = OpVariable %uvec3ptr Input\n"
5865 "%zero = OpConstant %i32 0\n"
5866 "%uzero = OpConstant %u32 0\n"
5867 "%one = OpConstant %i32 1\n"
5868 "%constf1 = OpConstant %f32 1.0\n"
5869 "%four = OpConstant %u32 4\n"
5871 "%main = OpFunction %void None %voidf\n"
5872 "%entry = OpLabel\n"
5873 "%i = OpVariable %u32ptr Function\n"
5874 " OpStore %i %uzero\n"
5876 "%idval = OpLoad %uvec3 %id\n"
5877 "%x = OpCompositeExtract %u32 %idval 0\n"
5878 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
5879 "%inval = OpLoad %f32 %inloc\n"
5880 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
5881 " OpStore %outloc %inval\n"
5882 " OpBranch %loop_entry\n"
5884 "%loop_entry = OpLabel\n"
5885 "%i_val = OpLoad %u32 %i\n"
5886 "%cmp_lt = OpULessThan %bool %i_val %four\n"
5887 " OpLoopMerge %loop_merge %loop_body ${CONTROL}\n"
5888 " OpBranchConditional %cmp_lt %loop_body %loop_merge\n"
5889 "%loop_body = OpLabel\n"
5890 "%outval = OpLoad %f32 %outloc\n"
5891 "%addf1 = OpFAdd %f32 %outval %constf1\n"
5892 " OpStore %outloc %addf1\n"
5893 "%new_i = OpIAdd %u32 %i_val %one\n"
5894 " OpStore %i %new_i\n"
5895 " OpBranch %loop_entry\n"
5896 "%loop_merge = OpLabel\n"
5898 " OpFunctionEnd\n");
5900 cases.push_back(CaseParameter("none", "None"));
5901 cases.push_back(CaseParameter("unroll", "Unroll"));
5902 cases.push_back(CaseParameter("dont_unroll", "DontUnroll"));
5904 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats[0], numElements);
5906 for (size_t ndx = 0; ndx < numElements; ++ndx)
5907 outputFloats[ndx] = inputFloats[ndx] + 4.f;
5909 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
5911 map<string, string> specializations;
5912 ComputeShaderSpec spec;
5914 specializations["CONTROL"] = cases[caseNdx].param;
5915 spec.assembly = shaderTemplate.specialize(specializations);
5916 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
5917 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
5918 spec.numWorkGroups = IVec3(numElements, 1, 1);
5920 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
5923 group->addChild(new SpvAsmLoopControlDependencyLengthCase(testCtx, "dependency_length", "dependency_length"));
5924 group->addChild(new SpvAsmLoopControlDependencyInfiniteCase(testCtx, "dependency_infinite", "dependency_infinite"));
5926 return group.release();
5929 // Assembly code used for testing selection control is based on GLSL source code:
5932 // layout(std140, set = 0, binding = 0) readonly buffer Input {
5933 // float elements[];
5935 // layout(std140, set = 0, binding = 1) writeonly buffer Output {
5936 // float elements[];
5940 // uint x = gl_GlobalInvocationID.x;
5941 // float val = input_data.elements[x];
5943 // output_data.elements[x] = val + 1.f;
5945 // output_data.elements[x] = val - 1.f;
5947 tcu::TestCaseGroup* createSelectionControlGroup (tcu::TestContext& testCtx)
5949 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "selection_control", "Tests selection control cases"));
5950 vector<CaseParameter> cases;
5951 de::Random rnd (deStringHash(group->getName()));
5952 const int numElements = 100;
5953 vector<float> inputFloats (numElements, 0);
5954 vector<float> outputFloats (numElements, 0);
5955 const StringTemplate shaderTemplate (
5956 string(getComputeAsmShaderPreamble()) +
5958 "OpSource GLSL 430\n"
5959 "OpName %main \"main\"\n"
5960 "OpName %id \"gl_GlobalInvocationID\"\n"
5962 "OpDecorate %id BuiltIn GlobalInvocationId\n"
5964 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
5966 "%id = OpVariable %uvec3ptr Input\n"
5967 "%zero = OpConstant %i32 0\n"
5968 "%constf1 = OpConstant %f32 1.0\n"
5969 "%constf10 = OpConstant %f32 10.0\n"
5971 "%main = OpFunction %void None %voidf\n"
5972 "%entry = OpLabel\n"
5973 "%idval = OpLoad %uvec3 %id\n"
5974 "%x = OpCompositeExtract %u32 %idval 0\n"
5975 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
5976 "%inval = OpLoad %f32 %inloc\n"
5977 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
5978 "%cmp_gt = OpFOrdGreaterThan %bool %inval %constf10\n"
5980 " OpSelectionMerge %if_end ${CONTROL}\n"
5981 " OpBranchConditional %cmp_gt %if_true %if_false\n"
5982 "%if_true = OpLabel\n"
5983 "%addf1 = OpFAdd %f32 %inval %constf1\n"
5984 " OpStore %outloc %addf1\n"
5985 " OpBranch %if_end\n"
5986 "%if_false = OpLabel\n"
5987 "%subf1 = OpFSub %f32 %inval %constf1\n"
5988 " OpStore %outloc %subf1\n"
5989 " OpBranch %if_end\n"
5990 "%if_end = OpLabel\n"
5992 " OpFunctionEnd\n");
5994 cases.push_back(CaseParameter("none", "None"));
5995 cases.push_back(CaseParameter("flatten", "Flatten"));
5996 cases.push_back(CaseParameter("dont_flatten", "DontFlatten"));
5997 cases.push_back(CaseParameter("flatten_dont_flatten", "DontFlatten|Flatten"));
5999 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats[0], numElements);
6001 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
6002 floorAll(inputFloats);
6004 for (size_t ndx = 0; ndx < numElements; ++ndx)
6005 outputFloats[ndx] = inputFloats[ndx] + (inputFloats[ndx] > 10.f ? 1.f : -1.f);
6007 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
6009 map<string, string> specializations;
6010 ComputeShaderSpec spec;
6012 specializations["CONTROL"] = cases[caseNdx].param;
6013 spec.assembly = shaderTemplate.specialize(specializations);
6014 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
6015 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
6016 spec.numWorkGroups = IVec3(numElements, 1, 1);
6018 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
6021 return group.release();
6024 void getOpNameAbuseCases (vector<CaseParameter> &abuseCases)
6026 // Generate a long name.
6027 std::string longname;
6028 longname.resize(65535, 'k'); // max string literal, spir-v 2.17
6030 // Some bad names, abusing utf-8 encoding. This may also cause problems
6032 // 1. Various illegal code points in utf-8
6033 std::string utf8illegal =
6034 "Illegal bytes in UTF-8: "
6035 "\xc0 \xc1 \xf5 \xf6 \xf7 \xf8 \xf9 \xfa \xfb \xfc \xfd \xfe \xff"
6036 "illegal surrogates: \xed\xad\xbf \xed\xbe\x80";
6038 // 2. Zero encoded as overlong, not exactly legal but often supported to differentiate from terminating zero
6039 std::string utf8nul = "UTF-8 encoded nul \xC0\x80 (should not end name)";
6041 // 3. Some overlong encodings
6042 std::string utf8overlong =
6043 "UTF-8 overlong \xF0\x82\x82\xAC \xfc\x83\xbf\xbf\xbf\xbf \xf8\x87\xbf\xbf\xbf "
6046 // 4. Internet "zalgo" meme "bleeding text"
6047 std::string utf8zalgo =
6048 "\x56\xcc\xb5\xcc\x85\xcc\x94\xcc\x88\xcd\x8a\xcc\x91\xcc\x88\xcd\x91\xcc\x83\xcd\x82"
6049 "\xcc\x83\xcd\x90\xcc\x8a\xcc\x92\xcc\x92\xcd\x8b\xcc\x94\xcd\x9d\xcc\x98\xcc\xab\xcc"
6050 "\xae\xcc\xa9\xcc\xad\xcc\x97\xcc\xb0\x75\xcc\xb6\xcc\xbe\xcc\x80\xcc\x82\xcc\x84\xcd"
6051 "\x84\xcc\x90\xcd\x86\xcc\x9a\xcd\x84\xcc\x9b\xcd\x86\xcd\x92\xcc\x9a\xcd\x99\xcd\x99"
6052 "\xcc\xbb\xcc\x98\xcd\x8e\xcd\x88\xcd\x9a\xcc\xa6\xcc\x9c\xcc\xab\xcc\x99\xcd\x94\xcd"
6053 "\x99\xcd\x95\xcc\xa5\xcc\xab\xcd\x89\x6c\xcc\xb8\xcc\x8e\xcc\x8b\xcc\x8b\xcc\x9a\xcc"
6054 "\x8e\xcd\x9d\xcc\x80\xcc\xa1\xcc\xad\xcd\x9c\xcc\xba\xcc\x96\xcc\xb3\xcc\xa2\xcd\x8e"
6055 "\xcc\xa2\xcd\x96\x6b\xcc\xb8\xcc\x84\xcd\x81\xcc\xbf\xcc\x8d\xcc\x89\xcc\x85\xcc\x92"
6056 "\xcc\x84\xcc\x90\xcd\x81\xcc\x93\xcd\x90\xcd\x92\xcd\x9d\xcc\x84\xcd\x98\xcd\x9d\xcd"
6057 "\xa0\xcd\x91\xcc\x94\xcc\xb9\xcd\x93\xcc\xa5\xcd\x87\xcc\xad\xcc\xa7\xcd\x96\xcd\x99"
6058 "\xcc\x9d\xcc\xbc\xcd\x96\xcd\x93\xcc\x9d\xcc\x99\xcc\xa8\xcc\xb1\xcd\x85\xcc\xba\xcc"
6059 "\xa7\x61\xcc\xb8\xcc\x8e\xcc\x81\xcd\x90\xcd\x84\xcd\x8c\xcc\x8c\xcc\x85\xcd\x86\xcc"
6060 "\x84\xcd\x84\xcc\x90\xcc\x84\xcc\x8d\xcd\x99\xcd\x8d\xcc\xb0\xcc\xa3\xcc\xa6\xcd\x89"
6061 "\xcd\x8d\xcd\x87\xcc\x98\xcd\x8d\xcc\xa4\xcd\x9a\xcd\x8e\xcc\xab\xcc\xb9\xcc\xac\xcc"
6062 "\xa2\xcd\x87\xcc\xa0\xcc\xb3\xcd\x89\xcc\xb9\xcc\xa7\xcc\xa6\xcd\x89\xcd\x95\x6e\xcc"
6063 "\xb8\xcd\x8a\xcc\x8a\xcd\x82\xcc\x9b\xcd\x81\xcd\x90\xcc\x85\xcc\x9b\xcd\x80\xcd\x91"
6064 "\xcd\x9b\xcc\x81\xcd\x81\xcc\x9a\xcc\xb3\xcd\x9c\xcc\x9e\xcc\x9d\xcd\x99\xcc\xa2\xcd"
6065 "\x93\xcd\x96\xcc\x97\xff";
6067 // General name abuses
6068 abuseCases.push_back(CaseParameter("_has_very_long_name", longname));
6069 abuseCases.push_back(CaseParameter("_utf8_illegal", utf8illegal));
6070 abuseCases.push_back(CaseParameter("_utf8_nul", utf8nul));
6071 abuseCases.push_back(CaseParameter("_utf8_overlong", utf8overlong));
6072 abuseCases.push_back(CaseParameter("_utf8_zalgo", utf8zalgo));
6075 abuseCases.push_back(CaseParameter("_is_gl_Position", "gl_Position"));
6076 abuseCases.push_back(CaseParameter("_is_gl_InstanceID", "gl_InstanceID"));
6077 abuseCases.push_back(CaseParameter("_is_gl_PrimitiveID", "gl_PrimitiveID"));
6078 abuseCases.push_back(CaseParameter("_is_gl_TessCoord", "gl_TessCoord"));
6079 abuseCases.push_back(CaseParameter("_is_gl_PerVertex", "gl_PerVertex"));
6080 abuseCases.push_back(CaseParameter("_is_gl_InvocationID", "gl_InvocationID"));
6081 abuseCases.push_back(CaseParameter("_is_gl_PointSize", "gl_PointSize"));
6082 abuseCases.push_back(CaseParameter("_is_gl_PointCoord", "gl_PointCoord"));
6083 abuseCases.push_back(CaseParameter("_is_gl_Layer", "gl_Layer"));
6084 abuseCases.push_back(CaseParameter("_is_gl_FragDepth", "gl_FragDepth"));
6085 abuseCases.push_back(CaseParameter("_is_gl_NumWorkGroups", "gl_NumWorkGroups"));
6086 abuseCases.push_back(CaseParameter("_is_gl_WorkGroupID", "gl_WorkGroupID"));
6087 abuseCases.push_back(CaseParameter("_is_gl_LocalInvocationID", "gl_LocalInvocationID"));
6088 abuseCases.push_back(CaseParameter("_is_gl_GlobalInvocationID", "gl_GlobalInvocationID"));
6089 abuseCases.push_back(CaseParameter("_is_gl_MaxVertexAttribs", "gl_MaxVertexAttribs"));
6090 abuseCases.push_back(CaseParameter("_is_gl_MaxViewports", "gl_MaxViewports"));
6091 abuseCases.push_back(CaseParameter("_is_gl_MaxComputeWorkGroupCount", "gl_MaxComputeWorkGroupCount"));
6092 abuseCases.push_back(CaseParameter("_is_mat3", "mat3"));
6093 abuseCases.push_back(CaseParameter("_is_volatile", "volatile"));
6094 abuseCases.push_back(CaseParameter("_is_inout", "inout"));
6095 abuseCases.push_back(CaseParameter("_is_isampler3d", "isampler3d"));
6098 tcu::TestCaseGroup* createOpNameGroup (tcu::TestContext& testCtx)
6100 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opname", "Tests OpName cases"));
6101 de::MovePtr<tcu::TestCaseGroup> entryMainGroup (new tcu::TestCaseGroup(testCtx, "entry_main", "OpName tests with entry main"));
6102 de::MovePtr<tcu::TestCaseGroup> entryNotGroup (new tcu::TestCaseGroup(testCtx, "entry_rdc", "OpName tests with entry rdc"));
6103 de::MovePtr<tcu::TestCaseGroup> abuseGroup (new tcu::TestCaseGroup(testCtx, "abuse", "OpName abuse tests"));
6104 vector<CaseParameter> cases;
6105 vector<CaseParameter> abuseCases;
6106 vector<string> testFunc;
6107 de::Random rnd (deStringHash(group->getName()));
6108 const int numElements = 128;
6109 vector<float> inputFloats (numElements, 0);
6110 vector<float> outputFloats (numElements, 0);
6112 getOpNameAbuseCases(abuseCases);
6114 fillRandomScalars(rnd, -100.0f, 100.0f, &inputFloats[0], numElements);
6116 for(size_t ndx = 0; ndx < numElements; ++ndx)
6117 outputFloats[ndx] = -inputFloats[ndx];
6119 const string commonShaderHeader =
6120 "OpCapability Shader\n"
6121 "OpMemoryModel Logical GLSL450\n"
6122 "OpEntryPoint GLCompute %main \"main\" %id\n"
6123 "OpExecutionMode %main LocalSize 1 1 1\n";
6125 const string commonShaderFooter =
6126 "OpDecorate %id BuiltIn GlobalInvocationId\n"
6128 + string(getComputeAsmInputOutputBufferTraits())
6129 + string(getComputeAsmCommonTypes())
6130 + string(getComputeAsmInputOutputBuffer()) +
6132 "%id = OpVariable %uvec3ptr Input\n"
6133 "%zero = OpConstant %i32 0\n"
6135 "%func = OpFunction %void None %voidf\n"
6140 "%main = OpFunction %void None %voidf\n"
6141 "%entry = OpLabel\n"
6142 "%7 = OpFunctionCall %void %func\n"
6144 "%idval = OpLoad %uvec3 %id\n"
6145 "%x = OpCompositeExtract %u32 %idval 0\n"
6147 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
6148 "%inval = OpLoad %f32 %inloc\n"
6149 "%neg = OpFNegate %f32 %inval\n"
6150 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
6151 " OpStore %outloc %neg\n"
6156 const StringTemplate shaderTemplate (
6157 "OpCapability Shader\n"
6158 "OpMemoryModel Logical GLSL450\n"
6159 "OpEntryPoint GLCompute %main \"${ENTRY}\" %id\n"
6160 "OpExecutionMode %main LocalSize 1 1 1\n"
6161 "OpName %${ID} \"${NAME}\"\n" +
6162 commonShaderFooter);
6164 const std::string multipleNames =
6165 commonShaderHeader +
6166 "OpName %main \"to_be\"\n"
6167 "OpName %id \"or_not\"\n"
6168 "OpName %main \"to_be\"\n"
6169 "OpName %main \"makes_no\"\n"
6170 "OpName %func \"difference\"\n"
6171 "OpName %5 \"to_me\"\n" +
6175 ComputeShaderSpec spec;
6177 spec.assembly = multipleNames;
6178 spec.numWorkGroups = IVec3(numElements, 1, 1);
6179 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
6180 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
6182 abuseGroup->addChild(new SpvAsmComputeShaderCase(testCtx, "main_has_multiple_names", "multiple_names", spec));
6185 const std::string everythingNamed =
6186 commonShaderHeader +
6187 "OpName %main \"name1\"\n"
6188 "OpName %id \"name2\"\n"
6189 "OpName %zero \"name3\"\n"
6190 "OpName %entry \"name4\"\n"
6191 "OpName %func \"name5\"\n"
6192 "OpName %5 \"name6\"\n"
6193 "OpName %7 \"name7\"\n"
6194 "OpName %idval \"name8\"\n"
6195 "OpName %inloc \"name9\"\n"
6196 "OpName %inval \"name10\"\n"
6197 "OpName %neg \"name11\"\n"
6198 "OpName %outloc \"name12\"\n"+
6201 ComputeShaderSpec spec;
6203 spec.assembly = everythingNamed;
6204 spec.numWorkGroups = IVec3(numElements, 1, 1);
6205 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
6206 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
6208 abuseGroup->addChild(new SpvAsmComputeShaderCase(testCtx, "everything_named", "everything_named", spec));
6211 const std::string everythingNamedTheSame =
6212 commonShaderHeader +
6213 "OpName %main \"the_same\"\n"
6214 "OpName %id \"the_same\"\n"
6215 "OpName %zero \"the_same\"\n"
6216 "OpName %entry \"the_same\"\n"
6217 "OpName %func \"the_same\"\n"
6218 "OpName %5 \"the_same\"\n"
6219 "OpName %7 \"the_same\"\n"
6220 "OpName %idval \"the_same\"\n"
6221 "OpName %inloc \"the_same\"\n"
6222 "OpName %inval \"the_same\"\n"
6223 "OpName %neg \"the_same\"\n"
6224 "OpName %outloc \"the_same\"\n"+
6227 ComputeShaderSpec spec;
6229 spec.assembly = everythingNamedTheSame;
6230 spec.numWorkGroups = IVec3(numElements, 1, 1);
6231 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
6232 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
6234 abuseGroup->addChild(new SpvAsmComputeShaderCase(testCtx, "everything_named_the_same", "everything_named_the_same", spec));
6238 for (size_t ndx = 0; ndx < abuseCases.size(); ++ndx)
6240 map<string, string> specializations;
6241 ComputeShaderSpec spec;
6243 specializations["ENTRY"] = "main";
6244 specializations["ID"] = "main";
6245 specializations["NAME"] = abuseCases[ndx].param;
6246 spec.assembly = shaderTemplate.specialize(specializations);
6247 spec.numWorkGroups = IVec3(numElements, 1, 1);
6248 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
6249 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
6251 abuseGroup->addChild(new SpvAsmComputeShaderCase(testCtx, (std::string("main") + abuseCases[ndx].name).c_str(), abuseCases[ndx].name, spec));
6255 for (size_t ndx = 0; ndx < abuseCases.size(); ++ndx)
6257 map<string, string> specializations;
6258 ComputeShaderSpec spec;
6260 specializations["ENTRY"] = "main";
6261 specializations["ID"] = "x";
6262 specializations["NAME"] = abuseCases[ndx].param;
6263 spec.assembly = shaderTemplate.specialize(specializations);
6264 spec.numWorkGroups = IVec3(numElements, 1, 1);
6265 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
6266 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
6268 abuseGroup->addChild(new SpvAsmComputeShaderCase(testCtx, (std::string("x") + abuseCases[ndx].name).c_str(), abuseCases[ndx].name, spec));
6271 cases.push_back(CaseParameter("_is_main", "main"));
6272 cases.push_back(CaseParameter("_is_not_main", "not_main"));
6273 testFunc.push_back("main");
6274 testFunc.push_back("func");
6276 for(size_t fNdx = 0; fNdx < testFunc.size(); ++fNdx)
6278 for(size_t ndx = 0; ndx < cases.size(); ++ndx)
6280 map<string, string> specializations;
6281 ComputeShaderSpec spec;
6283 specializations["ENTRY"] = "main";
6284 specializations["ID"] = testFunc[fNdx];
6285 specializations["NAME"] = cases[ndx].param;
6286 spec.assembly = shaderTemplate.specialize(specializations);
6287 spec.numWorkGroups = IVec3(numElements, 1, 1);
6288 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
6289 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
6291 entryMainGroup->addChild(new SpvAsmComputeShaderCase(testCtx, (testFunc[fNdx] + cases[ndx].name).c_str(), cases[ndx].name, spec));
6295 cases.push_back(CaseParameter("_is_entry", "rdc"));
6297 for(size_t fNdx = 0; fNdx < testFunc.size(); ++fNdx)
6299 for(size_t ndx = 0; ndx < cases.size(); ++ndx)
6301 map<string, string> specializations;
6302 ComputeShaderSpec spec;
6304 specializations["ENTRY"] = "rdc";
6305 specializations["ID"] = testFunc[fNdx];
6306 specializations["NAME"] = cases[ndx].param;
6307 spec.assembly = shaderTemplate.specialize(specializations);
6308 spec.numWorkGroups = IVec3(numElements, 1, 1);
6309 spec.entryPoint = "rdc";
6310 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
6311 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
6313 entryNotGroup->addChild(new SpvAsmComputeShaderCase(testCtx, (testFunc[fNdx] + cases[ndx].name).c_str(), cases[ndx].name, spec));
6317 group->addChild(entryMainGroup.release());
6318 group->addChild(entryNotGroup.release());
6319 group->addChild(abuseGroup.release());
6321 return group.release();
6324 tcu::TestCaseGroup* createOpMemberNameGroup (tcu::TestContext& testCtx)
6326 de::MovePtr<tcu::TestCaseGroup> group(new tcu::TestCaseGroup(testCtx, "opmembername", "Tests OpMemberName cases"));
6327 de::MovePtr<tcu::TestCaseGroup> abuseGroup(new tcu::TestCaseGroup(testCtx, "abuse", "OpMemberName abuse tests"));
6328 vector<CaseParameter> abuseCases;
6329 vector<string> testFunc;
6330 de::Random rnd(deStringHash(group->getName()));
6331 const int numElements = 128;
6332 vector<float> inputFloats(numElements, 0);
6333 vector<float> outputFloats(numElements, 0);
6335 getOpNameAbuseCases(abuseCases);
6337 fillRandomScalars(rnd, -100.0f, 100.0f, &inputFloats[0], numElements);
6339 for (size_t ndx = 0; ndx < numElements; ++ndx)
6340 outputFloats[ndx] = -inputFloats[ndx];
6342 const string commonShaderHeader =
6343 "OpCapability Shader\n"
6344 "OpMemoryModel Logical GLSL450\n"
6345 "OpEntryPoint GLCompute %main \"main\" %id\n"
6346 "OpExecutionMode %main LocalSize 1 1 1\n";
6348 const string commonShaderFooter =
6349 "OpDecorate %id BuiltIn GlobalInvocationId\n"
6351 + string(getComputeAsmInputOutputBufferTraits())
6352 + string(getComputeAsmCommonTypes())
6353 + string(getComputeAsmInputOutputBuffer()) +
6355 "%u3str = OpTypeStruct %u32 %u32 %u32\n"
6357 "%id = OpVariable %uvec3ptr Input\n"
6358 "%zero = OpConstant %i32 0\n"
6360 "%main = OpFunction %void None %voidf\n"
6361 "%entry = OpLabel\n"
6363 "%idval = OpLoad %uvec3 %id\n"
6364 "%x0 = OpCompositeExtract %u32 %idval 0\n"
6366 "%idstr = OpCompositeConstruct %u3str %x0 %x0 %x0\n"
6367 "%x = OpCompositeExtract %u32 %idstr 0\n"
6369 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
6370 "%inval = OpLoad %f32 %inloc\n"
6371 "%neg = OpFNegate %f32 %inval\n"
6372 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
6373 " OpStore %outloc %neg\n"
6378 const StringTemplate shaderTemplate(
6379 commonShaderHeader +
6380 "OpMemberName %u3str 0 \"${NAME}\"\n" +
6381 commonShaderFooter);
6383 const std::string multipleNames =
6384 commonShaderHeader +
6385 "OpMemberName %u3str 0 \"to_be\"\n"
6386 "OpMemberName %u3str 1 \"or_not\"\n"
6387 "OpMemberName %u3str 0 \"to_be\"\n"
6388 "OpMemberName %u3str 2 \"makes_no\"\n"
6389 "OpMemberName %u3str 0 \"difference\"\n"
6390 "OpMemberName %u3str 0 \"to_me\"\n" +
6393 ComputeShaderSpec spec;
6395 spec.assembly = multipleNames;
6396 spec.numWorkGroups = IVec3(numElements, 1, 1);
6397 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
6398 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
6400 abuseGroup->addChild(new SpvAsmComputeShaderCase(testCtx, "u3str_x_has_multiple_names", "multiple_names", spec));
6403 const std::string everythingNamedTheSame =
6404 commonShaderHeader +
6405 "OpMemberName %u3str 0 \"the_same\"\n"
6406 "OpMemberName %u3str 1 \"the_same\"\n"
6407 "OpMemberName %u3str 2 \"the_same\"\n" +
6411 ComputeShaderSpec spec;
6413 spec.assembly = everythingNamedTheSame;
6414 spec.numWorkGroups = IVec3(numElements, 1, 1);
6415 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
6416 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
6418 abuseGroup->addChild(new SpvAsmComputeShaderCase(testCtx, "everything_named_the_same", "everything_named_the_same", spec));
6422 for (size_t ndx = 0; ndx < abuseCases.size(); ++ndx)
6424 map<string, string> specializations;
6425 ComputeShaderSpec spec;
6427 specializations["NAME"] = abuseCases[ndx].param;
6428 spec.assembly = shaderTemplate.specialize(specializations);
6429 spec.numWorkGroups = IVec3(numElements, 1, 1);
6430 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
6431 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
6433 abuseGroup->addChild(new SpvAsmComputeShaderCase(testCtx, (std::string("u3str_x") + abuseCases[ndx].name).c_str(), abuseCases[ndx].name, spec));
6436 group->addChild(abuseGroup.release());
6438 return group.release();
6441 // Assembly code used for testing function control is based on GLSL source code:
6445 // layout(std140, set = 0, binding = 0) readonly buffer Input {
6446 // float elements[];
6448 // layout(std140, set = 0, binding = 1) writeonly buffer Output {
6449 // float elements[];
6452 // float const10() { return 10.f; }
6455 // uint x = gl_GlobalInvocationID.x;
6456 // output_data.elements[x] = input_data.elements[x] + const10();
6458 tcu::TestCaseGroup* createFunctionControlGroup (tcu::TestContext& testCtx)
6460 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "function_control", "Tests function control cases"));
6461 vector<CaseParameter> cases;
6462 de::Random rnd (deStringHash(group->getName()));
6463 const int numElements = 100;
6464 vector<float> inputFloats (numElements, 0);
6465 vector<float> outputFloats (numElements, 0);
6466 const StringTemplate shaderTemplate (
6467 string(getComputeAsmShaderPreamble()) +
6469 "OpSource GLSL 430\n"
6470 "OpName %main \"main\"\n"
6471 "OpName %func_const10 \"const10(\"\n"
6472 "OpName %id \"gl_GlobalInvocationID\"\n"
6474 "OpDecorate %id BuiltIn GlobalInvocationId\n"
6476 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
6478 "%f32f = OpTypeFunction %f32\n"
6479 "%id = OpVariable %uvec3ptr Input\n"
6480 "%zero = OpConstant %i32 0\n"
6481 "%constf10 = OpConstant %f32 10.0\n"
6483 "%main = OpFunction %void None %voidf\n"
6484 "%entry = OpLabel\n"
6485 "%idval = OpLoad %uvec3 %id\n"
6486 "%x = OpCompositeExtract %u32 %idval 0\n"
6487 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
6488 "%inval = OpLoad %f32 %inloc\n"
6489 "%ret_10 = OpFunctionCall %f32 %func_const10\n"
6490 "%fadd = OpFAdd %f32 %inval %ret_10\n"
6491 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
6492 " OpStore %outloc %fadd\n"
6496 "%func_const10 = OpFunction %f32 ${CONTROL} %f32f\n"
6497 "%label = OpLabel\n"
6498 " OpReturnValue %constf10\n"
6499 " OpFunctionEnd\n");
6501 cases.push_back(CaseParameter("none", "None"));
6502 cases.push_back(CaseParameter("inline", "Inline"));
6503 cases.push_back(CaseParameter("dont_inline", "DontInline"));
6504 cases.push_back(CaseParameter("pure", "Pure"));
6505 cases.push_back(CaseParameter("const", "Const"));
6506 cases.push_back(CaseParameter("inline_pure", "Inline|Pure"));
6507 cases.push_back(CaseParameter("const_dont_inline", "Const|DontInline"));
6508 cases.push_back(CaseParameter("inline_dont_inline", "Inline|DontInline"));
6509 cases.push_back(CaseParameter("pure_inline_dont_inline", "Pure|Inline|DontInline"));
6511 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats[0], numElements);
6513 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
6514 floorAll(inputFloats);
6516 for (size_t ndx = 0; ndx < numElements; ++ndx)
6517 outputFloats[ndx] = inputFloats[ndx] + 10.f;
6519 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
6521 map<string, string> specializations;
6522 ComputeShaderSpec spec;
6524 specializations["CONTROL"] = cases[caseNdx].param;
6525 spec.assembly = shaderTemplate.specialize(specializations);
6526 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
6527 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
6528 spec.numWorkGroups = IVec3(numElements, 1, 1);
6530 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
6533 return group.release();
6536 tcu::TestCaseGroup* createMemoryAccessGroup (tcu::TestContext& testCtx)
6538 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "memory_access", "Tests memory access cases"));
6539 vector<CaseParameter> cases;
6540 de::Random rnd (deStringHash(group->getName()));
6541 const int numElements = 100;
6542 vector<float> inputFloats (numElements, 0);
6543 vector<float> outputFloats (numElements, 0);
6544 const StringTemplate shaderTemplate (
6545 string(getComputeAsmShaderPreamble()) +
6547 "OpSource GLSL 430\n"
6548 "OpName %main \"main\"\n"
6549 "OpName %id \"gl_GlobalInvocationID\"\n"
6551 "OpDecorate %id BuiltIn GlobalInvocationId\n"
6553 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
6555 "%f32ptr_f = OpTypePointer Function %f32\n"
6557 "%id = OpVariable %uvec3ptr Input\n"
6558 "%zero = OpConstant %i32 0\n"
6559 "%four = OpConstant %i32 4\n"
6561 "%main = OpFunction %void None %voidf\n"
6562 "%label = OpLabel\n"
6563 "%copy = OpVariable %f32ptr_f Function\n"
6564 "%idval = OpLoad %uvec3 %id ${ACCESS}\n"
6565 "%x = OpCompositeExtract %u32 %idval 0\n"
6566 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
6567 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
6568 " OpCopyMemory %copy %inloc ${ACCESS}\n"
6569 "%val1 = OpLoad %f32 %copy\n"
6570 "%val2 = OpLoad %f32 %inloc\n"
6571 "%add = OpFAdd %f32 %val1 %val2\n"
6572 " OpStore %outloc %add ${ACCESS}\n"
6574 " OpFunctionEnd\n");
6576 cases.push_back(CaseParameter("null", ""));
6577 cases.push_back(CaseParameter("none", "None"));
6578 cases.push_back(CaseParameter("volatile", "Volatile"));
6579 cases.push_back(CaseParameter("aligned", "Aligned 4"));
6580 cases.push_back(CaseParameter("nontemporal", "Nontemporal"));
6581 cases.push_back(CaseParameter("aligned_nontemporal", "Aligned|Nontemporal 4"));
6582 cases.push_back(CaseParameter("aligned_volatile", "Volatile|Aligned 4"));
6584 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats[0], numElements);
6586 for (size_t ndx = 0; ndx < numElements; ++ndx)
6587 outputFloats[ndx] = inputFloats[ndx] + inputFloats[ndx];
6589 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
6591 map<string, string> specializations;
6592 ComputeShaderSpec spec;
6594 specializations["ACCESS"] = cases[caseNdx].param;
6595 spec.assembly = shaderTemplate.specialize(specializations);
6596 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
6597 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
6598 spec.numWorkGroups = IVec3(numElements, 1, 1);
6600 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
6603 return group.release();
6606 // Checks that we can get undefined values for various types, without exercising a computation with it.
6607 tcu::TestCaseGroup* createOpUndefGroup (tcu::TestContext& testCtx)
6609 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opundef", "Tests the OpUndef instruction"));
6610 vector<CaseParameter> cases;
6611 de::Random rnd (deStringHash(group->getName()));
6612 const int numElements = 100;
6613 vector<float> positiveFloats (numElements, 0);
6614 vector<float> negativeFloats (numElements, 0);
6615 const StringTemplate shaderTemplate (
6616 string(getComputeAsmShaderPreamble()) +
6618 "OpSource GLSL 430\n"
6619 "OpName %main \"main\"\n"
6620 "OpName %id \"gl_GlobalInvocationID\"\n"
6622 "OpDecorate %id BuiltIn GlobalInvocationId\n"
6624 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
6625 "%uvec2 = OpTypeVector %u32 2\n"
6626 "%fvec4 = OpTypeVector %f32 4\n"
6627 "%fmat33 = OpTypeMatrix %fvec3 3\n"
6628 "%image = OpTypeImage %f32 2D 0 0 0 1 Unknown\n"
6629 "%sampler = OpTypeSampler\n"
6630 "%simage = OpTypeSampledImage %image\n"
6631 "%const100 = OpConstant %u32 100\n"
6632 "%uarr100 = OpTypeArray %i32 %const100\n"
6633 "%struct = OpTypeStruct %f32 %i32 %u32\n"
6634 "%pointer = OpTypePointer Function %i32\n"
6635 + string(getComputeAsmInputOutputBuffer()) +
6637 "%id = OpVariable %uvec3ptr Input\n"
6638 "%zero = OpConstant %i32 0\n"
6640 "%main = OpFunction %void None %voidf\n"
6641 "%label = OpLabel\n"
6643 "%undef = OpUndef ${TYPE}\n"
6645 "%idval = OpLoad %uvec3 %id\n"
6646 "%x = OpCompositeExtract %u32 %idval 0\n"
6648 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
6649 "%inval = OpLoad %f32 %inloc\n"
6650 "%neg = OpFNegate %f32 %inval\n"
6651 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
6652 " OpStore %outloc %neg\n"
6654 " OpFunctionEnd\n");
6656 cases.push_back(CaseParameter("bool", "%bool"));
6657 cases.push_back(CaseParameter("sint32", "%i32"));
6658 cases.push_back(CaseParameter("uint32", "%u32"));
6659 cases.push_back(CaseParameter("float32", "%f32"));
6660 cases.push_back(CaseParameter("vec4float32", "%fvec4"));
6661 cases.push_back(CaseParameter("vec2uint32", "%uvec2"));
6662 cases.push_back(CaseParameter("matrix", "%fmat33"));
6663 cases.push_back(CaseParameter("image", "%image"));
6664 cases.push_back(CaseParameter("sampler", "%sampler"));
6665 cases.push_back(CaseParameter("sampledimage", "%simage"));
6666 cases.push_back(CaseParameter("array", "%uarr100"));
6667 cases.push_back(CaseParameter("runtimearray", "%f32arr"));
6668 cases.push_back(CaseParameter("struct", "%struct"));
6669 cases.push_back(CaseParameter("pointer", "%pointer"));
6671 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
6673 for (size_t ndx = 0; ndx < numElements; ++ndx)
6674 negativeFloats[ndx] = -positiveFloats[ndx];
6676 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
6678 map<string, string> specializations;
6679 ComputeShaderSpec spec;
6681 specializations["TYPE"] = cases[caseNdx].param;
6682 spec.assembly = shaderTemplate.specialize(specializations);
6683 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
6684 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
6685 spec.numWorkGroups = IVec3(numElements, 1, 1);
6687 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
6690 return group.release();
6693 // Checks that a compute shader can generate a constant composite value of various types, without exercising a computation on it.
6694 tcu::TestCaseGroup* createFloat16OpConstantCompositeGroup (tcu::TestContext& testCtx)
6696 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opconstantcomposite", "Tests the OpConstantComposite instruction"));
6697 vector<CaseParameter> cases;
6698 de::Random rnd (deStringHash(group->getName()));
6699 const int numElements = 100;
6700 vector<float> positiveFloats (numElements, 0);
6701 vector<float> negativeFloats (numElements, 0);
6702 const StringTemplate shaderTemplate (
6703 "OpCapability Shader\n"
6704 "OpCapability Float16\n"
6705 "OpMemoryModel Logical GLSL450\n"
6706 "OpEntryPoint GLCompute %main \"main\" %id\n"
6707 "OpExecutionMode %main LocalSize 1 1 1\n"
6708 "OpSource GLSL 430\n"
6709 "OpName %main \"main\"\n"
6710 "OpName %id \"gl_GlobalInvocationID\"\n"
6712 "OpDecorate %id BuiltIn GlobalInvocationId\n"
6714 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
6716 "%id = OpVariable %uvec3ptr Input\n"
6717 "%zero = OpConstant %i32 0\n"
6718 "%f16 = OpTypeFloat 16\n"
6719 "%c_f16_0 = OpConstant %f16 0.0\n"
6720 "%c_f16_0_5 = OpConstant %f16 0.5\n"
6721 "%c_f16_1 = OpConstant %f16 1.0\n"
6722 "%v2f16 = OpTypeVector %f16 2\n"
6723 "%v3f16 = OpTypeVector %f16 3\n"
6724 "%v4f16 = OpTypeVector %f16 4\n"
6728 "%main = OpFunction %void None %voidf\n"
6729 "%label = OpLabel\n"
6730 "%idval = OpLoad %uvec3 %id\n"
6731 "%x = OpCompositeExtract %u32 %idval 0\n"
6732 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
6733 "%inval = OpLoad %f32 %inloc\n"
6734 "%neg = OpFNegate %f32 %inval\n"
6735 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
6736 " OpStore %outloc %neg\n"
6738 " OpFunctionEnd\n");
6741 cases.push_back(CaseParameter("vector", "%const = OpConstantComposite %v3f16 %c_f16_0 %c_f16_0_5 %c_f16_1\n"));
6742 cases.push_back(CaseParameter("matrix", "%m3v3f16 = OpTypeMatrix %v3f16 3\n"
6743 "%vec = OpConstantComposite %v3f16 %c_f16_0 %c_f16_0_5 %c_f16_1\n"
6744 "%mat = OpConstantComposite %m3v3f16 %vec %vec %vec"));
6745 cases.push_back(CaseParameter("struct", "%m2v3f16 = OpTypeMatrix %v3f16 2\n"
6746 "%struct = OpTypeStruct %i32 %f16 %v3f16 %m2v3f16\n"
6747 "%vec = OpConstantComposite %v3f16 %c_f16_0 %c_f16_0_5 %c_f16_1\n"
6748 "%mat = OpConstantComposite %m2v3f16 %vec %vec\n"
6749 "%const = OpConstantComposite %struct %zero %c_f16_0_5 %vec %mat\n"));
6750 cases.push_back(CaseParameter("nested_struct", "%st1 = OpTypeStruct %i32 %f16\n"
6751 "%st2 = OpTypeStruct %i32 %i32\n"
6752 "%struct = OpTypeStruct %st1 %st2\n"
6753 "%st1val = OpConstantComposite %st1 %zero %c_f16_0_5\n"
6754 "%st2val = OpConstantComposite %st2 %zero %zero\n"
6755 "%const = OpConstantComposite %struct %st1val %st2val"));
6757 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
6759 for (size_t ndx = 0; ndx < numElements; ++ndx)
6760 negativeFloats[ndx] = -positiveFloats[ndx];
6762 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
6764 map<string, string> specializations;
6765 ComputeShaderSpec spec;
6767 specializations["CONSTANT"] = cases[caseNdx].param;
6768 spec.assembly = shaderTemplate.specialize(specializations);
6769 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
6770 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
6771 spec.numWorkGroups = IVec3(numElements, 1, 1);
6773 spec.extensions.push_back("VK_KHR_shader_float16_int8");
6775 spec.requestedVulkanFeatures.extFloat16Int8 = EXTFLOAT16INT8FEATURES_FLOAT16;
6777 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
6780 return group.release();
6783 const vector<deFloat16> squarize(const vector<deFloat16>& inData, const deUint32 argNo)
6785 const size_t inDataLength = inData.size();
6786 vector<deFloat16> result;
6788 result.reserve(inDataLength * inDataLength);
6792 for (size_t numIdx = 0; numIdx < inDataLength; ++numIdx)
6793 result.insert(result.end(), inData.begin(), inData.end());
6798 for (size_t numIdx = 0; numIdx < inDataLength; ++numIdx)
6800 const vector<deFloat16> tmp(inDataLength, inData[numIdx]);
6802 result.insert(result.end(), tmp.begin(), tmp.end());
6809 const vector<deFloat16> squarizeVector(const vector<deFloat16>& inData, const deUint32 argNo)
6811 vector<deFloat16> vec;
6812 vector<deFloat16> result;
6814 // Create vectors. vec will contain each possible pair from inData
6816 const size_t inDataLength = inData.size();
6818 DE_ASSERT(inDataLength <= 64);
6820 vec.reserve(2 * inDataLength * inDataLength);
6822 for (size_t numIdxX = 0; numIdxX < inDataLength; ++numIdxX)
6823 for (size_t numIdxY = 0; numIdxY < inDataLength; ++numIdxY)
6825 vec.push_back(inData[numIdxX]);
6826 vec.push_back(inData[numIdxY]);
6830 // Create vector pairs. result will contain each possible pair from vec
6832 const size_t coordsPerVector = 2;
6833 const size_t vectorsCount = vec.size() / coordsPerVector;
6835 result.reserve(coordsPerVector * vectorsCount * vectorsCount);
6839 for (size_t numIdxX = 0; numIdxX < vectorsCount; ++numIdxX)
6840 for (size_t numIdxY = 0; numIdxY < vectorsCount; ++numIdxY)
6842 for (size_t coordNdx = 0; coordNdx < coordsPerVector; ++coordNdx)
6843 result.push_back(vec[coordsPerVector * numIdxY + coordNdx]);
6849 for (size_t numIdxX = 0; numIdxX < vectorsCount; ++numIdxX)
6850 for (size_t numIdxY = 0; numIdxY < vectorsCount; ++numIdxY)
6852 for (size_t coordNdx = 0; coordNdx < coordsPerVector; ++coordNdx)
6853 result.push_back(vec[coordsPerVector * numIdxX + coordNdx]);
6861 struct fp16isNan { bool operator()(const tcu::Float16 in1, const tcu::Float16) { return in1.isNaN(); } };
6862 struct fp16isInf { bool operator()(const tcu::Float16 in1, const tcu::Float16) { return in1.isInf(); } };
6863 struct fp16isEqual { bool operator()(const tcu::Float16 in1, const tcu::Float16 in2) { return in1.asFloat() == in2.asFloat(); } };
6864 struct fp16isUnequal { bool operator()(const tcu::Float16 in1, const tcu::Float16 in2) { return in1.asFloat() != in2.asFloat(); } };
6865 struct fp16isLess { bool operator()(const tcu::Float16 in1, const tcu::Float16 in2) { return in1.asFloat() < in2.asFloat(); } };
6866 struct fp16isGreater { bool operator()(const tcu::Float16 in1, const tcu::Float16 in2) { return in1.asFloat() > in2.asFloat(); } };
6867 struct fp16isLessOrEqual { bool operator()(const tcu::Float16 in1, const tcu::Float16 in2) { return in1.asFloat() <= in2.asFloat(); } };
6868 struct fp16isGreaterOrEqual { bool operator()(const tcu::Float16 in1, const tcu::Float16 in2) { return in1.asFloat() >= in2.asFloat(); } };
6870 template <class TestedLogicalFunction, bool onlyTestFunc, bool unationModeAnd, bool nanSupported>
6871 bool compareFP16Logical (const std::vector<Resource>& inputs, const vector<AllocationSp>& outputAllocs, const std::vector<Resource>&, TestLog& log)
6873 if (inputs.size() != 2 || outputAllocs.size() != 1)
6876 vector<deUint8> input1Bytes;
6877 vector<deUint8> input2Bytes;
6879 inputs[0].getBytes(input1Bytes);
6880 inputs[1].getBytes(input2Bytes);
6882 const deUint32 denormModesCount = 2;
6883 const deFloat16 float16one = tcu::Float16(1.0f).bits();
6884 const deFloat16 float16zero = tcu::Float16(0.0f).bits();
6885 const tcu::Float16 zero = tcu::Float16::zero(1);
6886 const deFloat16* const outputAsFP16 = static_cast<deFloat16*>(outputAllocs[0]->getHostPtr());
6887 const deFloat16* const input1AsFP16 = reinterpret_cast<deFloat16* const>(&input1Bytes.front());
6888 const deFloat16* const input2AsFP16 = reinterpret_cast<deFloat16* const>(&input2Bytes.front());
6889 deUint32 successfulRuns = denormModesCount;
6890 std::string results[denormModesCount];
6891 TestedLogicalFunction testedLogicalFunction;
6893 for (deUint32 denormMode = 0; denormMode < denormModesCount; denormMode++)
6895 const bool flushToZero = (denormMode == 1);
6897 for (size_t idx = 0; idx < input1Bytes.size() / sizeof(deFloat16); ++idx)
6899 const tcu::Float16 f1pre = tcu::Float16(input1AsFP16[idx]);
6900 const tcu::Float16 f2pre = tcu::Float16(input2AsFP16[idx]);
6901 const tcu::Float16 f1 = (flushToZero && f1pre.isDenorm()) ? zero : f1pre;
6902 const tcu::Float16 f2 = (flushToZero && f2pre.isDenorm()) ? zero : f2pre;
6903 deFloat16 expectedOutput = float16zero;
6907 if (testedLogicalFunction(f1, f2))
6908 expectedOutput = float16one;
6912 const bool f1nan = f1.isNaN();
6913 const bool f2nan = f2.isNaN();
6915 // Skip NaN floats if not supported by implementation
6916 if (!nanSupported && (f1nan || f2nan))
6921 const bool ordered = !f1nan && !f2nan;
6923 if (ordered && testedLogicalFunction(f1, f2))
6924 expectedOutput = float16one;
6928 const bool unordered = f1nan || f2nan;
6930 if (unordered || testedLogicalFunction(f1, f2))
6931 expectedOutput = float16one;
6935 if (outputAsFP16[idx] != expectedOutput)
6937 std::ostringstream str;
6939 str << "ERROR: Sub-case #" << idx
6940 << " flushToZero:" << flushToZero
6942 << " failed, inputs: 0x" << f1.bits()
6943 << ";0x" << f2.bits()
6944 << " output: 0x" << outputAsFP16[idx]
6945 << " expected output: 0x" << expectedOutput;
6947 results[denormMode] = str.str();
6956 if (successfulRuns == 0)
6957 for (deUint32 denormMode = 0; denormMode < denormModesCount; denormMode++)
6958 log << TestLog::Message << results[denormMode] << TestLog::EndMessage;
6960 return successfulRuns > 0;
6965 tcu::TestCaseGroup* createOpSourceTests (tcu::TestContext& testCtx)
6967 struct NameCodePair { string name, code; };
6968 RGBA defaultColors[4];
6969 de::MovePtr<tcu::TestCaseGroup> opSourceTests (new tcu::TestCaseGroup(testCtx, "opsource", "OpSource instruction"));
6970 const std::string opsourceGLSLWithFile = "%opsrcfile = OpString \"foo.vert\"\nOpSource GLSL 450 %opsrcfile ";
6971 map<string, string> fragments = passthruFragments();
6972 const NameCodePair tests[] =
6974 {"unknown", "OpSource Unknown 321"},
6975 {"essl", "OpSource ESSL 310"},
6976 {"glsl", "OpSource GLSL 450"},
6977 {"opencl_cpp", "OpSource OpenCL_CPP 120"},
6978 {"opencl_c", "OpSource OpenCL_C 120"},
6979 {"multiple", "OpSource GLSL 450\nOpSource GLSL 450"},
6980 {"file", opsourceGLSLWithFile},
6981 {"source", opsourceGLSLWithFile + "\"void main(){}\""},
6982 // Longest possible source string: SPIR-V limits instructions to 65535
6983 // words, of which the first 4 are opsourceGLSLWithFile; the rest will
6984 // contain 65530 UTF8 characters (one word each) plus one last word
6985 // containing 3 ASCII characters and \0.
6986 {"longsource", opsourceGLSLWithFile + '"' + makeLongUTF8String(65530) + "ccc" + '"'}
6989 getDefaultColors(defaultColors);
6990 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameCodePair); ++testNdx)
6992 fragments["debug"] = tests[testNdx].code;
6993 createTestsForAllStages(tests[testNdx].name, defaultColors, defaultColors, fragments, opSourceTests.get());
6996 return opSourceTests.release();
6999 tcu::TestCaseGroup* createOpSourceContinuedTests (tcu::TestContext& testCtx)
7001 struct NameCodePair { string name, code; };
7002 RGBA defaultColors[4];
7003 de::MovePtr<tcu::TestCaseGroup> opSourceTests (new tcu::TestCaseGroup(testCtx, "opsourcecontinued", "OpSourceContinued instruction"));
7004 map<string, string> fragments = passthruFragments();
7005 const std::string opsource = "%opsrcfile = OpString \"foo.vert\"\nOpSource GLSL 450 %opsrcfile \"void main(){}\"\n";
7006 const NameCodePair tests[] =
7008 {"empty", opsource + "OpSourceContinued \"\""},
7009 {"short", opsource + "OpSourceContinued \"abcde\""},
7010 {"multiple", opsource + "OpSourceContinued \"abcde\"\nOpSourceContinued \"fghij\""},
7011 // Longest possible source string: SPIR-V limits instructions to 65535
7012 // words, of which the first one is OpSourceContinued/length; the rest
7013 // will contain 65533 UTF8 characters (one word each) plus one last word
7014 // containing 3 ASCII characters and \0.
7015 {"long", opsource + "OpSourceContinued \"" + makeLongUTF8String(65533) + "ccc\""}
7018 getDefaultColors(defaultColors);
7019 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameCodePair); ++testNdx)
7021 fragments["debug"] = tests[testNdx].code;
7022 createTestsForAllStages(tests[testNdx].name, defaultColors, defaultColors, fragments, opSourceTests.get());
7025 return opSourceTests.release();
7027 tcu::TestCaseGroup* createOpNoLineTests(tcu::TestContext& testCtx)
7029 RGBA defaultColors[4];
7030 de::MovePtr<tcu::TestCaseGroup> opLineTests (new tcu::TestCaseGroup(testCtx, "opnoline", "OpNoLine instruction"));
7031 map<string, string> fragments;
7032 getDefaultColors(defaultColors);
7033 fragments["debug"] =
7034 "%name = OpString \"name\"\n";
7036 fragments["pre_main"] =
7039 "OpLine %name 1 1\n"
7041 "OpLine %name 1 1\n"
7042 "OpLine %name 1 1\n"
7043 "%second_function = OpFunction %v4f32 None %v4f32_v4f32_function\n"
7045 "OpLine %name 1 1\n"
7047 "OpLine %name 1 1\n"
7048 "OpLine %name 1 1\n"
7049 "%second_param1 = OpFunctionParameter %v4f32\n"
7052 "%label_secondfunction = OpLabel\n"
7054 "OpReturnValue %second_param1\n"
7059 fragments["testfun"] =
7060 // A %test_code function that returns its argument unchanged.
7063 "OpLine %name 1 1\n"
7064 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
7066 "%param1 = OpFunctionParameter %v4f32\n"
7069 "%label_testfun = OpLabel\n"
7071 "%val1 = OpFunctionCall %v4f32 %second_function %param1\n"
7072 "OpReturnValue %val1\n"
7074 "OpLine %name 1 1\n"
7077 createTestsForAllStages("opnoline", defaultColors, defaultColors, fragments, opLineTests.get());
7079 return opLineTests.release();
7082 tcu::TestCaseGroup* createOpModuleProcessedTests(tcu::TestContext& testCtx)
7084 RGBA defaultColors[4];
7085 de::MovePtr<tcu::TestCaseGroup> opModuleProcessedTests (new tcu::TestCaseGroup(testCtx, "opmoduleprocessed", "OpModuleProcessed instruction"));
7086 map<string, string> fragments;
7087 std::vector<std::string> noExtensions;
7088 GraphicsResources resources;
7090 getDefaultColors(defaultColors);
7091 resources.verifyBinary = veryfiBinaryShader;
7092 resources.spirvVersion = SPIRV_VERSION_1_3;
7094 fragments["moduleprocessed"] =
7095 "OpModuleProcessed \"VULKAN CTS\"\n"
7096 "OpModuleProcessed \"Negative values\"\n"
7097 "OpModuleProcessed \"Date: 2017/09/21\"\n";
7099 fragments["pre_main"] =
7100 "%second_function = OpFunction %v4f32 None %v4f32_v4f32_function\n"
7101 "%second_param1 = OpFunctionParameter %v4f32\n"
7102 "%label_secondfunction = OpLabel\n"
7103 "OpReturnValue %second_param1\n"
7106 fragments["testfun"] =
7107 // A %test_code function that returns its argument unchanged.
7108 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
7109 "%param1 = OpFunctionParameter %v4f32\n"
7110 "%label_testfun = OpLabel\n"
7111 "%val1 = OpFunctionCall %v4f32 %second_function %param1\n"
7112 "OpReturnValue %val1\n"
7115 createTestsForAllStages ("opmoduleprocessed", defaultColors, defaultColors, fragments, resources, noExtensions, opModuleProcessedTests.get());
7117 return opModuleProcessedTests.release();
7121 tcu::TestCaseGroup* createOpLineTests(tcu::TestContext& testCtx)
7123 RGBA defaultColors[4];
7124 de::MovePtr<tcu::TestCaseGroup> opLineTests (new tcu::TestCaseGroup(testCtx, "opline", "OpLine instruction"));
7125 map<string, string> fragments;
7126 std::vector<std::pair<std::string, std::string> > problemStrings;
7128 problemStrings.push_back(std::make_pair<std::string, std::string>("empty_name", ""));
7129 problemStrings.push_back(std::make_pair<std::string, std::string>("short_name", "short_name"));
7130 problemStrings.push_back(std::make_pair<std::string, std::string>("long_name", makeLongUTF8String(65530) + "ccc"));
7131 getDefaultColors(defaultColors);
7133 fragments["debug"] =
7134 "%other_name = OpString \"other_name\"\n";
7136 fragments["pre_main"] =
7137 "OpLine %file_name 32 0\n"
7138 "OpLine %file_name 32 32\n"
7139 "OpLine %file_name 32 40\n"
7140 "OpLine %other_name 32 40\n"
7141 "OpLine %other_name 0 100\n"
7142 "OpLine %other_name 0 4294967295\n"
7143 "OpLine %other_name 4294967295 0\n"
7144 "OpLine %other_name 32 40\n"
7145 "OpLine %file_name 0 0\n"
7146 "%second_function = OpFunction %v4f32 None %v4f32_v4f32_function\n"
7147 "OpLine %file_name 1 0\n"
7148 "%second_param1 = OpFunctionParameter %v4f32\n"
7149 "OpLine %file_name 1 3\n"
7150 "OpLine %file_name 1 2\n"
7151 "%label_secondfunction = OpLabel\n"
7152 "OpLine %file_name 0 2\n"
7153 "OpReturnValue %second_param1\n"
7155 "OpLine %file_name 0 2\n"
7156 "OpLine %file_name 0 2\n";
7158 fragments["testfun"] =
7159 // A %test_code function that returns its argument unchanged.
7160 "OpLine %file_name 1 0\n"
7161 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
7162 "OpLine %file_name 16 330\n"
7163 "%param1 = OpFunctionParameter %v4f32\n"
7164 "OpLine %file_name 14 442\n"
7165 "%label_testfun = OpLabel\n"
7166 "OpLine %file_name 11 1024\n"
7167 "%val1 = OpFunctionCall %v4f32 %second_function %param1\n"
7168 "OpLine %file_name 2 97\n"
7169 "OpReturnValue %val1\n"
7171 "OpLine %file_name 5 32\n";
7173 for (size_t i = 0; i < problemStrings.size(); ++i)
7175 map<string, string> testFragments = fragments;
7176 testFragments["debug"] += "%file_name = OpString \"" + problemStrings[i].second + "\"\n";
7177 createTestsForAllStages(string("opline") + "_" + problemStrings[i].first, defaultColors, defaultColors, testFragments, opLineTests.get());
7180 return opLineTests.release();
7183 tcu::TestCaseGroup* createOpConstantNullTests(tcu::TestContext& testCtx)
7185 de::MovePtr<tcu::TestCaseGroup> opConstantNullTests (new tcu::TestCaseGroup(testCtx, "opconstantnull", "OpConstantNull instruction"));
7189 const char functionStart[] =
7190 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
7191 "%param1 = OpFunctionParameter %v4f32\n"
7194 const char functionEnd[] =
7195 "OpReturnValue %transformed_param\n"
7198 struct NameConstantsCode
7205 NameConstantsCode tests[] =
7209 "%cnull = OpConstantNull %v4f32\n",
7210 "%transformed_param = OpFAdd %v4f32 %param1 %cnull\n"
7214 "%cnull = OpConstantNull %f32\n",
7215 "%vp = OpVariable %fp_v4f32 Function\n"
7216 "%v = OpLoad %v4f32 %vp\n"
7217 "%v0 = OpVectorInsertDynamic %v4f32 %v %cnull %c_i32_0\n"
7218 "%v1 = OpVectorInsertDynamic %v4f32 %v0 %cnull %c_i32_1\n"
7219 "%v2 = OpVectorInsertDynamic %v4f32 %v1 %cnull %c_i32_2\n"
7220 "%v3 = OpVectorInsertDynamic %v4f32 %v2 %cnull %c_i32_3\n"
7221 "%transformed_param = OpFAdd %v4f32 %param1 %v3\n"
7225 "%cnull = OpConstantNull %bool\n",
7226 "%v = OpVariable %fp_v4f32 Function\n"
7227 " OpStore %v %param1\n"
7228 " OpSelectionMerge %false_label None\n"
7229 " OpBranchConditional %cnull %true_label %false_label\n"
7230 "%true_label = OpLabel\n"
7231 " OpStore %v %c_v4f32_0_5_0_5_0_5_0_5\n"
7232 " OpBranch %false_label\n"
7233 "%false_label = OpLabel\n"
7234 "%transformed_param = OpLoad %v4f32 %v\n"
7238 "%cnull = OpConstantNull %i32\n",
7239 "%v = OpVariable %fp_v4f32 Function %c_v4f32_0_5_0_5_0_5_0_5\n"
7240 "%b = OpIEqual %bool %cnull %c_i32_0\n"
7241 " OpSelectionMerge %false_label None\n"
7242 " OpBranchConditional %b %true_label %false_label\n"
7243 "%true_label = OpLabel\n"
7244 " OpStore %v %param1\n"
7245 " OpBranch %false_label\n"
7246 "%false_label = OpLabel\n"
7247 "%transformed_param = OpLoad %v4f32 %v\n"
7251 "%stype = OpTypeStruct %f32 %v4f32\n"
7252 "%fp_stype = OpTypePointer Function %stype\n"
7253 "%cnull = OpConstantNull %stype\n",
7254 "%v = OpVariable %fp_stype Function %cnull\n"
7255 "%f = OpAccessChain %fp_v4f32 %v %c_i32_1\n"
7256 "%f_val = OpLoad %v4f32 %f\n"
7257 "%transformed_param = OpFAdd %v4f32 %param1 %f_val\n"
7261 "%a4_v4f32 = OpTypeArray %v4f32 %c_u32_4\n"
7262 "%fp_a4_v4f32 = OpTypePointer Function %a4_v4f32\n"
7263 "%cnull = OpConstantNull %a4_v4f32\n",
7264 "%v = OpVariable %fp_a4_v4f32 Function %cnull\n"
7265 "%f = OpAccessChain %fp_v4f32 %v %c_u32_0\n"
7266 "%f1 = OpAccessChain %fp_v4f32 %v %c_u32_1\n"
7267 "%f2 = OpAccessChain %fp_v4f32 %v %c_u32_2\n"
7268 "%f3 = OpAccessChain %fp_v4f32 %v %c_u32_3\n"
7269 "%f_val = OpLoad %v4f32 %f\n"
7270 "%f1_val = OpLoad %v4f32 %f1\n"
7271 "%f2_val = OpLoad %v4f32 %f2\n"
7272 "%f3_val = OpLoad %v4f32 %f3\n"
7273 "%t0 = OpFAdd %v4f32 %param1 %f_val\n"
7274 "%t1 = OpFAdd %v4f32 %t0 %f1_val\n"
7275 "%t2 = OpFAdd %v4f32 %t1 %f2_val\n"
7276 "%transformed_param = OpFAdd %v4f32 %t2 %f3_val\n"
7280 "%mat4x4_f32 = OpTypeMatrix %v4f32 4\n"
7281 "%cnull = OpConstantNull %mat4x4_f32\n",
7282 // Our null matrix * any vector should result in a zero vector.
7283 "%v = OpVectorTimesMatrix %v4f32 %param1 %cnull\n"
7284 "%transformed_param = OpFAdd %v4f32 %param1 %v\n"
7288 getHalfColorsFullAlpha(colors);
7290 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameConstantsCode); ++testNdx)
7292 map<string, string> fragments;
7293 fragments["pre_main"] = tests[testNdx].constants;
7294 fragments["testfun"] = string(functionStart) + tests[testNdx].code + functionEnd;
7295 createTestsForAllStages(tests[testNdx].name, colors, colors, fragments, opConstantNullTests.get());
7297 return opConstantNullTests.release();
7299 tcu::TestCaseGroup* createOpConstantCompositeTests(tcu::TestContext& testCtx)
7301 de::MovePtr<tcu::TestCaseGroup> opConstantCompositeTests (new tcu::TestCaseGroup(testCtx, "opconstantcomposite", "OpConstantComposite instruction"));
7302 RGBA inputColors[4];
7303 RGBA outputColors[4];
7306 const char functionStart[] =
7307 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
7308 "%param1 = OpFunctionParameter %v4f32\n"
7311 const char functionEnd[] =
7312 "OpReturnValue %transformed_param\n"
7315 struct NameConstantsCode
7322 NameConstantsCode tests[] =
7327 "%cval = OpConstantComposite %v4f32 %c_f32_0_5 %c_f32_0_5 %c_f32_0_5 %c_f32_0\n",
7328 "%transformed_param = OpFAdd %v4f32 %param1 %cval\n"
7333 "%stype = OpTypeStruct %v4f32 %f32\n"
7334 "%fp_stype = OpTypePointer Function %stype\n"
7335 "%f32_n_1 = OpConstant %f32 -1.0\n"
7336 "%f32_1_5 = OpConstant %f32 !0x3fc00000\n" // +1.5
7337 "%cvec = OpConstantComposite %v4f32 %f32_1_5 %f32_1_5 %f32_1_5 %c_f32_1\n"
7338 "%cval = OpConstantComposite %stype %cvec %f32_n_1\n",
7340 "%v = OpVariable %fp_stype Function %cval\n"
7341 "%vec_ptr = OpAccessChain %fp_v4f32 %v %c_u32_0\n"
7342 "%f32_ptr = OpAccessChain %fp_f32 %v %c_u32_1\n"
7343 "%vec_val = OpLoad %v4f32 %vec_ptr\n"
7344 "%f32_val = OpLoad %f32 %f32_ptr\n"
7345 "%tmp1 = OpVectorTimesScalar %v4f32 %c_v4f32_1_1_1_1 %f32_val\n" // vec4(-1)
7346 "%tmp2 = OpFAdd %v4f32 %tmp1 %param1\n" // param1 + vec4(-1)
7347 "%transformed_param = OpFAdd %v4f32 %tmp2 %vec_val\n" // param1 + vec4(-1) + vec4(1.5, 1.5, 1.5, 1.0)
7350 // [1|0|0|0.5] [x] = x + 0.5
7351 // [0|1|0|0.5] [y] = y + 0.5
7352 // [0|0|1|0.5] [z] = z + 0.5
7353 // [0|0|0|1 ] [1] = 1
7356 "%mat4x4_f32 = OpTypeMatrix %v4f32 4\n"
7357 "%v4f32_1_0_0_0 = OpConstantComposite %v4f32 %c_f32_1 %c_f32_0 %c_f32_0 %c_f32_0\n"
7358 "%v4f32_0_1_0_0 = OpConstantComposite %v4f32 %c_f32_0 %c_f32_1 %c_f32_0 %c_f32_0\n"
7359 "%v4f32_0_0_1_0 = OpConstantComposite %v4f32 %c_f32_0 %c_f32_0 %c_f32_1 %c_f32_0\n"
7360 "%v4f32_0_5_0_5_0_5_1 = OpConstantComposite %v4f32 %c_f32_0_5 %c_f32_0_5 %c_f32_0_5 %c_f32_1\n"
7361 "%cval = OpConstantComposite %mat4x4_f32 %v4f32_1_0_0_0 %v4f32_0_1_0_0 %v4f32_0_0_1_0 %v4f32_0_5_0_5_0_5_1\n",
7363 "%transformed_param = OpMatrixTimesVector %v4f32 %cval %param1\n"
7368 "%c_v4f32_1_1_1_0 = OpConstantComposite %v4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_0\n"
7369 "%fp_a4f32 = OpTypePointer Function %a4f32\n"
7370 "%f32_n_1 = OpConstant %f32 -1.0\n"
7371 "%f32_1_5 = OpConstant %f32 !0x3fc00000\n" // +1.5
7372 "%carr = OpConstantComposite %a4f32 %c_f32_0 %f32_n_1 %f32_1_5 %c_f32_0\n",
7374 "%v = OpVariable %fp_a4f32 Function %carr\n"
7375 "%f = OpAccessChain %fp_f32 %v %c_u32_0\n"
7376 "%f1 = OpAccessChain %fp_f32 %v %c_u32_1\n"
7377 "%f2 = OpAccessChain %fp_f32 %v %c_u32_2\n"
7378 "%f3 = OpAccessChain %fp_f32 %v %c_u32_3\n"
7379 "%f_val = OpLoad %f32 %f\n"
7380 "%f1_val = OpLoad %f32 %f1\n"
7381 "%f2_val = OpLoad %f32 %f2\n"
7382 "%f3_val = OpLoad %f32 %f3\n"
7383 "%ftot1 = OpFAdd %f32 %f_val %f1_val\n"
7384 "%ftot2 = OpFAdd %f32 %ftot1 %f2_val\n"
7385 "%ftot3 = OpFAdd %f32 %ftot2 %f3_val\n" // 0 - 1 + 1.5 + 0
7386 "%add_vec = OpVectorTimesScalar %v4f32 %c_v4f32_1_1_1_0 %ftot3\n"
7387 "%transformed_param = OpFAdd %v4f32 %param1 %add_vec\n"
7394 // [ 1.0, 1.0, 1.0, 1.0]
7398 // [ 0.0, 0.5, 0.0, 0.0]
7402 // [ 1.0, 1.0, 1.0, 1.0]
7405 "array_of_struct_of_array",
7407 "%c_v4f32_1_1_1_0 = OpConstantComposite %v4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_0\n"
7408 "%fp_a4f32 = OpTypePointer Function %a4f32\n"
7409 "%stype = OpTypeStruct %f32 %a4f32\n"
7410 "%a3stype = OpTypeArray %stype %c_u32_3\n"
7411 "%fp_a3stype = OpTypePointer Function %a3stype\n"
7412 "%ca4f32_0 = OpConstantComposite %a4f32 %c_f32_0 %c_f32_0_5 %c_f32_0 %c_f32_0\n"
7413 "%ca4f32_1 = OpConstantComposite %a4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_1\n"
7414 "%cstype1 = OpConstantComposite %stype %c_f32_0 %ca4f32_1\n"
7415 "%cstype2 = OpConstantComposite %stype %c_f32_1 %ca4f32_0\n"
7416 "%carr = OpConstantComposite %a3stype %cstype1 %cstype2 %cstype1",
7418 "%v = OpVariable %fp_a3stype Function %carr\n"
7419 "%f = OpAccessChain %fp_f32 %v %c_u32_1 %c_u32_1 %c_u32_1\n"
7420 "%f_l = OpLoad %f32 %f\n"
7421 "%add_vec = OpVectorTimesScalar %v4f32 %c_v4f32_1_1_1_0 %f_l\n"
7422 "%transformed_param = OpFAdd %v4f32 %param1 %add_vec\n"
7426 getHalfColorsFullAlpha(inputColors);
7427 outputColors[0] = RGBA(255, 255, 255, 255);
7428 outputColors[1] = RGBA(255, 127, 127, 255);
7429 outputColors[2] = RGBA(127, 255, 127, 255);
7430 outputColors[3] = RGBA(127, 127, 255, 255);
7432 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameConstantsCode); ++testNdx)
7434 map<string, string> fragments;
7435 fragments["pre_main"] = tests[testNdx].constants;
7436 fragments["testfun"] = string(functionStart) + tests[testNdx].code + functionEnd;
7437 createTestsForAllStages(tests[testNdx].name, inputColors, outputColors, fragments, opConstantCompositeTests.get());
7439 return opConstantCompositeTests.release();
7442 tcu::TestCaseGroup* createSelectionBlockOrderTests(tcu::TestContext& testCtx)
7444 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "selection_block_order", "Out-of-order blocks for selection"));
7445 RGBA inputColors[4];
7446 RGBA outputColors[4];
7447 map<string, string> fragments;
7449 // vec4 test_code(vec4 param) {
7450 // vec4 result = param;
7451 // for (int i = 0; i < 4; ++i) {
7452 // if (i == 0) result[i] = 0.;
7453 // else result[i] = 1. - result[i];
7457 const char function[] =
7458 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
7459 "%param1 = OpFunctionParameter %v4f32\n"
7461 "%iptr = OpVariable %fp_i32 Function\n"
7462 "%result = OpVariable %fp_v4f32 Function\n"
7463 " OpStore %iptr %c_i32_0\n"
7464 " OpStore %result %param1\n"
7467 // Loop entry block.
7469 "%ival = OpLoad %i32 %iptr\n"
7470 "%lt_4 = OpSLessThan %bool %ival %c_i32_4\n"
7471 " OpLoopMerge %exit %if_entry None\n"
7472 " OpBranchConditional %lt_4 %if_entry %exit\n"
7474 // Merge block for loop.
7476 "%ret = OpLoad %v4f32 %result\n"
7477 " OpReturnValue %ret\n"
7479 // If-statement entry block.
7480 "%if_entry = OpLabel\n"
7481 "%loc = OpAccessChain %fp_f32 %result %ival\n"
7482 "%eq_0 = OpIEqual %bool %ival %c_i32_0\n"
7483 " OpSelectionMerge %if_exit None\n"
7484 " OpBranchConditional %eq_0 %if_true %if_false\n"
7486 // False branch for if-statement.
7487 "%if_false = OpLabel\n"
7488 "%val = OpLoad %f32 %loc\n"
7489 "%sub = OpFSub %f32 %c_f32_1 %val\n"
7490 " OpStore %loc %sub\n"
7491 " OpBranch %if_exit\n"
7493 // Merge block for if-statement.
7494 "%if_exit = OpLabel\n"
7495 "%ival_next = OpIAdd %i32 %ival %c_i32_1\n"
7496 " OpStore %iptr %ival_next\n"
7499 // True branch for if-statement.
7500 "%if_true = OpLabel\n"
7501 " OpStore %loc %c_f32_0\n"
7502 " OpBranch %if_exit\n"
7506 fragments["testfun"] = function;
7508 inputColors[0] = RGBA(127, 127, 127, 0);
7509 inputColors[1] = RGBA(127, 0, 0, 0);
7510 inputColors[2] = RGBA(0, 127, 0, 0);
7511 inputColors[3] = RGBA(0, 0, 127, 0);
7513 outputColors[0] = RGBA(0, 128, 128, 255);
7514 outputColors[1] = RGBA(0, 255, 255, 255);
7515 outputColors[2] = RGBA(0, 128, 255, 255);
7516 outputColors[3] = RGBA(0, 255, 128, 255);
7518 createTestsForAllStages("out_of_order", inputColors, outputColors, fragments, group.get());
7520 return group.release();
7523 tcu::TestCaseGroup* createSwitchBlockOrderTests(tcu::TestContext& testCtx)
7525 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "switch_block_order", "Out-of-order blocks for switch"));
7526 RGBA inputColors[4];
7527 RGBA outputColors[4];
7528 map<string, string> fragments;
7530 const char typesAndConstants[] =
7531 "%c_f32_p2 = OpConstant %f32 0.2\n"
7532 "%c_f32_p4 = OpConstant %f32 0.4\n"
7533 "%c_f32_p6 = OpConstant %f32 0.6\n"
7534 "%c_f32_p8 = OpConstant %f32 0.8\n";
7536 // vec4 test_code(vec4 param) {
7537 // vec4 result = param;
7538 // for (int i = 0; i < 4; ++i) {
7540 // case 0: result[i] += .2; break;
7541 // case 1: result[i] += .6; break;
7542 // case 2: result[i] += .4; break;
7543 // case 3: result[i] += .8; break;
7544 // default: break; // unreachable
7549 const char function[] =
7550 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
7551 "%param1 = OpFunctionParameter %v4f32\n"
7553 "%iptr = OpVariable %fp_i32 Function\n"
7554 "%result = OpVariable %fp_v4f32 Function\n"
7555 " OpStore %iptr %c_i32_0\n"
7556 " OpStore %result %param1\n"
7559 // Loop entry block.
7561 "%ival = OpLoad %i32 %iptr\n"
7562 "%lt_4 = OpSLessThan %bool %ival %c_i32_4\n"
7563 " OpLoopMerge %exit %cont None\n"
7564 " OpBranchConditional %lt_4 %switch_entry %exit\n"
7566 // Merge block for loop.
7568 "%ret = OpLoad %v4f32 %result\n"
7569 " OpReturnValue %ret\n"
7571 // Switch-statement entry block.
7572 "%switch_entry = OpLabel\n"
7573 "%loc = OpAccessChain %fp_f32 %result %ival\n"
7574 "%val = OpLoad %f32 %loc\n"
7575 " OpSelectionMerge %switch_exit None\n"
7576 " OpSwitch %ival %switch_default 0 %case0 1 %case1 2 %case2 3 %case3\n"
7578 "%case2 = OpLabel\n"
7579 "%addp4 = OpFAdd %f32 %val %c_f32_p4\n"
7580 " OpStore %loc %addp4\n"
7581 " OpBranch %switch_exit\n"
7583 "%switch_default = OpLabel\n"
7586 "%case3 = OpLabel\n"
7587 "%addp8 = OpFAdd %f32 %val %c_f32_p8\n"
7588 " OpStore %loc %addp8\n"
7589 " OpBranch %switch_exit\n"
7591 "%case0 = OpLabel\n"
7592 "%addp2 = OpFAdd %f32 %val %c_f32_p2\n"
7593 " OpStore %loc %addp2\n"
7594 " OpBranch %switch_exit\n"
7596 // Merge block for switch-statement.
7597 "%switch_exit = OpLabel\n"
7598 "%ival_next = OpIAdd %i32 %ival %c_i32_1\n"
7599 " OpStore %iptr %ival_next\n"
7604 "%case1 = OpLabel\n"
7605 "%addp6 = OpFAdd %f32 %val %c_f32_p6\n"
7606 " OpStore %loc %addp6\n"
7607 " OpBranch %switch_exit\n"
7611 fragments["pre_main"] = typesAndConstants;
7612 fragments["testfun"] = function;
7614 inputColors[0] = RGBA(127, 27, 127, 51);
7615 inputColors[1] = RGBA(127, 0, 0, 51);
7616 inputColors[2] = RGBA(0, 27, 0, 51);
7617 inputColors[3] = RGBA(0, 0, 127, 51);
7619 outputColors[0] = RGBA(178, 180, 229, 255);
7620 outputColors[1] = RGBA(178, 153, 102, 255);
7621 outputColors[2] = RGBA(51, 180, 102, 255);
7622 outputColors[3] = RGBA(51, 153, 229, 255);
7624 createTestsForAllStages("out_of_order", inputColors, outputColors, fragments, group.get());
7626 return group.release();
7629 tcu::TestCaseGroup* createDecorationGroupTests(tcu::TestContext& testCtx)
7631 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "decoration_group", "Decoration group tests"));
7632 RGBA inputColors[4];
7633 RGBA outputColors[4];
7634 map<string, string> fragments;
7636 const char decorations[] =
7637 "OpDecorate %array_group ArrayStride 4\n"
7638 "OpDecorate %struct_member_group Offset 0\n"
7639 "%array_group = OpDecorationGroup\n"
7640 "%struct_member_group = OpDecorationGroup\n"
7642 "OpDecorate %group1 RelaxedPrecision\n"
7643 "OpDecorate %group3 RelaxedPrecision\n"
7644 "OpDecorate %group3 Invariant\n"
7645 "OpDecorate %group3 Restrict\n"
7646 "%group0 = OpDecorationGroup\n"
7647 "%group1 = OpDecorationGroup\n"
7648 "%group3 = OpDecorationGroup\n";
7650 const char typesAndConstants[] =
7651 "%a3f32 = OpTypeArray %f32 %c_u32_3\n"
7652 "%struct1 = OpTypeStruct %a3f32\n"
7653 "%struct2 = OpTypeStruct %a3f32\n"
7654 "%fp_struct1 = OpTypePointer Function %struct1\n"
7655 "%fp_struct2 = OpTypePointer Function %struct2\n"
7656 "%c_f32_2 = OpConstant %f32 2.\n"
7657 "%c_f32_n2 = OpConstant %f32 -2.\n"
7659 "%c_a3f32_1 = OpConstantComposite %a3f32 %c_f32_1 %c_f32_2 %c_f32_1\n"
7660 "%c_a3f32_2 = OpConstantComposite %a3f32 %c_f32_n1 %c_f32_n2 %c_f32_n1\n"
7661 "%c_struct1 = OpConstantComposite %struct1 %c_a3f32_1\n"
7662 "%c_struct2 = OpConstantComposite %struct2 %c_a3f32_2\n";
7664 const char function[] =
7665 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
7666 "%param = OpFunctionParameter %v4f32\n"
7667 "%entry = OpLabel\n"
7668 "%result = OpVariable %fp_v4f32 Function\n"
7669 "%v_struct1 = OpVariable %fp_struct1 Function\n"
7670 "%v_struct2 = OpVariable %fp_struct2 Function\n"
7671 " OpStore %result %param\n"
7672 " OpStore %v_struct1 %c_struct1\n"
7673 " OpStore %v_struct2 %c_struct2\n"
7674 "%ptr1 = OpAccessChain %fp_f32 %v_struct1 %c_i32_0 %c_i32_2\n"
7675 "%val1 = OpLoad %f32 %ptr1\n"
7676 "%ptr2 = OpAccessChain %fp_f32 %v_struct2 %c_i32_0 %c_i32_2\n"
7677 "%val2 = OpLoad %f32 %ptr2\n"
7678 "%addvalues = OpFAdd %f32 %val1 %val2\n"
7679 "%ptr = OpAccessChain %fp_f32 %result %c_i32_1\n"
7680 "%val = OpLoad %f32 %ptr\n"
7681 "%addresult = OpFAdd %f32 %addvalues %val\n"
7682 " OpStore %ptr %addresult\n"
7683 "%ret = OpLoad %v4f32 %result\n"
7684 " OpReturnValue %ret\n"
7687 struct CaseNameDecoration
7693 CaseNameDecoration tests[] =
7696 "same_decoration_group_on_multiple_types",
7697 "OpGroupMemberDecorate %struct_member_group %struct1 0 %struct2 0\n"
7700 "empty_decoration_group",
7701 "OpGroupDecorate %group0 %a3f32\n"
7702 "OpGroupDecorate %group0 %result\n"
7705 "one_element_decoration_group",
7706 "OpGroupDecorate %array_group %a3f32\n"
7709 "multiple_elements_decoration_group",
7710 "OpGroupDecorate %group3 %v_struct1\n"
7713 "multiple_decoration_groups_on_same_variable",
7714 "OpGroupDecorate %group0 %v_struct2\n"
7715 "OpGroupDecorate %group1 %v_struct2\n"
7716 "OpGroupDecorate %group3 %v_struct2\n"
7719 "same_decoration_group_multiple_times",
7720 "OpGroupDecorate %group1 %addvalues\n"
7721 "OpGroupDecorate %group1 %addvalues\n"
7722 "OpGroupDecorate %group1 %addvalues\n"
7727 getHalfColorsFullAlpha(inputColors);
7728 getHalfColorsFullAlpha(outputColors);
7730 for (size_t idx = 0; idx < (sizeof(tests) / sizeof(tests[0])); ++idx)
7732 fragments["decoration"] = decorations + tests[idx].decoration;
7733 fragments["pre_main"] = typesAndConstants;
7734 fragments["testfun"] = function;
7736 createTestsForAllStages(tests[idx].name, inputColors, outputColors, fragments, group.get());
7739 return group.release();
7742 struct SpecConstantTwoIntGraphicsCase
7744 const char* caseName;
7745 const char* scDefinition0;
7746 const char* scDefinition1;
7747 const char* scResultType;
7748 const char* scOperation;
7749 deInt32 scActualValue0;
7750 deInt32 scActualValue1;
7751 const char* resultOperation;
7752 RGBA expectedColors[4];
7753 deInt32 scActualValueLength;
7755 SpecConstantTwoIntGraphicsCase (const char* name,
7756 const char* definition0,
7757 const char* definition1,
7758 const char* resultType,
7759 const char* operation,
7760 const deInt32 value0,
7761 const deInt32 value1,
7762 const char* resultOp,
7763 const RGBA (&output)[4],
7764 const deInt32 valueLength = sizeof(deInt32))
7766 , scDefinition0 (definition0)
7767 , scDefinition1 (definition1)
7768 , scResultType (resultType)
7769 , scOperation (operation)
7770 , scActualValue0 (value0)
7771 , scActualValue1 (value1)
7772 , resultOperation (resultOp)
7773 , scActualValueLength (valueLength)
7775 expectedColors[0] = output[0];
7776 expectedColors[1] = output[1];
7777 expectedColors[2] = output[2];
7778 expectedColors[3] = output[3];
7782 tcu::TestCaseGroup* createSpecConstantTests (tcu::TestContext& testCtx)
7784 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opspecconstantop", "Test the OpSpecConstantOp instruction"));
7785 vector<SpecConstantTwoIntGraphicsCase> cases;
7786 RGBA inputColors[4];
7787 RGBA outputColors0[4];
7788 RGBA outputColors1[4];
7789 RGBA outputColors2[4];
7791 const deInt32 m1AsFloat16 = 0xbc00; // -1(fp16) == 1 01111 0000000000 == 1011 1100 0000 0000
7793 const char decorations1[] =
7794 "OpDecorate %sc_0 SpecId 0\n"
7795 "OpDecorate %sc_1 SpecId 1\n";
7797 const char typesAndConstants1[] =
7798 "${OPTYPE_DEFINITIONS:opt}"
7799 "%sc_0 = OpSpecConstant${SC_DEF0}\n"
7800 "%sc_1 = OpSpecConstant${SC_DEF1}\n"
7801 "%sc_op = OpSpecConstantOp ${SC_RESULT_TYPE} ${SC_OP}\n";
7803 const char function1[] =
7804 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
7805 "%param = OpFunctionParameter %v4f32\n"
7806 "%label = OpLabel\n"
7807 "%result = OpVariable %fp_v4f32 Function\n"
7808 "${TYPE_CONVERT:opt}"
7809 " OpStore %result %param\n"
7810 "%gen = ${GEN_RESULT}\n"
7811 "%index = OpIAdd %i32 %gen %c_i32_1\n"
7812 "%loc = OpAccessChain %fp_f32 %result %index\n"
7813 "%val = OpLoad %f32 %loc\n"
7814 "%add = OpFAdd %f32 %val %c_f32_0_5\n"
7815 " OpStore %loc %add\n"
7816 "%ret = OpLoad %v4f32 %result\n"
7817 " OpReturnValue %ret\n"
7820 inputColors[0] = RGBA(127, 127, 127, 255);
7821 inputColors[1] = RGBA(127, 0, 0, 255);
7822 inputColors[2] = RGBA(0, 127, 0, 255);
7823 inputColors[3] = RGBA(0, 0, 127, 255);
7825 // Derived from inputColors[x] by adding 128 to inputColors[x][0].
7826 outputColors0[0] = RGBA(255, 127, 127, 255);
7827 outputColors0[1] = RGBA(255, 0, 0, 255);
7828 outputColors0[2] = RGBA(128, 127, 0, 255);
7829 outputColors0[3] = RGBA(128, 0, 127, 255);
7831 // Derived from inputColors[x] by adding 128 to inputColors[x][1].
7832 outputColors1[0] = RGBA(127, 255, 127, 255);
7833 outputColors1[1] = RGBA(127, 128, 0, 255);
7834 outputColors1[2] = RGBA(0, 255, 0, 255);
7835 outputColors1[3] = RGBA(0, 128, 127, 255);
7837 // Derived from inputColors[x] by adding 128 to inputColors[x][2].
7838 outputColors2[0] = RGBA(127, 127, 255, 255);
7839 outputColors2[1] = RGBA(127, 0, 128, 255);
7840 outputColors2[2] = RGBA(0, 127, 128, 255);
7841 outputColors2[3] = RGBA(0, 0, 255, 255);
7843 const char addZeroToSc[] = "OpIAdd %i32 %c_i32_0 %sc_op";
7844 const char addZeroToSc32[] = "OpIAdd %i32 %c_i32_0 %sc_op32";
7845 const char selectTrueUsingSc[] = "OpSelect %i32 %sc_op %c_i32_1 %c_i32_0";
7846 const char selectFalseUsingSc[] = "OpSelect %i32 %sc_op %c_i32_0 %c_i32_1";
7848 cases.push_back(SpecConstantTwoIntGraphicsCase("iadd", " %i32 0", " %i32 0", "%i32", "IAdd %sc_0 %sc_1", 19, -20, addZeroToSc, outputColors0));
7849 cases.push_back(SpecConstantTwoIntGraphicsCase("isub", " %i32 0", " %i32 0", "%i32", "ISub %sc_0 %sc_1", 19, 20, addZeroToSc, outputColors0));
7850 cases.push_back(SpecConstantTwoIntGraphicsCase("imul", " %i32 0", " %i32 0", "%i32", "IMul %sc_0 %sc_1", -1, -1, addZeroToSc, outputColors2));
7851 cases.push_back(SpecConstantTwoIntGraphicsCase("sdiv", " %i32 0", " %i32 0", "%i32", "SDiv %sc_0 %sc_1", -126, 126, addZeroToSc, outputColors0));
7852 cases.push_back(SpecConstantTwoIntGraphicsCase("udiv", " %i32 0", " %i32 0", "%i32", "UDiv %sc_0 %sc_1", 126, 126, addZeroToSc, outputColors2));
7853 cases.push_back(SpecConstantTwoIntGraphicsCase("srem", " %i32 0", " %i32 0", "%i32", "SRem %sc_0 %sc_1", 3, 2, addZeroToSc, outputColors2));
7854 cases.push_back(SpecConstantTwoIntGraphicsCase("smod", " %i32 0", " %i32 0", "%i32", "SMod %sc_0 %sc_1", 3, 2, addZeroToSc, outputColors2));
7855 cases.push_back(SpecConstantTwoIntGraphicsCase("umod", " %i32 0", " %i32 0", "%i32", "UMod %sc_0 %sc_1", 1001, 500, addZeroToSc, outputColors2));
7856 cases.push_back(SpecConstantTwoIntGraphicsCase("bitwiseand", " %i32 0", " %i32 0", "%i32", "BitwiseAnd %sc_0 %sc_1", 0x33, 0x0d, addZeroToSc, outputColors2));
7857 cases.push_back(SpecConstantTwoIntGraphicsCase("bitwiseor", " %i32 0", " %i32 0", "%i32", "BitwiseOr %sc_0 %sc_1", 0, 1, addZeroToSc, outputColors2));
7858 cases.push_back(SpecConstantTwoIntGraphicsCase("bitwisexor", " %i32 0", " %i32 0", "%i32", "BitwiseXor %sc_0 %sc_1", 0x2e, 0x2f, addZeroToSc, outputColors2));
7859 cases.push_back(SpecConstantTwoIntGraphicsCase("shiftrightlogical", " %i32 0", " %i32 0", "%i32", "ShiftRightLogical %sc_0 %sc_1", 2, 1, addZeroToSc, outputColors2));
7860 cases.push_back(SpecConstantTwoIntGraphicsCase("shiftrightarithmetic", " %i32 0", " %i32 0", "%i32", "ShiftRightArithmetic %sc_0 %sc_1", -4, 2, addZeroToSc, outputColors0));
7861 cases.push_back(SpecConstantTwoIntGraphicsCase("shiftleftlogical", " %i32 0", " %i32 0", "%i32", "ShiftLeftLogical %sc_0 %sc_1", 1, 0, addZeroToSc, outputColors2));
7862 cases.push_back(SpecConstantTwoIntGraphicsCase("slessthan", " %i32 0", " %i32 0", "%bool", "SLessThan %sc_0 %sc_1", -20, -10, selectTrueUsingSc, outputColors2));
7863 cases.push_back(SpecConstantTwoIntGraphicsCase("ulessthan", " %i32 0", " %i32 0", "%bool", "ULessThan %sc_0 %sc_1", 10, 20, selectTrueUsingSc, outputColors2));
7864 cases.push_back(SpecConstantTwoIntGraphicsCase("sgreaterthan", " %i32 0", " %i32 0", "%bool", "SGreaterThan %sc_0 %sc_1", -1000, 50, selectFalseUsingSc, outputColors2));
7865 cases.push_back(SpecConstantTwoIntGraphicsCase("ugreaterthan", " %i32 0", " %i32 0", "%bool", "UGreaterThan %sc_0 %sc_1", 10, 5, selectTrueUsingSc, outputColors2));
7866 cases.push_back(SpecConstantTwoIntGraphicsCase("slessthanequal", " %i32 0", " %i32 0", "%bool", "SLessThanEqual %sc_0 %sc_1", -10, -10, selectTrueUsingSc, outputColors2));
7867 cases.push_back(SpecConstantTwoIntGraphicsCase("ulessthanequal", " %i32 0", " %i32 0", "%bool", "ULessThanEqual %sc_0 %sc_1", 50, 100, selectTrueUsingSc, outputColors2));
7868 cases.push_back(SpecConstantTwoIntGraphicsCase("sgreaterthanequal", " %i32 0", " %i32 0", "%bool", "SGreaterThanEqual %sc_0 %sc_1", -1000, 50, selectFalseUsingSc, outputColors2));
7869 cases.push_back(SpecConstantTwoIntGraphicsCase("ugreaterthanequal", " %i32 0", " %i32 0", "%bool", "UGreaterThanEqual %sc_0 %sc_1", 10, 10, selectTrueUsingSc, outputColors2));
7870 cases.push_back(SpecConstantTwoIntGraphicsCase("iequal", " %i32 0", " %i32 0", "%bool", "IEqual %sc_0 %sc_1", 42, 24, selectFalseUsingSc, outputColors2));
7871 cases.push_back(SpecConstantTwoIntGraphicsCase("inotequal", " %i32 0", " %i32 0", "%bool", "INotEqual %sc_0 %sc_1", 42, 24, selectTrueUsingSc, outputColors2));
7872 cases.push_back(SpecConstantTwoIntGraphicsCase("logicaland", "True %bool", "True %bool", "%bool", "LogicalAnd %sc_0 %sc_1", 0, 1, selectFalseUsingSc, outputColors2));
7873 cases.push_back(SpecConstantTwoIntGraphicsCase("logicalor", "False %bool", "False %bool", "%bool", "LogicalOr %sc_0 %sc_1", 1, 0, selectTrueUsingSc, outputColors2));
7874 cases.push_back(SpecConstantTwoIntGraphicsCase("logicalequal", "True %bool", "True %bool", "%bool", "LogicalEqual %sc_0 %sc_1", 0, 1, selectFalseUsingSc, outputColors2));
7875 cases.push_back(SpecConstantTwoIntGraphicsCase("logicalnotequal", "False %bool", "False %bool", "%bool", "LogicalNotEqual %sc_0 %sc_1", 1, 0, selectTrueUsingSc, outputColors2));
7876 cases.push_back(SpecConstantTwoIntGraphicsCase("snegate", " %i32 0", " %i32 0", "%i32", "SNegate %sc_0", -1, 0, addZeroToSc, outputColors2));
7877 cases.push_back(SpecConstantTwoIntGraphicsCase("not", " %i32 0", " %i32 0", "%i32", "Not %sc_0", -2, 0, addZeroToSc, outputColors2));
7878 cases.push_back(SpecConstantTwoIntGraphicsCase("logicalnot", "False %bool", "False %bool", "%bool", "LogicalNot %sc_0", 1, 0, selectFalseUsingSc, outputColors2));
7879 cases.push_back(SpecConstantTwoIntGraphicsCase("select", "False %bool", " %i32 0", "%i32", "Select %sc_0 %sc_1 %c_i32_0", 1, 1, addZeroToSc, outputColors2));
7880 cases.push_back(SpecConstantTwoIntGraphicsCase("sconvert", " %i32 0", " %i32 0", "%i16", "SConvert %sc_0", -1, 0, addZeroToSc32, outputColors0));
7881 // -1082130432 stored as 32-bit two's complement is the binary representation of -1 as IEEE-754 Float
7882 cases.push_back(SpecConstantTwoIntGraphicsCase("fconvert", " %f32 0", " %f32 0", "%f64", "FConvert %sc_0", -1082130432, 0, addZeroToSc32, outputColors0));
7883 cases.push_back(SpecConstantTwoIntGraphicsCase("fconvert16", " %f16 0", " %f16 0", "%f32", "FConvert %sc_0", m1AsFloat16, 0, addZeroToSc32, outputColors0, sizeof(deFloat16)));
7884 // \todo[2015-12-1 antiagainst] OpQuantizeToF16
7886 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
7888 map<string, string> specializations;
7889 map<string, string> fragments;
7890 SpecConstants specConstants;
7891 PushConstants noPushConstants;
7892 GraphicsResources noResources;
7893 GraphicsInterfaces noInterfaces;
7894 vector<string> extensions;
7895 VulkanFeatures requiredFeatures;
7897 // Special SPIR-V code for SConvert-case
7898 if (strcmp(cases[caseNdx].caseName, "sconvert") == 0)
7900 requiredFeatures.coreFeatures.shaderInt16 = VK_TRUE;
7901 fragments["capability"] = "OpCapability Int16\n"; // Adds 16-bit integer capability
7902 specializations["OPTYPE_DEFINITIONS"] = "%i16 = OpTypeInt 16 1\n"; // Adds 16-bit integer type
7903 specializations["TYPE_CONVERT"] = "%sc_op32 = OpSConvert %i32 %sc_op\n"; // Converts 16-bit integer to 32-bit integer
7906 // Special SPIR-V code for FConvert-case
7907 if (strcmp(cases[caseNdx].caseName, "fconvert") == 0)
7909 requiredFeatures.coreFeatures.shaderFloat64 = VK_TRUE;
7910 fragments["capability"] = "OpCapability Float64\n"; // Adds 64-bit float capability
7911 specializations["OPTYPE_DEFINITIONS"] = "%f64 = OpTypeFloat 64\n"; // Adds 64-bit float type
7912 specializations["TYPE_CONVERT"] = "%sc_op32 = OpConvertFToS %i32 %sc_op\n"; // Converts 64-bit float to 32-bit integer
7915 // Special SPIR-V code for FConvert-case for 16-bit floats
7916 if (strcmp(cases[caseNdx].caseName, "fconvert16") == 0)
7918 extensions.push_back("VK_KHR_shader_float16_int8");
7919 requiredFeatures.extFloat16Int8 = EXTFLOAT16INT8FEATURES_FLOAT16;
7920 fragments["capability"] = "OpCapability Float16\n"; // Adds 16-bit float capability
7921 specializations["OPTYPE_DEFINITIONS"] = "%f16 = OpTypeFloat 16\n"; // Adds 16-bit float type
7922 specializations["TYPE_CONVERT"] = "%sc_op32 = OpConvertFToS %i32 %sc_op\n"; // Converts 16-bit float to 32-bit integer
7925 specializations["SC_DEF0"] = cases[caseNdx].scDefinition0;
7926 specializations["SC_DEF1"] = cases[caseNdx].scDefinition1;
7927 specializations["SC_RESULT_TYPE"] = cases[caseNdx].scResultType;
7928 specializations["SC_OP"] = cases[caseNdx].scOperation;
7929 specializations["GEN_RESULT"] = cases[caseNdx].resultOperation;
7931 fragments["decoration"] = tcu::StringTemplate(decorations1).specialize(specializations);
7932 fragments["pre_main"] = tcu::StringTemplate(typesAndConstants1).specialize(specializations);
7933 fragments["testfun"] = tcu::StringTemplate(function1).specialize(specializations);
7935 specConstants.append(&cases[caseNdx].scActualValue0, cases[caseNdx].scActualValueLength);
7936 specConstants.append(&cases[caseNdx].scActualValue1, cases[caseNdx].scActualValueLength);
7938 createTestsForAllStages(
7939 cases[caseNdx].caseName, inputColors, cases[caseNdx].expectedColors, fragments, specConstants,
7940 noPushConstants, noResources, noInterfaces, extensions, requiredFeatures, group.get());
7943 const char decorations2[] =
7944 "OpDecorate %sc_0 SpecId 0\n"
7945 "OpDecorate %sc_1 SpecId 1\n"
7946 "OpDecorate %sc_2 SpecId 2\n";
7948 const char typesAndConstants2[] =
7949 "%vec3_0 = OpConstantComposite %v3i32 %c_i32_0 %c_i32_0 %c_i32_0\n"
7950 "%vec3_undef = OpUndef %v3i32\n"
7952 "%sc_0 = OpSpecConstant %i32 0\n"
7953 "%sc_1 = OpSpecConstant %i32 0\n"
7954 "%sc_2 = OpSpecConstant %i32 0\n"
7955 "%sc_vec3_0 = OpSpecConstantOp %v3i32 CompositeInsert %sc_0 %vec3_0 0\n" // (sc_0, 0, 0)
7956 "%sc_vec3_1 = OpSpecConstantOp %v3i32 CompositeInsert %sc_1 %vec3_0 1\n" // (0, sc_1, 0)
7957 "%sc_vec3_2 = OpSpecConstantOp %v3i32 CompositeInsert %sc_2 %vec3_0 2\n" // (0, 0, sc_2)
7958 "%sc_vec3_0_s = OpSpecConstantOp %v3i32 VectorShuffle %sc_vec3_0 %vec3_undef 0 0xFFFFFFFF 2\n" // (sc_0, ???, 0)
7959 "%sc_vec3_1_s = OpSpecConstantOp %v3i32 VectorShuffle %sc_vec3_1 %vec3_undef 0xFFFFFFFF 1 0\n" // (???, sc_1, 0)
7960 "%sc_vec3_2_s = OpSpecConstantOp %v3i32 VectorShuffle %vec3_undef %sc_vec3_2 5 0xFFFFFFFF 5\n" // (sc_2, ???, sc_2)
7961 "%sc_vec3_01 = OpSpecConstantOp %v3i32 VectorShuffle %sc_vec3_0_s %sc_vec3_1_s 1 0 4\n" // (0, sc_0, sc_1)
7962 "%sc_vec3_012 = OpSpecConstantOp %v3i32 VectorShuffle %sc_vec3_01 %sc_vec3_2_s 5 1 2\n" // (sc_2, sc_0, sc_1)
7963 "%sc_ext_0 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 0\n" // sc_2
7964 "%sc_ext_1 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 1\n" // sc_0
7965 "%sc_ext_2 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 2\n" // sc_1
7966 "%sc_sub = OpSpecConstantOp %i32 ISub %sc_ext_0 %sc_ext_1\n" // (sc_2 - sc_0)
7967 "%sc_final = OpSpecConstantOp %i32 IMul %sc_sub %sc_ext_2\n"; // (sc_2 - sc_0) * sc_1
7969 const char function2[] =
7970 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
7971 "%param = OpFunctionParameter %v4f32\n"
7972 "%label = OpLabel\n"
7973 "%result = OpVariable %fp_v4f32 Function\n"
7974 " OpStore %result %param\n"
7975 "%loc = OpAccessChain %fp_f32 %result %sc_final\n"
7976 "%val = OpLoad %f32 %loc\n"
7977 "%add = OpFAdd %f32 %val %c_f32_0_5\n"
7978 " OpStore %loc %add\n"
7979 "%ret = OpLoad %v4f32 %result\n"
7980 " OpReturnValue %ret\n"
7983 map<string, string> fragments;
7984 SpecConstants specConstants;
7986 fragments["decoration"] = decorations2;
7987 fragments["pre_main"] = typesAndConstants2;
7988 fragments["testfun"] = function2;
7990 specConstants.append<deInt32>(56789);
7991 specConstants.append<deInt32>(-2);
7992 specConstants.append<deInt32>(56788);
7994 createTestsForAllStages("vector_related", inputColors, outputColors2, fragments, specConstants, group.get());
7996 return group.release();
7999 tcu::TestCaseGroup* createOpPhiTests(tcu::TestContext& testCtx)
8001 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opphi", "Test the OpPhi instruction"));
8002 RGBA inputColors[4];
8003 RGBA outputColors1[4];
8004 RGBA outputColors2[4];
8005 RGBA outputColors3[4];
8006 RGBA outputColors4[4];
8007 map<string, string> fragments1;
8008 map<string, string> fragments2;
8009 map<string, string> fragments3;
8010 map<string, string> fragments4;
8011 std::vector<std::string> extensions4;
8012 GraphicsResources resources4;
8013 VulkanFeatures vulkanFeatures4;
8015 const char typesAndConstants1[] =
8016 "%c_f32_p2 = OpConstant %f32 0.2\n"
8017 "%c_f32_p4 = OpConstant %f32 0.4\n"
8018 "%c_f32_p5 = OpConstant %f32 0.5\n"
8019 "%c_f32_p8 = OpConstant %f32 0.8\n";
8021 // vec4 test_code(vec4 param) {
8022 // vec4 result = param;
8023 // for (int i = 0; i < 4; ++i) {
8026 // case 0: operand = .2; break;
8027 // case 1: operand = .5; break;
8028 // case 2: operand = .4; break;
8029 // case 3: operand = .0; break;
8030 // default: break; // unreachable
8032 // result[i] += operand;
8036 const char function1[] =
8037 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
8038 "%param1 = OpFunctionParameter %v4f32\n"
8040 "%iptr = OpVariable %fp_i32 Function\n"
8041 "%result = OpVariable %fp_v4f32 Function\n"
8042 " OpStore %iptr %c_i32_0\n"
8043 " OpStore %result %param1\n"
8047 "%ival = OpLoad %i32 %iptr\n"
8048 "%lt_4 = OpSLessThan %bool %ival %c_i32_4\n"
8049 " OpLoopMerge %exit %cont None\n"
8050 " OpBranchConditional %lt_4 %entry %exit\n"
8052 "%entry = OpLabel\n"
8053 "%loc = OpAccessChain %fp_f32 %result %ival\n"
8054 "%val = OpLoad %f32 %loc\n"
8055 " OpSelectionMerge %phi None\n"
8056 " OpSwitch %ival %default 0 %case0 1 %case1 2 %case2 3 %case3\n"
8058 "%case0 = OpLabel\n"
8060 "%case1 = OpLabel\n"
8062 "%case2 = OpLabel\n"
8064 "%case3 = OpLabel\n"
8067 "%default = OpLabel\n"
8071 "%operand = OpPhi %f32 %c_f32_p4 %case2 %c_f32_p5 %case1 %c_f32_p2 %case0 %c_f32_0 %case3\n" // not in the order of blocks
8074 "%add = OpFAdd %f32 %val %operand\n"
8075 " OpStore %loc %add\n"
8076 "%ival_next = OpIAdd %i32 %ival %c_i32_1\n"
8077 " OpStore %iptr %ival_next\n"
8081 "%ret = OpLoad %v4f32 %result\n"
8082 " OpReturnValue %ret\n"
8086 fragments1["pre_main"] = typesAndConstants1;
8087 fragments1["testfun"] = function1;
8089 getHalfColorsFullAlpha(inputColors);
8091 outputColors1[0] = RGBA(178, 255, 229, 255);
8092 outputColors1[1] = RGBA(178, 127, 102, 255);
8093 outputColors1[2] = RGBA(51, 255, 102, 255);
8094 outputColors1[3] = RGBA(51, 127, 229, 255);
8096 createTestsForAllStages("out_of_order", inputColors, outputColors1, fragments1, group.get());
8098 const char typesAndConstants2[] =
8099 "%c_f32_p2 = OpConstant %f32 0.2\n";
8101 // Add .4 to the second element of the given parameter.
8102 const char function2[] =
8103 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
8104 "%param = OpFunctionParameter %v4f32\n"
8105 "%entry = OpLabel\n"
8106 "%result = OpVariable %fp_v4f32 Function\n"
8107 " OpStore %result %param\n"
8108 "%loc = OpAccessChain %fp_f32 %result %c_i32_1\n"
8109 "%val = OpLoad %f32 %loc\n"
8113 "%step = OpPhi %i32 %c_i32_0 %entry %step_next %phi\n"
8114 "%accum = OpPhi %f32 %val %entry %accum_next %phi\n"
8115 "%step_next = OpIAdd %i32 %step %c_i32_1\n"
8116 "%accum_next = OpFAdd %f32 %accum %c_f32_p2\n"
8117 "%still_loop = OpSLessThan %bool %step %c_i32_2\n"
8118 " OpLoopMerge %exit %phi None\n"
8119 " OpBranchConditional %still_loop %phi %exit\n"
8122 " OpStore %loc %accum\n"
8123 "%ret = OpLoad %v4f32 %result\n"
8124 " OpReturnValue %ret\n"
8128 fragments2["pre_main"] = typesAndConstants2;
8129 fragments2["testfun"] = function2;
8131 outputColors2[0] = RGBA(127, 229, 127, 255);
8132 outputColors2[1] = RGBA(127, 102, 0, 255);
8133 outputColors2[2] = RGBA(0, 229, 0, 255);
8134 outputColors2[3] = RGBA(0, 102, 127, 255);
8136 createTestsForAllStages("induction", inputColors, outputColors2, fragments2, group.get());
8138 const char typesAndConstants3[] =
8139 "%true = OpConstantTrue %bool\n"
8140 "%false = OpConstantFalse %bool\n"
8141 "%c_f32_p2 = OpConstant %f32 0.2\n";
8143 // Swap the second and the third element of the given parameter.
8144 const char function3[] =
8145 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
8146 "%param = OpFunctionParameter %v4f32\n"
8147 "%entry = OpLabel\n"
8148 "%result = OpVariable %fp_v4f32 Function\n"
8149 " OpStore %result %param\n"
8150 "%a_loc = OpAccessChain %fp_f32 %result %c_i32_1\n"
8151 "%a_init = OpLoad %f32 %a_loc\n"
8152 "%b_loc = OpAccessChain %fp_f32 %result %c_i32_2\n"
8153 "%b_init = OpLoad %f32 %b_loc\n"
8157 "%still_loop = OpPhi %bool %true %entry %false %phi\n"
8158 "%a_next = OpPhi %f32 %a_init %entry %b_next %phi\n"
8159 "%b_next = OpPhi %f32 %b_init %entry %a_next %phi\n"
8160 " OpLoopMerge %exit %phi None\n"
8161 " OpBranchConditional %still_loop %phi %exit\n"
8164 " OpStore %a_loc %a_next\n"
8165 " OpStore %b_loc %b_next\n"
8166 "%ret = OpLoad %v4f32 %result\n"
8167 " OpReturnValue %ret\n"
8171 fragments3["pre_main"] = typesAndConstants3;
8172 fragments3["testfun"] = function3;
8174 outputColors3[0] = RGBA(127, 127, 127, 255);
8175 outputColors3[1] = RGBA(127, 0, 0, 255);
8176 outputColors3[2] = RGBA(0, 0, 127, 255);
8177 outputColors3[3] = RGBA(0, 127, 0, 255);
8179 createTestsForAllStages("swap", inputColors, outputColors3, fragments3, group.get());
8181 const char typesAndConstants4[] =
8182 "%f16 = OpTypeFloat 16\n"
8183 "%v4f16 = OpTypeVector %f16 4\n"
8184 "%fp_f16 = OpTypePointer Function %f16\n"
8185 "%fp_v4f16 = OpTypePointer Function %v4f16\n"
8186 "%true = OpConstantTrue %bool\n"
8187 "%false = OpConstantFalse %bool\n"
8188 "%c_f32_p2 = OpConstant %f32 0.2\n";
8190 // Swap the second and the third element of the given parameter.
8191 const char function4[] =
8192 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
8193 "%param = OpFunctionParameter %v4f32\n"
8194 "%entry = OpLabel\n"
8195 "%result = OpVariable %fp_v4f16 Function\n"
8196 "%param16 = OpFConvert %v4f16 %param\n"
8197 " OpStore %result %param16\n"
8198 "%a_loc = OpAccessChain %fp_f16 %result %c_i32_1\n"
8199 "%a_init = OpLoad %f16 %a_loc\n"
8200 "%b_loc = OpAccessChain %fp_f16 %result %c_i32_2\n"
8201 "%b_init = OpLoad %f16 %b_loc\n"
8205 "%still_loop = OpPhi %bool %true %entry %false %phi\n"
8206 "%a_next = OpPhi %f16 %a_init %entry %b_next %phi\n"
8207 "%b_next = OpPhi %f16 %b_init %entry %a_next %phi\n"
8208 " OpLoopMerge %exit %phi None\n"
8209 " OpBranchConditional %still_loop %phi %exit\n"
8212 " OpStore %a_loc %a_next\n"
8213 " OpStore %b_loc %b_next\n"
8214 "%ret16 = OpLoad %v4f16 %result\n"
8215 "%ret = OpFConvert %v4f32 %ret16\n"
8216 " OpReturnValue %ret\n"
8220 fragments4["pre_main"] = typesAndConstants4;
8221 fragments4["testfun"] = function4;
8222 fragments4["capability"] = "OpCapability StorageUniformBufferBlock16\nOpCapability Float16\n";
8223 fragments4["extension"] = "OpExtension \"SPV_KHR_16bit_storage\"";
8225 extensions4.push_back("VK_KHR_16bit_storage");
8226 extensions4.push_back("VK_KHR_shader_float16_int8");
8228 vulkanFeatures4.ext16BitStorage = EXT16BITSTORAGEFEATURES_UNIFORM_BUFFER_BLOCK;
8229 vulkanFeatures4.extFloat16Int8 = EXTFLOAT16INT8FEATURES_FLOAT16;
8231 outputColors4[0] = RGBA(127, 127, 127, 255);
8232 outputColors4[1] = RGBA(127, 0, 0, 255);
8233 outputColors4[2] = RGBA(0, 0, 127, 255);
8234 outputColors4[3] = RGBA(0, 127, 0, 255);
8236 createTestsForAllStages("swap16", inputColors, outputColors4, fragments4, resources4, extensions4, group.get(), vulkanFeatures4);
8238 return group.release();
8241 tcu::TestCaseGroup* createNoContractionTests(tcu::TestContext& testCtx)
8243 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "nocontraction", "Test the NoContraction decoration"));
8244 RGBA inputColors[4];
8245 RGBA outputColors[4];
8247 // With NoContraction, (1 + 2^-23) * (1 - 2^-23) - 1 should be conducted as a multiplication and an addition separately.
8248 // For the multiplication, the result is 1 - 2^-46, which is out of the precision range for 32-bit float. (32-bit float
8249 // only have 23-bit fraction.) So it will be rounded to 1. Or 0x1.fffffc. Then the final result is 0 or -0x1p-24.
8250 // On the contrary, the result will be 2^-46, which is a normalized number perfectly representable as 32-bit float.
8251 const char constantsAndTypes[] =
8252 "%c_vec4_0 = OpConstantComposite %v4f32 %c_f32_0 %c_f32_0 %c_f32_0 %c_f32_1\n"
8253 "%c_vec4_1 = OpConstantComposite %v4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_1\n"
8254 "%c_f32_1pl2_23 = OpConstant %f32 0x1.000002p+0\n" // 1 + 2^-23
8255 "%c_f32_1mi2_23 = OpConstant %f32 0x1.fffffcp-1\n" // 1 - 2^-23
8256 "%c_f32_n1pn24 = OpConstant %f32 -0x1p-24\n";
8258 const char function[] =
8259 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
8260 "%param = OpFunctionParameter %v4f32\n"
8261 "%label = OpLabel\n"
8262 "%var1 = OpVariable %fp_f32 Function %c_f32_1pl2_23\n"
8263 "%var2 = OpVariable %fp_f32 Function\n"
8264 "%red = OpCompositeExtract %f32 %param 0\n"
8265 "%plus_red = OpFAdd %f32 %c_f32_1mi2_23 %red\n"
8266 " OpStore %var2 %plus_red\n"
8267 "%val1 = OpLoad %f32 %var1\n"
8268 "%val2 = OpLoad %f32 %var2\n"
8269 "%mul = OpFMul %f32 %val1 %val2\n"
8270 "%add = OpFAdd %f32 %mul %c_f32_n1\n"
8271 "%is0 = OpFOrdEqual %bool %add %c_f32_0\n"
8272 "%isn1n24 = OpFOrdEqual %bool %add %c_f32_n1pn24\n"
8273 "%success = OpLogicalOr %bool %is0 %isn1n24\n"
8274 "%v4success = OpCompositeConstruct %v4bool %success %success %success %success\n"
8275 "%ret = OpSelect %v4f32 %v4success %c_vec4_0 %c_vec4_1\n"
8276 " OpReturnValue %ret\n"
8279 struct CaseNameDecoration
8286 CaseNameDecoration tests[] = {
8287 {"multiplication", "OpDecorate %mul NoContraction"},
8288 {"addition", "OpDecorate %add NoContraction"},
8289 {"both", "OpDecorate %mul NoContraction\nOpDecorate %add NoContraction"},
8292 getHalfColorsFullAlpha(inputColors);
8294 for (deUint8 idx = 0; idx < 4; ++idx)
8296 inputColors[idx].setRed(0);
8297 outputColors[idx] = RGBA(0, 0, 0, 255);
8300 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(CaseNameDecoration); ++testNdx)
8302 map<string, string> fragments;
8304 fragments["decoration"] = tests[testNdx].decoration;
8305 fragments["pre_main"] = constantsAndTypes;
8306 fragments["testfun"] = function;
8308 createTestsForAllStages(tests[testNdx].name, inputColors, outputColors, fragments, group.get());
8311 return group.release();
8314 tcu::TestCaseGroup* createMemoryAccessTests(tcu::TestContext& testCtx)
8316 de::MovePtr<tcu::TestCaseGroup> memoryAccessTests (new tcu::TestCaseGroup(testCtx, "opmemoryaccess", "Memory Semantics"));
8319 const char constantsAndTypes[] =
8320 "%c_a2f32_1 = OpConstantComposite %a2f32 %c_f32_1 %c_f32_1\n"
8321 "%fp_a2f32 = OpTypePointer Function %a2f32\n"
8322 "%stype = OpTypeStruct %v4f32 %a2f32 %f32\n"
8323 "%fp_stype = OpTypePointer Function %stype\n";
8325 const char function[] =
8326 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
8327 "%param1 = OpFunctionParameter %v4f32\n"
8329 "%v1 = OpVariable %fp_v4f32 Function\n"
8330 "%v2 = OpVariable %fp_a2f32 Function\n"
8331 "%v3 = OpVariable %fp_f32 Function\n"
8332 "%v = OpVariable %fp_stype Function\n"
8333 "%vv = OpVariable %fp_stype Function\n"
8334 "%vvv = OpVariable %fp_f32 Function\n"
8336 " OpStore %v1 %c_v4f32_1_1_1_1\n"
8337 " OpStore %v2 %c_a2f32_1\n"
8338 " OpStore %v3 %c_f32_1\n"
8340 "%p_v4f32 = OpAccessChain %fp_v4f32 %v %c_u32_0\n"
8341 "%p_a2f32 = OpAccessChain %fp_a2f32 %v %c_u32_1\n"
8342 "%p_f32 = OpAccessChain %fp_f32 %v %c_u32_2\n"
8343 "%v1_v = OpLoad %v4f32 %v1 ${access_type}\n"
8344 "%v2_v = OpLoad %a2f32 %v2 ${access_type}\n"
8345 "%v3_v = OpLoad %f32 %v3 ${access_type}\n"
8347 " OpStore %p_v4f32 %v1_v ${access_type}\n"
8348 " OpStore %p_a2f32 %v2_v ${access_type}\n"
8349 " OpStore %p_f32 %v3_v ${access_type}\n"
8351 " OpCopyMemory %vv %v ${access_type}\n"
8352 " OpCopyMemory %vvv %p_f32 ${access_type}\n"
8354 "%p_f32_2 = OpAccessChain %fp_f32 %vv %c_u32_2\n"
8355 "%v_f32_2 = OpLoad %f32 %p_f32_2\n"
8356 "%v_f32_3 = OpLoad %f32 %vvv\n"
8358 "%ret1 = OpVectorTimesScalar %v4f32 %param1 %v_f32_2\n"
8359 "%ret2 = OpVectorTimesScalar %v4f32 %ret1 %v_f32_3\n"
8360 " OpReturnValue %ret2\n"
8363 struct NameMemoryAccess
8370 NameMemoryAccess tests[] =
8373 { "volatile", "Volatile" },
8374 { "aligned", "Aligned 1" },
8375 { "volatile_aligned", "Volatile|Aligned 1" },
8376 { "nontemporal_aligned", "Nontemporal|Aligned 1" },
8377 { "volatile_nontemporal", "Volatile|Nontemporal" },
8378 { "volatile_nontermporal_aligned", "Volatile|Nontemporal|Aligned 1" },
8381 getHalfColorsFullAlpha(colors);
8383 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameMemoryAccess); ++testNdx)
8385 map<string, string> fragments;
8386 map<string, string> memoryAccess;
8387 memoryAccess["access_type"] = tests[testNdx].accessType;
8389 fragments["pre_main"] = constantsAndTypes;
8390 fragments["testfun"] = tcu::StringTemplate(function).specialize(memoryAccess);
8391 createTestsForAllStages(tests[testNdx].name, colors, colors, fragments, memoryAccessTests.get());
8393 return memoryAccessTests.release();
8395 tcu::TestCaseGroup* createOpUndefTests(tcu::TestContext& testCtx)
8397 de::MovePtr<tcu::TestCaseGroup> opUndefTests (new tcu::TestCaseGroup(testCtx, "opundef", "Test OpUndef"));
8398 RGBA defaultColors[4];
8399 map<string, string> fragments;
8400 getDefaultColors(defaultColors);
8402 // First, simple cases that don't do anything with the OpUndef result.
8403 struct NameCodePair { string name, decl, type; };
8404 const NameCodePair tests[] =
8406 {"bool", "", "%bool"},
8407 {"vec2uint32", "", "%v2u32"},
8408 {"image", "%type = OpTypeImage %f32 2D 0 0 0 1 Unknown", "%type"},
8409 {"sampler", "%type = OpTypeSampler", "%type"},
8410 {"sampledimage", "%img = OpTypeImage %f32 2D 0 0 0 1 Unknown\n" "%type = OpTypeSampledImage %img", "%type"},
8411 {"pointer", "", "%fp_i32"},
8412 {"runtimearray", "%type = OpTypeRuntimeArray %f32", "%type"},
8413 {"array", "%c_u32_100 = OpConstant %u32 100\n" "%type = OpTypeArray %i32 %c_u32_100", "%type"},
8414 {"struct", "%type = OpTypeStruct %f32 %i32 %u32", "%type"}};
8415 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameCodePair); ++testNdx)
8417 fragments["undef_type"] = tests[testNdx].type;
8418 fragments["testfun"] = StringTemplate(
8419 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
8420 "%param1 = OpFunctionParameter %v4f32\n"
8421 "%label_testfun = OpLabel\n"
8422 "%undef = OpUndef ${undef_type}\n"
8423 "OpReturnValue %param1\n"
8424 "OpFunctionEnd\n").specialize(fragments);
8425 fragments["pre_main"] = tests[testNdx].decl;
8426 createTestsForAllStages(tests[testNdx].name, defaultColors, defaultColors, fragments, opUndefTests.get());
8430 fragments["testfun"] =
8431 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
8432 "%param1 = OpFunctionParameter %v4f32\n"
8433 "%label_testfun = OpLabel\n"
8434 "%undef = OpUndef %f32\n"
8435 "%zero = OpFMul %f32 %undef %c_f32_0\n"
8436 "%is_nan = OpIsNan %bool %zero\n" //OpUndef may result in NaN which may turn %zero into Nan.
8437 "%actually_zero = OpSelect %f32 %is_nan %c_f32_0 %zero\n"
8438 "%a = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
8439 "%b = OpFAdd %f32 %a %actually_zero\n"
8440 "%ret = OpVectorInsertDynamic %v4f32 %param1 %b %c_i32_0\n"
8441 "OpReturnValue %ret\n"
8444 createTestsForAllStages("float32", defaultColors, defaultColors, fragments, opUndefTests.get());
8446 fragments["testfun"] =
8447 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
8448 "%param1 = OpFunctionParameter %v4f32\n"
8449 "%label_testfun = OpLabel\n"
8450 "%undef = OpUndef %i32\n"
8451 "%zero = OpIMul %i32 %undef %c_i32_0\n"
8452 "%a = OpVectorExtractDynamic %f32 %param1 %zero\n"
8453 "%ret = OpVectorInsertDynamic %v4f32 %param1 %a %c_i32_0\n"
8454 "OpReturnValue %ret\n"
8457 createTestsForAllStages("sint32", defaultColors, defaultColors, fragments, opUndefTests.get());
8459 fragments["testfun"] =
8460 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
8461 "%param1 = OpFunctionParameter %v4f32\n"
8462 "%label_testfun = OpLabel\n"
8463 "%undef = OpUndef %u32\n"
8464 "%zero = OpIMul %u32 %undef %c_i32_0\n"
8465 "%a = OpVectorExtractDynamic %f32 %param1 %zero\n"
8466 "%ret = OpVectorInsertDynamic %v4f32 %param1 %a %c_i32_0\n"
8467 "OpReturnValue %ret\n"
8470 createTestsForAllStages("uint32", defaultColors, defaultColors, fragments, opUndefTests.get());
8472 fragments["testfun"] =
8473 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
8474 "%param1 = OpFunctionParameter %v4f32\n"
8475 "%label_testfun = OpLabel\n"
8476 "%undef = OpUndef %v4f32\n"
8477 "%vzero = OpVectorTimesScalar %v4f32 %undef %c_f32_0\n"
8478 "%zero_0 = OpVectorExtractDynamic %f32 %vzero %c_i32_0\n"
8479 "%zero_1 = OpVectorExtractDynamic %f32 %vzero %c_i32_1\n"
8480 "%zero_2 = OpVectorExtractDynamic %f32 %vzero %c_i32_2\n"
8481 "%zero_3 = OpVectorExtractDynamic %f32 %vzero %c_i32_3\n"
8482 "%is_nan_0 = OpIsNan %bool %zero_0\n"
8483 "%is_nan_1 = OpIsNan %bool %zero_1\n"
8484 "%is_nan_2 = OpIsNan %bool %zero_2\n"
8485 "%is_nan_3 = OpIsNan %bool %zero_3\n"
8486 "%actually_zero_0 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_0\n"
8487 "%actually_zero_1 = OpSelect %f32 %is_nan_1 %c_f32_0 %zero_1\n"
8488 "%actually_zero_2 = OpSelect %f32 %is_nan_2 %c_f32_0 %zero_2\n"
8489 "%actually_zero_3 = OpSelect %f32 %is_nan_3 %c_f32_0 %zero_3\n"
8490 "%param1_0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
8491 "%param1_1 = OpVectorExtractDynamic %f32 %param1 %c_i32_1\n"
8492 "%param1_2 = OpVectorExtractDynamic %f32 %param1 %c_i32_2\n"
8493 "%param1_3 = OpVectorExtractDynamic %f32 %param1 %c_i32_3\n"
8494 "%sum_0 = OpFAdd %f32 %param1_0 %actually_zero_0\n"
8495 "%sum_1 = OpFAdd %f32 %param1_1 %actually_zero_1\n"
8496 "%sum_2 = OpFAdd %f32 %param1_2 %actually_zero_2\n"
8497 "%sum_3 = OpFAdd %f32 %param1_3 %actually_zero_3\n"
8498 "%ret3 = OpVectorInsertDynamic %v4f32 %param1 %sum_3 %c_i32_3\n"
8499 "%ret2 = OpVectorInsertDynamic %v4f32 %ret3 %sum_2 %c_i32_2\n"
8500 "%ret1 = OpVectorInsertDynamic %v4f32 %ret2 %sum_1 %c_i32_1\n"
8501 "%ret = OpVectorInsertDynamic %v4f32 %ret1 %sum_0 %c_i32_0\n"
8502 "OpReturnValue %ret\n"
8505 createTestsForAllStages("vec4float32", defaultColors, defaultColors, fragments, opUndefTests.get());
8507 fragments["pre_main"] =
8508 "%m2x2f32 = OpTypeMatrix %v2f32 2\n";
8509 fragments["testfun"] =
8510 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
8511 "%param1 = OpFunctionParameter %v4f32\n"
8512 "%label_testfun = OpLabel\n"
8513 "%undef = OpUndef %m2x2f32\n"
8514 "%mzero = OpMatrixTimesScalar %m2x2f32 %undef %c_f32_0\n"
8515 "%zero_0 = OpCompositeExtract %f32 %mzero 0 0\n"
8516 "%zero_1 = OpCompositeExtract %f32 %mzero 0 1\n"
8517 "%zero_2 = OpCompositeExtract %f32 %mzero 1 0\n"
8518 "%zero_3 = OpCompositeExtract %f32 %mzero 1 1\n"
8519 "%is_nan_0 = OpIsNan %bool %zero_0\n"
8520 "%is_nan_1 = OpIsNan %bool %zero_1\n"
8521 "%is_nan_2 = OpIsNan %bool %zero_2\n"
8522 "%is_nan_3 = OpIsNan %bool %zero_3\n"
8523 "%actually_zero_0 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_0\n"
8524 "%actually_zero_1 = OpSelect %f32 %is_nan_1 %c_f32_0 %zero_1\n"
8525 "%actually_zero_2 = OpSelect %f32 %is_nan_2 %c_f32_0 %zero_2\n"
8526 "%actually_zero_3 = OpSelect %f32 %is_nan_3 %c_f32_0 %zero_3\n"
8527 "%param1_0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
8528 "%param1_1 = OpVectorExtractDynamic %f32 %param1 %c_i32_1\n"
8529 "%param1_2 = OpVectorExtractDynamic %f32 %param1 %c_i32_2\n"
8530 "%param1_3 = OpVectorExtractDynamic %f32 %param1 %c_i32_3\n"
8531 "%sum_0 = OpFAdd %f32 %param1_0 %actually_zero_0\n"
8532 "%sum_1 = OpFAdd %f32 %param1_1 %actually_zero_1\n"
8533 "%sum_2 = OpFAdd %f32 %param1_2 %actually_zero_2\n"
8534 "%sum_3 = OpFAdd %f32 %param1_3 %actually_zero_3\n"
8535 "%ret3 = OpVectorInsertDynamic %v4f32 %param1 %sum_3 %c_i32_3\n"
8536 "%ret2 = OpVectorInsertDynamic %v4f32 %ret3 %sum_2 %c_i32_2\n"
8537 "%ret1 = OpVectorInsertDynamic %v4f32 %ret2 %sum_1 %c_i32_1\n"
8538 "%ret = OpVectorInsertDynamic %v4f32 %ret1 %sum_0 %c_i32_0\n"
8539 "OpReturnValue %ret\n"
8542 createTestsForAllStages("matrix", defaultColors, defaultColors, fragments, opUndefTests.get());
8544 return opUndefTests.release();
8547 void createOpQuantizeSingleOptionTests(tcu::TestCaseGroup* testCtx)
8549 const RGBA inputColors[4] =
8552 RGBA(0, 0, 255, 255),
8553 RGBA(0, 255, 0, 255),
8554 RGBA(0, 255, 255, 255)
8557 const RGBA expectedColors[4] =
8559 RGBA(255, 0, 0, 255),
8560 RGBA(255, 0, 0, 255),
8561 RGBA(255, 0, 0, 255),
8562 RGBA(255, 0, 0, 255)
8565 const struct SingleFP16Possibility
8568 const char* constant; // Value to assign to %test_constant.
8570 const char* condition; // Must assign to %cond an expression that evaluates to true after %c = OpQuantizeToF16(%test_constant + 0).
8576 -constructNormalizedFloat(1, 0x300000),
8577 "%cond = OpFOrdEqual %bool %c %test_constant\n"
8582 constructNormalizedFloat(7, 0x000000),
8583 "%cond = OpFOrdEqual %bool %c %test_constant\n"
8585 // SPIR-V requires that OpQuantizeToF16 flushes
8586 // any numbers that would end up denormalized in F16 to zero.
8590 std::ldexp(1.5f, -140),
8591 "%cond = OpFOrdEqual %bool %c %c_f32_0\n"
8596 -std::ldexp(1.5f, -140),
8597 "%cond = OpFOrdEqual %bool %c %c_f32_0\n"
8602 std::ldexp(1.0f, -16),
8603 "%cond = OpFOrdEqual %bool %c %c_f32_0\n"
8604 }, // too small positive
8606 "negative_too_small",
8608 -std::ldexp(1.0f, -32),
8609 "%cond = OpFOrdEqual %bool %c %c_f32_0\n"
8610 }, // too small negative
8614 -std::ldexp(1.0f, 128),
8616 "%gz = OpFOrdLessThan %bool %c %c_f32_0\n"
8617 "%inf = OpIsInf %bool %c\n"
8618 "%cond = OpLogicalAnd %bool %gz %inf\n"
8623 std::ldexp(1.0f, 128),
8625 "%gz = OpFOrdGreaterThan %bool %c %c_f32_0\n"
8626 "%inf = OpIsInf %bool %c\n"
8627 "%cond = OpLogicalAnd %bool %gz %inf\n"
8630 "round_to_negative_inf",
8632 -std::ldexp(1.0f, 32),
8634 "%gz = OpFOrdLessThan %bool %c %c_f32_0\n"
8635 "%inf = OpIsInf %bool %c\n"
8636 "%cond = OpLogicalAnd %bool %gz %inf\n"
8641 std::ldexp(1.0f, 16),
8643 "%gz = OpFOrdGreaterThan %bool %c %c_f32_0\n"
8644 "%inf = OpIsInf %bool %c\n"
8645 "%cond = OpLogicalAnd %bool %gz %inf\n"
8650 std::numeric_limits<float>::quiet_NaN(),
8652 // Test for any NaN value, as NaNs are not preserved
8653 "%direct_quant = OpQuantizeToF16 %f32 %test_constant\n"
8654 "%cond = OpIsNan %bool %direct_quant\n"
8659 std::numeric_limits<float>::quiet_NaN(),
8661 // Test for any NaN value, as NaNs are not preserved
8662 "%direct_quant = OpQuantizeToF16 %f32 %test_constant\n"
8663 "%cond = OpIsNan %bool %direct_quant\n"
8666 const char* constants =
8667 "%test_constant = OpConstant %f32 "; // The value will be test.constant.
8669 StringTemplate function (
8670 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
8671 "%param1 = OpFunctionParameter %v4f32\n"
8672 "%label_testfun = OpLabel\n"
8673 "%a = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
8674 "%b = OpFAdd %f32 %test_constant %a\n"
8675 "%c = OpQuantizeToF16 %f32 %b\n"
8677 "%v4cond = OpCompositeConstruct %v4bool %cond %cond %cond %cond\n"
8678 "%retval = OpSelect %v4f32 %v4cond %c_v4f32_1_0_0_1 %param1\n"
8679 " OpReturnValue %retval\n"
8683 const char* specDecorations = "OpDecorate %test_constant SpecId 0\n";
8684 const char* specConstants =
8685 "%test_constant = OpSpecConstant %f32 0.\n"
8686 "%c = OpSpecConstantOp %f32 QuantizeToF16 %test_constant\n";
8688 StringTemplate specConstantFunction(
8689 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
8690 "%param1 = OpFunctionParameter %v4f32\n"
8691 "%label_testfun = OpLabel\n"
8693 "%v4cond = OpCompositeConstruct %v4bool %cond %cond %cond %cond\n"
8694 "%retval = OpSelect %v4f32 %v4cond %c_v4f32_1_0_0_1 %param1\n"
8695 " OpReturnValue %retval\n"
8699 for (size_t idx = 0; idx < (sizeof(tests)/sizeof(tests[0])); ++idx)
8701 map<string, string> codeSpecialization;
8702 map<string, string> fragments;
8703 codeSpecialization["condition"] = tests[idx].condition;
8704 fragments["testfun"] = function.specialize(codeSpecialization);
8705 fragments["pre_main"] = string(constants) + tests[idx].constant + "\n";
8706 createTestsForAllStages(tests[idx].name, inputColors, expectedColors, fragments, testCtx);
8709 for (size_t idx = 0; idx < (sizeof(tests)/sizeof(tests[0])); ++idx)
8711 map<string, string> codeSpecialization;
8712 map<string, string> fragments;
8713 SpecConstants passConstants;
8715 codeSpecialization["condition"] = tests[idx].condition;
8716 fragments["testfun"] = specConstantFunction.specialize(codeSpecialization);
8717 fragments["decoration"] = specDecorations;
8718 fragments["pre_main"] = specConstants;
8720 passConstants.append<float>(tests[idx].valueAsFloat);
8722 createTestsForAllStages(string("spec_const_") + tests[idx].name, inputColors, expectedColors, fragments, passConstants, testCtx);
8726 void createOpQuantizeTwoPossibilityTests(tcu::TestCaseGroup* testCtx)
8728 RGBA inputColors[4] = {
8730 RGBA(0, 0, 255, 255),
8731 RGBA(0, 255, 0, 255),
8732 RGBA(0, 255, 255, 255)
8735 RGBA expectedColors[4] =
8737 RGBA(255, 0, 0, 255),
8738 RGBA(255, 0, 0, 255),
8739 RGBA(255, 0, 0, 255),
8740 RGBA(255, 0, 0, 255)
8743 struct DualFP16Possibility
8748 const char* possibleOutput1;
8749 const char* possibleOutput2;
8752 "positive_round_up_or_round_down",
8754 constructNormalizedFloat(8, 0x300300),
8759 "negative_round_up_or_round_down",
8761 -constructNormalizedFloat(-7, 0x600800),
8768 constructNormalizedFloat(2, 0x01e000),
8773 "carry_to_exponent",
8775 constructNormalizedFloat(1, 0xffe000),
8780 StringTemplate constants (
8781 "%input_const = OpConstant %f32 ${input}\n"
8782 "%possible_solution1 = OpConstant %f32 ${output1}\n"
8783 "%possible_solution2 = OpConstant %f32 ${output2}\n"
8786 StringTemplate specConstants (
8787 "%input_const = OpSpecConstant %f32 0.\n"
8788 "%possible_solution1 = OpConstant %f32 ${output1}\n"
8789 "%possible_solution2 = OpConstant %f32 ${output2}\n"
8792 const char* specDecorations = "OpDecorate %input_const SpecId 0\n";
8794 const char* function =
8795 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
8796 "%param1 = OpFunctionParameter %v4f32\n"
8797 "%label_testfun = OpLabel\n"
8798 "%a = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
8799 // For the purposes of this test we assume that 0.f will always get
8800 // faithfully passed through the pipeline stages.
8801 "%b = OpFAdd %f32 %input_const %a\n"
8802 "%c = OpQuantizeToF16 %f32 %b\n"
8803 "%eq_1 = OpFOrdEqual %bool %c %possible_solution1\n"
8804 "%eq_2 = OpFOrdEqual %bool %c %possible_solution2\n"
8805 "%cond = OpLogicalOr %bool %eq_1 %eq_2\n"
8806 "%v4cond = OpCompositeConstruct %v4bool %cond %cond %cond %cond\n"
8807 "%retval = OpSelect %v4f32 %v4cond %c_v4f32_1_0_0_1 %param1"
8808 " OpReturnValue %retval\n"
8811 for(size_t idx = 0; idx < (sizeof(tests)/sizeof(tests[0])); ++idx) {
8812 map<string, string> fragments;
8813 map<string, string> constantSpecialization;
8815 constantSpecialization["input"] = tests[idx].input;
8816 constantSpecialization["output1"] = tests[idx].possibleOutput1;
8817 constantSpecialization["output2"] = tests[idx].possibleOutput2;
8818 fragments["testfun"] = function;
8819 fragments["pre_main"] = constants.specialize(constantSpecialization);
8820 createTestsForAllStages(tests[idx].name, inputColors, expectedColors, fragments, testCtx);
8823 for(size_t idx = 0; idx < (sizeof(tests)/sizeof(tests[0])); ++idx) {
8824 map<string, string> fragments;
8825 map<string, string> constantSpecialization;
8826 SpecConstants passConstants;
8828 constantSpecialization["output1"] = tests[idx].possibleOutput1;
8829 constantSpecialization["output2"] = tests[idx].possibleOutput2;
8830 fragments["testfun"] = function;
8831 fragments["decoration"] = specDecorations;
8832 fragments["pre_main"] = specConstants.specialize(constantSpecialization);
8834 passConstants.append<float>(tests[idx].inputAsFloat);
8836 createTestsForAllStages(string("spec_const_") + tests[idx].name, inputColors, expectedColors, fragments, passConstants, testCtx);
8840 tcu::TestCaseGroup* createOpQuantizeTests(tcu::TestContext& testCtx)
8842 de::MovePtr<tcu::TestCaseGroup> opQuantizeTests (new tcu::TestCaseGroup(testCtx, "opquantize", "Test OpQuantizeToF16"));
8843 createOpQuantizeSingleOptionTests(opQuantizeTests.get());
8844 createOpQuantizeTwoPossibilityTests(opQuantizeTests.get());
8845 return opQuantizeTests.release();
8848 struct ShaderPermutation
8850 deUint8 vertexPermutation;
8851 deUint8 geometryPermutation;
8852 deUint8 tesscPermutation;
8853 deUint8 tessePermutation;
8854 deUint8 fragmentPermutation;
8857 ShaderPermutation getShaderPermutation(deUint8 inputValue)
8859 ShaderPermutation permutation =
8861 static_cast<deUint8>(inputValue & 0x10? 1u: 0u),
8862 static_cast<deUint8>(inputValue & 0x08? 1u: 0u),
8863 static_cast<deUint8>(inputValue & 0x04? 1u: 0u),
8864 static_cast<deUint8>(inputValue & 0x02? 1u: 0u),
8865 static_cast<deUint8>(inputValue & 0x01? 1u: 0u)
8870 tcu::TestCaseGroup* createModuleTests(tcu::TestContext& testCtx)
8872 RGBA defaultColors[4];
8873 RGBA invertedColors[4];
8874 de::MovePtr<tcu::TestCaseGroup> moduleTests (new tcu::TestCaseGroup(testCtx, "module", "Multiple entry points into shaders"));
8876 getDefaultColors(defaultColors);
8877 getInvertedDefaultColors(invertedColors);
8879 // Combined module tests
8881 // Shader stages: vertex and fragment
8883 const ShaderElement combinedPipeline[] =
8885 ShaderElement("module", "main", VK_SHADER_STAGE_VERTEX_BIT),
8886 ShaderElement("module", "main", VK_SHADER_STAGE_FRAGMENT_BIT)
8889 addFunctionCaseWithPrograms<InstanceContext>(
8890 moduleTests.get(), "same_module", "", createCombinedModule, runAndVerifyDefaultPipeline,
8891 createInstanceContext(combinedPipeline, map<string, string>()));
8894 // Shader stages: vertex, geometry and fragment
8896 const ShaderElement combinedPipeline[] =
8898 ShaderElement("module", "main", VK_SHADER_STAGE_VERTEX_BIT),
8899 ShaderElement("module", "main", VK_SHADER_STAGE_GEOMETRY_BIT),
8900 ShaderElement("module", "main", VK_SHADER_STAGE_FRAGMENT_BIT)
8903 addFunctionCaseWithPrograms<InstanceContext>(
8904 moduleTests.get(), "same_module_geom", "", createCombinedModule, runAndVerifyDefaultPipeline,
8905 createInstanceContext(combinedPipeline, map<string, string>()));
8908 // Shader stages: vertex, tessellation control, tessellation evaluation and fragment
8910 const ShaderElement combinedPipeline[] =
8912 ShaderElement("module", "main", VK_SHADER_STAGE_VERTEX_BIT),
8913 ShaderElement("module", "main", VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT),
8914 ShaderElement("module", "main", VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT),
8915 ShaderElement("module", "main", VK_SHADER_STAGE_FRAGMENT_BIT)
8918 addFunctionCaseWithPrograms<InstanceContext>(
8919 moduleTests.get(), "same_module_tessc_tesse", "", createCombinedModule, runAndVerifyDefaultPipeline,
8920 createInstanceContext(combinedPipeline, map<string, string>()));
8923 // Shader stages: vertex, tessellation control, tessellation evaluation, geometry and fragment
8925 const ShaderElement combinedPipeline[] =
8927 ShaderElement("module", "main", VK_SHADER_STAGE_VERTEX_BIT),
8928 ShaderElement("module", "main", VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT),
8929 ShaderElement("module", "main", VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT),
8930 ShaderElement("module", "main", VK_SHADER_STAGE_GEOMETRY_BIT),
8931 ShaderElement("module", "main", VK_SHADER_STAGE_FRAGMENT_BIT)
8934 addFunctionCaseWithPrograms<InstanceContext>(
8935 moduleTests.get(), "same_module_tessc_tesse_geom", "", createCombinedModule, runAndVerifyDefaultPipeline,
8936 createInstanceContext(combinedPipeline, map<string, string>()));
8940 const char* numbers[] =
8945 for (deInt8 idx = 0; idx < 32; ++idx)
8947 ShaderPermutation permutation = getShaderPermutation(idx);
8948 string name = string("vert") + numbers[permutation.vertexPermutation] + "_geom" + numbers[permutation.geometryPermutation] + "_tessc" + numbers[permutation.tesscPermutation] + "_tesse" + numbers[permutation.tessePermutation] + "_frag" + numbers[permutation.fragmentPermutation];
8949 const ShaderElement pipeline[] =
8951 ShaderElement("vert", string("vert") + numbers[permutation.vertexPermutation], VK_SHADER_STAGE_VERTEX_BIT),
8952 ShaderElement("geom", string("geom") + numbers[permutation.geometryPermutation], VK_SHADER_STAGE_GEOMETRY_BIT),
8953 ShaderElement("tessc", string("tessc") + numbers[permutation.tesscPermutation], VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT),
8954 ShaderElement("tesse", string("tesse") + numbers[permutation.tessePermutation], VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT),
8955 ShaderElement("frag", string("frag") + numbers[permutation.fragmentPermutation], VK_SHADER_STAGE_FRAGMENT_BIT)
8958 // If there are an even number of swaps, then it should be no-op.
8959 // If there are an odd number, the color should be flipped.
8960 if ((permutation.vertexPermutation + permutation.geometryPermutation + permutation.tesscPermutation + permutation.tessePermutation + permutation.fragmentPermutation) % 2 == 0)
8962 addFunctionCaseWithPrograms<InstanceContext>(
8963 moduleTests.get(), name, "", createMultipleEntries, runAndVerifyDefaultPipeline,
8964 createInstanceContext(pipeline, defaultColors, defaultColors, map<string, string>()));
8968 addFunctionCaseWithPrograms<InstanceContext>(
8969 moduleTests.get(), name, "", createMultipleEntries, runAndVerifyDefaultPipeline,
8970 createInstanceContext(pipeline, defaultColors, invertedColors, map<string, string>()));
8973 return moduleTests.release();
8976 std::string getUnusedVarTestNamePiece(const std::string& prefix, ShaderTask task)
8980 case SHADER_TASK_NONE: return "";
8981 case SHADER_TASK_NORMAL: return prefix + "_normal";
8982 case SHADER_TASK_UNUSED_VAR: return prefix + "_unused_var";
8983 case SHADER_TASK_UNUSED_FUNC: return prefix + "_unused_func";
8984 default: DE_ASSERT(DE_FALSE);
8990 std::string getShaderTaskIndexName(ShaderTaskIndex index)
8994 case SHADER_TASK_INDEX_VERTEX: return "vertex";
8995 case SHADER_TASK_INDEX_GEOMETRY: return "geom";
8996 case SHADER_TASK_INDEX_TESS_CONTROL: return "tessc";
8997 case SHADER_TASK_INDEX_TESS_EVAL: return "tesse";
8998 case SHADER_TASK_INDEX_FRAGMENT: return "frag";
8999 default: DE_ASSERT(DE_FALSE);
9005 std::string getUnusedVarTestName(const ShaderTaskArray& shaderTasks, const VariableLocation& location)
9007 std::string testName = location.toString();
9009 for (size_t i = 0; i < DE_LENGTH_OF_ARRAY(shaderTasks); ++i)
9011 if (shaderTasks[i] != SHADER_TASK_NONE)
9013 testName += "_" + getUnusedVarTestNamePiece(getShaderTaskIndexName((ShaderTaskIndex)i), shaderTasks[i]);
9020 tcu::TestCaseGroup* createUnusedVariableTests(tcu::TestContext& testCtx)
9022 de::MovePtr<tcu::TestCaseGroup> moduleTests (new tcu::TestCaseGroup(testCtx, "unused_variables", "Graphics shaders with unused variables"));
9024 ShaderTaskArray shaderCombinations[] =
9026 // Vertex Geometry Tess. Control Tess. Evaluation Fragment
9027 { SHADER_TASK_UNUSED_VAR, SHADER_TASK_NONE, SHADER_TASK_NONE, SHADER_TASK_NONE, SHADER_TASK_NORMAL },
9028 { SHADER_TASK_UNUSED_FUNC, SHADER_TASK_NONE, SHADER_TASK_NONE, SHADER_TASK_NONE, SHADER_TASK_NORMAL },
9029 { SHADER_TASK_NORMAL, SHADER_TASK_NONE, SHADER_TASK_NONE, SHADER_TASK_NONE, SHADER_TASK_UNUSED_VAR },
9030 { SHADER_TASK_NORMAL, SHADER_TASK_NONE, SHADER_TASK_NONE, SHADER_TASK_NONE, SHADER_TASK_UNUSED_FUNC },
9031 { SHADER_TASK_NORMAL, SHADER_TASK_UNUSED_VAR, SHADER_TASK_NONE, SHADER_TASK_NONE, SHADER_TASK_NORMAL },
9032 { SHADER_TASK_NORMAL, SHADER_TASK_UNUSED_FUNC, SHADER_TASK_NONE, SHADER_TASK_NONE, SHADER_TASK_NORMAL },
9033 { SHADER_TASK_NORMAL, SHADER_TASK_NONE, SHADER_TASK_UNUSED_VAR, SHADER_TASK_NORMAL, SHADER_TASK_NORMAL },
9034 { SHADER_TASK_NORMAL, SHADER_TASK_NONE, SHADER_TASK_UNUSED_FUNC, SHADER_TASK_NORMAL, SHADER_TASK_NORMAL },
9035 { SHADER_TASK_NORMAL, SHADER_TASK_NONE, SHADER_TASK_NORMAL, SHADER_TASK_UNUSED_VAR, SHADER_TASK_NORMAL },
9036 { SHADER_TASK_NORMAL, SHADER_TASK_NONE, SHADER_TASK_NORMAL, SHADER_TASK_UNUSED_FUNC, SHADER_TASK_NORMAL }
9039 const VariableLocation testLocations[] =
9046 for (size_t combNdx = 0; combNdx < DE_LENGTH_OF_ARRAY(shaderCombinations); ++combNdx)
9048 for (size_t locationNdx = 0; locationNdx < DE_LENGTH_OF_ARRAY(testLocations); ++locationNdx)
9050 const ShaderTaskArray& shaderTasks = shaderCombinations[combNdx];
9051 const VariableLocation& location = testLocations[locationNdx];
9052 std::string testName = getUnusedVarTestName(shaderTasks, location);
9054 addFunctionCaseWithPrograms<UnusedVariableContext>(
9055 moduleTests.get(), testName, "", createUnusedVariableModules, runAndVerifyUnusedVariablePipeline,
9056 createUnusedVariableContext(shaderTasks, location));
9060 return moduleTests.release();
9063 tcu::TestCaseGroup* createLoopTests(tcu::TestContext& testCtx)
9065 de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, "loop", "Looping control flow"));
9066 RGBA defaultColors[4];
9067 getDefaultColors(defaultColors);
9068 map<string, string> fragments;
9069 fragments["pre_main"] =
9070 "%c_f32_5 = OpConstant %f32 5.\n";
9072 // A loop with a single block. The Continue Target is the loop block
9073 // itself. In SPIR-V terms, the "loop construct" contains no blocks at all
9074 // -- the "continue construct" forms the entire loop.
9075 fragments["testfun"] =
9076 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
9077 "%param1 = OpFunctionParameter %v4f32\n"
9079 "%entry = OpLabel\n"
9080 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
9083 ";adds and subtracts 1.0 to %val in alternate iterations\n"
9085 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %loop\n"
9086 "%delta = OpPhi %f32 %c_f32_1 %entry %minus_delta %loop\n"
9087 "%val1 = OpPhi %f32 %val0 %entry %val %loop\n"
9088 "%val = OpFAdd %f32 %val1 %delta\n"
9089 "%minus_delta = OpFSub %f32 %c_f32_0 %delta\n"
9090 "%count__ = OpISub %i32 %count %c_i32_1\n"
9091 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
9092 "OpLoopMerge %exit %loop None\n"
9093 "OpBranchConditional %again %loop %exit\n"
9096 "%result = OpVectorInsertDynamic %v4f32 %param1 %val %c_i32_0\n"
9097 "OpReturnValue %result\n"
9101 createTestsForAllStages("single_block", defaultColors, defaultColors, fragments, testGroup.get());
9103 // Body comprised of multiple basic blocks.
9104 const StringTemplate multiBlock(
9105 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
9106 "%param1 = OpFunctionParameter %v4f32\n"
9108 "%entry = OpLabel\n"
9109 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
9112 ";adds and subtracts 1.0 to %val in alternate iterations\n"
9114 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %cont\n"
9115 "%delta = OpPhi %f32 %c_f32_1 %entry %delta_next %cont\n"
9116 "%val1 = OpPhi %f32 %val0 %entry %val %cont\n"
9117 // There are several possibilities for the Continue Target below. Each
9118 // will be specialized into a separate test case.
9119 "OpLoopMerge %exit ${continue_target} None\n"
9123 ";delta_next = (delta > 0) ? -1 : 1;\n"
9124 "%gt0 = OpFOrdGreaterThan %bool %delta %c_f32_0\n"
9125 "OpSelectionMerge %gather DontFlatten\n"
9126 "OpBranchConditional %gt0 %even %odd ;tells us if %count is even or odd\n"
9129 "OpBranch %gather\n"
9132 "OpBranch %gather\n"
9134 "%gather = OpLabel\n"
9135 "%delta_next = OpPhi %f32 %c_f32_n1 %even %c_f32_1 %odd\n"
9136 "%val = OpFAdd %f32 %val1 %delta\n"
9137 "%count__ = OpISub %i32 %count %c_i32_1\n"
9141 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
9142 "OpBranchConditional %again %loop %exit\n"
9145 "%result = OpVectorInsertDynamic %v4f32 %param1 %val %c_i32_0\n"
9146 "OpReturnValue %result\n"
9150 map<string, string> continue_target;
9152 // The Continue Target is the loop block itself.
9153 continue_target["continue_target"] = "%loop";
9154 fragments["testfun"] = multiBlock.specialize(continue_target);
9155 createTestsForAllStages("multi_block_continue_construct", defaultColors, defaultColors, fragments, testGroup.get());
9157 // The Continue Target is at the end of the loop.
9158 continue_target["continue_target"] = "%cont";
9159 fragments["testfun"] = multiBlock.specialize(continue_target);
9160 createTestsForAllStages("multi_block_loop_construct", defaultColors, defaultColors, fragments, testGroup.get());
9162 // A loop with continue statement.
9163 fragments["testfun"] =
9164 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
9165 "%param1 = OpFunctionParameter %v4f32\n"
9167 "%entry = OpLabel\n"
9168 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
9171 ";adds 4, 3, and 1 to %val0 (skips 2)\n"
9173 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %continue\n"
9174 "%val1 = OpPhi %f32 %val0 %entry %val %continue\n"
9175 "OpLoopMerge %exit %continue None\n"
9179 ";skip if %count==2\n"
9180 "%eq2 = OpIEqual %bool %count %c_i32_2\n"
9181 "OpBranchConditional %eq2 %continue %body\n"
9184 "%fcount = OpConvertSToF %f32 %count\n"
9185 "%val2 = OpFAdd %f32 %val1 %fcount\n"
9186 "OpBranch %continue\n"
9188 "%continue = OpLabel\n"
9189 "%val = OpPhi %f32 %val2 %body %val1 %if\n"
9190 "%count__ = OpISub %i32 %count %c_i32_1\n"
9191 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
9192 "OpBranchConditional %again %loop %exit\n"
9195 "%same = OpFSub %f32 %val %c_f32_8\n"
9196 "%result = OpVectorInsertDynamic %v4f32 %param1 %same %c_i32_0\n"
9197 "OpReturnValue %result\n"
9199 createTestsForAllStages("continue", defaultColors, defaultColors, fragments, testGroup.get());
9201 // A loop with break.
9202 fragments["testfun"] =
9203 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
9204 "%param1 = OpFunctionParameter %v4f32\n"
9206 "%entry = OpLabel\n"
9207 ";param1 components are between 0 and 1, so dot product is 4 or less\n"
9208 "%dot = OpDot %f32 %param1 %param1\n"
9209 "%div = OpFDiv %f32 %dot %c_f32_5\n"
9210 "%zero = OpConvertFToU %u32 %div\n"
9211 "%two = OpIAdd %i32 %zero %c_i32_2\n"
9212 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
9215 ";adds 4 and 3 to %val0 (exits early)\n"
9217 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %continue\n"
9218 "%val1 = OpPhi %f32 %val0 %entry %val2 %continue\n"
9219 "OpLoopMerge %exit %continue None\n"
9223 ";end loop if %count==%two\n"
9224 "%above2 = OpSGreaterThan %bool %count %two\n"
9225 "OpBranchConditional %above2 %body %exit\n"
9228 "%fcount = OpConvertSToF %f32 %count\n"
9229 "%val2 = OpFAdd %f32 %val1 %fcount\n"
9230 "OpBranch %continue\n"
9232 "%continue = OpLabel\n"
9233 "%count__ = OpISub %i32 %count %c_i32_1\n"
9234 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
9235 "OpBranchConditional %again %loop %exit\n"
9238 "%val_post = OpPhi %f32 %val2 %continue %val1 %if\n"
9239 "%same = OpFSub %f32 %val_post %c_f32_7\n"
9240 "%result = OpVectorInsertDynamic %v4f32 %param1 %same %c_i32_0\n"
9241 "OpReturnValue %result\n"
9243 createTestsForAllStages("break", defaultColors, defaultColors, fragments, testGroup.get());
9245 // A loop with return.
9246 fragments["testfun"] =
9247 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
9248 "%param1 = OpFunctionParameter %v4f32\n"
9250 "%entry = OpLabel\n"
9251 ";param1 components are between 0 and 1, so dot product is 4 or less\n"
9252 "%dot = OpDot %f32 %param1 %param1\n"
9253 "%div = OpFDiv %f32 %dot %c_f32_5\n"
9254 "%zero = OpConvertFToU %u32 %div\n"
9255 "%two = OpIAdd %i32 %zero %c_i32_2\n"
9256 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
9259 ";returns early without modifying %param1\n"
9261 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %continue\n"
9262 "%val1 = OpPhi %f32 %val0 %entry %val2 %continue\n"
9263 "OpLoopMerge %exit %continue None\n"
9267 ";return if %count==%two\n"
9268 "%above2 = OpSGreaterThan %bool %count %two\n"
9269 "OpSelectionMerge %body DontFlatten\n"
9270 "OpBranchConditional %above2 %body %early_exit\n"
9272 "%early_exit = OpLabel\n"
9273 "OpReturnValue %param1\n"
9276 "%fcount = OpConvertSToF %f32 %count\n"
9277 "%val2 = OpFAdd %f32 %val1 %fcount\n"
9278 "OpBranch %continue\n"
9280 "%continue = OpLabel\n"
9281 "%count__ = OpISub %i32 %count %c_i32_1\n"
9282 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
9283 "OpBranchConditional %again %loop %exit\n"
9286 ";should never get here, so return an incorrect result\n"
9287 "%result = OpVectorInsertDynamic %v4f32 %param1 %val2 %c_i32_0\n"
9288 "OpReturnValue %result\n"
9290 createTestsForAllStages("return", defaultColors, defaultColors, fragments, testGroup.get());
9292 // Continue inside a switch block to break to enclosing loop's merge block.
9293 // Matches roughly the following GLSL code:
9294 // for (; keep_going; keep_going = false)
9296 // switch (int(param1.x))
9298 // case 0: continue;
9299 // case 1: continue;
9300 // default: continue;
9302 // dead code: modify return value to invalid result.
9304 fragments["pre_main"] =
9305 "%fp_bool = OpTypePointer Function %bool\n"
9306 "%true = OpConstantTrue %bool\n"
9307 "%false = OpConstantFalse %bool\n";
9309 fragments["testfun"] =
9310 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
9311 "%param1 = OpFunctionParameter %v4f32\n"
9313 "%entry = OpLabel\n"
9314 "%keep_going = OpVariable %fp_bool Function\n"
9315 "%val_ptr = OpVariable %fp_f32 Function\n"
9316 "%param1_x = OpCompositeExtract %f32 %param1 0\n"
9317 "OpStore %keep_going %true\n"
9318 "OpBranch %forloop_begin\n"
9320 "%forloop_begin = OpLabel\n"
9321 "OpLoopMerge %forloop_merge %forloop_continue None\n"
9322 "OpBranch %forloop\n"
9324 "%forloop = OpLabel\n"
9325 "%for_condition = OpLoad %bool %keep_going\n"
9326 "OpBranchConditional %for_condition %forloop_body %forloop_merge\n"
9328 "%forloop_body = OpLabel\n"
9329 "OpStore %val_ptr %param1_x\n"
9330 "%param1_x_int = OpConvertFToS %i32 %param1_x\n"
9332 "OpSelectionMerge %switch_merge None\n"
9333 "OpSwitch %param1_x_int %default 0 %case_0 1 %case_1\n"
9334 "%case_0 = OpLabel\n"
9335 "OpBranch %forloop_continue\n"
9336 "%case_1 = OpLabel\n"
9337 "OpBranch %forloop_continue\n"
9338 "%default = OpLabel\n"
9339 "OpBranch %forloop_continue\n"
9340 "%switch_merge = OpLabel\n"
9341 ";should never get here, so change the return value to invalid result\n"
9342 "OpStore %val_ptr %c_f32_1\n"
9343 "OpBranch %forloop_continue\n"
9345 "%forloop_continue = OpLabel\n"
9346 "OpStore %keep_going %false\n"
9347 "OpBranch %forloop_begin\n"
9348 "%forloop_merge = OpLabel\n"
9350 "%val = OpLoad %f32 %val_ptr\n"
9351 "%result = OpVectorInsertDynamic %v4f32 %param1 %val %c_i32_0\n"
9352 "OpReturnValue %result\n"
9354 createTestsForAllStages("switch_continue", defaultColors, defaultColors, fragments, testGroup.get());
9356 return testGroup.release();
9359 // A collection of tests putting OpControlBarrier in places GLSL forbids but SPIR-V allows.
9360 tcu::TestCaseGroup* createBarrierTests(tcu::TestContext& testCtx)
9362 de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, "barrier", "OpControlBarrier"));
9363 map<string, string> fragments;
9365 // A barrier inside a function body.
9366 fragments["pre_main"] =
9367 "%Workgroup = OpConstant %i32 2\n"
9368 "%WorkgroupAcquireRelease = OpConstant %i32 0x108\n";
9369 fragments["testfun"] =
9370 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
9371 "%param1 = OpFunctionParameter %v4f32\n"
9372 "%label_testfun = OpLabel\n"
9373 "OpControlBarrier %Workgroup %Workgroup %WorkgroupAcquireRelease\n"
9374 "OpReturnValue %param1\n"
9376 addTessCtrlTest(testGroup.get(), "in_function", fragments);
9378 // Common setup code for the following tests.
9379 fragments["pre_main"] =
9380 "%Workgroup = OpConstant %i32 2\n"
9381 "%WorkgroupAcquireRelease = OpConstant %i32 0x108\n"
9382 "%c_f32_5 = OpConstant %f32 5.\n";
9383 const string setupPercentZero = // Begins %test_code function with code that sets %zero to 0u but cannot be optimized away.
9384 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
9385 "%param1 = OpFunctionParameter %v4f32\n"
9386 "%entry = OpLabel\n"
9387 ";param1 components are between 0 and 1, so dot product is 4 or less\n"
9388 "%dot = OpDot %f32 %param1 %param1\n"
9389 "%div = OpFDiv %f32 %dot %c_f32_5\n"
9390 "%zero = OpConvertFToU %u32 %div\n";
9392 // Barriers inside OpSwitch branches.
9393 fragments["testfun"] =
9395 "OpSelectionMerge %switch_exit None\n"
9396 "OpSwitch %zero %switch_default 0 %case0 1 %case1 ;should always go to %case0\n"
9398 "%case1 = OpLabel\n"
9399 ";This barrier should never be executed, but its presence makes test failure more likely when there's a bug.\n"
9400 "OpControlBarrier %Workgroup %Workgroup %WorkgroupAcquireRelease\n"
9401 "%wrong_branch_alert1 = OpVectorInsertDynamic %v4f32 %param1 %c_f32_0_5 %c_i32_0\n"
9402 "OpBranch %switch_exit\n"
9404 "%switch_default = OpLabel\n"
9405 "%wrong_branch_alert2 = OpVectorInsertDynamic %v4f32 %param1 %c_f32_0_5 %c_i32_0\n"
9406 ";This barrier should never be executed, but its presence makes test failure more likely when there's a bug.\n"
9407 "OpControlBarrier %Workgroup %Workgroup %WorkgroupAcquireRelease\n"
9408 "OpBranch %switch_exit\n"
9410 "%case0 = OpLabel\n"
9411 "OpControlBarrier %Workgroup %Workgroup %WorkgroupAcquireRelease\n"
9412 "OpBranch %switch_exit\n"
9414 "%switch_exit = OpLabel\n"
9415 "%ret = OpPhi %v4f32 %param1 %case0 %wrong_branch_alert1 %case1 %wrong_branch_alert2 %switch_default\n"
9416 "OpReturnValue %ret\n"
9418 addTessCtrlTest(testGroup.get(), "in_switch", fragments);
9420 // Barriers inside if-then-else.
9421 fragments["testfun"] =
9423 "%eq0 = OpIEqual %bool %zero %c_u32_0\n"
9424 "OpSelectionMerge %exit DontFlatten\n"
9425 "OpBranchConditional %eq0 %then %else\n"
9428 ";This barrier should never be executed, but its presence makes test failure more likely when there's a bug.\n"
9429 "OpControlBarrier %Workgroup %Workgroup %WorkgroupAcquireRelease\n"
9430 "%wrong_branch_alert = OpVectorInsertDynamic %v4f32 %param1 %c_f32_0_5 %c_i32_0\n"
9434 "OpControlBarrier %Workgroup %Workgroup %WorkgroupAcquireRelease\n"
9437 "%ret = OpPhi %v4f32 %param1 %then %wrong_branch_alert %else\n"
9438 "OpReturnValue %ret\n"
9440 addTessCtrlTest(testGroup.get(), "in_if", fragments);
9442 // A barrier after control-flow reconvergence, tempting the compiler to attempt something like this:
9443 // http://lists.llvm.org/pipermail/llvm-dev/2009-October/026317.html.
9444 fragments["testfun"] =
9446 "%thread_id = OpLoad %i32 %BP_gl_InvocationID\n"
9447 "%thread0 = OpIEqual %bool %thread_id %c_i32_0\n"
9448 "OpSelectionMerge %exit DontFlatten\n"
9449 "OpBranchConditional %thread0 %then %else\n"
9452 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
9456 "%val1 = OpVectorExtractDynamic %f32 %param1 %zero\n"
9460 "%val = OpPhi %f32 %val0 %else %val1 %then\n"
9461 "OpControlBarrier %Workgroup %Workgroup %WorkgroupAcquireRelease\n"
9462 "%ret = OpVectorInsertDynamic %v4f32 %param1 %val %zero\n"
9463 "OpReturnValue %ret\n"
9465 addTessCtrlTest(testGroup.get(), "after_divergent_if", fragments);
9467 // A barrier inside a loop.
9468 fragments["pre_main"] =
9469 "%Workgroup = OpConstant %i32 2\n"
9470 "%WorkgroupAcquireRelease = OpConstant %i32 0x108\n"
9471 "%c_f32_10 = OpConstant %f32 10.\n";
9472 fragments["testfun"] =
9473 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
9474 "%param1 = OpFunctionParameter %v4f32\n"
9475 "%entry = OpLabel\n"
9476 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
9479 ";adds 4, 3, 2, and 1 to %val0\n"
9481 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %loop\n"
9482 "%val1 = OpPhi %f32 %val0 %entry %val %loop\n"
9483 "OpControlBarrier %Workgroup %Workgroup %WorkgroupAcquireRelease\n"
9484 "%fcount = OpConvertSToF %f32 %count\n"
9485 "%val = OpFAdd %f32 %val1 %fcount\n"
9486 "%count__ = OpISub %i32 %count %c_i32_1\n"
9487 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
9488 "OpLoopMerge %exit %loop None\n"
9489 "OpBranchConditional %again %loop %exit\n"
9492 "%same = OpFSub %f32 %val %c_f32_10\n"
9493 "%ret = OpVectorInsertDynamic %v4f32 %param1 %same %c_i32_0\n"
9494 "OpReturnValue %ret\n"
9496 addTessCtrlTest(testGroup.get(), "in_loop", fragments);
9498 return testGroup.release();
9501 // Test for the OpFRem instruction.
9502 tcu::TestCaseGroup* createFRemTests(tcu::TestContext& testCtx)
9504 de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, "frem", "OpFRem"));
9505 map<string, string> fragments;
9506 RGBA inputColors[4];
9507 RGBA outputColors[4];
9509 fragments["pre_main"] =
9510 "%c_f32_3 = OpConstant %f32 3.0\n"
9511 "%c_f32_n3 = OpConstant %f32 -3.0\n"
9512 "%c_f32_4 = OpConstant %f32 4.0\n"
9513 "%c_f32_p75 = OpConstant %f32 0.75\n"
9514 "%c_v4f32_p75_p75_p75_p75 = OpConstantComposite %v4f32 %c_f32_p75 %c_f32_p75 %c_f32_p75 %c_f32_p75 \n"
9515 "%c_v4f32_4_4_4_4 = OpConstantComposite %v4f32 %c_f32_4 %c_f32_4 %c_f32_4 %c_f32_4\n"
9516 "%c_v4f32_3_n3_3_n3 = OpConstantComposite %v4f32 %c_f32_3 %c_f32_n3 %c_f32_3 %c_f32_n3\n";
9518 // The test does the following.
9519 // vec4 result = (param1 * 8.0) - 4.0;
9520 // return (frem(result.x,3) + 0.75, frem(result.y, -3) + 0.75, 0, 1)
9521 fragments["testfun"] =
9522 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
9523 "%param1 = OpFunctionParameter %v4f32\n"
9524 "%label_testfun = OpLabel\n"
9525 "%v_times_8 = OpVectorTimesScalar %v4f32 %param1 %c_f32_8\n"
9526 "%minus_4 = OpFSub %v4f32 %v_times_8 %c_v4f32_4_4_4_4\n"
9527 "%frem = OpFRem %v4f32 %minus_4 %c_v4f32_3_n3_3_n3\n"
9528 "%added = OpFAdd %v4f32 %frem %c_v4f32_p75_p75_p75_p75\n"
9529 "%xyz_1 = OpVectorInsertDynamic %v4f32 %added %c_f32_1 %c_i32_3\n"
9530 "%xy_0_1 = OpVectorInsertDynamic %v4f32 %xyz_1 %c_f32_0 %c_i32_2\n"
9531 "OpReturnValue %xy_0_1\n"
9535 inputColors[0] = RGBA(16, 16, 0, 255);
9536 inputColors[1] = RGBA(232, 232, 0, 255);
9537 inputColors[2] = RGBA(232, 16, 0, 255);
9538 inputColors[3] = RGBA(16, 232, 0, 255);
9540 outputColors[0] = RGBA(64, 64, 0, 255);
9541 outputColors[1] = RGBA(255, 255, 0, 255);
9542 outputColors[2] = RGBA(255, 64, 0, 255);
9543 outputColors[3] = RGBA(64, 255, 0, 255);
9545 createTestsForAllStages("frem", inputColors, outputColors, fragments, testGroup.get());
9546 return testGroup.release();
9549 // Test for the OpSRem instruction.
9550 tcu::TestCaseGroup* createOpSRemGraphicsTests(tcu::TestContext& testCtx, qpTestResult negFailResult)
9552 de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, "srem", "OpSRem"));
9553 map<string, string> fragments;
9555 fragments["pre_main"] =
9556 "%c_f32_255 = OpConstant %f32 255.0\n"
9557 "%c_i32_128 = OpConstant %i32 128\n"
9558 "%c_i32_255 = OpConstant %i32 255\n"
9559 "%c_v4f32_255 = OpConstantComposite %v4f32 %c_f32_255 %c_f32_255 %c_f32_255 %c_f32_255 \n"
9560 "%c_v4f32_0_5 = OpConstantComposite %v4f32 %c_f32_0_5 %c_f32_0_5 %c_f32_0_5 %c_f32_0_5 \n"
9561 "%c_v4i32_128 = OpConstantComposite %v4i32 %c_i32_128 %c_i32_128 %c_i32_128 %c_i32_128 \n";
9563 // The test does the following.
9564 // ivec4 ints = int(param1 * 255.0 + 0.5) - 128;
9565 // ivec4 result = ivec4(srem(ints.x, ints.y), srem(ints.y, ints.z), srem(ints.z, ints.x), 255);
9566 // return float(result + 128) / 255.0;
9567 fragments["testfun"] =
9568 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
9569 "%param1 = OpFunctionParameter %v4f32\n"
9570 "%label_testfun = OpLabel\n"
9571 "%div255 = OpFMul %v4f32 %param1 %c_v4f32_255\n"
9572 "%add0_5 = OpFAdd %v4f32 %div255 %c_v4f32_0_5\n"
9573 "%uints_in = OpConvertFToS %v4i32 %add0_5\n"
9574 "%ints_in = OpISub %v4i32 %uints_in %c_v4i32_128\n"
9575 "%x_in = OpCompositeExtract %i32 %ints_in 0\n"
9576 "%y_in = OpCompositeExtract %i32 %ints_in 1\n"
9577 "%z_in = OpCompositeExtract %i32 %ints_in 2\n"
9578 "%x_out = OpSRem %i32 %x_in %y_in\n"
9579 "%y_out = OpSRem %i32 %y_in %z_in\n"
9580 "%z_out = OpSRem %i32 %z_in %x_in\n"
9581 "%ints_out = OpCompositeConstruct %v4i32 %x_out %y_out %z_out %c_i32_255\n"
9582 "%ints_offset = OpIAdd %v4i32 %ints_out %c_v4i32_128\n"
9583 "%f_ints_offset = OpConvertSToF %v4f32 %ints_offset\n"
9584 "%float_out = OpFDiv %v4f32 %f_ints_offset %c_v4f32_255\n"
9585 "OpReturnValue %float_out\n"
9588 const struct CaseParams
9591 const char* failMessageTemplate; // customized status message
9592 qpTestResult failResult; // override status on failure
9593 int operands[4][3]; // four (x, y, z) vectors of operands
9594 int results[4][3]; // four (x, y, z) vectors of results
9600 QP_TEST_RESULT_FAIL,
9601 { { 5, 12, 17 }, { 5, 5, 7 }, { 75, 8, 81 }, { 25, 60, 100 } }, // operands
9602 { { 5, 12, 2 }, { 0, 5, 2 }, { 3, 8, 6 }, { 25, 60, 0 } }, // results
9606 "Inconsistent results, but within specification: ${reason}",
9607 negFailResult, // negative operands, not required by the spec
9608 { { 5, 12, -17 }, { -5, -5, 7 }, { 75, 8, -81 }, { 25, -60, 100 } }, // operands
9609 { { 5, 12, -2 }, { 0, -5, 2 }, { 3, 8, -6 }, { 25, -60, 0 } }, // results
9612 // If either operand is negative the result is undefined. Some implementations may still return correct values.
9614 for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(cases); ++caseNdx)
9616 const CaseParams& params = cases[caseNdx];
9617 RGBA inputColors[4];
9618 RGBA outputColors[4];
9620 for (int i = 0; i < 4; ++i)
9622 inputColors [i] = RGBA(params.operands[i][0] + 128, params.operands[i][1] + 128, params.operands[i][2] + 128, 255);
9623 outputColors[i] = RGBA(params.results [i][0] + 128, params.results [i][1] + 128, params.results [i][2] + 128, 255);
9626 createTestsForAllStages(params.name, inputColors, outputColors, fragments, testGroup.get(), params.failResult, params.failMessageTemplate);
9629 return testGroup.release();
9632 // Test for the OpSMod instruction.
9633 tcu::TestCaseGroup* createOpSModGraphicsTests(tcu::TestContext& testCtx, qpTestResult negFailResult)
9635 de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, "smod", "OpSMod"));
9636 map<string, string> fragments;
9638 fragments["pre_main"] =
9639 "%c_f32_255 = OpConstant %f32 255.0\n"
9640 "%c_i32_128 = OpConstant %i32 128\n"
9641 "%c_i32_255 = OpConstant %i32 255\n"
9642 "%c_v4f32_255 = OpConstantComposite %v4f32 %c_f32_255 %c_f32_255 %c_f32_255 %c_f32_255 \n"
9643 "%c_v4f32_0_5 = OpConstantComposite %v4f32 %c_f32_0_5 %c_f32_0_5 %c_f32_0_5 %c_f32_0_5 \n"
9644 "%c_v4i32_128 = OpConstantComposite %v4i32 %c_i32_128 %c_i32_128 %c_i32_128 %c_i32_128 \n";
9646 // The test does the following.
9647 // ivec4 ints = int(param1 * 255.0 + 0.5) - 128;
9648 // ivec4 result = ivec4(smod(ints.x, ints.y), smod(ints.y, ints.z), smod(ints.z, ints.x), 255);
9649 // return float(result + 128) / 255.0;
9650 fragments["testfun"] =
9651 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
9652 "%param1 = OpFunctionParameter %v4f32\n"
9653 "%label_testfun = OpLabel\n"
9654 "%div255 = OpFMul %v4f32 %param1 %c_v4f32_255\n"
9655 "%add0_5 = OpFAdd %v4f32 %div255 %c_v4f32_0_5\n"
9656 "%uints_in = OpConvertFToS %v4i32 %add0_5\n"
9657 "%ints_in = OpISub %v4i32 %uints_in %c_v4i32_128\n"
9658 "%x_in = OpCompositeExtract %i32 %ints_in 0\n"
9659 "%y_in = OpCompositeExtract %i32 %ints_in 1\n"
9660 "%z_in = OpCompositeExtract %i32 %ints_in 2\n"
9661 "%x_out = OpSMod %i32 %x_in %y_in\n"
9662 "%y_out = OpSMod %i32 %y_in %z_in\n"
9663 "%z_out = OpSMod %i32 %z_in %x_in\n"
9664 "%ints_out = OpCompositeConstruct %v4i32 %x_out %y_out %z_out %c_i32_255\n"
9665 "%ints_offset = OpIAdd %v4i32 %ints_out %c_v4i32_128\n"
9666 "%f_ints_offset = OpConvertSToF %v4f32 %ints_offset\n"
9667 "%float_out = OpFDiv %v4f32 %f_ints_offset %c_v4f32_255\n"
9668 "OpReturnValue %float_out\n"
9671 const struct CaseParams
9674 const char* failMessageTemplate; // customized status message
9675 qpTestResult failResult; // override status on failure
9676 int operands[4][3]; // four (x, y, z) vectors of operands
9677 int results[4][3]; // four (x, y, z) vectors of results
9683 QP_TEST_RESULT_FAIL,
9684 { { 5, 12, 17 }, { 5, 5, 7 }, { 75, 8, 81 }, { 25, 60, 100 } }, // operands
9685 { { 5, 12, 2 }, { 0, 5, 2 }, { 3, 8, 6 }, { 25, 60, 0 } }, // results
9689 "Inconsistent results, but within specification: ${reason}",
9690 negFailResult, // negative operands, not required by the spec
9691 { { 5, 12, -17 }, { -5, -5, 7 }, { 75, 8, -81 }, { 25, -60, 100 } }, // operands
9692 { { 5, -5, 3 }, { 0, 2, -3 }, { 3, -73, 69 }, { -35, 40, 0 } }, // results
9695 // If either operand is negative the result is undefined. Some implementations may still return correct values.
9697 for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(cases); ++caseNdx)
9699 const CaseParams& params = cases[caseNdx];
9700 RGBA inputColors[4];
9701 RGBA outputColors[4];
9703 for (int i = 0; i < 4; ++i)
9705 inputColors [i] = RGBA(params.operands[i][0] + 128, params.operands[i][1] + 128, params.operands[i][2] + 128, 255);
9706 outputColors[i] = RGBA(params.results [i][0] + 128, params.results [i][1] + 128, params.results [i][2] + 128, 255);
9709 createTestsForAllStages(params.name, inputColors, outputColors, fragments, testGroup.get(), params.failResult, params.failMessageTemplate);
9711 return testGroup.release();
9714 enum ConversionDataType
9717 DATA_TYPE_SIGNED_16,
9718 DATA_TYPE_SIGNED_32,
9719 DATA_TYPE_SIGNED_64,
9720 DATA_TYPE_UNSIGNED_8,
9721 DATA_TYPE_UNSIGNED_16,
9722 DATA_TYPE_UNSIGNED_32,
9723 DATA_TYPE_UNSIGNED_64,
9727 DATA_TYPE_VEC2_SIGNED_16,
9728 DATA_TYPE_VEC2_SIGNED_32
9731 const string getBitWidthStr (ConversionDataType type)
9735 case DATA_TYPE_SIGNED_8:
9736 case DATA_TYPE_UNSIGNED_8:
9739 case DATA_TYPE_SIGNED_16:
9740 case DATA_TYPE_UNSIGNED_16:
9741 case DATA_TYPE_FLOAT_16:
9744 case DATA_TYPE_SIGNED_32:
9745 case DATA_TYPE_UNSIGNED_32:
9746 case DATA_TYPE_FLOAT_32:
9747 case DATA_TYPE_VEC2_SIGNED_16:
9750 case DATA_TYPE_SIGNED_64:
9751 case DATA_TYPE_UNSIGNED_64:
9752 case DATA_TYPE_FLOAT_64:
9753 case DATA_TYPE_VEC2_SIGNED_32:
9762 const string getByteWidthStr (ConversionDataType type)
9766 case DATA_TYPE_SIGNED_8:
9767 case DATA_TYPE_UNSIGNED_8:
9770 case DATA_TYPE_SIGNED_16:
9771 case DATA_TYPE_UNSIGNED_16:
9772 case DATA_TYPE_FLOAT_16:
9775 case DATA_TYPE_SIGNED_32:
9776 case DATA_TYPE_UNSIGNED_32:
9777 case DATA_TYPE_FLOAT_32:
9778 case DATA_TYPE_VEC2_SIGNED_16:
9781 case DATA_TYPE_SIGNED_64:
9782 case DATA_TYPE_UNSIGNED_64:
9783 case DATA_TYPE_FLOAT_64:
9784 case DATA_TYPE_VEC2_SIGNED_32:
9793 bool isSigned (ConversionDataType type)
9797 case DATA_TYPE_SIGNED_8:
9798 case DATA_TYPE_SIGNED_16:
9799 case DATA_TYPE_SIGNED_32:
9800 case DATA_TYPE_SIGNED_64:
9801 case DATA_TYPE_FLOAT_16:
9802 case DATA_TYPE_FLOAT_32:
9803 case DATA_TYPE_FLOAT_64:
9804 case DATA_TYPE_VEC2_SIGNED_16:
9805 case DATA_TYPE_VEC2_SIGNED_32:
9808 case DATA_TYPE_UNSIGNED_8:
9809 case DATA_TYPE_UNSIGNED_16:
9810 case DATA_TYPE_UNSIGNED_32:
9811 case DATA_TYPE_UNSIGNED_64:
9820 bool isInt (ConversionDataType type)
9824 case DATA_TYPE_SIGNED_8:
9825 case DATA_TYPE_SIGNED_16:
9826 case DATA_TYPE_SIGNED_32:
9827 case DATA_TYPE_SIGNED_64:
9828 case DATA_TYPE_UNSIGNED_8:
9829 case DATA_TYPE_UNSIGNED_16:
9830 case DATA_TYPE_UNSIGNED_32:
9831 case DATA_TYPE_UNSIGNED_64:
9834 case DATA_TYPE_FLOAT_16:
9835 case DATA_TYPE_FLOAT_32:
9836 case DATA_TYPE_FLOAT_64:
9837 case DATA_TYPE_VEC2_SIGNED_16:
9838 case DATA_TYPE_VEC2_SIGNED_32:
9847 bool isFloat (ConversionDataType type)
9851 case DATA_TYPE_SIGNED_8:
9852 case DATA_TYPE_SIGNED_16:
9853 case DATA_TYPE_SIGNED_32:
9854 case DATA_TYPE_SIGNED_64:
9855 case DATA_TYPE_UNSIGNED_8:
9856 case DATA_TYPE_UNSIGNED_16:
9857 case DATA_TYPE_UNSIGNED_32:
9858 case DATA_TYPE_UNSIGNED_64:
9859 case DATA_TYPE_VEC2_SIGNED_16:
9860 case DATA_TYPE_VEC2_SIGNED_32:
9863 case DATA_TYPE_FLOAT_16:
9864 case DATA_TYPE_FLOAT_32:
9865 case DATA_TYPE_FLOAT_64:
9874 const string getTypeName (ConversionDataType type)
9876 string prefix = isSigned(type) ? "" : "u";
9878 if (isInt(type)) return prefix + "int" + getBitWidthStr(type);
9879 else if (isFloat(type)) return prefix + "float" + getBitWidthStr(type);
9880 else if (type == DATA_TYPE_VEC2_SIGNED_16) return "i16vec2";
9881 else if (type == DATA_TYPE_VEC2_SIGNED_32) return "i32vec2";
9882 else DE_ASSERT(false);
9887 const string getTestName (ConversionDataType from, ConversionDataType to, const char* suffix)
9889 const string fullSuffix(suffix == DE_NULL ? "" : string("_") + string(suffix));
9891 return getTypeName(from) + "_to_" + getTypeName(to) + fullSuffix;
9894 const string getAsmTypeName (ConversionDataType type, deUint32 elements = 1)
9898 if (isInt(type)) prefix = isSigned(type) ? "i" : "u";
9899 else if (isFloat(type)) prefix = "f";
9900 else if (type == DATA_TYPE_VEC2_SIGNED_16) return "i16vec2";
9901 else if (type == DATA_TYPE_VEC2_SIGNED_32) return "v2i32";
9902 else DE_ASSERT(false);
9903 if ((isInt(type) || isFloat(type)) && elements == 2)
9905 prefix = "v2" + prefix;
9908 return prefix + getBitWidthStr(type);
9911 template<typename T>
9912 BufferSp getSpecializedBuffer (deInt64 number, deUint32 elements = 1)
9914 return BufferSp(new Buffer<T>(vector<T>(elements, (T)number)));
9917 BufferSp getBuffer (ConversionDataType type, deInt64 number, deUint32 elements = 1)
9921 case DATA_TYPE_SIGNED_8: return getSpecializedBuffer<deInt8>(number, elements);
9922 case DATA_TYPE_SIGNED_16: return getSpecializedBuffer<deInt16>(number, elements);
9923 case DATA_TYPE_SIGNED_32: return getSpecializedBuffer<deInt32>(number, elements);
9924 case DATA_TYPE_SIGNED_64: return getSpecializedBuffer<deInt64>(number, elements);
9925 case DATA_TYPE_UNSIGNED_8: return getSpecializedBuffer<deUint8>(number, elements);
9926 case DATA_TYPE_UNSIGNED_16: return getSpecializedBuffer<deUint16>(number, elements);
9927 case DATA_TYPE_UNSIGNED_32: return getSpecializedBuffer<deUint32>(number, elements);
9928 case DATA_TYPE_UNSIGNED_64: return getSpecializedBuffer<deUint64>(number, elements);
9929 case DATA_TYPE_FLOAT_16: return getSpecializedBuffer<deUint16>(number, elements);
9930 case DATA_TYPE_FLOAT_32: return getSpecializedBuffer<deUint32>(number, elements);
9931 case DATA_TYPE_FLOAT_64: return getSpecializedBuffer<deUint64>(number, elements);
9932 case DATA_TYPE_VEC2_SIGNED_16: return getSpecializedBuffer<deUint32>(number, elements);
9933 case DATA_TYPE_VEC2_SIGNED_32: return getSpecializedBuffer<deUint64>(number, elements);
9935 default: TCU_THROW(InternalError, "Unimplemented type passed");
9939 bool usesInt8 (ConversionDataType from, ConversionDataType to)
9941 return (from == DATA_TYPE_SIGNED_8 || to == DATA_TYPE_SIGNED_8 ||
9942 from == DATA_TYPE_UNSIGNED_8 || to == DATA_TYPE_UNSIGNED_8);
9945 bool usesInt16 (ConversionDataType from, ConversionDataType to)
9947 return (from == DATA_TYPE_SIGNED_16 || to == DATA_TYPE_SIGNED_16 ||
9948 from == DATA_TYPE_UNSIGNED_16 || to == DATA_TYPE_UNSIGNED_16 ||
9949 from == DATA_TYPE_VEC2_SIGNED_16 || to == DATA_TYPE_VEC2_SIGNED_16);
9952 bool usesInt32 (ConversionDataType from, ConversionDataType to)
9954 return (from == DATA_TYPE_SIGNED_32 || to == DATA_TYPE_SIGNED_32 ||
9955 from == DATA_TYPE_UNSIGNED_32 || to == DATA_TYPE_UNSIGNED_32 ||
9956 from == DATA_TYPE_VEC2_SIGNED_32|| to == DATA_TYPE_VEC2_SIGNED_32);
9959 bool usesInt64 (ConversionDataType from, ConversionDataType to)
9961 return (from == DATA_TYPE_SIGNED_64 || to == DATA_TYPE_SIGNED_64 ||
9962 from == DATA_TYPE_UNSIGNED_64 || to == DATA_TYPE_UNSIGNED_64);
9965 bool usesFloat16 (ConversionDataType from, ConversionDataType to)
9967 return (from == DATA_TYPE_FLOAT_16 || to == DATA_TYPE_FLOAT_16);
9970 bool usesFloat32 (ConversionDataType from, ConversionDataType to)
9972 return (from == DATA_TYPE_FLOAT_32 || to == DATA_TYPE_FLOAT_32);
9975 bool usesFloat64 (ConversionDataType from, ConversionDataType to)
9977 return (from == DATA_TYPE_FLOAT_64 || to == DATA_TYPE_FLOAT_64);
9980 void getVulkanFeaturesAndExtensions (ConversionDataType from, ConversionDataType to, bool useStorageExt, VulkanFeatures& vulkanFeatures, vector<string>& extensions)
9982 if (usesInt16(from, to) && !usesInt32(from, to))
9983 vulkanFeatures.coreFeatures.shaderInt16 = DE_TRUE;
9985 if (usesInt64(from, to))
9986 vulkanFeatures.coreFeatures.shaderInt64 = DE_TRUE;
9988 if (usesFloat64(from, to))
9989 vulkanFeatures.coreFeatures.shaderFloat64 = DE_TRUE;
9991 if ((usesInt16(from, to) || usesFloat16(from, to)) && useStorageExt)
9993 extensions.push_back("VK_KHR_16bit_storage");
9994 vulkanFeatures.ext16BitStorage |= EXT16BITSTORAGEFEATURES_UNIFORM_BUFFER_BLOCK;
9997 if (usesFloat16(from, to) || usesInt8(from, to))
9999 extensions.push_back("VK_KHR_shader_float16_int8");
10001 if (usesFloat16(from, to))
10003 vulkanFeatures.extFloat16Int8 |= EXTFLOAT16INT8FEATURES_FLOAT16;
10006 if (usesInt8(from, to))
10008 vulkanFeatures.extFloat16Int8 |= EXTFLOAT16INT8FEATURES_INT8;
10010 extensions.push_back("VK_KHR_8bit_storage");
10011 vulkanFeatures.ext8BitStorage |= EXT8BITSTORAGEFEATURES_STORAGE_BUFFER;
10018 ConvertCase (const string& instruction, ConversionDataType from, ConversionDataType to, deInt64 number, bool separateOutput = false, deInt64 outputNumber = 0, const char* suffix = DE_NULL, bool useStorageExt = true)
10019 : m_fromType (from)
10022 , m_useStorageExt (useStorageExt)
10023 , m_name (getTestName(from, to, suffix))
10029 m_asmTypes["inStorageType"] = getAsmTypeName(from);
10030 m_asmTypes["outStorageType"] = getAsmTypeName(to);
10031 m_asmTypes["inCast"] = "OpCopyObject";
10032 m_asmTypes["outCast"] = "OpCopyObject";
10033 // If the storage extensions are being avoided, tests instead uses
10034 // vectors so that they are easily convertible to 32-bit integers.
10035 // |m_elements| indicates the size of the vector. It modifies how many
10036 // items added to the buffers and converted in the tests.
10038 // Currently only supports 1 (default) or 2 elements.
10039 if (!m_useStorageExt)
10041 bool in_change = false;
10042 bool out_change = false;
10043 if (usesFloat16(from, from) || usesInt16(from, from))
10045 m_asmTypes["inStorageType"] = "u32";
10046 m_asmTypes["inCast"] = "OpBitcast";
10050 if (usesFloat16(to, to) || usesInt16(to, to))
10052 m_asmTypes["outStorageType"] = "u32";
10053 m_asmTypes["outCast"] = "OpBitcast";
10057 if (in_change && !out_change)
10059 m_asmTypes["outStorageType"] = getAsmTypeName(to, m_elements);
10061 if (!in_change && out_change)
10063 m_asmTypes["inStorageType"] = getAsmTypeName(from, m_elements);
10067 // Safety check for implementation.
10068 if (m_elements < 1 || m_elements > 2)
10069 TCU_THROW(InternalError, "Unsupported number of elements");
10071 m_asmTypes["inputType"] = getAsmTypeName(from, m_elements);
10072 m_asmTypes["outputType"] = getAsmTypeName(to, m_elements);
10074 m_inputBuffer = getBuffer(from, number, m_elements);
10075 if (separateOutput)
10076 m_outputBuffer = getBuffer(to, outputNumber, m_elements);
10078 m_outputBuffer = getBuffer(to, number, m_elements);
10080 if (usesInt8(from, to))
10082 bool requiresInt8Capability = true;
10083 if (instruction == "OpUConvert" || instruction == "OpSConvert")
10085 // Conversions between 8 and 32 bit are provided by SPV_KHR_8bit_storage. The rest requires explicit Int8
10086 if (usesInt32(from, to))
10087 requiresInt8Capability = false;
10090 caps += "OpCapability StorageBuffer8BitAccess\n";
10091 if (requiresInt8Capability)
10092 caps += "OpCapability Int8\n";
10094 decl += "%i8 = OpTypeInt 8 1\n"
10095 "%u8 = OpTypeInt 8 0\n";
10097 if (m_elements == 2)
10099 decl += "%v2i8 = OpTypeVector %i8 2\n"
10100 "%v2u8 = OpTypeVector %u8 2\n";
10102 exts += "OpExtension \"SPV_KHR_8bit_storage\"\n";
10105 if (usesInt16(from, to))
10107 bool requiresInt16Capability = true;
10109 if (instruction == "OpUConvert" || instruction == "OpSConvert" || instruction == "OpFConvert")
10111 // Width-only conversions between 16 and 32 bit are provided by SPV_KHR_16bit_storage. The rest requires explicit Int16
10112 if (usesInt32(from, to) || usesFloat32(from, to))
10113 requiresInt16Capability = false;
10116 decl += "%i16 = OpTypeInt 16 1\n"
10117 "%u16 = OpTypeInt 16 0\n";
10118 if (m_elements == 2)
10120 decl += "%v2i16 = OpTypeVector %i16 2\n"
10121 "%v2u16 = OpTypeVector %u16 2\n";
10125 decl += "%i16vec2 = OpTypeVector %i16 2\n";
10128 // Conversions between 16 and 32 bit are provided by SPV_KHR_16bit_storage. The rest requires explicit Int16
10129 if (requiresInt16Capability || !m_useStorageExt)
10130 caps += "OpCapability Int16\n";
10133 if (usesFloat16(from, to))
10135 decl += "%f16 = OpTypeFloat 16\n";
10136 if (m_elements == 2)
10138 decl += "%v2f16 = OpTypeVector %f16 2\n";
10141 // Width-only conversions between 16 and 32 bit are provided by SPV_KHR_16bit_storage. The rest requires explicit Float16
10142 if (!usesFloat32(from, to) || !m_useStorageExt)
10143 caps += "OpCapability Float16\n";
10146 if ((usesInt16(from, to) || usesFloat16(from, to)) && m_useStorageExt)
10148 caps += "OpCapability StorageUniformBufferBlock16\n";
10149 exts += "OpExtension \"SPV_KHR_16bit_storage\"\n";
10152 if (usesInt64(from, to))
10154 caps += "OpCapability Int64\n";
10155 decl += "%i64 = OpTypeInt 64 1\n"
10156 "%u64 = OpTypeInt 64 0\n";
10157 if (m_elements == 2)
10159 decl += "%v2i64 = OpTypeVector %i64 2\n"
10160 "%v2u64 = OpTypeVector %u64 2\n";
10164 if (usesFloat64(from, to))
10166 caps += "OpCapability Float64\n";
10167 decl += "%f64 = OpTypeFloat 64\n";
10168 if (m_elements == 2)
10170 decl += "%v2f64 = OpTypeVector %f64 2\n";
10174 m_asmTypes["datatype_capabilities"] = caps;
10175 m_asmTypes["datatype_additional_decl"] = decl;
10176 m_asmTypes["datatype_extensions"] = exts;
10179 ConversionDataType m_fromType;
10180 ConversionDataType m_toType;
10181 deUint32 m_elements;
10182 bool m_useStorageExt;
10184 map<string, string> m_asmTypes;
10185 BufferSp m_inputBuffer;
10186 BufferSp m_outputBuffer;
10189 const string getConvertCaseShaderStr (const string& instruction, const ConvertCase& convertCase, bool addVectors = false)
10191 map<string, string> params = convertCase.m_asmTypes;
10193 params["instruction"] = instruction;
10194 params["inDecorator"] = getByteWidthStr(convertCase.m_fromType);
10195 params["outDecorator"] = getByteWidthStr(convertCase.m_toType);
10197 std::string shader (
10198 "OpCapability Shader\n"
10199 "${datatype_capabilities}"
10200 "${datatype_extensions:opt}"
10201 "OpMemoryModel Logical GLSL450\n"
10202 "OpEntryPoint GLCompute %main \"main\"\n"
10203 "OpExecutionMode %main LocalSize 1 1 1\n"
10204 "OpSource GLSL 430\n"
10205 "OpName %main \"main\"\n"
10207 "OpDecorate %indata DescriptorSet 0\n"
10208 "OpDecorate %indata Binding 0\n"
10209 "OpDecorate %outdata DescriptorSet 0\n"
10210 "OpDecorate %outdata Binding 1\n"
10211 "OpDecorate %in_buf BufferBlock\n"
10212 "OpDecorate %out_buf BufferBlock\n"
10213 "OpMemberDecorate %in_buf 0 Offset 0\n"
10214 "OpMemberDecorate %out_buf 0 Offset 0\n"
10216 "%void = OpTypeVoid\n"
10217 "%voidf = OpTypeFunction %void\n"
10218 "%u32 = OpTypeInt 32 0\n"
10219 "%i32 = OpTypeInt 32 1\n"
10220 "%f32 = OpTypeFloat 32\n"
10221 "%v2i32 = OpTypeVector %i32 2\n"
10222 "${datatype_additional_decl}"
10226 shader += "%v2u32 = OpTypeVector %u32 2\n"
10227 "%v2f32 = OpTypeVector %f32 2\n";
10230 "%uvec3 = OpTypeVector %u32 3\n"
10232 "%in_ptr = OpTypePointer Uniform %${inStorageType}\n"
10233 "%out_ptr = OpTypePointer Uniform %${outStorageType}\n"
10234 "%in_buf = OpTypeStruct %${inStorageType}\n"
10235 "%out_buf = OpTypeStruct %${outStorageType}\n"
10236 "%in_bufptr = OpTypePointer Uniform %in_buf\n"
10237 "%out_bufptr = OpTypePointer Uniform %out_buf\n"
10238 "%indata = OpVariable %in_bufptr Uniform\n"
10239 "%outdata = OpVariable %out_bufptr Uniform\n"
10241 "%zero = OpConstant %i32 0\n"
10243 "%main = OpFunction %void None %voidf\n"
10244 "%label = OpLabel\n"
10245 "%inloc = OpAccessChain %in_ptr %indata %zero\n"
10246 "%outloc = OpAccessChain %out_ptr %outdata %zero\n"
10247 "%inval = OpLoad %${inStorageType} %inloc\n"
10248 "%in_cast = ${inCast} %${inputType} %inval\n"
10249 "%conv = ${instruction} %${outputType} %in_cast\n"
10250 "%out_cast = ${outCast} %${outStorageType} %conv\n"
10251 " OpStore %outloc %out_cast\n"
10256 return StringTemplate(shader).specialize(params);
10259 void createConvertCases (vector<ConvertCase>& testCases, const string& instruction)
10261 if (instruction == "OpUConvert")
10263 // Convert unsigned int to unsigned int
10264 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_8, DATA_TYPE_UNSIGNED_16, 42));
10265 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_8, DATA_TYPE_UNSIGNED_32, 73));
10266 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_8, DATA_TYPE_UNSIGNED_64, 121));
10268 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_16, DATA_TYPE_UNSIGNED_8, 33));
10269 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_16, DATA_TYPE_UNSIGNED_32, 60653));
10270 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_16, DATA_TYPE_UNSIGNED_64, 17991));
10272 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_32, DATA_TYPE_UNSIGNED_64, 904256275));
10273 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_32, DATA_TYPE_UNSIGNED_16, 6275));
10274 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_32, DATA_TYPE_UNSIGNED_8, 17));
10276 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_64, DATA_TYPE_UNSIGNED_32, 701256243));
10277 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_64, DATA_TYPE_UNSIGNED_16, 4741));
10278 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_64, DATA_TYPE_UNSIGNED_8, 65));
10280 // Zero extension for int->uint
10281 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_8, DATA_TYPE_UNSIGNED_16, 56));
10282 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_8, DATA_TYPE_UNSIGNED_32, -47, true, 209));
10283 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_8, DATA_TYPE_UNSIGNED_64, -5, true, 251));
10284 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_16, DATA_TYPE_UNSIGNED_32, 14669));
10285 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_16, DATA_TYPE_UNSIGNED_64, -3341, true, 62195));
10286 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_32, DATA_TYPE_UNSIGNED_64, 973610259));
10288 // Truncate for int->uint
10289 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_16, DATA_TYPE_UNSIGNED_8, -25711, true, 145));
10290 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_32, DATA_TYPE_UNSIGNED_8, 103));
10291 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_64, DATA_TYPE_UNSIGNED_8, -1067742499291926803ll, true, 237));
10292 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_32, DATA_TYPE_UNSIGNED_16, 12382));
10293 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_64, DATA_TYPE_UNSIGNED_32, -972812359, true, 3322154937u));
10294 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_64, DATA_TYPE_UNSIGNED_16, -1067742499291926803ll, true, 61165));
10296 else if (instruction == "OpSConvert")
10298 // Sign extension int->int
10299 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_8, DATA_TYPE_SIGNED_16, -30));
10300 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_8, DATA_TYPE_SIGNED_32, 55));
10301 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_8, DATA_TYPE_SIGNED_64, -3));
10302 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_16, DATA_TYPE_SIGNED_32, 14669));
10303 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_16, DATA_TYPE_SIGNED_64, -3341));
10304 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_32, DATA_TYPE_SIGNED_64, 973610259));
10306 // Truncate for int->int
10307 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_16, DATA_TYPE_SIGNED_8, 81));
10308 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_32, DATA_TYPE_SIGNED_8, -93));
10309 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_64, DATA_TYPE_SIGNED_8, 3182748172687672ll, true, 56));
10310 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_32, DATA_TYPE_SIGNED_16, 12382));
10311 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_64, DATA_TYPE_SIGNED_32, -972812359));
10312 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_64, DATA_TYPE_SIGNED_16, -1067742499291926803ll, true, -4371));
10314 // Sign extension for int->uint
10315 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_8, DATA_TYPE_UNSIGNED_16, 56));
10316 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_8, DATA_TYPE_UNSIGNED_32, -47, true, 4294967249u));
10317 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_8, DATA_TYPE_UNSIGNED_64, -5, true, 18446744073709551611ull));
10318 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_16, DATA_TYPE_UNSIGNED_32, 14669));
10319 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_16, DATA_TYPE_UNSIGNED_64, -3341, true, 18446744073709548275ull));
10320 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_32, DATA_TYPE_UNSIGNED_64, 973610259));
10322 // Truncate for int->uint
10323 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_16, DATA_TYPE_UNSIGNED_8, -25711, true, 145));
10324 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_32, DATA_TYPE_UNSIGNED_8, 103));
10325 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_64, DATA_TYPE_UNSIGNED_8, -1067742499291926803ll, true, 237));
10326 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_32, DATA_TYPE_UNSIGNED_16, 12382));
10327 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_64, DATA_TYPE_UNSIGNED_32, -972812359, true, 3322154937u));
10328 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_64, DATA_TYPE_UNSIGNED_16, -1067742499291926803ll, true, 61165));
10330 // Sign extension for uint->int
10331 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_8, DATA_TYPE_SIGNED_16, 71));
10332 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_8, DATA_TYPE_SIGNED_32, 201, true, -55));
10333 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_8, DATA_TYPE_SIGNED_64, 188, true, -68));
10334 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_16, DATA_TYPE_SIGNED_32, 14669));
10335 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_16, DATA_TYPE_SIGNED_64, 62195, true, -3341));
10336 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_32, DATA_TYPE_SIGNED_64, 973610259));
10338 // Truncate for uint->int
10339 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_16, DATA_TYPE_SIGNED_8, 67));
10340 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_32, DATA_TYPE_SIGNED_8, 133, true, -123));
10341 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_64, DATA_TYPE_SIGNED_8, 836927654193256494ull, true, 46));
10342 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_32, DATA_TYPE_SIGNED_16, 12382));
10343 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_64, DATA_TYPE_SIGNED_32, 18446744072736739257ull, true, -972812359));
10344 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_64, DATA_TYPE_SIGNED_16, 17379001574417624813ull, true, -4371));
10346 // Convert i16vec2 to i32vec2 and vice versa
10347 // Unsigned values are used here to represent negative signed values and to allow defined shifting behaviour.
10348 // The actual signed value -32123 is used here as uint16 value 33413 and uint32 value 4294935173
10349 testCases.push_back(ConvertCase(instruction, DATA_TYPE_VEC2_SIGNED_16, DATA_TYPE_VEC2_SIGNED_32, (33413u << 16) | 27593, true, (4294935173ull << 32) | 27593));
10350 testCases.push_back(ConvertCase(instruction, DATA_TYPE_VEC2_SIGNED_32, DATA_TYPE_VEC2_SIGNED_16, (4294935173ull << 32) | 27593, true, (33413u << 16) | 27593));
10352 else if (instruction == "OpFConvert")
10354 // All hexadecimal values below represent 1234.0 as 16/32/64-bit IEEE 754 float
10355 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_32, DATA_TYPE_FLOAT_64, 0x449a4000, true, 0x4093480000000000));
10356 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_64, DATA_TYPE_FLOAT_32, 0x4093480000000000, true, 0x449a4000));
10358 // Conversion to/from 32-bit floats are supported by both 16-bit
10359 // storage and Float16. The tests are duplicated to exercise both
10361 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_32, DATA_TYPE_FLOAT_16, 0x449a4000, true, 0x64D2));
10362 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_FLOAT_32, 0x64D2, true, 0x449a4000));
10363 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_32, DATA_TYPE_FLOAT_16, 0x449a4000, true, 0x64D2, "no_storage", false));
10364 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_FLOAT_32, 0x64D2, true, 0x449a4000, "no_storage", false));
10366 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_FLOAT_64, 0x64D2, true, 0x4093480000000000));
10367 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_64, DATA_TYPE_FLOAT_16, 0x4093480000000000, true, 0x64D2));
10369 else if (instruction == "OpConvertFToU")
10371 // Normal numbers from uint8 range
10372 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_UNSIGNED_8, 0x5020, true, 33, "33", false));
10373 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_32, DATA_TYPE_UNSIGNED_8, 0x42280000, true, 42, "42"));
10374 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_64, DATA_TYPE_UNSIGNED_8, 0x4067800000000000ull, true, 188, "188"));
10376 // Maximum uint8 value
10377 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_UNSIGNED_8, 0x5BF8, true, 255, "max", false));
10378 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_32, DATA_TYPE_UNSIGNED_8, 0x437F0000, true, 255, "max"));
10379 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_64, DATA_TYPE_UNSIGNED_8, 0x406FE00000000000ull, true, 255, "max"));
10382 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_UNSIGNED_8, 0x0000, true, 0, "p0", false));
10383 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_32, DATA_TYPE_UNSIGNED_8, 0x00000000, true, 0, "p0"));
10384 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_64, DATA_TYPE_UNSIGNED_8, 0x0000000000000000ull, true, 0, "p0"));
10387 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_UNSIGNED_8, 0x8000, true, 0, "m0", false));
10388 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_32, DATA_TYPE_UNSIGNED_8, 0x80000000, true, 0, "m0"));
10389 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_64, DATA_TYPE_UNSIGNED_8, 0x8000000000000000ull, true, 0, "m0"));
10391 // All hexadecimal values below represent 1234.0 as 16/32/64-bit IEEE 754 float
10392 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_UNSIGNED_16, 0x64D2, true, 1234, "1234", false));
10393 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_UNSIGNED_32, 0x64D2, true, 1234, "1234", false));
10394 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_UNSIGNED_64, 0x64D2, true, 1234, "1234", false));
10396 // 0x7BFF = 0111 1011 1111 1111 = 0 11110 1111111111 = 65504
10397 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_UNSIGNED_16, 0x7BFF, true, 65504, "max", false));
10398 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_UNSIGNED_32, 0x7BFF, true, 65504, "max", false));
10399 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_UNSIGNED_64, 0x7BFF, true, 65504, "max", false));
10402 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_UNSIGNED_32, 0x0000, true, 0, "p0", false));
10403 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_UNSIGNED_16, 0x0000, true, 0, "p0", false));
10404 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_UNSIGNED_64, 0x0000, true, 0, "p0", false));
10407 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_UNSIGNED_16, 0x8000, true, 0, "m0", false));
10408 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_UNSIGNED_32, 0x8000, true, 0, "m0", false));
10409 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_UNSIGNED_64, 0x8000, true, 0, "m0", false));
10411 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_32, DATA_TYPE_UNSIGNED_16, 0x449a4000, true, 1234));
10412 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_32, DATA_TYPE_UNSIGNED_32, 0x449a4000, true, 1234));
10413 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_32, DATA_TYPE_UNSIGNED_64, 0x449a4000, true, 1234));
10414 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_64, DATA_TYPE_UNSIGNED_16, 0x4093480000000000, true, 1234));
10415 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_64, DATA_TYPE_UNSIGNED_32, 0x4093480000000000, true, 1234));
10416 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_64, DATA_TYPE_UNSIGNED_64, 0x4093480000000000, true, 1234));
10418 else if (instruction == "OpConvertUToF")
10420 // Normal numbers from uint8 range
10421 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_8, DATA_TYPE_FLOAT_16, 116, true, 0x5740, "116", false));
10422 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_8, DATA_TYPE_FLOAT_32, 232, true, 0x43680000, "232"));
10423 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_8, DATA_TYPE_FLOAT_64, 164, true, 0x4064800000000000ull, "164"));
10425 // Maximum uint8 value
10426 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_8, DATA_TYPE_FLOAT_16, 255, true, 0x5BF8, "max", false));
10427 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_8, DATA_TYPE_FLOAT_32, 255, true, 0x437F0000, "max"));
10428 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_8, DATA_TYPE_FLOAT_64, 255, true, 0x406FE00000000000ull, "max"));
10430 // All hexadecimal values below represent 1234.0 as 32/64-bit IEEE 754 float
10431 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_16, DATA_TYPE_FLOAT_16, 1234, true, 0x64D2, "1234", false));
10432 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_32, DATA_TYPE_FLOAT_16, 1234, true, 0x64D2, "1234", false));
10433 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_64, DATA_TYPE_FLOAT_16, 1234, true, 0x64D2, "1234", false));
10435 // 0x7BFF = 0111 1011 1111 1111 = 0 11110 1111111111 = 65504
10436 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_16, DATA_TYPE_FLOAT_16, 65504, true, 0x7BFF, "max", false));
10437 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_32, DATA_TYPE_FLOAT_16, 65504, true, 0x7BFF, "max", false));
10438 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_64, DATA_TYPE_FLOAT_16, 65504, true, 0x7BFF, "max", false));
10440 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_16, DATA_TYPE_FLOAT_32, 1234, true, 0x449a4000));
10441 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_16, DATA_TYPE_FLOAT_64, 1234, true, 0x4093480000000000));
10442 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_32, DATA_TYPE_FLOAT_32, 1234, true, 0x449a4000));
10443 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_32, DATA_TYPE_FLOAT_64, 1234, true, 0x4093480000000000));
10444 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_64, DATA_TYPE_FLOAT_32, 1234, true, 0x449a4000));
10445 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_64, DATA_TYPE_FLOAT_64, 1234, true, 0x4093480000000000));
10447 else if (instruction == "OpConvertFToS")
10449 // Normal numbers from int8 range
10450 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_SIGNED_8, 0xC980, true, -11, "m11", false));
10451 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_32, DATA_TYPE_SIGNED_8, 0xC2140000, true, -37, "m37"));
10452 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_64, DATA_TYPE_SIGNED_8, 0xC050800000000000ull, true, -66, "m66"));
10454 // Minimum int8 value
10455 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_SIGNED_8, 0xD800, true, -128, "min", false));
10456 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_32, DATA_TYPE_SIGNED_8, 0xC3000000, true, -128, "min"));
10457 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_64, DATA_TYPE_SIGNED_8, 0xC060000000000000ull, true, -128, "min"));
10459 // Maximum int8 value
10460 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_SIGNED_8, 0x57F0, true, 127, "max", false));
10461 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_32, DATA_TYPE_SIGNED_8, 0x42FE0000, true, 127, "max"));
10462 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_64, DATA_TYPE_SIGNED_8, 0x405FC00000000000ull, true, 127, "max"));
10465 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_SIGNED_8, 0x0000, true, 0, "p0", false));
10466 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_32, DATA_TYPE_SIGNED_8, 0x00000000, true, 0, "p0"));
10467 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_64, DATA_TYPE_SIGNED_8, 0x0000000000000000ull, true, 0, "p0"));
10470 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_SIGNED_8, 0x8000, true, 0, "m0", false));
10471 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_32, DATA_TYPE_SIGNED_8, 0x80000000, true, 0, "m0"));
10472 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_64, DATA_TYPE_SIGNED_8, 0x8000000000000000ull, true, 0, "m0"));
10474 // All hexadecimal values below represent -1234.0 as 32/64-bit IEEE 754 float
10475 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_SIGNED_16, 0xE4D2, true, -1234, "m1234", false));
10476 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_SIGNED_32, 0xE4D2, true, -1234, "m1234", false));
10477 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_SIGNED_64, 0xE4D2, true, -1234, "m1234", false));
10479 // 0xF800 = 1111 1000 0000 0000 = 1 11110 0000000000 = -32768
10480 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_SIGNED_16, 0xF800, true, -32768, "min", false));
10481 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_SIGNED_32, 0xF800, true, -32768, "min", false));
10482 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_SIGNED_64, 0xF800, true, -32768, "min", false));
10484 // 0x77FF = 0111 0111 1111 1111 = 0 11101 1111111111 = 32752
10485 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_SIGNED_16, 0x77FF, true, 32752, "max", false));
10486 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_SIGNED_32, 0x77FF, true, 32752, "max", false));
10487 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_SIGNED_64, 0x77FF, true, 32752, "max", false));
10490 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_SIGNED_16, 0x0000, true, 0, "p0", false));
10491 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_SIGNED_32, 0x0000, true, 0, "p0", false));
10492 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_SIGNED_64, 0x0000, true, 0, "p0", false));
10495 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_SIGNED_16, 0x8000, true, 0, "m0", false));
10496 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_SIGNED_32, 0x8000, true, 0, "m0", false));
10497 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_SIGNED_64, 0x8000, true, 0, "m0", false));
10499 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_32, DATA_TYPE_SIGNED_16, 0xc49a4000, true, -1234));
10500 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_32, DATA_TYPE_SIGNED_32, 0xc49a4000, true, -1234));
10501 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_32, DATA_TYPE_SIGNED_64, 0xc49a4000, true, -1234));
10502 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_64, DATA_TYPE_SIGNED_16, 0xc093480000000000, true, -1234));
10503 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_64, DATA_TYPE_SIGNED_32, 0xc093480000000000, true, -1234));
10504 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_64, DATA_TYPE_SIGNED_64, 0xc093480000000000, true, -1234));
10505 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_32, DATA_TYPE_SIGNED_16, 0x453b9000, true, 3001, "p3001"));
10506 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_32, DATA_TYPE_SIGNED_16, 0xc53b9000, true, -3001, "m3001"));
10508 else if (instruction == "OpConvertSToF")
10510 // Normal numbers from int8 range
10511 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_8, DATA_TYPE_FLOAT_16, -12, true, 0xCA00, "m21", false));
10512 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_8, DATA_TYPE_FLOAT_32, -21, true, 0xC1A80000, "m21"));
10513 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_8, DATA_TYPE_FLOAT_64, -99, true, 0xC058C00000000000ull, "m99"));
10515 // Minimum int8 value
10516 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_8, DATA_TYPE_FLOAT_16, -128, true, 0xD800, "min", false));
10517 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_8, DATA_TYPE_FLOAT_32, -128, true, 0xC3000000, "min"));
10518 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_8, DATA_TYPE_FLOAT_64, -128, true, 0xC060000000000000ull, "min"));
10520 // Maximum int8 value
10521 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_8, DATA_TYPE_FLOAT_16, 127, true, 0x57F0, "max", false));
10522 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_8, DATA_TYPE_FLOAT_32, 127, true, 0x42FE0000, "max"));
10523 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_8, DATA_TYPE_FLOAT_64, 127, true, 0x405FC00000000000ull, "max"));
10525 // All hexadecimal values below represent 1234.0 as 32/64-bit IEEE 754 float
10526 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_16, DATA_TYPE_FLOAT_16, -1234, true, 0xE4D2, "m1234", false));
10527 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_32, DATA_TYPE_FLOAT_16, -1234, true, 0xE4D2, "m1234", false));
10528 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_64, DATA_TYPE_FLOAT_16, -1234, true, 0xE4D2, "m1234", false));
10530 // 0xF800 = 1111 1000 0000 0000 = 1 11110 0000000000 = -32768
10531 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_16, DATA_TYPE_FLOAT_16, -32768, true, 0xF800, "min", false));
10532 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_32, DATA_TYPE_FLOAT_16, -32768, true, 0xF800, "min", false));
10533 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_64, DATA_TYPE_FLOAT_16, -32768, true, 0xF800, "min", false));
10535 // 0x77FF = 0111 0111 1111 1111 = 0 11101 1111111111 = 32752
10536 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_16, DATA_TYPE_FLOAT_16, 32752, true, 0x77FF, "max", false));
10537 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_32, DATA_TYPE_FLOAT_16, 32752, true, 0x77FF, "max", false));
10538 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_64, DATA_TYPE_FLOAT_16, 32752, true, 0x77FF, "max", false));
10540 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_16, DATA_TYPE_FLOAT_32, -1234, true, 0xc49a4000));
10541 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_16, DATA_TYPE_FLOAT_64, -1234, true, 0xc093480000000000));
10542 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_32, DATA_TYPE_FLOAT_32, -1234, true, 0xc49a4000));
10543 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_32, DATA_TYPE_FLOAT_64, -1234, true, 0xc093480000000000));
10544 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_64, DATA_TYPE_FLOAT_32, -1234, true, 0xc49a4000));
10545 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_64, DATA_TYPE_FLOAT_64, -1234, true, 0xc093480000000000));
10548 DE_FATAL("Unknown instruction");
10551 const map<string, string> getConvertCaseFragments (string instruction, const ConvertCase& convertCase)
10553 map<string, string> params = convertCase.m_asmTypes;
10554 map<string, string> fragments;
10556 params["instruction"] = instruction;
10557 params["inDecorator"] = getByteWidthStr(convertCase.m_fromType);
10559 const StringTemplate decoration (
10560 " OpDecorate %SSBOi DescriptorSet 0\n"
10561 " OpDecorate %SSBOo DescriptorSet 0\n"
10562 " OpDecorate %SSBOi Binding 0\n"
10563 " OpDecorate %SSBOo Binding 1\n"
10564 " OpDecorate %s_SSBOi Block\n"
10565 " OpDecorate %s_SSBOo Block\n"
10566 "OpMemberDecorate %s_SSBOi 0 Offset 0\n"
10567 "OpMemberDecorate %s_SSBOo 0 Offset 0\n");
10569 const StringTemplate pre_main (
10570 "${datatype_additional_decl:opt}"
10571 " %ptr_in = OpTypePointer StorageBuffer %${inputType}\n"
10572 " %ptr_out = OpTypePointer StorageBuffer %${outputType}\n"
10573 " %s_SSBOi = OpTypeStruct %${inputType}\n"
10574 " %s_SSBOo = OpTypeStruct %${outputType}\n"
10575 " %ptr_SSBOi = OpTypePointer StorageBuffer %s_SSBOi\n"
10576 " %ptr_SSBOo = OpTypePointer StorageBuffer %s_SSBOo\n"
10577 " %SSBOi = OpVariable %ptr_SSBOi StorageBuffer\n"
10578 " %SSBOo = OpVariable %ptr_SSBOo StorageBuffer\n");
10580 const StringTemplate testfun (
10581 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
10582 "%param = OpFunctionParameter %v4f32\n"
10583 "%label = OpLabel\n"
10584 "%iLoc = OpAccessChain %ptr_in %SSBOi %c_u32_0\n"
10585 "%oLoc = OpAccessChain %ptr_out %SSBOo %c_u32_0\n"
10586 "%valIn = OpLoad %${inputType} %iLoc\n"
10587 "%valOut = ${instruction} %${outputType} %valIn\n"
10588 " OpStore %oLoc %valOut\n"
10589 " OpReturnValue %param\n"
10590 " OpFunctionEnd\n");
10592 params["datatype_extensions"] =
10593 params["datatype_extensions"] +
10594 "OpExtension \"SPV_KHR_storage_buffer_storage_class\"\n";
10596 fragments["capability"] = params["datatype_capabilities"];
10597 fragments["extension"] = params["datatype_extensions"];
10598 fragments["decoration"] = decoration.specialize(params);
10599 fragments["pre_main"] = pre_main.specialize(params);
10600 fragments["testfun"] = testfun.specialize(params);
10605 // Test for OpSConvert, OpUConvert, OpFConvert and OpConvert* in compute shaders
10606 tcu::TestCaseGroup* createConvertComputeTests (tcu::TestContext& testCtx, const string& instruction, const string& name)
10608 de::MovePtr<tcu::TestCaseGroup> group(new tcu::TestCaseGroup(testCtx, name.c_str(), instruction.c_str()));
10609 vector<ConvertCase> testCases;
10610 createConvertCases(testCases, instruction);
10612 for (vector<ConvertCase>::const_iterator test = testCases.begin(); test != testCases.end(); ++test)
10614 ComputeShaderSpec spec;
10615 spec.assembly = getConvertCaseShaderStr(instruction, *test, true);
10616 spec.numWorkGroups = IVec3(1, 1, 1);
10617 spec.inputs.push_back (test->m_inputBuffer);
10618 spec.outputs.push_back (test->m_outputBuffer);
10620 getVulkanFeaturesAndExtensions(test->m_fromType, test->m_toType, test->m_useStorageExt, spec.requestedVulkanFeatures, spec.extensions);
10622 group->addChild(new SpvAsmComputeShaderCase(testCtx, test->m_name.c_str(), "", spec));
10624 return group.release();
10627 // Test for OpSConvert, OpUConvert, OpFConvert and OpConvert* in graphics shaders
10628 tcu::TestCaseGroup* createConvertGraphicsTests (tcu::TestContext& testCtx, const string& instruction, const string& name)
10630 de::MovePtr<tcu::TestCaseGroup> group(new tcu::TestCaseGroup(testCtx, name.c_str(), instruction.c_str()));
10631 vector<ConvertCase> testCases;
10632 createConvertCases(testCases, instruction);
10634 for (vector<ConvertCase>::const_iterator test = testCases.begin(); test != testCases.end(); ++test)
10636 map<string, string> fragments = getConvertCaseFragments(instruction, *test);
10637 VulkanFeatures vulkanFeatures;
10638 GraphicsResources resources;
10639 vector<string> extensions;
10640 SpecConstants noSpecConstants;
10641 PushConstants noPushConstants;
10642 GraphicsInterfaces noInterfaces;
10643 tcu::RGBA defaultColors[4];
10645 getDefaultColors (defaultColors);
10646 resources.inputs.push_back (Resource(test->m_inputBuffer, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
10647 resources.outputs.push_back (Resource(test->m_outputBuffer, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
10648 extensions.push_back ("VK_KHR_storage_buffer_storage_class");
10650 getVulkanFeaturesAndExtensions(test->m_fromType, test->m_toType, test->m_useStorageExt, vulkanFeatures, extensions);
10652 vulkanFeatures.coreFeatures.vertexPipelineStoresAndAtomics = true;
10653 vulkanFeatures.coreFeatures.fragmentStoresAndAtomics = true;
10655 createTestsForAllStages(
10656 test->m_name, defaultColors, defaultColors, fragments, noSpecConstants,
10657 noPushConstants, resources, noInterfaces, extensions, vulkanFeatures, group.get());
10659 return group.release();
10662 // Constant-Creation Instructions: OpConstant, OpConstantComposite
10663 tcu::TestCaseGroup* createOpConstantFloat16Tests(tcu::TestContext& testCtx)
10665 de::MovePtr<tcu::TestCaseGroup> opConstantCompositeTests (new tcu::TestCaseGroup(testCtx, "opconstant", "OpConstant and OpConstantComposite instruction"));
10666 RGBA inputColors[4];
10667 RGBA outputColors[4];
10668 vector<string> extensions;
10669 GraphicsResources resources;
10670 VulkanFeatures features;
10672 const char functionStart[] =
10673 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
10674 "%param1 = OpFunctionParameter %v4f32\n"
10675 "%lbl = OpLabel\n";
10677 const char functionEnd[] =
10678 "%transformed_param_32 = OpFConvert %v4f32 %transformed_param\n"
10679 " OpReturnValue %transformed_param_32\n"
10680 " OpFunctionEnd\n";
10682 struct NameConstantsCode
10689 #define FLOAT_16_COMMON_TYPES_AND_CONSTS \
10690 "%f16 = OpTypeFloat 16\n" \
10691 "%c_f16_0 = OpConstant %f16 0.0\n" \
10692 "%c_f16_0_5 = OpConstant %f16 0.5\n" \
10693 "%c_f16_1 = OpConstant %f16 1.0\n" \
10694 "%v4f16 = OpTypeVector %f16 4\n" \
10695 "%fp_f16 = OpTypePointer Function %f16\n" \
10696 "%fp_v4f16 = OpTypePointer Function %v4f16\n" \
10697 "%c_v4f16_1_1_1_1 = OpConstantComposite %v4f16 %c_f16_1 %c_f16_1 %c_f16_1 %c_f16_1\n" \
10698 "%a4f16 = OpTypeArray %f16 %c_u32_4\n" \
10700 NameConstantsCode tests[] =
10705 FLOAT_16_COMMON_TYPES_AND_CONSTS
10706 "%cval = OpConstantComposite %v4f16 %c_f16_0_5 %c_f16_0_5 %c_f16_0_5 %c_f16_0\n",
10707 "%param1_16 = OpFConvert %v4f16 %param1\n"
10708 "%transformed_param = OpFAdd %v4f16 %param1_16 %cval\n"
10713 FLOAT_16_COMMON_TYPES_AND_CONSTS
10714 "%stype = OpTypeStruct %v4f16 %f16\n"
10715 "%fp_stype = OpTypePointer Function %stype\n"
10716 "%f16_n_1 = OpConstant %f16 -1.0\n"
10717 "%f16_1_5 = OpConstant %f16 !0x3e00\n" // +1.5
10718 "%cvec = OpConstantComposite %v4f16 %f16_1_5 %f16_1_5 %f16_1_5 %c_f16_1\n"
10719 "%cval = OpConstantComposite %stype %cvec %f16_n_1\n",
10721 "%v = OpVariable %fp_stype Function %cval\n"
10722 "%vec_ptr = OpAccessChain %fp_v4f16 %v %c_u32_0\n"
10723 "%f16_ptr = OpAccessChain %fp_f16 %v %c_u32_1\n"
10724 "%vec_val = OpLoad %v4f16 %vec_ptr\n"
10725 "%f16_val = OpLoad %f16 %f16_ptr\n"
10726 "%tmp1 = OpVectorTimesScalar %v4f16 %c_v4f16_1_1_1_1 %f16_val\n" // vec4(-1)
10727 "%param1_16 = OpFConvert %v4f16 %param1\n"
10728 "%tmp2 = OpFAdd %v4f16 %tmp1 %param1_16\n" // param1 + vec4(-1)
10729 "%transformed_param = OpFAdd %v4f16 %tmp2 %vec_val\n" // param1 + vec4(-1) + vec4(1.5, 1.5, 1.5, 1.0)
10732 // [1|0|0|0.5] [x] = x + 0.5
10733 // [0|1|0|0.5] [y] = y + 0.5
10734 // [0|0|1|0.5] [z] = z + 0.5
10735 // [0|0|0|1 ] [1] = 1
10738 FLOAT_16_COMMON_TYPES_AND_CONSTS
10739 "%mat4x4_f16 = OpTypeMatrix %v4f16 4\n"
10740 "%v4f16_1_0_0_0 = OpConstantComposite %v4f16 %c_f16_1 %c_f16_0 %c_f16_0 %c_f16_0\n"
10741 "%v4f16_0_1_0_0 = OpConstantComposite %v4f16 %c_f16_0 %c_f16_1 %c_f16_0 %c_f16_0\n"
10742 "%v4f16_0_0_1_0 = OpConstantComposite %v4f16 %c_f16_0 %c_f16_0 %c_f16_1 %c_f16_0\n"
10743 "%v4f16_0_5_0_5_0_5_1 = OpConstantComposite %v4f16 %c_f16_0_5 %c_f16_0_5 %c_f16_0_5 %c_f16_1\n"
10744 "%cval = OpConstantComposite %mat4x4_f16 %v4f16_1_0_0_0 %v4f16_0_1_0_0 %v4f16_0_0_1_0 %v4f16_0_5_0_5_0_5_1\n",
10746 "%param1_16 = OpFConvert %v4f16 %param1\n"
10747 "%transformed_param = OpMatrixTimesVector %v4f16 %cval %param1_16\n"
10752 FLOAT_16_COMMON_TYPES_AND_CONSTS
10753 "%c_v4f16_1_1_1_0 = OpConstantComposite %v4f16 %c_f16_1 %c_f16_1 %c_f16_1 %c_f16_0\n"
10754 "%fp_a4f16 = OpTypePointer Function %a4f16\n"
10755 "%f16_n_1 = OpConstant %f16 -1.0\n"
10756 "%f16_1_5 = OpConstant %f16 !0x3e00\n" // +1.5
10757 "%carr = OpConstantComposite %a4f16 %c_f16_0 %f16_n_1 %f16_1_5 %c_f16_0\n",
10759 "%v = OpVariable %fp_a4f16 Function %carr\n"
10760 "%f = OpAccessChain %fp_f16 %v %c_u32_0\n"
10761 "%f1 = OpAccessChain %fp_f16 %v %c_u32_1\n"
10762 "%f2 = OpAccessChain %fp_f16 %v %c_u32_2\n"
10763 "%f3 = OpAccessChain %fp_f16 %v %c_u32_3\n"
10764 "%f_val = OpLoad %f16 %f\n"
10765 "%f1_val = OpLoad %f16 %f1\n"
10766 "%f2_val = OpLoad %f16 %f2\n"
10767 "%f3_val = OpLoad %f16 %f3\n"
10768 "%ftot1 = OpFAdd %f16 %f_val %f1_val\n"
10769 "%ftot2 = OpFAdd %f16 %ftot1 %f2_val\n"
10770 "%ftot3 = OpFAdd %f16 %ftot2 %f3_val\n" // 0 - 1 + 1.5 + 0
10771 "%add_vec = OpVectorTimesScalar %v4f16 %c_v4f16_1_1_1_0 %ftot3\n"
10772 "%param1_16 = OpFConvert %v4f16 %param1\n"
10773 "%transformed_param = OpFAdd %v4f16 %param1_16 %add_vec\n"
10780 // [ 1.0, 1.0, 1.0, 1.0]
10784 // [ 0.0, 0.5, 0.0, 0.0]
10788 // [ 1.0, 1.0, 1.0, 1.0]
10791 "array_of_struct_of_array",
10793 FLOAT_16_COMMON_TYPES_AND_CONSTS
10794 "%c_v4f16_1_1_1_0 = OpConstantComposite %v4f16 %c_f16_1 %c_f16_1 %c_f16_1 %c_f16_0\n"
10795 "%fp_a4f16 = OpTypePointer Function %a4f16\n"
10796 "%stype = OpTypeStruct %f16 %a4f16\n"
10797 "%a3stype = OpTypeArray %stype %c_u32_3\n"
10798 "%fp_a3stype = OpTypePointer Function %a3stype\n"
10799 "%ca4f16_0 = OpConstantComposite %a4f16 %c_f16_0 %c_f16_0_5 %c_f16_0 %c_f16_0\n"
10800 "%ca4f16_1 = OpConstantComposite %a4f16 %c_f16_1 %c_f16_1 %c_f16_1 %c_f16_1\n"
10801 "%cstype1 = OpConstantComposite %stype %c_f16_0 %ca4f16_1\n"
10802 "%cstype2 = OpConstantComposite %stype %c_f16_1 %ca4f16_0\n"
10803 "%carr = OpConstantComposite %a3stype %cstype1 %cstype2 %cstype1",
10805 "%v = OpVariable %fp_a3stype Function %carr\n"
10806 "%f = OpAccessChain %fp_f16 %v %c_u32_1 %c_u32_1 %c_u32_1\n"
10807 "%f_l = OpLoad %f16 %f\n"
10808 "%add_vec = OpVectorTimesScalar %v4f16 %c_v4f16_1_1_1_0 %f_l\n"
10809 "%param1_16 = OpFConvert %v4f16 %param1\n"
10810 "%transformed_param = OpFAdd %v4f16 %param1_16 %add_vec\n"
10814 getHalfColorsFullAlpha(inputColors);
10815 outputColors[0] = RGBA(255, 255, 255, 255);
10816 outputColors[1] = RGBA(255, 127, 127, 255);
10817 outputColors[2] = RGBA(127, 255, 127, 255);
10818 outputColors[3] = RGBA(127, 127, 255, 255);
10820 extensions.push_back("VK_KHR_shader_float16_int8");
10821 features.extFloat16Int8 = EXTFLOAT16INT8FEATURES_FLOAT16;
10823 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameConstantsCode); ++testNdx)
10825 map<string, string> fragments;
10827 fragments["capability"] = "OpCapability Float16\n";
10828 fragments["pre_main"] = tests[testNdx].constants;
10829 fragments["testfun"] = string(functionStart) + tests[testNdx].code + functionEnd;
10831 createTestsForAllStages(tests[testNdx].name, inputColors, outputColors, fragments, resources, extensions, opConstantCompositeTests.get(), features);
10833 return opConstantCompositeTests.release();
10836 template<typename T>
10837 void finalizeTestsCreation (T& specResource,
10838 const map<string, string>& fragments,
10839 tcu::TestContext& testCtx,
10840 tcu::TestCaseGroup& testGroup,
10841 const std::string& testName,
10842 const VulkanFeatures& vulkanFeatures,
10843 const vector<string>& extensions,
10844 const IVec3& numWorkGroups);
10847 void finalizeTestsCreation (GraphicsResources& specResource,
10848 const map<string, string>& fragments,
10849 tcu::TestContext& ,
10850 tcu::TestCaseGroup& testGroup,
10851 const std::string& testName,
10852 const VulkanFeatures& vulkanFeatures,
10853 const vector<string>& extensions,
10856 RGBA defaultColors[4];
10857 getDefaultColors(defaultColors);
10859 createTestsForAllStages(testName, defaultColors, defaultColors, fragments, specResource, extensions, &testGroup, vulkanFeatures);
10863 void finalizeTestsCreation (ComputeShaderSpec& specResource,
10864 const map<string, string>& fragments,
10865 tcu::TestContext& testCtx,
10866 tcu::TestCaseGroup& testGroup,
10867 const std::string& testName,
10868 const VulkanFeatures& vulkanFeatures,
10869 const vector<string>& extensions,
10870 const IVec3& numWorkGroups)
10872 specResource.numWorkGroups = numWorkGroups;
10873 specResource.requestedVulkanFeatures = vulkanFeatures;
10874 specResource.extensions = extensions;
10876 specResource.assembly = makeComputeShaderAssembly(fragments);
10878 testGroup.addChild(new SpvAsmComputeShaderCase(testCtx, testName.c_str(), "", specResource));
10881 template<class SpecResource>
10882 tcu::TestCaseGroup* createFloat16LogicalSet (tcu::TestContext& testCtx, const bool nanSupported)
10884 const string nan = nanSupported ? "_nan" : "";
10885 const string groupName = "logical" + nan;
10886 de::MovePtr<tcu::TestCaseGroup> testGroup (new tcu::TestCaseGroup(testCtx, groupName.c_str(), "Float 16 logical tests"));
10888 de::Random rnd (deStringHash(testGroup->getName()));
10889 const string spvCapabilities = string("OpCapability Float16\n") + (nanSupported ? "OpCapability SignedZeroInfNanPreserve\n" : "");
10890 const string spvExtensions = (nanSupported ? "OpExtension \"SPV_KHR_float_controls\"\n" : "");
10891 const string spvExecutionMode = nanSupported ? "OpExecutionMode %BP_main SignedZeroInfNanPreserve 16\n" : "";
10892 const deUint32 numDataPointsScalar = 16;
10893 const deUint32 numDataPointsVector = 14;
10894 const vector<deFloat16> float16DataScalar = getFloat16s(rnd, numDataPointsScalar);
10895 const vector<deFloat16> float16DataVector = getFloat16s(rnd, numDataPointsVector);
10896 const vector<deFloat16> float16Data1 = squarize(float16DataScalar, 0); // Total Size: square(sizeof(float16DataScalar))
10897 const vector<deFloat16> float16Data2 = squarize(float16DataScalar, 1);
10898 const vector<deFloat16> float16DataVec1 = squarizeVector(float16DataVector, 0); // Total Size: 2 * (square(square(sizeof(float16DataVector))))
10899 const vector<deFloat16> float16DataVec2 = squarizeVector(float16DataVector, 1);
10900 const vector<deFloat16> float16OutDummy (float16Data1.size(), 0);
10901 const vector<deFloat16> float16OutVecDummy (float16DataVec1.size(), 0);
10905 const char* opCode;
10906 VerifyIOFunc verifyFuncNan;
10907 VerifyIOFunc verifyFuncNonNan;
10908 const deUint32 argCount;
10911 const TestOp testOps[] =
10913 { "OpIsNan" , compareFP16Logical<fp16isNan, true, false, true>, compareFP16Logical<fp16isNan, true, false, false>, 1 },
10914 { "OpIsInf" , compareFP16Logical<fp16isInf, true, false, true>, compareFP16Logical<fp16isInf, true, false, false>, 1 },
10915 { "OpFOrdEqual" , compareFP16Logical<fp16isEqual, false, true, true>, compareFP16Logical<fp16isEqual, false, true, false>, 2 },
10916 { "OpFUnordEqual" , compareFP16Logical<fp16isEqual, false, false, true>, compareFP16Logical<fp16isEqual, false, false, false>, 2 },
10917 { "OpFOrdNotEqual" , compareFP16Logical<fp16isUnequal, false, true, true>, compareFP16Logical<fp16isUnequal, false, true, false>, 2 },
10918 { "OpFUnordNotEqual" , compareFP16Logical<fp16isUnequal, false, false, true>, compareFP16Logical<fp16isUnequal, false, false, false>, 2 },
10919 { "OpFOrdLessThan" , compareFP16Logical<fp16isLess, false, true, true>, compareFP16Logical<fp16isLess, false, true, false>, 2 },
10920 { "OpFUnordLessThan" , compareFP16Logical<fp16isLess, false, false, true>, compareFP16Logical<fp16isLess, false, false, false>, 2 },
10921 { "OpFOrdGreaterThan" , compareFP16Logical<fp16isGreater, false, true, true>, compareFP16Logical<fp16isGreater, false, true, false>, 2 },
10922 { "OpFUnordGreaterThan" , compareFP16Logical<fp16isGreater, false, false, true>, compareFP16Logical<fp16isGreater, false, false, false>, 2 },
10923 { "OpFOrdLessThanEqual" , compareFP16Logical<fp16isLessOrEqual, false, true, true>, compareFP16Logical<fp16isLessOrEqual, false, true, false>, 2 },
10924 { "OpFUnordLessThanEqual" , compareFP16Logical<fp16isLessOrEqual, false, false, true>, compareFP16Logical<fp16isLessOrEqual, false, false, false>, 2 },
10925 { "OpFOrdGreaterThanEqual" , compareFP16Logical<fp16isGreaterOrEqual, false, true, true>, compareFP16Logical<fp16isGreaterOrEqual, false, true, false>, 2 },
10926 { "OpFUnordGreaterThanEqual" , compareFP16Logical<fp16isGreaterOrEqual, false, false, true>, compareFP16Logical<fp16isGreaterOrEqual, false, false, false>, 2 },
10930 const StringTemplate preMain
10932 " %c_i32_ndp = OpConstant %i32 ${num_data_points}\n"
10933 " %c_i32_hndp = OpSpecConstantOp %i32 SDiv %c_i32_ndp %c_i32_2\n"
10934 "%c_u32_high_ones = OpConstant %u32 0xffff0000\n"
10935 " %c_u32_low_ones = OpConstant %u32 0x0000ffff\n"
10936 " %f16 = OpTypeFloat 16\n"
10937 " %v2f16 = OpTypeVector %f16 2\n"
10938 " %c_f16_0 = OpConstant %f16 0.0\n"
10939 " %c_f16_1 = OpConstant %f16 1.0\n"
10940 " %up_u32 = OpTypePointer Uniform %u32\n"
10941 " %ra_u32 = OpTypeArray %u32 %c_i32_hndp\n"
10942 " %SSBO16 = OpTypeStruct %ra_u32\n"
10943 " %up_SSBO16 = OpTypePointer Uniform %SSBO16\n"
10944 " %f16_i32_fn = OpTypeFunction %f16 %i32\n"
10945 "%void_f16_i32_fn = OpTypeFunction %void %f16 %i32\n"
10946 " %ssbo_src0 = OpVariable %up_SSBO16 Uniform\n"
10947 " %ssbo_src1 = OpVariable %up_SSBO16 Uniform\n"
10948 " %ssbo_dst = OpVariable %up_SSBO16 Uniform\n"
10951 const StringTemplate decoration
10953 "OpDecorate %ra_u32 ArrayStride 4\n"
10954 "OpMemberDecorate %SSBO16 0 Offset 0\n"
10955 "OpDecorate %SSBO16 BufferBlock\n"
10956 "OpDecorate %ssbo_src0 DescriptorSet 0\n"
10957 "OpDecorate %ssbo_src0 Binding 0\n"
10958 "OpDecorate %ssbo_src1 DescriptorSet 0\n"
10959 "OpDecorate %ssbo_src1 Binding 1\n"
10960 "OpDecorate %ssbo_dst DescriptorSet 0\n"
10961 "OpDecorate %ssbo_dst Binding 2\n"
10964 const StringTemplate testFun
10966 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
10967 " %param = OpFunctionParameter %v4f32\n"
10969 " %entry = OpLabel\n"
10970 " %i = OpVariable %fp_i32 Function\n"
10971 " OpStore %i %c_i32_0\n"
10972 " OpBranch %loop\n"
10974 " %loop = OpLabel\n"
10975 " %i_cmp = OpLoad %i32 %i\n"
10976 " %lt = OpSLessThan %bool %i_cmp %c_i32_ndp\n"
10977 " OpLoopMerge %merge %next None\n"
10978 " OpBranchConditional %lt %write %merge\n"
10980 " %write = OpLabel\n"
10981 " %ndx = OpLoad %i32 %i\n"
10983 " %val_src0 = OpFunctionCall %f16 %ld_arg_ssbo_src0 %ndx\n"
10987 " %val_bdst = ${op_code} %bool %val_src0 ${op_arg1}\n"
10988 " %val_dst = OpSelect %f16 %val_bdst %c_f16_1 %c_f16_0\n"
10989 " %dst = OpFunctionCall %void %st_fn_ssbo_dst %val_dst %ndx\n"
10990 " OpBranch %next\n"
10992 " %next = OpLabel\n"
10993 " %i_cur = OpLoad %i32 %i\n"
10994 " %i_new = OpIAdd %i32 %i_cur %c_i32_1\n"
10995 " OpStore %i %i_new\n"
10996 " OpBranch %loop\n"
10998 " %merge = OpLabel\n"
10999 " OpReturnValue %param\n"
11004 const StringTemplate arg1Calc
11006 " %val_src1 = OpFunctionCall %f16 %ld_arg_ssbo_src1 %ndx\n"
11009 for (deUint32 testOpsIdx = 0; testOpsIdx < DE_LENGTH_OF_ARRAY(testOps); ++testOpsIdx)
11011 const size_t iterations = float16Data1.size();
11012 const TestOp& testOp = testOps[testOpsIdx];
11013 const string testName = de::toLower(string(testOp.opCode)) + "_scalar";
11014 SpecResource specResource;
11015 map<string, string> specs;
11016 VulkanFeatures features;
11017 map<string, string> fragments;
11018 vector<string> extensions;
11020 specs["num_data_points"] = de::toString(iterations);
11021 specs["op_code"] = testOp.opCode;
11022 specs["op_arg1"] = (testOp.argCount == 1) ? "" : "%val_src1";
11023 specs["op_arg1_calc"] = (testOp.argCount == 1) ? "" : arg1Calc.specialize(specs);
11025 fragments["extension"] = spvExtensions;
11026 fragments["capability"] = spvCapabilities;
11027 fragments["execution_mode"] = spvExecutionMode;
11028 fragments["decoration"] = decoration.specialize(specs);
11029 fragments["pre_main"] = preMain.specialize(specs);
11030 fragments["testfun"] = testFun.specialize(specs);
11031 fragments["testfun"] += StringTemplate(loadScalarF16FromUint).specialize({{"var", "ssbo_src0"}});
11032 if (testOp.argCount > 1)
11034 fragments["testfun"] += StringTemplate(loadScalarF16FromUint).specialize({{"var", "ssbo_src1"}});
11036 fragments["testfun"] += StringTemplate(storeScalarF16AsUint).specialize({{"var", "ssbo_dst"}});
11038 specResource.inputs.push_back(Resource(BufferSp(new Float16Buffer(float16Data1)), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
11039 specResource.inputs.push_back(Resource(BufferSp(new Float16Buffer(float16Data2)), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
11040 specResource.outputs.push_back(Resource(BufferSp(new Float16Buffer(float16OutDummy)), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
11041 specResource.verifyIO = nanSupported ? testOp.verifyFuncNan : testOp.verifyFuncNonNan;
11043 extensions.push_back("VK_KHR_shader_float16_int8");
11047 extensions.push_back("VK_KHR_shader_float_controls");
11049 features.floatControlsProperties.shaderSignedZeroInfNanPreserveFloat16 = DE_TRUE;
11052 features.extFloat16Int8 = EXTFLOAT16INT8FEATURES_FLOAT16;
11054 finalizeTestsCreation(specResource, fragments, testCtx, *testGroup.get(), testName, features, extensions, IVec3(1, 1, 1));
11058 const StringTemplate preMain
11060 " %c_i32_ndp = OpConstant %i32 ${num_data_points}\n"
11061 " %v2bool = OpTypeVector %bool 2\n"
11062 " %f16 = OpTypeFloat 16\n"
11063 " %c_f16_0 = OpConstant %f16 0.0\n"
11064 " %c_f16_1 = OpConstant %f16 1.0\n"
11065 " %v2f16 = OpTypeVector %f16 2\n"
11066 " %c_v2f16_0_0 = OpConstantComposite %v2f16 %c_f16_0 %c_f16_0\n"
11067 " %c_v2f16_1_1 = OpConstantComposite %v2f16 %c_f16_1 %c_f16_1\n"
11068 " %up_u32 = OpTypePointer Uniform %u32\n"
11069 " %ra_u32 = OpTypeArray %u32 %c_i32_ndp\n"
11070 " %SSBO16 = OpTypeStruct %ra_u32\n"
11071 " %up_SSBO16 = OpTypePointer Uniform %SSBO16\n"
11072 " %v2f16_i32_fn = OpTypeFunction %v2f16 %i32\n"
11073 "%void_v2f16_i32_fn = OpTypeFunction %void %v2f16 %i32\n"
11074 " %ssbo_src0 = OpVariable %up_SSBO16 Uniform\n"
11075 " %ssbo_src1 = OpVariable %up_SSBO16 Uniform\n"
11076 " %ssbo_dst = OpVariable %up_SSBO16 Uniform\n"
11079 const StringTemplate decoration
11081 "OpDecorate %ra_u32 ArrayStride 4\n"
11082 "OpMemberDecorate %SSBO16 0 Offset 0\n"
11083 "OpDecorate %SSBO16 BufferBlock\n"
11084 "OpDecorate %ssbo_src0 DescriptorSet 0\n"
11085 "OpDecorate %ssbo_src0 Binding 0\n"
11086 "OpDecorate %ssbo_src1 DescriptorSet 0\n"
11087 "OpDecorate %ssbo_src1 Binding 1\n"
11088 "OpDecorate %ssbo_dst DescriptorSet 0\n"
11089 "OpDecorate %ssbo_dst Binding 2\n"
11092 const StringTemplate testFun
11094 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
11095 " %param = OpFunctionParameter %v4f32\n"
11097 " %entry = OpLabel\n"
11098 " %i = OpVariable %fp_i32 Function\n"
11099 " OpStore %i %c_i32_0\n"
11100 " OpBranch %loop\n"
11102 " %loop = OpLabel\n"
11103 " %i_cmp = OpLoad %i32 %i\n"
11104 " %lt = OpSLessThan %bool %i_cmp %c_i32_ndp\n"
11105 " OpLoopMerge %merge %next None\n"
11106 " OpBranchConditional %lt %write %merge\n"
11108 " %write = OpLabel\n"
11109 " %ndx = OpLoad %i32 %i\n"
11111 " %val_src0 = OpFunctionCall %v2f16 %ld_arg_ssbo_src0 %ndx\n"
11115 " %val_bdst = ${op_code} %v2bool %val_src0 ${op_arg1}\n"
11116 " %val_dst = OpSelect %v2f16 %val_bdst %c_v2f16_1_1 %c_v2f16_0_0\n"
11117 " %dst = OpFunctionCall %void %st_fn_ssbo_dst %val_dst %ndx\n"
11118 " OpBranch %next\n"
11120 " %next = OpLabel\n"
11121 " %i_cur = OpLoad %i32 %i\n"
11122 " %i_new = OpIAdd %i32 %i_cur %c_i32_1\n"
11123 " OpStore %i %i_new\n"
11124 " OpBranch %loop\n"
11126 " %merge = OpLabel\n"
11127 " OpReturnValue %param\n"
11132 const StringTemplate arg1Calc
11134 " %val_src1 = OpFunctionCall %v2f16 %ld_arg_ssbo_src1 %ndx\n"
11137 for (deUint32 testOpsIdx = 0; testOpsIdx < DE_LENGTH_OF_ARRAY(testOps); ++testOpsIdx)
11139 const deUint32 itemsPerVec = 2;
11140 const size_t iterations = float16DataVec1.size() / itemsPerVec;
11141 const TestOp& testOp = testOps[testOpsIdx];
11142 const string testName = de::toLower(string(testOp.opCode)) + "_vector";
11143 SpecResource specResource;
11144 map<string, string> specs;
11145 vector<string> extensions;
11146 VulkanFeatures features;
11147 map<string, string> fragments;
11149 specs["num_data_points"] = de::toString(iterations);
11150 specs["op_code"] = testOp.opCode;
11151 specs["op_arg1"] = (testOp.argCount == 1) ? "" : "%val_src1";
11152 specs["op_arg1_calc"] = (testOp.argCount == 1) ? "" : arg1Calc.specialize(specs);
11154 fragments["extension"] = spvExtensions;
11155 fragments["capability"] = spvCapabilities;
11156 fragments["execution_mode"] = spvExecutionMode;
11157 fragments["decoration"] = decoration.specialize(specs);
11158 fragments["pre_main"] = preMain.specialize(specs);
11159 fragments["testfun"] = testFun.specialize(specs);
11160 fragments["testfun"] += StringTemplate(loadV2F16FromUint).specialize({{"var", "ssbo_src0"}});
11161 if (testOp.argCount > 1)
11163 fragments["testfun"] += StringTemplate(loadV2F16FromUint).specialize({{"var", "ssbo_src1"}});
11165 fragments["testfun"] += StringTemplate(storeV2F16AsUint).specialize({{"var", "ssbo_dst"}});
11167 specResource.inputs.push_back(Resource(BufferSp(new Float16Buffer(float16DataVec1)), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
11168 specResource.inputs.push_back(Resource(BufferSp(new Float16Buffer(float16DataVec2)), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
11169 specResource.outputs.push_back(Resource(BufferSp(new Float16Buffer(float16OutVecDummy)), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
11170 specResource.verifyIO = nanSupported ? testOp.verifyFuncNan : testOp.verifyFuncNonNan;
11172 extensions.push_back("VK_KHR_shader_float16_int8");
11176 extensions.push_back("VK_KHR_shader_float_controls");
11178 features.floatControlsProperties.shaderSignedZeroInfNanPreserveFloat16 = DE_TRUE;
11181 features.extFloat16Int8 = EXTFLOAT16INT8FEATURES_FLOAT16;
11183 finalizeTestsCreation(specResource, fragments, testCtx, *testGroup.get(), testName, features, extensions, IVec3(1, 1, 1));
11187 return testGroup.release();
11190 bool compareFP16FunctionSetFunc (const std::vector<Resource>& inputs, const vector<AllocationSp>& outputAllocs, const std::vector<Resource>&, TestLog& log)
11192 if (inputs.size() != 1 || outputAllocs.size() != 1)
11195 vector<deUint8> input1Bytes;
11197 inputs[0].getBytes(input1Bytes);
11199 const deUint16* const input1AsFP16 = (const deUint16*)&input1Bytes[0];
11200 const deUint16* const outputAsFP16 = (const deUint16*)outputAllocs[0]->getHostPtr();
11203 for (size_t idx = 0; idx < input1Bytes.size() / sizeof(deUint16); ++idx)
11205 if (!compare16BitFloat(input1AsFP16[idx], outputAsFP16[idx], error))
11207 log << TestLog::Message << error << TestLog::EndMessage;
11216 template<class SpecResource>
11217 tcu::TestCaseGroup* createFloat16FuncSet (tcu::TestContext& testCtx)
11219 de::MovePtr<tcu::TestCaseGroup> testGroup (new tcu::TestCaseGroup(testCtx, "function", "Float 16 function call related tests"));
11221 de::Random rnd (deStringHash(testGroup->getName()));
11222 const StringTemplate capabilities ("OpCapability Float16\n");
11223 const deUint32 numDataPoints = 256;
11224 const vector<deFloat16> float16InputData = getFloat16s(rnd, numDataPoints);
11225 const vector<deFloat16> float16OutputDummy (float16InputData.size(), 0);
11226 map<string, string> fragments;
11230 const deUint32 typeComponents;
11231 const char* typeName;
11232 const char* typeDecls;
11233 const char* typeStorage;
11234 const string loadFunc;
11235 const string storeFunc;
11238 const TestType testTypes[] =
11243 " %v2f16 = OpTypeVector %f16 2\n"
11244 "%f16_i32_fn = OpTypeFunction %f16 %i32\n"
11245 "%void_f16_i32_fn = OpTypeFunction %void %f16 %i32\n"
11246 "%c_u32_high_ones = OpConstant %u32 0xffff0000\n"
11247 " %c_u32_low_ones = OpConstant %u32 0x0000ffff\n",
11249 loadScalarF16FromUint,
11250 storeScalarF16AsUint
11255 " %v2f16 = OpTypeVector %f16 2\n"
11256 " %c_v2f16_0 = OpConstantComposite %v2f16 %c_f16_0 %c_f16_0\n"
11257 "%v2f16_i32_fn = OpTypeFunction %v2f16 %i32\n"
11258 "%void_v2f16_i32_fn = OpTypeFunction %void %v2f16 %i32\n",
11266 " %v2f16 = OpTypeVector %f16 2\n"
11267 " %v4f16 = OpTypeVector %f16 4\n"
11268 " %c_v4f16_0 = OpConstantComposite %v4f16 %c_f16_0 %c_f16_0 %c_f16_0 %c_f16_0\n"
11269 "%v4f16_i32_fn = OpTypeFunction %v4f16 %i32\n"
11270 "%void_v4f16_i32_fn = OpTypeFunction %void %v4f16 %i32\n",
11272 loadV4F16FromUints,
11277 const StringTemplate preMain
11279 " %c_i32_ndp = OpConstant %i32 ${num_data_points}\n"
11280 " %c_i32_hndp = OpSpecConstantOp %i32 SDiv %c_i32_ndp %c_i32_2\n"
11281 " %v2bool = OpTypeVector %bool 2\n"
11282 " %f16 = OpTypeFloat 16\n"
11283 " %c_f16_0 = OpConstant %f16 0.0\n"
11287 " %${tt}_fun = OpTypeFunction %${tt} %${tt}\n"
11288 " %ra_u32_2 = OpTypeArray %u32 %c_u32_2\n"
11289 "%ra_u32_hndp = OpTypeArray %u32 %c_i32_hndp\n"
11290 " %ra_u32_ndp = OpTypeArray %u32 %c_i32_ndp\n"
11291 "%ra_ra_u32_2 = OpTypeArray %ra_u32_2 %c_i32_ndp\n"
11292 " %up_u32 = OpTypePointer Uniform %u32\n"
11293 " %SSBO16 = OpTypeStruct %ra_${ts}\n"
11294 " %up_SSBO16 = OpTypePointer Uniform %SSBO16\n"
11295 " %ssbo_src = OpVariable %up_SSBO16 Uniform\n"
11296 " %ssbo_dst = OpVariable %up_SSBO16 Uniform\n"
11299 const StringTemplate decoration
11301 "OpDecorate %ra_u32_2 ArrayStride 4\n"
11302 "OpDecorate %ra_u32_hndp ArrayStride 4\n"
11303 "OpDecorate %ra_u32_ndp ArrayStride 4\n"
11304 "OpDecorate %ra_ra_u32_2 ArrayStride 8\n"
11305 "OpMemberDecorate %SSBO16 0 Offset 0\n"
11306 "OpDecorate %SSBO16 BufferBlock\n"
11307 "OpDecorate %ssbo_src DescriptorSet 0\n"
11308 "OpDecorate %ssbo_src Binding 0\n"
11309 "OpDecorate %ssbo_dst DescriptorSet 0\n"
11310 "OpDecorate %ssbo_dst Binding 1\n"
11313 const StringTemplate testFun
11315 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
11316 " %param = OpFunctionParameter %v4f32\n"
11317 " %entry = OpLabel\n"
11319 " %i = OpVariable %fp_i32 Function\n"
11320 " OpStore %i %c_i32_0\n"
11321 " OpBranch %loop\n"
11323 " %loop = OpLabel\n"
11324 " %i_cmp = OpLoad %i32 %i\n"
11325 " %lt = OpSLessThan %bool %i_cmp %c_i32_ndp\n"
11326 " OpLoopMerge %merge %next None\n"
11327 " OpBranchConditional %lt %write %merge\n"
11329 " %write = OpLabel\n"
11330 " %ndx = OpLoad %i32 %i\n"
11332 " %val_src = OpFunctionCall %${tt} %ld_arg_ssbo_src %ndx\n"
11333 " %val_dst = OpFunctionCall %${tt} %pass_fun %val_src\n"
11334 " %dst = OpFunctionCall %void %st_fn_ssbo_dst %val_dst %ndx\n"
11335 " OpBranch %next\n"
11337 " %next = OpLabel\n"
11338 " %i_cur = OpLoad %i32 %i\n"
11339 " %i_new = OpIAdd %i32 %i_cur %c_i32_1\n"
11340 " OpStore %i %i_new\n"
11341 " OpBranch %loop\n"
11343 " %merge = OpLabel\n"
11344 " OpReturnValue %param\n"
11348 " %pass_fun = OpFunction %${tt} None %${tt}_fun\n"
11349 " %param0 = OpFunctionParameter %${tt}\n"
11350 " %entry_pf = OpLabel\n"
11351 " %res0 = OpFAdd %${tt} %param0 %c_${tt}_0\n"
11352 " OpReturnValue %res0\n"
11356 for (deUint32 testTypeIdx = 0; testTypeIdx < DE_LENGTH_OF_ARRAY(testTypes); ++testTypeIdx)
11358 const TestType& testType = testTypes[testTypeIdx];
11359 const string testName = testType.typeName;
11360 const deUint32 itemsPerType = testType.typeComponents;
11361 const size_t iterations = float16InputData.size() / itemsPerType;
11362 const size_t typeStride = itemsPerType * sizeof(deFloat16);
11363 SpecResource specResource;
11364 map<string, string> specs;
11365 VulkanFeatures features;
11366 vector<string> extensions;
11368 specs["num_data_points"] = de::toString(iterations);
11369 specs["tt"] = testType.typeName;
11370 specs["ts"] = testType.typeStorage;
11371 specs["tt_stride"] = de::toString(typeStride);
11372 specs["type_decls"] = testType.typeDecls;
11374 fragments["capability"] = capabilities.specialize(specs);
11375 fragments["decoration"] = decoration.specialize(specs);
11376 fragments["pre_main"] = preMain.specialize(specs);
11377 fragments["testfun"] = testFun.specialize(specs);
11378 fragments["testfun"] += StringTemplate(testType.loadFunc).specialize({{"var", "ssbo_src"}});
11379 fragments["testfun"] += StringTemplate(testType.storeFunc).specialize({{"var", "ssbo_dst"}});
11381 specResource.inputs.push_back(Resource(BufferSp(new Float16Buffer(float16InputData)), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
11382 specResource.outputs.push_back(Resource(BufferSp(new Float16Buffer(float16OutputDummy)), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
11383 specResource.verifyIO = compareFP16FunctionSetFunc;
11385 extensions.push_back("VK_KHR_shader_float16_int8");
11387 features.extFloat16Int8 = EXTFLOAT16INT8FEATURES_FLOAT16;
11389 finalizeTestsCreation(specResource, fragments, testCtx, *testGroup.get(), testName, features, extensions, IVec3(1, 1, 1));
11392 return testGroup.release();
11395 bool compareFP16VectorExtractFunc (const std::vector<Resource>& inputs, const vector<AllocationSp>& outputAllocs, const std::vector<Resource>&, TestLog& log)
11397 if (inputs.size() != 2 || outputAllocs.size() != 1)
11400 vector<deUint8> input1Bytes;
11401 vector<deUint8> input2Bytes;
11403 inputs[0].getBytes(input1Bytes);
11404 inputs[1].getBytes(input2Bytes);
11406 DE_ASSERT(input1Bytes.size() > 0);
11407 DE_ASSERT(input2Bytes.size() > 0);
11408 DE_ASSERT(input2Bytes.size() % sizeof(deUint32) == 0);
11410 const size_t iterations = input2Bytes.size() / sizeof(deUint32);
11411 const size_t components = input1Bytes.size() / (sizeof(deFloat16) * iterations);
11412 const deFloat16* const input1AsFP16 = (const deFloat16*)&input1Bytes[0];
11413 const deUint32* const inputIndices = (const deUint32*)&input2Bytes[0];
11414 const deFloat16* const outputAsFP16 = (const deFloat16*)outputAllocs[0]->getHostPtr();
11417 DE_ASSERT(components == 2 || components == 4);
11418 DE_ASSERT(input1Bytes.size() == iterations * components * sizeof(deFloat16));
11420 for (size_t idx = 0; idx < iterations; ++idx)
11422 const deUint32 componentNdx = inputIndices[idx];
11424 DE_ASSERT(componentNdx < components);
11426 const deFloat16 expected = input1AsFP16[components * idx + componentNdx];
11428 if (!compare16BitFloat(expected, outputAsFP16[idx], error))
11430 log << TestLog::Message << "At " << idx << error << TestLog::EndMessage;
11439 template<class SpecResource>
11440 tcu::TestCaseGroup* createFloat16VectorExtractSet (tcu::TestContext& testCtx)
11442 de::MovePtr<tcu::TestCaseGroup> testGroup (new tcu::TestCaseGroup(testCtx, "opvectorextractdynamic", "OpVectorExtractDynamic tests"));
11444 de::Random rnd (deStringHash(testGroup->getName()));
11445 const deUint32 numDataPoints = 256;
11446 const vector<deFloat16> float16InputData = getFloat16s(rnd, numDataPoints);
11447 const vector<deFloat16> float16OutputDummy (float16InputData.size(), 0);
11451 const deUint32 typeComponents;
11452 const size_t typeStride;
11453 const char* typeName;
11454 const char* typeDecls;
11455 const char* typeStorage;
11456 const string loadFunction;
11457 const string storeFunction;
11460 const TestType testTypes[] =
11464 2 * sizeof(deFloat16),
11466 " %v2f16 = OpTypeVector %f16 2\n"
11467 "%v2f16_i32_fn = OpTypeFunction %v2f16 %i32\n"
11468 "%void_f16_i32_fn = OpTypeFunction %void %f16 %i32\n"
11469 "%c_u32_high_ones = OpConstant %u32 0xffff0000\n"
11470 " %c_u32_low_ones = OpConstant %u32 0x0000ffff\n",
11473 storeScalarF16AsUint
11477 4 * sizeof(deFloat16),
11479 " %v2f16 = OpTypeVector %f16 2\n"
11480 " %v3f16 = OpTypeVector %f16 3\n"
11481 "%v3f16_i32_fn = OpTypeFunction %v3f16 %i32\n"
11482 "%void_f16_i32_fn = OpTypeFunction %void %f16 %i32\n"
11483 "%c_u32_high_ones = OpConstant %u32 0xffff0000\n"
11484 " %c_u32_low_ones = OpConstant %u32 0x0000ffff\n",
11486 loadV3F16FromUints,
11487 storeScalarF16AsUint
11491 4 * sizeof(deFloat16),
11493 " %v2f16 = OpTypeVector %f16 2\n"
11494 " %v4f16 = OpTypeVector %f16 4\n"
11495 "%v4f16_i32_fn = OpTypeFunction %v4f16 %i32\n"
11496 "%void_f16_i32_fn = OpTypeFunction %void %f16 %i32\n"
11497 "%c_u32_high_ones = OpConstant %u32 0xffff0000\n"
11498 " %c_u32_low_ones = OpConstant %u32 0x0000ffff\n",
11500 loadV4F16FromUints,
11501 storeScalarF16AsUint
11505 const StringTemplate preMain
11507 " %c_i32_ndp = OpConstant %i32 ${num_data_points}\n"
11508 " %c_i32_hndp = OpSpecConstantOp %i32 SDiv %c_i32_ndp %c_i32_2\n"
11509 " %f16 = OpTypeFloat 16\n"
11513 " %up_u32 = OpTypePointer Uniform %u32\n"
11514 " %ra_u32 = OpTypeArray %u32 %c_i32_ndp\n"
11515 " %SSBO_IDX = OpTypeStruct %ra_u32\n"
11516 "%up_SSBO_IDX = OpTypePointer Uniform %SSBO_IDX\n"
11518 " %ra_u32_2 = OpTypeArray %u32 %c_u32_2\n"
11519 " %ra_u32_ndp = OpTypeArray %u32 %c_i32_ndp\n"
11520 "%ra_ra_u32_2 = OpTypeArray %ra_u32_2 %c_i32_ndp\n"
11521 " %SSBO_SRC = OpTypeStruct %ra_${ts}\n"
11522 "%up_SSBO_SRC = OpTypePointer Uniform %SSBO_SRC\n"
11524 " %ra_u32_hndp = OpTypeArray %u32 %c_i32_hndp\n"
11525 " %SSBO_DST = OpTypeStruct %ra_u32_hndp\n"
11526 "%up_SSBO_DST = OpTypePointer Uniform %SSBO_DST\n"
11528 " %ssbo_src = OpVariable %up_SSBO_SRC Uniform\n"
11529 " %ssbo_idx = OpVariable %up_SSBO_IDX Uniform\n"
11530 " %ssbo_dst = OpVariable %up_SSBO_DST Uniform\n"
11533 const StringTemplate decoration
11535 "OpDecorate %ra_u32_2 ArrayStride 4\n"
11536 "OpDecorate %ra_u32_hndp ArrayStride 4\n"
11537 "OpDecorate %ra_ra_u32_2 ArrayStride 8\n"
11538 "OpMemberDecorate %SSBO_SRC 0 Offset 0\n"
11539 "OpDecorate %SSBO_SRC BufferBlock\n"
11540 "OpDecorate %ssbo_src DescriptorSet 0\n"
11541 "OpDecorate %ssbo_src Binding 0\n"
11543 "OpDecorate %ra_u32 ArrayStride 4\n"
11544 "OpMemberDecorate %SSBO_IDX 0 Offset 0\n"
11545 "OpDecorate %SSBO_IDX BufferBlock\n"
11546 "OpDecorate %ssbo_idx DescriptorSet 0\n"
11547 "OpDecorate %ssbo_idx Binding 1\n"
11549 "OpMemberDecorate %SSBO_DST 0 Offset 0\n"
11550 "OpDecorate %SSBO_DST BufferBlock\n"
11551 "OpDecorate %ssbo_dst DescriptorSet 0\n"
11552 "OpDecorate %ssbo_dst Binding 2\n"
11555 const StringTemplate testFun
11557 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
11558 " %param = OpFunctionParameter %v4f32\n"
11559 " %entry = OpLabel\n"
11561 " %i = OpVariable %fp_i32 Function\n"
11562 " OpStore %i %c_i32_0\n"
11564 " %will_run = OpFunctionCall %bool %isUniqueIdZero\n"
11565 " OpSelectionMerge %end_if None\n"
11566 " OpBranchConditional %will_run %run_test %end_if\n"
11568 " %run_test = OpLabel\n"
11569 " OpBranch %loop\n"
11571 " %loop = OpLabel\n"
11572 " %i_cmp = OpLoad %i32 %i\n"
11573 " %lt = OpSLessThan %bool %i_cmp %c_i32_ndp\n"
11574 " OpLoopMerge %merge %next None\n"
11575 " OpBranchConditional %lt %write %merge\n"
11577 " %write = OpLabel\n"
11578 " %ndx = OpLoad %i32 %i\n"
11580 " %val_src = OpFunctionCall %${tt} %ld_arg_ssbo_src %ndx\n"
11582 " %src_idx = OpAccessChain %up_u32 %ssbo_idx %c_i32_0 %ndx\n"
11583 " %val_idx = OpLoad %u32 %src_idx\n"
11585 " %val_dst = OpVectorExtractDynamic %f16 %val_src %val_idx\n"
11586 " %dst = OpFunctionCall %void %st_fn_ssbo_dst %val_dst %ndx\n"
11588 " OpBranch %next\n"
11590 " %next = OpLabel\n"
11591 " %i_cur = OpLoad %i32 %i\n"
11592 " %i_new = OpIAdd %i32 %i_cur %c_i32_1\n"
11593 " OpStore %i %i_new\n"
11594 " OpBranch %loop\n"
11596 " %merge = OpLabel\n"
11597 " OpBranch %end_if\n"
11598 " %end_if = OpLabel\n"
11599 " OpReturnValue %param\n"
11604 for (deUint32 testTypeIdx = 0; testTypeIdx < DE_LENGTH_OF_ARRAY(testTypes); ++testTypeIdx)
11606 const TestType& testType = testTypes[testTypeIdx];
11607 const string testName = testType.typeName;
11608 const size_t itemsPerType = testType.typeStride / sizeof(deFloat16);
11609 const size_t iterations = float16InputData.size() / itemsPerType;
11610 SpecResource specResource;
11611 map<string, string> specs;
11612 VulkanFeatures features;
11613 vector<deUint32> inputDataNdx;
11614 map<string, string> fragments;
11615 vector<string> extensions;
11617 for (deUint32 ndx = 0; ndx < iterations; ++ndx)
11618 inputDataNdx.push_back(rnd.getUint32() % testType.typeComponents);
11620 specs["num_data_points"] = de::toString(iterations);
11621 specs["tt"] = testType.typeName;
11622 specs["ts"] = testType.typeStorage;
11623 specs["tt_stride"] = de::toString(testType.typeStride);
11624 specs["type_decl"] = testType.typeDecls;
11626 fragments["capability"] = "OpCapability Float16\n";
11627 fragments["decoration"] = decoration.specialize(specs);
11628 fragments["pre_main"] = preMain.specialize(specs);
11629 fragments["testfun"] = testFun.specialize(specs);
11630 fragments["testfun"] += StringTemplate(testType.loadFunction).specialize({{"var", "ssbo_src"}});
11631 fragments["testfun"] += StringTemplate(testType.storeFunction).specialize({{"var", "ssbo_dst"}});
11633 specResource.inputs.push_back(Resource(BufferSp(new Float16Buffer(float16InputData)), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
11634 specResource.inputs.push_back(Resource(BufferSp(new Uint32Buffer(inputDataNdx)), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
11635 specResource.outputs.push_back(Resource(BufferSp(new Float16Buffer(float16OutputDummy)), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
11636 specResource.verifyIO = compareFP16VectorExtractFunc;
11638 extensions.push_back("VK_KHR_shader_float16_int8");
11640 features.extFloat16Int8 = EXTFLOAT16INT8FEATURES_FLOAT16;
11642 finalizeTestsCreation(specResource, fragments, testCtx, *testGroup.get(), testName, features, extensions, IVec3(1, 1, 1));
11645 return testGroup.release();
11648 template<deUint32 COMPONENTS_COUNT, deUint32 REPLACEMENT>
11649 bool compareFP16VectorInsertFunc (const std::vector<Resource>& inputs, const vector<AllocationSp>& outputAllocs, const std::vector<Resource>&, TestLog& log)
11651 if (inputs.size() != 2 || outputAllocs.size() != 1)
11654 vector<deUint8> input1Bytes;
11655 vector<deUint8> input2Bytes;
11657 inputs[0].getBytes(input1Bytes);
11658 inputs[1].getBytes(input2Bytes);
11660 DE_ASSERT(input1Bytes.size() > 0);
11661 DE_ASSERT(input2Bytes.size() > 0);
11662 DE_ASSERT(input2Bytes.size() % sizeof(deUint32) == 0);
11664 const size_t iterations = input2Bytes.size() / sizeof(deUint32);
11665 const size_t componentsStride = input1Bytes.size() / (sizeof(deFloat16) * iterations);
11666 const deFloat16* const input1AsFP16 = (const deFloat16*)&input1Bytes[0];
11667 const deUint32* const inputIndices = (const deUint32*)&input2Bytes[0];
11668 const deFloat16* const outputAsFP16 = (const deFloat16*)outputAllocs[0]->getHostPtr();
11669 const deFloat16 magic = tcu::Float16(float(REPLACEMENT)).bits();
11672 DE_ASSERT(componentsStride == 2 || componentsStride == 4);
11673 DE_ASSERT(input1Bytes.size() == iterations * componentsStride * sizeof(deFloat16));
11675 for (size_t idx = 0; idx < iterations; ++idx)
11677 const deFloat16* inputVec = &input1AsFP16[componentsStride * idx];
11678 const deFloat16* outputVec = &outputAsFP16[componentsStride * idx];
11679 const deUint32 replacedCompNdx = inputIndices[idx];
11681 DE_ASSERT(replacedCompNdx < COMPONENTS_COUNT);
11683 for (size_t compNdx = 0; compNdx < COMPONENTS_COUNT; ++compNdx)
11685 const deFloat16 expected = (compNdx == replacedCompNdx) ? magic : inputVec[compNdx];
11687 if (!compare16BitFloat(expected, outputVec[compNdx], error))
11689 log << TestLog::Message << "At " << idx << "[" << compNdx << "]: " << error << TestLog::EndMessage;
11699 template<class SpecResource>
11700 tcu::TestCaseGroup* createFloat16VectorInsertSet (tcu::TestContext& testCtx)
11702 de::MovePtr<tcu::TestCaseGroup> testGroup (new tcu::TestCaseGroup(testCtx, "opvectorinsertdynamic", "OpVectorInsertDynamic tests"));
11704 de::Random rnd (deStringHash(testGroup->getName()));
11705 const deUint32 replacement = 42;
11706 const deUint32 numDataPoints = 256;
11707 const vector<deFloat16> float16InputData = getFloat16s(rnd, numDataPoints);
11708 const vector<deFloat16> float16OutputDummy (float16InputData.size(), 0);
11712 const deUint32 typeComponents;
11713 const size_t typeStride;
11714 const char* typeName;
11715 const char* typeDecls;
11716 VerifyIOFunc verifyIOFunc;
11717 const char* typeStorage;
11718 const string loadFunction;
11719 const string storeFunction;
11722 const TestType testTypes[] =
11726 2 * sizeof(deFloat16),
11728 " %v2f16 = OpTypeVector %f16 2\n"
11729 "%v2f16_i32_fn = OpTypeFunction %v2f16 %i32\n"
11730 "%void_v2f16_i32_fn = OpTypeFunction %void %v2f16 %i32\n",
11731 compareFP16VectorInsertFunc<2, replacement>,
11738 4 * sizeof(deFloat16),
11740 " %v2f16 = OpTypeVector %f16 2\n"
11741 " %v3f16 = OpTypeVector %f16 3\n"
11742 "%v3f16_i32_fn = OpTypeFunction %v3f16 %i32\n"
11743 "%void_v3f16_i32_fn = OpTypeFunction %void %v3f16 %i32\n",
11744 compareFP16VectorInsertFunc<3, replacement>,
11746 loadV3F16FromUints,
11751 4 * sizeof(deFloat16),
11753 " %v2f16 = OpTypeVector %f16 2\n"
11754 " %v4f16 = OpTypeVector %f16 4\n"
11755 "%v4f16_i32_fn = OpTypeFunction %v4f16 %i32\n"
11756 "%void_v4f16_i32_fn = OpTypeFunction %void %v4f16 %i32\n",
11757 compareFP16VectorInsertFunc<4, replacement>,
11759 loadV4F16FromUints,
11764 const StringTemplate preMain
11766 " %c_i32_ndp = OpConstant %i32 ${num_data_points}\n"
11767 " %f16 = OpTypeFloat 16\n"
11768 " %c_f16_ins = OpConstant %f16 ${replacement}\n"
11772 " %ra_u32 = OpTypeArray %u32 %c_i32_ndp\n"
11773 " %up_u32 = OpTypePointer Uniform %u32\n"
11774 " %SSBO_IDX = OpTypeStruct %ra_u32\n"
11775 "%up_SSBO_IDX = OpTypePointer Uniform %SSBO_IDX\n"
11777 " %ra_u32_2 = OpTypeArray %u32 %c_u32_2\n"
11778 "%ra_ra_u32_2 = OpTypeArray %ra_u32_2 %c_i32_ndp\n"
11779 " %SSBO_SRC = OpTypeStruct %ra_${ts}\n"
11780 "%up_SSBO_SRC = OpTypePointer Uniform %SSBO_SRC\n"
11782 " %SSBO_DST = OpTypeStruct %ra_${ts}\n"
11783 "%up_SSBO_DST = OpTypePointer Uniform %SSBO_DST\n"
11785 " %ssbo_src = OpVariable %up_SSBO_SRC Uniform\n"
11786 " %ssbo_idx = OpVariable %up_SSBO_IDX Uniform\n"
11787 " %ssbo_dst = OpVariable %up_SSBO_DST Uniform\n"
11790 const StringTemplate decoration
11792 "OpDecorate %ra_u32_2 ArrayStride 4\n"
11793 "OpDecorate %ra_ra_u32_2 ArrayStride 8\n"
11794 "OpMemberDecorate %SSBO_SRC 0 Offset 0\n"
11795 "OpDecorate %SSBO_SRC BufferBlock\n"
11796 "OpDecorate %ssbo_src DescriptorSet 0\n"
11797 "OpDecorate %ssbo_src Binding 0\n"
11799 "OpDecorate %ra_u32 ArrayStride 4\n"
11800 "OpMemberDecorate %SSBO_IDX 0 Offset 0\n"
11801 "OpDecorate %SSBO_IDX BufferBlock\n"
11802 "OpDecorate %ssbo_idx DescriptorSet 0\n"
11803 "OpDecorate %ssbo_idx Binding 1\n"
11805 "OpMemberDecorate %SSBO_DST 0 Offset 0\n"
11806 "OpDecorate %SSBO_DST BufferBlock\n"
11807 "OpDecorate %ssbo_dst DescriptorSet 0\n"
11808 "OpDecorate %ssbo_dst Binding 2\n"
11811 const StringTemplate testFun
11813 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
11814 " %param = OpFunctionParameter %v4f32\n"
11815 " %entry = OpLabel\n"
11817 " %i = OpVariable %fp_i32 Function\n"
11818 " OpStore %i %c_i32_0\n"
11820 " %will_run = OpFunctionCall %bool %isUniqueIdZero\n"
11821 " OpSelectionMerge %end_if None\n"
11822 " OpBranchConditional %will_run %run_test %end_if\n"
11824 " %run_test = OpLabel\n"
11825 " OpBranch %loop\n"
11827 " %loop = OpLabel\n"
11828 " %i_cmp = OpLoad %i32 %i\n"
11829 " %lt = OpSLessThan %bool %i_cmp %c_i32_ndp\n"
11830 " OpLoopMerge %merge %next None\n"
11831 " OpBranchConditional %lt %write %merge\n"
11833 " %write = OpLabel\n"
11834 " %ndx = OpLoad %i32 %i\n"
11836 " %val_src = OpFunctionCall %${tt} %ld_arg_ssbo_src %ndx\n"
11838 " %src_idx = OpAccessChain %up_u32 %ssbo_idx %c_i32_0 %ndx\n"
11839 " %val_idx = OpLoad %u32 %src_idx\n"
11841 " %val_dst = OpVectorInsertDynamic %${tt} %val_src %c_f16_ins %val_idx\n"
11842 " %dst = OpFunctionCall %void %st_fn_ssbo_dst %val_dst %ndx\n"
11844 " OpBranch %next\n"
11846 " %next = OpLabel\n"
11847 " %i_cur = OpLoad %i32 %i\n"
11848 " %i_new = OpIAdd %i32 %i_cur %c_i32_1\n"
11849 " OpStore %i %i_new\n"
11850 " OpBranch %loop\n"
11852 " %merge = OpLabel\n"
11853 " OpBranch %end_if\n"
11854 " %end_if = OpLabel\n"
11855 " OpReturnValue %param\n"
11860 for (deUint32 testTypeIdx = 0; testTypeIdx < DE_LENGTH_OF_ARRAY(testTypes); ++testTypeIdx)
11862 const TestType& testType = testTypes[testTypeIdx];
11863 const string testName = testType.typeName;
11864 const size_t itemsPerType = testType.typeStride / sizeof(deFloat16);
11865 const size_t iterations = float16InputData.size() / itemsPerType;
11866 SpecResource specResource;
11867 map<string, string> specs;
11868 VulkanFeatures features;
11869 vector<deUint32> inputDataNdx;
11870 map<string, string> fragments;
11871 vector<string> extensions;
11873 for (deUint32 ndx = 0; ndx < iterations; ++ndx)
11874 inputDataNdx.push_back(rnd.getUint32() % testType.typeComponents);
11876 specs["num_data_points"] = de::toString(iterations);
11877 specs["tt"] = testType.typeName;
11878 specs["ts"] = testType.typeStorage;
11879 specs["tt_stride"] = de::toString(testType.typeStride);
11880 specs["type_decl"] = testType.typeDecls;
11881 specs["replacement"] = de::toString(replacement);
11883 fragments["capability"] = "OpCapability Float16\n";
11884 fragments["decoration"] = decoration.specialize(specs);
11885 fragments["pre_main"] = preMain.specialize(specs);
11886 fragments["testfun"] = testFun.specialize(specs);
11887 fragments["testfun"] += StringTemplate(testType.loadFunction).specialize({{"var", "ssbo_src"}});
11888 fragments["testfun"] += StringTemplate(testType.storeFunction).specialize({{"var", "ssbo_dst"}});
11890 specResource.inputs.push_back(Resource(BufferSp(new Float16Buffer(float16InputData)), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
11891 specResource.inputs.push_back(Resource(BufferSp(new Uint32Buffer(inputDataNdx)), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
11892 specResource.outputs.push_back(Resource(BufferSp(new Float16Buffer(float16OutputDummy)), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
11893 specResource.verifyIO = testType.verifyIOFunc;
11895 extensions.push_back("VK_KHR_shader_float16_int8");
11897 features.extFloat16Int8 = EXTFLOAT16INT8FEATURES_FLOAT16;
11899 finalizeTestsCreation(specResource, fragments, testCtx, *testGroup.get(), testName, features, extensions, IVec3(1, 1, 1));
11902 return testGroup.release();
11905 inline deFloat16 getShuffledComponent (const size_t iteration, const size_t componentNdx, const deFloat16* input1Vec, const deFloat16* input2Vec, size_t vec1Len, size_t vec2Len, bool& validate)
11907 const size_t compNdxCount = (vec1Len + vec2Len + 1);
11908 const size_t compNdxLimited = iteration % (compNdxCount * compNdxCount);
11911 switch (componentNdx)
11913 case 0: comp = compNdxLimited / compNdxCount; break;
11914 case 1: comp = compNdxLimited % compNdxCount; break;
11915 case 2: comp = 0; break;
11916 case 3: comp = 1; break;
11917 default: TCU_THROW(InternalError, "Impossible");
11920 if (comp >= vec1Len + vec2Len)
11928 return (comp < vec1Len) ? input1Vec[comp] : input2Vec[comp - vec1Len];
11932 template<deUint32 DST_COMPONENTS_COUNT, deUint32 SRC0_COMPONENTS_COUNT, deUint32 SRC1_COMPONENTS_COUNT>
11933 bool compareFP16VectorShuffleFunc (const std::vector<Resource>& inputs, const vector<AllocationSp>& outputAllocs, const std::vector<Resource>&, TestLog& log)
11935 DE_STATIC_ASSERT(DST_COMPONENTS_COUNT == 2 || DST_COMPONENTS_COUNT == 3 || DST_COMPONENTS_COUNT == 4);
11936 DE_STATIC_ASSERT(SRC0_COMPONENTS_COUNT == 2 || SRC0_COMPONENTS_COUNT == 3 || SRC0_COMPONENTS_COUNT == 4);
11937 DE_STATIC_ASSERT(SRC1_COMPONENTS_COUNT == 2 || SRC1_COMPONENTS_COUNT == 3 || SRC1_COMPONENTS_COUNT == 4);
11939 if (inputs.size() != 2 || outputAllocs.size() != 1)
11942 vector<deUint8> input1Bytes;
11943 vector<deUint8> input2Bytes;
11945 inputs[0].getBytes(input1Bytes);
11946 inputs[1].getBytes(input2Bytes);
11948 DE_ASSERT(input1Bytes.size() > 0);
11949 DE_ASSERT(input2Bytes.size() > 0);
11950 DE_ASSERT(input2Bytes.size() % sizeof(deFloat16) == 0);
11952 const size_t componentsStrideDst = (DST_COMPONENTS_COUNT == 3) ? 4 : DST_COMPONENTS_COUNT;
11953 const size_t componentsStrideSrc0 = (SRC0_COMPONENTS_COUNT == 3) ? 4 : SRC0_COMPONENTS_COUNT;
11954 const size_t componentsStrideSrc1 = (SRC1_COMPONENTS_COUNT == 3) ? 4 : SRC1_COMPONENTS_COUNT;
11955 const size_t iterations = input1Bytes.size() / (componentsStrideSrc0 * sizeof(deFloat16));
11956 const deFloat16* const input1AsFP16 = (const deFloat16*)&input1Bytes[0];
11957 const deFloat16* const input2AsFP16 = (const deFloat16*)&input2Bytes[0];
11958 const deFloat16* const outputAsFP16 = (const deFloat16*)outputAllocs[0]->getHostPtr();
11961 DE_ASSERT(input1Bytes.size() == iterations * componentsStrideSrc0 * sizeof(deFloat16));
11962 DE_ASSERT(input2Bytes.size() == iterations * componentsStrideSrc1 * sizeof(deFloat16));
11964 for (size_t idx = 0; idx < iterations; ++idx)
11966 const deFloat16* input1Vec = &input1AsFP16[componentsStrideSrc0 * idx];
11967 const deFloat16* input2Vec = &input2AsFP16[componentsStrideSrc1 * idx];
11968 const deFloat16* outputVec = &outputAsFP16[componentsStrideDst * idx];
11970 for (size_t compNdx = 0; compNdx < DST_COMPONENTS_COUNT; ++compNdx)
11972 bool validate = true;
11973 deFloat16 expected = getShuffledComponent(idx, compNdx, input1Vec, input2Vec, SRC0_COMPONENTS_COUNT, SRC1_COMPONENTS_COUNT, validate);
11975 if (validate && !compare16BitFloat(expected, outputVec[compNdx], error))
11977 log << TestLog::Message << "At " << idx << "[" << compNdx << "]: " << error << TestLog::EndMessage;
11987 VerifyIOFunc getFloat16VectorShuffleVerifyIOFunc (deUint32 dstComponentsCount, deUint32 src0ComponentsCount, deUint32 src1ComponentsCount)
11989 DE_ASSERT(dstComponentsCount <= 4);
11990 DE_ASSERT(src0ComponentsCount <= 4);
11991 DE_ASSERT(src1ComponentsCount <= 4);
11992 deUint32 funcCode = 100 * dstComponentsCount + 10 * src0ComponentsCount + src1ComponentsCount;
11996 case 222:return compareFP16VectorShuffleFunc<2, 2, 2>;
11997 case 223:return compareFP16VectorShuffleFunc<2, 2, 3>;
11998 case 224:return compareFP16VectorShuffleFunc<2, 2, 4>;
11999 case 232:return compareFP16VectorShuffleFunc<2, 3, 2>;
12000 case 233:return compareFP16VectorShuffleFunc<2, 3, 3>;
12001 case 234:return compareFP16VectorShuffleFunc<2, 3, 4>;
12002 case 242:return compareFP16VectorShuffleFunc<2, 4, 2>;
12003 case 243:return compareFP16VectorShuffleFunc<2, 4, 3>;
12004 case 244:return compareFP16VectorShuffleFunc<2, 4, 4>;
12005 case 322:return compareFP16VectorShuffleFunc<3, 2, 2>;
12006 case 323:return compareFP16VectorShuffleFunc<3, 2, 3>;
12007 case 324:return compareFP16VectorShuffleFunc<3, 2, 4>;
12008 case 332:return compareFP16VectorShuffleFunc<3, 3, 2>;
12009 case 333:return compareFP16VectorShuffleFunc<3, 3, 3>;
12010 case 334:return compareFP16VectorShuffleFunc<3, 3, 4>;
12011 case 342:return compareFP16VectorShuffleFunc<3, 4, 2>;
12012 case 343:return compareFP16VectorShuffleFunc<3, 4, 3>;
12013 case 344:return compareFP16VectorShuffleFunc<3, 4, 4>;
12014 case 422:return compareFP16VectorShuffleFunc<4, 2, 2>;
12015 case 423:return compareFP16VectorShuffleFunc<4, 2, 3>;
12016 case 424:return compareFP16VectorShuffleFunc<4, 2, 4>;
12017 case 432:return compareFP16VectorShuffleFunc<4, 3, 2>;
12018 case 433:return compareFP16VectorShuffleFunc<4, 3, 3>;
12019 case 434:return compareFP16VectorShuffleFunc<4, 3, 4>;
12020 case 442:return compareFP16VectorShuffleFunc<4, 4, 2>;
12021 case 443:return compareFP16VectorShuffleFunc<4, 4, 3>;
12022 case 444:return compareFP16VectorShuffleFunc<4, 4, 4>;
12023 default: TCU_THROW(InternalError, "Invalid number of components specified.");
12027 template<class SpecResource>
12028 tcu::TestCaseGroup* createFloat16VectorShuffleSet (tcu::TestContext& testCtx)
12030 de::MovePtr<tcu::TestCaseGroup> testGroup (new tcu::TestCaseGroup(testCtx, "opvectorshuffle", "OpVectorShuffle tests"));
12031 const int testSpecificSeed = deStringHash(testGroup->getName());
12032 const int seed = testCtx.getCommandLine().getBaseSeed() ^ testSpecificSeed;
12033 de::Random rnd (seed);
12034 const deUint32 numDataPoints = 128;
12035 map<string, string> fragments;
12039 const deUint32 typeComponents;
12040 const char* typeName;
12041 const string loadFunction;
12042 const string storeFunction;
12045 const TestType testTypes[] =
12056 loadV3F16FromUints,
12062 loadV4F16FromUints,
12067 const StringTemplate preMain
12069 " %c_i32_ndp = OpConstant %i32 ${num_data_points}\n"
12070 " %c_i32_cc = OpConstant %i32 ${case_count}\n"
12071 " %f16 = OpTypeFloat 16\n"
12072 " %v2f16 = OpTypeVector %f16 2\n"
12073 " %v3f16 = OpTypeVector %f16 3\n"
12074 " %v4f16 = OpTypeVector %f16 4\n"
12076 " %v2f16_i32_fn = OpTypeFunction %v2f16 %i32\n"
12077 " %v3f16_i32_fn = OpTypeFunction %v3f16 %i32\n"
12078 " %v4f16_i32_fn = OpTypeFunction %v4f16 %i32\n"
12079 "%void_v2f16_i32_fn = OpTypeFunction %void %v2f16 %i32\n"
12080 "%void_v3f16_i32_fn = OpTypeFunction %void %v3f16 %i32\n"
12081 "%void_v4f16_i32_fn = OpTypeFunction %void %v4f16 %i32\n"
12083 " %ra_u32_2 = OpTypeArray %u32 %c_u32_2\n"
12084 " %ra_u32_ndp = OpTypeArray %u32 %c_i32_ndp\n"
12085 " %ra_ra_u32_2 = OpTypeArray %ra_u32_2 %c_i32_ndp\n"
12086 " %up_u32 = OpTypePointer Uniform %u32\n"
12087 " %SSBO_v2f16 = OpTypeStruct %ra_u32_ndp\n"
12088 " %SSBO_v3f16 = OpTypeStruct %ra_ra_u32_2\n"
12089 " %SSBO_v4f16 = OpTypeStruct %ra_ra_u32_2\n"
12091 "%up_SSBO_v2f16 = OpTypePointer Uniform %SSBO_v2f16\n"
12092 "%up_SSBO_v3f16 = OpTypePointer Uniform %SSBO_v3f16\n"
12093 "%up_SSBO_v4f16 = OpTypePointer Uniform %SSBO_v4f16\n"
12095 " %fun_t = OpTypeFunction %${tt_dst} %${tt_src0} %${tt_src1} %i32\n"
12097 " %ssbo_src0 = OpVariable %up_SSBO_${tt_src0} Uniform\n"
12098 " %ssbo_src1 = OpVariable %up_SSBO_${tt_src1} Uniform\n"
12099 " %ssbo_dst = OpVariable %up_SSBO_${tt_dst} Uniform\n"
12102 const StringTemplate decoration
12104 "OpDecorate %ra_u32_2 ArrayStride 4\n"
12105 "OpDecorate %ra_u32_ndp ArrayStride 4\n"
12106 "OpDecorate %ra_ra_u32_2 ArrayStride 8\n"
12108 "OpMemberDecorate %SSBO_v2f16 0 Offset 0\n"
12109 "OpDecorate %SSBO_v2f16 BufferBlock\n"
12111 "OpMemberDecorate %SSBO_v3f16 0 Offset 0\n"
12112 "OpDecorate %SSBO_v3f16 BufferBlock\n"
12114 "OpMemberDecorate %SSBO_v4f16 0 Offset 0\n"
12115 "OpDecorate %SSBO_v4f16 BufferBlock\n"
12117 "OpDecorate %ssbo_src0 DescriptorSet 0\n"
12118 "OpDecorate %ssbo_src0 Binding 0\n"
12119 "OpDecorate %ssbo_src1 DescriptorSet 0\n"
12120 "OpDecorate %ssbo_src1 Binding 1\n"
12121 "OpDecorate %ssbo_dst DescriptorSet 0\n"
12122 "OpDecorate %ssbo_dst Binding 2\n"
12125 const StringTemplate testFun
12127 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
12128 " %param = OpFunctionParameter %v4f32\n"
12129 " %entry = OpLabel\n"
12131 " %i = OpVariable %fp_i32 Function\n"
12132 " OpStore %i %c_i32_0\n"
12134 " %will_run = OpFunctionCall %bool %isUniqueIdZero\n"
12135 " OpSelectionMerge %end_if None\n"
12136 " OpBranchConditional %will_run %run_test %end_if\n"
12138 " %run_test = OpLabel\n"
12139 " OpBranch %loop\n"
12141 " %loop = OpLabel\n"
12142 " %i_cmp = OpLoad %i32 %i\n"
12143 " %lt = OpSLessThan %bool %i_cmp %c_i32_ndp\n"
12144 " OpLoopMerge %merge %next None\n"
12145 " OpBranchConditional %lt %write %merge\n"
12147 " %write = OpLabel\n"
12148 " %ndx = OpLoad %i32 %i\n"
12149 " %val_src0 = OpFunctionCall %${tt_src0} %ld_arg_ssbo_src0 %ndx\n"
12150 " %val_src1 = OpFunctionCall %${tt_src1} %ld_arg_ssbo_src1 %ndx\n"
12151 " %val_dst = OpFunctionCall %${tt_dst} %sw_fun %val_src0 %val_src1 %ndx\n"
12152 " %dst = OpFunctionCall %void %st_fn_ssbo_dst %val_dst %ndx\n"
12153 " OpBranch %next\n"
12155 " %next = OpLabel\n"
12156 " %i_cur = OpLoad %i32 %i\n"
12157 " %i_new = OpIAdd %i32 %i_cur %c_i32_1\n"
12158 " OpStore %i %i_new\n"
12159 " OpBranch %loop\n"
12161 " %merge = OpLabel\n"
12162 " OpBranch %end_if\n"
12163 " %end_if = OpLabel\n"
12164 " OpReturnValue %param\n"
12168 " %sw_fun = OpFunction %${tt_dst} None %fun_t\n"
12169 "%sw_param0 = OpFunctionParameter %${tt_src0}\n"
12170 "%sw_param1 = OpFunctionParameter %${tt_src1}\n"
12171 "%sw_paramn = OpFunctionParameter %i32\n"
12172 " %sw_entry = OpLabel\n"
12173 " %modulo = OpSMod %i32 %sw_paramn %c_i32_cc\n"
12174 " OpSelectionMerge %switch_e None\n"
12175 " OpSwitch %modulo %default ${case_list}\n"
12177 "%default = OpLabel\n"
12178 " OpUnreachable\n" // Unreachable default case for switch statement
12179 "%switch_e = OpLabel\n"
12180 " OpUnreachable\n" // Unreachable merge block for switch statement
12184 const StringTemplate testCaseBody
12186 "%case_${case_ndx} = OpLabel\n"
12187 "%val_dst_${case_ndx} = OpVectorShuffle %${tt_dst} %sw_param0 %sw_param1 ${shuffle}\n"
12188 " OpReturnValue %val_dst_${case_ndx}\n"
12191 for (deUint32 dstTypeIdx = 0; dstTypeIdx < DE_LENGTH_OF_ARRAY(testTypes); ++dstTypeIdx)
12193 const TestType& dstType = testTypes[dstTypeIdx];
12195 for (deUint32 comp0Idx = 0; comp0Idx < DE_LENGTH_OF_ARRAY(testTypes); ++comp0Idx)
12197 const TestType& src0Type = testTypes[comp0Idx];
12199 for (deUint32 comp1Idx = 0; comp1Idx < DE_LENGTH_OF_ARRAY(testTypes); ++comp1Idx)
12201 const TestType& src1Type = testTypes[comp1Idx];
12202 const deUint32 input0Stride = (src0Type.typeComponents == 3) ? 4 : src0Type.typeComponents;
12203 const deUint32 input1Stride = (src1Type.typeComponents == 3) ? 4 : src1Type.typeComponents;
12204 const deUint32 outputStride = (dstType.typeComponents == 3) ? 4 : dstType.typeComponents;
12205 const vector<deFloat16> float16Input0Data = getFloat16s(rnd, input0Stride * numDataPoints);
12206 const vector<deFloat16> float16Input1Data = getFloat16s(rnd, input1Stride * numDataPoints);
12207 const vector<deFloat16> float16OutputDummy (outputStride * numDataPoints, 0);
12208 const string testName = de::toString(dstType.typeComponents) + de::toString(src0Type.typeComponents) + de::toString(src1Type.typeComponents);
12209 deUint32 caseCount = 0;
12210 SpecResource specResource;
12211 map<string, string> specs;
12212 vector<string> extensions;
12213 VulkanFeatures features;
12219 vector<string> componentList;
12221 // Generate component possible indices for OpVectorShuffle for components 0 and 1 in output vector
12223 deUint32 caseNo = 0;
12225 for (deUint32 comp0IdxLocal = 0; comp0IdxLocal < src0Type.typeComponents; ++comp0IdxLocal)
12226 componentList.push_back(de::toString(caseNo++));
12227 for (deUint32 comp1IdxLocal = 0; comp1IdxLocal < src1Type.typeComponents; ++comp1IdxLocal)
12228 componentList.push_back(de::toString(caseNo++));
12229 componentList.push_back("0xFFFFFFFF");
12232 for (deUint32 comp0IdxLocal = 0; comp0IdxLocal < componentList.size(); ++comp0IdxLocal)
12234 for (deUint32 comp1IdxLocal = 0; comp1IdxLocal < componentList.size(); ++comp1IdxLocal)
12236 map<string, string> specCase;
12237 string shuffle = componentList[comp0IdxLocal] + " " + componentList[comp1IdxLocal];
12239 for (deUint32 compIdx = 2; compIdx < dstType.typeComponents; ++compIdx)
12240 shuffle += " " + de::toString(compIdx - 2);
12242 specCase["case_ndx"] = de::toString(caseCount);
12243 specCase["shuffle"] = shuffle;
12244 specCase["tt_dst"] = dstType.typeName;
12246 caseBodies += testCaseBody.specialize(specCase);
12247 caseList += de::toString(caseCount) + " %case_" + de::toString(caseCount) + " ";
12254 specs["num_data_points"] = de::toString(numDataPoints);
12255 specs["tt_dst"] = dstType.typeName;
12256 specs["tt_src0"] = src0Type.typeName;
12257 specs["tt_src1"] = src1Type.typeName;
12258 specs["case_bodies"] = caseBodies;
12259 specs["case_list"] = caseList;
12260 specs["case_count"] = de::toString(caseCount);
12262 fragments["capability"] = "OpCapability Float16\n";
12263 fragments["decoration"] = decoration.specialize(specs);
12264 fragments["pre_main"] = preMain.specialize(specs);
12265 fragments["testfun"] = testFun.specialize(specs);
12266 fragments["testfun"] += StringTemplate(src0Type.loadFunction).specialize({{"var", "ssbo_src0"}});
12267 fragments["testfun"] += StringTemplate(src1Type.loadFunction).specialize({{"var", "ssbo_src1"}});
12268 fragments["testfun"] += StringTemplate(dstType.storeFunction).specialize({{"var", "ssbo_dst"}});
12270 specResource.inputs.push_back(Resource(BufferSp(new Float16Buffer(float16Input0Data)), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
12271 specResource.inputs.push_back(Resource(BufferSp(new Float16Buffer(float16Input1Data)), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
12272 specResource.outputs.push_back(Resource(BufferSp(new Float16Buffer(float16OutputDummy)), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
12273 specResource.verifyIO = getFloat16VectorShuffleVerifyIOFunc(dstType.typeComponents, src0Type.typeComponents, src1Type.typeComponents);
12275 extensions.push_back("VK_KHR_shader_float16_int8");
12277 features.extFloat16Int8 = EXTFLOAT16INT8FEATURES_FLOAT16;
12279 finalizeTestsCreation(specResource, fragments, testCtx, *testGroup.get(), testName, features, extensions, IVec3(1, 1, 1));
12284 return testGroup.release();
12287 bool compareFP16CompositeFunc (const std::vector<Resource>& inputs, const vector<AllocationSp>& outputAllocs, const std::vector<Resource>&, TestLog& log)
12289 if (inputs.size() != 1 || outputAllocs.size() != 1)
12292 vector<deUint8> input1Bytes;
12294 inputs[0].getBytes(input1Bytes);
12296 DE_ASSERT(input1Bytes.size() > 0);
12297 DE_ASSERT(input1Bytes.size() % sizeof(deFloat16) == 0);
12299 const size_t iterations = input1Bytes.size() / sizeof(deFloat16);
12300 const deFloat16* const input1AsFP16 = (const deFloat16*)&input1Bytes[0];
12301 const deFloat16* const outputAsFP16 = (const deFloat16*)outputAllocs[0]->getHostPtr();
12302 const deFloat16 exceptionValue = tcu::Float16(-1.0).bits();
12305 for (size_t idx = 0; idx < iterations; ++idx)
12307 if (input1AsFP16[idx] == exceptionValue)
12310 if (!compare16BitFloat(input1AsFP16[idx], outputAsFP16[idx], error))
12312 log << TestLog::Message << "At " << idx << ":" << error << TestLog::EndMessage;
12321 template<class SpecResource>
12322 tcu::TestCaseGroup* createFloat16CompositeConstructSet (tcu::TestContext& testCtx)
12324 de::MovePtr<tcu::TestCaseGroup> testGroup (new tcu::TestCaseGroup(testCtx, "opcompositeconstruct", "OpCompositeConstruct tests"));
12325 const deUint32 numElements = 8;
12326 const string testName = "struct";
12327 const deUint32 structItemsCount = 88;
12328 const deUint32 exceptionIndices[] = { 1, 7, 15, 17, 25, 33, 51, 55, 59, 63, 67, 71, 84, 85, 86, 87 };
12329 const deFloat16 exceptionValue = tcu::Float16(-1.0).bits();
12330 const deUint32 fieldModifier = 2;
12331 const deUint32 fieldModifiedMulIndex = 60;
12332 const deUint32 fieldModifiedAddIndex = 66;
12334 const StringTemplate preMain
12336 " %c_i32_ndp = OpConstant %i32 ${num_elements}\n"
12337 " %f16 = OpTypeFloat 16\n"
12338 " %v2f16 = OpTypeVector %f16 2\n"
12339 " %v3f16 = OpTypeVector %f16 3\n"
12340 " %v4f16 = OpTypeVector %f16 4\n"
12341 " %c_f16_mod = OpConstant %f16 ${field_modifier}\n"
12345 " %c_f16_n1 = OpConstant %f16 -1.0\n"
12346 " %c_v2f16_n1 = OpConstantComposite %v2f16 %c_f16_n1 %c_f16_n1\n"
12347 " %c_u32_5 = OpConstant %u32 5\n"
12348 " %c_u32_6 = OpConstant %u32 6\n"
12349 " %c_u32_7 = OpConstant %u32 7\n"
12350 " %c_u32_8 = OpConstant %u32 8\n"
12351 " %c_u32_9 = OpConstant %u32 9\n"
12352 " %c_u32_10 = OpConstant %u32 10\n"
12353 " %c_u32_11 = OpConstant %u32 11\n"
12354 " %c_u32_12 = OpConstant %u32 12\n"
12355 " %c_u32_13 = OpConstant %u32 13\n"
12356 " %c_u32_14 = OpConstant %u32 14\n"
12357 " %c_u32_15 = OpConstant %u32 15\n"
12358 " %c_u32_16 = OpConstant %u32 16\n"
12359 " %c_u32_17 = OpConstant %u32 17\n"
12360 " %c_u32_18 = OpConstant %u32 18\n"
12361 " %c_u32_19 = OpConstant %u32 19\n"
12362 " %c_u32_20 = OpConstant %u32 20\n"
12363 " %c_u32_21 = OpConstant %u32 21\n"
12364 " %c_u32_22 = OpConstant %u32 22\n"
12365 " %c_u32_23 = OpConstant %u32 23\n"
12366 " %c_u32_24 = OpConstant %u32 24\n"
12367 " %c_u32_25 = OpConstant %u32 25\n"
12368 " %c_u32_26 = OpConstant %u32 26\n"
12369 " %c_u32_27 = OpConstant %u32 27\n"
12370 " %c_u32_28 = OpConstant %u32 28\n"
12371 " %c_u32_29 = OpConstant %u32 29\n"
12372 " %c_u32_30 = OpConstant %u32 30\n"
12373 " %c_u32_31 = OpConstant %u32 31\n"
12374 " %c_u32_33 = OpConstant %u32 33\n"
12375 " %c_u32_34 = OpConstant %u32 34\n"
12376 " %c_u32_35 = OpConstant %u32 35\n"
12377 " %c_u32_36 = OpConstant %u32 36\n"
12378 " %c_u32_37 = OpConstant %u32 37\n"
12379 " %c_u32_38 = OpConstant %u32 38\n"
12380 " %c_u32_39 = OpConstant %u32 39\n"
12381 " %c_u32_40 = OpConstant %u32 40\n"
12382 " %c_u32_41 = OpConstant %u32 41\n"
12383 " %c_u32_44 = OpConstant %u32 44\n"
12385 " %f16arr3 = OpTypeArray %f16 %c_u32_3\n"
12386 " %v2f16arr3 = OpTypeArray %v2f16 %c_u32_3\n"
12387 " %v2f16arr5 = OpTypeArray %v2f16 %c_u32_5\n"
12388 " %v3f16arr5 = OpTypeArray %v3f16 %c_u32_5\n"
12389 " %v4f16arr3 = OpTypeArray %v4f16 %c_u32_3\n"
12390 " %struct16 = OpTypeStruct %f16 %v2f16arr3\n"
12391 " %struct16arr3 = OpTypeArray %struct16 %c_u32_3\n"
12392 " %st_test = OpTypeStruct %f16 %v2f16 %v3f16 %v4f16 %f16arr3 %struct16arr3 %v2f16arr5 %f16 %v3f16arr5 %v4f16arr3\n"
12394 " %up_u32 = OpTypePointer Uniform %u32\n"
12395 " %ra_u32_44 = OpTypeArray %u32 %c_u32_44\n"
12396 " %ra_ra_u32 = OpTypeArray %ra_u32_44 %c_i32_ndp\n"
12397 " %SSBO_st = OpTypeStruct %ra_ra_u32\n"
12398 " %up_SSBO_st = OpTypePointer Uniform %SSBO_st\n"
12400 " %ssbo_dst = OpVariable %up_SSBO_st Uniform\n"
12403 const StringTemplate decoration
12405 "OpDecorate %SSBO_st BufferBlock\n"
12406 "OpDecorate %ra_u32_44 ArrayStride 4\n"
12407 "OpDecorate %ra_ra_u32 ArrayStride ${struct_item_size}\n"
12408 "OpDecorate %ssbo_dst DescriptorSet 0\n"
12409 "OpDecorate %ssbo_dst Binding 1\n"
12411 "OpMemberDecorate %SSBO_st 0 Offset 0\n"
12413 "OpDecorate %v2f16arr3 ArrayStride 4\n"
12414 "OpMemberDecorate %struct16 0 Offset 0\n"
12415 "OpMemberDecorate %struct16 1 Offset 4\n"
12416 "OpDecorate %struct16arr3 ArrayStride 16\n"
12417 "OpDecorate %f16arr3 ArrayStride 2\n"
12418 "OpDecorate %v2f16arr5 ArrayStride 4\n"
12419 "OpDecorate %v3f16arr5 ArrayStride 8\n"
12420 "OpDecorate %v4f16arr3 ArrayStride 8\n"
12422 "OpMemberDecorate %st_test 0 Offset 0\n"
12423 "OpMemberDecorate %st_test 1 Offset 4\n"
12424 "OpMemberDecorate %st_test 2 Offset 8\n"
12425 "OpMemberDecorate %st_test 3 Offset 16\n"
12426 "OpMemberDecorate %st_test 4 Offset 24\n"
12427 "OpMemberDecorate %st_test 5 Offset 32\n"
12428 "OpMemberDecorate %st_test 6 Offset 80\n"
12429 "OpMemberDecorate %st_test 7 Offset 100\n"
12430 "OpMemberDecorate %st_test 8 Offset 104\n"
12431 "OpMemberDecorate %st_test 9 Offset 144\n"
12434 const StringTemplate testFun
12436 " %test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
12437 " %param = OpFunctionParameter %v4f32\n"
12438 " %entry = OpLabel\n"
12440 " %i = OpVariable %fp_i32 Function\n"
12441 " OpStore %i %c_i32_0\n"
12443 " %will_run = OpFunctionCall %bool %isUniqueIdZero\n"
12444 " OpSelectionMerge %end_if None\n"
12445 " OpBranchConditional %will_run %run_test %end_if\n"
12447 " %run_test = OpLabel\n"
12448 " OpBranch %loop\n"
12450 " %loop = OpLabel\n"
12451 " %i_cmp = OpLoad %i32 %i\n"
12452 " %lt = OpSLessThan %bool %i_cmp %c_i32_ndp\n"
12453 " OpLoopMerge %merge %next None\n"
12454 " OpBranchConditional %lt %write %merge\n"
12456 " %write = OpLabel\n"
12457 " %ndx = OpLoad %i32 %i\n"
12459 " %fld1 = OpCompositeConstruct %v2f16 %c_f16_2 %c_f16_3\n"
12460 " %fld2 = OpCompositeConstruct %v3f16 %c_f16_4 %c_f16_5 %c_f16_6\n"
12461 " %fld3 = OpCompositeConstruct %v4f16 %c_f16_8 %c_f16_9 %c_f16_10 %c_f16_11\n"
12463 " %fld4 = OpCompositeConstruct %f16arr3 %c_f16_12 %c_f16_13 %c_f16_14\n"
12465 "%fld5_0_1_0 = OpCompositeConstruct %v2f16 %c_f16_18 %c_f16_19\n"
12466 "%fld5_0_1_1 = OpCompositeConstruct %v2f16 %c_f16_20 %c_f16_21\n"
12467 "%fld5_0_1_2 = OpCompositeConstruct %v2f16 %c_f16_22 %c_f16_23\n"
12468 " %fld5_0_1 = OpCompositeConstruct %v2f16arr3 %fld5_0_1_0 %fld5_0_1_1 %fld5_0_1_2\n"
12469 " %fld5_0 = OpCompositeConstruct %struct16 %c_f16_16 %fld5_0_1\n"
12471 "%fld5_1_1_0 = OpCompositeConstruct %v2f16 %c_f16_26 %c_f16_27\n"
12472 "%fld5_1_1_1 = OpCompositeConstruct %v2f16 %c_f16_28 %c_f16_29\n"
12473 "%fld5_1_1_2 = OpCompositeConstruct %v2f16 %c_f16_30 %c_f16_31\n"
12474 " %fld5_1_1 = OpCompositeConstruct %v2f16arr3 %fld5_1_1_0 %fld5_1_1_1 %fld5_1_1_2\n"
12475 " %fld5_1 = OpCompositeConstruct %struct16 %c_f16_24 %fld5_1_1\n"
12477 "%fld5_2_1_0 = OpCompositeConstruct %v2f16 %c_f16_34 %c_f16_35\n"
12478 "%fld5_2_1_1 = OpCompositeConstruct %v2f16 %c_f16_36 %c_f16_37\n"
12479 "%fld5_2_1_2 = OpCompositeConstruct %v2f16 %c_f16_38 %c_f16_39\n"
12480 " %fld5_2_1 = OpCompositeConstruct %v2f16arr3 %fld5_2_1_0 %fld5_2_1_1 %fld5_2_1_2\n"
12481 " %fld5_2 = OpCompositeConstruct %struct16 %c_f16_32 %fld5_2_1\n"
12483 " %fld5 = OpCompositeConstruct %struct16arr3 %fld5_0 %fld5_1 %fld5_2\n"
12485 " %fld6_0 = OpCompositeConstruct %v2f16 %c_f16_40 %c_f16_41\n"
12486 " %fld6_1 = OpCompositeConstruct %v2f16 %c_f16_42 %c_f16_43\n"
12487 " %fld6_2 = OpCompositeConstruct %v2f16 %c_f16_44 %c_f16_45\n"
12488 " %fld6_3 = OpCompositeConstruct %v2f16 %c_f16_46 %c_f16_47\n"
12489 " %fld6_4 = OpCompositeConstruct %v2f16 %c_f16_48 %c_f16_49\n"
12490 " %fld6 = OpCompositeConstruct %v2f16arr5 %fld6_0 %fld6_1 %fld6_2 %fld6_3 %fld6_4\n"
12492 " %fndx = OpConvertSToF %f16 %ndx\n"
12493 " %fld8_2a0 = OpFMul %f16 %fndx %c_f16_mod\n"
12494 " %fld8_3b1 = OpFAdd %f16 %fndx %c_f16_mod\n"
12496 " %fld8_2a = OpCompositeConstruct %v2f16 %fld8_2a0 %c_f16_61\n"
12497 " %fld8_3b = OpCompositeConstruct %v2f16 %c_f16_65 %fld8_3b1\n"
12498 " %fld8_0 = OpCompositeConstruct %v3f16 %c_f16_52 %c_f16_53 %c_f16_54\n"
12499 " %fld8_1 = OpCompositeConstruct %v3f16 %c_f16_56 %c_f16_57 %c_f16_58\n"
12500 " %fld8_2 = OpCompositeConstruct %v3f16 %fld8_2a %c_f16_62\n"
12501 " %fld8_3 = OpCompositeConstruct %v3f16 %c_f16_64 %fld8_3b\n"
12502 " %fld8_4 = OpCompositeConstruct %v3f16 %c_f16_68 %c_f16_69 %c_f16_70\n"
12503 " %fld8 = OpCompositeConstruct %v3f16arr5 %fld8_0 %fld8_1 %fld8_2 %fld8_3 %fld8_4\n"
12505 " %fld9_0 = OpCompositeConstruct %v4f16 %c_f16_72 %c_f16_73 %c_f16_74 %c_f16_75\n"
12506 " %fld9_1 = OpCompositeConstruct %v4f16 %c_f16_76 %c_f16_77 %c_f16_78 %c_f16_79\n"
12507 " %fld9_2 = OpCompositeConstruct %v4f16 %c_f16_80 %c_f16_81 %c_f16_82 %c_f16_83\n"
12508 " %fld9 = OpCompositeConstruct %v4f16arr3 %fld9_0 %fld9_1 %fld9_2\n"
12510 " %st_val = OpCompositeConstruct %st_test %c_f16_0 %fld1 %fld2 %fld3 %fld4 %fld5 %fld6 %c_f16_50 %fld8 %fld9\n"
12512 // Storage section: all elements that are not directly accessed should
12513 // have the value of -1.0. This means for f16 and v3f16 stores the v2f16
12514 // is constructed with one element from a constant -1.0.
12516 " %ex_0 = OpCompositeExtract %f16 %st_val 0\n"
12517 " %vec_0 = OpCompositeConstruct %v2f16 %ex_0 %c_f16_n1\n"
12518 " %bc_0 = OpBitcast %u32 %vec_0\n"
12519 " %gep_0 = OpAccessChain %up_u32 %ssbo_dst %c_u32_0 %ndx %c_u32_0\n"
12520 " OpStore %gep_0 %bc_0\n"
12522 // <2 x half> offset 4
12523 " %ex_1 = OpCompositeExtract %v2f16 %st_val 1\n"
12524 " %bc_1 = OpBitcast %u32 %ex_1\n"
12525 " %gep_1 = OpAccessChain %up_u32 %ssbo_dst %c_u32_0 %ndx %c_u32_1\n"
12526 " OpStore %gep_1 %bc_1\n"
12528 // <3 x half> offset 8
12529 " %ex_2 = OpCompositeExtract %v3f16 %st_val 2\n"
12530 " %ex_2_0 = OpVectorShuffle %v2f16 %ex_2 %c_v2f16_n1 0 1\n"
12531 " %ex_2_1 = OpVectorShuffle %v2f16 %ex_2 %c_v2f16_n1 2 3\n"
12532 " %bc_2_0 = OpBitcast %u32 %ex_2_0\n"
12533 " %bc_2_1 = OpBitcast %u32 %ex_2_1\n"
12534 " %gep_2_0 = OpAccessChain %up_u32 %ssbo_dst %c_u32_0 %ndx %c_u32_2\n"
12535 " %gep_2_1 = OpAccessChain %up_u32 %ssbo_dst %c_u32_0 %ndx %c_u32_3\n"
12536 " OpStore %gep_2_0 %bc_2_0\n"
12537 " OpStore %gep_2_1 %bc_2_1\n"
12539 // <4 x half> offset 16
12540 " %ex_3 = OpCompositeExtract %v4f16 %st_val 3\n"
12541 " %ex_3_0 = OpVectorShuffle %v2f16 %ex_3 %ex_3 0 1\n"
12542 " %ex_3_1 = OpVectorShuffle %v2f16 %ex_3 %ex_3 2 3\n"
12543 " %bc_3_0 = OpBitcast %u32 %ex_3_0\n"
12544 " %bc_3_1 = OpBitcast %u32 %ex_3_1\n"
12545 " %gep_3_0 = OpAccessChain %up_u32 %ssbo_dst %c_u32_0 %ndx %c_u32_4\n"
12546 " %gep_3_1 = OpAccessChain %up_u32 %ssbo_dst %c_u32_0 %ndx %c_u32_5\n"
12547 " OpStore %gep_3_0 %bc_3_0\n"
12548 " OpStore %gep_3_1 %bc_3_1\n"
12550 // [3 x half] offset 24
12551 " %ex_4_0 = OpCompositeExtract %f16 %st_val 4 0\n"
12552 " %ex_4_1 = OpCompositeExtract %f16 %st_val 4 1\n"
12553 " %ex_4_2 = OpCompositeExtract %f16 %st_val 4 2\n"
12554 " %vec_4_0 = OpCompositeConstruct %v2f16 %ex_4_0 %ex_4_1\n"
12555 " %vec_4_1 = OpCompositeConstruct %v2f16 %ex_4_2 %c_f16_n1\n"
12556 " %bc_4_0 = OpBitcast %u32 %vec_4_0\n"
12557 " %bc_4_1 = OpBitcast %u32 %vec_4_1\n"
12558 " %gep_4_0 = OpAccessChain %up_u32 %ssbo_dst %c_u32_0 %ndx %c_u32_6\n"
12559 " %gep_4_1 = OpAccessChain %up_u32 %ssbo_dst %c_u32_0 %ndx %c_u32_7\n"
12560 " OpStore %gep_4_0 %bc_4_0\n"
12561 " OpStore %gep_4_1 %bc_4_1\n"
12563 // [3 x {half, [3 x <2 x half>]}] offset 32
12564 " %ex_5_0 = OpCompositeExtract %struct16 %st_val 5 0\n"
12565 " %ex_5_1 = OpCompositeExtract %struct16 %st_val 5 1\n"
12566 " %ex_5_2 = OpCompositeExtract %struct16 %st_val 5 2\n"
12567 " %ex_5_0_0 = OpCompositeExtract %f16 %ex_5_0 0\n"
12568 " %ex_5_1_0 = OpCompositeExtract %f16 %ex_5_1 0\n"
12569 " %ex_5_2_0 = OpCompositeExtract %f16 %ex_5_2 0\n"
12570 "%ex_5_0_1_0 = OpCompositeExtract %v2f16 %ex_5_0 1 0\n"
12571 "%ex_5_0_1_1 = OpCompositeExtract %v2f16 %ex_5_0 1 1\n"
12572 "%ex_5_0_1_2 = OpCompositeExtract %v2f16 %ex_5_0 1 2\n"
12573 "%ex_5_1_1_0 = OpCompositeExtract %v2f16 %ex_5_1 1 0\n"
12574 "%ex_5_1_1_1 = OpCompositeExtract %v2f16 %ex_5_1 1 1\n"
12575 "%ex_5_1_1_2 = OpCompositeExtract %v2f16 %ex_5_1 1 2\n"
12576 "%ex_5_2_1_0 = OpCompositeExtract %v2f16 %ex_5_2 1 0\n"
12577 "%ex_5_2_1_1 = OpCompositeExtract %v2f16 %ex_5_2 1 1\n"
12578 "%ex_5_2_1_2 = OpCompositeExtract %v2f16 %ex_5_2 1 2\n"
12579 " %vec_5_0_0 = OpCompositeConstruct %v2f16 %ex_5_0_0 %c_f16_n1\n"
12580 " %vec_5_1_0 = OpCompositeConstruct %v2f16 %ex_5_1_0 %c_f16_n1\n"
12581 " %vec_5_2_0 = OpCompositeConstruct %v2f16 %ex_5_2_0 %c_f16_n1\n"
12582 " %bc_5_0_0 = OpBitcast %u32 %vec_5_0_0\n"
12583 " %bc_5_1_0 = OpBitcast %u32 %vec_5_1_0\n"
12584 " %bc_5_2_0 = OpBitcast %u32 %vec_5_2_0\n"
12585 "%bc_5_0_1_0 = OpBitcast %u32 %ex_5_0_1_0\n"
12586 "%bc_5_0_1_1 = OpBitcast %u32 %ex_5_0_1_1\n"
12587 "%bc_5_0_1_2 = OpBitcast %u32 %ex_5_0_1_2\n"
12588 "%bc_5_1_1_0 = OpBitcast %u32 %ex_5_1_1_0\n"
12589 "%bc_5_1_1_1 = OpBitcast %u32 %ex_5_1_1_1\n"
12590 "%bc_5_1_1_2 = OpBitcast %u32 %ex_5_1_1_2\n"
12591 "%bc_5_2_1_0 = OpBitcast %u32 %ex_5_2_1_0\n"
12592 "%bc_5_2_1_1 = OpBitcast %u32 %ex_5_2_1_1\n"
12593 "%bc_5_2_1_2 = OpBitcast %u32 %ex_5_2_1_2\n"
12594 " %gep_5_0_0 = OpAccessChain %up_u32 %ssbo_dst %c_u32_0 %ndx %c_u32_8\n"
12595 "%gep_5_0_1_0 = OpAccessChain %up_u32 %ssbo_dst %c_u32_0 %ndx %c_u32_9\n"
12596 "%gep_5_0_1_1 = OpAccessChain %up_u32 %ssbo_dst %c_u32_0 %ndx %c_u32_10\n"
12597 "%gep_5_0_1_2 = OpAccessChain %up_u32 %ssbo_dst %c_u32_0 %ndx %c_u32_11\n"
12598 " %gep_5_1_0 = OpAccessChain %up_u32 %ssbo_dst %c_u32_0 %ndx %c_u32_12\n"
12599 "%gep_5_1_1_0 = OpAccessChain %up_u32 %ssbo_dst %c_u32_0 %ndx %c_u32_13\n"
12600 "%gep_5_1_1_1 = OpAccessChain %up_u32 %ssbo_dst %c_u32_0 %ndx %c_u32_14\n"
12601 "%gep_5_1_1_2 = OpAccessChain %up_u32 %ssbo_dst %c_u32_0 %ndx %c_u32_15\n"
12602 " %gep_5_2_0 = OpAccessChain %up_u32 %ssbo_dst %c_u32_0 %ndx %c_u32_16\n"
12603 "%gep_5_2_1_0 = OpAccessChain %up_u32 %ssbo_dst %c_u32_0 %ndx %c_u32_17\n"
12604 "%gep_5_2_1_1 = OpAccessChain %up_u32 %ssbo_dst %c_u32_0 %ndx %c_u32_18\n"
12605 "%gep_5_2_1_2 = OpAccessChain %up_u32 %ssbo_dst %c_u32_0 %ndx %c_u32_19\n"
12606 " OpStore %gep_5_0_0 %bc_5_0_0\n"
12607 " OpStore %gep_5_0_1_0 %bc_5_0_1_0\n"
12608 " OpStore %gep_5_0_1_1 %bc_5_0_1_1\n"
12609 " OpStore %gep_5_0_1_2 %bc_5_0_1_2\n"
12610 " OpStore %gep_5_1_0 %bc_5_1_0\n"
12611 " OpStore %gep_5_1_1_0 %bc_5_1_1_0\n"
12612 " OpStore %gep_5_1_1_1 %bc_5_1_1_1\n"
12613 " OpStore %gep_5_1_1_2 %bc_5_1_1_2\n"
12614 " OpStore %gep_5_2_0 %bc_5_2_0\n"
12615 " OpStore %gep_5_2_1_0 %bc_5_2_1_0\n"
12616 " OpStore %gep_5_2_1_1 %bc_5_2_1_1\n"
12617 " OpStore %gep_5_2_1_2 %bc_5_2_1_2\n"
12619 // [5 x <2 x half>] offset 80
12620 " %ex_6_0 = OpCompositeExtract %v2f16 %st_val 6 0\n"
12621 " %ex_6_1 = OpCompositeExtract %v2f16 %st_val 6 1\n"
12622 " %ex_6_2 = OpCompositeExtract %v2f16 %st_val 6 2\n"
12623 " %ex_6_3 = OpCompositeExtract %v2f16 %st_val 6 3\n"
12624 " %ex_6_4 = OpCompositeExtract %v2f16 %st_val 6 4\n"
12625 " %bc_6_0 = OpBitcast %u32 %ex_6_0\n"
12626 " %bc_6_1 = OpBitcast %u32 %ex_6_1\n"
12627 " %bc_6_2 = OpBitcast %u32 %ex_6_2\n"
12628 " %bc_6_3 = OpBitcast %u32 %ex_6_3\n"
12629 " %bc_6_4 = OpBitcast %u32 %ex_6_4\n"
12630 " %gep_6_0 = OpAccessChain %up_u32 %ssbo_dst %c_u32_0 %ndx %c_u32_20\n"
12631 " %gep_6_1 = OpAccessChain %up_u32 %ssbo_dst %c_u32_0 %ndx %c_u32_21\n"
12632 " %gep_6_2 = OpAccessChain %up_u32 %ssbo_dst %c_u32_0 %ndx %c_u32_22\n"
12633 " %gep_6_3 = OpAccessChain %up_u32 %ssbo_dst %c_u32_0 %ndx %c_u32_23\n"
12634 " %gep_6_4 = OpAccessChain %up_u32 %ssbo_dst %c_u32_0 %ndx %c_u32_24\n"
12635 " OpStore %gep_6_0 %bc_6_0\n"
12636 " OpStore %gep_6_1 %bc_6_1\n"
12637 " OpStore %gep_6_2 %bc_6_2\n"
12638 " OpStore %gep_6_3 %bc_6_3\n"
12639 " OpStore %gep_6_4 %bc_6_4\n"
12642 " %ex_7 = OpCompositeExtract %f16 %st_val 7\n"
12643 " %vec_7 = OpCompositeConstruct %v2f16 %ex_7 %c_f16_n1\n"
12644 " %bc_7 = OpBitcast %u32 %vec_7\n"
12645 " %gep_7 = OpAccessChain %up_u32 %ssbo_dst %c_u32_0 %ndx %c_u32_25\n"
12646 " OpStore %gep_7 %bc_7\n"
12648 // [5 x <3 x half>] offset 104
12649 " %ex_8_0 = OpCompositeExtract %v3f16 %st_val 8 0\n"
12650 " %ex_8_1 = OpCompositeExtract %v3f16 %st_val 8 1\n"
12651 " %ex_8_2 = OpCompositeExtract %v3f16 %st_val 8 2\n"
12652 " %ex_8_3 = OpCompositeExtract %v3f16 %st_val 8 3\n"
12653 " %ex_8_4 = OpCompositeExtract %v3f16 %st_val 8 4\n"
12654 " %vec_8_0_0 = OpVectorShuffle %v2f16 %ex_8_0 %c_v2f16_n1 0 1\n"
12655 " %vec_8_0_1 = OpVectorShuffle %v2f16 %ex_8_0 %c_v2f16_n1 2 3\n"
12656 " %vec_8_1_0 = OpVectorShuffle %v2f16 %ex_8_1 %c_v2f16_n1 0 1\n"
12657 " %vec_8_1_1 = OpVectorShuffle %v2f16 %ex_8_1 %c_v2f16_n1 2 3\n"
12658 " %vec_8_2_0 = OpVectorShuffle %v2f16 %ex_8_2 %c_v2f16_n1 0 1\n"
12659 " %vec_8_2_1 = OpVectorShuffle %v2f16 %ex_8_2 %c_v2f16_n1 2 3\n"
12660 " %vec_8_3_0 = OpVectorShuffle %v2f16 %ex_8_3 %c_v2f16_n1 0 1\n"
12661 " %vec_8_3_1 = OpVectorShuffle %v2f16 %ex_8_3 %c_v2f16_n1 2 3\n"
12662 " %vec_8_4_0 = OpVectorShuffle %v2f16 %ex_8_4 %c_v2f16_n1 0 1\n"
12663 " %vec_8_4_1 = OpVectorShuffle %v2f16 %ex_8_4 %c_v2f16_n1 2 3\n"
12664 " %bc_8_0_0 = OpBitcast %u32 %vec_8_0_0\n"
12665 " %bc_8_0_1 = OpBitcast %u32 %vec_8_0_1\n"
12666 " %bc_8_1_0 = OpBitcast %u32 %vec_8_1_0\n"
12667 " %bc_8_1_1 = OpBitcast %u32 %vec_8_1_1\n"
12668 " %bc_8_2_0 = OpBitcast %u32 %vec_8_2_0\n"
12669 " %bc_8_2_1 = OpBitcast %u32 %vec_8_2_1\n"
12670 " %bc_8_3_0 = OpBitcast %u32 %vec_8_3_0\n"
12671 " %bc_8_3_1 = OpBitcast %u32 %vec_8_3_1\n"
12672 " %bc_8_4_0 = OpBitcast %u32 %vec_8_4_0\n"
12673 " %bc_8_4_1 = OpBitcast %u32 %vec_8_4_1\n"
12674 " %gep_8_0_0 = OpAccessChain %up_u32 %ssbo_dst %c_u32_0 %ndx %c_u32_26\n"
12675 " %gep_8_0_1 = OpAccessChain %up_u32 %ssbo_dst %c_u32_0 %ndx %c_u32_27\n"
12676 " %gep_8_1_0 = OpAccessChain %up_u32 %ssbo_dst %c_u32_0 %ndx %c_u32_28\n"
12677 " %gep_8_1_1 = OpAccessChain %up_u32 %ssbo_dst %c_u32_0 %ndx %c_u32_29\n"
12678 " %gep_8_2_0 = OpAccessChain %up_u32 %ssbo_dst %c_u32_0 %ndx %c_u32_30\n"
12679 " %gep_8_2_1 = OpAccessChain %up_u32 %ssbo_dst %c_u32_0 %ndx %c_u32_31\n"
12680 " %gep_8_3_0 = OpAccessChain %up_u32 %ssbo_dst %c_u32_0 %ndx %c_u32_32\n"
12681 " %gep_8_3_1 = OpAccessChain %up_u32 %ssbo_dst %c_u32_0 %ndx %c_u32_33\n"
12682 " %gep_8_4_0 = OpAccessChain %up_u32 %ssbo_dst %c_u32_0 %ndx %c_u32_34\n"
12683 " %gep_8_4_1 = OpAccessChain %up_u32 %ssbo_dst %c_u32_0 %ndx %c_u32_35\n"
12684 " OpStore %gep_8_0_0 %bc_8_0_0\n"
12685 " OpStore %gep_8_0_1 %bc_8_0_1\n"
12686 " OpStore %gep_8_1_0 %bc_8_1_0\n"
12687 " OpStore %gep_8_1_1 %bc_8_1_1\n"
12688 " OpStore %gep_8_2_0 %bc_8_2_0\n"
12689 " OpStore %gep_8_2_1 %bc_8_2_1\n"
12690 " OpStore %gep_8_3_0 %bc_8_3_0\n"
12691 " OpStore %gep_8_3_1 %bc_8_3_1\n"
12692 " OpStore %gep_8_4_0 %bc_8_4_0\n"
12693 " OpStore %gep_8_4_1 %bc_8_4_1\n"
12695 // [3 x <4 x half>] offset 144
12696 " %ex_9_0 = OpCompositeExtract %v4f16 %st_val 9 0\n"
12697 " %ex_9_1 = OpCompositeExtract %v4f16 %st_val 9 1\n"
12698 " %ex_9_2 = OpCompositeExtract %v4f16 %st_val 9 2\n"
12699 " %vec_9_0_0 = OpVectorShuffle %v2f16 %ex_9_0 %ex_9_0 0 1\n"
12700 " %vec_9_0_1 = OpVectorShuffle %v2f16 %ex_9_0 %ex_9_0 2 3\n"
12701 " %vec_9_1_0 = OpVectorShuffle %v2f16 %ex_9_1 %ex_9_1 0 1\n"
12702 " %vec_9_1_1 = OpVectorShuffle %v2f16 %ex_9_1 %ex_9_1 2 3\n"
12703 " %vec_9_2_0 = OpVectorShuffle %v2f16 %ex_9_2 %ex_9_2 0 1\n"
12704 " %vec_9_2_1 = OpVectorShuffle %v2f16 %ex_9_2 %ex_9_2 2 3\n"
12705 " %bc_9_0_0 = OpBitcast %u32 %vec_9_0_0\n"
12706 " %bc_9_0_1 = OpBitcast %u32 %vec_9_0_1\n"
12707 " %bc_9_1_0 = OpBitcast %u32 %vec_9_1_0\n"
12708 " %bc_9_1_1 = OpBitcast %u32 %vec_9_1_1\n"
12709 " %bc_9_2_0 = OpBitcast %u32 %vec_9_2_0\n"
12710 " %bc_9_2_1 = OpBitcast %u32 %vec_9_2_1\n"
12711 " %gep_9_0_0 = OpAccessChain %up_u32 %ssbo_dst %c_u32_0 %ndx %c_u32_36\n"
12712 " %gep_9_0_1 = OpAccessChain %up_u32 %ssbo_dst %c_u32_0 %ndx %c_u32_37\n"
12713 " %gep_9_1_0 = OpAccessChain %up_u32 %ssbo_dst %c_u32_0 %ndx %c_u32_38\n"
12714 " %gep_9_1_1 = OpAccessChain %up_u32 %ssbo_dst %c_u32_0 %ndx %c_u32_39\n"
12715 " %gep_9_2_0 = OpAccessChain %up_u32 %ssbo_dst %c_u32_0 %ndx %c_u32_40\n"
12716 " %gep_9_2_1 = OpAccessChain %up_u32 %ssbo_dst %c_u32_0 %ndx %c_u32_41\n"
12717 " OpStore %gep_9_0_0 %bc_9_0_0\n"
12718 " OpStore %gep_9_0_1 %bc_9_0_1\n"
12719 " OpStore %gep_9_1_0 %bc_9_1_0\n"
12720 " OpStore %gep_9_1_1 %bc_9_1_1\n"
12721 " OpStore %gep_9_2_0 %bc_9_2_0\n"
12722 " OpStore %gep_9_2_1 %bc_9_2_1\n"
12724 " OpBranch %next\n"
12726 " %next = OpLabel\n"
12727 " %i_cur = OpLoad %i32 %i\n"
12728 " %i_new = OpIAdd %i32 %i_cur %c_i32_1\n"
12729 " OpStore %i %i_new\n"
12730 " OpBranch %loop\n"
12732 " %merge = OpLabel\n"
12733 " OpBranch %end_if\n"
12734 " %end_if = OpLabel\n"
12735 " OpReturnValue %param\n"
12740 SpecResource specResource;
12741 map<string, string> specs;
12742 VulkanFeatures features;
12743 map<string, string> fragments;
12744 vector<string> extensions;
12745 vector<deFloat16> expectedOutput;
12748 for (deUint32 elementNdx = 0; elementNdx < numElements; ++elementNdx)
12750 vector<deFloat16> expectedIterationOutput;
12752 for (deUint32 structItemNdx = 0; structItemNdx < structItemsCount; ++structItemNdx)
12753 expectedIterationOutput.push_back(tcu::Float16(float(structItemNdx)).bits());
12755 for (deUint32 structItemNdx = 0; structItemNdx < DE_LENGTH_OF_ARRAY(exceptionIndices); ++structItemNdx)
12756 expectedIterationOutput[exceptionIndices[structItemNdx]] = exceptionValue;
12758 expectedIterationOutput[fieldModifiedMulIndex] = tcu::Float16(float(elementNdx * fieldModifier)).bits();
12759 expectedIterationOutput[fieldModifiedAddIndex] = tcu::Float16(float(elementNdx + fieldModifier)).bits();
12761 expectedOutput.insert(expectedOutput.end(), expectedIterationOutput.begin(), expectedIterationOutput.end());
12764 for (deUint32 i = 0; i < structItemsCount; ++i)
12765 consts += " %c_f16_" + de::toString(i) + " = OpConstant %f16 " + de::toString(i) + "\n";
12767 specs["num_elements"] = de::toString(numElements);
12768 specs["struct_item_size"] = de::toString(structItemsCount * sizeof(deFloat16));
12769 specs["field_modifier"] = de::toString(fieldModifier);
12770 specs["consts"] = consts;
12772 fragments["capability"] = "OpCapability Float16\n";
12773 fragments["decoration"] = decoration.specialize(specs);
12774 fragments["pre_main"] = preMain.specialize(specs);
12775 fragments["testfun"] = testFun.specialize(specs);
12777 specResource.inputs.push_back(Resource(BufferSp(new Float16Buffer(expectedOutput)), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
12778 specResource.outputs.push_back(Resource(BufferSp(new Float16Buffer(expectedOutput)), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
12779 specResource.verifyIO = compareFP16CompositeFunc;
12781 extensions.push_back("VK_KHR_shader_float16_int8");
12783 features.extFloat16Int8 = EXTFLOAT16INT8FEATURES_FLOAT16;
12785 finalizeTestsCreation(specResource, fragments, testCtx, *testGroup.get(), testName, features, extensions, IVec3(1, 1, 1));
12788 return testGroup.release();
12791 template<class SpecResource>
12792 tcu::TestCaseGroup* createFloat16CompositeInsertExtractSet (tcu::TestContext& testCtx, const char* op)
12794 de::MovePtr<tcu::TestCaseGroup> testGroup (new tcu::TestCaseGroup(testCtx, de::toLower(op).c_str(), op));
12795 const deFloat16 exceptionValue = tcu::Float16(-1.0).bits();
12796 const string opName (op);
12797 const deUint32 opIndex = (opName == "OpCompositeInsert") ? 0
12798 : (opName == "OpCompositeExtract") ? 1
12801 const StringTemplate preMain
12803 " %c_i32_ndp = OpConstant %i32 ${num_elements}\n"
12804 " %c_i32_hndp = OpSpecConstantOp %i32 SDiv %c_i32_ndp %c_i32_2\n"
12805 " %c_i32_size = OpConstant %i32 ${struct_u32s}\n"
12806 "%c_u32_high_ones = OpConstant %u32 0xffff0000\n"
12807 " %c_u32_low_ones = OpConstant %u32 0x0000ffff\n"
12808 " %f16 = OpTypeFloat 16\n"
12809 " %v2f16 = OpTypeVector %f16 2\n"
12810 " %v3f16 = OpTypeVector %f16 3\n"
12811 " %v4f16 = OpTypeVector %f16 4\n"
12812 " %c_f16_na = OpConstant %f16 -1.0\n"
12813 " %c_v2f16_n1 = OpConstantComposite %v2f16 %c_f16_na %c_f16_na\n"
12814 " %c_u32_5 = OpConstant %u32 5\n"
12815 " %c_i32_5 = OpConstant %i32 5\n"
12816 " %c_i32_6 = OpConstant %i32 6\n"
12817 " %c_i32_7 = OpConstant %i32 7\n"
12818 " %c_i32_8 = OpConstant %i32 8\n"
12819 " %c_i32_9 = OpConstant %i32 9\n"
12820 " %c_i32_10 = OpConstant %i32 10\n"
12821 " %c_i32_11 = OpConstant %i32 11\n"
12823 "%f16arr3 = OpTypeArray %f16 %c_u32_3\n"
12824 "%v2f16arr3 = OpTypeArray %v2f16 %c_u32_3\n"
12825 "%v2f16arr5 = OpTypeArray %v2f16 %c_u32_5\n"
12826 "%v3f16arr5 = OpTypeArray %v3f16 %c_u32_5\n"
12827 "%v4f16arr3 = OpTypeArray %v4f16 %c_u32_3\n"
12828 "%struct16 = OpTypeStruct %f16 %v2f16arr3\n"
12829 "%struct16arr3 = OpTypeArray %struct16 %c_u32_3\n"
12830 "%st_test = OpTypeStruct %${field_type}\n"
12832 " %ra_f16 = OpTypeArray %u32 %c_i32_hndp\n"
12833 " %ra_st = OpTypeArray %u32 %c_i32_size\n"
12834 " %up_u32 = OpTypePointer Uniform %u32\n"
12835 " %st_test_i32_fn = OpTypeFunction %st_test %i32\n"
12836 "%void_st_test_i32_fn = OpTypeFunction %void %st_test %i32\n"
12837 " %f16_i32_fn = OpTypeFunction %f16 %i32\n"
12838 " %void_f16_i32_fn = OpTypeFunction %void %f16 %i32\n"
12839 " %v2f16_i32_fn = OpTypeFunction %v2f16 %i32\n"
12840 " %void_v2f16_i32_fn = OpTypeFunction %void %v2f16 %i32\n"
12842 "${op_premain_decls}"
12844 " %up_SSBO_src = OpTypePointer Uniform %SSBO_src\n"
12845 " %up_SSBO_dst = OpTypePointer Uniform %SSBO_dst\n"
12847 " %ssbo_src = OpVariable %up_SSBO_src Uniform\n"
12848 " %ssbo_dst = OpVariable %up_SSBO_dst Uniform\n"
12851 const StringTemplate decoration
12853 "OpDecorate %SSBO_src BufferBlock\n"
12854 "OpDecorate %SSBO_dst BufferBlock\n"
12855 "OpDecorate %ra_f16 ArrayStride 4\n"
12856 "OpDecorate %ra_st ArrayStride 4\n"
12857 "OpDecorate %ssbo_src DescriptorSet 0\n"
12858 "OpDecorate %ssbo_src Binding 0\n"
12859 "OpDecorate %ssbo_dst DescriptorSet 0\n"
12860 "OpDecorate %ssbo_dst Binding 1\n"
12862 "OpMemberDecorate %SSBO_src 0 Offset 0\n"
12863 "OpMemberDecorate %SSBO_dst 0 Offset 0\n"
12865 "OpDecorate %v2f16arr3 ArrayStride 4\n"
12866 "OpMemberDecorate %struct16 0 Offset 0\n"
12867 "OpMemberDecorate %struct16 1 Offset 4\n"
12868 "OpDecorate %struct16arr3 ArrayStride 16\n"
12869 "OpDecorate %f16arr3 ArrayStride 2\n"
12870 "OpDecorate %v2f16arr5 ArrayStride 4\n"
12871 "OpDecorate %v3f16arr5 ArrayStride 8\n"
12872 "OpDecorate %v4f16arr3 ArrayStride 8\n"
12874 "OpMemberDecorate %st_test 0 Offset 0\n"
12877 const StringTemplate testFun
12879 " %test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
12880 " %param = OpFunctionParameter %v4f32\n"
12881 " %entry = OpLabel\n"
12883 " %i = OpVariable %fp_i32 Function\n"
12884 " OpStore %i %c_i32_0\n"
12886 " %will_run = OpFunctionCall %bool %isUniqueIdZero\n"
12887 " OpSelectionMerge %end_if None\n"
12888 " OpBranchConditional %will_run %run_test %end_if\n"
12890 " %run_test = OpLabel\n"
12891 " OpBranch %loop\n"
12893 " %loop = OpLabel\n"
12894 " %i_cmp = OpLoad %i32 %i\n"
12895 " %lt = OpSLessThan %bool %i_cmp %c_i32_ndp\n"
12896 " OpLoopMerge %merge %next None\n"
12897 " OpBranchConditional %lt %write %merge\n"
12899 " %write = OpLabel\n"
12900 " %ndx = OpLoad %i32 %i\n"
12902 "${op_sw_fun_call}"
12904 " %dst_st = OpFunctionCall %void %${st_call} %val_dst %${st_ndx}\n"
12905 " OpBranch %next\n"
12907 " %next = OpLabel\n"
12908 " %i_cur = OpLoad %i32 %i\n"
12909 " %i_new = OpIAdd %i32 %i_cur %c_i32_1\n"
12910 " OpStore %i %i_new\n"
12911 " OpBranch %loop\n"
12913 " %merge = OpLabel\n"
12914 " OpBranch %end_if\n"
12915 " %end_if = OpLabel\n"
12916 " OpReturnValue %param\n"
12919 "${op_sw_fun_header}"
12920 " %sw_param = OpFunctionParameter %st_test\n"
12921 "%sw_paramn = OpFunctionParameter %i32\n"
12922 " %sw_entry = OpLabel\n"
12923 " OpSelectionMerge %switch_e None\n"
12924 " OpSwitch %sw_paramn %default ${case_list}\n"
12928 "%default = OpLabel\n"
12929 " OpReturnValue ${op_case_default_value}\n"
12930 "%switch_e = OpLabel\n"
12931 " OpUnreachable\n" // Unreachable merge block for switch statement
12935 const StringTemplate testCaseBody
12937 "%case_${case_ndx} = OpLabel\n"
12938 "%val_ret_${case_ndx} = ${op_name} ${op_args_part} ${access_path}\n"
12939 " OpReturnValue %val_ret_${case_ndx}\n"
12942 const string loadF16
12944 " %ld_${var} = OpFunction %st_test None %st_test_i32_fn\n"
12945 " %ld_${var}_param = OpFunctionParameter %i32\n"
12946 " %ld_${var}_entry = OpLabel\n"
12947 " %ld_${var}_call = OpFunctionCall %f16 %ld_arg_${var} %ld_${var}_param\n"
12948 "%ld_${var}_st_test = OpCompositeConstruct %st_test %ld_${var}_call\n"
12949 " OpReturnValue %ld_${var}_st_test\n"
12950 " OpFunctionEnd\n" +
12951 loadScalarF16FromUint
12954 const string loadV2F16
12956 " %ld_${var} = OpFunction %st_test None %st_test_i32_fn\n"
12957 " %ld_${var}_param = OpFunctionParameter %i32\n"
12958 " %ld_${var}_entry = OpLabel\n"
12959 " %ld_${var}_call = OpFunctionCall %v2f16 %ld_arg_${var} %ld_${var}_param\n"
12960 "%ld_${var}_st_test = OpCompositeConstruct %st_test %ld_${var}_call\n"
12961 " OpReturnValue %ld_${var}_st_test\n"
12962 " OpFunctionEnd\n" +
12966 const string loadV3F16
12968 " %ld_${var} = OpFunction %st_test None %st_test_i32_fn\n"
12969 " %ld_${var}_param = OpFunctionParameter %i32\n"
12970 " %ld_${var}_entry = OpLabel\n"
12971 " %ld_${var}_gep_0 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_0\n"
12972 " %ld_${var}_gep_1 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_1\n"
12973 " %ld_${var}_ld_0 = OpLoad %u32 %ld_${var}_gep_0\n"
12974 " %ld_${var}_ld_1 = OpLoad %u32 %ld_${var}_gep_1\n"
12975 " %ld_${var}_bc_0 = OpBitcast %v2f16 %ld_${var}_ld_0\n"
12976 " %ld_${var}_bc_1 = OpBitcast %v2f16 %ld_${var}_ld_1\n"
12977 " %ld_${var}_vec = OpVectorShuffle %v3f16 %ld_${var}_bc_0 %ld_${var}_bc_1 0 1 2\n"
12978 "%ld_${var}_st_test = OpCompositeConstruct %st_test %ld_${var}_vec\n"
12979 " OpReturnValue %ld_${var}_st_test\n"
12983 const string loadV4F16
12985 " %ld_${var} = OpFunction %st_test None %st_test_i32_fn\n"
12986 " %ld_${var}_param = OpFunctionParameter %i32\n"
12987 " %ld_${var}_entry = OpLabel\n"
12988 " %ld_${var}_gep_0 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_0\n"
12989 " %ld_${var}_gep_1 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_1\n"
12990 " %ld_${var}_ld_0 = OpLoad %u32 %ld_${var}_gep_0\n"
12991 " %ld_${var}_ld_1 = OpLoad %u32 %ld_${var}_gep_1\n"
12992 " %ld_${var}_bc_0 = OpBitcast %v2f16 %ld_${var}_ld_0\n"
12993 " %ld_${var}_bc_1 = OpBitcast %v2f16 %ld_${var}_ld_1\n"
12994 " %ld_${var}_vec = OpVectorShuffle %v4f16 %ld_${var}_bc_0 %ld_${var}_bc_1 0 1 2 3\n"
12995 "%ld_${var}_st_test = OpCompositeConstruct %st_test %ld_${var}_vec\n"
12996 " OpReturnValue %ld_${var}_st_test\n"
13000 const string loadF16Arr3
13002 " %ld_${var} = OpFunction %st_test None %st_test_i32_fn\n"
13003 " %ld_${var}_param = OpFunctionParameter %i32\n"
13004 " %ld_${var}_entry = OpLabel\n"
13005 " %ld_${var}_gep_0 = OpAccessChain %up_u32 %${var} %c_u32_0 %c_u32_0\n"
13006 " %ld_${var}_gep_1 = OpAccessChain %up_u32 %${var} %c_u32_0 %c_u32_1\n"
13007 " %ld_${var}_ld_0 = OpLoad %u32 %ld_${var}_gep_0\n"
13008 " %ld_${var}_ld_1 = OpLoad %u32 %ld_${var}_gep_1\n"
13009 " %ld_${var}_bc_0 = OpBitcast %v2f16 %ld_${var}_ld_0\n"
13010 " %ld_${var}_bc_1 = OpBitcast %v2f16 %ld_${var}_ld_1\n"
13011 " %ld_${var}_ex_0 = OpCompositeExtract %f16 %ld_${var}_bc_0 0\n"
13012 " %ld_${var}_ex_1 = OpCompositeExtract %f16 %ld_${var}_bc_0 1\n"
13013 " %ld_${var}_ex_2 = OpCompositeExtract %f16 %ld_${var}_bc_1 0\n"
13014 " %ld_${var}_cons = OpCompositeConstruct %f16arr3 %ld_${var}_ex_0 %ld_${var}_ex_1 %ld_${var}_ex_2\n"
13015 "%ld_${var}_st_test = OpCompositeConstruct %st_test %ld_${var}_cons\n"
13016 " OpReturnValue %ld_${var}_st_test\n"
13020 const string loadV2F16Arr5
13022 " %ld_${var} = OpFunction %st_test None %st_test_i32_fn\n"
13023 " %ld_${var}_param = OpFunctionParameter %i32\n"
13024 " %ld_${var}_label = OpLabel\n"
13025 " %ld_${var}_gep_0 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_0\n"
13026 " %ld_${var}_gep_1 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_1\n"
13027 " %ld_${var}_gep_2 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_2\n"
13028 " %ld_${var}_gep_3 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_3\n"
13029 " %ld_${var}_gep_4 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_4\n"
13030 " %ld_${var}_ld_0 = OpLoad %u32 %ld_${var}_gep_0\n"
13031 " %ld_${var}_ld_1 = OpLoad %u32 %ld_${var}_gep_1\n"
13032 " %ld_${var}_ld_2 = OpLoad %u32 %ld_${var}_gep_2\n"
13033 " %ld_${var}_ld_3 = OpLoad %u32 %ld_${var}_gep_3\n"
13034 " %ld_${var}_ld_4 = OpLoad %u32 %ld_${var}_gep_4\n"
13035 " %ld_${var}_bc_0 = OpBitcast %v2f16 %ld_${var}_ld_0\n"
13036 " %ld_${var}_bc_1 = OpBitcast %v2f16 %ld_${var}_ld_1\n"
13037 " %ld_${var}_bc_2 = OpBitcast %v2f16 %ld_${var}_ld_2\n"
13038 " %ld_${var}_bc_3 = OpBitcast %v2f16 %ld_${var}_ld_3\n"
13039 " %ld_${var}_bc_4 = OpBitcast %v2f16 %ld_${var}_ld_4\n"
13040 " %ld_${var}_cons = OpCompositeConstruct %v2f16arr5 %ld_${var}_bc_0 %ld_${var}_bc_1 %ld_${var}_bc_2 %ld_${var}_bc_3 %ld_${var}_bc_4\n"
13041 "%ld_${var}_st_test = OpCompositeConstruct %st_test %ld_${var}_cons\n"
13042 " OpReturnValue %ld_${var}_st_test\n"
13046 const string loadV3F16Arr5
13048 " %ld_${var} = OpFunction %st_test None %st_test_i32_fn\n"
13049 " %ld_${var}_param = OpFunctionParameter %i32\n"
13050 " %ld_${var}_entry = OpLabel\n"
13051 "%ld_${var}_gep_0_0 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_0\n"
13052 "%ld_${var}_gep_0_1 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_1\n"
13053 "%ld_${var}_gep_1_0 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_2\n"
13054 "%ld_${var}_gep_1_1 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_3\n"
13055 "%ld_${var}_gep_2_0 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_4\n"
13056 "%ld_${var}_gep_2_1 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_5\n"
13057 "%ld_${var}_gep_3_0 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_6\n"
13058 "%ld_${var}_gep_3_1 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_7\n"
13059 "%ld_${var}_gep_4_0 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_8\n"
13060 "%ld_${var}_gep_4_1 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_9\n"
13061 " %ld_${var}_ld_0_0 = OpLoad %u32 %ld_${var}_gep_0_0\n"
13062 " %ld_${var}_ld_0_1 = OpLoad %u32 %ld_${var}_gep_0_1\n"
13063 " %ld_${var}_ld_1_0 = OpLoad %u32 %ld_${var}_gep_1_0\n"
13064 " %ld_${var}_ld_1_1 = OpLoad %u32 %ld_${var}_gep_1_1\n"
13065 " %ld_${var}_ld_2_0 = OpLoad %u32 %ld_${var}_gep_2_0\n"
13066 " %ld_${var}_ld_2_1 = OpLoad %u32 %ld_${var}_gep_2_1\n"
13067 " %ld_${var}_ld_3_0 = OpLoad %u32 %ld_${var}_gep_3_0\n"
13068 " %ld_${var}_ld_3_1 = OpLoad %u32 %ld_${var}_gep_3_1\n"
13069 " %ld_${var}_ld_4_0 = OpLoad %u32 %ld_${var}_gep_4_0\n"
13070 " %ld_${var}_ld_4_1 = OpLoad %u32 %ld_${var}_gep_4_1\n"
13071 " %ld_${var}_bc_0_0 = OpBitcast %v2f16 %ld_${var}_ld_0_0\n"
13072 " %ld_${var}_bc_0_1 = OpBitcast %v2f16 %ld_${var}_ld_0_1\n"
13073 " %ld_${var}_bc_1_0 = OpBitcast %v2f16 %ld_${var}_ld_1_0\n"
13074 " %ld_${var}_bc_1_1 = OpBitcast %v2f16 %ld_${var}_ld_1_1\n"
13075 " %ld_${var}_bc_2_0 = OpBitcast %v2f16 %ld_${var}_ld_2_0\n"
13076 " %ld_${var}_bc_2_1 = OpBitcast %v2f16 %ld_${var}_ld_2_1\n"
13077 " %ld_${var}_bc_3_0 = OpBitcast %v2f16 %ld_${var}_ld_3_0\n"
13078 " %ld_${var}_bc_3_1 = OpBitcast %v2f16 %ld_${var}_ld_3_1\n"
13079 " %ld_${var}_bc_4_0 = OpBitcast %v2f16 %ld_${var}_ld_4_0\n"
13080 " %ld_${var}_bc_4_1 = OpBitcast %v2f16 %ld_${var}_ld_4_1\n"
13081 " %ld_${var}_vec_0 = OpVectorShuffle %v3f16 %ld_${var}_bc_0_0 %ld_${var}_bc_0_1 0 1 2\n"
13082 " %ld_${var}_vec_1 = OpVectorShuffle %v3f16 %ld_${var}_bc_1_0 %ld_${var}_bc_1_1 0 1 2\n"
13083 " %ld_${var}_vec_2 = OpVectorShuffle %v3f16 %ld_${var}_bc_2_0 %ld_${var}_bc_2_1 0 1 2\n"
13084 " %ld_${var}_vec_3 = OpVectorShuffle %v3f16 %ld_${var}_bc_3_0 %ld_${var}_bc_3_1 0 1 2\n"
13085 " %ld_${var}_vec_4 = OpVectorShuffle %v3f16 %ld_${var}_bc_4_0 %ld_${var}_bc_4_1 0 1 2\n"
13086 " %ld_${var}_cons = OpCompositeConstruct %v3f16arr5 %ld_${var}_vec_0 %ld_${var}_vec_1 %ld_${var}_vec_2 %ld_${var}_vec_3 %ld_${var}_vec_4\n"
13087 "%ld_${var}_st_test = OpCompositeConstruct %st_test %ld_${var}_cons\n"
13088 " OpReturnValue %ld_${var}_st_test\n"
13092 const string loadV4F16Arr3
13094 " %ld_${var} = OpFunction %st_test None %st_test_i32_fn\n"
13095 " %ld_${var}_param = OpFunctionParameter %i32\n"
13096 " %ld_${var}_entry = OpLabel\n"
13097 "%ld_${var}_gep_0_0 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_0\n"
13098 "%ld_${var}_gep_0_1 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_1\n"
13099 "%ld_${var}_gep_1_0 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_2\n"
13100 "%ld_${var}_gep_1_1 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_3\n"
13101 "%ld_${var}_gep_2_0 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_4\n"
13102 "%ld_${var}_gep_2_1 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_5\n"
13103 " %ld_${var}_ld_0_0 = OpLoad %u32 %ld_${var}_gep_0_0\n"
13104 " %ld_${var}_ld_0_1 = OpLoad %u32 %ld_${var}_gep_0_1\n"
13105 " %ld_${var}_ld_1_0 = OpLoad %u32 %ld_${var}_gep_1_0\n"
13106 " %ld_${var}_ld_1_1 = OpLoad %u32 %ld_${var}_gep_1_1\n"
13107 " %ld_${var}_ld_2_0 = OpLoad %u32 %ld_${var}_gep_2_0\n"
13108 " %ld_${var}_ld_2_1 = OpLoad %u32 %ld_${var}_gep_2_1\n"
13109 " %ld_${var}_bc_0_0 = OpBitcast %v2f16 %ld_${var}_ld_0_0\n"
13110 " %ld_${var}_bc_0_1 = OpBitcast %v2f16 %ld_${var}_ld_0_1\n"
13111 " %ld_${var}_bc_1_0 = OpBitcast %v2f16 %ld_${var}_ld_1_0\n"
13112 " %ld_${var}_bc_1_1 = OpBitcast %v2f16 %ld_${var}_ld_1_1\n"
13113 " %ld_${var}_bc_2_0 = OpBitcast %v2f16 %ld_${var}_ld_2_0\n"
13114 " %ld_${var}_bc_2_1 = OpBitcast %v2f16 %ld_${var}_ld_2_1\n"
13115 " %ld_${var}_vec_0 = OpVectorShuffle %v4f16 %ld_${var}_bc_0_0 %ld_${var}_bc_0_1 0 1 2 3\n"
13116 " %ld_${var}_vec_1 = OpVectorShuffle %v4f16 %ld_${var}_bc_1_0 %ld_${var}_bc_1_1 0 1 2 3\n"
13117 " %ld_${var}_vec_2 = OpVectorShuffle %v4f16 %ld_${var}_bc_2_0 %ld_${var}_bc_2_1 0 1 2 3\n"
13118 " %ld_${var}_cons = OpCompositeConstruct %v4f16arr3 %ld_${var}_vec_0 %ld_${var}_vec_1 %ld_${var}_vec_2\n"
13119 "%ld_${var}_st_test = OpCompositeConstruct %st_test %ld_${var}_cons\n"
13120 " OpReturnValue %ld_${var}_st_test\n"
13124 const string loadStruct16Arr3
13126 " %ld_${var} = OpFunction %st_test None %st_test_i32_fn\n"
13127 " %ld_${var}_param = OpFunctionParameter %i32\n"
13128 " %ld_${var}_entry = OpLabel\n"
13129 "%ld_${var}_gep_0_0 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_0\n"
13130 "%ld_${var}_gep_0_1_0 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_1\n"
13131 "%ld_${var}_gep_0_1_1 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_2\n"
13132 "%ld_${var}_gep_0_1_2 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_3\n"
13133 "%ld_${var}_gep_1_0 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_4\n"
13134 "%ld_${var}_gep_1_1_0 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_5\n"
13135 "%ld_${var}_gep_1_1_1 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_6\n"
13136 "%ld_${var}_gep_1_1_2 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_7\n"
13137 "%ld_${var}_gep_2_0 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_8\n"
13138 "%ld_${var}_gep_2_1_0 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_9\n"
13139 "%ld_${var}_gep_2_1_1 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_10\n"
13140 "%ld_${var}_gep_2_1_2 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_11\n"
13141 " %ld_${var}_ld_0_0 = OpLoad %u32 %ld_${var}_gep_0_0\n"
13142 " %ld_${var}_ld_0_1_0 = OpLoad %u32 %ld_${var}_gep_0_1_0\n"
13143 " %ld_${var}_ld_0_1_1 = OpLoad %u32 %ld_${var}_gep_0_1_1\n"
13144 " %ld_${var}_ld_0_1_2 = OpLoad %u32 %ld_${var}_gep_0_1_2\n"
13145 " %ld_${var}_ld_1_0 = OpLoad %u32 %ld_${var}_gep_1_0\n"
13146 " %ld_${var}_ld_1_1_0 = OpLoad %u32 %ld_${var}_gep_1_1_0\n"
13147 " %ld_${var}_ld_1_1_1 = OpLoad %u32 %ld_${var}_gep_1_1_1\n"
13148 " %ld_${var}_ld_1_1_2 = OpLoad %u32 %ld_${var}_gep_1_1_2\n"
13149 " %ld_${var}_ld_2_0 = OpLoad %u32 %ld_${var}_gep_2_0\n"
13150 " %ld_${var}_ld_2_1_0 = OpLoad %u32 %ld_${var}_gep_2_1_0\n"
13151 " %ld_${var}_ld_2_1_1 = OpLoad %u32 %ld_${var}_gep_2_1_1\n"
13152 " %ld_${var}_ld_2_1_2 = OpLoad %u32 %ld_${var}_gep_2_1_2\n"
13153 " %ld_${var}_bc_0_0 = OpBitcast %v2f16 %ld_${var}_ld_0_0\n"
13154 " %ld_${var}_bc_0_1_0 = OpBitcast %v2f16 %ld_${var}_ld_0_1_0\n"
13155 " %ld_${var}_bc_0_1_1 = OpBitcast %v2f16 %ld_${var}_ld_0_1_1\n"
13156 " %ld_${var}_bc_0_1_2 = OpBitcast %v2f16 %ld_${var}_ld_0_1_2\n"
13157 " %ld_${var}_bc_1_0 = OpBitcast %v2f16 %ld_${var}_ld_1_0\n"
13158 " %ld_${var}_bc_1_1_0 = OpBitcast %v2f16 %ld_${var}_ld_1_1_0\n"
13159 " %ld_${var}_bc_1_1_1 = OpBitcast %v2f16 %ld_${var}_ld_1_1_1\n"
13160 " %ld_${var}_bc_1_1_2 = OpBitcast %v2f16 %ld_${var}_ld_1_1_2\n"
13161 " %ld_${var}_bc_2_0 = OpBitcast %v2f16 %ld_${var}_ld_2_0\n"
13162 " %ld_${var}_bc_2_1_0 = OpBitcast %v2f16 %ld_${var}_ld_2_1_0\n"
13163 " %ld_${var}_bc_2_1_1 = OpBitcast %v2f16 %ld_${var}_ld_2_1_1\n"
13164 " %ld_${var}_bc_2_1_2 = OpBitcast %v2f16 %ld_${var}_ld_2_1_2\n"
13165 " %ld_${var}_arr_0 = OpCompositeConstruct %v2f16arr3 %ld_${var}_bc_0_1_0 %ld_${var}_bc_0_1_1 %ld_${var}_bc_0_1_2\n"
13166 " %ld_${var}_arr_1 = OpCompositeConstruct %v2f16arr3 %ld_${var}_bc_1_1_0 %ld_${var}_bc_1_1_1 %ld_${var}_bc_1_1_2\n"
13167 " %ld_${var}_arr_2 = OpCompositeConstruct %v2f16arr3 %ld_${var}_bc_2_1_0 %ld_${var}_bc_2_1_1 %ld_${var}_bc_2_1_2\n"
13168 " %ld_${var}_ex_0 = OpCompositeExtract %f16 %ld_${var}_bc_0_0 0\n"
13169 " %ld_${var}_ex_1 = OpCompositeExtract %f16 %ld_${var}_bc_1_0 0\n"
13170 " %ld_${var}_ex_2 = OpCompositeExtract %f16 %ld_${var}_bc_2_0 0\n"
13171 " %ld_${var}_st_0 = OpCompositeConstruct %struct16 %ld_${var}_ex_0 %ld_${var}_arr_0\n"
13172 " %ld_${var}_st_1 = OpCompositeConstruct %struct16 %ld_${var}_ex_1 %ld_${var}_arr_1\n"
13173 " %ld_${var}_st_2 = OpCompositeConstruct %struct16 %ld_${var}_ex_2 %ld_${var}_arr_2\n"
13174 " %ld_${var}_cons = OpCompositeConstruct %struct16arr3 %ld_${var}_st_0 %ld_${var}_st_1 %ld_${var}_st_2\n"
13175 " %ld_${var}_st_test = OpCompositeConstruct %st_test %ld_${var}_cons\n"
13176 " OpReturnValue %ld_${var}_st_test\n"
13180 const string storeF16
13182 " %st_${var} = OpFunction %void None %void_st_test_i32_fn\n"
13183 "%st_${var}_param1 = OpFunctionParameter %st_test\n"
13184 "%st_${var}_param2 = OpFunctionParameter %i32\n"
13185 " %st_${var}_entry = OpLabel\n"
13186 " %st_${var}_ex = OpCompositeExtract %f16 %st_${var}_param1 0\n"
13187 " %st_${var}_call = OpFunctionCall %void %st_fn_${var} %st_${var}_ex %st_${var}_param2\n"
13189 " OpFunctionEnd\n" +
13190 storeScalarF16AsUint
13193 const string storeV2F16
13195 " %st_${var} = OpFunction %void None %void_st_test_i32_fn\n"
13196 "%st_${var}_param1 = OpFunctionParameter %st_test\n"
13197 "%st_${var}_param2 = OpFunctionParameter %i32\n"
13198 " %st_${var}_entry = OpLabel\n"
13199 " %st_${var}_ex = OpCompositeExtract %v2f16 %st_${var}_param1 0\n"
13200 " %st_${var}_call = OpFunctionCall %void %st_fn_${var} %st_${var}_ex %st_${var}_param2\n"
13202 " OpFunctionEnd\n" +
13206 const string storeV3F16
13208 " %st_${var} = OpFunction %void None %void_st_test_i32_fn\n"
13209 "%st_${var}_param1 = OpFunctionParameter %st_test\n"
13210 "%st_${var}_param2 = OpFunctionParameter %i32\n"
13211 " %st_${var}_entry = OpLabel\n"
13212 " %st_${var}_ex = OpCompositeExtract %v3f16 %st_${var}_param1 0\n"
13213 " %st_${var}_vec_0 = OpVectorShuffle %v2f16 %st_${var}_ex %c_v2f16_n1 0 1\n"
13214 " %st_${var}_vec_1 = OpVectorShuffle %v2f16 %st_${var}_ex %c_v2f16_n1 2 3\n"
13215 " %st_${var}_bc_0 = OpBitcast %u32 %st_${var}_vec_0\n"
13216 " %st_${var}_bc_1 = OpBitcast %u32 %st_${var}_vec_1\n"
13217 " %st_${var}_gep_0 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_0\n"
13218 " %st_${var}_gep_1 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_1\n"
13219 " OpStore %st_${var}_gep_0 %st_${var}_bc_0\n"
13220 " OpStore %st_${var}_gep_1 %st_${var}_bc_1\n"
13225 const string storeV4F16
13227 " %st_${var} = OpFunction %void None %void_st_test_i32_fn\n"
13228 "%st_${var}_param1 = OpFunctionParameter %st_test\n"
13229 "%st_${var}_param2 = OpFunctionParameter %i32\n"
13230 " %st_${var}_entry = OpLabel\n"
13231 " %st_${var}_ex = OpCompositeExtract %v4f16 %st_${var}_param1 0\n"
13232 " %st_${var}_vec_0 = OpVectorShuffle %v2f16 %st_${var}_ex %c_v2f16_n1 0 1\n"
13233 " %st_${var}_vec_1 = OpVectorShuffle %v2f16 %st_${var}_ex %c_v2f16_n1 2 3\n"
13234 " %st_${var}_bc_0 = OpBitcast %u32 %st_${var}_vec_0\n"
13235 " %st_${var}_bc_1 = OpBitcast %u32 %st_${var}_vec_1\n"
13236 " %st_${var}_gep_0 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_0\n"
13237 " %st_${var}_gep_1 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_1\n"
13238 " OpStore %st_${var}_gep_0 %st_${var}_bc_0\n"
13239 " OpStore %st_${var}_gep_1 %st_${var}_bc_1\n"
13244 const string storeF16Arr3
13246 " %st_${var} = OpFunction %void None %void_st_test_i32_fn\n"
13247 "%st_${var}_param1 = OpFunctionParameter %st_test\n"
13248 "%st_${var}_param2 = OpFunctionParameter %i32\n"
13249 " %st_${var}_entry = OpLabel\n"
13250 " %st_${var}_ex_0 = OpCompositeExtract %f16 %st_${var}_param1 0 0\n"
13251 " %st_${var}_ex_1 = OpCompositeExtract %f16 %st_${var}_param1 0 1\n"
13252 " %st_${var}_ex_2 = OpCompositeExtract %f16 %st_${var}_param1 0 2\n"
13253 " %st_${var}_vec_0 = OpCompositeConstruct %v2f16 %st_${var}_ex_0 %st_${var}_ex_1\n"
13254 " %st_${var}_vec_1 = OpCompositeConstruct %v2f16 %st_${var}_ex_2 %c_f16_na\n"
13255 " %st_${var}_bc_0 = OpBitcast %u32 %st_${var}_vec_0\n"
13256 " %st_${var}_bc_1 = OpBitcast %u32 %st_${var}_vec_1\n"
13257 " %st_${var}_gep_0 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_0\n"
13258 " %st_${var}_gep_1 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_1\n"
13259 " OpStore %st_${var}_gep_0 %st_${var}_bc_0\n"
13260 " OpStore %st_${var}_gep_1 %st_${var}_bc_1\n"
13265 const string storeV2F16Arr5
13267 " %st_${var} = OpFunction %void None %void_st_test_i32_fn\n"
13268 "%st_${var}_param1 = OpFunctionParameter %st_test\n"
13269 "%st_${var}_param2 = OpFunctionParameter %i32\n"
13270 " %st_${var}_entry = OpLabel\n"
13271 " %st_${var}_ex_0 = OpCompositeExtract %v2f16 %st_${var}_param1 0 0\n"
13272 " %st_${var}_ex_1 = OpCompositeExtract %v2f16 %st_${var}_param1 0 1\n"
13273 " %st_${var}_ex_2 = OpCompositeExtract %v2f16 %st_${var}_param1 0 2\n"
13274 " %st_${var}_ex_3 = OpCompositeExtract %v2f16 %st_${var}_param1 0 3\n"
13275 " %st_${var}_ex_4 = OpCompositeExtract %v2f16 %st_${var}_param1 0 4\n"
13276 " %st_${var}_bc_0 = OpBitcast %u32 %st_${var}_ex_0\n"
13277 " %st_${var}_bc_1 = OpBitcast %u32 %st_${var}_ex_1\n"
13278 " %st_${var}_bc_2 = OpBitcast %u32 %st_${var}_ex_2\n"
13279 " %st_${var}_bc_3 = OpBitcast %u32 %st_${var}_ex_3\n"
13280 " %st_${var}_bc_4 = OpBitcast %u32 %st_${var}_ex_4\n"
13281 " %st_${var}_gep_0 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_0\n"
13282 " %st_${var}_gep_1 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_1\n"
13283 " %st_${var}_gep_2 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_2\n"
13284 " %st_${var}_gep_3 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_3\n"
13285 " %st_${var}_gep_4 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_4\n"
13286 " OpStore %st_${var}_gep_0 %st_${var}_bc_0\n"
13287 " OpStore %st_${var}_gep_1 %st_${var}_bc_1\n"
13288 " OpStore %st_${var}_gep_2 %st_${var}_bc_2\n"
13289 " OpStore %st_${var}_gep_3 %st_${var}_bc_3\n"
13290 " OpStore %st_${var}_gep_4 %st_${var}_bc_4\n"
13295 const string storeV3F16Arr5
13297 " %st_${var} = OpFunction %void None %void_st_test_i32_fn\n"
13298 "%st_${var}_param1 = OpFunctionParameter %st_test\n"
13299 "%st_${var}_param2 = OpFunctionParameter %i32\n"
13300 " %st_${var}_entry = OpLabel\n"
13301 " %st_${var}_ex_0 = OpCompositeExtract %v3f16 %st_${var}_param1 0 0\n"
13302 " %st_${var}_ex_1 = OpCompositeExtract %v3f16 %st_${var}_param1 0 1\n"
13303 " %st_${var}_ex_2 = OpCompositeExtract %v3f16 %st_${var}_param1 0 2\n"
13304 " %st_${var}_ex_3 = OpCompositeExtract %v3f16 %st_${var}_param1 0 3\n"
13305 " %st_${var}_ex_4 = OpCompositeExtract %v3f16 %st_${var}_param1 0 4\n"
13306 "%st_${var}_v2_0_0 = OpVectorShuffle %v2f16 %st_${var}_ex_0 %c_v2f16_n1 0 1\n"
13307 "%st_${var}_v2_0_1 = OpVectorShuffle %v2f16 %st_${var}_ex_0 %c_v2f16_n1 2 3\n"
13308 "%st_${var}_v2_1_0 = OpVectorShuffle %v2f16 %st_${var}_ex_1 %c_v2f16_n1 0 1\n"
13309 "%st_${var}_v2_1_1 = OpVectorShuffle %v2f16 %st_${var}_ex_1 %c_v2f16_n1 2 3\n"
13310 "%st_${var}_v2_2_0 = OpVectorShuffle %v2f16 %st_${var}_ex_2 %c_v2f16_n1 0 1\n"
13311 "%st_${var}_v2_2_1 = OpVectorShuffle %v2f16 %st_${var}_ex_2 %c_v2f16_n1 2 3\n"
13312 "%st_${var}_v2_3_0 = OpVectorShuffle %v2f16 %st_${var}_ex_3 %c_v2f16_n1 0 1\n"
13313 "%st_${var}_v2_3_1 = OpVectorShuffle %v2f16 %st_${var}_ex_3 %c_v2f16_n1 2 3\n"
13314 "%st_${var}_v2_4_0 = OpVectorShuffle %v2f16 %st_${var}_ex_4 %c_v2f16_n1 0 1\n"
13315 "%st_${var}_v2_4_1 = OpVectorShuffle %v2f16 %st_${var}_ex_4 %c_v2f16_n1 2 3\n"
13316 "%st_${var}_bc_0_0 = OpBitcast %u32 %st_${var}_v2_0_0\n"
13317 "%st_${var}_bc_0_1 = OpBitcast %u32 %st_${var}_v2_0_1\n"
13318 "%st_${var}_bc_1_0 = OpBitcast %u32 %st_${var}_v2_1_0\n"
13319 "%st_${var}_bc_1_1 = OpBitcast %u32 %st_${var}_v2_1_1\n"
13320 "%st_${var}_bc_2_0 = OpBitcast %u32 %st_${var}_v2_2_0\n"
13321 "%st_${var}_bc_2_1 = OpBitcast %u32 %st_${var}_v2_2_1\n"
13322 "%st_${var}_bc_3_0 = OpBitcast %u32 %st_${var}_v2_3_0\n"
13323 "%st_${var}_bc_3_1 = OpBitcast %u32 %st_${var}_v2_3_1\n"
13324 "%st_${var}_bc_4_0 = OpBitcast %u32 %st_${var}_v2_4_0\n"
13325 "%st_${var}_bc_4_1 = OpBitcast %u32 %st_${var}_v2_4_1\n"
13326 " %st_${var}_gep_0 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_0\n"
13327 " %st_${var}_gep_1 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_1\n"
13328 " %st_${var}_gep_2 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_2\n"
13329 " %st_${var}_gep_3 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_3\n"
13330 " %st_${var}_gep_4 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_4\n"
13331 " %st_${var}_gep_5 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_5\n"
13332 " %st_${var}_gep_6 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_6\n"
13333 " %st_${var}_gep_7 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_7\n"
13334 " %st_${var}_gep_8 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_8\n"
13335 " %st_${var}_gep_9 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_9\n"
13336 " OpStore %st_${var}_gep_0 %st_${var}_bc_0_0\n"
13337 " OpStore %st_${var}_gep_1 %st_${var}_bc_0_1\n"
13338 " OpStore %st_${var}_gep_2 %st_${var}_bc_1_0\n"
13339 " OpStore %st_${var}_gep_3 %st_${var}_bc_1_1\n"
13340 " OpStore %st_${var}_gep_4 %st_${var}_bc_2_0\n"
13341 " OpStore %st_${var}_gep_5 %st_${var}_bc_2_1\n"
13342 " OpStore %st_${var}_gep_6 %st_${var}_bc_3_0\n"
13343 " OpStore %st_${var}_gep_7 %st_${var}_bc_3_1\n"
13344 " OpStore %st_${var}_gep_8 %st_${var}_bc_4_0\n"
13345 " OpStore %st_${var}_gep_9 %st_${var}_bc_4_1\n"
13350 const string storeV4F16Arr3
13352 " %st_${var} = OpFunction %void None %void_st_test_i32_fn\n"
13353 " %st_${var}_param1 = OpFunctionParameter %st_test\n"
13354 " %st_${var}_param2 = OpFunctionParameter %i32\n"
13355 " %st_${var}_entry = OpLabel\n"
13356 " %st_${var}_ex_0 = OpCompositeExtract %v4f16 %st_${var}_param1 0 0\n"
13357 " %st_${var}_ex_1 = OpCompositeExtract %v4f16 %st_${var}_param1 0 1\n"
13358 " %st_${var}_ex_2 = OpCompositeExtract %v4f16 %st_${var}_param1 0 2\n"
13359 "%st_${var}_vec_0_0 = OpVectorShuffle %v2f16 %st_${var}_ex_0 %st_${var}_ex_0 0 1\n"
13360 "%st_${var}_vec_0_1 = OpVectorShuffle %v2f16 %st_${var}_ex_0 %st_${var}_ex_0 2 3\n"
13361 "%st_${var}_vec_1_0 = OpVectorShuffle %v2f16 %st_${var}_ex_1 %st_${var}_ex_1 0 1\n"
13362 "%st_${var}_vec_1_1 = OpVectorShuffle %v2f16 %st_${var}_ex_1 %st_${var}_ex_1 2 3\n"
13363 "%st_${var}_vec_2_0 = OpVectorShuffle %v2f16 %st_${var}_ex_2 %st_${var}_ex_2 0 1\n"
13364 "%st_${var}_vec_2_1 = OpVectorShuffle %v2f16 %st_${var}_ex_2 %st_${var}_ex_2 2 3\n"
13365 " %st_${var}_bc_0_0 = OpBitcast %u32 %st_${var}_vec_0_0\n"
13366 " %st_${var}_bc_0_1 = OpBitcast %u32 %st_${var}_vec_0_1\n"
13367 " %st_${var}_bc_1_0 = OpBitcast %u32 %st_${var}_vec_1_0\n"
13368 " %st_${var}_bc_1_1 = OpBitcast %u32 %st_${var}_vec_1_1\n"
13369 " %st_${var}_bc_2_0 = OpBitcast %u32 %st_${var}_vec_2_0\n"
13370 " %st_${var}_bc_2_1 = OpBitcast %u32 %st_${var}_vec_2_1\n"
13371 "%st_${var}_gep_0_0 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_0\n"
13372 "%st_${var}_gep_0_1 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_1\n"
13373 "%st_${var}_gep_1_0 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_2\n"
13374 "%st_${var}_gep_1_1 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_3\n"
13375 "%st_${var}_gep_2_0 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_4\n"
13376 "%st_${var}_gep_2_1 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_5\n"
13377 " OpStore %st_${var}_gep_0_0 %st_${var}_bc_0_0\n"
13378 " OpStore %st_${var}_gep_0_1 %st_${var}_bc_0_1\n"
13379 " OpStore %st_${var}_gep_1_0 %st_${var}_bc_1_0\n"
13380 " OpStore %st_${var}_gep_1_1 %st_${var}_bc_1_1\n"
13381 " OpStore %st_${var}_gep_2_0 %st_${var}_bc_2_0\n"
13382 " OpStore %st_${var}_gep_2_1 %st_${var}_bc_2_1\n"
13387 const string storeStruct16Arr3
13389 " %st_${var} = OpFunction %void None %void_st_test_i32_fn\n"
13390 " %st_${var}_param1 = OpFunctionParameter %st_test\n"
13391 " %st_${var}_param2 = OpFunctionParameter %i32\n"
13392 " %st_${var}_entry = OpLabel\n"
13393 " %st_${var}_st_0 = OpCompositeExtract %struct16 %st_${var}_param1 0 0\n"
13394 " %st_${var}_st_1 = OpCompositeExtract %struct16 %st_${var}_param1 0 1\n"
13395 " %st_${var}_st_2 = OpCompositeExtract %struct16 %st_${var}_param1 0 2\n"
13396 " %st_${var}_el_0 = OpCompositeExtract %f16 %st_${var}_st_0 0\n"
13397 " %st_${var}_v2_0_0 = OpCompositeExtract %v2f16 %st_${var}_st_0 1 0\n"
13398 " %st_${var}_v2_0_1 = OpCompositeExtract %v2f16 %st_${var}_st_0 1 1\n"
13399 " %st_${var}_v2_0_2 = OpCompositeExtract %v2f16 %st_${var}_st_0 1 2\n"
13400 " %st_${var}_el_1 = OpCompositeExtract %f16 %st_${var}_st_1 0\n"
13401 " %st_${var}_v2_1_0 = OpCompositeExtract %v2f16 %st_${var}_st_1 1 0\n"
13402 " %st_${var}_v2_1_1 = OpCompositeExtract %v2f16 %st_${var}_st_1 1 1\n"
13403 " %st_${var}_v2_1_2 = OpCompositeExtract %v2f16 %st_${var}_st_1 1 2\n"
13404 " %st_${var}_el_2 = OpCompositeExtract %f16 %st_${var}_st_2 0\n"
13405 " %st_${var}_v2_2_0 = OpCompositeExtract %v2f16 %st_${var}_st_2 1 0\n"
13406 " %st_${var}_v2_2_1 = OpCompositeExtract %v2f16 %st_${var}_st_2 1 1\n"
13407 " %st_${var}_v2_2_2 = OpCompositeExtract %v2f16 %st_${var}_st_2 1 2\n"
13408 " %st_${var}_v2_0 = OpCompositeConstruct %v2f16 %st_${var}_el_0 %c_f16_na\n"
13409 " %st_${var}_v2_1 = OpCompositeConstruct %v2f16 %st_${var}_el_1 %c_f16_na\n"
13410 " %st_${var}_v2_2 = OpCompositeConstruct %v2f16 %st_${var}_el_2 %c_f16_na\n"
13411 " %st_${var}_bc_0 = OpBitcast %u32 %st_${var}_v2_0\n"
13412 " %st_${var}_bc_0_0 = OpBitcast %u32 %st_${var}_v2_0_0\n"
13413 " %st_${var}_bc_0_1 = OpBitcast %u32 %st_${var}_v2_0_1\n"
13414 " %st_${var}_bc_0_2 = OpBitcast %u32 %st_${var}_v2_0_2\n"
13415 " %st_${var}_bc_1 = OpBitcast %u32 %st_${var}_v2_1\n"
13416 " %st_${var}_bc_1_0 = OpBitcast %u32 %st_${var}_v2_1_0\n"
13417 " %st_${var}_bc_1_1 = OpBitcast %u32 %st_${var}_v2_1_1\n"
13418 " %st_${var}_bc_1_2 = OpBitcast %u32 %st_${var}_v2_1_2\n"
13419 " %st_${var}_bc_2 = OpBitcast %u32 %st_${var}_v2_2\n"
13420 " %st_${var}_bc_2_0 = OpBitcast %u32 %st_${var}_v2_2_0\n"
13421 " %st_${var}_bc_2_1 = OpBitcast %u32 %st_${var}_v2_2_1\n"
13422 " %st_${var}_bc_2_2 = OpBitcast %u32 %st_${var}_v2_2_2\n"
13423 "%st_${var}_gep_0_0_0 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_0\n"
13424 "%st_${var}_gep_0_1_0 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_1\n"
13425 "%st_${var}_gep_0_1_1 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_2\n"
13426 "%st_${var}_gep_0_1_2 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_3\n"
13427 "%st_${var}_gep_1_0_0 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_4\n"
13428 "%st_${var}_gep_1_1_0 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_5\n"
13429 "%st_${var}_gep_1_1_1 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_6\n"
13430 "%st_${var}_gep_1_1_2 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_7\n"
13431 "%st_${var}_gep_2_0_0 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_8\n"
13432 "%st_${var}_gep_2_1_0 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_9\n"
13433 "%st_${var}_gep_2_1_1 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_10\n"
13434 "%st_${var}_gep_2_1_2 = OpAccessChain %up_u32 %${var} %c_i32_0 %c_i32_11\n"
13435 " OpStore %st_${var}_gep_0_0_0 %st_${var}_bc_0\n"
13436 " OpStore %st_${var}_gep_0_1_0 %st_${var}_bc_0_0\n"
13437 " OpStore %st_${var}_gep_0_1_1 %st_${var}_bc_0_1\n"
13438 " OpStore %st_${var}_gep_0_1_2 %st_${var}_bc_0_2\n"
13439 " OpStore %st_${var}_gep_1_0_0 %st_${var}_bc_1\n"
13440 " OpStore %st_${var}_gep_1_1_0 %st_${var}_bc_1_0\n"
13441 " OpStore %st_${var}_gep_1_1_1 %st_${var}_bc_1_1\n"
13442 " OpStore %st_${var}_gep_1_1_2 %st_${var}_bc_1_2\n"
13443 " OpStore %st_${var}_gep_2_0_0 %st_${var}_bc_2\n"
13444 " OpStore %st_${var}_gep_2_1_0 %st_${var}_bc_2_0\n"
13445 " OpStore %st_${var}_gep_2_1_1 %st_${var}_bc_2_1\n"
13446 " OpStore %st_${var}_gep_2_1_2 %st_${var}_bc_2_2\n"
13453 const char* premainDecls;
13454 const char* swFunCall;
13455 const char* swFunHeader;
13456 const char* caseDefaultValue;
13457 const char* argsPartial;
13460 OpParts opPartsArray[] =
13462 // OpCompositeInsert
13464 " %fun_t = OpTypeFunction %st_test %f16 %st_test %i32\n"
13465 " %SSBO_src = OpTypeStruct %ra_f16\n"
13466 " %SSBO_dst = OpTypeStruct %ra_st\n",
13468 " %val_new = OpFunctionCall %f16 %ld_arg_ssbo_src %ndx\n"
13469 " %val_old = OpFunctionCall %st_test %ld_ssbo_dst %c_i32_0\n"
13470 " %val_dst = OpFunctionCall %st_test %sw_fun %val_new %val_old %ndx\n",
13472 " %sw_fun = OpFunction %st_test None %fun_t\n"
13473 "%sw_paramv = OpFunctionParameter %f16\n",
13477 "%st_test %sw_paramv %sw_param",
13479 // OpCompositeExtract
13481 " %fun_t = OpTypeFunction %f16 %st_test %i32\n"
13482 " %SSBO_src = OpTypeStruct %ra_st\n"
13483 " %SSBO_dst = OpTypeStruct %ra_f16\n",
13485 " %val_src = OpFunctionCall %st_test %ld_ssbo_src %c_i32_0\n"
13486 " %val_dst = OpFunctionCall %f16 %sw_fun %val_src %ndx\n",
13488 " %sw_fun = OpFunction %f16 None %fun_t\n",
13496 DE_ASSERT(opIndex >= 0 && opIndex < DE_LENGTH_OF_ARRAY(opPartsArray));
13498 const char* accessPathF16[] =
13503 const char* accessPathV2F16[] =
13508 const char* accessPathV3F16[] =
13515 const char* accessPathV4F16[] =
13522 const char* accessPathF16Arr3[] =
13529 const char* accessPathStruct16Arr3[] =
13531 "0 0 0", // %struct16arr3
13556 const char* accessPathV2F16Arr5[] =
13558 "0 0 0", // %v2f16arr5
13569 const char* accessPathV3F16Arr5[] =
13571 "0 0 0", // %v3f16arr5
13592 const char* accessPathV4F16Arr3[] =
13594 "0 0 0", // %v4f16arr3
13612 struct TypeTestParameters
13615 size_t accessPathLength;
13616 const char** accessPath;
13617 const string loadFunction;
13618 const string storeFunction;
13621 const TypeTestParameters typeTestParameters[] =
13623 { "f16", DE_LENGTH_OF_ARRAY(accessPathF16), accessPathF16, loadF16, storeF16 },
13624 { "v2f16", DE_LENGTH_OF_ARRAY(accessPathV2F16), accessPathV2F16, loadV2F16, storeV2F16 },
13625 { "v3f16", DE_LENGTH_OF_ARRAY(accessPathV3F16), accessPathV3F16, loadV3F16, storeV3F16 },
13626 { "v4f16", DE_LENGTH_OF_ARRAY(accessPathV4F16), accessPathV4F16, loadV4F16, storeV4F16 },
13627 { "f16arr3", DE_LENGTH_OF_ARRAY(accessPathF16Arr3), accessPathF16Arr3, loadF16Arr3, storeF16Arr3 },
13628 { "v2f16arr5", DE_LENGTH_OF_ARRAY(accessPathV2F16Arr5), accessPathV2F16Arr5, loadV2F16Arr5, storeV2F16Arr5 },
13629 { "v3f16arr5", DE_LENGTH_OF_ARRAY(accessPathV3F16Arr5), accessPathV3F16Arr5, loadV3F16Arr5, storeV3F16Arr5 },
13630 { "v4f16arr3", DE_LENGTH_OF_ARRAY(accessPathV4F16Arr3), accessPathV4F16Arr3, loadV4F16Arr3, storeV4F16Arr3 },
13631 { "struct16arr3", DE_LENGTH_OF_ARRAY(accessPathStruct16Arr3), accessPathStruct16Arr3, loadStruct16Arr3, storeStruct16Arr3},
13634 for (size_t typeTestNdx = 0; typeTestNdx < DE_LENGTH_OF_ARRAY(typeTestParameters); ++typeTestNdx)
13636 const OpParts opParts = opPartsArray[opIndex];
13637 const string testName = typeTestParameters[typeTestNdx].name;
13638 const size_t structItemsCount = typeTestParameters[typeTestNdx].accessPathLength;
13639 const char** accessPath = typeTestParameters[typeTestNdx].accessPath;
13640 SpecResource specResource;
13641 map<string, string> specs;
13642 VulkanFeatures features;
13643 map<string, string> fragments;
13644 vector<string> extensions;
13645 vector<deFloat16> inputFP16;
13646 vector<deFloat16> dummyFP16Output;
13648 // Generate values for input
13649 inputFP16.reserve(structItemsCount);
13650 for (deUint32 structItemNdx = 0; structItemNdx < structItemsCount; ++structItemNdx)
13651 inputFP16.push_back((accessPath[structItemNdx] == DE_NULL) ? exceptionValue : tcu::Float16(float(structItemNdx)).bits());
13653 dummyFP16Output.resize(structItemsCount);
13655 // Generate cases for OpSwitch
13660 for (deUint32 caseNdx = 0; caseNdx < structItemsCount; ++caseNdx)
13661 if (accessPath[caseNdx] != DE_NULL)
13663 map<string, string> specCase;
13665 specCase["case_ndx"] = de::toString(caseNdx);
13666 specCase["access_path"] = accessPath[caseNdx];
13667 specCase["op_args_part"] = opParts.argsPartial;
13668 specCase["op_name"] = opName;
13670 caseBodies += testCaseBody.specialize(specCase);
13671 caseList += de::toString(caseNdx) + " %case_" + de::toString(caseNdx) + " ";
13674 specs["case_bodies"] = caseBodies;
13675 specs["case_list"] = caseList;
13678 specs["num_elements"] = de::toString(structItemsCount);
13679 specs["field_type"] = typeTestParameters[typeTestNdx].name;
13680 specs["struct_item_size"] = de::toString(structItemsCount * sizeof(deFloat16));
13681 specs["struct_u32s"] = de::toString(structItemsCount / 2);
13682 specs["op_premain_decls"] = opParts.premainDecls;
13683 specs["op_sw_fun_call"] = opParts.swFunCall;
13684 specs["op_sw_fun_header"] = opParts.swFunHeader;
13685 specs["op_case_default_value"] = opParts.caseDefaultValue;
13686 if (opIndex == 0) {
13687 specs["st_call"] = "st_ssbo_dst";
13688 specs["st_ndx"] = "c_i32_0";
13690 specs["st_call"] = "st_fn_ssbo_dst";
13691 specs["st_ndx"] = "ndx";
13694 fragments["capability"] = "OpCapability Float16\n";
13695 fragments["decoration"] = decoration.specialize(specs);
13696 fragments["pre_main"] = preMain.specialize(specs);
13697 fragments["testfun"] = testFun.specialize(specs);
13698 if (opIndex == 0) {
13699 fragments["testfun"] += StringTemplate(loadScalarF16FromUint).specialize({{"var", "ssbo_src"}});
13700 fragments["testfun"] += StringTemplate(typeTestParameters[typeTestNdx].loadFunction).specialize({{"var", "ssbo_dst"}});
13701 fragments["testfun"] += StringTemplate(typeTestParameters[typeTestNdx].storeFunction).specialize({{"var", "ssbo_dst"}});
13703 fragments["testfun"] += StringTemplate(typeTestParameters[typeTestNdx].loadFunction).specialize({{"var", "ssbo_src"}});
13704 fragments["testfun"] += StringTemplate(storeScalarF16AsUint).specialize({{"var", "ssbo_dst"}});
13707 specResource.inputs.push_back(Resource(BufferSp(new Float16Buffer(inputFP16)), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
13708 specResource.outputs.push_back(Resource(BufferSp(new Float16Buffer(dummyFP16Output)), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
13709 specResource.verifyIO = compareFP16CompositeFunc;
13711 extensions.push_back("VK_KHR_shader_float16_int8");
13713 features.extFloat16Int8 = EXTFLOAT16INT8FEATURES_FLOAT16;
13715 finalizeTestsCreation(specResource, fragments, testCtx, *testGroup.get(), testName, features, extensions, IVec3(1, 1, 1));
13718 return testGroup.release();
13721 struct fp16PerComponent
13725 , floatFormat16 (-14, 15, 10, true)
13727 , argCompCount(3, 0)
13731 bool callOncePerComponent () { return true; }
13732 deUint32 getComponentValidity () { return static_cast<deUint32>(-1); }
13734 virtual double getULPs (vector<const deFloat16*>&) { return 1.0; }
13735 virtual double getMin (double value, double ulps) { return value - floatFormat16.ulp(deAbs(value), ulps); }
13736 virtual double getMax (double value, double ulps) { return value + floatFormat16.ulp(deAbs(value), ulps); }
13738 virtual size_t getFlavorCount () { return flavorNames.empty() ? 1 : flavorNames.size(); }
13739 virtual void setFlavor (size_t flavorNo) { DE_ASSERT(flavorNo < getFlavorCount()); flavor = flavorNo; }
13740 virtual size_t getFlavor () { return flavor; }
13741 virtual string getCurrentFlavorName () { return flavorNames.empty() ? string("") : flavorNames[getFlavor()]; }
13743 virtual void setOutCompCount (size_t compCount) { outCompCount = compCount; }
13744 virtual size_t getOutCompCount () { return outCompCount; }
13746 virtual void setArgCompCount (size_t argNo, size_t compCount) { argCompCount[argNo] = compCount; }
13747 virtual size_t getArgCompCount (size_t argNo) { return argCompCount[argNo]; }
13751 tcu::FloatFormat floatFormat16;
13752 size_t outCompCount;
13753 vector<size_t> argCompCount;
13754 vector<string> flavorNames;
13757 struct fp16OpFNegate : public fp16PerComponent
13759 template <class fp16type>
13760 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
13762 const fp16type x (*in[0]);
13763 const double d (x.asDouble());
13764 const double result (0.0 - d);
13766 out[0] = fp16type(result).bits();
13767 min[0] = getMin(result, getULPs(in));
13768 max[0] = getMax(result, getULPs(in));
13774 struct fp16Round : public fp16PerComponent
13776 fp16Round() : fp16PerComponent()
13778 flavorNames.push_back("Floor(x+0.5)");
13779 flavorNames.push_back("Floor(x-0.5)");
13780 flavorNames.push_back("RoundEven");
13783 template<class fp16type>
13784 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
13786 const fp16type x (*in[0]);
13787 const double d (x.asDouble());
13788 double result (0.0);
13792 case 0: result = deRound(d); break;
13793 case 1: result = deFloor(d - 0.5); break;
13794 case 2: result = deRoundEven(d); break;
13795 default: TCU_THROW(InternalError, "Invalid flavor specified");
13798 out[0] = fp16type(result).bits();
13799 min[0] = getMin(result, getULPs(in));
13800 max[0] = getMax(result, getULPs(in));
13806 struct fp16RoundEven : public fp16PerComponent
13808 template<class fp16type>
13809 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
13811 const fp16type x (*in[0]);
13812 const double d (x.asDouble());
13813 const double result (deRoundEven(d));
13815 out[0] = fp16type(result).bits();
13816 min[0] = getMin(result, getULPs(in));
13817 max[0] = getMax(result, getULPs(in));
13823 struct fp16Trunc : public fp16PerComponent
13825 template<class fp16type>
13826 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
13828 const fp16type x (*in[0]);
13829 const double d (x.asDouble());
13830 const double result (deTrunc(d));
13832 out[0] = fp16type(result).bits();
13833 min[0] = getMin(result, getULPs(in));
13834 max[0] = getMax(result, getULPs(in));
13840 struct fp16FAbs : public fp16PerComponent
13842 template<class fp16type>
13843 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
13845 const fp16type x (*in[0]);
13846 const double d (x.asDouble());
13847 const double result (deAbs(d));
13849 out[0] = fp16type(result).bits();
13850 min[0] = getMin(result, getULPs(in));
13851 max[0] = getMax(result, getULPs(in));
13857 struct fp16FSign : public fp16PerComponent
13859 template<class fp16type>
13860 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
13862 const fp16type x (*in[0]);
13863 const double d (x.asDouble());
13864 const double result (deSign(d));
13869 out[0] = fp16type(result).bits();
13870 min[0] = getMin(result, getULPs(in));
13871 max[0] = getMax(result, getULPs(in));
13877 struct fp16Floor : public fp16PerComponent
13879 template<class fp16type>
13880 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
13882 const fp16type x (*in[0]);
13883 const double d (x.asDouble());
13884 const double result (deFloor(d));
13886 out[0] = fp16type(result).bits();
13887 min[0] = getMin(result, getULPs(in));
13888 max[0] = getMax(result, getULPs(in));
13894 struct fp16Ceil : public fp16PerComponent
13896 template<class fp16type>
13897 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
13899 const fp16type x (*in[0]);
13900 const double d (x.asDouble());
13901 const double result (deCeil(d));
13903 out[0] = fp16type(result).bits();
13904 min[0] = getMin(result, getULPs(in));
13905 max[0] = getMax(result, getULPs(in));
13911 struct fp16Fract : public fp16PerComponent
13913 template<class fp16type>
13914 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
13916 const fp16type x (*in[0]);
13917 const double d (x.asDouble());
13918 const double result (deFrac(d));
13920 out[0] = fp16type(result).bits();
13921 min[0] = getMin(result, getULPs(in));
13922 max[0] = getMax(result, getULPs(in));
13928 struct fp16Radians : public fp16PerComponent
13930 virtual double getULPs (vector<const deFloat16*>& in)
13937 template<class fp16type>
13938 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
13940 const fp16type x (*in[0]);
13941 const float d (x.asFloat());
13942 const float result (deFloatRadians(d));
13944 out[0] = fp16type(result).bits();
13945 min[0] = getMin(result, getULPs(in));
13946 max[0] = getMax(result, getULPs(in));
13952 struct fp16Degrees : public fp16PerComponent
13954 virtual double getULPs (vector<const deFloat16*>& in)
13961 template<class fp16type>
13962 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
13964 const fp16type x (*in[0]);
13965 const float d (x.asFloat());
13966 const float result (deFloatDegrees(d));
13968 out[0] = fp16type(result).bits();
13969 min[0] = getMin(result, getULPs(in));
13970 max[0] = getMax(result, getULPs(in));
13976 struct fp16Sin : public fp16PerComponent
13978 template<class fp16type>
13979 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
13981 const fp16type x (*in[0]);
13982 const double d (x.asDouble());
13983 const double result (deSin(d));
13984 const double unspecUlp (16.0);
13985 const double err (de::inRange(d, -DE_PI_DOUBLE, DE_PI_DOUBLE) ? deLdExp(1.0, -7) : floatFormat16.ulp(deAbs(result), unspecUlp));
13987 if (!de::inRange(d, -DE_PI_DOUBLE, DE_PI_DOUBLE))
13990 out[0] = fp16type(result).bits();
13991 min[0] = result - err;
13992 max[0] = result + err;
13998 struct fp16Cos : public fp16PerComponent
14000 template<class fp16type>
14001 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
14003 const fp16type x (*in[0]);
14004 const double d (x.asDouble());
14005 const double result (deCos(d));
14006 const double unspecUlp (16.0);
14007 const double err (de::inRange(d, -DE_PI_DOUBLE, DE_PI_DOUBLE) ? deLdExp(1.0, -7) : floatFormat16.ulp(deAbs(result), unspecUlp));
14009 if (!de::inRange(d, -DE_PI_DOUBLE, DE_PI_DOUBLE))
14012 out[0] = fp16type(result).bits();
14013 min[0] = result - err;
14014 max[0] = result + err;
14020 struct fp16Tan : public fp16PerComponent
14022 template<class fp16type>
14023 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
14025 const fp16type x (*in[0]);
14026 const double d (x.asDouble());
14027 const double result (deTan(d));
14029 if (!de::inRange(d, -DE_PI_DOUBLE, DE_PI_DOUBLE))
14032 out[0] = fp16type(result).bits();
14034 const double err = deLdExp(1.0, -7);
14035 const double s1 = deSin(d) + err;
14036 const double s2 = deSin(d) - err;
14037 const double c1 = deCos(d) + err;
14038 const double c2 = deCos(d) - err;
14039 const double edgeVals[] = {s1/c1, s1/c2, s2/c1, s2/c2};
14040 double edgeLeft = out[0];
14041 double edgeRight = out[0];
14043 if (deSign(c1 * c2) < 0.0)
14045 edgeLeft = -std::numeric_limits<double>::infinity();
14046 edgeRight = +std::numeric_limits<double>::infinity();
14050 edgeLeft = *std::min_element(&edgeVals[0], &edgeVals[DE_LENGTH_OF_ARRAY(edgeVals)]);
14051 edgeRight = *std::max_element(&edgeVals[0], &edgeVals[DE_LENGTH_OF_ARRAY(edgeVals)]);
14055 max[0] = edgeRight;
14062 struct fp16Asin : public fp16PerComponent
14064 template<class fp16type>
14065 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
14067 const fp16type x (*in[0]);
14068 const double d (x.asDouble());
14069 const double result (deAsin(d));
14070 const double error (deAtan2(d, sqrt(1.0 - d * d)));
14072 if (!x.isNaN() && deAbs(d) > 1.0)
14075 out[0] = fp16type(result).bits();
14076 min[0] = result - floatFormat16.ulp(deAbs(error), 2 * 5.0); // This is not a precision test. Value is not from spec
14077 max[0] = result + floatFormat16.ulp(deAbs(error), 2 * 5.0); // This is not a precision test. Value is not from spec
14083 struct fp16Acos : public fp16PerComponent
14085 template<class fp16type>
14086 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
14088 const fp16type x (*in[0]);
14089 const double d (x.asDouble());
14090 const double result (deAcos(d));
14091 const double error (deAtan2(sqrt(1.0 - d * d), d));
14093 if (!x.isNaN() && deAbs(d) > 1.0)
14096 out[0] = fp16type(result).bits();
14097 min[0] = result - floatFormat16.ulp(deAbs(error), 2 * 5.0); // This is not a precision test. Value is not from spec
14098 max[0] = result + floatFormat16.ulp(deAbs(error), 2 * 5.0); // This is not a precision test. Value is not from spec
14104 struct fp16Atan : public fp16PerComponent
14106 virtual double getULPs(vector<const deFloat16*>& in)
14110 return 2 * 5.0; // This is not a precision test. Value is not from spec
14113 template<class fp16type>
14114 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
14116 const fp16type x (*in[0]);
14117 const double d (x.asDouble());
14118 const double result (deAtanOver(d));
14120 out[0] = fp16type(result).bits();
14121 min[0] = getMin(result, getULPs(in));
14122 max[0] = getMax(result, getULPs(in));
14128 struct fp16Sinh : public fp16PerComponent
14130 fp16Sinh() : fp16PerComponent()
14132 flavorNames.push_back("Double");
14133 flavorNames.push_back("ExpFP16");
14136 template<class fp16type>
14137 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
14139 const fp16type x (*in[0]);
14140 const double d (x.asDouble());
14141 const double ulps (64 * (1.0 + 2 * deAbs(d))); // This is not a precision test. Value is not from spec
14142 double result (0.0);
14143 double error (0.0);
14145 if (getFlavor() == 0)
14147 result = deSinh(d);
14148 error = floatFormat16.ulp(deAbs(result), ulps);
14150 else if (getFlavor() == 1)
14152 const fp16type epx (deExp(d));
14153 const fp16type enx (deExp(-d));
14154 const fp16type esx (epx.asDouble() - enx.asDouble());
14155 const fp16type sx2 (esx.asDouble() / 2.0);
14157 result = sx2.asDouble();
14158 error = deAbs(floatFormat16.ulp(epx.asDouble(), ulps)) + deAbs(floatFormat16.ulp(enx.asDouble(), ulps));
14162 TCU_THROW(InternalError, "Unknown flavor");
14165 out[0] = fp16type(result).bits();
14166 min[0] = result - error;
14167 max[0] = result + error;
14173 struct fp16Cosh : public fp16PerComponent
14175 fp16Cosh() : fp16PerComponent()
14177 flavorNames.push_back("Double");
14178 flavorNames.push_back("ExpFP16");
14181 template<class fp16type>
14182 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
14184 const fp16type x (*in[0]);
14185 const double d (x.asDouble());
14186 const double ulps (64 * (1.0 + 2 * deAbs(d))); // This is not a precision test. Value is not from spec
14187 double result (0.0);
14189 if (getFlavor() == 0)
14191 result = deCosh(d);
14193 else if (getFlavor() == 1)
14195 const fp16type epx (deExp(d));
14196 const fp16type enx (deExp(-d));
14197 const fp16type esx (epx.asDouble() + enx.asDouble());
14198 const fp16type sx2 (esx.asDouble() / 2.0);
14200 result = sx2.asDouble();
14204 TCU_THROW(InternalError, "Unknown flavor");
14207 out[0] = fp16type(result).bits();
14208 min[0] = result - floatFormat16.ulp(deAbs(result), ulps);
14209 max[0] = result + floatFormat16.ulp(deAbs(result), ulps);
14215 struct fp16Tanh : public fp16PerComponent
14217 fp16Tanh() : fp16PerComponent()
14219 flavorNames.push_back("Tanh");
14220 flavorNames.push_back("SinhCosh");
14221 flavorNames.push_back("SinhCoshFP16");
14222 flavorNames.push_back("PolyFP16");
14225 virtual double getULPs (vector<const deFloat16*>& in)
14227 const tcu::Float16 x (*in[0]);
14228 const double d (x.asDouble());
14230 return 2 * (1.0 + 2 * deAbs(d)); // This is not a precision test. Value is not from spec
14233 template<class fp16type>
14234 inline double calcPoly (const fp16type& espx, const fp16type& esnx, const fp16type& ecpx, const fp16type& ecnx)
14236 const fp16type esx (espx.asDouble() - esnx.asDouble());
14237 const fp16type sx2 (esx.asDouble() / 2.0);
14238 const fp16type ecx (ecpx.asDouble() + ecnx.asDouble());
14239 const fp16type cx2 (ecx.asDouble() / 2.0);
14240 const fp16type tg (sx2.asDouble() / cx2.asDouble());
14241 const double rez (tg.asDouble());
14246 template<class fp16type>
14247 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
14249 const fp16type x (*in[0]);
14250 const double d (x.asDouble());
14251 double result (0.0);
14253 if (getFlavor() == 0)
14255 result = deTanh(d);
14256 min[0] = getMin(result, getULPs(in));
14257 max[0] = getMax(result, getULPs(in));
14259 else if (getFlavor() == 1)
14261 result = deSinh(d) / deCosh(d);
14262 min[0] = getMin(result, getULPs(in));
14263 max[0] = getMax(result, getULPs(in));
14265 else if (getFlavor() == 2)
14267 const fp16type s (deSinh(d));
14268 const fp16type c (deCosh(d));
14270 result = s.asDouble() / c.asDouble();
14271 min[0] = getMin(result, getULPs(in));
14272 max[0] = getMax(result, getULPs(in));
14274 else if (getFlavor() == 3)
14276 const double ulps (getULPs(in));
14277 const double epxm (deExp( d));
14278 const double enxm (deExp(-d));
14279 const double epxmerr = floatFormat16.ulp(epxm, ulps);
14280 const double enxmerr = floatFormat16.ulp(enxm, ulps);
14281 const fp16type epx[] = { fp16type(epxm - epxmerr), fp16type(epxm + epxmerr) };
14282 const fp16type enx[] = { fp16type(enxm - enxmerr), fp16type(enxm + enxmerr) };
14283 const fp16type epxm16 (epxm);
14284 const fp16type enxm16 (enxm);
14285 vector<double> tgs;
14287 for (size_t spNdx = 0; spNdx < DE_LENGTH_OF_ARRAY(epx); ++spNdx)
14288 for (size_t snNdx = 0; snNdx < DE_LENGTH_OF_ARRAY(enx); ++snNdx)
14289 for (size_t cpNdx = 0; cpNdx < DE_LENGTH_OF_ARRAY(epx); ++cpNdx)
14290 for (size_t cnNdx = 0; cnNdx < DE_LENGTH_OF_ARRAY(enx); ++cnNdx)
14292 const double tgh = calcPoly(epx[spNdx], enx[snNdx], epx[cpNdx], enx[cnNdx]);
14294 tgs.push_back(tgh);
14297 result = calcPoly(epxm16, enxm16, epxm16, enxm16);
14298 min[0] = *std::min_element(tgs.begin(), tgs.end());
14299 max[0] = *std::max_element(tgs.begin(), tgs.end());
14303 TCU_THROW(InternalError, "Unknown flavor");
14306 out[0] = fp16type(result).bits();
14312 struct fp16Asinh : public fp16PerComponent
14314 fp16Asinh() : fp16PerComponent()
14316 flavorNames.push_back("Double");
14317 flavorNames.push_back("PolyFP16Wiki");
14318 flavorNames.push_back("PolyFP16Abs");
14321 virtual double getULPs (vector<const deFloat16*>& in)
14325 return 256.0; // This is not a precision test. Value is not from spec
14328 template<class fp16type>
14329 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
14331 const fp16type x (*in[0]);
14332 const double d (x.asDouble());
14333 double result (0.0);
14335 if (getFlavor() == 0)
14337 result = deAsinh(d);
14339 else if (getFlavor() == 1)
14341 const fp16type x2 (d * d);
14342 const fp16type x2p1 (x2.asDouble() + 1.0);
14343 const fp16type sq (deSqrt(x2p1.asDouble()));
14344 const fp16type sxsq (d + sq.asDouble());
14345 const fp16type lsxsq (deLog(sxsq.asDouble()));
14350 result = lsxsq.asDouble();
14352 else if (getFlavor() == 2)
14354 const fp16type x2 (d * d);
14355 const fp16type x2p1 (x2.asDouble() + 1.0);
14356 const fp16type sq (deSqrt(x2p1.asDouble()));
14357 const fp16type sxsq (deAbs(d) + sq.asDouble());
14358 const fp16type lsxsq (deLog(sxsq.asDouble()));
14360 result = deSign(d) * lsxsq.asDouble();
14364 TCU_THROW(InternalError, "Unknown flavor");
14367 out[0] = fp16type(result).bits();
14368 min[0] = getMin(result, getULPs(in));
14369 max[0] = getMax(result, getULPs(in));
14375 struct fp16Acosh : public fp16PerComponent
14377 fp16Acosh() : fp16PerComponent()
14379 flavorNames.push_back("Double");
14380 flavorNames.push_back("PolyFP16");
14383 virtual double getULPs (vector<const deFloat16*>& in)
14387 return 16.0; // This is not a precision test. Value is not from spec
14390 template<class fp16type>
14391 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
14393 const fp16type x (*in[0]);
14394 const double d (x.asDouble());
14395 double result (0.0);
14397 if (!x.isNaN() && d < 1.0)
14400 if (getFlavor() == 0)
14402 result = deAcosh(d);
14404 else if (getFlavor() == 1)
14406 const fp16type x2 (d * d);
14407 const fp16type x2m1 (x2.asDouble() - 1.0);
14408 const fp16type sq (deSqrt(x2m1.asDouble()));
14409 const fp16type sxsq (d + sq.asDouble());
14410 const fp16type lsxsq (deLog(sxsq.asDouble()));
14412 result = lsxsq.asDouble();
14416 TCU_THROW(InternalError, "Unknown flavor");
14419 out[0] = fp16type(result).bits();
14420 min[0] = getMin(result, getULPs(in));
14421 max[0] = getMax(result, getULPs(in));
14427 struct fp16Atanh : public fp16PerComponent
14429 fp16Atanh() : fp16PerComponent()
14431 flavorNames.push_back("Double");
14432 flavorNames.push_back("PolyFP16");
14435 template<class fp16type>
14436 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
14438 const fp16type x (*in[0]);
14439 const double d (x.asDouble());
14440 double result (0.0);
14442 if (deAbs(d) >= 1.0)
14445 if (getFlavor() == 0)
14447 const double ulps (16.0); // This is not a precision test. Value is not from spec
14449 result = deAtanh(d);
14450 min[0] = getMin(result, ulps);
14451 max[0] = getMax(result, ulps);
14453 else if (getFlavor() == 1)
14455 const fp16type x1a (1.0 + d);
14456 const fp16type x1b (1.0 - d);
14457 const fp16type x1d (x1a.asDouble() / x1b.asDouble());
14458 const fp16type lx1d (deLog(x1d.asDouble()));
14459 const fp16type lx1d2 (0.5 * lx1d.asDouble());
14460 const double error (2 * (de::inRange(deAbs(x1d.asDouble()), 0.5, 2.0) ? deLdExp(2.0, -7) : floatFormat16.ulp(deAbs(x1d.asDouble()), 3.0)));
14462 result = lx1d2.asDouble();
14463 min[0] = result - error;
14464 max[0] = result + error;
14468 TCU_THROW(InternalError, "Unknown flavor");
14471 out[0] = fp16type(result).bits();
14477 struct fp16Exp : public fp16PerComponent
14479 template<class fp16type>
14480 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
14482 const fp16type x (*in[0]);
14483 const double d (x.asDouble());
14484 const double ulps (10.0 * (1.0 + 2.0 * deAbs(d)));
14485 const double result (deExp(d));
14487 out[0] = fp16type(result).bits();
14488 min[0] = getMin(result, ulps);
14489 max[0] = getMax(result, ulps);
14495 struct fp16Log : public fp16PerComponent
14497 template<class fp16type>
14498 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
14500 const fp16type x (*in[0]);
14501 const double d (x.asDouble());
14502 const double result (deLog(d));
14503 const double error (de::inRange(deAbs(d), 0.5, 2.0) ? deLdExp(2.0, -7) : floatFormat16.ulp(deAbs(result), 3.0));
14508 out[0] = fp16type(result).bits();
14509 min[0] = result - error;
14510 max[0] = result + error;
14516 struct fp16Exp2 : public fp16PerComponent
14518 template<class fp16type>
14519 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
14521 const fp16type x (*in[0]);
14522 const double d (x.asDouble());
14523 const double result (deExp2(d));
14524 const double ulps (1.0 + 2.0 * deAbs(fp16type(in[0][0]).asDouble()));
14526 out[0] = fp16type(result).bits();
14527 min[0] = getMin(result, ulps);
14528 max[0] = getMax(result, ulps);
14534 struct fp16Log2 : public fp16PerComponent
14536 template<class fp16type>
14537 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
14539 const fp16type x (*in[0]);
14540 const double d (x.asDouble());
14541 const double result (deLog2(d));
14542 const double error (de::inRange(deAbs(d), 0.5, 2.0) ? deLdExp(2.0, -7) : floatFormat16.ulp(deAbs(result), 3.0));
14547 out[0] = fp16type(result).bits();
14548 min[0] = result - error;
14549 max[0] = result + error;
14555 struct fp16Sqrt : public fp16PerComponent
14557 virtual double getULPs (vector<const deFloat16*>& in)
14564 template<class fp16type>
14565 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
14567 const fp16type x (*in[0]);
14568 const double d (x.asDouble());
14569 const double result (deSqrt(d));
14571 if (!x.isNaN() && d < 0.0)
14574 out[0] = fp16type(result).bits();
14575 min[0] = getMin(result, getULPs(in));
14576 max[0] = getMax(result, getULPs(in));
14582 struct fp16InverseSqrt : public fp16PerComponent
14584 virtual double getULPs (vector<const deFloat16*>& in)
14591 template<class fp16type>
14592 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
14594 const fp16type x (*in[0]);
14595 const double d (x.asDouble());
14596 const double result (1.0/deSqrt(d));
14598 if (!x.isNaN() && d <= 0.0)
14601 out[0] = fp16type(result).bits();
14602 min[0] = getMin(result, getULPs(in));
14603 max[0] = getMax(result, getULPs(in));
14609 struct fp16ModfFrac : public fp16PerComponent
14611 template<class fp16type>
14612 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
14614 const fp16type x (*in[0]);
14615 const double d (x.asDouble());
14617 const double result (deModf(d, &i));
14619 if (x.isInf() || x.isNaN())
14622 out[0] = fp16type(result).bits();
14623 min[0] = getMin(result, getULPs(in));
14624 max[0] = getMax(result, getULPs(in));
14630 struct fp16ModfInt : public fp16PerComponent
14632 template<class fp16type>
14633 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
14635 const fp16type x (*in[0]);
14636 const double d (x.asDouble());
14638 const double dummy (deModf(d, &i));
14639 const double result (i);
14643 if (x.isInf() || x.isNaN())
14646 out[0] = fp16type(result).bits();
14647 min[0] = getMin(result, getULPs(in));
14648 max[0] = getMax(result, getULPs(in));
14654 struct fp16FrexpS : public fp16PerComponent
14656 template<class fp16type>
14657 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
14659 const fp16type x (*in[0]);
14660 const double d (x.asDouble());
14662 const double result (deFrExp(d, &e));
14664 if (x.isNaN() || x.isInf())
14667 out[0] = fp16type(result).bits();
14668 min[0] = getMin(result, getULPs(in));
14669 max[0] = getMax(result, getULPs(in));
14675 struct fp16FrexpE : public fp16PerComponent
14677 template<class fp16type>
14678 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
14680 const fp16type x (*in[0]);
14681 const double d (x.asDouble());
14683 const double dummy (deFrExp(d, &e));
14684 const double result (static_cast<double>(e));
14688 if (x.isNaN() || x.isInf())
14691 out[0] = fp16type(result).bits();
14692 min[0] = getMin(result, getULPs(in));
14693 max[0] = getMax(result, getULPs(in));
14699 struct fp16OpFAdd : public fp16PerComponent
14701 template<class fp16type>
14702 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
14704 const fp16type x (*in[0]);
14705 const fp16type y (*in[1]);
14706 const double xd (x.asDouble());
14707 const double yd (y.asDouble());
14708 const double result (xd + yd);
14710 out[0] = fp16type(result).bits();
14711 min[0] = getMin(result, getULPs(in));
14712 max[0] = getMax(result, getULPs(in));
14718 struct fp16OpFSub : public fp16PerComponent
14720 template<class fp16type>
14721 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
14723 const fp16type x (*in[0]);
14724 const fp16type y (*in[1]);
14725 const double xd (x.asDouble());
14726 const double yd (y.asDouble());
14727 const double result (xd - yd);
14729 out[0] = fp16type(result).bits();
14730 min[0] = getMin(result, getULPs(in));
14731 max[0] = getMax(result, getULPs(in));
14737 struct fp16OpFMul : public fp16PerComponent
14739 template<class fp16type>
14740 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
14742 const fp16type x (*in[0]);
14743 const fp16type y (*in[1]);
14744 const double xd (x.asDouble());
14745 const double yd (y.asDouble());
14746 const double result (xd * yd);
14748 out[0] = fp16type(result).bits();
14749 min[0] = getMin(result, getULPs(in));
14750 max[0] = getMax(result, getULPs(in));
14756 struct fp16OpFDiv : public fp16PerComponent
14758 fp16OpFDiv() : fp16PerComponent()
14760 flavorNames.push_back("DirectDiv");
14761 flavorNames.push_back("InverseDiv");
14764 template<class fp16type>
14765 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
14767 const fp16type x (*in[0]);
14768 const fp16type y (*in[1]);
14769 const double xd (x.asDouble());
14770 const double yd (y.asDouble());
14771 const double unspecUlp (16.0);
14772 const double ulpCnt (de::inRange(deAbs(yd), deLdExp(1, -14), deLdExp(1, 14)) ? 2.5 : unspecUlp);
14773 double result (0.0);
14778 if (getFlavor() == 0)
14780 result = (xd / yd);
14782 else if (getFlavor() == 1)
14784 const double invyd (1.0 / yd);
14785 const fp16type invy (invyd);
14787 result = (xd * invy.asDouble());
14791 TCU_THROW(InternalError, "Unknown flavor");
14794 out[0] = fp16type(result).bits();
14795 min[0] = getMin(result, ulpCnt);
14796 max[0] = getMax(result, ulpCnt);
14802 struct fp16Atan2 : public fp16PerComponent
14804 fp16Atan2() : fp16PerComponent()
14806 flavorNames.push_back("DoubleCalc");
14807 flavorNames.push_back("DoubleCalc_PI");
14810 virtual double getULPs(vector<const deFloat16*>& in)
14814 return 2 * 5.0; // This is not a precision test. Value is not from spec
14817 template<class fp16type>
14818 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
14820 const fp16type x (*in[0]);
14821 const fp16type y (*in[1]);
14822 const double xd (x.asDouble());
14823 const double yd (y.asDouble());
14824 double result (0.0);
14826 if (x.isZero() && y.isZero())
14829 if (getFlavor() == 0)
14831 result = deAtan2(xd, yd);
14833 else if (getFlavor() == 1)
14835 const double ulps (2.0 * 5.0); // This is not a precision test. Value is not from spec
14836 const double eps (floatFormat16.ulp(DE_PI_DOUBLE, ulps));
14838 result = deAtan2(xd, yd);
14840 if (de::inRange(deAbs(result), DE_PI_DOUBLE - eps, DE_PI_DOUBLE + eps))
14845 TCU_THROW(InternalError, "Unknown flavor");
14848 out[0] = fp16type(result).bits();
14849 min[0] = getMin(result, getULPs(in));
14850 max[0] = getMax(result, getULPs(in));
14856 struct fp16Pow : public fp16PerComponent
14858 fp16Pow() : fp16PerComponent()
14860 flavorNames.push_back("Pow");
14861 flavorNames.push_back("PowLog2");
14862 flavorNames.push_back("PowLog2FP16");
14865 template<class fp16type>
14866 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
14868 const fp16type x (*in[0]);
14869 const fp16type y (*in[1]);
14870 const double xd (x.asDouble());
14871 const double yd (y.asDouble());
14872 const double logxeps (de::inRange(deAbs(xd), 0.5, 2.0) ? deLdExp(1.0, -7) : floatFormat16.ulp(deLog2(xd), 3.0));
14873 const double ulps1 (1.0 + 4.0 * deAbs(yd * (deLog2(xd) - logxeps)));
14874 const double ulps2 (1.0 + 4.0 * deAbs(yd * (deLog2(xd) + logxeps)));
14875 const double ulps (deMax(deAbs(ulps1), deAbs(ulps2)));
14876 double result (0.0);
14881 if (x.isZero() && yd <= 0.0)
14884 if (getFlavor() == 0)
14886 result = dePow(xd, yd);
14888 else if (getFlavor() == 1)
14890 const double l2d (deLog2(xd));
14891 const double e2d (deExp2(yd * l2d));
14895 else if (getFlavor() == 2)
14897 const double l2d (deLog2(xd));
14898 const fp16type l2 (l2d);
14899 const double e2d (deExp2(yd * l2.asDouble()));
14900 const fp16type e2 (e2d);
14902 result = e2.asDouble();
14906 TCU_THROW(InternalError, "Unknown flavor");
14909 out[0] = fp16type(result).bits();
14910 min[0] = getMin(result, ulps);
14911 max[0] = getMax(result, ulps);
14917 struct fp16FMin : public fp16PerComponent
14919 template<class fp16type>
14920 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
14922 const fp16type x (*in[0]);
14923 const fp16type y (*in[1]);
14924 const double xd (x.asDouble());
14925 const double yd (y.asDouble());
14926 const double result (deMin(xd, yd));
14928 if (x.isNaN() || y.isNaN())
14931 out[0] = fp16type(result).bits();
14932 min[0] = getMin(result, getULPs(in));
14933 max[0] = getMax(result, getULPs(in));
14939 struct fp16FMax : public fp16PerComponent
14941 template<class fp16type>
14942 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
14944 const fp16type x (*in[0]);
14945 const fp16type y (*in[1]);
14946 const double xd (x.asDouble());
14947 const double yd (y.asDouble());
14948 const double result (deMax(xd, yd));
14950 if (x.isNaN() || y.isNaN())
14953 out[0] = fp16type(result).bits();
14954 min[0] = getMin(result, getULPs(in));
14955 max[0] = getMax(result, getULPs(in));
14961 struct fp16Step : public fp16PerComponent
14963 template<class fp16type>
14964 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
14966 const fp16type edge (*in[0]);
14967 const fp16type x (*in[1]);
14968 const double edged (edge.asDouble());
14969 const double xd (x.asDouble());
14970 const double result (deStep(edged, xd));
14972 out[0] = fp16type(result).bits();
14973 min[0] = getMin(result, getULPs(in));
14974 max[0] = getMax(result, getULPs(in));
14980 struct fp16Ldexp : public fp16PerComponent
14982 template<class fp16type>
14983 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
14985 const fp16type x (*in[0]);
14986 const fp16type y (*in[1]);
14987 const double xd (x.asDouble());
14988 const int yd (static_cast<int>(deTrunc(y.asDouble())));
14989 const double result (deLdExp(xd, yd));
14991 if (y.isNaN() || y.isInf() || y.isDenorm() || yd < -14 || yd > 15)
14994 // Spec: "If this product is too large to be represented in the floating-point type, the result is undefined."
14995 if (fp16type(result).isInf())
14998 out[0] = fp16type(result).bits();
14999 min[0] = getMin(result, getULPs(in));
15000 max[0] = getMax(result, getULPs(in));
15006 struct fp16FClamp : public fp16PerComponent
15008 template<class fp16type>
15009 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
15011 const fp16type x (*in[0]);
15012 const fp16type minVal (*in[1]);
15013 const fp16type maxVal (*in[2]);
15014 const double xd (x.asDouble());
15015 const double minVald (minVal.asDouble());
15016 const double maxVald (maxVal.asDouble());
15017 const double result (deClamp(xd, minVald, maxVald));
15019 if (minVal.isNaN() || maxVal.isNaN() || minVald > maxVald)
15022 out[0] = fp16type(result).bits();
15023 min[0] = getMin(result, getULPs(in));
15024 max[0] = getMax(result, getULPs(in));
15030 struct fp16FMix : public fp16PerComponent
15032 fp16FMix() : fp16PerComponent()
15034 flavorNames.push_back("DoubleCalc");
15035 flavorNames.push_back("EmulatingFP16");
15036 flavorNames.push_back("EmulatingFP16YminusX");
15039 template<class fp16type>
15040 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
15042 const fp16type x (*in[0]);
15043 const fp16type y (*in[1]);
15044 const fp16type a (*in[2]);
15045 const double ulps (8.0); // This is not a precision test. Value is not from spec
15046 double result (0.0);
15048 if (getFlavor() == 0)
15050 const double xd (x.asDouble());
15051 const double yd (y.asDouble());
15052 const double ad (a.asDouble());
15053 const double xeps (floatFormat16.ulp(deAbs(xd * (1.0 - ad)), ulps));
15054 const double yeps (floatFormat16.ulp(deAbs(yd * ad), ulps));
15055 const double eps (xeps + yeps);
15057 result = deMix(xd, yd, ad);
15058 min[0] = result - eps;
15059 max[0] = result + eps;
15061 else if (getFlavor() == 1)
15063 const double xd (x.asDouble());
15064 const double yd (y.asDouble());
15065 const double ad (a.asDouble());
15066 const fp16type am (1.0 - ad);
15067 const double amd (am.asDouble());
15068 const fp16type xam (xd * amd);
15069 const double xamd (xam.asDouble());
15070 const fp16type ya (yd * ad);
15071 const double yad (ya.asDouble());
15072 const double xeps (floatFormat16.ulp(deAbs(xd * (1.0 - ad)), ulps));
15073 const double yeps (floatFormat16.ulp(deAbs(yd * ad), ulps));
15074 const double eps (xeps + yeps);
15076 result = xamd + yad;
15077 min[0] = result - eps;
15078 max[0] = result + eps;
15080 else if (getFlavor() == 2)
15082 const double xd (x.asDouble());
15083 const double yd (y.asDouble());
15084 const double ad (a.asDouble());
15085 const fp16type ymx (yd - xd);
15086 const double ymxd (ymx.asDouble());
15087 const fp16type ymxa (ymxd * ad);
15088 const double ymxad (ymxa.asDouble());
15089 const double xeps (floatFormat16.ulp(deAbs(xd * (1.0 - ad)), ulps));
15090 const double yeps (floatFormat16.ulp(deAbs(yd * ad), ulps));
15091 const double eps (xeps + yeps);
15093 result = xd + ymxad;
15094 min[0] = result - eps;
15095 max[0] = result + eps;
15099 TCU_THROW(InternalError, "Unknown flavor");
15102 out[0] = fp16type(result).bits();
15108 struct fp16SmoothStep : public fp16PerComponent
15110 fp16SmoothStep() : fp16PerComponent()
15112 flavorNames.push_back("FloatCalc");
15113 flavorNames.push_back("EmulatingFP16");
15114 flavorNames.push_back("EmulatingFP16WClamp");
15117 virtual double getULPs(vector<const deFloat16*>& in)
15121 return 4.0; // This is not a precision test. Value is not from spec
15124 template<class fp16type>
15125 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
15127 const fp16type edge0 (*in[0]);
15128 const fp16type edge1 (*in[1]);
15129 const fp16type x (*in[2]);
15130 double result (0.0);
15132 if (edge0.isNaN() || edge1.isNaN() || x.isNaN() || edge0.asDouble() >= edge1.asDouble())
15135 if (edge0.isInf() || edge1.isInf() || x.isInf())
15138 if (getFlavor() == 0)
15140 const float edge0d (edge0.asFloat());
15141 const float edge1d (edge1.asFloat());
15142 const float xd (x.asFloat());
15143 const float sstep (deFloatSmoothStep(edge0d, edge1d, xd));
15147 else if (getFlavor() == 1)
15149 const double edge0d (edge0.asDouble());
15150 const double edge1d (edge1.asDouble());
15151 const double xd (x.asDouble());
15155 else if (xd >= edge1d)
15159 const fp16type a (xd - edge0d);
15160 const fp16type b (edge1d - edge0d);
15161 const fp16type t (a.asDouble() / b.asDouble());
15162 const fp16type t2 (2.0 * t.asDouble());
15163 const fp16type t3 (3.0 - t2.asDouble());
15164 const fp16type t4 (t.asDouble() * t3.asDouble());
15165 const fp16type t5 (t.asDouble() * t4.asDouble());
15167 result = t5.asDouble();
15170 else if (getFlavor() == 2)
15172 const double edge0d (edge0.asDouble());
15173 const double edge1d (edge1.asDouble());
15174 const double xd (x.asDouble());
15175 const fp16type a (xd - edge0d);
15176 const fp16type b (edge1d - edge0d);
15177 const fp16type bi (1.0 / b.asDouble());
15178 const fp16type t0 (a.asDouble() * bi.asDouble());
15179 const double tc (deClamp(t0.asDouble(), 0.0, 1.0));
15180 const fp16type t (tc);
15181 const fp16type t2 (2.0 * t.asDouble());
15182 const fp16type t3 (3.0 - t2.asDouble());
15183 const fp16type t4 (t.asDouble() * t3.asDouble());
15184 const fp16type t5 (t.asDouble() * t4.asDouble());
15186 result = t5.asDouble();
15190 TCU_THROW(InternalError, "Unknown flavor");
15193 out[0] = fp16type(result).bits();
15194 min[0] = getMin(result, getULPs(in));
15195 max[0] = getMax(result, getULPs(in));
15201 struct fp16Fma : public fp16PerComponent
15205 flavorNames.push_back("DoubleCalc");
15206 flavorNames.push_back("EmulatingFP16");
15209 virtual double getULPs(vector<const deFloat16*>& in)
15216 template<class fp16type>
15217 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
15219 DE_ASSERT(in.size() == 3);
15220 DE_ASSERT(getArgCompCount(0) == getOutCompCount());
15221 DE_ASSERT(getArgCompCount(1) == getOutCompCount());
15222 DE_ASSERT(getArgCompCount(2) == getOutCompCount());
15223 DE_ASSERT(getOutCompCount() > 0);
15225 const fp16type a (*in[0]);
15226 const fp16type b (*in[1]);
15227 const fp16type c (*in[2]);
15228 double result (0.0);
15230 if (getFlavor() == 0)
15232 const double ad (a.asDouble());
15233 const double bd (b.asDouble());
15234 const double cd (c.asDouble());
15236 result = deMadd(ad, bd, cd);
15238 else if (getFlavor() == 1)
15240 const double ad (a.asDouble());
15241 const double bd (b.asDouble());
15242 const double cd (c.asDouble());
15243 const fp16type ab (ad * bd);
15244 const fp16type r (ab.asDouble() + cd);
15246 result = r.asDouble();
15250 TCU_THROW(InternalError, "Unknown flavor");
15253 out[0] = fp16type(result).bits();
15254 min[0] = getMin(result, getULPs(in));
15255 max[0] = getMax(result, getULPs(in));
15262 struct fp16AllComponents : public fp16PerComponent
15264 bool callOncePerComponent () { return false; }
15267 struct fp16Length : public fp16AllComponents
15269 fp16Length() : fp16AllComponents()
15271 flavorNames.push_back("EmulatingFP16");
15272 flavorNames.push_back("DoubleCalc");
15275 virtual double getULPs(vector<const deFloat16*>& in)
15282 template<class fp16type>
15283 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
15285 DE_ASSERT(getOutCompCount() == 1);
15286 DE_ASSERT(in.size() == 1);
15288 double result (0.0);
15290 if (getFlavor() == 0)
15294 for (size_t componentNdx = 0; componentNdx < getArgCompCount(0); ++componentNdx)
15296 const fp16type x (in[0][componentNdx]);
15297 const fp16type q (x.asDouble() * x.asDouble());
15299 r = fp16type(r.asDouble() + q.asDouble());
15302 result = deSqrt(r.asDouble());
15304 out[0] = fp16type(result).bits();
15306 else if (getFlavor() == 1)
15310 for (size_t componentNdx = 0; componentNdx < getArgCompCount(0); ++componentNdx)
15312 const fp16type x (in[0][componentNdx]);
15313 const double q (x.asDouble() * x.asDouble());
15318 result = deSqrt(r);
15320 out[0] = fp16type(result).bits();
15324 TCU_THROW(InternalError, "Unknown flavor");
15327 min[0] = getMin(result, getULPs(in));
15328 max[0] = getMax(result, getULPs(in));
15334 struct fp16Distance : public fp16AllComponents
15336 fp16Distance() : fp16AllComponents()
15338 flavorNames.push_back("EmulatingFP16");
15339 flavorNames.push_back("DoubleCalc");
15342 virtual double getULPs(vector<const deFloat16*>& in)
15349 template<class fp16type>
15350 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
15352 DE_ASSERT(getOutCompCount() == 1);
15353 DE_ASSERT(in.size() == 2);
15354 DE_ASSERT(getArgCompCount(0) == getArgCompCount(1));
15356 double result (0.0);
15358 if (getFlavor() == 0)
15362 for (size_t componentNdx = 0; componentNdx < getArgCompCount(0); ++componentNdx)
15364 const fp16type x (in[0][componentNdx]);
15365 const fp16type y (in[1][componentNdx]);
15366 const fp16type d (x.asDouble() - y.asDouble());
15367 const fp16type q (d.asDouble() * d.asDouble());
15369 r = fp16type(r.asDouble() + q.asDouble());
15372 result = deSqrt(r.asDouble());
15374 else if (getFlavor() == 1)
15378 for (size_t componentNdx = 0; componentNdx < getArgCompCount(0); ++componentNdx)
15380 const fp16type x (in[0][componentNdx]);
15381 const fp16type y (in[1][componentNdx]);
15382 const double d (x.asDouble() - y.asDouble());
15383 const double q (d * d);
15388 result = deSqrt(r);
15392 TCU_THROW(InternalError, "Unknown flavor");
15395 out[0] = fp16type(result).bits();
15396 min[0] = getMin(result, getULPs(in));
15397 max[0] = getMax(result, getULPs(in));
15403 struct fp16Cross : public fp16AllComponents
15405 fp16Cross() : fp16AllComponents()
15407 flavorNames.push_back("EmulatingFP16");
15408 flavorNames.push_back("DoubleCalc");
15411 virtual double getULPs(vector<const deFloat16*>& in)
15418 template<class fp16type>
15419 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
15421 DE_ASSERT(getOutCompCount() == 3);
15422 DE_ASSERT(in.size() == 2);
15423 DE_ASSERT(getArgCompCount(0) == 3);
15424 DE_ASSERT(getArgCompCount(1) == 3);
15426 if (getFlavor() == 0)
15428 const fp16type x0 (in[0][0]);
15429 const fp16type x1 (in[0][1]);
15430 const fp16type x2 (in[0][2]);
15431 const fp16type y0 (in[1][0]);
15432 const fp16type y1 (in[1][1]);
15433 const fp16type y2 (in[1][2]);
15434 const fp16type x1y2 (x1.asDouble() * y2.asDouble());
15435 const fp16type y1x2 (y1.asDouble() * x2.asDouble());
15436 const fp16type x2y0 (x2.asDouble() * y0.asDouble());
15437 const fp16type y2x0 (y2.asDouble() * x0.asDouble());
15438 const fp16type x0y1 (x0.asDouble() * y1.asDouble());
15439 const fp16type y0x1 (y0.asDouble() * x1.asDouble());
15441 out[0] = fp16type(x1y2.asDouble() - y1x2.asDouble()).bits();
15442 out[1] = fp16type(x2y0.asDouble() - y2x0.asDouble()).bits();
15443 out[2] = fp16type(x0y1.asDouble() - y0x1.asDouble()).bits();
15445 else if (getFlavor() == 1)
15447 const fp16type x0 (in[0][0]);
15448 const fp16type x1 (in[0][1]);
15449 const fp16type x2 (in[0][2]);
15450 const fp16type y0 (in[1][0]);
15451 const fp16type y1 (in[1][1]);
15452 const fp16type y2 (in[1][2]);
15453 const double x1y2 (x1.asDouble() * y2.asDouble());
15454 const double y1x2 (y1.asDouble() * x2.asDouble());
15455 const double x2y0 (x2.asDouble() * y0.asDouble());
15456 const double y2x0 (y2.asDouble() * x0.asDouble());
15457 const double x0y1 (x0.asDouble() * y1.asDouble());
15458 const double y0x1 (y0.asDouble() * x1.asDouble());
15460 out[0] = fp16type(x1y2 - y1x2).bits();
15461 out[1] = fp16type(x2y0 - y2x0).bits();
15462 out[2] = fp16type(x0y1 - y0x1).bits();
15466 TCU_THROW(InternalError, "Unknown flavor");
15469 for (size_t ndx = 0; ndx < getOutCompCount(); ++ndx)
15470 min[ndx] = getMin(fp16type(out[ndx]).asDouble(), getULPs(in));
15471 for (size_t ndx = 0; ndx < getOutCompCount(); ++ndx)
15472 max[ndx] = getMax(fp16type(out[ndx]).asDouble(), getULPs(in));
15478 struct fp16Normalize : public fp16AllComponents
15480 fp16Normalize() : fp16AllComponents()
15482 flavorNames.push_back("EmulatingFP16");
15483 flavorNames.push_back("DoubleCalc");
15485 // flavorNames will be extended later
15488 virtual void setArgCompCount (size_t argNo, size_t compCount)
15490 DE_ASSERT(argCompCount[argNo] == 0); // Once only
15492 if (argNo == 0 && argCompCount[argNo] == 0)
15494 const size_t maxPermutationsCount = 24u; // Equal to 4!
15495 std::vector<int> indices;
15497 for (size_t componentNdx = 0; componentNdx < compCount; ++componentNdx)
15498 indices.push_back(static_cast<int>(componentNdx));
15500 m_permutations.reserve(maxPermutationsCount);
15502 permutationsFlavorStart = flavorNames.size();
15506 tcu::UVec4 permutation;
15507 std::string name = "Permutted_";
15509 for (size_t componentNdx = 0; componentNdx < compCount; ++componentNdx)
15511 permutation[static_cast<int>(componentNdx)] = indices[componentNdx];
15512 name += de::toString(indices[componentNdx]);
15515 m_permutations.push_back(permutation);
15516 flavorNames.push_back(name);
15518 } while(std::next_permutation(indices.begin(), indices.end()));
15520 permutationsFlavorEnd = flavorNames.size();
15523 fp16AllComponents::setArgCompCount(argNo, compCount);
15525 virtual double getULPs(vector<const deFloat16*>& in)
15532 template<class fp16type>
15533 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
15535 DE_ASSERT(in.size() == 1);
15536 DE_ASSERT(getArgCompCount(0) == getOutCompCount());
15538 if (getFlavor() == 0)
15542 for (size_t componentNdx = 0; componentNdx < getArgCompCount(0); ++componentNdx)
15544 const fp16type x (in[0][componentNdx]);
15545 const fp16type q (x.asDouble() * x.asDouble());
15547 r = fp16type(r.asDouble() + q.asDouble());
15550 r = fp16type(deSqrt(r.asDouble()));
15555 for (size_t componentNdx = 0; componentNdx < getArgCompCount(0); ++componentNdx)
15557 const fp16type x (in[0][componentNdx]);
15559 out[componentNdx] = fp16type(x.asDouble() / r.asDouble()).bits();
15562 else if (getFlavor() == 1)
15566 for (size_t componentNdx = 0; componentNdx < getArgCompCount(0); ++componentNdx)
15568 const fp16type x (in[0][componentNdx]);
15569 const double q (x.asDouble() * x.asDouble());
15579 for (size_t componentNdx = 0; componentNdx < getArgCompCount(0); ++componentNdx)
15581 const fp16type x (in[0][componentNdx]);
15583 out[componentNdx] = fp16type(x.asDouble() / r).bits();
15586 else if (de::inBounds<size_t>(getFlavor(), permutationsFlavorStart, permutationsFlavorEnd))
15588 const int compCount (static_cast<int>(getArgCompCount(0)));
15589 const size_t permutationNdx (getFlavor() - permutationsFlavorStart);
15590 const tcu::UVec4& permutation (m_permutations[permutationNdx]);
15593 for (int permComponentNdx = 0; permComponentNdx < compCount; ++permComponentNdx)
15595 const size_t componentNdx (permutation[permComponentNdx]);
15596 const fp16type x (in[0][componentNdx]);
15597 const fp16type q (x.asDouble() * x.asDouble());
15599 r = fp16type(r.asDouble() + q.asDouble());
15602 r = fp16type(deSqrt(r.asDouble()));
15607 for (int permComponentNdx = 0; permComponentNdx < compCount; ++permComponentNdx)
15609 const size_t componentNdx (permutation[permComponentNdx]);
15610 const fp16type x (in[0][componentNdx]);
15612 out[componentNdx] = fp16type(x.asDouble() / r.asDouble()).bits();
15617 TCU_THROW(InternalError, "Unknown flavor");
15620 for (size_t ndx = 0; ndx < getOutCompCount(); ++ndx)
15621 min[ndx] = getMin(fp16type(out[ndx]).asDouble(), getULPs(in));
15622 for (size_t ndx = 0; ndx < getOutCompCount(); ++ndx)
15623 max[ndx] = getMax(fp16type(out[ndx]).asDouble(), getULPs(in));
15629 std::vector<tcu::UVec4> m_permutations;
15630 size_t permutationsFlavorStart;
15631 size_t permutationsFlavorEnd;
15634 struct fp16FaceForward : public fp16AllComponents
15636 virtual double getULPs(vector<const deFloat16*>& in)
15643 template<class fp16type>
15644 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
15646 DE_ASSERT(in.size() == 3);
15647 DE_ASSERT(getArgCompCount(0) == getOutCompCount());
15648 DE_ASSERT(getArgCompCount(1) == getOutCompCount());
15649 DE_ASSERT(getArgCompCount(2) == getOutCompCount());
15653 for (size_t componentNdx = 0; componentNdx < getArgCompCount(1); ++componentNdx)
15655 const fp16type x (in[1][componentNdx]);
15656 const fp16type y (in[2][componentNdx]);
15657 const double xd (x.asDouble());
15658 const double yd (y.asDouble());
15659 const fp16type q (xd * yd);
15661 dp = fp16type(dp.asDouble() + q.asDouble());
15664 if (dp.isNaN() || dp.isZero())
15667 for (size_t componentNdx = 0; componentNdx < getOutCompCount(); ++componentNdx)
15669 const fp16type n (in[0][componentNdx]);
15671 out[componentNdx] = (dp.signBit() == 1) ? n.bits() : fp16type(-n.asDouble()).bits();
15674 for (size_t ndx = 0; ndx < getOutCompCount(); ++ndx)
15675 min[ndx] = getMin(fp16type(out[ndx]).asDouble(), getULPs(in));
15676 for (size_t ndx = 0; ndx < getOutCompCount(); ++ndx)
15677 max[ndx] = getMax(fp16type(out[ndx]).asDouble(), getULPs(in));
15683 struct fp16Reflect : public fp16AllComponents
15685 fp16Reflect() : fp16AllComponents()
15687 flavorNames.push_back("EmulatingFP16");
15688 flavorNames.push_back("EmulatingFP16+KeepZeroSign");
15689 flavorNames.push_back("FloatCalc");
15690 flavorNames.push_back("FloatCalc+KeepZeroSign");
15691 flavorNames.push_back("EmulatingFP16+2Nfirst");
15692 flavorNames.push_back("EmulatingFP16+2Ifirst");
15695 virtual double getULPs(vector<const deFloat16*>& in)
15699 return 256.0; // This is not a precision test. Value is not from spec
15702 template<class fp16type>
15703 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
15705 DE_ASSERT(in.size() == 2);
15706 DE_ASSERT(getArgCompCount(0) == getOutCompCount());
15707 DE_ASSERT(getArgCompCount(1) == getOutCompCount());
15709 if (getFlavor() < 4)
15711 const bool keepZeroSign ((flavor & 1) != 0 ? true : false);
15712 const bool floatCalc ((flavor & 2) != 0 ? true : false);
15718 for (size_t componentNdx = 0; componentNdx < getArgCompCount(1); ++componentNdx)
15720 const fp16type i (in[0][componentNdx]);
15721 const fp16type n (in[1][componentNdx]);
15722 const float id (i.asFloat());
15723 const float nd (n.asFloat());
15724 const float qd (id * nd);
15727 dp = (componentNdx == 0) ? qd : dp + qd;
15732 for (size_t componentNdx = 0; componentNdx < getOutCompCount(); ++componentNdx)
15734 const fp16type i (in[0][componentNdx]);
15735 const fp16type n (in[1][componentNdx]);
15736 const float dpnd (dp * n.asFloat());
15737 const float dpn2d (2.0f * dpnd);
15738 const float idpn2d (i.asFloat() - dpn2d);
15739 const fp16type result (idpn2d);
15741 out[componentNdx] = result.bits();
15748 for (size_t componentNdx = 0; componentNdx < getArgCompCount(1); ++componentNdx)
15750 const fp16type i (in[0][componentNdx]);
15751 const fp16type n (in[1][componentNdx]);
15752 const double id (i.asDouble());
15753 const double nd (n.asDouble());
15754 const fp16type q (id * nd);
15757 dp = (componentNdx == 0) ? q : fp16type(dp.asDouble() + q.asDouble());
15759 dp = fp16type(dp.asDouble() + q.asDouble());
15765 for (size_t componentNdx = 0; componentNdx < getOutCompCount(); ++componentNdx)
15767 const fp16type i (in[0][componentNdx]);
15768 const fp16type n (in[1][componentNdx]);
15769 const fp16type dpn (dp.asDouble() * n.asDouble());
15770 const fp16type dpn2 (2 * dpn.asDouble());
15771 const fp16type idpn2 (i.asDouble() - dpn2.asDouble());
15773 out[componentNdx] = idpn2.bits();
15777 else if (getFlavor() == 4)
15781 for (size_t componentNdx = 0; componentNdx < getArgCompCount(1); ++componentNdx)
15783 const fp16type i (in[0][componentNdx]);
15784 const fp16type n (in[1][componentNdx]);
15785 const double id (i.asDouble());
15786 const double nd (n.asDouble());
15787 const fp16type q (id * nd);
15789 dp = fp16type(dp.asDouble() + q.asDouble());
15795 for (size_t componentNdx = 0; componentNdx < getOutCompCount(); ++componentNdx)
15797 const fp16type i (in[0][componentNdx]);
15798 const fp16type n (in[1][componentNdx]);
15799 const fp16type n2 (2 * n.asDouble());
15800 const fp16type dpn2 (dp.asDouble() * n2.asDouble());
15801 const fp16type idpn2 (i.asDouble() - dpn2.asDouble());
15803 out[componentNdx] = idpn2.bits();
15806 else if (getFlavor() == 5)
15810 for (size_t componentNdx = 0; componentNdx < getArgCompCount(1); ++componentNdx)
15812 const fp16type i (in[0][componentNdx]);
15813 const fp16type n (in[1][componentNdx]);
15814 const fp16type i2 (2.0 * i.asDouble());
15815 const double i2d (i2.asDouble());
15816 const double nd (n.asDouble());
15817 const fp16type q (i2d * nd);
15819 dp2 = fp16type(dp2.asDouble() + q.asDouble());
15825 for (size_t componentNdx = 0; componentNdx < getOutCompCount(); ++componentNdx)
15827 const fp16type i (in[0][componentNdx]);
15828 const fp16type n (in[1][componentNdx]);
15829 const fp16type dpn2 (dp2.asDouble() * n.asDouble());
15830 const fp16type idpn2 (i.asDouble() - dpn2.asDouble());
15832 out[componentNdx] = idpn2.bits();
15837 TCU_THROW(InternalError, "Unknown flavor");
15840 for (size_t ndx = 0; ndx < getOutCompCount(); ++ndx)
15841 min[ndx] = getMin(fp16type(out[ndx]).asDouble(), getULPs(in));
15842 for (size_t ndx = 0; ndx < getOutCompCount(); ++ndx)
15843 max[ndx] = getMax(fp16type(out[ndx]).asDouble(), getULPs(in));
15849 struct fp16Refract : public fp16AllComponents
15851 fp16Refract() : fp16AllComponents()
15853 flavorNames.push_back("EmulatingFP16");
15854 flavorNames.push_back("EmulatingFP16+KeepZeroSign");
15855 flavorNames.push_back("FloatCalc");
15856 flavorNames.push_back("FloatCalc+KeepZeroSign");
15859 virtual double getULPs(vector<const deFloat16*>& in)
15863 return 8192.0; // This is not a precision test. Value is not from spec
15866 template<class fp16type>
15867 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
15869 DE_ASSERT(in.size() == 3);
15870 DE_ASSERT(getArgCompCount(0) == getOutCompCount());
15871 DE_ASSERT(getArgCompCount(1) == getOutCompCount());
15872 DE_ASSERT(getArgCompCount(2) == 1);
15874 const bool keepZeroSign ((flavor & 1) != 0 ? true : false);
15875 const bool doubleCalc ((flavor & 2) != 0 ? true : false);
15876 const fp16type eta (*in[2]);
15882 for (size_t componentNdx = 0; componentNdx < getArgCompCount(1); ++componentNdx)
15884 const fp16type i (in[0][componentNdx]);
15885 const fp16type n (in[1][componentNdx]);
15886 const double id (i.asDouble());
15887 const double nd (n.asDouble());
15888 const double qd (id * nd);
15891 dp = (componentNdx == 0) ? qd : dp + qd;
15896 const double eta2 (eta.asDouble() * eta.asDouble());
15897 const double dp2 (dp * dp);
15898 const double dp1 (1.0 - dp2);
15899 const double dpe (eta2 * dp1);
15900 const double k (1.0 - dpe);
15904 const fp16type zero (0.0);
15906 for (size_t componentNdx = 0; componentNdx < getOutCompCount(); ++componentNdx)
15907 out[componentNdx] = zero.bits();
15911 const double sk (deSqrt(k));
15913 for (size_t componentNdx = 0; componentNdx < getOutCompCount(); ++componentNdx)
15915 const fp16type i (in[0][componentNdx]);
15916 const fp16type n (in[1][componentNdx]);
15917 const double etai (i.asDouble() * eta.asDouble());
15918 const double etadp (eta.asDouble() * dp);
15919 const double etadpk (etadp + sk);
15920 const double etadpkn (etadpk * n.asDouble());
15921 const double full (etai - etadpkn);
15922 const fp16type result (full);
15924 if (result.isInf())
15927 out[componentNdx] = result.bits();
15935 for (size_t componentNdx = 0; componentNdx < getArgCompCount(1); ++componentNdx)
15937 const fp16type i (in[0][componentNdx]);
15938 const fp16type n (in[1][componentNdx]);
15939 const double id (i.asDouble());
15940 const double nd (n.asDouble());
15941 const fp16type q (id * nd);
15944 dp = (componentNdx == 0) ? q : fp16type(dp.asDouble() + q.asDouble());
15946 dp = fp16type(dp.asDouble() + q.asDouble());
15952 const fp16type eta2(eta.asDouble() * eta.asDouble());
15953 const fp16type dp2 (dp.asDouble() * dp.asDouble());
15954 const fp16type dp1 (1.0 - dp2.asDouble());
15955 const fp16type dpe (eta2.asDouble() * dp1.asDouble());
15956 const fp16type k (1.0 - dpe.asDouble());
15958 if (k.asDouble() < 0.0)
15960 const fp16type zero (0.0);
15962 for (size_t componentNdx = 0; componentNdx < getOutCompCount(); ++componentNdx)
15963 out[componentNdx] = zero.bits();
15967 const fp16type sk (deSqrt(k.asDouble()));
15969 for (size_t componentNdx = 0; componentNdx < getOutCompCount(); ++componentNdx)
15971 const fp16type i (in[0][componentNdx]);
15972 const fp16type n (in[1][componentNdx]);
15973 const fp16type etai (i.asDouble() * eta.asDouble());
15974 const fp16type etadp (eta.asDouble() * dp.asDouble());
15975 const fp16type etadpk (etadp.asDouble() + sk.asDouble());
15976 const fp16type etadpkn (etadpk.asDouble() * n.asDouble());
15977 const fp16type full (etai.asDouble() - etadpkn.asDouble());
15979 if (full.isNaN() || full.isInf())
15982 out[componentNdx] = full.bits();
15987 for (size_t ndx = 0; ndx < getOutCompCount(); ++ndx)
15988 min[ndx] = getMin(fp16type(out[ndx]).asDouble(), getULPs(in));
15989 for (size_t ndx = 0; ndx < getOutCompCount(); ++ndx)
15990 max[ndx] = getMax(fp16type(out[ndx]).asDouble(), getULPs(in));
15996 struct fp16Dot : public fp16AllComponents
15998 fp16Dot() : fp16AllComponents()
16000 flavorNames.push_back("EmulatingFP16");
16001 flavorNames.push_back("FloatCalc");
16002 flavorNames.push_back("DoubleCalc");
16004 // flavorNames will be extended later
16007 virtual void setArgCompCount (size_t argNo, size_t compCount)
16009 DE_ASSERT(argCompCount[argNo] == 0); // Once only
16011 if (argNo == 0 && argCompCount[argNo] == 0)
16013 const size_t maxPermutationsCount = 24u; // Equal to 4!
16014 std::vector<int> indices;
16016 for (size_t componentNdx = 0; componentNdx < compCount; ++componentNdx)
16017 indices.push_back(static_cast<int>(componentNdx));
16019 m_permutations.reserve(maxPermutationsCount);
16021 permutationsFlavorStart = flavorNames.size();
16025 tcu::UVec4 permutation;
16026 std::string name = "Permutted_";
16028 for (size_t componentNdx = 0; componentNdx < compCount; ++componentNdx)
16030 permutation[static_cast<int>(componentNdx)] = indices[componentNdx];
16031 name += de::toString(indices[componentNdx]);
16034 m_permutations.push_back(permutation);
16035 flavorNames.push_back(name);
16037 } while(std::next_permutation(indices.begin(), indices.end()));
16039 permutationsFlavorEnd = flavorNames.size();
16042 fp16AllComponents::setArgCompCount(argNo, compCount);
16045 virtual double getULPs(vector<const deFloat16*>& in)
16049 return 16.0; // This is not a precision test. Value is not from spec
16052 template<class fp16type>
16053 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
16055 DE_ASSERT(in.size() == 2);
16056 DE_ASSERT(getArgCompCount(0) == getArgCompCount(1));
16057 DE_ASSERT(getOutCompCount() == 1);
16059 double result (0.0);
16062 if (getFlavor() == 0)
16066 for (size_t componentNdx = 0; componentNdx < getArgCompCount(1); ++componentNdx)
16068 const fp16type x (in[0][componentNdx]);
16069 const fp16type y (in[1][componentNdx]);
16070 const fp16type q (x.asDouble() * y.asDouble());
16072 dp = fp16type(dp.asDouble() + q.asDouble());
16073 eps += floatFormat16.ulp(q.asDouble(), 2.0);
16076 result = dp.asDouble();
16078 else if (getFlavor() == 1)
16082 for (size_t componentNdx = 0; componentNdx < getArgCompCount(1); ++componentNdx)
16084 const fp16type x (in[0][componentNdx]);
16085 const fp16type y (in[1][componentNdx]);
16086 const float q (x.asFloat() * y.asFloat());
16089 eps += floatFormat16.ulp(static_cast<double>(q), 2.0);
16094 else if (getFlavor() == 2)
16098 for (size_t componentNdx = 0; componentNdx < getArgCompCount(1); ++componentNdx)
16100 const fp16type x (in[0][componentNdx]);
16101 const fp16type y (in[1][componentNdx]);
16102 const double q (x.asDouble() * y.asDouble());
16105 eps += floatFormat16.ulp(q, 2.0);
16110 else if (de::inBounds<size_t>(getFlavor(), permutationsFlavorStart, permutationsFlavorEnd))
16112 const int compCount (static_cast<int>(getArgCompCount(1)));
16113 const size_t permutationNdx (getFlavor() - permutationsFlavorStart);
16114 const tcu::UVec4& permutation (m_permutations[permutationNdx]);
16117 for (int permComponentNdx = 0; permComponentNdx < compCount; ++permComponentNdx)
16119 const size_t componentNdx (permutation[permComponentNdx]);
16120 const fp16type x (in[0][componentNdx]);
16121 const fp16type y (in[1][componentNdx]);
16122 const fp16type q (x.asDouble() * y.asDouble());
16124 dp = fp16type(dp.asDouble() + q.asDouble());
16125 eps += floatFormat16.ulp(q.asDouble(), 2.0);
16128 result = dp.asDouble();
16132 TCU_THROW(InternalError, "Unknown flavor");
16135 out[0] = fp16type(result).bits();
16136 min[0] = result - eps;
16137 max[0] = result + eps;
16143 std::vector<tcu::UVec4> m_permutations;
16144 size_t permutationsFlavorStart;
16145 size_t permutationsFlavorEnd;
16148 struct fp16VectorTimesScalar : public fp16AllComponents
16150 virtual double getULPs(vector<const deFloat16*>& in)
16157 template<class fp16type>
16158 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
16160 DE_ASSERT(in.size() == 2);
16161 DE_ASSERT(getArgCompCount(0) == getOutCompCount());
16162 DE_ASSERT(getArgCompCount(1) == 1);
16164 fp16type s (*in[1]);
16166 for (size_t componentNdx = 0; componentNdx < getArgCompCount(0); ++componentNdx)
16168 const fp16type x (in[0][componentNdx]);
16169 const double result (s.asDouble() * x.asDouble());
16170 const fp16type m (result);
16172 out[componentNdx] = m.bits();
16173 min[componentNdx] = getMin(result, getULPs(in));
16174 max[componentNdx] = getMax(result, getULPs(in));
16181 struct fp16MatrixBase : public fp16AllComponents
16183 deUint32 getComponentValidity ()
16185 return static_cast<deUint32>(-1);
16188 inline size_t getNdx (const size_t rowCount, const size_t col, const size_t row)
16190 const size_t minComponentCount = 0;
16191 const size_t maxComponentCount = 3;
16192 const size_t alignedRowsCount = (rowCount == 3) ? 4 : rowCount;
16194 DE_ASSERT(de::inRange(rowCount, minComponentCount + 1, maxComponentCount + 1));
16195 DE_ASSERT(de::inRange(col, minComponentCount, maxComponentCount));
16196 DE_ASSERT(de::inBounds(row, minComponentCount, rowCount));
16197 DE_UNREF(minComponentCount);
16198 DE_UNREF(maxComponentCount);
16200 return col * alignedRowsCount + row;
16203 deUint32 getComponentMatrixValidityMask (size_t cols, size_t rows)
16205 deUint32 result = 0u;
16207 for (size_t rowNdx = 0; rowNdx < rows; ++rowNdx)
16208 for (size_t colNdx = 0; colNdx < cols; ++colNdx)
16210 const size_t bitNdx = getNdx(rows, colNdx, rowNdx);
16212 DE_ASSERT(bitNdx < sizeof(result) * 8);
16214 result |= (1<<bitNdx);
16221 template<size_t cols, size_t rows>
16222 struct fp16Transpose : public fp16MatrixBase
16224 virtual double getULPs(vector<const deFloat16*>& in)
16231 deUint32 getComponentValidity ()
16233 return getComponentMatrixValidityMask(rows, cols);
16236 template<class fp16type>
16237 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
16239 DE_ASSERT(in.size() == 1);
16241 const size_t alignedCols = (cols == 3) ? 4 : cols;
16242 const size_t alignedRows = (rows == 3) ? 4 : rows;
16243 vector<deFloat16> output (alignedCols * alignedRows, 0);
16245 DE_ASSERT(output.size() == alignedCols * alignedRows);
16247 for (size_t rowNdx = 0; rowNdx < rows; ++rowNdx)
16248 for (size_t colNdx = 0; colNdx < cols; ++colNdx)
16249 output[rowNdx * alignedCols + colNdx] = in[0][colNdx * alignedRows + rowNdx];
16251 deMemcpy(out, &output[0], sizeof(deFloat16) * output.size());
16252 deMemcpy(min, &output[0], sizeof(deFloat16) * output.size());
16253 deMemcpy(max, &output[0], sizeof(deFloat16) * output.size());
16259 template<size_t cols, size_t rows>
16260 struct fp16MatrixTimesScalar : public fp16MatrixBase
16262 virtual double getULPs(vector<const deFloat16*>& in)
16269 deUint32 getComponentValidity ()
16271 return getComponentMatrixValidityMask(cols, rows);
16274 template<class fp16type>
16275 bool calc(vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
16277 DE_ASSERT(in.size() == 2);
16278 DE_ASSERT(getArgCompCount(1) == 1);
16280 const fp16type y (in[1][0]);
16281 const float scalar (y.asFloat());
16282 const size_t alignedCols = (cols == 3) ? 4 : cols;
16283 const size_t alignedRows = (rows == 3) ? 4 : rows;
16285 DE_ASSERT(getArgCompCount(0) == alignedCols * alignedRows);
16286 DE_ASSERT(getOutCompCount() == alignedCols * alignedRows);
16287 DE_UNREF(alignedCols);
16289 for (size_t rowNdx = 0; rowNdx < rows; ++rowNdx)
16290 for (size_t colNdx = 0; colNdx < cols; ++colNdx)
16292 const size_t ndx (colNdx * alignedRows + rowNdx);
16293 const fp16type x (in[0][ndx]);
16294 const double result (scalar * x.asFloat());
16296 out[ndx] = fp16type(result).bits();
16297 min[ndx] = getMin(result, getULPs(in));
16298 max[ndx] = getMax(result, getULPs(in));
16305 template<size_t cols, size_t rows>
16306 struct fp16VectorTimesMatrix : public fp16MatrixBase
16308 fp16VectorTimesMatrix() : fp16MatrixBase()
16310 flavorNames.push_back("EmulatingFP16");
16311 flavorNames.push_back("FloatCalc");
16314 virtual double getULPs (vector<const deFloat16*>& in)
16318 return (8.0 * cols);
16321 deUint32 getComponentValidity ()
16323 return getComponentMatrixValidityMask(cols, 1);
16326 template<class fp16type>
16327 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
16329 DE_ASSERT(in.size() == 2);
16331 const size_t alignedCols = (cols == 3) ? 4 : cols;
16332 const size_t alignedRows = (rows == 3) ? 4 : rows;
16334 DE_ASSERT(getOutCompCount() == cols);
16335 DE_ASSERT(getArgCompCount(0) == rows);
16336 DE_ASSERT(getArgCompCount(1) == alignedCols * alignedRows);
16337 DE_UNREF(alignedCols);
16339 if (getFlavor() == 0)
16341 for (size_t colNdx = 0; colNdx < cols; ++colNdx)
16343 fp16type s (fp16type::zero(1));
16345 for (size_t rowNdx = 0; rowNdx < rows; ++rowNdx)
16347 const fp16type v (in[0][rowNdx]);
16348 const float vf (v.asFloat());
16349 const size_t ndx (colNdx * alignedRows + rowNdx);
16350 const fp16type x (in[1][ndx]);
16351 const float xf (x.asFloat());
16352 const fp16type m (vf * xf);
16354 s = fp16type(s.asFloat() + m.asFloat());
16357 out[colNdx] = s.bits();
16358 min[colNdx] = getMin(s.asDouble(), getULPs(in));
16359 max[colNdx] = getMax(s.asDouble(), getULPs(in));
16362 else if (getFlavor() == 1)
16364 for (size_t colNdx = 0; colNdx < cols; ++colNdx)
16368 for (size_t rowNdx = 0; rowNdx < rows; ++rowNdx)
16370 const fp16type v (in[0][rowNdx]);
16371 const float vf (v.asFloat());
16372 const size_t ndx (colNdx * alignedRows + rowNdx);
16373 const fp16type x (in[1][ndx]);
16374 const float xf (x.asFloat());
16375 const float m (vf * xf);
16380 out[colNdx] = fp16type(s).bits();
16381 min[colNdx] = getMin(static_cast<double>(s), getULPs(in));
16382 max[colNdx] = getMax(static_cast<double>(s), getULPs(in));
16387 TCU_THROW(InternalError, "Unknown flavor");
16394 template<size_t cols, size_t rows>
16395 struct fp16MatrixTimesVector : public fp16MatrixBase
16397 fp16MatrixTimesVector() : fp16MatrixBase()
16399 flavorNames.push_back("EmulatingFP16");
16400 flavorNames.push_back("FloatCalc");
16403 virtual double getULPs (vector<const deFloat16*>& in)
16407 return (8.0 * rows);
16410 deUint32 getComponentValidity ()
16412 return getComponentMatrixValidityMask(rows, 1);
16415 template<class fp16type>
16416 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
16418 DE_ASSERT(in.size() == 2);
16420 const size_t alignedCols = (cols == 3) ? 4 : cols;
16421 const size_t alignedRows = (rows == 3) ? 4 : rows;
16423 DE_ASSERT(getOutCompCount() == rows);
16424 DE_ASSERT(getArgCompCount(0) == alignedCols * alignedRows);
16425 DE_ASSERT(getArgCompCount(1) == cols);
16426 DE_UNREF(alignedCols);
16428 if (getFlavor() == 0)
16430 for (size_t rowNdx = 0; rowNdx < rows; ++rowNdx)
16432 fp16type s (fp16type::zero(1));
16434 for (size_t colNdx = 0; colNdx < cols; ++colNdx)
16436 const size_t ndx (colNdx * alignedRows + rowNdx);
16437 const fp16type x (in[0][ndx]);
16438 const float xf (x.asFloat());
16439 const fp16type v (in[1][colNdx]);
16440 const float vf (v.asFloat());
16441 const fp16type m (vf * xf);
16443 s = fp16type(s.asFloat() + m.asFloat());
16446 out[rowNdx] = s.bits();
16447 min[rowNdx] = getMin(s.asDouble(), getULPs(in));
16448 max[rowNdx] = getMax(s.asDouble(), getULPs(in));
16451 else if (getFlavor() == 1)
16453 for (size_t rowNdx = 0; rowNdx < rows; ++rowNdx)
16457 for (size_t colNdx = 0; colNdx < cols; ++colNdx)
16459 const size_t ndx (colNdx * alignedRows + rowNdx);
16460 const fp16type x (in[0][ndx]);
16461 const float xf (x.asFloat());
16462 const fp16type v (in[1][colNdx]);
16463 const float vf (v.asFloat());
16464 const float m (vf * xf);
16469 out[rowNdx] = fp16type(s).bits();
16470 min[rowNdx] = getMin(static_cast<double>(s), getULPs(in));
16471 max[rowNdx] = getMax(static_cast<double>(s), getULPs(in));
16476 TCU_THROW(InternalError, "Unknown flavor");
16483 template<size_t colsL, size_t rowsL, size_t colsR, size_t rowsR>
16484 struct fp16MatrixTimesMatrix : public fp16MatrixBase
16486 fp16MatrixTimesMatrix() : fp16MatrixBase()
16488 flavorNames.push_back("EmulatingFP16");
16489 flavorNames.push_back("FloatCalc");
16492 virtual double getULPs (vector<const deFloat16*>& in)
16499 deUint32 getComponentValidity ()
16501 return getComponentMatrixValidityMask(colsR, rowsL);
16504 template<class fp16type>
16505 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
16507 DE_STATIC_ASSERT(colsL == rowsR);
16509 DE_ASSERT(in.size() == 2);
16511 const size_t alignedColsL = (colsL == 3) ? 4 : colsL;
16512 const size_t alignedRowsL = (rowsL == 3) ? 4 : rowsL;
16513 const size_t alignedColsR = (colsR == 3) ? 4 : colsR;
16514 const size_t alignedRowsR = (rowsR == 3) ? 4 : rowsR;
16516 DE_ASSERT(getOutCompCount() == alignedColsR * alignedRowsL);
16517 DE_ASSERT(getArgCompCount(0) == alignedColsL * alignedRowsL);
16518 DE_ASSERT(getArgCompCount(1) == alignedColsR * alignedRowsR);
16519 DE_UNREF(alignedColsL);
16520 DE_UNREF(alignedColsR);
16522 if (getFlavor() == 0)
16524 for (size_t rowNdx = 0; rowNdx < rowsL; ++rowNdx)
16526 for (size_t colNdx = 0; colNdx < colsR; ++colNdx)
16528 const size_t ndx (colNdx * alignedRowsL + rowNdx);
16529 fp16type s (fp16type::zero(1));
16531 for (size_t commonNdx = 0; commonNdx < colsL; ++commonNdx)
16533 const size_t ndxl (commonNdx * alignedRowsL + rowNdx);
16534 const fp16type l (in[0][ndxl]);
16535 const float lf (l.asFloat());
16536 const size_t ndxr (colNdx * alignedRowsR + commonNdx);
16537 const fp16type r (in[1][ndxr]);
16538 const float rf (r.asFloat());
16539 const fp16type m (lf * rf);
16541 s = fp16type(s.asFloat() + m.asFloat());
16544 out[ndx] = s.bits();
16545 min[ndx] = getMin(s.asDouble(), getULPs(in));
16546 max[ndx] = getMax(s.asDouble(), getULPs(in));
16550 else if (getFlavor() == 1)
16552 for (size_t rowNdx = 0; rowNdx < rowsL; ++rowNdx)
16554 for (size_t colNdx = 0; colNdx < colsR; ++colNdx)
16556 const size_t ndx (colNdx * alignedRowsL + rowNdx);
16559 for (size_t commonNdx = 0; commonNdx < colsL; ++commonNdx)
16561 const size_t ndxl (commonNdx * alignedRowsL + rowNdx);
16562 const fp16type l (in[0][ndxl]);
16563 const float lf (l.asFloat());
16564 const size_t ndxr (colNdx * alignedRowsR + commonNdx);
16565 const fp16type r (in[1][ndxr]);
16566 const float rf (r.asFloat());
16567 const float m (lf * rf);
16572 out[ndx] = fp16type(s).bits();
16573 min[ndx] = getMin(static_cast<double>(s), getULPs(in));
16574 max[ndx] = getMax(static_cast<double>(s), getULPs(in));
16580 TCU_THROW(InternalError, "Unknown flavor");
16587 template<size_t cols, size_t rows>
16588 struct fp16OuterProduct : public fp16MatrixBase
16590 virtual double getULPs (vector<const deFloat16*>& in)
16597 deUint32 getComponentValidity ()
16599 return getComponentMatrixValidityMask(cols, rows);
16602 template<class fp16type>
16603 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
16605 DE_ASSERT(in.size() == 2);
16607 const size_t alignedCols = (cols == 3) ? 4 : cols;
16608 const size_t alignedRows = (rows == 3) ? 4 : rows;
16610 DE_ASSERT(getArgCompCount(0) == rows);
16611 DE_ASSERT(getArgCompCount(1) == cols);
16612 DE_ASSERT(getOutCompCount() == alignedCols * alignedRows);
16613 DE_UNREF(alignedCols);
16615 for (size_t rowNdx = 0; rowNdx < rows; ++rowNdx)
16617 for (size_t colNdx = 0; colNdx < cols; ++colNdx)
16619 const size_t ndx (colNdx * alignedRows + rowNdx);
16620 const fp16type x (in[0][rowNdx]);
16621 const float xf (x.asFloat());
16622 const fp16type y (in[1][colNdx]);
16623 const float yf (y.asFloat());
16624 const fp16type m (xf * yf);
16626 out[ndx] = m.bits();
16627 min[ndx] = getMin(m.asDouble(), getULPs(in));
16628 max[ndx] = getMax(m.asDouble(), getULPs(in));
16636 template<size_t size>
16637 struct fp16Determinant;
16640 struct fp16Determinant<2> : public fp16MatrixBase
16642 virtual double getULPs (vector<const deFloat16*>& in)
16646 return 128.0; // This is not a precision test. Value is not from spec
16649 deUint32 getComponentValidity ()
16654 template<class fp16type>
16655 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
16657 const size_t cols = 2;
16658 const size_t rows = 2;
16659 const size_t alignedCols = (cols == 3) ? 4 : cols;
16660 const size_t alignedRows = (rows == 3) ? 4 : rows;
16662 DE_ASSERT(in.size() == 1);
16663 DE_ASSERT(getOutCompCount() == 1);
16664 DE_ASSERT(getArgCompCount(0) == alignedRows * alignedCols);
16665 DE_UNREF(alignedCols);
16666 DE_UNREF(alignedRows);
16670 const float a (fp16type(in[0][getNdx(rows, 0, 0)]).asFloat());
16671 const float b (fp16type(in[0][getNdx(rows, 1, 0)]).asFloat());
16672 const float c (fp16type(in[0][getNdx(rows, 0, 1)]).asFloat());
16673 const float d (fp16type(in[0][getNdx(rows, 1, 1)]).asFloat());
16674 const float ad (a * d);
16675 const fp16type adf16 (ad);
16676 const float bc (b * c);
16677 const fp16type bcf16 (bc);
16678 const float r (adf16.asFloat() - bcf16.asFloat());
16679 const fp16type rf16 (r);
16681 out[0] = rf16.bits();
16682 min[0] = getMin(r, getULPs(in));
16683 max[0] = getMax(r, getULPs(in));
16690 struct fp16Determinant<3> : public fp16MatrixBase
16692 virtual double getULPs (vector<const deFloat16*>& in)
16696 return 128.0; // This is not a precision test. Value is not from spec
16699 deUint32 getComponentValidity ()
16704 template<class fp16type>
16705 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
16707 const size_t cols = 3;
16708 const size_t rows = 3;
16709 const size_t alignedCols = (cols == 3) ? 4 : cols;
16710 const size_t alignedRows = (rows == 3) ? 4 : rows;
16712 DE_ASSERT(in.size() == 1);
16713 DE_ASSERT(getOutCompCount() == 1);
16714 DE_ASSERT(getArgCompCount(0) == alignedRows * alignedCols);
16715 DE_UNREF(alignedCols);
16716 DE_UNREF(alignedRows);
16721 const float a (fp16type(in[0][getNdx(rows, 0, 0)]).asFloat());
16722 const float b (fp16type(in[0][getNdx(rows, 1, 0)]).asFloat());
16723 const float c (fp16type(in[0][getNdx(rows, 2, 0)]).asFloat());
16724 const float d (fp16type(in[0][getNdx(rows, 0, 1)]).asFloat());
16725 const float e (fp16type(in[0][getNdx(rows, 1, 1)]).asFloat());
16726 const float f (fp16type(in[0][getNdx(rows, 2, 1)]).asFloat());
16727 const float g (fp16type(in[0][getNdx(rows, 0, 2)]).asFloat());
16728 const float h (fp16type(in[0][getNdx(rows, 1, 2)]).asFloat());
16729 const float i (fp16type(in[0][getNdx(rows, 2, 2)]).asFloat());
16730 const fp16type aei (a * e * i);
16731 const fp16type bfg (b * f * g);
16732 const fp16type cdh (c * d * h);
16733 const fp16type ceg (c * e * g);
16734 const fp16type bdi (b * d * i);
16735 const fp16type afh (a * f * h);
16736 const float r (aei.asFloat() + bfg.asFloat() + cdh.asFloat() - ceg.asFloat() - bdi.asFloat() - afh.asFloat());
16737 const fp16type rf16 (r);
16739 out[0] = rf16.bits();
16740 min[0] = getMin(r, getULPs(in));
16741 max[0] = getMax(r, getULPs(in));
16748 struct fp16Determinant<4> : public fp16MatrixBase
16750 virtual double getULPs (vector<const deFloat16*>& in)
16754 return 128.0; // This is not a precision test. Value is not from spec
16757 deUint32 getComponentValidity ()
16762 template<class fp16type>
16763 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
16765 const size_t rows = 4;
16766 const size_t cols = 4;
16767 const size_t alignedCols = (cols == 3) ? 4 : cols;
16768 const size_t alignedRows = (rows == 3) ? 4 : rows;
16770 DE_ASSERT(in.size() == 1);
16771 DE_ASSERT(getOutCompCount() == 1);
16772 DE_ASSERT(getArgCompCount(0) == alignedRows * alignedCols);
16773 DE_UNREF(alignedCols);
16774 DE_UNREF(alignedRows);
16780 const float a (fp16type(in[0][getNdx(rows, 0, 0)]).asFloat());
16781 const float b (fp16type(in[0][getNdx(rows, 1, 0)]).asFloat());
16782 const float c (fp16type(in[0][getNdx(rows, 2, 0)]).asFloat());
16783 const float d (fp16type(in[0][getNdx(rows, 3, 0)]).asFloat());
16784 const float e (fp16type(in[0][getNdx(rows, 0, 1)]).asFloat());
16785 const float f (fp16type(in[0][getNdx(rows, 1, 1)]).asFloat());
16786 const float g (fp16type(in[0][getNdx(rows, 2, 1)]).asFloat());
16787 const float h (fp16type(in[0][getNdx(rows, 3, 1)]).asFloat());
16788 const float i (fp16type(in[0][getNdx(rows, 0, 2)]).asFloat());
16789 const float j (fp16type(in[0][getNdx(rows, 1, 2)]).asFloat());
16790 const float k (fp16type(in[0][getNdx(rows, 2, 2)]).asFloat());
16791 const float l (fp16type(in[0][getNdx(rows, 3, 2)]).asFloat());
16792 const float m (fp16type(in[0][getNdx(rows, 0, 3)]).asFloat());
16793 const float n (fp16type(in[0][getNdx(rows, 1, 3)]).asFloat());
16794 const float o (fp16type(in[0][getNdx(rows, 2, 3)]).asFloat());
16795 const float p (fp16type(in[0][getNdx(rows, 3, 3)]).asFloat());
16800 const fp16type fkp (f * k * p);
16801 const fp16type gln (g * l * n);
16802 const fp16type hjo (h * j * o);
16803 const fp16type hkn (h * k * n);
16804 const fp16type gjp (g * j * p);
16805 const fp16type flo (f * l * o);
16806 const fp16type detA (a * (fkp.asFloat() + gln.asFloat() + hjo.asFloat() - hkn.asFloat() - gjp.asFloat() - flo.asFloat()));
16811 const fp16type ekp (e * k * p);
16812 const fp16type glm (g * l * m);
16813 const fp16type hio (h * i * o);
16814 const fp16type hkm (h * k * m);
16815 const fp16type gip (g * i * p);
16816 const fp16type elo (e * l * o);
16817 const fp16type detB (b * (ekp.asFloat() + glm.asFloat() + hio.asFloat() - hkm.asFloat() - gip.asFloat() - elo.asFloat()));
16822 const fp16type ejp (e * j * p);
16823 const fp16type flm (f * l * m);
16824 const fp16type hin (h * i * n);
16825 const fp16type hjm (h * j * m);
16826 const fp16type fip (f * i * p);
16827 const fp16type eln (e * l * n);
16828 const fp16type detC (c * (ejp.asFloat() + flm.asFloat() + hin.asFloat() - hjm.asFloat() - fip.asFloat() - eln.asFloat()));
16833 const fp16type ejo (e * j * o);
16834 const fp16type fkm (f * k * m);
16835 const fp16type gin (g * i * n);
16836 const fp16type gjm (g * j * m);
16837 const fp16type fio (f * i * o);
16838 const fp16type ekn (e * k * n);
16839 const fp16type detD (d * (ejo.asFloat() + fkm.asFloat() + gin.asFloat() - gjm.asFloat() - fio.asFloat() - ekn.asFloat()));
16841 const float r (detA.asFloat() - detB.asFloat() + detC.asFloat() - detD.asFloat());
16842 const fp16type rf16 (r);
16844 out[0] = rf16.bits();
16845 min[0] = getMin(r, getULPs(in));
16846 max[0] = getMax(r, getULPs(in));
16852 template<size_t size>
16853 struct fp16Inverse;
16856 struct fp16Inverse<2> : public fp16MatrixBase
16858 virtual double getULPs (vector<const deFloat16*>& in)
16862 return 128.0; // This is not a precision test. Value is not from spec
16865 deUint32 getComponentValidity ()
16867 return getComponentMatrixValidityMask(2, 2);
16870 template<class fp16type>
16871 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
16873 const size_t cols = 2;
16874 const size_t rows = 2;
16875 const size_t alignedCols = (cols == 3) ? 4 : cols;
16876 const size_t alignedRows = (rows == 3) ? 4 : rows;
16878 DE_ASSERT(in.size() == 1);
16879 DE_ASSERT(getOutCompCount() == alignedRows * alignedCols);
16880 DE_ASSERT(getArgCompCount(0) == alignedRows * alignedCols);
16881 DE_UNREF(alignedCols);
16885 const float a (fp16type(in[0][getNdx(rows, 0, 0)]).asFloat());
16886 const float b (fp16type(in[0][getNdx(rows, 1, 0)]).asFloat());
16887 const float c (fp16type(in[0][getNdx(rows, 0, 1)]).asFloat());
16888 const float d (fp16type(in[0][getNdx(rows, 1, 1)]).asFloat());
16889 const float ad (a * d);
16890 const fp16type adf16 (ad);
16891 const float bc (b * c);
16892 const fp16type bcf16 (bc);
16893 const float det (adf16.asFloat() - bcf16.asFloat());
16894 const fp16type det16 (det);
16896 out[0] = fp16type( d / det16.asFloat()).bits();
16897 out[1] = fp16type(-c / det16.asFloat()).bits();
16898 out[2] = fp16type(-b / det16.asFloat()).bits();
16899 out[3] = fp16type( a / det16.asFloat()).bits();
16901 for (size_t rowNdx = 0; rowNdx < rows; ++rowNdx)
16902 for (size_t colNdx = 0; colNdx < cols; ++colNdx)
16904 const size_t ndx (colNdx * alignedRows + rowNdx);
16905 const fp16type s (out[ndx]);
16907 min[ndx] = getMin(s.asDouble(), getULPs(in));
16908 max[ndx] = getMax(s.asDouble(), getULPs(in));
16915 inline std::string fp16ToString(deFloat16 val)
16917 return tcu::toHex<4>(val).toString() + " (" + de::floatToString(tcu::Float16(val).asFloat(), 10) + ")";
16920 template <size_t RES_COMPONENTS, size_t ARG0_COMPONENTS, size_t ARG1_COMPONENTS, size_t ARG2_COMPONENTS, class TestedArithmeticFunction>
16921 bool compareFP16ArithmeticFunc (const std::vector<Resource>& inputs, const vector<AllocationSp>& outputAllocs, const std::vector<Resource>& expectedOutputs, TestLog& log)
16923 if (inputs.size() < 1 || inputs.size() > 3 || outputAllocs.size() != 1 || expectedOutputs.size() != 1)
16926 const size_t resultStep = (RES_COMPONENTS == 3) ? 4 : RES_COMPONENTS;
16927 const size_t iterationsCount = expectedOutputs[0].getByteSize() / (sizeof(deFloat16) * resultStep);
16928 const size_t inputsSteps[3] =
16930 (ARG0_COMPONENTS == 3) ? 4 : ARG0_COMPONENTS,
16931 (ARG1_COMPONENTS == 3) ? 4 : ARG1_COMPONENTS,
16932 (ARG2_COMPONENTS == 3) ? 4 : ARG2_COMPONENTS,
16935 DE_ASSERT(expectedOutputs[0].getByteSize() > 0);
16936 DE_ASSERT(expectedOutputs[0].getByteSize() == sizeof(deFloat16) * iterationsCount * resultStep);
16938 for (size_t inputNdx = 0; inputNdx < inputs.size(); ++inputNdx)
16940 DE_ASSERT(inputs[inputNdx].getByteSize() > 0);
16941 DE_ASSERT(inputs[inputNdx].getByteSize() == sizeof(deFloat16) * iterationsCount * inputsSteps[inputNdx]);
16944 const deFloat16* const outputAsFP16 = (const deFloat16*)outputAllocs[0]->getHostPtr();
16945 TestedArithmeticFunction func;
16947 func.setOutCompCount(RES_COMPONENTS);
16948 func.setArgCompCount(0, ARG0_COMPONENTS);
16949 func.setArgCompCount(1, ARG1_COMPONENTS);
16950 func.setArgCompCount(2, ARG2_COMPONENTS);
16952 const bool callOncePerComponent = func.callOncePerComponent();
16953 const deUint32 componentValidityMask = func.getComponentValidity();
16954 const size_t denormModesCount = 2;
16955 const char* denormModes[denormModesCount] = { "keep denormal numbers", "flush to zero" };
16956 const size_t successfulRunsPerComponent = denormModesCount * func.getFlavorCount();
16957 bool success = true;
16958 size_t validatedCount = 0;
16960 vector<deUint8> inputBytes[3];
16962 for (size_t inputNdx = 0; inputNdx < inputs.size(); ++inputNdx)
16963 inputs[inputNdx].getBytes(inputBytes[inputNdx]);
16965 const deFloat16* const inputsAsFP16[3] =
16967 inputs.size() >= 1 ? (const deFloat16*)&inputBytes[0][0] : DE_NULL,
16968 inputs.size() >= 2 ? (const deFloat16*)&inputBytes[1][0] : DE_NULL,
16969 inputs.size() >= 3 ? (const deFloat16*)&inputBytes[2][0] : DE_NULL,
16972 for (size_t idx = 0; idx < iterationsCount; ++idx)
16974 std::vector<size_t> successfulRuns (RES_COMPONENTS, successfulRunsPerComponent);
16975 std::vector<std::string> errors (RES_COMPONENTS);
16976 bool iterationValidated (true);
16978 for (size_t denormNdx = 0; denormNdx < 2; ++denormNdx)
16980 for (size_t flavorNdx = 0; flavorNdx < func.getFlavorCount(); ++flavorNdx)
16982 func.setFlavor(flavorNdx);
16984 const deFloat16* iterationOutputFP16 = &outputAsFP16[idx * resultStep];
16985 vector<deFloat16> iterationCalculatedFP16 (resultStep, 0);
16986 vector<double> iterationEdgeMin (resultStep, 0.0);
16987 vector<double> iterationEdgeMax (resultStep, 0.0);
16988 vector<const deFloat16*> arguments;
16990 for (size_t componentNdx = 0; componentNdx < RES_COMPONENTS; ++componentNdx)
16993 bool reportError = false;
16995 if (callOncePerComponent || componentNdx == 0)
16997 bool funcCallResult;
17001 for (size_t inputNdx = 0; inputNdx < inputs.size(); ++inputNdx)
17002 arguments.push_back(&inputsAsFP16[inputNdx][idx * inputsSteps[inputNdx] + componentNdx]);
17004 if (denormNdx == 0)
17005 funcCallResult = func.template calc<tcu::Float16>(arguments, &iterationCalculatedFP16[componentNdx], &iterationEdgeMin[componentNdx], &iterationEdgeMax[componentNdx]);
17007 funcCallResult = func.template calc<tcu::Float16Denormless>(arguments, &iterationCalculatedFP16[componentNdx], &iterationEdgeMin[componentNdx], &iterationEdgeMax[componentNdx]);
17009 if (!funcCallResult)
17011 iterationValidated = false;
17013 if (callOncePerComponent)
17020 if ((componentValidityMask != 0) && (componentValidityMask & (1<<componentNdx)) == 0)
17023 reportError = !compare16BitFloat(iterationCalculatedFP16[componentNdx], iterationOutputFP16[componentNdx], error);
17027 tcu::Float16 expected (iterationCalculatedFP16[componentNdx]);
17028 tcu::Float16 outputted (iterationOutputFP16[componentNdx]);
17030 if (reportError && expected.isNaN())
17031 reportError = false;
17033 if (reportError && !expected.isNaN() && !outputted.isNaN())
17035 if (reportError && !expected.isInf() && !outputted.isInf())
17038 if (expected.bits() == outputted.bits() + 1 || expected.bits() + 1 == outputted.bits())
17039 reportError = false;
17042 if (reportError && expected.isInf())
17044 // RTZ rounding mode returns +/-65504 instead of Inf on overflow
17045 if (expected.sign() == 1 && outputted.bits() == 0x7bff && iterationEdgeMin[componentNdx] <= std::numeric_limits<double>::max())
17046 reportError = false;
17047 else if (expected.sign() == -1 && outputted.bits() == 0xfbff && iterationEdgeMax[componentNdx] >= -std::numeric_limits<double>::max())
17048 reportError = false;
17053 const double outputtedDouble = outputted.asDouble();
17055 DE_ASSERT(iterationEdgeMin[componentNdx] <= iterationEdgeMax[componentNdx]);
17057 if (de::inRange(outputtedDouble, iterationEdgeMin[componentNdx], iterationEdgeMax[componentNdx]))
17058 reportError = false;
17064 const size_t inputsComps[3] =
17070 string inputsValues ("Inputs:");
17071 string flavorName (func.getFlavorCount() == 1 ? "" : string(" flavor ") + de::toString(flavorNdx) + " (" + func.getCurrentFlavorName() + ")");
17072 std::stringstream errStream;
17074 for (size_t inputNdx = 0; inputNdx < inputs.size(); ++inputNdx)
17076 const size_t inputCompsCount = inputsComps[inputNdx];
17078 inputsValues += " [" + de::toString(inputNdx) + "]=(";
17080 for (size_t compNdx = 0; compNdx < inputCompsCount; ++compNdx)
17082 const deFloat16 inputComponentValue = inputsAsFP16[inputNdx][idx * inputsSteps[inputNdx] + compNdx];
17084 inputsValues += fp16ToString(inputComponentValue) + ((compNdx + 1 == inputCompsCount) ? ")": ", ");
17089 << " iteration " << de::toString(idx)
17090 << " component " << de::toString(componentNdx)
17091 << " denormMode " << de::toString(denormNdx)
17092 << " (" << denormModes[denormNdx] << ")"
17093 << " " << flavorName
17094 << " " << inputsValues
17095 << " outputted:" + fp16ToString(iterationOutputFP16[componentNdx])
17096 << " expected:" + fp16ToString(iterationCalculatedFP16[componentNdx])
17097 << " or in range: [" << iterationEdgeMin[componentNdx] << ", " << iterationEdgeMax[componentNdx] << "]."
17098 << " " << error << "."
17101 errors[componentNdx] += errStream.str();
17103 successfulRuns[componentNdx]--;
17110 for (size_t componentNdx = 0; componentNdx < RES_COMPONENTS; ++componentNdx)
17112 // Check if any component has total failure
17113 if (successfulRuns[componentNdx] == 0)
17115 // Test failed in all denorm modes and all flavors for certain component: dump errors
17116 log << TestLog::Message << errors[componentNdx] << TestLog::EndMessage;
17122 if (iterationValidated)
17126 if (validatedCount < 16)
17127 TCU_THROW(InternalError, "Too few samples has been validated.");
17132 // IEEE-754 floating point numbers:
17133 // +--------+------+----------+-------------+
17134 // | binary | sign | exponent | significand |
17135 // +--------+------+----------+-------------+
17136 // | 16-bit | 1 | 5 | 10 |
17137 // +--------+------+----------+-------------+
17138 // | 32-bit | 1 | 8 | 23 |
17139 // +--------+------+----------+-------------+
17143 // 0 000 00 00 0000 0001 (0x0001: 2e-24: minimum positive denormalized)
17144 // 0 000 00 11 1111 1111 (0x03ff: 2e-14 - 2e-24: maximum positive denormalized)
17145 // 0 000 01 00 0000 0000 (0x0400: 2e-14: minimum positive normalized)
17146 // 0 111 10 11 1111 1111 (0x7bff: 65504: maximum positive normalized)
17148 // 0 000 00 00 0000 0000 (0x0000: +0)
17149 // 0 111 11 00 0000 0000 (0x7c00: +Inf)
17150 // 0 000 00 11 1111 0000 (0x03f0: +Denorm)
17151 // 0 000 01 00 0000 0001 (0x0401: +Norm)
17152 // 0 111 11 00 0000 1111 (0x7c0f: +SNaN)
17153 // 0 111 11 11 1111 0000 (0x7ff0: +QNaN)
17154 // Generate and return 16-bit floats and their corresponding 32-bit values.
17156 // The first 14 number pairs are manually picked, while the rest are randomly generated.
17157 // Expected count to be at least 14 (numPicks).
17158 vector<deFloat16> getFloat16a (de::Random& rnd, deUint32 count)
17160 vector<deFloat16> float16;
17162 float16.reserve(count);
17165 float16.push_back(deUint16(0x0000));
17166 float16.push_back(deUint16(0x8000));
17168 float16.push_back(deUint16(0x7c00));
17169 float16.push_back(deUint16(0xfc00));
17171 float16.push_back(deUint16(0x0401));
17172 float16.push_back(deUint16(0x8401));
17173 // Some normal number
17174 float16.push_back(deUint16(0x14cb));
17175 float16.push_back(deUint16(0x94cb));
17176 // Min/max positive normal
17177 float16.push_back(deUint16(0x0400));
17178 float16.push_back(deUint16(0x7bff));
17179 // Min/max negative normal
17180 float16.push_back(deUint16(0x8400));
17181 float16.push_back(deUint16(0xfbff));
17183 float16.push_back(deUint16(0x4248)); // 3.140625
17184 float16.push_back(deUint16(0xb248)); // -3.140625
17186 float16.push_back(deUint16(0x3e48)); // 1.5703125
17187 float16.push_back(deUint16(0xbe48)); // -1.5703125
17188 float16.push_back(deUint16(0x3c00)); // 1.0
17189 float16.push_back(deUint16(0x3800)); // 0.5
17190 // Some useful constants
17191 float16.push_back(tcu::Float16(-2.5f).bits());
17192 float16.push_back(tcu::Float16(-1.0f).bits());
17193 float16.push_back(tcu::Float16( 0.4f).bits());
17194 float16.push_back(tcu::Float16( 2.5f).bits());
17196 const deUint32 numPicks = static_cast<deUint32>(float16.size());
17198 DE_ASSERT(count >= numPicks);
17201 for (deUint32 numIdx = 0; numIdx < count; ++numIdx)
17203 int sign = (rnd.getUint16() % 2 == 0) ? +1 : -1;
17204 int exponent = (rnd.getUint16() % 29) - 14 + 1;
17205 deUint16 mantissa = static_cast<deUint16>(2 * (rnd.getUint16() % 512));
17207 // Exclude power of -14 to avoid denorms
17208 DE_ASSERT(de::inRange(exponent, -13, 15));
17210 float16.push_back(tcu::Float16::constructBits(sign, exponent, mantissa).bits());
17216 static inline vector<deFloat16> getInputData1 (deUint32 seed, size_t count, size_t argNo)
17220 de::Random rnd(seed);
17222 return getFloat16a(rnd, static_cast<deUint32>(count));
17225 static inline vector<deFloat16> getInputData2 (deUint32 seed, size_t count, size_t argNo)
17227 de::Random rnd (seed);
17228 size_t newCount = static_cast<size_t>(deSqrt(double(count)));
17230 DE_ASSERT(newCount * newCount == count);
17232 vector<deFloat16> float16 = getFloat16a(rnd, static_cast<deUint32>(newCount));
17234 return squarize(float16, static_cast<deUint32>(argNo));
17237 static inline vector<deFloat16> getInputData3 (deUint32 seed, size_t count, size_t argNo)
17239 if (argNo == 0 || argNo == 1)
17240 return getInputData2(seed, count, argNo);
17242 return getInputData1(seed<<argNo, count, argNo);
17245 vector<deFloat16> getInputData (deUint32 seed, size_t count, size_t compCount, size_t stride, size_t argCount, size_t argNo)
17249 vector<deFloat16> result;
17253 case 1:result = getInputData1(seed, count, argNo); break;
17254 case 2:result = getInputData2(seed, count, argNo); break;
17255 case 3:result = getInputData3(seed, count, argNo); break;
17256 default: TCU_THROW(InternalError, "Invalid argument count specified");
17259 if (compCount == 3)
17261 const size_t newCount = (3 * count) / 4;
17262 vector<deFloat16> newResult;
17264 newResult.reserve(result.size());
17266 for (size_t ndx = 0; ndx < newCount; ++ndx)
17268 newResult.push_back(result[ndx]);
17271 newResult.push_back(0);
17274 result = newResult;
17277 DE_ASSERT(result.size() == count);
17282 // Generator for functions requiring data in range [1, inf]
17283 vector<deFloat16> getInputDataAC (deUint32 seed, size_t count, size_t compCount, size_t stride, size_t argCount, size_t argNo)
17285 vector<deFloat16> result;
17287 result = getInputData(seed, count, compCount, stride, argCount, argNo);
17289 // Filter out values below 1.0 from upper half of numbers
17290 for (size_t idx = result.size() / 2; idx < result.size(); ++idx)
17292 const float f = tcu::Float16(result[idx]).asFloat();
17295 result[idx] = tcu::Float16(1.0f - f).bits();
17301 // Generator for functions requiring data in range [-1, 1]
17302 vector<deFloat16> getInputDataA (deUint32 seed, size_t count, size_t compCount, size_t stride, size_t argCount, size_t argNo)
17304 vector<deFloat16> result;
17306 result = getInputData(seed, count, compCount, stride, argCount, argNo);
17308 for (size_t idx = result.size() / 2; idx < result.size(); ++idx)
17310 const float f = tcu::Float16(result[idx]).asFloat();
17312 if (!de::inRange(f, -1.0f, 1.0f))
17313 result[idx] = tcu::Float16(deFloatFrac(f)).bits();
17319 // Generator for functions requiring data in range [-pi, pi]
17320 vector<deFloat16> getInputDataPI (deUint32 seed, size_t count, size_t compCount, size_t stride, size_t argCount, size_t argNo)
17322 vector<deFloat16> result;
17324 result = getInputData(seed, count, compCount, stride, argCount, argNo);
17326 for (size_t idx = result.size() / 2; idx < result.size(); ++idx)
17328 const float f = tcu::Float16(result[idx]).asFloat();
17330 if (!de::inRange(f, -DE_PI, DE_PI))
17331 result[idx] = tcu::Float16(fmodf(f, DE_PI)).bits();
17337 // Generator for functions requiring data in range [0, inf]
17338 vector<deFloat16> getInputDataP (deUint32 seed, size_t count, size_t compCount, size_t stride, size_t argCount, size_t argNo)
17340 vector<deFloat16> result;
17342 result = getInputData(seed, count, compCount, stride, argCount, argNo);
17346 for (size_t idx = result.size() / 2; idx < result.size(); ++idx)
17347 result[idx] &= static_cast<deFloat16>(~0x8000);
17353 vector<deFloat16> getInputDataV (deUint32 seed, size_t count, size_t compCount, size_t stride, size_t argCount, size_t argNo)
17356 DE_UNREF(argCount);
17358 vector<deFloat16> result;
17361 result = getInputData2(seed, count, argNo);
17364 const size_t alignedCount = (compCount == 3) ? 4 : compCount;
17365 const size_t newCountX = static_cast<size_t>(deSqrt(double(count * alignedCount)));
17366 const size_t newCountY = count / newCountX;
17367 de::Random rnd (seed);
17368 vector<deFloat16> float16 = getFloat16a(rnd, static_cast<deUint32>(newCountX));
17370 DE_ASSERT(newCountX * newCountX == alignedCount * count);
17372 for (size_t numIdx = 0; numIdx < newCountX; ++numIdx)
17374 const vector<deFloat16> tmp(newCountY, float16[numIdx]);
17376 result.insert(result.end(), tmp.begin(), tmp.end());
17380 DE_ASSERT(result.size() == count);
17385 vector<deFloat16> getInputDataM (deUint32 seed, size_t count, size_t compCount, size_t stride, size_t argCount, size_t argNo)
17387 DE_UNREF(compCount);
17389 DE_UNREF(argCount);
17391 de::Random rnd (seed << argNo);
17392 vector<deFloat16> result;
17394 result = getFloat16a(rnd, static_cast<deUint32>(count));
17396 DE_ASSERT(result.size() == count);
17401 vector<deFloat16> getInputDataD (deUint32 seed, size_t count, size_t compCount, size_t stride, size_t argCount, size_t argNo)
17403 DE_UNREF(compCount);
17404 DE_UNREF(argCount);
17406 de::Random rnd (seed << argNo);
17407 vector<deFloat16> result;
17409 for (deUint32 numIdx = 0; numIdx < count; ++numIdx)
17411 int num = (rnd.getUint16() % 16) - 8;
17413 result.push_back(tcu::Float16(float(num)).bits());
17416 result[0 * stride] = deUint16(0x7c00); // +Inf
17417 result[1 * stride] = deUint16(0xfc00); // -Inf
17419 DE_ASSERT(result.size() == count);
17424 // Generator for smoothstep function
17425 vector<deFloat16> getInputDataSS (deUint32 seed, size_t count, size_t compCount, size_t stride, size_t argCount, size_t argNo)
17427 vector<deFloat16> result;
17429 result = getInputDataD(seed, count, compCount, stride, argCount, argNo);
17433 for (size_t idx = result.size() / 2; idx < result.size(); ++idx)
17435 const float f = tcu::Float16(result[idx]).asFloat();
17438 result[idx] = tcu::Float16(-f).bits();
17444 for (size_t idx = result.size() / 2; idx < result.size(); ++idx)
17446 const float f = tcu::Float16(result[idx]).asFloat();
17449 result[idx] = tcu::Float16(-f).bits();
17456 // Generates normalized vectors for arguments 0 and 1
17457 vector<deFloat16> getInputDataN (deUint32 seed, size_t count, size_t compCount, size_t stride, size_t argCount, size_t argNo)
17459 DE_UNREF(compCount);
17460 DE_UNREF(argCount);
17462 de::Random rnd (seed << argNo);
17463 vector<deFloat16> result;
17465 if (argNo == 0 || argNo == 1)
17467 // The input parameters for the incident vector I and the surface normal N must already be normalized
17468 for (size_t numIdx = 0; numIdx < count; numIdx += stride)
17470 vector <float> unnormolized;
17473 for (size_t compIdx = 0; compIdx < compCount; ++compIdx)
17474 unnormolized.push_back(float((rnd.getUint16() % 16) - 8));
17476 for (size_t compIdx = 0; compIdx < compCount; ++compIdx)
17477 sum += unnormolized[compIdx] * unnormolized[compIdx];
17479 sum = deFloatSqrt(sum);
17481 unnormolized[0] = sum = 1.0f;
17483 for (size_t compIdx = 0; compIdx < compCount; ++compIdx)
17484 result.push_back(tcu::Float16(unnormolized[compIdx] / sum).bits());
17486 for (size_t compIdx = compCount; compIdx < stride; ++compIdx)
17487 result.push_back(0);
17492 // Input parameter eta
17493 for (deUint32 numIdx = 0; numIdx < count; ++numIdx)
17495 int num = (rnd.getUint16() % 16) - 8;
17497 result.push_back(tcu::Float16(float(num)).bits());
17501 DE_ASSERT(result.size() == count);
17506 // Data generator for complex matrix functions like determinant and inverse
17507 vector<deFloat16> getInputDataC (deUint32 seed, size_t count, size_t compCount, size_t stride, size_t argCount, size_t argNo)
17509 DE_UNREF(compCount);
17511 DE_UNREF(argCount);
17513 de::Random rnd (seed << argNo);
17514 vector<deFloat16> result;
17516 for (deUint32 numIdx = 0; numIdx < count; ++numIdx)
17518 int num = (rnd.getUint16() % 16) - 8;
17520 result.push_back(tcu::Float16(float(num)).bits());
17523 DE_ASSERT(result.size() == count);
17528 struct Math16TestType
17530 const char* typePrefix;
17531 const size_t typeComponents;
17532 const size_t typeArrayStride;
17533 const size_t typeStructStride;
17534 const char* storage_type;
17537 enum Math16DataTypes
17556 struct Math16ArgFragments
17558 const char* bodies;
17559 const char* variables;
17560 const char* decorations;
17561 const char* funcVariables;
17564 typedef vector<deFloat16> Math16GetInputData (deUint32 seed, size_t count, size_t compCount, size_t stride, size_t argCount, size_t argNo);
17566 struct Math16TestFunc
17568 const char* funcName;
17569 const char* funcSuffix;
17570 size_t funcArgsCount;
17575 Math16GetInputData* getInputDataFunc;
17576 VerifyIOFunc verifyFunc;
17579 template<class SpecResource>
17580 void createFloat16ArithmeticFuncTest (tcu::TestContext& testCtx, tcu::TestCaseGroup& testGroup, const size_t testTypeIdx, const Math16TestFunc& testFunc)
17582 const int testSpecificSeed = deStringHash(testGroup.getName());
17583 const int seed = testCtx.getCommandLine().getBaseSeed() ^ testSpecificSeed;
17584 const size_t numDataPointsByAxis = 32;
17585 const size_t numDataPoints = numDataPointsByAxis * numDataPointsByAxis;
17586 const char* componentType = "f16";
17587 const Math16TestType testTypes[MATH16_TYPE_LAST] =
17589 { "", 0, 0, 0, "" },
17590 { "", 1, 1 * sizeof(deFloat16), 2 * sizeof(deFloat16), "u32_half_ndp" },
17591 { "v2", 2, 2 * sizeof(deFloat16), 2 * sizeof(deFloat16), "u32_ndp" },
17592 { "v3", 3, 4 * sizeof(deFloat16), 4 * sizeof(deFloat16), "u32_ndp_2" },
17593 { "v4", 4, 4 * sizeof(deFloat16), 4 * sizeof(deFloat16), "u32_ndp_2" },
17594 { "m2x2", 0, 4 * sizeof(deFloat16), 4 * sizeof(deFloat16), "u32_ndp_2" },
17595 { "m2x3", 0, 8 * sizeof(deFloat16), 8 * sizeof(deFloat16), "u32_ndp_4" },
17596 { "m2x4", 0, 8 * sizeof(deFloat16), 8 * sizeof(deFloat16), "u32_ndp_4" },
17597 { "m3x2", 0, 8 * sizeof(deFloat16), 8 * sizeof(deFloat16), "u32_ndp_3" },
17598 { "m3x3", 0, 16 * sizeof(deFloat16), 16 * sizeof(deFloat16), "u32_ndp_6" },
17599 { "m3x4", 0, 16 * sizeof(deFloat16), 16 * sizeof(deFloat16), "u32_ndp_6" },
17600 { "m4x2", 0, 8 * sizeof(deFloat16), 8 * sizeof(deFloat16), "u32_ndp_4" },
17601 { "m4x3", 0, 16 * sizeof(deFloat16), 16 * sizeof(deFloat16), "u32_ndp_8" },
17602 { "m4x4", 0, 16 * sizeof(deFloat16), 16 * sizeof(deFloat16), "u32_ndp_8" },
17605 DE_ASSERT(testTypeIdx == testTypes[testTypeIdx].typeComponents);
17608 const StringTemplate preMain
17610 " %c_i32_ndp = OpConstant %i32 ${num_data_points}\n"
17612 " %f16 = OpTypeFloat 16\n"
17613 " %v2f16 = OpTypeVector %f16 2\n"
17614 " %v3f16 = OpTypeVector %f16 3\n"
17615 " %v4f16 = OpTypeVector %f16 4\n"
17616 " %m2x2f16 = OpTypeMatrix %v2f16 2\n"
17617 " %m2x3f16 = OpTypeMatrix %v3f16 2\n"
17618 " %m2x4f16 = OpTypeMatrix %v4f16 2\n"
17619 " %m3x2f16 = OpTypeMatrix %v2f16 3\n"
17620 " %m3x3f16 = OpTypeMatrix %v3f16 3\n"
17621 " %m3x4f16 = OpTypeMatrix %v4f16 3\n"
17622 " %m4x2f16 = OpTypeMatrix %v2f16 4\n"
17623 " %m4x3f16 = OpTypeMatrix %v3f16 4\n"
17624 " %m4x4f16 = OpTypeMatrix %v4f16 4\n"
17626 " %fp_v2i32 = OpTypePointer Function %v2i32\n"
17627 " %fp_v3i32 = OpTypePointer Function %v3i32\n"
17628 " %fp_v4i32 = OpTypePointer Function %v4i32\n"
17630 " %c_u32_ndp = OpConstant %u32 ${num_data_points}\n"
17631 " %c_u32_half_ndp = OpSpecConstantOp %u32 UDiv %c_i32_ndp %c_u32_2\n"
17632 " %c_u32_5 = OpConstant %u32 5\n"
17633 " %c_u32_6 = OpConstant %u32 6\n"
17634 " %c_u32_7 = OpConstant %u32 7\n"
17635 " %c_u32_8 = OpConstant %u32 8\n"
17636 " %c_f16_0 = OpConstant %f16 0\n"
17637 " %c_f16_1 = OpConstant %f16 1\n"
17638 " %c_v2f16_0 = OpConstantComposite %v2f16 %c_f16_0 %c_f16_0\n"
17639 " %up_u32 = OpTypePointer Uniform %u32\n"
17640 "%c_u32_high_ones = OpConstant %u32 0xffff0000\n"
17641 " %c_u32_low_ones = OpConstant %u32 0x0000ffff\n"
17643 " %ra_u32_half_ndp = OpTypeArray %u32 %c_u32_half_ndp\n"
17644 " %SSBO_u32_half_ndp = OpTypeStruct %ra_u32_half_ndp\n"
17645 "%up_SSBO_u32_half_ndp = OpTypePointer Uniform %SSBO_u32_half_ndp\n"
17646 " %ra_u32_ndp = OpTypeArray %u32 %c_u32_ndp\n"
17647 " %SSBO_u32_ndp = OpTypeStruct %ra_u32_ndp\n"
17648 " %up_SSBO_u32_ndp = OpTypePointer Uniform %SSBO_u32_ndp\n"
17649 " %ra_u32_2 = OpTypeArray %u32 %c_u32_2\n"
17650 " %up_ra_u32_2 = OpTypePointer Uniform %ra_u32_2\n"
17651 " %ra_ra_u32_ndp = OpTypeArray %ra_u32_2 %c_u32_ndp\n"
17652 " %SSBO_u32_ndp_2 = OpTypeStruct %ra_ra_u32_ndp\n"
17653 " %up_SSBO_u32_ndp_2 = OpTypePointer Uniform %SSBO_u32_ndp_2\n"
17654 " %ra_u32_4 = OpTypeArray %u32 %c_u32_4\n"
17655 " %up_ra_u32_4 = OpTypePointer Uniform %ra_u32_4\n"
17656 " %ra_ra_u32_4 = OpTypeArray %ra_u32_4 %c_u32_ndp\n"
17657 " %SSBO_u32_ndp_4 = OpTypeStruct %ra_ra_u32_4\n"
17658 " %up_SSBO_u32_ndp_4 = OpTypePointer Uniform %SSBO_u32_ndp_4\n"
17659 " %ra_u32_3 = OpTypeArray %u32 %c_u32_3\n"
17660 " %up_ra_u32_3 = OpTypePointer Uniform %ra_u32_3\n"
17661 " %ra_ra_u32_3 = OpTypeArray %ra_u32_3 %c_u32_ndp\n"
17662 " %SSBO_u32_ndp_3 = OpTypeStruct %ra_ra_u32_3\n"
17663 " %up_SSBO_u32_ndp_3 = OpTypePointer Uniform %SSBO_u32_ndp_3\n"
17664 " %ra_u32_6 = OpTypeArray %u32 %c_u32_6\n"
17665 " %up_ra_u32_6 = OpTypePointer Uniform %ra_u32_6\n"
17666 " %ra_ra_u32_6 = OpTypeArray %ra_u32_6 %c_u32_ndp\n"
17667 " %SSBO_u32_ndp_6 = OpTypeStruct %ra_ra_u32_6\n"
17668 " %up_SSBO_u32_ndp_6 = OpTypePointer Uniform %SSBO_u32_ndp_6\n"
17669 " %ra_u32_8 = OpTypeArray %u32 %c_u32_8\n"
17670 " %up_ra_u32_8 = OpTypePointer Uniform %ra_u32_8\n"
17671 " %ra_ra_u32_8 = OpTypeArray %ra_u32_8 %c_u32_ndp\n"
17672 " %SSBO_u32_ndp_8 = OpTypeStruct %ra_ra_u32_8\n"
17673 " %up_SSBO_u32_ndp_8 = OpTypePointer Uniform %SSBO_u32_ndp_8\n"
17675 " %f16_i32_fn = OpTypeFunction %f16 %i32\n"
17676 " %v2f16_i32_fn = OpTypeFunction %v2f16 %i32\n"
17677 " %v3f16_i32_fn = OpTypeFunction %v3f16 %i32\n"
17678 " %v4f16_i32_fn = OpTypeFunction %v4f16 %i32\n"
17679 " %m2x2f16_i32_fn = OpTypeFunction %m2x2f16 %i32\n"
17680 " %m2x3f16_i32_fn = OpTypeFunction %m2x3f16 %i32\n"
17681 " %m2x4f16_i32_fn = OpTypeFunction %m2x4f16 %i32\n"
17682 " %m3x2f16_i32_fn = OpTypeFunction %m3x2f16 %i32\n"
17683 " %m3x3f16_i32_fn = OpTypeFunction %m3x3f16 %i32\n"
17684 " %m3x4f16_i32_fn = OpTypeFunction %m3x4f16 %i32\n"
17685 " %m4x2f16_i32_fn = OpTypeFunction %m4x2f16 %i32\n"
17686 " %m4x3f16_i32_fn = OpTypeFunction %m4x3f16 %i32\n"
17687 " %m4x4f16_i32_fn = OpTypeFunction %m4x4f16 %i32\n"
17688 " %void_f16_i32_fn = OpTypeFunction %void %f16 %i32\n"
17689 " %void_v2f16_i32_fn = OpTypeFunction %void %v2f16 %i32\n"
17690 " %void_v3f16_i32_fn = OpTypeFunction %void %v3f16 %i32\n"
17691 " %void_v4f16_i32_fn = OpTypeFunction %void %v4f16 %i32\n"
17692 "%void_m2x2f16_i32_fn = OpTypeFunction %void %m2x2f16 %i32\n"
17693 "%void_m2x3f16_i32_fn = OpTypeFunction %void %m2x3f16 %i32\n"
17694 "%void_m2x4f16_i32_fn = OpTypeFunction %void %m2x4f16 %i32\n"
17695 "%void_m3x2f16_i32_fn = OpTypeFunction %void %m3x2f16 %i32\n"
17696 "%void_m3x3f16_i32_fn = OpTypeFunction %void %m3x3f16 %i32\n"
17697 "%void_m3x4f16_i32_fn = OpTypeFunction %void %m3x4f16 %i32\n"
17698 "%void_m4x2f16_i32_fn = OpTypeFunction %void %m4x2f16 %i32\n"
17699 "%void_m4x3f16_i32_fn = OpTypeFunction %void %m4x3f16 %i32\n"
17700 "%void_m4x4f16_i32_fn = OpTypeFunction %void %m4x4f16 %i32\n"
17704 const StringTemplate decoration
17706 "OpDecorate %ra_u32_half_ndp ArrayStride 4\n"
17707 "OpMemberDecorate %SSBO_u32_half_ndp 0 Offset 0\n"
17708 "OpDecorate %SSBO_u32_half_ndp BufferBlock\n"
17710 "OpDecorate %ra_u32_ndp ArrayStride 4\n"
17711 "OpMemberDecorate %SSBO_u32_ndp 0 Offset 0\n"
17712 "OpDecorate %SSBO_u32_ndp BufferBlock\n"
17714 "OpDecorate %ra_u32_2 ArrayStride 4\n"
17715 "OpDecorate %ra_ra_u32_ndp ArrayStride 8\n"
17716 "OpMemberDecorate %SSBO_u32_ndp_2 0 Offset 0\n"
17717 "OpDecorate %SSBO_u32_ndp_2 BufferBlock\n"
17719 "OpDecorate %ra_u32_4 ArrayStride 4\n"
17720 "OpDecorate %ra_ra_u32_4 ArrayStride 16\n"
17721 "OpMemberDecorate %SSBO_u32_ndp_4 0 Offset 0\n"
17722 "OpDecorate %SSBO_u32_ndp_4 BufferBlock\n"
17724 "OpDecorate %ra_u32_3 ArrayStride 4\n"
17725 "OpDecorate %ra_ra_u32_3 ArrayStride 16\n"
17726 "OpMemberDecorate %SSBO_u32_ndp_3 0 Offset 0\n"
17727 "OpDecorate %SSBO_u32_ndp_3 BufferBlock\n"
17729 "OpDecorate %ra_u32_6 ArrayStride 4\n"
17730 "OpDecorate %ra_ra_u32_6 ArrayStride 32\n"
17731 "OpMemberDecorate %SSBO_u32_ndp_6 0 Offset 0\n"
17732 "OpDecorate %SSBO_u32_ndp_6 BufferBlock\n"
17734 "OpDecorate %ra_u32_8 ArrayStride 4\n"
17735 "OpDecorate %ra_ra_u32_8 ArrayStride 32\n"
17736 "OpMemberDecorate %SSBO_u32_ndp_8 0 Offset 0\n"
17737 "OpDecorate %SSBO_u32_ndp_8 BufferBlock\n"
17739 "${arg_decorations}"
17742 const StringTemplate testFun
17744 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
17745 " %param = OpFunctionParameter %v4f32\n"
17746 " %entry = OpLabel\n"
17748 " %i = OpVariable %fp_i32 Function\n"
17749 "${arg_infunc_vars}"
17750 " OpStore %i %c_i32_0\n"
17751 " OpBranch %loop\n"
17753 " %loop = OpLabel\n"
17754 " %i_cmp = OpLoad %i32 %i\n"
17755 " %lt = OpSLessThan %bool %i_cmp %c_i32_ndp\n"
17756 " OpLoopMerge %merge %next None\n"
17757 " OpBranchConditional %lt %write %merge\n"
17759 " %write = OpLabel\n"
17760 " %ndx = OpLoad %i32 %i\n"
17764 " OpBranch %next\n"
17766 " %next = OpLabel\n"
17767 " %i_cur = OpLoad %i32 %i\n"
17768 " %i_new = OpIAdd %i32 %i_cur %c_i32_1\n"
17769 " OpStore %i %i_new\n"
17770 " OpBranch %loop\n"
17772 " %merge = OpLabel\n"
17773 " OpReturnValue %param\n"
17777 const Math16ArgFragments argFragment1 =
17779 " %val_src0 = OpFunctionCall %${t0} %ld_arg_ssbo_src0 %ndx\n"
17780 " %val_dst = ${op} %${tr} ${ext_inst} %val_src0\n"
17781 " %dst = OpFunctionCall %void %st_fn_ssbo_dst %val_dst %ndx\n",
17787 const Math16ArgFragments argFragment2 =
17789 " %val_src0 = OpFunctionCall %${t0} %ld_arg_ssbo_src0 %ndx\n"
17790 " %val_src1 = OpFunctionCall %${t1} %ld_arg_ssbo_src1 %ndx\n"
17791 " %val_dst = ${op} %${tr} ${ext_inst} %val_src0 %val_src1\n"
17792 " %dst = OpFunctionCall %void %st_fn_ssbo_dst %val_dst %ndx\n",
17798 const Math16ArgFragments argFragment3 =
17800 " %val_src0 = OpFunctionCall %${t0} %ld_arg_ssbo_src0 %ndx\n"
17801 " %val_src1 = OpFunctionCall %${t1} %ld_arg_ssbo_src1 %ndx\n"
17802 " %val_src2 = OpFunctionCall %${t2} %ld_arg_ssbo_src2 %ndx\n"
17803 " %val_dst = ${op} %${tr} ${ext_inst} %val_src0 %val_src1 %val_src2\n"
17804 " %dst = OpFunctionCall %void %st_fn_ssbo_dst %val_dst %ndx\n",
17810 const Math16ArgFragments argFragmentLdExp =
17812 " %val_src0 = OpFunctionCall %${t0} %ld_arg_ssbo_src0 %ndx\n"
17813 " %val_src1 = OpFunctionCall %${t1} %ld_arg_ssbo_src1 %ndx\n"
17814 "%val_src1i = OpConvertFToS %${dr}i32 %val_src1\n"
17815 " %val_dst = ${op} %${tr} ${ext_inst} %val_src0 %val_src1i\n"
17816 " %dst = OpFunctionCall %void %st_fn_ssbo_dst %val_dst %ndx\n",
17825 const Math16ArgFragments argFragmentModfFrac =
17827 " %val_src0 = OpFunctionCall %${t0} %ld_arg_ssbo_src0 %ndx\n"
17828 " %val_dst = ${op} %${tr} ${ext_inst} %val_src0 %tmp\n"
17829 " %dst = OpFunctionCall %void %st_fn_ssbo_dst %val_dst %ndx\n",
17831 " %fp_tmp = OpTypePointer Function %${tr}\n",
17835 " %tmp = OpVariable %fp_tmp Function\n",
17838 const Math16ArgFragments argFragmentModfInt =
17840 " %val_src0 = OpFunctionCall %${t0} %ld_arg_ssbo_src0 %ndx\n"
17841 "%val_dummy = ${op} %${tr} ${ext_inst} %val_src0 %tmp\n"
17842 " %tmp0 = OpAccessChain %fp_tmp %tmp\n"
17843 " %val_dst = OpLoad %${tr} %tmp0\n"
17844 " %dst = OpFunctionCall %void %st_fn_ssbo_dst %val_dst %ndx\n",
17846 " %fp_tmp = OpTypePointer Function %${tr}\n",
17850 " %tmp = OpVariable %fp_tmp Function\n",
17853 const Math16ArgFragments argFragmentModfStruct =
17855 " %val_src0 = OpFunctionCall %${t0} %ld_arg_ssbo_src0 %ndx\n"
17856 " %val_tmp = ${op} %st_tmp ${ext_inst} %val_src0\n"
17857 "%tmp_ptr_s = OpAccessChain %fp_tmp %tmp\n"
17858 " OpStore %tmp_ptr_s %val_tmp\n"
17859 "%tmp_ptr_l = OpAccessChain %fp_${tr} %tmp %c_${struct_member}\n"
17860 " %val_dst = OpLoad %${tr} %tmp_ptr_l\n"
17861 " %dst = OpFunctionCall %void %st_fn_ssbo_dst %val_dst %ndx\n",
17863 " %fp_${tr} = OpTypePointer Function %${tr}\n"
17864 " %st_tmp = OpTypeStruct %${tr} %${tr}\n"
17865 " %fp_tmp = OpTypePointer Function %st_tmp\n"
17866 " %c_frac = OpConstant %i32 0\n"
17867 " %c_int = OpConstant %i32 1\n",
17869 "OpMemberDecorate %st_tmp 0 Offset 0\n"
17870 "OpMemberDecorate %st_tmp 1 Offset ${struct_stride}\n",
17872 " %tmp = OpVariable %fp_tmp Function\n",
17875 const Math16ArgFragments argFragmentFrexpStructS =
17877 " %val_src0 = OpFunctionCall %${t0} %ld_arg_ssbo_src0 %ndx\n"
17878 " %val_tmp = ${op} %st_tmp ${ext_inst} %val_src0\n"
17879 "%tmp_ptr_s = OpAccessChain %fp_tmp %tmp\n"
17880 " OpStore %tmp_ptr_s %val_tmp\n"
17881 "%tmp_ptr_l = OpAccessChain %fp_${tr} %tmp %c_i32_0\n"
17882 " %val_dst = OpLoad %${tr} %tmp_ptr_l\n"
17883 " %dst = OpFunctionCall %void %st_fn_ssbo_dst %val_dst %ndx\n",
17885 " %fp_${tr} = OpTypePointer Function %${tr}\n"
17886 " %st_tmp = OpTypeStruct %${tr} %${dr}i32\n"
17887 " %fp_tmp = OpTypePointer Function %st_tmp\n",
17889 "OpMemberDecorate %st_tmp 0 Offset 0\n"
17890 "OpMemberDecorate %st_tmp 1 Offset ${struct_stride}\n",
17892 " %tmp = OpVariable %fp_tmp Function\n",
17895 const Math16ArgFragments argFragmentFrexpStructE =
17897 " %val_src0 = OpFunctionCall %${t0} %ld_arg_ssbo_src0 %ndx\n"
17898 " %val_tmp = ${op} %st_tmp ${ext_inst} %val_src0\n"
17899 "%tmp_ptr_s = OpAccessChain %fp_tmp %tmp\n"
17900 " OpStore %tmp_ptr_s %val_tmp\n"
17901 "%tmp_ptr_l = OpAccessChain %fp_${dr}i32 %tmp %c_i32_1\n"
17902 "%val_dst_i = OpLoad %${dr}i32 %tmp_ptr_l\n"
17903 " %val_dst = OpConvertSToF %${tr} %val_dst_i\n"
17904 " %dst = OpFunctionCall %void %st_fn_ssbo_dst %val_dst %ndx\n",
17906 " %st_tmp = OpTypeStruct %${tr} %${dr}i32\n"
17907 " %fp_tmp = OpTypePointer Function %st_tmp\n",
17909 "OpMemberDecorate %st_tmp 0 Offset 0\n"
17910 "OpMemberDecorate %st_tmp 1 Offset ${struct_stride}\n",
17912 " %tmp = OpVariable %fp_tmp Function\n",
17915 const Math16ArgFragments argFragmentFrexpS =
17917 " %val_src0 = OpFunctionCall %${t0} %ld_arg_ssbo_src0 %ndx\n"
17918 " %out_exp = OpAccessChain %fp_${dr}i32 %tmp\n"
17919 " %val_dst = ${op} %${tr} ${ext_inst} %val_src0 %out_exp\n"
17920 " %dst = OpFunctionCall %void %st_fn_ssbo_dst %val_dst %ndx\n",
17926 " %tmp = OpVariable %fp_${dr}i32 Function\n",
17929 const Math16ArgFragments argFragmentFrexpE =
17931 " %val_src0 = OpFunctionCall %${t0} %ld_arg_ssbo_src0 %ndx\n"
17932 " %out_exp = OpAccessChain %fp_${dr}i32 %tmp\n"
17933 "%val_dummy = ${op} %${tr} ${ext_inst} %val_src0 %out_exp\n"
17934 "%val_dst_i = OpLoad %${dr}i32 %out_exp\n"
17935 " %val_dst = OpConvertSToF %${tr} %val_dst_i\n"
17936 " %dst = OpFunctionCall %void %st_fn_ssbo_dst %val_dst %ndx\n",
17942 " %tmp = OpVariable %fp_${dr}i32 Function\n",
17945 string load_funcs[MATH16_TYPE_LAST];
17946 load_funcs[SCALAR] = loadScalarF16FromUint;
17947 load_funcs[VEC2] = loadV2F16FromUint;
17948 load_funcs[VEC3] = loadV3F16FromUints;
17949 load_funcs[VEC4] = loadV4F16FromUints;
17950 load_funcs[MAT2X2] = loadM2x2F16FromUints;
17951 load_funcs[MAT2X3] = loadM2x3F16FromUints;
17952 load_funcs[MAT2X4] = loadM2x4F16FromUints;
17953 load_funcs[MAT3X2] = loadM3x2F16FromUints;
17954 load_funcs[MAT3X3] = loadM3x3F16FromUints;
17955 load_funcs[MAT3X4] = loadM3x4F16FromUints;
17956 load_funcs[MAT4X2] = loadM4x2F16FromUints;
17957 load_funcs[MAT4X3] = loadM4x3F16FromUints;
17958 load_funcs[MAT4X4] = loadM4x4F16FromUints;
17960 string store_funcs[MATH16_TYPE_LAST];
17961 store_funcs[SCALAR] = storeScalarF16AsUint;
17962 store_funcs[VEC2] = storeV2F16AsUint;
17963 store_funcs[VEC3] = storeV3F16AsUints;
17964 store_funcs[VEC4] = storeV4F16AsUints;
17965 store_funcs[MAT2X2] = storeM2x2F16AsUints;
17966 store_funcs[MAT2X3] = storeM2x3F16AsUints;
17967 store_funcs[MAT2X4] = storeM2x4F16AsUints;
17968 store_funcs[MAT3X2] = storeM3x2F16AsUints;
17969 store_funcs[MAT3X3] = storeM3x3F16AsUints;
17970 store_funcs[MAT3X4] = storeM3x4F16AsUints;
17971 store_funcs[MAT4X2] = storeM4x2F16AsUints;
17972 store_funcs[MAT4X3] = storeM4x3F16AsUints;
17973 store_funcs[MAT4X4] = storeM4x4F16AsUints;
17975 const Math16TestType& testType = testTypes[testTypeIdx];
17976 const string funcNameString = string(testFunc.funcName) + string(testFunc.funcSuffix);
17977 const string testName = de::toLower(funcNameString);
17978 const Math16ArgFragments* argFragments = DE_NULL;
17979 const size_t typeStructStride = testType.typeStructStride;
17980 const bool extInst = !(testFunc.funcName[0] == 'O' && testFunc.funcName[1] == 'p');
17981 const size_t numFloatsPerArg0Type = testTypes[testFunc.typeArg0].typeArrayStride / sizeof(deFloat16);
17982 const size_t iterations = numDataPoints / numFloatsPerArg0Type;
17983 const size_t numFloatsPerResultType = testTypes[testFunc.typeResult].typeArrayStride / sizeof(deFloat16);
17984 const vector<deFloat16> float16DummyOutput (iterations * numFloatsPerResultType, 0);
17985 VulkanFeatures features;
17986 SpecResource specResource;
17987 map<string, string> specs;
17988 map<string, string> fragments;
17989 vector<string> extensions;
17991 string funcVariables;
17993 string declarations;
17994 string decorations;
17997 switch (testFunc.funcArgsCount)
18001 argFragments = &argFragment1;
18003 if (funcNameString == "ModfFrac") argFragments = &argFragmentModfFrac;
18004 if (funcNameString == "ModfInt") argFragments = &argFragmentModfInt;
18005 if (funcNameString == "ModfStructFrac") argFragments = &argFragmentModfStruct;
18006 if (funcNameString == "ModfStructInt") argFragments = &argFragmentModfStruct;
18007 if (funcNameString == "FrexpS") argFragments = &argFragmentFrexpS;
18008 if (funcNameString == "FrexpE") argFragments = &argFragmentFrexpE;
18009 if (funcNameString == "FrexpStructS") argFragments = &argFragmentFrexpStructS;
18010 if (funcNameString == "FrexpStructE") argFragments = &argFragmentFrexpStructE;
18016 argFragments = &argFragment2;
18018 if (funcNameString == "Ldexp") argFragments = &argFragmentLdExp;
18024 argFragments = &argFragment3;
18030 TCU_THROW(InternalError, "Invalid number of arguments");
18034 functions = StringTemplate(store_funcs[testFunc.typeResult]).specialize({{"var", "ssbo_dst"}});
18035 if (testFunc.funcArgsCount == 1)
18037 functions += StringTemplate(load_funcs[testFunc.typeArg0]).specialize({{"var", "ssbo_src0"}});
18039 " %ssbo_src0 = OpVariable %up_SSBO_${store_t0} Uniform\n"
18040 " %ssbo_dst = OpVariable %up_SSBO_${store_tr} Uniform\n";
18043 "OpDecorate %ssbo_src0 DescriptorSet 0\n"
18044 "OpDecorate %ssbo_src0 Binding 0\n"
18045 "OpDecorate %ssbo_dst DescriptorSet 0\n"
18046 "OpDecorate %ssbo_dst Binding 1\n";
18048 else if (testFunc.funcArgsCount == 2)
18050 functions += StringTemplate(load_funcs[testFunc.typeArg0]).specialize({{"var", "ssbo_src0"}});
18051 functions += StringTemplate(load_funcs[testFunc.typeArg1]).specialize({{"var", "ssbo_src1"}});
18053 " %ssbo_src0 = OpVariable %up_SSBO_${store_t0} Uniform\n"
18054 " %ssbo_src1 = OpVariable %up_SSBO_${store_t1} Uniform\n"
18055 " %ssbo_dst = OpVariable %up_SSBO_${store_tr} Uniform\n";
18058 "OpDecorate %ssbo_src0 DescriptorSet 0\n"
18059 "OpDecorate %ssbo_src0 Binding 0\n"
18060 "OpDecorate %ssbo_src1 DescriptorSet 0\n"
18061 "OpDecorate %ssbo_src1 Binding 1\n"
18062 "OpDecorate %ssbo_dst DescriptorSet 0\n"
18063 "OpDecorate %ssbo_dst Binding 2\n";
18065 else if (testFunc.funcArgsCount == 3)
18067 functions += StringTemplate(load_funcs[testFunc.typeArg0]).specialize({{"var", "ssbo_src0"}});
18068 functions += StringTemplate(load_funcs[testFunc.typeArg1]).specialize({{"var", "ssbo_src1"}});
18069 functions += StringTemplate(load_funcs[testFunc.typeArg2]).specialize({{"var", "ssbo_src2"}});
18071 " %ssbo_src0 = OpVariable %up_SSBO_${store_t0} Uniform\n"
18072 " %ssbo_src1 = OpVariable %up_SSBO_${store_t1} Uniform\n"
18073 " %ssbo_src2 = OpVariable %up_SSBO_${store_t2} Uniform\n"
18074 " %ssbo_dst = OpVariable %up_SSBO_${store_tr} Uniform\n";
18077 "OpDecorate %ssbo_src0 DescriptorSet 0\n"
18078 "OpDecorate %ssbo_src0 Binding 0\n"
18079 "OpDecorate %ssbo_src1 DescriptorSet 0\n"
18080 "OpDecorate %ssbo_src1 Binding 1\n"
18081 "OpDecorate %ssbo_src2 DescriptorSet 0\n"
18082 "OpDecorate %ssbo_src2 Binding 2\n"
18083 "OpDecorate %ssbo_dst DescriptorSet 0\n"
18084 "OpDecorate %ssbo_dst Binding 3\n";
18088 TCU_THROW(InternalError, "Invalid number of function arguments");
18091 variables += argFragments->variables;
18092 decorations += argFragments->decorations;
18094 specs["dr"] = testTypes[testFunc.typeResult].typePrefix;
18095 specs["d0"] = testTypes[testFunc.typeArg0].typePrefix;
18096 specs["d1"] = testTypes[testFunc.typeArg1].typePrefix;
18097 specs["d2"] = testTypes[testFunc.typeArg2].typePrefix;
18098 specs["tr"] = string(testTypes[testFunc.typeResult].typePrefix) + componentType;
18099 specs["t0"] = string(testTypes[testFunc.typeArg0].typePrefix) + componentType;
18100 specs["t1"] = string(testTypes[testFunc.typeArg1].typePrefix) + componentType;
18101 specs["t2"] = string(testTypes[testFunc.typeArg2].typePrefix) + componentType;
18102 specs["store_tr"] = string(testTypes[testFunc.typeResult].storage_type);
18103 specs["store_t0"] = string(testTypes[testFunc.typeArg0].storage_type);
18104 specs["store_t1"] = string(testTypes[testFunc.typeArg1].storage_type);
18105 specs["store_t2"] = string(testTypes[testFunc.typeArg2].storage_type);
18106 specs["struct_stride"] = de::toString(typeStructStride);
18107 specs["op"] = extInst ? "OpExtInst" : testFunc.funcName;
18108 specs["ext_inst"] = extInst ? string("%ext_import ") + testFunc.funcName : "";
18109 specs["struct_member"] = de::toLower(testFunc.funcSuffix);
18111 variables = StringTemplate(variables).specialize(specs);
18112 decorations = StringTemplate(decorations).specialize(specs);
18113 funcVariables = StringTemplate(argFragments->funcVariables).specialize(specs);
18114 funcCall = StringTemplate(argFragments->bodies).specialize(specs);
18116 specs["num_data_points"] = de::toString(iterations);
18117 specs["arg_vars"] = variables;
18118 specs["arg_decorations"] = decorations;
18119 specs["arg_infunc_vars"] = funcVariables;
18120 specs["arg_func_call"] = funcCall;
18122 fragments["extension"] = "%ext_import = OpExtInstImport \"GLSL.std.450\"";
18123 fragments["capability"] = "OpCapability Matrix\nOpCapability Float16\n";
18124 fragments["decoration"] = decoration.specialize(specs);
18125 fragments["pre_main"] = preMain.specialize(specs) + functions;
18126 fragments["testfun"] = testFun.specialize(specs);
18128 for (size_t inputArgNdx = 0; inputArgNdx < testFunc.funcArgsCount; ++inputArgNdx)
18130 const size_t numFloatsPerItem = (inputArgNdx == 0) ? testTypes[testFunc.typeArg0].typeArrayStride / sizeof(deFloat16)
18131 : (inputArgNdx == 1) ? testTypes[testFunc.typeArg1].typeArrayStride / sizeof(deFloat16)
18132 : (inputArgNdx == 2) ? testTypes[testFunc.typeArg2].typeArrayStride / sizeof(deFloat16)
18134 const vector<deFloat16> inputData = testFunc.getInputDataFunc(seed, numFloatsPerItem * iterations, testTypeIdx, numFloatsPerItem, testFunc.funcArgsCount, inputArgNdx);
18136 specResource.inputs.push_back(Resource(BufferSp(new Float16Buffer(inputData)), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
18139 specResource.outputs.push_back(Resource(BufferSp(new Float16Buffer(float16DummyOutput)), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
18140 specResource.verifyIO = testFunc.verifyFunc;
18142 extensions.push_back("VK_KHR_shader_float16_int8");
18144 features.extFloat16Int8 = EXTFLOAT16INT8FEATURES_FLOAT16;
18146 finalizeTestsCreation(specResource, fragments, testCtx, testGroup, testName, features, extensions, IVec3(1, 1, 1));
18149 template<size_t C, class SpecResource>
18150 tcu::TestCaseGroup* createFloat16ArithmeticSet (tcu::TestContext& testCtx)
18152 DE_STATIC_ASSERT(C >= 1 && C <= 4);
18154 const std::string testGroupName (string("arithmetic_") + de::toString(C));
18155 de::MovePtr<tcu::TestCaseGroup> testGroup (new tcu::TestCaseGroup(testCtx, testGroupName.c_str(), "Float 16 arithmetic and related tests"));
18156 const Math16TestFunc testFuncs[] =
18158 { "OpFNegate", "", 1, C, C, 0, 0, &getInputData, compareFP16ArithmeticFunc< C, C, 0, 0, fp16OpFNegate> },
18159 { "Round", "", 1, C, C, 0, 0, &getInputData, compareFP16ArithmeticFunc< C, C, 0, 0, fp16Round> },
18160 { "RoundEven", "", 1, C, C, 0, 0, &getInputData, compareFP16ArithmeticFunc< C, C, 0, 0, fp16RoundEven> },
18161 { "Trunc", "", 1, C, C, 0, 0, &getInputData, compareFP16ArithmeticFunc< C, C, 0, 0, fp16Trunc> },
18162 { "FAbs", "", 1, C, C, 0, 0, &getInputData, compareFP16ArithmeticFunc< C, C, 0, 0, fp16FAbs> },
18163 { "FSign", "", 1, C, C, 0, 0, &getInputData, compareFP16ArithmeticFunc< C, C, 0, 0, fp16FSign> },
18164 { "Floor", "", 1, C, C, 0, 0, &getInputData, compareFP16ArithmeticFunc< C, C, 0, 0, fp16Floor> },
18165 { "Ceil", "", 1, C, C, 0, 0, &getInputData, compareFP16ArithmeticFunc< C, C, 0, 0, fp16Ceil> },
18166 { "Fract", "", 1, C, C, 0, 0, &getInputData, compareFP16ArithmeticFunc< C, C, 0, 0, fp16Fract> },
18167 { "Radians", "", 1, C, C, 0, 0, &getInputData, compareFP16ArithmeticFunc< C, C, 0, 0, fp16Radians> },
18168 { "Degrees", "", 1, C, C, 0, 0, &getInputData, compareFP16ArithmeticFunc< C, C, 0, 0, fp16Degrees> },
18169 { "Sin", "", 1, C, C, 0, 0, &getInputDataPI, compareFP16ArithmeticFunc< C, C, 0, 0, fp16Sin> },
18170 { "Cos", "", 1, C, C, 0, 0, &getInputDataPI, compareFP16ArithmeticFunc< C, C, 0, 0, fp16Cos> },
18171 { "Tan", "", 1, C, C, 0, 0, &getInputDataPI, compareFP16ArithmeticFunc< C, C, 0, 0, fp16Tan> },
18172 { "Asin", "", 1, C, C, 0, 0, &getInputDataA, compareFP16ArithmeticFunc< C, C, 0, 0, fp16Asin> },
18173 { "Acos", "", 1, C, C, 0, 0, &getInputDataA, compareFP16ArithmeticFunc< C, C, 0, 0, fp16Acos> },
18174 { "Atan", "", 1, C, C, 0, 0, &getInputData, compareFP16ArithmeticFunc< C, C, 0, 0, fp16Atan> },
18175 { "Sinh", "", 1, C, C, 0, 0, &getInputData, compareFP16ArithmeticFunc< C, C, 0, 0, fp16Sinh> },
18176 { "Cosh", "", 1, C, C, 0, 0, &getInputData, compareFP16ArithmeticFunc< C, C, 0, 0, fp16Cosh> },
18177 { "Tanh", "", 1, C, C, 0, 0, &getInputData, compareFP16ArithmeticFunc< C, C, 0, 0, fp16Tanh> },
18178 { "Asinh", "", 1, C, C, 0, 0, &getInputData, compareFP16ArithmeticFunc< C, C, 0, 0, fp16Asinh> },
18179 { "Acosh", "", 1, C, C, 0, 0, &getInputDataAC, compareFP16ArithmeticFunc< C, C, 0, 0, fp16Acosh> },
18180 { "Atanh", "", 1, C, C, 0, 0, &getInputDataA, compareFP16ArithmeticFunc< C, C, 0, 0, fp16Atanh> },
18181 { "Exp", "", 1, C, C, 0, 0, &getInputData, compareFP16ArithmeticFunc< C, C, 0, 0, fp16Exp> },
18182 { "Log", "", 1, C, C, 0, 0, &getInputDataP, compareFP16ArithmeticFunc< C, C, 0, 0, fp16Log> },
18183 { "Exp2", "", 1, C, C, 0, 0, &getInputData, compareFP16ArithmeticFunc< C, C, 0, 0, fp16Exp2> },
18184 { "Log2", "", 1, C, C, 0, 0, &getInputDataP, compareFP16ArithmeticFunc< C, C, 0, 0, fp16Log2> },
18185 { "Sqrt", "", 1, C, C, 0, 0, &getInputDataP, compareFP16ArithmeticFunc< C, C, 0, 0, fp16Sqrt> },
18186 { "InverseSqrt", "", 1, C, C, 0, 0, &getInputDataP, compareFP16ArithmeticFunc< C, C, 0, 0, fp16InverseSqrt> },
18187 { "Modf", "Frac", 1, C, C, 0, 0, &getInputData, compareFP16ArithmeticFunc< C, C, 0, 0, fp16ModfFrac> },
18188 { "Modf", "Int", 1, C, C, 0, 0, &getInputData, compareFP16ArithmeticFunc< C, C, 0, 0, fp16ModfInt> },
18189 { "ModfStruct", "Frac", 1, C, C, 0, 0, &getInputData, compareFP16ArithmeticFunc< C, C, 0, 0, fp16ModfFrac> },
18190 { "ModfStruct", "Int", 1, C, C, 0, 0, &getInputData, compareFP16ArithmeticFunc< C, C, 0, 0, fp16ModfInt> },
18191 { "Frexp", "S", 1, C, C, 0, 0, &getInputData, compareFP16ArithmeticFunc< C, C, 0, 0, fp16FrexpS> },
18192 { "Frexp", "E", 1, C, C, 0, 0, &getInputData, compareFP16ArithmeticFunc< C, C, 0, 0, fp16FrexpE> },
18193 { "FrexpStruct", "S", 1, C, C, 0, 0, &getInputData, compareFP16ArithmeticFunc< C, C, 0, 0, fp16FrexpS> },
18194 { "FrexpStruct", "E", 1, C, C, 0, 0, &getInputData, compareFP16ArithmeticFunc< C, C, 0, 0, fp16FrexpE> },
18195 { "OpFAdd", "", 2, C, C, C, 0, &getInputData, compareFP16ArithmeticFunc< C, C, C, 0, fp16OpFAdd> },
18196 { "OpFSub", "", 2, C, C, C, 0, &getInputData, compareFP16ArithmeticFunc< C, C, C, 0, fp16OpFSub> },
18197 { "OpFMul", "", 2, C, C, C, 0, &getInputData, compareFP16ArithmeticFunc< C, C, C, 0, fp16OpFMul> },
18198 { "OpFDiv", "", 2, C, C, C, 0, &getInputData, compareFP16ArithmeticFunc< C, C, C, 0, fp16OpFDiv> },
18199 { "Atan2", "", 2, C, C, C, 0, &getInputData, compareFP16ArithmeticFunc< C, C, C, 0, fp16Atan2> },
18200 { "Pow", "", 2, C, C, C, 0, &getInputDataP, compareFP16ArithmeticFunc< C, C, C, 0, fp16Pow> },
18201 { "FMin", "", 2, C, C, C, 0, &getInputData, compareFP16ArithmeticFunc< C, C, C, 0, fp16FMin> },
18202 { "FMax", "", 2, C, C, C, 0, &getInputData, compareFP16ArithmeticFunc< C, C, C, 0, fp16FMax> },
18203 { "Step", "", 2, C, C, C, 0, &getInputData, compareFP16ArithmeticFunc< C, C, C, 0, fp16Step> },
18204 { "Ldexp", "", 2, C, C, C, 0, &getInputData, compareFP16ArithmeticFunc< C, C, C, 0, fp16Ldexp> },
18205 { "FClamp", "", 3, C, C, C, C, &getInputData, compareFP16ArithmeticFunc< C, C, C, C, fp16FClamp> },
18206 { "FMix", "", 3, C, C, C, C, &getInputDataD, compareFP16ArithmeticFunc< C, C, C, C, fp16FMix> },
18207 { "SmoothStep", "", 3, C, C, C, C, &getInputDataSS, compareFP16ArithmeticFunc< C, C, C, C, fp16SmoothStep> },
18208 { "Fma", "", 3, C, C, C, C, &getInputData, compareFP16ArithmeticFunc< C, C, C, C, fp16Fma> },
18209 { "Length", "", 1, 1, C, 0, 0, &getInputData, compareFP16ArithmeticFunc< 1, C, 0, 0, fp16Length> },
18210 { "Distance", "", 2, 1, C, C, 0, &getInputData, compareFP16ArithmeticFunc< 1, C, C, 0, fp16Distance> },
18211 { "Cross", "", 2, C, C, C, 0, &getInputDataD, compareFP16ArithmeticFunc< C, C, C, 0, fp16Cross> },
18212 { "Normalize", "", 1, C, C, 0, 0, &getInputData, compareFP16ArithmeticFunc< C, C, 0, 0, fp16Normalize> },
18213 { "FaceForward", "", 3, C, C, C, C, &getInputDataD, compareFP16ArithmeticFunc< C, C, C, C, fp16FaceForward> },
18214 { "Reflect", "", 2, C, C, C, 0, &getInputDataD, compareFP16ArithmeticFunc< C, C, C, 0, fp16Reflect> },
18215 { "Refract", "", 3, C, C, C, 1, &getInputDataN, compareFP16ArithmeticFunc< C, C, C, 1, fp16Refract> },
18216 { "OpDot", "", 2, 1, C, C, 0, &getInputDataD, compareFP16ArithmeticFunc< 1, C, C, 0, fp16Dot> },
18217 { "OpVectorTimesScalar", "", 2, C, C, 1, 0, &getInputDataV, compareFP16ArithmeticFunc< C, C, 1, 0, fp16VectorTimesScalar> },
18220 for (deUint32 testFuncIdx = 0; testFuncIdx < DE_LENGTH_OF_ARRAY(testFuncs); ++testFuncIdx)
18222 const Math16TestFunc& testFunc = testFuncs[testFuncIdx];
18223 const string funcNameString = testFunc.funcName;
18225 if ((C != 3) && funcNameString == "Cross")
18228 if ((C < 2) && funcNameString == "OpDot")
18231 if ((C < 2) && funcNameString == "OpVectorTimesScalar")
18234 createFloat16ArithmeticFuncTest<SpecResource>(testCtx, *testGroup.get(), C, testFunc);
18237 return testGroup.release();
18240 template<class SpecResource>
18241 tcu::TestCaseGroup* createFloat16ArithmeticSet (tcu::TestContext& testCtx)
18243 const std::string testGroupName ("arithmetic");
18244 de::MovePtr<tcu::TestCaseGroup> testGroup (new tcu::TestCaseGroup(testCtx, testGroupName.c_str(), "Float 16 arithmetic and related tests"));
18245 const Math16TestFunc testFuncs[] =
18247 { "OpTranspose", "2x2", 1, MAT2X2, MAT2X2, 0, 0, &getInputDataM, compareFP16ArithmeticFunc< 4, 4, 0, 0, fp16Transpose<2,2> > },
18248 { "OpTranspose", "3x2", 1, MAT2X3, MAT3X2, 0, 0, &getInputDataM, compareFP16ArithmeticFunc< 8, 8, 0, 0, fp16Transpose<3,2> > },
18249 { "OpTranspose", "4x2", 1, MAT2X4, MAT4X2, 0, 0, &getInputDataM, compareFP16ArithmeticFunc< 8, 8, 0, 0, fp16Transpose<4,2> > },
18250 { "OpTranspose", "2x3", 1, MAT3X2, MAT2X3, 0, 0, &getInputDataM, compareFP16ArithmeticFunc< 8, 8, 0, 0, fp16Transpose<2,3> > },
18251 { "OpTranspose", "3x3", 1, MAT3X3, MAT3X3, 0, 0, &getInputDataM, compareFP16ArithmeticFunc< 16, 16, 0, 0, fp16Transpose<3,3> > },
18252 { "OpTranspose", "4x3", 1, MAT3X4, MAT4X3, 0, 0, &getInputDataM, compareFP16ArithmeticFunc< 16, 16, 0, 0, fp16Transpose<4,3> > },
18253 { "OpTranspose", "2x4", 1, MAT4X2, MAT2X4, 0, 0, &getInputDataM, compareFP16ArithmeticFunc< 8, 8, 0, 0, fp16Transpose<2,4> > },
18254 { "OpTranspose", "3x4", 1, MAT4X3, MAT3X4, 0, 0, &getInputDataM, compareFP16ArithmeticFunc< 16, 16, 0, 0, fp16Transpose<3,4> > },
18255 { "OpTranspose", "4x4", 1, MAT4X4, MAT4X4, 0, 0, &getInputDataM, compareFP16ArithmeticFunc< 16, 16, 0, 0, fp16Transpose<4,4> > },
18256 { "OpMatrixTimesScalar", "2x2", 2, MAT2X2, MAT2X2, 1, 0, &getInputDataD, compareFP16ArithmeticFunc< 4, 4, 1, 0, fp16MatrixTimesScalar<2,2> > },
18257 { "OpMatrixTimesScalar", "2x3", 2, MAT2X3, MAT2X3, 1, 0, &getInputDataD, compareFP16ArithmeticFunc< 8, 8, 1, 0, fp16MatrixTimesScalar<2,3> > },
18258 { "OpMatrixTimesScalar", "2x4", 2, MAT2X4, MAT2X4, 1, 0, &getInputDataD, compareFP16ArithmeticFunc< 8, 8, 1, 0, fp16MatrixTimesScalar<2,4> > },
18259 { "OpMatrixTimesScalar", "3x2", 2, MAT3X2, MAT3X2, 1, 0, &getInputDataD, compareFP16ArithmeticFunc< 8, 8, 1, 0, fp16MatrixTimesScalar<3,2> > },
18260 { "OpMatrixTimesScalar", "3x3", 2, MAT3X3, MAT3X3, 1, 0, &getInputDataD, compareFP16ArithmeticFunc< 16, 16, 1, 0, fp16MatrixTimesScalar<3,3> > },
18261 { "OpMatrixTimesScalar", "3x4", 2, MAT3X4, MAT3X4, 1, 0, &getInputDataD, compareFP16ArithmeticFunc< 16, 16, 1, 0, fp16MatrixTimesScalar<3,4> > },
18262 { "OpMatrixTimesScalar", "4x2", 2, MAT4X2, MAT4X2, 1, 0, &getInputDataD, compareFP16ArithmeticFunc< 8, 8, 1, 0, fp16MatrixTimesScalar<4,2> > },
18263 { "OpMatrixTimesScalar", "4x3", 2, MAT4X3, MAT4X3, 1, 0, &getInputDataD, compareFP16ArithmeticFunc< 16, 16, 1, 0, fp16MatrixTimesScalar<4,3> > },
18264 { "OpMatrixTimesScalar", "4x4", 2, MAT4X4, MAT4X4, 1, 0, &getInputDataD, compareFP16ArithmeticFunc< 16, 16, 1, 0, fp16MatrixTimesScalar<4,4> > },
18265 { "OpVectorTimesMatrix", "2x2", 2, VEC2, VEC2, MAT2X2, 0, &getInputDataD, compareFP16ArithmeticFunc< 2, 2, 4, 0, fp16VectorTimesMatrix<2,2> > },
18266 { "OpVectorTimesMatrix", "2x3", 2, VEC2, VEC3, MAT2X3, 0, &getInputDataD, compareFP16ArithmeticFunc< 2, 3, 8, 0, fp16VectorTimesMatrix<2,3> > },
18267 { "OpVectorTimesMatrix", "2x4", 2, VEC2, VEC4, MAT2X4, 0, &getInputDataD, compareFP16ArithmeticFunc< 2, 4, 8, 0, fp16VectorTimesMatrix<2,4> > },
18268 { "OpVectorTimesMatrix", "3x2", 2, VEC3, VEC2, MAT3X2, 0, &getInputDataD, compareFP16ArithmeticFunc< 3, 2, 8, 0, fp16VectorTimesMatrix<3,2> > },
18269 { "OpVectorTimesMatrix", "3x3", 2, VEC3, VEC3, MAT3X3, 0, &getInputDataD, compareFP16ArithmeticFunc< 3, 3, 16, 0, fp16VectorTimesMatrix<3,3> > },
18270 { "OpVectorTimesMatrix", "3x4", 2, VEC3, VEC4, MAT3X4, 0, &getInputDataD, compareFP16ArithmeticFunc< 3, 4, 16, 0, fp16VectorTimesMatrix<3,4> > },
18271 { "OpVectorTimesMatrix", "4x2", 2, VEC4, VEC2, MAT4X2, 0, &getInputDataD, compareFP16ArithmeticFunc< 4, 2, 8, 0, fp16VectorTimesMatrix<4,2> > },
18272 { "OpVectorTimesMatrix", "4x3", 2, VEC4, VEC3, MAT4X3, 0, &getInputDataD, compareFP16ArithmeticFunc< 4, 3, 16, 0, fp16VectorTimesMatrix<4,3> > },
18273 { "OpVectorTimesMatrix", "4x4", 2, VEC4, VEC4, MAT4X4, 0, &getInputDataD, compareFP16ArithmeticFunc< 4, 4, 16, 0, fp16VectorTimesMatrix<4,4> > },
18274 { "OpMatrixTimesVector", "2x2", 2, VEC2, MAT2X2, VEC2, 0, &getInputDataD, compareFP16ArithmeticFunc< 2, 4, 2, 0, fp16MatrixTimesVector<2,2> > },
18275 { "OpMatrixTimesVector", "2x3", 2, VEC3, MAT2X3, VEC2, 0, &getInputDataD, compareFP16ArithmeticFunc< 3, 8, 2, 0, fp16MatrixTimesVector<2,3> > },
18276 { "OpMatrixTimesVector", "2x4", 2, VEC4, MAT2X4, VEC2, 0, &getInputDataD, compareFP16ArithmeticFunc< 4, 8, 2, 0, fp16MatrixTimesVector<2,4> > },
18277 { "OpMatrixTimesVector", "3x2", 2, VEC2, MAT3X2, VEC3, 0, &getInputDataD, compareFP16ArithmeticFunc< 2, 8, 3, 0, fp16MatrixTimesVector<3,2> > },
18278 { "OpMatrixTimesVector", "3x3", 2, VEC3, MAT3X3, VEC3, 0, &getInputDataD, compareFP16ArithmeticFunc< 3, 16, 3, 0, fp16MatrixTimesVector<3,3> > },
18279 { "OpMatrixTimesVector", "3x4", 2, VEC4, MAT3X4, VEC3, 0, &getInputDataD, compareFP16ArithmeticFunc< 4, 16, 3, 0, fp16MatrixTimesVector<3,4> > },
18280 { "OpMatrixTimesVector", "4x2", 2, VEC2, MAT4X2, VEC4, 0, &getInputDataD, compareFP16ArithmeticFunc< 2, 8, 4, 0, fp16MatrixTimesVector<4,2> > },
18281 { "OpMatrixTimesVector", "4x3", 2, VEC3, MAT4X3, VEC4, 0, &getInputDataD, compareFP16ArithmeticFunc< 3, 16, 4, 0, fp16MatrixTimesVector<4,3> > },
18282 { "OpMatrixTimesVector", "4x4", 2, VEC4, MAT4X4, VEC4, 0, &getInputDataD, compareFP16ArithmeticFunc< 4, 16, 4, 0, fp16MatrixTimesVector<4,4> > },
18283 { "OpMatrixTimesMatrix", "2x2_2x2", 2, MAT2X2, MAT2X2, MAT2X2, 0, &getInputDataD, compareFP16ArithmeticFunc< 4, 4, 4, 0, fp16MatrixTimesMatrix<2,2,2,2> > },
18284 { "OpMatrixTimesMatrix", "2x2_3x2", 2, MAT3X2, MAT2X2, MAT3X2, 0, &getInputDataD, compareFP16ArithmeticFunc< 8, 4, 8, 0, fp16MatrixTimesMatrix<2,2,3,2> > },
18285 { "OpMatrixTimesMatrix", "2x2_4x2", 2, MAT4X2, MAT2X2, MAT4X2, 0, &getInputDataD, compareFP16ArithmeticFunc< 8, 4, 8, 0, fp16MatrixTimesMatrix<2,2,4,2> > },
18286 { "OpMatrixTimesMatrix", "2x3_2x2", 2, MAT2X3, MAT2X3, MAT2X2, 0, &getInputDataD, compareFP16ArithmeticFunc< 8, 8, 4, 0, fp16MatrixTimesMatrix<2,3,2,2> > },
18287 { "OpMatrixTimesMatrix", "2x3_3x2", 2, MAT3X3, MAT2X3, MAT3X2, 0, &getInputDataD, compareFP16ArithmeticFunc< 16, 8, 8, 0, fp16MatrixTimesMatrix<2,3,3,2> > },
18288 { "OpMatrixTimesMatrix", "2x3_4x2", 2, MAT4X3, MAT2X3, MAT4X2, 0, &getInputDataD, compareFP16ArithmeticFunc< 16, 8, 8, 0, fp16MatrixTimesMatrix<2,3,4,2> > },
18289 { "OpMatrixTimesMatrix", "2x4_2x2", 2, MAT2X4, MAT2X4, MAT2X2, 0, &getInputDataD, compareFP16ArithmeticFunc< 8, 8, 4, 0, fp16MatrixTimesMatrix<2,4,2,2> > },
18290 { "OpMatrixTimesMatrix", "2x4_3x2", 2, MAT3X4, MAT2X4, MAT3X2, 0, &getInputDataD, compareFP16ArithmeticFunc< 16, 8, 8, 0, fp16MatrixTimesMatrix<2,4,3,2> > },
18291 { "OpMatrixTimesMatrix", "2x4_4x2", 2, MAT4X4, MAT2X4, MAT4X2, 0, &getInputDataD, compareFP16ArithmeticFunc< 16, 8, 8, 0, fp16MatrixTimesMatrix<2,4,4,2> > },
18292 { "OpMatrixTimesMatrix", "3x2_2x3", 2, MAT2X2, MAT3X2, MAT2X3, 0, &getInputDataD, compareFP16ArithmeticFunc< 4, 8, 8, 0, fp16MatrixTimesMatrix<3,2,2,3> > },
18293 { "OpMatrixTimesMatrix", "3x2_3x3", 2, MAT3X2, MAT3X2, MAT3X3, 0, &getInputDataD, compareFP16ArithmeticFunc< 8, 8, 16, 0, fp16MatrixTimesMatrix<3,2,3,3> > },
18294 { "OpMatrixTimesMatrix", "3x2_4x3", 2, MAT4X2, MAT3X2, MAT4X3, 0, &getInputDataD, compareFP16ArithmeticFunc< 8, 8, 16, 0, fp16MatrixTimesMatrix<3,2,4,3> > },
18295 { "OpMatrixTimesMatrix", "3x3_2x3", 2, MAT2X3, MAT3X3, MAT2X3, 0, &getInputDataD, compareFP16ArithmeticFunc< 8, 16, 8, 0, fp16MatrixTimesMatrix<3,3,2,3> > },
18296 { "OpMatrixTimesMatrix", "3x3_3x3", 2, MAT3X3, MAT3X3, MAT3X3, 0, &getInputDataD, compareFP16ArithmeticFunc< 16, 16, 16, 0, fp16MatrixTimesMatrix<3,3,3,3> > },
18297 { "OpMatrixTimesMatrix", "3x3_4x3", 2, MAT4X3, MAT3X3, MAT4X3, 0, &getInputDataD, compareFP16ArithmeticFunc< 16, 16, 16, 0, fp16MatrixTimesMatrix<3,3,4,3> > },
18298 { "OpMatrixTimesMatrix", "3x4_2x3", 2, MAT2X4, MAT3X4, MAT2X3, 0, &getInputDataD, compareFP16ArithmeticFunc< 8, 16, 8, 0, fp16MatrixTimesMatrix<3,4,2,3> > },
18299 { "OpMatrixTimesMatrix", "3x4_3x3", 2, MAT3X4, MAT3X4, MAT3X3, 0, &getInputDataD, compareFP16ArithmeticFunc< 16, 16, 16, 0, fp16MatrixTimesMatrix<3,4,3,3> > },
18300 { "OpMatrixTimesMatrix", "3x4_4x3", 2, MAT4X4, MAT3X4, MAT4X3, 0, &getInputDataD, compareFP16ArithmeticFunc< 16, 16, 16, 0, fp16MatrixTimesMatrix<3,4,4,3> > },
18301 { "OpMatrixTimesMatrix", "4x2_2x4", 2, MAT2X2, MAT4X2, MAT2X4, 0, &getInputDataD, compareFP16ArithmeticFunc< 4, 8, 8, 0, fp16MatrixTimesMatrix<4,2,2,4> > },
18302 { "OpMatrixTimesMatrix", "4x2_3x4", 2, MAT3X2, MAT4X2, MAT3X4, 0, &getInputDataD, compareFP16ArithmeticFunc< 8, 8, 16, 0, fp16MatrixTimesMatrix<4,2,3,4> > },
18303 { "OpMatrixTimesMatrix", "4x2_4x4", 2, MAT4X2, MAT4X2, MAT4X4, 0, &getInputDataD, compareFP16ArithmeticFunc< 8, 8, 16, 0, fp16MatrixTimesMatrix<4,2,4,4> > },
18304 { "OpMatrixTimesMatrix", "4x3_2x4", 2, MAT2X3, MAT4X3, MAT2X4, 0, &getInputDataD, compareFP16ArithmeticFunc< 8, 16, 8, 0, fp16MatrixTimesMatrix<4,3,2,4> > },
18305 { "OpMatrixTimesMatrix", "4x3_3x4", 2, MAT3X3, MAT4X3, MAT3X4, 0, &getInputDataD, compareFP16ArithmeticFunc< 16, 16, 16, 0, fp16MatrixTimesMatrix<4,3,3,4> > },
18306 { "OpMatrixTimesMatrix", "4x3_4x4", 2, MAT4X3, MAT4X3, MAT4X4, 0, &getInputDataD, compareFP16ArithmeticFunc< 16, 16, 16, 0, fp16MatrixTimesMatrix<4,3,4,4> > },
18307 { "OpMatrixTimesMatrix", "4x4_2x4", 2, MAT2X4, MAT4X4, MAT2X4, 0, &getInputDataD, compareFP16ArithmeticFunc< 8, 16, 8, 0, fp16MatrixTimesMatrix<4,4,2,4> > },
18308 { "OpMatrixTimesMatrix", "4x4_3x4", 2, MAT3X4, MAT4X4, MAT3X4, 0, &getInputDataD, compareFP16ArithmeticFunc< 16, 16, 16, 0, fp16MatrixTimesMatrix<4,4,3,4> > },
18309 { "OpMatrixTimesMatrix", "4x4_4x4", 2, MAT4X4, MAT4X4, MAT4X4, 0, &getInputDataD, compareFP16ArithmeticFunc< 16, 16, 16, 0, fp16MatrixTimesMatrix<4,4,4,4> > },
18310 { "OpOuterProduct", "2x2", 2, MAT2X2, VEC2, VEC2, 0, &getInputDataD, compareFP16ArithmeticFunc< 4, 2, 2, 0, fp16OuterProduct<2,2> > },
18311 { "OpOuterProduct", "2x3", 2, MAT2X3, VEC3, VEC2, 0, &getInputDataD, compareFP16ArithmeticFunc< 8, 3, 2, 0, fp16OuterProduct<2,3> > },
18312 { "OpOuterProduct", "2x4", 2, MAT2X4, VEC4, VEC2, 0, &getInputDataD, compareFP16ArithmeticFunc< 8, 4, 2, 0, fp16OuterProduct<2,4> > },
18313 { "OpOuterProduct", "3x2", 2, MAT3X2, VEC2, VEC3, 0, &getInputDataD, compareFP16ArithmeticFunc< 8, 2, 3, 0, fp16OuterProduct<3,2> > },
18314 { "OpOuterProduct", "3x3", 2, MAT3X3, VEC3, VEC3, 0, &getInputDataD, compareFP16ArithmeticFunc< 16, 3, 3, 0, fp16OuterProduct<3,3> > },
18315 { "OpOuterProduct", "3x4", 2, MAT3X4, VEC4, VEC3, 0, &getInputDataD, compareFP16ArithmeticFunc< 16, 4, 3, 0, fp16OuterProduct<3,4> > },
18316 { "OpOuterProduct", "4x2", 2, MAT4X2, VEC2, VEC4, 0, &getInputDataD, compareFP16ArithmeticFunc< 8, 2, 4, 0, fp16OuterProduct<4,2> > },
18317 { "OpOuterProduct", "4x3", 2, MAT4X3, VEC3, VEC4, 0, &getInputDataD, compareFP16ArithmeticFunc< 16, 3, 4, 0, fp16OuterProduct<4,3> > },
18318 { "OpOuterProduct", "4x4", 2, MAT4X4, VEC4, VEC4, 0, &getInputDataD, compareFP16ArithmeticFunc< 16, 4, 4, 0, fp16OuterProduct<4,4> > },
18319 { "Determinant", "2x2", 1, SCALAR, MAT2X2, NONE, 0, &getInputDataC, compareFP16ArithmeticFunc< 1, 4, 0, 0, fp16Determinant<2> > },
18320 { "Determinant", "3x3", 1, SCALAR, MAT3X3, NONE, 0, &getInputDataC, compareFP16ArithmeticFunc< 1, 16, 0, 0, fp16Determinant<3> > },
18321 { "Determinant", "4x4", 1, SCALAR, MAT4X4, NONE, 0, &getInputDataC, compareFP16ArithmeticFunc< 1, 16, 0, 0, fp16Determinant<4> > },
18322 { "MatrixInverse", "2x2", 1, MAT2X2, MAT2X2, NONE, 0, &getInputDataC, compareFP16ArithmeticFunc< 4, 4, 0, 0, fp16Inverse<2> > },
18325 for (deUint32 testFuncIdx = 0; testFuncIdx < DE_LENGTH_OF_ARRAY(testFuncs); ++testFuncIdx)
18327 const Math16TestFunc& testFunc = testFuncs[testFuncIdx];
18329 createFloat16ArithmeticFuncTest<SpecResource>(testCtx, *testGroup.get(), 0, testFunc);
18332 return testGroup.release();
18335 const string getNumberTypeName (const NumberType type)
18337 if (type == NUMBERTYPE_INT32)
18341 else if (type == NUMBERTYPE_UINT32)
18345 else if (type == NUMBERTYPE_FLOAT32)
18356 deInt32 getInt(de::Random& rnd)
18358 return rnd.getInt(std::numeric_limits<int>::min(), std::numeric_limits<int>::max());
18361 const string repeatString (const string& str, int times)
18364 for (int i = 0; i < times; ++i)
18371 const string getRandomConstantString (const NumberType type, de::Random& rnd)
18373 if (type == NUMBERTYPE_INT32)
18375 return numberToString<deInt32>(getInt(rnd));
18377 else if (type == NUMBERTYPE_UINT32)
18379 return numberToString<deUint32>(rnd.getUint32());
18381 else if (type == NUMBERTYPE_FLOAT32)
18383 return numberToString<float>(rnd.getFloat());
18392 void createVectorCompositeCases (vector<map<string, string> >& testCases, de::Random& rnd, const NumberType type)
18394 map<string, string> params;
18397 for (int width = 2; width <= 4; ++width)
18399 const string randomConst = numberToString(getInt(rnd));
18400 const string widthStr = numberToString(width);
18401 const string composite_type = "${customType}vec" + widthStr;
18402 const int index = rnd.getInt(0, width-1);
18404 params["type"] = "vec";
18405 params["name"] = params["type"] + "_" + widthStr;
18406 params["compositeDecl"] = composite_type + " = OpTypeVector ${customType} " + widthStr +"\n";
18407 params["compositeType"] = composite_type;
18408 params["filler"] = string("%filler = OpConstant ${customType} ") + getRandomConstantString(type, rnd) + "\n";
18409 params["compositeConstruct"] = "%instance = OpCompositeConstruct " + composite_type + repeatString(" %filler", width) + "\n";
18410 params["indexes"] = numberToString(index);
18411 testCases.push_back(params);
18415 void createArrayCompositeCases (vector<map<string, string> >& testCases, de::Random& rnd, const NumberType type)
18417 const int limit = 10;
18418 map<string, string> params;
18420 for (int width = 2; width <= limit; ++width)
18422 string randomConst = numberToString(getInt(rnd));
18423 string widthStr = numberToString(width);
18424 int index = rnd.getInt(0, width-1);
18426 params["type"] = "array";
18427 params["name"] = params["type"] + "_" + widthStr;
18428 params["compositeDecl"] = string("%arraywidth = OpConstant %u32 " + widthStr + "\n")
18429 + "%composite = OpTypeArray ${customType} %arraywidth\n";
18430 params["compositeType"] = "%composite";
18431 params["filler"] = string("%filler = OpConstant ${customType} ") + getRandomConstantString(type, rnd) + "\n";
18432 params["compositeConstruct"] = "%instance = OpCompositeConstruct %composite" + repeatString(" %filler", width) + "\n";
18433 params["indexes"] = numberToString(index);
18434 testCases.push_back(params);
18438 void createStructCompositeCases (vector<map<string, string> >& testCases, de::Random& rnd, const NumberType type)
18440 const int limit = 10;
18441 map<string, string> params;
18443 for (int width = 2; width <= limit; ++width)
18445 string randomConst = numberToString(getInt(rnd));
18446 int index = rnd.getInt(0, width-1);
18448 params["type"] = "struct";
18449 params["name"] = params["type"] + "_" + numberToString(width);
18450 params["compositeDecl"] = "%composite = OpTypeStruct" + repeatString(" ${customType}", width) + "\n";
18451 params["compositeType"] = "%composite";
18452 params["filler"] = string("%filler = OpConstant ${customType} ") + getRandomConstantString(type, rnd) + "\n";
18453 params["compositeConstruct"] = "%instance = OpCompositeConstruct %composite" + repeatString(" %filler", width) + "\n";
18454 params["indexes"] = numberToString(index);
18455 testCases.push_back(params);
18459 void createMatrixCompositeCases (vector<map<string, string> >& testCases, de::Random& rnd, const NumberType type)
18461 map<string, string> params;
18464 for (int width = 2; width <= 4; ++width)
18466 string widthStr = numberToString(width);
18468 for (int column = 2 ; column <= 4; ++column)
18470 int index_0 = rnd.getInt(0, column-1);
18471 int index_1 = rnd.getInt(0, width-1);
18472 string columnStr = numberToString(column);
18474 params["type"] = "matrix";
18475 params["name"] = params["type"] + "_" + widthStr + "x" + columnStr;
18476 params["compositeDecl"] = string("%vectype = OpTypeVector ${customType} " + widthStr + "\n")
18477 + "%composite = OpTypeMatrix %vectype " + columnStr + "\n";
18478 params["compositeType"] = "%composite";
18480 params["filler"] = string("%filler = OpConstant ${customType} ") + getRandomConstantString(type, rnd) + "\n"
18481 + "%fillerVec = OpConstantComposite %vectype" + repeatString(" %filler", width) + "\n";
18483 params["compositeConstruct"] = "%instance = OpCompositeConstruct %composite" + repeatString(" %fillerVec", column) + "\n";
18484 params["indexes"] = numberToString(index_0) + " " + numberToString(index_1);
18485 testCases.push_back(params);
18490 void createCompositeCases (vector<map<string, string> >& testCases, de::Random& rnd, const NumberType type)
18492 createVectorCompositeCases(testCases, rnd, type);
18493 createArrayCompositeCases(testCases, rnd, type);
18494 createStructCompositeCases(testCases, rnd, type);
18495 // Matrix only supports float types
18496 if (type == NUMBERTYPE_FLOAT32)
18498 createMatrixCompositeCases(testCases, rnd, type);
18502 const string getAssemblyTypeDeclaration (const NumberType type)
18506 case NUMBERTYPE_INT32: return "OpTypeInt 32 1";
18507 case NUMBERTYPE_UINT32: return "OpTypeInt 32 0";
18508 case NUMBERTYPE_FLOAT32: return "OpTypeFloat 32";
18509 default: DE_ASSERT(false); return "";
18513 const string getAssemblyTypeName (const NumberType type)
18517 case NUMBERTYPE_INT32: return "%i32";
18518 case NUMBERTYPE_UINT32: return "%u32";
18519 case NUMBERTYPE_FLOAT32: return "%f32";
18520 default: DE_ASSERT(false); return "";
18524 const string specializeCompositeInsertShaderTemplate (const NumberType type, const map<string, string>& params)
18526 map<string, string> parameters(params);
18528 const string customType = getAssemblyTypeName(type);
18529 map<string, string> substCustomType;
18530 substCustomType["customType"] = customType;
18531 parameters["compositeDecl"] = StringTemplate(parameters.at("compositeDecl")).specialize(substCustomType);
18532 parameters["compositeType"] = StringTemplate(parameters.at("compositeType")).specialize(substCustomType);
18533 parameters["compositeConstruct"] = StringTemplate(parameters.at("compositeConstruct")).specialize(substCustomType);
18534 parameters["filler"] = StringTemplate(parameters.at("filler")).specialize(substCustomType);
18535 parameters["customType"] = customType;
18536 parameters["compositeDecorator"] = (parameters["type"] == "array") ? "OpDecorate %composite ArrayStride 4\n" : "";
18538 if (parameters.at("compositeType") != "%u32vec3")
18540 parameters["u32vec3Decl"] = "%u32vec3 = OpTypeVector %u32 3\n";
18543 return StringTemplate(
18544 "OpCapability Shader\n"
18545 "OpCapability Matrix\n"
18546 "OpMemoryModel Logical GLSL450\n"
18547 "OpEntryPoint GLCompute %main \"main\" %id\n"
18548 "OpExecutionMode %main LocalSize 1 1 1\n"
18550 "OpSource GLSL 430\n"
18551 "OpName %main \"main\"\n"
18552 "OpName %id \"gl_GlobalInvocationID\"\n"
18555 "OpDecorate %id BuiltIn GlobalInvocationId\n"
18556 "OpDecorate %buf BufferBlock\n"
18557 "OpDecorate %indata DescriptorSet 0\n"
18558 "OpDecorate %indata Binding 0\n"
18559 "OpDecorate %outdata DescriptorSet 0\n"
18560 "OpDecorate %outdata Binding 1\n"
18561 "OpDecorate %customarr ArrayStride 4\n"
18562 "${compositeDecorator}"
18563 "OpMemberDecorate %buf 0 Offset 0\n"
18566 "%void = OpTypeVoid\n"
18567 "%voidf = OpTypeFunction %void\n"
18568 "%u32 = OpTypeInt 32 0\n"
18569 "%i32 = OpTypeInt 32 1\n"
18570 "%f32 = OpTypeFloat 32\n"
18572 // Composite declaration
18578 "${u32vec3Decl:opt}"
18579 "%uvec3ptr = OpTypePointer Input %u32vec3\n"
18581 // Inherited from custom
18582 "%customptr = OpTypePointer Uniform ${customType}\n"
18583 "%customarr = OpTypeRuntimeArray ${customType}\n"
18584 "%buf = OpTypeStruct %customarr\n"
18585 "%bufptr = OpTypePointer Uniform %buf\n"
18587 "%indata = OpVariable %bufptr Uniform\n"
18588 "%outdata = OpVariable %bufptr Uniform\n"
18590 "%id = OpVariable %uvec3ptr Input\n"
18591 "%zero = OpConstant %i32 0\n"
18593 "%main = OpFunction %void None %voidf\n"
18594 "%label = OpLabel\n"
18595 "%idval = OpLoad %u32vec3 %id\n"
18596 "%x = OpCompositeExtract %u32 %idval 0\n"
18598 "%inloc = OpAccessChain %customptr %indata %zero %x\n"
18599 "%outloc = OpAccessChain %customptr %outdata %zero %x\n"
18600 // Read the input value
18601 "%inval = OpLoad ${customType} %inloc\n"
18602 // Create the composite and fill it
18603 "${compositeConstruct}"
18604 // Insert the input value to a place
18605 "%instance2 = OpCompositeInsert ${compositeType} %inval %instance ${indexes}\n"
18606 // Read back the value from the position
18607 "%out_val = OpCompositeExtract ${customType} %instance2 ${indexes}\n"
18608 // Store it in the output position
18609 " OpStore %outloc %out_val\n"
18612 ).specialize(parameters);
18615 template<typename T>
18616 BufferSp createCompositeBuffer(T number)
18618 return BufferSp(new Buffer<T>(vector<T>(1, number)));
18621 tcu::TestCaseGroup* createOpCompositeInsertGroup (tcu::TestContext& testCtx)
18623 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opcompositeinsert", "Test the OpCompositeInsert instruction"));
18624 de::Random rnd (deStringHash(group->getName()));
18626 for (int type = NUMBERTYPE_INT32; type != NUMBERTYPE_END32; ++type)
18628 NumberType numberType = NumberType(type);
18629 const string typeName = getNumberTypeName(numberType);
18630 const string description = "Test the OpCompositeInsert instruction with " + typeName + "s";
18631 de::MovePtr<tcu::TestCaseGroup> subGroup (new tcu::TestCaseGroup(testCtx, typeName.c_str(), description.c_str()));
18632 vector<map<string, string> > testCases;
18634 createCompositeCases(testCases, rnd, numberType);
18636 for (vector<map<string, string> >::const_iterator test = testCases.begin(); test != testCases.end(); ++test)
18638 ComputeShaderSpec spec;
18640 spec.assembly = specializeCompositeInsertShaderTemplate(numberType, *test);
18642 switch (numberType)
18644 case NUMBERTYPE_INT32:
18646 deInt32 number = getInt(rnd);
18647 spec.inputs.push_back(createCompositeBuffer<deInt32>(number));
18648 spec.outputs.push_back(createCompositeBuffer<deInt32>(number));
18651 case NUMBERTYPE_UINT32:
18653 deUint32 number = rnd.getUint32();
18654 spec.inputs.push_back(createCompositeBuffer<deUint32>(number));
18655 spec.outputs.push_back(createCompositeBuffer<deUint32>(number));
18658 case NUMBERTYPE_FLOAT32:
18660 float number = rnd.getFloat();
18661 spec.inputs.push_back(createCompositeBuffer<float>(number));
18662 spec.outputs.push_back(createCompositeBuffer<float>(number));
18669 spec.numWorkGroups = IVec3(1, 1, 1);
18670 subGroup->addChild(new SpvAsmComputeShaderCase(testCtx, test->at("name").c_str(), "OpCompositeInsert test", spec));
18672 group->addChild(subGroup.release());
18674 return group.release();
18677 struct AssemblyStructInfo
18679 AssemblyStructInfo (const deUint32 comp, const deUint32 idx)
18680 : components (comp)
18684 deUint32 components;
18688 const string specializeInBoundsShaderTemplate (const NumberType type, const AssemblyStructInfo& structInfo, const map<string, string>& params)
18690 // Create the full index string
18691 string fullIndex = numberToString(structInfo.index) + " " + params.at("indexes");
18692 // Convert it to list of indexes
18693 vector<string> indexes = de::splitString(fullIndex, ' ');
18695 map<string, string> parameters (params);
18696 parameters["structType"] = repeatString(" ${compositeType}", structInfo.components);
18697 parameters["structConstruct"] = repeatString(" %instance", structInfo.components);
18698 parameters["insertIndexes"] = fullIndex;
18700 // In matrix cases the last two index is the CompositeExtract indexes
18701 const deUint32 extractIndexes = (parameters["type"] == "matrix") ? 2 : 1;
18703 // Construct the extractIndex
18704 for (vector<string>::const_iterator index = indexes.end() - extractIndexes; index != indexes.end(); ++index)
18706 parameters["extractIndexes"] += " " + *index;
18709 // Remove the last 1 or 2 element depends on matrix case or not
18710 indexes.erase(indexes.end() - extractIndexes, indexes.end());
18713 // Generate AccessChain index expressions (except for the last one, because we use ptr to the composite)
18714 for (vector<string>::const_iterator index = indexes.begin(); index != indexes.end(); ++index)
18716 string indexId = "%index_" + numberToString(id++);
18717 parameters["accessChainConstDeclaration"] += indexId + " = OpConstant %u32 " + *index + "\n";
18718 parameters["accessChainIndexes"] += " " + indexId;
18721 parameters["compositeDecorator"] = (parameters["type"] == "array") ? "OpDecorate %composite ArrayStride 4\n" : "";
18723 const string customType = getAssemblyTypeName(type);
18724 map<string, string> substCustomType;
18725 substCustomType["customType"] = customType;
18726 parameters["compositeDecl"] = StringTemplate(parameters.at("compositeDecl")).specialize(substCustomType);
18727 parameters["compositeType"] = StringTemplate(parameters.at("compositeType")).specialize(substCustomType);
18728 parameters["compositeConstruct"] = StringTemplate(parameters.at("compositeConstruct")).specialize(substCustomType);
18729 parameters["filler"] = StringTemplate(parameters.at("filler")).specialize(substCustomType);
18730 parameters["customType"] = customType;
18732 const string compositeType = parameters.at("compositeType");
18733 map<string, string> substCompositeType;
18734 substCompositeType["compositeType"] = compositeType;
18735 parameters["structType"] = StringTemplate(parameters.at("structType")).specialize(substCompositeType);
18736 if (compositeType != "%u32vec3")
18738 parameters["u32vec3Decl"] = "%u32vec3 = OpTypeVector %u32 3\n";
18741 return StringTemplate(
18742 "OpCapability Shader\n"
18743 "OpCapability Matrix\n"
18744 "OpMemoryModel Logical GLSL450\n"
18745 "OpEntryPoint GLCompute %main \"main\" %id\n"
18746 "OpExecutionMode %main LocalSize 1 1 1\n"
18748 "OpSource GLSL 430\n"
18749 "OpName %main \"main\"\n"
18750 "OpName %id \"gl_GlobalInvocationID\"\n"
18752 "OpDecorate %id BuiltIn GlobalInvocationId\n"
18753 "OpDecorate %buf BufferBlock\n"
18754 "OpDecorate %indata DescriptorSet 0\n"
18755 "OpDecorate %indata Binding 0\n"
18756 "OpDecorate %outdata DescriptorSet 0\n"
18757 "OpDecorate %outdata Binding 1\n"
18758 "OpDecorate %customarr ArrayStride 4\n"
18759 "${compositeDecorator}"
18760 "OpMemberDecorate %buf 0 Offset 0\n"
18762 "%void = OpTypeVoid\n"
18763 "%voidf = OpTypeFunction %void\n"
18764 "%i32 = OpTypeInt 32 1\n"
18765 "%u32 = OpTypeInt 32 0\n"
18766 "%f32 = OpTypeFloat 32\n"
18769 // %u32vec3 if not already declared in ${compositeDecl}
18770 "${u32vec3Decl:opt}"
18771 "%uvec3ptr = OpTypePointer Input %u32vec3\n"
18772 // Inherited from composite
18773 "%composite_p = OpTypePointer Function ${compositeType}\n"
18774 "%struct_t = OpTypeStruct${structType}\n"
18775 "%struct_p = OpTypePointer Function %struct_t\n"
18778 "${accessChainConstDeclaration}"
18779 // Inherited from custom
18780 "%customptr = OpTypePointer Uniform ${customType}\n"
18781 "%customarr = OpTypeRuntimeArray ${customType}\n"
18782 "%buf = OpTypeStruct %customarr\n"
18783 "%bufptr = OpTypePointer Uniform %buf\n"
18784 "%indata = OpVariable %bufptr Uniform\n"
18785 "%outdata = OpVariable %bufptr Uniform\n"
18787 "%id = OpVariable %uvec3ptr Input\n"
18788 "%zero = OpConstant %u32 0\n"
18789 "%main = OpFunction %void None %voidf\n"
18790 "%label = OpLabel\n"
18791 "%struct_v = OpVariable %struct_p Function\n"
18792 "%idval = OpLoad %u32vec3 %id\n"
18793 "%x = OpCompositeExtract %u32 %idval 0\n"
18794 // Create the input/output type
18795 "%inloc = OpInBoundsAccessChain %customptr %indata %zero %x\n"
18796 "%outloc = OpInBoundsAccessChain %customptr %outdata %zero %x\n"
18797 // Read the input value
18798 "%inval = OpLoad ${customType} %inloc\n"
18799 // Create the composite and fill it
18800 "${compositeConstruct}"
18801 // Create the struct and fill it with the composite
18802 "%struct = OpCompositeConstruct %struct_t${structConstruct}\n"
18803 // Insert the value
18804 "%comp_obj = OpCompositeInsert %struct_t %inval %struct ${insertIndexes}\n"
18805 // Store the object
18806 " OpStore %struct_v %comp_obj\n"
18807 // Get deepest possible composite pointer
18808 "%inner_ptr = OpInBoundsAccessChain %composite_p %struct_v${accessChainIndexes}\n"
18809 "%read_obj = OpLoad ${compositeType} %inner_ptr\n"
18810 // Read back the stored value
18811 "%read_val = OpCompositeExtract ${customType} %read_obj${extractIndexes}\n"
18812 " OpStore %outloc %read_val\n"
18815 ).specialize(parameters);
18818 tcu::TestCaseGroup* createOpInBoundsAccessChainGroup (tcu::TestContext& testCtx)
18820 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opinboundsaccesschain", "Test the OpInBoundsAccessChain instruction"));
18821 de::Random rnd (deStringHash(group->getName()));
18823 for (int type = NUMBERTYPE_INT32; type != NUMBERTYPE_END32; ++type)
18825 NumberType numberType = NumberType(type);
18826 const string typeName = getNumberTypeName(numberType);
18827 const string description = "Test the OpInBoundsAccessChain instruction with " + typeName + "s";
18828 de::MovePtr<tcu::TestCaseGroup> subGroup (new tcu::TestCaseGroup(testCtx, typeName.c_str(), description.c_str()));
18830 vector<map<string, string> > testCases;
18831 createCompositeCases(testCases, rnd, numberType);
18833 for (vector<map<string, string> >::const_iterator test = testCases.begin(); test != testCases.end(); ++test)
18835 ComputeShaderSpec spec;
18837 // Number of components inside of a struct
18838 deUint32 structComponents = rnd.getInt(2, 8);
18839 // Component index value
18840 deUint32 structIndex = rnd.getInt(0, structComponents - 1);
18841 AssemblyStructInfo structInfo(structComponents, structIndex);
18843 spec.assembly = specializeInBoundsShaderTemplate(numberType, structInfo, *test);
18845 switch (numberType)
18847 case NUMBERTYPE_INT32:
18849 deInt32 number = getInt(rnd);
18850 spec.inputs.push_back(createCompositeBuffer<deInt32>(number));
18851 spec.outputs.push_back(createCompositeBuffer<deInt32>(number));
18854 case NUMBERTYPE_UINT32:
18856 deUint32 number = rnd.getUint32();
18857 spec.inputs.push_back(createCompositeBuffer<deUint32>(number));
18858 spec.outputs.push_back(createCompositeBuffer<deUint32>(number));
18861 case NUMBERTYPE_FLOAT32:
18863 float number = rnd.getFloat();
18864 spec.inputs.push_back(createCompositeBuffer<float>(number));
18865 spec.outputs.push_back(createCompositeBuffer<float>(number));
18871 spec.numWorkGroups = IVec3(1, 1, 1);
18872 subGroup->addChild(new SpvAsmComputeShaderCase(testCtx, test->at("name").c_str(), "OpInBoundsAccessChain test", spec));
18874 group->addChild(subGroup.release());
18876 return group.release();
18879 // If the params missing, uninitialized case
18880 const string specializeDefaultOutputShaderTemplate (const NumberType type, const map<string, string>& params = map<string, string>())
18882 map<string, string> parameters(params);
18884 parameters["customType"] = getAssemblyTypeName(type);
18886 // Declare the const value, and use it in the initializer
18887 if (params.find("constValue") != params.end())
18889 parameters["variableInitializer"] = " %const";
18891 // Uninitialized case
18894 parameters["commentDecl"] = ";";
18897 return StringTemplate(
18898 "OpCapability Shader\n"
18899 "OpMemoryModel Logical GLSL450\n"
18900 "OpEntryPoint GLCompute %main \"main\" %id\n"
18901 "OpExecutionMode %main LocalSize 1 1 1\n"
18902 "OpSource GLSL 430\n"
18903 "OpName %main \"main\"\n"
18904 "OpName %id \"gl_GlobalInvocationID\"\n"
18906 "OpDecorate %id BuiltIn GlobalInvocationId\n"
18907 "OpDecorate %indata DescriptorSet 0\n"
18908 "OpDecorate %indata Binding 0\n"
18909 "OpDecorate %outdata DescriptorSet 0\n"
18910 "OpDecorate %outdata Binding 1\n"
18911 "OpDecorate %in_arr ArrayStride 4\n"
18912 "OpDecorate %in_buf BufferBlock\n"
18913 "OpMemberDecorate %in_buf 0 Offset 0\n"
18915 "%void = OpTypeVoid\n"
18916 "%voidf = OpTypeFunction %void\n"
18917 "%u32 = OpTypeInt 32 0\n"
18918 "%i32 = OpTypeInt 32 1\n"
18919 "%f32 = OpTypeFloat 32\n"
18920 "%uvec3 = OpTypeVector %u32 3\n"
18921 "%uvec3ptr = OpTypePointer Input %uvec3\n"
18922 "${commentDecl:opt}%const = OpConstant ${customType} ${constValue:opt}\n"
18924 "%in_ptr = OpTypePointer Uniform ${customType}\n"
18925 "%in_arr = OpTypeRuntimeArray ${customType}\n"
18926 "%in_buf = OpTypeStruct %in_arr\n"
18927 "%in_bufptr = OpTypePointer Uniform %in_buf\n"
18928 "%indata = OpVariable %in_bufptr Uniform\n"
18929 "%outdata = OpVariable %in_bufptr Uniform\n"
18930 "%id = OpVariable %uvec3ptr Input\n"
18931 "%var_ptr = OpTypePointer Function ${customType}\n"
18933 "%zero = OpConstant %i32 0\n"
18935 "%main = OpFunction %void None %voidf\n"
18936 "%label = OpLabel\n"
18937 "%out_var = OpVariable %var_ptr Function${variableInitializer:opt}\n"
18938 "%idval = OpLoad %uvec3 %id\n"
18939 "%x = OpCompositeExtract %u32 %idval 0\n"
18940 "%inloc = OpAccessChain %in_ptr %indata %zero %x\n"
18941 "%outloc = OpAccessChain %in_ptr %outdata %zero %x\n"
18943 "%outval = OpLoad ${customType} %out_var\n"
18944 " OpStore %outloc %outval\n"
18947 ).specialize(parameters);
18950 bool compareFloats (const std::vector<Resource>&, const vector<AllocationSp>& outputAllocs, const std::vector<Resource>& expectedOutputs, TestLog& log)
18952 DE_ASSERT(outputAllocs.size() != 0);
18953 DE_ASSERT(outputAllocs.size() == expectedOutputs.size());
18955 // Use custom epsilon because of the float->string conversion
18956 const float epsilon = 0.00001f;
18958 for (size_t outputNdx = 0; outputNdx < outputAllocs.size(); ++outputNdx)
18960 vector<deUint8> expectedBytes;
18964 expectedOutputs[outputNdx].getBytes(expectedBytes);
18965 memcpy(&expected, &expectedBytes.front(), expectedBytes.size());
18966 memcpy(&actual, outputAllocs[outputNdx]->getHostPtr(), expectedBytes.size());
18968 // Test with epsilon
18969 if (fabs(expected - actual) > epsilon)
18971 log << TestLog::Message << "Error: The actual and expected values not matching."
18972 << " Expected: " << expected << " Actual: " << actual << " Epsilon: " << epsilon << TestLog::EndMessage;
18979 // Checks if the driver crash with uninitialized cases
18980 bool passthruVerify (const std::vector<Resource>&, const vector<AllocationSp>& outputAllocs, const std::vector<Resource>& expectedOutputs, TestLog&)
18982 DE_ASSERT(outputAllocs.size() != 0);
18983 DE_ASSERT(outputAllocs.size() == expectedOutputs.size());
18985 // Copy and discard the result.
18986 for (size_t outputNdx = 0; outputNdx < outputAllocs.size(); ++outputNdx)
18988 vector<deUint8> expectedBytes;
18989 expectedOutputs[outputNdx].getBytes(expectedBytes);
18991 const size_t width = expectedBytes.size();
18992 vector<char> data (width);
18994 memcpy(&data[0], outputAllocs[outputNdx]->getHostPtr(), width);
18999 tcu::TestCaseGroup* createShaderDefaultOutputGroup (tcu::TestContext& testCtx)
19001 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "shader_default_output", "Test shader default output."));
19002 de::Random rnd (deStringHash(group->getName()));
19004 for (int type = NUMBERTYPE_INT32; type != NUMBERTYPE_END32; ++type)
19006 NumberType numberType = NumberType(type);
19007 const string typeName = getNumberTypeName(numberType);
19008 const string description = "Test the OpVariable initializer with " + typeName + ".";
19009 de::MovePtr<tcu::TestCaseGroup> subGroup (new tcu::TestCaseGroup(testCtx, typeName.c_str(), description.c_str()));
19011 // 2 similar subcases (initialized and uninitialized)
19012 for (int subCase = 0; subCase < 2; ++subCase)
19014 ComputeShaderSpec spec;
19015 spec.numWorkGroups = IVec3(1, 1, 1);
19017 map<string, string> params;
19019 switch (numberType)
19021 case NUMBERTYPE_INT32:
19023 deInt32 number = getInt(rnd);
19024 spec.inputs.push_back(createCompositeBuffer<deInt32>(number));
19025 spec.outputs.push_back(createCompositeBuffer<deInt32>(number));
19026 params["constValue"] = numberToString(number);
19029 case NUMBERTYPE_UINT32:
19031 deUint32 number = rnd.getUint32();
19032 spec.inputs.push_back(createCompositeBuffer<deUint32>(number));
19033 spec.outputs.push_back(createCompositeBuffer<deUint32>(number));
19034 params["constValue"] = numberToString(number);
19037 case NUMBERTYPE_FLOAT32:
19039 float number = rnd.getFloat();
19040 spec.inputs.push_back(createCompositeBuffer<float>(number));
19041 spec.outputs.push_back(createCompositeBuffer<float>(number));
19042 spec.verifyIO = &compareFloats;
19043 params["constValue"] = numberToString(number);
19050 // Initialized subcase
19053 spec.assembly = specializeDefaultOutputShaderTemplate(numberType, params);
19054 subGroup->addChild(new SpvAsmComputeShaderCase(testCtx, "initialized", "OpVariable initializer tests.", spec));
19056 // Uninitialized subcase
19059 spec.assembly = specializeDefaultOutputShaderTemplate(numberType);
19060 spec.verifyIO = &passthruVerify;
19061 subGroup->addChild(new SpvAsmComputeShaderCase(testCtx, "uninitialized", "OpVariable initializer tests.", spec));
19064 group->addChild(subGroup.release());
19066 return group.release();
19069 tcu::TestCaseGroup* createOpNopTests (tcu::TestContext& testCtx)
19071 de::MovePtr<tcu::TestCaseGroup> testGroup (new tcu::TestCaseGroup(testCtx, "opnop", "Test OpNop"));
19072 RGBA defaultColors[4];
19073 map<string, string> opNopFragments;
19075 getDefaultColors(defaultColors);
19077 opNopFragments["testfun"] =
19078 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
19079 "%param1 = OpFunctionParameter %v4f32\n"
19080 "%label_testfun = OpLabel\n"
19089 "%a = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
19090 "%b = OpFAdd %f32 %a %a\n"
19092 "%c = OpFSub %f32 %b %a\n"
19093 "%ret = OpVectorInsertDynamic %v4f32 %param1 %c %c_i32_0\n"
19096 "OpReturnValue %ret\n"
19099 createTestsForAllStages("opnop", defaultColors, defaultColors, opNopFragments, testGroup.get());
19101 return testGroup.release();
19104 tcu::TestCaseGroup* createOpNameTests (tcu::TestContext& testCtx)
19106 de::MovePtr<tcu::TestCaseGroup> testGroup (new tcu::TestCaseGroup(testCtx, "opname","Test OpName"));
19107 RGBA defaultColors[4];
19108 map<string, string> opNameFragments;
19110 getDefaultColors(defaultColors);
19112 opNameFragments["testfun"] =
19113 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
19114 "%param1 = OpFunctionParameter %v4f32\n"
19115 "%label_func = OpLabel\n"
19116 "%a = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
19117 "%b = OpFAdd %f32 %a %a\n"
19118 "%c = OpFSub %f32 %b %a\n"
19119 "%ret = OpVectorInsertDynamic %v4f32 %param1 %c %c_i32_0\n"
19120 "OpReturnValue %ret\n"
19123 opNameFragments["debug"] =
19124 "OpName %BP_main \"not_main\"";
19126 createTestsForAllStages("opname", defaultColors, defaultColors, opNameFragments, testGroup.get());
19128 return testGroup.release();
19131 tcu::TestCaseGroup* createFloat16Tests (tcu::TestContext& testCtx)
19133 de::MovePtr<tcu::TestCaseGroup> testGroup (new tcu::TestCaseGroup(testCtx, "float16", "Float 16 tests"));
19135 testGroup->addChild(createOpConstantFloat16Tests(testCtx));
19136 testGroup->addChild(createFloat16LogicalSet<GraphicsResources>(testCtx, TEST_WITH_NAN));
19137 testGroup->addChild(createFloat16LogicalSet<GraphicsResources>(testCtx, TEST_WITHOUT_NAN));
19138 testGroup->addChild(createFloat16FuncSet<GraphicsResources>(testCtx));
19139 testGroup->addChild(createFloat16VectorExtractSet<GraphicsResources>(testCtx));
19140 testGroup->addChild(createFloat16VectorInsertSet<GraphicsResources>(testCtx));
19141 testGroup->addChild(createFloat16VectorShuffleSet<GraphicsResources>(testCtx));
19142 testGroup->addChild(createFloat16CompositeConstructSet<GraphicsResources>(testCtx));
19143 testGroup->addChild(createFloat16CompositeInsertExtractSet<GraphicsResources>(testCtx, "OpCompositeExtract"));
19144 testGroup->addChild(createFloat16CompositeInsertExtractSet<GraphicsResources>(testCtx, "OpCompositeInsert"));
19145 testGroup->addChild(createFloat16ArithmeticSet<GraphicsResources>(testCtx));
19146 testGroup->addChild(createFloat16ArithmeticSet<1, GraphicsResources>(testCtx));
19147 testGroup->addChild(createFloat16ArithmeticSet<2, GraphicsResources>(testCtx));
19148 testGroup->addChild(createFloat16ArithmeticSet<3, GraphicsResources>(testCtx));
19149 testGroup->addChild(createFloat16ArithmeticSet<4, GraphicsResources>(testCtx));
19151 return testGroup.release();
19154 tcu::TestCaseGroup* createFloat16Group (tcu::TestContext& testCtx)
19156 de::MovePtr<tcu::TestCaseGroup> testGroup (new tcu::TestCaseGroup(testCtx, "float16", "Float 16 tests"));
19158 testGroup->addChild(createFloat16OpConstantCompositeGroup(testCtx));
19159 testGroup->addChild(createFloat16LogicalSet<ComputeShaderSpec>(testCtx, TEST_WITH_NAN));
19160 testGroup->addChild(createFloat16LogicalSet<ComputeShaderSpec>(testCtx, TEST_WITHOUT_NAN));
19161 testGroup->addChild(createFloat16FuncSet<ComputeShaderSpec>(testCtx));
19162 testGroup->addChild(createFloat16VectorExtractSet<ComputeShaderSpec>(testCtx));
19163 testGroup->addChild(createFloat16VectorInsertSet<ComputeShaderSpec>(testCtx));
19164 testGroup->addChild(createFloat16VectorShuffleSet<ComputeShaderSpec>(testCtx));
19165 testGroup->addChild(createFloat16CompositeConstructSet<ComputeShaderSpec>(testCtx));
19166 testGroup->addChild(createFloat16CompositeInsertExtractSet<ComputeShaderSpec>(testCtx, "OpCompositeExtract"));
19167 testGroup->addChild(createFloat16CompositeInsertExtractSet<ComputeShaderSpec>(testCtx, "OpCompositeInsert"));
19168 testGroup->addChild(createFloat16ArithmeticSet<ComputeShaderSpec>(testCtx));
19169 testGroup->addChild(createFloat16ArithmeticSet<1, ComputeShaderSpec>(testCtx));
19170 testGroup->addChild(createFloat16ArithmeticSet<2, ComputeShaderSpec>(testCtx));
19171 testGroup->addChild(createFloat16ArithmeticSet<3, ComputeShaderSpec>(testCtx));
19172 testGroup->addChild(createFloat16ArithmeticSet<4, ComputeShaderSpec>(testCtx));
19174 return testGroup.release();
19177 tcu::TestCaseGroup* createBoolMixedBitSizeGroup (tcu::TestContext& testCtx)
19179 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "mixed_bitsize", "Tests boolean operands produced from instructions of different bit-sizes"));
19181 de::Random rnd (deStringHash(group->getName()));
19182 const int numElements = 100;
19183 vector<float> inputData (numElements, 0);
19184 vector<float> outputData (numElements, 0);
19185 fillRandomScalars(rnd, 0.0f, 100.0f, &inputData[0], 100);
19187 const StringTemplate shaderTemplate (
19189 "OpMemoryModel Logical GLSL450\n"
19190 "OpEntryPoint GLCompute %main \"main\" %id\n"
19191 "OpExecutionMode %main LocalSize 1 1 1\n"
19192 "OpSource GLSL 430\n"
19193 "OpName %main \"main\"\n"
19194 "OpName %id \"gl_GlobalInvocationID\"\n"
19196 "OpDecorate %id BuiltIn GlobalInvocationId\n"
19198 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
19200 "%id = OpVariable %uvec3ptr Input\n"
19202 "%main = OpFunction %void None %voidf\n"
19203 "%label = OpLabel\n"
19204 "%idval = OpLoad %uvec3 %id\n"
19205 "%x = OpCompositeExtract %u32 %idval 0\n"
19206 "%inloc = OpAccessChain %f32ptr %indata %c0i32 %x\n"
19210 "%outloc = OpAccessChain %f32ptr %outdata %c0i32 %x\n"
19211 " OpStore %outloc %res\n"
19216 // Each test case produces 4 boolean values, and we want each of these values
19217 // to come froma different combination of the available bit-sizes, so compute
19218 // all possible combinations here.
19219 vector<deUint32> widths;
19220 widths.push_back(32);
19221 widths.push_back(16);
19222 widths.push_back(8);
19224 vector<IVec4> cases;
19225 for (size_t width0 = 0; width0 < widths.size(); width0++)
19227 for (size_t width1 = 0; width1 < widths.size(); width1++)
19229 for (size_t width2 = 0; width2 < widths.size(); width2++)
19231 for (size_t width3 = 0; width3 < widths.size(); width3++)
19233 cases.push_back(IVec4(widths[width0], widths[width1], widths[width2], widths[width3]));
19239 for (size_t caseNdx = 0; caseNdx < cases.size(); caseNdx++)
19241 /// Skip cases where all bitsizes are the same, we are only interested in testing booleans produced from instructions with different native bit-sizes
19242 if (cases[caseNdx][0] == cases[caseNdx][1] && cases[caseNdx][0] == cases[caseNdx][2] && cases[caseNdx][0] == cases[caseNdx][3])
19245 map<string, string> specializations;
19246 ComputeShaderSpec spec;
19248 // Inject appropriate capabilities and reference constants depending
19249 // on the bit-sizes required by this test case
19250 bool hasFloat32 = cases[caseNdx][0] == 32 || cases[caseNdx][1] == 32 || cases[caseNdx][2] == 32 || cases[caseNdx][3] == 32;
19251 bool hasFloat16 = cases[caseNdx][0] == 16 || cases[caseNdx][1] == 16 || cases[caseNdx][2] == 16 || cases[caseNdx][3] == 16;
19252 bool hasInt8 = cases[caseNdx][0] == 8 || cases[caseNdx][1] == 8 || cases[caseNdx][2] == 8 || cases[caseNdx][3] == 8;
19254 string capsStr = "OpCapability Shader\n";
19256 "%c0i32 = OpConstant %i32 0\n"
19257 "%c1f32 = OpConstant %f32 1.0\n"
19258 "%c0f32 = OpConstant %f32 0.0\n";
19263 "%c10f32 = OpConstant %f32 10.0\n"
19264 "%c25f32 = OpConstant %f32 25.0\n"
19265 "%c50f32 = OpConstant %f32 50.0\n"
19266 "%c90f32 = OpConstant %f32 90.0\n";
19271 capsStr += "OpCapability Float16\n";
19273 "%f16 = OpTypeFloat 16\n"
19274 "%c10f16 = OpConstant %f16 10.0\n"
19275 "%c25f16 = OpConstant %f16 25.0\n"
19276 "%c50f16 = OpConstant %f16 50.0\n"
19277 "%c90f16 = OpConstant %f16 90.0\n";
19282 capsStr += "OpCapability Int8\n";
19284 "%i8 = OpTypeInt 8 1\n"
19285 "%c10i8 = OpConstant %i8 10\n"
19286 "%c25i8 = OpConstant %i8 25\n"
19287 "%c50i8 = OpConstant %i8 50\n"
19288 "%c90i8 = OpConstant %i8 90\n";
19291 // Each invocation reads a different float32 value as input. Depending on
19292 // the bit-sizes required by the particular test case, we also produce
19293 // float16 and/or and int8 values by converting from the 32-bit float.
19294 string testStr = "";
19295 testStr += "%inval32 = OpLoad %f32 %inloc\n";
19297 testStr += "%inval16 = OpFConvert %f16 %inval32\n";
19299 testStr += "%inval8 = OpConvertFToS %i8 %inval32\n";
19301 // Because conversions from Float to Int round towards 0 we want our "greater" comparisons to be >=,
19302 // that way a float32/float16 comparison such as 50.6f >= 50.0f will preserve its result
19303 // when converted to int8, since FtoS(50.6f) results in 50. For "less" comparisons, it is the
19304 // other way around, so in this case we want < instead of <=.
19305 if (cases[caseNdx][0] == 32)
19306 testStr += "%cmp1 = OpFOrdGreaterThanEqual %bool %inval32 %c25f32\n";
19307 else if (cases[caseNdx][0] == 16)
19308 testStr += "%cmp1 = OpFOrdGreaterThanEqual %bool %inval16 %c25f16\n";
19310 testStr += "%cmp1 = OpSGreaterThanEqual %bool %inval8 %c25i8\n";
19312 if (cases[caseNdx][1] == 32)
19313 testStr += "%cmp2 = OpFOrdLessThan %bool %inval32 %c50f32\n";
19314 else if (cases[caseNdx][1] == 16)
19315 testStr += "%cmp2 = OpFOrdLessThan %bool %inval16 %c50f16\n";
19317 testStr += "%cmp2 = OpSLessThan %bool %inval8 %c50i8\n";
19319 if (cases[caseNdx][2] == 32)
19320 testStr += "%cmp3 = OpFOrdLessThan %bool %inval32 %c10f32\n";
19321 else if (cases[caseNdx][2] == 16)
19322 testStr += "%cmp3 = OpFOrdLessThan %bool %inval16 %c10f16\n";
19324 testStr += "%cmp3 = OpSLessThan %bool %inval8 %c10i8\n";
19326 if (cases[caseNdx][3] == 32)
19327 testStr += "%cmp4 = OpFOrdGreaterThanEqual %bool %inval32 %c90f32\n";
19328 else if (cases[caseNdx][3] == 16)
19329 testStr += "%cmp4 = OpFOrdGreaterThanEqual %bool %inval16 %c90f16\n";
19331 testStr += "%cmp4 = OpSGreaterThanEqual %bool %inval8 %c90i8\n";
19333 testStr += "%and1 = OpLogicalAnd %bool %cmp1 %cmp2\n";
19334 testStr += "%or1 = OpLogicalOr %bool %cmp3 %cmp4\n";
19335 testStr += "%or2 = OpLogicalOr %bool %and1 %or1\n";
19336 testStr += "%not1 = OpLogicalNot %bool %or2\n";
19337 testStr += "%res = OpSelect %f32 %not1 %c1f32 %c0f32\n";
19339 specializations["CAPS"] = capsStr;
19340 specializations["CONST"] = constStr;
19341 specializations["TEST"] = testStr;
19343 // Compute expected result by evaluating the boolean expression computed in the shader for each input value
19344 for (size_t ndx = 0; ndx < numElements; ++ndx)
19345 outputData[ndx] = !((inputData[ndx] >= 25.0f && inputData[ndx] < 50.0f) || (inputData[ndx] < 10.0f || inputData[ndx] >= 90.0f));
19347 spec.assembly = shaderTemplate.specialize(specializations);
19348 spec.inputs.push_back(BufferSp(new Float32Buffer(inputData)));
19349 spec.outputs.push_back(BufferSp(new Float32Buffer(outputData)));
19350 spec.numWorkGroups = IVec3(numElements, 1, 1);
19352 spec.requestedVulkanFeatures.extFloat16Int8 |= EXTFLOAT16INT8FEATURES_FLOAT16;
19354 spec.requestedVulkanFeatures.extFloat16Int8 |= EXTFLOAT16INT8FEATURES_INT8;
19355 spec.extensions.push_back("VK_KHR_shader_float16_int8");
19357 string testName = "b" + de::toString(cases[caseNdx][0]) + "b" + de::toString(cases[caseNdx][1]) + "b" + de::toString(cases[caseNdx][2]) + "b" + de::toString(cases[caseNdx][3]);
19358 group->addChild(new SpvAsmComputeShaderCase(testCtx, testName.c_str(), "", spec));
19361 return group.release();
19364 tcu::TestCaseGroup* createBoolGroup (tcu::TestContext& testCtx)
19366 de::MovePtr<tcu::TestCaseGroup> testGroup (new tcu::TestCaseGroup(testCtx, "bool", "Boolean tests"));
19368 testGroup->addChild(createBoolMixedBitSizeGroup(testCtx));
19370 return testGroup.release();
19373 tcu::TestCaseGroup* createOpNameAbuseTests (tcu::TestContext& testCtx)
19375 de::MovePtr<tcu::TestCaseGroup> abuseGroup(new tcu::TestCaseGroup(testCtx, "opname_abuse", "OpName abuse tests"));
19376 vector<CaseParameter> abuseCases;
19377 RGBA defaultColors[4];
19378 map<string, string> opNameFragments;
19380 getOpNameAbuseCases(abuseCases);
19381 getDefaultColors(defaultColors);
19383 opNameFragments["testfun"] =
19384 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
19385 "%param1 = OpFunctionParameter %v4f32\n"
19386 "%label_func = OpLabel\n"
19387 "%a = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
19388 "%b = OpFAdd %f32 %a %a\n"
19389 "%c = OpFSub %f32 %b %a\n"
19390 "%ret = OpVectorInsertDynamic %v4f32 %param1 %c %c_i32_0\n"
19391 "OpReturnValue %ret\n"
19394 for (unsigned int i = 0; i < abuseCases.size(); i++)
19397 casename = string("main") + abuseCases[i].name;
19399 opNameFragments["debug"] =
19400 "OpName %BP_main \"" + abuseCases[i].param + "\"";
19402 createTestsForAllStages(casename, defaultColors, defaultColors, opNameFragments, abuseGroup.get());
19405 for (unsigned int i = 0; i < abuseCases.size(); i++)
19408 casename = string("b") + abuseCases[i].name;
19410 opNameFragments["debug"] =
19411 "OpName %b \"" + abuseCases[i].param + "\"";
19413 createTestsForAllStages(casename, defaultColors, defaultColors, opNameFragments, abuseGroup.get());
19417 opNameFragments["debug"] =
19418 "OpName %test_code \"name1\"\n"
19419 "OpName %param1 \"name2\"\n"
19420 "OpName %a \"name3\"\n"
19421 "OpName %b \"name4\"\n"
19422 "OpName %c \"name5\"\n"
19423 "OpName %ret \"name6\"\n";
19425 createTestsForAllStages("everything_named", defaultColors, defaultColors, opNameFragments, abuseGroup.get());
19429 opNameFragments["debug"] =
19430 "OpName %test_code \"the_same\"\n"
19431 "OpName %param1 \"the_same\"\n"
19432 "OpName %a \"the_same\"\n"
19433 "OpName %b \"the_same\"\n"
19434 "OpName %c \"the_same\"\n"
19435 "OpName %ret \"the_same\"\n";
19437 createTestsForAllStages("everything_named_the_same", defaultColors, defaultColors, opNameFragments, abuseGroup.get());
19441 opNameFragments["debug"] =
19442 "OpName %BP_main \"to_be\"\n"
19443 "OpName %BP_main \"or_not\"\n"
19444 "OpName %BP_main \"to_be\"\n";
19446 createTestsForAllStages("main_has_multiple_names", defaultColors, defaultColors, opNameFragments, abuseGroup.get());
19450 opNameFragments["debug"] =
19451 "OpName %b \"to_be\"\n"
19452 "OpName %b \"or_not\"\n"
19453 "OpName %b \"to_be\"\n";
19455 createTestsForAllStages("b_has_multiple_names", defaultColors, defaultColors, opNameFragments, abuseGroup.get());
19458 return abuseGroup.release();
19462 tcu::TestCaseGroup* createOpMemberNameAbuseTests (tcu::TestContext& testCtx)
19464 de::MovePtr<tcu::TestCaseGroup> abuseGroup(new tcu::TestCaseGroup(testCtx, "opmembername_abuse", "OpName abuse tests"));
19465 vector<CaseParameter> abuseCases;
19466 RGBA defaultColors[4];
19467 map<string, string> opMemberNameFragments;
19469 getOpNameAbuseCases(abuseCases);
19470 getDefaultColors(defaultColors);
19472 opMemberNameFragments["pre_main"] =
19473 "%f3str = OpTypeStruct %f32 %f32 %f32\n";
19475 opMemberNameFragments["testfun"] =
19476 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
19477 "%param1 = OpFunctionParameter %v4f32\n"
19478 "%label_func = OpLabel\n"
19479 "%a = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
19480 "%b = OpFAdd %f32 %a %a\n"
19481 "%c = OpFSub %f32 %b %a\n"
19482 "%cstr = OpCompositeConstruct %f3str %c %c %c\n"
19483 "%d = OpCompositeExtract %f32 %cstr 0\n"
19484 "%ret = OpVectorInsertDynamic %v4f32 %param1 %d %c_i32_0\n"
19485 "OpReturnValue %ret\n"
19488 for (unsigned int i = 0; i < abuseCases.size(); i++)
19491 casename = string("f3str_x") + abuseCases[i].name;
19493 opMemberNameFragments["debug"] =
19494 "OpMemberName %f3str 0 \"" + abuseCases[i].param + "\"";
19496 createTestsForAllStages(casename, defaultColors, defaultColors, opMemberNameFragments, abuseGroup.get());
19500 opMemberNameFragments["debug"] =
19501 "OpMemberName %f3str 0 \"name1\"\n"
19502 "OpMemberName %f3str 1 \"name2\"\n"
19503 "OpMemberName %f3str 2 \"name3\"\n";
19505 createTestsForAllStages("everything_named", defaultColors, defaultColors, opMemberNameFragments, abuseGroup.get());
19509 opMemberNameFragments["debug"] =
19510 "OpMemberName %f3str 0 \"the_same\"\n"
19511 "OpMemberName %f3str 1 \"the_same\"\n"
19512 "OpMemberName %f3str 2 \"the_same\"\n";
19514 createTestsForAllStages("everything_named_the_same", defaultColors, defaultColors, opMemberNameFragments, abuseGroup.get());
19518 opMemberNameFragments["debug"] =
19519 "OpMemberName %f3str 0 \"to_be\"\n"
19520 "OpMemberName %f3str 1 \"or_not\"\n"
19521 "OpMemberName %f3str 0 \"to_be\"\n"
19522 "OpMemberName %f3str 2 \"makes_no\"\n"
19523 "OpMemberName %f3str 0 \"difference\"\n"
19524 "OpMemberName %f3str 0 \"to_me\"\n";
19527 createTestsForAllStages("f3str_x_has_multiple_names", defaultColors, defaultColors, opMemberNameFragments, abuseGroup.get());
19530 return abuseGroup.release();
19533 vector<deUint32> getSparseIdsAbuseData (const deUint32 numDataPoints, const deUint32 seed)
19535 vector<deUint32> result;
19536 de::Random rnd (seed);
19538 result.reserve(numDataPoints);
19540 for (deUint32 dataPointNdx = 0; dataPointNdx < numDataPoints; ++dataPointNdx)
19541 result.push_back(rnd.getUint32());
19546 vector<deUint32> getSparseIdsAbuseResults (const vector<deUint32>& inData1, const vector<deUint32>& inData2)
19548 vector<deUint32> result;
19550 result.reserve(inData1.size());
19552 for (size_t dataPointNdx = 0; dataPointNdx < inData1.size(); ++dataPointNdx)
19553 result.push_back(inData1[dataPointNdx] + inData2[dataPointNdx]);
19558 template<class SpecResource>
19559 void createSparseIdsAbuseTest (tcu::TestContext& testCtx, de::MovePtr<tcu::TestCaseGroup>& testGroup)
19561 const deUint32 numDataPoints = 16;
19562 const std::string testName ("sparse_ids");
19563 const deUint32 seed (deStringHash(testName.c_str()));
19564 const vector<deUint32> inData1 (getSparseIdsAbuseData(numDataPoints, seed + 1));
19565 const vector<deUint32> inData2 (getSparseIdsAbuseData(numDataPoints, seed + 2));
19566 const vector<deUint32> outData (getSparseIdsAbuseResults(inData1, inData2));
19567 const StringTemplate preMain
19569 "%c_i32_ndp = OpConstant %i32 ${num_data_points}\n"
19570 " %up_u32 = OpTypePointer Uniform %u32\n"
19571 " %ra_u32 = OpTypeArray %u32 %c_i32_ndp\n"
19572 " %SSBO32 = OpTypeStruct %ra_u32\n"
19573 "%up_SSBO32 = OpTypePointer Uniform %SSBO32\n"
19574 "%ssbo_src0 = OpVariable %up_SSBO32 Uniform\n"
19575 "%ssbo_src1 = OpVariable %up_SSBO32 Uniform\n"
19576 " %ssbo_dst = OpVariable %up_SSBO32 Uniform\n"
19578 const StringTemplate decoration
19580 "OpDecorate %ra_u32 ArrayStride 4\n"
19581 "OpMemberDecorate %SSBO32 0 Offset 0\n"
19582 "OpDecorate %SSBO32 BufferBlock\n"
19583 "OpDecorate %ssbo_src0 DescriptorSet 0\n"
19584 "OpDecorate %ssbo_src0 Binding 0\n"
19585 "OpDecorate %ssbo_src1 DescriptorSet 0\n"
19586 "OpDecorate %ssbo_src1 Binding 1\n"
19587 "OpDecorate %ssbo_dst DescriptorSet 0\n"
19588 "OpDecorate %ssbo_dst Binding 2\n"
19590 const StringTemplate testFun
19592 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
19593 " %param = OpFunctionParameter %v4f32\n"
19595 " %entry = OpLabel\n"
19596 " %i = OpVariable %fp_i32 Function\n"
19597 " OpStore %i %c_i32_0\n"
19598 " OpBranch %loop\n"
19600 " %loop = OpLabel\n"
19601 " %i_cmp = OpLoad %i32 %i\n"
19602 " %lt = OpSLessThan %bool %i_cmp %c_i32_ndp\n"
19603 " OpLoopMerge %merge %next None\n"
19604 " OpBranchConditional %lt %write %merge\n"
19606 " %write = OpLabel\n"
19607 " %ndx = OpLoad %i32 %i\n"
19609 " %127 = OpAccessChain %up_u32 %ssbo_src0 %c_i32_0 %ndx\n"
19610 " %128 = OpLoad %u32 %127\n"
19612 // The test relies on SPIR-V compiler option SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS set in assembleSpirV()
19613 " %4194000 = OpAccessChain %up_u32 %ssbo_src1 %c_i32_0 %ndx\n"
19614 " %4194001 = OpLoad %u32 %4194000\n"
19616 " %2097151 = OpIAdd %u32 %128 %4194001\n"
19617 " %2097152 = OpAccessChain %up_u32 %ssbo_dst %c_i32_0 %ndx\n"
19618 " OpStore %2097152 %2097151\n"
19619 " OpBranch %next\n"
19621 " %next = OpLabel\n"
19622 " %i_cur = OpLoad %i32 %i\n"
19623 " %i_new = OpIAdd %i32 %i_cur %c_i32_1\n"
19624 " OpStore %i %i_new\n"
19625 " OpBranch %loop\n"
19627 " %merge = OpLabel\n"
19628 " OpReturnValue %param\n"
19632 SpecResource specResource;
19633 map<string, string> specs;
19634 VulkanFeatures features;
19635 map<string, string> fragments;
19636 vector<string> extensions;
19638 specs["num_data_points"] = de::toString(numDataPoints);
19640 fragments["decoration"] = decoration.specialize(specs);
19641 fragments["pre_main"] = preMain.specialize(specs);
19642 fragments["testfun"] = testFun.specialize(specs);
19644 specResource.inputs.push_back(Resource(BufferSp(new Uint32Buffer(inData1)), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
19645 specResource.inputs.push_back(Resource(BufferSp(new Uint32Buffer(inData2)), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
19646 specResource.outputs.push_back(Resource(BufferSp(new Uint32Buffer(outData)), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
19648 features.coreFeatures.vertexPipelineStoresAndAtomics = true;
19649 features.coreFeatures.fragmentStoresAndAtomics = true;
19651 finalizeTestsCreation(specResource, fragments, testCtx, *testGroup.get(), testName, features, extensions, IVec3(1, 1, 1));
19654 vector<deUint32> getLotsIdsAbuseData (const deUint32 numDataPoints, const deUint32 seed)
19656 vector<deUint32> result;
19657 de::Random rnd (seed);
19659 result.reserve(numDataPoints);
19662 result.push_back(1u);
19665 for (deUint32 dataPointNdx = 1; dataPointNdx < numDataPoints; ++dataPointNdx)
19666 result.push_back(rnd.getUint8());
19671 vector<deUint32> getLotsIdsAbuseResults (const vector<deUint32>& inData1, const vector<deUint32>& inData2, const deUint32 count)
19673 vector<deUint32> result;
19675 result.reserve(inData1.size());
19677 for (size_t dataPointNdx = 0; dataPointNdx < inData1.size(); ++dataPointNdx)
19678 result.push_back(inData1[dataPointNdx] + count * inData2[dataPointNdx]);
19683 template<class SpecResource>
19684 void createLotsIdsAbuseTest (tcu::TestContext& testCtx, de::MovePtr<tcu::TestCaseGroup>& testGroup)
19686 const deUint32 numDataPoints = 16;
19687 const deUint32 firstNdx = 100u;
19688 const deUint32 sequenceCount = 10000u;
19689 const std::string testName ("lots_ids");
19690 const deUint32 seed (deStringHash(testName.c_str()));
19691 const vector<deUint32> inData1 (getLotsIdsAbuseData(numDataPoints, seed + 1));
19692 const vector<deUint32> inData2 (getLotsIdsAbuseData(numDataPoints, seed + 2));
19693 const vector<deUint32> outData (getLotsIdsAbuseResults(inData1, inData2, sequenceCount));
19694 const StringTemplate preMain
19696 "%c_i32_ndp = OpConstant %i32 ${num_data_points}\n"
19697 " %up_u32 = OpTypePointer Uniform %u32\n"
19698 " %ra_u32 = OpTypeArray %u32 %c_i32_ndp\n"
19699 " %SSBO32 = OpTypeStruct %ra_u32\n"
19700 "%up_SSBO32 = OpTypePointer Uniform %SSBO32\n"
19701 "%ssbo_src0 = OpVariable %up_SSBO32 Uniform\n"
19702 "%ssbo_src1 = OpVariable %up_SSBO32 Uniform\n"
19703 " %ssbo_dst = OpVariable %up_SSBO32 Uniform\n"
19705 const StringTemplate decoration
19707 "OpDecorate %ra_u32 ArrayStride 4\n"
19708 "OpMemberDecorate %SSBO32 0 Offset 0\n"
19709 "OpDecorate %SSBO32 BufferBlock\n"
19710 "OpDecorate %ssbo_src0 DescriptorSet 0\n"
19711 "OpDecorate %ssbo_src0 Binding 0\n"
19712 "OpDecorate %ssbo_src1 DescriptorSet 0\n"
19713 "OpDecorate %ssbo_src1 Binding 1\n"
19714 "OpDecorate %ssbo_dst DescriptorSet 0\n"
19715 "OpDecorate %ssbo_dst Binding 2\n"
19717 const StringTemplate testFun
19719 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
19720 " %param = OpFunctionParameter %v4f32\n"
19722 " %entry = OpLabel\n"
19723 " %i = OpVariable %fp_i32 Function\n"
19724 " OpStore %i %c_i32_0\n"
19725 " OpBranch %loop\n"
19727 " %loop = OpLabel\n"
19728 " %i_cmp = OpLoad %i32 %i\n"
19729 " %lt = OpSLessThan %bool %i_cmp %c_i32_ndp\n"
19730 " OpLoopMerge %merge %next None\n"
19731 " OpBranchConditional %lt %write %merge\n"
19733 " %write = OpLabel\n"
19734 " %ndx = OpLoad %i32 %i\n"
19736 " %90 = OpAccessChain %up_u32 %ssbo_src1 %c_i32_0 %ndx\n"
19737 " %91 = OpLoad %u32 %90\n"
19739 " %98 = OpAccessChain %up_u32 %ssbo_src0 %c_i32_0 %ndx\n"
19740 " %${zeroth_id} = OpLoad %u32 %98\n"
19744 // The test relies on SPIR-V compiler option SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS set in assembleSpirV()
19745 " %dst = OpAccessChain %up_u32 %ssbo_dst %c_i32_0 %ndx\n"
19746 " OpStore %dst %${last_id}\n"
19747 " OpBranch %next\n"
19749 " %next = OpLabel\n"
19750 " %i_cur = OpLoad %i32 %i\n"
19751 " %i_new = OpIAdd %i32 %i_cur %c_i32_1\n"
19752 " OpStore %i %i_new\n"
19753 " OpBranch %loop\n"
19755 " %merge = OpLabel\n"
19756 " OpReturnValue %param\n"
19760 deUint32 lastId = firstNdx;
19761 SpecResource specResource;
19762 map<string, string> specs;
19763 VulkanFeatures features;
19764 map<string, string> fragments;
19765 vector<string> extensions;
19766 std::string sequence;
19768 for (deUint32 sequenceNdx = 0; sequenceNdx < sequenceCount; ++sequenceNdx)
19770 const deUint32 sequenceId = sequenceNdx + firstNdx;
19771 const std::string sequenceIdStr = de::toString(sequenceId);
19773 sequence += "%" + sequenceIdStr + " = OpIAdd %u32 %91 %" + de::toString(sequenceId - 1) + "\n";
19774 lastId = sequenceId;
19776 if (sequenceNdx == 0)
19777 sequence.reserve((10 + sequence.length()) * sequenceCount);
19780 specs["num_data_points"] = de::toString(numDataPoints);
19781 specs["zeroth_id"] = de::toString(firstNdx - 1);
19782 specs["last_id"] = de::toString(lastId);
19783 specs["seq"] = sequence;
19785 fragments["decoration"] = decoration.specialize(specs);
19786 fragments["pre_main"] = preMain.specialize(specs);
19787 fragments["testfun"] = testFun.specialize(specs);
19789 specResource.inputs.push_back(Resource(BufferSp(new Uint32Buffer(inData1)), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
19790 specResource.inputs.push_back(Resource(BufferSp(new Uint32Buffer(inData2)), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
19791 specResource.outputs.push_back(Resource(BufferSp(new Uint32Buffer(outData)), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
19793 features.coreFeatures.vertexPipelineStoresAndAtomics = true;
19794 features.coreFeatures.fragmentStoresAndAtomics = true;
19796 finalizeTestsCreation(specResource, fragments, testCtx, *testGroup.get(), testName, features, extensions, IVec3(1, 1, 1));
19799 tcu::TestCaseGroup* createSpirvIdsAbuseTests (tcu::TestContext& testCtx)
19801 de::MovePtr<tcu::TestCaseGroup> testGroup (new tcu::TestCaseGroup(testCtx, "spirv_ids_abuse", "SPIR-V abuse tests"));
19803 createSparseIdsAbuseTest<GraphicsResources>(testCtx, testGroup);
19804 createLotsIdsAbuseTest<GraphicsResources>(testCtx, testGroup);
19806 return testGroup.release();
19809 tcu::TestCaseGroup* createSpirvIdsAbuseGroup (tcu::TestContext& testCtx)
19811 de::MovePtr<tcu::TestCaseGroup> testGroup (new tcu::TestCaseGroup(testCtx, "spirv_ids_abuse", "SPIR-V abuse tests"));
19813 createSparseIdsAbuseTest<ComputeShaderSpec>(testCtx, testGroup);
19814 createLotsIdsAbuseTest<ComputeShaderSpec>(testCtx, testGroup);
19816 return testGroup.release();
19819 tcu::TestCaseGroup* createInstructionTests (tcu::TestContext& testCtx)
19821 const bool testComputePipeline = true;
19823 de::MovePtr<tcu::TestCaseGroup> instructionTests (new tcu::TestCaseGroup(testCtx, "instruction", "Instructions with special opcodes/operands"));
19824 de::MovePtr<tcu::TestCaseGroup> computeTests (new tcu::TestCaseGroup(testCtx, "compute", "Compute Instructions with special opcodes/operands"));
19825 de::MovePtr<tcu::TestCaseGroup> graphicsTests (new tcu::TestCaseGroup(testCtx, "graphics", "Graphics Instructions with special opcodes/operands"));
19827 computeTests->addChild(createSpivVersionCheckTests(testCtx, testComputePipeline));
19828 computeTests->addChild(createLocalSizeGroup(testCtx));
19829 computeTests->addChild(createOpNopGroup(testCtx));
19830 computeTests->addChild(createOpFUnordGroup(testCtx, TEST_WITHOUT_NAN));
19831 computeTests->addChild(createOpFUnordGroup(testCtx, TEST_WITH_NAN));
19832 computeTests->addChild(createOpAtomicGroup(testCtx, false));
19833 computeTests->addChild(createOpAtomicGroup(testCtx, true)); // Using new StorageBuffer decoration
19834 computeTests->addChild(createOpAtomicGroup(testCtx, false, 1024, true)); // Return value validation
19835 computeTests->addChild(createOpAtomicGroup(testCtx, true, 65536, false, true)); // volatile atomics
19836 computeTests->addChild(createOpLineGroup(testCtx));
19837 computeTests->addChild(createOpModuleProcessedGroup(testCtx));
19838 computeTests->addChild(createOpNoLineGroup(testCtx));
19839 computeTests->addChild(createOpConstantNullGroup(testCtx));
19840 computeTests->addChild(createOpConstantCompositeGroup(testCtx));
19841 computeTests->addChild(createOpConstantUsageGroup(testCtx));
19842 computeTests->addChild(createSpecConstantGroup(testCtx));
19843 computeTests->addChild(createOpSourceGroup(testCtx));
19844 computeTests->addChild(createOpSourceExtensionGroup(testCtx));
19845 computeTests->addChild(createDecorationGroupGroup(testCtx));
19846 computeTests->addChild(createOpPhiGroup(testCtx));
19847 computeTests->addChild(createLoopControlGroup(testCtx));
19848 computeTests->addChild(createFunctionControlGroup(testCtx));
19849 computeTests->addChild(createSelectionControlGroup(testCtx));
19850 computeTests->addChild(createBlockOrderGroup(testCtx));
19851 computeTests->addChild(createMultipleShaderGroup(testCtx));
19852 computeTests->addChild(createMemoryAccessGroup(testCtx));
19853 computeTests->addChild(createOpCopyMemoryGroup(testCtx));
19854 computeTests->addChild(createOpCopyObjectGroup(testCtx));
19855 computeTests->addChild(createNoContractionGroup(testCtx));
19856 computeTests->addChild(createOpUndefGroup(testCtx));
19857 computeTests->addChild(createOpUnreachableGroup(testCtx));
19858 computeTests->addChild(createOpQuantizeToF16Group(testCtx));
19859 computeTests->addChild(createOpFRemGroup(testCtx));
19860 computeTests->addChild(createOpSRemComputeGroup(testCtx, QP_TEST_RESULT_PASS));
19861 computeTests->addChild(createOpSRemComputeGroup64(testCtx, QP_TEST_RESULT_PASS));
19862 computeTests->addChild(createOpSModComputeGroup(testCtx, QP_TEST_RESULT_PASS));
19863 computeTests->addChild(createOpSModComputeGroup64(testCtx, QP_TEST_RESULT_PASS));
19864 computeTests->addChild(createConvertComputeTests(testCtx, "OpSConvert", "sconvert"));
19865 computeTests->addChild(createConvertComputeTests(testCtx, "OpUConvert", "uconvert"));
19866 computeTests->addChild(createConvertComputeTests(testCtx, "OpFConvert", "fconvert"));
19867 computeTests->addChild(createConvertComputeTests(testCtx, "OpConvertSToF", "convertstof"));
19868 computeTests->addChild(createConvertComputeTests(testCtx, "OpConvertFToS", "convertftos"));
19869 computeTests->addChild(createConvertComputeTests(testCtx, "OpConvertUToF", "convertutof"));
19870 computeTests->addChild(createConvertComputeTests(testCtx, "OpConvertFToU", "convertftou"));
19871 computeTests->addChild(createOpCompositeInsertGroup(testCtx));
19872 computeTests->addChild(createOpInBoundsAccessChainGroup(testCtx));
19873 computeTests->addChild(createShaderDefaultOutputGroup(testCtx));
19874 computeTests->addChild(createOpNMinGroup(testCtx));
19875 computeTests->addChild(createOpNMaxGroup(testCtx));
19876 computeTests->addChild(createOpNClampGroup(testCtx));
19878 de::MovePtr<tcu::TestCaseGroup> computeAndroidTests (new tcu::TestCaseGroup(testCtx, "android", "Android CTS Tests"));
19880 computeAndroidTests->addChild(createOpSRemComputeGroup(testCtx, QP_TEST_RESULT_QUALITY_WARNING));
19881 computeAndroidTests->addChild(createOpSModComputeGroup(testCtx, QP_TEST_RESULT_QUALITY_WARNING));
19883 computeTests->addChild(computeAndroidTests.release());
19886 computeTests->addChild(create8BitStorageComputeGroup(testCtx));
19887 computeTests->addChild(create16BitStorageComputeGroup(testCtx));
19888 computeTests->addChild(createFloatControlsComputeGroup(testCtx));
19889 computeTests->addChild(createUboMatrixPaddingComputeGroup(testCtx));
19890 computeTests->addChild(createCompositeInsertComputeGroup(testCtx));
19891 computeTests->addChild(createVariableInitComputeGroup(testCtx));
19892 computeTests->addChild(createConditionalBranchComputeGroup(testCtx));
19893 computeTests->addChild(createIndexingComputeGroup(testCtx));
19894 computeTests->addChild(createVariablePointersComputeGroup(testCtx));
19895 computeTests->addChild(createPhysicalPointersComputeGroup(testCtx));
19896 computeTests->addChild(createImageSamplerComputeGroup(testCtx));
19897 computeTests->addChild(createOpNameGroup(testCtx));
19898 computeTests->addChild(createOpMemberNameGroup(testCtx));
19899 computeTests->addChild(createPointerParameterComputeGroup(testCtx));
19900 computeTests->addChild(createFloat16Group(testCtx));
19901 computeTests->addChild(createBoolGroup(testCtx));
19902 computeTests->addChild(createWorkgroupMemoryComputeGroup(testCtx));
19903 computeTests->addChild(createSpirvIdsAbuseGroup(testCtx));
19904 computeTests->addChild(createSignedIntCompareGroup(testCtx));
19905 computeTests->addChild(createUnusedVariableComputeTests(testCtx));
19906 computeTests->addChild(createPtrAccessChainGroup(testCtx));
19907 computeTests->addChild(createHlslComputeGroup(testCtx));
19908 computeTests->addChild(create64bitCompareComputeGroup(testCtx));
19910 graphicsTests->addChild(createCrossStageInterfaceTests(testCtx));
19911 graphicsTests->addChild(createSpivVersionCheckTests(testCtx, !testComputePipeline));
19912 graphicsTests->addChild(createOpNopTests(testCtx));
19913 graphicsTests->addChild(createOpSourceTests(testCtx));
19914 graphicsTests->addChild(createOpSourceContinuedTests(testCtx));
19915 graphicsTests->addChild(createOpModuleProcessedTests(testCtx));
19916 graphicsTests->addChild(createOpLineTests(testCtx));
19917 graphicsTests->addChild(createOpNoLineTests(testCtx));
19918 graphicsTests->addChild(createOpConstantNullTests(testCtx));
19919 graphicsTests->addChild(createOpConstantCompositeTests(testCtx));
19920 graphicsTests->addChild(createMemoryAccessTests(testCtx));
19921 graphicsTests->addChild(createOpUndefTests(testCtx));
19922 graphicsTests->addChild(createSelectionBlockOrderTests(testCtx));
19923 graphicsTests->addChild(createModuleTests(testCtx));
19924 graphicsTests->addChild(createUnusedVariableTests(testCtx));
19925 graphicsTests->addChild(createSwitchBlockOrderTests(testCtx));
19926 graphicsTests->addChild(createOpPhiTests(testCtx));
19927 graphicsTests->addChild(createNoContractionTests(testCtx));
19928 graphicsTests->addChild(createOpQuantizeTests(testCtx));
19929 graphicsTests->addChild(createLoopTests(testCtx));
19930 graphicsTests->addChild(createSpecConstantTests(testCtx));
19931 graphicsTests->addChild(createSpecConstantOpQuantizeToF16Group(testCtx));
19932 graphicsTests->addChild(createBarrierTests(testCtx));
19933 graphicsTests->addChild(createDecorationGroupTests(testCtx));
19934 graphicsTests->addChild(createFRemTests(testCtx));
19935 graphicsTests->addChild(createOpSRemGraphicsTests(testCtx, QP_TEST_RESULT_PASS));
19936 graphicsTests->addChild(createOpSModGraphicsTests(testCtx, QP_TEST_RESULT_PASS));
19939 de::MovePtr<tcu::TestCaseGroup> graphicsAndroidTests (new tcu::TestCaseGroup(testCtx, "android", "Android CTS Tests"));
19941 graphicsAndroidTests->addChild(createOpSRemGraphicsTests(testCtx, QP_TEST_RESULT_QUALITY_WARNING));
19942 graphicsAndroidTests->addChild(createOpSModGraphicsTests(testCtx, QP_TEST_RESULT_QUALITY_WARNING));
19944 graphicsTests->addChild(graphicsAndroidTests.release());
19946 graphicsTests->addChild(createOpNameTests(testCtx));
19947 graphicsTests->addChild(createOpNameAbuseTests(testCtx));
19948 graphicsTests->addChild(createOpMemberNameAbuseTests(testCtx));
19950 graphicsTests->addChild(create8BitStorageGraphicsGroup(testCtx));
19951 graphicsTests->addChild(create16BitStorageGraphicsGroup(testCtx));
19952 graphicsTests->addChild(createFloatControlsGraphicsGroup(testCtx));
19953 graphicsTests->addChild(createUboMatrixPaddingGraphicsGroup(testCtx));
19954 graphicsTests->addChild(createCompositeInsertGraphicsGroup(testCtx));
19955 graphicsTests->addChild(createVariableInitGraphicsGroup(testCtx));
19956 graphicsTests->addChild(createConditionalBranchGraphicsGroup(testCtx));
19957 graphicsTests->addChild(createIndexingGraphicsGroup(testCtx));
19958 graphicsTests->addChild(createVariablePointersGraphicsGroup(testCtx));
19959 graphicsTests->addChild(createImageSamplerGraphicsGroup(testCtx));
19960 graphicsTests->addChild(createConvertGraphicsTests(testCtx, "OpSConvert", "sconvert"));
19961 graphicsTests->addChild(createConvertGraphicsTests(testCtx, "OpUConvert", "uconvert"));
19962 graphicsTests->addChild(createConvertGraphicsTests(testCtx, "OpFConvert", "fconvert"));
19963 graphicsTests->addChild(createConvertGraphicsTests(testCtx, "OpConvertSToF", "convertstof"));
19964 graphicsTests->addChild(createConvertGraphicsTests(testCtx, "OpConvertFToS", "convertftos"));
19965 graphicsTests->addChild(createConvertGraphicsTests(testCtx, "OpConvertUToF", "convertutof"));
19966 graphicsTests->addChild(createConvertGraphicsTests(testCtx, "OpConvertFToU", "convertftou"));
19967 graphicsTests->addChild(createPointerParameterGraphicsGroup(testCtx));
19968 graphicsTests->addChild(createVaryingNameGraphicsGroup(testCtx));
19969 graphicsTests->addChild(createFloat16Tests(testCtx));
19970 graphicsTests->addChild(createSpirvIdsAbuseTests(testCtx));
19971 graphicsTests->addChild(create64bitCompareGraphicsGroup(testCtx));
19973 instructionTests->addChild(computeTests.release());
19974 instructionTests->addChild(graphicsTests.release());
19975 instructionTests->addChild(createSpirvVersion1p4Group(testCtx));
19977 return instructionTests.release();