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 "tcuRGBA.hpp"
31 #include "tcuStringTemplate.hpp"
32 #include "tcuTestLog.hpp"
33 #include "tcuVectorUtil.hpp"
36 #include "vkDeviceUtil.hpp"
37 #include "vkMemUtil.hpp"
38 #include "vkPlatform.hpp"
39 #include "vkPrograms.hpp"
40 #include "vkQueryUtil.hpp"
42 #include "vkRefUtil.hpp"
43 #include "vkStrUtil.hpp"
44 #include "vkTypeUtil.hpp"
46 #include "deRandom.hpp"
47 #include "deStringUtil.hpp"
48 #include "deUniquePtr.hpp"
49 #include "tcuStringTemplate.hpp"
51 #include "vktSpvAsm16bitStorageTests.hpp"
52 #include "vktSpvAsmComputeShaderCase.hpp"
53 #include "vktSpvAsmComputeShaderTestUtil.hpp"
54 #include "vktSpvAsmGraphicsShaderTestUtil.hpp"
55 #include "vktSpvAsmVariablePointersTests.hpp"
56 #include "vktTestCaseUtil.hpp"
67 namespace SpirVAssembly
81 using tcu::TestStatus;
84 using tcu::StringTemplate;
88 static void fillRandomScalars (de::Random& rnd, T minValue, T maxValue, void* dst, int numValues, int offset = 0)
90 T* const typedPtr = (T*)dst;
91 for (int ndx = 0; ndx < numValues; ndx++)
92 typedPtr[offset + ndx] = randomScalar<T>(rnd, minValue, maxValue);
95 // Filter is a function that returns true if a value should pass, false otherwise.
96 template<typename T, typename FilterT>
97 static void fillRandomScalars (de::Random& rnd, T minValue, T maxValue, void* dst, int numValues, FilterT filter, int offset = 0)
99 T* const typedPtr = (T*)dst;
101 for (int ndx = 0; ndx < numValues; ndx++)
104 value = randomScalar<T>(rnd, minValue, maxValue);
105 while (!filter(value));
107 typedPtr[offset + ndx] = value;
111 static void floorAll (vector<float>& values)
113 for (size_t i = 0; i < values.size(); i++)
114 values[i] = deFloatFloor(values[i]);
117 static void floorAll (vector<Vec4>& values)
119 for (size_t i = 0; i < values.size(); i++)
120 values[i] = floor(values[i]);
128 CaseParameter (const char* case_, const string& param_) : name(case_), param(param_) {}
131 // Assembly code used for testing OpNop, OpConstant{Null|Composite}, Op[No]Line, OpSource[Continued], OpSourceExtension, OpUndef is based on GLSL source code:
135 // layout(std140, set = 0, binding = 0) readonly buffer Input {
138 // layout(std140, set = 0, binding = 1) writeonly buffer Output {
142 // layout (local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
145 // uint x = gl_GlobalInvocationID.x;
146 // output_data.elements[x] = -input_data.elements[x];
149 tcu::TestCaseGroup* createOpNopGroup (tcu::TestContext& testCtx)
151 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opnop", "Test the OpNop instruction"));
152 ComputeShaderSpec spec;
153 de::Random rnd (deStringHash(group->getName()));
154 const int numElements = 100;
155 vector<float> positiveFloats (numElements, 0);
156 vector<float> negativeFloats (numElements, 0);
158 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
160 for (size_t ndx = 0; ndx < numElements; ++ndx)
161 negativeFloats[ndx] = -positiveFloats[ndx];
164 string(getComputeAsmShaderPreamble()) +
166 "OpSource GLSL 430\n"
167 "OpName %main \"main\"\n"
168 "OpName %id \"gl_GlobalInvocationID\"\n"
170 "OpDecorate %id BuiltIn GlobalInvocationId\n"
172 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes())
174 + string(getComputeAsmInputOutputBuffer()) +
176 "%id = OpVariable %uvec3ptr Input\n"
177 "%zero = OpConstant %i32 0\n"
179 "%main = OpFunction %void None %voidf\n"
181 "%idval = OpLoad %uvec3 %id\n"
182 "%x = OpCompositeExtract %u32 %idval 0\n"
184 " OpNop\n" // Inside a function body
186 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
187 "%inval = OpLoad %f32 %inloc\n"
188 "%neg = OpFNegate %f32 %inval\n"
189 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
190 " OpStore %outloc %neg\n"
193 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
194 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
195 spec.numWorkGroups = IVec3(numElements, 1, 1);
197 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "OpNop appearing at different places", spec));
199 return group.release();
202 bool compareFUnord (const std::vector<BufferSp>& inputs, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs, TestLog& log)
204 if (outputAllocs.size() != 1)
207 const BufferSp& expectedOutput = expectedOutputs[0];
208 const deInt32* expectedOutputAsInt = static_cast<const deInt32*>(expectedOutputs[0]->data());
209 const deInt32* outputAsInt = static_cast<const deInt32*>(outputAllocs[0]->getHostPtr());
210 const float* input1AsFloat = static_cast<const float*>(inputs[0]->data());
211 const float* input2AsFloat = static_cast<const float*>(inputs[1]->data());
212 bool returnValue = true;
214 for (size_t idx = 0; idx < expectedOutput->getNumBytes() / sizeof(deInt32); ++idx)
216 if (outputAsInt[idx] != expectedOutputAsInt[idx])
218 log << TestLog::Message << "ERROR: Sub-case failed. inputs: " << input1AsFloat[idx] << "," << input2AsFloat[idx] << " output: " << outputAsInt[idx]<< " expected output: " << expectedOutputAsInt[idx] << TestLog::EndMessage;
225 typedef VkBool32 (*compareFuncType) (float, float);
231 compareFuncType compareFunc;
233 OpFUnordCase (const char* _name, const char* _opCode, compareFuncType _compareFunc)
236 , compareFunc (_compareFunc) {}
239 #define ADD_OPFUNORD_CASE(NAME, OPCODE, OPERATOR) \
241 struct compare_##NAME { static VkBool32 compare(float x, float y) { return (x OPERATOR y) ? VK_TRUE : VK_FALSE; } }; \
242 cases.push_back(OpFUnordCase(#NAME, OPCODE, compare_##NAME::compare)); \
243 } while (deGetFalse())
245 tcu::TestCaseGroup* createOpFUnordGroup (tcu::TestContext& testCtx)
247 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opfunord", "Test the OpFUnord* opcodes"));
248 de::Random rnd (deStringHash(group->getName()));
249 const int numElements = 100;
250 vector<OpFUnordCase> cases;
252 const StringTemplate shaderTemplate (
254 string(getComputeAsmShaderPreamble()) +
256 "OpSource GLSL 430\n"
257 "OpName %main \"main\"\n"
258 "OpName %id \"gl_GlobalInvocationID\"\n"
260 "OpDecorate %id BuiltIn GlobalInvocationId\n"
262 "OpDecorate %buf BufferBlock\n"
263 "OpDecorate %buf2 BufferBlock\n"
264 "OpDecorate %indata1 DescriptorSet 0\n"
265 "OpDecorate %indata1 Binding 0\n"
266 "OpDecorate %indata2 DescriptorSet 0\n"
267 "OpDecorate %indata2 Binding 1\n"
268 "OpDecorate %outdata DescriptorSet 0\n"
269 "OpDecorate %outdata Binding 2\n"
270 "OpDecorate %f32arr ArrayStride 4\n"
271 "OpDecorate %i32arr ArrayStride 4\n"
272 "OpMemberDecorate %buf 0 Offset 0\n"
273 "OpMemberDecorate %buf2 0 Offset 0\n"
275 + string(getComputeAsmCommonTypes()) +
277 "%buf = OpTypeStruct %f32arr\n"
278 "%bufptr = OpTypePointer Uniform %buf\n"
279 "%indata1 = OpVariable %bufptr Uniform\n"
280 "%indata2 = OpVariable %bufptr Uniform\n"
282 "%buf2 = OpTypeStruct %i32arr\n"
283 "%buf2ptr = OpTypePointer Uniform %buf2\n"
284 "%outdata = OpVariable %buf2ptr Uniform\n"
286 "%id = OpVariable %uvec3ptr Input\n"
287 "%zero = OpConstant %i32 0\n"
288 "%consti1 = OpConstant %i32 1\n"
289 "%constf1 = OpConstant %f32 1.0\n"
291 "%main = OpFunction %void None %voidf\n"
293 "%idval = OpLoad %uvec3 %id\n"
294 "%x = OpCompositeExtract %u32 %idval 0\n"
296 "%inloc1 = OpAccessChain %f32ptr %indata1 %zero %x\n"
297 "%inval1 = OpLoad %f32 %inloc1\n"
298 "%inloc2 = OpAccessChain %f32ptr %indata2 %zero %x\n"
299 "%inval2 = OpLoad %f32 %inloc2\n"
300 "%outloc = OpAccessChain %i32ptr %outdata %zero %x\n"
302 "%result = ${OPCODE} %bool %inval1 %inval2\n"
303 "%int_res = OpSelect %i32 %result %consti1 %zero\n"
304 " OpStore %outloc %int_res\n"
309 ADD_OPFUNORD_CASE(equal, "OpFUnordEqual", ==);
310 ADD_OPFUNORD_CASE(less, "OpFUnordLessThan", <);
311 ADD_OPFUNORD_CASE(lessequal, "OpFUnordLessThanEqual", <=);
312 ADD_OPFUNORD_CASE(greater, "OpFUnordGreaterThan", >);
313 ADD_OPFUNORD_CASE(greaterequal, "OpFUnordGreaterThanEqual", >=);
314 ADD_OPFUNORD_CASE(notequal, "OpFUnordNotEqual", !=);
316 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
318 map<string, string> specializations;
319 ComputeShaderSpec spec;
320 const float NaN = std::numeric_limits<float>::quiet_NaN();
321 vector<float> inputFloats1 (numElements, 0);
322 vector<float> inputFloats2 (numElements, 0);
323 vector<deInt32> expectedInts (numElements, 0);
325 specializations["OPCODE"] = cases[caseNdx].opCode;
326 spec.assembly = shaderTemplate.specialize(specializations);
328 fillRandomScalars(rnd, 1.f, 100.f, &inputFloats1[0], numElements);
329 for (size_t ndx = 0; ndx < numElements; ++ndx)
333 case 0: inputFloats2[ndx] = inputFloats1[ndx] + 1.0f; break;
334 case 1: inputFloats2[ndx] = inputFloats1[ndx] - 1.0f; break;
335 case 2: inputFloats2[ndx] = inputFloats1[ndx]; break;
336 case 3: inputFloats2[ndx] = NaN; break;
337 case 4: inputFloats2[ndx] = inputFloats1[ndx]; inputFloats1[ndx] = NaN; break;
338 case 5: inputFloats2[ndx] = NaN; inputFloats1[ndx] = NaN; break;
340 expectedInts[ndx] = tcu::Float32(inputFloats1[ndx]).isNaN() || tcu::Float32(inputFloats2[ndx]).isNaN() || cases[caseNdx].compareFunc(inputFloats1[ndx], inputFloats2[ndx]);
343 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats1)));
344 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
345 spec.outputs.push_back(BufferSp(new Int32Buffer(expectedInts)));
346 spec.numWorkGroups = IVec3(numElements, 1, 1);
347 spec.verifyIO = &compareFUnord;
348 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
351 return group.release();
357 const char* assembly;
358 void (*calculateExpected)(deInt32&, deInt32);
359 deInt32 numOutputElements;
361 OpAtomicCase (const char* _name, const char* _assembly, void (*_calculateExpected)(deInt32&, deInt32), deInt32 _numOutputElements)
363 , assembly (_assembly)
364 , calculateExpected (_calculateExpected)
365 , numOutputElements (_numOutputElements) {}
368 tcu::TestCaseGroup* createOpAtomicGroup (tcu::TestContext& testCtx, bool useStorageBuffer)
370 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx,
371 useStorageBuffer ? "opatomic_storage_buffer" : "opatomic",
372 "Test the OpAtomic* opcodes"));
373 de::Random rnd (deStringHash(group->getName()));
374 const int numElements = 65535;
375 vector<OpAtomicCase> cases;
377 const StringTemplate shaderTemplate (
379 string("OpCapability Shader\n") +
380 (useStorageBuffer ? "OpExtension \"SPV_KHR_storage_buffer_storage_class\"\n" : "") +
381 "OpMemoryModel Logical GLSL450\n"
382 "OpEntryPoint GLCompute %main \"main\" %id\n"
383 "OpExecutionMode %main LocalSize 1 1 1\n" +
385 "OpSource GLSL 430\n"
386 "OpName %main \"main\"\n"
387 "OpName %id \"gl_GlobalInvocationID\"\n"
389 "OpDecorate %id BuiltIn GlobalInvocationId\n"
391 "OpDecorate %buf ${BLOCK_DECORATION}\n"
392 "OpDecorate %indata DescriptorSet 0\n"
393 "OpDecorate %indata Binding 0\n"
394 "OpDecorate %i32arr ArrayStride 4\n"
395 "OpMemberDecorate %buf 0 Offset 0\n"
397 "OpDecorate %sumbuf ${BLOCK_DECORATION}\n"
398 "OpDecorate %sum DescriptorSet 0\n"
399 "OpDecorate %sum Binding 1\n"
400 "OpMemberDecorate %sumbuf 0 Coherent\n"
401 "OpMemberDecorate %sumbuf 0 Offset 0\n"
403 "%void = OpTypeVoid\n"
404 "%voidf = OpTypeFunction %void\n"
405 "%u32 = OpTypeInt 32 0\n"
406 "%i32 = OpTypeInt 32 1\n"
407 "%uvec3 = OpTypeVector %u32 3\n"
408 "%uvec3ptr = OpTypePointer Input %uvec3\n"
409 "%i32ptr = OpTypePointer ${BLOCK_POINTER_TYPE} %i32\n"
410 "%i32arr = OpTypeRuntimeArray %i32\n"
412 "%buf = OpTypeStruct %i32arr\n"
413 "%bufptr = OpTypePointer ${BLOCK_POINTER_TYPE} %buf\n"
414 "%indata = OpVariable %bufptr ${BLOCK_POINTER_TYPE}\n"
416 "%sumbuf = OpTypeStruct %i32arr\n"
417 "%sumbufptr = OpTypePointer ${BLOCK_POINTER_TYPE} %sumbuf\n"
418 "%sum = OpVariable %sumbufptr ${BLOCK_POINTER_TYPE}\n"
420 "%id = OpVariable %uvec3ptr Input\n"
421 "%minusone = OpConstant %i32 -1\n"
422 "%zero = OpConstant %i32 0\n"
423 "%one = OpConstant %u32 1\n"
424 "%two = OpConstant %i32 2\n"
426 "%main = OpFunction %void None %voidf\n"
428 "%idval = OpLoad %uvec3 %id\n"
429 "%x = OpCompositeExtract %u32 %idval 0\n"
431 "%inloc = OpAccessChain %i32ptr %indata %zero %x\n"
432 "%inval = OpLoad %i32 %inloc\n"
434 "%outloc = OpAccessChain %i32ptr %sum %zero ${INDEX}\n"
440 #define ADD_OPATOMIC_CASE(NAME, ASSEMBLY, CALCULATE_EXPECTED, NUM_OUTPUT_ELEMENTS) \
442 DE_STATIC_ASSERT((NUM_OUTPUT_ELEMENTS) == 1 || (NUM_OUTPUT_ELEMENTS) == numElements); \
443 struct calculateExpected_##NAME { static void calculateExpected(deInt32& expected, deInt32 input) CALCULATE_EXPECTED }; /* NOLINT(CALCULATE_EXPECTED) */ \
444 cases.push_back(OpAtomicCase(#NAME, ASSEMBLY, calculateExpected_##NAME::calculateExpected, NUM_OUTPUT_ELEMENTS)); \
445 } while (deGetFalse())
446 #define ADD_OPATOMIC_CASE_1(NAME, ASSEMBLY, CALCULATE_EXPECTED) ADD_OPATOMIC_CASE(NAME, ASSEMBLY, CALCULATE_EXPECTED, 1)
447 #define ADD_OPATOMIC_CASE_N(NAME, ASSEMBLY, CALCULATE_EXPECTED) ADD_OPATOMIC_CASE(NAME, ASSEMBLY, CALCULATE_EXPECTED, numElements)
449 ADD_OPATOMIC_CASE_1(iadd, "%unused = OpAtomicIAdd %i32 %outloc %one %zero %inval\n", { expected += input; } );
450 ADD_OPATOMIC_CASE_1(isub, "%unused = OpAtomicISub %i32 %outloc %one %zero %inval\n", { expected -= input; } );
451 ADD_OPATOMIC_CASE_1(iinc, "%unused = OpAtomicIIncrement %i32 %outloc %one %zero\n", { ++expected; (void)input;} );
452 ADD_OPATOMIC_CASE_1(idec, "%unused = OpAtomicIDecrement %i32 %outloc %one %zero\n", { --expected; (void)input;} );
453 ADD_OPATOMIC_CASE_N(load, "%inval2 = OpAtomicLoad %i32 %inloc %zero %zero\n"
454 " OpStore %outloc %inval2\n", { expected = input;} );
455 ADD_OPATOMIC_CASE_N(store, " OpAtomicStore %outloc %zero %zero %inval\n", { expected = input;} );
456 ADD_OPATOMIC_CASE_N(compex, "%even = OpSMod %i32 %inval %two\n"
457 " OpStore %outloc %even\n"
458 "%unused = OpAtomicCompareExchange %i32 %outloc %one %zero %zero %minusone %zero\n", { expected = (input % 2) == 0 ? -1 : 1;} );
460 #undef ADD_OPATOMIC_CASE
461 #undef ADD_OPATOMIC_CASE_1
462 #undef ADD_OPATOMIC_CASE_N
464 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
466 map<string, string> specializations;
467 ComputeShaderSpec spec;
468 vector<deInt32> inputInts (numElements, 0);
469 vector<deInt32> expected (cases[caseNdx].numOutputElements, -1);
471 specializations["INDEX"] = (cases[caseNdx].numOutputElements == 1) ? "%zero" : "%x";
472 specializations["INSTRUCTION"] = cases[caseNdx].assembly;
473 specializations["BLOCK_DECORATION"] = useStorageBuffer ? "Block" : "BufferBlock";
474 specializations["BLOCK_POINTER_TYPE"] = useStorageBuffer ? "StorageBuffer" : "Uniform";
475 spec.assembly = shaderTemplate.specialize(specializations);
477 if (useStorageBuffer)
478 spec.extensions.push_back("VK_KHR_storage_buffer_storage_class");
480 fillRandomScalars(rnd, 1, 100, &inputInts[0], numElements);
481 for (size_t ndx = 0; ndx < numElements; ++ndx)
483 cases[caseNdx].calculateExpected((cases[caseNdx].numOutputElements == 1) ? expected[0] : expected[ndx], inputInts[ndx]);
486 spec.inputs.push_back(BufferSp(new Int32Buffer(inputInts)));
487 spec.outputs.push_back(BufferSp(new Int32Buffer(expected)));
488 spec.numWorkGroups = IVec3(numElements, 1, 1);
489 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
492 return group.release();
495 tcu::TestCaseGroup* createOpLineGroup (tcu::TestContext& testCtx)
497 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opline", "Test the OpLine instruction"));
498 ComputeShaderSpec spec;
499 de::Random rnd (deStringHash(group->getName()));
500 const int numElements = 100;
501 vector<float> positiveFloats (numElements, 0);
502 vector<float> negativeFloats (numElements, 0);
504 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
506 for (size_t ndx = 0; ndx < numElements; ++ndx)
507 negativeFloats[ndx] = -positiveFloats[ndx];
510 string(getComputeAsmShaderPreamble()) +
512 "%fname1 = OpString \"negateInputs.comp\"\n"
513 "%fname2 = OpString \"negateInputs\"\n"
515 "OpSource GLSL 430\n"
516 "OpName %main \"main\"\n"
517 "OpName %id \"gl_GlobalInvocationID\"\n"
519 "OpDecorate %id BuiltIn GlobalInvocationId\n"
521 + string(getComputeAsmInputOutputBufferTraits()) +
523 "OpLine %fname1 0 0\n" // At the earliest possible position
525 + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
527 "OpLine %fname1 0 1\n" // Multiple OpLines in sequence
528 "OpLine %fname2 1 0\n" // Different filenames
529 "OpLine %fname1 1000 100000\n"
531 "%id = OpVariable %uvec3ptr Input\n"
532 "%zero = OpConstant %i32 0\n"
534 "OpLine %fname1 1 1\n" // Before a function
536 "%main = OpFunction %void None %voidf\n"
539 "OpLine %fname1 1 1\n" // In a function
541 "%idval = OpLoad %uvec3 %id\n"
542 "%x = OpCompositeExtract %u32 %idval 0\n"
543 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
544 "%inval = OpLoad %f32 %inloc\n"
545 "%neg = OpFNegate %f32 %inval\n"
546 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
547 " OpStore %outloc %neg\n"
550 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
551 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
552 spec.numWorkGroups = IVec3(numElements, 1, 1);
554 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "OpLine appearing at different places", spec));
556 return group.release();
559 tcu::TestCaseGroup* createOpNoLineGroup (tcu::TestContext& testCtx)
561 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opnoline", "Test the OpNoLine instruction"));
562 ComputeShaderSpec spec;
563 de::Random rnd (deStringHash(group->getName()));
564 const int numElements = 100;
565 vector<float> positiveFloats (numElements, 0);
566 vector<float> negativeFloats (numElements, 0);
568 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
570 for (size_t ndx = 0; ndx < numElements; ++ndx)
571 negativeFloats[ndx] = -positiveFloats[ndx];
574 string(getComputeAsmShaderPreamble()) +
576 "%fname = OpString \"negateInputs.comp\"\n"
578 "OpSource GLSL 430\n"
579 "OpName %main \"main\"\n"
580 "OpName %id \"gl_GlobalInvocationID\"\n"
582 "OpDecorate %id BuiltIn GlobalInvocationId\n"
584 + string(getComputeAsmInputOutputBufferTraits()) +
586 "OpNoLine\n" // At the earliest possible position, without preceding OpLine
588 + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
590 "OpLine %fname 0 1\n"
591 "OpNoLine\n" // Immediately following a preceding OpLine
593 "OpLine %fname 1000 1\n"
595 "%id = OpVariable %uvec3ptr Input\n"
596 "%zero = OpConstant %i32 0\n"
598 "OpNoLine\n" // Contents after the previous OpLine
600 "%main = OpFunction %void None %voidf\n"
602 "%idval = OpLoad %uvec3 %id\n"
603 "%x = OpCompositeExtract %u32 %idval 0\n"
605 "OpNoLine\n" // Multiple OpNoLine
609 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
610 "%inval = OpLoad %f32 %inloc\n"
611 "%neg = OpFNegate %f32 %inval\n"
612 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
613 " OpStore %outloc %neg\n"
616 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
617 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
618 spec.numWorkGroups = IVec3(numElements, 1, 1);
620 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "OpNoLine appearing at different places", spec));
622 return group.release();
625 // Compare instruction for the contraction compute case.
626 // Returns true if the output is what is expected from the test case.
627 bool compareNoContractCase(const std::vector<BufferSp>&, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs, TestLog&)
629 if (outputAllocs.size() != 1)
632 // We really just need this for size because we are not comparing the exact values.
633 const BufferSp& expectedOutput = expectedOutputs[0];
634 const float* outputAsFloat = static_cast<const float*>(outputAllocs[0]->getHostPtr());;
636 for(size_t i = 0; i < expectedOutput->getNumBytes() / sizeof(float); ++i) {
637 if (outputAsFloat[i] != 0.f &&
638 outputAsFloat[i] != -ldexp(1, -24)) {
646 tcu::TestCaseGroup* createNoContractionGroup (tcu::TestContext& testCtx)
648 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "nocontraction", "Test the NoContraction decoration"));
649 vector<CaseParameter> cases;
650 const int numElements = 100;
651 vector<float> inputFloats1 (numElements, 0);
652 vector<float> inputFloats2 (numElements, 0);
653 vector<float> outputFloats (numElements, 0);
654 const StringTemplate shaderTemplate (
655 string(getComputeAsmShaderPreamble()) +
657 "OpName %main \"main\"\n"
658 "OpName %id \"gl_GlobalInvocationID\"\n"
660 "OpDecorate %id BuiltIn GlobalInvocationId\n"
664 "OpDecorate %buf BufferBlock\n"
665 "OpDecorate %indata1 DescriptorSet 0\n"
666 "OpDecorate %indata1 Binding 0\n"
667 "OpDecorate %indata2 DescriptorSet 0\n"
668 "OpDecorate %indata2 Binding 1\n"
669 "OpDecorate %outdata DescriptorSet 0\n"
670 "OpDecorate %outdata Binding 2\n"
671 "OpDecorate %f32arr ArrayStride 4\n"
672 "OpMemberDecorate %buf 0 Offset 0\n"
674 + string(getComputeAsmCommonTypes()) +
676 "%buf = OpTypeStruct %f32arr\n"
677 "%bufptr = OpTypePointer Uniform %buf\n"
678 "%indata1 = OpVariable %bufptr Uniform\n"
679 "%indata2 = OpVariable %bufptr Uniform\n"
680 "%outdata = OpVariable %bufptr Uniform\n"
682 "%id = OpVariable %uvec3ptr Input\n"
683 "%zero = OpConstant %i32 0\n"
684 "%c_f_m1 = OpConstant %f32 -1.\n"
686 "%main = OpFunction %void None %voidf\n"
688 "%idval = OpLoad %uvec3 %id\n"
689 "%x = OpCompositeExtract %u32 %idval 0\n"
690 "%inloc1 = OpAccessChain %f32ptr %indata1 %zero %x\n"
691 "%inval1 = OpLoad %f32 %inloc1\n"
692 "%inloc2 = OpAccessChain %f32ptr %indata2 %zero %x\n"
693 "%inval2 = OpLoad %f32 %inloc2\n"
694 "%mul = OpFMul %f32 %inval1 %inval2\n"
695 "%add = OpFAdd %f32 %mul %c_f_m1\n"
696 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
697 " OpStore %outloc %add\n"
701 cases.push_back(CaseParameter("multiplication", "OpDecorate %mul NoContraction"));
702 cases.push_back(CaseParameter("addition", "OpDecorate %add NoContraction"));
703 cases.push_back(CaseParameter("both", "OpDecorate %mul NoContraction\nOpDecorate %add NoContraction"));
705 for (size_t ndx = 0; ndx < numElements; ++ndx)
707 inputFloats1[ndx] = 1.f + std::ldexp(1.f, -23); // 1 + 2^-23.
708 inputFloats2[ndx] = 1.f - std::ldexp(1.f, -23); // 1 - 2^-23.
709 // Result for (1 + 2^-23) * (1 - 2^-23) - 1. With NoContraction, the multiplication will be
710 // conducted separately and the result is rounded to 1, or 0x1.fffffcp-1
711 // So the final result will be 0.f or 0x1p-24.
712 // If the operation is combined into a precise fused multiply-add, then the result would be
713 // 2^-46 (0xa8800000).
714 outputFloats[ndx] = 0.f;
717 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
719 map<string, string> specializations;
720 ComputeShaderSpec spec;
722 specializations["DECORATION"] = cases[caseNdx].param;
723 spec.assembly = shaderTemplate.specialize(specializations);
724 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats1)));
725 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
726 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
727 spec.numWorkGroups = IVec3(numElements, 1, 1);
728 // Check against the two possible answers based on rounding mode.
729 spec.verifyIO = &compareNoContractCase;
731 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
733 return group.release();
736 bool compareFRem(const std::vector<BufferSp>&, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs, TestLog&)
738 if (outputAllocs.size() != 1)
741 const BufferSp& expectedOutput = expectedOutputs[0];
742 const float *expectedOutputAsFloat = static_cast<const float*>(expectedOutput->data());
743 const float* outputAsFloat = static_cast<const float*>(outputAllocs[0]->getHostPtr());;
745 for (size_t idx = 0; idx < expectedOutput->getNumBytes() / sizeof(float); ++idx)
747 const float f0 = expectedOutputAsFloat[idx];
748 const float f1 = outputAsFloat[idx];
749 // \todo relative error needs to be fairly high because FRem may be implemented as
750 // (roughly) frac(a/b)*b, so LSB errors can be magnified. But this should be fine for now.
751 if (deFloatAbs((f1 - f0) / f0) > 0.02)
758 tcu::TestCaseGroup* createOpFRemGroup (tcu::TestContext& testCtx)
760 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opfrem", "Test the OpFRem instruction"));
761 ComputeShaderSpec spec;
762 de::Random rnd (deStringHash(group->getName()));
763 const int numElements = 200;
764 vector<float> inputFloats1 (numElements, 0);
765 vector<float> inputFloats2 (numElements, 0);
766 vector<float> outputFloats (numElements, 0);
768 fillRandomScalars(rnd, -10000.f, 10000.f, &inputFloats1[0], numElements);
769 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats2[0], numElements);
771 for (size_t ndx = 0; ndx < numElements; ++ndx)
773 // Guard against divisors near zero.
774 if (std::fabs(inputFloats2[ndx]) < 1e-3)
775 inputFloats2[ndx] = 8.f;
777 // The return value of std::fmod() has the same sign as its first operand, which is how OpFRem spec'd.
778 outputFloats[ndx] = std::fmod(inputFloats1[ndx], inputFloats2[ndx]);
782 string(getComputeAsmShaderPreamble()) +
784 "OpName %main \"main\"\n"
785 "OpName %id \"gl_GlobalInvocationID\"\n"
787 "OpDecorate %id BuiltIn GlobalInvocationId\n"
789 "OpDecorate %buf BufferBlock\n"
790 "OpDecorate %indata1 DescriptorSet 0\n"
791 "OpDecorate %indata1 Binding 0\n"
792 "OpDecorate %indata2 DescriptorSet 0\n"
793 "OpDecorate %indata2 Binding 1\n"
794 "OpDecorate %outdata DescriptorSet 0\n"
795 "OpDecorate %outdata Binding 2\n"
796 "OpDecorate %f32arr ArrayStride 4\n"
797 "OpMemberDecorate %buf 0 Offset 0\n"
799 + string(getComputeAsmCommonTypes()) +
801 "%buf = OpTypeStruct %f32arr\n"
802 "%bufptr = OpTypePointer Uniform %buf\n"
803 "%indata1 = OpVariable %bufptr Uniform\n"
804 "%indata2 = OpVariable %bufptr Uniform\n"
805 "%outdata = OpVariable %bufptr Uniform\n"
807 "%id = OpVariable %uvec3ptr Input\n"
808 "%zero = OpConstant %i32 0\n"
810 "%main = OpFunction %void None %voidf\n"
812 "%idval = OpLoad %uvec3 %id\n"
813 "%x = OpCompositeExtract %u32 %idval 0\n"
814 "%inloc1 = OpAccessChain %f32ptr %indata1 %zero %x\n"
815 "%inval1 = OpLoad %f32 %inloc1\n"
816 "%inloc2 = OpAccessChain %f32ptr %indata2 %zero %x\n"
817 "%inval2 = OpLoad %f32 %inloc2\n"
818 "%rem = OpFRem %f32 %inval1 %inval2\n"
819 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
820 " OpStore %outloc %rem\n"
824 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats1)));
825 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
826 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
827 spec.numWorkGroups = IVec3(numElements, 1, 1);
828 spec.verifyIO = &compareFRem;
830 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "", spec));
832 return group.release();
835 // Copy contents in the input buffer to the output buffer.
836 tcu::TestCaseGroup* createOpCopyMemoryGroup (tcu::TestContext& testCtx)
838 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opcopymemory", "Test the OpCopyMemory instruction"));
839 de::Random rnd (deStringHash(group->getName()));
840 const int numElements = 100;
842 // 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.
843 ComputeShaderSpec spec1;
844 vector<Vec4> inputFloats1 (numElements);
845 vector<Vec4> outputFloats1 (numElements);
847 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats1[0], numElements * 4);
849 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
850 floorAll(inputFloats1);
852 for (size_t ndx = 0; ndx < numElements; ++ndx)
853 outputFloats1[ndx] = inputFloats1[ndx] + Vec4(0.f, 0.5f, 1.5f, 2.5f);
856 string(getComputeAsmShaderPreamble()) +
858 "OpName %main \"main\"\n"
859 "OpName %id \"gl_GlobalInvocationID\"\n"
861 "OpDecorate %id BuiltIn GlobalInvocationId\n"
862 "OpDecorate %vec4arr ArrayStride 16\n"
864 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
866 "%vec4 = OpTypeVector %f32 4\n"
867 "%vec4ptr_u = OpTypePointer Uniform %vec4\n"
868 "%vec4ptr_f = OpTypePointer Function %vec4\n"
869 "%vec4arr = OpTypeRuntimeArray %vec4\n"
870 "%buf = OpTypeStruct %vec4arr\n"
871 "%bufptr = OpTypePointer Uniform %buf\n"
872 "%indata = OpVariable %bufptr Uniform\n"
873 "%outdata = OpVariable %bufptr Uniform\n"
875 "%id = OpVariable %uvec3ptr Input\n"
876 "%zero = OpConstant %i32 0\n"
877 "%c_f_0 = OpConstant %f32 0.\n"
878 "%c_f_0_5 = OpConstant %f32 0.5\n"
879 "%c_f_1_5 = OpConstant %f32 1.5\n"
880 "%c_f_2_5 = OpConstant %f32 2.5\n"
881 "%c_vec4 = OpConstantComposite %vec4 %c_f_0 %c_f_0_5 %c_f_1_5 %c_f_2_5\n"
883 "%main = OpFunction %void None %voidf\n"
885 "%v_vec4 = OpVariable %vec4ptr_f Function\n"
886 "%idval = OpLoad %uvec3 %id\n"
887 "%x = OpCompositeExtract %u32 %idval 0\n"
888 "%inloc = OpAccessChain %vec4ptr_u %indata %zero %x\n"
889 "%outloc = OpAccessChain %vec4ptr_u %outdata %zero %x\n"
890 " OpCopyMemory %v_vec4 %inloc\n"
891 "%v_vec4_val = OpLoad %vec4 %v_vec4\n"
892 "%add = OpFAdd %vec4 %v_vec4_val %c_vec4\n"
893 " OpStore %outloc %add\n"
897 spec1.inputs.push_back(BufferSp(new Vec4Buffer(inputFloats1)));
898 spec1.outputs.push_back(BufferSp(new Vec4Buffer(outputFloats1)));
899 spec1.numWorkGroups = IVec3(numElements, 1, 1);
901 group->addChild(new SpvAsmComputeShaderCase(testCtx, "vector", "OpCopyMemory elements of vector type", spec1));
903 // The following case copies a float[100] variable from the input buffer to the output buffer.
904 ComputeShaderSpec spec2;
905 vector<float> inputFloats2 (numElements);
906 vector<float> outputFloats2 (numElements);
908 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats2[0], numElements);
910 for (size_t ndx = 0; ndx < numElements; ++ndx)
911 outputFloats2[ndx] = inputFloats2[ndx];
914 string(getComputeAsmShaderPreamble()) +
916 "OpName %main \"main\"\n"
917 "OpName %id \"gl_GlobalInvocationID\"\n"
919 "OpDecorate %id BuiltIn GlobalInvocationId\n"
920 "OpDecorate %f32arr100 ArrayStride 4\n"
922 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
924 "%hundred = OpConstant %u32 100\n"
925 "%f32arr100 = OpTypeArray %f32 %hundred\n"
926 "%f32arr100ptr_f = OpTypePointer Function %f32arr100\n"
927 "%f32arr100ptr_u = OpTypePointer Uniform %f32arr100\n"
928 "%buf = OpTypeStruct %f32arr100\n"
929 "%bufptr = OpTypePointer Uniform %buf\n"
930 "%indata = OpVariable %bufptr Uniform\n"
931 "%outdata = OpVariable %bufptr Uniform\n"
933 "%id = OpVariable %uvec3ptr Input\n"
934 "%zero = OpConstant %i32 0\n"
936 "%main = OpFunction %void None %voidf\n"
938 "%var = OpVariable %f32arr100ptr_f Function\n"
939 "%inarr = OpAccessChain %f32arr100ptr_u %indata %zero\n"
940 "%outarr = OpAccessChain %f32arr100ptr_u %outdata %zero\n"
941 " OpCopyMemory %var %inarr\n"
942 " OpCopyMemory %outarr %var\n"
946 spec2.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
947 spec2.outputs.push_back(BufferSp(new Float32Buffer(outputFloats2)));
948 spec2.numWorkGroups = IVec3(1, 1, 1);
950 group->addChild(new SpvAsmComputeShaderCase(testCtx, "array", "OpCopyMemory elements of array type", spec2));
952 // The following case copies a struct{vec4, vec4, vec4, vec4} variable from the input buffer to the output buffer.
953 ComputeShaderSpec spec3;
954 vector<float> inputFloats3 (16);
955 vector<float> outputFloats3 (16);
957 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats3[0], 16);
959 for (size_t ndx = 0; ndx < 16; ++ndx)
960 outputFloats3[ndx] = inputFloats3[ndx];
963 string(getComputeAsmShaderPreamble()) +
965 "OpName %main \"main\"\n"
966 "OpName %id \"gl_GlobalInvocationID\"\n"
968 "OpDecorate %id BuiltIn GlobalInvocationId\n"
969 "OpMemberDecorate %buf 0 Offset 0\n"
970 "OpMemberDecorate %buf 1 Offset 16\n"
971 "OpMemberDecorate %buf 2 Offset 32\n"
972 "OpMemberDecorate %buf 3 Offset 48\n"
974 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
976 "%vec4 = OpTypeVector %f32 4\n"
977 "%buf = OpTypeStruct %vec4 %vec4 %vec4 %vec4\n"
978 "%bufptr = OpTypePointer Uniform %buf\n"
979 "%indata = OpVariable %bufptr Uniform\n"
980 "%outdata = OpVariable %bufptr Uniform\n"
981 "%vec4stptr = OpTypePointer Function %buf\n"
983 "%id = OpVariable %uvec3ptr Input\n"
984 "%zero = OpConstant %i32 0\n"
986 "%main = OpFunction %void None %voidf\n"
988 "%var = OpVariable %vec4stptr Function\n"
989 " OpCopyMemory %var %indata\n"
990 " OpCopyMemory %outdata %var\n"
994 spec3.inputs.push_back(BufferSp(new Float32Buffer(inputFloats3)));
995 spec3.outputs.push_back(BufferSp(new Float32Buffer(outputFloats3)));
996 spec3.numWorkGroups = IVec3(1, 1, 1);
998 group->addChild(new SpvAsmComputeShaderCase(testCtx, "struct", "OpCopyMemory elements of struct type", spec3));
1000 // The following case negates multiple float variables from the input buffer and stores the results to the output buffer.
1001 ComputeShaderSpec spec4;
1002 vector<float> inputFloats4 (numElements);
1003 vector<float> outputFloats4 (numElements);
1005 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats4[0], numElements);
1007 for (size_t ndx = 0; ndx < numElements; ++ndx)
1008 outputFloats4[ndx] = -inputFloats4[ndx];
1011 string(getComputeAsmShaderPreamble()) +
1013 "OpName %main \"main\"\n"
1014 "OpName %id \"gl_GlobalInvocationID\"\n"
1016 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1018 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
1020 "%f32ptr_f = OpTypePointer Function %f32\n"
1021 "%id = OpVariable %uvec3ptr Input\n"
1022 "%zero = OpConstant %i32 0\n"
1024 "%main = OpFunction %void None %voidf\n"
1025 "%label = OpLabel\n"
1026 "%var = OpVariable %f32ptr_f Function\n"
1027 "%idval = OpLoad %uvec3 %id\n"
1028 "%x = OpCompositeExtract %u32 %idval 0\n"
1029 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
1030 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
1031 " OpCopyMemory %var %inloc\n"
1032 "%val = OpLoad %f32 %var\n"
1033 "%neg = OpFNegate %f32 %val\n"
1034 " OpStore %outloc %neg\n"
1038 spec4.inputs.push_back(BufferSp(new Float32Buffer(inputFloats4)));
1039 spec4.outputs.push_back(BufferSp(new Float32Buffer(outputFloats4)));
1040 spec4.numWorkGroups = IVec3(numElements, 1, 1);
1042 group->addChild(new SpvAsmComputeShaderCase(testCtx, "float", "OpCopyMemory elements of float type", spec4));
1044 return group.release();
1047 tcu::TestCaseGroup* createOpCopyObjectGroup (tcu::TestContext& testCtx)
1049 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opcopyobject", "Test the OpCopyObject instruction"));
1050 ComputeShaderSpec spec;
1051 de::Random rnd (deStringHash(group->getName()));
1052 const int numElements = 100;
1053 vector<float> inputFloats (numElements, 0);
1054 vector<float> outputFloats (numElements, 0);
1056 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats[0], numElements);
1058 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
1059 floorAll(inputFloats);
1061 for (size_t ndx = 0; ndx < numElements; ++ndx)
1062 outputFloats[ndx] = inputFloats[ndx] + 7.5f;
1065 string(getComputeAsmShaderPreamble()) +
1067 "OpName %main \"main\"\n"
1068 "OpName %id \"gl_GlobalInvocationID\"\n"
1070 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1072 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
1074 "%fmat = OpTypeMatrix %fvec3 3\n"
1075 "%three = OpConstant %u32 3\n"
1076 "%farr = OpTypeArray %f32 %three\n"
1077 "%fst = OpTypeStruct %f32 %f32\n"
1079 + string(getComputeAsmInputOutputBuffer()) +
1081 "%id = OpVariable %uvec3ptr Input\n"
1082 "%zero = OpConstant %i32 0\n"
1083 "%c_f = OpConstant %f32 1.5\n"
1084 "%c_fvec3 = OpConstantComposite %fvec3 %c_f %c_f %c_f\n"
1085 "%c_fmat = OpConstantComposite %fmat %c_fvec3 %c_fvec3 %c_fvec3\n"
1086 "%c_farr = OpConstantComposite %farr %c_f %c_f %c_f\n"
1087 "%c_fst = OpConstantComposite %fst %c_f %c_f\n"
1089 "%main = OpFunction %void None %voidf\n"
1090 "%label = OpLabel\n"
1091 "%c_f_copy = OpCopyObject %f32 %c_f\n"
1092 "%c_fvec3_copy = OpCopyObject %fvec3 %c_fvec3\n"
1093 "%c_fmat_copy = OpCopyObject %fmat %c_fmat\n"
1094 "%c_farr_copy = OpCopyObject %farr %c_farr\n"
1095 "%c_fst_copy = OpCopyObject %fst %c_fst\n"
1096 "%fvec3_elem = OpCompositeExtract %f32 %c_fvec3_copy 0\n"
1097 "%fmat_elem = OpCompositeExtract %f32 %c_fmat_copy 1 2\n"
1098 "%farr_elem = OpCompositeExtract %f32 %c_farr_copy 2\n"
1099 "%fst_elem = OpCompositeExtract %f32 %c_fst_copy 1\n"
1100 // Add up. 1.5 * 5 = 7.5.
1101 "%add1 = OpFAdd %f32 %c_f_copy %fvec3_elem\n"
1102 "%add2 = OpFAdd %f32 %add1 %fmat_elem\n"
1103 "%add3 = OpFAdd %f32 %add2 %farr_elem\n"
1104 "%add4 = OpFAdd %f32 %add3 %fst_elem\n"
1106 "%idval = OpLoad %uvec3 %id\n"
1107 "%x = OpCompositeExtract %u32 %idval 0\n"
1108 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
1109 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
1110 "%inval = OpLoad %f32 %inloc\n"
1111 "%add = OpFAdd %f32 %add4 %inval\n"
1112 " OpStore %outloc %add\n"
1115 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
1116 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
1117 spec.numWorkGroups = IVec3(numElements, 1, 1);
1119 group->addChild(new SpvAsmComputeShaderCase(testCtx, "spotcheck", "OpCopyObject on different types", spec));
1121 return group.release();
1123 // Assembly code used for testing OpUnreachable is based on GLSL source code:
1127 // layout(std140, set = 0, binding = 0) readonly buffer Input {
1128 // float elements[];
1130 // layout(std140, set = 0, binding = 1) writeonly buffer Output {
1131 // float elements[];
1134 // void not_called_func() {
1135 // // place OpUnreachable here
1138 // uint modulo4(uint val) {
1139 // switch (val % uint(4)) {
1140 // case 0: return 3;
1141 // case 1: return 2;
1142 // case 2: return 1;
1143 // case 3: return 0;
1144 // default: return 100; // place OpUnreachable here
1150 // // place OpUnreachable here
1154 // uint x = gl_GlobalInvocationID.x;
1155 // if (const5() > modulo4(1000)) {
1156 // output_data.elements[x] = -input_data.elements[x];
1158 // // place OpUnreachable here
1159 // output_data.elements[x] = input_data.elements[x];
1163 tcu::TestCaseGroup* createOpUnreachableGroup (tcu::TestContext& testCtx)
1165 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opunreachable", "Test the OpUnreachable instruction"));
1166 ComputeShaderSpec spec;
1167 de::Random rnd (deStringHash(group->getName()));
1168 const int numElements = 100;
1169 vector<float> positiveFloats (numElements, 0);
1170 vector<float> negativeFloats (numElements, 0);
1172 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
1174 for (size_t ndx = 0; ndx < numElements; ++ndx)
1175 negativeFloats[ndx] = -positiveFloats[ndx];
1178 string(getComputeAsmShaderPreamble()) +
1180 "OpSource GLSL 430\n"
1181 "OpName %main \"main\"\n"
1182 "OpName %func_not_called_func \"not_called_func(\"\n"
1183 "OpName %func_modulo4 \"modulo4(u1;\"\n"
1184 "OpName %func_const5 \"const5(\"\n"
1185 "OpName %id \"gl_GlobalInvocationID\"\n"
1187 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1189 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
1191 "%u32ptr = OpTypePointer Function %u32\n"
1192 "%uintfuint = OpTypeFunction %u32 %u32ptr\n"
1193 "%unitf = OpTypeFunction %u32\n"
1195 "%id = OpVariable %uvec3ptr Input\n"
1196 "%zero = OpConstant %u32 0\n"
1197 "%one = OpConstant %u32 1\n"
1198 "%two = OpConstant %u32 2\n"
1199 "%three = OpConstant %u32 3\n"
1200 "%four = OpConstant %u32 4\n"
1201 "%five = OpConstant %u32 5\n"
1202 "%hundred = OpConstant %u32 100\n"
1203 "%thousand = OpConstant %u32 1000\n"
1205 + string(getComputeAsmInputOutputBuffer()) +
1208 "%main = OpFunction %void None %voidf\n"
1209 "%main_entry = OpLabel\n"
1210 "%v_thousand = OpVariable %u32ptr Function %thousand\n"
1211 "%idval = OpLoad %uvec3 %id\n"
1212 "%x = OpCompositeExtract %u32 %idval 0\n"
1213 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
1214 "%inval = OpLoad %f32 %inloc\n"
1215 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
1216 "%ret_const5 = OpFunctionCall %u32 %func_const5\n"
1217 "%ret_modulo4 = OpFunctionCall %u32 %func_modulo4 %v_thousand\n"
1218 "%cmp_gt = OpUGreaterThan %bool %ret_const5 %ret_modulo4\n"
1219 " OpSelectionMerge %if_end None\n"
1220 " OpBranchConditional %cmp_gt %if_true %if_false\n"
1221 "%if_true = OpLabel\n"
1222 "%negate = OpFNegate %f32 %inval\n"
1223 " OpStore %outloc %negate\n"
1224 " OpBranch %if_end\n"
1225 "%if_false = OpLabel\n"
1226 " OpUnreachable\n" // Unreachable else branch for if statement
1227 "%if_end = OpLabel\n"
1231 // not_called_function()
1232 "%func_not_called_func = OpFunction %void None %voidf\n"
1233 "%not_called_func_entry = OpLabel\n"
1234 " OpUnreachable\n" // Unreachable entry block in not called static function
1238 "%func_modulo4 = OpFunction %u32 None %uintfuint\n"
1239 "%valptr = OpFunctionParameter %u32ptr\n"
1240 "%modulo4_entry = OpLabel\n"
1241 "%val = OpLoad %u32 %valptr\n"
1242 "%modulo = OpUMod %u32 %val %four\n"
1243 " OpSelectionMerge %switch_merge None\n"
1244 " OpSwitch %modulo %default 0 %case0 1 %case1 2 %case2 3 %case3\n"
1245 "%case0 = OpLabel\n"
1246 " OpReturnValue %three\n"
1247 "%case1 = OpLabel\n"
1248 " OpReturnValue %two\n"
1249 "%case2 = OpLabel\n"
1250 " OpReturnValue %one\n"
1251 "%case3 = OpLabel\n"
1252 " OpReturnValue %zero\n"
1253 "%default = OpLabel\n"
1254 " OpUnreachable\n" // Unreachable default case for switch statement
1255 "%switch_merge = OpLabel\n"
1256 " OpUnreachable\n" // Unreachable merge block for switch statement
1260 "%func_const5 = OpFunction %u32 None %unitf\n"
1261 "%const5_entry = OpLabel\n"
1262 " OpReturnValue %five\n"
1263 "%unreachable = OpLabel\n"
1264 " OpUnreachable\n" // Unreachable block in function
1266 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
1267 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
1268 spec.numWorkGroups = IVec3(numElements, 1, 1);
1270 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "OpUnreachable appearing at different places", spec));
1272 return group.release();
1275 // Assembly code used for testing decoration group is based on GLSL source code:
1279 // layout(std140, set = 0, binding = 0) readonly buffer Input0 {
1280 // float elements[];
1282 // layout(std140, set = 0, binding = 1) readonly buffer Input1 {
1283 // float elements[];
1285 // layout(std140, set = 0, binding = 2) readonly buffer Input2 {
1286 // float elements[];
1288 // layout(std140, set = 0, binding = 3) readonly buffer Input3 {
1289 // float elements[];
1291 // layout(std140, set = 0, binding = 4) readonly buffer Input4 {
1292 // float elements[];
1294 // layout(std140, set = 0, binding = 5) writeonly buffer Output {
1295 // float elements[];
1299 // uint x = gl_GlobalInvocationID.x;
1300 // output_data.elements[x] = input_data0.elements[x] + input_data1.elements[x] + input_data2.elements[x] + input_data3.elements[x] + input_data4.elements[x];
1302 tcu::TestCaseGroup* createDecorationGroupGroup (tcu::TestContext& testCtx)
1304 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "decoration_group", "Test the OpDecorationGroup & OpGroupDecorate instruction"));
1305 ComputeShaderSpec spec;
1306 de::Random rnd (deStringHash(group->getName()));
1307 const int numElements = 100;
1308 vector<float> inputFloats0 (numElements, 0);
1309 vector<float> inputFloats1 (numElements, 0);
1310 vector<float> inputFloats2 (numElements, 0);
1311 vector<float> inputFloats3 (numElements, 0);
1312 vector<float> inputFloats4 (numElements, 0);
1313 vector<float> outputFloats (numElements, 0);
1315 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats0[0], numElements);
1316 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats1[0], numElements);
1317 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats2[0], numElements);
1318 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats3[0], numElements);
1319 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats4[0], numElements);
1321 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
1322 floorAll(inputFloats0);
1323 floorAll(inputFloats1);
1324 floorAll(inputFloats2);
1325 floorAll(inputFloats3);
1326 floorAll(inputFloats4);
1328 for (size_t ndx = 0; ndx < numElements; ++ndx)
1329 outputFloats[ndx] = inputFloats0[ndx] + inputFloats1[ndx] + inputFloats2[ndx] + inputFloats3[ndx] + inputFloats4[ndx];
1332 string(getComputeAsmShaderPreamble()) +
1334 "OpSource GLSL 430\n"
1335 "OpName %main \"main\"\n"
1336 "OpName %id \"gl_GlobalInvocationID\"\n"
1338 // Not using group decoration on variable.
1339 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1340 // Not using group decoration on type.
1341 "OpDecorate %f32arr ArrayStride 4\n"
1343 "OpDecorate %groups BufferBlock\n"
1344 "OpDecorate %groupm Offset 0\n"
1345 "%groups = OpDecorationGroup\n"
1346 "%groupm = OpDecorationGroup\n"
1348 // Group decoration on multiple structs.
1349 "OpGroupDecorate %groups %outbuf %inbuf0 %inbuf1 %inbuf2 %inbuf3 %inbuf4\n"
1350 // Group decoration on multiple struct members.
1351 "OpGroupMemberDecorate %groupm %outbuf 0 %inbuf0 0 %inbuf1 0 %inbuf2 0 %inbuf3 0 %inbuf4 0\n"
1353 "OpDecorate %group1 DescriptorSet 0\n"
1354 "OpDecorate %group3 DescriptorSet 0\n"
1355 "OpDecorate %group3 NonWritable\n"
1356 "OpDecorate %group3 Restrict\n"
1357 "%group0 = OpDecorationGroup\n"
1358 "%group1 = OpDecorationGroup\n"
1359 "%group3 = OpDecorationGroup\n"
1361 // Applying the same decoration group multiple times.
1362 "OpGroupDecorate %group1 %outdata\n"
1363 "OpGroupDecorate %group1 %outdata\n"
1364 "OpGroupDecorate %group1 %outdata\n"
1365 "OpDecorate %outdata DescriptorSet 0\n"
1366 "OpDecorate %outdata Binding 5\n"
1367 // Applying decoration group containing nothing.
1368 "OpGroupDecorate %group0 %indata0\n"
1369 "OpDecorate %indata0 DescriptorSet 0\n"
1370 "OpDecorate %indata0 Binding 0\n"
1371 // Applying decoration group containing one decoration.
1372 "OpGroupDecorate %group1 %indata1\n"
1373 "OpDecorate %indata1 Binding 1\n"
1374 // Applying decoration group containing multiple decorations.
1375 "OpGroupDecorate %group3 %indata2 %indata3\n"
1376 "OpDecorate %indata2 Binding 2\n"
1377 "OpDecorate %indata3 Binding 3\n"
1378 // Applying multiple decoration groups (with overlapping).
1379 "OpGroupDecorate %group0 %indata4\n"
1380 "OpGroupDecorate %group1 %indata4\n"
1381 "OpGroupDecorate %group3 %indata4\n"
1382 "OpDecorate %indata4 Binding 4\n"
1384 + string(getComputeAsmCommonTypes()) +
1386 "%id = OpVariable %uvec3ptr Input\n"
1387 "%zero = OpConstant %i32 0\n"
1389 "%outbuf = OpTypeStruct %f32arr\n"
1390 "%outbufptr = OpTypePointer Uniform %outbuf\n"
1391 "%outdata = OpVariable %outbufptr Uniform\n"
1392 "%inbuf0 = OpTypeStruct %f32arr\n"
1393 "%inbuf0ptr = OpTypePointer Uniform %inbuf0\n"
1394 "%indata0 = OpVariable %inbuf0ptr Uniform\n"
1395 "%inbuf1 = OpTypeStruct %f32arr\n"
1396 "%inbuf1ptr = OpTypePointer Uniform %inbuf1\n"
1397 "%indata1 = OpVariable %inbuf1ptr Uniform\n"
1398 "%inbuf2 = OpTypeStruct %f32arr\n"
1399 "%inbuf2ptr = OpTypePointer Uniform %inbuf2\n"
1400 "%indata2 = OpVariable %inbuf2ptr Uniform\n"
1401 "%inbuf3 = OpTypeStruct %f32arr\n"
1402 "%inbuf3ptr = OpTypePointer Uniform %inbuf3\n"
1403 "%indata3 = OpVariable %inbuf3ptr Uniform\n"
1404 "%inbuf4 = OpTypeStruct %f32arr\n"
1405 "%inbufptr = OpTypePointer Uniform %inbuf4\n"
1406 "%indata4 = OpVariable %inbufptr Uniform\n"
1408 "%main = OpFunction %void None %voidf\n"
1409 "%label = OpLabel\n"
1410 "%idval = OpLoad %uvec3 %id\n"
1411 "%x = OpCompositeExtract %u32 %idval 0\n"
1412 "%inloc0 = OpAccessChain %f32ptr %indata0 %zero %x\n"
1413 "%inloc1 = OpAccessChain %f32ptr %indata1 %zero %x\n"
1414 "%inloc2 = OpAccessChain %f32ptr %indata2 %zero %x\n"
1415 "%inloc3 = OpAccessChain %f32ptr %indata3 %zero %x\n"
1416 "%inloc4 = OpAccessChain %f32ptr %indata4 %zero %x\n"
1417 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
1418 "%inval0 = OpLoad %f32 %inloc0\n"
1419 "%inval1 = OpLoad %f32 %inloc1\n"
1420 "%inval2 = OpLoad %f32 %inloc2\n"
1421 "%inval3 = OpLoad %f32 %inloc3\n"
1422 "%inval4 = OpLoad %f32 %inloc4\n"
1423 "%add0 = OpFAdd %f32 %inval0 %inval1\n"
1424 "%add1 = OpFAdd %f32 %add0 %inval2\n"
1425 "%add2 = OpFAdd %f32 %add1 %inval3\n"
1426 "%add = OpFAdd %f32 %add2 %inval4\n"
1427 " OpStore %outloc %add\n"
1430 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats0)));
1431 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats1)));
1432 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
1433 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats3)));
1434 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats4)));
1435 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
1436 spec.numWorkGroups = IVec3(numElements, 1, 1);
1438 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "decoration group cases", spec));
1440 return group.release();
1443 struct SpecConstantTwoIntCase
1445 const char* caseName;
1446 const char* scDefinition0;
1447 const char* scDefinition1;
1448 const char* scResultType;
1449 const char* scOperation;
1450 deInt32 scActualValue0;
1451 deInt32 scActualValue1;
1452 const char* resultOperation;
1453 vector<deInt32> expectedOutput;
1455 SpecConstantTwoIntCase (const char* name,
1456 const char* definition0,
1457 const char* definition1,
1458 const char* resultType,
1459 const char* operation,
1462 const char* resultOp,
1463 const vector<deInt32>& output)
1465 , scDefinition0 (definition0)
1466 , scDefinition1 (definition1)
1467 , scResultType (resultType)
1468 , scOperation (operation)
1469 , scActualValue0 (value0)
1470 , scActualValue1 (value1)
1471 , resultOperation (resultOp)
1472 , expectedOutput (output) {}
1475 tcu::TestCaseGroup* createSpecConstantGroup (tcu::TestContext& testCtx)
1477 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opspecconstantop", "Test the OpSpecConstantOp instruction"));
1478 vector<SpecConstantTwoIntCase> cases;
1479 de::Random rnd (deStringHash(group->getName()));
1480 const int numElements = 100;
1481 vector<deInt32> inputInts (numElements, 0);
1482 vector<deInt32> outputInts1 (numElements, 0);
1483 vector<deInt32> outputInts2 (numElements, 0);
1484 vector<deInt32> outputInts3 (numElements, 0);
1485 vector<deInt32> outputInts4 (numElements, 0);
1486 const StringTemplate shaderTemplate (
1487 string(getComputeAsmShaderPreamble()) +
1489 "OpName %main \"main\"\n"
1490 "OpName %id \"gl_GlobalInvocationID\"\n"
1492 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1493 "OpDecorate %sc_0 SpecId 0\n"
1494 "OpDecorate %sc_1 SpecId 1\n"
1495 "OpDecorate %i32arr ArrayStride 4\n"
1497 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
1499 "%buf = OpTypeStruct %i32arr\n"
1500 "%bufptr = OpTypePointer Uniform %buf\n"
1501 "%indata = OpVariable %bufptr Uniform\n"
1502 "%outdata = OpVariable %bufptr Uniform\n"
1504 "%id = OpVariable %uvec3ptr Input\n"
1505 "%zero = OpConstant %i32 0\n"
1507 "%sc_0 = OpSpecConstant${SC_DEF0}\n"
1508 "%sc_1 = OpSpecConstant${SC_DEF1}\n"
1509 "%sc_final = OpSpecConstantOp ${SC_RESULT_TYPE} ${SC_OP}\n"
1511 "%main = OpFunction %void None %voidf\n"
1512 "%label = OpLabel\n"
1513 "%idval = OpLoad %uvec3 %id\n"
1514 "%x = OpCompositeExtract %u32 %idval 0\n"
1515 "%inloc = OpAccessChain %i32ptr %indata %zero %x\n"
1516 "%inval = OpLoad %i32 %inloc\n"
1517 "%final = ${GEN_RESULT}\n"
1518 "%outloc = OpAccessChain %i32ptr %outdata %zero %x\n"
1519 " OpStore %outloc %final\n"
1521 " OpFunctionEnd\n");
1523 fillRandomScalars(rnd, -65536, 65536, &inputInts[0], numElements);
1525 for (size_t ndx = 0; ndx < numElements; ++ndx)
1527 outputInts1[ndx] = inputInts[ndx] + 42;
1528 outputInts2[ndx] = inputInts[ndx];
1529 outputInts3[ndx] = inputInts[ndx] - 11200;
1530 outputInts4[ndx] = inputInts[ndx] + 1;
1533 const char addScToInput[] = "OpIAdd %i32 %inval %sc_final";
1534 const char selectTrueUsingSc[] = "OpSelect %i32 %sc_final %inval %zero";
1535 const char selectFalseUsingSc[] = "OpSelect %i32 %sc_final %zero %inval";
1537 cases.push_back(SpecConstantTwoIntCase("iadd", " %i32 0", " %i32 0", "%i32", "IAdd %sc_0 %sc_1", 62, -20, addScToInput, outputInts1));
1538 cases.push_back(SpecConstantTwoIntCase("isub", " %i32 0", " %i32 0", "%i32", "ISub %sc_0 %sc_1", 100, 58, addScToInput, outputInts1));
1539 cases.push_back(SpecConstantTwoIntCase("imul", " %i32 0", " %i32 0", "%i32", "IMul %sc_0 %sc_1", -2, -21, addScToInput, outputInts1));
1540 cases.push_back(SpecConstantTwoIntCase("sdiv", " %i32 0", " %i32 0", "%i32", "SDiv %sc_0 %sc_1", -126, -3, addScToInput, outputInts1));
1541 cases.push_back(SpecConstantTwoIntCase("udiv", " %i32 0", " %i32 0", "%i32", "UDiv %sc_0 %sc_1", 126, 3, addScToInput, outputInts1));
1542 cases.push_back(SpecConstantTwoIntCase("srem", " %i32 0", " %i32 0", "%i32", "SRem %sc_0 %sc_1", 7, 3, addScToInput, outputInts4));
1543 cases.push_back(SpecConstantTwoIntCase("smod", " %i32 0", " %i32 0", "%i32", "SMod %sc_0 %sc_1", 7, 3, addScToInput, outputInts4));
1544 cases.push_back(SpecConstantTwoIntCase("umod", " %i32 0", " %i32 0", "%i32", "UMod %sc_0 %sc_1", 342, 50, addScToInput, outputInts1));
1545 cases.push_back(SpecConstantTwoIntCase("bitwiseand", " %i32 0", " %i32 0", "%i32", "BitwiseAnd %sc_0 %sc_1", 42, 63, addScToInput, outputInts1));
1546 cases.push_back(SpecConstantTwoIntCase("bitwiseor", " %i32 0", " %i32 0", "%i32", "BitwiseOr %sc_0 %sc_1", 34, 8, addScToInput, outputInts1));
1547 cases.push_back(SpecConstantTwoIntCase("bitwisexor", " %i32 0", " %i32 0", "%i32", "BitwiseXor %sc_0 %sc_1", 18, 56, addScToInput, outputInts1));
1548 cases.push_back(SpecConstantTwoIntCase("shiftrightlogical", " %i32 0", " %i32 0", "%i32", "ShiftRightLogical %sc_0 %sc_1", 168, 2, addScToInput, outputInts1));
1549 cases.push_back(SpecConstantTwoIntCase("shiftrightarithmetic", " %i32 0", " %i32 0", "%i32", "ShiftRightArithmetic %sc_0 %sc_1", 168, 2, addScToInput, outputInts1));
1550 cases.push_back(SpecConstantTwoIntCase("shiftleftlogical", " %i32 0", " %i32 0", "%i32", "ShiftLeftLogical %sc_0 %sc_1", 21, 1, addScToInput, outputInts1));
1551 cases.push_back(SpecConstantTwoIntCase("slessthan", " %i32 0", " %i32 0", "%bool", "SLessThan %sc_0 %sc_1", -20, -10, selectTrueUsingSc, outputInts2));
1552 cases.push_back(SpecConstantTwoIntCase("ulessthan", " %i32 0", " %i32 0", "%bool", "ULessThan %sc_0 %sc_1", 10, 20, selectTrueUsingSc, outputInts2));
1553 cases.push_back(SpecConstantTwoIntCase("sgreaterthan", " %i32 0", " %i32 0", "%bool", "SGreaterThan %sc_0 %sc_1", -1000, 50, selectFalseUsingSc, outputInts2));
1554 cases.push_back(SpecConstantTwoIntCase("ugreaterthan", " %i32 0", " %i32 0", "%bool", "UGreaterThan %sc_0 %sc_1", 10, 5, selectTrueUsingSc, outputInts2));
1555 cases.push_back(SpecConstantTwoIntCase("slessthanequal", " %i32 0", " %i32 0", "%bool", "SLessThanEqual %sc_0 %sc_1", -10, -10, selectTrueUsingSc, outputInts2));
1556 cases.push_back(SpecConstantTwoIntCase("ulessthanequal", " %i32 0", " %i32 0", "%bool", "ULessThanEqual %sc_0 %sc_1", 50, 100, selectTrueUsingSc, outputInts2));
1557 cases.push_back(SpecConstantTwoIntCase("sgreaterthanequal", " %i32 0", " %i32 0", "%bool", "SGreaterThanEqual %sc_0 %sc_1", -1000, 50, selectFalseUsingSc, outputInts2));
1558 cases.push_back(SpecConstantTwoIntCase("ugreaterthanequal", " %i32 0", " %i32 0", "%bool", "UGreaterThanEqual %sc_0 %sc_1", 10, 10, selectTrueUsingSc, outputInts2));
1559 cases.push_back(SpecConstantTwoIntCase("iequal", " %i32 0", " %i32 0", "%bool", "IEqual %sc_0 %sc_1", 42, 24, selectFalseUsingSc, outputInts2));
1560 cases.push_back(SpecConstantTwoIntCase("logicaland", "True %bool", "True %bool", "%bool", "LogicalAnd %sc_0 %sc_1", 0, 1, selectFalseUsingSc, outputInts2));
1561 cases.push_back(SpecConstantTwoIntCase("logicalor", "False %bool", "False %bool", "%bool", "LogicalOr %sc_0 %sc_1", 1, 0, selectTrueUsingSc, outputInts2));
1562 cases.push_back(SpecConstantTwoIntCase("logicalequal", "True %bool", "True %bool", "%bool", "LogicalEqual %sc_0 %sc_1", 0, 1, selectFalseUsingSc, outputInts2));
1563 cases.push_back(SpecConstantTwoIntCase("logicalnotequal", "False %bool", "False %bool", "%bool", "LogicalNotEqual %sc_0 %sc_1", 1, 0, selectTrueUsingSc, outputInts2));
1564 cases.push_back(SpecConstantTwoIntCase("snegate", " %i32 0", " %i32 0", "%i32", "SNegate %sc_0", -42, 0, addScToInput, outputInts1));
1565 cases.push_back(SpecConstantTwoIntCase("not", " %i32 0", " %i32 0", "%i32", "Not %sc_0", -43, 0, addScToInput, outputInts1));
1566 cases.push_back(SpecConstantTwoIntCase("logicalnot", "False %bool", "False %bool", "%bool", "LogicalNot %sc_0", 1, 0, selectFalseUsingSc, outputInts2));
1567 cases.push_back(SpecConstantTwoIntCase("select", "False %bool", " %i32 0", "%i32", "Select %sc_0 %sc_1 %zero", 1, 42, addScToInput, outputInts1));
1568 // OpSConvert, OpFConvert: these two instructions involve ints/floats of different bitwidths.
1570 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
1572 map<string, string> specializations;
1573 ComputeShaderSpec spec;
1575 specializations["SC_DEF0"] = cases[caseNdx].scDefinition0;
1576 specializations["SC_DEF1"] = cases[caseNdx].scDefinition1;
1577 specializations["SC_RESULT_TYPE"] = cases[caseNdx].scResultType;
1578 specializations["SC_OP"] = cases[caseNdx].scOperation;
1579 specializations["GEN_RESULT"] = cases[caseNdx].resultOperation;
1581 spec.assembly = shaderTemplate.specialize(specializations);
1582 spec.inputs.push_back(BufferSp(new Int32Buffer(inputInts)));
1583 spec.outputs.push_back(BufferSp(new Int32Buffer(cases[caseNdx].expectedOutput)));
1584 spec.numWorkGroups = IVec3(numElements, 1, 1);
1585 spec.specConstants.push_back(cases[caseNdx].scActualValue0);
1586 spec.specConstants.push_back(cases[caseNdx].scActualValue1);
1588 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].caseName, cases[caseNdx].caseName, spec));
1591 ComputeShaderSpec spec;
1594 string(getComputeAsmShaderPreamble()) +
1596 "OpName %main \"main\"\n"
1597 "OpName %id \"gl_GlobalInvocationID\"\n"
1599 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1600 "OpDecorate %sc_0 SpecId 0\n"
1601 "OpDecorate %sc_1 SpecId 1\n"
1602 "OpDecorate %sc_2 SpecId 2\n"
1603 "OpDecorate %i32arr ArrayStride 4\n"
1605 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
1607 "%ivec3 = OpTypeVector %i32 3\n"
1608 "%buf = OpTypeStruct %i32arr\n"
1609 "%bufptr = OpTypePointer Uniform %buf\n"
1610 "%indata = OpVariable %bufptr Uniform\n"
1611 "%outdata = OpVariable %bufptr Uniform\n"
1613 "%id = OpVariable %uvec3ptr Input\n"
1614 "%zero = OpConstant %i32 0\n"
1615 "%ivec3_0 = OpConstantComposite %ivec3 %zero %zero %zero\n"
1617 "%sc_0 = OpSpecConstant %i32 0\n"
1618 "%sc_1 = OpSpecConstant %i32 0\n"
1619 "%sc_2 = OpSpecConstant %i32 0\n"
1620 "%sc_vec3_0 = OpSpecConstantOp %ivec3 CompositeInsert %sc_0 %ivec3_0 0\n" // (sc_0, 0, 0)
1621 "%sc_vec3_1 = OpSpecConstantOp %ivec3 CompositeInsert %sc_1 %ivec3_0 1\n" // (0, sc_1, 0)
1622 "%sc_vec3_2 = OpSpecConstantOp %ivec3 CompositeInsert %sc_2 %ivec3_0 2\n" // (0, 0, sc_2)
1623 "%sc_vec3_01 = OpSpecConstantOp %ivec3 VectorShuffle %sc_vec3_0 %sc_vec3_1 1 0 4\n" // (0, sc_0, sc_1)
1624 "%sc_vec3_012 = OpSpecConstantOp %ivec3 VectorShuffle %sc_vec3_01 %sc_vec3_2 5 1 2\n" // (sc_2, sc_0, sc_1)
1625 "%sc_ext_0 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 0\n" // sc_2
1626 "%sc_ext_1 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 1\n" // sc_0
1627 "%sc_ext_2 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 2\n" // sc_1
1628 "%sc_sub = OpSpecConstantOp %i32 ISub %sc_ext_0 %sc_ext_1\n" // (sc_2 - sc_0)
1629 "%sc_final = OpSpecConstantOp %i32 IMul %sc_sub %sc_ext_2\n" // (sc_2 - sc_0) * sc_1
1631 "%main = OpFunction %void None %voidf\n"
1632 "%label = OpLabel\n"
1633 "%idval = OpLoad %uvec3 %id\n"
1634 "%x = OpCompositeExtract %u32 %idval 0\n"
1635 "%inloc = OpAccessChain %i32ptr %indata %zero %x\n"
1636 "%inval = OpLoad %i32 %inloc\n"
1637 "%final = OpIAdd %i32 %inval %sc_final\n"
1638 "%outloc = OpAccessChain %i32ptr %outdata %zero %x\n"
1639 " OpStore %outloc %final\n"
1642 spec.inputs.push_back(BufferSp(new Int32Buffer(inputInts)));
1643 spec.outputs.push_back(BufferSp(new Int32Buffer(outputInts3)));
1644 spec.numWorkGroups = IVec3(numElements, 1, 1);
1645 spec.specConstants.push_back(123);
1646 spec.specConstants.push_back(56);
1647 spec.specConstants.push_back(-77);
1649 group->addChild(new SpvAsmComputeShaderCase(testCtx, "vector_related", "VectorShuffle, CompositeExtract, & CompositeInsert", spec));
1651 return group.release();
1654 tcu::TestCaseGroup* createOpPhiGroup (tcu::TestContext& testCtx)
1656 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opphi", "Test the OpPhi instruction"));
1657 ComputeShaderSpec spec1;
1658 ComputeShaderSpec spec2;
1659 ComputeShaderSpec spec3;
1660 de::Random rnd (deStringHash(group->getName()));
1661 const int numElements = 100;
1662 vector<float> inputFloats (numElements, 0);
1663 vector<float> outputFloats1 (numElements, 0);
1664 vector<float> outputFloats2 (numElements, 0);
1665 vector<float> outputFloats3 (numElements, 0);
1667 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats[0], numElements);
1669 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
1670 floorAll(inputFloats);
1672 for (size_t ndx = 0; ndx < numElements; ++ndx)
1676 case 0: outputFloats1[ndx] = inputFloats[ndx] + 5.5f; break;
1677 case 1: outputFloats1[ndx] = inputFloats[ndx] + 20.5f; break;
1678 case 2: outputFloats1[ndx] = inputFloats[ndx] + 1.75f; break;
1681 outputFloats2[ndx] = inputFloats[ndx] + 6.5f * 3;
1682 outputFloats3[ndx] = 8.5f - inputFloats[ndx];
1686 string(getComputeAsmShaderPreamble()) +
1688 "OpSource GLSL 430\n"
1689 "OpName %main \"main\"\n"
1690 "OpName %id \"gl_GlobalInvocationID\"\n"
1692 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1694 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
1696 "%id = OpVariable %uvec3ptr Input\n"
1697 "%zero = OpConstant %i32 0\n"
1698 "%three = OpConstant %u32 3\n"
1699 "%constf5p5 = OpConstant %f32 5.5\n"
1700 "%constf20p5 = OpConstant %f32 20.5\n"
1701 "%constf1p75 = OpConstant %f32 1.75\n"
1702 "%constf8p5 = OpConstant %f32 8.5\n"
1703 "%constf6p5 = OpConstant %f32 6.5\n"
1705 "%main = OpFunction %void None %voidf\n"
1706 "%entry = OpLabel\n"
1707 "%idval = OpLoad %uvec3 %id\n"
1708 "%x = OpCompositeExtract %u32 %idval 0\n"
1709 "%selector = OpUMod %u32 %x %three\n"
1710 " OpSelectionMerge %phi None\n"
1711 " OpSwitch %selector %default 0 %case0 1 %case1 2 %case2\n"
1713 // Case 1 before OpPhi.
1714 "%case1 = OpLabel\n"
1717 "%default = OpLabel\n"
1721 "%operand = OpPhi %f32 %constf1p75 %case2 %constf20p5 %case1 %constf5p5 %case0\n" // not in the order of blocks
1722 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
1723 "%inval = OpLoad %f32 %inloc\n"
1724 "%add = OpFAdd %f32 %inval %operand\n"
1725 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
1726 " OpStore %outloc %add\n"
1729 // Case 0 after OpPhi.
1730 "%case0 = OpLabel\n"
1734 // Case 2 after OpPhi.
1735 "%case2 = OpLabel\n"
1739 spec1.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
1740 spec1.outputs.push_back(BufferSp(new Float32Buffer(outputFloats1)));
1741 spec1.numWorkGroups = IVec3(numElements, 1, 1);
1743 group->addChild(new SpvAsmComputeShaderCase(testCtx, "block", "out-of-order and unreachable blocks for OpPhi", spec1));
1746 string(getComputeAsmShaderPreamble()) +
1748 "OpName %main \"main\"\n"
1749 "OpName %id \"gl_GlobalInvocationID\"\n"
1751 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1753 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
1755 "%id = OpVariable %uvec3ptr Input\n"
1756 "%zero = OpConstant %i32 0\n"
1757 "%one = OpConstant %i32 1\n"
1758 "%three = OpConstant %i32 3\n"
1759 "%constf6p5 = OpConstant %f32 6.5\n"
1761 "%main = OpFunction %void None %voidf\n"
1762 "%entry = OpLabel\n"
1763 "%idval = OpLoad %uvec3 %id\n"
1764 "%x = OpCompositeExtract %u32 %idval 0\n"
1765 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
1766 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
1767 "%inval = OpLoad %f32 %inloc\n"
1771 "%step = OpPhi %i32 %zero %entry %step_next %phi\n"
1772 "%accum = OpPhi %f32 %inval %entry %accum_next %phi\n"
1773 "%step_next = OpIAdd %i32 %step %one\n"
1774 "%accum_next = OpFAdd %f32 %accum %constf6p5\n"
1775 "%still_loop = OpSLessThan %bool %step %three\n"
1776 " OpLoopMerge %exit %phi None\n"
1777 " OpBranchConditional %still_loop %phi %exit\n"
1780 " OpStore %outloc %accum\n"
1783 spec2.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
1784 spec2.outputs.push_back(BufferSp(new Float32Buffer(outputFloats2)));
1785 spec2.numWorkGroups = IVec3(numElements, 1, 1);
1787 group->addChild(new SpvAsmComputeShaderCase(testCtx, "induction", "The usual way induction variables are handled in LLVM IR", spec2));
1790 string(getComputeAsmShaderPreamble()) +
1792 "OpName %main \"main\"\n"
1793 "OpName %id \"gl_GlobalInvocationID\"\n"
1795 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1797 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
1799 "%f32ptr_f = OpTypePointer Function %f32\n"
1800 "%id = OpVariable %uvec3ptr Input\n"
1801 "%true = OpConstantTrue %bool\n"
1802 "%false = OpConstantFalse %bool\n"
1803 "%zero = OpConstant %i32 0\n"
1804 "%constf8p5 = OpConstant %f32 8.5\n"
1806 "%main = OpFunction %void None %voidf\n"
1807 "%entry = OpLabel\n"
1808 "%b = OpVariable %f32ptr_f Function %constf8p5\n"
1809 "%idval = OpLoad %uvec3 %id\n"
1810 "%x = OpCompositeExtract %u32 %idval 0\n"
1811 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
1812 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
1813 "%a_init = OpLoad %f32 %inloc\n"
1814 "%b_init = OpLoad %f32 %b\n"
1818 "%still_loop = OpPhi %bool %true %entry %false %phi\n"
1819 "%a_next = OpPhi %f32 %a_init %entry %b_next %phi\n"
1820 "%b_next = OpPhi %f32 %b_init %entry %a_next %phi\n"
1821 " OpLoopMerge %exit %phi None\n"
1822 " OpBranchConditional %still_loop %phi %exit\n"
1825 "%sub = OpFSub %f32 %a_next %b_next\n"
1826 " OpStore %outloc %sub\n"
1829 spec3.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
1830 spec3.outputs.push_back(BufferSp(new Float32Buffer(outputFloats3)));
1831 spec3.numWorkGroups = IVec3(numElements, 1, 1);
1833 group->addChild(new SpvAsmComputeShaderCase(testCtx, "swap", "Swap the values of two variables using OpPhi", spec3));
1835 return group.release();
1838 // Assembly code used for testing block order is based on GLSL source code:
1842 // layout(std140, set = 0, binding = 0) readonly buffer Input {
1843 // float elements[];
1845 // layout(std140, set = 0, binding = 1) writeonly buffer Output {
1846 // float elements[];
1850 // uint x = gl_GlobalInvocationID.x;
1851 // output_data.elements[x] = input_data.elements[x];
1852 // if (x > uint(50)) {
1853 // switch (x % uint(3)) {
1854 // case 0: output_data.elements[x] += 1.5f; break;
1855 // case 1: output_data.elements[x] += 42.f; break;
1856 // case 2: output_data.elements[x] -= 27.f; break;
1860 // output_data.elements[x] = -input_data.elements[x];
1863 tcu::TestCaseGroup* createBlockOrderGroup (tcu::TestContext& testCtx)
1865 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "block_order", "Test block orders"));
1866 ComputeShaderSpec spec;
1867 de::Random rnd (deStringHash(group->getName()));
1868 const int numElements = 100;
1869 vector<float> inputFloats (numElements, 0);
1870 vector<float> outputFloats (numElements, 0);
1872 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats[0], numElements);
1874 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
1875 floorAll(inputFloats);
1877 for (size_t ndx = 0; ndx <= 50; ++ndx)
1878 outputFloats[ndx] = -inputFloats[ndx];
1880 for (size_t ndx = 51; ndx < numElements; ++ndx)
1884 case 0: outputFloats[ndx] = inputFloats[ndx] + 1.5f; break;
1885 case 1: outputFloats[ndx] = inputFloats[ndx] + 42.f; break;
1886 case 2: outputFloats[ndx] = inputFloats[ndx] - 27.f; break;
1892 string(getComputeAsmShaderPreamble()) +
1894 "OpSource GLSL 430\n"
1895 "OpName %main \"main\"\n"
1896 "OpName %id \"gl_GlobalInvocationID\"\n"
1898 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1900 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
1902 "%u32ptr = OpTypePointer Function %u32\n"
1903 "%u32ptr_input = OpTypePointer Input %u32\n"
1905 + string(getComputeAsmInputOutputBuffer()) +
1907 "%id = OpVariable %uvec3ptr Input\n"
1908 "%zero = OpConstant %i32 0\n"
1909 "%const3 = OpConstant %u32 3\n"
1910 "%const50 = OpConstant %u32 50\n"
1911 "%constf1p5 = OpConstant %f32 1.5\n"
1912 "%constf27 = OpConstant %f32 27.0\n"
1913 "%constf42 = OpConstant %f32 42.0\n"
1915 "%main = OpFunction %void None %voidf\n"
1918 "%entry = OpLabel\n"
1920 // Create a temporary variable to hold the value of gl_GlobalInvocationID.x.
1921 "%xvar = OpVariable %u32ptr Function\n"
1922 "%xptr = OpAccessChain %u32ptr_input %id %zero\n"
1923 "%x = OpLoad %u32 %xptr\n"
1924 " OpStore %xvar %x\n"
1926 "%cmp = OpUGreaterThan %bool %x %const50\n"
1927 " OpSelectionMerge %if_merge None\n"
1928 " OpBranchConditional %cmp %if_true %if_false\n"
1930 // False branch for if-statement: placed in the middle of switch cases and before true branch.
1931 "%if_false = OpLabel\n"
1932 "%x_f = OpLoad %u32 %xvar\n"
1933 "%inloc_f = OpAccessChain %f32ptr %indata %zero %x_f\n"
1934 "%inval_f = OpLoad %f32 %inloc_f\n"
1935 "%negate = OpFNegate %f32 %inval_f\n"
1936 "%outloc_f = OpAccessChain %f32ptr %outdata %zero %x_f\n"
1937 " OpStore %outloc_f %negate\n"
1938 " OpBranch %if_merge\n"
1940 // Merge block for if-statement: placed in the middle of true and false branch.
1941 "%if_merge = OpLabel\n"
1944 // True branch for if-statement: placed in the middle of swtich cases and after the false branch.
1945 "%if_true = OpLabel\n"
1946 "%xval_t = OpLoad %u32 %xvar\n"
1947 "%mod = OpUMod %u32 %xval_t %const3\n"
1948 " OpSelectionMerge %switch_merge None\n"
1949 " OpSwitch %mod %default 0 %case0 1 %case1 2 %case2\n"
1951 // Merge block for switch-statement: placed before the case
1952 // bodies. But it must follow OpSwitch which dominates it.
1953 "%switch_merge = OpLabel\n"
1954 " OpBranch %if_merge\n"
1956 // Case 1 for switch-statement: placed before case 0.
1957 // It must follow the OpSwitch that dominates it.
1958 "%case1 = OpLabel\n"
1959 "%x_1 = OpLoad %u32 %xvar\n"
1960 "%inloc_1 = OpAccessChain %f32ptr %indata %zero %x_1\n"
1961 "%inval_1 = OpLoad %f32 %inloc_1\n"
1962 "%addf42 = OpFAdd %f32 %inval_1 %constf42\n"
1963 "%outloc_1 = OpAccessChain %f32ptr %outdata %zero %x_1\n"
1964 " OpStore %outloc_1 %addf42\n"
1965 " OpBranch %switch_merge\n"
1967 // Case 2 for switch-statement.
1968 "%case2 = OpLabel\n"
1969 "%x_2 = OpLoad %u32 %xvar\n"
1970 "%inloc_2 = OpAccessChain %f32ptr %indata %zero %x_2\n"
1971 "%inval_2 = OpLoad %f32 %inloc_2\n"
1972 "%subf27 = OpFSub %f32 %inval_2 %constf27\n"
1973 "%outloc_2 = OpAccessChain %f32ptr %outdata %zero %x_2\n"
1974 " OpStore %outloc_2 %subf27\n"
1975 " OpBranch %switch_merge\n"
1977 // Default case for switch-statement: placed in the middle of normal cases.
1978 "%default = OpLabel\n"
1979 " OpBranch %switch_merge\n"
1981 // Case 0 for switch-statement: out of order.
1982 "%case0 = OpLabel\n"
1983 "%x_0 = OpLoad %u32 %xvar\n"
1984 "%inloc_0 = OpAccessChain %f32ptr %indata %zero %x_0\n"
1985 "%inval_0 = OpLoad %f32 %inloc_0\n"
1986 "%addf1p5 = OpFAdd %f32 %inval_0 %constf1p5\n"
1987 "%outloc_0 = OpAccessChain %f32ptr %outdata %zero %x_0\n"
1988 " OpStore %outloc_0 %addf1p5\n"
1989 " OpBranch %switch_merge\n"
1992 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
1993 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
1994 spec.numWorkGroups = IVec3(numElements, 1, 1);
1996 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "various out-of-order blocks", spec));
1998 return group.release();
2001 tcu::TestCaseGroup* createMultipleShaderGroup (tcu::TestContext& testCtx)
2003 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "multiple_shaders", "Test multiple shaders in the same module"));
2004 ComputeShaderSpec spec1;
2005 ComputeShaderSpec spec2;
2006 de::Random rnd (deStringHash(group->getName()));
2007 const int numElements = 100;
2008 vector<float> inputFloats (numElements, 0);
2009 vector<float> outputFloats1 (numElements, 0);
2010 vector<float> outputFloats2 (numElements, 0);
2011 fillRandomScalars(rnd, -500.f, 500.f, &inputFloats[0], numElements);
2013 for (size_t ndx = 0; ndx < numElements; ++ndx)
2015 outputFloats1[ndx] = inputFloats[ndx] + inputFloats[ndx];
2016 outputFloats2[ndx] = -inputFloats[ndx];
2019 const string assembly(
2020 "OpCapability Shader\n"
2021 "OpCapability ClipDistance\n"
2022 "OpMemoryModel Logical GLSL450\n"
2023 "OpEntryPoint GLCompute %comp_main1 \"entrypoint1\" %id\n"
2024 "OpEntryPoint GLCompute %comp_main2 \"entrypoint2\" %id\n"
2025 // A module cannot have two OpEntryPoint instructions with the same Execution Model and the same Name string.
2026 "OpEntryPoint Vertex %vert_main \"entrypoint2\" %vert_builtins %vertexIndex %instanceIndex\n"
2027 "OpExecutionMode %comp_main1 LocalSize 1 1 1\n"
2028 "OpExecutionMode %comp_main2 LocalSize 1 1 1\n"
2030 "OpName %comp_main1 \"entrypoint1\"\n"
2031 "OpName %comp_main2 \"entrypoint2\"\n"
2032 "OpName %vert_main \"entrypoint2\"\n"
2033 "OpName %id \"gl_GlobalInvocationID\"\n"
2034 "OpName %vert_builtin_st \"gl_PerVertex\"\n"
2035 "OpName %vertexIndex \"gl_VertexIndex\"\n"
2036 "OpName %instanceIndex \"gl_InstanceIndex\"\n"
2037 "OpMemberName %vert_builtin_st 0 \"gl_Position\"\n"
2038 "OpMemberName %vert_builtin_st 1 \"gl_PointSize\"\n"
2039 "OpMemberName %vert_builtin_st 2 \"gl_ClipDistance\"\n"
2041 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2042 "OpDecorate %vertexIndex BuiltIn VertexIndex\n"
2043 "OpDecorate %instanceIndex BuiltIn InstanceIndex\n"
2044 "OpDecorate %vert_builtin_st Block\n"
2045 "OpMemberDecorate %vert_builtin_st 0 BuiltIn Position\n"
2046 "OpMemberDecorate %vert_builtin_st 1 BuiltIn PointSize\n"
2047 "OpMemberDecorate %vert_builtin_st 2 BuiltIn ClipDistance\n"
2049 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
2051 "%zero = OpConstant %i32 0\n"
2052 "%one = OpConstant %u32 1\n"
2053 "%c_f32_1 = OpConstant %f32 1\n"
2055 "%i32inputptr = OpTypePointer Input %i32\n"
2056 "%vec4 = OpTypeVector %f32 4\n"
2057 "%vec4ptr = OpTypePointer Output %vec4\n"
2058 "%f32arr1 = OpTypeArray %f32 %one\n"
2059 "%vert_builtin_st = OpTypeStruct %vec4 %f32 %f32arr1\n"
2060 "%vert_builtin_st_ptr = OpTypePointer Output %vert_builtin_st\n"
2061 "%vert_builtins = OpVariable %vert_builtin_st_ptr Output\n"
2063 "%id = OpVariable %uvec3ptr Input\n"
2064 "%vertexIndex = OpVariable %i32inputptr Input\n"
2065 "%instanceIndex = OpVariable %i32inputptr Input\n"
2066 "%c_vec4_1 = OpConstantComposite %vec4 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_1\n"
2068 // gl_Position = vec4(1.);
2069 "%vert_main = OpFunction %void None %voidf\n"
2070 "%vert_entry = OpLabel\n"
2071 "%position = OpAccessChain %vec4ptr %vert_builtins %zero\n"
2072 " OpStore %position %c_vec4_1\n"
2077 "%comp_main1 = OpFunction %void None %voidf\n"
2078 "%comp1_entry = OpLabel\n"
2079 "%idval1 = OpLoad %uvec3 %id\n"
2080 "%x1 = OpCompositeExtract %u32 %idval1 0\n"
2081 "%inloc1 = OpAccessChain %f32ptr %indata %zero %x1\n"
2082 "%inval1 = OpLoad %f32 %inloc1\n"
2083 "%add = OpFAdd %f32 %inval1 %inval1\n"
2084 "%outloc1 = OpAccessChain %f32ptr %outdata %zero %x1\n"
2085 " OpStore %outloc1 %add\n"
2090 "%comp_main2 = OpFunction %void None %voidf\n"
2091 "%comp2_entry = OpLabel\n"
2092 "%idval2 = OpLoad %uvec3 %id\n"
2093 "%x2 = OpCompositeExtract %u32 %idval2 0\n"
2094 "%inloc2 = OpAccessChain %f32ptr %indata %zero %x2\n"
2095 "%inval2 = OpLoad %f32 %inloc2\n"
2096 "%neg = OpFNegate %f32 %inval2\n"
2097 "%outloc2 = OpAccessChain %f32ptr %outdata %zero %x2\n"
2098 " OpStore %outloc2 %neg\n"
2100 " OpFunctionEnd\n");
2102 spec1.assembly = assembly;
2103 spec1.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
2104 spec1.outputs.push_back(BufferSp(new Float32Buffer(outputFloats1)));
2105 spec1.numWorkGroups = IVec3(numElements, 1, 1);
2106 spec1.entryPoint = "entrypoint1";
2108 spec2.assembly = assembly;
2109 spec2.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
2110 spec2.outputs.push_back(BufferSp(new Float32Buffer(outputFloats2)));
2111 spec2.numWorkGroups = IVec3(numElements, 1, 1);
2112 spec2.entryPoint = "entrypoint2";
2114 group->addChild(new SpvAsmComputeShaderCase(testCtx, "shader1", "multiple shaders in the same module", spec1));
2115 group->addChild(new SpvAsmComputeShaderCase(testCtx, "shader2", "multiple shaders in the same module", spec2));
2117 return group.release();
2120 inline std::string makeLongUTF8String (size_t num4ByteChars)
2122 // An example of a longest valid UTF-8 character. Be explicit about the
2123 // character type because Microsoft compilers can otherwise interpret the
2124 // character string as being over wide (16-bit) characters. Ideally, we
2125 // would just use a C++11 UTF-8 string literal, but we want to support older
2126 // Microsoft compilers.
2127 const std::basic_string<char> earthAfrica("\xF0\x9F\x8C\x8D");
2128 std::string longString;
2129 longString.reserve(num4ByteChars * 4);
2130 for (size_t count = 0; count < num4ByteChars; count++)
2132 longString += earthAfrica;
2137 tcu::TestCaseGroup* createOpSourceGroup (tcu::TestContext& testCtx)
2139 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opsource", "Tests the OpSource & OpSourceContinued instruction"));
2140 vector<CaseParameter> cases;
2141 de::Random rnd (deStringHash(group->getName()));
2142 const int numElements = 100;
2143 vector<float> positiveFloats (numElements, 0);
2144 vector<float> negativeFloats (numElements, 0);
2145 const StringTemplate shaderTemplate (
2146 "OpCapability Shader\n"
2147 "OpMemoryModel Logical GLSL450\n"
2149 "OpEntryPoint GLCompute %main \"main\" %id\n"
2150 "OpExecutionMode %main LocalSize 1 1 1\n"
2154 "OpName %main \"main\"\n"
2155 "OpName %id \"gl_GlobalInvocationID\"\n"
2157 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2159 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
2161 "%id = OpVariable %uvec3ptr Input\n"
2162 "%zero = OpConstant %i32 0\n"
2164 "%main = OpFunction %void None %voidf\n"
2165 "%label = OpLabel\n"
2166 "%idval = OpLoad %uvec3 %id\n"
2167 "%x = OpCompositeExtract %u32 %idval 0\n"
2168 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
2169 "%inval = OpLoad %f32 %inloc\n"
2170 "%neg = OpFNegate %f32 %inval\n"
2171 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2172 " OpStore %outloc %neg\n"
2174 " OpFunctionEnd\n");
2176 cases.push_back(CaseParameter("unknown_source", "OpSource Unknown 0"));
2177 cases.push_back(CaseParameter("wrong_source", "OpSource OpenCL_C 210"));
2178 cases.push_back(CaseParameter("normal_filename", "%fname = OpString \"filename\"\n"
2179 "OpSource GLSL 430 %fname"));
2180 cases.push_back(CaseParameter("empty_filename", "%fname = OpString \"\"\n"
2181 "OpSource GLSL 430 %fname"));
2182 cases.push_back(CaseParameter("normal_source_code", "%fname = OpString \"filename\"\n"
2183 "OpSource GLSL 430 %fname \"#version 430\nvoid main() {}\""));
2184 cases.push_back(CaseParameter("empty_source_code", "%fname = OpString \"filename\"\n"
2185 "OpSource GLSL 430 %fname \"\""));
2186 cases.push_back(CaseParameter("long_source_code", "%fname = OpString \"filename\"\n"
2187 "OpSource GLSL 430 %fname \"" + makeLongUTF8String(65530) + "ccc\"")); // word count: 65535
2188 cases.push_back(CaseParameter("utf8_source_code", "%fname = OpString \"filename\"\n"
2189 "OpSource GLSL 430 %fname \"\xE2\x98\x82\xE2\x98\x85\"")); // umbrella & black star symbol
2190 cases.push_back(CaseParameter("normal_sourcecontinued", "%fname = OpString \"filename\"\n"
2191 "OpSource GLSL 430 %fname \"#version 430\nvo\"\n"
2192 "OpSourceContinued \"id main() {}\""));
2193 cases.push_back(CaseParameter("empty_sourcecontinued", "%fname = OpString \"filename\"\n"
2194 "OpSource GLSL 430 %fname \"#version 430\nvoid main() {}\"\n"
2195 "OpSourceContinued \"\""));
2196 cases.push_back(CaseParameter("long_sourcecontinued", "%fname = OpString \"filename\"\n"
2197 "OpSource GLSL 430 %fname \"#version 430\nvoid main() {}\"\n"
2198 "OpSourceContinued \"" + makeLongUTF8String(65533) + "ccc\"")); // word count: 65535
2199 cases.push_back(CaseParameter("utf8_sourcecontinued", "%fname = OpString \"filename\"\n"
2200 "OpSource GLSL 430 %fname \"#version 430\nvoid main() {}\"\n"
2201 "OpSourceContinued \"\xE2\x98\x8E\xE2\x9A\x91\"")); // white telephone & black flag symbol
2202 cases.push_back(CaseParameter("multi_sourcecontinued", "%fname = OpString \"filename\"\n"
2203 "OpSource GLSL 430 %fname \"#version 430\n\"\n"
2204 "OpSourceContinued \"void\"\n"
2205 "OpSourceContinued \"main()\"\n"
2206 "OpSourceContinued \"{}\""));
2207 cases.push_back(CaseParameter("empty_source_before_sourcecontinued", "%fname = OpString \"filename\"\n"
2208 "OpSource GLSL 430 %fname \"\"\n"
2209 "OpSourceContinued \"#version 430\nvoid main() {}\""));
2211 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
2213 for (size_t ndx = 0; ndx < numElements; ++ndx)
2214 negativeFloats[ndx] = -positiveFloats[ndx];
2216 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
2218 map<string, string> specializations;
2219 ComputeShaderSpec spec;
2221 specializations["SOURCE"] = cases[caseNdx].param;
2222 spec.assembly = shaderTemplate.specialize(specializations);
2223 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
2224 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
2225 spec.numWorkGroups = IVec3(numElements, 1, 1);
2227 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
2230 return group.release();
2233 tcu::TestCaseGroup* createOpSourceExtensionGroup (tcu::TestContext& testCtx)
2235 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opsourceextension", "Tests the OpSource instruction"));
2236 vector<CaseParameter> cases;
2237 de::Random rnd (deStringHash(group->getName()));
2238 const int numElements = 100;
2239 vector<float> inputFloats (numElements, 0);
2240 vector<float> outputFloats (numElements, 0);
2241 const StringTemplate shaderTemplate (
2242 string(getComputeAsmShaderPreamble()) +
2244 "OpSourceExtension \"${EXTENSION}\"\n"
2246 "OpName %main \"main\"\n"
2247 "OpName %id \"gl_GlobalInvocationID\"\n"
2249 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2251 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
2253 "%id = OpVariable %uvec3ptr Input\n"
2254 "%zero = OpConstant %i32 0\n"
2256 "%main = OpFunction %void None %voidf\n"
2257 "%label = OpLabel\n"
2258 "%idval = OpLoad %uvec3 %id\n"
2259 "%x = OpCompositeExtract %u32 %idval 0\n"
2260 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
2261 "%inval = OpLoad %f32 %inloc\n"
2262 "%neg = OpFNegate %f32 %inval\n"
2263 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2264 " OpStore %outloc %neg\n"
2266 " OpFunctionEnd\n");
2268 cases.push_back(CaseParameter("empty_extension", ""));
2269 cases.push_back(CaseParameter("real_extension", "GL_ARB_texture_rectangle"));
2270 cases.push_back(CaseParameter("fake_extension", "GL_ARB_im_the_ultimate_extension"));
2271 cases.push_back(CaseParameter("utf8_extension", "GL_ARB_\xE2\x98\x82\xE2\x98\x85"));
2272 cases.push_back(CaseParameter("long_extension", makeLongUTF8String(65533) + "ccc")); // word count: 65535
2274 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats[0], numElements);
2276 for (size_t ndx = 0; ndx < numElements; ++ndx)
2277 outputFloats[ndx] = -inputFloats[ndx];
2279 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
2281 map<string, string> specializations;
2282 ComputeShaderSpec spec;
2284 specializations["EXTENSION"] = cases[caseNdx].param;
2285 spec.assembly = shaderTemplate.specialize(specializations);
2286 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
2287 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
2288 spec.numWorkGroups = IVec3(numElements, 1, 1);
2290 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
2293 return group.release();
2296 // Checks that a compute shader can generate a constant null value of various types, without exercising a computation on it.
2297 tcu::TestCaseGroup* createOpConstantNullGroup (tcu::TestContext& testCtx)
2299 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opconstantnull", "Tests the OpConstantNull instruction"));
2300 vector<CaseParameter> cases;
2301 de::Random rnd (deStringHash(group->getName()));
2302 const int numElements = 100;
2303 vector<float> positiveFloats (numElements, 0);
2304 vector<float> negativeFloats (numElements, 0);
2305 const StringTemplate shaderTemplate (
2306 string(getComputeAsmShaderPreamble()) +
2308 "OpSource GLSL 430\n"
2309 "OpName %main \"main\"\n"
2310 "OpName %id \"gl_GlobalInvocationID\"\n"
2312 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2314 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
2315 "%uvec2 = OpTypeVector %u32 2\n"
2316 "%bvec3 = OpTypeVector %bool 3\n"
2317 "%fvec4 = OpTypeVector %f32 4\n"
2318 "%fmat33 = OpTypeMatrix %fvec3 3\n"
2319 "%const100 = OpConstant %u32 100\n"
2320 "%uarr100 = OpTypeArray %i32 %const100\n"
2321 "%struct = OpTypeStruct %f32 %i32 %u32\n"
2322 "%pointer = OpTypePointer Function %i32\n"
2323 + string(getComputeAsmInputOutputBuffer()) +
2325 "%null = OpConstantNull ${TYPE}\n"
2327 "%id = OpVariable %uvec3ptr Input\n"
2328 "%zero = OpConstant %i32 0\n"
2330 "%main = OpFunction %void None %voidf\n"
2331 "%label = OpLabel\n"
2332 "%idval = OpLoad %uvec3 %id\n"
2333 "%x = OpCompositeExtract %u32 %idval 0\n"
2334 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
2335 "%inval = OpLoad %f32 %inloc\n"
2336 "%neg = OpFNegate %f32 %inval\n"
2337 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2338 " OpStore %outloc %neg\n"
2340 " OpFunctionEnd\n");
2342 cases.push_back(CaseParameter("bool", "%bool"));
2343 cases.push_back(CaseParameter("sint32", "%i32"));
2344 cases.push_back(CaseParameter("uint32", "%u32"));
2345 cases.push_back(CaseParameter("float32", "%f32"));
2346 cases.push_back(CaseParameter("vec4float32", "%fvec4"));
2347 cases.push_back(CaseParameter("vec3bool", "%bvec3"));
2348 cases.push_back(CaseParameter("vec2uint32", "%uvec2"));
2349 cases.push_back(CaseParameter("matrix", "%fmat33"));
2350 cases.push_back(CaseParameter("array", "%uarr100"));
2351 cases.push_back(CaseParameter("struct", "%struct"));
2352 cases.push_back(CaseParameter("pointer", "%pointer"));
2354 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
2356 for (size_t ndx = 0; ndx < numElements; ++ndx)
2357 negativeFloats[ndx] = -positiveFloats[ndx];
2359 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
2361 map<string, string> specializations;
2362 ComputeShaderSpec spec;
2364 specializations["TYPE"] = cases[caseNdx].param;
2365 spec.assembly = shaderTemplate.specialize(specializations);
2366 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
2367 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
2368 spec.numWorkGroups = IVec3(numElements, 1, 1);
2370 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
2373 return group.release();
2376 // Checks that a compute shader can generate a constant composite value of various types, without exercising a computation on it.
2377 tcu::TestCaseGroup* createOpConstantCompositeGroup (tcu::TestContext& testCtx)
2379 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opconstantcomposite", "Tests the OpConstantComposite instruction"));
2380 vector<CaseParameter> cases;
2381 de::Random rnd (deStringHash(group->getName()));
2382 const int numElements = 100;
2383 vector<float> positiveFloats (numElements, 0);
2384 vector<float> negativeFloats (numElements, 0);
2385 const StringTemplate shaderTemplate (
2386 string(getComputeAsmShaderPreamble()) +
2388 "OpSource GLSL 430\n"
2389 "OpName %main \"main\"\n"
2390 "OpName %id \"gl_GlobalInvocationID\"\n"
2392 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2394 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
2396 "%id = OpVariable %uvec3ptr Input\n"
2397 "%zero = OpConstant %i32 0\n"
2401 "%main = OpFunction %void None %voidf\n"
2402 "%label = OpLabel\n"
2403 "%idval = OpLoad %uvec3 %id\n"
2404 "%x = OpCompositeExtract %u32 %idval 0\n"
2405 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
2406 "%inval = OpLoad %f32 %inloc\n"
2407 "%neg = OpFNegate %f32 %inval\n"
2408 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2409 " OpStore %outloc %neg\n"
2411 " OpFunctionEnd\n");
2413 cases.push_back(CaseParameter("vector", "%five = OpConstant %u32 5\n"
2414 "%const = OpConstantComposite %uvec3 %five %zero %five"));
2415 cases.push_back(CaseParameter("matrix", "%m3fvec3 = OpTypeMatrix %fvec3 3\n"
2416 "%ten = OpConstant %f32 10.\n"
2417 "%fzero = OpConstant %f32 0.\n"
2418 "%vec = OpConstantComposite %fvec3 %ten %fzero %ten\n"
2419 "%mat = OpConstantComposite %m3fvec3 %vec %vec %vec"));
2420 cases.push_back(CaseParameter("struct", "%m2vec3 = OpTypeMatrix %fvec3 2\n"
2421 "%struct = OpTypeStruct %i32 %f32 %fvec3 %m2vec3\n"
2422 "%fzero = OpConstant %f32 0.\n"
2423 "%one = OpConstant %f32 1.\n"
2424 "%point5 = OpConstant %f32 0.5\n"
2425 "%vec = OpConstantComposite %fvec3 %one %one %fzero\n"
2426 "%mat = OpConstantComposite %m2vec3 %vec %vec\n"
2427 "%const = OpConstantComposite %struct %zero %point5 %vec %mat"));
2428 cases.push_back(CaseParameter("nested_struct", "%st1 = OpTypeStruct %u32 %f32\n"
2429 "%st2 = OpTypeStruct %i32 %i32\n"
2430 "%struct = OpTypeStruct %st1 %st2\n"
2431 "%point5 = OpConstant %f32 0.5\n"
2432 "%one = OpConstant %u32 1\n"
2433 "%ten = OpConstant %i32 10\n"
2434 "%st1val = OpConstantComposite %st1 %one %point5\n"
2435 "%st2val = OpConstantComposite %st2 %ten %ten\n"
2436 "%const = OpConstantComposite %struct %st1val %st2val"));
2438 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
2440 for (size_t ndx = 0; ndx < numElements; ++ndx)
2441 negativeFloats[ndx] = -positiveFloats[ndx];
2443 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
2445 map<string, string> specializations;
2446 ComputeShaderSpec spec;
2448 specializations["CONSTANT"] = cases[caseNdx].param;
2449 spec.assembly = shaderTemplate.specialize(specializations);
2450 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
2451 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
2452 spec.numWorkGroups = IVec3(numElements, 1, 1);
2454 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
2457 return group.release();
2460 // Creates a floating point number with the given exponent, and significand
2461 // bits set. It can only create normalized numbers. Only the least significant
2462 // 24 bits of the significand will be examined. The final bit of the
2463 // significand will also be ignored. This allows alignment to be written
2464 // similarly to C99 hex-floats.
2465 // For example if you wanted to write 0x1.7f34p-12 you would call
2466 // constructNormalizedFloat(-12, 0x7f3400)
2467 float constructNormalizedFloat (deInt32 exponent, deUint32 significand)
2471 for (deInt32 idx = 0; idx < 23; ++idx)
2473 f += ((significand & 0x800000) == 0) ? 0.f : std::ldexp(1.0f, -(idx + 1));
2477 return std::ldexp(f, exponent);
2480 // Compare instruction for the OpQuantizeF16 compute exact case.
2481 // Returns true if the output is what is expected from the test case.
2482 bool compareOpQuantizeF16ComputeExactCase (const std::vector<BufferSp>&, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs, TestLog&)
2484 if (outputAllocs.size() != 1)
2487 // We really just need this for size because we cannot compare Nans.
2488 const BufferSp& expectedOutput = expectedOutputs[0];
2489 const float* outputAsFloat = static_cast<const float*>(outputAllocs[0]->getHostPtr());;
2491 if (expectedOutput->getNumBytes() != 4*sizeof(float)) {
2495 if (*outputAsFloat != constructNormalizedFloat(8, 0x304000) &&
2496 *outputAsFloat != constructNormalizedFloat(8, 0x300000)) {
2501 if (*outputAsFloat != -constructNormalizedFloat(-7, 0x600000) &&
2502 *outputAsFloat != -constructNormalizedFloat(-7, 0x604000)) {
2507 if (*outputAsFloat != constructNormalizedFloat(2, 0x01C000) &&
2508 *outputAsFloat != constructNormalizedFloat(2, 0x020000)) {
2513 if (*outputAsFloat != constructNormalizedFloat(1, 0xFFC000) &&
2514 *outputAsFloat != constructNormalizedFloat(2, 0x000000)) {
2521 // Checks that every output from a test-case is a float NaN.
2522 bool compareNan (const std::vector<BufferSp>&, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs, TestLog&)
2524 if (outputAllocs.size() != 1)
2527 // We really just need this for size because we cannot compare Nans.
2528 const BufferSp& expectedOutput = expectedOutputs[0];
2529 const float* output_as_float = static_cast<const float*>(outputAllocs[0]->getHostPtr());;
2531 for (size_t idx = 0; idx < expectedOutput->getNumBytes() / sizeof(float); ++idx)
2533 if (!deFloatIsNaN(output_as_float[idx]))
2542 // Checks that a compute shader can generate a constant composite value of various types, without exercising a computation on it.
2543 tcu::TestCaseGroup* createOpQuantizeToF16Group (tcu::TestContext& testCtx)
2545 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opquantize", "Tests the OpQuantizeToF16 instruction"));
2547 const std::string shader (
2548 string(getComputeAsmShaderPreamble()) +
2550 "OpSource GLSL 430\n"
2551 "OpName %main \"main\"\n"
2552 "OpName %id \"gl_GlobalInvocationID\"\n"
2554 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2556 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
2558 "%id = OpVariable %uvec3ptr Input\n"
2559 "%zero = OpConstant %i32 0\n"
2561 "%main = OpFunction %void None %voidf\n"
2562 "%label = OpLabel\n"
2563 "%idval = OpLoad %uvec3 %id\n"
2564 "%x = OpCompositeExtract %u32 %idval 0\n"
2565 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
2566 "%inval = OpLoad %f32 %inloc\n"
2567 "%quant = OpQuantizeToF16 %f32 %inval\n"
2568 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2569 " OpStore %outloc %quant\n"
2571 " OpFunctionEnd\n");
2574 ComputeShaderSpec spec;
2575 const deUint32 numElements = 100;
2576 vector<float> infinities;
2577 vector<float> results;
2579 infinities.reserve(numElements);
2580 results.reserve(numElements);
2582 for (size_t idx = 0; idx < numElements; ++idx)
2587 infinities.push_back(std::numeric_limits<float>::infinity());
2588 results.push_back(std::numeric_limits<float>::infinity());
2591 infinities.push_back(-std::numeric_limits<float>::infinity());
2592 results.push_back(-std::numeric_limits<float>::infinity());
2595 infinities.push_back(std::ldexp(1.0f, 16));
2596 results.push_back(std::numeric_limits<float>::infinity());
2599 infinities.push_back(std::ldexp(-1.0f, 32));
2600 results.push_back(-std::numeric_limits<float>::infinity());
2605 spec.assembly = shader;
2606 spec.inputs.push_back(BufferSp(new Float32Buffer(infinities)));
2607 spec.outputs.push_back(BufferSp(new Float32Buffer(results)));
2608 spec.numWorkGroups = IVec3(numElements, 1, 1);
2610 group->addChild(new SpvAsmComputeShaderCase(
2611 testCtx, "infinities", "Check that infinities propagated and created", spec));
2615 ComputeShaderSpec spec;
2617 const deUint32 numElements = 100;
2619 nans.reserve(numElements);
2621 for (size_t idx = 0; idx < numElements; ++idx)
2625 nans.push_back(std::numeric_limits<float>::quiet_NaN());
2629 nans.push_back(-std::numeric_limits<float>::quiet_NaN());
2633 spec.assembly = shader;
2634 spec.inputs.push_back(BufferSp(new Float32Buffer(nans)));
2635 spec.outputs.push_back(BufferSp(new Float32Buffer(nans)));
2636 spec.numWorkGroups = IVec3(numElements, 1, 1);
2637 spec.verifyIO = &compareNan;
2639 group->addChild(new SpvAsmComputeShaderCase(
2640 testCtx, "propagated_nans", "Check that nans are propagated", spec));
2644 ComputeShaderSpec spec;
2645 vector<float> small;
2646 vector<float> zeros;
2647 const deUint32 numElements = 100;
2649 small.reserve(numElements);
2650 zeros.reserve(numElements);
2652 for (size_t idx = 0; idx < numElements; ++idx)
2657 small.push_back(0.f);
2658 zeros.push_back(0.f);
2661 small.push_back(-0.f);
2662 zeros.push_back(-0.f);
2665 small.push_back(std::ldexp(1.0f, -16));
2666 zeros.push_back(0.f);
2669 small.push_back(std::ldexp(-1.0f, -32));
2670 zeros.push_back(-0.f);
2673 small.push_back(std::ldexp(1.0f, -127));
2674 zeros.push_back(0.f);
2677 small.push_back(-std::ldexp(1.0f, -128));
2678 zeros.push_back(-0.f);
2683 spec.assembly = shader;
2684 spec.inputs.push_back(BufferSp(new Float32Buffer(small)));
2685 spec.outputs.push_back(BufferSp(new Float32Buffer(zeros)));
2686 spec.numWorkGroups = IVec3(numElements, 1, 1);
2688 group->addChild(new SpvAsmComputeShaderCase(
2689 testCtx, "flush_to_zero", "Check that values are zeroed correctly", spec));
2693 ComputeShaderSpec spec;
2694 vector<float> exact;
2695 const deUint32 numElements = 200;
2697 exact.reserve(numElements);
2699 for (size_t idx = 0; idx < numElements; ++idx)
2700 exact.push_back(static_cast<float>(static_cast<int>(idx) - 100));
2702 spec.assembly = shader;
2703 spec.inputs.push_back(BufferSp(new Float32Buffer(exact)));
2704 spec.outputs.push_back(BufferSp(new Float32Buffer(exact)));
2705 spec.numWorkGroups = IVec3(numElements, 1, 1);
2707 group->addChild(new SpvAsmComputeShaderCase(
2708 testCtx, "exact", "Check that values exactly preserved where appropriate", spec));
2712 ComputeShaderSpec spec;
2713 vector<float> inputs;
2714 const deUint32 numElements = 4;
2716 inputs.push_back(constructNormalizedFloat(8, 0x300300));
2717 inputs.push_back(-constructNormalizedFloat(-7, 0x600800));
2718 inputs.push_back(constructNormalizedFloat(2, 0x01E000));
2719 inputs.push_back(constructNormalizedFloat(1, 0xFFE000));
2721 spec.assembly = shader;
2722 spec.verifyIO = &compareOpQuantizeF16ComputeExactCase;
2723 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs)));
2724 spec.outputs.push_back(BufferSp(new Float32Buffer(inputs)));
2725 spec.numWorkGroups = IVec3(numElements, 1, 1);
2727 group->addChild(new SpvAsmComputeShaderCase(
2728 testCtx, "rounded", "Check that are rounded when needed", spec));
2731 return group.release();
2734 tcu::TestCaseGroup* createSpecConstantOpQuantizeToF16Group (tcu::TestContext& testCtx)
2736 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opspecconstantop_opquantize", "Tests the OpQuantizeToF16 opcode for the OpSpecConstantOp instruction"));
2738 const std::string shader (
2739 string(getComputeAsmShaderPreamble()) +
2741 "OpName %main \"main\"\n"
2742 "OpName %id \"gl_GlobalInvocationID\"\n"
2744 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2746 "OpDecorate %sc_0 SpecId 0\n"
2747 "OpDecorate %sc_1 SpecId 1\n"
2748 "OpDecorate %sc_2 SpecId 2\n"
2749 "OpDecorate %sc_3 SpecId 3\n"
2750 "OpDecorate %sc_4 SpecId 4\n"
2751 "OpDecorate %sc_5 SpecId 5\n"
2753 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
2755 "%id = OpVariable %uvec3ptr Input\n"
2756 "%zero = OpConstant %i32 0\n"
2757 "%c_u32_6 = OpConstant %u32 6\n"
2759 "%sc_0 = OpSpecConstant %f32 0.\n"
2760 "%sc_1 = OpSpecConstant %f32 0.\n"
2761 "%sc_2 = OpSpecConstant %f32 0.\n"
2762 "%sc_3 = OpSpecConstant %f32 0.\n"
2763 "%sc_4 = OpSpecConstant %f32 0.\n"
2764 "%sc_5 = OpSpecConstant %f32 0.\n"
2766 "%sc_0_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_0\n"
2767 "%sc_1_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_1\n"
2768 "%sc_2_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_2\n"
2769 "%sc_3_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_3\n"
2770 "%sc_4_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_4\n"
2771 "%sc_5_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_5\n"
2773 "%main = OpFunction %void None %voidf\n"
2774 "%label = OpLabel\n"
2775 "%idval = OpLoad %uvec3 %id\n"
2776 "%x = OpCompositeExtract %u32 %idval 0\n"
2777 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2778 "%selector = OpUMod %u32 %x %c_u32_6\n"
2779 " OpSelectionMerge %exit None\n"
2780 " OpSwitch %selector %exit 0 %case0 1 %case1 2 %case2 3 %case3 4 %case4 5 %case5\n"
2782 "%case0 = OpLabel\n"
2783 " OpStore %outloc %sc_0_quant\n"
2786 "%case1 = OpLabel\n"
2787 " OpStore %outloc %sc_1_quant\n"
2790 "%case2 = OpLabel\n"
2791 " OpStore %outloc %sc_2_quant\n"
2794 "%case3 = OpLabel\n"
2795 " OpStore %outloc %sc_3_quant\n"
2798 "%case4 = OpLabel\n"
2799 " OpStore %outloc %sc_4_quant\n"
2802 "%case5 = OpLabel\n"
2803 " OpStore %outloc %sc_5_quant\n"
2809 " OpFunctionEnd\n");
2812 ComputeShaderSpec spec;
2813 const deUint8 numCases = 4;
2814 vector<float> inputs (numCases, 0.f);
2815 vector<float> outputs;
2817 spec.assembly = shader;
2818 spec.numWorkGroups = IVec3(numCases, 1, 1);
2820 spec.specConstants.push_back(bitwiseCast<deUint32>(std::numeric_limits<float>::infinity()));
2821 spec.specConstants.push_back(bitwiseCast<deUint32>(-std::numeric_limits<float>::infinity()));
2822 spec.specConstants.push_back(bitwiseCast<deUint32>(std::ldexp(1.0f, 16)));
2823 spec.specConstants.push_back(bitwiseCast<deUint32>(std::ldexp(-1.0f, 32)));
2825 outputs.push_back(std::numeric_limits<float>::infinity());
2826 outputs.push_back(-std::numeric_limits<float>::infinity());
2827 outputs.push_back(std::numeric_limits<float>::infinity());
2828 outputs.push_back(-std::numeric_limits<float>::infinity());
2830 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs)));
2831 spec.outputs.push_back(BufferSp(new Float32Buffer(outputs)));
2833 group->addChild(new SpvAsmComputeShaderCase(
2834 testCtx, "infinities", "Check that infinities propagated and created", spec));
2838 ComputeShaderSpec spec;
2839 const deUint8 numCases = 2;
2840 vector<float> inputs (numCases, 0.f);
2841 vector<float> outputs;
2843 spec.assembly = shader;
2844 spec.numWorkGroups = IVec3(numCases, 1, 1);
2845 spec.verifyIO = &compareNan;
2847 outputs.push_back(std::numeric_limits<float>::quiet_NaN());
2848 outputs.push_back(-std::numeric_limits<float>::quiet_NaN());
2850 for (deUint8 idx = 0; idx < numCases; ++idx)
2851 spec.specConstants.push_back(bitwiseCast<deUint32>(outputs[idx]));
2853 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs)));
2854 spec.outputs.push_back(BufferSp(new Float32Buffer(outputs)));
2856 group->addChild(new SpvAsmComputeShaderCase(
2857 testCtx, "propagated_nans", "Check that nans are propagated", spec));
2861 ComputeShaderSpec spec;
2862 const deUint8 numCases = 6;
2863 vector<float> inputs (numCases, 0.f);
2864 vector<float> outputs;
2866 spec.assembly = shader;
2867 spec.numWorkGroups = IVec3(numCases, 1, 1);
2869 spec.specConstants.push_back(bitwiseCast<deUint32>(0.f));
2870 spec.specConstants.push_back(bitwiseCast<deUint32>(-0.f));
2871 spec.specConstants.push_back(bitwiseCast<deUint32>(std::ldexp(1.0f, -16)));
2872 spec.specConstants.push_back(bitwiseCast<deUint32>(std::ldexp(-1.0f, -32)));
2873 spec.specConstants.push_back(bitwiseCast<deUint32>(std::ldexp(1.0f, -127)));
2874 spec.specConstants.push_back(bitwiseCast<deUint32>(-std::ldexp(1.0f, -128)));
2876 outputs.push_back(0.f);
2877 outputs.push_back(-0.f);
2878 outputs.push_back(0.f);
2879 outputs.push_back(-0.f);
2880 outputs.push_back(0.f);
2881 outputs.push_back(-0.f);
2883 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs)));
2884 spec.outputs.push_back(BufferSp(new Float32Buffer(outputs)));
2886 group->addChild(new SpvAsmComputeShaderCase(
2887 testCtx, "flush_to_zero", "Check that values are zeroed correctly", spec));
2891 ComputeShaderSpec spec;
2892 const deUint8 numCases = 6;
2893 vector<float> inputs (numCases, 0.f);
2894 vector<float> outputs;
2896 spec.assembly = shader;
2897 spec.numWorkGroups = IVec3(numCases, 1, 1);
2899 for (deUint8 idx = 0; idx < 6; ++idx)
2901 const float f = static_cast<float>(idx * 10 - 30) / 4.f;
2902 spec.specConstants.push_back(bitwiseCast<deUint32>(f));
2903 outputs.push_back(f);
2906 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs)));
2907 spec.outputs.push_back(BufferSp(new Float32Buffer(outputs)));
2909 group->addChild(new SpvAsmComputeShaderCase(
2910 testCtx, "exact", "Check that values exactly preserved where appropriate", spec));
2914 ComputeShaderSpec spec;
2915 const deUint8 numCases = 4;
2916 vector<float> inputs (numCases, 0.f);
2917 vector<float> outputs;
2919 spec.assembly = shader;
2920 spec.numWorkGroups = IVec3(numCases, 1, 1);
2921 spec.verifyIO = &compareOpQuantizeF16ComputeExactCase;
2923 outputs.push_back(constructNormalizedFloat(8, 0x300300));
2924 outputs.push_back(-constructNormalizedFloat(-7, 0x600800));
2925 outputs.push_back(constructNormalizedFloat(2, 0x01E000));
2926 outputs.push_back(constructNormalizedFloat(1, 0xFFE000));
2928 for (deUint8 idx = 0; idx < numCases; ++idx)
2929 spec.specConstants.push_back(bitwiseCast<deUint32>(outputs[idx]));
2931 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs)));
2932 spec.outputs.push_back(BufferSp(new Float32Buffer(outputs)));
2934 group->addChild(new SpvAsmComputeShaderCase(
2935 testCtx, "rounded", "Check that are rounded when needed", spec));
2938 return group.release();
2941 // Checks that constant null/composite values can be used in computation.
2942 tcu::TestCaseGroup* createOpConstantUsageGroup (tcu::TestContext& testCtx)
2944 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opconstantnullcomposite", "Spotcheck the OpConstantNull & OpConstantComposite instruction"));
2945 ComputeShaderSpec spec;
2946 de::Random rnd (deStringHash(group->getName()));
2947 const int numElements = 100;
2948 vector<float> positiveFloats (numElements, 0);
2949 vector<float> negativeFloats (numElements, 0);
2951 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
2953 for (size_t ndx = 0; ndx < numElements; ++ndx)
2954 negativeFloats[ndx] = -positiveFloats[ndx];
2957 "OpCapability Shader\n"
2958 "%std450 = OpExtInstImport \"GLSL.std.450\"\n"
2959 "OpMemoryModel Logical GLSL450\n"
2960 "OpEntryPoint GLCompute %main \"main\" %id\n"
2961 "OpExecutionMode %main LocalSize 1 1 1\n"
2963 "OpSource GLSL 430\n"
2964 "OpName %main \"main\"\n"
2965 "OpName %id \"gl_GlobalInvocationID\"\n"
2967 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2969 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
2971 "%fmat = OpTypeMatrix %fvec3 3\n"
2972 "%ten = OpConstant %u32 10\n"
2973 "%f32arr10 = OpTypeArray %f32 %ten\n"
2974 "%fst = OpTypeStruct %f32 %f32\n"
2976 + string(getComputeAsmInputOutputBuffer()) +
2978 "%id = OpVariable %uvec3ptr Input\n"
2979 "%zero = OpConstant %i32 0\n"
2981 // Create a bunch of null values
2982 "%unull = OpConstantNull %u32\n"
2983 "%fnull = OpConstantNull %f32\n"
2984 "%vnull = OpConstantNull %fvec3\n"
2985 "%mnull = OpConstantNull %fmat\n"
2986 "%anull = OpConstantNull %f32arr10\n"
2987 "%snull = OpConstantComposite %fst %fnull %fnull\n"
2989 "%main = OpFunction %void None %voidf\n"
2990 "%label = OpLabel\n"
2991 "%idval = OpLoad %uvec3 %id\n"
2992 "%x = OpCompositeExtract %u32 %idval 0\n"
2993 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
2994 "%inval = OpLoad %f32 %inloc\n"
2995 "%neg = OpFNegate %f32 %inval\n"
2997 // Get the abs() of (a certain element of) those null values
2998 "%unull_cov = OpConvertUToF %f32 %unull\n"
2999 "%unull_abs = OpExtInst %f32 %std450 FAbs %unull_cov\n"
3000 "%fnull_abs = OpExtInst %f32 %std450 FAbs %fnull\n"
3001 "%vnull_0 = OpCompositeExtract %f32 %vnull 0\n"
3002 "%vnull_abs = OpExtInst %f32 %std450 FAbs %vnull_0\n"
3003 "%mnull_12 = OpCompositeExtract %f32 %mnull 1 2\n"
3004 "%mnull_abs = OpExtInst %f32 %std450 FAbs %mnull_12\n"
3005 "%anull_3 = OpCompositeExtract %f32 %anull 3\n"
3006 "%anull_abs = OpExtInst %f32 %std450 FAbs %anull_3\n"
3007 "%snull_1 = OpCompositeExtract %f32 %snull 1\n"
3008 "%snull_abs = OpExtInst %f32 %std450 FAbs %snull_1\n"
3011 "%add1 = OpFAdd %f32 %neg %unull_abs\n"
3012 "%add2 = OpFAdd %f32 %add1 %fnull_abs\n"
3013 "%add3 = OpFAdd %f32 %add2 %vnull_abs\n"
3014 "%add4 = OpFAdd %f32 %add3 %mnull_abs\n"
3015 "%add5 = OpFAdd %f32 %add4 %anull_abs\n"
3016 "%final = OpFAdd %f32 %add5 %snull_abs\n"
3018 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3019 " OpStore %outloc %final\n" // write to output
3022 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
3023 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
3024 spec.numWorkGroups = IVec3(numElements, 1, 1);
3026 group->addChild(new SpvAsmComputeShaderCase(testCtx, "spotcheck", "Check that values constructed via OpConstantNull & OpConstantComposite can be used", spec));
3028 return group.release();
3031 // Assembly code used for testing loop control is based on GLSL source code:
3034 // layout(std140, set = 0, binding = 0) readonly buffer Input {
3035 // float elements[];
3037 // layout(std140, set = 0, binding = 1) writeonly buffer Output {
3038 // float elements[];
3042 // uint x = gl_GlobalInvocationID.x;
3043 // output_data.elements[x] = input_data.elements[x];
3044 // for (uint i = 0; i < 4; ++i)
3045 // output_data.elements[x] += 1.f;
3047 tcu::TestCaseGroup* createLoopControlGroup (tcu::TestContext& testCtx)
3049 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "loop_control", "Tests loop control cases"));
3050 vector<CaseParameter> cases;
3051 de::Random rnd (deStringHash(group->getName()));
3052 const int numElements = 100;
3053 vector<float> inputFloats (numElements, 0);
3054 vector<float> outputFloats (numElements, 0);
3055 const StringTemplate shaderTemplate (
3056 string(getComputeAsmShaderPreamble()) +
3058 "OpSource GLSL 430\n"
3059 "OpName %main \"main\"\n"
3060 "OpName %id \"gl_GlobalInvocationID\"\n"
3062 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3064 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
3066 "%u32ptr = OpTypePointer Function %u32\n"
3068 "%id = OpVariable %uvec3ptr Input\n"
3069 "%zero = OpConstant %i32 0\n"
3070 "%uzero = OpConstant %u32 0\n"
3071 "%one = OpConstant %i32 1\n"
3072 "%constf1 = OpConstant %f32 1.0\n"
3073 "%four = OpConstant %u32 4\n"
3075 "%main = OpFunction %void None %voidf\n"
3076 "%entry = OpLabel\n"
3077 "%i = OpVariable %u32ptr Function\n"
3078 " OpStore %i %uzero\n"
3080 "%idval = OpLoad %uvec3 %id\n"
3081 "%x = OpCompositeExtract %u32 %idval 0\n"
3082 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3083 "%inval = OpLoad %f32 %inloc\n"
3084 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3085 " OpStore %outloc %inval\n"
3086 " OpBranch %loop_entry\n"
3088 "%loop_entry = OpLabel\n"
3089 "%i_val = OpLoad %u32 %i\n"
3090 "%cmp_lt = OpULessThan %bool %i_val %four\n"
3091 " OpLoopMerge %loop_merge %loop_body ${CONTROL}\n"
3092 " OpBranchConditional %cmp_lt %loop_body %loop_merge\n"
3093 "%loop_body = OpLabel\n"
3094 "%outval = OpLoad %f32 %outloc\n"
3095 "%addf1 = OpFAdd %f32 %outval %constf1\n"
3096 " OpStore %outloc %addf1\n"
3097 "%new_i = OpIAdd %u32 %i_val %one\n"
3098 " OpStore %i %new_i\n"
3099 " OpBranch %loop_entry\n"
3100 "%loop_merge = OpLabel\n"
3102 " OpFunctionEnd\n");
3104 cases.push_back(CaseParameter("none", "None"));
3105 cases.push_back(CaseParameter("unroll", "Unroll"));
3106 cases.push_back(CaseParameter("dont_unroll", "DontUnroll"));
3107 cases.push_back(CaseParameter("unroll_dont_unroll", "Unroll|DontUnroll"));
3109 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats[0], numElements);
3111 for (size_t ndx = 0; ndx < numElements; ++ndx)
3112 outputFloats[ndx] = inputFloats[ndx] + 4.f;
3114 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
3116 map<string, string> specializations;
3117 ComputeShaderSpec spec;
3119 specializations["CONTROL"] = cases[caseNdx].param;
3120 spec.assembly = shaderTemplate.specialize(specializations);
3121 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
3122 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
3123 spec.numWorkGroups = IVec3(numElements, 1, 1);
3125 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
3128 return group.release();
3131 // Assembly code used for testing selection control is based on GLSL source code:
3134 // layout(std140, set = 0, binding = 0) readonly buffer Input {
3135 // float elements[];
3137 // layout(std140, set = 0, binding = 1) writeonly buffer Output {
3138 // float elements[];
3142 // uint x = gl_GlobalInvocationID.x;
3143 // float val = input_data.elements[x];
3145 // output_data.elements[x] = val + 1.f;
3147 // output_data.elements[x] = val - 1.f;
3149 tcu::TestCaseGroup* createSelectionControlGroup (tcu::TestContext& testCtx)
3151 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "selection_control", "Tests selection control cases"));
3152 vector<CaseParameter> cases;
3153 de::Random rnd (deStringHash(group->getName()));
3154 const int numElements = 100;
3155 vector<float> inputFloats (numElements, 0);
3156 vector<float> outputFloats (numElements, 0);
3157 const StringTemplate shaderTemplate (
3158 string(getComputeAsmShaderPreamble()) +
3160 "OpSource GLSL 430\n"
3161 "OpName %main \"main\"\n"
3162 "OpName %id \"gl_GlobalInvocationID\"\n"
3164 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3166 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
3168 "%id = OpVariable %uvec3ptr Input\n"
3169 "%zero = OpConstant %i32 0\n"
3170 "%constf1 = OpConstant %f32 1.0\n"
3171 "%constf10 = OpConstant %f32 10.0\n"
3173 "%main = OpFunction %void None %voidf\n"
3174 "%entry = OpLabel\n"
3175 "%idval = OpLoad %uvec3 %id\n"
3176 "%x = OpCompositeExtract %u32 %idval 0\n"
3177 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3178 "%inval = OpLoad %f32 %inloc\n"
3179 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3180 "%cmp_gt = OpFOrdGreaterThan %bool %inval %constf10\n"
3182 " OpSelectionMerge %if_end ${CONTROL}\n"
3183 " OpBranchConditional %cmp_gt %if_true %if_false\n"
3184 "%if_true = OpLabel\n"
3185 "%addf1 = OpFAdd %f32 %inval %constf1\n"
3186 " OpStore %outloc %addf1\n"
3187 " OpBranch %if_end\n"
3188 "%if_false = OpLabel\n"
3189 "%subf1 = OpFSub %f32 %inval %constf1\n"
3190 " OpStore %outloc %subf1\n"
3191 " OpBranch %if_end\n"
3192 "%if_end = OpLabel\n"
3194 " OpFunctionEnd\n");
3196 cases.push_back(CaseParameter("none", "None"));
3197 cases.push_back(CaseParameter("flatten", "Flatten"));
3198 cases.push_back(CaseParameter("dont_flatten", "DontFlatten"));
3199 cases.push_back(CaseParameter("flatten_dont_flatten", "DontFlatten|Flatten"));
3201 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats[0], numElements);
3203 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
3204 floorAll(inputFloats);
3206 for (size_t ndx = 0; ndx < numElements; ++ndx)
3207 outputFloats[ndx] = inputFloats[ndx] + (inputFloats[ndx] > 10.f ? 1.f : -1.f);
3209 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
3211 map<string, string> specializations;
3212 ComputeShaderSpec spec;
3214 specializations["CONTROL"] = cases[caseNdx].param;
3215 spec.assembly = shaderTemplate.specialize(specializations);
3216 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
3217 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
3218 spec.numWorkGroups = IVec3(numElements, 1, 1);
3220 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
3223 return group.release();
3226 // Assembly code used for testing function control is based on GLSL source code:
3230 // layout(std140, set = 0, binding = 0) readonly buffer Input {
3231 // float elements[];
3233 // layout(std140, set = 0, binding = 1) writeonly buffer Output {
3234 // float elements[];
3237 // float const10() { return 10.f; }
3240 // uint x = gl_GlobalInvocationID.x;
3241 // output_data.elements[x] = input_data.elements[x] + const10();
3243 tcu::TestCaseGroup* createFunctionControlGroup (tcu::TestContext& testCtx)
3245 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "function_control", "Tests function control cases"));
3246 vector<CaseParameter> cases;
3247 de::Random rnd (deStringHash(group->getName()));
3248 const int numElements = 100;
3249 vector<float> inputFloats (numElements, 0);
3250 vector<float> outputFloats (numElements, 0);
3251 const StringTemplate shaderTemplate (
3252 string(getComputeAsmShaderPreamble()) +
3254 "OpSource GLSL 430\n"
3255 "OpName %main \"main\"\n"
3256 "OpName %func_const10 \"const10(\"\n"
3257 "OpName %id \"gl_GlobalInvocationID\"\n"
3259 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3261 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
3263 "%f32f = OpTypeFunction %f32\n"
3264 "%id = OpVariable %uvec3ptr Input\n"
3265 "%zero = OpConstant %i32 0\n"
3266 "%constf10 = OpConstant %f32 10.0\n"
3268 "%main = OpFunction %void None %voidf\n"
3269 "%entry = OpLabel\n"
3270 "%idval = OpLoad %uvec3 %id\n"
3271 "%x = OpCompositeExtract %u32 %idval 0\n"
3272 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3273 "%inval = OpLoad %f32 %inloc\n"
3274 "%ret_10 = OpFunctionCall %f32 %func_const10\n"
3275 "%fadd = OpFAdd %f32 %inval %ret_10\n"
3276 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3277 " OpStore %outloc %fadd\n"
3281 "%func_const10 = OpFunction %f32 ${CONTROL} %f32f\n"
3282 "%label = OpLabel\n"
3283 " OpReturnValue %constf10\n"
3284 " OpFunctionEnd\n");
3286 cases.push_back(CaseParameter("none", "None"));
3287 cases.push_back(CaseParameter("inline", "Inline"));
3288 cases.push_back(CaseParameter("dont_inline", "DontInline"));
3289 cases.push_back(CaseParameter("pure", "Pure"));
3290 cases.push_back(CaseParameter("const", "Const"));
3291 cases.push_back(CaseParameter("inline_pure", "Inline|Pure"));
3292 cases.push_back(CaseParameter("const_dont_inline", "Const|DontInline"));
3293 cases.push_back(CaseParameter("inline_dont_inline", "Inline|DontInline"));
3294 cases.push_back(CaseParameter("pure_inline_dont_inline", "Pure|Inline|DontInline"));
3296 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats[0], numElements);
3298 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
3299 floorAll(inputFloats);
3301 for (size_t ndx = 0; ndx < numElements; ++ndx)
3302 outputFloats[ndx] = inputFloats[ndx] + 10.f;
3304 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
3306 map<string, string> specializations;
3307 ComputeShaderSpec spec;
3309 specializations["CONTROL"] = cases[caseNdx].param;
3310 spec.assembly = shaderTemplate.specialize(specializations);
3311 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
3312 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
3313 spec.numWorkGroups = IVec3(numElements, 1, 1);
3315 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
3318 return group.release();
3321 tcu::TestCaseGroup* createMemoryAccessGroup (tcu::TestContext& testCtx)
3323 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "memory_access", "Tests memory access cases"));
3324 vector<CaseParameter> cases;
3325 de::Random rnd (deStringHash(group->getName()));
3326 const int numElements = 100;
3327 vector<float> inputFloats (numElements, 0);
3328 vector<float> outputFloats (numElements, 0);
3329 const StringTemplate shaderTemplate (
3330 string(getComputeAsmShaderPreamble()) +
3332 "OpSource GLSL 430\n"
3333 "OpName %main \"main\"\n"
3334 "OpName %id \"gl_GlobalInvocationID\"\n"
3336 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3338 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
3340 "%f32ptr_f = OpTypePointer Function %f32\n"
3342 "%id = OpVariable %uvec3ptr Input\n"
3343 "%zero = OpConstant %i32 0\n"
3344 "%four = OpConstant %i32 4\n"
3346 "%main = OpFunction %void None %voidf\n"
3347 "%label = OpLabel\n"
3348 "%copy = OpVariable %f32ptr_f Function\n"
3349 "%idval = OpLoad %uvec3 %id ${ACCESS}\n"
3350 "%x = OpCompositeExtract %u32 %idval 0\n"
3351 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3352 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3353 " OpCopyMemory %copy %inloc ${ACCESS}\n"
3354 "%val1 = OpLoad %f32 %copy\n"
3355 "%val2 = OpLoad %f32 %inloc\n"
3356 "%add = OpFAdd %f32 %val1 %val2\n"
3357 " OpStore %outloc %add ${ACCESS}\n"
3359 " OpFunctionEnd\n");
3361 cases.push_back(CaseParameter("null", ""));
3362 cases.push_back(CaseParameter("none", "None"));
3363 cases.push_back(CaseParameter("volatile", "Volatile"));
3364 cases.push_back(CaseParameter("aligned", "Aligned 4"));
3365 cases.push_back(CaseParameter("nontemporal", "Nontemporal"));
3366 cases.push_back(CaseParameter("aligned_nontemporal", "Aligned|Nontemporal 4"));
3367 cases.push_back(CaseParameter("aligned_volatile", "Volatile|Aligned 4"));
3369 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats[0], numElements);
3371 for (size_t ndx = 0; ndx < numElements; ++ndx)
3372 outputFloats[ndx] = inputFloats[ndx] + inputFloats[ndx];
3374 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
3376 map<string, string> specializations;
3377 ComputeShaderSpec spec;
3379 specializations["ACCESS"] = cases[caseNdx].param;
3380 spec.assembly = shaderTemplate.specialize(specializations);
3381 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
3382 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
3383 spec.numWorkGroups = IVec3(numElements, 1, 1);
3385 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
3388 return group.release();
3391 // Checks that we can get undefined values for various types, without exercising a computation with it.
3392 tcu::TestCaseGroup* createOpUndefGroup (tcu::TestContext& testCtx)
3394 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opundef", "Tests the OpUndef instruction"));
3395 vector<CaseParameter> cases;
3396 de::Random rnd (deStringHash(group->getName()));
3397 const int numElements = 100;
3398 vector<float> positiveFloats (numElements, 0);
3399 vector<float> negativeFloats (numElements, 0);
3400 const StringTemplate shaderTemplate (
3401 string(getComputeAsmShaderPreamble()) +
3403 "OpSource GLSL 430\n"
3404 "OpName %main \"main\"\n"
3405 "OpName %id \"gl_GlobalInvocationID\"\n"
3407 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3409 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
3410 "%uvec2 = OpTypeVector %u32 2\n"
3411 "%fvec4 = OpTypeVector %f32 4\n"
3412 "%fmat33 = OpTypeMatrix %fvec3 3\n"
3413 "%image = OpTypeImage %f32 2D 0 0 0 1 Unknown\n"
3414 "%sampler = OpTypeSampler\n"
3415 "%simage = OpTypeSampledImage %image\n"
3416 "%const100 = OpConstant %u32 100\n"
3417 "%uarr100 = OpTypeArray %i32 %const100\n"
3418 "%struct = OpTypeStruct %f32 %i32 %u32\n"
3419 "%pointer = OpTypePointer Function %i32\n"
3420 + string(getComputeAsmInputOutputBuffer()) +
3422 "%id = OpVariable %uvec3ptr Input\n"
3423 "%zero = OpConstant %i32 0\n"
3425 "%main = OpFunction %void None %voidf\n"
3426 "%label = OpLabel\n"
3428 "%undef = OpUndef ${TYPE}\n"
3430 "%idval = OpLoad %uvec3 %id\n"
3431 "%x = OpCompositeExtract %u32 %idval 0\n"
3433 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3434 "%inval = OpLoad %f32 %inloc\n"
3435 "%neg = OpFNegate %f32 %inval\n"
3436 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3437 " OpStore %outloc %neg\n"
3439 " OpFunctionEnd\n");
3441 cases.push_back(CaseParameter("bool", "%bool"));
3442 cases.push_back(CaseParameter("sint32", "%i32"));
3443 cases.push_back(CaseParameter("uint32", "%u32"));
3444 cases.push_back(CaseParameter("float32", "%f32"));
3445 cases.push_back(CaseParameter("vec4float32", "%fvec4"));
3446 cases.push_back(CaseParameter("vec2uint32", "%uvec2"));
3447 cases.push_back(CaseParameter("matrix", "%fmat33"));
3448 cases.push_back(CaseParameter("image", "%image"));
3449 cases.push_back(CaseParameter("sampler", "%sampler"));
3450 cases.push_back(CaseParameter("sampledimage", "%simage"));
3451 cases.push_back(CaseParameter("array", "%uarr100"));
3452 cases.push_back(CaseParameter("runtimearray", "%f32arr"));
3453 cases.push_back(CaseParameter("struct", "%struct"));
3454 cases.push_back(CaseParameter("pointer", "%pointer"));
3456 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
3458 for (size_t ndx = 0; ndx < numElements; ++ndx)
3459 negativeFloats[ndx] = -positiveFloats[ndx];
3461 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
3463 map<string, string> specializations;
3464 ComputeShaderSpec spec;
3466 specializations["TYPE"] = cases[caseNdx].param;
3467 spec.assembly = shaderTemplate.specialize(specializations);
3468 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
3469 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
3470 spec.numWorkGroups = IVec3(numElements, 1, 1);
3472 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
3475 return group.release();
3479 tcu::TestCaseGroup* createOpSourceTests (tcu::TestContext& testCtx)
3481 struct NameCodePair { string name, code; };
3482 RGBA defaultColors[4];
3483 de::MovePtr<tcu::TestCaseGroup> opSourceTests (new tcu::TestCaseGroup(testCtx, "opsource", "OpSource instruction"));
3484 const std::string opsourceGLSLWithFile = "%opsrcfile = OpString \"foo.vert\"\nOpSource GLSL 450 %opsrcfile ";
3485 map<string, string> fragments = passthruFragments();
3486 const NameCodePair tests[] =
3488 {"unknown", "OpSource Unknown 321"},
3489 {"essl", "OpSource ESSL 310"},
3490 {"glsl", "OpSource GLSL 450"},
3491 {"opencl_cpp", "OpSource OpenCL_CPP 120"},
3492 {"opencl_c", "OpSource OpenCL_C 120"},
3493 {"multiple", "OpSource GLSL 450\nOpSource GLSL 450"},
3494 {"file", opsourceGLSLWithFile},
3495 {"source", opsourceGLSLWithFile + "\"void main(){}\""},
3496 // Longest possible source string: SPIR-V limits instructions to 65535
3497 // words, of which the first 4 are opsourceGLSLWithFile; the rest will
3498 // contain 65530 UTF8 characters (one word each) plus one last word
3499 // containing 3 ASCII characters and \0.
3500 {"longsource", opsourceGLSLWithFile + '"' + makeLongUTF8String(65530) + "ccc" + '"'}
3503 getDefaultColors(defaultColors);
3504 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameCodePair); ++testNdx)
3506 fragments["debug"] = tests[testNdx].code;
3507 createTestsForAllStages(tests[testNdx].name, defaultColors, defaultColors, fragments, opSourceTests.get());
3510 return opSourceTests.release();
3513 tcu::TestCaseGroup* createOpSourceContinuedTests (tcu::TestContext& testCtx)
3515 struct NameCodePair { string name, code; };
3516 RGBA defaultColors[4];
3517 de::MovePtr<tcu::TestCaseGroup> opSourceTests (new tcu::TestCaseGroup(testCtx, "opsourcecontinued", "OpSourceContinued instruction"));
3518 map<string, string> fragments = passthruFragments();
3519 const std::string opsource = "%opsrcfile = OpString \"foo.vert\"\nOpSource GLSL 450 %opsrcfile \"void main(){}\"\n";
3520 const NameCodePair tests[] =
3522 {"empty", opsource + "OpSourceContinued \"\""},
3523 {"short", opsource + "OpSourceContinued \"abcde\""},
3524 {"multiple", opsource + "OpSourceContinued \"abcde\"\nOpSourceContinued \"fghij\""},
3525 // Longest possible source string: SPIR-V limits instructions to 65535
3526 // words, of which the first one is OpSourceContinued/length; the rest
3527 // will contain 65533 UTF8 characters (one word each) plus one last word
3528 // containing 3 ASCII characters and \0.
3529 {"long", opsource + "OpSourceContinued \"" + makeLongUTF8String(65533) + "ccc\""}
3532 getDefaultColors(defaultColors);
3533 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameCodePair); ++testNdx)
3535 fragments["debug"] = tests[testNdx].code;
3536 createTestsForAllStages(tests[testNdx].name, defaultColors, defaultColors, fragments, opSourceTests.get());
3539 return opSourceTests.release();
3542 tcu::TestCaseGroup* createOpNoLineTests(tcu::TestContext& testCtx)
3544 RGBA defaultColors[4];
3545 de::MovePtr<tcu::TestCaseGroup> opLineTests (new tcu::TestCaseGroup(testCtx, "opnoline", "OpNoLine instruction"));
3546 map<string, string> fragments;
3547 getDefaultColors(defaultColors);
3548 fragments["debug"] =
3549 "%name = OpString \"name\"\n";
3551 fragments["pre_main"] =
3554 "OpLine %name 1 1\n"
3556 "OpLine %name 1 1\n"
3557 "OpLine %name 1 1\n"
3558 "%second_function = OpFunction %v4f32 None %v4f32_function\n"
3560 "OpLine %name 1 1\n"
3562 "OpLine %name 1 1\n"
3563 "OpLine %name 1 1\n"
3564 "%second_param1 = OpFunctionParameter %v4f32\n"
3567 "%label_secondfunction = OpLabel\n"
3569 "OpReturnValue %second_param1\n"
3574 fragments["testfun"] =
3575 // A %test_code function that returns its argument unchanged.
3578 "OpLine %name 1 1\n"
3579 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
3581 "%param1 = OpFunctionParameter %v4f32\n"
3584 "%label_testfun = OpLabel\n"
3586 "%val1 = OpFunctionCall %v4f32 %second_function %param1\n"
3587 "OpReturnValue %val1\n"
3589 "OpLine %name 1 1\n"
3592 createTestsForAllStages("opnoline", defaultColors, defaultColors, fragments, opLineTests.get());
3594 return opLineTests.release();
3598 tcu::TestCaseGroup* createOpLineTests(tcu::TestContext& testCtx)
3600 RGBA defaultColors[4];
3601 de::MovePtr<tcu::TestCaseGroup> opLineTests (new tcu::TestCaseGroup(testCtx, "opline", "OpLine instruction"));
3602 map<string, string> fragments;
3603 std::vector<std::pair<std::string, std::string> > problemStrings;
3605 problemStrings.push_back(std::make_pair<std::string, std::string>("empty_name", ""));
3606 problemStrings.push_back(std::make_pair<std::string, std::string>("short_name", "short_name"));
3607 problemStrings.push_back(std::make_pair<std::string, std::string>("long_name", makeLongUTF8String(65530) + "ccc"));
3608 getDefaultColors(defaultColors);
3610 fragments["debug"] =
3611 "%other_name = OpString \"other_name\"\n";
3613 fragments["pre_main"] =
3614 "OpLine %file_name 32 0\n"
3615 "OpLine %file_name 32 32\n"
3616 "OpLine %file_name 32 40\n"
3617 "OpLine %other_name 32 40\n"
3618 "OpLine %other_name 0 100\n"
3619 "OpLine %other_name 0 4294967295\n"
3620 "OpLine %other_name 4294967295 0\n"
3621 "OpLine %other_name 32 40\n"
3622 "OpLine %file_name 0 0\n"
3623 "%second_function = OpFunction %v4f32 None %v4f32_function\n"
3624 "OpLine %file_name 1 0\n"
3625 "%second_param1 = OpFunctionParameter %v4f32\n"
3626 "OpLine %file_name 1 3\n"
3627 "OpLine %file_name 1 2\n"
3628 "%label_secondfunction = OpLabel\n"
3629 "OpLine %file_name 0 2\n"
3630 "OpReturnValue %second_param1\n"
3632 "OpLine %file_name 0 2\n"
3633 "OpLine %file_name 0 2\n";
3635 fragments["testfun"] =
3636 // A %test_code function that returns its argument unchanged.
3637 "OpLine %file_name 1 0\n"
3638 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
3639 "OpLine %file_name 16 330\n"
3640 "%param1 = OpFunctionParameter %v4f32\n"
3641 "OpLine %file_name 14 442\n"
3642 "%label_testfun = OpLabel\n"
3643 "OpLine %file_name 11 1024\n"
3644 "%val1 = OpFunctionCall %v4f32 %second_function %param1\n"
3645 "OpLine %file_name 2 97\n"
3646 "OpReturnValue %val1\n"
3648 "OpLine %file_name 5 32\n";
3650 for (size_t i = 0; i < problemStrings.size(); ++i)
3652 map<string, string> testFragments = fragments;
3653 testFragments["debug"] += "%file_name = OpString \"" + problemStrings[i].second + "\"\n";
3654 createTestsForAllStages(string("opline") + "_" + problemStrings[i].first, defaultColors, defaultColors, testFragments, opLineTests.get());
3657 return opLineTests.release();
3660 tcu::TestCaseGroup* createOpConstantNullTests(tcu::TestContext& testCtx)
3662 de::MovePtr<tcu::TestCaseGroup> opConstantNullTests (new tcu::TestCaseGroup(testCtx, "opconstantnull", "OpConstantNull instruction"));
3666 const char functionStart[] =
3667 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
3668 "%param1 = OpFunctionParameter %v4f32\n"
3671 const char functionEnd[] =
3672 "OpReturnValue %transformed_param\n"
3675 struct NameConstantsCode
3682 NameConstantsCode tests[] =
3686 "%cnull = OpConstantNull %v4f32\n",
3687 "%transformed_param = OpFAdd %v4f32 %param1 %cnull\n"
3691 "%cnull = OpConstantNull %f32\n",
3692 "%vp = OpVariable %fp_v4f32 Function\n"
3693 "%v = OpLoad %v4f32 %vp\n"
3694 "%v0 = OpVectorInsertDynamic %v4f32 %v %cnull %c_i32_0\n"
3695 "%v1 = OpVectorInsertDynamic %v4f32 %v0 %cnull %c_i32_1\n"
3696 "%v2 = OpVectorInsertDynamic %v4f32 %v1 %cnull %c_i32_2\n"
3697 "%v3 = OpVectorInsertDynamic %v4f32 %v2 %cnull %c_i32_3\n"
3698 "%transformed_param = OpFAdd %v4f32 %param1 %v3\n"
3702 "%cnull = OpConstantNull %bool\n",
3703 "%v = OpVariable %fp_v4f32 Function\n"
3704 " OpStore %v %param1\n"
3705 " OpSelectionMerge %false_label None\n"
3706 " OpBranchConditional %cnull %true_label %false_label\n"
3707 "%true_label = OpLabel\n"
3708 " OpStore %v %c_v4f32_0_5_0_5_0_5_0_5\n"
3709 " OpBranch %false_label\n"
3710 "%false_label = OpLabel\n"
3711 "%transformed_param = OpLoad %v4f32 %v\n"
3715 "%cnull = OpConstantNull %i32\n",
3716 "%v = OpVariable %fp_v4f32 Function %c_v4f32_0_5_0_5_0_5_0_5\n"
3717 "%b = OpIEqual %bool %cnull %c_i32_0\n"
3718 " OpSelectionMerge %false_label None\n"
3719 " OpBranchConditional %b %true_label %false_label\n"
3720 "%true_label = OpLabel\n"
3721 " OpStore %v %param1\n"
3722 " OpBranch %false_label\n"
3723 "%false_label = OpLabel\n"
3724 "%transformed_param = OpLoad %v4f32 %v\n"
3728 "%stype = OpTypeStruct %f32 %v4f32\n"
3729 "%fp_stype = OpTypePointer Function %stype\n"
3730 "%cnull = OpConstantNull %stype\n",
3731 "%v = OpVariable %fp_stype Function %cnull\n"
3732 "%f = OpAccessChain %fp_v4f32 %v %c_i32_1\n"
3733 "%f_val = OpLoad %v4f32 %f\n"
3734 "%transformed_param = OpFAdd %v4f32 %param1 %f_val\n"
3738 "%a4_v4f32 = OpTypeArray %v4f32 %c_u32_4\n"
3739 "%fp_a4_v4f32 = OpTypePointer Function %a4_v4f32\n"
3740 "%cnull = OpConstantNull %a4_v4f32\n",
3741 "%v = OpVariable %fp_a4_v4f32 Function %cnull\n"
3742 "%f = OpAccessChain %fp_v4f32 %v %c_u32_0\n"
3743 "%f1 = OpAccessChain %fp_v4f32 %v %c_u32_1\n"
3744 "%f2 = OpAccessChain %fp_v4f32 %v %c_u32_2\n"
3745 "%f3 = OpAccessChain %fp_v4f32 %v %c_u32_3\n"
3746 "%f_val = OpLoad %v4f32 %f\n"
3747 "%f1_val = OpLoad %v4f32 %f1\n"
3748 "%f2_val = OpLoad %v4f32 %f2\n"
3749 "%f3_val = OpLoad %v4f32 %f3\n"
3750 "%t0 = OpFAdd %v4f32 %param1 %f_val\n"
3751 "%t1 = OpFAdd %v4f32 %t0 %f1_val\n"
3752 "%t2 = OpFAdd %v4f32 %t1 %f2_val\n"
3753 "%transformed_param = OpFAdd %v4f32 %t2 %f3_val\n"
3757 "%mat4x4_f32 = OpTypeMatrix %v4f32 4\n"
3758 "%cnull = OpConstantNull %mat4x4_f32\n",
3759 // Our null matrix * any vector should result in a zero vector.
3760 "%v = OpVectorTimesMatrix %v4f32 %param1 %cnull\n"
3761 "%transformed_param = OpFAdd %v4f32 %param1 %v\n"
3765 getHalfColorsFullAlpha(colors);
3767 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameConstantsCode); ++testNdx)
3769 map<string, string> fragments;
3770 fragments["pre_main"] = tests[testNdx].constants;
3771 fragments["testfun"] = string(functionStart) + tests[testNdx].code + functionEnd;
3772 createTestsForAllStages(tests[testNdx].name, colors, colors, fragments, opConstantNullTests.get());
3774 return opConstantNullTests.release();
3776 tcu::TestCaseGroup* createOpConstantCompositeTests(tcu::TestContext& testCtx)
3778 de::MovePtr<tcu::TestCaseGroup> opConstantCompositeTests (new tcu::TestCaseGroup(testCtx, "opconstantcomposite", "OpConstantComposite instruction"));
3779 RGBA inputColors[4];
3780 RGBA outputColors[4];
3783 const char functionStart[] =
3784 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
3785 "%param1 = OpFunctionParameter %v4f32\n"
3788 const char functionEnd[] =
3789 "OpReturnValue %transformed_param\n"
3792 struct NameConstantsCode
3799 NameConstantsCode tests[] =
3804 "%cval = OpConstantComposite %v4f32 %c_f32_0_5 %c_f32_0_5 %c_f32_0_5 %c_f32_0\n",
3805 "%transformed_param = OpFAdd %v4f32 %param1 %cval\n"
3810 "%stype = OpTypeStruct %v4f32 %f32\n"
3811 "%fp_stype = OpTypePointer Function %stype\n"
3812 "%f32_n_1 = OpConstant %f32 -1.0\n"
3813 "%f32_1_5 = OpConstant %f32 !0x3fc00000\n" // +1.5
3814 "%cvec = OpConstantComposite %v4f32 %f32_1_5 %f32_1_5 %f32_1_5 %c_f32_1\n"
3815 "%cval = OpConstantComposite %stype %cvec %f32_n_1\n",
3817 "%v = OpVariable %fp_stype Function %cval\n"
3818 "%vec_ptr = OpAccessChain %fp_v4f32 %v %c_u32_0\n"
3819 "%f32_ptr = OpAccessChain %fp_f32 %v %c_u32_1\n"
3820 "%vec_val = OpLoad %v4f32 %vec_ptr\n"
3821 "%f32_val = OpLoad %f32 %f32_ptr\n"
3822 "%tmp1 = OpVectorTimesScalar %v4f32 %c_v4f32_1_1_1_1 %f32_val\n" // vec4(-1)
3823 "%tmp2 = OpFAdd %v4f32 %tmp1 %param1\n" // param1 + vec4(-1)
3824 "%transformed_param = OpFAdd %v4f32 %tmp2 %vec_val\n" // param1 + vec4(-1) + vec4(1.5, 1.5, 1.5, 1.0)
3827 // [1|0|0|0.5] [x] = x + 0.5
3828 // [0|1|0|0.5] [y] = y + 0.5
3829 // [0|0|1|0.5] [z] = z + 0.5
3830 // [0|0|0|1 ] [1] = 1
3833 "%mat4x4_f32 = OpTypeMatrix %v4f32 4\n"
3834 "%v4f32_1_0_0_0 = OpConstantComposite %v4f32 %c_f32_1 %c_f32_0 %c_f32_0 %c_f32_0\n"
3835 "%v4f32_0_1_0_0 = OpConstantComposite %v4f32 %c_f32_0 %c_f32_1 %c_f32_0 %c_f32_0\n"
3836 "%v4f32_0_0_1_0 = OpConstantComposite %v4f32 %c_f32_0 %c_f32_0 %c_f32_1 %c_f32_0\n"
3837 "%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"
3838 "%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",
3840 "%transformed_param = OpMatrixTimesVector %v4f32 %cval %param1\n"
3845 "%c_v4f32_1_1_1_0 = OpConstantComposite %v4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_0\n"
3846 "%fp_a4f32 = OpTypePointer Function %a4f32\n"
3847 "%f32_n_1 = OpConstant %f32 -1.0\n"
3848 "%f32_1_5 = OpConstant %f32 !0x3fc00000\n" // +1.5
3849 "%carr = OpConstantComposite %a4f32 %c_f32_0 %f32_n_1 %f32_1_5 %c_f32_0\n",
3851 "%v = OpVariable %fp_a4f32 Function %carr\n"
3852 "%f = OpAccessChain %fp_f32 %v %c_u32_0\n"
3853 "%f1 = OpAccessChain %fp_f32 %v %c_u32_1\n"
3854 "%f2 = OpAccessChain %fp_f32 %v %c_u32_2\n"
3855 "%f3 = OpAccessChain %fp_f32 %v %c_u32_3\n"
3856 "%f_val = OpLoad %f32 %f\n"
3857 "%f1_val = OpLoad %f32 %f1\n"
3858 "%f2_val = OpLoad %f32 %f2\n"
3859 "%f3_val = OpLoad %f32 %f3\n"
3860 "%ftot1 = OpFAdd %f32 %f_val %f1_val\n"
3861 "%ftot2 = OpFAdd %f32 %ftot1 %f2_val\n"
3862 "%ftot3 = OpFAdd %f32 %ftot2 %f3_val\n" // 0 - 1 + 1.5 + 0
3863 "%add_vec = OpVectorTimesScalar %v4f32 %c_v4f32_1_1_1_0 %ftot3\n"
3864 "%transformed_param = OpFAdd %v4f32 %param1 %add_vec\n"
3871 // [ 1.0, 1.0, 1.0, 1.0]
3875 // [ 0.0, 0.5, 0.0, 0.0]
3879 // [ 1.0, 1.0, 1.0, 1.0]
3882 "array_of_struct_of_array",
3884 "%c_v4f32_1_1_1_0 = OpConstantComposite %v4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_0\n"
3885 "%fp_a4f32 = OpTypePointer Function %a4f32\n"
3886 "%stype = OpTypeStruct %f32 %a4f32\n"
3887 "%a3stype = OpTypeArray %stype %c_u32_3\n"
3888 "%fp_a3stype = OpTypePointer Function %a3stype\n"
3889 "%ca4f32_0 = OpConstantComposite %a4f32 %c_f32_0 %c_f32_0_5 %c_f32_0 %c_f32_0\n"
3890 "%ca4f32_1 = OpConstantComposite %a4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_1\n"
3891 "%cstype1 = OpConstantComposite %stype %c_f32_0 %ca4f32_1\n"
3892 "%cstype2 = OpConstantComposite %stype %c_f32_1 %ca4f32_0\n"
3893 "%carr = OpConstantComposite %a3stype %cstype1 %cstype2 %cstype1",
3895 "%v = OpVariable %fp_a3stype Function %carr\n"
3896 "%f = OpAccessChain %fp_f32 %v %c_u32_1 %c_u32_1 %c_u32_1\n"
3897 "%f_l = OpLoad %f32 %f\n"
3898 "%add_vec = OpVectorTimesScalar %v4f32 %c_v4f32_1_1_1_0 %f_l\n"
3899 "%transformed_param = OpFAdd %v4f32 %param1 %add_vec\n"
3903 getHalfColorsFullAlpha(inputColors);
3904 outputColors[0] = RGBA(255, 255, 255, 255);
3905 outputColors[1] = RGBA(255, 127, 127, 255);
3906 outputColors[2] = RGBA(127, 255, 127, 255);
3907 outputColors[3] = RGBA(127, 127, 255, 255);
3909 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameConstantsCode); ++testNdx)
3911 map<string, string> fragments;
3912 fragments["pre_main"] = tests[testNdx].constants;
3913 fragments["testfun"] = string(functionStart) + tests[testNdx].code + functionEnd;
3914 createTestsForAllStages(tests[testNdx].name, inputColors, outputColors, fragments, opConstantCompositeTests.get());
3916 return opConstantCompositeTests.release();
3919 tcu::TestCaseGroup* createSelectionBlockOrderTests(tcu::TestContext& testCtx)
3921 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "selection_block_order", "Out-of-order blocks for selection"));
3922 RGBA inputColors[4];
3923 RGBA outputColors[4];
3924 map<string, string> fragments;
3926 // vec4 test_code(vec4 param) {
3927 // vec4 result = param;
3928 // for (int i = 0; i < 4; ++i) {
3929 // if (i == 0) result[i] = 0.;
3930 // else result[i] = 1. - result[i];
3934 const char function[] =
3935 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
3936 "%param1 = OpFunctionParameter %v4f32\n"
3938 "%iptr = OpVariable %fp_i32 Function\n"
3939 "%result = OpVariable %fp_v4f32 Function\n"
3940 " OpStore %iptr %c_i32_0\n"
3941 " OpStore %result %param1\n"
3944 // Loop entry block.
3946 "%ival = OpLoad %i32 %iptr\n"
3947 "%lt_4 = OpSLessThan %bool %ival %c_i32_4\n"
3948 " OpLoopMerge %exit %if_entry None\n"
3949 " OpBranchConditional %lt_4 %if_entry %exit\n"
3951 // Merge block for loop.
3953 "%ret = OpLoad %v4f32 %result\n"
3954 " OpReturnValue %ret\n"
3956 // If-statement entry block.
3957 "%if_entry = OpLabel\n"
3958 "%loc = OpAccessChain %fp_f32 %result %ival\n"
3959 "%eq_0 = OpIEqual %bool %ival %c_i32_0\n"
3960 " OpSelectionMerge %if_exit None\n"
3961 " OpBranchConditional %eq_0 %if_true %if_false\n"
3963 // False branch for if-statement.
3964 "%if_false = OpLabel\n"
3965 "%val = OpLoad %f32 %loc\n"
3966 "%sub = OpFSub %f32 %c_f32_1 %val\n"
3967 " OpStore %loc %sub\n"
3968 " OpBranch %if_exit\n"
3970 // Merge block for if-statement.
3971 "%if_exit = OpLabel\n"
3972 "%ival_next = OpIAdd %i32 %ival %c_i32_1\n"
3973 " OpStore %iptr %ival_next\n"
3976 // True branch for if-statement.
3977 "%if_true = OpLabel\n"
3978 " OpStore %loc %c_f32_0\n"
3979 " OpBranch %if_exit\n"
3983 fragments["testfun"] = function;
3985 inputColors[0] = RGBA(127, 127, 127, 0);
3986 inputColors[1] = RGBA(127, 0, 0, 0);
3987 inputColors[2] = RGBA(0, 127, 0, 0);
3988 inputColors[3] = RGBA(0, 0, 127, 0);
3990 outputColors[0] = RGBA(0, 128, 128, 255);
3991 outputColors[1] = RGBA(0, 255, 255, 255);
3992 outputColors[2] = RGBA(0, 128, 255, 255);
3993 outputColors[3] = RGBA(0, 255, 128, 255);
3995 createTestsForAllStages("out_of_order", inputColors, outputColors, fragments, group.get());
3997 return group.release();
4000 tcu::TestCaseGroup* createSwitchBlockOrderTests(tcu::TestContext& testCtx)
4002 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "switch_block_order", "Out-of-order blocks for switch"));
4003 RGBA inputColors[4];
4004 RGBA outputColors[4];
4005 map<string, string> fragments;
4007 const char typesAndConstants[] =
4008 "%c_f32_p2 = OpConstant %f32 0.2\n"
4009 "%c_f32_p4 = OpConstant %f32 0.4\n"
4010 "%c_f32_p6 = OpConstant %f32 0.6\n"
4011 "%c_f32_p8 = OpConstant %f32 0.8\n";
4013 // vec4 test_code(vec4 param) {
4014 // vec4 result = param;
4015 // for (int i = 0; i < 4; ++i) {
4017 // case 0: result[i] += .2; break;
4018 // case 1: result[i] += .6; break;
4019 // case 2: result[i] += .4; break;
4020 // case 3: result[i] += .8; break;
4021 // default: break; // unreachable
4026 const char function[] =
4027 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
4028 "%param1 = OpFunctionParameter %v4f32\n"
4030 "%iptr = OpVariable %fp_i32 Function\n"
4031 "%result = OpVariable %fp_v4f32 Function\n"
4032 " OpStore %iptr %c_i32_0\n"
4033 " OpStore %result %param1\n"
4036 // Loop entry block.
4038 "%ival = OpLoad %i32 %iptr\n"
4039 "%lt_4 = OpSLessThan %bool %ival %c_i32_4\n"
4040 " OpLoopMerge %exit %switch_exit None\n"
4041 " OpBranchConditional %lt_4 %switch_entry %exit\n"
4043 // Merge block for loop.
4045 "%ret = OpLoad %v4f32 %result\n"
4046 " OpReturnValue %ret\n"
4048 // Switch-statement entry block.
4049 "%switch_entry = OpLabel\n"
4050 "%loc = OpAccessChain %fp_f32 %result %ival\n"
4051 "%val = OpLoad %f32 %loc\n"
4052 " OpSelectionMerge %switch_exit None\n"
4053 " OpSwitch %ival %switch_default 0 %case0 1 %case1 2 %case2 3 %case3\n"
4055 "%case2 = OpLabel\n"
4056 "%addp4 = OpFAdd %f32 %val %c_f32_p4\n"
4057 " OpStore %loc %addp4\n"
4058 " OpBranch %switch_exit\n"
4060 "%switch_default = OpLabel\n"
4063 "%case3 = OpLabel\n"
4064 "%addp8 = OpFAdd %f32 %val %c_f32_p8\n"
4065 " OpStore %loc %addp8\n"
4066 " OpBranch %switch_exit\n"
4068 "%case0 = OpLabel\n"
4069 "%addp2 = OpFAdd %f32 %val %c_f32_p2\n"
4070 " OpStore %loc %addp2\n"
4071 " OpBranch %switch_exit\n"
4073 // Merge block for switch-statement.
4074 "%switch_exit = OpLabel\n"
4075 "%ival_next = OpIAdd %i32 %ival %c_i32_1\n"
4076 " OpStore %iptr %ival_next\n"
4079 "%case1 = OpLabel\n"
4080 "%addp6 = OpFAdd %f32 %val %c_f32_p6\n"
4081 " OpStore %loc %addp6\n"
4082 " OpBranch %switch_exit\n"
4086 fragments["pre_main"] = typesAndConstants;
4087 fragments["testfun"] = function;
4089 inputColors[0] = RGBA(127, 27, 127, 51);
4090 inputColors[1] = RGBA(127, 0, 0, 51);
4091 inputColors[2] = RGBA(0, 27, 0, 51);
4092 inputColors[3] = RGBA(0, 0, 127, 51);
4094 outputColors[0] = RGBA(178, 180, 229, 255);
4095 outputColors[1] = RGBA(178, 153, 102, 255);
4096 outputColors[2] = RGBA(51, 180, 102, 255);
4097 outputColors[3] = RGBA(51, 153, 229, 255);
4099 createTestsForAllStages("out_of_order", inputColors, outputColors, fragments, group.get());
4101 return group.release();
4104 tcu::TestCaseGroup* createDecorationGroupTests(tcu::TestContext& testCtx)
4106 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "decoration_group", "Decoration group tests"));
4107 RGBA inputColors[4];
4108 RGBA outputColors[4];
4109 map<string, string> fragments;
4111 const char decorations[] =
4112 "OpDecorate %array_group ArrayStride 4\n"
4113 "OpDecorate %struct_member_group Offset 0\n"
4114 "%array_group = OpDecorationGroup\n"
4115 "%struct_member_group = OpDecorationGroup\n"
4117 "OpDecorate %group1 RelaxedPrecision\n"
4118 "OpDecorate %group3 RelaxedPrecision\n"
4119 "OpDecorate %group3 Invariant\n"
4120 "OpDecorate %group3 Restrict\n"
4121 "%group0 = OpDecorationGroup\n"
4122 "%group1 = OpDecorationGroup\n"
4123 "%group3 = OpDecorationGroup\n";
4125 const char typesAndConstants[] =
4126 "%a3f32 = OpTypeArray %f32 %c_u32_3\n"
4127 "%struct1 = OpTypeStruct %a3f32\n"
4128 "%struct2 = OpTypeStruct %a3f32\n"
4129 "%fp_struct1 = OpTypePointer Function %struct1\n"
4130 "%fp_struct2 = OpTypePointer Function %struct2\n"
4131 "%c_f32_2 = OpConstant %f32 2.\n"
4132 "%c_f32_n2 = OpConstant %f32 -2.\n"
4134 "%c_a3f32_1 = OpConstantComposite %a3f32 %c_f32_1 %c_f32_2 %c_f32_1\n"
4135 "%c_a3f32_2 = OpConstantComposite %a3f32 %c_f32_n1 %c_f32_n2 %c_f32_n1\n"
4136 "%c_struct1 = OpConstantComposite %struct1 %c_a3f32_1\n"
4137 "%c_struct2 = OpConstantComposite %struct2 %c_a3f32_2\n";
4139 const char function[] =
4140 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
4141 "%param = OpFunctionParameter %v4f32\n"
4142 "%entry = OpLabel\n"
4143 "%result = OpVariable %fp_v4f32 Function\n"
4144 "%v_struct1 = OpVariable %fp_struct1 Function\n"
4145 "%v_struct2 = OpVariable %fp_struct2 Function\n"
4146 " OpStore %result %param\n"
4147 " OpStore %v_struct1 %c_struct1\n"
4148 " OpStore %v_struct2 %c_struct2\n"
4149 "%ptr1 = OpAccessChain %fp_f32 %v_struct1 %c_i32_0 %c_i32_2\n"
4150 "%val1 = OpLoad %f32 %ptr1\n"
4151 "%ptr2 = OpAccessChain %fp_f32 %v_struct2 %c_i32_0 %c_i32_2\n"
4152 "%val2 = OpLoad %f32 %ptr2\n"
4153 "%addvalues = OpFAdd %f32 %val1 %val2\n"
4154 "%ptr = OpAccessChain %fp_f32 %result %c_i32_1\n"
4155 "%val = OpLoad %f32 %ptr\n"
4156 "%addresult = OpFAdd %f32 %addvalues %val\n"
4157 " OpStore %ptr %addresult\n"
4158 "%ret = OpLoad %v4f32 %result\n"
4159 " OpReturnValue %ret\n"
4162 struct CaseNameDecoration
4168 CaseNameDecoration tests[] =
4171 "same_decoration_group_on_multiple_types",
4172 "OpGroupMemberDecorate %struct_member_group %struct1 0 %struct2 0\n"
4175 "empty_decoration_group",
4176 "OpGroupDecorate %group0 %a3f32\n"
4177 "OpGroupDecorate %group0 %result\n"
4180 "one_element_decoration_group",
4181 "OpGroupDecorate %array_group %a3f32\n"
4184 "multiple_elements_decoration_group",
4185 "OpGroupDecorate %group3 %v_struct1\n"
4188 "multiple_decoration_groups_on_same_variable",
4189 "OpGroupDecorate %group0 %v_struct2\n"
4190 "OpGroupDecorate %group1 %v_struct2\n"
4191 "OpGroupDecorate %group3 %v_struct2\n"
4194 "same_decoration_group_multiple_times",
4195 "OpGroupDecorate %group1 %addvalues\n"
4196 "OpGroupDecorate %group1 %addvalues\n"
4197 "OpGroupDecorate %group1 %addvalues\n"
4202 getHalfColorsFullAlpha(inputColors);
4203 getHalfColorsFullAlpha(outputColors);
4205 for (size_t idx = 0; idx < (sizeof(tests) / sizeof(tests[0])); ++idx)
4207 fragments["decoration"] = decorations + tests[idx].decoration;
4208 fragments["pre_main"] = typesAndConstants;
4209 fragments["testfun"] = function;
4211 createTestsForAllStages(tests[idx].name, inputColors, outputColors, fragments, group.get());
4214 return group.release();
4217 struct SpecConstantTwoIntGraphicsCase
4219 const char* caseName;
4220 const char* scDefinition0;
4221 const char* scDefinition1;
4222 const char* scResultType;
4223 const char* scOperation;
4224 deInt32 scActualValue0;
4225 deInt32 scActualValue1;
4226 const char* resultOperation;
4227 RGBA expectedColors[4];
4229 SpecConstantTwoIntGraphicsCase (const char* name,
4230 const char* definition0,
4231 const char* definition1,
4232 const char* resultType,
4233 const char* operation,
4236 const char* resultOp,
4237 const RGBA (&output)[4])
4239 , scDefinition0 (definition0)
4240 , scDefinition1 (definition1)
4241 , scResultType (resultType)
4242 , scOperation (operation)
4243 , scActualValue0 (value0)
4244 , scActualValue1 (value1)
4245 , resultOperation (resultOp)
4247 expectedColors[0] = output[0];
4248 expectedColors[1] = output[1];
4249 expectedColors[2] = output[2];
4250 expectedColors[3] = output[3];
4254 tcu::TestCaseGroup* createSpecConstantTests (tcu::TestContext& testCtx)
4256 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opspecconstantop", "Test the OpSpecConstantOp instruction"));
4257 vector<SpecConstantTwoIntGraphicsCase> cases;
4258 RGBA inputColors[4];
4259 RGBA outputColors0[4];
4260 RGBA outputColors1[4];
4261 RGBA outputColors2[4];
4263 const char decorations1[] =
4264 "OpDecorate %sc_0 SpecId 0\n"
4265 "OpDecorate %sc_1 SpecId 1\n";
4267 const char typesAndConstants1[] =
4268 "%sc_0 = OpSpecConstant${SC_DEF0}\n"
4269 "%sc_1 = OpSpecConstant${SC_DEF1}\n"
4270 "%sc_op = OpSpecConstantOp ${SC_RESULT_TYPE} ${SC_OP}\n";
4272 const char function1[] =
4273 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
4274 "%param = OpFunctionParameter %v4f32\n"
4275 "%label = OpLabel\n"
4276 "%result = OpVariable %fp_v4f32 Function\n"
4277 " OpStore %result %param\n"
4278 "%gen = ${GEN_RESULT}\n"
4279 "%index = OpIAdd %i32 %gen %c_i32_1\n"
4280 "%loc = OpAccessChain %fp_f32 %result %index\n"
4281 "%val = OpLoad %f32 %loc\n"
4282 "%add = OpFAdd %f32 %val %c_f32_0_5\n"
4283 " OpStore %loc %add\n"
4284 "%ret = OpLoad %v4f32 %result\n"
4285 " OpReturnValue %ret\n"
4288 inputColors[0] = RGBA(127, 127, 127, 255);
4289 inputColors[1] = RGBA(127, 0, 0, 255);
4290 inputColors[2] = RGBA(0, 127, 0, 255);
4291 inputColors[3] = RGBA(0, 0, 127, 255);
4293 // Derived from inputColors[x] by adding 128 to inputColors[x][0].
4294 outputColors0[0] = RGBA(255, 127, 127, 255);
4295 outputColors0[1] = RGBA(255, 0, 0, 255);
4296 outputColors0[2] = RGBA(128, 127, 0, 255);
4297 outputColors0[3] = RGBA(128, 0, 127, 255);
4299 // Derived from inputColors[x] by adding 128 to inputColors[x][1].
4300 outputColors1[0] = RGBA(127, 255, 127, 255);
4301 outputColors1[1] = RGBA(127, 128, 0, 255);
4302 outputColors1[2] = RGBA(0, 255, 0, 255);
4303 outputColors1[3] = RGBA(0, 128, 127, 255);
4305 // Derived from inputColors[x] by adding 128 to inputColors[x][2].
4306 outputColors2[0] = RGBA(127, 127, 255, 255);
4307 outputColors2[1] = RGBA(127, 0, 128, 255);
4308 outputColors2[2] = RGBA(0, 127, 128, 255);
4309 outputColors2[3] = RGBA(0, 0, 255, 255);
4311 const char addZeroToSc[] = "OpIAdd %i32 %c_i32_0 %sc_op";
4312 const char selectTrueUsingSc[] = "OpSelect %i32 %sc_op %c_i32_1 %c_i32_0";
4313 const char selectFalseUsingSc[] = "OpSelect %i32 %sc_op %c_i32_0 %c_i32_1";
4315 cases.push_back(SpecConstantTwoIntGraphicsCase("iadd", " %i32 0", " %i32 0", "%i32", "IAdd %sc_0 %sc_1", 19, -20, addZeroToSc, outputColors0));
4316 cases.push_back(SpecConstantTwoIntGraphicsCase("isub", " %i32 0", " %i32 0", "%i32", "ISub %sc_0 %sc_1", 19, 20, addZeroToSc, outputColors0));
4317 cases.push_back(SpecConstantTwoIntGraphicsCase("imul", " %i32 0", " %i32 0", "%i32", "IMul %sc_0 %sc_1", -1, -1, addZeroToSc, outputColors2));
4318 cases.push_back(SpecConstantTwoIntGraphicsCase("sdiv", " %i32 0", " %i32 0", "%i32", "SDiv %sc_0 %sc_1", -126, 126, addZeroToSc, outputColors0));
4319 cases.push_back(SpecConstantTwoIntGraphicsCase("udiv", " %i32 0", " %i32 0", "%i32", "UDiv %sc_0 %sc_1", 126, 126, addZeroToSc, outputColors2));
4320 cases.push_back(SpecConstantTwoIntGraphicsCase("srem", " %i32 0", " %i32 0", "%i32", "SRem %sc_0 %sc_1", 3, 2, addZeroToSc, outputColors2));
4321 cases.push_back(SpecConstantTwoIntGraphicsCase("smod", " %i32 0", " %i32 0", "%i32", "SMod %sc_0 %sc_1", 3, 2, addZeroToSc, outputColors2));
4322 cases.push_back(SpecConstantTwoIntGraphicsCase("umod", " %i32 0", " %i32 0", "%i32", "UMod %sc_0 %sc_1", 1001, 500, addZeroToSc, outputColors2));
4323 cases.push_back(SpecConstantTwoIntGraphicsCase("bitwiseand", " %i32 0", " %i32 0", "%i32", "BitwiseAnd %sc_0 %sc_1", 0x33, 0x0d, addZeroToSc, outputColors2));
4324 cases.push_back(SpecConstantTwoIntGraphicsCase("bitwiseor", " %i32 0", " %i32 0", "%i32", "BitwiseOr %sc_0 %sc_1", 0, 1, addZeroToSc, outputColors2));
4325 cases.push_back(SpecConstantTwoIntGraphicsCase("bitwisexor", " %i32 0", " %i32 0", "%i32", "BitwiseXor %sc_0 %sc_1", 0x2e, 0x2f, addZeroToSc, outputColors2));
4326 cases.push_back(SpecConstantTwoIntGraphicsCase("shiftrightlogical", " %i32 0", " %i32 0", "%i32", "ShiftRightLogical %sc_0 %sc_1", 2, 1, addZeroToSc, outputColors2));
4327 cases.push_back(SpecConstantTwoIntGraphicsCase("shiftrightarithmetic", " %i32 0", " %i32 0", "%i32", "ShiftRightArithmetic %sc_0 %sc_1", -4, 2, addZeroToSc, outputColors0));
4328 cases.push_back(SpecConstantTwoIntGraphicsCase("shiftleftlogical", " %i32 0", " %i32 0", "%i32", "ShiftLeftLogical %sc_0 %sc_1", 1, 0, addZeroToSc, outputColors2));
4329 cases.push_back(SpecConstantTwoIntGraphicsCase("slessthan", " %i32 0", " %i32 0", "%bool", "SLessThan %sc_0 %sc_1", -20, -10, selectTrueUsingSc, outputColors2));
4330 cases.push_back(SpecConstantTwoIntGraphicsCase("ulessthan", " %i32 0", " %i32 0", "%bool", "ULessThan %sc_0 %sc_1", 10, 20, selectTrueUsingSc, outputColors2));
4331 cases.push_back(SpecConstantTwoIntGraphicsCase("sgreaterthan", " %i32 0", " %i32 0", "%bool", "SGreaterThan %sc_0 %sc_1", -1000, 50, selectFalseUsingSc, outputColors2));
4332 cases.push_back(SpecConstantTwoIntGraphicsCase("ugreaterthan", " %i32 0", " %i32 0", "%bool", "UGreaterThan %sc_0 %sc_1", 10, 5, selectTrueUsingSc, outputColors2));
4333 cases.push_back(SpecConstantTwoIntGraphicsCase("slessthanequal", " %i32 0", " %i32 0", "%bool", "SLessThanEqual %sc_0 %sc_1", -10, -10, selectTrueUsingSc, outputColors2));
4334 cases.push_back(SpecConstantTwoIntGraphicsCase("ulessthanequal", " %i32 0", " %i32 0", "%bool", "ULessThanEqual %sc_0 %sc_1", 50, 100, selectTrueUsingSc, outputColors2));
4335 cases.push_back(SpecConstantTwoIntGraphicsCase("sgreaterthanequal", " %i32 0", " %i32 0", "%bool", "SGreaterThanEqual %sc_0 %sc_1", -1000, 50, selectFalseUsingSc, outputColors2));
4336 cases.push_back(SpecConstantTwoIntGraphicsCase("ugreaterthanequal", " %i32 0", " %i32 0", "%bool", "UGreaterThanEqual %sc_0 %sc_1", 10, 10, selectTrueUsingSc, outputColors2));
4337 cases.push_back(SpecConstantTwoIntGraphicsCase("iequal", " %i32 0", " %i32 0", "%bool", "IEqual %sc_0 %sc_1", 42, 24, selectFalseUsingSc, outputColors2));
4338 cases.push_back(SpecConstantTwoIntGraphicsCase("logicaland", "True %bool", "True %bool", "%bool", "LogicalAnd %sc_0 %sc_1", 0, 1, selectFalseUsingSc, outputColors2));
4339 cases.push_back(SpecConstantTwoIntGraphicsCase("logicalor", "False %bool", "False %bool", "%bool", "LogicalOr %sc_0 %sc_1", 1, 0, selectTrueUsingSc, outputColors2));
4340 cases.push_back(SpecConstantTwoIntGraphicsCase("logicalequal", "True %bool", "True %bool", "%bool", "LogicalEqual %sc_0 %sc_1", 0, 1, selectFalseUsingSc, outputColors2));
4341 cases.push_back(SpecConstantTwoIntGraphicsCase("logicalnotequal", "False %bool", "False %bool", "%bool", "LogicalNotEqual %sc_0 %sc_1", 1, 0, selectTrueUsingSc, outputColors2));
4342 cases.push_back(SpecConstantTwoIntGraphicsCase("snegate", " %i32 0", " %i32 0", "%i32", "SNegate %sc_0", -1, 0, addZeroToSc, outputColors2));
4343 cases.push_back(SpecConstantTwoIntGraphicsCase("not", " %i32 0", " %i32 0", "%i32", "Not %sc_0", -2, 0, addZeroToSc, outputColors2));
4344 cases.push_back(SpecConstantTwoIntGraphicsCase("logicalnot", "False %bool", "False %bool", "%bool", "LogicalNot %sc_0", 1, 0, selectFalseUsingSc, outputColors2));
4345 cases.push_back(SpecConstantTwoIntGraphicsCase("select", "False %bool", " %i32 0", "%i32", "Select %sc_0 %sc_1 %c_i32_0", 1, 1, addZeroToSc, outputColors2));
4346 // OpSConvert, OpFConvert: these two instructions involve ints/floats of different bitwidths.
4347 // \todo[2015-12-1 antiagainst] OpQuantizeToF16
4349 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
4351 map<string, string> specializations;
4352 map<string, string> fragments;
4353 vector<deInt32> specConstants;
4355 specializations["SC_DEF0"] = cases[caseNdx].scDefinition0;
4356 specializations["SC_DEF1"] = cases[caseNdx].scDefinition1;
4357 specializations["SC_RESULT_TYPE"] = cases[caseNdx].scResultType;
4358 specializations["SC_OP"] = cases[caseNdx].scOperation;
4359 specializations["GEN_RESULT"] = cases[caseNdx].resultOperation;
4361 fragments["decoration"] = tcu::StringTemplate(decorations1).specialize(specializations);
4362 fragments["pre_main"] = tcu::StringTemplate(typesAndConstants1).specialize(specializations);
4363 fragments["testfun"] = tcu::StringTemplate(function1).specialize(specializations);
4365 specConstants.push_back(cases[caseNdx].scActualValue0);
4366 specConstants.push_back(cases[caseNdx].scActualValue1);
4368 createTestsForAllStages(cases[caseNdx].caseName, inputColors, cases[caseNdx].expectedColors, fragments, specConstants, group.get());
4371 const char decorations2[] =
4372 "OpDecorate %sc_0 SpecId 0\n"
4373 "OpDecorate %sc_1 SpecId 1\n"
4374 "OpDecorate %sc_2 SpecId 2\n";
4376 const char typesAndConstants2[] =
4377 "%v3i32 = OpTypeVector %i32 3\n"
4379 "%sc_0 = OpSpecConstant %i32 0\n"
4380 "%sc_1 = OpSpecConstant %i32 0\n"
4381 "%sc_2 = OpSpecConstant %i32 0\n"
4383 "%vec3_0 = OpConstantComposite %v3i32 %c_i32_0 %c_i32_0 %c_i32_0\n"
4384 "%sc_vec3_0 = OpSpecConstantOp %v3i32 CompositeInsert %sc_0 %vec3_0 0\n" // (sc_0, 0, 0)
4385 "%sc_vec3_1 = OpSpecConstantOp %v3i32 CompositeInsert %sc_1 %vec3_0 1\n" // (0, sc_1, 0)
4386 "%sc_vec3_2 = OpSpecConstantOp %v3i32 CompositeInsert %sc_2 %vec3_0 2\n" // (0, 0, sc_2)
4387 "%sc_vec3_01 = OpSpecConstantOp %v3i32 VectorShuffle %sc_vec3_0 %sc_vec3_1 1 0 4\n" // (0, sc_0, sc_1)
4388 "%sc_vec3_012 = OpSpecConstantOp %v3i32 VectorShuffle %sc_vec3_01 %sc_vec3_2 5 1 2\n" // (sc_2, sc_0, sc_1)
4389 "%sc_ext_0 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 0\n" // sc_2
4390 "%sc_ext_1 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 1\n" // sc_0
4391 "%sc_ext_2 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 2\n" // sc_1
4392 "%sc_sub = OpSpecConstantOp %i32 ISub %sc_ext_0 %sc_ext_1\n" // (sc_2 - sc_0)
4393 "%sc_final = OpSpecConstantOp %i32 IMul %sc_sub %sc_ext_2\n"; // (sc_2 - sc_0) * sc_1
4395 const char function2[] =
4396 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
4397 "%param = OpFunctionParameter %v4f32\n"
4398 "%label = OpLabel\n"
4399 "%result = OpVariable %fp_v4f32 Function\n"
4400 " OpStore %result %param\n"
4401 "%loc = OpAccessChain %fp_f32 %result %sc_final\n"
4402 "%val = OpLoad %f32 %loc\n"
4403 "%add = OpFAdd %f32 %val %c_f32_0_5\n"
4404 " OpStore %loc %add\n"
4405 "%ret = OpLoad %v4f32 %result\n"
4406 " OpReturnValue %ret\n"
4409 map<string, string> fragments;
4410 vector<deInt32> specConstants;
4412 fragments["decoration"] = decorations2;
4413 fragments["pre_main"] = typesAndConstants2;
4414 fragments["testfun"] = function2;
4416 specConstants.push_back(56789);
4417 specConstants.push_back(-2);
4418 specConstants.push_back(56788);
4420 createTestsForAllStages("vector_related", inputColors, outputColors2, fragments, specConstants, group.get());
4422 return group.release();
4425 tcu::TestCaseGroup* createOpPhiTests(tcu::TestContext& testCtx)
4427 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opphi", "Test the OpPhi instruction"));
4428 RGBA inputColors[4];
4429 RGBA outputColors1[4];
4430 RGBA outputColors2[4];
4431 RGBA outputColors3[4];
4432 map<string, string> fragments1;
4433 map<string, string> fragments2;
4434 map<string, string> fragments3;
4436 const char typesAndConstants1[] =
4437 "%c_f32_p2 = OpConstant %f32 0.2\n"
4438 "%c_f32_p4 = OpConstant %f32 0.4\n"
4439 "%c_f32_p5 = OpConstant %f32 0.5\n"
4440 "%c_f32_p8 = OpConstant %f32 0.8\n";
4442 // vec4 test_code(vec4 param) {
4443 // vec4 result = param;
4444 // for (int i = 0; i < 4; ++i) {
4447 // case 0: operand = .2; break;
4448 // case 1: operand = .5; break;
4449 // case 2: operand = .4; break;
4450 // case 3: operand = .0; break;
4451 // default: break; // unreachable
4453 // result[i] += operand;
4457 const char function1[] =
4458 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
4459 "%param1 = OpFunctionParameter %v4f32\n"
4461 "%iptr = OpVariable %fp_i32 Function\n"
4462 "%result = OpVariable %fp_v4f32 Function\n"
4463 " OpStore %iptr %c_i32_0\n"
4464 " OpStore %result %param1\n"
4468 "%ival = OpLoad %i32 %iptr\n"
4469 "%lt_4 = OpSLessThan %bool %ival %c_i32_4\n"
4470 " OpLoopMerge %exit %phi None\n"
4471 " OpBranchConditional %lt_4 %entry %exit\n"
4473 "%entry = OpLabel\n"
4474 "%loc = OpAccessChain %fp_f32 %result %ival\n"
4475 "%val = OpLoad %f32 %loc\n"
4476 " OpSelectionMerge %phi None\n"
4477 " OpSwitch %ival %default 0 %case0 1 %case1 2 %case2 3 %case3\n"
4479 "%case0 = OpLabel\n"
4481 "%case1 = OpLabel\n"
4483 "%case2 = OpLabel\n"
4485 "%case3 = OpLabel\n"
4488 "%default = OpLabel\n"
4492 "%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
4493 "%add = OpFAdd %f32 %val %operand\n"
4494 " OpStore %loc %add\n"
4495 "%ival_next = OpIAdd %i32 %ival %c_i32_1\n"
4496 " OpStore %iptr %ival_next\n"
4500 "%ret = OpLoad %v4f32 %result\n"
4501 " OpReturnValue %ret\n"
4505 fragments1["pre_main"] = typesAndConstants1;
4506 fragments1["testfun"] = function1;
4508 getHalfColorsFullAlpha(inputColors);
4510 outputColors1[0] = RGBA(178, 255, 229, 255);
4511 outputColors1[1] = RGBA(178, 127, 102, 255);
4512 outputColors1[2] = RGBA(51, 255, 102, 255);
4513 outputColors1[3] = RGBA(51, 127, 229, 255);
4515 createTestsForAllStages("out_of_order", inputColors, outputColors1, fragments1, group.get());
4517 const char typesAndConstants2[] =
4518 "%c_f32_p2 = OpConstant %f32 0.2\n";
4520 // Add .4 to the second element of the given parameter.
4521 const char function2[] =
4522 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
4523 "%param = OpFunctionParameter %v4f32\n"
4524 "%entry = OpLabel\n"
4525 "%result = OpVariable %fp_v4f32 Function\n"
4526 " OpStore %result %param\n"
4527 "%loc = OpAccessChain %fp_f32 %result %c_i32_1\n"
4528 "%val = OpLoad %f32 %loc\n"
4532 "%step = OpPhi %i32 %c_i32_0 %entry %step_next %phi\n"
4533 "%accum = OpPhi %f32 %val %entry %accum_next %phi\n"
4534 "%step_next = OpIAdd %i32 %step %c_i32_1\n"
4535 "%accum_next = OpFAdd %f32 %accum %c_f32_p2\n"
4536 "%still_loop = OpSLessThan %bool %step %c_i32_2\n"
4537 " OpLoopMerge %exit %phi None\n"
4538 " OpBranchConditional %still_loop %phi %exit\n"
4541 " OpStore %loc %accum\n"
4542 "%ret = OpLoad %v4f32 %result\n"
4543 " OpReturnValue %ret\n"
4547 fragments2["pre_main"] = typesAndConstants2;
4548 fragments2["testfun"] = function2;
4550 outputColors2[0] = RGBA(127, 229, 127, 255);
4551 outputColors2[1] = RGBA(127, 102, 0, 255);
4552 outputColors2[2] = RGBA(0, 229, 0, 255);
4553 outputColors2[3] = RGBA(0, 102, 127, 255);
4555 createTestsForAllStages("induction", inputColors, outputColors2, fragments2, group.get());
4557 const char typesAndConstants3[] =
4558 "%true = OpConstantTrue %bool\n"
4559 "%false = OpConstantFalse %bool\n"
4560 "%c_f32_p2 = OpConstant %f32 0.2\n";
4562 // Swap the second and the third element of the given parameter.
4563 const char function3[] =
4564 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
4565 "%param = OpFunctionParameter %v4f32\n"
4566 "%entry = OpLabel\n"
4567 "%result = OpVariable %fp_v4f32 Function\n"
4568 " OpStore %result %param\n"
4569 "%a_loc = OpAccessChain %fp_f32 %result %c_i32_1\n"
4570 "%a_init = OpLoad %f32 %a_loc\n"
4571 "%b_loc = OpAccessChain %fp_f32 %result %c_i32_2\n"
4572 "%b_init = OpLoad %f32 %b_loc\n"
4576 "%still_loop = OpPhi %bool %true %entry %false %phi\n"
4577 "%a_next = OpPhi %f32 %a_init %entry %b_next %phi\n"
4578 "%b_next = OpPhi %f32 %b_init %entry %a_next %phi\n"
4579 " OpLoopMerge %exit %phi None\n"
4580 " OpBranchConditional %still_loop %phi %exit\n"
4583 " OpStore %a_loc %a_next\n"
4584 " OpStore %b_loc %b_next\n"
4585 "%ret = OpLoad %v4f32 %result\n"
4586 " OpReturnValue %ret\n"
4590 fragments3["pre_main"] = typesAndConstants3;
4591 fragments3["testfun"] = function3;
4593 outputColors3[0] = RGBA(127, 127, 127, 255);
4594 outputColors3[1] = RGBA(127, 0, 0, 255);
4595 outputColors3[2] = RGBA(0, 0, 127, 255);
4596 outputColors3[3] = RGBA(0, 127, 0, 255);
4598 createTestsForAllStages("swap", inputColors, outputColors3, fragments3, group.get());
4600 return group.release();
4603 tcu::TestCaseGroup* createNoContractionTests(tcu::TestContext& testCtx)
4605 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "nocontraction", "Test the NoContraction decoration"));
4606 RGBA inputColors[4];
4607 RGBA outputColors[4];
4609 // With NoContraction, (1 + 2^-23) * (1 - 2^-23) - 1 should be conducted as a multiplication and an addition separately.
4610 // For the multiplication, the result is 1 - 2^-46, which is out of the precision range for 32-bit float. (32-bit float
4611 // only have 23-bit fraction.) So it will be rounded to 1. Or 0x1.fffffc. Then the final result is 0 or -0x1p-24.
4612 // On the contrary, the result will be 2^-46, which is a normalized number perfectly representable as 32-bit float.
4613 const char constantsAndTypes[] =
4614 "%c_vec4_0 = OpConstantComposite %v4f32 %c_f32_0 %c_f32_0 %c_f32_0 %c_f32_1\n"
4615 "%c_vec4_1 = OpConstantComposite %v4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_1\n"
4616 "%c_f32_1pl2_23 = OpConstant %f32 0x1.000002p+0\n" // 1 + 2^-23
4617 "%c_f32_1mi2_23 = OpConstant %f32 0x1.fffffcp-1\n" // 1 - 2^-23
4618 "%c_f32_n1pn24 = OpConstant %f32 -0x1p-24\n"
4621 const char function[] =
4622 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
4623 "%param = OpFunctionParameter %v4f32\n"
4624 "%label = OpLabel\n"
4625 "%var1 = OpVariable %fp_f32 Function %c_f32_1pl2_23\n"
4626 "%var2 = OpVariable %fp_f32 Function\n"
4627 "%red = OpCompositeExtract %f32 %param 0\n"
4628 "%plus_red = OpFAdd %f32 %c_f32_1mi2_23 %red\n"
4629 " OpStore %var2 %plus_red\n"
4630 "%val1 = OpLoad %f32 %var1\n"
4631 "%val2 = OpLoad %f32 %var2\n"
4632 "%mul = OpFMul %f32 %val1 %val2\n"
4633 "%add = OpFAdd %f32 %mul %c_f32_n1\n"
4634 "%is0 = OpFOrdEqual %bool %add %c_f32_0\n"
4635 "%isn1n24 = OpFOrdEqual %bool %add %c_f32_n1pn24\n"
4636 "%success = OpLogicalOr %bool %is0 %isn1n24\n"
4637 "%v4success = OpCompositeConstruct %v4bool %success %success %success %success\n"
4638 "%ret = OpSelect %v4f32 %v4success %c_vec4_0 %c_vec4_1\n"
4639 " OpReturnValue %ret\n"
4642 struct CaseNameDecoration
4649 CaseNameDecoration tests[] = {
4650 {"multiplication", "OpDecorate %mul NoContraction"},
4651 {"addition", "OpDecorate %add NoContraction"},
4652 {"both", "OpDecorate %mul NoContraction\nOpDecorate %add NoContraction"},
4655 getHalfColorsFullAlpha(inputColors);
4657 for (deUint8 idx = 0; idx < 4; ++idx)
4659 inputColors[idx].setRed(0);
4660 outputColors[idx] = RGBA(0, 0, 0, 255);
4663 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(CaseNameDecoration); ++testNdx)
4665 map<string, string> fragments;
4667 fragments["decoration"] = tests[testNdx].decoration;
4668 fragments["pre_main"] = constantsAndTypes;
4669 fragments["testfun"] = function;
4671 createTestsForAllStages(tests[testNdx].name, inputColors, outputColors, fragments, group.get());
4674 return group.release();
4677 tcu::TestCaseGroup* createMemoryAccessTests(tcu::TestContext& testCtx)
4679 de::MovePtr<tcu::TestCaseGroup> memoryAccessTests (new tcu::TestCaseGroup(testCtx, "opmemoryaccess", "Memory Semantics"));
4682 const char constantsAndTypes[] =
4683 "%c_a2f32_1 = OpConstantComposite %a2f32 %c_f32_1 %c_f32_1\n"
4684 "%fp_a2f32 = OpTypePointer Function %a2f32\n"
4685 "%stype = OpTypeStruct %v4f32 %a2f32 %f32\n"
4686 "%fp_stype = OpTypePointer Function %stype\n";
4688 const char function[] =
4689 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
4690 "%param1 = OpFunctionParameter %v4f32\n"
4692 "%v1 = OpVariable %fp_v4f32 Function\n"
4693 "%v2 = OpVariable %fp_a2f32 Function\n"
4694 "%v3 = OpVariable %fp_f32 Function\n"
4695 "%v = OpVariable %fp_stype Function\n"
4696 "%vv = OpVariable %fp_stype Function\n"
4697 "%vvv = OpVariable %fp_f32 Function\n"
4699 " OpStore %v1 %c_v4f32_1_1_1_1\n"
4700 " OpStore %v2 %c_a2f32_1\n"
4701 " OpStore %v3 %c_f32_1\n"
4703 "%p_v4f32 = OpAccessChain %fp_v4f32 %v %c_u32_0\n"
4704 "%p_a2f32 = OpAccessChain %fp_a2f32 %v %c_u32_1\n"
4705 "%p_f32 = OpAccessChain %fp_f32 %v %c_u32_2\n"
4706 "%v1_v = OpLoad %v4f32 %v1 ${access_type}\n"
4707 "%v2_v = OpLoad %a2f32 %v2 ${access_type}\n"
4708 "%v3_v = OpLoad %f32 %v3 ${access_type}\n"
4710 " OpStore %p_v4f32 %v1_v ${access_type}\n"
4711 " OpStore %p_a2f32 %v2_v ${access_type}\n"
4712 " OpStore %p_f32 %v3_v ${access_type}\n"
4714 " OpCopyMemory %vv %v ${access_type}\n"
4715 " OpCopyMemory %vvv %p_f32 ${access_type}\n"
4717 "%p_f32_2 = OpAccessChain %fp_f32 %vv %c_u32_2\n"
4718 "%v_f32_2 = OpLoad %f32 %p_f32_2\n"
4719 "%v_f32_3 = OpLoad %f32 %vvv\n"
4721 "%ret1 = OpVectorTimesScalar %v4f32 %param1 %v_f32_2\n"
4722 "%ret2 = OpVectorTimesScalar %v4f32 %ret1 %v_f32_3\n"
4723 " OpReturnValue %ret2\n"
4726 struct NameMemoryAccess
4733 NameMemoryAccess tests[] =
4736 { "volatile", "Volatile" },
4737 { "aligned", "Aligned 1" },
4738 { "volatile_aligned", "Volatile|Aligned 1" },
4739 { "nontemporal_aligned", "Nontemporal|Aligned 1" },
4740 { "volatile_nontemporal", "Volatile|Nontemporal" },
4741 { "volatile_nontermporal_aligned", "Volatile|Nontemporal|Aligned 1" },
4744 getHalfColorsFullAlpha(colors);
4746 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameMemoryAccess); ++testNdx)
4748 map<string, string> fragments;
4749 map<string, string> memoryAccess;
4750 memoryAccess["access_type"] = tests[testNdx].accessType;
4752 fragments["pre_main"] = constantsAndTypes;
4753 fragments["testfun"] = tcu::StringTemplate(function).specialize(memoryAccess);
4754 createTestsForAllStages(tests[testNdx].name, colors, colors, fragments, memoryAccessTests.get());
4756 return memoryAccessTests.release();
4758 tcu::TestCaseGroup* createOpUndefTests(tcu::TestContext& testCtx)
4760 de::MovePtr<tcu::TestCaseGroup> opUndefTests (new tcu::TestCaseGroup(testCtx, "opundef", "Test OpUndef"));
4761 RGBA defaultColors[4];
4762 map<string, string> fragments;
4763 getDefaultColors(defaultColors);
4765 // First, simple cases that don't do anything with the OpUndef result.
4766 struct NameCodePair { string name, decl, type; };
4767 const NameCodePair tests[] =
4769 {"bool", "", "%bool"},
4770 {"vec2uint32", "%type = OpTypeVector %u32 2", "%type"},
4771 {"image", "%type = OpTypeImage %f32 2D 0 0 0 1 Unknown", "%type"},
4772 {"sampler", "%type = OpTypeSampler", "%type"},
4773 {"sampledimage", "%img = OpTypeImage %f32 2D 0 0 0 1 Unknown\n" "%type = OpTypeSampledImage %img", "%type"},
4774 {"pointer", "", "%fp_i32"},
4775 {"runtimearray", "%type = OpTypeRuntimeArray %f32", "%type"},
4776 {"array", "%c_u32_100 = OpConstant %u32 100\n" "%type = OpTypeArray %i32 %c_u32_100", "%type"},
4777 {"struct", "%type = OpTypeStruct %f32 %i32 %u32", "%type"}};
4778 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameCodePair); ++testNdx)
4780 fragments["undef_type"] = tests[testNdx].type;
4781 fragments["testfun"] = StringTemplate(
4782 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
4783 "%param1 = OpFunctionParameter %v4f32\n"
4784 "%label_testfun = OpLabel\n"
4785 "%undef = OpUndef ${undef_type}\n"
4786 "OpReturnValue %param1\n"
4787 "OpFunctionEnd\n").specialize(fragments);
4788 fragments["pre_main"] = tests[testNdx].decl;
4789 createTestsForAllStages(tests[testNdx].name, defaultColors, defaultColors, fragments, opUndefTests.get());
4793 fragments["testfun"] =
4794 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
4795 "%param1 = OpFunctionParameter %v4f32\n"
4796 "%label_testfun = OpLabel\n"
4797 "%undef = OpUndef %f32\n"
4798 "%zero = OpFMul %f32 %undef %c_f32_0\n"
4799 "%is_nan = OpIsNan %bool %zero\n" //OpUndef may result in NaN which may turn %zero into Nan.
4800 "%actually_zero = OpSelect %f32 %is_nan %c_f32_0 %zero\n"
4801 "%a = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
4802 "%b = OpFAdd %f32 %a %actually_zero\n"
4803 "%ret = OpVectorInsertDynamic %v4f32 %param1 %b %c_i32_0\n"
4804 "OpReturnValue %ret\n"
4807 createTestsForAllStages("float32", defaultColors, defaultColors, fragments, opUndefTests.get());
4809 fragments["testfun"] =
4810 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
4811 "%param1 = OpFunctionParameter %v4f32\n"
4812 "%label_testfun = OpLabel\n"
4813 "%undef = OpUndef %i32\n"
4814 "%zero = OpIMul %i32 %undef %c_i32_0\n"
4815 "%a = OpVectorExtractDynamic %f32 %param1 %zero\n"
4816 "%ret = OpVectorInsertDynamic %v4f32 %param1 %a %c_i32_0\n"
4817 "OpReturnValue %ret\n"
4820 createTestsForAllStages("sint32", defaultColors, defaultColors, fragments, opUndefTests.get());
4822 fragments["testfun"] =
4823 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
4824 "%param1 = OpFunctionParameter %v4f32\n"
4825 "%label_testfun = OpLabel\n"
4826 "%undef = OpUndef %u32\n"
4827 "%zero = OpIMul %u32 %undef %c_i32_0\n"
4828 "%a = OpVectorExtractDynamic %f32 %param1 %zero\n"
4829 "%ret = OpVectorInsertDynamic %v4f32 %param1 %a %c_i32_0\n"
4830 "OpReturnValue %ret\n"
4833 createTestsForAllStages("uint32", defaultColors, defaultColors, fragments, opUndefTests.get());
4835 fragments["testfun"] =
4836 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
4837 "%param1 = OpFunctionParameter %v4f32\n"
4838 "%label_testfun = OpLabel\n"
4839 "%undef = OpUndef %v4f32\n"
4840 "%vzero = OpVectorTimesScalar %v4f32 %undef %c_f32_0\n"
4841 "%zero_0 = OpVectorExtractDynamic %f32 %vzero %c_i32_0\n"
4842 "%zero_1 = OpVectorExtractDynamic %f32 %vzero %c_i32_1\n"
4843 "%zero_2 = OpVectorExtractDynamic %f32 %vzero %c_i32_2\n"
4844 "%zero_3 = OpVectorExtractDynamic %f32 %vzero %c_i32_3\n"
4845 "%is_nan_0 = OpIsNan %bool %zero_0\n"
4846 "%is_nan_1 = OpIsNan %bool %zero_1\n"
4847 "%is_nan_2 = OpIsNan %bool %zero_2\n"
4848 "%is_nan_3 = OpIsNan %bool %zero_3\n"
4849 "%actually_zero_0 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_0\n"
4850 "%actually_zero_1 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_1\n"
4851 "%actually_zero_2 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_2\n"
4852 "%actually_zero_3 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_3\n"
4853 "%param1_0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
4854 "%param1_1 = OpVectorExtractDynamic %f32 %param1 %c_i32_1\n"
4855 "%param1_2 = OpVectorExtractDynamic %f32 %param1 %c_i32_2\n"
4856 "%param1_3 = OpVectorExtractDynamic %f32 %param1 %c_i32_3\n"
4857 "%sum_0 = OpFAdd %f32 %param1_0 %actually_zero_0\n"
4858 "%sum_1 = OpFAdd %f32 %param1_1 %actually_zero_1\n"
4859 "%sum_2 = OpFAdd %f32 %param1_2 %actually_zero_2\n"
4860 "%sum_3 = OpFAdd %f32 %param1_3 %actually_zero_3\n"
4861 "%ret3 = OpVectorInsertDynamic %v4f32 %param1 %sum_3 %c_i32_3\n"
4862 "%ret2 = OpVectorInsertDynamic %v4f32 %ret3 %sum_2 %c_i32_2\n"
4863 "%ret1 = OpVectorInsertDynamic %v4f32 %ret2 %sum_1 %c_i32_1\n"
4864 "%ret = OpVectorInsertDynamic %v4f32 %ret1 %sum_0 %c_i32_0\n"
4865 "OpReturnValue %ret\n"
4868 createTestsForAllStages("vec4float32", defaultColors, defaultColors, fragments, opUndefTests.get());
4870 fragments["pre_main"] =
4871 "%m2x2f32 = OpTypeMatrix %v2f32 2\n";
4872 fragments["testfun"] =
4873 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
4874 "%param1 = OpFunctionParameter %v4f32\n"
4875 "%label_testfun = OpLabel\n"
4876 "%undef = OpUndef %m2x2f32\n"
4877 "%mzero = OpMatrixTimesScalar %m2x2f32 %undef %c_f32_0\n"
4878 "%zero_0 = OpCompositeExtract %f32 %mzero 0 0\n"
4879 "%zero_1 = OpCompositeExtract %f32 %mzero 0 1\n"
4880 "%zero_2 = OpCompositeExtract %f32 %mzero 1 0\n"
4881 "%zero_3 = OpCompositeExtract %f32 %mzero 1 1\n"
4882 "%is_nan_0 = OpIsNan %bool %zero_0\n"
4883 "%is_nan_1 = OpIsNan %bool %zero_1\n"
4884 "%is_nan_2 = OpIsNan %bool %zero_2\n"
4885 "%is_nan_3 = OpIsNan %bool %zero_3\n"
4886 "%actually_zero_0 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_0\n"
4887 "%actually_zero_1 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_1\n"
4888 "%actually_zero_2 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_2\n"
4889 "%actually_zero_3 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_3\n"
4890 "%param1_0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
4891 "%param1_1 = OpVectorExtractDynamic %f32 %param1 %c_i32_1\n"
4892 "%param1_2 = OpVectorExtractDynamic %f32 %param1 %c_i32_2\n"
4893 "%param1_3 = OpVectorExtractDynamic %f32 %param1 %c_i32_3\n"
4894 "%sum_0 = OpFAdd %f32 %param1_0 %actually_zero_0\n"
4895 "%sum_1 = OpFAdd %f32 %param1_1 %actually_zero_1\n"
4896 "%sum_2 = OpFAdd %f32 %param1_2 %actually_zero_2\n"
4897 "%sum_3 = OpFAdd %f32 %param1_3 %actually_zero_3\n"
4898 "%ret3 = OpVectorInsertDynamic %v4f32 %param1 %sum_3 %c_i32_3\n"
4899 "%ret2 = OpVectorInsertDynamic %v4f32 %ret3 %sum_2 %c_i32_2\n"
4900 "%ret1 = OpVectorInsertDynamic %v4f32 %ret2 %sum_1 %c_i32_1\n"
4901 "%ret = OpVectorInsertDynamic %v4f32 %ret1 %sum_0 %c_i32_0\n"
4902 "OpReturnValue %ret\n"
4905 createTestsForAllStages("matrix", defaultColors, defaultColors, fragments, opUndefTests.get());
4907 return opUndefTests.release();
4910 void createOpQuantizeSingleOptionTests(tcu::TestCaseGroup* testCtx)
4912 const RGBA inputColors[4] =
4915 RGBA(0, 0, 255, 255),
4916 RGBA(0, 255, 0, 255),
4917 RGBA(0, 255, 255, 255)
4920 const RGBA expectedColors[4] =
4922 RGBA(255, 0, 0, 255),
4923 RGBA(255, 0, 0, 255),
4924 RGBA(255, 0, 0, 255),
4925 RGBA(255, 0, 0, 255)
4928 const struct SingleFP16Possibility
4931 const char* constant; // Value to assign to %test_constant.
4933 const char* condition; // Must assign to %cond an expression that evaluates to true after %c = OpQuantizeToF16(%test_constant + 0).
4939 -constructNormalizedFloat(1, 0x300000),
4940 "%cond = OpFOrdEqual %bool %c %test_constant\n"
4945 constructNormalizedFloat(7, 0x000000),
4946 "%cond = OpFOrdEqual %bool %c %test_constant\n"
4948 // SPIR-V requires that OpQuantizeToF16 flushes
4949 // any numbers that would end up denormalized in F16 to zero.
4953 std::ldexp(1.5f, -140),
4954 "%cond = OpFOrdEqual %bool %c %c_f32_0\n"
4959 -std::ldexp(1.5f, -140),
4960 "%cond = OpFOrdEqual %bool %c %c_f32_0\n"
4965 std::ldexp(1.0f, -16),
4966 "%cond = OpFOrdEqual %bool %c %c_f32_0\n"
4967 }, // too small positive
4969 "negative_too_small",
4971 -std::ldexp(1.0f, -32),
4972 "%cond = OpFOrdEqual %bool %c %c_f32_0\n"
4973 }, // too small negative
4977 -std::ldexp(1.0f, 128),
4979 "%gz = OpFOrdLessThan %bool %c %c_f32_0\n"
4980 "%inf = OpIsInf %bool %c\n"
4981 "%cond = OpLogicalAnd %bool %gz %inf\n"
4986 std::ldexp(1.0f, 128),
4988 "%gz = OpFOrdGreaterThan %bool %c %c_f32_0\n"
4989 "%inf = OpIsInf %bool %c\n"
4990 "%cond = OpLogicalAnd %bool %gz %inf\n"
4993 "round_to_negative_inf",
4995 -std::ldexp(1.0f, 32),
4997 "%gz = OpFOrdLessThan %bool %c %c_f32_0\n"
4998 "%inf = OpIsInf %bool %c\n"
4999 "%cond = OpLogicalAnd %bool %gz %inf\n"
5004 std::ldexp(1.0f, 16),
5006 "%gz = OpFOrdGreaterThan %bool %c %c_f32_0\n"
5007 "%inf = OpIsInf %bool %c\n"
5008 "%cond = OpLogicalAnd %bool %gz %inf\n"
5013 std::numeric_limits<float>::quiet_NaN(),
5015 // Test for any NaN value, as NaNs are not preserved
5016 "%direct_quant = OpQuantizeToF16 %f32 %test_constant\n"
5017 "%cond = OpIsNan %bool %direct_quant\n"
5022 std::numeric_limits<float>::quiet_NaN(),
5024 // Test for any NaN value, as NaNs are not preserved
5025 "%direct_quant = OpQuantizeToF16 %f32 %test_constant\n"
5026 "%cond = OpIsNan %bool %direct_quant\n"
5029 const char* constants =
5030 "%test_constant = OpConstant %f32 "; // The value will be test.constant.
5032 StringTemplate function (
5033 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5034 "%param1 = OpFunctionParameter %v4f32\n"
5035 "%label_testfun = OpLabel\n"
5036 "%a = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
5037 "%b = OpFAdd %f32 %test_constant %a\n"
5038 "%c = OpQuantizeToF16 %f32 %b\n"
5040 "%v4cond = OpCompositeConstruct %v4bool %cond %cond %cond %cond\n"
5041 "%retval = OpSelect %v4f32 %v4cond %c_v4f32_1_0_0_1 %param1\n"
5042 " OpReturnValue %retval\n"
5046 const char* specDecorations = "OpDecorate %test_constant SpecId 0\n";
5047 const char* specConstants =
5048 "%test_constant = OpSpecConstant %f32 0.\n"
5049 "%c = OpSpecConstantOp %f32 QuantizeToF16 %test_constant\n";
5051 StringTemplate specConstantFunction(
5052 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5053 "%param1 = OpFunctionParameter %v4f32\n"
5054 "%label_testfun = OpLabel\n"
5056 "%v4cond = OpCompositeConstruct %v4bool %cond %cond %cond %cond\n"
5057 "%retval = OpSelect %v4f32 %v4cond %c_v4f32_1_0_0_1 %param1\n"
5058 " OpReturnValue %retval\n"
5062 for (size_t idx = 0; idx < (sizeof(tests)/sizeof(tests[0])); ++idx)
5064 map<string, string> codeSpecialization;
5065 map<string, string> fragments;
5066 codeSpecialization["condition"] = tests[idx].condition;
5067 fragments["testfun"] = function.specialize(codeSpecialization);
5068 fragments["pre_main"] = string(constants) + tests[idx].constant + "\n";
5069 createTestsForAllStages(tests[idx].name, inputColors, expectedColors, fragments, testCtx);
5072 for (size_t idx = 0; idx < (sizeof(tests)/sizeof(tests[0])); ++idx)
5074 map<string, string> codeSpecialization;
5075 map<string, string> fragments;
5076 vector<deInt32> passConstants;
5077 deInt32 specConstant;
5079 codeSpecialization["condition"] = tests[idx].condition;
5080 fragments["testfun"] = specConstantFunction.specialize(codeSpecialization);
5081 fragments["decoration"] = specDecorations;
5082 fragments["pre_main"] = specConstants;
5084 memcpy(&specConstant, &tests[idx].valueAsFloat, sizeof(float));
5085 passConstants.push_back(specConstant);
5087 createTestsForAllStages(string("spec_const_") + tests[idx].name, inputColors, expectedColors, fragments, passConstants, testCtx);
5091 void createOpQuantizeTwoPossibilityTests(tcu::TestCaseGroup* testCtx)
5093 RGBA inputColors[4] = {
5095 RGBA(0, 0, 255, 255),
5096 RGBA(0, 255, 0, 255),
5097 RGBA(0, 255, 255, 255)
5100 RGBA expectedColors[4] =
5102 RGBA(255, 0, 0, 255),
5103 RGBA(255, 0, 0, 255),
5104 RGBA(255, 0, 0, 255),
5105 RGBA(255, 0, 0, 255)
5108 struct DualFP16Possibility
5113 const char* possibleOutput1;
5114 const char* possibleOutput2;
5117 "positive_round_up_or_round_down",
5119 constructNormalizedFloat(8, 0x300300),
5124 "negative_round_up_or_round_down",
5126 -constructNormalizedFloat(-7, 0x600800),
5133 constructNormalizedFloat(2, 0x01e000),
5138 "carry_to_exponent",
5140 constructNormalizedFloat(1, 0xffe000),
5145 StringTemplate constants (
5146 "%input_const = OpConstant %f32 ${input}\n"
5147 "%possible_solution1 = OpConstant %f32 ${output1}\n"
5148 "%possible_solution2 = OpConstant %f32 ${output2}\n"
5151 StringTemplate specConstants (
5152 "%input_const = OpSpecConstant %f32 0.\n"
5153 "%possible_solution1 = OpConstant %f32 ${output1}\n"
5154 "%possible_solution2 = OpConstant %f32 ${output2}\n"
5157 const char* specDecorations = "OpDecorate %input_const SpecId 0\n";
5159 const char* function =
5160 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5161 "%param1 = OpFunctionParameter %v4f32\n"
5162 "%label_testfun = OpLabel\n"
5163 "%a = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
5164 // For the purposes of this test we assume that 0.f will always get
5165 // faithfully passed through the pipeline stages.
5166 "%b = OpFAdd %f32 %input_const %a\n"
5167 "%c = OpQuantizeToF16 %f32 %b\n"
5168 "%eq_1 = OpFOrdEqual %bool %c %possible_solution1\n"
5169 "%eq_2 = OpFOrdEqual %bool %c %possible_solution2\n"
5170 "%cond = OpLogicalOr %bool %eq_1 %eq_2\n"
5171 "%v4cond = OpCompositeConstruct %v4bool %cond %cond %cond %cond\n"
5172 "%retval = OpSelect %v4f32 %v4cond %c_v4f32_1_0_0_1 %param1"
5173 " OpReturnValue %retval\n"
5176 for(size_t idx = 0; idx < (sizeof(tests)/sizeof(tests[0])); ++idx) {
5177 map<string, string> fragments;
5178 map<string, string> constantSpecialization;
5180 constantSpecialization["input"] = tests[idx].input;
5181 constantSpecialization["output1"] = tests[idx].possibleOutput1;
5182 constantSpecialization["output2"] = tests[idx].possibleOutput2;
5183 fragments["testfun"] = function;
5184 fragments["pre_main"] = constants.specialize(constantSpecialization);
5185 createTestsForAllStages(tests[idx].name, inputColors, expectedColors, fragments, testCtx);
5188 for(size_t idx = 0; idx < (sizeof(tests)/sizeof(tests[0])); ++idx) {
5189 map<string, string> fragments;
5190 map<string, string> constantSpecialization;
5191 vector<deInt32> passConstants;
5192 deInt32 specConstant;
5194 constantSpecialization["output1"] = tests[idx].possibleOutput1;
5195 constantSpecialization["output2"] = tests[idx].possibleOutput2;
5196 fragments["testfun"] = function;
5197 fragments["decoration"] = specDecorations;
5198 fragments["pre_main"] = specConstants.specialize(constantSpecialization);
5200 memcpy(&specConstant, &tests[idx].inputAsFloat, sizeof(float));
5201 passConstants.push_back(specConstant);
5203 createTestsForAllStages(string("spec_const_") + tests[idx].name, inputColors, expectedColors, fragments, passConstants, testCtx);
5207 tcu::TestCaseGroup* createOpQuantizeTests(tcu::TestContext& testCtx)
5209 de::MovePtr<tcu::TestCaseGroup> opQuantizeTests (new tcu::TestCaseGroup(testCtx, "opquantize", "Test OpQuantizeToF16"));
5210 createOpQuantizeSingleOptionTests(opQuantizeTests.get());
5211 createOpQuantizeTwoPossibilityTests(opQuantizeTests.get());
5212 return opQuantizeTests.release();
5215 struct ShaderPermutation
5217 deUint8 vertexPermutation;
5218 deUint8 geometryPermutation;
5219 deUint8 tesscPermutation;
5220 deUint8 tessePermutation;
5221 deUint8 fragmentPermutation;
5224 ShaderPermutation getShaderPermutation(deUint8 inputValue)
5226 ShaderPermutation permutation =
5228 static_cast<deUint8>(inputValue & 0x10? 1u: 0u),
5229 static_cast<deUint8>(inputValue & 0x08? 1u: 0u),
5230 static_cast<deUint8>(inputValue & 0x04? 1u: 0u),
5231 static_cast<deUint8>(inputValue & 0x02? 1u: 0u),
5232 static_cast<deUint8>(inputValue & 0x01? 1u: 0u)
5237 tcu::TestCaseGroup* createModuleTests(tcu::TestContext& testCtx)
5239 RGBA defaultColors[4];
5240 RGBA invertedColors[4];
5241 de::MovePtr<tcu::TestCaseGroup> moduleTests (new tcu::TestCaseGroup(testCtx, "module", "Multiple entry points into shaders"));
5243 const ShaderElement combinedPipeline[] =
5245 ShaderElement("module", "main", VK_SHADER_STAGE_VERTEX_BIT),
5246 ShaderElement("module", "main", VK_SHADER_STAGE_GEOMETRY_BIT),
5247 ShaderElement("module", "main", VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT),
5248 ShaderElement("module", "main", VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT),
5249 ShaderElement("module", "main", VK_SHADER_STAGE_FRAGMENT_BIT)
5252 getDefaultColors(defaultColors);
5253 getInvertedDefaultColors(invertedColors);
5254 addFunctionCaseWithPrograms<InstanceContext>(
5255 moduleTests.get(), "same_module", "", createCombinedModule, runAndVerifyDefaultPipeline,
5256 createInstanceContext(combinedPipeline, map<string, string>()));
5258 const char* numbers[] =
5263 for (deInt8 idx = 0; idx < 32; ++idx)
5265 ShaderPermutation permutation = getShaderPermutation(idx);
5266 string name = string("vert") + numbers[permutation.vertexPermutation] + "_geom" + numbers[permutation.geometryPermutation] + "_tessc" + numbers[permutation.tesscPermutation] + "_tesse" + numbers[permutation.tessePermutation] + "_frag" + numbers[permutation.fragmentPermutation];
5267 const ShaderElement pipeline[] =
5269 ShaderElement("vert", string("vert") + numbers[permutation.vertexPermutation], VK_SHADER_STAGE_VERTEX_BIT),
5270 ShaderElement("geom", string("geom") + numbers[permutation.geometryPermutation], VK_SHADER_STAGE_GEOMETRY_BIT),
5271 ShaderElement("tessc", string("tessc") + numbers[permutation.tesscPermutation], VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT),
5272 ShaderElement("tesse", string("tesse") + numbers[permutation.tessePermutation], VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT),
5273 ShaderElement("frag", string("frag") + numbers[permutation.fragmentPermutation], VK_SHADER_STAGE_FRAGMENT_BIT)
5276 // If there are an even number of swaps, then it should be no-op.
5277 // If there are an odd number, the color should be flipped.
5278 if ((permutation.vertexPermutation + permutation.geometryPermutation + permutation.tesscPermutation + permutation.tessePermutation + permutation.fragmentPermutation) % 2 == 0)
5280 addFunctionCaseWithPrograms<InstanceContext>(
5281 moduleTests.get(), name, "", createMultipleEntries, runAndVerifyDefaultPipeline,
5282 createInstanceContext(pipeline, defaultColors, defaultColors, map<string, string>()));
5286 addFunctionCaseWithPrograms<InstanceContext>(
5287 moduleTests.get(), name, "", createMultipleEntries, runAndVerifyDefaultPipeline,
5288 createInstanceContext(pipeline, defaultColors, invertedColors, map<string, string>()));
5291 return moduleTests.release();
5294 tcu::TestCaseGroup* createLoopTests(tcu::TestContext& testCtx)
5296 de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, "loop", "Looping control flow"));
5297 RGBA defaultColors[4];
5298 getDefaultColors(defaultColors);
5299 map<string, string> fragments;
5300 fragments["pre_main"] =
5301 "%c_f32_5 = OpConstant %f32 5.\n";
5303 // A loop with a single block. The Continue Target is the loop block
5304 // itself. In SPIR-V terms, the "loop construct" contains no blocks at all
5305 // -- the "continue construct" forms the entire loop.
5306 fragments["testfun"] =
5307 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5308 "%param1 = OpFunctionParameter %v4f32\n"
5310 "%entry = OpLabel\n"
5311 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
5314 ";adds and subtracts 1.0 to %val in alternate iterations\n"
5316 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %loop\n"
5317 "%delta = OpPhi %f32 %c_f32_1 %entry %minus_delta %loop\n"
5318 "%val1 = OpPhi %f32 %val0 %entry %val %loop\n"
5319 "%val = OpFAdd %f32 %val1 %delta\n"
5320 "%minus_delta = OpFSub %f32 %c_f32_0 %delta\n"
5321 "%count__ = OpISub %i32 %count %c_i32_1\n"
5322 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
5323 "OpLoopMerge %exit %loop None\n"
5324 "OpBranchConditional %again %loop %exit\n"
5327 "%result = OpVectorInsertDynamic %v4f32 %param1 %val %c_i32_0\n"
5328 "OpReturnValue %result\n"
5332 createTestsForAllStages("single_block", defaultColors, defaultColors, fragments, testGroup.get());
5334 // Body comprised of multiple basic blocks.
5335 const StringTemplate multiBlock(
5336 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5337 "%param1 = OpFunctionParameter %v4f32\n"
5339 "%entry = OpLabel\n"
5340 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
5343 ";adds and subtracts 1.0 to %val in alternate iterations\n"
5345 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %gather\n"
5346 "%delta = OpPhi %f32 %c_f32_1 %entry %delta_next %gather\n"
5347 "%val1 = OpPhi %f32 %val0 %entry %val %gather\n"
5348 // There are several possibilities for the Continue Target below. Each
5349 // will be specialized into a separate test case.
5350 "OpLoopMerge %exit ${continue_target} None\n"
5354 ";delta_next = (delta > 0) ? -1 : 1;\n"
5355 "%gt0 = OpFOrdGreaterThan %bool %delta %c_f32_0\n"
5356 "OpSelectionMerge %gather DontFlatten\n"
5357 "OpBranchConditional %gt0 %even %odd ;tells us if %count is even or odd\n"
5360 "OpBranch %gather\n"
5363 "OpBranch %gather\n"
5365 "%gather = OpLabel\n"
5366 "%delta_next = OpPhi %f32 %c_f32_n1 %even %c_f32_1 %odd\n"
5367 "%val = OpFAdd %f32 %val1 %delta\n"
5368 "%count__ = OpISub %i32 %count %c_i32_1\n"
5369 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
5370 "OpBranchConditional %again %loop %exit\n"
5373 "%result = OpVectorInsertDynamic %v4f32 %param1 %val %c_i32_0\n"
5374 "OpReturnValue %result\n"
5378 map<string, string> continue_target;
5380 // The Continue Target is the loop block itself.
5381 continue_target["continue_target"] = "%loop";
5382 fragments["testfun"] = multiBlock.specialize(continue_target);
5383 createTestsForAllStages("multi_block_continue_construct", defaultColors, defaultColors, fragments, testGroup.get());
5385 // The Continue Target is at the end of the loop.
5386 continue_target["continue_target"] = "%gather";
5387 fragments["testfun"] = multiBlock.specialize(continue_target);
5388 createTestsForAllStages("multi_block_loop_construct", defaultColors, defaultColors, fragments, testGroup.get());
5390 // A loop with continue statement.
5391 fragments["testfun"] =
5392 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5393 "%param1 = OpFunctionParameter %v4f32\n"
5395 "%entry = OpLabel\n"
5396 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
5399 ";adds 4, 3, and 1 to %val0 (skips 2)\n"
5401 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %continue\n"
5402 "%val1 = OpPhi %f32 %val0 %entry %val %continue\n"
5403 "OpLoopMerge %exit %continue None\n"
5407 ";skip if %count==2\n"
5408 "%eq2 = OpIEqual %bool %count %c_i32_2\n"
5409 "OpSelectionMerge %continue DontFlatten\n"
5410 "OpBranchConditional %eq2 %continue %body\n"
5413 "%fcount = OpConvertSToF %f32 %count\n"
5414 "%val2 = OpFAdd %f32 %val1 %fcount\n"
5415 "OpBranch %continue\n"
5417 "%continue = OpLabel\n"
5418 "%val = OpPhi %f32 %val2 %body %val1 %if\n"
5419 "%count__ = OpISub %i32 %count %c_i32_1\n"
5420 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
5421 "OpBranchConditional %again %loop %exit\n"
5424 "%same = OpFSub %f32 %val %c_f32_8\n"
5425 "%result = OpVectorInsertDynamic %v4f32 %param1 %same %c_i32_0\n"
5426 "OpReturnValue %result\n"
5428 createTestsForAllStages("continue", defaultColors, defaultColors, fragments, testGroup.get());
5430 // A loop with break.
5431 fragments["testfun"] =
5432 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5433 "%param1 = OpFunctionParameter %v4f32\n"
5435 "%entry = OpLabel\n"
5436 ";param1 components are between 0 and 1, so dot product is 4 or less\n"
5437 "%dot = OpDot %f32 %param1 %param1\n"
5438 "%div = OpFDiv %f32 %dot %c_f32_5\n"
5439 "%zero = OpConvertFToU %u32 %div\n"
5440 "%two = OpIAdd %i32 %zero %c_i32_2\n"
5441 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
5444 ";adds 4 and 3 to %val0 (exits early)\n"
5446 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %continue\n"
5447 "%val1 = OpPhi %f32 %val0 %entry %val2 %continue\n"
5448 "OpLoopMerge %exit %continue None\n"
5452 ";end loop if %count==%two\n"
5453 "%above2 = OpSGreaterThan %bool %count %two\n"
5454 "OpSelectionMerge %continue DontFlatten\n"
5455 "OpBranchConditional %above2 %body %exit\n"
5458 "%fcount = OpConvertSToF %f32 %count\n"
5459 "%val2 = OpFAdd %f32 %val1 %fcount\n"
5460 "OpBranch %continue\n"
5462 "%continue = OpLabel\n"
5463 "%count__ = OpISub %i32 %count %c_i32_1\n"
5464 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
5465 "OpBranchConditional %again %loop %exit\n"
5468 "%val_post = OpPhi %f32 %val2 %continue %val1 %if\n"
5469 "%same = OpFSub %f32 %val_post %c_f32_7\n"
5470 "%result = OpVectorInsertDynamic %v4f32 %param1 %same %c_i32_0\n"
5471 "OpReturnValue %result\n"
5473 createTestsForAllStages("break", defaultColors, defaultColors, fragments, testGroup.get());
5475 // A loop with return.
5476 fragments["testfun"] =
5477 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5478 "%param1 = OpFunctionParameter %v4f32\n"
5480 "%entry = OpLabel\n"
5481 ";param1 components are between 0 and 1, so dot product is 4 or less\n"
5482 "%dot = OpDot %f32 %param1 %param1\n"
5483 "%div = OpFDiv %f32 %dot %c_f32_5\n"
5484 "%zero = OpConvertFToU %u32 %div\n"
5485 "%two = OpIAdd %i32 %zero %c_i32_2\n"
5486 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
5489 ";returns early without modifying %param1\n"
5491 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %continue\n"
5492 "%val1 = OpPhi %f32 %val0 %entry %val2 %continue\n"
5493 "OpLoopMerge %exit %continue None\n"
5497 ";return if %count==%two\n"
5498 "%above2 = OpSGreaterThan %bool %count %two\n"
5499 "OpSelectionMerge %continue DontFlatten\n"
5500 "OpBranchConditional %above2 %body %early_exit\n"
5502 "%early_exit = OpLabel\n"
5503 "OpReturnValue %param1\n"
5506 "%fcount = OpConvertSToF %f32 %count\n"
5507 "%val2 = OpFAdd %f32 %val1 %fcount\n"
5508 "OpBranch %continue\n"
5510 "%continue = OpLabel\n"
5511 "%count__ = OpISub %i32 %count %c_i32_1\n"
5512 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
5513 "OpBranchConditional %again %loop %exit\n"
5516 ";should never get here, so return an incorrect result\n"
5517 "%result = OpVectorInsertDynamic %v4f32 %param1 %val2 %c_i32_0\n"
5518 "OpReturnValue %result\n"
5520 createTestsForAllStages("return", defaultColors, defaultColors, fragments, testGroup.get());
5522 return testGroup.release();
5525 // A collection of tests putting OpControlBarrier in places GLSL forbids but SPIR-V allows.
5526 tcu::TestCaseGroup* createBarrierTests(tcu::TestContext& testCtx)
5528 de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, "barrier", "OpControlBarrier"));
5529 map<string, string> fragments;
5531 // A barrier inside a function body.
5532 fragments["pre_main"] =
5533 "%Workgroup = OpConstant %i32 2\n"
5534 "%SequentiallyConsistent = OpConstant %i32 0x10\n";
5535 fragments["testfun"] =
5536 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5537 "%param1 = OpFunctionParameter %v4f32\n"
5538 "%label_testfun = OpLabel\n"
5539 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n"
5540 "OpReturnValue %param1\n"
5542 addTessCtrlTest(testGroup.get(), "in_function", fragments);
5544 // Common setup code for the following tests.
5545 fragments["pre_main"] =
5546 "%Workgroup = OpConstant %i32 2\n"
5547 "%SequentiallyConsistent = OpConstant %i32 0x10\n"
5548 "%c_f32_5 = OpConstant %f32 5.\n";
5549 const string setupPercentZero = // Begins %test_code function with code that sets %zero to 0u but cannot be optimized away.
5550 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5551 "%param1 = OpFunctionParameter %v4f32\n"
5552 "%entry = OpLabel\n"
5553 ";param1 components are between 0 and 1, so dot product is 4 or less\n"
5554 "%dot = OpDot %f32 %param1 %param1\n"
5555 "%div = OpFDiv %f32 %dot %c_f32_5\n"
5556 "%zero = OpConvertFToU %u32 %div\n";
5558 // Barriers inside OpSwitch branches.
5559 fragments["testfun"] =
5561 "OpSelectionMerge %switch_exit None\n"
5562 "OpSwitch %zero %switch_default 0 %case0 1 %case1 ;should always go to %case0\n"
5564 "%case1 = OpLabel\n"
5565 ";This barrier should never be executed, but its presence makes test failure more likely when there's a bug.\n"
5566 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n"
5567 "%wrong_branch_alert1 = OpVectorInsertDynamic %v4f32 %param1 %c_f32_0_5 %c_i32_0\n"
5568 "OpBranch %switch_exit\n"
5570 "%switch_default = OpLabel\n"
5571 "%wrong_branch_alert2 = OpVectorInsertDynamic %v4f32 %param1 %c_f32_0_5 %c_i32_0\n"
5572 ";This barrier should never be executed, but its presence makes test failure more likely when there's a bug.\n"
5573 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n"
5574 "OpBranch %switch_exit\n"
5576 "%case0 = OpLabel\n"
5577 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n"
5578 "OpBranch %switch_exit\n"
5580 "%switch_exit = OpLabel\n"
5581 "%ret = OpPhi %v4f32 %param1 %case0 %wrong_branch_alert1 %case1 %wrong_branch_alert2 %switch_default\n"
5582 "OpReturnValue %ret\n"
5584 addTessCtrlTest(testGroup.get(), "in_switch", fragments);
5586 // Barriers inside if-then-else.
5587 fragments["testfun"] =
5589 "%eq0 = OpIEqual %bool %zero %c_u32_0\n"
5590 "OpSelectionMerge %exit DontFlatten\n"
5591 "OpBranchConditional %eq0 %then %else\n"
5594 ";This barrier should never be executed, but its presence makes test failure more likely when there's a bug.\n"
5595 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n"
5596 "%wrong_branch_alert = OpVectorInsertDynamic %v4f32 %param1 %c_f32_0_5 %c_i32_0\n"
5600 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n"
5604 "%ret = OpPhi %v4f32 %param1 %then %wrong_branch_alert %else\n"
5605 "OpReturnValue %ret\n"
5607 addTessCtrlTest(testGroup.get(), "in_if", fragments);
5609 // A barrier after control-flow reconvergence, tempting the compiler to attempt something like this:
5610 // http://lists.llvm.org/pipermail/llvm-dev/2009-October/026317.html.
5611 fragments["testfun"] =
5613 "%thread_id = OpLoad %i32 %BP_gl_InvocationID\n"
5614 "%thread0 = OpIEqual %bool %thread_id %c_i32_0\n"
5615 "OpSelectionMerge %exit DontFlatten\n"
5616 "OpBranchConditional %thread0 %then %else\n"
5619 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
5623 "%val1 = OpVectorExtractDynamic %f32 %param1 %zero\n"
5627 "%val = OpPhi %f32 %val0 %else %val1 %then\n"
5628 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n"
5629 "%ret = OpVectorInsertDynamic %v4f32 %param1 %val %zero\n"
5630 "OpReturnValue %ret\n"
5632 addTessCtrlTest(testGroup.get(), "after_divergent_if", fragments);
5634 // A barrier inside a loop.
5635 fragments["pre_main"] =
5636 "%Workgroup = OpConstant %i32 2\n"
5637 "%SequentiallyConsistent = OpConstant %i32 0x10\n"
5638 "%c_f32_10 = OpConstant %f32 10.\n";
5639 fragments["testfun"] =
5640 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5641 "%param1 = OpFunctionParameter %v4f32\n"
5642 "%entry = OpLabel\n"
5643 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
5646 ";adds 4, 3, 2, and 1 to %val0\n"
5648 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %loop\n"
5649 "%val1 = OpPhi %f32 %val0 %entry %val %loop\n"
5650 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n"
5651 "%fcount = OpConvertSToF %f32 %count\n"
5652 "%val = OpFAdd %f32 %val1 %fcount\n"
5653 "%count__ = OpISub %i32 %count %c_i32_1\n"
5654 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
5655 "OpLoopMerge %exit %loop None\n"
5656 "OpBranchConditional %again %loop %exit\n"
5659 "%same = OpFSub %f32 %val %c_f32_10\n"
5660 "%ret = OpVectorInsertDynamic %v4f32 %param1 %same %c_i32_0\n"
5661 "OpReturnValue %ret\n"
5663 addTessCtrlTest(testGroup.get(), "in_loop", fragments);
5665 return testGroup.release();
5668 // Test for the OpFRem instruction.
5669 tcu::TestCaseGroup* createFRemTests(tcu::TestContext& testCtx)
5671 de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, "frem", "OpFRem"));
5672 map<string, string> fragments;
5673 RGBA inputColors[4];
5674 RGBA outputColors[4];
5676 fragments["pre_main"] =
5677 "%c_f32_3 = OpConstant %f32 3.0\n"
5678 "%c_f32_n3 = OpConstant %f32 -3.0\n"
5679 "%c_f32_4 = OpConstant %f32 4.0\n"
5680 "%c_f32_p75 = OpConstant %f32 0.75\n"
5681 "%c_v4f32_p75_p75_p75_p75 = OpConstantComposite %v4f32 %c_f32_p75 %c_f32_p75 %c_f32_p75 %c_f32_p75 \n"
5682 "%c_v4f32_4_4_4_4 = OpConstantComposite %v4f32 %c_f32_4 %c_f32_4 %c_f32_4 %c_f32_4\n"
5683 "%c_v4f32_3_n3_3_n3 = OpConstantComposite %v4f32 %c_f32_3 %c_f32_n3 %c_f32_3 %c_f32_n3\n";
5685 // The test does the following.
5686 // vec4 result = (param1 * 8.0) - 4.0;
5687 // return (frem(result.x,3) + 0.75, frem(result.y, -3) + 0.75, 0, 1)
5688 fragments["testfun"] =
5689 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5690 "%param1 = OpFunctionParameter %v4f32\n"
5691 "%label_testfun = OpLabel\n"
5692 "%v_times_8 = OpVectorTimesScalar %v4f32 %param1 %c_f32_8\n"
5693 "%minus_4 = OpFSub %v4f32 %v_times_8 %c_v4f32_4_4_4_4\n"
5694 "%frem = OpFRem %v4f32 %minus_4 %c_v4f32_3_n3_3_n3\n"
5695 "%added = OpFAdd %v4f32 %frem %c_v4f32_p75_p75_p75_p75\n"
5696 "%xyz_1 = OpVectorInsertDynamic %v4f32 %added %c_f32_1 %c_i32_3\n"
5697 "%xy_0_1 = OpVectorInsertDynamic %v4f32 %xyz_1 %c_f32_0 %c_i32_2\n"
5698 "OpReturnValue %xy_0_1\n"
5702 inputColors[0] = RGBA(16, 16, 0, 255);
5703 inputColors[1] = RGBA(232, 232, 0, 255);
5704 inputColors[2] = RGBA(232, 16, 0, 255);
5705 inputColors[3] = RGBA(16, 232, 0, 255);
5707 outputColors[0] = RGBA(64, 64, 0, 255);
5708 outputColors[1] = RGBA(255, 255, 0, 255);
5709 outputColors[2] = RGBA(255, 64, 0, 255);
5710 outputColors[3] = RGBA(64, 255, 0, 255);
5712 createTestsForAllStages("frem", inputColors, outputColors, fragments, testGroup.get());
5713 return testGroup.release();
5718 INTEGER_TYPE_SIGNED_16,
5719 INTEGER_TYPE_SIGNED_32,
5720 INTEGER_TYPE_SIGNED_64,
5722 INTEGER_TYPE_UNSIGNED_16,
5723 INTEGER_TYPE_UNSIGNED_32,
5724 INTEGER_TYPE_UNSIGNED_64,
5727 const string getBitWidthStr (IntegerType type)
5731 case INTEGER_TYPE_SIGNED_16:
5732 case INTEGER_TYPE_UNSIGNED_16: return "16";
5734 case INTEGER_TYPE_SIGNED_32:
5735 case INTEGER_TYPE_UNSIGNED_32: return "32";
5737 case INTEGER_TYPE_SIGNED_64:
5738 case INTEGER_TYPE_UNSIGNED_64: return "64";
5740 default: DE_ASSERT(false);
5745 const string getByteWidthStr (IntegerType type)
5749 case INTEGER_TYPE_SIGNED_16:
5750 case INTEGER_TYPE_UNSIGNED_16: return "2";
5752 case INTEGER_TYPE_SIGNED_32:
5753 case INTEGER_TYPE_UNSIGNED_32: return "4";
5755 case INTEGER_TYPE_SIGNED_64:
5756 case INTEGER_TYPE_UNSIGNED_64: return "8";
5758 default: DE_ASSERT(false);
5763 bool isSigned (IntegerType type)
5765 return (type <= INTEGER_TYPE_SIGNED_64);
5768 const string getTypeName (IntegerType type)
5770 string prefix = isSigned(type) ? "" : "u";
5771 return prefix + "int" + getBitWidthStr(type);
5774 const string getTestName (IntegerType from, IntegerType to)
5776 return getTypeName(from) + "_to_" + getTypeName(to);
5779 const string getAsmTypeDeclaration (IntegerType type)
5781 string sign = isSigned(type) ? " 1" : " 0";
5782 return "OpTypeInt " + getBitWidthStr(type) + sign;
5785 template<typename T>
5786 BufferSp getSpecializedBuffer (deInt64 number)
5788 return BufferSp(new Buffer<T>(vector<T>(1, (T)number)));
5791 BufferSp getBuffer (IntegerType type, deInt64 number)
5795 case INTEGER_TYPE_SIGNED_16: return getSpecializedBuffer<deInt16>(number);
5796 case INTEGER_TYPE_SIGNED_32: return getSpecializedBuffer<deInt32>(number);
5797 case INTEGER_TYPE_SIGNED_64: return getSpecializedBuffer<deInt64>(number);
5799 case INTEGER_TYPE_UNSIGNED_16: return getSpecializedBuffer<deUint16>(number);
5800 case INTEGER_TYPE_UNSIGNED_32: return getSpecializedBuffer<deUint32>(number);
5801 case INTEGER_TYPE_UNSIGNED_64: return getSpecializedBuffer<deUint64>(number);
5803 default: DE_ASSERT(false);
5804 return BufferSp(new Buffer<deInt32>(vector<deInt32>(1, 0)));
5808 bool usesInt16 (IntegerType from, IntegerType to)
5810 return (from == INTEGER_TYPE_SIGNED_16 || from == INTEGER_TYPE_UNSIGNED_16
5811 || to == INTEGER_TYPE_SIGNED_16 || to == INTEGER_TYPE_UNSIGNED_16);
5814 bool usesInt64 (IntegerType from, IntegerType to)
5816 return (from == INTEGER_TYPE_SIGNED_64 || from == INTEGER_TYPE_UNSIGNED_64
5817 || to == INTEGER_TYPE_SIGNED_64 || to == INTEGER_TYPE_UNSIGNED_64);
5820 ComputeTestFeatures getConversionUsedFeatures (IntegerType from, IntegerType to)
5822 if (usesInt16(from, to))
5824 if (usesInt64(from, to))
5826 return COMPUTE_TEST_USES_INT16_INT64;
5830 return COMPUTE_TEST_USES_INT16;
5835 return COMPUTE_TEST_USES_INT64;
5841 ConvertCase (IntegerType from, IntegerType to, deInt64 number)
5844 , m_features (getConversionUsedFeatures(from, to))
5845 , m_name (getTestName(from, to))
5846 , m_inputBuffer (getBuffer(from, number))
5847 , m_outputBuffer (getBuffer(to, number))
5849 m_asmTypes["inputType"] = getAsmTypeDeclaration(from);
5850 m_asmTypes["outputType"] = getAsmTypeDeclaration(to);
5852 if (m_features == COMPUTE_TEST_USES_INT16)
5854 m_asmTypes["int_capabilities"] = "OpCapability Int16\n";
5856 else if (m_features == COMPUTE_TEST_USES_INT64)
5858 m_asmTypes["int_capabilities"] = "OpCapability Int64\n";
5860 else if (m_features == COMPUTE_TEST_USES_INT16_INT64)
5862 m_asmTypes["int_capabilities"] = string("OpCapability Int16\n") +
5863 "OpCapability Int64\n";
5871 IntegerType m_fromType;
5872 IntegerType m_toType;
5873 ComputeTestFeatures m_features;
5875 map<string, string> m_asmTypes;
5876 BufferSp m_inputBuffer;
5877 BufferSp m_outputBuffer;
5880 const string getConvertCaseShaderStr (const string& instruction, const ConvertCase& convertCase)
5882 map<string, string> params = convertCase.m_asmTypes;
5884 params["instruction"] = instruction;
5886 params["inDecorator"] = getByteWidthStr(convertCase.m_fromType);
5887 params["outDecorator"] = getByteWidthStr(convertCase.m_toType);
5889 const StringTemplate shader (
5890 "OpCapability Shader\n"
5891 "${int_capabilities}"
5892 "OpMemoryModel Logical GLSL450\n"
5893 "OpEntryPoint GLCompute %main \"main\" %id\n"
5894 "OpExecutionMode %main LocalSize 1 1 1\n"
5895 "OpSource GLSL 430\n"
5896 "OpName %main \"main\"\n"
5897 "OpName %id \"gl_GlobalInvocationID\"\n"
5899 "OpDecorate %id BuiltIn GlobalInvocationId\n"
5900 "OpDecorate %indata DescriptorSet 0\n"
5901 "OpDecorate %indata Binding 0\n"
5902 "OpDecorate %outdata DescriptorSet 0\n"
5903 "OpDecorate %outdata Binding 1\n"
5904 "OpDecorate %in_arr ArrayStride ${inDecorator}\n"
5905 "OpDecorate %out_arr ArrayStride ${outDecorator}\n"
5906 "OpDecorate %in_buf BufferBlock\n"
5907 "OpDecorate %out_buf BufferBlock\n"
5908 "OpMemberDecorate %in_buf 0 Offset 0\n"
5909 "OpMemberDecorate %out_buf 0 Offset 0\n"
5911 "%void = OpTypeVoid\n"
5912 "%voidf = OpTypeFunction %void\n"
5913 "%u32 = OpTypeInt 32 0\n"
5914 "%i32 = OpTypeInt 32 1\n"
5915 "%uvec3 = OpTypeVector %u32 3\n"
5916 "%uvec3ptr = OpTypePointer Input %uvec3\n"
5918 "%in_type = ${inputType}\n"
5919 "%out_type = ${outputType}\n"
5921 "%in_ptr = OpTypePointer Uniform %in_type\n"
5922 "%out_ptr = OpTypePointer Uniform %out_type\n"
5923 "%in_arr = OpTypeRuntimeArray %in_type\n"
5924 "%out_arr = OpTypeRuntimeArray %out_type\n"
5925 "%in_buf = OpTypeStruct %in_arr\n"
5926 "%out_buf = OpTypeStruct %out_arr\n"
5927 "%in_bufptr = OpTypePointer Uniform %in_buf\n"
5928 "%out_bufptr = OpTypePointer Uniform %out_buf\n"
5929 "%indata = OpVariable %in_bufptr Uniform\n"
5930 "%outdata = OpVariable %out_bufptr Uniform\n"
5931 "%inputptr = OpTypePointer Input %in_type\n"
5932 "%id = OpVariable %uvec3ptr Input\n"
5934 "%zero = OpConstant %i32 0\n"
5936 "%main = OpFunction %void None %voidf\n"
5937 "%label = OpLabel\n"
5938 "%idval = OpLoad %uvec3 %id\n"
5939 "%x = OpCompositeExtract %u32 %idval 0\n"
5940 "%inloc = OpAccessChain %in_ptr %indata %zero %x\n"
5941 "%outloc = OpAccessChain %out_ptr %outdata %zero %x\n"
5942 "%inval = OpLoad %in_type %inloc\n"
5943 "%conv = ${instruction} %out_type %inval\n"
5944 " OpStore %outloc %conv\n"
5949 return shader.specialize(params);
5952 void createSConvertCases (vector<ConvertCase>& testCases)
5954 // Convert int to int
5955 testCases.push_back(ConvertCase(INTEGER_TYPE_SIGNED_16, INTEGER_TYPE_SIGNED_32, 14669));
5956 testCases.push_back(ConvertCase(INTEGER_TYPE_SIGNED_16, INTEGER_TYPE_SIGNED_64, 3341));
5958 testCases.push_back(ConvertCase(INTEGER_TYPE_SIGNED_32, INTEGER_TYPE_SIGNED_64, 973610259));
5960 // Convert int to unsigned int
5961 testCases.push_back(ConvertCase(INTEGER_TYPE_SIGNED_16, INTEGER_TYPE_UNSIGNED_32, 9288));
5962 testCases.push_back(ConvertCase(INTEGER_TYPE_SIGNED_16, INTEGER_TYPE_UNSIGNED_64, 15460));
5964 testCases.push_back(ConvertCase(INTEGER_TYPE_SIGNED_32, INTEGER_TYPE_UNSIGNED_64, 346213461));
5967 // Test for the OpSConvert instruction.
5968 tcu::TestCaseGroup* createSConvertTests (tcu::TestContext& testCtx)
5970 const string instruction ("OpSConvert");
5971 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "sconvert", "OpSConvert"));
5972 vector<ConvertCase> testCases;
5973 createSConvertCases(testCases);
5975 for (vector<ConvertCase>::const_iterator test = testCases.begin(); test != testCases.end(); ++test)
5977 ComputeShaderSpec spec;
5979 spec.assembly = getConvertCaseShaderStr(instruction, *test);
5980 spec.inputs.push_back(test->m_inputBuffer);
5981 spec.outputs.push_back(test->m_outputBuffer);
5982 spec.numWorkGroups = IVec3(1, 1, 1);
5984 group->addChild(new SpvAsmComputeShaderCase(testCtx, test->m_name.c_str(), "Convert integers with OpSConvert.", spec, test->m_features));
5987 return group.release();
5990 void createUConvertCases (vector<ConvertCase>& testCases)
5992 // Convert unsigned int to unsigned int
5993 testCases.push_back(ConvertCase(INTEGER_TYPE_UNSIGNED_16, INTEGER_TYPE_UNSIGNED_32, 60653));
5994 testCases.push_back(ConvertCase(INTEGER_TYPE_UNSIGNED_16, INTEGER_TYPE_UNSIGNED_64, 17991));
5996 testCases.push_back(ConvertCase(INTEGER_TYPE_UNSIGNED_32, INTEGER_TYPE_UNSIGNED_64, 904256275));
5998 // Convert unsigned int to int
5999 testCases.push_back(ConvertCase(INTEGER_TYPE_UNSIGNED_16, INTEGER_TYPE_SIGNED_32, 38002));
6000 testCases.push_back(ConvertCase(INTEGER_TYPE_UNSIGNED_16, INTEGER_TYPE_SIGNED_64, 64921));
6002 testCases.push_back(ConvertCase(INTEGER_TYPE_UNSIGNED_32, INTEGER_TYPE_SIGNED_64, 4294956295ll));
6005 // Test for the OpUConvert instruction.
6006 tcu::TestCaseGroup* createUConvertTests (tcu::TestContext& testCtx)
6008 const string instruction ("OpUConvert");
6009 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "uconvert", "OpUConvert"));
6010 vector<ConvertCase> testCases;
6011 createUConvertCases(testCases);
6013 for (vector<ConvertCase>::const_iterator test = testCases.begin(); test != testCases.end(); ++test)
6015 ComputeShaderSpec spec;
6017 spec.assembly = getConvertCaseShaderStr(instruction, *test);
6018 spec.inputs.push_back(test->m_inputBuffer);
6019 spec.outputs.push_back(test->m_outputBuffer);
6020 spec.numWorkGroups = IVec3(1, 1, 1);
6022 group->addChild(new SpvAsmComputeShaderCase(testCtx, test->m_name.c_str(), "Convert integers with OpUConvert.", spec, test->m_features));
6024 return group.release();
6027 const string getNumberTypeName (const NumberType type)
6029 if (type == NUMBERTYPE_INT32)
6033 else if (type == NUMBERTYPE_UINT32)
6037 else if (type == NUMBERTYPE_FLOAT32)
6048 deInt32 getInt(de::Random& rnd)
6050 return rnd.getInt(std::numeric_limits<int>::min(), std::numeric_limits<int>::max());
6053 const string repeatString (const string& str, int times)
6056 for (int i = 0; i < times; ++i)
6063 const string getRandomConstantString (const NumberType type, de::Random& rnd)
6065 if (type == NUMBERTYPE_INT32)
6067 return numberToString<deInt32>(getInt(rnd));
6069 else if (type == NUMBERTYPE_UINT32)
6071 return numberToString<deUint32>(rnd.getUint32());
6073 else if (type == NUMBERTYPE_FLOAT32)
6075 return numberToString<float>(rnd.getFloat());
6084 void createVectorCompositeCases (vector<map<string, string> >& testCases, de::Random& rnd, const NumberType type)
6086 map<string, string> params;
6089 for (int width = 2; width <= 4; ++width)
6091 string randomConst = numberToString(getInt(rnd));
6092 string widthStr = numberToString(width);
6093 int index = rnd.getInt(0, width-1);
6095 params["type"] = "vec";
6096 params["name"] = params["type"] + "_" + widthStr;
6097 params["compositeType"] = "%composite = OpTypeVector %custom " + widthStr +"\n";
6098 params["filler"] = string("%filler = OpConstant %custom ") + getRandomConstantString(type, rnd) + "\n";
6099 params["compositeConstruct"] = "%instance = OpCompositeConstruct %composite" + repeatString(" %filler", width) + "\n";
6100 params["indexes"] = numberToString(index);
6101 testCases.push_back(params);
6105 void createArrayCompositeCases (vector<map<string, string> >& testCases, de::Random& rnd, const NumberType type)
6107 const int limit = 10;
6108 map<string, string> params;
6110 for (int width = 2; width <= limit; ++width)
6112 string randomConst = numberToString(getInt(rnd));
6113 string widthStr = numberToString(width);
6114 int index = rnd.getInt(0, width-1);
6116 params["type"] = "array";
6117 params["name"] = params["type"] + "_" + widthStr;
6118 params["compositeType"] = string("%arraywidth = OpConstant %u32 " + widthStr + "\n")
6119 + "%composite = OpTypeArray %custom %arraywidth\n";
6121 params["filler"] = string("%filler = OpConstant %custom ") + getRandomConstantString(type, rnd) + "\n";
6122 params["compositeConstruct"] = "%instance = OpCompositeConstruct %composite" + repeatString(" %filler", width) + "\n";
6123 params["indexes"] = numberToString(index);
6124 testCases.push_back(params);
6128 void createStructCompositeCases (vector<map<string, string> >& testCases, de::Random& rnd, const NumberType type)
6130 const int limit = 10;
6131 map<string, string> params;
6133 for (int width = 2; width <= limit; ++width)
6135 string randomConst = numberToString(getInt(rnd));
6136 int index = rnd.getInt(0, width-1);
6138 params["type"] = "struct";
6139 params["name"] = params["type"] + "_" + numberToString(width);
6140 params["compositeType"] = "%composite = OpTypeStruct" + repeatString(" %custom", width) + "\n";
6141 params["filler"] = string("%filler = OpConstant %custom ") + getRandomConstantString(type, rnd) + "\n";
6142 params["compositeConstruct"] = "%instance = OpCompositeConstruct %composite" + repeatString(" %filler", width) + "\n";
6143 params["indexes"] = numberToString(index);
6144 testCases.push_back(params);
6148 void createMatrixCompositeCases (vector<map<string, string> >& testCases, de::Random& rnd, const NumberType type)
6150 map<string, string> params;
6153 for (int width = 2; width <= 4; ++width)
6155 string widthStr = numberToString(width);
6157 for (int column = 2 ; column <= 4; ++column)
6159 int index_0 = rnd.getInt(0, column-1);
6160 int index_1 = rnd.getInt(0, width-1);
6161 string columnStr = numberToString(column);
6163 params["type"] = "matrix";
6164 params["name"] = params["type"] + "_" + widthStr + "x" + columnStr;
6165 params["compositeType"] = string("%vectype = OpTypeVector %custom " + widthStr + "\n")
6166 + "%composite = OpTypeMatrix %vectype " + columnStr + "\n";
6168 params["filler"] = string("%filler = OpConstant %custom ") + getRandomConstantString(type, rnd) + "\n"
6169 + "%fillerVec = OpConstantComposite %vectype" + repeatString(" %filler", width) + "\n";
6171 params["compositeConstruct"] = "%instance = OpCompositeConstruct %composite" + repeatString(" %fillerVec", column) + "\n";
6172 params["indexes"] = numberToString(index_0) + " " + numberToString(index_1);
6173 testCases.push_back(params);
6178 void createCompositeCases (vector<map<string, string> >& testCases, de::Random& rnd, const NumberType type)
6180 createVectorCompositeCases(testCases, rnd, type);
6181 createArrayCompositeCases(testCases, rnd, type);
6182 createStructCompositeCases(testCases, rnd, type);
6183 // Matrix only supports float types
6184 if (type == NUMBERTYPE_FLOAT32)
6186 createMatrixCompositeCases(testCases, rnd, type);
6190 const string getAssemblyTypeDeclaration (const NumberType type)
6194 case NUMBERTYPE_INT32: return "OpTypeInt 32 1";
6195 case NUMBERTYPE_UINT32: return "OpTypeInt 32 0";
6196 case NUMBERTYPE_FLOAT32: return "OpTypeFloat 32";
6197 default: DE_ASSERT(false); return "";
6201 const string specializeCompositeInsertShaderTemplate (const NumberType type, const map<string, string>& params)
6203 map<string, string> parameters(params);
6205 parameters["typeDeclaration"] = getAssemblyTypeDeclaration(type);
6207 parameters["compositeDecorator"] = (parameters["type"] == "array") ? "OpDecorate %composite ArrayStride 4\n" : "";
6209 return StringTemplate (
6210 "OpCapability Shader\n"
6211 "OpCapability Matrix\n"
6212 "OpMemoryModel Logical GLSL450\n"
6213 "OpEntryPoint GLCompute %main \"main\" %id\n"
6214 "OpExecutionMode %main LocalSize 1 1 1\n"
6216 "OpSource GLSL 430\n"
6217 "OpName %main \"main\"\n"
6218 "OpName %id \"gl_GlobalInvocationID\"\n"
6221 "OpDecorate %id BuiltIn GlobalInvocationId\n"
6222 "OpDecorate %buf BufferBlock\n"
6223 "OpDecorate %indata DescriptorSet 0\n"
6224 "OpDecorate %indata Binding 0\n"
6225 "OpDecorate %outdata DescriptorSet 0\n"
6226 "OpDecorate %outdata Binding 1\n"
6227 "OpDecorate %customarr ArrayStride 4\n"
6228 "${compositeDecorator}"
6229 "OpMemberDecorate %buf 0 Offset 0\n"
6232 "%void = OpTypeVoid\n"
6233 "%voidf = OpTypeFunction %void\n"
6234 "%u32 = OpTypeInt 32 0\n"
6235 "%i32 = OpTypeInt 32 1\n"
6236 "%uvec3 = OpTypeVector %u32 3\n"
6237 "%uvec3ptr = OpTypePointer Input %uvec3\n"
6240 "%custom = ${typeDeclaration}\n"
6246 // Inherited from custom
6247 "%customptr = OpTypePointer Uniform %custom\n"
6248 "%customarr = OpTypeRuntimeArray %custom\n"
6249 "%buf = OpTypeStruct %customarr\n"
6250 "%bufptr = OpTypePointer Uniform %buf\n"
6252 "%indata = OpVariable %bufptr Uniform\n"
6253 "%outdata = OpVariable %bufptr Uniform\n"
6255 "%id = OpVariable %uvec3ptr Input\n"
6256 "%zero = OpConstant %i32 0\n"
6258 "%main = OpFunction %void None %voidf\n"
6259 "%label = OpLabel\n"
6260 "%idval = OpLoad %uvec3 %id\n"
6261 "%x = OpCompositeExtract %u32 %idval 0\n"
6263 "%inloc = OpAccessChain %customptr %indata %zero %x\n"
6264 "%outloc = OpAccessChain %customptr %outdata %zero %x\n"
6265 // Read the input value
6266 "%inval = OpLoad %custom %inloc\n"
6267 // Create the composite and fill it
6268 "${compositeConstruct}"
6269 // Insert the input value to a place
6270 "%instance2 = OpCompositeInsert %composite %inval %instance ${indexes}\n"
6271 // Read back the value from the position
6272 "%out_val = OpCompositeExtract %custom %instance2 ${indexes}\n"
6273 // Store it in the output position
6274 " OpStore %outloc %out_val\n"
6277 ).specialize(parameters);
6280 template<typename T>
6281 BufferSp createCompositeBuffer(T number)
6283 return BufferSp(new Buffer<T>(vector<T>(1, number)));
6286 tcu::TestCaseGroup* createOpCompositeInsertGroup (tcu::TestContext& testCtx)
6288 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opcompositeinsert", "Test the OpCompositeInsert instruction"));
6289 de::Random rnd (deStringHash(group->getName()));
6291 for (int type = NUMBERTYPE_INT32; type != NUMBERTYPE_END32; ++type)
6293 NumberType numberType = NumberType(type);
6294 const string typeName = getNumberTypeName(numberType);
6295 const string description = "Test the OpCompositeInsert instruction with " + typeName + "s";
6296 de::MovePtr<tcu::TestCaseGroup> subGroup (new tcu::TestCaseGroup(testCtx, typeName.c_str(), description.c_str()));
6297 vector<map<string, string> > testCases;
6299 createCompositeCases(testCases, rnd, numberType);
6301 for (vector<map<string, string> >::const_iterator test = testCases.begin(); test != testCases.end(); ++test)
6303 ComputeShaderSpec spec;
6305 spec.assembly = specializeCompositeInsertShaderTemplate(numberType, *test);
6309 case NUMBERTYPE_INT32:
6311 deInt32 number = getInt(rnd);
6312 spec.inputs.push_back(createCompositeBuffer<deInt32>(number));
6313 spec.outputs.push_back(createCompositeBuffer<deInt32>(number));
6316 case NUMBERTYPE_UINT32:
6318 deUint32 number = rnd.getUint32();
6319 spec.inputs.push_back(createCompositeBuffer<deUint32>(number));
6320 spec.outputs.push_back(createCompositeBuffer<deUint32>(number));
6323 case NUMBERTYPE_FLOAT32:
6325 float number = rnd.getFloat();
6326 spec.inputs.push_back(createCompositeBuffer<float>(number));
6327 spec.outputs.push_back(createCompositeBuffer<float>(number));
6334 spec.numWorkGroups = IVec3(1, 1, 1);
6335 subGroup->addChild(new SpvAsmComputeShaderCase(testCtx, test->at("name").c_str(), "OpCompositeInsert test", spec));
6337 group->addChild(subGroup.release());
6339 return group.release();
6342 struct AssemblyStructInfo
6344 AssemblyStructInfo (const deUint32 comp, const deUint32 idx)
6349 deUint32 components;
6353 const string specializeInBoundsShaderTemplate (const NumberType type, const AssemblyStructInfo& structInfo, const map<string, string>& params)
6355 // Create the full index string
6356 string fullIndex = numberToString(structInfo.index) + " " + params.at("indexes");
6357 // Convert it to list of indexes
6358 vector<string> indexes = de::splitString(fullIndex, ' ');
6360 map<string, string> parameters (params);
6361 parameters["typeDeclaration"] = getAssemblyTypeDeclaration(type);
6362 parameters["structType"] = repeatString(" %composite", structInfo.components);
6363 parameters["structConstruct"] = repeatString(" %instance", structInfo.components);
6364 parameters["insertIndexes"] = fullIndex;
6366 // In matrix cases the last two index is the CompositeExtract indexes
6367 const deUint32 extractIndexes = (parameters["type"] == "matrix") ? 2 : 1;
6369 // Construct the extractIndex
6370 for (vector<string>::const_iterator index = indexes.end() - extractIndexes; index != indexes.end(); ++index)
6372 parameters["extractIndexes"] += " " + *index;
6375 // Remove the last 1 or 2 element depends on matrix case or not
6376 indexes.erase(indexes.end() - extractIndexes, indexes.end());
6379 // Generate AccessChain index expressions (except for the last one, because we use ptr to the composite)
6380 for (vector<string>::const_iterator index = indexes.begin(); index != indexes.end(); ++index)
6382 string indexId = "%index_" + numberToString(id++);
6383 parameters["accessChainConstDeclaration"] += indexId + " = OpConstant %u32 " + *index + "\n";
6384 parameters["accessChainIndexes"] += " " + indexId;
6387 parameters["compositeDecorator"] = (parameters["type"] == "array") ? "OpDecorate %composite ArrayStride 4\n" : "";
6389 return StringTemplate (
6390 "OpCapability Shader\n"
6391 "OpCapability Matrix\n"
6392 "OpMemoryModel Logical GLSL450\n"
6393 "OpEntryPoint GLCompute %main \"main\" %id\n"
6394 "OpExecutionMode %main LocalSize 1 1 1\n"
6396 "OpSource GLSL 430\n"
6397 "OpName %main \"main\"\n"
6398 "OpName %id \"gl_GlobalInvocationID\"\n"
6400 "OpDecorate %id BuiltIn GlobalInvocationId\n"
6401 "OpDecorate %buf BufferBlock\n"
6402 "OpDecorate %indata DescriptorSet 0\n"
6403 "OpDecorate %indata Binding 0\n"
6404 "OpDecorate %outdata DescriptorSet 0\n"
6405 "OpDecorate %outdata Binding 1\n"
6406 "OpDecorate %customarr ArrayStride 4\n"
6407 "${compositeDecorator}"
6408 "OpMemberDecorate %buf 0 Offset 0\n"
6410 "%void = OpTypeVoid\n"
6411 "%voidf = OpTypeFunction %void\n"
6412 "%u32 = OpTypeInt 32 0\n"
6413 "%uvec3 = OpTypeVector %u32 3\n"
6414 "%uvec3ptr = OpTypePointer Input %uvec3\n"
6416 "%custom = ${typeDeclaration}\n"
6419 // Inherited from composite
6420 "%composite_p = OpTypePointer Function %composite\n"
6421 "%struct_t = OpTypeStruct${structType}\n"
6422 "%struct_p = OpTypePointer Function %struct_t\n"
6425 "${accessChainConstDeclaration}"
6426 // Inherited from custom
6427 "%customptr = OpTypePointer Uniform %custom\n"
6428 "%customarr = OpTypeRuntimeArray %custom\n"
6429 "%buf = OpTypeStruct %customarr\n"
6430 "%bufptr = OpTypePointer Uniform %buf\n"
6431 "%indata = OpVariable %bufptr Uniform\n"
6432 "%outdata = OpVariable %bufptr Uniform\n"
6434 "%id = OpVariable %uvec3ptr Input\n"
6435 "%zero = OpConstant %u32 0\n"
6436 "%main = OpFunction %void None %voidf\n"
6437 "%label = OpLabel\n"
6438 "%struct_v = OpVariable %struct_p Function\n"
6439 "%idval = OpLoad %uvec3 %id\n"
6440 "%x = OpCompositeExtract %u32 %idval 0\n"
6441 // Create the input/output type
6442 "%inloc = OpInBoundsAccessChain %customptr %indata %zero %x\n"
6443 "%outloc = OpInBoundsAccessChain %customptr %outdata %zero %x\n"
6444 // Read the input value
6445 "%inval = OpLoad %custom %inloc\n"
6446 // Create the composite and fill it
6447 "${compositeConstruct}"
6448 // Create the struct and fill it with the composite
6449 "%struct = OpCompositeConstruct %struct_t${structConstruct}\n"
6451 "%comp_obj = OpCompositeInsert %struct_t %inval %struct ${insertIndexes}\n"
6453 " OpStore %struct_v %comp_obj\n"
6454 // Get deepest possible composite pointer
6455 "%inner_ptr = OpInBoundsAccessChain %composite_p %struct_v${accessChainIndexes}\n"
6456 "%read_obj = OpLoad %composite %inner_ptr\n"
6457 // Read back the stored value
6458 "%read_val = OpCompositeExtract %custom %read_obj${extractIndexes}\n"
6459 " OpStore %outloc %read_val\n"
6461 " OpFunctionEnd\n").specialize(parameters);
6464 tcu::TestCaseGroup* createOpInBoundsAccessChainGroup (tcu::TestContext& testCtx)
6466 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opinboundsaccesschain", "Test the OpInBoundsAccessChain instruction"));
6467 de::Random rnd (deStringHash(group->getName()));
6469 for (int type = NUMBERTYPE_INT32; type != NUMBERTYPE_END32; ++type)
6471 NumberType numberType = NumberType(type);
6472 const string typeName = getNumberTypeName(numberType);
6473 const string description = "Test the OpInBoundsAccessChain instruction with " + typeName + "s";
6474 de::MovePtr<tcu::TestCaseGroup> subGroup (new tcu::TestCaseGroup(testCtx, typeName.c_str(), description.c_str()));
6476 vector<map<string, string> > testCases;
6477 createCompositeCases(testCases, rnd, numberType);
6479 for (vector<map<string, string> >::const_iterator test = testCases.begin(); test != testCases.end(); ++test)
6481 ComputeShaderSpec spec;
6483 // Number of components inside of a struct
6484 deUint32 structComponents = rnd.getInt(2, 8);
6485 // Component index value
6486 deUint32 structIndex = rnd.getInt(0, structComponents - 1);
6487 AssemblyStructInfo structInfo(structComponents, structIndex);
6489 spec.assembly = specializeInBoundsShaderTemplate(numberType, structInfo, *test);
6493 case NUMBERTYPE_INT32:
6495 deInt32 number = getInt(rnd);
6496 spec.inputs.push_back(createCompositeBuffer<deInt32>(number));
6497 spec.outputs.push_back(createCompositeBuffer<deInt32>(number));
6500 case NUMBERTYPE_UINT32:
6502 deUint32 number = rnd.getUint32();
6503 spec.inputs.push_back(createCompositeBuffer<deUint32>(number));
6504 spec.outputs.push_back(createCompositeBuffer<deUint32>(number));
6507 case NUMBERTYPE_FLOAT32:
6509 float number = rnd.getFloat();
6510 spec.inputs.push_back(createCompositeBuffer<float>(number));
6511 spec.outputs.push_back(createCompositeBuffer<float>(number));
6517 spec.numWorkGroups = IVec3(1, 1, 1);
6518 subGroup->addChild(new SpvAsmComputeShaderCase(testCtx, test->at("name").c_str(), "OpInBoundsAccessChain test", spec));
6520 group->addChild(subGroup.release());
6522 return group.release();
6525 // If the params missing, uninitialized case
6526 const string specializeDefaultOutputShaderTemplate (const NumberType type, const map<string, string>& params = map<string, string>())
6528 map<string, string> parameters(params);
6530 parameters["typeDeclaration"] = getAssemblyTypeDeclaration(type);
6532 // Declare the const value, and use it in the initializer
6533 if (params.find("constValue") != params.end())
6535 parameters["constDeclaration"] = "%const = OpConstant %in_type " + params.at("constValue") + "\n";
6536 parameters["variableInitializer"] = "%const";
6538 // Uninitialized case
6541 parameters["constDeclaration"] = "";
6542 parameters["variableInitializer"] = "";
6545 return StringTemplate(
6546 "OpCapability Shader\n"
6547 "OpMemoryModel Logical GLSL450\n"
6548 "OpEntryPoint GLCompute %main \"main\" %id\n"
6549 "OpExecutionMode %main LocalSize 1 1 1\n"
6550 "OpSource GLSL 430\n"
6551 "OpName %main \"main\"\n"
6552 "OpName %id \"gl_GlobalInvocationID\"\n"
6554 "OpDecorate %id BuiltIn GlobalInvocationId\n"
6555 "OpDecorate %indata DescriptorSet 0\n"
6556 "OpDecorate %indata Binding 0\n"
6557 "OpDecorate %outdata DescriptorSet 0\n"
6558 "OpDecorate %outdata Binding 1\n"
6559 "OpDecorate %in_arr ArrayStride 4\n"
6560 "OpDecorate %in_buf BufferBlock\n"
6561 "OpMemberDecorate %in_buf 0 Offset 0\n"
6563 "%void = OpTypeVoid\n"
6564 "%voidf = OpTypeFunction %void\n"
6565 "%u32 = OpTypeInt 32 0\n"
6566 "%i32 = OpTypeInt 32 1\n"
6567 "%uvec3 = OpTypeVector %u32 3\n"
6568 "%uvec3ptr = OpTypePointer Input %uvec3\n"
6570 "%in_type = ${typeDeclaration}\n"
6571 // "%const = OpConstant %in_type ${constValue}\n"
6572 "${constDeclaration}\n"
6574 "%in_ptr = OpTypePointer Uniform %in_type\n"
6575 "%in_arr = OpTypeRuntimeArray %in_type\n"
6576 "%in_buf = OpTypeStruct %in_arr\n"
6577 "%in_bufptr = OpTypePointer Uniform %in_buf\n"
6578 "%indata = OpVariable %in_bufptr Uniform\n"
6579 "%outdata = OpVariable %in_bufptr Uniform\n"
6580 "%id = OpVariable %uvec3ptr Input\n"
6581 "%var_ptr = OpTypePointer Function %in_type\n"
6583 "%zero = OpConstant %i32 0\n"
6585 "%main = OpFunction %void None %voidf\n"
6586 "%label = OpLabel\n"
6587 "%out_var = OpVariable %var_ptr Function ${variableInitializer}\n"
6588 "%idval = OpLoad %uvec3 %id\n"
6589 "%x = OpCompositeExtract %u32 %idval 0\n"
6590 "%inloc = OpAccessChain %in_ptr %indata %zero %x\n"
6591 "%outloc = OpAccessChain %in_ptr %outdata %zero %x\n"
6593 "%outval = OpLoad %in_type %out_var\n"
6594 " OpStore %outloc %outval\n"
6597 ).specialize(parameters);
6600 bool compareFloats (const std::vector<BufferSp>&, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs, TestLog& log)
6602 DE_ASSERT(outputAllocs.size() != 0);
6603 DE_ASSERT(outputAllocs.size() == expectedOutputs.size());
6605 // Use custom epsilon because of the float->string conversion
6606 const float epsilon = 0.00001f;
6608 for (size_t outputNdx = 0; outputNdx < outputAllocs.size(); ++outputNdx)
6611 memcpy(&expected, expectedOutputs[outputNdx]->data(), expectedOutputs[outputNdx]->getNumBytes());
6614 memcpy(&actual, outputAllocs[outputNdx]->getHostPtr(), expectedOutputs[outputNdx]->getNumBytes());
6616 // Test with epsilon
6617 if (fabs(expected - actual) > epsilon)
6619 log << TestLog::Message << "Error: The actual and expected values not matching."
6620 << " Expected: " << expected << " Actual: " << actual << " Epsilon: " << epsilon << TestLog::EndMessage;
6627 // Checks if the driver crash with uninitialized cases
6628 bool passthruVerify (const std::vector<BufferSp>&, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs, TestLog&)
6630 DE_ASSERT(outputAllocs.size() != 0);
6631 DE_ASSERT(outputAllocs.size() == expectedOutputs.size());
6633 // Copy and discard the result.
6634 for (size_t outputNdx = 0; outputNdx < outputAllocs.size(); ++outputNdx)
6636 size_t width = expectedOutputs[outputNdx]->getNumBytes();
6638 vector<char> data(width);
6639 memcpy(&data[0], outputAllocs[outputNdx]->getHostPtr(), width);
6644 tcu::TestCaseGroup* createShaderDefaultOutputGroup (tcu::TestContext& testCtx)
6646 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "shader_default_output", "Test shader default output."));
6647 de::Random rnd (deStringHash(group->getName()));
6649 for (int type = NUMBERTYPE_INT32; type != NUMBERTYPE_END32; ++type)
6651 NumberType numberType = NumberType(type);
6652 const string typeName = getNumberTypeName(numberType);
6653 const string description = "Test the OpVariable initializer with " + typeName + ".";
6654 de::MovePtr<tcu::TestCaseGroup> subGroup (new tcu::TestCaseGroup(testCtx, typeName.c_str(), description.c_str()));
6656 // 2 similar subcases (initialized and uninitialized)
6657 for (int subCase = 0; subCase < 2; ++subCase)
6659 ComputeShaderSpec spec;
6660 spec.numWorkGroups = IVec3(1, 1, 1);
6662 map<string, string> params;
6666 case NUMBERTYPE_INT32:
6668 deInt32 number = getInt(rnd);
6669 spec.inputs.push_back(createCompositeBuffer<deInt32>(number));
6670 spec.outputs.push_back(createCompositeBuffer<deInt32>(number));
6671 params["constValue"] = numberToString(number);
6674 case NUMBERTYPE_UINT32:
6676 deUint32 number = rnd.getUint32();
6677 spec.inputs.push_back(createCompositeBuffer<deUint32>(number));
6678 spec.outputs.push_back(createCompositeBuffer<deUint32>(number));
6679 params["constValue"] = numberToString(number);
6682 case NUMBERTYPE_FLOAT32:
6684 float number = rnd.getFloat();
6685 spec.inputs.push_back(createCompositeBuffer<float>(number));
6686 spec.outputs.push_back(createCompositeBuffer<float>(number));
6687 spec.verifyIO = &compareFloats;
6688 params["constValue"] = numberToString(number);
6695 // Initialized subcase
6698 spec.assembly = specializeDefaultOutputShaderTemplate(numberType, params);
6699 subGroup->addChild(new SpvAsmComputeShaderCase(testCtx, "initialized", "OpVariable initializer tests.", spec));
6701 // Uninitialized subcase
6704 spec.assembly = specializeDefaultOutputShaderTemplate(numberType);
6705 spec.verifyIO = &passthruVerify;
6706 subGroup->addChild(new SpvAsmComputeShaderCase(testCtx, "uninitialized", "OpVariable initializer tests.", spec));
6709 group->addChild(subGroup.release());
6711 return group.release();
6714 tcu::TestCaseGroup* createOpNopTests (tcu::TestContext& testCtx)
6716 de::MovePtr<tcu::TestCaseGroup> testGroup (new tcu::TestCaseGroup(testCtx, "opnop", "Test OpNop"));
6717 RGBA defaultColors[4];
6718 map<string, string> opNopFragments;
6720 getDefaultColors(defaultColors);
6722 opNopFragments["testfun"] =
6723 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6724 "%param1 = OpFunctionParameter %v4f32\n"
6725 "%label_testfun = OpLabel\n"
6734 "%a = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
6735 "%b = OpFAdd %f32 %a %a\n"
6737 "%c = OpFSub %f32 %b %a\n"
6738 "%ret = OpVectorInsertDynamic %v4f32 %param1 %c %c_i32_0\n"
6741 "OpReturnValue %ret\n"
6744 createTestsForAllStages("opnop", defaultColors, defaultColors, opNopFragments, testGroup.get());
6746 return testGroup.release();
6749 tcu::TestCaseGroup* createInstructionTests (tcu::TestContext& testCtx)
6751 de::MovePtr<tcu::TestCaseGroup> instructionTests (new tcu::TestCaseGroup(testCtx, "instruction", "Instructions with special opcodes/operands"));
6752 de::MovePtr<tcu::TestCaseGroup> computeTests (new tcu::TestCaseGroup(testCtx, "compute", "Compute Instructions with special opcodes/operands"));
6753 de::MovePtr<tcu::TestCaseGroup> graphicsTests (new tcu::TestCaseGroup(testCtx, "graphics", "Graphics Instructions with special opcodes/operands"));
6755 computeTests->addChild(createOpNopGroup(testCtx));
6756 computeTests->addChild(createOpFUnordGroup(testCtx));
6757 computeTests->addChild(createOpAtomicGroup(testCtx, false));
6758 computeTests->addChild(createOpAtomicGroup(testCtx, true)); // Using new StorageBuffer decoration
6759 computeTests->addChild(createOpLineGroup(testCtx));
6760 computeTests->addChild(createOpNoLineGroup(testCtx));
6761 computeTests->addChild(createOpConstantNullGroup(testCtx));
6762 computeTests->addChild(createOpConstantCompositeGroup(testCtx));
6763 computeTests->addChild(createOpConstantUsageGroup(testCtx));
6764 computeTests->addChild(createSpecConstantGroup(testCtx));
6765 computeTests->addChild(createOpSourceGroup(testCtx));
6766 computeTests->addChild(createOpSourceExtensionGroup(testCtx));
6767 computeTests->addChild(createDecorationGroupGroup(testCtx));
6768 computeTests->addChild(createOpPhiGroup(testCtx));
6769 computeTests->addChild(createLoopControlGroup(testCtx));
6770 computeTests->addChild(createFunctionControlGroup(testCtx));
6771 computeTests->addChild(createSelectionControlGroup(testCtx));
6772 computeTests->addChild(createBlockOrderGroup(testCtx));
6773 computeTests->addChild(createMultipleShaderGroup(testCtx));
6774 computeTests->addChild(createMemoryAccessGroup(testCtx));
6775 computeTests->addChild(createOpCopyMemoryGroup(testCtx));
6776 computeTests->addChild(createOpCopyObjectGroup(testCtx));
6777 computeTests->addChild(createNoContractionGroup(testCtx));
6778 computeTests->addChild(createOpUndefGroup(testCtx));
6779 computeTests->addChild(createOpUnreachableGroup(testCtx));
6780 computeTests ->addChild(createOpQuantizeToF16Group(testCtx));
6781 computeTests ->addChild(createOpFRemGroup(testCtx));
6782 computeTests->addChild(createSConvertTests(testCtx));
6783 computeTests->addChild(createUConvertTests(testCtx));
6784 computeTests->addChild(createOpCompositeInsertGroup(testCtx));
6785 computeTests->addChild(createOpInBoundsAccessChainGroup(testCtx));
6786 computeTests->addChild(createShaderDefaultOutputGroup(testCtx));
6787 computeTests->addChild(create16BitStorageComputeGroup(testCtx));
6788 computeTests->addChild(createVariablePointersComputeGroup(testCtx));
6789 graphicsTests->addChild(createOpNopTests(testCtx));
6790 graphicsTests->addChild(createOpSourceTests(testCtx));
6791 graphicsTests->addChild(createOpSourceContinuedTests(testCtx));
6792 graphicsTests->addChild(createOpLineTests(testCtx));
6793 graphicsTests->addChild(createOpNoLineTests(testCtx));
6794 graphicsTests->addChild(createOpConstantNullTests(testCtx));
6795 graphicsTests->addChild(createOpConstantCompositeTests(testCtx));
6796 graphicsTests->addChild(createMemoryAccessTests(testCtx));
6797 graphicsTests->addChild(createOpUndefTests(testCtx));
6798 graphicsTests->addChild(createSelectionBlockOrderTests(testCtx));
6799 graphicsTests->addChild(createModuleTests(testCtx));
6800 graphicsTests->addChild(createSwitchBlockOrderTests(testCtx));
6801 graphicsTests->addChild(createOpPhiTests(testCtx));
6802 graphicsTests->addChild(createNoContractionTests(testCtx));
6803 graphicsTests->addChild(createOpQuantizeTests(testCtx));
6804 graphicsTests->addChild(createLoopTests(testCtx));
6805 graphicsTests->addChild(createSpecConstantTests(testCtx));
6806 graphicsTests->addChild(createSpecConstantOpQuantizeToF16Group(testCtx));
6807 graphicsTests->addChild(createBarrierTests(testCtx));
6808 graphicsTests->addChild(createDecorationGroupTests(testCtx));
6809 graphicsTests->addChild(createFRemTests(testCtx));
6811 graphicsTests->addChild(create16BitStorageGraphicsGroup(testCtx));
6812 graphicsTests->addChild(createVariablePointersGraphicsGroup(testCtx));
6814 instructionTests->addChild(computeTests.release());
6815 instructionTests->addChild(graphicsTests.release());
6817 return instructionTests.release();