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 "vktSpvAsmSpirvVersionTests.hpp"
61 #include "vktTestCaseUtil.hpp"
62 #include "vktSpvAsmLoopDepLenTests.hpp"
63 #include "vktSpvAsmLoopDepInfTests.hpp"
74 namespace SpirVAssembly
88 using tcu::TestStatus;
91 using tcu::StringTemplate;
95 static void fillRandomScalars (de::Random& rnd, T minValue, T maxValue, void* dst, int numValues, int offset = 0)
97 T* const typedPtr = (T*)dst;
98 for (int ndx = 0; ndx < numValues; ndx++)
99 typedPtr[offset + ndx] = randomScalar<T>(rnd, minValue, maxValue);
102 // Filter is a function that returns true if a value should pass, false otherwise.
103 template<typename T, typename FilterT>
104 static void fillRandomScalars (de::Random& rnd, T minValue, T maxValue, void* dst, int numValues, FilterT filter, int offset = 0)
106 T* const typedPtr = (T*)dst;
108 for (int ndx = 0; ndx < numValues; ndx++)
111 value = randomScalar<T>(rnd, minValue, maxValue);
112 while (!filter(value));
114 typedPtr[offset + ndx] = value;
118 // Gets a 64-bit integer with a more logarithmic distribution
119 deInt64 randomInt64LogDistributed (de::Random& rnd)
121 deInt64 val = rnd.getUint64();
122 val &= (1ull << rnd.getInt(1, 63)) - 1;
128 static void fillRandomInt64sLogDistributed (de::Random& rnd, vector<deInt64>& dst, int numValues)
130 for (int ndx = 0; ndx < numValues; ndx++)
131 dst[ndx] = randomInt64LogDistributed(rnd);
134 template<typename FilterT>
135 static void fillRandomInt64sLogDistributed (de::Random& rnd, vector<deInt64>& dst, int numValues, FilterT filter)
137 for (int ndx = 0; ndx < numValues; ndx++)
141 value = randomInt64LogDistributed(rnd);
142 } while (!filter(value));
147 inline bool filterNonNegative (const deInt64 value)
152 inline bool filterPositive (const deInt64 value)
157 inline bool filterNotZero (const deInt64 value)
162 static void floorAll (vector<float>& values)
164 for (size_t i = 0; i < values.size(); i++)
165 values[i] = deFloatFloor(values[i]);
168 static void floorAll (vector<Vec4>& values)
170 for (size_t i = 0; i < values.size(); i++)
171 values[i] = floor(values[i]);
179 CaseParameter (const char* case_, const string& param_) : name(case_), param(param_) {}
182 // Assembly code used for testing OpNop, OpConstant{Null|Composite}, Op[No]Line, OpSource[Continued], OpSourceExtension, OpUndef is based on GLSL source code:
186 // layout(std140, set = 0, binding = 0) readonly buffer Input {
189 // layout(std140, set = 0, binding = 1) writeonly buffer Output {
193 // layout (local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
196 // uint x = gl_GlobalInvocationID.x;
197 // output_data.elements[x] = -input_data.elements[x];
200 tcu::TestCaseGroup* createOpNopGroup (tcu::TestContext& testCtx)
202 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opnop", "Test the OpNop instruction"));
203 ComputeShaderSpec spec;
204 de::Random rnd (deStringHash(group->getName()));
205 const int numElements = 100;
206 vector<float> positiveFloats (numElements, 0);
207 vector<float> negativeFloats (numElements, 0);
209 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
211 for (size_t ndx = 0; ndx < numElements; ++ndx)
212 negativeFloats[ndx] = -positiveFloats[ndx];
215 string(getComputeAsmShaderPreamble()) +
217 "OpSource GLSL 430\n"
218 "OpName %main \"main\"\n"
219 "OpName %id \"gl_GlobalInvocationID\"\n"
221 "OpDecorate %id BuiltIn GlobalInvocationId\n"
223 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes())
225 + string(getComputeAsmInputOutputBuffer()) +
227 "%id = OpVariable %uvec3ptr Input\n"
228 "%zero = OpConstant %i32 0\n"
230 "%main = OpFunction %void None %voidf\n"
232 "%idval = OpLoad %uvec3 %id\n"
233 "%x = OpCompositeExtract %u32 %idval 0\n"
235 " OpNop\n" // Inside a function body
237 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
238 "%inval = OpLoad %f32 %inloc\n"
239 "%neg = OpFNegate %f32 %inval\n"
240 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
241 " OpStore %outloc %neg\n"
244 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
245 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
246 spec.numWorkGroups = IVec3(numElements, 1, 1);
248 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "OpNop appearing at different places", spec));
250 return group.release();
253 bool compareFUnord (const std::vector<BufferSp>& inputs, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs, TestLog& log)
255 if (outputAllocs.size() != 1)
258 vector<deUint8> input1Bytes;
259 vector<deUint8> input2Bytes;
260 vector<deUint8> expectedBytes;
262 inputs[0]->getBytes(input1Bytes);
263 inputs[1]->getBytes(input2Bytes);
264 expectedOutputs[0]->getBytes(expectedBytes);
266 const deInt32* const expectedOutputAsInt = reinterpret_cast<const deInt32* const>(&expectedBytes.front());
267 const deInt32* const outputAsInt = static_cast<const deInt32* const>(outputAllocs[0]->getHostPtr());
268 const float* const input1AsFloat = reinterpret_cast<const float* const>(&input1Bytes.front());
269 const float* const input2AsFloat = reinterpret_cast<const float* const>(&input2Bytes.front());
270 bool returnValue = true;
272 for (size_t idx = 0; idx < expectedBytes.size() / sizeof(deInt32); ++idx)
274 if (outputAsInt[idx] != expectedOutputAsInt[idx])
276 log << TestLog::Message << "ERROR: Sub-case failed. inputs: " << input1AsFloat[idx] << "," << input2AsFloat[idx] << " output: " << outputAsInt[idx]<< " expected output: " << expectedOutputAsInt[idx] << TestLog::EndMessage;
283 typedef VkBool32 (*compareFuncType) (float, float);
289 compareFuncType compareFunc;
291 OpFUnordCase (const char* _name, const char* _opCode, compareFuncType _compareFunc)
294 , compareFunc (_compareFunc) {}
297 #define ADD_OPFUNORD_CASE(NAME, OPCODE, OPERATOR) \
299 struct compare_##NAME { static VkBool32 compare(float x, float y) { return (x OPERATOR y) ? VK_TRUE : VK_FALSE; } }; \
300 cases.push_back(OpFUnordCase(#NAME, OPCODE, compare_##NAME::compare)); \
301 } while (deGetFalse())
303 tcu::TestCaseGroup* createOpFUnordGroup (tcu::TestContext& testCtx)
305 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opfunord", "Test the OpFUnord* opcodes"));
306 de::Random rnd (deStringHash(group->getName()));
307 const int numElements = 100;
308 vector<OpFUnordCase> cases;
310 const StringTemplate shaderTemplate (
312 string(getComputeAsmShaderPreamble()) +
314 "OpSource GLSL 430\n"
315 "OpName %main \"main\"\n"
316 "OpName %id \"gl_GlobalInvocationID\"\n"
318 "OpDecorate %id BuiltIn GlobalInvocationId\n"
320 "OpDecorate %buf BufferBlock\n"
321 "OpDecorate %buf2 BufferBlock\n"
322 "OpDecorate %indata1 DescriptorSet 0\n"
323 "OpDecorate %indata1 Binding 0\n"
324 "OpDecorate %indata2 DescriptorSet 0\n"
325 "OpDecorate %indata2 Binding 1\n"
326 "OpDecorate %outdata DescriptorSet 0\n"
327 "OpDecorate %outdata Binding 2\n"
328 "OpDecorate %f32arr ArrayStride 4\n"
329 "OpDecorate %i32arr ArrayStride 4\n"
330 "OpMemberDecorate %buf 0 Offset 0\n"
331 "OpMemberDecorate %buf2 0 Offset 0\n"
333 + string(getComputeAsmCommonTypes()) +
335 "%buf = OpTypeStruct %f32arr\n"
336 "%bufptr = OpTypePointer Uniform %buf\n"
337 "%indata1 = OpVariable %bufptr Uniform\n"
338 "%indata2 = OpVariable %bufptr Uniform\n"
340 "%buf2 = OpTypeStruct %i32arr\n"
341 "%buf2ptr = OpTypePointer Uniform %buf2\n"
342 "%outdata = OpVariable %buf2ptr Uniform\n"
344 "%id = OpVariable %uvec3ptr Input\n"
345 "%zero = OpConstant %i32 0\n"
346 "%consti1 = OpConstant %i32 1\n"
347 "%constf1 = OpConstant %f32 1.0\n"
349 "%main = OpFunction %void None %voidf\n"
351 "%idval = OpLoad %uvec3 %id\n"
352 "%x = OpCompositeExtract %u32 %idval 0\n"
354 "%inloc1 = OpAccessChain %f32ptr %indata1 %zero %x\n"
355 "%inval1 = OpLoad %f32 %inloc1\n"
356 "%inloc2 = OpAccessChain %f32ptr %indata2 %zero %x\n"
357 "%inval2 = OpLoad %f32 %inloc2\n"
358 "%outloc = OpAccessChain %i32ptr %outdata %zero %x\n"
360 "%result = ${OPCODE} %bool %inval1 %inval2\n"
361 "%int_res = OpSelect %i32 %result %consti1 %zero\n"
362 " OpStore %outloc %int_res\n"
367 ADD_OPFUNORD_CASE(equal, "OpFUnordEqual", ==);
368 ADD_OPFUNORD_CASE(less, "OpFUnordLessThan", <);
369 ADD_OPFUNORD_CASE(lessequal, "OpFUnordLessThanEqual", <=);
370 ADD_OPFUNORD_CASE(greater, "OpFUnordGreaterThan", >);
371 ADD_OPFUNORD_CASE(greaterequal, "OpFUnordGreaterThanEqual", >=);
372 ADD_OPFUNORD_CASE(notequal, "OpFUnordNotEqual", !=);
374 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
376 map<string, string> specializations;
377 ComputeShaderSpec spec;
378 const float NaN = std::numeric_limits<float>::quiet_NaN();
379 vector<float> inputFloats1 (numElements, 0);
380 vector<float> inputFloats2 (numElements, 0);
381 vector<deInt32> expectedInts (numElements, 0);
383 specializations["OPCODE"] = cases[caseNdx].opCode;
384 spec.assembly = shaderTemplate.specialize(specializations);
386 fillRandomScalars(rnd, 1.f, 100.f, &inputFloats1[0], numElements);
387 for (size_t ndx = 0; ndx < numElements; ++ndx)
391 case 0: inputFloats2[ndx] = inputFloats1[ndx] + 1.0f; break;
392 case 1: inputFloats2[ndx] = inputFloats1[ndx] - 1.0f; break;
393 case 2: inputFloats2[ndx] = inputFloats1[ndx]; break;
394 case 3: inputFloats2[ndx] = NaN; break;
395 case 4: inputFloats2[ndx] = inputFloats1[ndx]; inputFloats1[ndx] = NaN; break;
396 case 5: inputFloats2[ndx] = NaN; inputFloats1[ndx] = NaN; break;
398 expectedInts[ndx] = tcu::Float32(inputFloats1[ndx]).isNaN() || tcu::Float32(inputFloats2[ndx]).isNaN() || cases[caseNdx].compareFunc(inputFloats1[ndx], inputFloats2[ndx]);
401 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats1)));
402 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
403 spec.outputs.push_back(BufferSp(new Int32Buffer(expectedInts)));
404 spec.numWorkGroups = IVec3(numElements, 1, 1);
405 spec.verifyIO = &compareFUnord;
406 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
409 return group.release();
415 const char* assembly;
416 OpAtomicType opAtomic;
417 deInt32 numOutputElements;
419 OpAtomicCase (const char* _name, const char* _assembly, OpAtomicType _opAtomic, deInt32 _numOutputElements)
421 , assembly (_assembly)
422 , opAtomic (_opAtomic)
423 , numOutputElements (_numOutputElements) {}
426 tcu::TestCaseGroup* createOpAtomicGroup (tcu::TestContext& testCtx, bool useStorageBuffer)
428 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx,
429 useStorageBuffer ? "opatomic_storage_buffer" : "opatomic",
430 "Test the OpAtomic* opcodes"));
431 const int numElements = 65535;
432 vector<OpAtomicCase> cases;
434 const StringTemplate shaderTemplate (
436 string("OpCapability Shader\n") +
437 (useStorageBuffer ? "OpExtension \"SPV_KHR_storage_buffer_storage_class\"\n" : "") +
438 "OpMemoryModel Logical GLSL450\n"
439 "OpEntryPoint GLCompute %main \"main\" %id\n"
440 "OpExecutionMode %main LocalSize 1 1 1\n" +
442 "OpSource GLSL 430\n"
443 "OpName %main \"main\"\n"
444 "OpName %id \"gl_GlobalInvocationID\"\n"
446 "OpDecorate %id BuiltIn GlobalInvocationId\n"
448 "OpDecorate %buf ${BLOCK_DECORATION}\n"
449 "OpDecorate %indata DescriptorSet 0\n"
450 "OpDecorate %indata Binding 0\n"
451 "OpDecorate %i32arr ArrayStride 4\n"
452 "OpMemberDecorate %buf 0 Offset 0\n"
454 "OpDecorate %sumbuf ${BLOCK_DECORATION}\n"
455 "OpDecorate %sum DescriptorSet 0\n"
456 "OpDecorate %sum Binding 1\n"
457 "OpMemberDecorate %sumbuf 0 Coherent\n"
458 "OpMemberDecorate %sumbuf 0 Offset 0\n"
460 + getComputeAsmCommonTypes("${BLOCK_POINTER_TYPE}") +
462 "%buf = OpTypeStruct %i32arr\n"
463 "%bufptr = OpTypePointer ${BLOCK_POINTER_TYPE} %buf\n"
464 "%indata = OpVariable %bufptr ${BLOCK_POINTER_TYPE}\n"
466 "%sumbuf = OpTypeStruct %i32arr\n"
467 "%sumbufptr = OpTypePointer ${BLOCK_POINTER_TYPE} %sumbuf\n"
468 "%sum = OpVariable %sumbufptr ${BLOCK_POINTER_TYPE}\n"
470 "%id = OpVariable %uvec3ptr Input\n"
471 "%minusone = OpConstant %i32 -1\n"
472 "%zero = OpConstant %i32 0\n"
473 "%one = OpConstant %u32 1\n"
474 "%two = OpConstant %i32 2\n"
476 "%main = OpFunction %void None %voidf\n"
478 "%idval = OpLoad %uvec3 %id\n"
479 "%x = OpCompositeExtract %u32 %idval 0\n"
481 "%inloc = OpAccessChain %i32ptr %indata %zero %x\n"
482 "%inval = OpLoad %i32 %inloc\n"
484 "%outloc = OpAccessChain %i32ptr %sum %zero ${INDEX}\n"
490 #define ADD_OPATOMIC_CASE(NAME, ASSEMBLY, OPATOMIC, NUM_OUTPUT_ELEMENTS) \
492 DE_STATIC_ASSERT((NUM_OUTPUT_ELEMENTS) == 1 || (NUM_OUTPUT_ELEMENTS) == numElements); \
493 cases.push_back(OpAtomicCase(#NAME, ASSEMBLY, OPATOMIC, NUM_OUTPUT_ELEMENTS)); \
494 } while (deGetFalse())
495 #define ADD_OPATOMIC_CASE_1(NAME, ASSEMBLY, OPATOMIC) ADD_OPATOMIC_CASE(NAME, ASSEMBLY, OPATOMIC, 1)
496 #define ADD_OPATOMIC_CASE_N(NAME, ASSEMBLY, OPATOMIC) ADD_OPATOMIC_CASE(NAME, ASSEMBLY, OPATOMIC, numElements)
498 ADD_OPATOMIC_CASE_1(iadd, "%unused = OpAtomicIAdd %i32 %outloc %one %zero %inval\n", OPATOMIC_IADD );
499 ADD_OPATOMIC_CASE_1(isub, "%unused = OpAtomicISub %i32 %outloc %one %zero %inval\n", OPATOMIC_ISUB );
500 ADD_OPATOMIC_CASE_1(iinc, "%unused = OpAtomicIIncrement %i32 %outloc %one %zero\n", OPATOMIC_IINC );
501 ADD_OPATOMIC_CASE_1(idec, "%unused = OpAtomicIDecrement %i32 %outloc %one %zero\n", OPATOMIC_IDEC );
502 ADD_OPATOMIC_CASE_N(load, "%inval2 = OpAtomicLoad %i32 %inloc %zero %zero\n"
503 " OpStore %outloc %inval2\n", OPATOMIC_LOAD );
504 ADD_OPATOMIC_CASE_N(store, " OpAtomicStore %outloc %zero %zero %inval\n", OPATOMIC_STORE );
505 ADD_OPATOMIC_CASE_N(compex, "%even = OpSMod %i32 %inval %two\n"
506 " OpStore %outloc %even\n"
507 "%unused = OpAtomicCompareExchange %i32 %outloc %one %zero %zero %minusone %zero\n", OPATOMIC_COMPEX );
509 #undef ADD_OPATOMIC_CASE
510 #undef ADD_OPATOMIC_CASE_1
511 #undef ADD_OPATOMIC_CASE_N
513 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
515 map<string, string> specializations;
516 ComputeShaderSpec spec;
517 vector<deInt32> inputInts (numElements, 0);
518 vector<deInt32> expected (cases[caseNdx].numOutputElements, -1);
520 specializations["INDEX"] = (cases[caseNdx].numOutputElements == 1) ? "%zero" : "%x";
521 specializations["INSTRUCTION"] = cases[caseNdx].assembly;
522 specializations["BLOCK_DECORATION"] = useStorageBuffer ? "Block" : "BufferBlock";
523 specializations["BLOCK_POINTER_TYPE"] = useStorageBuffer ? "StorageBuffer" : "Uniform";
524 spec.assembly = shaderTemplate.specialize(specializations);
526 if (useStorageBuffer)
527 spec.extensions.push_back("VK_KHR_storage_buffer_storage_class");
529 spec.inputs.push_back(BufferSp(new OpAtomicBuffer(numElements, cases[caseNdx].numOutputElements, cases[caseNdx].opAtomic, BUFFERTYPE_INPUT)));
530 spec.outputs.push_back(BufferSp(new OpAtomicBuffer(numElements, cases[caseNdx].numOutputElements, cases[caseNdx].opAtomic, BUFFERTYPE_EXPECTED)));
531 spec.numWorkGroups = IVec3(numElements, 1, 1);
532 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
535 return group.release();
538 tcu::TestCaseGroup* createOpLineGroup (tcu::TestContext& testCtx)
540 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opline", "Test the OpLine instruction"));
541 ComputeShaderSpec spec;
542 de::Random rnd (deStringHash(group->getName()));
543 const int numElements = 100;
544 vector<float> positiveFloats (numElements, 0);
545 vector<float> negativeFloats (numElements, 0);
547 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
549 for (size_t ndx = 0; ndx < numElements; ++ndx)
550 negativeFloats[ndx] = -positiveFloats[ndx];
553 string(getComputeAsmShaderPreamble()) +
555 "%fname1 = OpString \"negateInputs.comp\"\n"
556 "%fname2 = OpString \"negateInputs\"\n"
558 "OpSource GLSL 430\n"
559 "OpName %main \"main\"\n"
560 "OpName %id \"gl_GlobalInvocationID\"\n"
562 "OpDecorate %id BuiltIn GlobalInvocationId\n"
564 + string(getComputeAsmInputOutputBufferTraits()) +
566 "OpLine %fname1 0 0\n" // At the earliest possible position
568 + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
570 "OpLine %fname1 0 1\n" // Multiple OpLines in sequence
571 "OpLine %fname2 1 0\n" // Different filenames
572 "OpLine %fname1 1000 100000\n"
574 "%id = OpVariable %uvec3ptr Input\n"
575 "%zero = OpConstant %i32 0\n"
577 "OpLine %fname1 1 1\n" // Before a function
579 "%main = OpFunction %void None %voidf\n"
582 "OpLine %fname1 1 1\n" // In a function
584 "%idval = OpLoad %uvec3 %id\n"
585 "%x = OpCompositeExtract %u32 %idval 0\n"
586 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
587 "%inval = OpLoad %f32 %inloc\n"
588 "%neg = OpFNegate %f32 %inval\n"
589 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
590 " OpStore %outloc %neg\n"
593 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
594 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
595 spec.numWorkGroups = IVec3(numElements, 1, 1);
597 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "OpLine appearing at different places", spec));
599 return group.release();
602 bool veryfiBinaryShader (const ProgramBinary& binary)
604 const size_t paternCount = 3u;
605 bool paternsCheck[paternCount] =
609 const string patersns[paternCount] =
615 size_t paternNdx = 0u;
617 for (size_t ndx = 0u; ndx < binary.getSize(); ++ndx)
619 if (false == paternsCheck[paternNdx] &&
620 patersns[paternNdx][0] == static_cast<char>(binary.getBinary()[ndx]) &&
621 deMemoryEqual((const char*)&binary.getBinary()[ndx], &patersns[paternNdx][0], patersns[paternNdx].length()))
623 paternsCheck[paternNdx]= true;
625 if (paternNdx == paternCount)
630 for (size_t ndx = 0u; ndx < paternCount; ++ndx)
632 if (!paternsCheck[ndx])
639 tcu::TestCaseGroup* createOpModuleProcessedGroup (tcu::TestContext& testCtx)
641 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opmoduleprocessed", "Test the OpModuleProcessed instruction"));
642 ComputeShaderSpec spec;
643 de::Random rnd (deStringHash(group->getName()));
644 const int numElements = 10;
645 vector<float> positiveFloats (numElements, 0);
646 vector<float> negativeFloats (numElements, 0);
648 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
650 for (size_t ndx = 0; ndx < numElements; ++ndx)
651 negativeFloats[ndx] = -positiveFloats[ndx];
654 string(getComputeAsmShaderPreamble()) +
655 "%fname = OpString \"negateInputs.comp\"\n"
657 "OpSource GLSL 430\n"
658 "OpName %main \"main\"\n"
659 "OpName %id \"gl_GlobalInvocationID\"\n"
660 "OpModuleProcessed \"VULKAN CTS\"\n" //OpModuleProcessed;
661 "OpModuleProcessed \"Negative values\"\n"
662 "OpModuleProcessed \"Date: 2017/09/21\"\n"
663 "OpDecorate %id BuiltIn GlobalInvocationId\n"
665 + string(getComputeAsmInputOutputBufferTraits())
667 + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
669 "OpLine %fname 0 1\n"
671 "OpLine %fname 1000 1\n"
673 "%id = OpVariable %uvec3ptr Input\n"
674 "%zero = OpConstant %i32 0\n"
675 "%main = OpFunction %void None %voidf\n"
678 "%idval = OpLoad %uvec3 %id\n"
679 "%x = OpCompositeExtract %u32 %idval 0\n"
681 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
682 "%inval = OpLoad %f32 %inloc\n"
683 "%neg = OpFNegate %f32 %inval\n"
684 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
685 " OpStore %outloc %neg\n"
688 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
689 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
690 spec.numWorkGroups = IVec3(numElements, 1, 1);
691 spec.verifyBinary = veryfiBinaryShader;
692 spec.spirvVersion = SPIRV_VERSION_1_3;
694 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "OpModuleProcessed Tests", spec));
696 return group.release();
699 tcu::TestCaseGroup* createOpNoLineGroup (tcu::TestContext& testCtx)
701 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opnoline", "Test the OpNoLine instruction"));
702 ComputeShaderSpec spec;
703 de::Random rnd (deStringHash(group->getName()));
704 const int numElements = 100;
705 vector<float> positiveFloats (numElements, 0);
706 vector<float> negativeFloats (numElements, 0);
708 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
710 for (size_t ndx = 0; ndx < numElements; ++ndx)
711 negativeFloats[ndx] = -positiveFloats[ndx];
714 string(getComputeAsmShaderPreamble()) +
716 "%fname = OpString \"negateInputs.comp\"\n"
718 "OpSource GLSL 430\n"
719 "OpName %main \"main\"\n"
720 "OpName %id \"gl_GlobalInvocationID\"\n"
722 "OpDecorate %id BuiltIn GlobalInvocationId\n"
724 + string(getComputeAsmInputOutputBufferTraits()) +
726 "OpNoLine\n" // At the earliest possible position, without preceding OpLine
728 + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
730 "OpLine %fname 0 1\n"
731 "OpNoLine\n" // Immediately following a preceding OpLine
733 "OpLine %fname 1000 1\n"
735 "%id = OpVariable %uvec3ptr Input\n"
736 "%zero = OpConstant %i32 0\n"
738 "OpNoLine\n" // Contents after the previous OpLine
740 "%main = OpFunction %void None %voidf\n"
742 "%idval = OpLoad %uvec3 %id\n"
743 "%x = OpCompositeExtract %u32 %idval 0\n"
745 "OpNoLine\n" // Multiple OpNoLine
749 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
750 "%inval = OpLoad %f32 %inloc\n"
751 "%neg = OpFNegate %f32 %inval\n"
752 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
753 " OpStore %outloc %neg\n"
756 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
757 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
758 spec.numWorkGroups = IVec3(numElements, 1, 1);
760 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "OpNoLine appearing at different places", spec));
762 return group.release();
765 // Compare instruction for the contraction compute case.
766 // Returns true if the output is what is expected from the test case.
767 bool compareNoContractCase(const std::vector<BufferSp>&, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs, TestLog&)
769 if (outputAllocs.size() != 1)
772 // Only size is needed because we are not comparing the exact values.
773 size_t byteSize = expectedOutputs[0]->getByteSize();
775 const float* outputAsFloat = static_cast<const float*>(outputAllocs[0]->getHostPtr());
777 for(size_t i = 0; i < byteSize / sizeof(float); ++i) {
778 if (outputAsFloat[i] != 0.f &&
779 outputAsFloat[i] != -ldexp(1, -24)) {
787 tcu::TestCaseGroup* createNoContractionGroup (tcu::TestContext& testCtx)
789 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "nocontraction", "Test the NoContraction decoration"));
790 vector<CaseParameter> cases;
791 const int numElements = 100;
792 vector<float> inputFloats1 (numElements, 0);
793 vector<float> inputFloats2 (numElements, 0);
794 vector<float> outputFloats (numElements, 0);
795 const StringTemplate shaderTemplate (
796 string(getComputeAsmShaderPreamble()) +
798 "OpName %main \"main\"\n"
799 "OpName %id \"gl_GlobalInvocationID\"\n"
801 "OpDecorate %id BuiltIn GlobalInvocationId\n"
805 "OpDecorate %buf BufferBlock\n"
806 "OpDecorate %indata1 DescriptorSet 0\n"
807 "OpDecorate %indata1 Binding 0\n"
808 "OpDecorate %indata2 DescriptorSet 0\n"
809 "OpDecorate %indata2 Binding 1\n"
810 "OpDecorate %outdata DescriptorSet 0\n"
811 "OpDecorate %outdata Binding 2\n"
812 "OpDecorate %f32arr ArrayStride 4\n"
813 "OpMemberDecorate %buf 0 Offset 0\n"
815 + string(getComputeAsmCommonTypes()) +
817 "%buf = OpTypeStruct %f32arr\n"
818 "%bufptr = OpTypePointer Uniform %buf\n"
819 "%indata1 = OpVariable %bufptr Uniform\n"
820 "%indata2 = OpVariable %bufptr Uniform\n"
821 "%outdata = OpVariable %bufptr Uniform\n"
823 "%id = OpVariable %uvec3ptr Input\n"
824 "%zero = OpConstant %i32 0\n"
825 "%c_f_m1 = OpConstant %f32 -1.\n"
827 "%main = OpFunction %void None %voidf\n"
829 "%idval = OpLoad %uvec3 %id\n"
830 "%x = OpCompositeExtract %u32 %idval 0\n"
831 "%inloc1 = OpAccessChain %f32ptr %indata1 %zero %x\n"
832 "%inval1 = OpLoad %f32 %inloc1\n"
833 "%inloc2 = OpAccessChain %f32ptr %indata2 %zero %x\n"
834 "%inval2 = OpLoad %f32 %inloc2\n"
835 "%mul = OpFMul %f32 %inval1 %inval2\n"
836 "%add = OpFAdd %f32 %mul %c_f_m1\n"
837 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
838 " OpStore %outloc %add\n"
842 cases.push_back(CaseParameter("multiplication", "OpDecorate %mul NoContraction"));
843 cases.push_back(CaseParameter("addition", "OpDecorate %add NoContraction"));
844 cases.push_back(CaseParameter("both", "OpDecorate %mul NoContraction\nOpDecorate %add NoContraction"));
846 for (size_t ndx = 0; ndx < numElements; ++ndx)
848 inputFloats1[ndx] = 1.f + std::ldexp(1.f, -23); // 1 + 2^-23.
849 inputFloats2[ndx] = 1.f - std::ldexp(1.f, -23); // 1 - 2^-23.
850 // Result for (1 + 2^-23) * (1 - 2^-23) - 1. With NoContraction, the multiplication will be
851 // conducted separately and the result is rounded to 1, or 0x1.fffffcp-1
852 // So the final result will be 0.f or 0x1p-24.
853 // If the operation is combined into a precise fused multiply-add, then the result would be
854 // 2^-46 (0xa8800000).
855 outputFloats[ndx] = 0.f;
858 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
860 map<string, string> specializations;
861 ComputeShaderSpec spec;
863 specializations["DECORATION"] = cases[caseNdx].param;
864 spec.assembly = shaderTemplate.specialize(specializations);
865 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats1)));
866 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
867 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
868 spec.numWorkGroups = IVec3(numElements, 1, 1);
869 // Check against the two possible answers based on rounding mode.
870 spec.verifyIO = &compareNoContractCase;
872 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
874 return group.release();
877 bool compareFRem(const std::vector<BufferSp>&, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs, TestLog&)
879 if (outputAllocs.size() != 1)
882 vector<deUint8> expectedBytes;
883 expectedOutputs[0]->getBytes(expectedBytes);
885 const float* expectedOutputAsFloat = reinterpret_cast<const float*>(&expectedBytes.front());
886 const float* outputAsFloat = static_cast<const float*>(outputAllocs[0]->getHostPtr());
888 for (size_t idx = 0; idx < expectedBytes.size() / sizeof(float); ++idx)
890 const float f0 = expectedOutputAsFloat[idx];
891 const float f1 = outputAsFloat[idx];
892 // \todo relative error needs to be fairly high because FRem may be implemented as
893 // (roughly) frac(a/b)*b, so LSB errors can be magnified. But this should be fine for now.
894 if (deFloatAbs((f1 - f0) / f0) > 0.02)
901 tcu::TestCaseGroup* createOpFRemGroup (tcu::TestContext& testCtx)
903 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opfrem", "Test the OpFRem instruction"));
904 ComputeShaderSpec spec;
905 de::Random rnd (deStringHash(group->getName()));
906 const int numElements = 200;
907 vector<float> inputFloats1 (numElements, 0);
908 vector<float> inputFloats2 (numElements, 0);
909 vector<float> outputFloats (numElements, 0);
911 fillRandomScalars(rnd, -10000.f, 10000.f, &inputFloats1[0], numElements);
912 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats2[0], numElements);
914 for (size_t ndx = 0; ndx < numElements; ++ndx)
916 // Guard against divisors near zero.
917 if (std::fabs(inputFloats2[ndx]) < 1e-3)
918 inputFloats2[ndx] = 8.f;
920 // The return value of std::fmod() has the same sign as its first operand, which is how OpFRem spec'd.
921 outputFloats[ndx] = std::fmod(inputFloats1[ndx], inputFloats2[ndx]);
925 string(getComputeAsmShaderPreamble()) +
927 "OpName %main \"main\"\n"
928 "OpName %id \"gl_GlobalInvocationID\"\n"
930 "OpDecorate %id BuiltIn GlobalInvocationId\n"
932 "OpDecorate %buf BufferBlock\n"
933 "OpDecorate %indata1 DescriptorSet 0\n"
934 "OpDecorate %indata1 Binding 0\n"
935 "OpDecorate %indata2 DescriptorSet 0\n"
936 "OpDecorate %indata2 Binding 1\n"
937 "OpDecorate %outdata DescriptorSet 0\n"
938 "OpDecorate %outdata Binding 2\n"
939 "OpDecorate %f32arr ArrayStride 4\n"
940 "OpMemberDecorate %buf 0 Offset 0\n"
942 + string(getComputeAsmCommonTypes()) +
944 "%buf = OpTypeStruct %f32arr\n"
945 "%bufptr = OpTypePointer Uniform %buf\n"
946 "%indata1 = OpVariable %bufptr Uniform\n"
947 "%indata2 = OpVariable %bufptr Uniform\n"
948 "%outdata = OpVariable %bufptr Uniform\n"
950 "%id = OpVariable %uvec3ptr Input\n"
951 "%zero = OpConstant %i32 0\n"
953 "%main = OpFunction %void None %voidf\n"
955 "%idval = OpLoad %uvec3 %id\n"
956 "%x = OpCompositeExtract %u32 %idval 0\n"
957 "%inloc1 = OpAccessChain %f32ptr %indata1 %zero %x\n"
958 "%inval1 = OpLoad %f32 %inloc1\n"
959 "%inloc2 = OpAccessChain %f32ptr %indata2 %zero %x\n"
960 "%inval2 = OpLoad %f32 %inloc2\n"
961 "%rem = OpFRem %f32 %inval1 %inval2\n"
962 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
963 " OpStore %outloc %rem\n"
967 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats1)));
968 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
969 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
970 spec.numWorkGroups = IVec3(numElements, 1, 1);
971 spec.verifyIO = &compareFRem;
973 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "", spec));
975 return group.release();
978 bool compareNMin (const std::vector<BufferSp>&, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs, TestLog&)
980 if (outputAllocs.size() != 1)
983 const BufferSp& expectedOutput (expectedOutputs[0]);
984 std::vector<deUint8> data;
985 expectedOutput->getBytes(data);
987 const float* const expectedOutputAsFloat = reinterpret_cast<const float*>(&data.front());
988 const float* const outputAsFloat = static_cast<const float*>(outputAllocs[0]->getHostPtr());
990 for (size_t idx = 0; idx < expectedOutput->getByteSize() / sizeof(float); ++idx)
992 const float f0 = expectedOutputAsFloat[idx];
993 const float f1 = outputAsFloat[idx];
995 // For NMin, we accept NaN as output if both inputs were NaN.
996 // Otherwise the NaN is the wrong choise, as on architectures that
997 // do not handle NaN, those are huge values.
998 if (!(tcu::Float32(f1).isNaN() && tcu::Float32(f0).isNaN()) && deFloatAbs(f1 - f0) > 0.00001f)
1005 tcu::TestCaseGroup* createOpNMinGroup (tcu::TestContext& testCtx)
1007 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opnmin", "Test the OpNMin instruction"));
1008 ComputeShaderSpec spec;
1009 de::Random rnd (deStringHash(group->getName()));
1010 const int numElements = 200;
1011 vector<float> inputFloats1 (numElements, 0);
1012 vector<float> inputFloats2 (numElements, 0);
1013 vector<float> outputFloats (numElements, 0);
1015 fillRandomScalars(rnd, -10000.f, 10000.f, &inputFloats1[0], numElements);
1016 fillRandomScalars(rnd, -10000.f, 10000.f, &inputFloats2[0], numElements);
1018 // Make the first case a full-NAN case.
1019 inputFloats1[0] = TCU_NAN;
1020 inputFloats2[0] = TCU_NAN;
1022 for (size_t ndx = 0; ndx < numElements; ++ndx)
1024 // By default, pick the smallest
1025 outputFloats[ndx] = std::min(inputFloats1[ndx], inputFloats2[ndx]);
1027 // Make half of the cases NaN cases
1030 // Alternate between the NaN operand
1033 outputFloats[ndx] = inputFloats2[ndx];
1034 inputFloats1[ndx] = TCU_NAN;
1038 outputFloats[ndx] = inputFloats1[ndx];
1039 inputFloats2[ndx] = TCU_NAN;
1045 "OpCapability Shader\n"
1046 "%std450 = OpExtInstImport \"GLSL.std.450\"\n"
1047 "OpMemoryModel Logical GLSL450\n"
1048 "OpEntryPoint GLCompute %main \"main\" %id\n"
1049 "OpExecutionMode %main LocalSize 1 1 1\n"
1051 "OpName %main \"main\"\n"
1052 "OpName %id \"gl_GlobalInvocationID\"\n"
1054 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1056 "OpDecorate %buf BufferBlock\n"
1057 "OpDecorate %indata1 DescriptorSet 0\n"
1058 "OpDecorate %indata1 Binding 0\n"
1059 "OpDecorate %indata2 DescriptorSet 0\n"
1060 "OpDecorate %indata2 Binding 1\n"
1061 "OpDecorate %outdata DescriptorSet 0\n"
1062 "OpDecorate %outdata Binding 2\n"
1063 "OpDecorate %f32arr ArrayStride 4\n"
1064 "OpMemberDecorate %buf 0 Offset 0\n"
1066 + string(getComputeAsmCommonTypes()) +
1068 "%buf = OpTypeStruct %f32arr\n"
1069 "%bufptr = OpTypePointer Uniform %buf\n"
1070 "%indata1 = OpVariable %bufptr Uniform\n"
1071 "%indata2 = OpVariable %bufptr Uniform\n"
1072 "%outdata = OpVariable %bufptr Uniform\n"
1074 "%id = OpVariable %uvec3ptr Input\n"
1075 "%zero = OpConstant %i32 0\n"
1077 "%main = OpFunction %void None %voidf\n"
1078 "%label = OpLabel\n"
1079 "%idval = OpLoad %uvec3 %id\n"
1080 "%x = OpCompositeExtract %u32 %idval 0\n"
1081 "%inloc1 = OpAccessChain %f32ptr %indata1 %zero %x\n"
1082 "%inval1 = OpLoad %f32 %inloc1\n"
1083 "%inloc2 = OpAccessChain %f32ptr %indata2 %zero %x\n"
1084 "%inval2 = OpLoad %f32 %inloc2\n"
1085 "%rem = OpExtInst %f32 %std450 NMin %inval1 %inval2\n"
1086 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
1087 " OpStore %outloc %rem\n"
1091 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats1)));
1092 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
1093 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
1094 spec.numWorkGroups = IVec3(numElements, 1, 1);
1095 spec.verifyIO = &compareNMin;
1097 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "", spec));
1099 return group.release();
1102 bool compareNMax (const std::vector<BufferSp>&, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs, TestLog&)
1104 if (outputAllocs.size() != 1)
1107 const BufferSp& expectedOutput = expectedOutputs[0];
1108 std::vector<deUint8> data;
1109 expectedOutput->getBytes(data);
1111 const float* const expectedOutputAsFloat = reinterpret_cast<const float*>(&data.front());
1112 const float* const outputAsFloat = static_cast<const float*>(outputAllocs[0]->getHostPtr());
1114 for (size_t idx = 0; idx < expectedOutput->getByteSize() / sizeof(float); ++idx)
1116 const float f0 = expectedOutputAsFloat[idx];
1117 const float f1 = outputAsFloat[idx];
1119 // For NMax, NaN is considered acceptable result, since in
1120 // architectures that do not handle NaNs, those are huge values.
1121 if (!tcu::Float32(f1).isNaN() && deFloatAbs(f1 - f0) > 0.00001f)
1128 tcu::TestCaseGroup* createOpNMaxGroup (tcu::TestContext& testCtx)
1130 de::MovePtr<tcu::TestCaseGroup> group(new tcu::TestCaseGroup(testCtx, "opnmax", "Test the OpNMax instruction"));
1131 ComputeShaderSpec spec;
1132 de::Random rnd (deStringHash(group->getName()));
1133 const int numElements = 200;
1134 vector<float> inputFloats1 (numElements, 0);
1135 vector<float> inputFloats2 (numElements, 0);
1136 vector<float> outputFloats (numElements, 0);
1138 fillRandomScalars(rnd, -10000.f, 10000.f, &inputFloats1[0], numElements);
1139 fillRandomScalars(rnd, -10000.f, 10000.f, &inputFloats2[0], numElements);
1141 // Make the first case a full-NAN case.
1142 inputFloats1[0] = TCU_NAN;
1143 inputFloats2[0] = TCU_NAN;
1145 for (size_t ndx = 0; ndx < numElements; ++ndx)
1147 // By default, pick the biggest
1148 outputFloats[ndx] = std::max(inputFloats1[ndx], inputFloats2[ndx]);
1150 // Make half of the cases NaN cases
1153 // Alternate between the NaN operand
1156 outputFloats[ndx] = inputFloats2[ndx];
1157 inputFloats1[ndx] = TCU_NAN;
1161 outputFloats[ndx] = inputFloats1[ndx];
1162 inputFloats2[ndx] = TCU_NAN;
1168 "OpCapability Shader\n"
1169 "%std450 = OpExtInstImport \"GLSL.std.450\"\n"
1170 "OpMemoryModel Logical GLSL450\n"
1171 "OpEntryPoint GLCompute %main \"main\" %id\n"
1172 "OpExecutionMode %main LocalSize 1 1 1\n"
1174 "OpName %main \"main\"\n"
1175 "OpName %id \"gl_GlobalInvocationID\"\n"
1177 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1179 "OpDecorate %buf BufferBlock\n"
1180 "OpDecorate %indata1 DescriptorSet 0\n"
1181 "OpDecorate %indata1 Binding 0\n"
1182 "OpDecorate %indata2 DescriptorSet 0\n"
1183 "OpDecorate %indata2 Binding 1\n"
1184 "OpDecorate %outdata DescriptorSet 0\n"
1185 "OpDecorate %outdata Binding 2\n"
1186 "OpDecorate %f32arr ArrayStride 4\n"
1187 "OpMemberDecorate %buf 0 Offset 0\n"
1189 + string(getComputeAsmCommonTypes()) +
1191 "%buf = OpTypeStruct %f32arr\n"
1192 "%bufptr = OpTypePointer Uniform %buf\n"
1193 "%indata1 = OpVariable %bufptr Uniform\n"
1194 "%indata2 = OpVariable %bufptr Uniform\n"
1195 "%outdata = OpVariable %bufptr Uniform\n"
1197 "%id = OpVariable %uvec3ptr Input\n"
1198 "%zero = OpConstant %i32 0\n"
1200 "%main = OpFunction %void None %voidf\n"
1201 "%label = OpLabel\n"
1202 "%idval = OpLoad %uvec3 %id\n"
1203 "%x = OpCompositeExtract %u32 %idval 0\n"
1204 "%inloc1 = OpAccessChain %f32ptr %indata1 %zero %x\n"
1205 "%inval1 = OpLoad %f32 %inloc1\n"
1206 "%inloc2 = OpAccessChain %f32ptr %indata2 %zero %x\n"
1207 "%inval2 = OpLoad %f32 %inloc2\n"
1208 "%rem = OpExtInst %f32 %std450 NMax %inval1 %inval2\n"
1209 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
1210 " OpStore %outloc %rem\n"
1214 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats1)));
1215 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
1216 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
1217 spec.numWorkGroups = IVec3(numElements, 1, 1);
1218 spec.verifyIO = &compareNMax;
1220 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "", spec));
1222 return group.release();
1225 bool compareNClamp (const std::vector<BufferSp>&, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs, TestLog&)
1227 if (outputAllocs.size() != 1)
1230 const BufferSp& expectedOutput = expectedOutputs[0];
1231 std::vector<deUint8> data;
1232 expectedOutput->getBytes(data);
1234 const float* const expectedOutputAsFloat = reinterpret_cast<const float*>(&data.front());
1235 const float* const outputAsFloat = static_cast<const float*>(outputAllocs[0]->getHostPtr());
1237 for (size_t idx = 0; idx < expectedOutput->getByteSize() / sizeof(float) / 2; ++idx)
1239 const float e0 = expectedOutputAsFloat[idx * 2];
1240 const float e1 = expectedOutputAsFloat[idx * 2 + 1];
1241 const float res = outputAsFloat[idx];
1243 // For NClamp, we have two possible outcomes based on
1244 // whether NaNs are handled or not.
1245 // If either min or max value is NaN, the result is undefined,
1246 // so this test doesn't stress those. If the clamped value is
1247 // NaN, and NaNs are handled, the result is min; if NaNs are not
1248 // handled, they are big values that result in max.
1249 // If all three parameters are NaN, the result should be NaN.
1250 if (!((tcu::Float32(e0).isNaN() && tcu::Float32(res).isNaN()) ||
1251 (deFloatAbs(e0 - res) < 0.00001f) ||
1252 (deFloatAbs(e1 - res) < 0.00001f)))
1259 tcu::TestCaseGroup* createOpNClampGroup (tcu::TestContext& testCtx)
1261 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opnclamp", "Test the OpNClamp instruction"));
1262 ComputeShaderSpec spec;
1263 de::Random rnd (deStringHash(group->getName()));
1264 const int numElements = 200;
1265 vector<float> inputFloats1 (numElements, 0);
1266 vector<float> inputFloats2 (numElements, 0);
1267 vector<float> inputFloats3 (numElements, 0);
1268 vector<float> outputFloats (numElements * 2, 0);
1270 fillRandomScalars(rnd, -10000.f, 10000.f, &inputFloats1[0], numElements);
1271 fillRandomScalars(rnd, -10000.f, 10000.f, &inputFloats2[0], numElements);
1272 fillRandomScalars(rnd, -10000.f, 10000.f, &inputFloats3[0], numElements);
1274 for (size_t ndx = 0; ndx < numElements; ++ndx)
1276 // Results are only defined if max value is bigger than min value.
1277 if (inputFloats2[ndx] > inputFloats3[ndx])
1279 float t = inputFloats2[ndx];
1280 inputFloats2[ndx] = inputFloats3[ndx];
1281 inputFloats3[ndx] = t;
1284 // By default, do the clamp, setting both possible answers
1285 float defaultRes = std::min(std::max(inputFloats1[ndx], inputFloats2[ndx]), inputFloats3[ndx]);
1287 float maxResA = std::max(inputFloats1[ndx], inputFloats2[ndx]);
1288 float maxResB = maxResA;
1290 // Alternate between the NaN cases
1293 inputFloats1[ndx] = TCU_NAN;
1294 // If NaN is handled, the result should be same as the clamp minimum.
1295 // If NaN is not handled, the result should clamp to the clamp maximum.
1296 maxResA = inputFloats2[ndx];
1297 maxResB = inputFloats3[ndx];
1301 // Not a NaN case - only one legal result.
1302 maxResA = defaultRes;
1303 maxResB = defaultRes;
1306 outputFloats[ndx * 2] = maxResA;
1307 outputFloats[ndx * 2 + 1] = maxResB;
1310 // Make the first case a full-NAN case.
1311 inputFloats1[0] = TCU_NAN;
1312 inputFloats2[0] = TCU_NAN;
1313 inputFloats3[0] = TCU_NAN;
1314 outputFloats[0] = TCU_NAN;
1315 outputFloats[1] = TCU_NAN;
1318 "OpCapability Shader\n"
1319 "%std450 = OpExtInstImport \"GLSL.std.450\"\n"
1320 "OpMemoryModel Logical GLSL450\n"
1321 "OpEntryPoint GLCompute %main \"main\" %id\n"
1322 "OpExecutionMode %main LocalSize 1 1 1\n"
1324 "OpName %main \"main\"\n"
1325 "OpName %id \"gl_GlobalInvocationID\"\n"
1327 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1329 "OpDecorate %buf BufferBlock\n"
1330 "OpDecorate %indata1 DescriptorSet 0\n"
1331 "OpDecorate %indata1 Binding 0\n"
1332 "OpDecorate %indata2 DescriptorSet 0\n"
1333 "OpDecorate %indata2 Binding 1\n"
1334 "OpDecorate %indata3 DescriptorSet 0\n"
1335 "OpDecorate %indata3 Binding 2\n"
1336 "OpDecorate %outdata DescriptorSet 0\n"
1337 "OpDecorate %outdata Binding 3\n"
1338 "OpDecorate %f32arr ArrayStride 4\n"
1339 "OpMemberDecorate %buf 0 Offset 0\n"
1341 + string(getComputeAsmCommonTypes()) +
1343 "%buf = OpTypeStruct %f32arr\n"
1344 "%bufptr = OpTypePointer Uniform %buf\n"
1345 "%indata1 = OpVariable %bufptr Uniform\n"
1346 "%indata2 = OpVariable %bufptr Uniform\n"
1347 "%indata3 = OpVariable %bufptr Uniform\n"
1348 "%outdata = OpVariable %bufptr Uniform\n"
1350 "%id = OpVariable %uvec3ptr Input\n"
1351 "%zero = OpConstant %i32 0\n"
1353 "%main = OpFunction %void None %voidf\n"
1354 "%label = OpLabel\n"
1355 "%idval = OpLoad %uvec3 %id\n"
1356 "%x = OpCompositeExtract %u32 %idval 0\n"
1357 "%inloc1 = OpAccessChain %f32ptr %indata1 %zero %x\n"
1358 "%inval1 = OpLoad %f32 %inloc1\n"
1359 "%inloc2 = OpAccessChain %f32ptr %indata2 %zero %x\n"
1360 "%inval2 = OpLoad %f32 %inloc2\n"
1361 "%inloc3 = OpAccessChain %f32ptr %indata3 %zero %x\n"
1362 "%inval3 = OpLoad %f32 %inloc3\n"
1363 "%rem = OpExtInst %f32 %std450 NClamp %inval1 %inval2 %inval3\n"
1364 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
1365 " OpStore %outloc %rem\n"
1369 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats1)));
1370 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
1371 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats3)));
1372 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
1373 spec.numWorkGroups = IVec3(numElements, 1, 1);
1374 spec.verifyIO = &compareNClamp;
1376 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "", spec));
1378 return group.release();
1381 tcu::TestCaseGroup* createOpSRemComputeGroup (tcu::TestContext& testCtx, qpTestResult negFailResult)
1383 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opsrem", "Test the OpSRem instruction"));
1384 de::Random rnd (deStringHash(group->getName()));
1385 const int numElements = 200;
1387 const struct CaseParams
1390 const char* failMessage; // customized status message
1391 qpTestResult failResult; // override status on failure
1392 int op1Min, op1Max; // operand ranges
1396 { "positive", "Output doesn't match with expected", QP_TEST_RESULT_FAIL, 0, 65536, 0, 100 },
1397 { "all", "Inconsistent results, but within specification", negFailResult, -65536, 65536, -100, 100 }, // see below
1399 // If either operand is negative the result is undefined. Some implementations may still return correct values.
1401 for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(cases); ++caseNdx)
1403 const CaseParams& params = cases[caseNdx];
1404 ComputeShaderSpec spec;
1405 vector<deInt32> inputInts1 (numElements, 0);
1406 vector<deInt32> inputInts2 (numElements, 0);
1407 vector<deInt32> outputInts (numElements, 0);
1409 fillRandomScalars(rnd, params.op1Min, params.op1Max, &inputInts1[0], numElements);
1410 fillRandomScalars(rnd, params.op2Min, params.op2Max, &inputInts2[0], numElements, filterNotZero);
1412 for (int ndx = 0; ndx < numElements; ++ndx)
1414 // The return value of std::fmod() has the same sign as its first operand, which is how OpFRem spec'd.
1415 outputInts[ndx] = inputInts1[ndx] % inputInts2[ndx];
1419 string(getComputeAsmShaderPreamble()) +
1421 "OpName %main \"main\"\n"
1422 "OpName %id \"gl_GlobalInvocationID\"\n"
1424 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1426 "OpDecorate %buf BufferBlock\n"
1427 "OpDecorate %indata1 DescriptorSet 0\n"
1428 "OpDecorate %indata1 Binding 0\n"
1429 "OpDecorate %indata2 DescriptorSet 0\n"
1430 "OpDecorate %indata2 Binding 1\n"
1431 "OpDecorate %outdata DescriptorSet 0\n"
1432 "OpDecorate %outdata Binding 2\n"
1433 "OpDecorate %i32arr ArrayStride 4\n"
1434 "OpMemberDecorate %buf 0 Offset 0\n"
1436 + string(getComputeAsmCommonTypes()) +
1438 "%buf = OpTypeStruct %i32arr\n"
1439 "%bufptr = OpTypePointer Uniform %buf\n"
1440 "%indata1 = OpVariable %bufptr Uniform\n"
1441 "%indata2 = OpVariable %bufptr Uniform\n"
1442 "%outdata = OpVariable %bufptr Uniform\n"
1444 "%id = OpVariable %uvec3ptr Input\n"
1445 "%zero = OpConstant %i32 0\n"
1447 "%main = OpFunction %void None %voidf\n"
1448 "%label = OpLabel\n"
1449 "%idval = OpLoad %uvec3 %id\n"
1450 "%x = OpCompositeExtract %u32 %idval 0\n"
1451 "%inloc1 = OpAccessChain %i32ptr %indata1 %zero %x\n"
1452 "%inval1 = OpLoad %i32 %inloc1\n"
1453 "%inloc2 = OpAccessChain %i32ptr %indata2 %zero %x\n"
1454 "%inval2 = OpLoad %i32 %inloc2\n"
1455 "%rem = OpSRem %i32 %inval1 %inval2\n"
1456 "%outloc = OpAccessChain %i32ptr %outdata %zero %x\n"
1457 " OpStore %outloc %rem\n"
1461 spec.inputs.push_back (BufferSp(new Int32Buffer(inputInts1)));
1462 spec.inputs.push_back (BufferSp(new Int32Buffer(inputInts2)));
1463 spec.outputs.push_back (BufferSp(new Int32Buffer(outputInts)));
1464 spec.numWorkGroups = IVec3(numElements, 1, 1);
1465 spec.failResult = params.failResult;
1466 spec.failMessage = params.failMessage;
1468 group->addChild(new SpvAsmComputeShaderCase(testCtx, params.name, "", spec));
1471 return group.release();
1474 tcu::TestCaseGroup* createOpSRemComputeGroup64 (tcu::TestContext& testCtx, qpTestResult negFailResult)
1476 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opsrem64", "Test the 64-bit OpSRem instruction"));
1477 de::Random rnd (deStringHash(group->getName()));
1478 const int numElements = 200;
1480 const struct CaseParams
1483 const char* failMessage; // customized status message
1484 qpTestResult failResult; // override status on failure
1488 { "positive", "Output doesn't match with expected", QP_TEST_RESULT_FAIL, true },
1489 { "all", "Inconsistent results, but within specification", negFailResult, false }, // see below
1491 // If either operand is negative the result is undefined. Some implementations may still return correct values.
1493 for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(cases); ++caseNdx)
1495 const CaseParams& params = cases[caseNdx];
1496 ComputeShaderSpec spec;
1497 vector<deInt64> inputInts1 (numElements, 0);
1498 vector<deInt64> inputInts2 (numElements, 0);
1499 vector<deInt64> outputInts (numElements, 0);
1501 if (params.positive)
1503 fillRandomInt64sLogDistributed(rnd, inputInts1, numElements, filterNonNegative);
1504 fillRandomInt64sLogDistributed(rnd, inputInts2, numElements, filterPositive);
1508 fillRandomInt64sLogDistributed(rnd, inputInts1, numElements);
1509 fillRandomInt64sLogDistributed(rnd, inputInts2, numElements, filterNotZero);
1512 for (int ndx = 0; ndx < numElements; ++ndx)
1514 // The return value of std::fmod() has the same sign as its first operand, which is how OpFRem spec'd.
1515 outputInts[ndx] = inputInts1[ndx] % inputInts2[ndx];
1519 "OpCapability Int64\n"
1521 + string(getComputeAsmShaderPreamble()) +
1523 "OpName %main \"main\"\n"
1524 "OpName %id \"gl_GlobalInvocationID\"\n"
1526 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1528 "OpDecorate %buf BufferBlock\n"
1529 "OpDecorate %indata1 DescriptorSet 0\n"
1530 "OpDecorate %indata1 Binding 0\n"
1531 "OpDecorate %indata2 DescriptorSet 0\n"
1532 "OpDecorate %indata2 Binding 1\n"
1533 "OpDecorate %outdata DescriptorSet 0\n"
1534 "OpDecorate %outdata Binding 2\n"
1535 "OpDecorate %i64arr ArrayStride 8\n"
1536 "OpMemberDecorate %buf 0 Offset 0\n"
1538 + string(getComputeAsmCommonTypes())
1539 + string(getComputeAsmCommonInt64Types()) +
1541 "%buf = OpTypeStruct %i64arr\n"
1542 "%bufptr = OpTypePointer Uniform %buf\n"
1543 "%indata1 = OpVariable %bufptr Uniform\n"
1544 "%indata2 = OpVariable %bufptr Uniform\n"
1545 "%outdata = OpVariable %bufptr Uniform\n"
1547 "%id = OpVariable %uvec3ptr Input\n"
1548 "%zero = OpConstant %i64 0\n"
1550 "%main = OpFunction %void None %voidf\n"
1551 "%label = OpLabel\n"
1552 "%idval = OpLoad %uvec3 %id\n"
1553 "%x = OpCompositeExtract %u32 %idval 0\n"
1554 "%inloc1 = OpAccessChain %i64ptr %indata1 %zero %x\n"
1555 "%inval1 = OpLoad %i64 %inloc1\n"
1556 "%inloc2 = OpAccessChain %i64ptr %indata2 %zero %x\n"
1557 "%inval2 = OpLoad %i64 %inloc2\n"
1558 "%rem = OpSRem %i64 %inval1 %inval2\n"
1559 "%outloc = OpAccessChain %i64ptr %outdata %zero %x\n"
1560 " OpStore %outloc %rem\n"
1564 spec.inputs.push_back (BufferSp(new Int64Buffer(inputInts1)));
1565 spec.inputs.push_back (BufferSp(new Int64Buffer(inputInts2)));
1566 spec.outputs.push_back (BufferSp(new Int64Buffer(outputInts)));
1567 spec.numWorkGroups = IVec3(numElements, 1, 1);
1568 spec.failResult = params.failResult;
1569 spec.failMessage = params.failMessage;
1571 group->addChild(new SpvAsmComputeShaderCase(testCtx, params.name, "", spec, COMPUTE_TEST_USES_INT64));
1574 return group.release();
1577 tcu::TestCaseGroup* createOpSModComputeGroup (tcu::TestContext& testCtx, qpTestResult negFailResult)
1579 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opsmod", "Test the OpSMod instruction"));
1580 de::Random rnd (deStringHash(group->getName()));
1581 const int numElements = 200;
1583 const struct CaseParams
1586 const char* failMessage; // customized status message
1587 qpTestResult failResult; // override status on failure
1588 int op1Min, op1Max; // operand ranges
1592 { "positive", "Output doesn't match with expected", QP_TEST_RESULT_FAIL, 0, 65536, 0, 100 },
1593 { "all", "Inconsistent results, but within specification", negFailResult, -65536, 65536, -100, 100 }, // see below
1595 // If either operand is negative the result is undefined. Some implementations may still return correct values.
1597 for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(cases); ++caseNdx)
1599 const CaseParams& params = cases[caseNdx];
1601 ComputeShaderSpec spec;
1602 vector<deInt32> inputInts1 (numElements, 0);
1603 vector<deInt32> inputInts2 (numElements, 0);
1604 vector<deInt32> outputInts (numElements, 0);
1606 fillRandomScalars(rnd, params.op1Min, params.op1Max, &inputInts1[0], numElements);
1607 fillRandomScalars(rnd, params.op2Min, params.op2Max, &inputInts2[0], numElements, filterNotZero);
1609 for (int ndx = 0; ndx < numElements; ++ndx)
1611 deInt32 rem = inputInts1[ndx] % inputInts2[ndx];
1614 outputInts[ndx] = 0;
1616 else if ((inputInts1[ndx] >= 0) == (inputInts2[ndx] >= 0))
1618 // They have the same sign
1619 outputInts[ndx] = rem;
1623 // They have opposite sign. The remainder operation takes the
1624 // sign inputInts1[ndx] but OpSMod is supposed to take ths sign
1625 // of inputInts2[ndx]. Adding inputInts2[ndx] will ensure that
1626 // the result has the correct sign and that it is still
1627 // congruent to inputInts1[ndx] modulo inputInts2[ndx]
1629 // See also http://mathforum.org/library/drmath/view/52343.html
1630 outputInts[ndx] = rem + inputInts2[ndx];
1635 string(getComputeAsmShaderPreamble()) +
1637 "OpName %main \"main\"\n"
1638 "OpName %id \"gl_GlobalInvocationID\"\n"
1640 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1642 "OpDecorate %buf BufferBlock\n"
1643 "OpDecorate %indata1 DescriptorSet 0\n"
1644 "OpDecorate %indata1 Binding 0\n"
1645 "OpDecorate %indata2 DescriptorSet 0\n"
1646 "OpDecorate %indata2 Binding 1\n"
1647 "OpDecorate %outdata DescriptorSet 0\n"
1648 "OpDecorate %outdata Binding 2\n"
1649 "OpDecorate %i32arr ArrayStride 4\n"
1650 "OpMemberDecorate %buf 0 Offset 0\n"
1652 + string(getComputeAsmCommonTypes()) +
1654 "%buf = OpTypeStruct %i32arr\n"
1655 "%bufptr = OpTypePointer Uniform %buf\n"
1656 "%indata1 = OpVariable %bufptr Uniform\n"
1657 "%indata2 = OpVariable %bufptr Uniform\n"
1658 "%outdata = OpVariable %bufptr Uniform\n"
1660 "%id = OpVariable %uvec3ptr Input\n"
1661 "%zero = OpConstant %i32 0\n"
1663 "%main = OpFunction %void None %voidf\n"
1664 "%label = OpLabel\n"
1665 "%idval = OpLoad %uvec3 %id\n"
1666 "%x = OpCompositeExtract %u32 %idval 0\n"
1667 "%inloc1 = OpAccessChain %i32ptr %indata1 %zero %x\n"
1668 "%inval1 = OpLoad %i32 %inloc1\n"
1669 "%inloc2 = OpAccessChain %i32ptr %indata2 %zero %x\n"
1670 "%inval2 = OpLoad %i32 %inloc2\n"
1671 "%rem = OpSMod %i32 %inval1 %inval2\n"
1672 "%outloc = OpAccessChain %i32ptr %outdata %zero %x\n"
1673 " OpStore %outloc %rem\n"
1677 spec.inputs.push_back (BufferSp(new Int32Buffer(inputInts1)));
1678 spec.inputs.push_back (BufferSp(new Int32Buffer(inputInts2)));
1679 spec.outputs.push_back (BufferSp(new Int32Buffer(outputInts)));
1680 spec.numWorkGroups = IVec3(numElements, 1, 1);
1681 spec.failResult = params.failResult;
1682 spec.failMessage = params.failMessage;
1684 group->addChild(new SpvAsmComputeShaderCase(testCtx, params.name, "", spec));
1687 return group.release();
1690 tcu::TestCaseGroup* createOpSModComputeGroup64 (tcu::TestContext& testCtx, qpTestResult negFailResult)
1692 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opsmod64", "Test the OpSMod instruction"));
1693 de::Random rnd (deStringHash(group->getName()));
1694 const int numElements = 200;
1696 const struct CaseParams
1699 const char* failMessage; // customized status message
1700 qpTestResult failResult; // override status on failure
1704 { "positive", "Output doesn't match with expected", QP_TEST_RESULT_FAIL, true },
1705 { "all", "Inconsistent results, but within specification", negFailResult, false }, // see below
1707 // If either operand is negative the result is undefined. Some implementations may still return correct values.
1709 for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(cases); ++caseNdx)
1711 const CaseParams& params = cases[caseNdx];
1713 ComputeShaderSpec spec;
1714 vector<deInt64> inputInts1 (numElements, 0);
1715 vector<deInt64> inputInts2 (numElements, 0);
1716 vector<deInt64> outputInts (numElements, 0);
1719 if (params.positive)
1721 fillRandomInt64sLogDistributed(rnd, inputInts1, numElements, filterNonNegative);
1722 fillRandomInt64sLogDistributed(rnd, inputInts2, numElements, filterPositive);
1726 fillRandomInt64sLogDistributed(rnd, inputInts1, numElements);
1727 fillRandomInt64sLogDistributed(rnd, inputInts2, numElements, filterNotZero);
1730 for (int ndx = 0; ndx < numElements; ++ndx)
1732 deInt64 rem = inputInts1[ndx] % inputInts2[ndx];
1735 outputInts[ndx] = 0;
1737 else if ((inputInts1[ndx] >= 0) == (inputInts2[ndx] >= 0))
1739 // They have the same sign
1740 outputInts[ndx] = rem;
1744 // They have opposite sign. The remainder operation takes the
1745 // sign inputInts1[ndx] but OpSMod is supposed to take ths sign
1746 // of inputInts2[ndx]. Adding inputInts2[ndx] will ensure that
1747 // the result has the correct sign and that it is still
1748 // congruent to inputInts1[ndx] modulo inputInts2[ndx]
1750 // See also http://mathforum.org/library/drmath/view/52343.html
1751 outputInts[ndx] = rem + inputInts2[ndx];
1756 "OpCapability Int64\n"
1758 + string(getComputeAsmShaderPreamble()) +
1760 "OpName %main \"main\"\n"
1761 "OpName %id \"gl_GlobalInvocationID\"\n"
1763 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1765 "OpDecorate %buf BufferBlock\n"
1766 "OpDecorate %indata1 DescriptorSet 0\n"
1767 "OpDecorate %indata1 Binding 0\n"
1768 "OpDecorate %indata2 DescriptorSet 0\n"
1769 "OpDecorate %indata2 Binding 1\n"
1770 "OpDecorate %outdata DescriptorSet 0\n"
1771 "OpDecorate %outdata Binding 2\n"
1772 "OpDecorate %i64arr ArrayStride 8\n"
1773 "OpMemberDecorate %buf 0 Offset 0\n"
1775 + string(getComputeAsmCommonTypes())
1776 + string(getComputeAsmCommonInt64Types()) +
1778 "%buf = OpTypeStruct %i64arr\n"
1779 "%bufptr = OpTypePointer Uniform %buf\n"
1780 "%indata1 = OpVariable %bufptr Uniform\n"
1781 "%indata2 = OpVariable %bufptr Uniform\n"
1782 "%outdata = OpVariable %bufptr Uniform\n"
1784 "%id = OpVariable %uvec3ptr Input\n"
1785 "%zero = OpConstant %i64 0\n"
1787 "%main = OpFunction %void None %voidf\n"
1788 "%label = OpLabel\n"
1789 "%idval = OpLoad %uvec3 %id\n"
1790 "%x = OpCompositeExtract %u32 %idval 0\n"
1791 "%inloc1 = OpAccessChain %i64ptr %indata1 %zero %x\n"
1792 "%inval1 = OpLoad %i64 %inloc1\n"
1793 "%inloc2 = OpAccessChain %i64ptr %indata2 %zero %x\n"
1794 "%inval2 = OpLoad %i64 %inloc2\n"
1795 "%rem = OpSMod %i64 %inval1 %inval2\n"
1796 "%outloc = OpAccessChain %i64ptr %outdata %zero %x\n"
1797 " OpStore %outloc %rem\n"
1801 spec.inputs.push_back (BufferSp(new Int64Buffer(inputInts1)));
1802 spec.inputs.push_back (BufferSp(new Int64Buffer(inputInts2)));
1803 spec.outputs.push_back (BufferSp(new Int64Buffer(outputInts)));
1804 spec.numWorkGroups = IVec3(numElements, 1, 1);
1805 spec.failResult = params.failResult;
1806 spec.failMessage = params.failMessage;
1808 group->addChild(new SpvAsmComputeShaderCase(testCtx, params.name, "", spec, COMPUTE_TEST_USES_INT64));
1811 return group.release();
1814 // Copy contents in the input buffer to the output buffer.
1815 tcu::TestCaseGroup* createOpCopyMemoryGroup (tcu::TestContext& testCtx)
1817 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opcopymemory", "Test the OpCopyMemory instruction"));
1818 de::Random rnd (deStringHash(group->getName()));
1819 const int numElements = 100;
1821 // 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.
1822 ComputeShaderSpec spec1;
1823 vector<Vec4> inputFloats1 (numElements);
1824 vector<Vec4> outputFloats1 (numElements);
1826 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats1[0], numElements * 4);
1828 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
1829 floorAll(inputFloats1);
1831 for (size_t ndx = 0; ndx < numElements; ++ndx)
1832 outputFloats1[ndx] = inputFloats1[ndx] + Vec4(0.f, 0.5f, 1.5f, 2.5f);
1835 string(getComputeAsmShaderPreamble()) +
1837 "OpName %main \"main\"\n"
1838 "OpName %id \"gl_GlobalInvocationID\"\n"
1840 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1841 "OpDecorate %vec4arr ArrayStride 16\n"
1843 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
1845 "%vec4 = OpTypeVector %f32 4\n"
1846 "%vec4ptr_u = OpTypePointer Uniform %vec4\n"
1847 "%vec4ptr_f = OpTypePointer Function %vec4\n"
1848 "%vec4arr = OpTypeRuntimeArray %vec4\n"
1849 "%buf = OpTypeStruct %vec4arr\n"
1850 "%bufptr = OpTypePointer Uniform %buf\n"
1851 "%indata = OpVariable %bufptr Uniform\n"
1852 "%outdata = OpVariable %bufptr Uniform\n"
1854 "%id = OpVariable %uvec3ptr Input\n"
1855 "%zero = OpConstant %i32 0\n"
1856 "%c_f_0 = OpConstant %f32 0.\n"
1857 "%c_f_0_5 = OpConstant %f32 0.5\n"
1858 "%c_f_1_5 = OpConstant %f32 1.5\n"
1859 "%c_f_2_5 = OpConstant %f32 2.5\n"
1860 "%c_vec4 = OpConstantComposite %vec4 %c_f_0 %c_f_0_5 %c_f_1_5 %c_f_2_5\n"
1862 "%main = OpFunction %void None %voidf\n"
1863 "%label = OpLabel\n"
1864 "%v_vec4 = OpVariable %vec4ptr_f Function\n"
1865 "%idval = OpLoad %uvec3 %id\n"
1866 "%x = OpCompositeExtract %u32 %idval 0\n"
1867 "%inloc = OpAccessChain %vec4ptr_u %indata %zero %x\n"
1868 "%outloc = OpAccessChain %vec4ptr_u %outdata %zero %x\n"
1869 " OpCopyMemory %v_vec4 %inloc\n"
1870 "%v_vec4_val = OpLoad %vec4 %v_vec4\n"
1871 "%add = OpFAdd %vec4 %v_vec4_val %c_vec4\n"
1872 " OpStore %outloc %add\n"
1876 spec1.inputs.push_back(BufferSp(new Vec4Buffer(inputFloats1)));
1877 spec1.outputs.push_back(BufferSp(new Vec4Buffer(outputFloats1)));
1878 spec1.numWorkGroups = IVec3(numElements, 1, 1);
1880 group->addChild(new SpvAsmComputeShaderCase(testCtx, "vector", "OpCopyMemory elements of vector type", spec1));
1882 // The following case copies a float[100] variable from the input buffer to the output buffer.
1883 ComputeShaderSpec spec2;
1884 vector<float> inputFloats2 (numElements);
1885 vector<float> outputFloats2 (numElements);
1887 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats2[0], numElements);
1889 for (size_t ndx = 0; ndx < numElements; ++ndx)
1890 outputFloats2[ndx] = inputFloats2[ndx];
1893 string(getComputeAsmShaderPreamble()) +
1895 "OpName %main \"main\"\n"
1896 "OpName %id \"gl_GlobalInvocationID\"\n"
1898 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1899 "OpDecorate %f32arr100 ArrayStride 4\n"
1901 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
1903 "%hundred = OpConstant %u32 100\n"
1904 "%f32arr100 = OpTypeArray %f32 %hundred\n"
1905 "%f32arr100ptr_f = OpTypePointer Function %f32arr100\n"
1906 "%f32arr100ptr_u = OpTypePointer Uniform %f32arr100\n"
1907 "%buf = OpTypeStruct %f32arr100\n"
1908 "%bufptr = OpTypePointer Uniform %buf\n"
1909 "%indata = OpVariable %bufptr Uniform\n"
1910 "%outdata = OpVariable %bufptr Uniform\n"
1912 "%id = OpVariable %uvec3ptr Input\n"
1913 "%zero = OpConstant %i32 0\n"
1915 "%main = OpFunction %void None %voidf\n"
1916 "%label = OpLabel\n"
1917 "%var = OpVariable %f32arr100ptr_f Function\n"
1918 "%inarr = OpAccessChain %f32arr100ptr_u %indata %zero\n"
1919 "%outarr = OpAccessChain %f32arr100ptr_u %outdata %zero\n"
1920 " OpCopyMemory %var %inarr\n"
1921 " OpCopyMemory %outarr %var\n"
1925 spec2.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
1926 spec2.outputs.push_back(BufferSp(new Float32Buffer(outputFloats2)));
1927 spec2.numWorkGroups = IVec3(1, 1, 1);
1929 group->addChild(new SpvAsmComputeShaderCase(testCtx, "array", "OpCopyMemory elements of array type", spec2));
1931 // The following case copies a struct{vec4, vec4, vec4, vec4} variable from the input buffer to the output buffer.
1932 ComputeShaderSpec spec3;
1933 vector<float> inputFloats3 (16);
1934 vector<float> outputFloats3 (16);
1936 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats3[0], 16);
1938 for (size_t ndx = 0; ndx < 16; ++ndx)
1939 outputFloats3[ndx] = inputFloats3[ndx];
1942 string(getComputeAsmShaderPreamble()) +
1944 "OpName %main \"main\"\n"
1945 "OpName %id \"gl_GlobalInvocationID\"\n"
1947 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1948 "OpMemberDecorate %buf 0 Offset 0\n"
1949 "OpMemberDecorate %buf 1 Offset 16\n"
1950 "OpMemberDecorate %buf 2 Offset 32\n"
1951 "OpMemberDecorate %buf 3 Offset 48\n"
1953 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
1955 "%vec4 = OpTypeVector %f32 4\n"
1956 "%buf = OpTypeStruct %vec4 %vec4 %vec4 %vec4\n"
1957 "%bufptr = OpTypePointer Uniform %buf\n"
1958 "%indata = OpVariable %bufptr Uniform\n"
1959 "%outdata = OpVariable %bufptr Uniform\n"
1960 "%vec4stptr = OpTypePointer Function %buf\n"
1962 "%id = OpVariable %uvec3ptr Input\n"
1963 "%zero = OpConstant %i32 0\n"
1965 "%main = OpFunction %void None %voidf\n"
1966 "%label = OpLabel\n"
1967 "%var = OpVariable %vec4stptr Function\n"
1968 " OpCopyMemory %var %indata\n"
1969 " OpCopyMemory %outdata %var\n"
1973 spec3.inputs.push_back(BufferSp(new Float32Buffer(inputFloats3)));
1974 spec3.outputs.push_back(BufferSp(new Float32Buffer(outputFloats3)));
1975 spec3.numWorkGroups = IVec3(1, 1, 1);
1977 group->addChild(new SpvAsmComputeShaderCase(testCtx, "struct", "OpCopyMemory elements of struct type", spec3));
1979 // The following case negates multiple float variables from the input buffer and stores the results to the output buffer.
1980 ComputeShaderSpec spec4;
1981 vector<float> inputFloats4 (numElements);
1982 vector<float> outputFloats4 (numElements);
1984 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats4[0], numElements);
1986 for (size_t ndx = 0; ndx < numElements; ++ndx)
1987 outputFloats4[ndx] = -inputFloats4[ndx];
1990 string(getComputeAsmShaderPreamble()) +
1992 "OpName %main \"main\"\n"
1993 "OpName %id \"gl_GlobalInvocationID\"\n"
1995 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1997 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
1999 "%f32ptr_f = OpTypePointer Function %f32\n"
2000 "%id = OpVariable %uvec3ptr Input\n"
2001 "%zero = OpConstant %i32 0\n"
2003 "%main = OpFunction %void None %voidf\n"
2004 "%label = OpLabel\n"
2005 "%var = OpVariable %f32ptr_f Function\n"
2006 "%idval = OpLoad %uvec3 %id\n"
2007 "%x = OpCompositeExtract %u32 %idval 0\n"
2008 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
2009 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2010 " OpCopyMemory %var %inloc\n"
2011 "%val = OpLoad %f32 %var\n"
2012 "%neg = OpFNegate %f32 %val\n"
2013 " OpStore %outloc %neg\n"
2017 spec4.inputs.push_back(BufferSp(new Float32Buffer(inputFloats4)));
2018 spec4.outputs.push_back(BufferSp(new Float32Buffer(outputFloats4)));
2019 spec4.numWorkGroups = IVec3(numElements, 1, 1);
2021 group->addChild(new SpvAsmComputeShaderCase(testCtx, "float", "OpCopyMemory elements of float type", spec4));
2023 return group.release();
2026 tcu::TestCaseGroup* createOpCopyObjectGroup (tcu::TestContext& testCtx)
2028 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opcopyobject", "Test the OpCopyObject instruction"));
2029 ComputeShaderSpec spec;
2030 de::Random rnd (deStringHash(group->getName()));
2031 const int numElements = 100;
2032 vector<float> inputFloats (numElements, 0);
2033 vector<float> outputFloats (numElements, 0);
2035 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats[0], numElements);
2037 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
2038 floorAll(inputFloats);
2040 for (size_t ndx = 0; ndx < numElements; ++ndx)
2041 outputFloats[ndx] = inputFloats[ndx] + 7.5f;
2044 string(getComputeAsmShaderPreamble()) +
2046 "OpName %main \"main\"\n"
2047 "OpName %id \"gl_GlobalInvocationID\"\n"
2049 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2051 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
2053 "%fmat = OpTypeMatrix %fvec3 3\n"
2054 "%three = OpConstant %u32 3\n"
2055 "%farr = OpTypeArray %f32 %three\n"
2056 "%fst = OpTypeStruct %f32 %f32\n"
2058 + string(getComputeAsmInputOutputBuffer()) +
2060 "%id = OpVariable %uvec3ptr Input\n"
2061 "%zero = OpConstant %i32 0\n"
2062 "%c_f = OpConstant %f32 1.5\n"
2063 "%c_fvec3 = OpConstantComposite %fvec3 %c_f %c_f %c_f\n"
2064 "%c_fmat = OpConstantComposite %fmat %c_fvec3 %c_fvec3 %c_fvec3\n"
2065 "%c_farr = OpConstantComposite %farr %c_f %c_f %c_f\n"
2066 "%c_fst = OpConstantComposite %fst %c_f %c_f\n"
2068 "%main = OpFunction %void None %voidf\n"
2069 "%label = OpLabel\n"
2070 "%c_f_copy = OpCopyObject %f32 %c_f\n"
2071 "%c_fvec3_copy = OpCopyObject %fvec3 %c_fvec3\n"
2072 "%c_fmat_copy = OpCopyObject %fmat %c_fmat\n"
2073 "%c_farr_copy = OpCopyObject %farr %c_farr\n"
2074 "%c_fst_copy = OpCopyObject %fst %c_fst\n"
2075 "%fvec3_elem = OpCompositeExtract %f32 %c_fvec3_copy 0\n"
2076 "%fmat_elem = OpCompositeExtract %f32 %c_fmat_copy 1 2\n"
2077 "%farr_elem = OpCompositeExtract %f32 %c_farr_copy 2\n"
2078 "%fst_elem = OpCompositeExtract %f32 %c_fst_copy 1\n"
2079 // Add up. 1.5 * 5 = 7.5.
2080 "%add1 = OpFAdd %f32 %c_f_copy %fvec3_elem\n"
2081 "%add2 = OpFAdd %f32 %add1 %fmat_elem\n"
2082 "%add3 = OpFAdd %f32 %add2 %farr_elem\n"
2083 "%add4 = OpFAdd %f32 %add3 %fst_elem\n"
2085 "%idval = OpLoad %uvec3 %id\n"
2086 "%x = OpCompositeExtract %u32 %idval 0\n"
2087 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
2088 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2089 "%inval = OpLoad %f32 %inloc\n"
2090 "%add = OpFAdd %f32 %add4 %inval\n"
2091 " OpStore %outloc %add\n"
2094 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
2095 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
2096 spec.numWorkGroups = IVec3(numElements, 1, 1);
2098 group->addChild(new SpvAsmComputeShaderCase(testCtx, "spotcheck", "OpCopyObject on different types", spec));
2100 return group.release();
2102 // Assembly code used for testing OpUnreachable is based on GLSL source code:
2106 // layout(std140, set = 0, binding = 0) readonly buffer Input {
2107 // float elements[];
2109 // layout(std140, set = 0, binding = 1) writeonly buffer Output {
2110 // float elements[];
2113 // void not_called_func() {
2114 // // place OpUnreachable here
2117 // uint modulo4(uint val) {
2118 // switch (val % uint(4)) {
2119 // case 0: return 3;
2120 // case 1: return 2;
2121 // case 2: return 1;
2122 // case 3: return 0;
2123 // default: return 100; // place OpUnreachable here
2129 // // place OpUnreachable here
2133 // uint x = gl_GlobalInvocationID.x;
2134 // if (const5() > modulo4(1000)) {
2135 // output_data.elements[x] = -input_data.elements[x];
2137 // // place OpUnreachable here
2138 // output_data.elements[x] = input_data.elements[x];
2142 tcu::TestCaseGroup* createOpUnreachableGroup (tcu::TestContext& testCtx)
2144 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opunreachable", "Test the OpUnreachable instruction"));
2145 ComputeShaderSpec spec;
2146 de::Random rnd (deStringHash(group->getName()));
2147 const int numElements = 100;
2148 vector<float> positiveFloats (numElements, 0);
2149 vector<float> negativeFloats (numElements, 0);
2151 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
2153 for (size_t ndx = 0; ndx < numElements; ++ndx)
2154 negativeFloats[ndx] = -positiveFloats[ndx];
2157 string(getComputeAsmShaderPreamble()) +
2159 "OpSource GLSL 430\n"
2160 "OpName %main \"main\"\n"
2161 "OpName %func_not_called_func \"not_called_func(\"\n"
2162 "OpName %func_modulo4 \"modulo4(u1;\"\n"
2163 "OpName %func_const5 \"const5(\"\n"
2164 "OpName %id \"gl_GlobalInvocationID\"\n"
2166 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2168 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
2170 "%u32ptr = OpTypePointer Function %u32\n"
2171 "%uintfuint = OpTypeFunction %u32 %u32ptr\n"
2172 "%unitf = OpTypeFunction %u32\n"
2174 "%id = OpVariable %uvec3ptr Input\n"
2175 "%zero = OpConstant %u32 0\n"
2176 "%one = OpConstant %u32 1\n"
2177 "%two = OpConstant %u32 2\n"
2178 "%three = OpConstant %u32 3\n"
2179 "%four = OpConstant %u32 4\n"
2180 "%five = OpConstant %u32 5\n"
2181 "%hundred = OpConstant %u32 100\n"
2182 "%thousand = OpConstant %u32 1000\n"
2184 + string(getComputeAsmInputOutputBuffer()) +
2187 "%main = OpFunction %void None %voidf\n"
2188 "%main_entry = OpLabel\n"
2189 "%v_thousand = OpVariable %u32ptr Function %thousand\n"
2190 "%idval = OpLoad %uvec3 %id\n"
2191 "%x = OpCompositeExtract %u32 %idval 0\n"
2192 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
2193 "%inval = OpLoad %f32 %inloc\n"
2194 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2195 "%ret_const5 = OpFunctionCall %u32 %func_const5\n"
2196 "%ret_modulo4 = OpFunctionCall %u32 %func_modulo4 %v_thousand\n"
2197 "%cmp_gt = OpUGreaterThan %bool %ret_const5 %ret_modulo4\n"
2198 " OpSelectionMerge %if_end None\n"
2199 " OpBranchConditional %cmp_gt %if_true %if_false\n"
2200 "%if_true = OpLabel\n"
2201 "%negate = OpFNegate %f32 %inval\n"
2202 " OpStore %outloc %negate\n"
2203 " OpBranch %if_end\n"
2204 "%if_false = OpLabel\n"
2205 " OpUnreachable\n" // Unreachable else branch for if statement
2206 "%if_end = OpLabel\n"
2210 // not_called_function()
2211 "%func_not_called_func = OpFunction %void None %voidf\n"
2212 "%not_called_func_entry = OpLabel\n"
2213 " OpUnreachable\n" // Unreachable entry block in not called static function
2217 "%func_modulo4 = OpFunction %u32 None %uintfuint\n"
2218 "%valptr = OpFunctionParameter %u32ptr\n"
2219 "%modulo4_entry = OpLabel\n"
2220 "%val = OpLoad %u32 %valptr\n"
2221 "%modulo = OpUMod %u32 %val %four\n"
2222 " OpSelectionMerge %switch_merge None\n"
2223 " OpSwitch %modulo %default 0 %case0 1 %case1 2 %case2 3 %case3\n"
2224 "%case0 = OpLabel\n"
2225 " OpReturnValue %three\n"
2226 "%case1 = OpLabel\n"
2227 " OpReturnValue %two\n"
2228 "%case2 = OpLabel\n"
2229 " OpReturnValue %one\n"
2230 "%case3 = OpLabel\n"
2231 " OpReturnValue %zero\n"
2232 "%default = OpLabel\n"
2233 " OpUnreachable\n" // Unreachable default case for switch statement
2234 "%switch_merge = OpLabel\n"
2235 " OpUnreachable\n" // Unreachable merge block for switch statement
2239 "%func_const5 = OpFunction %u32 None %unitf\n"
2240 "%const5_entry = OpLabel\n"
2241 " OpReturnValue %five\n"
2242 "%unreachable = OpLabel\n"
2243 " OpUnreachable\n" // Unreachable block in function
2245 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
2246 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
2247 spec.numWorkGroups = IVec3(numElements, 1, 1);
2249 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "OpUnreachable appearing at different places", spec));
2251 return group.release();
2254 // Assembly code used for testing decoration group is based on GLSL source code:
2258 // layout(std140, set = 0, binding = 0) readonly buffer Input0 {
2259 // float elements[];
2261 // layout(std140, set = 0, binding = 1) readonly buffer Input1 {
2262 // float elements[];
2264 // layout(std140, set = 0, binding = 2) readonly buffer Input2 {
2265 // float elements[];
2267 // layout(std140, set = 0, binding = 3) readonly buffer Input3 {
2268 // float elements[];
2270 // layout(std140, set = 0, binding = 4) readonly buffer Input4 {
2271 // float elements[];
2273 // layout(std140, set = 0, binding = 5) writeonly buffer Output {
2274 // float elements[];
2278 // uint x = gl_GlobalInvocationID.x;
2279 // output_data.elements[x] = input_data0.elements[x] + input_data1.elements[x] + input_data2.elements[x] + input_data3.elements[x] + input_data4.elements[x];
2281 tcu::TestCaseGroup* createDecorationGroupGroup (tcu::TestContext& testCtx)
2283 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "decoration_group", "Test the OpDecorationGroup & OpGroupDecorate instruction"));
2284 ComputeShaderSpec spec;
2285 de::Random rnd (deStringHash(group->getName()));
2286 const int numElements = 100;
2287 vector<float> inputFloats0 (numElements, 0);
2288 vector<float> inputFloats1 (numElements, 0);
2289 vector<float> inputFloats2 (numElements, 0);
2290 vector<float> inputFloats3 (numElements, 0);
2291 vector<float> inputFloats4 (numElements, 0);
2292 vector<float> outputFloats (numElements, 0);
2294 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats0[0], numElements);
2295 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats1[0], numElements);
2296 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats2[0], numElements);
2297 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats3[0], numElements);
2298 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats4[0], numElements);
2300 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
2301 floorAll(inputFloats0);
2302 floorAll(inputFloats1);
2303 floorAll(inputFloats2);
2304 floorAll(inputFloats3);
2305 floorAll(inputFloats4);
2307 for (size_t ndx = 0; ndx < numElements; ++ndx)
2308 outputFloats[ndx] = inputFloats0[ndx] + inputFloats1[ndx] + inputFloats2[ndx] + inputFloats3[ndx] + inputFloats4[ndx];
2311 string(getComputeAsmShaderPreamble()) +
2313 "OpSource GLSL 430\n"
2314 "OpName %main \"main\"\n"
2315 "OpName %id \"gl_GlobalInvocationID\"\n"
2317 // Not using group decoration on variable.
2318 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2319 // Not using group decoration on type.
2320 "OpDecorate %f32arr ArrayStride 4\n"
2322 "OpDecorate %groups BufferBlock\n"
2323 "OpDecorate %groupm Offset 0\n"
2324 "%groups = OpDecorationGroup\n"
2325 "%groupm = OpDecorationGroup\n"
2327 // Group decoration on multiple structs.
2328 "OpGroupDecorate %groups %outbuf %inbuf0 %inbuf1 %inbuf2 %inbuf3 %inbuf4\n"
2329 // Group decoration on multiple struct members.
2330 "OpGroupMemberDecorate %groupm %outbuf 0 %inbuf0 0 %inbuf1 0 %inbuf2 0 %inbuf3 0 %inbuf4 0\n"
2332 "OpDecorate %group1 DescriptorSet 0\n"
2333 "OpDecorate %group3 DescriptorSet 0\n"
2334 "OpDecorate %group3 NonWritable\n"
2335 "OpDecorate %group3 Restrict\n"
2336 "%group0 = OpDecorationGroup\n"
2337 "%group1 = OpDecorationGroup\n"
2338 "%group3 = OpDecorationGroup\n"
2340 // Applying the same decoration group multiple times.
2341 "OpGroupDecorate %group1 %outdata\n"
2342 "OpGroupDecorate %group1 %outdata\n"
2343 "OpGroupDecorate %group1 %outdata\n"
2344 "OpDecorate %outdata DescriptorSet 0\n"
2345 "OpDecorate %outdata Binding 5\n"
2346 // Applying decoration group containing nothing.
2347 "OpGroupDecorate %group0 %indata0\n"
2348 "OpDecorate %indata0 DescriptorSet 0\n"
2349 "OpDecorate %indata0 Binding 0\n"
2350 // Applying decoration group containing one decoration.
2351 "OpGroupDecorate %group1 %indata1\n"
2352 "OpDecorate %indata1 Binding 1\n"
2353 // Applying decoration group containing multiple decorations.
2354 "OpGroupDecorate %group3 %indata2 %indata3\n"
2355 "OpDecorate %indata2 Binding 2\n"
2356 "OpDecorate %indata3 Binding 3\n"
2357 // Applying multiple decoration groups (with overlapping).
2358 "OpGroupDecorate %group0 %indata4\n"
2359 "OpGroupDecorate %group1 %indata4\n"
2360 "OpGroupDecorate %group3 %indata4\n"
2361 "OpDecorate %indata4 Binding 4\n"
2363 + string(getComputeAsmCommonTypes()) +
2365 "%id = OpVariable %uvec3ptr Input\n"
2366 "%zero = OpConstant %i32 0\n"
2368 "%outbuf = OpTypeStruct %f32arr\n"
2369 "%outbufptr = OpTypePointer Uniform %outbuf\n"
2370 "%outdata = OpVariable %outbufptr Uniform\n"
2371 "%inbuf0 = OpTypeStruct %f32arr\n"
2372 "%inbuf0ptr = OpTypePointer Uniform %inbuf0\n"
2373 "%indata0 = OpVariable %inbuf0ptr Uniform\n"
2374 "%inbuf1 = OpTypeStruct %f32arr\n"
2375 "%inbuf1ptr = OpTypePointer Uniform %inbuf1\n"
2376 "%indata1 = OpVariable %inbuf1ptr Uniform\n"
2377 "%inbuf2 = OpTypeStruct %f32arr\n"
2378 "%inbuf2ptr = OpTypePointer Uniform %inbuf2\n"
2379 "%indata2 = OpVariable %inbuf2ptr Uniform\n"
2380 "%inbuf3 = OpTypeStruct %f32arr\n"
2381 "%inbuf3ptr = OpTypePointer Uniform %inbuf3\n"
2382 "%indata3 = OpVariable %inbuf3ptr Uniform\n"
2383 "%inbuf4 = OpTypeStruct %f32arr\n"
2384 "%inbufptr = OpTypePointer Uniform %inbuf4\n"
2385 "%indata4 = OpVariable %inbufptr Uniform\n"
2387 "%main = OpFunction %void None %voidf\n"
2388 "%label = OpLabel\n"
2389 "%idval = OpLoad %uvec3 %id\n"
2390 "%x = OpCompositeExtract %u32 %idval 0\n"
2391 "%inloc0 = OpAccessChain %f32ptr %indata0 %zero %x\n"
2392 "%inloc1 = OpAccessChain %f32ptr %indata1 %zero %x\n"
2393 "%inloc2 = OpAccessChain %f32ptr %indata2 %zero %x\n"
2394 "%inloc3 = OpAccessChain %f32ptr %indata3 %zero %x\n"
2395 "%inloc4 = OpAccessChain %f32ptr %indata4 %zero %x\n"
2396 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2397 "%inval0 = OpLoad %f32 %inloc0\n"
2398 "%inval1 = OpLoad %f32 %inloc1\n"
2399 "%inval2 = OpLoad %f32 %inloc2\n"
2400 "%inval3 = OpLoad %f32 %inloc3\n"
2401 "%inval4 = OpLoad %f32 %inloc4\n"
2402 "%add0 = OpFAdd %f32 %inval0 %inval1\n"
2403 "%add1 = OpFAdd %f32 %add0 %inval2\n"
2404 "%add2 = OpFAdd %f32 %add1 %inval3\n"
2405 "%add = OpFAdd %f32 %add2 %inval4\n"
2406 " OpStore %outloc %add\n"
2409 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats0)));
2410 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats1)));
2411 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
2412 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats3)));
2413 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats4)));
2414 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
2415 spec.numWorkGroups = IVec3(numElements, 1, 1);
2417 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "decoration group cases", spec));
2419 return group.release();
2422 struct SpecConstantTwoIntCase
2424 const char* caseName;
2425 const char* scDefinition0;
2426 const char* scDefinition1;
2427 const char* scResultType;
2428 const char* scOperation;
2429 deInt32 scActualValue0;
2430 deInt32 scActualValue1;
2431 const char* resultOperation;
2432 vector<deInt32> expectedOutput;
2434 SpecConstantTwoIntCase (const char* name,
2435 const char* definition0,
2436 const char* definition1,
2437 const char* resultType,
2438 const char* operation,
2441 const char* resultOp,
2442 const vector<deInt32>& output)
2444 , scDefinition0 (definition0)
2445 , scDefinition1 (definition1)
2446 , scResultType (resultType)
2447 , scOperation (operation)
2448 , scActualValue0 (value0)
2449 , scActualValue1 (value1)
2450 , resultOperation (resultOp)
2451 , expectedOutput (output) {}
2454 tcu::TestCaseGroup* createSpecConstantGroup (tcu::TestContext& testCtx)
2456 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opspecconstantop", "Test the OpSpecConstantOp instruction"));
2457 vector<SpecConstantTwoIntCase> cases;
2458 de::Random rnd (deStringHash(group->getName()));
2459 const int numElements = 100;
2460 vector<deInt32> inputInts (numElements, 0);
2461 vector<deInt32> outputInts1 (numElements, 0);
2462 vector<deInt32> outputInts2 (numElements, 0);
2463 vector<deInt32> outputInts3 (numElements, 0);
2464 vector<deInt32> outputInts4 (numElements, 0);
2465 const StringTemplate shaderTemplate (
2466 string(getComputeAsmShaderPreamble()) +
2468 "OpName %main \"main\"\n"
2469 "OpName %id \"gl_GlobalInvocationID\"\n"
2471 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2472 "OpDecorate %sc_0 SpecId 0\n"
2473 "OpDecorate %sc_1 SpecId 1\n"
2474 "OpDecorate %i32arr ArrayStride 4\n"
2476 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
2478 "%buf = OpTypeStruct %i32arr\n"
2479 "%bufptr = OpTypePointer Uniform %buf\n"
2480 "%indata = OpVariable %bufptr Uniform\n"
2481 "%outdata = OpVariable %bufptr Uniform\n"
2483 "%id = OpVariable %uvec3ptr Input\n"
2484 "%zero = OpConstant %i32 0\n"
2486 "%sc_0 = OpSpecConstant${SC_DEF0}\n"
2487 "%sc_1 = OpSpecConstant${SC_DEF1}\n"
2488 "%sc_final = OpSpecConstantOp ${SC_RESULT_TYPE} ${SC_OP}\n"
2490 "%main = OpFunction %void None %voidf\n"
2491 "%label = OpLabel\n"
2492 "%idval = OpLoad %uvec3 %id\n"
2493 "%x = OpCompositeExtract %u32 %idval 0\n"
2494 "%inloc = OpAccessChain %i32ptr %indata %zero %x\n"
2495 "%inval = OpLoad %i32 %inloc\n"
2496 "%final = ${GEN_RESULT}\n"
2497 "%outloc = OpAccessChain %i32ptr %outdata %zero %x\n"
2498 " OpStore %outloc %final\n"
2500 " OpFunctionEnd\n");
2502 fillRandomScalars(rnd, -65536, 65536, &inputInts[0], numElements);
2504 for (size_t ndx = 0; ndx < numElements; ++ndx)
2506 outputInts1[ndx] = inputInts[ndx] + 42;
2507 outputInts2[ndx] = inputInts[ndx];
2508 outputInts3[ndx] = inputInts[ndx] - 11200;
2509 outputInts4[ndx] = inputInts[ndx] + 1;
2512 const char addScToInput[] = "OpIAdd %i32 %inval %sc_final";
2513 const char selectTrueUsingSc[] = "OpSelect %i32 %sc_final %inval %zero";
2514 const char selectFalseUsingSc[] = "OpSelect %i32 %sc_final %zero %inval";
2516 cases.push_back(SpecConstantTwoIntCase("iadd", " %i32 0", " %i32 0", "%i32", "IAdd %sc_0 %sc_1", 62, -20, addScToInput, outputInts1));
2517 cases.push_back(SpecConstantTwoIntCase("isub", " %i32 0", " %i32 0", "%i32", "ISub %sc_0 %sc_1", 100, 58, addScToInput, outputInts1));
2518 cases.push_back(SpecConstantTwoIntCase("imul", " %i32 0", " %i32 0", "%i32", "IMul %sc_0 %sc_1", -2, -21, addScToInput, outputInts1));
2519 cases.push_back(SpecConstantTwoIntCase("sdiv", " %i32 0", " %i32 0", "%i32", "SDiv %sc_0 %sc_1", -126, -3, addScToInput, outputInts1));
2520 cases.push_back(SpecConstantTwoIntCase("udiv", " %i32 0", " %i32 0", "%i32", "UDiv %sc_0 %sc_1", 126, 3, addScToInput, outputInts1));
2521 cases.push_back(SpecConstantTwoIntCase("srem", " %i32 0", " %i32 0", "%i32", "SRem %sc_0 %sc_1", 7, 3, addScToInput, outputInts4));
2522 cases.push_back(SpecConstantTwoIntCase("smod", " %i32 0", " %i32 0", "%i32", "SMod %sc_0 %sc_1", 7, 3, addScToInput, outputInts4));
2523 cases.push_back(SpecConstantTwoIntCase("umod", " %i32 0", " %i32 0", "%i32", "UMod %sc_0 %sc_1", 342, 50, addScToInput, outputInts1));
2524 cases.push_back(SpecConstantTwoIntCase("bitwiseand", " %i32 0", " %i32 0", "%i32", "BitwiseAnd %sc_0 %sc_1", 42, 63, addScToInput, outputInts1));
2525 cases.push_back(SpecConstantTwoIntCase("bitwiseor", " %i32 0", " %i32 0", "%i32", "BitwiseOr %sc_0 %sc_1", 34, 8, addScToInput, outputInts1));
2526 cases.push_back(SpecConstantTwoIntCase("bitwisexor", " %i32 0", " %i32 0", "%i32", "BitwiseXor %sc_0 %sc_1", 18, 56, addScToInput, outputInts1));
2527 cases.push_back(SpecConstantTwoIntCase("shiftrightlogical", " %i32 0", " %i32 0", "%i32", "ShiftRightLogical %sc_0 %sc_1", 168, 2, addScToInput, outputInts1));
2528 cases.push_back(SpecConstantTwoIntCase("shiftrightarithmetic", " %i32 0", " %i32 0", "%i32", "ShiftRightArithmetic %sc_0 %sc_1", 168, 2, addScToInput, outputInts1));
2529 cases.push_back(SpecConstantTwoIntCase("shiftleftlogical", " %i32 0", " %i32 0", "%i32", "ShiftLeftLogical %sc_0 %sc_1", 21, 1, addScToInput, outputInts1));
2530 cases.push_back(SpecConstantTwoIntCase("slessthan", " %i32 0", " %i32 0", "%bool", "SLessThan %sc_0 %sc_1", -20, -10, selectTrueUsingSc, outputInts2));
2531 cases.push_back(SpecConstantTwoIntCase("ulessthan", " %i32 0", " %i32 0", "%bool", "ULessThan %sc_0 %sc_1", 10, 20, selectTrueUsingSc, outputInts2));
2532 cases.push_back(SpecConstantTwoIntCase("sgreaterthan", " %i32 0", " %i32 0", "%bool", "SGreaterThan %sc_0 %sc_1", -1000, 50, selectFalseUsingSc, outputInts2));
2533 cases.push_back(SpecConstantTwoIntCase("ugreaterthan", " %i32 0", " %i32 0", "%bool", "UGreaterThan %sc_0 %sc_1", 10, 5, selectTrueUsingSc, outputInts2));
2534 cases.push_back(SpecConstantTwoIntCase("slessthanequal", " %i32 0", " %i32 0", "%bool", "SLessThanEqual %sc_0 %sc_1", -10, -10, selectTrueUsingSc, outputInts2));
2535 cases.push_back(SpecConstantTwoIntCase("ulessthanequal", " %i32 0", " %i32 0", "%bool", "ULessThanEqual %sc_0 %sc_1", 50, 100, selectTrueUsingSc, outputInts2));
2536 cases.push_back(SpecConstantTwoIntCase("sgreaterthanequal", " %i32 0", " %i32 0", "%bool", "SGreaterThanEqual %sc_0 %sc_1", -1000, 50, selectFalseUsingSc, outputInts2));
2537 cases.push_back(SpecConstantTwoIntCase("ugreaterthanequal", " %i32 0", " %i32 0", "%bool", "UGreaterThanEqual %sc_0 %sc_1", 10, 10, selectTrueUsingSc, outputInts2));
2538 cases.push_back(SpecConstantTwoIntCase("iequal", " %i32 0", " %i32 0", "%bool", "IEqual %sc_0 %sc_1", 42, 24, selectFalseUsingSc, outputInts2));
2539 cases.push_back(SpecConstantTwoIntCase("logicaland", "True %bool", "True %bool", "%bool", "LogicalAnd %sc_0 %sc_1", 0, 1, selectFalseUsingSc, outputInts2));
2540 cases.push_back(SpecConstantTwoIntCase("logicalor", "False %bool", "False %bool", "%bool", "LogicalOr %sc_0 %sc_1", 1, 0, selectTrueUsingSc, outputInts2));
2541 cases.push_back(SpecConstantTwoIntCase("logicalequal", "True %bool", "True %bool", "%bool", "LogicalEqual %sc_0 %sc_1", 0, 1, selectFalseUsingSc, outputInts2));
2542 cases.push_back(SpecConstantTwoIntCase("logicalnotequal", "False %bool", "False %bool", "%bool", "LogicalNotEqual %sc_0 %sc_1", 1, 0, selectTrueUsingSc, outputInts2));
2543 cases.push_back(SpecConstantTwoIntCase("snegate", " %i32 0", " %i32 0", "%i32", "SNegate %sc_0", -42, 0, addScToInput, outputInts1));
2544 cases.push_back(SpecConstantTwoIntCase("not", " %i32 0", " %i32 0", "%i32", "Not %sc_0", -43, 0, addScToInput, outputInts1));
2545 cases.push_back(SpecConstantTwoIntCase("logicalnot", "False %bool", "False %bool", "%bool", "LogicalNot %sc_0", 1, 0, selectFalseUsingSc, outputInts2));
2546 cases.push_back(SpecConstantTwoIntCase("select", "False %bool", " %i32 0", "%i32", "Select %sc_0 %sc_1 %zero", 1, 42, addScToInput, outputInts1));
2547 // OpSConvert, OpFConvert: these two instructions involve ints/floats of different bitwidths.
2549 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
2551 map<string, string> specializations;
2552 ComputeShaderSpec spec;
2554 specializations["SC_DEF0"] = cases[caseNdx].scDefinition0;
2555 specializations["SC_DEF1"] = cases[caseNdx].scDefinition1;
2556 specializations["SC_RESULT_TYPE"] = cases[caseNdx].scResultType;
2557 specializations["SC_OP"] = cases[caseNdx].scOperation;
2558 specializations["GEN_RESULT"] = cases[caseNdx].resultOperation;
2560 spec.assembly = shaderTemplate.specialize(specializations);
2561 spec.inputs.push_back(BufferSp(new Int32Buffer(inputInts)));
2562 spec.outputs.push_back(BufferSp(new Int32Buffer(cases[caseNdx].expectedOutput)));
2563 spec.numWorkGroups = IVec3(numElements, 1, 1);
2564 spec.specConstants.push_back(cases[caseNdx].scActualValue0);
2565 spec.specConstants.push_back(cases[caseNdx].scActualValue1);
2567 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].caseName, cases[caseNdx].caseName, spec));
2570 ComputeShaderSpec spec;
2573 string(getComputeAsmShaderPreamble()) +
2575 "OpName %main \"main\"\n"
2576 "OpName %id \"gl_GlobalInvocationID\"\n"
2578 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2579 "OpDecorate %sc_0 SpecId 0\n"
2580 "OpDecorate %sc_1 SpecId 1\n"
2581 "OpDecorate %sc_2 SpecId 2\n"
2582 "OpDecorate %i32arr ArrayStride 4\n"
2584 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
2586 "%ivec3 = OpTypeVector %i32 3\n"
2587 "%buf = OpTypeStruct %i32arr\n"
2588 "%bufptr = OpTypePointer Uniform %buf\n"
2589 "%indata = OpVariable %bufptr Uniform\n"
2590 "%outdata = OpVariable %bufptr Uniform\n"
2592 "%id = OpVariable %uvec3ptr Input\n"
2593 "%zero = OpConstant %i32 0\n"
2594 "%ivec3_0 = OpConstantComposite %ivec3 %zero %zero %zero\n"
2595 "%vec3_undef = OpUndef %ivec3\n"
2597 "%sc_0 = OpSpecConstant %i32 0\n"
2598 "%sc_1 = OpSpecConstant %i32 0\n"
2599 "%sc_2 = OpSpecConstant %i32 0\n"
2600 "%sc_vec3_0 = OpSpecConstantOp %ivec3 CompositeInsert %sc_0 %ivec3_0 0\n" // (sc_0, 0, 0)
2601 "%sc_vec3_1 = OpSpecConstantOp %ivec3 CompositeInsert %sc_1 %ivec3_0 1\n" // (0, sc_1, 0)
2602 "%sc_vec3_2 = OpSpecConstantOp %ivec3 CompositeInsert %sc_2 %ivec3_0 2\n" // (0, 0, sc_2)
2603 "%sc_vec3_0_s = OpSpecConstantOp %ivec3 VectorShuffle %sc_vec3_0 %vec3_undef 0 0xFFFFFFFF 2\n" // (sc_0, ???, 0)
2604 "%sc_vec3_1_s = OpSpecConstantOp %ivec3 VectorShuffle %sc_vec3_1 %vec3_undef 0xFFFFFFFF 1 0\n" // (???, sc_1, 0)
2605 "%sc_vec3_2_s = OpSpecConstantOp %ivec3 VectorShuffle %vec3_undef %sc_vec3_2 5 0xFFFFFFFF 5\n" // (sc_2, ???, sc_2)
2606 "%sc_vec3_01 = OpSpecConstantOp %ivec3 VectorShuffle %sc_vec3_0_s %sc_vec3_1_s 1 0 4\n" // (0, sc_0, sc_1)
2607 "%sc_vec3_012 = OpSpecConstantOp %ivec3 VectorShuffle %sc_vec3_01 %sc_vec3_2_s 5 1 2\n" // (sc_2, sc_0, sc_1)
2608 "%sc_ext_0 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 0\n" // sc_2
2609 "%sc_ext_1 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 1\n" // sc_0
2610 "%sc_ext_2 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 2\n" // sc_1
2611 "%sc_sub = OpSpecConstantOp %i32 ISub %sc_ext_0 %sc_ext_1\n" // (sc_2 - sc_0)
2612 "%sc_final = OpSpecConstantOp %i32 IMul %sc_sub %sc_ext_2\n" // (sc_2 - sc_0) * sc_1
2614 "%main = OpFunction %void None %voidf\n"
2615 "%label = OpLabel\n"
2616 "%idval = OpLoad %uvec3 %id\n"
2617 "%x = OpCompositeExtract %u32 %idval 0\n"
2618 "%inloc = OpAccessChain %i32ptr %indata %zero %x\n"
2619 "%inval = OpLoad %i32 %inloc\n"
2620 "%final = OpIAdd %i32 %inval %sc_final\n"
2621 "%outloc = OpAccessChain %i32ptr %outdata %zero %x\n"
2622 " OpStore %outloc %final\n"
2625 spec.inputs.push_back(BufferSp(new Int32Buffer(inputInts)));
2626 spec.outputs.push_back(BufferSp(new Int32Buffer(outputInts3)));
2627 spec.numWorkGroups = IVec3(numElements, 1, 1);
2628 spec.specConstants.push_back(123);
2629 spec.specConstants.push_back(56);
2630 spec.specConstants.push_back(-77);
2632 group->addChild(new SpvAsmComputeShaderCase(testCtx, "vector_related", "VectorShuffle, CompositeExtract, & CompositeInsert", spec));
2634 return group.release();
2637 string generateConstantDefinitions (int count)
2639 std::stringstream r;
2640 for (int i = 0; i < count; i++)
2641 r << "%cf" << (i * 10 + 5) << " = OpConstant %f32 " <<(i * 10 + 5) << ".0\n";
2642 return r.str() + string("\n");
2645 string generateSwitchCases (int count)
2647 std::stringstream r;
2648 for (int i = 0; i < count; i++)
2649 r << " " << i << " %case" << i;
2650 return r.str() + string("\n");
2653 string generateSwitchTargets (int count)
2655 std::stringstream r;
2656 for (int i = 0; i < count; i++)
2657 r << "%case" << i << " = OpLabel\n OpBranch %phi\n";
2658 return r.str() + string("\n");
2661 string generateOpPhiParams (int count)
2663 std::stringstream r;
2664 for (int i = 0; i < count; i++)
2665 r << " %cf" << (i * 10 + 5) << " %case" << i;
2666 return r.str() + string("\n");
2669 string generateIntWidth (int value)
2671 std::stringstream r;
2676 tcu::TestCaseGroup* createOpPhiGroup (tcu::TestContext& testCtx)
2678 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opphi", "Test the OpPhi instruction"));
2679 ComputeShaderSpec spec1;
2680 ComputeShaderSpec spec2;
2681 ComputeShaderSpec spec3;
2682 ComputeShaderSpec spec4;
2683 de::Random rnd (deStringHash(group->getName()));
2684 const int numElements = 100;
2685 vector<float> inputFloats (numElements, 0);
2686 vector<float> outputFloats1 (numElements, 0);
2687 vector<float> outputFloats2 (numElements, 0);
2688 vector<float> outputFloats3 (numElements, 0);
2689 vector<float> outputFloats4 (numElements, 0);
2690 const int test4Width = 1024;
2692 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats[0], numElements);
2694 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
2695 floorAll(inputFloats);
2697 for (size_t ndx = 0; ndx < numElements; ++ndx)
2701 case 0: outputFloats1[ndx] = inputFloats[ndx] + 5.5f; break;
2702 case 1: outputFloats1[ndx] = inputFloats[ndx] + 20.5f; break;
2703 case 2: outputFloats1[ndx] = inputFloats[ndx] + 1.75f; break;
2706 outputFloats2[ndx] = inputFloats[ndx] + 6.5f * 3;
2707 outputFloats3[ndx] = 8.5f - inputFloats[ndx];
2709 int index4 = (int)deFloor(deAbs((float)ndx * inputFloats[ndx]));
2710 outputFloats4[ndx] = (float)(index4 % test4Width) * 10.0f + 5.0f;
2714 string(getComputeAsmShaderPreamble()) +
2716 "OpSource GLSL 430\n"
2717 "OpName %main \"main\"\n"
2718 "OpName %id \"gl_GlobalInvocationID\"\n"
2720 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2722 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
2724 "%id = OpVariable %uvec3ptr Input\n"
2725 "%zero = OpConstant %i32 0\n"
2726 "%three = OpConstant %u32 3\n"
2727 "%constf5p5 = OpConstant %f32 5.5\n"
2728 "%constf20p5 = OpConstant %f32 20.5\n"
2729 "%constf1p75 = OpConstant %f32 1.75\n"
2730 "%constf8p5 = OpConstant %f32 8.5\n"
2731 "%constf6p5 = OpConstant %f32 6.5\n"
2733 "%main = OpFunction %void None %voidf\n"
2734 "%entry = OpLabel\n"
2735 "%idval = OpLoad %uvec3 %id\n"
2736 "%x = OpCompositeExtract %u32 %idval 0\n"
2737 "%selector = OpUMod %u32 %x %three\n"
2738 " OpSelectionMerge %phi None\n"
2739 " OpSwitch %selector %default 0 %case0 1 %case1 2 %case2\n"
2741 // Case 1 before OpPhi.
2742 "%case1 = OpLabel\n"
2745 "%default = OpLabel\n"
2749 "%operand = OpPhi %f32 %constf1p75 %case2 %constf20p5 %case1 %constf5p5 %case0\n" // not in the order of blocks
2750 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
2751 "%inval = OpLoad %f32 %inloc\n"
2752 "%add = OpFAdd %f32 %inval %operand\n"
2753 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2754 " OpStore %outloc %add\n"
2757 // Case 0 after OpPhi.
2758 "%case0 = OpLabel\n"
2762 // Case 2 after OpPhi.
2763 "%case2 = OpLabel\n"
2767 spec1.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
2768 spec1.outputs.push_back(BufferSp(new Float32Buffer(outputFloats1)));
2769 spec1.numWorkGroups = IVec3(numElements, 1, 1);
2771 group->addChild(new SpvAsmComputeShaderCase(testCtx, "block", "out-of-order and unreachable blocks for OpPhi", spec1));
2774 string(getComputeAsmShaderPreamble()) +
2776 "OpName %main \"main\"\n"
2777 "OpName %id \"gl_GlobalInvocationID\"\n"
2779 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2781 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
2783 "%id = OpVariable %uvec3ptr Input\n"
2784 "%zero = OpConstant %i32 0\n"
2785 "%one = OpConstant %i32 1\n"
2786 "%three = OpConstant %i32 3\n"
2787 "%constf6p5 = OpConstant %f32 6.5\n"
2789 "%main = OpFunction %void None %voidf\n"
2790 "%entry = OpLabel\n"
2791 "%idval = OpLoad %uvec3 %id\n"
2792 "%x = OpCompositeExtract %u32 %idval 0\n"
2793 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
2794 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2795 "%inval = OpLoad %f32 %inloc\n"
2799 "%step = OpPhi %i32 %zero %entry %step_next %phi\n"
2800 "%accum = OpPhi %f32 %inval %entry %accum_next %phi\n"
2801 "%step_next = OpIAdd %i32 %step %one\n"
2802 "%accum_next = OpFAdd %f32 %accum %constf6p5\n"
2803 "%still_loop = OpSLessThan %bool %step %three\n"
2804 " OpLoopMerge %exit %phi None\n"
2805 " OpBranchConditional %still_loop %phi %exit\n"
2808 " OpStore %outloc %accum\n"
2811 spec2.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
2812 spec2.outputs.push_back(BufferSp(new Float32Buffer(outputFloats2)));
2813 spec2.numWorkGroups = IVec3(numElements, 1, 1);
2815 group->addChild(new SpvAsmComputeShaderCase(testCtx, "induction", "The usual way induction variables are handled in LLVM IR", spec2));
2818 string(getComputeAsmShaderPreamble()) +
2820 "OpName %main \"main\"\n"
2821 "OpName %id \"gl_GlobalInvocationID\"\n"
2823 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2825 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
2827 "%f32ptr_f = OpTypePointer Function %f32\n"
2828 "%id = OpVariable %uvec3ptr Input\n"
2829 "%true = OpConstantTrue %bool\n"
2830 "%false = OpConstantFalse %bool\n"
2831 "%zero = OpConstant %i32 0\n"
2832 "%constf8p5 = OpConstant %f32 8.5\n"
2834 "%main = OpFunction %void None %voidf\n"
2835 "%entry = OpLabel\n"
2836 "%b = OpVariable %f32ptr_f Function %constf8p5\n"
2837 "%idval = OpLoad %uvec3 %id\n"
2838 "%x = OpCompositeExtract %u32 %idval 0\n"
2839 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
2840 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2841 "%a_init = OpLoad %f32 %inloc\n"
2842 "%b_init = OpLoad %f32 %b\n"
2846 "%still_loop = OpPhi %bool %true %entry %false %phi\n"
2847 "%a_next = OpPhi %f32 %a_init %entry %b_next %phi\n"
2848 "%b_next = OpPhi %f32 %b_init %entry %a_next %phi\n"
2849 " OpLoopMerge %exit %phi None\n"
2850 " OpBranchConditional %still_loop %phi %exit\n"
2853 "%sub = OpFSub %f32 %a_next %b_next\n"
2854 " OpStore %outloc %sub\n"
2857 spec3.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
2858 spec3.outputs.push_back(BufferSp(new Float32Buffer(outputFloats3)));
2859 spec3.numWorkGroups = IVec3(numElements, 1, 1);
2861 group->addChild(new SpvAsmComputeShaderCase(testCtx, "swap", "Swap the values of two variables using OpPhi", spec3));
2864 "OpCapability Shader\n"
2865 "%ext = OpExtInstImport \"GLSL.std.450\"\n"
2866 "OpMemoryModel Logical GLSL450\n"
2867 "OpEntryPoint GLCompute %main \"main\" %id\n"
2868 "OpExecutionMode %main LocalSize 1 1 1\n"
2870 "OpSource GLSL 430\n"
2871 "OpName %main \"main\"\n"
2872 "OpName %id \"gl_GlobalInvocationID\"\n"
2874 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2876 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
2878 "%id = OpVariable %uvec3ptr Input\n"
2879 "%zero = OpConstant %i32 0\n"
2880 "%cimod = OpConstant %u32 " + generateIntWidth(test4Width) + "\n"
2882 + generateConstantDefinitions(test4Width) +
2884 "%main = OpFunction %void None %voidf\n"
2885 "%entry = OpLabel\n"
2886 "%idval = OpLoad %uvec3 %id\n"
2887 "%x = OpCompositeExtract %u32 %idval 0\n"
2888 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
2889 "%inval = OpLoad %f32 %inloc\n"
2890 "%xf = OpConvertUToF %f32 %x\n"
2891 "%xm = OpFMul %f32 %xf %inval\n"
2892 "%xa = OpExtInst %f32 %ext FAbs %xm\n"
2893 "%xi = OpConvertFToU %u32 %xa\n"
2894 "%selector = OpUMod %u32 %xi %cimod\n"
2895 " OpSelectionMerge %phi None\n"
2896 " OpSwitch %selector %default "
2898 + generateSwitchCases(test4Width) +
2900 "%default = OpLabel\n"
2903 + generateSwitchTargets(test4Width) +
2906 "%result = OpPhi %f32"
2908 + generateOpPhiParams(test4Width) +
2910 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2911 " OpStore %outloc %result\n"
2915 spec4.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
2916 spec4.outputs.push_back(BufferSp(new Float32Buffer(outputFloats4)));
2917 spec4.numWorkGroups = IVec3(numElements, 1, 1);
2919 group->addChild(new SpvAsmComputeShaderCase(testCtx, "wide", "OpPhi with a lot of parameters", spec4));
2921 return group.release();
2924 // Assembly code used for testing block order is based on GLSL source code:
2928 // layout(std140, set = 0, binding = 0) readonly buffer Input {
2929 // float elements[];
2931 // layout(std140, set = 0, binding = 1) writeonly buffer Output {
2932 // float elements[];
2936 // uint x = gl_GlobalInvocationID.x;
2937 // output_data.elements[x] = input_data.elements[x];
2938 // if (x > uint(50)) {
2939 // switch (x % uint(3)) {
2940 // case 0: output_data.elements[x] += 1.5f; break;
2941 // case 1: output_data.elements[x] += 42.f; break;
2942 // case 2: output_data.elements[x] -= 27.f; break;
2946 // output_data.elements[x] = -input_data.elements[x];
2949 tcu::TestCaseGroup* createBlockOrderGroup (tcu::TestContext& testCtx)
2951 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "block_order", "Test block orders"));
2952 ComputeShaderSpec spec;
2953 de::Random rnd (deStringHash(group->getName()));
2954 const int numElements = 100;
2955 vector<float> inputFloats (numElements, 0);
2956 vector<float> outputFloats (numElements, 0);
2958 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats[0], numElements);
2960 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
2961 floorAll(inputFloats);
2963 for (size_t ndx = 0; ndx <= 50; ++ndx)
2964 outputFloats[ndx] = -inputFloats[ndx];
2966 for (size_t ndx = 51; ndx < numElements; ++ndx)
2970 case 0: outputFloats[ndx] = inputFloats[ndx] + 1.5f; break;
2971 case 1: outputFloats[ndx] = inputFloats[ndx] + 42.f; break;
2972 case 2: outputFloats[ndx] = inputFloats[ndx] - 27.f; break;
2978 string(getComputeAsmShaderPreamble()) +
2980 "OpSource GLSL 430\n"
2981 "OpName %main \"main\"\n"
2982 "OpName %id \"gl_GlobalInvocationID\"\n"
2984 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2986 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
2988 "%u32ptr = OpTypePointer Function %u32\n"
2989 "%u32ptr_input = OpTypePointer Input %u32\n"
2991 + string(getComputeAsmInputOutputBuffer()) +
2993 "%id = OpVariable %uvec3ptr Input\n"
2994 "%zero = OpConstant %i32 0\n"
2995 "%const3 = OpConstant %u32 3\n"
2996 "%const50 = OpConstant %u32 50\n"
2997 "%constf1p5 = OpConstant %f32 1.5\n"
2998 "%constf27 = OpConstant %f32 27.0\n"
2999 "%constf42 = OpConstant %f32 42.0\n"
3001 "%main = OpFunction %void None %voidf\n"
3004 "%entry = OpLabel\n"
3006 // Create a temporary variable to hold the value of gl_GlobalInvocationID.x.
3007 "%xvar = OpVariable %u32ptr Function\n"
3008 "%xptr = OpAccessChain %u32ptr_input %id %zero\n"
3009 "%x = OpLoad %u32 %xptr\n"
3010 " OpStore %xvar %x\n"
3012 "%cmp = OpUGreaterThan %bool %x %const50\n"
3013 " OpSelectionMerge %if_merge None\n"
3014 " OpBranchConditional %cmp %if_true %if_false\n"
3016 // False branch for if-statement: placed in the middle of switch cases and before true branch.
3017 "%if_false = OpLabel\n"
3018 "%x_f = OpLoad %u32 %xvar\n"
3019 "%inloc_f = OpAccessChain %f32ptr %indata %zero %x_f\n"
3020 "%inval_f = OpLoad %f32 %inloc_f\n"
3021 "%negate = OpFNegate %f32 %inval_f\n"
3022 "%outloc_f = OpAccessChain %f32ptr %outdata %zero %x_f\n"
3023 " OpStore %outloc_f %negate\n"
3024 " OpBranch %if_merge\n"
3026 // Merge block for if-statement: placed in the middle of true and false branch.
3027 "%if_merge = OpLabel\n"
3030 // True branch for if-statement: placed in the middle of swtich cases and after the false branch.
3031 "%if_true = OpLabel\n"
3032 "%xval_t = OpLoad %u32 %xvar\n"
3033 "%mod = OpUMod %u32 %xval_t %const3\n"
3034 " OpSelectionMerge %switch_merge None\n"
3035 " OpSwitch %mod %default 0 %case0 1 %case1 2 %case2\n"
3037 // Merge block for switch-statement: placed before the case
3038 // bodies. But it must follow OpSwitch which dominates it.
3039 "%switch_merge = OpLabel\n"
3040 " OpBranch %if_merge\n"
3042 // Case 1 for switch-statement: placed before case 0.
3043 // It must follow the OpSwitch that dominates it.
3044 "%case1 = OpLabel\n"
3045 "%x_1 = OpLoad %u32 %xvar\n"
3046 "%inloc_1 = OpAccessChain %f32ptr %indata %zero %x_1\n"
3047 "%inval_1 = OpLoad %f32 %inloc_1\n"
3048 "%addf42 = OpFAdd %f32 %inval_1 %constf42\n"
3049 "%outloc_1 = OpAccessChain %f32ptr %outdata %zero %x_1\n"
3050 " OpStore %outloc_1 %addf42\n"
3051 " OpBranch %switch_merge\n"
3053 // Case 2 for switch-statement.
3054 "%case2 = OpLabel\n"
3055 "%x_2 = OpLoad %u32 %xvar\n"
3056 "%inloc_2 = OpAccessChain %f32ptr %indata %zero %x_2\n"
3057 "%inval_2 = OpLoad %f32 %inloc_2\n"
3058 "%subf27 = OpFSub %f32 %inval_2 %constf27\n"
3059 "%outloc_2 = OpAccessChain %f32ptr %outdata %zero %x_2\n"
3060 " OpStore %outloc_2 %subf27\n"
3061 " OpBranch %switch_merge\n"
3063 // Default case for switch-statement: placed in the middle of normal cases.
3064 "%default = OpLabel\n"
3065 " OpBranch %switch_merge\n"
3067 // Case 0 for switch-statement: out of order.
3068 "%case0 = OpLabel\n"
3069 "%x_0 = OpLoad %u32 %xvar\n"
3070 "%inloc_0 = OpAccessChain %f32ptr %indata %zero %x_0\n"
3071 "%inval_0 = OpLoad %f32 %inloc_0\n"
3072 "%addf1p5 = OpFAdd %f32 %inval_0 %constf1p5\n"
3073 "%outloc_0 = OpAccessChain %f32ptr %outdata %zero %x_0\n"
3074 " OpStore %outloc_0 %addf1p5\n"
3075 " OpBranch %switch_merge\n"
3078 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
3079 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
3080 spec.numWorkGroups = IVec3(numElements, 1, 1);
3082 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "various out-of-order blocks", spec));
3084 return group.release();
3087 tcu::TestCaseGroup* createMultipleShaderGroup (tcu::TestContext& testCtx)
3089 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "multiple_shaders", "Test multiple shaders in the same module"));
3090 ComputeShaderSpec spec1;
3091 ComputeShaderSpec spec2;
3092 de::Random rnd (deStringHash(group->getName()));
3093 const int numElements = 100;
3094 vector<float> inputFloats (numElements, 0);
3095 vector<float> outputFloats1 (numElements, 0);
3096 vector<float> outputFloats2 (numElements, 0);
3097 fillRandomScalars(rnd, -500.f, 500.f, &inputFloats[0], numElements);
3099 for (size_t ndx = 0; ndx < numElements; ++ndx)
3101 outputFloats1[ndx] = inputFloats[ndx] + inputFloats[ndx];
3102 outputFloats2[ndx] = -inputFloats[ndx];
3105 const string assembly(
3106 "OpCapability Shader\n"
3107 "OpCapability ClipDistance\n"
3108 "OpMemoryModel Logical GLSL450\n"
3109 "OpEntryPoint GLCompute %comp_main1 \"entrypoint1\" %id\n"
3110 "OpEntryPoint GLCompute %comp_main2 \"entrypoint2\" %id\n"
3111 // A module cannot have two OpEntryPoint instructions with the same Execution Model and the same Name string.
3112 "OpEntryPoint Vertex %vert_main \"entrypoint2\" %vert_builtins %vertexIndex %instanceIndex\n"
3113 "OpExecutionMode %comp_main1 LocalSize 1 1 1\n"
3114 "OpExecutionMode %comp_main2 LocalSize 1 1 1\n"
3116 "OpName %comp_main1 \"entrypoint1\"\n"
3117 "OpName %comp_main2 \"entrypoint2\"\n"
3118 "OpName %vert_main \"entrypoint2\"\n"
3119 "OpName %id \"gl_GlobalInvocationID\"\n"
3120 "OpName %vert_builtin_st \"gl_PerVertex\"\n"
3121 "OpName %vertexIndex \"gl_VertexIndex\"\n"
3122 "OpName %instanceIndex \"gl_InstanceIndex\"\n"
3123 "OpMemberName %vert_builtin_st 0 \"gl_Position\"\n"
3124 "OpMemberName %vert_builtin_st 1 \"gl_PointSize\"\n"
3125 "OpMemberName %vert_builtin_st 2 \"gl_ClipDistance\"\n"
3127 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3128 "OpDecorate %vertexIndex BuiltIn VertexIndex\n"
3129 "OpDecorate %instanceIndex BuiltIn InstanceIndex\n"
3130 "OpDecorate %vert_builtin_st Block\n"
3131 "OpMemberDecorate %vert_builtin_st 0 BuiltIn Position\n"
3132 "OpMemberDecorate %vert_builtin_st 1 BuiltIn PointSize\n"
3133 "OpMemberDecorate %vert_builtin_st 2 BuiltIn ClipDistance\n"
3135 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
3137 "%zero = OpConstant %i32 0\n"
3138 "%one = OpConstant %u32 1\n"
3139 "%c_f32_1 = OpConstant %f32 1\n"
3141 "%i32inputptr = OpTypePointer Input %i32\n"
3142 "%vec4 = OpTypeVector %f32 4\n"
3143 "%vec4ptr = OpTypePointer Output %vec4\n"
3144 "%f32arr1 = OpTypeArray %f32 %one\n"
3145 "%vert_builtin_st = OpTypeStruct %vec4 %f32 %f32arr1\n"
3146 "%vert_builtin_st_ptr = OpTypePointer Output %vert_builtin_st\n"
3147 "%vert_builtins = OpVariable %vert_builtin_st_ptr Output\n"
3149 "%id = OpVariable %uvec3ptr Input\n"
3150 "%vertexIndex = OpVariable %i32inputptr Input\n"
3151 "%instanceIndex = OpVariable %i32inputptr Input\n"
3152 "%c_vec4_1 = OpConstantComposite %vec4 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_1\n"
3154 // gl_Position = vec4(1.);
3155 "%vert_main = OpFunction %void None %voidf\n"
3156 "%vert_entry = OpLabel\n"
3157 "%position = OpAccessChain %vec4ptr %vert_builtins %zero\n"
3158 " OpStore %position %c_vec4_1\n"
3163 "%comp_main1 = OpFunction %void None %voidf\n"
3164 "%comp1_entry = OpLabel\n"
3165 "%idval1 = OpLoad %uvec3 %id\n"
3166 "%x1 = OpCompositeExtract %u32 %idval1 0\n"
3167 "%inloc1 = OpAccessChain %f32ptr %indata %zero %x1\n"
3168 "%inval1 = OpLoad %f32 %inloc1\n"
3169 "%add = OpFAdd %f32 %inval1 %inval1\n"
3170 "%outloc1 = OpAccessChain %f32ptr %outdata %zero %x1\n"
3171 " OpStore %outloc1 %add\n"
3176 "%comp_main2 = OpFunction %void None %voidf\n"
3177 "%comp2_entry = OpLabel\n"
3178 "%idval2 = OpLoad %uvec3 %id\n"
3179 "%x2 = OpCompositeExtract %u32 %idval2 0\n"
3180 "%inloc2 = OpAccessChain %f32ptr %indata %zero %x2\n"
3181 "%inval2 = OpLoad %f32 %inloc2\n"
3182 "%neg = OpFNegate %f32 %inval2\n"
3183 "%outloc2 = OpAccessChain %f32ptr %outdata %zero %x2\n"
3184 " OpStore %outloc2 %neg\n"
3186 " OpFunctionEnd\n");
3188 spec1.assembly = assembly;
3189 spec1.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
3190 spec1.outputs.push_back(BufferSp(new Float32Buffer(outputFloats1)));
3191 spec1.numWorkGroups = IVec3(numElements, 1, 1);
3192 spec1.entryPoint = "entrypoint1";
3194 spec2.assembly = assembly;
3195 spec2.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
3196 spec2.outputs.push_back(BufferSp(new Float32Buffer(outputFloats2)));
3197 spec2.numWorkGroups = IVec3(numElements, 1, 1);
3198 spec2.entryPoint = "entrypoint2";
3200 group->addChild(new SpvAsmComputeShaderCase(testCtx, "shader1", "multiple shaders in the same module", spec1));
3201 group->addChild(new SpvAsmComputeShaderCase(testCtx, "shader2", "multiple shaders in the same module", spec2));
3203 return group.release();
3206 inline std::string makeLongUTF8String (size_t num4ByteChars)
3208 // An example of a longest valid UTF-8 character. Be explicit about the
3209 // character type because Microsoft compilers can otherwise interpret the
3210 // character string as being over wide (16-bit) characters. Ideally, we
3211 // would just use a C++11 UTF-8 string literal, but we want to support older
3212 // Microsoft compilers.
3213 const std::basic_string<char> earthAfrica("\xF0\x9F\x8C\x8D");
3214 std::string longString;
3215 longString.reserve(num4ByteChars * 4);
3216 for (size_t count = 0; count < num4ByteChars; count++)
3218 longString += earthAfrica;
3223 tcu::TestCaseGroup* createOpSourceGroup (tcu::TestContext& testCtx)
3225 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opsource", "Tests the OpSource & OpSourceContinued instruction"));
3226 vector<CaseParameter> cases;
3227 de::Random rnd (deStringHash(group->getName()));
3228 const int numElements = 100;
3229 vector<float> positiveFloats (numElements, 0);
3230 vector<float> negativeFloats (numElements, 0);
3231 const StringTemplate shaderTemplate (
3232 "OpCapability Shader\n"
3233 "OpMemoryModel Logical GLSL450\n"
3235 "OpEntryPoint GLCompute %main \"main\" %id\n"
3236 "OpExecutionMode %main LocalSize 1 1 1\n"
3240 "OpName %main \"main\"\n"
3241 "OpName %id \"gl_GlobalInvocationID\"\n"
3243 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3245 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
3247 "%id = OpVariable %uvec3ptr Input\n"
3248 "%zero = OpConstant %i32 0\n"
3250 "%main = OpFunction %void None %voidf\n"
3251 "%label = OpLabel\n"
3252 "%idval = OpLoad %uvec3 %id\n"
3253 "%x = OpCompositeExtract %u32 %idval 0\n"
3254 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3255 "%inval = OpLoad %f32 %inloc\n"
3256 "%neg = OpFNegate %f32 %inval\n"
3257 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3258 " OpStore %outloc %neg\n"
3260 " OpFunctionEnd\n");
3262 cases.push_back(CaseParameter("unknown_source", "OpSource Unknown 0"));
3263 cases.push_back(CaseParameter("wrong_source", "OpSource OpenCL_C 210"));
3264 cases.push_back(CaseParameter("normal_filename", "%fname = OpString \"filename\"\n"
3265 "OpSource GLSL 430 %fname"));
3266 cases.push_back(CaseParameter("empty_filename", "%fname = OpString \"\"\n"
3267 "OpSource GLSL 430 %fname"));
3268 cases.push_back(CaseParameter("normal_source_code", "%fname = OpString \"filename\"\n"
3269 "OpSource GLSL 430 %fname \"#version 430\nvoid main() {}\""));
3270 cases.push_back(CaseParameter("empty_source_code", "%fname = OpString \"filename\"\n"
3271 "OpSource GLSL 430 %fname \"\""));
3272 cases.push_back(CaseParameter("long_source_code", "%fname = OpString \"filename\"\n"
3273 "OpSource GLSL 430 %fname \"" + makeLongUTF8String(65530) + "ccc\"")); // word count: 65535
3274 cases.push_back(CaseParameter("utf8_source_code", "%fname = OpString \"filename\"\n"
3275 "OpSource GLSL 430 %fname \"\xE2\x98\x82\xE2\x98\x85\"")); // umbrella & black star symbol
3276 cases.push_back(CaseParameter("normal_sourcecontinued", "%fname = OpString \"filename\"\n"
3277 "OpSource GLSL 430 %fname \"#version 430\nvo\"\n"
3278 "OpSourceContinued \"id main() {}\""));
3279 cases.push_back(CaseParameter("empty_sourcecontinued", "%fname = OpString \"filename\"\n"
3280 "OpSource GLSL 430 %fname \"#version 430\nvoid main() {}\"\n"
3281 "OpSourceContinued \"\""));
3282 cases.push_back(CaseParameter("long_sourcecontinued", "%fname = OpString \"filename\"\n"
3283 "OpSource GLSL 430 %fname \"#version 430\nvoid main() {}\"\n"
3284 "OpSourceContinued \"" + makeLongUTF8String(65533) + "ccc\"")); // word count: 65535
3285 cases.push_back(CaseParameter("utf8_sourcecontinued", "%fname = OpString \"filename\"\n"
3286 "OpSource GLSL 430 %fname \"#version 430\nvoid main() {}\"\n"
3287 "OpSourceContinued \"\xE2\x98\x8E\xE2\x9A\x91\"")); // white telephone & black flag symbol
3288 cases.push_back(CaseParameter("multi_sourcecontinued", "%fname = OpString \"filename\"\n"
3289 "OpSource GLSL 430 %fname \"#version 430\n\"\n"
3290 "OpSourceContinued \"void\"\n"
3291 "OpSourceContinued \"main()\"\n"
3292 "OpSourceContinued \"{}\""));
3293 cases.push_back(CaseParameter("empty_source_before_sourcecontinued", "%fname = OpString \"filename\"\n"
3294 "OpSource GLSL 430 %fname \"\"\n"
3295 "OpSourceContinued \"#version 430\nvoid main() {}\""));
3297 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
3299 for (size_t ndx = 0; ndx < numElements; ++ndx)
3300 negativeFloats[ndx] = -positiveFloats[ndx];
3302 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
3304 map<string, string> specializations;
3305 ComputeShaderSpec spec;
3307 specializations["SOURCE"] = cases[caseNdx].param;
3308 spec.assembly = shaderTemplate.specialize(specializations);
3309 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
3310 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
3311 spec.numWorkGroups = IVec3(numElements, 1, 1);
3313 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
3316 return group.release();
3319 tcu::TestCaseGroup* createOpSourceExtensionGroup (tcu::TestContext& testCtx)
3321 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opsourceextension", "Tests the OpSource instruction"));
3322 vector<CaseParameter> cases;
3323 de::Random rnd (deStringHash(group->getName()));
3324 const int numElements = 100;
3325 vector<float> inputFloats (numElements, 0);
3326 vector<float> outputFloats (numElements, 0);
3327 const StringTemplate shaderTemplate (
3328 string(getComputeAsmShaderPreamble()) +
3330 "OpSourceExtension \"${EXTENSION}\"\n"
3332 "OpName %main \"main\"\n"
3333 "OpName %id \"gl_GlobalInvocationID\"\n"
3335 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3337 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
3339 "%id = OpVariable %uvec3ptr Input\n"
3340 "%zero = OpConstant %i32 0\n"
3342 "%main = OpFunction %void None %voidf\n"
3343 "%label = OpLabel\n"
3344 "%idval = OpLoad %uvec3 %id\n"
3345 "%x = OpCompositeExtract %u32 %idval 0\n"
3346 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3347 "%inval = OpLoad %f32 %inloc\n"
3348 "%neg = OpFNegate %f32 %inval\n"
3349 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3350 " OpStore %outloc %neg\n"
3352 " OpFunctionEnd\n");
3354 cases.push_back(CaseParameter("empty_extension", ""));
3355 cases.push_back(CaseParameter("real_extension", "GL_ARB_texture_rectangle"));
3356 cases.push_back(CaseParameter("fake_extension", "GL_ARB_im_the_ultimate_extension"));
3357 cases.push_back(CaseParameter("utf8_extension", "GL_ARB_\xE2\x98\x82\xE2\x98\x85"));
3358 cases.push_back(CaseParameter("long_extension", makeLongUTF8String(65533) + "ccc")); // word count: 65535
3360 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats[0], numElements);
3362 for (size_t ndx = 0; ndx < numElements; ++ndx)
3363 outputFloats[ndx] = -inputFloats[ndx];
3365 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
3367 map<string, string> specializations;
3368 ComputeShaderSpec spec;
3370 specializations["EXTENSION"] = cases[caseNdx].param;
3371 spec.assembly = shaderTemplate.specialize(specializations);
3372 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
3373 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
3374 spec.numWorkGroups = IVec3(numElements, 1, 1);
3376 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
3379 return group.release();
3382 // Checks that a compute shader can generate a constant null value of various types, without exercising a computation on it.
3383 tcu::TestCaseGroup* createOpConstantNullGroup (tcu::TestContext& testCtx)
3385 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opconstantnull", "Tests the OpConstantNull instruction"));
3386 vector<CaseParameter> cases;
3387 de::Random rnd (deStringHash(group->getName()));
3388 const int numElements = 100;
3389 vector<float> positiveFloats (numElements, 0);
3390 vector<float> negativeFloats (numElements, 0);
3391 const StringTemplate shaderTemplate (
3392 string(getComputeAsmShaderPreamble()) +
3394 "OpSource GLSL 430\n"
3395 "OpName %main \"main\"\n"
3396 "OpName %id \"gl_GlobalInvocationID\"\n"
3398 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3400 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
3401 "%uvec2 = OpTypeVector %u32 2\n"
3402 "%bvec3 = OpTypeVector %bool 3\n"
3403 "%fvec4 = OpTypeVector %f32 4\n"
3404 "%fmat33 = OpTypeMatrix %fvec3 3\n"
3405 "%const100 = OpConstant %u32 100\n"
3406 "%uarr100 = OpTypeArray %i32 %const100\n"
3407 "%struct = OpTypeStruct %f32 %i32 %u32\n"
3408 "%pointer = OpTypePointer Function %i32\n"
3409 + string(getComputeAsmInputOutputBuffer()) +
3411 "%null = OpConstantNull ${TYPE}\n"
3413 "%id = OpVariable %uvec3ptr Input\n"
3414 "%zero = OpConstant %i32 0\n"
3416 "%main = OpFunction %void None %voidf\n"
3417 "%label = OpLabel\n"
3418 "%idval = OpLoad %uvec3 %id\n"
3419 "%x = OpCompositeExtract %u32 %idval 0\n"
3420 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3421 "%inval = OpLoad %f32 %inloc\n"
3422 "%neg = OpFNegate %f32 %inval\n"
3423 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3424 " OpStore %outloc %neg\n"
3426 " OpFunctionEnd\n");
3428 cases.push_back(CaseParameter("bool", "%bool"));
3429 cases.push_back(CaseParameter("sint32", "%i32"));
3430 cases.push_back(CaseParameter("uint32", "%u32"));
3431 cases.push_back(CaseParameter("float32", "%f32"));
3432 cases.push_back(CaseParameter("vec4float32", "%fvec4"));
3433 cases.push_back(CaseParameter("vec3bool", "%bvec3"));
3434 cases.push_back(CaseParameter("vec2uint32", "%uvec2"));
3435 cases.push_back(CaseParameter("matrix", "%fmat33"));
3436 cases.push_back(CaseParameter("array", "%uarr100"));
3437 cases.push_back(CaseParameter("struct", "%struct"));
3438 cases.push_back(CaseParameter("pointer", "%pointer"));
3440 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
3442 for (size_t ndx = 0; ndx < numElements; ++ndx)
3443 negativeFloats[ndx] = -positiveFloats[ndx];
3445 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
3447 map<string, string> specializations;
3448 ComputeShaderSpec spec;
3450 specializations["TYPE"] = cases[caseNdx].param;
3451 spec.assembly = shaderTemplate.specialize(specializations);
3452 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
3453 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
3454 spec.numWorkGroups = IVec3(numElements, 1, 1);
3456 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
3459 return group.release();
3462 // Checks that a compute shader can generate a constant composite value of various types, without exercising a computation on it.
3463 tcu::TestCaseGroup* createOpConstantCompositeGroup (tcu::TestContext& testCtx)
3465 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opconstantcomposite", "Tests the OpConstantComposite instruction"));
3466 vector<CaseParameter> cases;
3467 de::Random rnd (deStringHash(group->getName()));
3468 const int numElements = 100;
3469 vector<float> positiveFloats (numElements, 0);
3470 vector<float> negativeFloats (numElements, 0);
3471 const StringTemplate shaderTemplate (
3472 string(getComputeAsmShaderPreamble()) +
3474 "OpSource GLSL 430\n"
3475 "OpName %main \"main\"\n"
3476 "OpName %id \"gl_GlobalInvocationID\"\n"
3478 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3480 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
3482 "%id = OpVariable %uvec3ptr Input\n"
3483 "%zero = OpConstant %i32 0\n"
3487 "%main = OpFunction %void None %voidf\n"
3488 "%label = OpLabel\n"
3489 "%idval = OpLoad %uvec3 %id\n"
3490 "%x = OpCompositeExtract %u32 %idval 0\n"
3491 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3492 "%inval = OpLoad %f32 %inloc\n"
3493 "%neg = OpFNegate %f32 %inval\n"
3494 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3495 " OpStore %outloc %neg\n"
3497 " OpFunctionEnd\n");
3499 cases.push_back(CaseParameter("vector", "%five = OpConstant %u32 5\n"
3500 "%const = OpConstantComposite %uvec3 %five %zero %five"));
3501 cases.push_back(CaseParameter("matrix", "%m3fvec3 = OpTypeMatrix %fvec3 3\n"
3502 "%ten = OpConstant %f32 10.\n"
3503 "%fzero = OpConstant %f32 0.\n"
3504 "%vec = OpConstantComposite %fvec3 %ten %fzero %ten\n"
3505 "%mat = OpConstantComposite %m3fvec3 %vec %vec %vec"));
3506 cases.push_back(CaseParameter("struct", "%m2vec3 = OpTypeMatrix %fvec3 2\n"
3507 "%struct = OpTypeStruct %i32 %f32 %fvec3 %m2vec3\n"
3508 "%fzero = OpConstant %f32 0.\n"
3509 "%one = OpConstant %f32 1.\n"
3510 "%point5 = OpConstant %f32 0.5\n"
3511 "%vec = OpConstantComposite %fvec3 %one %one %fzero\n"
3512 "%mat = OpConstantComposite %m2vec3 %vec %vec\n"
3513 "%const = OpConstantComposite %struct %zero %point5 %vec %mat"));
3514 cases.push_back(CaseParameter("nested_struct", "%st1 = OpTypeStruct %u32 %f32\n"
3515 "%st2 = OpTypeStruct %i32 %i32\n"
3516 "%struct = OpTypeStruct %st1 %st2\n"
3517 "%point5 = OpConstant %f32 0.5\n"
3518 "%one = OpConstant %u32 1\n"
3519 "%ten = OpConstant %i32 10\n"
3520 "%st1val = OpConstantComposite %st1 %one %point5\n"
3521 "%st2val = OpConstantComposite %st2 %ten %ten\n"
3522 "%const = OpConstantComposite %struct %st1val %st2val"));
3524 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
3526 for (size_t ndx = 0; ndx < numElements; ++ndx)
3527 negativeFloats[ndx] = -positiveFloats[ndx];
3529 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
3531 map<string, string> specializations;
3532 ComputeShaderSpec spec;
3534 specializations["CONSTANT"] = cases[caseNdx].param;
3535 spec.assembly = shaderTemplate.specialize(specializations);
3536 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
3537 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
3538 spec.numWorkGroups = IVec3(numElements, 1, 1);
3540 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
3543 return group.release();
3546 // Creates a floating point number with the given exponent, and significand
3547 // bits set. It can only create normalized numbers. Only the least significant
3548 // 24 bits of the significand will be examined. The final bit of the
3549 // significand will also be ignored. This allows alignment to be written
3550 // similarly to C99 hex-floats.
3551 // For example if you wanted to write 0x1.7f34p-12 you would call
3552 // constructNormalizedFloat(-12, 0x7f3400)
3553 float constructNormalizedFloat (deInt32 exponent, deUint32 significand)
3557 for (deInt32 idx = 0; idx < 23; ++idx)
3559 f += ((significand & 0x800000) == 0) ? 0.f : std::ldexp(1.0f, -(idx + 1));
3563 return std::ldexp(f, exponent);
3566 // Compare instruction for the OpQuantizeF16 compute exact case.
3567 // Returns true if the output is what is expected from the test case.
3568 bool compareOpQuantizeF16ComputeExactCase (const std::vector<BufferSp>&, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs, TestLog&)
3570 if (outputAllocs.size() != 1)
3573 // Only size is needed because we cannot compare Nans.
3574 size_t byteSize = expectedOutputs[0]->getByteSize();
3576 const float* outputAsFloat = static_cast<const float*>(outputAllocs[0]->getHostPtr());
3578 if (byteSize != 4*sizeof(float)) {
3582 if (*outputAsFloat != constructNormalizedFloat(8, 0x304000) &&
3583 *outputAsFloat != constructNormalizedFloat(8, 0x300000)) {
3588 if (*outputAsFloat != -constructNormalizedFloat(-7, 0x600000) &&
3589 *outputAsFloat != -constructNormalizedFloat(-7, 0x604000)) {
3594 if (*outputAsFloat != constructNormalizedFloat(2, 0x01C000) &&
3595 *outputAsFloat != constructNormalizedFloat(2, 0x020000)) {
3600 if (*outputAsFloat != constructNormalizedFloat(1, 0xFFC000) &&
3601 *outputAsFloat != constructNormalizedFloat(2, 0x000000)) {
3608 // Checks that every output from a test-case is a float NaN.
3609 bool compareNan (const std::vector<BufferSp>&, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs, TestLog&)
3611 if (outputAllocs.size() != 1)
3614 // Only size is needed because we cannot compare Nans.
3615 size_t byteSize = expectedOutputs[0]->getByteSize();
3617 const float* const output_as_float = static_cast<const float* const>(outputAllocs[0]->getHostPtr());
3619 for (size_t idx = 0; idx < byteSize / sizeof(float); ++idx)
3621 if (!deFloatIsNaN(output_as_float[idx]))
3630 // Checks that a compute shader can generate a constant composite value of various types, without exercising a computation on it.
3631 tcu::TestCaseGroup* createOpQuantizeToF16Group (tcu::TestContext& testCtx)
3633 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opquantize", "Tests the OpQuantizeToF16 instruction"));
3635 const std::string shader (
3636 string(getComputeAsmShaderPreamble()) +
3638 "OpSource GLSL 430\n"
3639 "OpName %main \"main\"\n"
3640 "OpName %id \"gl_GlobalInvocationID\"\n"
3642 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3644 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
3646 "%id = OpVariable %uvec3ptr Input\n"
3647 "%zero = OpConstant %i32 0\n"
3649 "%main = OpFunction %void None %voidf\n"
3650 "%label = OpLabel\n"
3651 "%idval = OpLoad %uvec3 %id\n"
3652 "%x = OpCompositeExtract %u32 %idval 0\n"
3653 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3654 "%inval = OpLoad %f32 %inloc\n"
3655 "%quant = OpQuantizeToF16 %f32 %inval\n"
3656 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3657 " OpStore %outloc %quant\n"
3659 " OpFunctionEnd\n");
3662 ComputeShaderSpec spec;
3663 const deUint32 numElements = 100;
3664 vector<float> infinities;
3665 vector<float> results;
3667 infinities.reserve(numElements);
3668 results.reserve(numElements);
3670 for (size_t idx = 0; idx < numElements; ++idx)
3675 infinities.push_back(std::numeric_limits<float>::infinity());
3676 results.push_back(std::numeric_limits<float>::infinity());
3679 infinities.push_back(-std::numeric_limits<float>::infinity());
3680 results.push_back(-std::numeric_limits<float>::infinity());
3683 infinities.push_back(std::ldexp(1.0f, 16));
3684 results.push_back(std::numeric_limits<float>::infinity());
3687 infinities.push_back(std::ldexp(-1.0f, 32));
3688 results.push_back(-std::numeric_limits<float>::infinity());
3693 spec.assembly = shader;
3694 spec.inputs.push_back(BufferSp(new Float32Buffer(infinities)));
3695 spec.outputs.push_back(BufferSp(new Float32Buffer(results)));
3696 spec.numWorkGroups = IVec3(numElements, 1, 1);
3698 group->addChild(new SpvAsmComputeShaderCase(
3699 testCtx, "infinities", "Check that infinities propagated and created", spec));
3703 ComputeShaderSpec spec;
3705 const deUint32 numElements = 100;
3707 nans.reserve(numElements);
3709 for (size_t idx = 0; idx < numElements; ++idx)
3713 nans.push_back(std::numeric_limits<float>::quiet_NaN());
3717 nans.push_back(-std::numeric_limits<float>::quiet_NaN());
3721 spec.assembly = shader;
3722 spec.inputs.push_back(BufferSp(new Float32Buffer(nans)));
3723 spec.outputs.push_back(BufferSp(new Float32Buffer(nans)));
3724 spec.numWorkGroups = IVec3(numElements, 1, 1);
3725 spec.verifyIO = &compareNan;
3727 group->addChild(new SpvAsmComputeShaderCase(
3728 testCtx, "propagated_nans", "Check that nans are propagated", spec));
3732 ComputeShaderSpec spec;
3733 vector<float> small;
3734 vector<float> zeros;
3735 const deUint32 numElements = 100;
3737 small.reserve(numElements);
3738 zeros.reserve(numElements);
3740 for (size_t idx = 0; idx < numElements; ++idx)
3745 small.push_back(0.f);
3746 zeros.push_back(0.f);
3749 small.push_back(-0.f);
3750 zeros.push_back(-0.f);
3753 small.push_back(std::ldexp(1.0f, -16));
3754 zeros.push_back(0.f);
3757 small.push_back(std::ldexp(-1.0f, -32));
3758 zeros.push_back(-0.f);
3761 small.push_back(std::ldexp(1.0f, -127));
3762 zeros.push_back(0.f);
3765 small.push_back(-std::ldexp(1.0f, -128));
3766 zeros.push_back(-0.f);
3771 spec.assembly = shader;
3772 spec.inputs.push_back(BufferSp(new Float32Buffer(small)));
3773 spec.outputs.push_back(BufferSp(new Float32Buffer(zeros)));
3774 spec.numWorkGroups = IVec3(numElements, 1, 1);
3776 group->addChild(new SpvAsmComputeShaderCase(
3777 testCtx, "flush_to_zero", "Check that values are zeroed correctly", spec));
3781 ComputeShaderSpec spec;
3782 vector<float> exact;
3783 const deUint32 numElements = 200;
3785 exact.reserve(numElements);
3787 for (size_t idx = 0; idx < numElements; ++idx)
3788 exact.push_back(static_cast<float>(static_cast<int>(idx) - 100));
3790 spec.assembly = shader;
3791 spec.inputs.push_back(BufferSp(new Float32Buffer(exact)));
3792 spec.outputs.push_back(BufferSp(new Float32Buffer(exact)));
3793 spec.numWorkGroups = IVec3(numElements, 1, 1);
3795 group->addChild(new SpvAsmComputeShaderCase(
3796 testCtx, "exact", "Check that values exactly preserved where appropriate", spec));
3800 ComputeShaderSpec spec;
3801 vector<float> inputs;
3802 const deUint32 numElements = 4;
3804 inputs.push_back(constructNormalizedFloat(8, 0x300300));
3805 inputs.push_back(-constructNormalizedFloat(-7, 0x600800));
3806 inputs.push_back(constructNormalizedFloat(2, 0x01E000));
3807 inputs.push_back(constructNormalizedFloat(1, 0xFFE000));
3809 spec.assembly = shader;
3810 spec.verifyIO = &compareOpQuantizeF16ComputeExactCase;
3811 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs)));
3812 spec.outputs.push_back(BufferSp(new Float32Buffer(inputs)));
3813 spec.numWorkGroups = IVec3(numElements, 1, 1);
3815 group->addChild(new SpvAsmComputeShaderCase(
3816 testCtx, "rounded", "Check that are rounded when needed", spec));
3819 return group.release();
3822 tcu::TestCaseGroup* createSpecConstantOpQuantizeToF16Group (tcu::TestContext& testCtx)
3824 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opspecconstantop_opquantize", "Tests the OpQuantizeToF16 opcode for the OpSpecConstantOp instruction"));
3826 const std::string shader (
3827 string(getComputeAsmShaderPreamble()) +
3829 "OpName %main \"main\"\n"
3830 "OpName %id \"gl_GlobalInvocationID\"\n"
3832 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3834 "OpDecorate %sc_0 SpecId 0\n"
3835 "OpDecorate %sc_1 SpecId 1\n"
3836 "OpDecorate %sc_2 SpecId 2\n"
3837 "OpDecorate %sc_3 SpecId 3\n"
3838 "OpDecorate %sc_4 SpecId 4\n"
3839 "OpDecorate %sc_5 SpecId 5\n"
3841 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
3843 "%id = OpVariable %uvec3ptr Input\n"
3844 "%zero = OpConstant %i32 0\n"
3845 "%c_u32_6 = OpConstant %u32 6\n"
3847 "%sc_0 = OpSpecConstant %f32 0.\n"
3848 "%sc_1 = OpSpecConstant %f32 0.\n"
3849 "%sc_2 = OpSpecConstant %f32 0.\n"
3850 "%sc_3 = OpSpecConstant %f32 0.\n"
3851 "%sc_4 = OpSpecConstant %f32 0.\n"
3852 "%sc_5 = OpSpecConstant %f32 0.\n"
3854 "%sc_0_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_0\n"
3855 "%sc_1_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_1\n"
3856 "%sc_2_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_2\n"
3857 "%sc_3_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_3\n"
3858 "%sc_4_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_4\n"
3859 "%sc_5_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_5\n"
3861 "%main = OpFunction %void None %voidf\n"
3862 "%label = OpLabel\n"
3863 "%idval = OpLoad %uvec3 %id\n"
3864 "%x = OpCompositeExtract %u32 %idval 0\n"
3865 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3866 "%selector = OpUMod %u32 %x %c_u32_6\n"
3867 " OpSelectionMerge %exit None\n"
3868 " OpSwitch %selector %exit 0 %case0 1 %case1 2 %case2 3 %case3 4 %case4 5 %case5\n"
3870 "%case0 = OpLabel\n"
3871 " OpStore %outloc %sc_0_quant\n"
3874 "%case1 = OpLabel\n"
3875 " OpStore %outloc %sc_1_quant\n"
3878 "%case2 = OpLabel\n"
3879 " OpStore %outloc %sc_2_quant\n"
3882 "%case3 = OpLabel\n"
3883 " OpStore %outloc %sc_3_quant\n"
3886 "%case4 = OpLabel\n"
3887 " OpStore %outloc %sc_4_quant\n"
3890 "%case5 = OpLabel\n"
3891 " OpStore %outloc %sc_5_quant\n"
3897 " OpFunctionEnd\n");
3900 ComputeShaderSpec spec;
3901 const deUint8 numCases = 4;
3902 vector<float> inputs (numCases, 0.f);
3903 vector<float> outputs;
3905 spec.assembly = shader;
3906 spec.numWorkGroups = IVec3(numCases, 1, 1);
3908 spec.specConstants.push_back(bitwiseCast<deUint32>(std::numeric_limits<float>::infinity()));
3909 spec.specConstants.push_back(bitwiseCast<deUint32>(-std::numeric_limits<float>::infinity()));
3910 spec.specConstants.push_back(bitwiseCast<deUint32>(std::ldexp(1.0f, 16)));
3911 spec.specConstants.push_back(bitwiseCast<deUint32>(std::ldexp(-1.0f, 32)));
3913 outputs.push_back(std::numeric_limits<float>::infinity());
3914 outputs.push_back(-std::numeric_limits<float>::infinity());
3915 outputs.push_back(std::numeric_limits<float>::infinity());
3916 outputs.push_back(-std::numeric_limits<float>::infinity());
3918 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs)));
3919 spec.outputs.push_back(BufferSp(new Float32Buffer(outputs)));
3921 group->addChild(new SpvAsmComputeShaderCase(
3922 testCtx, "infinities", "Check that infinities propagated and created", spec));
3926 ComputeShaderSpec spec;
3927 const deUint8 numCases = 2;
3928 vector<float> inputs (numCases, 0.f);
3929 vector<float> outputs;
3931 spec.assembly = shader;
3932 spec.numWorkGroups = IVec3(numCases, 1, 1);
3933 spec.verifyIO = &compareNan;
3935 outputs.push_back(std::numeric_limits<float>::quiet_NaN());
3936 outputs.push_back(-std::numeric_limits<float>::quiet_NaN());
3938 for (deUint8 idx = 0; idx < numCases; ++idx)
3939 spec.specConstants.push_back(bitwiseCast<deUint32>(outputs[idx]));
3941 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs)));
3942 spec.outputs.push_back(BufferSp(new Float32Buffer(outputs)));
3944 group->addChild(new SpvAsmComputeShaderCase(
3945 testCtx, "propagated_nans", "Check that nans are propagated", spec));
3949 ComputeShaderSpec spec;
3950 const deUint8 numCases = 6;
3951 vector<float> inputs (numCases, 0.f);
3952 vector<float> outputs;
3954 spec.assembly = shader;
3955 spec.numWorkGroups = IVec3(numCases, 1, 1);
3957 spec.specConstants.push_back(bitwiseCast<deUint32>(0.f));
3958 spec.specConstants.push_back(bitwiseCast<deUint32>(-0.f));
3959 spec.specConstants.push_back(bitwiseCast<deUint32>(std::ldexp(1.0f, -16)));
3960 spec.specConstants.push_back(bitwiseCast<deUint32>(std::ldexp(-1.0f, -32)));
3961 spec.specConstants.push_back(bitwiseCast<deUint32>(std::ldexp(1.0f, -127)));
3962 spec.specConstants.push_back(bitwiseCast<deUint32>(-std::ldexp(1.0f, -128)));
3964 outputs.push_back(0.f);
3965 outputs.push_back(-0.f);
3966 outputs.push_back(0.f);
3967 outputs.push_back(-0.f);
3968 outputs.push_back(0.f);
3969 outputs.push_back(-0.f);
3971 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs)));
3972 spec.outputs.push_back(BufferSp(new Float32Buffer(outputs)));
3974 group->addChild(new SpvAsmComputeShaderCase(
3975 testCtx, "flush_to_zero", "Check that values are zeroed correctly", spec));
3979 ComputeShaderSpec spec;
3980 const deUint8 numCases = 6;
3981 vector<float> inputs (numCases, 0.f);
3982 vector<float> outputs;
3984 spec.assembly = shader;
3985 spec.numWorkGroups = IVec3(numCases, 1, 1);
3987 for (deUint8 idx = 0; idx < 6; ++idx)
3989 const float f = static_cast<float>(idx * 10 - 30) / 4.f;
3990 spec.specConstants.push_back(bitwiseCast<deUint32>(f));
3991 outputs.push_back(f);
3994 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs)));
3995 spec.outputs.push_back(BufferSp(new Float32Buffer(outputs)));
3997 group->addChild(new SpvAsmComputeShaderCase(
3998 testCtx, "exact", "Check that values exactly preserved where appropriate", spec));
4002 ComputeShaderSpec spec;
4003 const deUint8 numCases = 4;
4004 vector<float> inputs (numCases, 0.f);
4005 vector<float> outputs;
4007 spec.assembly = shader;
4008 spec.numWorkGroups = IVec3(numCases, 1, 1);
4009 spec.verifyIO = &compareOpQuantizeF16ComputeExactCase;
4011 outputs.push_back(constructNormalizedFloat(8, 0x300300));
4012 outputs.push_back(-constructNormalizedFloat(-7, 0x600800));
4013 outputs.push_back(constructNormalizedFloat(2, 0x01E000));
4014 outputs.push_back(constructNormalizedFloat(1, 0xFFE000));
4016 for (deUint8 idx = 0; idx < numCases; ++idx)
4017 spec.specConstants.push_back(bitwiseCast<deUint32>(outputs[idx]));
4019 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs)));
4020 spec.outputs.push_back(BufferSp(new Float32Buffer(outputs)));
4022 group->addChild(new SpvAsmComputeShaderCase(
4023 testCtx, "rounded", "Check that are rounded when needed", spec));
4026 return group.release();
4029 // Checks that constant null/composite values can be used in computation.
4030 tcu::TestCaseGroup* createOpConstantUsageGroup (tcu::TestContext& testCtx)
4032 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opconstantnullcomposite", "Spotcheck the OpConstantNull & OpConstantComposite instruction"));
4033 ComputeShaderSpec spec;
4034 de::Random rnd (deStringHash(group->getName()));
4035 const int numElements = 100;
4036 vector<float> positiveFloats (numElements, 0);
4037 vector<float> negativeFloats (numElements, 0);
4039 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
4041 for (size_t ndx = 0; ndx < numElements; ++ndx)
4042 negativeFloats[ndx] = -positiveFloats[ndx];
4045 "OpCapability Shader\n"
4046 "%std450 = OpExtInstImport \"GLSL.std.450\"\n"
4047 "OpMemoryModel Logical GLSL450\n"
4048 "OpEntryPoint GLCompute %main \"main\" %id\n"
4049 "OpExecutionMode %main LocalSize 1 1 1\n"
4051 "OpSource GLSL 430\n"
4052 "OpName %main \"main\"\n"
4053 "OpName %id \"gl_GlobalInvocationID\"\n"
4055 "OpDecorate %id BuiltIn GlobalInvocationId\n"
4057 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
4059 "%fmat = OpTypeMatrix %fvec3 3\n"
4060 "%ten = OpConstant %u32 10\n"
4061 "%f32arr10 = OpTypeArray %f32 %ten\n"
4062 "%fst = OpTypeStruct %f32 %f32\n"
4064 + string(getComputeAsmInputOutputBuffer()) +
4066 "%id = OpVariable %uvec3ptr Input\n"
4067 "%zero = OpConstant %i32 0\n"
4069 // Create a bunch of null values
4070 "%unull = OpConstantNull %u32\n"
4071 "%fnull = OpConstantNull %f32\n"
4072 "%vnull = OpConstantNull %fvec3\n"
4073 "%mnull = OpConstantNull %fmat\n"
4074 "%anull = OpConstantNull %f32arr10\n"
4075 "%snull = OpConstantComposite %fst %fnull %fnull\n"
4077 "%main = OpFunction %void None %voidf\n"
4078 "%label = OpLabel\n"
4079 "%idval = OpLoad %uvec3 %id\n"
4080 "%x = OpCompositeExtract %u32 %idval 0\n"
4081 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
4082 "%inval = OpLoad %f32 %inloc\n"
4083 "%neg = OpFNegate %f32 %inval\n"
4085 // Get the abs() of (a certain element of) those null values
4086 "%unull_cov = OpConvertUToF %f32 %unull\n"
4087 "%unull_abs = OpExtInst %f32 %std450 FAbs %unull_cov\n"
4088 "%fnull_abs = OpExtInst %f32 %std450 FAbs %fnull\n"
4089 "%vnull_0 = OpCompositeExtract %f32 %vnull 0\n"
4090 "%vnull_abs = OpExtInst %f32 %std450 FAbs %vnull_0\n"
4091 "%mnull_12 = OpCompositeExtract %f32 %mnull 1 2\n"
4092 "%mnull_abs = OpExtInst %f32 %std450 FAbs %mnull_12\n"
4093 "%anull_3 = OpCompositeExtract %f32 %anull 3\n"
4094 "%anull_abs = OpExtInst %f32 %std450 FAbs %anull_3\n"
4095 "%snull_1 = OpCompositeExtract %f32 %snull 1\n"
4096 "%snull_abs = OpExtInst %f32 %std450 FAbs %snull_1\n"
4099 "%add1 = OpFAdd %f32 %neg %unull_abs\n"
4100 "%add2 = OpFAdd %f32 %add1 %fnull_abs\n"
4101 "%add3 = OpFAdd %f32 %add2 %vnull_abs\n"
4102 "%add4 = OpFAdd %f32 %add3 %mnull_abs\n"
4103 "%add5 = OpFAdd %f32 %add4 %anull_abs\n"
4104 "%final = OpFAdd %f32 %add5 %snull_abs\n"
4106 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
4107 " OpStore %outloc %final\n" // write to output
4110 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
4111 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
4112 spec.numWorkGroups = IVec3(numElements, 1, 1);
4114 group->addChild(new SpvAsmComputeShaderCase(testCtx, "spotcheck", "Check that values constructed via OpConstantNull & OpConstantComposite can be used", spec));
4116 return group.release();
4119 // Assembly code used for testing loop control is based on GLSL source code:
4122 // layout(std140, set = 0, binding = 0) readonly buffer Input {
4123 // float elements[];
4125 // layout(std140, set = 0, binding = 1) writeonly buffer Output {
4126 // float elements[];
4130 // uint x = gl_GlobalInvocationID.x;
4131 // output_data.elements[x] = input_data.elements[x];
4132 // for (uint i = 0; i < 4; ++i)
4133 // output_data.elements[x] += 1.f;
4135 tcu::TestCaseGroup* createLoopControlGroup (tcu::TestContext& testCtx)
4137 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "loop_control", "Tests loop control cases"));
4138 vector<CaseParameter> cases;
4139 de::Random rnd (deStringHash(group->getName()));
4140 const int numElements = 100;
4141 vector<float> inputFloats (numElements, 0);
4142 vector<float> outputFloats (numElements, 0);
4143 const StringTemplate shaderTemplate (
4144 string(getComputeAsmShaderPreamble()) +
4146 "OpSource GLSL 430\n"
4147 "OpName %main \"main\"\n"
4148 "OpName %id \"gl_GlobalInvocationID\"\n"
4150 "OpDecorate %id BuiltIn GlobalInvocationId\n"
4152 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
4154 "%u32ptr = OpTypePointer Function %u32\n"
4156 "%id = OpVariable %uvec3ptr Input\n"
4157 "%zero = OpConstant %i32 0\n"
4158 "%uzero = OpConstant %u32 0\n"
4159 "%one = OpConstant %i32 1\n"
4160 "%constf1 = OpConstant %f32 1.0\n"
4161 "%four = OpConstant %u32 4\n"
4163 "%main = OpFunction %void None %voidf\n"
4164 "%entry = OpLabel\n"
4165 "%i = OpVariable %u32ptr Function\n"
4166 " OpStore %i %uzero\n"
4168 "%idval = OpLoad %uvec3 %id\n"
4169 "%x = OpCompositeExtract %u32 %idval 0\n"
4170 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
4171 "%inval = OpLoad %f32 %inloc\n"
4172 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
4173 " OpStore %outloc %inval\n"
4174 " OpBranch %loop_entry\n"
4176 "%loop_entry = OpLabel\n"
4177 "%i_val = OpLoad %u32 %i\n"
4178 "%cmp_lt = OpULessThan %bool %i_val %four\n"
4179 " OpLoopMerge %loop_merge %loop_body ${CONTROL}\n"
4180 " OpBranchConditional %cmp_lt %loop_body %loop_merge\n"
4181 "%loop_body = OpLabel\n"
4182 "%outval = OpLoad %f32 %outloc\n"
4183 "%addf1 = OpFAdd %f32 %outval %constf1\n"
4184 " OpStore %outloc %addf1\n"
4185 "%new_i = OpIAdd %u32 %i_val %one\n"
4186 " OpStore %i %new_i\n"
4187 " OpBranch %loop_entry\n"
4188 "%loop_merge = OpLabel\n"
4190 " OpFunctionEnd\n");
4192 cases.push_back(CaseParameter("none", "None"));
4193 cases.push_back(CaseParameter("unroll", "Unroll"));
4194 cases.push_back(CaseParameter("dont_unroll", "DontUnroll"));
4195 cases.push_back(CaseParameter("unroll_dont_unroll", "Unroll|DontUnroll"));
4197 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats[0], numElements);
4199 for (size_t ndx = 0; ndx < numElements; ++ndx)
4200 outputFloats[ndx] = inputFloats[ndx] + 4.f;
4202 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
4204 map<string, string> specializations;
4205 ComputeShaderSpec spec;
4207 specializations["CONTROL"] = cases[caseNdx].param;
4208 spec.assembly = shaderTemplate.specialize(specializations);
4209 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
4210 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
4211 spec.numWorkGroups = IVec3(numElements, 1, 1);
4213 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
4216 group->addChild(new SpvAsmLoopControlDependencyLengthCase(testCtx, "dependency_length", "dependency_length"));
4217 group->addChild(new SpvAsmLoopControlDependencyInfiniteCase(testCtx, "dependency_infinite", "dependency_infinite"));
4219 return group.release();
4222 // Assembly code used for testing selection control is based on GLSL source code:
4225 // layout(std140, set = 0, binding = 0) readonly buffer Input {
4226 // float elements[];
4228 // layout(std140, set = 0, binding = 1) writeonly buffer Output {
4229 // float elements[];
4233 // uint x = gl_GlobalInvocationID.x;
4234 // float val = input_data.elements[x];
4236 // output_data.elements[x] = val + 1.f;
4238 // output_data.elements[x] = val - 1.f;
4240 tcu::TestCaseGroup* createSelectionControlGroup (tcu::TestContext& testCtx)
4242 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "selection_control", "Tests selection control cases"));
4243 vector<CaseParameter> cases;
4244 de::Random rnd (deStringHash(group->getName()));
4245 const int numElements = 100;
4246 vector<float> inputFloats (numElements, 0);
4247 vector<float> outputFloats (numElements, 0);
4248 const StringTemplate shaderTemplate (
4249 string(getComputeAsmShaderPreamble()) +
4251 "OpSource GLSL 430\n"
4252 "OpName %main \"main\"\n"
4253 "OpName %id \"gl_GlobalInvocationID\"\n"
4255 "OpDecorate %id BuiltIn GlobalInvocationId\n"
4257 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
4259 "%id = OpVariable %uvec3ptr Input\n"
4260 "%zero = OpConstant %i32 0\n"
4261 "%constf1 = OpConstant %f32 1.0\n"
4262 "%constf10 = OpConstant %f32 10.0\n"
4264 "%main = OpFunction %void None %voidf\n"
4265 "%entry = OpLabel\n"
4266 "%idval = OpLoad %uvec3 %id\n"
4267 "%x = OpCompositeExtract %u32 %idval 0\n"
4268 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
4269 "%inval = OpLoad %f32 %inloc\n"
4270 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
4271 "%cmp_gt = OpFOrdGreaterThan %bool %inval %constf10\n"
4273 " OpSelectionMerge %if_end ${CONTROL}\n"
4274 " OpBranchConditional %cmp_gt %if_true %if_false\n"
4275 "%if_true = OpLabel\n"
4276 "%addf1 = OpFAdd %f32 %inval %constf1\n"
4277 " OpStore %outloc %addf1\n"
4278 " OpBranch %if_end\n"
4279 "%if_false = OpLabel\n"
4280 "%subf1 = OpFSub %f32 %inval %constf1\n"
4281 " OpStore %outloc %subf1\n"
4282 " OpBranch %if_end\n"
4283 "%if_end = OpLabel\n"
4285 " OpFunctionEnd\n");
4287 cases.push_back(CaseParameter("none", "None"));
4288 cases.push_back(CaseParameter("flatten", "Flatten"));
4289 cases.push_back(CaseParameter("dont_flatten", "DontFlatten"));
4290 cases.push_back(CaseParameter("flatten_dont_flatten", "DontFlatten|Flatten"));
4292 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats[0], numElements);
4294 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
4295 floorAll(inputFloats);
4297 for (size_t ndx = 0; ndx < numElements; ++ndx)
4298 outputFloats[ndx] = inputFloats[ndx] + (inputFloats[ndx] > 10.f ? 1.f : -1.f);
4300 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
4302 map<string, string> specializations;
4303 ComputeShaderSpec spec;
4305 specializations["CONTROL"] = cases[caseNdx].param;
4306 spec.assembly = shaderTemplate.specialize(specializations);
4307 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
4308 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
4309 spec.numWorkGroups = IVec3(numElements, 1, 1);
4311 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
4314 return group.release();
4317 // Assembly code used for testing function control is based on GLSL source code:
4321 // layout(std140, set = 0, binding = 0) readonly buffer Input {
4322 // float elements[];
4324 // layout(std140, set = 0, binding = 1) writeonly buffer Output {
4325 // float elements[];
4328 // float const10() { return 10.f; }
4331 // uint x = gl_GlobalInvocationID.x;
4332 // output_data.elements[x] = input_data.elements[x] + const10();
4334 tcu::TestCaseGroup* createFunctionControlGroup (tcu::TestContext& testCtx)
4336 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "function_control", "Tests function control cases"));
4337 vector<CaseParameter> cases;
4338 de::Random rnd (deStringHash(group->getName()));
4339 const int numElements = 100;
4340 vector<float> inputFloats (numElements, 0);
4341 vector<float> outputFloats (numElements, 0);
4342 const StringTemplate shaderTemplate (
4343 string(getComputeAsmShaderPreamble()) +
4345 "OpSource GLSL 430\n"
4346 "OpName %main \"main\"\n"
4347 "OpName %func_const10 \"const10(\"\n"
4348 "OpName %id \"gl_GlobalInvocationID\"\n"
4350 "OpDecorate %id BuiltIn GlobalInvocationId\n"
4352 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
4354 "%f32f = OpTypeFunction %f32\n"
4355 "%id = OpVariable %uvec3ptr Input\n"
4356 "%zero = OpConstant %i32 0\n"
4357 "%constf10 = OpConstant %f32 10.0\n"
4359 "%main = OpFunction %void None %voidf\n"
4360 "%entry = OpLabel\n"
4361 "%idval = OpLoad %uvec3 %id\n"
4362 "%x = OpCompositeExtract %u32 %idval 0\n"
4363 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
4364 "%inval = OpLoad %f32 %inloc\n"
4365 "%ret_10 = OpFunctionCall %f32 %func_const10\n"
4366 "%fadd = OpFAdd %f32 %inval %ret_10\n"
4367 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
4368 " OpStore %outloc %fadd\n"
4372 "%func_const10 = OpFunction %f32 ${CONTROL} %f32f\n"
4373 "%label = OpLabel\n"
4374 " OpReturnValue %constf10\n"
4375 " OpFunctionEnd\n");
4377 cases.push_back(CaseParameter("none", "None"));
4378 cases.push_back(CaseParameter("inline", "Inline"));
4379 cases.push_back(CaseParameter("dont_inline", "DontInline"));
4380 cases.push_back(CaseParameter("pure", "Pure"));
4381 cases.push_back(CaseParameter("const", "Const"));
4382 cases.push_back(CaseParameter("inline_pure", "Inline|Pure"));
4383 cases.push_back(CaseParameter("const_dont_inline", "Const|DontInline"));
4384 cases.push_back(CaseParameter("inline_dont_inline", "Inline|DontInline"));
4385 cases.push_back(CaseParameter("pure_inline_dont_inline", "Pure|Inline|DontInline"));
4387 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats[0], numElements);
4389 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
4390 floorAll(inputFloats);
4392 for (size_t ndx = 0; ndx < numElements; ++ndx)
4393 outputFloats[ndx] = inputFloats[ndx] + 10.f;
4395 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
4397 map<string, string> specializations;
4398 ComputeShaderSpec spec;
4400 specializations["CONTROL"] = cases[caseNdx].param;
4401 spec.assembly = shaderTemplate.specialize(specializations);
4402 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
4403 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
4404 spec.numWorkGroups = IVec3(numElements, 1, 1);
4406 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
4409 return group.release();
4412 tcu::TestCaseGroup* createMemoryAccessGroup (tcu::TestContext& testCtx)
4414 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "memory_access", "Tests memory access cases"));
4415 vector<CaseParameter> cases;
4416 de::Random rnd (deStringHash(group->getName()));
4417 const int numElements = 100;
4418 vector<float> inputFloats (numElements, 0);
4419 vector<float> outputFloats (numElements, 0);
4420 const StringTemplate shaderTemplate (
4421 string(getComputeAsmShaderPreamble()) +
4423 "OpSource GLSL 430\n"
4424 "OpName %main \"main\"\n"
4425 "OpName %id \"gl_GlobalInvocationID\"\n"
4427 "OpDecorate %id BuiltIn GlobalInvocationId\n"
4429 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
4431 "%f32ptr_f = OpTypePointer Function %f32\n"
4433 "%id = OpVariable %uvec3ptr Input\n"
4434 "%zero = OpConstant %i32 0\n"
4435 "%four = OpConstant %i32 4\n"
4437 "%main = OpFunction %void None %voidf\n"
4438 "%label = OpLabel\n"
4439 "%copy = OpVariable %f32ptr_f Function\n"
4440 "%idval = OpLoad %uvec3 %id ${ACCESS}\n"
4441 "%x = OpCompositeExtract %u32 %idval 0\n"
4442 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
4443 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
4444 " OpCopyMemory %copy %inloc ${ACCESS}\n"
4445 "%val1 = OpLoad %f32 %copy\n"
4446 "%val2 = OpLoad %f32 %inloc\n"
4447 "%add = OpFAdd %f32 %val1 %val2\n"
4448 " OpStore %outloc %add ${ACCESS}\n"
4450 " OpFunctionEnd\n");
4452 cases.push_back(CaseParameter("null", ""));
4453 cases.push_back(CaseParameter("none", "None"));
4454 cases.push_back(CaseParameter("volatile", "Volatile"));
4455 cases.push_back(CaseParameter("aligned", "Aligned 4"));
4456 cases.push_back(CaseParameter("nontemporal", "Nontemporal"));
4457 cases.push_back(CaseParameter("aligned_nontemporal", "Aligned|Nontemporal 4"));
4458 cases.push_back(CaseParameter("aligned_volatile", "Volatile|Aligned 4"));
4460 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats[0], numElements);
4462 for (size_t ndx = 0; ndx < numElements; ++ndx)
4463 outputFloats[ndx] = inputFloats[ndx] + inputFloats[ndx];
4465 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
4467 map<string, string> specializations;
4468 ComputeShaderSpec spec;
4470 specializations["ACCESS"] = cases[caseNdx].param;
4471 spec.assembly = shaderTemplate.specialize(specializations);
4472 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
4473 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
4474 spec.numWorkGroups = IVec3(numElements, 1, 1);
4476 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
4479 return group.release();
4482 // Checks that we can get undefined values for various types, without exercising a computation with it.
4483 tcu::TestCaseGroup* createOpUndefGroup (tcu::TestContext& testCtx)
4485 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opundef", "Tests the OpUndef instruction"));
4486 vector<CaseParameter> cases;
4487 de::Random rnd (deStringHash(group->getName()));
4488 const int numElements = 100;
4489 vector<float> positiveFloats (numElements, 0);
4490 vector<float> negativeFloats (numElements, 0);
4491 const StringTemplate shaderTemplate (
4492 string(getComputeAsmShaderPreamble()) +
4494 "OpSource GLSL 430\n"
4495 "OpName %main \"main\"\n"
4496 "OpName %id \"gl_GlobalInvocationID\"\n"
4498 "OpDecorate %id BuiltIn GlobalInvocationId\n"
4500 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
4501 "%uvec2 = OpTypeVector %u32 2\n"
4502 "%fvec4 = OpTypeVector %f32 4\n"
4503 "%fmat33 = OpTypeMatrix %fvec3 3\n"
4504 "%image = OpTypeImage %f32 2D 0 0 0 1 Unknown\n"
4505 "%sampler = OpTypeSampler\n"
4506 "%simage = OpTypeSampledImage %image\n"
4507 "%const100 = OpConstant %u32 100\n"
4508 "%uarr100 = OpTypeArray %i32 %const100\n"
4509 "%struct = OpTypeStruct %f32 %i32 %u32\n"
4510 "%pointer = OpTypePointer Function %i32\n"
4511 + string(getComputeAsmInputOutputBuffer()) +
4513 "%id = OpVariable %uvec3ptr Input\n"
4514 "%zero = OpConstant %i32 0\n"
4516 "%main = OpFunction %void None %voidf\n"
4517 "%label = OpLabel\n"
4519 "%undef = OpUndef ${TYPE}\n"
4521 "%idval = OpLoad %uvec3 %id\n"
4522 "%x = OpCompositeExtract %u32 %idval 0\n"
4524 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
4525 "%inval = OpLoad %f32 %inloc\n"
4526 "%neg = OpFNegate %f32 %inval\n"
4527 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
4528 " OpStore %outloc %neg\n"
4530 " OpFunctionEnd\n");
4532 cases.push_back(CaseParameter("bool", "%bool"));
4533 cases.push_back(CaseParameter("sint32", "%i32"));
4534 cases.push_back(CaseParameter("uint32", "%u32"));
4535 cases.push_back(CaseParameter("float32", "%f32"));
4536 cases.push_back(CaseParameter("vec4float32", "%fvec4"));
4537 cases.push_back(CaseParameter("vec2uint32", "%uvec2"));
4538 cases.push_back(CaseParameter("matrix", "%fmat33"));
4539 cases.push_back(CaseParameter("image", "%image"));
4540 cases.push_back(CaseParameter("sampler", "%sampler"));
4541 cases.push_back(CaseParameter("sampledimage", "%simage"));
4542 cases.push_back(CaseParameter("array", "%uarr100"));
4543 cases.push_back(CaseParameter("runtimearray", "%f32arr"));
4544 cases.push_back(CaseParameter("struct", "%struct"));
4545 cases.push_back(CaseParameter("pointer", "%pointer"));
4547 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
4549 for (size_t ndx = 0; ndx < numElements; ++ndx)
4550 negativeFloats[ndx] = -positiveFloats[ndx];
4552 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
4554 map<string, string> specializations;
4555 ComputeShaderSpec spec;
4557 specializations["TYPE"] = cases[caseNdx].param;
4558 spec.assembly = shaderTemplate.specialize(specializations);
4559 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
4560 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
4561 spec.numWorkGroups = IVec3(numElements, 1, 1);
4563 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
4566 return group.release();
4570 tcu::TestCaseGroup* createOpSourceTests (tcu::TestContext& testCtx)
4572 struct NameCodePair { string name, code; };
4573 RGBA defaultColors[4];
4574 de::MovePtr<tcu::TestCaseGroup> opSourceTests (new tcu::TestCaseGroup(testCtx, "opsource", "OpSource instruction"));
4575 const std::string opsourceGLSLWithFile = "%opsrcfile = OpString \"foo.vert\"\nOpSource GLSL 450 %opsrcfile ";
4576 map<string, string> fragments = passthruFragments();
4577 const NameCodePair tests[] =
4579 {"unknown", "OpSource Unknown 321"},
4580 {"essl", "OpSource ESSL 310"},
4581 {"glsl", "OpSource GLSL 450"},
4582 {"opencl_cpp", "OpSource OpenCL_CPP 120"},
4583 {"opencl_c", "OpSource OpenCL_C 120"},
4584 {"multiple", "OpSource GLSL 450\nOpSource GLSL 450"},
4585 {"file", opsourceGLSLWithFile},
4586 {"source", opsourceGLSLWithFile + "\"void main(){}\""},
4587 // Longest possible source string: SPIR-V limits instructions to 65535
4588 // words, of which the first 4 are opsourceGLSLWithFile; the rest will
4589 // contain 65530 UTF8 characters (one word each) plus one last word
4590 // containing 3 ASCII characters and \0.
4591 {"longsource", opsourceGLSLWithFile + '"' + makeLongUTF8String(65530) + "ccc" + '"'}
4594 getDefaultColors(defaultColors);
4595 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameCodePair); ++testNdx)
4597 fragments["debug"] = tests[testNdx].code;
4598 createTestsForAllStages(tests[testNdx].name, defaultColors, defaultColors, fragments, opSourceTests.get());
4601 return opSourceTests.release();
4604 tcu::TestCaseGroup* createOpSourceContinuedTests (tcu::TestContext& testCtx)
4606 struct NameCodePair { string name, code; };
4607 RGBA defaultColors[4];
4608 de::MovePtr<tcu::TestCaseGroup> opSourceTests (new tcu::TestCaseGroup(testCtx, "opsourcecontinued", "OpSourceContinued instruction"));
4609 map<string, string> fragments = passthruFragments();
4610 const std::string opsource = "%opsrcfile = OpString \"foo.vert\"\nOpSource GLSL 450 %opsrcfile \"void main(){}\"\n";
4611 const NameCodePair tests[] =
4613 {"empty", opsource + "OpSourceContinued \"\""},
4614 {"short", opsource + "OpSourceContinued \"abcde\""},
4615 {"multiple", opsource + "OpSourceContinued \"abcde\"\nOpSourceContinued \"fghij\""},
4616 // Longest possible source string: SPIR-V limits instructions to 65535
4617 // words, of which the first one is OpSourceContinued/length; the rest
4618 // will contain 65533 UTF8 characters (one word each) plus one last word
4619 // containing 3 ASCII characters and \0.
4620 {"long", opsource + "OpSourceContinued \"" + makeLongUTF8String(65533) + "ccc\""}
4623 getDefaultColors(defaultColors);
4624 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameCodePair); ++testNdx)
4626 fragments["debug"] = tests[testNdx].code;
4627 createTestsForAllStages(tests[testNdx].name, defaultColors, defaultColors, fragments, opSourceTests.get());
4630 return opSourceTests.release();
4632 tcu::TestCaseGroup* createOpNoLineTests(tcu::TestContext& testCtx)
4634 RGBA defaultColors[4];
4635 de::MovePtr<tcu::TestCaseGroup> opLineTests (new tcu::TestCaseGroup(testCtx, "opnoline", "OpNoLine instruction"));
4636 map<string, string> fragments;
4637 getDefaultColors(defaultColors);
4638 fragments["debug"] =
4639 "%name = OpString \"name\"\n";
4641 fragments["pre_main"] =
4644 "OpLine %name 1 1\n"
4646 "OpLine %name 1 1\n"
4647 "OpLine %name 1 1\n"
4648 "%second_function = OpFunction %v4f32 None %v4f32_function\n"
4650 "OpLine %name 1 1\n"
4652 "OpLine %name 1 1\n"
4653 "OpLine %name 1 1\n"
4654 "%second_param1 = OpFunctionParameter %v4f32\n"
4657 "%label_secondfunction = OpLabel\n"
4659 "OpReturnValue %second_param1\n"
4664 fragments["testfun"] =
4665 // A %test_code function that returns its argument unchanged.
4668 "OpLine %name 1 1\n"
4669 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
4671 "%param1 = OpFunctionParameter %v4f32\n"
4674 "%label_testfun = OpLabel\n"
4676 "%val1 = OpFunctionCall %v4f32 %second_function %param1\n"
4677 "OpReturnValue %val1\n"
4679 "OpLine %name 1 1\n"
4682 createTestsForAllStages("opnoline", defaultColors, defaultColors, fragments, opLineTests.get());
4684 return opLineTests.release();
4687 tcu::TestCaseGroup* createOpModuleProcessedTests(tcu::TestContext& testCtx)
4689 RGBA defaultColors[4];
4690 de::MovePtr<tcu::TestCaseGroup> opModuleProcessedTests (new tcu::TestCaseGroup(testCtx, "opmoduleprocessed", "OpModuleProcessed instruction"));
4691 map<string, string> fragments;
4692 std::vector<std::string> noExtensions;
4693 GraphicsResources resources;
4695 getDefaultColors(defaultColors);
4696 resources.verifyBinary = veryfiBinaryShader;
4697 resources.spirvVersion = SPIRV_VERSION_1_3;
4699 fragments["moduleprocessed"] =
4700 "OpModuleProcessed \"VULKAN CTS\"\n"
4701 "OpModuleProcessed \"Negative values\"\n"
4702 "OpModuleProcessed \"Date: 2017/09/21\"\n";
4704 fragments["pre_main"] =
4705 "%second_function = OpFunction %v4f32 None %v4f32_function\n"
4706 "%second_param1 = OpFunctionParameter %v4f32\n"
4707 "%label_secondfunction = OpLabel\n"
4708 "OpReturnValue %second_param1\n"
4711 fragments["testfun"] =
4712 // A %test_code function that returns its argument unchanged.
4713 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
4714 "%param1 = OpFunctionParameter %v4f32\n"
4715 "%label_testfun = OpLabel\n"
4716 "%val1 = OpFunctionCall %v4f32 %second_function %param1\n"
4717 "OpReturnValue %val1\n"
4720 createTestsForAllStages ("opmoduleprocessed", defaultColors, defaultColors, fragments, resources, noExtensions, opModuleProcessedTests.get());
4722 return opModuleProcessedTests.release();
4726 tcu::TestCaseGroup* createOpLineTests(tcu::TestContext& testCtx)
4728 RGBA defaultColors[4];
4729 de::MovePtr<tcu::TestCaseGroup> opLineTests (new tcu::TestCaseGroup(testCtx, "opline", "OpLine instruction"));
4730 map<string, string> fragments;
4731 std::vector<std::pair<std::string, std::string> > problemStrings;
4733 problemStrings.push_back(std::make_pair<std::string, std::string>("empty_name", ""));
4734 problemStrings.push_back(std::make_pair<std::string, std::string>("short_name", "short_name"));
4735 problemStrings.push_back(std::make_pair<std::string, std::string>("long_name", makeLongUTF8String(65530) + "ccc"));
4736 getDefaultColors(defaultColors);
4738 fragments["debug"] =
4739 "%other_name = OpString \"other_name\"\n";
4741 fragments["pre_main"] =
4742 "OpLine %file_name 32 0\n"
4743 "OpLine %file_name 32 32\n"
4744 "OpLine %file_name 32 40\n"
4745 "OpLine %other_name 32 40\n"
4746 "OpLine %other_name 0 100\n"
4747 "OpLine %other_name 0 4294967295\n"
4748 "OpLine %other_name 4294967295 0\n"
4749 "OpLine %other_name 32 40\n"
4750 "OpLine %file_name 0 0\n"
4751 "%second_function = OpFunction %v4f32 None %v4f32_function\n"
4752 "OpLine %file_name 1 0\n"
4753 "%second_param1 = OpFunctionParameter %v4f32\n"
4754 "OpLine %file_name 1 3\n"
4755 "OpLine %file_name 1 2\n"
4756 "%label_secondfunction = OpLabel\n"
4757 "OpLine %file_name 0 2\n"
4758 "OpReturnValue %second_param1\n"
4760 "OpLine %file_name 0 2\n"
4761 "OpLine %file_name 0 2\n";
4763 fragments["testfun"] =
4764 // A %test_code function that returns its argument unchanged.
4765 "OpLine %file_name 1 0\n"
4766 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
4767 "OpLine %file_name 16 330\n"
4768 "%param1 = OpFunctionParameter %v4f32\n"
4769 "OpLine %file_name 14 442\n"
4770 "%label_testfun = OpLabel\n"
4771 "OpLine %file_name 11 1024\n"
4772 "%val1 = OpFunctionCall %v4f32 %second_function %param1\n"
4773 "OpLine %file_name 2 97\n"
4774 "OpReturnValue %val1\n"
4776 "OpLine %file_name 5 32\n";
4778 for (size_t i = 0; i < problemStrings.size(); ++i)
4780 map<string, string> testFragments = fragments;
4781 testFragments["debug"] += "%file_name = OpString \"" + problemStrings[i].second + "\"\n";
4782 createTestsForAllStages(string("opline") + "_" + problemStrings[i].first, defaultColors, defaultColors, testFragments, opLineTests.get());
4785 return opLineTests.release();
4788 tcu::TestCaseGroup* createOpConstantNullTests(tcu::TestContext& testCtx)
4790 de::MovePtr<tcu::TestCaseGroup> opConstantNullTests (new tcu::TestCaseGroup(testCtx, "opconstantnull", "OpConstantNull instruction"));
4794 const char functionStart[] =
4795 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
4796 "%param1 = OpFunctionParameter %v4f32\n"
4799 const char functionEnd[] =
4800 "OpReturnValue %transformed_param\n"
4803 struct NameConstantsCode
4810 NameConstantsCode tests[] =
4814 "%cnull = OpConstantNull %v4f32\n",
4815 "%transformed_param = OpFAdd %v4f32 %param1 %cnull\n"
4819 "%cnull = OpConstantNull %f32\n",
4820 "%vp = OpVariable %fp_v4f32 Function\n"
4821 "%v = OpLoad %v4f32 %vp\n"
4822 "%v0 = OpVectorInsertDynamic %v4f32 %v %cnull %c_i32_0\n"
4823 "%v1 = OpVectorInsertDynamic %v4f32 %v0 %cnull %c_i32_1\n"
4824 "%v2 = OpVectorInsertDynamic %v4f32 %v1 %cnull %c_i32_2\n"
4825 "%v3 = OpVectorInsertDynamic %v4f32 %v2 %cnull %c_i32_3\n"
4826 "%transformed_param = OpFAdd %v4f32 %param1 %v3\n"
4830 "%cnull = OpConstantNull %bool\n",
4831 "%v = OpVariable %fp_v4f32 Function\n"
4832 " OpStore %v %param1\n"
4833 " OpSelectionMerge %false_label None\n"
4834 " OpBranchConditional %cnull %true_label %false_label\n"
4835 "%true_label = OpLabel\n"
4836 " OpStore %v %c_v4f32_0_5_0_5_0_5_0_5\n"
4837 " OpBranch %false_label\n"
4838 "%false_label = OpLabel\n"
4839 "%transformed_param = OpLoad %v4f32 %v\n"
4843 "%cnull = OpConstantNull %i32\n",
4844 "%v = OpVariable %fp_v4f32 Function %c_v4f32_0_5_0_5_0_5_0_5\n"
4845 "%b = OpIEqual %bool %cnull %c_i32_0\n"
4846 " OpSelectionMerge %false_label None\n"
4847 " OpBranchConditional %b %true_label %false_label\n"
4848 "%true_label = OpLabel\n"
4849 " OpStore %v %param1\n"
4850 " OpBranch %false_label\n"
4851 "%false_label = OpLabel\n"
4852 "%transformed_param = OpLoad %v4f32 %v\n"
4856 "%stype = OpTypeStruct %f32 %v4f32\n"
4857 "%fp_stype = OpTypePointer Function %stype\n"
4858 "%cnull = OpConstantNull %stype\n",
4859 "%v = OpVariable %fp_stype Function %cnull\n"
4860 "%f = OpAccessChain %fp_v4f32 %v %c_i32_1\n"
4861 "%f_val = OpLoad %v4f32 %f\n"
4862 "%transformed_param = OpFAdd %v4f32 %param1 %f_val\n"
4866 "%a4_v4f32 = OpTypeArray %v4f32 %c_u32_4\n"
4867 "%fp_a4_v4f32 = OpTypePointer Function %a4_v4f32\n"
4868 "%cnull = OpConstantNull %a4_v4f32\n",
4869 "%v = OpVariable %fp_a4_v4f32 Function %cnull\n"
4870 "%f = OpAccessChain %fp_v4f32 %v %c_u32_0\n"
4871 "%f1 = OpAccessChain %fp_v4f32 %v %c_u32_1\n"
4872 "%f2 = OpAccessChain %fp_v4f32 %v %c_u32_2\n"
4873 "%f3 = OpAccessChain %fp_v4f32 %v %c_u32_3\n"
4874 "%f_val = OpLoad %v4f32 %f\n"
4875 "%f1_val = OpLoad %v4f32 %f1\n"
4876 "%f2_val = OpLoad %v4f32 %f2\n"
4877 "%f3_val = OpLoad %v4f32 %f3\n"
4878 "%t0 = OpFAdd %v4f32 %param1 %f_val\n"
4879 "%t1 = OpFAdd %v4f32 %t0 %f1_val\n"
4880 "%t2 = OpFAdd %v4f32 %t1 %f2_val\n"
4881 "%transformed_param = OpFAdd %v4f32 %t2 %f3_val\n"
4885 "%mat4x4_f32 = OpTypeMatrix %v4f32 4\n"
4886 "%cnull = OpConstantNull %mat4x4_f32\n",
4887 // Our null matrix * any vector should result in a zero vector.
4888 "%v = OpVectorTimesMatrix %v4f32 %param1 %cnull\n"
4889 "%transformed_param = OpFAdd %v4f32 %param1 %v\n"
4893 getHalfColorsFullAlpha(colors);
4895 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameConstantsCode); ++testNdx)
4897 map<string, string> fragments;
4898 fragments["pre_main"] = tests[testNdx].constants;
4899 fragments["testfun"] = string(functionStart) + tests[testNdx].code + functionEnd;
4900 createTestsForAllStages(tests[testNdx].name, colors, colors, fragments, opConstantNullTests.get());
4902 return opConstantNullTests.release();
4904 tcu::TestCaseGroup* createOpConstantCompositeTests(tcu::TestContext& testCtx)
4906 de::MovePtr<tcu::TestCaseGroup> opConstantCompositeTests (new tcu::TestCaseGroup(testCtx, "opconstantcomposite", "OpConstantComposite instruction"));
4907 RGBA inputColors[4];
4908 RGBA outputColors[4];
4911 const char functionStart[] =
4912 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
4913 "%param1 = OpFunctionParameter %v4f32\n"
4916 const char functionEnd[] =
4917 "OpReturnValue %transformed_param\n"
4920 struct NameConstantsCode
4927 NameConstantsCode tests[] =
4932 "%cval = OpConstantComposite %v4f32 %c_f32_0_5 %c_f32_0_5 %c_f32_0_5 %c_f32_0\n",
4933 "%transformed_param = OpFAdd %v4f32 %param1 %cval\n"
4938 "%stype = OpTypeStruct %v4f32 %f32\n"
4939 "%fp_stype = OpTypePointer Function %stype\n"
4940 "%f32_n_1 = OpConstant %f32 -1.0\n"
4941 "%f32_1_5 = OpConstant %f32 !0x3fc00000\n" // +1.5
4942 "%cvec = OpConstantComposite %v4f32 %f32_1_5 %f32_1_5 %f32_1_5 %c_f32_1\n"
4943 "%cval = OpConstantComposite %stype %cvec %f32_n_1\n",
4945 "%v = OpVariable %fp_stype Function %cval\n"
4946 "%vec_ptr = OpAccessChain %fp_v4f32 %v %c_u32_0\n"
4947 "%f32_ptr = OpAccessChain %fp_f32 %v %c_u32_1\n"
4948 "%vec_val = OpLoad %v4f32 %vec_ptr\n"
4949 "%f32_val = OpLoad %f32 %f32_ptr\n"
4950 "%tmp1 = OpVectorTimesScalar %v4f32 %c_v4f32_1_1_1_1 %f32_val\n" // vec4(-1)
4951 "%tmp2 = OpFAdd %v4f32 %tmp1 %param1\n" // param1 + vec4(-1)
4952 "%transformed_param = OpFAdd %v4f32 %tmp2 %vec_val\n" // param1 + vec4(-1) + vec4(1.5, 1.5, 1.5, 1.0)
4955 // [1|0|0|0.5] [x] = x + 0.5
4956 // [0|1|0|0.5] [y] = y + 0.5
4957 // [0|0|1|0.5] [z] = z + 0.5
4958 // [0|0|0|1 ] [1] = 1
4961 "%mat4x4_f32 = OpTypeMatrix %v4f32 4\n"
4962 "%v4f32_1_0_0_0 = OpConstantComposite %v4f32 %c_f32_1 %c_f32_0 %c_f32_0 %c_f32_0\n"
4963 "%v4f32_0_1_0_0 = OpConstantComposite %v4f32 %c_f32_0 %c_f32_1 %c_f32_0 %c_f32_0\n"
4964 "%v4f32_0_0_1_0 = OpConstantComposite %v4f32 %c_f32_0 %c_f32_0 %c_f32_1 %c_f32_0\n"
4965 "%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"
4966 "%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",
4968 "%transformed_param = OpMatrixTimesVector %v4f32 %cval %param1\n"
4973 "%c_v4f32_1_1_1_0 = OpConstantComposite %v4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_0\n"
4974 "%fp_a4f32 = OpTypePointer Function %a4f32\n"
4975 "%f32_n_1 = OpConstant %f32 -1.0\n"
4976 "%f32_1_5 = OpConstant %f32 !0x3fc00000\n" // +1.5
4977 "%carr = OpConstantComposite %a4f32 %c_f32_0 %f32_n_1 %f32_1_5 %c_f32_0\n",
4979 "%v = OpVariable %fp_a4f32 Function %carr\n"
4980 "%f = OpAccessChain %fp_f32 %v %c_u32_0\n"
4981 "%f1 = OpAccessChain %fp_f32 %v %c_u32_1\n"
4982 "%f2 = OpAccessChain %fp_f32 %v %c_u32_2\n"
4983 "%f3 = OpAccessChain %fp_f32 %v %c_u32_3\n"
4984 "%f_val = OpLoad %f32 %f\n"
4985 "%f1_val = OpLoad %f32 %f1\n"
4986 "%f2_val = OpLoad %f32 %f2\n"
4987 "%f3_val = OpLoad %f32 %f3\n"
4988 "%ftot1 = OpFAdd %f32 %f_val %f1_val\n"
4989 "%ftot2 = OpFAdd %f32 %ftot1 %f2_val\n"
4990 "%ftot3 = OpFAdd %f32 %ftot2 %f3_val\n" // 0 - 1 + 1.5 + 0
4991 "%add_vec = OpVectorTimesScalar %v4f32 %c_v4f32_1_1_1_0 %ftot3\n"
4992 "%transformed_param = OpFAdd %v4f32 %param1 %add_vec\n"
4999 // [ 1.0, 1.0, 1.0, 1.0]
5003 // [ 0.0, 0.5, 0.0, 0.0]
5007 // [ 1.0, 1.0, 1.0, 1.0]
5010 "array_of_struct_of_array",
5012 "%c_v4f32_1_1_1_0 = OpConstantComposite %v4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_0\n"
5013 "%fp_a4f32 = OpTypePointer Function %a4f32\n"
5014 "%stype = OpTypeStruct %f32 %a4f32\n"
5015 "%a3stype = OpTypeArray %stype %c_u32_3\n"
5016 "%fp_a3stype = OpTypePointer Function %a3stype\n"
5017 "%ca4f32_0 = OpConstantComposite %a4f32 %c_f32_0 %c_f32_0_5 %c_f32_0 %c_f32_0\n"
5018 "%ca4f32_1 = OpConstantComposite %a4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_1\n"
5019 "%cstype1 = OpConstantComposite %stype %c_f32_0 %ca4f32_1\n"
5020 "%cstype2 = OpConstantComposite %stype %c_f32_1 %ca4f32_0\n"
5021 "%carr = OpConstantComposite %a3stype %cstype1 %cstype2 %cstype1",
5023 "%v = OpVariable %fp_a3stype Function %carr\n"
5024 "%f = OpAccessChain %fp_f32 %v %c_u32_1 %c_u32_1 %c_u32_1\n"
5025 "%f_l = OpLoad %f32 %f\n"
5026 "%add_vec = OpVectorTimesScalar %v4f32 %c_v4f32_1_1_1_0 %f_l\n"
5027 "%transformed_param = OpFAdd %v4f32 %param1 %add_vec\n"
5031 getHalfColorsFullAlpha(inputColors);
5032 outputColors[0] = RGBA(255, 255, 255, 255);
5033 outputColors[1] = RGBA(255, 127, 127, 255);
5034 outputColors[2] = RGBA(127, 255, 127, 255);
5035 outputColors[3] = RGBA(127, 127, 255, 255);
5037 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameConstantsCode); ++testNdx)
5039 map<string, string> fragments;
5040 fragments["pre_main"] = tests[testNdx].constants;
5041 fragments["testfun"] = string(functionStart) + tests[testNdx].code + functionEnd;
5042 createTestsForAllStages(tests[testNdx].name, inputColors, outputColors, fragments, opConstantCompositeTests.get());
5044 return opConstantCompositeTests.release();
5047 tcu::TestCaseGroup* createSelectionBlockOrderTests(tcu::TestContext& testCtx)
5049 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "selection_block_order", "Out-of-order blocks for selection"));
5050 RGBA inputColors[4];
5051 RGBA outputColors[4];
5052 map<string, string> fragments;
5054 // vec4 test_code(vec4 param) {
5055 // vec4 result = param;
5056 // for (int i = 0; i < 4; ++i) {
5057 // if (i == 0) result[i] = 0.;
5058 // else result[i] = 1. - result[i];
5062 const char function[] =
5063 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5064 "%param1 = OpFunctionParameter %v4f32\n"
5066 "%iptr = OpVariable %fp_i32 Function\n"
5067 "%result = OpVariable %fp_v4f32 Function\n"
5068 " OpStore %iptr %c_i32_0\n"
5069 " OpStore %result %param1\n"
5072 // Loop entry block.
5074 "%ival = OpLoad %i32 %iptr\n"
5075 "%lt_4 = OpSLessThan %bool %ival %c_i32_4\n"
5076 " OpLoopMerge %exit %if_entry None\n"
5077 " OpBranchConditional %lt_4 %if_entry %exit\n"
5079 // Merge block for loop.
5081 "%ret = OpLoad %v4f32 %result\n"
5082 " OpReturnValue %ret\n"
5084 // If-statement entry block.
5085 "%if_entry = OpLabel\n"
5086 "%loc = OpAccessChain %fp_f32 %result %ival\n"
5087 "%eq_0 = OpIEqual %bool %ival %c_i32_0\n"
5088 " OpSelectionMerge %if_exit None\n"
5089 " OpBranchConditional %eq_0 %if_true %if_false\n"
5091 // False branch for if-statement.
5092 "%if_false = OpLabel\n"
5093 "%val = OpLoad %f32 %loc\n"
5094 "%sub = OpFSub %f32 %c_f32_1 %val\n"
5095 " OpStore %loc %sub\n"
5096 " OpBranch %if_exit\n"
5098 // Merge block for if-statement.
5099 "%if_exit = OpLabel\n"
5100 "%ival_next = OpIAdd %i32 %ival %c_i32_1\n"
5101 " OpStore %iptr %ival_next\n"
5104 // True branch for if-statement.
5105 "%if_true = OpLabel\n"
5106 " OpStore %loc %c_f32_0\n"
5107 " OpBranch %if_exit\n"
5111 fragments["testfun"] = function;
5113 inputColors[0] = RGBA(127, 127, 127, 0);
5114 inputColors[1] = RGBA(127, 0, 0, 0);
5115 inputColors[2] = RGBA(0, 127, 0, 0);
5116 inputColors[3] = RGBA(0, 0, 127, 0);
5118 outputColors[0] = RGBA(0, 128, 128, 255);
5119 outputColors[1] = RGBA(0, 255, 255, 255);
5120 outputColors[2] = RGBA(0, 128, 255, 255);
5121 outputColors[3] = RGBA(0, 255, 128, 255);
5123 createTestsForAllStages("out_of_order", inputColors, outputColors, fragments, group.get());
5125 return group.release();
5128 tcu::TestCaseGroup* createSwitchBlockOrderTests(tcu::TestContext& testCtx)
5130 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "switch_block_order", "Out-of-order blocks for switch"));
5131 RGBA inputColors[4];
5132 RGBA outputColors[4];
5133 map<string, string> fragments;
5135 const char typesAndConstants[] =
5136 "%c_f32_p2 = OpConstant %f32 0.2\n"
5137 "%c_f32_p4 = OpConstant %f32 0.4\n"
5138 "%c_f32_p6 = OpConstant %f32 0.6\n"
5139 "%c_f32_p8 = OpConstant %f32 0.8\n";
5141 // vec4 test_code(vec4 param) {
5142 // vec4 result = param;
5143 // for (int i = 0; i < 4; ++i) {
5145 // case 0: result[i] += .2; break;
5146 // case 1: result[i] += .6; break;
5147 // case 2: result[i] += .4; break;
5148 // case 3: result[i] += .8; break;
5149 // default: break; // unreachable
5154 const char function[] =
5155 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5156 "%param1 = OpFunctionParameter %v4f32\n"
5158 "%iptr = OpVariable %fp_i32 Function\n"
5159 "%result = OpVariable %fp_v4f32 Function\n"
5160 " OpStore %iptr %c_i32_0\n"
5161 " OpStore %result %param1\n"
5164 // Loop entry block.
5166 "%ival = OpLoad %i32 %iptr\n"
5167 "%lt_4 = OpSLessThan %bool %ival %c_i32_4\n"
5168 " OpLoopMerge %exit %switch_exit None\n"
5169 " OpBranchConditional %lt_4 %switch_entry %exit\n"
5171 // Merge block for loop.
5173 "%ret = OpLoad %v4f32 %result\n"
5174 " OpReturnValue %ret\n"
5176 // Switch-statement entry block.
5177 "%switch_entry = OpLabel\n"
5178 "%loc = OpAccessChain %fp_f32 %result %ival\n"
5179 "%val = OpLoad %f32 %loc\n"
5180 " OpSelectionMerge %switch_exit None\n"
5181 " OpSwitch %ival %switch_default 0 %case0 1 %case1 2 %case2 3 %case3\n"
5183 "%case2 = OpLabel\n"
5184 "%addp4 = OpFAdd %f32 %val %c_f32_p4\n"
5185 " OpStore %loc %addp4\n"
5186 " OpBranch %switch_exit\n"
5188 "%switch_default = OpLabel\n"
5191 "%case3 = OpLabel\n"
5192 "%addp8 = OpFAdd %f32 %val %c_f32_p8\n"
5193 " OpStore %loc %addp8\n"
5194 " OpBranch %switch_exit\n"
5196 "%case0 = OpLabel\n"
5197 "%addp2 = OpFAdd %f32 %val %c_f32_p2\n"
5198 " OpStore %loc %addp2\n"
5199 " OpBranch %switch_exit\n"
5201 // Merge block for switch-statement.
5202 "%switch_exit = OpLabel\n"
5203 "%ival_next = OpIAdd %i32 %ival %c_i32_1\n"
5204 " OpStore %iptr %ival_next\n"
5207 "%case1 = OpLabel\n"
5208 "%addp6 = OpFAdd %f32 %val %c_f32_p6\n"
5209 " OpStore %loc %addp6\n"
5210 " OpBranch %switch_exit\n"
5214 fragments["pre_main"] = typesAndConstants;
5215 fragments["testfun"] = function;
5217 inputColors[0] = RGBA(127, 27, 127, 51);
5218 inputColors[1] = RGBA(127, 0, 0, 51);
5219 inputColors[2] = RGBA(0, 27, 0, 51);
5220 inputColors[3] = RGBA(0, 0, 127, 51);
5222 outputColors[0] = RGBA(178, 180, 229, 255);
5223 outputColors[1] = RGBA(178, 153, 102, 255);
5224 outputColors[2] = RGBA(51, 180, 102, 255);
5225 outputColors[3] = RGBA(51, 153, 229, 255);
5227 createTestsForAllStages("out_of_order", inputColors, outputColors, fragments, group.get());
5229 return group.release();
5232 tcu::TestCaseGroup* createDecorationGroupTests(tcu::TestContext& testCtx)
5234 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "decoration_group", "Decoration group tests"));
5235 RGBA inputColors[4];
5236 RGBA outputColors[4];
5237 map<string, string> fragments;
5239 const char decorations[] =
5240 "OpDecorate %array_group ArrayStride 4\n"
5241 "OpDecorate %struct_member_group Offset 0\n"
5242 "%array_group = OpDecorationGroup\n"
5243 "%struct_member_group = OpDecorationGroup\n"
5245 "OpDecorate %group1 RelaxedPrecision\n"
5246 "OpDecorate %group3 RelaxedPrecision\n"
5247 "OpDecorate %group3 Invariant\n"
5248 "OpDecorate %group3 Restrict\n"
5249 "%group0 = OpDecorationGroup\n"
5250 "%group1 = OpDecorationGroup\n"
5251 "%group3 = OpDecorationGroup\n";
5253 const char typesAndConstants[] =
5254 "%a3f32 = OpTypeArray %f32 %c_u32_3\n"
5255 "%struct1 = OpTypeStruct %a3f32\n"
5256 "%struct2 = OpTypeStruct %a3f32\n"
5257 "%fp_struct1 = OpTypePointer Function %struct1\n"
5258 "%fp_struct2 = OpTypePointer Function %struct2\n"
5259 "%c_f32_2 = OpConstant %f32 2.\n"
5260 "%c_f32_n2 = OpConstant %f32 -2.\n"
5262 "%c_a3f32_1 = OpConstantComposite %a3f32 %c_f32_1 %c_f32_2 %c_f32_1\n"
5263 "%c_a3f32_2 = OpConstantComposite %a3f32 %c_f32_n1 %c_f32_n2 %c_f32_n1\n"
5264 "%c_struct1 = OpConstantComposite %struct1 %c_a3f32_1\n"
5265 "%c_struct2 = OpConstantComposite %struct2 %c_a3f32_2\n";
5267 const char function[] =
5268 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5269 "%param = OpFunctionParameter %v4f32\n"
5270 "%entry = OpLabel\n"
5271 "%result = OpVariable %fp_v4f32 Function\n"
5272 "%v_struct1 = OpVariable %fp_struct1 Function\n"
5273 "%v_struct2 = OpVariable %fp_struct2 Function\n"
5274 " OpStore %result %param\n"
5275 " OpStore %v_struct1 %c_struct1\n"
5276 " OpStore %v_struct2 %c_struct2\n"
5277 "%ptr1 = OpAccessChain %fp_f32 %v_struct1 %c_i32_0 %c_i32_2\n"
5278 "%val1 = OpLoad %f32 %ptr1\n"
5279 "%ptr2 = OpAccessChain %fp_f32 %v_struct2 %c_i32_0 %c_i32_2\n"
5280 "%val2 = OpLoad %f32 %ptr2\n"
5281 "%addvalues = OpFAdd %f32 %val1 %val2\n"
5282 "%ptr = OpAccessChain %fp_f32 %result %c_i32_1\n"
5283 "%val = OpLoad %f32 %ptr\n"
5284 "%addresult = OpFAdd %f32 %addvalues %val\n"
5285 " OpStore %ptr %addresult\n"
5286 "%ret = OpLoad %v4f32 %result\n"
5287 " OpReturnValue %ret\n"
5290 struct CaseNameDecoration
5296 CaseNameDecoration tests[] =
5299 "same_decoration_group_on_multiple_types",
5300 "OpGroupMemberDecorate %struct_member_group %struct1 0 %struct2 0\n"
5303 "empty_decoration_group",
5304 "OpGroupDecorate %group0 %a3f32\n"
5305 "OpGroupDecorate %group0 %result\n"
5308 "one_element_decoration_group",
5309 "OpGroupDecorate %array_group %a3f32\n"
5312 "multiple_elements_decoration_group",
5313 "OpGroupDecorate %group3 %v_struct1\n"
5316 "multiple_decoration_groups_on_same_variable",
5317 "OpGroupDecorate %group0 %v_struct2\n"
5318 "OpGroupDecorate %group1 %v_struct2\n"
5319 "OpGroupDecorate %group3 %v_struct2\n"
5322 "same_decoration_group_multiple_times",
5323 "OpGroupDecorate %group1 %addvalues\n"
5324 "OpGroupDecorate %group1 %addvalues\n"
5325 "OpGroupDecorate %group1 %addvalues\n"
5330 getHalfColorsFullAlpha(inputColors);
5331 getHalfColorsFullAlpha(outputColors);
5333 for (size_t idx = 0; idx < (sizeof(tests) / sizeof(tests[0])); ++idx)
5335 fragments["decoration"] = decorations + tests[idx].decoration;
5336 fragments["pre_main"] = typesAndConstants;
5337 fragments["testfun"] = function;
5339 createTestsForAllStages(tests[idx].name, inputColors, outputColors, fragments, group.get());
5342 return group.release();
5345 struct SpecConstantTwoIntGraphicsCase
5347 const char* caseName;
5348 const char* scDefinition0;
5349 const char* scDefinition1;
5350 const char* scResultType;
5351 const char* scOperation;
5352 deInt32 scActualValue0;
5353 deInt32 scActualValue1;
5354 const char* resultOperation;
5355 RGBA expectedColors[4];
5357 SpecConstantTwoIntGraphicsCase (const char* name,
5358 const char* definition0,
5359 const char* definition1,
5360 const char* resultType,
5361 const char* operation,
5364 const char* resultOp,
5365 const RGBA (&output)[4])
5367 , scDefinition0 (definition0)
5368 , scDefinition1 (definition1)
5369 , scResultType (resultType)
5370 , scOperation (operation)
5371 , scActualValue0 (value0)
5372 , scActualValue1 (value1)
5373 , resultOperation (resultOp)
5375 expectedColors[0] = output[0];
5376 expectedColors[1] = output[1];
5377 expectedColors[2] = output[2];
5378 expectedColors[3] = output[3];
5382 tcu::TestCaseGroup* createSpecConstantTests (tcu::TestContext& testCtx)
5384 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opspecconstantop", "Test the OpSpecConstantOp instruction"));
5385 vector<SpecConstantTwoIntGraphicsCase> cases;
5386 RGBA inputColors[4];
5387 RGBA outputColors0[4];
5388 RGBA outputColors1[4];
5389 RGBA outputColors2[4];
5391 const char decorations1[] =
5392 "OpDecorate %sc_0 SpecId 0\n"
5393 "OpDecorate %sc_1 SpecId 1\n";
5395 const char typesAndConstants1[] =
5396 "%sc_0 = OpSpecConstant${SC_DEF0}\n"
5397 "%sc_1 = OpSpecConstant${SC_DEF1}\n"
5398 "%sc_op = OpSpecConstantOp ${SC_RESULT_TYPE} ${SC_OP}\n";
5400 const char function1[] =
5401 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5402 "%param = OpFunctionParameter %v4f32\n"
5403 "%label = OpLabel\n"
5404 "%result = OpVariable %fp_v4f32 Function\n"
5405 " OpStore %result %param\n"
5406 "%gen = ${GEN_RESULT}\n"
5407 "%index = OpIAdd %i32 %gen %c_i32_1\n"
5408 "%loc = OpAccessChain %fp_f32 %result %index\n"
5409 "%val = OpLoad %f32 %loc\n"
5410 "%add = OpFAdd %f32 %val %c_f32_0_5\n"
5411 " OpStore %loc %add\n"
5412 "%ret = OpLoad %v4f32 %result\n"
5413 " OpReturnValue %ret\n"
5416 inputColors[0] = RGBA(127, 127, 127, 255);
5417 inputColors[1] = RGBA(127, 0, 0, 255);
5418 inputColors[2] = RGBA(0, 127, 0, 255);
5419 inputColors[3] = RGBA(0, 0, 127, 255);
5421 // Derived from inputColors[x] by adding 128 to inputColors[x][0].
5422 outputColors0[0] = RGBA(255, 127, 127, 255);
5423 outputColors0[1] = RGBA(255, 0, 0, 255);
5424 outputColors0[2] = RGBA(128, 127, 0, 255);
5425 outputColors0[3] = RGBA(128, 0, 127, 255);
5427 // Derived from inputColors[x] by adding 128 to inputColors[x][1].
5428 outputColors1[0] = RGBA(127, 255, 127, 255);
5429 outputColors1[1] = RGBA(127, 128, 0, 255);
5430 outputColors1[2] = RGBA(0, 255, 0, 255);
5431 outputColors1[3] = RGBA(0, 128, 127, 255);
5433 // Derived from inputColors[x] by adding 128 to inputColors[x][2].
5434 outputColors2[0] = RGBA(127, 127, 255, 255);
5435 outputColors2[1] = RGBA(127, 0, 128, 255);
5436 outputColors2[2] = RGBA(0, 127, 128, 255);
5437 outputColors2[3] = RGBA(0, 0, 255, 255);
5439 const char addZeroToSc[] = "OpIAdd %i32 %c_i32_0 %sc_op";
5440 const char selectTrueUsingSc[] = "OpSelect %i32 %sc_op %c_i32_1 %c_i32_0";
5441 const char selectFalseUsingSc[] = "OpSelect %i32 %sc_op %c_i32_0 %c_i32_1";
5443 cases.push_back(SpecConstantTwoIntGraphicsCase("iadd", " %i32 0", " %i32 0", "%i32", "IAdd %sc_0 %sc_1", 19, -20, addZeroToSc, outputColors0));
5444 cases.push_back(SpecConstantTwoIntGraphicsCase("isub", " %i32 0", " %i32 0", "%i32", "ISub %sc_0 %sc_1", 19, 20, addZeroToSc, outputColors0));
5445 cases.push_back(SpecConstantTwoIntGraphicsCase("imul", " %i32 0", " %i32 0", "%i32", "IMul %sc_0 %sc_1", -1, -1, addZeroToSc, outputColors2));
5446 cases.push_back(SpecConstantTwoIntGraphicsCase("sdiv", " %i32 0", " %i32 0", "%i32", "SDiv %sc_0 %sc_1", -126, 126, addZeroToSc, outputColors0));
5447 cases.push_back(SpecConstantTwoIntGraphicsCase("udiv", " %i32 0", " %i32 0", "%i32", "UDiv %sc_0 %sc_1", 126, 126, addZeroToSc, outputColors2));
5448 cases.push_back(SpecConstantTwoIntGraphicsCase("srem", " %i32 0", " %i32 0", "%i32", "SRem %sc_0 %sc_1", 3, 2, addZeroToSc, outputColors2));
5449 cases.push_back(SpecConstantTwoIntGraphicsCase("smod", " %i32 0", " %i32 0", "%i32", "SMod %sc_0 %sc_1", 3, 2, addZeroToSc, outputColors2));
5450 cases.push_back(SpecConstantTwoIntGraphicsCase("umod", " %i32 0", " %i32 0", "%i32", "UMod %sc_0 %sc_1", 1001, 500, addZeroToSc, outputColors2));
5451 cases.push_back(SpecConstantTwoIntGraphicsCase("bitwiseand", " %i32 0", " %i32 0", "%i32", "BitwiseAnd %sc_0 %sc_1", 0x33, 0x0d, addZeroToSc, outputColors2));
5452 cases.push_back(SpecConstantTwoIntGraphicsCase("bitwiseor", " %i32 0", " %i32 0", "%i32", "BitwiseOr %sc_0 %sc_1", 0, 1, addZeroToSc, outputColors2));
5453 cases.push_back(SpecConstantTwoIntGraphicsCase("bitwisexor", " %i32 0", " %i32 0", "%i32", "BitwiseXor %sc_0 %sc_1", 0x2e, 0x2f, addZeroToSc, outputColors2));
5454 cases.push_back(SpecConstantTwoIntGraphicsCase("shiftrightlogical", " %i32 0", " %i32 0", "%i32", "ShiftRightLogical %sc_0 %sc_1", 2, 1, addZeroToSc, outputColors2));
5455 cases.push_back(SpecConstantTwoIntGraphicsCase("shiftrightarithmetic", " %i32 0", " %i32 0", "%i32", "ShiftRightArithmetic %sc_0 %sc_1", -4, 2, addZeroToSc, outputColors0));
5456 cases.push_back(SpecConstantTwoIntGraphicsCase("shiftleftlogical", " %i32 0", " %i32 0", "%i32", "ShiftLeftLogical %sc_0 %sc_1", 1, 0, addZeroToSc, outputColors2));
5457 cases.push_back(SpecConstantTwoIntGraphicsCase("slessthan", " %i32 0", " %i32 0", "%bool", "SLessThan %sc_0 %sc_1", -20, -10, selectTrueUsingSc, outputColors2));
5458 cases.push_back(SpecConstantTwoIntGraphicsCase("ulessthan", " %i32 0", " %i32 0", "%bool", "ULessThan %sc_0 %sc_1", 10, 20, selectTrueUsingSc, outputColors2));
5459 cases.push_back(SpecConstantTwoIntGraphicsCase("sgreaterthan", " %i32 0", " %i32 0", "%bool", "SGreaterThan %sc_0 %sc_1", -1000, 50, selectFalseUsingSc, outputColors2));
5460 cases.push_back(SpecConstantTwoIntGraphicsCase("ugreaterthan", " %i32 0", " %i32 0", "%bool", "UGreaterThan %sc_0 %sc_1", 10, 5, selectTrueUsingSc, outputColors2));
5461 cases.push_back(SpecConstantTwoIntGraphicsCase("slessthanequal", " %i32 0", " %i32 0", "%bool", "SLessThanEqual %sc_0 %sc_1", -10, -10, selectTrueUsingSc, outputColors2));
5462 cases.push_back(SpecConstantTwoIntGraphicsCase("ulessthanequal", " %i32 0", " %i32 0", "%bool", "ULessThanEqual %sc_0 %sc_1", 50, 100, selectTrueUsingSc, outputColors2));
5463 cases.push_back(SpecConstantTwoIntGraphicsCase("sgreaterthanequal", " %i32 0", " %i32 0", "%bool", "SGreaterThanEqual %sc_0 %sc_1", -1000, 50, selectFalseUsingSc, outputColors2));
5464 cases.push_back(SpecConstantTwoIntGraphicsCase("ugreaterthanequal", " %i32 0", " %i32 0", "%bool", "UGreaterThanEqual %sc_0 %sc_1", 10, 10, selectTrueUsingSc, outputColors2));
5465 cases.push_back(SpecConstantTwoIntGraphicsCase("iequal", " %i32 0", " %i32 0", "%bool", "IEqual %sc_0 %sc_1", 42, 24, selectFalseUsingSc, outputColors2));
5466 cases.push_back(SpecConstantTwoIntGraphicsCase("logicaland", "True %bool", "True %bool", "%bool", "LogicalAnd %sc_0 %sc_1", 0, 1, selectFalseUsingSc, outputColors2));
5467 cases.push_back(SpecConstantTwoIntGraphicsCase("logicalor", "False %bool", "False %bool", "%bool", "LogicalOr %sc_0 %sc_1", 1, 0, selectTrueUsingSc, outputColors2));
5468 cases.push_back(SpecConstantTwoIntGraphicsCase("logicalequal", "True %bool", "True %bool", "%bool", "LogicalEqual %sc_0 %sc_1", 0, 1, selectFalseUsingSc, outputColors2));
5469 cases.push_back(SpecConstantTwoIntGraphicsCase("logicalnotequal", "False %bool", "False %bool", "%bool", "LogicalNotEqual %sc_0 %sc_1", 1, 0, selectTrueUsingSc, outputColors2));
5470 cases.push_back(SpecConstantTwoIntGraphicsCase("snegate", " %i32 0", " %i32 0", "%i32", "SNegate %sc_0", -1, 0, addZeroToSc, outputColors2));
5471 cases.push_back(SpecConstantTwoIntGraphicsCase("not", " %i32 0", " %i32 0", "%i32", "Not %sc_0", -2, 0, addZeroToSc, outputColors2));
5472 cases.push_back(SpecConstantTwoIntGraphicsCase("logicalnot", "False %bool", "False %bool", "%bool", "LogicalNot %sc_0", 1, 0, selectFalseUsingSc, outputColors2));
5473 cases.push_back(SpecConstantTwoIntGraphicsCase("select", "False %bool", " %i32 0", "%i32", "Select %sc_0 %sc_1 %c_i32_0", 1, 1, addZeroToSc, outputColors2));
5474 // OpSConvert, OpFConvert: these two instructions involve ints/floats of different bitwidths.
5475 // \todo[2015-12-1 antiagainst] OpQuantizeToF16
5477 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
5479 map<string, string> specializations;
5480 map<string, string> fragments;
5481 vector<deInt32> specConstants;
5483 specializations["SC_DEF0"] = cases[caseNdx].scDefinition0;
5484 specializations["SC_DEF1"] = cases[caseNdx].scDefinition1;
5485 specializations["SC_RESULT_TYPE"] = cases[caseNdx].scResultType;
5486 specializations["SC_OP"] = cases[caseNdx].scOperation;
5487 specializations["GEN_RESULT"] = cases[caseNdx].resultOperation;
5489 fragments["decoration"] = tcu::StringTemplate(decorations1).specialize(specializations);
5490 fragments["pre_main"] = tcu::StringTemplate(typesAndConstants1).specialize(specializations);
5491 fragments["testfun"] = tcu::StringTemplate(function1).specialize(specializations);
5493 specConstants.push_back(cases[caseNdx].scActualValue0);
5494 specConstants.push_back(cases[caseNdx].scActualValue1);
5496 createTestsForAllStages(cases[caseNdx].caseName, inputColors, cases[caseNdx].expectedColors, fragments, specConstants, group.get());
5499 const char decorations2[] =
5500 "OpDecorate %sc_0 SpecId 0\n"
5501 "OpDecorate %sc_1 SpecId 1\n"
5502 "OpDecorate %sc_2 SpecId 2\n";
5504 const char typesAndConstants2[] =
5505 "%v3i32 = OpTypeVector %i32 3\n"
5506 "%vec3_0 = OpConstantComposite %v3i32 %c_i32_0 %c_i32_0 %c_i32_0\n"
5507 "%vec3_undef = OpUndef %v3i32\n"
5509 "%sc_0 = OpSpecConstant %i32 0\n"
5510 "%sc_1 = OpSpecConstant %i32 0\n"
5511 "%sc_2 = OpSpecConstant %i32 0\n"
5512 "%sc_vec3_0 = OpSpecConstantOp %v3i32 CompositeInsert %sc_0 %vec3_0 0\n" // (sc_0, 0, 0)
5513 "%sc_vec3_1 = OpSpecConstantOp %v3i32 CompositeInsert %sc_1 %vec3_0 1\n" // (0, sc_1, 0)
5514 "%sc_vec3_2 = OpSpecConstantOp %v3i32 CompositeInsert %sc_2 %vec3_0 2\n" // (0, 0, sc_2)
5515 "%sc_vec3_0_s = OpSpecConstantOp %v3i32 VectorShuffle %sc_vec3_0 %vec3_undef 0 0xFFFFFFFF 2\n" // (sc_0, ???, 0)
5516 "%sc_vec3_1_s = OpSpecConstantOp %v3i32 VectorShuffle %sc_vec3_1 %vec3_undef 0xFFFFFFFF 1 0\n" // (???, sc_1, 0)
5517 "%sc_vec3_2_s = OpSpecConstantOp %v3i32 VectorShuffle %vec3_undef %sc_vec3_2 5 0xFFFFFFFF 5\n" // (sc_2, ???, sc_2)
5518 "%sc_vec3_01 = OpSpecConstantOp %v3i32 VectorShuffle %sc_vec3_0_s %sc_vec3_1_s 1 0 4\n" // (0, sc_0, sc_1)
5519 "%sc_vec3_012 = OpSpecConstantOp %v3i32 VectorShuffle %sc_vec3_01 %sc_vec3_2_s 5 1 2\n" // (sc_2, sc_0, sc_1)
5520 "%sc_ext_0 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 0\n" // sc_2
5521 "%sc_ext_1 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 1\n" // sc_0
5522 "%sc_ext_2 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 2\n" // sc_1
5523 "%sc_sub = OpSpecConstantOp %i32 ISub %sc_ext_0 %sc_ext_1\n" // (sc_2 - sc_0)
5524 "%sc_final = OpSpecConstantOp %i32 IMul %sc_sub %sc_ext_2\n"; // (sc_2 - sc_0) * sc_1
5526 const char function2[] =
5527 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5528 "%param = OpFunctionParameter %v4f32\n"
5529 "%label = OpLabel\n"
5530 "%result = OpVariable %fp_v4f32 Function\n"
5531 " OpStore %result %param\n"
5532 "%loc = OpAccessChain %fp_f32 %result %sc_final\n"
5533 "%val = OpLoad %f32 %loc\n"
5534 "%add = OpFAdd %f32 %val %c_f32_0_5\n"
5535 " OpStore %loc %add\n"
5536 "%ret = OpLoad %v4f32 %result\n"
5537 " OpReturnValue %ret\n"
5540 map<string, string> fragments;
5541 vector<deInt32> specConstants;
5543 fragments["decoration"] = decorations2;
5544 fragments["pre_main"] = typesAndConstants2;
5545 fragments["testfun"] = function2;
5547 specConstants.push_back(56789);
5548 specConstants.push_back(-2);
5549 specConstants.push_back(56788);
5551 createTestsForAllStages("vector_related", inputColors, outputColors2, fragments, specConstants, group.get());
5553 return group.release();
5556 tcu::TestCaseGroup* createOpPhiTests(tcu::TestContext& testCtx)
5558 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opphi", "Test the OpPhi instruction"));
5559 RGBA inputColors[4];
5560 RGBA outputColors1[4];
5561 RGBA outputColors2[4];
5562 RGBA outputColors3[4];
5563 map<string, string> fragments1;
5564 map<string, string> fragments2;
5565 map<string, string> fragments3;
5567 const char typesAndConstants1[] =
5568 "%c_f32_p2 = OpConstant %f32 0.2\n"
5569 "%c_f32_p4 = OpConstant %f32 0.4\n"
5570 "%c_f32_p5 = OpConstant %f32 0.5\n"
5571 "%c_f32_p8 = OpConstant %f32 0.8\n";
5573 // vec4 test_code(vec4 param) {
5574 // vec4 result = param;
5575 // for (int i = 0; i < 4; ++i) {
5578 // case 0: operand = .2; break;
5579 // case 1: operand = .5; break;
5580 // case 2: operand = .4; break;
5581 // case 3: operand = .0; break;
5582 // default: break; // unreachable
5584 // result[i] += operand;
5588 const char function1[] =
5589 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5590 "%param1 = OpFunctionParameter %v4f32\n"
5592 "%iptr = OpVariable %fp_i32 Function\n"
5593 "%result = OpVariable %fp_v4f32 Function\n"
5594 " OpStore %iptr %c_i32_0\n"
5595 " OpStore %result %param1\n"
5599 "%ival = OpLoad %i32 %iptr\n"
5600 "%lt_4 = OpSLessThan %bool %ival %c_i32_4\n"
5601 " OpLoopMerge %exit %phi None\n"
5602 " OpBranchConditional %lt_4 %entry %exit\n"
5604 "%entry = OpLabel\n"
5605 "%loc = OpAccessChain %fp_f32 %result %ival\n"
5606 "%val = OpLoad %f32 %loc\n"
5607 " OpSelectionMerge %phi None\n"
5608 " OpSwitch %ival %default 0 %case0 1 %case1 2 %case2 3 %case3\n"
5610 "%case0 = OpLabel\n"
5612 "%case1 = OpLabel\n"
5614 "%case2 = OpLabel\n"
5616 "%case3 = OpLabel\n"
5619 "%default = OpLabel\n"
5623 "%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
5624 "%add = OpFAdd %f32 %val %operand\n"
5625 " OpStore %loc %add\n"
5626 "%ival_next = OpIAdd %i32 %ival %c_i32_1\n"
5627 " OpStore %iptr %ival_next\n"
5631 "%ret = OpLoad %v4f32 %result\n"
5632 " OpReturnValue %ret\n"
5636 fragments1["pre_main"] = typesAndConstants1;
5637 fragments1["testfun"] = function1;
5639 getHalfColorsFullAlpha(inputColors);
5641 outputColors1[0] = RGBA(178, 255, 229, 255);
5642 outputColors1[1] = RGBA(178, 127, 102, 255);
5643 outputColors1[2] = RGBA(51, 255, 102, 255);
5644 outputColors1[3] = RGBA(51, 127, 229, 255);
5646 createTestsForAllStages("out_of_order", inputColors, outputColors1, fragments1, group.get());
5648 const char typesAndConstants2[] =
5649 "%c_f32_p2 = OpConstant %f32 0.2\n";
5651 // Add .4 to the second element of the given parameter.
5652 const char function2[] =
5653 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5654 "%param = OpFunctionParameter %v4f32\n"
5655 "%entry = OpLabel\n"
5656 "%result = OpVariable %fp_v4f32 Function\n"
5657 " OpStore %result %param\n"
5658 "%loc = OpAccessChain %fp_f32 %result %c_i32_1\n"
5659 "%val = OpLoad %f32 %loc\n"
5663 "%step = OpPhi %i32 %c_i32_0 %entry %step_next %phi\n"
5664 "%accum = OpPhi %f32 %val %entry %accum_next %phi\n"
5665 "%step_next = OpIAdd %i32 %step %c_i32_1\n"
5666 "%accum_next = OpFAdd %f32 %accum %c_f32_p2\n"
5667 "%still_loop = OpSLessThan %bool %step %c_i32_2\n"
5668 " OpLoopMerge %exit %phi None\n"
5669 " OpBranchConditional %still_loop %phi %exit\n"
5672 " OpStore %loc %accum\n"
5673 "%ret = OpLoad %v4f32 %result\n"
5674 " OpReturnValue %ret\n"
5678 fragments2["pre_main"] = typesAndConstants2;
5679 fragments2["testfun"] = function2;
5681 outputColors2[0] = RGBA(127, 229, 127, 255);
5682 outputColors2[1] = RGBA(127, 102, 0, 255);
5683 outputColors2[2] = RGBA(0, 229, 0, 255);
5684 outputColors2[3] = RGBA(0, 102, 127, 255);
5686 createTestsForAllStages("induction", inputColors, outputColors2, fragments2, group.get());
5688 const char typesAndConstants3[] =
5689 "%true = OpConstantTrue %bool\n"
5690 "%false = OpConstantFalse %bool\n"
5691 "%c_f32_p2 = OpConstant %f32 0.2\n";
5693 // Swap the second and the third element of the given parameter.
5694 const char function3[] =
5695 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5696 "%param = OpFunctionParameter %v4f32\n"
5697 "%entry = OpLabel\n"
5698 "%result = OpVariable %fp_v4f32 Function\n"
5699 " OpStore %result %param\n"
5700 "%a_loc = OpAccessChain %fp_f32 %result %c_i32_1\n"
5701 "%a_init = OpLoad %f32 %a_loc\n"
5702 "%b_loc = OpAccessChain %fp_f32 %result %c_i32_2\n"
5703 "%b_init = OpLoad %f32 %b_loc\n"
5707 "%still_loop = OpPhi %bool %true %entry %false %phi\n"
5708 "%a_next = OpPhi %f32 %a_init %entry %b_next %phi\n"
5709 "%b_next = OpPhi %f32 %b_init %entry %a_next %phi\n"
5710 " OpLoopMerge %exit %phi None\n"
5711 " OpBranchConditional %still_loop %phi %exit\n"
5714 " OpStore %a_loc %a_next\n"
5715 " OpStore %b_loc %b_next\n"
5716 "%ret = OpLoad %v4f32 %result\n"
5717 " OpReturnValue %ret\n"
5721 fragments3["pre_main"] = typesAndConstants3;
5722 fragments3["testfun"] = function3;
5724 outputColors3[0] = RGBA(127, 127, 127, 255);
5725 outputColors3[1] = RGBA(127, 0, 0, 255);
5726 outputColors3[2] = RGBA(0, 0, 127, 255);
5727 outputColors3[3] = RGBA(0, 127, 0, 255);
5729 createTestsForAllStages("swap", inputColors, outputColors3, fragments3, group.get());
5731 return group.release();
5734 tcu::TestCaseGroup* createNoContractionTests(tcu::TestContext& testCtx)
5736 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "nocontraction", "Test the NoContraction decoration"));
5737 RGBA inputColors[4];
5738 RGBA outputColors[4];
5740 // With NoContraction, (1 + 2^-23) * (1 - 2^-23) - 1 should be conducted as a multiplication and an addition separately.
5741 // For the multiplication, the result is 1 - 2^-46, which is out of the precision range for 32-bit float. (32-bit float
5742 // only have 23-bit fraction.) So it will be rounded to 1. Or 0x1.fffffc. Then the final result is 0 or -0x1p-24.
5743 // On the contrary, the result will be 2^-46, which is a normalized number perfectly representable as 32-bit float.
5744 const char constantsAndTypes[] =
5745 "%c_vec4_0 = OpConstantComposite %v4f32 %c_f32_0 %c_f32_0 %c_f32_0 %c_f32_1\n"
5746 "%c_vec4_1 = OpConstantComposite %v4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_1\n"
5747 "%c_f32_1pl2_23 = OpConstant %f32 0x1.000002p+0\n" // 1 + 2^-23
5748 "%c_f32_1mi2_23 = OpConstant %f32 0x1.fffffcp-1\n" // 1 - 2^-23
5749 "%c_f32_n1pn24 = OpConstant %f32 -0x1p-24\n"
5752 const char function[] =
5753 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5754 "%param = OpFunctionParameter %v4f32\n"
5755 "%label = OpLabel\n"
5756 "%var1 = OpVariable %fp_f32 Function %c_f32_1pl2_23\n"
5757 "%var2 = OpVariable %fp_f32 Function\n"
5758 "%red = OpCompositeExtract %f32 %param 0\n"
5759 "%plus_red = OpFAdd %f32 %c_f32_1mi2_23 %red\n"
5760 " OpStore %var2 %plus_red\n"
5761 "%val1 = OpLoad %f32 %var1\n"
5762 "%val2 = OpLoad %f32 %var2\n"
5763 "%mul = OpFMul %f32 %val1 %val2\n"
5764 "%add = OpFAdd %f32 %mul %c_f32_n1\n"
5765 "%is0 = OpFOrdEqual %bool %add %c_f32_0\n"
5766 "%isn1n24 = OpFOrdEqual %bool %add %c_f32_n1pn24\n"
5767 "%success = OpLogicalOr %bool %is0 %isn1n24\n"
5768 "%v4success = OpCompositeConstruct %v4bool %success %success %success %success\n"
5769 "%ret = OpSelect %v4f32 %v4success %c_vec4_0 %c_vec4_1\n"
5770 " OpReturnValue %ret\n"
5773 struct CaseNameDecoration
5780 CaseNameDecoration tests[] = {
5781 {"multiplication", "OpDecorate %mul NoContraction"},
5782 {"addition", "OpDecorate %add NoContraction"},
5783 {"both", "OpDecorate %mul NoContraction\nOpDecorate %add NoContraction"},
5786 getHalfColorsFullAlpha(inputColors);
5788 for (deUint8 idx = 0; idx < 4; ++idx)
5790 inputColors[idx].setRed(0);
5791 outputColors[idx] = RGBA(0, 0, 0, 255);
5794 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(CaseNameDecoration); ++testNdx)
5796 map<string, string> fragments;
5798 fragments["decoration"] = tests[testNdx].decoration;
5799 fragments["pre_main"] = constantsAndTypes;
5800 fragments["testfun"] = function;
5802 createTestsForAllStages(tests[testNdx].name, inputColors, outputColors, fragments, group.get());
5805 return group.release();
5808 tcu::TestCaseGroup* createMemoryAccessTests(tcu::TestContext& testCtx)
5810 de::MovePtr<tcu::TestCaseGroup> memoryAccessTests (new tcu::TestCaseGroup(testCtx, "opmemoryaccess", "Memory Semantics"));
5813 const char constantsAndTypes[] =
5814 "%c_a2f32_1 = OpConstantComposite %a2f32 %c_f32_1 %c_f32_1\n"
5815 "%fp_a2f32 = OpTypePointer Function %a2f32\n"
5816 "%stype = OpTypeStruct %v4f32 %a2f32 %f32\n"
5817 "%fp_stype = OpTypePointer Function %stype\n";
5819 const char function[] =
5820 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5821 "%param1 = OpFunctionParameter %v4f32\n"
5823 "%v1 = OpVariable %fp_v4f32 Function\n"
5824 "%v2 = OpVariable %fp_a2f32 Function\n"
5825 "%v3 = OpVariable %fp_f32 Function\n"
5826 "%v = OpVariable %fp_stype Function\n"
5827 "%vv = OpVariable %fp_stype Function\n"
5828 "%vvv = OpVariable %fp_f32 Function\n"
5830 " OpStore %v1 %c_v4f32_1_1_1_1\n"
5831 " OpStore %v2 %c_a2f32_1\n"
5832 " OpStore %v3 %c_f32_1\n"
5834 "%p_v4f32 = OpAccessChain %fp_v4f32 %v %c_u32_0\n"
5835 "%p_a2f32 = OpAccessChain %fp_a2f32 %v %c_u32_1\n"
5836 "%p_f32 = OpAccessChain %fp_f32 %v %c_u32_2\n"
5837 "%v1_v = OpLoad %v4f32 %v1 ${access_type}\n"
5838 "%v2_v = OpLoad %a2f32 %v2 ${access_type}\n"
5839 "%v3_v = OpLoad %f32 %v3 ${access_type}\n"
5841 " OpStore %p_v4f32 %v1_v ${access_type}\n"
5842 " OpStore %p_a2f32 %v2_v ${access_type}\n"
5843 " OpStore %p_f32 %v3_v ${access_type}\n"
5845 " OpCopyMemory %vv %v ${access_type}\n"
5846 " OpCopyMemory %vvv %p_f32 ${access_type}\n"
5848 "%p_f32_2 = OpAccessChain %fp_f32 %vv %c_u32_2\n"
5849 "%v_f32_2 = OpLoad %f32 %p_f32_2\n"
5850 "%v_f32_3 = OpLoad %f32 %vvv\n"
5852 "%ret1 = OpVectorTimesScalar %v4f32 %param1 %v_f32_2\n"
5853 "%ret2 = OpVectorTimesScalar %v4f32 %ret1 %v_f32_3\n"
5854 " OpReturnValue %ret2\n"
5857 struct NameMemoryAccess
5864 NameMemoryAccess tests[] =
5867 { "volatile", "Volatile" },
5868 { "aligned", "Aligned 1" },
5869 { "volatile_aligned", "Volatile|Aligned 1" },
5870 { "nontemporal_aligned", "Nontemporal|Aligned 1" },
5871 { "volatile_nontemporal", "Volatile|Nontemporal" },
5872 { "volatile_nontermporal_aligned", "Volatile|Nontemporal|Aligned 1" },
5875 getHalfColorsFullAlpha(colors);
5877 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameMemoryAccess); ++testNdx)
5879 map<string, string> fragments;
5880 map<string, string> memoryAccess;
5881 memoryAccess["access_type"] = tests[testNdx].accessType;
5883 fragments["pre_main"] = constantsAndTypes;
5884 fragments["testfun"] = tcu::StringTemplate(function).specialize(memoryAccess);
5885 createTestsForAllStages(tests[testNdx].name, colors, colors, fragments, memoryAccessTests.get());
5887 return memoryAccessTests.release();
5889 tcu::TestCaseGroup* createOpUndefTests(tcu::TestContext& testCtx)
5891 de::MovePtr<tcu::TestCaseGroup> opUndefTests (new tcu::TestCaseGroup(testCtx, "opundef", "Test OpUndef"));
5892 RGBA defaultColors[4];
5893 map<string, string> fragments;
5894 getDefaultColors(defaultColors);
5896 // First, simple cases that don't do anything with the OpUndef result.
5897 struct NameCodePair { string name, decl, type; };
5898 const NameCodePair tests[] =
5900 {"bool", "", "%bool"},
5901 {"vec2uint32", "%type = OpTypeVector %u32 2", "%type"},
5902 {"image", "%type = OpTypeImage %f32 2D 0 0 0 1 Unknown", "%type"},
5903 {"sampler", "%type = OpTypeSampler", "%type"},
5904 {"sampledimage", "%img = OpTypeImage %f32 2D 0 0 0 1 Unknown\n" "%type = OpTypeSampledImage %img", "%type"},
5905 {"pointer", "", "%fp_i32"},
5906 {"runtimearray", "%type = OpTypeRuntimeArray %f32", "%type"},
5907 {"array", "%c_u32_100 = OpConstant %u32 100\n" "%type = OpTypeArray %i32 %c_u32_100", "%type"},
5908 {"struct", "%type = OpTypeStruct %f32 %i32 %u32", "%type"}};
5909 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameCodePair); ++testNdx)
5911 fragments["undef_type"] = tests[testNdx].type;
5912 fragments["testfun"] = StringTemplate(
5913 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5914 "%param1 = OpFunctionParameter %v4f32\n"
5915 "%label_testfun = OpLabel\n"
5916 "%undef = OpUndef ${undef_type}\n"
5917 "OpReturnValue %param1\n"
5918 "OpFunctionEnd\n").specialize(fragments);
5919 fragments["pre_main"] = tests[testNdx].decl;
5920 createTestsForAllStages(tests[testNdx].name, defaultColors, defaultColors, fragments, opUndefTests.get());
5924 fragments["testfun"] =
5925 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5926 "%param1 = OpFunctionParameter %v4f32\n"
5927 "%label_testfun = OpLabel\n"
5928 "%undef = OpUndef %f32\n"
5929 "%zero = OpFMul %f32 %undef %c_f32_0\n"
5930 "%is_nan = OpIsNan %bool %zero\n" //OpUndef may result in NaN which may turn %zero into Nan.
5931 "%actually_zero = OpSelect %f32 %is_nan %c_f32_0 %zero\n"
5932 "%a = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
5933 "%b = OpFAdd %f32 %a %actually_zero\n"
5934 "%ret = OpVectorInsertDynamic %v4f32 %param1 %b %c_i32_0\n"
5935 "OpReturnValue %ret\n"
5938 createTestsForAllStages("float32", defaultColors, defaultColors, fragments, opUndefTests.get());
5940 fragments["testfun"] =
5941 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5942 "%param1 = OpFunctionParameter %v4f32\n"
5943 "%label_testfun = OpLabel\n"
5944 "%undef = OpUndef %i32\n"
5945 "%zero = OpIMul %i32 %undef %c_i32_0\n"
5946 "%a = OpVectorExtractDynamic %f32 %param1 %zero\n"
5947 "%ret = OpVectorInsertDynamic %v4f32 %param1 %a %c_i32_0\n"
5948 "OpReturnValue %ret\n"
5951 createTestsForAllStages("sint32", defaultColors, defaultColors, fragments, opUndefTests.get());
5953 fragments["testfun"] =
5954 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5955 "%param1 = OpFunctionParameter %v4f32\n"
5956 "%label_testfun = OpLabel\n"
5957 "%undef = OpUndef %u32\n"
5958 "%zero = OpIMul %u32 %undef %c_i32_0\n"
5959 "%a = OpVectorExtractDynamic %f32 %param1 %zero\n"
5960 "%ret = OpVectorInsertDynamic %v4f32 %param1 %a %c_i32_0\n"
5961 "OpReturnValue %ret\n"
5964 createTestsForAllStages("uint32", defaultColors, defaultColors, fragments, opUndefTests.get());
5966 fragments["testfun"] =
5967 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5968 "%param1 = OpFunctionParameter %v4f32\n"
5969 "%label_testfun = OpLabel\n"
5970 "%undef = OpUndef %v4f32\n"
5971 "%vzero = OpVectorTimesScalar %v4f32 %undef %c_f32_0\n"
5972 "%zero_0 = OpVectorExtractDynamic %f32 %vzero %c_i32_0\n"
5973 "%zero_1 = OpVectorExtractDynamic %f32 %vzero %c_i32_1\n"
5974 "%zero_2 = OpVectorExtractDynamic %f32 %vzero %c_i32_2\n"
5975 "%zero_3 = OpVectorExtractDynamic %f32 %vzero %c_i32_3\n"
5976 "%is_nan_0 = OpIsNan %bool %zero_0\n"
5977 "%is_nan_1 = OpIsNan %bool %zero_1\n"
5978 "%is_nan_2 = OpIsNan %bool %zero_2\n"
5979 "%is_nan_3 = OpIsNan %bool %zero_3\n"
5980 "%actually_zero_0 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_0\n"
5981 "%actually_zero_1 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_1\n"
5982 "%actually_zero_2 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_2\n"
5983 "%actually_zero_3 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_3\n"
5984 "%param1_0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
5985 "%param1_1 = OpVectorExtractDynamic %f32 %param1 %c_i32_1\n"
5986 "%param1_2 = OpVectorExtractDynamic %f32 %param1 %c_i32_2\n"
5987 "%param1_3 = OpVectorExtractDynamic %f32 %param1 %c_i32_3\n"
5988 "%sum_0 = OpFAdd %f32 %param1_0 %actually_zero_0\n"
5989 "%sum_1 = OpFAdd %f32 %param1_1 %actually_zero_1\n"
5990 "%sum_2 = OpFAdd %f32 %param1_2 %actually_zero_2\n"
5991 "%sum_3 = OpFAdd %f32 %param1_3 %actually_zero_3\n"
5992 "%ret3 = OpVectorInsertDynamic %v4f32 %param1 %sum_3 %c_i32_3\n"
5993 "%ret2 = OpVectorInsertDynamic %v4f32 %ret3 %sum_2 %c_i32_2\n"
5994 "%ret1 = OpVectorInsertDynamic %v4f32 %ret2 %sum_1 %c_i32_1\n"
5995 "%ret = OpVectorInsertDynamic %v4f32 %ret1 %sum_0 %c_i32_0\n"
5996 "OpReturnValue %ret\n"
5999 createTestsForAllStages("vec4float32", defaultColors, defaultColors, fragments, opUndefTests.get());
6001 fragments["pre_main"] =
6002 "%m2x2f32 = OpTypeMatrix %v2f32 2\n";
6003 fragments["testfun"] =
6004 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6005 "%param1 = OpFunctionParameter %v4f32\n"
6006 "%label_testfun = OpLabel\n"
6007 "%undef = OpUndef %m2x2f32\n"
6008 "%mzero = OpMatrixTimesScalar %m2x2f32 %undef %c_f32_0\n"
6009 "%zero_0 = OpCompositeExtract %f32 %mzero 0 0\n"
6010 "%zero_1 = OpCompositeExtract %f32 %mzero 0 1\n"
6011 "%zero_2 = OpCompositeExtract %f32 %mzero 1 0\n"
6012 "%zero_3 = OpCompositeExtract %f32 %mzero 1 1\n"
6013 "%is_nan_0 = OpIsNan %bool %zero_0\n"
6014 "%is_nan_1 = OpIsNan %bool %zero_1\n"
6015 "%is_nan_2 = OpIsNan %bool %zero_2\n"
6016 "%is_nan_3 = OpIsNan %bool %zero_3\n"
6017 "%actually_zero_0 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_0\n"
6018 "%actually_zero_1 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_1\n"
6019 "%actually_zero_2 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_2\n"
6020 "%actually_zero_3 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_3\n"
6021 "%param1_0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
6022 "%param1_1 = OpVectorExtractDynamic %f32 %param1 %c_i32_1\n"
6023 "%param1_2 = OpVectorExtractDynamic %f32 %param1 %c_i32_2\n"
6024 "%param1_3 = OpVectorExtractDynamic %f32 %param1 %c_i32_3\n"
6025 "%sum_0 = OpFAdd %f32 %param1_0 %actually_zero_0\n"
6026 "%sum_1 = OpFAdd %f32 %param1_1 %actually_zero_1\n"
6027 "%sum_2 = OpFAdd %f32 %param1_2 %actually_zero_2\n"
6028 "%sum_3 = OpFAdd %f32 %param1_3 %actually_zero_3\n"
6029 "%ret3 = OpVectorInsertDynamic %v4f32 %param1 %sum_3 %c_i32_3\n"
6030 "%ret2 = OpVectorInsertDynamic %v4f32 %ret3 %sum_2 %c_i32_2\n"
6031 "%ret1 = OpVectorInsertDynamic %v4f32 %ret2 %sum_1 %c_i32_1\n"
6032 "%ret = OpVectorInsertDynamic %v4f32 %ret1 %sum_0 %c_i32_0\n"
6033 "OpReturnValue %ret\n"
6036 createTestsForAllStages("matrix", defaultColors, defaultColors, fragments, opUndefTests.get());
6038 return opUndefTests.release();
6041 void createOpQuantizeSingleOptionTests(tcu::TestCaseGroup* testCtx)
6043 const RGBA inputColors[4] =
6046 RGBA(0, 0, 255, 255),
6047 RGBA(0, 255, 0, 255),
6048 RGBA(0, 255, 255, 255)
6051 const RGBA expectedColors[4] =
6053 RGBA(255, 0, 0, 255),
6054 RGBA(255, 0, 0, 255),
6055 RGBA(255, 0, 0, 255),
6056 RGBA(255, 0, 0, 255)
6059 const struct SingleFP16Possibility
6062 const char* constant; // Value to assign to %test_constant.
6064 const char* condition; // Must assign to %cond an expression that evaluates to true after %c = OpQuantizeToF16(%test_constant + 0).
6070 -constructNormalizedFloat(1, 0x300000),
6071 "%cond = OpFOrdEqual %bool %c %test_constant\n"
6076 constructNormalizedFloat(7, 0x000000),
6077 "%cond = OpFOrdEqual %bool %c %test_constant\n"
6079 // SPIR-V requires that OpQuantizeToF16 flushes
6080 // any numbers that would end up denormalized in F16 to zero.
6084 std::ldexp(1.5f, -140),
6085 "%cond = OpFOrdEqual %bool %c %c_f32_0\n"
6090 -std::ldexp(1.5f, -140),
6091 "%cond = OpFOrdEqual %bool %c %c_f32_0\n"
6096 std::ldexp(1.0f, -16),
6097 "%cond = OpFOrdEqual %bool %c %c_f32_0\n"
6098 }, // too small positive
6100 "negative_too_small",
6102 -std::ldexp(1.0f, -32),
6103 "%cond = OpFOrdEqual %bool %c %c_f32_0\n"
6104 }, // too small negative
6108 -std::ldexp(1.0f, 128),
6110 "%gz = OpFOrdLessThan %bool %c %c_f32_0\n"
6111 "%inf = OpIsInf %bool %c\n"
6112 "%cond = OpLogicalAnd %bool %gz %inf\n"
6117 std::ldexp(1.0f, 128),
6119 "%gz = OpFOrdGreaterThan %bool %c %c_f32_0\n"
6120 "%inf = OpIsInf %bool %c\n"
6121 "%cond = OpLogicalAnd %bool %gz %inf\n"
6124 "round_to_negative_inf",
6126 -std::ldexp(1.0f, 32),
6128 "%gz = OpFOrdLessThan %bool %c %c_f32_0\n"
6129 "%inf = OpIsInf %bool %c\n"
6130 "%cond = OpLogicalAnd %bool %gz %inf\n"
6135 std::ldexp(1.0f, 16),
6137 "%gz = OpFOrdGreaterThan %bool %c %c_f32_0\n"
6138 "%inf = OpIsInf %bool %c\n"
6139 "%cond = OpLogicalAnd %bool %gz %inf\n"
6144 std::numeric_limits<float>::quiet_NaN(),
6146 // Test for any NaN value, as NaNs are not preserved
6147 "%direct_quant = OpQuantizeToF16 %f32 %test_constant\n"
6148 "%cond = OpIsNan %bool %direct_quant\n"
6153 std::numeric_limits<float>::quiet_NaN(),
6155 // Test for any NaN value, as NaNs are not preserved
6156 "%direct_quant = OpQuantizeToF16 %f32 %test_constant\n"
6157 "%cond = OpIsNan %bool %direct_quant\n"
6160 const char* constants =
6161 "%test_constant = OpConstant %f32 "; // The value will be test.constant.
6163 StringTemplate function (
6164 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6165 "%param1 = OpFunctionParameter %v4f32\n"
6166 "%label_testfun = OpLabel\n"
6167 "%a = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
6168 "%b = OpFAdd %f32 %test_constant %a\n"
6169 "%c = OpQuantizeToF16 %f32 %b\n"
6171 "%v4cond = OpCompositeConstruct %v4bool %cond %cond %cond %cond\n"
6172 "%retval = OpSelect %v4f32 %v4cond %c_v4f32_1_0_0_1 %param1\n"
6173 " OpReturnValue %retval\n"
6177 const char* specDecorations = "OpDecorate %test_constant SpecId 0\n";
6178 const char* specConstants =
6179 "%test_constant = OpSpecConstant %f32 0.\n"
6180 "%c = OpSpecConstantOp %f32 QuantizeToF16 %test_constant\n";
6182 StringTemplate specConstantFunction(
6183 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6184 "%param1 = OpFunctionParameter %v4f32\n"
6185 "%label_testfun = OpLabel\n"
6187 "%v4cond = OpCompositeConstruct %v4bool %cond %cond %cond %cond\n"
6188 "%retval = OpSelect %v4f32 %v4cond %c_v4f32_1_0_0_1 %param1\n"
6189 " OpReturnValue %retval\n"
6193 for (size_t idx = 0; idx < (sizeof(tests)/sizeof(tests[0])); ++idx)
6195 map<string, string> codeSpecialization;
6196 map<string, string> fragments;
6197 codeSpecialization["condition"] = tests[idx].condition;
6198 fragments["testfun"] = function.specialize(codeSpecialization);
6199 fragments["pre_main"] = string(constants) + tests[idx].constant + "\n";
6200 createTestsForAllStages(tests[idx].name, inputColors, expectedColors, fragments, testCtx);
6203 for (size_t idx = 0; idx < (sizeof(tests)/sizeof(tests[0])); ++idx)
6205 map<string, string> codeSpecialization;
6206 map<string, string> fragments;
6207 vector<deInt32> passConstants;
6208 deInt32 specConstant;
6210 codeSpecialization["condition"] = tests[idx].condition;
6211 fragments["testfun"] = specConstantFunction.specialize(codeSpecialization);
6212 fragments["decoration"] = specDecorations;
6213 fragments["pre_main"] = specConstants;
6215 memcpy(&specConstant, &tests[idx].valueAsFloat, sizeof(float));
6216 passConstants.push_back(specConstant);
6218 createTestsForAllStages(string("spec_const_") + tests[idx].name, inputColors, expectedColors, fragments, passConstants, testCtx);
6222 void createOpQuantizeTwoPossibilityTests(tcu::TestCaseGroup* testCtx)
6224 RGBA inputColors[4] = {
6226 RGBA(0, 0, 255, 255),
6227 RGBA(0, 255, 0, 255),
6228 RGBA(0, 255, 255, 255)
6231 RGBA expectedColors[4] =
6233 RGBA(255, 0, 0, 255),
6234 RGBA(255, 0, 0, 255),
6235 RGBA(255, 0, 0, 255),
6236 RGBA(255, 0, 0, 255)
6239 struct DualFP16Possibility
6244 const char* possibleOutput1;
6245 const char* possibleOutput2;
6248 "positive_round_up_or_round_down",
6250 constructNormalizedFloat(8, 0x300300),
6255 "negative_round_up_or_round_down",
6257 -constructNormalizedFloat(-7, 0x600800),
6264 constructNormalizedFloat(2, 0x01e000),
6269 "carry_to_exponent",
6271 constructNormalizedFloat(1, 0xffe000),
6276 StringTemplate constants (
6277 "%input_const = OpConstant %f32 ${input}\n"
6278 "%possible_solution1 = OpConstant %f32 ${output1}\n"
6279 "%possible_solution2 = OpConstant %f32 ${output2}\n"
6282 StringTemplate specConstants (
6283 "%input_const = OpSpecConstant %f32 0.\n"
6284 "%possible_solution1 = OpConstant %f32 ${output1}\n"
6285 "%possible_solution2 = OpConstant %f32 ${output2}\n"
6288 const char* specDecorations = "OpDecorate %input_const SpecId 0\n";
6290 const char* function =
6291 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6292 "%param1 = OpFunctionParameter %v4f32\n"
6293 "%label_testfun = OpLabel\n"
6294 "%a = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
6295 // For the purposes of this test we assume that 0.f will always get
6296 // faithfully passed through the pipeline stages.
6297 "%b = OpFAdd %f32 %input_const %a\n"
6298 "%c = OpQuantizeToF16 %f32 %b\n"
6299 "%eq_1 = OpFOrdEqual %bool %c %possible_solution1\n"
6300 "%eq_2 = OpFOrdEqual %bool %c %possible_solution2\n"
6301 "%cond = OpLogicalOr %bool %eq_1 %eq_2\n"
6302 "%v4cond = OpCompositeConstruct %v4bool %cond %cond %cond %cond\n"
6303 "%retval = OpSelect %v4f32 %v4cond %c_v4f32_1_0_0_1 %param1"
6304 " OpReturnValue %retval\n"
6307 for(size_t idx = 0; idx < (sizeof(tests)/sizeof(tests[0])); ++idx) {
6308 map<string, string> fragments;
6309 map<string, string> constantSpecialization;
6311 constantSpecialization["input"] = tests[idx].input;
6312 constantSpecialization["output1"] = tests[idx].possibleOutput1;
6313 constantSpecialization["output2"] = tests[idx].possibleOutput2;
6314 fragments["testfun"] = function;
6315 fragments["pre_main"] = constants.specialize(constantSpecialization);
6316 createTestsForAllStages(tests[idx].name, inputColors, expectedColors, fragments, testCtx);
6319 for(size_t idx = 0; idx < (sizeof(tests)/sizeof(tests[0])); ++idx) {
6320 map<string, string> fragments;
6321 map<string, string> constantSpecialization;
6322 vector<deInt32> passConstants;
6323 deInt32 specConstant;
6325 constantSpecialization["output1"] = tests[idx].possibleOutput1;
6326 constantSpecialization["output2"] = tests[idx].possibleOutput2;
6327 fragments["testfun"] = function;
6328 fragments["decoration"] = specDecorations;
6329 fragments["pre_main"] = specConstants.specialize(constantSpecialization);
6331 memcpy(&specConstant, &tests[idx].inputAsFloat, sizeof(float));
6332 passConstants.push_back(specConstant);
6334 createTestsForAllStages(string("spec_const_") + tests[idx].name, inputColors, expectedColors, fragments, passConstants, testCtx);
6338 tcu::TestCaseGroup* createOpQuantizeTests(tcu::TestContext& testCtx)
6340 de::MovePtr<tcu::TestCaseGroup> opQuantizeTests (new tcu::TestCaseGroup(testCtx, "opquantize", "Test OpQuantizeToF16"));
6341 createOpQuantizeSingleOptionTests(opQuantizeTests.get());
6342 createOpQuantizeTwoPossibilityTests(opQuantizeTests.get());
6343 return opQuantizeTests.release();
6346 struct ShaderPermutation
6348 deUint8 vertexPermutation;
6349 deUint8 geometryPermutation;
6350 deUint8 tesscPermutation;
6351 deUint8 tessePermutation;
6352 deUint8 fragmentPermutation;
6355 ShaderPermutation getShaderPermutation(deUint8 inputValue)
6357 ShaderPermutation permutation =
6359 static_cast<deUint8>(inputValue & 0x10? 1u: 0u),
6360 static_cast<deUint8>(inputValue & 0x08? 1u: 0u),
6361 static_cast<deUint8>(inputValue & 0x04? 1u: 0u),
6362 static_cast<deUint8>(inputValue & 0x02? 1u: 0u),
6363 static_cast<deUint8>(inputValue & 0x01? 1u: 0u)
6368 tcu::TestCaseGroup* createModuleTests(tcu::TestContext& testCtx)
6370 RGBA defaultColors[4];
6371 RGBA invertedColors[4];
6372 de::MovePtr<tcu::TestCaseGroup> moduleTests (new tcu::TestCaseGroup(testCtx, "module", "Multiple entry points into shaders"));
6374 const ShaderElement combinedPipeline[] =
6376 ShaderElement("module", "main", VK_SHADER_STAGE_VERTEX_BIT),
6377 ShaderElement("module", "main", VK_SHADER_STAGE_GEOMETRY_BIT),
6378 ShaderElement("module", "main", VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT),
6379 ShaderElement("module", "main", VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT),
6380 ShaderElement("module", "main", VK_SHADER_STAGE_FRAGMENT_BIT)
6383 getDefaultColors(defaultColors);
6384 getInvertedDefaultColors(invertedColors);
6385 addFunctionCaseWithPrograms<InstanceContext>(
6386 moduleTests.get(), "same_module", "", createCombinedModule, runAndVerifyDefaultPipeline,
6387 createInstanceContext(combinedPipeline, map<string, string>()));
6389 const char* numbers[] =
6394 for (deInt8 idx = 0; idx < 32; ++idx)
6396 ShaderPermutation permutation = getShaderPermutation(idx);
6397 string name = string("vert") + numbers[permutation.vertexPermutation] + "_geom" + numbers[permutation.geometryPermutation] + "_tessc" + numbers[permutation.tesscPermutation] + "_tesse" + numbers[permutation.tessePermutation] + "_frag" + numbers[permutation.fragmentPermutation];
6398 const ShaderElement pipeline[] =
6400 ShaderElement("vert", string("vert") + numbers[permutation.vertexPermutation], VK_SHADER_STAGE_VERTEX_BIT),
6401 ShaderElement("geom", string("geom") + numbers[permutation.geometryPermutation], VK_SHADER_STAGE_GEOMETRY_BIT),
6402 ShaderElement("tessc", string("tessc") + numbers[permutation.tesscPermutation], VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT),
6403 ShaderElement("tesse", string("tesse") + numbers[permutation.tessePermutation], VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT),
6404 ShaderElement("frag", string("frag") + numbers[permutation.fragmentPermutation], VK_SHADER_STAGE_FRAGMENT_BIT)
6407 // If there are an even number of swaps, then it should be no-op.
6408 // If there are an odd number, the color should be flipped.
6409 if ((permutation.vertexPermutation + permutation.geometryPermutation + permutation.tesscPermutation + permutation.tessePermutation + permutation.fragmentPermutation) % 2 == 0)
6411 addFunctionCaseWithPrograms<InstanceContext>(
6412 moduleTests.get(), name, "", createMultipleEntries, runAndVerifyDefaultPipeline,
6413 createInstanceContext(pipeline, defaultColors, defaultColors, map<string, string>()));
6417 addFunctionCaseWithPrograms<InstanceContext>(
6418 moduleTests.get(), name, "", createMultipleEntries, runAndVerifyDefaultPipeline,
6419 createInstanceContext(pipeline, defaultColors, invertedColors, map<string, string>()));
6422 return moduleTests.release();
6425 tcu::TestCaseGroup* createLoopTests(tcu::TestContext& testCtx)
6427 de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, "loop", "Looping control flow"));
6428 RGBA defaultColors[4];
6429 getDefaultColors(defaultColors);
6430 map<string, string> fragments;
6431 fragments["pre_main"] =
6432 "%c_f32_5 = OpConstant %f32 5.\n";
6434 // A loop with a single block. The Continue Target is the loop block
6435 // itself. In SPIR-V terms, the "loop construct" contains no blocks at all
6436 // -- the "continue construct" forms the entire loop.
6437 fragments["testfun"] =
6438 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6439 "%param1 = OpFunctionParameter %v4f32\n"
6441 "%entry = OpLabel\n"
6442 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
6445 ";adds and subtracts 1.0 to %val in alternate iterations\n"
6447 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %loop\n"
6448 "%delta = OpPhi %f32 %c_f32_1 %entry %minus_delta %loop\n"
6449 "%val1 = OpPhi %f32 %val0 %entry %val %loop\n"
6450 "%val = OpFAdd %f32 %val1 %delta\n"
6451 "%minus_delta = OpFSub %f32 %c_f32_0 %delta\n"
6452 "%count__ = OpISub %i32 %count %c_i32_1\n"
6453 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
6454 "OpLoopMerge %exit %loop None\n"
6455 "OpBranchConditional %again %loop %exit\n"
6458 "%result = OpVectorInsertDynamic %v4f32 %param1 %val %c_i32_0\n"
6459 "OpReturnValue %result\n"
6463 createTestsForAllStages("single_block", defaultColors, defaultColors, fragments, testGroup.get());
6465 // Body comprised of multiple basic blocks.
6466 const StringTemplate multiBlock(
6467 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6468 "%param1 = OpFunctionParameter %v4f32\n"
6470 "%entry = OpLabel\n"
6471 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
6474 ";adds and subtracts 1.0 to %val in alternate iterations\n"
6476 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %gather\n"
6477 "%delta = OpPhi %f32 %c_f32_1 %entry %delta_next %gather\n"
6478 "%val1 = OpPhi %f32 %val0 %entry %val %gather\n"
6479 // There are several possibilities for the Continue Target below. Each
6480 // will be specialized into a separate test case.
6481 "OpLoopMerge %exit ${continue_target} None\n"
6485 ";delta_next = (delta > 0) ? -1 : 1;\n"
6486 "%gt0 = OpFOrdGreaterThan %bool %delta %c_f32_0\n"
6487 "OpSelectionMerge %gather DontFlatten\n"
6488 "OpBranchConditional %gt0 %even %odd ;tells us if %count is even or odd\n"
6491 "OpBranch %gather\n"
6494 "OpBranch %gather\n"
6496 "%gather = OpLabel\n"
6497 "%delta_next = OpPhi %f32 %c_f32_n1 %even %c_f32_1 %odd\n"
6498 "%val = OpFAdd %f32 %val1 %delta\n"
6499 "%count__ = OpISub %i32 %count %c_i32_1\n"
6500 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
6501 "OpBranchConditional %again %loop %exit\n"
6504 "%result = OpVectorInsertDynamic %v4f32 %param1 %val %c_i32_0\n"
6505 "OpReturnValue %result\n"
6509 map<string, string> continue_target;
6511 // The Continue Target is the loop block itself.
6512 continue_target["continue_target"] = "%loop";
6513 fragments["testfun"] = multiBlock.specialize(continue_target);
6514 createTestsForAllStages("multi_block_continue_construct", defaultColors, defaultColors, fragments, testGroup.get());
6516 // The Continue Target is at the end of the loop.
6517 continue_target["continue_target"] = "%gather";
6518 fragments["testfun"] = multiBlock.specialize(continue_target);
6519 createTestsForAllStages("multi_block_loop_construct", defaultColors, defaultColors, fragments, testGroup.get());
6521 // A loop with continue statement.
6522 fragments["testfun"] =
6523 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6524 "%param1 = OpFunctionParameter %v4f32\n"
6526 "%entry = OpLabel\n"
6527 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
6530 ";adds 4, 3, and 1 to %val0 (skips 2)\n"
6532 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %continue\n"
6533 "%val1 = OpPhi %f32 %val0 %entry %val %continue\n"
6534 "OpLoopMerge %exit %continue None\n"
6538 ";skip if %count==2\n"
6539 "%eq2 = OpIEqual %bool %count %c_i32_2\n"
6540 "OpSelectionMerge %continue DontFlatten\n"
6541 "OpBranchConditional %eq2 %continue %body\n"
6544 "%fcount = OpConvertSToF %f32 %count\n"
6545 "%val2 = OpFAdd %f32 %val1 %fcount\n"
6546 "OpBranch %continue\n"
6548 "%continue = OpLabel\n"
6549 "%val = OpPhi %f32 %val2 %body %val1 %if\n"
6550 "%count__ = OpISub %i32 %count %c_i32_1\n"
6551 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
6552 "OpBranchConditional %again %loop %exit\n"
6555 "%same = OpFSub %f32 %val %c_f32_8\n"
6556 "%result = OpVectorInsertDynamic %v4f32 %param1 %same %c_i32_0\n"
6557 "OpReturnValue %result\n"
6559 createTestsForAllStages("continue", defaultColors, defaultColors, fragments, testGroup.get());
6561 // A loop with break.
6562 fragments["testfun"] =
6563 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6564 "%param1 = OpFunctionParameter %v4f32\n"
6566 "%entry = OpLabel\n"
6567 ";param1 components are between 0 and 1, so dot product is 4 or less\n"
6568 "%dot = OpDot %f32 %param1 %param1\n"
6569 "%div = OpFDiv %f32 %dot %c_f32_5\n"
6570 "%zero = OpConvertFToU %u32 %div\n"
6571 "%two = OpIAdd %i32 %zero %c_i32_2\n"
6572 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
6575 ";adds 4 and 3 to %val0 (exits early)\n"
6577 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %continue\n"
6578 "%val1 = OpPhi %f32 %val0 %entry %val2 %continue\n"
6579 "OpLoopMerge %exit %continue None\n"
6583 ";end loop if %count==%two\n"
6584 "%above2 = OpSGreaterThan %bool %count %two\n"
6585 "OpSelectionMerge %continue DontFlatten\n"
6586 "OpBranchConditional %above2 %body %exit\n"
6589 "%fcount = OpConvertSToF %f32 %count\n"
6590 "%val2 = OpFAdd %f32 %val1 %fcount\n"
6591 "OpBranch %continue\n"
6593 "%continue = OpLabel\n"
6594 "%count__ = OpISub %i32 %count %c_i32_1\n"
6595 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
6596 "OpBranchConditional %again %loop %exit\n"
6599 "%val_post = OpPhi %f32 %val2 %continue %val1 %if\n"
6600 "%same = OpFSub %f32 %val_post %c_f32_7\n"
6601 "%result = OpVectorInsertDynamic %v4f32 %param1 %same %c_i32_0\n"
6602 "OpReturnValue %result\n"
6604 createTestsForAllStages("break", defaultColors, defaultColors, fragments, testGroup.get());
6606 // A loop with return.
6607 fragments["testfun"] =
6608 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6609 "%param1 = OpFunctionParameter %v4f32\n"
6611 "%entry = OpLabel\n"
6612 ";param1 components are between 0 and 1, so dot product is 4 or less\n"
6613 "%dot = OpDot %f32 %param1 %param1\n"
6614 "%div = OpFDiv %f32 %dot %c_f32_5\n"
6615 "%zero = OpConvertFToU %u32 %div\n"
6616 "%two = OpIAdd %i32 %zero %c_i32_2\n"
6617 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
6620 ";returns early without modifying %param1\n"
6622 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %continue\n"
6623 "%val1 = OpPhi %f32 %val0 %entry %val2 %continue\n"
6624 "OpLoopMerge %exit %continue None\n"
6628 ";return if %count==%two\n"
6629 "%above2 = OpSGreaterThan %bool %count %two\n"
6630 "OpSelectionMerge %continue DontFlatten\n"
6631 "OpBranchConditional %above2 %body %early_exit\n"
6633 "%early_exit = OpLabel\n"
6634 "OpReturnValue %param1\n"
6637 "%fcount = OpConvertSToF %f32 %count\n"
6638 "%val2 = OpFAdd %f32 %val1 %fcount\n"
6639 "OpBranch %continue\n"
6641 "%continue = OpLabel\n"
6642 "%count__ = OpISub %i32 %count %c_i32_1\n"
6643 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
6644 "OpBranchConditional %again %loop %exit\n"
6647 ";should never get here, so return an incorrect result\n"
6648 "%result = OpVectorInsertDynamic %v4f32 %param1 %val2 %c_i32_0\n"
6649 "OpReturnValue %result\n"
6651 createTestsForAllStages("return", defaultColors, defaultColors, fragments, testGroup.get());
6653 return testGroup.release();
6656 // A collection of tests putting OpControlBarrier in places GLSL forbids but SPIR-V allows.
6657 tcu::TestCaseGroup* createBarrierTests(tcu::TestContext& testCtx)
6659 de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, "barrier", "OpControlBarrier"));
6660 map<string, string> fragments;
6662 // A barrier inside a function body.
6663 fragments["pre_main"] =
6664 "%Workgroup = OpConstant %i32 2\n"
6665 "%SequentiallyConsistent = OpConstant %i32 0x10\n";
6666 fragments["testfun"] =
6667 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6668 "%param1 = OpFunctionParameter %v4f32\n"
6669 "%label_testfun = OpLabel\n"
6670 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n"
6671 "OpReturnValue %param1\n"
6673 addTessCtrlTest(testGroup.get(), "in_function", fragments);
6675 // Common setup code for the following tests.
6676 fragments["pre_main"] =
6677 "%Workgroup = OpConstant %i32 2\n"
6678 "%SequentiallyConsistent = OpConstant %i32 0x10\n"
6679 "%c_f32_5 = OpConstant %f32 5.\n";
6680 const string setupPercentZero = // Begins %test_code function with code that sets %zero to 0u but cannot be optimized away.
6681 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6682 "%param1 = OpFunctionParameter %v4f32\n"
6683 "%entry = OpLabel\n"
6684 ";param1 components are between 0 and 1, so dot product is 4 or less\n"
6685 "%dot = OpDot %f32 %param1 %param1\n"
6686 "%div = OpFDiv %f32 %dot %c_f32_5\n"
6687 "%zero = OpConvertFToU %u32 %div\n";
6689 // Barriers inside OpSwitch branches.
6690 fragments["testfun"] =
6692 "OpSelectionMerge %switch_exit None\n"
6693 "OpSwitch %zero %switch_default 0 %case0 1 %case1 ;should always go to %case0\n"
6695 "%case1 = OpLabel\n"
6696 ";This barrier should never be executed, but its presence makes test failure more likely when there's a bug.\n"
6697 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n"
6698 "%wrong_branch_alert1 = OpVectorInsertDynamic %v4f32 %param1 %c_f32_0_5 %c_i32_0\n"
6699 "OpBranch %switch_exit\n"
6701 "%switch_default = OpLabel\n"
6702 "%wrong_branch_alert2 = OpVectorInsertDynamic %v4f32 %param1 %c_f32_0_5 %c_i32_0\n"
6703 ";This barrier should never be executed, but its presence makes test failure more likely when there's a bug.\n"
6704 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n"
6705 "OpBranch %switch_exit\n"
6707 "%case0 = OpLabel\n"
6708 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n"
6709 "OpBranch %switch_exit\n"
6711 "%switch_exit = OpLabel\n"
6712 "%ret = OpPhi %v4f32 %param1 %case0 %wrong_branch_alert1 %case1 %wrong_branch_alert2 %switch_default\n"
6713 "OpReturnValue %ret\n"
6715 addTessCtrlTest(testGroup.get(), "in_switch", fragments);
6717 // Barriers inside if-then-else.
6718 fragments["testfun"] =
6720 "%eq0 = OpIEqual %bool %zero %c_u32_0\n"
6721 "OpSelectionMerge %exit DontFlatten\n"
6722 "OpBranchConditional %eq0 %then %else\n"
6725 ";This barrier should never be executed, but its presence makes test failure more likely when there's a bug.\n"
6726 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n"
6727 "%wrong_branch_alert = OpVectorInsertDynamic %v4f32 %param1 %c_f32_0_5 %c_i32_0\n"
6731 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n"
6735 "%ret = OpPhi %v4f32 %param1 %then %wrong_branch_alert %else\n"
6736 "OpReturnValue %ret\n"
6738 addTessCtrlTest(testGroup.get(), "in_if", fragments);
6740 // A barrier after control-flow reconvergence, tempting the compiler to attempt something like this:
6741 // http://lists.llvm.org/pipermail/llvm-dev/2009-October/026317.html.
6742 fragments["testfun"] =
6744 "%thread_id = OpLoad %i32 %BP_gl_InvocationID\n"
6745 "%thread0 = OpIEqual %bool %thread_id %c_i32_0\n"
6746 "OpSelectionMerge %exit DontFlatten\n"
6747 "OpBranchConditional %thread0 %then %else\n"
6750 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
6754 "%val1 = OpVectorExtractDynamic %f32 %param1 %zero\n"
6758 "%val = OpPhi %f32 %val0 %else %val1 %then\n"
6759 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n"
6760 "%ret = OpVectorInsertDynamic %v4f32 %param1 %val %zero\n"
6761 "OpReturnValue %ret\n"
6763 addTessCtrlTest(testGroup.get(), "after_divergent_if", fragments);
6765 // A barrier inside a loop.
6766 fragments["pre_main"] =
6767 "%Workgroup = OpConstant %i32 2\n"
6768 "%SequentiallyConsistent = OpConstant %i32 0x10\n"
6769 "%c_f32_10 = OpConstant %f32 10.\n";
6770 fragments["testfun"] =
6771 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6772 "%param1 = OpFunctionParameter %v4f32\n"
6773 "%entry = OpLabel\n"
6774 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
6777 ";adds 4, 3, 2, and 1 to %val0\n"
6779 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %loop\n"
6780 "%val1 = OpPhi %f32 %val0 %entry %val %loop\n"
6781 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n"
6782 "%fcount = OpConvertSToF %f32 %count\n"
6783 "%val = OpFAdd %f32 %val1 %fcount\n"
6784 "%count__ = OpISub %i32 %count %c_i32_1\n"
6785 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
6786 "OpLoopMerge %exit %loop None\n"
6787 "OpBranchConditional %again %loop %exit\n"
6790 "%same = OpFSub %f32 %val %c_f32_10\n"
6791 "%ret = OpVectorInsertDynamic %v4f32 %param1 %same %c_i32_0\n"
6792 "OpReturnValue %ret\n"
6794 addTessCtrlTest(testGroup.get(), "in_loop", fragments);
6796 return testGroup.release();
6799 // Test for the OpFRem instruction.
6800 tcu::TestCaseGroup* createFRemTests(tcu::TestContext& testCtx)
6802 de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, "frem", "OpFRem"));
6803 map<string, string> fragments;
6804 RGBA inputColors[4];
6805 RGBA outputColors[4];
6807 fragments["pre_main"] =
6808 "%c_f32_3 = OpConstant %f32 3.0\n"
6809 "%c_f32_n3 = OpConstant %f32 -3.0\n"
6810 "%c_f32_4 = OpConstant %f32 4.0\n"
6811 "%c_f32_p75 = OpConstant %f32 0.75\n"
6812 "%c_v4f32_p75_p75_p75_p75 = OpConstantComposite %v4f32 %c_f32_p75 %c_f32_p75 %c_f32_p75 %c_f32_p75 \n"
6813 "%c_v4f32_4_4_4_4 = OpConstantComposite %v4f32 %c_f32_4 %c_f32_4 %c_f32_4 %c_f32_4\n"
6814 "%c_v4f32_3_n3_3_n3 = OpConstantComposite %v4f32 %c_f32_3 %c_f32_n3 %c_f32_3 %c_f32_n3\n";
6816 // The test does the following.
6817 // vec4 result = (param1 * 8.0) - 4.0;
6818 // return (frem(result.x,3) + 0.75, frem(result.y, -3) + 0.75, 0, 1)
6819 fragments["testfun"] =
6820 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6821 "%param1 = OpFunctionParameter %v4f32\n"
6822 "%label_testfun = OpLabel\n"
6823 "%v_times_8 = OpVectorTimesScalar %v4f32 %param1 %c_f32_8\n"
6824 "%minus_4 = OpFSub %v4f32 %v_times_8 %c_v4f32_4_4_4_4\n"
6825 "%frem = OpFRem %v4f32 %minus_4 %c_v4f32_3_n3_3_n3\n"
6826 "%added = OpFAdd %v4f32 %frem %c_v4f32_p75_p75_p75_p75\n"
6827 "%xyz_1 = OpVectorInsertDynamic %v4f32 %added %c_f32_1 %c_i32_3\n"
6828 "%xy_0_1 = OpVectorInsertDynamic %v4f32 %xyz_1 %c_f32_0 %c_i32_2\n"
6829 "OpReturnValue %xy_0_1\n"
6833 inputColors[0] = RGBA(16, 16, 0, 255);
6834 inputColors[1] = RGBA(232, 232, 0, 255);
6835 inputColors[2] = RGBA(232, 16, 0, 255);
6836 inputColors[3] = RGBA(16, 232, 0, 255);
6838 outputColors[0] = RGBA(64, 64, 0, 255);
6839 outputColors[1] = RGBA(255, 255, 0, 255);
6840 outputColors[2] = RGBA(255, 64, 0, 255);
6841 outputColors[3] = RGBA(64, 255, 0, 255);
6843 createTestsForAllStages("frem", inputColors, outputColors, fragments, testGroup.get());
6844 return testGroup.release();
6847 // Test for the OpSRem instruction.
6848 tcu::TestCaseGroup* createOpSRemGraphicsTests(tcu::TestContext& testCtx, qpTestResult negFailResult)
6850 de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, "srem", "OpSRem"));
6851 map<string, string> fragments;
6853 fragments["pre_main"] =
6854 "%c_f32_255 = OpConstant %f32 255.0\n"
6855 "%c_i32_128 = OpConstant %i32 128\n"
6856 "%c_i32_255 = OpConstant %i32 255\n"
6857 "%c_v4f32_255 = OpConstantComposite %v4f32 %c_f32_255 %c_f32_255 %c_f32_255 %c_f32_255 \n"
6858 "%c_v4f32_0_5 = OpConstantComposite %v4f32 %c_f32_0_5 %c_f32_0_5 %c_f32_0_5 %c_f32_0_5 \n"
6859 "%c_v4i32_128 = OpConstantComposite %v4i32 %c_i32_128 %c_i32_128 %c_i32_128 %c_i32_128 \n";
6861 // The test does the following.
6862 // ivec4 ints = int(param1 * 255.0 + 0.5) - 128;
6863 // ivec4 result = ivec4(srem(ints.x, ints.y), srem(ints.y, ints.z), srem(ints.z, ints.x), 255);
6864 // return float(result + 128) / 255.0;
6865 fragments["testfun"] =
6866 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6867 "%param1 = OpFunctionParameter %v4f32\n"
6868 "%label_testfun = OpLabel\n"
6869 "%div255 = OpFMul %v4f32 %param1 %c_v4f32_255\n"
6870 "%add0_5 = OpFAdd %v4f32 %div255 %c_v4f32_0_5\n"
6871 "%uints_in = OpConvertFToS %v4i32 %add0_5\n"
6872 "%ints_in = OpISub %v4i32 %uints_in %c_v4i32_128\n"
6873 "%x_in = OpCompositeExtract %i32 %ints_in 0\n"
6874 "%y_in = OpCompositeExtract %i32 %ints_in 1\n"
6875 "%z_in = OpCompositeExtract %i32 %ints_in 2\n"
6876 "%x_out = OpSRem %i32 %x_in %y_in\n"
6877 "%y_out = OpSRem %i32 %y_in %z_in\n"
6878 "%z_out = OpSRem %i32 %z_in %x_in\n"
6879 "%ints_out = OpCompositeConstruct %v4i32 %x_out %y_out %z_out %c_i32_255\n"
6880 "%ints_offset = OpIAdd %v4i32 %ints_out %c_v4i32_128\n"
6881 "%f_ints_offset = OpConvertSToF %v4f32 %ints_offset\n"
6882 "%float_out = OpFDiv %v4f32 %f_ints_offset %c_v4f32_255\n"
6883 "OpReturnValue %float_out\n"
6886 const struct CaseParams
6889 const char* failMessageTemplate; // customized status message
6890 qpTestResult failResult; // override status on failure
6891 int operands[4][3]; // four (x, y, z) vectors of operands
6892 int results[4][3]; // four (x, y, z) vectors of results
6898 QP_TEST_RESULT_FAIL,
6899 { { 5, 12, 17 }, { 5, 5, 7 }, { 75, 8, 81 }, { 25, 60, 100 } }, // operands
6900 { { 5, 12, 2 }, { 0, 5, 2 }, { 3, 8, 6 }, { 25, 60, 0 } }, // results
6904 "Inconsistent results, but within specification: ${reason}",
6905 negFailResult, // negative operands, not required by the spec
6906 { { 5, 12, -17 }, { -5, -5, 7 }, { 75, 8, -81 }, { 25, -60, 100 } }, // operands
6907 { { 5, 12, -2 }, { 0, -5, 2 }, { 3, 8, -6 }, { 25, -60, 0 } }, // results
6910 // If either operand is negative the result is undefined. Some implementations may still return correct values.
6912 for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(cases); ++caseNdx)
6914 const CaseParams& params = cases[caseNdx];
6915 RGBA inputColors[4];
6916 RGBA outputColors[4];
6918 for (int i = 0; i < 4; ++i)
6920 inputColors [i] = RGBA(params.operands[i][0] + 128, params.operands[i][1] + 128, params.operands[i][2] + 128, 255);
6921 outputColors[i] = RGBA(params.results [i][0] + 128, params.results [i][1] + 128, params.results [i][2] + 128, 255);
6924 createTestsForAllStages(params.name, inputColors, outputColors, fragments, testGroup.get(), params.failResult, params.failMessageTemplate);
6927 return testGroup.release();
6930 // Test for the OpSMod instruction.
6931 tcu::TestCaseGroup* createOpSModGraphicsTests(tcu::TestContext& testCtx, qpTestResult negFailResult)
6933 de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, "smod", "OpSMod"));
6934 map<string, string> fragments;
6936 fragments["pre_main"] =
6937 "%c_f32_255 = OpConstant %f32 255.0\n"
6938 "%c_i32_128 = OpConstant %i32 128\n"
6939 "%c_i32_255 = OpConstant %i32 255\n"
6940 "%c_v4f32_255 = OpConstantComposite %v4f32 %c_f32_255 %c_f32_255 %c_f32_255 %c_f32_255 \n"
6941 "%c_v4f32_0_5 = OpConstantComposite %v4f32 %c_f32_0_5 %c_f32_0_5 %c_f32_0_5 %c_f32_0_5 \n"
6942 "%c_v4i32_128 = OpConstantComposite %v4i32 %c_i32_128 %c_i32_128 %c_i32_128 %c_i32_128 \n";
6944 // The test does the following.
6945 // ivec4 ints = int(param1 * 255.0 + 0.5) - 128;
6946 // ivec4 result = ivec4(smod(ints.x, ints.y), smod(ints.y, ints.z), smod(ints.z, ints.x), 255);
6947 // return float(result + 128) / 255.0;
6948 fragments["testfun"] =
6949 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6950 "%param1 = OpFunctionParameter %v4f32\n"
6951 "%label_testfun = OpLabel\n"
6952 "%div255 = OpFMul %v4f32 %param1 %c_v4f32_255\n"
6953 "%add0_5 = OpFAdd %v4f32 %div255 %c_v4f32_0_5\n"
6954 "%uints_in = OpConvertFToS %v4i32 %add0_5\n"
6955 "%ints_in = OpISub %v4i32 %uints_in %c_v4i32_128\n"
6956 "%x_in = OpCompositeExtract %i32 %ints_in 0\n"
6957 "%y_in = OpCompositeExtract %i32 %ints_in 1\n"
6958 "%z_in = OpCompositeExtract %i32 %ints_in 2\n"
6959 "%x_out = OpSMod %i32 %x_in %y_in\n"
6960 "%y_out = OpSMod %i32 %y_in %z_in\n"
6961 "%z_out = OpSMod %i32 %z_in %x_in\n"
6962 "%ints_out = OpCompositeConstruct %v4i32 %x_out %y_out %z_out %c_i32_255\n"
6963 "%ints_offset = OpIAdd %v4i32 %ints_out %c_v4i32_128\n"
6964 "%f_ints_offset = OpConvertSToF %v4f32 %ints_offset\n"
6965 "%float_out = OpFDiv %v4f32 %f_ints_offset %c_v4f32_255\n"
6966 "OpReturnValue %float_out\n"
6969 const struct CaseParams
6972 const char* failMessageTemplate; // customized status message
6973 qpTestResult failResult; // override status on failure
6974 int operands[4][3]; // four (x, y, z) vectors of operands
6975 int results[4][3]; // four (x, y, z) vectors of results
6981 QP_TEST_RESULT_FAIL,
6982 { { 5, 12, 17 }, { 5, 5, 7 }, { 75, 8, 81 }, { 25, 60, 100 } }, // operands
6983 { { 5, 12, 2 }, { 0, 5, 2 }, { 3, 8, 6 }, { 25, 60, 0 } }, // results
6987 "Inconsistent results, but within specification: ${reason}",
6988 negFailResult, // negative operands, not required by the spec
6989 { { 5, 12, -17 }, { -5, -5, 7 }, { 75, 8, -81 }, { 25, -60, 100 } }, // operands
6990 { { 5, -5, 3 }, { 0, 2, -3 }, { 3, -73, 69 }, { -35, 40, 0 } }, // results
6993 // If either operand is negative the result is undefined. Some implementations may still return correct values.
6995 for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(cases); ++caseNdx)
6997 const CaseParams& params = cases[caseNdx];
6998 RGBA inputColors[4];
6999 RGBA outputColors[4];
7001 for (int i = 0; i < 4; ++i)
7003 inputColors [i] = RGBA(params.operands[i][0] + 128, params.operands[i][1] + 128, params.operands[i][2] + 128, 255);
7004 outputColors[i] = RGBA(params.results [i][0] + 128, params.results [i][1] + 128, params.results [i][2] + 128, 255);
7007 createTestsForAllStages(params.name, inputColors, outputColors, fragments, testGroup.get(), params.failResult, params.failMessageTemplate);
7009 return testGroup.release();
7015 INTEGER_TYPE_SIGNED_16,
7016 INTEGER_TYPE_SIGNED_32,
7017 INTEGER_TYPE_SIGNED_64,
7019 INTEGER_TYPE_UNSIGNED_16,
7020 INTEGER_TYPE_UNSIGNED_32,
7021 INTEGER_TYPE_UNSIGNED_64,
7024 const string getBitWidthStr (IntegerType type)
7028 case INTEGER_TYPE_SIGNED_16:
7029 case INTEGER_TYPE_UNSIGNED_16: return "16";
7031 case INTEGER_TYPE_SIGNED_32:
7032 case INTEGER_TYPE_UNSIGNED_32: return "32";
7034 case INTEGER_TYPE_SIGNED_64:
7035 case INTEGER_TYPE_UNSIGNED_64: return "64";
7037 default: DE_ASSERT(false);
7042 const string getByteWidthStr (IntegerType type)
7046 case INTEGER_TYPE_SIGNED_16:
7047 case INTEGER_TYPE_UNSIGNED_16: return "2";
7049 case INTEGER_TYPE_SIGNED_32:
7050 case INTEGER_TYPE_UNSIGNED_32: return "4";
7052 case INTEGER_TYPE_SIGNED_64:
7053 case INTEGER_TYPE_UNSIGNED_64: return "8";
7055 default: DE_ASSERT(false);
7060 bool isSigned (IntegerType type)
7062 return (type <= INTEGER_TYPE_SIGNED_64);
7065 const string getTypeName (IntegerType type)
7067 string prefix = isSigned(type) ? "" : "u";
7068 return prefix + "int" + getBitWidthStr(type);
7071 const string getTestName (IntegerType from, IntegerType to)
7073 return getTypeName(from) + "_to_" + getTypeName(to);
7076 const string getAsmTypeDeclaration (IntegerType type)
7078 string sign = isSigned(type) ? " 1" : " 0";
7079 return "OpTypeInt " + getBitWidthStr(type) + sign;
7082 template<typename T>
7083 BufferSp getSpecializedBuffer (deInt64 number)
7085 return BufferSp(new Buffer<T>(vector<T>(1, (T)number)));
7088 BufferSp getBuffer (IntegerType type, deInt64 number)
7092 case INTEGER_TYPE_SIGNED_16: return getSpecializedBuffer<deInt16>(number);
7093 case INTEGER_TYPE_SIGNED_32: return getSpecializedBuffer<deInt32>(number);
7094 case INTEGER_TYPE_SIGNED_64: return getSpecializedBuffer<deInt64>(number);
7096 case INTEGER_TYPE_UNSIGNED_16: return getSpecializedBuffer<deUint16>(number);
7097 case INTEGER_TYPE_UNSIGNED_32: return getSpecializedBuffer<deUint32>(number);
7098 case INTEGER_TYPE_UNSIGNED_64: return getSpecializedBuffer<deUint64>(number);
7100 default: DE_ASSERT(false);
7101 return BufferSp(new Buffer<deInt32>(vector<deInt32>(1, 0)));
7105 bool usesInt16 (IntegerType from, IntegerType to)
7107 return (from == INTEGER_TYPE_SIGNED_16 || from == INTEGER_TYPE_UNSIGNED_16
7108 || to == INTEGER_TYPE_SIGNED_16 || to == INTEGER_TYPE_UNSIGNED_16);
7111 bool usesInt64 (IntegerType from, IntegerType to)
7113 return (from == INTEGER_TYPE_SIGNED_64 || from == INTEGER_TYPE_UNSIGNED_64
7114 || to == INTEGER_TYPE_SIGNED_64 || to == INTEGER_TYPE_UNSIGNED_64);
7117 ComputeTestFeatures getConversionUsedFeatures (IntegerType from, IntegerType to)
7119 if (usesInt16(from, to))
7121 if (usesInt64(from, to))
7123 return COMPUTE_TEST_USES_INT16_INT64;
7127 return COMPUTE_TEST_USES_INT16;
7132 return COMPUTE_TEST_USES_INT64;
7138 ConvertCase (IntegerType from, IntegerType to, deInt64 number)
7141 , m_features (getConversionUsedFeatures(from, to))
7142 , m_name (getTestName(from, to))
7143 , m_inputBuffer (getBuffer(from, number))
7144 , m_outputBuffer (getBuffer(to, number))
7146 m_asmTypes["inputType"] = getAsmTypeDeclaration(from);
7147 m_asmTypes["outputType"] = getAsmTypeDeclaration(to);
7149 if (m_features == COMPUTE_TEST_USES_INT16)
7151 m_asmTypes["int_capabilities"] = "OpCapability Int16\n"
7152 "OpCapability StorageUniformBufferBlock16\n";
7153 m_asmTypes["int_extensions"] = "OpExtension \"SPV_KHR_16bit_storage\"\n";
7155 else if (m_features == COMPUTE_TEST_USES_INT64)
7157 m_asmTypes["int_capabilities"] = "OpCapability Int64\n";
7158 m_asmTypes["int_extensions"] = "";
7160 else if (m_features == COMPUTE_TEST_USES_INT16_INT64)
7162 m_asmTypes["int_capabilities"] = "OpCapability Int16\n"
7163 "OpCapability StorageUniformBufferBlock16\n"
7164 "OpCapability Int64\n";
7165 m_asmTypes["int_extensions"] = "OpExtension \"SPV_KHR_16bit_storage\"\n";
7173 IntegerType m_fromType;
7174 IntegerType m_toType;
7175 ComputeTestFeatures m_features;
7177 map<string, string> m_asmTypes;
7178 BufferSp m_inputBuffer;
7179 BufferSp m_outputBuffer;
7182 const string getConvertCaseShaderStr (const string& instruction, const ConvertCase& convertCase)
7184 map<string, string> params = convertCase.m_asmTypes;
7186 params["instruction"] = instruction;
7188 params["inDecorator"] = getByteWidthStr(convertCase.m_fromType);
7189 params["outDecorator"] = getByteWidthStr(convertCase.m_toType);
7191 const StringTemplate shader (
7192 "OpCapability Shader\n"
7193 "${int_capabilities}"
7195 "OpMemoryModel Logical GLSL450\n"
7196 "OpEntryPoint GLCompute %main \"main\" %id\n"
7197 "OpExecutionMode %main LocalSize 1 1 1\n"
7198 "OpSource GLSL 430\n"
7199 "OpName %main \"main\"\n"
7200 "OpName %id \"gl_GlobalInvocationID\"\n"
7202 "OpDecorate %id BuiltIn GlobalInvocationId\n"
7203 "OpDecorate %indata DescriptorSet 0\n"
7204 "OpDecorate %indata Binding 0\n"
7205 "OpDecorate %outdata DescriptorSet 0\n"
7206 "OpDecorate %outdata Binding 1\n"
7207 "OpDecorate %in_arr ArrayStride ${inDecorator}\n"
7208 "OpDecorate %out_arr ArrayStride ${outDecorator}\n"
7209 "OpDecorate %in_buf BufferBlock\n"
7210 "OpDecorate %out_buf BufferBlock\n"
7211 "OpMemberDecorate %in_buf 0 Offset 0\n"
7212 "OpMemberDecorate %out_buf 0 Offset 0\n"
7214 "%void = OpTypeVoid\n"
7215 "%voidf = OpTypeFunction %void\n"
7216 "%u32 = OpTypeInt 32 0\n"
7217 "%i32 = OpTypeInt 32 1\n"
7218 "%uvec3 = OpTypeVector %u32 3\n"
7219 "%uvec3ptr = OpTypePointer Input %uvec3\n"
7221 "%in_type = ${inputType}\n"
7222 "%out_type = ${outputType}\n"
7224 "%in_ptr = OpTypePointer Uniform %in_type\n"
7225 "%out_ptr = OpTypePointer Uniform %out_type\n"
7226 "%in_arr = OpTypeRuntimeArray %in_type\n"
7227 "%out_arr = OpTypeRuntimeArray %out_type\n"
7228 "%in_buf = OpTypeStruct %in_arr\n"
7229 "%out_buf = OpTypeStruct %out_arr\n"
7230 "%in_bufptr = OpTypePointer Uniform %in_buf\n"
7231 "%out_bufptr = OpTypePointer Uniform %out_buf\n"
7232 "%indata = OpVariable %in_bufptr Uniform\n"
7233 "%outdata = OpVariable %out_bufptr Uniform\n"
7234 "%inputptr = OpTypePointer Input %in_type\n"
7235 "%id = OpVariable %uvec3ptr Input\n"
7237 "%zero = OpConstant %i32 0\n"
7239 "%main = OpFunction %void None %voidf\n"
7240 "%label = OpLabel\n"
7241 "%idval = OpLoad %uvec3 %id\n"
7242 "%x = OpCompositeExtract %u32 %idval 0\n"
7243 "%inloc = OpAccessChain %in_ptr %indata %zero %x\n"
7244 "%outloc = OpAccessChain %out_ptr %outdata %zero %x\n"
7245 "%inval = OpLoad %in_type %inloc\n"
7246 "%conv = ${instruction} %out_type %inval\n"
7247 " OpStore %outloc %conv\n"
7252 return shader.specialize(params);
7255 void createSConvertCases (vector<ConvertCase>& testCases)
7257 // Convert int to int
7258 testCases.push_back(ConvertCase(INTEGER_TYPE_SIGNED_16, INTEGER_TYPE_SIGNED_32, 14669));
7259 testCases.push_back(ConvertCase(INTEGER_TYPE_SIGNED_16, INTEGER_TYPE_SIGNED_64, 3341));
7261 testCases.push_back(ConvertCase(INTEGER_TYPE_SIGNED_32, INTEGER_TYPE_SIGNED_64, 973610259));
7263 // Convert int to unsigned int
7264 testCases.push_back(ConvertCase(INTEGER_TYPE_SIGNED_16, INTEGER_TYPE_UNSIGNED_32, 9288));
7265 testCases.push_back(ConvertCase(INTEGER_TYPE_SIGNED_16, INTEGER_TYPE_UNSIGNED_64, 15460));
7267 testCases.push_back(ConvertCase(INTEGER_TYPE_SIGNED_32, INTEGER_TYPE_UNSIGNED_64, 346213461));
7270 // Test for the OpSConvert instruction.
7271 tcu::TestCaseGroup* createSConvertTests (tcu::TestContext& testCtx)
7273 const string instruction ("OpSConvert");
7274 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "sconvert", "OpSConvert"));
7275 vector<ConvertCase> testCases;
7276 createSConvertCases(testCases);
7278 for (vector<ConvertCase>::const_iterator test = testCases.begin(); test != testCases.end(); ++test)
7280 ComputeShaderSpec spec;
7282 spec.assembly = getConvertCaseShaderStr(instruction, *test);
7283 spec.inputs.push_back(test->m_inputBuffer);
7284 spec.outputs.push_back(test->m_outputBuffer);
7285 spec.numWorkGroups = IVec3(1, 1, 1);
7287 if (test->m_features == COMPUTE_TEST_USES_INT16 || test->m_features == COMPUTE_TEST_USES_INT16_INT64)
7289 spec.extensions.push_back("VK_KHR_16bit_storage");
7290 spec.requestedVulkanFeatures.ext16BitStorage = EXT16BITSTORAGEFEATURES_UNIFORM_BUFFER_BLOCK;
7293 group->addChild(new SpvAsmComputeShaderCase(testCtx, test->m_name.c_str(), "Convert integers with OpSConvert.", spec, test->m_features));
7296 return group.release();
7299 void createUConvertCases (vector<ConvertCase>& testCases)
7301 // Convert unsigned int to unsigned int
7302 testCases.push_back(ConvertCase(INTEGER_TYPE_UNSIGNED_16, INTEGER_TYPE_UNSIGNED_32, 60653));
7303 testCases.push_back(ConvertCase(INTEGER_TYPE_UNSIGNED_16, INTEGER_TYPE_UNSIGNED_64, 17991));
7305 testCases.push_back(ConvertCase(INTEGER_TYPE_UNSIGNED_32, INTEGER_TYPE_UNSIGNED_64, 904256275));
7308 // Test for the OpUConvert instruction.
7309 tcu::TestCaseGroup* createUConvertTests (tcu::TestContext& testCtx)
7311 const string instruction ("OpUConvert");
7312 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "uconvert", "OpUConvert"));
7313 vector<ConvertCase> testCases;
7314 createUConvertCases(testCases);
7316 for (vector<ConvertCase>::const_iterator test = testCases.begin(); test != testCases.end(); ++test)
7318 ComputeShaderSpec spec;
7320 spec.assembly = getConvertCaseShaderStr(instruction, *test);
7321 spec.inputs.push_back(test->m_inputBuffer);
7322 spec.outputs.push_back(test->m_outputBuffer);
7323 spec.numWorkGroups = IVec3(1, 1, 1);
7325 if (test->m_features == COMPUTE_TEST_USES_INT16 || test->m_features == COMPUTE_TEST_USES_INT16_INT64)
7327 spec.extensions.push_back("VK_KHR_16bit_storage");
7328 spec.requestedVulkanFeatures.ext16BitStorage = EXT16BITSTORAGEFEATURES_UNIFORM_BUFFER_BLOCK;
7331 group->addChild(new SpvAsmComputeShaderCase(testCtx, test->m_name.c_str(), "Convert integers with OpUConvert.", spec, test->m_features));
7333 return group.release();
7336 const string getNumberTypeName (const NumberType type)
7338 if (type == NUMBERTYPE_INT32)
7342 else if (type == NUMBERTYPE_UINT32)
7346 else if (type == NUMBERTYPE_FLOAT32)
7357 deInt32 getInt(de::Random& rnd)
7359 return rnd.getInt(std::numeric_limits<int>::min(), std::numeric_limits<int>::max());
7362 const string repeatString (const string& str, int times)
7365 for (int i = 0; i < times; ++i)
7372 const string getRandomConstantString (const NumberType type, de::Random& rnd)
7374 if (type == NUMBERTYPE_INT32)
7376 return numberToString<deInt32>(getInt(rnd));
7378 else if (type == NUMBERTYPE_UINT32)
7380 return numberToString<deUint32>(rnd.getUint32());
7382 else if (type == NUMBERTYPE_FLOAT32)
7384 return numberToString<float>(rnd.getFloat());
7393 void createVectorCompositeCases (vector<map<string, string> >& testCases, de::Random& rnd, const NumberType type)
7395 map<string, string> params;
7398 for (int width = 2; width <= 4; ++width)
7400 string randomConst = numberToString(getInt(rnd));
7401 string widthStr = numberToString(width);
7402 int index = rnd.getInt(0, width-1);
7404 params["type"] = "vec";
7405 params["name"] = params["type"] + "_" + widthStr;
7406 params["compositeType"] = "%composite = OpTypeVector %custom " + widthStr +"\n";
7407 params["filler"] = string("%filler = OpConstant %custom ") + getRandomConstantString(type, rnd) + "\n";
7408 params["compositeConstruct"] = "%instance = OpCompositeConstruct %composite" + repeatString(" %filler", width) + "\n";
7409 params["indexes"] = numberToString(index);
7410 testCases.push_back(params);
7414 void createArrayCompositeCases (vector<map<string, string> >& testCases, de::Random& rnd, const NumberType type)
7416 const int limit = 10;
7417 map<string, string> params;
7419 for (int width = 2; width <= limit; ++width)
7421 string randomConst = numberToString(getInt(rnd));
7422 string widthStr = numberToString(width);
7423 int index = rnd.getInt(0, width-1);
7425 params["type"] = "array";
7426 params["name"] = params["type"] + "_" + widthStr;
7427 params["compositeType"] = string("%arraywidth = OpConstant %u32 " + widthStr + "\n")
7428 + "%composite = OpTypeArray %custom %arraywidth\n";
7430 params["filler"] = string("%filler = OpConstant %custom ") + getRandomConstantString(type, rnd) + "\n";
7431 params["compositeConstruct"] = "%instance = OpCompositeConstruct %composite" + repeatString(" %filler", width) + "\n";
7432 params["indexes"] = numberToString(index);
7433 testCases.push_back(params);
7437 void createStructCompositeCases (vector<map<string, string> >& testCases, de::Random& rnd, const NumberType type)
7439 const int limit = 10;
7440 map<string, string> params;
7442 for (int width = 2; width <= limit; ++width)
7444 string randomConst = numberToString(getInt(rnd));
7445 int index = rnd.getInt(0, width-1);
7447 params["type"] = "struct";
7448 params["name"] = params["type"] + "_" + numberToString(width);
7449 params["compositeType"] = "%composite = OpTypeStruct" + repeatString(" %custom", width) + "\n";
7450 params["filler"] = string("%filler = OpConstant %custom ") + getRandomConstantString(type, rnd) + "\n";
7451 params["compositeConstruct"] = "%instance = OpCompositeConstruct %composite" + repeatString(" %filler", width) + "\n";
7452 params["indexes"] = numberToString(index);
7453 testCases.push_back(params);
7457 void createMatrixCompositeCases (vector<map<string, string> >& testCases, de::Random& rnd, const NumberType type)
7459 map<string, string> params;
7462 for (int width = 2; width <= 4; ++width)
7464 string widthStr = numberToString(width);
7466 for (int column = 2 ; column <= 4; ++column)
7468 int index_0 = rnd.getInt(0, column-1);
7469 int index_1 = rnd.getInt(0, width-1);
7470 string columnStr = numberToString(column);
7472 params["type"] = "matrix";
7473 params["name"] = params["type"] + "_" + widthStr + "x" + columnStr;
7474 params["compositeType"] = string("%vectype = OpTypeVector %custom " + widthStr + "\n")
7475 + "%composite = OpTypeMatrix %vectype " + columnStr + "\n";
7477 params["filler"] = string("%filler = OpConstant %custom ") + getRandomConstantString(type, rnd) + "\n"
7478 + "%fillerVec = OpConstantComposite %vectype" + repeatString(" %filler", width) + "\n";
7480 params["compositeConstruct"] = "%instance = OpCompositeConstruct %composite" + repeatString(" %fillerVec", column) + "\n";
7481 params["indexes"] = numberToString(index_0) + " " + numberToString(index_1);
7482 testCases.push_back(params);
7487 void createCompositeCases (vector<map<string, string> >& testCases, de::Random& rnd, const NumberType type)
7489 createVectorCompositeCases(testCases, rnd, type);
7490 createArrayCompositeCases(testCases, rnd, type);
7491 createStructCompositeCases(testCases, rnd, type);
7492 // Matrix only supports float types
7493 if (type == NUMBERTYPE_FLOAT32)
7495 createMatrixCompositeCases(testCases, rnd, type);
7499 const string getAssemblyTypeDeclaration (const NumberType type)
7503 case NUMBERTYPE_INT32: return "OpTypeInt 32 1";
7504 case NUMBERTYPE_UINT32: return "OpTypeInt 32 0";
7505 case NUMBERTYPE_FLOAT32: return "OpTypeFloat 32";
7506 default: DE_ASSERT(false); return "";
7510 const string specializeCompositeInsertShaderTemplate (const NumberType type, const map<string, string>& params)
7512 map<string, string> parameters(params);
7514 parameters["typeDeclaration"] = getAssemblyTypeDeclaration(type);
7516 parameters["compositeDecorator"] = (parameters["type"] == "array") ? "OpDecorate %composite ArrayStride 4\n" : "";
7518 return StringTemplate (
7519 "OpCapability Shader\n"
7520 "OpCapability Matrix\n"
7521 "OpMemoryModel Logical GLSL450\n"
7522 "OpEntryPoint GLCompute %main \"main\" %id\n"
7523 "OpExecutionMode %main LocalSize 1 1 1\n"
7525 "OpSource GLSL 430\n"
7526 "OpName %main \"main\"\n"
7527 "OpName %id \"gl_GlobalInvocationID\"\n"
7530 "OpDecorate %id BuiltIn GlobalInvocationId\n"
7531 "OpDecorate %buf BufferBlock\n"
7532 "OpDecorate %indata DescriptorSet 0\n"
7533 "OpDecorate %indata Binding 0\n"
7534 "OpDecorate %outdata DescriptorSet 0\n"
7535 "OpDecorate %outdata Binding 1\n"
7536 "OpDecorate %customarr ArrayStride 4\n"
7537 "${compositeDecorator}"
7538 "OpMemberDecorate %buf 0 Offset 0\n"
7541 "%void = OpTypeVoid\n"
7542 "%voidf = OpTypeFunction %void\n"
7543 "%u32 = OpTypeInt 32 0\n"
7544 "%i32 = OpTypeInt 32 1\n"
7545 "%uvec3 = OpTypeVector %u32 3\n"
7546 "%uvec3ptr = OpTypePointer Input %uvec3\n"
7549 "%custom = ${typeDeclaration}\n"
7555 // Inherited from custom
7556 "%customptr = OpTypePointer Uniform %custom\n"
7557 "%customarr = OpTypeRuntimeArray %custom\n"
7558 "%buf = OpTypeStruct %customarr\n"
7559 "%bufptr = OpTypePointer Uniform %buf\n"
7561 "%indata = OpVariable %bufptr Uniform\n"
7562 "%outdata = OpVariable %bufptr Uniform\n"
7564 "%id = OpVariable %uvec3ptr Input\n"
7565 "%zero = OpConstant %i32 0\n"
7567 "%main = OpFunction %void None %voidf\n"
7568 "%label = OpLabel\n"
7569 "%idval = OpLoad %uvec3 %id\n"
7570 "%x = OpCompositeExtract %u32 %idval 0\n"
7572 "%inloc = OpAccessChain %customptr %indata %zero %x\n"
7573 "%outloc = OpAccessChain %customptr %outdata %zero %x\n"
7574 // Read the input value
7575 "%inval = OpLoad %custom %inloc\n"
7576 // Create the composite and fill it
7577 "${compositeConstruct}"
7578 // Insert the input value to a place
7579 "%instance2 = OpCompositeInsert %composite %inval %instance ${indexes}\n"
7580 // Read back the value from the position
7581 "%out_val = OpCompositeExtract %custom %instance2 ${indexes}\n"
7582 // Store it in the output position
7583 " OpStore %outloc %out_val\n"
7586 ).specialize(parameters);
7589 template<typename T>
7590 BufferSp createCompositeBuffer(T number)
7592 return BufferSp(new Buffer<T>(vector<T>(1, number)));
7595 tcu::TestCaseGroup* createOpCompositeInsertGroup (tcu::TestContext& testCtx)
7597 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opcompositeinsert", "Test the OpCompositeInsert instruction"));
7598 de::Random rnd (deStringHash(group->getName()));
7600 for (int type = NUMBERTYPE_INT32; type != NUMBERTYPE_END32; ++type)
7602 NumberType numberType = NumberType(type);
7603 const string typeName = getNumberTypeName(numberType);
7604 const string description = "Test the OpCompositeInsert instruction with " + typeName + "s";
7605 de::MovePtr<tcu::TestCaseGroup> subGroup (new tcu::TestCaseGroup(testCtx, typeName.c_str(), description.c_str()));
7606 vector<map<string, string> > testCases;
7608 createCompositeCases(testCases, rnd, numberType);
7610 for (vector<map<string, string> >::const_iterator test = testCases.begin(); test != testCases.end(); ++test)
7612 ComputeShaderSpec spec;
7614 spec.assembly = specializeCompositeInsertShaderTemplate(numberType, *test);
7618 case NUMBERTYPE_INT32:
7620 deInt32 number = getInt(rnd);
7621 spec.inputs.push_back(createCompositeBuffer<deInt32>(number));
7622 spec.outputs.push_back(createCompositeBuffer<deInt32>(number));
7625 case NUMBERTYPE_UINT32:
7627 deUint32 number = rnd.getUint32();
7628 spec.inputs.push_back(createCompositeBuffer<deUint32>(number));
7629 spec.outputs.push_back(createCompositeBuffer<deUint32>(number));
7632 case NUMBERTYPE_FLOAT32:
7634 float number = rnd.getFloat();
7635 spec.inputs.push_back(createCompositeBuffer<float>(number));
7636 spec.outputs.push_back(createCompositeBuffer<float>(number));
7643 spec.numWorkGroups = IVec3(1, 1, 1);
7644 subGroup->addChild(new SpvAsmComputeShaderCase(testCtx, test->at("name").c_str(), "OpCompositeInsert test", spec));
7646 group->addChild(subGroup.release());
7648 return group.release();
7651 struct AssemblyStructInfo
7653 AssemblyStructInfo (const deUint32 comp, const deUint32 idx)
7658 deUint32 components;
7662 const string specializeInBoundsShaderTemplate (const NumberType type, const AssemblyStructInfo& structInfo, const map<string, string>& params)
7664 // Create the full index string
7665 string fullIndex = numberToString(structInfo.index) + " " + params.at("indexes");
7666 // Convert it to list of indexes
7667 vector<string> indexes = de::splitString(fullIndex, ' ');
7669 map<string, string> parameters (params);
7670 parameters["typeDeclaration"] = getAssemblyTypeDeclaration(type);
7671 parameters["structType"] = repeatString(" %composite", structInfo.components);
7672 parameters["structConstruct"] = repeatString(" %instance", structInfo.components);
7673 parameters["insertIndexes"] = fullIndex;
7675 // In matrix cases the last two index is the CompositeExtract indexes
7676 const deUint32 extractIndexes = (parameters["type"] == "matrix") ? 2 : 1;
7678 // Construct the extractIndex
7679 for (vector<string>::const_iterator index = indexes.end() - extractIndexes; index != indexes.end(); ++index)
7681 parameters["extractIndexes"] += " " + *index;
7684 // Remove the last 1 or 2 element depends on matrix case or not
7685 indexes.erase(indexes.end() - extractIndexes, indexes.end());
7688 // Generate AccessChain index expressions (except for the last one, because we use ptr to the composite)
7689 for (vector<string>::const_iterator index = indexes.begin(); index != indexes.end(); ++index)
7691 string indexId = "%index_" + numberToString(id++);
7692 parameters["accessChainConstDeclaration"] += indexId + " = OpConstant %u32 " + *index + "\n";
7693 parameters["accessChainIndexes"] += " " + indexId;
7696 parameters["compositeDecorator"] = (parameters["type"] == "array") ? "OpDecorate %composite ArrayStride 4\n" : "";
7698 return StringTemplate (
7699 "OpCapability Shader\n"
7700 "OpCapability Matrix\n"
7701 "OpMemoryModel Logical GLSL450\n"
7702 "OpEntryPoint GLCompute %main \"main\" %id\n"
7703 "OpExecutionMode %main LocalSize 1 1 1\n"
7705 "OpSource GLSL 430\n"
7706 "OpName %main \"main\"\n"
7707 "OpName %id \"gl_GlobalInvocationID\"\n"
7709 "OpDecorate %id BuiltIn GlobalInvocationId\n"
7710 "OpDecorate %buf BufferBlock\n"
7711 "OpDecorate %indata DescriptorSet 0\n"
7712 "OpDecorate %indata Binding 0\n"
7713 "OpDecorate %outdata DescriptorSet 0\n"
7714 "OpDecorate %outdata Binding 1\n"
7715 "OpDecorate %customarr ArrayStride 4\n"
7716 "${compositeDecorator}"
7717 "OpMemberDecorate %buf 0 Offset 0\n"
7719 "%void = OpTypeVoid\n"
7720 "%voidf = OpTypeFunction %void\n"
7721 "%u32 = OpTypeInt 32 0\n"
7722 "%uvec3 = OpTypeVector %u32 3\n"
7723 "%uvec3ptr = OpTypePointer Input %uvec3\n"
7725 "%custom = ${typeDeclaration}\n"
7728 // Inherited from composite
7729 "%composite_p = OpTypePointer Function %composite\n"
7730 "%struct_t = OpTypeStruct${structType}\n"
7731 "%struct_p = OpTypePointer Function %struct_t\n"
7734 "${accessChainConstDeclaration}"
7735 // Inherited from custom
7736 "%customptr = OpTypePointer Uniform %custom\n"
7737 "%customarr = OpTypeRuntimeArray %custom\n"
7738 "%buf = OpTypeStruct %customarr\n"
7739 "%bufptr = OpTypePointer Uniform %buf\n"
7740 "%indata = OpVariable %bufptr Uniform\n"
7741 "%outdata = OpVariable %bufptr Uniform\n"
7743 "%id = OpVariable %uvec3ptr Input\n"
7744 "%zero = OpConstant %u32 0\n"
7745 "%main = OpFunction %void None %voidf\n"
7746 "%label = OpLabel\n"
7747 "%struct_v = OpVariable %struct_p Function\n"
7748 "%idval = OpLoad %uvec3 %id\n"
7749 "%x = OpCompositeExtract %u32 %idval 0\n"
7750 // Create the input/output type
7751 "%inloc = OpInBoundsAccessChain %customptr %indata %zero %x\n"
7752 "%outloc = OpInBoundsAccessChain %customptr %outdata %zero %x\n"
7753 // Read the input value
7754 "%inval = OpLoad %custom %inloc\n"
7755 // Create the composite and fill it
7756 "${compositeConstruct}"
7757 // Create the struct and fill it with the composite
7758 "%struct = OpCompositeConstruct %struct_t${structConstruct}\n"
7760 "%comp_obj = OpCompositeInsert %struct_t %inval %struct ${insertIndexes}\n"
7762 " OpStore %struct_v %comp_obj\n"
7763 // Get deepest possible composite pointer
7764 "%inner_ptr = OpInBoundsAccessChain %composite_p %struct_v${accessChainIndexes}\n"
7765 "%read_obj = OpLoad %composite %inner_ptr\n"
7766 // Read back the stored value
7767 "%read_val = OpCompositeExtract %custom %read_obj${extractIndexes}\n"
7768 " OpStore %outloc %read_val\n"
7770 " OpFunctionEnd\n").specialize(parameters);
7773 tcu::TestCaseGroup* createOpInBoundsAccessChainGroup (tcu::TestContext& testCtx)
7775 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opinboundsaccesschain", "Test the OpInBoundsAccessChain instruction"));
7776 de::Random rnd (deStringHash(group->getName()));
7778 for (int type = NUMBERTYPE_INT32; type != NUMBERTYPE_END32; ++type)
7780 NumberType numberType = NumberType(type);
7781 const string typeName = getNumberTypeName(numberType);
7782 const string description = "Test the OpInBoundsAccessChain instruction with " + typeName + "s";
7783 de::MovePtr<tcu::TestCaseGroup> subGroup (new tcu::TestCaseGroup(testCtx, typeName.c_str(), description.c_str()));
7785 vector<map<string, string> > testCases;
7786 createCompositeCases(testCases, rnd, numberType);
7788 for (vector<map<string, string> >::const_iterator test = testCases.begin(); test != testCases.end(); ++test)
7790 ComputeShaderSpec spec;
7792 // Number of components inside of a struct
7793 deUint32 structComponents = rnd.getInt(2, 8);
7794 // Component index value
7795 deUint32 structIndex = rnd.getInt(0, structComponents - 1);
7796 AssemblyStructInfo structInfo(structComponents, structIndex);
7798 spec.assembly = specializeInBoundsShaderTemplate(numberType, structInfo, *test);
7802 case NUMBERTYPE_INT32:
7804 deInt32 number = getInt(rnd);
7805 spec.inputs.push_back(createCompositeBuffer<deInt32>(number));
7806 spec.outputs.push_back(createCompositeBuffer<deInt32>(number));
7809 case NUMBERTYPE_UINT32:
7811 deUint32 number = rnd.getUint32();
7812 spec.inputs.push_back(createCompositeBuffer<deUint32>(number));
7813 spec.outputs.push_back(createCompositeBuffer<deUint32>(number));
7816 case NUMBERTYPE_FLOAT32:
7818 float number = rnd.getFloat();
7819 spec.inputs.push_back(createCompositeBuffer<float>(number));
7820 spec.outputs.push_back(createCompositeBuffer<float>(number));
7826 spec.numWorkGroups = IVec3(1, 1, 1);
7827 subGroup->addChild(new SpvAsmComputeShaderCase(testCtx, test->at("name").c_str(), "OpInBoundsAccessChain test", spec));
7829 group->addChild(subGroup.release());
7831 return group.release();
7834 // If the params missing, uninitialized case
7835 const string specializeDefaultOutputShaderTemplate (const NumberType type, const map<string, string>& params = map<string, string>())
7837 map<string, string> parameters(params);
7839 parameters["typeDeclaration"] = getAssemblyTypeDeclaration(type);
7841 // Declare the const value, and use it in the initializer
7842 if (params.find("constValue") != params.end())
7844 parameters["constDeclaration"] = "%const = OpConstant %in_type " + params.at("constValue") + "\n";
7845 parameters["variableInitializer"] = "%const";
7847 // Uninitialized case
7850 parameters["constDeclaration"] = "";
7851 parameters["variableInitializer"] = "";
7854 return StringTemplate(
7855 "OpCapability Shader\n"
7856 "OpMemoryModel Logical GLSL450\n"
7857 "OpEntryPoint GLCompute %main \"main\" %id\n"
7858 "OpExecutionMode %main LocalSize 1 1 1\n"
7859 "OpSource GLSL 430\n"
7860 "OpName %main \"main\"\n"
7861 "OpName %id \"gl_GlobalInvocationID\"\n"
7863 "OpDecorate %id BuiltIn GlobalInvocationId\n"
7864 "OpDecorate %indata DescriptorSet 0\n"
7865 "OpDecorate %indata Binding 0\n"
7866 "OpDecorate %outdata DescriptorSet 0\n"
7867 "OpDecorate %outdata Binding 1\n"
7868 "OpDecorate %in_arr ArrayStride 4\n"
7869 "OpDecorate %in_buf BufferBlock\n"
7870 "OpMemberDecorate %in_buf 0 Offset 0\n"
7872 "%void = OpTypeVoid\n"
7873 "%voidf = OpTypeFunction %void\n"
7874 "%u32 = OpTypeInt 32 0\n"
7875 "%i32 = OpTypeInt 32 1\n"
7876 "%uvec3 = OpTypeVector %u32 3\n"
7877 "%uvec3ptr = OpTypePointer Input %uvec3\n"
7879 "%in_type = ${typeDeclaration}\n"
7880 // "%const = OpConstant %in_type ${constValue}\n"
7881 "${constDeclaration}\n"
7883 "%in_ptr = OpTypePointer Uniform %in_type\n"
7884 "%in_arr = OpTypeRuntimeArray %in_type\n"
7885 "%in_buf = OpTypeStruct %in_arr\n"
7886 "%in_bufptr = OpTypePointer Uniform %in_buf\n"
7887 "%indata = OpVariable %in_bufptr Uniform\n"
7888 "%outdata = OpVariable %in_bufptr Uniform\n"
7889 "%id = OpVariable %uvec3ptr Input\n"
7890 "%var_ptr = OpTypePointer Function %in_type\n"
7892 "%zero = OpConstant %i32 0\n"
7894 "%main = OpFunction %void None %voidf\n"
7895 "%label = OpLabel\n"
7896 "%out_var = OpVariable %var_ptr Function ${variableInitializer}\n"
7897 "%idval = OpLoad %uvec3 %id\n"
7898 "%x = OpCompositeExtract %u32 %idval 0\n"
7899 "%inloc = OpAccessChain %in_ptr %indata %zero %x\n"
7900 "%outloc = OpAccessChain %in_ptr %outdata %zero %x\n"
7902 "%outval = OpLoad %in_type %out_var\n"
7903 " OpStore %outloc %outval\n"
7906 ).specialize(parameters);
7909 bool compareFloats (const std::vector<BufferSp>&, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs, TestLog& log)
7911 DE_ASSERT(outputAllocs.size() != 0);
7912 DE_ASSERT(outputAllocs.size() == expectedOutputs.size());
7914 // Use custom epsilon because of the float->string conversion
7915 const float epsilon = 0.00001f;
7917 for (size_t outputNdx = 0; outputNdx < outputAllocs.size(); ++outputNdx)
7919 vector<deUint8> expectedBytes;
7923 expectedOutputs[outputNdx]->getBytes(expectedBytes);
7924 memcpy(&expected, &expectedBytes.front(), expectedBytes.size());
7925 memcpy(&actual, outputAllocs[outputNdx]->getHostPtr(), expectedBytes.size());
7927 // Test with epsilon
7928 if (fabs(expected - actual) > epsilon)
7930 log << TestLog::Message << "Error: The actual and expected values not matching."
7931 << " Expected: " << expected << " Actual: " << actual << " Epsilon: " << epsilon << TestLog::EndMessage;
7938 // Checks if the driver crash with uninitialized cases
7939 bool passthruVerify (const std::vector<BufferSp>&, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs, TestLog&)
7941 DE_ASSERT(outputAllocs.size() != 0);
7942 DE_ASSERT(outputAllocs.size() == expectedOutputs.size());
7944 // Copy and discard the result.
7945 for (size_t outputNdx = 0; outputNdx < outputAllocs.size(); ++outputNdx)
7947 vector<deUint8> expectedBytes;
7948 expectedOutputs[outputNdx]->getBytes(expectedBytes);
7950 const size_t width = expectedBytes.size();
7951 vector<char> data (width);
7953 memcpy(&data[0], outputAllocs[outputNdx]->getHostPtr(), width);
7958 tcu::TestCaseGroup* createShaderDefaultOutputGroup (tcu::TestContext& testCtx)
7960 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "shader_default_output", "Test shader default output."));
7961 de::Random rnd (deStringHash(group->getName()));
7963 for (int type = NUMBERTYPE_INT32; type != NUMBERTYPE_END32; ++type)
7965 NumberType numberType = NumberType(type);
7966 const string typeName = getNumberTypeName(numberType);
7967 const string description = "Test the OpVariable initializer with " + typeName + ".";
7968 de::MovePtr<tcu::TestCaseGroup> subGroup (new tcu::TestCaseGroup(testCtx, typeName.c_str(), description.c_str()));
7970 // 2 similar subcases (initialized and uninitialized)
7971 for (int subCase = 0; subCase < 2; ++subCase)
7973 ComputeShaderSpec spec;
7974 spec.numWorkGroups = IVec3(1, 1, 1);
7976 map<string, string> params;
7980 case NUMBERTYPE_INT32:
7982 deInt32 number = getInt(rnd);
7983 spec.inputs.push_back(createCompositeBuffer<deInt32>(number));
7984 spec.outputs.push_back(createCompositeBuffer<deInt32>(number));
7985 params["constValue"] = numberToString(number);
7988 case NUMBERTYPE_UINT32:
7990 deUint32 number = rnd.getUint32();
7991 spec.inputs.push_back(createCompositeBuffer<deUint32>(number));
7992 spec.outputs.push_back(createCompositeBuffer<deUint32>(number));
7993 params["constValue"] = numberToString(number);
7996 case NUMBERTYPE_FLOAT32:
7998 float number = rnd.getFloat();
7999 spec.inputs.push_back(createCompositeBuffer<float>(number));
8000 spec.outputs.push_back(createCompositeBuffer<float>(number));
8001 spec.verifyIO = &compareFloats;
8002 params["constValue"] = numberToString(number);
8009 // Initialized subcase
8012 spec.assembly = specializeDefaultOutputShaderTemplate(numberType, params);
8013 subGroup->addChild(new SpvAsmComputeShaderCase(testCtx, "initialized", "OpVariable initializer tests.", spec));
8015 // Uninitialized subcase
8018 spec.assembly = specializeDefaultOutputShaderTemplate(numberType);
8019 spec.verifyIO = &passthruVerify;
8020 subGroup->addChild(new SpvAsmComputeShaderCase(testCtx, "uninitialized", "OpVariable initializer tests.", spec));
8023 group->addChild(subGroup.release());
8025 return group.release();
8028 tcu::TestCaseGroup* createOpNopTests (tcu::TestContext& testCtx)
8030 de::MovePtr<tcu::TestCaseGroup> testGroup (new tcu::TestCaseGroup(testCtx, "opnop", "Test OpNop"));
8031 RGBA defaultColors[4];
8032 map<string, string> opNopFragments;
8034 getDefaultColors(defaultColors);
8036 opNopFragments["testfun"] =
8037 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
8038 "%param1 = OpFunctionParameter %v4f32\n"
8039 "%label_testfun = OpLabel\n"
8048 "%a = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
8049 "%b = OpFAdd %f32 %a %a\n"
8051 "%c = OpFSub %f32 %b %a\n"
8052 "%ret = OpVectorInsertDynamic %v4f32 %param1 %c %c_i32_0\n"
8055 "OpReturnValue %ret\n"
8058 createTestsForAllStages("opnop", defaultColors, defaultColors, opNopFragments, testGroup.get());
8060 return testGroup.release();
8063 tcu::TestCaseGroup* createInstructionTests (tcu::TestContext& testCtx)
8065 const bool testComputePipeline = true;
8067 de::MovePtr<tcu::TestCaseGroup> instructionTests (new tcu::TestCaseGroup(testCtx, "instruction", "Instructions with special opcodes/operands"));
8068 de::MovePtr<tcu::TestCaseGroup> computeTests (new tcu::TestCaseGroup(testCtx, "compute", "Compute Instructions with special opcodes/operands"));
8069 de::MovePtr<tcu::TestCaseGroup> graphicsTests (new tcu::TestCaseGroup(testCtx, "graphics", "Graphics Instructions with special opcodes/operands"));
8071 computeTests->addChild(createSpivVersionCheckTests(testCtx, testComputePipeline));
8072 computeTests->addChild(createOpNopGroup(testCtx));
8073 computeTests->addChild(createOpFUnordGroup(testCtx));
8074 computeTests->addChild(createOpAtomicGroup(testCtx, false));
8075 computeTests->addChild(createOpAtomicGroup(testCtx, true)); // Using new StorageBuffer decoration
8076 computeTests->addChild(createOpLineGroup(testCtx));
8077 computeTests->addChild(createOpModuleProcessedGroup(testCtx));
8078 computeTests->addChild(createOpNoLineGroup(testCtx));
8079 computeTests->addChild(createOpConstantNullGroup(testCtx));
8080 computeTests->addChild(createOpConstantCompositeGroup(testCtx));
8081 computeTests->addChild(createOpConstantUsageGroup(testCtx));
8082 computeTests->addChild(createSpecConstantGroup(testCtx));
8083 computeTests->addChild(createOpSourceGroup(testCtx));
8084 computeTests->addChild(createOpSourceExtensionGroup(testCtx));
8085 computeTests->addChild(createDecorationGroupGroup(testCtx));
8086 computeTests->addChild(createOpPhiGroup(testCtx));
8087 computeTests->addChild(createLoopControlGroup(testCtx));
8088 computeTests->addChild(createFunctionControlGroup(testCtx));
8089 computeTests->addChild(createSelectionControlGroup(testCtx));
8090 computeTests->addChild(createBlockOrderGroup(testCtx));
8091 computeTests->addChild(createMultipleShaderGroup(testCtx));
8092 computeTests->addChild(createMemoryAccessGroup(testCtx));
8093 computeTests->addChild(createOpCopyMemoryGroup(testCtx));
8094 computeTests->addChild(createOpCopyObjectGroup(testCtx));
8095 computeTests->addChild(createNoContractionGroup(testCtx));
8096 computeTests->addChild(createOpUndefGroup(testCtx));
8097 computeTests->addChild(createOpUnreachableGroup(testCtx));
8098 computeTests ->addChild(createOpQuantizeToF16Group(testCtx));
8099 computeTests ->addChild(createOpFRemGroup(testCtx));
8100 computeTests->addChild(createOpSRemComputeGroup(testCtx, QP_TEST_RESULT_PASS));
8101 computeTests->addChild(createOpSRemComputeGroup64(testCtx, QP_TEST_RESULT_PASS));
8102 computeTests->addChild(createOpSModComputeGroup(testCtx, QP_TEST_RESULT_PASS));
8103 computeTests->addChild(createOpSModComputeGroup64(testCtx, QP_TEST_RESULT_PASS));
8104 computeTests->addChild(createSConvertTests(testCtx));
8105 computeTests->addChild(createUConvertTests(testCtx));
8106 computeTests->addChild(createOpCompositeInsertGroup(testCtx));
8107 computeTests->addChild(createOpInBoundsAccessChainGroup(testCtx));
8108 computeTests->addChild(createShaderDefaultOutputGroup(testCtx));
8109 computeTests->addChild(createOpNMinGroup(testCtx));
8110 computeTests->addChild(createOpNMaxGroup(testCtx));
8111 computeTests->addChild(createOpNClampGroup(testCtx));
8113 de::MovePtr<tcu::TestCaseGroup> computeAndroidTests (new tcu::TestCaseGroup(testCtx, "android", "Android CTS Tests"));
8115 computeAndroidTests->addChild(createOpSRemComputeGroup(testCtx, QP_TEST_RESULT_QUALITY_WARNING));
8116 computeAndroidTests->addChild(createOpSModComputeGroup(testCtx, QP_TEST_RESULT_QUALITY_WARNING));
8118 computeTests->addChild(computeAndroidTests.release());
8121 computeTests->addChild(create16BitStorageComputeGroup(testCtx));
8122 computeTests->addChild(createUboMatrixPaddingComputeGroup(testCtx));
8123 computeTests->addChild(createConditionalBranchComputeGroup(testCtx));
8124 computeTests->addChild(createIndexingComputeGroup(testCtx));
8125 computeTests->addChild(createVariablePointersComputeGroup(testCtx));
8126 graphicsTests->addChild(createSpivVersionCheckTests(testCtx, !testComputePipeline));
8127 graphicsTests->addChild(createOpNopTests(testCtx));
8128 graphicsTests->addChild(createOpSourceTests(testCtx));
8129 graphicsTests->addChild(createOpSourceContinuedTests(testCtx));
8130 graphicsTests->addChild(createOpModuleProcessedTests(testCtx));
8131 graphicsTests->addChild(createOpLineTests(testCtx));
8132 graphicsTests->addChild(createOpNoLineTests(testCtx));
8133 graphicsTests->addChild(createOpConstantNullTests(testCtx));
8134 graphicsTests->addChild(createOpConstantCompositeTests(testCtx));
8135 graphicsTests->addChild(createMemoryAccessTests(testCtx));
8136 graphicsTests->addChild(createOpUndefTests(testCtx));
8137 graphicsTests->addChild(createSelectionBlockOrderTests(testCtx));
8138 graphicsTests->addChild(createModuleTests(testCtx));
8139 graphicsTests->addChild(createSwitchBlockOrderTests(testCtx));
8140 graphicsTests->addChild(createOpPhiTests(testCtx));
8141 graphicsTests->addChild(createNoContractionTests(testCtx));
8142 graphicsTests->addChild(createOpQuantizeTests(testCtx));
8143 graphicsTests->addChild(createLoopTests(testCtx));
8144 graphicsTests->addChild(createSpecConstantTests(testCtx));
8145 graphicsTests->addChild(createSpecConstantOpQuantizeToF16Group(testCtx));
8146 graphicsTests->addChild(createBarrierTests(testCtx));
8147 graphicsTests->addChild(createDecorationGroupTests(testCtx));
8148 graphicsTests->addChild(createFRemTests(testCtx));
8149 graphicsTests->addChild(createOpSRemGraphicsTests(testCtx, QP_TEST_RESULT_PASS));
8150 graphicsTests->addChild(createOpSModGraphicsTests(testCtx, QP_TEST_RESULT_PASS));
8153 de::MovePtr<tcu::TestCaseGroup> graphicsAndroidTests (new tcu::TestCaseGroup(testCtx, "android", "Android CTS Tests"));
8155 graphicsAndroidTests->addChild(createOpSRemGraphicsTests(testCtx, QP_TEST_RESULT_QUALITY_WARNING));
8156 graphicsAndroidTests->addChild(createOpSModGraphicsTests(testCtx, QP_TEST_RESULT_QUALITY_WARNING));
8158 graphicsTests->addChild(graphicsAndroidTests.release());
8161 graphicsTests->addChild(create16BitStorageGraphicsGroup(testCtx));
8162 graphicsTests->addChild(createUboMatrixPaddingGraphicsGroup(testCtx));
8163 graphicsTests->addChild(createConditionalBranchGraphicsGroup(testCtx));
8164 graphicsTests->addChild(createIndexingGraphicsGroup(testCtx));
8165 graphicsTests->addChild(createVariablePointersGraphicsGroup(testCtx));
8167 instructionTests->addChild(computeTests.release());
8168 instructionTests->addChild(graphicsTests.release());
8170 return instructionTests.release();