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"
34 #include "tcuInterval.hpp"
37 #include "vkDeviceUtil.hpp"
38 #include "vkMemUtil.hpp"
39 #include "vkPlatform.hpp"
40 #include "vkPrograms.hpp"
41 #include "vkQueryUtil.hpp"
43 #include "vkRefUtil.hpp"
44 #include "vkStrUtil.hpp"
45 #include "vkTypeUtil.hpp"
47 #include "deStringUtil.hpp"
48 #include "deUniquePtr.hpp"
50 #include "tcuStringTemplate.hpp"
52 #include "vktSpvAsmCrossStageInterfaceTests.hpp"
53 #include "vktSpvAsm8bitStorageTests.hpp"
54 #include "vktSpvAsm16bitStorageTests.hpp"
55 #include "vktSpvAsmUboMatrixPaddingTests.hpp"
56 #include "vktSpvAsmConditionalBranchTests.hpp"
57 #include "vktSpvAsmIndexingTests.hpp"
58 #include "vktSpvAsmImageSamplerTests.hpp"
59 #include "vktSpvAsmComputeShaderCase.hpp"
60 #include "vktSpvAsmComputeShaderTestUtil.hpp"
61 #include "vktSpvAsmGraphicsShaderTestUtil.hpp"
62 #include "vktSpvAsmVariablePointersTests.hpp"
63 #include "vktSpvAsmVariableInitTests.hpp"
64 #include "vktSpvAsmSpirvVersionTests.hpp"
65 #include "vktTestCaseUtil.hpp"
66 #include "vktSpvAsmLoopDepLenTests.hpp"
67 #include "vktSpvAsmLoopDepInfTests.hpp"
79 namespace SpirVAssembly
93 using tcu::TestStatus;
96 using tcu::StringTemplate;
100 static void fillRandomScalars (de::Random& rnd, T minValue, T maxValue, void* dst, int numValues, int offset = 0)
102 T* const typedPtr = (T*)dst;
103 for (int ndx = 0; ndx < numValues; ndx++)
104 typedPtr[offset + ndx] = randomScalar<T>(rnd, minValue, maxValue);
107 // Filter is a function that returns true if a value should pass, false otherwise.
108 template<typename T, typename FilterT>
109 static void fillRandomScalars (de::Random& rnd, T minValue, T maxValue, void* dst, int numValues, FilterT filter, int offset = 0)
111 T* const typedPtr = (T*)dst;
113 for (int ndx = 0; ndx < numValues; ndx++)
116 value = randomScalar<T>(rnd, minValue, maxValue);
117 while (!filter(value));
119 typedPtr[offset + ndx] = value;
123 // Gets a 64-bit integer with a more logarithmic distribution
124 deInt64 randomInt64LogDistributed (de::Random& rnd)
126 deInt64 val = rnd.getUint64();
127 val &= (1ull << rnd.getInt(1, 63)) - 1;
133 static void fillRandomInt64sLogDistributed (de::Random& rnd, vector<deInt64>& dst, int numValues)
135 for (int ndx = 0; ndx < numValues; ndx++)
136 dst[ndx] = randomInt64LogDistributed(rnd);
139 template<typename FilterT>
140 static void fillRandomInt64sLogDistributed (de::Random& rnd, vector<deInt64>& dst, int numValues, FilterT filter)
142 for (int ndx = 0; ndx < numValues; ndx++)
146 value = randomInt64LogDistributed(rnd);
147 } while (!filter(value));
152 inline bool filterNonNegative (const deInt64 value)
157 inline bool filterPositive (const deInt64 value)
162 inline bool filterNotZero (const deInt64 value)
167 static void floorAll (vector<float>& values)
169 for (size_t i = 0; i < values.size(); i++)
170 values[i] = deFloatFloor(values[i]);
173 static void floorAll (vector<Vec4>& values)
175 for (size_t i = 0; i < values.size(); i++)
176 values[i] = floor(values[i]);
184 CaseParameter (const char* case_, const string& param_) : name(case_), param(param_) {}
187 // Assembly code used for testing LocalSize, OpNop, OpConstant{Null|Composite}, Op[No]Line, OpSource[Continued], OpSourceExtension, OpUndef is based on GLSL source code:
191 // layout(std140, set = 0, binding = 0) readonly buffer Input {
194 // layout(std140, set = 0, binding = 1) writeonly buffer Output {
198 // layout (local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
201 // uint x = gl_GlobalInvocationID.x;
202 // output_data.elements[x] = -input_data.elements[x];
205 static string getAsmForLocalSizeTest(bool useLiteralLocalSize, bool useSpecConstantWorkgroupSize, IVec3 workGroupSize, deUint32 ndx)
207 std::ostringstream out;
208 out << getComputeAsmShaderPreambleWithoutLocalSize();
210 if (useLiteralLocalSize)
212 out << "OpExecutionMode %main LocalSize "
213 << workGroupSize.x() << " " << workGroupSize.y() << " " << workGroupSize.z() << "\n";
216 out << "OpSource GLSL 430\n"
217 "OpName %main \"main\"\n"
218 "OpName %id \"gl_GlobalInvocationID\"\n"
219 "OpDecorate %id BuiltIn GlobalInvocationId\n";
221 if (useSpecConstantWorkgroupSize)
223 out << "OpDecorate %spec_0 SpecId 100\n"
224 << "OpDecorate %spec_1 SpecId 101\n"
225 << "OpDecorate %spec_2 SpecId 102\n"
226 << "OpDecorate %gl_WorkGroupSize BuiltIn WorkgroupSize\n";
229 out << getComputeAsmInputOutputBufferTraits()
230 << getComputeAsmCommonTypes()
231 << getComputeAsmInputOutputBuffer()
232 << "%id = OpVariable %uvec3ptr Input\n"
233 << "%zero = OpConstant %i32 0 \n";
235 if (useSpecConstantWorkgroupSize)
237 out << "%spec_0 = OpSpecConstant %u32 "<< workGroupSize.x() << "\n"
238 << "%spec_1 = OpSpecConstant %u32 "<< workGroupSize.y() << "\n"
239 << "%spec_2 = OpSpecConstant %u32 "<< workGroupSize.z() << "\n"
240 << "%gl_WorkGroupSize = OpSpecConstantComposite %uvec3 %spec_0 %spec_1 %spec_2\n";
243 out << "%main = OpFunction %void None %voidf\n"
244 << "%label = OpLabel\n"
245 << "%idval = OpLoad %uvec3 %id\n"
246 << "%ndx = OpCompositeExtract %u32 %idval " << ndx << "\n"
248 "%inloc = OpAccessChain %f32ptr %indata %zero %ndx\n"
249 "%inval = OpLoad %f32 %inloc\n"
250 "%neg = OpFNegate %f32 %inval\n"
251 "%outloc = OpAccessChain %f32ptr %outdata %zero %ndx\n"
252 " OpStore %outloc %neg\n"
258 tcu::TestCaseGroup* createLocalSizeGroup (tcu::TestContext& testCtx)
260 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "localsize", ""));
261 ComputeShaderSpec spec;
262 de::Random rnd (deStringHash(group->getName()));
263 const deUint32 numElements = 64u;
264 vector<float> positiveFloats (numElements, 0);
265 vector<float> negativeFloats (numElements, 0);
267 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
269 for (size_t ndx = 0; ndx < numElements; ++ndx)
270 negativeFloats[ndx] = -positiveFloats[ndx];
272 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
273 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
275 spec.numWorkGroups = IVec3(numElements, 1, 1);
277 spec.assembly = getAsmForLocalSizeTest(true, false, IVec3(1, 1, 1), 0u);
278 group->addChild(new SpvAsmComputeShaderCase(testCtx, "literal_localsize", "", spec));
280 spec.assembly = getAsmForLocalSizeTest(true, true, IVec3(1, 1, 1), 0u);
281 group->addChild(new SpvAsmComputeShaderCase(testCtx, "literal_and_specid_localsize", "", spec));
283 spec.assembly = getAsmForLocalSizeTest(false, true, IVec3(1, 1, 1), 0u);
284 group->addChild(new SpvAsmComputeShaderCase(testCtx, "specid_localsize", "", spec));
286 spec.numWorkGroups = IVec3(1, 1, 1);
288 spec.assembly = getAsmForLocalSizeTest(true, false, IVec3(numElements, 1, 1), 0u);
289 group->addChild(new SpvAsmComputeShaderCase(testCtx, "literal_localsize_x", "", spec));
291 spec.assembly = getAsmForLocalSizeTest(true, true, IVec3(numElements, 1, 1), 0u);
292 group->addChild(new SpvAsmComputeShaderCase(testCtx, "literal_and_specid_localsize_x", "", spec));
294 spec.assembly = getAsmForLocalSizeTest(false, true, IVec3(numElements, 1, 1), 0u);
295 group->addChild(new SpvAsmComputeShaderCase(testCtx, "specid_localsize_x", "", spec));
297 spec.assembly = getAsmForLocalSizeTest(true, false, IVec3(1, numElements, 1), 1u);
298 group->addChild(new SpvAsmComputeShaderCase(testCtx, "literal_localsize_y", "", spec));
300 spec.assembly = getAsmForLocalSizeTest(true, true, IVec3(1, numElements, 1), 1u);
301 group->addChild(new SpvAsmComputeShaderCase(testCtx, "literal_and_specid_localsize_y", "", spec));
303 spec.assembly = getAsmForLocalSizeTest(false, true, IVec3(1, numElements, 1), 1u);
304 group->addChild(new SpvAsmComputeShaderCase(testCtx, "specid_localsize_y", "", spec));
306 spec.assembly = getAsmForLocalSizeTest(true, false, IVec3(1, 1, numElements), 2u);
307 group->addChild(new SpvAsmComputeShaderCase(testCtx, "literal_localsize_z", "", spec));
309 spec.assembly = getAsmForLocalSizeTest(true, true, IVec3(1, 1, numElements), 2u);
310 group->addChild(new SpvAsmComputeShaderCase(testCtx, "literal_and_specid_localsize_z", "", spec));
312 spec.assembly = getAsmForLocalSizeTest(false, true, IVec3(1, 1, numElements), 2u);
313 group->addChild(new SpvAsmComputeShaderCase(testCtx, "specid_localsize_z", "", spec));
315 return group.release();
318 tcu::TestCaseGroup* createOpNopGroup (tcu::TestContext& testCtx)
320 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opnop", "Test the OpNop instruction"));
321 ComputeShaderSpec spec;
322 de::Random rnd (deStringHash(group->getName()));
323 const int numElements = 100;
324 vector<float> positiveFloats (numElements, 0);
325 vector<float> negativeFloats (numElements, 0);
327 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
329 for (size_t ndx = 0; ndx < numElements; ++ndx)
330 negativeFloats[ndx] = -positiveFloats[ndx];
333 string(getComputeAsmShaderPreamble()) +
335 "OpSource GLSL 430\n"
336 "OpName %main \"main\"\n"
337 "OpName %id \"gl_GlobalInvocationID\"\n"
339 "OpDecorate %id BuiltIn GlobalInvocationId\n"
341 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes())
343 + string(getComputeAsmInputOutputBuffer()) +
345 "%id = OpVariable %uvec3ptr Input\n"
346 "%zero = OpConstant %i32 0\n"
348 "%main = OpFunction %void None %voidf\n"
350 "%idval = OpLoad %uvec3 %id\n"
351 "%x = OpCompositeExtract %u32 %idval 0\n"
353 " OpNop\n" // Inside a function body
355 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
356 "%inval = OpLoad %f32 %inloc\n"
357 "%neg = OpFNegate %f32 %inval\n"
358 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
359 " OpStore %outloc %neg\n"
362 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
363 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
364 spec.numWorkGroups = IVec3(numElements, 1, 1);
366 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "OpNop appearing at different places", spec));
368 return group.release();
371 bool compareFUnord (const std::vector<BufferSp>& inputs, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs, TestLog& log)
373 if (outputAllocs.size() != 1)
376 vector<deUint8> input1Bytes;
377 vector<deUint8> input2Bytes;
378 vector<deUint8> expectedBytes;
380 inputs[0]->getBytes(input1Bytes);
381 inputs[1]->getBytes(input2Bytes);
382 expectedOutputs[0]->getBytes(expectedBytes);
384 const deInt32* const expectedOutputAsInt = reinterpret_cast<const deInt32*>(&expectedBytes.front());
385 const deInt32* const outputAsInt = static_cast<const deInt32*>(outputAllocs[0]->getHostPtr());
386 const float* const input1AsFloat = reinterpret_cast<const float*>(&input1Bytes.front());
387 const float* const input2AsFloat = reinterpret_cast<const float*>(&input2Bytes.front());
388 bool returnValue = true;
390 for (size_t idx = 0; idx < expectedBytes.size() / sizeof(deInt32); ++idx)
392 if (outputAsInt[idx] != expectedOutputAsInt[idx])
394 log << TestLog::Message << "ERROR: Sub-case failed. inputs: " << input1AsFloat[idx] << "," << input2AsFloat[idx] << " output: " << outputAsInt[idx]<< " expected output: " << expectedOutputAsInt[idx] << TestLog::EndMessage;
401 typedef VkBool32 (*compareFuncType) (float, float);
407 compareFuncType compareFunc;
409 OpFUnordCase (const char* _name, const char* _opCode, compareFuncType _compareFunc)
412 , compareFunc (_compareFunc) {}
415 #define ADD_OPFUNORD_CASE(NAME, OPCODE, OPERATOR) \
417 struct compare_##NAME { static VkBool32 compare(float x, float y) { return (x OPERATOR y) ? VK_TRUE : VK_FALSE; } }; \
418 cases.push_back(OpFUnordCase(#NAME, OPCODE, compare_##NAME::compare)); \
419 } while (deGetFalse())
421 tcu::TestCaseGroup* createOpFUnordGroup (tcu::TestContext& testCtx)
423 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opfunord", "Test the OpFUnord* opcodes"));
424 de::Random rnd (deStringHash(group->getName()));
425 const int numElements = 100;
426 vector<OpFUnordCase> cases;
428 const StringTemplate shaderTemplate (
430 string(getComputeAsmShaderPreamble()) +
432 "OpSource GLSL 430\n"
433 "OpName %main \"main\"\n"
434 "OpName %id \"gl_GlobalInvocationID\"\n"
436 "OpDecorate %id BuiltIn GlobalInvocationId\n"
438 "OpDecorate %buf BufferBlock\n"
439 "OpDecorate %buf2 BufferBlock\n"
440 "OpDecorate %indata1 DescriptorSet 0\n"
441 "OpDecorate %indata1 Binding 0\n"
442 "OpDecorate %indata2 DescriptorSet 0\n"
443 "OpDecorate %indata2 Binding 1\n"
444 "OpDecorate %outdata DescriptorSet 0\n"
445 "OpDecorate %outdata Binding 2\n"
446 "OpDecorate %f32arr ArrayStride 4\n"
447 "OpDecorate %i32arr ArrayStride 4\n"
448 "OpMemberDecorate %buf 0 Offset 0\n"
449 "OpMemberDecorate %buf2 0 Offset 0\n"
451 + string(getComputeAsmCommonTypes()) +
453 "%buf = OpTypeStruct %f32arr\n"
454 "%bufptr = OpTypePointer Uniform %buf\n"
455 "%indata1 = OpVariable %bufptr Uniform\n"
456 "%indata2 = OpVariable %bufptr Uniform\n"
458 "%buf2 = OpTypeStruct %i32arr\n"
459 "%buf2ptr = OpTypePointer Uniform %buf2\n"
460 "%outdata = OpVariable %buf2ptr Uniform\n"
462 "%id = OpVariable %uvec3ptr Input\n"
463 "%zero = OpConstant %i32 0\n"
464 "%consti1 = OpConstant %i32 1\n"
465 "%constf1 = OpConstant %f32 1.0\n"
467 "%main = OpFunction %void None %voidf\n"
469 "%idval = OpLoad %uvec3 %id\n"
470 "%x = OpCompositeExtract %u32 %idval 0\n"
472 "%inloc1 = OpAccessChain %f32ptr %indata1 %zero %x\n"
473 "%inval1 = OpLoad %f32 %inloc1\n"
474 "%inloc2 = OpAccessChain %f32ptr %indata2 %zero %x\n"
475 "%inval2 = OpLoad %f32 %inloc2\n"
476 "%outloc = OpAccessChain %i32ptr %outdata %zero %x\n"
478 "%result = ${OPCODE} %bool %inval1 %inval2\n"
479 "%int_res = OpSelect %i32 %result %consti1 %zero\n"
480 " OpStore %outloc %int_res\n"
485 ADD_OPFUNORD_CASE(equal, "OpFUnordEqual", ==);
486 ADD_OPFUNORD_CASE(less, "OpFUnordLessThan", <);
487 ADD_OPFUNORD_CASE(lessequal, "OpFUnordLessThanEqual", <=);
488 ADD_OPFUNORD_CASE(greater, "OpFUnordGreaterThan", >);
489 ADD_OPFUNORD_CASE(greaterequal, "OpFUnordGreaterThanEqual", >=);
490 ADD_OPFUNORD_CASE(notequal, "OpFUnordNotEqual", !=);
492 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
494 map<string, string> specializations;
495 ComputeShaderSpec spec;
496 const float NaN = std::numeric_limits<float>::quiet_NaN();
497 vector<float> inputFloats1 (numElements, 0);
498 vector<float> inputFloats2 (numElements, 0);
499 vector<deInt32> expectedInts (numElements, 0);
501 specializations["OPCODE"] = cases[caseNdx].opCode;
502 spec.assembly = shaderTemplate.specialize(specializations);
504 fillRandomScalars(rnd, 1.f, 100.f, &inputFloats1[0], numElements);
505 for (size_t ndx = 0; ndx < numElements; ++ndx)
509 case 0: inputFloats2[ndx] = inputFloats1[ndx] + 1.0f; break;
510 case 1: inputFloats2[ndx] = inputFloats1[ndx] - 1.0f; break;
511 case 2: inputFloats2[ndx] = inputFloats1[ndx]; break;
512 case 3: inputFloats2[ndx] = NaN; break;
513 case 4: inputFloats2[ndx] = inputFloats1[ndx]; inputFloats1[ndx] = NaN; break;
514 case 5: inputFloats2[ndx] = NaN; inputFloats1[ndx] = NaN; break;
516 expectedInts[ndx] = tcu::Float32(inputFloats1[ndx]).isNaN() || tcu::Float32(inputFloats2[ndx]).isNaN() || cases[caseNdx].compareFunc(inputFloats1[ndx], inputFloats2[ndx]);
519 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats1)));
520 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
521 spec.outputs.push_back(BufferSp(new Int32Buffer(expectedInts)));
522 spec.numWorkGroups = IVec3(numElements, 1, 1);
523 spec.verifyIO = &compareFUnord;
524 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
527 return group.release();
533 const char* assembly;
534 const char* retValAssembly;
535 OpAtomicType opAtomic;
536 deInt32 numOutputElements;
538 OpAtomicCase(const char* _name, const char* _assembly, const char* _retValAssembly, OpAtomicType _opAtomic, deInt32 _numOutputElements)
540 , assembly (_assembly)
541 , retValAssembly (_retValAssembly)
542 , opAtomic (_opAtomic)
543 , numOutputElements (_numOutputElements) {}
546 tcu::TestCaseGroup* createOpAtomicGroup (tcu::TestContext& testCtx, bool useStorageBuffer, int numElements = 65535, bool verifyReturnValues = false)
548 std::string groupName ("opatomic");
549 if (useStorageBuffer)
550 groupName += "_storage_buffer";
551 if (verifyReturnValues)
552 groupName += "_return_values";
553 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, groupName.c_str(), "Test the OpAtomic* opcodes"));
554 vector<OpAtomicCase> cases;
556 const StringTemplate shaderTemplate (
558 string("OpCapability Shader\n") +
559 (useStorageBuffer ? "OpExtension \"SPV_KHR_storage_buffer_storage_class\"\n" : "") +
560 "OpMemoryModel Logical GLSL450\n"
561 "OpEntryPoint GLCompute %main \"main\" %id\n"
562 "OpExecutionMode %main LocalSize 1 1 1\n" +
564 "OpSource GLSL 430\n"
565 "OpName %main \"main\"\n"
566 "OpName %id \"gl_GlobalInvocationID\"\n"
568 "OpDecorate %id BuiltIn GlobalInvocationId\n"
570 "OpDecorate %buf ${BLOCK_DECORATION}\n"
571 "OpDecorate %indata DescriptorSet 0\n"
572 "OpDecorate %indata Binding 0\n"
573 "OpDecorate %i32arr ArrayStride 4\n"
574 "OpMemberDecorate %buf 0 Offset 0\n"
576 "OpDecorate %sumbuf ${BLOCK_DECORATION}\n"
577 "OpDecorate %sum DescriptorSet 0\n"
578 "OpDecorate %sum Binding 1\n"
579 "OpMemberDecorate %sumbuf 0 Coherent\n"
580 "OpMemberDecorate %sumbuf 0 Offset 0\n"
582 "${RETVAL_BUF_DECORATE}"
584 + getComputeAsmCommonTypes("${BLOCK_POINTER_TYPE}") +
586 "%buf = OpTypeStruct %i32arr\n"
587 "%bufptr = OpTypePointer ${BLOCK_POINTER_TYPE} %buf\n"
588 "%indata = OpVariable %bufptr ${BLOCK_POINTER_TYPE}\n"
590 "%sumbuf = OpTypeStruct %i32arr\n"
591 "%sumbufptr = OpTypePointer ${BLOCK_POINTER_TYPE} %sumbuf\n"
592 "%sum = OpVariable %sumbufptr ${BLOCK_POINTER_TYPE}\n"
596 "%id = OpVariable %uvec3ptr Input\n"
597 "%minusone = OpConstant %i32 -1\n"
598 "%zero = OpConstant %i32 0\n"
599 "%one = OpConstant %u32 1\n"
600 "%two = OpConstant %i32 2\n"
602 "%main = OpFunction %void None %voidf\n"
604 "%idval = OpLoad %uvec3 %id\n"
605 "%x = OpCompositeExtract %u32 %idval 0\n"
607 "%inloc = OpAccessChain %i32ptr %indata %zero %x\n"
608 "%inval = OpLoad %i32 %inloc\n"
610 "%outloc = OpAccessChain %i32ptr %sum %zero ${INDEX}\n"
617 #define ADD_OPATOMIC_CASE(NAME, ASSEMBLY, RETVAL_ASSEMBLY, OPATOMIC, NUM_OUTPUT_ELEMENTS) \
619 DE_ASSERT((NUM_OUTPUT_ELEMENTS) == 1 || (NUM_OUTPUT_ELEMENTS) == numElements); \
620 cases.push_back(OpAtomicCase(#NAME, ASSEMBLY, RETVAL_ASSEMBLY, OPATOMIC, NUM_OUTPUT_ELEMENTS)); \
621 } while (deGetFalse())
622 #define ADD_OPATOMIC_CASE_1(NAME, ASSEMBLY, RETVAL_ASSEMBLY, OPATOMIC) ADD_OPATOMIC_CASE(NAME, ASSEMBLY, RETVAL_ASSEMBLY, OPATOMIC, 1)
623 #define ADD_OPATOMIC_CASE_N(NAME, ASSEMBLY, RETVAL_ASSEMBLY, OPATOMIC) ADD_OPATOMIC_CASE(NAME, ASSEMBLY, RETVAL_ASSEMBLY, OPATOMIC, numElements)
625 ADD_OPATOMIC_CASE_1(iadd, "%retv = OpAtomicIAdd %i32 %outloc %one %zero %inval\n",
626 " OpStore %retloc %retv\n", OPATOMIC_IADD );
627 ADD_OPATOMIC_CASE_1(isub, "%retv = OpAtomicISub %i32 %outloc %one %zero %inval\n",
628 " OpStore %retloc %retv\n", OPATOMIC_ISUB );
629 ADD_OPATOMIC_CASE_1(iinc, "%retv = OpAtomicIIncrement %i32 %outloc %one %zero\n",
630 " OpStore %retloc %retv\n", OPATOMIC_IINC );
631 ADD_OPATOMIC_CASE_1(idec, "%retv = OpAtomicIDecrement %i32 %outloc %one %zero\n",
632 " OpStore %retloc %retv\n", OPATOMIC_IDEC );
633 if (!verifyReturnValues)
635 ADD_OPATOMIC_CASE_N(load, "%inval2 = OpAtomicLoad %i32 %inloc %one %zero\n"
636 " OpStore %outloc %inval2\n", "", OPATOMIC_LOAD );
637 ADD_OPATOMIC_CASE_N(store, " OpAtomicStore %outloc %one %zero %inval\n", "", OPATOMIC_STORE );
640 ADD_OPATOMIC_CASE_N(compex, "%even = OpSMod %i32 %inval %two\n"
641 " OpStore %outloc %even\n"
642 "%retv = OpAtomicCompareExchange %i32 %outloc %one %zero %zero %minusone %zero\n",
643 " OpStore %retloc %retv\n", OPATOMIC_COMPEX );
646 #undef ADD_OPATOMIC_CASE
647 #undef ADD_OPATOMIC_CASE_1
648 #undef ADD_OPATOMIC_CASE_N
650 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
652 map<string, string> specializations;
653 ComputeShaderSpec spec;
654 vector<deInt32> inputInts (numElements, 0);
655 vector<deInt32> expected (cases[caseNdx].numOutputElements, -1);
657 specializations["INDEX"] = (cases[caseNdx].numOutputElements == 1) ? "%zero" : "%x";
658 specializations["INSTRUCTION"] = cases[caseNdx].assembly;
659 specializations["BLOCK_DECORATION"] = useStorageBuffer ? "Block" : "BufferBlock";
660 specializations["BLOCK_POINTER_TYPE"] = useStorageBuffer ? "StorageBuffer" : "Uniform";
662 if (verifyReturnValues)
664 const StringTemplate blockDecoration (
666 "OpDecorate %retbuf ${BLOCK_DECORATION}\n"
667 "OpDecorate %ret DescriptorSet 0\n"
668 "OpDecorate %ret Binding 2\n"
669 "OpMemberDecorate %retbuf 0 Offset 0\n\n");
671 const StringTemplate blockDeclaration (
673 "%retbuf = OpTypeStruct %i32arr\n"
674 "%retbufptr = OpTypePointer ${BLOCK_POINTER_TYPE} %retbuf\n"
675 "%ret = OpVariable %retbufptr ${BLOCK_POINTER_TYPE}\n\n");
677 specializations["RETVAL_ASSEMBLY"] =
678 "%retloc = OpAccessChain %i32ptr %ret %zero %x\n"
679 + std::string(cases[caseNdx].retValAssembly);
681 specializations["RETVAL_BUF_DECORATE"] = blockDecoration.specialize(specializations);
682 specializations["RETVAL_BUF_DECL"] = blockDeclaration.specialize(specializations);
686 specializations["RETVAL_ASSEMBLY"] = "";
687 specializations["RETVAL_BUF_DECORATE"] = "";
688 specializations["RETVAL_BUF_DECL"] = "";
691 spec.assembly = shaderTemplate.specialize(specializations);
693 if (useStorageBuffer)
694 spec.extensions.push_back("VK_KHR_storage_buffer_storage_class");
696 spec.inputs.push_back(BufferSp(new OpAtomicBuffer(numElements, cases[caseNdx].numOutputElements, cases[caseNdx].opAtomic, BUFFERTYPE_INPUT)));
697 spec.outputs.push_back(BufferSp(new OpAtomicBuffer(numElements, cases[caseNdx].numOutputElements, cases[caseNdx].opAtomic, BUFFERTYPE_EXPECTED)));
698 if (verifyReturnValues)
699 spec.outputs.push_back(BufferSp(new OpAtomicBuffer(numElements, cases[caseNdx].numOutputElements, cases[caseNdx].opAtomic, BUFFERTYPE_ATOMIC_RET)));
700 spec.numWorkGroups = IVec3(numElements, 1, 1);
702 if (verifyReturnValues)
704 switch (cases[caseNdx].opAtomic)
707 spec.verifyIO = OpAtomicBuffer::compareWithRetvals<OPATOMIC_IADD>;
710 spec.verifyIO = OpAtomicBuffer::compareWithRetvals<OPATOMIC_ISUB>;
713 spec.verifyIO = OpAtomicBuffer::compareWithRetvals<OPATOMIC_IINC>;
716 spec.verifyIO = OpAtomicBuffer::compareWithRetvals<OPATOMIC_IDEC>;
718 case OPATOMIC_COMPEX:
719 spec.verifyIO = OpAtomicBuffer::compareWithRetvals<OPATOMIC_COMPEX>;
722 DE_FATAL("Unsupported OpAtomic type for return value verification");
725 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
728 return group.release();
731 tcu::TestCaseGroup* createOpLineGroup (tcu::TestContext& testCtx)
733 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opline", "Test the OpLine instruction"));
734 ComputeShaderSpec spec;
735 de::Random rnd (deStringHash(group->getName()));
736 const int numElements = 100;
737 vector<float> positiveFloats (numElements, 0);
738 vector<float> negativeFloats (numElements, 0);
740 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
742 for (size_t ndx = 0; ndx < numElements; ++ndx)
743 negativeFloats[ndx] = -positiveFloats[ndx];
746 string(getComputeAsmShaderPreamble()) +
748 "%fname1 = OpString \"negateInputs.comp\"\n"
749 "%fname2 = OpString \"negateInputs\"\n"
751 "OpSource GLSL 430\n"
752 "OpName %main \"main\"\n"
753 "OpName %id \"gl_GlobalInvocationID\"\n"
755 "OpDecorate %id BuiltIn GlobalInvocationId\n"
757 + string(getComputeAsmInputOutputBufferTraits()) +
759 "OpLine %fname1 0 0\n" // At the earliest possible position
761 + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
763 "OpLine %fname1 0 1\n" // Multiple OpLines in sequence
764 "OpLine %fname2 1 0\n" // Different filenames
765 "OpLine %fname1 1000 100000\n"
767 "%id = OpVariable %uvec3ptr Input\n"
768 "%zero = OpConstant %i32 0\n"
770 "OpLine %fname1 1 1\n" // Before a function
772 "%main = OpFunction %void None %voidf\n"
775 "OpLine %fname1 1 1\n" // In a function
777 "%idval = OpLoad %uvec3 %id\n"
778 "%x = OpCompositeExtract %u32 %idval 0\n"
779 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
780 "%inval = OpLoad %f32 %inloc\n"
781 "%neg = OpFNegate %f32 %inval\n"
782 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
783 " OpStore %outloc %neg\n"
786 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
787 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
788 spec.numWorkGroups = IVec3(numElements, 1, 1);
790 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "OpLine appearing at different places", spec));
792 return group.release();
795 bool veryfiBinaryShader (const ProgramBinary& binary)
797 const size_t paternCount = 3u;
798 bool paternsCheck[paternCount] =
802 const string patersns[paternCount] =
808 size_t paternNdx = 0u;
810 for (size_t ndx = 0u; ndx < binary.getSize(); ++ndx)
812 if (false == paternsCheck[paternNdx] &&
813 patersns[paternNdx][0] == static_cast<char>(binary.getBinary()[ndx]) &&
814 deMemoryEqual((const char*)&binary.getBinary()[ndx], &patersns[paternNdx][0], patersns[paternNdx].length()))
816 paternsCheck[paternNdx]= true;
818 if (paternNdx == paternCount)
823 for (size_t ndx = 0u; ndx < paternCount; ++ndx)
825 if (!paternsCheck[ndx])
832 tcu::TestCaseGroup* createOpModuleProcessedGroup (tcu::TestContext& testCtx)
834 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opmoduleprocessed", "Test the OpModuleProcessed instruction"));
835 ComputeShaderSpec spec;
836 de::Random rnd (deStringHash(group->getName()));
837 const int numElements = 10;
838 vector<float> positiveFloats (numElements, 0);
839 vector<float> negativeFloats (numElements, 0);
841 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
843 for (size_t ndx = 0; ndx < numElements; ++ndx)
844 negativeFloats[ndx] = -positiveFloats[ndx];
847 string(getComputeAsmShaderPreamble()) +
848 "%fname = OpString \"negateInputs.comp\"\n"
850 "OpSource GLSL 430\n"
851 "OpName %main \"main\"\n"
852 "OpName %id \"gl_GlobalInvocationID\"\n"
853 "OpModuleProcessed \"VULKAN CTS\"\n" //OpModuleProcessed;
854 "OpModuleProcessed \"Negative values\"\n"
855 "OpModuleProcessed \"Date: 2017/09/21\"\n"
856 "OpDecorate %id BuiltIn GlobalInvocationId\n"
858 + string(getComputeAsmInputOutputBufferTraits())
860 + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
862 "OpLine %fname 0 1\n"
864 "OpLine %fname 1000 1\n"
866 "%id = OpVariable %uvec3ptr Input\n"
867 "%zero = OpConstant %i32 0\n"
868 "%main = OpFunction %void None %voidf\n"
871 "%idval = OpLoad %uvec3 %id\n"
872 "%x = OpCompositeExtract %u32 %idval 0\n"
874 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
875 "%inval = OpLoad %f32 %inloc\n"
876 "%neg = OpFNegate %f32 %inval\n"
877 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
878 " OpStore %outloc %neg\n"
881 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
882 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
883 spec.numWorkGroups = IVec3(numElements, 1, 1);
884 spec.verifyBinary = veryfiBinaryShader;
885 spec.spirvVersion = SPIRV_VERSION_1_3;
887 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "OpModuleProcessed Tests", spec));
889 return group.release();
892 tcu::TestCaseGroup* createOpNoLineGroup (tcu::TestContext& testCtx)
894 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opnoline", "Test the OpNoLine instruction"));
895 ComputeShaderSpec spec;
896 de::Random rnd (deStringHash(group->getName()));
897 const int numElements = 100;
898 vector<float> positiveFloats (numElements, 0);
899 vector<float> negativeFloats (numElements, 0);
901 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
903 for (size_t ndx = 0; ndx < numElements; ++ndx)
904 negativeFloats[ndx] = -positiveFloats[ndx];
907 string(getComputeAsmShaderPreamble()) +
909 "%fname = OpString \"negateInputs.comp\"\n"
911 "OpSource GLSL 430\n"
912 "OpName %main \"main\"\n"
913 "OpName %id \"gl_GlobalInvocationID\"\n"
915 "OpDecorate %id BuiltIn GlobalInvocationId\n"
917 + string(getComputeAsmInputOutputBufferTraits()) +
919 "OpNoLine\n" // At the earliest possible position, without preceding OpLine
921 + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
923 "OpLine %fname 0 1\n"
924 "OpNoLine\n" // Immediately following a preceding OpLine
926 "OpLine %fname 1000 1\n"
928 "%id = OpVariable %uvec3ptr Input\n"
929 "%zero = OpConstant %i32 0\n"
931 "OpNoLine\n" // Contents after the previous OpLine
933 "%main = OpFunction %void None %voidf\n"
935 "%idval = OpLoad %uvec3 %id\n"
936 "%x = OpCompositeExtract %u32 %idval 0\n"
938 "OpNoLine\n" // Multiple OpNoLine
942 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
943 "%inval = OpLoad %f32 %inloc\n"
944 "%neg = OpFNegate %f32 %inval\n"
945 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
946 " OpStore %outloc %neg\n"
949 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
950 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
951 spec.numWorkGroups = IVec3(numElements, 1, 1);
953 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "OpNoLine appearing at different places", spec));
955 return group.release();
958 // Compare instruction for the contraction compute case.
959 // Returns true if the output is what is expected from the test case.
960 bool compareNoContractCase(const std::vector<BufferSp>&, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs, TestLog&)
962 if (outputAllocs.size() != 1)
965 // Only size is needed because we are not comparing the exact values.
966 size_t byteSize = expectedOutputs[0]->getByteSize();
968 const float* outputAsFloat = static_cast<const float*>(outputAllocs[0]->getHostPtr());
970 for(size_t i = 0; i < byteSize / sizeof(float); ++i) {
971 if (outputAsFloat[i] != 0.f &&
972 outputAsFloat[i] != -ldexp(1, -24)) {
980 tcu::TestCaseGroup* createNoContractionGroup (tcu::TestContext& testCtx)
982 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "nocontraction", "Test the NoContraction decoration"));
983 vector<CaseParameter> cases;
984 const int numElements = 100;
985 vector<float> inputFloats1 (numElements, 0);
986 vector<float> inputFloats2 (numElements, 0);
987 vector<float> outputFloats (numElements, 0);
988 const StringTemplate shaderTemplate (
989 string(getComputeAsmShaderPreamble()) +
991 "OpName %main \"main\"\n"
992 "OpName %id \"gl_GlobalInvocationID\"\n"
994 "OpDecorate %id BuiltIn GlobalInvocationId\n"
998 "OpDecorate %buf BufferBlock\n"
999 "OpDecorate %indata1 DescriptorSet 0\n"
1000 "OpDecorate %indata1 Binding 0\n"
1001 "OpDecorate %indata2 DescriptorSet 0\n"
1002 "OpDecorate %indata2 Binding 1\n"
1003 "OpDecorate %outdata DescriptorSet 0\n"
1004 "OpDecorate %outdata Binding 2\n"
1005 "OpDecorate %f32arr ArrayStride 4\n"
1006 "OpMemberDecorate %buf 0 Offset 0\n"
1008 + string(getComputeAsmCommonTypes()) +
1010 "%buf = OpTypeStruct %f32arr\n"
1011 "%bufptr = OpTypePointer Uniform %buf\n"
1012 "%indata1 = OpVariable %bufptr Uniform\n"
1013 "%indata2 = OpVariable %bufptr Uniform\n"
1014 "%outdata = OpVariable %bufptr Uniform\n"
1016 "%id = OpVariable %uvec3ptr Input\n"
1017 "%zero = OpConstant %i32 0\n"
1018 "%c_f_m1 = OpConstant %f32 -1.\n"
1020 "%main = OpFunction %void None %voidf\n"
1021 "%label = OpLabel\n"
1022 "%idval = OpLoad %uvec3 %id\n"
1023 "%x = OpCompositeExtract %u32 %idval 0\n"
1024 "%inloc1 = OpAccessChain %f32ptr %indata1 %zero %x\n"
1025 "%inval1 = OpLoad %f32 %inloc1\n"
1026 "%inloc2 = OpAccessChain %f32ptr %indata2 %zero %x\n"
1027 "%inval2 = OpLoad %f32 %inloc2\n"
1028 "%mul = OpFMul %f32 %inval1 %inval2\n"
1029 "%add = OpFAdd %f32 %mul %c_f_m1\n"
1030 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
1031 " OpStore %outloc %add\n"
1033 " OpFunctionEnd\n");
1035 cases.push_back(CaseParameter("multiplication", "OpDecorate %mul NoContraction"));
1036 cases.push_back(CaseParameter("addition", "OpDecorate %add NoContraction"));
1037 cases.push_back(CaseParameter("both", "OpDecorate %mul NoContraction\nOpDecorate %add NoContraction"));
1039 for (size_t ndx = 0; ndx < numElements; ++ndx)
1041 inputFloats1[ndx] = 1.f + std::ldexp(1.f, -23); // 1 + 2^-23.
1042 inputFloats2[ndx] = 1.f - std::ldexp(1.f, -23); // 1 - 2^-23.
1043 // Result for (1 + 2^-23) * (1 - 2^-23) - 1. With NoContraction, the multiplication will be
1044 // conducted separately and the result is rounded to 1, or 0x1.fffffcp-1
1045 // So the final result will be 0.f or 0x1p-24.
1046 // If the operation is combined into a precise fused multiply-add, then the result would be
1047 // 2^-46 (0xa8800000).
1048 outputFloats[ndx] = 0.f;
1051 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
1053 map<string, string> specializations;
1054 ComputeShaderSpec spec;
1056 specializations["DECORATION"] = cases[caseNdx].param;
1057 spec.assembly = shaderTemplate.specialize(specializations);
1058 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats1)));
1059 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
1060 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
1061 spec.numWorkGroups = IVec3(numElements, 1, 1);
1062 // Check against the two possible answers based on rounding mode.
1063 spec.verifyIO = &compareNoContractCase;
1065 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
1067 return group.release();
1070 bool compareFRem(const std::vector<BufferSp>&, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs, TestLog&)
1072 if (outputAllocs.size() != 1)
1075 vector<deUint8> expectedBytes;
1076 expectedOutputs[0]->getBytes(expectedBytes);
1078 const float* expectedOutputAsFloat = reinterpret_cast<const float*>(&expectedBytes.front());
1079 const float* outputAsFloat = static_cast<const float*>(outputAllocs[0]->getHostPtr());
1081 for (size_t idx = 0; idx < expectedBytes.size() / sizeof(float); ++idx)
1083 const float f0 = expectedOutputAsFloat[idx];
1084 const float f1 = outputAsFloat[idx];
1085 // \todo relative error needs to be fairly high because FRem may be implemented as
1086 // (roughly) frac(a/b)*b, so LSB errors can be magnified. But this should be fine for now.
1087 if (deFloatAbs((f1 - f0) / f0) > 0.02)
1094 tcu::TestCaseGroup* createOpFRemGroup (tcu::TestContext& testCtx)
1096 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opfrem", "Test the OpFRem instruction"));
1097 ComputeShaderSpec spec;
1098 de::Random rnd (deStringHash(group->getName()));
1099 const int numElements = 200;
1100 vector<float> inputFloats1 (numElements, 0);
1101 vector<float> inputFloats2 (numElements, 0);
1102 vector<float> outputFloats (numElements, 0);
1104 fillRandomScalars(rnd, -10000.f, 10000.f, &inputFloats1[0], numElements);
1105 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats2[0], numElements);
1107 for (size_t ndx = 0; ndx < numElements; ++ndx)
1109 // Guard against divisors near zero.
1110 if (std::fabs(inputFloats2[ndx]) < 1e-3)
1111 inputFloats2[ndx] = 8.f;
1113 // The return value of std::fmod() has the same sign as its first operand, which is how OpFRem spec'd.
1114 outputFloats[ndx] = std::fmod(inputFloats1[ndx], inputFloats2[ndx]);
1118 string(getComputeAsmShaderPreamble()) +
1120 "OpName %main \"main\"\n"
1121 "OpName %id \"gl_GlobalInvocationID\"\n"
1123 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1125 "OpDecorate %buf BufferBlock\n"
1126 "OpDecorate %indata1 DescriptorSet 0\n"
1127 "OpDecorate %indata1 Binding 0\n"
1128 "OpDecorate %indata2 DescriptorSet 0\n"
1129 "OpDecorate %indata2 Binding 1\n"
1130 "OpDecorate %outdata DescriptorSet 0\n"
1131 "OpDecorate %outdata Binding 2\n"
1132 "OpDecorate %f32arr ArrayStride 4\n"
1133 "OpMemberDecorate %buf 0 Offset 0\n"
1135 + string(getComputeAsmCommonTypes()) +
1137 "%buf = OpTypeStruct %f32arr\n"
1138 "%bufptr = OpTypePointer Uniform %buf\n"
1139 "%indata1 = OpVariable %bufptr Uniform\n"
1140 "%indata2 = OpVariable %bufptr Uniform\n"
1141 "%outdata = OpVariable %bufptr Uniform\n"
1143 "%id = OpVariable %uvec3ptr Input\n"
1144 "%zero = OpConstant %i32 0\n"
1146 "%main = OpFunction %void None %voidf\n"
1147 "%label = OpLabel\n"
1148 "%idval = OpLoad %uvec3 %id\n"
1149 "%x = OpCompositeExtract %u32 %idval 0\n"
1150 "%inloc1 = OpAccessChain %f32ptr %indata1 %zero %x\n"
1151 "%inval1 = OpLoad %f32 %inloc1\n"
1152 "%inloc2 = OpAccessChain %f32ptr %indata2 %zero %x\n"
1153 "%inval2 = OpLoad %f32 %inloc2\n"
1154 "%rem = OpFRem %f32 %inval1 %inval2\n"
1155 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
1156 " OpStore %outloc %rem\n"
1160 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats1)));
1161 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
1162 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
1163 spec.numWorkGroups = IVec3(numElements, 1, 1);
1164 spec.verifyIO = &compareFRem;
1166 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "", spec));
1168 return group.release();
1171 bool compareNMin (const std::vector<BufferSp>&, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs, TestLog&)
1173 if (outputAllocs.size() != 1)
1176 const BufferSp& expectedOutput (expectedOutputs[0]);
1177 std::vector<deUint8> data;
1178 expectedOutput->getBytes(data);
1180 const float* const expectedOutputAsFloat = reinterpret_cast<const float*>(&data.front());
1181 const float* const outputAsFloat = static_cast<const float*>(outputAllocs[0]->getHostPtr());
1183 for (size_t idx = 0; idx < expectedOutput->getByteSize() / sizeof(float); ++idx)
1185 const float f0 = expectedOutputAsFloat[idx];
1186 const float f1 = outputAsFloat[idx];
1188 // For NMin, we accept NaN as output if both inputs were NaN.
1189 // Otherwise the NaN is the wrong choise, as on architectures that
1190 // do not handle NaN, those are huge values.
1191 if (!(tcu::Float32(f1).isNaN() && tcu::Float32(f0).isNaN()) && deFloatAbs(f1 - f0) > 0.00001f)
1198 tcu::TestCaseGroup* createOpNMinGroup (tcu::TestContext& testCtx)
1200 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opnmin", "Test the OpNMin instruction"));
1201 ComputeShaderSpec spec;
1202 de::Random rnd (deStringHash(group->getName()));
1203 const int numElements = 200;
1204 vector<float> inputFloats1 (numElements, 0);
1205 vector<float> inputFloats2 (numElements, 0);
1206 vector<float> outputFloats (numElements, 0);
1208 fillRandomScalars(rnd, -10000.f, 10000.f, &inputFloats1[0], numElements);
1209 fillRandomScalars(rnd, -10000.f, 10000.f, &inputFloats2[0], numElements);
1211 // Make the first case a full-NAN case.
1212 inputFloats1[0] = TCU_NAN;
1213 inputFloats2[0] = TCU_NAN;
1215 for (size_t ndx = 0; ndx < numElements; ++ndx)
1217 // By default, pick the smallest
1218 outputFloats[ndx] = std::min(inputFloats1[ndx], inputFloats2[ndx]);
1220 // Make half of the cases NaN cases
1223 // Alternate between the NaN operand
1226 outputFloats[ndx] = inputFloats2[ndx];
1227 inputFloats1[ndx] = TCU_NAN;
1231 outputFloats[ndx] = inputFloats1[ndx];
1232 inputFloats2[ndx] = TCU_NAN;
1238 "OpCapability Shader\n"
1239 "%std450 = OpExtInstImport \"GLSL.std.450\"\n"
1240 "OpMemoryModel Logical GLSL450\n"
1241 "OpEntryPoint GLCompute %main \"main\" %id\n"
1242 "OpExecutionMode %main LocalSize 1 1 1\n"
1244 "OpName %main \"main\"\n"
1245 "OpName %id \"gl_GlobalInvocationID\"\n"
1247 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1249 "OpDecorate %buf BufferBlock\n"
1250 "OpDecorate %indata1 DescriptorSet 0\n"
1251 "OpDecorate %indata1 Binding 0\n"
1252 "OpDecorate %indata2 DescriptorSet 0\n"
1253 "OpDecorate %indata2 Binding 1\n"
1254 "OpDecorate %outdata DescriptorSet 0\n"
1255 "OpDecorate %outdata Binding 2\n"
1256 "OpDecorate %f32arr ArrayStride 4\n"
1257 "OpMemberDecorate %buf 0 Offset 0\n"
1259 + string(getComputeAsmCommonTypes()) +
1261 "%buf = OpTypeStruct %f32arr\n"
1262 "%bufptr = OpTypePointer Uniform %buf\n"
1263 "%indata1 = OpVariable %bufptr Uniform\n"
1264 "%indata2 = OpVariable %bufptr Uniform\n"
1265 "%outdata = OpVariable %bufptr Uniform\n"
1267 "%id = OpVariable %uvec3ptr Input\n"
1268 "%zero = OpConstant %i32 0\n"
1270 "%main = OpFunction %void None %voidf\n"
1271 "%label = OpLabel\n"
1272 "%idval = OpLoad %uvec3 %id\n"
1273 "%x = OpCompositeExtract %u32 %idval 0\n"
1274 "%inloc1 = OpAccessChain %f32ptr %indata1 %zero %x\n"
1275 "%inval1 = OpLoad %f32 %inloc1\n"
1276 "%inloc2 = OpAccessChain %f32ptr %indata2 %zero %x\n"
1277 "%inval2 = OpLoad %f32 %inloc2\n"
1278 "%rem = OpExtInst %f32 %std450 NMin %inval1 %inval2\n"
1279 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
1280 " OpStore %outloc %rem\n"
1284 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats1)));
1285 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
1286 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
1287 spec.numWorkGroups = IVec3(numElements, 1, 1);
1288 spec.verifyIO = &compareNMin;
1290 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "", spec));
1292 return group.release();
1295 bool compareNMax (const std::vector<BufferSp>&, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs, TestLog&)
1297 if (outputAllocs.size() != 1)
1300 const BufferSp& expectedOutput = expectedOutputs[0];
1301 std::vector<deUint8> data;
1302 expectedOutput->getBytes(data);
1304 const float* const expectedOutputAsFloat = reinterpret_cast<const float*>(&data.front());
1305 const float* const outputAsFloat = static_cast<const float*>(outputAllocs[0]->getHostPtr());
1307 for (size_t idx = 0; idx < expectedOutput->getByteSize() / sizeof(float); ++idx)
1309 const float f0 = expectedOutputAsFloat[idx];
1310 const float f1 = outputAsFloat[idx];
1312 // For NMax, NaN is considered acceptable result, since in
1313 // architectures that do not handle NaNs, those are huge values.
1314 if (!tcu::Float32(f1).isNaN() && deFloatAbs(f1 - f0) > 0.00001f)
1321 tcu::TestCaseGroup* createOpNMaxGroup (tcu::TestContext& testCtx)
1323 de::MovePtr<tcu::TestCaseGroup> group(new tcu::TestCaseGroup(testCtx, "opnmax", "Test the OpNMax instruction"));
1324 ComputeShaderSpec spec;
1325 de::Random rnd (deStringHash(group->getName()));
1326 const int numElements = 200;
1327 vector<float> inputFloats1 (numElements, 0);
1328 vector<float> inputFloats2 (numElements, 0);
1329 vector<float> outputFloats (numElements, 0);
1331 fillRandomScalars(rnd, -10000.f, 10000.f, &inputFloats1[0], numElements);
1332 fillRandomScalars(rnd, -10000.f, 10000.f, &inputFloats2[0], numElements);
1334 // Make the first case a full-NAN case.
1335 inputFloats1[0] = TCU_NAN;
1336 inputFloats2[0] = TCU_NAN;
1338 for (size_t ndx = 0; ndx < numElements; ++ndx)
1340 // By default, pick the biggest
1341 outputFloats[ndx] = std::max(inputFloats1[ndx], inputFloats2[ndx]);
1343 // Make half of the cases NaN cases
1346 // Alternate between the NaN operand
1349 outputFloats[ndx] = inputFloats2[ndx];
1350 inputFloats1[ndx] = TCU_NAN;
1354 outputFloats[ndx] = inputFloats1[ndx];
1355 inputFloats2[ndx] = TCU_NAN;
1361 "OpCapability Shader\n"
1362 "%std450 = OpExtInstImport \"GLSL.std.450\"\n"
1363 "OpMemoryModel Logical GLSL450\n"
1364 "OpEntryPoint GLCompute %main \"main\" %id\n"
1365 "OpExecutionMode %main LocalSize 1 1 1\n"
1367 "OpName %main \"main\"\n"
1368 "OpName %id \"gl_GlobalInvocationID\"\n"
1370 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1372 "OpDecorate %buf BufferBlock\n"
1373 "OpDecorate %indata1 DescriptorSet 0\n"
1374 "OpDecorate %indata1 Binding 0\n"
1375 "OpDecorate %indata2 DescriptorSet 0\n"
1376 "OpDecorate %indata2 Binding 1\n"
1377 "OpDecorate %outdata DescriptorSet 0\n"
1378 "OpDecorate %outdata Binding 2\n"
1379 "OpDecorate %f32arr ArrayStride 4\n"
1380 "OpMemberDecorate %buf 0 Offset 0\n"
1382 + string(getComputeAsmCommonTypes()) +
1384 "%buf = OpTypeStruct %f32arr\n"
1385 "%bufptr = OpTypePointer Uniform %buf\n"
1386 "%indata1 = OpVariable %bufptr Uniform\n"
1387 "%indata2 = OpVariable %bufptr Uniform\n"
1388 "%outdata = OpVariable %bufptr Uniform\n"
1390 "%id = OpVariable %uvec3ptr Input\n"
1391 "%zero = OpConstant %i32 0\n"
1393 "%main = OpFunction %void None %voidf\n"
1394 "%label = OpLabel\n"
1395 "%idval = OpLoad %uvec3 %id\n"
1396 "%x = OpCompositeExtract %u32 %idval 0\n"
1397 "%inloc1 = OpAccessChain %f32ptr %indata1 %zero %x\n"
1398 "%inval1 = OpLoad %f32 %inloc1\n"
1399 "%inloc2 = OpAccessChain %f32ptr %indata2 %zero %x\n"
1400 "%inval2 = OpLoad %f32 %inloc2\n"
1401 "%rem = OpExtInst %f32 %std450 NMax %inval1 %inval2\n"
1402 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
1403 " OpStore %outloc %rem\n"
1407 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats1)));
1408 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
1409 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
1410 spec.numWorkGroups = IVec3(numElements, 1, 1);
1411 spec.verifyIO = &compareNMax;
1413 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "", spec));
1415 return group.release();
1418 bool compareNClamp (const std::vector<BufferSp>&, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs, TestLog&)
1420 if (outputAllocs.size() != 1)
1423 const BufferSp& expectedOutput = expectedOutputs[0];
1424 std::vector<deUint8> data;
1425 expectedOutput->getBytes(data);
1427 const float* const expectedOutputAsFloat = reinterpret_cast<const float*>(&data.front());
1428 const float* const outputAsFloat = static_cast<const float*>(outputAllocs[0]->getHostPtr());
1430 for (size_t idx = 0; idx < expectedOutput->getByteSize() / sizeof(float) / 2; ++idx)
1432 const float e0 = expectedOutputAsFloat[idx * 2];
1433 const float e1 = expectedOutputAsFloat[idx * 2 + 1];
1434 const float res = outputAsFloat[idx];
1436 // For NClamp, we have two possible outcomes based on
1437 // whether NaNs are handled or not.
1438 // If either min or max value is NaN, the result is undefined,
1439 // so this test doesn't stress those. If the clamped value is
1440 // NaN, and NaNs are handled, the result is min; if NaNs are not
1441 // handled, they are big values that result in max.
1442 // If all three parameters are NaN, the result should be NaN.
1443 if (!((tcu::Float32(e0).isNaN() && tcu::Float32(res).isNaN()) ||
1444 (deFloatAbs(e0 - res) < 0.00001f) ||
1445 (deFloatAbs(e1 - res) < 0.00001f)))
1452 tcu::TestCaseGroup* createOpNClampGroup (tcu::TestContext& testCtx)
1454 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opnclamp", "Test the OpNClamp instruction"));
1455 ComputeShaderSpec spec;
1456 de::Random rnd (deStringHash(group->getName()));
1457 const int numElements = 200;
1458 vector<float> inputFloats1 (numElements, 0);
1459 vector<float> inputFloats2 (numElements, 0);
1460 vector<float> inputFloats3 (numElements, 0);
1461 vector<float> outputFloats (numElements * 2, 0);
1463 fillRandomScalars(rnd, -10000.f, 10000.f, &inputFloats1[0], numElements);
1464 fillRandomScalars(rnd, -10000.f, 10000.f, &inputFloats2[0], numElements);
1465 fillRandomScalars(rnd, -10000.f, 10000.f, &inputFloats3[0], numElements);
1467 for (size_t ndx = 0; ndx < numElements; ++ndx)
1469 // Results are only defined if max value is bigger than min value.
1470 if (inputFloats2[ndx] > inputFloats3[ndx])
1472 float t = inputFloats2[ndx];
1473 inputFloats2[ndx] = inputFloats3[ndx];
1474 inputFloats3[ndx] = t;
1477 // By default, do the clamp, setting both possible answers
1478 float defaultRes = std::min(std::max(inputFloats1[ndx], inputFloats2[ndx]), inputFloats3[ndx]);
1480 float maxResA = std::max(inputFloats1[ndx], inputFloats2[ndx]);
1481 float maxResB = maxResA;
1483 // Alternate between the NaN cases
1486 inputFloats1[ndx] = TCU_NAN;
1487 // If NaN is handled, the result should be same as the clamp minimum.
1488 // If NaN is not handled, the result should clamp to the clamp maximum.
1489 maxResA = inputFloats2[ndx];
1490 maxResB = inputFloats3[ndx];
1494 // Not a NaN case - only one legal result.
1495 maxResA = defaultRes;
1496 maxResB = defaultRes;
1499 outputFloats[ndx * 2] = maxResA;
1500 outputFloats[ndx * 2 + 1] = maxResB;
1503 // Make the first case a full-NAN case.
1504 inputFloats1[0] = TCU_NAN;
1505 inputFloats2[0] = TCU_NAN;
1506 inputFloats3[0] = TCU_NAN;
1507 outputFloats[0] = TCU_NAN;
1508 outputFloats[1] = TCU_NAN;
1511 "OpCapability Shader\n"
1512 "%std450 = OpExtInstImport \"GLSL.std.450\"\n"
1513 "OpMemoryModel Logical GLSL450\n"
1514 "OpEntryPoint GLCompute %main \"main\" %id\n"
1515 "OpExecutionMode %main LocalSize 1 1 1\n"
1517 "OpName %main \"main\"\n"
1518 "OpName %id \"gl_GlobalInvocationID\"\n"
1520 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1522 "OpDecorate %buf BufferBlock\n"
1523 "OpDecorate %indata1 DescriptorSet 0\n"
1524 "OpDecorate %indata1 Binding 0\n"
1525 "OpDecorate %indata2 DescriptorSet 0\n"
1526 "OpDecorate %indata2 Binding 1\n"
1527 "OpDecorate %indata3 DescriptorSet 0\n"
1528 "OpDecorate %indata3 Binding 2\n"
1529 "OpDecorate %outdata DescriptorSet 0\n"
1530 "OpDecorate %outdata Binding 3\n"
1531 "OpDecorate %f32arr ArrayStride 4\n"
1532 "OpMemberDecorate %buf 0 Offset 0\n"
1534 + string(getComputeAsmCommonTypes()) +
1536 "%buf = OpTypeStruct %f32arr\n"
1537 "%bufptr = OpTypePointer Uniform %buf\n"
1538 "%indata1 = OpVariable %bufptr Uniform\n"
1539 "%indata2 = OpVariable %bufptr Uniform\n"
1540 "%indata3 = OpVariable %bufptr Uniform\n"
1541 "%outdata = OpVariable %bufptr Uniform\n"
1543 "%id = OpVariable %uvec3ptr Input\n"
1544 "%zero = OpConstant %i32 0\n"
1546 "%main = OpFunction %void None %voidf\n"
1547 "%label = OpLabel\n"
1548 "%idval = OpLoad %uvec3 %id\n"
1549 "%x = OpCompositeExtract %u32 %idval 0\n"
1550 "%inloc1 = OpAccessChain %f32ptr %indata1 %zero %x\n"
1551 "%inval1 = OpLoad %f32 %inloc1\n"
1552 "%inloc2 = OpAccessChain %f32ptr %indata2 %zero %x\n"
1553 "%inval2 = OpLoad %f32 %inloc2\n"
1554 "%inloc3 = OpAccessChain %f32ptr %indata3 %zero %x\n"
1555 "%inval3 = OpLoad %f32 %inloc3\n"
1556 "%rem = OpExtInst %f32 %std450 NClamp %inval1 %inval2 %inval3\n"
1557 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
1558 " OpStore %outloc %rem\n"
1562 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats1)));
1563 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
1564 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats3)));
1565 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
1566 spec.numWorkGroups = IVec3(numElements, 1, 1);
1567 spec.verifyIO = &compareNClamp;
1569 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "", spec));
1571 return group.release();
1574 tcu::TestCaseGroup* createOpSRemComputeGroup (tcu::TestContext& testCtx, qpTestResult negFailResult)
1576 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opsrem", "Test the OpSRem instruction"));
1577 de::Random rnd (deStringHash(group->getName()));
1578 const int numElements = 200;
1580 const struct CaseParams
1583 const char* failMessage; // customized status message
1584 qpTestResult failResult; // override status on failure
1585 int op1Min, op1Max; // operand ranges
1589 { "positive", "Output doesn't match with expected", QP_TEST_RESULT_FAIL, 0, 65536, 0, 100 },
1590 { "all", "Inconsistent results, but within specification", negFailResult, -65536, 65536, -100, 100 }, // see below
1592 // If either operand is negative the result is undefined. Some implementations may still return correct values.
1594 for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(cases); ++caseNdx)
1596 const CaseParams& params = cases[caseNdx];
1597 ComputeShaderSpec spec;
1598 vector<deInt32> inputInts1 (numElements, 0);
1599 vector<deInt32> inputInts2 (numElements, 0);
1600 vector<deInt32> outputInts (numElements, 0);
1602 fillRandomScalars(rnd, params.op1Min, params.op1Max, &inputInts1[0], numElements);
1603 fillRandomScalars(rnd, params.op2Min, params.op2Max, &inputInts2[0], numElements, filterNotZero);
1605 for (int ndx = 0; ndx < numElements; ++ndx)
1607 // The return value of std::fmod() has the same sign as its first operand, which is how OpFRem spec'd.
1608 outputInts[ndx] = inputInts1[ndx] % inputInts2[ndx];
1612 string(getComputeAsmShaderPreamble()) +
1614 "OpName %main \"main\"\n"
1615 "OpName %id \"gl_GlobalInvocationID\"\n"
1617 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1619 "OpDecorate %buf BufferBlock\n"
1620 "OpDecorate %indata1 DescriptorSet 0\n"
1621 "OpDecorate %indata1 Binding 0\n"
1622 "OpDecorate %indata2 DescriptorSet 0\n"
1623 "OpDecorate %indata2 Binding 1\n"
1624 "OpDecorate %outdata DescriptorSet 0\n"
1625 "OpDecorate %outdata Binding 2\n"
1626 "OpDecorate %i32arr ArrayStride 4\n"
1627 "OpMemberDecorate %buf 0 Offset 0\n"
1629 + string(getComputeAsmCommonTypes()) +
1631 "%buf = OpTypeStruct %i32arr\n"
1632 "%bufptr = OpTypePointer Uniform %buf\n"
1633 "%indata1 = OpVariable %bufptr Uniform\n"
1634 "%indata2 = OpVariable %bufptr Uniform\n"
1635 "%outdata = OpVariable %bufptr Uniform\n"
1637 "%id = OpVariable %uvec3ptr Input\n"
1638 "%zero = OpConstant %i32 0\n"
1640 "%main = OpFunction %void None %voidf\n"
1641 "%label = OpLabel\n"
1642 "%idval = OpLoad %uvec3 %id\n"
1643 "%x = OpCompositeExtract %u32 %idval 0\n"
1644 "%inloc1 = OpAccessChain %i32ptr %indata1 %zero %x\n"
1645 "%inval1 = OpLoad %i32 %inloc1\n"
1646 "%inloc2 = OpAccessChain %i32ptr %indata2 %zero %x\n"
1647 "%inval2 = OpLoad %i32 %inloc2\n"
1648 "%rem = OpSRem %i32 %inval1 %inval2\n"
1649 "%outloc = OpAccessChain %i32ptr %outdata %zero %x\n"
1650 " OpStore %outloc %rem\n"
1654 spec.inputs.push_back (BufferSp(new Int32Buffer(inputInts1)));
1655 spec.inputs.push_back (BufferSp(new Int32Buffer(inputInts2)));
1656 spec.outputs.push_back (BufferSp(new Int32Buffer(outputInts)));
1657 spec.numWorkGroups = IVec3(numElements, 1, 1);
1658 spec.failResult = params.failResult;
1659 spec.failMessage = params.failMessage;
1661 group->addChild(new SpvAsmComputeShaderCase(testCtx, params.name, "", spec));
1664 return group.release();
1667 tcu::TestCaseGroup* createOpSRemComputeGroup64 (tcu::TestContext& testCtx, qpTestResult negFailResult)
1669 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opsrem64", "Test the 64-bit OpSRem instruction"));
1670 de::Random rnd (deStringHash(group->getName()));
1671 const int numElements = 200;
1673 const struct CaseParams
1676 const char* failMessage; // customized status message
1677 qpTestResult failResult; // override status on failure
1681 { "positive", "Output doesn't match with expected", QP_TEST_RESULT_FAIL, true },
1682 { "all", "Inconsistent results, but within specification", negFailResult, false }, // see below
1684 // If either operand is negative the result is undefined. Some implementations may still return correct values.
1686 for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(cases); ++caseNdx)
1688 const CaseParams& params = cases[caseNdx];
1689 ComputeShaderSpec spec;
1690 vector<deInt64> inputInts1 (numElements, 0);
1691 vector<deInt64> inputInts2 (numElements, 0);
1692 vector<deInt64> outputInts (numElements, 0);
1694 if (params.positive)
1696 fillRandomInt64sLogDistributed(rnd, inputInts1, numElements, filterNonNegative);
1697 fillRandomInt64sLogDistributed(rnd, inputInts2, numElements, filterPositive);
1701 fillRandomInt64sLogDistributed(rnd, inputInts1, numElements);
1702 fillRandomInt64sLogDistributed(rnd, inputInts2, numElements, filterNotZero);
1705 for (int ndx = 0; ndx < numElements; ++ndx)
1707 // The return value of std::fmod() has the same sign as its first operand, which is how OpFRem spec'd.
1708 outputInts[ndx] = inputInts1[ndx] % inputInts2[ndx];
1712 "OpCapability Int64\n"
1714 + string(getComputeAsmShaderPreamble()) +
1716 "OpName %main \"main\"\n"
1717 "OpName %id \"gl_GlobalInvocationID\"\n"
1719 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1721 "OpDecorate %buf BufferBlock\n"
1722 "OpDecorate %indata1 DescriptorSet 0\n"
1723 "OpDecorate %indata1 Binding 0\n"
1724 "OpDecorate %indata2 DescriptorSet 0\n"
1725 "OpDecorate %indata2 Binding 1\n"
1726 "OpDecorate %outdata DescriptorSet 0\n"
1727 "OpDecorate %outdata Binding 2\n"
1728 "OpDecorate %i64arr ArrayStride 8\n"
1729 "OpMemberDecorate %buf 0 Offset 0\n"
1731 + string(getComputeAsmCommonTypes())
1732 + string(getComputeAsmCommonInt64Types()) +
1734 "%buf = OpTypeStruct %i64arr\n"
1735 "%bufptr = OpTypePointer Uniform %buf\n"
1736 "%indata1 = OpVariable %bufptr Uniform\n"
1737 "%indata2 = OpVariable %bufptr Uniform\n"
1738 "%outdata = OpVariable %bufptr Uniform\n"
1740 "%id = OpVariable %uvec3ptr Input\n"
1741 "%zero = OpConstant %i64 0\n"
1743 "%main = OpFunction %void None %voidf\n"
1744 "%label = OpLabel\n"
1745 "%idval = OpLoad %uvec3 %id\n"
1746 "%x = OpCompositeExtract %u32 %idval 0\n"
1747 "%inloc1 = OpAccessChain %i64ptr %indata1 %zero %x\n"
1748 "%inval1 = OpLoad %i64 %inloc1\n"
1749 "%inloc2 = OpAccessChain %i64ptr %indata2 %zero %x\n"
1750 "%inval2 = OpLoad %i64 %inloc2\n"
1751 "%rem = OpSRem %i64 %inval1 %inval2\n"
1752 "%outloc = OpAccessChain %i64ptr %outdata %zero %x\n"
1753 " OpStore %outloc %rem\n"
1757 spec.inputs.push_back (BufferSp(new Int64Buffer(inputInts1)));
1758 spec.inputs.push_back (BufferSp(new Int64Buffer(inputInts2)));
1759 spec.outputs.push_back (BufferSp(new Int64Buffer(outputInts)));
1760 spec.numWorkGroups = IVec3(numElements, 1, 1);
1761 spec.failResult = params.failResult;
1762 spec.failMessage = params.failMessage;
1764 group->addChild(new SpvAsmComputeShaderCase(testCtx, params.name, "", spec, COMPUTE_TEST_USES_INT64));
1767 return group.release();
1770 tcu::TestCaseGroup* createOpSModComputeGroup (tcu::TestContext& testCtx, qpTestResult negFailResult)
1772 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opsmod", "Test the OpSMod instruction"));
1773 de::Random rnd (deStringHash(group->getName()));
1774 const int numElements = 200;
1776 const struct CaseParams
1779 const char* failMessage; // customized status message
1780 qpTestResult failResult; // override status on failure
1781 int op1Min, op1Max; // operand ranges
1785 { "positive", "Output doesn't match with expected", QP_TEST_RESULT_FAIL, 0, 65536, 0, 100 },
1786 { "all", "Inconsistent results, but within specification", negFailResult, -65536, 65536, -100, 100 }, // see below
1788 // If either operand is negative the result is undefined. Some implementations may still return correct values.
1790 for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(cases); ++caseNdx)
1792 const CaseParams& params = cases[caseNdx];
1794 ComputeShaderSpec spec;
1795 vector<deInt32> inputInts1 (numElements, 0);
1796 vector<deInt32> inputInts2 (numElements, 0);
1797 vector<deInt32> outputInts (numElements, 0);
1799 fillRandomScalars(rnd, params.op1Min, params.op1Max, &inputInts1[0], numElements);
1800 fillRandomScalars(rnd, params.op2Min, params.op2Max, &inputInts2[0], numElements, filterNotZero);
1802 for (int ndx = 0; ndx < numElements; ++ndx)
1804 deInt32 rem = inputInts1[ndx] % inputInts2[ndx];
1807 outputInts[ndx] = 0;
1809 else if ((inputInts1[ndx] >= 0) == (inputInts2[ndx] >= 0))
1811 // They have the same sign
1812 outputInts[ndx] = rem;
1816 // They have opposite sign. The remainder operation takes the
1817 // sign inputInts1[ndx] but OpSMod is supposed to take ths sign
1818 // of inputInts2[ndx]. Adding inputInts2[ndx] will ensure that
1819 // the result has the correct sign and that it is still
1820 // congruent to inputInts1[ndx] modulo inputInts2[ndx]
1822 // See also http://mathforum.org/library/drmath/view/52343.html
1823 outputInts[ndx] = rem + inputInts2[ndx];
1828 string(getComputeAsmShaderPreamble()) +
1830 "OpName %main \"main\"\n"
1831 "OpName %id \"gl_GlobalInvocationID\"\n"
1833 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1835 "OpDecorate %buf BufferBlock\n"
1836 "OpDecorate %indata1 DescriptorSet 0\n"
1837 "OpDecorate %indata1 Binding 0\n"
1838 "OpDecorate %indata2 DescriptorSet 0\n"
1839 "OpDecorate %indata2 Binding 1\n"
1840 "OpDecorate %outdata DescriptorSet 0\n"
1841 "OpDecorate %outdata Binding 2\n"
1842 "OpDecorate %i32arr ArrayStride 4\n"
1843 "OpMemberDecorate %buf 0 Offset 0\n"
1845 + string(getComputeAsmCommonTypes()) +
1847 "%buf = OpTypeStruct %i32arr\n"
1848 "%bufptr = OpTypePointer Uniform %buf\n"
1849 "%indata1 = OpVariable %bufptr Uniform\n"
1850 "%indata2 = OpVariable %bufptr Uniform\n"
1851 "%outdata = OpVariable %bufptr Uniform\n"
1853 "%id = OpVariable %uvec3ptr Input\n"
1854 "%zero = OpConstant %i32 0\n"
1856 "%main = OpFunction %void None %voidf\n"
1857 "%label = OpLabel\n"
1858 "%idval = OpLoad %uvec3 %id\n"
1859 "%x = OpCompositeExtract %u32 %idval 0\n"
1860 "%inloc1 = OpAccessChain %i32ptr %indata1 %zero %x\n"
1861 "%inval1 = OpLoad %i32 %inloc1\n"
1862 "%inloc2 = OpAccessChain %i32ptr %indata2 %zero %x\n"
1863 "%inval2 = OpLoad %i32 %inloc2\n"
1864 "%rem = OpSMod %i32 %inval1 %inval2\n"
1865 "%outloc = OpAccessChain %i32ptr %outdata %zero %x\n"
1866 " OpStore %outloc %rem\n"
1870 spec.inputs.push_back (BufferSp(new Int32Buffer(inputInts1)));
1871 spec.inputs.push_back (BufferSp(new Int32Buffer(inputInts2)));
1872 spec.outputs.push_back (BufferSp(new Int32Buffer(outputInts)));
1873 spec.numWorkGroups = IVec3(numElements, 1, 1);
1874 spec.failResult = params.failResult;
1875 spec.failMessage = params.failMessage;
1877 group->addChild(new SpvAsmComputeShaderCase(testCtx, params.name, "", spec));
1880 return group.release();
1883 tcu::TestCaseGroup* createOpSModComputeGroup64 (tcu::TestContext& testCtx, qpTestResult negFailResult)
1885 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opsmod64", "Test the OpSMod instruction"));
1886 de::Random rnd (deStringHash(group->getName()));
1887 const int numElements = 200;
1889 const struct CaseParams
1892 const char* failMessage; // customized status message
1893 qpTestResult failResult; // override status on failure
1897 { "positive", "Output doesn't match with expected", QP_TEST_RESULT_FAIL, true },
1898 { "all", "Inconsistent results, but within specification", negFailResult, false }, // see below
1900 // If either operand is negative the result is undefined. Some implementations may still return correct values.
1902 for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(cases); ++caseNdx)
1904 const CaseParams& params = cases[caseNdx];
1906 ComputeShaderSpec spec;
1907 vector<deInt64> inputInts1 (numElements, 0);
1908 vector<deInt64> inputInts2 (numElements, 0);
1909 vector<deInt64> outputInts (numElements, 0);
1912 if (params.positive)
1914 fillRandomInt64sLogDistributed(rnd, inputInts1, numElements, filterNonNegative);
1915 fillRandomInt64sLogDistributed(rnd, inputInts2, numElements, filterPositive);
1919 fillRandomInt64sLogDistributed(rnd, inputInts1, numElements);
1920 fillRandomInt64sLogDistributed(rnd, inputInts2, numElements, filterNotZero);
1923 for (int ndx = 0; ndx < numElements; ++ndx)
1925 deInt64 rem = inputInts1[ndx] % inputInts2[ndx];
1928 outputInts[ndx] = 0;
1930 else if ((inputInts1[ndx] >= 0) == (inputInts2[ndx] >= 0))
1932 // They have the same sign
1933 outputInts[ndx] = rem;
1937 // They have opposite sign. The remainder operation takes the
1938 // sign inputInts1[ndx] but OpSMod is supposed to take ths sign
1939 // of inputInts2[ndx]. Adding inputInts2[ndx] will ensure that
1940 // the result has the correct sign and that it is still
1941 // congruent to inputInts1[ndx] modulo inputInts2[ndx]
1943 // See also http://mathforum.org/library/drmath/view/52343.html
1944 outputInts[ndx] = rem + inputInts2[ndx];
1949 "OpCapability Int64\n"
1951 + string(getComputeAsmShaderPreamble()) +
1953 "OpName %main \"main\"\n"
1954 "OpName %id \"gl_GlobalInvocationID\"\n"
1956 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1958 "OpDecorate %buf BufferBlock\n"
1959 "OpDecorate %indata1 DescriptorSet 0\n"
1960 "OpDecorate %indata1 Binding 0\n"
1961 "OpDecorate %indata2 DescriptorSet 0\n"
1962 "OpDecorate %indata2 Binding 1\n"
1963 "OpDecorate %outdata DescriptorSet 0\n"
1964 "OpDecorate %outdata Binding 2\n"
1965 "OpDecorate %i64arr ArrayStride 8\n"
1966 "OpMemberDecorate %buf 0 Offset 0\n"
1968 + string(getComputeAsmCommonTypes())
1969 + string(getComputeAsmCommonInt64Types()) +
1971 "%buf = OpTypeStruct %i64arr\n"
1972 "%bufptr = OpTypePointer Uniform %buf\n"
1973 "%indata1 = OpVariable %bufptr Uniform\n"
1974 "%indata2 = OpVariable %bufptr Uniform\n"
1975 "%outdata = OpVariable %bufptr Uniform\n"
1977 "%id = OpVariable %uvec3ptr Input\n"
1978 "%zero = OpConstant %i64 0\n"
1980 "%main = OpFunction %void None %voidf\n"
1981 "%label = OpLabel\n"
1982 "%idval = OpLoad %uvec3 %id\n"
1983 "%x = OpCompositeExtract %u32 %idval 0\n"
1984 "%inloc1 = OpAccessChain %i64ptr %indata1 %zero %x\n"
1985 "%inval1 = OpLoad %i64 %inloc1\n"
1986 "%inloc2 = OpAccessChain %i64ptr %indata2 %zero %x\n"
1987 "%inval2 = OpLoad %i64 %inloc2\n"
1988 "%rem = OpSMod %i64 %inval1 %inval2\n"
1989 "%outloc = OpAccessChain %i64ptr %outdata %zero %x\n"
1990 " OpStore %outloc %rem\n"
1994 spec.inputs.push_back (BufferSp(new Int64Buffer(inputInts1)));
1995 spec.inputs.push_back (BufferSp(new Int64Buffer(inputInts2)));
1996 spec.outputs.push_back (BufferSp(new Int64Buffer(outputInts)));
1997 spec.numWorkGroups = IVec3(numElements, 1, 1);
1998 spec.failResult = params.failResult;
1999 spec.failMessage = params.failMessage;
2001 group->addChild(new SpvAsmComputeShaderCase(testCtx, params.name, "", spec, COMPUTE_TEST_USES_INT64));
2004 return group.release();
2007 // Copy contents in the input buffer to the output buffer.
2008 tcu::TestCaseGroup* createOpCopyMemoryGroup (tcu::TestContext& testCtx)
2010 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opcopymemory", "Test the OpCopyMemory instruction"));
2011 de::Random rnd (deStringHash(group->getName()));
2012 const int numElements = 100;
2014 // 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.
2015 ComputeShaderSpec spec1;
2016 vector<Vec4> inputFloats1 (numElements);
2017 vector<Vec4> outputFloats1 (numElements);
2019 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats1[0], numElements * 4);
2021 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
2022 floorAll(inputFloats1);
2024 for (size_t ndx = 0; ndx < numElements; ++ndx)
2025 outputFloats1[ndx] = inputFloats1[ndx] + Vec4(0.f, 0.5f, 1.5f, 2.5f);
2028 string(getComputeAsmShaderPreamble()) +
2030 "OpName %main \"main\"\n"
2031 "OpName %id \"gl_GlobalInvocationID\"\n"
2033 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2034 "OpDecorate %vec4arr ArrayStride 16\n"
2036 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
2038 "%vec4 = OpTypeVector %f32 4\n"
2039 "%vec4ptr_u = OpTypePointer Uniform %vec4\n"
2040 "%vec4ptr_f = OpTypePointer Function %vec4\n"
2041 "%vec4arr = OpTypeRuntimeArray %vec4\n"
2042 "%buf = OpTypeStruct %vec4arr\n"
2043 "%bufptr = OpTypePointer Uniform %buf\n"
2044 "%indata = OpVariable %bufptr Uniform\n"
2045 "%outdata = OpVariable %bufptr Uniform\n"
2047 "%id = OpVariable %uvec3ptr Input\n"
2048 "%zero = OpConstant %i32 0\n"
2049 "%c_f_0 = OpConstant %f32 0.\n"
2050 "%c_f_0_5 = OpConstant %f32 0.5\n"
2051 "%c_f_1_5 = OpConstant %f32 1.5\n"
2052 "%c_f_2_5 = OpConstant %f32 2.5\n"
2053 "%c_vec4 = OpConstantComposite %vec4 %c_f_0 %c_f_0_5 %c_f_1_5 %c_f_2_5\n"
2055 "%main = OpFunction %void None %voidf\n"
2056 "%label = OpLabel\n"
2057 "%v_vec4 = OpVariable %vec4ptr_f Function\n"
2058 "%idval = OpLoad %uvec3 %id\n"
2059 "%x = OpCompositeExtract %u32 %idval 0\n"
2060 "%inloc = OpAccessChain %vec4ptr_u %indata %zero %x\n"
2061 "%outloc = OpAccessChain %vec4ptr_u %outdata %zero %x\n"
2062 " OpCopyMemory %v_vec4 %inloc\n"
2063 "%v_vec4_val = OpLoad %vec4 %v_vec4\n"
2064 "%add = OpFAdd %vec4 %v_vec4_val %c_vec4\n"
2065 " OpStore %outloc %add\n"
2069 spec1.inputs.push_back(BufferSp(new Vec4Buffer(inputFloats1)));
2070 spec1.outputs.push_back(BufferSp(new Vec4Buffer(outputFloats1)));
2071 spec1.numWorkGroups = IVec3(numElements, 1, 1);
2073 group->addChild(new SpvAsmComputeShaderCase(testCtx, "vector", "OpCopyMemory elements of vector type", spec1));
2075 // The following case copies a float[100] variable from the input buffer to the output buffer.
2076 ComputeShaderSpec spec2;
2077 vector<float> inputFloats2 (numElements);
2078 vector<float> outputFloats2 (numElements);
2080 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats2[0], numElements);
2082 for (size_t ndx = 0; ndx < numElements; ++ndx)
2083 outputFloats2[ndx] = inputFloats2[ndx];
2086 string(getComputeAsmShaderPreamble()) +
2088 "OpName %main \"main\"\n"
2089 "OpName %id \"gl_GlobalInvocationID\"\n"
2091 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2092 "OpDecorate %f32arr100 ArrayStride 4\n"
2094 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
2096 "%hundred = OpConstant %u32 100\n"
2097 "%f32arr100 = OpTypeArray %f32 %hundred\n"
2098 "%f32arr100ptr_f = OpTypePointer Function %f32arr100\n"
2099 "%f32arr100ptr_u = OpTypePointer Uniform %f32arr100\n"
2100 "%buf = OpTypeStruct %f32arr100\n"
2101 "%bufptr = OpTypePointer Uniform %buf\n"
2102 "%indata = OpVariable %bufptr Uniform\n"
2103 "%outdata = OpVariable %bufptr Uniform\n"
2105 "%id = OpVariable %uvec3ptr Input\n"
2106 "%zero = OpConstant %i32 0\n"
2108 "%main = OpFunction %void None %voidf\n"
2109 "%label = OpLabel\n"
2110 "%var = OpVariable %f32arr100ptr_f Function\n"
2111 "%inarr = OpAccessChain %f32arr100ptr_u %indata %zero\n"
2112 "%outarr = OpAccessChain %f32arr100ptr_u %outdata %zero\n"
2113 " OpCopyMemory %var %inarr\n"
2114 " OpCopyMemory %outarr %var\n"
2118 spec2.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
2119 spec2.outputs.push_back(BufferSp(new Float32Buffer(outputFloats2)));
2120 spec2.numWorkGroups = IVec3(1, 1, 1);
2122 group->addChild(new SpvAsmComputeShaderCase(testCtx, "array", "OpCopyMemory elements of array type", spec2));
2124 // The following case copies a struct{vec4, vec4, vec4, vec4} variable from the input buffer to the output buffer.
2125 ComputeShaderSpec spec3;
2126 vector<float> inputFloats3 (16);
2127 vector<float> outputFloats3 (16);
2129 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats3[0], 16);
2131 for (size_t ndx = 0; ndx < 16; ++ndx)
2132 outputFloats3[ndx] = inputFloats3[ndx];
2135 string(getComputeAsmShaderPreamble()) +
2137 "OpName %main \"main\"\n"
2138 "OpName %id \"gl_GlobalInvocationID\"\n"
2140 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2141 "OpMemberDecorate %buf 0 Offset 0\n"
2142 "OpMemberDecorate %buf 1 Offset 16\n"
2143 "OpMemberDecorate %buf 2 Offset 32\n"
2144 "OpMemberDecorate %buf 3 Offset 48\n"
2146 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
2148 "%vec4 = OpTypeVector %f32 4\n"
2149 "%buf = OpTypeStruct %vec4 %vec4 %vec4 %vec4\n"
2150 "%bufptr = OpTypePointer Uniform %buf\n"
2151 "%indata = OpVariable %bufptr Uniform\n"
2152 "%outdata = OpVariable %bufptr Uniform\n"
2153 "%vec4stptr = OpTypePointer Function %buf\n"
2155 "%id = OpVariable %uvec3ptr Input\n"
2156 "%zero = OpConstant %i32 0\n"
2158 "%main = OpFunction %void None %voidf\n"
2159 "%label = OpLabel\n"
2160 "%var = OpVariable %vec4stptr Function\n"
2161 " OpCopyMemory %var %indata\n"
2162 " OpCopyMemory %outdata %var\n"
2166 spec3.inputs.push_back(BufferSp(new Float32Buffer(inputFloats3)));
2167 spec3.outputs.push_back(BufferSp(new Float32Buffer(outputFloats3)));
2168 spec3.numWorkGroups = IVec3(1, 1, 1);
2170 group->addChild(new SpvAsmComputeShaderCase(testCtx, "struct", "OpCopyMemory elements of struct type", spec3));
2172 // The following case negates multiple float variables from the input buffer and stores the results to the output buffer.
2173 ComputeShaderSpec spec4;
2174 vector<float> inputFloats4 (numElements);
2175 vector<float> outputFloats4 (numElements);
2177 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats4[0], numElements);
2179 for (size_t ndx = 0; ndx < numElements; ++ndx)
2180 outputFloats4[ndx] = -inputFloats4[ndx];
2183 string(getComputeAsmShaderPreamble()) +
2185 "OpName %main \"main\"\n"
2186 "OpName %id \"gl_GlobalInvocationID\"\n"
2188 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2190 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
2192 "%f32ptr_f = OpTypePointer Function %f32\n"
2193 "%id = OpVariable %uvec3ptr Input\n"
2194 "%zero = OpConstant %i32 0\n"
2196 "%main = OpFunction %void None %voidf\n"
2197 "%label = OpLabel\n"
2198 "%var = OpVariable %f32ptr_f Function\n"
2199 "%idval = OpLoad %uvec3 %id\n"
2200 "%x = OpCompositeExtract %u32 %idval 0\n"
2201 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
2202 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2203 " OpCopyMemory %var %inloc\n"
2204 "%val = OpLoad %f32 %var\n"
2205 "%neg = OpFNegate %f32 %val\n"
2206 " OpStore %outloc %neg\n"
2210 spec4.inputs.push_back(BufferSp(new Float32Buffer(inputFloats4)));
2211 spec4.outputs.push_back(BufferSp(new Float32Buffer(outputFloats4)));
2212 spec4.numWorkGroups = IVec3(numElements, 1, 1);
2214 group->addChild(new SpvAsmComputeShaderCase(testCtx, "float", "OpCopyMemory elements of float type", spec4));
2216 return group.release();
2219 tcu::TestCaseGroup* createOpCopyObjectGroup (tcu::TestContext& testCtx)
2221 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opcopyobject", "Test the OpCopyObject instruction"));
2222 ComputeShaderSpec spec;
2223 de::Random rnd (deStringHash(group->getName()));
2224 const int numElements = 100;
2225 vector<float> inputFloats (numElements, 0);
2226 vector<float> outputFloats (numElements, 0);
2228 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats[0], numElements);
2230 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
2231 floorAll(inputFloats);
2233 for (size_t ndx = 0; ndx < numElements; ++ndx)
2234 outputFloats[ndx] = inputFloats[ndx] + 7.5f;
2237 string(getComputeAsmShaderPreamble()) +
2239 "OpName %main \"main\"\n"
2240 "OpName %id \"gl_GlobalInvocationID\"\n"
2242 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2244 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
2246 "%fmat = OpTypeMatrix %fvec3 3\n"
2247 "%three = OpConstant %u32 3\n"
2248 "%farr = OpTypeArray %f32 %three\n"
2249 "%fst = OpTypeStruct %f32 %f32\n"
2251 + string(getComputeAsmInputOutputBuffer()) +
2253 "%id = OpVariable %uvec3ptr Input\n"
2254 "%zero = OpConstant %i32 0\n"
2255 "%c_f = OpConstant %f32 1.5\n"
2256 "%c_fvec3 = OpConstantComposite %fvec3 %c_f %c_f %c_f\n"
2257 "%c_fmat = OpConstantComposite %fmat %c_fvec3 %c_fvec3 %c_fvec3\n"
2258 "%c_farr = OpConstantComposite %farr %c_f %c_f %c_f\n"
2259 "%c_fst = OpConstantComposite %fst %c_f %c_f\n"
2261 "%main = OpFunction %void None %voidf\n"
2262 "%label = OpLabel\n"
2263 "%c_f_copy = OpCopyObject %f32 %c_f\n"
2264 "%c_fvec3_copy = OpCopyObject %fvec3 %c_fvec3\n"
2265 "%c_fmat_copy = OpCopyObject %fmat %c_fmat\n"
2266 "%c_farr_copy = OpCopyObject %farr %c_farr\n"
2267 "%c_fst_copy = OpCopyObject %fst %c_fst\n"
2268 "%fvec3_elem = OpCompositeExtract %f32 %c_fvec3_copy 0\n"
2269 "%fmat_elem = OpCompositeExtract %f32 %c_fmat_copy 1 2\n"
2270 "%farr_elem = OpCompositeExtract %f32 %c_farr_copy 2\n"
2271 "%fst_elem = OpCompositeExtract %f32 %c_fst_copy 1\n"
2272 // Add up. 1.5 * 5 = 7.5.
2273 "%add1 = OpFAdd %f32 %c_f_copy %fvec3_elem\n"
2274 "%add2 = OpFAdd %f32 %add1 %fmat_elem\n"
2275 "%add3 = OpFAdd %f32 %add2 %farr_elem\n"
2276 "%add4 = OpFAdd %f32 %add3 %fst_elem\n"
2278 "%idval = OpLoad %uvec3 %id\n"
2279 "%x = OpCompositeExtract %u32 %idval 0\n"
2280 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
2281 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2282 "%inval = OpLoad %f32 %inloc\n"
2283 "%add = OpFAdd %f32 %add4 %inval\n"
2284 " OpStore %outloc %add\n"
2287 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
2288 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
2289 spec.numWorkGroups = IVec3(numElements, 1, 1);
2291 group->addChild(new SpvAsmComputeShaderCase(testCtx, "spotcheck", "OpCopyObject on different types", spec));
2293 return group.release();
2295 // Assembly code used for testing OpUnreachable is based on GLSL source code:
2299 // layout(std140, set = 0, binding = 0) readonly buffer Input {
2300 // float elements[];
2302 // layout(std140, set = 0, binding = 1) writeonly buffer Output {
2303 // float elements[];
2306 // void not_called_func() {
2307 // // place OpUnreachable here
2310 // uint modulo4(uint val) {
2311 // switch (val % uint(4)) {
2312 // case 0: return 3;
2313 // case 1: return 2;
2314 // case 2: return 1;
2315 // case 3: return 0;
2316 // default: return 100; // place OpUnreachable here
2322 // // place OpUnreachable here
2326 // uint x = gl_GlobalInvocationID.x;
2327 // if (const5() > modulo4(1000)) {
2328 // output_data.elements[x] = -input_data.elements[x];
2330 // // place OpUnreachable here
2331 // output_data.elements[x] = input_data.elements[x];
2335 tcu::TestCaseGroup* createOpUnreachableGroup (tcu::TestContext& testCtx)
2337 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opunreachable", "Test the OpUnreachable instruction"));
2338 ComputeShaderSpec spec;
2339 de::Random rnd (deStringHash(group->getName()));
2340 const int numElements = 100;
2341 vector<float> positiveFloats (numElements, 0);
2342 vector<float> negativeFloats (numElements, 0);
2344 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
2346 for (size_t ndx = 0; ndx < numElements; ++ndx)
2347 negativeFloats[ndx] = -positiveFloats[ndx];
2350 string(getComputeAsmShaderPreamble()) +
2352 "OpSource GLSL 430\n"
2353 "OpName %main \"main\"\n"
2354 "OpName %func_not_called_func \"not_called_func(\"\n"
2355 "OpName %func_modulo4 \"modulo4(u1;\"\n"
2356 "OpName %func_const5 \"const5(\"\n"
2357 "OpName %id \"gl_GlobalInvocationID\"\n"
2359 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2361 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
2363 "%u32ptr = OpTypePointer Function %u32\n"
2364 "%uintfuint = OpTypeFunction %u32 %u32ptr\n"
2365 "%unitf = OpTypeFunction %u32\n"
2367 "%id = OpVariable %uvec3ptr Input\n"
2368 "%zero = OpConstant %u32 0\n"
2369 "%one = OpConstant %u32 1\n"
2370 "%two = OpConstant %u32 2\n"
2371 "%three = OpConstant %u32 3\n"
2372 "%four = OpConstant %u32 4\n"
2373 "%five = OpConstant %u32 5\n"
2374 "%hundred = OpConstant %u32 100\n"
2375 "%thousand = OpConstant %u32 1000\n"
2377 + string(getComputeAsmInputOutputBuffer()) +
2380 "%main = OpFunction %void None %voidf\n"
2381 "%main_entry = OpLabel\n"
2382 "%v_thousand = OpVariable %u32ptr Function %thousand\n"
2383 "%idval = OpLoad %uvec3 %id\n"
2384 "%x = OpCompositeExtract %u32 %idval 0\n"
2385 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
2386 "%inval = OpLoad %f32 %inloc\n"
2387 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2388 "%ret_const5 = OpFunctionCall %u32 %func_const5\n"
2389 "%ret_modulo4 = OpFunctionCall %u32 %func_modulo4 %v_thousand\n"
2390 "%cmp_gt = OpUGreaterThan %bool %ret_const5 %ret_modulo4\n"
2391 " OpSelectionMerge %if_end None\n"
2392 " OpBranchConditional %cmp_gt %if_true %if_false\n"
2393 "%if_true = OpLabel\n"
2394 "%negate = OpFNegate %f32 %inval\n"
2395 " OpStore %outloc %negate\n"
2396 " OpBranch %if_end\n"
2397 "%if_false = OpLabel\n"
2398 " OpUnreachable\n" // Unreachable else branch for if statement
2399 "%if_end = OpLabel\n"
2403 // not_called_function()
2404 "%func_not_called_func = OpFunction %void None %voidf\n"
2405 "%not_called_func_entry = OpLabel\n"
2406 " OpUnreachable\n" // Unreachable entry block in not called static function
2410 "%func_modulo4 = OpFunction %u32 None %uintfuint\n"
2411 "%valptr = OpFunctionParameter %u32ptr\n"
2412 "%modulo4_entry = OpLabel\n"
2413 "%val = OpLoad %u32 %valptr\n"
2414 "%modulo = OpUMod %u32 %val %four\n"
2415 " OpSelectionMerge %switch_merge None\n"
2416 " OpSwitch %modulo %default 0 %case0 1 %case1 2 %case2 3 %case3\n"
2417 "%case0 = OpLabel\n"
2418 " OpReturnValue %three\n"
2419 "%case1 = OpLabel\n"
2420 " OpReturnValue %two\n"
2421 "%case2 = OpLabel\n"
2422 " OpReturnValue %one\n"
2423 "%case3 = OpLabel\n"
2424 " OpReturnValue %zero\n"
2425 "%default = OpLabel\n"
2426 " OpUnreachable\n" // Unreachable default case for switch statement
2427 "%switch_merge = OpLabel\n"
2428 " OpUnreachable\n" // Unreachable merge block for switch statement
2432 "%func_const5 = OpFunction %u32 None %unitf\n"
2433 "%const5_entry = OpLabel\n"
2434 " OpReturnValue %five\n"
2435 "%unreachable = OpLabel\n"
2436 " OpUnreachable\n" // Unreachable block in function
2438 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
2439 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
2440 spec.numWorkGroups = IVec3(numElements, 1, 1);
2442 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "OpUnreachable appearing at different places", spec));
2444 return group.release();
2447 // Assembly code used for testing decoration group is based on GLSL source code:
2451 // layout(std140, set = 0, binding = 0) readonly buffer Input0 {
2452 // float elements[];
2454 // layout(std140, set = 0, binding = 1) readonly buffer Input1 {
2455 // float elements[];
2457 // layout(std140, set = 0, binding = 2) readonly buffer Input2 {
2458 // float elements[];
2460 // layout(std140, set = 0, binding = 3) readonly buffer Input3 {
2461 // float elements[];
2463 // layout(std140, set = 0, binding = 4) readonly buffer Input4 {
2464 // float elements[];
2466 // layout(std140, set = 0, binding = 5) writeonly buffer Output {
2467 // float elements[];
2471 // uint x = gl_GlobalInvocationID.x;
2472 // output_data.elements[x] = input_data0.elements[x] + input_data1.elements[x] + input_data2.elements[x] + input_data3.elements[x] + input_data4.elements[x];
2474 tcu::TestCaseGroup* createDecorationGroupGroup (tcu::TestContext& testCtx)
2476 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "decoration_group", "Test the OpDecorationGroup & OpGroupDecorate instruction"));
2477 ComputeShaderSpec spec;
2478 de::Random rnd (deStringHash(group->getName()));
2479 const int numElements = 100;
2480 vector<float> inputFloats0 (numElements, 0);
2481 vector<float> inputFloats1 (numElements, 0);
2482 vector<float> inputFloats2 (numElements, 0);
2483 vector<float> inputFloats3 (numElements, 0);
2484 vector<float> inputFloats4 (numElements, 0);
2485 vector<float> outputFloats (numElements, 0);
2487 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats0[0], numElements);
2488 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats1[0], numElements);
2489 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats2[0], numElements);
2490 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats3[0], numElements);
2491 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats4[0], numElements);
2493 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
2494 floorAll(inputFloats0);
2495 floorAll(inputFloats1);
2496 floorAll(inputFloats2);
2497 floorAll(inputFloats3);
2498 floorAll(inputFloats4);
2500 for (size_t ndx = 0; ndx < numElements; ++ndx)
2501 outputFloats[ndx] = inputFloats0[ndx] + inputFloats1[ndx] + inputFloats2[ndx] + inputFloats3[ndx] + inputFloats4[ndx];
2504 string(getComputeAsmShaderPreamble()) +
2506 "OpSource GLSL 430\n"
2507 "OpName %main \"main\"\n"
2508 "OpName %id \"gl_GlobalInvocationID\"\n"
2510 // Not using group decoration on variable.
2511 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2512 // Not using group decoration on type.
2513 "OpDecorate %f32arr ArrayStride 4\n"
2515 "OpDecorate %groups BufferBlock\n"
2516 "OpDecorate %groupm Offset 0\n"
2517 "%groups = OpDecorationGroup\n"
2518 "%groupm = OpDecorationGroup\n"
2520 // Group decoration on multiple structs.
2521 "OpGroupDecorate %groups %outbuf %inbuf0 %inbuf1 %inbuf2 %inbuf3 %inbuf4\n"
2522 // Group decoration on multiple struct members.
2523 "OpGroupMemberDecorate %groupm %outbuf 0 %inbuf0 0 %inbuf1 0 %inbuf2 0 %inbuf3 0 %inbuf4 0\n"
2525 "OpDecorate %group1 DescriptorSet 0\n"
2526 "OpDecorate %group3 DescriptorSet 0\n"
2527 "OpDecorate %group3 NonWritable\n"
2528 "OpDecorate %group3 Restrict\n"
2529 "%group0 = OpDecorationGroup\n"
2530 "%group1 = OpDecorationGroup\n"
2531 "%group3 = OpDecorationGroup\n"
2533 // Applying the same decoration group multiple times.
2534 "OpGroupDecorate %group1 %outdata\n"
2535 "OpGroupDecorate %group1 %outdata\n"
2536 "OpGroupDecorate %group1 %outdata\n"
2537 "OpDecorate %outdata DescriptorSet 0\n"
2538 "OpDecorate %outdata Binding 5\n"
2539 // Applying decoration group containing nothing.
2540 "OpGroupDecorate %group0 %indata0\n"
2541 "OpDecorate %indata0 DescriptorSet 0\n"
2542 "OpDecorate %indata0 Binding 0\n"
2543 // Applying decoration group containing one decoration.
2544 "OpGroupDecorate %group1 %indata1\n"
2545 "OpDecorate %indata1 Binding 1\n"
2546 // Applying decoration group containing multiple decorations.
2547 "OpGroupDecorate %group3 %indata2 %indata3\n"
2548 "OpDecorate %indata2 Binding 2\n"
2549 "OpDecorate %indata3 Binding 3\n"
2550 // Applying multiple decoration groups (with overlapping).
2551 "OpGroupDecorate %group0 %indata4\n"
2552 "OpGroupDecorate %group1 %indata4\n"
2553 "OpGroupDecorate %group3 %indata4\n"
2554 "OpDecorate %indata4 Binding 4\n"
2556 + string(getComputeAsmCommonTypes()) +
2558 "%id = OpVariable %uvec3ptr Input\n"
2559 "%zero = OpConstant %i32 0\n"
2561 "%outbuf = OpTypeStruct %f32arr\n"
2562 "%outbufptr = OpTypePointer Uniform %outbuf\n"
2563 "%outdata = OpVariable %outbufptr Uniform\n"
2564 "%inbuf0 = OpTypeStruct %f32arr\n"
2565 "%inbuf0ptr = OpTypePointer Uniform %inbuf0\n"
2566 "%indata0 = OpVariable %inbuf0ptr Uniform\n"
2567 "%inbuf1 = OpTypeStruct %f32arr\n"
2568 "%inbuf1ptr = OpTypePointer Uniform %inbuf1\n"
2569 "%indata1 = OpVariable %inbuf1ptr Uniform\n"
2570 "%inbuf2 = OpTypeStruct %f32arr\n"
2571 "%inbuf2ptr = OpTypePointer Uniform %inbuf2\n"
2572 "%indata2 = OpVariable %inbuf2ptr Uniform\n"
2573 "%inbuf3 = OpTypeStruct %f32arr\n"
2574 "%inbuf3ptr = OpTypePointer Uniform %inbuf3\n"
2575 "%indata3 = OpVariable %inbuf3ptr Uniform\n"
2576 "%inbuf4 = OpTypeStruct %f32arr\n"
2577 "%inbufptr = OpTypePointer Uniform %inbuf4\n"
2578 "%indata4 = OpVariable %inbufptr Uniform\n"
2580 "%main = OpFunction %void None %voidf\n"
2581 "%label = OpLabel\n"
2582 "%idval = OpLoad %uvec3 %id\n"
2583 "%x = OpCompositeExtract %u32 %idval 0\n"
2584 "%inloc0 = OpAccessChain %f32ptr %indata0 %zero %x\n"
2585 "%inloc1 = OpAccessChain %f32ptr %indata1 %zero %x\n"
2586 "%inloc2 = OpAccessChain %f32ptr %indata2 %zero %x\n"
2587 "%inloc3 = OpAccessChain %f32ptr %indata3 %zero %x\n"
2588 "%inloc4 = OpAccessChain %f32ptr %indata4 %zero %x\n"
2589 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2590 "%inval0 = OpLoad %f32 %inloc0\n"
2591 "%inval1 = OpLoad %f32 %inloc1\n"
2592 "%inval2 = OpLoad %f32 %inloc2\n"
2593 "%inval3 = OpLoad %f32 %inloc3\n"
2594 "%inval4 = OpLoad %f32 %inloc4\n"
2595 "%add0 = OpFAdd %f32 %inval0 %inval1\n"
2596 "%add1 = OpFAdd %f32 %add0 %inval2\n"
2597 "%add2 = OpFAdd %f32 %add1 %inval3\n"
2598 "%add = OpFAdd %f32 %add2 %inval4\n"
2599 " OpStore %outloc %add\n"
2602 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats0)));
2603 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats1)));
2604 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
2605 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats3)));
2606 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats4)));
2607 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
2608 spec.numWorkGroups = IVec3(numElements, 1, 1);
2610 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "decoration group cases", spec));
2612 return group.release();
2615 struct SpecConstantTwoIntCase
2617 const char* caseName;
2618 const char* scDefinition0;
2619 const char* scDefinition1;
2620 const char* scResultType;
2621 const char* scOperation;
2622 deInt32 scActualValue0;
2623 deInt32 scActualValue1;
2624 const char* resultOperation;
2625 vector<deInt32> expectedOutput;
2627 SpecConstantTwoIntCase (const char* name,
2628 const char* definition0,
2629 const char* definition1,
2630 const char* resultType,
2631 const char* operation,
2634 const char* resultOp,
2635 const vector<deInt32>& output)
2637 , scDefinition0 (definition0)
2638 , scDefinition1 (definition1)
2639 , scResultType (resultType)
2640 , scOperation (operation)
2641 , scActualValue0 (value0)
2642 , scActualValue1 (value1)
2643 , resultOperation (resultOp)
2644 , expectedOutput (output) {}
2647 tcu::TestCaseGroup* createSpecConstantGroup (tcu::TestContext& testCtx)
2649 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opspecconstantop", "Test the OpSpecConstantOp instruction"));
2650 vector<SpecConstantTwoIntCase> cases;
2651 de::Random rnd (deStringHash(group->getName()));
2652 const int numElements = 100;
2653 vector<deInt32> inputInts (numElements, 0);
2654 vector<deInt32> outputInts1 (numElements, 0);
2655 vector<deInt32> outputInts2 (numElements, 0);
2656 vector<deInt32> outputInts3 (numElements, 0);
2657 vector<deInt32> outputInts4 (numElements, 0);
2658 const StringTemplate shaderTemplate (
2659 "${CAPABILITIES:opt}"
2660 + string(getComputeAsmShaderPreamble()) +
2662 "OpName %main \"main\"\n"
2663 "OpName %id \"gl_GlobalInvocationID\"\n"
2665 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2666 "OpDecorate %sc_0 SpecId 0\n"
2667 "OpDecorate %sc_1 SpecId 1\n"
2668 "OpDecorate %i32arr ArrayStride 4\n"
2670 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
2672 "${OPTYPE_DEFINITIONS:opt}"
2673 "%buf = OpTypeStruct %i32arr\n"
2674 "%bufptr = OpTypePointer Uniform %buf\n"
2675 "%indata = OpVariable %bufptr Uniform\n"
2676 "%outdata = OpVariable %bufptr Uniform\n"
2678 "%id = OpVariable %uvec3ptr Input\n"
2679 "%zero = OpConstant %i32 0\n"
2681 "%sc_0 = OpSpecConstant${SC_DEF0}\n"
2682 "%sc_1 = OpSpecConstant${SC_DEF1}\n"
2683 "%sc_final = OpSpecConstantOp ${SC_RESULT_TYPE} ${SC_OP}\n"
2685 "%main = OpFunction %void None %voidf\n"
2686 "%label = OpLabel\n"
2687 "${TYPE_CONVERT:opt}"
2688 "%idval = OpLoad %uvec3 %id\n"
2689 "%x = OpCompositeExtract %u32 %idval 0\n"
2690 "%inloc = OpAccessChain %i32ptr %indata %zero %x\n"
2691 "%inval = OpLoad %i32 %inloc\n"
2692 "%final = ${GEN_RESULT}\n"
2693 "%outloc = OpAccessChain %i32ptr %outdata %zero %x\n"
2694 " OpStore %outloc %final\n"
2696 " OpFunctionEnd\n");
2698 fillRandomScalars(rnd, -65536, 65536, &inputInts[0], numElements);
2700 for (size_t ndx = 0; ndx < numElements; ++ndx)
2702 outputInts1[ndx] = inputInts[ndx] + 42;
2703 outputInts2[ndx] = inputInts[ndx];
2704 outputInts3[ndx] = inputInts[ndx] - 11200;
2705 outputInts4[ndx] = inputInts[ndx] + 1;
2708 const char addScToInput[] = "OpIAdd %i32 %inval %sc_final";
2709 const char addSc32ToInput[] = "OpIAdd %i32 %inval %sc_final32";
2710 const char selectTrueUsingSc[] = "OpSelect %i32 %sc_final %inval %zero";
2711 const char selectFalseUsingSc[] = "OpSelect %i32 %sc_final %zero %inval";
2713 cases.push_back(SpecConstantTwoIntCase("iadd", " %i32 0", " %i32 0", "%i32", "IAdd %sc_0 %sc_1", 62, -20, addScToInput, outputInts1));
2714 cases.push_back(SpecConstantTwoIntCase("isub", " %i32 0", " %i32 0", "%i32", "ISub %sc_0 %sc_1", 100, 58, addScToInput, outputInts1));
2715 cases.push_back(SpecConstantTwoIntCase("imul", " %i32 0", " %i32 0", "%i32", "IMul %sc_0 %sc_1", -2, -21, addScToInput, outputInts1));
2716 cases.push_back(SpecConstantTwoIntCase("sdiv", " %i32 0", " %i32 0", "%i32", "SDiv %sc_0 %sc_1", -126, -3, addScToInput, outputInts1));
2717 cases.push_back(SpecConstantTwoIntCase("udiv", " %i32 0", " %i32 0", "%i32", "UDiv %sc_0 %sc_1", 126, 3, addScToInput, outputInts1));
2718 cases.push_back(SpecConstantTwoIntCase("srem", " %i32 0", " %i32 0", "%i32", "SRem %sc_0 %sc_1", 7, 3, addScToInput, outputInts4));
2719 cases.push_back(SpecConstantTwoIntCase("smod", " %i32 0", " %i32 0", "%i32", "SMod %sc_0 %sc_1", 7, 3, addScToInput, outputInts4));
2720 cases.push_back(SpecConstantTwoIntCase("umod", " %i32 0", " %i32 0", "%i32", "UMod %sc_0 %sc_1", 342, 50, addScToInput, outputInts1));
2721 cases.push_back(SpecConstantTwoIntCase("bitwiseand", " %i32 0", " %i32 0", "%i32", "BitwiseAnd %sc_0 %sc_1", 42, 63, addScToInput, outputInts1));
2722 cases.push_back(SpecConstantTwoIntCase("bitwiseor", " %i32 0", " %i32 0", "%i32", "BitwiseOr %sc_0 %sc_1", 34, 8, addScToInput, outputInts1));
2723 cases.push_back(SpecConstantTwoIntCase("bitwisexor", " %i32 0", " %i32 0", "%i32", "BitwiseXor %sc_0 %sc_1", 18, 56, addScToInput, outputInts1));
2724 cases.push_back(SpecConstantTwoIntCase("shiftrightlogical", " %i32 0", " %i32 0", "%i32", "ShiftRightLogical %sc_0 %sc_1", 168, 2, addScToInput, outputInts1));
2725 cases.push_back(SpecConstantTwoIntCase("shiftrightarithmetic", " %i32 0", " %i32 0", "%i32", "ShiftRightArithmetic %sc_0 %sc_1", 168, 2, addScToInput, outputInts1));
2726 cases.push_back(SpecConstantTwoIntCase("shiftleftlogical", " %i32 0", " %i32 0", "%i32", "ShiftLeftLogical %sc_0 %sc_1", 21, 1, addScToInput, outputInts1));
2727 cases.push_back(SpecConstantTwoIntCase("slessthan", " %i32 0", " %i32 0", "%bool", "SLessThan %sc_0 %sc_1", -20, -10, selectTrueUsingSc, outputInts2));
2728 cases.push_back(SpecConstantTwoIntCase("ulessthan", " %i32 0", " %i32 0", "%bool", "ULessThan %sc_0 %sc_1", 10, 20, selectTrueUsingSc, outputInts2));
2729 cases.push_back(SpecConstantTwoIntCase("sgreaterthan", " %i32 0", " %i32 0", "%bool", "SGreaterThan %sc_0 %sc_1", -1000, 50, selectFalseUsingSc, outputInts2));
2730 cases.push_back(SpecConstantTwoIntCase("ugreaterthan", " %i32 0", " %i32 0", "%bool", "UGreaterThan %sc_0 %sc_1", 10, 5, selectTrueUsingSc, outputInts2));
2731 cases.push_back(SpecConstantTwoIntCase("slessthanequal", " %i32 0", " %i32 0", "%bool", "SLessThanEqual %sc_0 %sc_1", -10, -10, selectTrueUsingSc, outputInts2));
2732 cases.push_back(SpecConstantTwoIntCase("ulessthanequal", " %i32 0", " %i32 0", "%bool", "ULessThanEqual %sc_0 %sc_1", 50, 100, selectTrueUsingSc, outputInts2));
2733 cases.push_back(SpecConstantTwoIntCase("sgreaterthanequal", " %i32 0", " %i32 0", "%bool", "SGreaterThanEqual %sc_0 %sc_1", -1000, 50, selectFalseUsingSc, outputInts2));
2734 cases.push_back(SpecConstantTwoIntCase("ugreaterthanequal", " %i32 0", " %i32 0", "%bool", "UGreaterThanEqual %sc_0 %sc_1", 10, 10, selectTrueUsingSc, outputInts2));
2735 cases.push_back(SpecConstantTwoIntCase("iequal", " %i32 0", " %i32 0", "%bool", "IEqual %sc_0 %sc_1", 42, 24, selectFalseUsingSc, outputInts2));
2736 cases.push_back(SpecConstantTwoIntCase("logicaland", "True %bool", "True %bool", "%bool", "LogicalAnd %sc_0 %sc_1", 0, 1, selectFalseUsingSc, outputInts2));
2737 cases.push_back(SpecConstantTwoIntCase("logicalor", "False %bool", "False %bool", "%bool", "LogicalOr %sc_0 %sc_1", 1, 0, selectTrueUsingSc, outputInts2));
2738 cases.push_back(SpecConstantTwoIntCase("logicalequal", "True %bool", "True %bool", "%bool", "LogicalEqual %sc_0 %sc_1", 0, 1, selectFalseUsingSc, outputInts2));
2739 cases.push_back(SpecConstantTwoIntCase("logicalnotequal", "False %bool", "False %bool", "%bool", "LogicalNotEqual %sc_0 %sc_1", 1, 0, selectTrueUsingSc, outputInts2));
2740 cases.push_back(SpecConstantTwoIntCase("snegate", " %i32 0", " %i32 0", "%i32", "SNegate %sc_0", -42, 0, addScToInput, outputInts1));
2741 cases.push_back(SpecConstantTwoIntCase("not", " %i32 0", " %i32 0", "%i32", "Not %sc_0", -43, 0, addScToInput, outputInts1));
2742 cases.push_back(SpecConstantTwoIntCase("logicalnot", "False %bool", "False %bool", "%bool", "LogicalNot %sc_0", 1, 0, selectFalseUsingSc, outputInts2));
2743 cases.push_back(SpecConstantTwoIntCase("select", "False %bool", " %i32 0", "%i32", "Select %sc_0 %sc_1 %zero", 1, 42, addScToInput, outputInts1));
2744 cases.push_back(SpecConstantTwoIntCase("sconvert", " %i32 0", " %i32 0", "%i16", "SConvert %sc_0", -11200, 0, addSc32ToInput, outputInts3));
2745 // -969998336 stored as 32-bit two's complement is the binary representation of -11200 as IEEE-754 Float
2746 cases.push_back(SpecConstantTwoIntCase("fconvert", " %f32 0", " %f32 0", "%f64", "FConvert %sc_0", -969998336, 0, addSc32ToInput, outputInts3));
2748 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
2750 map<string, string> specializations;
2751 ComputeShaderSpec spec;
2752 ComputeTestFeatures features = COMPUTE_TEST_USES_NONE;
2754 specializations["SC_DEF0"] = cases[caseNdx].scDefinition0;
2755 specializations["SC_DEF1"] = cases[caseNdx].scDefinition1;
2756 specializations["SC_RESULT_TYPE"] = cases[caseNdx].scResultType;
2757 specializations["SC_OP"] = cases[caseNdx].scOperation;
2758 specializations["GEN_RESULT"] = cases[caseNdx].resultOperation;
2760 // Special SPIR-V code for SConvert-case
2761 if (strcmp(cases[caseNdx].caseName, "sconvert") == 0)
2763 features = COMPUTE_TEST_USES_INT16;
2764 specializations["CAPABILITIES"] = "OpCapability Int16\n"; // Adds 16-bit integer capability
2765 specializations["OPTYPE_DEFINITIONS"] = "%i16 = OpTypeInt 16 1\n"; // Adds 16-bit integer type
2766 specializations["TYPE_CONVERT"] = "%sc_final32 = OpSConvert %i32 %sc_final\n"; // Converts 16-bit integer to 32-bit integer
2769 // Special SPIR-V code for FConvert-case
2770 if (strcmp(cases[caseNdx].caseName, "fconvert") == 0)
2772 features = COMPUTE_TEST_USES_FLOAT64;
2773 specializations["CAPABILITIES"] = "OpCapability Float64\n"; // Adds 64-bit float capability
2774 specializations["OPTYPE_DEFINITIONS"] = "%f64 = OpTypeFloat 64\n"; // Adds 64-bit float type
2775 specializations["TYPE_CONVERT"] = "%sc_final32 = OpConvertFToS %i32 %sc_final\n"; // Converts 64-bit float to 32-bit integer
2778 spec.assembly = shaderTemplate.specialize(specializations);
2779 spec.inputs.push_back(BufferSp(new Int32Buffer(inputInts)));
2780 spec.outputs.push_back(BufferSp(new Int32Buffer(cases[caseNdx].expectedOutput)));
2781 spec.numWorkGroups = IVec3(numElements, 1, 1);
2782 spec.specConstants.push_back(cases[caseNdx].scActualValue0);
2783 spec.specConstants.push_back(cases[caseNdx].scActualValue1);
2785 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].caseName, cases[caseNdx].caseName, spec, features));
2788 ComputeShaderSpec spec;
2791 string(getComputeAsmShaderPreamble()) +
2793 "OpName %main \"main\"\n"
2794 "OpName %id \"gl_GlobalInvocationID\"\n"
2796 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2797 "OpDecorate %sc_0 SpecId 0\n"
2798 "OpDecorate %sc_1 SpecId 1\n"
2799 "OpDecorate %sc_2 SpecId 2\n"
2800 "OpDecorate %i32arr ArrayStride 4\n"
2802 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
2804 "%ivec3 = OpTypeVector %i32 3\n"
2805 "%buf = OpTypeStruct %i32arr\n"
2806 "%bufptr = OpTypePointer Uniform %buf\n"
2807 "%indata = OpVariable %bufptr Uniform\n"
2808 "%outdata = OpVariable %bufptr Uniform\n"
2810 "%id = OpVariable %uvec3ptr Input\n"
2811 "%zero = OpConstant %i32 0\n"
2812 "%ivec3_0 = OpConstantComposite %ivec3 %zero %zero %zero\n"
2813 "%vec3_undef = OpUndef %ivec3\n"
2815 "%sc_0 = OpSpecConstant %i32 0\n"
2816 "%sc_1 = OpSpecConstant %i32 0\n"
2817 "%sc_2 = OpSpecConstant %i32 0\n"
2818 "%sc_vec3_0 = OpSpecConstantOp %ivec3 CompositeInsert %sc_0 %ivec3_0 0\n" // (sc_0, 0, 0)
2819 "%sc_vec3_1 = OpSpecConstantOp %ivec3 CompositeInsert %sc_1 %ivec3_0 1\n" // (0, sc_1, 0)
2820 "%sc_vec3_2 = OpSpecConstantOp %ivec3 CompositeInsert %sc_2 %ivec3_0 2\n" // (0, 0, sc_2)
2821 "%sc_vec3_0_s = OpSpecConstantOp %ivec3 VectorShuffle %sc_vec3_0 %vec3_undef 0 0xFFFFFFFF 2\n" // (sc_0, ???, 0)
2822 "%sc_vec3_1_s = OpSpecConstantOp %ivec3 VectorShuffle %sc_vec3_1 %vec3_undef 0xFFFFFFFF 1 0\n" // (???, sc_1, 0)
2823 "%sc_vec3_2_s = OpSpecConstantOp %ivec3 VectorShuffle %vec3_undef %sc_vec3_2 5 0xFFFFFFFF 5\n" // (sc_2, ???, sc_2)
2824 "%sc_vec3_01 = OpSpecConstantOp %ivec3 VectorShuffle %sc_vec3_0_s %sc_vec3_1_s 1 0 4\n" // (0, sc_0, sc_1)
2825 "%sc_vec3_012 = OpSpecConstantOp %ivec3 VectorShuffle %sc_vec3_01 %sc_vec3_2_s 5 1 2\n" // (sc_2, sc_0, sc_1)
2826 "%sc_ext_0 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 0\n" // sc_2
2827 "%sc_ext_1 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 1\n" // sc_0
2828 "%sc_ext_2 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 2\n" // sc_1
2829 "%sc_sub = OpSpecConstantOp %i32 ISub %sc_ext_0 %sc_ext_1\n" // (sc_2 - sc_0)
2830 "%sc_final = OpSpecConstantOp %i32 IMul %sc_sub %sc_ext_2\n" // (sc_2 - sc_0) * sc_1
2832 "%main = OpFunction %void None %voidf\n"
2833 "%label = OpLabel\n"
2834 "%idval = OpLoad %uvec3 %id\n"
2835 "%x = OpCompositeExtract %u32 %idval 0\n"
2836 "%inloc = OpAccessChain %i32ptr %indata %zero %x\n"
2837 "%inval = OpLoad %i32 %inloc\n"
2838 "%final = OpIAdd %i32 %inval %sc_final\n"
2839 "%outloc = OpAccessChain %i32ptr %outdata %zero %x\n"
2840 " OpStore %outloc %final\n"
2843 spec.inputs.push_back(BufferSp(new Int32Buffer(inputInts)));
2844 spec.outputs.push_back(BufferSp(new Int32Buffer(outputInts3)));
2845 spec.numWorkGroups = IVec3(numElements, 1, 1);
2846 spec.specConstants.push_back(123);
2847 spec.specConstants.push_back(56);
2848 spec.specConstants.push_back(-77);
2850 group->addChild(new SpvAsmComputeShaderCase(testCtx, "vector_related", "VectorShuffle, CompositeExtract, & CompositeInsert", spec));
2852 return group.release();
2855 void createOpPhiVartypeTests (de::MovePtr<tcu::TestCaseGroup>& group, tcu::TestContext& testCtx)
2857 ComputeShaderSpec specInt;
2858 ComputeShaderSpec specFloat;
2859 ComputeShaderSpec specVec3;
2860 ComputeShaderSpec specMat4;
2861 ComputeShaderSpec specArray;
2862 ComputeShaderSpec specStruct;
2863 de::Random rnd (deStringHash(group->getName()));
2864 const int numElements = 100;
2865 vector<float> inputFloats (numElements, 0);
2866 vector<float> outputFloats (numElements, 0);
2868 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats[0], numElements);
2870 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
2871 floorAll(inputFloats);
2873 for (size_t ndx = 0; ndx < numElements; ++ndx)
2875 // Just check if the value is positive or not
2876 outputFloats[ndx] = (inputFloats[ndx] > 0) ? 1.0f : -1.0f;
2879 // All of the tests are of the form:
2883 // if (inputdata > 0)
2890 specFloat.assembly =
2891 string(getComputeAsmShaderPreamble()) +
2893 "OpSource GLSL 430\n"
2894 "OpName %main \"main\"\n"
2895 "OpName %id \"gl_GlobalInvocationID\"\n"
2897 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2899 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
2901 "%id = OpVariable %uvec3ptr Input\n"
2902 "%zero = OpConstant %i32 0\n"
2903 "%float_0 = OpConstant %f32 0.0\n"
2904 "%float_1 = OpConstant %f32 1.0\n"
2905 "%float_n1 = OpConstant %f32 -1.0\n"
2907 "%main = OpFunction %void None %voidf\n"
2908 "%entry = OpLabel\n"
2909 "%idval = OpLoad %uvec3 %id\n"
2910 "%x = OpCompositeExtract %u32 %idval 0\n"
2911 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
2912 "%inval = OpLoad %f32 %inloc\n"
2914 "%comp = OpFOrdGreaterThan %bool %inval %float_0\n"
2915 " OpSelectionMerge %cm None\n"
2916 " OpBranchConditional %comp %tb %fb\n"
2922 "%res = OpPhi %f32 %float_1 %tb %float_n1 %fb\n"
2924 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2925 " OpStore %outloc %res\n"
2929 specFloat.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
2930 specFloat.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
2931 specFloat.numWorkGroups = IVec3(numElements, 1, 1);
2934 string(getComputeAsmShaderPreamble()) +
2936 "OpSource GLSL 430\n"
2937 "OpName %main \"main\"\n"
2938 "OpName %id \"gl_GlobalInvocationID\"\n"
2940 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2942 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
2944 "%id = OpVariable %uvec3ptr Input\n"
2945 "%v4f32 = OpTypeVector %f32 4\n"
2946 "%mat4v4f32 = OpTypeMatrix %v4f32 4\n"
2947 "%zero = OpConstant %i32 0\n"
2948 "%float_0 = OpConstant %f32 0.0\n"
2949 "%float_1 = OpConstant %f32 1.0\n"
2950 "%float_n1 = OpConstant %f32 -1.0\n"
2951 "%m11 = OpConstantComposite %v4f32 %float_1 %float_0 %float_0 %float_0\n"
2952 "%m12 = OpConstantComposite %v4f32 %float_0 %float_1 %float_0 %float_0\n"
2953 "%m13 = OpConstantComposite %v4f32 %float_0 %float_0 %float_1 %float_0\n"
2954 "%m14 = OpConstantComposite %v4f32 %float_0 %float_0 %float_0 %float_1\n"
2955 "%m1 = OpConstantComposite %mat4v4f32 %m11 %m12 %m13 %m14\n"
2956 "%m21 = OpConstantComposite %v4f32 %float_n1 %float_0 %float_0 %float_0\n"
2957 "%m22 = OpConstantComposite %v4f32 %float_0 %float_n1 %float_0 %float_0\n"
2958 "%m23 = OpConstantComposite %v4f32 %float_0 %float_0 %float_n1 %float_0\n"
2959 "%m24 = OpConstantComposite %v4f32 %float_0 %float_0 %float_0 %float_n1\n"
2960 "%m2 = OpConstantComposite %mat4v4f32 %m21 %m22 %m23 %m24\n"
2962 "%main = OpFunction %void None %voidf\n"
2963 "%entry = OpLabel\n"
2964 "%idval = OpLoad %uvec3 %id\n"
2965 "%x = OpCompositeExtract %u32 %idval 0\n"
2966 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
2967 "%inval = OpLoad %f32 %inloc\n"
2969 "%comp = OpFOrdGreaterThan %bool %inval %float_0\n"
2970 " OpSelectionMerge %cm None\n"
2971 " OpBranchConditional %comp %tb %fb\n"
2977 "%mres = OpPhi %mat4v4f32 %m1 %tb %m2 %fb\n"
2978 "%res = OpCompositeExtract %f32 %mres 2 2\n"
2980 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2981 " OpStore %outloc %res\n"
2985 specMat4.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
2986 specMat4.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
2987 specMat4.numWorkGroups = IVec3(numElements, 1, 1);
2990 string(getComputeAsmShaderPreamble()) +
2992 "OpSource GLSL 430\n"
2993 "OpName %main \"main\"\n"
2994 "OpName %id \"gl_GlobalInvocationID\"\n"
2996 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2998 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
3000 "%id = OpVariable %uvec3ptr Input\n"
3001 "%zero = OpConstant %i32 0\n"
3002 "%float_0 = OpConstant %f32 0.0\n"
3003 "%float_1 = OpConstant %f32 1.0\n"
3004 "%float_n1 = OpConstant %f32 -1.0\n"
3005 "%v1 = OpConstantComposite %fvec3 %float_1 %float_1 %float_1\n"
3006 "%v2 = OpConstantComposite %fvec3 %float_n1 %float_n1 %float_n1\n"
3008 "%main = OpFunction %void None %voidf\n"
3009 "%entry = OpLabel\n"
3010 "%idval = OpLoad %uvec3 %id\n"
3011 "%x = OpCompositeExtract %u32 %idval 0\n"
3012 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3013 "%inval = OpLoad %f32 %inloc\n"
3015 "%comp = OpFOrdGreaterThan %bool %inval %float_0\n"
3016 " OpSelectionMerge %cm None\n"
3017 " OpBranchConditional %comp %tb %fb\n"
3023 "%vres = OpPhi %fvec3 %v1 %tb %v2 %fb\n"
3024 "%res = OpCompositeExtract %f32 %vres 2\n"
3026 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3027 " OpStore %outloc %res\n"
3031 specVec3.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
3032 specVec3.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
3033 specVec3.numWorkGroups = IVec3(numElements, 1, 1);
3036 string(getComputeAsmShaderPreamble()) +
3038 "OpSource GLSL 430\n"
3039 "OpName %main \"main\"\n"
3040 "OpName %id \"gl_GlobalInvocationID\"\n"
3042 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3044 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
3046 "%id = OpVariable %uvec3ptr Input\n"
3047 "%zero = OpConstant %i32 0\n"
3048 "%float_0 = OpConstant %f32 0.0\n"
3049 "%i1 = OpConstant %i32 1\n"
3050 "%i2 = OpConstant %i32 -1\n"
3052 "%main = OpFunction %void None %voidf\n"
3053 "%entry = OpLabel\n"
3054 "%idval = OpLoad %uvec3 %id\n"
3055 "%x = OpCompositeExtract %u32 %idval 0\n"
3056 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3057 "%inval = OpLoad %f32 %inloc\n"
3059 "%comp = OpFOrdGreaterThan %bool %inval %float_0\n"
3060 " OpSelectionMerge %cm None\n"
3061 " OpBranchConditional %comp %tb %fb\n"
3067 "%ires = OpPhi %i32 %i1 %tb %i2 %fb\n"
3068 "%res = OpConvertSToF %f32 %ires\n"
3070 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3071 " OpStore %outloc %res\n"
3075 specInt.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
3076 specInt.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
3077 specInt.numWorkGroups = IVec3(numElements, 1, 1);
3079 specArray.assembly =
3080 string(getComputeAsmShaderPreamble()) +
3082 "OpSource GLSL 430\n"
3083 "OpName %main \"main\"\n"
3084 "OpName %id \"gl_GlobalInvocationID\"\n"
3086 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3088 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
3090 "%id = OpVariable %uvec3ptr Input\n"
3091 "%zero = OpConstant %i32 0\n"
3092 "%u7 = OpConstant %u32 7\n"
3093 "%float_0 = OpConstant %f32 0.0\n"
3094 "%float_1 = OpConstant %f32 1.0\n"
3095 "%float_n1 = OpConstant %f32 -1.0\n"
3096 "%f32a7 = OpTypeArray %f32 %u7\n"
3097 "%a1 = OpConstantComposite %f32a7 %float_1 %float_1 %float_1 %float_1 %float_1 %float_1 %float_1\n"
3098 "%a2 = OpConstantComposite %f32a7 %float_n1 %float_n1 %float_n1 %float_n1 %float_n1 %float_n1 %float_n1\n"
3099 "%main = OpFunction %void None %voidf\n"
3100 "%entry = OpLabel\n"
3101 "%idval = OpLoad %uvec3 %id\n"
3102 "%x = OpCompositeExtract %u32 %idval 0\n"
3103 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3104 "%inval = OpLoad %f32 %inloc\n"
3106 "%comp = OpFOrdGreaterThan %bool %inval %float_0\n"
3107 " OpSelectionMerge %cm None\n"
3108 " OpBranchConditional %comp %tb %fb\n"
3114 "%ares = OpPhi %f32a7 %a1 %tb %a2 %fb\n"
3115 "%res = OpCompositeExtract %f32 %ares 5\n"
3117 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3118 " OpStore %outloc %res\n"
3122 specArray.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
3123 specArray.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
3124 specArray.numWorkGroups = IVec3(numElements, 1, 1);
3126 specStruct.assembly =
3127 string(getComputeAsmShaderPreamble()) +
3129 "OpSource GLSL 430\n"
3130 "OpName %main \"main\"\n"
3131 "OpName %id \"gl_GlobalInvocationID\"\n"
3133 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3135 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
3137 "%id = OpVariable %uvec3ptr Input\n"
3138 "%zero = OpConstant %i32 0\n"
3139 "%float_0 = OpConstant %f32 0.0\n"
3140 "%float_1 = OpConstant %f32 1.0\n"
3141 "%float_n1 = OpConstant %f32 -1.0\n"
3143 "%v2f32 = OpTypeVector %f32 2\n"
3144 "%Data2 = OpTypeStruct %f32 %v2f32\n"
3145 "%Data = OpTypeStruct %Data2 %f32\n"
3147 "%in1a = OpConstantComposite %v2f32 %float_1 %float_1\n"
3148 "%in1b = OpConstantComposite %Data2 %float_1 %in1a\n"
3149 "%s1 = OpConstantComposite %Data %in1b %float_1\n"
3150 "%in2a = OpConstantComposite %v2f32 %float_n1 %float_n1\n"
3151 "%in2b = OpConstantComposite %Data2 %float_n1 %in2a\n"
3152 "%s2 = OpConstantComposite %Data %in2b %float_n1\n"
3154 "%main = OpFunction %void None %voidf\n"
3155 "%entry = OpLabel\n"
3156 "%idval = OpLoad %uvec3 %id\n"
3157 "%x = OpCompositeExtract %u32 %idval 0\n"
3158 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3159 "%inval = OpLoad %f32 %inloc\n"
3161 "%comp = OpFOrdGreaterThan %bool %inval %float_0\n"
3162 " OpSelectionMerge %cm None\n"
3163 " OpBranchConditional %comp %tb %fb\n"
3169 "%sres = OpPhi %Data %s1 %tb %s2 %fb\n"
3170 "%res = OpCompositeExtract %f32 %sres 0 0\n"
3172 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3173 " OpStore %outloc %res\n"
3177 specStruct.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
3178 specStruct.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
3179 specStruct.numWorkGroups = IVec3(numElements, 1, 1);
3181 group->addChild(new SpvAsmComputeShaderCase(testCtx, "vartype_int", "OpPhi with int variables", specInt));
3182 group->addChild(new SpvAsmComputeShaderCase(testCtx, "vartype_float", "OpPhi with float variables", specFloat));
3183 group->addChild(new SpvAsmComputeShaderCase(testCtx, "vartype_vec3", "OpPhi with vec3 variables", specVec3));
3184 group->addChild(new SpvAsmComputeShaderCase(testCtx, "vartype_mat4", "OpPhi with mat4 variables", specMat4));
3185 group->addChild(new SpvAsmComputeShaderCase(testCtx, "vartype_array", "OpPhi with array variables", specArray));
3186 group->addChild(new SpvAsmComputeShaderCase(testCtx, "vartype_struct", "OpPhi with struct variables", specStruct));
3189 string generateConstantDefinitions (int count)
3191 std::ostringstream r;
3192 for (int i = 0; i < count; i++)
3193 r << "%cf" << (i * 10 + 5) << " = OpConstant %f32 " <<(i * 10 + 5) << ".0\n";
3198 string generateSwitchCases (int count)
3200 std::ostringstream r;
3201 for (int i = 0; i < count; i++)
3202 r << " " << i << " %case" << i;
3207 string generateSwitchTargets (int count)
3209 std::ostringstream r;
3210 for (int i = 0; i < count; i++)
3211 r << "%case" << i << " = OpLabel\n OpBranch %phi\n";
3216 string generateOpPhiParams (int count)
3218 std::ostringstream r;
3219 for (int i = 0; i < count; i++)
3220 r << " %cf" << (i * 10 + 5) << " %case" << i;
3225 string generateIntWidth (int value)
3227 std::ostringstream r;
3232 // Expand input string by injecting "ABC" between the input
3233 // string characters. The acc/add/treshold parameters are used
3234 // to skip some of the injections to make the result less
3235 // uniform (and a lot shorter).
3236 string expandOpPhiCase5 (const string& s, int &acc, int add, int treshold)
3238 std::ostringstream res;
3239 const char* p = s.c_str();
3255 // Calculate expected result based on the code string
3256 float calcOpPhiCase5 (float val, const string& s)
3258 const char* p = s.c_str();
3261 const float tv[8] = { 0.5f, 1.5f, 3.5f, 7.5f, 15.5f, 31.5f, 63.5f, 127.5f };
3262 const float v = deFloatAbs(val);
3267 for (int i = 7; i >= 0; --i)
3268 x[i] = std::fmod((float)v, (float)(2 << i));
3269 for (int i = 7; i >= 0; --i)
3270 b[i] = x[i] > tv[i];
3277 if (skip == 0 && b[depth])
3288 if (b[depth] || skip)
3302 // In the code string, the letters represent the following:
3305 // if (certain bit is set)
3316 // AABCBC leads to if(){r++;if(){r++;}else{}}else{}
3317 // ABABCC leads to if(){r++;}else{if(){r++;}else{}}
3318 // ABCABC leads to if(){r++;}else{}if(){r++;}else{}
3320 // Code generation gets a bit complicated due to the else-branches,
3321 // which do not generate new values. Thus, the generator needs to
3322 // keep track of the previous variable change seen by the else
3324 string generateOpPhiCase5 (const string& s)
3326 std::stack<int> idStack;
3327 std::stack<std::string> value;
3328 std::stack<std::string> valueLabel;
3329 std::stack<std::string> mergeLeft;
3330 std::stack<std::string> mergeRight;
3331 std::ostringstream res;
3332 const char* p = s.c_str();
3338 value.push("%f32_0");
3339 valueLabel.push("%f32_0 %entry");
3347 idStack.push(currId);
3348 res << "\tOpSelectionMerge %m" << currId << " None\n";
3349 res << "\tOpBranchConditional %b" << depth << " %t" << currId << " %f" << currId << "\n";
3350 res << "%t" << currId << " = OpLabel\n";
3351 res << "%rt" << currId << " = OpFAdd %f32 " << value.top() << " %f32_1\n";
3352 std::ostringstream tag;
3353 tag << "%rt" << currId;
3354 value.push(tag.str());
3355 tag << " %t" << currId;
3356 valueLabel.push(tag.str());
3361 mergeLeft.push(valueLabel.top());
3364 res << "\tOpBranch %m" << currId << "\n";
3365 res << "%f" << currId << " = OpLabel\n";
3366 std::ostringstream tag;
3367 tag << value.top() << " %f" << currId;
3369 valueLabel.push(tag.str());
3374 mergeRight.push(valueLabel.top());
3375 res << "\tOpBranch %m" << currId << "\n";
3376 res << "%m" << currId << " = OpLabel\n";
3378 res << "%res"; // last result goes to %res
3380 res << "%rm" << currId;
3381 res << " = OpPhi %f32 " << mergeLeft.top() << " " << mergeRight.top() << "\n";
3382 std::ostringstream tag;
3383 tag << "%rm" << currId;
3385 value.push(tag.str());
3386 tag << " %m" << currId;
3388 valueLabel.push(tag.str());
3393 currId = idStack.top();
3401 tcu::TestCaseGroup* createOpPhiGroup (tcu::TestContext& testCtx)
3403 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opphi", "Test the OpPhi instruction"));
3404 ComputeShaderSpec spec1;
3405 ComputeShaderSpec spec2;
3406 ComputeShaderSpec spec3;
3407 ComputeShaderSpec spec4;
3408 ComputeShaderSpec spec5;
3409 de::Random rnd (deStringHash(group->getName()));
3410 const int numElements = 100;
3411 vector<float> inputFloats (numElements, 0);
3412 vector<float> outputFloats1 (numElements, 0);
3413 vector<float> outputFloats2 (numElements, 0);
3414 vector<float> outputFloats3 (numElements, 0);
3415 vector<float> outputFloats4 (numElements, 0);
3416 vector<float> outputFloats5 (numElements, 0);
3417 std::string codestring = "ABC";
3418 const int test4Width = 1024;
3420 // Build case 5 code string. Each iteration makes the hierarchy more complicated.
3421 // 9 iterations with (7, 24) parameters makes the hierarchy 8 deep with about 1500 lines of
3423 for (int i = 0, acc = 0; i < 9; i++)
3424 codestring = expandOpPhiCase5(codestring, acc, 7, 24);
3426 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats[0], numElements);
3428 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
3429 floorAll(inputFloats);
3431 for (size_t ndx = 0; ndx < numElements; ++ndx)
3435 case 0: outputFloats1[ndx] = inputFloats[ndx] + 5.5f; break;
3436 case 1: outputFloats1[ndx] = inputFloats[ndx] + 20.5f; break;
3437 case 2: outputFloats1[ndx] = inputFloats[ndx] + 1.75f; break;
3440 outputFloats2[ndx] = inputFloats[ndx] + 6.5f * 3;
3441 outputFloats3[ndx] = 8.5f - inputFloats[ndx];
3443 int index4 = (int)deFloor(deAbs((float)ndx * inputFloats[ndx]));
3444 outputFloats4[ndx] = (float)(index4 % test4Width) * 10.0f + 5.0f;
3446 outputFloats5[ndx] = calcOpPhiCase5(inputFloats[ndx], codestring);
3450 string(getComputeAsmShaderPreamble()) +
3452 "OpSource GLSL 430\n"
3453 "OpName %main \"main\"\n"
3454 "OpName %id \"gl_GlobalInvocationID\"\n"
3456 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3458 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
3460 "%id = OpVariable %uvec3ptr Input\n"
3461 "%zero = OpConstant %i32 0\n"
3462 "%three = OpConstant %u32 3\n"
3463 "%constf5p5 = OpConstant %f32 5.5\n"
3464 "%constf20p5 = OpConstant %f32 20.5\n"
3465 "%constf1p75 = OpConstant %f32 1.75\n"
3466 "%constf8p5 = OpConstant %f32 8.5\n"
3467 "%constf6p5 = OpConstant %f32 6.5\n"
3469 "%main = OpFunction %void None %voidf\n"
3470 "%entry = OpLabel\n"
3471 "%idval = OpLoad %uvec3 %id\n"
3472 "%x = OpCompositeExtract %u32 %idval 0\n"
3473 "%selector = OpUMod %u32 %x %three\n"
3474 " OpSelectionMerge %phi None\n"
3475 " OpSwitch %selector %default 0 %case0 1 %case1 2 %case2\n"
3477 // Case 1 before OpPhi.
3478 "%case1 = OpLabel\n"
3481 "%default = OpLabel\n"
3485 "%operand = OpPhi %f32 %constf1p75 %case2 %constf20p5 %case1 %constf5p5 %case0\n" // not in the order of blocks
3486 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3487 "%inval = OpLoad %f32 %inloc\n"
3488 "%add = OpFAdd %f32 %inval %operand\n"
3489 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3490 " OpStore %outloc %add\n"
3493 // Case 0 after OpPhi.
3494 "%case0 = OpLabel\n"
3498 // Case 2 after OpPhi.
3499 "%case2 = OpLabel\n"
3503 spec1.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
3504 spec1.outputs.push_back(BufferSp(new Float32Buffer(outputFloats1)));
3505 spec1.numWorkGroups = IVec3(numElements, 1, 1);
3507 group->addChild(new SpvAsmComputeShaderCase(testCtx, "block", "out-of-order and unreachable blocks for OpPhi", spec1));
3510 string(getComputeAsmShaderPreamble()) +
3512 "OpName %main \"main\"\n"
3513 "OpName %id \"gl_GlobalInvocationID\"\n"
3515 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3517 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
3519 "%id = OpVariable %uvec3ptr Input\n"
3520 "%zero = OpConstant %i32 0\n"
3521 "%one = OpConstant %i32 1\n"
3522 "%three = OpConstant %i32 3\n"
3523 "%constf6p5 = OpConstant %f32 6.5\n"
3525 "%main = OpFunction %void None %voidf\n"
3526 "%entry = OpLabel\n"
3527 "%idval = OpLoad %uvec3 %id\n"
3528 "%x = OpCompositeExtract %u32 %idval 0\n"
3529 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3530 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3531 "%inval = OpLoad %f32 %inloc\n"
3535 "%step = OpPhi %i32 %zero %entry %step_next %phi\n"
3536 "%accum = OpPhi %f32 %inval %entry %accum_next %phi\n"
3537 "%step_next = OpIAdd %i32 %step %one\n"
3538 "%accum_next = OpFAdd %f32 %accum %constf6p5\n"
3539 "%still_loop = OpSLessThan %bool %step %three\n"
3540 " OpLoopMerge %exit %phi None\n"
3541 " OpBranchConditional %still_loop %phi %exit\n"
3544 " OpStore %outloc %accum\n"
3547 spec2.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
3548 spec2.outputs.push_back(BufferSp(new Float32Buffer(outputFloats2)));
3549 spec2.numWorkGroups = IVec3(numElements, 1, 1);
3551 group->addChild(new SpvAsmComputeShaderCase(testCtx, "induction", "The usual way induction variables are handled in LLVM IR", spec2));
3554 string(getComputeAsmShaderPreamble()) +
3556 "OpName %main \"main\"\n"
3557 "OpName %id \"gl_GlobalInvocationID\"\n"
3559 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3561 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
3563 "%f32ptr_f = OpTypePointer Function %f32\n"
3564 "%id = OpVariable %uvec3ptr Input\n"
3565 "%true = OpConstantTrue %bool\n"
3566 "%false = OpConstantFalse %bool\n"
3567 "%zero = OpConstant %i32 0\n"
3568 "%constf8p5 = OpConstant %f32 8.5\n"
3570 "%main = OpFunction %void None %voidf\n"
3571 "%entry = OpLabel\n"
3572 "%b = OpVariable %f32ptr_f Function %constf8p5\n"
3573 "%idval = OpLoad %uvec3 %id\n"
3574 "%x = OpCompositeExtract %u32 %idval 0\n"
3575 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3576 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3577 "%a_init = OpLoad %f32 %inloc\n"
3578 "%b_init = OpLoad %f32 %b\n"
3582 "%still_loop = OpPhi %bool %true %entry %false %phi\n"
3583 "%a_next = OpPhi %f32 %a_init %entry %b_next %phi\n"
3584 "%b_next = OpPhi %f32 %b_init %entry %a_next %phi\n"
3585 " OpLoopMerge %exit %phi None\n"
3586 " OpBranchConditional %still_loop %phi %exit\n"
3589 "%sub = OpFSub %f32 %a_next %b_next\n"
3590 " OpStore %outloc %sub\n"
3593 spec3.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
3594 spec3.outputs.push_back(BufferSp(new Float32Buffer(outputFloats3)));
3595 spec3.numWorkGroups = IVec3(numElements, 1, 1);
3597 group->addChild(new SpvAsmComputeShaderCase(testCtx, "swap", "Swap the values of two variables using OpPhi", spec3));
3600 "OpCapability Shader\n"
3601 "%ext = OpExtInstImport \"GLSL.std.450\"\n"
3602 "OpMemoryModel Logical GLSL450\n"
3603 "OpEntryPoint GLCompute %main \"main\" %id\n"
3604 "OpExecutionMode %main LocalSize 1 1 1\n"
3606 "OpSource GLSL 430\n"
3607 "OpName %main \"main\"\n"
3608 "OpName %id \"gl_GlobalInvocationID\"\n"
3610 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3612 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
3614 "%id = OpVariable %uvec3ptr Input\n"
3615 "%zero = OpConstant %i32 0\n"
3616 "%cimod = OpConstant %u32 " + generateIntWidth(test4Width) + "\n"
3618 + generateConstantDefinitions(test4Width) +
3620 "%main = OpFunction %void None %voidf\n"
3621 "%entry = OpLabel\n"
3622 "%idval = OpLoad %uvec3 %id\n"
3623 "%x = OpCompositeExtract %u32 %idval 0\n"
3624 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3625 "%inval = OpLoad %f32 %inloc\n"
3626 "%xf = OpConvertUToF %f32 %x\n"
3627 "%xm = OpFMul %f32 %xf %inval\n"
3628 "%xa = OpExtInst %f32 %ext FAbs %xm\n"
3629 "%xi = OpConvertFToU %u32 %xa\n"
3630 "%selector = OpUMod %u32 %xi %cimod\n"
3631 " OpSelectionMerge %phi None\n"
3632 " OpSwitch %selector %default "
3634 + generateSwitchCases(test4Width) +
3636 "%default = OpLabel\n"
3639 + generateSwitchTargets(test4Width) +
3642 "%result = OpPhi %f32"
3644 + generateOpPhiParams(test4Width) +
3646 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3647 " OpStore %outloc %result\n"
3651 spec4.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
3652 spec4.outputs.push_back(BufferSp(new Float32Buffer(outputFloats4)));
3653 spec4.numWorkGroups = IVec3(numElements, 1, 1);
3655 group->addChild(new SpvAsmComputeShaderCase(testCtx, "wide", "OpPhi with a lot of parameters", spec4));
3658 "OpCapability Shader\n"
3659 "%ext = OpExtInstImport \"GLSL.std.450\"\n"
3660 "OpMemoryModel Logical GLSL450\n"
3661 "OpEntryPoint GLCompute %main \"main\" %id\n"
3662 "OpExecutionMode %main LocalSize 1 1 1\n"
3663 "%code = OpString \"" + codestring + "\"\n"
3665 "OpSource GLSL 430\n"
3666 "OpName %main \"main\"\n"
3667 "OpName %id \"gl_GlobalInvocationID\"\n"
3669 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3671 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
3673 "%id = OpVariable %uvec3ptr Input\n"
3674 "%zero = OpConstant %i32 0\n"
3675 "%f32_0 = OpConstant %f32 0.0\n"
3676 "%f32_0_5 = OpConstant %f32 0.5\n"
3677 "%f32_1 = OpConstant %f32 1.0\n"
3678 "%f32_1_5 = OpConstant %f32 1.5\n"
3679 "%f32_2 = OpConstant %f32 2.0\n"
3680 "%f32_3_5 = OpConstant %f32 3.5\n"
3681 "%f32_4 = OpConstant %f32 4.0\n"
3682 "%f32_7_5 = OpConstant %f32 7.5\n"
3683 "%f32_8 = OpConstant %f32 8.0\n"
3684 "%f32_15_5 = OpConstant %f32 15.5\n"
3685 "%f32_16 = OpConstant %f32 16.0\n"
3686 "%f32_31_5 = OpConstant %f32 31.5\n"
3687 "%f32_32 = OpConstant %f32 32.0\n"
3688 "%f32_63_5 = OpConstant %f32 63.5\n"
3689 "%f32_64 = OpConstant %f32 64.0\n"
3690 "%f32_127_5 = OpConstant %f32 127.5\n"
3691 "%f32_128 = OpConstant %f32 128.0\n"
3692 "%f32_256 = OpConstant %f32 256.0\n"
3694 "%main = OpFunction %void None %voidf\n"
3695 "%entry = OpLabel\n"
3696 "%idval = OpLoad %uvec3 %id\n"
3697 "%x = OpCompositeExtract %u32 %idval 0\n"
3698 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3699 "%inval = OpLoad %f32 %inloc\n"
3701 "%xabs = OpExtInst %f32 %ext FAbs %inval\n"
3702 "%x8 = OpFMod %f32 %xabs %f32_256\n"
3703 "%x7 = OpFMod %f32 %xabs %f32_128\n"
3704 "%x6 = OpFMod %f32 %xabs %f32_64\n"
3705 "%x5 = OpFMod %f32 %xabs %f32_32\n"
3706 "%x4 = OpFMod %f32 %xabs %f32_16\n"
3707 "%x3 = OpFMod %f32 %xabs %f32_8\n"
3708 "%x2 = OpFMod %f32 %xabs %f32_4\n"
3709 "%x1 = OpFMod %f32 %xabs %f32_2\n"
3711 "%b7 = OpFOrdGreaterThanEqual %bool %x8 %f32_127_5\n"
3712 "%b6 = OpFOrdGreaterThanEqual %bool %x7 %f32_63_5\n"
3713 "%b5 = OpFOrdGreaterThanEqual %bool %x6 %f32_31_5\n"
3714 "%b4 = OpFOrdGreaterThanEqual %bool %x5 %f32_15_5\n"
3715 "%b3 = OpFOrdGreaterThanEqual %bool %x4 %f32_7_5\n"
3716 "%b2 = OpFOrdGreaterThanEqual %bool %x3 %f32_3_5\n"
3717 "%b1 = OpFOrdGreaterThanEqual %bool %x2 %f32_1_5\n"
3718 "%b0 = OpFOrdGreaterThanEqual %bool %x1 %f32_0_5\n"
3720 + generateOpPhiCase5(codestring) +
3722 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3723 " OpStore %outloc %res\n"
3727 spec5.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
3728 spec5.outputs.push_back(BufferSp(new Float32Buffer(outputFloats5)));
3729 spec5.numWorkGroups = IVec3(numElements, 1, 1);
3731 group->addChild(new SpvAsmComputeShaderCase(testCtx, "nested", "Stress OpPhi with a lot of nesting", spec5));
3733 createOpPhiVartypeTests(group, testCtx);
3735 return group.release();
3738 // Assembly code used for testing block order is based on GLSL source code:
3742 // layout(std140, set = 0, binding = 0) readonly buffer Input {
3743 // float elements[];
3745 // layout(std140, set = 0, binding = 1) writeonly buffer Output {
3746 // float elements[];
3750 // uint x = gl_GlobalInvocationID.x;
3751 // output_data.elements[x] = input_data.elements[x];
3752 // if (x > uint(50)) {
3753 // switch (x % uint(3)) {
3754 // case 0: output_data.elements[x] += 1.5f; break;
3755 // case 1: output_data.elements[x] += 42.f; break;
3756 // case 2: output_data.elements[x] -= 27.f; break;
3760 // output_data.elements[x] = -input_data.elements[x];
3763 tcu::TestCaseGroup* createBlockOrderGroup (tcu::TestContext& testCtx)
3765 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "block_order", "Test block orders"));
3766 ComputeShaderSpec spec;
3767 de::Random rnd (deStringHash(group->getName()));
3768 const int numElements = 100;
3769 vector<float> inputFloats (numElements, 0);
3770 vector<float> outputFloats (numElements, 0);
3772 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats[0], numElements);
3774 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
3775 floorAll(inputFloats);
3777 for (size_t ndx = 0; ndx <= 50; ++ndx)
3778 outputFloats[ndx] = -inputFloats[ndx];
3780 for (size_t ndx = 51; ndx < numElements; ++ndx)
3784 case 0: outputFloats[ndx] = inputFloats[ndx] + 1.5f; break;
3785 case 1: outputFloats[ndx] = inputFloats[ndx] + 42.f; break;
3786 case 2: outputFloats[ndx] = inputFloats[ndx] - 27.f; break;
3792 string(getComputeAsmShaderPreamble()) +
3794 "OpSource GLSL 430\n"
3795 "OpName %main \"main\"\n"
3796 "OpName %id \"gl_GlobalInvocationID\"\n"
3798 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3800 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
3802 "%u32ptr = OpTypePointer Function %u32\n"
3803 "%u32ptr_input = OpTypePointer Input %u32\n"
3805 + string(getComputeAsmInputOutputBuffer()) +
3807 "%id = OpVariable %uvec3ptr Input\n"
3808 "%zero = OpConstant %i32 0\n"
3809 "%const3 = OpConstant %u32 3\n"
3810 "%const50 = OpConstant %u32 50\n"
3811 "%constf1p5 = OpConstant %f32 1.5\n"
3812 "%constf27 = OpConstant %f32 27.0\n"
3813 "%constf42 = OpConstant %f32 42.0\n"
3815 "%main = OpFunction %void None %voidf\n"
3818 "%entry = OpLabel\n"
3820 // Create a temporary variable to hold the value of gl_GlobalInvocationID.x.
3821 "%xvar = OpVariable %u32ptr Function\n"
3822 "%xptr = OpAccessChain %u32ptr_input %id %zero\n"
3823 "%x = OpLoad %u32 %xptr\n"
3824 " OpStore %xvar %x\n"
3826 "%cmp = OpUGreaterThan %bool %x %const50\n"
3827 " OpSelectionMerge %if_merge None\n"
3828 " OpBranchConditional %cmp %if_true %if_false\n"
3830 // False branch for if-statement: placed in the middle of switch cases and before true branch.
3831 "%if_false = OpLabel\n"
3832 "%x_f = OpLoad %u32 %xvar\n"
3833 "%inloc_f = OpAccessChain %f32ptr %indata %zero %x_f\n"
3834 "%inval_f = OpLoad %f32 %inloc_f\n"
3835 "%negate = OpFNegate %f32 %inval_f\n"
3836 "%outloc_f = OpAccessChain %f32ptr %outdata %zero %x_f\n"
3837 " OpStore %outloc_f %negate\n"
3838 " OpBranch %if_merge\n"
3840 // Merge block for if-statement: placed in the middle of true and false branch.
3841 "%if_merge = OpLabel\n"
3844 // True branch for if-statement: placed in the middle of swtich cases and after the false branch.
3845 "%if_true = OpLabel\n"
3846 "%xval_t = OpLoad %u32 %xvar\n"
3847 "%mod = OpUMod %u32 %xval_t %const3\n"
3848 " OpSelectionMerge %switch_merge None\n"
3849 " OpSwitch %mod %default 0 %case0 1 %case1 2 %case2\n"
3851 // Merge block for switch-statement: placed before the case
3852 // bodies. But it must follow OpSwitch which dominates it.
3853 "%switch_merge = OpLabel\n"
3854 " OpBranch %if_merge\n"
3856 // Case 1 for switch-statement: placed before case 0.
3857 // It must follow the OpSwitch that dominates it.
3858 "%case1 = OpLabel\n"
3859 "%x_1 = OpLoad %u32 %xvar\n"
3860 "%inloc_1 = OpAccessChain %f32ptr %indata %zero %x_1\n"
3861 "%inval_1 = OpLoad %f32 %inloc_1\n"
3862 "%addf42 = OpFAdd %f32 %inval_1 %constf42\n"
3863 "%outloc_1 = OpAccessChain %f32ptr %outdata %zero %x_1\n"
3864 " OpStore %outloc_1 %addf42\n"
3865 " OpBranch %switch_merge\n"
3867 // Case 2 for switch-statement.
3868 "%case2 = OpLabel\n"
3869 "%x_2 = OpLoad %u32 %xvar\n"
3870 "%inloc_2 = OpAccessChain %f32ptr %indata %zero %x_2\n"
3871 "%inval_2 = OpLoad %f32 %inloc_2\n"
3872 "%subf27 = OpFSub %f32 %inval_2 %constf27\n"
3873 "%outloc_2 = OpAccessChain %f32ptr %outdata %zero %x_2\n"
3874 " OpStore %outloc_2 %subf27\n"
3875 " OpBranch %switch_merge\n"
3877 // Default case for switch-statement: placed in the middle of normal cases.
3878 "%default = OpLabel\n"
3879 " OpBranch %switch_merge\n"
3881 // Case 0 for switch-statement: out of order.
3882 "%case0 = OpLabel\n"
3883 "%x_0 = OpLoad %u32 %xvar\n"
3884 "%inloc_0 = OpAccessChain %f32ptr %indata %zero %x_0\n"
3885 "%inval_0 = OpLoad %f32 %inloc_0\n"
3886 "%addf1p5 = OpFAdd %f32 %inval_0 %constf1p5\n"
3887 "%outloc_0 = OpAccessChain %f32ptr %outdata %zero %x_0\n"
3888 " OpStore %outloc_0 %addf1p5\n"
3889 " OpBranch %switch_merge\n"
3892 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
3893 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
3894 spec.numWorkGroups = IVec3(numElements, 1, 1);
3896 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "various out-of-order blocks", spec));
3898 return group.release();
3901 tcu::TestCaseGroup* createMultipleShaderGroup (tcu::TestContext& testCtx)
3903 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "multiple_shaders", "Test multiple shaders in the same module"));
3904 ComputeShaderSpec spec1;
3905 ComputeShaderSpec spec2;
3906 de::Random rnd (deStringHash(group->getName()));
3907 const int numElements = 100;
3908 vector<float> inputFloats (numElements, 0);
3909 vector<float> outputFloats1 (numElements, 0);
3910 vector<float> outputFloats2 (numElements, 0);
3911 fillRandomScalars(rnd, -500.f, 500.f, &inputFloats[0], numElements);
3913 for (size_t ndx = 0; ndx < numElements; ++ndx)
3915 outputFloats1[ndx] = inputFloats[ndx] + inputFloats[ndx];
3916 outputFloats2[ndx] = -inputFloats[ndx];
3919 const string assembly(
3920 "OpCapability Shader\n"
3921 "OpCapability ClipDistance\n"
3922 "OpMemoryModel Logical GLSL450\n"
3923 "OpEntryPoint GLCompute %comp_main1 \"entrypoint1\" %id\n"
3924 "OpEntryPoint GLCompute %comp_main2 \"entrypoint2\" %id\n"
3925 // A module cannot have two OpEntryPoint instructions with the same Execution Model and the same Name string.
3926 "OpEntryPoint Vertex %vert_main \"entrypoint2\" %vert_builtins %vertexIndex %instanceIndex\n"
3927 "OpExecutionMode %comp_main1 LocalSize 1 1 1\n"
3928 "OpExecutionMode %comp_main2 LocalSize 1 1 1\n"
3930 "OpName %comp_main1 \"entrypoint1\"\n"
3931 "OpName %comp_main2 \"entrypoint2\"\n"
3932 "OpName %vert_main \"entrypoint2\"\n"
3933 "OpName %id \"gl_GlobalInvocationID\"\n"
3934 "OpName %vert_builtin_st \"gl_PerVertex\"\n"
3935 "OpName %vertexIndex \"gl_VertexIndex\"\n"
3936 "OpName %instanceIndex \"gl_InstanceIndex\"\n"
3937 "OpMemberName %vert_builtin_st 0 \"gl_Position\"\n"
3938 "OpMemberName %vert_builtin_st 1 \"gl_PointSize\"\n"
3939 "OpMemberName %vert_builtin_st 2 \"gl_ClipDistance\"\n"
3941 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3942 "OpDecorate %vertexIndex BuiltIn VertexIndex\n"
3943 "OpDecorate %instanceIndex BuiltIn InstanceIndex\n"
3944 "OpDecorate %vert_builtin_st Block\n"
3945 "OpMemberDecorate %vert_builtin_st 0 BuiltIn Position\n"
3946 "OpMemberDecorate %vert_builtin_st 1 BuiltIn PointSize\n"
3947 "OpMemberDecorate %vert_builtin_st 2 BuiltIn ClipDistance\n"
3949 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
3951 "%zero = OpConstant %i32 0\n"
3952 "%one = OpConstant %u32 1\n"
3953 "%c_f32_1 = OpConstant %f32 1\n"
3955 "%i32inputptr = OpTypePointer Input %i32\n"
3956 "%vec4 = OpTypeVector %f32 4\n"
3957 "%vec4ptr = OpTypePointer Output %vec4\n"
3958 "%f32arr1 = OpTypeArray %f32 %one\n"
3959 "%vert_builtin_st = OpTypeStruct %vec4 %f32 %f32arr1\n"
3960 "%vert_builtin_st_ptr = OpTypePointer Output %vert_builtin_st\n"
3961 "%vert_builtins = OpVariable %vert_builtin_st_ptr Output\n"
3963 "%id = OpVariable %uvec3ptr Input\n"
3964 "%vertexIndex = OpVariable %i32inputptr Input\n"
3965 "%instanceIndex = OpVariable %i32inputptr Input\n"
3966 "%c_vec4_1 = OpConstantComposite %vec4 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_1\n"
3968 // gl_Position = vec4(1.);
3969 "%vert_main = OpFunction %void None %voidf\n"
3970 "%vert_entry = OpLabel\n"
3971 "%position = OpAccessChain %vec4ptr %vert_builtins %zero\n"
3972 " OpStore %position %c_vec4_1\n"
3977 "%comp_main1 = OpFunction %void None %voidf\n"
3978 "%comp1_entry = OpLabel\n"
3979 "%idval1 = OpLoad %uvec3 %id\n"
3980 "%x1 = OpCompositeExtract %u32 %idval1 0\n"
3981 "%inloc1 = OpAccessChain %f32ptr %indata %zero %x1\n"
3982 "%inval1 = OpLoad %f32 %inloc1\n"
3983 "%add = OpFAdd %f32 %inval1 %inval1\n"
3984 "%outloc1 = OpAccessChain %f32ptr %outdata %zero %x1\n"
3985 " OpStore %outloc1 %add\n"
3990 "%comp_main2 = OpFunction %void None %voidf\n"
3991 "%comp2_entry = OpLabel\n"
3992 "%idval2 = OpLoad %uvec3 %id\n"
3993 "%x2 = OpCompositeExtract %u32 %idval2 0\n"
3994 "%inloc2 = OpAccessChain %f32ptr %indata %zero %x2\n"
3995 "%inval2 = OpLoad %f32 %inloc2\n"
3996 "%neg = OpFNegate %f32 %inval2\n"
3997 "%outloc2 = OpAccessChain %f32ptr %outdata %zero %x2\n"
3998 " OpStore %outloc2 %neg\n"
4000 " OpFunctionEnd\n");
4002 spec1.assembly = assembly;
4003 spec1.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
4004 spec1.outputs.push_back(BufferSp(new Float32Buffer(outputFloats1)));
4005 spec1.numWorkGroups = IVec3(numElements, 1, 1);
4006 spec1.entryPoint = "entrypoint1";
4008 spec2.assembly = assembly;
4009 spec2.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
4010 spec2.outputs.push_back(BufferSp(new Float32Buffer(outputFloats2)));
4011 spec2.numWorkGroups = IVec3(numElements, 1, 1);
4012 spec2.entryPoint = "entrypoint2";
4014 group->addChild(new SpvAsmComputeShaderCase(testCtx, "shader1", "multiple shaders in the same module", spec1));
4015 group->addChild(new SpvAsmComputeShaderCase(testCtx, "shader2", "multiple shaders in the same module", spec2));
4017 return group.release();
4020 inline std::string makeLongUTF8String (size_t num4ByteChars)
4022 // An example of a longest valid UTF-8 character. Be explicit about the
4023 // character type because Microsoft compilers can otherwise interpret the
4024 // character string as being over wide (16-bit) characters. Ideally, we
4025 // would just use a C++11 UTF-8 string literal, but we want to support older
4026 // Microsoft compilers.
4027 const std::basic_string<char> earthAfrica("\xF0\x9F\x8C\x8D");
4028 std::string longString;
4029 longString.reserve(num4ByteChars * 4);
4030 for (size_t count = 0; count < num4ByteChars; count++)
4032 longString += earthAfrica;
4037 tcu::TestCaseGroup* createOpSourceGroup (tcu::TestContext& testCtx)
4039 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opsource", "Tests the OpSource & OpSourceContinued instruction"));
4040 vector<CaseParameter> cases;
4041 de::Random rnd (deStringHash(group->getName()));
4042 const int numElements = 100;
4043 vector<float> positiveFloats (numElements, 0);
4044 vector<float> negativeFloats (numElements, 0);
4045 const StringTemplate shaderTemplate (
4046 "OpCapability Shader\n"
4047 "OpMemoryModel Logical GLSL450\n"
4049 "OpEntryPoint GLCompute %main \"main\" %id\n"
4050 "OpExecutionMode %main LocalSize 1 1 1\n"
4054 "OpName %main \"main\"\n"
4055 "OpName %id \"gl_GlobalInvocationID\"\n"
4057 "OpDecorate %id BuiltIn GlobalInvocationId\n"
4059 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
4061 "%id = OpVariable %uvec3ptr Input\n"
4062 "%zero = OpConstant %i32 0\n"
4064 "%main = OpFunction %void None %voidf\n"
4065 "%label = OpLabel\n"
4066 "%idval = OpLoad %uvec3 %id\n"
4067 "%x = OpCompositeExtract %u32 %idval 0\n"
4068 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
4069 "%inval = OpLoad %f32 %inloc\n"
4070 "%neg = OpFNegate %f32 %inval\n"
4071 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
4072 " OpStore %outloc %neg\n"
4074 " OpFunctionEnd\n");
4076 cases.push_back(CaseParameter("unknown_source", "OpSource Unknown 0"));
4077 cases.push_back(CaseParameter("wrong_source", "OpSource OpenCL_C 210"));
4078 cases.push_back(CaseParameter("normal_filename", "%fname = OpString \"filename\"\n"
4079 "OpSource GLSL 430 %fname"));
4080 cases.push_back(CaseParameter("empty_filename", "%fname = OpString \"\"\n"
4081 "OpSource GLSL 430 %fname"));
4082 cases.push_back(CaseParameter("normal_source_code", "%fname = OpString \"filename\"\n"
4083 "OpSource GLSL 430 %fname \"#version 430\nvoid main() {}\""));
4084 cases.push_back(CaseParameter("empty_source_code", "%fname = OpString \"filename\"\n"
4085 "OpSource GLSL 430 %fname \"\""));
4086 cases.push_back(CaseParameter("long_source_code", "%fname = OpString \"filename\"\n"
4087 "OpSource GLSL 430 %fname \"" + makeLongUTF8String(65530) + "ccc\"")); // word count: 65535
4088 cases.push_back(CaseParameter("utf8_source_code", "%fname = OpString \"filename\"\n"
4089 "OpSource GLSL 430 %fname \"\xE2\x98\x82\xE2\x98\x85\"")); // umbrella & black star symbol
4090 cases.push_back(CaseParameter("normal_sourcecontinued", "%fname = OpString \"filename\"\n"
4091 "OpSource GLSL 430 %fname \"#version 430\nvo\"\n"
4092 "OpSourceContinued \"id main() {}\""));
4093 cases.push_back(CaseParameter("empty_sourcecontinued", "%fname = OpString \"filename\"\n"
4094 "OpSource GLSL 430 %fname \"#version 430\nvoid main() {}\"\n"
4095 "OpSourceContinued \"\""));
4096 cases.push_back(CaseParameter("long_sourcecontinued", "%fname = OpString \"filename\"\n"
4097 "OpSource GLSL 430 %fname \"#version 430\nvoid main() {}\"\n"
4098 "OpSourceContinued \"" + makeLongUTF8String(65533) + "ccc\"")); // word count: 65535
4099 cases.push_back(CaseParameter("utf8_sourcecontinued", "%fname = OpString \"filename\"\n"
4100 "OpSource GLSL 430 %fname \"#version 430\nvoid main() {}\"\n"
4101 "OpSourceContinued \"\xE2\x98\x8E\xE2\x9A\x91\"")); // white telephone & black flag symbol
4102 cases.push_back(CaseParameter("multi_sourcecontinued", "%fname = OpString \"filename\"\n"
4103 "OpSource GLSL 430 %fname \"#version 430\n\"\n"
4104 "OpSourceContinued \"void\"\n"
4105 "OpSourceContinued \"main()\"\n"
4106 "OpSourceContinued \"{}\""));
4107 cases.push_back(CaseParameter("empty_source_before_sourcecontinued", "%fname = OpString \"filename\"\n"
4108 "OpSource GLSL 430 %fname \"\"\n"
4109 "OpSourceContinued \"#version 430\nvoid main() {}\""));
4111 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
4113 for (size_t ndx = 0; ndx < numElements; ++ndx)
4114 negativeFloats[ndx] = -positiveFloats[ndx];
4116 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
4118 map<string, string> specializations;
4119 ComputeShaderSpec spec;
4121 specializations["SOURCE"] = cases[caseNdx].param;
4122 spec.assembly = shaderTemplate.specialize(specializations);
4123 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
4124 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
4125 spec.numWorkGroups = IVec3(numElements, 1, 1);
4127 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
4130 return group.release();
4133 tcu::TestCaseGroup* createOpSourceExtensionGroup (tcu::TestContext& testCtx)
4135 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opsourceextension", "Tests the OpSource instruction"));
4136 vector<CaseParameter> cases;
4137 de::Random rnd (deStringHash(group->getName()));
4138 const int numElements = 100;
4139 vector<float> inputFloats (numElements, 0);
4140 vector<float> outputFloats (numElements, 0);
4141 const StringTemplate shaderTemplate (
4142 string(getComputeAsmShaderPreamble()) +
4144 "OpSourceExtension \"${EXTENSION}\"\n"
4146 "OpName %main \"main\"\n"
4147 "OpName %id \"gl_GlobalInvocationID\"\n"
4149 "OpDecorate %id BuiltIn GlobalInvocationId\n"
4151 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
4153 "%id = OpVariable %uvec3ptr Input\n"
4154 "%zero = OpConstant %i32 0\n"
4156 "%main = OpFunction %void None %voidf\n"
4157 "%label = OpLabel\n"
4158 "%idval = OpLoad %uvec3 %id\n"
4159 "%x = OpCompositeExtract %u32 %idval 0\n"
4160 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
4161 "%inval = OpLoad %f32 %inloc\n"
4162 "%neg = OpFNegate %f32 %inval\n"
4163 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
4164 " OpStore %outloc %neg\n"
4166 " OpFunctionEnd\n");
4168 cases.push_back(CaseParameter("empty_extension", ""));
4169 cases.push_back(CaseParameter("real_extension", "GL_ARB_texture_rectangle"));
4170 cases.push_back(CaseParameter("fake_extension", "GL_ARB_im_the_ultimate_extension"));
4171 cases.push_back(CaseParameter("utf8_extension", "GL_ARB_\xE2\x98\x82\xE2\x98\x85"));
4172 cases.push_back(CaseParameter("long_extension", makeLongUTF8String(65533) + "ccc")); // word count: 65535
4174 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats[0], numElements);
4176 for (size_t ndx = 0; ndx < numElements; ++ndx)
4177 outputFloats[ndx] = -inputFloats[ndx];
4179 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
4181 map<string, string> specializations;
4182 ComputeShaderSpec spec;
4184 specializations["EXTENSION"] = cases[caseNdx].param;
4185 spec.assembly = shaderTemplate.specialize(specializations);
4186 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
4187 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
4188 spec.numWorkGroups = IVec3(numElements, 1, 1);
4190 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
4193 return group.release();
4196 // Checks that a compute shader can generate a constant null value of various types, without exercising a computation on it.
4197 tcu::TestCaseGroup* createOpConstantNullGroup (tcu::TestContext& testCtx)
4199 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opconstantnull", "Tests the OpConstantNull instruction"));
4200 vector<CaseParameter> cases;
4201 de::Random rnd (deStringHash(group->getName()));
4202 const int numElements = 100;
4203 vector<float> positiveFloats (numElements, 0);
4204 vector<float> negativeFloats (numElements, 0);
4205 const StringTemplate shaderTemplate (
4206 string(getComputeAsmShaderPreamble()) +
4208 "OpSource GLSL 430\n"
4209 "OpName %main \"main\"\n"
4210 "OpName %id \"gl_GlobalInvocationID\"\n"
4212 "OpDecorate %id BuiltIn GlobalInvocationId\n"
4214 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
4215 "%uvec2 = OpTypeVector %u32 2\n"
4216 "%bvec3 = OpTypeVector %bool 3\n"
4217 "%fvec4 = OpTypeVector %f32 4\n"
4218 "%fmat33 = OpTypeMatrix %fvec3 3\n"
4219 "%const100 = OpConstant %u32 100\n"
4220 "%uarr100 = OpTypeArray %i32 %const100\n"
4221 "%struct = OpTypeStruct %f32 %i32 %u32\n"
4222 "%pointer = OpTypePointer Function %i32\n"
4223 + string(getComputeAsmInputOutputBuffer()) +
4225 "%null = OpConstantNull ${TYPE}\n"
4227 "%id = OpVariable %uvec3ptr Input\n"
4228 "%zero = OpConstant %i32 0\n"
4230 "%main = OpFunction %void None %voidf\n"
4231 "%label = OpLabel\n"
4232 "%idval = OpLoad %uvec3 %id\n"
4233 "%x = OpCompositeExtract %u32 %idval 0\n"
4234 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
4235 "%inval = OpLoad %f32 %inloc\n"
4236 "%neg = OpFNegate %f32 %inval\n"
4237 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
4238 " OpStore %outloc %neg\n"
4240 " OpFunctionEnd\n");
4242 cases.push_back(CaseParameter("bool", "%bool"));
4243 cases.push_back(CaseParameter("sint32", "%i32"));
4244 cases.push_back(CaseParameter("uint32", "%u32"));
4245 cases.push_back(CaseParameter("float32", "%f32"));
4246 cases.push_back(CaseParameter("vec4float32", "%fvec4"));
4247 cases.push_back(CaseParameter("vec3bool", "%bvec3"));
4248 cases.push_back(CaseParameter("vec2uint32", "%uvec2"));
4249 cases.push_back(CaseParameter("matrix", "%fmat33"));
4250 cases.push_back(CaseParameter("array", "%uarr100"));
4251 cases.push_back(CaseParameter("struct", "%struct"));
4252 cases.push_back(CaseParameter("pointer", "%pointer"));
4254 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
4256 for (size_t ndx = 0; ndx < numElements; ++ndx)
4257 negativeFloats[ndx] = -positiveFloats[ndx];
4259 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
4261 map<string, string> specializations;
4262 ComputeShaderSpec spec;
4264 specializations["TYPE"] = cases[caseNdx].param;
4265 spec.assembly = shaderTemplate.specialize(specializations);
4266 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
4267 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
4268 spec.numWorkGroups = IVec3(numElements, 1, 1);
4270 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
4273 return group.release();
4276 // Checks that a compute shader can generate a constant composite value of various types, without exercising a computation on it.
4277 tcu::TestCaseGroup* createOpConstantCompositeGroup (tcu::TestContext& testCtx)
4279 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opconstantcomposite", "Tests the OpConstantComposite instruction"));
4280 vector<CaseParameter> cases;
4281 de::Random rnd (deStringHash(group->getName()));
4282 const int numElements = 100;
4283 vector<float> positiveFloats (numElements, 0);
4284 vector<float> negativeFloats (numElements, 0);
4285 const StringTemplate shaderTemplate (
4286 string(getComputeAsmShaderPreamble()) +
4288 "OpSource GLSL 430\n"
4289 "OpName %main \"main\"\n"
4290 "OpName %id \"gl_GlobalInvocationID\"\n"
4292 "OpDecorate %id BuiltIn GlobalInvocationId\n"
4294 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
4296 "%id = OpVariable %uvec3ptr Input\n"
4297 "%zero = OpConstant %i32 0\n"
4301 "%main = OpFunction %void None %voidf\n"
4302 "%label = OpLabel\n"
4303 "%idval = OpLoad %uvec3 %id\n"
4304 "%x = OpCompositeExtract %u32 %idval 0\n"
4305 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
4306 "%inval = OpLoad %f32 %inloc\n"
4307 "%neg = OpFNegate %f32 %inval\n"
4308 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
4309 " OpStore %outloc %neg\n"
4311 " OpFunctionEnd\n");
4313 cases.push_back(CaseParameter("vector", "%five = OpConstant %u32 5\n"
4314 "%const = OpConstantComposite %uvec3 %five %zero %five"));
4315 cases.push_back(CaseParameter("matrix", "%m3fvec3 = OpTypeMatrix %fvec3 3\n"
4316 "%ten = OpConstant %f32 10.\n"
4317 "%fzero = OpConstant %f32 0.\n"
4318 "%vec = OpConstantComposite %fvec3 %ten %fzero %ten\n"
4319 "%mat = OpConstantComposite %m3fvec3 %vec %vec %vec"));
4320 cases.push_back(CaseParameter("struct", "%m2vec3 = OpTypeMatrix %fvec3 2\n"
4321 "%struct = OpTypeStruct %i32 %f32 %fvec3 %m2vec3\n"
4322 "%fzero = OpConstant %f32 0.\n"
4323 "%one = OpConstant %f32 1.\n"
4324 "%point5 = OpConstant %f32 0.5\n"
4325 "%vec = OpConstantComposite %fvec3 %one %one %fzero\n"
4326 "%mat = OpConstantComposite %m2vec3 %vec %vec\n"
4327 "%const = OpConstantComposite %struct %zero %point5 %vec %mat"));
4328 cases.push_back(CaseParameter("nested_struct", "%st1 = OpTypeStruct %u32 %f32\n"
4329 "%st2 = OpTypeStruct %i32 %i32\n"
4330 "%struct = OpTypeStruct %st1 %st2\n"
4331 "%point5 = OpConstant %f32 0.5\n"
4332 "%one = OpConstant %u32 1\n"
4333 "%ten = OpConstant %i32 10\n"
4334 "%st1val = OpConstantComposite %st1 %one %point5\n"
4335 "%st2val = OpConstantComposite %st2 %ten %ten\n"
4336 "%const = OpConstantComposite %struct %st1val %st2val"));
4338 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
4340 for (size_t ndx = 0; ndx < numElements; ++ndx)
4341 negativeFloats[ndx] = -positiveFloats[ndx];
4343 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
4345 map<string, string> specializations;
4346 ComputeShaderSpec spec;
4348 specializations["CONSTANT"] = cases[caseNdx].param;
4349 spec.assembly = shaderTemplate.specialize(specializations);
4350 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
4351 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
4352 spec.numWorkGroups = IVec3(numElements, 1, 1);
4354 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
4357 return group.release();
4360 // Creates a floating point number with the given exponent, and significand
4361 // bits set. It can only create normalized numbers. Only the least significant
4362 // 24 bits of the significand will be examined. The final bit of the
4363 // significand will also be ignored. This allows alignment to be written
4364 // similarly to C99 hex-floats.
4365 // For example if you wanted to write 0x1.7f34p-12 you would call
4366 // constructNormalizedFloat(-12, 0x7f3400)
4367 float constructNormalizedFloat (deInt32 exponent, deUint32 significand)
4371 for (deInt32 idx = 0; idx < 23; ++idx)
4373 f += ((significand & 0x800000) == 0) ? 0.f : std::ldexp(1.0f, -(idx + 1));
4377 return std::ldexp(f, exponent);
4380 // Compare instruction for the OpQuantizeF16 compute exact case.
4381 // Returns true if the output is what is expected from the test case.
4382 bool compareOpQuantizeF16ComputeExactCase (const std::vector<BufferSp>&, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs, TestLog&)
4384 if (outputAllocs.size() != 1)
4387 // Only size is needed because we cannot compare Nans.
4388 size_t byteSize = expectedOutputs[0]->getByteSize();
4390 const float* outputAsFloat = static_cast<const float*>(outputAllocs[0]->getHostPtr());
4392 if (byteSize != 4*sizeof(float)) {
4396 if (*outputAsFloat != constructNormalizedFloat(8, 0x304000) &&
4397 *outputAsFloat != constructNormalizedFloat(8, 0x300000)) {
4402 if (*outputAsFloat != -constructNormalizedFloat(-7, 0x600000) &&
4403 *outputAsFloat != -constructNormalizedFloat(-7, 0x604000)) {
4408 if (*outputAsFloat != constructNormalizedFloat(2, 0x01C000) &&
4409 *outputAsFloat != constructNormalizedFloat(2, 0x020000)) {
4414 if (*outputAsFloat != constructNormalizedFloat(1, 0xFFC000) &&
4415 *outputAsFloat != constructNormalizedFloat(2, 0x000000)) {
4422 // Checks that every output from a test-case is a float NaN.
4423 bool compareNan (const std::vector<BufferSp>&, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs, TestLog&)
4425 if (outputAllocs.size() != 1)
4428 // Only size is needed because we cannot compare Nans.
4429 size_t byteSize = expectedOutputs[0]->getByteSize();
4431 const float* const output_as_float = static_cast<const float*>(outputAllocs[0]->getHostPtr());
4433 for (size_t idx = 0; idx < byteSize / sizeof(float); ++idx)
4435 if (!deFloatIsNaN(output_as_float[idx]))
4444 // Checks that a compute shader can generate a constant composite value of various types, without exercising a computation on it.
4445 tcu::TestCaseGroup* createOpQuantizeToF16Group (tcu::TestContext& testCtx)
4447 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opquantize", "Tests the OpQuantizeToF16 instruction"));
4449 const std::string shader (
4450 string(getComputeAsmShaderPreamble()) +
4452 "OpSource GLSL 430\n"
4453 "OpName %main \"main\"\n"
4454 "OpName %id \"gl_GlobalInvocationID\"\n"
4456 "OpDecorate %id BuiltIn GlobalInvocationId\n"
4458 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
4460 "%id = OpVariable %uvec3ptr Input\n"
4461 "%zero = OpConstant %i32 0\n"
4463 "%main = OpFunction %void None %voidf\n"
4464 "%label = OpLabel\n"
4465 "%idval = OpLoad %uvec3 %id\n"
4466 "%x = OpCompositeExtract %u32 %idval 0\n"
4467 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
4468 "%inval = OpLoad %f32 %inloc\n"
4469 "%quant = OpQuantizeToF16 %f32 %inval\n"
4470 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
4471 " OpStore %outloc %quant\n"
4473 " OpFunctionEnd\n");
4476 ComputeShaderSpec spec;
4477 const deUint32 numElements = 100;
4478 vector<float> infinities;
4479 vector<float> results;
4481 infinities.reserve(numElements);
4482 results.reserve(numElements);
4484 for (size_t idx = 0; idx < numElements; ++idx)
4489 infinities.push_back(std::numeric_limits<float>::infinity());
4490 results.push_back(std::numeric_limits<float>::infinity());
4493 infinities.push_back(-std::numeric_limits<float>::infinity());
4494 results.push_back(-std::numeric_limits<float>::infinity());
4497 infinities.push_back(std::ldexp(1.0f, 16));
4498 results.push_back(std::numeric_limits<float>::infinity());
4501 infinities.push_back(std::ldexp(-1.0f, 32));
4502 results.push_back(-std::numeric_limits<float>::infinity());
4507 spec.assembly = shader;
4508 spec.inputs.push_back(BufferSp(new Float32Buffer(infinities)));
4509 spec.outputs.push_back(BufferSp(new Float32Buffer(results)));
4510 spec.numWorkGroups = IVec3(numElements, 1, 1);
4512 group->addChild(new SpvAsmComputeShaderCase(
4513 testCtx, "infinities", "Check that infinities propagated and created", spec));
4517 ComputeShaderSpec spec;
4519 const deUint32 numElements = 100;
4521 nans.reserve(numElements);
4523 for (size_t idx = 0; idx < numElements; ++idx)
4527 nans.push_back(std::numeric_limits<float>::quiet_NaN());
4531 nans.push_back(-std::numeric_limits<float>::quiet_NaN());
4535 spec.assembly = shader;
4536 spec.inputs.push_back(BufferSp(new Float32Buffer(nans)));
4537 spec.outputs.push_back(BufferSp(new Float32Buffer(nans)));
4538 spec.numWorkGroups = IVec3(numElements, 1, 1);
4539 spec.verifyIO = &compareNan;
4541 group->addChild(new SpvAsmComputeShaderCase(
4542 testCtx, "propagated_nans", "Check that nans are propagated", spec));
4546 ComputeShaderSpec spec;
4547 vector<float> small;
4548 vector<float> zeros;
4549 const deUint32 numElements = 100;
4551 small.reserve(numElements);
4552 zeros.reserve(numElements);
4554 for (size_t idx = 0; idx < numElements; ++idx)
4559 small.push_back(0.f);
4560 zeros.push_back(0.f);
4563 small.push_back(-0.f);
4564 zeros.push_back(-0.f);
4567 small.push_back(std::ldexp(1.0f, -16));
4568 zeros.push_back(0.f);
4571 small.push_back(std::ldexp(-1.0f, -32));
4572 zeros.push_back(-0.f);
4575 small.push_back(std::ldexp(1.0f, -127));
4576 zeros.push_back(0.f);
4579 small.push_back(-std::ldexp(1.0f, -128));
4580 zeros.push_back(-0.f);
4585 spec.assembly = shader;
4586 spec.inputs.push_back(BufferSp(new Float32Buffer(small)));
4587 spec.outputs.push_back(BufferSp(new Float32Buffer(zeros)));
4588 spec.numWorkGroups = IVec3(numElements, 1, 1);
4590 group->addChild(new SpvAsmComputeShaderCase(
4591 testCtx, "flush_to_zero", "Check that values are zeroed correctly", spec));
4595 ComputeShaderSpec spec;
4596 vector<float> exact;
4597 const deUint32 numElements = 200;
4599 exact.reserve(numElements);
4601 for (size_t idx = 0; idx < numElements; ++idx)
4602 exact.push_back(static_cast<float>(static_cast<int>(idx) - 100));
4604 spec.assembly = shader;
4605 spec.inputs.push_back(BufferSp(new Float32Buffer(exact)));
4606 spec.outputs.push_back(BufferSp(new Float32Buffer(exact)));
4607 spec.numWorkGroups = IVec3(numElements, 1, 1);
4609 group->addChild(new SpvAsmComputeShaderCase(
4610 testCtx, "exact", "Check that values exactly preserved where appropriate", spec));
4614 ComputeShaderSpec spec;
4615 vector<float> inputs;
4616 const deUint32 numElements = 4;
4618 inputs.push_back(constructNormalizedFloat(8, 0x300300));
4619 inputs.push_back(-constructNormalizedFloat(-7, 0x600800));
4620 inputs.push_back(constructNormalizedFloat(2, 0x01E000));
4621 inputs.push_back(constructNormalizedFloat(1, 0xFFE000));
4623 spec.assembly = shader;
4624 spec.verifyIO = &compareOpQuantizeF16ComputeExactCase;
4625 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs)));
4626 spec.outputs.push_back(BufferSp(new Float32Buffer(inputs)));
4627 spec.numWorkGroups = IVec3(numElements, 1, 1);
4629 group->addChild(new SpvAsmComputeShaderCase(
4630 testCtx, "rounded", "Check that are rounded when needed", spec));
4633 return group.release();
4636 tcu::TestCaseGroup* createSpecConstantOpQuantizeToF16Group (tcu::TestContext& testCtx)
4638 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opspecconstantop_opquantize", "Tests the OpQuantizeToF16 opcode for the OpSpecConstantOp instruction"));
4640 const std::string shader (
4641 string(getComputeAsmShaderPreamble()) +
4643 "OpName %main \"main\"\n"
4644 "OpName %id \"gl_GlobalInvocationID\"\n"
4646 "OpDecorate %id BuiltIn GlobalInvocationId\n"
4648 "OpDecorate %sc_0 SpecId 0\n"
4649 "OpDecorate %sc_1 SpecId 1\n"
4650 "OpDecorate %sc_2 SpecId 2\n"
4651 "OpDecorate %sc_3 SpecId 3\n"
4652 "OpDecorate %sc_4 SpecId 4\n"
4653 "OpDecorate %sc_5 SpecId 5\n"
4655 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
4657 "%id = OpVariable %uvec3ptr Input\n"
4658 "%zero = OpConstant %i32 0\n"
4659 "%c_u32_6 = OpConstant %u32 6\n"
4661 "%sc_0 = OpSpecConstant %f32 0.\n"
4662 "%sc_1 = OpSpecConstant %f32 0.\n"
4663 "%sc_2 = OpSpecConstant %f32 0.\n"
4664 "%sc_3 = OpSpecConstant %f32 0.\n"
4665 "%sc_4 = OpSpecConstant %f32 0.\n"
4666 "%sc_5 = OpSpecConstant %f32 0.\n"
4668 "%sc_0_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_0\n"
4669 "%sc_1_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_1\n"
4670 "%sc_2_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_2\n"
4671 "%sc_3_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_3\n"
4672 "%sc_4_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_4\n"
4673 "%sc_5_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_5\n"
4675 "%main = OpFunction %void None %voidf\n"
4676 "%label = OpLabel\n"
4677 "%idval = OpLoad %uvec3 %id\n"
4678 "%x = OpCompositeExtract %u32 %idval 0\n"
4679 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
4680 "%selector = OpUMod %u32 %x %c_u32_6\n"
4681 " OpSelectionMerge %exit None\n"
4682 " OpSwitch %selector %exit 0 %case0 1 %case1 2 %case2 3 %case3 4 %case4 5 %case5\n"
4684 "%case0 = OpLabel\n"
4685 " OpStore %outloc %sc_0_quant\n"
4688 "%case1 = OpLabel\n"
4689 " OpStore %outloc %sc_1_quant\n"
4692 "%case2 = OpLabel\n"
4693 " OpStore %outloc %sc_2_quant\n"
4696 "%case3 = OpLabel\n"
4697 " OpStore %outloc %sc_3_quant\n"
4700 "%case4 = OpLabel\n"
4701 " OpStore %outloc %sc_4_quant\n"
4704 "%case5 = OpLabel\n"
4705 " OpStore %outloc %sc_5_quant\n"
4711 " OpFunctionEnd\n");
4714 ComputeShaderSpec spec;
4715 const deUint8 numCases = 4;
4716 vector<float> inputs (numCases, 0.f);
4717 vector<float> outputs;
4719 spec.assembly = shader;
4720 spec.numWorkGroups = IVec3(numCases, 1, 1);
4722 spec.specConstants.push_back(bitwiseCast<deUint32>(std::numeric_limits<float>::infinity()));
4723 spec.specConstants.push_back(bitwiseCast<deUint32>(-std::numeric_limits<float>::infinity()));
4724 spec.specConstants.push_back(bitwiseCast<deUint32>(std::ldexp(1.0f, 16)));
4725 spec.specConstants.push_back(bitwiseCast<deUint32>(std::ldexp(-1.0f, 32)));
4727 outputs.push_back(std::numeric_limits<float>::infinity());
4728 outputs.push_back(-std::numeric_limits<float>::infinity());
4729 outputs.push_back(std::numeric_limits<float>::infinity());
4730 outputs.push_back(-std::numeric_limits<float>::infinity());
4732 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs)));
4733 spec.outputs.push_back(BufferSp(new Float32Buffer(outputs)));
4735 group->addChild(new SpvAsmComputeShaderCase(
4736 testCtx, "infinities", "Check that infinities propagated and created", spec));
4740 ComputeShaderSpec spec;
4741 const deUint8 numCases = 2;
4742 vector<float> inputs (numCases, 0.f);
4743 vector<float> outputs;
4745 spec.assembly = shader;
4746 spec.numWorkGroups = IVec3(numCases, 1, 1);
4747 spec.verifyIO = &compareNan;
4749 outputs.push_back(std::numeric_limits<float>::quiet_NaN());
4750 outputs.push_back(-std::numeric_limits<float>::quiet_NaN());
4752 for (deUint8 idx = 0; idx < numCases; ++idx)
4753 spec.specConstants.push_back(bitwiseCast<deUint32>(outputs[idx]));
4755 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs)));
4756 spec.outputs.push_back(BufferSp(new Float32Buffer(outputs)));
4758 group->addChild(new SpvAsmComputeShaderCase(
4759 testCtx, "propagated_nans", "Check that nans are propagated", spec));
4763 ComputeShaderSpec spec;
4764 const deUint8 numCases = 6;
4765 vector<float> inputs (numCases, 0.f);
4766 vector<float> outputs;
4768 spec.assembly = shader;
4769 spec.numWorkGroups = IVec3(numCases, 1, 1);
4771 spec.specConstants.push_back(bitwiseCast<deUint32>(0.f));
4772 spec.specConstants.push_back(bitwiseCast<deUint32>(-0.f));
4773 spec.specConstants.push_back(bitwiseCast<deUint32>(std::ldexp(1.0f, -16)));
4774 spec.specConstants.push_back(bitwiseCast<deUint32>(std::ldexp(-1.0f, -32)));
4775 spec.specConstants.push_back(bitwiseCast<deUint32>(std::ldexp(1.0f, -127)));
4776 spec.specConstants.push_back(bitwiseCast<deUint32>(-std::ldexp(1.0f, -128)));
4778 outputs.push_back(0.f);
4779 outputs.push_back(-0.f);
4780 outputs.push_back(0.f);
4781 outputs.push_back(-0.f);
4782 outputs.push_back(0.f);
4783 outputs.push_back(-0.f);
4785 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs)));
4786 spec.outputs.push_back(BufferSp(new Float32Buffer(outputs)));
4788 group->addChild(new SpvAsmComputeShaderCase(
4789 testCtx, "flush_to_zero", "Check that values are zeroed correctly", spec));
4793 ComputeShaderSpec spec;
4794 const deUint8 numCases = 6;
4795 vector<float> inputs (numCases, 0.f);
4796 vector<float> outputs;
4798 spec.assembly = shader;
4799 spec.numWorkGroups = IVec3(numCases, 1, 1);
4801 for (deUint8 idx = 0; idx < 6; ++idx)
4803 const float f = static_cast<float>(idx * 10 - 30) / 4.f;
4804 spec.specConstants.push_back(bitwiseCast<deUint32>(f));
4805 outputs.push_back(f);
4808 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs)));
4809 spec.outputs.push_back(BufferSp(new Float32Buffer(outputs)));
4811 group->addChild(new SpvAsmComputeShaderCase(
4812 testCtx, "exact", "Check that values exactly preserved where appropriate", spec));
4816 ComputeShaderSpec spec;
4817 const deUint8 numCases = 4;
4818 vector<float> inputs (numCases, 0.f);
4819 vector<float> outputs;
4821 spec.assembly = shader;
4822 spec.numWorkGroups = IVec3(numCases, 1, 1);
4823 spec.verifyIO = &compareOpQuantizeF16ComputeExactCase;
4825 outputs.push_back(constructNormalizedFloat(8, 0x300300));
4826 outputs.push_back(-constructNormalizedFloat(-7, 0x600800));
4827 outputs.push_back(constructNormalizedFloat(2, 0x01E000));
4828 outputs.push_back(constructNormalizedFloat(1, 0xFFE000));
4830 for (deUint8 idx = 0; idx < numCases; ++idx)
4831 spec.specConstants.push_back(bitwiseCast<deUint32>(outputs[idx]));
4833 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs)));
4834 spec.outputs.push_back(BufferSp(new Float32Buffer(outputs)));
4836 group->addChild(new SpvAsmComputeShaderCase(
4837 testCtx, "rounded", "Check that are rounded when needed", spec));
4840 return group.release();
4843 // Checks that constant null/composite values can be used in computation.
4844 tcu::TestCaseGroup* createOpConstantUsageGroup (tcu::TestContext& testCtx)
4846 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opconstantnullcomposite", "Spotcheck the OpConstantNull & OpConstantComposite instruction"));
4847 ComputeShaderSpec spec;
4848 de::Random rnd (deStringHash(group->getName()));
4849 const int numElements = 100;
4850 vector<float> positiveFloats (numElements, 0);
4851 vector<float> negativeFloats (numElements, 0);
4853 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
4855 for (size_t ndx = 0; ndx < numElements; ++ndx)
4856 negativeFloats[ndx] = -positiveFloats[ndx];
4859 "OpCapability Shader\n"
4860 "%std450 = OpExtInstImport \"GLSL.std.450\"\n"
4861 "OpMemoryModel Logical GLSL450\n"
4862 "OpEntryPoint GLCompute %main \"main\" %id\n"
4863 "OpExecutionMode %main LocalSize 1 1 1\n"
4865 "OpSource GLSL 430\n"
4866 "OpName %main \"main\"\n"
4867 "OpName %id \"gl_GlobalInvocationID\"\n"
4869 "OpDecorate %id BuiltIn GlobalInvocationId\n"
4871 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
4873 "%fmat = OpTypeMatrix %fvec3 3\n"
4874 "%ten = OpConstant %u32 10\n"
4875 "%f32arr10 = OpTypeArray %f32 %ten\n"
4876 "%fst = OpTypeStruct %f32 %f32\n"
4878 + string(getComputeAsmInputOutputBuffer()) +
4880 "%id = OpVariable %uvec3ptr Input\n"
4881 "%zero = OpConstant %i32 0\n"
4883 // Create a bunch of null values
4884 "%unull = OpConstantNull %u32\n"
4885 "%fnull = OpConstantNull %f32\n"
4886 "%vnull = OpConstantNull %fvec3\n"
4887 "%mnull = OpConstantNull %fmat\n"
4888 "%anull = OpConstantNull %f32arr10\n"
4889 "%snull = OpConstantComposite %fst %fnull %fnull\n"
4891 "%main = OpFunction %void None %voidf\n"
4892 "%label = OpLabel\n"
4893 "%idval = OpLoad %uvec3 %id\n"
4894 "%x = OpCompositeExtract %u32 %idval 0\n"
4895 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
4896 "%inval = OpLoad %f32 %inloc\n"
4897 "%neg = OpFNegate %f32 %inval\n"
4899 // Get the abs() of (a certain element of) those null values
4900 "%unull_cov = OpConvertUToF %f32 %unull\n"
4901 "%unull_abs = OpExtInst %f32 %std450 FAbs %unull_cov\n"
4902 "%fnull_abs = OpExtInst %f32 %std450 FAbs %fnull\n"
4903 "%vnull_0 = OpCompositeExtract %f32 %vnull 0\n"
4904 "%vnull_abs = OpExtInst %f32 %std450 FAbs %vnull_0\n"
4905 "%mnull_12 = OpCompositeExtract %f32 %mnull 1 2\n"
4906 "%mnull_abs = OpExtInst %f32 %std450 FAbs %mnull_12\n"
4907 "%anull_3 = OpCompositeExtract %f32 %anull 3\n"
4908 "%anull_abs = OpExtInst %f32 %std450 FAbs %anull_3\n"
4909 "%snull_1 = OpCompositeExtract %f32 %snull 1\n"
4910 "%snull_abs = OpExtInst %f32 %std450 FAbs %snull_1\n"
4913 "%add1 = OpFAdd %f32 %neg %unull_abs\n"
4914 "%add2 = OpFAdd %f32 %add1 %fnull_abs\n"
4915 "%add3 = OpFAdd %f32 %add2 %vnull_abs\n"
4916 "%add4 = OpFAdd %f32 %add3 %mnull_abs\n"
4917 "%add5 = OpFAdd %f32 %add4 %anull_abs\n"
4918 "%final = OpFAdd %f32 %add5 %snull_abs\n"
4920 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
4921 " OpStore %outloc %final\n" // write to output
4924 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
4925 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
4926 spec.numWorkGroups = IVec3(numElements, 1, 1);
4928 group->addChild(new SpvAsmComputeShaderCase(testCtx, "spotcheck", "Check that values constructed via OpConstantNull & OpConstantComposite can be used", spec));
4930 return group.release();
4933 // Assembly code used for testing loop control is based on GLSL source code:
4936 // layout(std140, set = 0, binding = 0) readonly buffer Input {
4937 // float elements[];
4939 // layout(std140, set = 0, binding = 1) writeonly buffer Output {
4940 // float elements[];
4944 // uint x = gl_GlobalInvocationID.x;
4945 // output_data.elements[x] = input_data.elements[x];
4946 // for (uint i = 0; i < 4; ++i)
4947 // output_data.elements[x] += 1.f;
4949 tcu::TestCaseGroup* createLoopControlGroup (tcu::TestContext& testCtx)
4951 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "loop_control", "Tests loop control cases"));
4952 vector<CaseParameter> cases;
4953 de::Random rnd (deStringHash(group->getName()));
4954 const int numElements = 100;
4955 vector<float> inputFloats (numElements, 0);
4956 vector<float> outputFloats (numElements, 0);
4957 const StringTemplate shaderTemplate (
4958 string(getComputeAsmShaderPreamble()) +
4960 "OpSource GLSL 430\n"
4961 "OpName %main \"main\"\n"
4962 "OpName %id \"gl_GlobalInvocationID\"\n"
4964 "OpDecorate %id BuiltIn GlobalInvocationId\n"
4966 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
4968 "%u32ptr = OpTypePointer Function %u32\n"
4970 "%id = OpVariable %uvec3ptr Input\n"
4971 "%zero = OpConstant %i32 0\n"
4972 "%uzero = OpConstant %u32 0\n"
4973 "%one = OpConstant %i32 1\n"
4974 "%constf1 = OpConstant %f32 1.0\n"
4975 "%four = OpConstant %u32 4\n"
4977 "%main = OpFunction %void None %voidf\n"
4978 "%entry = OpLabel\n"
4979 "%i = OpVariable %u32ptr Function\n"
4980 " OpStore %i %uzero\n"
4982 "%idval = OpLoad %uvec3 %id\n"
4983 "%x = OpCompositeExtract %u32 %idval 0\n"
4984 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
4985 "%inval = OpLoad %f32 %inloc\n"
4986 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
4987 " OpStore %outloc %inval\n"
4988 " OpBranch %loop_entry\n"
4990 "%loop_entry = OpLabel\n"
4991 "%i_val = OpLoad %u32 %i\n"
4992 "%cmp_lt = OpULessThan %bool %i_val %four\n"
4993 " OpLoopMerge %loop_merge %loop_body ${CONTROL}\n"
4994 " OpBranchConditional %cmp_lt %loop_body %loop_merge\n"
4995 "%loop_body = OpLabel\n"
4996 "%outval = OpLoad %f32 %outloc\n"
4997 "%addf1 = OpFAdd %f32 %outval %constf1\n"
4998 " OpStore %outloc %addf1\n"
4999 "%new_i = OpIAdd %u32 %i_val %one\n"
5000 " OpStore %i %new_i\n"
5001 " OpBranch %loop_entry\n"
5002 "%loop_merge = OpLabel\n"
5004 " OpFunctionEnd\n");
5006 cases.push_back(CaseParameter("none", "None"));
5007 cases.push_back(CaseParameter("unroll", "Unroll"));
5008 cases.push_back(CaseParameter("dont_unroll", "DontUnroll"));
5009 cases.push_back(CaseParameter("unroll_dont_unroll", "Unroll|DontUnroll"));
5011 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats[0], numElements);
5013 for (size_t ndx = 0; ndx < numElements; ++ndx)
5014 outputFloats[ndx] = inputFloats[ndx] + 4.f;
5016 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
5018 map<string, string> specializations;
5019 ComputeShaderSpec spec;
5021 specializations["CONTROL"] = cases[caseNdx].param;
5022 spec.assembly = shaderTemplate.specialize(specializations);
5023 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
5024 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
5025 spec.numWorkGroups = IVec3(numElements, 1, 1);
5027 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
5030 group->addChild(new SpvAsmLoopControlDependencyLengthCase(testCtx, "dependency_length", "dependency_length"));
5031 group->addChild(new SpvAsmLoopControlDependencyInfiniteCase(testCtx, "dependency_infinite", "dependency_infinite"));
5033 return group.release();
5036 // Assembly code used for testing selection control is based on GLSL source code:
5039 // layout(std140, set = 0, binding = 0) readonly buffer Input {
5040 // float elements[];
5042 // layout(std140, set = 0, binding = 1) writeonly buffer Output {
5043 // float elements[];
5047 // uint x = gl_GlobalInvocationID.x;
5048 // float val = input_data.elements[x];
5050 // output_data.elements[x] = val + 1.f;
5052 // output_data.elements[x] = val - 1.f;
5054 tcu::TestCaseGroup* createSelectionControlGroup (tcu::TestContext& testCtx)
5056 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "selection_control", "Tests selection control cases"));
5057 vector<CaseParameter> cases;
5058 de::Random rnd (deStringHash(group->getName()));
5059 const int numElements = 100;
5060 vector<float> inputFloats (numElements, 0);
5061 vector<float> outputFloats (numElements, 0);
5062 const StringTemplate shaderTemplate (
5063 string(getComputeAsmShaderPreamble()) +
5065 "OpSource GLSL 430\n"
5066 "OpName %main \"main\"\n"
5067 "OpName %id \"gl_GlobalInvocationID\"\n"
5069 "OpDecorate %id BuiltIn GlobalInvocationId\n"
5071 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
5073 "%id = OpVariable %uvec3ptr Input\n"
5074 "%zero = OpConstant %i32 0\n"
5075 "%constf1 = OpConstant %f32 1.0\n"
5076 "%constf10 = OpConstant %f32 10.0\n"
5078 "%main = OpFunction %void None %voidf\n"
5079 "%entry = OpLabel\n"
5080 "%idval = OpLoad %uvec3 %id\n"
5081 "%x = OpCompositeExtract %u32 %idval 0\n"
5082 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
5083 "%inval = OpLoad %f32 %inloc\n"
5084 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
5085 "%cmp_gt = OpFOrdGreaterThan %bool %inval %constf10\n"
5087 " OpSelectionMerge %if_end ${CONTROL}\n"
5088 " OpBranchConditional %cmp_gt %if_true %if_false\n"
5089 "%if_true = OpLabel\n"
5090 "%addf1 = OpFAdd %f32 %inval %constf1\n"
5091 " OpStore %outloc %addf1\n"
5092 " OpBranch %if_end\n"
5093 "%if_false = OpLabel\n"
5094 "%subf1 = OpFSub %f32 %inval %constf1\n"
5095 " OpStore %outloc %subf1\n"
5096 " OpBranch %if_end\n"
5097 "%if_end = OpLabel\n"
5099 " OpFunctionEnd\n");
5101 cases.push_back(CaseParameter("none", "None"));
5102 cases.push_back(CaseParameter("flatten", "Flatten"));
5103 cases.push_back(CaseParameter("dont_flatten", "DontFlatten"));
5104 cases.push_back(CaseParameter("flatten_dont_flatten", "DontFlatten|Flatten"));
5106 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats[0], numElements);
5108 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
5109 floorAll(inputFloats);
5111 for (size_t ndx = 0; ndx < numElements; ++ndx)
5112 outputFloats[ndx] = inputFloats[ndx] + (inputFloats[ndx] > 10.f ? 1.f : -1.f);
5114 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
5116 map<string, string> specializations;
5117 ComputeShaderSpec spec;
5119 specializations["CONTROL"] = cases[caseNdx].param;
5120 spec.assembly = shaderTemplate.specialize(specializations);
5121 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
5122 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
5123 spec.numWorkGroups = IVec3(numElements, 1, 1);
5125 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
5128 return group.release();
5131 tcu::TestCaseGroup* createOpNameGroup(tcu::TestContext& testCtx)
5133 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opname", "Tests OpName cases"));
5134 de::MovePtr<tcu::TestCaseGroup> entryMainGroup (new tcu::TestCaseGroup(testCtx, "entry_main", "OpName tests with entry main"));
5135 de::MovePtr<tcu::TestCaseGroup> entryNotGroup (new tcu::TestCaseGroup(testCtx, "entry_rdc", "OpName tests with entry rdc"));
5136 vector<CaseParameter> cases;
5137 vector<string> testFunc;
5138 de::Random rnd (deStringHash(group->getName()));
5139 const int numElements = 100;
5140 vector<float> inputFloats (numElements, 0);
5141 vector<float> outputFloats (numElements, 0);
5143 fillRandomScalars(rnd, -100.0f, 100.0f, &inputFloats[0], numElements);
5145 for(size_t ndx = 0; ndx < numElements; ++ndx)
5146 outputFloats[ndx] = -inputFloats[ndx];
5148 const StringTemplate shaderTemplate (
5149 "OpCapability Shader\n"
5150 "OpMemoryModel Logical GLSL450\n"
5151 "OpEntryPoint GLCompute %main \"${ENTRY}\" %id\n"
5152 "OpExecutionMode %main LocalSize 1 1 1\n"
5154 "OpName %${FUNC_ID} \"${NAME}\"\n"
5156 "OpDecorate %id BuiltIn GlobalInvocationId\n"
5158 + string(getComputeAsmInputOutputBufferTraits())
5160 + string(getComputeAsmCommonTypes())
5162 + string(getComputeAsmInputOutputBuffer()) +
5164 "%id = OpVariable %uvec3ptr Input\n"
5165 "%zero = OpConstant %i32 0\n"
5167 "%func = OpFunction %void None %voidf\n"
5172 "%main = OpFunction %void None %voidf\n"
5173 "%entry = OpLabel\n"
5174 "%7 = OpFunctionCall %void %func\n"
5176 "%idval = OpLoad %uvec3 %id\n"
5177 "%x = OpCompositeExtract %u32 %idval 0\n"
5179 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
5180 "%inval = OpLoad %f32 %inloc\n"
5181 "%neg = OpFNegate %f32 %inval\n"
5182 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
5183 " OpStore %outloc %neg\n"
5187 " OpFunctionEnd\n");
5189 cases.push_back(CaseParameter("_is_main", "main"));
5190 cases.push_back(CaseParameter("_is_not_main", "not_main"));
5192 testFunc.push_back("main");
5193 testFunc.push_back("func");
5195 for(size_t fNdx = 0; fNdx < testFunc.size(); ++fNdx)
5197 for(size_t ndx = 0; ndx < cases.size(); ++ndx)
5199 map<string, string> specializations;
5200 ComputeShaderSpec spec;
5202 specializations["ENTRY"] = "main";
5203 specializations["FUNC_ID"] = testFunc[fNdx];
5204 specializations["NAME"] = cases[ndx].param;
5205 spec.assembly = shaderTemplate.specialize(specializations);
5206 spec.numWorkGroups = IVec3(numElements, 1, 1);
5207 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
5208 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
5210 entryMainGroup->addChild(new SpvAsmComputeShaderCase(testCtx, (testFunc[fNdx] + cases[ndx].name).c_str(), cases[ndx].name, spec));
5214 cases.push_back(CaseParameter("_is_entry", "rdc"));
5216 for(size_t fNdx = 0; fNdx < testFunc.size(); ++fNdx)
5218 for(size_t ndx = 0; ndx < cases.size(); ++ndx)
5220 map<string, string> specializations;
5221 ComputeShaderSpec spec;
5223 specializations["ENTRY"] = "rdc";
5224 specializations["FUNC_ID"] = testFunc[fNdx];
5225 specializations["NAME"] = cases[ndx].param;
5226 spec.assembly = shaderTemplate.specialize(specializations);
5227 spec.numWorkGroups = IVec3(numElements, 1, 1);
5228 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
5229 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
5230 spec.entryPoint = "rdc";
5232 entryNotGroup->addChild(new SpvAsmComputeShaderCase(testCtx, (testFunc[fNdx] + cases[ndx].name).c_str(), cases[ndx].name, spec));
5236 group->addChild(entryMainGroup.release());
5237 group->addChild(entryNotGroup.release());
5239 return group.release();
5242 // Assembly code used for testing function control is based on GLSL source code:
5246 // layout(std140, set = 0, binding = 0) readonly buffer Input {
5247 // float elements[];
5249 // layout(std140, set = 0, binding = 1) writeonly buffer Output {
5250 // float elements[];
5253 // float const10() { return 10.f; }
5256 // uint x = gl_GlobalInvocationID.x;
5257 // output_data.elements[x] = input_data.elements[x] + const10();
5259 tcu::TestCaseGroup* createFunctionControlGroup (tcu::TestContext& testCtx)
5261 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "function_control", "Tests function control cases"));
5262 vector<CaseParameter> cases;
5263 de::Random rnd (deStringHash(group->getName()));
5264 const int numElements = 100;
5265 vector<float> inputFloats (numElements, 0);
5266 vector<float> outputFloats (numElements, 0);
5267 const StringTemplate shaderTemplate (
5268 string(getComputeAsmShaderPreamble()) +
5270 "OpSource GLSL 430\n"
5271 "OpName %main \"main\"\n"
5272 "OpName %func_const10 \"const10(\"\n"
5273 "OpName %id \"gl_GlobalInvocationID\"\n"
5275 "OpDecorate %id BuiltIn GlobalInvocationId\n"
5277 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
5279 "%f32f = OpTypeFunction %f32\n"
5280 "%id = OpVariable %uvec3ptr Input\n"
5281 "%zero = OpConstant %i32 0\n"
5282 "%constf10 = OpConstant %f32 10.0\n"
5284 "%main = OpFunction %void None %voidf\n"
5285 "%entry = OpLabel\n"
5286 "%idval = OpLoad %uvec3 %id\n"
5287 "%x = OpCompositeExtract %u32 %idval 0\n"
5288 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
5289 "%inval = OpLoad %f32 %inloc\n"
5290 "%ret_10 = OpFunctionCall %f32 %func_const10\n"
5291 "%fadd = OpFAdd %f32 %inval %ret_10\n"
5292 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
5293 " OpStore %outloc %fadd\n"
5297 "%func_const10 = OpFunction %f32 ${CONTROL} %f32f\n"
5298 "%label = OpLabel\n"
5299 " OpReturnValue %constf10\n"
5300 " OpFunctionEnd\n");
5302 cases.push_back(CaseParameter("none", "None"));
5303 cases.push_back(CaseParameter("inline", "Inline"));
5304 cases.push_back(CaseParameter("dont_inline", "DontInline"));
5305 cases.push_back(CaseParameter("pure", "Pure"));
5306 cases.push_back(CaseParameter("const", "Const"));
5307 cases.push_back(CaseParameter("inline_pure", "Inline|Pure"));
5308 cases.push_back(CaseParameter("const_dont_inline", "Const|DontInline"));
5309 cases.push_back(CaseParameter("inline_dont_inline", "Inline|DontInline"));
5310 cases.push_back(CaseParameter("pure_inline_dont_inline", "Pure|Inline|DontInline"));
5312 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats[0], numElements);
5314 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
5315 floorAll(inputFloats);
5317 for (size_t ndx = 0; ndx < numElements; ++ndx)
5318 outputFloats[ndx] = inputFloats[ndx] + 10.f;
5320 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
5322 map<string, string> specializations;
5323 ComputeShaderSpec spec;
5325 specializations["CONTROL"] = cases[caseNdx].param;
5326 spec.assembly = shaderTemplate.specialize(specializations);
5327 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
5328 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
5329 spec.numWorkGroups = IVec3(numElements, 1, 1);
5331 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
5334 return group.release();
5337 tcu::TestCaseGroup* createMemoryAccessGroup (tcu::TestContext& testCtx)
5339 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "memory_access", "Tests memory access cases"));
5340 vector<CaseParameter> cases;
5341 de::Random rnd (deStringHash(group->getName()));
5342 const int numElements = 100;
5343 vector<float> inputFloats (numElements, 0);
5344 vector<float> outputFloats (numElements, 0);
5345 const StringTemplate shaderTemplate (
5346 string(getComputeAsmShaderPreamble()) +
5348 "OpSource GLSL 430\n"
5349 "OpName %main \"main\"\n"
5350 "OpName %id \"gl_GlobalInvocationID\"\n"
5352 "OpDecorate %id BuiltIn GlobalInvocationId\n"
5354 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
5356 "%f32ptr_f = OpTypePointer Function %f32\n"
5358 "%id = OpVariable %uvec3ptr Input\n"
5359 "%zero = OpConstant %i32 0\n"
5360 "%four = OpConstant %i32 4\n"
5362 "%main = OpFunction %void None %voidf\n"
5363 "%label = OpLabel\n"
5364 "%copy = OpVariable %f32ptr_f Function\n"
5365 "%idval = OpLoad %uvec3 %id ${ACCESS}\n"
5366 "%x = OpCompositeExtract %u32 %idval 0\n"
5367 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
5368 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
5369 " OpCopyMemory %copy %inloc ${ACCESS}\n"
5370 "%val1 = OpLoad %f32 %copy\n"
5371 "%val2 = OpLoad %f32 %inloc\n"
5372 "%add = OpFAdd %f32 %val1 %val2\n"
5373 " OpStore %outloc %add ${ACCESS}\n"
5375 " OpFunctionEnd\n");
5377 cases.push_back(CaseParameter("null", ""));
5378 cases.push_back(CaseParameter("none", "None"));
5379 cases.push_back(CaseParameter("volatile", "Volatile"));
5380 cases.push_back(CaseParameter("aligned", "Aligned 4"));
5381 cases.push_back(CaseParameter("nontemporal", "Nontemporal"));
5382 cases.push_back(CaseParameter("aligned_nontemporal", "Aligned|Nontemporal 4"));
5383 cases.push_back(CaseParameter("aligned_volatile", "Volatile|Aligned 4"));
5385 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats[0], numElements);
5387 for (size_t ndx = 0; ndx < numElements; ++ndx)
5388 outputFloats[ndx] = inputFloats[ndx] + inputFloats[ndx];
5390 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
5392 map<string, string> specializations;
5393 ComputeShaderSpec spec;
5395 specializations["ACCESS"] = cases[caseNdx].param;
5396 spec.assembly = shaderTemplate.specialize(specializations);
5397 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
5398 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
5399 spec.numWorkGroups = IVec3(numElements, 1, 1);
5401 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
5404 return group.release();
5407 // Checks that we can get undefined values for various types, without exercising a computation with it.
5408 tcu::TestCaseGroup* createOpUndefGroup (tcu::TestContext& testCtx)
5410 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opundef", "Tests the OpUndef instruction"));
5411 vector<CaseParameter> cases;
5412 de::Random rnd (deStringHash(group->getName()));
5413 const int numElements = 100;
5414 vector<float> positiveFloats (numElements, 0);
5415 vector<float> negativeFloats (numElements, 0);
5416 const StringTemplate shaderTemplate (
5417 string(getComputeAsmShaderPreamble()) +
5419 "OpSource GLSL 430\n"
5420 "OpName %main \"main\"\n"
5421 "OpName %id \"gl_GlobalInvocationID\"\n"
5423 "OpDecorate %id BuiltIn GlobalInvocationId\n"
5425 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
5426 "%uvec2 = OpTypeVector %u32 2\n"
5427 "%fvec4 = OpTypeVector %f32 4\n"
5428 "%fmat33 = OpTypeMatrix %fvec3 3\n"
5429 "%image = OpTypeImage %f32 2D 0 0 0 1 Unknown\n"
5430 "%sampler = OpTypeSampler\n"
5431 "%simage = OpTypeSampledImage %image\n"
5432 "%const100 = OpConstant %u32 100\n"
5433 "%uarr100 = OpTypeArray %i32 %const100\n"
5434 "%struct = OpTypeStruct %f32 %i32 %u32\n"
5435 "%pointer = OpTypePointer Function %i32\n"
5436 + string(getComputeAsmInputOutputBuffer()) +
5438 "%id = OpVariable %uvec3ptr Input\n"
5439 "%zero = OpConstant %i32 0\n"
5441 "%main = OpFunction %void None %voidf\n"
5442 "%label = OpLabel\n"
5444 "%undef = OpUndef ${TYPE}\n"
5446 "%idval = OpLoad %uvec3 %id\n"
5447 "%x = OpCompositeExtract %u32 %idval 0\n"
5449 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
5450 "%inval = OpLoad %f32 %inloc\n"
5451 "%neg = OpFNegate %f32 %inval\n"
5452 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
5453 " OpStore %outloc %neg\n"
5455 " OpFunctionEnd\n");
5457 cases.push_back(CaseParameter("bool", "%bool"));
5458 cases.push_back(CaseParameter("sint32", "%i32"));
5459 cases.push_back(CaseParameter("uint32", "%u32"));
5460 cases.push_back(CaseParameter("float32", "%f32"));
5461 cases.push_back(CaseParameter("vec4float32", "%fvec4"));
5462 cases.push_back(CaseParameter("vec2uint32", "%uvec2"));
5463 cases.push_back(CaseParameter("matrix", "%fmat33"));
5464 cases.push_back(CaseParameter("image", "%image"));
5465 cases.push_back(CaseParameter("sampler", "%sampler"));
5466 cases.push_back(CaseParameter("sampledimage", "%simage"));
5467 cases.push_back(CaseParameter("array", "%uarr100"));
5468 cases.push_back(CaseParameter("runtimearray", "%f32arr"));
5469 cases.push_back(CaseParameter("struct", "%struct"));
5470 cases.push_back(CaseParameter("pointer", "%pointer"));
5472 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
5474 for (size_t ndx = 0; ndx < numElements; ++ndx)
5475 negativeFloats[ndx] = -positiveFloats[ndx];
5477 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
5479 map<string, string> specializations;
5480 ComputeShaderSpec spec;
5482 specializations["TYPE"] = cases[caseNdx].param;
5483 spec.assembly = shaderTemplate.specialize(specializations);
5484 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
5485 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
5486 spec.numWorkGroups = IVec3(numElements, 1, 1);
5488 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
5491 return group.release();
5495 tcu::TestCaseGroup* createOpSourceTests (tcu::TestContext& testCtx)
5497 struct NameCodePair { string name, code; };
5498 RGBA defaultColors[4];
5499 de::MovePtr<tcu::TestCaseGroup> opSourceTests (new tcu::TestCaseGroup(testCtx, "opsource", "OpSource instruction"));
5500 const std::string opsourceGLSLWithFile = "%opsrcfile = OpString \"foo.vert\"\nOpSource GLSL 450 %opsrcfile ";
5501 map<string, string> fragments = passthruFragments();
5502 const NameCodePair tests[] =
5504 {"unknown", "OpSource Unknown 321"},
5505 {"essl", "OpSource ESSL 310"},
5506 {"glsl", "OpSource GLSL 450"},
5507 {"opencl_cpp", "OpSource OpenCL_CPP 120"},
5508 {"opencl_c", "OpSource OpenCL_C 120"},
5509 {"multiple", "OpSource GLSL 450\nOpSource GLSL 450"},
5510 {"file", opsourceGLSLWithFile},
5511 {"source", opsourceGLSLWithFile + "\"void main(){}\""},
5512 // Longest possible source string: SPIR-V limits instructions to 65535
5513 // words, of which the first 4 are opsourceGLSLWithFile; the rest will
5514 // contain 65530 UTF8 characters (one word each) plus one last word
5515 // containing 3 ASCII characters and \0.
5516 {"longsource", opsourceGLSLWithFile + '"' + makeLongUTF8String(65530) + "ccc" + '"'}
5519 getDefaultColors(defaultColors);
5520 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameCodePair); ++testNdx)
5522 fragments["debug"] = tests[testNdx].code;
5523 createTestsForAllStages(tests[testNdx].name, defaultColors, defaultColors, fragments, opSourceTests.get());
5526 return opSourceTests.release();
5529 tcu::TestCaseGroup* createOpSourceContinuedTests (tcu::TestContext& testCtx)
5531 struct NameCodePair { string name, code; };
5532 RGBA defaultColors[4];
5533 de::MovePtr<tcu::TestCaseGroup> opSourceTests (new tcu::TestCaseGroup(testCtx, "opsourcecontinued", "OpSourceContinued instruction"));
5534 map<string, string> fragments = passthruFragments();
5535 const std::string opsource = "%opsrcfile = OpString \"foo.vert\"\nOpSource GLSL 450 %opsrcfile \"void main(){}\"\n";
5536 const NameCodePair tests[] =
5538 {"empty", opsource + "OpSourceContinued \"\""},
5539 {"short", opsource + "OpSourceContinued \"abcde\""},
5540 {"multiple", opsource + "OpSourceContinued \"abcde\"\nOpSourceContinued \"fghij\""},
5541 // Longest possible source string: SPIR-V limits instructions to 65535
5542 // words, of which the first one is OpSourceContinued/length; the rest
5543 // will contain 65533 UTF8 characters (one word each) plus one last word
5544 // containing 3 ASCII characters and \0.
5545 {"long", opsource + "OpSourceContinued \"" + makeLongUTF8String(65533) + "ccc\""}
5548 getDefaultColors(defaultColors);
5549 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameCodePair); ++testNdx)
5551 fragments["debug"] = tests[testNdx].code;
5552 createTestsForAllStages(tests[testNdx].name, defaultColors, defaultColors, fragments, opSourceTests.get());
5555 return opSourceTests.release();
5557 tcu::TestCaseGroup* createOpNoLineTests(tcu::TestContext& testCtx)
5559 RGBA defaultColors[4];
5560 de::MovePtr<tcu::TestCaseGroup> opLineTests (new tcu::TestCaseGroup(testCtx, "opnoline", "OpNoLine instruction"));
5561 map<string, string> fragments;
5562 getDefaultColors(defaultColors);
5563 fragments["debug"] =
5564 "%name = OpString \"name\"\n";
5566 fragments["pre_main"] =
5569 "OpLine %name 1 1\n"
5571 "OpLine %name 1 1\n"
5572 "OpLine %name 1 1\n"
5573 "%second_function = OpFunction %v4f32 None %v4f32_v4f32_function\n"
5575 "OpLine %name 1 1\n"
5577 "OpLine %name 1 1\n"
5578 "OpLine %name 1 1\n"
5579 "%second_param1 = OpFunctionParameter %v4f32\n"
5582 "%label_secondfunction = OpLabel\n"
5584 "OpReturnValue %second_param1\n"
5589 fragments["testfun"] =
5590 // A %test_code function that returns its argument unchanged.
5593 "OpLine %name 1 1\n"
5594 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
5596 "%param1 = OpFunctionParameter %v4f32\n"
5599 "%label_testfun = OpLabel\n"
5601 "%val1 = OpFunctionCall %v4f32 %second_function %param1\n"
5602 "OpReturnValue %val1\n"
5604 "OpLine %name 1 1\n"
5607 createTestsForAllStages("opnoline", defaultColors, defaultColors, fragments, opLineTests.get());
5609 return opLineTests.release();
5612 tcu::TestCaseGroup* createOpModuleProcessedTests(tcu::TestContext& testCtx)
5614 RGBA defaultColors[4];
5615 de::MovePtr<tcu::TestCaseGroup> opModuleProcessedTests (new tcu::TestCaseGroup(testCtx, "opmoduleprocessed", "OpModuleProcessed instruction"));
5616 map<string, string> fragments;
5617 std::vector<std::string> noExtensions;
5618 GraphicsResources resources;
5620 getDefaultColors(defaultColors);
5621 resources.verifyBinary = veryfiBinaryShader;
5622 resources.spirvVersion = SPIRV_VERSION_1_3;
5624 fragments["moduleprocessed"] =
5625 "OpModuleProcessed \"VULKAN CTS\"\n"
5626 "OpModuleProcessed \"Negative values\"\n"
5627 "OpModuleProcessed \"Date: 2017/09/21\"\n";
5629 fragments["pre_main"] =
5630 "%second_function = OpFunction %v4f32 None %v4f32_v4f32_function\n"
5631 "%second_param1 = OpFunctionParameter %v4f32\n"
5632 "%label_secondfunction = OpLabel\n"
5633 "OpReturnValue %second_param1\n"
5636 fragments["testfun"] =
5637 // A %test_code function that returns its argument unchanged.
5638 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
5639 "%param1 = OpFunctionParameter %v4f32\n"
5640 "%label_testfun = OpLabel\n"
5641 "%val1 = OpFunctionCall %v4f32 %second_function %param1\n"
5642 "OpReturnValue %val1\n"
5645 createTestsForAllStages ("opmoduleprocessed", defaultColors, defaultColors, fragments, resources, noExtensions, opModuleProcessedTests.get());
5647 return opModuleProcessedTests.release();
5651 tcu::TestCaseGroup* createOpLineTests(tcu::TestContext& testCtx)
5653 RGBA defaultColors[4];
5654 de::MovePtr<tcu::TestCaseGroup> opLineTests (new tcu::TestCaseGroup(testCtx, "opline", "OpLine instruction"));
5655 map<string, string> fragments;
5656 std::vector<std::pair<std::string, std::string> > problemStrings;
5658 problemStrings.push_back(std::make_pair<std::string, std::string>("empty_name", ""));
5659 problemStrings.push_back(std::make_pair<std::string, std::string>("short_name", "short_name"));
5660 problemStrings.push_back(std::make_pair<std::string, std::string>("long_name", makeLongUTF8String(65530) + "ccc"));
5661 getDefaultColors(defaultColors);
5663 fragments["debug"] =
5664 "%other_name = OpString \"other_name\"\n";
5666 fragments["pre_main"] =
5667 "OpLine %file_name 32 0\n"
5668 "OpLine %file_name 32 32\n"
5669 "OpLine %file_name 32 40\n"
5670 "OpLine %other_name 32 40\n"
5671 "OpLine %other_name 0 100\n"
5672 "OpLine %other_name 0 4294967295\n"
5673 "OpLine %other_name 4294967295 0\n"
5674 "OpLine %other_name 32 40\n"
5675 "OpLine %file_name 0 0\n"
5676 "%second_function = OpFunction %v4f32 None %v4f32_v4f32_function\n"
5677 "OpLine %file_name 1 0\n"
5678 "%second_param1 = OpFunctionParameter %v4f32\n"
5679 "OpLine %file_name 1 3\n"
5680 "OpLine %file_name 1 2\n"
5681 "%label_secondfunction = OpLabel\n"
5682 "OpLine %file_name 0 2\n"
5683 "OpReturnValue %second_param1\n"
5685 "OpLine %file_name 0 2\n"
5686 "OpLine %file_name 0 2\n";
5688 fragments["testfun"] =
5689 // A %test_code function that returns its argument unchanged.
5690 "OpLine %file_name 1 0\n"
5691 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
5692 "OpLine %file_name 16 330\n"
5693 "%param1 = OpFunctionParameter %v4f32\n"
5694 "OpLine %file_name 14 442\n"
5695 "%label_testfun = OpLabel\n"
5696 "OpLine %file_name 11 1024\n"
5697 "%val1 = OpFunctionCall %v4f32 %second_function %param1\n"
5698 "OpLine %file_name 2 97\n"
5699 "OpReturnValue %val1\n"
5701 "OpLine %file_name 5 32\n";
5703 for (size_t i = 0; i < problemStrings.size(); ++i)
5705 map<string, string> testFragments = fragments;
5706 testFragments["debug"] += "%file_name = OpString \"" + problemStrings[i].second + "\"\n";
5707 createTestsForAllStages(string("opline") + "_" + problemStrings[i].first, defaultColors, defaultColors, testFragments, opLineTests.get());
5710 return opLineTests.release();
5713 tcu::TestCaseGroup* createOpConstantNullTests(tcu::TestContext& testCtx)
5715 de::MovePtr<tcu::TestCaseGroup> opConstantNullTests (new tcu::TestCaseGroup(testCtx, "opconstantnull", "OpConstantNull instruction"));
5719 const char functionStart[] =
5720 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
5721 "%param1 = OpFunctionParameter %v4f32\n"
5724 const char functionEnd[] =
5725 "OpReturnValue %transformed_param\n"
5728 struct NameConstantsCode
5735 NameConstantsCode tests[] =
5739 "%cnull = OpConstantNull %v4f32\n",
5740 "%transformed_param = OpFAdd %v4f32 %param1 %cnull\n"
5744 "%cnull = OpConstantNull %f32\n",
5745 "%vp = OpVariable %fp_v4f32 Function\n"
5746 "%v = OpLoad %v4f32 %vp\n"
5747 "%v0 = OpVectorInsertDynamic %v4f32 %v %cnull %c_i32_0\n"
5748 "%v1 = OpVectorInsertDynamic %v4f32 %v0 %cnull %c_i32_1\n"
5749 "%v2 = OpVectorInsertDynamic %v4f32 %v1 %cnull %c_i32_2\n"
5750 "%v3 = OpVectorInsertDynamic %v4f32 %v2 %cnull %c_i32_3\n"
5751 "%transformed_param = OpFAdd %v4f32 %param1 %v3\n"
5755 "%cnull = OpConstantNull %bool\n",
5756 "%v = OpVariable %fp_v4f32 Function\n"
5757 " OpStore %v %param1\n"
5758 " OpSelectionMerge %false_label None\n"
5759 " OpBranchConditional %cnull %true_label %false_label\n"
5760 "%true_label = OpLabel\n"
5761 " OpStore %v %c_v4f32_0_5_0_5_0_5_0_5\n"
5762 " OpBranch %false_label\n"
5763 "%false_label = OpLabel\n"
5764 "%transformed_param = OpLoad %v4f32 %v\n"
5768 "%cnull = OpConstantNull %i32\n",
5769 "%v = OpVariable %fp_v4f32 Function %c_v4f32_0_5_0_5_0_5_0_5\n"
5770 "%b = OpIEqual %bool %cnull %c_i32_0\n"
5771 " OpSelectionMerge %false_label None\n"
5772 " OpBranchConditional %b %true_label %false_label\n"
5773 "%true_label = OpLabel\n"
5774 " OpStore %v %param1\n"
5775 " OpBranch %false_label\n"
5776 "%false_label = OpLabel\n"
5777 "%transformed_param = OpLoad %v4f32 %v\n"
5781 "%stype = OpTypeStruct %f32 %v4f32\n"
5782 "%fp_stype = OpTypePointer Function %stype\n"
5783 "%cnull = OpConstantNull %stype\n",
5784 "%v = OpVariable %fp_stype Function %cnull\n"
5785 "%f = OpAccessChain %fp_v4f32 %v %c_i32_1\n"
5786 "%f_val = OpLoad %v4f32 %f\n"
5787 "%transformed_param = OpFAdd %v4f32 %param1 %f_val\n"
5791 "%a4_v4f32 = OpTypeArray %v4f32 %c_u32_4\n"
5792 "%fp_a4_v4f32 = OpTypePointer Function %a4_v4f32\n"
5793 "%cnull = OpConstantNull %a4_v4f32\n",
5794 "%v = OpVariable %fp_a4_v4f32 Function %cnull\n"
5795 "%f = OpAccessChain %fp_v4f32 %v %c_u32_0\n"
5796 "%f1 = OpAccessChain %fp_v4f32 %v %c_u32_1\n"
5797 "%f2 = OpAccessChain %fp_v4f32 %v %c_u32_2\n"
5798 "%f3 = OpAccessChain %fp_v4f32 %v %c_u32_3\n"
5799 "%f_val = OpLoad %v4f32 %f\n"
5800 "%f1_val = OpLoad %v4f32 %f1\n"
5801 "%f2_val = OpLoad %v4f32 %f2\n"
5802 "%f3_val = OpLoad %v4f32 %f3\n"
5803 "%t0 = OpFAdd %v4f32 %param1 %f_val\n"
5804 "%t1 = OpFAdd %v4f32 %t0 %f1_val\n"
5805 "%t2 = OpFAdd %v4f32 %t1 %f2_val\n"
5806 "%transformed_param = OpFAdd %v4f32 %t2 %f3_val\n"
5810 "%mat4x4_f32 = OpTypeMatrix %v4f32 4\n"
5811 "%cnull = OpConstantNull %mat4x4_f32\n",
5812 // Our null matrix * any vector should result in a zero vector.
5813 "%v = OpVectorTimesMatrix %v4f32 %param1 %cnull\n"
5814 "%transformed_param = OpFAdd %v4f32 %param1 %v\n"
5818 getHalfColorsFullAlpha(colors);
5820 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameConstantsCode); ++testNdx)
5822 map<string, string> fragments;
5823 fragments["pre_main"] = tests[testNdx].constants;
5824 fragments["testfun"] = string(functionStart) + tests[testNdx].code + functionEnd;
5825 createTestsForAllStages(tests[testNdx].name, colors, colors, fragments, opConstantNullTests.get());
5827 return opConstantNullTests.release();
5829 tcu::TestCaseGroup* createOpConstantCompositeTests(tcu::TestContext& testCtx)
5831 de::MovePtr<tcu::TestCaseGroup> opConstantCompositeTests (new tcu::TestCaseGroup(testCtx, "opconstantcomposite", "OpConstantComposite instruction"));
5832 RGBA inputColors[4];
5833 RGBA outputColors[4];
5836 const char functionStart[] =
5837 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
5838 "%param1 = OpFunctionParameter %v4f32\n"
5841 const char functionEnd[] =
5842 "OpReturnValue %transformed_param\n"
5845 struct NameConstantsCode
5852 NameConstantsCode tests[] =
5857 "%cval = OpConstantComposite %v4f32 %c_f32_0_5 %c_f32_0_5 %c_f32_0_5 %c_f32_0\n",
5858 "%transformed_param = OpFAdd %v4f32 %param1 %cval\n"
5863 "%stype = OpTypeStruct %v4f32 %f32\n"
5864 "%fp_stype = OpTypePointer Function %stype\n"
5865 "%f32_n_1 = OpConstant %f32 -1.0\n"
5866 "%f32_1_5 = OpConstant %f32 !0x3fc00000\n" // +1.5
5867 "%cvec = OpConstantComposite %v4f32 %f32_1_5 %f32_1_5 %f32_1_5 %c_f32_1\n"
5868 "%cval = OpConstantComposite %stype %cvec %f32_n_1\n",
5870 "%v = OpVariable %fp_stype Function %cval\n"
5871 "%vec_ptr = OpAccessChain %fp_v4f32 %v %c_u32_0\n"
5872 "%f32_ptr = OpAccessChain %fp_f32 %v %c_u32_1\n"
5873 "%vec_val = OpLoad %v4f32 %vec_ptr\n"
5874 "%f32_val = OpLoad %f32 %f32_ptr\n"
5875 "%tmp1 = OpVectorTimesScalar %v4f32 %c_v4f32_1_1_1_1 %f32_val\n" // vec4(-1)
5876 "%tmp2 = OpFAdd %v4f32 %tmp1 %param1\n" // param1 + vec4(-1)
5877 "%transformed_param = OpFAdd %v4f32 %tmp2 %vec_val\n" // param1 + vec4(-1) + vec4(1.5, 1.5, 1.5, 1.0)
5880 // [1|0|0|0.5] [x] = x + 0.5
5881 // [0|1|0|0.5] [y] = y + 0.5
5882 // [0|0|1|0.5] [z] = z + 0.5
5883 // [0|0|0|1 ] [1] = 1
5886 "%mat4x4_f32 = OpTypeMatrix %v4f32 4\n"
5887 "%v4f32_1_0_0_0 = OpConstantComposite %v4f32 %c_f32_1 %c_f32_0 %c_f32_0 %c_f32_0\n"
5888 "%v4f32_0_1_0_0 = OpConstantComposite %v4f32 %c_f32_0 %c_f32_1 %c_f32_0 %c_f32_0\n"
5889 "%v4f32_0_0_1_0 = OpConstantComposite %v4f32 %c_f32_0 %c_f32_0 %c_f32_1 %c_f32_0\n"
5890 "%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"
5891 "%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",
5893 "%transformed_param = OpMatrixTimesVector %v4f32 %cval %param1\n"
5898 "%c_v4f32_1_1_1_0 = OpConstantComposite %v4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_0\n"
5899 "%fp_a4f32 = OpTypePointer Function %a4f32\n"
5900 "%f32_n_1 = OpConstant %f32 -1.0\n"
5901 "%f32_1_5 = OpConstant %f32 !0x3fc00000\n" // +1.5
5902 "%carr = OpConstantComposite %a4f32 %c_f32_0 %f32_n_1 %f32_1_5 %c_f32_0\n",
5904 "%v = OpVariable %fp_a4f32 Function %carr\n"
5905 "%f = OpAccessChain %fp_f32 %v %c_u32_0\n"
5906 "%f1 = OpAccessChain %fp_f32 %v %c_u32_1\n"
5907 "%f2 = OpAccessChain %fp_f32 %v %c_u32_2\n"
5908 "%f3 = OpAccessChain %fp_f32 %v %c_u32_3\n"
5909 "%f_val = OpLoad %f32 %f\n"
5910 "%f1_val = OpLoad %f32 %f1\n"
5911 "%f2_val = OpLoad %f32 %f2\n"
5912 "%f3_val = OpLoad %f32 %f3\n"
5913 "%ftot1 = OpFAdd %f32 %f_val %f1_val\n"
5914 "%ftot2 = OpFAdd %f32 %ftot1 %f2_val\n"
5915 "%ftot3 = OpFAdd %f32 %ftot2 %f3_val\n" // 0 - 1 + 1.5 + 0
5916 "%add_vec = OpVectorTimesScalar %v4f32 %c_v4f32_1_1_1_0 %ftot3\n"
5917 "%transformed_param = OpFAdd %v4f32 %param1 %add_vec\n"
5924 // [ 1.0, 1.0, 1.0, 1.0]
5928 // [ 0.0, 0.5, 0.0, 0.0]
5932 // [ 1.0, 1.0, 1.0, 1.0]
5935 "array_of_struct_of_array",
5937 "%c_v4f32_1_1_1_0 = OpConstantComposite %v4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_0\n"
5938 "%fp_a4f32 = OpTypePointer Function %a4f32\n"
5939 "%stype = OpTypeStruct %f32 %a4f32\n"
5940 "%a3stype = OpTypeArray %stype %c_u32_3\n"
5941 "%fp_a3stype = OpTypePointer Function %a3stype\n"
5942 "%ca4f32_0 = OpConstantComposite %a4f32 %c_f32_0 %c_f32_0_5 %c_f32_0 %c_f32_0\n"
5943 "%ca4f32_1 = OpConstantComposite %a4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_1\n"
5944 "%cstype1 = OpConstantComposite %stype %c_f32_0 %ca4f32_1\n"
5945 "%cstype2 = OpConstantComposite %stype %c_f32_1 %ca4f32_0\n"
5946 "%carr = OpConstantComposite %a3stype %cstype1 %cstype2 %cstype1",
5948 "%v = OpVariable %fp_a3stype Function %carr\n"
5949 "%f = OpAccessChain %fp_f32 %v %c_u32_1 %c_u32_1 %c_u32_1\n"
5950 "%f_l = OpLoad %f32 %f\n"
5951 "%add_vec = OpVectorTimesScalar %v4f32 %c_v4f32_1_1_1_0 %f_l\n"
5952 "%transformed_param = OpFAdd %v4f32 %param1 %add_vec\n"
5956 getHalfColorsFullAlpha(inputColors);
5957 outputColors[0] = RGBA(255, 255, 255, 255);
5958 outputColors[1] = RGBA(255, 127, 127, 255);
5959 outputColors[2] = RGBA(127, 255, 127, 255);
5960 outputColors[3] = RGBA(127, 127, 255, 255);
5962 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameConstantsCode); ++testNdx)
5964 map<string, string> fragments;
5965 fragments["pre_main"] = tests[testNdx].constants;
5966 fragments["testfun"] = string(functionStart) + tests[testNdx].code + functionEnd;
5967 createTestsForAllStages(tests[testNdx].name, inputColors, outputColors, fragments, opConstantCompositeTests.get());
5969 return opConstantCompositeTests.release();
5972 tcu::TestCaseGroup* createSelectionBlockOrderTests(tcu::TestContext& testCtx)
5974 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "selection_block_order", "Out-of-order blocks for selection"));
5975 RGBA inputColors[4];
5976 RGBA outputColors[4];
5977 map<string, string> fragments;
5979 // vec4 test_code(vec4 param) {
5980 // vec4 result = param;
5981 // for (int i = 0; i < 4; ++i) {
5982 // if (i == 0) result[i] = 0.;
5983 // else result[i] = 1. - result[i];
5987 const char function[] =
5988 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
5989 "%param1 = OpFunctionParameter %v4f32\n"
5991 "%iptr = OpVariable %fp_i32 Function\n"
5992 "%result = OpVariable %fp_v4f32 Function\n"
5993 " OpStore %iptr %c_i32_0\n"
5994 " OpStore %result %param1\n"
5997 // Loop entry block.
5999 "%ival = OpLoad %i32 %iptr\n"
6000 "%lt_4 = OpSLessThan %bool %ival %c_i32_4\n"
6001 " OpLoopMerge %exit %if_entry None\n"
6002 " OpBranchConditional %lt_4 %if_entry %exit\n"
6004 // Merge block for loop.
6006 "%ret = OpLoad %v4f32 %result\n"
6007 " OpReturnValue %ret\n"
6009 // If-statement entry block.
6010 "%if_entry = OpLabel\n"
6011 "%loc = OpAccessChain %fp_f32 %result %ival\n"
6012 "%eq_0 = OpIEqual %bool %ival %c_i32_0\n"
6013 " OpSelectionMerge %if_exit None\n"
6014 " OpBranchConditional %eq_0 %if_true %if_false\n"
6016 // False branch for if-statement.
6017 "%if_false = OpLabel\n"
6018 "%val = OpLoad %f32 %loc\n"
6019 "%sub = OpFSub %f32 %c_f32_1 %val\n"
6020 " OpStore %loc %sub\n"
6021 " OpBranch %if_exit\n"
6023 // Merge block for if-statement.
6024 "%if_exit = OpLabel\n"
6025 "%ival_next = OpIAdd %i32 %ival %c_i32_1\n"
6026 " OpStore %iptr %ival_next\n"
6029 // True branch for if-statement.
6030 "%if_true = OpLabel\n"
6031 " OpStore %loc %c_f32_0\n"
6032 " OpBranch %if_exit\n"
6036 fragments["testfun"] = function;
6038 inputColors[0] = RGBA(127, 127, 127, 0);
6039 inputColors[1] = RGBA(127, 0, 0, 0);
6040 inputColors[2] = RGBA(0, 127, 0, 0);
6041 inputColors[3] = RGBA(0, 0, 127, 0);
6043 outputColors[0] = RGBA(0, 128, 128, 255);
6044 outputColors[1] = RGBA(0, 255, 255, 255);
6045 outputColors[2] = RGBA(0, 128, 255, 255);
6046 outputColors[3] = RGBA(0, 255, 128, 255);
6048 createTestsForAllStages("out_of_order", inputColors, outputColors, fragments, group.get());
6050 return group.release();
6053 tcu::TestCaseGroup* createSwitchBlockOrderTests(tcu::TestContext& testCtx)
6055 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "switch_block_order", "Out-of-order blocks for switch"));
6056 RGBA inputColors[4];
6057 RGBA outputColors[4];
6058 map<string, string> fragments;
6060 const char typesAndConstants[] =
6061 "%c_f32_p2 = OpConstant %f32 0.2\n"
6062 "%c_f32_p4 = OpConstant %f32 0.4\n"
6063 "%c_f32_p6 = OpConstant %f32 0.6\n"
6064 "%c_f32_p8 = OpConstant %f32 0.8\n";
6066 // vec4 test_code(vec4 param) {
6067 // vec4 result = param;
6068 // for (int i = 0; i < 4; ++i) {
6070 // case 0: result[i] += .2; break;
6071 // case 1: result[i] += .6; break;
6072 // case 2: result[i] += .4; break;
6073 // case 3: result[i] += .8; break;
6074 // default: break; // unreachable
6079 const char function[] =
6080 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
6081 "%param1 = OpFunctionParameter %v4f32\n"
6083 "%iptr = OpVariable %fp_i32 Function\n"
6084 "%result = OpVariable %fp_v4f32 Function\n"
6085 " OpStore %iptr %c_i32_0\n"
6086 " OpStore %result %param1\n"
6089 // Loop entry block.
6091 "%ival = OpLoad %i32 %iptr\n"
6092 "%lt_4 = OpSLessThan %bool %ival %c_i32_4\n"
6093 " OpLoopMerge %exit %switch_exit None\n"
6094 " OpBranchConditional %lt_4 %switch_entry %exit\n"
6096 // Merge block for loop.
6098 "%ret = OpLoad %v4f32 %result\n"
6099 " OpReturnValue %ret\n"
6101 // Switch-statement entry block.
6102 "%switch_entry = OpLabel\n"
6103 "%loc = OpAccessChain %fp_f32 %result %ival\n"
6104 "%val = OpLoad %f32 %loc\n"
6105 " OpSelectionMerge %switch_exit None\n"
6106 " OpSwitch %ival %switch_default 0 %case0 1 %case1 2 %case2 3 %case3\n"
6108 "%case2 = OpLabel\n"
6109 "%addp4 = OpFAdd %f32 %val %c_f32_p4\n"
6110 " OpStore %loc %addp4\n"
6111 " OpBranch %switch_exit\n"
6113 "%switch_default = OpLabel\n"
6116 "%case3 = OpLabel\n"
6117 "%addp8 = OpFAdd %f32 %val %c_f32_p8\n"
6118 " OpStore %loc %addp8\n"
6119 " OpBranch %switch_exit\n"
6121 "%case0 = OpLabel\n"
6122 "%addp2 = OpFAdd %f32 %val %c_f32_p2\n"
6123 " OpStore %loc %addp2\n"
6124 " OpBranch %switch_exit\n"
6126 // Merge block for switch-statement.
6127 "%switch_exit = OpLabel\n"
6128 "%ival_next = OpIAdd %i32 %ival %c_i32_1\n"
6129 " OpStore %iptr %ival_next\n"
6132 "%case1 = OpLabel\n"
6133 "%addp6 = OpFAdd %f32 %val %c_f32_p6\n"
6134 " OpStore %loc %addp6\n"
6135 " OpBranch %switch_exit\n"
6139 fragments["pre_main"] = typesAndConstants;
6140 fragments["testfun"] = function;
6142 inputColors[0] = RGBA(127, 27, 127, 51);
6143 inputColors[1] = RGBA(127, 0, 0, 51);
6144 inputColors[2] = RGBA(0, 27, 0, 51);
6145 inputColors[3] = RGBA(0, 0, 127, 51);
6147 outputColors[0] = RGBA(178, 180, 229, 255);
6148 outputColors[1] = RGBA(178, 153, 102, 255);
6149 outputColors[2] = RGBA(51, 180, 102, 255);
6150 outputColors[3] = RGBA(51, 153, 229, 255);
6152 createTestsForAllStages("out_of_order", inputColors, outputColors, fragments, group.get());
6154 return group.release();
6157 tcu::TestCaseGroup* createDecorationGroupTests(tcu::TestContext& testCtx)
6159 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "decoration_group", "Decoration group tests"));
6160 RGBA inputColors[4];
6161 RGBA outputColors[4];
6162 map<string, string> fragments;
6164 const char decorations[] =
6165 "OpDecorate %array_group ArrayStride 4\n"
6166 "OpDecorate %struct_member_group Offset 0\n"
6167 "%array_group = OpDecorationGroup\n"
6168 "%struct_member_group = OpDecorationGroup\n"
6170 "OpDecorate %group1 RelaxedPrecision\n"
6171 "OpDecorate %group3 RelaxedPrecision\n"
6172 "OpDecorate %group3 Invariant\n"
6173 "OpDecorate %group3 Restrict\n"
6174 "%group0 = OpDecorationGroup\n"
6175 "%group1 = OpDecorationGroup\n"
6176 "%group3 = OpDecorationGroup\n";
6178 const char typesAndConstants[] =
6179 "%a3f32 = OpTypeArray %f32 %c_u32_3\n"
6180 "%struct1 = OpTypeStruct %a3f32\n"
6181 "%struct2 = OpTypeStruct %a3f32\n"
6182 "%fp_struct1 = OpTypePointer Function %struct1\n"
6183 "%fp_struct2 = OpTypePointer Function %struct2\n"
6184 "%c_f32_2 = OpConstant %f32 2.\n"
6185 "%c_f32_n2 = OpConstant %f32 -2.\n"
6187 "%c_a3f32_1 = OpConstantComposite %a3f32 %c_f32_1 %c_f32_2 %c_f32_1\n"
6188 "%c_a3f32_2 = OpConstantComposite %a3f32 %c_f32_n1 %c_f32_n2 %c_f32_n1\n"
6189 "%c_struct1 = OpConstantComposite %struct1 %c_a3f32_1\n"
6190 "%c_struct2 = OpConstantComposite %struct2 %c_a3f32_2\n";
6192 const char function[] =
6193 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
6194 "%param = OpFunctionParameter %v4f32\n"
6195 "%entry = OpLabel\n"
6196 "%result = OpVariable %fp_v4f32 Function\n"
6197 "%v_struct1 = OpVariable %fp_struct1 Function\n"
6198 "%v_struct2 = OpVariable %fp_struct2 Function\n"
6199 " OpStore %result %param\n"
6200 " OpStore %v_struct1 %c_struct1\n"
6201 " OpStore %v_struct2 %c_struct2\n"
6202 "%ptr1 = OpAccessChain %fp_f32 %v_struct1 %c_i32_0 %c_i32_2\n"
6203 "%val1 = OpLoad %f32 %ptr1\n"
6204 "%ptr2 = OpAccessChain %fp_f32 %v_struct2 %c_i32_0 %c_i32_2\n"
6205 "%val2 = OpLoad %f32 %ptr2\n"
6206 "%addvalues = OpFAdd %f32 %val1 %val2\n"
6207 "%ptr = OpAccessChain %fp_f32 %result %c_i32_1\n"
6208 "%val = OpLoad %f32 %ptr\n"
6209 "%addresult = OpFAdd %f32 %addvalues %val\n"
6210 " OpStore %ptr %addresult\n"
6211 "%ret = OpLoad %v4f32 %result\n"
6212 " OpReturnValue %ret\n"
6215 struct CaseNameDecoration
6221 CaseNameDecoration tests[] =
6224 "same_decoration_group_on_multiple_types",
6225 "OpGroupMemberDecorate %struct_member_group %struct1 0 %struct2 0\n"
6228 "empty_decoration_group",
6229 "OpGroupDecorate %group0 %a3f32\n"
6230 "OpGroupDecorate %group0 %result\n"
6233 "one_element_decoration_group",
6234 "OpGroupDecorate %array_group %a3f32\n"
6237 "multiple_elements_decoration_group",
6238 "OpGroupDecorate %group3 %v_struct1\n"
6241 "multiple_decoration_groups_on_same_variable",
6242 "OpGroupDecorate %group0 %v_struct2\n"
6243 "OpGroupDecorate %group1 %v_struct2\n"
6244 "OpGroupDecorate %group3 %v_struct2\n"
6247 "same_decoration_group_multiple_times",
6248 "OpGroupDecorate %group1 %addvalues\n"
6249 "OpGroupDecorate %group1 %addvalues\n"
6250 "OpGroupDecorate %group1 %addvalues\n"
6255 getHalfColorsFullAlpha(inputColors);
6256 getHalfColorsFullAlpha(outputColors);
6258 for (size_t idx = 0; idx < (sizeof(tests) / sizeof(tests[0])); ++idx)
6260 fragments["decoration"] = decorations + tests[idx].decoration;
6261 fragments["pre_main"] = typesAndConstants;
6262 fragments["testfun"] = function;
6264 createTestsForAllStages(tests[idx].name, inputColors, outputColors, fragments, group.get());
6267 return group.release();
6270 struct SpecConstantTwoIntGraphicsCase
6272 const char* caseName;
6273 const char* scDefinition0;
6274 const char* scDefinition1;
6275 const char* scResultType;
6276 const char* scOperation;
6277 deInt32 scActualValue0;
6278 deInt32 scActualValue1;
6279 const char* resultOperation;
6280 RGBA expectedColors[4];
6282 SpecConstantTwoIntGraphicsCase (const char* name,
6283 const char* definition0,
6284 const char* definition1,
6285 const char* resultType,
6286 const char* operation,
6289 const char* resultOp,
6290 const RGBA (&output)[4])
6292 , scDefinition0 (definition0)
6293 , scDefinition1 (definition1)
6294 , scResultType (resultType)
6295 , scOperation (operation)
6296 , scActualValue0 (value0)
6297 , scActualValue1 (value1)
6298 , resultOperation (resultOp)
6300 expectedColors[0] = output[0];
6301 expectedColors[1] = output[1];
6302 expectedColors[2] = output[2];
6303 expectedColors[3] = output[3];
6307 tcu::TestCaseGroup* createSpecConstantTests (tcu::TestContext& testCtx)
6309 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opspecconstantop", "Test the OpSpecConstantOp instruction"));
6310 vector<SpecConstantTwoIntGraphicsCase> cases;
6311 RGBA inputColors[4];
6312 RGBA outputColors0[4];
6313 RGBA outputColors1[4];
6314 RGBA outputColors2[4];
6316 const char decorations1[] =
6317 "OpDecorate %sc_0 SpecId 0\n"
6318 "OpDecorate %sc_1 SpecId 1\n";
6320 const char typesAndConstants1[] =
6321 "${OPTYPE_DEFINITIONS:opt}"
6322 "%sc_0 = OpSpecConstant${SC_DEF0}\n"
6323 "%sc_1 = OpSpecConstant${SC_DEF1}\n"
6324 "%sc_op = OpSpecConstantOp ${SC_RESULT_TYPE} ${SC_OP}\n";
6326 const char function1[] =
6327 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
6328 "%param = OpFunctionParameter %v4f32\n"
6329 "%label = OpLabel\n"
6330 "${TYPE_CONVERT:opt}"
6331 "%result = OpVariable %fp_v4f32 Function\n"
6332 " OpStore %result %param\n"
6333 "%gen = ${GEN_RESULT}\n"
6334 "%index = OpIAdd %i32 %gen %c_i32_1\n"
6335 "%loc = OpAccessChain %fp_f32 %result %index\n"
6336 "%val = OpLoad %f32 %loc\n"
6337 "%add = OpFAdd %f32 %val %c_f32_0_5\n"
6338 " OpStore %loc %add\n"
6339 "%ret = OpLoad %v4f32 %result\n"
6340 " OpReturnValue %ret\n"
6343 inputColors[0] = RGBA(127, 127, 127, 255);
6344 inputColors[1] = RGBA(127, 0, 0, 255);
6345 inputColors[2] = RGBA(0, 127, 0, 255);
6346 inputColors[3] = RGBA(0, 0, 127, 255);
6348 // Derived from inputColors[x] by adding 128 to inputColors[x][0].
6349 outputColors0[0] = RGBA(255, 127, 127, 255);
6350 outputColors0[1] = RGBA(255, 0, 0, 255);
6351 outputColors0[2] = RGBA(128, 127, 0, 255);
6352 outputColors0[3] = RGBA(128, 0, 127, 255);
6354 // Derived from inputColors[x] by adding 128 to inputColors[x][1].
6355 outputColors1[0] = RGBA(127, 255, 127, 255);
6356 outputColors1[1] = RGBA(127, 128, 0, 255);
6357 outputColors1[2] = RGBA(0, 255, 0, 255);
6358 outputColors1[3] = RGBA(0, 128, 127, 255);
6360 // Derived from inputColors[x] by adding 128 to inputColors[x][2].
6361 outputColors2[0] = RGBA(127, 127, 255, 255);
6362 outputColors2[1] = RGBA(127, 0, 128, 255);
6363 outputColors2[2] = RGBA(0, 127, 128, 255);
6364 outputColors2[3] = RGBA(0, 0, 255, 255);
6366 const char addZeroToSc[] = "OpIAdd %i32 %c_i32_0 %sc_op";
6367 const char addZeroToSc32[] = "OpIAdd %i32 %c_i32_0 %sc_op32";
6368 const char selectTrueUsingSc[] = "OpSelect %i32 %sc_op %c_i32_1 %c_i32_0";
6369 const char selectFalseUsingSc[] = "OpSelect %i32 %sc_op %c_i32_0 %c_i32_1";
6371 cases.push_back(SpecConstantTwoIntGraphicsCase("iadd", " %i32 0", " %i32 0", "%i32", "IAdd %sc_0 %sc_1", 19, -20, addZeroToSc, outputColors0));
6372 cases.push_back(SpecConstantTwoIntGraphicsCase("isub", " %i32 0", " %i32 0", "%i32", "ISub %sc_0 %sc_1", 19, 20, addZeroToSc, outputColors0));
6373 cases.push_back(SpecConstantTwoIntGraphicsCase("imul", " %i32 0", " %i32 0", "%i32", "IMul %sc_0 %sc_1", -1, -1, addZeroToSc, outputColors2));
6374 cases.push_back(SpecConstantTwoIntGraphicsCase("sdiv", " %i32 0", " %i32 0", "%i32", "SDiv %sc_0 %sc_1", -126, 126, addZeroToSc, outputColors0));
6375 cases.push_back(SpecConstantTwoIntGraphicsCase("udiv", " %i32 0", " %i32 0", "%i32", "UDiv %sc_0 %sc_1", 126, 126, addZeroToSc, outputColors2));
6376 cases.push_back(SpecConstantTwoIntGraphicsCase("srem", " %i32 0", " %i32 0", "%i32", "SRem %sc_0 %sc_1", 3, 2, addZeroToSc, outputColors2));
6377 cases.push_back(SpecConstantTwoIntGraphicsCase("smod", " %i32 0", " %i32 0", "%i32", "SMod %sc_0 %sc_1", 3, 2, addZeroToSc, outputColors2));
6378 cases.push_back(SpecConstantTwoIntGraphicsCase("umod", " %i32 0", " %i32 0", "%i32", "UMod %sc_0 %sc_1", 1001, 500, addZeroToSc, outputColors2));
6379 cases.push_back(SpecConstantTwoIntGraphicsCase("bitwiseand", " %i32 0", " %i32 0", "%i32", "BitwiseAnd %sc_0 %sc_1", 0x33, 0x0d, addZeroToSc, outputColors2));
6380 cases.push_back(SpecConstantTwoIntGraphicsCase("bitwiseor", " %i32 0", " %i32 0", "%i32", "BitwiseOr %sc_0 %sc_1", 0, 1, addZeroToSc, outputColors2));
6381 cases.push_back(SpecConstantTwoIntGraphicsCase("bitwisexor", " %i32 0", " %i32 0", "%i32", "BitwiseXor %sc_0 %sc_1", 0x2e, 0x2f, addZeroToSc, outputColors2));
6382 cases.push_back(SpecConstantTwoIntGraphicsCase("shiftrightlogical", " %i32 0", " %i32 0", "%i32", "ShiftRightLogical %sc_0 %sc_1", 2, 1, addZeroToSc, outputColors2));
6383 cases.push_back(SpecConstantTwoIntGraphicsCase("shiftrightarithmetic", " %i32 0", " %i32 0", "%i32", "ShiftRightArithmetic %sc_0 %sc_1", -4, 2, addZeroToSc, outputColors0));
6384 cases.push_back(SpecConstantTwoIntGraphicsCase("shiftleftlogical", " %i32 0", " %i32 0", "%i32", "ShiftLeftLogical %sc_0 %sc_1", 1, 0, addZeroToSc, outputColors2));
6385 cases.push_back(SpecConstantTwoIntGraphicsCase("slessthan", " %i32 0", " %i32 0", "%bool", "SLessThan %sc_0 %sc_1", -20, -10, selectTrueUsingSc, outputColors2));
6386 cases.push_back(SpecConstantTwoIntGraphicsCase("ulessthan", " %i32 0", " %i32 0", "%bool", "ULessThan %sc_0 %sc_1", 10, 20, selectTrueUsingSc, outputColors2));
6387 cases.push_back(SpecConstantTwoIntGraphicsCase("sgreaterthan", " %i32 0", " %i32 0", "%bool", "SGreaterThan %sc_0 %sc_1", -1000, 50, selectFalseUsingSc, outputColors2));
6388 cases.push_back(SpecConstantTwoIntGraphicsCase("ugreaterthan", " %i32 0", " %i32 0", "%bool", "UGreaterThan %sc_0 %sc_1", 10, 5, selectTrueUsingSc, outputColors2));
6389 cases.push_back(SpecConstantTwoIntGraphicsCase("slessthanequal", " %i32 0", " %i32 0", "%bool", "SLessThanEqual %sc_0 %sc_1", -10, -10, selectTrueUsingSc, outputColors2));
6390 cases.push_back(SpecConstantTwoIntGraphicsCase("ulessthanequal", " %i32 0", " %i32 0", "%bool", "ULessThanEqual %sc_0 %sc_1", 50, 100, selectTrueUsingSc, outputColors2));
6391 cases.push_back(SpecConstantTwoIntGraphicsCase("sgreaterthanequal", " %i32 0", " %i32 0", "%bool", "SGreaterThanEqual %sc_0 %sc_1", -1000, 50, selectFalseUsingSc, outputColors2));
6392 cases.push_back(SpecConstantTwoIntGraphicsCase("ugreaterthanequal", " %i32 0", " %i32 0", "%bool", "UGreaterThanEqual %sc_0 %sc_1", 10, 10, selectTrueUsingSc, outputColors2));
6393 cases.push_back(SpecConstantTwoIntGraphicsCase("iequal", " %i32 0", " %i32 0", "%bool", "IEqual %sc_0 %sc_1", 42, 24, selectFalseUsingSc, outputColors2));
6394 cases.push_back(SpecConstantTwoIntGraphicsCase("logicaland", "True %bool", "True %bool", "%bool", "LogicalAnd %sc_0 %sc_1", 0, 1, selectFalseUsingSc, outputColors2));
6395 cases.push_back(SpecConstantTwoIntGraphicsCase("logicalor", "False %bool", "False %bool", "%bool", "LogicalOr %sc_0 %sc_1", 1, 0, selectTrueUsingSc, outputColors2));
6396 cases.push_back(SpecConstantTwoIntGraphicsCase("logicalequal", "True %bool", "True %bool", "%bool", "LogicalEqual %sc_0 %sc_1", 0, 1, selectFalseUsingSc, outputColors2));
6397 cases.push_back(SpecConstantTwoIntGraphicsCase("logicalnotequal", "False %bool", "False %bool", "%bool", "LogicalNotEqual %sc_0 %sc_1", 1, 0, selectTrueUsingSc, outputColors2));
6398 cases.push_back(SpecConstantTwoIntGraphicsCase("snegate", " %i32 0", " %i32 0", "%i32", "SNegate %sc_0", -1, 0, addZeroToSc, outputColors2));
6399 cases.push_back(SpecConstantTwoIntGraphicsCase("not", " %i32 0", " %i32 0", "%i32", "Not %sc_0", -2, 0, addZeroToSc, outputColors2));
6400 cases.push_back(SpecConstantTwoIntGraphicsCase("logicalnot", "False %bool", "False %bool", "%bool", "LogicalNot %sc_0", 1, 0, selectFalseUsingSc, outputColors2));
6401 cases.push_back(SpecConstantTwoIntGraphicsCase("select", "False %bool", " %i32 0", "%i32", "Select %sc_0 %sc_1 %c_i32_0", 1, 1, addZeroToSc, outputColors2));
6402 cases.push_back(SpecConstantTwoIntGraphicsCase("sconvert", " %i32 0", " %i32 0", "%i16", "SConvert %sc_0", -1, 0, addZeroToSc32, outputColors0));
6403 // -1082130432 stored as 32-bit two's complement is the binary representation of -1 as IEEE-754 Float
6404 cases.push_back(SpecConstantTwoIntGraphicsCase("fconvert", " %f32 0", " %f32 0", "%f64", "FConvert %sc_0", -1082130432, 0, addZeroToSc32, outputColors0));
6405 // \todo[2015-12-1 antiagainst] OpQuantizeToF16
6407 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
6409 map<string, string> specializations;
6410 map<string, string> fragments;
6411 vector<deInt32> specConstants;
6412 vector<string> features;
6413 PushConstants noPushConstants;
6414 GraphicsResources noResources;
6415 GraphicsInterfaces noInterfaces;
6416 std::vector<std::string> noExtensions;
6418 // Special SPIR-V code for SConvert-case
6419 if (strcmp(cases[caseNdx].caseName, "sconvert") == 0)
6421 features.push_back("shaderInt16");
6422 fragments["capability"] = "OpCapability Int16\n"; // Adds 16-bit integer capability
6423 specializations["OPTYPE_DEFINITIONS"] = "%i16 = OpTypeInt 16 1\n"; // Adds 16-bit integer type
6424 specializations["TYPE_CONVERT"] = "%sc_op32 = OpSConvert %i32 %sc_op\n"; // Converts 16-bit integer to 32-bit integer
6427 // Special SPIR-V code for FConvert-case
6428 if (strcmp(cases[caseNdx].caseName, "fconvert") == 0)
6430 features.push_back("shaderFloat64");
6431 fragments["capability"] = "OpCapability Float64\n"; // Adds 64-bit float capability
6432 specializations["OPTYPE_DEFINITIONS"] = "%f64 = OpTypeFloat 64\n"; // Adds 64-bit float type
6433 specializations["TYPE_CONVERT"] = "%sc_op32 = OpConvertFToS %i32 %sc_op\n"; // Converts 64-bit float to 32-bit integer
6436 specializations["SC_DEF0"] = cases[caseNdx].scDefinition0;
6437 specializations["SC_DEF1"] = cases[caseNdx].scDefinition1;
6438 specializations["SC_RESULT_TYPE"] = cases[caseNdx].scResultType;
6439 specializations["SC_OP"] = cases[caseNdx].scOperation;
6440 specializations["GEN_RESULT"] = cases[caseNdx].resultOperation;
6442 fragments["decoration"] = tcu::StringTemplate(decorations1).specialize(specializations);
6443 fragments["pre_main"] = tcu::StringTemplate(typesAndConstants1).specialize(specializations);
6444 fragments["testfun"] = tcu::StringTemplate(function1).specialize(specializations);
6446 specConstants.push_back(cases[caseNdx].scActualValue0);
6447 specConstants.push_back(cases[caseNdx].scActualValue1);
6449 createTestsForAllStages(
6450 cases[caseNdx].caseName, inputColors, cases[caseNdx].expectedColors, fragments, specConstants,
6451 noPushConstants, noResources, noInterfaces, noExtensions, features, VulkanFeatures(), group.get());
6454 const char decorations2[] =
6455 "OpDecorate %sc_0 SpecId 0\n"
6456 "OpDecorate %sc_1 SpecId 1\n"
6457 "OpDecorate %sc_2 SpecId 2\n";
6459 const char typesAndConstants2[] =
6460 "%vec3_0 = OpConstantComposite %v3i32 %c_i32_0 %c_i32_0 %c_i32_0\n"
6461 "%vec3_undef = OpUndef %v3i32\n"
6463 "%sc_0 = OpSpecConstant %i32 0\n"
6464 "%sc_1 = OpSpecConstant %i32 0\n"
6465 "%sc_2 = OpSpecConstant %i32 0\n"
6466 "%sc_vec3_0 = OpSpecConstantOp %v3i32 CompositeInsert %sc_0 %vec3_0 0\n" // (sc_0, 0, 0)
6467 "%sc_vec3_1 = OpSpecConstantOp %v3i32 CompositeInsert %sc_1 %vec3_0 1\n" // (0, sc_1, 0)
6468 "%sc_vec3_2 = OpSpecConstantOp %v3i32 CompositeInsert %sc_2 %vec3_0 2\n" // (0, 0, sc_2)
6469 "%sc_vec3_0_s = OpSpecConstantOp %v3i32 VectorShuffle %sc_vec3_0 %vec3_undef 0 0xFFFFFFFF 2\n" // (sc_0, ???, 0)
6470 "%sc_vec3_1_s = OpSpecConstantOp %v3i32 VectorShuffle %sc_vec3_1 %vec3_undef 0xFFFFFFFF 1 0\n" // (???, sc_1, 0)
6471 "%sc_vec3_2_s = OpSpecConstantOp %v3i32 VectorShuffle %vec3_undef %sc_vec3_2 5 0xFFFFFFFF 5\n" // (sc_2, ???, sc_2)
6472 "%sc_vec3_01 = OpSpecConstantOp %v3i32 VectorShuffle %sc_vec3_0_s %sc_vec3_1_s 1 0 4\n" // (0, sc_0, sc_1)
6473 "%sc_vec3_012 = OpSpecConstantOp %v3i32 VectorShuffle %sc_vec3_01 %sc_vec3_2_s 5 1 2\n" // (sc_2, sc_0, sc_1)
6474 "%sc_ext_0 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 0\n" // sc_2
6475 "%sc_ext_1 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 1\n" // sc_0
6476 "%sc_ext_2 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 2\n" // sc_1
6477 "%sc_sub = OpSpecConstantOp %i32 ISub %sc_ext_0 %sc_ext_1\n" // (sc_2 - sc_0)
6478 "%sc_final = OpSpecConstantOp %i32 IMul %sc_sub %sc_ext_2\n"; // (sc_2 - sc_0) * sc_1
6480 const char function2[] =
6481 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
6482 "%param = OpFunctionParameter %v4f32\n"
6483 "%label = OpLabel\n"
6484 "%result = OpVariable %fp_v4f32 Function\n"
6485 " OpStore %result %param\n"
6486 "%loc = OpAccessChain %fp_f32 %result %sc_final\n"
6487 "%val = OpLoad %f32 %loc\n"
6488 "%add = OpFAdd %f32 %val %c_f32_0_5\n"
6489 " OpStore %loc %add\n"
6490 "%ret = OpLoad %v4f32 %result\n"
6491 " OpReturnValue %ret\n"
6494 map<string, string> fragments;
6495 vector<deInt32> specConstants;
6497 fragments["decoration"] = decorations2;
6498 fragments["pre_main"] = typesAndConstants2;
6499 fragments["testfun"] = function2;
6501 specConstants.push_back(56789);
6502 specConstants.push_back(-2);
6503 specConstants.push_back(56788);
6505 createTestsForAllStages("vector_related", inputColors, outputColors2, fragments, specConstants, group.get());
6507 return group.release();
6510 tcu::TestCaseGroup* createOpPhiTests(tcu::TestContext& testCtx)
6512 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opphi", "Test the OpPhi instruction"));
6513 RGBA inputColors[4];
6514 RGBA outputColors1[4];
6515 RGBA outputColors2[4];
6516 RGBA outputColors3[4];
6517 map<string, string> fragments1;
6518 map<string, string> fragments2;
6519 map<string, string> fragments3;
6521 const char typesAndConstants1[] =
6522 "%c_f32_p2 = OpConstant %f32 0.2\n"
6523 "%c_f32_p4 = OpConstant %f32 0.4\n"
6524 "%c_f32_p5 = OpConstant %f32 0.5\n"
6525 "%c_f32_p8 = OpConstant %f32 0.8\n";
6527 // vec4 test_code(vec4 param) {
6528 // vec4 result = param;
6529 // for (int i = 0; i < 4; ++i) {
6532 // case 0: operand = .2; break;
6533 // case 1: operand = .5; break;
6534 // case 2: operand = .4; break;
6535 // case 3: operand = .0; break;
6536 // default: break; // unreachable
6538 // result[i] += operand;
6542 const char function1[] =
6543 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
6544 "%param1 = OpFunctionParameter %v4f32\n"
6546 "%iptr = OpVariable %fp_i32 Function\n"
6547 "%result = OpVariable %fp_v4f32 Function\n"
6548 " OpStore %iptr %c_i32_0\n"
6549 " OpStore %result %param1\n"
6553 "%ival = OpLoad %i32 %iptr\n"
6554 "%lt_4 = OpSLessThan %bool %ival %c_i32_4\n"
6555 " OpLoopMerge %exit %phi None\n"
6556 " OpBranchConditional %lt_4 %entry %exit\n"
6558 "%entry = OpLabel\n"
6559 "%loc = OpAccessChain %fp_f32 %result %ival\n"
6560 "%val = OpLoad %f32 %loc\n"
6561 " OpSelectionMerge %phi None\n"
6562 " OpSwitch %ival %default 0 %case0 1 %case1 2 %case2 3 %case3\n"
6564 "%case0 = OpLabel\n"
6566 "%case1 = OpLabel\n"
6568 "%case2 = OpLabel\n"
6570 "%case3 = OpLabel\n"
6573 "%default = OpLabel\n"
6577 "%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
6578 "%add = OpFAdd %f32 %val %operand\n"
6579 " OpStore %loc %add\n"
6580 "%ival_next = OpIAdd %i32 %ival %c_i32_1\n"
6581 " OpStore %iptr %ival_next\n"
6585 "%ret = OpLoad %v4f32 %result\n"
6586 " OpReturnValue %ret\n"
6590 fragments1["pre_main"] = typesAndConstants1;
6591 fragments1["testfun"] = function1;
6593 getHalfColorsFullAlpha(inputColors);
6595 outputColors1[0] = RGBA(178, 255, 229, 255);
6596 outputColors1[1] = RGBA(178, 127, 102, 255);
6597 outputColors1[2] = RGBA(51, 255, 102, 255);
6598 outputColors1[3] = RGBA(51, 127, 229, 255);
6600 createTestsForAllStages("out_of_order", inputColors, outputColors1, fragments1, group.get());
6602 const char typesAndConstants2[] =
6603 "%c_f32_p2 = OpConstant %f32 0.2\n";
6605 // Add .4 to the second element of the given parameter.
6606 const char function2[] =
6607 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
6608 "%param = OpFunctionParameter %v4f32\n"
6609 "%entry = OpLabel\n"
6610 "%result = OpVariable %fp_v4f32 Function\n"
6611 " OpStore %result %param\n"
6612 "%loc = OpAccessChain %fp_f32 %result %c_i32_1\n"
6613 "%val = OpLoad %f32 %loc\n"
6617 "%step = OpPhi %i32 %c_i32_0 %entry %step_next %phi\n"
6618 "%accum = OpPhi %f32 %val %entry %accum_next %phi\n"
6619 "%step_next = OpIAdd %i32 %step %c_i32_1\n"
6620 "%accum_next = OpFAdd %f32 %accum %c_f32_p2\n"
6621 "%still_loop = OpSLessThan %bool %step %c_i32_2\n"
6622 " OpLoopMerge %exit %phi None\n"
6623 " OpBranchConditional %still_loop %phi %exit\n"
6626 " OpStore %loc %accum\n"
6627 "%ret = OpLoad %v4f32 %result\n"
6628 " OpReturnValue %ret\n"
6632 fragments2["pre_main"] = typesAndConstants2;
6633 fragments2["testfun"] = function2;
6635 outputColors2[0] = RGBA(127, 229, 127, 255);
6636 outputColors2[1] = RGBA(127, 102, 0, 255);
6637 outputColors2[2] = RGBA(0, 229, 0, 255);
6638 outputColors2[3] = RGBA(0, 102, 127, 255);
6640 createTestsForAllStages("induction", inputColors, outputColors2, fragments2, group.get());
6642 const char typesAndConstants3[] =
6643 "%true = OpConstantTrue %bool\n"
6644 "%false = OpConstantFalse %bool\n"
6645 "%c_f32_p2 = OpConstant %f32 0.2\n";
6647 // Swap the second and the third element of the given parameter.
6648 const char function3[] =
6649 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
6650 "%param = OpFunctionParameter %v4f32\n"
6651 "%entry = OpLabel\n"
6652 "%result = OpVariable %fp_v4f32 Function\n"
6653 " OpStore %result %param\n"
6654 "%a_loc = OpAccessChain %fp_f32 %result %c_i32_1\n"
6655 "%a_init = OpLoad %f32 %a_loc\n"
6656 "%b_loc = OpAccessChain %fp_f32 %result %c_i32_2\n"
6657 "%b_init = OpLoad %f32 %b_loc\n"
6661 "%still_loop = OpPhi %bool %true %entry %false %phi\n"
6662 "%a_next = OpPhi %f32 %a_init %entry %b_next %phi\n"
6663 "%b_next = OpPhi %f32 %b_init %entry %a_next %phi\n"
6664 " OpLoopMerge %exit %phi None\n"
6665 " OpBranchConditional %still_loop %phi %exit\n"
6668 " OpStore %a_loc %a_next\n"
6669 " OpStore %b_loc %b_next\n"
6670 "%ret = OpLoad %v4f32 %result\n"
6671 " OpReturnValue %ret\n"
6675 fragments3["pre_main"] = typesAndConstants3;
6676 fragments3["testfun"] = function3;
6678 outputColors3[0] = RGBA(127, 127, 127, 255);
6679 outputColors3[1] = RGBA(127, 0, 0, 255);
6680 outputColors3[2] = RGBA(0, 0, 127, 255);
6681 outputColors3[3] = RGBA(0, 127, 0, 255);
6683 createTestsForAllStages("swap", inputColors, outputColors3, fragments3, group.get());
6685 return group.release();
6688 tcu::TestCaseGroup* createNoContractionTests(tcu::TestContext& testCtx)
6690 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "nocontraction", "Test the NoContraction decoration"));
6691 RGBA inputColors[4];
6692 RGBA outputColors[4];
6694 // With NoContraction, (1 + 2^-23) * (1 - 2^-23) - 1 should be conducted as a multiplication and an addition separately.
6695 // For the multiplication, the result is 1 - 2^-46, which is out of the precision range for 32-bit float. (32-bit float
6696 // only have 23-bit fraction.) So it will be rounded to 1. Or 0x1.fffffc. Then the final result is 0 or -0x1p-24.
6697 // On the contrary, the result will be 2^-46, which is a normalized number perfectly representable as 32-bit float.
6698 const char constantsAndTypes[] =
6699 "%c_vec4_0 = OpConstantComposite %v4f32 %c_f32_0 %c_f32_0 %c_f32_0 %c_f32_1\n"
6700 "%c_vec4_1 = OpConstantComposite %v4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_1\n"
6701 "%c_f32_1pl2_23 = OpConstant %f32 0x1.000002p+0\n" // 1 + 2^-23
6702 "%c_f32_1mi2_23 = OpConstant %f32 0x1.fffffcp-1\n" // 1 - 2^-23
6703 "%c_f32_n1pn24 = OpConstant %f32 -0x1p-24\n";
6705 const char function[] =
6706 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
6707 "%param = OpFunctionParameter %v4f32\n"
6708 "%label = OpLabel\n"
6709 "%var1 = OpVariable %fp_f32 Function %c_f32_1pl2_23\n"
6710 "%var2 = OpVariable %fp_f32 Function\n"
6711 "%red = OpCompositeExtract %f32 %param 0\n"
6712 "%plus_red = OpFAdd %f32 %c_f32_1mi2_23 %red\n"
6713 " OpStore %var2 %plus_red\n"
6714 "%val1 = OpLoad %f32 %var1\n"
6715 "%val2 = OpLoad %f32 %var2\n"
6716 "%mul = OpFMul %f32 %val1 %val2\n"
6717 "%add = OpFAdd %f32 %mul %c_f32_n1\n"
6718 "%is0 = OpFOrdEqual %bool %add %c_f32_0\n"
6719 "%isn1n24 = OpFOrdEqual %bool %add %c_f32_n1pn24\n"
6720 "%success = OpLogicalOr %bool %is0 %isn1n24\n"
6721 "%v4success = OpCompositeConstruct %v4bool %success %success %success %success\n"
6722 "%ret = OpSelect %v4f32 %v4success %c_vec4_0 %c_vec4_1\n"
6723 " OpReturnValue %ret\n"
6726 struct CaseNameDecoration
6733 CaseNameDecoration tests[] = {
6734 {"multiplication", "OpDecorate %mul NoContraction"},
6735 {"addition", "OpDecorate %add NoContraction"},
6736 {"both", "OpDecorate %mul NoContraction\nOpDecorate %add NoContraction"},
6739 getHalfColorsFullAlpha(inputColors);
6741 for (deUint8 idx = 0; idx < 4; ++idx)
6743 inputColors[idx].setRed(0);
6744 outputColors[idx] = RGBA(0, 0, 0, 255);
6747 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(CaseNameDecoration); ++testNdx)
6749 map<string, string> fragments;
6751 fragments["decoration"] = tests[testNdx].decoration;
6752 fragments["pre_main"] = constantsAndTypes;
6753 fragments["testfun"] = function;
6755 createTestsForAllStages(tests[testNdx].name, inputColors, outputColors, fragments, group.get());
6758 return group.release();
6761 tcu::TestCaseGroup* createMemoryAccessTests(tcu::TestContext& testCtx)
6763 de::MovePtr<tcu::TestCaseGroup> memoryAccessTests (new tcu::TestCaseGroup(testCtx, "opmemoryaccess", "Memory Semantics"));
6766 const char constantsAndTypes[] =
6767 "%c_a2f32_1 = OpConstantComposite %a2f32 %c_f32_1 %c_f32_1\n"
6768 "%fp_a2f32 = OpTypePointer Function %a2f32\n"
6769 "%stype = OpTypeStruct %v4f32 %a2f32 %f32\n"
6770 "%fp_stype = OpTypePointer Function %stype\n";
6772 const char function[] =
6773 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
6774 "%param1 = OpFunctionParameter %v4f32\n"
6776 "%v1 = OpVariable %fp_v4f32 Function\n"
6777 "%v2 = OpVariable %fp_a2f32 Function\n"
6778 "%v3 = OpVariable %fp_f32 Function\n"
6779 "%v = OpVariable %fp_stype Function\n"
6780 "%vv = OpVariable %fp_stype Function\n"
6781 "%vvv = OpVariable %fp_f32 Function\n"
6783 " OpStore %v1 %c_v4f32_1_1_1_1\n"
6784 " OpStore %v2 %c_a2f32_1\n"
6785 " OpStore %v3 %c_f32_1\n"
6787 "%p_v4f32 = OpAccessChain %fp_v4f32 %v %c_u32_0\n"
6788 "%p_a2f32 = OpAccessChain %fp_a2f32 %v %c_u32_1\n"
6789 "%p_f32 = OpAccessChain %fp_f32 %v %c_u32_2\n"
6790 "%v1_v = OpLoad %v4f32 %v1 ${access_type}\n"
6791 "%v2_v = OpLoad %a2f32 %v2 ${access_type}\n"
6792 "%v3_v = OpLoad %f32 %v3 ${access_type}\n"
6794 " OpStore %p_v4f32 %v1_v ${access_type}\n"
6795 " OpStore %p_a2f32 %v2_v ${access_type}\n"
6796 " OpStore %p_f32 %v3_v ${access_type}\n"
6798 " OpCopyMemory %vv %v ${access_type}\n"
6799 " OpCopyMemory %vvv %p_f32 ${access_type}\n"
6801 "%p_f32_2 = OpAccessChain %fp_f32 %vv %c_u32_2\n"
6802 "%v_f32_2 = OpLoad %f32 %p_f32_2\n"
6803 "%v_f32_3 = OpLoad %f32 %vvv\n"
6805 "%ret1 = OpVectorTimesScalar %v4f32 %param1 %v_f32_2\n"
6806 "%ret2 = OpVectorTimesScalar %v4f32 %ret1 %v_f32_3\n"
6807 " OpReturnValue %ret2\n"
6810 struct NameMemoryAccess
6817 NameMemoryAccess tests[] =
6820 { "volatile", "Volatile" },
6821 { "aligned", "Aligned 1" },
6822 { "volatile_aligned", "Volatile|Aligned 1" },
6823 { "nontemporal_aligned", "Nontemporal|Aligned 1" },
6824 { "volatile_nontemporal", "Volatile|Nontemporal" },
6825 { "volatile_nontermporal_aligned", "Volatile|Nontemporal|Aligned 1" },
6828 getHalfColorsFullAlpha(colors);
6830 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameMemoryAccess); ++testNdx)
6832 map<string, string> fragments;
6833 map<string, string> memoryAccess;
6834 memoryAccess["access_type"] = tests[testNdx].accessType;
6836 fragments["pre_main"] = constantsAndTypes;
6837 fragments["testfun"] = tcu::StringTemplate(function).specialize(memoryAccess);
6838 createTestsForAllStages(tests[testNdx].name, colors, colors, fragments, memoryAccessTests.get());
6840 return memoryAccessTests.release();
6842 tcu::TestCaseGroup* createOpUndefTests(tcu::TestContext& testCtx)
6844 de::MovePtr<tcu::TestCaseGroup> opUndefTests (new tcu::TestCaseGroup(testCtx, "opundef", "Test OpUndef"));
6845 RGBA defaultColors[4];
6846 map<string, string> fragments;
6847 getDefaultColors(defaultColors);
6849 // First, simple cases that don't do anything with the OpUndef result.
6850 struct NameCodePair { string name, decl, type; };
6851 const NameCodePair tests[] =
6853 {"bool", "", "%bool"},
6854 {"vec2uint32", "", "%v2u32"},
6855 {"image", "%type = OpTypeImage %f32 2D 0 0 0 1 Unknown", "%type"},
6856 {"sampler", "%type = OpTypeSampler", "%type"},
6857 {"sampledimage", "%img = OpTypeImage %f32 2D 0 0 0 1 Unknown\n" "%type = OpTypeSampledImage %img", "%type"},
6858 {"pointer", "", "%fp_i32"},
6859 {"runtimearray", "%type = OpTypeRuntimeArray %f32", "%type"},
6860 {"array", "%c_u32_100 = OpConstant %u32 100\n" "%type = OpTypeArray %i32 %c_u32_100", "%type"},
6861 {"struct", "%type = OpTypeStruct %f32 %i32 %u32", "%type"}};
6862 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameCodePair); ++testNdx)
6864 fragments["undef_type"] = tests[testNdx].type;
6865 fragments["testfun"] = StringTemplate(
6866 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
6867 "%param1 = OpFunctionParameter %v4f32\n"
6868 "%label_testfun = OpLabel\n"
6869 "%undef = OpUndef ${undef_type}\n"
6870 "OpReturnValue %param1\n"
6871 "OpFunctionEnd\n").specialize(fragments);
6872 fragments["pre_main"] = tests[testNdx].decl;
6873 createTestsForAllStages(tests[testNdx].name, defaultColors, defaultColors, fragments, opUndefTests.get());
6877 fragments["testfun"] =
6878 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
6879 "%param1 = OpFunctionParameter %v4f32\n"
6880 "%label_testfun = OpLabel\n"
6881 "%undef = OpUndef %f32\n"
6882 "%zero = OpFMul %f32 %undef %c_f32_0\n"
6883 "%is_nan = OpIsNan %bool %zero\n" //OpUndef may result in NaN which may turn %zero into Nan.
6884 "%actually_zero = OpSelect %f32 %is_nan %c_f32_0 %zero\n"
6885 "%a = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
6886 "%b = OpFAdd %f32 %a %actually_zero\n"
6887 "%ret = OpVectorInsertDynamic %v4f32 %param1 %b %c_i32_0\n"
6888 "OpReturnValue %ret\n"
6891 createTestsForAllStages("float32", defaultColors, defaultColors, fragments, opUndefTests.get());
6893 fragments["testfun"] =
6894 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
6895 "%param1 = OpFunctionParameter %v4f32\n"
6896 "%label_testfun = OpLabel\n"
6897 "%undef = OpUndef %i32\n"
6898 "%zero = OpIMul %i32 %undef %c_i32_0\n"
6899 "%a = OpVectorExtractDynamic %f32 %param1 %zero\n"
6900 "%ret = OpVectorInsertDynamic %v4f32 %param1 %a %c_i32_0\n"
6901 "OpReturnValue %ret\n"
6904 createTestsForAllStages("sint32", defaultColors, defaultColors, fragments, opUndefTests.get());
6906 fragments["testfun"] =
6907 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
6908 "%param1 = OpFunctionParameter %v4f32\n"
6909 "%label_testfun = OpLabel\n"
6910 "%undef = OpUndef %u32\n"
6911 "%zero = OpIMul %u32 %undef %c_i32_0\n"
6912 "%a = OpVectorExtractDynamic %f32 %param1 %zero\n"
6913 "%ret = OpVectorInsertDynamic %v4f32 %param1 %a %c_i32_0\n"
6914 "OpReturnValue %ret\n"
6917 createTestsForAllStages("uint32", defaultColors, defaultColors, fragments, opUndefTests.get());
6919 fragments["testfun"] =
6920 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
6921 "%param1 = OpFunctionParameter %v4f32\n"
6922 "%label_testfun = OpLabel\n"
6923 "%undef = OpUndef %v4f32\n"
6924 "%vzero = OpVectorTimesScalar %v4f32 %undef %c_f32_0\n"
6925 "%zero_0 = OpVectorExtractDynamic %f32 %vzero %c_i32_0\n"
6926 "%zero_1 = OpVectorExtractDynamic %f32 %vzero %c_i32_1\n"
6927 "%zero_2 = OpVectorExtractDynamic %f32 %vzero %c_i32_2\n"
6928 "%zero_3 = OpVectorExtractDynamic %f32 %vzero %c_i32_3\n"
6929 "%is_nan_0 = OpIsNan %bool %zero_0\n"
6930 "%is_nan_1 = OpIsNan %bool %zero_1\n"
6931 "%is_nan_2 = OpIsNan %bool %zero_2\n"
6932 "%is_nan_3 = OpIsNan %bool %zero_3\n"
6933 "%actually_zero_0 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_0\n"
6934 "%actually_zero_1 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_1\n"
6935 "%actually_zero_2 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_2\n"
6936 "%actually_zero_3 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_3\n"
6937 "%param1_0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
6938 "%param1_1 = OpVectorExtractDynamic %f32 %param1 %c_i32_1\n"
6939 "%param1_2 = OpVectorExtractDynamic %f32 %param1 %c_i32_2\n"
6940 "%param1_3 = OpVectorExtractDynamic %f32 %param1 %c_i32_3\n"
6941 "%sum_0 = OpFAdd %f32 %param1_0 %actually_zero_0\n"
6942 "%sum_1 = OpFAdd %f32 %param1_1 %actually_zero_1\n"
6943 "%sum_2 = OpFAdd %f32 %param1_2 %actually_zero_2\n"
6944 "%sum_3 = OpFAdd %f32 %param1_3 %actually_zero_3\n"
6945 "%ret3 = OpVectorInsertDynamic %v4f32 %param1 %sum_3 %c_i32_3\n"
6946 "%ret2 = OpVectorInsertDynamic %v4f32 %ret3 %sum_2 %c_i32_2\n"
6947 "%ret1 = OpVectorInsertDynamic %v4f32 %ret2 %sum_1 %c_i32_1\n"
6948 "%ret = OpVectorInsertDynamic %v4f32 %ret1 %sum_0 %c_i32_0\n"
6949 "OpReturnValue %ret\n"
6952 createTestsForAllStages("vec4float32", defaultColors, defaultColors, fragments, opUndefTests.get());
6954 fragments["pre_main"] =
6955 "%m2x2f32 = OpTypeMatrix %v2f32 2\n";
6956 fragments["testfun"] =
6957 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
6958 "%param1 = OpFunctionParameter %v4f32\n"
6959 "%label_testfun = OpLabel\n"
6960 "%undef = OpUndef %m2x2f32\n"
6961 "%mzero = OpMatrixTimesScalar %m2x2f32 %undef %c_f32_0\n"
6962 "%zero_0 = OpCompositeExtract %f32 %mzero 0 0\n"
6963 "%zero_1 = OpCompositeExtract %f32 %mzero 0 1\n"
6964 "%zero_2 = OpCompositeExtract %f32 %mzero 1 0\n"
6965 "%zero_3 = OpCompositeExtract %f32 %mzero 1 1\n"
6966 "%is_nan_0 = OpIsNan %bool %zero_0\n"
6967 "%is_nan_1 = OpIsNan %bool %zero_1\n"
6968 "%is_nan_2 = OpIsNan %bool %zero_2\n"
6969 "%is_nan_3 = OpIsNan %bool %zero_3\n"
6970 "%actually_zero_0 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_0\n"
6971 "%actually_zero_1 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_1\n"
6972 "%actually_zero_2 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_2\n"
6973 "%actually_zero_3 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_3\n"
6974 "%param1_0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
6975 "%param1_1 = OpVectorExtractDynamic %f32 %param1 %c_i32_1\n"
6976 "%param1_2 = OpVectorExtractDynamic %f32 %param1 %c_i32_2\n"
6977 "%param1_3 = OpVectorExtractDynamic %f32 %param1 %c_i32_3\n"
6978 "%sum_0 = OpFAdd %f32 %param1_0 %actually_zero_0\n"
6979 "%sum_1 = OpFAdd %f32 %param1_1 %actually_zero_1\n"
6980 "%sum_2 = OpFAdd %f32 %param1_2 %actually_zero_2\n"
6981 "%sum_3 = OpFAdd %f32 %param1_3 %actually_zero_3\n"
6982 "%ret3 = OpVectorInsertDynamic %v4f32 %param1 %sum_3 %c_i32_3\n"
6983 "%ret2 = OpVectorInsertDynamic %v4f32 %ret3 %sum_2 %c_i32_2\n"
6984 "%ret1 = OpVectorInsertDynamic %v4f32 %ret2 %sum_1 %c_i32_1\n"
6985 "%ret = OpVectorInsertDynamic %v4f32 %ret1 %sum_0 %c_i32_0\n"
6986 "OpReturnValue %ret\n"
6989 createTestsForAllStages("matrix", defaultColors, defaultColors, fragments, opUndefTests.get());
6991 return opUndefTests.release();
6994 void createOpQuantizeSingleOptionTests(tcu::TestCaseGroup* testCtx)
6996 const RGBA inputColors[4] =
6999 RGBA(0, 0, 255, 255),
7000 RGBA(0, 255, 0, 255),
7001 RGBA(0, 255, 255, 255)
7004 const RGBA expectedColors[4] =
7006 RGBA(255, 0, 0, 255),
7007 RGBA(255, 0, 0, 255),
7008 RGBA(255, 0, 0, 255),
7009 RGBA(255, 0, 0, 255)
7012 const struct SingleFP16Possibility
7015 const char* constant; // Value to assign to %test_constant.
7017 const char* condition; // Must assign to %cond an expression that evaluates to true after %c = OpQuantizeToF16(%test_constant + 0).
7023 -constructNormalizedFloat(1, 0x300000),
7024 "%cond = OpFOrdEqual %bool %c %test_constant\n"
7029 constructNormalizedFloat(7, 0x000000),
7030 "%cond = OpFOrdEqual %bool %c %test_constant\n"
7032 // SPIR-V requires that OpQuantizeToF16 flushes
7033 // any numbers that would end up denormalized in F16 to zero.
7037 std::ldexp(1.5f, -140),
7038 "%cond = OpFOrdEqual %bool %c %c_f32_0\n"
7043 -std::ldexp(1.5f, -140),
7044 "%cond = OpFOrdEqual %bool %c %c_f32_0\n"
7049 std::ldexp(1.0f, -16),
7050 "%cond = OpFOrdEqual %bool %c %c_f32_0\n"
7051 }, // too small positive
7053 "negative_too_small",
7055 -std::ldexp(1.0f, -32),
7056 "%cond = OpFOrdEqual %bool %c %c_f32_0\n"
7057 }, // too small negative
7061 -std::ldexp(1.0f, 128),
7063 "%gz = OpFOrdLessThan %bool %c %c_f32_0\n"
7064 "%inf = OpIsInf %bool %c\n"
7065 "%cond = OpLogicalAnd %bool %gz %inf\n"
7070 std::ldexp(1.0f, 128),
7072 "%gz = OpFOrdGreaterThan %bool %c %c_f32_0\n"
7073 "%inf = OpIsInf %bool %c\n"
7074 "%cond = OpLogicalAnd %bool %gz %inf\n"
7077 "round_to_negative_inf",
7079 -std::ldexp(1.0f, 32),
7081 "%gz = OpFOrdLessThan %bool %c %c_f32_0\n"
7082 "%inf = OpIsInf %bool %c\n"
7083 "%cond = OpLogicalAnd %bool %gz %inf\n"
7088 std::ldexp(1.0f, 16),
7090 "%gz = OpFOrdGreaterThan %bool %c %c_f32_0\n"
7091 "%inf = OpIsInf %bool %c\n"
7092 "%cond = OpLogicalAnd %bool %gz %inf\n"
7097 std::numeric_limits<float>::quiet_NaN(),
7099 // Test for any NaN value, as NaNs are not preserved
7100 "%direct_quant = OpQuantizeToF16 %f32 %test_constant\n"
7101 "%cond = OpIsNan %bool %direct_quant\n"
7106 std::numeric_limits<float>::quiet_NaN(),
7108 // Test for any NaN value, as NaNs are not preserved
7109 "%direct_quant = OpQuantizeToF16 %f32 %test_constant\n"
7110 "%cond = OpIsNan %bool %direct_quant\n"
7113 const char* constants =
7114 "%test_constant = OpConstant %f32 "; // The value will be test.constant.
7116 StringTemplate function (
7117 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
7118 "%param1 = OpFunctionParameter %v4f32\n"
7119 "%label_testfun = OpLabel\n"
7120 "%a = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
7121 "%b = OpFAdd %f32 %test_constant %a\n"
7122 "%c = OpQuantizeToF16 %f32 %b\n"
7124 "%v4cond = OpCompositeConstruct %v4bool %cond %cond %cond %cond\n"
7125 "%retval = OpSelect %v4f32 %v4cond %c_v4f32_1_0_0_1 %param1\n"
7126 " OpReturnValue %retval\n"
7130 const char* specDecorations = "OpDecorate %test_constant SpecId 0\n";
7131 const char* specConstants =
7132 "%test_constant = OpSpecConstant %f32 0.\n"
7133 "%c = OpSpecConstantOp %f32 QuantizeToF16 %test_constant\n";
7135 StringTemplate specConstantFunction(
7136 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
7137 "%param1 = OpFunctionParameter %v4f32\n"
7138 "%label_testfun = OpLabel\n"
7140 "%v4cond = OpCompositeConstruct %v4bool %cond %cond %cond %cond\n"
7141 "%retval = OpSelect %v4f32 %v4cond %c_v4f32_1_0_0_1 %param1\n"
7142 " OpReturnValue %retval\n"
7146 for (size_t idx = 0; idx < (sizeof(tests)/sizeof(tests[0])); ++idx)
7148 map<string, string> codeSpecialization;
7149 map<string, string> fragments;
7150 codeSpecialization["condition"] = tests[idx].condition;
7151 fragments["testfun"] = function.specialize(codeSpecialization);
7152 fragments["pre_main"] = string(constants) + tests[idx].constant + "\n";
7153 createTestsForAllStages(tests[idx].name, inputColors, expectedColors, fragments, testCtx);
7156 for (size_t idx = 0; idx < (sizeof(tests)/sizeof(tests[0])); ++idx)
7158 map<string, string> codeSpecialization;
7159 map<string, string> fragments;
7160 vector<deInt32> passConstants;
7161 deInt32 specConstant;
7163 codeSpecialization["condition"] = tests[idx].condition;
7164 fragments["testfun"] = specConstantFunction.specialize(codeSpecialization);
7165 fragments["decoration"] = specDecorations;
7166 fragments["pre_main"] = specConstants;
7168 memcpy(&specConstant, &tests[idx].valueAsFloat, sizeof(float));
7169 passConstants.push_back(specConstant);
7171 createTestsForAllStages(string("spec_const_") + tests[idx].name, inputColors, expectedColors, fragments, passConstants, testCtx);
7175 void createOpQuantizeTwoPossibilityTests(tcu::TestCaseGroup* testCtx)
7177 RGBA inputColors[4] = {
7179 RGBA(0, 0, 255, 255),
7180 RGBA(0, 255, 0, 255),
7181 RGBA(0, 255, 255, 255)
7184 RGBA expectedColors[4] =
7186 RGBA(255, 0, 0, 255),
7187 RGBA(255, 0, 0, 255),
7188 RGBA(255, 0, 0, 255),
7189 RGBA(255, 0, 0, 255)
7192 struct DualFP16Possibility
7197 const char* possibleOutput1;
7198 const char* possibleOutput2;
7201 "positive_round_up_or_round_down",
7203 constructNormalizedFloat(8, 0x300300),
7208 "negative_round_up_or_round_down",
7210 -constructNormalizedFloat(-7, 0x600800),
7217 constructNormalizedFloat(2, 0x01e000),
7222 "carry_to_exponent",
7224 constructNormalizedFloat(1, 0xffe000),
7229 StringTemplate constants (
7230 "%input_const = OpConstant %f32 ${input}\n"
7231 "%possible_solution1 = OpConstant %f32 ${output1}\n"
7232 "%possible_solution2 = OpConstant %f32 ${output2}\n"
7235 StringTemplate specConstants (
7236 "%input_const = OpSpecConstant %f32 0.\n"
7237 "%possible_solution1 = OpConstant %f32 ${output1}\n"
7238 "%possible_solution2 = OpConstant %f32 ${output2}\n"
7241 const char* specDecorations = "OpDecorate %input_const SpecId 0\n";
7243 const char* function =
7244 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
7245 "%param1 = OpFunctionParameter %v4f32\n"
7246 "%label_testfun = OpLabel\n"
7247 "%a = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
7248 // For the purposes of this test we assume that 0.f will always get
7249 // faithfully passed through the pipeline stages.
7250 "%b = OpFAdd %f32 %input_const %a\n"
7251 "%c = OpQuantizeToF16 %f32 %b\n"
7252 "%eq_1 = OpFOrdEqual %bool %c %possible_solution1\n"
7253 "%eq_2 = OpFOrdEqual %bool %c %possible_solution2\n"
7254 "%cond = OpLogicalOr %bool %eq_1 %eq_2\n"
7255 "%v4cond = OpCompositeConstruct %v4bool %cond %cond %cond %cond\n"
7256 "%retval = OpSelect %v4f32 %v4cond %c_v4f32_1_0_0_1 %param1"
7257 " OpReturnValue %retval\n"
7260 for(size_t idx = 0; idx < (sizeof(tests)/sizeof(tests[0])); ++idx) {
7261 map<string, string> fragments;
7262 map<string, string> constantSpecialization;
7264 constantSpecialization["input"] = tests[idx].input;
7265 constantSpecialization["output1"] = tests[idx].possibleOutput1;
7266 constantSpecialization["output2"] = tests[idx].possibleOutput2;
7267 fragments["testfun"] = function;
7268 fragments["pre_main"] = constants.specialize(constantSpecialization);
7269 createTestsForAllStages(tests[idx].name, inputColors, expectedColors, fragments, testCtx);
7272 for(size_t idx = 0; idx < (sizeof(tests)/sizeof(tests[0])); ++idx) {
7273 map<string, string> fragments;
7274 map<string, string> constantSpecialization;
7275 vector<deInt32> passConstants;
7276 deInt32 specConstant;
7278 constantSpecialization["output1"] = tests[idx].possibleOutput1;
7279 constantSpecialization["output2"] = tests[idx].possibleOutput2;
7280 fragments["testfun"] = function;
7281 fragments["decoration"] = specDecorations;
7282 fragments["pre_main"] = specConstants.specialize(constantSpecialization);
7284 memcpy(&specConstant, &tests[idx].inputAsFloat, sizeof(float));
7285 passConstants.push_back(specConstant);
7287 createTestsForAllStages(string("spec_const_") + tests[idx].name, inputColors, expectedColors, fragments, passConstants, testCtx);
7291 tcu::TestCaseGroup* createOpQuantizeTests(tcu::TestContext& testCtx)
7293 de::MovePtr<tcu::TestCaseGroup> opQuantizeTests (new tcu::TestCaseGroup(testCtx, "opquantize", "Test OpQuantizeToF16"));
7294 createOpQuantizeSingleOptionTests(opQuantizeTests.get());
7295 createOpQuantizeTwoPossibilityTests(opQuantizeTests.get());
7296 return opQuantizeTests.release();
7299 struct ShaderPermutation
7301 deUint8 vertexPermutation;
7302 deUint8 geometryPermutation;
7303 deUint8 tesscPermutation;
7304 deUint8 tessePermutation;
7305 deUint8 fragmentPermutation;
7308 ShaderPermutation getShaderPermutation(deUint8 inputValue)
7310 ShaderPermutation permutation =
7312 static_cast<deUint8>(inputValue & 0x10? 1u: 0u),
7313 static_cast<deUint8>(inputValue & 0x08? 1u: 0u),
7314 static_cast<deUint8>(inputValue & 0x04? 1u: 0u),
7315 static_cast<deUint8>(inputValue & 0x02? 1u: 0u),
7316 static_cast<deUint8>(inputValue & 0x01? 1u: 0u)
7321 tcu::TestCaseGroup* createModuleTests(tcu::TestContext& testCtx)
7323 RGBA defaultColors[4];
7324 RGBA invertedColors[4];
7325 de::MovePtr<tcu::TestCaseGroup> moduleTests (new tcu::TestCaseGroup(testCtx, "module", "Multiple entry points into shaders"));
7327 const ShaderElement combinedPipeline[] =
7329 ShaderElement("module", "main", VK_SHADER_STAGE_VERTEX_BIT),
7330 ShaderElement("module", "main", VK_SHADER_STAGE_GEOMETRY_BIT),
7331 ShaderElement("module", "main", VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT),
7332 ShaderElement("module", "main", VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT),
7333 ShaderElement("module", "main", VK_SHADER_STAGE_FRAGMENT_BIT)
7336 getDefaultColors(defaultColors);
7337 getInvertedDefaultColors(invertedColors);
7338 addFunctionCaseWithPrograms<InstanceContext>(
7339 moduleTests.get(), "same_module", "", createCombinedModule, runAndVerifyDefaultPipeline,
7340 createInstanceContext(combinedPipeline, map<string, string>()));
7342 const char* numbers[] =
7347 for (deInt8 idx = 0; idx < 32; ++idx)
7349 ShaderPermutation permutation = getShaderPermutation(idx);
7350 string name = string("vert") + numbers[permutation.vertexPermutation] + "_geom" + numbers[permutation.geometryPermutation] + "_tessc" + numbers[permutation.tesscPermutation] + "_tesse" + numbers[permutation.tessePermutation] + "_frag" + numbers[permutation.fragmentPermutation];
7351 const ShaderElement pipeline[] =
7353 ShaderElement("vert", string("vert") + numbers[permutation.vertexPermutation], VK_SHADER_STAGE_VERTEX_BIT),
7354 ShaderElement("geom", string("geom") + numbers[permutation.geometryPermutation], VK_SHADER_STAGE_GEOMETRY_BIT),
7355 ShaderElement("tessc", string("tessc") + numbers[permutation.tesscPermutation], VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT),
7356 ShaderElement("tesse", string("tesse") + numbers[permutation.tessePermutation], VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT),
7357 ShaderElement("frag", string("frag") + numbers[permutation.fragmentPermutation], VK_SHADER_STAGE_FRAGMENT_BIT)
7360 // If there are an even number of swaps, then it should be no-op.
7361 // If there are an odd number, the color should be flipped.
7362 if ((permutation.vertexPermutation + permutation.geometryPermutation + permutation.tesscPermutation + permutation.tessePermutation + permutation.fragmentPermutation) % 2 == 0)
7364 addFunctionCaseWithPrograms<InstanceContext>(
7365 moduleTests.get(), name, "", createMultipleEntries, runAndVerifyDefaultPipeline,
7366 createInstanceContext(pipeline, defaultColors, defaultColors, map<string, string>()));
7370 addFunctionCaseWithPrograms<InstanceContext>(
7371 moduleTests.get(), name, "", createMultipleEntries, runAndVerifyDefaultPipeline,
7372 createInstanceContext(pipeline, defaultColors, invertedColors, map<string, string>()));
7375 return moduleTests.release();
7378 tcu::TestCaseGroup* createLoopTests(tcu::TestContext& testCtx)
7380 de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, "loop", "Looping control flow"));
7381 RGBA defaultColors[4];
7382 getDefaultColors(defaultColors);
7383 map<string, string> fragments;
7384 fragments["pre_main"] =
7385 "%c_f32_5 = OpConstant %f32 5.\n";
7387 // A loop with a single block. The Continue Target is the loop block
7388 // itself. In SPIR-V terms, the "loop construct" contains no blocks at all
7389 // -- the "continue construct" forms the entire loop.
7390 fragments["testfun"] =
7391 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
7392 "%param1 = OpFunctionParameter %v4f32\n"
7394 "%entry = OpLabel\n"
7395 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
7398 ";adds and subtracts 1.0 to %val in alternate iterations\n"
7400 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %loop\n"
7401 "%delta = OpPhi %f32 %c_f32_1 %entry %minus_delta %loop\n"
7402 "%val1 = OpPhi %f32 %val0 %entry %val %loop\n"
7403 "%val = OpFAdd %f32 %val1 %delta\n"
7404 "%minus_delta = OpFSub %f32 %c_f32_0 %delta\n"
7405 "%count__ = OpISub %i32 %count %c_i32_1\n"
7406 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
7407 "OpLoopMerge %exit %loop None\n"
7408 "OpBranchConditional %again %loop %exit\n"
7411 "%result = OpVectorInsertDynamic %v4f32 %param1 %val %c_i32_0\n"
7412 "OpReturnValue %result\n"
7416 createTestsForAllStages("single_block", defaultColors, defaultColors, fragments, testGroup.get());
7418 // Body comprised of multiple basic blocks.
7419 const StringTemplate multiBlock(
7420 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
7421 "%param1 = OpFunctionParameter %v4f32\n"
7423 "%entry = OpLabel\n"
7424 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
7427 ";adds and subtracts 1.0 to %val in alternate iterations\n"
7429 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %gather\n"
7430 "%delta = OpPhi %f32 %c_f32_1 %entry %delta_next %gather\n"
7431 "%val1 = OpPhi %f32 %val0 %entry %val %gather\n"
7432 // There are several possibilities for the Continue Target below. Each
7433 // will be specialized into a separate test case.
7434 "OpLoopMerge %exit ${continue_target} None\n"
7438 ";delta_next = (delta > 0) ? -1 : 1;\n"
7439 "%gt0 = OpFOrdGreaterThan %bool %delta %c_f32_0\n"
7440 "OpSelectionMerge %gather DontFlatten\n"
7441 "OpBranchConditional %gt0 %even %odd ;tells us if %count is even or odd\n"
7444 "OpBranch %gather\n"
7447 "OpBranch %gather\n"
7449 "%gather = OpLabel\n"
7450 "%delta_next = OpPhi %f32 %c_f32_n1 %even %c_f32_1 %odd\n"
7451 "%val = OpFAdd %f32 %val1 %delta\n"
7452 "%count__ = OpISub %i32 %count %c_i32_1\n"
7453 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
7454 "OpBranchConditional %again %loop %exit\n"
7457 "%result = OpVectorInsertDynamic %v4f32 %param1 %val %c_i32_0\n"
7458 "OpReturnValue %result\n"
7462 map<string, string> continue_target;
7464 // The Continue Target is the loop block itself.
7465 continue_target["continue_target"] = "%loop";
7466 fragments["testfun"] = multiBlock.specialize(continue_target);
7467 createTestsForAllStages("multi_block_continue_construct", defaultColors, defaultColors, fragments, testGroup.get());
7469 // The Continue Target is at the end of the loop.
7470 continue_target["continue_target"] = "%gather";
7471 fragments["testfun"] = multiBlock.specialize(continue_target);
7472 createTestsForAllStages("multi_block_loop_construct", defaultColors, defaultColors, fragments, testGroup.get());
7474 // A loop with continue statement.
7475 fragments["testfun"] =
7476 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
7477 "%param1 = OpFunctionParameter %v4f32\n"
7479 "%entry = OpLabel\n"
7480 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
7483 ";adds 4, 3, and 1 to %val0 (skips 2)\n"
7485 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %continue\n"
7486 "%val1 = OpPhi %f32 %val0 %entry %val %continue\n"
7487 "OpLoopMerge %exit %continue None\n"
7491 ";skip if %count==2\n"
7492 "%eq2 = OpIEqual %bool %count %c_i32_2\n"
7493 "OpSelectionMerge %continue DontFlatten\n"
7494 "OpBranchConditional %eq2 %continue %body\n"
7497 "%fcount = OpConvertSToF %f32 %count\n"
7498 "%val2 = OpFAdd %f32 %val1 %fcount\n"
7499 "OpBranch %continue\n"
7501 "%continue = OpLabel\n"
7502 "%val = OpPhi %f32 %val2 %body %val1 %if\n"
7503 "%count__ = OpISub %i32 %count %c_i32_1\n"
7504 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
7505 "OpBranchConditional %again %loop %exit\n"
7508 "%same = OpFSub %f32 %val %c_f32_8\n"
7509 "%result = OpVectorInsertDynamic %v4f32 %param1 %same %c_i32_0\n"
7510 "OpReturnValue %result\n"
7512 createTestsForAllStages("continue", defaultColors, defaultColors, fragments, testGroup.get());
7514 // A loop with break.
7515 fragments["testfun"] =
7516 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
7517 "%param1 = OpFunctionParameter %v4f32\n"
7519 "%entry = OpLabel\n"
7520 ";param1 components are between 0 and 1, so dot product is 4 or less\n"
7521 "%dot = OpDot %f32 %param1 %param1\n"
7522 "%div = OpFDiv %f32 %dot %c_f32_5\n"
7523 "%zero = OpConvertFToU %u32 %div\n"
7524 "%two = OpIAdd %i32 %zero %c_i32_2\n"
7525 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
7528 ";adds 4 and 3 to %val0 (exits early)\n"
7530 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %continue\n"
7531 "%val1 = OpPhi %f32 %val0 %entry %val2 %continue\n"
7532 "OpLoopMerge %exit %continue None\n"
7536 ";end loop if %count==%two\n"
7537 "%above2 = OpSGreaterThan %bool %count %two\n"
7538 "OpSelectionMerge %continue DontFlatten\n"
7539 "OpBranchConditional %above2 %body %exit\n"
7542 "%fcount = OpConvertSToF %f32 %count\n"
7543 "%val2 = OpFAdd %f32 %val1 %fcount\n"
7544 "OpBranch %continue\n"
7546 "%continue = OpLabel\n"
7547 "%count__ = OpISub %i32 %count %c_i32_1\n"
7548 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
7549 "OpBranchConditional %again %loop %exit\n"
7552 "%val_post = OpPhi %f32 %val2 %continue %val1 %if\n"
7553 "%same = OpFSub %f32 %val_post %c_f32_7\n"
7554 "%result = OpVectorInsertDynamic %v4f32 %param1 %same %c_i32_0\n"
7555 "OpReturnValue %result\n"
7557 createTestsForAllStages("break", defaultColors, defaultColors, fragments, testGroup.get());
7559 // A loop with return.
7560 fragments["testfun"] =
7561 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
7562 "%param1 = OpFunctionParameter %v4f32\n"
7564 "%entry = OpLabel\n"
7565 ";param1 components are between 0 and 1, so dot product is 4 or less\n"
7566 "%dot = OpDot %f32 %param1 %param1\n"
7567 "%div = OpFDiv %f32 %dot %c_f32_5\n"
7568 "%zero = OpConvertFToU %u32 %div\n"
7569 "%two = OpIAdd %i32 %zero %c_i32_2\n"
7570 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
7573 ";returns early without modifying %param1\n"
7575 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %continue\n"
7576 "%val1 = OpPhi %f32 %val0 %entry %val2 %continue\n"
7577 "OpLoopMerge %exit %continue None\n"
7581 ";return if %count==%two\n"
7582 "%above2 = OpSGreaterThan %bool %count %two\n"
7583 "OpSelectionMerge %continue DontFlatten\n"
7584 "OpBranchConditional %above2 %body %early_exit\n"
7586 "%early_exit = OpLabel\n"
7587 "OpReturnValue %param1\n"
7590 "%fcount = OpConvertSToF %f32 %count\n"
7591 "%val2 = OpFAdd %f32 %val1 %fcount\n"
7592 "OpBranch %continue\n"
7594 "%continue = OpLabel\n"
7595 "%count__ = OpISub %i32 %count %c_i32_1\n"
7596 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
7597 "OpBranchConditional %again %loop %exit\n"
7600 ";should never get here, so return an incorrect result\n"
7601 "%result = OpVectorInsertDynamic %v4f32 %param1 %val2 %c_i32_0\n"
7602 "OpReturnValue %result\n"
7604 createTestsForAllStages("return", defaultColors, defaultColors, fragments, testGroup.get());
7606 // Continue inside a switch block to break to enclosing loop's merge block.
7607 // Matches roughly the following GLSL code:
7608 // for (; keep_going; keep_going = false)
7610 // switch (int(param1.x))
7612 // case 0: continue;
7613 // case 1: continue;
7614 // default: continue;
7616 // dead code: modify return value to invalid result.
7618 fragments["pre_main"] =
7619 "%fp_bool = OpTypePointer Function %bool\n"
7620 "%true = OpConstantTrue %bool\n"
7621 "%false = OpConstantFalse %bool\n";
7623 fragments["testfun"] =
7624 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
7625 "%param1 = OpFunctionParameter %v4f32\n"
7627 "%entry = OpLabel\n"
7628 "%keep_going = OpVariable %fp_bool Function\n"
7629 "%val_ptr = OpVariable %fp_f32 Function\n"
7630 "%param1_x = OpCompositeExtract %f32 %param1 0\n"
7631 "OpStore %keep_going %true\n"
7632 "OpBranch %forloop_begin\n"
7634 "%forloop_begin = OpLabel\n"
7635 "OpLoopMerge %forloop_merge %forloop_continue None\n"
7636 "OpBranch %forloop\n"
7638 "%forloop = OpLabel\n"
7639 "%for_condition = OpLoad %bool %keep_going\n"
7640 "OpBranchConditional %for_condition %forloop_body %forloop_merge\n"
7642 "%forloop_body = OpLabel\n"
7643 "OpStore %val_ptr %param1_x\n"
7644 "%param1_x_int = OpConvertFToS %i32 %param1_x\n"
7646 "OpSelectionMerge %switch_merge None\n"
7647 "OpSwitch %param1_x_int %default 0 %case_0 1 %case_1\n"
7648 "%case_0 = OpLabel\n"
7649 "OpBranch %forloop_continue\n"
7650 "%case_1 = OpLabel\n"
7651 "OpBranch %forloop_continue\n"
7652 "%default = OpLabel\n"
7653 "OpBranch %forloop_continue\n"
7654 "%switch_merge = OpLabel\n"
7655 ";should never get here, so change the return value to invalid result\n"
7656 "OpStore %val_ptr %c_f32_1\n"
7657 "OpBranch %forloop_continue\n"
7659 "%forloop_continue = OpLabel\n"
7660 "OpStore %keep_going %false\n"
7661 "OpBranch %forloop_begin\n"
7662 "%forloop_merge = OpLabel\n"
7664 "%val = OpLoad %f32 %val_ptr\n"
7665 "%result = OpVectorInsertDynamic %v4f32 %param1 %val %c_i32_0\n"
7666 "OpReturnValue %result\n"
7668 createTestsForAllStages("switch_continue", defaultColors, defaultColors, fragments, testGroup.get());
7670 return testGroup.release();
7673 // A collection of tests putting OpControlBarrier in places GLSL forbids but SPIR-V allows.
7674 tcu::TestCaseGroup* createBarrierTests(tcu::TestContext& testCtx)
7676 de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, "barrier", "OpControlBarrier"));
7677 map<string, string> fragments;
7679 // A barrier inside a function body.
7680 fragments["pre_main"] =
7681 "%Workgroup = OpConstant %i32 2\n"
7682 "%WorkgroupAcquireRelease = OpConstant %i32 0x108\n";
7683 fragments["testfun"] =
7684 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
7685 "%param1 = OpFunctionParameter %v4f32\n"
7686 "%label_testfun = OpLabel\n"
7687 "OpControlBarrier %Workgroup %Workgroup %WorkgroupAcquireRelease\n"
7688 "OpReturnValue %param1\n"
7690 addTessCtrlTest(testGroup.get(), "in_function", fragments);
7692 // Common setup code for the following tests.
7693 fragments["pre_main"] =
7694 "%Workgroup = OpConstant %i32 2\n"
7695 "%WorkgroupAcquireRelease = OpConstant %i32 0x108\n"
7696 "%c_f32_5 = OpConstant %f32 5.\n";
7697 const string setupPercentZero = // Begins %test_code function with code that sets %zero to 0u but cannot be optimized away.
7698 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
7699 "%param1 = OpFunctionParameter %v4f32\n"
7700 "%entry = OpLabel\n"
7701 ";param1 components are between 0 and 1, so dot product is 4 or less\n"
7702 "%dot = OpDot %f32 %param1 %param1\n"
7703 "%div = OpFDiv %f32 %dot %c_f32_5\n"
7704 "%zero = OpConvertFToU %u32 %div\n";
7706 // Barriers inside OpSwitch branches.
7707 fragments["testfun"] =
7709 "OpSelectionMerge %switch_exit None\n"
7710 "OpSwitch %zero %switch_default 0 %case0 1 %case1 ;should always go to %case0\n"
7712 "%case1 = OpLabel\n"
7713 ";This barrier should never be executed, but its presence makes test failure more likely when there's a bug.\n"
7714 "OpControlBarrier %Workgroup %Workgroup %WorkgroupAcquireRelease\n"
7715 "%wrong_branch_alert1 = OpVectorInsertDynamic %v4f32 %param1 %c_f32_0_5 %c_i32_0\n"
7716 "OpBranch %switch_exit\n"
7718 "%switch_default = OpLabel\n"
7719 "%wrong_branch_alert2 = OpVectorInsertDynamic %v4f32 %param1 %c_f32_0_5 %c_i32_0\n"
7720 ";This barrier should never be executed, but its presence makes test failure more likely when there's a bug.\n"
7721 "OpControlBarrier %Workgroup %Workgroup %WorkgroupAcquireRelease\n"
7722 "OpBranch %switch_exit\n"
7724 "%case0 = OpLabel\n"
7725 "OpControlBarrier %Workgroup %Workgroup %WorkgroupAcquireRelease\n"
7726 "OpBranch %switch_exit\n"
7728 "%switch_exit = OpLabel\n"
7729 "%ret = OpPhi %v4f32 %param1 %case0 %wrong_branch_alert1 %case1 %wrong_branch_alert2 %switch_default\n"
7730 "OpReturnValue %ret\n"
7732 addTessCtrlTest(testGroup.get(), "in_switch", fragments);
7734 // Barriers inside if-then-else.
7735 fragments["testfun"] =
7737 "%eq0 = OpIEqual %bool %zero %c_u32_0\n"
7738 "OpSelectionMerge %exit DontFlatten\n"
7739 "OpBranchConditional %eq0 %then %else\n"
7742 ";This barrier should never be executed, but its presence makes test failure more likely when there's a bug.\n"
7743 "OpControlBarrier %Workgroup %Workgroup %WorkgroupAcquireRelease\n"
7744 "%wrong_branch_alert = OpVectorInsertDynamic %v4f32 %param1 %c_f32_0_5 %c_i32_0\n"
7748 "OpControlBarrier %Workgroup %Workgroup %WorkgroupAcquireRelease\n"
7752 "%ret = OpPhi %v4f32 %param1 %then %wrong_branch_alert %else\n"
7753 "OpReturnValue %ret\n"
7755 addTessCtrlTest(testGroup.get(), "in_if", fragments);
7757 // A barrier after control-flow reconvergence, tempting the compiler to attempt something like this:
7758 // http://lists.llvm.org/pipermail/llvm-dev/2009-October/026317.html.
7759 fragments["testfun"] =
7761 "%thread_id = OpLoad %i32 %BP_gl_InvocationID\n"
7762 "%thread0 = OpIEqual %bool %thread_id %c_i32_0\n"
7763 "OpSelectionMerge %exit DontFlatten\n"
7764 "OpBranchConditional %thread0 %then %else\n"
7767 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
7771 "%val1 = OpVectorExtractDynamic %f32 %param1 %zero\n"
7775 "%val = OpPhi %f32 %val0 %else %val1 %then\n"
7776 "OpControlBarrier %Workgroup %Workgroup %WorkgroupAcquireRelease\n"
7777 "%ret = OpVectorInsertDynamic %v4f32 %param1 %val %zero\n"
7778 "OpReturnValue %ret\n"
7780 addTessCtrlTest(testGroup.get(), "after_divergent_if", fragments);
7782 // A barrier inside a loop.
7783 fragments["pre_main"] =
7784 "%Workgroup = OpConstant %i32 2\n"
7785 "%WorkgroupAcquireRelease = OpConstant %i32 0x108\n"
7786 "%c_f32_10 = OpConstant %f32 10.\n";
7787 fragments["testfun"] =
7788 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
7789 "%param1 = OpFunctionParameter %v4f32\n"
7790 "%entry = OpLabel\n"
7791 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
7794 ";adds 4, 3, 2, and 1 to %val0\n"
7796 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %loop\n"
7797 "%val1 = OpPhi %f32 %val0 %entry %val %loop\n"
7798 "OpControlBarrier %Workgroup %Workgroup %WorkgroupAcquireRelease\n"
7799 "%fcount = OpConvertSToF %f32 %count\n"
7800 "%val = OpFAdd %f32 %val1 %fcount\n"
7801 "%count__ = OpISub %i32 %count %c_i32_1\n"
7802 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
7803 "OpLoopMerge %exit %loop None\n"
7804 "OpBranchConditional %again %loop %exit\n"
7807 "%same = OpFSub %f32 %val %c_f32_10\n"
7808 "%ret = OpVectorInsertDynamic %v4f32 %param1 %same %c_i32_0\n"
7809 "OpReturnValue %ret\n"
7811 addTessCtrlTest(testGroup.get(), "in_loop", fragments);
7813 return testGroup.release();
7816 // Test for the OpFRem instruction.
7817 tcu::TestCaseGroup* createFRemTests(tcu::TestContext& testCtx)
7819 de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, "frem", "OpFRem"));
7820 map<string, string> fragments;
7821 RGBA inputColors[4];
7822 RGBA outputColors[4];
7824 fragments["pre_main"] =
7825 "%c_f32_3 = OpConstant %f32 3.0\n"
7826 "%c_f32_n3 = OpConstant %f32 -3.0\n"
7827 "%c_f32_4 = OpConstant %f32 4.0\n"
7828 "%c_f32_p75 = OpConstant %f32 0.75\n"
7829 "%c_v4f32_p75_p75_p75_p75 = OpConstantComposite %v4f32 %c_f32_p75 %c_f32_p75 %c_f32_p75 %c_f32_p75 \n"
7830 "%c_v4f32_4_4_4_4 = OpConstantComposite %v4f32 %c_f32_4 %c_f32_4 %c_f32_4 %c_f32_4\n"
7831 "%c_v4f32_3_n3_3_n3 = OpConstantComposite %v4f32 %c_f32_3 %c_f32_n3 %c_f32_3 %c_f32_n3\n";
7833 // The test does the following.
7834 // vec4 result = (param1 * 8.0) - 4.0;
7835 // return (frem(result.x,3) + 0.75, frem(result.y, -3) + 0.75, 0, 1)
7836 fragments["testfun"] =
7837 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
7838 "%param1 = OpFunctionParameter %v4f32\n"
7839 "%label_testfun = OpLabel\n"
7840 "%v_times_8 = OpVectorTimesScalar %v4f32 %param1 %c_f32_8\n"
7841 "%minus_4 = OpFSub %v4f32 %v_times_8 %c_v4f32_4_4_4_4\n"
7842 "%frem = OpFRem %v4f32 %minus_4 %c_v4f32_3_n3_3_n3\n"
7843 "%added = OpFAdd %v4f32 %frem %c_v4f32_p75_p75_p75_p75\n"
7844 "%xyz_1 = OpVectorInsertDynamic %v4f32 %added %c_f32_1 %c_i32_3\n"
7845 "%xy_0_1 = OpVectorInsertDynamic %v4f32 %xyz_1 %c_f32_0 %c_i32_2\n"
7846 "OpReturnValue %xy_0_1\n"
7850 inputColors[0] = RGBA(16, 16, 0, 255);
7851 inputColors[1] = RGBA(232, 232, 0, 255);
7852 inputColors[2] = RGBA(232, 16, 0, 255);
7853 inputColors[3] = RGBA(16, 232, 0, 255);
7855 outputColors[0] = RGBA(64, 64, 0, 255);
7856 outputColors[1] = RGBA(255, 255, 0, 255);
7857 outputColors[2] = RGBA(255, 64, 0, 255);
7858 outputColors[3] = RGBA(64, 255, 0, 255);
7860 createTestsForAllStages("frem", inputColors, outputColors, fragments, testGroup.get());
7861 return testGroup.release();
7864 // Test for the OpSRem instruction.
7865 tcu::TestCaseGroup* createOpSRemGraphicsTests(tcu::TestContext& testCtx, qpTestResult negFailResult)
7867 de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, "srem", "OpSRem"));
7868 map<string, string> fragments;
7870 fragments["pre_main"] =
7871 "%c_f32_255 = OpConstant %f32 255.0\n"
7872 "%c_i32_128 = OpConstant %i32 128\n"
7873 "%c_i32_255 = OpConstant %i32 255\n"
7874 "%c_v4f32_255 = OpConstantComposite %v4f32 %c_f32_255 %c_f32_255 %c_f32_255 %c_f32_255 \n"
7875 "%c_v4f32_0_5 = OpConstantComposite %v4f32 %c_f32_0_5 %c_f32_0_5 %c_f32_0_5 %c_f32_0_5 \n"
7876 "%c_v4i32_128 = OpConstantComposite %v4i32 %c_i32_128 %c_i32_128 %c_i32_128 %c_i32_128 \n";
7878 // The test does the following.
7879 // ivec4 ints = int(param1 * 255.0 + 0.5) - 128;
7880 // ivec4 result = ivec4(srem(ints.x, ints.y), srem(ints.y, ints.z), srem(ints.z, ints.x), 255);
7881 // return float(result + 128) / 255.0;
7882 fragments["testfun"] =
7883 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
7884 "%param1 = OpFunctionParameter %v4f32\n"
7885 "%label_testfun = OpLabel\n"
7886 "%div255 = OpFMul %v4f32 %param1 %c_v4f32_255\n"
7887 "%add0_5 = OpFAdd %v4f32 %div255 %c_v4f32_0_5\n"
7888 "%uints_in = OpConvertFToS %v4i32 %add0_5\n"
7889 "%ints_in = OpISub %v4i32 %uints_in %c_v4i32_128\n"
7890 "%x_in = OpCompositeExtract %i32 %ints_in 0\n"
7891 "%y_in = OpCompositeExtract %i32 %ints_in 1\n"
7892 "%z_in = OpCompositeExtract %i32 %ints_in 2\n"
7893 "%x_out = OpSRem %i32 %x_in %y_in\n"
7894 "%y_out = OpSRem %i32 %y_in %z_in\n"
7895 "%z_out = OpSRem %i32 %z_in %x_in\n"
7896 "%ints_out = OpCompositeConstruct %v4i32 %x_out %y_out %z_out %c_i32_255\n"
7897 "%ints_offset = OpIAdd %v4i32 %ints_out %c_v4i32_128\n"
7898 "%f_ints_offset = OpConvertSToF %v4f32 %ints_offset\n"
7899 "%float_out = OpFDiv %v4f32 %f_ints_offset %c_v4f32_255\n"
7900 "OpReturnValue %float_out\n"
7903 const struct CaseParams
7906 const char* failMessageTemplate; // customized status message
7907 qpTestResult failResult; // override status on failure
7908 int operands[4][3]; // four (x, y, z) vectors of operands
7909 int results[4][3]; // four (x, y, z) vectors of results
7915 QP_TEST_RESULT_FAIL,
7916 { { 5, 12, 17 }, { 5, 5, 7 }, { 75, 8, 81 }, { 25, 60, 100 } }, // operands
7917 { { 5, 12, 2 }, { 0, 5, 2 }, { 3, 8, 6 }, { 25, 60, 0 } }, // results
7921 "Inconsistent results, but within specification: ${reason}",
7922 negFailResult, // negative operands, not required by the spec
7923 { { 5, 12, -17 }, { -5, -5, 7 }, { 75, 8, -81 }, { 25, -60, 100 } }, // operands
7924 { { 5, 12, -2 }, { 0, -5, 2 }, { 3, 8, -6 }, { 25, -60, 0 } }, // results
7927 // If either operand is negative the result is undefined. Some implementations may still return correct values.
7929 for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(cases); ++caseNdx)
7931 const CaseParams& params = cases[caseNdx];
7932 RGBA inputColors[4];
7933 RGBA outputColors[4];
7935 for (int i = 0; i < 4; ++i)
7937 inputColors [i] = RGBA(params.operands[i][0] + 128, params.operands[i][1] + 128, params.operands[i][2] + 128, 255);
7938 outputColors[i] = RGBA(params.results [i][0] + 128, params.results [i][1] + 128, params.results [i][2] + 128, 255);
7941 createTestsForAllStages(params.name, inputColors, outputColors, fragments, testGroup.get(), params.failResult, params.failMessageTemplate);
7944 return testGroup.release();
7947 // Test for the OpSMod instruction.
7948 tcu::TestCaseGroup* createOpSModGraphicsTests(tcu::TestContext& testCtx, qpTestResult negFailResult)
7950 de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, "smod", "OpSMod"));
7951 map<string, string> fragments;
7953 fragments["pre_main"] =
7954 "%c_f32_255 = OpConstant %f32 255.0\n"
7955 "%c_i32_128 = OpConstant %i32 128\n"
7956 "%c_i32_255 = OpConstant %i32 255\n"
7957 "%c_v4f32_255 = OpConstantComposite %v4f32 %c_f32_255 %c_f32_255 %c_f32_255 %c_f32_255 \n"
7958 "%c_v4f32_0_5 = OpConstantComposite %v4f32 %c_f32_0_5 %c_f32_0_5 %c_f32_0_5 %c_f32_0_5 \n"
7959 "%c_v4i32_128 = OpConstantComposite %v4i32 %c_i32_128 %c_i32_128 %c_i32_128 %c_i32_128 \n";
7961 // The test does the following.
7962 // ivec4 ints = int(param1 * 255.0 + 0.5) - 128;
7963 // ivec4 result = ivec4(smod(ints.x, ints.y), smod(ints.y, ints.z), smod(ints.z, ints.x), 255);
7964 // return float(result + 128) / 255.0;
7965 fragments["testfun"] =
7966 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
7967 "%param1 = OpFunctionParameter %v4f32\n"
7968 "%label_testfun = OpLabel\n"
7969 "%div255 = OpFMul %v4f32 %param1 %c_v4f32_255\n"
7970 "%add0_5 = OpFAdd %v4f32 %div255 %c_v4f32_0_5\n"
7971 "%uints_in = OpConvertFToS %v4i32 %add0_5\n"
7972 "%ints_in = OpISub %v4i32 %uints_in %c_v4i32_128\n"
7973 "%x_in = OpCompositeExtract %i32 %ints_in 0\n"
7974 "%y_in = OpCompositeExtract %i32 %ints_in 1\n"
7975 "%z_in = OpCompositeExtract %i32 %ints_in 2\n"
7976 "%x_out = OpSMod %i32 %x_in %y_in\n"
7977 "%y_out = OpSMod %i32 %y_in %z_in\n"
7978 "%z_out = OpSMod %i32 %z_in %x_in\n"
7979 "%ints_out = OpCompositeConstruct %v4i32 %x_out %y_out %z_out %c_i32_255\n"
7980 "%ints_offset = OpIAdd %v4i32 %ints_out %c_v4i32_128\n"
7981 "%f_ints_offset = OpConvertSToF %v4f32 %ints_offset\n"
7982 "%float_out = OpFDiv %v4f32 %f_ints_offset %c_v4f32_255\n"
7983 "OpReturnValue %float_out\n"
7986 const struct CaseParams
7989 const char* failMessageTemplate; // customized status message
7990 qpTestResult failResult; // override status on failure
7991 int operands[4][3]; // four (x, y, z) vectors of operands
7992 int results[4][3]; // four (x, y, z) vectors of results
7998 QP_TEST_RESULT_FAIL,
7999 { { 5, 12, 17 }, { 5, 5, 7 }, { 75, 8, 81 }, { 25, 60, 100 } }, // operands
8000 { { 5, 12, 2 }, { 0, 5, 2 }, { 3, 8, 6 }, { 25, 60, 0 } }, // results
8004 "Inconsistent results, but within specification: ${reason}",
8005 negFailResult, // negative operands, not required by the spec
8006 { { 5, 12, -17 }, { -5, -5, 7 }, { 75, 8, -81 }, { 25, -60, 100 } }, // operands
8007 { { 5, -5, 3 }, { 0, 2, -3 }, { 3, -73, 69 }, { -35, 40, 0 } }, // results
8010 // If either operand is negative the result is undefined. Some implementations may still return correct values.
8012 for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(cases); ++caseNdx)
8014 const CaseParams& params = cases[caseNdx];
8015 RGBA inputColors[4];
8016 RGBA outputColors[4];
8018 for (int i = 0; i < 4; ++i)
8020 inputColors [i] = RGBA(params.operands[i][0] + 128, params.operands[i][1] + 128, params.operands[i][2] + 128, 255);
8021 outputColors[i] = RGBA(params.results [i][0] + 128, params.results [i][1] + 128, params.results [i][2] + 128, 255);
8024 createTestsForAllStages(params.name, inputColors, outputColors, fragments, testGroup.get(), params.failResult, params.failMessageTemplate);
8026 return testGroup.release();
8029 enum ConversionDataType
8031 DATA_TYPE_SIGNED_16,
8032 DATA_TYPE_SIGNED_32,
8033 DATA_TYPE_SIGNED_64,
8034 DATA_TYPE_UNSIGNED_16,
8035 DATA_TYPE_UNSIGNED_32,
8036 DATA_TYPE_UNSIGNED_64,
8039 DATA_TYPE_VEC2_SIGNED_16,
8040 DATA_TYPE_VEC2_SIGNED_32
8043 const string getBitWidthStr (ConversionDataType type)
8047 case DATA_TYPE_SIGNED_16:
8048 case DATA_TYPE_UNSIGNED_16:
8051 case DATA_TYPE_SIGNED_32:
8052 case DATA_TYPE_UNSIGNED_32:
8053 case DATA_TYPE_FLOAT_32:
8054 case DATA_TYPE_VEC2_SIGNED_16:
8057 case DATA_TYPE_SIGNED_64:
8058 case DATA_TYPE_UNSIGNED_64:
8059 case DATA_TYPE_FLOAT_64:
8060 case DATA_TYPE_VEC2_SIGNED_32:
8069 const string getByteWidthStr (ConversionDataType type)
8073 case DATA_TYPE_SIGNED_16:
8074 case DATA_TYPE_UNSIGNED_16:
8077 case DATA_TYPE_SIGNED_32:
8078 case DATA_TYPE_UNSIGNED_32:
8079 case DATA_TYPE_FLOAT_32:
8080 case DATA_TYPE_VEC2_SIGNED_16:
8083 case DATA_TYPE_SIGNED_64:
8084 case DATA_TYPE_UNSIGNED_64:
8085 case DATA_TYPE_FLOAT_64:
8086 case DATA_TYPE_VEC2_SIGNED_32:
8095 bool isSigned (ConversionDataType type)
8099 case DATA_TYPE_SIGNED_16:
8100 case DATA_TYPE_SIGNED_32:
8101 case DATA_TYPE_SIGNED_64:
8102 case DATA_TYPE_FLOAT_32:
8103 case DATA_TYPE_FLOAT_64:
8104 case DATA_TYPE_VEC2_SIGNED_16:
8105 case DATA_TYPE_VEC2_SIGNED_32:
8108 case DATA_TYPE_UNSIGNED_16:
8109 case DATA_TYPE_UNSIGNED_32:
8110 case DATA_TYPE_UNSIGNED_64:
8119 bool isInt (ConversionDataType type)
8123 case DATA_TYPE_SIGNED_16:
8124 case DATA_TYPE_SIGNED_32:
8125 case DATA_TYPE_SIGNED_64:
8126 case DATA_TYPE_UNSIGNED_16:
8127 case DATA_TYPE_UNSIGNED_32:
8128 case DATA_TYPE_UNSIGNED_64:
8131 case DATA_TYPE_FLOAT_32:
8132 case DATA_TYPE_FLOAT_64:
8133 case DATA_TYPE_VEC2_SIGNED_16:
8134 case DATA_TYPE_VEC2_SIGNED_32:
8143 bool isFloat (ConversionDataType type)
8147 case DATA_TYPE_SIGNED_16:
8148 case DATA_TYPE_SIGNED_32:
8149 case DATA_TYPE_SIGNED_64:
8150 case DATA_TYPE_UNSIGNED_16:
8151 case DATA_TYPE_UNSIGNED_32:
8152 case DATA_TYPE_UNSIGNED_64:
8153 case DATA_TYPE_VEC2_SIGNED_16:
8154 case DATA_TYPE_VEC2_SIGNED_32:
8157 case DATA_TYPE_FLOAT_32:
8158 case DATA_TYPE_FLOAT_64:
8167 const string getTypeName (ConversionDataType type)
8169 string prefix = isSigned(type) ? "" : "u";
8171 if (isInt(type)) return prefix + "int" + getBitWidthStr(type);
8172 else if (isFloat(type)) return prefix + "float" + getBitWidthStr(type);
8173 else if (type == DATA_TYPE_VEC2_SIGNED_16) return "i16vec2";
8174 else if (type == DATA_TYPE_VEC2_SIGNED_32) return "i32vec2";
8175 else DE_ASSERT(false);
8180 const string getTestName (ConversionDataType from, ConversionDataType to)
8182 return getTypeName(from) + "_to_" + getTypeName(to);
8185 const string getAsmTypeName (ConversionDataType type)
8189 if (isInt(type)) prefix = isSigned(type) ? "i" : "u";
8190 else if (isFloat(type)) prefix = "f";
8191 else if (type == DATA_TYPE_VEC2_SIGNED_16) return "i16vec2";
8192 else if (type == DATA_TYPE_VEC2_SIGNED_32) return "v2i32";
8193 else DE_ASSERT(false);
8195 return prefix + getBitWidthStr(type);
8198 template<typename T>
8199 BufferSp getSpecializedBuffer (deInt64 number)
8201 return BufferSp(new Buffer<T>(vector<T>(1, (T)number)));
8204 BufferSp getBuffer (ConversionDataType type, deInt64 number)
8208 case DATA_TYPE_SIGNED_16: return getSpecializedBuffer<deInt16>(number);
8209 case DATA_TYPE_SIGNED_32: return getSpecializedBuffer<deInt32>(number);
8210 case DATA_TYPE_SIGNED_64: return getSpecializedBuffer<deInt64>(number);
8211 case DATA_TYPE_UNSIGNED_16: return getSpecializedBuffer<deUint16>(number);
8212 case DATA_TYPE_UNSIGNED_32: return getSpecializedBuffer<deUint32>(number);
8213 case DATA_TYPE_UNSIGNED_64: return getSpecializedBuffer<deUint64>(number);
8214 case DATA_TYPE_FLOAT_32: return getSpecializedBuffer<deUint32>(number);
8215 case DATA_TYPE_FLOAT_64: return getSpecializedBuffer<deUint64>(number);
8216 case DATA_TYPE_VEC2_SIGNED_16: return getSpecializedBuffer<deUint32>(number);
8217 case DATA_TYPE_VEC2_SIGNED_32: return getSpecializedBuffer<deUint64>(number);
8219 default: DE_ASSERT(false);
8220 return BufferSp(new Buffer<deInt32>(vector<deInt32>(1, 0)));
8224 bool usesInt16 (ConversionDataType from, ConversionDataType to)
8226 return (from == DATA_TYPE_SIGNED_16 || from == DATA_TYPE_UNSIGNED_16
8227 || to == DATA_TYPE_SIGNED_16 || to == DATA_TYPE_UNSIGNED_16
8228 || from == DATA_TYPE_VEC2_SIGNED_16 || to == DATA_TYPE_VEC2_SIGNED_16);
8231 bool usesInt32 (ConversionDataType from, ConversionDataType to)
8233 return (from == DATA_TYPE_SIGNED_32 || from == DATA_TYPE_UNSIGNED_32
8234 || to == DATA_TYPE_SIGNED_32 || to == DATA_TYPE_UNSIGNED_32
8235 || from == DATA_TYPE_VEC2_SIGNED_32 || to == DATA_TYPE_VEC2_SIGNED_32);
8238 bool usesInt64 (ConversionDataType from, ConversionDataType to)
8240 return (from == DATA_TYPE_SIGNED_64 || from == DATA_TYPE_UNSIGNED_64
8241 || to == DATA_TYPE_SIGNED_64 || to == DATA_TYPE_UNSIGNED_64);
8244 bool usesFloat64 (ConversionDataType from, ConversionDataType to)
8246 return (from == DATA_TYPE_FLOAT_64 || to == DATA_TYPE_FLOAT_64);
8250 ComputeTestFeatures getConversionUsedFeatures (ConversionDataType from, ConversionDataType to)
8252 if (usesInt16(from, to) && usesInt64(from, to)) return COMPUTE_TEST_USES_INT16_INT64;
8253 else if (usesInt16(from, to) && usesInt32(from, to)) return COMPUTE_TEST_USES_NONE;
8254 else if (usesInt16(from, to)) return COMPUTE_TEST_USES_INT16; // This is not set for int16<-->int32 only conversions
8255 else if (usesInt64(from, to)) return COMPUTE_TEST_USES_INT64;
8256 else if (usesFloat64(from, to)) return COMPUTE_TEST_USES_FLOAT64;
8257 else return COMPUTE_TEST_USES_NONE;
8260 vector<string> getFeatureStringVector (ComputeTestFeatures computeTestFeatures)
8262 vector<string> features;
8263 if (computeTestFeatures == COMPUTE_TEST_USES_INT16_INT64)
8265 features.push_back("shaderInt16");
8266 features.push_back("shaderInt64");
8268 else if (computeTestFeatures == COMPUTE_TEST_USES_INT16) features.push_back("shaderInt16");
8269 else if (computeTestFeatures == COMPUTE_TEST_USES_INT64) features.push_back("shaderInt64");
8270 else if (computeTestFeatures == COMPUTE_TEST_USES_FLOAT64) features.push_back("shaderFloat64");
8271 else if (computeTestFeatures == COMPUTE_TEST_USES_NONE) {}
8272 else DE_ASSERT(false);
8279 ConvertCase (ConversionDataType from, ConversionDataType to, deInt64 number, bool separateOutput = false, deInt64 outputNumber = 0)
8282 , m_features (getConversionUsedFeatures(from, to))
8283 , m_name (getTestName(from, to))
8284 , m_inputBuffer (getBuffer(from, number))
8286 m_asmTypes["inputType"] = getAsmTypeName(from);
8287 m_asmTypes["outputType"] = getAsmTypeName(to);
8290 m_outputBuffer = getBuffer(to, outputNumber);
8292 m_outputBuffer = getBuffer(to, number);
8294 if (m_features == COMPUTE_TEST_USES_INT16)
8296 m_asmTypes["datatype_capabilities"] = "OpCapability Int16\n"
8297 "OpCapability StorageUniformBufferBlock16\n"
8298 "OpCapability StorageUniform16\n";
8299 m_asmTypes["datatype_additional_decl"] = "%i16 = OpTypeInt 16 1\n"
8300 "%u16 = OpTypeInt 16 0\n"
8301 "%i16vec2 = OpTypeVector %i16 2\n";
8302 m_asmTypes["datatype_extensions"] = "OpExtension \"SPV_KHR_16bit_storage\"\n";
8304 else if (m_features == COMPUTE_TEST_USES_INT64)
8306 m_asmTypes["datatype_capabilities"] = "OpCapability Int64\n";
8307 m_asmTypes["datatype_additional_decl"] = "%i64 = OpTypeInt 64 1\n"
8308 "%u64 = OpTypeInt 64 0\n";
8309 m_asmTypes["datatype_extensions"] = "";
8311 else if (m_features == COMPUTE_TEST_USES_INT16_INT64)
8313 m_asmTypes["datatype_capabilities"] = "OpCapability Int16\n"
8314 "OpCapability StorageUniformBufferBlock16\n"
8315 "OpCapability StorageUniform16\n"
8316 "OpCapability Int64\n";
8317 m_asmTypes["datatype_additional_decl"] = "%i16 = OpTypeInt 16 1\n"
8318 "%u16 = OpTypeInt 16 0\n"
8319 "%i64 = OpTypeInt 64 1\n"
8320 "%u64 = OpTypeInt 64 0\n";
8321 m_asmTypes["datatype_extensions"] = "OpExtension \"SPV_KHR_16bit_storage\"\n";
8323 else if (m_features == COMPUTE_TEST_USES_FLOAT64)
8325 m_asmTypes["datatype_capabilities"] = "OpCapability Float64\n";
8326 m_asmTypes["datatype_additional_decl"] = "%f64 = OpTypeFloat 64\n";
8328 else if (usesInt16(from, to) && usesInt32(from, to))
8330 m_asmTypes["datatype_capabilities"] = "OpCapability StorageUniformBufferBlock16\n"
8331 "OpCapability StorageUniform16\n";
8332 m_asmTypes["datatype_additional_decl"] = "%i16 = OpTypeInt 16 1\n"
8333 "%u16 = OpTypeInt 16 0\n"
8334 "%i16vec2 = OpTypeVector %i16 2\n";
8335 m_asmTypes["datatype_extensions"] = "OpExtension \"SPV_KHR_16bit_storage\"\n";
8343 ConversionDataType m_fromType;
8344 ConversionDataType m_toType;
8345 ComputeTestFeatures m_features;
8347 map<string, string> m_asmTypes;
8348 BufferSp m_inputBuffer;
8349 BufferSp m_outputBuffer;
8352 const string getConvertCaseShaderStr (const string& instruction, const ConvertCase& convertCase)
8354 map<string, string> params = convertCase.m_asmTypes;
8356 params["instruction"] = instruction;
8357 params["inDecorator"] = getByteWidthStr(convertCase.m_fromType);
8358 params["outDecorator"] = getByteWidthStr(convertCase.m_toType);
8360 const StringTemplate shader (
8361 "OpCapability Shader\n"
8362 "${datatype_capabilities}"
8363 "${datatype_extensions:opt}"
8364 "OpMemoryModel Logical GLSL450\n"
8365 "OpEntryPoint GLCompute %main \"main\"\n"
8366 "OpExecutionMode %main LocalSize 1 1 1\n"
8367 "OpSource GLSL 430\n"
8368 "OpName %main \"main\"\n"
8370 "OpDecorate %indata DescriptorSet 0\n"
8371 "OpDecorate %indata Binding 0\n"
8372 "OpDecorate %outdata DescriptorSet 0\n"
8373 "OpDecorate %outdata Binding 1\n"
8374 "OpDecorate %in_buf BufferBlock\n"
8375 "OpDecorate %out_buf BufferBlock\n"
8376 "OpMemberDecorate %in_buf 0 Offset 0\n"
8377 "OpMemberDecorate %out_buf 0 Offset 0\n"
8379 "%void = OpTypeVoid\n"
8380 "%voidf = OpTypeFunction %void\n"
8381 "%u32 = OpTypeInt 32 0\n"
8382 "%i32 = OpTypeInt 32 1\n"
8383 "%f32 = OpTypeFloat 32\n"
8384 "%v2i32 = OpTypeVector %i32 2\n"
8385 "${datatype_additional_decl}"
8386 "%uvec3 = OpTypeVector %u32 3\n"
8388 "%in_ptr = OpTypePointer Uniform %${inputType}\n"
8389 "%out_ptr = OpTypePointer Uniform %${outputType}\n"
8390 "%in_buf = OpTypeStruct %${inputType}\n"
8391 "%out_buf = OpTypeStruct %${outputType}\n"
8392 "%in_bufptr = OpTypePointer Uniform %in_buf\n"
8393 "%out_bufptr = OpTypePointer Uniform %out_buf\n"
8394 "%indata = OpVariable %in_bufptr Uniform\n"
8395 "%outdata = OpVariable %out_bufptr Uniform\n"
8397 "%zero = OpConstant %i32 0\n"
8399 "%main = OpFunction %void None %voidf\n"
8400 "%label = OpLabel\n"
8401 "%inloc = OpAccessChain %in_ptr %indata %zero\n"
8402 "%outloc = OpAccessChain %out_ptr %outdata %zero\n"
8403 "%inval = OpLoad %${inputType} %inloc\n"
8404 "%conv = ${instruction} %${outputType} %inval\n"
8405 " OpStore %outloc %conv\n"
8410 return shader.specialize(params);
8413 void createConvertCases (vector<ConvertCase>& testCases, const string& instruction)
8415 if (instruction == "OpUConvert")
8417 // Convert unsigned int to unsigned int
8418 testCases.push_back(ConvertCase(DATA_TYPE_UNSIGNED_16, DATA_TYPE_UNSIGNED_32, 60653));
8419 testCases.push_back(ConvertCase(DATA_TYPE_UNSIGNED_16, DATA_TYPE_UNSIGNED_64, 17991));
8420 testCases.push_back(ConvertCase(DATA_TYPE_UNSIGNED_32, DATA_TYPE_UNSIGNED_64, 904256275));
8421 testCases.push_back(ConvertCase(DATA_TYPE_UNSIGNED_32, DATA_TYPE_UNSIGNED_16, 6275));
8422 testCases.push_back(ConvertCase(DATA_TYPE_UNSIGNED_64, DATA_TYPE_UNSIGNED_32, 701256243));
8423 testCases.push_back(ConvertCase(DATA_TYPE_UNSIGNED_64, DATA_TYPE_UNSIGNED_16, 4741));
8425 else if (instruction == "OpSConvert")
8427 // Sign extension int->int
8428 testCases.push_back(ConvertCase(DATA_TYPE_SIGNED_16, DATA_TYPE_SIGNED_32, 14669));
8429 testCases.push_back(ConvertCase(DATA_TYPE_SIGNED_16, DATA_TYPE_SIGNED_64, -3341));
8430 testCases.push_back(ConvertCase(DATA_TYPE_SIGNED_32, DATA_TYPE_SIGNED_64, 973610259));
8432 // Truncate for int->int
8433 testCases.push_back(ConvertCase(DATA_TYPE_SIGNED_32, DATA_TYPE_SIGNED_16, 12382));
8434 testCases.push_back(ConvertCase(DATA_TYPE_SIGNED_64, DATA_TYPE_SIGNED_32, -972812359));
8435 testCases.push_back(ConvertCase(DATA_TYPE_SIGNED_64, DATA_TYPE_SIGNED_16, -1067742499291926803ll, true, -4371));
8437 // Sign extension for int->uint
8438 testCases.push_back(ConvertCase(DATA_TYPE_SIGNED_16, DATA_TYPE_UNSIGNED_32, 14669));
8439 testCases.push_back(ConvertCase(DATA_TYPE_SIGNED_16, DATA_TYPE_UNSIGNED_64, -3341, true, 18446744073709548275ull));
8440 testCases.push_back(ConvertCase(DATA_TYPE_SIGNED_32, DATA_TYPE_UNSIGNED_64, 973610259));
8442 // Truncate for int->uint
8443 testCases.push_back(ConvertCase(DATA_TYPE_SIGNED_32, DATA_TYPE_UNSIGNED_16, 12382));
8444 testCases.push_back(ConvertCase(DATA_TYPE_SIGNED_64, DATA_TYPE_UNSIGNED_32, -972812359, true, 3322154937u));
8445 testCases.push_back(ConvertCase(DATA_TYPE_SIGNED_64, DATA_TYPE_UNSIGNED_16, -1067742499291926803ll, true, 61165));
8447 // Sign extension for uint->int
8448 testCases.push_back(ConvertCase(DATA_TYPE_UNSIGNED_16, DATA_TYPE_SIGNED_32, 14669));
8449 testCases.push_back(ConvertCase(DATA_TYPE_UNSIGNED_16, DATA_TYPE_SIGNED_64, 62195, true, -3341));
8450 testCases.push_back(ConvertCase(DATA_TYPE_UNSIGNED_32, DATA_TYPE_SIGNED_64, 973610259));
8452 // Truncate for uint->int
8453 testCases.push_back(ConvertCase(DATA_TYPE_UNSIGNED_32, DATA_TYPE_SIGNED_16, 12382));
8454 testCases.push_back(ConvertCase(DATA_TYPE_UNSIGNED_64, DATA_TYPE_SIGNED_32, 18446744072736739257ull, true, -972812359));
8455 testCases.push_back(ConvertCase(DATA_TYPE_UNSIGNED_64, DATA_TYPE_SIGNED_16, 17379001574417624813ull, true, -4371));
8457 // Convert i16vec2 to i32vec2 and vice versa
8458 // Unsigned values are used here to represent negative signed values and to allow defined shifting behaviour.
8459 // The actual signed value -32123 is used here as uint16 value 33413 and uint32 value 4294935173
8460 testCases.push_back(ConvertCase(DATA_TYPE_VEC2_SIGNED_16, DATA_TYPE_VEC2_SIGNED_32, (33413u << 16) | 27593, true, (4294935173ull << 32) | 27593));
8461 testCases.push_back(ConvertCase(DATA_TYPE_VEC2_SIGNED_32, DATA_TYPE_VEC2_SIGNED_16, (4294935173ull << 32) | 27593, true, (33413u << 16) | 27593));
8463 else if (instruction == "OpFConvert")
8465 // All hexadecimal values below represent 1024.0 as 32/64-bit IEEE 754 float
8466 testCases.push_back(ConvertCase(DATA_TYPE_FLOAT_32, DATA_TYPE_FLOAT_64, 0x449a4000, true, 0x4093480000000000));
8467 testCases.push_back(ConvertCase(DATA_TYPE_FLOAT_64, DATA_TYPE_FLOAT_32, 0x4093480000000000, true, 0x449a4000));
8470 DE_FATAL("Unknown instruction");
8473 const map<string, string> getConvertCaseFragments (string instruction, const ConvertCase& convertCase)
8475 map<string, string> params = convertCase.m_asmTypes;
8476 map<string, string> fragments;
8478 params["instruction"] = instruction;
8479 params["inDecorator"] = getByteWidthStr(convertCase.m_fromType);
8481 const StringTemplate decoration (
8482 " OpDecorate %SSBOi DescriptorSet 0\n"
8483 " OpDecorate %SSBOo DescriptorSet 0\n"
8484 " OpDecorate %SSBOi Binding 0\n"
8485 " OpDecorate %SSBOo Binding 1\n"
8486 " OpDecorate %s_SSBOi Block\n"
8487 " OpDecorate %s_SSBOo Block\n"
8488 "OpMemberDecorate %s_SSBOi 0 Offset 0\n"
8489 "OpMemberDecorate %s_SSBOo 0 Offset 0\n");
8491 const StringTemplate pre_main (
8492 "${datatype_additional_decl:opt}"
8493 " %ptr_in = OpTypePointer StorageBuffer %${inputType}\n"
8494 " %ptr_out = OpTypePointer StorageBuffer %${outputType}\n"
8495 " %s_SSBOi = OpTypeStruct %${inputType}\n"
8496 " %s_SSBOo = OpTypeStruct %${outputType}\n"
8497 " %ptr_SSBOi = OpTypePointer StorageBuffer %s_SSBOi\n"
8498 " %ptr_SSBOo = OpTypePointer StorageBuffer %s_SSBOo\n"
8499 " %SSBOi = OpVariable %ptr_SSBOi StorageBuffer\n"
8500 " %SSBOo = OpVariable %ptr_SSBOo StorageBuffer\n");
8502 const StringTemplate testfun (
8503 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
8504 "%param = OpFunctionParameter %v4f32\n"
8505 "%label = OpLabel\n"
8506 "%iLoc = OpAccessChain %ptr_in %SSBOi %c_u32_0\n"
8507 "%oLoc = OpAccessChain %ptr_out %SSBOo %c_u32_0\n"
8508 "%valIn = OpLoad %${inputType} %iLoc\n"
8509 "%valOut = ${instruction} %${outputType} %valIn\n"
8510 " OpStore %oLoc %valOut\n"
8511 " OpReturnValue %param\n"
8512 " OpFunctionEnd\n");
8514 params["datatype_extensions"] =
8515 params["datatype_extensions"] +
8516 "OpExtension \"SPV_KHR_storage_buffer_storage_class\"\n";
8518 fragments["capability"] = params["datatype_capabilities"];
8519 fragments["extension"] = params["datatype_extensions"];
8520 fragments["decoration"] = decoration.specialize(params);
8521 fragments["pre_main"] = pre_main.specialize(params);
8522 fragments["testfun"] = testfun.specialize(params);
8527 // Test for OpSConvert, OpUConvert and OpFConvert in compute shaders
8528 tcu::TestCaseGroup* createConvertComputeTests (tcu::TestContext& testCtx, const string& instruction, const string& name)
8530 de::MovePtr<tcu::TestCaseGroup> group(new tcu::TestCaseGroup(testCtx, name.c_str(), instruction.c_str()));
8531 vector<ConvertCase> testCases;
8532 createConvertCases(testCases, instruction);
8534 for (vector<ConvertCase>::const_iterator test = testCases.begin(); test != testCases.end(); ++test)
8536 ComputeShaderSpec spec;
8537 spec.assembly = getConvertCaseShaderStr(instruction, *test);
8538 spec.numWorkGroups = IVec3(1, 1, 1);
8539 spec.inputs.push_back (test->m_inputBuffer);
8540 spec.outputs.push_back (test->m_outputBuffer);
8542 if (test->m_features == COMPUTE_TEST_USES_INT16 || test->m_features == COMPUTE_TEST_USES_INT16_INT64 || usesInt16(test->m_fromType, test->m_toType)) {
8543 spec.extensions.push_back("VK_KHR_16bit_storage");
8544 spec.requestedVulkanFeatures.ext16BitStorage = EXT16BITSTORAGEFEATURES_UNIFORM_BUFFER_BLOCK;
8547 group->addChild(new SpvAsmComputeShaderCase(testCtx, test->m_name.c_str(), "", spec, test->m_features));
8549 return group.release();
8552 // Test for OpSConvert, OpUConvert and OpFConvert in graphics shaders
8553 tcu::TestCaseGroup* createConvertGraphicsTests (tcu::TestContext& testCtx, const string& instruction, const string& name)
8555 de::MovePtr<tcu::TestCaseGroup> group(new tcu::TestCaseGroup(testCtx, name.c_str(), instruction.c_str()));
8556 vector<ConvertCase> testCases;
8557 createConvertCases(testCases, instruction);
8559 for (vector<ConvertCase>::const_iterator test = testCases.begin(); test != testCases.end(); ++test)
8561 map<string, string> fragments = getConvertCaseFragments(instruction, *test);
8562 vector<string> features = getFeatureStringVector(test->m_features);
8563 GraphicsResources resources;
8564 vector<string> extensions;
8565 vector<deInt32> noSpecConstants;
8566 PushConstants noPushConstants;
8567 VulkanFeatures vulkanFeatures;
8568 GraphicsInterfaces noInterfaces;
8569 tcu::RGBA defaultColors[4];
8571 getDefaultColors (defaultColors);
8572 resources.inputs.push_back (std::make_pair(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, test->m_inputBuffer));
8573 resources.outputs.push_back (std::make_pair(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, test->m_outputBuffer));
8574 extensions.push_back ("VK_KHR_storage_buffer_storage_class");
8576 if (test->m_features == COMPUTE_TEST_USES_INT16 || test->m_features == COMPUTE_TEST_USES_INT16_INT64 || usesInt16(test->m_fromType, test->m_toType))
8578 extensions.push_back("VK_KHR_16bit_storage");
8579 vulkanFeatures.ext16BitStorage = EXT16BITSTORAGEFEATURES_UNIFORM_BUFFER_BLOCK;
8582 createTestsForAllStages(
8583 test->m_name, defaultColors, defaultColors, fragments, noSpecConstants,
8584 noPushConstants, resources, noInterfaces, extensions, features, vulkanFeatures, group.get());
8586 return group.release();
8589 const string getNumberTypeName (const NumberType type)
8591 if (type == NUMBERTYPE_INT32)
8595 else if (type == NUMBERTYPE_UINT32)
8599 else if (type == NUMBERTYPE_FLOAT32)
8610 deInt32 getInt(de::Random& rnd)
8612 return rnd.getInt(std::numeric_limits<int>::min(), std::numeric_limits<int>::max());
8615 const string repeatString (const string& str, int times)
8618 for (int i = 0; i < times; ++i)
8625 const string getRandomConstantString (const NumberType type, de::Random& rnd)
8627 if (type == NUMBERTYPE_INT32)
8629 return numberToString<deInt32>(getInt(rnd));
8631 else if (type == NUMBERTYPE_UINT32)
8633 return numberToString<deUint32>(rnd.getUint32());
8635 else if (type == NUMBERTYPE_FLOAT32)
8637 return numberToString<float>(rnd.getFloat());
8646 void createVectorCompositeCases (vector<map<string, string> >& testCases, de::Random& rnd, const NumberType type)
8648 map<string, string> params;
8651 for (int width = 2; width <= 4; ++width)
8653 const string randomConst = numberToString(getInt(rnd));
8654 const string widthStr = numberToString(width);
8655 const string composite_type = "${customType}vec" + widthStr;
8656 const int index = rnd.getInt(0, width-1);
8658 params["type"] = "vec";
8659 params["name"] = params["type"] + "_" + widthStr;
8660 params["compositeDecl"] = composite_type + " = OpTypeVector ${customType} " + widthStr +"\n";
8661 params["compositeType"] = composite_type;
8662 params["filler"] = string("%filler = OpConstant ${customType} ") + getRandomConstantString(type, rnd) + "\n";
8663 params["compositeConstruct"] = "%instance = OpCompositeConstruct " + composite_type + repeatString(" %filler", width) + "\n";
8664 params["indexes"] = numberToString(index);
8665 testCases.push_back(params);
8669 void createArrayCompositeCases (vector<map<string, string> >& testCases, de::Random& rnd, const NumberType type)
8671 const int limit = 10;
8672 map<string, string> params;
8674 for (int width = 2; width <= limit; ++width)
8676 string randomConst = numberToString(getInt(rnd));
8677 string widthStr = numberToString(width);
8678 int index = rnd.getInt(0, width-1);
8680 params["type"] = "array";
8681 params["name"] = params["type"] + "_" + widthStr;
8682 params["compositeDecl"] = string("%arraywidth = OpConstant %u32 " + widthStr + "\n")
8683 + "%composite = OpTypeArray ${customType} %arraywidth\n";
8684 params["compositeType"] = "%composite";
8685 params["filler"] = string("%filler = OpConstant ${customType} ") + getRandomConstantString(type, rnd) + "\n";
8686 params["compositeConstruct"] = "%instance = OpCompositeConstruct %composite" + repeatString(" %filler", width) + "\n";
8687 params["indexes"] = numberToString(index);
8688 testCases.push_back(params);
8692 void createStructCompositeCases (vector<map<string, string> >& testCases, de::Random& rnd, const NumberType type)
8694 const int limit = 10;
8695 map<string, string> params;
8697 for (int width = 2; width <= limit; ++width)
8699 string randomConst = numberToString(getInt(rnd));
8700 int index = rnd.getInt(0, width-1);
8702 params["type"] = "struct";
8703 params["name"] = params["type"] + "_" + numberToString(width);
8704 params["compositeDecl"] = "%composite = OpTypeStruct" + repeatString(" ${customType}", width) + "\n";
8705 params["compositeType"] = "%composite";
8706 params["filler"] = string("%filler = OpConstant ${customType} ") + getRandomConstantString(type, rnd) + "\n";
8707 params["compositeConstruct"] = "%instance = OpCompositeConstruct %composite" + repeatString(" %filler", width) + "\n";
8708 params["indexes"] = numberToString(index);
8709 testCases.push_back(params);
8713 void createMatrixCompositeCases (vector<map<string, string> >& testCases, de::Random& rnd, const NumberType type)
8715 map<string, string> params;
8718 for (int width = 2; width <= 4; ++width)
8720 string widthStr = numberToString(width);
8722 for (int column = 2 ; column <= 4; ++column)
8724 int index_0 = rnd.getInt(0, column-1);
8725 int index_1 = rnd.getInt(0, width-1);
8726 string columnStr = numberToString(column);
8728 params["type"] = "matrix";
8729 params["name"] = params["type"] + "_" + widthStr + "x" + columnStr;
8730 params["compositeDecl"] = string("%vectype = OpTypeVector ${customType} " + widthStr + "\n")
8731 + "%composite = OpTypeMatrix %vectype " + columnStr + "\n";
8732 params["compositeType"] = "%composite";
8734 params["filler"] = string("%filler = OpConstant ${customType} ") + getRandomConstantString(type, rnd) + "\n"
8735 + "%fillerVec = OpConstantComposite %vectype" + repeatString(" %filler", width) + "\n";
8737 params["compositeConstruct"] = "%instance = OpCompositeConstruct %composite" + repeatString(" %fillerVec", column) + "\n";
8738 params["indexes"] = numberToString(index_0) + " " + numberToString(index_1);
8739 testCases.push_back(params);
8744 void createCompositeCases (vector<map<string, string> >& testCases, de::Random& rnd, const NumberType type)
8746 createVectorCompositeCases(testCases, rnd, type);
8747 createArrayCompositeCases(testCases, rnd, type);
8748 createStructCompositeCases(testCases, rnd, type);
8749 // Matrix only supports float types
8750 if (type == NUMBERTYPE_FLOAT32)
8752 createMatrixCompositeCases(testCases, rnd, type);
8756 const string getAssemblyTypeDeclaration (const NumberType type)
8760 case NUMBERTYPE_INT32: return "OpTypeInt 32 1";
8761 case NUMBERTYPE_UINT32: return "OpTypeInt 32 0";
8762 case NUMBERTYPE_FLOAT32: return "OpTypeFloat 32";
8763 default: DE_ASSERT(false); return "";
8767 const string getAssemblyTypeName (const NumberType type)
8771 case NUMBERTYPE_INT32: return "%i32";
8772 case NUMBERTYPE_UINT32: return "%u32";
8773 case NUMBERTYPE_FLOAT32: return "%f32";
8774 default: DE_ASSERT(false); return "";
8778 const string specializeCompositeInsertShaderTemplate (const NumberType type, const map<string, string>& params)
8780 map<string, string> parameters(params);
8782 const string customType = getAssemblyTypeName(type);
8783 map<string, string> substCustomType;
8784 substCustomType["customType"] = customType;
8785 parameters["compositeDecl"] = StringTemplate(parameters.at("compositeDecl")).specialize(substCustomType);
8786 parameters["compositeType"] = StringTemplate(parameters.at("compositeType")).specialize(substCustomType);
8787 parameters["compositeConstruct"] = StringTemplate(parameters.at("compositeConstruct")).specialize(substCustomType);
8788 parameters["filler"] = StringTemplate(parameters.at("filler")).specialize(substCustomType);
8789 parameters["customType"] = customType;
8790 parameters["compositeDecorator"] = (parameters["type"] == "array") ? "OpDecorate %composite ArrayStride 4\n" : "";
8792 if (parameters.at("compositeType") != "%u32vec3")
8794 parameters["u32vec3Decl"] = "%u32vec3 = OpTypeVector %u32 3\n";
8797 return StringTemplate(
8798 "OpCapability Shader\n"
8799 "OpCapability Matrix\n"
8800 "OpMemoryModel Logical GLSL450\n"
8801 "OpEntryPoint GLCompute %main \"main\" %id\n"
8802 "OpExecutionMode %main LocalSize 1 1 1\n"
8804 "OpSource GLSL 430\n"
8805 "OpName %main \"main\"\n"
8806 "OpName %id \"gl_GlobalInvocationID\"\n"
8809 "OpDecorate %id BuiltIn GlobalInvocationId\n"
8810 "OpDecorate %buf BufferBlock\n"
8811 "OpDecorate %indata DescriptorSet 0\n"
8812 "OpDecorate %indata Binding 0\n"
8813 "OpDecorate %outdata DescriptorSet 0\n"
8814 "OpDecorate %outdata Binding 1\n"
8815 "OpDecorate %customarr ArrayStride 4\n"
8816 "${compositeDecorator}"
8817 "OpMemberDecorate %buf 0 Offset 0\n"
8820 "%void = OpTypeVoid\n"
8821 "%voidf = OpTypeFunction %void\n"
8822 "%u32 = OpTypeInt 32 0\n"
8823 "%i32 = OpTypeInt 32 1\n"
8824 "%f32 = OpTypeFloat 32\n"
8826 // Composite declaration
8832 "${u32vec3Decl:opt}"
8833 "%uvec3ptr = OpTypePointer Input %u32vec3\n"
8835 // Inherited from custom
8836 "%customptr = OpTypePointer Uniform ${customType}\n"
8837 "%customarr = OpTypeRuntimeArray ${customType}\n"
8838 "%buf = OpTypeStruct %customarr\n"
8839 "%bufptr = OpTypePointer Uniform %buf\n"
8841 "%indata = OpVariable %bufptr Uniform\n"
8842 "%outdata = OpVariable %bufptr Uniform\n"
8844 "%id = OpVariable %uvec3ptr Input\n"
8845 "%zero = OpConstant %i32 0\n"
8847 "%main = OpFunction %void None %voidf\n"
8848 "%label = OpLabel\n"
8849 "%idval = OpLoad %u32vec3 %id\n"
8850 "%x = OpCompositeExtract %u32 %idval 0\n"
8852 "%inloc = OpAccessChain %customptr %indata %zero %x\n"
8853 "%outloc = OpAccessChain %customptr %outdata %zero %x\n"
8854 // Read the input value
8855 "%inval = OpLoad ${customType} %inloc\n"
8856 // Create the composite and fill it
8857 "${compositeConstruct}"
8858 // Insert the input value to a place
8859 "%instance2 = OpCompositeInsert ${compositeType} %inval %instance ${indexes}\n"
8860 // Read back the value from the position
8861 "%out_val = OpCompositeExtract ${customType} %instance2 ${indexes}\n"
8862 // Store it in the output position
8863 " OpStore %outloc %out_val\n"
8866 ).specialize(parameters);
8869 template<typename T>
8870 BufferSp createCompositeBuffer(T number)
8872 return BufferSp(new Buffer<T>(vector<T>(1, number)));
8875 tcu::TestCaseGroup* createOpCompositeInsertGroup (tcu::TestContext& testCtx)
8877 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opcompositeinsert", "Test the OpCompositeInsert instruction"));
8878 de::Random rnd (deStringHash(group->getName()));
8880 for (int type = NUMBERTYPE_INT32; type != NUMBERTYPE_END32; ++type)
8882 NumberType numberType = NumberType(type);
8883 const string typeName = getNumberTypeName(numberType);
8884 const string description = "Test the OpCompositeInsert instruction with " + typeName + "s";
8885 de::MovePtr<tcu::TestCaseGroup> subGroup (new tcu::TestCaseGroup(testCtx, typeName.c_str(), description.c_str()));
8886 vector<map<string, string> > testCases;
8888 createCompositeCases(testCases, rnd, numberType);
8890 for (vector<map<string, string> >::const_iterator test = testCases.begin(); test != testCases.end(); ++test)
8892 ComputeShaderSpec spec;
8894 spec.assembly = specializeCompositeInsertShaderTemplate(numberType, *test);
8898 case NUMBERTYPE_INT32:
8900 deInt32 number = getInt(rnd);
8901 spec.inputs.push_back(createCompositeBuffer<deInt32>(number));
8902 spec.outputs.push_back(createCompositeBuffer<deInt32>(number));
8905 case NUMBERTYPE_UINT32:
8907 deUint32 number = rnd.getUint32();
8908 spec.inputs.push_back(createCompositeBuffer<deUint32>(number));
8909 spec.outputs.push_back(createCompositeBuffer<deUint32>(number));
8912 case NUMBERTYPE_FLOAT32:
8914 float number = rnd.getFloat();
8915 spec.inputs.push_back(createCompositeBuffer<float>(number));
8916 spec.outputs.push_back(createCompositeBuffer<float>(number));
8923 spec.numWorkGroups = IVec3(1, 1, 1);
8924 subGroup->addChild(new SpvAsmComputeShaderCase(testCtx, test->at("name").c_str(), "OpCompositeInsert test", spec));
8926 group->addChild(subGroup.release());
8928 return group.release();
8931 struct AssemblyStructInfo
8933 AssemblyStructInfo (const deUint32 comp, const deUint32 idx)
8938 deUint32 components;
8942 const string specializeInBoundsShaderTemplate (const NumberType type, const AssemblyStructInfo& structInfo, const map<string, string>& params)
8944 // Create the full index string
8945 string fullIndex = numberToString(structInfo.index) + " " + params.at("indexes");
8946 // Convert it to list of indexes
8947 vector<string> indexes = de::splitString(fullIndex, ' ');
8949 map<string, string> parameters (params);
8950 parameters["structType"] = repeatString(" ${compositeType}", structInfo.components);
8951 parameters["structConstruct"] = repeatString(" %instance", structInfo.components);
8952 parameters["insertIndexes"] = fullIndex;
8954 // In matrix cases the last two index is the CompositeExtract indexes
8955 const deUint32 extractIndexes = (parameters["type"] == "matrix") ? 2 : 1;
8957 // Construct the extractIndex
8958 for (vector<string>::const_iterator index = indexes.end() - extractIndexes; index != indexes.end(); ++index)
8960 parameters["extractIndexes"] += " " + *index;
8963 // Remove the last 1 or 2 element depends on matrix case or not
8964 indexes.erase(indexes.end() - extractIndexes, indexes.end());
8967 // Generate AccessChain index expressions (except for the last one, because we use ptr to the composite)
8968 for (vector<string>::const_iterator index = indexes.begin(); index != indexes.end(); ++index)
8970 string indexId = "%index_" + numberToString(id++);
8971 parameters["accessChainConstDeclaration"] += indexId + " = OpConstant %u32 " + *index + "\n";
8972 parameters["accessChainIndexes"] += " " + indexId;
8975 parameters["compositeDecorator"] = (parameters["type"] == "array") ? "OpDecorate %composite ArrayStride 4\n" : "";
8977 const string customType = getAssemblyTypeName(type);
8978 map<string, string> substCustomType;
8979 substCustomType["customType"] = customType;
8980 parameters["compositeDecl"] = StringTemplate(parameters.at("compositeDecl")).specialize(substCustomType);
8981 parameters["compositeType"] = StringTemplate(parameters.at("compositeType")).specialize(substCustomType);
8982 parameters["compositeConstruct"] = StringTemplate(parameters.at("compositeConstruct")).specialize(substCustomType);
8983 parameters["filler"] = StringTemplate(parameters.at("filler")).specialize(substCustomType);
8984 parameters["customType"] = customType;
8986 const string compositeType = parameters.at("compositeType");
8987 map<string, string> substCompositeType;
8988 substCompositeType["compositeType"] = compositeType;
8989 parameters["structType"] = StringTemplate(parameters.at("structType")).specialize(substCompositeType);
8990 if (compositeType != "%u32vec3")
8992 parameters["u32vec3Decl"] = "%u32vec3 = OpTypeVector %u32 3\n";
8995 return StringTemplate(
8996 "OpCapability Shader\n"
8997 "OpCapability Matrix\n"
8998 "OpMemoryModel Logical GLSL450\n"
8999 "OpEntryPoint GLCompute %main \"main\" %id\n"
9000 "OpExecutionMode %main LocalSize 1 1 1\n"
9002 "OpSource GLSL 430\n"
9003 "OpName %main \"main\"\n"
9004 "OpName %id \"gl_GlobalInvocationID\"\n"
9006 "OpDecorate %id BuiltIn GlobalInvocationId\n"
9007 "OpDecorate %buf BufferBlock\n"
9008 "OpDecorate %indata DescriptorSet 0\n"
9009 "OpDecorate %indata Binding 0\n"
9010 "OpDecorate %outdata DescriptorSet 0\n"
9011 "OpDecorate %outdata Binding 1\n"
9012 "OpDecorate %customarr ArrayStride 4\n"
9013 "${compositeDecorator}"
9014 "OpMemberDecorate %buf 0 Offset 0\n"
9016 "%void = OpTypeVoid\n"
9017 "%voidf = OpTypeFunction %void\n"
9018 "%i32 = OpTypeInt 32 1\n"
9019 "%u32 = OpTypeInt 32 0\n"
9020 "%f32 = OpTypeFloat 32\n"
9023 // %u32vec3 if not already declared in ${compositeDecl}
9024 "${u32vec3Decl:opt}"
9025 "%uvec3ptr = OpTypePointer Input %u32vec3\n"
9026 // Inherited from composite
9027 "%composite_p = OpTypePointer Function ${compositeType}\n"
9028 "%struct_t = OpTypeStruct${structType}\n"
9029 "%struct_p = OpTypePointer Function %struct_t\n"
9032 "${accessChainConstDeclaration}"
9033 // Inherited from custom
9034 "%customptr = OpTypePointer Uniform ${customType}\n"
9035 "%customarr = OpTypeRuntimeArray ${customType}\n"
9036 "%buf = OpTypeStruct %customarr\n"
9037 "%bufptr = OpTypePointer Uniform %buf\n"
9038 "%indata = OpVariable %bufptr Uniform\n"
9039 "%outdata = OpVariable %bufptr Uniform\n"
9041 "%id = OpVariable %uvec3ptr Input\n"
9042 "%zero = OpConstant %u32 0\n"
9043 "%main = OpFunction %void None %voidf\n"
9044 "%label = OpLabel\n"
9045 "%struct_v = OpVariable %struct_p Function\n"
9046 "%idval = OpLoad %u32vec3 %id\n"
9047 "%x = OpCompositeExtract %u32 %idval 0\n"
9048 // Create the input/output type
9049 "%inloc = OpInBoundsAccessChain %customptr %indata %zero %x\n"
9050 "%outloc = OpInBoundsAccessChain %customptr %outdata %zero %x\n"
9051 // Read the input value
9052 "%inval = OpLoad ${customType} %inloc\n"
9053 // Create the composite and fill it
9054 "${compositeConstruct}"
9055 // Create the struct and fill it with the composite
9056 "%struct = OpCompositeConstruct %struct_t${structConstruct}\n"
9058 "%comp_obj = OpCompositeInsert %struct_t %inval %struct ${insertIndexes}\n"
9060 " OpStore %struct_v %comp_obj\n"
9061 // Get deepest possible composite pointer
9062 "%inner_ptr = OpInBoundsAccessChain %composite_p %struct_v${accessChainIndexes}\n"
9063 "%read_obj = OpLoad ${compositeType} %inner_ptr\n"
9064 // Read back the stored value
9065 "%read_val = OpCompositeExtract ${customType} %read_obj${extractIndexes}\n"
9066 " OpStore %outloc %read_val\n"
9069 ).specialize(parameters);
9072 tcu::TestCaseGroup* createOpInBoundsAccessChainGroup (tcu::TestContext& testCtx)
9074 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opinboundsaccesschain", "Test the OpInBoundsAccessChain instruction"));
9075 de::Random rnd (deStringHash(group->getName()));
9077 for (int type = NUMBERTYPE_INT32; type != NUMBERTYPE_END32; ++type)
9079 NumberType numberType = NumberType(type);
9080 const string typeName = getNumberTypeName(numberType);
9081 const string description = "Test the OpInBoundsAccessChain instruction with " + typeName + "s";
9082 de::MovePtr<tcu::TestCaseGroup> subGroup (new tcu::TestCaseGroup(testCtx, typeName.c_str(), description.c_str()));
9084 vector<map<string, string> > testCases;
9085 createCompositeCases(testCases, rnd, numberType);
9087 for (vector<map<string, string> >::const_iterator test = testCases.begin(); test != testCases.end(); ++test)
9089 ComputeShaderSpec spec;
9091 // Number of components inside of a struct
9092 deUint32 structComponents = rnd.getInt(2, 8);
9093 // Component index value
9094 deUint32 structIndex = rnd.getInt(0, structComponents - 1);
9095 AssemblyStructInfo structInfo(structComponents, structIndex);
9097 spec.assembly = specializeInBoundsShaderTemplate(numberType, structInfo, *test);
9101 case NUMBERTYPE_INT32:
9103 deInt32 number = getInt(rnd);
9104 spec.inputs.push_back(createCompositeBuffer<deInt32>(number));
9105 spec.outputs.push_back(createCompositeBuffer<deInt32>(number));
9108 case NUMBERTYPE_UINT32:
9110 deUint32 number = rnd.getUint32();
9111 spec.inputs.push_back(createCompositeBuffer<deUint32>(number));
9112 spec.outputs.push_back(createCompositeBuffer<deUint32>(number));
9115 case NUMBERTYPE_FLOAT32:
9117 float number = rnd.getFloat();
9118 spec.inputs.push_back(createCompositeBuffer<float>(number));
9119 spec.outputs.push_back(createCompositeBuffer<float>(number));
9125 spec.numWorkGroups = IVec3(1, 1, 1);
9126 subGroup->addChild(new SpvAsmComputeShaderCase(testCtx, test->at("name").c_str(), "OpInBoundsAccessChain test", spec));
9128 group->addChild(subGroup.release());
9130 return group.release();
9133 // If the params missing, uninitialized case
9134 const string specializeDefaultOutputShaderTemplate (const NumberType type, const map<string, string>& params = map<string, string>())
9136 map<string, string> parameters(params);
9138 parameters["customType"] = getAssemblyTypeName(type);
9140 // Declare the const value, and use it in the initializer
9141 if (params.find("constValue") != params.end())
9143 parameters["variableInitializer"] = " %const";
9145 // Uninitialized case
9148 parameters["commentDecl"] = ";";
9151 return StringTemplate(
9152 "OpCapability Shader\n"
9153 "OpMemoryModel Logical GLSL450\n"
9154 "OpEntryPoint GLCompute %main \"main\" %id\n"
9155 "OpExecutionMode %main LocalSize 1 1 1\n"
9156 "OpSource GLSL 430\n"
9157 "OpName %main \"main\"\n"
9158 "OpName %id \"gl_GlobalInvocationID\"\n"
9160 "OpDecorate %id BuiltIn GlobalInvocationId\n"
9161 "OpDecorate %indata DescriptorSet 0\n"
9162 "OpDecorate %indata Binding 0\n"
9163 "OpDecorate %outdata DescriptorSet 0\n"
9164 "OpDecorate %outdata Binding 1\n"
9165 "OpDecorate %in_arr ArrayStride 4\n"
9166 "OpDecorate %in_buf BufferBlock\n"
9167 "OpMemberDecorate %in_buf 0 Offset 0\n"
9169 "%void = OpTypeVoid\n"
9170 "%voidf = OpTypeFunction %void\n"
9171 "%u32 = OpTypeInt 32 0\n"
9172 "%i32 = OpTypeInt 32 1\n"
9173 "%f32 = OpTypeFloat 32\n"
9174 "%uvec3 = OpTypeVector %u32 3\n"
9175 "%uvec3ptr = OpTypePointer Input %uvec3\n"
9176 "${commentDecl:opt}%const = OpConstant ${customType} ${constValue:opt}\n"
9178 "%in_ptr = OpTypePointer Uniform ${customType}\n"
9179 "%in_arr = OpTypeRuntimeArray ${customType}\n"
9180 "%in_buf = OpTypeStruct %in_arr\n"
9181 "%in_bufptr = OpTypePointer Uniform %in_buf\n"
9182 "%indata = OpVariable %in_bufptr Uniform\n"
9183 "%outdata = OpVariable %in_bufptr Uniform\n"
9184 "%id = OpVariable %uvec3ptr Input\n"
9185 "%var_ptr = OpTypePointer Function ${customType}\n"
9187 "%zero = OpConstant %i32 0\n"
9189 "%main = OpFunction %void None %voidf\n"
9190 "%label = OpLabel\n"
9191 "%out_var = OpVariable %var_ptr Function${variableInitializer:opt}\n"
9192 "%idval = OpLoad %uvec3 %id\n"
9193 "%x = OpCompositeExtract %u32 %idval 0\n"
9194 "%inloc = OpAccessChain %in_ptr %indata %zero %x\n"
9195 "%outloc = OpAccessChain %in_ptr %outdata %zero %x\n"
9197 "%outval = OpLoad ${customType} %out_var\n"
9198 " OpStore %outloc %outval\n"
9201 ).specialize(parameters);
9204 bool compareFloats (const std::vector<BufferSp>&, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs, TestLog& log)
9206 DE_ASSERT(outputAllocs.size() != 0);
9207 DE_ASSERT(outputAllocs.size() == expectedOutputs.size());
9209 // Use custom epsilon because of the float->string conversion
9210 const float epsilon = 0.00001f;
9212 for (size_t outputNdx = 0; outputNdx < outputAllocs.size(); ++outputNdx)
9214 vector<deUint8> expectedBytes;
9218 expectedOutputs[outputNdx]->getBytes(expectedBytes);
9219 memcpy(&expected, &expectedBytes.front(), expectedBytes.size());
9220 memcpy(&actual, outputAllocs[outputNdx]->getHostPtr(), expectedBytes.size());
9222 // Test with epsilon
9223 if (fabs(expected - actual) > epsilon)
9225 log << TestLog::Message << "Error: The actual and expected values not matching."
9226 << " Expected: " << expected << " Actual: " << actual << " Epsilon: " << epsilon << TestLog::EndMessage;
9233 // Checks if the driver crash with uninitialized cases
9234 bool passthruVerify (const std::vector<BufferSp>&, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs, TestLog&)
9236 DE_ASSERT(outputAllocs.size() != 0);
9237 DE_ASSERT(outputAllocs.size() == expectedOutputs.size());
9239 // Copy and discard the result.
9240 for (size_t outputNdx = 0; outputNdx < outputAllocs.size(); ++outputNdx)
9242 vector<deUint8> expectedBytes;
9243 expectedOutputs[outputNdx]->getBytes(expectedBytes);
9245 const size_t width = expectedBytes.size();
9246 vector<char> data (width);
9248 memcpy(&data[0], outputAllocs[outputNdx]->getHostPtr(), width);
9253 tcu::TestCaseGroup* createShaderDefaultOutputGroup (tcu::TestContext& testCtx)
9255 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "shader_default_output", "Test shader default output."));
9256 de::Random rnd (deStringHash(group->getName()));
9258 for (int type = NUMBERTYPE_INT32; type != NUMBERTYPE_END32; ++type)
9260 NumberType numberType = NumberType(type);
9261 const string typeName = getNumberTypeName(numberType);
9262 const string description = "Test the OpVariable initializer with " + typeName + ".";
9263 de::MovePtr<tcu::TestCaseGroup> subGroup (new tcu::TestCaseGroup(testCtx, typeName.c_str(), description.c_str()));
9265 // 2 similar subcases (initialized and uninitialized)
9266 for (int subCase = 0; subCase < 2; ++subCase)
9268 ComputeShaderSpec spec;
9269 spec.numWorkGroups = IVec3(1, 1, 1);
9271 map<string, string> params;
9275 case NUMBERTYPE_INT32:
9277 deInt32 number = getInt(rnd);
9278 spec.inputs.push_back(createCompositeBuffer<deInt32>(number));
9279 spec.outputs.push_back(createCompositeBuffer<deInt32>(number));
9280 params["constValue"] = numberToString(number);
9283 case NUMBERTYPE_UINT32:
9285 deUint32 number = rnd.getUint32();
9286 spec.inputs.push_back(createCompositeBuffer<deUint32>(number));
9287 spec.outputs.push_back(createCompositeBuffer<deUint32>(number));
9288 params["constValue"] = numberToString(number);
9291 case NUMBERTYPE_FLOAT32:
9293 float number = rnd.getFloat();
9294 spec.inputs.push_back(createCompositeBuffer<float>(number));
9295 spec.outputs.push_back(createCompositeBuffer<float>(number));
9296 spec.verifyIO = &compareFloats;
9297 params["constValue"] = numberToString(number);
9304 // Initialized subcase
9307 spec.assembly = specializeDefaultOutputShaderTemplate(numberType, params);
9308 subGroup->addChild(new SpvAsmComputeShaderCase(testCtx, "initialized", "OpVariable initializer tests.", spec));
9310 // Uninitialized subcase
9313 spec.assembly = specializeDefaultOutputShaderTemplate(numberType);
9314 spec.verifyIO = &passthruVerify;
9315 subGroup->addChild(new SpvAsmComputeShaderCase(testCtx, "uninitialized", "OpVariable initializer tests.", spec));
9318 group->addChild(subGroup.release());
9320 return group.release();
9323 tcu::TestCaseGroup* createOpNopTests (tcu::TestContext& testCtx)
9325 de::MovePtr<tcu::TestCaseGroup> testGroup (new tcu::TestCaseGroup(testCtx, "opnop", "Test OpNop"));
9326 RGBA defaultColors[4];
9327 map<string, string> opNopFragments;
9329 getDefaultColors(defaultColors);
9331 opNopFragments["testfun"] =
9332 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
9333 "%param1 = OpFunctionParameter %v4f32\n"
9334 "%label_testfun = OpLabel\n"
9343 "%a = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
9344 "%b = OpFAdd %f32 %a %a\n"
9346 "%c = OpFSub %f32 %b %a\n"
9347 "%ret = OpVectorInsertDynamic %v4f32 %param1 %c %c_i32_0\n"
9350 "OpReturnValue %ret\n"
9353 createTestsForAllStages("opnop", defaultColors, defaultColors, opNopFragments, testGroup.get());
9355 return testGroup.release();
9358 tcu::TestCaseGroup* createOpNameTests (tcu::TestContext& testCtx)
9360 de::MovePtr<tcu::TestCaseGroup> testGroup (new tcu::TestCaseGroup(testCtx, "opname","Test OpName"));
9361 RGBA defaultColors[4];
9362 map<string, string> opNameFragments;
9364 getDefaultColors(defaultColors);
9366 opNameFragments["debug"] =
9367 "OpName %BP_main \"not_main\"";
9369 opNameFragments["testfun"] =
9370 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
9371 "%param1 = OpFunctionParameter %v4f32\n"
9372 "%label_func = OpLabel\n"
9373 "%a = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
9374 "%b = OpFAdd %f32 %a %a\n"
9375 "%c = OpFSub %f32 %b %a\n"
9376 "%ret = OpVectorInsertDynamic %v4f32 %param1 %c %c_i32_0\n"
9377 "OpReturnValue %ret\n"
9380 createTestsForAllStages("opname", defaultColors, defaultColors, opNameFragments, testGroup.get());
9382 return testGroup.release();
9385 tcu::TestCaseGroup* createInstructionTests (tcu::TestContext& testCtx)
9387 const bool testComputePipeline = true;
9389 de::MovePtr<tcu::TestCaseGroup> instructionTests (new tcu::TestCaseGroup(testCtx, "instruction", "Instructions with special opcodes/operands"));
9390 de::MovePtr<tcu::TestCaseGroup> computeTests (new tcu::TestCaseGroup(testCtx, "compute", "Compute Instructions with special opcodes/operands"));
9391 de::MovePtr<tcu::TestCaseGroup> graphicsTests (new tcu::TestCaseGroup(testCtx, "graphics", "Graphics Instructions with special opcodes/operands"));
9393 computeTests->addChild(createSpivVersionCheckTests(testCtx, testComputePipeline));
9394 computeTests->addChild(createLocalSizeGroup(testCtx));
9395 computeTests->addChild(createOpNopGroup(testCtx));
9396 computeTests->addChild(createOpFUnordGroup(testCtx));
9397 computeTests->addChild(createOpAtomicGroup(testCtx, false));
9398 computeTests->addChild(createOpAtomicGroup(testCtx, true)); // Using new StorageBuffer decoration
9399 computeTests->addChild(createOpAtomicGroup(testCtx, false, 1024, true)); // Return value validation
9400 computeTests->addChild(createOpLineGroup(testCtx));
9401 computeTests->addChild(createOpModuleProcessedGroup(testCtx));
9402 computeTests->addChild(createOpNoLineGroup(testCtx));
9403 computeTests->addChild(createOpConstantNullGroup(testCtx));
9404 computeTests->addChild(createOpConstantCompositeGroup(testCtx));
9405 computeTests->addChild(createOpConstantUsageGroup(testCtx));
9406 computeTests->addChild(createSpecConstantGroup(testCtx));
9407 computeTests->addChild(createOpSourceGroup(testCtx));
9408 computeTests->addChild(createOpSourceExtensionGroup(testCtx));
9409 computeTests->addChild(createDecorationGroupGroup(testCtx));
9410 computeTests->addChild(createOpPhiGroup(testCtx));
9411 computeTests->addChild(createLoopControlGroup(testCtx));
9412 computeTests->addChild(createFunctionControlGroup(testCtx));
9413 computeTests->addChild(createSelectionControlGroup(testCtx));
9414 computeTests->addChild(createBlockOrderGroup(testCtx));
9415 computeTests->addChild(createMultipleShaderGroup(testCtx));
9416 computeTests->addChild(createMemoryAccessGroup(testCtx));
9417 computeTests->addChild(createOpCopyMemoryGroup(testCtx));
9418 computeTests->addChild(createOpCopyObjectGroup(testCtx));
9419 computeTests->addChild(createNoContractionGroup(testCtx));
9420 computeTests->addChild(createOpUndefGroup(testCtx));
9421 computeTests->addChild(createOpUnreachableGroup(testCtx));
9422 computeTests ->addChild(createOpQuantizeToF16Group(testCtx));
9423 computeTests ->addChild(createOpFRemGroup(testCtx));
9424 computeTests->addChild(createOpSRemComputeGroup(testCtx, QP_TEST_RESULT_PASS));
9425 computeTests->addChild(createOpSRemComputeGroup64(testCtx, QP_TEST_RESULT_PASS));
9426 computeTests->addChild(createOpSModComputeGroup(testCtx, QP_TEST_RESULT_PASS));
9427 computeTests->addChild(createOpSModComputeGroup64(testCtx, QP_TEST_RESULT_PASS));
9428 computeTests->addChild(createConvertComputeTests(testCtx, "OpSConvert", "sconvert"));
9429 computeTests->addChild(createConvertComputeTests(testCtx, "OpUConvert", "uconvert"));
9430 computeTests->addChild(createConvertComputeTests(testCtx, "OpFConvert", "fconvert"));
9431 computeTests->addChild(createOpCompositeInsertGroup(testCtx));
9432 computeTests->addChild(createOpInBoundsAccessChainGroup(testCtx));
9433 computeTests->addChild(createShaderDefaultOutputGroup(testCtx));
9434 computeTests->addChild(createOpNMinGroup(testCtx));
9435 computeTests->addChild(createOpNMaxGroup(testCtx));
9436 computeTests->addChild(createOpNClampGroup(testCtx));
9438 de::MovePtr<tcu::TestCaseGroup> computeAndroidTests (new tcu::TestCaseGroup(testCtx, "android", "Android CTS Tests"));
9440 computeAndroidTests->addChild(createOpSRemComputeGroup(testCtx, QP_TEST_RESULT_QUALITY_WARNING));
9441 computeAndroidTests->addChild(createOpSModComputeGroup(testCtx, QP_TEST_RESULT_QUALITY_WARNING));
9443 computeTests->addChild(computeAndroidTests.release());
9446 computeTests->addChild(create8BitStorageComputeGroup(testCtx));
9447 computeTests->addChild(create16BitStorageComputeGroup(testCtx));
9448 computeTests->addChild(createUboMatrixPaddingComputeGroup(testCtx));
9449 computeTests->addChild(createVariableInitComputeGroup(testCtx));
9450 computeTests->addChild(createConditionalBranchComputeGroup(testCtx));
9451 computeTests->addChild(createIndexingComputeGroup(testCtx));
9452 computeTests->addChild(createVariablePointersComputeGroup(testCtx));
9453 computeTests->addChild(createImageSamplerComputeGroup(testCtx));
9454 computeTests->addChild(createOpNameGroup(testCtx));
9455 graphicsTests->addChild(createCrossStageInterfaceTests(testCtx));
9456 graphicsTests->addChild(createSpivVersionCheckTests(testCtx, !testComputePipeline));
9457 graphicsTests->addChild(createOpNopTests(testCtx));
9458 graphicsTests->addChild(createOpSourceTests(testCtx));
9459 graphicsTests->addChild(createOpSourceContinuedTests(testCtx));
9460 graphicsTests->addChild(createOpModuleProcessedTests(testCtx));
9461 graphicsTests->addChild(createOpLineTests(testCtx));
9462 graphicsTests->addChild(createOpNoLineTests(testCtx));
9463 graphicsTests->addChild(createOpConstantNullTests(testCtx));
9464 graphicsTests->addChild(createOpConstantCompositeTests(testCtx));
9465 graphicsTests->addChild(createMemoryAccessTests(testCtx));
9466 graphicsTests->addChild(createOpUndefTests(testCtx));
9467 graphicsTests->addChild(createSelectionBlockOrderTests(testCtx));
9468 graphicsTests->addChild(createModuleTests(testCtx));
9469 graphicsTests->addChild(createSwitchBlockOrderTests(testCtx));
9470 graphicsTests->addChild(createOpPhiTests(testCtx));
9471 graphicsTests->addChild(createNoContractionTests(testCtx));
9472 graphicsTests->addChild(createOpQuantizeTests(testCtx));
9473 graphicsTests->addChild(createLoopTests(testCtx));
9474 graphicsTests->addChild(createSpecConstantTests(testCtx));
9475 graphicsTests->addChild(createSpecConstantOpQuantizeToF16Group(testCtx));
9476 graphicsTests->addChild(createBarrierTests(testCtx));
9477 graphicsTests->addChild(createDecorationGroupTests(testCtx));
9478 graphicsTests->addChild(createFRemTests(testCtx));
9479 graphicsTests->addChild(createOpSRemGraphicsTests(testCtx, QP_TEST_RESULT_PASS));
9480 graphicsTests->addChild(createOpSModGraphicsTests(testCtx, QP_TEST_RESULT_PASS));
9483 de::MovePtr<tcu::TestCaseGroup> graphicsAndroidTests (new tcu::TestCaseGroup(testCtx, "android", "Android CTS Tests"));
9485 graphicsAndroidTests->addChild(createOpSRemGraphicsTests(testCtx, QP_TEST_RESULT_QUALITY_WARNING));
9486 graphicsAndroidTests->addChild(createOpSModGraphicsTests(testCtx, QP_TEST_RESULT_QUALITY_WARNING));
9488 graphicsTests->addChild(graphicsAndroidTests.release());
9490 graphicsTests->addChild(createOpNameTests(testCtx));
9492 graphicsTests->addChild(create8BitStorageGraphicsGroup(testCtx));
9493 graphicsTests->addChild(create16BitStorageGraphicsGroup(testCtx));
9494 graphicsTests->addChild(createUboMatrixPaddingGraphicsGroup(testCtx));
9495 graphicsTests->addChild(createVariableInitGraphicsGroup(testCtx));
9496 graphicsTests->addChild(createConditionalBranchGraphicsGroup(testCtx));
9497 graphicsTests->addChild(createIndexingGraphicsGroup(testCtx));
9498 graphicsTests->addChild(createVariablePointersGraphicsGroup(testCtx));
9499 graphicsTests->addChild(createImageSamplerGraphicsGroup(testCtx));
9500 graphicsTests->addChild(createConvertGraphicsTests(testCtx, "OpSConvert", "sconvert"));
9501 graphicsTests->addChild(createConvertGraphicsTests(testCtx, "OpUConvert", "uconvert"));
9502 graphicsTests->addChild(createConvertGraphicsTests(testCtx, "OpFConvert", "fconvert"));
9504 instructionTests->addChild(computeTests.release());
9505 instructionTests->addChild(graphicsTests.release());
9507 return instructionTests.release();