1 /*-------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
5 * Copyright (c) 2015 Google Inc.
6 * Copyright (c) 2016 The Khronos Group Inc.
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
22 * \brief SPIR-V Assembly Tests for Instructions (special opcode/operand)
23 *//*--------------------------------------------------------------------*/
25 #include "vktSpvAsmInstructionTests.hpp"
27 #include "tcuCommandLine.hpp"
28 #include "tcuFormatUtil.hpp"
29 #include "tcuFloat.hpp"
30 #include "tcuFloatFormat.hpp"
31 #include "tcuRGBA.hpp"
32 #include "tcuStringTemplate.hpp"
33 #include "tcuTestLog.hpp"
34 #include "tcuVectorUtil.hpp"
35 #include "tcuInterval.hpp"
38 #include "vkDeviceUtil.hpp"
39 #include "vkMemUtil.hpp"
40 #include "vkPlatform.hpp"
41 #include "vkPrograms.hpp"
42 #include "vkQueryUtil.hpp"
44 #include "vkRefUtil.hpp"
45 #include "vkStrUtil.hpp"
46 #include "vkTypeUtil.hpp"
48 #include "deStringUtil.hpp"
49 #include "deUniquePtr.hpp"
51 #include "tcuStringTemplate.hpp"
53 #include "vktSpvAsmCrossStageInterfaceTests.hpp"
54 #include "vktSpvAsm8bitStorageTests.hpp"
55 #include "vktSpvAsm16bitStorageTests.hpp"
56 #include "vktSpvAsmUboMatrixPaddingTests.hpp"
57 #include "vktSpvAsmConditionalBranchTests.hpp"
58 #include "vktSpvAsmIndexingTests.hpp"
59 #include "vktSpvAsmImageSamplerTests.hpp"
60 #include "vktSpvAsmComputeShaderCase.hpp"
61 #include "vktSpvAsmComputeShaderTestUtil.hpp"
62 #include "vktSpvAsmFloatControlsTests.hpp"
63 #include "vktSpvAsmGraphicsShaderTestUtil.hpp"
64 #include "vktSpvAsmVariablePointersTests.hpp"
65 #include "vktSpvAsmVariableInitTests.hpp"
66 #include "vktSpvAsmPointerParameterTests.hpp"
67 #include "vktSpvAsmSpirvVersionTests.hpp"
68 #include "vktTestCaseUtil.hpp"
69 #include "vktSpvAsmLoopDepLenTests.hpp"
70 #include "vktSpvAsmLoopDepInfTests.hpp"
82 namespace SpirVAssembly
96 using tcu::TestStatus;
99 using tcu::StringTemplate;
102 const bool TEST_WITHOUT_NAN = false;
105 static void fillRandomScalars (de::Random& rnd, T minValue, T maxValue, void* dst, int numValues, int offset = 0)
107 T* const typedPtr = (T*)dst;
108 for (int ndx = 0; ndx < numValues; ndx++)
109 typedPtr[offset + ndx] = randomScalar<T>(rnd, minValue, maxValue);
112 // Filter is a function that returns true if a value should pass, false otherwise.
113 template<typename T, typename FilterT>
114 static void fillRandomScalars (de::Random& rnd, T minValue, T maxValue, void* dst, int numValues, FilterT filter, int offset = 0)
116 T* const typedPtr = (T*)dst;
118 for (int ndx = 0; ndx < numValues; ndx++)
121 value = randomScalar<T>(rnd, minValue, maxValue);
122 while (!filter(value));
124 typedPtr[offset + ndx] = value;
128 // Gets a 64-bit integer with a more logarithmic distribution
129 deInt64 randomInt64LogDistributed (de::Random& rnd)
131 deInt64 val = rnd.getUint64();
132 val &= (1ull << rnd.getInt(1, 63)) - 1;
138 static void fillRandomInt64sLogDistributed (de::Random& rnd, vector<deInt64>& dst, int numValues)
140 for (int ndx = 0; ndx < numValues; ndx++)
141 dst[ndx] = randomInt64LogDistributed(rnd);
144 template<typename FilterT>
145 static void fillRandomInt64sLogDistributed (de::Random& rnd, vector<deInt64>& dst, int numValues, FilterT filter)
147 for (int ndx = 0; ndx < numValues; ndx++)
151 value = randomInt64LogDistributed(rnd);
152 } while (!filter(value));
157 inline bool filterNonNegative (const deInt64 value)
162 inline bool filterPositive (const deInt64 value)
167 inline bool filterNotZero (const deInt64 value)
172 static void floorAll (vector<float>& values)
174 for (size_t i = 0; i < values.size(); i++)
175 values[i] = deFloatFloor(values[i]);
178 static void floorAll (vector<Vec4>& values)
180 for (size_t i = 0; i < values.size(); i++)
181 values[i] = floor(values[i]);
189 CaseParameter (const char* case_, const string& param_) : name(case_), param(param_) {}
192 // Assembly code used for testing LocalSize, OpNop, OpConstant{Null|Composite}, Op[No]Line, OpSource[Continued], OpSourceExtension, OpUndef is based on GLSL source code:
196 // layout(std140, set = 0, binding = 0) readonly buffer Input {
199 // layout(std140, set = 0, binding = 1) writeonly buffer Output {
203 // layout (local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
206 // uint x = gl_GlobalInvocationID.x;
207 // output_data.elements[x] = -input_data.elements[x];
210 static string getAsmForLocalSizeTest(bool useLiteralLocalSize, bool useSpecConstantWorkgroupSize, IVec3 workGroupSize, deUint32 ndx)
212 std::ostringstream out;
213 out << getComputeAsmShaderPreambleWithoutLocalSize();
215 if (useLiteralLocalSize)
217 out << "OpExecutionMode %main LocalSize "
218 << workGroupSize.x() << " " << workGroupSize.y() << " " << workGroupSize.z() << "\n";
221 out << "OpSource GLSL 430\n"
222 "OpName %main \"main\"\n"
223 "OpName %id \"gl_GlobalInvocationID\"\n"
224 "OpDecorate %id BuiltIn GlobalInvocationId\n";
226 if (useSpecConstantWorkgroupSize)
228 out << "OpDecorate %spec_0 SpecId 100\n"
229 << "OpDecorate %spec_1 SpecId 101\n"
230 << "OpDecorate %spec_2 SpecId 102\n"
231 << "OpDecorate %gl_WorkGroupSize BuiltIn WorkgroupSize\n";
234 out << getComputeAsmInputOutputBufferTraits()
235 << getComputeAsmCommonTypes()
236 << getComputeAsmInputOutputBuffer()
237 << "%id = OpVariable %uvec3ptr Input\n"
238 << "%zero = OpConstant %i32 0 \n";
240 if (useSpecConstantWorkgroupSize)
242 out << "%spec_0 = OpSpecConstant %u32 "<< workGroupSize.x() << "\n"
243 << "%spec_1 = OpSpecConstant %u32 "<< workGroupSize.y() << "\n"
244 << "%spec_2 = OpSpecConstant %u32 "<< workGroupSize.z() << "\n"
245 << "%gl_WorkGroupSize = OpSpecConstantComposite %uvec3 %spec_0 %spec_1 %spec_2\n";
248 out << "%main = OpFunction %void None %voidf\n"
249 << "%label = OpLabel\n"
250 << "%idval = OpLoad %uvec3 %id\n"
251 << "%ndx = OpCompositeExtract %u32 %idval " << ndx << "\n"
253 "%inloc = OpAccessChain %f32ptr %indata %zero %ndx\n"
254 "%inval = OpLoad %f32 %inloc\n"
255 "%neg = OpFNegate %f32 %inval\n"
256 "%outloc = OpAccessChain %f32ptr %outdata %zero %ndx\n"
257 " OpStore %outloc %neg\n"
263 tcu::TestCaseGroup* createLocalSizeGroup (tcu::TestContext& testCtx)
265 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "localsize", ""));
266 ComputeShaderSpec spec;
267 de::Random rnd (deStringHash(group->getName()));
268 const deUint32 numElements = 64u;
269 vector<float> positiveFloats (numElements, 0);
270 vector<float> negativeFloats (numElements, 0);
272 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
274 for (size_t ndx = 0; ndx < numElements; ++ndx)
275 negativeFloats[ndx] = -positiveFloats[ndx];
277 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
278 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
280 spec.numWorkGroups = IVec3(numElements, 1, 1);
282 spec.assembly = getAsmForLocalSizeTest(true, false, IVec3(1, 1, 1), 0u);
283 group->addChild(new SpvAsmComputeShaderCase(testCtx, "literal_localsize", "", spec));
285 spec.assembly = getAsmForLocalSizeTest(true, true, IVec3(1, 1, 1), 0u);
286 group->addChild(new SpvAsmComputeShaderCase(testCtx, "literal_and_specid_localsize", "", spec));
288 spec.assembly = getAsmForLocalSizeTest(false, true, IVec3(1, 1, 1), 0u);
289 group->addChild(new SpvAsmComputeShaderCase(testCtx, "specid_localsize", "", spec));
291 spec.numWorkGroups = IVec3(1, 1, 1);
293 spec.assembly = getAsmForLocalSizeTest(true, false, IVec3(numElements, 1, 1), 0u);
294 group->addChild(new SpvAsmComputeShaderCase(testCtx, "literal_localsize_x", "", spec));
296 spec.assembly = getAsmForLocalSizeTest(true, true, IVec3(numElements, 1, 1), 0u);
297 group->addChild(new SpvAsmComputeShaderCase(testCtx, "literal_and_specid_localsize_x", "", spec));
299 spec.assembly = getAsmForLocalSizeTest(false, true, IVec3(numElements, 1, 1), 0u);
300 group->addChild(new SpvAsmComputeShaderCase(testCtx, "specid_localsize_x", "", spec));
302 spec.assembly = getAsmForLocalSizeTest(true, false, IVec3(1, numElements, 1), 1u);
303 group->addChild(new SpvAsmComputeShaderCase(testCtx, "literal_localsize_y", "", spec));
305 spec.assembly = getAsmForLocalSizeTest(true, true, IVec3(1, numElements, 1), 1u);
306 group->addChild(new SpvAsmComputeShaderCase(testCtx, "literal_and_specid_localsize_y", "", spec));
308 spec.assembly = getAsmForLocalSizeTest(false, true, IVec3(1, numElements, 1), 1u);
309 group->addChild(new SpvAsmComputeShaderCase(testCtx, "specid_localsize_y", "", spec));
311 spec.assembly = getAsmForLocalSizeTest(true, false, IVec3(1, 1, numElements), 2u);
312 group->addChild(new SpvAsmComputeShaderCase(testCtx, "literal_localsize_z", "", spec));
314 spec.assembly = getAsmForLocalSizeTest(true, true, IVec3(1, 1, numElements), 2u);
315 group->addChild(new SpvAsmComputeShaderCase(testCtx, "literal_and_specid_localsize_z", "", spec));
317 spec.assembly = getAsmForLocalSizeTest(false, true, IVec3(1, 1, numElements), 2u);
318 group->addChild(new SpvAsmComputeShaderCase(testCtx, "specid_localsize_z", "", spec));
320 return group.release();
323 tcu::TestCaseGroup* createOpNopGroup (tcu::TestContext& testCtx)
325 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opnop", "Test the OpNop instruction"));
326 ComputeShaderSpec spec;
327 de::Random rnd (deStringHash(group->getName()));
328 const int numElements = 100;
329 vector<float> positiveFloats (numElements, 0);
330 vector<float> negativeFloats (numElements, 0);
332 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
334 for (size_t ndx = 0; ndx < numElements; ++ndx)
335 negativeFloats[ndx] = -positiveFloats[ndx];
338 string(getComputeAsmShaderPreamble()) +
340 "OpSource GLSL 430\n"
341 "OpName %main \"main\"\n"
342 "OpName %id \"gl_GlobalInvocationID\"\n"
344 "OpDecorate %id BuiltIn GlobalInvocationId\n"
346 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes())
348 + string(getComputeAsmInputOutputBuffer()) +
350 "%id = OpVariable %uvec3ptr Input\n"
351 "%zero = OpConstant %i32 0\n"
353 "%main = OpFunction %void None %voidf\n"
355 "%idval = OpLoad %uvec3 %id\n"
356 "%x = OpCompositeExtract %u32 %idval 0\n"
358 " OpNop\n" // Inside a function body
360 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
361 "%inval = OpLoad %f32 %inloc\n"
362 "%neg = OpFNegate %f32 %inval\n"
363 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
364 " OpStore %outloc %neg\n"
367 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
368 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
369 spec.numWorkGroups = IVec3(numElements, 1, 1);
371 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "OpNop appearing at different places", spec));
373 return group.release();
376 bool compareFUnord (const std::vector<Resource>& inputs, const vector<AllocationSp>& outputAllocs, const std::vector<Resource>& expectedOutputs, TestLog& log)
378 if (outputAllocs.size() != 1)
381 vector<deUint8> input1Bytes;
382 vector<deUint8> input2Bytes;
383 vector<deUint8> expectedBytes;
385 inputs[0].getBytes(input1Bytes);
386 inputs[1].getBytes(input2Bytes);
387 expectedOutputs[0].getBytes(expectedBytes);
389 const deInt32* const expectedOutputAsInt = reinterpret_cast<const deInt32*>(&expectedBytes.front());
390 const deInt32* const outputAsInt = static_cast<const deInt32*>(outputAllocs[0]->getHostPtr());
391 const float* const input1AsFloat = reinterpret_cast<const float*>(&input1Bytes.front());
392 const float* const input2AsFloat = reinterpret_cast<const float*>(&input2Bytes.front());
393 bool returnValue = true;
395 for (size_t idx = 0; idx < expectedBytes.size() / sizeof(deInt32); ++idx)
397 if (outputAsInt[idx] != expectedOutputAsInt[idx])
399 log << TestLog::Message << "ERROR: Sub-case failed. inputs: " << input1AsFloat[idx] << "," << input2AsFloat[idx] << " output: " << outputAsInt[idx]<< " expected output: " << expectedOutputAsInt[idx] << TestLog::EndMessage;
406 typedef VkBool32 (*compareFuncType) (float, float);
412 compareFuncType compareFunc;
414 OpFUnordCase (const char* _name, const char* _opCode, compareFuncType _compareFunc)
417 , compareFunc (_compareFunc) {}
420 #define ADD_OPFUNORD_CASE(NAME, OPCODE, OPERATOR) \
422 struct compare_##NAME { static VkBool32 compare(float x, float y) { return (x OPERATOR y) ? VK_TRUE : VK_FALSE; } }; \
423 cases.push_back(OpFUnordCase(#NAME, OPCODE, compare_##NAME::compare)); \
424 } while (deGetFalse())
426 tcu::TestCaseGroup* createOpFUnordGroup (tcu::TestContext& testCtx)
428 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opfunord", "Test the OpFUnord* opcodes"));
429 de::Random rnd (deStringHash(group->getName()));
430 const int numElements = 100;
431 vector<OpFUnordCase> cases;
433 const StringTemplate shaderTemplate (
435 string(getComputeAsmShaderPreamble()) +
437 "OpSource GLSL 430\n"
438 "OpName %main \"main\"\n"
439 "OpName %id \"gl_GlobalInvocationID\"\n"
441 "OpDecorate %id BuiltIn GlobalInvocationId\n"
443 "OpDecorate %buf BufferBlock\n"
444 "OpDecorate %buf2 BufferBlock\n"
445 "OpDecorate %indata1 DescriptorSet 0\n"
446 "OpDecorate %indata1 Binding 0\n"
447 "OpDecorate %indata2 DescriptorSet 0\n"
448 "OpDecorate %indata2 Binding 1\n"
449 "OpDecorate %outdata DescriptorSet 0\n"
450 "OpDecorate %outdata Binding 2\n"
451 "OpDecorate %f32arr ArrayStride 4\n"
452 "OpDecorate %i32arr ArrayStride 4\n"
453 "OpMemberDecorate %buf 0 Offset 0\n"
454 "OpMemberDecorate %buf2 0 Offset 0\n"
456 + string(getComputeAsmCommonTypes()) +
458 "%buf = OpTypeStruct %f32arr\n"
459 "%bufptr = OpTypePointer Uniform %buf\n"
460 "%indata1 = OpVariable %bufptr Uniform\n"
461 "%indata2 = OpVariable %bufptr Uniform\n"
463 "%buf2 = OpTypeStruct %i32arr\n"
464 "%buf2ptr = OpTypePointer Uniform %buf2\n"
465 "%outdata = OpVariable %buf2ptr Uniform\n"
467 "%id = OpVariable %uvec3ptr Input\n"
468 "%zero = OpConstant %i32 0\n"
469 "%consti1 = OpConstant %i32 1\n"
470 "%constf1 = OpConstant %f32 1.0\n"
472 "%main = OpFunction %void None %voidf\n"
474 "%idval = OpLoad %uvec3 %id\n"
475 "%x = OpCompositeExtract %u32 %idval 0\n"
477 "%inloc1 = OpAccessChain %f32ptr %indata1 %zero %x\n"
478 "%inval1 = OpLoad %f32 %inloc1\n"
479 "%inloc2 = OpAccessChain %f32ptr %indata2 %zero %x\n"
480 "%inval2 = OpLoad %f32 %inloc2\n"
481 "%outloc = OpAccessChain %i32ptr %outdata %zero %x\n"
483 "%result = ${OPCODE} %bool %inval1 %inval2\n"
484 "%int_res = OpSelect %i32 %result %consti1 %zero\n"
485 " OpStore %outloc %int_res\n"
490 ADD_OPFUNORD_CASE(equal, "OpFUnordEqual", ==);
491 ADD_OPFUNORD_CASE(less, "OpFUnordLessThan", <);
492 ADD_OPFUNORD_CASE(lessequal, "OpFUnordLessThanEqual", <=);
493 ADD_OPFUNORD_CASE(greater, "OpFUnordGreaterThan", >);
494 ADD_OPFUNORD_CASE(greaterequal, "OpFUnordGreaterThanEqual", >=);
495 ADD_OPFUNORD_CASE(notequal, "OpFUnordNotEqual", !=);
497 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
499 map<string, string> specializations;
500 ComputeShaderSpec spec;
501 const float NaN = std::numeric_limits<float>::quiet_NaN();
502 vector<float> inputFloats1 (numElements, 0);
503 vector<float> inputFloats2 (numElements, 0);
504 vector<deInt32> expectedInts (numElements, 0);
506 specializations["OPCODE"] = cases[caseNdx].opCode;
507 spec.assembly = shaderTemplate.specialize(specializations);
509 fillRandomScalars(rnd, 1.f, 100.f, &inputFloats1[0], numElements);
510 for (size_t ndx = 0; ndx < numElements; ++ndx)
514 case 0: inputFloats2[ndx] = inputFloats1[ndx] + 1.0f; break;
515 case 1: inputFloats2[ndx] = inputFloats1[ndx] - 1.0f; break;
516 case 2: inputFloats2[ndx] = inputFloats1[ndx]; break;
517 case 3: inputFloats2[ndx] = NaN; break;
518 case 4: inputFloats2[ndx] = inputFloats1[ndx]; inputFloats1[ndx] = NaN; break;
519 case 5: inputFloats2[ndx] = NaN; inputFloats1[ndx] = NaN; break;
521 expectedInts[ndx] = tcu::Float32(inputFloats1[ndx]).isNaN() || tcu::Float32(inputFloats2[ndx]).isNaN() || cases[caseNdx].compareFunc(inputFloats1[ndx], inputFloats2[ndx]);
524 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats1)));
525 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
526 spec.outputs.push_back(BufferSp(new Int32Buffer(expectedInts)));
527 spec.numWorkGroups = IVec3(numElements, 1, 1);
528 spec.verifyIO = &compareFUnord;
529 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
532 return group.release();
538 const char* assembly;
539 const char* retValAssembly;
540 OpAtomicType opAtomic;
541 deInt32 numOutputElements;
543 OpAtomicCase(const char* _name, const char* _assembly, const char* _retValAssembly, OpAtomicType _opAtomic, deInt32 _numOutputElements)
545 , assembly (_assembly)
546 , retValAssembly (_retValAssembly)
547 , opAtomic (_opAtomic)
548 , numOutputElements (_numOutputElements) {}
551 tcu::TestCaseGroup* createOpAtomicGroup (tcu::TestContext& testCtx, bool useStorageBuffer, int numElements = 65535, bool verifyReturnValues = false)
553 std::string groupName ("opatomic");
554 if (useStorageBuffer)
555 groupName += "_storage_buffer";
556 if (verifyReturnValues)
557 groupName += "_return_values";
558 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, groupName.c_str(), "Test the OpAtomic* opcodes"));
559 vector<OpAtomicCase> cases;
561 const StringTemplate shaderTemplate (
563 string("OpCapability Shader\n") +
564 (useStorageBuffer ? "OpExtension \"SPV_KHR_storage_buffer_storage_class\"\n" : "") +
565 "OpMemoryModel Logical GLSL450\n"
566 "OpEntryPoint GLCompute %main \"main\" %id\n"
567 "OpExecutionMode %main LocalSize 1 1 1\n" +
569 "OpSource GLSL 430\n"
570 "OpName %main \"main\"\n"
571 "OpName %id \"gl_GlobalInvocationID\"\n"
573 "OpDecorate %id BuiltIn GlobalInvocationId\n"
575 "OpDecorate %buf ${BLOCK_DECORATION}\n"
576 "OpDecorate %indata DescriptorSet 0\n"
577 "OpDecorate %indata Binding 0\n"
578 "OpDecorate %i32arr ArrayStride 4\n"
579 "OpMemberDecorate %buf 0 Offset 0\n"
581 "OpDecorate %sumbuf ${BLOCK_DECORATION}\n"
582 "OpDecorate %sum DescriptorSet 0\n"
583 "OpDecorate %sum Binding 1\n"
584 "OpMemberDecorate %sumbuf 0 Coherent\n"
585 "OpMemberDecorate %sumbuf 0 Offset 0\n"
587 "${RETVAL_BUF_DECORATE}"
589 + getComputeAsmCommonTypes("${BLOCK_POINTER_TYPE}") +
591 "%buf = OpTypeStruct %i32arr\n"
592 "%bufptr = OpTypePointer ${BLOCK_POINTER_TYPE} %buf\n"
593 "%indata = OpVariable %bufptr ${BLOCK_POINTER_TYPE}\n"
595 "%sumbuf = OpTypeStruct %i32arr\n"
596 "%sumbufptr = OpTypePointer ${BLOCK_POINTER_TYPE} %sumbuf\n"
597 "%sum = OpVariable %sumbufptr ${BLOCK_POINTER_TYPE}\n"
601 "%id = OpVariable %uvec3ptr Input\n"
602 "%minusone = OpConstant %i32 -1\n"
603 "%zero = OpConstant %i32 0\n"
604 "%one = OpConstant %u32 1\n"
605 "%two = OpConstant %i32 2\n"
607 "%main = OpFunction %void None %voidf\n"
609 "%idval = OpLoad %uvec3 %id\n"
610 "%x = OpCompositeExtract %u32 %idval 0\n"
612 "%inloc = OpAccessChain %i32ptr %indata %zero %x\n"
613 "%inval = OpLoad %i32 %inloc\n"
615 "%outloc = OpAccessChain %i32ptr %sum %zero ${INDEX}\n"
622 #define ADD_OPATOMIC_CASE(NAME, ASSEMBLY, RETVAL_ASSEMBLY, OPATOMIC, NUM_OUTPUT_ELEMENTS) \
624 DE_ASSERT((NUM_OUTPUT_ELEMENTS) == 1 || (NUM_OUTPUT_ELEMENTS) == numElements); \
625 cases.push_back(OpAtomicCase(#NAME, ASSEMBLY, RETVAL_ASSEMBLY, OPATOMIC, NUM_OUTPUT_ELEMENTS)); \
626 } while (deGetFalse())
627 #define ADD_OPATOMIC_CASE_1(NAME, ASSEMBLY, RETVAL_ASSEMBLY, OPATOMIC) ADD_OPATOMIC_CASE(NAME, ASSEMBLY, RETVAL_ASSEMBLY, OPATOMIC, 1)
628 #define ADD_OPATOMIC_CASE_N(NAME, ASSEMBLY, RETVAL_ASSEMBLY, OPATOMIC) ADD_OPATOMIC_CASE(NAME, ASSEMBLY, RETVAL_ASSEMBLY, OPATOMIC, numElements)
630 ADD_OPATOMIC_CASE_1(iadd, "%retv = OpAtomicIAdd %i32 %outloc %one %zero %inval\n",
631 " OpStore %retloc %retv\n", OPATOMIC_IADD );
632 ADD_OPATOMIC_CASE_1(isub, "%retv = OpAtomicISub %i32 %outloc %one %zero %inval\n",
633 " OpStore %retloc %retv\n", OPATOMIC_ISUB );
634 ADD_OPATOMIC_CASE_1(iinc, "%retv = OpAtomicIIncrement %i32 %outloc %one %zero\n",
635 " OpStore %retloc %retv\n", OPATOMIC_IINC );
636 ADD_OPATOMIC_CASE_1(idec, "%retv = OpAtomicIDecrement %i32 %outloc %one %zero\n",
637 " OpStore %retloc %retv\n", OPATOMIC_IDEC );
638 if (!verifyReturnValues)
640 ADD_OPATOMIC_CASE_N(load, "%inval2 = OpAtomicLoad %i32 %inloc %one %zero\n"
641 " OpStore %outloc %inval2\n", "", OPATOMIC_LOAD );
642 ADD_OPATOMIC_CASE_N(store, " OpAtomicStore %outloc %one %zero %inval\n", "", OPATOMIC_STORE );
645 ADD_OPATOMIC_CASE_N(compex, "%even = OpSMod %i32 %inval %two\n"
646 " OpStore %outloc %even\n"
647 "%retv = OpAtomicCompareExchange %i32 %outloc %one %zero %zero %minusone %zero\n",
648 " OpStore %retloc %retv\n", OPATOMIC_COMPEX );
651 #undef ADD_OPATOMIC_CASE
652 #undef ADD_OPATOMIC_CASE_1
653 #undef ADD_OPATOMIC_CASE_N
655 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
657 map<string, string> specializations;
658 ComputeShaderSpec spec;
659 vector<deInt32> inputInts (numElements, 0);
660 vector<deInt32> expected (cases[caseNdx].numOutputElements, -1);
662 specializations["INDEX"] = (cases[caseNdx].numOutputElements == 1) ? "%zero" : "%x";
663 specializations["INSTRUCTION"] = cases[caseNdx].assembly;
664 specializations["BLOCK_DECORATION"] = useStorageBuffer ? "Block" : "BufferBlock";
665 specializations["BLOCK_POINTER_TYPE"] = useStorageBuffer ? "StorageBuffer" : "Uniform";
667 if (verifyReturnValues)
669 const StringTemplate blockDecoration (
671 "OpDecorate %retbuf ${BLOCK_DECORATION}\n"
672 "OpDecorate %ret DescriptorSet 0\n"
673 "OpDecorate %ret Binding 2\n"
674 "OpMemberDecorate %retbuf 0 Offset 0\n\n");
676 const StringTemplate blockDeclaration (
678 "%retbuf = OpTypeStruct %i32arr\n"
679 "%retbufptr = OpTypePointer ${BLOCK_POINTER_TYPE} %retbuf\n"
680 "%ret = OpVariable %retbufptr ${BLOCK_POINTER_TYPE}\n\n");
682 specializations["RETVAL_ASSEMBLY"] =
683 "%retloc = OpAccessChain %i32ptr %ret %zero %x\n"
684 + std::string(cases[caseNdx].retValAssembly);
686 specializations["RETVAL_BUF_DECORATE"] = blockDecoration.specialize(specializations);
687 specializations["RETVAL_BUF_DECL"] = blockDeclaration.specialize(specializations);
691 specializations["RETVAL_ASSEMBLY"] = "";
692 specializations["RETVAL_BUF_DECORATE"] = "";
693 specializations["RETVAL_BUF_DECL"] = "";
696 spec.assembly = shaderTemplate.specialize(specializations);
698 if (useStorageBuffer)
699 spec.extensions.push_back("VK_KHR_storage_buffer_storage_class");
701 spec.inputs.push_back(BufferSp(new OpAtomicBuffer(numElements, cases[caseNdx].numOutputElements, cases[caseNdx].opAtomic, BUFFERTYPE_INPUT)));
702 spec.outputs.push_back(BufferSp(new OpAtomicBuffer(numElements, cases[caseNdx].numOutputElements, cases[caseNdx].opAtomic, BUFFERTYPE_EXPECTED)));
703 if (verifyReturnValues)
704 spec.outputs.push_back(BufferSp(new OpAtomicBuffer(numElements, cases[caseNdx].numOutputElements, cases[caseNdx].opAtomic, BUFFERTYPE_ATOMIC_RET)));
705 spec.numWorkGroups = IVec3(numElements, 1, 1);
707 if (verifyReturnValues)
709 switch (cases[caseNdx].opAtomic)
712 spec.verifyIO = OpAtomicBuffer::compareWithRetvals<OPATOMIC_IADD>;
715 spec.verifyIO = OpAtomicBuffer::compareWithRetvals<OPATOMIC_ISUB>;
718 spec.verifyIO = OpAtomicBuffer::compareWithRetvals<OPATOMIC_IINC>;
721 spec.verifyIO = OpAtomicBuffer::compareWithRetvals<OPATOMIC_IDEC>;
723 case OPATOMIC_COMPEX:
724 spec.verifyIO = OpAtomicBuffer::compareWithRetvals<OPATOMIC_COMPEX>;
727 DE_FATAL("Unsupported OpAtomic type for return value verification");
730 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
733 return group.release();
736 tcu::TestCaseGroup* createOpLineGroup (tcu::TestContext& testCtx)
738 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opline", "Test the OpLine instruction"));
739 ComputeShaderSpec spec;
740 de::Random rnd (deStringHash(group->getName()));
741 const int numElements = 100;
742 vector<float> positiveFloats (numElements, 0);
743 vector<float> negativeFloats (numElements, 0);
745 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
747 for (size_t ndx = 0; ndx < numElements; ++ndx)
748 negativeFloats[ndx] = -positiveFloats[ndx];
751 string(getComputeAsmShaderPreamble()) +
753 "%fname1 = OpString \"negateInputs.comp\"\n"
754 "%fname2 = OpString \"negateInputs\"\n"
756 "OpSource GLSL 430\n"
757 "OpName %main \"main\"\n"
758 "OpName %id \"gl_GlobalInvocationID\"\n"
760 "OpDecorate %id BuiltIn GlobalInvocationId\n"
762 + string(getComputeAsmInputOutputBufferTraits()) +
764 "OpLine %fname1 0 0\n" // At the earliest possible position
766 + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
768 "OpLine %fname1 0 1\n" // Multiple OpLines in sequence
769 "OpLine %fname2 1 0\n" // Different filenames
770 "OpLine %fname1 1000 100000\n"
772 "%id = OpVariable %uvec3ptr Input\n"
773 "%zero = OpConstant %i32 0\n"
775 "OpLine %fname1 1 1\n" // Before a function
777 "%main = OpFunction %void None %voidf\n"
780 "OpLine %fname1 1 1\n" // In a function
782 "%idval = OpLoad %uvec3 %id\n"
783 "%x = OpCompositeExtract %u32 %idval 0\n"
784 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
785 "%inval = OpLoad %f32 %inloc\n"
786 "%neg = OpFNegate %f32 %inval\n"
787 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
788 " OpStore %outloc %neg\n"
791 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
792 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
793 spec.numWorkGroups = IVec3(numElements, 1, 1);
795 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "OpLine appearing at different places", spec));
797 return group.release();
800 bool veryfiBinaryShader (const ProgramBinary& binary)
802 const size_t paternCount = 3u;
803 bool paternsCheck[paternCount] =
807 const string patersns[paternCount] =
813 size_t paternNdx = 0u;
815 for (size_t ndx = 0u; ndx < binary.getSize(); ++ndx)
817 if (false == paternsCheck[paternNdx] &&
818 patersns[paternNdx][0] == static_cast<char>(binary.getBinary()[ndx]) &&
819 deMemoryEqual((const char*)&binary.getBinary()[ndx], &patersns[paternNdx][0], patersns[paternNdx].length()))
821 paternsCheck[paternNdx]= true;
823 if (paternNdx == paternCount)
828 for (size_t ndx = 0u; ndx < paternCount; ++ndx)
830 if (!paternsCheck[ndx])
837 tcu::TestCaseGroup* createOpModuleProcessedGroup (tcu::TestContext& testCtx)
839 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opmoduleprocessed", "Test the OpModuleProcessed instruction"));
840 ComputeShaderSpec spec;
841 de::Random rnd (deStringHash(group->getName()));
842 const int numElements = 10;
843 vector<float> positiveFloats (numElements, 0);
844 vector<float> negativeFloats (numElements, 0);
846 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
848 for (size_t ndx = 0; ndx < numElements; ++ndx)
849 negativeFloats[ndx] = -positiveFloats[ndx];
852 string(getComputeAsmShaderPreamble()) +
853 "%fname = OpString \"negateInputs.comp\"\n"
855 "OpSource GLSL 430\n"
856 "OpName %main \"main\"\n"
857 "OpName %id \"gl_GlobalInvocationID\"\n"
858 "OpModuleProcessed \"VULKAN CTS\"\n" //OpModuleProcessed;
859 "OpModuleProcessed \"Negative values\"\n"
860 "OpModuleProcessed \"Date: 2017/09/21\"\n"
861 "OpDecorate %id BuiltIn GlobalInvocationId\n"
863 + string(getComputeAsmInputOutputBufferTraits())
865 + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
867 "OpLine %fname 0 1\n"
869 "OpLine %fname 1000 1\n"
871 "%id = OpVariable %uvec3ptr Input\n"
872 "%zero = OpConstant %i32 0\n"
873 "%main = OpFunction %void None %voidf\n"
876 "%idval = OpLoad %uvec3 %id\n"
877 "%x = OpCompositeExtract %u32 %idval 0\n"
879 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
880 "%inval = OpLoad %f32 %inloc\n"
881 "%neg = OpFNegate %f32 %inval\n"
882 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
883 " OpStore %outloc %neg\n"
886 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
887 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
888 spec.numWorkGroups = IVec3(numElements, 1, 1);
889 spec.verifyBinary = veryfiBinaryShader;
890 spec.spirvVersion = SPIRV_VERSION_1_3;
892 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "OpModuleProcessed Tests", spec));
894 return group.release();
897 tcu::TestCaseGroup* createOpNoLineGroup (tcu::TestContext& testCtx)
899 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opnoline", "Test the OpNoLine instruction"));
900 ComputeShaderSpec spec;
901 de::Random rnd (deStringHash(group->getName()));
902 const int numElements = 100;
903 vector<float> positiveFloats (numElements, 0);
904 vector<float> negativeFloats (numElements, 0);
906 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
908 for (size_t ndx = 0; ndx < numElements; ++ndx)
909 negativeFloats[ndx] = -positiveFloats[ndx];
912 string(getComputeAsmShaderPreamble()) +
914 "%fname = OpString \"negateInputs.comp\"\n"
916 "OpSource GLSL 430\n"
917 "OpName %main \"main\"\n"
918 "OpName %id \"gl_GlobalInvocationID\"\n"
920 "OpDecorate %id BuiltIn GlobalInvocationId\n"
922 + string(getComputeAsmInputOutputBufferTraits()) +
924 "OpNoLine\n" // At the earliest possible position, without preceding OpLine
926 + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
928 "OpLine %fname 0 1\n"
929 "OpNoLine\n" // Immediately following a preceding OpLine
931 "OpLine %fname 1000 1\n"
933 "%id = OpVariable %uvec3ptr Input\n"
934 "%zero = OpConstant %i32 0\n"
936 "OpNoLine\n" // Contents after the previous OpLine
938 "%main = OpFunction %void None %voidf\n"
940 "%idval = OpLoad %uvec3 %id\n"
941 "%x = OpCompositeExtract %u32 %idval 0\n"
943 "OpNoLine\n" // Multiple OpNoLine
947 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
948 "%inval = OpLoad %f32 %inloc\n"
949 "%neg = OpFNegate %f32 %inval\n"
950 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
951 " OpStore %outloc %neg\n"
954 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
955 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
956 spec.numWorkGroups = IVec3(numElements, 1, 1);
958 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "OpNoLine appearing at different places", spec));
960 return group.release();
963 // Compare instruction for the contraction compute case.
964 // Returns true if the output is what is expected from the test case.
965 bool compareNoContractCase(const std::vector<Resource>&, const vector<AllocationSp>& outputAllocs, const std::vector<Resource>& expectedOutputs, TestLog&)
967 if (outputAllocs.size() != 1)
970 // Only size is needed because we are not comparing the exact values.
971 size_t byteSize = expectedOutputs[0].getByteSize();
973 const float* outputAsFloat = static_cast<const float*>(outputAllocs[0]->getHostPtr());
975 for(size_t i = 0; i < byteSize / sizeof(float); ++i) {
976 if (outputAsFloat[i] != 0.f &&
977 outputAsFloat[i] != -ldexp(1, -24)) {
985 tcu::TestCaseGroup* createNoContractionGroup (tcu::TestContext& testCtx)
987 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "nocontraction", "Test the NoContraction decoration"));
988 vector<CaseParameter> cases;
989 const int numElements = 100;
990 vector<float> inputFloats1 (numElements, 0);
991 vector<float> inputFloats2 (numElements, 0);
992 vector<float> outputFloats (numElements, 0);
993 const StringTemplate shaderTemplate (
994 string(getComputeAsmShaderPreamble()) +
996 "OpName %main \"main\"\n"
997 "OpName %id \"gl_GlobalInvocationID\"\n"
999 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1003 "OpDecorate %buf BufferBlock\n"
1004 "OpDecorate %indata1 DescriptorSet 0\n"
1005 "OpDecorate %indata1 Binding 0\n"
1006 "OpDecorate %indata2 DescriptorSet 0\n"
1007 "OpDecorate %indata2 Binding 1\n"
1008 "OpDecorate %outdata DescriptorSet 0\n"
1009 "OpDecorate %outdata Binding 2\n"
1010 "OpDecorate %f32arr ArrayStride 4\n"
1011 "OpMemberDecorate %buf 0 Offset 0\n"
1013 + string(getComputeAsmCommonTypes()) +
1015 "%buf = OpTypeStruct %f32arr\n"
1016 "%bufptr = OpTypePointer Uniform %buf\n"
1017 "%indata1 = OpVariable %bufptr Uniform\n"
1018 "%indata2 = OpVariable %bufptr Uniform\n"
1019 "%outdata = OpVariable %bufptr Uniform\n"
1021 "%id = OpVariable %uvec3ptr Input\n"
1022 "%zero = OpConstant %i32 0\n"
1023 "%c_f_m1 = OpConstant %f32 -1.\n"
1025 "%main = OpFunction %void None %voidf\n"
1026 "%label = OpLabel\n"
1027 "%idval = OpLoad %uvec3 %id\n"
1028 "%x = OpCompositeExtract %u32 %idval 0\n"
1029 "%inloc1 = OpAccessChain %f32ptr %indata1 %zero %x\n"
1030 "%inval1 = OpLoad %f32 %inloc1\n"
1031 "%inloc2 = OpAccessChain %f32ptr %indata2 %zero %x\n"
1032 "%inval2 = OpLoad %f32 %inloc2\n"
1033 "%mul = OpFMul %f32 %inval1 %inval2\n"
1034 "%add = OpFAdd %f32 %mul %c_f_m1\n"
1035 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
1036 " OpStore %outloc %add\n"
1038 " OpFunctionEnd\n");
1040 cases.push_back(CaseParameter("multiplication", "OpDecorate %mul NoContraction"));
1041 cases.push_back(CaseParameter("addition", "OpDecorate %add NoContraction"));
1042 cases.push_back(CaseParameter("both", "OpDecorate %mul NoContraction\nOpDecorate %add NoContraction"));
1044 for (size_t ndx = 0; ndx < numElements; ++ndx)
1046 inputFloats1[ndx] = 1.f + std::ldexp(1.f, -23); // 1 + 2^-23.
1047 inputFloats2[ndx] = 1.f - std::ldexp(1.f, -23); // 1 - 2^-23.
1048 // Result for (1 + 2^-23) * (1 - 2^-23) - 1. With NoContraction, the multiplication will be
1049 // conducted separately and the result is rounded to 1, or 0x1.fffffcp-1
1050 // So the final result will be 0.f or 0x1p-24.
1051 // If the operation is combined into a precise fused multiply-add, then the result would be
1052 // 2^-46 (0xa8800000).
1053 outputFloats[ndx] = 0.f;
1056 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
1058 map<string, string> specializations;
1059 ComputeShaderSpec spec;
1061 specializations["DECORATION"] = cases[caseNdx].param;
1062 spec.assembly = shaderTemplate.specialize(specializations);
1063 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats1)));
1064 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
1065 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
1066 spec.numWorkGroups = IVec3(numElements, 1, 1);
1067 // Check against the two possible answers based on rounding mode.
1068 spec.verifyIO = &compareNoContractCase;
1070 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
1072 return group.release();
1075 bool compareFRem(const std::vector<Resource>&, const vector<AllocationSp>& outputAllocs, const std::vector<Resource>& expectedOutputs, TestLog&)
1077 if (outputAllocs.size() != 1)
1080 vector<deUint8> expectedBytes;
1081 expectedOutputs[0].getBytes(expectedBytes);
1083 const float* expectedOutputAsFloat = reinterpret_cast<const float*>(&expectedBytes.front());
1084 const float* outputAsFloat = static_cast<const float*>(outputAllocs[0]->getHostPtr());
1086 for (size_t idx = 0; idx < expectedBytes.size() / sizeof(float); ++idx)
1088 const float f0 = expectedOutputAsFloat[idx];
1089 const float f1 = outputAsFloat[idx];
1090 // \todo relative error needs to be fairly high because FRem may be implemented as
1091 // (roughly) frac(a/b)*b, so LSB errors can be magnified. But this should be fine for now.
1092 if (deFloatAbs((f1 - f0) / f0) > 0.02)
1099 tcu::TestCaseGroup* createOpFRemGroup (tcu::TestContext& testCtx)
1101 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opfrem", "Test the OpFRem instruction"));
1102 ComputeShaderSpec spec;
1103 de::Random rnd (deStringHash(group->getName()));
1104 const int numElements = 200;
1105 vector<float> inputFloats1 (numElements, 0);
1106 vector<float> inputFloats2 (numElements, 0);
1107 vector<float> outputFloats (numElements, 0);
1109 fillRandomScalars(rnd, -10000.f, 10000.f, &inputFloats1[0], numElements);
1110 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats2[0], numElements);
1112 for (size_t ndx = 0; ndx < numElements; ++ndx)
1114 // Guard against divisors near zero.
1115 if (std::fabs(inputFloats2[ndx]) < 1e-3)
1116 inputFloats2[ndx] = 8.f;
1118 // The return value of std::fmod() has the same sign as its first operand, which is how OpFRem spec'd.
1119 outputFloats[ndx] = std::fmod(inputFloats1[ndx], inputFloats2[ndx]);
1123 string(getComputeAsmShaderPreamble()) +
1125 "OpName %main \"main\"\n"
1126 "OpName %id \"gl_GlobalInvocationID\"\n"
1128 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1130 "OpDecorate %buf BufferBlock\n"
1131 "OpDecorate %indata1 DescriptorSet 0\n"
1132 "OpDecorate %indata1 Binding 0\n"
1133 "OpDecorate %indata2 DescriptorSet 0\n"
1134 "OpDecorate %indata2 Binding 1\n"
1135 "OpDecorate %outdata DescriptorSet 0\n"
1136 "OpDecorate %outdata Binding 2\n"
1137 "OpDecorate %f32arr ArrayStride 4\n"
1138 "OpMemberDecorate %buf 0 Offset 0\n"
1140 + string(getComputeAsmCommonTypes()) +
1142 "%buf = OpTypeStruct %f32arr\n"
1143 "%bufptr = OpTypePointer Uniform %buf\n"
1144 "%indata1 = OpVariable %bufptr Uniform\n"
1145 "%indata2 = OpVariable %bufptr Uniform\n"
1146 "%outdata = OpVariable %bufptr Uniform\n"
1148 "%id = OpVariable %uvec3ptr Input\n"
1149 "%zero = OpConstant %i32 0\n"
1151 "%main = OpFunction %void None %voidf\n"
1152 "%label = OpLabel\n"
1153 "%idval = OpLoad %uvec3 %id\n"
1154 "%x = OpCompositeExtract %u32 %idval 0\n"
1155 "%inloc1 = OpAccessChain %f32ptr %indata1 %zero %x\n"
1156 "%inval1 = OpLoad %f32 %inloc1\n"
1157 "%inloc2 = OpAccessChain %f32ptr %indata2 %zero %x\n"
1158 "%inval2 = OpLoad %f32 %inloc2\n"
1159 "%rem = OpFRem %f32 %inval1 %inval2\n"
1160 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
1161 " OpStore %outloc %rem\n"
1165 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats1)));
1166 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
1167 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
1168 spec.numWorkGroups = IVec3(numElements, 1, 1);
1169 spec.verifyIO = &compareFRem;
1171 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "", spec));
1173 return group.release();
1176 bool compareNMin (const std::vector<Resource>&, const vector<AllocationSp>& outputAllocs, const std::vector<Resource>& expectedOutputs, TestLog&)
1178 if (outputAllocs.size() != 1)
1181 const BufferSp& expectedOutput (expectedOutputs[0].getBuffer());
1182 std::vector<deUint8> data;
1183 expectedOutput->getBytes(data);
1185 const float* const expectedOutputAsFloat = reinterpret_cast<const float*>(&data.front());
1186 const float* const outputAsFloat = static_cast<const float*>(outputAllocs[0]->getHostPtr());
1188 for (size_t idx = 0; idx < expectedOutput->getByteSize() / sizeof(float); ++idx)
1190 const float f0 = expectedOutputAsFloat[idx];
1191 const float f1 = outputAsFloat[idx];
1193 // For NMin, we accept NaN as output if both inputs were NaN.
1194 // Otherwise the NaN is the wrong choise, as on architectures that
1195 // do not handle NaN, those are huge values.
1196 if (!(tcu::Float32(f1).isNaN() && tcu::Float32(f0).isNaN()) && deFloatAbs(f1 - f0) > 0.00001f)
1203 tcu::TestCaseGroup* createOpNMinGroup (tcu::TestContext& testCtx)
1205 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opnmin", "Test the OpNMin instruction"));
1206 ComputeShaderSpec spec;
1207 de::Random rnd (deStringHash(group->getName()));
1208 const int numElements = 200;
1209 vector<float> inputFloats1 (numElements, 0);
1210 vector<float> inputFloats2 (numElements, 0);
1211 vector<float> outputFloats (numElements, 0);
1213 fillRandomScalars(rnd, -10000.f, 10000.f, &inputFloats1[0], numElements);
1214 fillRandomScalars(rnd, -10000.f, 10000.f, &inputFloats2[0], numElements);
1216 // Make the first case a full-NAN case.
1217 inputFloats1[0] = TCU_NAN;
1218 inputFloats2[0] = TCU_NAN;
1220 for (size_t ndx = 0; ndx < numElements; ++ndx)
1222 // By default, pick the smallest
1223 outputFloats[ndx] = std::min(inputFloats1[ndx], inputFloats2[ndx]);
1225 // Make half of the cases NaN cases
1228 // Alternate between the NaN operand
1231 outputFloats[ndx] = inputFloats2[ndx];
1232 inputFloats1[ndx] = TCU_NAN;
1236 outputFloats[ndx] = inputFloats1[ndx];
1237 inputFloats2[ndx] = TCU_NAN;
1243 "OpCapability Shader\n"
1244 "%std450 = OpExtInstImport \"GLSL.std.450\"\n"
1245 "OpMemoryModel Logical GLSL450\n"
1246 "OpEntryPoint GLCompute %main \"main\" %id\n"
1247 "OpExecutionMode %main LocalSize 1 1 1\n"
1249 "OpName %main \"main\"\n"
1250 "OpName %id \"gl_GlobalInvocationID\"\n"
1252 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1254 "OpDecorate %buf BufferBlock\n"
1255 "OpDecorate %indata1 DescriptorSet 0\n"
1256 "OpDecorate %indata1 Binding 0\n"
1257 "OpDecorate %indata2 DescriptorSet 0\n"
1258 "OpDecorate %indata2 Binding 1\n"
1259 "OpDecorate %outdata DescriptorSet 0\n"
1260 "OpDecorate %outdata Binding 2\n"
1261 "OpDecorate %f32arr ArrayStride 4\n"
1262 "OpMemberDecorate %buf 0 Offset 0\n"
1264 + string(getComputeAsmCommonTypes()) +
1266 "%buf = OpTypeStruct %f32arr\n"
1267 "%bufptr = OpTypePointer Uniform %buf\n"
1268 "%indata1 = OpVariable %bufptr Uniform\n"
1269 "%indata2 = OpVariable %bufptr Uniform\n"
1270 "%outdata = OpVariable %bufptr Uniform\n"
1272 "%id = OpVariable %uvec3ptr Input\n"
1273 "%zero = OpConstant %i32 0\n"
1275 "%main = OpFunction %void None %voidf\n"
1276 "%label = OpLabel\n"
1277 "%idval = OpLoad %uvec3 %id\n"
1278 "%x = OpCompositeExtract %u32 %idval 0\n"
1279 "%inloc1 = OpAccessChain %f32ptr %indata1 %zero %x\n"
1280 "%inval1 = OpLoad %f32 %inloc1\n"
1281 "%inloc2 = OpAccessChain %f32ptr %indata2 %zero %x\n"
1282 "%inval2 = OpLoad %f32 %inloc2\n"
1283 "%rem = OpExtInst %f32 %std450 NMin %inval1 %inval2\n"
1284 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
1285 " OpStore %outloc %rem\n"
1289 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats1)));
1290 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
1291 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
1292 spec.numWorkGroups = IVec3(numElements, 1, 1);
1293 spec.verifyIO = &compareNMin;
1295 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "", spec));
1297 return group.release();
1300 bool compareNMax (const std::vector<Resource>&, const vector<AllocationSp>& outputAllocs, const std::vector<Resource>& expectedOutputs, TestLog&)
1302 if (outputAllocs.size() != 1)
1305 const BufferSp& expectedOutput = expectedOutputs[0].getBuffer();
1306 std::vector<deUint8> data;
1307 expectedOutput->getBytes(data);
1309 const float* const expectedOutputAsFloat = reinterpret_cast<const float*>(&data.front());
1310 const float* const outputAsFloat = static_cast<const float*>(outputAllocs[0]->getHostPtr());
1312 for (size_t idx = 0; idx < expectedOutput->getByteSize() / sizeof(float); ++idx)
1314 const float f0 = expectedOutputAsFloat[idx];
1315 const float f1 = outputAsFloat[idx];
1317 // For NMax, NaN is considered acceptable result, since in
1318 // architectures that do not handle NaNs, those are huge values.
1319 if (!tcu::Float32(f1).isNaN() && deFloatAbs(f1 - f0) > 0.00001f)
1326 tcu::TestCaseGroup* createOpNMaxGroup (tcu::TestContext& testCtx)
1328 de::MovePtr<tcu::TestCaseGroup> group(new tcu::TestCaseGroup(testCtx, "opnmax", "Test the OpNMax instruction"));
1329 ComputeShaderSpec spec;
1330 de::Random rnd (deStringHash(group->getName()));
1331 const int numElements = 200;
1332 vector<float> inputFloats1 (numElements, 0);
1333 vector<float> inputFloats2 (numElements, 0);
1334 vector<float> outputFloats (numElements, 0);
1336 fillRandomScalars(rnd, -10000.f, 10000.f, &inputFloats1[0], numElements);
1337 fillRandomScalars(rnd, -10000.f, 10000.f, &inputFloats2[0], numElements);
1339 // Make the first case a full-NAN case.
1340 inputFloats1[0] = TCU_NAN;
1341 inputFloats2[0] = TCU_NAN;
1343 for (size_t ndx = 0; ndx < numElements; ++ndx)
1345 // By default, pick the biggest
1346 outputFloats[ndx] = std::max(inputFloats1[ndx], inputFloats2[ndx]);
1348 // Make half of the cases NaN cases
1351 // Alternate between the NaN operand
1354 outputFloats[ndx] = inputFloats2[ndx];
1355 inputFloats1[ndx] = TCU_NAN;
1359 outputFloats[ndx] = inputFloats1[ndx];
1360 inputFloats2[ndx] = TCU_NAN;
1366 "OpCapability Shader\n"
1367 "%std450 = OpExtInstImport \"GLSL.std.450\"\n"
1368 "OpMemoryModel Logical GLSL450\n"
1369 "OpEntryPoint GLCompute %main \"main\" %id\n"
1370 "OpExecutionMode %main LocalSize 1 1 1\n"
1372 "OpName %main \"main\"\n"
1373 "OpName %id \"gl_GlobalInvocationID\"\n"
1375 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1377 "OpDecorate %buf BufferBlock\n"
1378 "OpDecorate %indata1 DescriptorSet 0\n"
1379 "OpDecorate %indata1 Binding 0\n"
1380 "OpDecorate %indata2 DescriptorSet 0\n"
1381 "OpDecorate %indata2 Binding 1\n"
1382 "OpDecorate %outdata DescriptorSet 0\n"
1383 "OpDecorate %outdata Binding 2\n"
1384 "OpDecorate %f32arr ArrayStride 4\n"
1385 "OpMemberDecorate %buf 0 Offset 0\n"
1387 + string(getComputeAsmCommonTypes()) +
1389 "%buf = OpTypeStruct %f32arr\n"
1390 "%bufptr = OpTypePointer Uniform %buf\n"
1391 "%indata1 = OpVariable %bufptr Uniform\n"
1392 "%indata2 = OpVariable %bufptr Uniform\n"
1393 "%outdata = OpVariable %bufptr Uniform\n"
1395 "%id = OpVariable %uvec3ptr Input\n"
1396 "%zero = OpConstant %i32 0\n"
1398 "%main = OpFunction %void None %voidf\n"
1399 "%label = OpLabel\n"
1400 "%idval = OpLoad %uvec3 %id\n"
1401 "%x = OpCompositeExtract %u32 %idval 0\n"
1402 "%inloc1 = OpAccessChain %f32ptr %indata1 %zero %x\n"
1403 "%inval1 = OpLoad %f32 %inloc1\n"
1404 "%inloc2 = OpAccessChain %f32ptr %indata2 %zero %x\n"
1405 "%inval2 = OpLoad %f32 %inloc2\n"
1406 "%rem = OpExtInst %f32 %std450 NMax %inval1 %inval2\n"
1407 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
1408 " OpStore %outloc %rem\n"
1412 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats1)));
1413 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
1414 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
1415 spec.numWorkGroups = IVec3(numElements, 1, 1);
1416 spec.verifyIO = &compareNMax;
1418 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "", spec));
1420 return group.release();
1423 bool compareNClamp (const std::vector<Resource>&, const vector<AllocationSp>& outputAllocs, const std::vector<Resource>& expectedOutputs, TestLog&)
1425 if (outputAllocs.size() != 1)
1428 const BufferSp& expectedOutput = expectedOutputs[0].getBuffer();
1429 std::vector<deUint8> data;
1430 expectedOutput->getBytes(data);
1432 const float* const expectedOutputAsFloat = reinterpret_cast<const float*>(&data.front());
1433 const float* const outputAsFloat = static_cast<const float*>(outputAllocs[0]->getHostPtr());
1435 for (size_t idx = 0; idx < expectedOutput->getByteSize() / sizeof(float) / 2; ++idx)
1437 const float e0 = expectedOutputAsFloat[idx * 2];
1438 const float e1 = expectedOutputAsFloat[idx * 2 + 1];
1439 const float res = outputAsFloat[idx];
1441 // For NClamp, we have two possible outcomes based on
1442 // whether NaNs are handled or not.
1443 // If either min or max value is NaN, the result is undefined,
1444 // so this test doesn't stress those. If the clamped value is
1445 // NaN, and NaNs are handled, the result is min; if NaNs are not
1446 // handled, they are big values that result in max.
1447 // If all three parameters are NaN, the result should be NaN.
1448 if (!((tcu::Float32(e0).isNaN() && tcu::Float32(res).isNaN()) ||
1449 (deFloatAbs(e0 - res) < 0.00001f) ||
1450 (deFloatAbs(e1 - res) < 0.00001f)))
1457 tcu::TestCaseGroup* createOpNClampGroup (tcu::TestContext& testCtx)
1459 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opnclamp", "Test the OpNClamp instruction"));
1460 ComputeShaderSpec spec;
1461 de::Random rnd (deStringHash(group->getName()));
1462 const int numElements = 200;
1463 vector<float> inputFloats1 (numElements, 0);
1464 vector<float> inputFloats2 (numElements, 0);
1465 vector<float> inputFloats3 (numElements, 0);
1466 vector<float> outputFloats (numElements * 2, 0);
1468 fillRandomScalars(rnd, -10000.f, 10000.f, &inputFloats1[0], numElements);
1469 fillRandomScalars(rnd, -10000.f, 10000.f, &inputFloats2[0], numElements);
1470 fillRandomScalars(rnd, -10000.f, 10000.f, &inputFloats3[0], numElements);
1472 for (size_t ndx = 0; ndx < numElements; ++ndx)
1474 // Results are only defined if max value is bigger than min value.
1475 if (inputFloats2[ndx] > inputFloats3[ndx])
1477 float t = inputFloats2[ndx];
1478 inputFloats2[ndx] = inputFloats3[ndx];
1479 inputFloats3[ndx] = t;
1482 // By default, do the clamp, setting both possible answers
1483 float defaultRes = std::min(std::max(inputFloats1[ndx], inputFloats2[ndx]), inputFloats3[ndx]);
1485 float maxResA = std::max(inputFloats1[ndx], inputFloats2[ndx]);
1486 float maxResB = maxResA;
1488 // Alternate between the NaN cases
1491 inputFloats1[ndx] = TCU_NAN;
1492 // If NaN is handled, the result should be same as the clamp minimum.
1493 // If NaN is not handled, the result should clamp to the clamp maximum.
1494 maxResA = inputFloats2[ndx];
1495 maxResB = inputFloats3[ndx];
1499 // Not a NaN case - only one legal result.
1500 maxResA = defaultRes;
1501 maxResB = defaultRes;
1504 outputFloats[ndx * 2] = maxResA;
1505 outputFloats[ndx * 2 + 1] = maxResB;
1508 // Make the first case a full-NAN case.
1509 inputFloats1[0] = TCU_NAN;
1510 inputFloats2[0] = TCU_NAN;
1511 inputFloats3[0] = TCU_NAN;
1512 outputFloats[0] = TCU_NAN;
1513 outputFloats[1] = TCU_NAN;
1516 "OpCapability Shader\n"
1517 "%std450 = OpExtInstImport \"GLSL.std.450\"\n"
1518 "OpMemoryModel Logical GLSL450\n"
1519 "OpEntryPoint GLCompute %main \"main\" %id\n"
1520 "OpExecutionMode %main LocalSize 1 1 1\n"
1522 "OpName %main \"main\"\n"
1523 "OpName %id \"gl_GlobalInvocationID\"\n"
1525 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1527 "OpDecorate %buf BufferBlock\n"
1528 "OpDecorate %indata1 DescriptorSet 0\n"
1529 "OpDecorate %indata1 Binding 0\n"
1530 "OpDecorate %indata2 DescriptorSet 0\n"
1531 "OpDecorate %indata2 Binding 1\n"
1532 "OpDecorate %indata3 DescriptorSet 0\n"
1533 "OpDecorate %indata3 Binding 2\n"
1534 "OpDecorate %outdata DescriptorSet 0\n"
1535 "OpDecorate %outdata Binding 3\n"
1536 "OpDecorate %f32arr ArrayStride 4\n"
1537 "OpMemberDecorate %buf 0 Offset 0\n"
1539 + string(getComputeAsmCommonTypes()) +
1541 "%buf = OpTypeStruct %f32arr\n"
1542 "%bufptr = OpTypePointer Uniform %buf\n"
1543 "%indata1 = OpVariable %bufptr Uniform\n"
1544 "%indata2 = OpVariable %bufptr Uniform\n"
1545 "%indata3 = OpVariable %bufptr Uniform\n"
1546 "%outdata = OpVariable %bufptr Uniform\n"
1548 "%id = OpVariable %uvec3ptr Input\n"
1549 "%zero = OpConstant %i32 0\n"
1551 "%main = OpFunction %void None %voidf\n"
1552 "%label = OpLabel\n"
1553 "%idval = OpLoad %uvec3 %id\n"
1554 "%x = OpCompositeExtract %u32 %idval 0\n"
1555 "%inloc1 = OpAccessChain %f32ptr %indata1 %zero %x\n"
1556 "%inval1 = OpLoad %f32 %inloc1\n"
1557 "%inloc2 = OpAccessChain %f32ptr %indata2 %zero %x\n"
1558 "%inval2 = OpLoad %f32 %inloc2\n"
1559 "%inloc3 = OpAccessChain %f32ptr %indata3 %zero %x\n"
1560 "%inval3 = OpLoad %f32 %inloc3\n"
1561 "%rem = OpExtInst %f32 %std450 NClamp %inval1 %inval2 %inval3\n"
1562 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
1563 " OpStore %outloc %rem\n"
1567 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats1)));
1568 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
1569 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats3)));
1570 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
1571 spec.numWorkGroups = IVec3(numElements, 1, 1);
1572 spec.verifyIO = &compareNClamp;
1574 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "", spec));
1576 return group.release();
1579 tcu::TestCaseGroup* createOpSRemComputeGroup (tcu::TestContext& testCtx, qpTestResult negFailResult)
1581 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opsrem", "Test the OpSRem instruction"));
1582 de::Random rnd (deStringHash(group->getName()));
1583 const int numElements = 200;
1585 const struct CaseParams
1588 const char* failMessage; // customized status message
1589 qpTestResult failResult; // override status on failure
1590 int op1Min, op1Max; // operand ranges
1594 { "positive", "Output doesn't match with expected", QP_TEST_RESULT_FAIL, 0, 65536, 0, 100 },
1595 { "all", "Inconsistent results, but within specification", negFailResult, -65536, 65536, -100, 100 }, // see below
1597 // If either operand is negative the result is undefined. Some implementations may still return correct values.
1599 for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(cases); ++caseNdx)
1601 const CaseParams& params = cases[caseNdx];
1602 ComputeShaderSpec spec;
1603 vector<deInt32> inputInts1 (numElements, 0);
1604 vector<deInt32> inputInts2 (numElements, 0);
1605 vector<deInt32> outputInts (numElements, 0);
1607 fillRandomScalars(rnd, params.op1Min, params.op1Max, &inputInts1[0], numElements);
1608 fillRandomScalars(rnd, params.op2Min, params.op2Max, &inputInts2[0], numElements, filterNotZero);
1610 for (int ndx = 0; ndx < numElements; ++ndx)
1612 // The return value of std::fmod() has the same sign as its first operand, which is how OpFRem spec'd.
1613 outputInts[ndx] = inputInts1[ndx] % inputInts2[ndx];
1617 string(getComputeAsmShaderPreamble()) +
1619 "OpName %main \"main\"\n"
1620 "OpName %id \"gl_GlobalInvocationID\"\n"
1622 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1624 "OpDecorate %buf BufferBlock\n"
1625 "OpDecorate %indata1 DescriptorSet 0\n"
1626 "OpDecorate %indata1 Binding 0\n"
1627 "OpDecorate %indata2 DescriptorSet 0\n"
1628 "OpDecorate %indata2 Binding 1\n"
1629 "OpDecorate %outdata DescriptorSet 0\n"
1630 "OpDecorate %outdata Binding 2\n"
1631 "OpDecorate %i32arr ArrayStride 4\n"
1632 "OpMemberDecorate %buf 0 Offset 0\n"
1634 + string(getComputeAsmCommonTypes()) +
1636 "%buf = OpTypeStruct %i32arr\n"
1637 "%bufptr = OpTypePointer Uniform %buf\n"
1638 "%indata1 = OpVariable %bufptr Uniform\n"
1639 "%indata2 = OpVariable %bufptr Uniform\n"
1640 "%outdata = OpVariable %bufptr Uniform\n"
1642 "%id = OpVariable %uvec3ptr Input\n"
1643 "%zero = OpConstant %i32 0\n"
1645 "%main = OpFunction %void None %voidf\n"
1646 "%label = OpLabel\n"
1647 "%idval = OpLoad %uvec3 %id\n"
1648 "%x = OpCompositeExtract %u32 %idval 0\n"
1649 "%inloc1 = OpAccessChain %i32ptr %indata1 %zero %x\n"
1650 "%inval1 = OpLoad %i32 %inloc1\n"
1651 "%inloc2 = OpAccessChain %i32ptr %indata2 %zero %x\n"
1652 "%inval2 = OpLoad %i32 %inloc2\n"
1653 "%rem = OpSRem %i32 %inval1 %inval2\n"
1654 "%outloc = OpAccessChain %i32ptr %outdata %zero %x\n"
1655 " OpStore %outloc %rem\n"
1659 spec.inputs.push_back (BufferSp(new Int32Buffer(inputInts1)));
1660 spec.inputs.push_back (BufferSp(new Int32Buffer(inputInts2)));
1661 spec.outputs.push_back (BufferSp(new Int32Buffer(outputInts)));
1662 spec.numWorkGroups = IVec3(numElements, 1, 1);
1663 spec.failResult = params.failResult;
1664 spec.failMessage = params.failMessage;
1666 group->addChild(new SpvAsmComputeShaderCase(testCtx, params.name, "", spec));
1669 return group.release();
1672 tcu::TestCaseGroup* createOpSRemComputeGroup64 (tcu::TestContext& testCtx, qpTestResult negFailResult)
1674 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opsrem64", "Test the 64-bit OpSRem instruction"));
1675 de::Random rnd (deStringHash(group->getName()));
1676 const int numElements = 200;
1678 const struct CaseParams
1681 const char* failMessage; // customized status message
1682 qpTestResult failResult; // override status on failure
1686 { "positive", "Output doesn't match with expected", QP_TEST_RESULT_FAIL, true },
1687 { "all", "Inconsistent results, but within specification", negFailResult, false }, // see below
1689 // If either operand is negative the result is undefined. Some implementations may still return correct values.
1691 for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(cases); ++caseNdx)
1693 const CaseParams& params = cases[caseNdx];
1694 ComputeShaderSpec spec;
1695 vector<deInt64> inputInts1 (numElements, 0);
1696 vector<deInt64> inputInts2 (numElements, 0);
1697 vector<deInt64> outputInts (numElements, 0);
1699 if (params.positive)
1701 fillRandomInt64sLogDistributed(rnd, inputInts1, numElements, filterNonNegative);
1702 fillRandomInt64sLogDistributed(rnd, inputInts2, numElements, filterPositive);
1706 fillRandomInt64sLogDistributed(rnd, inputInts1, numElements);
1707 fillRandomInt64sLogDistributed(rnd, inputInts2, numElements, filterNotZero);
1710 for (int ndx = 0; ndx < numElements; ++ndx)
1712 // The return value of std::fmod() has the same sign as its first operand, which is how OpFRem spec'd.
1713 outputInts[ndx] = inputInts1[ndx] % inputInts2[ndx];
1717 "OpCapability Int64\n"
1719 + string(getComputeAsmShaderPreamble()) +
1721 "OpName %main \"main\"\n"
1722 "OpName %id \"gl_GlobalInvocationID\"\n"
1724 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1726 "OpDecorate %buf BufferBlock\n"
1727 "OpDecorate %indata1 DescriptorSet 0\n"
1728 "OpDecorate %indata1 Binding 0\n"
1729 "OpDecorate %indata2 DescriptorSet 0\n"
1730 "OpDecorate %indata2 Binding 1\n"
1731 "OpDecorate %outdata DescriptorSet 0\n"
1732 "OpDecorate %outdata Binding 2\n"
1733 "OpDecorate %i64arr ArrayStride 8\n"
1734 "OpMemberDecorate %buf 0 Offset 0\n"
1736 + string(getComputeAsmCommonTypes())
1737 + string(getComputeAsmCommonInt64Types()) +
1739 "%buf = OpTypeStruct %i64arr\n"
1740 "%bufptr = OpTypePointer Uniform %buf\n"
1741 "%indata1 = OpVariable %bufptr Uniform\n"
1742 "%indata2 = OpVariable %bufptr Uniform\n"
1743 "%outdata = OpVariable %bufptr Uniform\n"
1745 "%id = OpVariable %uvec3ptr Input\n"
1746 "%zero = OpConstant %i64 0\n"
1748 "%main = OpFunction %void None %voidf\n"
1749 "%label = OpLabel\n"
1750 "%idval = OpLoad %uvec3 %id\n"
1751 "%x = OpCompositeExtract %u32 %idval 0\n"
1752 "%inloc1 = OpAccessChain %i64ptr %indata1 %zero %x\n"
1753 "%inval1 = OpLoad %i64 %inloc1\n"
1754 "%inloc2 = OpAccessChain %i64ptr %indata2 %zero %x\n"
1755 "%inval2 = OpLoad %i64 %inloc2\n"
1756 "%rem = OpSRem %i64 %inval1 %inval2\n"
1757 "%outloc = OpAccessChain %i64ptr %outdata %zero %x\n"
1758 " OpStore %outloc %rem\n"
1762 spec.inputs.push_back (BufferSp(new Int64Buffer(inputInts1)));
1763 spec.inputs.push_back (BufferSp(new Int64Buffer(inputInts2)));
1764 spec.outputs.push_back (BufferSp(new Int64Buffer(outputInts)));
1765 spec.numWorkGroups = IVec3(numElements, 1, 1);
1766 spec.failResult = params.failResult;
1767 spec.failMessage = params.failMessage;
1769 spec.requestedVulkanFeatures.coreFeatures.shaderInt64 = VK_TRUE;
1771 group->addChild(new SpvAsmComputeShaderCase(testCtx, params.name, "", spec));
1774 return group.release();
1777 tcu::TestCaseGroup* createOpSModComputeGroup (tcu::TestContext& testCtx, qpTestResult negFailResult)
1779 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opsmod", "Test the OpSMod instruction"));
1780 de::Random rnd (deStringHash(group->getName()));
1781 const int numElements = 200;
1783 const struct CaseParams
1786 const char* failMessage; // customized status message
1787 qpTestResult failResult; // override status on failure
1788 int op1Min, op1Max; // operand ranges
1792 { "positive", "Output doesn't match with expected", QP_TEST_RESULT_FAIL, 0, 65536, 0, 100 },
1793 { "all", "Inconsistent results, but within specification", negFailResult, -65536, 65536, -100, 100 }, // see below
1795 // If either operand is negative the result is undefined. Some implementations may still return correct values.
1797 for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(cases); ++caseNdx)
1799 const CaseParams& params = cases[caseNdx];
1801 ComputeShaderSpec spec;
1802 vector<deInt32> inputInts1 (numElements, 0);
1803 vector<deInt32> inputInts2 (numElements, 0);
1804 vector<deInt32> outputInts (numElements, 0);
1806 fillRandomScalars(rnd, params.op1Min, params.op1Max, &inputInts1[0], numElements);
1807 fillRandomScalars(rnd, params.op2Min, params.op2Max, &inputInts2[0], numElements, filterNotZero);
1809 for (int ndx = 0; ndx < numElements; ++ndx)
1811 deInt32 rem = inputInts1[ndx] % inputInts2[ndx];
1814 outputInts[ndx] = 0;
1816 else if ((inputInts1[ndx] >= 0) == (inputInts2[ndx] >= 0))
1818 // They have the same sign
1819 outputInts[ndx] = rem;
1823 // They have opposite sign. The remainder operation takes the
1824 // sign inputInts1[ndx] but OpSMod is supposed to take ths sign
1825 // of inputInts2[ndx]. Adding inputInts2[ndx] will ensure that
1826 // the result has the correct sign and that it is still
1827 // congruent to inputInts1[ndx] modulo inputInts2[ndx]
1829 // See also http://mathforum.org/library/drmath/view/52343.html
1830 outputInts[ndx] = rem + inputInts2[ndx];
1835 string(getComputeAsmShaderPreamble()) +
1837 "OpName %main \"main\"\n"
1838 "OpName %id \"gl_GlobalInvocationID\"\n"
1840 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1842 "OpDecorate %buf BufferBlock\n"
1843 "OpDecorate %indata1 DescriptorSet 0\n"
1844 "OpDecorate %indata1 Binding 0\n"
1845 "OpDecorate %indata2 DescriptorSet 0\n"
1846 "OpDecorate %indata2 Binding 1\n"
1847 "OpDecorate %outdata DescriptorSet 0\n"
1848 "OpDecorate %outdata Binding 2\n"
1849 "OpDecorate %i32arr ArrayStride 4\n"
1850 "OpMemberDecorate %buf 0 Offset 0\n"
1852 + string(getComputeAsmCommonTypes()) +
1854 "%buf = OpTypeStruct %i32arr\n"
1855 "%bufptr = OpTypePointer Uniform %buf\n"
1856 "%indata1 = OpVariable %bufptr Uniform\n"
1857 "%indata2 = OpVariable %bufptr Uniform\n"
1858 "%outdata = OpVariable %bufptr Uniform\n"
1860 "%id = OpVariable %uvec3ptr Input\n"
1861 "%zero = OpConstant %i32 0\n"
1863 "%main = OpFunction %void None %voidf\n"
1864 "%label = OpLabel\n"
1865 "%idval = OpLoad %uvec3 %id\n"
1866 "%x = OpCompositeExtract %u32 %idval 0\n"
1867 "%inloc1 = OpAccessChain %i32ptr %indata1 %zero %x\n"
1868 "%inval1 = OpLoad %i32 %inloc1\n"
1869 "%inloc2 = OpAccessChain %i32ptr %indata2 %zero %x\n"
1870 "%inval2 = OpLoad %i32 %inloc2\n"
1871 "%rem = OpSMod %i32 %inval1 %inval2\n"
1872 "%outloc = OpAccessChain %i32ptr %outdata %zero %x\n"
1873 " OpStore %outloc %rem\n"
1877 spec.inputs.push_back (BufferSp(new Int32Buffer(inputInts1)));
1878 spec.inputs.push_back (BufferSp(new Int32Buffer(inputInts2)));
1879 spec.outputs.push_back (BufferSp(new Int32Buffer(outputInts)));
1880 spec.numWorkGroups = IVec3(numElements, 1, 1);
1881 spec.failResult = params.failResult;
1882 spec.failMessage = params.failMessage;
1884 group->addChild(new SpvAsmComputeShaderCase(testCtx, params.name, "", spec));
1887 return group.release();
1890 tcu::TestCaseGroup* createOpSModComputeGroup64 (tcu::TestContext& testCtx, qpTestResult negFailResult)
1892 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opsmod64", "Test the OpSMod instruction"));
1893 de::Random rnd (deStringHash(group->getName()));
1894 const int numElements = 200;
1896 const struct CaseParams
1899 const char* failMessage; // customized status message
1900 qpTestResult failResult; // override status on failure
1904 { "positive", "Output doesn't match with expected", QP_TEST_RESULT_FAIL, true },
1905 { "all", "Inconsistent results, but within specification", negFailResult, false }, // see below
1907 // If either operand is negative the result is undefined. Some implementations may still return correct values.
1909 for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(cases); ++caseNdx)
1911 const CaseParams& params = cases[caseNdx];
1913 ComputeShaderSpec spec;
1914 vector<deInt64> inputInts1 (numElements, 0);
1915 vector<deInt64> inputInts2 (numElements, 0);
1916 vector<deInt64> outputInts (numElements, 0);
1919 if (params.positive)
1921 fillRandomInt64sLogDistributed(rnd, inputInts1, numElements, filterNonNegative);
1922 fillRandomInt64sLogDistributed(rnd, inputInts2, numElements, filterPositive);
1926 fillRandomInt64sLogDistributed(rnd, inputInts1, numElements);
1927 fillRandomInt64sLogDistributed(rnd, inputInts2, numElements, filterNotZero);
1930 for (int ndx = 0; ndx < numElements; ++ndx)
1932 deInt64 rem = inputInts1[ndx] % inputInts2[ndx];
1935 outputInts[ndx] = 0;
1937 else if ((inputInts1[ndx] >= 0) == (inputInts2[ndx] >= 0))
1939 // They have the same sign
1940 outputInts[ndx] = rem;
1944 // They have opposite sign. The remainder operation takes the
1945 // sign inputInts1[ndx] but OpSMod is supposed to take ths sign
1946 // of inputInts2[ndx]. Adding inputInts2[ndx] will ensure that
1947 // the result has the correct sign and that it is still
1948 // congruent to inputInts1[ndx] modulo inputInts2[ndx]
1950 // See also http://mathforum.org/library/drmath/view/52343.html
1951 outputInts[ndx] = rem + inputInts2[ndx];
1956 "OpCapability Int64\n"
1958 + string(getComputeAsmShaderPreamble()) +
1960 "OpName %main \"main\"\n"
1961 "OpName %id \"gl_GlobalInvocationID\"\n"
1963 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1965 "OpDecorate %buf BufferBlock\n"
1966 "OpDecorate %indata1 DescriptorSet 0\n"
1967 "OpDecorate %indata1 Binding 0\n"
1968 "OpDecorate %indata2 DescriptorSet 0\n"
1969 "OpDecorate %indata2 Binding 1\n"
1970 "OpDecorate %outdata DescriptorSet 0\n"
1971 "OpDecorate %outdata Binding 2\n"
1972 "OpDecorate %i64arr ArrayStride 8\n"
1973 "OpMemberDecorate %buf 0 Offset 0\n"
1975 + string(getComputeAsmCommonTypes())
1976 + string(getComputeAsmCommonInt64Types()) +
1978 "%buf = OpTypeStruct %i64arr\n"
1979 "%bufptr = OpTypePointer Uniform %buf\n"
1980 "%indata1 = OpVariable %bufptr Uniform\n"
1981 "%indata2 = OpVariable %bufptr Uniform\n"
1982 "%outdata = OpVariable %bufptr Uniform\n"
1984 "%id = OpVariable %uvec3ptr Input\n"
1985 "%zero = OpConstant %i64 0\n"
1987 "%main = OpFunction %void None %voidf\n"
1988 "%label = OpLabel\n"
1989 "%idval = OpLoad %uvec3 %id\n"
1990 "%x = OpCompositeExtract %u32 %idval 0\n"
1991 "%inloc1 = OpAccessChain %i64ptr %indata1 %zero %x\n"
1992 "%inval1 = OpLoad %i64 %inloc1\n"
1993 "%inloc2 = OpAccessChain %i64ptr %indata2 %zero %x\n"
1994 "%inval2 = OpLoad %i64 %inloc2\n"
1995 "%rem = OpSMod %i64 %inval1 %inval2\n"
1996 "%outloc = OpAccessChain %i64ptr %outdata %zero %x\n"
1997 " OpStore %outloc %rem\n"
2001 spec.inputs.push_back (BufferSp(new Int64Buffer(inputInts1)));
2002 spec.inputs.push_back (BufferSp(new Int64Buffer(inputInts2)));
2003 spec.outputs.push_back (BufferSp(new Int64Buffer(outputInts)));
2004 spec.numWorkGroups = IVec3(numElements, 1, 1);
2005 spec.failResult = params.failResult;
2006 spec.failMessage = params.failMessage;
2008 spec.requestedVulkanFeatures.coreFeatures.shaderInt64 = VK_TRUE;
2010 group->addChild(new SpvAsmComputeShaderCase(testCtx, params.name, "", spec));
2013 return group.release();
2016 // Copy contents in the input buffer to the output buffer.
2017 tcu::TestCaseGroup* createOpCopyMemoryGroup (tcu::TestContext& testCtx)
2019 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opcopymemory", "Test the OpCopyMemory instruction"));
2020 de::Random rnd (deStringHash(group->getName()));
2021 const int numElements = 100;
2023 // 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.
2024 ComputeShaderSpec spec1;
2025 vector<Vec4> inputFloats1 (numElements);
2026 vector<Vec4> outputFloats1 (numElements);
2028 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats1[0], numElements * 4);
2030 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
2031 floorAll(inputFloats1);
2033 for (size_t ndx = 0; ndx < numElements; ++ndx)
2034 outputFloats1[ndx] = inputFloats1[ndx] + Vec4(0.f, 0.5f, 1.5f, 2.5f);
2037 string(getComputeAsmShaderPreamble()) +
2039 "OpName %main \"main\"\n"
2040 "OpName %id \"gl_GlobalInvocationID\"\n"
2042 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2043 "OpDecorate %vec4arr ArrayStride 16\n"
2045 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
2047 "%vec4 = OpTypeVector %f32 4\n"
2048 "%vec4ptr_u = OpTypePointer Uniform %vec4\n"
2049 "%vec4ptr_f = OpTypePointer Function %vec4\n"
2050 "%vec4arr = OpTypeRuntimeArray %vec4\n"
2051 "%buf = OpTypeStruct %vec4arr\n"
2052 "%bufptr = OpTypePointer Uniform %buf\n"
2053 "%indata = OpVariable %bufptr Uniform\n"
2054 "%outdata = OpVariable %bufptr Uniform\n"
2056 "%id = OpVariable %uvec3ptr Input\n"
2057 "%zero = OpConstant %i32 0\n"
2058 "%c_f_0 = OpConstant %f32 0.\n"
2059 "%c_f_0_5 = OpConstant %f32 0.5\n"
2060 "%c_f_1_5 = OpConstant %f32 1.5\n"
2061 "%c_f_2_5 = OpConstant %f32 2.5\n"
2062 "%c_vec4 = OpConstantComposite %vec4 %c_f_0 %c_f_0_5 %c_f_1_5 %c_f_2_5\n"
2064 "%main = OpFunction %void None %voidf\n"
2065 "%label = OpLabel\n"
2066 "%v_vec4 = OpVariable %vec4ptr_f Function\n"
2067 "%idval = OpLoad %uvec3 %id\n"
2068 "%x = OpCompositeExtract %u32 %idval 0\n"
2069 "%inloc = OpAccessChain %vec4ptr_u %indata %zero %x\n"
2070 "%outloc = OpAccessChain %vec4ptr_u %outdata %zero %x\n"
2071 " OpCopyMemory %v_vec4 %inloc\n"
2072 "%v_vec4_val = OpLoad %vec4 %v_vec4\n"
2073 "%add = OpFAdd %vec4 %v_vec4_val %c_vec4\n"
2074 " OpStore %outloc %add\n"
2078 spec1.inputs.push_back(BufferSp(new Vec4Buffer(inputFloats1)));
2079 spec1.outputs.push_back(BufferSp(new Vec4Buffer(outputFloats1)));
2080 spec1.numWorkGroups = IVec3(numElements, 1, 1);
2082 group->addChild(new SpvAsmComputeShaderCase(testCtx, "vector", "OpCopyMemory elements of vector type", spec1));
2084 // The following case copies a float[100] variable from the input buffer to the output buffer.
2085 ComputeShaderSpec spec2;
2086 vector<float> inputFloats2 (numElements);
2087 vector<float> outputFloats2 (numElements);
2089 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats2[0], numElements);
2091 for (size_t ndx = 0; ndx < numElements; ++ndx)
2092 outputFloats2[ndx] = inputFloats2[ndx];
2095 string(getComputeAsmShaderPreamble()) +
2097 "OpName %main \"main\"\n"
2098 "OpName %id \"gl_GlobalInvocationID\"\n"
2100 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2101 "OpDecorate %f32arr100 ArrayStride 4\n"
2103 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
2105 "%hundred = OpConstant %u32 100\n"
2106 "%f32arr100 = OpTypeArray %f32 %hundred\n"
2107 "%f32arr100ptr_f = OpTypePointer Function %f32arr100\n"
2108 "%f32arr100ptr_u = OpTypePointer Uniform %f32arr100\n"
2109 "%buf = OpTypeStruct %f32arr100\n"
2110 "%bufptr = OpTypePointer Uniform %buf\n"
2111 "%indata = OpVariable %bufptr Uniform\n"
2112 "%outdata = OpVariable %bufptr Uniform\n"
2114 "%id = OpVariable %uvec3ptr Input\n"
2115 "%zero = OpConstant %i32 0\n"
2117 "%main = OpFunction %void None %voidf\n"
2118 "%label = OpLabel\n"
2119 "%var = OpVariable %f32arr100ptr_f Function\n"
2120 "%inarr = OpAccessChain %f32arr100ptr_u %indata %zero\n"
2121 "%outarr = OpAccessChain %f32arr100ptr_u %outdata %zero\n"
2122 " OpCopyMemory %var %inarr\n"
2123 " OpCopyMemory %outarr %var\n"
2127 spec2.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
2128 spec2.outputs.push_back(BufferSp(new Float32Buffer(outputFloats2)));
2129 spec2.numWorkGroups = IVec3(1, 1, 1);
2131 group->addChild(new SpvAsmComputeShaderCase(testCtx, "array", "OpCopyMemory elements of array type", spec2));
2133 // The following case copies a struct{vec4, vec4, vec4, vec4} variable from the input buffer to the output buffer.
2134 ComputeShaderSpec spec3;
2135 vector<float> inputFloats3 (16);
2136 vector<float> outputFloats3 (16);
2138 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats3[0], 16);
2140 for (size_t ndx = 0; ndx < 16; ++ndx)
2141 outputFloats3[ndx] = inputFloats3[ndx];
2144 string(getComputeAsmShaderPreamble()) +
2146 "OpName %main \"main\"\n"
2147 "OpName %id \"gl_GlobalInvocationID\"\n"
2149 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2150 //"OpMemberDecorate %buf 0 Offset 0\n" - exists in getComputeAsmInputOutputBufferTraits
2151 "OpMemberDecorate %buf 1 Offset 16\n"
2152 "OpMemberDecorate %buf 2 Offset 32\n"
2153 "OpMemberDecorate %buf 3 Offset 48\n"
2155 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
2157 "%vec4 = OpTypeVector %f32 4\n"
2158 "%buf = OpTypeStruct %vec4 %vec4 %vec4 %vec4\n"
2159 "%bufptr = OpTypePointer Uniform %buf\n"
2160 "%indata = OpVariable %bufptr Uniform\n"
2161 "%outdata = OpVariable %bufptr Uniform\n"
2162 "%vec4stptr = OpTypePointer Function %buf\n"
2164 "%id = OpVariable %uvec3ptr Input\n"
2165 "%zero = OpConstant %i32 0\n"
2167 "%main = OpFunction %void None %voidf\n"
2168 "%label = OpLabel\n"
2169 "%var = OpVariable %vec4stptr Function\n"
2170 " OpCopyMemory %var %indata\n"
2171 " OpCopyMemory %outdata %var\n"
2175 spec3.inputs.push_back(BufferSp(new Float32Buffer(inputFloats3)));
2176 spec3.outputs.push_back(BufferSp(new Float32Buffer(outputFloats3)));
2177 spec3.numWorkGroups = IVec3(1, 1, 1);
2179 group->addChild(new SpvAsmComputeShaderCase(testCtx, "struct", "OpCopyMemory elements of struct type", spec3));
2181 // The following case negates multiple float variables from the input buffer and stores the results to the output buffer.
2182 ComputeShaderSpec spec4;
2183 vector<float> inputFloats4 (numElements);
2184 vector<float> outputFloats4 (numElements);
2186 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats4[0], numElements);
2188 for (size_t ndx = 0; ndx < numElements; ++ndx)
2189 outputFloats4[ndx] = -inputFloats4[ndx];
2192 string(getComputeAsmShaderPreamble()) +
2194 "OpName %main \"main\"\n"
2195 "OpName %id \"gl_GlobalInvocationID\"\n"
2197 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2199 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
2201 "%f32ptr_f = OpTypePointer Function %f32\n"
2202 "%id = OpVariable %uvec3ptr Input\n"
2203 "%zero = OpConstant %i32 0\n"
2205 "%main = OpFunction %void None %voidf\n"
2206 "%label = OpLabel\n"
2207 "%var = OpVariable %f32ptr_f Function\n"
2208 "%idval = OpLoad %uvec3 %id\n"
2209 "%x = OpCompositeExtract %u32 %idval 0\n"
2210 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
2211 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2212 " OpCopyMemory %var %inloc\n"
2213 "%val = OpLoad %f32 %var\n"
2214 "%neg = OpFNegate %f32 %val\n"
2215 " OpStore %outloc %neg\n"
2219 spec4.inputs.push_back(BufferSp(new Float32Buffer(inputFloats4)));
2220 spec4.outputs.push_back(BufferSp(new Float32Buffer(outputFloats4)));
2221 spec4.numWorkGroups = IVec3(numElements, 1, 1);
2223 group->addChild(new SpvAsmComputeShaderCase(testCtx, "float", "OpCopyMemory elements of float type", spec4));
2225 return group.release();
2228 tcu::TestCaseGroup* createOpCopyObjectGroup (tcu::TestContext& testCtx)
2230 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opcopyobject", "Test the OpCopyObject instruction"));
2231 ComputeShaderSpec spec;
2232 de::Random rnd (deStringHash(group->getName()));
2233 const int numElements = 100;
2234 vector<float> inputFloats (numElements, 0);
2235 vector<float> outputFloats (numElements, 0);
2237 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats[0], numElements);
2239 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
2240 floorAll(inputFloats);
2242 for (size_t ndx = 0; ndx < numElements; ++ndx)
2243 outputFloats[ndx] = inputFloats[ndx] + 7.5f;
2246 string(getComputeAsmShaderPreamble()) +
2248 "OpName %main \"main\"\n"
2249 "OpName %id \"gl_GlobalInvocationID\"\n"
2251 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2253 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
2255 "%fmat = OpTypeMatrix %fvec3 3\n"
2256 "%three = OpConstant %u32 3\n"
2257 "%farr = OpTypeArray %f32 %three\n"
2258 "%fst = OpTypeStruct %f32 %f32\n"
2260 + string(getComputeAsmInputOutputBuffer()) +
2262 "%id = OpVariable %uvec3ptr Input\n"
2263 "%zero = OpConstant %i32 0\n"
2264 "%c_f = OpConstant %f32 1.5\n"
2265 "%c_fvec3 = OpConstantComposite %fvec3 %c_f %c_f %c_f\n"
2266 "%c_fmat = OpConstantComposite %fmat %c_fvec3 %c_fvec3 %c_fvec3\n"
2267 "%c_farr = OpConstantComposite %farr %c_f %c_f %c_f\n"
2268 "%c_fst = OpConstantComposite %fst %c_f %c_f\n"
2270 "%main = OpFunction %void None %voidf\n"
2271 "%label = OpLabel\n"
2272 "%c_f_copy = OpCopyObject %f32 %c_f\n"
2273 "%c_fvec3_copy = OpCopyObject %fvec3 %c_fvec3\n"
2274 "%c_fmat_copy = OpCopyObject %fmat %c_fmat\n"
2275 "%c_farr_copy = OpCopyObject %farr %c_farr\n"
2276 "%c_fst_copy = OpCopyObject %fst %c_fst\n"
2277 "%fvec3_elem = OpCompositeExtract %f32 %c_fvec3_copy 0\n"
2278 "%fmat_elem = OpCompositeExtract %f32 %c_fmat_copy 1 2\n"
2279 "%farr_elem = OpCompositeExtract %f32 %c_farr_copy 2\n"
2280 "%fst_elem = OpCompositeExtract %f32 %c_fst_copy 1\n"
2281 // Add up. 1.5 * 5 = 7.5.
2282 "%add1 = OpFAdd %f32 %c_f_copy %fvec3_elem\n"
2283 "%add2 = OpFAdd %f32 %add1 %fmat_elem\n"
2284 "%add3 = OpFAdd %f32 %add2 %farr_elem\n"
2285 "%add4 = OpFAdd %f32 %add3 %fst_elem\n"
2287 "%idval = OpLoad %uvec3 %id\n"
2288 "%x = OpCompositeExtract %u32 %idval 0\n"
2289 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
2290 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2291 "%inval = OpLoad %f32 %inloc\n"
2292 "%add = OpFAdd %f32 %add4 %inval\n"
2293 " OpStore %outloc %add\n"
2296 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
2297 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
2298 spec.numWorkGroups = IVec3(numElements, 1, 1);
2300 group->addChild(new SpvAsmComputeShaderCase(testCtx, "spotcheck", "OpCopyObject on different types", spec));
2302 return group.release();
2304 // Assembly code used for testing OpUnreachable is based on GLSL source code:
2308 // layout(std140, set = 0, binding = 0) readonly buffer Input {
2309 // float elements[];
2311 // layout(std140, set = 0, binding = 1) writeonly buffer Output {
2312 // float elements[];
2315 // void not_called_func() {
2316 // // place OpUnreachable here
2319 // uint modulo4(uint val) {
2320 // switch (val % uint(4)) {
2321 // case 0: return 3;
2322 // case 1: return 2;
2323 // case 2: return 1;
2324 // case 3: return 0;
2325 // default: return 100; // place OpUnreachable here
2331 // // place OpUnreachable here
2335 // uint x = gl_GlobalInvocationID.x;
2336 // if (const5() > modulo4(1000)) {
2337 // output_data.elements[x] = -input_data.elements[x];
2339 // // place OpUnreachable here
2340 // output_data.elements[x] = input_data.elements[x];
2344 tcu::TestCaseGroup* createOpUnreachableGroup (tcu::TestContext& testCtx)
2346 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opunreachable", "Test the OpUnreachable instruction"));
2347 ComputeShaderSpec spec;
2348 de::Random rnd (deStringHash(group->getName()));
2349 const int numElements = 100;
2350 vector<float> positiveFloats (numElements, 0);
2351 vector<float> negativeFloats (numElements, 0);
2353 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
2355 for (size_t ndx = 0; ndx < numElements; ++ndx)
2356 negativeFloats[ndx] = -positiveFloats[ndx];
2359 string(getComputeAsmShaderPreamble()) +
2361 "OpSource GLSL 430\n"
2362 "OpName %main \"main\"\n"
2363 "OpName %func_not_called_func \"not_called_func(\"\n"
2364 "OpName %func_modulo4 \"modulo4(u1;\"\n"
2365 "OpName %func_const5 \"const5(\"\n"
2366 "OpName %id \"gl_GlobalInvocationID\"\n"
2368 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2370 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
2372 "%u32ptr = OpTypePointer Function %u32\n"
2373 "%uintfuint = OpTypeFunction %u32 %u32ptr\n"
2374 "%unitf = OpTypeFunction %u32\n"
2376 "%id = OpVariable %uvec3ptr Input\n"
2377 "%zero = OpConstant %u32 0\n"
2378 "%one = OpConstant %u32 1\n"
2379 "%two = OpConstant %u32 2\n"
2380 "%three = OpConstant %u32 3\n"
2381 "%four = OpConstant %u32 4\n"
2382 "%five = OpConstant %u32 5\n"
2383 "%hundred = OpConstant %u32 100\n"
2384 "%thousand = OpConstant %u32 1000\n"
2386 + string(getComputeAsmInputOutputBuffer()) +
2389 "%main = OpFunction %void None %voidf\n"
2390 "%main_entry = OpLabel\n"
2391 "%v_thousand = OpVariable %u32ptr Function %thousand\n"
2392 "%idval = OpLoad %uvec3 %id\n"
2393 "%x = OpCompositeExtract %u32 %idval 0\n"
2394 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
2395 "%inval = OpLoad %f32 %inloc\n"
2396 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2397 "%ret_const5 = OpFunctionCall %u32 %func_const5\n"
2398 "%ret_modulo4 = OpFunctionCall %u32 %func_modulo4 %v_thousand\n"
2399 "%cmp_gt = OpUGreaterThan %bool %ret_const5 %ret_modulo4\n"
2400 " OpSelectionMerge %if_end None\n"
2401 " OpBranchConditional %cmp_gt %if_true %if_false\n"
2402 "%if_true = OpLabel\n"
2403 "%negate = OpFNegate %f32 %inval\n"
2404 " OpStore %outloc %negate\n"
2405 " OpBranch %if_end\n"
2406 "%if_false = OpLabel\n"
2407 " OpUnreachable\n" // Unreachable else branch for if statement
2408 "%if_end = OpLabel\n"
2412 // not_called_function()
2413 "%func_not_called_func = OpFunction %void None %voidf\n"
2414 "%not_called_func_entry = OpLabel\n"
2415 " OpUnreachable\n" // Unreachable entry block in not called static function
2419 "%func_modulo4 = OpFunction %u32 None %uintfuint\n"
2420 "%valptr = OpFunctionParameter %u32ptr\n"
2421 "%modulo4_entry = OpLabel\n"
2422 "%val = OpLoad %u32 %valptr\n"
2423 "%modulo = OpUMod %u32 %val %four\n"
2424 " OpSelectionMerge %switch_merge None\n"
2425 " OpSwitch %modulo %default 0 %case0 1 %case1 2 %case2 3 %case3\n"
2426 "%case0 = OpLabel\n"
2427 " OpReturnValue %three\n"
2428 "%case1 = OpLabel\n"
2429 " OpReturnValue %two\n"
2430 "%case2 = OpLabel\n"
2431 " OpReturnValue %one\n"
2432 "%case3 = OpLabel\n"
2433 " OpReturnValue %zero\n"
2434 "%default = OpLabel\n"
2435 " OpUnreachable\n" // Unreachable default case for switch statement
2436 "%switch_merge = OpLabel\n"
2437 " OpUnreachable\n" // Unreachable merge block for switch statement
2441 "%func_const5 = OpFunction %u32 None %unitf\n"
2442 "%const5_entry = OpLabel\n"
2443 " OpReturnValue %five\n"
2444 "%unreachable = OpLabel\n"
2445 " OpUnreachable\n" // Unreachable block in function
2447 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
2448 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
2449 spec.numWorkGroups = IVec3(numElements, 1, 1);
2451 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "OpUnreachable appearing at different places", spec));
2453 return group.release();
2456 // Assembly code used for testing decoration group is based on GLSL source code:
2460 // layout(std140, set = 0, binding = 0) readonly buffer Input0 {
2461 // float elements[];
2463 // layout(std140, set = 0, binding = 1) readonly buffer Input1 {
2464 // float elements[];
2466 // layout(std140, set = 0, binding = 2) readonly buffer Input2 {
2467 // float elements[];
2469 // layout(std140, set = 0, binding = 3) readonly buffer Input3 {
2470 // float elements[];
2472 // layout(std140, set = 0, binding = 4) readonly buffer Input4 {
2473 // float elements[];
2475 // layout(std140, set = 0, binding = 5) writeonly buffer Output {
2476 // float elements[];
2480 // uint x = gl_GlobalInvocationID.x;
2481 // output_data.elements[x] = input_data0.elements[x] + input_data1.elements[x] + input_data2.elements[x] + input_data3.elements[x] + input_data4.elements[x];
2483 tcu::TestCaseGroup* createDecorationGroupGroup (tcu::TestContext& testCtx)
2485 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "decoration_group", "Test the OpDecorationGroup & OpGroupDecorate instruction"));
2486 ComputeShaderSpec spec;
2487 de::Random rnd (deStringHash(group->getName()));
2488 const int numElements = 100;
2489 vector<float> inputFloats0 (numElements, 0);
2490 vector<float> inputFloats1 (numElements, 0);
2491 vector<float> inputFloats2 (numElements, 0);
2492 vector<float> inputFloats3 (numElements, 0);
2493 vector<float> inputFloats4 (numElements, 0);
2494 vector<float> outputFloats (numElements, 0);
2496 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats0[0], numElements);
2497 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats1[0], numElements);
2498 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats2[0], numElements);
2499 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats3[0], numElements);
2500 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats4[0], numElements);
2502 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
2503 floorAll(inputFloats0);
2504 floorAll(inputFloats1);
2505 floorAll(inputFloats2);
2506 floorAll(inputFloats3);
2507 floorAll(inputFloats4);
2509 for (size_t ndx = 0; ndx < numElements; ++ndx)
2510 outputFloats[ndx] = inputFloats0[ndx] + inputFloats1[ndx] + inputFloats2[ndx] + inputFloats3[ndx] + inputFloats4[ndx];
2513 string(getComputeAsmShaderPreamble()) +
2515 "OpSource GLSL 430\n"
2516 "OpName %main \"main\"\n"
2517 "OpName %id \"gl_GlobalInvocationID\"\n"
2519 // Not using group decoration on variable.
2520 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2521 // Not using group decoration on type.
2522 "OpDecorate %f32arr ArrayStride 4\n"
2524 "OpDecorate %groups BufferBlock\n"
2525 "OpDecorate %groupm Offset 0\n"
2526 "%groups = OpDecorationGroup\n"
2527 "%groupm = OpDecorationGroup\n"
2529 // Group decoration on multiple structs.
2530 "OpGroupDecorate %groups %outbuf %inbuf0 %inbuf1 %inbuf2 %inbuf3 %inbuf4\n"
2531 // Group decoration on multiple struct members.
2532 "OpGroupMemberDecorate %groupm %outbuf 0 %inbuf0 0 %inbuf1 0 %inbuf2 0 %inbuf3 0 %inbuf4 0\n"
2534 "OpDecorate %group1 DescriptorSet 0\n"
2535 "OpDecorate %group3 DescriptorSet 0\n"
2536 "OpDecorate %group3 NonWritable\n"
2537 "OpDecorate %group3 Restrict\n"
2538 "%group0 = OpDecorationGroup\n"
2539 "%group1 = OpDecorationGroup\n"
2540 "%group3 = OpDecorationGroup\n"
2542 // Applying the same decoration group multiple times.
2543 "OpGroupDecorate %group1 %outdata\n"
2544 "OpGroupDecorate %group1 %outdata\n"
2545 "OpGroupDecorate %group1 %outdata\n"
2546 "OpDecorate %outdata DescriptorSet 0\n"
2547 "OpDecorate %outdata Binding 5\n"
2548 // Applying decoration group containing nothing.
2549 "OpGroupDecorate %group0 %indata0\n"
2550 "OpDecorate %indata0 DescriptorSet 0\n"
2551 "OpDecorate %indata0 Binding 0\n"
2552 // Applying decoration group containing one decoration.
2553 "OpGroupDecorate %group1 %indata1\n"
2554 "OpDecorate %indata1 Binding 1\n"
2555 // Applying decoration group containing multiple decorations.
2556 "OpGroupDecorate %group3 %indata2 %indata3\n"
2557 "OpDecorate %indata2 Binding 2\n"
2558 "OpDecorate %indata3 Binding 3\n"
2559 // Applying multiple decoration groups (with overlapping).
2560 "OpGroupDecorate %group0 %indata4\n"
2561 "OpGroupDecorate %group1 %indata4\n"
2562 "OpGroupDecorate %group3 %indata4\n"
2563 "OpDecorate %indata4 Binding 4\n"
2565 + string(getComputeAsmCommonTypes()) +
2567 "%id = OpVariable %uvec3ptr Input\n"
2568 "%zero = OpConstant %i32 0\n"
2570 "%outbuf = OpTypeStruct %f32arr\n"
2571 "%outbufptr = OpTypePointer Uniform %outbuf\n"
2572 "%outdata = OpVariable %outbufptr Uniform\n"
2573 "%inbuf0 = OpTypeStruct %f32arr\n"
2574 "%inbuf0ptr = OpTypePointer Uniform %inbuf0\n"
2575 "%indata0 = OpVariable %inbuf0ptr Uniform\n"
2576 "%inbuf1 = OpTypeStruct %f32arr\n"
2577 "%inbuf1ptr = OpTypePointer Uniform %inbuf1\n"
2578 "%indata1 = OpVariable %inbuf1ptr Uniform\n"
2579 "%inbuf2 = OpTypeStruct %f32arr\n"
2580 "%inbuf2ptr = OpTypePointer Uniform %inbuf2\n"
2581 "%indata2 = OpVariable %inbuf2ptr Uniform\n"
2582 "%inbuf3 = OpTypeStruct %f32arr\n"
2583 "%inbuf3ptr = OpTypePointer Uniform %inbuf3\n"
2584 "%indata3 = OpVariable %inbuf3ptr Uniform\n"
2585 "%inbuf4 = OpTypeStruct %f32arr\n"
2586 "%inbufptr = OpTypePointer Uniform %inbuf4\n"
2587 "%indata4 = OpVariable %inbufptr Uniform\n"
2589 "%main = OpFunction %void None %voidf\n"
2590 "%label = OpLabel\n"
2591 "%idval = OpLoad %uvec3 %id\n"
2592 "%x = OpCompositeExtract %u32 %idval 0\n"
2593 "%inloc0 = OpAccessChain %f32ptr %indata0 %zero %x\n"
2594 "%inloc1 = OpAccessChain %f32ptr %indata1 %zero %x\n"
2595 "%inloc2 = OpAccessChain %f32ptr %indata2 %zero %x\n"
2596 "%inloc3 = OpAccessChain %f32ptr %indata3 %zero %x\n"
2597 "%inloc4 = OpAccessChain %f32ptr %indata4 %zero %x\n"
2598 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2599 "%inval0 = OpLoad %f32 %inloc0\n"
2600 "%inval1 = OpLoad %f32 %inloc1\n"
2601 "%inval2 = OpLoad %f32 %inloc2\n"
2602 "%inval3 = OpLoad %f32 %inloc3\n"
2603 "%inval4 = OpLoad %f32 %inloc4\n"
2604 "%add0 = OpFAdd %f32 %inval0 %inval1\n"
2605 "%add1 = OpFAdd %f32 %add0 %inval2\n"
2606 "%add2 = OpFAdd %f32 %add1 %inval3\n"
2607 "%add = OpFAdd %f32 %add2 %inval4\n"
2608 " OpStore %outloc %add\n"
2611 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats0)));
2612 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats1)));
2613 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
2614 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats3)));
2615 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats4)));
2616 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
2617 spec.numWorkGroups = IVec3(numElements, 1, 1);
2619 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "decoration group cases", spec));
2621 return group.release();
2624 struct SpecConstantTwoIntCase
2626 const char* caseName;
2627 const char* scDefinition0;
2628 const char* scDefinition1;
2629 const char* scResultType;
2630 const char* scOperation;
2631 deInt32 scActualValue0;
2632 deInt32 scActualValue1;
2633 const char* resultOperation;
2634 vector<deInt32> expectedOutput;
2635 deInt32 scActualValueLength;
2637 SpecConstantTwoIntCase (const char* name,
2638 const char* definition0,
2639 const char* definition1,
2640 const char* resultType,
2641 const char* operation,
2644 const char* resultOp,
2645 const vector<deInt32>& output,
2646 const deInt32 valueLength = sizeof(deInt32))
2648 , scDefinition0 (definition0)
2649 , scDefinition1 (definition1)
2650 , scResultType (resultType)
2651 , scOperation (operation)
2652 , scActualValue0 (value0)
2653 , scActualValue1 (value1)
2654 , resultOperation (resultOp)
2655 , expectedOutput (output)
2656 , scActualValueLength (valueLength)
2660 tcu::TestCaseGroup* createSpecConstantGroup (tcu::TestContext& testCtx)
2662 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opspecconstantop", "Test the OpSpecConstantOp instruction"));
2663 vector<SpecConstantTwoIntCase> cases;
2664 de::Random rnd (deStringHash(group->getName()));
2665 const int numElements = 100;
2666 const deInt32 p1AsFloat16 = 0x3c00; // +1(fp16) == 0 01111 0000000000 == 0011 1100 0000 0000
2667 vector<deInt32> inputInts (numElements, 0);
2668 vector<deInt32> outputInts1 (numElements, 0);
2669 vector<deInt32> outputInts2 (numElements, 0);
2670 vector<deInt32> outputInts3 (numElements, 0);
2671 vector<deInt32> outputInts4 (numElements, 0);
2672 const StringTemplate shaderTemplate (
2673 "${CAPABILITIES:opt}"
2674 + string(getComputeAsmShaderPreamble()) +
2676 "OpName %main \"main\"\n"
2677 "OpName %id \"gl_GlobalInvocationID\"\n"
2679 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2680 "OpDecorate %sc_0 SpecId 0\n"
2681 "OpDecorate %sc_1 SpecId 1\n"
2682 "OpDecorate %i32arr ArrayStride 4\n"
2684 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
2686 "${OPTYPE_DEFINITIONS:opt}"
2687 "%buf = OpTypeStruct %i32arr\n"
2688 "%bufptr = OpTypePointer Uniform %buf\n"
2689 "%indata = OpVariable %bufptr Uniform\n"
2690 "%outdata = OpVariable %bufptr Uniform\n"
2692 "%id = OpVariable %uvec3ptr Input\n"
2693 "%zero = OpConstant %i32 0\n"
2695 "%sc_0 = OpSpecConstant${SC_DEF0}\n"
2696 "%sc_1 = OpSpecConstant${SC_DEF1}\n"
2697 "%sc_final = OpSpecConstantOp ${SC_RESULT_TYPE} ${SC_OP}\n"
2699 "%main = OpFunction %void None %voidf\n"
2700 "%label = OpLabel\n"
2701 "${TYPE_CONVERT:opt}"
2702 "%idval = OpLoad %uvec3 %id\n"
2703 "%x = OpCompositeExtract %u32 %idval 0\n"
2704 "%inloc = OpAccessChain %i32ptr %indata %zero %x\n"
2705 "%inval = OpLoad %i32 %inloc\n"
2706 "%final = ${GEN_RESULT}\n"
2707 "%outloc = OpAccessChain %i32ptr %outdata %zero %x\n"
2708 " OpStore %outloc %final\n"
2710 " OpFunctionEnd\n");
2712 fillRandomScalars(rnd, -65536, 65536, &inputInts[0], numElements);
2714 for (size_t ndx = 0; ndx < numElements; ++ndx)
2716 outputInts1[ndx] = inputInts[ndx] + 42;
2717 outputInts2[ndx] = inputInts[ndx];
2718 outputInts3[ndx] = inputInts[ndx] - 11200;
2719 outputInts4[ndx] = inputInts[ndx] + 1;
2722 const char addScToInput[] = "OpIAdd %i32 %inval %sc_final";
2723 const char addSc32ToInput[] = "OpIAdd %i32 %inval %sc_final32";
2724 const char selectTrueUsingSc[] = "OpSelect %i32 %sc_final %inval %zero";
2725 const char selectFalseUsingSc[] = "OpSelect %i32 %sc_final %zero %inval";
2727 cases.push_back(SpecConstantTwoIntCase("iadd", " %i32 0", " %i32 0", "%i32", "IAdd %sc_0 %sc_1", 62, -20, addScToInput, outputInts1));
2728 cases.push_back(SpecConstantTwoIntCase("isub", " %i32 0", " %i32 0", "%i32", "ISub %sc_0 %sc_1", 100, 58, addScToInput, outputInts1));
2729 cases.push_back(SpecConstantTwoIntCase("imul", " %i32 0", " %i32 0", "%i32", "IMul %sc_0 %sc_1", -2, -21, addScToInput, outputInts1));
2730 cases.push_back(SpecConstantTwoIntCase("sdiv", " %i32 0", " %i32 0", "%i32", "SDiv %sc_0 %sc_1", -126, -3, addScToInput, outputInts1));
2731 cases.push_back(SpecConstantTwoIntCase("udiv", " %i32 0", " %i32 0", "%i32", "UDiv %sc_0 %sc_1", 126, 3, addScToInput, outputInts1));
2732 cases.push_back(SpecConstantTwoIntCase("srem", " %i32 0", " %i32 0", "%i32", "SRem %sc_0 %sc_1", 7, 3, addScToInput, outputInts4));
2733 cases.push_back(SpecConstantTwoIntCase("smod", " %i32 0", " %i32 0", "%i32", "SMod %sc_0 %sc_1", 7, 3, addScToInput, outputInts4));
2734 cases.push_back(SpecConstantTwoIntCase("umod", " %i32 0", " %i32 0", "%i32", "UMod %sc_0 %sc_1", 342, 50, addScToInput, outputInts1));
2735 cases.push_back(SpecConstantTwoIntCase("bitwiseand", " %i32 0", " %i32 0", "%i32", "BitwiseAnd %sc_0 %sc_1", 42, 63, addScToInput, outputInts1));
2736 cases.push_back(SpecConstantTwoIntCase("bitwiseor", " %i32 0", " %i32 0", "%i32", "BitwiseOr %sc_0 %sc_1", 34, 8, addScToInput, outputInts1));
2737 cases.push_back(SpecConstantTwoIntCase("bitwisexor", " %i32 0", " %i32 0", "%i32", "BitwiseXor %sc_0 %sc_1", 18, 56, addScToInput, outputInts1));
2738 cases.push_back(SpecConstantTwoIntCase("shiftrightlogical", " %i32 0", " %i32 0", "%i32", "ShiftRightLogical %sc_0 %sc_1", 168, 2, addScToInput, outputInts1));
2739 cases.push_back(SpecConstantTwoIntCase("shiftrightarithmetic", " %i32 0", " %i32 0", "%i32", "ShiftRightArithmetic %sc_0 %sc_1", 168, 2, addScToInput, outputInts1));
2740 cases.push_back(SpecConstantTwoIntCase("shiftleftlogical", " %i32 0", " %i32 0", "%i32", "ShiftLeftLogical %sc_0 %sc_1", 21, 1, addScToInput, outputInts1));
2741 cases.push_back(SpecConstantTwoIntCase("slessthan", " %i32 0", " %i32 0", "%bool", "SLessThan %sc_0 %sc_1", -20, -10, selectTrueUsingSc, outputInts2));
2742 cases.push_back(SpecConstantTwoIntCase("ulessthan", " %i32 0", " %i32 0", "%bool", "ULessThan %sc_0 %sc_1", 10, 20, selectTrueUsingSc, outputInts2));
2743 cases.push_back(SpecConstantTwoIntCase("sgreaterthan", " %i32 0", " %i32 0", "%bool", "SGreaterThan %sc_0 %sc_1", -1000, 50, selectFalseUsingSc, outputInts2));
2744 cases.push_back(SpecConstantTwoIntCase("ugreaterthan", " %i32 0", " %i32 0", "%bool", "UGreaterThan %sc_0 %sc_1", 10, 5, selectTrueUsingSc, outputInts2));
2745 cases.push_back(SpecConstantTwoIntCase("slessthanequal", " %i32 0", " %i32 0", "%bool", "SLessThanEqual %sc_0 %sc_1", -10, -10, selectTrueUsingSc, outputInts2));
2746 cases.push_back(SpecConstantTwoIntCase("ulessthanequal", " %i32 0", " %i32 0", "%bool", "ULessThanEqual %sc_0 %sc_1", 50, 100, selectTrueUsingSc, outputInts2));
2747 cases.push_back(SpecConstantTwoIntCase("sgreaterthanequal", " %i32 0", " %i32 0", "%bool", "SGreaterThanEqual %sc_0 %sc_1", -1000, 50, selectFalseUsingSc, outputInts2));
2748 cases.push_back(SpecConstantTwoIntCase("ugreaterthanequal", " %i32 0", " %i32 0", "%bool", "UGreaterThanEqual %sc_0 %sc_1", 10, 10, selectTrueUsingSc, outputInts2));
2749 cases.push_back(SpecConstantTwoIntCase("iequal", " %i32 0", " %i32 0", "%bool", "IEqual %sc_0 %sc_1", 42, 24, selectFalseUsingSc, outputInts2));
2750 cases.push_back(SpecConstantTwoIntCase("inotequal", " %i32 0", " %i32 0", "%bool", "INotEqual %sc_0 %sc_1", 42, 24, selectTrueUsingSc, outputInts2));
2751 cases.push_back(SpecConstantTwoIntCase("logicaland", "True %bool", "True %bool", "%bool", "LogicalAnd %sc_0 %sc_1", 0, 1, selectFalseUsingSc, outputInts2));
2752 cases.push_back(SpecConstantTwoIntCase("logicalor", "False %bool", "False %bool", "%bool", "LogicalOr %sc_0 %sc_1", 1, 0, selectTrueUsingSc, outputInts2));
2753 cases.push_back(SpecConstantTwoIntCase("logicalequal", "True %bool", "True %bool", "%bool", "LogicalEqual %sc_0 %sc_1", 0, 1, selectFalseUsingSc, outputInts2));
2754 cases.push_back(SpecConstantTwoIntCase("logicalnotequal", "False %bool", "False %bool", "%bool", "LogicalNotEqual %sc_0 %sc_1", 1, 0, selectTrueUsingSc, outputInts2));
2755 cases.push_back(SpecConstantTwoIntCase("snegate", " %i32 0", " %i32 0", "%i32", "SNegate %sc_0", -42, 0, addScToInput, outputInts1));
2756 cases.push_back(SpecConstantTwoIntCase("not", " %i32 0", " %i32 0", "%i32", "Not %sc_0", -43, 0, addScToInput, outputInts1));
2757 cases.push_back(SpecConstantTwoIntCase("logicalnot", "False %bool", "False %bool", "%bool", "LogicalNot %sc_0", 1, 0, selectFalseUsingSc, outputInts2));
2758 cases.push_back(SpecConstantTwoIntCase("select", "False %bool", " %i32 0", "%i32", "Select %sc_0 %sc_1 %zero", 1, 42, addScToInput, outputInts1));
2759 cases.push_back(SpecConstantTwoIntCase("sconvert", " %i32 0", " %i32 0", "%i16", "SConvert %sc_0", -11200, 0, addSc32ToInput, outputInts3));
2760 // -969998336 stored as 32-bit two's complement is the binary representation of -11200 as IEEE-754 Float
2761 cases.push_back(SpecConstantTwoIntCase("fconvert", " %f32 0", " %f32 0", "%f64", "FConvert %sc_0", -969998336, 0, addSc32ToInput, outputInts3));
2762 cases.push_back(SpecConstantTwoIntCase("fconvert16", " %f16 0", " %f16 0", "%f32", "FConvert %sc_0", p1AsFloat16, 0, addSc32ToInput, outputInts4, sizeof(deFloat16)));
2764 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
2766 map<string, string> specializations;
2767 ComputeShaderSpec spec;
2769 specializations["SC_DEF0"] = cases[caseNdx].scDefinition0;
2770 specializations["SC_DEF1"] = cases[caseNdx].scDefinition1;
2771 specializations["SC_RESULT_TYPE"] = cases[caseNdx].scResultType;
2772 specializations["SC_OP"] = cases[caseNdx].scOperation;
2773 specializations["GEN_RESULT"] = cases[caseNdx].resultOperation;
2775 // Special SPIR-V code for SConvert-case
2776 if (strcmp(cases[caseNdx].caseName, "sconvert") == 0)
2778 spec.requestedVulkanFeatures.coreFeatures.shaderInt16 = VK_TRUE;
2779 specializations["CAPABILITIES"] = "OpCapability Int16\n"; // Adds 16-bit integer capability
2780 specializations["OPTYPE_DEFINITIONS"] = "%i16 = OpTypeInt 16 1\n"; // Adds 16-bit integer type
2781 specializations["TYPE_CONVERT"] = "%sc_final32 = OpSConvert %i32 %sc_final\n"; // Converts 16-bit integer to 32-bit integer
2784 // Special SPIR-V code for FConvert-case
2785 if (strcmp(cases[caseNdx].caseName, "fconvert") == 0)
2787 spec.requestedVulkanFeatures.coreFeatures.shaderFloat64 = VK_TRUE;
2788 specializations["CAPABILITIES"] = "OpCapability Float64\n"; // Adds 64-bit float capability
2789 specializations["OPTYPE_DEFINITIONS"] = "%f64 = OpTypeFloat 64\n"; // Adds 64-bit float type
2790 specializations["TYPE_CONVERT"] = "%sc_final32 = OpConvertFToS %i32 %sc_final\n"; // Converts 64-bit float to 32-bit integer
2793 // Special SPIR-V code for FConvert-case for 16-bit floats
2794 if (strcmp(cases[caseNdx].caseName, "fconvert16") == 0)
2796 spec.extensions.push_back("VK_KHR_shader_float16_int8");
2797 spec.requestedVulkanFeatures.extFloat16Int8 = EXTFLOAT16INT8FEATURES_FLOAT16;
2798 specializations["CAPABILITIES"] = "OpCapability Float16\n"; // Adds 16-bit float capability
2799 specializations["OPTYPE_DEFINITIONS"] = "%f16 = OpTypeFloat 16\n"; // Adds 16-bit float type
2800 specializations["TYPE_CONVERT"] = "%sc_final32 = OpConvertFToS %i32 %sc_final\n"; // Converts 16-bit float to 32-bit integer
2803 spec.assembly = shaderTemplate.specialize(specializations);
2804 spec.inputs.push_back(BufferSp(new Int32Buffer(inputInts)));
2805 spec.outputs.push_back(BufferSp(new Int32Buffer(cases[caseNdx].expectedOutput)));
2806 spec.numWorkGroups = IVec3(numElements, 1, 1);
2807 spec.specConstants.append(&cases[caseNdx].scActualValue0, cases[caseNdx].scActualValueLength);
2808 spec.specConstants.append(&cases[caseNdx].scActualValue1, cases[caseNdx].scActualValueLength);
2810 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].caseName, cases[caseNdx].caseName, spec));
2813 ComputeShaderSpec spec;
2816 string(getComputeAsmShaderPreamble()) +
2818 "OpName %main \"main\"\n"
2819 "OpName %id \"gl_GlobalInvocationID\"\n"
2821 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2822 "OpDecorate %sc_0 SpecId 0\n"
2823 "OpDecorate %sc_1 SpecId 1\n"
2824 "OpDecorate %sc_2 SpecId 2\n"
2825 "OpDecorate %i32arr ArrayStride 4\n"
2827 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
2829 "%ivec3 = OpTypeVector %i32 3\n"
2830 "%buf = OpTypeStruct %i32arr\n"
2831 "%bufptr = OpTypePointer Uniform %buf\n"
2832 "%indata = OpVariable %bufptr Uniform\n"
2833 "%outdata = OpVariable %bufptr Uniform\n"
2835 "%id = OpVariable %uvec3ptr Input\n"
2836 "%zero = OpConstant %i32 0\n"
2837 "%ivec3_0 = OpConstantComposite %ivec3 %zero %zero %zero\n"
2838 "%vec3_undef = OpUndef %ivec3\n"
2840 "%sc_0 = OpSpecConstant %i32 0\n"
2841 "%sc_1 = OpSpecConstant %i32 0\n"
2842 "%sc_2 = OpSpecConstant %i32 0\n"
2843 "%sc_vec3_0 = OpSpecConstantOp %ivec3 CompositeInsert %sc_0 %ivec3_0 0\n" // (sc_0, 0, 0)
2844 "%sc_vec3_1 = OpSpecConstantOp %ivec3 CompositeInsert %sc_1 %ivec3_0 1\n" // (0, sc_1, 0)
2845 "%sc_vec3_2 = OpSpecConstantOp %ivec3 CompositeInsert %sc_2 %ivec3_0 2\n" // (0, 0, sc_2)
2846 "%sc_vec3_0_s = OpSpecConstantOp %ivec3 VectorShuffle %sc_vec3_0 %vec3_undef 0 0xFFFFFFFF 2\n" // (sc_0, ???, 0)
2847 "%sc_vec3_1_s = OpSpecConstantOp %ivec3 VectorShuffle %sc_vec3_1 %vec3_undef 0xFFFFFFFF 1 0\n" // (???, sc_1, 0)
2848 "%sc_vec3_2_s = OpSpecConstantOp %ivec3 VectorShuffle %vec3_undef %sc_vec3_2 5 0xFFFFFFFF 5\n" // (sc_2, ???, sc_2)
2849 "%sc_vec3_01 = OpSpecConstantOp %ivec3 VectorShuffle %sc_vec3_0_s %sc_vec3_1_s 1 0 4\n" // (0, sc_0, sc_1)
2850 "%sc_vec3_012 = OpSpecConstantOp %ivec3 VectorShuffle %sc_vec3_01 %sc_vec3_2_s 5 1 2\n" // (sc_2, sc_0, sc_1)
2851 "%sc_ext_0 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 0\n" // sc_2
2852 "%sc_ext_1 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 1\n" // sc_0
2853 "%sc_ext_2 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 2\n" // sc_1
2854 "%sc_sub = OpSpecConstantOp %i32 ISub %sc_ext_0 %sc_ext_1\n" // (sc_2 - sc_0)
2855 "%sc_final = OpSpecConstantOp %i32 IMul %sc_sub %sc_ext_2\n" // (sc_2 - sc_0) * sc_1
2857 "%main = OpFunction %void None %voidf\n"
2858 "%label = OpLabel\n"
2859 "%idval = OpLoad %uvec3 %id\n"
2860 "%x = OpCompositeExtract %u32 %idval 0\n"
2861 "%inloc = OpAccessChain %i32ptr %indata %zero %x\n"
2862 "%inval = OpLoad %i32 %inloc\n"
2863 "%final = OpIAdd %i32 %inval %sc_final\n"
2864 "%outloc = OpAccessChain %i32ptr %outdata %zero %x\n"
2865 " OpStore %outloc %final\n"
2868 spec.inputs.push_back(BufferSp(new Int32Buffer(inputInts)));
2869 spec.outputs.push_back(BufferSp(new Int32Buffer(outputInts3)));
2870 spec.numWorkGroups = IVec3(numElements, 1, 1);
2871 spec.specConstants.append<deInt32>(123);
2872 spec.specConstants.append<deInt32>(56);
2873 spec.specConstants.append<deInt32>(-77);
2875 group->addChild(new SpvAsmComputeShaderCase(testCtx, "vector_related", "VectorShuffle, CompositeExtract, & CompositeInsert", spec));
2877 return group.release();
2880 void createOpPhiVartypeTests (de::MovePtr<tcu::TestCaseGroup>& group, tcu::TestContext& testCtx)
2882 ComputeShaderSpec specInt;
2883 ComputeShaderSpec specFloat;
2884 ComputeShaderSpec specFloat16;
2885 ComputeShaderSpec specVec3;
2886 ComputeShaderSpec specMat4;
2887 ComputeShaderSpec specArray;
2888 ComputeShaderSpec specStruct;
2889 de::Random rnd (deStringHash(group->getName()));
2890 const int numElements = 100;
2891 vector<float> inputFloats (numElements, 0);
2892 vector<float> outputFloats (numElements, 0);
2893 vector<deFloat16> inputFloats16 (numElements, 0);
2894 vector<deFloat16> outputFloats16 (numElements, 0);
2896 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats[0], numElements);
2898 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
2899 floorAll(inputFloats);
2901 for (size_t ndx = 0; ndx < numElements; ++ndx)
2903 // Just check if the value is positive or not
2904 outputFloats[ndx] = (inputFloats[ndx] > 0) ? 1.0f : -1.0f;
2907 for (size_t ndx = 0; ndx < numElements; ++ndx)
2909 inputFloats16[ndx] = tcu::Float16(inputFloats[ndx]).bits();
2910 outputFloats16[ndx] = tcu::Float16(outputFloats[ndx]).bits();
2913 // All of the tests are of the form:
2917 // if (inputdata > 0)
2924 specFloat.assembly =
2925 string(getComputeAsmShaderPreamble()) +
2927 "OpSource GLSL 430\n"
2928 "OpName %main \"main\"\n"
2929 "OpName %id \"gl_GlobalInvocationID\"\n"
2931 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2933 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
2935 "%id = OpVariable %uvec3ptr Input\n"
2936 "%zero = OpConstant %i32 0\n"
2937 "%float_0 = OpConstant %f32 0.0\n"
2938 "%float_1 = OpConstant %f32 1.0\n"
2939 "%float_n1 = OpConstant %f32 -1.0\n"
2941 "%main = OpFunction %void None %voidf\n"
2942 "%entry = OpLabel\n"
2943 "%idval = OpLoad %uvec3 %id\n"
2944 "%x = OpCompositeExtract %u32 %idval 0\n"
2945 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
2946 "%inval = OpLoad %f32 %inloc\n"
2948 "%comp = OpFOrdGreaterThan %bool %inval %float_0\n"
2949 " OpSelectionMerge %cm None\n"
2950 " OpBranchConditional %comp %tb %fb\n"
2956 "%res = OpPhi %f32 %float_1 %tb %float_n1 %fb\n"
2958 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2959 " OpStore %outloc %res\n"
2963 specFloat.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
2964 specFloat.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
2965 specFloat.numWorkGroups = IVec3(numElements, 1, 1);
2967 specFloat16.assembly =
2968 "OpCapability Shader\n"
2969 "OpCapability StorageUniformBufferBlock16\n"
2970 "OpExtension \"SPV_KHR_16bit_storage\"\n"
2971 "OpMemoryModel Logical GLSL450\n"
2972 "OpEntryPoint GLCompute %main \"main\" %id\n"
2973 "OpExecutionMode %main LocalSize 1 1 1\n"
2975 "OpSource GLSL 430\n"
2976 "OpName %main \"main\"\n"
2977 "OpName %id \"gl_GlobalInvocationID\"\n"
2979 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2981 "OpDecorate %buf BufferBlock\n"
2982 "OpDecorate %indata DescriptorSet 0\n"
2983 "OpDecorate %indata Binding 0\n"
2984 "OpDecorate %outdata DescriptorSet 0\n"
2985 "OpDecorate %outdata Binding 1\n"
2986 "OpDecorate %f16arr ArrayStride 2\n"
2987 "OpMemberDecorate %buf 0 Offset 0\n"
2989 "%f16 = OpTypeFloat 16\n"
2990 "%f16ptr = OpTypePointer Uniform %f16\n"
2991 "%f16arr = OpTypeRuntimeArray %f16\n"
2993 + string(getComputeAsmCommonTypes()) +
2995 "%buf = OpTypeStruct %f16arr\n"
2996 "%bufptr = OpTypePointer Uniform %buf\n"
2997 "%indata = OpVariable %bufptr Uniform\n"
2998 "%outdata = OpVariable %bufptr Uniform\n"
3000 "%id = OpVariable %uvec3ptr Input\n"
3001 "%zero = OpConstant %i32 0\n"
3002 "%float_0 = OpConstant %f16 0.0\n"
3003 "%float_1 = OpConstant %f16 1.0\n"
3004 "%float_n1 = OpConstant %f16 -1.0\n"
3006 "%main = OpFunction %void None %voidf\n"
3007 "%entry = OpLabel\n"
3008 "%idval = OpLoad %uvec3 %id\n"
3009 "%x = OpCompositeExtract %u32 %idval 0\n"
3010 "%inloc = OpAccessChain %f16ptr %indata %zero %x\n"
3011 "%inval = OpLoad %f16 %inloc\n"
3013 "%comp = OpFOrdGreaterThan %bool %inval %float_0\n"
3014 " OpSelectionMerge %cm None\n"
3015 " OpBranchConditional %comp %tb %fb\n"
3021 "%res = OpPhi %f16 %float_1 %tb %float_n1 %fb\n"
3023 "%outloc = OpAccessChain %f16ptr %outdata %zero %x\n"
3024 " OpStore %outloc %res\n"
3028 specFloat16.inputs.push_back(BufferSp(new Float16Buffer(inputFloats16)));
3029 specFloat16.outputs.push_back(BufferSp(new Float16Buffer(outputFloats16)));
3030 specFloat16.numWorkGroups = IVec3(numElements, 1, 1);
3031 specFloat16.requestedVulkanFeatures.ext16BitStorage = EXT16BITSTORAGEFEATURES_UNIFORM_BUFFER_BLOCK;
3032 specFloat16.requestedVulkanFeatures.extFloat16Int8 = EXTFLOAT16INT8FEATURES_FLOAT16;
3035 string(getComputeAsmShaderPreamble()) +
3037 "OpSource GLSL 430\n"
3038 "OpName %main \"main\"\n"
3039 "OpName %id \"gl_GlobalInvocationID\"\n"
3041 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3043 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
3045 "%id = OpVariable %uvec3ptr Input\n"
3046 "%v4f32 = OpTypeVector %f32 4\n"
3047 "%mat4v4f32 = OpTypeMatrix %v4f32 4\n"
3048 "%zero = OpConstant %i32 0\n"
3049 "%float_0 = OpConstant %f32 0.0\n"
3050 "%float_1 = OpConstant %f32 1.0\n"
3051 "%float_n1 = OpConstant %f32 -1.0\n"
3052 "%m11 = OpConstantComposite %v4f32 %float_1 %float_0 %float_0 %float_0\n"
3053 "%m12 = OpConstantComposite %v4f32 %float_0 %float_1 %float_0 %float_0\n"
3054 "%m13 = OpConstantComposite %v4f32 %float_0 %float_0 %float_1 %float_0\n"
3055 "%m14 = OpConstantComposite %v4f32 %float_0 %float_0 %float_0 %float_1\n"
3056 "%m1 = OpConstantComposite %mat4v4f32 %m11 %m12 %m13 %m14\n"
3057 "%m21 = OpConstantComposite %v4f32 %float_n1 %float_0 %float_0 %float_0\n"
3058 "%m22 = OpConstantComposite %v4f32 %float_0 %float_n1 %float_0 %float_0\n"
3059 "%m23 = OpConstantComposite %v4f32 %float_0 %float_0 %float_n1 %float_0\n"
3060 "%m24 = OpConstantComposite %v4f32 %float_0 %float_0 %float_0 %float_n1\n"
3061 "%m2 = OpConstantComposite %mat4v4f32 %m21 %m22 %m23 %m24\n"
3063 "%main = OpFunction %void None %voidf\n"
3064 "%entry = OpLabel\n"
3065 "%idval = OpLoad %uvec3 %id\n"
3066 "%x = OpCompositeExtract %u32 %idval 0\n"
3067 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3068 "%inval = OpLoad %f32 %inloc\n"
3070 "%comp = OpFOrdGreaterThan %bool %inval %float_0\n"
3071 " OpSelectionMerge %cm None\n"
3072 " OpBranchConditional %comp %tb %fb\n"
3078 "%mres = OpPhi %mat4v4f32 %m1 %tb %m2 %fb\n"
3079 "%res = OpCompositeExtract %f32 %mres 2 2\n"
3081 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3082 " OpStore %outloc %res\n"
3086 specMat4.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
3087 specMat4.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
3088 specMat4.numWorkGroups = IVec3(numElements, 1, 1);
3091 string(getComputeAsmShaderPreamble()) +
3093 "OpSource GLSL 430\n"
3094 "OpName %main \"main\"\n"
3095 "OpName %id \"gl_GlobalInvocationID\"\n"
3097 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3099 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
3101 "%id = OpVariable %uvec3ptr Input\n"
3102 "%zero = OpConstant %i32 0\n"
3103 "%float_0 = OpConstant %f32 0.0\n"
3104 "%float_1 = OpConstant %f32 1.0\n"
3105 "%float_n1 = OpConstant %f32 -1.0\n"
3106 "%v1 = OpConstantComposite %fvec3 %float_1 %float_1 %float_1\n"
3107 "%v2 = OpConstantComposite %fvec3 %float_n1 %float_n1 %float_n1\n"
3109 "%main = OpFunction %void None %voidf\n"
3110 "%entry = OpLabel\n"
3111 "%idval = OpLoad %uvec3 %id\n"
3112 "%x = OpCompositeExtract %u32 %idval 0\n"
3113 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3114 "%inval = OpLoad %f32 %inloc\n"
3116 "%comp = OpFOrdGreaterThan %bool %inval %float_0\n"
3117 " OpSelectionMerge %cm None\n"
3118 " OpBranchConditional %comp %tb %fb\n"
3124 "%vres = OpPhi %fvec3 %v1 %tb %v2 %fb\n"
3125 "%res = OpCompositeExtract %f32 %vres 2\n"
3127 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3128 " OpStore %outloc %res\n"
3132 specVec3.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
3133 specVec3.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
3134 specVec3.numWorkGroups = IVec3(numElements, 1, 1);
3137 string(getComputeAsmShaderPreamble()) +
3139 "OpSource GLSL 430\n"
3140 "OpName %main \"main\"\n"
3141 "OpName %id \"gl_GlobalInvocationID\"\n"
3143 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3145 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
3147 "%id = OpVariable %uvec3ptr Input\n"
3148 "%zero = OpConstant %i32 0\n"
3149 "%float_0 = OpConstant %f32 0.0\n"
3150 "%i1 = OpConstant %i32 1\n"
3151 "%i2 = OpConstant %i32 -1\n"
3153 "%main = OpFunction %void None %voidf\n"
3154 "%entry = OpLabel\n"
3155 "%idval = OpLoad %uvec3 %id\n"
3156 "%x = OpCompositeExtract %u32 %idval 0\n"
3157 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3158 "%inval = OpLoad %f32 %inloc\n"
3160 "%comp = OpFOrdGreaterThan %bool %inval %float_0\n"
3161 " OpSelectionMerge %cm None\n"
3162 " OpBranchConditional %comp %tb %fb\n"
3168 "%ires = OpPhi %i32 %i1 %tb %i2 %fb\n"
3169 "%res = OpConvertSToF %f32 %ires\n"
3171 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3172 " OpStore %outloc %res\n"
3176 specInt.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
3177 specInt.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
3178 specInt.numWorkGroups = IVec3(numElements, 1, 1);
3180 specArray.assembly =
3181 string(getComputeAsmShaderPreamble()) +
3183 "OpSource GLSL 430\n"
3184 "OpName %main \"main\"\n"
3185 "OpName %id \"gl_GlobalInvocationID\"\n"
3187 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3189 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
3191 "%id = OpVariable %uvec3ptr Input\n"
3192 "%zero = OpConstant %i32 0\n"
3193 "%u7 = OpConstant %u32 7\n"
3194 "%float_0 = OpConstant %f32 0.0\n"
3195 "%float_1 = OpConstant %f32 1.0\n"
3196 "%float_n1 = OpConstant %f32 -1.0\n"
3197 "%f32a7 = OpTypeArray %f32 %u7\n"
3198 "%a1 = OpConstantComposite %f32a7 %float_1 %float_1 %float_1 %float_1 %float_1 %float_1 %float_1\n"
3199 "%a2 = OpConstantComposite %f32a7 %float_n1 %float_n1 %float_n1 %float_n1 %float_n1 %float_n1 %float_n1\n"
3200 "%main = OpFunction %void None %voidf\n"
3201 "%entry = OpLabel\n"
3202 "%idval = OpLoad %uvec3 %id\n"
3203 "%x = OpCompositeExtract %u32 %idval 0\n"
3204 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3205 "%inval = OpLoad %f32 %inloc\n"
3207 "%comp = OpFOrdGreaterThan %bool %inval %float_0\n"
3208 " OpSelectionMerge %cm None\n"
3209 " OpBranchConditional %comp %tb %fb\n"
3215 "%ares = OpPhi %f32a7 %a1 %tb %a2 %fb\n"
3216 "%res = OpCompositeExtract %f32 %ares 5\n"
3218 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3219 " OpStore %outloc %res\n"
3223 specArray.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
3224 specArray.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
3225 specArray.numWorkGroups = IVec3(numElements, 1, 1);
3227 specStruct.assembly =
3228 string(getComputeAsmShaderPreamble()) +
3230 "OpSource GLSL 430\n"
3231 "OpName %main \"main\"\n"
3232 "OpName %id \"gl_GlobalInvocationID\"\n"
3234 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3236 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
3238 "%id = OpVariable %uvec3ptr Input\n"
3239 "%zero = OpConstant %i32 0\n"
3240 "%float_0 = OpConstant %f32 0.0\n"
3241 "%float_1 = OpConstant %f32 1.0\n"
3242 "%float_n1 = OpConstant %f32 -1.0\n"
3244 "%v2f32 = OpTypeVector %f32 2\n"
3245 "%Data2 = OpTypeStruct %f32 %v2f32\n"
3246 "%Data = OpTypeStruct %Data2 %f32\n"
3248 "%in1a = OpConstantComposite %v2f32 %float_1 %float_1\n"
3249 "%in1b = OpConstantComposite %Data2 %float_1 %in1a\n"
3250 "%s1 = OpConstantComposite %Data %in1b %float_1\n"
3251 "%in2a = OpConstantComposite %v2f32 %float_n1 %float_n1\n"
3252 "%in2b = OpConstantComposite %Data2 %float_n1 %in2a\n"
3253 "%s2 = OpConstantComposite %Data %in2b %float_n1\n"
3255 "%main = OpFunction %void None %voidf\n"
3256 "%entry = OpLabel\n"
3257 "%idval = OpLoad %uvec3 %id\n"
3258 "%x = OpCompositeExtract %u32 %idval 0\n"
3259 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3260 "%inval = OpLoad %f32 %inloc\n"
3262 "%comp = OpFOrdGreaterThan %bool %inval %float_0\n"
3263 " OpSelectionMerge %cm None\n"
3264 " OpBranchConditional %comp %tb %fb\n"
3270 "%sres = OpPhi %Data %s1 %tb %s2 %fb\n"
3271 "%res = OpCompositeExtract %f32 %sres 0 0\n"
3273 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3274 " OpStore %outloc %res\n"
3278 specStruct.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
3279 specStruct.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
3280 specStruct.numWorkGroups = IVec3(numElements, 1, 1);
3282 group->addChild(new SpvAsmComputeShaderCase(testCtx, "vartype_int", "OpPhi with int variables", specInt));
3283 group->addChild(new SpvAsmComputeShaderCase(testCtx, "vartype_float", "OpPhi with float variables", specFloat));
3284 group->addChild(new SpvAsmComputeShaderCase(testCtx, "vartype_float16", "OpPhi with 16bit float variables", specFloat16));
3285 group->addChild(new SpvAsmComputeShaderCase(testCtx, "vartype_vec3", "OpPhi with vec3 variables", specVec3));
3286 group->addChild(new SpvAsmComputeShaderCase(testCtx, "vartype_mat4", "OpPhi with mat4 variables", specMat4));
3287 group->addChild(new SpvAsmComputeShaderCase(testCtx, "vartype_array", "OpPhi with array variables", specArray));
3288 group->addChild(new SpvAsmComputeShaderCase(testCtx, "vartype_struct", "OpPhi with struct variables", specStruct));
3291 string generateConstantDefinitions (int count)
3293 std::ostringstream r;
3294 for (int i = 0; i < count; i++)
3295 r << "%cf" << (i * 10 + 5) << " = OpConstant %f32 " <<(i * 10 + 5) << ".0\n";
3300 string generateSwitchCases (int count)
3302 std::ostringstream r;
3303 for (int i = 0; i < count; i++)
3304 r << " " << i << " %case" << i;
3309 string generateSwitchTargets (int count)
3311 std::ostringstream r;
3312 for (int i = 0; i < count; i++)
3313 r << "%case" << i << " = OpLabel\n OpBranch %phi\n";
3318 string generateOpPhiParams (int count)
3320 std::ostringstream r;
3321 for (int i = 0; i < count; i++)
3322 r << " %cf" << (i * 10 + 5) << " %case" << i;
3327 string generateIntWidth (int value)
3329 std::ostringstream r;
3334 // Expand input string by injecting "ABC" between the input
3335 // string characters. The acc/add/treshold parameters are used
3336 // to skip some of the injections to make the result less
3337 // uniform (and a lot shorter).
3338 string expandOpPhiCase5 (const string& s, int &acc, int add, int treshold)
3340 std::ostringstream res;
3341 const char* p = s.c_str();
3357 // Calculate expected result based on the code string
3358 float calcOpPhiCase5 (float val, const string& s)
3360 const char* p = s.c_str();
3363 const float tv[8] = { 0.5f, 1.5f, 3.5f, 7.5f, 15.5f, 31.5f, 63.5f, 127.5f };
3364 const float v = deFloatAbs(val);
3369 for (int i = 7; i >= 0; --i)
3370 x[i] = std::fmod((float)v, (float)(2 << i));
3371 for (int i = 7; i >= 0; --i)
3372 b[i] = x[i] > tv[i];
3379 if (skip == 0 && b[depth])
3390 if (b[depth] || skip)
3404 // In the code string, the letters represent the following:
3407 // if (certain bit is set)
3418 // AABCBC leads to if(){r++;if(){r++;}else{}}else{}
3419 // ABABCC leads to if(){r++;}else{if(){r++;}else{}}
3420 // ABCABC leads to if(){r++;}else{}if(){r++;}else{}
3422 // Code generation gets a bit complicated due to the else-branches,
3423 // which do not generate new values. Thus, the generator needs to
3424 // keep track of the previous variable change seen by the else
3426 string generateOpPhiCase5 (const string& s)
3428 std::stack<int> idStack;
3429 std::stack<std::string> value;
3430 std::stack<std::string> valueLabel;
3431 std::stack<std::string> mergeLeft;
3432 std::stack<std::string> mergeRight;
3433 std::ostringstream res;
3434 const char* p = s.c_str();
3440 value.push("%f32_0");
3441 valueLabel.push("%f32_0 %entry");
3449 idStack.push(currId);
3450 res << "\tOpSelectionMerge %m" << currId << " None\n";
3451 res << "\tOpBranchConditional %b" << depth << " %t" << currId << " %f" << currId << "\n";
3452 res << "%t" << currId << " = OpLabel\n";
3453 res << "%rt" << currId << " = OpFAdd %f32 " << value.top() << " %f32_1\n";
3454 std::ostringstream tag;
3455 tag << "%rt" << currId;
3456 value.push(tag.str());
3457 tag << " %t" << currId;
3458 valueLabel.push(tag.str());
3463 mergeLeft.push(valueLabel.top());
3466 res << "\tOpBranch %m" << currId << "\n";
3467 res << "%f" << currId << " = OpLabel\n";
3468 std::ostringstream tag;
3469 tag << value.top() << " %f" << currId;
3471 valueLabel.push(tag.str());
3476 mergeRight.push(valueLabel.top());
3477 res << "\tOpBranch %m" << currId << "\n";
3478 res << "%m" << currId << " = OpLabel\n";
3480 res << "%res"; // last result goes to %res
3482 res << "%rm" << currId;
3483 res << " = OpPhi %f32 " << mergeLeft.top() << " " << mergeRight.top() << "\n";
3484 std::ostringstream tag;
3485 tag << "%rm" << currId;
3487 value.push(tag.str());
3488 tag << " %m" << currId;
3490 valueLabel.push(tag.str());
3495 currId = idStack.top();
3503 tcu::TestCaseGroup* createOpPhiGroup (tcu::TestContext& testCtx)
3505 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opphi", "Test the OpPhi instruction"));
3506 ComputeShaderSpec spec1;
3507 ComputeShaderSpec spec2;
3508 ComputeShaderSpec spec3;
3509 ComputeShaderSpec spec4;
3510 ComputeShaderSpec spec5;
3511 de::Random rnd (deStringHash(group->getName()));
3512 const int numElements = 100;
3513 vector<float> inputFloats (numElements, 0);
3514 vector<float> outputFloats1 (numElements, 0);
3515 vector<float> outputFloats2 (numElements, 0);
3516 vector<float> outputFloats3 (numElements, 0);
3517 vector<float> outputFloats4 (numElements, 0);
3518 vector<float> outputFloats5 (numElements, 0);
3519 std::string codestring = "ABC";
3520 const int test4Width = 1024;
3522 // Build case 5 code string. Each iteration makes the hierarchy more complicated.
3523 // 9 iterations with (7, 24) parameters makes the hierarchy 8 deep with about 1500 lines of
3525 for (int i = 0, acc = 0; i < 9; i++)
3526 codestring = expandOpPhiCase5(codestring, acc, 7, 24);
3528 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats[0], numElements);
3530 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
3531 floorAll(inputFloats);
3533 for (size_t ndx = 0; ndx < numElements; ++ndx)
3537 case 0: outputFloats1[ndx] = inputFloats[ndx] + 5.5f; break;
3538 case 1: outputFloats1[ndx] = inputFloats[ndx] + 20.5f; break;
3539 case 2: outputFloats1[ndx] = inputFloats[ndx] + 1.75f; break;
3542 outputFloats2[ndx] = inputFloats[ndx] + 6.5f * 3;
3543 outputFloats3[ndx] = 8.5f - inputFloats[ndx];
3545 int index4 = (int)deFloor(deAbs((float)ndx * inputFloats[ndx]));
3546 outputFloats4[ndx] = (float)(index4 % test4Width) * 10.0f + 5.0f;
3548 outputFloats5[ndx] = calcOpPhiCase5(inputFloats[ndx], codestring);
3552 string(getComputeAsmShaderPreamble()) +
3554 "OpSource GLSL 430\n"
3555 "OpName %main \"main\"\n"
3556 "OpName %id \"gl_GlobalInvocationID\"\n"
3558 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3560 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
3562 "%id = OpVariable %uvec3ptr Input\n"
3563 "%zero = OpConstant %i32 0\n"
3564 "%three = OpConstant %u32 3\n"
3565 "%constf5p5 = OpConstant %f32 5.5\n"
3566 "%constf20p5 = OpConstant %f32 20.5\n"
3567 "%constf1p75 = OpConstant %f32 1.75\n"
3568 "%constf8p5 = OpConstant %f32 8.5\n"
3569 "%constf6p5 = OpConstant %f32 6.5\n"
3571 "%main = OpFunction %void None %voidf\n"
3572 "%entry = OpLabel\n"
3573 "%idval = OpLoad %uvec3 %id\n"
3574 "%x = OpCompositeExtract %u32 %idval 0\n"
3575 "%selector = OpUMod %u32 %x %three\n"
3576 " OpSelectionMerge %phi None\n"
3577 " OpSwitch %selector %default 0 %case0 1 %case1 2 %case2\n"
3579 // Case 1 before OpPhi.
3580 "%case1 = OpLabel\n"
3583 "%default = OpLabel\n"
3587 "%operand = OpPhi %f32 %constf1p75 %case2 %constf20p5 %case1 %constf5p5 %case0\n" // not in the order of blocks
3588 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3589 "%inval = OpLoad %f32 %inloc\n"
3590 "%add = OpFAdd %f32 %inval %operand\n"
3591 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3592 " OpStore %outloc %add\n"
3595 // Case 0 after OpPhi.
3596 "%case0 = OpLabel\n"
3600 // Case 2 after OpPhi.
3601 "%case2 = OpLabel\n"
3605 spec1.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
3606 spec1.outputs.push_back(BufferSp(new Float32Buffer(outputFloats1)));
3607 spec1.numWorkGroups = IVec3(numElements, 1, 1);
3609 group->addChild(new SpvAsmComputeShaderCase(testCtx, "block", "out-of-order and unreachable blocks for OpPhi", spec1));
3612 string(getComputeAsmShaderPreamble()) +
3614 "OpName %main \"main\"\n"
3615 "OpName %id \"gl_GlobalInvocationID\"\n"
3617 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3619 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
3621 "%id = OpVariable %uvec3ptr Input\n"
3622 "%zero = OpConstant %i32 0\n"
3623 "%one = OpConstant %i32 1\n"
3624 "%three = OpConstant %i32 3\n"
3625 "%constf6p5 = OpConstant %f32 6.5\n"
3627 "%main = OpFunction %void None %voidf\n"
3628 "%entry = OpLabel\n"
3629 "%idval = OpLoad %uvec3 %id\n"
3630 "%x = OpCompositeExtract %u32 %idval 0\n"
3631 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3632 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3633 "%inval = OpLoad %f32 %inloc\n"
3637 "%step = OpPhi %i32 %zero %entry %step_next %phi\n"
3638 "%accum = OpPhi %f32 %inval %entry %accum_next %phi\n"
3639 "%step_next = OpIAdd %i32 %step %one\n"
3640 "%accum_next = OpFAdd %f32 %accum %constf6p5\n"
3641 "%still_loop = OpSLessThan %bool %step %three\n"
3642 " OpLoopMerge %exit %phi None\n"
3643 " OpBranchConditional %still_loop %phi %exit\n"
3646 " OpStore %outloc %accum\n"
3649 spec2.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
3650 spec2.outputs.push_back(BufferSp(new Float32Buffer(outputFloats2)));
3651 spec2.numWorkGroups = IVec3(numElements, 1, 1);
3653 group->addChild(new SpvAsmComputeShaderCase(testCtx, "induction", "The usual way induction variables are handled in LLVM IR", spec2));
3656 string(getComputeAsmShaderPreamble()) +
3658 "OpName %main \"main\"\n"
3659 "OpName %id \"gl_GlobalInvocationID\"\n"
3661 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3663 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
3665 "%f32ptr_f = OpTypePointer Function %f32\n"
3666 "%id = OpVariable %uvec3ptr Input\n"
3667 "%true = OpConstantTrue %bool\n"
3668 "%false = OpConstantFalse %bool\n"
3669 "%zero = OpConstant %i32 0\n"
3670 "%constf8p5 = OpConstant %f32 8.5\n"
3672 "%main = OpFunction %void None %voidf\n"
3673 "%entry = OpLabel\n"
3674 "%b = OpVariable %f32ptr_f Function %constf8p5\n"
3675 "%idval = OpLoad %uvec3 %id\n"
3676 "%x = OpCompositeExtract %u32 %idval 0\n"
3677 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3678 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3679 "%a_init = OpLoad %f32 %inloc\n"
3680 "%b_init = OpLoad %f32 %b\n"
3684 "%still_loop = OpPhi %bool %true %entry %false %phi\n"
3685 "%a_next = OpPhi %f32 %a_init %entry %b_next %phi\n"
3686 "%b_next = OpPhi %f32 %b_init %entry %a_next %phi\n"
3687 " OpLoopMerge %exit %phi None\n"
3688 " OpBranchConditional %still_loop %phi %exit\n"
3691 "%sub = OpFSub %f32 %a_next %b_next\n"
3692 " OpStore %outloc %sub\n"
3695 spec3.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
3696 spec3.outputs.push_back(BufferSp(new Float32Buffer(outputFloats3)));
3697 spec3.numWorkGroups = IVec3(numElements, 1, 1);
3699 group->addChild(new SpvAsmComputeShaderCase(testCtx, "swap", "Swap the values of two variables using OpPhi", spec3));
3702 "OpCapability Shader\n"
3703 "%ext = OpExtInstImport \"GLSL.std.450\"\n"
3704 "OpMemoryModel Logical GLSL450\n"
3705 "OpEntryPoint GLCompute %main \"main\" %id\n"
3706 "OpExecutionMode %main LocalSize 1 1 1\n"
3708 "OpSource GLSL 430\n"
3709 "OpName %main \"main\"\n"
3710 "OpName %id \"gl_GlobalInvocationID\"\n"
3712 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3714 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
3716 "%id = OpVariable %uvec3ptr Input\n"
3717 "%zero = OpConstant %i32 0\n"
3718 "%cimod = OpConstant %u32 " + generateIntWidth(test4Width) + "\n"
3720 + generateConstantDefinitions(test4Width) +
3722 "%main = OpFunction %void None %voidf\n"
3723 "%entry = OpLabel\n"
3724 "%idval = OpLoad %uvec3 %id\n"
3725 "%x = OpCompositeExtract %u32 %idval 0\n"
3726 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3727 "%inval = OpLoad %f32 %inloc\n"
3728 "%xf = OpConvertUToF %f32 %x\n"
3729 "%xm = OpFMul %f32 %xf %inval\n"
3730 "%xa = OpExtInst %f32 %ext FAbs %xm\n"
3731 "%xi = OpConvertFToU %u32 %xa\n"
3732 "%selector = OpUMod %u32 %xi %cimod\n"
3733 " OpSelectionMerge %phi None\n"
3734 " OpSwitch %selector %default "
3736 + generateSwitchCases(test4Width) +
3738 "%default = OpLabel\n"
3741 + generateSwitchTargets(test4Width) +
3744 "%result = OpPhi %f32"
3746 + generateOpPhiParams(test4Width) +
3748 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3749 " OpStore %outloc %result\n"
3753 spec4.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
3754 spec4.outputs.push_back(BufferSp(new Float32Buffer(outputFloats4)));
3755 spec4.numWorkGroups = IVec3(numElements, 1, 1);
3757 group->addChild(new SpvAsmComputeShaderCase(testCtx, "wide", "OpPhi with a lot of parameters", spec4));
3760 "OpCapability Shader\n"
3761 "%ext = OpExtInstImport \"GLSL.std.450\"\n"
3762 "OpMemoryModel Logical GLSL450\n"
3763 "OpEntryPoint GLCompute %main \"main\" %id\n"
3764 "OpExecutionMode %main LocalSize 1 1 1\n"
3765 "%code = OpString \"" + codestring + "\"\n"
3767 "OpSource GLSL 430\n"
3768 "OpName %main \"main\"\n"
3769 "OpName %id \"gl_GlobalInvocationID\"\n"
3771 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3773 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
3775 "%id = OpVariable %uvec3ptr Input\n"
3776 "%zero = OpConstant %i32 0\n"
3777 "%f32_0 = OpConstant %f32 0.0\n"
3778 "%f32_0_5 = OpConstant %f32 0.5\n"
3779 "%f32_1 = OpConstant %f32 1.0\n"
3780 "%f32_1_5 = OpConstant %f32 1.5\n"
3781 "%f32_2 = OpConstant %f32 2.0\n"
3782 "%f32_3_5 = OpConstant %f32 3.5\n"
3783 "%f32_4 = OpConstant %f32 4.0\n"
3784 "%f32_7_5 = OpConstant %f32 7.5\n"
3785 "%f32_8 = OpConstant %f32 8.0\n"
3786 "%f32_15_5 = OpConstant %f32 15.5\n"
3787 "%f32_16 = OpConstant %f32 16.0\n"
3788 "%f32_31_5 = OpConstant %f32 31.5\n"
3789 "%f32_32 = OpConstant %f32 32.0\n"
3790 "%f32_63_5 = OpConstant %f32 63.5\n"
3791 "%f32_64 = OpConstant %f32 64.0\n"
3792 "%f32_127_5 = OpConstant %f32 127.5\n"
3793 "%f32_128 = OpConstant %f32 128.0\n"
3794 "%f32_256 = OpConstant %f32 256.0\n"
3796 "%main = OpFunction %void None %voidf\n"
3797 "%entry = OpLabel\n"
3798 "%idval = OpLoad %uvec3 %id\n"
3799 "%x = OpCompositeExtract %u32 %idval 0\n"
3800 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3801 "%inval = OpLoad %f32 %inloc\n"
3803 "%xabs = OpExtInst %f32 %ext FAbs %inval\n"
3804 "%x8 = OpFMod %f32 %xabs %f32_256\n"
3805 "%x7 = OpFMod %f32 %xabs %f32_128\n"
3806 "%x6 = OpFMod %f32 %xabs %f32_64\n"
3807 "%x5 = OpFMod %f32 %xabs %f32_32\n"
3808 "%x4 = OpFMod %f32 %xabs %f32_16\n"
3809 "%x3 = OpFMod %f32 %xabs %f32_8\n"
3810 "%x2 = OpFMod %f32 %xabs %f32_4\n"
3811 "%x1 = OpFMod %f32 %xabs %f32_2\n"
3813 "%b7 = OpFOrdGreaterThanEqual %bool %x8 %f32_127_5\n"
3814 "%b6 = OpFOrdGreaterThanEqual %bool %x7 %f32_63_5\n"
3815 "%b5 = OpFOrdGreaterThanEqual %bool %x6 %f32_31_5\n"
3816 "%b4 = OpFOrdGreaterThanEqual %bool %x5 %f32_15_5\n"
3817 "%b3 = OpFOrdGreaterThanEqual %bool %x4 %f32_7_5\n"
3818 "%b2 = OpFOrdGreaterThanEqual %bool %x3 %f32_3_5\n"
3819 "%b1 = OpFOrdGreaterThanEqual %bool %x2 %f32_1_5\n"
3820 "%b0 = OpFOrdGreaterThanEqual %bool %x1 %f32_0_5\n"
3822 + generateOpPhiCase5(codestring) +
3824 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3825 " OpStore %outloc %res\n"
3829 spec5.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
3830 spec5.outputs.push_back(BufferSp(new Float32Buffer(outputFloats5)));
3831 spec5.numWorkGroups = IVec3(numElements, 1, 1);
3833 group->addChild(new SpvAsmComputeShaderCase(testCtx, "nested", "Stress OpPhi with a lot of nesting", spec5));
3835 createOpPhiVartypeTests(group, testCtx);
3837 return group.release();
3840 // Assembly code used for testing block order is based on GLSL source code:
3844 // layout(std140, set = 0, binding = 0) readonly buffer Input {
3845 // float elements[];
3847 // layout(std140, set = 0, binding = 1) writeonly buffer Output {
3848 // float elements[];
3852 // uint x = gl_GlobalInvocationID.x;
3853 // output_data.elements[x] = input_data.elements[x];
3854 // if (x > uint(50)) {
3855 // switch (x % uint(3)) {
3856 // case 0: output_data.elements[x] += 1.5f; break;
3857 // case 1: output_data.elements[x] += 42.f; break;
3858 // case 2: output_data.elements[x] -= 27.f; break;
3862 // output_data.elements[x] = -input_data.elements[x];
3865 tcu::TestCaseGroup* createBlockOrderGroup (tcu::TestContext& testCtx)
3867 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "block_order", "Test block orders"));
3868 ComputeShaderSpec spec;
3869 de::Random rnd (deStringHash(group->getName()));
3870 const int numElements = 100;
3871 vector<float> inputFloats (numElements, 0);
3872 vector<float> outputFloats (numElements, 0);
3874 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats[0], numElements);
3876 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
3877 floorAll(inputFloats);
3879 for (size_t ndx = 0; ndx <= 50; ++ndx)
3880 outputFloats[ndx] = -inputFloats[ndx];
3882 for (size_t ndx = 51; ndx < numElements; ++ndx)
3886 case 0: outputFloats[ndx] = inputFloats[ndx] + 1.5f; break;
3887 case 1: outputFloats[ndx] = inputFloats[ndx] + 42.f; break;
3888 case 2: outputFloats[ndx] = inputFloats[ndx] - 27.f; break;
3894 string(getComputeAsmShaderPreamble()) +
3896 "OpSource GLSL 430\n"
3897 "OpName %main \"main\"\n"
3898 "OpName %id \"gl_GlobalInvocationID\"\n"
3900 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3902 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
3904 "%u32ptr = OpTypePointer Function %u32\n"
3905 "%u32ptr_input = OpTypePointer Input %u32\n"
3907 + string(getComputeAsmInputOutputBuffer()) +
3909 "%id = OpVariable %uvec3ptr Input\n"
3910 "%zero = OpConstant %i32 0\n"
3911 "%const3 = OpConstant %u32 3\n"
3912 "%const50 = OpConstant %u32 50\n"
3913 "%constf1p5 = OpConstant %f32 1.5\n"
3914 "%constf27 = OpConstant %f32 27.0\n"
3915 "%constf42 = OpConstant %f32 42.0\n"
3917 "%main = OpFunction %void None %voidf\n"
3920 "%entry = OpLabel\n"
3922 // Create a temporary variable to hold the value of gl_GlobalInvocationID.x.
3923 "%xvar = OpVariable %u32ptr Function\n"
3924 "%xptr = OpAccessChain %u32ptr_input %id %zero\n"
3925 "%x = OpLoad %u32 %xptr\n"
3926 " OpStore %xvar %x\n"
3928 "%cmp = OpUGreaterThan %bool %x %const50\n"
3929 " OpSelectionMerge %if_merge None\n"
3930 " OpBranchConditional %cmp %if_true %if_false\n"
3932 // False branch for if-statement: placed in the middle of switch cases and before true branch.
3933 "%if_false = OpLabel\n"
3934 "%x_f = OpLoad %u32 %xvar\n"
3935 "%inloc_f = OpAccessChain %f32ptr %indata %zero %x_f\n"
3936 "%inval_f = OpLoad %f32 %inloc_f\n"
3937 "%negate = OpFNegate %f32 %inval_f\n"
3938 "%outloc_f = OpAccessChain %f32ptr %outdata %zero %x_f\n"
3939 " OpStore %outloc_f %negate\n"
3940 " OpBranch %if_merge\n"
3942 // Merge block for if-statement: placed in the middle of true and false branch.
3943 "%if_merge = OpLabel\n"
3946 // True branch for if-statement: placed in the middle of swtich cases and after the false branch.
3947 "%if_true = OpLabel\n"
3948 "%xval_t = OpLoad %u32 %xvar\n"
3949 "%mod = OpUMod %u32 %xval_t %const3\n"
3950 " OpSelectionMerge %switch_merge None\n"
3951 " OpSwitch %mod %default 0 %case0 1 %case1 2 %case2\n"
3953 // Merge block for switch-statement: placed before the case
3954 // bodies. But it must follow OpSwitch which dominates it.
3955 "%switch_merge = OpLabel\n"
3956 " OpBranch %if_merge\n"
3958 // Case 1 for switch-statement: placed before case 0.
3959 // It must follow the OpSwitch that dominates it.
3960 "%case1 = OpLabel\n"
3961 "%x_1 = OpLoad %u32 %xvar\n"
3962 "%inloc_1 = OpAccessChain %f32ptr %indata %zero %x_1\n"
3963 "%inval_1 = OpLoad %f32 %inloc_1\n"
3964 "%addf42 = OpFAdd %f32 %inval_1 %constf42\n"
3965 "%outloc_1 = OpAccessChain %f32ptr %outdata %zero %x_1\n"
3966 " OpStore %outloc_1 %addf42\n"
3967 " OpBranch %switch_merge\n"
3969 // Case 2 for switch-statement.
3970 "%case2 = OpLabel\n"
3971 "%x_2 = OpLoad %u32 %xvar\n"
3972 "%inloc_2 = OpAccessChain %f32ptr %indata %zero %x_2\n"
3973 "%inval_2 = OpLoad %f32 %inloc_2\n"
3974 "%subf27 = OpFSub %f32 %inval_2 %constf27\n"
3975 "%outloc_2 = OpAccessChain %f32ptr %outdata %zero %x_2\n"
3976 " OpStore %outloc_2 %subf27\n"
3977 " OpBranch %switch_merge\n"
3979 // Default case for switch-statement: placed in the middle of normal cases.
3980 "%default = OpLabel\n"
3981 " OpBranch %switch_merge\n"
3983 // Case 0 for switch-statement: out of order.
3984 "%case0 = OpLabel\n"
3985 "%x_0 = OpLoad %u32 %xvar\n"
3986 "%inloc_0 = OpAccessChain %f32ptr %indata %zero %x_0\n"
3987 "%inval_0 = OpLoad %f32 %inloc_0\n"
3988 "%addf1p5 = OpFAdd %f32 %inval_0 %constf1p5\n"
3989 "%outloc_0 = OpAccessChain %f32ptr %outdata %zero %x_0\n"
3990 " OpStore %outloc_0 %addf1p5\n"
3991 " OpBranch %switch_merge\n"
3994 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
3995 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
3996 spec.numWorkGroups = IVec3(numElements, 1, 1);
3998 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "various out-of-order blocks", spec));
4000 return group.release();
4003 tcu::TestCaseGroup* createMultipleShaderGroup (tcu::TestContext& testCtx)
4005 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "multiple_shaders", "Test multiple shaders in the same module"));
4006 ComputeShaderSpec spec1;
4007 ComputeShaderSpec spec2;
4008 de::Random rnd (deStringHash(group->getName()));
4009 const int numElements = 100;
4010 vector<float> inputFloats (numElements, 0);
4011 vector<float> outputFloats1 (numElements, 0);
4012 vector<float> outputFloats2 (numElements, 0);
4013 fillRandomScalars(rnd, -500.f, 500.f, &inputFloats[0], numElements);
4015 for (size_t ndx = 0; ndx < numElements; ++ndx)
4017 outputFloats1[ndx] = inputFloats[ndx] + inputFloats[ndx];
4018 outputFloats2[ndx] = -inputFloats[ndx];
4021 const string assembly(
4022 "OpCapability Shader\n"
4023 "OpMemoryModel Logical GLSL450\n"
4024 "OpEntryPoint GLCompute %comp_main1 \"entrypoint1\" %id\n"
4025 "OpEntryPoint GLCompute %comp_main2 \"entrypoint2\" %id\n"
4026 // A module cannot have two OpEntryPoint instructions with the same Execution Model and the same Name string.
4027 "OpEntryPoint Vertex %vert_main \"entrypoint2\" %vert_builtins %vertexIndex %instanceIndex\n"
4028 "OpExecutionMode %comp_main1 LocalSize 1 1 1\n"
4029 "OpExecutionMode %comp_main2 LocalSize 1 1 1\n"
4031 "OpName %comp_main1 \"entrypoint1\"\n"
4032 "OpName %comp_main2 \"entrypoint2\"\n"
4033 "OpName %vert_main \"entrypoint2\"\n"
4034 "OpName %id \"gl_GlobalInvocationID\"\n"
4035 "OpName %vert_builtin_st \"gl_PerVertex\"\n"
4036 "OpName %vertexIndex \"gl_VertexIndex\"\n"
4037 "OpName %instanceIndex \"gl_InstanceIndex\"\n"
4038 "OpMemberName %vert_builtin_st 0 \"gl_Position\"\n"
4039 "OpMemberName %vert_builtin_st 1 \"gl_PointSize\"\n"
4040 "OpMemberName %vert_builtin_st 2 \"gl_ClipDistance\"\n"
4042 "OpDecorate %id BuiltIn GlobalInvocationId\n"
4043 "OpDecorate %vertexIndex BuiltIn VertexIndex\n"
4044 "OpDecorate %instanceIndex BuiltIn InstanceIndex\n"
4045 "OpDecorate %vert_builtin_st Block\n"
4046 "OpMemberDecorate %vert_builtin_st 0 BuiltIn Position\n"
4047 "OpMemberDecorate %vert_builtin_st 1 BuiltIn PointSize\n"
4048 "OpMemberDecorate %vert_builtin_st 2 BuiltIn ClipDistance\n"
4050 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
4052 "%zero = OpConstant %i32 0\n"
4053 "%one = OpConstant %u32 1\n"
4054 "%c_f32_1 = OpConstant %f32 1\n"
4056 "%i32inputptr = OpTypePointer Input %i32\n"
4057 "%vec4 = OpTypeVector %f32 4\n"
4058 "%vec4ptr = OpTypePointer Output %vec4\n"
4059 "%f32arr1 = OpTypeArray %f32 %one\n"
4060 "%vert_builtin_st = OpTypeStruct %vec4 %f32 %f32arr1\n"
4061 "%vert_builtin_st_ptr = OpTypePointer Output %vert_builtin_st\n"
4062 "%vert_builtins = OpVariable %vert_builtin_st_ptr Output\n"
4064 "%id = OpVariable %uvec3ptr Input\n"
4065 "%vertexIndex = OpVariable %i32inputptr Input\n"
4066 "%instanceIndex = OpVariable %i32inputptr Input\n"
4067 "%c_vec4_1 = OpConstantComposite %vec4 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_1\n"
4069 // gl_Position = vec4(1.);
4070 "%vert_main = OpFunction %void None %voidf\n"
4071 "%vert_entry = OpLabel\n"
4072 "%position = OpAccessChain %vec4ptr %vert_builtins %zero\n"
4073 " OpStore %position %c_vec4_1\n"
4078 "%comp_main1 = OpFunction %void None %voidf\n"
4079 "%comp1_entry = OpLabel\n"
4080 "%idval1 = OpLoad %uvec3 %id\n"
4081 "%x1 = OpCompositeExtract %u32 %idval1 0\n"
4082 "%inloc1 = OpAccessChain %f32ptr %indata %zero %x1\n"
4083 "%inval1 = OpLoad %f32 %inloc1\n"
4084 "%add = OpFAdd %f32 %inval1 %inval1\n"
4085 "%outloc1 = OpAccessChain %f32ptr %outdata %zero %x1\n"
4086 " OpStore %outloc1 %add\n"
4091 "%comp_main2 = OpFunction %void None %voidf\n"
4092 "%comp2_entry = OpLabel\n"
4093 "%idval2 = OpLoad %uvec3 %id\n"
4094 "%x2 = OpCompositeExtract %u32 %idval2 0\n"
4095 "%inloc2 = OpAccessChain %f32ptr %indata %zero %x2\n"
4096 "%inval2 = OpLoad %f32 %inloc2\n"
4097 "%neg = OpFNegate %f32 %inval2\n"
4098 "%outloc2 = OpAccessChain %f32ptr %outdata %zero %x2\n"
4099 " OpStore %outloc2 %neg\n"
4101 " OpFunctionEnd\n");
4103 spec1.assembly = assembly;
4104 spec1.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
4105 spec1.outputs.push_back(BufferSp(new Float32Buffer(outputFloats1)));
4106 spec1.numWorkGroups = IVec3(numElements, 1, 1);
4107 spec1.entryPoint = "entrypoint1";
4109 spec2.assembly = assembly;
4110 spec2.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
4111 spec2.outputs.push_back(BufferSp(new Float32Buffer(outputFloats2)));
4112 spec2.numWorkGroups = IVec3(numElements, 1, 1);
4113 spec2.entryPoint = "entrypoint2";
4115 group->addChild(new SpvAsmComputeShaderCase(testCtx, "shader1", "multiple shaders in the same module", spec1));
4116 group->addChild(new SpvAsmComputeShaderCase(testCtx, "shader2", "multiple shaders in the same module", spec2));
4118 return group.release();
4121 inline std::string makeLongUTF8String (size_t num4ByteChars)
4123 // An example of a longest valid UTF-8 character. Be explicit about the
4124 // character type because Microsoft compilers can otherwise interpret the
4125 // character string as being over wide (16-bit) characters. Ideally, we
4126 // would just use a C++11 UTF-8 string literal, but we want to support older
4127 // Microsoft compilers.
4128 const std::basic_string<char> earthAfrica("\xF0\x9F\x8C\x8D");
4129 std::string longString;
4130 longString.reserve(num4ByteChars * 4);
4131 for (size_t count = 0; count < num4ByteChars; count++)
4133 longString += earthAfrica;
4138 tcu::TestCaseGroup* createOpSourceGroup (tcu::TestContext& testCtx)
4140 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opsource", "Tests the OpSource & OpSourceContinued instruction"));
4141 vector<CaseParameter> cases;
4142 de::Random rnd (deStringHash(group->getName()));
4143 const int numElements = 100;
4144 vector<float> positiveFloats (numElements, 0);
4145 vector<float> negativeFloats (numElements, 0);
4146 const StringTemplate shaderTemplate (
4147 "OpCapability Shader\n"
4148 "OpMemoryModel Logical GLSL450\n"
4150 "OpEntryPoint GLCompute %main \"main\" %id\n"
4151 "OpExecutionMode %main LocalSize 1 1 1\n"
4155 "OpName %main \"main\"\n"
4156 "OpName %id \"gl_GlobalInvocationID\"\n"
4158 "OpDecorate %id BuiltIn GlobalInvocationId\n"
4160 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
4162 "%id = OpVariable %uvec3ptr Input\n"
4163 "%zero = OpConstant %i32 0\n"
4165 "%main = OpFunction %void None %voidf\n"
4166 "%label = OpLabel\n"
4167 "%idval = OpLoad %uvec3 %id\n"
4168 "%x = OpCompositeExtract %u32 %idval 0\n"
4169 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
4170 "%inval = OpLoad %f32 %inloc\n"
4171 "%neg = OpFNegate %f32 %inval\n"
4172 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
4173 " OpStore %outloc %neg\n"
4175 " OpFunctionEnd\n");
4177 cases.push_back(CaseParameter("unknown_source", "OpSource Unknown 0"));
4178 cases.push_back(CaseParameter("wrong_source", "OpSource OpenCL_C 210"));
4179 cases.push_back(CaseParameter("normal_filename", "%fname = OpString \"filename\"\n"
4180 "OpSource GLSL 430 %fname"));
4181 cases.push_back(CaseParameter("empty_filename", "%fname = OpString \"\"\n"
4182 "OpSource GLSL 430 %fname"));
4183 cases.push_back(CaseParameter("normal_source_code", "%fname = OpString \"filename\"\n"
4184 "OpSource GLSL 430 %fname \"#version 430\nvoid main() {}\""));
4185 cases.push_back(CaseParameter("empty_source_code", "%fname = OpString \"filename\"\n"
4186 "OpSource GLSL 430 %fname \"\""));
4187 cases.push_back(CaseParameter("long_source_code", "%fname = OpString \"filename\"\n"
4188 "OpSource GLSL 430 %fname \"" + makeLongUTF8String(65530) + "ccc\"")); // word count: 65535
4189 cases.push_back(CaseParameter("utf8_source_code", "%fname = OpString \"filename\"\n"
4190 "OpSource GLSL 430 %fname \"\xE2\x98\x82\xE2\x98\x85\"")); // umbrella & black star symbol
4191 cases.push_back(CaseParameter("normal_sourcecontinued", "%fname = OpString \"filename\"\n"
4192 "OpSource GLSL 430 %fname \"#version 430\nvo\"\n"
4193 "OpSourceContinued \"id main() {}\""));
4194 cases.push_back(CaseParameter("empty_sourcecontinued", "%fname = OpString \"filename\"\n"
4195 "OpSource GLSL 430 %fname \"#version 430\nvoid main() {}\"\n"
4196 "OpSourceContinued \"\""));
4197 cases.push_back(CaseParameter("long_sourcecontinued", "%fname = OpString \"filename\"\n"
4198 "OpSource GLSL 430 %fname \"#version 430\nvoid main() {}\"\n"
4199 "OpSourceContinued \"" + makeLongUTF8String(65533) + "ccc\"")); // word count: 65535
4200 cases.push_back(CaseParameter("utf8_sourcecontinued", "%fname = OpString \"filename\"\n"
4201 "OpSource GLSL 430 %fname \"#version 430\nvoid main() {}\"\n"
4202 "OpSourceContinued \"\xE2\x98\x8E\xE2\x9A\x91\"")); // white telephone & black flag symbol
4203 cases.push_back(CaseParameter("multi_sourcecontinued", "%fname = OpString \"filename\"\n"
4204 "OpSource GLSL 430 %fname \"#version 430\n\"\n"
4205 "OpSourceContinued \"void\"\n"
4206 "OpSourceContinued \"main()\"\n"
4207 "OpSourceContinued \"{}\""));
4208 cases.push_back(CaseParameter("empty_source_before_sourcecontinued", "%fname = OpString \"filename\"\n"
4209 "OpSource GLSL 430 %fname \"\"\n"
4210 "OpSourceContinued \"#version 430\nvoid main() {}\""));
4212 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
4214 for (size_t ndx = 0; ndx < numElements; ++ndx)
4215 negativeFloats[ndx] = -positiveFloats[ndx];
4217 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
4219 map<string, string> specializations;
4220 ComputeShaderSpec spec;
4222 specializations["SOURCE"] = cases[caseNdx].param;
4223 spec.assembly = shaderTemplate.specialize(specializations);
4224 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
4225 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
4226 spec.numWorkGroups = IVec3(numElements, 1, 1);
4228 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
4231 return group.release();
4234 tcu::TestCaseGroup* createOpSourceExtensionGroup (tcu::TestContext& testCtx)
4236 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opsourceextension", "Tests the OpSource instruction"));
4237 vector<CaseParameter> cases;
4238 de::Random rnd (deStringHash(group->getName()));
4239 const int numElements = 100;
4240 vector<float> inputFloats (numElements, 0);
4241 vector<float> outputFloats (numElements, 0);
4242 const StringTemplate shaderTemplate (
4243 string(getComputeAsmShaderPreamble()) +
4245 "OpSourceExtension \"${EXTENSION}\"\n"
4247 "OpName %main \"main\"\n"
4248 "OpName %id \"gl_GlobalInvocationID\"\n"
4250 "OpDecorate %id BuiltIn GlobalInvocationId\n"
4252 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
4254 "%id = OpVariable %uvec3ptr Input\n"
4255 "%zero = OpConstant %i32 0\n"
4257 "%main = OpFunction %void None %voidf\n"
4258 "%label = OpLabel\n"
4259 "%idval = OpLoad %uvec3 %id\n"
4260 "%x = OpCompositeExtract %u32 %idval 0\n"
4261 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
4262 "%inval = OpLoad %f32 %inloc\n"
4263 "%neg = OpFNegate %f32 %inval\n"
4264 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
4265 " OpStore %outloc %neg\n"
4267 " OpFunctionEnd\n");
4269 cases.push_back(CaseParameter("empty_extension", ""));
4270 cases.push_back(CaseParameter("real_extension", "GL_ARB_texture_rectangle"));
4271 cases.push_back(CaseParameter("fake_extension", "GL_ARB_im_the_ultimate_extension"));
4272 cases.push_back(CaseParameter("utf8_extension", "GL_ARB_\xE2\x98\x82\xE2\x98\x85"));
4273 cases.push_back(CaseParameter("long_extension", makeLongUTF8String(65533) + "ccc")); // word count: 65535
4275 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats[0], numElements);
4277 for (size_t ndx = 0; ndx < numElements; ++ndx)
4278 outputFloats[ndx] = -inputFloats[ndx];
4280 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
4282 map<string, string> specializations;
4283 ComputeShaderSpec spec;
4285 specializations["EXTENSION"] = cases[caseNdx].param;
4286 spec.assembly = shaderTemplate.specialize(specializations);
4287 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
4288 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
4289 spec.numWorkGroups = IVec3(numElements, 1, 1);
4291 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
4294 return group.release();
4297 // Checks that a compute shader can generate a constant null value of various types, without exercising a computation on it.
4298 tcu::TestCaseGroup* createOpConstantNullGroup (tcu::TestContext& testCtx)
4300 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opconstantnull", "Tests the OpConstantNull instruction"));
4301 vector<CaseParameter> cases;
4302 de::Random rnd (deStringHash(group->getName()));
4303 const int numElements = 100;
4304 vector<float> positiveFloats (numElements, 0);
4305 vector<float> negativeFloats (numElements, 0);
4306 const StringTemplate shaderTemplate (
4307 string(getComputeAsmShaderPreamble()) +
4309 "OpSource GLSL 430\n"
4310 "OpName %main \"main\"\n"
4311 "OpName %id \"gl_GlobalInvocationID\"\n"
4313 "OpDecorate %id BuiltIn GlobalInvocationId\n"
4315 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
4316 "%uvec2 = OpTypeVector %u32 2\n"
4317 "%bvec3 = OpTypeVector %bool 3\n"
4318 "%fvec4 = OpTypeVector %f32 4\n"
4319 "%fmat33 = OpTypeMatrix %fvec3 3\n"
4320 "%const100 = OpConstant %u32 100\n"
4321 "%uarr100 = OpTypeArray %i32 %const100\n"
4322 "%struct = OpTypeStruct %f32 %i32 %u32\n"
4323 "%pointer = OpTypePointer Function %i32\n"
4324 + string(getComputeAsmInputOutputBuffer()) +
4326 "%null = OpConstantNull ${TYPE}\n"
4328 "%id = OpVariable %uvec3ptr Input\n"
4329 "%zero = OpConstant %i32 0\n"
4331 "%main = OpFunction %void None %voidf\n"
4332 "%label = OpLabel\n"
4333 "%idval = OpLoad %uvec3 %id\n"
4334 "%x = OpCompositeExtract %u32 %idval 0\n"
4335 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
4336 "%inval = OpLoad %f32 %inloc\n"
4337 "%neg = OpFNegate %f32 %inval\n"
4338 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
4339 " OpStore %outloc %neg\n"
4341 " OpFunctionEnd\n");
4343 cases.push_back(CaseParameter("bool", "%bool"));
4344 cases.push_back(CaseParameter("sint32", "%i32"));
4345 cases.push_back(CaseParameter("uint32", "%u32"));
4346 cases.push_back(CaseParameter("float32", "%f32"));
4347 cases.push_back(CaseParameter("vec4float32", "%fvec4"));
4348 cases.push_back(CaseParameter("vec3bool", "%bvec3"));
4349 cases.push_back(CaseParameter("vec2uint32", "%uvec2"));
4350 cases.push_back(CaseParameter("matrix", "%fmat33"));
4351 cases.push_back(CaseParameter("array", "%uarr100"));
4352 cases.push_back(CaseParameter("struct", "%struct"));
4353 cases.push_back(CaseParameter("pointer", "%pointer"));
4355 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
4357 for (size_t ndx = 0; ndx < numElements; ++ndx)
4358 negativeFloats[ndx] = -positiveFloats[ndx];
4360 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
4362 map<string, string> specializations;
4363 ComputeShaderSpec spec;
4365 specializations["TYPE"] = cases[caseNdx].param;
4366 spec.assembly = shaderTemplate.specialize(specializations);
4367 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
4368 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
4369 spec.numWorkGroups = IVec3(numElements, 1, 1);
4371 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
4374 return group.release();
4377 // Checks that a compute shader can generate a constant composite value of various types, without exercising a computation on it.
4378 tcu::TestCaseGroup* createOpConstantCompositeGroup (tcu::TestContext& testCtx)
4380 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opconstantcomposite", "Tests the OpConstantComposite instruction"));
4381 vector<CaseParameter> cases;
4382 de::Random rnd (deStringHash(group->getName()));
4383 const int numElements = 100;
4384 vector<float> positiveFloats (numElements, 0);
4385 vector<float> negativeFloats (numElements, 0);
4386 const StringTemplate shaderTemplate (
4387 string(getComputeAsmShaderPreamble()) +
4389 "OpSource GLSL 430\n"
4390 "OpName %main \"main\"\n"
4391 "OpName %id \"gl_GlobalInvocationID\"\n"
4393 "OpDecorate %id BuiltIn GlobalInvocationId\n"
4395 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
4397 "%id = OpVariable %uvec3ptr Input\n"
4398 "%zero = OpConstant %i32 0\n"
4402 "%main = OpFunction %void None %voidf\n"
4403 "%label = OpLabel\n"
4404 "%idval = OpLoad %uvec3 %id\n"
4405 "%x = OpCompositeExtract %u32 %idval 0\n"
4406 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
4407 "%inval = OpLoad %f32 %inloc\n"
4408 "%neg = OpFNegate %f32 %inval\n"
4409 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
4410 " OpStore %outloc %neg\n"
4412 " OpFunctionEnd\n");
4414 cases.push_back(CaseParameter("vector", "%five = OpConstant %u32 5\n"
4415 "%const = OpConstantComposite %uvec3 %five %zero %five"));
4416 cases.push_back(CaseParameter("matrix", "%m3fvec3 = OpTypeMatrix %fvec3 3\n"
4417 "%ten = OpConstant %f32 10.\n"
4418 "%fzero = OpConstant %f32 0.\n"
4419 "%vec = OpConstantComposite %fvec3 %ten %fzero %ten\n"
4420 "%mat = OpConstantComposite %m3fvec3 %vec %vec %vec"));
4421 cases.push_back(CaseParameter("struct", "%m2vec3 = OpTypeMatrix %fvec3 2\n"
4422 "%struct = OpTypeStruct %i32 %f32 %fvec3 %m2vec3\n"
4423 "%fzero = OpConstant %f32 0.\n"
4424 "%one = OpConstant %f32 1.\n"
4425 "%point5 = OpConstant %f32 0.5\n"
4426 "%vec = OpConstantComposite %fvec3 %one %one %fzero\n"
4427 "%mat = OpConstantComposite %m2vec3 %vec %vec\n"
4428 "%const = OpConstantComposite %struct %zero %point5 %vec %mat"));
4429 cases.push_back(CaseParameter("nested_struct", "%st1 = OpTypeStruct %u32 %f32\n"
4430 "%st2 = OpTypeStruct %i32 %i32\n"
4431 "%struct = OpTypeStruct %st1 %st2\n"
4432 "%point5 = OpConstant %f32 0.5\n"
4433 "%one = OpConstant %u32 1\n"
4434 "%ten = OpConstant %i32 10\n"
4435 "%st1val = OpConstantComposite %st1 %one %point5\n"
4436 "%st2val = OpConstantComposite %st2 %ten %ten\n"
4437 "%const = OpConstantComposite %struct %st1val %st2val"));
4439 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
4441 for (size_t ndx = 0; ndx < numElements; ++ndx)
4442 negativeFloats[ndx] = -positiveFloats[ndx];
4444 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
4446 map<string, string> specializations;
4447 ComputeShaderSpec spec;
4449 specializations["CONSTANT"] = cases[caseNdx].param;
4450 spec.assembly = shaderTemplate.specialize(specializations);
4451 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
4452 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
4453 spec.numWorkGroups = IVec3(numElements, 1, 1);
4455 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
4458 return group.release();
4461 // Creates a floating point number with the given exponent, and significand
4462 // bits set. It can only create normalized numbers. Only the least significant
4463 // 24 bits of the significand will be examined. The final bit of the
4464 // significand will also be ignored. This allows alignment to be written
4465 // similarly to C99 hex-floats.
4466 // For example if you wanted to write 0x1.7f34p-12 you would call
4467 // constructNormalizedFloat(-12, 0x7f3400)
4468 float constructNormalizedFloat (deInt32 exponent, deUint32 significand)
4472 for (deInt32 idx = 0; idx < 23; ++idx)
4474 f += ((significand & 0x800000) == 0) ? 0.f : std::ldexp(1.0f, -(idx + 1));
4478 return std::ldexp(f, exponent);
4481 // Compare instruction for the OpQuantizeF16 compute exact case.
4482 // Returns true if the output is what is expected from the test case.
4483 bool compareOpQuantizeF16ComputeExactCase (const std::vector<Resource>&, const vector<AllocationSp>& outputAllocs, const std::vector<Resource>& expectedOutputs, TestLog&)
4485 if (outputAllocs.size() != 1)
4488 // Only size is needed because we cannot compare Nans.
4489 size_t byteSize = expectedOutputs[0].getByteSize();
4491 const float* outputAsFloat = static_cast<const float*>(outputAllocs[0]->getHostPtr());
4493 if (byteSize != 4*sizeof(float)) {
4497 if (*outputAsFloat != constructNormalizedFloat(8, 0x304000) &&
4498 *outputAsFloat != constructNormalizedFloat(8, 0x300000)) {
4503 if (*outputAsFloat != -constructNormalizedFloat(-7, 0x600000) &&
4504 *outputAsFloat != -constructNormalizedFloat(-7, 0x604000)) {
4509 if (*outputAsFloat != constructNormalizedFloat(2, 0x01C000) &&
4510 *outputAsFloat != constructNormalizedFloat(2, 0x020000)) {
4515 if (*outputAsFloat != constructNormalizedFloat(1, 0xFFC000) &&
4516 *outputAsFloat != constructNormalizedFloat(2, 0x000000)) {
4523 // Checks that every output from a test-case is a float NaN.
4524 bool compareNan (const std::vector<Resource>&, const vector<AllocationSp>& outputAllocs, const std::vector<Resource>& expectedOutputs, TestLog&)
4526 if (outputAllocs.size() != 1)
4529 // Only size is needed because we cannot compare Nans.
4530 size_t byteSize = expectedOutputs[0].getByteSize();
4532 const float* const output_as_float = static_cast<const float*>(outputAllocs[0]->getHostPtr());
4534 for (size_t idx = 0; idx < byteSize / sizeof(float); ++idx)
4536 if (!deFloatIsNaN(output_as_float[idx]))
4545 // Checks that a compute shader can generate a constant composite value of various types, without exercising a computation on it.
4546 tcu::TestCaseGroup* createOpQuantizeToF16Group (tcu::TestContext& testCtx)
4548 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opquantize", "Tests the OpQuantizeToF16 instruction"));
4550 const std::string shader (
4551 string(getComputeAsmShaderPreamble()) +
4553 "OpSource GLSL 430\n"
4554 "OpName %main \"main\"\n"
4555 "OpName %id \"gl_GlobalInvocationID\"\n"
4557 "OpDecorate %id BuiltIn GlobalInvocationId\n"
4559 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
4561 "%id = OpVariable %uvec3ptr Input\n"
4562 "%zero = OpConstant %i32 0\n"
4564 "%main = OpFunction %void None %voidf\n"
4565 "%label = OpLabel\n"
4566 "%idval = OpLoad %uvec3 %id\n"
4567 "%x = OpCompositeExtract %u32 %idval 0\n"
4568 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
4569 "%inval = OpLoad %f32 %inloc\n"
4570 "%quant = OpQuantizeToF16 %f32 %inval\n"
4571 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
4572 " OpStore %outloc %quant\n"
4574 " OpFunctionEnd\n");
4577 ComputeShaderSpec spec;
4578 const deUint32 numElements = 100;
4579 vector<float> infinities;
4580 vector<float> results;
4582 infinities.reserve(numElements);
4583 results.reserve(numElements);
4585 for (size_t idx = 0; idx < numElements; ++idx)
4590 infinities.push_back(std::numeric_limits<float>::infinity());
4591 results.push_back(std::numeric_limits<float>::infinity());
4594 infinities.push_back(-std::numeric_limits<float>::infinity());
4595 results.push_back(-std::numeric_limits<float>::infinity());
4598 infinities.push_back(std::ldexp(1.0f, 16));
4599 results.push_back(std::numeric_limits<float>::infinity());
4602 infinities.push_back(std::ldexp(-1.0f, 32));
4603 results.push_back(-std::numeric_limits<float>::infinity());
4608 spec.assembly = shader;
4609 spec.inputs.push_back(BufferSp(new Float32Buffer(infinities)));
4610 spec.outputs.push_back(BufferSp(new Float32Buffer(results)));
4611 spec.numWorkGroups = IVec3(numElements, 1, 1);
4613 group->addChild(new SpvAsmComputeShaderCase(
4614 testCtx, "infinities", "Check that infinities propagated and created", spec));
4618 ComputeShaderSpec spec;
4620 const deUint32 numElements = 100;
4622 nans.reserve(numElements);
4624 for (size_t idx = 0; idx < numElements; ++idx)
4628 nans.push_back(std::numeric_limits<float>::quiet_NaN());
4632 nans.push_back(-std::numeric_limits<float>::quiet_NaN());
4636 spec.assembly = shader;
4637 spec.inputs.push_back(BufferSp(new Float32Buffer(nans)));
4638 spec.outputs.push_back(BufferSp(new Float32Buffer(nans)));
4639 spec.numWorkGroups = IVec3(numElements, 1, 1);
4640 spec.verifyIO = &compareNan;
4642 group->addChild(new SpvAsmComputeShaderCase(
4643 testCtx, "propagated_nans", "Check that nans are propagated", spec));
4647 ComputeShaderSpec spec;
4648 vector<float> small;
4649 vector<float> zeros;
4650 const deUint32 numElements = 100;
4652 small.reserve(numElements);
4653 zeros.reserve(numElements);
4655 for (size_t idx = 0; idx < numElements; ++idx)
4660 small.push_back(0.f);
4661 zeros.push_back(0.f);
4664 small.push_back(-0.f);
4665 zeros.push_back(-0.f);
4668 small.push_back(std::ldexp(1.0f, -16));
4669 zeros.push_back(0.f);
4672 small.push_back(std::ldexp(-1.0f, -32));
4673 zeros.push_back(-0.f);
4676 small.push_back(std::ldexp(1.0f, -127));
4677 zeros.push_back(0.f);
4680 small.push_back(-std::ldexp(1.0f, -128));
4681 zeros.push_back(-0.f);
4686 spec.assembly = shader;
4687 spec.inputs.push_back(BufferSp(new Float32Buffer(small)));
4688 spec.outputs.push_back(BufferSp(new Float32Buffer(zeros)));
4689 spec.numWorkGroups = IVec3(numElements, 1, 1);
4691 group->addChild(new SpvAsmComputeShaderCase(
4692 testCtx, "flush_to_zero", "Check that values are zeroed correctly", spec));
4696 ComputeShaderSpec spec;
4697 vector<float> exact;
4698 const deUint32 numElements = 200;
4700 exact.reserve(numElements);
4702 for (size_t idx = 0; idx < numElements; ++idx)
4703 exact.push_back(static_cast<float>(static_cast<int>(idx) - 100));
4705 spec.assembly = shader;
4706 spec.inputs.push_back(BufferSp(new Float32Buffer(exact)));
4707 spec.outputs.push_back(BufferSp(new Float32Buffer(exact)));
4708 spec.numWorkGroups = IVec3(numElements, 1, 1);
4710 group->addChild(new SpvAsmComputeShaderCase(
4711 testCtx, "exact", "Check that values exactly preserved where appropriate", spec));
4715 ComputeShaderSpec spec;
4716 vector<float> inputs;
4717 const deUint32 numElements = 4;
4719 inputs.push_back(constructNormalizedFloat(8, 0x300300));
4720 inputs.push_back(-constructNormalizedFloat(-7, 0x600800));
4721 inputs.push_back(constructNormalizedFloat(2, 0x01E000));
4722 inputs.push_back(constructNormalizedFloat(1, 0xFFE000));
4724 spec.assembly = shader;
4725 spec.verifyIO = &compareOpQuantizeF16ComputeExactCase;
4726 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs)));
4727 spec.outputs.push_back(BufferSp(new Float32Buffer(inputs)));
4728 spec.numWorkGroups = IVec3(numElements, 1, 1);
4730 group->addChild(new SpvAsmComputeShaderCase(
4731 testCtx, "rounded", "Check that are rounded when needed", spec));
4734 return group.release();
4737 tcu::TestCaseGroup* createSpecConstantOpQuantizeToF16Group (tcu::TestContext& testCtx)
4739 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opspecconstantop_opquantize", "Tests the OpQuantizeToF16 opcode for the OpSpecConstantOp instruction"));
4741 const std::string shader (
4742 string(getComputeAsmShaderPreamble()) +
4744 "OpName %main \"main\"\n"
4745 "OpName %id \"gl_GlobalInvocationID\"\n"
4747 "OpDecorate %id BuiltIn GlobalInvocationId\n"
4749 "OpDecorate %sc_0 SpecId 0\n"
4750 "OpDecorate %sc_1 SpecId 1\n"
4751 "OpDecorate %sc_2 SpecId 2\n"
4752 "OpDecorate %sc_3 SpecId 3\n"
4753 "OpDecorate %sc_4 SpecId 4\n"
4754 "OpDecorate %sc_5 SpecId 5\n"
4756 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
4758 "%id = OpVariable %uvec3ptr Input\n"
4759 "%zero = OpConstant %i32 0\n"
4760 "%c_u32_6 = OpConstant %u32 6\n"
4762 "%sc_0 = OpSpecConstant %f32 0.\n"
4763 "%sc_1 = OpSpecConstant %f32 0.\n"
4764 "%sc_2 = OpSpecConstant %f32 0.\n"
4765 "%sc_3 = OpSpecConstant %f32 0.\n"
4766 "%sc_4 = OpSpecConstant %f32 0.\n"
4767 "%sc_5 = OpSpecConstant %f32 0.\n"
4769 "%sc_0_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_0\n"
4770 "%sc_1_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_1\n"
4771 "%sc_2_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_2\n"
4772 "%sc_3_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_3\n"
4773 "%sc_4_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_4\n"
4774 "%sc_5_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_5\n"
4776 "%main = OpFunction %void None %voidf\n"
4777 "%label = OpLabel\n"
4778 "%idval = OpLoad %uvec3 %id\n"
4779 "%x = OpCompositeExtract %u32 %idval 0\n"
4780 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
4781 "%selector = OpUMod %u32 %x %c_u32_6\n"
4782 " OpSelectionMerge %exit None\n"
4783 " OpSwitch %selector %exit 0 %case0 1 %case1 2 %case2 3 %case3 4 %case4 5 %case5\n"
4785 "%case0 = OpLabel\n"
4786 " OpStore %outloc %sc_0_quant\n"
4789 "%case1 = OpLabel\n"
4790 " OpStore %outloc %sc_1_quant\n"
4793 "%case2 = OpLabel\n"
4794 " OpStore %outloc %sc_2_quant\n"
4797 "%case3 = OpLabel\n"
4798 " OpStore %outloc %sc_3_quant\n"
4801 "%case4 = OpLabel\n"
4802 " OpStore %outloc %sc_4_quant\n"
4805 "%case5 = OpLabel\n"
4806 " OpStore %outloc %sc_5_quant\n"
4812 " OpFunctionEnd\n");
4815 ComputeShaderSpec spec;
4816 const deUint8 numCases = 4;
4817 vector<float> inputs (numCases, 0.f);
4818 vector<float> outputs;
4820 spec.assembly = shader;
4821 spec.numWorkGroups = IVec3(numCases, 1, 1);
4823 spec.specConstants.append<deInt32>(bitwiseCast<deUint32>(std::numeric_limits<float>::infinity()));
4824 spec.specConstants.append<deInt32>(bitwiseCast<deUint32>(-std::numeric_limits<float>::infinity()));
4825 spec.specConstants.append<deInt32>(bitwiseCast<deUint32>(std::ldexp(1.0f, 16)));
4826 spec.specConstants.append<deInt32>(bitwiseCast<deUint32>(std::ldexp(-1.0f, 32)));
4828 outputs.push_back(std::numeric_limits<float>::infinity());
4829 outputs.push_back(-std::numeric_limits<float>::infinity());
4830 outputs.push_back(std::numeric_limits<float>::infinity());
4831 outputs.push_back(-std::numeric_limits<float>::infinity());
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, "infinities", "Check that infinities propagated and created", spec));
4841 ComputeShaderSpec spec;
4842 const deUint8 numCases = 2;
4843 vector<float> inputs (numCases, 0.f);
4844 vector<float> outputs;
4846 spec.assembly = shader;
4847 spec.numWorkGroups = IVec3(numCases, 1, 1);
4848 spec.verifyIO = &compareNan;
4850 outputs.push_back(std::numeric_limits<float>::quiet_NaN());
4851 outputs.push_back(-std::numeric_limits<float>::quiet_NaN());
4853 for (deUint8 idx = 0; idx < numCases; ++idx)
4854 spec.specConstants.append<deInt32>(bitwiseCast<deUint32>(outputs[idx]));
4856 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs)));
4857 spec.outputs.push_back(BufferSp(new Float32Buffer(outputs)));
4859 group->addChild(new SpvAsmComputeShaderCase(
4860 testCtx, "propagated_nans", "Check that nans are propagated", spec));
4864 ComputeShaderSpec spec;
4865 const deUint8 numCases = 6;
4866 vector<float> inputs (numCases, 0.f);
4867 vector<float> outputs;
4869 spec.assembly = shader;
4870 spec.numWorkGroups = IVec3(numCases, 1, 1);
4872 spec.specConstants.append<deInt32>(bitwiseCast<deUint32>(0.f));
4873 spec.specConstants.append<deInt32>(bitwiseCast<deUint32>(-0.f));
4874 spec.specConstants.append<deInt32>(bitwiseCast<deUint32>(std::ldexp(1.0f, -16)));
4875 spec.specConstants.append<deInt32>(bitwiseCast<deUint32>(std::ldexp(-1.0f, -32)));
4876 spec.specConstants.append<deInt32>(bitwiseCast<deUint32>(std::ldexp(1.0f, -127)));
4877 spec.specConstants.append<deInt32>(bitwiseCast<deUint32>(-std::ldexp(1.0f, -128)));
4879 outputs.push_back(0.f);
4880 outputs.push_back(-0.f);
4881 outputs.push_back(0.f);
4882 outputs.push_back(-0.f);
4883 outputs.push_back(0.f);
4884 outputs.push_back(-0.f);
4886 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs)));
4887 spec.outputs.push_back(BufferSp(new Float32Buffer(outputs)));
4889 group->addChild(new SpvAsmComputeShaderCase(
4890 testCtx, "flush_to_zero", "Check that values are zeroed correctly", spec));
4894 ComputeShaderSpec spec;
4895 const deUint8 numCases = 6;
4896 vector<float> inputs (numCases, 0.f);
4897 vector<float> outputs;
4899 spec.assembly = shader;
4900 spec.numWorkGroups = IVec3(numCases, 1, 1);
4902 for (deUint8 idx = 0; idx < 6; ++idx)
4904 const float f = static_cast<float>(idx * 10 - 30) / 4.f;
4905 spec.specConstants.append<deInt32>(bitwiseCast<deUint32>(f));
4906 outputs.push_back(f);
4909 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs)));
4910 spec.outputs.push_back(BufferSp(new Float32Buffer(outputs)));
4912 group->addChild(new SpvAsmComputeShaderCase(
4913 testCtx, "exact", "Check that values exactly preserved where appropriate", spec));
4917 ComputeShaderSpec spec;
4918 const deUint8 numCases = 4;
4919 vector<float> inputs (numCases, 0.f);
4920 vector<float> outputs;
4922 spec.assembly = shader;
4923 spec.numWorkGroups = IVec3(numCases, 1, 1);
4924 spec.verifyIO = &compareOpQuantizeF16ComputeExactCase;
4926 outputs.push_back(constructNormalizedFloat(8, 0x300300));
4927 outputs.push_back(-constructNormalizedFloat(-7, 0x600800));
4928 outputs.push_back(constructNormalizedFloat(2, 0x01E000));
4929 outputs.push_back(constructNormalizedFloat(1, 0xFFE000));
4931 for (deUint8 idx = 0; idx < numCases; ++idx)
4932 spec.specConstants.append<deInt32>(bitwiseCast<deUint32>(outputs[idx]));
4934 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs)));
4935 spec.outputs.push_back(BufferSp(new Float32Buffer(outputs)));
4937 group->addChild(new SpvAsmComputeShaderCase(
4938 testCtx, "rounded", "Check that are rounded when needed", spec));
4941 return group.release();
4944 // Checks that constant null/composite values can be used in computation.
4945 tcu::TestCaseGroup* createOpConstantUsageGroup (tcu::TestContext& testCtx)
4947 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opconstantnullcomposite", "Spotcheck the OpConstantNull & OpConstantComposite instruction"));
4948 ComputeShaderSpec spec;
4949 de::Random rnd (deStringHash(group->getName()));
4950 const int numElements = 100;
4951 vector<float> positiveFloats (numElements, 0);
4952 vector<float> negativeFloats (numElements, 0);
4954 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
4956 for (size_t ndx = 0; ndx < numElements; ++ndx)
4957 negativeFloats[ndx] = -positiveFloats[ndx];
4960 "OpCapability Shader\n"
4961 "%std450 = OpExtInstImport \"GLSL.std.450\"\n"
4962 "OpMemoryModel Logical GLSL450\n"
4963 "OpEntryPoint GLCompute %main \"main\" %id\n"
4964 "OpExecutionMode %main LocalSize 1 1 1\n"
4966 "OpSource GLSL 430\n"
4967 "OpName %main \"main\"\n"
4968 "OpName %id \"gl_GlobalInvocationID\"\n"
4970 "OpDecorate %id BuiltIn GlobalInvocationId\n"
4972 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
4974 "%fmat = OpTypeMatrix %fvec3 3\n"
4975 "%ten = OpConstant %u32 10\n"
4976 "%f32arr10 = OpTypeArray %f32 %ten\n"
4977 "%fst = OpTypeStruct %f32 %f32\n"
4979 + string(getComputeAsmInputOutputBuffer()) +
4981 "%id = OpVariable %uvec3ptr Input\n"
4982 "%zero = OpConstant %i32 0\n"
4984 // Create a bunch of null values
4985 "%unull = OpConstantNull %u32\n"
4986 "%fnull = OpConstantNull %f32\n"
4987 "%vnull = OpConstantNull %fvec3\n"
4988 "%mnull = OpConstantNull %fmat\n"
4989 "%anull = OpConstantNull %f32arr10\n"
4990 "%snull = OpConstantComposite %fst %fnull %fnull\n"
4992 "%main = OpFunction %void None %voidf\n"
4993 "%label = OpLabel\n"
4994 "%idval = OpLoad %uvec3 %id\n"
4995 "%x = OpCompositeExtract %u32 %idval 0\n"
4996 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
4997 "%inval = OpLoad %f32 %inloc\n"
4998 "%neg = OpFNegate %f32 %inval\n"
5000 // Get the abs() of (a certain element of) those null values
5001 "%unull_cov = OpConvertUToF %f32 %unull\n"
5002 "%unull_abs = OpExtInst %f32 %std450 FAbs %unull_cov\n"
5003 "%fnull_abs = OpExtInst %f32 %std450 FAbs %fnull\n"
5004 "%vnull_0 = OpCompositeExtract %f32 %vnull 0\n"
5005 "%vnull_abs = OpExtInst %f32 %std450 FAbs %vnull_0\n"
5006 "%mnull_12 = OpCompositeExtract %f32 %mnull 1 2\n"
5007 "%mnull_abs = OpExtInst %f32 %std450 FAbs %mnull_12\n"
5008 "%anull_3 = OpCompositeExtract %f32 %anull 3\n"
5009 "%anull_abs = OpExtInst %f32 %std450 FAbs %anull_3\n"
5010 "%snull_1 = OpCompositeExtract %f32 %snull 1\n"
5011 "%snull_abs = OpExtInst %f32 %std450 FAbs %snull_1\n"
5014 "%add1 = OpFAdd %f32 %neg %unull_abs\n"
5015 "%add2 = OpFAdd %f32 %add1 %fnull_abs\n"
5016 "%add3 = OpFAdd %f32 %add2 %vnull_abs\n"
5017 "%add4 = OpFAdd %f32 %add3 %mnull_abs\n"
5018 "%add5 = OpFAdd %f32 %add4 %anull_abs\n"
5019 "%final = OpFAdd %f32 %add5 %snull_abs\n"
5021 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
5022 " OpStore %outloc %final\n" // write to output
5025 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
5026 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
5027 spec.numWorkGroups = IVec3(numElements, 1, 1);
5029 group->addChild(new SpvAsmComputeShaderCase(testCtx, "spotcheck", "Check that values constructed via OpConstantNull & OpConstantComposite can be used", spec));
5031 return group.release();
5034 // Assembly code used for testing loop control is based on GLSL source code:
5037 // layout(std140, set = 0, binding = 0) readonly buffer Input {
5038 // float elements[];
5040 // layout(std140, set = 0, binding = 1) writeonly buffer Output {
5041 // float elements[];
5045 // uint x = gl_GlobalInvocationID.x;
5046 // output_data.elements[x] = input_data.elements[x];
5047 // for (uint i = 0; i < 4; ++i)
5048 // output_data.elements[x] += 1.f;
5050 tcu::TestCaseGroup* createLoopControlGroup (tcu::TestContext& testCtx)
5052 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "loop_control", "Tests loop control cases"));
5053 vector<CaseParameter> cases;
5054 de::Random rnd (deStringHash(group->getName()));
5055 const int numElements = 100;
5056 vector<float> inputFloats (numElements, 0);
5057 vector<float> outputFloats (numElements, 0);
5058 const StringTemplate shaderTemplate (
5059 string(getComputeAsmShaderPreamble()) +
5061 "OpSource GLSL 430\n"
5062 "OpName %main \"main\"\n"
5063 "OpName %id \"gl_GlobalInvocationID\"\n"
5065 "OpDecorate %id BuiltIn GlobalInvocationId\n"
5067 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
5069 "%u32ptr = OpTypePointer Function %u32\n"
5071 "%id = OpVariable %uvec3ptr Input\n"
5072 "%zero = OpConstant %i32 0\n"
5073 "%uzero = OpConstant %u32 0\n"
5074 "%one = OpConstant %i32 1\n"
5075 "%constf1 = OpConstant %f32 1.0\n"
5076 "%four = OpConstant %u32 4\n"
5078 "%main = OpFunction %void None %voidf\n"
5079 "%entry = OpLabel\n"
5080 "%i = OpVariable %u32ptr Function\n"
5081 " OpStore %i %uzero\n"
5083 "%idval = OpLoad %uvec3 %id\n"
5084 "%x = OpCompositeExtract %u32 %idval 0\n"
5085 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
5086 "%inval = OpLoad %f32 %inloc\n"
5087 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
5088 " OpStore %outloc %inval\n"
5089 " OpBranch %loop_entry\n"
5091 "%loop_entry = OpLabel\n"
5092 "%i_val = OpLoad %u32 %i\n"
5093 "%cmp_lt = OpULessThan %bool %i_val %four\n"
5094 " OpLoopMerge %loop_merge %loop_body ${CONTROL}\n"
5095 " OpBranchConditional %cmp_lt %loop_body %loop_merge\n"
5096 "%loop_body = OpLabel\n"
5097 "%outval = OpLoad %f32 %outloc\n"
5098 "%addf1 = OpFAdd %f32 %outval %constf1\n"
5099 " OpStore %outloc %addf1\n"
5100 "%new_i = OpIAdd %u32 %i_val %one\n"
5101 " OpStore %i %new_i\n"
5102 " OpBranch %loop_entry\n"
5103 "%loop_merge = OpLabel\n"
5105 " OpFunctionEnd\n");
5107 cases.push_back(CaseParameter("none", "None"));
5108 cases.push_back(CaseParameter("unroll", "Unroll"));
5109 cases.push_back(CaseParameter("dont_unroll", "DontUnroll"));
5111 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats[0], numElements);
5113 for (size_t ndx = 0; ndx < numElements; ++ndx)
5114 outputFloats[ndx] = inputFloats[ndx] + 4.f;
5116 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
5118 map<string, string> specializations;
5119 ComputeShaderSpec spec;
5121 specializations["CONTROL"] = cases[caseNdx].param;
5122 spec.assembly = shaderTemplate.specialize(specializations);
5123 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
5124 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
5125 spec.numWorkGroups = IVec3(numElements, 1, 1);
5127 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
5130 group->addChild(new SpvAsmLoopControlDependencyLengthCase(testCtx, "dependency_length", "dependency_length"));
5131 group->addChild(new SpvAsmLoopControlDependencyInfiniteCase(testCtx, "dependency_infinite", "dependency_infinite"));
5133 return group.release();
5136 // Assembly code used for testing selection control is based on GLSL source code:
5139 // layout(std140, set = 0, binding = 0) readonly buffer Input {
5140 // float elements[];
5142 // layout(std140, set = 0, binding = 1) writeonly buffer Output {
5143 // float elements[];
5147 // uint x = gl_GlobalInvocationID.x;
5148 // float val = input_data.elements[x];
5150 // output_data.elements[x] = val + 1.f;
5152 // output_data.elements[x] = val - 1.f;
5154 tcu::TestCaseGroup* createSelectionControlGroup (tcu::TestContext& testCtx)
5156 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "selection_control", "Tests selection control cases"));
5157 vector<CaseParameter> cases;
5158 de::Random rnd (deStringHash(group->getName()));
5159 const int numElements = 100;
5160 vector<float> inputFloats (numElements, 0);
5161 vector<float> outputFloats (numElements, 0);
5162 const StringTemplate shaderTemplate (
5163 string(getComputeAsmShaderPreamble()) +
5165 "OpSource GLSL 430\n"
5166 "OpName %main \"main\"\n"
5167 "OpName %id \"gl_GlobalInvocationID\"\n"
5169 "OpDecorate %id BuiltIn GlobalInvocationId\n"
5171 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
5173 "%id = OpVariable %uvec3ptr Input\n"
5174 "%zero = OpConstant %i32 0\n"
5175 "%constf1 = OpConstant %f32 1.0\n"
5176 "%constf10 = OpConstant %f32 10.0\n"
5178 "%main = OpFunction %void None %voidf\n"
5179 "%entry = OpLabel\n"
5180 "%idval = OpLoad %uvec3 %id\n"
5181 "%x = OpCompositeExtract %u32 %idval 0\n"
5182 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
5183 "%inval = OpLoad %f32 %inloc\n"
5184 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
5185 "%cmp_gt = OpFOrdGreaterThan %bool %inval %constf10\n"
5187 " OpSelectionMerge %if_end ${CONTROL}\n"
5188 " OpBranchConditional %cmp_gt %if_true %if_false\n"
5189 "%if_true = OpLabel\n"
5190 "%addf1 = OpFAdd %f32 %inval %constf1\n"
5191 " OpStore %outloc %addf1\n"
5192 " OpBranch %if_end\n"
5193 "%if_false = OpLabel\n"
5194 "%subf1 = OpFSub %f32 %inval %constf1\n"
5195 " OpStore %outloc %subf1\n"
5196 " OpBranch %if_end\n"
5197 "%if_end = OpLabel\n"
5199 " OpFunctionEnd\n");
5201 cases.push_back(CaseParameter("none", "None"));
5202 cases.push_back(CaseParameter("flatten", "Flatten"));
5203 cases.push_back(CaseParameter("dont_flatten", "DontFlatten"));
5204 cases.push_back(CaseParameter("flatten_dont_flatten", "DontFlatten|Flatten"));
5206 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats[0], numElements);
5208 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
5209 floorAll(inputFloats);
5211 for (size_t ndx = 0; ndx < numElements; ++ndx)
5212 outputFloats[ndx] = inputFloats[ndx] + (inputFloats[ndx] > 10.f ? 1.f : -1.f);
5214 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
5216 map<string, string> specializations;
5217 ComputeShaderSpec spec;
5219 specializations["CONTROL"] = cases[caseNdx].param;
5220 spec.assembly = shaderTemplate.specialize(specializations);
5221 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
5222 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
5223 spec.numWorkGroups = IVec3(numElements, 1, 1);
5225 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
5228 return group.release();
5231 tcu::TestCaseGroup* createOpNameGroup(tcu::TestContext& testCtx)
5233 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opname", "Tests OpName cases"));
5234 de::MovePtr<tcu::TestCaseGroup> entryMainGroup (new tcu::TestCaseGroup(testCtx, "entry_main", "OpName tests with entry main"));
5235 de::MovePtr<tcu::TestCaseGroup> entryNotGroup (new tcu::TestCaseGroup(testCtx, "entry_rdc", "OpName tests with entry rdc"));
5236 vector<CaseParameter> cases;
5237 vector<string> testFunc;
5238 de::Random rnd (deStringHash(group->getName()));
5239 const int numElements = 100;
5240 vector<float> inputFloats (numElements, 0);
5241 vector<float> outputFloats (numElements, 0);
5243 fillRandomScalars(rnd, -100.0f, 100.0f, &inputFloats[0], numElements);
5245 for(size_t ndx = 0; ndx < numElements; ++ndx)
5246 outputFloats[ndx] = -inputFloats[ndx];
5248 const StringTemplate shaderTemplate (
5249 "OpCapability Shader\n"
5250 "OpMemoryModel Logical GLSL450\n"
5251 "OpEntryPoint GLCompute %main \"${ENTRY}\" %id\n"
5252 "OpExecutionMode %main LocalSize 1 1 1\n"
5254 "OpName %${FUNC_ID} \"${NAME}\"\n"
5256 "OpDecorate %id BuiltIn GlobalInvocationId\n"
5258 + string(getComputeAsmInputOutputBufferTraits())
5260 + string(getComputeAsmCommonTypes())
5262 + string(getComputeAsmInputOutputBuffer()) +
5264 "%id = OpVariable %uvec3ptr Input\n"
5265 "%zero = OpConstant %i32 0\n"
5267 "%func = OpFunction %void None %voidf\n"
5272 "%main = OpFunction %void None %voidf\n"
5273 "%entry = OpLabel\n"
5274 "%7 = OpFunctionCall %void %func\n"
5276 "%idval = OpLoad %uvec3 %id\n"
5277 "%x = OpCompositeExtract %u32 %idval 0\n"
5279 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
5280 "%inval = OpLoad %f32 %inloc\n"
5281 "%neg = OpFNegate %f32 %inval\n"
5282 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
5283 " OpStore %outloc %neg\n"
5287 " OpFunctionEnd\n");
5289 cases.push_back(CaseParameter("_is_main", "main"));
5290 cases.push_back(CaseParameter("_is_not_main", "not_main"));
5292 testFunc.push_back("main");
5293 testFunc.push_back("func");
5295 for(size_t fNdx = 0; fNdx < testFunc.size(); ++fNdx)
5297 for(size_t ndx = 0; ndx < cases.size(); ++ndx)
5299 map<string, string> specializations;
5300 ComputeShaderSpec spec;
5302 specializations["ENTRY"] = "main";
5303 specializations["FUNC_ID"] = testFunc[fNdx];
5304 specializations["NAME"] = cases[ndx].param;
5305 spec.assembly = shaderTemplate.specialize(specializations);
5306 spec.numWorkGroups = IVec3(numElements, 1, 1);
5307 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
5308 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
5310 entryMainGroup->addChild(new SpvAsmComputeShaderCase(testCtx, (testFunc[fNdx] + cases[ndx].name).c_str(), cases[ndx].name, spec));
5314 cases.push_back(CaseParameter("_is_entry", "rdc"));
5316 for(size_t fNdx = 0; fNdx < testFunc.size(); ++fNdx)
5318 for(size_t ndx = 0; ndx < cases.size(); ++ndx)
5320 map<string, string> specializations;
5321 ComputeShaderSpec spec;
5323 specializations["ENTRY"] = "rdc";
5324 specializations["FUNC_ID"] = testFunc[fNdx];
5325 specializations["NAME"] = cases[ndx].param;
5326 spec.assembly = shaderTemplate.specialize(specializations);
5327 spec.numWorkGroups = IVec3(numElements, 1, 1);
5328 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
5329 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
5330 spec.entryPoint = "rdc";
5332 entryNotGroup->addChild(new SpvAsmComputeShaderCase(testCtx, (testFunc[fNdx] + cases[ndx].name).c_str(), cases[ndx].name, spec));
5336 group->addChild(entryMainGroup.release());
5337 group->addChild(entryNotGroup.release());
5339 return group.release();
5342 // Assembly code used for testing function control is based on GLSL source code:
5346 // layout(std140, set = 0, binding = 0) readonly buffer Input {
5347 // float elements[];
5349 // layout(std140, set = 0, binding = 1) writeonly buffer Output {
5350 // float elements[];
5353 // float const10() { return 10.f; }
5356 // uint x = gl_GlobalInvocationID.x;
5357 // output_data.elements[x] = input_data.elements[x] + const10();
5359 tcu::TestCaseGroup* createFunctionControlGroup (tcu::TestContext& testCtx)
5361 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "function_control", "Tests function control cases"));
5362 vector<CaseParameter> cases;
5363 de::Random rnd (deStringHash(group->getName()));
5364 const int numElements = 100;
5365 vector<float> inputFloats (numElements, 0);
5366 vector<float> outputFloats (numElements, 0);
5367 const StringTemplate shaderTemplate (
5368 string(getComputeAsmShaderPreamble()) +
5370 "OpSource GLSL 430\n"
5371 "OpName %main \"main\"\n"
5372 "OpName %func_const10 \"const10(\"\n"
5373 "OpName %id \"gl_GlobalInvocationID\"\n"
5375 "OpDecorate %id BuiltIn GlobalInvocationId\n"
5377 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
5379 "%f32f = OpTypeFunction %f32\n"
5380 "%id = OpVariable %uvec3ptr Input\n"
5381 "%zero = OpConstant %i32 0\n"
5382 "%constf10 = OpConstant %f32 10.0\n"
5384 "%main = OpFunction %void None %voidf\n"
5385 "%entry = OpLabel\n"
5386 "%idval = OpLoad %uvec3 %id\n"
5387 "%x = OpCompositeExtract %u32 %idval 0\n"
5388 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
5389 "%inval = OpLoad %f32 %inloc\n"
5390 "%ret_10 = OpFunctionCall %f32 %func_const10\n"
5391 "%fadd = OpFAdd %f32 %inval %ret_10\n"
5392 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
5393 " OpStore %outloc %fadd\n"
5397 "%func_const10 = OpFunction %f32 ${CONTROL} %f32f\n"
5398 "%label = OpLabel\n"
5399 " OpReturnValue %constf10\n"
5400 " OpFunctionEnd\n");
5402 cases.push_back(CaseParameter("none", "None"));
5403 cases.push_back(CaseParameter("inline", "Inline"));
5404 cases.push_back(CaseParameter("dont_inline", "DontInline"));
5405 cases.push_back(CaseParameter("pure", "Pure"));
5406 cases.push_back(CaseParameter("const", "Const"));
5407 cases.push_back(CaseParameter("inline_pure", "Inline|Pure"));
5408 cases.push_back(CaseParameter("const_dont_inline", "Const|DontInline"));
5409 cases.push_back(CaseParameter("inline_dont_inline", "Inline|DontInline"));
5410 cases.push_back(CaseParameter("pure_inline_dont_inline", "Pure|Inline|DontInline"));
5412 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats[0], numElements);
5414 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
5415 floorAll(inputFloats);
5417 for (size_t ndx = 0; ndx < numElements; ++ndx)
5418 outputFloats[ndx] = inputFloats[ndx] + 10.f;
5420 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
5422 map<string, string> specializations;
5423 ComputeShaderSpec spec;
5425 specializations["CONTROL"] = cases[caseNdx].param;
5426 spec.assembly = shaderTemplate.specialize(specializations);
5427 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
5428 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
5429 spec.numWorkGroups = IVec3(numElements, 1, 1);
5431 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
5434 return group.release();
5437 tcu::TestCaseGroup* createMemoryAccessGroup (tcu::TestContext& testCtx)
5439 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "memory_access", "Tests memory access cases"));
5440 vector<CaseParameter> cases;
5441 de::Random rnd (deStringHash(group->getName()));
5442 const int numElements = 100;
5443 vector<float> inputFloats (numElements, 0);
5444 vector<float> outputFloats (numElements, 0);
5445 const StringTemplate shaderTemplate (
5446 string(getComputeAsmShaderPreamble()) +
5448 "OpSource GLSL 430\n"
5449 "OpName %main \"main\"\n"
5450 "OpName %id \"gl_GlobalInvocationID\"\n"
5452 "OpDecorate %id BuiltIn GlobalInvocationId\n"
5454 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
5456 "%f32ptr_f = OpTypePointer Function %f32\n"
5458 "%id = OpVariable %uvec3ptr Input\n"
5459 "%zero = OpConstant %i32 0\n"
5460 "%four = OpConstant %i32 4\n"
5462 "%main = OpFunction %void None %voidf\n"
5463 "%label = OpLabel\n"
5464 "%copy = OpVariable %f32ptr_f Function\n"
5465 "%idval = OpLoad %uvec3 %id ${ACCESS}\n"
5466 "%x = OpCompositeExtract %u32 %idval 0\n"
5467 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
5468 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
5469 " OpCopyMemory %copy %inloc ${ACCESS}\n"
5470 "%val1 = OpLoad %f32 %copy\n"
5471 "%val2 = OpLoad %f32 %inloc\n"
5472 "%add = OpFAdd %f32 %val1 %val2\n"
5473 " OpStore %outloc %add ${ACCESS}\n"
5475 " OpFunctionEnd\n");
5477 cases.push_back(CaseParameter("null", ""));
5478 cases.push_back(CaseParameter("none", "None"));
5479 cases.push_back(CaseParameter("volatile", "Volatile"));
5480 cases.push_back(CaseParameter("aligned", "Aligned 4"));
5481 cases.push_back(CaseParameter("nontemporal", "Nontemporal"));
5482 cases.push_back(CaseParameter("aligned_nontemporal", "Aligned|Nontemporal 4"));
5483 cases.push_back(CaseParameter("aligned_volatile", "Volatile|Aligned 4"));
5485 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats[0], numElements);
5487 for (size_t ndx = 0; ndx < numElements; ++ndx)
5488 outputFloats[ndx] = inputFloats[ndx] + inputFloats[ndx];
5490 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
5492 map<string, string> specializations;
5493 ComputeShaderSpec spec;
5495 specializations["ACCESS"] = cases[caseNdx].param;
5496 spec.assembly = shaderTemplate.specialize(specializations);
5497 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
5498 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
5499 spec.numWorkGroups = IVec3(numElements, 1, 1);
5501 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
5504 return group.release();
5507 // Checks that we can get undefined values for various types, without exercising a computation with it.
5508 tcu::TestCaseGroup* createOpUndefGroup (tcu::TestContext& testCtx)
5510 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opundef", "Tests the OpUndef instruction"));
5511 vector<CaseParameter> cases;
5512 de::Random rnd (deStringHash(group->getName()));
5513 const int numElements = 100;
5514 vector<float> positiveFloats (numElements, 0);
5515 vector<float> negativeFloats (numElements, 0);
5516 const StringTemplate shaderTemplate (
5517 string(getComputeAsmShaderPreamble()) +
5519 "OpSource GLSL 430\n"
5520 "OpName %main \"main\"\n"
5521 "OpName %id \"gl_GlobalInvocationID\"\n"
5523 "OpDecorate %id BuiltIn GlobalInvocationId\n"
5525 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
5526 "%uvec2 = OpTypeVector %u32 2\n"
5527 "%fvec4 = OpTypeVector %f32 4\n"
5528 "%fmat33 = OpTypeMatrix %fvec3 3\n"
5529 "%image = OpTypeImage %f32 2D 0 0 0 1 Unknown\n"
5530 "%sampler = OpTypeSampler\n"
5531 "%simage = OpTypeSampledImage %image\n"
5532 "%const100 = OpConstant %u32 100\n"
5533 "%uarr100 = OpTypeArray %i32 %const100\n"
5534 "%struct = OpTypeStruct %f32 %i32 %u32\n"
5535 "%pointer = OpTypePointer Function %i32\n"
5536 + string(getComputeAsmInputOutputBuffer()) +
5538 "%id = OpVariable %uvec3ptr Input\n"
5539 "%zero = OpConstant %i32 0\n"
5541 "%main = OpFunction %void None %voidf\n"
5542 "%label = OpLabel\n"
5544 "%undef = OpUndef ${TYPE}\n"
5546 "%idval = OpLoad %uvec3 %id\n"
5547 "%x = OpCompositeExtract %u32 %idval 0\n"
5549 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
5550 "%inval = OpLoad %f32 %inloc\n"
5551 "%neg = OpFNegate %f32 %inval\n"
5552 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
5553 " OpStore %outloc %neg\n"
5555 " OpFunctionEnd\n");
5557 cases.push_back(CaseParameter("bool", "%bool"));
5558 cases.push_back(CaseParameter("sint32", "%i32"));
5559 cases.push_back(CaseParameter("uint32", "%u32"));
5560 cases.push_back(CaseParameter("float32", "%f32"));
5561 cases.push_back(CaseParameter("vec4float32", "%fvec4"));
5562 cases.push_back(CaseParameter("vec2uint32", "%uvec2"));
5563 cases.push_back(CaseParameter("matrix", "%fmat33"));
5564 cases.push_back(CaseParameter("image", "%image"));
5565 cases.push_back(CaseParameter("sampler", "%sampler"));
5566 cases.push_back(CaseParameter("sampledimage", "%simage"));
5567 cases.push_back(CaseParameter("array", "%uarr100"));
5568 cases.push_back(CaseParameter("runtimearray", "%f32arr"));
5569 cases.push_back(CaseParameter("struct", "%struct"));
5570 cases.push_back(CaseParameter("pointer", "%pointer"));
5572 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
5574 for (size_t ndx = 0; ndx < numElements; ++ndx)
5575 negativeFloats[ndx] = -positiveFloats[ndx];
5577 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
5579 map<string, string> specializations;
5580 ComputeShaderSpec spec;
5582 specializations["TYPE"] = cases[caseNdx].param;
5583 spec.assembly = shaderTemplate.specialize(specializations);
5584 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
5585 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
5586 spec.numWorkGroups = IVec3(numElements, 1, 1);
5588 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
5591 return group.release();
5594 // Checks that a compute shader can generate a constant composite value of various types, without exercising a computation on it.
5595 tcu::TestCaseGroup* createFloat16OpConstantCompositeGroup (tcu::TestContext& testCtx)
5597 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opconstantcomposite", "Tests the OpConstantComposite instruction"));
5598 vector<CaseParameter> cases;
5599 de::Random rnd (deStringHash(group->getName()));
5600 const int numElements = 100;
5601 vector<float> positiveFloats (numElements, 0);
5602 vector<float> negativeFloats (numElements, 0);
5603 const StringTemplate shaderTemplate (
5604 "OpCapability Shader\n"
5605 "OpCapability Float16\n"
5606 "OpMemoryModel Logical GLSL450\n"
5607 "OpEntryPoint GLCompute %main \"main\" %id\n"
5608 "OpExecutionMode %main LocalSize 1 1 1\n"
5609 "OpSource GLSL 430\n"
5610 "OpName %main \"main\"\n"
5611 "OpName %id \"gl_GlobalInvocationID\"\n"
5613 "OpDecorate %id BuiltIn GlobalInvocationId\n"
5615 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
5617 "%id = OpVariable %uvec3ptr Input\n"
5618 "%zero = OpConstant %i32 0\n"
5619 "%f16 = OpTypeFloat 16\n"
5620 "%c_f16_0 = OpConstant %f16 0.0\n"
5621 "%c_f16_0_5 = OpConstant %f16 0.5\n"
5622 "%c_f16_1 = OpConstant %f16 1.0\n"
5623 "%v2f16 = OpTypeVector %f16 2\n"
5624 "%v3f16 = OpTypeVector %f16 3\n"
5625 "%v4f16 = OpTypeVector %f16 4\n"
5629 "%main = OpFunction %void None %voidf\n"
5630 "%label = OpLabel\n"
5631 "%idval = OpLoad %uvec3 %id\n"
5632 "%x = OpCompositeExtract %u32 %idval 0\n"
5633 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
5634 "%inval = OpLoad %f32 %inloc\n"
5635 "%neg = OpFNegate %f32 %inval\n"
5636 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
5637 " OpStore %outloc %neg\n"
5639 " OpFunctionEnd\n");
5642 cases.push_back(CaseParameter("vector", "%const = OpConstantComposite %v3f16 %c_f16_0 %c_f16_0_5 %c_f16_1\n"));
5643 cases.push_back(CaseParameter("matrix", "%m3v3f16 = OpTypeMatrix %v3f16 3\n"
5644 "%vec = OpConstantComposite %v3f16 %c_f16_0 %c_f16_0_5 %c_f16_1\n"
5645 "%mat = OpConstantComposite %m3v3f16 %vec %vec %vec"));
5646 cases.push_back(CaseParameter("struct", "%m2v3f16 = OpTypeMatrix %v3f16 2\n"
5647 "%struct = OpTypeStruct %i32 %f16 %v3f16 %m2v3f16\n"
5648 "%vec = OpConstantComposite %v3f16 %c_f16_0 %c_f16_0_5 %c_f16_1\n"
5649 "%mat = OpConstantComposite %m2v3f16 %vec %vec\n"
5650 "%const = OpConstantComposite %struct %zero %c_f16_0_5 %vec %mat\n"));
5651 cases.push_back(CaseParameter("nested_struct", "%st1 = OpTypeStruct %i32 %f16\n"
5652 "%st2 = OpTypeStruct %i32 %i32\n"
5653 "%struct = OpTypeStruct %st1 %st2\n"
5654 "%st1val = OpConstantComposite %st1 %zero %c_f16_0_5\n"
5655 "%st2val = OpConstantComposite %st2 %zero %zero\n"
5656 "%const = OpConstantComposite %struct %st1val %st2val"));
5658 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
5660 for (size_t ndx = 0; ndx < numElements; ++ndx)
5661 negativeFloats[ndx] = -positiveFloats[ndx];
5663 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
5665 map<string, string> specializations;
5666 ComputeShaderSpec spec;
5668 specializations["CONSTANT"] = cases[caseNdx].param;
5669 spec.assembly = shaderTemplate.specialize(specializations);
5670 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
5671 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
5672 spec.numWorkGroups = IVec3(numElements, 1, 1);
5673 spec.extensions.push_back("VK_KHR_16bit_storage");
5675 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
5678 return group.release();
5681 // IEEE-754 floating point numbers:
5682 // +--------+------+----------+-------------+
5683 // | binary | sign | exponent | significand |
5684 // +--------+------+----------+-------------+
5685 // | 16-bit | 1 | 5 | 10 |
5686 // +--------+------+----------+-------------+
5687 // | 32-bit | 1 | 8 | 23 |
5688 // +--------+------+----------+-------------+
5692 // 0 000 00 00 0000 0001 (0x0001: 2e-24: minimum positive denormalized)
5693 // 0 000 00 11 1111 1111 (0x03ff: 2e-14 - 2e-24: maximum positive denormalized)
5694 // 0 000 01 00 0000 0000 (0x0400: 2e-14: minimum positive normalized)
5696 // 0 000 00 00 0000 0000 (0x0000: +0)
5697 // 0 111 11 00 0000 0000 (0x7c00: +Inf)
5698 // 0 000 00 11 1111 0000 (0x03f0: +Denorm)
5699 // 0 000 01 00 0000 0001 (0x0401: +Norm)
5700 // 0 111 11 00 0000 1111 (0x7c0f: +SNaN)
5701 // 0 111 11 11 1111 0000 (0x7ff0: +QNaN)
5703 // Generate and return 16-bit floats and their corresponding 32-bit values.
5705 // The first 14 number pairs are manually picked, while the rest are randomly generated.
5706 // Expected count to be at least 14 (numPicks).
5707 vector<deFloat16> getFloat16s (de::Random& rnd, deUint32 count)
5709 vector<deFloat16> float16;
5711 float16.reserve(count);
5714 float16.push_back(deUint16(0x0000));
5715 float16.push_back(deUint16(0x8000));
5717 float16.push_back(deUint16(0x7c00));
5718 float16.push_back(deUint16(0xfc00));
5720 float16.push_back(deUint16(0x7c0f));
5721 float16.push_back(deUint16(0xfc0f));
5723 float16.push_back(deUint16(0x7ff0));
5724 float16.push_back(deUint16(0xfff0));
5727 float16.push_back(deUint16(0x03f0));
5728 float16.push_back(deUint16(0x83f0));
5730 float16.push_back(deUint16(0x0401));
5731 float16.push_back(deUint16(0x8401));
5732 // Some normal number
5733 float16.push_back(deUint16(0x14cb));
5734 float16.push_back(deUint16(0x94cb));
5736 const deUint32 numPicks = static_cast<deUint32>(float16.size());
5738 DE_ASSERT(count >= numPicks);
5741 for (deUint32 numIdx = 0; numIdx < count; ++numIdx)
5742 float16.push_back(rnd.getUint16());
5747 const vector<deFloat16> squarize(const vector<deFloat16>& inData, const deUint32 argNo)
5749 const size_t inDataLength = inData.size();
5750 vector<deFloat16> result;
5752 result.reserve(inDataLength * inDataLength);
5756 for (size_t numIdx = 0; numIdx < inDataLength; ++numIdx)
5757 result.insert(result.end(), inData.begin(), inData.end());
5762 for (size_t numIdx = 0; numIdx < inDataLength; ++numIdx)
5764 const vector<deFloat16> tmp(inDataLength, inData[numIdx]);
5766 result.insert(result.end(), tmp.begin(), tmp.end());
5773 const vector<deFloat16> squarizeVector(const vector<deFloat16>& inData, const deUint32 argNo)
5775 vector<deFloat16> vec;
5776 vector<deFloat16> result;
5778 // Create vectors. vec will contain each possible pair from inData
5780 const size_t inDataLength = inData.size();
5782 DE_ASSERT(inDataLength <= 64);
5784 vec.reserve(2 * inDataLength * inDataLength);
5786 for (size_t numIdxX = 0; numIdxX < inDataLength; ++numIdxX)
5787 for (size_t numIdxY = 0; numIdxY < inDataLength; ++numIdxY)
5789 vec.push_back(inData[numIdxX]);
5790 vec.push_back(inData[numIdxY]);
5794 // Create vector pairs. result will contain each possible pair from vec
5796 const size_t coordsPerVector = 2;
5797 const size_t vectorsCount = vec.size() / coordsPerVector;
5799 result.reserve(coordsPerVector * vectorsCount * vectorsCount);
5803 for (size_t numIdxX = 0; numIdxX < vectorsCount; ++numIdxX)
5804 for (size_t numIdxY = 0; numIdxY < vectorsCount; ++numIdxY)
5806 for (size_t coordNdx = 0; coordNdx < coordsPerVector; ++coordNdx)
5807 result.push_back(vec[coordsPerVector * numIdxY + coordNdx]);
5813 for (size_t numIdxX = 0; numIdxX < vectorsCount; ++numIdxX)
5814 for (size_t numIdxY = 0; numIdxY < vectorsCount; ++numIdxY)
5816 for (size_t coordNdx = 0; coordNdx < coordsPerVector; ++coordNdx)
5817 result.push_back(vec[coordsPerVector * numIdxX + coordNdx]);
5825 struct fp16isNan { bool operator()(const tcu::Float16 in1, const tcu::Float16) { return in1.isNaN(); } };
5826 struct fp16isInf { bool operator()(const tcu::Float16 in1, const tcu::Float16) { return in1.isInf(); } };
5827 struct fp16isEqual { bool operator()(const tcu::Float16 in1, const tcu::Float16 in2) { return in1.asFloat() == in2.asFloat(); } };
5828 struct fp16isUnequal { bool operator()(const tcu::Float16 in1, const tcu::Float16 in2) { return in1.asFloat() != in2.asFloat(); } };
5829 struct fp16isLess { bool operator()(const tcu::Float16 in1, const tcu::Float16 in2) { return in1.asFloat() < in2.asFloat(); } };
5830 struct fp16isGreater { bool operator()(const tcu::Float16 in1, const tcu::Float16 in2) { return in1.asFloat() > in2.asFloat(); } };
5831 struct fp16isLessOrEqual { bool operator()(const tcu::Float16 in1, const tcu::Float16 in2) { return in1.asFloat() <= in2.asFloat(); } };
5832 struct fp16isGreaterOrEqual { bool operator()(const tcu::Float16 in1, const tcu::Float16 in2) { return in1.asFloat() >= in2.asFloat(); } };
5834 template <class TestedLogicalFunction, bool onlyTestFunc, bool unationModeAnd, bool nanSupported>
5835 bool compareFP16Logical (const std::vector<Resource>& inputs, const vector<AllocationSp>& outputAllocs, const std::vector<Resource>&, TestLog& log)
5837 if (inputs.size() != 2 || outputAllocs.size() != 1)
5840 vector<deUint8> input1Bytes;
5841 vector<deUint8> input2Bytes;
5843 inputs[0].getBytes(input1Bytes);
5844 inputs[1].getBytes(input2Bytes);
5846 const deUint32 denormModesCount = 2;
5847 const deFloat16 float16one = tcu::Float16(1.0f).bits();
5848 const deFloat16 float16zero = tcu::Float16(0.0f).bits();
5849 const tcu::Float16 zero = tcu::Float16::zero(1);
5850 const deFloat16* const outputAsFP16 = static_cast<deFloat16*>(outputAllocs[0]->getHostPtr());
5851 const deFloat16* const input1AsFP16 = reinterpret_cast<deFloat16* const>(&input1Bytes.front());
5852 const deFloat16* const input2AsFP16 = reinterpret_cast<deFloat16* const>(&input2Bytes.front());
5853 deUint32 successfulRuns = denormModesCount;
5854 std::string results[denormModesCount];
5855 TestedLogicalFunction testedLogicalFunction;
5857 for (deUint32 denormMode = 0; denormMode < denormModesCount; denormMode++)
5859 const bool flushToZero = (denormMode == 1);
5861 for (size_t idx = 0; idx < input1Bytes.size() / sizeof(deFloat16); ++idx)
5863 const tcu::Float16 f1pre = tcu::Float16(input1AsFP16[idx]);
5864 const tcu::Float16 f2pre = tcu::Float16(input2AsFP16[idx]);
5865 const tcu::Float16 f1 = (flushToZero && f1pre.isDenorm()) ? zero : f1pre;
5866 const tcu::Float16 f2 = (flushToZero && f2pre.isDenorm()) ? zero : f2pre;
5867 deFloat16 expectedOutput = float16zero;
5871 if (testedLogicalFunction(f1, f2))
5872 expectedOutput = float16one;
5876 const bool f1nan = f1.isNaN();
5877 const bool f2nan = f2.isNaN();
5879 // Skip NaN floats if not supported by implementation
5880 if (!nanSupported && (f1nan || f2nan))
5885 const bool ordered = !f1nan && !f2nan;
5887 if (ordered && testedLogicalFunction(f1, f2))
5888 expectedOutput = float16one;
5892 const bool unordered = f1nan || f2nan;
5894 if (unordered || testedLogicalFunction(f1, f2))
5895 expectedOutput = float16one;
5899 if (outputAsFP16[idx] != expectedOutput)
5901 std::ostringstream str;
5903 str << "ERROR: Sub-case #" << idx
5904 << " flushToZero:" << flushToZero
5906 << " failed, inputs: 0x" << f1.bits()
5907 << ";0x" << f2.bits()
5908 << " output: 0x" << outputAsFP16[idx]
5909 << " expected output: 0x" << expectedOutput;
5911 results[denormMode] = str.str();
5920 if (successfulRuns == 0)
5921 for (deUint32 denormMode = 0; denormMode < denormModesCount; denormMode++)
5922 log << TestLog::Message << results[denormMode] << TestLog::EndMessage;
5924 return successfulRuns > 0;
5929 tcu::TestCaseGroup* createOpSourceTests (tcu::TestContext& testCtx)
5931 struct NameCodePair { string name, code; };
5932 RGBA defaultColors[4];
5933 de::MovePtr<tcu::TestCaseGroup> opSourceTests (new tcu::TestCaseGroup(testCtx, "opsource", "OpSource instruction"));
5934 const std::string opsourceGLSLWithFile = "%opsrcfile = OpString \"foo.vert\"\nOpSource GLSL 450 %opsrcfile ";
5935 map<string, string> fragments = passthruFragments();
5936 const NameCodePair tests[] =
5938 {"unknown", "OpSource Unknown 321"},
5939 {"essl", "OpSource ESSL 310"},
5940 {"glsl", "OpSource GLSL 450"},
5941 {"opencl_cpp", "OpSource OpenCL_CPP 120"},
5942 {"opencl_c", "OpSource OpenCL_C 120"},
5943 {"multiple", "OpSource GLSL 450\nOpSource GLSL 450"},
5944 {"file", opsourceGLSLWithFile},
5945 {"source", opsourceGLSLWithFile + "\"void main(){}\""},
5946 // Longest possible source string: SPIR-V limits instructions to 65535
5947 // words, of which the first 4 are opsourceGLSLWithFile; the rest will
5948 // contain 65530 UTF8 characters (one word each) plus one last word
5949 // containing 3 ASCII characters and \0.
5950 {"longsource", opsourceGLSLWithFile + '"' + makeLongUTF8String(65530) + "ccc" + '"'}
5953 getDefaultColors(defaultColors);
5954 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameCodePair); ++testNdx)
5956 fragments["debug"] = tests[testNdx].code;
5957 createTestsForAllStages(tests[testNdx].name, defaultColors, defaultColors, fragments, opSourceTests.get());
5960 return opSourceTests.release();
5963 tcu::TestCaseGroup* createOpSourceContinuedTests (tcu::TestContext& testCtx)
5965 struct NameCodePair { string name, code; };
5966 RGBA defaultColors[4];
5967 de::MovePtr<tcu::TestCaseGroup> opSourceTests (new tcu::TestCaseGroup(testCtx, "opsourcecontinued", "OpSourceContinued instruction"));
5968 map<string, string> fragments = passthruFragments();
5969 const std::string opsource = "%opsrcfile = OpString \"foo.vert\"\nOpSource GLSL 450 %opsrcfile \"void main(){}\"\n";
5970 const NameCodePair tests[] =
5972 {"empty", opsource + "OpSourceContinued \"\""},
5973 {"short", opsource + "OpSourceContinued \"abcde\""},
5974 {"multiple", opsource + "OpSourceContinued \"abcde\"\nOpSourceContinued \"fghij\""},
5975 // Longest possible source string: SPIR-V limits instructions to 65535
5976 // words, of which the first one is OpSourceContinued/length; the rest
5977 // will contain 65533 UTF8 characters (one word each) plus one last word
5978 // containing 3 ASCII characters and \0.
5979 {"long", opsource + "OpSourceContinued \"" + makeLongUTF8String(65533) + "ccc\""}
5982 getDefaultColors(defaultColors);
5983 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameCodePair); ++testNdx)
5985 fragments["debug"] = tests[testNdx].code;
5986 createTestsForAllStages(tests[testNdx].name, defaultColors, defaultColors, fragments, opSourceTests.get());
5989 return opSourceTests.release();
5991 tcu::TestCaseGroup* createOpNoLineTests(tcu::TestContext& testCtx)
5993 RGBA defaultColors[4];
5994 de::MovePtr<tcu::TestCaseGroup> opLineTests (new tcu::TestCaseGroup(testCtx, "opnoline", "OpNoLine instruction"));
5995 map<string, string> fragments;
5996 getDefaultColors(defaultColors);
5997 fragments["debug"] =
5998 "%name = OpString \"name\"\n";
6000 fragments["pre_main"] =
6003 "OpLine %name 1 1\n"
6005 "OpLine %name 1 1\n"
6006 "OpLine %name 1 1\n"
6007 "%second_function = OpFunction %v4f32 None %v4f32_v4f32_function\n"
6009 "OpLine %name 1 1\n"
6011 "OpLine %name 1 1\n"
6012 "OpLine %name 1 1\n"
6013 "%second_param1 = OpFunctionParameter %v4f32\n"
6016 "%label_secondfunction = OpLabel\n"
6018 "OpReturnValue %second_param1\n"
6023 fragments["testfun"] =
6024 // A %test_code function that returns its argument unchanged.
6027 "OpLine %name 1 1\n"
6028 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
6030 "%param1 = OpFunctionParameter %v4f32\n"
6033 "%label_testfun = OpLabel\n"
6035 "%val1 = OpFunctionCall %v4f32 %second_function %param1\n"
6036 "OpReturnValue %val1\n"
6038 "OpLine %name 1 1\n"
6041 createTestsForAllStages("opnoline", defaultColors, defaultColors, fragments, opLineTests.get());
6043 return opLineTests.release();
6046 tcu::TestCaseGroup* createOpModuleProcessedTests(tcu::TestContext& testCtx)
6048 RGBA defaultColors[4];
6049 de::MovePtr<tcu::TestCaseGroup> opModuleProcessedTests (new tcu::TestCaseGroup(testCtx, "opmoduleprocessed", "OpModuleProcessed instruction"));
6050 map<string, string> fragments;
6051 std::vector<std::string> noExtensions;
6052 GraphicsResources resources;
6054 getDefaultColors(defaultColors);
6055 resources.verifyBinary = veryfiBinaryShader;
6056 resources.spirvVersion = SPIRV_VERSION_1_3;
6058 fragments["moduleprocessed"] =
6059 "OpModuleProcessed \"VULKAN CTS\"\n"
6060 "OpModuleProcessed \"Negative values\"\n"
6061 "OpModuleProcessed \"Date: 2017/09/21\"\n";
6063 fragments["pre_main"] =
6064 "%second_function = OpFunction %v4f32 None %v4f32_v4f32_function\n"
6065 "%second_param1 = OpFunctionParameter %v4f32\n"
6066 "%label_secondfunction = OpLabel\n"
6067 "OpReturnValue %second_param1\n"
6070 fragments["testfun"] =
6071 // A %test_code function that returns its argument unchanged.
6072 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
6073 "%param1 = OpFunctionParameter %v4f32\n"
6074 "%label_testfun = OpLabel\n"
6075 "%val1 = OpFunctionCall %v4f32 %second_function %param1\n"
6076 "OpReturnValue %val1\n"
6079 createTestsForAllStages ("opmoduleprocessed", defaultColors, defaultColors, fragments, resources, noExtensions, opModuleProcessedTests.get());
6081 return opModuleProcessedTests.release();
6085 tcu::TestCaseGroup* createOpLineTests(tcu::TestContext& testCtx)
6087 RGBA defaultColors[4];
6088 de::MovePtr<tcu::TestCaseGroup> opLineTests (new tcu::TestCaseGroup(testCtx, "opline", "OpLine instruction"));
6089 map<string, string> fragments;
6090 std::vector<std::pair<std::string, std::string> > problemStrings;
6092 problemStrings.push_back(std::make_pair<std::string, std::string>("empty_name", ""));
6093 problemStrings.push_back(std::make_pair<std::string, std::string>("short_name", "short_name"));
6094 problemStrings.push_back(std::make_pair<std::string, std::string>("long_name", makeLongUTF8String(65530) + "ccc"));
6095 getDefaultColors(defaultColors);
6097 fragments["debug"] =
6098 "%other_name = OpString \"other_name\"\n";
6100 fragments["pre_main"] =
6101 "OpLine %file_name 32 0\n"
6102 "OpLine %file_name 32 32\n"
6103 "OpLine %file_name 32 40\n"
6104 "OpLine %other_name 32 40\n"
6105 "OpLine %other_name 0 100\n"
6106 "OpLine %other_name 0 4294967295\n"
6107 "OpLine %other_name 4294967295 0\n"
6108 "OpLine %other_name 32 40\n"
6109 "OpLine %file_name 0 0\n"
6110 "%second_function = OpFunction %v4f32 None %v4f32_v4f32_function\n"
6111 "OpLine %file_name 1 0\n"
6112 "%second_param1 = OpFunctionParameter %v4f32\n"
6113 "OpLine %file_name 1 3\n"
6114 "OpLine %file_name 1 2\n"
6115 "%label_secondfunction = OpLabel\n"
6116 "OpLine %file_name 0 2\n"
6117 "OpReturnValue %second_param1\n"
6119 "OpLine %file_name 0 2\n"
6120 "OpLine %file_name 0 2\n";
6122 fragments["testfun"] =
6123 // A %test_code function that returns its argument unchanged.
6124 "OpLine %file_name 1 0\n"
6125 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
6126 "OpLine %file_name 16 330\n"
6127 "%param1 = OpFunctionParameter %v4f32\n"
6128 "OpLine %file_name 14 442\n"
6129 "%label_testfun = OpLabel\n"
6130 "OpLine %file_name 11 1024\n"
6131 "%val1 = OpFunctionCall %v4f32 %second_function %param1\n"
6132 "OpLine %file_name 2 97\n"
6133 "OpReturnValue %val1\n"
6135 "OpLine %file_name 5 32\n";
6137 for (size_t i = 0; i < problemStrings.size(); ++i)
6139 map<string, string> testFragments = fragments;
6140 testFragments["debug"] += "%file_name = OpString \"" + problemStrings[i].second + "\"\n";
6141 createTestsForAllStages(string("opline") + "_" + problemStrings[i].first, defaultColors, defaultColors, testFragments, opLineTests.get());
6144 return opLineTests.release();
6147 tcu::TestCaseGroup* createOpConstantNullTests(tcu::TestContext& testCtx)
6149 de::MovePtr<tcu::TestCaseGroup> opConstantNullTests (new tcu::TestCaseGroup(testCtx, "opconstantnull", "OpConstantNull instruction"));
6153 const char functionStart[] =
6154 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
6155 "%param1 = OpFunctionParameter %v4f32\n"
6158 const char functionEnd[] =
6159 "OpReturnValue %transformed_param\n"
6162 struct NameConstantsCode
6169 NameConstantsCode tests[] =
6173 "%cnull = OpConstantNull %v4f32\n",
6174 "%transformed_param = OpFAdd %v4f32 %param1 %cnull\n"
6178 "%cnull = OpConstantNull %f32\n",
6179 "%vp = OpVariable %fp_v4f32 Function\n"
6180 "%v = OpLoad %v4f32 %vp\n"
6181 "%v0 = OpVectorInsertDynamic %v4f32 %v %cnull %c_i32_0\n"
6182 "%v1 = OpVectorInsertDynamic %v4f32 %v0 %cnull %c_i32_1\n"
6183 "%v2 = OpVectorInsertDynamic %v4f32 %v1 %cnull %c_i32_2\n"
6184 "%v3 = OpVectorInsertDynamic %v4f32 %v2 %cnull %c_i32_3\n"
6185 "%transformed_param = OpFAdd %v4f32 %param1 %v3\n"
6189 "%cnull = OpConstantNull %bool\n",
6190 "%v = OpVariable %fp_v4f32 Function\n"
6191 " OpStore %v %param1\n"
6192 " OpSelectionMerge %false_label None\n"
6193 " OpBranchConditional %cnull %true_label %false_label\n"
6194 "%true_label = OpLabel\n"
6195 " OpStore %v %c_v4f32_0_5_0_5_0_5_0_5\n"
6196 " OpBranch %false_label\n"
6197 "%false_label = OpLabel\n"
6198 "%transformed_param = OpLoad %v4f32 %v\n"
6202 "%cnull = OpConstantNull %i32\n",
6203 "%v = OpVariable %fp_v4f32 Function %c_v4f32_0_5_0_5_0_5_0_5\n"
6204 "%b = OpIEqual %bool %cnull %c_i32_0\n"
6205 " OpSelectionMerge %false_label None\n"
6206 " OpBranchConditional %b %true_label %false_label\n"
6207 "%true_label = OpLabel\n"
6208 " OpStore %v %param1\n"
6209 " OpBranch %false_label\n"
6210 "%false_label = OpLabel\n"
6211 "%transformed_param = OpLoad %v4f32 %v\n"
6215 "%stype = OpTypeStruct %f32 %v4f32\n"
6216 "%fp_stype = OpTypePointer Function %stype\n"
6217 "%cnull = OpConstantNull %stype\n",
6218 "%v = OpVariable %fp_stype Function %cnull\n"
6219 "%f = OpAccessChain %fp_v4f32 %v %c_i32_1\n"
6220 "%f_val = OpLoad %v4f32 %f\n"
6221 "%transformed_param = OpFAdd %v4f32 %param1 %f_val\n"
6225 "%a4_v4f32 = OpTypeArray %v4f32 %c_u32_4\n"
6226 "%fp_a4_v4f32 = OpTypePointer Function %a4_v4f32\n"
6227 "%cnull = OpConstantNull %a4_v4f32\n",
6228 "%v = OpVariable %fp_a4_v4f32 Function %cnull\n"
6229 "%f = OpAccessChain %fp_v4f32 %v %c_u32_0\n"
6230 "%f1 = OpAccessChain %fp_v4f32 %v %c_u32_1\n"
6231 "%f2 = OpAccessChain %fp_v4f32 %v %c_u32_2\n"
6232 "%f3 = OpAccessChain %fp_v4f32 %v %c_u32_3\n"
6233 "%f_val = OpLoad %v4f32 %f\n"
6234 "%f1_val = OpLoad %v4f32 %f1\n"
6235 "%f2_val = OpLoad %v4f32 %f2\n"
6236 "%f3_val = OpLoad %v4f32 %f3\n"
6237 "%t0 = OpFAdd %v4f32 %param1 %f_val\n"
6238 "%t1 = OpFAdd %v4f32 %t0 %f1_val\n"
6239 "%t2 = OpFAdd %v4f32 %t1 %f2_val\n"
6240 "%transformed_param = OpFAdd %v4f32 %t2 %f3_val\n"
6244 "%mat4x4_f32 = OpTypeMatrix %v4f32 4\n"
6245 "%cnull = OpConstantNull %mat4x4_f32\n",
6246 // Our null matrix * any vector should result in a zero vector.
6247 "%v = OpVectorTimesMatrix %v4f32 %param1 %cnull\n"
6248 "%transformed_param = OpFAdd %v4f32 %param1 %v\n"
6252 getHalfColorsFullAlpha(colors);
6254 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameConstantsCode); ++testNdx)
6256 map<string, string> fragments;
6257 fragments["pre_main"] = tests[testNdx].constants;
6258 fragments["testfun"] = string(functionStart) + tests[testNdx].code + functionEnd;
6259 createTestsForAllStages(tests[testNdx].name, colors, colors, fragments, opConstantNullTests.get());
6261 return opConstantNullTests.release();
6263 tcu::TestCaseGroup* createOpConstantCompositeTests(tcu::TestContext& testCtx)
6265 de::MovePtr<tcu::TestCaseGroup> opConstantCompositeTests (new tcu::TestCaseGroup(testCtx, "opconstantcomposite", "OpConstantComposite instruction"));
6266 RGBA inputColors[4];
6267 RGBA outputColors[4];
6270 const char functionStart[] =
6271 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
6272 "%param1 = OpFunctionParameter %v4f32\n"
6275 const char functionEnd[] =
6276 "OpReturnValue %transformed_param\n"
6279 struct NameConstantsCode
6286 NameConstantsCode tests[] =
6291 "%cval = OpConstantComposite %v4f32 %c_f32_0_5 %c_f32_0_5 %c_f32_0_5 %c_f32_0\n",
6292 "%transformed_param = OpFAdd %v4f32 %param1 %cval\n"
6297 "%stype = OpTypeStruct %v4f32 %f32\n"
6298 "%fp_stype = OpTypePointer Function %stype\n"
6299 "%f32_n_1 = OpConstant %f32 -1.0\n"
6300 "%f32_1_5 = OpConstant %f32 !0x3fc00000\n" // +1.5
6301 "%cvec = OpConstantComposite %v4f32 %f32_1_5 %f32_1_5 %f32_1_5 %c_f32_1\n"
6302 "%cval = OpConstantComposite %stype %cvec %f32_n_1\n",
6304 "%v = OpVariable %fp_stype Function %cval\n"
6305 "%vec_ptr = OpAccessChain %fp_v4f32 %v %c_u32_0\n"
6306 "%f32_ptr = OpAccessChain %fp_f32 %v %c_u32_1\n"
6307 "%vec_val = OpLoad %v4f32 %vec_ptr\n"
6308 "%f32_val = OpLoad %f32 %f32_ptr\n"
6309 "%tmp1 = OpVectorTimesScalar %v4f32 %c_v4f32_1_1_1_1 %f32_val\n" // vec4(-1)
6310 "%tmp2 = OpFAdd %v4f32 %tmp1 %param1\n" // param1 + vec4(-1)
6311 "%transformed_param = OpFAdd %v4f32 %tmp2 %vec_val\n" // param1 + vec4(-1) + vec4(1.5, 1.5, 1.5, 1.0)
6314 // [1|0|0|0.5] [x] = x + 0.5
6315 // [0|1|0|0.5] [y] = y + 0.5
6316 // [0|0|1|0.5] [z] = z + 0.5
6317 // [0|0|0|1 ] [1] = 1
6320 "%mat4x4_f32 = OpTypeMatrix %v4f32 4\n"
6321 "%v4f32_1_0_0_0 = OpConstantComposite %v4f32 %c_f32_1 %c_f32_0 %c_f32_0 %c_f32_0\n"
6322 "%v4f32_0_1_0_0 = OpConstantComposite %v4f32 %c_f32_0 %c_f32_1 %c_f32_0 %c_f32_0\n"
6323 "%v4f32_0_0_1_0 = OpConstantComposite %v4f32 %c_f32_0 %c_f32_0 %c_f32_1 %c_f32_0\n"
6324 "%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"
6325 "%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",
6327 "%transformed_param = OpMatrixTimesVector %v4f32 %cval %param1\n"
6332 "%c_v4f32_1_1_1_0 = OpConstantComposite %v4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_0\n"
6333 "%fp_a4f32 = OpTypePointer Function %a4f32\n"
6334 "%f32_n_1 = OpConstant %f32 -1.0\n"
6335 "%f32_1_5 = OpConstant %f32 !0x3fc00000\n" // +1.5
6336 "%carr = OpConstantComposite %a4f32 %c_f32_0 %f32_n_1 %f32_1_5 %c_f32_0\n",
6338 "%v = OpVariable %fp_a4f32 Function %carr\n"
6339 "%f = OpAccessChain %fp_f32 %v %c_u32_0\n"
6340 "%f1 = OpAccessChain %fp_f32 %v %c_u32_1\n"
6341 "%f2 = OpAccessChain %fp_f32 %v %c_u32_2\n"
6342 "%f3 = OpAccessChain %fp_f32 %v %c_u32_3\n"
6343 "%f_val = OpLoad %f32 %f\n"
6344 "%f1_val = OpLoad %f32 %f1\n"
6345 "%f2_val = OpLoad %f32 %f2\n"
6346 "%f3_val = OpLoad %f32 %f3\n"
6347 "%ftot1 = OpFAdd %f32 %f_val %f1_val\n"
6348 "%ftot2 = OpFAdd %f32 %ftot1 %f2_val\n"
6349 "%ftot3 = OpFAdd %f32 %ftot2 %f3_val\n" // 0 - 1 + 1.5 + 0
6350 "%add_vec = OpVectorTimesScalar %v4f32 %c_v4f32_1_1_1_0 %ftot3\n"
6351 "%transformed_param = OpFAdd %v4f32 %param1 %add_vec\n"
6358 // [ 1.0, 1.0, 1.0, 1.0]
6362 // [ 0.0, 0.5, 0.0, 0.0]
6366 // [ 1.0, 1.0, 1.0, 1.0]
6369 "array_of_struct_of_array",
6371 "%c_v4f32_1_1_1_0 = OpConstantComposite %v4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_0\n"
6372 "%fp_a4f32 = OpTypePointer Function %a4f32\n"
6373 "%stype = OpTypeStruct %f32 %a4f32\n"
6374 "%a3stype = OpTypeArray %stype %c_u32_3\n"
6375 "%fp_a3stype = OpTypePointer Function %a3stype\n"
6376 "%ca4f32_0 = OpConstantComposite %a4f32 %c_f32_0 %c_f32_0_5 %c_f32_0 %c_f32_0\n"
6377 "%ca4f32_1 = OpConstantComposite %a4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_1\n"
6378 "%cstype1 = OpConstantComposite %stype %c_f32_0 %ca4f32_1\n"
6379 "%cstype2 = OpConstantComposite %stype %c_f32_1 %ca4f32_0\n"
6380 "%carr = OpConstantComposite %a3stype %cstype1 %cstype2 %cstype1",
6382 "%v = OpVariable %fp_a3stype Function %carr\n"
6383 "%f = OpAccessChain %fp_f32 %v %c_u32_1 %c_u32_1 %c_u32_1\n"
6384 "%f_l = OpLoad %f32 %f\n"
6385 "%add_vec = OpVectorTimesScalar %v4f32 %c_v4f32_1_1_1_0 %f_l\n"
6386 "%transformed_param = OpFAdd %v4f32 %param1 %add_vec\n"
6390 getHalfColorsFullAlpha(inputColors);
6391 outputColors[0] = RGBA(255, 255, 255, 255);
6392 outputColors[1] = RGBA(255, 127, 127, 255);
6393 outputColors[2] = RGBA(127, 255, 127, 255);
6394 outputColors[3] = RGBA(127, 127, 255, 255);
6396 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameConstantsCode); ++testNdx)
6398 map<string, string> fragments;
6399 fragments["pre_main"] = tests[testNdx].constants;
6400 fragments["testfun"] = string(functionStart) + tests[testNdx].code + functionEnd;
6401 createTestsForAllStages(tests[testNdx].name, inputColors, outputColors, fragments, opConstantCompositeTests.get());
6403 return opConstantCompositeTests.release();
6406 tcu::TestCaseGroup* createSelectionBlockOrderTests(tcu::TestContext& testCtx)
6408 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "selection_block_order", "Out-of-order blocks for selection"));
6409 RGBA inputColors[4];
6410 RGBA outputColors[4];
6411 map<string, string> fragments;
6413 // vec4 test_code(vec4 param) {
6414 // vec4 result = param;
6415 // for (int i = 0; i < 4; ++i) {
6416 // if (i == 0) result[i] = 0.;
6417 // else result[i] = 1. - result[i];
6421 const char function[] =
6422 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
6423 "%param1 = OpFunctionParameter %v4f32\n"
6425 "%iptr = OpVariable %fp_i32 Function\n"
6426 "%result = OpVariable %fp_v4f32 Function\n"
6427 " OpStore %iptr %c_i32_0\n"
6428 " OpStore %result %param1\n"
6431 // Loop entry block.
6433 "%ival = OpLoad %i32 %iptr\n"
6434 "%lt_4 = OpSLessThan %bool %ival %c_i32_4\n"
6435 " OpLoopMerge %exit %if_entry None\n"
6436 " OpBranchConditional %lt_4 %if_entry %exit\n"
6438 // Merge block for loop.
6440 "%ret = OpLoad %v4f32 %result\n"
6441 " OpReturnValue %ret\n"
6443 // If-statement entry block.
6444 "%if_entry = OpLabel\n"
6445 "%loc = OpAccessChain %fp_f32 %result %ival\n"
6446 "%eq_0 = OpIEqual %bool %ival %c_i32_0\n"
6447 " OpSelectionMerge %if_exit None\n"
6448 " OpBranchConditional %eq_0 %if_true %if_false\n"
6450 // False branch for if-statement.
6451 "%if_false = OpLabel\n"
6452 "%val = OpLoad %f32 %loc\n"
6453 "%sub = OpFSub %f32 %c_f32_1 %val\n"
6454 " OpStore %loc %sub\n"
6455 " OpBranch %if_exit\n"
6457 // Merge block for if-statement.
6458 "%if_exit = OpLabel\n"
6459 "%ival_next = OpIAdd %i32 %ival %c_i32_1\n"
6460 " OpStore %iptr %ival_next\n"
6463 // True branch for if-statement.
6464 "%if_true = OpLabel\n"
6465 " OpStore %loc %c_f32_0\n"
6466 " OpBranch %if_exit\n"
6470 fragments["testfun"] = function;
6472 inputColors[0] = RGBA(127, 127, 127, 0);
6473 inputColors[1] = RGBA(127, 0, 0, 0);
6474 inputColors[2] = RGBA(0, 127, 0, 0);
6475 inputColors[3] = RGBA(0, 0, 127, 0);
6477 outputColors[0] = RGBA(0, 128, 128, 255);
6478 outputColors[1] = RGBA(0, 255, 255, 255);
6479 outputColors[2] = RGBA(0, 128, 255, 255);
6480 outputColors[3] = RGBA(0, 255, 128, 255);
6482 createTestsForAllStages("out_of_order", inputColors, outputColors, fragments, group.get());
6484 return group.release();
6487 tcu::TestCaseGroup* createSwitchBlockOrderTests(tcu::TestContext& testCtx)
6489 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "switch_block_order", "Out-of-order blocks for switch"));
6490 RGBA inputColors[4];
6491 RGBA outputColors[4];
6492 map<string, string> fragments;
6494 const char typesAndConstants[] =
6495 "%c_f32_p2 = OpConstant %f32 0.2\n"
6496 "%c_f32_p4 = OpConstant %f32 0.4\n"
6497 "%c_f32_p6 = OpConstant %f32 0.6\n"
6498 "%c_f32_p8 = OpConstant %f32 0.8\n";
6500 // vec4 test_code(vec4 param) {
6501 // vec4 result = param;
6502 // for (int i = 0; i < 4; ++i) {
6504 // case 0: result[i] += .2; break;
6505 // case 1: result[i] += .6; break;
6506 // case 2: result[i] += .4; break;
6507 // case 3: result[i] += .8; break;
6508 // default: break; // unreachable
6513 const char function[] =
6514 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
6515 "%param1 = OpFunctionParameter %v4f32\n"
6517 "%iptr = OpVariable %fp_i32 Function\n"
6518 "%result = OpVariable %fp_v4f32 Function\n"
6519 " OpStore %iptr %c_i32_0\n"
6520 " OpStore %result %param1\n"
6523 // Loop entry block.
6525 "%ival = OpLoad %i32 %iptr\n"
6526 "%lt_4 = OpSLessThan %bool %ival %c_i32_4\n"
6527 " OpLoopMerge %exit %switch_exit None\n"
6528 " OpBranchConditional %lt_4 %switch_entry %exit\n"
6530 // Merge block for loop.
6532 "%ret = OpLoad %v4f32 %result\n"
6533 " OpReturnValue %ret\n"
6535 // Switch-statement entry block.
6536 "%switch_entry = OpLabel\n"
6537 "%loc = OpAccessChain %fp_f32 %result %ival\n"
6538 "%val = OpLoad %f32 %loc\n"
6539 " OpSelectionMerge %switch_exit None\n"
6540 " OpSwitch %ival %switch_default 0 %case0 1 %case1 2 %case2 3 %case3\n"
6542 "%case2 = OpLabel\n"
6543 "%addp4 = OpFAdd %f32 %val %c_f32_p4\n"
6544 " OpStore %loc %addp4\n"
6545 " OpBranch %switch_exit\n"
6547 "%switch_default = OpLabel\n"
6550 "%case3 = OpLabel\n"
6551 "%addp8 = OpFAdd %f32 %val %c_f32_p8\n"
6552 " OpStore %loc %addp8\n"
6553 " OpBranch %switch_exit\n"
6555 "%case0 = OpLabel\n"
6556 "%addp2 = OpFAdd %f32 %val %c_f32_p2\n"
6557 " OpStore %loc %addp2\n"
6558 " OpBranch %switch_exit\n"
6560 // Merge block for switch-statement.
6561 "%switch_exit = OpLabel\n"
6562 "%ival_next = OpIAdd %i32 %ival %c_i32_1\n"
6563 " OpStore %iptr %ival_next\n"
6566 "%case1 = OpLabel\n"
6567 "%addp6 = OpFAdd %f32 %val %c_f32_p6\n"
6568 " OpStore %loc %addp6\n"
6569 " OpBranch %switch_exit\n"
6573 fragments["pre_main"] = typesAndConstants;
6574 fragments["testfun"] = function;
6576 inputColors[0] = RGBA(127, 27, 127, 51);
6577 inputColors[1] = RGBA(127, 0, 0, 51);
6578 inputColors[2] = RGBA(0, 27, 0, 51);
6579 inputColors[3] = RGBA(0, 0, 127, 51);
6581 outputColors[0] = RGBA(178, 180, 229, 255);
6582 outputColors[1] = RGBA(178, 153, 102, 255);
6583 outputColors[2] = RGBA(51, 180, 102, 255);
6584 outputColors[3] = RGBA(51, 153, 229, 255);
6586 createTestsForAllStages("out_of_order", inputColors, outputColors, fragments, group.get());
6588 return group.release();
6591 tcu::TestCaseGroup* createDecorationGroupTests(tcu::TestContext& testCtx)
6593 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "decoration_group", "Decoration group tests"));
6594 RGBA inputColors[4];
6595 RGBA outputColors[4];
6596 map<string, string> fragments;
6598 const char decorations[] =
6599 "OpDecorate %array_group ArrayStride 4\n"
6600 "OpDecorate %struct_member_group Offset 0\n"
6601 "%array_group = OpDecorationGroup\n"
6602 "%struct_member_group = OpDecorationGroup\n"
6604 "OpDecorate %group1 RelaxedPrecision\n"
6605 "OpDecorate %group3 RelaxedPrecision\n"
6606 "OpDecorate %group3 Invariant\n"
6607 "OpDecorate %group3 Restrict\n"
6608 "%group0 = OpDecorationGroup\n"
6609 "%group1 = OpDecorationGroup\n"
6610 "%group3 = OpDecorationGroup\n";
6612 const char typesAndConstants[] =
6613 "%a3f32 = OpTypeArray %f32 %c_u32_3\n"
6614 "%struct1 = OpTypeStruct %a3f32\n"
6615 "%struct2 = OpTypeStruct %a3f32\n"
6616 "%fp_struct1 = OpTypePointer Function %struct1\n"
6617 "%fp_struct2 = OpTypePointer Function %struct2\n"
6618 "%c_f32_2 = OpConstant %f32 2.\n"
6619 "%c_f32_n2 = OpConstant %f32 -2.\n"
6621 "%c_a3f32_1 = OpConstantComposite %a3f32 %c_f32_1 %c_f32_2 %c_f32_1\n"
6622 "%c_a3f32_2 = OpConstantComposite %a3f32 %c_f32_n1 %c_f32_n2 %c_f32_n1\n"
6623 "%c_struct1 = OpConstantComposite %struct1 %c_a3f32_1\n"
6624 "%c_struct2 = OpConstantComposite %struct2 %c_a3f32_2\n";
6626 const char function[] =
6627 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
6628 "%param = OpFunctionParameter %v4f32\n"
6629 "%entry = OpLabel\n"
6630 "%result = OpVariable %fp_v4f32 Function\n"
6631 "%v_struct1 = OpVariable %fp_struct1 Function\n"
6632 "%v_struct2 = OpVariable %fp_struct2 Function\n"
6633 " OpStore %result %param\n"
6634 " OpStore %v_struct1 %c_struct1\n"
6635 " OpStore %v_struct2 %c_struct2\n"
6636 "%ptr1 = OpAccessChain %fp_f32 %v_struct1 %c_i32_0 %c_i32_2\n"
6637 "%val1 = OpLoad %f32 %ptr1\n"
6638 "%ptr2 = OpAccessChain %fp_f32 %v_struct2 %c_i32_0 %c_i32_2\n"
6639 "%val2 = OpLoad %f32 %ptr2\n"
6640 "%addvalues = OpFAdd %f32 %val1 %val2\n"
6641 "%ptr = OpAccessChain %fp_f32 %result %c_i32_1\n"
6642 "%val = OpLoad %f32 %ptr\n"
6643 "%addresult = OpFAdd %f32 %addvalues %val\n"
6644 " OpStore %ptr %addresult\n"
6645 "%ret = OpLoad %v4f32 %result\n"
6646 " OpReturnValue %ret\n"
6649 struct CaseNameDecoration
6655 CaseNameDecoration tests[] =
6658 "same_decoration_group_on_multiple_types",
6659 "OpGroupMemberDecorate %struct_member_group %struct1 0 %struct2 0\n"
6662 "empty_decoration_group",
6663 "OpGroupDecorate %group0 %a3f32\n"
6664 "OpGroupDecorate %group0 %result\n"
6667 "one_element_decoration_group",
6668 "OpGroupDecorate %array_group %a3f32\n"
6671 "multiple_elements_decoration_group",
6672 "OpGroupDecorate %group3 %v_struct1\n"
6675 "multiple_decoration_groups_on_same_variable",
6676 "OpGroupDecorate %group0 %v_struct2\n"
6677 "OpGroupDecorate %group1 %v_struct2\n"
6678 "OpGroupDecorate %group3 %v_struct2\n"
6681 "same_decoration_group_multiple_times",
6682 "OpGroupDecorate %group1 %addvalues\n"
6683 "OpGroupDecorate %group1 %addvalues\n"
6684 "OpGroupDecorate %group1 %addvalues\n"
6689 getHalfColorsFullAlpha(inputColors);
6690 getHalfColorsFullAlpha(outputColors);
6692 for (size_t idx = 0; idx < (sizeof(tests) / sizeof(tests[0])); ++idx)
6694 fragments["decoration"] = decorations + tests[idx].decoration;
6695 fragments["pre_main"] = typesAndConstants;
6696 fragments["testfun"] = function;
6698 createTestsForAllStages(tests[idx].name, inputColors, outputColors, fragments, group.get());
6701 return group.release();
6704 struct SpecConstantTwoIntGraphicsCase
6706 const char* caseName;
6707 const char* scDefinition0;
6708 const char* scDefinition1;
6709 const char* scResultType;
6710 const char* scOperation;
6711 deInt32 scActualValue0;
6712 deInt32 scActualValue1;
6713 const char* resultOperation;
6714 RGBA expectedColors[4];
6715 deInt32 scActualValueLength;
6717 SpecConstantTwoIntGraphicsCase (const char* name,
6718 const char* definition0,
6719 const char* definition1,
6720 const char* resultType,
6721 const char* operation,
6722 const deInt32 value0,
6723 const deInt32 value1,
6724 const char* resultOp,
6725 const RGBA (&output)[4],
6726 const deInt32 valueLength = sizeof(deInt32))
6728 , scDefinition0 (definition0)
6729 , scDefinition1 (definition1)
6730 , scResultType (resultType)
6731 , scOperation (operation)
6732 , scActualValue0 (value0)
6733 , scActualValue1 (value1)
6734 , resultOperation (resultOp)
6735 , scActualValueLength (valueLength)
6737 expectedColors[0] = output[0];
6738 expectedColors[1] = output[1];
6739 expectedColors[2] = output[2];
6740 expectedColors[3] = output[3];
6744 tcu::TestCaseGroup* createSpecConstantTests (tcu::TestContext& testCtx)
6746 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opspecconstantop", "Test the OpSpecConstantOp instruction"));
6747 vector<SpecConstantTwoIntGraphicsCase> cases;
6748 RGBA inputColors[4];
6749 RGBA outputColors0[4];
6750 RGBA outputColors1[4];
6751 RGBA outputColors2[4];
6753 const deInt32 m1AsFloat16 = 0xbc00; // -1(fp16) == 1 01111 0000000000 == 1011 1100 0000 0000
6755 const char decorations1[] =
6756 "OpDecorate %sc_0 SpecId 0\n"
6757 "OpDecorate %sc_1 SpecId 1\n";
6759 const char typesAndConstants1[] =
6760 "${OPTYPE_DEFINITIONS:opt}"
6761 "%sc_0 = OpSpecConstant${SC_DEF0}\n"
6762 "%sc_1 = OpSpecConstant${SC_DEF1}\n"
6763 "%sc_op = OpSpecConstantOp ${SC_RESULT_TYPE} ${SC_OP}\n";
6765 const char function1[] =
6766 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
6767 "%param = OpFunctionParameter %v4f32\n"
6768 "%label = OpLabel\n"
6769 "%result = OpVariable %fp_v4f32 Function\n"
6770 "${TYPE_CONVERT:opt}"
6771 " OpStore %result %param\n"
6772 "%gen = ${GEN_RESULT}\n"
6773 "%index = OpIAdd %i32 %gen %c_i32_1\n"
6774 "%loc = OpAccessChain %fp_f32 %result %index\n"
6775 "%val = OpLoad %f32 %loc\n"
6776 "%add = OpFAdd %f32 %val %c_f32_0_5\n"
6777 " OpStore %loc %add\n"
6778 "%ret = OpLoad %v4f32 %result\n"
6779 " OpReturnValue %ret\n"
6782 inputColors[0] = RGBA(127, 127, 127, 255);
6783 inputColors[1] = RGBA(127, 0, 0, 255);
6784 inputColors[2] = RGBA(0, 127, 0, 255);
6785 inputColors[3] = RGBA(0, 0, 127, 255);
6787 // Derived from inputColors[x] by adding 128 to inputColors[x][0].
6788 outputColors0[0] = RGBA(255, 127, 127, 255);
6789 outputColors0[1] = RGBA(255, 0, 0, 255);
6790 outputColors0[2] = RGBA(128, 127, 0, 255);
6791 outputColors0[3] = RGBA(128, 0, 127, 255);
6793 // Derived from inputColors[x] by adding 128 to inputColors[x][1].
6794 outputColors1[0] = RGBA(127, 255, 127, 255);
6795 outputColors1[1] = RGBA(127, 128, 0, 255);
6796 outputColors1[2] = RGBA(0, 255, 0, 255);
6797 outputColors1[3] = RGBA(0, 128, 127, 255);
6799 // Derived from inputColors[x] by adding 128 to inputColors[x][2].
6800 outputColors2[0] = RGBA(127, 127, 255, 255);
6801 outputColors2[1] = RGBA(127, 0, 128, 255);
6802 outputColors2[2] = RGBA(0, 127, 128, 255);
6803 outputColors2[3] = RGBA(0, 0, 255, 255);
6805 const char addZeroToSc[] = "OpIAdd %i32 %c_i32_0 %sc_op";
6806 const char addZeroToSc32[] = "OpIAdd %i32 %c_i32_0 %sc_op32";
6807 const char selectTrueUsingSc[] = "OpSelect %i32 %sc_op %c_i32_1 %c_i32_0";
6808 const char selectFalseUsingSc[] = "OpSelect %i32 %sc_op %c_i32_0 %c_i32_1";
6810 cases.push_back(SpecConstantTwoIntGraphicsCase("iadd", " %i32 0", " %i32 0", "%i32", "IAdd %sc_0 %sc_1", 19, -20, addZeroToSc, outputColors0));
6811 cases.push_back(SpecConstantTwoIntGraphicsCase("isub", " %i32 0", " %i32 0", "%i32", "ISub %sc_0 %sc_1", 19, 20, addZeroToSc, outputColors0));
6812 cases.push_back(SpecConstantTwoIntGraphicsCase("imul", " %i32 0", " %i32 0", "%i32", "IMul %sc_0 %sc_1", -1, -1, addZeroToSc, outputColors2));
6813 cases.push_back(SpecConstantTwoIntGraphicsCase("sdiv", " %i32 0", " %i32 0", "%i32", "SDiv %sc_0 %sc_1", -126, 126, addZeroToSc, outputColors0));
6814 cases.push_back(SpecConstantTwoIntGraphicsCase("udiv", " %i32 0", " %i32 0", "%i32", "UDiv %sc_0 %sc_1", 126, 126, addZeroToSc, outputColors2));
6815 cases.push_back(SpecConstantTwoIntGraphicsCase("srem", " %i32 0", " %i32 0", "%i32", "SRem %sc_0 %sc_1", 3, 2, addZeroToSc, outputColors2));
6816 cases.push_back(SpecConstantTwoIntGraphicsCase("smod", " %i32 0", " %i32 0", "%i32", "SMod %sc_0 %sc_1", 3, 2, addZeroToSc, outputColors2));
6817 cases.push_back(SpecConstantTwoIntGraphicsCase("umod", " %i32 0", " %i32 0", "%i32", "UMod %sc_0 %sc_1", 1001, 500, addZeroToSc, outputColors2));
6818 cases.push_back(SpecConstantTwoIntGraphicsCase("bitwiseand", " %i32 0", " %i32 0", "%i32", "BitwiseAnd %sc_0 %sc_1", 0x33, 0x0d, addZeroToSc, outputColors2));
6819 cases.push_back(SpecConstantTwoIntGraphicsCase("bitwiseor", " %i32 0", " %i32 0", "%i32", "BitwiseOr %sc_0 %sc_1", 0, 1, addZeroToSc, outputColors2));
6820 cases.push_back(SpecConstantTwoIntGraphicsCase("bitwisexor", " %i32 0", " %i32 0", "%i32", "BitwiseXor %sc_0 %sc_1", 0x2e, 0x2f, addZeroToSc, outputColors2));
6821 cases.push_back(SpecConstantTwoIntGraphicsCase("shiftrightlogical", " %i32 0", " %i32 0", "%i32", "ShiftRightLogical %sc_0 %sc_1", 2, 1, addZeroToSc, outputColors2));
6822 cases.push_back(SpecConstantTwoIntGraphicsCase("shiftrightarithmetic", " %i32 0", " %i32 0", "%i32", "ShiftRightArithmetic %sc_0 %sc_1", -4, 2, addZeroToSc, outputColors0));
6823 cases.push_back(SpecConstantTwoIntGraphicsCase("shiftleftlogical", " %i32 0", " %i32 0", "%i32", "ShiftLeftLogical %sc_0 %sc_1", 1, 0, addZeroToSc, outputColors2));
6824 cases.push_back(SpecConstantTwoIntGraphicsCase("slessthan", " %i32 0", " %i32 0", "%bool", "SLessThan %sc_0 %sc_1", -20, -10, selectTrueUsingSc, outputColors2));
6825 cases.push_back(SpecConstantTwoIntGraphicsCase("ulessthan", " %i32 0", " %i32 0", "%bool", "ULessThan %sc_0 %sc_1", 10, 20, selectTrueUsingSc, outputColors2));
6826 cases.push_back(SpecConstantTwoIntGraphicsCase("sgreaterthan", " %i32 0", " %i32 0", "%bool", "SGreaterThan %sc_0 %sc_1", -1000, 50, selectFalseUsingSc, outputColors2));
6827 cases.push_back(SpecConstantTwoIntGraphicsCase("ugreaterthan", " %i32 0", " %i32 0", "%bool", "UGreaterThan %sc_0 %sc_1", 10, 5, selectTrueUsingSc, outputColors2));
6828 cases.push_back(SpecConstantTwoIntGraphicsCase("slessthanequal", " %i32 0", " %i32 0", "%bool", "SLessThanEqual %sc_0 %sc_1", -10, -10, selectTrueUsingSc, outputColors2));
6829 cases.push_back(SpecConstantTwoIntGraphicsCase("ulessthanequal", " %i32 0", " %i32 0", "%bool", "ULessThanEqual %sc_0 %sc_1", 50, 100, selectTrueUsingSc, outputColors2));
6830 cases.push_back(SpecConstantTwoIntGraphicsCase("sgreaterthanequal", " %i32 0", " %i32 0", "%bool", "SGreaterThanEqual %sc_0 %sc_1", -1000, 50, selectFalseUsingSc, outputColors2));
6831 cases.push_back(SpecConstantTwoIntGraphicsCase("ugreaterthanequal", " %i32 0", " %i32 0", "%bool", "UGreaterThanEqual %sc_0 %sc_1", 10, 10, selectTrueUsingSc, outputColors2));
6832 cases.push_back(SpecConstantTwoIntGraphicsCase("iequal", " %i32 0", " %i32 0", "%bool", "IEqual %sc_0 %sc_1", 42, 24, selectFalseUsingSc, outputColors2));
6833 cases.push_back(SpecConstantTwoIntGraphicsCase("inotequal", " %i32 0", " %i32 0", "%bool", "INotEqual %sc_0 %sc_1", 42, 24, selectTrueUsingSc, outputColors2));
6834 cases.push_back(SpecConstantTwoIntGraphicsCase("logicaland", "True %bool", "True %bool", "%bool", "LogicalAnd %sc_0 %sc_1", 0, 1, selectFalseUsingSc, outputColors2));
6835 cases.push_back(SpecConstantTwoIntGraphicsCase("logicalor", "False %bool", "False %bool", "%bool", "LogicalOr %sc_0 %sc_1", 1, 0, selectTrueUsingSc, outputColors2));
6836 cases.push_back(SpecConstantTwoIntGraphicsCase("logicalequal", "True %bool", "True %bool", "%bool", "LogicalEqual %sc_0 %sc_1", 0, 1, selectFalseUsingSc, outputColors2));
6837 cases.push_back(SpecConstantTwoIntGraphicsCase("logicalnotequal", "False %bool", "False %bool", "%bool", "LogicalNotEqual %sc_0 %sc_1", 1, 0, selectTrueUsingSc, outputColors2));
6838 cases.push_back(SpecConstantTwoIntGraphicsCase("snegate", " %i32 0", " %i32 0", "%i32", "SNegate %sc_0", -1, 0, addZeroToSc, outputColors2));
6839 cases.push_back(SpecConstantTwoIntGraphicsCase("not", " %i32 0", " %i32 0", "%i32", "Not %sc_0", -2, 0, addZeroToSc, outputColors2));
6840 cases.push_back(SpecConstantTwoIntGraphicsCase("logicalnot", "False %bool", "False %bool", "%bool", "LogicalNot %sc_0", 1, 0, selectFalseUsingSc, outputColors2));
6841 cases.push_back(SpecConstantTwoIntGraphicsCase("select", "False %bool", " %i32 0", "%i32", "Select %sc_0 %sc_1 %c_i32_0", 1, 1, addZeroToSc, outputColors2));
6842 cases.push_back(SpecConstantTwoIntGraphicsCase("sconvert", " %i32 0", " %i32 0", "%i16", "SConvert %sc_0", -1, 0, addZeroToSc32, outputColors0));
6843 // -1082130432 stored as 32-bit two's complement is the binary representation of -1 as IEEE-754 Float
6844 cases.push_back(SpecConstantTwoIntGraphicsCase("fconvert", " %f32 0", " %f32 0", "%f64", "FConvert %sc_0", -1082130432, 0, addZeroToSc32, outputColors0));
6845 cases.push_back(SpecConstantTwoIntGraphicsCase("fconvert16", " %f16 0", " %f16 0", "%f32", "FConvert %sc_0", m1AsFloat16, 0, addZeroToSc32, outputColors0, sizeof(deFloat16)));
6846 // \todo[2015-12-1 antiagainst] OpQuantizeToF16
6848 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
6850 map<string, string> specializations;
6851 map<string, string> fragments;
6852 SpecConstants specConstants;
6853 vector<string> features;
6854 PushConstants noPushConstants;
6855 GraphicsResources noResources;
6856 GraphicsInterfaces noInterfaces;
6857 std::vector<std::string> noExtensions;
6859 // Special SPIR-V code for SConvert-case
6860 if (strcmp(cases[caseNdx].caseName, "sconvert") == 0)
6862 features.push_back("shaderInt16");
6863 fragments["capability"] = "OpCapability Int16\n"; // Adds 16-bit integer capability
6864 specializations["OPTYPE_DEFINITIONS"] = "%i16 = OpTypeInt 16 1\n"; // Adds 16-bit integer type
6865 specializations["TYPE_CONVERT"] = "%sc_op32 = OpSConvert %i32 %sc_op\n"; // Converts 16-bit integer to 32-bit integer
6868 // Special SPIR-V code for FConvert-case
6869 if (strcmp(cases[caseNdx].caseName, "fconvert") == 0)
6871 features.push_back("shaderFloat64");
6872 fragments["capability"] = "OpCapability Float64\n"; // Adds 64-bit float capability
6873 specializations["OPTYPE_DEFINITIONS"] = "%f64 = OpTypeFloat 64\n"; // Adds 64-bit float type
6874 specializations["TYPE_CONVERT"] = "%sc_op32 = OpConvertFToS %i32 %sc_op\n"; // Converts 64-bit float to 32-bit integer
6877 // Special SPIR-V code for FConvert-case for 16-bit floats
6878 if (strcmp(cases[caseNdx].caseName, "fconvert16") == 0)
6880 fragments["capability"] = "OpCapability Float16\n"; // Adds 16-bit float capability
6881 specializations["OPTYPE_DEFINITIONS"] = "%f16 = OpTypeFloat 16\n"; // Adds 16-bit float type
6882 specializations["TYPE_CONVERT"] = "%sc_op32 = OpConvertFToS %i32 %sc_op\n"; // Converts 16-bit float to 32-bit integer
6885 specializations["SC_DEF0"] = cases[caseNdx].scDefinition0;
6886 specializations["SC_DEF1"] = cases[caseNdx].scDefinition1;
6887 specializations["SC_RESULT_TYPE"] = cases[caseNdx].scResultType;
6888 specializations["SC_OP"] = cases[caseNdx].scOperation;
6889 specializations["GEN_RESULT"] = cases[caseNdx].resultOperation;
6891 fragments["decoration"] = tcu::StringTemplate(decorations1).specialize(specializations);
6892 fragments["pre_main"] = tcu::StringTemplate(typesAndConstants1).specialize(specializations);
6893 fragments["testfun"] = tcu::StringTemplate(function1).specialize(specializations);
6895 specConstants.append(&cases[caseNdx].scActualValue0, cases[caseNdx].scActualValueLength);
6896 specConstants.append(&cases[caseNdx].scActualValue1, cases[caseNdx].scActualValueLength);
6898 createTestsForAllStages(
6899 cases[caseNdx].caseName, inputColors, cases[caseNdx].expectedColors, fragments, specConstants,
6900 noPushConstants, noResources, noInterfaces, noExtensions, features, VulkanFeatures(), group.get());
6903 const char decorations2[] =
6904 "OpDecorate %sc_0 SpecId 0\n"
6905 "OpDecorate %sc_1 SpecId 1\n"
6906 "OpDecorate %sc_2 SpecId 2\n";
6908 const char typesAndConstants2[] =
6909 "%vec3_0 = OpConstantComposite %v3i32 %c_i32_0 %c_i32_0 %c_i32_0\n"
6910 "%vec3_undef = OpUndef %v3i32\n"
6912 "%sc_0 = OpSpecConstant %i32 0\n"
6913 "%sc_1 = OpSpecConstant %i32 0\n"
6914 "%sc_2 = OpSpecConstant %i32 0\n"
6915 "%sc_vec3_0 = OpSpecConstantOp %v3i32 CompositeInsert %sc_0 %vec3_0 0\n" // (sc_0, 0, 0)
6916 "%sc_vec3_1 = OpSpecConstantOp %v3i32 CompositeInsert %sc_1 %vec3_0 1\n" // (0, sc_1, 0)
6917 "%sc_vec3_2 = OpSpecConstantOp %v3i32 CompositeInsert %sc_2 %vec3_0 2\n" // (0, 0, sc_2)
6918 "%sc_vec3_0_s = OpSpecConstantOp %v3i32 VectorShuffle %sc_vec3_0 %vec3_undef 0 0xFFFFFFFF 2\n" // (sc_0, ???, 0)
6919 "%sc_vec3_1_s = OpSpecConstantOp %v3i32 VectorShuffle %sc_vec3_1 %vec3_undef 0xFFFFFFFF 1 0\n" // (???, sc_1, 0)
6920 "%sc_vec3_2_s = OpSpecConstantOp %v3i32 VectorShuffle %vec3_undef %sc_vec3_2 5 0xFFFFFFFF 5\n" // (sc_2, ???, sc_2)
6921 "%sc_vec3_01 = OpSpecConstantOp %v3i32 VectorShuffle %sc_vec3_0_s %sc_vec3_1_s 1 0 4\n" // (0, sc_0, sc_1)
6922 "%sc_vec3_012 = OpSpecConstantOp %v3i32 VectorShuffle %sc_vec3_01 %sc_vec3_2_s 5 1 2\n" // (sc_2, sc_0, sc_1)
6923 "%sc_ext_0 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 0\n" // sc_2
6924 "%sc_ext_1 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 1\n" // sc_0
6925 "%sc_ext_2 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 2\n" // sc_1
6926 "%sc_sub = OpSpecConstantOp %i32 ISub %sc_ext_0 %sc_ext_1\n" // (sc_2 - sc_0)
6927 "%sc_final = OpSpecConstantOp %i32 IMul %sc_sub %sc_ext_2\n"; // (sc_2 - sc_0) * sc_1
6929 const char function2[] =
6930 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
6931 "%param = OpFunctionParameter %v4f32\n"
6932 "%label = OpLabel\n"
6933 "%result = OpVariable %fp_v4f32 Function\n"
6934 " OpStore %result %param\n"
6935 "%loc = OpAccessChain %fp_f32 %result %sc_final\n"
6936 "%val = OpLoad %f32 %loc\n"
6937 "%add = OpFAdd %f32 %val %c_f32_0_5\n"
6938 " OpStore %loc %add\n"
6939 "%ret = OpLoad %v4f32 %result\n"
6940 " OpReturnValue %ret\n"
6943 map<string, string> fragments;
6944 SpecConstants specConstants;
6946 fragments["decoration"] = decorations2;
6947 fragments["pre_main"] = typesAndConstants2;
6948 fragments["testfun"] = function2;
6950 specConstants.append<deInt32>(56789);
6951 specConstants.append<deInt32>(-2);
6952 specConstants.append<deInt32>(56788);
6954 createTestsForAllStages("vector_related", inputColors, outputColors2, fragments, specConstants, group.get());
6956 return group.release();
6959 tcu::TestCaseGroup* createOpPhiTests(tcu::TestContext& testCtx)
6961 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opphi", "Test the OpPhi instruction"));
6962 RGBA inputColors[4];
6963 RGBA outputColors1[4];
6964 RGBA outputColors2[4];
6965 RGBA outputColors3[4];
6966 RGBA outputColors4[4];
6967 map<string, string> fragments1;
6968 map<string, string> fragments2;
6969 map<string, string> fragments3;
6970 map<string, string> fragments4;
6971 std::vector<std::string> extensions4;
6972 GraphicsResources resources4;
6973 VulkanFeatures vulkanFeatures4;
6975 const char typesAndConstants1[] =
6976 "%c_f32_p2 = OpConstant %f32 0.2\n"
6977 "%c_f32_p4 = OpConstant %f32 0.4\n"
6978 "%c_f32_p5 = OpConstant %f32 0.5\n"
6979 "%c_f32_p8 = OpConstant %f32 0.8\n";
6981 // vec4 test_code(vec4 param) {
6982 // vec4 result = param;
6983 // for (int i = 0; i < 4; ++i) {
6986 // case 0: operand = .2; break;
6987 // case 1: operand = .5; break;
6988 // case 2: operand = .4; break;
6989 // case 3: operand = .0; break;
6990 // default: break; // unreachable
6992 // result[i] += operand;
6996 const char function1[] =
6997 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
6998 "%param1 = OpFunctionParameter %v4f32\n"
7000 "%iptr = OpVariable %fp_i32 Function\n"
7001 "%result = OpVariable %fp_v4f32 Function\n"
7002 " OpStore %iptr %c_i32_0\n"
7003 " OpStore %result %param1\n"
7007 "%ival = OpLoad %i32 %iptr\n"
7008 "%lt_4 = OpSLessThan %bool %ival %c_i32_4\n"
7009 " OpLoopMerge %exit %phi None\n"
7010 " OpBranchConditional %lt_4 %entry %exit\n"
7012 "%entry = OpLabel\n"
7013 "%loc = OpAccessChain %fp_f32 %result %ival\n"
7014 "%val = OpLoad %f32 %loc\n"
7015 " OpSelectionMerge %phi None\n"
7016 " OpSwitch %ival %default 0 %case0 1 %case1 2 %case2 3 %case3\n"
7018 "%case0 = OpLabel\n"
7020 "%case1 = OpLabel\n"
7022 "%case2 = OpLabel\n"
7024 "%case3 = OpLabel\n"
7027 "%default = OpLabel\n"
7031 "%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
7032 "%add = OpFAdd %f32 %val %operand\n"
7033 " OpStore %loc %add\n"
7034 "%ival_next = OpIAdd %i32 %ival %c_i32_1\n"
7035 " OpStore %iptr %ival_next\n"
7039 "%ret = OpLoad %v4f32 %result\n"
7040 " OpReturnValue %ret\n"
7044 fragments1["pre_main"] = typesAndConstants1;
7045 fragments1["testfun"] = function1;
7047 getHalfColorsFullAlpha(inputColors);
7049 outputColors1[0] = RGBA(178, 255, 229, 255);
7050 outputColors1[1] = RGBA(178, 127, 102, 255);
7051 outputColors1[2] = RGBA(51, 255, 102, 255);
7052 outputColors1[3] = RGBA(51, 127, 229, 255);
7054 createTestsForAllStages("out_of_order", inputColors, outputColors1, fragments1, group.get());
7056 const char typesAndConstants2[] =
7057 "%c_f32_p2 = OpConstant %f32 0.2\n";
7059 // Add .4 to the second element of the given parameter.
7060 const char function2[] =
7061 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
7062 "%param = OpFunctionParameter %v4f32\n"
7063 "%entry = OpLabel\n"
7064 "%result = OpVariable %fp_v4f32 Function\n"
7065 " OpStore %result %param\n"
7066 "%loc = OpAccessChain %fp_f32 %result %c_i32_1\n"
7067 "%val = OpLoad %f32 %loc\n"
7071 "%step = OpPhi %i32 %c_i32_0 %entry %step_next %phi\n"
7072 "%accum = OpPhi %f32 %val %entry %accum_next %phi\n"
7073 "%step_next = OpIAdd %i32 %step %c_i32_1\n"
7074 "%accum_next = OpFAdd %f32 %accum %c_f32_p2\n"
7075 "%still_loop = OpSLessThan %bool %step %c_i32_2\n"
7076 " OpLoopMerge %exit %phi None\n"
7077 " OpBranchConditional %still_loop %phi %exit\n"
7080 " OpStore %loc %accum\n"
7081 "%ret = OpLoad %v4f32 %result\n"
7082 " OpReturnValue %ret\n"
7086 fragments2["pre_main"] = typesAndConstants2;
7087 fragments2["testfun"] = function2;
7089 outputColors2[0] = RGBA(127, 229, 127, 255);
7090 outputColors2[1] = RGBA(127, 102, 0, 255);
7091 outputColors2[2] = RGBA(0, 229, 0, 255);
7092 outputColors2[3] = RGBA(0, 102, 127, 255);
7094 createTestsForAllStages("induction", inputColors, outputColors2, fragments2, group.get());
7096 const char typesAndConstants3[] =
7097 "%true = OpConstantTrue %bool\n"
7098 "%false = OpConstantFalse %bool\n"
7099 "%c_f32_p2 = OpConstant %f32 0.2\n";
7101 // Swap the second and the third element of the given parameter.
7102 const char function3[] =
7103 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
7104 "%param = OpFunctionParameter %v4f32\n"
7105 "%entry = OpLabel\n"
7106 "%result = OpVariable %fp_v4f32 Function\n"
7107 " OpStore %result %param\n"
7108 "%a_loc = OpAccessChain %fp_f32 %result %c_i32_1\n"
7109 "%a_init = OpLoad %f32 %a_loc\n"
7110 "%b_loc = OpAccessChain %fp_f32 %result %c_i32_2\n"
7111 "%b_init = OpLoad %f32 %b_loc\n"
7115 "%still_loop = OpPhi %bool %true %entry %false %phi\n"
7116 "%a_next = OpPhi %f32 %a_init %entry %b_next %phi\n"
7117 "%b_next = OpPhi %f32 %b_init %entry %a_next %phi\n"
7118 " OpLoopMerge %exit %phi None\n"
7119 " OpBranchConditional %still_loop %phi %exit\n"
7122 " OpStore %a_loc %a_next\n"
7123 " OpStore %b_loc %b_next\n"
7124 "%ret = OpLoad %v4f32 %result\n"
7125 " OpReturnValue %ret\n"
7129 fragments3["pre_main"] = typesAndConstants3;
7130 fragments3["testfun"] = function3;
7132 outputColors3[0] = RGBA(127, 127, 127, 255);
7133 outputColors3[1] = RGBA(127, 0, 0, 255);
7134 outputColors3[2] = RGBA(0, 0, 127, 255);
7135 outputColors3[3] = RGBA(0, 127, 0, 255);
7137 createTestsForAllStages("swap", inputColors, outputColors3, fragments3, group.get());
7139 const char typesAndConstants4[] =
7140 "%f16 = OpTypeFloat 16\n"
7141 "%v4f16 = OpTypeVector %f16 4\n"
7142 "%fp_f16 = OpTypePointer Function %f16\n"
7143 "%fp_v4f16 = OpTypePointer Function %v4f16\n"
7144 "%true = OpConstantTrue %bool\n"
7145 "%false = OpConstantFalse %bool\n"
7146 "%c_f32_p2 = OpConstant %f32 0.2\n";
7148 // Swap the second and the third element of the given parameter.
7149 const char function4[] =
7150 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
7151 "%param = OpFunctionParameter %v4f32\n"
7152 "%entry = OpLabel\n"
7153 "%result = OpVariable %fp_v4f16 Function\n"
7154 "%param16 = OpFConvert %v4f16 %param\n"
7155 " OpStore %result %param16\n"
7156 "%a_loc = OpAccessChain %fp_f16 %result %c_i32_1\n"
7157 "%a_init = OpLoad %f16 %a_loc\n"
7158 "%b_loc = OpAccessChain %fp_f16 %result %c_i32_2\n"
7159 "%b_init = OpLoad %f16 %b_loc\n"
7163 "%still_loop = OpPhi %bool %true %entry %false %phi\n"
7164 "%a_next = OpPhi %f16 %a_init %entry %b_next %phi\n"
7165 "%b_next = OpPhi %f16 %b_init %entry %a_next %phi\n"
7166 " OpLoopMerge %exit %phi None\n"
7167 " OpBranchConditional %still_loop %phi %exit\n"
7170 " OpStore %a_loc %a_next\n"
7171 " OpStore %b_loc %b_next\n"
7172 "%ret16 = OpLoad %v4f16 %result\n"
7173 "%ret = OpFConvert %v4f32 %ret16\n"
7174 " OpReturnValue %ret\n"
7178 fragments4["pre_main"] = typesAndConstants4;
7179 fragments4["testfun"] = function4;
7180 fragments4["capability"] = "OpCapability StorageUniformBufferBlock16\n";
7181 fragments4["extension"] = "OpExtension \"SPV_KHR_16bit_storage\"";
7183 extensions4.push_back("VK_KHR_16bit_storage");
7184 extensions4.push_back("VK_KHR_shader_float16_int8");
7186 vulkanFeatures4.ext16BitStorage = EXT16BITSTORAGEFEATURES_UNIFORM_BUFFER_BLOCK;
7187 vulkanFeatures4.extFloat16Int8 = EXTFLOAT16INT8FEATURES_FLOAT16;
7189 outputColors4[0] = RGBA(127, 127, 127, 255);
7190 outputColors4[1] = RGBA(127, 0, 0, 255);
7191 outputColors4[2] = RGBA(0, 0, 127, 255);
7192 outputColors4[3] = RGBA(0, 127, 0, 255);
7194 createTestsForAllStages("swap16", inputColors, outputColors4, fragments4, resources4, extensions4, group.get(), vulkanFeatures4);
7196 return group.release();
7199 tcu::TestCaseGroup* createNoContractionTests(tcu::TestContext& testCtx)
7201 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "nocontraction", "Test the NoContraction decoration"));
7202 RGBA inputColors[4];
7203 RGBA outputColors[4];
7205 // With NoContraction, (1 + 2^-23) * (1 - 2^-23) - 1 should be conducted as a multiplication and an addition separately.
7206 // For the multiplication, the result is 1 - 2^-46, which is out of the precision range for 32-bit float. (32-bit float
7207 // only have 23-bit fraction.) So it will be rounded to 1. Or 0x1.fffffc. Then the final result is 0 or -0x1p-24.
7208 // On the contrary, the result will be 2^-46, which is a normalized number perfectly representable as 32-bit float.
7209 const char constantsAndTypes[] =
7210 "%c_vec4_0 = OpConstantComposite %v4f32 %c_f32_0 %c_f32_0 %c_f32_0 %c_f32_1\n"
7211 "%c_vec4_1 = OpConstantComposite %v4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_1\n"
7212 "%c_f32_1pl2_23 = OpConstant %f32 0x1.000002p+0\n" // 1 + 2^-23
7213 "%c_f32_1mi2_23 = OpConstant %f32 0x1.fffffcp-1\n" // 1 - 2^-23
7214 "%c_f32_n1pn24 = OpConstant %f32 -0x1p-24\n";
7216 const char function[] =
7217 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
7218 "%param = OpFunctionParameter %v4f32\n"
7219 "%label = OpLabel\n"
7220 "%var1 = OpVariable %fp_f32 Function %c_f32_1pl2_23\n"
7221 "%var2 = OpVariable %fp_f32 Function\n"
7222 "%red = OpCompositeExtract %f32 %param 0\n"
7223 "%plus_red = OpFAdd %f32 %c_f32_1mi2_23 %red\n"
7224 " OpStore %var2 %plus_red\n"
7225 "%val1 = OpLoad %f32 %var1\n"
7226 "%val2 = OpLoad %f32 %var2\n"
7227 "%mul = OpFMul %f32 %val1 %val2\n"
7228 "%add = OpFAdd %f32 %mul %c_f32_n1\n"
7229 "%is0 = OpFOrdEqual %bool %add %c_f32_0\n"
7230 "%isn1n24 = OpFOrdEqual %bool %add %c_f32_n1pn24\n"
7231 "%success = OpLogicalOr %bool %is0 %isn1n24\n"
7232 "%v4success = OpCompositeConstruct %v4bool %success %success %success %success\n"
7233 "%ret = OpSelect %v4f32 %v4success %c_vec4_0 %c_vec4_1\n"
7234 " OpReturnValue %ret\n"
7237 struct CaseNameDecoration
7244 CaseNameDecoration tests[] = {
7245 {"multiplication", "OpDecorate %mul NoContraction"},
7246 {"addition", "OpDecorate %add NoContraction"},
7247 {"both", "OpDecorate %mul NoContraction\nOpDecorate %add NoContraction"},
7250 getHalfColorsFullAlpha(inputColors);
7252 for (deUint8 idx = 0; idx < 4; ++idx)
7254 inputColors[idx].setRed(0);
7255 outputColors[idx] = RGBA(0, 0, 0, 255);
7258 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(CaseNameDecoration); ++testNdx)
7260 map<string, string> fragments;
7262 fragments["decoration"] = tests[testNdx].decoration;
7263 fragments["pre_main"] = constantsAndTypes;
7264 fragments["testfun"] = function;
7266 createTestsForAllStages(tests[testNdx].name, inputColors, outputColors, fragments, group.get());
7269 return group.release();
7272 tcu::TestCaseGroup* createMemoryAccessTests(tcu::TestContext& testCtx)
7274 de::MovePtr<tcu::TestCaseGroup> memoryAccessTests (new tcu::TestCaseGroup(testCtx, "opmemoryaccess", "Memory Semantics"));
7277 const char constantsAndTypes[] =
7278 "%c_a2f32_1 = OpConstantComposite %a2f32 %c_f32_1 %c_f32_1\n"
7279 "%fp_a2f32 = OpTypePointer Function %a2f32\n"
7280 "%stype = OpTypeStruct %v4f32 %a2f32 %f32\n"
7281 "%fp_stype = OpTypePointer Function %stype\n";
7283 const char function[] =
7284 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
7285 "%param1 = OpFunctionParameter %v4f32\n"
7287 "%v1 = OpVariable %fp_v4f32 Function\n"
7288 "%v2 = OpVariable %fp_a2f32 Function\n"
7289 "%v3 = OpVariable %fp_f32 Function\n"
7290 "%v = OpVariable %fp_stype Function\n"
7291 "%vv = OpVariable %fp_stype Function\n"
7292 "%vvv = OpVariable %fp_f32 Function\n"
7294 " OpStore %v1 %c_v4f32_1_1_1_1\n"
7295 " OpStore %v2 %c_a2f32_1\n"
7296 " OpStore %v3 %c_f32_1\n"
7298 "%p_v4f32 = OpAccessChain %fp_v4f32 %v %c_u32_0\n"
7299 "%p_a2f32 = OpAccessChain %fp_a2f32 %v %c_u32_1\n"
7300 "%p_f32 = OpAccessChain %fp_f32 %v %c_u32_2\n"
7301 "%v1_v = OpLoad %v4f32 %v1 ${access_type}\n"
7302 "%v2_v = OpLoad %a2f32 %v2 ${access_type}\n"
7303 "%v3_v = OpLoad %f32 %v3 ${access_type}\n"
7305 " OpStore %p_v4f32 %v1_v ${access_type}\n"
7306 " OpStore %p_a2f32 %v2_v ${access_type}\n"
7307 " OpStore %p_f32 %v3_v ${access_type}\n"
7309 " OpCopyMemory %vv %v ${access_type}\n"
7310 " OpCopyMemory %vvv %p_f32 ${access_type}\n"
7312 "%p_f32_2 = OpAccessChain %fp_f32 %vv %c_u32_2\n"
7313 "%v_f32_2 = OpLoad %f32 %p_f32_2\n"
7314 "%v_f32_3 = OpLoad %f32 %vvv\n"
7316 "%ret1 = OpVectorTimesScalar %v4f32 %param1 %v_f32_2\n"
7317 "%ret2 = OpVectorTimesScalar %v4f32 %ret1 %v_f32_3\n"
7318 " OpReturnValue %ret2\n"
7321 struct NameMemoryAccess
7328 NameMemoryAccess tests[] =
7331 { "volatile", "Volatile" },
7332 { "aligned", "Aligned 1" },
7333 { "volatile_aligned", "Volatile|Aligned 1" },
7334 { "nontemporal_aligned", "Nontemporal|Aligned 1" },
7335 { "volatile_nontemporal", "Volatile|Nontemporal" },
7336 { "volatile_nontermporal_aligned", "Volatile|Nontemporal|Aligned 1" },
7339 getHalfColorsFullAlpha(colors);
7341 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameMemoryAccess); ++testNdx)
7343 map<string, string> fragments;
7344 map<string, string> memoryAccess;
7345 memoryAccess["access_type"] = tests[testNdx].accessType;
7347 fragments["pre_main"] = constantsAndTypes;
7348 fragments["testfun"] = tcu::StringTemplate(function).specialize(memoryAccess);
7349 createTestsForAllStages(tests[testNdx].name, colors, colors, fragments, memoryAccessTests.get());
7351 return memoryAccessTests.release();
7353 tcu::TestCaseGroup* createOpUndefTests(tcu::TestContext& testCtx)
7355 de::MovePtr<tcu::TestCaseGroup> opUndefTests (new tcu::TestCaseGroup(testCtx, "opundef", "Test OpUndef"));
7356 RGBA defaultColors[4];
7357 map<string, string> fragments;
7358 getDefaultColors(defaultColors);
7360 // First, simple cases that don't do anything with the OpUndef result.
7361 struct NameCodePair { string name, decl, type; };
7362 const NameCodePair tests[] =
7364 {"bool", "", "%bool"},
7365 {"vec2uint32", "", "%v2u32"},
7366 {"image", "%type = OpTypeImage %f32 2D 0 0 0 1 Unknown", "%type"},
7367 {"sampler", "%type = OpTypeSampler", "%type"},
7368 {"sampledimage", "%img = OpTypeImage %f32 2D 0 0 0 1 Unknown\n" "%type = OpTypeSampledImage %img", "%type"},
7369 {"pointer", "", "%fp_i32"},
7370 {"runtimearray", "%type = OpTypeRuntimeArray %f32", "%type"},
7371 {"array", "%c_u32_100 = OpConstant %u32 100\n" "%type = OpTypeArray %i32 %c_u32_100", "%type"},
7372 {"struct", "%type = OpTypeStruct %f32 %i32 %u32", "%type"}};
7373 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameCodePair); ++testNdx)
7375 fragments["undef_type"] = tests[testNdx].type;
7376 fragments["testfun"] = StringTemplate(
7377 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
7378 "%param1 = OpFunctionParameter %v4f32\n"
7379 "%label_testfun = OpLabel\n"
7380 "%undef = OpUndef ${undef_type}\n"
7381 "OpReturnValue %param1\n"
7382 "OpFunctionEnd\n").specialize(fragments);
7383 fragments["pre_main"] = tests[testNdx].decl;
7384 createTestsForAllStages(tests[testNdx].name, defaultColors, defaultColors, fragments, opUndefTests.get());
7388 fragments["testfun"] =
7389 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
7390 "%param1 = OpFunctionParameter %v4f32\n"
7391 "%label_testfun = OpLabel\n"
7392 "%undef = OpUndef %f32\n"
7393 "%zero = OpFMul %f32 %undef %c_f32_0\n"
7394 "%is_nan = OpIsNan %bool %zero\n" //OpUndef may result in NaN which may turn %zero into Nan.
7395 "%actually_zero = OpSelect %f32 %is_nan %c_f32_0 %zero\n"
7396 "%a = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
7397 "%b = OpFAdd %f32 %a %actually_zero\n"
7398 "%ret = OpVectorInsertDynamic %v4f32 %param1 %b %c_i32_0\n"
7399 "OpReturnValue %ret\n"
7402 createTestsForAllStages("float32", defaultColors, defaultColors, fragments, opUndefTests.get());
7404 fragments["testfun"] =
7405 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
7406 "%param1 = OpFunctionParameter %v4f32\n"
7407 "%label_testfun = OpLabel\n"
7408 "%undef = OpUndef %i32\n"
7409 "%zero = OpIMul %i32 %undef %c_i32_0\n"
7410 "%a = OpVectorExtractDynamic %f32 %param1 %zero\n"
7411 "%ret = OpVectorInsertDynamic %v4f32 %param1 %a %c_i32_0\n"
7412 "OpReturnValue %ret\n"
7415 createTestsForAllStages("sint32", defaultColors, defaultColors, fragments, opUndefTests.get());
7417 fragments["testfun"] =
7418 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
7419 "%param1 = OpFunctionParameter %v4f32\n"
7420 "%label_testfun = OpLabel\n"
7421 "%undef = OpUndef %u32\n"
7422 "%zero = OpIMul %u32 %undef %c_i32_0\n"
7423 "%a = OpVectorExtractDynamic %f32 %param1 %zero\n"
7424 "%ret = OpVectorInsertDynamic %v4f32 %param1 %a %c_i32_0\n"
7425 "OpReturnValue %ret\n"
7428 createTestsForAllStages("uint32", defaultColors, defaultColors, fragments, opUndefTests.get());
7430 fragments["testfun"] =
7431 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
7432 "%param1 = OpFunctionParameter %v4f32\n"
7433 "%label_testfun = OpLabel\n"
7434 "%undef = OpUndef %v4f32\n"
7435 "%vzero = OpVectorTimesScalar %v4f32 %undef %c_f32_0\n"
7436 "%zero_0 = OpVectorExtractDynamic %f32 %vzero %c_i32_0\n"
7437 "%zero_1 = OpVectorExtractDynamic %f32 %vzero %c_i32_1\n"
7438 "%zero_2 = OpVectorExtractDynamic %f32 %vzero %c_i32_2\n"
7439 "%zero_3 = OpVectorExtractDynamic %f32 %vzero %c_i32_3\n"
7440 "%is_nan_0 = OpIsNan %bool %zero_0\n"
7441 "%is_nan_1 = OpIsNan %bool %zero_1\n"
7442 "%is_nan_2 = OpIsNan %bool %zero_2\n"
7443 "%is_nan_3 = OpIsNan %bool %zero_3\n"
7444 "%actually_zero_0 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_0\n"
7445 "%actually_zero_1 = OpSelect %f32 %is_nan_1 %c_f32_0 %zero_1\n"
7446 "%actually_zero_2 = OpSelect %f32 %is_nan_2 %c_f32_0 %zero_2\n"
7447 "%actually_zero_3 = OpSelect %f32 %is_nan_3 %c_f32_0 %zero_3\n"
7448 "%param1_0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
7449 "%param1_1 = OpVectorExtractDynamic %f32 %param1 %c_i32_1\n"
7450 "%param1_2 = OpVectorExtractDynamic %f32 %param1 %c_i32_2\n"
7451 "%param1_3 = OpVectorExtractDynamic %f32 %param1 %c_i32_3\n"
7452 "%sum_0 = OpFAdd %f32 %param1_0 %actually_zero_0\n"
7453 "%sum_1 = OpFAdd %f32 %param1_1 %actually_zero_1\n"
7454 "%sum_2 = OpFAdd %f32 %param1_2 %actually_zero_2\n"
7455 "%sum_3 = OpFAdd %f32 %param1_3 %actually_zero_3\n"
7456 "%ret3 = OpVectorInsertDynamic %v4f32 %param1 %sum_3 %c_i32_3\n"
7457 "%ret2 = OpVectorInsertDynamic %v4f32 %ret3 %sum_2 %c_i32_2\n"
7458 "%ret1 = OpVectorInsertDynamic %v4f32 %ret2 %sum_1 %c_i32_1\n"
7459 "%ret = OpVectorInsertDynamic %v4f32 %ret1 %sum_0 %c_i32_0\n"
7460 "OpReturnValue %ret\n"
7463 createTestsForAllStages("vec4float32", defaultColors, defaultColors, fragments, opUndefTests.get());
7465 fragments["pre_main"] =
7466 "%m2x2f32 = OpTypeMatrix %v2f32 2\n";
7467 fragments["testfun"] =
7468 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
7469 "%param1 = OpFunctionParameter %v4f32\n"
7470 "%label_testfun = OpLabel\n"
7471 "%undef = OpUndef %m2x2f32\n"
7472 "%mzero = OpMatrixTimesScalar %m2x2f32 %undef %c_f32_0\n"
7473 "%zero_0 = OpCompositeExtract %f32 %mzero 0 0\n"
7474 "%zero_1 = OpCompositeExtract %f32 %mzero 0 1\n"
7475 "%zero_2 = OpCompositeExtract %f32 %mzero 1 0\n"
7476 "%zero_3 = OpCompositeExtract %f32 %mzero 1 1\n"
7477 "%is_nan_0 = OpIsNan %bool %zero_0\n"
7478 "%is_nan_1 = OpIsNan %bool %zero_1\n"
7479 "%is_nan_2 = OpIsNan %bool %zero_2\n"
7480 "%is_nan_3 = OpIsNan %bool %zero_3\n"
7481 "%actually_zero_0 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_0\n"
7482 "%actually_zero_1 = OpSelect %f32 %is_nan_1 %c_f32_0 %zero_1\n"
7483 "%actually_zero_2 = OpSelect %f32 %is_nan_2 %c_f32_0 %zero_2\n"
7484 "%actually_zero_3 = OpSelect %f32 %is_nan_3 %c_f32_0 %zero_3\n"
7485 "%param1_0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
7486 "%param1_1 = OpVectorExtractDynamic %f32 %param1 %c_i32_1\n"
7487 "%param1_2 = OpVectorExtractDynamic %f32 %param1 %c_i32_2\n"
7488 "%param1_3 = OpVectorExtractDynamic %f32 %param1 %c_i32_3\n"
7489 "%sum_0 = OpFAdd %f32 %param1_0 %actually_zero_0\n"
7490 "%sum_1 = OpFAdd %f32 %param1_1 %actually_zero_1\n"
7491 "%sum_2 = OpFAdd %f32 %param1_2 %actually_zero_2\n"
7492 "%sum_3 = OpFAdd %f32 %param1_3 %actually_zero_3\n"
7493 "%ret3 = OpVectorInsertDynamic %v4f32 %param1 %sum_3 %c_i32_3\n"
7494 "%ret2 = OpVectorInsertDynamic %v4f32 %ret3 %sum_2 %c_i32_2\n"
7495 "%ret1 = OpVectorInsertDynamic %v4f32 %ret2 %sum_1 %c_i32_1\n"
7496 "%ret = OpVectorInsertDynamic %v4f32 %ret1 %sum_0 %c_i32_0\n"
7497 "OpReturnValue %ret\n"
7500 createTestsForAllStages("matrix", defaultColors, defaultColors, fragments, opUndefTests.get());
7502 return opUndefTests.release();
7505 void createOpQuantizeSingleOptionTests(tcu::TestCaseGroup* testCtx)
7507 const RGBA inputColors[4] =
7510 RGBA(0, 0, 255, 255),
7511 RGBA(0, 255, 0, 255),
7512 RGBA(0, 255, 255, 255)
7515 const RGBA expectedColors[4] =
7517 RGBA(255, 0, 0, 255),
7518 RGBA(255, 0, 0, 255),
7519 RGBA(255, 0, 0, 255),
7520 RGBA(255, 0, 0, 255)
7523 const struct SingleFP16Possibility
7526 const char* constant; // Value to assign to %test_constant.
7528 const char* condition; // Must assign to %cond an expression that evaluates to true after %c = OpQuantizeToF16(%test_constant + 0).
7534 -constructNormalizedFloat(1, 0x300000),
7535 "%cond = OpFOrdEqual %bool %c %test_constant\n"
7540 constructNormalizedFloat(7, 0x000000),
7541 "%cond = OpFOrdEqual %bool %c %test_constant\n"
7543 // SPIR-V requires that OpQuantizeToF16 flushes
7544 // any numbers that would end up denormalized in F16 to zero.
7548 std::ldexp(1.5f, -140),
7549 "%cond = OpFOrdEqual %bool %c %c_f32_0\n"
7554 -std::ldexp(1.5f, -140),
7555 "%cond = OpFOrdEqual %bool %c %c_f32_0\n"
7560 std::ldexp(1.0f, -16),
7561 "%cond = OpFOrdEqual %bool %c %c_f32_0\n"
7562 }, // too small positive
7564 "negative_too_small",
7566 -std::ldexp(1.0f, -32),
7567 "%cond = OpFOrdEqual %bool %c %c_f32_0\n"
7568 }, // too small negative
7572 -std::ldexp(1.0f, 128),
7574 "%gz = OpFOrdLessThan %bool %c %c_f32_0\n"
7575 "%inf = OpIsInf %bool %c\n"
7576 "%cond = OpLogicalAnd %bool %gz %inf\n"
7581 std::ldexp(1.0f, 128),
7583 "%gz = OpFOrdGreaterThan %bool %c %c_f32_0\n"
7584 "%inf = OpIsInf %bool %c\n"
7585 "%cond = OpLogicalAnd %bool %gz %inf\n"
7588 "round_to_negative_inf",
7590 -std::ldexp(1.0f, 32),
7592 "%gz = OpFOrdLessThan %bool %c %c_f32_0\n"
7593 "%inf = OpIsInf %bool %c\n"
7594 "%cond = OpLogicalAnd %bool %gz %inf\n"
7599 std::ldexp(1.0f, 16),
7601 "%gz = OpFOrdGreaterThan %bool %c %c_f32_0\n"
7602 "%inf = OpIsInf %bool %c\n"
7603 "%cond = OpLogicalAnd %bool %gz %inf\n"
7608 std::numeric_limits<float>::quiet_NaN(),
7610 // Test for any NaN value, as NaNs are not preserved
7611 "%direct_quant = OpQuantizeToF16 %f32 %test_constant\n"
7612 "%cond = OpIsNan %bool %direct_quant\n"
7617 std::numeric_limits<float>::quiet_NaN(),
7619 // Test for any NaN value, as NaNs are not preserved
7620 "%direct_quant = OpQuantizeToF16 %f32 %test_constant\n"
7621 "%cond = OpIsNan %bool %direct_quant\n"
7624 const char* constants =
7625 "%test_constant = OpConstant %f32 "; // The value will be test.constant.
7627 StringTemplate function (
7628 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
7629 "%param1 = OpFunctionParameter %v4f32\n"
7630 "%label_testfun = OpLabel\n"
7631 "%a = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
7632 "%b = OpFAdd %f32 %test_constant %a\n"
7633 "%c = OpQuantizeToF16 %f32 %b\n"
7635 "%v4cond = OpCompositeConstruct %v4bool %cond %cond %cond %cond\n"
7636 "%retval = OpSelect %v4f32 %v4cond %c_v4f32_1_0_0_1 %param1\n"
7637 " OpReturnValue %retval\n"
7641 const char* specDecorations = "OpDecorate %test_constant SpecId 0\n";
7642 const char* specConstants =
7643 "%test_constant = OpSpecConstant %f32 0.\n"
7644 "%c = OpSpecConstantOp %f32 QuantizeToF16 %test_constant\n";
7646 StringTemplate specConstantFunction(
7647 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
7648 "%param1 = OpFunctionParameter %v4f32\n"
7649 "%label_testfun = OpLabel\n"
7651 "%v4cond = OpCompositeConstruct %v4bool %cond %cond %cond %cond\n"
7652 "%retval = OpSelect %v4f32 %v4cond %c_v4f32_1_0_0_1 %param1\n"
7653 " OpReturnValue %retval\n"
7657 for (size_t idx = 0; idx < (sizeof(tests)/sizeof(tests[0])); ++idx)
7659 map<string, string> codeSpecialization;
7660 map<string, string> fragments;
7661 codeSpecialization["condition"] = tests[idx].condition;
7662 fragments["testfun"] = function.specialize(codeSpecialization);
7663 fragments["pre_main"] = string(constants) + tests[idx].constant + "\n";
7664 createTestsForAllStages(tests[idx].name, inputColors, expectedColors, fragments, testCtx);
7667 for (size_t idx = 0; idx < (sizeof(tests)/sizeof(tests[0])); ++idx)
7669 map<string, string> codeSpecialization;
7670 map<string, string> fragments;
7671 SpecConstants passConstants;
7673 codeSpecialization["condition"] = tests[idx].condition;
7674 fragments["testfun"] = specConstantFunction.specialize(codeSpecialization);
7675 fragments["decoration"] = specDecorations;
7676 fragments["pre_main"] = specConstants;
7678 passConstants.append<float>(tests[idx].valueAsFloat);
7680 createTestsForAllStages(string("spec_const_") + tests[idx].name, inputColors, expectedColors, fragments, passConstants, testCtx);
7684 void createOpQuantizeTwoPossibilityTests(tcu::TestCaseGroup* testCtx)
7686 RGBA inputColors[4] = {
7688 RGBA(0, 0, 255, 255),
7689 RGBA(0, 255, 0, 255),
7690 RGBA(0, 255, 255, 255)
7693 RGBA expectedColors[4] =
7695 RGBA(255, 0, 0, 255),
7696 RGBA(255, 0, 0, 255),
7697 RGBA(255, 0, 0, 255),
7698 RGBA(255, 0, 0, 255)
7701 struct DualFP16Possibility
7706 const char* possibleOutput1;
7707 const char* possibleOutput2;
7710 "positive_round_up_or_round_down",
7712 constructNormalizedFloat(8, 0x300300),
7717 "negative_round_up_or_round_down",
7719 -constructNormalizedFloat(-7, 0x600800),
7726 constructNormalizedFloat(2, 0x01e000),
7731 "carry_to_exponent",
7733 constructNormalizedFloat(1, 0xffe000),
7738 StringTemplate constants (
7739 "%input_const = OpConstant %f32 ${input}\n"
7740 "%possible_solution1 = OpConstant %f32 ${output1}\n"
7741 "%possible_solution2 = OpConstant %f32 ${output2}\n"
7744 StringTemplate specConstants (
7745 "%input_const = OpSpecConstant %f32 0.\n"
7746 "%possible_solution1 = OpConstant %f32 ${output1}\n"
7747 "%possible_solution2 = OpConstant %f32 ${output2}\n"
7750 const char* specDecorations = "OpDecorate %input_const SpecId 0\n";
7752 const char* function =
7753 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
7754 "%param1 = OpFunctionParameter %v4f32\n"
7755 "%label_testfun = OpLabel\n"
7756 "%a = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
7757 // For the purposes of this test we assume that 0.f will always get
7758 // faithfully passed through the pipeline stages.
7759 "%b = OpFAdd %f32 %input_const %a\n"
7760 "%c = OpQuantizeToF16 %f32 %b\n"
7761 "%eq_1 = OpFOrdEqual %bool %c %possible_solution1\n"
7762 "%eq_2 = OpFOrdEqual %bool %c %possible_solution2\n"
7763 "%cond = OpLogicalOr %bool %eq_1 %eq_2\n"
7764 "%v4cond = OpCompositeConstruct %v4bool %cond %cond %cond %cond\n"
7765 "%retval = OpSelect %v4f32 %v4cond %c_v4f32_1_0_0_1 %param1"
7766 " OpReturnValue %retval\n"
7769 for(size_t idx = 0; idx < (sizeof(tests)/sizeof(tests[0])); ++idx) {
7770 map<string, string> fragments;
7771 map<string, string> constantSpecialization;
7773 constantSpecialization["input"] = tests[idx].input;
7774 constantSpecialization["output1"] = tests[idx].possibleOutput1;
7775 constantSpecialization["output2"] = tests[idx].possibleOutput2;
7776 fragments["testfun"] = function;
7777 fragments["pre_main"] = constants.specialize(constantSpecialization);
7778 createTestsForAllStages(tests[idx].name, inputColors, expectedColors, fragments, testCtx);
7781 for(size_t idx = 0; idx < (sizeof(tests)/sizeof(tests[0])); ++idx) {
7782 map<string, string> fragments;
7783 map<string, string> constantSpecialization;
7784 SpecConstants passConstants;
7786 constantSpecialization["output1"] = tests[idx].possibleOutput1;
7787 constantSpecialization["output2"] = tests[idx].possibleOutput2;
7788 fragments["testfun"] = function;
7789 fragments["decoration"] = specDecorations;
7790 fragments["pre_main"] = specConstants.specialize(constantSpecialization);
7792 passConstants.append<float>(tests[idx].inputAsFloat);
7794 createTestsForAllStages(string("spec_const_") + tests[idx].name, inputColors, expectedColors, fragments, passConstants, testCtx);
7798 tcu::TestCaseGroup* createOpQuantizeTests(tcu::TestContext& testCtx)
7800 de::MovePtr<tcu::TestCaseGroup> opQuantizeTests (new tcu::TestCaseGroup(testCtx, "opquantize", "Test OpQuantizeToF16"));
7801 createOpQuantizeSingleOptionTests(opQuantizeTests.get());
7802 createOpQuantizeTwoPossibilityTests(opQuantizeTests.get());
7803 return opQuantizeTests.release();
7806 struct ShaderPermutation
7808 deUint8 vertexPermutation;
7809 deUint8 geometryPermutation;
7810 deUint8 tesscPermutation;
7811 deUint8 tessePermutation;
7812 deUint8 fragmentPermutation;
7815 ShaderPermutation getShaderPermutation(deUint8 inputValue)
7817 ShaderPermutation permutation =
7819 static_cast<deUint8>(inputValue & 0x10? 1u: 0u),
7820 static_cast<deUint8>(inputValue & 0x08? 1u: 0u),
7821 static_cast<deUint8>(inputValue & 0x04? 1u: 0u),
7822 static_cast<deUint8>(inputValue & 0x02? 1u: 0u),
7823 static_cast<deUint8>(inputValue & 0x01? 1u: 0u)
7828 tcu::TestCaseGroup* createModuleTests(tcu::TestContext& testCtx)
7830 RGBA defaultColors[4];
7831 RGBA invertedColors[4];
7832 de::MovePtr<tcu::TestCaseGroup> moduleTests (new tcu::TestCaseGroup(testCtx, "module", "Multiple entry points into shaders"));
7834 const ShaderElement combinedPipeline[] =
7836 ShaderElement("module", "main", VK_SHADER_STAGE_VERTEX_BIT),
7837 ShaderElement("module", "main", VK_SHADER_STAGE_GEOMETRY_BIT),
7838 ShaderElement("module", "main", VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT),
7839 ShaderElement("module", "main", VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT),
7840 ShaderElement("module", "main", VK_SHADER_STAGE_FRAGMENT_BIT)
7843 getDefaultColors(defaultColors);
7844 getInvertedDefaultColors(invertedColors);
7845 addFunctionCaseWithPrograms<InstanceContext>(
7846 moduleTests.get(), "same_module", "", createCombinedModule, runAndVerifyDefaultPipeline,
7847 createInstanceContext(combinedPipeline, map<string, string>()));
7849 const char* numbers[] =
7854 for (deInt8 idx = 0; idx < 32; ++idx)
7856 ShaderPermutation permutation = getShaderPermutation(idx);
7857 string name = string("vert") + numbers[permutation.vertexPermutation] + "_geom" + numbers[permutation.geometryPermutation] + "_tessc" + numbers[permutation.tesscPermutation] + "_tesse" + numbers[permutation.tessePermutation] + "_frag" + numbers[permutation.fragmentPermutation];
7858 const ShaderElement pipeline[] =
7860 ShaderElement("vert", string("vert") + numbers[permutation.vertexPermutation], VK_SHADER_STAGE_VERTEX_BIT),
7861 ShaderElement("geom", string("geom") + numbers[permutation.geometryPermutation], VK_SHADER_STAGE_GEOMETRY_BIT),
7862 ShaderElement("tessc", string("tessc") + numbers[permutation.tesscPermutation], VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT),
7863 ShaderElement("tesse", string("tesse") + numbers[permutation.tessePermutation], VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT),
7864 ShaderElement("frag", string("frag") + numbers[permutation.fragmentPermutation], VK_SHADER_STAGE_FRAGMENT_BIT)
7867 // If there are an even number of swaps, then it should be no-op.
7868 // If there are an odd number, the color should be flipped.
7869 if ((permutation.vertexPermutation + permutation.geometryPermutation + permutation.tesscPermutation + permutation.tessePermutation + permutation.fragmentPermutation) % 2 == 0)
7871 addFunctionCaseWithPrograms<InstanceContext>(
7872 moduleTests.get(), name, "", createMultipleEntries, runAndVerifyDefaultPipeline,
7873 createInstanceContext(pipeline, defaultColors, defaultColors, map<string, string>()));
7877 addFunctionCaseWithPrograms<InstanceContext>(
7878 moduleTests.get(), name, "", createMultipleEntries, runAndVerifyDefaultPipeline,
7879 createInstanceContext(pipeline, defaultColors, invertedColors, map<string, string>()));
7882 return moduleTests.release();
7885 tcu::TestCaseGroup* createLoopTests(tcu::TestContext& testCtx)
7887 de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, "loop", "Looping control flow"));
7888 RGBA defaultColors[4];
7889 getDefaultColors(defaultColors);
7890 map<string, string> fragments;
7891 fragments["pre_main"] =
7892 "%c_f32_5 = OpConstant %f32 5.\n";
7894 // A loop with a single block. The Continue Target is the loop block
7895 // itself. In SPIR-V terms, the "loop construct" contains no blocks at all
7896 // -- the "continue construct" forms the entire loop.
7897 fragments["testfun"] =
7898 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
7899 "%param1 = OpFunctionParameter %v4f32\n"
7901 "%entry = OpLabel\n"
7902 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
7905 ";adds and subtracts 1.0 to %val in alternate iterations\n"
7907 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %loop\n"
7908 "%delta = OpPhi %f32 %c_f32_1 %entry %minus_delta %loop\n"
7909 "%val1 = OpPhi %f32 %val0 %entry %val %loop\n"
7910 "%val = OpFAdd %f32 %val1 %delta\n"
7911 "%minus_delta = OpFSub %f32 %c_f32_0 %delta\n"
7912 "%count__ = OpISub %i32 %count %c_i32_1\n"
7913 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
7914 "OpLoopMerge %exit %loop None\n"
7915 "OpBranchConditional %again %loop %exit\n"
7918 "%result = OpVectorInsertDynamic %v4f32 %param1 %val %c_i32_0\n"
7919 "OpReturnValue %result\n"
7923 createTestsForAllStages("single_block", defaultColors, defaultColors, fragments, testGroup.get());
7925 // Body comprised of multiple basic blocks.
7926 const StringTemplate multiBlock(
7927 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
7928 "%param1 = OpFunctionParameter %v4f32\n"
7930 "%entry = OpLabel\n"
7931 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
7934 ";adds and subtracts 1.0 to %val in alternate iterations\n"
7936 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %gather\n"
7937 "%delta = OpPhi %f32 %c_f32_1 %entry %delta_next %gather\n"
7938 "%val1 = OpPhi %f32 %val0 %entry %val %gather\n"
7939 // There are several possibilities for the Continue Target below. Each
7940 // will be specialized into a separate test case.
7941 "OpLoopMerge %exit ${continue_target} None\n"
7945 ";delta_next = (delta > 0) ? -1 : 1;\n"
7946 "%gt0 = OpFOrdGreaterThan %bool %delta %c_f32_0\n"
7947 "OpSelectionMerge %gather DontFlatten\n"
7948 "OpBranchConditional %gt0 %even %odd ;tells us if %count is even or odd\n"
7951 "OpBranch %gather\n"
7954 "OpBranch %gather\n"
7956 "%gather = OpLabel\n"
7957 "%delta_next = OpPhi %f32 %c_f32_n1 %even %c_f32_1 %odd\n"
7958 "%val = OpFAdd %f32 %val1 %delta\n"
7959 "%count__ = OpISub %i32 %count %c_i32_1\n"
7960 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
7961 "OpBranchConditional %again %loop %exit\n"
7964 "%result = OpVectorInsertDynamic %v4f32 %param1 %val %c_i32_0\n"
7965 "OpReturnValue %result\n"
7969 map<string, string> continue_target;
7971 // The Continue Target is the loop block itself.
7972 continue_target["continue_target"] = "%loop";
7973 fragments["testfun"] = multiBlock.specialize(continue_target);
7974 createTestsForAllStages("multi_block_continue_construct", defaultColors, defaultColors, fragments, testGroup.get());
7976 // The Continue Target is at the end of the loop.
7977 continue_target["continue_target"] = "%gather";
7978 fragments["testfun"] = multiBlock.specialize(continue_target);
7979 createTestsForAllStages("multi_block_loop_construct", defaultColors, defaultColors, fragments, testGroup.get());
7981 // A loop with continue statement.
7982 fragments["testfun"] =
7983 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
7984 "%param1 = OpFunctionParameter %v4f32\n"
7986 "%entry = OpLabel\n"
7987 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
7990 ";adds 4, 3, and 1 to %val0 (skips 2)\n"
7992 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %continue\n"
7993 "%val1 = OpPhi %f32 %val0 %entry %val %continue\n"
7994 "OpLoopMerge %exit %continue None\n"
7998 ";skip if %count==2\n"
7999 "%eq2 = OpIEqual %bool %count %c_i32_2\n"
8000 "OpSelectionMerge %continue DontFlatten\n"
8001 "OpBranchConditional %eq2 %continue %body\n"
8004 "%fcount = OpConvertSToF %f32 %count\n"
8005 "%val2 = OpFAdd %f32 %val1 %fcount\n"
8006 "OpBranch %continue\n"
8008 "%continue = OpLabel\n"
8009 "%val = OpPhi %f32 %val2 %body %val1 %if\n"
8010 "%count__ = OpISub %i32 %count %c_i32_1\n"
8011 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
8012 "OpBranchConditional %again %loop %exit\n"
8015 "%same = OpFSub %f32 %val %c_f32_8\n"
8016 "%result = OpVectorInsertDynamic %v4f32 %param1 %same %c_i32_0\n"
8017 "OpReturnValue %result\n"
8019 createTestsForAllStages("continue", defaultColors, defaultColors, fragments, testGroup.get());
8021 // A loop with break.
8022 fragments["testfun"] =
8023 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
8024 "%param1 = OpFunctionParameter %v4f32\n"
8026 "%entry = OpLabel\n"
8027 ";param1 components are between 0 and 1, so dot product is 4 or less\n"
8028 "%dot = OpDot %f32 %param1 %param1\n"
8029 "%div = OpFDiv %f32 %dot %c_f32_5\n"
8030 "%zero = OpConvertFToU %u32 %div\n"
8031 "%two = OpIAdd %i32 %zero %c_i32_2\n"
8032 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
8035 ";adds 4 and 3 to %val0 (exits early)\n"
8037 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %continue\n"
8038 "%val1 = OpPhi %f32 %val0 %entry %val2 %continue\n"
8039 "OpLoopMerge %exit %continue None\n"
8043 ";end loop if %count==%two\n"
8044 "%above2 = OpSGreaterThan %bool %count %two\n"
8045 "OpSelectionMerge %continue DontFlatten\n"
8046 "OpBranchConditional %above2 %body %exit\n"
8049 "%fcount = OpConvertSToF %f32 %count\n"
8050 "%val2 = OpFAdd %f32 %val1 %fcount\n"
8051 "OpBranch %continue\n"
8053 "%continue = OpLabel\n"
8054 "%count__ = OpISub %i32 %count %c_i32_1\n"
8055 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
8056 "OpBranchConditional %again %loop %exit\n"
8059 "%val_post = OpPhi %f32 %val2 %continue %val1 %if\n"
8060 "%same = OpFSub %f32 %val_post %c_f32_7\n"
8061 "%result = OpVectorInsertDynamic %v4f32 %param1 %same %c_i32_0\n"
8062 "OpReturnValue %result\n"
8064 createTestsForAllStages("break", defaultColors, defaultColors, fragments, testGroup.get());
8066 // A loop with return.
8067 fragments["testfun"] =
8068 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
8069 "%param1 = OpFunctionParameter %v4f32\n"
8071 "%entry = OpLabel\n"
8072 ";param1 components are between 0 and 1, so dot product is 4 or less\n"
8073 "%dot = OpDot %f32 %param1 %param1\n"
8074 "%div = OpFDiv %f32 %dot %c_f32_5\n"
8075 "%zero = OpConvertFToU %u32 %div\n"
8076 "%two = OpIAdd %i32 %zero %c_i32_2\n"
8077 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
8080 ";returns early without modifying %param1\n"
8082 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %continue\n"
8083 "%val1 = OpPhi %f32 %val0 %entry %val2 %continue\n"
8084 "OpLoopMerge %exit %continue None\n"
8088 ";return if %count==%two\n"
8089 "%above2 = OpSGreaterThan %bool %count %two\n"
8090 "OpSelectionMerge %continue DontFlatten\n"
8091 "OpBranchConditional %above2 %body %early_exit\n"
8093 "%early_exit = OpLabel\n"
8094 "OpReturnValue %param1\n"
8097 "%fcount = OpConvertSToF %f32 %count\n"
8098 "%val2 = OpFAdd %f32 %val1 %fcount\n"
8099 "OpBranch %continue\n"
8101 "%continue = OpLabel\n"
8102 "%count__ = OpISub %i32 %count %c_i32_1\n"
8103 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
8104 "OpBranchConditional %again %loop %exit\n"
8107 ";should never get here, so return an incorrect result\n"
8108 "%result = OpVectorInsertDynamic %v4f32 %param1 %val2 %c_i32_0\n"
8109 "OpReturnValue %result\n"
8111 createTestsForAllStages("return", defaultColors, defaultColors, fragments, testGroup.get());
8113 // Continue inside a switch block to break to enclosing loop's merge block.
8114 // Matches roughly the following GLSL code:
8115 // for (; keep_going; keep_going = false)
8117 // switch (int(param1.x))
8119 // case 0: continue;
8120 // case 1: continue;
8121 // default: continue;
8123 // dead code: modify return value to invalid result.
8125 fragments["pre_main"] =
8126 "%fp_bool = OpTypePointer Function %bool\n"
8127 "%true = OpConstantTrue %bool\n"
8128 "%false = OpConstantFalse %bool\n";
8130 fragments["testfun"] =
8131 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
8132 "%param1 = OpFunctionParameter %v4f32\n"
8134 "%entry = OpLabel\n"
8135 "%keep_going = OpVariable %fp_bool Function\n"
8136 "%val_ptr = OpVariable %fp_f32 Function\n"
8137 "%param1_x = OpCompositeExtract %f32 %param1 0\n"
8138 "OpStore %keep_going %true\n"
8139 "OpBranch %forloop_begin\n"
8141 "%forloop_begin = OpLabel\n"
8142 "OpLoopMerge %forloop_merge %forloop_continue None\n"
8143 "OpBranch %forloop\n"
8145 "%forloop = OpLabel\n"
8146 "%for_condition = OpLoad %bool %keep_going\n"
8147 "OpBranchConditional %for_condition %forloop_body %forloop_merge\n"
8149 "%forloop_body = OpLabel\n"
8150 "OpStore %val_ptr %param1_x\n"
8151 "%param1_x_int = OpConvertFToS %i32 %param1_x\n"
8153 "OpSelectionMerge %switch_merge None\n"
8154 "OpSwitch %param1_x_int %default 0 %case_0 1 %case_1\n"
8155 "%case_0 = OpLabel\n"
8156 "OpBranch %forloop_continue\n"
8157 "%case_1 = OpLabel\n"
8158 "OpBranch %forloop_continue\n"
8159 "%default = OpLabel\n"
8160 "OpBranch %forloop_continue\n"
8161 "%switch_merge = OpLabel\n"
8162 ";should never get here, so change the return value to invalid result\n"
8163 "OpStore %val_ptr %c_f32_1\n"
8164 "OpBranch %forloop_continue\n"
8166 "%forloop_continue = OpLabel\n"
8167 "OpStore %keep_going %false\n"
8168 "OpBranch %forloop_begin\n"
8169 "%forloop_merge = OpLabel\n"
8171 "%val = OpLoad %f32 %val_ptr\n"
8172 "%result = OpVectorInsertDynamic %v4f32 %param1 %val %c_i32_0\n"
8173 "OpReturnValue %result\n"
8175 createTestsForAllStages("switch_continue", defaultColors, defaultColors, fragments, testGroup.get());
8177 return testGroup.release();
8180 // A collection of tests putting OpControlBarrier in places GLSL forbids but SPIR-V allows.
8181 tcu::TestCaseGroup* createBarrierTests(tcu::TestContext& testCtx)
8183 de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, "barrier", "OpControlBarrier"));
8184 map<string, string> fragments;
8186 // A barrier inside a function body.
8187 fragments["pre_main"] =
8188 "%Workgroup = OpConstant %i32 2\n"
8189 "%WorkgroupAcquireRelease = OpConstant %i32 0x108\n";
8190 fragments["testfun"] =
8191 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
8192 "%param1 = OpFunctionParameter %v4f32\n"
8193 "%label_testfun = OpLabel\n"
8194 "OpControlBarrier %Workgroup %Workgroup %WorkgroupAcquireRelease\n"
8195 "OpReturnValue %param1\n"
8197 addTessCtrlTest(testGroup.get(), "in_function", fragments);
8199 // Common setup code for the following tests.
8200 fragments["pre_main"] =
8201 "%Workgroup = OpConstant %i32 2\n"
8202 "%WorkgroupAcquireRelease = OpConstant %i32 0x108\n"
8203 "%c_f32_5 = OpConstant %f32 5.\n";
8204 const string setupPercentZero = // Begins %test_code function with code that sets %zero to 0u but cannot be optimized away.
8205 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
8206 "%param1 = OpFunctionParameter %v4f32\n"
8207 "%entry = OpLabel\n"
8208 ";param1 components are between 0 and 1, so dot product is 4 or less\n"
8209 "%dot = OpDot %f32 %param1 %param1\n"
8210 "%div = OpFDiv %f32 %dot %c_f32_5\n"
8211 "%zero = OpConvertFToU %u32 %div\n";
8213 // Barriers inside OpSwitch branches.
8214 fragments["testfun"] =
8216 "OpSelectionMerge %switch_exit None\n"
8217 "OpSwitch %zero %switch_default 0 %case0 1 %case1 ;should always go to %case0\n"
8219 "%case1 = OpLabel\n"
8220 ";This barrier should never be executed, but its presence makes test failure more likely when there's a bug.\n"
8221 "OpControlBarrier %Workgroup %Workgroup %WorkgroupAcquireRelease\n"
8222 "%wrong_branch_alert1 = OpVectorInsertDynamic %v4f32 %param1 %c_f32_0_5 %c_i32_0\n"
8223 "OpBranch %switch_exit\n"
8225 "%switch_default = OpLabel\n"
8226 "%wrong_branch_alert2 = OpVectorInsertDynamic %v4f32 %param1 %c_f32_0_5 %c_i32_0\n"
8227 ";This barrier should never be executed, but its presence makes test failure more likely when there's a bug.\n"
8228 "OpControlBarrier %Workgroup %Workgroup %WorkgroupAcquireRelease\n"
8229 "OpBranch %switch_exit\n"
8231 "%case0 = OpLabel\n"
8232 "OpControlBarrier %Workgroup %Workgroup %WorkgroupAcquireRelease\n"
8233 "OpBranch %switch_exit\n"
8235 "%switch_exit = OpLabel\n"
8236 "%ret = OpPhi %v4f32 %param1 %case0 %wrong_branch_alert1 %case1 %wrong_branch_alert2 %switch_default\n"
8237 "OpReturnValue %ret\n"
8239 addTessCtrlTest(testGroup.get(), "in_switch", fragments);
8241 // Barriers inside if-then-else.
8242 fragments["testfun"] =
8244 "%eq0 = OpIEqual %bool %zero %c_u32_0\n"
8245 "OpSelectionMerge %exit DontFlatten\n"
8246 "OpBranchConditional %eq0 %then %else\n"
8249 ";This barrier should never be executed, but its presence makes test failure more likely when there's a bug.\n"
8250 "OpControlBarrier %Workgroup %Workgroup %WorkgroupAcquireRelease\n"
8251 "%wrong_branch_alert = OpVectorInsertDynamic %v4f32 %param1 %c_f32_0_5 %c_i32_0\n"
8255 "OpControlBarrier %Workgroup %Workgroup %WorkgroupAcquireRelease\n"
8259 "%ret = OpPhi %v4f32 %param1 %then %wrong_branch_alert %else\n"
8260 "OpReturnValue %ret\n"
8262 addTessCtrlTest(testGroup.get(), "in_if", fragments);
8264 // A barrier after control-flow reconvergence, tempting the compiler to attempt something like this:
8265 // http://lists.llvm.org/pipermail/llvm-dev/2009-October/026317.html.
8266 fragments["testfun"] =
8268 "%thread_id = OpLoad %i32 %BP_gl_InvocationID\n"
8269 "%thread0 = OpIEqual %bool %thread_id %c_i32_0\n"
8270 "OpSelectionMerge %exit DontFlatten\n"
8271 "OpBranchConditional %thread0 %then %else\n"
8274 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
8278 "%val1 = OpVectorExtractDynamic %f32 %param1 %zero\n"
8282 "%val = OpPhi %f32 %val0 %else %val1 %then\n"
8283 "OpControlBarrier %Workgroup %Workgroup %WorkgroupAcquireRelease\n"
8284 "%ret = OpVectorInsertDynamic %v4f32 %param1 %val %zero\n"
8285 "OpReturnValue %ret\n"
8287 addTessCtrlTest(testGroup.get(), "after_divergent_if", fragments);
8289 // A barrier inside a loop.
8290 fragments["pre_main"] =
8291 "%Workgroup = OpConstant %i32 2\n"
8292 "%WorkgroupAcquireRelease = OpConstant %i32 0x108\n"
8293 "%c_f32_10 = OpConstant %f32 10.\n";
8294 fragments["testfun"] =
8295 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
8296 "%param1 = OpFunctionParameter %v4f32\n"
8297 "%entry = OpLabel\n"
8298 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
8301 ";adds 4, 3, 2, and 1 to %val0\n"
8303 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %loop\n"
8304 "%val1 = OpPhi %f32 %val0 %entry %val %loop\n"
8305 "OpControlBarrier %Workgroup %Workgroup %WorkgroupAcquireRelease\n"
8306 "%fcount = OpConvertSToF %f32 %count\n"
8307 "%val = OpFAdd %f32 %val1 %fcount\n"
8308 "%count__ = OpISub %i32 %count %c_i32_1\n"
8309 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
8310 "OpLoopMerge %exit %loop None\n"
8311 "OpBranchConditional %again %loop %exit\n"
8314 "%same = OpFSub %f32 %val %c_f32_10\n"
8315 "%ret = OpVectorInsertDynamic %v4f32 %param1 %same %c_i32_0\n"
8316 "OpReturnValue %ret\n"
8318 addTessCtrlTest(testGroup.get(), "in_loop", fragments);
8320 return testGroup.release();
8323 // Test for the OpFRem instruction.
8324 tcu::TestCaseGroup* createFRemTests(tcu::TestContext& testCtx)
8326 de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, "frem", "OpFRem"));
8327 map<string, string> fragments;
8328 RGBA inputColors[4];
8329 RGBA outputColors[4];
8331 fragments["pre_main"] =
8332 "%c_f32_3 = OpConstant %f32 3.0\n"
8333 "%c_f32_n3 = OpConstant %f32 -3.0\n"
8334 "%c_f32_4 = OpConstant %f32 4.0\n"
8335 "%c_f32_p75 = OpConstant %f32 0.75\n"
8336 "%c_v4f32_p75_p75_p75_p75 = OpConstantComposite %v4f32 %c_f32_p75 %c_f32_p75 %c_f32_p75 %c_f32_p75 \n"
8337 "%c_v4f32_4_4_4_4 = OpConstantComposite %v4f32 %c_f32_4 %c_f32_4 %c_f32_4 %c_f32_4\n"
8338 "%c_v4f32_3_n3_3_n3 = OpConstantComposite %v4f32 %c_f32_3 %c_f32_n3 %c_f32_3 %c_f32_n3\n";
8340 // The test does the following.
8341 // vec4 result = (param1 * 8.0) - 4.0;
8342 // return (frem(result.x,3) + 0.75, frem(result.y, -3) + 0.75, 0, 1)
8343 fragments["testfun"] =
8344 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
8345 "%param1 = OpFunctionParameter %v4f32\n"
8346 "%label_testfun = OpLabel\n"
8347 "%v_times_8 = OpVectorTimesScalar %v4f32 %param1 %c_f32_8\n"
8348 "%minus_4 = OpFSub %v4f32 %v_times_8 %c_v4f32_4_4_4_4\n"
8349 "%frem = OpFRem %v4f32 %minus_4 %c_v4f32_3_n3_3_n3\n"
8350 "%added = OpFAdd %v4f32 %frem %c_v4f32_p75_p75_p75_p75\n"
8351 "%xyz_1 = OpVectorInsertDynamic %v4f32 %added %c_f32_1 %c_i32_3\n"
8352 "%xy_0_1 = OpVectorInsertDynamic %v4f32 %xyz_1 %c_f32_0 %c_i32_2\n"
8353 "OpReturnValue %xy_0_1\n"
8357 inputColors[0] = RGBA(16, 16, 0, 255);
8358 inputColors[1] = RGBA(232, 232, 0, 255);
8359 inputColors[2] = RGBA(232, 16, 0, 255);
8360 inputColors[3] = RGBA(16, 232, 0, 255);
8362 outputColors[0] = RGBA(64, 64, 0, 255);
8363 outputColors[1] = RGBA(255, 255, 0, 255);
8364 outputColors[2] = RGBA(255, 64, 0, 255);
8365 outputColors[3] = RGBA(64, 255, 0, 255);
8367 createTestsForAllStages("frem", inputColors, outputColors, fragments, testGroup.get());
8368 return testGroup.release();
8371 // Test for the OpSRem instruction.
8372 tcu::TestCaseGroup* createOpSRemGraphicsTests(tcu::TestContext& testCtx, qpTestResult negFailResult)
8374 de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, "srem", "OpSRem"));
8375 map<string, string> fragments;
8377 fragments["pre_main"] =
8378 "%c_f32_255 = OpConstant %f32 255.0\n"
8379 "%c_i32_128 = OpConstant %i32 128\n"
8380 "%c_i32_255 = OpConstant %i32 255\n"
8381 "%c_v4f32_255 = OpConstantComposite %v4f32 %c_f32_255 %c_f32_255 %c_f32_255 %c_f32_255 \n"
8382 "%c_v4f32_0_5 = OpConstantComposite %v4f32 %c_f32_0_5 %c_f32_0_5 %c_f32_0_5 %c_f32_0_5 \n"
8383 "%c_v4i32_128 = OpConstantComposite %v4i32 %c_i32_128 %c_i32_128 %c_i32_128 %c_i32_128 \n";
8385 // The test does the following.
8386 // ivec4 ints = int(param1 * 255.0 + 0.5) - 128;
8387 // ivec4 result = ivec4(srem(ints.x, ints.y), srem(ints.y, ints.z), srem(ints.z, ints.x), 255);
8388 // return float(result + 128) / 255.0;
8389 fragments["testfun"] =
8390 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
8391 "%param1 = OpFunctionParameter %v4f32\n"
8392 "%label_testfun = OpLabel\n"
8393 "%div255 = OpFMul %v4f32 %param1 %c_v4f32_255\n"
8394 "%add0_5 = OpFAdd %v4f32 %div255 %c_v4f32_0_5\n"
8395 "%uints_in = OpConvertFToS %v4i32 %add0_5\n"
8396 "%ints_in = OpISub %v4i32 %uints_in %c_v4i32_128\n"
8397 "%x_in = OpCompositeExtract %i32 %ints_in 0\n"
8398 "%y_in = OpCompositeExtract %i32 %ints_in 1\n"
8399 "%z_in = OpCompositeExtract %i32 %ints_in 2\n"
8400 "%x_out = OpSRem %i32 %x_in %y_in\n"
8401 "%y_out = OpSRem %i32 %y_in %z_in\n"
8402 "%z_out = OpSRem %i32 %z_in %x_in\n"
8403 "%ints_out = OpCompositeConstruct %v4i32 %x_out %y_out %z_out %c_i32_255\n"
8404 "%ints_offset = OpIAdd %v4i32 %ints_out %c_v4i32_128\n"
8405 "%f_ints_offset = OpConvertSToF %v4f32 %ints_offset\n"
8406 "%float_out = OpFDiv %v4f32 %f_ints_offset %c_v4f32_255\n"
8407 "OpReturnValue %float_out\n"
8410 const struct CaseParams
8413 const char* failMessageTemplate; // customized status message
8414 qpTestResult failResult; // override status on failure
8415 int operands[4][3]; // four (x, y, z) vectors of operands
8416 int results[4][3]; // four (x, y, z) vectors of results
8422 QP_TEST_RESULT_FAIL,
8423 { { 5, 12, 17 }, { 5, 5, 7 }, { 75, 8, 81 }, { 25, 60, 100 } }, // operands
8424 { { 5, 12, 2 }, { 0, 5, 2 }, { 3, 8, 6 }, { 25, 60, 0 } }, // results
8428 "Inconsistent results, but within specification: ${reason}",
8429 negFailResult, // negative operands, not required by the spec
8430 { { 5, 12, -17 }, { -5, -5, 7 }, { 75, 8, -81 }, { 25, -60, 100 } }, // operands
8431 { { 5, 12, -2 }, { 0, -5, 2 }, { 3, 8, -6 }, { 25, -60, 0 } }, // results
8434 // If either operand is negative the result is undefined. Some implementations may still return correct values.
8436 for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(cases); ++caseNdx)
8438 const CaseParams& params = cases[caseNdx];
8439 RGBA inputColors[4];
8440 RGBA outputColors[4];
8442 for (int i = 0; i < 4; ++i)
8444 inputColors [i] = RGBA(params.operands[i][0] + 128, params.operands[i][1] + 128, params.operands[i][2] + 128, 255);
8445 outputColors[i] = RGBA(params.results [i][0] + 128, params.results [i][1] + 128, params.results [i][2] + 128, 255);
8448 createTestsForAllStages(params.name, inputColors, outputColors, fragments, testGroup.get(), params.failResult, params.failMessageTemplate);
8451 return testGroup.release();
8454 // Test for the OpSMod instruction.
8455 tcu::TestCaseGroup* createOpSModGraphicsTests(tcu::TestContext& testCtx, qpTestResult negFailResult)
8457 de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, "smod", "OpSMod"));
8458 map<string, string> fragments;
8460 fragments["pre_main"] =
8461 "%c_f32_255 = OpConstant %f32 255.0\n"
8462 "%c_i32_128 = OpConstant %i32 128\n"
8463 "%c_i32_255 = OpConstant %i32 255\n"
8464 "%c_v4f32_255 = OpConstantComposite %v4f32 %c_f32_255 %c_f32_255 %c_f32_255 %c_f32_255 \n"
8465 "%c_v4f32_0_5 = OpConstantComposite %v4f32 %c_f32_0_5 %c_f32_0_5 %c_f32_0_5 %c_f32_0_5 \n"
8466 "%c_v4i32_128 = OpConstantComposite %v4i32 %c_i32_128 %c_i32_128 %c_i32_128 %c_i32_128 \n";
8468 // The test does the following.
8469 // ivec4 ints = int(param1 * 255.0 + 0.5) - 128;
8470 // ivec4 result = ivec4(smod(ints.x, ints.y), smod(ints.y, ints.z), smod(ints.z, ints.x), 255);
8471 // return float(result + 128) / 255.0;
8472 fragments["testfun"] =
8473 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
8474 "%param1 = OpFunctionParameter %v4f32\n"
8475 "%label_testfun = OpLabel\n"
8476 "%div255 = OpFMul %v4f32 %param1 %c_v4f32_255\n"
8477 "%add0_5 = OpFAdd %v4f32 %div255 %c_v4f32_0_5\n"
8478 "%uints_in = OpConvertFToS %v4i32 %add0_5\n"
8479 "%ints_in = OpISub %v4i32 %uints_in %c_v4i32_128\n"
8480 "%x_in = OpCompositeExtract %i32 %ints_in 0\n"
8481 "%y_in = OpCompositeExtract %i32 %ints_in 1\n"
8482 "%z_in = OpCompositeExtract %i32 %ints_in 2\n"
8483 "%x_out = OpSMod %i32 %x_in %y_in\n"
8484 "%y_out = OpSMod %i32 %y_in %z_in\n"
8485 "%z_out = OpSMod %i32 %z_in %x_in\n"
8486 "%ints_out = OpCompositeConstruct %v4i32 %x_out %y_out %z_out %c_i32_255\n"
8487 "%ints_offset = OpIAdd %v4i32 %ints_out %c_v4i32_128\n"
8488 "%f_ints_offset = OpConvertSToF %v4f32 %ints_offset\n"
8489 "%float_out = OpFDiv %v4f32 %f_ints_offset %c_v4f32_255\n"
8490 "OpReturnValue %float_out\n"
8493 const struct CaseParams
8496 const char* failMessageTemplate; // customized status message
8497 qpTestResult failResult; // override status on failure
8498 int operands[4][3]; // four (x, y, z) vectors of operands
8499 int results[4][3]; // four (x, y, z) vectors of results
8505 QP_TEST_RESULT_FAIL,
8506 { { 5, 12, 17 }, { 5, 5, 7 }, { 75, 8, 81 }, { 25, 60, 100 } }, // operands
8507 { { 5, 12, 2 }, { 0, 5, 2 }, { 3, 8, 6 }, { 25, 60, 0 } }, // results
8511 "Inconsistent results, but within specification: ${reason}",
8512 negFailResult, // negative operands, not required by the spec
8513 { { 5, 12, -17 }, { -5, -5, 7 }, { 75, 8, -81 }, { 25, -60, 100 } }, // operands
8514 { { 5, -5, 3 }, { 0, 2, -3 }, { 3, -73, 69 }, { -35, 40, 0 } }, // results
8517 // If either operand is negative the result is undefined. Some implementations may still return correct values.
8519 for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(cases); ++caseNdx)
8521 const CaseParams& params = cases[caseNdx];
8522 RGBA inputColors[4];
8523 RGBA outputColors[4];
8525 for (int i = 0; i < 4; ++i)
8527 inputColors [i] = RGBA(params.operands[i][0] + 128, params.operands[i][1] + 128, params.operands[i][2] + 128, 255);
8528 outputColors[i] = RGBA(params.results [i][0] + 128, params.results [i][1] + 128, params.results [i][2] + 128, 255);
8531 createTestsForAllStages(params.name, inputColors, outputColors, fragments, testGroup.get(), params.failResult, params.failMessageTemplate);
8533 return testGroup.release();
8536 enum ConversionDataType
8539 DATA_TYPE_SIGNED_16,
8540 DATA_TYPE_SIGNED_32,
8541 DATA_TYPE_SIGNED_64,
8542 DATA_TYPE_UNSIGNED_8,
8543 DATA_TYPE_UNSIGNED_16,
8544 DATA_TYPE_UNSIGNED_32,
8545 DATA_TYPE_UNSIGNED_64,
8549 DATA_TYPE_VEC2_SIGNED_16,
8550 DATA_TYPE_VEC2_SIGNED_32
8553 const string getBitWidthStr (ConversionDataType type)
8557 case DATA_TYPE_SIGNED_8:
8558 case DATA_TYPE_UNSIGNED_8:
8561 case DATA_TYPE_SIGNED_16:
8562 case DATA_TYPE_UNSIGNED_16:
8563 case DATA_TYPE_FLOAT_16:
8566 case DATA_TYPE_SIGNED_32:
8567 case DATA_TYPE_UNSIGNED_32:
8568 case DATA_TYPE_FLOAT_32:
8569 case DATA_TYPE_VEC2_SIGNED_16:
8572 case DATA_TYPE_SIGNED_64:
8573 case DATA_TYPE_UNSIGNED_64:
8574 case DATA_TYPE_FLOAT_64:
8575 case DATA_TYPE_VEC2_SIGNED_32:
8584 const string getByteWidthStr (ConversionDataType type)
8588 case DATA_TYPE_SIGNED_8:
8589 case DATA_TYPE_UNSIGNED_8:
8592 case DATA_TYPE_SIGNED_16:
8593 case DATA_TYPE_UNSIGNED_16:
8594 case DATA_TYPE_FLOAT_16:
8597 case DATA_TYPE_SIGNED_32:
8598 case DATA_TYPE_UNSIGNED_32:
8599 case DATA_TYPE_FLOAT_32:
8600 case DATA_TYPE_VEC2_SIGNED_16:
8603 case DATA_TYPE_SIGNED_64:
8604 case DATA_TYPE_UNSIGNED_64:
8605 case DATA_TYPE_FLOAT_64:
8606 case DATA_TYPE_VEC2_SIGNED_32:
8615 bool isSigned (ConversionDataType type)
8619 case DATA_TYPE_SIGNED_8:
8620 case DATA_TYPE_SIGNED_16:
8621 case DATA_TYPE_SIGNED_32:
8622 case DATA_TYPE_SIGNED_64:
8623 case DATA_TYPE_FLOAT_16:
8624 case DATA_TYPE_FLOAT_32:
8625 case DATA_TYPE_FLOAT_64:
8626 case DATA_TYPE_VEC2_SIGNED_16:
8627 case DATA_TYPE_VEC2_SIGNED_32:
8630 case DATA_TYPE_UNSIGNED_8:
8631 case DATA_TYPE_UNSIGNED_16:
8632 case DATA_TYPE_UNSIGNED_32:
8633 case DATA_TYPE_UNSIGNED_64:
8642 bool isInt (ConversionDataType type)
8646 case DATA_TYPE_SIGNED_8:
8647 case DATA_TYPE_SIGNED_16:
8648 case DATA_TYPE_SIGNED_32:
8649 case DATA_TYPE_SIGNED_64:
8650 case DATA_TYPE_UNSIGNED_8:
8651 case DATA_TYPE_UNSIGNED_16:
8652 case DATA_TYPE_UNSIGNED_32:
8653 case DATA_TYPE_UNSIGNED_64:
8656 case DATA_TYPE_FLOAT_16:
8657 case DATA_TYPE_FLOAT_32:
8658 case DATA_TYPE_FLOAT_64:
8659 case DATA_TYPE_VEC2_SIGNED_16:
8660 case DATA_TYPE_VEC2_SIGNED_32:
8669 bool isFloat (ConversionDataType type)
8673 case DATA_TYPE_SIGNED_8:
8674 case DATA_TYPE_SIGNED_16:
8675 case DATA_TYPE_SIGNED_32:
8676 case DATA_TYPE_SIGNED_64:
8677 case DATA_TYPE_UNSIGNED_8:
8678 case DATA_TYPE_UNSIGNED_16:
8679 case DATA_TYPE_UNSIGNED_32:
8680 case DATA_TYPE_UNSIGNED_64:
8681 case DATA_TYPE_VEC2_SIGNED_16:
8682 case DATA_TYPE_VEC2_SIGNED_32:
8685 case DATA_TYPE_FLOAT_16:
8686 case DATA_TYPE_FLOAT_32:
8687 case DATA_TYPE_FLOAT_64:
8696 const string getTypeName (ConversionDataType type)
8698 string prefix = isSigned(type) ? "" : "u";
8700 if (isInt(type)) return prefix + "int" + getBitWidthStr(type);
8701 else if (isFloat(type)) return prefix + "float" + getBitWidthStr(type);
8702 else if (type == DATA_TYPE_VEC2_SIGNED_16) return "i16vec2";
8703 else if (type == DATA_TYPE_VEC2_SIGNED_32) return "i32vec2";
8704 else DE_ASSERT(false);
8709 const string getTestName (ConversionDataType from, ConversionDataType to, const char* suffix)
8711 const string fullSuffix(suffix == DE_NULL ? "" : string("_") + string(suffix));
8713 return getTypeName(from) + "_to_" + getTypeName(to) + fullSuffix;
8716 const string getAsmTypeName (ConversionDataType type)
8720 if (isInt(type)) prefix = isSigned(type) ? "i" : "u";
8721 else if (isFloat(type)) prefix = "f";
8722 else if (type == DATA_TYPE_VEC2_SIGNED_16) return "i16vec2";
8723 else if (type == DATA_TYPE_VEC2_SIGNED_32) return "v2i32";
8724 else DE_ASSERT(false);
8726 return prefix + getBitWidthStr(type);
8729 template<typename T>
8730 BufferSp getSpecializedBuffer (deInt64 number)
8732 return BufferSp(new Buffer<T>(vector<T>(1, (T)number)));
8735 BufferSp getBuffer (ConversionDataType type, deInt64 number)
8739 case DATA_TYPE_SIGNED_8: return getSpecializedBuffer<deInt8>(number);
8740 case DATA_TYPE_SIGNED_16: return getSpecializedBuffer<deInt16>(number);
8741 case DATA_TYPE_SIGNED_32: return getSpecializedBuffer<deInt32>(number);
8742 case DATA_TYPE_SIGNED_64: return getSpecializedBuffer<deInt64>(number);
8743 case DATA_TYPE_UNSIGNED_8: return getSpecializedBuffer<deUint8>(number);
8744 case DATA_TYPE_UNSIGNED_16: return getSpecializedBuffer<deUint16>(number);
8745 case DATA_TYPE_UNSIGNED_32: return getSpecializedBuffer<deUint32>(number);
8746 case DATA_TYPE_UNSIGNED_64: return getSpecializedBuffer<deUint64>(number);
8747 case DATA_TYPE_FLOAT_16: return getSpecializedBuffer<deUint16>(number);
8748 case DATA_TYPE_FLOAT_32: return getSpecializedBuffer<deUint32>(number);
8749 case DATA_TYPE_FLOAT_64: return getSpecializedBuffer<deUint64>(number);
8750 case DATA_TYPE_VEC2_SIGNED_16: return getSpecializedBuffer<deUint32>(number);
8751 case DATA_TYPE_VEC2_SIGNED_32: return getSpecializedBuffer<deUint64>(number);
8753 default: TCU_THROW(InternalError, "Unimplemented type passed");
8757 bool usesInt8 (ConversionDataType from, ConversionDataType to)
8759 return (from == DATA_TYPE_SIGNED_8 || to == DATA_TYPE_SIGNED_8 ||
8760 from == DATA_TYPE_UNSIGNED_8 || to == DATA_TYPE_UNSIGNED_8);
8763 bool usesInt16 (ConversionDataType from, ConversionDataType to)
8765 return (from == DATA_TYPE_SIGNED_16 || to == DATA_TYPE_SIGNED_16 ||
8766 from == DATA_TYPE_UNSIGNED_16 || to == DATA_TYPE_UNSIGNED_16 ||
8767 from == DATA_TYPE_VEC2_SIGNED_16 || to == DATA_TYPE_VEC2_SIGNED_16);
8770 bool usesInt32 (ConversionDataType from, ConversionDataType to)
8772 return (from == DATA_TYPE_SIGNED_32 || to == DATA_TYPE_SIGNED_32 ||
8773 from == DATA_TYPE_UNSIGNED_32 || to == DATA_TYPE_UNSIGNED_32 ||
8774 from == DATA_TYPE_VEC2_SIGNED_32|| to == DATA_TYPE_VEC2_SIGNED_32);
8777 bool usesInt64 (ConversionDataType from, ConversionDataType to)
8779 return (from == DATA_TYPE_SIGNED_64 || to == DATA_TYPE_SIGNED_64 ||
8780 from == DATA_TYPE_UNSIGNED_64 || to == DATA_TYPE_UNSIGNED_64);
8783 bool usesFloat16 (ConversionDataType from, ConversionDataType to)
8785 return (from == DATA_TYPE_FLOAT_16 || to == DATA_TYPE_FLOAT_16);
8788 bool usesFloat32 (ConversionDataType from, ConversionDataType to)
8790 return (from == DATA_TYPE_FLOAT_32 || to == DATA_TYPE_FLOAT_32);
8793 bool usesFloat64 (ConversionDataType from, ConversionDataType to)
8795 return (from == DATA_TYPE_FLOAT_64 || to == DATA_TYPE_FLOAT_64);
8798 void getVulkanFeaturesAndExtensions (ConversionDataType from, ConversionDataType to, VulkanFeatures& vulkanFeatures, vector<string>& extensions)
8800 if (usesInt16(from, to) && !usesInt32(from, to))
8801 vulkanFeatures.coreFeatures.shaderInt16 = DE_TRUE;
8803 if (usesInt64(from, to))
8804 vulkanFeatures.coreFeatures.shaderInt64 = DE_TRUE;
8806 if (usesFloat64(from, to))
8807 vulkanFeatures.coreFeatures.shaderFloat64 = DE_TRUE;
8809 if (usesInt16(from, to) || usesFloat16(from, to))
8811 extensions.push_back("VK_KHR_16bit_storage");
8812 vulkanFeatures.ext16BitStorage |= EXT16BITSTORAGEFEATURES_UNIFORM_BUFFER_BLOCK;
8815 if (usesFloat16(from, to) || usesInt8(from, to))
8817 extensions.push_back("VK_KHR_shader_float16_int8");
8819 if (usesFloat16(from, to))
8821 vulkanFeatures.extFloat16Int8 |= EXTFLOAT16INT8FEATURES_FLOAT16;
8824 if (usesInt8(from, to))
8826 vulkanFeatures.extFloat16Int8 |= EXTFLOAT16INT8FEATURES_INT8;
8828 extensions.push_back("VK_KHR_8bit_storage");
8829 vulkanFeatures.ext8BitStorage |= EXT8BITSTORAGEFEATURES_STORAGE_BUFFER;
8836 ConvertCase (const string& instruction, ConversionDataType from, ConversionDataType to, deInt64 number, bool separateOutput = false, deInt64 outputNumber = 0, const char* suffix = DE_NULL)
8839 , m_name (getTestName(from, to, suffix))
8840 , m_inputBuffer (getBuffer(from, number))
8846 m_asmTypes["inputType"] = getAsmTypeName(from);
8847 m_asmTypes["outputType"] = getAsmTypeName(to);
8850 m_outputBuffer = getBuffer(to, outputNumber);
8852 m_outputBuffer = getBuffer(to, number);
8854 if (usesInt8(from, to))
8856 bool requiresInt8Capability = true;
8857 if (instruction == "OpUConvert" || instruction == "OpSConvert")
8859 // Conversions between 8 and 32 bit are provided by SPV_KHR_8bit_storage. The rest requires explicit Int8
8860 if (usesInt32(from, to))
8861 requiresInt8Capability = false;
8864 caps += "OpCapability StorageBuffer8BitAccess\n";
8865 if (requiresInt8Capability)
8866 caps += "OpCapability Int8\n";
8868 decl += "%i8 = OpTypeInt 8 1\n"
8869 "%u8 = OpTypeInt 8 0\n";
8870 exts += "OpExtension \"SPV_KHR_8bit_storage\"\n";
8873 if (usesInt16(from, to))
8875 bool requiresInt16Capability = true;
8877 if (instruction == "OpUConvert" || instruction == "OpSConvert" || instruction == "OpFConvert")
8879 // Conversions between 16 and 32 bit are provided by SPV_KHR_16bit_storage. The rest requires explicit Int16
8880 if (usesInt32(from, to) || usesFloat32(from, to))
8881 requiresInt16Capability = false;
8884 decl += "%i16 = OpTypeInt 16 1\n"
8885 "%u16 = OpTypeInt 16 0\n"
8886 "%i16vec2 = OpTypeVector %i16 2\n";
8888 // Conversions between 16 and 32 bit are provided by SPV_KHR_16bit_storage. The rest requires explicit Int16
8889 if (requiresInt16Capability)
8890 caps += "OpCapability Int16\n";
8893 if (usesFloat16(from, to))
8895 decl += "%f16 = OpTypeFloat 16\n";
8897 // Conversions between 16 and 32 bit are provided by SPV_KHR_16bit_storage. The rest requires explicit Float16
8898 if (!(usesInt32(from, to) || usesFloat32(from, to)))
8899 caps += "OpCapability Float16\n";
8902 if (usesInt16(from, to) || usesFloat16(from, to))
8904 caps += "OpCapability StorageUniformBufferBlock16\n"
8905 "OpCapability StorageUniform16\n";
8906 exts += "OpExtension \"SPV_KHR_16bit_storage\"\n";
8909 if (usesInt64(from, to))
8911 caps += "OpCapability Int64\n";
8912 decl += "%i64 = OpTypeInt 64 1\n"
8913 "%u64 = OpTypeInt 64 0\n";
8916 if (usesFloat64(from, to))
8918 caps += "OpCapability Float64\n";
8919 decl += "%f64 = OpTypeFloat 64\n";
8922 m_asmTypes["datatype_capabilities"] = caps;
8923 m_asmTypes["datatype_additional_decl"] = decl;
8924 m_asmTypes["datatype_extensions"] = exts;
8927 ConversionDataType m_fromType;
8928 ConversionDataType m_toType;
8930 map<string, string> m_asmTypes;
8931 BufferSp m_inputBuffer;
8932 BufferSp m_outputBuffer;
8935 const string getConvertCaseShaderStr (const string& instruction, const ConvertCase& convertCase)
8937 map<string, string> params = convertCase.m_asmTypes;
8939 params["instruction"] = instruction;
8940 params["inDecorator"] = getByteWidthStr(convertCase.m_fromType);
8941 params["outDecorator"] = getByteWidthStr(convertCase.m_toType);
8943 const StringTemplate shader (
8944 "OpCapability Shader\n"
8945 "${datatype_capabilities}"
8946 "${datatype_extensions:opt}"
8947 "OpMemoryModel Logical GLSL450\n"
8948 "OpEntryPoint GLCompute %main \"main\"\n"
8949 "OpExecutionMode %main LocalSize 1 1 1\n"
8950 "OpSource GLSL 430\n"
8951 "OpName %main \"main\"\n"
8953 "OpDecorate %indata DescriptorSet 0\n"
8954 "OpDecorate %indata Binding 0\n"
8955 "OpDecorate %outdata DescriptorSet 0\n"
8956 "OpDecorate %outdata Binding 1\n"
8957 "OpDecorate %in_buf BufferBlock\n"
8958 "OpDecorate %out_buf BufferBlock\n"
8959 "OpMemberDecorate %in_buf 0 Offset 0\n"
8960 "OpMemberDecorate %out_buf 0 Offset 0\n"
8962 "%void = OpTypeVoid\n"
8963 "%voidf = OpTypeFunction %void\n"
8964 "%u32 = OpTypeInt 32 0\n"
8965 "%i32 = OpTypeInt 32 1\n"
8966 "%f32 = OpTypeFloat 32\n"
8967 "%v2i32 = OpTypeVector %i32 2\n"
8968 "${datatype_additional_decl}"
8969 "%uvec3 = OpTypeVector %u32 3\n"
8971 "%in_ptr = OpTypePointer Uniform %${inputType}\n"
8972 "%out_ptr = OpTypePointer Uniform %${outputType}\n"
8973 "%in_buf = OpTypeStruct %${inputType}\n"
8974 "%out_buf = OpTypeStruct %${outputType}\n"
8975 "%in_bufptr = OpTypePointer Uniform %in_buf\n"
8976 "%out_bufptr = OpTypePointer Uniform %out_buf\n"
8977 "%indata = OpVariable %in_bufptr Uniform\n"
8978 "%outdata = OpVariable %out_bufptr Uniform\n"
8980 "%zero = OpConstant %i32 0\n"
8982 "%main = OpFunction %void None %voidf\n"
8983 "%label = OpLabel\n"
8984 "%inloc = OpAccessChain %in_ptr %indata %zero\n"
8985 "%outloc = OpAccessChain %out_ptr %outdata %zero\n"
8986 "%inval = OpLoad %${inputType} %inloc\n"
8987 "%conv = ${instruction} %${outputType} %inval\n"
8988 " OpStore %outloc %conv\n"
8993 return shader.specialize(params);
8996 void createConvertCases (vector<ConvertCase>& testCases, const string& instruction)
8998 if (instruction == "OpUConvert")
9000 // Convert unsigned int to unsigned int
9001 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_8, DATA_TYPE_UNSIGNED_16, 42));
9002 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_8, DATA_TYPE_UNSIGNED_32, 73));
9003 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_8, DATA_TYPE_UNSIGNED_64, 121));
9005 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_16, DATA_TYPE_UNSIGNED_8, 33));
9006 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_16, DATA_TYPE_UNSIGNED_32, 60653));
9007 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_16, DATA_TYPE_UNSIGNED_64, 17991));
9009 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_32, DATA_TYPE_UNSIGNED_64, 904256275));
9010 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_32, DATA_TYPE_UNSIGNED_16, 6275));
9011 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_32, DATA_TYPE_UNSIGNED_8, 17));
9013 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_64, DATA_TYPE_UNSIGNED_32, 701256243));
9014 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_64, DATA_TYPE_UNSIGNED_16, 4741));
9015 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_64, DATA_TYPE_UNSIGNED_8, 65));
9017 else if (instruction == "OpSConvert")
9019 // Sign extension int->int
9020 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_8, DATA_TYPE_SIGNED_16, -30));
9021 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_8, DATA_TYPE_SIGNED_32, 55));
9022 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_8, DATA_TYPE_SIGNED_64, -3));
9023 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_16, DATA_TYPE_SIGNED_32, 14669));
9024 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_16, DATA_TYPE_SIGNED_64, -3341));
9025 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_32, DATA_TYPE_SIGNED_64, 973610259));
9027 // Truncate for int->int
9028 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_16, DATA_TYPE_SIGNED_8, 81));
9029 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_32, DATA_TYPE_SIGNED_8, -93));
9030 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_64, DATA_TYPE_SIGNED_8, 3182748172687672ll, true, 56));
9031 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_32, DATA_TYPE_SIGNED_16, 12382));
9032 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_64, DATA_TYPE_SIGNED_32, -972812359));
9033 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_64, DATA_TYPE_SIGNED_16, -1067742499291926803ll, true, -4371));
9035 // Sign extension for int->uint
9036 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_8, DATA_TYPE_UNSIGNED_16, 56));
9037 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_8, DATA_TYPE_UNSIGNED_32, -47, true, 4294967249u));
9038 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_8, DATA_TYPE_UNSIGNED_64, -5, true, 18446744073709551611ull));
9039 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_16, DATA_TYPE_UNSIGNED_32, 14669));
9040 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_16, DATA_TYPE_UNSIGNED_64, -3341, true, 18446744073709548275ull));
9041 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_32, DATA_TYPE_UNSIGNED_64, 973610259));
9043 // Truncate for int->uint
9044 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_16, DATA_TYPE_UNSIGNED_8, -25711, true, 145));
9045 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_32, DATA_TYPE_UNSIGNED_8, 103));
9046 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_64, DATA_TYPE_UNSIGNED_8, -1067742499291926803ll, true, 61165));
9047 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_32, DATA_TYPE_UNSIGNED_16, 12382));
9048 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_64, DATA_TYPE_UNSIGNED_32, -972812359, true, 3322154937u));
9049 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_64, DATA_TYPE_UNSIGNED_16, -1067742499291926803ll, true, 61165));
9051 // Sign extension for uint->int
9052 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_8, DATA_TYPE_SIGNED_16, 71));
9053 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_8, DATA_TYPE_SIGNED_32, 201, true, -55));
9054 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_8, DATA_TYPE_SIGNED_64, 188, true, -68));
9055 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_16, DATA_TYPE_SIGNED_32, 14669));
9056 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_16, DATA_TYPE_SIGNED_64, 62195, true, -3341));
9057 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_32, DATA_TYPE_SIGNED_64, 973610259));
9059 // Truncate for uint->int
9060 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_16, DATA_TYPE_SIGNED_8, 67));
9061 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_32, DATA_TYPE_SIGNED_8, 133, true, -123));
9062 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_64, DATA_TYPE_SIGNED_8, 836927654193256494ull, true, 46));
9063 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_32, DATA_TYPE_SIGNED_16, 12382));
9064 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_64, DATA_TYPE_SIGNED_32, 18446744072736739257ull, true, -972812359));
9065 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_64, DATA_TYPE_SIGNED_16, 17379001574417624813ull, true, -4371));
9067 // Convert i16vec2 to i32vec2 and vice versa
9068 // Unsigned values are used here to represent negative signed values and to allow defined shifting behaviour.
9069 // The actual signed value -32123 is used here as uint16 value 33413 and uint32 value 4294935173
9070 testCases.push_back(ConvertCase(instruction, DATA_TYPE_VEC2_SIGNED_16, DATA_TYPE_VEC2_SIGNED_32, (33413u << 16) | 27593, true, (4294935173ull << 32) | 27593));
9071 testCases.push_back(ConvertCase(instruction, DATA_TYPE_VEC2_SIGNED_32, DATA_TYPE_VEC2_SIGNED_16, (4294935173ull << 32) | 27593, true, (33413u << 16) | 27593));
9073 else if (instruction == "OpFConvert")
9075 // All hexadecimal values below represent 1234.0 as 16/32/64-bit IEEE 754 float
9076 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_32, DATA_TYPE_FLOAT_64, 0x449a4000, true, 0x4093480000000000));
9077 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_64, DATA_TYPE_FLOAT_32, 0x4093480000000000, true, 0x449a4000));
9079 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_32, DATA_TYPE_FLOAT_16, 0x449a4000, true, 0x64D2));
9080 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_FLOAT_32, 0x64D2, true, 0x449a4000));
9082 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_FLOAT_64, 0x64D2, true, 0x4093480000000000));
9083 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_64, DATA_TYPE_FLOAT_16, 0x4093480000000000, true, 0x64D2));
9085 else if (instruction == "OpConvertFToU")
9087 // Normal numbers from uint8 range
9088 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_UNSIGNED_8, 0x5020, true, 33, "33"));
9089 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_32, DATA_TYPE_UNSIGNED_8, 0x42280000, true, 42, "42"));
9090 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_64, DATA_TYPE_UNSIGNED_8, 0x4067800000000000ull, true, 188, "188"));
9092 // Maximum uint8 value
9093 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_UNSIGNED_8, 0x5BF8, true, 255, "max"));
9094 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_32, DATA_TYPE_UNSIGNED_8, 0x437F0000, true, 255, "max"));
9095 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_64, DATA_TYPE_UNSIGNED_8, 0x406FE00000000000ull, true, 255, "max"));
9098 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_UNSIGNED_8, 0x0000, true, 0, "p0"));
9099 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_32, DATA_TYPE_UNSIGNED_8, 0x00000000, true, 0, "p0"));
9100 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_64, DATA_TYPE_UNSIGNED_8, 0x0000000000000000ull, true, 0, "p0"));
9103 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_UNSIGNED_8, 0x8000, true, 0, "m0"));
9104 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_32, DATA_TYPE_UNSIGNED_8, 0x80000000, true, 0, "m0"));
9105 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_64, DATA_TYPE_UNSIGNED_8, 0x8000000000000000ull, true, 0, "m0"));
9107 // All hexadecimal values below represent 1234.0 as 16/32/64-bit IEEE 754 float
9108 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_UNSIGNED_16, 0x64D2, true, 1234, "1234"));
9109 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_UNSIGNED_32, 0x64D2, true, 1234, "1234"));
9110 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_UNSIGNED_64, 0x64D2, true, 1234, "1234"));
9112 // 0x7BFF = 0111 1011 1111 1111 = 0 11110 1111111111 = 65504
9113 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_UNSIGNED_16, 0x7BFF, true, 65504, "max"));
9114 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_UNSIGNED_32, 0x7BFF, true, 65504, "max"));
9115 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_UNSIGNED_64, 0x7BFF, true, 65504, "max"));
9118 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_UNSIGNED_32, 0x0000, true, 0, "p0"));
9119 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_UNSIGNED_16, 0x0000, true, 0, "p0"));
9120 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_UNSIGNED_64, 0x0000, true, 0, "p0"));
9123 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_UNSIGNED_16, 0x8000, true, 0, "m0"));
9124 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_UNSIGNED_32, 0x8000, true, 0, "m0"));
9125 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_UNSIGNED_64, 0x8000, true, 0, "m0"));
9127 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_32, DATA_TYPE_UNSIGNED_16, 0x449a4000, true, 1234));
9128 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_32, DATA_TYPE_UNSIGNED_32, 0x449a4000, true, 1234));
9129 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_32, DATA_TYPE_UNSIGNED_64, 0x449a4000, true, 1234));
9130 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_64, DATA_TYPE_UNSIGNED_16, 0x4093480000000000, true, 1234));
9131 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_64, DATA_TYPE_UNSIGNED_32, 0x4093480000000000, true, 1234));
9132 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_64, DATA_TYPE_UNSIGNED_64, 0x4093480000000000, true, 1234));
9134 else if (instruction == "OpConvertUToF")
9136 // Normal numbers from uint8 range
9137 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_8, DATA_TYPE_FLOAT_16, 116, true, 0x5740, "116"));
9138 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_8, DATA_TYPE_FLOAT_32, 232, true, 0x43680000, "232"));
9139 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_8, DATA_TYPE_FLOAT_64, 164, true, 0x4064800000000000ull, "164"));
9141 // Maximum uint8 value
9142 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_8, DATA_TYPE_FLOAT_16, 255, true, 0x5BF8, "max"));
9143 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_8, DATA_TYPE_FLOAT_32, 255, true, 0x437F0000, "max"));
9144 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_8, DATA_TYPE_FLOAT_64, 255, true, 0x406FE00000000000ull, "max"));
9146 // All hexadecimal values below represent 1234.0 as 32/64-bit IEEE 754 float
9147 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_16, DATA_TYPE_FLOAT_16, 1234, true, 0x64D2, "1234"));
9148 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_32, DATA_TYPE_FLOAT_16, 1234, true, 0x64D2, "1234"));
9149 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_64, DATA_TYPE_FLOAT_16, 1234, true, 0x64D2, "1234"));
9151 // 0x7BFF = 0111 1011 1111 1111 = 0 11110 1111111111 = 65504
9152 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_16, DATA_TYPE_FLOAT_16, 65504, true, 0x7BFF, "max"));
9153 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_32, DATA_TYPE_FLOAT_16, 65504, true, 0x7BFF, "max"));
9154 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_64, DATA_TYPE_FLOAT_16, 65504, true, 0x7BFF, "max"));
9156 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_16, DATA_TYPE_FLOAT_32, 1234, true, 0x449a4000));
9157 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_16, DATA_TYPE_FLOAT_64, 1234, true, 0x4093480000000000));
9158 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_32, DATA_TYPE_FLOAT_32, 1234, true, 0x449a4000));
9159 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_32, DATA_TYPE_FLOAT_64, 1234, true, 0x4093480000000000));
9160 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_64, DATA_TYPE_FLOAT_32, 1234, true, 0x449a4000));
9161 testCases.push_back(ConvertCase(instruction, DATA_TYPE_UNSIGNED_64, DATA_TYPE_FLOAT_64, 1234, true, 0x4093480000000000));
9163 else if (instruction == "OpConvertFToS")
9165 // Normal numbers from int8 range
9166 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_SIGNED_8, 0xC980, true, -11, "m11"));
9167 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_32, DATA_TYPE_SIGNED_8, 0xC2140000, true, -37, "m37"));
9168 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_64, DATA_TYPE_SIGNED_8, 0xC050800000000000ull, true, -66, "m66"));
9170 // Minimum int8 value
9171 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_SIGNED_8, 0xD800, true, -128, "min"));
9172 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_32, DATA_TYPE_SIGNED_8, 0xC3000000, true, -128, "min"));
9173 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_64, DATA_TYPE_SIGNED_8, 0xC060000000000000ull, true, -128, "min"));
9175 // Maximum int8 value
9176 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_SIGNED_8, 0x57F0, true, 127, "max"));
9177 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_32, DATA_TYPE_SIGNED_8, 0x42FE0000, true, 127, "max"));
9178 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_64, DATA_TYPE_SIGNED_8, 0x405FC00000000000ull, true, 127, "max"));
9181 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_SIGNED_8, 0x0000, true, 0, "p0"));
9182 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_32, DATA_TYPE_SIGNED_8, 0x00000000, true, 0, "p0"));
9183 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_64, DATA_TYPE_SIGNED_8, 0x0000000000000000ull, true, 0, "p0"));
9186 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_SIGNED_8, 0x8000, true, 0, "m0"));
9187 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_32, DATA_TYPE_SIGNED_8, 0x80000000, true, 0, "m0"));
9188 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_64, DATA_TYPE_SIGNED_8, 0x8000000000000000ull, true, 0, "m0"));
9190 // All hexadecimal values below represent -1234.0 as 32/64-bit IEEE 754 float
9191 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_SIGNED_16, 0xE4D2, true, -1234, "m1234"));
9192 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_SIGNED_32, 0xE4D2, true, -1234, "m1234"));
9193 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_SIGNED_64, 0xE4D2, true, -1234, "m1234"));
9195 // 0xF800 = 1111 1000 0000 0000 = 1 11110 0000000000 = -32768
9196 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_SIGNED_16, 0xF800, true, -32768, "min"));
9197 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_SIGNED_32, 0xF800, true, -32768, "min"));
9198 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_SIGNED_64, 0xF800, true, -32768, "min"));
9200 // 0x77FF = 0111 0111 1111 1111 = 0 11101 1111111111 = 32752
9201 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_SIGNED_16, 0x77FF, true, 32752, "max"));
9202 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_SIGNED_32, 0x77FF, true, 32752, "max"));
9203 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_SIGNED_64, 0x77FF, true, 32752, "max"));
9206 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_SIGNED_16, 0x0000, true, 0, "p0"));
9207 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_SIGNED_32, 0x0000, true, 0, "p0"));
9208 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_SIGNED_64, 0x0000, true, 0, "p0"));
9211 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_SIGNED_16, 0x8000, true, 0, "m0"));
9212 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_SIGNED_32, 0x8000, true, 0, "m0"));
9213 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_16, DATA_TYPE_SIGNED_64, 0x8000, true, 0, "m0"));
9215 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_32, DATA_TYPE_SIGNED_16, 0xc49a4000, true, -1234));
9216 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_32, DATA_TYPE_SIGNED_32, 0xc49a4000, true, -1234));
9217 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_32, DATA_TYPE_SIGNED_64, 0xc49a4000, true, -1234));
9218 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_64, DATA_TYPE_SIGNED_16, 0xc093480000000000, true, -1234));
9219 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_64, DATA_TYPE_SIGNED_32, 0xc093480000000000, true, -1234));
9220 testCases.push_back(ConvertCase(instruction, DATA_TYPE_FLOAT_64, DATA_TYPE_SIGNED_64, 0xc093480000000000, true, -1234));
9222 else if (instruction == "OpConvertSToF")
9224 // Normal numbers from int8 range
9225 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_8, DATA_TYPE_FLOAT_16, -12, true, 0xCA00, "m21"));
9226 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_8, DATA_TYPE_FLOAT_32, -21, true, 0xC1A80000, "m21"));
9227 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_8, DATA_TYPE_FLOAT_64, -99, true, 0xC058C00000000000ull, "m99"));
9229 // Minimum int8 value
9230 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_8, DATA_TYPE_FLOAT_16, -128, true, 0xD800, "min"));
9231 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_8, DATA_TYPE_FLOAT_32, -128, true, 0xC3000000, "min"));
9232 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_8, DATA_TYPE_FLOAT_64, -128, true, 0xC060000000000000ull, "min"));
9234 // Maximum int8 value
9235 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_8, DATA_TYPE_FLOAT_16, 127, true, 0x57F0, "max"));
9236 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_8, DATA_TYPE_FLOAT_32, 127, true, 0x42FE0000, "max"));
9237 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_8, DATA_TYPE_FLOAT_64, 127, true, 0x405FC00000000000ull, "max"));
9239 // All hexadecimal values below represent 1234.0 as 32/64-bit IEEE 754 float
9240 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_16, DATA_TYPE_FLOAT_16, -1234, true, 0xE4D2, "m1234"));
9241 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_32, DATA_TYPE_FLOAT_16, -1234, true, 0xE4D2, "m1234"));
9242 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_64, DATA_TYPE_FLOAT_16, -1234, true, 0xE4D2, "m1234"));
9244 // 0xF800 = 1111 1000 0000 0000 = 1 11110 0000000000 = -32768
9245 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_16, DATA_TYPE_FLOAT_16, -32768, true, 0xF800, "min"));
9246 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_32, DATA_TYPE_FLOAT_16, -32768, true, 0xF800, "min"));
9247 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_64, DATA_TYPE_FLOAT_16, -32768, true, 0xF800, "min"));
9249 // 0x77FF = 0111 0111 1111 1111 = 0 11101 1111111111 = 32752
9250 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_16, DATA_TYPE_FLOAT_16, 32752, true, 0x77FF, "max"));
9251 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_32, DATA_TYPE_FLOAT_16, 32752, true, 0x77FF, "max"));
9252 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_64, DATA_TYPE_FLOAT_16, 32752, true, 0x77FF, "max"));
9254 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_16, DATA_TYPE_FLOAT_32, -1234, true, 0xc49a4000));
9255 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_16, DATA_TYPE_FLOAT_64, -1234, true, 0xc093480000000000));
9256 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_32, DATA_TYPE_FLOAT_32, -1234, true, 0xc49a4000));
9257 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_32, DATA_TYPE_FLOAT_64, -1234, true, 0xc093480000000000));
9258 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_64, DATA_TYPE_FLOAT_32, -1234, true, 0xc49a4000));
9259 testCases.push_back(ConvertCase(instruction, DATA_TYPE_SIGNED_64, DATA_TYPE_FLOAT_64, -1234, true, 0xc093480000000000));
9262 DE_FATAL("Unknown instruction");
9265 const map<string, string> getConvertCaseFragments (string instruction, const ConvertCase& convertCase)
9267 map<string, string> params = convertCase.m_asmTypes;
9268 map<string, string> fragments;
9270 params["instruction"] = instruction;
9271 params["inDecorator"] = getByteWidthStr(convertCase.m_fromType);
9273 const StringTemplate decoration (
9274 " OpDecorate %SSBOi DescriptorSet 0\n"
9275 " OpDecorate %SSBOo DescriptorSet 0\n"
9276 " OpDecorate %SSBOi Binding 0\n"
9277 " OpDecorate %SSBOo Binding 1\n"
9278 " OpDecorate %s_SSBOi Block\n"
9279 " OpDecorate %s_SSBOo Block\n"
9280 "OpMemberDecorate %s_SSBOi 0 Offset 0\n"
9281 "OpMemberDecorate %s_SSBOo 0 Offset 0\n");
9283 const StringTemplate pre_main (
9284 "${datatype_additional_decl:opt}"
9285 " %ptr_in = OpTypePointer StorageBuffer %${inputType}\n"
9286 " %ptr_out = OpTypePointer StorageBuffer %${outputType}\n"
9287 " %s_SSBOi = OpTypeStruct %${inputType}\n"
9288 " %s_SSBOo = OpTypeStruct %${outputType}\n"
9289 " %ptr_SSBOi = OpTypePointer StorageBuffer %s_SSBOi\n"
9290 " %ptr_SSBOo = OpTypePointer StorageBuffer %s_SSBOo\n"
9291 " %SSBOi = OpVariable %ptr_SSBOi StorageBuffer\n"
9292 " %SSBOo = OpVariable %ptr_SSBOo StorageBuffer\n");
9294 const StringTemplate testfun (
9295 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
9296 "%param = OpFunctionParameter %v4f32\n"
9297 "%label = OpLabel\n"
9298 "%iLoc = OpAccessChain %ptr_in %SSBOi %c_u32_0\n"
9299 "%oLoc = OpAccessChain %ptr_out %SSBOo %c_u32_0\n"
9300 "%valIn = OpLoad %${inputType} %iLoc\n"
9301 "%valOut = ${instruction} %${outputType} %valIn\n"
9302 " OpStore %oLoc %valOut\n"
9303 " OpReturnValue %param\n"
9304 " OpFunctionEnd\n");
9306 params["datatype_extensions"] =
9307 params["datatype_extensions"] +
9308 "OpExtension \"SPV_KHR_storage_buffer_storage_class\"\n";
9310 fragments["capability"] = params["datatype_capabilities"];
9311 fragments["extension"] = params["datatype_extensions"];
9312 fragments["decoration"] = decoration.specialize(params);
9313 fragments["pre_main"] = pre_main.specialize(params);
9314 fragments["testfun"] = testfun.specialize(params);
9319 // Test for OpSConvert, OpUConvert, OpFConvert and OpConvert* in compute shaders
9320 tcu::TestCaseGroup* createConvertComputeTests (tcu::TestContext& testCtx, const string& instruction, const string& name)
9322 de::MovePtr<tcu::TestCaseGroup> group(new tcu::TestCaseGroup(testCtx, name.c_str(), instruction.c_str()));
9323 vector<ConvertCase> testCases;
9324 createConvertCases(testCases, instruction);
9326 for (vector<ConvertCase>::const_iterator test = testCases.begin(); test != testCases.end(); ++test)
9328 ComputeShaderSpec spec;
9329 spec.assembly = getConvertCaseShaderStr(instruction, *test);
9330 spec.numWorkGroups = IVec3(1, 1, 1);
9331 spec.inputs.push_back (test->m_inputBuffer);
9332 spec.outputs.push_back (test->m_outputBuffer);
9334 getVulkanFeaturesAndExtensions(test->m_fromType, test->m_toType, spec.requestedVulkanFeatures, spec.extensions);
9336 group->addChild(new SpvAsmComputeShaderCase(testCtx, test->m_name.c_str(), "", spec));
9338 return group.release();
9341 // Test for OpSConvert, OpUConvert, OpFConvert and OpConvert* in graphics shaders
9342 tcu::TestCaseGroup* createConvertGraphicsTests (tcu::TestContext& testCtx, const string& instruction, const string& name)
9344 de::MovePtr<tcu::TestCaseGroup> group(new tcu::TestCaseGroup(testCtx, name.c_str(), instruction.c_str()));
9345 vector<ConvertCase> testCases;
9346 createConvertCases(testCases, instruction);
9348 for (vector<ConvertCase>::const_iterator test = testCases.begin(); test != testCases.end(); ++test)
9350 map<string, string> fragments = getConvertCaseFragments(instruction, *test);
9351 vector<string> features;
9352 VulkanFeatures vulkanFeatures;
9353 GraphicsResources resources;
9354 vector<string> extensions;
9355 SpecConstants noSpecConstants;
9356 PushConstants noPushConstants;
9357 GraphicsInterfaces noInterfaces;
9358 tcu::RGBA defaultColors[4];
9360 getDefaultColors (defaultColors);
9361 resources.inputs.push_back (Resource(test->m_inputBuffer, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
9362 resources.outputs.push_back (Resource(test->m_outputBuffer, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
9363 extensions.push_back ("VK_KHR_storage_buffer_storage_class");
9365 getVulkanFeaturesAndExtensions(test->m_fromType, test->m_toType, vulkanFeatures, extensions);
9367 createTestsForAllStages(
9368 test->m_name, defaultColors, defaultColors, fragments, noSpecConstants,
9369 noPushConstants, resources, noInterfaces, extensions, features, vulkanFeatures, group.get());
9371 return group.release();
9374 // Constant-Creation Instructions: OpConstant, OpConstantComposite
9375 tcu::TestCaseGroup* createOpConstantFloat16Tests(tcu::TestContext& testCtx)
9377 de::MovePtr<tcu::TestCaseGroup> opConstantCompositeTests (new tcu::TestCaseGroup(testCtx, "opconstant", "OpConstant and OpConstantComposite instruction"));
9378 RGBA inputColors[4];
9379 RGBA outputColors[4];
9380 vector<string> extensions;
9381 GraphicsResources resources;
9382 VulkanFeatures features;
9384 const char functionStart[] =
9385 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
9386 "%param1 = OpFunctionParameter %v4f32\n"
9389 const char functionEnd[] =
9390 "%transformed_param_32 = OpFConvert %v4f32 %transformed_param\n"
9391 " OpReturnValue %transformed_param_32\n"
9394 struct NameConstantsCode
9401 #define FLOAT_16_COMMON_TYPES_AND_CONSTS \
9402 "%f16 = OpTypeFloat 16\n" \
9403 "%c_f16_0 = OpConstant %f16 0.0\n" \
9404 "%c_f16_0_5 = OpConstant %f16 0.5\n" \
9405 "%c_f16_1 = OpConstant %f16 1.0\n" \
9406 "%v4f16 = OpTypeVector %f16 4\n" \
9407 "%fp_f16 = OpTypePointer Function %f16\n" \
9408 "%fp_v4f16 = OpTypePointer Function %v4f16\n" \
9409 "%c_v4f16_1_1_1_1 = OpConstantComposite %v4f16 %c_f16_1 %c_f16_1 %c_f16_1 %c_f16_1\n" \
9410 "%a4f16 = OpTypeArray %f16 %c_u32_4\n" \
9412 NameConstantsCode tests[] =
9417 FLOAT_16_COMMON_TYPES_AND_CONSTS
9418 "%cval = OpConstantComposite %v4f16 %c_f16_0_5 %c_f16_0_5 %c_f16_0_5 %c_f16_0\n",
9419 "%param1_16 = OpFConvert %v4f16 %param1\n"
9420 "%transformed_param = OpFAdd %v4f16 %param1_16 %cval\n"
9425 FLOAT_16_COMMON_TYPES_AND_CONSTS
9426 "%stype = OpTypeStruct %v4f16 %f16\n"
9427 "%fp_stype = OpTypePointer Function %stype\n"
9428 "%f16_n_1 = OpConstant %f16 -1.0\n"
9429 "%f16_1_5 = OpConstant %f16 !0x3e00\n" // +1.5
9430 "%cvec = OpConstantComposite %v4f16 %f16_1_5 %f16_1_5 %f16_1_5 %c_f16_1\n"
9431 "%cval = OpConstantComposite %stype %cvec %f16_n_1\n",
9433 "%v = OpVariable %fp_stype Function %cval\n"
9434 "%vec_ptr = OpAccessChain %fp_v4f16 %v %c_u32_0\n"
9435 "%f16_ptr = OpAccessChain %fp_f16 %v %c_u32_1\n"
9436 "%vec_val = OpLoad %v4f16 %vec_ptr\n"
9437 "%f16_val = OpLoad %f16 %f16_ptr\n"
9438 "%tmp1 = OpVectorTimesScalar %v4f16 %c_v4f16_1_1_1_1 %f16_val\n" // vec4(-1)
9439 "%param1_16 = OpFConvert %v4f16 %param1\n"
9440 "%tmp2 = OpFAdd %v4f16 %tmp1 %param1_16\n" // param1 + vec4(-1)
9441 "%transformed_param = OpFAdd %v4f16 %tmp2 %vec_val\n" // param1 + vec4(-1) + vec4(1.5, 1.5, 1.5, 1.0)
9444 // [1|0|0|0.5] [x] = x + 0.5
9445 // [0|1|0|0.5] [y] = y + 0.5
9446 // [0|0|1|0.5] [z] = z + 0.5
9447 // [0|0|0|1 ] [1] = 1
9450 FLOAT_16_COMMON_TYPES_AND_CONSTS
9451 "%mat4x4_f16 = OpTypeMatrix %v4f16 4\n"
9452 "%v4f16_1_0_0_0 = OpConstantComposite %v4f16 %c_f16_1 %c_f16_0 %c_f16_0 %c_f16_0\n"
9453 "%v4f16_0_1_0_0 = OpConstantComposite %v4f16 %c_f16_0 %c_f16_1 %c_f16_0 %c_f16_0\n"
9454 "%v4f16_0_0_1_0 = OpConstantComposite %v4f16 %c_f16_0 %c_f16_0 %c_f16_1 %c_f16_0\n"
9455 "%v4f16_0_5_0_5_0_5_1 = OpConstantComposite %v4f16 %c_f16_0_5 %c_f16_0_5 %c_f16_0_5 %c_f16_1\n"
9456 "%cval = OpConstantComposite %mat4x4_f16 %v4f16_1_0_0_0 %v4f16_0_1_0_0 %v4f16_0_0_1_0 %v4f16_0_5_0_5_0_5_1\n",
9458 "%param1_16 = OpFConvert %v4f16 %param1\n"
9459 "%transformed_param = OpMatrixTimesVector %v4f16 %cval %param1_16\n"
9464 FLOAT_16_COMMON_TYPES_AND_CONSTS
9465 "%c_v4f16_1_1_1_0 = OpConstantComposite %v4f16 %c_f16_1 %c_f16_1 %c_f16_1 %c_f16_0\n"
9466 "%fp_a4f16 = OpTypePointer Function %a4f16\n"
9467 "%f16_n_1 = OpConstant %f16 -1.0\n"
9468 "%f16_1_5 = OpConstant %f16 !0x3e00\n" // +1.5
9469 "%carr = OpConstantComposite %a4f16 %c_f16_0 %f16_n_1 %f16_1_5 %c_f16_0\n",
9471 "%v = OpVariable %fp_a4f16 Function %carr\n"
9472 "%f = OpAccessChain %fp_f16 %v %c_u32_0\n"
9473 "%f1 = OpAccessChain %fp_f16 %v %c_u32_1\n"
9474 "%f2 = OpAccessChain %fp_f16 %v %c_u32_2\n"
9475 "%f3 = OpAccessChain %fp_f16 %v %c_u32_3\n"
9476 "%f_val = OpLoad %f16 %f\n"
9477 "%f1_val = OpLoad %f16 %f1\n"
9478 "%f2_val = OpLoad %f16 %f2\n"
9479 "%f3_val = OpLoad %f16 %f3\n"
9480 "%ftot1 = OpFAdd %f16 %f_val %f1_val\n"
9481 "%ftot2 = OpFAdd %f16 %ftot1 %f2_val\n"
9482 "%ftot3 = OpFAdd %f16 %ftot2 %f3_val\n" // 0 - 1 + 1.5 + 0
9483 "%add_vec = OpVectorTimesScalar %v4f16 %c_v4f16_1_1_1_0 %ftot3\n"
9484 "%param1_16 = OpFConvert %v4f16 %param1\n"
9485 "%transformed_param = OpFAdd %v4f16 %param1_16 %add_vec\n"
9492 // [ 1.0, 1.0, 1.0, 1.0]
9496 // [ 0.0, 0.5, 0.0, 0.0]
9500 // [ 1.0, 1.0, 1.0, 1.0]
9503 "array_of_struct_of_array",
9505 FLOAT_16_COMMON_TYPES_AND_CONSTS
9506 "%c_v4f16_1_1_1_0 = OpConstantComposite %v4f16 %c_f16_1 %c_f16_1 %c_f16_1 %c_f16_0\n"
9507 "%fp_a4f16 = OpTypePointer Function %a4f16\n"
9508 "%stype = OpTypeStruct %f16 %a4f16\n"
9509 "%a3stype = OpTypeArray %stype %c_u32_3\n"
9510 "%fp_a3stype = OpTypePointer Function %a3stype\n"
9511 "%ca4f16_0 = OpConstantComposite %a4f16 %c_f16_0 %c_f16_0_5 %c_f16_0 %c_f16_0\n"
9512 "%ca4f16_1 = OpConstantComposite %a4f16 %c_f16_1 %c_f16_1 %c_f16_1 %c_f16_1\n"
9513 "%cstype1 = OpConstantComposite %stype %c_f16_0 %ca4f16_1\n"
9514 "%cstype2 = OpConstantComposite %stype %c_f16_1 %ca4f16_0\n"
9515 "%carr = OpConstantComposite %a3stype %cstype1 %cstype2 %cstype1",
9517 "%v = OpVariable %fp_a3stype Function %carr\n"
9518 "%f = OpAccessChain %fp_f16 %v %c_u32_1 %c_u32_1 %c_u32_1\n"
9519 "%f_l = OpLoad %f16 %f\n"
9520 "%add_vec = OpVectorTimesScalar %v4f16 %c_v4f16_1_1_1_0 %f_l\n"
9521 "%param1_16 = OpFConvert %v4f16 %param1\n"
9522 "%transformed_param = OpFAdd %v4f16 %param1_16 %add_vec\n"
9526 getHalfColorsFullAlpha(inputColors);
9527 outputColors[0] = RGBA(255, 255, 255, 255);
9528 outputColors[1] = RGBA(255, 127, 127, 255);
9529 outputColors[2] = RGBA(127, 255, 127, 255);
9530 outputColors[3] = RGBA(127, 127, 255, 255);
9532 extensions.push_back("VK_KHR_16bit_storage");
9533 extensions.push_back("VK_KHR_shader_float16_int8");
9535 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameConstantsCode); ++testNdx)
9537 map<string, string> fragments;
9539 fragments["extension"] = "OpExtension \"SPV_KHR_16bit_storage\"";
9540 fragments["capability"] = "OpCapability Float16\n";
9541 fragments["pre_main"] = tests[testNdx].constants;
9542 fragments["testfun"] = string(functionStart) + tests[testNdx].code + functionEnd;
9544 createTestsForAllStages(tests[testNdx].name, inputColors, outputColors, fragments, resources, extensions, opConstantCompositeTests.get(), features);
9546 return opConstantCompositeTests.release();
9549 template<typename T>
9550 void finalizeTestsCreation (T& specResource,
9551 const map<string, string>& fragments,
9552 tcu::TestContext& testCtx,
9553 tcu::TestCaseGroup& testGroup,
9554 const std::string& testName,
9555 const VulkanFeatures& vulkanFeatures,
9556 const vector<string>& extensions,
9557 const IVec3& numWorkGroups);
9560 void finalizeTestsCreation (GraphicsResources& specResource,
9561 const map<string, string>& fragments,
9563 tcu::TestCaseGroup& testGroup,
9564 const std::string& testName,
9565 const VulkanFeatures& vulkanFeatures,
9566 const vector<string>& extensions,
9569 RGBA defaultColors[4];
9570 getDefaultColors(defaultColors);
9572 createTestsForAllStages(testName, defaultColors, defaultColors, fragments, specResource, extensions, &testGroup, vulkanFeatures);
9576 void finalizeTestsCreation (ComputeShaderSpec& specResource,
9577 const map<string, string>& fragments,
9578 tcu::TestContext& testCtx,
9579 tcu::TestCaseGroup& testGroup,
9580 const std::string& testName,
9581 const VulkanFeatures& vulkanFeatures,
9582 const vector<string>& extensions,
9583 const IVec3& numWorkGroups)
9585 specResource.numWorkGroups = numWorkGroups;
9586 specResource.requestedVulkanFeatures = vulkanFeatures;
9587 specResource.extensions = extensions;
9589 specResource.assembly = makeComputeShaderAssembly(fragments);
9591 testGroup.addChild(new SpvAsmComputeShaderCase(testCtx, testName.c_str(), "", specResource));
9594 template<class SpecResource>
9595 tcu::TestCaseGroup* createFloat16LogicalSet (tcu::TestContext& testCtx, const bool nanSupported)
9597 const string nan = nanSupported ? "_nan" : "";
9598 const string groupName = "logical" + nan;
9599 de::MovePtr<tcu::TestCaseGroup> testGroup (new tcu::TestCaseGroup(testCtx, groupName.c_str(), "Float 16 logical tests"));
9601 de::Random rnd (deStringHash(testGroup->getName()));
9602 const StringTemplate capabilities ("OpCapability ${cap}\n");
9603 const deUint32 numDataPoints = 16;
9604 const vector<deFloat16> float16Data = getFloat16s(rnd, numDataPoints);
9605 const vector<deFloat16> float16Data1 = squarize(float16Data, 0);
9606 const vector<deFloat16> float16Data2 = squarize(float16Data, 1);
9607 const vector<deFloat16> float16DataVec1 = squarizeVector(float16Data, 0);
9608 const vector<deFloat16> float16DataVec2 = squarizeVector(float16Data, 1);
9609 const vector<deFloat16> float16OutDummy (float16Data1.size(), 0);
9610 const vector<deFloat16> float16OutVecDummy (float16DataVec1.size(), 0);
9615 VerifyIOFunc verifyFuncNan;
9616 VerifyIOFunc verifyFuncNonNan;
9617 const deUint32 argCount;
9620 const TestOp testOps[] =
9622 { "OpIsNan" , compareFP16Logical<fp16isNan, true, false, true>, compareFP16Logical<fp16isNan, true, false, false>, 1 },
9623 { "OpIsInf" , compareFP16Logical<fp16isInf, true, false, true>, compareFP16Logical<fp16isInf, true, false, false>, 1 },
9624 { "OpFOrdEqual" , compareFP16Logical<fp16isEqual, false, true, true>, compareFP16Logical<fp16isEqual, false, true, false>, 2 },
9625 { "OpFUnordEqual" , compareFP16Logical<fp16isEqual, false, false, true>, compareFP16Logical<fp16isEqual, false, false, false>, 2 },
9626 { "OpFOrdNotEqual" , compareFP16Logical<fp16isUnequal, false, true, true>, compareFP16Logical<fp16isUnequal, false, true, false>, 2 },
9627 { "OpFUnordNotEqual" , compareFP16Logical<fp16isUnequal, false, false, true>, compareFP16Logical<fp16isUnequal, false, false, false>, 2 },
9628 { "OpFOrdLessThan" , compareFP16Logical<fp16isLess, false, true, true>, compareFP16Logical<fp16isLess, false, true, false>, 2 },
9629 { "OpFUnordLessThan" , compareFP16Logical<fp16isLess, false, false, true>, compareFP16Logical<fp16isLess, false, false, false>, 2 },
9630 { "OpFOrdGreaterThan" , compareFP16Logical<fp16isGreater, false, true, true>, compareFP16Logical<fp16isGreater, false, true, false>, 2 },
9631 { "OpFUnordGreaterThan" , compareFP16Logical<fp16isGreater, false, false, true>, compareFP16Logical<fp16isGreater, false, false, false>, 2 },
9632 { "OpFOrdLessThanEqual" , compareFP16Logical<fp16isLessOrEqual, false, true, true>, compareFP16Logical<fp16isLessOrEqual, false, true, false>, 2 },
9633 { "OpFUnordLessThanEqual" , compareFP16Logical<fp16isLessOrEqual, false, false, true>, compareFP16Logical<fp16isLessOrEqual, false, false, false>, 2 },
9634 { "OpFOrdGreaterThanEqual" , compareFP16Logical<fp16isGreaterOrEqual, false, true, true>, compareFP16Logical<fp16isGreaterOrEqual, false, true, false>, 2 },
9635 { "OpFUnordGreaterThanEqual" , compareFP16Logical<fp16isGreaterOrEqual, false, false, true>, compareFP16Logical<fp16isGreaterOrEqual, false, false, false>, 2 },
9639 const StringTemplate preMain
9641 "%c_i32_ndp = OpConstant %i32 ${num_data_points}\n"
9642 " %f16 = OpTypeFloat 16\n"
9643 " %c_f16_0 = OpConstant %f16 0.0\n"
9644 " %c_f16_1 = OpConstant %f16 1.0\n"
9645 " %up_f16 = OpTypePointer Uniform %f16\n"
9646 " %ra_f16 = OpTypeArray %f16 %c_i32_ndp\n"
9647 " %SSBO16 = OpTypeStruct %ra_f16\n"
9648 "%up_SSBO16 = OpTypePointer Uniform %SSBO16\n"
9649 "%ssbo_src0 = OpVariable %up_SSBO16 Uniform\n"
9650 "%ssbo_src1 = OpVariable %up_SSBO16 Uniform\n"
9651 " %ssbo_dst = OpVariable %up_SSBO16 Uniform\n"
9654 const StringTemplate decoration
9656 "OpDecorate %ra_f16 ArrayStride 2\n"
9657 "OpMemberDecorate %SSBO16 0 Offset 0\n"
9658 "OpDecorate %SSBO16 BufferBlock\n"
9659 "OpDecorate %ssbo_src0 DescriptorSet 0\n"
9660 "OpDecorate %ssbo_src0 Binding 0\n"
9661 "OpDecorate %ssbo_src1 DescriptorSet 0\n"
9662 "OpDecorate %ssbo_src1 Binding 1\n"
9663 "OpDecorate %ssbo_dst DescriptorSet 0\n"
9664 "OpDecorate %ssbo_dst Binding 2\n"
9667 const StringTemplate testFun
9669 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
9670 " %param = OpFunctionParameter %v4f32\n"
9672 " %entry = OpLabel\n"
9673 " %i = OpVariable %fp_i32 Function\n"
9674 " OpStore %i %c_i32_0\n"
9677 " %loop = OpLabel\n"
9678 " %i_cmp = OpLoad %i32 %i\n"
9679 " %lt = OpSLessThan %bool %i_cmp %c_i32_ndp\n"
9680 " OpLoopMerge %merge %next None\n"
9681 " OpBranchConditional %lt %write %merge\n"
9683 " %write = OpLabel\n"
9684 " %ndx = OpLoad %i32 %i\n"
9686 " %src0 = OpAccessChain %up_f16 %ssbo_src0 %c_i32_0 %ndx\n"
9687 " %val_src0 = OpLoad %f16 %src0\n"
9691 " %val_bdst = ${op_code} %bool %val_src0 ${op_arg1}\n"
9692 " %val_dst = OpSelect %f16 %val_bdst %c_f16_1 %c_f16_0\n"
9693 " %dst = OpAccessChain %up_f16 %ssbo_dst %c_i32_0 %ndx\n"
9694 " OpStore %dst %val_dst\n"
9697 " %next = OpLabel\n"
9698 " %i_cur = OpLoad %i32 %i\n"
9699 " %i_new = OpIAdd %i32 %i_cur %c_i32_1\n"
9700 " OpStore %i %i_new\n"
9703 " %merge = OpLabel\n"
9704 " OpReturnValue %param\n"
9709 const StringTemplate arg1Calc
9711 " %src1 = OpAccessChain %up_f16 %ssbo_src1 %c_i32_0 %ndx\n"
9712 " %val_src1 = OpLoad %f16 %src1\n"
9715 for (deUint32 testOpsIdx = 0; testOpsIdx < DE_LENGTH_OF_ARRAY(testOps); ++testOpsIdx)
9717 const size_t iterations = float16Data1.size();
9718 const TestOp& testOp = testOps[testOpsIdx];
9719 const string testName = de::toLower(string(testOp.opCode)) + "_scalar";
9720 SpecResource specResource;
9721 map<string, string> specs;
9722 VulkanFeatures features;
9723 map<string, string> fragments;
9724 vector<string> extensions;
9726 specs["cap"] = "StorageUniformBufferBlock16";
9727 specs["num_data_points"] = de::toString(iterations);
9728 specs["op_code"] = testOp.opCode;
9729 specs["op_arg1"] = (testOp.argCount == 1) ? "" : "%val_src1";
9730 specs["op_arg1_calc"] = (testOp.argCount == 1) ? "" : arg1Calc.specialize(specs);
9732 fragments["extension"] = "OpExtension \"SPV_KHR_16bit_storage\"";
9733 fragments["capability"] = capabilities.specialize(specs);
9734 fragments["decoration"] = decoration.specialize(specs);
9735 fragments["pre_main"] = preMain.specialize(specs);
9736 fragments["testfun"] = testFun.specialize(specs);
9738 specResource.inputs.push_back(Resource(BufferSp(new Float16Buffer(float16Data1)), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
9739 specResource.inputs.push_back(Resource(BufferSp(new Float16Buffer(float16Data2)), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
9740 specResource.outputs.push_back(Resource(BufferSp(new Float16Buffer(float16OutDummy)), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
9741 specResource.verifyIO = nanSupported ? testOp.verifyFuncNan : testOp.verifyFuncNonNan;
9743 extensions.push_back("VK_KHR_16bit_storage");
9744 extensions.push_back("VK_KHR_shader_float16_int8");
9748 extensions.push_back("VK_KHR_shader_float_controls");
9750 features.floatControlsProperties.shaderSignedZeroInfNanPreserveFloat16 = DE_TRUE;
9753 features.ext16BitStorage = EXT16BITSTORAGEFEATURES_UNIFORM_BUFFER_BLOCK;
9754 features.extFloat16Int8 = EXTFLOAT16INT8FEATURES_FLOAT16;
9756 finalizeTestsCreation(specResource, fragments, testCtx, *testGroup.get(), testName, features, extensions, IVec3(1, 1, 1));
9760 const StringTemplate preMain
9762 " %c_i32_ndp = OpConstant %i32 ${num_data_points}\n"
9763 " %v2bool = OpTypeVector %bool 2\n"
9764 " %f16 = OpTypeFloat 16\n"
9765 " %c_f16_0 = OpConstant %f16 0.0\n"
9766 " %c_f16_1 = OpConstant %f16 1.0\n"
9767 " %v2f16 = OpTypeVector %f16 2\n"
9768 "%c_v2f16_0_0 = OpConstantComposite %v2f16 %c_f16_0 %c_f16_0\n"
9769 "%c_v2f16_1_1 = OpConstantComposite %v2f16 %c_f16_1 %c_f16_1\n"
9770 " %up_v2f16 = OpTypePointer Uniform %v2f16\n"
9771 " %ra_v2f16 = OpTypeArray %v2f16 %c_i32_ndp\n"
9772 " %SSBO16 = OpTypeStruct %ra_v2f16\n"
9773 " %up_SSBO16 = OpTypePointer Uniform %SSBO16\n"
9774 " %ssbo_src0 = OpVariable %up_SSBO16 Uniform\n"
9775 " %ssbo_src1 = OpVariable %up_SSBO16 Uniform\n"
9776 " %ssbo_dst = OpVariable %up_SSBO16 Uniform\n"
9779 const StringTemplate decoration
9781 "OpDecorate %ra_v2f16 ArrayStride 4\n"
9782 "OpMemberDecorate %SSBO16 0 Offset 0\n"
9783 "OpDecorate %SSBO16 BufferBlock\n"
9784 "OpDecorate %ssbo_src0 DescriptorSet 0\n"
9785 "OpDecorate %ssbo_src0 Binding 0\n"
9786 "OpDecorate %ssbo_src1 DescriptorSet 0\n"
9787 "OpDecorate %ssbo_src1 Binding 1\n"
9788 "OpDecorate %ssbo_dst DescriptorSet 0\n"
9789 "OpDecorate %ssbo_dst Binding 2\n"
9792 const StringTemplate testFun
9794 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
9795 " %param = OpFunctionParameter %v4f32\n"
9797 " %entry = OpLabel\n"
9798 " %i = OpVariable %fp_i32 Function\n"
9799 " OpStore %i %c_i32_0\n"
9802 " %loop = OpLabel\n"
9803 " %i_cmp = OpLoad %i32 %i\n"
9804 " %lt = OpSLessThan %bool %i_cmp %c_i32_ndp\n"
9805 " OpLoopMerge %merge %next None\n"
9806 " OpBranchConditional %lt %write %merge\n"
9808 " %write = OpLabel\n"
9809 " %ndx = OpLoad %i32 %i\n"
9811 " %src0 = OpAccessChain %up_v2f16 %ssbo_src0 %c_i32_0 %ndx\n"
9812 " %val_src0 = OpLoad %v2f16 %src0\n"
9816 " %val_bdst = ${op_code} %v2bool %val_src0 ${op_arg1}\n"
9817 " %val_dst = OpSelect %v2f16 %val_bdst %c_v2f16_1_1 %c_v2f16_0_0\n"
9818 " %dst = OpAccessChain %up_v2f16 %ssbo_dst %c_i32_0 %ndx\n"
9819 " OpStore %dst %val_dst\n"
9822 " %next = OpLabel\n"
9823 " %i_cur = OpLoad %i32 %i\n"
9824 " %i_new = OpIAdd %i32 %i_cur %c_i32_1\n"
9825 " OpStore %i %i_new\n"
9828 " %merge = OpLabel\n"
9829 " OpReturnValue %param\n"
9834 const StringTemplate arg1Calc
9836 " %src1 = OpAccessChain %up_v2f16 %ssbo_src1 %c_i32_0 %ndx\n"
9837 " %val_src1 = OpLoad %v2f16 %src1\n"
9840 for (deUint32 testOpsIdx = 0; testOpsIdx < DE_LENGTH_OF_ARRAY(testOps); ++testOpsIdx)
9842 const deUint32 itemsPerVec = 2;
9843 const size_t iterations = float16DataVec1.size() / itemsPerVec;
9844 const TestOp& testOp = testOps[testOpsIdx];
9845 const string testName = de::toLower(string(testOp.opCode)) + "_vector";
9846 SpecResource specResource;
9847 map<string, string> specs;
9848 vector<string> extensions;
9849 VulkanFeatures features;
9850 map<string, string> fragments;
9852 specs["cap"] = "StorageUniformBufferBlock16";
9853 specs["num_data_points"] = de::toString(iterations);
9854 specs["op_code"] = testOp.opCode;
9855 specs["op_arg1"] = (testOp.argCount == 1) ? "" : "%val_src1";
9856 specs["op_arg1_calc"] = (testOp.argCount == 1) ? "" : arg1Calc.specialize(specs);
9858 fragments["extension"] = "OpExtension \"SPV_KHR_16bit_storage\"";
9859 fragments["capability"] = capabilities.specialize(specs);
9860 fragments["decoration"] = decoration.specialize(specs);
9861 fragments["pre_main"] = preMain.specialize(specs);
9862 fragments["testfun"] = testFun.specialize(specs);
9864 specResource.inputs.push_back(Resource(BufferSp(new Float16Buffer(float16DataVec1)), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
9865 specResource.inputs.push_back(Resource(BufferSp(new Float16Buffer(float16DataVec2)), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
9866 specResource.outputs.push_back(Resource(BufferSp(new Float16Buffer(float16OutVecDummy)), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
9867 specResource.verifyIO = nanSupported ? testOp.verifyFuncNan : testOp.verifyFuncNonNan;
9869 extensions.push_back("VK_KHR_16bit_storage");
9870 extensions.push_back("VK_KHR_shader_float16_int8");
9874 extensions.push_back("VK_KHR_shader_float_controls");
9876 features.floatControlsProperties.shaderSignedZeroInfNanPreserveFloat16 = DE_TRUE;
9879 features.ext16BitStorage = EXT16BITSTORAGEFEATURES_UNIFORM_BUFFER_BLOCK;
9880 features.extFloat16Int8 = EXTFLOAT16INT8FEATURES_FLOAT16;
9882 finalizeTestsCreation(specResource, fragments, testCtx, *testGroup.get(), testName, features, extensions, IVec3(1, 1, 1));
9886 return testGroup.release();
9889 bool compareFP16FunctionSetFunc (const std::vector<Resource>& inputs, const vector<AllocationSp>& outputAllocs, const std::vector<Resource>&, TestLog& log)
9891 if (inputs.size() != 1 || outputAllocs.size() != 1)
9894 vector<deUint8> input1Bytes;
9896 inputs[0].getBytes(input1Bytes);
9898 const deUint16* const input1AsFP16 = (const deUint16*)&input1Bytes[0];
9899 const deUint16* const outputAsFP16 = (const deUint16*)outputAllocs[0]->getHostPtr();
9902 for (size_t idx = 0; idx < input1Bytes.size() / sizeof(deUint16); ++idx)
9904 if (!compare16BitFloat(input1AsFP16[idx], outputAsFP16[idx], error))
9906 log << TestLog::Message << error << TestLog::EndMessage;
9915 template<class SpecResource>
9916 tcu::TestCaseGroup* createFloat16FuncSet (tcu::TestContext& testCtx)
9918 de::MovePtr<tcu::TestCaseGroup> testGroup (new tcu::TestCaseGroup(testCtx, "function", "Float 16 function call related tests"));
9920 de::Random rnd (deStringHash(testGroup->getName()));
9921 const StringTemplate capabilities ("OpCapability ${cap}\n");
9922 const deUint32 numDataPoints = 256;
9923 const vector<deFloat16> float16InputData = getFloat16s(rnd, numDataPoints);
9924 const vector<deFloat16> float16OutputDummy (float16InputData.size(), 0);
9925 map<string, string> fragments;
9929 const deUint32 typeComponents;
9930 const char* typeName;
9931 const char* typeDecls;
9934 const TestType testTypes[] =
9944 " %v2f16 = OpTypeVector %f16 2\n"
9945 " %c_v2f16_0 = OpConstantComposite %v2f16 %c_f16_0 %c_f16_0\n"
9950 " %v4f16 = OpTypeVector %f16 4\n"
9951 " %c_v4f16_0 = OpConstantComposite %v4f16 %c_f16_0 %c_f16_0 %c_f16_0 %c_f16_0\n"
9955 const StringTemplate preMain
9957 " %c_i32_ndp = OpConstant %i32 ${num_data_points}\n"
9958 " %v2bool = OpTypeVector %bool 2\n"
9959 " %f16 = OpTypeFloat 16\n"
9960 " %c_f16_0 = OpConstant %f16 0.0\n"
9964 " %${tt}_fun = OpTypeFunction %${tt} %${tt}\n"
9965 " %up_${tt} = OpTypePointer Uniform %${tt}\n"
9966 " %ra_${tt} = OpTypeArray %${tt} %c_i32_ndp\n"
9967 " %SSBO16 = OpTypeStruct %ra_${tt}\n"
9968 " %up_SSBO16 = OpTypePointer Uniform %SSBO16\n"
9969 " %ssbo_src = OpVariable %up_SSBO16 Uniform\n"
9970 " %ssbo_dst = OpVariable %up_SSBO16 Uniform\n"
9973 const StringTemplate decoration
9975 "OpDecorate %ra_${tt} ArrayStride ${tt_stride}\n"
9976 "OpMemberDecorate %SSBO16 0 Offset 0\n"
9977 "OpDecorate %SSBO16 BufferBlock\n"
9978 "OpDecorate %ssbo_src DescriptorSet 0\n"
9979 "OpDecorate %ssbo_src Binding 0\n"
9980 "OpDecorate %ssbo_dst DescriptorSet 0\n"
9981 "OpDecorate %ssbo_dst Binding 1\n"
9984 const StringTemplate testFun
9986 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
9987 " %param = OpFunctionParameter %v4f32\n"
9988 " %entry = OpLabel\n"
9990 " %i = OpVariable %fp_i32 Function\n"
9991 " OpStore %i %c_i32_0\n"
9994 " %loop = OpLabel\n"
9995 " %i_cmp = OpLoad %i32 %i\n"
9996 " %lt = OpSLessThan %bool %i_cmp %c_i32_ndp\n"
9997 " OpLoopMerge %merge %next None\n"
9998 " OpBranchConditional %lt %write %merge\n"
10000 " %write = OpLabel\n"
10001 " %ndx = OpLoad %i32 %i\n"
10003 " %src = OpAccessChain %up_${tt} %ssbo_src %c_i32_0 %ndx\n"
10004 " %val_src = OpLoad %${tt} %src\n"
10006 " %val_dst = OpFunctionCall %${tt} %pass_fun %val_src\n"
10007 " %dst = OpAccessChain %up_${tt} %ssbo_dst %c_i32_0 %ndx\n"
10008 " OpStore %dst %val_dst\n"
10009 " OpBranch %next\n"
10011 " %next = OpLabel\n"
10012 " %i_cur = OpLoad %i32 %i\n"
10013 " %i_new = OpIAdd %i32 %i_cur %c_i32_1\n"
10014 " OpStore %i %i_new\n"
10015 " OpBranch %loop\n"
10017 " %merge = OpLabel\n"
10018 " OpReturnValue %param\n"
10022 " %pass_fun = OpFunction %${tt} None %${tt}_fun\n"
10023 " %param0 = OpFunctionParameter %${tt}\n"
10024 " %entry_pf = OpLabel\n"
10025 " %res0 = OpFAdd %${tt} %param0 %c_${tt}_0\n"
10026 " OpReturnValue %res0\n"
10030 for (deUint32 testTypeIdx = 0; testTypeIdx < DE_LENGTH_OF_ARRAY(testTypes); ++testTypeIdx)
10032 const TestType& testType = testTypes[testTypeIdx];
10033 const string testName = testType.typeName;
10034 const deUint32 itemsPerType = testType.typeComponents;
10035 const size_t iterations = float16InputData.size() / itemsPerType;
10036 const size_t typeStride = itemsPerType * sizeof(deFloat16);
10037 SpecResource specResource;
10038 map<string, string> specs;
10039 VulkanFeatures features;
10040 vector<string> extensions;
10042 specs["cap"] = "StorageUniformBufferBlock16";
10043 specs["num_data_points"] = de::toString(iterations);
10044 specs["tt"] = testType.typeName;
10045 specs["tt_stride"] = de::toString(typeStride);
10046 specs["type_decls"] = testType.typeDecls;
10048 fragments["extension"] = "OpExtension \"SPV_KHR_16bit_storage\"";
10049 fragments["capability"] = capabilities.specialize(specs);
10050 fragments["decoration"] = decoration.specialize(specs);
10051 fragments["pre_main"] = preMain.specialize(specs);
10052 fragments["testfun"] = testFun.specialize(specs);
10054 specResource.inputs.push_back(Resource(BufferSp(new Float16Buffer(float16InputData)), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
10055 specResource.outputs.push_back(Resource(BufferSp(new Float16Buffer(float16OutputDummy)), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
10056 specResource.verifyIO = compareFP16FunctionSetFunc;
10058 extensions.push_back("VK_KHR_16bit_storage");
10059 extensions.push_back("VK_KHR_shader_float16_int8");
10061 features.ext16BitStorage = EXT16BITSTORAGEFEATURES_UNIFORM_BUFFER_BLOCK;
10062 features.extFloat16Int8 = EXTFLOAT16INT8FEATURES_FLOAT16;
10064 finalizeTestsCreation(specResource, fragments, testCtx, *testGroup.get(), testName, features, extensions, IVec3(1, 1, 1));
10067 return testGroup.release();
10070 struct getV_ { deUint32 inline operator()(deUint32 v) const { return v; } getV_(){} };
10071 struct getV0 { deUint32 inline operator()(deUint32 v) const { return v & (~1); } getV0(){} };
10072 struct getV1 { deUint32 inline operator()(deUint32 v) const { return v | ( 1); } getV1(){} };
10074 template<deUint32 R, deUint32 N>
10075 inline static deUint32 getOffset(deUint32 x, deUint32 y, deUint32 n)
10077 return N * ((R * y) + x) + n;
10080 template<deUint32 R, deUint32 N, class X0, class X1, class Y0, class Y1>
10083 float operator() (const deFloat16* data, deUint32 x, deUint32 y, deUint32 n, deUint32 flavor) const
10085 DE_STATIC_ASSERT(R%2 == 0);
10086 DE_ASSERT(flavor == 0);
10093 const deFloat16 v0 = data[getOffset<R, N>(x0(x), y0(y), n)];
10094 const deFloat16 v1 = data[getOffset<R, N>(x1(x), y1(y), n)];
10095 const tcu::Float16 f0 = tcu::Float16(v0);
10096 const tcu::Float16 f1 = tcu::Float16(v1);
10097 const float d0 = f0.asFloat();
10098 const float d1 = f1.asFloat();
10099 const float d = d1 - d0;
10107 template<deUint32 F, class Class0, class Class1>
10110 float operator() (const deFloat16* data, deUint32 x, deUint32 y, deUint32 n, deUint32 flavor) const
10112 DE_ASSERT(flavor < F);
10118 return c(data, x, y, n, flavor);
10124 return c(data, x, y, n, flavor - 1);
10131 template<class FineX0, class FineX1, class FineY0, class FineY1>
10132 struct calcWidthOf4
10134 float operator() (const deFloat16* data, deUint32 x, deUint32 y, deUint32 n, deUint32 flavor) const
10136 DE_ASSERT(flavor < 4);
10138 const deUint32 flavorX = (flavor & 1) == 0 ? 0 : 1;
10139 const deUint32 flavorY = (flavor & 2) == 0 ? 0 : 1;
10140 const getFOneOf<2, FineX0, FineX1> cx;
10141 const getFOneOf<2, FineY0, FineY1> cy;
10144 v += fabsf(cx(data, x, y, n, flavorX));
10145 v += fabsf(cy(data, x, y, n, flavorY));
10153 template<deUint32 R, deUint32 N, class Derivative>
10154 bool compareDerivativeWithFlavor (const deFloat16* inputAsFP16, const deFloat16* outputAsFP16, deUint32 flavor, std::string& error)
10156 const deUint32 numDataPointsByAxis = R;
10157 const Derivative derivativeFunc;
10159 for (deUint32 y = 0; y < numDataPointsByAxis; ++y)
10160 for (deUint32 x = 0; x < numDataPointsByAxis; ++x)
10161 for (deUint32 n = 0; n < N; ++n)
10163 const float expectedFloat = derivativeFunc(inputAsFP16, x, y, n, flavor);
10164 deFloat16 expected = deFloat32To16Round(expectedFloat, DE_ROUNDINGMODE_TO_NEAREST_EVEN);
10165 const deFloat16 output = outputAsFP16[getOffset<R, N>(x, y, n)];
10167 bool reportError = !compare16BitFloat(expected, output, error);
10171 expected = deFloat32To16Round(expectedFloat, DE_ROUNDINGMODE_TO_ZERO);
10172 reportError = !compare16BitFloat(expected, output, error);
10177 error = "subcase at " + de::toString(x) + "," + de::toString(y) + "," + de::toString(n) + ": " + error;
10186 template<deUint32 R, deUint32 N, deUint32 FLAVOUR_COUNT, class Derivative>
10187 bool compareDerivative (const std::vector<Resource>& inputs, const vector<AllocationSp>& outputAllocs, const std::vector<Resource>&, TestLog& log)
10189 if (inputs.size() != 1 || outputAllocs.size() != 1)
10192 deUint32 successfulRuns = FLAVOUR_COUNT;
10193 std::string results[FLAVOUR_COUNT];
10194 vector<deUint8> inputBytes;
10196 inputs[0].getBytes(inputBytes);
10198 const deFloat16* inputAsFP16 = reinterpret_cast<deFloat16* const>(&inputBytes.front());
10199 const deFloat16* outputAsFP16 = static_cast<deFloat16*>(outputAllocs[0]->getHostPtr());
10201 DE_ASSERT(inputBytes.size() == R * R * N * sizeof(deFloat16));
10203 for (deUint32 flavor = 0; flavor < FLAVOUR_COUNT; ++flavor)
10204 if (compareDerivativeWithFlavor<R, N, Derivative> (inputAsFP16, outputAsFP16, flavor, results[flavor]))
10213 if (successfulRuns == 0)
10214 for (deUint32 flavor = 0; flavor < FLAVOUR_COUNT; flavor++)
10215 log << TestLog::Message << "At flavor #" << flavor << " " << results[flavor] << TestLog::EndMessage;
10217 return successfulRuns > 0;
10220 template<deUint32 R, deUint32 N>
10221 tcu::TestCaseGroup* createDerivativeTests (tcu::TestContext& testCtx)
10223 typedef getFDelta<R, N, getV0, getV1, getV_, getV_> getFDxFine;
10224 typedef getFDelta<R, N, getV_, getV_, getV0, getV1> getFDyFine;
10226 typedef getFDelta<R, N, getV0, getV1, getV0, getV0> getFdxCoarse0;
10227 typedef getFDelta<R, N, getV0, getV1, getV1, getV1> getFdxCoarse1;
10228 typedef getFDelta<R, N, getV0, getV0, getV0, getV1> getFdyCoarse0;
10229 typedef getFDelta<R, N, getV1, getV1, getV0, getV1> getFdyCoarse1;
10230 typedef getFOneOf<2, getFdxCoarse0, getFdxCoarse1> getFDxCoarse;
10231 typedef getFOneOf<2, getFdyCoarse0, getFdyCoarse1> getFDyCoarse;
10233 typedef calcWidthOf4<getFDxFine, getFDxFine, getFDyFine, getFDyFine> getFWidthFine;
10234 typedef calcWidthOf4<getFdxCoarse0, getFdxCoarse1, getFdyCoarse0, getFdyCoarse1> getFWidthCoarse;
10236 typedef getFOneOf<3, getFDxFine, getFDxCoarse> getFDx;
10237 typedef getFOneOf<3, getFDyFine, getFDyCoarse> getFDy;
10238 typedef getFOneOf<5, getFWidthFine, getFWidthCoarse> getFWidth;
10240 const std::string testGroupName (std::string("derivative_") + de::toString(N));
10241 de::MovePtr<tcu::TestCaseGroup> testGroup (new tcu::TestCaseGroup(testCtx, testGroupName.c_str(), "Derivative instruction tests"));
10243 de::Random rnd (deStringHash(testGroup->getName()));
10244 const deUint32 numDataPointsByAxis = R;
10245 const deUint32 numDataPoints = N * numDataPointsByAxis * numDataPointsByAxis;
10246 vector<deFloat16> float16InputX;
10247 vector<deFloat16> float16InputY;
10248 vector<deFloat16> float16InputW;
10249 vector<deFloat16> float16OutputDummy (numDataPoints, 0);
10250 RGBA defaultColors[4];
10252 getDefaultColors(defaultColors);
10254 float16InputX.reserve(numDataPoints);
10255 for (deUint32 y = 0; y < numDataPointsByAxis; ++y)
10256 for (deUint32 x = 0; x < numDataPointsByAxis; ++x)
10257 for (deUint32 n = 0; n < N; ++n)
10259 const float arg = static_cast<float>(2 * DE_PI) * static_cast<float>(x * (n + 1)) / static_cast<float>(1 * numDataPointsByAxis);
10262 float16InputX.push_back(tcu::Float16(sin(arg)).bits());
10264 float16InputX.push_back(tcu::Float16(cos(arg)).bits());
10267 float16InputY.reserve(numDataPoints);
10268 for (deUint32 y = 0; y < numDataPointsByAxis; ++y)
10269 for (deUint32 x = 0; x < numDataPointsByAxis; ++x)
10270 for (deUint32 n = 0; n < N; ++n)
10272 const float arg = static_cast<float>(2 * DE_PI) * static_cast<float>(y * (n + 1)) / static_cast<float>(1 * numDataPointsByAxis);
10275 float16InputY.push_back(tcu::Float16(sin(arg)).bits());
10277 float16InputY.push_back(tcu::Float16(cos(arg)).bits());
10280 const deFloat16 testNumbers[] =
10282 tcu::Float16( 2.0 ).bits(),
10283 tcu::Float16( 4.0 ).bits(),
10284 tcu::Float16( 8.0 ).bits(),
10285 tcu::Float16( 16.0 ).bits(),
10286 tcu::Float16( 32.0 ).bits(),
10287 tcu::Float16( 64.0 ).bits(),
10288 tcu::Float16( 128.0).bits(),
10289 tcu::Float16( 256.0).bits(),
10290 tcu::Float16( 512.0).bits(),
10291 tcu::Float16(-2.0 ).bits(),
10292 tcu::Float16(-4.0 ).bits(),
10293 tcu::Float16(-8.0 ).bits(),
10294 tcu::Float16(-16.0 ).bits(),
10295 tcu::Float16(-32.0 ).bits(),
10296 tcu::Float16(-64.0 ).bits(),
10297 tcu::Float16(-128.0).bits(),
10298 tcu::Float16(-256.0).bits(),
10299 tcu::Float16(-512.0).bits(),
10302 float16InputW.reserve(numDataPoints);
10303 for (deUint32 y = 0; y < numDataPointsByAxis; ++y)
10304 for (deUint32 x = 0; x < numDataPointsByAxis; ++x)
10305 for (deUint32 n = 0; n < N; ++n)
10306 float16InputW.push_back(testNumbers[rnd.getInt(0, DE_LENGTH_OF_ARRAY(testNumbers) - 1)]);
10310 const char* opCode;
10311 vector<deFloat16>& inputData;
10312 VerifyIOFunc verifyFunc;
10315 const TestOp testOps[] =
10317 { "OpDPdxFine" , float16InputX , compareDerivative<R, N, 1, getFDxFine > },
10318 { "OpDPdyFine" , float16InputY , compareDerivative<R, N, 1, getFDyFine > },
10319 { "OpFwidthFine" , float16InputW , compareDerivative<R, N, 1, getFWidthFine > },
10320 { "OpDPdxCoarse" , float16InputX , compareDerivative<R, N, 3, getFDx > },
10321 { "OpDPdyCoarse" , float16InputY , compareDerivative<R, N, 3, getFDy > },
10322 { "OpFwidthCoarse" , float16InputW , compareDerivative<R, N, 5, getFWidth > },
10323 { "OpDPdx" , float16InputX , compareDerivative<R, N, 3, getFDx > },
10324 { "OpDPdy" , float16InputY , compareDerivative<R, N, 3, getFDy > },
10325 { "OpFwidth" , float16InputW , compareDerivative<R, N, 5, getFWidth > },
10330 const deUint32 typeComponents;
10331 const char* typeName;
10332 const char* typeDecls;
10335 const TestType testTypes[] =
10345 " %v2f16 = OpTypeVector %f16 2\n"
10350 " %v4f16 = OpTypeVector %f16 4\n"
10354 const deUint32 testTypeNdx = (N == 1) ? 0
10357 : DE_LENGTH_OF_ARRAY(testTypes);
10358 const TestType& testType = testTypes[testTypeNdx];
10360 DE_ASSERT(testTypeNdx < DE_LENGTH_OF_ARRAY(testTypes));
10361 DE_ASSERT(testType.typeComponents == N);
10363 const StringTemplate preMain
10365 "%c_i32_ndp = OpConstant %i32 ${num_data_points}\n"
10366 " %c_u32_xw = OpConstant %u32 ${items_by_x}\n"
10367 " %f16 = OpTypeFloat 16\n"
10369 " %up_${tt} = OpTypePointer Uniform %${tt}\n"
10370 " %ra_${tt} = OpTypeArray %${tt} %c_i32_ndp\n"
10371 " %SSBO16 = OpTypeStruct %ra_${tt}\n"
10372 "%up_SSBO16 = OpTypePointer Uniform %SSBO16\n"
10373 " %ssbo_src = OpVariable %up_SSBO16 Uniform\n"
10374 " %ssbo_dst = OpVariable %up_SSBO16 Uniform\n"
10377 const StringTemplate decoration
10379 "OpDecorate %ra_${tt} ArrayStride ${tt_stride}\n"
10380 "OpMemberDecorate %SSBO16 0 Offset 0\n"
10381 "OpDecorate %SSBO16 BufferBlock\n"
10382 "OpDecorate %ssbo_src DescriptorSet 0\n"
10383 "OpDecorate %ssbo_src Binding 0\n"
10384 "OpDecorate %ssbo_dst DescriptorSet 0\n"
10385 "OpDecorate %ssbo_dst Binding 1\n"
10388 const StringTemplate testFun
10390 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
10391 " %param = OpFunctionParameter %v4f32\n"
10392 " %entry = OpLabel\n"
10394 " %loc_x_c = OpAccessChain %ip_f32 %BP_gl_FragCoord %c_i32_0\n"
10395 " %loc_y_c = OpAccessChain %ip_f32 %BP_gl_FragCoord %c_i32_1\n"
10396 " %x_c = OpLoad %f32 %loc_x_c\n"
10397 " %y_c = OpLoad %f32 %loc_y_c\n"
10398 " %x_idx = OpConvertFToU %u32 %x_c\n"
10399 " %y_idx = OpConvertFToU %u32 %y_c\n"
10400 " %ndx_y = OpIMul %u32 %y_idx %c_u32_xw\n"
10401 " %ndx = OpIAdd %u32 %ndx_y %x_idx\n"
10403 " %src = OpAccessChain %up_${tt} %ssbo_src %c_i32_0 %ndx\n"
10404 " %val_src = OpLoad %${tt} %src\n"
10405 " %val_dst = ${op_code} %${tt} %val_src\n"
10406 " %dst = OpAccessChain %up_${tt} %ssbo_dst %c_i32_0 %ndx\n"
10407 " OpStore %dst %val_dst\n"
10408 " OpBranch %merge\n"
10410 " %merge = OpLabel\n"
10411 " OpReturnValue %param\n"
10416 for (deUint32 testOpsIdx = 0; testOpsIdx < DE_LENGTH_OF_ARRAY(testOps); ++testOpsIdx)
10418 const TestOp& testOp = testOps[testOpsIdx];
10419 const string testName = de::toLower(string(testOp.opCode));
10420 const size_t typeStride = N * sizeof(deFloat16);
10421 GraphicsResources specResource;
10422 map<string, string> specs;
10423 VulkanFeatures features;
10424 vector<string> extensions;
10425 map<string, string> fragments;
10426 SpecConstants noSpecConstants;
10427 PushConstants noPushConstants;
10428 GraphicsInterfaces noInterfaces;
10429 vector<string> noFeatures;
10431 specs["op_code"] = testOp.opCode;
10432 specs["num_data_points"] = de::toString(testOp.inputData.size() / N);
10433 specs["items_by_x"] = de::toString(numDataPointsByAxis);
10434 specs["tt"] = testType.typeName;
10435 specs["tt_stride"] = de::toString(typeStride);
10436 specs["type_decls"] = testType.typeDecls;
10438 fragments["extension"] = "OpExtension \"SPV_KHR_16bit_storage\"";
10439 fragments["capability"] = "OpCapability DerivativeControl\nOpCapability StorageUniformBufferBlock16\n";
10440 fragments["decoration"] = decoration.specialize(specs);
10441 fragments["pre_main"] = preMain.specialize(specs);
10442 fragments["testfun"] = testFun.specialize(specs);
10444 specResource.inputs.push_back(Resource(BufferSp(new Float16Buffer(testOp.inputData)), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
10445 specResource.outputs.push_back(Resource(BufferSp(new Float16Buffer(float16OutputDummy)), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
10446 specResource.verifyIO = testOp.verifyFunc;
10448 extensions.push_back("VK_KHR_16bit_storage");
10449 extensions.push_back("VK_KHR_shader_float16_int8");
10451 features.extFloat16Int8 = EXTFLOAT16INT8FEATURES_FLOAT16;
10452 features.ext16BitStorage = EXT16BITSTORAGEFEATURES_UNIFORM_BUFFER_BLOCK;
10454 createTestForStage(VK_SHADER_STAGE_FRAGMENT_BIT, testName.c_str(), defaultColors, defaultColors, fragments, noSpecConstants,
10455 noPushConstants, specResource, noInterfaces, extensions, noFeatures, features, testGroup.get(), QP_TEST_RESULT_FAIL, string(), true);
10458 return testGroup.release();
10461 bool compareFP16VectorExtractFunc (const std::vector<Resource>& inputs, const vector<AllocationSp>& outputAllocs, const std::vector<Resource>&, TestLog& log)
10463 if (inputs.size() != 2 || outputAllocs.size() != 1)
10466 vector<deUint8> input1Bytes;
10467 vector<deUint8> input2Bytes;
10469 inputs[0].getBytes(input1Bytes);
10470 inputs[1].getBytes(input2Bytes);
10472 DE_ASSERT(input1Bytes.size() > 0);
10473 DE_ASSERT(input2Bytes.size() > 0);
10474 DE_ASSERT(input2Bytes.size() % sizeof(deUint32) == 0);
10476 const size_t iterations = input2Bytes.size() / sizeof(deUint32);
10477 const size_t components = input1Bytes.size() / (sizeof(deFloat16) * iterations);
10478 const deFloat16* const input1AsFP16 = (const deFloat16*)&input1Bytes[0];
10479 const deUint32* const inputIndices = (const deUint32*)&input2Bytes[0];
10480 const deFloat16* const outputAsFP16 = (const deFloat16*)outputAllocs[0]->getHostPtr();
10483 DE_ASSERT(components == 2 || components == 4);
10484 DE_ASSERT(input1Bytes.size() == iterations * components * sizeof(deFloat16));
10486 for (size_t idx = 0; idx < iterations; ++idx)
10488 const deUint32 componentNdx = inputIndices[idx];
10490 DE_ASSERT(componentNdx < components);
10492 const deFloat16 expected = input1AsFP16[components * idx + componentNdx];
10494 if (!compare16BitFloat(expected, outputAsFP16[idx], error))
10496 log << TestLog::Message << "At " << idx << error << TestLog::EndMessage;
10505 template<class SpecResource>
10506 tcu::TestCaseGroup* createFloat16VectorExtractSet (tcu::TestContext& testCtx)
10508 de::MovePtr<tcu::TestCaseGroup> testGroup (new tcu::TestCaseGroup(testCtx, "opvectorextractdynamic", "OpVectorExtractDynamic tests"));
10510 de::Random rnd (deStringHash(testGroup->getName()));
10511 const deUint32 numDataPoints = 256;
10512 const vector<deFloat16> float16InputData = getFloat16s(rnd, numDataPoints);
10513 const vector<deFloat16> float16OutputDummy (float16InputData.size(), 0);
10517 const deUint32 typeComponents;
10518 const size_t typeStride;
10519 const char* typeName;
10520 const char* typeDecls;
10523 const TestType testTypes[] =
10527 2 * sizeof(deFloat16),
10529 " %v2f16 = OpTypeVector %f16 2\n"
10533 4 * sizeof(deFloat16),
10535 " %v3f16 = OpTypeVector %f16 3\n"
10539 4 * sizeof(deFloat16),
10541 " %v4f16 = OpTypeVector %f16 4\n"
10545 const StringTemplate preMain
10547 " %c_i32_ndp = OpConstant %i32 ${num_data_points}\n"
10548 " %f16 = OpTypeFloat 16\n"
10552 " %up_${tt} = OpTypePointer Uniform %${tt}\n"
10553 " %ra_${tt} = OpTypeArray %${tt} %c_i32_ndp\n"
10554 " %SSBO_SRC = OpTypeStruct %ra_${tt}\n"
10555 "%up_SSBO_SRC = OpTypePointer Uniform %SSBO_SRC\n"
10557 " %up_u32 = OpTypePointer Uniform %u32\n"
10558 " %ra_u32 = OpTypeArray %u32 %c_i32_ndp\n"
10559 " %SSBO_IDX = OpTypeStruct %ra_u32\n"
10560 "%up_SSBO_IDX = OpTypePointer Uniform %SSBO_IDX\n"
10562 " %up_f16 = OpTypePointer Uniform %f16\n"
10563 " %ra_f16 = OpTypeArray %f16 %c_i32_ndp\n"
10564 " %SSBO_DST = OpTypeStruct %ra_f16\n"
10565 "%up_SSBO_DST = OpTypePointer Uniform %SSBO_DST\n"
10567 " %ssbo_src = OpVariable %up_SSBO_SRC Uniform\n"
10568 " %ssbo_idx = OpVariable %up_SSBO_IDX Uniform\n"
10569 " %ssbo_dst = OpVariable %up_SSBO_DST Uniform\n"
10572 const StringTemplate decoration
10574 "OpDecorate %ra_${tt} ArrayStride ${tt_stride}\n"
10575 "OpMemberDecorate %SSBO_SRC 0 Offset 0\n"
10576 "OpDecorate %SSBO_SRC BufferBlock\n"
10577 "OpDecorate %ssbo_src DescriptorSet 0\n"
10578 "OpDecorate %ssbo_src Binding 0\n"
10580 "OpDecorate %ra_u32 ArrayStride 4\n"
10581 "OpMemberDecorate %SSBO_IDX 0 Offset 0\n"
10582 "OpDecorate %SSBO_IDX BufferBlock\n"
10583 "OpDecorate %ssbo_idx DescriptorSet 0\n"
10584 "OpDecorate %ssbo_idx Binding 1\n"
10586 "OpDecorate %ra_f16 ArrayStride 2\n"
10587 "OpMemberDecorate %SSBO_DST 0 Offset 0\n"
10588 "OpDecorate %SSBO_DST BufferBlock\n"
10589 "OpDecorate %ssbo_dst DescriptorSet 0\n"
10590 "OpDecorate %ssbo_dst Binding 2\n"
10593 const StringTemplate testFun
10595 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
10596 " %param = OpFunctionParameter %v4f32\n"
10597 " %entry = OpLabel\n"
10599 " %i = OpVariable %fp_i32 Function\n"
10600 " OpStore %i %c_i32_0\n"
10602 " %will_run = OpFunctionCall %bool %isUniqueIdZero\n"
10603 " OpSelectionMerge %end_if None\n"
10604 " OpBranchConditional %will_run %run_test %end_if\n"
10606 " %run_test = OpLabel\n"
10607 " OpBranch %loop\n"
10609 " %loop = OpLabel\n"
10610 " %i_cmp = OpLoad %i32 %i\n"
10611 " %lt = OpSLessThan %bool %i_cmp %c_i32_ndp\n"
10612 " OpLoopMerge %merge %next None\n"
10613 " OpBranchConditional %lt %write %merge\n"
10615 " %write = OpLabel\n"
10616 " %ndx = OpLoad %i32 %i\n"
10618 " %src = OpAccessChain %up_${tt} %ssbo_src %c_i32_0 %ndx\n"
10619 " %val_src = OpLoad %${tt} %src\n"
10621 " %src_idx = OpAccessChain %up_u32 %ssbo_idx %c_i32_0 %ndx\n"
10622 " %val_idx = OpLoad %u32 %src_idx\n"
10624 " %val_dst = OpVectorExtractDynamic %f16 %val_src %val_idx\n"
10625 " %dst = OpAccessChain %up_f16 %ssbo_dst %c_i32_0 %ndx\n"
10627 " OpStore %dst %val_dst\n"
10628 " OpBranch %next\n"
10630 " %next = OpLabel\n"
10631 " %i_cur = OpLoad %i32 %i\n"
10632 " %i_new = OpIAdd %i32 %i_cur %c_i32_1\n"
10633 " OpStore %i %i_new\n"
10634 " OpBranch %loop\n"
10636 " %merge = OpLabel\n"
10637 " OpBranch %end_if\n"
10638 " %end_if = OpLabel\n"
10639 " OpReturnValue %param\n"
10644 for (deUint32 testTypeIdx = 0; testTypeIdx < DE_LENGTH_OF_ARRAY(testTypes); ++testTypeIdx)
10646 const TestType& testType = testTypes[testTypeIdx];
10647 const string testName = testType.typeName;
10648 const size_t itemsPerType = testType.typeStride / sizeof(deFloat16);
10649 const size_t iterations = float16InputData.size() / itemsPerType;
10650 SpecResource specResource;
10651 map<string, string> specs;
10652 VulkanFeatures features;
10653 vector<deUint32> inputDataNdx;
10654 map<string, string> fragments;
10655 vector<string> extensions;
10657 for (deUint32 ndx = 0; ndx < iterations; ++ndx)
10658 inputDataNdx.push_back(rnd.getUint32() % testType.typeComponents);
10660 specs["num_data_points"] = de::toString(iterations);
10661 specs["tt"] = testType.typeName;
10662 specs["tt_stride"] = de::toString(testType.typeStride);
10663 specs["type_decl"] = testType.typeDecls;
10665 fragments["extension"] = "OpExtension \"SPV_KHR_16bit_storage\"";
10666 fragments["capability"] = "OpCapability StorageUniformBufferBlock16\n";
10667 fragments["decoration"] = decoration.specialize(specs);
10668 fragments["pre_main"] = preMain.specialize(specs);
10669 fragments["testfun"] = testFun.specialize(specs);
10671 specResource.inputs.push_back(Resource(BufferSp(new Float16Buffer(float16InputData)), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
10672 specResource.inputs.push_back(Resource(BufferSp(new Uint32Buffer(inputDataNdx)), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
10673 specResource.outputs.push_back(Resource(BufferSp(new Float16Buffer(float16OutputDummy)), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
10674 specResource.verifyIO = compareFP16VectorExtractFunc;
10676 extensions.push_back("VK_KHR_16bit_storage");
10677 extensions.push_back("VK_KHR_shader_float16_int8");
10679 features.extFloat16Int8 = EXTFLOAT16INT8FEATURES_FLOAT16;
10680 features.ext16BitStorage = EXT16BITSTORAGEFEATURES_UNIFORM_BUFFER_BLOCK;
10682 finalizeTestsCreation(specResource, fragments, testCtx, *testGroup.get(), testName, features, extensions, IVec3(1, 1, 1));
10685 return testGroup.release();
10688 template<deUint32 COMPONENTS_COUNT, deUint32 REPLACEMENT>
10689 bool compareFP16VectorInsertFunc (const std::vector<Resource>& inputs, const vector<AllocationSp>& outputAllocs, const std::vector<Resource>&, TestLog& log)
10691 if (inputs.size() != 2 || outputAllocs.size() != 1)
10694 vector<deUint8> input1Bytes;
10695 vector<deUint8> input2Bytes;
10697 inputs[0].getBytes(input1Bytes);
10698 inputs[1].getBytes(input2Bytes);
10700 DE_ASSERT(input1Bytes.size() > 0);
10701 DE_ASSERT(input2Bytes.size() > 0);
10702 DE_ASSERT(input2Bytes.size() % sizeof(deUint32) == 0);
10704 const size_t iterations = input2Bytes.size() / sizeof(deUint32);
10705 const size_t componentsStride = input1Bytes.size() / (sizeof(deFloat16) * iterations);
10706 const deFloat16* const input1AsFP16 = (const deFloat16*)&input1Bytes[0];
10707 const deUint32* const inputIndices = (const deUint32*)&input2Bytes[0];
10708 const deFloat16* const outputAsFP16 = (const deFloat16*)outputAllocs[0]->getHostPtr();
10709 const deFloat16 magic = tcu::Float16(float(REPLACEMENT)).bits();
10712 DE_ASSERT(componentsStride == 2 || componentsStride == 4);
10713 DE_ASSERT(input1Bytes.size() == iterations * componentsStride * sizeof(deFloat16));
10715 for (size_t idx = 0; idx < iterations; ++idx)
10717 const deFloat16* inputVec = &input1AsFP16[componentsStride * idx];
10718 const deFloat16* outputVec = &outputAsFP16[componentsStride * idx];
10719 const deUint32 replacedCompNdx = inputIndices[idx];
10721 DE_ASSERT(replacedCompNdx < COMPONENTS_COUNT);
10723 for (size_t compNdx = 0; compNdx < COMPONENTS_COUNT; ++compNdx)
10725 const deFloat16 expected = (compNdx == replacedCompNdx) ? magic : inputVec[compNdx];
10727 if (!compare16BitFloat(expected, outputVec[compNdx], error))
10729 log << TestLog::Message << "At " << idx << "[" << compNdx << "]: " << error << TestLog::EndMessage;
10739 template<class SpecResource>
10740 tcu::TestCaseGroup* createFloat16VectorInsertSet (tcu::TestContext& testCtx)
10742 de::MovePtr<tcu::TestCaseGroup> testGroup (new tcu::TestCaseGroup(testCtx, "opvectorinsertdynamic", "OpVectorInsertDynamic tests"));
10744 de::Random rnd (deStringHash(testGroup->getName()));
10745 const deUint32 replacement = 42;
10746 const deUint32 numDataPoints = 256;
10747 const vector<deFloat16> float16InputData = getFloat16s(rnd, numDataPoints);
10748 const vector<deFloat16> float16OutputDummy (float16InputData.size(), 0);
10752 const deUint32 typeComponents;
10753 const size_t typeStride;
10754 const char* typeName;
10755 const char* typeDecls;
10756 VerifyIOFunc verifyIOFunc;
10759 const TestType testTypes[] =
10763 2 * sizeof(deFloat16),
10765 " %v2f16 = OpTypeVector %f16 2\n",
10766 compareFP16VectorInsertFunc<2, replacement>
10770 4 * sizeof(deFloat16),
10772 " %v3f16 = OpTypeVector %f16 3\n",
10773 compareFP16VectorInsertFunc<3, replacement>
10777 4 * sizeof(deFloat16),
10779 " %v4f16 = OpTypeVector %f16 4\n",
10780 compareFP16VectorInsertFunc<4, replacement>
10784 const StringTemplate preMain
10786 " %c_i32_ndp = OpConstant %i32 ${num_data_points}\n"
10787 " %f16 = OpTypeFloat 16\n"
10788 " %c_f16_ins = OpConstant %f16 ${replacement}\n"
10792 " %up_${tt} = OpTypePointer Uniform %${tt}\n"
10793 " %ra_${tt} = OpTypeArray %${tt} %c_i32_ndp\n"
10794 " %SSBO_SRC = OpTypeStruct %ra_${tt}\n"
10795 "%up_SSBO_SRC = OpTypePointer Uniform %SSBO_SRC\n"
10797 " %up_u32 = OpTypePointer Uniform %u32\n"
10798 " %ra_u32 = OpTypeArray %u32 %c_i32_ndp\n"
10799 " %SSBO_IDX = OpTypeStruct %ra_u32\n"
10800 "%up_SSBO_IDX = OpTypePointer Uniform %SSBO_IDX\n"
10802 " %SSBO_DST = OpTypeStruct %ra_${tt}\n"
10803 "%up_SSBO_DST = OpTypePointer Uniform %SSBO_DST\n"
10805 " %ssbo_src = OpVariable %up_SSBO_SRC Uniform\n"
10806 " %ssbo_idx = OpVariable %up_SSBO_IDX Uniform\n"
10807 " %ssbo_dst = OpVariable %up_SSBO_DST Uniform\n"
10810 const StringTemplate decoration
10812 "OpDecorate %ra_${tt} ArrayStride ${tt_stride}\n"
10813 "OpMemberDecorate %SSBO_SRC 0 Offset 0\n"
10814 "OpDecorate %SSBO_SRC BufferBlock\n"
10815 "OpDecorate %ssbo_src DescriptorSet 0\n"
10816 "OpDecorate %ssbo_src Binding 0\n"
10818 "OpDecorate %ra_u32 ArrayStride 4\n"
10819 "OpMemberDecorate %SSBO_IDX 0 Offset 0\n"
10820 "OpDecorate %SSBO_IDX BufferBlock\n"
10821 "OpDecorate %ssbo_idx DescriptorSet 0\n"
10822 "OpDecorate %ssbo_idx Binding 1\n"
10824 "OpMemberDecorate %SSBO_DST 0 Offset 0\n"
10825 "OpDecorate %SSBO_DST BufferBlock\n"
10826 "OpDecorate %ssbo_dst DescriptorSet 0\n"
10827 "OpDecorate %ssbo_dst Binding 2\n"
10830 const StringTemplate testFun
10832 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
10833 " %param = OpFunctionParameter %v4f32\n"
10834 " %entry = OpLabel\n"
10836 " %i = OpVariable %fp_i32 Function\n"
10837 " OpStore %i %c_i32_0\n"
10839 " %will_run = OpFunctionCall %bool %isUniqueIdZero\n"
10840 " OpSelectionMerge %end_if None\n"
10841 " OpBranchConditional %will_run %run_test %end_if\n"
10843 " %run_test = OpLabel\n"
10844 " OpBranch %loop\n"
10846 " %loop = OpLabel\n"
10847 " %i_cmp = OpLoad %i32 %i\n"
10848 " %lt = OpSLessThan %bool %i_cmp %c_i32_ndp\n"
10849 " OpLoopMerge %merge %next None\n"
10850 " OpBranchConditional %lt %write %merge\n"
10852 " %write = OpLabel\n"
10853 " %ndx = OpLoad %i32 %i\n"
10855 " %src = OpAccessChain %up_${tt} %ssbo_src %c_i32_0 %ndx\n"
10856 " %val_src = OpLoad %${tt} %src\n"
10858 " %src_idx = OpAccessChain %up_u32 %ssbo_idx %c_i32_0 %ndx\n"
10859 " %val_idx = OpLoad %u32 %src_idx\n"
10861 " %val_dst = OpVectorInsertDynamic %${tt} %val_src %c_f16_ins %val_idx\n"
10862 " %dst = OpAccessChain %up_${tt} %ssbo_dst %c_i32_0 %ndx\n"
10864 " OpStore %dst %val_dst\n"
10865 " OpBranch %next\n"
10867 " %next = OpLabel\n"
10868 " %i_cur = OpLoad %i32 %i\n"
10869 " %i_new = OpIAdd %i32 %i_cur %c_i32_1\n"
10870 " OpStore %i %i_new\n"
10871 " OpBranch %loop\n"
10873 " %merge = OpLabel\n"
10874 " OpBranch %end_if\n"
10875 " %end_if = OpLabel\n"
10876 " OpReturnValue %param\n"
10881 for (deUint32 testTypeIdx = 0; testTypeIdx < DE_LENGTH_OF_ARRAY(testTypes); ++testTypeIdx)
10883 const TestType& testType = testTypes[testTypeIdx];
10884 const string testName = testType.typeName;
10885 const size_t itemsPerType = testType.typeStride / sizeof(deFloat16);
10886 const size_t iterations = float16InputData.size() / itemsPerType;
10887 SpecResource specResource;
10888 map<string, string> specs;
10889 VulkanFeatures features;
10890 vector<deUint32> inputDataNdx;
10891 map<string, string> fragments;
10892 vector<string> extensions;
10894 for (deUint32 ndx = 0; ndx < iterations; ++ndx)
10895 inputDataNdx.push_back(rnd.getUint32() % testType.typeComponents);
10897 specs["num_data_points"] = de::toString(iterations);
10898 specs["tt"] = testType.typeName;
10899 specs["tt_stride"] = de::toString(testType.typeStride);
10900 specs["type_decl"] = testType.typeDecls;
10901 specs["replacement"] = de::toString(replacement);
10903 fragments["extension"] = "OpExtension \"SPV_KHR_16bit_storage\"";
10904 fragments["capability"] = "OpCapability StorageUniformBufferBlock16\n";
10905 fragments["decoration"] = decoration.specialize(specs);
10906 fragments["pre_main"] = preMain.specialize(specs);
10907 fragments["testfun"] = testFun.specialize(specs);
10909 specResource.inputs.push_back(Resource(BufferSp(new Float16Buffer(float16InputData)), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
10910 specResource.inputs.push_back(Resource(BufferSp(new Uint32Buffer(inputDataNdx)), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
10911 specResource.outputs.push_back(Resource(BufferSp(new Float16Buffer(float16OutputDummy)), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
10912 specResource.verifyIO = testType.verifyIOFunc;
10914 extensions.push_back("VK_KHR_16bit_storage");
10915 extensions.push_back("VK_KHR_shader_float16_int8");
10917 features.extFloat16Int8 = EXTFLOAT16INT8FEATURES_FLOAT16;
10918 features.ext16BitStorage = EXT16BITSTORAGEFEATURES_UNIFORM_BUFFER_BLOCK;
10920 finalizeTestsCreation(specResource, fragments, testCtx, *testGroup.get(), testName, features, extensions, IVec3(1, 1, 1));
10923 return testGroup.release();
10926 inline deFloat16 getShuffledComponent (const size_t iteration, const size_t componentNdx, const deFloat16* input1Vec, const deFloat16* input2Vec, size_t vec1Len, size_t vec2Len, bool& validate)
10928 const size_t compNdxCount = (vec1Len + vec2Len + 1);
10929 const size_t compNdxLimited = iteration % (compNdxCount * compNdxCount);
10932 switch (componentNdx)
10934 case 0: comp = compNdxLimited / compNdxCount; break;
10935 case 1: comp = compNdxLimited % compNdxCount; break;
10936 case 2: comp = 0; break;
10937 case 3: comp = 1; break;
10938 default: TCU_THROW(InternalError, "Impossible");
10941 if (comp >= vec1Len + vec2Len)
10949 return (comp < vec1Len) ? input1Vec[comp] : input2Vec[comp - vec1Len];
10953 template<deUint32 DST_COMPONENTS_COUNT, deUint32 SRC0_COMPONENTS_COUNT, deUint32 SRC1_COMPONENTS_COUNT>
10954 bool compareFP16VectorShuffleFunc (const std::vector<Resource>& inputs, const vector<AllocationSp>& outputAllocs, const std::vector<Resource>&, TestLog& log)
10956 DE_STATIC_ASSERT(DST_COMPONENTS_COUNT == 2 || DST_COMPONENTS_COUNT == 3 || DST_COMPONENTS_COUNT == 4);
10957 DE_STATIC_ASSERT(SRC0_COMPONENTS_COUNT == 2 || SRC0_COMPONENTS_COUNT == 3 || SRC0_COMPONENTS_COUNT == 4);
10958 DE_STATIC_ASSERT(SRC1_COMPONENTS_COUNT == 2 || SRC1_COMPONENTS_COUNT == 3 || SRC1_COMPONENTS_COUNT == 4);
10960 if (inputs.size() != 2 || outputAllocs.size() != 1)
10963 vector<deUint8> input1Bytes;
10964 vector<deUint8> input2Bytes;
10966 inputs[0].getBytes(input1Bytes);
10967 inputs[1].getBytes(input2Bytes);
10969 DE_ASSERT(input1Bytes.size() > 0);
10970 DE_ASSERT(input2Bytes.size() > 0);
10971 DE_ASSERT(input2Bytes.size() % sizeof(deFloat16) == 0);
10973 const size_t componentsStrideDst = (DST_COMPONENTS_COUNT == 3) ? 4 : DST_COMPONENTS_COUNT;
10974 const size_t componentsStrideSrc0 = (SRC0_COMPONENTS_COUNT == 3) ? 4 : SRC0_COMPONENTS_COUNT;
10975 const size_t componentsStrideSrc1 = (SRC1_COMPONENTS_COUNT == 3) ? 4 : SRC1_COMPONENTS_COUNT;
10976 const size_t iterations = input1Bytes.size() / (componentsStrideSrc0 * sizeof(deFloat16));
10977 const deFloat16* const input1AsFP16 = (const deFloat16*)&input1Bytes[0];
10978 const deFloat16* const input2AsFP16 = (const deFloat16*)&input2Bytes[0];
10979 const deFloat16* const outputAsFP16 = (const deFloat16*)outputAllocs[0]->getHostPtr();
10982 DE_ASSERT(input1Bytes.size() == iterations * componentsStrideSrc0 * sizeof(deFloat16));
10983 DE_ASSERT(input2Bytes.size() == iterations * componentsStrideSrc1 * sizeof(deFloat16));
10985 for (size_t idx = 0; idx < iterations; ++idx)
10987 const deFloat16* input1Vec = &input1AsFP16[componentsStrideSrc0 * idx];
10988 const deFloat16* input2Vec = &input2AsFP16[componentsStrideSrc1 * idx];
10989 const deFloat16* outputVec = &outputAsFP16[componentsStrideDst * idx];
10991 for (size_t compNdx = 0; compNdx < DST_COMPONENTS_COUNT; ++compNdx)
10993 bool validate = true;
10994 deFloat16 expected = getShuffledComponent(idx, compNdx, input1Vec, input2Vec, SRC0_COMPONENTS_COUNT, SRC1_COMPONENTS_COUNT, validate);
10996 if (validate && !compare16BitFloat(expected, outputVec[compNdx], error))
10998 log << TestLog::Message << "At " << idx << "[" << compNdx << "]: " << error << TestLog::EndMessage;
11008 VerifyIOFunc getFloat16VectorShuffleVerifyIOFunc (deUint32 dstComponentsCount, deUint32 src0ComponentsCount, deUint32 src1ComponentsCount)
11010 DE_ASSERT(dstComponentsCount <= 4);
11011 DE_ASSERT(src0ComponentsCount <= 4);
11012 DE_ASSERT(src1ComponentsCount <= 4);
11013 deUint32 funcCode = 100 * dstComponentsCount + 10 * src0ComponentsCount + src1ComponentsCount;
11017 case 222:return compareFP16VectorShuffleFunc<2, 2, 2>;
11018 case 223:return compareFP16VectorShuffleFunc<2, 2, 3>;
11019 case 224:return compareFP16VectorShuffleFunc<2, 2, 4>;
11020 case 232:return compareFP16VectorShuffleFunc<2, 3, 2>;
11021 case 233:return compareFP16VectorShuffleFunc<2, 3, 3>;
11022 case 234:return compareFP16VectorShuffleFunc<2, 3, 4>;
11023 case 242:return compareFP16VectorShuffleFunc<2, 4, 2>;
11024 case 243:return compareFP16VectorShuffleFunc<2, 4, 3>;
11025 case 244:return compareFP16VectorShuffleFunc<2, 4, 4>;
11026 case 322:return compareFP16VectorShuffleFunc<3, 2, 2>;
11027 case 323:return compareFP16VectorShuffleFunc<3, 2, 3>;
11028 case 324:return compareFP16VectorShuffleFunc<3, 2, 4>;
11029 case 332:return compareFP16VectorShuffleFunc<3, 3, 2>;
11030 case 333:return compareFP16VectorShuffleFunc<3, 3, 3>;
11031 case 334:return compareFP16VectorShuffleFunc<3, 3, 4>;
11032 case 342:return compareFP16VectorShuffleFunc<3, 4, 2>;
11033 case 343:return compareFP16VectorShuffleFunc<3, 4, 3>;
11034 case 344:return compareFP16VectorShuffleFunc<3, 4, 4>;
11035 case 422:return compareFP16VectorShuffleFunc<4, 2, 2>;
11036 case 423:return compareFP16VectorShuffleFunc<4, 2, 3>;
11037 case 424:return compareFP16VectorShuffleFunc<4, 2, 4>;
11038 case 432:return compareFP16VectorShuffleFunc<4, 3, 2>;
11039 case 433:return compareFP16VectorShuffleFunc<4, 3, 3>;
11040 case 434:return compareFP16VectorShuffleFunc<4, 3, 4>;
11041 case 442:return compareFP16VectorShuffleFunc<4, 4, 2>;
11042 case 443:return compareFP16VectorShuffleFunc<4, 4, 3>;
11043 case 444:return compareFP16VectorShuffleFunc<4, 4, 4>;
11044 default: TCU_THROW(InternalError, "Invalid number of components specified.");
11048 template<class SpecResource>
11049 tcu::TestCaseGroup* createFloat16VectorShuffleSet (tcu::TestContext& testCtx)
11051 de::MovePtr<tcu::TestCaseGroup> testGroup (new tcu::TestCaseGroup(testCtx, "opvectorshuffle", "OpVectorShuffle tests"));
11052 const int testSpecificSeed = deStringHash(testGroup->getName());
11053 const int seed = testCtx.getCommandLine().getBaseSeed() ^ testSpecificSeed;
11054 de::Random rnd (seed);
11055 const deUint32 numDataPoints = 128;
11056 map<string, string> fragments;
11060 const deUint32 typeComponents;
11061 const char* typeName;
11064 const TestType testTypes[] =
11080 const StringTemplate preMain
11082 " %c_i32_ndp = OpConstant %i32 ${num_data_points}\n"
11083 " %c_i32_cc = OpConstant %i32 ${case_count}\n"
11084 " %f16 = OpTypeFloat 16\n"
11085 " %v2f16 = OpTypeVector %f16 2\n"
11086 " %v3f16 = OpTypeVector %f16 3\n"
11087 " %v4f16 = OpTypeVector %f16 4\n"
11089 " %up_v2f16 = OpTypePointer Uniform %v2f16\n"
11090 " %ra_v2f16 = OpTypeArray %v2f16 %c_i32_ndp\n"
11091 " %SSBO_v2f16 = OpTypeStruct %ra_v2f16\n"
11092 "%up_SSBO_v2f16 = OpTypePointer Uniform %SSBO_v2f16\n"
11094 " %up_v3f16 = OpTypePointer Uniform %v3f16\n"
11095 " %ra_v3f16 = OpTypeArray %v3f16 %c_i32_ndp\n"
11096 " %SSBO_v3f16 = OpTypeStruct %ra_v3f16\n"
11097 "%up_SSBO_v3f16 = OpTypePointer Uniform %SSBO_v3f16\n"
11099 " %up_v4f16 = OpTypePointer Uniform %v4f16\n"
11100 " %ra_v4f16 = OpTypeArray %v4f16 %c_i32_ndp\n"
11101 " %SSBO_v4f16 = OpTypeStruct %ra_v4f16\n"
11102 "%up_SSBO_v4f16 = OpTypePointer Uniform %SSBO_v4f16\n"
11104 " %fun_t = OpTypeFunction %${tt_dst} %${tt_src0} %${tt_src1} %i32\n"
11106 " %ssbo_src0 = OpVariable %up_SSBO_${tt_src0} Uniform\n"
11107 " %ssbo_src1 = OpVariable %up_SSBO_${tt_src1} Uniform\n"
11108 " %ssbo_dst = OpVariable %up_SSBO_${tt_dst} Uniform\n"
11111 const StringTemplate decoration
11113 "OpDecorate %ra_v2f16 ArrayStride 4\n"
11114 "OpDecorate %ra_v3f16 ArrayStride 8\n"
11115 "OpDecorate %ra_v4f16 ArrayStride 8\n"
11117 "OpMemberDecorate %SSBO_v2f16 0 Offset 0\n"
11118 "OpDecorate %SSBO_v2f16 BufferBlock\n"
11120 "OpMemberDecorate %SSBO_v3f16 0 Offset 0\n"
11121 "OpDecorate %SSBO_v3f16 BufferBlock\n"
11123 "OpMemberDecorate %SSBO_v4f16 0 Offset 0\n"
11124 "OpDecorate %SSBO_v4f16 BufferBlock\n"
11126 "OpDecorate %ssbo_src0 DescriptorSet 0\n"
11127 "OpDecorate %ssbo_src0 Binding 0\n"
11128 "OpDecorate %ssbo_src1 DescriptorSet 0\n"
11129 "OpDecorate %ssbo_src1 Binding 1\n"
11130 "OpDecorate %ssbo_dst DescriptorSet 0\n"
11131 "OpDecorate %ssbo_dst Binding 2\n"
11134 const StringTemplate testFun
11136 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
11137 " %param = OpFunctionParameter %v4f32\n"
11138 " %entry = OpLabel\n"
11140 " %i = OpVariable %fp_i32 Function\n"
11141 " OpStore %i %c_i32_0\n"
11143 " %will_run = OpFunctionCall %bool %isUniqueIdZero\n"
11144 " OpSelectionMerge %end_if None\n"
11145 " OpBranchConditional %will_run %run_test %end_if\n"
11147 " %run_test = OpLabel\n"
11148 " OpBranch %loop\n"
11150 " %loop = OpLabel\n"
11151 " %i_cmp = OpLoad %i32 %i\n"
11152 " %lt = OpSLessThan %bool %i_cmp %c_i32_ndp\n"
11153 " OpLoopMerge %merge %next None\n"
11154 " OpBranchConditional %lt %write %merge\n"
11156 " %write = OpLabel\n"
11157 " %ndx = OpLoad %i32 %i\n"
11158 " %src0 = OpAccessChain %up_${tt_src0} %ssbo_src0 %c_i32_0 %ndx\n"
11159 " %val_src0 = OpLoad %${tt_src0} %src0\n"
11160 " %src1 = OpAccessChain %up_${tt_src1} %ssbo_src1 %c_i32_0 %ndx\n"
11161 " %val_src1 = OpLoad %${tt_src1} %src1\n"
11162 " %val_dst = OpFunctionCall %${tt_dst} %sw_fun %val_src0 %val_src1 %ndx\n"
11163 " %dst = OpAccessChain %up_${tt_dst} %ssbo_dst %c_i32_0 %ndx\n"
11164 " OpStore %dst %val_dst\n"
11165 " OpBranch %next\n"
11167 " %next = OpLabel\n"
11168 " %i_cur = OpLoad %i32 %i\n"
11169 " %i_new = OpIAdd %i32 %i_cur %c_i32_1\n"
11170 " OpStore %i %i_new\n"
11171 " OpBranch %loop\n"
11173 " %merge = OpLabel\n"
11174 " OpBranch %end_if\n"
11175 " %end_if = OpLabel\n"
11176 " OpReturnValue %param\n"
11180 " %sw_fun = OpFunction %${tt_dst} None %fun_t\n"
11181 "%sw_param0 = OpFunctionParameter %${tt_src0}\n"
11182 "%sw_param1 = OpFunctionParameter %${tt_src1}\n"
11183 "%sw_paramn = OpFunctionParameter %i32\n"
11184 " %sw_entry = OpLabel\n"
11185 " %modulo = OpSMod %i32 %sw_paramn %c_i32_cc\n"
11186 " OpSelectionMerge %switch_e None\n"
11187 " OpSwitch %modulo %default ${case_list}\n"
11189 "%default = OpLabel\n"
11190 " OpUnreachable\n" // Unreachable default case for switch statement
11191 "%switch_e = OpLabel\n"
11192 " OpUnreachable\n" // Unreachable merge block for switch statement
11196 const StringTemplate testCaseBody
11198 "%case_${case_ndx} = OpLabel\n"
11199 "%val_dst_${case_ndx} = OpVectorShuffle %${tt_dst} %sw_param0 %sw_param1 ${shuffle}\n"
11200 " OpReturnValue %val_dst_${case_ndx}\n"
11203 for (deUint32 dstTypeIdx = 0; dstTypeIdx < DE_LENGTH_OF_ARRAY(testTypes); ++dstTypeIdx)
11205 const TestType& dstType = testTypes[dstTypeIdx];
11207 for (deUint32 comp0Idx = 0; comp0Idx < DE_LENGTH_OF_ARRAY(testTypes); ++comp0Idx)
11209 const TestType& src0Type = testTypes[comp0Idx];
11211 for (deUint32 comp1Idx = 0; comp1Idx < DE_LENGTH_OF_ARRAY(testTypes); ++comp1Idx)
11213 const TestType& src1Type = testTypes[comp1Idx];
11214 const deUint32 input0Stride = (src0Type.typeComponents == 3) ? 4 : src0Type.typeComponents;
11215 const deUint32 input1Stride = (src1Type.typeComponents == 3) ? 4 : src1Type.typeComponents;
11216 const deUint32 outputStride = (dstType.typeComponents == 3) ? 4 : dstType.typeComponents;
11217 const vector<deFloat16> float16Input0Data = getFloat16s(rnd, input0Stride * numDataPoints);
11218 const vector<deFloat16> float16Input1Data = getFloat16s(rnd, input1Stride * numDataPoints);
11219 const vector<deFloat16> float16OutputDummy (outputStride * numDataPoints, 0);
11220 const string testName = de::toString(dstType.typeComponents) + de::toString(src0Type.typeComponents) + de::toString(src1Type.typeComponents);
11221 deUint32 caseCount = 0;
11222 SpecResource specResource;
11223 map<string, string> specs;
11224 vector<string> extensions;
11225 VulkanFeatures features;
11231 vector<string> componentList;
11233 // Generate component possible indices for OpVectorShuffle for components 0 and 1 in output vector
11235 deUint32 caseNo = 0;
11237 for (deUint32 comp0IdxLocal = 0; comp0IdxLocal < src0Type.typeComponents; ++comp0IdxLocal)
11238 componentList.push_back(de::toString(caseNo++));
11239 for (deUint32 comp1IdxLocal = 0; comp1IdxLocal < src1Type.typeComponents; ++comp1IdxLocal)
11240 componentList.push_back(de::toString(caseNo++));
11241 componentList.push_back("0xFFFFFFFF");
11244 for (deUint32 comp0IdxLocal = 0; comp0IdxLocal < componentList.size(); ++comp0IdxLocal)
11246 for (deUint32 comp1IdxLocal = 0; comp1IdxLocal < componentList.size(); ++comp1IdxLocal)
11248 map<string, string> specCase;
11249 string shuffle = componentList[comp0IdxLocal] + " " + componentList[comp1IdxLocal];
11251 for (deUint32 compIdx = 2; compIdx < dstType.typeComponents; ++compIdx)
11252 shuffle += " " + de::toString(compIdx - 2);
11254 specCase["case_ndx"] = de::toString(caseCount);
11255 specCase["shuffle"] = shuffle;
11256 specCase["tt_dst"] = dstType.typeName;
11258 caseBodies += testCaseBody.specialize(specCase);
11259 caseList += de::toString(caseCount) + " %case_" + de::toString(caseCount) + " ";
11266 specs["num_data_points"] = de::toString(numDataPoints);
11267 specs["tt_dst"] = dstType.typeName;
11268 specs["tt_src0"] = src0Type.typeName;
11269 specs["tt_src1"] = src1Type.typeName;
11270 specs["case_bodies"] = caseBodies;
11271 specs["case_list"] = caseList;
11272 specs["case_count"] = de::toString(caseCount);
11274 fragments["extension"] = "OpExtension \"SPV_KHR_16bit_storage\"";
11275 fragments["capability"] = "OpCapability StorageUniformBufferBlock16\n";
11276 fragments["decoration"] = decoration.specialize(specs);
11277 fragments["pre_main"] = preMain.specialize(specs);
11278 fragments["testfun"] = testFun.specialize(specs);
11280 specResource.inputs.push_back(Resource(BufferSp(new Float16Buffer(float16Input0Data)), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
11281 specResource.inputs.push_back(Resource(BufferSp(new Float16Buffer(float16Input1Data)), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
11282 specResource.outputs.push_back(Resource(BufferSp(new Float16Buffer(float16OutputDummy)), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
11283 specResource.verifyIO = getFloat16VectorShuffleVerifyIOFunc(dstType.typeComponents, src0Type.typeComponents, src1Type.typeComponents);
11285 extensions.push_back("VK_KHR_16bit_storage");
11286 extensions.push_back("VK_KHR_shader_float16_int8");
11288 features.extFloat16Int8 = EXTFLOAT16INT8FEATURES_FLOAT16;
11289 features.ext16BitStorage = EXT16BITSTORAGEFEATURES_UNIFORM_BUFFER_BLOCK;
11291 finalizeTestsCreation(specResource, fragments, testCtx, *testGroup.get(), testName, features, extensions, IVec3(1, 1, 1));
11296 return testGroup.release();
11299 bool compareFP16CompositeFunc (const std::vector<Resource>& inputs, const vector<AllocationSp>& outputAllocs, const std::vector<Resource>&, TestLog& log)
11301 if (inputs.size() != 1 || outputAllocs.size() != 1)
11304 vector<deUint8> input1Bytes;
11306 inputs[0].getBytes(input1Bytes);
11308 DE_ASSERT(input1Bytes.size() > 0);
11309 DE_ASSERT(input1Bytes.size() % sizeof(deFloat16) == 0);
11311 const size_t iterations = input1Bytes.size() / sizeof(deFloat16);
11312 const deFloat16* const input1AsFP16 = (const deFloat16*)&input1Bytes[0];
11313 const deFloat16* const outputAsFP16 = (const deFloat16*)outputAllocs[0]->getHostPtr();
11314 const deFloat16 exceptionValue = tcu::Float16(-1.0).bits();
11317 for (size_t idx = 0; idx < iterations; ++idx)
11319 if (input1AsFP16[idx] == exceptionValue)
11322 if (!compare16BitFloat(input1AsFP16[idx], outputAsFP16[idx], error))
11324 log << TestLog::Message << "At " << idx << ":" << error << TestLog::EndMessage;
11333 template<class SpecResource>
11334 tcu::TestCaseGroup* createFloat16CompositeConstructSet (tcu::TestContext& testCtx)
11336 de::MovePtr<tcu::TestCaseGroup> testGroup (new tcu::TestCaseGroup(testCtx, "opcompositeconstruct", "OpCompositeConstruct tests"));
11337 const deUint32 numElements = 8;
11338 const string testName = "struct";
11339 const deUint32 structItemsCount = 88;
11340 const deUint32 exceptionIndices[] = { 1, 7, 15, 17, 25, 33, 51, 55, 59, 63, 67, 71, 84, 85, 86, 87 };
11341 const deFloat16 exceptionValue = tcu::Float16(-1.0).bits();
11342 const deUint32 fieldModifier = 2;
11343 const deUint32 fieldModifiedMulIndex = 60;
11344 const deUint32 fieldModifiedAddIndex = 66;
11346 const StringTemplate preMain
11348 " %c_i32_ndp = OpConstant %i32 ${num_elements}\n"
11349 " %f16 = OpTypeFloat 16\n"
11350 " %v2f16 = OpTypeVector %f16 2\n"
11351 " %v3f16 = OpTypeVector %f16 3\n"
11352 " %v4f16 = OpTypeVector %f16 4\n"
11353 " %c_f16_mod = OpConstant %f16 ${field_modifier}\n"
11357 " %c_u32_5 = OpConstant %u32 5\n"
11359 " %f16arr3 = OpTypeArray %f16 %c_u32_3\n"
11360 " %v2f16arr3 = OpTypeArray %v2f16 %c_u32_3\n"
11361 " %v2f16arr5 = OpTypeArray %v2f16 %c_u32_5\n"
11362 " %v3f16arr5 = OpTypeArray %v3f16 %c_u32_5\n"
11363 " %v4f16arr3 = OpTypeArray %v4f16 %c_u32_3\n"
11364 " %struct16 = OpTypeStruct %f16 %v2f16arr3\n"
11365 " %struct16arr3 = OpTypeArray %struct16 %c_u32_3\n"
11366 " %st_test = OpTypeStruct %f16 %v2f16 %v3f16 %v4f16 %f16arr3 %struct16arr3 %v2f16arr5 %f16 %v3f16arr5 %v4f16arr3\n"
11368 " %up_st = OpTypePointer Uniform %st_test\n"
11369 " %ra_st = OpTypeArray %st_test %c_i32_ndp\n"
11370 " %SSBO_st = OpTypeStruct %ra_st\n"
11371 " %up_SSBO_st = OpTypePointer Uniform %SSBO_st\n"
11373 " %ssbo_dst = OpVariable %up_SSBO_st Uniform\n"
11376 const StringTemplate decoration
11378 "OpDecorate %SSBO_st BufferBlock\n"
11379 "OpDecorate %ra_st ArrayStride ${struct_item_size}\n"
11380 "OpDecorate %ssbo_dst DescriptorSet 0\n"
11381 "OpDecorate %ssbo_dst Binding 1\n"
11383 "OpMemberDecorate %SSBO_st 0 Offset 0\n"
11385 "OpDecorate %v2f16arr3 ArrayStride 4\n"
11386 "OpMemberDecorate %struct16 0 Offset 0\n"
11387 "OpMemberDecorate %struct16 1 Offset 4\n"
11388 "OpDecorate %struct16arr3 ArrayStride 16\n"
11389 "OpDecorate %f16arr3 ArrayStride 2\n"
11390 "OpDecorate %v2f16arr5 ArrayStride 4\n"
11391 "OpDecorate %v3f16arr5 ArrayStride 8\n"
11392 "OpDecorate %v4f16arr3 ArrayStride 8\n"
11394 "OpMemberDecorate %st_test 0 Offset 0\n"
11395 "OpMemberDecorate %st_test 1 Offset 4\n"
11396 "OpMemberDecorate %st_test 2 Offset 8\n"
11397 "OpMemberDecorate %st_test 3 Offset 16\n"
11398 "OpMemberDecorate %st_test 4 Offset 24\n"
11399 "OpMemberDecorate %st_test 5 Offset 32\n"
11400 "OpMemberDecorate %st_test 6 Offset 80\n"
11401 "OpMemberDecorate %st_test 7 Offset 100\n"
11402 "OpMemberDecorate %st_test 8 Offset 104\n"
11403 "OpMemberDecorate %st_test 9 Offset 144\n"
11406 const StringTemplate testFun
11408 " %test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
11409 " %param = OpFunctionParameter %v4f32\n"
11410 " %entry = OpLabel\n"
11412 " %i = OpVariable %fp_i32 Function\n"
11413 " OpStore %i %c_i32_0\n"
11415 " %will_run = OpFunctionCall %bool %isUniqueIdZero\n"
11416 " OpSelectionMerge %end_if None\n"
11417 " OpBranchConditional %will_run %run_test %end_if\n"
11419 " %run_test = OpLabel\n"
11420 " OpBranch %loop\n"
11422 " %loop = OpLabel\n"
11423 " %i_cmp = OpLoad %i32 %i\n"
11424 " %lt = OpSLessThan %bool %i_cmp %c_i32_ndp\n"
11425 " OpLoopMerge %merge %next None\n"
11426 " OpBranchConditional %lt %write %merge\n"
11428 " %write = OpLabel\n"
11429 " %ndx = OpLoad %i32 %i\n"
11431 " %fld1 = OpCompositeConstruct %v2f16 %c_f16_2 %c_f16_3\n"
11432 " %fld2 = OpCompositeConstruct %v3f16 %c_f16_4 %c_f16_5 %c_f16_6\n"
11433 " %fld3 = OpCompositeConstruct %v4f16 %c_f16_8 %c_f16_9 %c_f16_10 %c_f16_11\n"
11435 " %fld4 = OpCompositeConstruct %f16arr3 %c_f16_12 %c_f16_13 %c_f16_14\n"
11437 "%fld5_0_1_0 = OpCompositeConstruct %v2f16 %c_f16_18 %c_f16_19\n"
11438 "%fld5_0_1_1 = OpCompositeConstruct %v2f16 %c_f16_20 %c_f16_21\n"
11439 "%fld5_0_1_2 = OpCompositeConstruct %v2f16 %c_f16_22 %c_f16_23\n"
11440 " %fld5_0_1 = OpCompositeConstruct %v2f16arr3 %fld5_0_1_0 %fld5_0_1_1 %fld5_0_1_2\n"
11441 " %fld5_0 = OpCompositeConstruct %struct16 %c_f16_16 %fld5_0_1\n"
11443 "%fld5_1_1_0 = OpCompositeConstruct %v2f16 %c_f16_26 %c_f16_27\n"
11444 "%fld5_1_1_1 = OpCompositeConstruct %v2f16 %c_f16_28 %c_f16_29\n"
11445 "%fld5_1_1_2 = OpCompositeConstruct %v2f16 %c_f16_30 %c_f16_31\n"
11446 " %fld5_1_1 = OpCompositeConstruct %v2f16arr3 %fld5_1_1_0 %fld5_1_1_1 %fld5_1_1_2\n"
11447 " %fld5_1 = OpCompositeConstruct %struct16 %c_f16_24 %fld5_1_1\n"
11449 "%fld5_2_1_0 = OpCompositeConstruct %v2f16 %c_f16_34 %c_f16_35\n"
11450 "%fld5_2_1_1 = OpCompositeConstruct %v2f16 %c_f16_36 %c_f16_37\n"
11451 "%fld5_2_1_2 = OpCompositeConstruct %v2f16 %c_f16_38 %c_f16_39\n"
11452 " %fld5_2_1 = OpCompositeConstruct %v2f16arr3 %fld5_2_1_0 %fld5_2_1_1 %fld5_2_1_2\n"
11453 " %fld5_2 = OpCompositeConstruct %struct16 %c_f16_32 %fld5_2_1\n"
11455 " %fld5 = OpCompositeConstruct %struct16arr3 %fld5_0 %fld5_1 %fld5_2\n"
11457 " %fld6_0 = OpCompositeConstruct %v2f16 %c_f16_40 %c_f16_41\n"
11458 " %fld6_1 = OpCompositeConstruct %v2f16 %c_f16_42 %c_f16_43\n"
11459 " %fld6_2 = OpCompositeConstruct %v2f16 %c_f16_44 %c_f16_45\n"
11460 " %fld6_3 = OpCompositeConstruct %v2f16 %c_f16_46 %c_f16_47\n"
11461 " %fld6_4 = OpCompositeConstruct %v2f16 %c_f16_48 %c_f16_49\n"
11462 " %fld6 = OpCompositeConstruct %v2f16arr5 %fld6_0 %fld6_1 %fld6_2 %fld6_3 %fld6_4\n"
11464 " %fndx = OpConvertSToF %f16 %ndx\n"
11465 " %fld8_2a0 = OpFMul %f16 %fndx %c_f16_mod\n"
11466 " %fld8_3b1 = OpFAdd %f16 %fndx %c_f16_mod\n"
11468 " %fld8_2a = OpCompositeConstruct %v2f16 %fld8_2a0 %c_f16_61\n"
11469 " %fld8_3b = OpCompositeConstruct %v2f16 %c_f16_65 %fld8_3b1\n"
11470 " %fld8_0 = OpCompositeConstruct %v3f16 %c_f16_52 %c_f16_53 %c_f16_54\n"
11471 " %fld8_1 = OpCompositeConstruct %v3f16 %c_f16_56 %c_f16_57 %c_f16_58\n"
11472 " %fld8_2 = OpCompositeConstruct %v3f16 %fld8_2a %c_f16_62\n"
11473 " %fld8_3 = OpCompositeConstruct %v3f16 %c_f16_64 %fld8_3b\n"
11474 " %fld8_4 = OpCompositeConstruct %v3f16 %c_f16_68 %c_f16_69 %c_f16_70\n"
11475 " %fld8 = OpCompositeConstruct %v3f16arr5 %fld8_0 %fld8_1 %fld8_2 %fld8_3 %fld8_4\n"
11477 " %fld9_0 = OpCompositeConstruct %v4f16 %c_f16_72 %c_f16_73 %c_f16_74 %c_f16_75\n"
11478 " %fld9_1 = OpCompositeConstruct %v4f16 %c_f16_76 %c_f16_77 %c_f16_78 %c_f16_79\n"
11479 " %fld9_2 = OpCompositeConstruct %v4f16 %c_f16_80 %c_f16_81 %c_f16_82 %c_f16_83\n"
11480 " %fld9 = OpCompositeConstruct %v4f16arr3 %fld9_0 %fld9_1 %fld9_2\n"
11482 " %st_val = OpCompositeConstruct %st_test %c_f16_0 %fld1 %fld2 %fld3 %fld4 %fld5 %fld6 %c_f16_50 %fld8 %fld9\n"
11483 " %dst = OpAccessChain %up_st %ssbo_dst %c_i32_0 %ndx\n"
11484 " OpStore %dst %st_val\n"
11486 " OpBranch %next\n"
11488 " %next = OpLabel\n"
11489 " %i_cur = OpLoad %i32 %i\n"
11490 " %i_new = OpIAdd %i32 %i_cur %c_i32_1\n"
11491 " OpStore %i %i_new\n"
11492 " OpBranch %loop\n"
11494 " %merge = OpLabel\n"
11495 " OpBranch %end_if\n"
11496 " %end_if = OpLabel\n"
11497 " OpReturnValue %param\n"
11502 SpecResource specResource;
11503 map<string, string> specs;
11504 VulkanFeatures features;
11505 map<string, string> fragments;
11506 vector<string> extensions;
11507 vector<deFloat16> expectedOutput;
11510 for (deUint32 elementNdx = 0; elementNdx < numElements; ++elementNdx)
11512 vector<deFloat16> expectedIterationOutput;
11514 for (deUint32 structItemNdx = 0; structItemNdx < structItemsCount; ++structItemNdx)
11515 expectedIterationOutput.push_back(tcu::Float16(float(structItemNdx)).bits());
11517 for (deUint32 structItemNdx = 0; structItemNdx < DE_LENGTH_OF_ARRAY(exceptionIndices); ++structItemNdx)
11518 expectedIterationOutput[exceptionIndices[structItemNdx]] = exceptionValue;
11520 expectedIterationOutput[fieldModifiedMulIndex] = tcu::Float16(float(elementNdx * fieldModifier)).bits();
11521 expectedIterationOutput[fieldModifiedAddIndex] = tcu::Float16(float(elementNdx + fieldModifier)).bits();
11523 expectedOutput.insert(expectedOutput.end(), expectedIterationOutput.begin(), expectedIterationOutput.end());
11526 for (deUint32 i = 0; i < structItemsCount; ++i)
11527 consts += " %c_f16_" + de::toString(i) + " = OpConstant %f16 " + de::toString(i) + "\n";
11529 specs["num_elements"] = de::toString(numElements);
11530 specs["struct_item_size"] = de::toString(structItemsCount * sizeof(deFloat16));
11531 specs["field_modifier"] = de::toString(fieldModifier);
11532 specs["consts"] = consts;
11534 fragments["extension"] = "OpExtension \"SPV_KHR_16bit_storage\"";
11535 fragments["capability"] = "OpCapability StorageUniformBufferBlock16\n";
11536 fragments["decoration"] = decoration.specialize(specs);
11537 fragments["pre_main"] = preMain.specialize(specs);
11538 fragments["testfun"] = testFun.specialize(specs);
11540 specResource.inputs.push_back(Resource(BufferSp(new Float16Buffer(expectedOutput)), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
11541 specResource.outputs.push_back(Resource(BufferSp(new Float16Buffer(expectedOutput)), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
11542 specResource.verifyIO = compareFP16CompositeFunc;
11544 extensions.push_back("VK_KHR_16bit_storage");
11545 extensions.push_back("VK_KHR_shader_float16_int8");
11547 features.extFloat16Int8 = EXTFLOAT16INT8FEATURES_FLOAT16;
11548 features.ext16BitStorage = EXT16BITSTORAGEFEATURES_UNIFORM_BUFFER_BLOCK;
11550 finalizeTestsCreation(specResource, fragments, testCtx, *testGroup.get(), testName, features, extensions, IVec3(1, 1, 1));
11553 return testGroup.release();
11556 template<class SpecResource>
11557 tcu::TestCaseGroup* createFloat16CompositeInsertExtractSet (tcu::TestContext& testCtx, const char* op)
11559 de::MovePtr<tcu::TestCaseGroup> testGroup (new tcu::TestCaseGroup(testCtx, de::toLower(op).c_str(), op));
11560 const deFloat16 exceptionValue = tcu::Float16(-1.0).bits();
11561 const string opName (op);
11562 const deUint32 opIndex = (opName == "OpCompositeInsert") ? 0
11563 : (opName == "OpCompositeExtract") ? 1
11566 const StringTemplate preMain
11568 " %c_i32_ndp = OpConstant %i32 ${num_elements}\n"
11569 " %f16 = OpTypeFloat 16\n"
11570 " %v2f16 = OpTypeVector %f16 2\n"
11571 " %v3f16 = OpTypeVector %f16 3\n"
11572 " %v4f16 = OpTypeVector %f16 4\n"
11573 " %c_f16_na = OpConstant %f16 -1.0\n"
11574 " %c_u32_5 = OpConstant %u32 5\n"
11576 "%f16arr3 = OpTypeArray %f16 %c_u32_3\n"
11577 "%v2f16arr3 = OpTypeArray %v2f16 %c_u32_3\n"
11578 "%v2f16arr5 = OpTypeArray %v2f16 %c_u32_5\n"
11579 "%v3f16arr5 = OpTypeArray %v3f16 %c_u32_5\n"
11580 "%v4f16arr3 = OpTypeArray %v4f16 %c_u32_3\n"
11581 "%struct16 = OpTypeStruct %f16 %v2f16arr3\n"
11582 "%struct16arr3 = OpTypeArray %struct16 %c_u32_3\n"
11583 "%st_test = OpTypeStruct %${field_type}\n"
11585 " %up_f16 = OpTypePointer Uniform %f16\n"
11586 " %up_st = OpTypePointer Uniform %st_test\n"
11587 " %ra_f16 = OpTypeArray %f16 %c_i32_ndp\n"
11588 " %ra_st = OpTypeArray %st_test %c_i32_1\n"
11590 "${op_premain_decls}"
11592 " %up_SSBO_src = OpTypePointer Uniform %SSBO_src\n"
11593 " %up_SSBO_dst = OpTypePointer Uniform %SSBO_dst\n"
11595 " %ssbo_src = OpVariable %up_SSBO_src Uniform\n"
11596 " %ssbo_dst = OpVariable %up_SSBO_dst Uniform\n"
11599 const StringTemplate decoration
11601 "OpDecorate %SSBO_src BufferBlock\n"
11602 "OpDecorate %SSBO_dst BufferBlock\n"
11603 "OpDecorate %ra_f16 ArrayStride 2\n"
11604 "OpDecorate %ra_st ArrayStride ${struct_item_size}\n"
11605 "OpDecorate %ssbo_src DescriptorSet 0\n"
11606 "OpDecorate %ssbo_src Binding 0\n"
11607 "OpDecorate %ssbo_dst DescriptorSet 0\n"
11608 "OpDecorate %ssbo_dst Binding 1\n"
11610 "OpMemberDecorate %SSBO_src 0 Offset 0\n"
11611 "OpMemberDecorate %SSBO_dst 0 Offset 0\n"
11613 "OpDecorate %v2f16arr3 ArrayStride 4\n"
11614 "OpMemberDecorate %struct16 0 Offset 0\n"
11615 "OpMemberDecorate %struct16 1 Offset 4\n"
11616 "OpDecorate %struct16arr3 ArrayStride 16\n"
11617 "OpDecorate %f16arr3 ArrayStride 2\n"
11618 "OpDecorate %v2f16arr5 ArrayStride 4\n"
11619 "OpDecorate %v3f16arr5 ArrayStride 8\n"
11620 "OpDecorate %v4f16arr3 ArrayStride 8\n"
11622 "OpMemberDecorate %st_test 0 Offset 0\n"
11625 const StringTemplate testFun
11627 " %test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
11628 " %param = OpFunctionParameter %v4f32\n"
11629 " %entry = OpLabel\n"
11631 " %i = OpVariable %fp_i32 Function\n"
11632 " OpStore %i %c_i32_0\n"
11634 " %will_run = OpFunctionCall %bool %isUniqueIdZero\n"
11635 " OpSelectionMerge %end_if None\n"
11636 " OpBranchConditional %will_run %run_test %end_if\n"
11638 " %run_test = OpLabel\n"
11639 " OpBranch %loop\n"
11641 " %loop = OpLabel\n"
11642 " %i_cmp = OpLoad %i32 %i\n"
11643 " %lt = OpSLessThan %bool %i_cmp %c_i32_ndp\n"
11644 " OpLoopMerge %merge %next None\n"
11645 " OpBranchConditional %lt %write %merge\n"
11647 " %write = OpLabel\n"
11648 " %ndx = OpLoad %i32 %i\n"
11650 "${op_sw_fun_call}"
11652 " OpStore %dst %val_dst\n"
11653 " OpBranch %next\n"
11655 " %next = OpLabel\n"
11656 " %i_cur = OpLoad %i32 %i\n"
11657 " %i_new = OpIAdd %i32 %i_cur %c_i32_1\n"
11658 " OpStore %i %i_new\n"
11659 " OpBranch %loop\n"
11661 " %merge = OpLabel\n"
11662 " OpBranch %end_if\n"
11663 " %end_if = OpLabel\n"
11664 " OpReturnValue %param\n"
11667 "${op_sw_fun_header}"
11668 " %sw_param = OpFunctionParameter %st_test\n"
11669 "%sw_paramn = OpFunctionParameter %i32\n"
11670 " %sw_entry = OpLabel\n"
11671 " OpSelectionMerge %switch_e None\n"
11672 " OpSwitch %sw_paramn %default ${case_list}\n"
11676 "%default = OpLabel\n"
11677 " OpReturnValue ${op_case_default_value}\n"
11678 "%switch_e = OpLabel\n"
11679 " OpUnreachable\n" // Unreachable merge block for switch statement
11683 const StringTemplate testCaseBody
11685 "%case_${case_ndx} = OpLabel\n"
11686 "%val_ret_${case_ndx} = ${op_name} ${op_args_part} ${access_path}\n"
11687 " OpReturnValue %val_ret_${case_ndx}\n"
11692 const char* premainDecls;
11693 const char* swFunCall;
11694 const char* swFunHeader;
11695 const char* caseDefaultValue;
11696 const char* argsPartial;
11699 OpParts opPartsArray[] =
11701 // OpCompositeInsert
11703 " %fun_t = OpTypeFunction %st_test %f16 %st_test %i32\n"
11704 " %SSBO_src = OpTypeStruct %ra_f16\n"
11705 " %SSBO_dst = OpTypeStruct %ra_st\n",
11707 " %src = OpAccessChain %up_f16 %ssbo_src %c_i32_0 %ndx\n"
11708 " %dst = OpAccessChain %up_st %ssbo_dst %c_i32_0 %c_i32_0\n"
11709 " %val_new = OpLoad %f16 %src\n"
11710 " %val_old = OpLoad %st_test %dst\n"
11711 " %val_dst = OpFunctionCall %st_test %sw_fun %val_new %val_old %ndx\n",
11713 " %sw_fun = OpFunction %st_test None %fun_t\n"
11714 "%sw_paramv = OpFunctionParameter %f16\n",
11718 "%st_test %sw_paramv %sw_param",
11720 // OpCompositeExtract
11722 " %fun_t = OpTypeFunction %f16 %st_test %i32\n"
11723 " %SSBO_src = OpTypeStruct %ra_st\n"
11724 " %SSBO_dst = OpTypeStruct %ra_f16\n",
11726 " %src = OpAccessChain %up_st %ssbo_src %c_i32_0 %c_i32_0\n"
11727 " %dst = OpAccessChain %up_f16 %ssbo_dst %c_i32_0 %ndx\n"
11728 " %val_src = OpLoad %st_test %src\n"
11729 " %val_dst = OpFunctionCall %f16 %sw_fun %val_src %ndx\n",
11731 " %sw_fun = OpFunction %f16 None %fun_t\n",
11739 DE_ASSERT(opIndex >= 0 && opIndex < DE_LENGTH_OF_ARRAY(opPartsArray));
11741 const char* accessPathF16[] =
11746 const char* accessPathV2F16[] =
11751 const char* accessPathV3F16[] =
11758 const char* accessPathV4F16[] =
11765 const char* accessPathF16Arr3[] =
11772 const char* accessPathStruct16Arr3[] =
11774 "0 0 0", // %struct16arr3
11799 const char* accessPathV2F16Arr5[] =
11801 "0 0 0", // %v2f16arr5
11812 const char* accessPathV3F16Arr5[] =
11814 "0 0 0", // %v3f16arr5
11835 const char* accessPathV4F16Arr3[] =
11837 "0 0 0", // %v4f16arr3
11855 struct TypeTestParameters
11858 size_t accessPathLength;
11859 const char** accessPath;
11862 const TypeTestParameters typeTestParameters[] =
11864 { "f16", DE_LENGTH_OF_ARRAY(accessPathF16), accessPathF16 },
11865 { "v2f16", DE_LENGTH_OF_ARRAY(accessPathV2F16), accessPathV2F16 },
11866 { "v3f16", DE_LENGTH_OF_ARRAY(accessPathV3F16), accessPathV3F16 },
11867 { "v4f16", DE_LENGTH_OF_ARRAY(accessPathV4F16), accessPathV4F16 },
11868 { "f16arr3", DE_LENGTH_OF_ARRAY(accessPathF16Arr3), accessPathF16Arr3 },
11869 { "v2f16arr5", DE_LENGTH_OF_ARRAY(accessPathV2F16Arr5), accessPathV2F16Arr5 },
11870 { "v3f16arr5", DE_LENGTH_OF_ARRAY(accessPathV3F16Arr5), accessPathV3F16Arr5 },
11871 { "v4f16arr3", DE_LENGTH_OF_ARRAY(accessPathV4F16Arr3), accessPathV4F16Arr3 },
11872 { "struct16arr3", DE_LENGTH_OF_ARRAY(accessPathStruct16Arr3), accessPathStruct16Arr3 },
11875 for (size_t typeTestNdx = 0; typeTestNdx < DE_LENGTH_OF_ARRAY(typeTestParameters); ++typeTestNdx)
11877 const OpParts opParts = opPartsArray[opIndex];
11878 const string testName = typeTestParameters[typeTestNdx].name;
11879 const size_t structItemsCount = typeTestParameters[typeTestNdx].accessPathLength;
11880 const char** accessPath = typeTestParameters[typeTestNdx].accessPath;
11881 SpecResource specResource;
11882 map<string, string> specs;
11883 VulkanFeatures features;
11884 map<string, string> fragments;
11885 vector<string> extensions;
11886 vector<deFloat16> inputFP16;
11887 vector<deFloat16> dummyFP16Output;
11889 // Generate values for input
11890 inputFP16.reserve(structItemsCount);
11891 for (deUint32 structItemNdx = 0; structItemNdx < structItemsCount; ++structItemNdx)
11892 inputFP16.push_back((accessPath[structItemNdx] == DE_NULL) ? exceptionValue : tcu::Float16(float(structItemNdx)).bits());
11894 dummyFP16Output.resize(structItemsCount);
11896 // Generate cases for OpSwitch
11901 for (deUint32 caseNdx = 0; caseNdx < structItemsCount; ++caseNdx)
11902 if (accessPath[caseNdx] != DE_NULL)
11904 map<string, string> specCase;
11906 specCase["case_ndx"] = de::toString(caseNdx);
11907 specCase["access_path"] = accessPath[caseNdx];
11908 specCase["op_args_part"] = opParts.argsPartial;
11909 specCase["op_name"] = opName;
11911 caseBodies += testCaseBody.specialize(specCase);
11912 caseList += de::toString(caseNdx) + " %case_" + de::toString(caseNdx) + " ";
11915 specs["case_bodies"] = caseBodies;
11916 specs["case_list"] = caseList;
11919 specs["num_elements"] = de::toString(structItemsCount);
11920 specs["field_type"] = typeTestParameters[typeTestNdx].name;
11921 specs["struct_item_size"] = de::toString(structItemsCount * sizeof(deFloat16));
11922 specs["op_premain_decls"] = opParts.premainDecls;
11923 specs["op_sw_fun_call"] = opParts.swFunCall;
11924 specs["op_sw_fun_header"] = opParts.swFunHeader;
11925 specs["op_case_default_value"] = opParts.caseDefaultValue;
11927 fragments["extension"] = "OpExtension \"SPV_KHR_16bit_storage\"";
11928 fragments["capability"] = "OpCapability StorageUniformBufferBlock16\n";
11929 fragments["decoration"] = decoration.specialize(specs);
11930 fragments["pre_main"] = preMain.specialize(specs);
11931 fragments["testfun"] = testFun.specialize(specs);
11933 specResource.inputs.push_back(Resource(BufferSp(new Float16Buffer(inputFP16)), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
11934 specResource.outputs.push_back(Resource(BufferSp(new Float16Buffer(dummyFP16Output)), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
11935 specResource.verifyIO = compareFP16CompositeFunc;
11937 extensions.push_back("VK_KHR_16bit_storage");
11938 extensions.push_back("VK_KHR_shader_float16_int8");
11940 features.extFloat16Int8 = EXTFLOAT16INT8FEATURES_FLOAT16;
11941 features.ext16BitStorage = EXT16BITSTORAGEFEATURES_UNIFORM_BUFFER_BLOCK;
11943 finalizeTestsCreation(specResource, fragments, testCtx, *testGroup.get(), testName, features, extensions, IVec3(1, 1, 1));
11946 return testGroup.release();
11949 struct fp16PerComponent
11953 , floatFormat16 (-14, 15, 10, true)
11955 , argCompCount(3, 0)
11959 bool callOncePerComponent () { return true; }
11960 deUint32 getComponentValidity () { return static_cast<deUint32>(-1); }
11962 virtual double getULPs (vector<const deFloat16*>&) { return 1.0; }
11963 virtual double getMin (double value, double ulps) { return value - floatFormat16.ulp(deAbs(value), ulps); }
11964 virtual double getMax (double value, double ulps) { return value + floatFormat16.ulp(deAbs(value), ulps); }
11966 virtual size_t getFlavorCount () { return flavorNames.empty() ? 1 : flavorNames.size(); }
11967 virtual void setFlavor (size_t flavorNo) { DE_ASSERT(flavorNo < getFlavorCount()); flavor = flavorNo; }
11968 virtual size_t getFlavor () { return flavor; }
11969 virtual string getCurrentFlavorName () { return flavorNames.empty() ? string("") : flavorNames[getFlavor()]; }
11971 virtual void setOutCompCount (size_t compCount) { outCompCount = compCount; }
11972 virtual size_t getOutCompCount () { return outCompCount; }
11974 virtual void setArgCompCount (size_t argNo, size_t compCount) { argCompCount[argNo] = compCount; }
11975 virtual size_t getArgCompCount (size_t argNo) { return argCompCount[argNo]; }
11979 tcu::FloatFormat floatFormat16;
11980 size_t outCompCount;
11981 vector<size_t> argCompCount;
11982 vector<string> flavorNames;
11985 struct fp16OpFNegate : public fp16PerComponent
11987 template <class fp16type>
11988 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
11990 const fp16type x (*in[0]);
11991 const double d (x.asDouble());
11992 const double result (0.0 - d);
11994 out[0] = fp16type(result).bits();
11995 min[0] = getMin(result, getULPs(in));
11996 max[0] = getMax(result, getULPs(in));
12002 struct fp16Round : public fp16PerComponent
12004 fp16Round() : fp16PerComponent()
12006 flavorNames.push_back("Floor(x+0.5)");
12007 flavorNames.push_back("Floor(x-0.5)");
12008 flavorNames.push_back("RoundEven");
12011 template<class fp16type>
12012 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
12014 const fp16type x (*in[0]);
12015 const double d (x.asDouble());
12016 double result (0.0);
12020 case 0: result = deRound(d); break;
12021 case 1: result = deFloor(d - 0.5); break;
12022 case 2: result = deRoundEven(d); break;
12023 default: TCU_THROW(InternalError, "Invalid flavor specified");
12026 out[0] = fp16type(result).bits();
12027 min[0] = getMin(result, getULPs(in));
12028 max[0] = getMax(result, getULPs(in));
12034 struct fp16RoundEven : public fp16PerComponent
12036 template<class fp16type>
12037 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
12039 const fp16type x (*in[0]);
12040 const double d (x.asDouble());
12041 const double result (deRoundEven(d));
12043 out[0] = fp16type(result).bits();
12044 min[0] = getMin(result, getULPs(in));
12045 max[0] = getMax(result, getULPs(in));
12051 struct fp16Trunc : public fp16PerComponent
12053 template<class fp16type>
12054 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
12056 const fp16type x (*in[0]);
12057 const double d (x.asDouble());
12058 const double result (deTrunc(d));
12060 out[0] = fp16type(result).bits();
12061 min[0] = getMin(result, getULPs(in));
12062 max[0] = getMax(result, getULPs(in));
12068 struct fp16FAbs : public fp16PerComponent
12070 template<class fp16type>
12071 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
12073 const fp16type x (*in[0]);
12074 const double d (x.asDouble());
12075 const double result (deAbs(d));
12077 out[0] = fp16type(result).bits();
12078 min[0] = getMin(result, getULPs(in));
12079 max[0] = getMax(result, getULPs(in));
12085 struct fp16FSign : public fp16PerComponent
12087 template<class fp16type>
12088 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
12090 const fp16type x (*in[0]);
12091 const double d (x.asDouble());
12092 const double result (deSign(d));
12097 out[0] = fp16type(result).bits();
12098 min[0] = getMin(result, getULPs(in));
12099 max[0] = getMax(result, getULPs(in));
12105 struct fp16Floor : public fp16PerComponent
12107 template<class fp16type>
12108 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
12110 const fp16type x (*in[0]);
12111 const double d (x.asDouble());
12112 const double result (deFloor(d));
12114 out[0] = fp16type(result).bits();
12115 min[0] = getMin(result, getULPs(in));
12116 max[0] = getMax(result, getULPs(in));
12122 struct fp16Ceil : public fp16PerComponent
12124 template<class fp16type>
12125 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
12127 const fp16type x (*in[0]);
12128 const double d (x.asDouble());
12129 const double result (deCeil(d));
12131 out[0] = fp16type(result).bits();
12132 min[0] = getMin(result, getULPs(in));
12133 max[0] = getMax(result, getULPs(in));
12139 struct fp16Fract : public fp16PerComponent
12141 template<class fp16type>
12142 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
12144 const fp16type x (*in[0]);
12145 const double d (x.asDouble());
12146 const double result (deFrac(d));
12148 out[0] = fp16type(result).bits();
12149 min[0] = getMin(result, getULPs(in));
12150 max[0] = getMax(result, getULPs(in));
12156 struct fp16Radians : public fp16PerComponent
12158 virtual double getULPs (vector<const deFloat16*>& in)
12165 template<class fp16type>
12166 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
12168 const fp16type x (*in[0]);
12169 const float d (x.asFloat());
12170 const float result (deFloatRadians(d));
12172 out[0] = fp16type(result).bits();
12173 min[0] = getMin(result, getULPs(in));
12174 max[0] = getMax(result, getULPs(in));
12180 struct fp16Degrees : public fp16PerComponent
12182 virtual double getULPs (vector<const deFloat16*>& in)
12189 template<class fp16type>
12190 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
12192 const fp16type x (*in[0]);
12193 const float d (x.asFloat());
12194 const float result (deFloatDegrees(d));
12196 out[0] = fp16type(result).bits();
12197 min[0] = getMin(result, getULPs(in));
12198 max[0] = getMax(result, getULPs(in));
12204 struct fp16Sin : public fp16PerComponent
12206 template<class fp16type>
12207 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
12209 const fp16type x (*in[0]);
12210 const double d (x.asDouble());
12211 const double result (deSin(d));
12212 const double unspecUlp (16.0);
12213 const double err (de::inRange(d, -DE_PI_DOUBLE, DE_PI_DOUBLE) ? deLdExp(1.0, -7) : floatFormat16.ulp(deAbs(result), unspecUlp));
12215 if (!de::inRange(d, -DE_PI_DOUBLE, DE_PI_DOUBLE))
12218 out[0] = fp16type(result).bits();
12219 min[0] = result - err;
12220 max[0] = result + err;
12226 struct fp16Cos : public fp16PerComponent
12228 template<class fp16type>
12229 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
12231 const fp16type x (*in[0]);
12232 const double d (x.asDouble());
12233 const double result (deCos(d));
12234 const double unspecUlp (16.0);
12235 const double err (de::inRange(d, -DE_PI_DOUBLE, DE_PI_DOUBLE) ? deLdExp(1.0, -7) : floatFormat16.ulp(deAbs(result), unspecUlp));
12237 if (!de::inRange(d, -DE_PI_DOUBLE, DE_PI_DOUBLE))
12240 out[0] = fp16type(result).bits();
12241 min[0] = result - err;
12242 max[0] = result + err;
12248 struct fp16Tan : public fp16PerComponent
12250 template<class fp16type>
12251 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
12253 const fp16type x (*in[0]);
12254 const double d (x.asDouble());
12255 const double result (deTan(d));
12257 if (!de::inRange(d, -DE_PI_DOUBLE, DE_PI_DOUBLE))
12260 out[0] = fp16type(result).bits();
12262 const double err = deLdExp(1.0, -7);
12263 const double s1 = deSin(d) + err;
12264 const double s2 = deSin(d) - err;
12265 const double c1 = deCos(d) + err;
12266 const double c2 = deCos(d) - err;
12267 const double edgeVals[] = {s1/c1, s1/c2, s2/c1, s2/c2};
12268 double edgeLeft = out[0];
12269 double edgeRight = out[0];
12271 if (deSign(c1 * c2) < 0.0)
12273 edgeLeft = -std::numeric_limits<double>::infinity();
12274 edgeRight = +std::numeric_limits<double>::infinity();
12278 edgeLeft = *std::min_element(&edgeVals[0], &edgeVals[DE_LENGTH_OF_ARRAY(edgeVals)]);
12279 edgeRight = *std::max_element(&edgeVals[0], &edgeVals[DE_LENGTH_OF_ARRAY(edgeVals)]);
12283 max[0] = edgeRight;
12290 struct fp16Asin : public fp16PerComponent
12292 template<class fp16type>
12293 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
12295 const fp16type x (*in[0]);
12296 const double d (x.asDouble());
12297 const double result (deAsin(d));
12298 const double error (deAtan2(d, sqrt(1.0 - d * d)));
12300 if (!x.isNaN() && deAbs(d) > 1.0)
12303 out[0] = fp16type(result).bits();
12304 min[0] = result - floatFormat16.ulp(deAbs(error), 2 * 5.0); // This is not a precision test. Value is not from spec
12305 max[0] = result + floatFormat16.ulp(deAbs(error), 2 * 5.0); // This is not a precision test. Value is not from spec
12311 struct fp16Acos : public fp16PerComponent
12313 template<class fp16type>
12314 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
12316 const fp16type x (*in[0]);
12317 const double d (x.asDouble());
12318 const double result (deAcos(d));
12319 const double error (deAtan2(sqrt(1.0 - d * d), d));
12321 if (!x.isNaN() && deAbs(d) > 1.0)
12324 out[0] = fp16type(result).bits();
12325 min[0] = result - floatFormat16.ulp(deAbs(error), 2 * 5.0); // This is not a precision test. Value is not from spec
12326 max[0] = result + floatFormat16.ulp(deAbs(error), 2 * 5.0); // This is not a precision test. Value is not from spec
12332 struct fp16Atan : public fp16PerComponent
12334 virtual double getULPs(vector<const deFloat16*>& in)
12338 return 2 * 5.0; // This is not a precision test. Value is not from spec
12341 template<class fp16type>
12342 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
12344 const fp16type x (*in[0]);
12345 const double d (x.asDouble());
12346 const double result (deAtanOver(d));
12348 out[0] = fp16type(result).bits();
12349 min[0] = getMin(result, getULPs(in));
12350 max[0] = getMax(result, getULPs(in));
12356 struct fp16Sinh : public fp16PerComponent
12358 fp16Sinh() : fp16PerComponent()
12360 flavorNames.push_back("Double");
12361 flavorNames.push_back("ExpFP16");
12364 template<class fp16type>
12365 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
12367 const fp16type x (*in[0]);
12368 const double d (x.asDouble());
12369 const double ulps (64 * (1.0 + 2 * deAbs(d))); // This is not a precision test. Value is not from spec
12370 double result (0.0);
12371 double error (0.0);
12373 if (getFlavor() == 0)
12375 result = deSinh(d);
12376 error = floatFormat16.ulp(deAbs(result), ulps);
12378 else if (getFlavor() == 1)
12380 const fp16type epx (deExp(d));
12381 const fp16type enx (deExp(-d));
12382 const fp16type esx (epx.asDouble() - enx.asDouble());
12383 const fp16type sx2 (esx.asDouble() / 2.0);
12385 result = sx2.asDouble();
12386 error = deAbs(floatFormat16.ulp(epx.asDouble(), ulps)) + deAbs(floatFormat16.ulp(enx.asDouble(), ulps));
12390 TCU_THROW(InternalError, "Unknown flavor");
12393 out[0] = fp16type(result).bits();
12394 min[0] = result - error;
12395 max[0] = result + error;
12401 struct fp16Cosh : public fp16PerComponent
12403 fp16Cosh() : fp16PerComponent()
12405 flavorNames.push_back("Double");
12406 flavorNames.push_back("ExpFP16");
12409 template<class fp16type>
12410 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
12412 const fp16type x (*in[0]);
12413 const double d (x.asDouble());
12414 const double ulps (64 * (1.0 + 2 * deAbs(d))); // This is not a precision test. Value is not from spec
12415 double result (0.0);
12417 if (getFlavor() == 0)
12419 result = deCosh(d);
12421 else if (getFlavor() == 1)
12423 const fp16type epx (deExp(d));
12424 const fp16type enx (deExp(-d));
12425 const fp16type esx (epx.asDouble() + enx.asDouble());
12426 const fp16type sx2 (esx.asDouble() / 2.0);
12428 result = sx2.asDouble();
12432 TCU_THROW(InternalError, "Unknown flavor");
12435 out[0] = fp16type(result).bits();
12436 min[0] = result - floatFormat16.ulp(deAbs(result), ulps);
12437 max[0] = result + floatFormat16.ulp(deAbs(result), ulps);
12443 struct fp16Tanh : public fp16PerComponent
12445 fp16Tanh() : fp16PerComponent()
12447 flavorNames.push_back("Tanh");
12448 flavorNames.push_back("SinhCosh");
12449 flavorNames.push_back("SinhCoshFP16");
12450 flavorNames.push_back("PolyFP16");
12453 virtual double getULPs (vector<const deFloat16*>& in)
12455 const tcu::Float16 x (*in[0]);
12456 const double d (x.asDouble());
12458 return 2 * (1.0 + 2 * deAbs(d)); // This is not a precision test. Value is not from spec
12461 template<class fp16type>
12462 inline double calcPoly (const fp16type& espx, const fp16type& esnx, const fp16type& ecpx, const fp16type& ecnx)
12464 const fp16type esx (espx.asDouble() - esnx.asDouble());
12465 const fp16type sx2 (esx.asDouble() / 2.0);
12466 const fp16type ecx (ecpx.asDouble() + ecnx.asDouble());
12467 const fp16type cx2 (ecx.asDouble() / 2.0);
12468 const fp16type tg (sx2.asDouble() / cx2.asDouble());
12469 const double rez (tg.asDouble());
12474 template<class fp16type>
12475 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
12477 const fp16type x (*in[0]);
12478 const double d (x.asDouble());
12479 double result (0.0);
12481 if (getFlavor() == 0)
12483 result = deTanh(d);
12484 min[0] = getMin(result, getULPs(in));
12485 max[0] = getMax(result, getULPs(in));
12487 else if (getFlavor() == 1)
12489 result = deSinh(d) / deCosh(d);
12490 min[0] = getMin(result, getULPs(in));
12491 max[0] = getMax(result, getULPs(in));
12493 else if (getFlavor() == 2)
12495 const fp16type s (deSinh(d));
12496 const fp16type c (deCosh(d));
12498 result = s.asDouble() / c.asDouble();
12499 min[0] = getMin(result, getULPs(in));
12500 max[0] = getMax(result, getULPs(in));
12502 else if (getFlavor() == 3)
12504 const double ulps (getULPs(in));
12505 const double epxm (deExp( d));
12506 const double enxm (deExp(-d));
12507 const double epxmerr = floatFormat16.ulp(epxm, ulps);
12508 const double enxmerr = floatFormat16.ulp(enxm, ulps);
12509 const fp16type epx[] = { fp16type(epxm - epxmerr), fp16type(epxm + epxmerr) };
12510 const fp16type enx[] = { fp16type(enxm - enxmerr), fp16type(enxm + enxmerr) };
12511 const fp16type epxm16 (epxm);
12512 const fp16type enxm16 (enxm);
12513 vector<double> tgs;
12515 for (size_t spNdx = 0; spNdx < DE_LENGTH_OF_ARRAY(epx); ++spNdx)
12516 for (size_t snNdx = 0; snNdx < DE_LENGTH_OF_ARRAY(enx); ++snNdx)
12517 for (size_t cpNdx = 0; cpNdx < DE_LENGTH_OF_ARRAY(epx); ++cpNdx)
12518 for (size_t cnNdx = 0; cnNdx < DE_LENGTH_OF_ARRAY(enx); ++cnNdx)
12520 const double tgh = calcPoly(epx[spNdx], enx[snNdx], epx[cpNdx], enx[cnNdx]);
12522 tgs.push_back(tgh);
12525 result = calcPoly(epxm16, enxm16, epxm16, enxm16);
12526 min[0] = *std::min_element(tgs.begin(), tgs.end());
12527 max[0] = *std::max_element(tgs.begin(), tgs.end());
12531 TCU_THROW(InternalError, "Unknown flavor");
12534 out[0] = fp16type(result).bits();
12540 struct fp16Asinh : public fp16PerComponent
12542 fp16Asinh() : fp16PerComponent()
12544 flavorNames.push_back("Double");
12545 flavorNames.push_back("PolyFP16Wiki");
12546 flavorNames.push_back("PolyFP16Abs");
12549 virtual double getULPs (vector<const deFloat16*>& in)
12553 return 256.0; // This is not a precision test. Value is not from spec
12556 template<class fp16type>
12557 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
12559 const fp16type x (*in[0]);
12560 const double d (x.asDouble());
12561 double result (0.0);
12563 if (getFlavor() == 0)
12565 result = deAsinh(d);
12567 else if (getFlavor() == 1)
12569 const fp16type x2 (d * d);
12570 const fp16type x2p1 (x2.asDouble() + 1.0);
12571 const fp16type sq (deSqrt(x2p1.asDouble()));
12572 const fp16type sxsq (d + sq.asDouble());
12573 const fp16type lsxsq (deLog(sxsq.asDouble()));
12578 result = lsxsq.asDouble();
12580 else if (getFlavor() == 2)
12582 const fp16type x2 (d * d);
12583 const fp16type x2p1 (x2.asDouble() + 1.0);
12584 const fp16type sq (deSqrt(x2p1.asDouble()));
12585 const fp16type sxsq (deAbs(d) + sq.asDouble());
12586 const fp16type lsxsq (deLog(sxsq.asDouble()));
12588 result = deSign(d) * lsxsq.asDouble();
12592 TCU_THROW(InternalError, "Unknown flavor");
12595 out[0] = fp16type(result).bits();
12596 min[0] = getMin(result, getULPs(in));
12597 max[0] = getMax(result, getULPs(in));
12603 struct fp16Acosh : public fp16PerComponent
12605 fp16Acosh() : fp16PerComponent()
12607 flavorNames.push_back("Double");
12608 flavorNames.push_back("PolyFP16");
12611 virtual double getULPs (vector<const deFloat16*>& in)
12615 return 16.0; // This is not a precision test. Value is not from spec
12618 template<class fp16type>
12619 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
12621 const fp16type x (*in[0]);
12622 const double d (x.asDouble());
12623 double result (0.0);
12625 if (!x.isNaN() && d < 1.0)
12628 if (getFlavor() == 0)
12630 result = deAcosh(d);
12632 else if (getFlavor() == 1)
12634 const fp16type x2 (d * d);
12635 const fp16type x2m1 (x2.asDouble() - 1.0);
12636 const fp16type sq (deSqrt(x2m1.asDouble()));
12637 const fp16type sxsq (d + sq.asDouble());
12638 const fp16type lsxsq (deLog(sxsq.asDouble()));
12640 result = lsxsq.asDouble();
12644 TCU_THROW(InternalError, "Unknown flavor");
12647 out[0] = fp16type(result).bits();
12648 min[0] = getMin(result, getULPs(in));
12649 max[0] = getMax(result, getULPs(in));
12655 struct fp16Atanh : public fp16PerComponent
12657 fp16Atanh() : fp16PerComponent()
12659 flavorNames.push_back("Double");
12660 flavorNames.push_back("PolyFP16");
12663 template<class fp16type>
12664 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
12666 const fp16type x (*in[0]);
12667 const double d (x.asDouble());
12668 double result (0.0);
12670 if (deAbs(d) >= 1.0)
12673 if (getFlavor() == 0)
12675 const double ulps (16.0); // This is not a precision test. Value is not from spec
12677 result = deAtanh(d);
12678 min[0] = getMin(result, ulps);
12679 max[0] = getMax(result, ulps);
12681 else if (getFlavor() == 1)
12683 const fp16type x1a (1.0 + d);
12684 const fp16type x1b (1.0 - d);
12685 const fp16type x1d (x1a.asDouble() / x1b.asDouble());
12686 const fp16type lx1d (deLog(x1d.asDouble()));
12687 const fp16type lx1d2 (0.5 * lx1d.asDouble());
12688 const double error (2 * (de::inRange(deAbs(x1d.asDouble()), 0.5, 2.0) ? deLdExp(2.0, -7) : floatFormat16.ulp(deAbs(x1d.asDouble()), 3.0)));
12690 result = lx1d2.asDouble();
12691 min[0] = result - error;
12692 max[0] = result + error;
12696 TCU_THROW(InternalError, "Unknown flavor");
12699 out[0] = fp16type(result).bits();
12705 struct fp16Exp : public fp16PerComponent
12707 template<class fp16type>
12708 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
12710 const fp16type x (*in[0]);
12711 const double d (x.asDouble());
12712 const double ulps (10.0 * (1.0 + 2.0 * deAbs(d)));
12713 const double result (deExp(d));
12715 out[0] = fp16type(result).bits();
12716 min[0] = getMin(result, ulps);
12717 max[0] = getMax(result, ulps);
12723 struct fp16Log : public fp16PerComponent
12725 template<class fp16type>
12726 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
12728 const fp16type x (*in[0]);
12729 const double d (x.asDouble());
12730 const double result (deLog(d));
12731 const double error (de::inRange(deAbs(d), 0.5, 2.0) ? deLdExp(2.0, -7) : floatFormat16.ulp(deAbs(result), 3.0));
12736 out[0] = fp16type(result).bits();
12737 min[0] = result - error;
12738 max[0] = result + error;
12744 struct fp16Exp2 : public fp16PerComponent
12746 template<class fp16type>
12747 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
12749 const fp16type x (*in[0]);
12750 const double d (x.asDouble());
12751 const double result (deExp2(d));
12752 const double ulps (1.0 + 2.0 * deAbs(fp16type(in[0][0]).asDouble()));
12754 out[0] = fp16type(result).bits();
12755 min[0] = getMin(result, ulps);
12756 max[0] = getMax(result, ulps);
12762 struct fp16Log2 : public fp16PerComponent
12764 template<class fp16type>
12765 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
12767 const fp16type x (*in[0]);
12768 const double d (x.asDouble());
12769 const double result (deLog2(d));
12770 const double error (de::inRange(deAbs(d), 0.5, 2.0) ? deLdExp(2.0, -7) : floatFormat16.ulp(deAbs(result), 3.0));
12775 out[0] = fp16type(result).bits();
12776 min[0] = result - error;
12777 max[0] = result + error;
12783 struct fp16Sqrt : public fp16PerComponent
12785 virtual double getULPs (vector<const deFloat16*>& in)
12792 template<class fp16type>
12793 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
12795 const fp16type x (*in[0]);
12796 const double d (x.asDouble());
12797 const double result (deSqrt(d));
12799 if (!x.isNaN() && d < 0.0)
12802 out[0] = fp16type(result).bits();
12803 min[0] = getMin(result, getULPs(in));
12804 max[0] = getMax(result, getULPs(in));
12810 struct fp16InverseSqrt : public fp16PerComponent
12812 virtual double getULPs (vector<const deFloat16*>& in)
12819 template<class fp16type>
12820 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
12822 const fp16type x (*in[0]);
12823 const double d (x.asDouble());
12824 const double result (1.0/deSqrt(d));
12826 if (!x.isNaN() && d <= 0.0)
12829 out[0] = fp16type(result).bits();
12830 min[0] = getMin(result, getULPs(in));
12831 max[0] = getMax(result, getULPs(in));
12837 struct fp16ModfFrac : public fp16PerComponent
12839 template<class fp16type>
12840 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
12842 const fp16type x (*in[0]);
12843 const double d (x.asDouble());
12845 const double result (deModf(d, &i));
12847 if (x.isInf() || x.isNaN())
12850 out[0] = fp16type(result).bits();
12851 min[0] = getMin(result, getULPs(in));
12852 max[0] = getMax(result, getULPs(in));
12858 struct fp16ModfInt : public fp16PerComponent
12860 template<class fp16type>
12861 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
12863 const fp16type x (*in[0]);
12864 const double d (x.asDouble());
12866 const double dummy (deModf(d, &i));
12867 const double result (i);
12871 if (x.isInf() || x.isNaN())
12874 out[0] = fp16type(result).bits();
12875 min[0] = getMin(result, getULPs(in));
12876 max[0] = getMax(result, getULPs(in));
12882 struct fp16FrexpS : public fp16PerComponent
12884 template<class fp16type>
12885 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
12887 const fp16type x (*in[0]);
12888 const double d (x.asDouble());
12890 const double result (deFrExp(d, &e));
12892 if (x.isNaN() || x.isInf())
12895 out[0] = fp16type(result).bits();
12896 min[0] = getMin(result, getULPs(in));
12897 max[0] = getMax(result, getULPs(in));
12903 struct fp16FrexpE : public fp16PerComponent
12905 template<class fp16type>
12906 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
12908 const fp16type x (*in[0]);
12909 const double d (x.asDouble());
12911 const double dummy (deFrExp(d, &e));
12912 const double result (static_cast<double>(e));
12916 if (x.isNaN() || x.isInf())
12919 out[0] = fp16type(result).bits();
12920 min[0] = getMin(result, getULPs(in));
12921 max[0] = getMax(result, getULPs(in));
12927 struct fp16OpFAdd : public fp16PerComponent
12929 template<class fp16type>
12930 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
12932 const fp16type x (*in[0]);
12933 const fp16type y (*in[1]);
12934 const double xd (x.asDouble());
12935 const double yd (y.asDouble());
12936 const double result (xd + yd);
12938 out[0] = fp16type(result).bits();
12939 min[0] = getMin(result, getULPs(in));
12940 max[0] = getMax(result, getULPs(in));
12946 struct fp16OpFSub : public fp16PerComponent
12948 template<class fp16type>
12949 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
12951 const fp16type x (*in[0]);
12952 const fp16type y (*in[1]);
12953 const double xd (x.asDouble());
12954 const double yd (y.asDouble());
12955 const double result (xd - yd);
12957 out[0] = fp16type(result).bits();
12958 min[0] = getMin(result, getULPs(in));
12959 max[0] = getMax(result, getULPs(in));
12965 struct fp16OpFMul : public fp16PerComponent
12967 template<class fp16type>
12968 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
12970 const fp16type x (*in[0]);
12971 const fp16type y (*in[1]);
12972 const double xd (x.asDouble());
12973 const double yd (y.asDouble());
12974 const double result (xd * yd);
12976 out[0] = fp16type(result).bits();
12977 min[0] = getMin(result, getULPs(in));
12978 max[0] = getMax(result, getULPs(in));
12984 struct fp16OpFDiv : public fp16PerComponent
12986 fp16OpFDiv() : fp16PerComponent()
12988 flavorNames.push_back("DirectDiv");
12989 flavorNames.push_back("InverseDiv");
12992 template<class fp16type>
12993 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
12995 const fp16type x (*in[0]);
12996 const fp16type y (*in[1]);
12997 const double xd (x.asDouble());
12998 const double yd (y.asDouble());
12999 const double unspecUlp (16.0);
13000 const double ulpCnt (de::inRange(deAbs(yd), deLdExp(1, -14), deLdExp(1, 14)) ? 2.5 : unspecUlp);
13001 double result (0.0);
13006 if (getFlavor() == 0)
13008 result = (xd / yd);
13010 else if (getFlavor() == 1)
13012 const double invyd (1.0 / yd);
13013 const fp16type invy (invyd);
13015 result = (xd * invy.asDouble());
13019 TCU_THROW(InternalError, "Unknown flavor");
13022 out[0] = fp16type(result).bits();
13023 min[0] = getMin(result, ulpCnt);
13024 max[0] = getMax(result, ulpCnt);
13030 struct fp16Atan2 : public fp16PerComponent
13032 fp16Atan2() : fp16PerComponent()
13034 flavorNames.push_back("DoubleCalc");
13035 flavorNames.push_back("DoubleCalc_PI");
13038 virtual double getULPs(vector<const deFloat16*>& in)
13042 return 2 * 5.0; // This is not a precision test. Value is not from spec
13045 template<class fp16type>
13046 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
13048 const fp16type x (*in[0]);
13049 const fp16type y (*in[1]);
13050 const double xd (x.asDouble());
13051 const double yd (y.asDouble());
13052 double result (0.0);
13054 if (x.isZero() && y.isZero())
13057 if (getFlavor() == 0)
13059 result = deAtan2(xd, yd);
13061 else if (getFlavor() == 1)
13063 const double ulps (2.0 * 5.0); // This is not a precision test. Value is not from spec
13064 const double eps (floatFormat16.ulp(DE_PI_DOUBLE, ulps));
13066 result = deAtan2(xd, yd);
13068 if (de::inRange(deAbs(result), DE_PI_DOUBLE - eps, DE_PI_DOUBLE + eps))
13073 TCU_THROW(InternalError, "Unknown flavor");
13076 out[0] = fp16type(result).bits();
13077 min[0] = getMin(result, getULPs(in));
13078 max[0] = getMax(result, getULPs(in));
13084 struct fp16Pow : public fp16PerComponent
13086 fp16Pow() : fp16PerComponent()
13088 flavorNames.push_back("Pow");
13089 flavorNames.push_back("PowLog2");
13090 flavorNames.push_back("PowLog2FP16");
13093 template<class fp16type>
13094 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
13096 const fp16type x (*in[0]);
13097 const fp16type y (*in[1]);
13098 const double xd (x.asDouble());
13099 const double yd (y.asDouble());
13100 const double logxeps (de::inRange(deAbs(xd), 0.5, 2.0) ? deLdExp(1.0, -7) : floatFormat16.ulp(deLog2(xd), 3.0));
13101 const double ulps1 (1.0 + 4.0 * deAbs(yd * (deLog2(xd) - logxeps)));
13102 const double ulps2 (1.0 + 4.0 * deAbs(yd * (deLog2(xd) + logxeps)));
13103 const double ulps (deMax(deAbs(ulps1), deAbs(ulps2)));
13104 double result (0.0);
13109 if (x.isZero() && yd <= 0.0)
13112 if (getFlavor() == 0)
13114 result = dePow(xd, yd);
13116 else if (getFlavor() == 1)
13118 const double l2d (deLog2(xd));
13119 const double e2d (deExp2(yd * l2d));
13123 else if (getFlavor() == 2)
13125 const double l2d (deLog2(xd));
13126 const fp16type l2 (l2d);
13127 const double e2d (deExp2(yd * l2.asDouble()));
13128 const fp16type e2 (e2d);
13130 result = e2.asDouble();
13134 TCU_THROW(InternalError, "Unknown flavor");
13137 out[0] = fp16type(result).bits();
13138 min[0] = getMin(result, ulps);
13139 max[0] = getMax(result, ulps);
13145 struct fp16FMin : public fp16PerComponent
13147 template<class fp16type>
13148 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
13150 const fp16type x (*in[0]);
13151 const fp16type y (*in[1]);
13152 const double xd (x.asDouble());
13153 const double yd (y.asDouble());
13154 const double result (deMin(xd, yd));
13156 if (x.isNaN() || y.isNaN())
13159 out[0] = fp16type(result).bits();
13160 min[0] = getMin(result, getULPs(in));
13161 max[0] = getMax(result, getULPs(in));
13167 struct fp16FMax : public fp16PerComponent
13169 template<class fp16type>
13170 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
13172 const fp16type x (*in[0]);
13173 const fp16type y (*in[1]);
13174 const double xd (x.asDouble());
13175 const double yd (y.asDouble());
13176 const double result (deMax(xd, yd));
13178 if (x.isNaN() || y.isNaN())
13181 out[0] = fp16type(result).bits();
13182 min[0] = getMin(result, getULPs(in));
13183 max[0] = getMax(result, getULPs(in));
13189 struct fp16Step : public fp16PerComponent
13191 template<class fp16type>
13192 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
13194 const fp16type edge (*in[0]);
13195 const fp16type x (*in[1]);
13196 const double edged (edge.asDouble());
13197 const double xd (x.asDouble());
13198 const double result (deStep(edged, xd));
13200 out[0] = fp16type(result).bits();
13201 min[0] = getMin(result, getULPs(in));
13202 max[0] = getMax(result, getULPs(in));
13208 struct fp16Ldexp : public fp16PerComponent
13210 template<class fp16type>
13211 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
13213 const fp16type x (*in[0]);
13214 const fp16type y (*in[1]);
13215 const double xd (x.asDouble());
13216 const int yd (static_cast<int>(deTrunc(y.asDouble())));
13217 const double result (deLdExp(xd, yd));
13219 if (y.isNaN() || y.isInf() || y.isDenorm() || yd < -14 || yd > 15)
13222 // Spec: "If this product is too large to be represented in the floating-point type, the result is undefined."
13223 if (fp16type(result).isInf())
13226 out[0] = fp16type(result).bits();
13227 min[0] = getMin(result, getULPs(in));
13228 max[0] = getMax(result, getULPs(in));
13234 struct fp16FClamp : public fp16PerComponent
13236 template<class fp16type>
13237 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
13239 const fp16type x (*in[0]);
13240 const fp16type minVal (*in[1]);
13241 const fp16type maxVal (*in[2]);
13242 const double xd (x.asDouble());
13243 const double minVald (minVal.asDouble());
13244 const double maxVald (maxVal.asDouble());
13245 const double result (deClamp(xd, minVald, maxVald));
13247 if (minVal.isNaN() || maxVal.isNaN() || minVald > maxVald)
13250 out[0] = fp16type(result).bits();
13251 min[0] = getMin(result, getULPs(in));
13252 max[0] = getMax(result, getULPs(in));
13258 struct fp16FMix : public fp16PerComponent
13260 fp16FMix() : fp16PerComponent()
13262 flavorNames.push_back("DoubleCalc");
13263 flavorNames.push_back("EmulatingFP16");
13264 flavorNames.push_back("EmulatingFP16YminusX");
13267 template<class fp16type>
13268 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
13270 const fp16type x (*in[0]);
13271 const fp16type y (*in[1]);
13272 const fp16type a (*in[2]);
13273 const double ulps (8.0); // This is not a precision test. Value is not from spec
13274 double result (0.0);
13276 if (getFlavor() == 0)
13278 const double xd (x.asDouble());
13279 const double yd (y.asDouble());
13280 const double ad (a.asDouble());
13281 const double xeps (floatFormat16.ulp(deAbs(xd * (1.0 - ad)), ulps));
13282 const double yeps (floatFormat16.ulp(deAbs(yd * ad), ulps));
13283 const double eps (xeps + yeps);
13285 result = deMix(xd, yd, ad);
13286 min[0] = result - eps;
13287 max[0] = result + eps;
13289 else if (getFlavor() == 1)
13291 const double xd (x.asDouble());
13292 const double yd (y.asDouble());
13293 const double ad (a.asDouble());
13294 const fp16type am (1.0 - ad);
13295 const double amd (am.asDouble());
13296 const fp16type xam (xd * amd);
13297 const double xamd (xam.asDouble());
13298 const fp16type ya (yd * ad);
13299 const double yad (ya.asDouble());
13300 const double xeps (floatFormat16.ulp(deAbs(xd * (1.0 - ad)), ulps));
13301 const double yeps (floatFormat16.ulp(deAbs(yd * ad), ulps));
13302 const double eps (xeps + yeps);
13304 result = xamd + yad;
13305 min[0] = result - eps;
13306 max[0] = result + eps;
13308 else if (getFlavor() == 2)
13310 const double xd (x.asDouble());
13311 const double yd (y.asDouble());
13312 const double ad (a.asDouble());
13313 const fp16type ymx (yd - xd);
13314 const double ymxd (ymx.asDouble());
13315 const fp16type ymxa (ymxd * ad);
13316 const double ymxad (ymxa.asDouble());
13317 const double xeps (floatFormat16.ulp(deAbs(xd * (1.0 - ad)), ulps));
13318 const double yeps (floatFormat16.ulp(deAbs(yd * ad), ulps));
13319 const double eps (xeps + yeps);
13321 result = xd + ymxad;
13322 min[0] = result - eps;
13323 max[0] = result + eps;
13327 TCU_THROW(InternalError, "Unknown flavor");
13330 out[0] = fp16type(result).bits();
13336 struct fp16SmoothStep : public fp16PerComponent
13338 fp16SmoothStep() : fp16PerComponent()
13340 flavorNames.push_back("FloatCalc");
13341 flavorNames.push_back("EmulatingFP16");
13342 flavorNames.push_back("EmulatingFP16WClamp");
13345 virtual double getULPs(vector<const deFloat16*>& in)
13349 return 4.0; // This is not a precision test. Value is not from spec
13352 template<class fp16type>
13353 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
13355 const fp16type edge0 (*in[0]);
13356 const fp16type edge1 (*in[1]);
13357 const fp16type x (*in[2]);
13358 double result (0.0);
13360 if (edge0.isNaN() || edge1.isNaN() || x.isNaN() || edge0.asDouble() >= edge1.asDouble())
13363 if (edge0.isInf() || edge1.isInf() || x.isInf())
13366 if (getFlavor() == 0)
13368 const float edge0d (edge0.asFloat());
13369 const float edge1d (edge1.asFloat());
13370 const float xd (x.asFloat());
13371 const float sstep (deFloatSmoothStep(edge0d, edge1d, xd));
13375 else if (getFlavor() == 1)
13377 const double edge0d (edge0.asDouble());
13378 const double edge1d (edge1.asDouble());
13379 const double xd (x.asDouble());
13383 else if (xd >= edge1d)
13387 const fp16type a (xd - edge0d);
13388 const fp16type b (edge1d - edge0d);
13389 const fp16type t (a.asDouble() / b.asDouble());
13390 const fp16type t2 (2.0 * t.asDouble());
13391 const fp16type t3 (3.0 - t2.asDouble());
13392 const fp16type t4 (t.asDouble() * t3.asDouble());
13393 const fp16type t5 (t.asDouble() * t4.asDouble());
13395 result = t5.asDouble();
13398 else if (getFlavor() == 2)
13400 const double edge0d (edge0.asDouble());
13401 const double edge1d (edge1.asDouble());
13402 const double xd (x.asDouble());
13403 const fp16type a (xd - edge0d);
13404 const fp16type b (edge1d - edge0d);
13405 const fp16type bi (1.0 / b.asDouble());
13406 const fp16type t0 (a.asDouble() * bi.asDouble());
13407 const double tc (deClamp(t0.asDouble(), 0.0, 1.0));
13408 const fp16type t (tc);
13409 const fp16type t2 (2.0 * t.asDouble());
13410 const fp16type t3 (3.0 - t2.asDouble());
13411 const fp16type t4 (t.asDouble() * t3.asDouble());
13412 const fp16type t5 (t.asDouble() * t4.asDouble());
13414 result = t5.asDouble();
13418 TCU_THROW(InternalError, "Unknown flavor");
13421 out[0] = fp16type(result).bits();
13422 min[0] = getMin(result, getULPs(in));
13423 max[0] = getMax(result, getULPs(in));
13429 struct fp16Fma : public fp16PerComponent
13433 flavorNames.push_back("DoubleCalc");
13434 flavorNames.push_back("EmulatingFP16");
13437 virtual double getULPs(vector<const deFloat16*>& in)
13444 template<class fp16type>
13445 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
13447 DE_ASSERT(in.size() == 3);
13448 DE_ASSERT(getArgCompCount(0) == getOutCompCount());
13449 DE_ASSERT(getArgCompCount(1) == getOutCompCount());
13450 DE_ASSERT(getArgCompCount(2) == getOutCompCount());
13451 DE_ASSERT(getOutCompCount() > 0);
13453 const fp16type a (*in[0]);
13454 const fp16type b (*in[1]);
13455 const fp16type c (*in[2]);
13456 double result (0.0);
13458 if (getFlavor() == 0)
13460 const double ad (a.asDouble());
13461 const double bd (b.asDouble());
13462 const double cd (c.asDouble());
13464 result = deMadd(ad, bd, cd);
13466 else if (getFlavor() == 1)
13468 const double ad (a.asDouble());
13469 const double bd (b.asDouble());
13470 const double cd (c.asDouble());
13471 const fp16type ab (ad * bd);
13472 const fp16type r (ab.asDouble() + cd);
13474 result = r.asDouble();
13478 TCU_THROW(InternalError, "Unknown flavor");
13481 out[0] = fp16type(result).bits();
13482 min[0] = getMin(result, getULPs(in));
13483 max[0] = getMax(result, getULPs(in));
13490 struct fp16AllComponents : public fp16PerComponent
13492 bool callOncePerComponent () { return false; }
13495 struct fp16Length : public fp16AllComponents
13497 fp16Length() : fp16AllComponents()
13499 flavorNames.push_back("EmulatingFP16");
13500 flavorNames.push_back("DoubleCalc");
13503 virtual double getULPs(vector<const deFloat16*>& in)
13510 template<class fp16type>
13511 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
13513 DE_ASSERT(getOutCompCount() == 1);
13514 DE_ASSERT(in.size() == 1);
13516 double result (0.0);
13518 if (getFlavor() == 0)
13522 for (size_t componentNdx = 0; componentNdx < getArgCompCount(0); ++componentNdx)
13524 const fp16type x (in[0][componentNdx]);
13525 const fp16type q (x.asDouble() * x.asDouble());
13527 r = fp16type(r.asDouble() + q.asDouble());
13530 result = deSqrt(r.asDouble());
13532 out[0] = fp16type(result).bits();
13534 else if (getFlavor() == 1)
13538 for (size_t componentNdx = 0; componentNdx < getArgCompCount(0); ++componentNdx)
13540 const fp16type x (in[0][componentNdx]);
13541 const double q (x.asDouble() * x.asDouble());
13546 result = deSqrt(r);
13548 out[0] = fp16type(result).bits();
13552 TCU_THROW(InternalError, "Unknown flavor");
13555 min[0] = getMin(result, getULPs(in));
13556 max[0] = getMax(result, getULPs(in));
13562 struct fp16Distance : public fp16AllComponents
13564 fp16Distance() : fp16AllComponents()
13566 flavorNames.push_back("EmulatingFP16");
13567 flavorNames.push_back("DoubleCalc");
13570 virtual double getULPs(vector<const deFloat16*>& in)
13577 template<class fp16type>
13578 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
13580 DE_ASSERT(getOutCompCount() == 1);
13581 DE_ASSERT(in.size() == 2);
13582 DE_ASSERT(getArgCompCount(0) == getArgCompCount(1));
13584 double result (0.0);
13586 if (getFlavor() == 0)
13590 for (size_t componentNdx = 0; componentNdx < getArgCompCount(0); ++componentNdx)
13592 const fp16type x (in[0][componentNdx]);
13593 const fp16type y (in[1][componentNdx]);
13594 const fp16type d (x.asDouble() - y.asDouble());
13595 const fp16type q (d.asDouble() * d.asDouble());
13597 r = fp16type(r.asDouble() + q.asDouble());
13600 result = deSqrt(r.asDouble());
13602 else if (getFlavor() == 1)
13606 for (size_t componentNdx = 0; componentNdx < getArgCompCount(0); ++componentNdx)
13608 const fp16type x (in[0][componentNdx]);
13609 const fp16type y (in[1][componentNdx]);
13610 const double d (x.asDouble() - y.asDouble());
13611 const double q (d * d);
13616 result = deSqrt(r);
13620 TCU_THROW(InternalError, "Unknown flavor");
13623 out[0] = fp16type(result).bits();
13624 min[0] = getMin(result, getULPs(in));
13625 max[0] = getMax(result, getULPs(in));
13631 struct fp16Cross : public fp16AllComponents
13633 fp16Cross() : fp16AllComponents()
13635 flavorNames.push_back("EmulatingFP16");
13636 flavorNames.push_back("DoubleCalc");
13639 virtual double getULPs(vector<const deFloat16*>& in)
13646 template<class fp16type>
13647 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
13649 DE_ASSERT(getOutCompCount() == 3);
13650 DE_ASSERT(in.size() == 2);
13651 DE_ASSERT(getArgCompCount(0) == 3);
13652 DE_ASSERT(getArgCompCount(1) == 3);
13654 if (getFlavor() == 0)
13656 const fp16type x0 (in[0][0]);
13657 const fp16type x1 (in[0][1]);
13658 const fp16type x2 (in[0][2]);
13659 const fp16type y0 (in[1][0]);
13660 const fp16type y1 (in[1][1]);
13661 const fp16type y2 (in[1][2]);
13662 const fp16type x1y2 (x1.asDouble() * y2.asDouble());
13663 const fp16type y1x2 (y1.asDouble() * x2.asDouble());
13664 const fp16type x2y0 (x2.asDouble() * y0.asDouble());
13665 const fp16type y2x0 (y2.asDouble() * x0.asDouble());
13666 const fp16type x0y1 (x0.asDouble() * y1.asDouble());
13667 const fp16type y0x1 (y0.asDouble() * x1.asDouble());
13669 out[0] = fp16type(x1y2.asDouble() - y1x2.asDouble()).bits();
13670 out[1] = fp16type(x2y0.asDouble() - y2x0.asDouble()).bits();
13671 out[2] = fp16type(x0y1.asDouble() - y0x1.asDouble()).bits();
13673 else if (getFlavor() == 1)
13675 const fp16type x0 (in[0][0]);
13676 const fp16type x1 (in[0][1]);
13677 const fp16type x2 (in[0][2]);
13678 const fp16type y0 (in[1][0]);
13679 const fp16type y1 (in[1][1]);
13680 const fp16type y2 (in[1][2]);
13681 const double x1y2 (x1.asDouble() * y2.asDouble());
13682 const double y1x2 (y1.asDouble() * x2.asDouble());
13683 const double x2y0 (x2.asDouble() * y0.asDouble());
13684 const double y2x0 (y2.asDouble() * x0.asDouble());
13685 const double x0y1 (x0.asDouble() * y1.asDouble());
13686 const double y0x1 (y0.asDouble() * x1.asDouble());
13688 out[0] = fp16type(x1y2 - y1x2).bits();
13689 out[1] = fp16type(x2y0 - y2x0).bits();
13690 out[2] = fp16type(x0y1 - y0x1).bits();
13694 TCU_THROW(InternalError, "Unknown flavor");
13697 for (size_t ndx = 0; ndx < getOutCompCount(); ++ndx)
13698 min[ndx] = getMin(fp16type(out[ndx]).asDouble(), getULPs(in));
13699 for (size_t ndx = 0; ndx < getOutCompCount(); ++ndx)
13700 max[ndx] = getMax(fp16type(out[ndx]).asDouble(), getULPs(in));
13706 struct fp16Normalize : public fp16AllComponents
13708 fp16Normalize() : fp16AllComponents()
13710 flavorNames.push_back("EmulatingFP16");
13711 flavorNames.push_back("DoubleCalc");
13713 // flavorNames will be extended later
13716 virtual void setArgCompCount (size_t argNo, size_t compCount)
13718 DE_ASSERT(argCompCount[argNo] == 0); // Once only
13720 if (argNo == 0 && argCompCount[argNo] == 0)
13722 const size_t maxPermutationsCount = 24u; // Equal to 4!
13723 std::vector<int> indices;
13725 for (size_t componentNdx = 0; componentNdx < compCount; ++componentNdx)
13726 indices.push_back(static_cast<int>(componentNdx));
13728 m_permutations.reserve(maxPermutationsCount);
13730 permutationsFlavorStart = flavorNames.size();
13734 tcu::UVec4 permutation;
13735 std::string name = "Permutted_";
13737 for (size_t componentNdx = 0; componentNdx < compCount; ++componentNdx)
13739 permutation[static_cast<int>(componentNdx)] = indices[componentNdx];
13740 name += de::toString(indices[componentNdx]);
13743 m_permutations.push_back(permutation);
13744 flavorNames.push_back(name);
13746 } while(std::next_permutation(indices.begin(), indices.end()));
13748 permutationsFlavorEnd = flavorNames.size();
13751 fp16AllComponents::setArgCompCount(argNo, compCount);
13753 virtual double getULPs(vector<const deFloat16*>& in)
13760 template<class fp16type>
13761 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
13763 DE_ASSERT(in.size() == 1);
13764 DE_ASSERT(getArgCompCount(0) == getOutCompCount());
13766 if (getFlavor() == 0)
13770 for (size_t componentNdx = 0; componentNdx < getArgCompCount(0); ++componentNdx)
13772 const fp16type x (in[0][componentNdx]);
13773 const fp16type q (x.asDouble() * x.asDouble());
13775 r = fp16type(r.asDouble() + q.asDouble());
13778 r = fp16type(deSqrt(r.asDouble()));
13783 for (size_t componentNdx = 0; componentNdx < getArgCompCount(0); ++componentNdx)
13785 const fp16type x (in[0][componentNdx]);
13787 out[componentNdx] = fp16type(x.asDouble() / r.asDouble()).bits();
13790 else if (getFlavor() == 1)
13794 for (size_t componentNdx = 0; componentNdx < getArgCompCount(0); ++componentNdx)
13796 const fp16type x (in[0][componentNdx]);
13797 const double q (x.asDouble() * x.asDouble());
13807 for (size_t componentNdx = 0; componentNdx < getArgCompCount(0); ++componentNdx)
13809 const fp16type x (in[0][componentNdx]);
13811 out[componentNdx] = fp16type(x.asDouble() / r).bits();
13814 else if (de::inBounds<size_t>(getFlavor(), permutationsFlavorStart, permutationsFlavorEnd))
13816 const int compCount (static_cast<int>(getArgCompCount(0)));
13817 const size_t permutationNdx (getFlavor() - permutationsFlavorStart);
13818 const tcu::UVec4& permutation (m_permutations[permutationNdx]);
13821 for (int permComponentNdx = 0; permComponentNdx < compCount; ++permComponentNdx)
13823 const size_t componentNdx (permutation[permComponentNdx]);
13824 const fp16type x (in[0][componentNdx]);
13825 const fp16type q (x.asDouble() * x.asDouble());
13827 r = fp16type(r.asDouble() + q.asDouble());
13830 r = fp16type(deSqrt(r.asDouble()));
13835 for (int permComponentNdx = 0; permComponentNdx < compCount; ++permComponentNdx)
13837 const size_t componentNdx (permutation[permComponentNdx]);
13838 const fp16type x (in[0][componentNdx]);
13840 out[componentNdx] = fp16type(x.asDouble() / r.asDouble()).bits();
13845 TCU_THROW(InternalError, "Unknown flavor");
13848 for (size_t ndx = 0; ndx < getOutCompCount(); ++ndx)
13849 min[ndx] = getMin(fp16type(out[ndx]).asDouble(), getULPs(in));
13850 for (size_t ndx = 0; ndx < getOutCompCount(); ++ndx)
13851 max[ndx] = getMax(fp16type(out[ndx]).asDouble(), getULPs(in));
13857 std::vector<tcu::UVec4> m_permutations;
13858 size_t permutationsFlavorStart;
13859 size_t permutationsFlavorEnd;
13862 struct fp16FaceForward : public fp16AllComponents
13864 virtual double getULPs(vector<const deFloat16*>& in)
13871 template<class fp16type>
13872 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
13874 DE_ASSERT(in.size() == 3);
13875 DE_ASSERT(getArgCompCount(0) == getOutCompCount());
13876 DE_ASSERT(getArgCompCount(1) == getOutCompCount());
13877 DE_ASSERT(getArgCompCount(2) == getOutCompCount());
13881 for (size_t componentNdx = 0; componentNdx < getArgCompCount(1); ++componentNdx)
13883 const fp16type x (in[1][componentNdx]);
13884 const fp16type y (in[2][componentNdx]);
13885 const double xd (x.asDouble());
13886 const double yd (y.asDouble());
13887 const fp16type q (xd * yd);
13889 dp = fp16type(dp.asDouble() + q.asDouble());
13892 if (dp.isNaN() || dp.isZero())
13895 for (size_t componentNdx = 0; componentNdx < getOutCompCount(); ++componentNdx)
13897 const fp16type n (in[0][componentNdx]);
13899 out[componentNdx] = (dp.signBit() == 1) ? n.bits() : fp16type(-n.asDouble()).bits();
13902 for (size_t ndx = 0; ndx < getOutCompCount(); ++ndx)
13903 min[ndx] = getMin(fp16type(out[ndx]).asDouble(), getULPs(in));
13904 for (size_t ndx = 0; ndx < getOutCompCount(); ++ndx)
13905 max[ndx] = getMax(fp16type(out[ndx]).asDouble(), getULPs(in));
13911 struct fp16Reflect : public fp16AllComponents
13913 fp16Reflect() : fp16AllComponents()
13915 flavorNames.push_back("EmulatingFP16");
13916 flavorNames.push_back("EmulatingFP16+KeepZeroSign");
13917 flavorNames.push_back("FloatCalc");
13918 flavorNames.push_back("FloatCalc+KeepZeroSign");
13919 flavorNames.push_back("EmulatingFP16+2Nfirst");
13920 flavorNames.push_back("EmulatingFP16+2Ifirst");
13923 virtual double getULPs(vector<const deFloat16*>& in)
13927 return 256.0; // This is not a precision test. Value is not from spec
13930 template<class fp16type>
13931 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
13933 DE_ASSERT(in.size() == 2);
13934 DE_ASSERT(getArgCompCount(0) == getOutCompCount());
13935 DE_ASSERT(getArgCompCount(1) == getOutCompCount());
13937 if (getFlavor() < 4)
13939 const bool keepZeroSign ((flavor & 1) != 0 ? true : false);
13940 const bool floatCalc ((flavor & 2) != 0 ? true : false);
13946 for (size_t componentNdx = 0; componentNdx < getArgCompCount(1); ++componentNdx)
13948 const fp16type i (in[0][componentNdx]);
13949 const fp16type n (in[1][componentNdx]);
13950 const float id (i.asFloat());
13951 const float nd (n.asFloat());
13952 const float qd (id * nd);
13955 dp = (componentNdx == 0) ? qd : dp + qd;
13960 for (size_t componentNdx = 0; componentNdx < getOutCompCount(); ++componentNdx)
13962 const fp16type i (in[0][componentNdx]);
13963 const fp16type n (in[1][componentNdx]);
13964 const float dpnd (dp * n.asFloat());
13965 const float dpn2d (2.0f * dpnd);
13966 const float idpn2d (i.asFloat() - dpn2d);
13967 const fp16type result (idpn2d);
13969 out[componentNdx] = result.bits();
13976 for (size_t componentNdx = 0; componentNdx < getArgCompCount(1); ++componentNdx)
13978 const fp16type i (in[0][componentNdx]);
13979 const fp16type n (in[1][componentNdx]);
13980 const double id (i.asDouble());
13981 const double nd (n.asDouble());
13982 const fp16type q (id * nd);
13985 dp = (componentNdx == 0) ? q : fp16type(dp.asDouble() + q.asDouble());
13987 dp = fp16type(dp.asDouble() + q.asDouble());
13993 for (size_t componentNdx = 0; componentNdx < getOutCompCount(); ++componentNdx)
13995 const fp16type i (in[0][componentNdx]);
13996 const fp16type n (in[1][componentNdx]);
13997 const fp16type dpn (dp.asDouble() * n.asDouble());
13998 const fp16type dpn2 (2 * dpn.asDouble());
13999 const fp16type idpn2 (i.asDouble() - dpn2.asDouble());
14001 out[componentNdx] = idpn2.bits();
14005 else if (getFlavor() == 4)
14009 for (size_t componentNdx = 0; componentNdx < getArgCompCount(1); ++componentNdx)
14011 const fp16type i (in[0][componentNdx]);
14012 const fp16type n (in[1][componentNdx]);
14013 const double id (i.asDouble());
14014 const double nd (n.asDouble());
14015 const fp16type q (id * nd);
14017 dp = fp16type(dp.asDouble() + q.asDouble());
14023 for (size_t componentNdx = 0; componentNdx < getOutCompCount(); ++componentNdx)
14025 const fp16type i (in[0][componentNdx]);
14026 const fp16type n (in[1][componentNdx]);
14027 const fp16type n2 (2 * n.asDouble());
14028 const fp16type dpn2 (dp.asDouble() * n2.asDouble());
14029 const fp16type idpn2 (i.asDouble() - dpn2.asDouble());
14031 out[componentNdx] = idpn2.bits();
14034 else if (getFlavor() == 5)
14038 for (size_t componentNdx = 0; componentNdx < getArgCompCount(1); ++componentNdx)
14040 const fp16type i (in[0][componentNdx]);
14041 const fp16type n (in[1][componentNdx]);
14042 const fp16type i2 (2.0 * i.asDouble());
14043 const double i2d (i2.asDouble());
14044 const double nd (n.asDouble());
14045 const fp16type q (i2d * nd);
14047 dp2 = fp16type(dp2.asDouble() + q.asDouble());
14053 for (size_t componentNdx = 0; componentNdx < getOutCompCount(); ++componentNdx)
14055 const fp16type i (in[0][componentNdx]);
14056 const fp16type n (in[1][componentNdx]);
14057 const fp16type dpn2 (dp2.asDouble() * n.asDouble());
14058 const fp16type idpn2 (i.asDouble() - dpn2.asDouble());
14060 out[componentNdx] = idpn2.bits();
14065 TCU_THROW(InternalError, "Unknown flavor");
14068 for (size_t ndx = 0; ndx < getOutCompCount(); ++ndx)
14069 min[ndx] = getMin(fp16type(out[ndx]).asDouble(), getULPs(in));
14070 for (size_t ndx = 0; ndx < getOutCompCount(); ++ndx)
14071 max[ndx] = getMax(fp16type(out[ndx]).asDouble(), getULPs(in));
14077 struct fp16Refract : public fp16AllComponents
14079 fp16Refract() : fp16AllComponents()
14081 flavorNames.push_back("EmulatingFP16");
14082 flavorNames.push_back("EmulatingFP16+KeepZeroSign");
14083 flavorNames.push_back("FloatCalc");
14084 flavorNames.push_back("FloatCalc+KeepZeroSign");
14087 virtual double getULPs(vector<const deFloat16*>& in)
14091 return 8192.0; // This is not a precision test. Value is not from spec
14094 template<class fp16type>
14095 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
14097 DE_ASSERT(in.size() == 3);
14098 DE_ASSERT(getArgCompCount(0) == getOutCompCount());
14099 DE_ASSERT(getArgCompCount(1) == getOutCompCount());
14100 DE_ASSERT(getArgCompCount(2) == 1);
14102 const bool keepZeroSign ((flavor & 1) != 0 ? true : false);
14103 const bool doubleCalc ((flavor & 2) != 0 ? true : false);
14104 const fp16type eta (*in[2]);
14110 for (size_t componentNdx = 0; componentNdx < getArgCompCount(1); ++componentNdx)
14112 const fp16type i (in[0][componentNdx]);
14113 const fp16type n (in[1][componentNdx]);
14114 const double id (i.asDouble());
14115 const double nd (n.asDouble());
14116 const double qd (id * nd);
14119 dp = (componentNdx == 0) ? qd : dp + qd;
14124 const double eta2 (eta.asDouble() * eta.asDouble());
14125 const double dp2 (dp * dp);
14126 const double dp1 (1.0 - dp2);
14127 const double dpe (eta2 * dp1);
14128 const double k (1.0 - dpe);
14132 const fp16type zero (0.0);
14134 for (size_t componentNdx = 0; componentNdx < getOutCompCount(); ++componentNdx)
14135 out[componentNdx] = zero.bits();
14139 const double sk (deSqrt(k));
14141 for (size_t componentNdx = 0; componentNdx < getOutCompCount(); ++componentNdx)
14143 const fp16type i (in[0][componentNdx]);
14144 const fp16type n (in[1][componentNdx]);
14145 const double etai (i.asDouble() * eta.asDouble());
14146 const double etadp (eta.asDouble() * dp);
14147 const double etadpk (etadp + sk);
14148 const double etadpkn (etadpk * n.asDouble());
14149 const double full (etai - etadpkn);
14150 const fp16type result (full);
14152 if (result.isInf())
14155 out[componentNdx] = result.bits();
14163 for (size_t componentNdx = 0; componentNdx < getArgCompCount(1); ++componentNdx)
14165 const fp16type i (in[0][componentNdx]);
14166 const fp16type n (in[1][componentNdx]);
14167 const double id (i.asDouble());
14168 const double nd (n.asDouble());
14169 const fp16type q (id * nd);
14172 dp = (componentNdx == 0) ? q : fp16type(dp.asDouble() + q.asDouble());
14174 dp = fp16type(dp.asDouble() + q.asDouble());
14180 const fp16type eta2(eta.asDouble() * eta.asDouble());
14181 const fp16type dp2 (dp.asDouble() * dp.asDouble());
14182 const fp16type dp1 (1.0 - dp2.asDouble());
14183 const fp16type dpe (eta2.asDouble() * dp1.asDouble());
14184 const fp16type k (1.0 - dpe.asDouble());
14186 if (k.asDouble() < 0.0)
14188 const fp16type zero (0.0);
14190 for (size_t componentNdx = 0; componentNdx < getOutCompCount(); ++componentNdx)
14191 out[componentNdx] = zero.bits();
14195 const fp16type sk (deSqrt(k.asDouble()));
14197 for (size_t componentNdx = 0; componentNdx < getOutCompCount(); ++componentNdx)
14199 const fp16type i (in[0][componentNdx]);
14200 const fp16type n (in[1][componentNdx]);
14201 const fp16type etai (i.asDouble() * eta.asDouble());
14202 const fp16type etadp (eta.asDouble() * dp.asDouble());
14203 const fp16type etadpk (etadp.asDouble() + sk.asDouble());
14204 const fp16type etadpkn (etadpk.asDouble() * n.asDouble());
14205 const fp16type full (etai.asDouble() - etadpkn.asDouble());
14207 if (full.isNaN() || full.isInf())
14210 out[componentNdx] = full.bits();
14215 for (size_t ndx = 0; ndx < getOutCompCount(); ++ndx)
14216 min[ndx] = getMin(fp16type(out[ndx]).asDouble(), getULPs(in));
14217 for (size_t ndx = 0; ndx < getOutCompCount(); ++ndx)
14218 max[ndx] = getMax(fp16type(out[ndx]).asDouble(), getULPs(in));
14224 struct fp16Dot : public fp16AllComponents
14226 fp16Dot() : fp16AllComponents()
14228 flavorNames.push_back("EmulatingFP16");
14229 flavorNames.push_back("FloatCalc");
14230 flavorNames.push_back("DoubleCalc");
14232 // flavorNames will be extended later
14235 virtual void setArgCompCount (size_t argNo, size_t compCount)
14237 DE_ASSERT(argCompCount[argNo] == 0); // Once only
14239 if (argNo == 0 && argCompCount[argNo] == 0)
14241 const size_t maxPermutationsCount = 24u; // Equal to 4!
14242 std::vector<int> indices;
14244 for (size_t componentNdx = 0; componentNdx < compCount; ++componentNdx)
14245 indices.push_back(static_cast<int>(componentNdx));
14247 m_permutations.reserve(maxPermutationsCount);
14249 permutationsFlavorStart = flavorNames.size();
14253 tcu::UVec4 permutation;
14254 std::string name = "Permutted_";
14256 for (size_t componentNdx = 0; componentNdx < compCount; ++componentNdx)
14258 permutation[static_cast<int>(componentNdx)] = indices[componentNdx];
14259 name += de::toString(indices[componentNdx]);
14262 m_permutations.push_back(permutation);
14263 flavorNames.push_back(name);
14265 } while(std::next_permutation(indices.begin(), indices.end()));
14267 permutationsFlavorEnd = flavorNames.size();
14270 fp16AllComponents::setArgCompCount(argNo, compCount);
14273 virtual double getULPs(vector<const deFloat16*>& in)
14277 return 16.0; // This is not a precision test. Value is not from spec
14280 template<class fp16type>
14281 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
14283 DE_ASSERT(in.size() == 2);
14284 DE_ASSERT(getArgCompCount(0) == getArgCompCount(1));
14285 DE_ASSERT(getOutCompCount() == 1);
14287 double result (0.0);
14290 if (getFlavor() == 0)
14294 for (size_t componentNdx = 0; componentNdx < getArgCompCount(1); ++componentNdx)
14296 const fp16type x (in[0][componentNdx]);
14297 const fp16type y (in[1][componentNdx]);
14298 const fp16type q (x.asDouble() * y.asDouble());
14300 dp = fp16type(dp.asDouble() + q.asDouble());
14301 eps += floatFormat16.ulp(q.asDouble(), 2.0);
14304 result = dp.asDouble();
14306 else if (getFlavor() == 1)
14310 for (size_t componentNdx = 0; componentNdx < getArgCompCount(1); ++componentNdx)
14312 const fp16type x (in[0][componentNdx]);
14313 const fp16type y (in[1][componentNdx]);
14314 const float q (x.asFloat() * y.asFloat());
14317 eps += floatFormat16.ulp(static_cast<double>(q), 2.0);
14322 else if (getFlavor() == 2)
14326 for (size_t componentNdx = 0; componentNdx < getArgCompCount(1); ++componentNdx)
14328 const fp16type x (in[0][componentNdx]);
14329 const fp16type y (in[1][componentNdx]);
14330 const double q (x.asDouble() * y.asDouble());
14333 eps += floatFormat16.ulp(q, 2.0);
14338 else if (de::inBounds<size_t>(getFlavor(), permutationsFlavorStart, permutationsFlavorEnd))
14340 const int compCount (static_cast<int>(getArgCompCount(1)));
14341 const size_t permutationNdx (getFlavor() - permutationsFlavorStart);
14342 const tcu::UVec4& permutation (m_permutations[permutationNdx]);
14345 for (int permComponentNdx = 0; permComponentNdx < compCount; ++permComponentNdx)
14347 const size_t componentNdx (permutation[permComponentNdx]);
14348 const fp16type x (in[0][componentNdx]);
14349 const fp16type y (in[1][componentNdx]);
14350 const fp16type q (x.asDouble() * y.asDouble());
14352 dp = fp16type(dp.asDouble() + q.asDouble());
14353 eps += floatFormat16.ulp(q.asDouble(), 2.0);
14356 result = dp.asDouble();
14360 TCU_THROW(InternalError, "Unknown flavor");
14363 out[0] = fp16type(result).bits();
14364 min[0] = result - eps;
14365 max[0] = result + eps;
14371 std::vector<tcu::UVec4> m_permutations;
14372 size_t permutationsFlavorStart;
14373 size_t permutationsFlavorEnd;
14376 struct fp16VectorTimesScalar : public fp16AllComponents
14378 virtual double getULPs(vector<const deFloat16*>& in)
14385 template<class fp16type>
14386 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
14388 DE_ASSERT(in.size() == 2);
14389 DE_ASSERT(getArgCompCount(0) == getOutCompCount());
14390 DE_ASSERT(getArgCompCount(1) == 1);
14392 fp16type s (*in[1]);
14394 for (size_t componentNdx = 0; componentNdx < getArgCompCount(0); ++componentNdx)
14396 const fp16type x (in[0][componentNdx]);
14397 const double result (s.asDouble() * x.asDouble());
14398 const fp16type m (result);
14400 out[componentNdx] = m.bits();
14401 min[componentNdx] = getMin(result, getULPs(in));
14402 max[componentNdx] = getMax(result, getULPs(in));
14409 struct fp16MatrixBase : public fp16AllComponents
14411 deUint32 getComponentValidity ()
14413 return static_cast<deUint32>(-1);
14416 inline size_t getNdx (const size_t rowCount, const size_t col, const size_t row)
14418 const size_t minComponentCount = 0;
14419 const size_t maxComponentCount = 3;
14420 const size_t alignedRowsCount = (rowCount == 3) ? 4 : rowCount;
14422 DE_ASSERT(de::inRange(rowCount, minComponentCount + 1, maxComponentCount + 1));
14423 DE_ASSERT(de::inRange(col, minComponentCount, maxComponentCount));
14424 DE_ASSERT(de::inBounds(row, minComponentCount, rowCount));
14425 DE_UNREF(minComponentCount);
14426 DE_UNREF(maxComponentCount);
14428 return col * alignedRowsCount + row;
14431 deUint32 getComponentMatrixValidityMask (size_t cols, size_t rows)
14433 deUint32 result = 0u;
14435 for (size_t rowNdx = 0; rowNdx < rows; ++rowNdx)
14436 for (size_t colNdx = 0; colNdx < cols; ++colNdx)
14438 const size_t bitNdx = getNdx(rows, colNdx, rowNdx);
14440 DE_ASSERT(bitNdx < sizeof(result) * 8);
14442 result |= (1<<bitNdx);
14449 template<size_t cols, size_t rows>
14450 struct fp16Transpose : public fp16MatrixBase
14452 virtual double getULPs(vector<const deFloat16*>& in)
14459 deUint32 getComponentValidity ()
14461 return getComponentMatrixValidityMask(rows, cols);
14464 template<class fp16type>
14465 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
14467 DE_ASSERT(in.size() == 1);
14469 const size_t alignedCols = (cols == 3) ? 4 : cols;
14470 const size_t alignedRows = (rows == 3) ? 4 : rows;
14471 vector<deFloat16> output (alignedCols * alignedRows, 0);
14473 DE_ASSERT(output.size() == alignedCols * alignedRows);
14475 for (size_t rowNdx = 0; rowNdx < rows; ++rowNdx)
14476 for (size_t colNdx = 0; colNdx < cols; ++colNdx)
14477 output[rowNdx * alignedCols + colNdx] = in[0][colNdx * alignedRows + rowNdx];
14479 deMemcpy(out, &output[0], sizeof(deFloat16) * output.size());
14480 deMemcpy(min, &output[0], sizeof(deFloat16) * output.size());
14481 deMemcpy(max, &output[0], sizeof(deFloat16) * output.size());
14487 template<size_t cols, size_t rows>
14488 struct fp16MatrixTimesScalar : public fp16MatrixBase
14490 virtual double getULPs(vector<const deFloat16*>& in)
14497 deUint32 getComponentValidity ()
14499 return getComponentMatrixValidityMask(cols, rows);
14502 template<class fp16type>
14503 bool calc(vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
14505 DE_ASSERT(in.size() == 2);
14506 DE_ASSERT(getArgCompCount(1) == 1);
14508 const fp16type y (in[1][0]);
14509 const float scalar (y.asFloat());
14510 const size_t alignedCols = (cols == 3) ? 4 : cols;
14511 const size_t alignedRows = (rows == 3) ? 4 : rows;
14513 DE_ASSERT(getArgCompCount(0) == alignedCols * alignedRows);
14514 DE_ASSERT(getOutCompCount() == alignedCols * alignedRows);
14515 DE_UNREF(alignedCols);
14517 for (size_t rowNdx = 0; rowNdx < rows; ++rowNdx)
14518 for (size_t colNdx = 0; colNdx < cols; ++colNdx)
14520 const size_t ndx (colNdx * alignedRows + rowNdx);
14521 const fp16type x (in[0][ndx]);
14522 const double result (scalar * x.asFloat());
14524 out[ndx] = fp16type(result).bits();
14525 min[ndx] = getMin(result, getULPs(in));
14526 max[ndx] = getMax(result, getULPs(in));
14533 template<size_t cols, size_t rows>
14534 struct fp16VectorTimesMatrix : public fp16MatrixBase
14536 fp16VectorTimesMatrix() : fp16MatrixBase()
14538 flavorNames.push_back("EmulatingFP16");
14539 flavorNames.push_back("FloatCalc");
14542 virtual double getULPs (vector<const deFloat16*>& in)
14546 return (8.0 * cols);
14549 deUint32 getComponentValidity ()
14551 return getComponentMatrixValidityMask(cols, 1);
14554 template<class fp16type>
14555 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
14557 DE_ASSERT(in.size() == 2);
14559 const size_t alignedCols = (cols == 3) ? 4 : cols;
14560 const size_t alignedRows = (rows == 3) ? 4 : rows;
14562 DE_ASSERT(getOutCompCount() == cols);
14563 DE_ASSERT(getArgCompCount(0) == rows);
14564 DE_ASSERT(getArgCompCount(1) == alignedCols * alignedRows);
14565 DE_UNREF(alignedCols);
14567 if (getFlavor() == 0)
14569 for (size_t colNdx = 0; colNdx < cols; ++colNdx)
14571 fp16type s (fp16type::zero(1));
14573 for (size_t rowNdx = 0; rowNdx < rows; ++rowNdx)
14575 const fp16type v (in[0][rowNdx]);
14576 const float vf (v.asFloat());
14577 const size_t ndx (colNdx * alignedRows + rowNdx);
14578 const fp16type x (in[1][ndx]);
14579 const float xf (x.asFloat());
14580 const fp16type m (vf * xf);
14582 s = fp16type(s.asFloat() + m.asFloat());
14585 out[colNdx] = s.bits();
14586 min[colNdx] = getMin(s.asDouble(), getULPs(in));
14587 max[colNdx] = getMax(s.asDouble(), getULPs(in));
14590 else if (getFlavor() == 1)
14592 for (size_t colNdx = 0; colNdx < cols; ++colNdx)
14596 for (size_t rowNdx = 0; rowNdx < rows; ++rowNdx)
14598 const fp16type v (in[0][rowNdx]);
14599 const float vf (v.asFloat());
14600 const size_t ndx (colNdx * alignedRows + rowNdx);
14601 const fp16type x (in[1][ndx]);
14602 const float xf (x.asFloat());
14603 const float m (vf * xf);
14608 out[colNdx] = fp16type(s).bits();
14609 min[colNdx] = getMin(static_cast<double>(s), getULPs(in));
14610 max[colNdx] = getMax(static_cast<double>(s), getULPs(in));
14615 TCU_THROW(InternalError, "Unknown flavor");
14622 template<size_t cols, size_t rows>
14623 struct fp16MatrixTimesVector : public fp16MatrixBase
14625 fp16MatrixTimesVector() : fp16MatrixBase()
14627 flavorNames.push_back("EmulatingFP16");
14628 flavorNames.push_back("FloatCalc");
14631 virtual double getULPs (vector<const deFloat16*>& in)
14635 return (8.0 * rows);
14638 deUint32 getComponentValidity ()
14640 return getComponentMatrixValidityMask(rows, 1);
14643 template<class fp16type>
14644 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
14646 DE_ASSERT(in.size() == 2);
14648 const size_t alignedCols = (cols == 3) ? 4 : cols;
14649 const size_t alignedRows = (rows == 3) ? 4 : rows;
14651 DE_ASSERT(getOutCompCount() == rows);
14652 DE_ASSERT(getArgCompCount(0) == alignedCols * alignedRows);
14653 DE_ASSERT(getArgCompCount(1) == cols);
14654 DE_UNREF(alignedCols);
14656 if (getFlavor() == 0)
14658 for (size_t rowNdx = 0; rowNdx < rows; ++rowNdx)
14660 fp16type s (fp16type::zero(1));
14662 for (size_t colNdx = 0; colNdx < cols; ++colNdx)
14664 const size_t ndx (colNdx * alignedRows + rowNdx);
14665 const fp16type x (in[0][ndx]);
14666 const float xf (x.asFloat());
14667 const fp16type v (in[1][colNdx]);
14668 const float vf (v.asFloat());
14669 const fp16type m (vf * xf);
14671 s = fp16type(s.asFloat() + m.asFloat());
14674 out[rowNdx] = s.bits();
14675 min[rowNdx] = getMin(s.asDouble(), getULPs(in));
14676 max[rowNdx] = getMax(s.asDouble(), getULPs(in));
14679 else if (getFlavor() == 1)
14681 for (size_t rowNdx = 0; rowNdx < rows; ++rowNdx)
14685 for (size_t colNdx = 0; colNdx < cols; ++colNdx)
14687 const size_t ndx (colNdx * alignedRows + rowNdx);
14688 const fp16type x (in[0][ndx]);
14689 const float xf (x.asFloat());
14690 const fp16type v (in[1][colNdx]);
14691 const float vf (v.asFloat());
14692 const float m (vf * xf);
14697 out[rowNdx] = fp16type(s).bits();
14698 min[rowNdx] = getMin(static_cast<double>(s), getULPs(in));
14699 max[rowNdx] = getMax(static_cast<double>(s), getULPs(in));
14704 TCU_THROW(InternalError, "Unknown flavor");
14711 template<size_t colsL, size_t rowsL, size_t colsR, size_t rowsR>
14712 struct fp16MatrixTimesMatrix : public fp16MatrixBase
14714 fp16MatrixTimesMatrix() : fp16MatrixBase()
14716 flavorNames.push_back("EmulatingFP16");
14717 flavorNames.push_back("FloatCalc");
14720 virtual double getULPs (vector<const deFloat16*>& in)
14727 deUint32 getComponentValidity ()
14729 return getComponentMatrixValidityMask(colsR, rowsL);
14732 template<class fp16type>
14733 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
14735 DE_STATIC_ASSERT(colsL == rowsR);
14737 DE_ASSERT(in.size() == 2);
14739 const size_t alignedColsL = (colsL == 3) ? 4 : colsL;
14740 const size_t alignedRowsL = (rowsL == 3) ? 4 : rowsL;
14741 const size_t alignedColsR = (colsR == 3) ? 4 : colsR;
14742 const size_t alignedRowsR = (rowsR == 3) ? 4 : rowsR;
14744 DE_ASSERT(getOutCompCount() == alignedColsR * alignedRowsL);
14745 DE_ASSERT(getArgCompCount(0) == alignedColsL * alignedRowsL);
14746 DE_ASSERT(getArgCompCount(1) == alignedColsR * alignedRowsR);
14747 DE_UNREF(alignedColsL);
14748 DE_UNREF(alignedColsR);
14750 if (getFlavor() == 0)
14752 for (size_t rowNdx = 0; rowNdx < rowsL; ++rowNdx)
14754 for (size_t colNdx = 0; colNdx < colsR; ++colNdx)
14756 const size_t ndx (colNdx * alignedRowsL + rowNdx);
14757 fp16type s (fp16type::zero(1));
14759 for (size_t commonNdx = 0; commonNdx < colsL; ++commonNdx)
14761 const size_t ndxl (commonNdx * alignedRowsL + rowNdx);
14762 const fp16type l (in[0][ndxl]);
14763 const float lf (l.asFloat());
14764 const size_t ndxr (colNdx * alignedRowsR + commonNdx);
14765 const fp16type r (in[1][ndxr]);
14766 const float rf (r.asFloat());
14767 const fp16type m (lf * rf);
14769 s = fp16type(s.asFloat() + m.asFloat());
14772 out[ndx] = s.bits();
14773 min[ndx] = getMin(s.asDouble(), getULPs(in));
14774 max[ndx] = getMax(s.asDouble(), getULPs(in));
14778 else if (getFlavor() == 1)
14780 for (size_t rowNdx = 0; rowNdx < rowsL; ++rowNdx)
14782 for (size_t colNdx = 0; colNdx < colsR; ++colNdx)
14784 const size_t ndx (colNdx * alignedRowsL + rowNdx);
14787 for (size_t commonNdx = 0; commonNdx < colsL; ++commonNdx)
14789 const size_t ndxl (commonNdx * alignedRowsL + rowNdx);
14790 const fp16type l (in[0][ndxl]);
14791 const float lf (l.asFloat());
14792 const size_t ndxr (colNdx * alignedRowsR + commonNdx);
14793 const fp16type r (in[1][ndxr]);
14794 const float rf (r.asFloat());
14795 const float m (lf * rf);
14800 out[ndx] = fp16type(s).bits();
14801 min[ndx] = getMin(static_cast<double>(s), getULPs(in));
14802 max[ndx] = getMax(static_cast<double>(s), getULPs(in));
14808 TCU_THROW(InternalError, "Unknown flavor");
14815 template<size_t cols, size_t rows>
14816 struct fp16OuterProduct : public fp16MatrixBase
14818 virtual double getULPs (vector<const deFloat16*>& in)
14825 deUint32 getComponentValidity ()
14827 return getComponentMatrixValidityMask(cols, rows);
14830 template<class fp16type>
14831 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
14833 DE_ASSERT(in.size() == 2);
14835 const size_t alignedCols = (cols == 3) ? 4 : cols;
14836 const size_t alignedRows = (rows == 3) ? 4 : rows;
14838 DE_ASSERT(getArgCompCount(0) == rows);
14839 DE_ASSERT(getArgCompCount(1) == cols);
14840 DE_ASSERT(getOutCompCount() == alignedCols * alignedRows);
14841 DE_UNREF(alignedCols);
14843 for (size_t rowNdx = 0; rowNdx < rows; ++rowNdx)
14845 for (size_t colNdx = 0; colNdx < cols; ++colNdx)
14847 const size_t ndx (colNdx * alignedRows + rowNdx);
14848 const fp16type x (in[0][rowNdx]);
14849 const float xf (x.asFloat());
14850 const fp16type y (in[1][colNdx]);
14851 const float yf (y.asFloat());
14852 const fp16type m (xf * yf);
14854 out[ndx] = m.bits();
14855 min[ndx] = getMin(m.asDouble(), getULPs(in));
14856 max[ndx] = getMax(m.asDouble(), getULPs(in));
14864 template<size_t size>
14865 struct fp16Determinant;
14868 struct fp16Determinant<2> : public fp16MatrixBase
14870 virtual double getULPs (vector<const deFloat16*>& in)
14874 return 128.0; // This is not a precision test. Value is not from spec
14877 deUint32 getComponentValidity ()
14882 template<class fp16type>
14883 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
14885 const size_t cols = 2;
14886 const size_t rows = 2;
14887 const size_t alignedCols = (cols == 3) ? 4 : cols;
14888 const size_t alignedRows = (rows == 3) ? 4 : rows;
14890 DE_ASSERT(in.size() == 1);
14891 DE_ASSERT(getOutCompCount() == 1);
14892 DE_ASSERT(getArgCompCount(0) == alignedRows * alignedCols);
14893 DE_UNREF(alignedCols);
14894 DE_UNREF(alignedRows);
14898 const float a (fp16type(in[0][getNdx(rows, 0, 0)]).asFloat());
14899 const float b (fp16type(in[0][getNdx(rows, 1, 0)]).asFloat());
14900 const float c (fp16type(in[0][getNdx(rows, 0, 1)]).asFloat());
14901 const float d (fp16type(in[0][getNdx(rows, 1, 1)]).asFloat());
14902 const float ad (a * d);
14903 const fp16type adf16 (ad);
14904 const float bc (b * c);
14905 const fp16type bcf16 (bc);
14906 const float r (adf16.asFloat() - bcf16.asFloat());
14907 const fp16type rf16 (r);
14909 out[0] = rf16.bits();
14910 min[0] = getMin(r, getULPs(in));
14911 max[0] = getMax(r, getULPs(in));
14918 struct fp16Determinant<3> : public fp16MatrixBase
14920 virtual double getULPs (vector<const deFloat16*>& in)
14924 return 128.0; // This is not a precision test. Value is not from spec
14927 deUint32 getComponentValidity ()
14932 template<class fp16type>
14933 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
14935 const size_t cols = 3;
14936 const size_t rows = 3;
14937 const size_t alignedCols = (cols == 3) ? 4 : cols;
14938 const size_t alignedRows = (rows == 3) ? 4 : rows;
14940 DE_ASSERT(in.size() == 1);
14941 DE_ASSERT(getOutCompCount() == 1);
14942 DE_ASSERT(getArgCompCount(0) == alignedRows * alignedCols);
14943 DE_UNREF(alignedCols);
14944 DE_UNREF(alignedRows);
14949 const float a (fp16type(in[0][getNdx(rows, 0, 0)]).asFloat());
14950 const float b (fp16type(in[0][getNdx(rows, 1, 0)]).asFloat());
14951 const float c (fp16type(in[0][getNdx(rows, 2, 0)]).asFloat());
14952 const float d (fp16type(in[0][getNdx(rows, 0, 1)]).asFloat());
14953 const float e (fp16type(in[0][getNdx(rows, 1, 1)]).asFloat());
14954 const float f (fp16type(in[0][getNdx(rows, 2, 1)]).asFloat());
14955 const float g (fp16type(in[0][getNdx(rows, 0, 2)]).asFloat());
14956 const float h (fp16type(in[0][getNdx(rows, 1, 2)]).asFloat());
14957 const float i (fp16type(in[0][getNdx(rows, 2, 2)]).asFloat());
14958 const fp16type aei (a * e * i);
14959 const fp16type bfg (b * f * g);
14960 const fp16type cdh (c * d * h);
14961 const fp16type ceg (c * e * g);
14962 const fp16type bdi (b * d * i);
14963 const fp16type afh (a * f * h);
14964 const float r (aei.asFloat() + bfg.asFloat() + cdh.asFloat() - ceg.asFloat() - bdi.asFloat() - afh.asFloat());
14965 const fp16type rf16 (r);
14967 out[0] = rf16.bits();
14968 min[0] = getMin(r, getULPs(in));
14969 max[0] = getMax(r, getULPs(in));
14976 struct fp16Determinant<4> : public fp16MatrixBase
14978 virtual double getULPs (vector<const deFloat16*>& in)
14982 return 128.0; // This is not a precision test. Value is not from spec
14985 deUint32 getComponentValidity ()
14990 template<class fp16type>
14991 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
14993 const size_t rows = 4;
14994 const size_t cols = 4;
14995 const size_t alignedCols = (cols == 3) ? 4 : cols;
14996 const size_t alignedRows = (rows == 3) ? 4 : rows;
14998 DE_ASSERT(in.size() == 1);
14999 DE_ASSERT(getOutCompCount() == 1);
15000 DE_ASSERT(getArgCompCount(0) == alignedRows * alignedCols);
15001 DE_UNREF(alignedCols);
15002 DE_UNREF(alignedRows);
15008 const float a (fp16type(in[0][getNdx(rows, 0, 0)]).asFloat());
15009 const float b (fp16type(in[0][getNdx(rows, 1, 0)]).asFloat());
15010 const float c (fp16type(in[0][getNdx(rows, 2, 0)]).asFloat());
15011 const float d (fp16type(in[0][getNdx(rows, 3, 0)]).asFloat());
15012 const float e (fp16type(in[0][getNdx(rows, 0, 1)]).asFloat());
15013 const float f (fp16type(in[0][getNdx(rows, 1, 1)]).asFloat());
15014 const float g (fp16type(in[0][getNdx(rows, 2, 1)]).asFloat());
15015 const float h (fp16type(in[0][getNdx(rows, 3, 1)]).asFloat());
15016 const float i (fp16type(in[0][getNdx(rows, 0, 2)]).asFloat());
15017 const float j (fp16type(in[0][getNdx(rows, 1, 2)]).asFloat());
15018 const float k (fp16type(in[0][getNdx(rows, 2, 2)]).asFloat());
15019 const float l (fp16type(in[0][getNdx(rows, 3, 2)]).asFloat());
15020 const float m (fp16type(in[0][getNdx(rows, 0, 3)]).asFloat());
15021 const float n (fp16type(in[0][getNdx(rows, 1, 3)]).asFloat());
15022 const float o (fp16type(in[0][getNdx(rows, 2, 3)]).asFloat());
15023 const float p (fp16type(in[0][getNdx(rows, 3, 3)]).asFloat());
15028 const fp16type fkp (f * k * p);
15029 const fp16type gln (g * l * n);
15030 const fp16type hjo (h * j * o);
15031 const fp16type hkn (h * k * n);
15032 const fp16type gjp (g * j * p);
15033 const fp16type flo (f * l * o);
15034 const fp16type detA (a * (fkp.asFloat() + gln.asFloat() + hjo.asFloat() - hkn.asFloat() - gjp.asFloat() - flo.asFloat()));
15039 const fp16type ekp (e * k * p);
15040 const fp16type glm (g * l * m);
15041 const fp16type hio (h * i * o);
15042 const fp16type hkm (h * k * m);
15043 const fp16type gip (g * i * p);
15044 const fp16type elo (e * l * o);
15045 const fp16type detB (b * (ekp.asFloat() + glm.asFloat() + hio.asFloat() - hkm.asFloat() - gip.asFloat() - elo.asFloat()));
15050 const fp16type ejp (e * j * p);
15051 const fp16type flm (f * l * m);
15052 const fp16type hin (h * i * n);
15053 const fp16type hjm (h * j * m);
15054 const fp16type fip (f * i * p);
15055 const fp16type eln (e * l * n);
15056 const fp16type detC (c * (ejp.asFloat() + flm.asFloat() + hin.asFloat() - hjm.asFloat() - fip.asFloat() - eln.asFloat()));
15061 const fp16type ejo (e * j * o);
15062 const fp16type fkm (f * k * m);
15063 const fp16type gin (g * i * n);
15064 const fp16type gjm (g * j * m);
15065 const fp16type fio (f * i * o);
15066 const fp16type ekn (e * k * n);
15067 const fp16type detD (d * (ejo.asFloat() + fkm.asFloat() + gin.asFloat() - gjm.asFloat() - fio.asFloat() - ekn.asFloat()));
15069 const float r (detA.asFloat() - detB.asFloat() + detC.asFloat() - detD.asFloat());
15070 const fp16type rf16 (r);
15072 out[0] = rf16.bits();
15073 min[0] = getMin(r, getULPs(in));
15074 max[0] = getMax(r, getULPs(in));
15080 template<size_t size>
15081 struct fp16Inverse;
15084 struct fp16Inverse<2> : public fp16MatrixBase
15086 virtual double getULPs (vector<const deFloat16*>& in)
15090 return 128.0; // This is not a precision test. Value is not from spec
15093 deUint32 getComponentValidity ()
15095 return getComponentMatrixValidityMask(2, 2);
15098 template<class fp16type>
15099 bool calc (vector<const deFloat16*>& in, deFloat16* out, double* min, double* max)
15101 const size_t cols = 2;
15102 const size_t rows = 2;
15103 const size_t alignedCols = (cols == 3) ? 4 : cols;
15104 const size_t alignedRows = (rows == 3) ? 4 : rows;
15106 DE_ASSERT(in.size() == 1);
15107 DE_ASSERT(getOutCompCount() == alignedRows * alignedCols);
15108 DE_ASSERT(getArgCompCount(0) == alignedRows * alignedCols);
15109 DE_UNREF(alignedCols);
15113 const float a (fp16type(in[0][getNdx(rows, 0, 0)]).asFloat());
15114 const float b (fp16type(in[0][getNdx(rows, 1, 0)]).asFloat());
15115 const float c (fp16type(in[0][getNdx(rows, 0, 1)]).asFloat());
15116 const float d (fp16type(in[0][getNdx(rows, 1, 1)]).asFloat());
15117 const float ad (a * d);
15118 const fp16type adf16 (ad);
15119 const float bc (b * c);
15120 const fp16type bcf16 (bc);
15121 const float det (adf16.asFloat() - bcf16.asFloat());
15122 const fp16type det16 (det);
15124 out[0] = fp16type( d / det16.asFloat()).bits();
15125 out[1] = fp16type(-c / det16.asFloat()).bits();
15126 out[2] = fp16type(-b / det16.asFloat()).bits();
15127 out[3] = fp16type( a / det16.asFloat()).bits();
15129 for (size_t rowNdx = 0; rowNdx < rows; ++rowNdx)
15130 for (size_t colNdx = 0; colNdx < cols; ++colNdx)
15132 const size_t ndx (colNdx * alignedRows + rowNdx);
15133 const fp16type s (out[ndx]);
15135 min[ndx] = getMin(s.asDouble(), getULPs(in));
15136 max[ndx] = getMax(s.asDouble(), getULPs(in));
15143 inline std::string fp16ToString(deFloat16 val)
15145 return tcu::toHex<4>(val).toString() + " (" + de::floatToString(tcu::Float16(val).asFloat(), 10) + ")";
15148 template <size_t RES_COMPONENTS, size_t ARG0_COMPONENTS, size_t ARG1_COMPONENTS, size_t ARG2_COMPONENTS, class TestedArithmeticFunction>
15149 bool compareFP16ArithmeticFunc (const std::vector<Resource>& inputs, const vector<AllocationSp>& outputAllocs, const std::vector<Resource>& expectedOutputs, TestLog& log)
15151 if (inputs.size() < 1 || inputs.size() > 3 || outputAllocs.size() != 1 || expectedOutputs.size() != 1)
15154 const size_t resultStep = (RES_COMPONENTS == 3) ? 4 : RES_COMPONENTS;
15155 const size_t iterationsCount = expectedOutputs[0].getByteSize() / (sizeof(deFloat16) * resultStep);
15156 const size_t inputsSteps[3] =
15158 (ARG0_COMPONENTS == 3) ? 4 : ARG0_COMPONENTS,
15159 (ARG1_COMPONENTS == 3) ? 4 : ARG1_COMPONENTS,
15160 (ARG2_COMPONENTS == 3) ? 4 : ARG2_COMPONENTS,
15163 DE_ASSERT(expectedOutputs[0].getByteSize() > 0);
15164 DE_ASSERT(expectedOutputs[0].getByteSize() == sizeof(deFloat16) * iterationsCount * resultStep);
15166 for (size_t inputNdx = 0; inputNdx < inputs.size(); ++inputNdx)
15168 DE_ASSERT(inputs[inputNdx].getByteSize() > 0);
15169 DE_ASSERT(inputs[inputNdx].getByteSize() == sizeof(deFloat16) * iterationsCount * inputsSteps[inputNdx]);
15172 const deFloat16* const outputAsFP16 = (const deFloat16*)outputAllocs[0]->getHostPtr();
15173 TestedArithmeticFunction func;
15175 func.setOutCompCount(RES_COMPONENTS);
15176 func.setArgCompCount(0, ARG0_COMPONENTS);
15177 func.setArgCompCount(1, ARG1_COMPONENTS);
15178 func.setArgCompCount(2, ARG2_COMPONENTS);
15180 const bool callOncePerComponent = func.callOncePerComponent();
15181 const deUint32 componentValidityMask = func.getComponentValidity();
15182 const size_t denormModesCount = 2;
15183 const char* denormModes[denormModesCount] = { "keep denormal numbers", "flush to zero" };
15184 const size_t successfulRunsPerComponent = denormModesCount * func.getFlavorCount();
15185 bool success = true;
15186 size_t validatedCount = 0;
15188 vector<deUint8> inputBytes[3];
15190 for (size_t inputNdx = 0; inputNdx < inputs.size(); ++inputNdx)
15191 inputs[inputNdx].getBytes(inputBytes[inputNdx]);
15193 const deFloat16* const inputsAsFP16[3] =
15195 inputs.size() >= 1 ? (const deFloat16*)&inputBytes[0][0] : DE_NULL,
15196 inputs.size() >= 2 ? (const deFloat16*)&inputBytes[1][0] : DE_NULL,
15197 inputs.size() >= 3 ? (const deFloat16*)&inputBytes[2][0] : DE_NULL,
15200 for (size_t idx = 0; idx < iterationsCount; ++idx)
15202 std::vector<size_t> successfulRuns (RES_COMPONENTS, successfulRunsPerComponent);
15203 std::vector<std::string> errors (RES_COMPONENTS);
15204 bool iterationValidated (true);
15206 for (size_t denormNdx = 0; denormNdx < 2; ++denormNdx)
15208 for (size_t flavorNdx = 0; flavorNdx < func.getFlavorCount(); ++flavorNdx)
15210 func.setFlavor(flavorNdx);
15212 const deFloat16* iterationOutputFP16 = &outputAsFP16[idx * resultStep];
15213 vector<deFloat16> iterationCalculatedFP16 (resultStep, 0);
15214 vector<double> iterationEdgeMin (resultStep, 0.0);
15215 vector<double> iterationEdgeMax (resultStep, 0.0);
15216 vector<const deFloat16*> arguments;
15218 for (size_t componentNdx = 0; componentNdx < RES_COMPONENTS; ++componentNdx)
15221 bool reportError = false;
15223 if (callOncePerComponent || componentNdx == 0)
15225 bool funcCallResult;
15229 for (size_t inputNdx = 0; inputNdx < inputs.size(); ++inputNdx)
15230 arguments.push_back(&inputsAsFP16[inputNdx][idx * inputsSteps[inputNdx] + componentNdx]);
15232 if (denormNdx == 0)
15233 funcCallResult = func.template calc<tcu::Float16>(arguments, &iterationCalculatedFP16[componentNdx], &iterationEdgeMin[componentNdx], &iterationEdgeMax[componentNdx]);
15235 funcCallResult = func.template calc<tcu::Float16Denormless>(arguments, &iterationCalculatedFP16[componentNdx], &iterationEdgeMin[componentNdx], &iterationEdgeMax[componentNdx]);
15237 if (!funcCallResult)
15239 iterationValidated = false;
15241 if (callOncePerComponent)
15248 if ((componentValidityMask != 0) && (componentValidityMask & (1<<componentNdx)) == 0)
15251 reportError = !compare16BitFloat(iterationCalculatedFP16[componentNdx], iterationOutputFP16[componentNdx], error);
15255 tcu::Float16 expected (iterationCalculatedFP16[componentNdx]);
15256 tcu::Float16 outputted (iterationOutputFP16[componentNdx]);
15258 if (reportError && expected.isNaN())
15259 reportError = false;
15261 if (reportError && !expected.isNaN() && !outputted.isNaN())
15263 if (reportError && !expected.isInf() && !outputted.isInf())
15266 if (expected.bits() == outputted.bits() + 1 || expected.bits() + 1 == outputted.bits())
15267 reportError = false;
15270 if (reportError && expected.isInf())
15272 // RTZ rounding mode returns +/-65504 instead of Inf on overflow
15273 if (expected.sign() == 1 && outputted.bits() == 0x7bff && iterationEdgeMin[componentNdx] <= std::numeric_limits<double>::max())
15274 reportError = false;
15275 else if (expected.sign() == -1 && outputted.bits() == 0xfbff && iterationEdgeMax[componentNdx] >= -std::numeric_limits<double>::max())
15276 reportError = false;
15281 const double outputtedDouble = outputted.asDouble();
15283 DE_ASSERT(iterationEdgeMin[componentNdx] <= iterationEdgeMax[componentNdx]);
15285 if (de::inRange(outputtedDouble, iterationEdgeMin[componentNdx], iterationEdgeMax[componentNdx]))
15286 reportError = false;
15292 const size_t inputsComps[3] =
15298 string inputsValues ("Inputs:");
15299 string flavorName (func.getFlavorCount() == 1 ? "" : string(" flavor ") + de::toString(flavorNdx) + " (" + func.getCurrentFlavorName() + ")");
15300 std::stringstream errStream;
15302 for (size_t inputNdx = 0; inputNdx < inputs.size(); ++inputNdx)
15304 const size_t inputCompsCount = inputsComps[inputNdx];
15306 inputsValues += " [" + de::toString(inputNdx) + "]=(";
15308 for (size_t compNdx = 0; compNdx < inputCompsCount; ++compNdx)
15310 const deFloat16 inputComponentValue = inputsAsFP16[inputNdx][idx * inputsSteps[inputNdx] + compNdx];
15312 inputsValues += fp16ToString(inputComponentValue) + ((compNdx + 1 == inputCompsCount) ? ")": ", ");
15317 << " iteration " << de::toString(idx)
15318 << " component " << de::toString(componentNdx)
15319 << " denormMode " << de::toString(denormNdx)
15320 << " (" << denormModes[denormNdx] << ")"
15321 << " " << flavorName
15322 << " " << inputsValues
15323 << " outputted:" + fp16ToString(iterationOutputFP16[componentNdx])
15324 << " expected:" + fp16ToString(iterationCalculatedFP16[componentNdx])
15325 << " or in range: [" << iterationEdgeMin[componentNdx] << ", " << iterationEdgeMax[componentNdx] << "]."
15326 << " " << error << "."
15329 errors[componentNdx] += errStream.str();
15331 successfulRuns[componentNdx]--;
15338 for (size_t componentNdx = 0; componentNdx < RES_COMPONENTS; ++componentNdx)
15340 // Check if any component has total failure
15341 if (successfulRuns[componentNdx] == 0)
15343 // Test failed in all denorm modes and all flavors for certain component: dump errors
15344 log << TestLog::Message << errors[componentNdx] << TestLog::EndMessage;
15350 if (iterationValidated)
15354 if (validatedCount < 16)
15355 TCU_THROW(InternalError, "Too few samples has been validated.");
15360 // IEEE-754 floating point numbers:
15361 // +--------+------+----------+-------------+
15362 // | binary | sign | exponent | significand |
15363 // +--------+------+----------+-------------+
15364 // | 16-bit | 1 | 5 | 10 |
15365 // +--------+------+----------+-------------+
15366 // | 32-bit | 1 | 8 | 23 |
15367 // +--------+------+----------+-------------+
15371 // 0 000 00 00 0000 0001 (0x0001: 2e-24: minimum positive denormalized)
15372 // 0 000 00 11 1111 1111 (0x03ff: 2e-14 - 2e-24: maximum positive denormalized)
15373 // 0 000 01 00 0000 0000 (0x0400: 2e-14: minimum positive normalized)
15374 // 0 111 10 11 1111 1111 (0x7bff: 65504: maximum positive normalized)
15376 // 0 000 00 00 0000 0000 (0x0000: +0)
15377 // 0 111 11 00 0000 0000 (0x7c00: +Inf)
15378 // 0 000 00 11 1111 0000 (0x03f0: +Denorm)
15379 // 0 000 01 00 0000 0001 (0x0401: +Norm)
15380 // 0 111 11 00 0000 1111 (0x7c0f: +SNaN)
15381 // 0 111 11 11 1111 0000 (0x7ff0: +QNaN)
15382 // Generate and return 16-bit floats and their corresponding 32-bit values.
15384 // The first 14 number pairs are manually picked, while the rest are randomly generated.
15385 // Expected count to be at least 14 (numPicks).
15386 vector<deFloat16> getFloat16a (de::Random& rnd, deUint32 count)
15388 vector<deFloat16> float16;
15390 float16.reserve(count);
15393 float16.push_back(deUint16(0x0000));
15394 float16.push_back(deUint16(0x8000));
15396 float16.push_back(deUint16(0x7c00));
15397 float16.push_back(deUint16(0xfc00));
15399 float16.push_back(deUint16(0x0401));
15400 float16.push_back(deUint16(0x8401));
15401 // Some normal number
15402 float16.push_back(deUint16(0x14cb));
15403 float16.push_back(deUint16(0x94cb));
15404 // Min/max positive normal
15405 float16.push_back(deUint16(0x0400));
15406 float16.push_back(deUint16(0x7bff));
15407 // Min/max negative normal
15408 float16.push_back(deUint16(0x8400));
15409 float16.push_back(deUint16(0xfbff));
15411 float16.push_back(deUint16(0x4248)); // 3.140625
15412 float16.push_back(deUint16(0xb248)); // -3.140625
15414 float16.push_back(deUint16(0x3e48)); // 1.5703125
15415 float16.push_back(deUint16(0xbe48)); // -1.5703125
15416 float16.push_back(deUint16(0x3c00)); // 1.0
15417 float16.push_back(deUint16(0x3800)); // 0.5
15418 // Some useful constants
15419 float16.push_back(tcu::Float16(-2.5f).bits());
15420 float16.push_back(tcu::Float16(-1.0f).bits());
15421 float16.push_back(tcu::Float16( 0.4f).bits());
15422 float16.push_back(tcu::Float16( 2.5f).bits());
15424 const deUint32 numPicks = static_cast<deUint32>(float16.size());
15426 DE_ASSERT(count >= numPicks);
15429 for (deUint32 numIdx = 0; numIdx < count; ++numIdx)
15431 int sign = (rnd.getUint16() % 2 == 0) ? +1 : -1;
15432 int exponent = (rnd.getUint16() % 29) - 14 + 1;
15433 deUint16 mantissa = static_cast<deUint16>(2 * (rnd.getUint16() % 512));
15435 // Exclude power of -14 to avoid denorms
15436 DE_ASSERT(de::inRange(exponent, -13, 15));
15438 float16.push_back(tcu::Float16::constructBits(sign, exponent, mantissa).bits());
15444 static inline vector<deFloat16> getInputData1 (deUint32 seed, size_t count, size_t argNo)
15448 de::Random rnd(seed);
15450 return getFloat16a(rnd, static_cast<deUint32>(count));
15453 static inline vector<deFloat16> getInputData2 (deUint32 seed, size_t count, size_t argNo)
15455 de::Random rnd (seed);
15456 size_t newCount = static_cast<size_t>(deSqrt(double(count)));
15458 DE_ASSERT(newCount * newCount == count);
15460 vector<deFloat16> float16 = getFloat16a(rnd, static_cast<deUint32>(newCount));
15462 return squarize(float16, static_cast<deUint32>(argNo));
15465 static inline vector<deFloat16> getInputData3 (deUint32 seed, size_t count, size_t argNo)
15467 if (argNo == 0 || argNo == 1)
15468 return getInputData2(seed, count, argNo);
15470 return getInputData1(seed<<argNo, count, argNo);
15473 vector<deFloat16> getInputData (deUint32 seed, size_t count, size_t compCount, size_t stride, size_t argCount, size_t argNo)
15477 vector<deFloat16> result;
15481 case 1:result = getInputData1(seed, count, argNo); break;
15482 case 2:result = getInputData2(seed, count, argNo); break;
15483 case 3:result = getInputData3(seed, count, argNo); break;
15484 default: TCU_THROW(InternalError, "Invalid argument count specified");
15487 if (compCount == 3)
15489 const size_t newCount = (3 * count) / 4;
15490 vector<deFloat16> newResult;
15492 newResult.reserve(result.size());
15494 for (size_t ndx = 0; ndx < newCount; ++ndx)
15496 newResult.push_back(result[ndx]);
15499 newResult.push_back(0);
15502 result = newResult;
15505 DE_ASSERT(result.size() == count);
15510 // Generator for functions requiring data in range [1, inf]
15511 vector<deFloat16> getInputDataAC (deUint32 seed, size_t count, size_t compCount, size_t stride, size_t argCount, size_t argNo)
15513 vector<deFloat16> result;
15515 result = getInputData(seed, count, compCount, stride, argCount, argNo);
15517 // Filter out values below 1.0 from upper half of numbers
15518 for (size_t idx = result.size() / 2; idx < result.size(); ++idx)
15520 const float f = tcu::Float16(result[idx]).asFloat();
15523 result[idx] = tcu::Float16(1.0f - f).bits();
15529 // Generator for functions requiring data in range [-1, 1]
15530 vector<deFloat16> getInputDataA (deUint32 seed, size_t count, size_t compCount, size_t stride, size_t argCount, size_t argNo)
15532 vector<deFloat16> result;
15534 result = getInputData(seed, count, compCount, stride, argCount, argNo);
15536 for (size_t idx = result.size() / 2; idx < result.size(); ++idx)
15538 const float f = tcu::Float16(result[idx]).asFloat();
15540 if (!de::inRange(f, -1.0f, 1.0f))
15541 result[idx] = tcu::Float16(deFloatFrac(f)).bits();
15547 // Generator for functions requiring data in range [-pi, pi]
15548 vector<deFloat16> getInputDataPI (deUint32 seed, size_t count, size_t compCount, size_t stride, size_t argCount, size_t argNo)
15550 vector<deFloat16> result;
15552 result = getInputData(seed, count, compCount, stride, argCount, argNo);
15554 for (size_t idx = result.size() / 2; idx < result.size(); ++idx)
15556 const float f = tcu::Float16(result[idx]).asFloat();
15558 if (!de::inRange(f, -DE_PI, DE_PI))
15559 result[idx] = tcu::Float16(fmodf(f, DE_PI)).bits();
15565 // Generator for functions requiring data in range [0, inf]
15566 vector<deFloat16> getInputDataP (deUint32 seed, size_t count, size_t compCount, size_t stride, size_t argCount, size_t argNo)
15568 vector<deFloat16> result;
15570 result = getInputData(seed, count, compCount, stride, argCount, argNo);
15574 for (size_t idx = result.size() / 2; idx < result.size(); ++idx)
15575 result[idx] &= static_cast<deFloat16>(~0x8000);
15581 vector<deFloat16> getInputDataV (deUint32 seed, size_t count, size_t compCount, size_t stride, size_t argCount, size_t argNo)
15584 DE_UNREF(argCount);
15586 vector<deFloat16> result;
15589 result = getInputData2(seed, count, argNo);
15592 const size_t alignedCount = (compCount == 3) ? 4 : compCount;
15593 const size_t newCountX = static_cast<size_t>(deSqrt(double(count * alignedCount)));
15594 const size_t newCountY = count / newCountX;
15595 de::Random rnd (seed);
15596 vector<deFloat16> float16 = getFloat16a(rnd, static_cast<deUint32>(newCountX));
15598 DE_ASSERT(newCountX * newCountX == alignedCount * count);
15600 for (size_t numIdx = 0; numIdx < newCountX; ++numIdx)
15602 const vector<deFloat16> tmp(newCountY, float16[numIdx]);
15604 result.insert(result.end(), tmp.begin(), tmp.end());
15608 DE_ASSERT(result.size() == count);
15613 vector<deFloat16> getInputDataM (deUint32 seed, size_t count, size_t compCount, size_t stride, size_t argCount, size_t argNo)
15615 DE_UNREF(compCount);
15617 DE_UNREF(argCount);
15619 de::Random rnd (seed << argNo);
15620 vector<deFloat16> result;
15622 result = getFloat16a(rnd, static_cast<deUint32>(count));
15624 DE_ASSERT(result.size() == count);
15629 vector<deFloat16> getInputDataD (deUint32 seed, size_t count, size_t compCount, size_t stride, size_t argCount, size_t argNo)
15631 DE_UNREF(compCount);
15632 DE_UNREF(argCount);
15634 de::Random rnd (seed << argNo);
15635 vector<deFloat16> result;
15637 for (deUint32 numIdx = 0; numIdx < count; ++numIdx)
15639 int num = (rnd.getUint16() % 16) - 8;
15641 result.push_back(tcu::Float16(float(num)).bits());
15644 result[0 * stride] = deUint16(0x7c00); // +Inf
15645 result[1 * stride] = deUint16(0xfc00); // -Inf
15647 DE_ASSERT(result.size() == count);
15652 // Generator for smoothstep function
15653 vector<deFloat16> getInputDataSS (deUint32 seed, size_t count, size_t compCount, size_t stride, size_t argCount, size_t argNo)
15655 vector<deFloat16> result;
15657 result = getInputDataD(seed, count, compCount, stride, argCount, argNo);
15661 for (size_t idx = result.size() / 2; idx < result.size(); ++idx)
15663 const float f = tcu::Float16(result[idx]).asFloat();
15666 result[idx] = tcu::Float16(-f).bits();
15672 for (size_t idx = result.size() / 2; idx < result.size(); ++idx)
15674 const float f = tcu::Float16(result[idx]).asFloat();
15677 result[idx] = tcu::Float16(-f).bits();
15684 // Generates normalized vectors for arguments 0 and 1
15685 vector<deFloat16> getInputDataN (deUint32 seed, size_t count, size_t compCount, size_t stride, size_t argCount, size_t argNo)
15687 DE_UNREF(compCount);
15688 DE_UNREF(argCount);
15690 de::Random rnd (seed << argNo);
15691 vector<deFloat16> result;
15693 if (argNo == 0 || argNo == 1)
15695 // The input parameters for the incident vector I and the surface normal N must already be normalized
15696 for (size_t numIdx = 0; numIdx < count; numIdx += stride)
15698 vector <float> unnormolized;
15701 for (size_t compIdx = 0; compIdx < compCount; ++compIdx)
15702 unnormolized.push_back(float((rnd.getUint16() % 16) - 8));
15704 for (size_t compIdx = 0; compIdx < compCount; ++compIdx)
15705 sum += unnormolized[compIdx] * unnormolized[compIdx];
15707 sum = deFloatSqrt(sum);
15709 unnormolized[0] = sum = 1.0f;
15711 for (size_t compIdx = 0; compIdx < compCount; ++compIdx)
15712 result.push_back(tcu::Float16(unnormolized[compIdx] / sum).bits());
15714 for (size_t compIdx = compCount; compIdx < stride; ++compIdx)
15715 result.push_back(0);
15720 // Input parameter eta
15721 for (deUint32 numIdx = 0; numIdx < count; ++numIdx)
15723 int num = (rnd.getUint16() % 16) - 8;
15725 result.push_back(tcu::Float16(float(num)).bits());
15729 DE_ASSERT(result.size() == count);
15734 // Data generator for complex matrix functions like determinant and inverse
15735 vector<deFloat16> getInputDataC (deUint32 seed, size_t count, size_t compCount, size_t stride, size_t argCount, size_t argNo)
15737 DE_UNREF(compCount);
15739 DE_UNREF(argCount);
15741 de::Random rnd (seed << argNo);
15742 vector<deFloat16> result;
15744 for (deUint32 numIdx = 0; numIdx < count; ++numIdx)
15746 int num = (rnd.getUint16() % 16) - 8;
15748 result.push_back(tcu::Float16(float(num)).bits());
15751 DE_ASSERT(result.size() == count);
15756 struct Math16TestType
15758 const char* typePrefix;
15759 const size_t typeComponents;
15760 const size_t typeArrayStride;
15761 const size_t typeStructStride;
15764 enum Math16DataTypes
15783 struct Math16ArgFragments
15785 const char* bodies;
15786 const char* variables;
15787 const char* decorations;
15788 const char* funcVariables;
15791 typedef vector<deFloat16> Math16GetInputData (deUint32 seed, size_t count, size_t compCount, size_t stride, size_t argCount, size_t argNo);
15793 struct Math16TestFunc
15795 const char* funcName;
15796 const char* funcSuffix;
15797 size_t funcArgsCount;
15802 Math16GetInputData* getInputDataFunc;
15803 VerifyIOFunc verifyFunc;
15806 template<class SpecResource>
15807 void createFloat16ArithmeticFuncTest (tcu::TestContext& testCtx, tcu::TestCaseGroup& testGroup, const size_t testTypeIdx, const Math16TestFunc& testFunc)
15809 const int testSpecificSeed = deStringHash(testGroup.getName());
15810 const int seed = testCtx.getCommandLine().getBaseSeed() ^ testSpecificSeed;
15811 const size_t numDataPointsByAxis = 32;
15812 const size_t numDataPoints = numDataPointsByAxis * numDataPointsByAxis;
15813 const char* componentType = "f16";
15814 const Math16TestType testTypes[MATH16_TYPE_LAST] =
15817 { "", 1, 1 * sizeof(deFloat16), 2 * sizeof(deFloat16) },
15818 { "v2", 2, 2 * sizeof(deFloat16), 2 * sizeof(deFloat16) },
15819 { "v3", 3, 4 * sizeof(deFloat16), 4 * sizeof(deFloat16) },
15820 { "v4", 4, 4 * sizeof(deFloat16), 4 * sizeof(deFloat16) },
15821 { "m2x2", 0, 4 * sizeof(deFloat16), 4 * sizeof(deFloat16) },
15822 { "m2x3", 0, 8 * sizeof(deFloat16), 8 * sizeof(deFloat16) },
15823 { "m2x4", 0, 8 * sizeof(deFloat16), 8 * sizeof(deFloat16) },
15824 { "m3x2", 0, 8 * sizeof(deFloat16), 8 * sizeof(deFloat16) },
15825 { "m3x3", 0, 16 * sizeof(deFloat16), 16 * sizeof(deFloat16) },
15826 { "m3x4", 0, 16 * sizeof(deFloat16), 16 * sizeof(deFloat16) },
15827 { "m4x2", 0, 8 * sizeof(deFloat16), 8 * sizeof(deFloat16) },
15828 { "m4x3", 0, 16 * sizeof(deFloat16), 16 * sizeof(deFloat16) },
15829 { "m4x4", 0, 16 * sizeof(deFloat16), 16 * sizeof(deFloat16) },
15832 DE_ASSERT(testTypeIdx == testTypes[testTypeIdx].typeComponents);
15835 const StringTemplate preMain
15837 " %c_i32_ndp = OpConstant %i32 ${num_data_points}\n"
15839 " %f16 = OpTypeFloat 16\n"
15840 " %v2f16 = OpTypeVector %f16 2\n"
15841 " %v3f16 = OpTypeVector %f16 3\n"
15842 " %v4f16 = OpTypeVector %f16 4\n"
15843 " %m2x2f16 = OpTypeMatrix %v2f16 2\n"
15844 " %m2x3f16 = OpTypeMatrix %v3f16 2\n"
15845 " %m2x4f16 = OpTypeMatrix %v4f16 2\n"
15846 " %m3x2f16 = OpTypeMatrix %v2f16 3\n"
15847 " %m3x3f16 = OpTypeMatrix %v3f16 3\n"
15848 " %m3x4f16 = OpTypeMatrix %v4f16 3\n"
15849 " %m4x2f16 = OpTypeMatrix %v2f16 4\n"
15850 " %m4x3f16 = OpTypeMatrix %v3f16 4\n"
15851 " %m4x4f16 = OpTypeMatrix %v4f16 4\n"
15853 " %up_f16 = OpTypePointer Uniform %f16 \n"
15854 " %up_v2f16 = OpTypePointer Uniform %v2f16 \n"
15855 " %up_v3f16 = OpTypePointer Uniform %v3f16 \n"
15856 " %up_v4f16 = OpTypePointer Uniform %v4f16 \n"
15857 " %up_m2x2f16 = OpTypePointer Uniform %m2x2f16\n"
15858 " %up_m2x3f16 = OpTypePointer Uniform %m2x3f16\n"
15859 " %up_m2x4f16 = OpTypePointer Uniform %m2x4f16\n"
15860 " %up_m3x2f16 = OpTypePointer Uniform %m3x2f16\n"
15861 " %up_m3x3f16 = OpTypePointer Uniform %m3x3f16\n"
15862 " %up_m3x4f16 = OpTypePointer Uniform %m3x4f16\n"
15863 " %up_m4x2f16 = OpTypePointer Uniform %m4x2f16\n"
15864 " %up_m4x3f16 = OpTypePointer Uniform %m4x3f16\n"
15865 " %up_m4x4f16 = OpTypePointer Uniform %m4x4f16\n"
15867 " %ra_f16 = OpTypeArray %f16 %c_i32_ndp\n"
15868 " %ra_v2f16 = OpTypeArray %v2f16 %c_i32_ndp\n"
15869 " %ra_v3f16 = OpTypeArray %v3f16 %c_i32_ndp\n"
15870 " %ra_v4f16 = OpTypeArray %v4f16 %c_i32_ndp\n"
15871 " %ra_m2x2f16 = OpTypeArray %m2x2f16 %c_i32_ndp\n"
15872 " %ra_m2x3f16 = OpTypeArray %m2x3f16 %c_i32_ndp\n"
15873 " %ra_m2x4f16 = OpTypeArray %m2x4f16 %c_i32_ndp\n"
15874 " %ra_m3x2f16 = OpTypeArray %m3x2f16 %c_i32_ndp\n"
15875 " %ra_m3x3f16 = OpTypeArray %m3x3f16 %c_i32_ndp\n"
15876 " %ra_m3x4f16 = OpTypeArray %m3x4f16 %c_i32_ndp\n"
15877 " %ra_m4x2f16 = OpTypeArray %m4x2f16 %c_i32_ndp\n"
15878 " %ra_m4x3f16 = OpTypeArray %m4x3f16 %c_i32_ndp\n"
15879 " %ra_m4x4f16 = OpTypeArray %m4x4f16 %c_i32_ndp\n"
15881 " %SSBO_f16 = OpTypeStruct %ra_f16 \n"
15882 " %SSBO_v2f16 = OpTypeStruct %ra_v2f16 \n"
15883 " %SSBO_v3f16 = OpTypeStruct %ra_v3f16 \n"
15884 " %SSBO_v4f16 = OpTypeStruct %ra_v4f16 \n"
15885 " %SSBO_m2x2f16 = OpTypeStruct %ra_m2x2f16\n"
15886 " %SSBO_m2x3f16 = OpTypeStruct %ra_m2x3f16\n"
15887 " %SSBO_m2x4f16 = OpTypeStruct %ra_m2x4f16\n"
15888 " %SSBO_m3x2f16 = OpTypeStruct %ra_m3x2f16\n"
15889 " %SSBO_m3x3f16 = OpTypeStruct %ra_m3x3f16\n"
15890 " %SSBO_m3x4f16 = OpTypeStruct %ra_m3x4f16\n"
15891 " %SSBO_m4x2f16 = OpTypeStruct %ra_m4x2f16\n"
15892 " %SSBO_m4x3f16 = OpTypeStruct %ra_m4x3f16\n"
15893 " %SSBO_m4x4f16 = OpTypeStruct %ra_m4x4f16\n"
15895 "%up_SSBO_f16 = OpTypePointer Uniform %SSBO_f16 \n"
15896 "%up_SSBO_v2f16 = OpTypePointer Uniform %SSBO_v2f16 \n"
15897 "%up_SSBO_v3f16 = OpTypePointer Uniform %SSBO_v3f16 \n"
15898 "%up_SSBO_v4f16 = OpTypePointer Uniform %SSBO_v4f16 \n"
15899 "%up_SSBO_m2x2f16 = OpTypePointer Uniform %SSBO_m2x2f16\n"
15900 "%up_SSBO_m2x3f16 = OpTypePointer Uniform %SSBO_m2x3f16\n"
15901 "%up_SSBO_m2x4f16 = OpTypePointer Uniform %SSBO_m2x4f16\n"
15902 "%up_SSBO_m3x2f16 = OpTypePointer Uniform %SSBO_m3x2f16\n"
15903 "%up_SSBO_m3x3f16 = OpTypePointer Uniform %SSBO_m3x3f16\n"
15904 "%up_SSBO_m3x4f16 = OpTypePointer Uniform %SSBO_m3x4f16\n"
15905 "%up_SSBO_m4x2f16 = OpTypePointer Uniform %SSBO_m4x2f16\n"
15906 "%up_SSBO_m4x3f16 = OpTypePointer Uniform %SSBO_m4x3f16\n"
15907 "%up_SSBO_m4x4f16 = OpTypePointer Uniform %SSBO_m4x4f16\n"
15909 " %fp_v2i32 = OpTypePointer Function %v2i32\n"
15910 " %fp_v3i32 = OpTypePointer Function %v3i32\n"
15911 " %fp_v4i32 = OpTypePointer Function %v4i32\n"
15915 const StringTemplate decoration
15917 "OpDecorate %ra_f16 ArrayStride 2 \n"
15918 "OpDecorate %ra_v2f16 ArrayStride 4 \n"
15919 "OpDecorate %ra_v3f16 ArrayStride 8 \n"
15920 "OpDecorate %ra_v4f16 ArrayStride 8 \n"
15921 "OpDecorate %ra_m2x2f16 ArrayStride 8 \n"
15922 "OpDecorate %ra_m2x3f16 ArrayStride 16\n"
15923 "OpDecorate %ra_m2x4f16 ArrayStride 16\n"
15924 "OpDecorate %ra_m3x2f16 ArrayStride 16\n"
15925 "OpDecorate %ra_m3x3f16 ArrayStride 32\n"
15926 "OpDecorate %ra_m3x4f16 ArrayStride 32\n"
15927 "OpDecorate %ra_m4x2f16 ArrayStride 16\n"
15928 "OpDecorate %ra_m4x3f16 ArrayStride 32\n"
15929 "OpDecorate %ra_m4x4f16 ArrayStride 32\n"
15931 "OpMemberDecorate %SSBO_f16 0 Offset 0\n"
15932 "OpMemberDecorate %SSBO_v2f16 0 Offset 0\n"
15933 "OpMemberDecorate %SSBO_v3f16 0 Offset 0\n"
15934 "OpMemberDecorate %SSBO_v4f16 0 Offset 0\n"
15935 "OpMemberDecorate %SSBO_m2x2f16 0 Offset 0\n"
15936 "OpMemberDecorate %SSBO_m2x3f16 0 Offset 0\n"
15937 "OpMemberDecorate %SSBO_m2x4f16 0 Offset 0\n"
15938 "OpMemberDecorate %SSBO_m3x2f16 0 Offset 0\n"
15939 "OpMemberDecorate %SSBO_m3x3f16 0 Offset 0\n"
15940 "OpMemberDecorate %SSBO_m3x4f16 0 Offset 0\n"
15941 "OpMemberDecorate %SSBO_m4x2f16 0 Offset 0\n"
15942 "OpMemberDecorate %SSBO_m4x3f16 0 Offset 0\n"
15943 "OpMemberDecorate %SSBO_m4x4f16 0 Offset 0\n"
15945 "OpDecorate %SSBO_f16 BufferBlock\n"
15946 "OpDecorate %SSBO_v2f16 BufferBlock\n"
15947 "OpDecorate %SSBO_v3f16 BufferBlock\n"
15948 "OpDecorate %SSBO_v4f16 BufferBlock\n"
15949 "OpDecorate %SSBO_m2x2f16 BufferBlock\n"
15950 "OpDecorate %SSBO_m2x3f16 BufferBlock\n"
15951 "OpDecorate %SSBO_m2x4f16 BufferBlock\n"
15952 "OpDecorate %SSBO_m3x2f16 BufferBlock\n"
15953 "OpDecorate %SSBO_m3x3f16 BufferBlock\n"
15954 "OpDecorate %SSBO_m3x4f16 BufferBlock\n"
15955 "OpDecorate %SSBO_m4x2f16 BufferBlock\n"
15956 "OpDecorate %SSBO_m4x3f16 BufferBlock\n"
15957 "OpDecorate %SSBO_m4x4f16 BufferBlock\n"
15959 "OpMemberDecorate %SSBO_m2x2f16 0 ColMajor\n"
15960 "OpMemberDecorate %SSBO_m2x3f16 0 ColMajor\n"
15961 "OpMemberDecorate %SSBO_m2x4f16 0 ColMajor\n"
15962 "OpMemberDecorate %SSBO_m3x2f16 0 ColMajor\n"
15963 "OpMemberDecorate %SSBO_m3x3f16 0 ColMajor\n"
15964 "OpMemberDecorate %SSBO_m3x4f16 0 ColMajor\n"
15965 "OpMemberDecorate %SSBO_m4x2f16 0 ColMajor\n"
15966 "OpMemberDecorate %SSBO_m4x3f16 0 ColMajor\n"
15967 "OpMemberDecorate %SSBO_m4x4f16 0 ColMajor\n"
15969 "OpMemberDecorate %SSBO_m2x2f16 0 MatrixStride 4\n"
15970 "OpMemberDecorate %SSBO_m2x3f16 0 MatrixStride 8\n"
15971 "OpMemberDecorate %SSBO_m2x4f16 0 MatrixStride 8\n"
15972 "OpMemberDecorate %SSBO_m3x2f16 0 MatrixStride 4\n"
15973 "OpMemberDecorate %SSBO_m3x3f16 0 MatrixStride 8\n"
15974 "OpMemberDecorate %SSBO_m3x4f16 0 MatrixStride 8\n"
15975 "OpMemberDecorate %SSBO_m4x2f16 0 MatrixStride 4\n"
15976 "OpMemberDecorate %SSBO_m4x3f16 0 MatrixStride 8\n"
15977 "OpMemberDecorate %SSBO_m4x4f16 0 MatrixStride 8\n"
15979 "${arg_decorations}"
15982 const StringTemplate testFun
15984 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
15985 " %param = OpFunctionParameter %v4f32\n"
15986 " %entry = OpLabel\n"
15988 " %i = OpVariable %fp_i32 Function\n"
15989 "${arg_infunc_vars}"
15990 " OpStore %i %c_i32_0\n"
15991 " OpBranch %loop\n"
15993 " %loop = OpLabel\n"
15994 " %i_cmp = OpLoad %i32 %i\n"
15995 " %lt = OpSLessThan %bool %i_cmp %c_i32_ndp\n"
15996 " OpLoopMerge %merge %next None\n"
15997 " OpBranchConditional %lt %write %merge\n"
15999 " %write = OpLabel\n"
16000 " %ndx = OpLoad %i32 %i\n"
16004 " OpBranch %next\n"
16006 " %next = OpLabel\n"
16007 " %i_cur = OpLoad %i32 %i\n"
16008 " %i_new = OpIAdd %i32 %i_cur %c_i32_1\n"
16009 " OpStore %i %i_new\n"
16010 " OpBranch %loop\n"
16012 " %merge = OpLabel\n"
16013 " OpReturnValue %param\n"
16017 const Math16ArgFragments argFragment1 =
16019 " %src0 = OpAccessChain %up_${t0} %ssbo_src0 %c_i32_0 %ndx\n"
16020 " %val_src0 = OpLoad %${t0} %src0\n"
16021 " %val_dst = ${op} %${tr} ${ext_inst} %val_src0\n"
16022 " %dst = OpAccessChain %up_${tr} %ssbo_dst %c_i32_0 %ndx\n"
16023 " OpStore %dst %val_dst\n",
16029 const Math16ArgFragments argFragment2 =
16031 " %src0 = OpAccessChain %up_${t0} %ssbo_src0 %c_i32_0 %ndx\n"
16032 " %val_src0 = OpLoad %${t0} %src0\n"
16033 " %src1 = OpAccessChain %up_${t1} %ssbo_src1 %c_i32_0 %ndx\n"
16034 " %val_src1 = OpLoad %${t1} %src1\n"
16035 " %val_dst = ${op} %${tr} ${ext_inst} %val_src0 %val_src1\n"
16036 " %dst = OpAccessChain %up_${tr} %ssbo_dst %c_i32_0 %ndx\n"
16037 " OpStore %dst %val_dst\n",
16043 const Math16ArgFragments argFragment3 =
16045 " %src0 = OpAccessChain %up_${t0} %ssbo_src0 %c_i32_0 %ndx\n"
16046 " %val_src0 = OpLoad %${t0} %src0\n"
16047 " %src1 = OpAccessChain %up_${t1} %ssbo_src1 %c_i32_0 %ndx\n"
16048 " %val_src1 = OpLoad %${t1} %src1\n"
16049 " %src2 = OpAccessChain %up_${t2} %ssbo_src2 %c_i32_0 %ndx\n"
16050 " %val_src2 = OpLoad %${t2} %src2\n"
16051 " %val_dst = ${op} %${tr} ${ext_inst} %val_src0 %val_src1 %val_src2\n"
16052 " %dst = OpAccessChain %up_${tr} %ssbo_dst %c_i32_0 %ndx\n"
16053 " OpStore %dst %val_dst\n",
16059 const Math16ArgFragments argFragmentLdExp =
16061 " %src0 = OpAccessChain %up_${t0} %ssbo_src0 %c_i32_0 %ndx\n"
16062 " %val_src0 = OpLoad %${t0} %src0\n"
16063 " %src1 = OpAccessChain %up_${t1} %ssbo_src1 %c_i32_0 %ndx\n"
16064 " %val_src1 = OpLoad %${t1} %src1\n"
16065 "%val_src1i = OpConvertFToS %${dr}i32 %val_src1\n"
16066 " %val_dst = ${op} %${tr} ${ext_inst} %val_src0 %val_src1i\n"
16067 " %dst = OpAccessChain %up_${tr} %ssbo_dst %c_i32_0 %ndx\n"
16068 " OpStore %dst %val_dst\n",
16077 const Math16ArgFragments argFragmentModfFrac =
16079 " %src0 = OpAccessChain %up_${t0} %ssbo_src0 %c_i32_0 %ndx\n"
16080 " %val_src0 = OpLoad %${t0} %src0\n"
16081 " %val_dst = ${op} %${tr} ${ext_inst} %val_src0 %tmp\n"
16082 " %dst = OpAccessChain %up_${tr} %ssbo_dst %c_i32_0 %ndx\n"
16083 " OpStore %dst %val_dst\n",
16085 " %fp_tmp = OpTypePointer Function %${tr}\n",
16089 " %tmp = OpVariable %fp_tmp Function\n",
16092 const Math16ArgFragments argFragmentModfInt =
16094 " %src0 = OpAccessChain %up_${t0} %ssbo_src0 %c_i32_0 %ndx\n"
16095 " %val_src0 = OpLoad %${t0} %src0\n"
16096 "%val_dummy = ${op} %${tr} ${ext_inst} %val_src0 %tmp\n"
16097 " %tmp0 = OpAccessChain %fp_tmp %tmp\n"
16098 " %val_dst = OpLoad %${tr} %tmp0\n"
16099 " %dst = OpAccessChain %up_${tr} %ssbo_dst %c_i32_0 %ndx\n"
16100 " OpStore %dst %val_dst\n",
16102 " %fp_tmp = OpTypePointer Function %${tr}\n",
16106 " %tmp = OpVariable %fp_tmp Function\n",
16109 const Math16ArgFragments argFragmentModfStruct =
16111 " %src0 = OpAccessChain %up_${t0} %ssbo_src0 %c_i32_0 %ndx\n"
16112 " %val_src0 = OpLoad %${t0} %src0\n"
16113 " %val_tmp = ${op} %st_tmp ${ext_inst} %val_src0\n"
16114 "%tmp_ptr_s = OpAccessChain %fp_tmp %tmp\n"
16115 " OpStore %tmp_ptr_s %val_tmp\n"
16116 "%tmp_ptr_l = OpAccessChain %fp_${tr} %tmp %c_${struct_member}\n"
16117 " %val_dst = OpLoad %${tr} %tmp_ptr_l\n"
16118 " %dst = OpAccessChain %up_${tr} %ssbo_dst %c_i32_0 %ndx\n"
16119 " OpStore %dst %val_dst\n",
16121 " %fp_${tr} = OpTypePointer Function %${tr}\n"
16122 " %st_tmp = OpTypeStruct %${tr} %${tr}\n"
16123 " %fp_tmp = OpTypePointer Function %st_tmp\n"
16124 " %c_frac = OpConstant %i32 0\n"
16125 " %c_int = OpConstant %i32 1\n",
16127 "OpMemberDecorate %st_tmp 0 Offset 0\n"
16128 "OpMemberDecorate %st_tmp 1 Offset ${struct_stride}\n",
16130 " %tmp = OpVariable %fp_tmp Function\n",
16133 const Math16ArgFragments argFragmentFrexpStructS =
16135 " %src0 = OpAccessChain %up_${t0} %ssbo_src0 %c_i32_0 %ndx\n"
16136 " %val_src0 = OpLoad %${t0} %src0\n"
16137 " %val_tmp = ${op} %st_tmp ${ext_inst} %val_src0\n"
16138 "%tmp_ptr_s = OpAccessChain %fp_tmp %tmp\n"
16139 " OpStore %tmp_ptr_s %val_tmp\n"
16140 "%tmp_ptr_l = OpAccessChain %fp_${tr} %tmp %c_i32_0\n"
16141 " %val_dst = OpLoad %${tr} %tmp_ptr_l\n"
16142 " %dst = OpAccessChain %up_${tr} %ssbo_dst %c_i32_0 %ndx\n"
16143 " OpStore %dst %val_dst\n",
16145 " %fp_${tr} = OpTypePointer Function %${tr}\n"
16146 " %st_tmp = OpTypeStruct %${tr} %${dr}i32\n"
16147 " %fp_tmp = OpTypePointer Function %st_tmp\n",
16149 "OpMemberDecorate %st_tmp 0 Offset 0\n"
16150 "OpMemberDecorate %st_tmp 1 Offset ${struct_stride}\n",
16152 " %tmp = OpVariable %fp_tmp Function\n",
16155 const Math16ArgFragments argFragmentFrexpStructE =
16157 " %src0 = OpAccessChain %up_${t0} %ssbo_src0 %c_i32_0 %ndx\n"
16158 " %val_src0 = OpLoad %${t0} %src0\n"
16159 " %val_tmp = ${op} %st_tmp ${ext_inst} %val_src0\n"
16160 "%tmp_ptr_s = OpAccessChain %fp_tmp %tmp\n"
16161 " OpStore %tmp_ptr_s %val_tmp\n"
16162 "%tmp_ptr_l = OpAccessChain %fp_${dr}i32 %tmp %c_i32_1\n"
16163 "%val_dst_i = OpLoad %${dr}i32 %tmp_ptr_l\n"
16164 " %val_dst = OpConvertSToF %${tr} %val_dst_i\n"
16165 " %dst = OpAccessChain %up_${tr} %ssbo_dst %c_i32_0 %ndx\n"
16166 " OpStore %dst %val_dst\n",
16168 " %st_tmp = OpTypeStruct %${tr} %${dr}i32\n"
16169 " %fp_tmp = OpTypePointer Function %st_tmp\n",
16171 "OpMemberDecorate %st_tmp 0 Offset 0\n"
16172 "OpMemberDecorate %st_tmp 1 Offset ${struct_stride}\n",
16174 " %tmp = OpVariable %fp_tmp Function\n",
16177 const Math16ArgFragments argFragmentFrexpS =
16179 " %src0 = OpAccessChain %up_${t0} %ssbo_src0 %c_i32_0 %ndx\n"
16180 " %val_src0 = OpLoad %${t0} %src0\n"
16181 " %out_exp = OpAccessChain %fp_${dr}i32 %tmp\n"
16182 " %val_dst = ${op} %${tr} ${ext_inst} %val_src0 %out_exp\n"
16183 " %dst = OpAccessChain %up_${tr} %ssbo_dst %c_i32_0 %ndx\n"
16184 " OpStore %dst %val_dst\n",
16190 " %tmp = OpVariable %fp_${dr}i32 Function\n",
16193 const Math16ArgFragments argFragmentFrexpE =
16195 " %src0 = OpAccessChain %up_${t0} %ssbo_src0 %c_i32_0 %ndx\n"
16196 " %val_src0 = OpLoad %${t0} %src0\n"
16197 " %out_exp = OpAccessChain %fp_${dr}i32 %tmp\n"
16198 "%val_dummy = ${op} %${tr} ${ext_inst} %val_src0 %out_exp\n"
16199 "%val_dst_i = OpLoad %${dr}i32 %out_exp\n"
16200 " %val_dst = OpConvertSToF %${tr} %val_dst_i\n"
16201 " %dst = OpAccessChain %up_${tr} %ssbo_dst %c_i32_0 %ndx\n"
16202 " OpStore %dst %val_dst\n",
16208 " %tmp = OpVariable %fp_${dr}i32 Function\n",
16211 const Math16TestType& testType = testTypes[testTypeIdx];
16212 const string funcNameString = string(testFunc.funcName) + string(testFunc.funcSuffix);
16213 const string testName = de::toLower(funcNameString);
16214 const Math16ArgFragments* argFragments = DE_NULL;
16215 const size_t typeStructStride = testType.typeStructStride;
16216 const bool extInst = !(testFunc.funcName[0] == 'O' && testFunc.funcName[1] == 'p');
16217 const size_t numFloatsPerArg0Type = testTypes[testFunc.typeArg0].typeArrayStride / sizeof(deFloat16);
16218 const size_t iterations = numDataPoints / numFloatsPerArg0Type;
16219 const size_t numFloatsPerResultType = testTypes[testFunc.typeResult].typeArrayStride / sizeof(deFloat16);
16220 const vector<deFloat16> float16DummyOutput (iterations * numFloatsPerResultType, 0);
16221 VulkanFeatures features;
16222 SpecResource specResource;
16223 map<string, string> specs;
16224 map<string, string> fragments;
16225 vector<string> extensions;
16227 string funcVariables;
16229 string declarations;
16230 string decorations;
16232 switch (testFunc.funcArgsCount)
16236 argFragments = &argFragment1;
16238 if (funcNameString == "ModfFrac") argFragments = &argFragmentModfFrac;
16239 if (funcNameString == "ModfInt") argFragments = &argFragmentModfInt;
16240 if (funcNameString == "ModfStructFrac") argFragments = &argFragmentModfStruct;
16241 if (funcNameString == "ModfStructInt") argFragments = &argFragmentModfStruct;
16242 if (funcNameString == "FrexpS") argFragments = &argFragmentFrexpS;
16243 if (funcNameString == "FrexpE") argFragments = &argFragmentFrexpE;
16244 if (funcNameString == "FrexpStructS") argFragments = &argFragmentFrexpStructS;
16245 if (funcNameString == "FrexpStructE") argFragments = &argFragmentFrexpStructE;
16251 argFragments = &argFragment2;
16253 if (funcNameString == "Ldexp") argFragments = &argFragmentLdExp;
16259 argFragments = &argFragment3;
16265 TCU_THROW(InternalError, "Invalid number of arguments");
16269 if (testFunc.funcArgsCount == 1)
16272 " %ssbo_src0 = OpVariable %up_SSBO_${t0} Uniform\n"
16273 " %ssbo_dst = OpVariable %up_SSBO_${tr} Uniform\n";
16276 "OpDecorate %ssbo_src0 DescriptorSet 0\n"
16277 "OpDecorate %ssbo_src0 Binding 0\n"
16278 "OpDecorate %ssbo_dst DescriptorSet 0\n"
16279 "OpDecorate %ssbo_dst Binding 1\n";
16281 else if (testFunc.funcArgsCount == 2)
16284 " %ssbo_src0 = OpVariable %up_SSBO_${t0} Uniform\n"
16285 " %ssbo_src1 = OpVariable %up_SSBO_${t1} Uniform\n"
16286 " %ssbo_dst = OpVariable %up_SSBO_${tr} Uniform\n";
16289 "OpDecorate %ssbo_src0 DescriptorSet 0\n"
16290 "OpDecorate %ssbo_src0 Binding 0\n"
16291 "OpDecorate %ssbo_src1 DescriptorSet 0\n"
16292 "OpDecorate %ssbo_src1 Binding 1\n"
16293 "OpDecorate %ssbo_dst DescriptorSet 0\n"
16294 "OpDecorate %ssbo_dst Binding 2\n";
16296 else if (testFunc.funcArgsCount == 3)
16299 " %ssbo_src0 = OpVariable %up_SSBO_${t0} Uniform\n"
16300 " %ssbo_src1 = OpVariable %up_SSBO_${t1} Uniform\n"
16301 " %ssbo_src2 = OpVariable %up_SSBO_${t2} Uniform\n"
16302 " %ssbo_dst = OpVariable %up_SSBO_${tr} Uniform\n";
16305 "OpDecorate %ssbo_src0 DescriptorSet 0\n"
16306 "OpDecorate %ssbo_src0 Binding 0\n"
16307 "OpDecorate %ssbo_src1 DescriptorSet 0\n"
16308 "OpDecorate %ssbo_src1 Binding 1\n"
16309 "OpDecorate %ssbo_src2 DescriptorSet 0\n"
16310 "OpDecorate %ssbo_src2 Binding 2\n"
16311 "OpDecorate %ssbo_dst DescriptorSet 0\n"
16312 "OpDecorate %ssbo_dst Binding 3\n";
16316 TCU_THROW(InternalError, "Invalid number of function arguments");
16319 variables += argFragments->variables;
16320 decorations += argFragments->decorations;
16322 specs["dr"] = testTypes[testFunc.typeResult].typePrefix;
16323 specs["d0"] = testTypes[testFunc.typeArg0].typePrefix;
16324 specs["d1"] = testTypes[testFunc.typeArg1].typePrefix;
16325 specs["d2"] = testTypes[testFunc.typeArg2].typePrefix;
16326 specs["tr"] = string(testTypes[testFunc.typeResult].typePrefix) + componentType;
16327 specs["t0"] = string(testTypes[testFunc.typeArg0].typePrefix) + componentType;
16328 specs["t1"] = string(testTypes[testFunc.typeArg1].typePrefix) + componentType;
16329 specs["t2"] = string(testTypes[testFunc.typeArg2].typePrefix) + componentType;
16330 specs["struct_stride"] = de::toString(typeStructStride);
16331 specs["op"] = extInst ? "OpExtInst" : testFunc.funcName;
16332 specs["ext_inst"] = extInst ? string("%ext_import ") + testFunc.funcName : "";
16333 specs["struct_member"] = de::toLower(testFunc.funcSuffix);
16335 variables = StringTemplate(variables).specialize(specs);
16336 decorations = StringTemplate(decorations).specialize(specs);
16337 funcVariables = StringTemplate(argFragments->funcVariables).specialize(specs);
16338 funcCall = StringTemplate(argFragments->bodies).specialize(specs);
16340 specs["num_data_points"] = de::toString(iterations);
16341 specs["arg_vars"] = variables;
16342 specs["arg_decorations"] = decorations;
16343 specs["arg_infunc_vars"] = funcVariables;
16344 specs["arg_func_call"] = funcCall;
16346 fragments["extension"] = "OpExtension \"SPV_KHR_16bit_storage\"\n%ext_import = OpExtInstImport \"GLSL.std.450\"";
16347 fragments["capability"] = "OpCapability Matrix\nOpCapability StorageUniformBufferBlock16";
16348 fragments["decoration"] = decoration.specialize(specs);
16349 fragments["pre_main"] = preMain.specialize(specs);
16350 fragments["testfun"] = testFun.specialize(specs);
16352 for (size_t inputArgNdx = 0; inputArgNdx < testFunc.funcArgsCount; ++inputArgNdx)
16354 const size_t numFloatsPerItem = (inputArgNdx == 0) ? testTypes[testFunc.typeArg0].typeArrayStride / sizeof(deFloat16)
16355 : (inputArgNdx == 1) ? testTypes[testFunc.typeArg1].typeArrayStride / sizeof(deFloat16)
16356 : (inputArgNdx == 2) ? testTypes[testFunc.typeArg2].typeArrayStride / sizeof(deFloat16)
16358 const vector<deFloat16> inputData = testFunc.getInputDataFunc(seed, numFloatsPerItem * iterations, testTypeIdx, numFloatsPerItem, testFunc.funcArgsCount, inputArgNdx);
16360 specResource.inputs.push_back(Resource(BufferSp(new Float16Buffer(inputData)), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
16363 specResource.outputs.push_back(Resource(BufferSp(new Float16Buffer(float16DummyOutput)), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
16364 specResource.verifyIO = testFunc.verifyFunc;
16366 extensions.push_back("VK_KHR_16bit_storage");
16367 extensions.push_back("VK_KHR_shader_float16_int8");
16369 features.ext16BitStorage = EXT16BITSTORAGEFEATURES_UNIFORM_BUFFER_BLOCK;
16370 features.extFloat16Int8 = EXTFLOAT16INT8FEATURES_FLOAT16;
16372 finalizeTestsCreation(specResource, fragments, testCtx, testGroup, testName, features, extensions, IVec3(1, 1, 1));
16375 template<size_t C, class SpecResource>
16376 tcu::TestCaseGroup* createFloat16ArithmeticSet (tcu::TestContext& testCtx)
16378 DE_STATIC_ASSERT(C >= 1 && C <= 4);
16380 const std::string testGroupName (string("arithmetic_") + de::toString(C));
16381 de::MovePtr<tcu::TestCaseGroup> testGroup (new tcu::TestCaseGroup(testCtx, testGroupName.c_str(), "Float 16 arithmetic and related tests"));
16382 const Math16TestFunc testFuncs[] =
16384 { "OpFNegate", "", 1, C, C, 0, 0, &getInputData, compareFP16ArithmeticFunc< C, C, 0, 0, fp16OpFNegate> },
16385 { "Round", "", 1, C, C, 0, 0, &getInputData, compareFP16ArithmeticFunc< C, C, 0, 0, fp16Round> },
16386 { "RoundEven", "", 1, C, C, 0, 0, &getInputData, compareFP16ArithmeticFunc< C, C, 0, 0, fp16RoundEven> },
16387 { "Trunc", "", 1, C, C, 0, 0, &getInputData, compareFP16ArithmeticFunc< C, C, 0, 0, fp16Trunc> },
16388 { "FAbs", "", 1, C, C, 0, 0, &getInputData, compareFP16ArithmeticFunc< C, C, 0, 0, fp16FAbs> },
16389 { "FSign", "", 1, C, C, 0, 0, &getInputData, compareFP16ArithmeticFunc< C, C, 0, 0, fp16FSign> },
16390 { "Floor", "", 1, C, C, 0, 0, &getInputData, compareFP16ArithmeticFunc< C, C, 0, 0, fp16Floor> },
16391 { "Ceil", "", 1, C, C, 0, 0, &getInputData, compareFP16ArithmeticFunc< C, C, 0, 0, fp16Ceil> },
16392 { "Fract", "", 1, C, C, 0, 0, &getInputData, compareFP16ArithmeticFunc< C, C, 0, 0, fp16Fract> },
16393 { "Radians", "", 1, C, C, 0, 0, &getInputData, compareFP16ArithmeticFunc< C, C, 0, 0, fp16Radians> },
16394 { "Degrees", "", 1, C, C, 0, 0, &getInputData, compareFP16ArithmeticFunc< C, C, 0, 0, fp16Degrees> },
16395 { "Sin", "", 1, C, C, 0, 0, &getInputDataPI, compareFP16ArithmeticFunc< C, C, 0, 0, fp16Sin> },
16396 { "Cos", "", 1, C, C, 0, 0, &getInputDataPI, compareFP16ArithmeticFunc< C, C, 0, 0, fp16Cos> },
16397 { "Tan", "", 1, C, C, 0, 0, &getInputDataPI, compareFP16ArithmeticFunc< C, C, 0, 0, fp16Tan> },
16398 { "Asin", "", 1, C, C, 0, 0, &getInputDataA, compareFP16ArithmeticFunc< C, C, 0, 0, fp16Asin> },
16399 { "Acos", "", 1, C, C, 0, 0, &getInputDataA, compareFP16ArithmeticFunc< C, C, 0, 0, fp16Acos> },
16400 { "Atan", "", 1, C, C, 0, 0, &getInputData, compareFP16ArithmeticFunc< C, C, 0, 0, fp16Atan> },
16401 { "Sinh", "", 1, C, C, 0, 0, &getInputData, compareFP16ArithmeticFunc< C, C, 0, 0, fp16Sinh> },
16402 { "Cosh", "", 1, C, C, 0, 0, &getInputData, compareFP16ArithmeticFunc< C, C, 0, 0, fp16Cosh> },
16403 { "Tanh", "", 1, C, C, 0, 0, &getInputData, compareFP16ArithmeticFunc< C, C, 0, 0, fp16Tanh> },
16404 { "Asinh", "", 1, C, C, 0, 0, &getInputData, compareFP16ArithmeticFunc< C, C, 0, 0, fp16Asinh> },
16405 { "Acosh", "", 1, C, C, 0, 0, &getInputDataAC, compareFP16ArithmeticFunc< C, C, 0, 0, fp16Acosh> },
16406 { "Atanh", "", 1, C, C, 0, 0, &getInputDataA, compareFP16ArithmeticFunc< C, C, 0, 0, fp16Atanh> },
16407 { "Exp", "", 1, C, C, 0, 0, &getInputData, compareFP16ArithmeticFunc< C, C, 0, 0, fp16Exp> },
16408 { "Log", "", 1, C, C, 0, 0, &getInputDataP, compareFP16ArithmeticFunc< C, C, 0, 0, fp16Log> },
16409 { "Exp2", "", 1, C, C, 0, 0, &getInputData, compareFP16ArithmeticFunc< C, C, 0, 0, fp16Exp2> },
16410 { "Log2", "", 1, C, C, 0, 0, &getInputDataP, compareFP16ArithmeticFunc< C, C, 0, 0, fp16Log2> },
16411 { "Sqrt", "", 1, C, C, 0, 0, &getInputDataP, compareFP16ArithmeticFunc< C, C, 0, 0, fp16Sqrt> },
16412 { "InverseSqrt", "", 1, C, C, 0, 0, &getInputDataP, compareFP16ArithmeticFunc< C, C, 0, 0, fp16InverseSqrt> },
16413 { "Modf", "Frac", 1, C, C, 0, 0, &getInputData, compareFP16ArithmeticFunc< C, C, 0, 0, fp16ModfFrac> },
16414 { "Modf", "Int", 1, C, C, 0, 0, &getInputData, compareFP16ArithmeticFunc< C, C, 0, 0, fp16ModfInt> },
16415 { "ModfStruct", "Frac", 1, C, C, 0, 0, &getInputData, compareFP16ArithmeticFunc< C, C, 0, 0, fp16ModfFrac> },
16416 { "ModfStruct", "Int", 1, C, C, 0, 0, &getInputData, compareFP16ArithmeticFunc< C, C, 0, 0, fp16ModfInt> },
16417 { "Frexp", "S", 1, C, C, 0, 0, &getInputData, compareFP16ArithmeticFunc< C, C, 0, 0, fp16FrexpS> },
16418 { "Frexp", "E", 1, C, C, 0, 0, &getInputData, compareFP16ArithmeticFunc< C, C, 0, 0, fp16FrexpE> },
16419 { "FrexpStruct", "S", 1, C, C, 0, 0, &getInputData, compareFP16ArithmeticFunc< C, C, 0, 0, fp16FrexpS> },
16420 { "FrexpStruct", "E", 1, C, C, 0, 0, &getInputData, compareFP16ArithmeticFunc< C, C, 0, 0, fp16FrexpE> },
16421 { "OpFAdd", "", 2, C, C, C, 0, &getInputData, compareFP16ArithmeticFunc< C, C, C, 0, fp16OpFAdd> },
16422 { "OpFSub", "", 2, C, C, C, 0, &getInputData, compareFP16ArithmeticFunc< C, C, C, 0, fp16OpFSub> },
16423 { "OpFMul", "", 2, C, C, C, 0, &getInputData, compareFP16ArithmeticFunc< C, C, C, 0, fp16OpFMul> },
16424 { "OpFDiv", "", 2, C, C, C, 0, &getInputData, compareFP16ArithmeticFunc< C, C, C, 0, fp16OpFDiv> },
16425 { "Atan2", "", 2, C, C, C, 0, &getInputData, compareFP16ArithmeticFunc< C, C, C, 0, fp16Atan2> },
16426 { "Pow", "", 2, C, C, C, 0, &getInputDataP, compareFP16ArithmeticFunc< C, C, C, 0, fp16Pow> },
16427 { "FMin", "", 2, C, C, C, 0, &getInputData, compareFP16ArithmeticFunc< C, C, C, 0, fp16FMin> },
16428 { "FMax", "", 2, C, C, C, 0, &getInputData, compareFP16ArithmeticFunc< C, C, C, 0, fp16FMax> },
16429 { "Step", "", 2, C, C, C, 0, &getInputData, compareFP16ArithmeticFunc< C, C, C, 0, fp16Step> },
16430 { "Ldexp", "", 2, C, C, C, 0, &getInputData, compareFP16ArithmeticFunc< C, C, C, 0, fp16Ldexp> },
16431 { "FClamp", "", 3, C, C, C, C, &getInputData, compareFP16ArithmeticFunc< C, C, C, C, fp16FClamp> },
16432 { "FMix", "", 3, C, C, C, C, &getInputDataD, compareFP16ArithmeticFunc< C, C, C, C, fp16FMix> },
16433 { "SmoothStep", "", 3, C, C, C, C, &getInputDataSS, compareFP16ArithmeticFunc< C, C, C, C, fp16SmoothStep> },
16434 { "Fma", "", 3, C, C, C, C, &getInputData, compareFP16ArithmeticFunc< C, C, C, C, fp16Fma> },
16435 { "Length", "", 1, 1, C, 0, 0, &getInputData, compareFP16ArithmeticFunc< 1, C, 0, 0, fp16Length> },
16436 { "Distance", "", 2, 1, C, C, 0, &getInputData, compareFP16ArithmeticFunc< 1, C, C, 0, fp16Distance> },
16437 { "Cross", "", 2, C, C, C, 0, &getInputDataD, compareFP16ArithmeticFunc< C, C, C, 0, fp16Cross> },
16438 { "Normalize", "", 1, C, C, 0, 0, &getInputData, compareFP16ArithmeticFunc< C, C, 0, 0, fp16Normalize> },
16439 { "FaceForward", "", 3, C, C, C, C, &getInputDataD, compareFP16ArithmeticFunc< C, C, C, C, fp16FaceForward> },
16440 { "Reflect", "", 2, C, C, C, 0, &getInputDataD, compareFP16ArithmeticFunc< C, C, C, 0, fp16Reflect> },
16441 { "Refract", "", 3, C, C, C, 1, &getInputDataN, compareFP16ArithmeticFunc< C, C, C, 1, fp16Refract> },
16442 { "OpDot", "", 2, 1, C, C, 0, &getInputDataD, compareFP16ArithmeticFunc< 1, C, C, 0, fp16Dot> },
16443 { "OpVectorTimesScalar", "", 2, C, C, 1, 0, &getInputDataV, compareFP16ArithmeticFunc< C, C, 1, 0, fp16VectorTimesScalar> },
16446 for (deUint32 testFuncIdx = 0; testFuncIdx < DE_LENGTH_OF_ARRAY(testFuncs); ++testFuncIdx)
16448 const Math16TestFunc& testFunc = testFuncs[testFuncIdx];
16449 const string funcNameString = testFunc.funcName;
16451 if ((C != 3) && funcNameString == "Cross")
16454 if ((C < 2) && funcNameString == "OpDot")
16457 if ((C < 2) && funcNameString == "OpVectorTimesScalar")
16460 createFloat16ArithmeticFuncTest<SpecResource>(testCtx, *testGroup.get(), C, testFunc);
16463 return testGroup.release();
16466 template<class SpecResource>
16467 tcu::TestCaseGroup* createFloat16ArithmeticSet (tcu::TestContext& testCtx)
16469 const std::string testGroupName ("arithmetic");
16470 de::MovePtr<tcu::TestCaseGroup> testGroup (new tcu::TestCaseGroup(testCtx, testGroupName.c_str(), "Float 16 arithmetic and related tests"));
16471 const Math16TestFunc testFuncs[] =
16473 { "OpTranspose", "2x2", 1, MAT2X2, MAT2X2, 0, 0, &getInputDataM, compareFP16ArithmeticFunc< 4, 4, 0, 0, fp16Transpose<2,2> > },
16474 { "OpTranspose", "3x2", 1, MAT2X3, MAT3X2, 0, 0, &getInputDataM, compareFP16ArithmeticFunc< 8, 8, 0, 0, fp16Transpose<3,2> > },
16475 { "OpTranspose", "4x2", 1, MAT2X4, MAT4X2, 0, 0, &getInputDataM, compareFP16ArithmeticFunc< 8, 8, 0, 0, fp16Transpose<4,2> > },
16476 { "OpTranspose", "2x3", 1, MAT3X2, MAT2X3, 0, 0, &getInputDataM, compareFP16ArithmeticFunc< 8, 8, 0, 0, fp16Transpose<2,3> > },
16477 { "OpTranspose", "3x3", 1, MAT3X3, MAT3X3, 0, 0, &getInputDataM, compareFP16ArithmeticFunc< 16, 16, 0, 0, fp16Transpose<3,3> > },
16478 { "OpTranspose", "4x3", 1, MAT3X4, MAT4X3, 0, 0, &getInputDataM, compareFP16ArithmeticFunc< 16, 16, 0, 0, fp16Transpose<4,3> > },
16479 { "OpTranspose", "2x4", 1, MAT4X2, MAT2X4, 0, 0, &getInputDataM, compareFP16ArithmeticFunc< 8, 8, 0, 0, fp16Transpose<2,4> > },
16480 { "OpTranspose", "3x4", 1, MAT4X3, MAT3X4, 0, 0, &getInputDataM, compareFP16ArithmeticFunc< 16, 16, 0, 0, fp16Transpose<3,4> > },
16481 { "OpTranspose", "4x4", 1, MAT4X4, MAT4X4, 0, 0, &getInputDataM, compareFP16ArithmeticFunc< 16, 16, 0, 0, fp16Transpose<4,4> > },
16482 { "OpMatrixTimesScalar", "2x2", 2, MAT2X2, MAT2X2, 1, 0, &getInputDataD, compareFP16ArithmeticFunc< 4, 4, 1, 0, fp16MatrixTimesScalar<2,2> > },
16483 { "OpMatrixTimesScalar", "2x3", 2, MAT2X3, MAT2X3, 1, 0, &getInputDataD, compareFP16ArithmeticFunc< 8, 8, 1, 0, fp16MatrixTimesScalar<2,3> > },
16484 { "OpMatrixTimesScalar", "2x4", 2, MAT2X4, MAT2X4, 1, 0, &getInputDataD, compareFP16ArithmeticFunc< 8, 8, 1, 0, fp16MatrixTimesScalar<2,4> > },
16485 { "OpMatrixTimesScalar", "3x2", 2, MAT3X2, MAT3X2, 1, 0, &getInputDataD, compareFP16ArithmeticFunc< 8, 8, 1, 0, fp16MatrixTimesScalar<3,2> > },
16486 { "OpMatrixTimesScalar", "3x3", 2, MAT3X3, MAT3X3, 1, 0, &getInputDataD, compareFP16ArithmeticFunc< 16, 16, 1, 0, fp16MatrixTimesScalar<3,3> > },
16487 { "OpMatrixTimesScalar", "3x4", 2, MAT3X4, MAT3X4, 1, 0, &getInputDataD, compareFP16ArithmeticFunc< 16, 16, 1, 0, fp16MatrixTimesScalar<3,4> > },
16488 { "OpMatrixTimesScalar", "4x2", 2, MAT4X2, MAT4X2, 1, 0, &getInputDataD, compareFP16ArithmeticFunc< 8, 8, 1, 0, fp16MatrixTimesScalar<4,2> > },
16489 { "OpMatrixTimesScalar", "4x3", 2, MAT4X3, MAT4X3, 1, 0, &getInputDataD, compareFP16ArithmeticFunc< 16, 16, 1, 0, fp16MatrixTimesScalar<4,3> > },
16490 { "OpMatrixTimesScalar", "4x4", 2, MAT4X4, MAT4X4, 1, 0, &getInputDataD, compareFP16ArithmeticFunc< 16, 16, 1, 0, fp16MatrixTimesScalar<4,4> > },
16491 { "OpVectorTimesMatrix", "2x2", 2, VEC2, VEC2, MAT2X2, 0, &getInputDataD, compareFP16ArithmeticFunc< 2, 2, 4, 0, fp16VectorTimesMatrix<2,2> > },
16492 { "OpVectorTimesMatrix", "2x3", 2, VEC2, VEC3, MAT2X3, 0, &getInputDataD, compareFP16ArithmeticFunc< 2, 3, 8, 0, fp16VectorTimesMatrix<2,3> > },
16493 { "OpVectorTimesMatrix", "2x4", 2, VEC2, VEC4, MAT2X4, 0, &getInputDataD, compareFP16ArithmeticFunc< 2, 4, 8, 0, fp16VectorTimesMatrix<2,4> > },
16494 { "OpVectorTimesMatrix", "3x2", 2, VEC3, VEC2, MAT3X2, 0, &getInputDataD, compareFP16ArithmeticFunc< 3, 2, 8, 0, fp16VectorTimesMatrix<3,2> > },
16495 { "OpVectorTimesMatrix", "3x3", 2, VEC3, VEC3, MAT3X3, 0, &getInputDataD, compareFP16ArithmeticFunc< 3, 3, 16, 0, fp16VectorTimesMatrix<3,3> > },
16496 { "OpVectorTimesMatrix", "3x4", 2, VEC3, VEC4, MAT3X4, 0, &getInputDataD, compareFP16ArithmeticFunc< 3, 4, 16, 0, fp16VectorTimesMatrix<3,4> > },
16497 { "OpVectorTimesMatrix", "4x2", 2, VEC4, VEC2, MAT4X2, 0, &getInputDataD, compareFP16ArithmeticFunc< 4, 2, 8, 0, fp16VectorTimesMatrix<4,2> > },
16498 { "OpVectorTimesMatrix", "4x3", 2, VEC4, VEC3, MAT4X3, 0, &getInputDataD, compareFP16ArithmeticFunc< 4, 3, 16, 0, fp16VectorTimesMatrix<4,3> > },
16499 { "OpVectorTimesMatrix", "4x4", 2, VEC4, VEC4, MAT4X4, 0, &getInputDataD, compareFP16ArithmeticFunc< 4, 4, 16, 0, fp16VectorTimesMatrix<4,4> > },
16500 { "OpMatrixTimesVector", "2x2", 2, VEC2, MAT2X2, VEC2, 0, &getInputDataD, compareFP16ArithmeticFunc< 2, 4, 2, 0, fp16MatrixTimesVector<2,2> > },
16501 { "OpMatrixTimesVector", "2x3", 2, VEC3, MAT2X3, VEC2, 0, &getInputDataD, compareFP16ArithmeticFunc< 3, 8, 2, 0, fp16MatrixTimesVector<2,3> > },
16502 { "OpMatrixTimesVector", "2x4", 2, VEC4, MAT2X4, VEC2, 0, &getInputDataD, compareFP16ArithmeticFunc< 4, 8, 2, 0, fp16MatrixTimesVector<2,4> > },
16503 { "OpMatrixTimesVector", "3x2", 2, VEC2, MAT3X2, VEC3, 0, &getInputDataD, compareFP16ArithmeticFunc< 2, 8, 3, 0, fp16MatrixTimesVector<3,2> > },
16504 { "OpMatrixTimesVector", "3x3", 2, VEC3, MAT3X3, VEC3, 0, &getInputDataD, compareFP16ArithmeticFunc< 3, 16, 3, 0, fp16MatrixTimesVector<3,3> > },
16505 { "OpMatrixTimesVector", "3x4", 2, VEC4, MAT3X4, VEC3, 0, &getInputDataD, compareFP16ArithmeticFunc< 4, 16, 3, 0, fp16MatrixTimesVector<3,4> > },
16506 { "OpMatrixTimesVector", "4x2", 2, VEC2, MAT4X2, VEC4, 0, &getInputDataD, compareFP16ArithmeticFunc< 2, 8, 4, 0, fp16MatrixTimesVector<4,2> > },
16507 { "OpMatrixTimesVector", "4x3", 2, VEC3, MAT4X3, VEC4, 0, &getInputDataD, compareFP16ArithmeticFunc< 3, 16, 4, 0, fp16MatrixTimesVector<4,3> > },
16508 { "OpMatrixTimesVector", "4x4", 2, VEC4, MAT4X4, VEC4, 0, &getInputDataD, compareFP16ArithmeticFunc< 4, 16, 4, 0, fp16MatrixTimesVector<4,4> > },
16509 { "OpMatrixTimesMatrix", "2x2_2x2", 2, MAT2X2, MAT2X2, MAT2X2, 0, &getInputDataD, compareFP16ArithmeticFunc< 4, 4, 4, 0, fp16MatrixTimesMatrix<2,2,2,2> > },
16510 { "OpMatrixTimesMatrix", "2x2_3x2", 2, MAT3X2, MAT2X2, MAT3X2, 0, &getInputDataD, compareFP16ArithmeticFunc< 8, 4, 8, 0, fp16MatrixTimesMatrix<2,2,3,2> > },
16511 { "OpMatrixTimesMatrix", "2x2_4x2", 2, MAT4X2, MAT2X2, MAT4X2, 0, &getInputDataD, compareFP16ArithmeticFunc< 8, 4, 8, 0, fp16MatrixTimesMatrix<2,2,4,2> > },
16512 { "OpMatrixTimesMatrix", "2x3_2x2", 2, MAT2X3, MAT2X3, MAT2X2, 0, &getInputDataD, compareFP16ArithmeticFunc< 8, 8, 4, 0, fp16MatrixTimesMatrix<2,3,2,2> > },
16513 { "OpMatrixTimesMatrix", "2x3_3x2", 2, MAT3X3, MAT2X3, MAT3X2, 0, &getInputDataD, compareFP16ArithmeticFunc< 16, 8, 8, 0, fp16MatrixTimesMatrix<2,3,3,2> > },
16514 { "OpMatrixTimesMatrix", "2x3_4x2", 2, MAT4X3, MAT2X3, MAT4X2, 0, &getInputDataD, compareFP16ArithmeticFunc< 16, 8, 8, 0, fp16MatrixTimesMatrix<2,3,4,2> > },
16515 { "OpMatrixTimesMatrix", "2x4_2x2", 2, MAT2X4, MAT2X4, MAT2X2, 0, &getInputDataD, compareFP16ArithmeticFunc< 8, 8, 4, 0, fp16MatrixTimesMatrix<2,4,2,2> > },
16516 { "OpMatrixTimesMatrix", "2x4_3x2", 2, MAT3X4, MAT2X4, MAT3X2, 0, &getInputDataD, compareFP16ArithmeticFunc< 16, 8, 8, 0, fp16MatrixTimesMatrix<2,4,3,2> > },
16517 { "OpMatrixTimesMatrix", "2x4_4x2", 2, MAT4X4, MAT2X4, MAT4X2, 0, &getInputDataD, compareFP16ArithmeticFunc< 16, 8, 8, 0, fp16MatrixTimesMatrix<2,4,4,2> > },
16518 { "OpMatrixTimesMatrix", "3x2_2x3", 2, MAT2X2, MAT3X2, MAT2X3, 0, &getInputDataD, compareFP16ArithmeticFunc< 4, 8, 8, 0, fp16MatrixTimesMatrix<3,2,2,3> > },
16519 { "OpMatrixTimesMatrix", "3x2_3x3", 2, MAT3X2, MAT3X2, MAT3X3, 0, &getInputDataD, compareFP16ArithmeticFunc< 8, 8, 16, 0, fp16MatrixTimesMatrix<3,2,3,3> > },
16520 { "OpMatrixTimesMatrix", "3x2_4x3", 2, MAT4X2, MAT3X2, MAT4X3, 0, &getInputDataD, compareFP16ArithmeticFunc< 8, 8, 16, 0, fp16MatrixTimesMatrix<3,2,4,3> > },
16521 { "OpMatrixTimesMatrix", "3x3_2x3", 2, MAT2X3, MAT3X3, MAT2X3, 0, &getInputDataD, compareFP16ArithmeticFunc< 8, 16, 8, 0, fp16MatrixTimesMatrix<3,3,2,3> > },
16522 { "OpMatrixTimesMatrix", "3x3_3x3", 2, MAT3X3, MAT3X3, MAT3X3, 0, &getInputDataD, compareFP16ArithmeticFunc< 16, 16, 16, 0, fp16MatrixTimesMatrix<3,3,3,3> > },
16523 { "OpMatrixTimesMatrix", "3x3_4x3", 2, MAT4X3, MAT3X3, MAT4X3, 0, &getInputDataD, compareFP16ArithmeticFunc< 16, 16, 16, 0, fp16MatrixTimesMatrix<3,3,4,3> > },
16524 { "OpMatrixTimesMatrix", "3x4_2x3", 2, MAT2X4, MAT3X4, MAT2X3, 0, &getInputDataD, compareFP16ArithmeticFunc< 8, 16, 8, 0, fp16MatrixTimesMatrix<3,4,2,3> > },
16525 { "OpMatrixTimesMatrix", "3x4_3x3", 2, MAT3X4, MAT3X4, MAT3X3, 0, &getInputDataD, compareFP16ArithmeticFunc< 16, 16, 16, 0, fp16MatrixTimesMatrix<3,4,3,3> > },
16526 { "OpMatrixTimesMatrix", "3x4_4x3", 2, MAT4X4, MAT3X4, MAT4X3, 0, &getInputDataD, compareFP16ArithmeticFunc< 16, 16, 16, 0, fp16MatrixTimesMatrix<3,4,4,3> > },
16527 { "OpMatrixTimesMatrix", "4x2_2x4", 2, MAT2X2, MAT4X2, MAT2X4, 0, &getInputDataD, compareFP16ArithmeticFunc< 4, 8, 8, 0, fp16MatrixTimesMatrix<4,2,2,4> > },
16528 { "OpMatrixTimesMatrix", "4x2_3x4", 2, MAT3X2, MAT4X2, MAT3X4, 0, &getInputDataD, compareFP16ArithmeticFunc< 8, 8, 16, 0, fp16MatrixTimesMatrix<4,2,3,4> > },
16529 { "OpMatrixTimesMatrix", "4x2_4x4", 2, MAT4X2, MAT4X2, MAT4X4, 0, &getInputDataD, compareFP16ArithmeticFunc< 8, 8, 16, 0, fp16MatrixTimesMatrix<4,2,4,4> > },
16530 { "OpMatrixTimesMatrix", "4x3_2x4", 2, MAT2X3, MAT4X3, MAT2X4, 0, &getInputDataD, compareFP16ArithmeticFunc< 8, 16, 8, 0, fp16MatrixTimesMatrix<4,3,2,4> > },
16531 { "OpMatrixTimesMatrix", "4x3_3x4", 2, MAT3X3, MAT4X3, MAT3X4, 0, &getInputDataD, compareFP16ArithmeticFunc< 16, 16, 16, 0, fp16MatrixTimesMatrix<4,3,3,4> > },
16532 { "OpMatrixTimesMatrix", "4x3_4x4", 2, MAT4X3, MAT4X3, MAT4X4, 0, &getInputDataD, compareFP16ArithmeticFunc< 16, 16, 16, 0, fp16MatrixTimesMatrix<4,3,4,4> > },
16533 { "OpMatrixTimesMatrix", "4x4_2x4", 2, MAT2X4, MAT4X4, MAT2X4, 0, &getInputDataD, compareFP16ArithmeticFunc< 8, 16, 8, 0, fp16MatrixTimesMatrix<4,4,2,4> > },
16534 { "OpMatrixTimesMatrix", "4x4_3x4", 2, MAT3X4, MAT4X4, MAT3X4, 0, &getInputDataD, compareFP16ArithmeticFunc< 16, 16, 16, 0, fp16MatrixTimesMatrix<4,4,3,4> > },
16535 { "OpMatrixTimesMatrix", "4x4_4x4", 2, MAT4X4, MAT4X4, MAT4X4, 0, &getInputDataD, compareFP16ArithmeticFunc< 16, 16, 16, 0, fp16MatrixTimesMatrix<4,4,4,4> > },
16536 { "OpOuterProduct", "2x2", 2, MAT2X2, VEC2, VEC2, 0, &getInputDataD, compareFP16ArithmeticFunc< 4, 2, 2, 0, fp16OuterProduct<2,2> > },
16537 { "OpOuterProduct", "2x3", 2, MAT2X3, VEC3, VEC2, 0, &getInputDataD, compareFP16ArithmeticFunc< 8, 3, 2, 0, fp16OuterProduct<2,3> > },
16538 { "OpOuterProduct", "2x4", 2, MAT2X4, VEC4, VEC2, 0, &getInputDataD, compareFP16ArithmeticFunc< 8, 4, 2, 0, fp16OuterProduct<2,4> > },
16539 { "OpOuterProduct", "3x2", 2, MAT3X2, VEC2, VEC3, 0, &getInputDataD, compareFP16ArithmeticFunc< 8, 2, 3, 0, fp16OuterProduct<3,2> > },
16540 { "OpOuterProduct", "3x3", 2, MAT3X3, VEC3, VEC3, 0, &getInputDataD, compareFP16ArithmeticFunc< 16, 3, 3, 0, fp16OuterProduct<3,3> > },
16541 { "OpOuterProduct", "3x4", 2, MAT3X4, VEC4, VEC3, 0, &getInputDataD, compareFP16ArithmeticFunc< 16, 4, 3, 0, fp16OuterProduct<3,4> > },
16542 { "OpOuterProduct", "4x2", 2, MAT4X2, VEC2, VEC4, 0, &getInputDataD, compareFP16ArithmeticFunc< 8, 2, 4, 0, fp16OuterProduct<4,2> > },
16543 { "OpOuterProduct", "4x3", 2, MAT4X3, VEC3, VEC4, 0, &getInputDataD, compareFP16ArithmeticFunc< 16, 3, 4, 0, fp16OuterProduct<4,3> > },
16544 { "OpOuterProduct", "4x4", 2, MAT4X4, VEC4, VEC4, 0, &getInputDataD, compareFP16ArithmeticFunc< 16, 4, 4, 0, fp16OuterProduct<4,4> > },
16545 { "Determinant", "2x2", 1, SCALAR, MAT2X2, NONE, 0, &getInputDataC, compareFP16ArithmeticFunc< 1, 4, 0, 0, fp16Determinant<2> > },
16546 { "Determinant", "3x3", 1, SCALAR, MAT3X3, NONE, 0, &getInputDataC, compareFP16ArithmeticFunc< 1, 16, 0, 0, fp16Determinant<3> > },
16547 { "Determinant", "4x4", 1, SCALAR, MAT4X4, NONE, 0, &getInputDataC, compareFP16ArithmeticFunc< 1, 16, 0, 0, fp16Determinant<4> > },
16548 { "MatrixInverse", "2x2", 1, MAT2X2, MAT2X2, NONE, 0, &getInputDataC, compareFP16ArithmeticFunc< 4, 4, 0, 0, fp16Inverse<2> > },
16551 for (deUint32 testFuncIdx = 0; testFuncIdx < DE_LENGTH_OF_ARRAY(testFuncs); ++testFuncIdx)
16553 const Math16TestFunc& testFunc = testFuncs[testFuncIdx];
16555 createFloat16ArithmeticFuncTest<SpecResource>(testCtx, *testGroup.get(), 0, testFunc);
16558 return testGroup.release();
16561 const string getNumberTypeName (const NumberType type)
16563 if (type == NUMBERTYPE_INT32)
16567 else if (type == NUMBERTYPE_UINT32)
16571 else if (type == NUMBERTYPE_FLOAT32)
16582 deInt32 getInt(de::Random& rnd)
16584 return rnd.getInt(std::numeric_limits<int>::min(), std::numeric_limits<int>::max());
16587 const string repeatString (const string& str, int times)
16590 for (int i = 0; i < times; ++i)
16597 const string getRandomConstantString (const NumberType type, de::Random& rnd)
16599 if (type == NUMBERTYPE_INT32)
16601 return numberToString<deInt32>(getInt(rnd));
16603 else if (type == NUMBERTYPE_UINT32)
16605 return numberToString<deUint32>(rnd.getUint32());
16607 else if (type == NUMBERTYPE_FLOAT32)
16609 return numberToString<float>(rnd.getFloat());
16618 void createVectorCompositeCases (vector<map<string, string> >& testCases, de::Random& rnd, const NumberType type)
16620 map<string, string> params;
16623 for (int width = 2; width <= 4; ++width)
16625 const string randomConst = numberToString(getInt(rnd));
16626 const string widthStr = numberToString(width);
16627 const string composite_type = "${customType}vec" + widthStr;
16628 const int index = rnd.getInt(0, width-1);
16630 params["type"] = "vec";
16631 params["name"] = params["type"] + "_" + widthStr;
16632 params["compositeDecl"] = composite_type + " = OpTypeVector ${customType} " + widthStr +"\n";
16633 params["compositeType"] = composite_type;
16634 params["filler"] = string("%filler = OpConstant ${customType} ") + getRandomConstantString(type, rnd) + "\n";
16635 params["compositeConstruct"] = "%instance = OpCompositeConstruct " + composite_type + repeatString(" %filler", width) + "\n";
16636 params["indexes"] = numberToString(index);
16637 testCases.push_back(params);
16641 void createArrayCompositeCases (vector<map<string, string> >& testCases, de::Random& rnd, const NumberType type)
16643 const int limit = 10;
16644 map<string, string> params;
16646 for (int width = 2; width <= limit; ++width)
16648 string randomConst = numberToString(getInt(rnd));
16649 string widthStr = numberToString(width);
16650 int index = rnd.getInt(0, width-1);
16652 params["type"] = "array";
16653 params["name"] = params["type"] + "_" + widthStr;
16654 params["compositeDecl"] = string("%arraywidth = OpConstant %u32 " + widthStr + "\n")
16655 + "%composite = OpTypeArray ${customType} %arraywidth\n";
16656 params["compositeType"] = "%composite";
16657 params["filler"] = string("%filler = OpConstant ${customType} ") + getRandomConstantString(type, rnd) + "\n";
16658 params["compositeConstruct"] = "%instance = OpCompositeConstruct %composite" + repeatString(" %filler", width) + "\n";
16659 params["indexes"] = numberToString(index);
16660 testCases.push_back(params);
16664 void createStructCompositeCases (vector<map<string, string> >& testCases, de::Random& rnd, const NumberType type)
16666 const int limit = 10;
16667 map<string, string> params;
16669 for (int width = 2; width <= limit; ++width)
16671 string randomConst = numberToString(getInt(rnd));
16672 int index = rnd.getInt(0, width-1);
16674 params["type"] = "struct";
16675 params["name"] = params["type"] + "_" + numberToString(width);
16676 params["compositeDecl"] = "%composite = OpTypeStruct" + repeatString(" ${customType}", width) + "\n";
16677 params["compositeType"] = "%composite";
16678 params["filler"] = string("%filler = OpConstant ${customType} ") + getRandomConstantString(type, rnd) + "\n";
16679 params["compositeConstruct"] = "%instance = OpCompositeConstruct %composite" + repeatString(" %filler", width) + "\n";
16680 params["indexes"] = numberToString(index);
16681 testCases.push_back(params);
16685 void createMatrixCompositeCases (vector<map<string, string> >& testCases, de::Random& rnd, const NumberType type)
16687 map<string, string> params;
16690 for (int width = 2; width <= 4; ++width)
16692 string widthStr = numberToString(width);
16694 for (int column = 2 ; column <= 4; ++column)
16696 int index_0 = rnd.getInt(0, column-1);
16697 int index_1 = rnd.getInt(0, width-1);
16698 string columnStr = numberToString(column);
16700 params["type"] = "matrix";
16701 params["name"] = params["type"] + "_" + widthStr + "x" + columnStr;
16702 params["compositeDecl"] = string("%vectype = OpTypeVector ${customType} " + widthStr + "\n")
16703 + "%composite = OpTypeMatrix %vectype " + columnStr + "\n";
16704 params["compositeType"] = "%composite";
16706 params["filler"] = string("%filler = OpConstant ${customType} ") + getRandomConstantString(type, rnd) + "\n"
16707 + "%fillerVec = OpConstantComposite %vectype" + repeatString(" %filler", width) + "\n";
16709 params["compositeConstruct"] = "%instance = OpCompositeConstruct %composite" + repeatString(" %fillerVec", column) + "\n";
16710 params["indexes"] = numberToString(index_0) + " " + numberToString(index_1);
16711 testCases.push_back(params);
16716 void createCompositeCases (vector<map<string, string> >& testCases, de::Random& rnd, const NumberType type)
16718 createVectorCompositeCases(testCases, rnd, type);
16719 createArrayCompositeCases(testCases, rnd, type);
16720 createStructCompositeCases(testCases, rnd, type);
16721 // Matrix only supports float types
16722 if (type == NUMBERTYPE_FLOAT32)
16724 createMatrixCompositeCases(testCases, rnd, type);
16728 const string getAssemblyTypeDeclaration (const NumberType type)
16732 case NUMBERTYPE_INT32: return "OpTypeInt 32 1";
16733 case NUMBERTYPE_UINT32: return "OpTypeInt 32 0";
16734 case NUMBERTYPE_FLOAT32: return "OpTypeFloat 32";
16735 default: DE_ASSERT(false); return "";
16739 const string getAssemblyTypeName (const NumberType type)
16743 case NUMBERTYPE_INT32: return "%i32";
16744 case NUMBERTYPE_UINT32: return "%u32";
16745 case NUMBERTYPE_FLOAT32: return "%f32";
16746 default: DE_ASSERT(false); return "";
16750 const string specializeCompositeInsertShaderTemplate (const NumberType type, const map<string, string>& params)
16752 map<string, string> parameters(params);
16754 const string customType = getAssemblyTypeName(type);
16755 map<string, string> substCustomType;
16756 substCustomType["customType"] = customType;
16757 parameters["compositeDecl"] = StringTemplate(parameters.at("compositeDecl")).specialize(substCustomType);
16758 parameters["compositeType"] = StringTemplate(parameters.at("compositeType")).specialize(substCustomType);
16759 parameters["compositeConstruct"] = StringTemplate(parameters.at("compositeConstruct")).specialize(substCustomType);
16760 parameters["filler"] = StringTemplate(parameters.at("filler")).specialize(substCustomType);
16761 parameters["customType"] = customType;
16762 parameters["compositeDecorator"] = (parameters["type"] == "array") ? "OpDecorate %composite ArrayStride 4\n" : "";
16764 if (parameters.at("compositeType") != "%u32vec3")
16766 parameters["u32vec3Decl"] = "%u32vec3 = OpTypeVector %u32 3\n";
16769 return StringTemplate(
16770 "OpCapability Shader\n"
16771 "OpCapability Matrix\n"
16772 "OpMemoryModel Logical GLSL450\n"
16773 "OpEntryPoint GLCompute %main \"main\" %id\n"
16774 "OpExecutionMode %main LocalSize 1 1 1\n"
16776 "OpSource GLSL 430\n"
16777 "OpName %main \"main\"\n"
16778 "OpName %id \"gl_GlobalInvocationID\"\n"
16781 "OpDecorate %id BuiltIn GlobalInvocationId\n"
16782 "OpDecorate %buf BufferBlock\n"
16783 "OpDecorate %indata DescriptorSet 0\n"
16784 "OpDecorate %indata Binding 0\n"
16785 "OpDecorate %outdata DescriptorSet 0\n"
16786 "OpDecorate %outdata Binding 1\n"
16787 "OpDecorate %customarr ArrayStride 4\n"
16788 "${compositeDecorator}"
16789 "OpMemberDecorate %buf 0 Offset 0\n"
16792 "%void = OpTypeVoid\n"
16793 "%voidf = OpTypeFunction %void\n"
16794 "%u32 = OpTypeInt 32 0\n"
16795 "%i32 = OpTypeInt 32 1\n"
16796 "%f32 = OpTypeFloat 32\n"
16798 // Composite declaration
16804 "${u32vec3Decl:opt}"
16805 "%uvec3ptr = OpTypePointer Input %u32vec3\n"
16807 // Inherited from custom
16808 "%customptr = OpTypePointer Uniform ${customType}\n"
16809 "%customarr = OpTypeRuntimeArray ${customType}\n"
16810 "%buf = OpTypeStruct %customarr\n"
16811 "%bufptr = OpTypePointer Uniform %buf\n"
16813 "%indata = OpVariable %bufptr Uniform\n"
16814 "%outdata = OpVariable %bufptr Uniform\n"
16816 "%id = OpVariable %uvec3ptr Input\n"
16817 "%zero = OpConstant %i32 0\n"
16819 "%main = OpFunction %void None %voidf\n"
16820 "%label = OpLabel\n"
16821 "%idval = OpLoad %u32vec3 %id\n"
16822 "%x = OpCompositeExtract %u32 %idval 0\n"
16824 "%inloc = OpAccessChain %customptr %indata %zero %x\n"
16825 "%outloc = OpAccessChain %customptr %outdata %zero %x\n"
16826 // Read the input value
16827 "%inval = OpLoad ${customType} %inloc\n"
16828 // Create the composite and fill it
16829 "${compositeConstruct}"
16830 // Insert the input value to a place
16831 "%instance2 = OpCompositeInsert ${compositeType} %inval %instance ${indexes}\n"
16832 // Read back the value from the position
16833 "%out_val = OpCompositeExtract ${customType} %instance2 ${indexes}\n"
16834 // Store it in the output position
16835 " OpStore %outloc %out_val\n"
16838 ).specialize(parameters);
16841 template<typename T>
16842 BufferSp createCompositeBuffer(T number)
16844 return BufferSp(new Buffer<T>(vector<T>(1, number)));
16847 tcu::TestCaseGroup* createOpCompositeInsertGroup (tcu::TestContext& testCtx)
16849 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opcompositeinsert", "Test the OpCompositeInsert instruction"));
16850 de::Random rnd (deStringHash(group->getName()));
16852 for (int type = NUMBERTYPE_INT32; type != NUMBERTYPE_END32; ++type)
16854 NumberType numberType = NumberType(type);
16855 const string typeName = getNumberTypeName(numberType);
16856 const string description = "Test the OpCompositeInsert instruction with " + typeName + "s";
16857 de::MovePtr<tcu::TestCaseGroup> subGroup (new tcu::TestCaseGroup(testCtx, typeName.c_str(), description.c_str()));
16858 vector<map<string, string> > testCases;
16860 createCompositeCases(testCases, rnd, numberType);
16862 for (vector<map<string, string> >::const_iterator test = testCases.begin(); test != testCases.end(); ++test)
16864 ComputeShaderSpec spec;
16866 spec.assembly = specializeCompositeInsertShaderTemplate(numberType, *test);
16868 switch (numberType)
16870 case NUMBERTYPE_INT32:
16872 deInt32 number = getInt(rnd);
16873 spec.inputs.push_back(createCompositeBuffer<deInt32>(number));
16874 spec.outputs.push_back(createCompositeBuffer<deInt32>(number));
16877 case NUMBERTYPE_UINT32:
16879 deUint32 number = rnd.getUint32();
16880 spec.inputs.push_back(createCompositeBuffer<deUint32>(number));
16881 spec.outputs.push_back(createCompositeBuffer<deUint32>(number));
16884 case NUMBERTYPE_FLOAT32:
16886 float number = rnd.getFloat();
16887 spec.inputs.push_back(createCompositeBuffer<float>(number));
16888 spec.outputs.push_back(createCompositeBuffer<float>(number));
16895 spec.numWorkGroups = IVec3(1, 1, 1);
16896 subGroup->addChild(new SpvAsmComputeShaderCase(testCtx, test->at("name").c_str(), "OpCompositeInsert test", spec));
16898 group->addChild(subGroup.release());
16900 return group.release();
16903 struct AssemblyStructInfo
16905 AssemblyStructInfo (const deUint32 comp, const deUint32 idx)
16906 : components (comp)
16910 deUint32 components;
16914 const string specializeInBoundsShaderTemplate (const NumberType type, const AssemblyStructInfo& structInfo, const map<string, string>& params)
16916 // Create the full index string
16917 string fullIndex = numberToString(structInfo.index) + " " + params.at("indexes");
16918 // Convert it to list of indexes
16919 vector<string> indexes = de::splitString(fullIndex, ' ');
16921 map<string, string> parameters (params);
16922 parameters["structType"] = repeatString(" ${compositeType}", structInfo.components);
16923 parameters["structConstruct"] = repeatString(" %instance", structInfo.components);
16924 parameters["insertIndexes"] = fullIndex;
16926 // In matrix cases the last two index is the CompositeExtract indexes
16927 const deUint32 extractIndexes = (parameters["type"] == "matrix") ? 2 : 1;
16929 // Construct the extractIndex
16930 for (vector<string>::const_iterator index = indexes.end() - extractIndexes; index != indexes.end(); ++index)
16932 parameters["extractIndexes"] += " " + *index;
16935 // Remove the last 1 or 2 element depends on matrix case or not
16936 indexes.erase(indexes.end() - extractIndexes, indexes.end());
16939 // Generate AccessChain index expressions (except for the last one, because we use ptr to the composite)
16940 for (vector<string>::const_iterator index = indexes.begin(); index != indexes.end(); ++index)
16942 string indexId = "%index_" + numberToString(id++);
16943 parameters["accessChainConstDeclaration"] += indexId + " = OpConstant %u32 " + *index + "\n";
16944 parameters["accessChainIndexes"] += " " + indexId;
16947 parameters["compositeDecorator"] = (parameters["type"] == "array") ? "OpDecorate %composite ArrayStride 4\n" : "";
16949 const string customType = getAssemblyTypeName(type);
16950 map<string, string> substCustomType;
16951 substCustomType["customType"] = customType;
16952 parameters["compositeDecl"] = StringTemplate(parameters.at("compositeDecl")).specialize(substCustomType);
16953 parameters["compositeType"] = StringTemplate(parameters.at("compositeType")).specialize(substCustomType);
16954 parameters["compositeConstruct"] = StringTemplate(parameters.at("compositeConstruct")).specialize(substCustomType);
16955 parameters["filler"] = StringTemplate(parameters.at("filler")).specialize(substCustomType);
16956 parameters["customType"] = customType;
16958 const string compositeType = parameters.at("compositeType");
16959 map<string, string> substCompositeType;
16960 substCompositeType["compositeType"] = compositeType;
16961 parameters["structType"] = StringTemplate(parameters.at("structType")).specialize(substCompositeType);
16962 if (compositeType != "%u32vec3")
16964 parameters["u32vec3Decl"] = "%u32vec3 = OpTypeVector %u32 3\n";
16967 return StringTemplate(
16968 "OpCapability Shader\n"
16969 "OpCapability Matrix\n"
16970 "OpMemoryModel Logical GLSL450\n"
16971 "OpEntryPoint GLCompute %main \"main\" %id\n"
16972 "OpExecutionMode %main LocalSize 1 1 1\n"
16974 "OpSource GLSL 430\n"
16975 "OpName %main \"main\"\n"
16976 "OpName %id \"gl_GlobalInvocationID\"\n"
16978 "OpDecorate %id BuiltIn GlobalInvocationId\n"
16979 "OpDecorate %buf BufferBlock\n"
16980 "OpDecorate %indata DescriptorSet 0\n"
16981 "OpDecorate %indata Binding 0\n"
16982 "OpDecorate %outdata DescriptorSet 0\n"
16983 "OpDecorate %outdata Binding 1\n"
16984 "OpDecorate %customarr ArrayStride 4\n"
16985 "${compositeDecorator}"
16986 "OpMemberDecorate %buf 0 Offset 0\n"
16988 "%void = OpTypeVoid\n"
16989 "%voidf = OpTypeFunction %void\n"
16990 "%i32 = OpTypeInt 32 1\n"
16991 "%u32 = OpTypeInt 32 0\n"
16992 "%f32 = OpTypeFloat 32\n"
16995 // %u32vec3 if not already declared in ${compositeDecl}
16996 "${u32vec3Decl:opt}"
16997 "%uvec3ptr = OpTypePointer Input %u32vec3\n"
16998 // Inherited from composite
16999 "%composite_p = OpTypePointer Function ${compositeType}\n"
17000 "%struct_t = OpTypeStruct${structType}\n"
17001 "%struct_p = OpTypePointer Function %struct_t\n"
17004 "${accessChainConstDeclaration}"
17005 // Inherited from custom
17006 "%customptr = OpTypePointer Uniform ${customType}\n"
17007 "%customarr = OpTypeRuntimeArray ${customType}\n"
17008 "%buf = OpTypeStruct %customarr\n"
17009 "%bufptr = OpTypePointer Uniform %buf\n"
17010 "%indata = OpVariable %bufptr Uniform\n"
17011 "%outdata = OpVariable %bufptr Uniform\n"
17013 "%id = OpVariable %uvec3ptr Input\n"
17014 "%zero = OpConstant %u32 0\n"
17015 "%main = OpFunction %void None %voidf\n"
17016 "%label = OpLabel\n"
17017 "%struct_v = OpVariable %struct_p Function\n"
17018 "%idval = OpLoad %u32vec3 %id\n"
17019 "%x = OpCompositeExtract %u32 %idval 0\n"
17020 // Create the input/output type
17021 "%inloc = OpInBoundsAccessChain %customptr %indata %zero %x\n"
17022 "%outloc = OpInBoundsAccessChain %customptr %outdata %zero %x\n"
17023 // Read the input value
17024 "%inval = OpLoad ${customType} %inloc\n"
17025 // Create the composite and fill it
17026 "${compositeConstruct}"
17027 // Create the struct and fill it with the composite
17028 "%struct = OpCompositeConstruct %struct_t${structConstruct}\n"
17029 // Insert the value
17030 "%comp_obj = OpCompositeInsert %struct_t %inval %struct ${insertIndexes}\n"
17031 // Store the object
17032 " OpStore %struct_v %comp_obj\n"
17033 // Get deepest possible composite pointer
17034 "%inner_ptr = OpInBoundsAccessChain %composite_p %struct_v${accessChainIndexes}\n"
17035 "%read_obj = OpLoad ${compositeType} %inner_ptr\n"
17036 // Read back the stored value
17037 "%read_val = OpCompositeExtract ${customType} %read_obj${extractIndexes}\n"
17038 " OpStore %outloc %read_val\n"
17041 ).specialize(parameters);
17044 tcu::TestCaseGroup* createOpInBoundsAccessChainGroup (tcu::TestContext& testCtx)
17046 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opinboundsaccesschain", "Test the OpInBoundsAccessChain instruction"));
17047 de::Random rnd (deStringHash(group->getName()));
17049 for (int type = NUMBERTYPE_INT32; type != NUMBERTYPE_END32; ++type)
17051 NumberType numberType = NumberType(type);
17052 const string typeName = getNumberTypeName(numberType);
17053 const string description = "Test the OpInBoundsAccessChain instruction with " + typeName + "s";
17054 de::MovePtr<tcu::TestCaseGroup> subGroup (new tcu::TestCaseGroup(testCtx, typeName.c_str(), description.c_str()));
17056 vector<map<string, string> > testCases;
17057 createCompositeCases(testCases, rnd, numberType);
17059 for (vector<map<string, string> >::const_iterator test = testCases.begin(); test != testCases.end(); ++test)
17061 ComputeShaderSpec spec;
17063 // Number of components inside of a struct
17064 deUint32 structComponents = rnd.getInt(2, 8);
17065 // Component index value
17066 deUint32 structIndex = rnd.getInt(0, structComponents - 1);
17067 AssemblyStructInfo structInfo(structComponents, structIndex);
17069 spec.assembly = specializeInBoundsShaderTemplate(numberType, structInfo, *test);
17071 switch (numberType)
17073 case NUMBERTYPE_INT32:
17075 deInt32 number = getInt(rnd);
17076 spec.inputs.push_back(createCompositeBuffer<deInt32>(number));
17077 spec.outputs.push_back(createCompositeBuffer<deInt32>(number));
17080 case NUMBERTYPE_UINT32:
17082 deUint32 number = rnd.getUint32();
17083 spec.inputs.push_back(createCompositeBuffer<deUint32>(number));
17084 spec.outputs.push_back(createCompositeBuffer<deUint32>(number));
17087 case NUMBERTYPE_FLOAT32:
17089 float number = rnd.getFloat();
17090 spec.inputs.push_back(createCompositeBuffer<float>(number));
17091 spec.outputs.push_back(createCompositeBuffer<float>(number));
17097 spec.numWorkGroups = IVec3(1, 1, 1);
17098 subGroup->addChild(new SpvAsmComputeShaderCase(testCtx, test->at("name").c_str(), "OpInBoundsAccessChain test", spec));
17100 group->addChild(subGroup.release());
17102 return group.release();
17105 // If the params missing, uninitialized case
17106 const string specializeDefaultOutputShaderTemplate (const NumberType type, const map<string, string>& params = map<string, string>())
17108 map<string, string> parameters(params);
17110 parameters["customType"] = getAssemblyTypeName(type);
17112 // Declare the const value, and use it in the initializer
17113 if (params.find("constValue") != params.end())
17115 parameters["variableInitializer"] = " %const";
17117 // Uninitialized case
17120 parameters["commentDecl"] = ";";
17123 return StringTemplate(
17124 "OpCapability Shader\n"
17125 "OpMemoryModel Logical GLSL450\n"
17126 "OpEntryPoint GLCompute %main \"main\" %id\n"
17127 "OpExecutionMode %main LocalSize 1 1 1\n"
17128 "OpSource GLSL 430\n"
17129 "OpName %main \"main\"\n"
17130 "OpName %id \"gl_GlobalInvocationID\"\n"
17132 "OpDecorate %id BuiltIn GlobalInvocationId\n"
17133 "OpDecorate %indata DescriptorSet 0\n"
17134 "OpDecorate %indata Binding 0\n"
17135 "OpDecorate %outdata DescriptorSet 0\n"
17136 "OpDecorate %outdata Binding 1\n"
17137 "OpDecorate %in_arr ArrayStride 4\n"
17138 "OpDecorate %in_buf BufferBlock\n"
17139 "OpMemberDecorate %in_buf 0 Offset 0\n"
17141 "%void = OpTypeVoid\n"
17142 "%voidf = OpTypeFunction %void\n"
17143 "%u32 = OpTypeInt 32 0\n"
17144 "%i32 = OpTypeInt 32 1\n"
17145 "%f32 = OpTypeFloat 32\n"
17146 "%uvec3 = OpTypeVector %u32 3\n"
17147 "%uvec3ptr = OpTypePointer Input %uvec3\n"
17148 "${commentDecl:opt}%const = OpConstant ${customType} ${constValue:opt}\n"
17150 "%in_ptr = OpTypePointer Uniform ${customType}\n"
17151 "%in_arr = OpTypeRuntimeArray ${customType}\n"
17152 "%in_buf = OpTypeStruct %in_arr\n"
17153 "%in_bufptr = OpTypePointer Uniform %in_buf\n"
17154 "%indata = OpVariable %in_bufptr Uniform\n"
17155 "%outdata = OpVariable %in_bufptr Uniform\n"
17156 "%id = OpVariable %uvec3ptr Input\n"
17157 "%var_ptr = OpTypePointer Function ${customType}\n"
17159 "%zero = OpConstant %i32 0\n"
17161 "%main = OpFunction %void None %voidf\n"
17162 "%label = OpLabel\n"
17163 "%out_var = OpVariable %var_ptr Function${variableInitializer:opt}\n"
17164 "%idval = OpLoad %uvec3 %id\n"
17165 "%x = OpCompositeExtract %u32 %idval 0\n"
17166 "%inloc = OpAccessChain %in_ptr %indata %zero %x\n"
17167 "%outloc = OpAccessChain %in_ptr %outdata %zero %x\n"
17169 "%outval = OpLoad ${customType} %out_var\n"
17170 " OpStore %outloc %outval\n"
17173 ).specialize(parameters);
17176 bool compareFloats (const std::vector<Resource>&, const vector<AllocationSp>& outputAllocs, const std::vector<Resource>& expectedOutputs, TestLog& log)
17178 DE_ASSERT(outputAllocs.size() != 0);
17179 DE_ASSERT(outputAllocs.size() == expectedOutputs.size());
17181 // Use custom epsilon because of the float->string conversion
17182 const float epsilon = 0.00001f;
17184 for (size_t outputNdx = 0; outputNdx < outputAllocs.size(); ++outputNdx)
17186 vector<deUint8> expectedBytes;
17190 expectedOutputs[outputNdx].getBytes(expectedBytes);
17191 memcpy(&expected, &expectedBytes.front(), expectedBytes.size());
17192 memcpy(&actual, outputAllocs[outputNdx]->getHostPtr(), expectedBytes.size());
17194 // Test with epsilon
17195 if (fabs(expected - actual) > epsilon)
17197 log << TestLog::Message << "Error: The actual and expected values not matching."
17198 << " Expected: " << expected << " Actual: " << actual << " Epsilon: " << epsilon << TestLog::EndMessage;
17205 // Checks if the driver crash with uninitialized cases
17206 bool passthruVerify (const std::vector<Resource>&, const vector<AllocationSp>& outputAllocs, const std::vector<Resource>& expectedOutputs, TestLog&)
17208 DE_ASSERT(outputAllocs.size() != 0);
17209 DE_ASSERT(outputAllocs.size() == expectedOutputs.size());
17211 // Copy and discard the result.
17212 for (size_t outputNdx = 0; outputNdx < outputAllocs.size(); ++outputNdx)
17214 vector<deUint8> expectedBytes;
17215 expectedOutputs[outputNdx].getBytes(expectedBytes);
17217 const size_t width = expectedBytes.size();
17218 vector<char> data (width);
17220 memcpy(&data[0], outputAllocs[outputNdx]->getHostPtr(), width);
17225 tcu::TestCaseGroup* createShaderDefaultOutputGroup (tcu::TestContext& testCtx)
17227 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "shader_default_output", "Test shader default output."));
17228 de::Random rnd (deStringHash(group->getName()));
17230 for (int type = NUMBERTYPE_INT32; type != NUMBERTYPE_END32; ++type)
17232 NumberType numberType = NumberType(type);
17233 const string typeName = getNumberTypeName(numberType);
17234 const string description = "Test the OpVariable initializer with " + typeName + ".";
17235 de::MovePtr<tcu::TestCaseGroup> subGroup (new tcu::TestCaseGroup(testCtx, typeName.c_str(), description.c_str()));
17237 // 2 similar subcases (initialized and uninitialized)
17238 for (int subCase = 0; subCase < 2; ++subCase)
17240 ComputeShaderSpec spec;
17241 spec.numWorkGroups = IVec3(1, 1, 1);
17243 map<string, string> params;
17245 switch (numberType)
17247 case NUMBERTYPE_INT32:
17249 deInt32 number = getInt(rnd);
17250 spec.inputs.push_back(createCompositeBuffer<deInt32>(number));
17251 spec.outputs.push_back(createCompositeBuffer<deInt32>(number));
17252 params["constValue"] = numberToString(number);
17255 case NUMBERTYPE_UINT32:
17257 deUint32 number = rnd.getUint32();
17258 spec.inputs.push_back(createCompositeBuffer<deUint32>(number));
17259 spec.outputs.push_back(createCompositeBuffer<deUint32>(number));
17260 params["constValue"] = numberToString(number);
17263 case NUMBERTYPE_FLOAT32:
17265 float number = rnd.getFloat();
17266 spec.inputs.push_back(createCompositeBuffer<float>(number));
17267 spec.outputs.push_back(createCompositeBuffer<float>(number));
17268 spec.verifyIO = &compareFloats;
17269 params["constValue"] = numberToString(number);
17276 // Initialized subcase
17279 spec.assembly = specializeDefaultOutputShaderTemplate(numberType, params);
17280 subGroup->addChild(new SpvAsmComputeShaderCase(testCtx, "initialized", "OpVariable initializer tests.", spec));
17282 // Uninitialized subcase
17285 spec.assembly = specializeDefaultOutputShaderTemplate(numberType);
17286 spec.verifyIO = &passthruVerify;
17287 subGroup->addChild(new SpvAsmComputeShaderCase(testCtx, "uninitialized", "OpVariable initializer tests.", spec));
17290 group->addChild(subGroup.release());
17292 return group.release();
17295 tcu::TestCaseGroup* createOpNopTests (tcu::TestContext& testCtx)
17297 de::MovePtr<tcu::TestCaseGroup> testGroup (new tcu::TestCaseGroup(testCtx, "opnop", "Test OpNop"));
17298 RGBA defaultColors[4];
17299 map<string, string> opNopFragments;
17301 getDefaultColors(defaultColors);
17303 opNopFragments["testfun"] =
17304 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
17305 "%param1 = OpFunctionParameter %v4f32\n"
17306 "%label_testfun = OpLabel\n"
17315 "%a = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
17316 "%b = OpFAdd %f32 %a %a\n"
17318 "%c = OpFSub %f32 %b %a\n"
17319 "%ret = OpVectorInsertDynamic %v4f32 %param1 %c %c_i32_0\n"
17322 "OpReturnValue %ret\n"
17325 createTestsForAllStages("opnop", defaultColors, defaultColors, opNopFragments, testGroup.get());
17327 return testGroup.release();
17330 tcu::TestCaseGroup* createOpNameTests (tcu::TestContext& testCtx)
17332 de::MovePtr<tcu::TestCaseGroup> testGroup (new tcu::TestCaseGroup(testCtx, "opname","Test OpName"));
17333 RGBA defaultColors[4];
17334 map<string, string> opNameFragments;
17336 getDefaultColors(defaultColors);
17338 opNameFragments["debug"] =
17339 "OpName %BP_main \"not_main\"";
17341 opNameFragments["testfun"] =
17342 "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
17343 "%param1 = OpFunctionParameter %v4f32\n"
17344 "%label_func = OpLabel\n"
17345 "%a = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
17346 "%b = OpFAdd %f32 %a %a\n"
17347 "%c = OpFSub %f32 %b %a\n"
17348 "%ret = OpVectorInsertDynamic %v4f32 %param1 %c %c_i32_0\n"
17349 "OpReturnValue %ret\n"
17352 createTestsForAllStages("opname", defaultColors, defaultColors, opNameFragments, testGroup.get());
17354 return testGroup.release();
17357 tcu::TestCaseGroup* createFloat16Tests (tcu::TestContext& testCtx)
17359 de::MovePtr<tcu::TestCaseGroup> testGroup (new tcu::TestCaseGroup(testCtx, "float16", "Float 16 tests"));
17361 testGroup->addChild(createOpConstantFloat16Tests(testCtx));
17362 testGroup->addChild(createFloat16LogicalSet<GraphicsResources>(testCtx, TEST_WITHOUT_NAN));
17363 testGroup->addChild(createFloat16FuncSet<GraphicsResources>(testCtx));
17364 testGroup->addChild(createDerivativeTests<256, 1>(testCtx));
17365 testGroup->addChild(createDerivativeTests<256, 2>(testCtx));
17366 testGroup->addChild(createDerivativeTests<256, 4>(testCtx));
17367 testGroup->addChild(createFloat16VectorExtractSet<GraphicsResources>(testCtx));
17368 testGroup->addChild(createFloat16VectorInsertSet<GraphicsResources>(testCtx));
17369 testGroup->addChild(createFloat16VectorShuffleSet<GraphicsResources>(testCtx));
17370 testGroup->addChild(createFloat16CompositeConstructSet<GraphicsResources>(testCtx));
17371 testGroup->addChild(createFloat16CompositeInsertExtractSet<GraphicsResources>(testCtx, "OpCompositeExtract"));
17372 testGroup->addChild(createFloat16CompositeInsertExtractSet<GraphicsResources>(testCtx, "OpCompositeInsert"));
17373 testGroup->addChild(createFloat16ArithmeticSet<GraphicsResources>(testCtx));
17374 testGroup->addChild(createFloat16ArithmeticSet<1, GraphicsResources>(testCtx));
17375 testGroup->addChild(createFloat16ArithmeticSet<2, GraphicsResources>(testCtx));
17376 testGroup->addChild(createFloat16ArithmeticSet<3, GraphicsResources>(testCtx));
17377 testGroup->addChild(createFloat16ArithmeticSet<4, GraphicsResources>(testCtx));
17379 return testGroup.release();
17382 tcu::TestCaseGroup* createFloat16Group (tcu::TestContext& testCtx)
17384 de::MovePtr<tcu::TestCaseGroup> testGroup (new tcu::TestCaseGroup(testCtx, "float16", "Float 16 tests"));
17386 testGroup->addChild(createFloat16OpConstantCompositeGroup(testCtx));
17387 testGroup->addChild(createFloat16LogicalSet<ComputeShaderSpec>(testCtx, TEST_WITHOUT_NAN));
17388 testGroup->addChild(createFloat16FuncSet<ComputeShaderSpec>(testCtx));
17389 testGroup->addChild(createFloat16VectorExtractSet<ComputeShaderSpec>(testCtx));
17390 testGroup->addChild(createFloat16VectorInsertSet<ComputeShaderSpec>(testCtx));
17391 testGroup->addChild(createFloat16VectorShuffleSet<ComputeShaderSpec>(testCtx));
17392 testGroup->addChild(createFloat16CompositeConstructSet<ComputeShaderSpec>(testCtx));
17393 testGroup->addChild(createFloat16CompositeInsertExtractSet<ComputeShaderSpec>(testCtx, "OpCompositeExtract"));
17394 testGroup->addChild(createFloat16CompositeInsertExtractSet<ComputeShaderSpec>(testCtx, "OpCompositeInsert"));
17395 testGroup->addChild(createFloat16ArithmeticSet<ComputeShaderSpec>(testCtx));
17396 testGroup->addChild(createFloat16ArithmeticSet<1, ComputeShaderSpec>(testCtx));
17397 testGroup->addChild(createFloat16ArithmeticSet<2, ComputeShaderSpec>(testCtx));
17398 testGroup->addChild(createFloat16ArithmeticSet<3, ComputeShaderSpec>(testCtx));
17399 testGroup->addChild(createFloat16ArithmeticSet<4, ComputeShaderSpec>(testCtx));
17401 return testGroup.release();
17404 tcu::TestCaseGroup* createInstructionTests (tcu::TestContext& testCtx)
17406 const bool testComputePipeline = true;
17408 de::MovePtr<tcu::TestCaseGroup> instructionTests (new tcu::TestCaseGroup(testCtx, "instruction", "Instructions with special opcodes/operands"));
17409 de::MovePtr<tcu::TestCaseGroup> computeTests (new tcu::TestCaseGroup(testCtx, "compute", "Compute Instructions with special opcodes/operands"));
17410 de::MovePtr<tcu::TestCaseGroup> graphicsTests (new tcu::TestCaseGroup(testCtx, "graphics", "Graphics Instructions with special opcodes/operands"));
17412 computeTests->addChild(createSpivVersionCheckTests(testCtx, testComputePipeline));
17413 computeTests->addChild(createLocalSizeGroup(testCtx));
17414 computeTests->addChild(createOpNopGroup(testCtx));
17415 computeTests->addChild(createOpFUnordGroup(testCtx));
17416 computeTests->addChild(createOpAtomicGroup(testCtx, false));
17417 computeTests->addChild(createOpAtomicGroup(testCtx, true)); // Using new StorageBuffer decoration
17418 computeTests->addChild(createOpAtomicGroup(testCtx, false, 1024, true)); // Return value validation
17419 computeTests->addChild(createOpLineGroup(testCtx));
17420 computeTests->addChild(createOpModuleProcessedGroup(testCtx));
17421 computeTests->addChild(createOpNoLineGroup(testCtx));
17422 computeTests->addChild(createOpConstantNullGroup(testCtx));
17423 computeTests->addChild(createOpConstantCompositeGroup(testCtx));
17424 computeTests->addChild(createOpConstantUsageGroup(testCtx));
17425 computeTests->addChild(createSpecConstantGroup(testCtx));
17426 computeTests->addChild(createOpSourceGroup(testCtx));
17427 computeTests->addChild(createOpSourceExtensionGroup(testCtx));
17428 computeTests->addChild(createDecorationGroupGroup(testCtx));
17429 computeTests->addChild(createOpPhiGroup(testCtx));
17430 computeTests->addChild(createLoopControlGroup(testCtx));
17431 computeTests->addChild(createFunctionControlGroup(testCtx));
17432 computeTests->addChild(createSelectionControlGroup(testCtx));
17433 computeTests->addChild(createBlockOrderGroup(testCtx));
17434 computeTests->addChild(createMultipleShaderGroup(testCtx));
17435 computeTests->addChild(createMemoryAccessGroup(testCtx));
17436 computeTests->addChild(createOpCopyMemoryGroup(testCtx));
17437 computeTests->addChild(createOpCopyObjectGroup(testCtx));
17438 computeTests->addChild(createNoContractionGroup(testCtx));
17439 computeTests->addChild(createOpUndefGroup(testCtx));
17440 computeTests->addChild(createOpUnreachableGroup(testCtx));
17441 computeTests->addChild(createOpQuantizeToF16Group(testCtx));
17442 computeTests->addChild(createOpFRemGroup(testCtx));
17443 computeTests->addChild(createOpSRemComputeGroup(testCtx, QP_TEST_RESULT_PASS));
17444 computeTests->addChild(createOpSRemComputeGroup64(testCtx, QP_TEST_RESULT_PASS));
17445 computeTests->addChild(createOpSModComputeGroup(testCtx, QP_TEST_RESULT_PASS));
17446 computeTests->addChild(createOpSModComputeGroup64(testCtx, QP_TEST_RESULT_PASS));
17447 computeTests->addChild(createConvertComputeTests(testCtx, "OpSConvert", "sconvert"));
17448 computeTests->addChild(createConvertComputeTests(testCtx, "OpUConvert", "uconvert"));
17449 computeTests->addChild(createConvertComputeTests(testCtx, "OpFConvert", "fconvert"));
17450 computeTests->addChild(createConvertComputeTests(testCtx, "OpConvertSToF", "convertstof"));
17451 computeTests->addChild(createConvertComputeTests(testCtx, "OpConvertFToS", "convertftos"));
17452 computeTests->addChild(createConvertComputeTests(testCtx, "OpConvertUToF", "convertutof"));
17453 computeTests->addChild(createConvertComputeTests(testCtx, "OpConvertFToU", "convertftou"));
17454 computeTests->addChild(createOpCompositeInsertGroup(testCtx));
17455 computeTests->addChild(createOpInBoundsAccessChainGroup(testCtx));
17456 computeTests->addChild(createShaderDefaultOutputGroup(testCtx));
17457 computeTests->addChild(createOpNMinGroup(testCtx));
17458 computeTests->addChild(createOpNMaxGroup(testCtx));
17459 computeTests->addChild(createOpNClampGroup(testCtx));
17461 de::MovePtr<tcu::TestCaseGroup> computeAndroidTests (new tcu::TestCaseGroup(testCtx, "android", "Android CTS Tests"));
17463 computeAndroidTests->addChild(createOpSRemComputeGroup(testCtx, QP_TEST_RESULT_QUALITY_WARNING));
17464 computeAndroidTests->addChild(createOpSModComputeGroup(testCtx, QP_TEST_RESULT_QUALITY_WARNING));
17466 computeTests->addChild(computeAndroidTests.release());
17469 computeTests->addChild(create8BitStorageComputeGroup(testCtx));
17470 computeTests->addChild(create16BitStorageComputeGroup(testCtx));
17471 computeTests->addChild(createFloatControlsComputeGroup(testCtx));
17472 computeTests->addChild(createUboMatrixPaddingComputeGroup(testCtx));
17473 computeTests->addChild(createVariableInitComputeGroup(testCtx));
17474 computeTests->addChild(createConditionalBranchComputeGroup(testCtx));
17475 computeTests->addChild(createIndexingComputeGroup(testCtx));
17476 computeTests->addChild(createVariablePointersComputeGroup(testCtx));
17477 computeTests->addChild(createImageSamplerComputeGroup(testCtx));
17478 computeTests->addChild(createOpNameGroup(testCtx));
17479 computeTests->addChild(createPointerParameterComputeGroup(testCtx));
17480 computeTests->addChild(createFloat16Group(testCtx));
17482 graphicsTests->addChild(createCrossStageInterfaceTests(testCtx));
17483 graphicsTests->addChild(createSpivVersionCheckTests(testCtx, !testComputePipeline));
17484 graphicsTests->addChild(createOpNopTests(testCtx));
17485 graphicsTests->addChild(createOpSourceTests(testCtx));
17486 graphicsTests->addChild(createOpSourceContinuedTests(testCtx));
17487 graphicsTests->addChild(createOpModuleProcessedTests(testCtx));
17488 graphicsTests->addChild(createOpLineTests(testCtx));
17489 graphicsTests->addChild(createOpNoLineTests(testCtx));
17490 graphicsTests->addChild(createOpConstantNullTests(testCtx));
17491 graphicsTests->addChild(createOpConstantCompositeTests(testCtx));
17492 graphicsTests->addChild(createMemoryAccessTests(testCtx));
17493 graphicsTests->addChild(createOpUndefTests(testCtx));
17494 graphicsTests->addChild(createSelectionBlockOrderTests(testCtx));
17495 graphicsTests->addChild(createModuleTests(testCtx));
17496 graphicsTests->addChild(createSwitchBlockOrderTests(testCtx));
17497 graphicsTests->addChild(createOpPhiTests(testCtx));
17498 graphicsTests->addChild(createNoContractionTests(testCtx));
17499 graphicsTests->addChild(createOpQuantizeTests(testCtx));
17500 graphicsTests->addChild(createLoopTests(testCtx));
17501 graphicsTests->addChild(createSpecConstantTests(testCtx));
17502 graphicsTests->addChild(createSpecConstantOpQuantizeToF16Group(testCtx));
17503 graphicsTests->addChild(createBarrierTests(testCtx));
17504 graphicsTests->addChild(createDecorationGroupTests(testCtx));
17505 graphicsTests->addChild(createFRemTests(testCtx));
17506 graphicsTests->addChild(createOpSRemGraphicsTests(testCtx, QP_TEST_RESULT_PASS));
17507 graphicsTests->addChild(createOpSModGraphicsTests(testCtx, QP_TEST_RESULT_PASS));
17510 de::MovePtr<tcu::TestCaseGroup> graphicsAndroidTests (new tcu::TestCaseGroup(testCtx, "android", "Android CTS Tests"));
17512 graphicsAndroidTests->addChild(createOpSRemGraphicsTests(testCtx, QP_TEST_RESULT_QUALITY_WARNING));
17513 graphicsAndroidTests->addChild(createOpSModGraphicsTests(testCtx, QP_TEST_RESULT_QUALITY_WARNING));
17515 graphicsTests->addChild(graphicsAndroidTests.release());
17517 graphicsTests->addChild(createOpNameTests(testCtx));
17519 graphicsTests->addChild(create8BitStorageGraphicsGroup(testCtx));
17520 graphicsTests->addChild(create16BitStorageGraphicsGroup(testCtx));
17521 graphicsTests->addChild(createFloatControlsGraphicsGroup(testCtx));
17522 graphicsTests->addChild(createUboMatrixPaddingGraphicsGroup(testCtx));
17523 graphicsTests->addChild(createVariableInitGraphicsGroup(testCtx));
17524 graphicsTests->addChild(createConditionalBranchGraphicsGroup(testCtx));
17525 graphicsTests->addChild(createIndexingGraphicsGroup(testCtx));
17526 graphicsTests->addChild(createVariablePointersGraphicsGroup(testCtx));
17527 graphicsTests->addChild(createImageSamplerGraphicsGroup(testCtx));
17528 graphicsTests->addChild(createConvertGraphicsTests(testCtx, "OpSConvert", "sconvert"));
17529 graphicsTests->addChild(createConvertGraphicsTests(testCtx, "OpUConvert", "uconvert"));
17530 graphicsTests->addChild(createConvertGraphicsTests(testCtx, "OpFConvert", "fconvert"));
17531 graphicsTests->addChild(createConvertGraphicsTests(testCtx, "OpConvertSToF", "convertstof"));
17532 graphicsTests->addChild(createConvertGraphicsTests(testCtx, "OpConvertFToS", "convertftos"));
17533 graphicsTests->addChild(createConvertGraphicsTests(testCtx, "OpConvertUToF", "convertutof"));
17534 graphicsTests->addChild(createConvertGraphicsTests(testCtx, "OpConvertFToU", "convertftou"));
17535 graphicsTests->addChild(createPointerParameterGraphicsGroup(testCtx));
17537 graphicsTests->addChild(createFloat16Tests(testCtx));
17539 instructionTests->addChild(computeTests.release());
17540 instructionTests->addChild(graphicsTests.release());
17542 return instructionTests.release();