1 /*-------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
5 * Copyright (c) 2015 Google Inc.
6 * Copyright (c) 2016 The Khronos Group Inc.
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
22 * \brief SPIR-V Assembly Tests for Instructions (special opcode/operand)
23 *//*--------------------------------------------------------------------*/
25 #include "vktSpvAsmInstructionTests.hpp"
27 #include "tcuCommandLine.hpp"
28 #include "tcuFormatUtil.hpp"
29 #include "tcuFloat.hpp"
30 #include "tcuRGBA.hpp"
31 #include "tcuStringTemplate.hpp"
32 #include "tcuTestLog.hpp"
33 #include "tcuVectorUtil.hpp"
34 #include "tcuInterval.hpp"
37 #include "vkDeviceUtil.hpp"
38 #include "vkMemUtil.hpp"
39 #include "vkPlatform.hpp"
40 #include "vkPrograms.hpp"
41 #include "vkQueryUtil.hpp"
43 #include "vkRefUtil.hpp"
44 #include "vkStrUtil.hpp"
45 #include "vkTypeUtil.hpp"
47 #include "deStringUtil.hpp"
48 #include "deUniquePtr.hpp"
50 #include "tcuStringTemplate.hpp"
52 #include "vktSpvAsm16bitStorageTests.hpp"
53 #include "vktSpvAsmUboMatrixPaddingTests.hpp"
54 #include "vktSpvAsmConditionalBranchTests.hpp"
55 #include "vktSpvAsmIndexingTests.hpp"
56 #include "vktSpvAsmComputeShaderCase.hpp"
57 #include "vktSpvAsmComputeShaderTestUtil.hpp"
58 #include "vktSpvAsmGraphicsShaderTestUtil.hpp"
59 #include "vktSpvAsmVariablePointersTests.hpp"
60 #include "vktTestCaseUtil.hpp"
72 namespace SpirVAssembly
86 using tcu::TestStatus;
89 using tcu::StringTemplate;
93 static void fillRandomScalars (de::Random& rnd, T minValue, T maxValue, void* dst, int numValues, int offset = 0)
95 T* const typedPtr = (T*)dst;
96 for (int ndx = 0; ndx < numValues; ndx++)
97 typedPtr[offset + ndx] = randomScalar<T>(rnd, minValue, maxValue);
100 // Filter is a function that returns true if a value should pass, false otherwise.
101 template<typename T, typename FilterT>
102 static void fillRandomScalars (de::Random& rnd, T minValue, T maxValue, void* dst, int numValues, FilterT filter, int offset = 0)
104 T* const typedPtr = (T*)dst;
106 for (int ndx = 0; ndx < numValues; ndx++)
109 value = randomScalar<T>(rnd, minValue, maxValue);
110 while (!filter(value));
112 typedPtr[offset + ndx] = value;
116 // Gets a 64-bit integer with a more logarithmic distribution
117 deInt64 randomInt64LogDistributed (de::Random& rnd)
119 deInt64 val = rnd.getUint64();
120 val &= (1ull << rnd.getInt(1, 63)) - 1;
126 static void fillRandomInt64sLogDistributed (de::Random& rnd, vector<deInt64>& dst, int numValues)
128 for (int ndx = 0; ndx < numValues; ndx++)
129 dst[ndx] = randomInt64LogDistributed(rnd);
132 template<typename FilterT>
133 static void fillRandomInt64sLogDistributed (de::Random& rnd, vector<deInt64>& dst, int numValues, FilterT filter)
135 for (int ndx = 0; ndx < numValues; ndx++)
139 value = randomInt64LogDistributed(rnd);
140 } while (!filter(value));
145 inline bool filterNonNegative (const deInt64 value)
150 inline bool filterPositive (const deInt64 value)
155 inline bool filterNotZero (const deInt64 value)
160 static void floorAll (vector<float>& values)
162 for (size_t i = 0; i < values.size(); i++)
163 values[i] = deFloatFloor(values[i]);
166 static void floorAll (vector<Vec4>& values)
168 for (size_t i = 0; i < values.size(); i++)
169 values[i] = floor(values[i]);
177 CaseParameter (const char* case_, const string& param_) : name(case_), param(param_) {}
180 // Assembly code used for testing OpNop, OpConstant{Null|Composite}, Op[No]Line, OpSource[Continued], OpSourceExtension, OpUndef is based on GLSL source code:
184 // layout(std140, set = 0, binding = 0) readonly buffer Input {
187 // layout(std140, set = 0, binding = 1) writeonly buffer Output {
191 // layout (local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
194 // uint x = gl_GlobalInvocationID.x;
195 // output_data.elements[x] = -input_data.elements[x];
199 static string getAsmForOpNopTest(bool useLiteralLocalSize, bool useSpecConstantWorkgroupSize) {
200 std::ostringstream out;
201 out << getComputeAsmShaderPreambleWithoutLocalSize();
202 if (useLiteralLocalSize) {
203 out << "OpExecutionMode %main LocalSize 1 1 1\n";
206 out << "OpSource GLSL 430\n"
207 "OpName %main \"main\"\n"
208 "OpName %id \"gl_GlobalInvocationID\"\n"
209 "OpDecorate %id BuiltIn GlobalInvocationId\n";
211 if (useSpecConstantWorkgroupSize) {
212 out << "OpDecorate %spec_0 SpecId 100\n"
213 "OpDecorate %spec_0 SpecId 100\n"
214 "OpDecorate %spec_1 SpecId 101\n"
215 "OpDecorate %spec_2 SpecId 102\n"
216 "OpDecorate %gl_WorkGroupSize BuiltIn WorkgroupSize\n";
219 out << getComputeAsmInputOutputBufferTraits()
220 << getComputeAsmCommonTypes()
221 << getComputeAsmInputOutputBuffer()
222 << "%id = OpVariable %uvec3ptr Input\n"
223 << "%zero = OpConstant %i32 0\n";
225 if (useSpecConstantWorkgroupSize) {
226 out << "%spec_0 = OpSpecConstant %u32 1\n"
227 "%spec_1 = OpSpecConstant %u32 1\n"
228 "%spec_2 = OpSpecConstant %u32 1\n"
229 "%gl_WorkGroupSize = OpSpecConstantComposite %uvec3 %spec_0 %spec_1 %spec_2\n";
232 out << "%main = OpFunction %void None %voidf\n"
234 "%idval = OpLoad %uvec3 %id\n"
235 "%x = OpCompositeExtract %u32 %idval 0\n"
237 " OpNop\n" // Inside a function body
239 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
240 "%inval = OpLoad %f32 %inloc\n"
241 "%neg = OpFNegate %f32 %inval\n"
242 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
243 " OpStore %outloc %neg\n"
249 tcu::TestCaseGroup* createOpNopGroup (tcu::TestContext& testCtx)
251 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opnop", "Test the OpNop instruction"));
252 ComputeShaderSpec spec;
253 de::Random rnd (deStringHash(group->getName()));
254 const int numElements = 100;
255 vector<float> positiveFloats (numElements, 0);
256 vector<float> negativeFloats (numElements, 0);
258 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
260 for (size_t ndx = 0; ndx < numElements; ++ndx)
261 negativeFloats[ndx] = -positiveFloats[ndx];
263 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
264 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
265 spec.numWorkGroups = IVec3(numElements, 1, 1);
267 spec.assembly = getAsmForOpNopTest(true, false);
268 group->addChild(new SpvAsmComputeShaderCase(testCtx, "literal_localsize", "OpNop appearing at different places", spec));
270 spec.assembly = getAsmForOpNopTest(true, true);
271 group->addChild(new SpvAsmComputeShaderCase(testCtx, "literal_and_specid_localsize", "OpNop appearing at different places", spec));
273 spec.assembly = getAsmForOpNopTest(false, true);
274 group->addChild(new SpvAsmComputeShaderCase(testCtx, "specid_localsize", "OpNop appearing at different places", spec));
276 return group.release();
279 bool compareFUnord (const std::vector<BufferSp>& inputs, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs, TestLog& log)
281 if (outputAllocs.size() != 1)
284 vector<deUint8> input1Bytes;
285 vector<deUint8> input2Bytes;
286 vector<deUint8> expectedBytes;
288 inputs[0]->getBytes(input1Bytes);
289 inputs[1]->getBytes(input2Bytes);
290 expectedOutputs[0]->getBytes(expectedBytes);
292 const deInt32* const expectedOutputAsInt = reinterpret_cast<const deInt32* const>(&expectedBytes.front());
293 const deInt32* const outputAsInt = static_cast<const deInt32* const>(outputAllocs[0]->getHostPtr());
294 const float* const input1AsFloat = reinterpret_cast<const float* const>(&input1Bytes.front());
295 const float* const input2AsFloat = reinterpret_cast<const float* const>(&input2Bytes.front());
296 bool returnValue = true;
298 for (size_t idx = 0; idx < expectedBytes.size() / sizeof(deInt32); ++idx)
300 if (outputAsInt[idx] != expectedOutputAsInt[idx])
302 log << TestLog::Message << "ERROR: Sub-case failed. inputs: " << input1AsFloat[idx] << "," << input2AsFloat[idx] << " output: " << outputAsInt[idx]<< " expected output: " << expectedOutputAsInt[idx] << TestLog::EndMessage;
309 typedef VkBool32 (*compareFuncType) (float, float);
315 compareFuncType compareFunc;
317 OpFUnordCase (const char* _name, const char* _opCode, compareFuncType _compareFunc)
320 , compareFunc (_compareFunc) {}
323 #define ADD_OPFUNORD_CASE(NAME, OPCODE, OPERATOR) \
325 struct compare_##NAME { static VkBool32 compare(float x, float y) { return (x OPERATOR y) ? VK_TRUE : VK_FALSE; } }; \
326 cases.push_back(OpFUnordCase(#NAME, OPCODE, compare_##NAME::compare)); \
327 } while (deGetFalse())
329 tcu::TestCaseGroup* createOpFUnordGroup (tcu::TestContext& testCtx)
331 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opfunord", "Test the OpFUnord* opcodes"));
332 de::Random rnd (deStringHash(group->getName()));
333 const int numElements = 100;
334 vector<OpFUnordCase> cases;
336 const StringTemplate shaderTemplate (
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 "OpDecorate %buf BufferBlock\n"
347 "OpDecorate %buf2 BufferBlock\n"
348 "OpDecorate %indata1 DescriptorSet 0\n"
349 "OpDecorate %indata1 Binding 0\n"
350 "OpDecorate %indata2 DescriptorSet 0\n"
351 "OpDecorate %indata2 Binding 1\n"
352 "OpDecorate %outdata DescriptorSet 0\n"
353 "OpDecorate %outdata Binding 2\n"
354 "OpDecorate %f32arr ArrayStride 4\n"
355 "OpDecorate %i32arr ArrayStride 4\n"
356 "OpMemberDecorate %buf 0 Offset 0\n"
357 "OpMemberDecorate %buf2 0 Offset 0\n"
359 + string(getComputeAsmCommonTypes()) +
361 "%buf = OpTypeStruct %f32arr\n"
362 "%bufptr = OpTypePointer Uniform %buf\n"
363 "%indata1 = OpVariable %bufptr Uniform\n"
364 "%indata2 = OpVariable %bufptr Uniform\n"
366 "%buf2 = OpTypeStruct %i32arr\n"
367 "%buf2ptr = OpTypePointer Uniform %buf2\n"
368 "%outdata = OpVariable %buf2ptr Uniform\n"
370 "%id = OpVariable %uvec3ptr Input\n"
371 "%zero = OpConstant %i32 0\n"
372 "%consti1 = OpConstant %i32 1\n"
373 "%constf1 = OpConstant %f32 1.0\n"
375 "%main = OpFunction %void None %voidf\n"
377 "%idval = OpLoad %uvec3 %id\n"
378 "%x = OpCompositeExtract %u32 %idval 0\n"
380 "%inloc1 = OpAccessChain %f32ptr %indata1 %zero %x\n"
381 "%inval1 = OpLoad %f32 %inloc1\n"
382 "%inloc2 = OpAccessChain %f32ptr %indata2 %zero %x\n"
383 "%inval2 = OpLoad %f32 %inloc2\n"
384 "%outloc = OpAccessChain %i32ptr %outdata %zero %x\n"
386 "%result = ${OPCODE} %bool %inval1 %inval2\n"
387 "%int_res = OpSelect %i32 %result %consti1 %zero\n"
388 " OpStore %outloc %int_res\n"
393 ADD_OPFUNORD_CASE(equal, "OpFUnordEqual", ==);
394 ADD_OPFUNORD_CASE(less, "OpFUnordLessThan", <);
395 ADD_OPFUNORD_CASE(lessequal, "OpFUnordLessThanEqual", <=);
396 ADD_OPFUNORD_CASE(greater, "OpFUnordGreaterThan", >);
397 ADD_OPFUNORD_CASE(greaterequal, "OpFUnordGreaterThanEqual", >=);
398 ADD_OPFUNORD_CASE(notequal, "OpFUnordNotEqual", !=);
400 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
402 map<string, string> specializations;
403 ComputeShaderSpec spec;
404 const float NaN = std::numeric_limits<float>::quiet_NaN();
405 vector<float> inputFloats1 (numElements, 0);
406 vector<float> inputFloats2 (numElements, 0);
407 vector<deInt32> expectedInts (numElements, 0);
409 specializations["OPCODE"] = cases[caseNdx].opCode;
410 spec.assembly = shaderTemplate.specialize(specializations);
412 fillRandomScalars(rnd, 1.f, 100.f, &inputFloats1[0], numElements);
413 for (size_t ndx = 0; ndx < numElements; ++ndx)
417 case 0: inputFloats2[ndx] = inputFloats1[ndx] + 1.0f; break;
418 case 1: inputFloats2[ndx] = inputFloats1[ndx] - 1.0f; break;
419 case 2: inputFloats2[ndx] = inputFloats1[ndx]; break;
420 case 3: inputFloats2[ndx] = NaN; break;
421 case 4: inputFloats2[ndx] = inputFloats1[ndx]; inputFloats1[ndx] = NaN; break;
422 case 5: inputFloats2[ndx] = NaN; inputFloats1[ndx] = NaN; break;
424 expectedInts[ndx] = tcu::Float32(inputFloats1[ndx]).isNaN() || tcu::Float32(inputFloats2[ndx]).isNaN() || cases[caseNdx].compareFunc(inputFloats1[ndx], inputFloats2[ndx]);
427 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats1)));
428 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
429 spec.outputs.push_back(BufferSp(new Int32Buffer(expectedInts)));
430 spec.numWorkGroups = IVec3(numElements, 1, 1);
431 spec.verifyIO = &compareFUnord;
432 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
435 return group.release();
441 const char* assembly;
442 OpAtomicType opAtomic;
443 deInt32 numOutputElements;
445 OpAtomicCase (const char* _name, const char* _assembly, OpAtomicType _opAtomic, deInt32 _numOutputElements)
447 , assembly (_assembly)
448 , opAtomic (_opAtomic)
449 , numOutputElements (_numOutputElements) {}
452 tcu::TestCaseGroup* createOpAtomicGroup (tcu::TestContext& testCtx, bool useStorageBuffer)
454 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx,
455 useStorageBuffer ? "opatomic_storage_buffer" : "opatomic",
456 "Test the OpAtomic* opcodes"));
457 const int numElements = 65535;
458 vector<OpAtomicCase> cases;
460 const StringTemplate shaderTemplate (
462 string("OpCapability Shader\n") +
463 (useStorageBuffer ? "OpExtension \"SPV_KHR_storage_buffer_storage_class\"\n" : "") +
464 "OpMemoryModel Logical GLSL450\n"
465 "OpEntryPoint GLCompute %main \"main\" %id\n"
466 "OpExecutionMode %main LocalSize 1 1 1\n" +
468 "OpSource GLSL 430\n"
469 "OpName %main \"main\"\n"
470 "OpName %id \"gl_GlobalInvocationID\"\n"
472 "OpDecorate %id BuiltIn GlobalInvocationId\n"
474 "OpDecorate %buf ${BLOCK_DECORATION}\n"
475 "OpDecorate %indata DescriptorSet 0\n"
476 "OpDecorate %indata Binding 0\n"
477 "OpDecorate %i32arr ArrayStride 4\n"
478 "OpMemberDecorate %buf 0 Offset 0\n"
480 "OpDecorate %sumbuf ${BLOCK_DECORATION}\n"
481 "OpDecorate %sum DescriptorSet 0\n"
482 "OpDecorate %sum Binding 1\n"
483 "OpMemberDecorate %sumbuf 0 Coherent\n"
484 "OpMemberDecorate %sumbuf 0 Offset 0\n"
486 + getComputeAsmCommonTypes("${BLOCK_POINTER_TYPE}") +
488 "%buf = OpTypeStruct %i32arr\n"
489 "%bufptr = OpTypePointer ${BLOCK_POINTER_TYPE} %buf\n"
490 "%indata = OpVariable %bufptr ${BLOCK_POINTER_TYPE}\n"
492 "%sumbuf = OpTypeStruct %i32arr\n"
493 "%sumbufptr = OpTypePointer ${BLOCK_POINTER_TYPE} %sumbuf\n"
494 "%sum = OpVariable %sumbufptr ${BLOCK_POINTER_TYPE}\n"
496 "%id = OpVariable %uvec3ptr Input\n"
497 "%minusone = OpConstant %i32 -1\n"
498 "%zero = OpConstant %i32 0\n"
499 "%one = OpConstant %u32 1\n"
500 "%two = OpConstant %i32 2\n"
502 "%main = OpFunction %void None %voidf\n"
504 "%idval = OpLoad %uvec3 %id\n"
505 "%x = OpCompositeExtract %u32 %idval 0\n"
507 "%inloc = OpAccessChain %i32ptr %indata %zero %x\n"
508 "%inval = OpLoad %i32 %inloc\n"
510 "%outloc = OpAccessChain %i32ptr %sum %zero ${INDEX}\n"
516 #define ADD_OPATOMIC_CASE(NAME, ASSEMBLY, OPATOMIC, NUM_OUTPUT_ELEMENTS) \
518 DE_STATIC_ASSERT((NUM_OUTPUT_ELEMENTS) == 1 || (NUM_OUTPUT_ELEMENTS) == numElements); \
519 cases.push_back(OpAtomicCase(#NAME, ASSEMBLY, OPATOMIC, NUM_OUTPUT_ELEMENTS)); \
520 } while (deGetFalse())
521 #define ADD_OPATOMIC_CASE_1(NAME, ASSEMBLY, OPATOMIC) ADD_OPATOMIC_CASE(NAME, ASSEMBLY, OPATOMIC, 1)
522 #define ADD_OPATOMIC_CASE_N(NAME, ASSEMBLY, OPATOMIC) ADD_OPATOMIC_CASE(NAME, ASSEMBLY, OPATOMIC, numElements)
524 ADD_OPATOMIC_CASE_1(iadd, "%unused = OpAtomicIAdd %i32 %outloc %one %zero %inval\n", OPATOMIC_IADD );
525 ADD_OPATOMIC_CASE_1(isub, "%unused = OpAtomicISub %i32 %outloc %one %zero %inval\n", OPATOMIC_ISUB );
526 ADD_OPATOMIC_CASE_1(iinc, "%unused = OpAtomicIIncrement %i32 %outloc %one %zero\n", OPATOMIC_IINC );
527 ADD_OPATOMIC_CASE_1(idec, "%unused = OpAtomicIDecrement %i32 %outloc %one %zero\n", OPATOMIC_IDEC );
528 ADD_OPATOMIC_CASE_N(load, "%inval2 = OpAtomicLoad %i32 %inloc %zero %zero\n"
529 " OpStore %outloc %inval2\n", OPATOMIC_LOAD );
530 ADD_OPATOMIC_CASE_N(store, " OpAtomicStore %outloc %zero %zero %inval\n", OPATOMIC_STORE );
531 ADD_OPATOMIC_CASE_N(compex, "%even = OpSMod %i32 %inval %two\n"
532 " OpStore %outloc %even\n"
533 "%unused = OpAtomicCompareExchange %i32 %outloc %one %zero %zero %minusone %zero\n", OPATOMIC_COMPEX );
535 #undef ADD_OPATOMIC_CASE
536 #undef ADD_OPATOMIC_CASE_1
537 #undef ADD_OPATOMIC_CASE_N
539 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
541 map<string, string> specializations;
542 ComputeShaderSpec spec;
543 vector<deInt32> inputInts (numElements, 0);
544 vector<deInt32> expected (cases[caseNdx].numOutputElements, -1);
546 specializations["INDEX"] = (cases[caseNdx].numOutputElements == 1) ? "%zero" : "%x";
547 specializations["INSTRUCTION"] = cases[caseNdx].assembly;
548 specializations["BLOCK_DECORATION"] = useStorageBuffer ? "Block" : "BufferBlock";
549 specializations["BLOCK_POINTER_TYPE"] = useStorageBuffer ? "StorageBuffer" : "Uniform";
550 spec.assembly = shaderTemplate.specialize(specializations);
552 if (useStorageBuffer)
553 spec.extensions.push_back("VK_KHR_storage_buffer_storage_class");
555 spec.inputs.push_back(BufferSp(new OpAtomicBuffer(numElements, cases[caseNdx].numOutputElements, cases[caseNdx].opAtomic, BUFFERTYPE_INPUT)));
556 spec.outputs.push_back(BufferSp(new OpAtomicBuffer(numElements, cases[caseNdx].numOutputElements, cases[caseNdx].opAtomic, BUFFERTYPE_EXPECTED)));
557 spec.numWorkGroups = IVec3(numElements, 1, 1);
558 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
561 return group.release();
564 tcu::TestCaseGroup* createOpLineGroup (tcu::TestContext& testCtx)
566 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opline", "Test the OpLine instruction"));
567 ComputeShaderSpec spec;
568 de::Random rnd (deStringHash(group->getName()));
569 const int numElements = 100;
570 vector<float> positiveFloats (numElements, 0);
571 vector<float> negativeFloats (numElements, 0);
573 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
575 for (size_t ndx = 0; ndx < numElements; ++ndx)
576 negativeFloats[ndx] = -positiveFloats[ndx];
579 string(getComputeAsmShaderPreamble()) +
581 "%fname1 = OpString \"negateInputs.comp\"\n"
582 "%fname2 = OpString \"negateInputs\"\n"
584 "OpSource GLSL 430\n"
585 "OpName %main \"main\"\n"
586 "OpName %id \"gl_GlobalInvocationID\"\n"
588 "OpDecorate %id BuiltIn GlobalInvocationId\n"
590 + string(getComputeAsmInputOutputBufferTraits()) +
592 "OpLine %fname1 0 0\n" // At the earliest possible position
594 + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
596 "OpLine %fname1 0 1\n" // Multiple OpLines in sequence
597 "OpLine %fname2 1 0\n" // Different filenames
598 "OpLine %fname1 1000 100000\n"
600 "%id = OpVariable %uvec3ptr Input\n"
601 "%zero = OpConstant %i32 0\n"
603 "OpLine %fname1 1 1\n" // Before a function
605 "%main = OpFunction %void None %voidf\n"
608 "OpLine %fname1 1 1\n" // In a function
610 "%idval = OpLoad %uvec3 %id\n"
611 "%x = OpCompositeExtract %u32 %idval 0\n"
612 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
613 "%inval = OpLoad %f32 %inloc\n"
614 "%neg = OpFNegate %f32 %inval\n"
615 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
616 " OpStore %outloc %neg\n"
619 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
620 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
621 spec.numWorkGroups = IVec3(numElements, 1, 1);
623 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "OpLine appearing at different places", spec));
625 return group.release();
628 tcu::TestCaseGroup* createOpNoLineGroup (tcu::TestContext& testCtx)
630 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opnoline", "Test the OpNoLine instruction"));
631 ComputeShaderSpec spec;
632 de::Random rnd (deStringHash(group->getName()));
633 const int numElements = 100;
634 vector<float> positiveFloats (numElements, 0);
635 vector<float> negativeFloats (numElements, 0);
637 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
639 for (size_t ndx = 0; ndx < numElements; ++ndx)
640 negativeFloats[ndx] = -positiveFloats[ndx];
643 string(getComputeAsmShaderPreamble()) +
645 "%fname = OpString \"negateInputs.comp\"\n"
647 "OpSource GLSL 430\n"
648 "OpName %main \"main\"\n"
649 "OpName %id \"gl_GlobalInvocationID\"\n"
651 "OpDecorate %id BuiltIn GlobalInvocationId\n"
653 + string(getComputeAsmInputOutputBufferTraits()) +
655 "OpNoLine\n" // At the earliest possible position, without preceding OpLine
657 + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
659 "OpLine %fname 0 1\n"
660 "OpNoLine\n" // Immediately following a preceding OpLine
662 "OpLine %fname 1000 1\n"
664 "%id = OpVariable %uvec3ptr Input\n"
665 "%zero = OpConstant %i32 0\n"
667 "OpNoLine\n" // Contents after the previous OpLine
669 "%main = OpFunction %void None %voidf\n"
671 "%idval = OpLoad %uvec3 %id\n"
672 "%x = OpCompositeExtract %u32 %idval 0\n"
674 "OpNoLine\n" // Multiple OpNoLine
678 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
679 "%inval = OpLoad %f32 %inloc\n"
680 "%neg = OpFNegate %f32 %inval\n"
681 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
682 " OpStore %outloc %neg\n"
685 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
686 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
687 spec.numWorkGroups = IVec3(numElements, 1, 1);
689 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "OpNoLine appearing at different places", spec));
691 return group.release();
694 // Compare instruction for the contraction compute case.
695 // Returns true if the output is what is expected from the test case.
696 bool compareNoContractCase(const std::vector<BufferSp>&, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs, TestLog&)
698 if (outputAllocs.size() != 1)
701 // Only size is needed because we are not comparing the exact values.
702 size_t byteSize = expectedOutputs[0]->getByteSize();
704 const float* outputAsFloat = static_cast<const float*>(outputAllocs[0]->getHostPtr());
706 for(size_t i = 0; i < byteSize / sizeof(float); ++i) {
707 if (outputAsFloat[i] != 0.f &&
708 outputAsFloat[i] != -ldexp(1, -24)) {
716 tcu::TestCaseGroup* createNoContractionGroup (tcu::TestContext& testCtx)
718 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "nocontraction", "Test the NoContraction decoration"));
719 vector<CaseParameter> cases;
720 const int numElements = 100;
721 vector<float> inputFloats1 (numElements, 0);
722 vector<float> inputFloats2 (numElements, 0);
723 vector<float> outputFloats (numElements, 0);
724 const StringTemplate shaderTemplate (
725 string(getComputeAsmShaderPreamble()) +
727 "OpName %main \"main\"\n"
728 "OpName %id \"gl_GlobalInvocationID\"\n"
730 "OpDecorate %id BuiltIn GlobalInvocationId\n"
734 "OpDecorate %buf BufferBlock\n"
735 "OpDecorate %indata1 DescriptorSet 0\n"
736 "OpDecorate %indata1 Binding 0\n"
737 "OpDecorate %indata2 DescriptorSet 0\n"
738 "OpDecorate %indata2 Binding 1\n"
739 "OpDecorate %outdata DescriptorSet 0\n"
740 "OpDecorate %outdata Binding 2\n"
741 "OpDecorate %f32arr ArrayStride 4\n"
742 "OpMemberDecorate %buf 0 Offset 0\n"
744 + string(getComputeAsmCommonTypes()) +
746 "%buf = OpTypeStruct %f32arr\n"
747 "%bufptr = OpTypePointer Uniform %buf\n"
748 "%indata1 = OpVariable %bufptr Uniform\n"
749 "%indata2 = OpVariable %bufptr Uniform\n"
750 "%outdata = OpVariable %bufptr Uniform\n"
752 "%id = OpVariable %uvec3ptr Input\n"
753 "%zero = OpConstant %i32 0\n"
754 "%c_f_m1 = OpConstant %f32 -1.\n"
756 "%main = OpFunction %void None %voidf\n"
758 "%idval = OpLoad %uvec3 %id\n"
759 "%x = OpCompositeExtract %u32 %idval 0\n"
760 "%inloc1 = OpAccessChain %f32ptr %indata1 %zero %x\n"
761 "%inval1 = OpLoad %f32 %inloc1\n"
762 "%inloc2 = OpAccessChain %f32ptr %indata2 %zero %x\n"
763 "%inval2 = OpLoad %f32 %inloc2\n"
764 "%mul = OpFMul %f32 %inval1 %inval2\n"
765 "%add = OpFAdd %f32 %mul %c_f_m1\n"
766 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
767 " OpStore %outloc %add\n"
771 cases.push_back(CaseParameter("multiplication", "OpDecorate %mul NoContraction"));
772 cases.push_back(CaseParameter("addition", "OpDecorate %add NoContraction"));
773 cases.push_back(CaseParameter("both", "OpDecorate %mul NoContraction\nOpDecorate %add NoContraction"));
775 for (size_t ndx = 0; ndx < numElements; ++ndx)
777 inputFloats1[ndx] = 1.f + std::ldexp(1.f, -23); // 1 + 2^-23.
778 inputFloats2[ndx] = 1.f - std::ldexp(1.f, -23); // 1 - 2^-23.
779 // Result for (1 + 2^-23) * (1 - 2^-23) - 1. With NoContraction, the multiplication will be
780 // conducted separately and the result is rounded to 1, or 0x1.fffffcp-1
781 // So the final result will be 0.f or 0x1p-24.
782 // If the operation is combined into a precise fused multiply-add, then the result would be
783 // 2^-46 (0xa8800000).
784 outputFloats[ndx] = 0.f;
787 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
789 map<string, string> specializations;
790 ComputeShaderSpec spec;
792 specializations["DECORATION"] = cases[caseNdx].param;
793 spec.assembly = shaderTemplate.specialize(specializations);
794 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats1)));
795 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
796 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
797 spec.numWorkGroups = IVec3(numElements, 1, 1);
798 // Check against the two possible answers based on rounding mode.
799 spec.verifyIO = &compareNoContractCase;
801 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
803 return group.release();
806 bool compareFRem(const std::vector<BufferSp>&, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs, TestLog&)
808 if (outputAllocs.size() != 1)
811 vector<deUint8> expectedBytes;
812 expectedOutputs[0]->getBytes(expectedBytes);
814 const float* expectedOutputAsFloat = reinterpret_cast<const float*>(&expectedBytes.front());
815 const float* outputAsFloat = static_cast<const float*>(outputAllocs[0]->getHostPtr());
817 for (size_t idx = 0; idx < expectedBytes.size() / sizeof(float); ++idx)
819 const float f0 = expectedOutputAsFloat[idx];
820 const float f1 = outputAsFloat[idx];
821 // \todo relative error needs to be fairly high because FRem may be implemented as
822 // (roughly) frac(a/b)*b, so LSB errors can be magnified. But this should be fine for now.
823 if (deFloatAbs((f1 - f0) / f0) > 0.02)
830 tcu::TestCaseGroup* createOpFRemGroup (tcu::TestContext& testCtx)
832 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opfrem", "Test the OpFRem instruction"));
833 ComputeShaderSpec spec;
834 de::Random rnd (deStringHash(group->getName()));
835 const int numElements = 200;
836 vector<float> inputFloats1 (numElements, 0);
837 vector<float> inputFloats2 (numElements, 0);
838 vector<float> outputFloats (numElements, 0);
840 fillRandomScalars(rnd, -10000.f, 10000.f, &inputFloats1[0], numElements);
841 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats2[0], numElements);
843 for (size_t ndx = 0; ndx < numElements; ++ndx)
845 // Guard against divisors near zero.
846 if (std::fabs(inputFloats2[ndx]) < 1e-3)
847 inputFloats2[ndx] = 8.f;
849 // The return value of std::fmod() has the same sign as its first operand, which is how OpFRem spec'd.
850 outputFloats[ndx] = std::fmod(inputFloats1[ndx], inputFloats2[ndx]);
854 string(getComputeAsmShaderPreamble()) +
856 "OpName %main \"main\"\n"
857 "OpName %id \"gl_GlobalInvocationID\"\n"
859 "OpDecorate %id BuiltIn GlobalInvocationId\n"
861 "OpDecorate %buf BufferBlock\n"
862 "OpDecorate %indata1 DescriptorSet 0\n"
863 "OpDecorate %indata1 Binding 0\n"
864 "OpDecorate %indata2 DescriptorSet 0\n"
865 "OpDecorate %indata2 Binding 1\n"
866 "OpDecorate %outdata DescriptorSet 0\n"
867 "OpDecorate %outdata Binding 2\n"
868 "OpDecorate %f32arr ArrayStride 4\n"
869 "OpMemberDecorate %buf 0 Offset 0\n"
871 + string(getComputeAsmCommonTypes()) +
873 "%buf = OpTypeStruct %f32arr\n"
874 "%bufptr = OpTypePointer Uniform %buf\n"
875 "%indata1 = OpVariable %bufptr Uniform\n"
876 "%indata2 = OpVariable %bufptr Uniform\n"
877 "%outdata = OpVariable %bufptr Uniform\n"
879 "%id = OpVariable %uvec3ptr Input\n"
880 "%zero = OpConstant %i32 0\n"
882 "%main = OpFunction %void None %voidf\n"
884 "%idval = OpLoad %uvec3 %id\n"
885 "%x = OpCompositeExtract %u32 %idval 0\n"
886 "%inloc1 = OpAccessChain %f32ptr %indata1 %zero %x\n"
887 "%inval1 = OpLoad %f32 %inloc1\n"
888 "%inloc2 = OpAccessChain %f32ptr %indata2 %zero %x\n"
889 "%inval2 = OpLoad %f32 %inloc2\n"
890 "%rem = OpFRem %f32 %inval1 %inval2\n"
891 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
892 " OpStore %outloc %rem\n"
896 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats1)));
897 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
898 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
899 spec.numWorkGroups = IVec3(numElements, 1, 1);
900 spec.verifyIO = &compareFRem;
902 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "", spec));
904 return group.release();
907 bool compareNMin (const std::vector<BufferSp>&, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs, TestLog&)
909 if (outputAllocs.size() != 1)
912 const BufferSp& expectedOutput (expectedOutputs[0]);
913 std::vector<deUint8> data;
914 expectedOutput->getBytes(data);
916 const float* const expectedOutputAsFloat = reinterpret_cast<const float*>(&data.front());
917 const float* const outputAsFloat = static_cast<const float*>(outputAllocs[0]->getHostPtr());
919 for (size_t idx = 0; idx < expectedOutput->getByteSize() / sizeof(float); ++idx)
921 const float f0 = expectedOutputAsFloat[idx];
922 const float f1 = outputAsFloat[idx];
924 // For NMin, we accept NaN as output if both inputs were NaN.
925 // Otherwise the NaN is the wrong choise, as on architectures that
926 // do not handle NaN, those are huge values.
927 if (!(tcu::Float32(f1).isNaN() && tcu::Float32(f0).isNaN()) && deFloatAbs(f1 - f0) > 0.00001f)
934 tcu::TestCaseGroup* createOpNMinGroup (tcu::TestContext& testCtx)
936 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opnmin", "Test the OpNMin instruction"));
937 ComputeShaderSpec spec;
938 de::Random rnd (deStringHash(group->getName()));
939 const int numElements = 200;
940 vector<float> inputFloats1 (numElements, 0);
941 vector<float> inputFloats2 (numElements, 0);
942 vector<float> outputFloats (numElements, 0);
944 fillRandomScalars(rnd, -10000.f, 10000.f, &inputFloats1[0], numElements);
945 fillRandomScalars(rnd, -10000.f, 10000.f, &inputFloats2[0], numElements);
947 // Make the first case a full-NAN case.
948 inputFloats1[0] = TCU_NAN;
949 inputFloats2[0] = TCU_NAN;
951 for (size_t ndx = 0; ndx < numElements; ++ndx)
953 // By default, pick the smallest
954 outputFloats[ndx] = std::min(inputFloats1[ndx], inputFloats2[ndx]);
956 // Make half of the cases NaN cases
959 // Alternate between the NaN operand
962 outputFloats[ndx] = inputFloats2[ndx];
963 inputFloats1[ndx] = TCU_NAN;
967 outputFloats[ndx] = inputFloats1[ndx];
968 inputFloats2[ndx] = TCU_NAN;
974 "OpCapability Shader\n"
975 "%std450 = OpExtInstImport \"GLSL.std.450\"\n"
976 "OpMemoryModel Logical GLSL450\n"
977 "OpEntryPoint GLCompute %main \"main\" %id\n"
978 "OpExecutionMode %main LocalSize 1 1 1\n"
980 "OpName %main \"main\"\n"
981 "OpName %id \"gl_GlobalInvocationID\"\n"
983 "OpDecorate %id BuiltIn GlobalInvocationId\n"
985 "OpDecorate %buf BufferBlock\n"
986 "OpDecorate %indata1 DescriptorSet 0\n"
987 "OpDecorate %indata1 Binding 0\n"
988 "OpDecorate %indata2 DescriptorSet 0\n"
989 "OpDecorate %indata2 Binding 1\n"
990 "OpDecorate %outdata DescriptorSet 0\n"
991 "OpDecorate %outdata Binding 2\n"
992 "OpDecorate %f32arr ArrayStride 4\n"
993 "OpMemberDecorate %buf 0 Offset 0\n"
995 + string(getComputeAsmCommonTypes()) +
997 "%buf = OpTypeStruct %f32arr\n"
998 "%bufptr = OpTypePointer Uniform %buf\n"
999 "%indata1 = OpVariable %bufptr Uniform\n"
1000 "%indata2 = OpVariable %bufptr Uniform\n"
1001 "%outdata = OpVariable %bufptr Uniform\n"
1003 "%id = OpVariable %uvec3ptr Input\n"
1004 "%zero = OpConstant %i32 0\n"
1006 "%main = OpFunction %void None %voidf\n"
1007 "%label = OpLabel\n"
1008 "%idval = OpLoad %uvec3 %id\n"
1009 "%x = OpCompositeExtract %u32 %idval 0\n"
1010 "%inloc1 = OpAccessChain %f32ptr %indata1 %zero %x\n"
1011 "%inval1 = OpLoad %f32 %inloc1\n"
1012 "%inloc2 = OpAccessChain %f32ptr %indata2 %zero %x\n"
1013 "%inval2 = OpLoad %f32 %inloc2\n"
1014 "%rem = OpExtInst %f32 %std450 NMin %inval1 %inval2\n"
1015 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
1016 " OpStore %outloc %rem\n"
1020 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats1)));
1021 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
1022 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
1023 spec.numWorkGroups = IVec3(numElements, 1, 1);
1024 spec.verifyIO = &compareNMin;
1026 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "", spec));
1028 return group.release();
1031 bool compareNMax (const std::vector<BufferSp>&, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs, TestLog&)
1033 if (outputAllocs.size() != 1)
1036 const BufferSp& expectedOutput = expectedOutputs[0];
1037 std::vector<deUint8> data;
1038 expectedOutput->getBytes(data);
1040 const float* const expectedOutputAsFloat = reinterpret_cast<const float*>(&data.front());
1041 const float* const outputAsFloat = static_cast<const float*>(outputAllocs[0]->getHostPtr());
1043 for (size_t idx = 0; idx < expectedOutput->getByteSize() / sizeof(float); ++idx)
1045 const float f0 = expectedOutputAsFloat[idx];
1046 const float f1 = outputAsFloat[idx];
1048 // For NMax, NaN is considered acceptable result, since in
1049 // architectures that do not handle NaNs, those are huge values.
1050 if (!tcu::Float32(f1).isNaN() && deFloatAbs(f1 - f0) > 0.00001f)
1057 tcu::TestCaseGroup* createOpNMaxGroup (tcu::TestContext& testCtx)
1059 de::MovePtr<tcu::TestCaseGroup> group(new tcu::TestCaseGroup(testCtx, "opnmax", "Test the OpNMax instruction"));
1060 ComputeShaderSpec spec;
1061 de::Random rnd (deStringHash(group->getName()));
1062 const int numElements = 200;
1063 vector<float> inputFloats1 (numElements, 0);
1064 vector<float> inputFloats2 (numElements, 0);
1065 vector<float> outputFloats (numElements, 0);
1067 fillRandomScalars(rnd, -10000.f, 10000.f, &inputFloats1[0], numElements);
1068 fillRandomScalars(rnd, -10000.f, 10000.f, &inputFloats2[0], numElements);
1070 // Make the first case a full-NAN case.
1071 inputFloats1[0] = TCU_NAN;
1072 inputFloats2[0] = TCU_NAN;
1074 for (size_t ndx = 0; ndx < numElements; ++ndx)
1076 // By default, pick the biggest
1077 outputFloats[ndx] = std::max(inputFloats1[ndx], inputFloats2[ndx]);
1079 // Make half of the cases NaN cases
1082 // Alternate between the NaN operand
1085 outputFloats[ndx] = inputFloats2[ndx];
1086 inputFloats1[ndx] = TCU_NAN;
1090 outputFloats[ndx] = inputFloats1[ndx];
1091 inputFloats2[ndx] = TCU_NAN;
1097 "OpCapability Shader\n"
1098 "%std450 = OpExtInstImport \"GLSL.std.450\"\n"
1099 "OpMemoryModel Logical GLSL450\n"
1100 "OpEntryPoint GLCompute %main \"main\" %id\n"
1101 "OpExecutionMode %main LocalSize 1 1 1\n"
1103 "OpName %main \"main\"\n"
1104 "OpName %id \"gl_GlobalInvocationID\"\n"
1106 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1108 "OpDecorate %buf BufferBlock\n"
1109 "OpDecorate %indata1 DescriptorSet 0\n"
1110 "OpDecorate %indata1 Binding 0\n"
1111 "OpDecorate %indata2 DescriptorSet 0\n"
1112 "OpDecorate %indata2 Binding 1\n"
1113 "OpDecorate %outdata DescriptorSet 0\n"
1114 "OpDecorate %outdata Binding 2\n"
1115 "OpDecorate %f32arr ArrayStride 4\n"
1116 "OpMemberDecorate %buf 0 Offset 0\n"
1118 + string(getComputeAsmCommonTypes()) +
1120 "%buf = OpTypeStruct %f32arr\n"
1121 "%bufptr = OpTypePointer Uniform %buf\n"
1122 "%indata1 = OpVariable %bufptr Uniform\n"
1123 "%indata2 = OpVariable %bufptr Uniform\n"
1124 "%outdata = OpVariable %bufptr Uniform\n"
1126 "%id = OpVariable %uvec3ptr Input\n"
1127 "%zero = OpConstant %i32 0\n"
1129 "%main = OpFunction %void None %voidf\n"
1130 "%label = OpLabel\n"
1131 "%idval = OpLoad %uvec3 %id\n"
1132 "%x = OpCompositeExtract %u32 %idval 0\n"
1133 "%inloc1 = OpAccessChain %f32ptr %indata1 %zero %x\n"
1134 "%inval1 = OpLoad %f32 %inloc1\n"
1135 "%inloc2 = OpAccessChain %f32ptr %indata2 %zero %x\n"
1136 "%inval2 = OpLoad %f32 %inloc2\n"
1137 "%rem = OpExtInst %f32 %std450 NMax %inval1 %inval2\n"
1138 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
1139 " OpStore %outloc %rem\n"
1143 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats1)));
1144 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
1145 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
1146 spec.numWorkGroups = IVec3(numElements, 1, 1);
1147 spec.verifyIO = &compareNMax;
1149 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "", spec));
1151 return group.release();
1154 bool compareNClamp (const std::vector<BufferSp>&, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs, TestLog&)
1156 if (outputAllocs.size() != 1)
1159 const BufferSp& expectedOutput = expectedOutputs[0];
1160 std::vector<deUint8> data;
1161 expectedOutput->getBytes(data);
1163 const float* const expectedOutputAsFloat = reinterpret_cast<const float*>(&data.front());
1164 const float* const outputAsFloat = static_cast<const float*>(outputAllocs[0]->getHostPtr());
1166 for (size_t idx = 0; idx < expectedOutput->getByteSize() / sizeof(float) / 2; ++idx)
1168 const float e0 = expectedOutputAsFloat[idx * 2];
1169 const float e1 = expectedOutputAsFloat[idx * 2 + 1];
1170 const float res = outputAsFloat[idx];
1172 // For NClamp, we have two possible outcomes based on
1173 // whether NaNs are handled or not.
1174 // If either min or max value is NaN, the result is undefined,
1175 // so this test doesn't stress those. If the clamped value is
1176 // NaN, and NaNs are handled, the result is min; if NaNs are not
1177 // handled, they are big values that result in max.
1178 // If all three parameters are NaN, the result should be NaN.
1179 if (!((tcu::Float32(e0).isNaN() && tcu::Float32(res).isNaN()) ||
1180 (deFloatAbs(e0 - res) < 0.00001f) ||
1181 (deFloatAbs(e1 - res) < 0.00001f)))
1188 tcu::TestCaseGroup* createOpNClampGroup (tcu::TestContext& testCtx)
1190 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opnclamp", "Test the OpNClamp instruction"));
1191 ComputeShaderSpec spec;
1192 de::Random rnd (deStringHash(group->getName()));
1193 const int numElements = 200;
1194 vector<float> inputFloats1 (numElements, 0);
1195 vector<float> inputFloats2 (numElements, 0);
1196 vector<float> inputFloats3 (numElements, 0);
1197 vector<float> outputFloats (numElements * 2, 0);
1199 fillRandomScalars(rnd, -10000.f, 10000.f, &inputFloats1[0], numElements);
1200 fillRandomScalars(rnd, -10000.f, 10000.f, &inputFloats2[0], numElements);
1201 fillRandomScalars(rnd, -10000.f, 10000.f, &inputFloats3[0], numElements);
1203 for (size_t ndx = 0; ndx < numElements; ++ndx)
1205 // Results are only defined if max value is bigger than min value.
1206 if (inputFloats2[ndx] > inputFloats3[ndx])
1208 float t = inputFloats2[ndx];
1209 inputFloats2[ndx] = inputFloats3[ndx];
1210 inputFloats3[ndx] = t;
1213 // By default, do the clamp, setting both possible answers
1214 float defaultRes = std::min(std::max(inputFloats1[ndx], inputFloats2[ndx]), inputFloats3[ndx]);
1216 float maxResA = std::max(inputFloats1[ndx], inputFloats2[ndx]);
1217 float maxResB = maxResA;
1219 // Alternate between the NaN cases
1222 inputFloats1[ndx] = TCU_NAN;
1223 // If NaN is handled, the result should be same as the clamp minimum.
1224 // If NaN is not handled, the result should clamp to the clamp maximum.
1225 maxResA = inputFloats2[ndx];
1226 maxResB = inputFloats3[ndx];
1230 // Not a NaN case - only one legal result.
1231 maxResA = defaultRes;
1232 maxResB = defaultRes;
1235 outputFloats[ndx * 2] = maxResA;
1236 outputFloats[ndx * 2 + 1] = maxResB;
1239 // Make the first case a full-NAN case.
1240 inputFloats1[0] = TCU_NAN;
1241 inputFloats2[0] = TCU_NAN;
1242 inputFloats3[0] = TCU_NAN;
1243 outputFloats[0] = TCU_NAN;
1244 outputFloats[1] = TCU_NAN;
1247 "OpCapability Shader\n"
1248 "%std450 = OpExtInstImport \"GLSL.std.450\"\n"
1249 "OpMemoryModel Logical GLSL450\n"
1250 "OpEntryPoint GLCompute %main \"main\" %id\n"
1251 "OpExecutionMode %main LocalSize 1 1 1\n"
1253 "OpName %main \"main\"\n"
1254 "OpName %id \"gl_GlobalInvocationID\"\n"
1256 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1258 "OpDecorate %buf BufferBlock\n"
1259 "OpDecorate %indata1 DescriptorSet 0\n"
1260 "OpDecorate %indata1 Binding 0\n"
1261 "OpDecorate %indata2 DescriptorSet 0\n"
1262 "OpDecorate %indata2 Binding 1\n"
1263 "OpDecorate %indata3 DescriptorSet 0\n"
1264 "OpDecorate %indata3 Binding 2\n"
1265 "OpDecorate %outdata DescriptorSet 0\n"
1266 "OpDecorate %outdata Binding 3\n"
1267 "OpDecorate %f32arr ArrayStride 4\n"
1268 "OpMemberDecorate %buf 0 Offset 0\n"
1270 + string(getComputeAsmCommonTypes()) +
1272 "%buf = OpTypeStruct %f32arr\n"
1273 "%bufptr = OpTypePointer Uniform %buf\n"
1274 "%indata1 = OpVariable %bufptr Uniform\n"
1275 "%indata2 = OpVariable %bufptr Uniform\n"
1276 "%indata3 = OpVariable %bufptr Uniform\n"
1277 "%outdata = OpVariable %bufptr Uniform\n"
1279 "%id = OpVariable %uvec3ptr Input\n"
1280 "%zero = OpConstant %i32 0\n"
1282 "%main = OpFunction %void None %voidf\n"
1283 "%label = OpLabel\n"
1284 "%idval = OpLoad %uvec3 %id\n"
1285 "%x = OpCompositeExtract %u32 %idval 0\n"
1286 "%inloc1 = OpAccessChain %f32ptr %indata1 %zero %x\n"
1287 "%inval1 = OpLoad %f32 %inloc1\n"
1288 "%inloc2 = OpAccessChain %f32ptr %indata2 %zero %x\n"
1289 "%inval2 = OpLoad %f32 %inloc2\n"
1290 "%inloc3 = OpAccessChain %f32ptr %indata3 %zero %x\n"
1291 "%inval3 = OpLoad %f32 %inloc3\n"
1292 "%rem = OpExtInst %f32 %std450 NClamp %inval1 %inval2 %inval3\n"
1293 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
1294 " OpStore %outloc %rem\n"
1298 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats1)));
1299 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
1300 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats3)));
1301 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
1302 spec.numWorkGroups = IVec3(numElements, 1, 1);
1303 spec.verifyIO = &compareNClamp;
1305 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "", spec));
1307 return group.release();
1310 tcu::TestCaseGroup* createOpSRemComputeGroup (tcu::TestContext& testCtx, qpTestResult negFailResult)
1312 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opsrem", "Test the OpSRem instruction"));
1313 de::Random rnd (deStringHash(group->getName()));
1314 const int numElements = 200;
1316 const struct CaseParams
1319 const char* failMessage; // customized status message
1320 qpTestResult failResult; // override status on failure
1321 int op1Min, op1Max; // operand ranges
1325 { "positive", "Output doesn't match with expected", QP_TEST_RESULT_FAIL, 0, 65536, 0, 100 },
1326 { "all", "Inconsistent results, but within specification", negFailResult, -65536, 65536, -100, 100 }, // see below
1328 // If either operand is negative the result is undefined. Some implementations may still return correct values.
1330 for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(cases); ++caseNdx)
1332 const CaseParams& params = cases[caseNdx];
1333 ComputeShaderSpec spec;
1334 vector<deInt32> inputInts1 (numElements, 0);
1335 vector<deInt32> inputInts2 (numElements, 0);
1336 vector<deInt32> outputInts (numElements, 0);
1338 fillRandomScalars(rnd, params.op1Min, params.op1Max, &inputInts1[0], numElements);
1339 fillRandomScalars(rnd, params.op2Min, params.op2Max, &inputInts2[0], numElements, filterNotZero);
1341 for (int ndx = 0; ndx < numElements; ++ndx)
1343 // The return value of std::fmod() has the same sign as its first operand, which is how OpFRem spec'd.
1344 outputInts[ndx] = inputInts1[ndx] % inputInts2[ndx];
1348 string(getComputeAsmShaderPreamble()) +
1350 "OpName %main \"main\"\n"
1351 "OpName %id \"gl_GlobalInvocationID\"\n"
1353 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1355 "OpDecorate %buf BufferBlock\n"
1356 "OpDecorate %indata1 DescriptorSet 0\n"
1357 "OpDecorate %indata1 Binding 0\n"
1358 "OpDecorate %indata2 DescriptorSet 0\n"
1359 "OpDecorate %indata2 Binding 1\n"
1360 "OpDecorate %outdata DescriptorSet 0\n"
1361 "OpDecorate %outdata Binding 2\n"
1362 "OpDecorate %i32arr ArrayStride 4\n"
1363 "OpMemberDecorate %buf 0 Offset 0\n"
1365 + string(getComputeAsmCommonTypes()) +
1367 "%buf = OpTypeStruct %i32arr\n"
1368 "%bufptr = OpTypePointer Uniform %buf\n"
1369 "%indata1 = OpVariable %bufptr Uniform\n"
1370 "%indata2 = OpVariable %bufptr Uniform\n"
1371 "%outdata = OpVariable %bufptr Uniform\n"
1373 "%id = OpVariable %uvec3ptr Input\n"
1374 "%zero = OpConstant %i32 0\n"
1376 "%main = OpFunction %void None %voidf\n"
1377 "%label = OpLabel\n"
1378 "%idval = OpLoad %uvec3 %id\n"
1379 "%x = OpCompositeExtract %u32 %idval 0\n"
1380 "%inloc1 = OpAccessChain %i32ptr %indata1 %zero %x\n"
1381 "%inval1 = OpLoad %i32 %inloc1\n"
1382 "%inloc2 = OpAccessChain %i32ptr %indata2 %zero %x\n"
1383 "%inval2 = OpLoad %i32 %inloc2\n"
1384 "%rem = OpSRem %i32 %inval1 %inval2\n"
1385 "%outloc = OpAccessChain %i32ptr %outdata %zero %x\n"
1386 " OpStore %outloc %rem\n"
1390 spec.inputs.push_back (BufferSp(new Int32Buffer(inputInts1)));
1391 spec.inputs.push_back (BufferSp(new Int32Buffer(inputInts2)));
1392 spec.outputs.push_back (BufferSp(new Int32Buffer(outputInts)));
1393 spec.numWorkGroups = IVec3(numElements, 1, 1);
1394 spec.failResult = params.failResult;
1395 spec.failMessage = params.failMessage;
1397 group->addChild(new SpvAsmComputeShaderCase(testCtx, params.name, "", spec));
1400 return group.release();
1403 tcu::TestCaseGroup* createOpSRemComputeGroup64 (tcu::TestContext& testCtx, qpTestResult negFailResult)
1405 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opsrem64", "Test the 64-bit OpSRem instruction"));
1406 de::Random rnd (deStringHash(group->getName()));
1407 const int numElements = 200;
1409 const struct CaseParams
1412 const char* failMessage; // customized status message
1413 qpTestResult failResult; // override status on failure
1417 { "positive", "Output doesn't match with expected", QP_TEST_RESULT_FAIL, true },
1418 { "all", "Inconsistent results, but within specification", negFailResult, false }, // see below
1420 // If either operand is negative the result is undefined. Some implementations may still return correct values.
1422 for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(cases); ++caseNdx)
1424 const CaseParams& params = cases[caseNdx];
1425 ComputeShaderSpec spec;
1426 vector<deInt64> inputInts1 (numElements, 0);
1427 vector<deInt64> inputInts2 (numElements, 0);
1428 vector<deInt64> outputInts (numElements, 0);
1430 if (params.positive)
1432 fillRandomInt64sLogDistributed(rnd, inputInts1, numElements, filterNonNegative);
1433 fillRandomInt64sLogDistributed(rnd, inputInts2, numElements, filterPositive);
1437 fillRandomInt64sLogDistributed(rnd, inputInts1, numElements);
1438 fillRandomInt64sLogDistributed(rnd, inputInts2, numElements, filterNotZero);
1441 for (int ndx = 0; ndx < numElements; ++ndx)
1443 // The return value of std::fmod() has the same sign as its first operand, which is how OpFRem spec'd.
1444 outputInts[ndx] = inputInts1[ndx] % inputInts2[ndx];
1448 "OpCapability Int64\n"
1450 + string(getComputeAsmShaderPreamble()) +
1452 "OpName %main \"main\"\n"
1453 "OpName %id \"gl_GlobalInvocationID\"\n"
1455 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1457 "OpDecorate %buf BufferBlock\n"
1458 "OpDecorate %indata1 DescriptorSet 0\n"
1459 "OpDecorate %indata1 Binding 0\n"
1460 "OpDecorate %indata2 DescriptorSet 0\n"
1461 "OpDecorate %indata2 Binding 1\n"
1462 "OpDecorate %outdata DescriptorSet 0\n"
1463 "OpDecorate %outdata Binding 2\n"
1464 "OpDecorate %i64arr ArrayStride 8\n"
1465 "OpMemberDecorate %buf 0 Offset 0\n"
1467 + string(getComputeAsmCommonTypes())
1468 + string(getComputeAsmCommonInt64Types()) +
1470 "%buf = OpTypeStruct %i64arr\n"
1471 "%bufptr = OpTypePointer Uniform %buf\n"
1472 "%indata1 = OpVariable %bufptr Uniform\n"
1473 "%indata2 = OpVariable %bufptr Uniform\n"
1474 "%outdata = OpVariable %bufptr Uniform\n"
1476 "%id = OpVariable %uvec3ptr Input\n"
1477 "%zero = OpConstant %i64 0\n"
1479 "%main = OpFunction %void None %voidf\n"
1480 "%label = OpLabel\n"
1481 "%idval = OpLoad %uvec3 %id\n"
1482 "%x = OpCompositeExtract %u32 %idval 0\n"
1483 "%inloc1 = OpAccessChain %i64ptr %indata1 %zero %x\n"
1484 "%inval1 = OpLoad %i64 %inloc1\n"
1485 "%inloc2 = OpAccessChain %i64ptr %indata2 %zero %x\n"
1486 "%inval2 = OpLoad %i64 %inloc2\n"
1487 "%rem = OpSRem %i64 %inval1 %inval2\n"
1488 "%outloc = OpAccessChain %i64ptr %outdata %zero %x\n"
1489 " OpStore %outloc %rem\n"
1493 spec.inputs.push_back (BufferSp(new Int64Buffer(inputInts1)));
1494 spec.inputs.push_back (BufferSp(new Int64Buffer(inputInts2)));
1495 spec.outputs.push_back (BufferSp(new Int64Buffer(outputInts)));
1496 spec.numWorkGroups = IVec3(numElements, 1, 1);
1497 spec.failResult = params.failResult;
1498 spec.failMessage = params.failMessage;
1500 group->addChild(new SpvAsmComputeShaderCase(testCtx, params.name, "", spec, COMPUTE_TEST_USES_INT64));
1503 return group.release();
1506 tcu::TestCaseGroup* createOpSModComputeGroup (tcu::TestContext& testCtx, qpTestResult negFailResult)
1508 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opsmod", "Test the OpSMod instruction"));
1509 de::Random rnd (deStringHash(group->getName()));
1510 const int numElements = 200;
1512 const struct CaseParams
1515 const char* failMessage; // customized status message
1516 qpTestResult failResult; // override status on failure
1517 int op1Min, op1Max; // operand ranges
1521 { "positive", "Output doesn't match with expected", QP_TEST_RESULT_FAIL, 0, 65536, 0, 100 },
1522 { "all", "Inconsistent results, but within specification", negFailResult, -65536, 65536, -100, 100 }, // see below
1524 // If either operand is negative the result is undefined. Some implementations may still return correct values.
1526 for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(cases); ++caseNdx)
1528 const CaseParams& params = cases[caseNdx];
1530 ComputeShaderSpec spec;
1531 vector<deInt32> inputInts1 (numElements, 0);
1532 vector<deInt32> inputInts2 (numElements, 0);
1533 vector<deInt32> outputInts (numElements, 0);
1535 fillRandomScalars(rnd, params.op1Min, params.op1Max, &inputInts1[0], numElements);
1536 fillRandomScalars(rnd, params.op2Min, params.op2Max, &inputInts2[0], numElements, filterNotZero);
1538 for (int ndx = 0; ndx < numElements; ++ndx)
1540 deInt32 rem = inputInts1[ndx] % inputInts2[ndx];
1543 outputInts[ndx] = 0;
1545 else if ((inputInts1[ndx] >= 0) == (inputInts2[ndx] >= 0))
1547 // They have the same sign
1548 outputInts[ndx] = rem;
1552 // They have opposite sign. The remainder operation takes the
1553 // sign inputInts1[ndx] but OpSMod is supposed to take ths sign
1554 // of inputInts2[ndx]. Adding inputInts2[ndx] will ensure that
1555 // the result has the correct sign and that it is still
1556 // congruent to inputInts1[ndx] modulo inputInts2[ndx]
1558 // See also http://mathforum.org/library/drmath/view/52343.html
1559 outputInts[ndx] = rem + inputInts2[ndx];
1564 string(getComputeAsmShaderPreamble()) +
1566 "OpName %main \"main\"\n"
1567 "OpName %id \"gl_GlobalInvocationID\"\n"
1569 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1571 "OpDecorate %buf BufferBlock\n"
1572 "OpDecorate %indata1 DescriptorSet 0\n"
1573 "OpDecorate %indata1 Binding 0\n"
1574 "OpDecorate %indata2 DescriptorSet 0\n"
1575 "OpDecorate %indata2 Binding 1\n"
1576 "OpDecorate %outdata DescriptorSet 0\n"
1577 "OpDecorate %outdata Binding 2\n"
1578 "OpDecorate %i32arr ArrayStride 4\n"
1579 "OpMemberDecorate %buf 0 Offset 0\n"
1581 + string(getComputeAsmCommonTypes()) +
1583 "%buf = OpTypeStruct %i32arr\n"
1584 "%bufptr = OpTypePointer Uniform %buf\n"
1585 "%indata1 = OpVariable %bufptr Uniform\n"
1586 "%indata2 = OpVariable %bufptr Uniform\n"
1587 "%outdata = OpVariable %bufptr Uniform\n"
1589 "%id = OpVariable %uvec3ptr Input\n"
1590 "%zero = OpConstant %i32 0\n"
1592 "%main = OpFunction %void None %voidf\n"
1593 "%label = OpLabel\n"
1594 "%idval = OpLoad %uvec3 %id\n"
1595 "%x = OpCompositeExtract %u32 %idval 0\n"
1596 "%inloc1 = OpAccessChain %i32ptr %indata1 %zero %x\n"
1597 "%inval1 = OpLoad %i32 %inloc1\n"
1598 "%inloc2 = OpAccessChain %i32ptr %indata2 %zero %x\n"
1599 "%inval2 = OpLoad %i32 %inloc2\n"
1600 "%rem = OpSMod %i32 %inval1 %inval2\n"
1601 "%outloc = OpAccessChain %i32ptr %outdata %zero %x\n"
1602 " OpStore %outloc %rem\n"
1606 spec.inputs.push_back (BufferSp(new Int32Buffer(inputInts1)));
1607 spec.inputs.push_back (BufferSp(new Int32Buffer(inputInts2)));
1608 spec.outputs.push_back (BufferSp(new Int32Buffer(outputInts)));
1609 spec.numWorkGroups = IVec3(numElements, 1, 1);
1610 spec.failResult = params.failResult;
1611 spec.failMessage = params.failMessage;
1613 group->addChild(new SpvAsmComputeShaderCase(testCtx, params.name, "", spec));
1616 return group.release();
1619 tcu::TestCaseGroup* createOpSModComputeGroup64 (tcu::TestContext& testCtx, qpTestResult negFailResult)
1621 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opsmod64", "Test the OpSMod instruction"));
1622 de::Random rnd (deStringHash(group->getName()));
1623 const int numElements = 200;
1625 const struct CaseParams
1628 const char* failMessage; // customized status message
1629 qpTestResult failResult; // override status on failure
1633 { "positive", "Output doesn't match with expected", QP_TEST_RESULT_FAIL, true },
1634 { "all", "Inconsistent results, but within specification", negFailResult, false }, // see below
1636 // If either operand is negative the result is undefined. Some implementations may still return correct values.
1638 for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(cases); ++caseNdx)
1640 const CaseParams& params = cases[caseNdx];
1642 ComputeShaderSpec spec;
1643 vector<deInt64> inputInts1 (numElements, 0);
1644 vector<deInt64> inputInts2 (numElements, 0);
1645 vector<deInt64> outputInts (numElements, 0);
1648 if (params.positive)
1650 fillRandomInt64sLogDistributed(rnd, inputInts1, numElements, filterNonNegative);
1651 fillRandomInt64sLogDistributed(rnd, inputInts2, numElements, filterPositive);
1655 fillRandomInt64sLogDistributed(rnd, inputInts1, numElements);
1656 fillRandomInt64sLogDistributed(rnd, inputInts2, numElements, filterNotZero);
1659 for (int ndx = 0; ndx < numElements; ++ndx)
1661 deInt64 rem = inputInts1[ndx] % inputInts2[ndx];
1664 outputInts[ndx] = 0;
1666 else if ((inputInts1[ndx] >= 0) == (inputInts2[ndx] >= 0))
1668 // They have the same sign
1669 outputInts[ndx] = rem;
1673 // They have opposite sign. The remainder operation takes the
1674 // sign inputInts1[ndx] but OpSMod is supposed to take ths sign
1675 // of inputInts2[ndx]. Adding inputInts2[ndx] will ensure that
1676 // the result has the correct sign and that it is still
1677 // congruent to inputInts1[ndx] modulo inputInts2[ndx]
1679 // See also http://mathforum.org/library/drmath/view/52343.html
1680 outputInts[ndx] = rem + inputInts2[ndx];
1685 "OpCapability Int64\n"
1687 + string(getComputeAsmShaderPreamble()) +
1689 "OpName %main \"main\"\n"
1690 "OpName %id \"gl_GlobalInvocationID\"\n"
1692 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1694 "OpDecorate %buf BufferBlock\n"
1695 "OpDecorate %indata1 DescriptorSet 0\n"
1696 "OpDecorate %indata1 Binding 0\n"
1697 "OpDecorate %indata2 DescriptorSet 0\n"
1698 "OpDecorate %indata2 Binding 1\n"
1699 "OpDecorate %outdata DescriptorSet 0\n"
1700 "OpDecorate %outdata Binding 2\n"
1701 "OpDecorate %i64arr ArrayStride 8\n"
1702 "OpMemberDecorate %buf 0 Offset 0\n"
1704 + string(getComputeAsmCommonTypes())
1705 + string(getComputeAsmCommonInt64Types()) +
1707 "%buf = OpTypeStruct %i64arr\n"
1708 "%bufptr = OpTypePointer Uniform %buf\n"
1709 "%indata1 = OpVariable %bufptr Uniform\n"
1710 "%indata2 = OpVariable %bufptr Uniform\n"
1711 "%outdata = OpVariable %bufptr Uniform\n"
1713 "%id = OpVariable %uvec3ptr Input\n"
1714 "%zero = OpConstant %i64 0\n"
1716 "%main = OpFunction %void None %voidf\n"
1717 "%label = OpLabel\n"
1718 "%idval = OpLoad %uvec3 %id\n"
1719 "%x = OpCompositeExtract %u32 %idval 0\n"
1720 "%inloc1 = OpAccessChain %i64ptr %indata1 %zero %x\n"
1721 "%inval1 = OpLoad %i64 %inloc1\n"
1722 "%inloc2 = OpAccessChain %i64ptr %indata2 %zero %x\n"
1723 "%inval2 = OpLoad %i64 %inloc2\n"
1724 "%rem = OpSMod %i64 %inval1 %inval2\n"
1725 "%outloc = OpAccessChain %i64ptr %outdata %zero %x\n"
1726 " OpStore %outloc %rem\n"
1730 spec.inputs.push_back (BufferSp(new Int64Buffer(inputInts1)));
1731 spec.inputs.push_back (BufferSp(new Int64Buffer(inputInts2)));
1732 spec.outputs.push_back (BufferSp(new Int64Buffer(outputInts)));
1733 spec.numWorkGroups = IVec3(numElements, 1, 1);
1734 spec.failResult = params.failResult;
1735 spec.failMessage = params.failMessage;
1737 group->addChild(new SpvAsmComputeShaderCase(testCtx, params.name, "", spec, COMPUTE_TEST_USES_INT64));
1740 return group.release();
1743 // Copy contents in the input buffer to the output buffer.
1744 tcu::TestCaseGroup* createOpCopyMemoryGroup (tcu::TestContext& testCtx)
1746 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opcopymemory", "Test the OpCopyMemory instruction"));
1747 de::Random rnd (deStringHash(group->getName()));
1748 const int numElements = 100;
1750 // 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.
1751 ComputeShaderSpec spec1;
1752 vector<Vec4> inputFloats1 (numElements);
1753 vector<Vec4> outputFloats1 (numElements);
1755 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats1[0], numElements * 4);
1757 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
1758 floorAll(inputFloats1);
1760 for (size_t ndx = 0; ndx < numElements; ++ndx)
1761 outputFloats1[ndx] = inputFloats1[ndx] + Vec4(0.f, 0.5f, 1.5f, 2.5f);
1764 string(getComputeAsmShaderPreamble()) +
1766 "OpName %main \"main\"\n"
1767 "OpName %id \"gl_GlobalInvocationID\"\n"
1769 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1770 "OpDecorate %vec4arr ArrayStride 16\n"
1772 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
1774 "%vec4 = OpTypeVector %f32 4\n"
1775 "%vec4ptr_u = OpTypePointer Uniform %vec4\n"
1776 "%vec4ptr_f = OpTypePointer Function %vec4\n"
1777 "%vec4arr = OpTypeRuntimeArray %vec4\n"
1778 "%buf = OpTypeStruct %vec4arr\n"
1779 "%bufptr = OpTypePointer Uniform %buf\n"
1780 "%indata = OpVariable %bufptr Uniform\n"
1781 "%outdata = OpVariable %bufptr Uniform\n"
1783 "%id = OpVariable %uvec3ptr Input\n"
1784 "%zero = OpConstant %i32 0\n"
1785 "%c_f_0 = OpConstant %f32 0.\n"
1786 "%c_f_0_5 = OpConstant %f32 0.5\n"
1787 "%c_f_1_5 = OpConstant %f32 1.5\n"
1788 "%c_f_2_5 = OpConstant %f32 2.5\n"
1789 "%c_vec4 = OpConstantComposite %vec4 %c_f_0 %c_f_0_5 %c_f_1_5 %c_f_2_5\n"
1791 "%main = OpFunction %void None %voidf\n"
1792 "%label = OpLabel\n"
1793 "%v_vec4 = OpVariable %vec4ptr_f Function\n"
1794 "%idval = OpLoad %uvec3 %id\n"
1795 "%x = OpCompositeExtract %u32 %idval 0\n"
1796 "%inloc = OpAccessChain %vec4ptr_u %indata %zero %x\n"
1797 "%outloc = OpAccessChain %vec4ptr_u %outdata %zero %x\n"
1798 " OpCopyMemory %v_vec4 %inloc\n"
1799 "%v_vec4_val = OpLoad %vec4 %v_vec4\n"
1800 "%add = OpFAdd %vec4 %v_vec4_val %c_vec4\n"
1801 " OpStore %outloc %add\n"
1805 spec1.inputs.push_back(BufferSp(new Vec4Buffer(inputFloats1)));
1806 spec1.outputs.push_back(BufferSp(new Vec4Buffer(outputFloats1)));
1807 spec1.numWorkGroups = IVec3(numElements, 1, 1);
1809 group->addChild(new SpvAsmComputeShaderCase(testCtx, "vector", "OpCopyMemory elements of vector type", spec1));
1811 // The following case copies a float[100] variable from the input buffer to the output buffer.
1812 ComputeShaderSpec spec2;
1813 vector<float> inputFloats2 (numElements);
1814 vector<float> outputFloats2 (numElements);
1816 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats2[0], numElements);
1818 for (size_t ndx = 0; ndx < numElements; ++ndx)
1819 outputFloats2[ndx] = inputFloats2[ndx];
1822 string(getComputeAsmShaderPreamble()) +
1824 "OpName %main \"main\"\n"
1825 "OpName %id \"gl_GlobalInvocationID\"\n"
1827 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1828 "OpDecorate %f32arr100 ArrayStride 4\n"
1830 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
1832 "%hundred = OpConstant %u32 100\n"
1833 "%f32arr100 = OpTypeArray %f32 %hundred\n"
1834 "%f32arr100ptr_f = OpTypePointer Function %f32arr100\n"
1835 "%f32arr100ptr_u = OpTypePointer Uniform %f32arr100\n"
1836 "%buf = OpTypeStruct %f32arr100\n"
1837 "%bufptr = OpTypePointer Uniform %buf\n"
1838 "%indata = OpVariable %bufptr Uniform\n"
1839 "%outdata = OpVariable %bufptr Uniform\n"
1841 "%id = OpVariable %uvec3ptr Input\n"
1842 "%zero = OpConstant %i32 0\n"
1844 "%main = OpFunction %void None %voidf\n"
1845 "%label = OpLabel\n"
1846 "%var = OpVariable %f32arr100ptr_f Function\n"
1847 "%inarr = OpAccessChain %f32arr100ptr_u %indata %zero\n"
1848 "%outarr = OpAccessChain %f32arr100ptr_u %outdata %zero\n"
1849 " OpCopyMemory %var %inarr\n"
1850 " OpCopyMemory %outarr %var\n"
1854 spec2.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
1855 spec2.outputs.push_back(BufferSp(new Float32Buffer(outputFloats2)));
1856 spec2.numWorkGroups = IVec3(1, 1, 1);
1858 group->addChild(new SpvAsmComputeShaderCase(testCtx, "array", "OpCopyMemory elements of array type", spec2));
1860 // The following case copies a struct{vec4, vec4, vec4, vec4} variable from the input buffer to the output buffer.
1861 ComputeShaderSpec spec3;
1862 vector<float> inputFloats3 (16);
1863 vector<float> outputFloats3 (16);
1865 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats3[0], 16);
1867 for (size_t ndx = 0; ndx < 16; ++ndx)
1868 outputFloats3[ndx] = inputFloats3[ndx];
1871 string(getComputeAsmShaderPreamble()) +
1873 "OpName %main \"main\"\n"
1874 "OpName %id \"gl_GlobalInvocationID\"\n"
1876 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1877 "OpMemberDecorate %buf 0 Offset 0\n"
1878 "OpMemberDecorate %buf 1 Offset 16\n"
1879 "OpMemberDecorate %buf 2 Offset 32\n"
1880 "OpMemberDecorate %buf 3 Offset 48\n"
1882 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
1884 "%vec4 = OpTypeVector %f32 4\n"
1885 "%buf = OpTypeStruct %vec4 %vec4 %vec4 %vec4\n"
1886 "%bufptr = OpTypePointer Uniform %buf\n"
1887 "%indata = OpVariable %bufptr Uniform\n"
1888 "%outdata = OpVariable %bufptr Uniform\n"
1889 "%vec4stptr = OpTypePointer Function %buf\n"
1891 "%id = OpVariable %uvec3ptr Input\n"
1892 "%zero = OpConstant %i32 0\n"
1894 "%main = OpFunction %void None %voidf\n"
1895 "%label = OpLabel\n"
1896 "%var = OpVariable %vec4stptr Function\n"
1897 " OpCopyMemory %var %indata\n"
1898 " OpCopyMemory %outdata %var\n"
1902 spec3.inputs.push_back(BufferSp(new Float32Buffer(inputFloats3)));
1903 spec3.outputs.push_back(BufferSp(new Float32Buffer(outputFloats3)));
1904 spec3.numWorkGroups = IVec3(1, 1, 1);
1906 group->addChild(new SpvAsmComputeShaderCase(testCtx, "struct", "OpCopyMemory elements of struct type", spec3));
1908 // The following case negates multiple float variables from the input buffer and stores the results to the output buffer.
1909 ComputeShaderSpec spec4;
1910 vector<float> inputFloats4 (numElements);
1911 vector<float> outputFloats4 (numElements);
1913 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats4[0], numElements);
1915 for (size_t ndx = 0; ndx < numElements; ++ndx)
1916 outputFloats4[ndx] = -inputFloats4[ndx];
1919 string(getComputeAsmShaderPreamble()) +
1921 "OpName %main \"main\"\n"
1922 "OpName %id \"gl_GlobalInvocationID\"\n"
1924 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1926 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
1928 "%f32ptr_f = OpTypePointer Function %f32\n"
1929 "%id = OpVariable %uvec3ptr Input\n"
1930 "%zero = OpConstant %i32 0\n"
1932 "%main = OpFunction %void None %voidf\n"
1933 "%label = OpLabel\n"
1934 "%var = OpVariable %f32ptr_f Function\n"
1935 "%idval = OpLoad %uvec3 %id\n"
1936 "%x = OpCompositeExtract %u32 %idval 0\n"
1937 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
1938 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
1939 " OpCopyMemory %var %inloc\n"
1940 "%val = OpLoad %f32 %var\n"
1941 "%neg = OpFNegate %f32 %val\n"
1942 " OpStore %outloc %neg\n"
1946 spec4.inputs.push_back(BufferSp(new Float32Buffer(inputFloats4)));
1947 spec4.outputs.push_back(BufferSp(new Float32Buffer(outputFloats4)));
1948 spec4.numWorkGroups = IVec3(numElements, 1, 1);
1950 group->addChild(new SpvAsmComputeShaderCase(testCtx, "float", "OpCopyMemory elements of float type", spec4));
1952 return group.release();
1955 tcu::TestCaseGroup* createOpCopyObjectGroup (tcu::TestContext& testCtx)
1957 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opcopyobject", "Test the OpCopyObject instruction"));
1958 ComputeShaderSpec spec;
1959 de::Random rnd (deStringHash(group->getName()));
1960 const int numElements = 100;
1961 vector<float> inputFloats (numElements, 0);
1962 vector<float> outputFloats (numElements, 0);
1964 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats[0], numElements);
1966 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
1967 floorAll(inputFloats);
1969 for (size_t ndx = 0; ndx < numElements; ++ndx)
1970 outputFloats[ndx] = inputFloats[ndx] + 7.5f;
1973 string(getComputeAsmShaderPreamble()) +
1975 "OpName %main \"main\"\n"
1976 "OpName %id \"gl_GlobalInvocationID\"\n"
1978 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1980 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
1982 "%fmat = OpTypeMatrix %fvec3 3\n"
1983 "%three = OpConstant %u32 3\n"
1984 "%farr = OpTypeArray %f32 %three\n"
1985 "%fst = OpTypeStruct %f32 %f32\n"
1987 + string(getComputeAsmInputOutputBuffer()) +
1989 "%id = OpVariable %uvec3ptr Input\n"
1990 "%zero = OpConstant %i32 0\n"
1991 "%c_f = OpConstant %f32 1.5\n"
1992 "%c_fvec3 = OpConstantComposite %fvec3 %c_f %c_f %c_f\n"
1993 "%c_fmat = OpConstantComposite %fmat %c_fvec3 %c_fvec3 %c_fvec3\n"
1994 "%c_farr = OpConstantComposite %farr %c_f %c_f %c_f\n"
1995 "%c_fst = OpConstantComposite %fst %c_f %c_f\n"
1997 "%main = OpFunction %void None %voidf\n"
1998 "%label = OpLabel\n"
1999 "%c_f_copy = OpCopyObject %f32 %c_f\n"
2000 "%c_fvec3_copy = OpCopyObject %fvec3 %c_fvec3\n"
2001 "%c_fmat_copy = OpCopyObject %fmat %c_fmat\n"
2002 "%c_farr_copy = OpCopyObject %farr %c_farr\n"
2003 "%c_fst_copy = OpCopyObject %fst %c_fst\n"
2004 "%fvec3_elem = OpCompositeExtract %f32 %c_fvec3_copy 0\n"
2005 "%fmat_elem = OpCompositeExtract %f32 %c_fmat_copy 1 2\n"
2006 "%farr_elem = OpCompositeExtract %f32 %c_farr_copy 2\n"
2007 "%fst_elem = OpCompositeExtract %f32 %c_fst_copy 1\n"
2008 // Add up. 1.5 * 5 = 7.5.
2009 "%add1 = OpFAdd %f32 %c_f_copy %fvec3_elem\n"
2010 "%add2 = OpFAdd %f32 %add1 %fmat_elem\n"
2011 "%add3 = OpFAdd %f32 %add2 %farr_elem\n"
2012 "%add4 = OpFAdd %f32 %add3 %fst_elem\n"
2014 "%idval = OpLoad %uvec3 %id\n"
2015 "%x = OpCompositeExtract %u32 %idval 0\n"
2016 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
2017 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2018 "%inval = OpLoad %f32 %inloc\n"
2019 "%add = OpFAdd %f32 %add4 %inval\n"
2020 " OpStore %outloc %add\n"
2023 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
2024 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
2025 spec.numWorkGroups = IVec3(numElements, 1, 1);
2027 group->addChild(new SpvAsmComputeShaderCase(testCtx, "spotcheck", "OpCopyObject on different types", spec));
2029 return group.release();
2031 // Assembly code used for testing OpUnreachable is based on GLSL source code:
2035 // layout(std140, set = 0, binding = 0) readonly buffer Input {
2036 // float elements[];
2038 // layout(std140, set = 0, binding = 1) writeonly buffer Output {
2039 // float elements[];
2042 // void not_called_func() {
2043 // // place OpUnreachable here
2046 // uint modulo4(uint val) {
2047 // switch (val % uint(4)) {
2048 // case 0: return 3;
2049 // case 1: return 2;
2050 // case 2: return 1;
2051 // case 3: return 0;
2052 // default: return 100; // place OpUnreachable here
2058 // // place OpUnreachable here
2062 // uint x = gl_GlobalInvocationID.x;
2063 // if (const5() > modulo4(1000)) {
2064 // output_data.elements[x] = -input_data.elements[x];
2066 // // place OpUnreachable here
2067 // output_data.elements[x] = input_data.elements[x];
2071 tcu::TestCaseGroup* createOpUnreachableGroup (tcu::TestContext& testCtx)
2073 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opunreachable", "Test the OpUnreachable instruction"));
2074 ComputeShaderSpec spec;
2075 de::Random rnd (deStringHash(group->getName()));
2076 const int numElements = 100;
2077 vector<float> positiveFloats (numElements, 0);
2078 vector<float> negativeFloats (numElements, 0);
2080 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
2082 for (size_t ndx = 0; ndx < numElements; ++ndx)
2083 negativeFloats[ndx] = -positiveFloats[ndx];
2086 string(getComputeAsmShaderPreamble()) +
2088 "OpSource GLSL 430\n"
2089 "OpName %main \"main\"\n"
2090 "OpName %func_not_called_func \"not_called_func(\"\n"
2091 "OpName %func_modulo4 \"modulo4(u1;\"\n"
2092 "OpName %func_const5 \"const5(\"\n"
2093 "OpName %id \"gl_GlobalInvocationID\"\n"
2095 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2097 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
2099 "%u32ptr = OpTypePointer Function %u32\n"
2100 "%uintfuint = OpTypeFunction %u32 %u32ptr\n"
2101 "%unitf = OpTypeFunction %u32\n"
2103 "%id = OpVariable %uvec3ptr Input\n"
2104 "%zero = OpConstant %u32 0\n"
2105 "%one = OpConstant %u32 1\n"
2106 "%two = OpConstant %u32 2\n"
2107 "%three = OpConstant %u32 3\n"
2108 "%four = OpConstant %u32 4\n"
2109 "%five = OpConstant %u32 5\n"
2110 "%hundred = OpConstant %u32 100\n"
2111 "%thousand = OpConstant %u32 1000\n"
2113 + string(getComputeAsmInputOutputBuffer()) +
2116 "%main = OpFunction %void None %voidf\n"
2117 "%main_entry = OpLabel\n"
2118 "%v_thousand = OpVariable %u32ptr Function %thousand\n"
2119 "%idval = OpLoad %uvec3 %id\n"
2120 "%x = OpCompositeExtract %u32 %idval 0\n"
2121 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
2122 "%inval = OpLoad %f32 %inloc\n"
2123 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2124 "%ret_const5 = OpFunctionCall %u32 %func_const5\n"
2125 "%ret_modulo4 = OpFunctionCall %u32 %func_modulo4 %v_thousand\n"
2126 "%cmp_gt = OpUGreaterThan %bool %ret_const5 %ret_modulo4\n"
2127 " OpSelectionMerge %if_end None\n"
2128 " OpBranchConditional %cmp_gt %if_true %if_false\n"
2129 "%if_true = OpLabel\n"
2130 "%negate = OpFNegate %f32 %inval\n"
2131 " OpStore %outloc %negate\n"
2132 " OpBranch %if_end\n"
2133 "%if_false = OpLabel\n"
2134 " OpUnreachable\n" // Unreachable else branch for if statement
2135 "%if_end = OpLabel\n"
2139 // not_called_function()
2140 "%func_not_called_func = OpFunction %void None %voidf\n"
2141 "%not_called_func_entry = OpLabel\n"
2142 " OpUnreachable\n" // Unreachable entry block in not called static function
2146 "%func_modulo4 = OpFunction %u32 None %uintfuint\n"
2147 "%valptr = OpFunctionParameter %u32ptr\n"
2148 "%modulo4_entry = OpLabel\n"
2149 "%val = OpLoad %u32 %valptr\n"
2150 "%modulo = OpUMod %u32 %val %four\n"
2151 " OpSelectionMerge %switch_merge None\n"
2152 " OpSwitch %modulo %default 0 %case0 1 %case1 2 %case2 3 %case3\n"
2153 "%case0 = OpLabel\n"
2154 " OpReturnValue %three\n"
2155 "%case1 = OpLabel\n"
2156 " OpReturnValue %two\n"
2157 "%case2 = OpLabel\n"
2158 " OpReturnValue %one\n"
2159 "%case3 = OpLabel\n"
2160 " OpReturnValue %zero\n"
2161 "%default = OpLabel\n"
2162 " OpUnreachable\n" // Unreachable default case for switch statement
2163 "%switch_merge = OpLabel\n"
2164 " OpUnreachable\n" // Unreachable merge block for switch statement
2168 "%func_const5 = OpFunction %u32 None %unitf\n"
2169 "%const5_entry = OpLabel\n"
2170 " OpReturnValue %five\n"
2171 "%unreachable = OpLabel\n"
2172 " OpUnreachable\n" // Unreachable block in function
2174 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
2175 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
2176 spec.numWorkGroups = IVec3(numElements, 1, 1);
2178 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "OpUnreachable appearing at different places", spec));
2180 return group.release();
2183 // Assembly code used for testing decoration group is based on GLSL source code:
2187 // layout(std140, set = 0, binding = 0) readonly buffer Input0 {
2188 // float elements[];
2190 // layout(std140, set = 0, binding = 1) readonly buffer Input1 {
2191 // float elements[];
2193 // layout(std140, set = 0, binding = 2) readonly buffer Input2 {
2194 // float elements[];
2196 // layout(std140, set = 0, binding = 3) readonly buffer Input3 {
2197 // float elements[];
2199 // layout(std140, set = 0, binding = 4) readonly buffer Input4 {
2200 // float elements[];
2202 // layout(std140, set = 0, binding = 5) writeonly buffer Output {
2203 // float elements[];
2207 // uint x = gl_GlobalInvocationID.x;
2208 // output_data.elements[x] = input_data0.elements[x] + input_data1.elements[x] + input_data2.elements[x] + input_data3.elements[x] + input_data4.elements[x];
2210 tcu::TestCaseGroup* createDecorationGroupGroup (tcu::TestContext& testCtx)
2212 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "decoration_group", "Test the OpDecorationGroup & OpGroupDecorate instruction"));
2213 ComputeShaderSpec spec;
2214 de::Random rnd (deStringHash(group->getName()));
2215 const int numElements = 100;
2216 vector<float> inputFloats0 (numElements, 0);
2217 vector<float> inputFloats1 (numElements, 0);
2218 vector<float> inputFloats2 (numElements, 0);
2219 vector<float> inputFloats3 (numElements, 0);
2220 vector<float> inputFloats4 (numElements, 0);
2221 vector<float> outputFloats (numElements, 0);
2223 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats0[0], numElements);
2224 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats1[0], numElements);
2225 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats2[0], numElements);
2226 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats3[0], numElements);
2227 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats4[0], numElements);
2229 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
2230 floorAll(inputFloats0);
2231 floorAll(inputFloats1);
2232 floorAll(inputFloats2);
2233 floorAll(inputFloats3);
2234 floorAll(inputFloats4);
2236 for (size_t ndx = 0; ndx < numElements; ++ndx)
2237 outputFloats[ndx] = inputFloats0[ndx] + inputFloats1[ndx] + inputFloats2[ndx] + inputFloats3[ndx] + inputFloats4[ndx];
2240 string(getComputeAsmShaderPreamble()) +
2242 "OpSource GLSL 430\n"
2243 "OpName %main \"main\"\n"
2244 "OpName %id \"gl_GlobalInvocationID\"\n"
2246 // Not using group decoration on variable.
2247 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2248 // Not using group decoration on type.
2249 "OpDecorate %f32arr ArrayStride 4\n"
2251 "OpDecorate %groups BufferBlock\n"
2252 "OpDecorate %groupm Offset 0\n"
2253 "%groups = OpDecorationGroup\n"
2254 "%groupm = OpDecorationGroup\n"
2256 // Group decoration on multiple structs.
2257 "OpGroupDecorate %groups %outbuf %inbuf0 %inbuf1 %inbuf2 %inbuf3 %inbuf4\n"
2258 // Group decoration on multiple struct members.
2259 "OpGroupMemberDecorate %groupm %outbuf 0 %inbuf0 0 %inbuf1 0 %inbuf2 0 %inbuf3 0 %inbuf4 0\n"
2261 "OpDecorate %group1 DescriptorSet 0\n"
2262 "OpDecorate %group3 DescriptorSet 0\n"
2263 "OpDecorate %group3 NonWritable\n"
2264 "OpDecorate %group3 Restrict\n"
2265 "%group0 = OpDecorationGroup\n"
2266 "%group1 = OpDecorationGroup\n"
2267 "%group3 = OpDecorationGroup\n"
2269 // Applying the same decoration group multiple times.
2270 "OpGroupDecorate %group1 %outdata\n"
2271 "OpGroupDecorate %group1 %outdata\n"
2272 "OpGroupDecorate %group1 %outdata\n"
2273 "OpDecorate %outdata DescriptorSet 0\n"
2274 "OpDecorate %outdata Binding 5\n"
2275 // Applying decoration group containing nothing.
2276 "OpGroupDecorate %group0 %indata0\n"
2277 "OpDecorate %indata0 DescriptorSet 0\n"
2278 "OpDecorate %indata0 Binding 0\n"
2279 // Applying decoration group containing one decoration.
2280 "OpGroupDecorate %group1 %indata1\n"
2281 "OpDecorate %indata1 Binding 1\n"
2282 // Applying decoration group containing multiple decorations.
2283 "OpGroupDecorate %group3 %indata2 %indata3\n"
2284 "OpDecorate %indata2 Binding 2\n"
2285 "OpDecorate %indata3 Binding 3\n"
2286 // Applying multiple decoration groups (with overlapping).
2287 "OpGroupDecorate %group0 %indata4\n"
2288 "OpGroupDecorate %group1 %indata4\n"
2289 "OpGroupDecorate %group3 %indata4\n"
2290 "OpDecorate %indata4 Binding 4\n"
2292 + string(getComputeAsmCommonTypes()) +
2294 "%id = OpVariable %uvec3ptr Input\n"
2295 "%zero = OpConstant %i32 0\n"
2297 "%outbuf = OpTypeStruct %f32arr\n"
2298 "%outbufptr = OpTypePointer Uniform %outbuf\n"
2299 "%outdata = OpVariable %outbufptr Uniform\n"
2300 "%inbuf0 = OpTypeStruct %f32arr\n"
2301 "%inbuf0ptr = OpTypePointer Uniform %inbuf0\n"
2302 "%indata0 = OpVariable %inbuf0ptr Uniform\n"
2303 "%inbuf1 = OpTypeStruct %f32arr\n"
2304 "%inbuf1ptr = OpTypePointer Uniform %inbuf1\n"
2305 "%indata1 = OpVariable %inbuf1ptr Uniform\n"
2306 "%inbuf2 = OpTypeStruct %f32arr\n"
2307 "%inbuf2ptr = OpTypePointer Uniform %inbuf2\n"
2308 "%indata2 = OpVariable %inbuf2ptr Uniform\n"
2309 "%inbuf3 = OpTypeStruct %f32arr\n"
2310 "%inbuf3ptr = OpTypePointer Uniform %inbuf3\n"
2311 "%indata3 = OpVariable %inbuf3ptr Uniform\n"
2312 "%inbuf4 = OpTypeStruct %f32arr\n"
2313 "%inbufptr = OpTypePointer Uniform %inbuf4\n"
2314 "%indata4 = OpVariable %inbufptr Uniform\n"
2316 "%main = OpFunction %void None %voidf\n"
2317 "%label = OpLabel\n"
2318 "%idval = OpLoad %uvec3 %id\n"
2319 "%x = OpCompositeExtract %u32 %idval 0\n"
2320 "%inloc0 = OpAccessChain %f32ptr %indata0 %zero %x\n"
2321 "%inloc1 = OpAccessChain %f32ptr %indata1 %zero %x\n"
2322 "%inloc2 = OpAccessChain %f32ptr %indata2 %zero %x\n"
2323 "%inloc3 = OpAccessChain %f32ptr %indata3 %zero %x\n"
2324 "%inloc4 = OpAccessChain %f32ptr %indata4 %zero %x\n"
2325 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2326 "%inval0 = OpLoad %f32 %inloc0\n"
2327 "%inval1 = OpLoad %f32 %inloc1\n"
2328 "%inval2 = OpLoad %f32 %inloc2\n"
2329 "%inval3 = OpLoad %f32 %inloc3\n"
2330 "%inval4 = OpLoad %f32 %inloc4\n"
2331 "%add0 = OpFAdd %f32 %inval0 %inval1\n"
2332 "%add1 = OpFAdd %f32 %add0 %inval2\n"
2333 "%add2 = OpFAdd %f32 %add1 %inval3\n"
2334 "%add = OpFAdd %f32 %add2 %inval4\n"
2335 " OpStore %outloc %add\n"
2338 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats0)));
2339 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats1)));
2340 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
2341 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats3)));
2342 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats4)));
2343 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
2344 spec.numWorkGroups = IVec3(numElements, 1, 1);
2346 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "decoration group cases", spec));
2348 return group.release();
2351 struct SpecConstantTwoIntCase
2353 const char* caseName;
2354 const char* scDefinition0;
2355 const char* scDefinition1;
2356 const char* scResultType;
2357 const char* scOperation;
2358 deInt32 scActualValue0;
2359 deInt32 scActualValue1;
2360 const char* resultOperation;
2361 vector<deInt32> expectedOutput;
2363 SpecConstantTwoIntCase (const char* name,
2364 const char* definition0,
2365 const char* definition1,
2366 const char* resultType,
2367 const char* operation,
2370 const char* resultOp,
2371 const vector<deInt32>& output)
2373 , scDefinition0 (definition0)
2374 , scDefinition1 (definition1)
2375 , scResultType (resultType)
2376 , scOperation (operation)
2377 , scActualValue0 (value0)
2378 , scActualValue1 (value1)
2379 , resultOperation (resultOp)
2380 , expectedOutput (output) {}
2383 tcu::TestCaseGroup* createSpecConstantGroup (tcu::TestContext& testCtx)
2385 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opspecconstantop", "Test the OpSpecConstantOp instruction"));
2386 vector<SpecConstantTwoIntCase> cases;
2387 de::Random rnd (deStringHash(group->getName()));
2388 const int numElements = 100;
2389 vector<deInt32> inputInts (numElements, 0);
2390 vector<deInt32> outputInts1 (numElements, 0);
2391 vector<deInt32> outputInts2 (numElements, 0);
2392 vector<deInt32> outputInts3 (numElements, 0);
2393 vector<deInt32> outputInts4 (numElements, 0);
2394 const StringTemplate shaderTemplate (
2395 string(getComputeAsmShaderPreamble()) +
2397 "OpName %main \"main\"\n"
2398 "OpName %id \"gl_GlobalInvocationID\"\n"
2400 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2401 "OpDecorate %sc_0 SpecId 0\n"
2402 "OpDecorate %sc_1 SpecId 1\n"
2403 "OpDecorate %i32arr ArrayStride 4\n"
2405 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
2407 "%buf = OpTypeStruct %i32arr\n"
2408 "%bufptr = OpTypePointer Uniform %buf\n"
2409 "%indata = OpVariable %bufptr Uniform\n"
2410 "%outdata = OpVariable %bufptr Uniform\n"
2412 "%id = OpVariable %uvec3ptr Input\n"
2413 "%zero = OpConstant %i32 0\n"
2415 "%sc_0 = OpSpecConstant${SC_DEF0}\n"
2416 "%sc_1 = OpSpecConstant${SC_DEF1}\n"
2417 "%sc_final = OpSpecConstantOp ${SC_RESULT_TYPE} ${SC_OP}\n"
2419 "%main = OpFunction %void None %voidf\n"
2420 "%label = OpLabel\n"
2421 "%idval = OpLoad %uvec3 %id\n"
2422 "%x = OpCompositeExtract %u32 %idval 0\n"
2423 "%inloc = OpAccessChain %i32ptr %indata %zero %x\n"
2424 "%inval = OpLoad %i32 %inloc\n"
2425 "%final = ${GEN_RESULT}\n"
2426 "%outloc = OpAccessChain %i32ptr %outdata %zero %x\n"
2427 " OpStore %outloc %final\n"
2429 " OpFunctionEnd\n");
2431 fillRandomScalars(rnd, -65536, 65536, &inputInts[0], numElements);
2433 for (size_t ndx = 0; ndx < numElements; ++ndx)
2435 outputInts1[ndx] = inputInts[ndx] + 42;
2436 outputInts2[ndx] = inputInts[ndx];
2437 outputInts3[ndx] = inputInts[ndx] - 11200;
2438 outputInts4[ndx] = inputInts[ndx] + 1;
2441 const char addScToInput[] = "OpIAdd %i32 %inval %sc_final";
2442 const char selectTrueUsingSc[] = "OpSelect %i32 %sc_final %inval %zero";
2443 const char selectFalseUsingSc[] = "OpSelect %i32 %sc_final %zero %inval";
2445 cases.push_back(SpecConstantTwoIntCase("iadd", " %i32 0", " %i32 0", "%i32", "IAdd %sc_0 %sc_1", 62, -20, addScToInput, outputInts1));
2446 cases.push_back(SpecConstantTwoIntCase("isub", " %i32 0", " %i32 0", "%i32", "ISub %sc_0 %sc_1", 100, 58, addScToInput, outputInts1));
2447 cases.push_back(SpecConstantTwoIntCase("imul", " %i32 0", " %i32 0", "%i32", "IMul %sc_0 %sc_1", -2, -21, addScToInput, outputInts1));
2448 cases.push_back(SpecConstantTwoIntCase("sdiv", " %i32 0", " %i32 0", "%i32", "SDiv %sc_0 %sc_1", -126, -3, addScToInput, outputInts1));
2449 cases.push_back(SpecConstantTwoIntCase("udiv", " %i32 0", " %i32 0", "%i32", "UDiv %sc_0 %sc_1", 126, 3, addScToInput, outputInts1));
2450 cases.push_back(SpecConstantTwoIntCase("srem", " %i32 0", " %i32 0", "%i32", "SRem %sc_0 %sc_1", 7, 3, addScToInput, outputInts4));
2451 cases.push_back(SpecConstantTwoIntCase("smod", " %i32 0", " %i32 0", "%i32", "SMod %sc_0 %sc_1", 7, 3, addScToInput, outputInts4));
2452 cases.push_back(SpecConstantTwoIntCase("umod", " %i32 0", " %i32 0", "%i32", "UMod %sc_0 %sc_1", 342, 50, addScToInput, outputInts1));
2453 cases.push_back(SpecConstantTwoIntCase("bitwiseand", " %i32 0", " %i32 0", "%i32", "BitwiseAnd %sc_0 %sc_1", 42, 63, addScToInput, outputInts1));
2454 cases.push_back(SpecConstantTwoIntCase("bitwiseor", " %i32 0", " %i32 0", "%i32", "BitwiseOr %sc_0 %sc_1", 34, 8, addScToInput, outputInts1));
2455 cases.push_back(SpecConstantTwoIntCase("bitwisexor", " %i32 0", " %i32 0", "%i32", "BitwiseXor %sc_0 %sc_1", 18, 56, addScToInput, outputInts1));
2456 cases.push_back(SpecConstantTwoIntCase("shiftrightlogical", " %i32 0", " %i32 0", "%i32", "ShiftRightLogical %sc_0 %sc_1", 168, 2, addScToInput, outputInts1));
2457 cases.push_back(SpecConstantTwoIntCase("shiftrightarithmetic", " %i32 0", " %i32 0", "%i32", "ShiftRightArithmetic %sc_0 %sc_1", 168, 2, addScToInput, outputInts1));
2458 cases.push_back(SpecConstantTwoIntCase("shiftleftlogical", " %i32 0", " %i32 0", "%i32", "ShiftLeftLogical %sc_0 %sc_1", 21, 1, addScToInput, outputInts1));
2459 cases.push_back(SpecConstantTwoIntCase("slessthan", " %i32 0", " %i32 0", "%bool", "SLessThan %sc_0 %sc_1", -20, -10, selectTrueUsingSc, outputInts2));
2460 cases.push_back(SpecConstantTwoIntCase("ulessthan", " %i32 0", " %i32 0", "%bool", "ULessThan %sc_0 %sc_1", 10, 20, selectTrueUsingSc, outputInts2));
2461 cases.push_back(SpecConstantTwoIntCase("sgreaterthan", " %i32 0", " %i32 0", "%bool", "SGreaterThan %sc_0 %sc_1", -1000, 50, selectFalseUsingSc, outputInts2));
2462 cases.push_back(SpecConstantTwoIntCase("ugreaterthan", " %i32 0", " %i32 0", "%bool", "UGreaterThan %sc_0 %sc_1", 10, 5, selectTrueUsingSc, outputInts2));
2463 cases.push_back(SpecConstantTwoIntCase("slessthanequal", " %i32 0", " %i32 0", "%bool", "SLessThanEqual %sc_0 %sc_1", -10, -10, selectTrueUsingSc, outputInts2));
2464 cases.push_back(SpecConstantTwoIntCase("ulessthanequal", " %i32 0", " %i32 0", "%bool", "ULessThanEqual %sc_0 %sc_1", 50, 100, selectTrueUsingSc, outputInts2));
2465 cases.push_back(SpecConstantTwoIntCase("sgreaterthanequal", " %i32 0", " %i32 0", "%bool", "SGreaterThanEqual %sc_0 %sc_1", -1000, 50, selectFalseUsingSc, outputInts2));
2466 cases.push_back(SpecConstantTwoIntCase("ugreaterthanequal", " %i32 0", " %i32 0", "%bool", "UGreaterThanEqual %sc_0 %sc_1", 10, 10, selectTrueUsingSc, outputInts2));
2467 cases.push_back(SpecConstantTwoIntCase("iequal", " %i32 0", " %i32 0", "%bool", "IEqual %sc_0 %sc_1", 42, 24, selectFalseUsingSc, outputInts2));
2468 cases.push_back(SpecConstantTwoIntCase("logicaland", "True %bool", "True %bool", "%bool", "LogicalAnd %sc_0 %sc_1", 0, 1, selectFalseUsingSc, outputInts2));
2469 cases.push_back(SpecConstantTwoIntCase("logicalor", "False %bool", "False %bool", "%bool", "LogicalOr %sc_0 %sc_1", 1, 0, selectTrueUsingSc, outputInts2));
2470 cases.push_back(SpecConstantTwoIntCase("logicalequal", "True %bool", "True %bool", "%bool", "LogicalEqual %sc_0 %sc_1", 0, 1, selectFalseUsingSc, outputInts2));
2471 cases.push_back(SpecConstantTwoIntCase("logicalnotequal", "False %bool", "False %bool", "%bool", "LogicalNotEqual %sc_0 %sc_1", 1, 0, selectTrueUsingSc, outputInts2));
2472 cases.push_back(SpecConstantTwoIntCase("snegate", " %i32 0", " %i32 0", "%i32", "SNegate %sc_0", -42, 0, addScToInput, outputInts1));
2473 cases.push_back(SpecConstantTwoIntCase("not", " %i32 0", " %i32 0", "%i32", "Not %sc_0", -43, 0, addScToInput, outputInts1));
2474 cases.push_back(SpecConstantTwoIntCase("logicalnot", "False %bool", "False %bool", "%bool", "LogicalNot %sc_0", 1, 0, selectFalseUsingSc, outputInts2));
2475 cases.push_back(SpecConstantTwoIntCase("select", "False %bool", " %i32 0", "%i32", "Select %sc_0 %sc_1 %zero", 1, 42, addScToInput, outputInts1));
2476 // OpSConvert, OpFConvert: these two instructions involve ints/floats of different bitwidths.
2478 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
2480 map<string, string> specializations;
2481 ComputeShaderSpec spec;
2483 specializations["SC_DEF0"] = cases[caseNdx].scDefinition0;
2484 specializations["SC_DEF1"] = cases[caseNdx].scDefinition1;
2485 specializations["SC_RESULT_TYPE"] = cases[caseNdx].scResultType;
2486 specializations["SC_OP"] = cases[caseNdx].scOperation;
2487 specializations["GEN_RESULT"] = cases[caseNdx].resultOperation;
2489 spec.assembly = shaderTemplate.specialize(specializations);
2490 spec.inputs.push_back(BufferSp(new Int32Buffer(inputInts)));
2491 spec.outputs.push_back(BufferSp(new Int32Buffer(cases[caseNdx].expectedOutput)));
2492 spec.numWorkGroups = IVec3(numElements, 1, 1);
2493 spec.specConstants.push_back(cases[caseNdx].scActualValue0);
2494 spec.specConstants.push_back(cases[caseNdx].scActualValue1);
2496 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].caseName, cases[caseNdx].caseName, spec));
2499 ComputeShaderSpec spec;
2502 string(getComputeAsmShaderPreamble()) +
2504 "OpName %main \"main\"\n"
2505 "OpName %id \"gl_GlobalInvocationID\"\n"
2507 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2508 "OpDecorate %sc_0 SpecId 0\n"
2509 "OpDecorate %sc_1 SpecId 1\n"
2510 "OpDecorate %sc_2 SpecId 2\n"
2511 "OpDecorate %i32arr ArrayStride 4\n"
2513 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
2515 "%ivec3 = OpTypeVector %i32 3\n"
2516 "%buf = OpTypeStruct %i32arr\n"
2517 "%bufptr = OpTypePointer Uniform %buf\n"
2518 "%indata = OpVariable %bufptr Uniform\n"
2519 "%outdata = OpVariable %bufptr Uniform\n"
2521 "%id = OpVariable %uvec3ptr Input\n"
2522 "%zero = OpConstant %i32 0\n"
2523 "%ivec3_0 = OpConstantComposite %ivec3 %zero %zero %zero\n"
2524 "%vec3_undef = OpUndef %ivec3\n"
2526 "%sc_0 = OpSpecConstant %i32 0\n"
2527 "%sc_1 = OpSpecConstant %i32 0\n"
2528 "%sc_2 = OpSpecConstant %i32 0\n"
2529 "%sc_vec3_0 = OpSpecConstantOp %ivec3 CompositeInsert %sc_0 %ivec3_0 0\n" // (sc_0, 0, 0)
2530 "%sc_vec3_1 = OpSpecConstantOp %ivec3 CompositeInsert %sc_1 %ivec3_0 1\n" // (0, sc_1, 0)
2531 "%sc_vec3_2 = OpSpecConstantOp %ivec3 CompositeInsert %sc_2 %ivec3_0 2\n" // (0, 0, sc_2)
2532 "%sc_vec3_0_s = OpSpecConstantOp %ivec3 VectorShuffle %sc_vec3_0 %vec3_undef 0 0xFFFFFFFF 2\n" // (sc_0, ???, 0)
2533 "%sc_vec3_1_s = OpSpecConstantOp %ivec3 VectorShuffle %sc_vec3_1 %vec3_undef 0xFFFFFFFF 1 0\n" // (???, sc_1, 0)
2534 "%sc_vec3_2_s = OpSpecConstantOp %ivec3 VectorShuffle %vec3_undef %sc_vec3_2 5 0xFFFFFFFF 5\n" // (sc_2, ???, sc_2)
2535 "%sc_vec3_01 = OpSpecConstantOp %ivec3 VectorShuffle %sc_vec3_0_s %sc_vec3_1_s 1 0 4\n" // (0, sc_0, sc_1)
2536 "%sc_vec3_012 = OpSpecConstantOp %ivec3 VectorShuffle %sc_vec3_01 %sc_vec3_2_s 5 1 2\n" // (sc_2, sc_0, sc_1)
2537 "%sc_ext_0 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 0\n" // sc_2
2538 "%sc_ext_1 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 1\n" // sc_0
2539 "%sc_ext_2 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 2\n" // sc_1
2540 "%sc_sub = OpSpecConstantOp %i32 ISub %sc_ext_0 %sc_ext_1\n" // (sc_2 - sc_0)
2541 "%sc_final = OpSpecConstantOp %i32 IMul %sc_sub %sc_ext_2\n" // (sc_2 - sc_0) * sc_1
2543 "%main = OpFunction %void None %voidf\n"
2544 "%label = OpLabel\n"
2545 "%idval = OpLoad %uvec3 %id\n"
2546 "%x = OpCompositeExtract %u32 %idval 0\n"
2547 "%inloc = OpAccessChain %i32ptr %indata %zero %x\n"
2548 "%inval = OpLoad %i32 %inloc\n"
2549 "%final = OpIAdd %i32 %inval %sc_final\n"
2550 "%outloc = OpAccessChain %i32ptr %outdata %zero %x\n"
2551 " OpStore %outloc %final\n"
2554 spec.inputs.push_back(BufferSp(new Int32Buffer(inputInts)));
2555 spec.outputs.push_back(BufferSp(new Int32Buffer(outputInts3)));
2556 spec.numWorkGroups = IVec3(numElements, 1, 1);
2557 spec.specConstants.push_back(123);
2558 spec.specConstants.push_back(56);
2559 spec.specConstants.push_back(-77);
2561 group->addChild(new SpvAsmComputeShaderCase(testCtx, "vector_related", "VectorShuffle, CompositeExtract, & CompositeInsert", spec));
2563 return group.release();
2566 void createOpPhiVartypeTests (de::MovePtr<tcu::TestCaseGroup>& group, tcu::TestContext& testCtx)
2568 ComputeShaderSpec specInt;
2569 ComputeShaderSpec specFloat;
2570 ComputeShaderSpec specVec3;
2571 ComputeShaderSpec specMat4;
2572 ComputeShaderSpec specArray;
2573 ComputeShaderSpec specStruct;
2574 de::Random rnd (deStringHash(group->getName()));
2575 const int numElements = 100;
2576 vector<float> inputFloats (numElements, 0);
2577 vector<float> outputFloats (numElements, 0);
2579 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats[0], numElements);
2581 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
2582 floorAll(inputFloats);
2584 for (size_t ndx = 0; ndx < numElements; ++ndx)
2586 // Just check if the value is positive or not
2587 outputFloats[ndx] = (inputFloats[ndx] > 0) ? 1.0f : -1.0f;
2590 // All of the tests are of the form:
2594 // if (inputdata > 0)
2601 specFloat.assembly =
2602 string(getComputeAsmShaderPreamble()) +
2604 "OpSource GLSL 430\n"
2605 "OpName %main \"main\"\n"
2606 "OpName %id \"gl_GlobalInvocationID\"\n"
2608 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2610 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
2612 "%id = OpVariable %uvec3ptr Input\n"
2613 "%zero = OpConstant %i32 0\n"
2614 "%float_0 = OpConstant %f32 0.0\n"
2615 "%float_1 = OpConstant %f32 1.0\n"
2616 "%float_n1 = OpConstant %f32 -1.0\n"
2618 "%main = OpFunction %void None %voidf\n"
2619 "%entry = OpLabel\n"
2620 "%idval = OpLoad %uvec3 %id\n"
2621 "%x = OpCompositeExtract %u32 %idval 0\n"
2622 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
2623 "%inval = OpLoad %f32 %inloc\n"
2625 "%comp = OpFOrdGreaterThan %bool %inval %float_0\n"
2626 " OpSelectionMerge %cm None\n"
2627 " OpBranchConditional %comp %tb %fb\n"
2633 "%res = OpPhi %f32 %float_1 %tb %float_n1 %fb\n"
2635 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2636 " OpStore %outloc %res\n"
2640 specFloat.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
2641 specFloat.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
2642 specFloat.numWorkGroups = IVec3(numElements, 1, 1);
2645 string(getComputeAsmShaderPreamble()) +
2647 "OpSource GLSL 430\n"
2648 "OpName %main \"main\"\n"
2649 "OpName %id \"gl_GlobalInvocationID\"\n"
2651 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2653 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
2655 "%id = OpVariable %uvec3ptr Input\n"
2656 "%v4f32 = OpTypeVector %f32 4\n"
2657 "%mat4v4f32 = OpTypeMatrix %v4f32 4\n"
2658 "%zero = OpConstant %i32 0\n"
2659 "%float_0 = OpConstant %f32 0.0\n"
2660 "%float_1 = OpConstant %f32 1.0\n"
2661 "%float_n1 = OpConstant %f32 -1.0\n"
2662 "%m11 = OpConstantComposite %v4f32 %float_1 %float_0 %float_0 %float_0\n"
2663 "%m12 = OpConstantComposite %v4f32 %float_0 %float_1 %float_0 %float_0\n"
2664 "%m13 = OpConstantComposite %v4f32 %float_0 %float_0 %float_1 %float_0\n"
2665 "%m14 = OpConstantComposite %v4f32 %float_0 %float_0 %float_0 %float_1\n"
2666 "%m1 = OpConstantComposite %mat4v4f32 %m11 %m12 %m13 %m14\n"
2667 "%m21 = OpConstantComposite %v4f32 %float_n1 %float_0 %float_0 %float_0\n"
2668 "%m22 = OpConstantComposite %v4f32 %float_0 %float_n1 %float_0 %float_0\n"
2669 "%m23 = OpConstantComposite %v4f32 %float_0 %float_0 %float_n1 %float_0\n"
2670 "%m24 = OpConstantComposite %v4f32 %float_0 %float_0 %float_0 %float_n1\n"
2671 "%m2 = OpConstantComposite %mat4v4f32 %m21 %m22 %m23 %m24\n"
2673 "%main = OpFunction %void None %voidf\n"
2674 "%entry = OpLabel\n"
2675 "%idval = OpLoad %uvec3 %id\n"
2676 "%x = OpCompositeExtract %u32 %idval 0\n"
2677 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
2678 "%inval = OpLoad %f32 %inloc\n"
2680 "%comp = OpFOrdGreaterThan %bool %inval %float_0\n"
2681 " OpSelectionMerge %cm None\n"
2682 " OpBranchConditional %comp %tb %fb\n"
2688 "%mres = OpPhi %mat4v4f32 %m1 %tb %m2 %fb\n"
2689 "%res = OpCompositeExtract %f32 %mres 2 2\n"
2691 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2692 " OpStore %outloc %res\n"
2696 specMat4.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
2697 specMat4.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
2698 specMat4.numWorkGroups = IVec3(numElements, 1, 1);
2701 string(getComputeAsmShaderPreamble()) +
2703 "OpSource GLSL 430\n"
2704 "OpName %main \"main\"\n"
2705 "OpName %id \"gl_GlobalInvocationID\"\n"
2707 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2709 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
2711 "%id = OpVariable %uvec3ptr Input\n"
2712 "%v3f32 = OpTypeVector %f32 3\n"
2713 "%zero = OpConstant %i32 0\n"
2714 "%float_0 = OpConstant %f32 0.0\n"
2715 "%float_1 = OpConstant %f32 1.0\n"
2716 "%float_n1 = OpConstant %f32 -1.0\n"
2717 "%v1 = OpConstantComposite %v3f32 %float_1 %float_1 %float_1\n"
2718 "%v2 = OpConstantComposite %v3f32 %float_n1 %float_n1 %float_n1\n"
2720 "%main = OpFunction %void None %voidf\n"
2721 "%entry = OpLabel\n"
2722 "%idval = OpLoad %uvec3 %id\n"
2723 "%x = OpCompositeExtract %u32 %idval 0\n"
2724 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
2725 "%inval = OpLoad %f32 %inloc\n"
2727 "%comp = OpFOrdGreaterThan %bool %inval %float_0\n"
2728 " OpSelectionMerge %cm None\n"
2729 " OpBranchConditional %comp %tb %fb\n"
2735 "%vres = OpPhi %v3f32 %v1 %tb %v2 %fb\n"
2736 "%res = OpCompositeExtract %f32 %vres 2\n"
2738 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2739 " OpStore %outloc %res\n"
2743 specVec3.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
2744 specVec3.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
2745 specVec3.numWorkGroups = IVec3(numElements, 1, 1);
2748 string(getComputeAsmShaderPreamble()) +
2750 "OpSource GLSL 430\n"
2751 "OpName %main \"main\"\n"
2752 "OpName %id \"gl_GlobalInvocationID\"\n"
2754 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2756 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
2758 "%id = OpVariable %uvec3ptr Input\n"
2759 "%zero = OpConstant %i32 0\n"
2760 "%float_0 = OpConstant %f32 0.0\n"
2761 "%i1 = OpConstant %i32 1\n"
2762 "%i2 = OpConstant %i32 -1\n"
2764 "%main = OpFunction %void None %voidf\n"
2765 "%entry = OpLabel\n"
2766 "%idval = OpLoad %uvec3 %id\n"
2767 "%x = OpCompositeExtract %u32 %idval 0\n"
2768 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
2769 "%inval = OpLoad %f32 %inloc\n"
2771 "%comp = OpFOrdGreaterThan %bool %inval %float_0\n"
2772 " OpSelectionMerge %cm None\n"
2773 " OpBranchConditional %comp %tb %fb\n"
2779 "%ires = OpPhi %i32 %i1 %tb %i2 %fb\n"
2780 "%res = OpConvertSToF %f32 %ires\n"
2782 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2783 " OpStore %outloc %res\n"
2787 specInt.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
2788 specInt.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
2789 specInt.numWorkGroups = IVec3(numElements, 1, 1);
2791 specArray.assembly =
2792 string(getComputeAsmShaderPreamble()) +
2794 "OpSource GLSL 430\n"
2795 "OpName %main \"main\"\n"
2796 "OpName %id \"gl_GlobalInvocationID\"\n"
2798 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2800 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
2802 "%id = OpVariable %uvec3ptr Input\n"
2803 "%zero = OpConstant %i32 0\n"
2804 "%u7 = OpConstant %u32 7\n"
2805 "%float_0 = OpConstant %f32 0.0\n"
2806 "%float_1 = OpConstant %f32 1.0\n"
2807 "%float_n1 = OpConstant %f32 -1.0\n"
2808 "%f32a7 = OpTypeArray %f32 %u7\n"
2809 "%a1 = OpConstantComposite %f32a7 %float_1 %float_1 %float_1 %float_1 %float_1 %float_1 %float_1\n"
2810 "%a2 = OpConstantComposite %f32a7 %float_n1 %float_n1 %float_n1 %float_n1 %float_n1 %float_n1 %float_n1\n"
2811 "%main = OpFunction %void None %voidf\n"
2812 "%entry = OpLabel\n"
2813 "%idval = OpLoad %uvec3 %id\n"
2814 "%x = OpCompositeExtract %u32 %idval 0\n"
2815 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
2816 "%inval = OpLoad %f32 %inloc\n"
2818 "%comp = OpFOrdGreaterThan %bool %inval %float_0\n"
2819 " OpSelectionMerge %cm None\n"
2820 " OpBranchConditional %comp %tb %fb\n"
2826 "%ares = OpPhi %f32a7 %a1 %tb %a2 %fb\n"
2827 "%res = OpCompositeExtract %f32 %ares 5\n"
2829 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2830 " OpStore %outloc %res\n"
2834 specArray.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
2835 specArray.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
2836 specArray.numWorkGroups = IVec3(numElements, 1, 1);
2838 specStruct.assembly =
2839 string(getComputeAsmShaderPreamble()) +
2841 "OpSource GLSL 430\n"
2842 "OpName %main \"main\"\n"
2843 "OpName %id \"gl_GlobalInvocationID\"\n"
2845 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2847 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
2849 "%id = OpVariable %uvec3ptr Input\n"
2850 "%v3f32 = OpTypeVector %f32 3\n"
2851 "%zero = OpConstant %i32 0\n"
2852 "%float_0 = OpConstant %f32 0.0\n"
2853 "%float_1 = OpConstant %f32 1.0\n"
2854 "%float_n1 = OpConstant %f32 -1.0\n"
2856 "%v2f32 = OpTypeVector %f32 2\n"
2857 "%Data2 = OpTypeStruct %f32 %v2f32\n"
2858 "%Data = OpTypeStruct %Data2 %f32\n"
2860 "%in1a = OpConstantComposite %v2f32 %float_1 %float_1\n"
2861 "%in1b = OpConstantComposite %Data2 %float_1 %in1a\n"
2862 "%s1 = OpConstantComposite %Data %in1b %float_1\n"
2863 "%in2a = OpConstantComposite %v2f32 %float_n1 %float_n1\n"
2864 "%in2b = OpConstantComposite %Data2 %float_n1 %in2a\n"
2865 "%s2 = OpConstantComposite %Data %in2b %float_n1\n"
2867 "%main = OpFunction %void None %voidf\n"
2868 "%entry = OpLabel\n"
2869 "%idval = OpLoad %uvec3 %id\n"
2870 "%x = OpCompositeExtract %u32 %idval 0\n"
2871 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
2872 "%inval = OpLoad %f32 %inloc\n"
2874 "%comp = OpFOrdGreaterThan %bool %inval %float_0\n"
2875 " OpSelectionMerge %cm None\n"
2876 " OpBranchConditional %comp %tb %fb\n"
2882 "%sres = OpPhi %Data %s1 %tb %s2 %fb\n"
2883 "%res = OpCompositeExtract %f32 %sres 0 0\n"
2885 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2886 " OpStore %outloc %res\n"
2890 specStruct.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
2891 specStruct.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
2892 specStruct.numWorkGroups = IVec3(numElements, 1, 1);
2894 group->addChild(new SpvAsmComputeShaderCase(testCtx, "vartype_int", "OpPhi with int variables", specInt));
2895 group->addChild(new SpvAsmComputeShaderCase(testCtx, "vartype_float", "OpPhi with float variables", specFloat));
2896 group->addChild(new SpvAsmComputeShaderCase(testCtx, "vartype_vec3", "OpPhi with vec3 variables", specVec3));
2897 group->addChild(new SpvAsmComputeShaderCase(testCtx, "vartype_mat4", "OpPhi with mat4 variables", specMat4));
2898 group->addChild(new SpvAsmComputeShaderCase(testCtx, "vartype_array", "OpPhi with array variables", specArray));
2899 group->addChild(new SpvAsmComputeShaderCase(testCtx, "vartype_struct", "OpPhi with struct variables", specStruct));
2902 string generateConstantDefinitions (int count)
2904 std::ostringstream r;
2905 for (int i = 0; i < count; i++)
2906 r << "%cf" << (i * 10 + 5) << " = OpConstant %f32 " <<(i * 10 + 5) << ".0\n";
2911 string generateSwitchCases (int count)
2913 std::ostringstream r;
2914 for (int i = 0; i < count; i++)
2915 r << " " << i << " %case" << i;
2920 string generateSwitchTargets (int count)
2922 std::ostringstream r;
2923 for (int i = 0; i < count; i++)
2924 r << "%case" << i << " = OpLabel\n OpBranch %phi\n";
2929 string generateOpPhiParams (int count)
2931 std::ostringstream r;
2932 for (int i = 0; i < count; i++)
2933 r << " %cf" << (i * 10 + 5) << " %case" << i;
2938 string generateIntWidth (int value)
2940 std::ostringstream r;
2945 // Expand input string by injecting "ABC" between the input
2946 // string characters. The acc/add/treshold parameters are used
2947 // to skip some of the injections to make the result less
2948 // uniform (and a lot shorter).
2949 string expandOpPhiCase5 (const string& s, int &acc, int add, int treshold)
2951 std::ostringstream res;
2952 const char* p = s.c_str();
2968 // Calculate expected result based on the code string
2969 float calcOpPhiCase5 (float val, const string& s)
2971 const char* p = s.c_str();
2974 const float tv[8] = { 0.5f, 1.5f, 3.5f, 7.5f, 15.5f, 31.5f, 63.5f, 127.5f };
2975 const float v = deFloatAbs(val);
2980 for (int i = 7; i >= 0; --i)
2981 x[i] = std::fmod((float)v, (float)(2 << i));
2982 for (int i = 7; i >= 0; --i)
2983 b[i] = x[i] > tv[i];
2990 if (skip == 0 && b[depth])
3001 if (b[depth] || skip)
3015 // In the code string, the letters represent the following:
3018 // if (certain bit is set)
3029 // AABCBC leads to if(){r++;if(){r++;}else{}}else{}
3030 // ABABCC leads to if(){r++;}else{if(){r++;}else{}}
3031 // ABCABC leads to if(){r++;}else{}if(){r++;}else{}
3033 // Code generation gets a bit complicated due to the else-branches,
3034 // which do not generate new values. Thus, the generator needs to
3035 // keep track of the previous variable change seen by the else
3037 string generateOpPhiCase5 (const string& s)
3039 std::stack<int> idStack;
3040 std::stack<std::string> value;
3041 std::stack<std::string> valueLabel;
3042 std::stack<std::string> mergeLeft;
3043 std::stack<std::string> mergeRight;
3044 std::ostringstream res;
3045 const char* p = s.c_str();
3051 value.push("%f32_0");
3052 valueLabel.push("%f32_0 %entry");
3060 idStack.push(currId);
3061 res << "\tOpSelectionMerge %m" << currId << " None\n";
3062 res << "\tOpBranchConditional %b" << depth << " %t" << currId << " %f" << currId << "\n";
3063 res << "%t" << currId << " = OpLabel\n";
3064 res << "%rt" << currId << " = OpFAdd %f32 " << value.top() << " %f32_1\n";
3065 std::ostringstream tag;
3066 tag << "%rt" << currId;
3067 value.push(tag.str());
3068 tag << " %t" << currId;
3069 valueLabel.push(tag.str());
3074 mergeLeft.push(valueLabel.top());
3077 res << "\tOpBranch %m" << currId << "\n";
3078 res << "%f" << currId << " = OpLabel\n";
3079 std::ostringstream tag;
3080 tag << value.top() << " %f" << currId;
3082 valueLabel.push(tag.str());
3087 mergeRight.push(valueLabel.top());
3088 res << "\tOpBranch %m" << currId << "\n";
3089 res << "%m" << currId << " = OpLabel\n";
3091 res << "%res"; // last result goes to %res
3093 res << "%rm" << currId;
3094 res << " = OpPhi %f32 " << mergeLeft.top() << " " << mergeRight.top() << "\n";
3095 std::ostringstream tag;
3096 tag << "%rm" << currId;
3098 value.push(tag.str());
3099 tag << " %m" << currId;
3101 valueLabel.push(tag.str());
3106 currId = idStack.top();
3114 tcu::TestCaseGroup* createOpPhiGroup (tcu::TestContext& testCtx)
3116 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opphi", "Test the OpPhi instruction"));
3117 ComputeShaderSpec spec1;
3118 ComputeShaderSpec spec2;
3119 ComputeShaderSpec spec3;
3120 ComputeShaderSpec spec4;
3121 ComputeShaderSpec spec5;
3122 de::Random rnd (deStringHash(group->getName()));
3123 const int numElements = 100;
3124 vector<float> inputFloats (numElements, 0);
3125 vector<float> outputFloats1 (numElements, 0);
3126 vector<float> outputFloats2 (numElements, 0);
3127 vector<float> outputFloats3 (numElements, 0);
3128 vector<float> outputFloats4 (numElements, 0);
3129 vector<float> outputFloats5 (numElements, 0);
3130 std::string codestring = "ABC";
3131 const int test4Width = 1024;
3133 // Build case 5 code string. Each iteration makes the hierarchy more complicated.
3134 // 9 iterations with (7, 24) parameters makes the hierarchy 8 deep with about 1500 lines of
3136 for (int i = 0, acc = 0; i < 9; i++)
3137 codestring = expandOpPhiCase5(codestring, acc, 7, 24);
3139 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats[0], numElements);
3141 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
3142 floorAll(inputFloats);
3144 for (size_t ndx = 0; ndx < numElements; ++ndx)
3148 case 0: outputFloats1[ndx] = inputFloats[ndx] + 5.5f; break;
3149 case 1: outputFloats1[ndx] = inputFloats[ndx] + 20.5f; break;
3150 case 2: outputFloats1[ndx] = inputFloats[ndx] + 1.75f; break;
3153 outputFloats2[ndx] = inputFloats[ndx] + 6.5f * 3;
3154 outputFloats3[ndx] = 8.5f - inputFloats[ndx];
3156 int index4 = (int)deFloor(deAbs((float)ndx * inputFloats[ndx]));
3157 outputFloats4[ndx] = (float)(index4 % test4Width) * 10.0f + 5.0f;
3159 outputFloats5[ndx] = calcOpPhiCase5(inputFloats[ndx], codestring);
3163 string(getComputeAsmShaderPreamble()) +
3165 "OpSource GLSL 430\n"
3166 "OpName %main \"main\"\n"
3167 "OpName %id \"gl_GlobalInvocationID\"\n"
3169 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3171 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
3173 "%id = OpVariable %uvec3ptr Input\n"
3174 "%zero = OpConstant %i32 0\n"
3175 "%three = OpConstant %u32 3\n"
3176 "%constf5p5 = OpConstant %f32 5.5\n"
3177 "%constf20p5 = OpConstant %f32 20.5\n"
3178 "%constf1p75 = OpConstant %f32 1.75\n"
3179 "%constf8p5 = OpConstant %f32 8.5\n"
3180 "%constf6p5 = OpConstant %f32 6.5\n"
3182 "%main = OpFunction %void None %voidf\n"
3183 "%entry = OpLabel\n"
3184 "%idval = OpLoad %uvec3 %id\n"
3185 "%x = OpCompositeExtract %u32 %idval 0\n"
3186 "%selector = OpUMod %u32 %x %three\n"
3187 " OpSelectionMerge %phi None\n"
3188 " OpSwitch %selector %default 0 %case0 1 %case1 2 %case2\n"
3190 // Case 1 before OpPhi.
3191 "%case1 = OpLabel\n"
3194 "%default = OpLabel\n"
3198 "%operand = OpPhi %f32 %constf1p75 %case2 %constf20p5 %case1 %constf5p5 %case0\n" // not in the order of blocks
3199 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3200 "%inval = OpLoad %f32 %inloc\n"
3201 "%add = OpFAdd %f32 %inval %operand\n"
3202 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3203 " OpStore %outloc %add\n"
3206 // Case 0 after OpPhi.
3207 "%case0 = OpLabel\n"
3211 // Case 2 after OpPhi.
3212 "%case2 = OpLabel\n"
3216 spec1.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
3217 spec1.outputs.push_back(BufferSp(new Float32Buffer(outputFloats1)));
3218 spec1.numWorkGroups = IVec3(numElements, 1, 1);
3220 group->addChild(new SpvAsmComputeShaderCase(testCtx, "block", "out-of-order and unreachable blocks for OpPhi", spec1));
3223 string(getComputeAsmShaderPreamble()) +
3225 "OpName %main \"main\"\n"
3226 "OpName %id \"gl_GlobalInvocationID\"\n"
3228 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3230 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
3232 "%id = OpVariable %uvec3ptr Input\n"
3233 "%zero = OpConstant %i32 0\n"
3234 "%one = OpConstant %i32 1\n"
3235 "%three = OpConstant %i32 3\n"
3236 "%constf6p5 = OpConstant %f32 6.5\n"
3238 "%main = OpFunction %void None %voidf\n"
3239 "%entry = OpLabel\n"
3240 "%idval = OpLoad %uvec3 %id\n"
3241 "%x = OpCompositeExtract %u32 %idval 0\n"
3242 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3243 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3244 "%inval = OpLoad %f32 %inloc\n"
3248 "%step = OpPhi %i32 %zero %entry %step_next %phi\n"
3249 "%accum = OpPhi %f32 %inval %entry %accum_next %phi\n"
3250 "%step_next = OpIAdd %i32 %step %one\n"
3251 "%accum_next = OpFAdd %f32 %accum %constf6p5\n"
3252 "%still_loop = OpSLessThan %bool %step %three\n"
3253 " OpLoopMerge %exit %phi None\n"
3254 " OpBranchConditional %still_loop %phi %exit\n"
3257 " OpStore %outloc %accum\n"
3260 spec2.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
3261 spec2.outputs.push_back(BufferSp(new Float32Buffer(outputFloats2)));
3262 spec2.numWorkGroups = IVec3(numElements, 1, 1);
3264 group->addChild(new SpvAsmComputeShaderCase(testCtx, "induction", "The usual way induction variables are handled in LLVM IR", spec2));
3267 string(getComputeAsmShaderPreamble()) +
3269 "OpName %main \"main\"\n"
3270 "OpName %id \"gl_GlobalInvocationID\"\n"
3272 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3274 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
3276 "%f32ptr_f = OpTypePointer Function %f32\n"
3277 "%id = OpVariable %uvec3ptr Input\n"
3278 "%true = OpConstantTrue %bool\n"
3279 "%false = OpConstantFalse %bool\n"
3280 "%zero = OpConstant %i32 0\n"
3281 "%constf8p5 = OpConstant %f32 8.5\n"
3283 "%main = OpFunction %void None %voidf\n"
3284 "%entry = OpLabel\n"
3285 "%b = OpVariable %f32ptr_f Function %constf8p5\n"
3286 "%idval = OpLoad %uvec3 %id\n"
3287 "%x = OpCompositeExtract %u32 %idval 0\n"
3288 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3289 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3290 "%a_init = OpLoad %f32 %inloc\n"
3291 "%b_init = OpLoad %f32 %b\n"
3295 "%still_loop = OpPhi %bool %true %entry %false %phi\n"
3296 "%a_next = OpPhi %f32 %a_init %entry %b_next %phi\n"
3297 "%b_next = OpPhi %f32 %b_init %entry %a_next %phi\n"
3298 " OpLoopMerge %exit %phi None\n"
3299 " OpBranchConditional %still_loop %phi %exit\n"
3302 "%sub = OpFSub %f32 %a_next %b_next\n"
3303 " OpStore %outloc %sub\n"
3306 spec3.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
3307 spec3.outputs.push_back(BufferSp(new Float32Buffer(outputFloats3)));
3308 spec3.numWorkGroups = IVec3(numElements, 1, 1);
3310 group->addChild(new SpvAsmComputeShaderCase(testCtx, "swap", "Swap the values of two variables using OpPhi", spec3));
3313 "OpCapability Shader\n"
3314 "%ext = OpExtInstImport \"GLSL.std.450\"\n"
3315 "OpMemoryModel Logical GLSL450\n"
3316 "OpEntryPoint GLCompute %main \"main\" %id\n"
3317 "OpExecutionMode %main LocalSize 1 1 1\n"
3319 "OpSource GLSL 430\n"
3320 "OpName %main \"main\"\n"
3321 "OpName %id \"gl_GlobalInvocationID\"\n"
3323 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3325 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
3327 "%id = OpVariable %uvec3ptr Input\n"
3328 "%zero = OpConstant %i32 0\n"
3329 "%cimod = OpConstant %u32 " + generateIntWidth(test4Width) + "\n"
3331 + generateConstantDefinitions(test4Width) +
3333 "%main = OpFunction %void None %voidf\n"
3334 "%entry = OpLabel\n"
3335 "%idval = OpLoad %uvec3 %id\n"
3336 "%x = OpCompositeExtract %u32 %idval 0\n"
3337 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3338 "%inval = OpLoad %f32 %inloc\n"
3339 "%xf = OpConvertUToF %f32 %x\n"
3340 "%xm = OpFMul %f32 %xf %inval\n"
3341 "%xa = OpExtInst %f32 %ext FAbs %xm\n"
3342 "%xi = OpConvertFToU %u32 %xa\n"
3343 "%selector = OpUMod %u32 %xi %cimod\n"
3344 " OpSelectionMerge %phi None\n"
3345 " OpSwitch %selector %default "
3347 + generateSwitchCases(test4Width) +
3349 "%default = OpLabel\n"
3352 + generateSwitchTargets(test4Width) +
3355 "%result = OpPhi %f32"
3357 + generateOpPhiParams(test4Width) +
3359 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3360 " OpStore %outloc %result\n"
3364 spec4.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
3365 spec4.outputs.push_back(BufferSp(new Float32Buffer(outputFloats4)));
3366 spec4.numWorkGroups = IVec3(numElements, 1, 1);
3368 group->addChild(new SpvAsmComputeShaderCase(testCtx, "wide", "OpPhi with a lot of parameters", spec4));
3371 "OpCapability Shader\n"
3372 "%ext = OpExtInstImport \"GLSL.std.450\"\n"
3373 "OpMemoryModel Logical GLSL450\n"
3374 "OpEntryPoint GLCompute %main \"main\" %id\n"
3375 "OpExecutionMode %main LocalSize 1 1 1\n"
3376 "%code = OpString \"" + codestring + "\"\n"
3378 "OpSource GLSL 430\n"
3379 "OpName %main \"main\"\n"
3380 "OpName %id \"gl_GlobalInvocationID\"\n"
3382 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3384 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
3386 "%id = OpVariable %uvec3ptr Input\n"
3387 "%zero = OpConstant %i32 0\n"
3388 "%f32_0 = OpConstant %f32 0.0\n"
3389 "%f32_0_5 = OpConstant %f32 0.5\n"
3390 "%f32_1 = OpConstant %f32 1.0\n"
3391 "%f32_1_5 = OpConstant %f32 1.5\n"
3392 "%f32_2 = OpConstant %f32 2.0\n"
3393 "%f32_3_5 = OpConstant %f32 3.5\n"
3394 "%f32_4 = OpConstant %f32 4.0\n"
3395 "%f32_7_5 = OpConstant %f32 7.5\n"
3396 "%f32_8 = OpConstant %f32 8.0\n"
3397 "%f32_15_5 = OpConstant %f32 15.5\n"
3398 "%f32_16 = OpConstant %f32 16.0\n"
3399 "%f32_31_5 = OpConstant %f32 31.5\n"
3400 "%f32_32 = OpConstant %f32 32.0\n"
3401 "%f32_63_5 = OpConstant %f32 63.5\n"
3402 "%f32_64 = OpConstant %f32 64.0\n"
3403 "%f32_127_5 = OpConstant %f32 127.5\n"
3404 "%f32_128 = OpConstant %f32 128.0\n"
3405 "%f32_256 = OpConstant %f32 256.0\n"
3407 "%main = OpFunction %void None %voidf\n"
3408 "%entry = OpLabel\n"
3409 "%idval = OpLoad %uvec3 %id\n"
3410 "%x = OpCompositeExtract %u32 %idval 0\n"
3411 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3412 "%inval = OpLoad %f32 %inloc\n"
3414 "%xabs = OpExtInst %f32 %ext FAbs %inval\n"
3415 "%x8 = OpFMod %f32 %xabs %f32_256\n"
3416 "%x7 = OpFMod %f32 %xabs %f32_128\n"
3417 "%x6 = OpFMod %f32 %xabs %f32_64\n"
3418 "%x5 = OpFMod %f32 %xabs %f32_32\n"
3419 "%x4 = OpFMod %f32 %xabs %f32_16\n"
3420 "%x3 = OpFMod %f32 %xabs %f32_8\n"
3421 "%x2 = OpFMod %f32 %xabs %f32_4\n"
3422 "%x1 = OpFMod %f32 %xabs %f32_2\n"
3424 "%b7 = OpFOrdGreaterThanEqual %bool %x8 %f32_127_5\n"
3425 "%b6 = OpFOrdGreaterThanEqual %bool %x7 %f32_63_5\n"
3426 "%b5 = OpFOrdGreaterThanEqual %bool %x6 %f32_31_5\n"
3427 "%b4 = OpFOrdGreaterThanEqual %bool %x5 %f32_15_5\n"
3428 "%b3 = OpFOrdGreaterThanEqual %bool %x4 %f32_7_5\n"
3429 "%b2 = OpFOrdGreaterThanEqual %bool %x3 %f32_3_5\n"
3430 "%b1 = OpFOrdGreaterThanEqual %bool %x2 %f32_1_5\n"
3431 "%b0 = OpFOrdGreaterThanEqual %bool %x1 %f32_0_5\n"
3433 + generateOpPhiCase5(codestring) +
3435 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3436 " OpStore %outloc %res\n"
3440 spec5.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
3441 spec5.outputs.push_back(BufferSp(new Float32Buffer(outputFloats5)));
3442 spec5.numWorkGroups = IVec3(numElements, 1, 1);
3444 group->addChild(new SpvAsmComputeShaderCase(testCtx, "nested", "Stress OpPhi with a lot of nesting", spec5));
3446 createOpPhiVartypeTests(group, testCtx);
3448 return group.release();
3451 // Assembly code used for testing block order is based on GLSL source code:
3455 // layout(std140, set = 0, binding = 0) readonly buffer Input {
3456 // float elements[];
3458 // layout(std140, set = 0, binding = 1) writeonly buffer Output {
3459 // float elements[];
3463 // uint x = gl_GlobalInvocationID.x;
3464 // output_data.elements[x] = input_data.elements[x];
3465 // if (x > uint(50)) {
3466 // switch (x % uint(3)) {
3467 // case 0: output_data.elements[x] += 1.5f; break;
3468 // case 1: output_data.elements[x] += 42.f; break;
3469 // case 2: output_data.elements[x] -= 27.f; break;
3473 // output_data.elements[x] = -input_data.elements[x];
3476 tcu::TestCaseGroup* createBlockOrderGroup (tcu::TestContext& testCtx)
3478 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "block_order", "Test block orders"));
3479 ComputeShaderSpec spec;
3480 de::Random rnd (deStringHash(group->getName()));
3481 const int numElements = 100;
3482 vector<float> inputFloats (numElements, 0);
3483 vector<float> outputFloats (numElements, 0);
3485 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats[0], numElements);
3487 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
3488 floorAll(inputFloats);
3490 for (size_t ndx = 0; ndx <= 50; ++ndx)
3491 outputFloats[ndx] = -inputFloats[ndx];
3493 for (size_t ndx = 51; ndx < numElements; ++ndx)
3497 case 0: outputFloats[ndx] = inputFloats[ndx] + 1.5f; break;
3498 case 1: outputFloats[ndx] = inputFloats[ndx] + 42.f; break;
3499 case 2: outputFloats[ndx] = inputFloats[ndx] - 27.f; break;
3505 string(getComputeAsmShaderPreamble()) +
3507 "OpSource GLSL 430\n"
3508 "OpName %main \"main\"\n"
3509 "OpName %id \"gl_GlobalInvocationID\"\n"
3511 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3513 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
3515 "%u32ptr = OpTypePointer Function %u32\n"
3516 "%u32ptr_input = OpTypePointer Input %u32\n"
3518 + string(getComputeAsmInputOutputBuffer()) +
3520 "%id = OpVariable %uvec3ptr Input\n"
3521 "%zero = OpConstant %i32 0\n"
3522 "%const3 = OpConstant %u32 3\n"
3523 "%const50 = OpConstant %u32 50\n"
3524 "%constf1p5 = OpConstant %f32 1.5\n"
3525 "%constf27 = OpConstant %f32 27.0\n"
3526 "%constf42 = OpConstant %f32 42.0\n"
3528 "%main = OpFunction %void None %voidf\n"
3531 "%entry = OpLabel\n"
3533 // Create a temporary variable to hold the value of gl_GlobalInvocationID.x.
3534 "%xvar = OpVariable %u32ptr Function\n"
3535 "%xptr = OpAccessChain %u32ptr_input %id %zero\n"
3536 "%x = OpLoad %u32 %xptr\n"
3537 " OpStore %xvar %x\n"
3539 "%cmp = OpUGreaterThan %bool %x %const50\n"
3540 " OpSelectionMerge %if_merge None\n"
3541 " OpBranchConditional %cmp %if_true %if_false\n"
3543 // False branch for if-statement: placed in the middle of switch cases and before true branch.
3544 "%if_false = OpLabel\n"
3545 "%x_f = OpLoad %u32 %xvar\n"
3546 "%inloc_f = OpAccessChain %f32ptr %indata %zero %x_f\n"
3547 "%inval_f = OpLoad %f32 %inloc_f\n"
3548 "%negate = OpFNegate %f32 %inval_f\n"
3549 "%outloc_f = OpAccessChain %f32ptr %outdata %zero %x_f\n"
3550 " OpStore %outloc_f %negate\n"
3551 " OpBranch %if_merge\n"
3553 // Merge block for if-statement: placed in the middle of true and false branch.
3554 "%if_merge = OpLabel\n"
3557 // True branch for if-statement: placed in the middle of swtich cases and after the false branch.
3558 "%if_true = OpLabel\n"
3559 "%xval_t = OpLoad %u32 %xvar\n"
3560 "%mod = OpUMod %u32 %xval_t %const3\n"
3561 " OpSelectionMerge %switch_merge None\n"
3562 " OpSwitch %mod %default 0 %case0 1 %case1 2 %case2\n"
3564 // Merge block for switch-statement: placed before the case
3565 // bodies. But it must follow OpSwitch which dominates it.
3566 "%switch_merge = OpLabel\n"
3567 " OpBranch %if_merge\n"
3569 // Case 1 for switch-statement: placed before case 0.
3570 // It must follow the OpSwitch that dominates it.
3571 "%case1 = OpLabel\n"
3572 "%x_1 = OpLoad %u32 %xvar\n"
3573 "%inloc_1 = OpAccessChain %f32ptr %indata %zero %x_1\n"
3574 "%inval_1 = OpLoad %f32 %inloc_1\n"
3575 "%addf42 = OpFAdd %f32 %inval_1 %constf42\n"
3576 "%outloc_1 = OpAccessChain %f32ptr %outdata %zero %x_1\n"
3577 " OpStore %outloc_1 %addf42\n"
3578 " OpBranch %switch_merge\n"
3580 // Case 2 for switch-statement.
3581 "%case2 = OpLabel\n"
3582 "%x_2 = OpLoad %u32 %xvar\n"
3583 "%inloc_2 = OpAccessChain %f32ptr %indata %zero %x_2\n"
3584 "%inval_2 = OpLoad %f32 %inloc_2\n"
3585 "%subf27 = OpFSub %f32 %inval_2 %constf27\n"
3586 "%outloc_2 = OpAccessChain %f32ptr %outdata %zero %x_2\n"
3587 " OpStore %outloc_2 %subf27\n"
3588 " OpBranch %switch_merge\n"
3590 // Default case for switch-statement: placed in the middle of normal cases.
3591 "%default = OpLabel\n"
3592 " OpBranch %switch_merge\n"
3594 // Case 0 for switch-statement: out of order.
3595 "%case0 = OpLabel\n"
3596 "%x_0 = OpLoad %u32 %xvar\n"
3597 "%inloc_0 = OpAccessChain %f32ptr %indata %zero %x_0\n"
3598 "%inval_0 = OpLoad %f32 %inloc_0\n"
3599 "%addf1p5 = OpFAdd %f32 %inval_0 %constf1p5\n"
3600 "%outloc_0 = OpAccessChain %f32ptr %outdata %zero %x_0\n"
3601 " OpStore %outloc_0 %addf1p5\n"
3602 " OpBranch %switch_merge\n"
3605 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
3606 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
3607 spec.numWorkGroups = IVec3(numElements, 1, 1);
3609 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "various out-of-order blocks", spec));
3611 return group.release();
3614 tcu::TestCaseGroup* createMultipleShaderGroup (tcu::TestContext& testCtx)
3616 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "multiple_shaders", "Test multiple shaders in the same module"));
3617 ComputeShaderSpec spec1;
3618 ComputeShaderSpec spec2;
3619 de::Random rnd (deStringHash(group->getName()));
3620 const int numElements = 100;
3621 vector<float> inputFloats (numElements, 0);
3622 vector<float> outputFloats1 (numElements, 0);
3623 vector<float> outputFloats2 (numElements, 0);
3624 fillRandomScalars(rnd, -500.f, 500.f, &inputFloats[0], numElements);
3626 for (size_t ndx = 0; ndx < numElements; ++ndx)
3628 outputFloats1[ndx] = inputFloats[ndx] + inputFloats[ndx];
3629 outputFloats2[ndx] = -inputFloats[ndx];
3632 const string assembly(
3633 "OpCapability Shader\n"
3634 "OpCapability ClipDistance\n"
3635 "OpMemoryModel Logical GLSL450\n"
3636 "OpEntryPoint GLCompute %comp_main1 \"entrypoint1\" %id\n"
3637 "OpEntryPoint GLCompute %comp_main2 \"entrypoint2\" %id\n"
3638 // A module cannot have two OpEntryPoint instructions with the same Execution Model and the same Name string.
3639 "OpEntryPoint Vertex %vert_main \"entrypoint2\" %vert_builtins %vertexIndex %instanceIndex\n"
3640 "OpExecutionMode %comp_main1 LocalSize 1 1 1\n"
3641 "OpExecutionMode %comp_main2 LocalSize 1 1 1\n"
3643 "OpName %comp_main1 \"entrypoint1\"\n"
3644 "OpName %comp_main2 \"entrypoint2\"\n"
3645 "OpName %vert_main \"entrypoint2\"\n"
3646 "OpName %id \"gl_GlobalInvocationID\"\n"
3647 "OpName %vert_builtin_st \"gl_PerVertex\"\n"
3648 "OpName %vertexIndex \"gl_VertexIndex\"\n"
3649 "OpName %instanceIndex \"gl_InstanceIndex\"\n"
3650 "OpMemberName %vert_builtin_st 0 \"gl_Position\"\n"
3651 "OpMemberName %vert_builtin_st 1 \"gl_PointSize\"\n"
3652 "OpMemberName %vert_builtin_st 2 \"gl_ClipDistance\"\n"
3654 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3655 "OpDecorate %vertexIndex BuiltIn VertexIndex\n"
3656 "OpDecorate %instanceIndex BuiltIn InstanceIndex\n"
3657 "OpDecorate %vert_builtin_st Block\n"
3658 "OpMemberDecorate %vert_builtin_st 0 BuiltIn Position\n"
3659 "OpMemberDecorate %vert_builtin_st 1 BuiltIn PointSize\n"
3660 "OpMemberDecorate %vert_builtin_st 2 BuiltIn ClipDistance\n"
3662 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
3664 "%zero = OpConstant %i32 0\n"
3665 "%one = OpConstant %u32 1\n"
3666 "%c_f32_1 = OpConstant %f32 1\n"
3668 "%i32inputptr = OpTypePointer Input %i32\n"
3669 "%vec4 = OpTypeVector %f32 4\n"
3670 "%vec4ptr = OpTypePointer Output %vec4\n"
3671 "%f32arr1 = OpTypeArray %f32 %one\n"
3672 "%vert_builtin_st = OpTypeStruct %vec4 %f32 %f32arr1\n"
3673 "%vert_builtin_st_ptr = OpTypePointer Output %vert_builtin_st\n"
3674 "%vert_builtins = OpVariable %vert_builtin_st_ptr Output\n"
3676 "%id = OpVariable %uvec3ptr Input\n"
3677 "%vertexIndex = OpVariable %i32inputptr Input\n"
3678 "%instanceIndex = OpVariable %i32inputptr Input\n"
3679 "%c_vec4_1 = OpConstantComposite %vec4 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_1\n"
3681 // gl_Position = vec4(1.);
3682 "%vert_main = OpFunction %void None %voidf\n"
3683 "%vert_entry = OpLabel\n"
3684 "%position = OpAccessChain %vec4ptr %vert_builtins %zero\n"
3685 " OpStore %position %c_vec4_1\n"
3690 "%comp_main1 = OpFunction %void None %voidf\n"
3691 "%comp1_entry = OpLabel\n"
3692 "%idval1 = OpLoad %uvec3 %id\n"
3693 "%x1 = OpCompositeExtract %u32 %idval1 0\n"
3694 "%inloc1 = OpAccessChain %f32ptr %indata %zero %x1\n"
3695 "%inval1 = OpLoad %f32 %inloc1\n"
3696 "%add = OpFAdd %f32 %inval1 %inval1\n"
3697 "%outloc1 = OpAccessChain %f32ptr %outdata %zero %x1\n"
3698 " OpStore %outloc1 %add\n"
3703 "%comp_main2 = OpFunction %void None %voidf\n"
3704 "%comp2_entry = OpLabel\n"
3705 "%idval2 = OpLoad %uvec3 %id\n"
3706 "%x2 = OpCompositeExtract %u32 %idval2 0\n"
3707 "%inloc2 = OpAccessChain %f32ptr %indata %zero %x2\n"
3708 "%inval2 = OpLoad %f32 %inloc2\n"
3709 "%neg = OpFNegate %f32 %inval2\n"
3710 "%outloc2 = OpAccessChain %f32ptr %outdata %zero %x2\n"
3711 " OpStore %outloc2 %neg\n"
3713 " OpFunctionEnd\n");
3715 spec1.assembly = assembly;
3716 spec1.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
3717 spec1.outputs.push_back(BufferSp(new Float32Buffer(outputFloats1)));
3718 spec1.numWorkGroups = IVec3(numElements, 1, 1);
3719 spec1.entryPoint = "entrypoint1";
3721 spec2.assembly = assembly;
3722 spec2.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
3723 spec2.outputs.push_back(BufferSp(new Float32Buffer(outputFloats2)));
3724 spec2.numWorkGroups = IVec3(numElements, 1, 1);
3725 spec2.entryPoint = "entrypoint2";
3727 group->addChild(new SpvAsmComputeShaderCase(testCtx, "shader1", "multiple shaders in the same module", spec1));
3728 group->addChild(new SpvAsmComputeShaderCase(testCtx, "shader2", "multiple shaders in the same module", spec2));
3730 return group.release();
3733 inline std::string makeLongUTF8String (size_t num4ByteChars)
3735 // An example of a longest valid UTF-8 character. Be explicit about the
3736 // character type because Microsoft compilers can otherwise interpret the
3737 // character string as being over wide (16-bit) characters. Ideally, we
3738 // would just use a C++11 UTF-8 string literal, but we want to support older
3739 // Microsoft compilers.
3740 const std::basic_string<char> earthAfrica("\xF0\x9F\x8C\x8D");
3741 std::string longString;
3742 longString.reserve(num4ByteChars * 4);
3743 for (size_t count = 0; count < num4ByteChars; count++)
3745 longString += earthAfrica;
3750 tcu::TestCaseGroup* createOpSourceGroup (tcu::TestContext& testCtx)
3752 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opsource", "Tests the OpSource & OpSourceContinued instruction"));
3753 vector<CaseParameter> cases;
3754 de::Random rnd (deStringHash(group->getName()));
3755 const int numElements = 100;
3756 vector<float> positiveFloats (numElements, 0);
3757 vector<float> negativeFloats (numElements, 0);
3758 const StringTemplate shaderTemplate (
3759 "OpCapability Shader\n"
3760 "OpMemoryModel Logical GLSL450\n"
3762 "OpEntryPoint GLCompute %main \"main\" %id\n"
3763 "OpExecutionMode %main LocalSize 1 1 1\n"
3767 "OpName %main \"main\"\n"
3768 "OpName %id \"gl_GlobalInvocationID\"\n"
3770 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3772 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
3774 "%id = OpVariable %uvec3ptr Input\n"
3775 "%zero = OpConstant %i32 0\n"
3777 "%main = OpFunction %void None %voidf\n"
3778 "%label = OpLabel\n"
3779 "%idval = OpLoad %uvec3 %id\n"
3780 "%x = OpCompositeExtract %u32 %idval 0\n"
3781 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3782 "%inval = OpLoad %f32 %inloc\n"
3783 "%neg = OpFNegate %f32 %inval\n"
3784 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3785 " OpStore %outloc %neg\n"
3787 " OpFunctionEnd\n");
3789 cases.push_back(CaseParameter("unknown_source", "OpSource Unknown 0"));
3790 cases.push_back(CaseParameter("wrong_source", "OpSource OpenCL_C 210"));
3791 cases.push_back(CaseParameter("normal_filename", "%fname = OpString \"filename\"\n"
3792 "OpSource GLSL 430 %fname"));
3793 cases.push_back(CaseParameter("empty_filename", "%fname = OpString \"\"\n"
3794 "OpSource GLSL 430 %fname"));
3795 cases.push_back(CaseParameter("normal_source_code", "%fname = OpString \"filename\"\n"
3796 "OpSource GLSL 430 %fname \"#version 430\nvoid main() {}\""));
3797 cases.push_back(CaseParameter("empty_source_code", "%fname = OpString \"filename\"\n"
3798 "OpSource GLSL 430 %fname \"\""));
3799 cases.push_back(CaseParameter("long_source_code", "%fname = OpString \"filename\"\n"
3800 "OpSource GLSL 430 %fname \"" + makeLongUTF8String(65530) + "ccc\"")); // word count: 65535
3801 cases.push_back(CaseParameter("utf8_source_code", "%fname = OpString \"filename\"\n"
3802 "OpSource GLSL 430 %fname \"\xE2\x98\x82\xE2\x98\x85\"")); // umbrella & black star symbol
3803 cases.push_back(CaseParameter("normal_sourcecontinued", "%fname = OpString \"filename\"\n"
3804 "OpSource GLSL 430 %fname \"#version 430\nvo\"\n"
3805 "OpSourceContinued \"id main() {}\""));
3806 cases.push_back(CaseParameter("empty_sourcecontinued", "%fname = OpString \"filename\"\n"
3807 "OpSource GLSL 430 %fname \"#version 430\nvoid main() {}\"\n"
3808 "OpSourceContinued \"\""));
3809 cases.push_back(CaseParameter("long_sourcecontinued", "%fname = OpString \"filename\"\n"
3810 "OpSource GLSL 430 %fname \"#version 430\nvoid main() {}\"\n"
3811 "OpSourceContinued \"" + makeLongUTF8String(65533) + "ccc\"")); // word count: 65535
3812 cases.push_back(CaseParameter("utf8_sourcecontinued", "%fname = OpString \"filename\"\n"
3813 "OpSource GLSL 430 %fname \"#version 430\nvoid main() {}\"\n"
3814 "OpSourceContinued \"\xE2\x98\x8E\xE2\x9A\x91\"")); // white telephone & black flag symbol
3815 cases.push_back(CaseParameter("multi_sourcecontinued", "%fname = OpString \"filename\"\n"
3816 "OpSource GLSL 430 %fname \"#version 430\n\"\n"
3817 "OpSourceContinued \"void\"\n"
3818 "OpSourceContinued \"main()\"\n"
3819 "OpSourceContinued \"{}\""));
3820 cases.push_back(CaseParameter("empty_source_before_sourcecontinued", "%fname = OpString \"filename\"\n"
3821 "OpSource GLSL 430 %fname \"\"\n"
3822 "OpSourceContinued \"#version 430\nvoid main() {}\""));
3824 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
3826 for (size_t ndx = 0; ndx < numElements; ++ndx)
3827 negativeFloats[ndx] = -positiveFloats[ndx];
3829 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
3831 map<string, string> specializations;
3832 ComputeShaderSpec spec;
3834 specializations["SOURCE"] = cases[caseNdx].param;
3835 spec.assembly = shaderTemplate.specialize(specializations);
3836 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
3837 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
3838 spec.numWorkGroups = IVec3(numElements, 1, 1);
3840 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
3843 return group.release();
3846 tcu::TestCaseGroup* createOpSourceExtensionGroup (tcu::TestContext& testCtx)
3848 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opsourceextension", "Tests the OpSource instruction"));
3849 vector<CaseParameter> cases;
3850 de::Random rnd (deStringHash(group->getName()));
3851 const int numElements = 100;
3852 vector<float> inputFloats (numElements, 0);
3853 vector<float> outputFloats (numElements, 0);
3854 const StringTemplate shaderTemplate (
3855 string(getComputeAsmShaderPreamble()) +
3857 "OpSourceExtension \"${EXTENSION}\"\n"
3859 "OpName %main \"main\"\n"
3860 "OpName %id \"gl_GlobalInvocationID\"\n"
3862 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3864 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
3866 "%id = OpVariable %uvec3ptr Input\n"
3867 "%zero = OpConstant %i32 0\n"
3869 "%main = OpFunction %void None %voidf\n"
3870 "%label = OpLabel\n"
3871 "%idval = OpLoad %uvec3 %id\n"
3872 "%x = OpCompositeExtract %u32 %idval 0\n"
3873 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3874 "%inval = OpLoad %f32 %inloc\n"
3875 "%neg = OpFNegate %f32 %inval\n"
3876 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3877 " OpStore %outloc %neg\n"
3879 " OpFunctionEnd\n");
3881 cases.push_back(CaseParameter("empty_extension", ""));
3882 cases.push_back(CaseParameter("real_extension", "GL_ARB_texture_rectangle"));
3883 cases.push_back(CaseParameter("fake_extension", "GL_ARB_im_the_ultimate_extension"));
3884 cases.push_back(CaseParameter("utf8_extension", "GL_ARB_\xE2\x98\x82\xE2\x98\x85"));
3885 cases.push_back(CaseParameter("long_extension", makeLongUTF8String(65533) + "ccc")); // word count: 65535
3887 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats[0], numElements);
3889 for (size_t ndx = 0; ndx < numElements; ++ndx)
3890 outputFloats[ndx] = -inputFloats[ndx];
3892 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
3894 map<string, string> specializations;
3895 ComputeShaderSpec spec;
3897 specializations["EXTENSION"] = cases[caseNdx].param;
3898 spec.assembly = shaderTemplate.specialize(specializations);
3899 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
3900 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
3901 spec.numWorkGroups = IVec3(numElements, 1, 1);
3903 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
3906 return group.release();
3909 // Checks that a compute shader can generate a constant null value of various types, without exercising a computation on it.
3910 tcu::TestCaseGroup* createOpConstantNullGroup (tcu::TestContext& testCtx)
3912 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opconstantnull", "Tests the OpConstantNull instruction"));
3913 vector<CaseParameter> cases;
3914 de::Random rnd (deStringHash(group->getName()));
3915 const int numElements = 100;
3916 vector<float> positiveFloats (numElements, 0);
3917 vector<float> negativeFloats (numElements, 0);
3918 const StringTemplate shaderTemplate (
3919 string(getComputeAsmShaderPreamble()) +
3921 "OpSource GLSL 430\n"
3922 "OpName %main \"main\"\n"
3923 "OpName %id \"gl_GlobalInvocationID\"\n"
3925 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3927 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
3928 "%uvec2 = OpTypeVector %u32 2\n"
3929 "%bvec3 = OpTypeVector %bool 3\n"
3930 "%fvec4 = OpTypeVector %f32 4\n"
3931 "%fmat33 = OpTypeMatrix %fvec3 3\n"
3932 "%const100 = OpConstant %u32 100\n"
3933 "%uarr100 = OpTypeArray %i32 %const100\n"
3934 "%struct = OpTypeStruct %f32 %i32 %u32\n"
3935 "%pointer = OpTypePointer Function %i32\n"
3936 + string(getComputeAsmInputOutputBuffer()) +
3938 "%null = OpConstantNull ${TYPE}\n"
3940 "%id = OpVariable %uvec3ptr Input\n"
3941 "%zero = OpConstant %i32 0\n"
3943 "%main = OpFunction %void None %voidf\n"
3944 "%label = OpLabel\n"
3945 "%idval = OpLoad %uvec3 %id\n"
3946 "%x = OpCompositeExtract %u32 %idval 0\n"
3947 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3948 "%inval = OpLoad %f32 %inloc\n"
3949 "%neg = OpFNegate %f32 %inval\n"
3950 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3951 " OpStore %outloc %neg\n"
3953 " OpFunctionEnd\n");
3955 cases.push_back(CaseParameter("bool", "%bool"));
3956 cases.push_back(CaseParameter("sint32", "%i32"));
3957 cases.push_back(CaseParameter("uint32", "%u32"));
3958 cases.push_back(CaseParameter("float32", "%f32"));
3959 cases.push_back(CaseParameter("vec4float32", "%fvec4"));
3960 cases.push_back(CaseParameter("vec3bool", "%bvec3"));
3961 cases.push_back(CaseParameter("vec2uint32", "%uvec2"));
3962 cases.push_back(CaseParameter("matrix", "%fmat33"));
3963 cases.push_back(CaseParameter("array", "%uarr100"));
3964 cases.push_back(CaseParameter("struct", "%struct"));
3965 cases.push_back(CaseParameter("pointer", "%pointer"));
3967 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
3969 for (size_t ndx = 0; ndx < numElements; ++ndx)
3970 negativeFloats[ndx] = -positiveFloats[ndx];
3972 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
3974 map<string, string> specializations;
3975 ComputeShaderSpec spec;
3977 specializations["TYPE"] = cases[caseNdx].param;
3978 spec.assembly = shaderTemplate.specialize(specializations);
3979 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
3980 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
3981 spec.numWorkGroups = IVec3(numElements, 1, 1);
3983 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
3986 return group.release();
3989 // Checks that a compute shader can generate a constant composite value of various types, without exercising a computation on it.
3990 tcu::TestCaseGroup* createOpConstantCompositeGroup (tcu::TestContext& testCtx)
3992 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opconstantcomposite", "Tests the OpConstantComposite instruction"));
3993 vector<CaseParameter> cases;
3994 de::Random rnd (deStringHash(group->getName()));
3995 const int numElements = 100;
3996 vector<float> positiveFloats (numElements, 0);
3997 vector<float> negativeFloats (numElements, 0);
3998 const StringTemplate shaderTemplate (
3999 string(getComputeAsmShaderPreamble()) +
4001 "OpSource GLSL 430\n"
4002 "OpName %main \"main\"\n"
4003 "OpName %id \"gl_GlobalInvocationID\"\n"
4005 "OpDecorate %id BuiltIn GlobalInvocationId\n"
4007 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
4009 "%id = OpVariable %uvec3ptr Input\n"
4010 "%zero = OpConstant %i32 0\n"
4014 "%main = OpFunction %void None %voidf\n"
4015 "%label = OpLabel\n"
4016 "%idval = OpLoad %uvec3 %id\n"
4017 "%x = OpCompositeExtract %u32 %idval 0\n"
4018 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
4019 "%inval = OpLoad %f32 %inloc\n"
4020 "%neg = OpFNegate %f32 %inval\n"
4021 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
4022 " OpStore %outloc %neg\n"
4024 " OpFunctionEnd\n");
4026 cases.push_back(CaseParameter("vector", "%five = OpConstant %u32 5\n"
4027 "%const = OpConstantComposite %uvec3 %five %zero %five"));
4028 cases.push_back(CaseParameter("matrix", "%m3fvec3 = OpTypeMatrix %fvec3 3\n"
4029 "%ten = OpConstant %f32 10.\n"
4030 "%fzero = OpConstant %f32 0.\n"
4031 "%vec = OpConstantComposite %fvec3 %ten %fzero %ten\n"
4032 "%mat = OpConstantComposite %m3fvec3 %vec %vec %vec"));
4033 cases.push_back(CaseParameter("struct", "%m2vec3 = OpTypeMatrix %fvec3 2\n"
4034 "%struct = OpTypeStruct %i32 %f32 %fvec3 %m2vec3\n"
4035 "%fzero = OpConstant %f32 0.\n"
4036 "%one = OpConstant %f32 1.\n"
4037 "%point5 = OpConstant %f32 0.5\n"
4038 "%vec = OpConstantComposite %fvec3 %one %one %fzero\n"
4039 "%mat = OpConstantComposite %m2vec3 %vec %vec\n"
4040 "%const = OpConstantComposite %struct %zero %point5 %vec %mat"));
4041 cases.push_back(CaseParameter("nested_struct", "%st1 = OpTypeStruct %u32 %f32\n"
4042 "%st2 = OpTypeStruct %i32 %i32\n"
4043 "%struct = OpTypeStruct %st1 %st2\n"
4044 "%point5 = OpConstant %f32 0.5\n"
4045 "%one = OpConstant %u32 1\n"
4046 "%ten = OpConstant %i32 10\n"
4047 "%st1val = OpConstantComposite %st1 %one %point5\n"
4048 "%st2val = OpConstantComposite %st2 %ten %ten\n"
4049 "%const = OpConstantComposite %struct %st1val %st2val"));
4051 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
4053 for (size_t ndx = 0; ndx < numElements; ++ndx)
4054 negativeFloats[ndx] = -positiveFloats[ndx];
4056 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
4058 map<string, string> specializations;
4059 ComputeShaderSpec spec;
4061 specializations["CONSTANT"] = cases[caseNdx].param;
4062 spec.assembly = shaderTemplate.specialize(specializations);
4063 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
4064 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
4065 spec.numWorkGroups = IVec3(numElements, 1, 1);
4067 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
4070 return group.release();
4073 // Creates a floating point number with the given exponent, and significand
4074 // bits set. It can only create normalized numbers. Only the least significant
4075 // 24 bits of the significand will be examined. The final bit of the
4076 // significand will also be ignored. This allows alignment to be written
4077 // similarly to C99 hex-floats.
4078 // For example if you wanted to write 0x1.7f34p-12 you would call
4079 // constructNormalizedFloat(-12, 0x7f3400)
4080 float constructNormalizedFloat (deInt32 exponent, deUint32 significand)
4084 for (deInt32 idx = 0; idx < 23; ++idx)
4086 f += ((significand & 0x800000) == 0) ? 0.f : std::ldexp(1.0f, -(idx + 1));
4090 return std::ldexp(f, exponent);
4093 // Compare instruction for the OpQuantizeF16 compute exact case.
4094 // Returns true if the output is what is expected from the test case.
4095 bool compareOpQuantizeF16ComputeExactCase (const std::vector<BufferSp>&, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs, TestLog&)
4097 if (outputAllocs.size() != 1)
4100 // Only size is needed because we cannot compare Nans.
4101 size_t byteSize = expectedOutputs[0]->getByteSize();
4103 const float* outputAsFloat = static_cast<const float*>(outputAllocs[0]->getHostPtr());
4105 if (byteSize != 4*sizeof(float)) {
4109 if (*outputAsFloat != constructNormalizedFloat(8, 0x304000) &&
4110 *outputAsFloat != constructNormalizedFloat(8, 0x300000)) {
4115 if (*outputAsFloat != -constructNormalizedFloat(-7, 0x600000) &&
4116 *outputAsFloat != -constructNormalizedFloat(-7, 0x604000)) {
4121 if (*outputAsFloat != constructNormalizedFloat(2, 0x01C000) &&
4122 *outputAsFloat != constructNormalizedFloat(2, 0x020000)) {
4127 if (*outputAsFloat != constructNormalizedFloat(1, 0xFFC000) &&
4128 *outputAsFloat != constructNormalizedFloat(2, 0x000000)) {
4135 // Checks that every output from a test-case is a float NaN.
4136 bool compareNan (const std::vector<BufferSp>&, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs, TestLog&)
4138 if (outputAllocs.size() != 1)
4141 // Only size is needed because we cannot compare Nans.
4142 size_t byteSize = expectedOutputs[0]->getByteSize();
4144 const float* const output_as_float = static_cast<const float* const>(outputAllocs[0]->getHostPtr());
4146 for (size_t idx = 0; idx < byteSize / sizeof(float); ++idx)
4148 if (!deFloatIsNaN(output_as_float[idx]))
4157 // Checks that a compute shader can generate a constant composite value of various types, without exercising a computation on it.
4158 tcu::TestCaseGroup* createOpQuantizeToF16Group (tcu::TestContext& testCtx)
4160 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opquantize", "Tests the OpQuantizeToF16 instruction"));
4162 const std::string shader (
4163 string(getComputeAsmShaderPreamble()) +
4165 "OpSource GLSL 430\n"
4166 "OpName %main \"main\"\n"
4167 "OpName %id \"gl_GlobalInvocationID\"\n"
4169 "OpDecorate %id BuiltIn GlobalInvocationId\n"
4171 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
4173 "%id = OpVariable %uvec3ptr Input\n"
4174 "%zero = OpConstant %i32 0\n"
4176 "%main = OpFunction %void None %voidf\n"
4177 "%label = OpLabel\n"
4178 "%idval = OpLoad %uvec3 %id\n"
4179 "%x = OpCompositeExtract %u32 %idval 0\n"
4180 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
4181 "%inval = OpLoad %f32 %inloc\n"
4182 "%quant = OpQuantizeToF16 %f32 %inval\n"
4183 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
4184 " OpStore %outloc %quant\n"
4186 " OpFunctionEnd\n");
4189 ComputeShaderSpec spec;
4190 const deUint32 numElements = 100;
4191 vector<float> infinities;
4192 vector<float> results;
4194 infinities.reserve(numElements);
4195 results.reserve(numElements);
4197 for (size_t idx = 0; idx < numElements; ++idx)
4202 infinities.push_back(std::numeric_limits<float>::infinity());
4203 results.push_back(std::numeric_limits<float>::infinity());
4206 infinities.push_back(-std::numeric_limits<float>::infinity());
4207 results.push_back(-std::numeric_limits<float>::infinity());
4210 infinities.push_back(std::ldexp(1.0f, 16));
4211 results.push_back(std::numeric_limits<float>::infinity());
4214 infinities.push_back(std::ldexp(-1.0f, 32));
4215 results.push_back(-std::numeric_limits<float>::infinity());
4220 spec.assembly = shader;
4221 spec.inputs.push_back(BufferSp(new Float32Buffer(infinities)));
4222 spec.outputs.push_back(BufferSp(new Float32Buffer(results)));
4223 spec.numWorkGroups = IVec3(numElements, 1, 1);
4225 group->addChild(new SpvAsmComputeShaderCase(
4226 testCtx, "infinities", "Check that infinities propagated and created", spec));
4230 ComputeShaderSpec spec;
4232 const deUint32 numElements = 100;
4234 nans.reserve(numElements);
4236 for (size_t idx = 0; idx < numElements; ++idx)
4240 nans.push_back(std::numeric_limits<float>::quiet_NaN());
4244 nans.push_back(-std::numeric_limits<float>::quiet_NaN());
4248 spec.assembly = shader;
4249 spec.inputs.push_back(BufferSp(new Float32Buffer(nans)));
4250 spec.outputs.push_back(BufferSp(new Float32Buffer(nans)));
4251 spec.numWorkGroups = IVec3(numElements, 1, 1);
4252 spec.verifyIO = &compareNan;
4254 group->addChild(new SpvAsmComputeShaderCase(
4255 testCtx, "propagated_nans", "Check that nans are propagated", spec));
4259 ComputeShaderSpec spec;
4260 vector<float> small;
4261 vector<float> zeros;
4262 const deUint32 numElements = 100;
4264 small.reserve(numElements);
4265 zeros.reserve(numElements);
4267 for (size_t idx = 0; idx < numElements; ++idx)
4272 small.push_back(0.f);
4273 zeros.push_back(0.f);
4276 small.push_back(-0.f);
4277 zeros.push_back(-0.f);
4280 small.push_back(std::ldexp(1.0f, -16));
4281 zeros.push_back(0.f);
4284 small.push_back(std::ldexp(-1.0f, -32));
4285 zeros.push_back(-0.f);
4288 small.push_back(std::ldexp(1.0f, -127));
4289 zeros.push_back(0.f);
4292 small.push_back(-std::ldexp(1.0f, -128));
4293 zeros.push_back(-0.f);
4298 spec.assembly = shader;
4299 spec.inputs.push_back(BufferSp(new Float32Buffer(small)));
4300 spec.outputs.push_back(BufferSp(new Float32Buffer(zeros)));
4301 spec.numWorkGroups = IVec3(numElements, 1, 1);
4303 group->addChild(new SpvAsmComputeShaderCase(
4304 testCtx, "flush_to_zero", "Check that values are zeroed correctly", spec));
4308 ComputeShaderSpec spec;
4309 vector<float> exact;
4310 const deUint32 numElements = 200;
4312 exact.reserve(numElements);
4314 for (size_t idx = 0; idx < numElements; ++idx)
4315 exact.push_back(static_cast<float>(static_cast<int>(idx) - 100));
4317 spec.assembly = shader;
4318 spec.inputs.push_back(BufferSp(new Float32Buffer(exact)));
4319 spec.outputs.push_back(BufferSp(new Float32Buffer(exact)));
4320 spec.numWorkGroups = IVec3(numElements, 1, 1);
4322 group->addChild(new SpvAsmComputeShaderCase(
4323 testCtx, "exact", "Check that values exactly preserved where appropriate", spec));
4327 ComputeShaderSpec spec;
4328 vector<float> inputs;
4329 const deUint32 numElements = 4;
4331 inputs.push_back(constructNormalizedFloat(8, 0x300300));
4332 inputs.push_back(-constructNormalizedFloat(-7, 0x600800));
4333 inputs.push_back(constructNormalizedFloat(2, 0x01E000));
4334 inputs.push_back(constructNormalizedFloat(1, 0xFFE000));
4336 spec.assembly = shader;
4337 spec.verifyIO = &compareOpQuantizeF16ComputeExactCase;
4338 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs)));
4339 spec.outputs.push_back(BufferSp(new Float32Buffer(inputs)));
4340 spec.numWorkGroups = IVec3(numElements, 1, 1);
4342 group->addChild(new SpvAsmComputeShaderCase(
4343 testCtx, "rounded", "Check that are rounded when needed", spec));
4346 return group.release();
4349 tcu::TestCaseGroup* createSpecConstantOpQuantizeToF16Group (tcu::TestContext& testCtx)
4351 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opspecconstantop_opquantize", "Tests the OpQuantizeToF16 opcode for the OpSpecConstantOp instruction"));
4353 const std::string shader (
4354 string(getComputeAsmShaderPreamble()) +
4356 "OpName %main \"main\"\n"
4357 "OpName %id \"gl_GlobalInvocationID\"\n"
4359 "OpDecorate %id BuiltIn GlobalInvocationId\n"
4361 "OpDecorate %sc_0 SpecId 0\n"
4362 "OpDecorate %sc_1 SpecId 1\n"
4363 "OpDecorate %sc_2 SpecId 2\n"
4364 "OpDecorate %sc_3 SpecId 3\n"
4365 "OpDecorate %sc_4 SpecId 4\n"
4366 "OpDecorate %sc_5 SpecId 5\n"
4368 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
4370 "%id = OpVariable %uvec3ptr Input\n"
4371 "%zero = OpConstant %i32 0\n"
4372 "%c_u32_6 = OpConstant %u32 6\n"
4374 "%sc_0 = OpSpecConstant %f32 0.\n"
4375 "%sc_1 = OpSpecConstant %f32 0.\n"
4376 "%sc_2 = OpSpecConstant %f32 0.\n"
4377 "%sc_3 = OpSpecConstant %f32 0.\n"
4378 "%sc_4 = OpSpecConstant %f32 0.\n"
4379 "%sc_5 = OpSpecConstant %f32 0.\n"
4381 "%sc_0_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_0\n"
4382 "%sc_1_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_1\n"
4383 "%sc_2_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_2\n"
4384 "%sc_3_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_3\n"
4385 "%sc_4_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_4\n"
4386 "%sc_5_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_5\n"
4388 "%main = OpFunction %void None %voidf\n"
4389 "%label = OpLabel\n"
4390 "%idval = OpLoad %uvec3 %id\n"
4391 "%x = OpCompositeExtract %u32 %idval 0\n"
4392 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
4393 "%selector = OpUMod %u32 %x %c_u32_6\n"
4394 " OpSelectionMerge %exit None\n"
4395 " OpSwitch %selector %exit 0 %case0 1 %case1 2 %case2 3 %case3 4 %case4 5 %case5\n"
4397 "%case0 = OpLabel\n"
4398 " OpStore %outloc %sc_0_quant\n"
4401 "%case1 = OpLabel\n"
4402 " OpStore %outloc %sc_1_quant\n"
4405 "%case2 = OpLabel\n"
4406 " OpStore %outloc %sc_2_quant\n"
4409 "%case3 = OpLabel\n"
4410 " OpStore %outloc %sc_3_quant\n"
4413 "%case4 = OpLabel\n"
4414 " OpStore %outloc %sc_4_quant\n"
4417 "%case5 = OpLabel\n"
4418 " OpStore %outloc %sc_5_quant\n"
4424 " OpFunctionEnd\n");
4427 ComputeShaderSpec spec;
4428 const deUint8 numCases = 4;
4429 vector<float> inputs (numCases, 0.f);
4430 vector<float> outputs;
4432 spec.assembly = shader;
4433 spec.numWorkGroups = IVec3(numCases, 1, 1);
4435 spec.specConstants.push_back(bitwiseCast<deUint32>(std::numeric_limits<float>::infinity()));
4436 spec.specConstants.push_back(bitwiseCast<deUint32>(-std::numeric_limits<float>::infinity()));
4437 spec.specConstants.push_back(bitwiseCast<deUint32>(std::ldexp(1.0f, 16)));
4438 spec.specConstants.push_back(bitwiseCast<deUint32>(std::ldexp(-1.0f, 32)));
4440 outputs.push_back(std::numeric_limits<float>::infinity());
4441 outputs.push_back(-std::numeric_limits<float>::infinity());
4442 outputs.push_back(std::numeric_limits<float>::infinity());
4443 outputs.push_back(-std::numeric_limits<float>::infinity());
4445 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs)));
4446 spec.outputs.push_back(BufferSp(new Float32Buffer(outputs)));
4448 group->addChild(new SpvAsmComputeShaderCase(
4449 testCtx, "infinities", "Check that infinities propagated and created", spec));
4453 ComputeShaderSpec spec;
4454 const deUint8 numCases = 2;
4455 vector<float> inputs (numCases, 0.f);
4456 vector<float> outputs;
4458 spec.assembly = shader;
4459 spec.numWorkGroups = IVec3(numCases, 1, 1);
4460 spec.verifyIO = &compareNan;
4462 outputs.push_back(std::numeric_limits<float>::quiet_NaN());
4463 outputs.push_back(-std::numeric_limits<float>::quiet_NaN());
4465 for (deUint8 idx = 0; idx < numCases; ++idx)
4466 spec.specConstants.push_back(bitwiseCast<deUint32>(outputs[idx]));
4468 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs)));
4469 spec.outputs.push_back(BufferSp(new Float32Buffer(outputs)));
4471 group->addChild(new SpvAsmComputeShaderCase(
4472 testCtx, "propagated_nans", "Check that nans are propagated", spec));
4476 ComputeShaderSpec spec;
4477 const deUint8 numCases = 6;
4478 vector<float> inputs (numCases, 0.f);
4479 vector<float> outputs;
4481 spec.assembly = shader;
4482 spec.numWorkGroups = IVec3(numCases, 1, 1);
4484 spec.specConstants.push_back(bitwiseCast<deUint32>(0.f));
4485 spec.specConstants.push_back(bitwiseCast<deUint32>(-0.f));
4486 spec.specConstants.push_back(bitwiseCast<deUint32>(std::ldexp(1.0f, -16)));
4487 spec.specConstants.push_back(bitwiseCast<deUint32>(std::ldexp(-1.0f, -32)));
4488 spec.specConstants.push_back(bitwiseCast<deUint32>(std::ldexp(1.0f, -127)));
4489 spec.specConstants.push_back(bitwiseCast<deUint32>(-std::ldexp(1.0f, -128)));
4491 outputs.push_back(0.f);
4492 outputs.push_back(-0.f);
4493 outputs.push_back(0.f);
4494 outputs.push_back(-0.f);
4495 outputs.push_back(0.f);
4496 outputs.push_back(-0.f);
4498 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs)));
4499 spec.outputs.push_back(BufferSp(new Float32Buffer(outputs)));
4501 group->addChild(new SpvAsmComputeShaderCase(
4502 testCtx, "flush_to_zero", "Check that values are zeroed correctly", spec));
4506 ComputeShaderSpec spec;
4507 const deUint8 numCases = 6;
4508 vector<float> inputs (numCases, 0.f);
4509 vector<float> outputs;
4511 spec.assembly = shader;
4512 spec.numWorkGroups = IVec3(numCases, 1, 1);
4514 for (deUint8 idx = 0; idx < 6; ++idx)
4516 const float f = static_cast<float>(idx * 10 - 30) / 4.f;
4517 spec.specConstants.push_back(bitwiseCast<deUint32>(f));
4518 outputs.push_back(f);
4521 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs)));
4522 spec.outputs.push_back(BufferSp(new Float32Buffer(outputs)));
4524 group->addChild(new SpvAsmComputeShaderCase(
4525 testCtx, "exact", "Check that values exactly preserved where appropriate", spec));
4529 ComputeShaderSpec spec;
4530 const deUint8 numCases = 4;
4531 vector<float> inputs (numCases, 0.f);
4532 vector<float> outputs;
4534 spec.assembly = shader;
4535 spec.numWorkGroups = IVec3(numCases, 1, 1);
4536 spec.verifyIO = &compareOpQuantizeF16ComputeExactCase;
4538 outputs.push_back(constructNormalizedFloat(8, 0x300300));
4539 outputs.push_back(-constructNormalizedFloat(-7, 0x600800));
4540 outputs.push_back(constructNormalizedFloat(2, 0x01E000));
4541 outputs.push_back(constructNormalizedFloat(1, 0xFFE000));
4543 for (deUint8 idx = 0; idx < numCases; ++idx)
4544 spec.specConstants.push_back(bitwiseCast<deUint32>(outputs[idx]));
4546 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs)));
4547 spec.outputs.push_back(BufferSp(new Float32Buffer(outputs)));
4549 group->addChild(new SpvAsmComputeShaderCase(
4550 testCtx, "rounded", "Check that are rounded when needed", spec));
4553 return group.release();
4556 // Checks that constant null/composite values can be used in computation.
4557 tcu::TestCaseGroup* createOpConstantUsageGroup (tcu::TestContext& testCtx)
4559 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opconstantnullcomposite", "Spotcheck the OpConstantNull & OpConstantComposite instruction"));
4560 ComputeShaderSpec spec;
4561 de::Random rnd (deStringHash(group->getName()));
4562 const int numElements = 100;
4563 vector<float> positiveFloats (numElements, 0);
4564 vector<float> negativeFloats (numElements, 0);
4566 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
4568 for (size_t ndx = 0; ndx < numElements; ++ndx)
4569 negativeFloats[ndx] = -positiveFloats[ndx];
4572 "OpCapability Shader\n"
4573 "%std450 = OpExtInstImport \"GLSL.std.450\"\n"
4574 "OpMemoryModel Logical GLSL450\n"
4575 "OpEntryPoint GLCompute %main \"main\" %id\n"
4576 "OpExecutionMode %main LocalSize 1 1 1\n"
4578 "OpSource GLSL 430\n"
4579 "OpName %main \"main\"\n"
4580 "OpName %id \"gl_GlobalInvocationID\"\n"
4582 "OpDecorate %id BuiltIn GlobalInvocationId\n"
4584 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
4586 "%fmat = OpTypeMatrix %fvec3 3\n"
4587 "%ten = OpConstant %u32 10\n"
4588 "%f32arr10 = OpTypeArray %f32 %ten\n"
4589 "%fst = OpTypeStruct %f32 %f32\n"
4591 + string(getComputeAsmInputOutputBuffer()) +
4593 "%id = OpVariable %uvec3ptr Input\n"
4594 "%zero = OpConstant %i32 0\n"
4596 // Create a bunch of null values
4597 "%unull = OpConstantNull %u32\n"
4598 "%fnull = OpConstantNull %f32\n"
4599 "%vnull = OpConstantNull %fvec3\n"
4600 "%mnull = OpConstantNull %fmat\n"
4601 "%anull = OpConstantNull %f32arr10\n"
4602 "%snull = OpConstantComposite %fst %fnull %fnull\n"
4604 "%main = OpFunction %void None %voidf\n"
4605 "%label = OpLabel\n"
4606 "%idval = OpLoad %uvec3 %id\n"
4607 "%x = OpCompositeExtract %u32 %idval 0\n"
4608 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
4609 "%inval = OpLoad %f32 %inloc\n"
4610 "%neg = OpFNegate %f32 %inval\n"
4612 // Get the abs() of (a certain element of) those null values
4613 "%unull_cov = OpConvertUToF %f32 %unull\n"
4614 "%unull_abs = OpExtInst %f32 %std450 FAbs %unull_cov\n"
4615 "%fnull_abs = OpExtInst %f32 %std450 FAbs %fnull\n"
4616 "%vnull_0 = OpCompositeExtract %f32 %vnull 0\n"
4617 "%vnull_abs = OpExtInst %f32 %std450 FAbs %vnull_0\n"
4618 "%mnull_12 = OpCompositeExtract %f32 %mnull 1 2\n"
4619 "%mnull_abs = OpExtInst %f32 %std450 FAbs %mnull_12\n"
4620 "%anull_3 = OpCompositeExtract %f32 %anull 3\n"
4621 "%anull_abs = OpExtInst %f32 %std450 FAbs %anull_3\n"
4622 "%snull_1 = OpCompositeExtract %f32 %snull 1\n"
4623 "%snull_abs = OpExtInst %f32 %std450 FAbs %snull_1\n"
4626 "%add1 = OpFAdd %f32 %neg %unull_abs\n"
4627 "%add2 = OpFAdd %f32 %add1 %fnull_abs\n"
4628 "%add3 = OpFAdd %f32 %add2 %vnull_abs\n"
4629 "%add4 = OpFAdd %f32 %add3 %mnull_abs\n"
4630 "%add5 = OpFAdd %f32 %add4 %anull_abs\n"
4631 "%final = OpFAdd %f32 %add5 %snull_abs\n"
4633 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
4634 " OpStore %outloc %final\n" // write to output
4637 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
4638 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
4639 spec.numWorkGroups = IVec3(numElements, 1, 1);
4641 group->addChild(new SpvAsmComputeShaderCase(testCtx, "spotcheck", "Check that values constructed via OpConstantNull & OpConstantComposite can be used", spec));
4643 return group.release();
4646 // Assembly code used for testing loop control is based on GLSL source code:
4649 // layout(std140, set = 0, binding = 0) readonly buffer Input {
4650 // float elements[];
4652 // layout(std140, set = 0, binding = 1) writeonly buffer Output {
4653 // float elements[];
4657 // uint x = gl_GlobalInvocationID.x;
4658 // output_data.elements[x] = input_data.elements[x];
4659 // for (uint i = 0; i < 4; ++i)
4660 // output_data.elements[x] += 1.f;
4662 tcu::TestCaseGroup* createLoopControlGroup (tcu::TestContext& testCtx)
4664 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "loop_control", "Tests loop control cases"));
4665 vector<CaseParameter> cases;
4666 de::Random rnd (deStringHash(group->getName()));
4667 const int numElements = 100;
4668 vector<float> inputFloats (numElements, 0);
4669 vector<float> outputFloats (numElements, 0);
4670 const StringTemplate shaderTemplate (
4671 string(getComputeAsmShaderPreamble()) +
4673 "OpSource GLSL 430\n"
4674 "OpName %main \"main\"\n"
4675 "OpName %id \"gl_GlobalInvocationID\"\n"
4677 "OpDecorate %id BuiltIn GlobalInvocationId\n"
4679 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
4681 "%u32ptr = OpTypePointer Function %u32\n"
4683 "%id = OpVariable %uvec3ptr Input\n"
4684 "%zero = OpConstant %i32 0\n"
4685 "%uzero = OpConstant %u32 0\n"
4686 "%one = OpConstant %i32 1\n"
4687 "%constf1 = OpConstant %f32 1.0\n"
4688 "%four = OpConstant %u32 4\n"
4690 "%main = OpFunction %void None %voidf\n"
4691 "%entry = OpLabel\n"
4692 "%i = OpVariable %u32ptr Function\n"
4693 " OpStore %i %uzero\n"
4695 "%idval = OpLoad %uvec3 %id\n"
4696 "%x = OpCompositeExtract %u32 %idval 0\n"
4697 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
4698 "%inval = OpLoad %f32 %inloc\n"
4699 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
4700 " OpStore %outloc %inval\n"
4701 " OpBranch %loop_entry\n"
4703 "%loop_entry = OpLabel\n"
4704 "%i_val = OpLoad %u32 %i\n"
4705 "%cmp_lt = OpULessThan %bool %i_val %four\n"
4706 " OpLoopMerge %loop_merge %loop_body ${CONTROL}\n"
4707 " OpBranchConditional %cmp_lt %loop_body %loop_merge\n"
4708 "%loop_body = OpLabel\n"
4709 "%outval = OpLoad %f32 %outloc\n"
4710 "%addf1 = OpFAdd %f32 %outval %constf1\n"
4711 " OpStore %outloc %addf1\n"
4712 "%new_i = OpIAdd %u32 %i_val %one\n"
4713 " OpStore %i %new_i\n"
4714 " OpBranch %loop_entry\n"
4715 "%loop_merge = OpLabel\n"
4717 " OpFunctionEnd\n");
4719 cases.push_back(CaseParameter("none", "None"));
4720 cases.push_back(CaseParameter("unroll", "Unroll"));
4721 cases.push_back(CaseParameter("dont_unroll", "DontUnroll"));
4722 cases.push_back(CaseParameter("unroll_dont_unroll", "Unroll|DontUnroll"));
4724 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats[0], numElements);
4726 for (size_t ndx = 0; ndx < numElements; ++ndx)
4727 outputFloats[ndx] = inputFloats[ndx] + 4.f;
4729 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
4731 map<string, string> specializations;
4732 ComputeShaderSpec spec;
4734 specializations["CONTROL"] = cases[caseNdx].param;
4735 spec.assembly = shaderTemplate.specialize(specializations);
4736 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
4737 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
4738 spec.numWorkGroups = IVec3(numElements, 1, 1);
4740 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
4743 return group.release();
4746 // Assembly code used for testing selection control is based on GLSL source code:
4749 // layout(std140, set = 0, binding = 0) readonly buffer Input {
4750 // float elements[];
4752 // layout(std140, set = 0, binding = 1) writeonly buffer Output {
4753 // float elements[];
4757 // uint x = gl_GlobalInvocationID.x;
4758 // float val = input_data.elements[x];
4760 // output_data.elements[x] = val + 1.f;
4762 // output_data.elements[x] = val - 1.f;
4764 tcu::TestCaseGroup* createSelectionControlGroup (tcu::TestContext& testCtx)
4766 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "selection_control", "Tests selection control cases"));
4767 vector<CaseParameter> cases;
4768 de::Random rnd (deStringHash(group->getName()));
4769 const int numElements = 100;
4770 vector<float> inputFloats (numElements, 0);
4771 vector<float> outputFloats (numElements, 0);
4772 const StringTemplate shaderTemplate (
4773 string(getComputeAsmShaderPreamble()) +
4775 "OpSource GLSL 430\n"
4776 "OpName %main \"main\"\n"
4777 "OpName %id \"gl_GlobalInvocationID\"\n"
4779 "OpDecorate %id BuiltIn GlobalInvocationId\n"
4781 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
4783 "%id = OpVariable %uvec3ptr Input\n"
4784 "%zero = OpConstant %i32 0\n"
4785 "%constf1 = OpConstant %f32 1.0\n"
4786 "%constf10 = OpConstant %f32 10.0\n"
4788 "%main = OpFunction %void None %voidf\n"
4789 "%entry = OpLabel\n"
4790 "%idval = OpLoad %uvec3 %id\n"
4791 "%x = OpCompositeExtract %u32 %idval 0\n"
4792 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
4793 "%inval = OpLoad %f32 %inloc\n"
4794 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
4795 "%cmp_gt = OpFOrdGreaterThan %bool %inval %constf10\n"
4797 " OpSelectionMerge %if_end ${CONTROL}\n"
4798 " OpBranchConditional %cmp_gt %if_true %if_false\n"
4799 "%if_true = OpLabel\n"
4800 "%addf1 = OpFAdd %f32 %inval %constf1\n"
4801 " OpStore %outloc %addf1\n"
4802 " OpBranch %if_end\n"
4803 "%if_false = OpLabel\n"
4804 "%subf1 = OpFSub %f32 %inval %constf1\n"
4805 " OpStore %outloc %subf1\n"
4806 " OpBranch %if_end\n"
4807 "%if_end = OpLabel\n"
4809 " OpFunctionEnd\n");
4811 cases.push_back(CaseParameter("none", "None"));
4812 cases.push_back(CaseParameter("flatten", "Flatten"));
4813 cases.push_back(CaseParameter("dont_flatten", "DontFlatten"));
4814 cases.push_back(CaseParameter("flatten_dont_flatten", "DontFlatten|Flatten"));
4816 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats[0], numElements);
4818 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
4819 floorAll(inputFloats);
4821 for (size_t ndx = 0; ndx < numElements; ++ndx)
4822 outputFloats[ndx] = inputFloats[ndx] + (inputFloats[ndx] > 10.f ? 1.f : -1.f);
4824 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
4826 map<string, string> specializations;
4827 ComputeShaderSpec spec;
4829 specializations["CONTROL"] = cases[caseNdx].param;
4830 spec.assembly = shaderTemplate.specialize(specializations);
4831 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
4832 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
4833 spec.numWorkGroups = IVec3(numElements, 1, 1);
4835 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
4838 return group.release();
4841 // Assembly code used for testing function control is based on GLSL source code:
4845 // layout(std140, set = 0, binding = 0) readonly buffer Input {
4846 // float elements[];
4848 // layout(std140, set = 0, binding = 1) writeonly buffer Output {
4849 // float elements[];
4852 // float const10() { return 10.f; }
4855 // uint x = gl_GlobalInvocationID.x;
4856 // output_data.elements[x] = input_data.elements[x] + const10();
4858 tcu::TestCaseGroup* createFunctionControlGroup (tcu::TestContext& testCtx)
4860 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "function_control", "Tests function control cases"));
4861 vector<CaseParameter> cases;
4862 de::Random rnd (deStringHash(group->getName()));
4863 const int numElements = 100;
4864 vector<float> inputFloats (numElements, 0);
4865 vector<float> outputFloats (numElements, 0);
4866 const StringTemplate shaderTemplate (
4867 string(getComputeAsmShaderPreamble()) +
4869 "OpSource GLSL 430\n"
4870 "OpName %main \"main\"\n"
4871 "OpName %func_const10 \"const10(\"\n"
4872 "OpName %id \"gl_GlobalInvocationID\"\n"
4874 "OpDecorate %id BuiltIn GlobalInvocationId\n"
4876 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
4878 "%f32f = OpTypeFunction %f32\n"
4879 "%id = OpVariable %uvec3ptr Input\n"
4880 "%zero = OpConstant %i32 0\n"
4881 "%constf10 = OpConstant %f32 10.0\n"
4883 "%main = OpFunction %void None %voidf\n"
4884 "%entry = OpLabel\n"
4885 "%idval = OpLoad %uvec3 %id\n"
4886 "%x = OpCompositeExtract %u32 %idval 0\n"
4887 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
4888 "%inval = OpLoad %f32 %inloc\n"
4889 "%ret_10 = OpFunctionCall %f32 %func_const10\n"
4890 "%fadd = OpFAdd %f32 %inval %ret_10\n"
4891 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
4892 " OpStore %outloc %fadd\n"
4896 "%func_const10 = OpFunction %f32 ${CONTROL} %f32f\n"
4897 "%label = OpLabel\n"
4898 " OpReturnValue %constf10\n"
4899 " OpFunctionEnd\n");
4901 cases.push_back(CaseParameter("none", "None"));
4902 cases.push_back(CaseParameter("inline", "Inline"));
4903 cases.push_back(CaseParameter("dont_inline", "DontInline"));
4904 cases.push_back(CaseParameter("pure", "Pure"));
4905 cases.push_back(CaseParameter("const", "Const"));
4906 cases.push_back(CaseParameter("inline_pure", "Inline|Pure"));
4907 cases.push_back(CaseParameter("const_dont_inline", "Const|DontInline"));
4908 cases.push_back(CaseParameter("inline_dont_inline", "Inline|DontInline"));
4909 cases.push_back(CaseParameter("pure_inline_dont_inline", "Pure|Inline|DontInline"));
4911 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats[0], numElements);
4913 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
4914 floorAll(inputFloats);
4916 for (size_t ndx = 0; ndx < numElements; ++ndx)
4917 outputFloats[ndx] = inputFloats[ndx] + 10.f;
4919 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
4921 map<string, string> specializations;
4922 ComputeShaderSpec spec;
4924 specializations["CONTROL"] = cases[caseNdx].param;
4925 spec.assembly = shaderTemplate.specialize(specializations);
4926 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
4927 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
4928 spec.numWorkGroups = IVec3(numElements, 1, 1);
4930 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
4933 return group.release();
4936 tcu::TestCaseGroup* createMemoryAccessGroup (tcu::TestContext& testCtx)
4938 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "memory_access", "Tests memory access cases"));
4939 vector<CaseParameter> cases;
4940 de::Random rnd (deStringHash(group->getName()));
4941 const int numElements = 100;
4942 vector<float> inputFloats (numElements, 0);
4943 vector<float> outputFloats (numElements, 0);
4944 const StringTemplate shaderTemplate (
4945 string(getComputeAsmShaderPreamble()) +
4947 "OpSource GLSL 430\n"
4948 "OpName %main \"main\"\n"
4949 "OpName %id \"gl_GlobalInvocationID\"\n"
4951 "OpDecorate %id BuiltIn GlobalInvocationId\n"
4953 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
4955 "%f32ptr_f = OpTypePointer Function %f32\n"
4957 "%id = OpVariable %uvec3ptr Input\n"
4958 "%zero = OpConstant %i32 0\n"
4959 "%four = OpConstant %i32 4\n"
4961 "%main = OpFunction %void None %voidf\n"
4962 "%label = OpLabel\n"
4963 "%copy = OpVariable %f32ptr_f Function\n"
4964 "%idval = OpLoad %uvec3 %id ${ACCESS}\n"
4965 "%x = OpCompositeExtract %u32 %idval 0\n"
4966 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
4967 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
4968 " OpCopyMemory %copy %inloc ${ACCESS}\n"
4969 "%val1 = OpLoad %f32 %copy\n"
4970 "%val2 = OpLoad %f32 %inloc\n"
4971 "%add = OpFAdd %f32 %val1 %val2\n"
4972 " OpStore %outloc %add ${ACCESS}\n"
4974 " OpFunctionEnd\n");
4976 cases.push_back(CaseParameter("null", ""));
4977 cases.push_back(CaseParameter("none", "None"));
4978 cases.push_back(CaseParameter("volatile", "Volatile"));
4979 cases.push_back(CaseParameter("aligned", "Aligned 4"));
4980 cases.push_back(CaseParameter("nontemporal", "Nontemporal"));
4981 cases.push_back(CaseParameter("aligned_nontemporal", "Aligned|Nontemporal 4"));
4982 cases.push_back(CaseParameter("aligned_volatile", "Volatile|Aligned 4"));
4984 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats[0], numElements);
4986 for (size_t ndx = 0; ndx < numElements; ++ndx)
4987 outputFloats[ndx] = inputFloats[ndx] + inputFloats[ndx];
4989 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
4991 map<string, string> specializations;
4992 ComputeShaderSpec spec;
4994 specializations["ACCESS"] = cases[caseNdx].param;
4995 spec.assembly = shaderTemplate.specialize(specializations);
4996 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
4997 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
4998 spec.numWorkGroups = IVec3(numElements, 1, 1);
5000 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
5003 return group.release();
5006 // Checks that we can get undefined values for various types, without exercising a computation with it.
5007 tcu::TestCaseGroup* createOpUndefGroup (tcu::TestContext& testCtx)
5009 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opundef", "Tests the OpUndef instruction"));
5010 vector<CaseParameter> cases;
5011 de::Random rnd (deStringHash(group->getName()));
5012 const int numElements = 100;
5013 vector<float> positiveFloats (numElements, 0);
5014 vector<float> negativeFloats (numElements, 0);
5015 const StringTemplate shaderTemplate (
5016 string(getComputeAsmShaderPreamble()) +
5018 "OpSource GLSL 430\n"
5019 "OpName %main \"main\"\n"
5020 "OpName %id \"gl_GlobalInvocationID\"\n"
5022 "OpDecorate %id BuiltIn GlobalInvocationId\n"
5024 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
5025 "%uvec2 = OpTypeVector %u32 2\n"
5026 "%fvec4 = OpTypeVector %f32 4\n"
5027 "%fmat33 = OpTypeMatrix %fvec3 3\n"
5028 "%image = OpTypeImage %f32 2D 0 0 0 1 Unknown\n"
5029 "%sampler = OpTypeSampler\n"
5030 "%simage = OpTypeSampledImage %image\n"
5031 "%const100 = OpConstant %u32 100\n"
5032 "%uarr100 = OpTypeArray %i32 %const100\n"
5033 "%struct = OpTypeStruct %f32 %i32 %u32\n"
5034 "%pointer = OpTypePointer Function %i32\n"
5035 + string(getComputeAsmInputOutputBuffer()) +
5037 "%id = OpVariable %uvec3ptr Input\n"
5038 "%zero = OpConstant %i32 0\n"
5040 "%main = OpFunction %void None %voidf\n"
5041 "%label = OpLabel\n"
5043 "%undef = OpUndef ${TYPE}\n"
5045 "%idval = OpLoad %uvec3 %id\n"
5046 "%x = OpCompositeExtract %u32 %idval 0\n"
5048 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
5049 "%inval = OpLoad %f32 %inloc\n"
5050 "%neg = OpFNegate %f32 %inval\n"
5051 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
5052 " OpStore %outloc %neg\n"
5054 " OpFunctionEnd\n");
5056 cases.push_back(CaseParameter("bool", "%bool"));
5057 cases.push_back(CaseParameter("sint32", "%i32"));
5058 cases.push_back(CaseParameter("uint32", "%u32"));
5059 cases.push_back(CaseParameter("float32", "%f32"));
5060 cases.push_back(CaseParameter("vec4float32", "%fvec4"));
5061 cases.push_back(CaseParameter("vec2uint32", "%uvec2"));
5062 cases.push_back(CaseParameter("matrix", "%fmat33"));
5063 cases.push_back(CaseParameter("image", "%image"));
5064 cases.push_back(CaseParameter("sampler", "%sampler"));
5065 cases.push_back(CaseParameter("sampledimage", "%simage"));
5066 cases.push_back(CaseParameter("array", "%uarr100"));
5067 cases.push_back(CaseParameter("runtimearray", "%f32arr"));
5068 cases.push_back(CaseParameter("struct", "%struct"));
5069 cases.push_back(CaseParameter("pointer", "%pointer"));
5071 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
5073 for (size_t ndx = 0; ndx < numElements; ++ndx)
5074 negativeFloats[ndx] = -positiveFloats[ndx];
5076 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
5078 map<string, string> specializations;
5079 ComputeShaderSpec spec;
5081 specializations["TYPE"] = cases[caseNdx].param;
5082 spec.assembly = shaderTemplate.specialize(specializations);
5083 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
5084 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
5085 spec.numWorkGroups = IVec3(numElements, 1, 1);
5087 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
5090 return group.release();
5095 tcu::TestCaseGroup* createOpSourceTests (tcu::TestContext& testCtx)
5097 struct NameCodePair { string name, code; };
5098 RGBA defaultColors[4];
5099 de::MovePtr<tcu::TestCaseGroup> opSourceTests (new tcu::TestCaseGroup(testCtx, "opsource", "OpSource instruction"));
5100 const std::string opsourceGLSLWithFile = "%opsrcfile = OpString \"foo.vert\"\nOpSource GLSL 450 %opsrcfile ";
5101 map<string, string> fragments = passthruFragments();
5102 const NameCodePair tests[] =
5104 {"unknown", "OpSource Unknown 321"},
5105 {"essl", "OpSource ESSL 310"},
5106 {"glsl", "OpSource GLSL 450"},
5107 {"opencl_cpp", "OpSource OpenCL_CPP 120"},
5108 {"opencl_c", "OpSource OpenCL_C 120"},
5109 {"multiple", "OpSource GLSL 450\nOpSource GLSL 450"},
5110 {"file", opsourceGLSLWithFile},
5111 {"source", opsourceGLSLWithFile + "\"void main(){}\""},
5112 // Longest possible source string: SPIR-V limits instructions to 65535
5113 // words, of which the first 4 are opsourceGLSLWithFile; the rest will
5114 // contain 65530 UTF8 characters (one word each) plus one last word
5115 // containing 3 ASCII characters and \0.
5116 {"longsource", opsourceGLSLWithFile + '"' + makeLongUTF8String(65530) + "ccc" + '"'}
5119 getDefaultColors(defaultColors);
5120 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameCodePair); ++testNdx)
5122 fragments["debug"] = tests[testNdx].code;
5123 createTestsForAllStages(tests[testNdx].name, defaultColors, defaultColors, fragments, opSourceTests.get());
5126 return opSourceTests.release();
5129 tcu::TestCaseGroup* createOpSourceContinuedTests (tcu::TestContext& testCtx)
5131 struct NameCodePair { string name, code; };
5132 RGBA defaultColors[4];
5133 de::MovePtr<tcu::TestCaseGroup> opSourceTests (new tcu::TestCaseGroup(testCtx, "opsourcecontinued", "OpSourceContinued instruction"));
5134 map<string, string> fragments = passthruFragments();
5135 const std::string opsource = "%opsrcfile = OpString \"foo.vert\"\nOpSource GLSL 450 %opsrcfile \"void main(){}\"\n";
5136 const NameCodePair tests[] =
5138 {"empty", opsource + "OpSourceContinued \"\""},
5139 {"short", opsource + "OpSourceContinued \"abcde\""},
5140 {"multiple", opsource + "OpSourceContinued \"abcde\"\nOpSourceContinued \"fghij\""},
5141 // Longest possible source string: SPIR-V limits instructions to 65535
5142 // words, of which the first one is OpSourceContinued/length; the rest
5143 // will contain 65533 UTF8 characters (one word each) plus one last word
5144 // containing 3 ASCII characters and \0.
5145 {"long", opsource + "OpSourceContinued \"" + makeLongUTF8String(65533) + "ccc\""}
5148 getDefaultColors(defaultColors);
5149 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameCodePair); ++testNdx)
5151 fragments["debug"] = tests[testNdx].code;
5152 createTestsForAllStages(tests[testNdx].name, defaultColors, defaultColors, fragments, opSourceTests.get());
5155 return opSourceTests.release();
5158 tcu::TestCaseGroup* createOpNoLineTests(tcu::TestContext& testCtx)
5160 RGBA defaultColors[4];
5161 de::MovePtr<tcu::TestCaseGroup> opLineTests (new tcu::TestCaseGroup(testCtx, "opnoline", "OpNoLine instruction"));
5162 map<string, string> fragments;
5163 getDefaultColors(defaultColors);
5164 fragments["debug"] =
5165 "%name = OpString \"name\"\n";
5167 fragments["pre_main"] =
5170 "OpLine %name 1 1\n"
5172 "OpLine %name 1 1\n"
5173 "OpLine %name 1 1\n"
5174 "%second_function = OpFunction %v4f32 None %v4f32_function\n"
5176 "OpLine %name 1 1\n"
5178 "OpLine %name 1 1\n"
5179 "OpLine %name 1 1\n"
5180 "%second_param1 = OpFunctionParameter %v4f32\n"
5183 "%label_secondfunction = OpLabel\n"
5185 "OpReturnValue %second_param1\n"
5190 fragments["testfun"] =
5191 // A %test_code function that returns its argument unchanged.
5194 "OpLine %name 1 1\n"
5195 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5197 "%param1 = OpFunctionParameter %v4f32\n"
5200 "%label_testfun = OpLabel\n"
5202 "%val1 = OpFunctionCall %v4f32 %second_function %param1\n"
5203 "OpReturnValue %val1\n"
5205 "OpLine %name 1 1\n"
5208 createTestsForAllStages("opnoline", defaultColors, defaultColors, fragments, opLineTests.get());
5210 return opLineTests.release();
5214 tcu::TestCaseGroup* createOpLineTests(tcu::TestContext& testCtx)
5216 RGBA defaultColors[4];
5217 de::MovePtr<tcu::TestCaseGroup> opLineTests (new tcu::TestCaseGroup(testCtx, "opline", "OpLine instruction"));
5218 map<string, string> fragments;
5219 std::vector<std::pair<std::string, std::string> > problemStrings;
5221 problemStrings.push_back(std::make_pair<std::string, std::string>("empty_name", ""));
5222 problemStrings.push_back(std::make_pair<std::string, std::string>("short_name", "short_name"));
5223 problemStrings.push_back(std::make_pair<std::string, std::string>("long_name", makeLongUTF8String(65530) + "ccc"));
5224 getDefaultColors(defaultColors);
5226 fragments["debug"] =
5227 "%other_name = OpString \"other_name\"\n";
5229 fragments["pre_main"] =
5230 "OpLine %file_name 32 0\n"
5231 "OpLine %file_name 32 32\n"
5232 "OpLine %file_name 32 40\n"
5233 "OpLine %other_name 32 40\n"
5234 "OpLine %other_name 0 100\n"
5235 "OpLine %other_name 0 4294967295\n"
5236 "OpLine %other_name 4294967295 0\n"
5237 "OpLine %other_name 32 40\n"
5238 "OpLine %file_name 0 0\n"
5239 "%second_function = OpFunction %v4f32 None %v4f32_function\n"
5240 "OpLine %file_name 1 0\n"
5241 "%second_param1 = OpFunctionParameter %v4f32\n"
5242 "OpLine %file_name 1 3\n"
5243 "OpLine %file_name 1 2\n"
5244 "%label_secondfunction = OpLabel\n"
5245 "OpLine %file_name 0 2\n"
5246 "OpReturnValue %second_param1\n"
5248 "OpLine %file_name 0 2\n"
5249 "OpLine %file_name 0 2\n";
5251 fragments["testfun"] =
5252 // A %test_code function that returns its argument unchanged.
5253 "OpLine %file_name 1 0\n"
5254 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5255 "OpLine %file_name 16 330\n"
5256 "%param1 = OpFunctionParameter %v4f32\n"
5257 "OpLine %file_name 14 442\n"
5258 "%label_testfun = OpLabel\n"
5259 "OpLine %file_name 11 1024\n"
5260 "%val1 = OpFunctionCall %v4f32 %second_function %param1\n"
5261 "OpLine %file_name 2 97\n"
5262 "OpReturnValue %val1\n"
5264 "OpLine %file_name 5 32\n";
5266 for (size_t i = 0; i < problemStrings.size(); ++i)
5268 map<string, string> testFragments = fragments;
5269 testFragments["debug"] += "%file_name = OpString \"" + problemStrings[i].second + "\"\n";
5270 createTestsForAllStages(string("opline") + "_" + problemStrings[i].first, defaultColors, defaultColors, testFragments, opLineTests.get());
5273 return opLineTests.release();
5276 tcu::TestCaseGroup* createOpConstantNullTests(tcu::TestContext& testCtx)
5278 de::MovePtr<tcu::TestCaseGroup> opConstantNullTests (new tcu::TestCaseGroup(testCtx, "opconstantnull", "OpConstantNull instruction"));
5282 const char functionStart[] =
5283 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5284 "%param1 = OpFunctionParameter %v4f32\n"
5287 const char functionEnd[] =
5288 "OpReturnValue %transformed_param\n"
5291 struct NameConstantsCode
5298 NameConstantsCode tests[] =
5302 "%cnull = OpConstantNull %v4f32\n",
5303 "%transformed_param = OpFAdd %v4f32 %param1 %cnull\n"
5307 "%cnull = OpConstantNull %f32\n",
5308 "%vp = OpVariable %fp_v4f32 Function\n"
5309 "%v = OpLoad %v4f32 %vp\n"
5310 "%v0 = OpVectorInsertDynamic %v4f32 %v %cnull %c_i32_0\n"
5311 "%v1 = OpVectorInsertDynamic %v4f32 %v0 %cnull %c_i32_1\n"
5312 "%v2 = OpVectorInsertDynamic %v4f32 %v1 %cnull %c_i32_2\n"
5313 "%v3 = OpVectorInsertDynamic %v4f32 %v2 %cnull %c_i32_3\n"
5314 "%transformed_param = OpFAdd %v4f32 %param1 %v3\n"
5318 "%cnull = OpConstantNull %bool\n",
5319 "%v = OpVariable %fp_v4f32 Function\n"
5320 " OpStore %v %param1\n"
5321 " OpSelectionMerge %false_label None\n"
5322 " OpBranchConditional %cnull %true_label %false_label\n"
5323 "%true_label = OpLabel\n"
5324 " OpStore %v %c_v4f32_0_5_0_5_0_5_0_5\n"
5325 " OpBranch %false_label\n"
5326 "%false_label = OpLabel\n"
5327 "%transformed_param = OpLoad %v4f32 %v\n"
5331 "%cnull = OpConstantNull %i32\n",
5332 "%v = OpVariable %fp_v4f32 Function %c_v4f32_0_5_0_5_0_5_0_5\n"
5333 "%b = OpIEqual %bool %cnull %c_i32_0\n"
5334 " OpSelectionMerge %false_label None\n"
5335 " OpBranchConditional %b %true_label %false_label\n"
5336 "%true_label = OpLabel\n"
5337 " OpStore %v %param1\n"
5338 " OpBranch %false_label\n"
5339 "%false_label = OpLabel\n"
5340 "%transformed_param = OpLoad %v4f32 %v\n"
5344 "%stype = OpTypeStruct %f32 %v4f32\n"
5345 "%fp_stype = OpTypePointer Function %stype\n"
5346 "%cnull = OpConstantNull %stype\n",
5347 "%v = OpVariable %fp_stype Function %cnull\n"
5348 "%f = OpAccessChain %fp_v4f32 %v %c_i32_1\n"
5349 "%f_val = OpLoad %v4f32 %f\n"
5350 "%transformed_param = OpFAdd %v4f32 %param1 %f_val\n"
5354 "%a4_v4f32 = OpTypeArray %v4f32 %c_u32_4\n"
5355 "%fp_a4_v4f32 = OpTypePointer Function %a4_v4f32\n"
5356 "%cnull = OpConstantNull %a4_v4f32\n",
5357 "%v = OpVariable %fp_a4_v4f32 Function %cnull\n"
5358 "%f = OpAccessChain %fp_v4f32 %v %c_u32_0\n"
5359 "%f1 = OpAccessChain %fp_v4f32 %v %c_u32_1\n"
5360 "%f2 = OpAccessChain %fp_v4f32 %v %c_u32_2\n"
5361 "%f3 = OpAccessChain %fp_v4f32 %v %c_u32_3\n"
5362 "%f_val = OpLoad %v4f32 %f\n"
5363 "%f1_val = OpLoad %v4f32 %f1\n"
5364 "%f2_val = OpLoad %v4f32 %f2\n"
5365 "%f3_val = OpLoad %v4f32 %f3\n"
5366 "%t0 = OpFAdd %v4f32 %param1 %f_val\n"
5367 "%t1 = OpFAdd %v4f32 %t0 %f1_val\n"
5368 "%t2 = OpFAdd %v4f32 %t1 %f2_val\n"
5369 "%transformed_param = OpFAdd %v4f32 %t2 %f3_val\n"
5373 "%mat4x4_f32 = OpTypeMatrix %v4f32 4\n"
5374 "%cnull = OpConstantNull %mat4x4_f32\n",
5375 // Our null matrix * any vector should result in a zero vector.
5376 "%v = OpVectorTimesMatrix %v4f32 %param1 %cnull\n"
5377 "%transformed_param = OpFAdd %v4f32 %param1 %v\n"
5381 getHalfColorsFullAlpha(colors);
5383 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameConstantsCode); ++testNdx)
5385 map<string, string> fragments;
5386 fragments["pre_main"] = tests[testNdx].constants;
5387 fragments["testfun"] = string(functionStart) + tests[testNdx].code + functionEnd;
5388 createTestsForAllStages(tests[testNdx].name, colors, colors, fragments, opConstantNullTests.get());
5390 return opConstantNullTests.release();
5392 tcu::TestCaseGroup* createOpConstantCompositeTests(tcu::TestContext& testCtx)
5394 de::MovePtr<tcu::TestCaseGroup> opConstantCompositeTests (new tcu::TestCaseGroup(testCtx, "opconstantcomposite", "OpConstantComposite instruction"));
5395 RGBA inputColors[4];
5396 RGBA outputColors[4];
5399 const char functionStart[] =
5400 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5401 "%param1 = OpFunctionParameter %v4f32\n"
5404 const char functionEnd[] =
5405 "OpReturnValue %transformed_param\n"
5408 struct NameConstantsCode
5415 NameConstantsCode tests[] =
5420 "%cval = OpConstantComposite %v4f32 %c_f32_0_5 %c_f32_0_5 %c_f32_0_5 %c_f32_0\n",
5421 "%transformed_param = OpFAdd %v4f32 %param1 %cval\n"
5426 "%stype = OpTypeStruct %v4f32 %f32\n"
5427 "%fp_stype = OpTypePointer Function %stype\n"
5428 "%f32_n_1 = OpConstant %f32 -1.0\n"
5429 "%f32_1_5 = OpConstant %f32 !0x3fc00000\n" // +1.5
5430 "%cvec = OpConstantComposite %v4f32 %f32_1_5 %f32_1_5 %f32_1_5 %c_f32_1\n"
5431 "%cval = OpConstantComposite %stype %cvec %f32_n_1\n",
5433 "%v = OpVariable %fp_stype Function %cval\n"
5434 "%vec_ptr = OpAccessChain %fp_v4f32 %v %c_u32_0\n"
5435 "%f32_ptr = OpAccessChain %fp_f32 %v %c_u32_1\n"
5436 "%vec_val = OpLoad %v4f32 %vec_ptr\n"
5437 "%f32_val = OpLoad %f32 %f32_ptr\n"
5438 "%tmp1 = OpVectorTimesScalar %v4f32 %c_v4f32_1_1_1_1 %f32_val\n" // vec4(-1)
5439 "%tmp2 = OpFAdd %v4f32 %tmp1 %param1\n" // param1 + vec4(-1)
5440 "%transformed_param = OpFAdd %v4f32 %tmp2 %vec_val\n" // param1 + vec4(-1) + vec4(1.5, 1.5, 1.5, 1.0)
5443 // [1|0|0|0.5] [x] = x + 0.5
5444 // [0|1|0|0.5] [y] = y + 0.5
5445 // [0|0|1|0.5] [z] = z + 0.5
5446 // [0|0|0|1 ] [1] = 1
5449 "%mat4x4_f32 = OpTypeMatrix %v4f32 4\n"
5450 "%v4f32_1_0_0_0 = OpConstantComposite %v4f32 %c_f32_1 %c_f32_0 %c_f32_0 %c_f32_0\n"
5451 "%v4f32_0_1_0_0 = OpConstantComposite %v4f32 %c_f32_0 %c_f32_1 %c_f32_0 %c_f32_0\n"
5452 "%v4f32_0_0_1_0 = OpConstantComposite %v4f32 %c_f32_0 %c_f32_0 %c_f32_1 %c_f32_0\n"
5453 "%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"
5454 "%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",
5456 "%transformed_param = OpMatrixTimesVector %v4f32 %cval %param1\n"
5461 "%c_v4f32_1_1_1_0 = OpConstantComposite %v4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_0\n"
5462 "%fp_a4f32 = OpTypePointer Function %a4f32\n"
5463 "%f32_n_1 = OpConstant %f32 -1.0\n"
5464 "%f32_1_5 = OpConstant %f32 !0x3fc00000\n" // +1.5
5465 "%carr = OpConstantComposite %a4f32 %c_f32_0 %f32_n_1 %f32_1_5 %c_f32_0\n",
5467 "%v = OpVariable %fp_a4f32 Function %carr\n"
5468 "%f = OpAccessChain %fp_f32 %v %c_u32_0\n"
5469 "%f1 = OpAccessChain %fp_f32 %v %c_u32_1\n"
5470 "%f2 = OpAccessChain %fp_f32 %v %c_u32_2\n"
5471 "%f3 = OpAccessChain %fp_f32 %v %c_u32_3\n"
5472 "%f_val = OpLoad %f32 %f\n"
5473 "%f1_val = OpLoad %f32 %f1\n"
5474 "%f2_val = OpLoad %f32 %f2\n"
5475 "%f3_val = OpLoad %f32 %f3\n"
5476 "%ftot1 = OpFAdd %f32 %f_val %f1_val\n"
5477 "%ftot2 = OpFAdd %f32 %ftot1 %f2_val\n"
5478 "%ftot3 = OpFAdd %f32 %ftot2 %f3_val\n" // 0 - 1 + 1.5 + 0
5479 "%add_vec = OpVectorTimesScalar %v4f32 %c_v4f32_1_1_1_0 %ftot3\n"
5480 "%transformed_param = OpFAdd %v4f32 %param1 %add_vec\n"
5487 // [ 1.0, 1.0, 1.0, 1.0]
5491 // [ 0.0, 0.5, 0.0, 0.0]
5495 // [ 1.0, 1.0, 1.0, 1.0]
5498 "array_of_struct_of_array",
5500 "%c_v4f32_1_1_1_0 = OpConstantComposite %v4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_0\n"
5501 "%fp_a4f32 = OpTypePointer Function %a4f32\n"
5502 "%stype = OpTypeStruct %f32 %a4f32\n"
5503 "%a3stype = OpTypeArray %stype %c_u32_3\n"
5504 "%fp_a3stype = OpTypePointer Function %a3stype\n"
5505 "%ca4f32_0 = OpConstantComposite %a4f32 %c_f32_0 %c_f32_0_5 %c_f32_0 %c_f32_0\n"
5506 "%ca4f32_1 = OpConstantComposite %a4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_1\n"
5507 "%cstype1 = OpConstantComposite %stype %c_f32_0 %ca4f32_1\n"
5508 "%cstype2 = OpConstantComposite %stype %c_f32_1 %ca4f32_0\n"
5509 "%carr = OpConstantComposite %a3stype %cstype1 %cstype2 %cstype1",
5511 "%v = OpVariable %fp_a3stype Function %carr\n"
5512 "%f = OpAccessChain %fp_f32 %v %c_u32_1 %c_u32_1 %c_u32_1\n"
5513 "%f_l = OpLoad %f32 %f\n"
5514 "%add_vec = OpVectorTimesScalar %v4f32 %c_v4f32_1_1_1_0 %f_l\n"
5515 "%transformed_param = OpFAdd %v4f32 %param1 %add_vec\n"
5519 getHalfColorsFullAlpha(inputColors);
5520 outputColors[0] = RGBA(255, 255, 255, 255);
5521 outputColors[1] = RGBA(255, 127, 127, 255);
5522 outputColors[2] = RGBA(127, 255, 127, 255);
5523 outputColors[3] = RGBA(127, 127, 255, 255);
5525 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameConstantsCode); ++testNdx)
5527 map<string, string> fragments;
5528 fragments["pre_main"] = tests[testNdx].constants;
5529 fragments["testfun"] = string(functionStart) + tests[testNdx].code + functionEnd;
5530 createTestsForAllStages(tests[testNdx].name, inputColors, outputColors, fragments, opConstantCompositeTests.get());
5532 return opConstantCompositeTests.release();
5535 tcu::TestCaseGroup* createSelectionBlockOrderTests(tcu::TestContext& testCtx)
5537 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "selection_block_order", "Out-of-order blocks for selection"));
5538 RGBA inputColors[4];
5539 RGBA outputColors[4];
5540 map<string, string> fragments;
5542 // vec4 test_code(vec4 param) {
5543 // vec4 result = param;
5544 // for (int i = 0; i < 4; ++i) {
5545 // if (i == 0) result[i] = 0.;
5546 // else result[i] = 1. - result[i];
5550 const char function[] =
5551 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5552 "%param1 = OpFunctionParameter %v4f32\n"
5554 "%iptr = OpVariable %fp_i32 Function\n"
5555 "%result = OpVariable %fp_v4f32 Function\n"
5556 " OpStore %iptr %c_i32_0\n"
5557 " OpStore %result %param1\n"
5560 // Loop entry block.
5562 "%ival = OpLoad %i32 %iptr\n"
5563 "%lt_4 = OpSLessThan %bool %ival %c_i32_4\n"
5564 " OpLoopMerge %exit %if_entry None\n"
5565 " OpBranchConditional %lt_4 %if_entry %exit\n"
5567 // Merge block for loop.
5569 "%ret = OpLoad %v4f32 %result\n"
5570 " OpReturnValue %ret\n"
5572 // If-statement entry block.
5573 "%if_entry = OpLabel\n"
5574 "%loc = OpAccessChain %fp_f32 %result %ival\n"
5575 "%eq_0 = OpIEqual %bool %ival %c_i32_0\n"
5576 " OpSelectionMerge %if_exit None\n"
5577 " OpBranchConditional %eq_0 %if_true %if_false\n"
5579 // False branch for if-statement.
5580 "%if_false = OpLabel\n"
5581 "%val = OpLoad %f32 %loc\n"
5582 "%sub = OpFSub %f32 %c_f32_1 %val\n"
5583 " OpStore %loc %sub\n"
5584 " OpBranch %if_exit\n"
5586 // Merge block for if-statement.
5587 "%if_exit = OpLabel\n"
5588 "%ival_next = OpIAdd %i32 %ival %c_i32_1\n"
5589 " OpStore %iptr %ival_next\n"
5592 // True branch for if-statement.
5593 "%if_true = OpLabel\n"
5594 " OpStore %loc %c_f32_0\n"
5595 " OpBranch %if_exit\n"
5599 fragments["testfun"] = function;
5601 inputColors[0] = RGBA(127, 127, 127, 0);
5602 inputColors[1] = RGBA(127, 0, 0, 0);
5603 inputColors[2] = RGBA(0, 127, 0, 0);
5604 inputColors[3] = RGBA(0, 0, 127, 0);
5606 outputColors[0] = RGBA(0, 128, 128, 255);
5607 outputColors[1] = RGBA(0, 255, 255, 255);
5608 outputColors[2] = RGBA(0, 128, 255, 255);
5609 outputColors[3] = RGBA(0, 255, 128, 255);
5611 createTestsForAllStages("out_of_order", inputColors, outputColors, fragments, group.get());
5613 return group.release();
5616 tcu::TestCaseGroup* createSwitchBlockOrderTests(tcu::TestContext& testCtx)
5618 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "switch_block_order", "Out-of-order blocks for switch"));
5619 RGBA inputColors[4];
5620 RGBA outputColors[4];
5621 map<string, string> fragments;
5623 const char typesAndConstants[] =
5624 "%c_f32_p2 = OpConstant %f32 0.2\n"
5625 "%c_f32_p4 = OpConstant %f32 0.4\n"
5626 "%c_f32_p6 = OpConstant %f32 0.6\n"
5627 "%c_f32_p8 = OpConstant %f32 0.8\n";
5629 // vec4 test_code(vec4 param) {
5630 // vec4 result = param;
5631 // for (int i = 0; i < 4; ++i) {
5633 // case 0: result[i] += .2; break;
5634 // case 1: result[i] += .6; break;
5635 // case 2: result[i] += .4; break;
5636 // case 3: result[i] += .8; break;
5637 // default: break; // unreachable
5642 const char function[] =
5643 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5644 "%param1 = OpFunctionParameter %v4f32\n"
5646 "%iptr = OpVariable %fp_i32 Function\n"
5647 "%result = OpVariable %fp_v4f32 Function\n"
5648 " OpStore %iptr %c_i32_0\n"
5649 " OpStore %result %param1\n"
5652 // Loop entry block.
5654 "%ival = OpLoad %i32 %iptr\n"
5655 "%lt_4 = OpSLessThan %bool %ival %c_i32_4\n"
5656 " OpLoopMerge %exit %switch_exit None\n"
5657 " OpBranchConditional %lt_4 %switch_entry %exit\n"
5659 // Merge block for loop.
5661 "%ret = OpLoad %v4f32 %result\n"
5662 " OpReturnValue %ret\n"
5664 // Switch-statement entry block.
5665 "%switch_entry = OpLabel\n"
5666 "%loc = OpAccessChain %fp_f32 %result %ival\n"
5667 "%val = OpLoad %f32 %loc\n"
5668 " OpSelectionMerge %switch_exit None\n"
5669 " OpSwitch %ival %switch_default 0 %case0 1 %case1 2 %case2 3 %case3\n"
5671 "%case2 = OpLabel\n"
5672 "%addp4 = OpFAdd %f32 %val %c_f32_p4\n"
5673 " OpStore %loc %addp4\n"
5674 " OpBranch %switch_exit\n"
5676 "%switch_default = OpLabel\n"
5679 "%case3 = OpLabel\n"
5680 "%addp8 = OpFAdd %f32 %val %c_f32_p8\n"
5681 " OpStore %loc %addp8\n"
5682 " OpBranch %switch_exit\n"
5684 "%case0 = OpLabel\n"
5685 "%addp2 = OpFAdd %f32 %val %c_f32_p2\n"
5686 " OpStore %loc %addp2\n"
5687 " OpBranch %switch_exit\n"
5689 // Merge block for switch-statement.
5690 "%switch_exit = OpLabel\n"
5691 "%ival_next = OpIAdd %i32 %ival %c_i32_1\n"
5692 " OpStore %iptr %ival_next\n"
5695 "%case1 = OpLabel\n"
5696 "%addp6 = OpFAdd %f32 %val %c_f32_p6\n"
5697 " OpStore %loc %addp6\n"
5698 " OpBranch %switch_exit\n"
5702 fragments["pre_main"] = typesAndConstants;
5703 fragments["testfun"] = function;
5705 inputColors[0] = RGBA(127, 27, 127, 51);
5706 inputColors[1] = RGBA(127, 0, 0, 51);
5707 inputColors[2] = RGBA(0, 27, 0, 51);
5708 inputColors[3] = RGBA(0, 0, 127, 51);
5710 outputColors[0] = RGBA(178, 180, 229, 255);
5711 outputColors[1] = RGBA(178, 153, 102, 255);
5712 outputColors[2] = RGBA(51, 180, 102, 255);
5713 outputColors[3] = RGBA(51, 153, 229, 255);
5715 createTestsForAllStages("out_of_order", inputColors, outputColors, fragments, group.get());
5717 return group.release();
5720 tcu::TestCaseGroup* createDecorationGroupTests(tcu::TestContext& testCtx)
5722 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "decoration_group", "Decoration group tests"));
5723 RGBA inputColors[4];
5724 RGBA outputColors[4];
5725 map<string, string> fragments;
5727 const char decorations[] =
5728 "OpDecorate %array_group ArrayStride 4\n"
5729 "OpDecorate %struct_member_group Offset 0\n"
5730 "%array_group = OpDecorationGroup\n"
5731 "%struct_member_group = OpDecorationGroup\n"
5733 "OpDecorate %group1 RelaxedPrecision\n"
5734 "OpDecorate %group3 RelaxedPrecision\n"
5735 "OpDecorate %group3 Invariant\n"
5736 "OpDecorate %group3 Restrict\n"
5737 "%group0 = OpDecorationGroup\n"
5738 "%group1 = OpDecorationGroup\n"
5739 "%group3 = OpDecorationGroup\n";
5741 const char typesAndConstants[] =
5742 "%a3f32 = OpTypeArray %f32 %c_u32_3\n"
5743 "%struct1 = OpTypeStruct %a3f32\n"
5744 "%struct2 = OpTypeStruct %a3f32\n"
5745 "%fp_struct1 = OpTypePointer Function %struct1\n"
5746 "%fp_struct2 = OpTypePointer Function %struct2\n"
5747 "%c_f32_2 = OpConstant %f32 2.\n"
5748 "%c_f32_n2 = OpConstant %f32 -2.\n"
5750 "%c_a3f32_1 = OpConstantComposite %a3f32 %c_f32_1 %c_f32_2 %c_f32_1\n"
5751 "%c_a3f32_2 = OpConstantComposite %a3f32 %c_f32_n1 %c_f32_n2 %c_f32_n1\n"
5752 "%c_struct1 = OpConstantComposite %struct1 %c_a3f32_1\n"
5753 "%c_struct2 = OpConstantComposite %struct2 %c_a3f32_2\n";
5755 const char function[] =
5756 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5757 "%param = OpFunctionParameter %v4f32\n"
5758 "%entry = OpLabel\n"
5759 "%result = OpVariable %fp_v4f32 Function\n"
5760 "%v_struct1 = OpVariable %fp_struct1 Function\n"
5761 "%v_struct2 = OpVariable %fp_struct2 Function\n"
5762 " OpStore %result %param\n"
5763 " OpStore %v_struct1 %c_struct1\n"
5764 " OpStore %v_struct2 %c_struct2\n"
5765 "%ptr1 = OpAccessChain %fp_f32 %v_struct1 %c_i32_0 %c_i32_2\n"
5766 "%val1 = OpLoad %f32 %ptr1\n"
5767 "%ptr2 = OpAccessChain %fp_f32 %v_struct2 %c_i32_0 %c_i32_2\n"
5768 "%val2 = OpLoad %f32 %ptr2\n"
5769 "%addvalues = OpFAdd %f32 %val1 %val2\n"
5770 "%ptr = OpAccessChain %fp_f32 %result %c_i32_1\n"
5771 "%val = OpLoad %f32 %ptr\n"
5772 "%addresult = OpFAdd %f32 %addvalues %val\n"
5773 " OpStore %ptr %addresult\n"
5774 "%ret = OpLoad %v4f32 %result\n"
5775 " OpReturnValue %ret\n"
5778 struct CaseNameDecoration
5784 CaseNameDecoration tests[] =
5787 "same_decoration_group_on_multiple_types",
5788 "OpGroupMemberDecorate %struct_member_group %struct1 0 %struct2 0\n"
5791 "empty_decoration_group",
5792 "OpGroupDecorate %group0 %a3f32\n"
5793 "OpGroupDecorate %group0 %result\n"
5796 "one_element_decoration_group",
5797 "OpGroupDecorate %array_group %a3f32\n"
5800 "multiple_elements_decoration_group",
5801 "OpGroupDecorate %group3 %v_struct1\n"
5804 "multiple_decoration_groups_on_same_variable",
5805 "OpGroupDecorate %group0 %v_struct2\n"
5806 "OpGroupDecorate %group1 %v_struct2\n"
5807 "OpGroupDecorate %group3 %v_struct2\n"
5810 "same_decoration_group_multiple_times",
5811 "OpGroupDecorate %group1 %addvalues\n"
5812 "OpGroupDecorate %group1 %addvalues\n"
5813 "OpGroupDecorate %group1 %addvalues\n"
5818 getHalfColorsFullAlpha(inputColors);
5819 getHalfColorsFullAlpha(outputColors);
5821 for (size_t idx = 0; idx < (sizeof(tests) / sizeof(tests[0])); ++idx)
5823 fragments["decoration"] = decorations + tests[idx].decoration;
5824 fragments["pre_main"] = typesAndConstants;
5825 fragments["testfun"] = function;
5827 createTestsForAllStages(tests[idx].name, inputColors, outputColors, fragments, group.get());
5830 return group.release();
5833 struct SpecConstantTwoIntGraphicsCase
5835 const char* caseName;
5836 const char* scDefinition0;
5837 const char* scDefinition1;
5838 const char* scResultType;
5839 const char* scOperation;
5840 deInt32 scActualValue0;
5841 deInt32 scActualValue1;
5842 const char* resultOperation;
5843 RGBA expectedColors[4];
5845 SpecConstantTwoIntGraphicsCase (const char* name,
5846 const char* definition0,
5847 const char* definition1,
5848 const char* resultType,
5849 const char* operation,
5852 const char* resultOp,
5853 const RGBA (&output)[4])
5855 , scDefinition0 (definition0)
5856 , scDefinition1 (definition1)
5857 , scResultType (resultType)
5858 , scOperation (operation)
5859 , scActualValue0 (value0)
5860 , scActualValue1 (value1)
5861 , resultOperation (resultOp)
5863 expectedColors[0] = output[0];
5864 expectedColors[1] = output[1];
5865 expectedColors[2] = output[2];
5866 expectedColors[3] = output[3];
5870 tcu::TestCaseGroup* createSpecConstantTests (tcu::TestContext& testCtx)
5872 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opspecconstantop", "Test the OpSpecConstantOp instruction"));
5873 vector<SpecConstantTwoIntGraphicsCase> cases;
5874 RGBA inputColors[4];
5875 RGBA outputColors0[4];
5876 RGBA outputColors1[4];
5877 RGBA outputColors2[4];
5879 const char decorations1[] =
5880 "OpDecorate %sc_0 SpecId 0\n"
5881 "OpDecorate %sc_1 SpecId 1\n";
5883 const char typesAndConstants1[] =
5884 "%sc_0 = OpSpecConstant${SC_DEF0}\n"
5885 "%sc_1 = OpSpecConstant${SC_DEF1}\n"
5886 "%sc_op = OpSpecConstantOp ${SC_RESULT_TYPE} ${SC_OP}\n";
5888 const char function1[] =
5889 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5890 "%param = OpFunctionParameter %v4f32\n"
5891 "%label = OpLabel\n"
5892 "%result = OpVariable %fp_v4f32 Function\n"
5893 " OpStore %result %param\n"
5894 "%gen = ${GEN_RESULT}\n"
5895 "%index = OpIAdd %i32 %gen %c_i32_1\n"
5896 "%loc = OpAccessChain %fp_f32 %result %index\n"
5897 "%val = OpLoad %f32 %loc\n"
5898 "%add = OpFAdd %f32 %val %c_f32_0_5\n"
5899 " OpStore %loc %add\n"
5900 "%ret = OpLoad %v4f32 %result\n"
5901 " OpReturnValue %ret\n"
5904 inputColors[0] = RGBA(127, 127, 127, 255);
5905 inputColors[1] = RGBA(127, 0, 0, 255);
5906 inputColors[2] = RGBA(0, 127, 0, 255);
5907 inputColors[3] = RGBA(0, 0, 127, 255);
5909 // Derived from inputColors[x] by adding 128 to inputColors[x][0].
5910 outputColors0[0] = RGBA(255, 127, 127, 255);
5911 outputColors0[1] = RGBA(255, 0, 0, 255);
5912 outputColors0[2] = RGBA(128, 127, 0, 255);
5913 outputColors0[3] = RGBA(128, 0, 127, 255);
5915 // Derived from inputColors[x] by adding 128 to inputColors[x][1].
5916 outputColors1[0] = RGBA(127, 255, 127, 255);
5917 outputColors1[1] = RGBA(127, 128, 0, 255);
5918 outputColors1[2] = RGBA(0, 255, 0, 255);
5919 outputColors1[3] = RGBA(0, 128, 127, 255);
5921 // Derived from inputColors[x] by adding 128 to inputColors[x][2].
5922 outputColors2[0] = RGBA(127, 127, 255, 255);
5923 outputColors2[1] = RGBA(127, 0, 128, 255);
5924 outputColors2[2] = RGBA(0, 127, 128, 255);
5925 outputColors2[3] = RGBA(0, 0, 255, 255);
5927 const char addZeroToSc[] = "OpIAdd %i32 %c_i32_0 %sc_op";
5928 const char selectTrueUsingSc[] = "OpSelect %i32 %sc_op %c_i32_1 %c_i32_0";
5929 const char selectFalseUsingSc[] = "OpSelect %i32 %sc_op %c_i32_0 %c_i32_1";
5931 cases.push_back(SpecConstantTwoIntGraphicsCase("iadd", " %i32 0", " %i32 0", "%i32", "IAdd %sc_0 %sc_1", 19, -20, addZeroToSc, outputColors0));
5932 cases.push_back(SpecConstantTwoIntGraphicsCase("isub", " %i32 0", " %i32 0", "%i32", "ISub %sc_0 %sc_1", 19, 20, addZeroToSc, outputColors0));
5933 cases.push_back(SpecConstantTwoIntGraphicsCase("imul", " %i32 0", " %i32 0", "%i32", "IMul %sc_0 %sc_1", -1, -1, addZeroToSc, outputColors2));
5934 cases.push_back(SpecConstantTwoIntGraphicsCase("sdiv", " %i32 0", " %i32 0", "%i32", "SDiv %sc_0 %sc_1", -126, 126, addZeroToSc, outputColors0));
5935 cases.push_back(SpecConstantTwoIntGraphicsCase("udiv", " %i32 0", " %i32 0", "%i32", "UDiv %sc_0 %sc_1", 126, 126, addZeroToSc, outputColors2));
5936 cases.push_back(SpecConstantTwoIntGraphicsCase("srem", " %i32 0", " %i32 0", "%i32", "SRem %sc_0 %sc_1", 3, 2, addZeroToSc, outputColors2));
5937 cases.push_back(SpecConstantTwoIntGraphicsCase("smod", " %i32 0", " %i32 0", "%i32", "SMod %sc_0 %sc_1", 3, 2, addZeroToSc, outputColors2));
5938 cases.push_back(SpecConstantTwoIntGraphicsCase("umod", " %i32 0", " %i32 0", "%i32", "UMod %sc_0 %sc_1", 1001, 500, addZeroToSc, outputColors2));
5939 cases.push_back(SpecConstantTwoIntGraphicsCase("bitwiseand", " %i32 0", " %i32 0", "%i32", "BitwiseAnd %sc_0 %sc_1", 0x33, 0x0d, addZeroToSc, outputColors2));
5940 cases.push_back(SpecConstantTwoIntGraphicsCase("bitwiseor", " %i32 0", " %i32 0", "%i32", "BitwiseOr %sc_0 %sc_1", 0, 1, addZeroToSc, outputColors2));
5941 cases.push_back(SpecConstantTwoIntGraphicsCase("bitwisexor", " %i32 0", " %i32 0", "%i32", "BitwiseXor %sc_0 %sc_1", 0x2e, 0x2f, addZeroToSc, outputColors2));
5942 cases.push_back(SpecConstantTwoIntGraphicsCase("shiftrightlogical", " %i32 0", " %i32 0", "%i32", "ShiftRightLogical %sc_0 %sc_1", 2, 1, addZeroToSc, outputColors2));
5943 cases.push_back(SpecConstantTwoIntGraphicsCase("shiftrightarithmetic", " %i32 0", " %i32 0", "%i32", "ShiftRightArithmetic %sc_0 %sc_1", -4, 2, addZeroToSc, outputColors0));
5944 cases.push_back(SpecConstantTwoIntGraphicsCase("shiftleftlogical", " %i32 0", " %i32 0", "%i32", "ShiftLeftLogical %sc_0 %sc_1", 1, 0, addZeroToSc, outputColors2));
5945 cases.push_back(SpecConstantTwoIntGraphicsCase("slessthan", " %i32 0", " %i32 0", "%bool", "SLessThan %sc_0 %sc_1", -20, -10, selectTrueUsingSc, outputColors2));
5946 cases.push_back(SpecConstantTwoIntGraphicsCase("ulessthan", " %i32 0", " %i32 0", "%bool", "ULessThan %sc_0 %sc_1", 10, 20, selectTrueUsingSc, outputColors2));
5947 cases.push_back(SpecConstantTwoIntGraphicsCase("sgreaterthan", " %i32 0", " %i32 0", "%bool", "SGreaterThan %sc_0 %sc_1", -1000, 50, selectFalseUsingSc, outputColors2));
5948 cases.push_back(SpecConstantTwoIntGraphicsCase("ugreaterthan", " %i32 0", " %i32 0", "%bool", "UGreaterThan %sc_0 %sc_1", 10, 5, selectTrueUsingSc, outputColors2));
5949 cases.push_back(SpecConstantTwoIntGraphicsCase("slessthanequal", " %i32 0", " %i32 0", "%bool", "SLessThanEqual %sc_0 %sc_1", -10, -10, selectTrueUsingSc, outputColors2));
5950 cases.push_back(SpecConstantTwoIntGraphicsCase("ulessthanequal", " %i32 0", " %i32 0", "%bool", "ULessThanEqual %sc_0 %sc_1", 50, 100, selectTrueUsingSc, outputColors2));
5951 cases.push_back(SpecConstantTwoIntGraphicsCase("sgreaterthanequal", " %i32 0", " %i32 0", "%bool", "SGreaterThanEqual %sc_0 %sc_1", -1000, 50, selectFalseUsingSc, outputColors2));
5952 cases.push_back(SpecConstantTwoIntGraphicsCase("ugreaterthanequal", " %i32 0", " %i32 0", "%bool", "UGreaterThanEqual %sc_0 %sc_1", 10, 10, selectTrueUsingSc, outputColors2));
5953 cases.push_back(SpecConstantTwoIntGraphicsCase("iequal", " %i32 0", " %i32 0", "%bool", "IEqual %sc_0 %sc_1", 42, 24, selectFalseUsingSc, outputColors2));
5954 cases.push_back(SpecConstantTwoIntGraphicsCase("logicaland", "True %bool", "True %bool", "%bool", "LogicalAnd %sc_0 %sc_1", 0, 1, selectFalseUsingSc, outputColors2));
5955 cases.push_back(SpecConstantTwoIntGraphicsCase("logicalor", "False %bool", "False %bool", "%bool", "LogicalOr %sc_0 %sc_1", 1, 0, selectTrueUsingSc, outputColors2));
5956 cases.push_back(SpecConstantTwoIntGraphicsCase("logicalequal", "True %bool", "True %bool", "%bool", "LogicalEqual %sc_0 %sc_1", 0, 1, selectFalseUsingSc, outputColors2));
5957 cases.push_back(SpecConstantTwoIntGraphicsCase("logicalnotequal", "False %bool", "False %bool", "%bool", "LogicalNotEqual %sc_0 %sc_1", 1, 0, selectTrueUsingSc, outputColors2));
5958 cases.push_back(SpecConstantTwoIntGraphicsCase("snegate", " %i32 0", " %i32 0", "%i32", "SNegate %sc_0", -1, 0, addZeroToSc, outputColors2));
5959 cases.push_back(SpecConstantTwoIntGraphicsCase("not", " %i32 0", " %i32 0", "%i32", "Not %sc_0", -2, 0, addZeroToSc, outputColors2));
5960 cases.push_back(SpecConstantTwoIntGraphicsCase("logicalnot", "False %bool", "False %bool", "%bool", "LogicalNot %sc_0", 1, 0, selectFalseUsingSc, outputColors2));
5961 cases.push_back(SpecConstantTwoIntGraphicsCase("select", "False %bool", " %i32 0", "%i32", "Select %sc_0 %sc_1 %c_i32_0", 1, 1, addZeroToSc, outputColors2));
5962 // OpSConvert, OpFConvert: these two instructions involve ints/floats of different bitwidths.
5963 // \todo[2015-12-1 antiagainst] OpQuantizeToF16
5965 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
5967 map<string, string> specializations;
5968 map<string, string> fragments;
5969 vector<deInt32> specConstants;
5971 specializations["SC_DEF0"] = cases[caseNdx].scDefinition0;
5972 specializations["SC_DEF1"] = cases[caseNdx].scDefinition1;
5973 specializations["SC_RESULT_TYPE"] = cases[caseNdx].scResultType;
5974 specializations["SC_OP"] = cases[caseNdx].scOperation;
5975 specializations["GEN_RESULT"] = cases[caseNdx].resultOperation;
5977 fragments["decoration"] = tcu::StringTemplate(decorations1).specialize(specializations);
5978 fragments["pre_main"] = tcu::StringTemplate(typesAndConstants1).specialize(specializations);
5979 fragments["testfun"] = tcu::StringTemplate(function1).specialize(specializations);
5981 specConstants.push_back(cases[caseNdx].scActualValue0);
5982 specConstants.push_back(cases[caseNdx].scActualValue1);
5984 createTestsForAllStages(cases[caseNdx].caseName, inputColors, cases[caseNdx].expectedColors, fragments, specConstants, group.get());
5987 const char decorations2[] =
5988 "OpDecorate %sc_0 SpecId 0\n"
5989 "OpDecorate %sc_1 SpecId 1\n"
5990 "OpDecorate %sc_2 SpecId 2\n";
5992 const char typesAndConstants2[] =
5993 "%v3i32 = OpTypeVector %i32 3\n"
5994 "%vec3_0 = OpConstantComposite %v3i32 %c_i32_0 %c_i32_0 %c_i32_0\n"
5995 "%vec3_undef = OpUndef %v3i32\n"
5997 "%sc_0 = OpSpecConstant %i32 0\n"
5998 "%sc_1 = OpSpecConstant %i32 0\n"
5999 "%sc_2 = OpSpecConstant %i32 0\n"
6000 "%sc_vec3_0 = OpSpecConstantOp %v3i32 CompositeInsert %sc_0 %vec3_0 0\n" // (sc_0, 0, 0)
6001 "%sc_vec3_1 = OpSpecConstantOp %v3i32 CompositeInsert %sc_1 %vec3_0 1\n" // (0, sc_1, 0)
6002 "%sc_vec3_2 = OpSpecConstantOp %v3i32 CompositeInsert %sc_2 %vec3_0 2\n" // (0, 0, sc_2)
6003 "%sc_vec3_0_s = OpSpecConstantOp %v3i32 VectorShuffle %sc_vec3_0 %vec3_undef 0 0xFFFFFFFF 2\n" // (sc_0, ???, 0)
6004 "%sc_vec3_1_s = OpSpecConstantOp %v3i32 VectorShuffle %sc_vec3_1 %vec3_undef 0xFFFFFFFF 1 0\n" // (???, sc_1, 0)
6005 "%sc_vec3_2_s = OpSpecConstantOp %v3i32 VectorShuffle %vec3_undef %sc_vec3_2 5 0xFFFFFFFF 5\n" // (sc_2, ???, sc_2)
6006 "%sc_vec3_01 = OpSpecConstantOp %v3i32 VectorShuffle %sc_vec3_0_s %sc_vec3_1_s 1 0 4\n" // (0, sc_0, sc_1)
6007 "%sc_vec3_012 = OpSpecConstantOp %v3i32 VectorShuffle %sc_vec3_01 %sc_vec3_2_s 5 1 2\n" // (sc_2, sc_0, sc_1)
6008 "%sc_ext_0 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 0\n" // sc_2
6009 "%sc_ext_1 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 1\n" // sc_0
6010 "%sc_ext_2 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 2\n" // sc_1
6011 "%sc_sub = OpSpecConstantOp %i32 ISub %sc_ext_0 %sc_ext_1\n" // (sc_2 - sc_0)
6012 "%sc_final = OpSpecConstantOp %i32 IMul %sc_sub %sc_ext_2\n"; // (sc_2 - sc_0) * sc_1
6014 const char function2[] =
6015 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6016 "%param = OpFunctionParameter %v4f32\n"
6017 "%label = OpLabel\n"
6018 "%result = OpVariable %fp_v4f32 Function\n"
6019 " OpStore %result %param\n"
6020 "%loc = OpAccessChain %fp_f32 %result %sc_final\n"
6021 "%val = OpLoad %f32 %loc\n"
6022 "%add = OpFAdd %f32 %val %c_f32_0_5\n"
6023 " OpStore %loc %add\n"
6024 "%ret = OpLoad %v4f32 %result\n"
6025 " OpReturnValue %ret\n"
6028 map<string, string> fragments;
6029 vector<deInt32> specConstants;
6031 fragments["decoration"] = decorations2;
6032 fragments["pre_main"] = typesAndConstants2;
6033 fragments["testfun"] = function2;
6035 specConstants.push_back(56789);
6036 specConstants.push_back(-2);
6037 specConstants.push_back(56788);
6039 createTestsForAllStages("vector_related", inputColors, outputColors2, fragments, specConstants, group.get());
6041 return group.release();
6044 tcu::TestCaseGroup* createOpPhiTests(tcu::TestContext& testCtx)
6046 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opphi", "Test the OpPhi instruction"));
6047 RGBA inputColors[4];
6048 RGBA outputColors1[4];
6049 RGBA outputColors2[4];
6050 RGBA outputColors3[4];
6051 map<string, string> fragments1;
6052 map<string, string> fragments2;
6053 map<string, string> fragments3;
6055 const char typesAndConstants1[] =
6056 "%c_f32_p2 = OpConstant %f32 0.2\n"
6057 "%c_f32_p4 = OpConstant %f32 0.4\n"
6058 "%c_f32_p5 = OpConstant %f32 0.5\n"
6059 "%c_f32_p8 = OpConstant %f32 0.8\n";
6061 // vec4 test_code(vec4 param) {
6062 // vec4 result = param;
6063 // for (int i = 0; i < 4; ++i) {
6066 // case 0: operand = .2; break;
6067 // case 1: operand = .5; break;
6068 // case 2: operand = .4; break;
6069 // case 3: operand = .0; break;
6070 // default: break; // unreachable
6072 // result[i] += operand;
6076 const char function1[] =
6077 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6078 "%param1 = OpFunctionParameter %v4f32\n"
6080 "%iptr = OpVariable %fp_i32 Function\n"
6081 "%result = OpVariable %fp_v4f32 Function\n"
6082 " OpStore %iptr %c_i32_0\n"
6083 " OpStore %result %param1\n"
6087 "%ival = OpLoad %i32 %iptr\n"
6088 "%lt_4 = OpSLessThan %bool %ival %c_i32_4\n"
6089 " OpLoopMerge %exit %phi None\n"
6090 " OpBranchConditional %lt_4 %entry %exit\n"
6092 "%entry = OpLabel\n"
6093 "%loc = OpAccessChain %fp_f32 %result %ival\n"
6094 "%val = OpLoad %f32 %loc\n"
6095 " OpSelectionMerge %phi None\n"
6096 " OpSwitch %ival %default 0 %case0 1 %case1 2 %case2 3 %case3\n"
6098 "%case0 = OpLabel\n"
6100 "%case1 = OpLabel\n"
6102 "%case2 = OpLabel\n"
6104 "%case3 = OpLabel\n"
6107 "%default = OpLabel\n"
6111 "%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
6112 "%add = OpFAdd %f32 %val %operand\n"
6113 " OpStore %loc %add\n"
6114 "%ival_next = OpIAdd %i32 %ival %c_i32_1\n"
6115 " OpStore %iptr %ival_next\n"
6119 "%ret = OpLoad %v4f32 %result\n"
6120 " OpReturnValue %ret\n"
6124 fragments1["pre_main"] = typesAndConstants1;
6125 fragments1["testfun"] = function1;
6127 getHalfColorsFullAlpha(inputColors);
6129 outputColors1[0] = RGBA(178, 255, 229, 255);
6130 outputColors1[1] = RGBA(178, 127, 102, 255);
6131 outputColors1[2] = RGBA(51, 255, 102, 255);
6132 outputColors1[3] = RGBA(51, 127, 229, 255);
6134 createTestsForAllStages("out_of_order", inputColors, outputColors1, fragments1, group.get());
6136 const char typesAndConstants2[] =
6137 "%c_f32_p2 = OpConstant %f32 0.2\n";
6139 // Add .4 to the second element of the given parameter.
6140 const char function2[] =
6141 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6142 "%param = OpFunctionParameter %v4f32\n"
6143 "%entry = OpLabel\n"
6144 "%result = OpVariable %fp_v4f32 Function\n"
6145 " OpStore %result %param\n"
6146 "%loc = OpAccessChain %fp_f32 %result %c_i32_1\n"
6147 "%val = OpLoad %f32 %loc\n"
6151 "%step = OpPhi %i32 %c_i32_0 %entry %step_next %phi\n"
6152 "%accum = OpPhi %f32 %val %entry %accum_next %phi\n"
6153 "%step_next = OpIAdd %i32 %step %c_i32_1\n"
6154 "%accum_next = OpFAdd %f32 %accum %c_f32_p2\n"
6155 "%still_loop = OpSLessThan %bool %step %c_i32_2\n"
6156 " OpLoopMerge %exit %phi None\n"
6157 " OpBranchConditional %still_loop %phi %exit\n"
6160 " OpStore %loc %accum\n"
6161 "%ret = OpLoad %v4f32 %result\n"
6162 " OpReturnValue %ret\n"
6166 fragments2["pre_main"] = typesAndConstants2;
6167 fragments2["testfun"] = function2;
6169 outputColors2[0] = RGBA(127, 229, 127, 255);
6170 outputColors2[1] = RGBA(127, 102, 0, 255);
6171 outputColors2[2] = RGBA(0, 229, 0, 255);
6172 outputColors2[3] = RGBA(0, 102, 127, 255);
6174 createTestsForAllStages("induction", inputColors, outputColors2, fragments2, group.get());
6176 const char typesAndConstants3[] =
6177 "%true = OpConstantTrue %bool\n"
6178 "%false = OpConstantFalse %bool\n"
6179 "%c_f32_p2 = OpConstant %f32 0.2\n";
6181 // Swap the second and the third element of the given parameter.
6182 const char function3[] =
6183 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6184 "%param = OpFunctionParameter %v4f32\n"
6185 "%entry = OpLabel\n"
6186 "%result = OpVariable %fp_v4f32 Function\n"
6187 " OpStore %result %param\n"
6188 "%a_loc = OpAccessChain %fp_f32 %result %c_i32_1\n"
6189 "%a_init = OpLoad %f32 %a_loc\n"
6190 "%b_loc = OpAccessChain %fp_f32 %result %c_i32_2\n"
6191 "%b_init = OpLoad %f32 %b_loc\n"
6195 "%still_loop = OpPhi %bool %true %entry %false %phi\n"
6196 "%a_next = OpPhi %f32 %a_init %entry %b_next %phi\n"
6197 "%b_next = OpPhi %f32 %b_init %entry %a_next %phi\n"
6198 " OpLoopMerge %exit %phi None\n"
6199 " OpBranchConditional %still_loop %phi %exit\n"
6202 " OpStore %a_loc %a_next\n"
6203 " OpStore %b_loc %b_next\n"
6204 "%ret = OpLoad %v4f32 %result\n"
6205 " OpReturnValue %ret\n"
6209 fragments3["pre_main"] = typesAndConstants3;
6210 fragments3["testfun"] = function3;
6212 outputColors3[0] = RGBA(127, 127, 127, 255);
6213 outputColors3[1] = RGBA(127, 0, 0, 255);
6214 outputColors3[2] = RGBA(0, 0, 127, 255);
6215 outputColors3[3] = RGBA(0, 127, 0, 255);
6217 createTestsForAllStages("swap", inputColors, outputColors3, fragments3, group.get());
6219 return group.release();
6222 tcu::TestCaseGroup* createNoContractionTests(tcu::TestContext& testCtx)
6224 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "nocontraction", "Test the NoContraction decoration"));
6225 RGBA inputColors[4];
6226 RGBA outputColors[4];
6228 // With NoContraction, (1 + 2^-23) * (1 - 2^-23) - 1 should be conducted as a multiplication and an addition separately.
6229 // For the multiplication, the result is 1 - 2^-46, which is out of the precision range for 32-bit float. (32-bit float
6230 // only have 23-bit fraction.) So it will be rounded to 1. Or 0x1.fffffc. Then the final result is 0 or -0x1p-24.
6231 // On the contrary, the result will be 2^-46, which is a normalized number perfectly representable as 32-bit float.
6232 const char constantsAndTypes[] =
6233 "%c_vec4_0 = OpConstantComposite %v4f32 %c_f32_0 %c_f32_0 %c_f32_0 %c_f32_1\n"
6234 "%c_vec4_1 = OpConstantComposite %v4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_1\n"
6235 "%c_f32_1pl2_23 = OpConstant %f32 0x1.000002p+0\n" // 1 + 2^-23
6236 "%c_f32_1mi2_23 = OpConstant %f32 0x1.fffffcp-1\n" // 1 - 2^-23
6237 "%c_f32_n1pn24 = OpConstant %f32 -0x1p-24\n"
6240 const char function[] =
6241 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6242 "%param = OpFunctionParameter %v4f32\n"
6243 "%label = OpLabel\n"
6244 "%var1 = OpVariable %fp_f32 Function %c_f32_1pl2_23\n"
6245 "%var2 = OpVariable %fp_f32 Function\n"
6246 "%red = OpCompositeExtract %f32 %param 0\n"
6247 "%plus_red = OpFAdd %f32 %c_f32_1mi2_23 %red\n"
6248 " OpStore %var2 %plus_red\n"
6249 "%val1 = OpLoad %f32 %var1\n"
6250 "%val2 = OpLoad %f32 %var2\n"
6251 "%mul = OpFMul %f32 %val1 %val2\n"
6252 "%add = OpFAdd %f32 %mul %c_f32_n1\n"
6253 "%is0 = OpFOrdEqual %bool %add %c_f32_0\n"
6254 "%isn1n24 = OpFOrdEqual %bool %add %c_f32_n1pn24\n"
6255 "%success = OpLogicalOr %bool %is0 %isn1n24\n"
6256 "%v4success = OpCompositeConstruct %v4bool %success %success %success %success\n"
6257 "%ret = OpSelect %v4f32 %v4success %c_vec4_0 %c_vec4_1\n"
6258 " OpReturnValue %ret\n"
6261 struct CaseNameDecoration
6268 CaseNameDecoration tests[] = {
6269 {"multiplication", "OpDecorate %mul NoContraction"},
6270 {"addition", "OpDecorate %add NoContraction"},
6271 {"both", "OpDecorate %mul NoContraction\nOpDecorate %add NoContraction"},
6274 getHalfColorsFullAlpha(inputColors);
6276 for (deUint8 idx = 0; idx < 4; ++idx)
6278 inputColors[idx].setRed(0);
6279 outputColors[idx] = RGBA(0, 0, 0, 255);
6282 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(CaseNameDecoration); ++testNdx)
6284 map<string, string> fragments;
6286 fragments["decoration"] = tests[testNdx].decoration;
6287 fragments["pre_main"] = constantsAndTypes;
6288 fragments["testfun"] = function;
6290 createTestsForAllStages(tests[testNdx].name, inputColors, outputColors, fragments, group.get());
6293 return group.release();
6296 tcu::TestCaseGroup* createMemoryAccessTests(tcu::TestContext& testCtx)
6298 de::MovePtr<tcu::TestCaseGroup> memoryAccessTests (new tcu::TestCaseGroup(testCtx, "opmemoryaccess", "Memory Semantics"));
6301 const char constantsAndTypes[] =
6302 "%c_a2f32_1 = OpConstantComposite %a2f32 %c_f32_1 %c_f32_1\n"
6303 "%fp_a2f32 = OpTypePointer Function %a2f32\n"
6304 "%stype = OpTypeStruct %v4f32 %a2f32 %f32\n"
6305 "%fp_stype = OpTypePointer Function %stype\n";
6307 const char function[] =
6308 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6309 "%param1 = OpFunctionParameter %v4f32\n"
6311 "%v1 = OpVariable %fp_v4f32 Function\n"
6312 "%v2 = OpVariable %fp_a2f32 Function\n"
6313 "%v3 = OpVariable %fp_f32 Function\n"
6314 "%v = OpVariable %fp_stype Function\n"
6315 "%vv = OpVariable %fp_stype Function\n"
6316 "%vvv = OpVariable %fp_f32 Function\n"
6318 " OpStore %v1 %c_v4f32_1_1_1_1\n"
6319 " OpStore %v2 %c_a2f32_1\n"
6320 " OpStore %v3 %c_f32_1\n"
6322 "%p_v4f32 = OpAccessChain %fp_v4f32 %v %c_u32_0\n"
6323 "%p_a2f32 = OpAccessChain %fp_a2f32 %v %c_u32_1\n"
6324 "%p_f32 = OpAccessChain %fp_f32 %v %c_u32_2\n"
6325 "%v1_v = OpLoad %v4f32 %v1 ${access_type}\n"
6326 "%v2_v = OpLoad %a2f32 %v2 ${access_type}\n"
6327 "%v3_v = OpLoad %f32 %v3 ${access_type}\n"
6329 " OpStore %p_v4f32 %v1_v ${access_type}\n"
6330 " OpStore %p_a2f32 %v2_v ${access_type}\n"
6331 " OpStore %p_f32 %v3_v ${access_type}\n"
6333 " OpCopyMemory %vv %v ${access_type}\n"
6334 " OpCopyMemory %vvv %p_f32 ${access_type}\n"
6336 "%p_f32_2 = OpAccessChain %fp_f32 %vv %c_u32_2\n"
6337 "%v_f32_2 = OpLoad %f32 %p_f32_2\n"
6338 "%v_f32_3 = OpLoad %f32 %vvv\n"
6340 "%ret1 = OpVectorTimesScalar %v4f32 %param1 %v_f32_2\n"
6341 "%ret2 = OpVectorTimesScalar %v4f32 %ret1 %v_f32_3\n"
6342 " OpReturnValue %ret2\n"
6345 struct NameMemoryAccess
6352 NameMemoryAccess tests[] =
6355 { "volatile", "Volatile" },
6356 { "aligned", "Aligned 1" },
6357 { "volatile_aligned", "Volatile|Aligned 1" },
6358 { "nontemporal_aligned", "Nontemporal|Aligned 1" },
6359 { "volatile_nontemporal", "Volatile|Nontemporal" },
6360 { "volatile_nontermporal_aligned", "Volatile|Nontemporal|Aligned 1" },
6363 getHalfColorsFullAlpha(colors);
6365 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameMemoryAccess); ++testNdx)
6367 map<string, string> fragments;
6368 map<string, string> memoryAccess;
6369 memoryAccess["access_type"] = tests[testNdx].accessType;
6371 fragments["pre_main"] = constantsAndTypes;
6372 fragments["testfun"] = tcu::StringTemplate(function).specialize(memoryAccess);
6373 createTestsForAllStages(tests[testNdx].name, colors, colors, fragments, memoryAccessTests.get());
6375 return memoryAccessTests.release();
6377 tcu::TestCaseGroup* createOpUndefTests(tcu::TestContext& testCtx)
6379 de::MovePtr<tcu::TestCaseGroup> opUndefTests (new tcu::TestCaseGroup(testCtx, "opundef", "Test OpUndef"));
6380 RGBA defaultColors[4];
6381 map<string, string> fragments;
6382 getDefaultColors(defaultColors);
6384 // First, simple cases that don't do anything with the OpUndef result.
6385 struct NameCodePair { string name, decl, type; };
6386 const NameCodePair tests[] =
6388 {"bool", "", "%bool"},
6389 {"vec2uint32", "", "%v2u32"},
6390 {"image", "%type = OpTypeImage %f32 2D 0 0 0 1 Unknown", "%type"},
6391 {"sampler", "%type = OpTypeSampler", "%type"},
6392 {"sampledimage", "%img = OpTypeImage %f32 2D 0 0 0 1 Unknown\n" "%type = OpTypeSampledImage %img", "%type"},
6393 {"pointer", "", "%fp_i32"},
6394 {"runtimearray", "%type = OpTypeRuntimeArray %f32", "%type"},
6395 {"array", "%c_u32_100 = OpConstant %u32 100\n" "%type = OpTypeArray %i32 %c_u32_100", "%type"},
6396 {"struct", "%type = OpTypeStruct %f32 %i32 %u32", "%type"}};
6397 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameCodePair); ++testNdx)
6399 fragments["undef_type"] = tests[testNdx].type;
6400 fragments["testfun"] = StringTemplate(
6401 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6402 "%param1 = OpFunctionParameter %v4f32\n"
6403 "%label_testfun = OpLabel\n"
6404 "%undef = OpUndef ${undef_type}\n"
6405 "OpReturnValue %param1\n"
6406 "OpFunctionEnd\n").specialize(fragments);
6407 fragments["pre_main"] = tests[testNdx].decl;
6408 createTestsForAllStages(tests[testNdx].name, defaultColors, defaultColors, fragments, opUndefTests.get());
6412 fragments["testfun"] =
6413 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6414 "%param1 = OpFunctionParameter %v4f32\n"
6415 "%label_testfun = OpLabel\n"
6416 "%undef = OpUndef %f32\n"
6417 "%zero = OpFMul %f32 %undef %c_f32_0\n"
6418 "%is_nan = OpIsNan %bool %zero\n" //OpUndef may result in NaN which may turn %zero into Nan.
6419 "%actually_zero = OpSelect %f32 %is_nan %c_f32_0 %zero\n"
6420 "%a = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
6421 "%b = OpFAdd %f32 %a %actually_zero\n"
6422 "%ret = OpVectorInsertDynamic %v4f32 %param1 %b %c_i32_0\n"
6423 "OpReturnValue %ret\n"
6426 createTestsForAllStages("float32", defaultColors, defaultColors, fragments, opUndefTests.get());
6428 fragments["testfun"] =
6429 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6430 "%param1 = OpFunctionParameter %v4f32\n"
6431 "%label_testfun = OpLabel\n"
6432 "%undef = OpUndef %i32\n"
6433 "%zero = OpIMul %i32 %undef %c_i32_0\n"
6434 "%a = OpVectorExtractDynamic %f32 %param1 %zero\n"
6435 "%ret = OpVectorInsertDynamic %v4f32 %param1 %a %c_i32_0\n"
6436 "OpReturnValue %ret\n"
6439 createTestsForAllStages("sint32", defaultColors, defaultColors, fragments, opUndefTests.get());
6441 fragments["testfun"] =
6442 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6443 "%param1 = OpFunctionParameter %v4f32\n"
6444 "%label_testfun = OpLabel\n"
6445 "%undef = OpUndef %u32\n"
6446 "%zero = OpIMul %u32 %undef %c_i32_0\n"
6447 "%a = OpVectorExtractDynamic %f32 %param1 %zero\n"
6448 "%ret = OpVectorInsertDynamic %v4f32 %param1 %a %c_i32_0\n"
6449 "OpReturnValue %ret\n"
6452 createTestsForAllStages("uint32", defaultColors, defaultColors, fragments, opUndefTests.get());
6454 fragments["testfun"] =
6455 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6456 "%param1 = OpFunctionParameter %v4f32\n"
6457 "%label_testfun = OpLabel\n"
6458 "%undef = OpUndef %v4f32\n"
6459 "%vzero = OpVectorTimesScalar %v4f32 %undef %c_f32_0\n"
6460 "%zero_0 = OpVectorExtractDynamic %f32 %vzero %c_i32_0\n"
6461 "%zero_1 = OpVectorExtractDynamic %f32 %vzero %c_i32_1\n"
6462 "%zero_2 = OpVectorExtractDynamic %f32 %vzero %c_i32_2\n"
6463 "%zero_3 = OpVectorExtractDynamic %f32 %vzero %c_i32_3\n"
6464 "%is_nan_0 = OpIsNan %bool %zero_0\n"
6465 "%is_nan_1 = OpIsNan %bool %zero_1\n"
6466 "%is_nan_2 = OpIsNan %bool %zero_2\n"
6467 "%is_nan_3 = OpIsNan %bool %zero_3\n"
6468 "%actually_zero_0 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_0\n"
6469 "%actually_zero_1 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_1\n"
6470 "%actually_zero_2 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_2\n"
6471 "%actually_zero_3 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_3\n"
6472 "%param1_0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
6473 "%param1_1 = OpVectorExtractDynamic %f32 %param1 %c_i32_1\n"
6474 "%param1_2 = OpVectorExtractDynamic %f32 %param1 %c_i32_2\n"
6475 "%param1_3 = OpVectorExtractDynamic %f32 %param1 %c_i32_3\n"
6476 "%sum_0 = OpFAdd %f32 %param1_0 %actually_zero_0\n"
6477 "%sum_1 = OpFAdd %f32 %param1_1 %actually_zero_1\n"
6478 "%sum_2 = OpFAdd %f32 %param1_2 %actually_zero_2\n"
6479 "%sum_3 = OpFAdd %f32 %param1_3 %actually_zero_3\n"
6480 "%ret3 = OpVectorInsertDynamic %v4f32 %param1 %sum_3 %c_i32_3\n"
6481 "%ret2 = OpVectorInsertDynamic %v4f32 %ret3 %sum_2 %c_i32_2\n"
6482 "%ret1 = OpVectorInsertDynamic %v4f32 %ret2 %sum_1 %c_i32_1\n"
6483 "%ret = OpVectorInsertDynamic %v4f32 %ret1 %sum_0 %c_i32_0\n"
6484 "OpReturnValue %ret\n"
6487 createTestsForAllStages("vec4float32", defaultColors, defaultColors, fragments, opUndefTests.get());
6489 fragments["pre_main"] =
6490 "%m2x2f32 = OpTypeMatrix %v2f32 2\n";
6491 fragments["testfun"] =
6492 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6493 "%param1 = OpFunctionParameter %v4f32\n"
6494 "%label_testfun = OpLabel\n"
6495 "%undef = OpUndef %m2x2f32\n"
6496 "%mzero = OpMatrixTimesScalar %m2x2f32 %undef %c_f32_0\n"
6497 "%zero_0 = OpCompositeExtract %f32 %mzero 0 0\n"
6498 "%zero_1 = OpCompositeExtract %f32 %mzero 0 1\n"
6499 "%zero_2 = OpCompositeExtract %f32 %mzero 1 0\n"
6500 "%zero_3 = OpCompositeExtract %f32 %mzero 1 1\n"
6501 "%is_nan_0 = OpIsNan %bool %zero_0\n"
6502 "%is_nan_1 = OpIsNan %bool %zero_1\n"
6503 "%is_nan_2 = OpIsNan %bool %zero_2\n"
6504 "%is_nan_3 = OpIsNan %bool %zero_3\n"
6505 "%actually_zero_0 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_0\n"
6506 "%actually_zero_1 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_1\n"
6507 "%actually_zero_2 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_2\n"
6508 "%actually_zero_3 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_3\n"
6509 "%param1_0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
6510 "%param1_1 = OpVectorExtractDynamic %f32 %param1 %c_i32_1\n"
6511 "%param1_2 = OpVectorExtractDynamic %f32 %param1 %c_i32_2\n"
6512 "%param1_3 = OpVectorExtractDynamic %f32 %param1 %c_i32_3\n"
6513 "%sum_0 = OpFAdd %f32 %param1_0 %actually_zero_0\n"
6514 "%sum_1 = OpFAdd %f32 %param1_1 %actually_zero_1\n"
6515 "%sum_2 = OpFAdd %f32 %param1_2 %actually_zero_2\n"
6516 "%sum_3 = OpFAdd %f32 %param1_3 %actually_zero_3\n"
6517 "%ret3 = OpVectorInsertDynamic %v4f32 %param1 %sum_3 %c_i32_3\n"
6518 "%ret2 = OpVectorInsertDynamic %v4f32 %ret3 %sum_2 %c_i32_2\n"
6519 "%ret1 = OpVectorInsertDynamic %v4f32 %ret2 %sum_1 %c_i32_1\n"
6520 "%ret = OpVectorInsertDynamic %v4f32 %ret1 %sum_0 %c_i32_0\n"
6521 "OpReturnValue %ret\n"
6524 createTestsForAllStages("matrix", defaultColors, defaultColors, fragments, opUndefTests.get());
6526 return opUndefTests.release();
6529 void createOpQuantizeSingleOptionTests(tcu::TestCaseGroup* testCtx)
6531 const RGBA inputColors[4] =
6534 RGBA(0, 0, 255, 255),
6535 RGBA(0, 255, 0, 255),
6536 RGBA(0, 255, 255, 255)
6539 const RGBA expectedColors[4] =
6541 RGBA(255, 0, 0, 255),
6542 RGBA(255, 0, 0, 255),
6543 RGBA(255, 0, 0, 255),
6544 RGBA(255, 0, 0, 255)
6547 const struct SingleFP16Possibility
6550 const char* constant; // Value to assign to %test_constant.
6552 const char* condition; // Must assign to %cond an expression that evaluates to true after %c = OpQuantizeToF16(%test_constant + 0).
6558 -constructNormalizedFloat(1, 0x300000),
6559 "%cond = OpFOrdEqual %bool %c %test_constant\n"
6564 constructNormalizedFloat(7, 0x000000),
6565 "%cond = OpFOrdEqual %bool %c %test_constant\n"
6567 // SPIR-V requires that OpQuantizeToF16 flushes
6568 // any numbers that would end up denormalized in F16 to zero.
6572 std::ldexp(1.5f, -140),
6573 "%cond = OpFOrdEqual %bool %c %c_f32_0\n"
6578 -std::ldexp(1.5f, -140),
6579 "%cond = OpFOrdEqual %bool %c %c_f32_0\n"
6584 std::ldexp(1.0f, -16),
6585 "%cond = OpFOrdEqual %bool %c %c_f32_0\n"
6586 }, // too small positive
6588 "negative_too_small",
6590 -std::ldexp(1.0f, -32),
6591 "%cond = OpFOrdEqual %bool %c %c_f32_0\n"
6592 }, // too small negative
6596 -std::ldexp(1.0f, 128),
6598 "%gz = OpFOrdLessThan %bool %c %c_f32_0\n"
6599 "%inf = OpIsInf %bool %c\n"
6600 "%cond = OpLogicalAnd %bool %gz %inf\n"
6605 std::ldexp(1.0f, 128),
6607 "%gz = OpFOrdGreaterThan %bool %c %c_f32_0\n"
6608 "%inf = OpIsInf %bool %c\n"
6609 "%cond = OpLogicalAnd %bool %gz %inf\n"
6612 "round_to_negative_inf",
6614 -std::ldexp(1.0f, 32),
6616 "%gz = OpFOrdLessThan %bool %c %c_f32_0\n"
6617 "%inf = OpIsInf %bool %c\n"
6618 "%cond = OpLogicalAnd %bool %gz %inf\n"
6623 std::ldexp(1.0f, 16),
6625 "%gz = OpFOrdGreaterThan %bool %c %c_f32_0\n"
6626 "%inf = OpIsInf %bool %c\n"
6627 "%cond = OpLogicalAnd %bool %gz %inf\n"
6632 std::numeric_limits<float>::quiet_NaN(),
6634 // Test for any NaN value, as NaNs are not preserved
6635 "%direct_quant = OpQuantizeToF16 %f32 %test_constant\n"
6636 "%cond = OpIsNan %bool %direct_quant\n"
6641 std::numeric_limits<float>::quiet_NaN(),
6643 // Test for any NaN value, as NaNs are not preserved
6644 "%direct_quant = OpQuantizeToF16 %f32 %test_constant\n"
6645 "%cond = OpIsNan %bool %direct_quant\n"
6648 const char* constants =
6649 "%test_constant = OpConstant %f32 "; // The value will be test.constant.
6651 StringTemplate function (
6652 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6653 "%param1 = OpFunctionParameter %v4f32\n"
6654 "%label_testfun = OpLabel\n"
6655 "%a = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
6656 "%b = OpFAdd %f32 %test_constant %a\n"
6657 "%c = OpQuantizeToF16 %f32 %b\n"
6659 "%v4cond = OpCompositeConstruct %v4bool %cond %cond %cond %cond\n"
6660 "%retval = OpSelect %v4f32 %v4cond %c_v4f32_1_0_0_1 %param1\n"
6661 " OpReturnValue %retval\n"
6665 const char* specDecorations = "OpDecorate %test_constant SpecId 0\n";
6666 const char* specConstants =
6667 "%test_constant = OpSpecConstant %f32 0.\n"
6668 "%c = OpSpecConstantOp %f32 QuantizeToF16 %test_constant\n";
6670 StringTemplate specConstantFunction(
6671 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6672 "%param1 = OpFunctionParameter %v4f32\n"
6673 "%label_testfun = OpLabel\n"
6675 "%v4cond = OpCompositeConstruct %v4bool %cond %cond %cond %cond\n"
6676 "%retval = OpSelect %v4f32 %v4cond %c_v4f32_1_0_0_1 %param1\n"
6677 " OpReturnValue %retval\n"
6681 for (size_t idx = 0; idx < (sizeof(tests)/sizeof(tests[0])); ++idx)
6683 map<string, string> codeSpecialization;
6684 map<string, string> fragments;
6685 codeSpecialization["condition"] = tests[idx].condition;
6686 fragments["testfun"] = function.specialize(codeSpecialization);
6687 fragments["pre_main"] = string(constants) + tests[idx].constant + "\n";
6688 createTestsForAllStages(tests[idx].name, inputColors, expectedColors, fragments, testCtx);
6691 for (size_t idx = 0; idx < (sizeof(tests)/sizeof(tests[0])); ++idx)
6693 map<string, string> codeSpecialization;
6694 map<string, string> fragments;
6695 vector<deInt32> passConstants;
6696 deInt32 specConstant;
6698 codeSpecialization["condition"] = tests[idx].condition;
6699 fragments["testfun"] = specConstantFunction.specialize(codeSpecialization);
6700 fragments["decoration"] = specDecorations;
6701 fragments["pre_main"] = specConstants;
6703 memcpy(&specConstant, &tests[idx].valueAsFloat, sizeof(float));
6704 passConstants.push_back(specConstant);
6706 createTestsForAllStages(string("spec_const_") + tests[idx].name, inputColors, expectedColors, fragments, passConstants, testCtx);
6710 void createOpQuantizeTwoPossibilityTests(tcu::TestCaseGroup* testCtx)
6712 RGBA inputColors[4] = {
6714 RGBA(0, 0, 255, 255),
6715 RGBA(0, 255, 0, 255),
6716 RGBA(0, 255, 255, 255)
6719 RGBA expectedColors[4] =
6721 RGBA(255, 0, 0, 255),
6722 RGBA(255, 0, 0, 255),
6723 RGBA(255, 0, 0, 255),
6724 RGBA(255, 0, 0, 255)
6727 struct DualFP16Possibility
6732 const char* possibleOutput1;
6733 const char* possibleOutput2;
6736 "positive_round_up_or_round_down",
6738 constructNormalizedFloat(8, 0x300300),
6743 "negative_round_up_or_round_down",
6745 -constructNormalizedFloat(-7, 0x600800),
6752 constructNormalizedFloat(2, 0x01e000),
6757 "carry_to_exponent",
6759 constructNormalizedFloat(1, 0xffe000),
6764 StringTemplate constants (
6765 "%input_const = OpConstant %f32 ${input}\n"
6766 "%possible_solution1 = OpConstant %f32 ${output1}\n"
6767 "%possible_solution2 = OpConstant %f32 ${output2}\n"
6770 StringTemplate specConstants (
6771 "%input_const = OpSpecConstant %f32 0.\n"
6772 "%possible_solution1 = OpConstant %f32 ${output1}\n"
6773 "%possible_solution2 = OpConstant %f32 ${output2}\n"
6776 const char* specDecorations = "OpDecorate %input_const SpecId 0\n";
6778 const char* function =
6779 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6780 "%param1 = OpFunctionParameter %v4f32\n"
6781 "%label_testfun = OpLabel\n"
6782 "%a = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
6783 // For the purposes of this test we assume that 0.f will always get
6784 // faithfully passed through the pipeline stages.
6785 "%b = OpFAdd %f32 %input_const %a\n"
6786 "%c = OpQuantizeToF16 %f32 %b\n"
6787 "%eq_1 = OpFOrdEqual %bool %c %possible_solution1\n"
6788 "%eq_2 = OpFOrdEqual %bool %c %possible_solution2\n"
6789 "%cond = OpLogicalOr %bool %eq_1 %eq_2\n"
6790 "%v4cond = OpCompositeConstruct %v4bool %cond %cond %cond %cond\n"
6791 "%retval = OpSelect %v4f32 %v4cond %c_v4f32_1_0_0_1 %param1"
6792 " OpReturnValue %retval\n"
6795 for(size_t idx = 0; idx < (sizeof(tests)/sizeof(tests[0])); ++idx) {
6796 map<string, string> fragments;
6797 map<string, string> constantSpecialization;
6799 constantSpecialization["input"] = tests[idx].input;
6800 constantSpecialization["output1"] = tests[idx].possibleOutput1;
6801 constantSpecialization["output2"] = tests[idx].possibleOutput2;
6802 fragments["testfun"] = function;
6803 fragments["pre_main"] = constants.specialize(constantSpecialization);
6804 createTestsForAllStages(tests[idx].name, inputColors, expectedColors, fragments, testCtx);
6807 for(size_t idx = 0; idx < (sizeof(tests)/sizeof(tests[0])); ++idx) {
6808 map<string, string> fragments;
6809 map<string, string> constantSpecialization;
6810 vector<deInt32> passConstants;
6811 deInt32 specConstant;
6813 constantSpecialization["output1"] = tests[idx].possibleOutput1;
6814 constantSpecialization["output2"] = tests[idx].possibleOutput2;
6815 fragments["testfun"] = function;
6816 fragments["decoration"] = specDecorations;
6817 fragments["pre_main"] = specConstants.specialize(constantSpecialization);
6819 memcpy(&specConstant, &tests[idx].inputAsFloat, sizeof(float));
6820 passConstants.push_back(specConstant);
6822 createTestsForAllStages(string("spec_const_") + tests[idx].name, inputColors, expectedColors, fragments, passConstants, testCtx);
6826 tcu::TestCaseGroup* createOpQuantizeTests(tcu::TestContext& testCtx)
6828 de::MovePtr<tcu::TestCaseGroup> opQuantizeTests (new tcu::TestCaseGroup(testCtx, "opquantize", "Test OpQuantizeToF16"));
6829 createOpQuantizeSingleOptionTests(opQuantizeTests.get());
6830 createOpQuantizeTwoPossibilityTests(opQuantizeTests.get());
6831 return opQuantizeTests.release();
6834 struct ShaderPermutation
6836 deUint8 vertexPermutation;
6837 deUint8 geometryPermutation;
6838 deUint8 tesscPermutation;
6839 deUint8 tessePermutation;
6840 deUint8 fragmentPermutation;
6843 ShaderPermutation getShaderPermutation(deUint8 inputValue)
6845 ShaderPermutation permutation =
6847 static_cast<deUint8>(inputValue & 0x10? 1u: 0u),
6848 static_cast<deUint8>(inputValue & 0x08? 1u: 0u),
6849 static_cast<deUint8>(inputValue & 0x04? 1u: 0u),
6850 static_cast<deUint8>(inputValue & 0x02? 1u: 0u),
6851 static_cast<deUint8>(inputValue & 0x01? 1u: 0u)
6856 tcu::TestCaseGroup* createModuleTests(tcu::TestContext& testCtx)
6858 RGBA defaultColors[4];
6859 RGBA invertedColors[4];
6860 de::MovePtr<tcu::TestCaseGroup> moduleTests (new tcu::TestCaseGroup(testCtx, "module", "Multiple entry points into shaders"));
6862 const ShaderElement combinedPipeline[] =
6864 ShaderElement("module", "main", VK_SHADER_STAGE_VERTEX_BIT),
6865 ShaderElement("module", "main", VK_SHADER_STAGE_GEOMETRY_BIT),
6866 ShaderElement("module", "main", VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT),
6867 ShaderElement("module", "main", VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT),
6868 ShaderElement("module", "main", VK_SHADER_STAGE_FRAGMENT_BIT)
6871 getDefaultColors(defaultColors);
6872 getInvertedDefaultColors(invertedColors);
6873 addFunctionCaseWithPrograms<InstanceContext>(
6874 moduleTests.get(), "same_module", "", createCombinedModule, runAndVerifyDefaultPipeline,
6875 createInstanceContext(combinedPipeline, map<string, string>()));
6877 const char* numbers[] =
6882 for (deInt8 idx = 0; idx < 32; ++idx)
6884 ShaderPermutation permutation = getShaderPermutation(idx);
6885 string name = string("vert") + numbers[permutation.vertexPermutation] + "_geom" + numbers[permutation.geometryPermutation] + "_tessc" + numbers[permutation.tesscPermutation] + "_tesse" + numbers[permutation.tessePermutation] + "_frag" + numbers[permutation.fragmentPermutation];
6886 const ShaderElement pipeline[] =
6888 ShaderElement("vert", string("vert") + numbers[permutation.vertexPermutation], VK_SHADER_STAGE_VERTEX_BIT),
6889 ShaderElement("geom", string("geom") + numbers[permutation.geometryPermutation], VK_SHADER_STAGE_GEOMETRY_BIT),
6890 ShaderElement("tessc", string("tessc") + numbers[permutation.tesscPermutation], VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT),
6891 ShaderElement("tesse", string("tesse") + numbers[permutation.tessePermutation], VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT),
6892 ShaderElement("frag", string("frag") + numbers[permutation.fragmentPermutation], VK_SHADER_STAGE_FRAGMENT_BIT)
6895 // If there are an even number of swaps, then it should be no-op.
6896 // If there are an odd number, the color should be flipped.
6897 if ((permutation.vertexPermutation + permutation.geometryPermutation + permutation.tesscPermutation + permutation.tessePermutation + permutation.fragmentPermutation) % 2 == 0)
6899 addFunctionCaseWithPrograms<InstanceContext>(
6900 moduleTests.get(), name, "", createMultipleEntries, runAndVerifyDefaultPipeline,
6901 createInstanceContext(pipeline, defaultColors, defaultColors, map<string, string>()));
6905 addFunctionCaseWithPrograms<InstanceContext>(
6906 moduleTests.get(), name, "", createMultipleEntries, runAndVerifyDefaultPipeline,
6907 createInstanceContext(pipeline, defaultColors, invertedColors, map<string, string>()));
6910 return moduleTests.release();
6913 tcu::TestCaseGroup* createLoopTests(tcu::TestContext& testCtx)
6915 de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, "loop", "Looping control flow"));
6916 RGBA defaultColors[4];
6917 getDefaultColors(defaultColors);
6918 map<string, string> fragments;
6919 fragments["pre_main"] =
6920 "%c_f32_5 = OpConstant %f32 5.\n";
6922 // A loop with a single block. The Continue Target is the loop block
6923 // itself. In SPIR-V terms, the "loop construct" contains no blocks at all
6924 // -- the "continue construct" forms the entire loop.
6925 fragments["testfun"] =
6926 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6927 "%param1 = OpFunctionParameter %v4f32\n"
6929 "%entry = OpLabel\n"
6930 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
6933 ";adds and subtracts 1.0 to %val in alternate iterations\n"
6935 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %loop\n"
6936 "%delta = OpPhi %f32 %c_f32_1 %entry %minus_delta %loop\n"
6937 "%val1 = OpPhi %f32 %val0 %entry %val %loop\n"
6938 "%val = OpFAdd %f32 %val1 %delta\n"
6939 "%minus_delta = OpFSub %f32 %c_f32_0 %delta\n"
6940 "%count__ = OpISub %i32 %count %c_i32_1\n"
6941 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
6942 "OpLoopMerge %exit %loop None\n"
6943 "OpBranchConditional %again %loop %exit\n"
6946 "%result = OpVectorInsertDynamic %v4f32 %param1 %val %c_i32_0\n"
6947 "OpReturnValue %result\n"
6951 createTestsForAllStages("single_block", defaultColors, defaultColors, fragments, testGroup.get());
6953 // Body comprised of multiple basic blocks.
6954 const StringTemplate multiBlock(
6955 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6956 "%param1 = OpFunctionParameter %v4f32\n"
6958 "%entry = OpLabel\n"
6959 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
6962 ";adds and subtracts 1.0 to %val in alternate iterations\n"
6964 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %gather\n"
6965 "%delta = OpPhi %f32 %c_f32_1 %entry %delta_next %gather\n"
6966 "%val1 = OpPhi %f32 %val0 %entry %val %gather\n"
6967 // There are several possibilities for the Continue Target below. Each
6968 // will be specialized into a separate test case.
6969 "OpLoopMerge %exit ${continue_target} None\n"
6973 ";delta_next = (delta > 0) ? -1 : 1;\n"
6974 "%gt0 = OpFOrdGreaterThan %bool %delta %c_f32_0\n"
6975 "OpSelectionMerge %gather DontFlatten\n"
6976 "OpBranchConditional %gt0 %even %odd ;tells us if %count is even or odd\n"
6979 "OpBranch %gather\n"
6982 "OpBranch %gather\n"
6984 "%gather = OpLabel\n"
6985 "%delta_next = OpPhi %f32 %c_f32_n1 %even %c_f32_1 %odd\n"
6986 "%val = OpFAdd %f32 %val1 %delta\n"
6987 "%count__ = OpISub %i32 %count %c_i32_1\n"
6988 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
6989 "OpBranchConditional %again %loop %exit\n"
6992 "%result = OpVectorInsertDynamic %v4f32 %param1 %val %c_i32_0\n"
6993 "OpReturnValue %result\n"
6997 map<string, string> continue_target;
6999 // The Continue Target is the loop block itself.
7000 continue_target["continue_target"] = "%loop";
7001 fragments["testfun"] = multiBlock.specialize(continue_target);
7002 createTestsForAllStages("multi_block_continue_construct", defaultColors, defaultColors, fragments, testGroup.get());
7004 // The Continue Target is at the end of the loop.
7005 continue_target["continue_target"] = "%gather";
7006 fragments["testfun"] = multiBlock.specialize(continue_target);
7007 createTestsForAllStages("multi_block_loop_construct", defaultColors, defaultColors, fragments, testGroup.get());
7009 // A loop with continue statement.
7010 fragments["testfun"] =
7011 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
7012 "%param1 = OpFunctionParameter %v4f32\n"
7014 "%entry = OpLabel\n"
7015 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
7018 ";adds 4, 3, and 1 to %val0 (skips 2)\n"
7020 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %continue\n"
7021 "%val1 = OpPhi %f32 %val0 %entry %val %continue\n"
7022 "OpLoopMerge %exit %continue None\n"
7026 ";skip if %count==2\n"
7027 "%eq2 = OpIEqual %bool %count %c_i32_2\n"
7028 "OpSelectionMerge %continue DontFlatten\n"
7029 "OpBranchConditional %eq2 %continue %body\n"
7032 "%fcount = OpConvertSToF %f32 %count\n"
7033 "%val2 = OpFAdd %f32 %val1 %fcount\n"
7034 "OpBranch %continue\n"
7036 "%continue = OpLabel\n"
7037 "%val = OpPhi %f32 %val2 %body %val1 %if\n"
7038 "%count__ = OpISub %i32 %count %c_i32_1\n"
7039 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
7040 "OpBranchConditional %again %loop %exit\n"
7043 "%same = OpFSub %f32 %val %c_f32_8\n"
7044 "%result = OpVectorInsertDynamic %v4f32 %param1 %same %c_i32_0\n"
7045 "OpReturnValue %result\n"
7047 createTestsForAllStages("continue", defaultColors, defaultColors, fragments, testGroup.get());
7049 // A loop with break.
7050 fragments["testfun"] =
7051 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
7052 "%param1 = OpFunctionParameter %v4f32\n"
7054 "%entry = OpLabel\n"
7055 ";param1 components are between 0 and 1, so dot product is 4 or less\n"
7056 "%dot = OpDot %f32 %param1 %param1\n"
7057 "%div = OpFDiv %f32 %dot %c_f32_5\n"
7058 "%zero = OpConvertFToU %u32 %div\n"
7059 "%two = OpIAdd %i32 %zero %c_i32_2\n"
7060 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
7063 ";adds 4 and 3 to %val0 (exits early)\n"
7065 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %continue\n"
7066 "%val1 = OpPhi %f32 %val0 %entry %val2 %continue\n"
7067 "OpLoopMerge %exit %continue None\n"
7071 ";end loop if %count==%two\n"
7072 "%above2 = OpSGreaterThan %bool %count %two\n"
7073 "OpSelectionMerge %continue DontFlatten\n"
7074 "OpBranchConditional %above2 %body %exit\n"
7077 "%fcount = OpConvertSToF %f32 %count\n"
7078 "%val2 = OpFAdd %f32 %val1 %fcount\n"
7079 "OpBranch %continue\n"
7081 "%continue = OpLabel\n"
7082 "%count__ = OpISub %i32 %count %c_i32_1\n"
7083 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
7084 "OpBranchConditional %again %loop %exit\n"
7087 "%val_post = OpPhi %f32 %val2 %continue %val1 %if\n"
7088 "%same = OpFSub %f32 %val_post %c_f32_7\n"
7089 "%result = OpVectorInsertDynamic %v4f32 %param1 %same %c_i32_0\n"
7090 "OpReturnValue %result\n"
7092 createTestsForAllStages("break", defaultColors, defaultColors, fragments, testGroup.get());
7094 // A loop with return.
7095 fragments["testfun"] =
7096 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
7097 "%param1 = OpFunctionParameter %v4f32\n"
7099 "%entry = OpLabel\n"
7100 ";param1 components are between 0 and 1, so dot product is 4 or less\n"
7101 "%dot = OpDot %f32 %param1 %param1\n"
7102 "%div = OpFDiv %f32 %dot %c_f32_5\n"
7103 "%zero = OpConvertFToU %u32 %div\n"
7104 "%two = OpIAdd %i32 %zero %c_i32_2\n"
7105 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
7108 ";returns early without modifying %param1\n"
7110 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %continue\n"
7111 "%val1 = OpPhi %f32 %val0 %entry %val2 %continue\n"
7112 "OpLoopMerge %exit %continue None\n"
7116 ";return if %count==%two\n"
7117 "%above2 = OpSGreaterThan %bool %count %two\n"
7118 "OpSelectionMerge %continue DontFlatten\n"
7119 "OpBranchConditional %above2 %body %early_exit\n"
7121 "%early_exit = OpLabel\n"
7122 "OpReturnValue %param1\n"
7125 "%fcount = OpConvertSToF %f32 %count\n"
7126 "%val2 = OpFAdd %f32 %val1 %fcount\n"
7127 "OpBranch %continue\n"
7129 "%continue = OpLabel\n"
7130 "%count__ = OpISub %i32 %count %c_i32_1\n"
7131 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
7132 "OpBranchConditional %again %loop %exit\n"
7135 ";should never get here, so return an incorrect result\n"
7136 "%result = OpVectorInsertDynamic %v4f32 %param1 %val2 %c_i32_0\n"
7137 "OpReturnValue %result\n"
7139 createTestsForAllStages("return", defaultColors, defaultColors, fragments, testGroup.get());
7141 return testGroup.release();
7144 // A collection of tests putting OpControlBarrier in places GLSL forbids but SPIR-V allows.
7145 tcu::TestCaseGroup* createBarrierTests(tcu::TestContext& testCtx)
7147 de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, "barrier", "OpControlBarrier"));
7148 map<string, string> fragments;
7150 // A barrier inside a function body.
7151 fragments["pre_main"] =
7152 "%Workgroup = OpConstant %i32 2\n"
7153 "%SequentiallyConsistent = OpConstant %i32 0x10\n";
7154 fragments["testfun"] =
7155 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
7156 "%param1 = OpFunctionParameter %v4f32\n"
7157 "%label_testfun = OpLabel\n"
7158 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n"
7159 "OpReturnValue %param1\n"
7161 addTessCtrlTest(testGroup.get(), "in_function", fragments);
7163 // Common setup code for the following tests.
7164 fragments["pre_main"] =
7165 "%Workgroup = OpConstant %i32 2\n"
7166 "%SequentiallyConsistent = OpConstant %i32 0x10\n"
7167 "%c_f32_5 = OpConstant %f32 5.\n";
7168 const string setupPercentZero = // Begins %test_code function with code that sets %zero to 0u but cannot be optimized away.
7169 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
7170 "%param1 = OpFunctionParameter %v4f32\n"
7171 "%entry = OpLabel\n"
7172 ";param1 components are between 0 and 1, so dot product is 4 or less\n"
7173 "%dot = OpDot %f32 %param1 %param1\n"
7174 "%div = OpFDiv %f32 %dot %c_f32_5\n"
7175 "%zero = OpConvertFToU %u32 %div\n";
7177 // Barriers inside OpSwitch branches.
7178 fragments["testfun"] =
7180 "OpSelectionMerge %switch_exit None\n"
7181 "OpSwitch %zero %switch_default 0 %case0 1 %case1 ;should always go to %case0\n"
7183 "%case1 = OpLabel\n"
7184 ";This barrier should never be executed, but its presence makes test failure more likely when there's a bug.\n"
7185 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n"
7186 "%wrong_branch_alert1 = OpVectorInsertDynamic %v4f32 %param1 %c_f32_0_5 %c_i32_0\n"
7187 "OpBranch %switch_exit\n"
7189 "%switch_default = OpLabel\n"
7190 "%wrong_branch_alert2 = OpVectorInsertDynamic %v4f32 %param1 %c_f32_0_5 %c_i32_0\n"
7191 ";This barrier should never be executed, but its presence makes test failure more likely when there's a bug.\n"
7192 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n"
7193 "OpBranch %switch_exit\n"
7195 "%case0 = OpLabel\n"
7196 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n"
7197 "OpBranch %switch_exit\n"
7199 "%switch_exit = OpLabel\n"
7200 "%ret = OpPhi %v4f32 %param1 %case0 %wrong_branch_alert1 %case1 %wrong_branch_alert2 %switch_default\n"
7201 "OpReturnValue %ret\n"
7203 addTessCtrlTest(testGroup.get(), "in_switch", fragments);
7205 // Barriers inside if-then-else.
7206 fragments["testfun"] =
7208 "%eq0 = OpIEqual %bool %zero %c_u32_0\n"
7209 "OpSelectionMerge %exit DontFlatten\n"
7210 "OpBranchConditional %eq0 %then %else\n"
7213 ";This barrier should never be executed, but its presence makes test failure more likely when there's a bug.\n"
7214 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n"
7215 "%wrong_branch_alert = OpVectorInsertDynamic %v4f32 %param1 %c_f32_0_5 %c_i32_0\n"
7219 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n"
7223 "%ret = OpPhi %v4f32 %param1 %then %wrong_branch_alert %else\n"
7224 "OpReturnValue %ret\n"
7226 addTessCtrlTest(testGroup.get(), "in_if", fragments);
7228 // A barrier after control-flow reconvergence, tempting the compiler to attempt something like this:
7229 // http://lists.llvm.org/pipermail/llvm-dev/2009-October/026317.html.
7230 fragments["testfun"] =
7232 "%thread_id = OpLoad %i32 %BP_gl_InvocationID\n"
7233 "%thread0 = OpIEqual %bool %thread_id %c_i32_0\n"
7234 "OpSelectionMerge %exit DontFlatten\n"
7235 "OpBranchConditional %thread0 %then %else\n"
7238 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
7242 "%val1 = OpVectorExtractDynamic %f32 %param1 %zero\n"
7246 "%val = OpPhi %f32 %val0 %else %val1 %then\n"
7247 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n"
7248 "%ret = OpVectorInsertDynamic %v4f32 %param1 %val %zero\n"
7249 "OpReturnValue %ret\n"
7251 addTessCtrlTest(testGroup.get(), "after_divergent_if", fragments);
7253 // A barrier inside a loop.
7254 fragments["pre_main"] =
7255 "%Workgroup = OpConstant %i32 2\n"
7256 "%SequentiallyConsistent = OpConstant %i32 0x10\n"
7257 "%c_f32_10 = OpConstant %f32 10.\n";
7258 fragments["testfun"] =
7259 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
7260 "%param1 = OpFunctionParameter %v4f32\n"
7261 "%entry = OpLabel\n"
7262 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
7265 ";adds 4, 3, 2, and 1 to %val0\n"
7267 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %loop\n"
7268 "%val1 = OpPhi %f32 %val0 %entry %val %loop\n"
7269 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n"
7270 "%fcount = OpConvertSToF %f32 %count\n"
7271 "%val = OpFAdd %f32 %val1 %fcount\n"
7272 "%count__ = OpISub %i32 %count %c_i32_1\n"
7273 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
7274 "OpLoopMerge %exit %loop None\n"
7275 "OpBranchConditional %again %loop %exit\n"
7278 "%same = OpFSub %f32 %val %c_f32_10\n"
7279 "%ret = OpVectorInsertDynamic %v4f32 %param1 %same %c_i32_0\n"
7280 "OpReturnValue %ret\n"
7282 addTessCtrlTest(testGroup.get(), "in_loop", fragments);
7284 return testGroup.release();
7287 // Test for the OpFRem instruction.
7288 tcu::TestCaseGroup* createFRemTests(tcu::TestContext& testCtx)
7290 de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, "frem", "OpFRem"));
7291 map<string, string> fragments;
7292 RGBA inputColors[4];
7293 RGBA outputColors[4];
7295 fragments["pre_main"] =
7296 "%c_f32_3 = OpConstant %f32 3.0\n"
7297 "%c_f32_n3 = OpConstant %f32 -3.0\n"
7298 "%c_f32_4 = OpConstant %f32 4.0\n"
7299 "%c_f32_p75 = OpConstant %f32 0.75\n"
7300 "%c_v4f32_p75_p75_p75_p75 = OpConstantComposite %v4f32 %c_f32_p75 %c_f32_p75 %c_f32_p75 %c_f32_p75 \n"
7301 "%c_v4f32_4_4_4_4 = OpConstantComposite %v4f32 %c_f32_4 %c_f32_4 %c_f32_4 %c_f32_4\n"
7302 "%c_v4f32_3_n3_3_n3 = OpConstantComposite %v4f32 %c_f32_3 %c_f32_n3 %c_f32_3 %c_f32_n3\n";
7304 // The test does the following.
7305 // vec4 result = (param1 * 8.0) - 4.0;
7306 // return (frem(result.x,3) + 0.75, frem(result.y, -3) + 0.75, 0, 1)
7307 fragments["testfun"] =
7308 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
7309 "%param1 = OpFunctionParameter %v4f32\n"
7310 "%label_testfun = OpLabel\n"
7311 "%v_times_8 = OpVectorTimesScalar %v4f32 %param1 %c_f32_8\n"
7312 "%minus_4 = OpFSub %v4f32 %v_times_8 %c_v4f32_4_4_4_4\n"
7313 "%frem = OpFRem %v4f32 %minus_4 %c_v4f32_3_n3_3_n3\n"
7314 "%added = OpFAdd %v4f32 %frem %c_v4f32_p75_p75_p75_p75\n"
7315 "%xyz_1 = OpVectorInsertDynamic %v4f32 %added %c_f32_1 %c_i32_3\n"
7316 "%xy_0_1 = OpVectorInsertDynamic %v4f32 %xyz_1 %c_f32_0 %c_i32_2\n"
7317 "OpReturnValue %xy_0_1\n"
7321 inputColors[0] = RGBA(16, 16, 0, 255);
7322 inputColors[1] = RGBA(232, 232, 0, 255);
7323 inputColors[2] = RGBA(232, 16, 0, 255);
7324 inputColors[3] = RGBA(16, 232, 0, 255);
7326 outputColors[0] = RGBA(64, 64, 0, 255);
7327 outputColors[1] = RGBA(255, 255, 0, 255);
7328 outputColors[2] = RGBA(255, 64, 0, 255);
7329 outputColors[3] = RGBA(64, 255, 0, 255);
7331 createTestsForAllStages("frem", inputColors, outputColors, fragments, testGroup.get());
7332 return testGroup.release();
7335 // Test for the OpSRem instruction.
7336 tcu::TestCaseGroup* createOpSRemGraphicsTests(tcu::TestContext& testCtx, qpTestResult negFailResult)
7338 de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, "srem", "OpSRem"));
7339 map<string, string> fragments;
7341 fragments["pre_main"] =
7342 "%c_f32_255 = OpConstant %f32 255.0\n"
7343 "%c_i32_128 = OpConstant %i32 128\n"
7344 "%c_i32_255 = OpConstant %i32 255\n"
7345 "%c_v4f32_255 = OpConstantComposite %v4f32 %c_f32_255 %c_f32_255 %c_f32_255 %c_f32_255 \n"
7346 "%c_v4f32_0_5 = OpConstantComposite %v4f32 %c_f32_0_5 %c_f32_0_5 %c_f32_0_5 %c_f32_0_5 \n"
7347 "%c_v4i32_128 = OpConstantComposite %v4i32 %c_i32_128 %c_i32_128 %c_i32_128 %c_i32_128 \n";
7349 // The test does the following.
7350 // ivec4 ints = int(param1 * 255.0 + 0.5) - 128;
7351 // ivec4 result = ivec4(srem(ints.x, ints.y), srem(ints.y, ints.z), srem(ints.z, ints.x), 255);
7352 // return float(result + 128) / 255.0;
7353 fragments["testfun"] =
7354 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
7355 "%param1 = OpFunctionParameter %v4f32\n"
7356 "%label_testfun = OpLabel\n"
7357 "%div255 = OpFMul %v4f32 %param1 %c_v4f32_255\n"
7358 "%add0_5 = OpFAdd %v4f32 %div255 %c_v4f32_0_5\n"
7359 "%uints_in = OpConvertFToS %v4i32 %add0_5\n"
7360 "%ints_in = OpISub %v4i32 %uints_in %c_v4i32_128\n"
7361 "%x_in = OpCompositeExtract %i32 %ints_in 0\n"
7362 "%y_in = OpCompositeExtract %i32 %ints_in 1\n"
7363 "%z_in = OpCompositeExtract %i32 %ints_in 2\n"
7364 "%x_out = OpSRem %i32 %x_in %y_in\n"
7365 "%y_out = OpSRem %i32 %y_in %z_in\n"
7366 "%z_out = OpSRem %i32 %z_in %x_in\n"
7367 "%ints_out = OpCompositeConstruct %v4i32 %x_out %y_out %z_out %c_i32_255\n"
7368 "%ints_offset = OpIAdd %v4i32 %ints_out %c_v4i32_128\n"
7369 "%f_ints_offset = OpConvertSToF %v4f32 %ints_offset\n"
7370 "%float_out = OpFDiv %v4f32 %f_ints_offset %c_v4f32_255\n"
7371 "OpReturnValue %float_out\n"
7374 const struct CaseParams
7377 const char* failMessageTemplate; // customized status message
7378 qpTestResult failResult; // override status on failure
7379 int operands[4][3]; // four (x, y, z) vectors of operands
7380 int results[4][3]; // four (x, y, z) vectors of results
7386 QP_TEST_RESULT_FAIL,
7387 { { 5, 12, 17 }, { 5, 5, 7 }, { 75, 8, 81 }, { 25, 60, 100 } }, // operands
7388 { { 5, 12, 2 }, { 0, 5, 2 }, { 3, 8, 6 }, { 25, 60, 0 } }, // results
7392 "Inconsistent results, but within specification: ${reason}",
7393 negFailResult, // negative operands, not required by the spec
7394 { { 5, 12, -17 }, { -5, -5, 7 }, { 75, 8, -81 }, { 25, -60, 100 } }, // operands
7395 { { 5, 12, -2 }, { 0, -5, 2 }, { 3, 8, -6 }, { 25, -60, 0 } }, // results
7398 // If either operand is negative the result is undefined. Some implementations may still return correct values.
7400 for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(cases); ++caseNdx)
7402 const CaseParams& params = cases[caseNdx];
7403 RGBA inputColors[4];
7404 RGBA outputColors[4];
7406 for (int i = 0; i < 4; ++i)
7408 inputColors [i] = RGBA(params.operands[i][0] + 128, params.operands[i][1] + 128, params.operands[i][2] + 128, 255);
7409 outputColors[i] = RGBA(params.results [i][0] + 128, params.results [i][1] + 128, params.results [i][2] + 128, 255);
7412 createTestsForAllStages(params.name, inputColors, outputColors, fragments, testGroup.get(), params.failResult, params.failMessageTemplate);
7415 return testGroup.release();
7418 // Test for the OpSMod instruction.
7419 tcu::TestCaseGroup* createOpSModGraphicsTests(tcu::TestContext& testCtx, qpTestResult negFailResult)
7421 de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, "smod", "OpSMod"));
7422 map<string, string> fragments;
7424 fragments["pre_main"] =
7425 "%c_f32_255 = OpConstant %f32 255.0\n"
7426 "%c_i32_128 = OpConstant %i32 128\n"
7427 "%c_i32_255 = OpConstant %i32 255\n"
7428 "%c_v4f32_255 = OpConstantComposite %v4f32 %c_f32_255 %c_f32_255 %c_f32_255 %c_f32_255 \n"
7429 "%c_v4f32_0_5 = OpConstantComposite %v4f32 %c_f32_0_5 %c_f32_0_5 %c_f32_0_5 %c_f32_0_5 \n"
7430 "%c_v4i32_128 = OpConstantComposite %v4i32 %c_i32_128 %c_i32_128 %c_i32_128 %c_i32_128 \n";
7432 // The test does the following.
7433 // ivec4 ints = int(param1 * 255.0 + 0.5) - 128;
7434 // ivec4 result = ivec4(smod(ints.x, ints.y), smod(ints.y, ints.z), smod(ints.z, ints.x), 255);
7435 // return float(result + 128) / 255.0;
7436 fragments["testfun"] =
7437 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
7438 "%param1 = OpFunctionParameter %v4f32\n"
7439 "%label_testfun = OpLabel\n"
7440 "%div255 = OpFMul %v4f32 %param1 %c_v4f32_255\n"
7441 "%add0_5 = OpFAdd %v4f32 %div255 %c_v4f32_0_5\n"
7442 "%uints_in = OpConvertFToS %v4i32 %add0_5\n"
7443 "%ints_in = OpISub %v4i32 %uints_in %c_v4i32_128\n"
7444 "%x_in = OpCompositeExtract %i32 %ints_in 0\n"
7445 "%y_in = OpCompositeExtract %i32 %ints_in 1\n"
7446 "%z_in = OpCompositeExtract %i32 %ints_in 2\n"
7447 "%x_out = OpSMod %i32 %x_in %y_in\n"
7448 "%y_out = OpSMod %i32 %y_in %z_in\n"
7449 "%z_out = OpSMod %i32 %z_in %x_in\n"
7450 "%ints_out = OpCompositeConstruct %v4i32 %x_out %y_out %z_out %c_i32_255\n"
7451 "%ints_offset = OpIAdd %v4i32 %ints_out %c_v4i32_128\n"
7452 "%f_ints_offset = OpConvertSToF %v4f32 %ints_offset\n"
7453 "%float_out = OpFDiv %v4f32 %f_ints_offset %c_v4f32_255\n"
7454 "OpReturnValue %float_out\n"
7457 const struct CaseParams
7460 const char* failMessageTemplate; // customized status message
7461 qpTestResult failResult; // override status on failure
7462 int operands[4][3]; // four (x, y, z) vectors of operands
7463 int results[4][3]; // four (x, y, z) vectors of results
7469 QP_TEST_RESULT_FAIL,
7470 { { 5, 12, 17 }, { 5, 5, 7 }, { 75, 8, 81 }, { 25, 60, 100 } }, // operands
7471 { { 5, 12, 2 }, { 0, 5, 2 }, { 3, 8, 6 }, { 25, 60, 0 } }, // results
7475 "Inconsistent results, but within specification: ${reason}",
7476 negFailResult, // negative operands, not required by the spec
7477 { { 5, 12, -17 }, { -5, -5, 7 }, { 75, 8, -81 }, { 25, -60, 100 } }, // operands
7478 { { 5, -5, 3 }, { 0, 2, -3 }, { 3, -73, 69 }, { -35, 40, 0 } }, // results
7481 // If either operand is negative the result is undefined. Some implementations may still return correct values.
7483 for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(cases); ++caseNdx)
7485 const CaseParams& params = cases[caseNdx];
7486 RGBA inputColors[4];
7487 RGBA outputColors[4];
7489 for (int i = 0; i < 4; ++i)
7491 inputColors [i] = RGBA(params.operands[i][0] + 128, params.operands[i][1] + 128, params.operands[i][2] + 128, 255);
7492 outputColors[i] = RGBA(params.results [i][0] + 128, params.results [i][1] + 128, params.results [i][2] + 128, 255);
7495 createTestsForAllStages(params.name, inputColors, outputColors, fragments, testGroup.get(), params.failResult, params.failMessageTemplate);
7498 return testGroup.release();
7503 INTEGER_TYPE_SIGNED_16,
7504 INTEGER_TYPE_SIGNED_32,
7505 INTEGER_TYPE_SIGNED_64,
7507 INTEGER_TYPE_UNSIGNED_16,
7508 INTEGER_TYPE_UNSIGNED_32,
7509 INTEGER_TYPE_UNSIGNED_64,
7512 const string getBitWidthStr (IntegerType type)
7516 case INTEGER_TYPE_SIGNED_16:
7517 case INTEGER_TYPE_UNSIGNED_16: return "16";
7519 case INTEGER_TYPE_SIGNED_32:
7520 case INTEGER_TYPE_UNSIGNED_32: return "32";
7522 case INTEGER_TYPE_SIGNED_64:
7523 case INTEGER_TYPE_UNSIGNED_64: return "64";
7525 default: DE_ASSERT(false);
7530 const string getByteWidthStr (IntegerType type)
7534 case INTEGER_TYPE_SIGNED_16:
7535 case INTEGER_TYPE_UNSIGNED_16: return "2";
7537 case INTEGER_TYPE_SIGNED_32:
7538 case INTEGER_TYPE_UNSIGNED_32: return "4";
7540 case INTEGER_TYPE_SIGNED_64:
7541 case INTEGER_TYPE_UNSIGNED_64: return "8";
7543 default: DE_ASSERT(false);
7548 bool isSigned (IntegerType type)
7550 return (type <= INTEGER_TYPE_SIGNED_64);
7553 const string getTypeName (IntegerType type)
7555 string prefix = isSigned(type) ? "" : "u";
7556 return prefix + "int" + getBitWidthStr(type);
7559 const string getTestName (IntegerType from, IntegerType to)
7561 return getTypeName(from) + "_to_" + getTypeName(to);
7564 const string getAsmTypeDeclaration (IntegerType type)
7566 string sign = isSigned(type) ? " 1" : " 0";
7567 return "OpTypeInt " + getBitWidthStr(type) + sign;
7570 const string getAsmTypeName (IntegerType type)
7572 const string prefix = isSigned(type) ? "%i" : "%u";
7573 return prefix + getBitWidthStr(type);
7576 template<typename T>
7577 BufferSp getSpecializedBuffer (deInt64 number)
7579 return BufferSp(new Buffer<T>(vector<T>(1, (T)number)));
7582 BufferSp getBuffer (IntegerType type, deInt64 number)
7586 case INTEGER_TYPE_SIGNED_16: return getSpecializedBuffer<deInt16>(number);
7587 case INTEGER_TYPE_SIGNED_32: return getSpecializedBuffer<deInt32>(number);
7588 case INTEGER_TYPE_SIGNED_64: return getSpecializedBuffer<deInt64>(number);
7590 case INTEGER_TYPE_UNSIGNED_16: return getSpecializedBuffer<deUint16>(number);
7591 case INTEGER_TYPE_UNSIGNED_32: return getSpecializedBuffer<deUint32>(number);
7592 case INTEGER_TYPE_UNSIGNED_64: return getSpecializedBuffer<deUint64>(number);
7594 default: DE_ASSERT(false);
7595 return BufferSp(new Buffer<deInt32>(vector<deInt32>(1, 0)));
7599 bool usesInt16 (IntegerType from, IntegerType to)
7601 return (from == INTEGER_TYPE_SIGNED_16 || from == INTEGER_TYPE_UNSIGNED_16
7602 || to == INTEGER_TYPE_SIGNED_16 || to == INTEGER_TYPE_UNSIGNED_16);
7605 bool usesInt64 (IntegerType from, IntegerType to)
7607 return (from == INTEGER_TYPE_SIGNED_64 || from == INTEGER_TYPE_UNSIGNED_64
7608 || to == INTEGER_TYPE_SIGNED_64 || to == INTEGER_TYPE_UNSIGNED_64);
7611 ComputeTestFeatures getConversionUsedFeatures (IntegerType from, IntegerType to)
7613 if (usesInt16(from, to))
7615 if (usesInt64(from, to))
7617 return COMPUTE_TEST_USES_INT16_INT64;
7621 return COMPUTE_TEST_USES_INT16;
7626 return COMPUTE_TEST_USES_INT64;
7632 ConvertCase (IntegerType from, IntegerType to, deInt64 number)
7635 , m_features (getConversionUsedFeatures(from, to))
7636 , m_name (getTestName(from, to))
7637 , m_inputBuffer (getBuffer(from, number))
7638 , m_outputBuffer (getBuffer(to, number))
7640 m_asmTypes["inputType"] = getAsmTypeName(from);
7641 m_asmTypes["outputType"] = getAsmTypeName(to);
7643 if (m_features == COMPUTE_TEST_USES_INT16)
7645 m_asmTypes["int_capabilities"] = "OpCapability Int16\n";
7646 m_asmTypes["int_additional_decl"] = "%i16 = OpTypeInt 16 1\n%u16 = OpTypeInt 16 0\n";
7648 else if (m_features == COMPUTE_TEST_USES_INT64)
7650 m_asmTypes["int_capabilities"] = "OpCapability Int64\n";
7651 m_asmTypes["int_additional_decl"] = "%i64 = OpTypeInt 64 1\n%u64 = OpTypeInt 64 0\n";
7653 else if (m_features == COMPUTE_TEST_USES_INT16_INT64)
7655 m_asmTypes["int_capabilities"] = string("OpCapability Int16\n") +
7656 "OpCapability Int64\n";
7657 m_asmTypes["int_additional_decl"] = "%i16 = OpTypeInt 16 1\n%u16 = OpTypeInt 16 0\n"
7658 "%i64 = OpTypeInt 64 1\n%u64 = OpTypeInt 64 0\n";
7666 IntegerType m_fromType;
7667 IntegerType m_toType;
7668 ComputeTestFeatures m_features;
7670 map<string, string> m_asmTypes;
7671 BufferSp m_inputBuffer;
7672 BufferSp m_outputBuffer;
7675 const string getConvertCaseShaderStr (const string& instruction, const ConvertCase& convertCase)
7677 map<string, string> params = convertCase.m_asmTypes;
7679 params["instruction"] = instruction;
7681 params["inDecorator"] = getByteWidthStr(convertCase.m_fromType);
7682 params["outDecorator"] = getByteWidthStr(convertCase.m_toType);
7684 const StringTemplate shader (
7685 "OpCapability Shader\n"
7686 "${int_capabilities}"
7687 "OpMemoryModel Logical GLSL450\n"
7688 "OpEntryPoint GLCompute %main \"main\" %id\n"
7689 "OpExecutionMode %main LocalSize 1 1 1\n"
7690 "OpSource GLSL 430\n"
7691 "OpName %main \"main\"\n"
7692 "OpName %id \"gl_GlobalInvocationID\"\n"
7694 "OpDecorate %id BuiltIn GlobalInvocationId\n"
7695 "OpDecorate %indata DescriptorSet 0\n"
7696 "OpDecorate %indata Binding 0\n"
7697 "OpDecorate %outdata DescriptorSet 0\n"
7698 "OpDecorate %outdata Binding 1\n"
7699 "OpDecorate %in_arr ArrayStride ${inDecorator}\n"
7700 "OpDecorate %out_arr ArrayStride ${outDecorator}\n"
7701 "OpDecorate %in_buf BufferBlock\n"
7702 "OpDecorate %out_buf BufferBlock\n"
7703 "OpMemberDecorate %in_buf 0 Offset 0\n"
7704 "OpMemberDecorate %out_buf 0 Offset 0\n"
7706 "%void = OpTypeVoid\n"
7707 "%voidf = OpTypeFunction %void\n"
7708 "%u32 = OpTypeInt 32 0\n"
7709 "%i32 = OpTypeInt 32 1\n"
7710 "${int_additional_decl}"
7711 "%uvec3 = OpTypeVector %u32 3\n"
7712 "%uvec3ptr = OpTypePointer Input %uvec3\n"
7714 "%in_ptr = OpTypePointer Uniform ${inputType}\n"
7715 "%out_ptr = OpTypePointer Uniform ${outputType}\n"
7716 "%in_arr = OpTypeRuntimeArray ${inputType}\n"
7717 "%out_arr = OpTypeRuntimeArray ${outputType}\n"
7718 "%in_buf = OpTypeStruct %in_arr\n"
7719 "%out_buf = OpTypeStruct %out_arr\n"
7720 "%in_bufptr = OpTypePointer Uniform %in_buf\n"
7721 "%out_bufptr = OpTypePointer Uniform %out_buf\n"
7722 "%indata = OpVariable %in_bufptr Uniform\n"
7723 "%outdata = OpVariable %out_bufptr Uniform\n"
7724 "%inputptr = OpTypePointer Input ${inputType}\n"
7725 "%id = OpVariable %uvec3ptr Input\n"
7727 "%zero = OpConstant %i32 0\n"
7729 "%main = OpFunction %void None %voidf\n"
7730 "%label = OpLabel\n"
7731 "%idval = OpLoad %uvec3 %id\n"
7732 "%x = OpCompositeExtract %u32 %idval 0\n"
7733 "%inloc = OpAccessChain %in_ptr %indata %zero %x\n"
7734 "%outloc = OpAccessChain %out_ptr %outdata %zero %x\n"
7735 "%inval = OpLoad ${inputType} %inloc\n"
7736 "%conv = ${instruction} ${outputType} %inval\n"
7737 " OpStore %outloc %conv\n"
7742 return shader.specialize(params);
7745 void createSConvertCases (vector<ConvertCase>& testCases)
7747 // Convert int to int
7748 testCases.push_back(ConvertCase(INTEGER_TYPE_SIGNED_16, INTEGER_TYPE_SIGNED_32, 14669));
7749 testCases.push_back(ConvertCase(INTEGER_TYPE_SIGNED_16, INTEGER_TYPE_SIGNED_64, 3341));
7751 testCases.push_back(ConvertCase(INTEGER_TYPE_SIGNED_32, INTEGER_TYPE_SIGNED_64, 973610259));
7753 // Convert int to unsigned int
7754 testCases.push_back(ConvertCase(INTEGER_TYPE_SIGNED_16, INTEGER_TYPE_UNSIGNED_32, 9288));
7755 testCases.push_back(ConvertCase(INTEGER_TYPE_SIGNED_16, INTEGER_TYPE_UNSIGNED_64, 15460));
7757 testCases.push_back(ConvertCase(INTEGER_TYPE_SIGNED_32, INTEGER_TYPE_UNSIGNED_64, 346213461));
7760 // Test for the OpSConvert instruction.
7761 tcu::TestCaseGroup* createSConvertTests (tcu::TestContext& testCtx)
7763 const string instruction ("OpSConvert");
7764 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "sconvert", "OpSConvert"));
7765 vector<ConvertCase> testCases;
7766 createSConvertCases(testCases);
7768 for (vector<ConvertCase>::const_iterator test = testCases.begin(); test != testCases.end(); ++test)
7770 ComputeShaderSpec spec;
7772 spec.assembly = getConvertCaseShaderStr(instruction, *test);
7773 spec.inputs.push_back(test->m_inputBuffer);
7774 spec.outputs.push_back(test->m_outputBuffer);
7775 spec.numWorkGroups = IVec3(1, 1, 1);
7777 group->addChild(new SpvAsmComputeShaderCase(testCtx, test->m_name.c_str(), "Convert integers with OpSConvert.", spec, test->m_features));
7780 return group.release();
7783 void createUConvertCases (vector<ConvertCase>& testCases)
7785 // Convert unsigned int to unsigned int
7786 testCases.push_back(ConvertCase(INTEGER_TYPE_UNSIGNED_16, INTEGER_TYPE_UNSIGNED_32, 60653));
7787 testCases.push_back(ConvertCase(INTEGER_TYPE_UNSIGNED_16, INTEGER_TYPE_UNSIGNED_64, 17991));
7789 testCases.push_back(ConvertCase(INTEGER_TYPE_UNSIGNED_32, INTEGER_TYPE_UNSIGNED_64, 904256275));
7791 // Convert unsigned int to int
7792 testCases.push_back(ConvertCase(INTEGER_TYPE_UNSIGNED_16, INTEGER_TYPE_SIGNED_32, 38002));
7793 testCases.push_back(ConvertCase(INTEGER_TYPE_UNSIGNED_16, INTEGER_TYPE_SIGNED_64, 64921));
7795 testCases.push_back(ConvertCase(INTEGER_TYPE_UNSIGNED_32, INTEGER_TYPE_SIGNED_64, 4294956295ll));
7798 // Test for the OpUConvert instruction.
7799 tcu::TestCaseGroup* createUConvertTests (tcu::TestContext& testCtx)
7801 const string instruction ("OpUConvert");
7802 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "uconvert", "OpUConvert"));
7803 vector<ConvertCase> testCases;
7804 createUConvertCases(testCases);
7806 for (vector<ConvertCase>::const_iterator test = testCases.begin(); test != testCases.end(); ++test)
7808 ComputeShaderSpec spec;
7810 spec.assembly = getConvertCaseShaderStr(instruction, *test);
7811 spec.inputs.push_back(test->m_inputBuffer);
7812 spec.outputs.push_back(test->m_outputBuffer);
7813 spec.numWorkGroups = IVec3(1, 1, 1);
7815 group->addChild(new SpvAsmComputeShaderCase(testCtx, test->m_name.c_str(), "Convert integers with OpUConvert.", spec, test->m_features));
7817 return group.release();
7820 const string getNumberTypeName (const NumberType type)
7822 if (type == NUMBERTYPE_INT32)
7826 else if (type == NUMBERTYPE_UINT32)
7830 else if (type == NUMBERTYPE_FLOAT32)
7841 deInt32 getInt(de::Random& rnd)
7843 return rnd.getInt(std::numeric_limits<int>::min(), std::numeric_limits<int>::max());
7846 const string repeatString (const string& str, int times)
7849 for (int i = 0; i < times; ++i)
7856 const string getRandomConstantString (const NumberType type, de::Random& rnd)
7858 if (type == NUMBERTYPE_INT32)
7860 return numberToString<deInt32>(getInt(rnd));
7862 else if (type == NUMBERTYPE_UINT32)
7864 return numberToString<deUint32>(rnd.getUint32());
7866 else if (type == NUMBERTYPE_FLOAT32)
7868 return numberToString<float>(rnd.getFloat());
7877 void createVectorCompositeCases (vector<map<string, string> >& testCases, de::Random& rnd, const NumberType type)
7879 map<string, string> params;
7882 for (int width = 2; width <= 4; ++width)
7884 const string randomConst = numberToString(getInt(rnd));
7885 const string widthStr = numberToString(width);
7886 const string composite_type = "${customType}vec" + widthStr;
7887 const int index = rnd.getInt(0, width-1);
7889 params["type"] = "vec";
7890 params["name"] = params["type"] + "_" + widthStr;
7891 params["compositeDecl"] = composite_type + " = OpTypeVector ${customType} " + widthStr +"\n";
7892 params["compositeType"] = composite_type;
7893 params["filler"] = string("%filler = OpConstant ${customType} ") + getRandomConstantString(type, rnd) + "\n";
7894 params["compositeConstruct"] = "%instance = OpCompositeConstruct " + composite_type + repeatString(" %filler", width) + "\n";
7895 params["indexes"] = numberToString(index);
7896 testCases.push_back(params);
7900 void createArrayCompositeCases (vector<map<string, string> >& testCases, de::Random& rnd, const NumberType type)
7902 const int limit = 10;
7903 map<string, string> params;
7905 for (int width = 2; width <= limit; ++width)
7907 string randomConst = numberToString(getInt(rnd));
7908 string widthStr = numberToString(width);
7909 int index = rnd.getInt(0, width-1);
7911 params["type"] = "array";
7912 params["name"] = params["type"] + "_" + widthStr;
7913 params["compositeDecl"] = string("%arraywidth = OpConstant %u32 " + widthStr + "\n")
7914 + "%composite = OpTypeArray ${customType} %arraywidth\n";
7915 params["compositeType"] = "%composite";
7916 params["filler"] = string("%filler = OpConstant ${customType} ") + getRandomConstantString(type, rnd) + "\n";
7917 params["compositeConstruct"] = "%instance = OpCompositeConstruct %composite" + repeatString(" %filler", width) + "\n";
7918 params["indexes"] = numberToString(index);
7919 testCases.push_back(params);
7923 void createStructCompositeCases (vector<map<string, string> >& testCases, de::Random& rnd, const NumberType type)
7925 const int limit = 10;
7926 map<string, string> params;
7928 for (int width = 2; width <= limit; ++width)
7930 string randomConst = numberToString(getInt(rnd));
7931 int index = rnd.getInt(0, width-1);
7933 params["type"] = "struct";
7934 params["name"] = params["type"] + "_" + numberToString(width);
7935 params["compositeDecl"] = "%composite = OpTypeStruct" + repeatString(" ${customType}", width) + "\n";
7936 params["compositeType"] = "%composite";
7937 params["filler"] = string("%filler = OpConstant ${customType} ") + getRandomConstantString(type, rnd) + "\n";
7938 params["compositeConstruct"] = "%instance = OpCompositeConstruct %composite" + repeatString(" %filler", width) + "\n";
7939 params["indexes"] = numberToString(index);
7940 testCases.push_back(params);
7944 void createMatrixCompositeCases (vector<map<string, string> >& testCases, de::Random& rnd, const NumberType type)
7946 map<string, string> params;
7949 for (int width = 2; width <= 4; ++width)
7951 string widthStr = numberToString(width);
7953 for (int column = 2 ; column <= 4; ++column)
7955 int index_0 = rnd.getInt(0, column-1);
7956 int index_1 = rnd.getInt(0, width-1);
7957 string columnStr = numberToString(column);
7959 params["type"] = "matrix";
7960 params["name"] = params["type"] + "_" + widthStr + "x" + columnStr;
7961 params["compositeDecl"] = string("%vectype = OpTypeVector ${customType} " + widthStr + "\n")
7962 + "%composite = OpTypeMatrix %vectype " + columnStr + "\n";
7963 params["compositeType"] = "%composite";
7965 params["filler"] = string("%filler = OpConstant ${customType} ") + getRandomConstantString(type, rnd) + "\n"
7966 + "%fillerVec = OpConstantComposite %vectype" + repeatString(" %filler", width) + "\n";
7968 params["compositeConstruct"] = "%instance = OpCompositeConstruct %composite" + repeatString(" %fillerVec", column) + "\n";
7969 params["indexes"] = numberToString(index_0) + " " + numberToString(index_1);
7970 testCases.push_back(params);
7975 void createCompositeCases (vector<map<string, string> >& testCases, de::Random& rnd, const NumberType type)
7977 createVectorCompositeCases(testCases, rnd, type);
7978 createArrayCompositeCases(testCases, rnd, type);
7979 createStructCompositeCases(testCases, rnd, type);
7980 // Matrix only supports float types
7981 if (type == NUMBERTYPE_FLOAT32)
7983 createMatrixCompositeCases(testCases, rnd, type);
7987 const string getAssemblyTypeDeclaration (const NumberType type)
7991 case NUMBERTYPE_INT32: return "OpTypeInt 32 1";
7992 case NUMBERTYPE_UINT32: return "OpTypeInt 32 0";
7993 case NUMBERTYPE_FLOAT32: return "OpTypeFloat 32";
7994 default: DE_ASSERT(false); return "";
7998 const string getAssemblyTypeName (const NumberType type)
8002 case NUMBERTYPE_INT32: return "%i32";
8003 case NUMBERTYPE_UINT32: return "%u32";
8004 case NUMBERTYPE_FLOAT32: return "%f32";
8005 default: DE_ASSERT(false); return "";
8009 const string specializeCompositeInsertShaderTemplate (const NumberType type, const map<string, string>& params)
8011 map<string, string> parameters(params);
8013 const string customType = getAssemblyTypeName(type);
8014 map<string, string> substCustomType;
8015 substCustomType["customType"] = customType;
8016 parameters["compositeDecl"] = StringTemplate(parameters.at("compositeDecl")).specialize(substCustomType);
8017 parameters["compositeType"] = StringTemplate(parameters.at("compositeType")).specialize(substCustomType);
8018 parameters["compositeConstruct"] = StringTemplate(parameters.at("compositeConstruct")).specialize(substCustomType);
8019 parameters["filler"] = StringTemplate(parameters.at("filler")).specialize(substCustomType);
8020 parameters["customType"] = customType;
8021 parameters["compositeDecorator"] = (parameters["type"] == "array") ? "OpDecorate %composite ArrayStride 4\n" : "";
8023 if (parameters.at("compositeType") != "%u32vec3")
8025 parameters["u32vec3Decl"] = "%u32vec3 = OpTypeVector %u32 3\n";
8028 return StringTemplate(
8029 "OpCapability Shader\n"
8030 "OpCapability Matrix\n"
8031 "OpMemoryModel Logical GLSL450\n"
8032 "OpEntryPoint GLCompute %main \"main\" %id\n"
8033 "OpExecutionMode %main LocalSize 1 1 1\n"
8035 "OpSource GLSL 430\n"
8036 "OpName %main \"main\"\n"
8037 "OpName %id \"gl_GlobalInvocationID\"\n"
8040 "OpDecorate %id BuiltIn GlobalInvocationId\n"
8041 "OpDecorate %buf BufferBlock\n"
8042 "OpDecorate %indata DescriptorSet 0\n"
8043 "OpDecorate %indata Binding 0\n"
8044 "OpDecorate %outdata DescriptorSet 0\n"
8045 "OpDecorate %outdata Binding 1\n"
8046 "OpDecorate %customarr ArrayStride 4\n"
8047 "${compositeDecorator}"
8048 "OpMemberDecorate %buf 0 Offset 0\n"
8051 "%void = OpTypeVoid\n"
8052 "%voidf = OpTypeFunction %void\n"
8053 "%u32 = OpTypeInt 32 0\n"
8054 "%i32 = OpTypeInt 32 1\n"
8055 "%f32 = OpTypeFloat 32\n"
8057 // Composite declaration
8063 "${u32vec3Decl:opt}"
8064 "%uvec3ptr = OpTypePointer Input %u32vec3\n"
8066 // Inherited from custom
8067 "%customptr = OpTypePointer Uniform ${customType}\n"
8068 "%customarr = OpTypeRuntimeArray ${customType}\n"
8069 "%buf = OpTypeStruct %customarr\n"
8070 "%bufptr = OpTypePointer Uniform %buf\n"
8072 "%indata = OpVariable %bufptr Uniform\n"
8073 "%outdata = OpVariable %bufptr Uniform\n"
8075 "%id = OpVariable %uvec3ptr Input\n"
8076 "%zero = OpConstant %i32 0\n"
8078 "%main = OpFunction %void None %voidf\n"
8079 "%label = OpLabel\n"
8080 "%idval = OpLoad %u32vec3 %id\n"
8081 "%x = OpCompositeExtract %u32 %idval 0\n"
8083 "%inloc = OpAccessChain %customptr %indata %zero %x\n"
8084 "%outloc = OpAccessChain %customptr %outdata %zero %x\n"
8085 // Read the input value
8086 "%inval = OpLoad ${customType} %inloc\n"
8087 // Create the composite and fill it
8088 "${compositeConstruct}"
8089 // Insert the input value to a place
8090 "%instance2 = OpCompositeInsert ${compositeType} %inval %instance ${indexes}\n"
8091 // Read back the value from the position
8092 "%out_val = OpCompositeExtract ${customType} %instance2 ${indexes}\n"
8093 // Store it in the output position
8094 " OpStore %outloc %out_val\n"
8097 ).specialize(parameters);
8100 template<typename T>
8101 BufferSp createCompositeBuffer(T number)
8103 return BufferSp(new Buffer<T>(vector<T>(1, number)));
8106 tcu::TestCaseGroup* createOpCompositeInsertGroup (tcu::TestContext& testCtx)
8108 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opcompositeinsert", "Test the OpCompositeInsert instruction"));
8109 de::Random rnd (deStringHash(group->getName()));
8111 for (int type = NUMBERTYPE_INT32; type != NUMBERTYPE_END32; ++type)
8113 NumberType numberType = NumberType(type);
8114 const string typeName = getNumberTypeName(numberType);
8115 const string description = "Test the OpCompositeInsert instruction with " + typeName + "s";
8116 de::MovePtr<tcu::TestCaseGroup> subGroup (new tcu::TestCaseGroup(testCtx, typeName.c_str(), description.c_str()));
8117 vector<map<string, string> > testCases;
8119 createCompositeCases(testCases, rnd, numberType);
8121 for (vector<map<string, string> >::const_iterator test = testCases.begin(); test != testCases.end(); ++test)
8123 ComputeShaderSpec spec;
8125 spec.assembly = specializeCompositeInsertShaderTemplate(numberType, *test);
8129 case NUMBERTYPE_INT32:
8131 deInt32 number = getInt(rnd);
8132 spec.inputs.push_back(createCompositeBuffer<deInt32>(number));
8133 spec.outputs.push_back(createCompositeBuffer<deInt32>(number));
8136 case NUMBERTYPE_UINT32:
8138 deUint32 number = rnd.getUint32();
8139 spec.inputs.push_back(createCompositeBuffer<deUint32>(number));
8140 spec.outputs.push_back(createCompositeBuffer<deUint32>(number));
8143 case NUMBERTYPE_FLOAT32:
8145 float number = rnd.getFloat();
8146 spec.inputs.push_back(createCompositeBuffer<float>(number));
8147 spec.outputs.push_back(createCompositeBuffer<float>(number));
8154 spec.numWorkGroups = IVec3(1, 1, 1);
8155 subGroup->addChild(new SpvAsmComputeShaderCase(testCtx, test->at("name").c_str(), "OpCompositeInsert test", spec));
8157 group->addChild(subGroup.release());
8159 return group.release();
8162 struct AssemblyStructInfo
8164 AssemblyStructInfo (const deUint32 comp, const deUint32 idx)
8169 deUint32 components;
8173 const string specializeInBoundsShaderTemplate (const NumberType type, const AssemblyStructInfo& structInfo, const map<string, string>& params)
8175 // Create the full index string
8176 string fullIndex = numberToString(structInfo.index) + " " + params.at("indexes");
8177 // Convert it to list of indexes
8178 vector<string> indexes = de::splitString(fullIndex, ' ');
8180 map<string, string> parameters (params);
8181 parameters["structType"] = repeatString(" ${compositeType}", structInfo.components);
8182 parameters["structConstruct"] = repeatString(" %instance", structInfo.components);
8183 parameters["insertIndexes"] = fullIndex;
8185 // In matrix cases the last two index is the CompositeExtract indexes
8186 const deUint32 extractIndexes = (parameters["type"] == "matrix") ? 2 : 1;
8188 // Construct the extractIndex
8189 for (vector<string>::const_iterator index = indexes.end() - extractIndexes; index != indexes.end(); ++index)
8191 parameters["extractIndexes"] += " " + *index;
8194 // Remove the last 1 or 2 element depends on matrix case or not
8195 indexes.erase(indexes.end() - extractIndexes, indexes.end());
8198 // Generate AccessChain index expressions (except for the last one, because we use ptr to the composite)
8199 for (vector<string>::const_iterator index = indexes.begin(); index != indexes.end(); ++index)
8201 string indexId = "%index_" + numberToString(id++);
8202 parameters["accessChainConstDeclaration"] += indexId + " = OpConstant %u32 " + *index + "\n";
8203 parameters["accessChainIndexes"] += " " + indexId;
8206 parameters["compositeDecorator"] = (parameters["type"] == "array") ? "OpDecorate %composite ArrayStride 4\n" : "";
8208 const string customType = getAssemblyTypeName(type);
8209 map<string, string> substCustomType;
8210 substCustomType["customType"] = customType;
8211 parameters["compositeDecl"] = StringTemplate(parameters.at("compositeDecl")).specialize(substCustomType);
8212 parameters["compositeType"] = StringTemplate(parameters.at("compositeType")).specialize(substCustomType);
8213 parameters["compositeConstruct"] = StringTemplate(parameters.at("compositeConstruct")).specialize(substCustomType);
8214 parameters["filler"] = StringTemplate(parameters.at("filler")).specialize(substCustomType);
8215 parameters["customType"] = customType;
8217 const string compositeType = parameters.at("compositeType");
8218 map<string, string> substCompositeType;
8219 substCompositeType["compositeType"] = compositeType;
8220 parameters["structType"] = StringTemplate(parameters.at("structType")).specialize(substCompositeType);
8221 if (compositeType != "%u32vec3")
8223 parameters["u32vec3Decl"] = "%u32vec3 = OpTypeVector %u32 3\n";
8226 return StringTemplate(
8227 "OpCapability Shader\n"
8228 "OpCapability Matrix\n"
8229 "OpMemoryModel Logical GLSL450\n"
8230 "OpEntryPoint GLCompute %main \"main\" %id\n"
8231 "OpExecutionMode %main LocalSize 1 1 1\n"
8233 "OpSource GLSL 430\n"
8234 "OpName %main \"main\"\n"
8235 "OpName %id \"gl_GlobalInvocationID\"\n"
8237 "OpDecorate %id BuiltIn GlobalInvocationId\n"
8238 "OpDecorate %buf BufferBlock\n"
8239 "OpDecorate %indata DescriptorSet 0\n"
8240 "OpDecorate %indata Binding 0\n"
8241 "OpDecorate %outdata DescriptorSet 0\n"
8242 "OpDecorate %outdata Binding 1\n"
8243 "OpDecorate %customarr ArrayStride 4\n"
8244 "${compositeDecorator}"
8245 "OpMemberDecorate %buf 0 Offset 0\n"
8247 "%void = OpTypeVoid\n"
8248 "%voidf = OpTypeFunction %void\n"
8249 "%i32 = OpTypeInt 32 1\n"
8250 "%u32 = OpTypeInt 32 0\n"
8251 "%f32 = OpTypeFloat 32\n"
8254 // %u32vec3 if not already declared in ${compositeDecl}
8255 "${u32vec3Decl:opt}"
8256 "%uvec3ptr = OpTypePointer Input %u32vec3\n"
8257 // Inherited from composite
8258 "%composite_p = OpTypePointer Function ${compositeType}\n"
8259 "%struct_t = OpTypeStruct${structType}\n"
8260 "%struct_p = OpTypePointer Function %struct_t\n"
8263 "${accessChainConstDeclaration}"
8264 // Inherited from custom
8265 "%customptr = OpTypePointer Uniform ${customType}\n"
8266 "%customarr = OpTypeRuntimeArray ${customType}\n"
8267 "%buf = OpTypeStruct %customarr\n"
8268 "%bufptr = OpTypePointer Uniform %buf\n"
8269 "%indata = OpVariable %bufptr Uniform\n"
8270 "%outdata = OpVariable %bufptr Uniform\n"
8272 "%id = OpVariable %uvec3ptr Input\n"
8273 "%zero = OpConstant %u32 0\n"
8274 "%main = OpFunction %void None %voidf\n"
8275 "%label = OpLabel\n"
8276 "%struct_v = OpVariable %struct_p Function\n"
8277 "%idval = OpLoad %u32vec3 %id\n"
8278 "%x = OpCompositeExtract %u32 %idval 0\n"
8279 // Create the input/output type
8280 "%inloc = OpInBoundsAccessChain %customptr %indata %zero %x\n"
8281 "%outloc = OpInBoundsAccessChain %customptr %outdata %zero %x\n"
8282 // Read the input value
8283 "%inval = OpLoad ${customType} %inloc\n"
8284 // Create the composite and fill it
8285 "${compositeConstruct}"
8286 // Create the struct and fill it with the composite
8287 "%struct = OpCompositeConstruct %struct_t${structConstruct}\n"
8289 "%comp_obj = OpCompositeInsert %struct_t %inval %struct ${insertIndexes}\n"
8291 " OpStore %struct_v %comp_obj\n"
8292 // Get deepest possible composite pointer
8293 "%inner_ptr = OpInBoundsAccessChain %composite_p %struct_v${accessChainIndexes}\n"
8294 "%read_obj = OpLoad ${compositeType} %inner_ptr\n"
8295 // Read back the stored value
8296 "%read_val = OpCompositeExtract ${customType} %read_obj${extractIndexes}\n"
8297 " OpStore %outloc %read_val\n"
8300 ).specialize(parameters);
8303 tcu::TestCaseGroup* createOpInBoundsAccessChainGroup (tcu::TestContext& testCtx)
8305 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opinboundsaccesschain", "Test the OpInBoundsAccessChain instruction"));
8306 de::Random rnd (deStringHash(group->getName()));
8308 for (int type = NUMBERTYPE_INT32; type != NUMBERTYPE_END32; ++type)
8310 NumberType numberType = NumberType(type);
8311 const string typeName = getNumberTypeName(numberType);
8312 const string description = "Test the OpInBoundsAccessChain instruction with " + typeName + "s";
8313 de::MovePtr<tcu::TestCaseGroup> subGroup (new tcu::TestCaseGroup(testCtx, typeName.c_str(), description.c_str()));
8315 vector<map<string, string> > testCases;
8316 createCompositeCases(testCases, rnd, numberType);
8318 for (vector<map<string, string> >::const_iterator test = testCases.begin(); test != testCases.end(); ++test)
8320 ComputeShaderSpec spec;
8322 // Number of components inside of a struct
8323 deUint32 structComponents = rnd.getInt(2, 8);
8324 // Component index value
8325 deUint32 structIndex = rnd.getInt(0, structComponents - 1);
8326 AssemblyStructInfo structInfo(structComponents, structIndex);
8328 spec.assembly = specializeInBoundsShaderTemplate(numberType, structInfo, *test);
8332 case NUMBERTYPE_INT32:
8334 deInt32 number = getInt(rnd);
8335 spec.inputs.push_back(createCompositeBuffer<deInt32>(number));
8336 spec.outputs.push_back(createCompositeBuffer<deInt32>(number));
8339 case NUMBERTYPE_UINT32:
8341 deUint32 number = rnd.getUint32();
8342 spec.inputs.push_back(createCompositeBuffer<deUint32>(number));
8343 spec.outputs.push_back(createCompositeBuffer<deUint32>(number));
8346 case NUMBERTYPE_FLOAT32:
8348 float number = rnd.getFloat();
8349 spec.inputs.push_back(createCompositeBuffer<float>(number));
8350 spec.outputs.push_back(createCompositeBuffer<float>(number));
8356 spec.numWorkGroups = IVec3(1, 1, 1);
8357 subGroup->addChild(new SpvAsmComputeShaderCase(testCtx, test->at("name").c_str(), "OpInBoundsAccessChain test", spec));
8359 group->addChild(subGroup.release());
8361 return group.release();
8364 // If the params missing, uninitialized case
8365 const string specializeDefaultOutputShaderTemplate (const NumberType type, const map<string, string>& params = map<string, string>())
8367 map<string, string> parameters(params);
8369 parameters["customType"] = getAssemblyTypeName(type);
8371 // Declare the const value, and use it in the initializer
8372 if (params.find("constValue") != params.end())
8374 parameters["variableInitializer"] = " %const";
8376 // Uninitialized case
8379 parameters["commentDecl"] = ";";
8382 return StringTemplate(
8383 "OpCapability Shader\n"
8384 "OpMemoryModel Logical GLSL450\n"
8385 "OpEntryPoint GLCompute %main \"main\" %id\n"
8386 "OpExecutionMode %main LocalSize 1 1 1\n"
8387 "OpSource GLSL 430\n"
8388 "OpName %main \"main\"\n"
8389 "OpName %id \"gl_GlobalInvocationID\"\n"
8391 "OpDecorate %id BuiltIn GlobalInvocationId\n"
8392 "OpDecorate %indata DescriptorSet 0\n"
8393 "OpDecorate %indata Binding 0\n"
8394 "OpDecorate %outdata DescriptorSet 0\n"
8395 "OpDecorate %outdata Binding 1\n"
8396 "OpDecorate %in_arr ArrayStride 4\n"
8397 "OpDecorate %in_buf BufferBlock\n"
8398 "OpMemberDecorate %in_buf 0 Offset 0\n"
8400 "%void = OpTypeVoid\n"
8401 "%voidf = OpTypeFunction %void\n"
8402 "%u32 = OpTypeInt 32 0\n"
8403 "%i32 = OpTypeInt 32 1\n"
8404 "%f32 = OpTypeFloat 32\n"
8405 "%uvec3 = OpTypeVector %u32 3\n"
8406 "%uvec3ptr = OpTypePointer Input %uvec3\n"
8407 "${commentDecl:opt}%const = OpConstant ${customType} ${constValue:opt}\n"
8409 "%in_ptr = OpTypePointer Uniform ${customType}\n"
8410 "%in_arr = OpTypeRuntimeArray ${customType}\n"
8411 "%in_buf = OpTypeStruct %in_arr\n"
8412 "%in_bufptr = OpTypePointer Uniform %in_buf\n"
8413 "%indata = OpVariable %in_bufptr Uniform\n"
8414 "%outdata = OpVariable %in_bufptr Uniform\n"
8415 "%id = OpVariable %uvec3ptr Input\n"
8416 "%var_ptr = OpTypePointer Function ${customType}\n"
8418 "%zero = OpConstant %i32 0\n"
8420 "%main = OpFunction %void None %voidf\n"
8421 "%label = OpLabel\n"
8422 "%out_var = OpVariable %var_ptr Function${variableInitializer:opt}\n"
8423 "%idval = OpLoad %uvec3 %id\n"
8424 "%x = OpCompositeExtract %u32 %idval 0\n"
8425 "%inloc = OpAccessChain %in_ptr %indata %zero %x\n"
8426 "%outloc = OpAccessChain %in_ptr %outdata %zero %x\n"
8428 "%outval = OpLoad ${customType} %out_var\n"
8429 " OpStore %outloc %outval\n"
8432 ).specialize(parameters);
8435 bool compareFloats (const std::vector<BufferSp>&, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs, TestLog& log)
8437 DE_ASSERT(outputAllocs.size() != 0);
8438 DE_ASSERT(outputAllocs.size() == expectedOutputs.size());
8440 // Use custom epsilon because of the float->string conversion
8441 const float epsilon = 0.00001f;
8443 for (size_t outputNdx = 0; outputNdx < outputAllocs.size(); ++outputNdx)
8445 vector<deUint8> expectedBytes;
8449 expectedOutputs[outputNdx]->getBytes(expectedBytes);
8450 memcpy(&expected, &expectedBytes.front(), expectedBytes.size());
8451 memcpy(&actual, outputAllocs[outputNdx]->getHostPtr(), expectedBytes.size());
8453 // Test with epsilon
8454 if (fabs(expected - actual) > epsilon)
8456 log << TestLog::Message << "Error: The actual and expected values not matching."
8457 << " Expected: " << expected << " Actual: " << actual << " Epsilon: " << epsilon << TestLog::EndMessage;
8464 // Checks if the driver crash with uninitialized cases
8465 bool passthruVerify (const std::vector<BufferSp>&, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs, TestLog&)
8467 DE_ASSERT(outputAllocs.size() != 0);
8468 DE_ASSERT(outputAllocs.size() == expectedOutputs.size());
8470 // Copy and discard the result.
8471 for (size_t outputNdx = 0; outputNdx < outputAllocs.size(); ++outputNdx)
8473 vector<deUint8> expectedBytes;
8474 expectedOutputs[outputNdx]->getBytes(expectedBytes);
8476 const size_t width = expectedBytes.size();
8477 vector<char> data (width);
8479 memcpy(&data[0], outputAllocs[outputNdx]->getHostPtr(), width);
8484 tcu::TestCaseGroup* createShaderDefaultOutputGroup (tcu::TestContext& testCtx)
8486 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "shader_default_output", "Test shader default output."));
8487 de::Random rnd (deStringHash(group->getName()));
8489 for (int type = NUMBERTYPE_INT32; type != NUMBERTYPE_END32; ++type)
8491 NumberType numberType = NumberType(type);
8492 const string typeName = getNumberTypeName(numberType);
8493 const string description = "Test the OpVariable initializer with " + typeName + ".";
8494 de::MovePtr<tcu::TestCaseGroup> subGroup (new tcu::TestCaseGroup(testCtx, typeName.c_str(), description.c_str()));
8496 // 2 similar subcases (initialized and uninitialized)
8497 for (int subCase = 0; subCase < 2; ++subCase)
8499 ComputeShaderSpec spec;
8500 spec.numWorkGroups = IVec3(1, 1, 1);
8502 map<string, string> params;
8506 case NUMBERTYPE_INT32:
8508 deInt32 number = getInt(rnd);
8509 spec.inputs.push_back(createCompositeBuffer<deInt32>(number));
8510 spec.outputs.push_back(createCompositeBuffer<deInt32>(number));
8511 params["constValue"] = numberToString(number);
8514 case NUMBERTYPE_UINT32:
8516 deUint32 number = rnd.getUint32();
8517 spec.inputs.push_back(createCompositeBuffer<deUint32>(number));
8518 spec.outputs.push_back(createCompositeBuffer<deUint32>(number));
8519 params["constValue"] = numberToString(number);
8522 case NUMBERTYPE_FLOAT32:
8524 float number = rnd.getFloat();
8525 spec.inputs.push_back(createCompositeBuffer<float>(number));
8526 spec.outputs.push_back(createCompositeBuffer<float>(number));
8527 spec.verifyIO = &compareFloats;
8528 params["constValue"] = numberToString(number);
8535 // Initialized subcase
8538 spec.assembly = specializeDefaultOutputShaderTemplate(numberType, params);
8539 subGroup->addChild(new SpvAsmComputeShaderCase(testCtx, "initialized", "OpVariable initializer tests.", spec));
8541 // Uninitialized subcase
8544 spec.assembly = specializeDefaultOutputShaderTemplate(numberType);
8545 spec.verifyIO = &passthruVerify;
8546 subGroup->addChild(new SpvAsmComputeShaderCase(testCtx, "uninitialized", "OpVariable initializer tests.", spec));
8549 group->addChild(subGroup.release());
8551 return group.release();
8554 tcu::TestCaseGroup* createOpNopTests (tcu::TestContext& testCtx)
8556 de::MovePtr<tcu::TestCaseGroup> testGroup (new tcu::TestCaseGroup(testCtx, "opnop", "Test OpNop"));
8557 RGBA defaultColors[4];
8558 map<string, string> opNopFragments;
8560 getDefaultColors(defaultColors);
8562 opNopFragments["testfun"] =
8563 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
8564 "%param1 = OpFunctionParameter %v4f32\n"
8565 "%label_testfun = OpLabel\n"
8574 "%a = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
8575 "%b = OpFAdd %f32 %a %a\n"
8577 "%c = OpFSub %f32 %b %a\n"
8578 "%ret = OpVectorInsertDynamic %v4f32 %param1 %c %c_i32_0\n"
8581 "OpReturnValue %ret\n"
8584 createTestsForAllStages("opnop", defaultColors, defaultColors, opNopFragments, testGroup.get());
8586 return testGroup.release();
8589 tcu::TestCaseGroup* createInstructionTests (tcu::TestContext& testCtx)
8591 de::MovePtr<tcu::TestCaseGroup> instructionTests (new tcu::TestCaseGroup(testCtx, "instruction", "Instructions with special opcodes/operands"));
8592 de::MovePtr<tcu::TestCaseGroup> computeTests (new tcu::TestCaseGroup(testCtx, "compute", "Compute Instructions with special opcodes/operands"));
8593 de::MovePtr<tcu::TestCaseGroup> graphicsTests (new tcu::TestCaseGroup(testCtx, "graphics", "Graphics Instructions with special opcodes/operands"));
8595 computeTests->addChild(createOpNopGroup(testCtx));
8596 computeTests->addChild(createOpFUnordGroup(testCtx));
8597 computeTests->addChild(createOpAtomicGroup(testCtx, false));
8598 computeTests->addChild(createOpAtomicGroup(testCtx, true)); // Using new StorageBuffer decoration
8599 computeTests->addChild(createOpLineGroup(testCtx));
8600 computeTests->addChild(createOpNoLineGroup(testCtx));
8601 computeTests->addChild(createOpConstantNullGroup(testCtx));
8602 computeTests->addChild(createOpConstantCompositeGroup(testCtx));
8603 computeTests->addChild(createOpConstantUsageGroup(testCtx));
8604 computeTests->addChild(createSpecConstantGroup(testCtx));
8605 computeTests->addChild(createOpSourceGroup(testCtx));
8606 computeTests->addChild(createOpSourceExtensionGroup(testCtx));
8607 computeTests->addChild(createDecorationGroupGroup(testCtx));
8608 computeTests->addChild(createOpPhiGroup(testCtx));
8609 computeTests->addChild(createLoopControlGroup(testCtx));
8610 computeTests->addChild(createFunctionControlGroup(testCtx));
8611 computeTests->addChild(createSelectionControlGroup(testCtx));
8612 computeTests->addChild(createBlockOrderGroup(testCtx));
8613 computeTests->addChild(createMultipleShaderGroup(testCtx));
8614 computeTests->addChild(createMemoryAccessGroup(testCtx));
8615 computeTests->addChild(createOpCopyMemoryGroup(testCtx));
8616 computeTests->addChild(createOpCopyObjectGroup(testCtx));
8617 computeTests->addChild(createNoContractionGroup(testCtx));
8618 computeTests->addChild(createOpUndefGroup(testCtx));
8619 computeTests->addChild(createOpUnreachableGroup(testCtx));
8620 computeTests ->addChild(createOpQuantizeToF16Group(testCtx));
8621 computeTests ->addChild(createOpFRemGroup(testCtx));
8622 computeTests->addChild(createOpSRemComputeGroup(testCtx, QP_TEST_RESULT_PASS));
8623 computeTests->addChild(createOpSRemComputeGroup64(testCtx, QP_TEST_RESULT_PASS));
8624 computeTests->addChild(createOpSModComputeGroup(testCtx, QP_TEST_RESULT_PASS));
8625 computeTests->addChild(createOpSModComputeGroup64(testCtx, QP_TEST_RESULT_PASS));
8626 computeTests->addChild(createSConvertTests(testCtx));
8627 computeTests->addChild(createUConvertTests(testCtx));
8628 computeTests->addChild(createOpCompositeInsertGroup(testCtx));
8629 computeTests->addChild(createOpInBoundsAccessChainGroup(testCtx));
8630 computeTests->addChild(createShaderDefaultOutputGroup(testCtx));
8631 computeTests->addChild(createOpNMinGroup(testCtx));
8632 computeTests->addChild(createOpNMaxGroup(testCtx));
8633 computeTests->addChild(createOpNClampGroup(testCtx));
8635 de::MovePtr<tcu::TestCaseGroup> computeAndroidTests (new tcu::TestCaseGroup(testCtx, "android", "Android CTS Tests"));
8637 computeAndroidTests->addChild(createOpSRemComputeGroup(testCtx, QP_TEST_RESULT_QUALITY_WARNING));
8638 computeAndroidTests->addChild(createOpSModComputeGroup(testCtx, QP_TEST_RESULT_QUALITY_WARNING));
8640 computeTests->addChild(computeAndroidTests.release());
8643 computeTests->addChild(create16BitStorageComputeGroup(testCtx));
8644 computeTests->addChild(createUboMatrixPaddingComputeGroup(testCtx));
8645 computeTests->addChild(createConditionalBranchComputeGroup(testCtx));
8646 computeTests->addChild(createIndexingComputeGroup(testCtx));
8647 computeTests->addChild(createVariablePointersComputeGroup(testCtx));
8648 graphicsTests->addChild(createOpNopTests(testCtx));
8649 graphicsTests->addChild(createOpSourceTests(testCtx));
8650 graphicsTests->addChild(createOpSourceContinuedTests(testCtx));
8651 graphicsTests->addChild(createOpLineTests(testCtx));
8652 graphicsTests->addChild(createOpNoLineTests(testCtx));
8653 graphicsTests->addChild(createOpConstantNullTests(testCtx));
8654 graphicsTests->addChild(createOpConstantCompositeTests(testCtx));
8655 graphicsTests->addChild(createMemoryAccessTests(testCtx));
8656 graphicsTests->addChild(createOpUndefTests(testCtx));
8657 graphicsTests->addChild(createSelectionBlockOrderTests(testCtx));
8658 graphicsTests->addChild(createModuleTests(testCtx));
8659 graphicsTests->addChild(createSwitchBlockOrderTests(testCtx));
8660 graphicsTests->addChild(createOpPhiTests(testCtx));
8661 graphicsTests->addChild(createNoContractionTests(testCtx));
8662 graphicsTests->addChild(createOpQuantizeTests(testCtx));
8663 graphicsTests->addChild(createLoopTests(testCtx));
8664 graphicsTests->addChild(createSpecConstantTests(testCtx));
8665 graphicsTests->addChild(createSpecConstantOpQuantizeToF16Group(testCtx));
8666 graphicsTests->addChild(createBarrierTests(testCtx));
8667 graphicsTests->addChild(createDecorationGroupTests(testCtx));
8668 graphicsTests->addChild(createFRemTests(testCtx));
8669 graphicsTests->addChild(createOpSRemGraphicsTests(testCtx, QP_TEST_RESULT_PASS));
8670 graphicsTests->addChild(createOpSModGraphicsTests(testCtx, QP_TEST_RESULT_PASS));
8673 de::MovePtr<tcu::TestCaseGroup> graphicsAndroidTests (new tcu::TestCaseGroup(testCtx, "android", "Android CTS Tests"));
8675 graphicsAndroidTests->addChild(createOpSRemGraphicsTests(testCtx, QP_TEST_RESULT_QUALITY_WARNING));
8676 graphicsAndroidTests->addChild(createOpSModGraphicsTests(testCtx, QP_TEST_RESULT_QUALITY_WARNING));
8678 graphicsTests->addChild(graphicsAndroidTests.release());
8681 graphicsTests->addChild(create16BitStorageGraphicsGroup(testCtx));
8682 graphicsTests->addChild(createUboMatrixPaddingGraphicsGroup(testCtx));
8683 graphicsTests->addChild(createConditionalBranchGraphicsGroup(testCtx));
8684 graphicsTests->addChild(createIndexingGraphicsGroup(testCtx));
8685 graphicsTests->addChild(createVariablePointersGraphicsGroup(testCtx));
8687 instructionTests->addChild(computeTests.release());
8688 instructionTests->addChild(graphicsTests.release());
8690 return instructionTests.release();