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"));
4196 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats[0], numElements);
4198 for (size_t ndx = 0; ndx < numElements; ++ndx)
4199 outputFloats[ndx] = inputFloats[ndx] + 4.f;
4201 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
4203 map<string, string> specializations;
4204 ComputeShaderSpec spec;
4206 specializations["CONTROL"] = cases[caseNdx].param;
4207 spec.assembly = shaderTemplate.specialize(specializations);
4208 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
4209 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
4210 spec.numWorkGroups = IVec3(numElements, 1, 1);
4212 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
4215 group->addChild(new SpvAsmLoopControlDependencyLengthCase(testCtx, "dependency_length", "dependency_length"));
4216 group->addChild(new SpvAsmLoopControlDependencyInfiniteCase(testCtx, "dependency_infinite", "dependency_infinite"));
4218 return group.release();
4221 // Assembly code used for testing selection control is based on GLSL source code:
4224 // layout(std140, set = 0, binding = 0) readonly buffer Input {
4225 // float elements[];
4227 // layout(std140, set = 0, binding = 1) writeonly buffer Output {
4228 // float elements[];
4232 // uint x = gl_GlobalInvocationID.x;
4233 // float val = input_data.elements[x];
4235 // output_data.elements[x] = val + 1.f;
4237 // output_data.elements[x] = val - 1.f;
4239 tcu::TestCaseGroup* createSelectionControlGroup (tcu::TestContext& testCtx)
4241 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "selection_control", "Tests selection control cases"));
4242 vector<CaseParameter> cases;
4243 de::Random rnd (deStringHash(group->getName()));
4244 const int numElements = 100;
4245 vector<float> inputFloats (numElements, 0);
4246 vector<float> outputFloats (numElements, 0);
4247 const StringTemplate shaderTemplate (
4248 string(getComputeAsmShaderPreamble()) +
4250 "OpSource GLSL 430\n"
4251 "OpName %main \"main\"\n"
4252 "OpName %id \"gl_GlobalInvocationID\"\n"
4254 "OpDecorate %id BuiltIn GlobalInvocationId\n"
4256 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
4258 "%id = OpVariable %uvec3ptr Input\n"
4259 "%zero = OpConstant %i32 0\n"
4260 "%constf1 = OpConstant %f32 1.0\n"
4261 "%constf10 = OpConstant %f32 10.0\n"
4263 "%main = OpFunction %void None %voidf\n"
4264 "%entry = OpLabel\n"
4265 "%idval = OpLoad %uvec3 %id\n"
4266 "%x = OpCompositeExtract %u32 %idval 0\n"
4267 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
4268 "%inval = OpLoad %f32 %inloc\n"
4269 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
4270 "%cmp_gt = OpFOrdGreaterThan %bool %inval %constf10\n"
4272 " OpSelectionMerge %if_end ${CONTROL}\n"
4273 " OpBranchConditional %cmp_gt %if_true %if_false\n"
4274 "%if_true = OpLabel\n"
4275 "%addf1 = OpFAdd %f32 %inval %constf1\n"
4276 " OpStore %outloc %addf1\n"
4277 " OpBranch %if_end\n"
4278 "%if_false = OpLabel\n"
4279 "%subf1 = OpFSub %f32 %inval %constf1\n"
4280 " OpStore %outloc %subf1\n"
4281 " OpBranch %if_end\n"
4282 "%if_end = OpLabel\n"
4284 " OpFunctionEnd\n");
4286 cases.push_back(CaseParameter("none", "None"));
4287 cases.push_back(CaseParameter("flatten", "Flatten"));
4288 cases.push_back(CaseParameter("dont_flatten", "DontFlatten"));
4289 cases.push_back(CaseParameter("flatten_dont_flatten", "DontFlatten|Flatten"));
4291 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats[0], numElements);
4293 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
4294 floorAll(inputFloats);
4296 for (size_t ndx = 0; ndx < numElements; ++ndx)
4297 outputFloats[ndx] = inputFloats[ndx] + (inputFloats[ndx] > 10.f ? 1.f : -1.f);
4299 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
4301 map<string, string> specializations;
4302 ComputeShaderSpec spec;
4304 specializations["CONTROL"] = cases[caseNdx].param;
4305 spec.assembly = shaderTemplate.specialize(specializations);
4306 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
4307 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
4308 spec.numWorkGroups = IVec3(numElements, 1, 1);
4310 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
4313 return group.release();
4316 // Assembly code used for testing function control is based on GLSL source code:
4320 // layout(std140, set = 0, binding = 0) readonly buffer Input {
4321 // float elements[];
4323 // layout(std140, set = 0, binding = 1) writeonly buffer Output {
4324 // float elements[];
4327 // float const10() { return 10.f; }
4330 // uint x = gl_GlobalInvocationID.x;
4331 // output_data.elements[x] = input_data.elements[x] + const10();
4333 tcu::TestCaseGroup* createFunctionControlGroup (tcu::TestContext& testCtx)
4335 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "function_control", "Tests function control cases"));
4336 vector<CaseParameter> cases;
4337 de::Random rnd (deStringHash(group->getName()));
4338 const int numElements = 100;
4339 vector<float> inputFloats (numElements, 0);
4340 vector<float> outputFloats (numElements, 0);
4341 const StringTemplate shaderTemplate (
4342 string(getComputeAsmShaderPreamble()) +
4344 "OpSource GLSL 430\n"
4345 "OpName %main \"main\"\n"
4346 "OpName %func_const10 \"const10(\"\n"
4347 "OpName %id \"gl_GlobalInvocationID\"\n"
4349 "OpDecorate %id BuiltIn GlobalInvocationId\n"
4351 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
4353 "%f32f = OpTypeFunction %f32\n"
4354 "%id = OpVariable %uvec3ptr Input\n"
4355 "%zero = OpConstant %i32 0\n"
4356 "%constf10 = OpConstant %f32 10.0\n"
4358 "%main = OpFunction %void None %voidf\n"
4359 "%entry = OpLabel\n"
4360 "%idval = OpLoad %uvec3 %id\n"
4361 "%x = OpCompositeExtract %u32 %idval 0\n"
4362 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
4363 "%inval = OpLoad %f32 %inloc\n"
4364 "%ret_10 = OpFunctionCall %f32 %func_const10\n"
4365 "%fadd = OpFAdd %f32 %inval %ret_10\n"
4366 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
4367 " OpStore %outloc %fadd\n"
4371 "%func_const10 = OpFunction %f32 ${CONTROL} %f32f\n"
4372 "%label = OpLabel\n"
4373 " OpReturnValue %constf10\n"
4374 " OpFunctionEnd\n");
4376 cases.push_back(CaseParameter("none", "None"));
4377 cases.push_back(CaseParameter("inline", "Inline"));
4378 cases.push_back(CaseParameter("dont_inline", "DontInline"));
4379 cases.push_back(CaseParameter("pure", "Pure"));
4380 cases.push_back(CaseParameter("const", "Const"));
4381 cases.push_back(CaseParameter("inline_pure", "Inline|Pure"));
4382 cases.push_back(CaseParameter("const_dont_inline", "Const|DontInline"));
4383 cases.push_back(CaseParameter("inline_dont_inline", "Inline|DontInline"));
4384 cases.push_back(CaseParameter("pure_inline_dont_inline", "Pure|Inline|DontInline"));
4386 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats[0], numElements);
4388 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
4389 floorAll(inputFloats);
4391 for (size_t ndx = 0; ndx < numElements; ++ndx)
4392 outputFloats[ndx] = inputFloats[ndx] + 10.f;
4394 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
4396 map<string, string> specializations;
4397 ComputeShaderSpec spec;
4399 specializations["CONTROL"] = cases[caseNdx].param;
4400 spec.assembly = shaderTemplate.specialize(specializations);
4401 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
4402 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
4403 spec.numWorkGroups = IVec3(numElements, 1, 1);
4405 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
4408 return group.release();
4411 tcu::TestCaseGroup* createMemoryAccessGroup (tcu::TestContext& testCtx)
4413 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "memory_access", "Tests memory access cases"));
4414 vector<CaseParameter> cases;
4415 de::Random rnd (deStringHash(group->getName()));
4416 const int numElements = 100;
4417 vector<float> inputFloats (numElements, 0);
4418 vector<float> outputFloats (numElements, 0);
4419 const StringTemplate shaderTemplate (
4420 string(getComputeAsmShaderPreamble()) +
4422 "OpSource GLSL 430\n"
4423 "OpName %main \"main\"\n"
4424 "OpName %id \"gl_GlobalInvocationID\"\n"
4426 "OpDecorate %id BuiltIn GlobalInvocationId\n"
4428 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
4430 "%f32ptr_f = OpTypePointer Function %f32\n"
4432 "%id = OpVariable %uvec3ptr Input\n"
4433 "%zero = OpConstant %i32 0\n"
4434 "%four = OpConstant %i32 4\n"
4436 "%main = OpFunction %void None %voidf\n"
4437 "%label = OpLabel\n"
4438 "%copy = OpVariable %f32ptr_f Function\n"
4439 "%idval = OpLoad %uvec3 %id ${ACCESS}\n"
4440 "%x = OpCompositeExtract %u32 %idval 0\n"
4441 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
4442 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
4443 " OpCopyMemory %copy %inloc ${ACCESS}\n"
4444 "%val1 = OpLoad %f32 %copy\n"
4445 "%val2 = OpLoad %f32 %inloc\n"
4446 "%add = OpFAdd %f32 %val1 %val2\n"
4447 " OpStore %outloc %add ${ACCESS}\n"
4449 " OpFunctionEnd\n");
4451 cases.push_back(CaseParameter("null", ""));
4452 cases.push_back(CaseParameter("none", "None"));
4453 cases.push_back(CaseParameter("volatile", "Volatile"));
4454 cases.push_back(CaseParameter("aligned", "Aligned 4"));
4455 cases.push_back(CaseParameter("nontemporal", "Nontemporal"));
4456 cases.push_back(CaseParameter("aligned_nontemporal", "Aligned|Nontemporal 4"));
4457 cases.push_back(CaseParameter("aligned_volatile", "Volatile|Aligned 4"));
4459 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats[0], numElements);
4461 for (size_t ndx = 0; ndx < numElements; ++ndx)
4462 outputFloats[ndx] = inputFloats[ndx] + inputFloats[ndx];
4464 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
4466 map<string, string> specializations;
4467 ComputeShaderSpec spec;
4469 specializations["ACCESS"] = cases[caseNdx].param;
4470 spec.assembly = shaderTemplate.specialize(specializations);
4471 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
4472 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
4473 spec.numWorkGroups = IVec3(numElements, 1, 1);
4475 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
4478 return group.release();
4481 // Checks that we can get undefined values for various types, without exercising a computation with it.
4482 tcu::TestCaseGroup* createOpUndefGroup (tcu::TestContext& testCtx)
4484 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opundef", "Tests the OpUndef instruction"));
4485 vector<CaseParameter> cases;
4486 de::Random rnd (deStringHash(group->getName()));
4487 const int numElements = 100;
4488 vector<float> positiveFloats (numElements, 0);
4489 vector<float> negativeFloats (numElements, 0);
4490 const StringTemplate shaderTemplate (
4491 string(getComputeAsmShaderPreamble()) +
4493 "OpSource GLSL 430\n"
4494 "OpName %main \"main\"\n"
4495 "OpName %id \"gl_GlobalInvocationID\"\n"
4497 "OpDecorate %id BuiltIn GlobalInvocationId\n"
4499 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
4500 "%uvec2 = OpTypeVector %u32 2\n"
4501 "%fvec4 = OpTypeVector %f32 4\n"
4502 "%fmat33 = OpTypeMatrix %fvec3 3\n"
4503 "%image = OpTypeImage %f32 2D 0 0 0 1 Unknown\n"
4504 "%sampler = OpTypeSampler\n"
4505 "%simage = OpTypeSampledImage %image\n"
4506 "%const100 = OpConstant %u32 100\n"
4507 "%uarr100 = OpTypeArray %i32 %const100\n"
4508 "%struct = OpTypeStruct %f32 %i32 %u32\n"
4509 "%pointer = OpTypePointer Function %i32\n"
4510 + string(getComputeAsmInputOutputBuffer()) +
4512 "%id = OpVariable %uvec3ptr Input\n"
4513 "%zero = OpConstant %i32 0\n"
4515 "%main = OpFunction %void None %voidf\n"
4516 "%label = OpLabel\n"
4518 "%undef = OpUndef ${TYPE}\n"
4520 "%idval = OpLoad %uvec3 %id\n"
4521 "%x = OpCompositeExtract %u32 %idval 0\n"
4523 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
4524 "%inval = OpLoad %f32 %inloc\n"
4525 "%neg = OpFNegate %f32 %inval\n"
4526 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
4527 " OpStore %outloc %neg\n"
4529 " OpFunctionEnd\n");
4531 cases.push_back(CaseParameter("bool", "%bool"));
4532 cases.push_back(CaseParameter("sint32", "%i32"));
4533 cases.push_back(CaseParameter("uint32", "%u32"));
4534 cases.push_back(CaseParameter("float32", "%f32"));
4535 cases.push_back(CaseParameter("vec4float32", "%fvec4"));
4536 cases.push_back(CaseParameter("vec2uint32", "%uvec2"));
4537 cases.push_back(CaseParameter("matrix", "%fmat33"));
4538 cases.push_back(CaseParameter("image", "%image"));
4539 cases.push_back(CaseParameter("sampler", "%sampler"));
4540 cases.push_back(CaseParameter("sampledimage", "%simage"));
4541 cases.push_back(CaseParameter("array", "%uarr100"));
4542 cases.push_back(CaseParameter("runtimearray", "%f32arr"));
4543 cases.push_back(CaseParameter("struct", "%struct"));
4544 cases.push_back(CaseParameter("pointer", "%pointer"));
4546 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
4548 for (size_t ndx = 0; ndx < numElements; ++ndx)
4549 negativeFloats[ndx] = -positiveFloats[ndx];
4551 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
4553 map<string, string> specializations;
4554 ComputeShaderSpec spec;
4556 specializations["TYPE"] = cases[caseNdx].param;
4557 spec.assembly = shaderTemplate.specialize(specializations);
4558 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
4559 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
4560 spec.numWorkGroups = IVec3(numElements, 1, 1);
4562 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
4565 return group.release();
4569 tcu::TestCaseGroup* createOpSourceTests (tcu::TestContext& testCtx)
4571 struct NameCodePair { string name, code; };
4572 RGBA defaultColors[4];
4573 de::MovePtr<tcu::TestCaseGroup> opSourceTests (new tcu::TestCaseGroup(testCtx, "opsource", "OpSource instruction"));
4574 const std::string opsourceGLSLWithFile = "%opsrcfile = OpString \"foo.vert\"\nOpSource GLSL 450 %opsrcfile ";
4575 map<string, string> fragments = passthruFragments();
4576 const NameCodePair tests[] =
4578 {"unknown", "OpSource Unknown 321"},
4579 {"essl", "OpSource ESSL 310"},
4580 {"glsl", "OpSource GLSL 450"},
4581 {"opencl_cpp", "OpSource OpenCL_CPP 120"},
4582 {"opencl_c", "OpSource OpenCL_C 120"},
4583 {"multiple", "OpSource GLSL 450\nOpSource GLSL 450"},
4584 {"file", opsourceGLSLWithFile},
4585 {"source", opsourceGLSLWithFile + "\"void main(){}\""},
4586 // Longest possible source string: SPIR-V limits instructions to 65535
4587 // words, of which the first 4 are opsourceGLSLWithFile; the rest will
4588 // contain 65530 UTF8 characters (one word each) plus one last word
4589 // containing 3 ASCII characters and \0.
4590 {"longsource", opsourceGLSLWithFile + '"' + makeLongUTF8String(65530) + "ccc" + '"'}
4593 getDefaultColors(defaultColors);
4594 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameCodePair); ++testNdx)
4596 fragments["debug"] = tests[testNdx].code;
4597 createTestsForAllStages(tests[testNdx].name, defaultColors, defaultColors, fragments, opSourceTests.get());
4600 return opSourceTests.release();
4603 tcu::TestCaseGroup* createOpSourceContinuedTests (tcu::TestContext& testCtx)
4605 struct NameCodePair { string name, code; };
4606 RGBA defaultColors[4];
4607 de::MovePtr<tcu::TestCaseGroup> opSourceTests (new tcu::TestCaseGroup(testCtx, "opsourcecontinued", "OpSourceContinued instruction"));
4608 map<string, string> fragments = passthruFragments();
4609 const std::string opsource = "%opsrcfile = OpString \"foo.vert\"\nOpSource GLSL 450 %opsrcfile \"void main(){}\"\n";
4610 const NameCodePair tests[] =
4612 {"empty", opsource + "OpSourceContinued \"\""},
4613 {"short", opsource + "OpSourceContinued \"abcde\""},
4614 {"multiple", opsource + "OpSourceContinued \"abcde\"\nOpSourceContinued \"fghij\""},
4615 // Longest possible source string: SPIR-V limits instructions to 65535
4616 // words, of which the first one is OpSourceContinued/length; the rest
4617 // will contain 65533 UTF8 characters (one word each) plus one last word
4618 // containing 3 ASCII characters and \0.
4619 {"long", opsource + "OpSourceContinued \"" + makeLongUTF8String(65533) + "ccc\""}
4622 getDefaultColors(defaultColors);
4623 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameCodePair); ++testNdx)
4625 fragments["debug"] = tests[testNdx].code;
4626 createTestsForAllStages(tests[testNdx].name, defaultColors, defaultColors, fragments, opSourceTests.get());
4629 return opSourceTests.release();
4631 tcu::TestCaseGroup* createOpNoLineTests(tcu::TestContext& testCtx)
4633 RGBA defaultColors[4];
4634 de::MovePtr<tcu::TestCaseGroup> opLineTests (new tcu::TestCaseGroup(testCtx, "opnoline", "OpNoLine instruction"));
4635 map<string, string> fragments;
4636 getDefaultColors(defaultColors);
4637 fragments["debug"] =
4638 "%name = OpString \"name\"\n";
4640 fragments["pre_main"] =
4643 "OpLine %name 1 1\n"
4645 "OpLine %name 1 1\n"
4646 "OpLine %name 1 1\n"
4647 "%second_function = OpFunction %v4f32 None %v4f32_function\n"
4649 "OpLine %name 1 1\n"
4651 "OpLine %name 1 1\n"
4652 "OpLine %name 1 1\n"
4653 "%second_param1 = OpFunctionParameter %v4f32\n"
4656 "%label_secondfunction = OpLabel\n"
4658 "OpReturnValue %second_param1\n"
4663 fragments["testfun"] =
4664 // A %test_code function that returns its argument unchanged.
4667 "OpLine %name 1 1\n"
4668 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
4670 "%param1 = OpFunctionParameter %v4f32\n"
4673 "%label_testfun = OpLabel\n"
4675 "%val1 = OpFunctionCall %v4f32 %second_function %param1\n"
4676 "OpReturnValue %val1\n"
4678 "OpLine %name 1 1\n"
4681 createTestsForAllStages("opnoline", defaultColors, defaultColors, fragments, opLineTests.get());
4683 return opLineTests.release();
4686 tcu::TestCaseGroup* createOpModuleProcessedTests(tcu::TestContext& testCtx)
4688 RGBA defaultColors[4];
4689 de::MovePtr<tcu::TestCaseGroup> opModuleProcessedTests (new tcu::TestCaseGroup(testCtx, "opmoduleprocessed", "OpModuleProcessed instruction"));
4690 map<string, string> fragments;
4691 std::vector<std::string> noExtensions;
4692 GraphicsResources resources;
4694 getDefaultColors(defaultColors);
4695 resources.verifyBinary = veryfiBinaryShader;
4696 resources.spirvVersion = SPIRV_VERSION_1_3;
4698 fragments["moduleprocessed"] =
4699 "OpModuleProcessed \"VULKAN CTS\"\n"
4700 "OpModuleProcessed \"Negative values\"\n"
4701 "OpModuleProcessed \"Date: 2017/09/21\"\n";
4703 fragments["pre_main"] =
4704 "%second_function = OpFunction %v4f32 None %v4f32_function\n"
4705 "%second_param1 = OpFunctionParameter %v4f32\n"
4706 "%label_secondfunction = OpLabel\n"
4707 "OpReturnValue %second_param1\n"
4710 fragments["testfun"] =
4711 // A %test_code function that returns its argument unchanged.
4712 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
4713 "%param1 = OpFunctionParameter %v4f32\n"
4714 "%label_testfun = OpLabel\n"
4715 "%val1 = OpFunctionCall %v4f32 %second_function %param1\n"
4716 "OpReturnValue %val1\n"
4719 createTestsForAllStages ("opmoduleprocessed", defaultColors, defaultColors, fragments, resources, noExtensions, opModuleProcessedTests.get());
4721 return opModuleProcessedTests.release();
4725 tcu::TestCaseGroup* createOpLineTests(tcu::TestContext& testCtx)
4727 RGBA defaultColors[4];
4728 de::MovePtr<tcu::TestCaseGroup> opLineTests (new tcu::TestCaseGroup(testCtx, "opline", "OpLine instruction"));
4729 map<string, string> fragments;
4730 std::vector<std::pair<std::string, std::string> > problemStrings;
4732 problemStrings.push_back(std::make_pair<std::string, std::string>("empty_name", ""));
4733 problemStrings.push_back(std::make_pair<std::string, std::string>("short_name", "short_name"));
4734 problemStrings.push_back(std::make_pair<std::string, std::string>("long_name", makeLongUTF8String(65530) + "ccc"));
4735 getDefaultColors(defaultColors);
4737 fragments["debug"] =
4738 "%other_name = OpString \"other_name\"\n";
4740 fragments["pre_main"] =
4741 "OpLine %file_name 32 0\n"
4742 "OpLine %file_name 32 32\n"
4743 "OpLine %file_name 32 40\n"
4744 "OpLine %other_name 32 40\n"
4745 "OpLine %other_name 0 100\n"
4746 "OpLine %other_name 0 4294967295\n"
4747 "OpLine %other_name 4294967295 0\n"
4748 "OpLine %other_name 32 40\n"
4749 "OpLine %file_name 0 0\n"
4750 "%second_function = OpFunction %v4f32 None %v4f32_function\n"
4751 "OpLine %file_name 1 0\n"
4752 "%second_param1 = OpFunctionParameter %v4f32\n"
4753 "OpLine %file_name 1 3\n"
4754 "OpLine %file_name 1 2\n"
4755 "%label_secondfunction = OpLabel\n"
4756 "OpLine %file_name 0 2\n"
4757 "OpReturnValue %second_param1\n"
4759 "OpLine %file_name 0 2\n"
4760 "OpLine %file_name 0 2\n";
4762 fragments["testfun"] =
4763 // A %test_code function that returns its argument unchanged.
4764 "OpLine %file_name 1 0\n"
4765 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
4766 "OpLine %file_name 16 330\n"
4767 "%param1 = OpFunctionParameter %v4f32\n"
4768 "OpLine %file_name 14 442\n"
4769 "%label_testfun = OpLabel\n"
4770 "OpLine %file_name 11 1024\n"
4771 "%val1 = OpFunctionCall %v4f32 %second_function %param1\n"
4772 "OpLine %file_name 2 97\n"
4773 "OpReturnValue %val1\n"
4775 "OpLine %file_name 5 32\n";
4777 for (size_t i = 0; i < problemStrings.size(); ++i)
4779 map<string, string> testFragments = fragments;
4780 testFragments["debug"] += "%file_name = OpString \"" + problemStrings[i].second + "\"\n";
4781 createTestsForAllStages(string("opline") + "_" + problemStrings[i].first, defaultColors, defaultColors, testFragments, opLineTests.get());
4784 return opLineTests.release();
4787 tcu::TestCaseGroup* createOpConstantNullTests(tcu::TestContext& testCtx)
4789 de::MovePtr<tcu::TestCaseGroup> opConstantNullTests (new tcu::TestCaseGroup(testCtx, "opconstantnull", "OpConstantNull instruction"));
4793 const char functionStart[] =
4794 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
4795 "%param1 = OpFunctionParameter %v4f32\n"
4798 const char functionEnd[] =
4799 "OpReturnValue %transformed_param\n"
4802 struct NameConstantsCode
4809 NameConstantsCode tests[] =
4813 "%cnull = OpConstantNull %v4f32\n",
4814 "%transformed_param = OpFAdd %v4f32 %param1 %cnull\n"
4818 "%cnull = OpConstantNull %f32\n",
4819 "%vp = OpVariable %fp_v4f32 Function\n"
4820 "%v = OpLoad %v4f32 %vp\n"
4821 "%v0 = OpVectorInsertDynamic %v4f32 %v %cnull %c_i32_0\n"
4822 "%v1 = OpVectorInsertDynamic %v4f32 %v0 %cnull %c_i32_1\n"
4823 "%v2 = OpVectorInsertDynamic %v4f32 %v1 %cnull %c_i32_2\n"
4824 "%v3 = OpVectorInsertDynamic %v4f32 %v2 %cnull %c_i32_3\n"
4825 "%transformed_param = OpFAdd %v4f32 %param1 %v3\n"
4829 "%cnull = OpConstantNull %bool\n",
4830 "%v = OpVariable %fp_v4f32 Function\n"
4831 " OpStore %v %param1\n"
4832 " OpSelectionMerge %false_label None\n"
4833 " OpBranchConditional %cnull %true_label %false_label\n"
4834 "%true_label = OpLabel\n"
4835 " OpStore %v %c_v4f32_0_5_0_5_0_5_0_5\n"
4836 " OpBranch %false_label\n"
4837 "%false_label = OpLabel\n"
4838 "%transformed_param = OpLoad %v4f32 %v\n"
4842 "%cnull = OpConstantNull %i32\n",
4843 "%v = OpVariable %fp_v4f32 Function %c_v4f32_0_5_0_5_0_5_0_5\n"
4844 "%b = OpIEqual %bool %cnull %c_i32_0\n"
4845 " OpSelectionMerge %false_label None\n"
4846 " OpBranchConditional %b %true_label %false_label\n"
4847 "%true_label = OpLabel\n"
4848 " OpStore %v %param1\n"
4849 " OpBranch %false_label\n"
4850 "%false_label = OpLabel\n"
4851 "%transformed_param = OpLoad %v4f32 %v\n"
4855 "%stype = OpTypeStruct %f32 %v4f32\n"
4856 "%fp_stype = OpTypePointer Function %stype\n"
4857 "%cnull = OpConstantNull %stype\n",
4858 "%v = OpVariable %fp_stype Function %cnull\n"
4859 "%f = OpAccessChain %fp_v4f32 %v %c_i32_1\n"
4860 "%f_val = OpLoad %v4f32 %f\n"
4861 "%transformed_param = OpFAdd %v4f32 %param1 %f_val\n"
4865 "%a4_v4f32 = OpTypeArray %v4f32 %c_u32_4\n"
4866 "%fp_a4_v4f32 = OpTypePointer Function %a4_v4f32\n"
4867 "%cnull = OpConstantNull %a4_v4f32\n",
4868 "%v = OpVariable %fp_a4_v4f32 Function %cnull\n"
4869 "%f = OpAccessChain %fp_v4f32 %v %c_u32_0\n"
4870 "%f1 = OpAccessChain %fp_v4f32 %v %c_u32_1\n"
4871 "%f2 = OpAccessChain %fp_v4f32 %v %c_u32_2\n"
4872 "%f3 = OpAccessChain %fp_v4f32 %v %c_u32_3\n"
4873 "%f_val = OpLoad %v4f32 %f\n"
4874 "%f1_val = OpLoad %v4f32 %f1\n"
4875 "%f2_val = OpLoad %v4f32 %f2\n"
4876 "%f3_val = OpLoad %v4f32 %f3\n"
4877 "%t0 = OpFAdd %v4f32 %param1 %f_val\n"
4878 "%t1 = OpFAdd %v4f32 %t0 %f1_val\n"
4879 "%t2 = OpFAdd %v4f32 %t1 %f2_val\n"
4880 "%transformed_param = OpFAdd %v4f32 %t2 %f3_val\n"
4884 "%mat4x4_f32 = OpTypeMatrix %v4f32 4\n"
4885 "%cnull = OpConstantNull %mat4x4_f32\n",
4886 // Our null matrix * any vector should result in a zero vector.
4887 "%v = OpVectorTimesMatrix %v4f32 %param1 %cnull\n"
4888 "%transformed_param = OpFAdd %v4f32 %param1 %v\n"
4892 getHalfColorsFullAlpha(colors);
4894 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameConstantsCode); ++testNdx)
4896 map<string, string> fragments;
4897 fragments["pre_main"] = tests[testNdx].constants;
4898 fragments["testfun"] = string(functionStart) + tests[testNdx].code + functionEnd;
4899 createTestsForAllStages(tests[testNdx].name, colors, colors, fragments, opConstantNullTests.get());
4901 return opConstantNullTests.release();
4903 tcu::TestCaseGroup* createOpConstantCompositeTests(tcu::TestContext& testCtx)
4905 de::MovePtr<tcu::TestCaseGroup> opConstantCompositeTests (new tcu::TestCaseGroup(testCtx, "opconstantcomposite", "OpConstantComposite instruction"));
4906 RGBA inputColors[4];
4907 RGBA outputColors[4];
4910 const char functionStart[] =
4911 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
4912 "%param1 = OpFunctionParameter %v4f32\n"
4915 const char functionEnd[] =
4916 "OpReturnValue %transformed_param\n"
4919 struct NameConstantsCode
4926 NameConstantsCode tests[] =
4931 "%cval = OpConstantComposite %v4f32 %c_f32_0_5 %c_f32_0_5 %c_f32_0_5 %c_f32_0\n",
4932 "%transformed_param = OpFAdd %v4f32 %param1 %cval\n"
4937 "%stype = OpTypeStruct %v4f32 %f32\n"
4938 "%fp_stype = OpTypePointer Function %stype\n"
4939 "%f32_n_1 = OpConstant %f32 -1.0\n"
4940 "%f32_1_5 = OpConstant %f32 !0x3fc00000\n" // +1.5
4941 "%cvec = OpConstantComposite %v4f32 %f32_1_5 %f32_1_5 %f32_1_5 %c_f32_1\n"
4942 "%cval = OpConstantComposite %stype %cvec %f32_n_1\n",
4944 "%v = OpVariable %fp_stype Function %cval\n"
4945 "%vec_ptr = OpAccessChain %fp_v4f32 %v %c_u32_0\n"
4946 "%f32_ptr = OpAccessChain %fp_f32 %v %c_u32_1\n"
4947 "%vec_val = OpLoad %v4f32 %vec_ptr\n"
4948 "%f32_val = OpLoad %f32 %f32_ptr\n"
4949 "%tmp1 = OpVectorTimesScalar %v4f32 %c_v4f32_1_1_1_1 %f32_val\n" // vec4(-1)
4950 "%tmp2 = OpFAdd %v4f32 %tmp1 %param1\n" // param1 + vec4(-1)
4951 "%transformed_param = OpFAdd %v4f32 %tmp2 %vec_val\n" // param1 + vec4(-1) + vec4(1.5, 1.5, 1.5, 1.0)
4954 // [1|0|0|0.5] [x] = x + 0.5
4955 // [0|1|0|0.5] [y] = y + 0.5
4956 // [0|0|1|0.5] [z] = z + 0.5
4957 // [0|0|0|1 ] [1] = 1
4960 "%mat4x4_f32 = OpTypeMatrix %v4f32 4\n"
4961 "%v4f32_1_0_0_0 = OpConstantComposite %v4f32 %c_f32_1 %c_f32_0 %c_f32_0 %c_f32_0\n"
4962 "%v4f32_0_1_0_0 = OpConstantComposite %v4f32 %c_f32_0 %c_f32_1 %c_f32_0 %c_f32_0\n"
4963 "%v4f32_0_0_1_0 = OpConstantComposite %v4f32 %c_f32_0 %c_f32_0 %c_f32_1 %c_f32_0\n"
4964 "%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"
4965 "%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",
4967 "%transformed_param = OpMatrixTimesVector %v4f32 %cval %param1\n"
4972 "%c_v4f32_1_1_1_0 = OpConstantComposite %v4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_0\n"
4973 "%fp_a4f32 = OpTypePointer Function %a4f32\n"
4974 "%f32_n_1 = OpConstant %f32 -1.0\n"
4975 "%f32_1_5 = OpConstant %f32 !0x3fc00000\n" // +1.5
4976 "%carr = OpConstantComposite %a4f32 %c_f32_0 %f32_n_1 %f32_1_5 %c_f32_0\n",
4978 "%v = OpVariable %fp_a4f32 Function %carr\n"
4979 "%f = OpAccessChain %fp_f32 %v %c_u32_0\n"
4980 "%f1 = OpAccessChain %fp_f32 %v %c_u32_1\n"
4981 "%f2 = OpAccessChain %fp_f32 %v %c_u32_2\n"
4982 "%f3 = OpAccessChain %fp_f32 %v %c_u32_3\n"
4983 "%f_val = OpLoad %f32 %f\n"
4984 "%f1_val = OpLoad %f32 %f1\n"
4985 "%f2_val = OpLoad %f32 %f2\n"
4986 "%f3_val = OpLoad %f32 %f3\n"
4987 "%ftot1 = OpFAdd %f32 %f_val %f1_val\n"
4988 "%ftot2 = OpFAdd %f32 %ftot1 %f2_val\n"
4989 "%ftot3 = OpFAdd %f32 %ftot2 %f3_val\n" // 0 - 1 + 1.5 + 0
4990 "%add_vec = OpVectorTimesScalar %v4f32 %c_v4f32_1_1_1_0 %ftot3\n"
4991 "%transformed_param = OpFAdd %v4f32 %param1 %add_vec\n"
4998 // [ 1.0, 1.0, 1.0, 1.0]
5002 // [ 0.0, 0.5, 0.0, 0.0]
5006 // [ 1.0, 1.0, 1.0, 1.0]
5009 "array_of_struct_of_array",
5011 "%c_v4f32_1_1_1_0 = OpConstantComposite %v4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_0\n"
5012 "%fp_a4f32 = OpTypePointer Function %a4f32\n"
5013 "%stype = OpTypeStruct %f32 %a4f32\n"
5014 "%a3stype = OpTypeArray %stype %c_u32_3\n"
5015 "%fp_a3stype = OpTypePointer Function %a3stype\n"
5016 "%ca4f32_0 = OpConstantComposite %a4f32 %c_f32_0 %c_f32_0_5 %c_f32_0 %c_f32_0\n"
5017 "%ca4f32_1 = OpConstantComposite %a4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_1\n"
5018 "%cstype1 = OpConstantComposite %stype %c_f32_0 %ca4f32_1\n"
5019 "%cstype2 = OpConstantComposite %stype %c_f32_1 %ca4f32_0\n"
5020 "%carr = OpConstantComposite %a3stype %cstype1 %cstype2 %cstype1",
5022 "%v = OpVariable %fp_a3stype Function %carr\n"
5023 "%f = OpAccessChain %fp_f32 %v %c_u32_1 %c_u32_1 %c_u32_1\n"
5024 "%f_l = OpLoad %f32 %f\n"
5025 "%add_vec = OpVectorTimesScalar %v4f32 %c_v4f32_1_1_1_0 %f_l\n"
5026 "%transformed_param = OpFAdd %v4f32 %param1 %add_vec\n"
5030 getHalfColorsFullAlpha(inputColors);
5031 outputColors[0] = RGBA(255, 255, 255, 255);
5032 outputColors[1] = RGBA(255, 127, 127, 255);
5033 outputColors[2] = RGBA(127, 255, 127, 255);
5034 outputColors[3] = RGBA(127, 127, 255, 255);
5036 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameConstantsCode); ++testNdx)
5038 map<string, string> fragments;
5039 fragments["pre_main"] = tests[testNdx].constants;
5040 fragments["testfun"] = string(functionStart) + tests[testNdx].code + functionEnd;
5041 createTestsForAllStages(tests[testNdx].name, inputColors, outputColors, fragments, opConstantCompositeTests.get());
5043 return opConstantCompositeTests.release();
5046 tcu::TestCaseGroup* createSelectionBlockOrderTests(tcu::TestContext& testCtx)
5048 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "selection_block_order", "Out-of-order blocks for selection"));
5049 RGBA inputColors[4];
5050 RGBA outputColors[4];
5051 map<string, string> fragments;
5053 // vec4 test_code(vec4 param) {
5054 // vec4 result = param;
5055 // for (int i = 0; i < 4; ++i) {
5056 // if (i == 0) result[i] = 0.;
5057 // else result[i] = 1. - result[i];
5061 const char function[] =
5062 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5063 "%param1 = OpFunctionParameter %v4f32\n"
5065 "%iptr = OpVariable %fp_i32 Function\n"
5066 "%result = OpVariable %fp_v4f32 Function\n"
5067 " OpStore %iptr %c_i32_0\n"
5068 " OpStore %result %param1\n"
5071 // Loop entry block.
5073 "%ival = OpLoad %i32 %iptr\n"
5074 "%lt_4 = OpSLessThan %bool %ival %c_i32_4\n"
5075 " OpLoopMerge %exit %if_entry None\n"
5076 " OpBranchConditional %lt_4 %if_entry %exit\n"
5078 // Merge block for loop.
5080 "%ret = OpLoad %v4f32 %result\n"
5081 " OpReturnValue %ret\n"
5083 // If-statement entry block.
5084 "%if_entry = OpLabel\n"
5085 "%loc = OpAccessChain %fp_f32 %result %ival\n"
5086 "%eq_0 = OpIEqual %bool %ival %c_i32_0\n"
5087 " OpSelectionMerge %if_exit None\n"
5088 " OpBranchConditional %eq_0 %if_true %if_false\n"
5090 // False branch for if-statement.
5091 "%if_false = OpLabel\n"
5092 "%val = OpLoad %f32 %loc\n"
5093 "%sub = OpFSub %f32 %c_f32_1 %val\n"
5094 " OpStore %loc %sub\n"
5095 " OpBranch %if_exit\n"
5097 // Merge block for if-statement.
5098 "%if_exit = OpLabel\n"
5099 "%ival_next = OpIAdd %i32 %ival %c_i32_1\n"
5100 " OpStore %iptr %ival_next\n"
5103 // True branch for if-statement.
5104 "%if_true = OpLabel\n"
5105 " OpStore %loc %c_f32_0\n"
5106 " OpBranch %if_exit\n"
5110 fragments["testfun"] = function;
5112 inputColors[0] = RGBA(127, 127, 127, 0);
5113 inputColors[1] = RGBA(127, 0, 0, 0);
5114 inputColors[2] = RGBA(0, 127, 0, 0);
5115 inputColors[3] = RGBA(0, 0, 127, 0);
5117 outputColors[0] = RGBA(0, 128, 128, 255);
5118 outputColors[1] = RGBA(0, 255, 255, 255);
5119 outputColors[2] = RGBA(0, 128, 255, 255);
5120 outputColors[3] = RGBA(0, 255, 128, 255);
5122 createTestsForAllStages("out_of_order", inputColors, outputColors, fragments, group.get());
5124 return group.release();
5127 tcu::TestCaseGroup* createSwitchBlockOrderTests(tcu::TestContext& testCtx)
5129 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "switch_block_order", "Out-of-order blocks for switch"));
5130 RGBA inputColors[4];
5131 RGBA outputColors[4];
5132 map<string, string> fragments;
5134 const char typesAndConstants[] =
5135 "%c_f32_p2 = OpConstant %f32 0.2\n"
5136 "%c_f32_p4 = OpConstant %f32 0.4\n"
5137 "%c_f32_p6 = OpConstant %f32 0.6\n"
5138 "%c_f32_p8 = OpConstant %f32 0.8\n";
5140 // vec4 test_code(vec4 param) {
5141 // vec4 result = param;
5142 // for (int i = 0; i < 4; ++i) {
5144 // case 0: result[i] += .2; break;
5145 // case 1: result[i] += .6; break;
5146 // case 2: result[i] += .4; break;
5147 // case 3: result[i] += .8; break;
5148 // default: break; // unreachable
5153 const char function[] =
5154 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5155 "%param1 = OpFunctionParameter %v4f32\n"
5157 "%iptr = OpVariable %fp_i32 Function\n"
5158 "%result = OpVariable %fp_v4f32 Function\n"
5159 " OpStore %iptr %c_i32_0\n"
5160 " OpStore %result %param1\n"
5163 // Loop entry block.
5165 "%ival = OpLoad %i32 %iptr\n"
5166 "%lt_4 = OpSLessThan %bool %ival %c_i32_4\n"
5167 " OpLoopMerge %exit %switch_exit None\n"
5168 " OpBranchConditional %lt_4 %switch_entry %exit\n"
5170 // Merge block for loop.
5172 "%ret = OpLoad %v4f32 %result\n"
5173 " OpReturnValue %ret\n"
5175 // Switch-statement entry block.
5176 "%switch_entry = OpLabel\n"
5177 "%loc = OpAccessChain %fp_f32 %result %ival\n"
5178 "%val = OpLoad %f32 %loc\n"
5179 " OpSelectionMerge %switch_exit None\n"
5180 " OpSwitch %ival %switch_default 0 %case0 1 %case1 2 %case2 3 %case3\n"
5182 "%case2 = OpLabel\n"
5183 "%addp4 = OpFAdd %f32 %val %c_f32_p4\n"
5184 " OpStore %loc %addp4\n"
5185 " OpBranch %switch_exit\n"
5187 "%switch_default = OpLabel\n"
5190 "%case3 = OpLabel\n"
5191 "%addp8 = OpFAdd %f32 %val %c_f32_p8\n"
5192 " OpStore %loc %addp8\n"
5193 " OpBranch %switch_exit\n"
5195 "%case0 = OpLabel\n"
5196 "%addp2 = OpFAdd %f32 %val %c_f32_p2\n"
5197 " OpStore %loc %addp2\n"
5198 " OpBranch %switch_exit\n"
5200 // Merge block for switch-statement.
5201 "%switch_exit = OpLabel\n"
5202 "%ival_next = OpIAdd %i32 %ival %c_i32_1\n"
5203 " OpStore %iptr %ival_next\n"
5206 "%case1 = OpLabel\n"
5207 "%addp6 = OpFAdd %f32 %val %c_f32_p6\n"
5208 " OpStore %loc %addp6\n"
5209 " OpBranch %switch_exit\n"
5213 fragments["pre_main"] = typesAndConstants;
5214 fragments["testfun"] = function;
5216 inputColors[0] = RGBA(127, 27, 127, 51);
5217 inputColors[1] = RGBA(127, 0, 0, 51);
5218 inputColors[2] = RGBA(0, 27, 0, 51);
5219 inputColors[3] = RGBA(0, 0, 127, 51);
5221 outputColors[0] = RGBA(178, 180, 229, 255);
5222 outputColors[1] = RGBA(178, 153, 102, 255);
5223 outputColors[2] = RGBA(51, 180, 102, 255);
5224 outputColors[3] = RGBA(51, 153, 229, 255);
5226 createTestsForAllStages("out_of_order", inputColors, outputColors, fragments, group.get());
5228 return group.release();
5231 tcu::TestCaseGroup* createDecorationGroupTests(tcu::TestContext& testCtx)
5233 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "decoration_group", "Decoration group tests"));
5234 RGBA inputColors[4];
5235 RGBA outputColors[4];
5236 map<string, string> fragments;
5238 const char decorations[] =
5239 "OpDecorate %array_group ArrayStride 4\n"
5240 "OpDecorate %struct_member_group Offset 0\n"
5241 "%array_group = OpDecorationGroup\n"
5242 "%struct_member_group = OpDecorationGroup\n"
5244 "OpDecorate %group1 RelaxedPrecision\n"
5245 "OpDecorate %group3 RelaxedPrecision\n"
5246 "OpDecorate %group3 Invariant\n"
5247 "OpDecorate %group3 Restrict\n"
5248 "%group0 = OpDecorationGroup\n"
5249 "%group1 = OpDecorationGroup\n"
5250 "%group3 = OpDecorationGroup\n";
5252 const char typesAndConstants[] =
5253 "%a3f32 = OpTypeArray %f32 %c_u32_3\n"
5254 "%struct1 = OpTypeStruct %a3f32\n"
5255 "%struct2 = OpTypeStruct %a3f32\n"
5256 "%fp_struct1 = OpTypePointer Function %struct1\n"
5257 "%fp_struct2 = OpTypePointer Function %struct2\n"
5258 "%c_f32_2 = OpConstant %f32 2.\n"
5259 "%c_f32_n2 = OpConstant %f32 -2.\n"
5261 "%c_a3f32_1 = OpConstantComposite %a3f32 %c_f32_1 %c_f32_2 %c_f32_1\n"
5262 "%c_a3f32_2 = OpConstantComposite %a3f32 %c_f32_n1 %c_f32_n2 %c_f32_n1\n"
5263 "%c_struct1 = OpConstantComposite %struct1 %c_a3f32_1\n"
5264 "%c_struct2 = OpConstantComposite %struct2 %c_a3f32_2\n";
5266 const char function[] =
5267 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5268 "%param = OpFunctionParameter %v4f32\n"
5269 "%entry = OpLabel\n"
5270 "%result = OpVariable %fp_v4f32 Function\n"
5271 "%v_struct1 = OpVariable %fp_struct1 Function\n"
5272 "%v_struct2 = OpVariable %fp_struct2 Function\n"
5273 " OpStore %result %param\n"
5274 " OpStore %v_struct1 %c_struct1\n"
5275 " OpStore %v_struct2 %c_struct2\n"
5276 "%ptr1 = OpAccessChain %fp_f32 %v_struct1 %c_i32_0 %c_i32_2\n"
5277 "%val1 = OpLoad %f32 %ptr1\n"
5278 "%ptr2 = OpAccessChain %fp_f32 %v_struct2 %c_i32_0 %c_i32_2\n"
5279 "%val2 = OpLoad %f32 %ptr2\n"
5280 "%addvalues = OpFAdd %f32 %val1 %val2\n"
5281 "%ptr = OpAccessChain %fp_f32 %result %c_i32_1\n"
5282 "%val = OpLoad %f32 %ptr\n"
5283 "%addresult = OpFAdd %f32 %addvalues %val\n"
5284 " OpStore %ptr %addresult\n"
5285 "%ret = OpLoad %v4f32 %result\n"
5286 " OpReturnValue %ret\n"
5289 struct CaseNameDecoration
5295 CaseNameDecoration tests[] =
5298 "same_decoration_group_on_multiple_types",
5299 "OpGroupMemberDecorate %struct_member_group %struct1 0 %struct2 0\n"
5302 "empty_decoration_group",
5303 "OpGroupDecorate %group0 %a3f32\n"
5304 "OpGroupDecorate %group0 %result\n"
5307 "one_element_decoration_group",
5308 "OpGroupDecorate %array_group %a3f32\n"
5311 "multiple_elements_decoration_group",
5312 "OpGroupDecorate %group3 %v_struct1\n"
5315 "multiple_decoration_groups_on_same_variable",
5316 "OpGroupDecorate %group0 %v_struct2\n"
5317 "OpGroupDecorate %group1 %v_struct2\n"
5318 "OpGroupDecorate %group3 %v_struct2\n"
5321 "same_decoration_group_multiple_times",
5322 "OpGroupDecorate %group1 %addvalues\n"
5323 "OpGroupDecorate %group1 %addvalues\n"
5324 "OpGroupDecorate %group1 %addvalues\n"
5329 getHalfColorsFullAlpha(inputColors);
5330 getHalfColorsFullAlpha(outputColors);
5332 for (size_t idx = 0; idx < (sizeof(tests) / sizeof(tests[0])); ++idx)
5334 fragments["decoration"] = decorations + tests[idx].decoration;
5335 fragments["pre_main"] = typesAndConstants;
5336 fragments["testfun"] = function;
5338 createTestsForAllStages(tests[idx].name, inputColors, outputColors, fragments, group.get());
5341 return group.release();
5344 struct SpecConstantTwoIntGraphicsCase
5346 const char* caseName;
5347 const char* scDefinition0;
5348 const char* scDefinition1;
5349 const char* scResultType;
5350 const char* scOperation;
5351 deInt32 scActualValue0;
5352 deInt32 scActualValue1;
5353 const char* resultOperation;
5354 RGBA expectedColors[4];
5356 SpecConstantTwoIntGraphicsCase (const char* name,
5357 const char* definition0,
5358 const char* definition1,
5359 const char* resultType,
5360 const char* operation,
5363 const char* resultOp,
5364 const RGBA (&output)[4])
5366 , scDefinition0 (definition0)
5367 , scDefinition1 (definition1)
5368 , scResultType (resultType)
5369 , scOperation (operation)
5370 , scActualValue0 (value0)
5371 , scActualValue1 (value1)
5372 , resultOperation (resultOp)
5374 expectedColors[0] = output[0];
5375 expectedColors[1] = output[1];
5376 expectedColors[2] = output[2];
5377 expectedColors[3] = output[3];
5381 tcu::TestCaseGroup* createSpecConstantTests (tcu::TestContext& testCtx)
5383 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opspecconstantop", "Test the OpSpecConstantOp instruction"));
5384 vector<SpecConstantTwoIntGraphicsCase> cases;
5385 RGBA inputColors[4];
5386 RGBA outputColors0[4];
5387 RGBA outputColors1[4];
5388 RGBA outputColors2[4];
5390 const char decorations1[] =
5391 "OpDecorate %sc_0 SpecId 0\n"
5392 "OpDecorate %sc_1 SpecId 1\n";
5394 const char typesAndConstants1[] =
5395 "%sc_0 = OpSpecConstant${SC_DEF0}\n"
5396 "%sc_1 = OpSpecConstant${SC_DEF1}\n"
5397 "%sc_op = OpSpecConstantOp ${SC_RESULT_TYPE} ${SC_OP}\n";
5399 const char function1[] =
5400 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5401 "%param = OpFunctionParameter %v4f32\n"
5402 "%label = OpLabel\n"
5403 "%result = OpVariable %fp_v4f32 Function\n"
5404 " OpStore %result %param\n"
5405 "%gen = ${GEN_RESULT}\n"
5406 "%index = OpIAdd %i32 %gen %c_i32_1\n"
5407 "%loc = OpAccessChain %fp_f32 %result %index\n"
5408 "%val = OpLoad %f32 %loc\n"
5409 "%add = OpFAdd %f32 %val %c_f32_0_5\n"
5410 " OpStore %loc %add\n"
5411 "%ret = OpLoad %v4f32 %result\n"
5412 " OpReturnValue %ret\n"
5415 inputColors[0] = RGBA(127, 127, 127, 255);
5416 inputColors[1] = RGBA(127, 0, 0, 255);
5417 inputColors[2] = RGBA(0, 127, 0, 255);
5418 inputColors[3] = RGBA(0, 0, 127, 255);
5420 // Derived from inputColors[x] by adding 128 to inputColors[x][0].
5421 outputColors0[0] = RGBA(255, 127, 127, 255);
5422 outputColors0[1] = RGBA(255, 0, 0, 255);
5423 outputColors0[2] = RGBA(128, 127, 0, 255);
5424 outputColors0[3] = RGBA(128, 0, 127, 255);
5426 // Derived from inputColors[x] by adding 128 to inputColors[x][1].
5427 outputColors1[0] = RGBA(127, 255, 127, 255);
5428 outputColors1[1] = RGBA(127, 128, 0, 255);
5429 outputColors1[2] = RGBA(0, 255, 0, 255);
5430 outputColors1[3] = RGBA(0, 128, 127, 255);
5432 // Derived from inputColors[x] by adding 128 to inputColors[x][2].
5433 outputColors2[0] = RGBA(127, 127, 255, 255);
5434 outputColors2[1] = RGBA(127, 0, 128, 255);
5435 outputColors2[2] = RGBA(0, 127, 128, 255);
5436 outputColors2[3] = RGBA(0, 0, 255, 255);
5438 const char addZeroToSc[] = "OpIAdd %i32 %c_i32_0 %sc_op";
5439 const char selectTrueUsingSc[] = "OpSelect %i32 %sc_op %c_i32_1 %c_i32_0";
5440 const char selectFalseUsingSc[] = "OpSelect %i32 %sc_op %c_i32_0 %c_i32_1";
5442 cases.push_back(SpecConstantTwoIntGraphicsCase("iadd", " %i32 0", " %i32 0", "%i32", "IAdd %sc_0 %sc_1", 19, -20, addZeroToSc, outputColors0));
5443 cases.push_back(SpecConstantTwoIntGraphicsCase("isub", " %i32 0", " %i32 0", "%i32", "ISub %sc_0 %sc_1", 19, 20, addZeroToSc, outputColors0));
5444 cases.push_back(SpecConstantTwoIntGraphicsCase("imul", " %i32 0", " %i32 0", "%i32", "IMul %sc_0 %sc_1", -1, -1, addZeroToSc, outputColors2));
5445 cases.push_back(SpecConstantTwoIntGraphicsCase("sdiv", " %i32 0", " %i32 0", "%i32", "SDiv %sc_0 %sc_1", -126, 126, addZeroToSc, outputColors0));
5446 cases.push_back(SpecConstantTwoIntGraphicsCase("udiv", " %i32 0", " %i32 0", "%i32", "UDiv %sc_0 %sc_1", 126, 126, addZeroToSc, outputColors2));
5447 cases.push_back(SpecConstantTwoIntGraphicsCase("srem", " %i32 0", " %i32 0", "%i32", "SRem %sc_0 %sc_1", 3, 2, addZeroToSc, outputColors2));
5448 cases.push_back(SpecConstantTwoIntGraphicsCase("smod", " %i32 0", " %i32 0", "%i32", "SMod %sc_0 %sc_1", 3, 2, addZeroToSc, outputColors2));
5449 cases.push_back(SpecConstantTwoIntGraphicsCase("umod", " %i32 0", " %i32 0", "%i32", "UMod %sc_0 %sc_1", 1001, 500, addZeroToSc, outputColors2));
5450 cases.push_back(SpecConstantTwoIntGraphicsCase("bitwiseand", " %i32 0", " %i32 0", "%i32", "BitwiseAnd %sc_0 %sc_1", 0x33, 0x0d, addZeroToSc, outputColors2));
5451 cases.push_back(SpecConstantTwoIntGraphicsCase("bitwiseor", " %i32 0", " %i32 0", "%i32", "BitwiseOr %sc_0 %sc_1", 0, 1, addZeroToSc, outputColors2));
5452 cases.push_back(SpecConstantTwoIntGraphicsCase("bitwisexor", " %i32 0", " %i32 0", "%i32", "BitwiseXor %sc_0 %sc_1", 0x2e, 0x2f, addZeroToSc, outputColors2));
5453 cases.push_back(SpecConstantTwoIntGraphicsCase("shiftrightlogical", " %i32 0", " %i32 0", "%i32", "ShiftRightLogical %sc_0 %sc_1", 2, 1, addZeroToSc, outputColors2));
5454 cases.push_back(SpecConstantTwoIntGraphicsCase("shiftrightarithmetic", " %i32 0", " %i32 0", "%i32", "ShiftRightArithmetic %sc_0 %sc_1", -4, 2, addZeroToSc, outputColors0));
5455 cases.push_back(SpecConstantTwoIntGraphicsCase("shiftleftlogical", " %i32 0", " %i32 0", "%i32", "ShiftLeftLogical %sc_0 %sc_1", 1, 0, addZeroToSc, outputColors2));
5456 cases.push_back(SpecConstantTwoIntGraphicsCase("slessthan", " %i32 0", " %i32 0", "%bool", "SLessThan %sc_0 %sc_1", -20, -10, selectTrueUsingSc, outputColors2));
5457 cases.push_back(SpecConstantTwoIntGraphicsCase("ulessthan", " %i32 0", " %i32 0", "%bool", "ULessThan %sc_0 %sc_1", 10, 20, selectTrueUsingSc, outputColors2));
5458 cases.push_back(SpecConstantTwoIntGraphicsCase("sgreaterthan", " %i32 0", " %i32 0", "%bool", "SGreaterThan %sc_0 %sc_1", -1000, 50, selectFalseUsingSc, outputColors2));
5459 cases.push_back(SpecConstantTwoIntGraphicsCase("ugreaterthan", " %i32 0", " %i32 0", "%bool", "UGreaterThan %sc_0 %sc_1", 10, 5, selectTrueUsingSc, outputColors2));
5460 cases.push_back(SpecConstantTwoIntGraphicsCase("slessthanequal", " %i32 0", " %i32 0", "%bool", "SLessThanEqual %sc_0 %sc_1", -10, -10, selectTrueUsingSc, outputColors2));
5461 cases.push_back(SpecConstantTwoIntGraphicsCase("ulessthanequal", " %i32 0", " %i32 0", "%bool", "ULessThanEqual %sc_0 %sc_1", 50, 100, selectTrueUsingSc, outputColors2));
5462 cases.push_back(SpecConstantTwoIntGraphicsCase("sgreaterthanequal", " %i32 0", " %i32 0", "%bool", "SGreaterThanEqual %sc_0 %sc_1", -1000, 50, selectFalseUsingSc, outputColors2));
5463 cases.push_back(SpecConstantTwoIntGraphicsCase("ugreaterthanequal", " %i32 0", " %i32 0", "%bool", "UGreaterThanEqual %sc_0 %sc_1", 10, 10, selectTrueUsingSc, outputColors2));
5464 cases.push_back(SpecConstantTwoIntGraphicsCase("iequal", " %i32 0", " %i32 0", "%bool", "IEqual %sc_0 %sc_1", 42, 24, selectFalseUsingSc, outputColors2));
5465 cases.push_back(SpecConstantTwoIntGraphicsCase("logicaland", "True %bool", "True %bool", "%bool", "LogicalAnd %sc_0 %sc_1", 0, 1, selectFalseUsingSc, outputColors2));
5466 cases.push_back(SpecConstantTwoIntGraphicsCase("logicalor", "False %bool", "False %bool", "%bool", "LogicalOr %sc_0 %sc_1", 1, 0, selectTrueUsingSc, outputColors2));
5467 cases.push_back(SpecConstantTwoIntGraphicsCase("logicalequal", "True %bool", "True %bool", "%bool", "LogicalEqual %sc_0 %sc_1", 0, 1, selectFalseUsingSc, outputColors2));
5468 cases.push_back(SpecConstantTwoIntGraphicsCase("logicalnotequal", "False %bool", "False %bool", "%bool", "LogicalNotEqual %sc_0 %sc_1", 1, 0, selectTrueUsingSc, outputColors2));
5469 cases.push_back(SpecConstantTwoIntGraphicsCase("snegate", " %i32 0", " %i32 0", "%i32", "SNegate %sc_0", -1, 0, addZeroToSc, outputColors2));
5470 cases.push_back(SpecConstantTwoIntGraphicsCase("not", " %i32 0", " %i32 0", "%i32", "Not %sc_0", -2, 0, addZeroToSc, outputColors2));
5471 cases.push_back(SpecConstantTwoIntGraphicsCase("logicalnot", "False %bool", "False %bool", "%bool", "LogicalNot %sc_0", 1, 0, selectFalseUsingSc, outputColors2));
5472 cases.push_back(SpecConstantTwoIntGraphicsCase("select", "False %bool", " %i32 0", "%i32", "Select %sc_0 %sc_1 %c_i32_0", 1, 1, addZeroToSc, outputColors2));
5473 // OpSConvert, OpFConvert: these two instructions involve ints/floats of different bitwidths.
5474 // \todo[2015-12-1 antiagainst] OpQuantizeToF16
5476 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
5478 map<string, string> specializations;
5479 map<string, string> fragments;
5480 vector<deInt32> specConstants;
5482 specializations["SC_DEF0"] = cases[caseNdx].scDefinition0;
5483 specializations["SC_DEF1"] = cases[caseNdx].scDefinition1;
5484 specializations["SC_RESULT_TYPE"] = cases[caseNdx].scResultType;
5485 specializations["SC_OP"] = cases[caseNdx].scOperation;
5486 specializations["GEN_RESULT"] = cases[caseNdx].resultOperation;
5488 fragments["decoration"] = tcu::StringTemplate(decorations1).specialize(specializations);
5489 fragments["pre_main"] = tcu::StringTemplate(typesAndConstants1).specialize(specializations);
5490 fragments["testfun"] = tcu::StringTemplate(function1).specialize(specializations);
5492 specConstants.push_back(cases[caseNdx].scActualValue0);
5493 specConstants.push_back(cases[caseNdx].scActualValue1);
5495 createTestsForAllStages(cases[caseNdx].caseName, inputColors, cases[caseNdx].expectedColors, fragments, specConstants, group.get());
5498 const char decorations2[] =
5499 "OpDecorate %sc_0 SpecId 0\n"
5500 "OpDecorate %sc_1 SpecId 1\n"
5501 "OpDecorate %sc_2 SpecId 2\n";
5503 const char typesAndConstants2[] =
5504 "%v3i32 = OpTypeVector %i32 3\n"
5505 "%vec3_0 = OpConstantComposite %v3i32 %c_i32_0 %c_i32_0 %c_i32_0\n"
5506 "%vec3_undef = OpUndef %v3i32\n"
5508 "%sc_0 = OpSpecConstant %i32 0\n"
5509 "%sc_1 = OpSpecConstant %i32 0\n"
5510 "%sc_2 = OpSpecConstant %i32 0\n"
5511 "%sc_vec3_0 = OpSpecConstantOp %v3i32 CompositeInsert %sc_0 %vec3_0 0\n" // (sc_0, 0, 0)
5512 "%sc_vec3_1 = OpSpecConstantOp %v3i32 CompositeInsert %sc_1 %vec3_0 1\n" // (0, sc_1, 0)
5513 "%sc_vec3_2 = OpSpecConstantOp %v3i32 CompositeInsert %sc_2 %vec3_0 2\n" // (0, 0, sc_2)
5514 "%sc_vec3_0_s = OpSpecConstantOp %v3i32 VectorShuffle %sc_vec3_0 %vec3_undef 0 0xFFFFFFFF 2\n" // (sc_0, ???, 0)
5515 "%sc_vec3_1_s = OpSpecConstantOp %v3i32 VectorShuffle %sc_vec3_1 %vec3_undef 0xFFFFFFFF 1 0\n" // (???, sc_1, 0)
5516 "%sc_vec3_2_s = OpSpecConstantOp %v3i32 VectorShuffle %vec3_undef %sc_vec3_2 5 0xFFFFFFFF 5\n" // (sc_2, ???, sc_2)
5517 "%sc_vec3_01 = OpSpecConstantOp %v3i32 VectorShuffle %sc_vec3_0_s %sc_vec3_1_s 1 0 4\n" // (0, sc_0, sc_1)
5518 "%sc_vec3_012 = OpSpecConstantOp %v3i32 VectorShuffle %sc_vec3_01 %sc_vec3_2_s 5 1 2\n" // (sc_2, sc_0, sc_1)
5519 "%sc_ext_0 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 0\n" // sc_2
5520 "%sc_ext_1 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 1\n" // sc_0
5521 "%sc_ext_2 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 2\n" // sc_1
5522 "%sc_sub = OpSpecConstantOp %i32 ISub %sc_ext_0 %sc_ext_1\n" // (sc_2 - sc_0)
5523 "%sc_final = OpSpecConstantOp %i32 IMul %sc_sub %sc_ext_2\n"; // (sc_2 - sc_0) * sc_1
5525 const char function2[] =
5526 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5527 "%param = OpFunctionParameter %v4f32\n"
5528 "%label = OpLabel\n"
5529 "%result = OpVariable %fp_v4f32 Function\n"
5530 " OpStore %result %param\n"
5531 "%loc = OpAccessChain %fp_f32 %result %sc_final\n"
5532 "%val = OpLoad %f32 %loc\n"
5533 "%add = OpFAdd %f32 %val %c_f32_0_5\n"
5534 " OpStore %loc %add\n"
5535 "%ret = OpLoad %v4f32 %result\n"
5536 " OpReturnValue %ret\n"
5539 map<string, string> fragments;
5540 vector<deInt32> specConstants;
5542 fragments["decoration"] = decorations2;
5543 fragments["pre_main"] = typesAndConstants2;
5544 fragments["testfun"] = function2;
5546 specConstants.push_back(56789);
5547 specConstants.push_back(-2);
5548 specConstants.push_back(56788);
5550 createTestsForAllStages("vector_related", inputColors, outputColors2, fragments, specConstants, group.get());
5552 return group.release();
5555 tcu::TestCaseGroup* createOpPhiTests(tcu::TestContext& testCtx)
5557 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opphi", "Test the OpPhi instruction"));
5558 RGBA inputColors[4];
5559 RGBA outputColors1[4];
5560 RGBA outputColors2[4];
5561 RGBA outputColors3[4];
5562 map<string, string> fragments1;
5563 map<string, string> fragments2;
5564 map<string, string> fragments3;
5566 const char typesAndConstants1[] =
5567 "%c_f32_p2 = OpConstant %f32 0.2\n"
5568 "%c_f32_p4 = OpConstant %f32 0.4\n"
5569 "%c_f32_p5 = OpConstant %f32 0.5\n"
5570 "%c_f32_p8 = OpConstant %f32 0.8\n";
5572 // vec4 test_code(vec4 param) {
5573 // vec4 result = param;
5574 // for (int i = 0; i < 4; ++i) {
5577 // case 0: operand = .2; break;
5578 // case 1: operand = .5; break;
5579 // case 2: operand = .4; break;
5580 // case 3: operand = .0; break;
5581 // default: break; // unreachable
5583 // result[i] += operand;
5587 const char function1[] =
5588 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5589 "%param1 = OpFunctionParameter %v4f32\n"
5591 "%iptr = OpVariable %fp_i32 Function\n"
5592 "%result = OpVariable %fp_v4f32 Function\n"
5593 " OpStore %iptr %c_i32_0\n"
5594 " OpStore %result %param1\n"
5598 "%ival = OpLoad %i32 %iptr\n"
5599 "%lt_4 = OpSLessThan %bool %ival %c_i32_4\n"
5600 " OpLoopMerge %exit %phi None\n"
5601 " OpBranchConditional %lt_4 %entry %exit\n"
5603 "%entry = OpLabel\n"
5604 "%loc = OpAccessChain %fp_f32 %result %ival\n"
5605 "%val = OpLoad %f32 %loc\n"
5606 " OpSelectionMerge %phi None\n"
5607 " OpSwitch %ival %default 0 %case0 1 %case1 2 %case2 3 %case3\n"
5609 "%case0 = OpLabel\n"
5611 "%case1 = OpLabel\n"
5613 "%case2 = OpLabel\n"
5615 "%case3 = OpLabel\n"
5618 "%default = OpLabel\n"
5622 "%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
5623 "%add = OpFAdd %f32 %val %operand\n"
5624 " OpStore %loc %add\n"
5625 "%ival_next = OpIAdd %i32 %ival %c_i32_1\n"
5626 " OpStore %iptr %ival_next\n"
5630 "%ret = OpLoad %v4f32 %result\n"
5631 " OpReturnValue %ret\n"
5635 fragments1["pre_main"] = typesAndConstants1;
5636 fragments1["testfun"] = function1;
5638 getHalfColorsFullAlpha(inputColors);
5640 outputColors1[0] = RGBA(178, 255, 229, 255);
5641 outputColors1[1] = RGBA(178, 127, 102, 255);
5642 outputColors1[2] = RGBA(51, 255, 102, 255);
5643 outputColors1[3] = RGBA(51, 127, 229, 255);
5645 createTestsForAllStages("out_of_order", inputColors, outputColors1, fragments1, group.get());
5647 const char typesAndConstants2[] =
5648 "%c_f32_p2 = OpConstant %f32 0.2\n";
5650 // Add .4 to the second element of the given parameter.
5651 const char function2[] =
5652 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5653 "%param = OpFunctionParameter %v4f32\n"
5654 "%entry = OpLabel\n"
5655 "%result = OpVariable %fp_v4f32 Function\n"
5656 " OpStore %result %param\n"
5657 "%loc = OpAccessChain %fp_f32 %result %c_i32_1\n"
5658 "%val = OpLoad %f32 %loc\n"
5662 "%step = OpPhi %i32 %c_i32_0 %entry %step_next %phi\n"
5663 "%accum = OpPhi %f32 %val %entry %accum_next %phi\n"
5664 "%step_next = OpIAdd %i32 %step %c_i32_1\n"
5665 "%accum_next = OpFAdd %f32 %accum %c_f32_p2\n"
5666 "%still_loop = OpSLessThan %bool %step %c_i32_2\n"
5667 " OpLoopMerge %exit %phi None\n"
5668 " OpBranchConditional %still_loop %phi %exit\n"
5671 " OpStore %loc %accum\n"
5672 "%ret = OpLoad %v4f32 %result\n"
5673 " OpReturnValue %ret\n"
5677 fragments2["pre_main"] = typesAndConstants2;
5678 fragments2["testfun"] = function2;
5680 outputColors2[0] = RGBA(127, 229, 127, 255);
5681 outputColors2[1] = RGBA(127, 102, 0, 255);
5682 outputColors2[2] = RGBA(0, 229, 0, 255);
5683 outputColors2[3] = RGBA(0, 102, 127, 255);
5685 createTestsForAllStages("induction", inputColors, outputColors2, fragments2, group.get());
5687 const char typesAndConstants3[] =
5688 "%true = OpConstantTrue %bool\n"
5689 "%false = OpConstantFalse %bool\n"
5690 "%c_f32_p2 = OpConstant %f32 0.2\n";
5692 // Swap the second and the third element of the given parameter.
5693 const char function3[] =
5694 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5695 "%param = OpFunctionParameter %v4f32\n"
5696 "%entry = OpLabel\n"
5697 "%result = OpVariable %fp_v4f32 Function\n"
5698 " OpStore %result %param\n"
5699 "%a_loc = OpAccessChain %fp_f32 %result %c_i32_1\n"
5700 "%a_init = OpLoad %f32 %a_loc\n"
5701 "%b_loc = OpAccessChain %fp_f32 %result %c_i32_2\n"
5702 "%b_init = OpLoad %f32 %b_loc\n"
5706 "%still_loop = OpPhi %bool %true %entry %false %phi\n"
5707 "%a_next = OpPhi %f32 %a_init %entry %b_next %phi\n"
5708 "%b_next = OpPhi %f32 %b_init %entry %a_next %phi\n"
5709 " OpLoopMerge %exit %phi None\n"
5710 " OpBranchConditional %still_loop %phi %exit\n"
5713 " OpStore %a_loc %a_next\n"
5714 " OpStore %b_loc %b_next\n"
5715 "%ret = OpLoad %v4f32 %result\n"
5716 " OpReturnValue %ret\n"
5720 fragments3["pre_main"] = typesAndConstants3;
5721 fragments3["testfun"] = function3;
5723 outputColors3[0] = RGBA(127, 127, 127, 255);
5724 outputColors3[1] = RGBA(127, 0, 0, 255);
5725 outputColors3[2] = RGBA(0, 0, 127, 255);
5726 outputColors3[3] = RGBA(0, 127, 0, 255);
5728 createTestsForAllStages("swap", inputColors, outputColors3, fragments3, group.get());
5730 return group.release();
5733 tcu::TestCaseGroup* createNoContractionTests(tcu::TestContext& testCtx)
5735 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "nocontraction", "Test the NoContraction decoration"));
5736 RGBA inputColors[4];
5737 RGBA outputColors[4];
5739 // With NoContraction, (1 + 2^-23) * (1 - 2^-23) - 1 should be conducted as a multiplication and an addition separately.
5740 // For the multiplication, the result is 1 - 2^-46, which is out of the precision range for 32-bit float. (32-bit float
5741 // only have 23-bit fraction.) So it will be rounded to 1. Or 0x1.fffffc. Then the final result is 0 or -0x1p-24.
5742 // On the contrary, the result will be 2^-46, which is a normalized number perfectly representable as 32-bit float.
5743 const char constantsAndTypes[] =
5744 "%c_vec4_0 = OpConstantComposite %v4f32 %c_f32_0 %c_f32_0 %c_f32_0 %c_f32_1\n"
5745 "%c_vec4_1 = OpConstantComposite %v4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_1\n"
5746 "%c_f32_1pl2_23 = OpConstant %f32 0x1.000002p+0\n" // 1 + 2^-23
5747 "%c_f32_1mi2_23 = OpConstant %f32 0x1.fffffcp-1\n" // 1 - 2^-23
5748 "%c_f32_n1pn24 = OpConstant %f32 -0x1p-24\n"
5751 const char function[] =
5752 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5753 "%param = OpFunctionParameter %v4f32\n"
5754 "%label = OpLabel\n"
5755 "%var1 = OpVariable %fp_f32 Function %c_f32_1pl2_23\n"
5756 "%var2 = OpVariable %fp_f32 Function\n"
5757 "%red = OpCompositeExtract %f32 %param 0\n"
5758 "%plus_red = OpFAdd %f32 %c_f32_1mi2_23 %red\n"
5759 " OpStore %var2 %plus_red\n"
5760 "%val1 = OpLoad %f32 %var1\n"
5761 "%val2 = OpLoad %f32 %var2\n"
5762 "%mul = OpFMul %f32 %val1 %val2\n"
5763 "%add = OpFAdd %f32 %mul %c_f32_n1\n"
5764 "%is0 = OpFOrdEqual %bool %add %c_f32_0\n"
5765 "%isn1n24 = OpFOrdEqual %bool %add %c_f32_n1pn24\n"
5766 "%success = OpLogicalOr %bool %is0 %isn1n24\n"
5767 "%v4success = OpCompositeConstruct %v4bool %success %success %success %success\n"
5768 "%ret = OpSelect %v4f32 %v4success %c_vec4_0 %c_vec4_1\n"
5769 " OpReturnValue %ret\n"
5772 struct CaseNameDecoration
5779 CaseNameDecoration tests[] = {
5780 {"multiplication", "OpDecorate %mul NoContraction"},
5781 {"addition", "OpDecorate %add NoContraction"},
5782 {"both", "OpDecorate %mul NoContraction\nOpDecorate %add NoContraction"},
5785 getHalfColorsFullAlpha(inputColors);
5787 for (deUint8 idx = 0; idx < 4; ++idx)
5789 inputColors[idx].setRed(0);
5790 outputColors[idx] = RGBA(0, 0, 0, 255);
5793 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(CaseNameDecoration); ++testNdx)
5795 map<string, string> fragments;
5797 fragments["decoration"] = tests[testNdx].decoration;
5798 fragments["pre_main"] = constantsAndTypes;
5799 fragments["testfun"] = function;
5801 createTestsForAllStages(tests[testNdx].name, inputColors, outputColors, fragments, group.get());
5804 return group.release();
5807 tcu::TestCaseGroup* createMemoryAccessTests(tcu::TestContext& testCtx)
5809 de::MovePtr<tcu::TestCaseGroup> memoryAccessTests (new tcu::TestCaseGroup(testCtx, "opmemoryaccess", "Memory Semantics"));
5812 const char constantsAndTypes[] =
5813 "%c_a2f32_1 = OpConstantComposite %a2f32 %c_f32_1 %c_f32_1\n"
5814 "%fp_a2f32 = OpTypePointer Function %a2f32\n"
5815 "%stype = OpTypeStruct %v4f32 %a2f32 %f32\n"
5816 "%fp_stype = OpTypePointer Function %stype\n";
5818 const char function[] =
5819 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5820 "%param1 = OpFunctionParameter %v4f32\n"
5822 "%v1 = OpVariable %fp_v4f32 Function\n"
5823 "%v2 = OpVariable %fp_a2f32 Function\n"
5824 "%v3 = OpVariable %fp_f32 Function\n"
5825 "%v = OpVariable %fp_stype Function\n"
5826 "%vv = OpVariable %fp_stype Function\n"
5827 "%vvv = OpVariable %fp_f32 Function\n"
5829 " OpStore %v1 %c_v4f32_1_1_1_1\n"
5830 " OpStore %v2 %c_a2f32_1\n"
5831 " OpStore %v3 %c_f32_1\n"
5833 "%p_v4f32 = OpAccessChain %fp_v4f32 %v %c_u32_0\n"
5834 "%p_a2f32 = OpAccessChain %fp_a2f32 %v %c_u32_1\n"
5835 "%p_f32 = OpAccessChain %fp_f32 %v %c_u32_2\n"
5836 "%v1_v = OpLoad %v4f32 %v1 ${access_type}\n"
5837 "%v2_v = OpLoad %a2f32 %v2 ${access_type}\n"
5838 "%v3_v = OpLoad %f32 %v3 ${access_type}\n"
5840 " OpStore %p_v4f32 %v1_v ${access_type}\n"
5841 " OpStore %p_a2f32 %v2_v ${access_type}\n"
5842 " OpStore %p_f32 %v3_v ${access_type}\n"
5844 " OpCopyMemory %vv %v ${access_type}\n"
5845 " OpCopyMemory %vvv %p_f32 ${access_type}\n"
5847 "%p_f32_2 = OpAccessChain %fp_f32 %vv %c_u32_2\n"
5848 "%v_f32_2 = OpLoad %f32 %p_f32_2\n"
5849 "%v_f32_3 = OpLoad %f32 %vvv\n"
5851 "%ret1 = OpVectorTimesScalar %v4f32 %param1 %v_f32_2\n"
5852 "%ret2 = OpVectorTimesScalar %v4f32 %ret1 %v_f32_3\n"
5853 " OpReturnValue %ret2\n"
5856 struct NameMemoryAccess
5863 NameMemoryAccess tests[] =
5866 { "volatile", "Volatile" },
5867 { "aligned", "Aligned 1" },
5868 { "volatile_aligned", "Volatile|Aligned 1" },
5869 { "nontemporal_aligned", "Nontemporal|Aligned 1" },
5870 { "volatile_nontemporal", "Volatile|Nontemporal" },
5871 { "volatile_nontermporal_aligned", "Volatile|Nontemporal|Aligned 1" },
5874 getHalfColorsFullAlpha(colors);
5876 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameMemoryAccess); ++testNdx)
5878 map<string, string> fragments;
5879 map<string, string> memoryAccess;
5880 memoryAccess["access_type"] = tests[testNdx].accessType;
5882 fragments["pre_main"] = constantsAndTypes;
5883 fragments["testfun"] = tcu::StringTemplate(function).specialize(memoryAccess);
5884 createTestsForAllStages(tests[testNdx].name, colors, colors, fragments, memoryAccessTests.get());
5886 return memoryAccessTests.release();
5888 tcu::TestCaseGroup* createOpUndefTests(tcu::TestContext& testCtx)
5890 de::MovePtr<tcu::TestCaseGroup> opUndefTests (new tcu::TestCaseGroup(testCtx, "opundef", "Test OpUndef"));
5891 RGBA defaultColors[4];
5892 map<string, string> fragments;
5893 getDefaultColors(defaultColors);
5895 // First, simple cases that don't do anything with the OpUndef result.
5896 struct NameCodePair { string name, decl, type; };
5897 const NameCodePair tests[] =
5899 {"bool", "", "%bool"},
5900 {"vec2uint32", "%type = OpTypeVector %u32 2", "%type"},
5901 {"image", "%type = OpTypeImage %f32 2D 0 0 0 1 Unknown", "%type"},
5902 {"sampler", "%type = OpTypeSampler", "%type"},
5903 {"sampledimage", "%img = OpTypeImage %f32 2D 0 0 0 1 Unknown\n" "%type = OpTypeSampledImage %img", "%type"},
5904 {"pointer", "", "%fp_i32"},
5905 {"runtimearray", "%type = OpTypeRuntimeArray %f32", "%type"},
5906 {"array", "%c_u32_100 = OpConstant %u32 100\n" "%type = OpTypeArray %i32 %c_u32_100", "%type"},
5907 {"struct", "%type = OpTypeStruct %f32 %i32 %u32", "%type"}};
5908 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameCodePair); ++testNdx)
5910 fragments["undef_type"] = tests[testNdx].type;
5911 fragments["testfun"] = StringTemplate(
5912 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5913 "%param1 = OpFunctionParameter %v4f32\n"
5914 "%label_testfun = OpLabel\n"
5915 "%undef = OpUndef ${undef_type}\n"
5916 "OpReturnValue %param1\n"
5917 "OpFunctionEnd\n").specialize(fragments);
5918 fragments["pre_main"] = tests[testNdx].decl;
5919 createTestsForAllStages(tests[testNdx].name, defaultColors, defaultColors, fragments, opUndefTests.get());
5923 fragments["testfun"] =
5924 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5925 "%param1 = OpFunctionParameter %v4f32\n"
5926 "%label_testfun = OpLabel\n"
5927 "%undef = OpUndef %f32\n"
5928 "%zero = OpFMul %f32 %undef %c_f32_0\n"
5929 "%is_nan = OpIsNan %bool %zero\n" //OpUndef may result in NaN which may turn %zero into Nan.
5930 "%actually_zero = OpSelect %f32 %is_nan %c_f32_0 %zero\n"
5931 "%a = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
5932 "%b = OpFAdd %f32 %a %actually_zero\n"
5933 "%ret = OpVectorInsertDynamic %v4f32 %param1 %b %c_i32_0\n"
5934 "OpReturnValue %ret\n"
5937 createTestsForAllStages("float32", defaultColors, defaultColors, fragments, opUndefTests.get());
5939 fragments["testfun"] =
5940 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5941 "%param1 = OpFunctionParameter %v4f32\n"
5942 "%label_testfun = OpLabel\n"
5943 "%undef = OpUndef %i32\n"
5944 "%zero = OpIMul %i32 %undef %c_i32_0\n"
5945 "%a = OpVectorExtractDynamic %f32 %param1 %zero\n"
5946 "%ret = OpVectorInsertDynamic %v4f32 %param1 %a %c_i32_0\n"
5947 "OpReturnValue %ret\n"
5950 createTestsForAllStages("sint32", defaultColors, defaultColors, fragments, opUndefTests.get());
5952 fragments["testfun"] =
5953 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5954 "%param1 = OpFunctionParameter %v4f32\n"
5955 "%label_testfun = OpLabel\n"
5956 "%undef = OpUndef %u32\n"
5957 "%zero = OpIMul %u32 %undef %c_i32_0\n"
5958 "%a = OpVectorExtractDynamic %f32 %param1 %zero\n"
5959 "%ret = OpVectorInsertDynamic %v4f32 %param1 %a %c_i32_0\n"
5960 "OpReturnValue %ret\n"
5963 createTestsForAllStages("uint32", defaultColors, defaultColors, fragments, opUndefTests.get());
5965 fragments["testfun"] =
5966 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5967 "%param1 = OpFunctionParameter %v4f32\n"
5968 "%label_testfun = OpLabel\n"
5969 "%undef = OpUndef %v4f32\n"
5970 "%vzero = OpVectorTimesScalar %v4f32 %undef %c_f32_0\n"
5971 "%zero_0 = OpVectorExtractDynamic %f32 %vzero %c_i32_0\n"
5972 "%zero_1 = OpVectorExtractDynamic %f32 %vzero %c_i32_1\n"
5973 "%zero_2 = OpVectorExtractDynamic %f32 %vzero %c_i32_2\n"
5974 "%zero_3 = OpVectorExtractDynamic %f32 %vzero %c_i32_3\n"
5975 "%is_nan_0 = OpIsNan %bool %zero_0\n"
5976 "%is_nan_1 = OpIsNan %bool %zero_1\n"
5977 "%is_nan_2 = OpIsNan %bool %zero_2\n"
5978 "%is_nan_3 = OpIsNan %bool %zero_3\n"
5979 "%actually_zero_0 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_0\n"
5980 "%actually_zero_1 = OpSelect %f32 %is_nan_1 %c_f32_0 %zero_1\n"
5981 "%actually_zero_2 = OpSelect %f32 %is_nan_2 %c_f32_0 %zero_2\n"
5982 "%actually_zero_3 = OpSelect %f32 %is_nan_3 %c_f32_0 %zero_3\n"
5983 "%param1_0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
5984 "%param1_1 = OpVectorExtractDynamic %f32 %param1 %c_i32_1\n"
5985 "%param1_2 = OpVectorExtractDynamic %f32 %param1 %c_i32_2\n"
5986 "%param1_3 = OpVectorExtractDynamic %f32 %param1 %c_i32_3\n"
5987 "%sum_0 = OpFAdd %f32 %param1_0 %actually_zero_0\n"
5988 "%sum_1 = OpFAdd %f32 %param1_1 %actually_zero_1\n"
5989 "%sum_2 = OpFAdd %f32 %param1_2 %actually_zero_2\n"
5990 "%sum_3 = OpFAdd %f32 %param1_3 %actually_zero_3\n"
5991 "%ret3 = OpVectorInsertDynamic %v4f32 %param1 %sum_3 %c_i32_3\n"
5992 "%ret2 = OpVectorInsertDynamic %v4f32 %ret3 %sum_2 %c_i32_2\n"
5993 "%ret1 = OpVectorInsertDynamic %v4f32 %ret2 %sum_1 %c_i32_1\n"
5994 "%ret = OpVectorInsertDynamic %v4f32 %ret1 %sum_0 %c_i32_0\n"
5995 "OpReturnValue %ret\n"
5998 createTestsForAllStages("vec4float32", defaultColors, defaultColors, fragments, opUndefTests.get());
6000 fragments["pre_main"] =
6001 "%m2x2f32 = OpTypeMatrix %v2f32 2\n";
6002 fragments["testfun"] =
6003 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6004 "%param1 = OpFunctionParameter %v4f32\n"
6005 "%label_testfun = OpLabel\n"
6006 "%undef = OpUndef %m2x2f32\n"
6007 "%mzero = OpMatrixTimesScalar %m2x2f32 %undef %c_f32_0\n"
6008 "%zero_0 = OpCompositeExtract %f32 %mzero 0 0\n"
6009 "%zero_1 = OpCompositeExtract %f32 %mzero 0 1\n"
6010 "%zero_2 = OpCompositeExtract %f32 %mzero 1 0\n"
6011 "%zero_3 = OpCompositeExtract %f32 %mzero 1 1\n"
6012 "%is_nan_0 = OpIsNan %bool %zero_0\n"
6013 "%is_nan_1 = OpIsNan %bool %zero_1\n"
6014 "%is_nan_2 = OpIsNan %bool %zero_2\n"
6015 "%is_nan_3 = OpIsNan %bool %zero_3\n"
6016 "%actually_zero_0 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_0\n"
6017 "%actually_zero_1 = OpSelect %f32 %is_nan_1 %c_f32_0 %zero_1\n"
6018 "%actually_zero_2 = OpSelect %f32 %is_nan_2 %c_f32_0 %zero_2\n"
6019 "%actually_zero_3 = OpSelect %f32 %is_nan_3 %c_f32_0 %zero_3\n"
6020 "%param1_0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
6021 "%param1_1 = OpVectorExtractDynamic %f32 %param1 %c_i32_1\n"
6022 "%param1_2 = OpVectorExtractDynamic %f32 %param1 %c_i32_2\n"
6023 "%param1_3 = OpVectorExtractDynamic %f32 %param1 %c_i32_3\n"
6024 "%sum_0 = OpFAdd %f32 %param1_0 %actually_zero_0\n"
6025 "%sum_1 = OpFAdd %f32 %param1_1 %actually_zero_1\n"
6026 "%sum_2 = OpFAdd %f32 %param1_2 %actually_zero_2\n"
6027 "%sum_3 = OpFAdd %f32 %param1_3 %actually_zero_3\n"
6028 "%ret3 = OpVectorInsertDynamic %v4f32 %param1 %sum_3 %c_i32_3\n"
6029 "%ret2 = OpVectorInsertDynamic %v4f32 %ret3 %sum_2 %c_i32_2\n"
6030 "%ret1 = OpVectorInsertDynamic %v4f32 %ret2 %sum_1 %c_i32_1\n"
6031 "%ret = OpVectorInsertDynamic %v4f32 %ret1 %sum_0 %c_i32_0\n"
6032 "OpReturnValue %ret\n"
6035 createTestsForAllStages("matrix", defaultColors, defaultColors, fragments, opUndefTests.get());
6037 return opUndefTests.release();
6040 void createOpQuantizeSingleOptionTests(tcu::TestCaseGroup* testCtx)
6042 const RGBA inputColors[4] =
6045 RGBA(0, 0, 255, 255),
6046 RGBA(0, 255, 0, 255),
6047 RGBA(0, 255, 255, 255)
6050 const RGBA expectedColors[4] =
6052 RGBA(255, 0, 0, 255),
6053 RGBA(255, 0, 0, 255),
6054 RGBA(255, 0, 0, 255),
6055 RGBA(255, 0, 0, 255)
6058 const struct SingleFP16Possibility
6061 const char* constant; // Value to assign to %test_constant.
6063 const char* condition; // Must assign to %cond an expression that evaluates to true after %c = OpQuantizeToF16(%test_constant + 0).
6069 -constructNormalizedFloat(1, 0x300000),
6070 "%cond = OpFOrdEqual %bool %c %test_constant\n"
6075 constructNormalizedFloat(7, 0x000000),
6076 "%cond = OpFOrdEqual %bool %c %test_constant\n"
6078 // SPIR-V requires that OpQuantizeToF16 flushes
6079 // any numbers that would end up denormalized in F16 to zero.
6083 std::ldexp(1.5f, -140),
6084 "%cond = OpFOrdEqual %bool %c %c_f32_0\n"
6089 -std::ldexp(1.5f, -140),
6090 "%cond = OpFOrdEqual %bool %c %c_f32_0\n"
6095 std::ldexp(1.0f, -16),
6096 "%cond = OpFOrdEqual %bool %c %c_f32_0\n"
6097 }, // too small positive
6099 "negative_too_small",
6101 -std::ldexp(1.0f, -32),
6102 "%cond = OpFOrdEqual %bool %c %c_f32_0\n"
6103 }, // too small negative
6107 -std::ldexp(1.0f, 128),
6109 "%gz = OpFOrdLessThan %bool %c %c_f32_0\n"
6110 "%inf = OpIsInf %bool %c\n"
6111 "%cond = OpLogicalAnd %bool %gz %inf\n"
6116 std::ldexp(1.0f, 128),
6118 "%gz = OpFOrdGreaterThan %bool %c %c_f32_0\n"
6119 "%inf = OpIsInf %bool %c\n"
6120 "%cond = OpLogicalAnd %bool %gz %inf\n"
6123 "round_to_negative_inf",
6125 -std::ldexp(1.0f, 32),
6127 "%gz = OpFOrdLessThan %bool %c %c_f32_0\n"
6128 "%inf = OpIsInf %bool %c\n"
6129 "%cond = OpLogicalAnd %bool %gz %inf\n"
6134 std::ldexp(1.0f, 16),
6136 "%gz = OpFOrdGreaterThan %bool %c %c_f32_0\n"
6137 "%inf = OpIsInf %bool %c\n"
6138 "%cond = OpLogicalAnd %bool %gz %inf\n"
6143 std::numeric_limits<float>::quiet_NaN(),
6145 // Test for any NaN value, as NaNs are not preserved
6146 "%direct_quant = OpQuantizeToF16 %f32 %test_constant\n"
6147 "%cond = OpIsNan %bool %direct_quant\n"
6152 std::numeric_limits<float>::quiet_NaN(),
6154 // Test for any NaN value, as NaNs are not preserved
6155 "%direct_quant = OpQuantizeToF16 %f32 %test_constant\n"
6156 "%cond = OpIsNan %bool %direct_quant\n"
6159 const char* constants =
6160 "%test_constant = OpConstant %f32 "; // The value will be test.constant.
6162 StringTemplate function (
6163 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6164 "%param1 = OpFunctionParameter %v4f32\n"
6165 "%label_testfun = OpLabel\n"
6166 "%a = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
6167 "%b = OpFAdd %f32 %test_constant %a\n"
6168 "%c = OpQuantizeToF16 %f32 %b\n"
6170 "%v4cond = OpCompositeConstruct %v4bool %cond %cond %cond %cond\n"
6171 "%retval = OpSelect %v4f32 %v4cond %c_v4f32_1_0_0_1 %param1\n"
6172 " OpReturnValue %retval\n"
6176 const char* specDecorations = "OpDecorate %test_constant SpecId 0\n";
6177 const char* specConstants =
6178 "%test_constant = OpSpecConstant %f32 0.\n"
6179 "%c = OpSpecConstantOp %f32 QuantizeToF16 %test_constant\n";
6181 StringTemplate specConstantFunction(
6182 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6183 "%param1 = OpFunctionParameter %v4f32\n"
6184 "%label_testfun = OpLabel\n"
6186 "%v4cond = OpCompositeConstruct %v4bool %cond %cond %cond %cond\n"
6187 "%retval = OpSelect %v4f32 %v4cond %c_v4f32_1_0_0_1 %param1\n"
6188 " OpReturnValue %retval\n"
6192 for (size_t idx = 0; idx < (sizeof(tests)/sizeof(tests[0])); ++idx)
6194 map<string, string> codeSpecialization;
6195 map<string, string> fragments;
6196 codeSpecialization["condition"] = tests[idx].condition;
6197 fragments["testfun"] = function.specialize(codeSpecialization);
6198 fragments["pre_main"] = string(constants) + tests[idx].constant + "\n";
6199 createTestsForAllStages(tests[idx].name, inputColors, expectedColors, fragments, testCtx);
6202 for (size_t idx = 0; idx < (sizeof(tests)/sizeof(tests[0])); ++idx)
6204 map<string, string> codeSpecialization;
6205 map<string, string> fragments;
6206 vector<deInt32> passConstants;
6207 deInt32 specConstant;
6209 codeSpecialization["condition"] = tests[idx].condition;
6210 fragments["testfun"] = specConstantFunction.specialize(codeSpecialization);
6211 fragments["decoration"] = specDecorations;
6212 fragments["pre_main"] = specConstants;
6214 memcpy(&specConstant, &tests[idx].valueAsFloat, sizeof(float));
6215 passConstants.push_back(specConstant);
6217 createTestsForAllStages(string("spec_const_") + tests[idx].name, inputColors, expectedColors, fragments, passConstants, testCtx);
6221 void createOpQuantizeTwoPossibilityTests(tcu::TestCaseGroup* testCtx)
6223 RGBA inputColors[4] = {
6225 RGBA(0, 0, 255, 255),
6226 RGBA(0, 255, 0, 255),
6227 RGBA(0, 255, 255, 255)
6230 RGBA expectedColors[4] =
6232 RGBA(255, 0, 0, 255),
6233 RGBA(255, 0, 0, 255),
6234 RGBA(255, 0, 0, 255),
6235 RGBA(255, 0, 0, 255)
6238 struct DualFP16Possibility
6243 const char* possibleOutput1;
6244 const char* possibleOutput2;
6247 "positive_round_up_or_round_down",
6249 constructNormalizedFloat(8, 0x300300),
6254 "negative_round_up_or_round_down",
6256 -constructNormalizedFloat(-7, 0x600800),
6263 constructNormalizedFloat(2, 0x01e000),
6268 "carry_to_exponent",
6270 constructNormalizedFloat(1, 0xffe000),
6275 StringTemplate constants (
6276 "%input_const = OpConstant %f32 ${input}\n"
6277 "%possible_solution1 = OpConstant %f32 ${output1}\n"
6278 "%possible_solution2 = OpConstant %f32 ${output2}\n"
6281 StringTemplate specConstants (
6282 "%input_const = OpSpecConstant %f32 0.\n"
6283 "%possible_solution1 = OpConstant %f32 ${output1}\n"
6284 "%possible_solution2 = OpConstant %f32 ${output2}\n"
6287 const char* specDecorations = "OpDecorate %input_const SpecId 0\n";
6289 const char* function =
6290 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6291 "%param1 = OpFunctionParameter %v4f32\n"
6292 "%label_testfun = OpLabel\n"
6293 "%a = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
6294 // For the purposes of this test we assume that 0.f will always get
6295 // faithfully passed through the pipeline stages.
6296 "%b = OpFAdd %f32 %input_const %a\n"
6297 "%c = OpQuantizeToF16 %f32 %b\n"
6298 "%eq_1 = OpFOrdEqual %bool %c %possible_solution1\n"
6299 "%eq_2 = OpFOrdEqual %bool %c %possible_solution2\n"
6300 "%cond = OpLogicalOr %bool %eq_1 %eq_2\n"
6301 "%v4cond = OpCompositeConstruct %v4bool %cond %cond %cond %cond\n"
6302 "%retval = OpSelect %v4f32 %v4cond %c_v4f32_1_0_0_1 %param1"
6303 " OpReturnValue %retval\n"
6306 for(size_t idx = 0; idx < (sizeof(tests)/sizeof(tests[0])); ++idx) {
6307 map<string, string> fragments;
6308 map<string, string> constantSpecialization;
6310 constantSpecialization["input"] = tests[idx].input;
6311 constantSpecialization["output1"] = tests[idx].possibleOutput1;
6312 constantSpecialization["output2"] = tests[idx].possibleOutput2;
6313 fragments["testfun"] = function;
6314 fragments["pre_main"] = constants.specialize(constantSpecialization);
6315 createTestsForAllStages(tests[idx].name, inputColors, expectedColors, fragments, testCtx);
6318 for(size_t idx = 0; idx < (sizeof(tests)/sizeof(tests[0])); ++idx) {
6319 map<string, string> fragments;
6320 map<string, string> constantSpecialization;
6321 vector<deInt32> passConstants;
6322 deInt32 specConstant;
6324 constantSpecialization["output1"] = tests[idx].possibleOutput1;
6325 constantSpecialization["output2"] = tests[idx].possibleOutput2;
6326 fragments["testfun"] = function;
6327 fragments["decoration"] = specDecorations;
6328 fragments["pre_main"] = specConstants.specialize(constantSpecialization);
6330 memcpy(&specConstant, &tests[idx].inputAsFloat, sizeof(float));
6331 passConstants.push_back(specConstant);
6333 createTestsForAllStages(string("spec_const_") + tests[idx].name, inputColors, expectedColors, fragments, passConstants, testCtx);
6337 tcu::TestCaseGroup* createOpQuantizeTests(tcu::TestContext& testCtx)
6339 de::MovePtr<tcu::TestCaseGroup> opQuantizeTests (new tcu::TestCaseGroup(testCtx, "opquantize", "Test OpQuantizeToF16"));
6340 createOpQuantizeSingleOptionTests(opQuantizeTests.get());
6341 createOpQuantizeTwoPossibilityTests(opQuantizeTests.get());
6342 return opQuantizeTests.release();
6345 struct ShaderPermutation
6347 deUint8 vertexPermutation;
6348 deUint8 geometryPermutation;
6349 deUint8 tesscPermutation;
6350 deUint8 tessePermutation;
6351 deUint8 fragmentPermutation;
6354 ShaderPermutation getShaderPermutation(deUint8 inputValue)
6356 ShaderPermutation permutation =
6358 static_cast<deUint8>(inputValue & 0x10? 1u: 0u),
6359 static_cast<deUint8>(inputValue & 0x08? 1u: 0u),
6360 static_cast<deUint8>(inputValue & 0x04? 1u: 0u),
6361 static_cast<deUint8>(inputValue & 0x02? 1u: 0u),
6362 static_cast<deUint8>(inputValue & 0x01? 1u: 0u)
6367 tcu::TestCaseGroup* createModuleTests(tcu::TestContext& testCtx)
6369 RGBA defaultColors[4];
6370 RGBA invertedColors[4];
6371 de::MovePtr<tcu::TestCaseGroup> moduleTests (new tcu::TestCaseGroup(testCtx, "module", "Multiple entry points into shaders"));
6373 const ShaderElement combinedPipeline[] =
6375 ShaderElement("module", "main", VK_SHADER_STAGE_VERTEX_BIT),
6376 ShaderElement("module", "main", VK_SHADER_STAGE_GEOMETRY_BIT),
6377 ShaderElement("module", "main", VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT),
6378 ShaderElement("module", "main", VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT),
6379 ShaderElement("module", "main", VK_SHADER_STAGE_FRAGMENT_BIT)
6382 getDefaultColors(defaultColors);
6383 getInvertedDefaultColors(invertedColors);
6384 addFunctionCaseWithPrograms<InstanceContext>(
6385 moduleTests.get(), "same_module", "", createCombinedModule, runAndVerifyDefaultPipeline,
6386 createInstanceContext(combinedPipeline, map<string, string>()));
6388 const char* numbers[] =
6393 for (deInt8 idx = 0; idx < 32; ++idx)
6395 ShaderPermutation permutation = getShaderPermutation(idx);
6396 string name = string("vert") + numbers[permutation.vertexPermutation] + "_geom" + numbers[permutation.geometryPermutation] + "_tessc" + numbers[permutation.tesscPermutation] + "_tesse" + numbers[permutation.tessePermutation] + "_frag" + numbers[permutation.fragmentPermutation];
6397 const ShaderElement pipeline[] =
6399 ShaderElement("vert", string("vert") + numbers[permutation.vertexPermutation], VK_SHADER_STAGE_VERTEX_BIT),
6400 ShaderElement("geom", string("geom") + numbers[permutation.geometryPermutation], VK_SHADER_STAGE_GEOMETRY_BIT),
6401 ShaderElement("tessc", string("tessc") + numbers[permutation.tesscPermutation], VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT),
6402 ShaderElement("tesse", string("tesse") + numbers[permutation.tessePermutation], VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT),
6403 ShaderElement("frag", string("frag") + numbers[permutation.fragmentPermutation], VK_SHADER_STAGE_FRAGMENT_BIT)
6406 // If there are an even number of swaps, then it should be no-op.
6407 // If there are an odd number, the color should be flipped.
6408 if ((permutation.vertexPermutation + permutation.geometryPermutation + permutation.tesscPermutation + permutation.tessePermutation + permutation.fragmentPermutation) % 2 == 0)
6410 addFunctionCaseWithPrograms<InstanceContext>(
6411 moduleTests.get(), name, "", createMultipleEntries, runAndVerifyDefaultPipeline,
6412 createInstanceContext(pipeline, defaultColors, defaultColors, map<string, string>()));
6416 addFunctionCaseWithPrograms<InstanceContext>(
6417 moduleTests.get(), name, "", createMultipleEntries, runAndVerifyDefaultPipeline,
6418 createInstanceContext(pipeline, defaultColors, invertedColors, map<string, string>()));
6421 return moduleTests.release();
6424 tcu::TestCaseGroup* createLoopTests(tcu::TestContext& testCtx)
6426 de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, "loop", "Looping control flow"));
6427 RGBA defaultColors[4];
6428 getDefaultColors(defaultColors);
6429 map<string, string> fragments;
6430 fragments["pre_main"] =
6431 "%c_f32_5 = OpConstant %f32 5.\n";
6433 // A loop with a single block. The Continue Target is the loop block
6434 // itself. In SPIR-V terms, the "loop construct" contains no blocks at all
6435 // -- the "continue construct" forms the entire loop.
6436 fragments["testfun"] =
6437 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6438 "%param1 = OpFunctionParameter %v4f32\n"
6440 "%entry = OpLabel\n"
6441 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
6444 ";adds and subtracts 1.0 to %val in alternate iterations\n"
6446 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %loop\n"
6447 "%delta = OpPhi %f32 %c_f32_1 %entry %minus_delta %loop\n"
6448 "%val1 = OpPhi %f32 %val0 %entry %val %loop\n"
6449 "%val = OpFAdd %f32 %val1 %delta\n"
6450 "%minus_delta = OpFSub %f32 %c_f32_0 %delta\n"
6451 "%count__ = OpISub %i32 %count %c_i32_1\n"
6452 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
6453 "OpLoopMerge %exit %loop None\n"
6454 "OpBranchConditional %again %loop %exit\n"
6457 "%result = OpVectorInsertDynamic %v4f32 %param1 %val %c_i32_0\n"
6458 "OpReturnValue %result\n"
6462 createTestsForAllStages("single_block", defaultColors, defaultColors, fragments, testGroup.get());
6464 // Body comprised of multiple basic blocks.
6465 const StringTemplate multiBlock(
6466 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6467 "%param1 = OpFunctionParameter %v4f32\n"
6469 "%entry = OpLabel\n"
6470 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
6473 ";adds and subtracts 1.0 to %val in alternate iterations\n"
6475 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %gather\n"
6476 "%delta = OpPhi %f32 %c_f32_1 %entry %delta_next %gather\n"
6477 "%val1 = OpPhi %f32 %val0 %entry %val %gather\n"
6478 // There are several possibilities for the Continue Target below. Each
6479 // will be specialized into a separate test case.
6480 "OpLoopMerge %exit ${continue_target} None\n"
6484 ";delta_next = (delta > 0) ? -1 : 1;\n"
6485 "%gt0 = OpFOrdGreaterThan %bool %delta %c_f32_0\n"
6486 "OpSelectionMerge %gather DontFlatten\n"
6487 "OpBranchConditional %gt0 %even %odd ;tells us if %count is even or odd\n"
6490 "OpBranch %gather\n"
6493 "OpBranch %gather\n"
6495 "%gather = OpLabel\n"
6496 "%delta_next = OpPhi %f32 %c_f32_n1 %even %c_f32_1 %odd\n"
6497 "%val = OpFAdd %f32 %val1 %delta\n"
6498 "%count__ = OpISub %i32 %count %c_i32_1\n"
6499 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
6500 "OpBranchConditional %again %loop %exit\n"
6503 "%result = OpVectorInsertDynamic %v4f32 %param1 %val %c_i32_0\n"
6504 "OpReturnValue %result\n"
6508 map<string, string> continue_target;
6510 // The Continue Target is the loop block itself.
6511 continue_target["continue_target"] = "%loop";
6512 fragments["testfun"] = multiBlock.specialize(continue_target);
6513 createTestsForAllStages("multi_block_continue_construct", defaultColors, defaultColors, fragments, testGroup.get());
6515 // The Continue Target is at the end of the loop.
6516 continue_target["continue_target"] = "%gather";
6517 fragments["testfun"] = multiBlock.specialize(continue_target);
6518 createTestsForAllStages("multi_block_loop_construct", defaultColors, defaultColors, fragments, testGroup.get());
6520 // A loop with continue statement.
6521 fragments["testfun"] =
6522 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6523 "%param1 = OpFunctionParameter %v4f32\n"
6525 "%entry = OpLabel\n"
6526 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
6529 ";adds 4, 3, and 1 to %val0 (skips 2)\n"
6531 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %continue\n"
6532 "%val1 = OpPhi %f32 %val0 %entry %val %continue\n"
6533 "OpLoopMerge %exit %continue None\n"
6537 ";skip if %count==2\n"
6538 "%eq2 = OpIEqual %bool %count %c_i32_2\n"
6539 "OpSelectionMerge %continue DontFlatten\n"
6540 "OpBranchConditional %eq2 %continue %body\n"
6543 "%fcount = OpConvertSToF %f32 %count\n"
6544 "%val2 = OpFAdd %f32 %val1 %fcount\n"
6545 "OpBranch %continue\n"
6547 "%continue = OpLabel\n"
6548 "%val = OpPhi %f32 %val2 %body %val1 %if\n"
6549 "%count__ = OpISub %i32 %count %c_i32_1\n"
6550 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
6551 "OpBranchConditional %again %loop %exit\n"
6554 "%same = OpFSub %f32 %val %c_f32_8\n"
6555 "%result = OpVectorInsertDynamic %v4f32 %param1 %same %c_i32_0\n"
6556 "OpReturnValue %result\n"
6558 createTestsForAllStages("continue", defaultColors, defaultColors, fragments, testGroup.get());
6560 // A loop with break.
6561 fragments["testfun"] =
6562 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6563 "%param1 = OpFunctionParameter %v4f32\n"
6565 "%entry = OpLabel\n"
6566 ";param1 components are between 0 and 1, so dot product is 4 or less\n"
6567 "%dot = OpDot %f32 %param1 %param1\n"
6568 "%div = OpFDiv %f32 %dot %c_f32_5\n"
6569 "%zero = OpConvertFToU %u32 %div\n"
6570 "%two = OpIAdd %i32 %zero %c_i32_2\n"
6571 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
6574 ";adds 4 and 3 to %val0 (exits early)\n"
6576 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %continue\n"
6577 "%val1 = OpPhi %f32 %val0 %entry %val2 %continue\n"
6578 "OpLoopMerge %exit %continue None\n"
6582 ";end loop if %count==%two\n"
6583 "%above2 = OpSGreaterThan %bool %count %two\n"
6584 "OpSelectionMerge %continue DontFlatten\n"
6585 "OpBranchConditional %above2 %body %exit\n"
6588 "%fcount = OpConvertSToF %f32 %count\n"
6589 "%val2 = OpFAdd %f32 %val1 %fcount\n"
6590 "OpBranch %continue\n"
6592 "%continue = OpLabel\n"
6593 "%count__ = OpISub %i32 %count %c_i32_1\n"
6594 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
6595 "OpBranchConditional %again %loop %exit\n"
6598 "%val_post = OpPhi %f32 %val2 %continue %val1 %if\n"
6599 "%same = OpFSub %f32 %val_post %c_f32_7\n"
6600 "%result = OpVectorInsertDynamic %v4f32 %param1 %same %c_i32_0\n"
6601 "OpReturnValue %result\n"
6603 createTestsForAllStages("break", defaultColors, defaultColors, fragments, testGroup.get());
6605 // A loop with return.
6606 fragments["testfun"] =
6607 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6608 "%param1 = OpFunctionParameter %v4f32\n"
6610 "%entry = OpLabel\n"
6611 ";param1 components are between 0 and 1, so dot product is 4 or less\n"
6612 "%dot = OpDot %f32 %param1 %param1\n"
6613 "%div = OpFDiv %f32 %dot %c_f32_5\n"
6614 "%zero = OpConvertFToU %u32 %div\n"
6615 "%two = OpIAdd %i32 %zero %c_i32_2\n"
6616 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
6619 ";returns early without modifying %param1\n"
6621 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %continue\n"
6622 "%val1 = OpPhi %f32 %val0 %entry %val2 %continue\n"
6623 "OpLoopMerge %exit %continue None\n"
6627 ";return if %count==%two\n"
6628 "%above2 = OpSGreaterThan %bool %count %two\n"
6629 "OpSelectionMerge %continue DontFlatten\n"
6630 "OpBranchConditional %above2 %body %early_exit\n"
6632 "%early_exit = OpLabel\n"
6633 "OpReturnValue %param1\n"
6636 "%fcount = OpConvertSToF %f32 %count\n"
6637 "%val2 = OpFAdd %f32 %val1 %fcount\n"
6638 "OpBranch %continue\n"
6640 "%continue = OpLabel\n"
6641 "%count__ = OpISub %i32 %count %c_i32_1\n"
6642 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
6643 "OpBranchConditional %again %loop %exit\n"
6646 ";should never get here, so return an incorrect result\n"
6647 "%result = OpVectorInsertDynamic %v4f32 %param1 %val2 %c_i32_0\n"
6648 "OpReturnValue %result\n"
6650 createTestsForAllStages("return", defaultColors, defaultColors, fragments, testGroup.get());
6652 return testGroup.release();
6655 // A collection of tests putting OpControlBarrier in places GLSL forbids but SPIR-V allows.
6656 tcu::TestCaseGroup* createBarrierTests(tcu::TestContext& testCtx)
6658 de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, "barrier", "OpControlBarrier"));
6659 map<string, string> fragments;
6661 // A barrier inside a function body.
6662 fragments["pre_main"] =
6663 "%Workgroup = OpConstant %i32 2\n"
6664 "%SequentiallyConsistent = OpConstant %i32 0x10\n";
6665 fragments["testfun"] =
6666 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6667 "%param1 = OpFunctionParameter %v4f32\n"
6668 "%label_testfun = OpLabel\n"
6669 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n"
6670 "OpReturnValue %param1\n"
6672 addTessCtrlTest(testGroup.get(), "in_function", fragments);
6674 // Common setup code for the following tests.
6675 fragments["pre_main"] =
6676 "%Workgroup = OpConstant %i32 2\n"
6677 "%SequentiallyConsistent = OpConstant %i32 0x10\n"
6678 "%c_f32_5 = OpConstant %f32 5.\n";
6679 const string setupPercentZero = // Begins %test_code function with code that sets %zero to 0u but cannot be optimized away.
6680 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6681 "%param1 = OpFunctionParameter %v4f32\n"
6682 "%entry = OpLabel\n"
6683 ";param1 components are between 0 and 1, so dot product is 4 or less\n"
6684 "%dot = OpDot %f32 %param1 %param1\n"
6685 "%div = OpFDiv %f32 %dot %c_f32_5\n"
6686 "%zero = OpConvertFToU %u32 %div\n";
6688 // Barriers inside OpSwitch branches.
6689 fragments["testfun"] =
6691 "OpSelectionMerge %switch_exit None\n"
6692 "OpSwitch %zero %switch_default 0 %case0 1 %case1 ;should always go to %case0\n"
6694 "%case1 = OpLabel\n"
6695 ";This barrier should never be executed, but its presence makes test failure more likely when there's a bug.\n"
6696 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n"
6697 "%wrong_branch_alert1 = OpVectorInsertDynamic %v4f32 %param1 %c_f32_0_5 %c_i32_0\n"
6698 "OpBranch %switch_exit\n"
6700 "%switch_default = OpLabel\n"
6701 "%wrong_branch_alert2 = OpVectorInsertDynamic %v4f32 %param1 %c_f32_0_5 %c_i32_0\n"
6702 ";This barrier should never be executed, but its presence makes test failure more likely when there's a bug.\n"
6703 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n"
6704 "OpBranch %switch_exit\n"
6706 "%case0 = OpLabel\n"
6707 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n"
6708 "OpBranch %switch_exit\n"
6710 "%switch_exit = OpLabel\n"
6711 "%ret = OpPhi %v4f32 %param1 %case0 %wrong_branch_alert1 %case1 %wrong_branch_alert2 %switch_default\n"
6712 "OpReturnValue %ret\n"
6714 addTessCtrlTest(testGroup.get(), "in_switch", fragments);
6716 // Barriers inside if-then-else.
6717 fragments["testfun"] =
6719 "%eq0 = OpIEqual %bool %zero %c_u32_0\n"
6720 "OpSelectionMerge %exit DontFlatten\n"
6721 "OpBranchConditional %eq0 %then %else\n"
6724 ";This barrier should never be executed, but its presence makes test failure more likely when there's a bug.\n"
6725 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n"
6726 "%wrong_branch_alert = OpVectorInsertDynamic %v4f32 %param1 %c_f32_0_5 %c_i32_0\n"
6730 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n"
6734 "%ret = OpPhi %v4f32 %param1 %then %wrong_branch_alert %else\n"
6735 "OpReturnValue %ret\n"
6737 addTessCtrlTest(testGroup.get(), "in_if", fragments);
6739 // A barrier after control-flow reconvergence, tempting the compiler to attempt something like this:
6740 // http://lists.llvm.org/pipermail/llvm-dev/2009-October/026317.html.
6741 fragments["testfun"] =
6743 "%thread_id = OpLoad %i32 %BP_gl_InvocationID\n"
6744 "%thread0 = OpIEqual %bool %thread_id %c_i32_0\n"
6745 "OpSelectionMerge %exit DontFlatten\n"
6746 "OpBranchConditional %thread0 %then %else\n"
6749 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
6753 "%val1 = OpVectorExtractDynamic %f32 %param1 %zero\n"
6757 "%val = OpPhi %f32 %val0 %else %val1 %then\n"
6758 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n"
6759 "%ret = OpVectorInsertDynamic %v4f32 %param1 %val %zero\n"
6760 "OpReturnValue %ret\n"
6762 addTessCtrlTest(testGroup.get(), "after_divergent_if", fragments);
6764 // A barrier inside a loop.
6765 fragments["pre_main"] =
6766 "%Workgroup = OpConstant %i32 2\n"
6767 "%SequentiallyConsistent = OpConstant %i32 0x10\n"
6768 "%c_f32_10 = OpConstant %f32 10.\n";
6769 fragments["testfun"] =
6770 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6771 "%param1 = OpFunctionParameter %v4f32\n"
6772 "%entry = OpLabel\n"
6773 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
6776 ";adds 4, 3, 2, and 1 to %val0\n"
6778 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %loop\n"
6779 "%val1 = OpPhi %f32 %val0 %entry %val %loop\n"
6780 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n"
6781 "%fcount = OpConvertSToF %f32 %count\n"
6782 "%val = OpFAdd %f32 %val1 %fcount\n"
6783 "%count__ = OpISub %i32 %count %c_i32_1\n"
6784 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
6785 "OpLoopMerge %exit %loop None\n"
6786 "OpBranchConditional %again %loop %exit\n"
6789 "%same = OpFSub %f32 %val %c_f32_10\n"
6790 "%ret = OpVectorInsertDynamic %v4f32 %param1 %same %c_i32_0\n"
6791 "OpReturnValue %ret\n"
6793 addTessCtrlTest(testGroup.get(), "in_loop", fragments);
6795 return testGroup.release();
6798 // Test for the OpFRem instruction.
6799 tcu::TestCaseGroup* createFRemTests(tcu::TestContext& testCtx)
6801 de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, "frem", "OpFRem"));
6802 map<string, string> fragments;
6803 RGBA inputColors[4];
6804 RGBA outputColors[4];
6806 fragments["pre_main"] =
6807 "%c_f32_3 = OpConstant %f32 3.0\n"
6808 "%c_f32_n3 = OpConstant %f32 -3.0\n"
6809 "%c_f32_4 = OpConstant %f32 4.0\n"
6810 "%c_f32_p75 = OpConstant %f32 0.75\n"
6811 "%c_v4f32_p75_p75_p75_p75 = OpConstantComposite %v4f32 %c_f32_p75 %c_f32_p75 %c_f32_p75 %c_f32_p75 \n"
6812 "%c_v4f32_4_4_4_4 = OpConstantComposite %v4f32 %c_f32_4 %c_f32_4 %c_f32_4 %c_f32_4\n"
6813 "%c_v4f32_3_n3_3_n3 = OpConstantComposite %v4f32 %c_f32_3 %c_f32_n3 %c_f32_3 %c_f32_n3\n";
6815 // The test does the following.
6816 // vec4 result = (param1 * 8.0) - 4.0;
6817 // return (frem(result.x,3) + 0.75, frem(result.y, -3) + 0.75, 0, 1)
6818 fragments["testfun"] =
6819 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6820 "%param1 = OpFunctionParameter %v4f32\n"
6821 "%label_testfun = OpLabel\n"
6822 "%v_times_8 = OpVectorTimesScalar %v4f32 %param1 %c_f32_8\n"
6823 "%minus_4 = OpFSub %v4f32 %v_times_8 %c_v4f32_4_4_4_4\n"
6824 "%frem = OpFRem %v4f32 %minus_4 %c_v4f32_3_n3_3_n3\n"
6825 "%added = OpFAdd %v4f32 %frem %c_v4f32_p75_p75_p75_p75\n"
6826 "%xyz_1 = OpVectorInsertDynamic %v4f32 %added %c_f32_1 %c_i32_3\n"
6827 "%xy_0_1 = OpVectorInsertDynamic %v4f32 %xyz_1 %c_f32_0 %c_i32_2\n"
6828 "OpReturnValue %xy_0_1\n"
6832 inputColors[0] = RGBA(16, 16, 0, 255);
6833 inputColors[1] = RGBA(232, 232, 0, 255);
6834 inputColors[2] = RGBA(232, 16, 0, 255);
6835 inputColors[3] = RGBA(16, 232, 0, 255);
6837 outputColors[0] = RGBA(64, 64, 0, 255);
6838 outputColors[1] = RGBA(255, 255, 0, 255);
6839 outputColors[2] = RGBA(255, 64, 0, 255);
6840 outputColors[3] = RGBA(64, 255, 0, 255);
6842 createTestsForAllStages("frem", inputColors, outputColors, fragments, testGroup.get());
6843 return testGroup.release();
6846 // Test for the OpSRem instruction.
6847 tcu::TestCaseGroup* createOpSRemGraphicsTests(tcu::TestContext& testCtx, qpTestResult negFailResult)
6849 de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, "srem", "OpSRem"));
6850 map<string, string> fragments;
6852 fragments["pre_main"] =
6853 "%c_f32_255 = OpConstant %f32 255.0\n"
6854 "%c_i32_128 = OpConstant %i32 128\n"
6855 "%c_i32_255 = OpConstant %i32 255\n"
6856 "%c_v4f32_255 = OpConstantComposite %v4f32 %c_f32_255 %c_f32_255 %c_f32_255 %c_f32_255 \n"
6857 "%c_v4f32_0_5 = OpConstantComposite %v4f32 %c_f32_0_5 %c_f32_0_5 %c_f32_0_5 %c_f32_0_5 \n"
6858 "%c_v4i32_128 = OpConstantComposite %v4i32 %c_i32_128 %c_i32_128 %c_i32_128 %c_i32_128 \n";
6860 // The test does the following.
6861 // ivec4 ints = int(param1 * 255.0 + 0.5) - 128;
6862 // ivec4 result = ivec4(srem(ints.x, ints.y), srem(ints.y, ints.z), srem(ints.z, ints.x), 255);
6863 // return float(result + 128) / 255.0;
6864 fragments["testfun"] =
6865 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6866 "%param1 = OpFunctionParameter %v4f32\n"
6867 "%label_testfun = OpLabel\n"
6868 "%div255 = OpFMul %v4f32 %param1 %c_v4f32_255\n"
6869 "%add0_5 = OpFAdd %v4f32 %div255 %c_v4f32_0_5\n"
6870 "%uints_in = OpConvertFToS %v4i32 %add0_5\n"
6871 "%ints_in = OpISub %v4i32 %uints_in %c_v4i32_128\n"
6872 "%x_in = OpCompositeExtract %i32 %ints_in 0\n"
6873 "%y_in = OpCompositeExtract %i32 %ints_in 1\n"
6874 "%z_in = OpCompositeExtract %i32 %ints_in 2\n"
6875 "%x_out = OpSRem %i32 %x_in %y_in\n"
6876 "%y_out = OpSRem %i32 %y_in %z_in\n"
6877 "%z_out = OpSRem %i32 %z_in %x_in\n"
6878 "%ints_out = OpCompositeConstruct %v4i32 %x_out %y_out %z_out %c_i32_255\n"
6879 "%ints_offset = OpIAdd %v4i32 %ints_out %c_v4i32_128\n"
6880 "%f_ints_offset = OpConvertSToF %v4f32 %ints_offset\n"
6881 "%float_out = OpFDiv %v4f32 %f_ints_offset %c_v4f32_255\n"
6882 "OpReturnValue %float_out\n"
6885 const struct CaseParams
6888 const char* failMessageTemplate; // customized status message
6889 qpTestResult failResult; // override status on failure
6890 int operands[4][3]; // four (x, y, z) vectors of operands
6891 int results[4][3]; // four (x, y, z) vectors of results
6897 QP_TEST_RESULT_FAIL,
6898 { { 5, 12, 17 }, { 5, 5, 7 }, { 75, 8, 81 }, { 25, 60, 100 } }, // operands
6899 { { 5, 12, 2 }, { 0, 5, 2 }, { 3, 8, 6 }, { 25, 60, 0 } }, // results
6903 "Inconsistent results, but within specification: ${reason}",
6904 negFailResult, // negative operands, not required by the spec
6905 { { 5, 12, -17 }, { -5, -5, 7 }, { 75, 8, -81 }, { 25, -60, 100 } }, // operands
6906 { { 5, 12, -2 }, { 0, -5, 2 }, { 3, 8, -6 }, { 25, -60, 0 } }, // results
6909 // If either operand is negative the result is undefined. Some implementations may still return correct values.
6911 for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(cases); ++caseNdx)
6913 const CaseParams& params = cases[caseNdx];
6914 RGBA inputColors[4];
6915 RGBA outputColors[4];
6917 for (int i = 0; i < 4; ++i)
6919 inputColors [i] = RGBA(params.operands[i][0] + 128, params.operands[i][1] + 128, params.operands[i][2] + 128, 255);
6920 outputColors[i] = RGBA(params.results [i][0] + 128, params.results [i][1] + 128, params.results [i][2] + 128, 255);
6923 createTestsForAllStages(params.name, inputColors, outputColors, fragments, testGroup.get(), params.failResult, params.failMessageTemplate);
6926 return testGroup.release();
6929 // Test for the OpSMod instruction.
6930 tcu::TestCaseGroup* createOpSModGraphicsTests(tcu::TestContext& testCtx, qpTestResult negFailResult)
6932 de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, "smod", "OpSMod"));
6933 map<string, string> fragments;
6935 fragments["pre_main"] =
6936 "%c_f32_255 = OpConstant %f32 255.0\n"
6937 "%c_i32_128 = OpConstant %i32 128\n"
6938 "%c_i32_255 = OpConstant %i32 255\n"
6939 "%c_v4f32_255 = OpConstantComposite %v4f32 %c_f32_255 %c_f32_255 %c_f32_255 %c_f32_255 \n"
6940 "%c_v4f32_0_5 = OpConstantComposite %v4f32 %c_f32_0_5 %c_f32_0_5 %c_f32_0_5 %c_f32_0_5 \n"
6941 "%c_v4i32_128 = OpConstantComposite %v4i32 %c_i32_128 %c_i32_128 %c_i32_128 %c_i32_128 \n";
6943 // The test does the following.
6944 // ivec4 ints = int(param1 * 255.0 + 0.5) - 128;
6945 // ivec4 result = ivec4(smod(ints.x, ints.y), smod(ints.y, ints.z), smod(ints.z, ints.x), 255);
6946 // return float(result + 128) / 255.0;
6947 fragments["testfun"] =
6948 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6949 "%param1 = OpFunctionParameter %v4f32\n"
6950 "%label_testfun = OpLabel\n"
6951 "%div255 = OpFMul %v4f32 %param1 %c_v4f32_255\n"
6952 "%add0_5 = OpFAdd %v4f32 %div255 %c_v4f32_0_5\n"
6953 "%uints_in = OpConvertFToS %v4i32 %add0_5\n"
6954 "%ints_in = OpISub %v4i32 %uints_in %c_v4i32_128\n"
6955 "%x_in = OpCompositeExtract %i32 %ints_in 0\n"
6956 "%y_in = OpCompositeExtract %i32 %ints_in 1\n"
6957 "%z_in = OpCompositeExtract %i32 %ints_in 2\n"
6958 "%x_out = OpSMod %i32 %x_in %y_in\n"
6959 "%y_out = OpSMod %i32 %y_in %z_in\n"
6960 "%z_out = OpSMod %i32 %z_in %x_in\n"
6961 "%ints_out = OpCompositeConstruct %v4i32 %x_out %y_out %z_out %c_i32_255\n"
6962 "%ints_offset = OpIAdd %v4i32 %ints_out %c_v4i32_128\n"
6963 "%f_ints_offset = OpConvertSToF %v4f32 %ints_offset\n"
6964 "%float_out = OpFDiv %v4f32 %f_ints_offset %c_v4f32_255\n"
6965 "OpReturnValue %float_out\n"
6968 const struct CaseParams
6971 const char* failMessageTemplate; // customized status message
6972 qpTestResult failResult; // override status on failure
6973 int operands[4][3]; // four (x, y, z) vectors of operands
6974 int results[4][3]; // four (x, y, z) vectors of results
6980 QP_TEST_RESULT_FAIL,
6981 { { 5, 12, 17 }, { 5, 5, 7 }, { 75, 8, 81 }, { 25, 60, 100 } }, // operands
6982 { { 5, 12, 2 }, { 0, 5, 2 }, { 3, 8, 6 }, { 25, 60, 0 } }, // results
6986 "Inconsistent results, but within specification: ${reason}",
6987 negFailResult, // negative operands, not required by the spec
6988 { { 5, 12, -17 }, { -5, -5, 7 }, { 75, 8, -81 }, { 25, -60, 100 } }, // operands
6989 { { 5, -5, 3 }, { 0, 2, -3 }, { 3, -73, 69 }, { -35, 40, 0 } }, // results
6992 // If either operand is negative the result is undefined. Some implementations may still return correct values.
6994 for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(cases); ++caseNdx)
6996 const CaseParams& params = cases[caseNdx];
6997 RGBA inputColors[4];
6998 RGBA outputColors[4];
7000 for (int i = 0; i < 4; ++i)
7002 inputColors [i] = RGBA(params.operands[i][0] + 128, params.operands[i][1] + 128, params.operands[i][2] + 128, 255);
7003 outputColors[i] = RGBA(params.results [i][0] + 128, params.results [i][1] + 128, params.results [i][2] + 128, 255);
7006 createTestsForAllStages(params.name, inputColors, outputColors, fragments, testGroup.get(), params.failResult, params.failMessageTemplate);
7008 return testGroup.release();
7014 INTEGER_TYPE_SIGNED_16,
7015 INTEGER_TYPE_SIGNED_32,
7016 INTEGER_TYPE_SIGNED_64,
7018 INTEGER_TYPE_UNSIGNED_16,
7019 INTEGER_TYPE_UNSIGNED_32,
7020 INTEGER_TYPE_UNSIGNED_64,
7023 const string getBitWidthStr (IntegerType type)
7027 case INTEGER_TYPE_SIGNED_16:
7028 case INTEGER_TYPE_UNSIGNED_16: return "16";
7030 case INTEGER_TYPE_SIGNED_32:
7031 case INTEGER_TYPE_UNSIGNED_32: return "32";
7033 case INTEGER_TYPE_SIGNED_64:
7034 case INTEGER_TYPE_UNSIGNED_64: return "64";
7036 default: DE_ASSERT(false);
7041 const string getByteWidthStr (IntegerType type)
7045 case INTEGER_TYPE_SIGNED_16:
7046 case INTEGER_TYPE_UNSIGNED_16: return "2";
7048 case INTEGER_TYPE_SIGNED_32:
7049 case INTEGER_TYPE_UNSIGNED_32: return "4";
7051 case INTEGER_TYPE_SIGNED_64:
7052 case INTEGER_TYPE_UNSIGNED_64: return "8";
7054 default: DE_ASSERT(false);
7059 bool isSigned (IntegerType type)
7061 return (type <= INTEGER_TYPE_SIGNED_64);
7064 const string getTypeName (IntegerType type)
7066 string prefix = isSigned(type) ? "" : "u";
7067 return prefix + "int" + getBitWidthStr(type);
7070 const string getTestName (IntegerType from, IntegerType to)
7072 return getTypeName(from) + "_to_" + getTypeName(to);
7075 const string getAsmTypeDeclaration (IntegerType type)
7077 string sign = isSigned(type) ? " 1" : " 0";
7078 return "OpTypeInt " + getBitWidthStr(type) + sign;
7081 template<typename T>
7082 BufferSp getSpecializedBuffer (deInt64 number)
7084 return BufferSp(new Buffer<T>(vector<T>(1, (T)number)));
7087 BufferSp getBuffer (IntegerType type, deInt64 number)
7091 case INTEGER_TYPE_SIGNED_16: return getSpecializedBuffer<deInt16>(number);
7092 case INTEGER_TYPE_SIGNED_32: return getSpecializedBuffer<deInt32>(number);
7093 case INTEGER_TYPE_SIGNED_64: return getSpecializedBuffer<deInt64>(number);
7095 case INTEGER_TYPE_UNSIGNED_16: return getSpecializedBuffer<deUint16>(number);
7096 case INTEGER_TYPE_UNSIGNED_32: return getSpecializedBuffer<deUint32>(number);
7097 case INTEGER_TYPE_UNSIGNED_64: return getSpecializedBuffer<deUint64>(number);
7099 default: DE_ASSERT(false);
7100 return BufferSp(new Buffer<deInt32>(vector<deInt32>(1, 0)));
7104 bool usesInt16 (IntegerType from, IntegerType to)
7106 return (from == INTEGER_TYPE_SIGNED_16 || from == INTEGER_TYPE_UNSIGNED_16
7107 || to == INTEGER_TYPE_SIGNED_16 || to == INTEGER_TYPE_UNSIGNED_16);
7110 bool usesInt64 (IntegerType from, IntegerType to)
7112 return (from == INTEGER_TYPE_SIGNED_64 || from == INTEGER_TYPE_UNSIGNED_64
7113 || to == INTEGER_TYPE_SIGNED_64 || to == INTEGER_TYPE_UNSIGNED_64);
7116 ComputeTestFeatures getConversionUsedFeatures (IntegerType from, IntegerType to)
7118 if (usesInt16(from, to))
7120 if (usesInt64(from, to))
7122 return COMPUTE_TEST_USES_INT16_INT64;
7126 return COMPUTE_TEST_USES_INT16;
7131 return COMPUTE_TEST_USES_INT64;
7137 ConvertCase (IntegerType from, IntegerType to, deInt64 number)
7140 , m_features (getConversionUsedFeatures(from, to))
7141 , m_name (getTestName(from, to))
7142 , m_inputBuffer (getBuffer(from, number))
7143 , m_outputBuffer (getBuffer(to, number))
7145 m_asmTypes["inputType"] = getAsmTypeDeclaration(from);
7146 m_asmTypes["outputType"] = getAsmTypeDeclaration(to);
7148 if (m_features == COMPUTE_TEST_USES_INT16)
7150 m_asmTypes["int_capabilities"] = "OpCapability Int16\n"
7151 "OpCapability StorageUniformBufferBlock16\n";
7152 m_asmTypes["int_extensions"] = "OpExtension \"SPV_KHR_16bit_storage\"\n";
7154 else if (m_features == COMPUTE_TEST_USES_INT64)
7156 m_asmTypes["int_capabilities"] = "OpCapability Int64\n";
7157 m_asmTypes["int_extensions"] = "";
7159 else if (m_features == COMPUTE_TEST_USES_INT16_INT64)
7161 m_asmTypes["int_capabilities"] = "OpCapability Int16\n"
7162 "OpCapability StorageUniformBufferBlock16\n"
7163 "OpCapability Int64\n";
7164 m_asmTypes["int_extensions"] = "OpExtension \"SPV_KHR_16bit_storage\"\n";
7172 IntegerType m_fromType;
7173 IntegerType m_toType;
7174 ComputeTestFeatures m_features;
7176 map<string, string> m_asmTypes;
7177 BufferSp m_inputBuffer;
7178 BufferSp m_outputBuffer;
7181 const string getConvertCaseShaderStr (const string& instruction, const ConvertCase& convertCase)
7183 map<string, string> params = convertCase.m_asmTypes;
7185 params["instruction"] = instruction;
7187 params["inDecorator"] = getByteWidthStr(convertCase.m_fromType);
7188 params["outDecorator"] = getByteWidthStr(convertCase.m_toType);
7190 const StringTemplate shader (
7191 "OpCapability Shader\n"
7192 "${int_capabilities}"
7194 "OpMemoryModel Logical GLSL450\n"
7195 "OpEntryPoint GLCompute %main \"main\" %id\n"
7196 "OpExecutionMode %main LocalSize 1 1 1\n"
7197 "OpSource GLSL 430\n"
7198 "OpName %main \"main\"\n"
7199 "OpName %id \"gl_GlobalInvocationID\"\n"
7201 "OpDecorate %id BuiltIn GlobalInvocationId\n"
7202 "OpDecorate %indata DescriptorSet 0\n"
7203 "OpDecorate %indata Binding 0\n"
7204 "OpDecorate %outdata DescriptorSet 0\n"
7205 "OpDecorate %outdata Binding 1\n"
7206 "OpDecorate %in_arr ArrayStride ${inDecorator}\n"
7207 "OpDecorate %out_arr ArrayStride ${outDecorator}\n"
7208 "OpDecorate %in_buf BufferBlock\n"
7209 "OpDecorate %out_buf BufferBlock\n"
7210 "OpMemberDecorate %in_buf 0 Offset 0\n"
7211 "OpMemberDecorate %out_buf 0 Offset 0\n"
7213 "%void = OpTypeVoid\n"
7214 "%voidf = OpTypeFunction %void\n"
7215 "%u32 = OpTypeInt 32 0\n"
7216 "%i32 = OpTypeInt 32 1\n"
7217 "%uvec3 = OpTypeVector %u32 3\n"
7218 "%uvec3ptr = OpTypePointer Input %uvec3\n"
7220 "%in_type = ${inputType}\n"
7221 "%out_type = ${outputType}\n"
7223 "%in_ptr = OpTypePointer Uniform %in_type\n"
7224 "%out_ptr = OpTypePointer Uniform %out_type\n"
7225 "%in_arr = OpTypeRuntimeArray %in_type\n"
7226 "%out_arr = OpTypeRuntimeArray %out_type\n"
7227 "%in_buf = OpTypeStruct %in_arr\n"
7228 "%out_buf = OpTypeStruct %out_arr\n"
7229 "%in_bufptr = OpTypePointer Uniform %in_buf\n"
7230 "%out_bufptr = OpTypePointer Uniform %out_buf\n"
7231 "%indata = OpVariable %in_bufptr Uniform\n"
7232 "%outdata = OpVariable %out_bufptr Uniform\n"
7233 "%inputptr = OpTypePointer Input %in_type\n"
7234 "%id = OpVariable %uvec3ptr Input\n"
7236 "%zero = OpConstant %i32 0\n"
7238 "%main = OpFunction %void None %voidf\n"
7239 "%label = OpLabel\n"
7240 "%idval = OpLoad %uvec3 %id\n"
7241 "%x = OpCompositeExtract %u32 %idval 0\n"
7242 "%inloc = OpAccessChain %in_ptr %indata %zero %x\n"
7243 "%outloc = OpAccessChain %out_ptr %outdata %zero %x\n"
7244 "%inval = OpLoad %in_type %inloc\n"
7245 "%conv = ${instruction} %out_type %inval\n"
7246 " OpStore %outloc %conv\n"
7251 return shader.specialize(params);
7254 void createSConvertCases (vector<ConvertCase>& testCases)
7256 // Convert int to int
7257 testCases.push_back(ConvertCase(INTEGER_TYPE_SIGNED_16, INTEGER_TYPE_SIGNED_32, 14669));
7258 testCases.push_back(ConvertCase(INTEGER_TYPE_SIGNED_16, INTEGER_TYPE_SIGNED_64, 3341));
7260 testCases.push_back(ConvertCase(INTEGER_TYPE_SIGNED_32, INTEGER_TYPE_SIGNED_64, 973610259));
7262 // Convert int to unsigned int
7263 testCases.push_back(ConvertCase(INTEGER_TYPE_SIGNED_16, INTEGER_TYPE_UNSIGNED_32, 9288));
7264 testCases.push_back(ConvertCase(INTEGER_TYPE_SIGNED_16, INTEGER_TYPE_UNSIGNED_64, 15460));
7266 testCases.push_back(ConvertCase(INTEGER_TYPE_SIGNED_32, INTEGER_TYPE_UNSIGNED_64, 346213461));
7269 // Test for the OpSConvert instruction.
7270 tcu::TestCaseGroup* createSConvertTests (tcu::TestContext& testCtx)
7272 const string instruction ("OpSConvert");
7273 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "sconvert", "OpSConvert"));
7274 vector<ConvertCase> testCases;
7275 createSConvertCases(testCases);
7277 for (vector<ConvertCase>::const_iterator test = testCases.begin(); test != testCases.end(); ++test)
7279 ComputeShaderSpec spec;
7281 spec.assembly = getConvertCaseShaderStr(instruction, *test);
7282 spec.inputs.push_back(test->m_inputBuffer);
7283 spec.outputs.push_back(test->m_outputBuffer);
7284 spec.numWorkGroups = IVec3(1, 1, 1);
7286 if (test->m_features == COMPUTE_TEST_USES_INT16 || test->m_features == COMPUTE_TEST_USES_INT16_INT64)
7288 spec.extensions.push_back("VK_KHR_16bit_storage");
7289 spec.requestedVulkanFeatures.ext16BitStorage = EXT16BITSTORAGEFEATURES_UNIFORM_BUFFER_BLOCK;
7292 group->addChild(new SpvAsmComputeShaderCase(testCtx, test->m_name.c_str(), "Convert integers with OpSConvert.", spec, test->m_features));
7295 return group.release();
7298 void createUConvertCases (vector<ConvertCase>& testCases)
7300 // Convert unsigned int to unsigned int
7301 testCases.push_back(ConvertCase(INTEGER_TYPE_UNSIGNED_16, INTEGER_TYPE_UNSIGNED_32, 60653));
7302 testCases.push_back(ConvertCase(INTEGER_TYPE_UNSIGNED_16, INTEGER_TYPE_UNSIGNED_64, 17991));
7304 testCases.push_back(ConvertCase(INTEGER_TYPE_UNSIGNED_32, INTEGER_TYPE_UNSIGNED_64, 904256275));
7307 // Test for the OpUConvert instruction.
7308 tcu::TestCaseGroup* createUConvertTests (tcu::TestContext& testCtx)
7310 const string instruction ("OpUConvert");
7311 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "uconvert", "OpUConvert"));
7312 vector<ConvertCase> testCases;
7313 createUConvertCases(testCases);
7315 for (vector<ConvertCase>::const_iterator test = testCases.begin(); test != testCases.end(); ++test)
7317 ComputeShaderSpec spec;
7319 spec.assembly = getConvertCaseShaderStr(instruction, *test);
7320 spec.inputs.push_back(test->m_inputBuffer);
7321 spec.outputs.push_back(test->m_outputBuffer);
7322 spec.numWorkGroups = IVec3(1, 1, 1);
7324 if (test->m_features == COMPUTE_TEST_USES_INT16 || test->m_features == COMPUTE_TEST_USES_INT16_INT64)
7326 spec.extensions.push_back("VK_KHR_16bit_storage");
7327 spec.requestedVulkanFeatures.ext16BitStorage = EXT16BITSTORAGEFEATURES_UNIFORM_BUFFER_BLOCK;
7330 group->addChild(new SpvAsmComputeShaderCase(testCtx, test->m_name.c_str(), "Convert integers with OpUConvert.", spec, test->m_features));
7332 return group.release();
7335 const string getNumberTypeName (const NumberType type)
7337 if (type == NUMBERTYPE_INT32)
7341 else if (type == NUMBERTYPE_UINT32)
7345 else if (type == NUMBERTYPE_FLOAT32)
7356 deInt32 getInt(de::Random& rnd)
7358 return rnd.getInt(std::numeric_limits<int>::min(), std::numeric_limits<int>::max());
7361 const string repeatString (const string& str, int times)
7364 for (int i = 0; i < times; ++i)
7371 const string getRandomConstantString (const NumberType type, de::Random& rnd)
7373 if (type == NUMBERTYPE_INT32)
7375 return numberToString<deInt32>(getInt(rnd));
7377 else if (type == NUMBERTYPE_UINT32)
7379 return numberToString<deUint32>(rnd.getUint32());
7381 else if (type == NUMBERTYPE_FLOAT32)
7383 return numberToString<float>(rnd.getFloat());
7392 void createVectorCompositeCases (vector<map<string, string> >& testCases, de::Random& rnd, const NumberType type)
7394 map<string, string> params;
7397 for (int width = 2; width <= 4; ++width)
7399 string randomConst = numberToString(getInt(rnd));
7400 string widthStr = numberToString(width);
7401 int index = rnd.getInt(0, width-1);
7403 params["type"] = "vec";
7404 params["name"] = params["type"] + "_" + widthStr;
7405 params["compositeType"] = "%composite = OpTypeVector %custom " + widthStr +"\n";
7406 params["filler"] = string("%filler = OpConstant %custom ") + getRandomConstantString(type, rnd) + "\n";
7407 params["compositeConstruct"] = "%instance = OpCompositeConstruct %composite" + repeatString(" %filler", width) + "\n";
7408 params["indexes"] = numberToString(index);
7409 testCases.push_back(params);
7413 void createArrayCompositeCases (vector<map<string, string> >& testCases, de::Random& rnd, const NumberType type)
7415 const int limit = 10;
7416 map<string, string> params;
7418 for (int width = 2; width <= limit; ++width)
7420 string randomConst = numberToString(getInt(rnd));
7421 string widthStr = numberToString(width);
7422 int index = rnd.getInt(0, width-1);
7424 params["type"] = "array";
7425 params["name"] = params["type"] + "_" + widthStr;
7426 params["compositeType"] = string("%arraywidth = OpConstant %u32 " + widthStr + "\n")
7427 + "%composite = OpTypeArray %custom %arraywidth\n";
7429 params["filler"] = string("%filler = OpConstant %custom ") + getRandomConstantString(type, rnd) + "\n";
7430 params["compositeConstruct"] = "%instance = OpCompositeConstruct %composite" + repeatString(" %filler", width) + "\n";
7431 params["indexes"] = numberToString(index);
7432 testCases.push_back(params);
7436 void createStructCompositeCases (vector<map<string, string> >& testCases, de::Random& rnd, const NumberType type)
7438 const int limit = 10;
7439 map<string, string> params;
7441 for (int width = 2; width <= limit; ++width)
7443 string randomConst = numberToString(getInt(rnd));
7444 int index = rnd.getInt(0, width-1);
7446 params["type"] = "struct";
7447 params["name"] = params["type"] + "_" + numberToString(width);
7448 params["compositeType"] = "%composite = OpTypeStruct" + repeatString(" %custom", width) + "\n";
7449 params["filler"] = string("%filler = OpConstant %custom ") + getRandomConstantString(type, rnd) + "\n";
7450 params["compositeConstruct"] = "%instance = OpCompositeConstruct %composite" + repeatString(" %filler", width) + "\n";
7451 params["indexes"] = numberToString(index);
7452 testCases.push_back(params);
7456 void createMatrixCompositeCases (vector<map<string, string> >& testCases, de::Random& rnd, const NumberType type)
7458 map<string, string> params;
7461 for (int width = 2; width <= 4; ++width)
7463 string widthStr = numberToString(width);
7465 for (int column = 2 ; column <= 4; ++column)
7467 int index_0 = rnd.getInt(0, column-1);
7468 int index_1 = rnd.getInt(0, width-1);
7469 string columnStr = numberToString(column);
7471 params["type"] = "matrix";
7472 params["name"] = params["type"] + "_" + widthStr + "x" + columnStr;
7473 params["compositeType"] = string("%vectype = OpTypeVector %custom " + widthStr + "\n")
7474 + "%composite = OpTypeMatrix %vectype " + columnStr + "\n";
7476 params["filler"] = string("%filler = OpConstant %custom ") + getRandomConstantString(type, rnd) + "\n"
7477 + "%fillerVec = OpConstantComposite %vectype" + repeatString(" %filler", width) + "\n";
7479 params["compositeConstruct"] = "%instance = OpCompositeConstruct %composite" + repeatString(" %fillerVec", column) + "\n";
7480 params["indexes"] = numberToString(index_0) + " " + numberToString(index_1);
7481 testCases.push_back(params);
7486 void createCompositeCases (vector<map<string, string> >& testCases, de::Random& rnd, const NumberType type)
7488 createVectorCompositeCases(testCases, rnd, type);
7489 createArrayCompositeCases(testCases, rnd, type);
7490 createStructCompositeCases(testCases, rnd, type);
7491 // Matrix only supports float types
7492 if (type == NUMBERTYPE_FLOAT32)
7494 createMatrixCompositeCases(testCases, rnd, type);
7498 const string getAssemblyTypeDeclaration (const NumberType type)
7502 case NUMBERTYPE_INT32: return "OpTypeInt 32 1";
7503 case NUMBERTYPE_UINT32: return "OpTypeInt 32 0";
7504 case NUMBERTYPE_FLOAT32: return "OpTypeFloat 32";
7505 default: DE_ASSERT(false); return "";
7509 const string specializeCompositeInsertShaderTemplate (const NumberType type, const map<string, string>& params)
7511 map<string, string> parameters(params);
7513 parameters["typeDeclaration"] = getAssemblyTypeDeclaration(type);
7515 parameters["compositeDecorator"] = (parameters["type"] == "array") ? "OpDecorate %composite ArrayStride 4\n" : "";
7517 return StringTemplate (
7518 "OpCapability Shader\n"
7519 "OpCapability Matrix\n"
7520 "OpMemoryModel Logical GLSL450\n"
7521 "OpEntryPoint GLCompute %main \"main\" %id\n"
7522 "OpExecutionMode %main LocalSize 1 1 1\n"
7524 "OpSource GLSL 430\n"
7525 "OpName %main \"main\"\n"
7526 "OpName %id \"gl_GlobalInvocationID\"\n"
7529 "OpDecorate %id BuiltIn GlobalInvocationId\n"
7530 "OpDecorate %buf BufferBlock\n"
7531 "OpDecorate %indata DescriptorSet 0\n"
7532 "OpDecorate %indata Binding 0\n"
7533 "OpDecorate %outdata DescriptorSet 0\n"
7534 "OpDecorate %outdata Binding 1\n"
7535 "OpDecorate %customarr ArrayStride 4\n"
7536 "${compositeDecorator}"
7537 "OpMemberDecorate %buf 0 Offset 0\n"
7540 "%void = OpTypeVoid\n"
7541 "%voidf = OpTypeFunction %void\n"
7542 "%u32 = OpTypeInt 32 0\n"
7543 "%i32 = OpTypeInt 32 1\n"
7544 "%uvec3 = OpTypeVector %u32 3\n"
7545 "%uvec3ptr = OpTypePointer Input %uvec3\n"
7548 "%custom = ${typeDeclaration}\n"
7554 // Inherited from custom
7555 "%customptr = OpTypePointer Uniform %custom\n"
7556 "%customarr = OpTypeRuntimeArray %custom\n"
7557 "%buf = OpTypeStruct %customarr\n"
7558 "%bufptr = OpTypePointer Uniform %buf\n"
7560 "%indata = OpVariable %bufptr Uniform\n"
7561 "%outdata = OpVariable %bufptr Uniform\n"
7563 "%id = OpVariable %uvec3ptr Input\n"
7564 "%zero = OpConstant %i32 0\n"
7566 "%main = OpFunction %void None %voidf\n"
7567 "%label = OpLabel\n"
7568 "%idval = OpLoad %uvec3 %id\n"
7569 "%x = OpCompositeExtract %u32 %idval 0\n"
7571 "%inloc = OpAccessChain %customptr %indata %zero %x\n"
7572 "%outloc = OpAccessChain %customptr %outdata %zero %x\n"
7573 // Read the input value
7574 "%inval = OpLoad %custom %inloc\n"
7575 // Create the composite and fill it
7576 "${compositeConstruct}"
7577 // Insert the input value to a place
7578 "%instance2 = OpCompositeInsert %composite %inval %instance ${indexes}\n"
7579 // Read back the value from the position
7580 "%out_val = OpCompositeExtract %custom %instance2 ${indexes}\n"
7581 // Store it in the output position
7582 " OpStore %outloc %out_val\n"
7585 ).specialize(parameters);
7588 template<typename T>
7589 BufferSp createCompositeBuffer(T number)
7591 return BufferSp(new Buffer<T>(vector<T>(1, number)));
7594 tcu::TestCaseGroup* createOpCompositeInsertGroup (tcu::TestContext& testCtx)
7596 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opcompositeinsert", "Test the OpCompositeInsert instruction"));
7597 de::Random rnd (deStringHash(group->getName()));
7599 for (int type = NUMBERTYPE_INT32; type != NUMBERTYPE_END32; ++type)
7601 NumberType numberType = NumberType(type);
7602 const string typeName = getNumberTypeName(numberType);
7603 const string description = "Test the OpCompositeInsert instruction with " + typeName + "s";
7604 de::MovePtr<tcu::TestCaseGroup> subGroup (new tcu::TestCaseGroup(testCtx, typeName.c_str(), description.c_str()));
7605 vector<map<string, string> > testCases;
7607 createCompositeCases(testCases, rnd, numberType);
7609 for (vector<map<string, string> >::const_iterator test = testCases.begin(); test != testCases.end(); ++test)
7611 ComputeShaderSpec spec;
7613 spec.assembly = specializeCompositeInsertShaderTemplate(numberType, *test);
7617 case NUMBERTYPE_INT32:
7619 deInt32 number = getInt(rnd);
7620 spec.inputs.push_back(createCompositeBuffer<deInt32>(number));
7621 spec.outputs.push_back(createCompositeBuffer<deInt32>(number));
7624 case NUMBERTYPE_UINT32:
7626 deUint32 number = rnd.getUint32();
7627 spec.inputs.push_back(createCompositeBuffer<deUint32>(number));
7628 spec.outputs.push_back(createCompositeBuffer<deUint32>(number));
7631 case NUMBERTYPE_FLOAT32:
7633 float number = rnd.getFloat();
7634 spec.inputs.push_back(createCompositeBuffer<float>(number));
7635 spec.outputs.push_back(createCompositeBuffer<float>(number));
7642 spec.numWorkGroups = IVec3(1, 1, 1);
7643 subGroup->addChild(new SpvAsmComputeShaderCase(testCtx, test->at("name").c_str(), "OpCompositeInsert test", spec));
7645 group->addChild(subGroup.release());
7647 return group.release();
7650 struct AssemblyStructInfo
7652 AssemblyStructInfo (const deUint32 comp, const deUint32 idx)
7657 deUint32 components;
7661 const string specializeInBoundsShaderTemplate (const NumberType type, const AssemblyStructInfo& structInfo, const map<string, string>& params)
7663 // Create the full index string
7664 string fullIndex = numberToString(structInfo.index) + " " + params.at("indexes");
7665 // Convert it to list of indexes
7666 vector<string> indexes = de::splitString(fullIndex, ' ');
7668 map<string, string> parameters (params);
7669 parameters["typeDeclaration"] = getAssemblyTypeDeclaration(type);
7670 parameters["structType"] = repeatString(" %composite", structInfo.components);
7671 parameters["structConstruct"] = repeatString(" %instance", structInfo.components);
7672 parameters["insertIndexes"] = fullIndex;
7674 // In matrix cases the last two index is the CompositeExtract indexes
7675 const deUint32 extractIndexes = (parameters["type"] == "matrix") ? 2 : 1;
7677 // Construct the extractIndex
7678 for (vector<string>::const_iterator index = indexes.end() - extractIndexes; index != indexes.end(); ++index)
7680 parameters["extractIndexes"] += " " + *index;
7683 // Remove the last 1 or 2 element depends on matrix case or not
7684 indexes.erase(indexes.end() - extractIndexes, indexes.end());
7687 // Generate AccessChain index expressions (except for the last one, because we use ptr to the composite)
7688 for (vector<string>::const_iterator index = indexes.begin(); index != indexes.end(); ++index)
7690 string indexId = "%index_" + numberToString(id++);
7691 parameters["accessChainConstDeclaration"] += indexId + " = OpConstant %u32 " + *index + "\n";
7692 parameters["accessChainIndexes"] += " " + indexId;
7695 parameters["compositeDecorator"] = (parameters["type"] == "array") ? "OpDecorate %composite ArrayStride 4\n" : "";
7697 return StringTemplate (
7698 "OpCapability Shader\n"
7699 "OpCapability Matrix\n"
7700 "OpMemoryModel Logical GLSL450\n"
7701 "OpEntryPoint GLCompute %main \"main\" %id\n"
7702 "OpExecutionMode %main LocalSize 1 1 1\n"
7704 "OpSource GLSL 430\n"
7705 "OpName %main \"main\"\n"
7706 "OpName %id \"gl_GlobalInvocationID\"\n"
7708 "OpDecorate %id BuiltIn GlobalInvocationId\n"
7709 "OpDecorate %buf BufferBlock\n"
7710 "OpDecorate %indata DescriptorSet 0\n"
7711 "OpDecorate %indata Binding 0\n"
7712 "OpDecorate %outdata DescriptorSet 0\n"
7713 "OpDecorate %outdata Binding 1\n"
7714 "OpDecorate %customarr ArrayStride 4\n"
7715 "${compositeDecorator}"
7716 "OpMemberDecorate %buf 0 Offset 0\n"
7718 "%void = OpTypeVoid\n"
7719 "%voidf = OpTypeFunction %void\n"
7720 "%u32 = OpTypeInt 32 0\n"
7721 "%uvec3 = OpTypeVector %u32 3\n"
7722 "%uvec3ptr = OpTypePointer Input %uvec3\n"
7724 "%custom = ${typeDeclaration}\n"
7727 // Inherited from composite
7728 "%composite_p = OpTypePointer Function %composite\n"
7729 "%struct_t = OpTypeStruct${structType}\n"
7730 "%struct_p = OpTypePointer Function %struct_t\n"
7733 "${accessChainConstDeclaration}"
7734 // Inherited from custom
7735 "%customptr = OpTypePointer Uniform %custom\n"
7736 "%customarr = OpTypeRuntimeArray %custom\n"
7737 "%buf = OpTypeStruct %customarr\n"
7738 "%bufptr = OpTypePointer Uniform %buf\n"
7739 "%indata = OpVariable %bufptr Uniform\n"
7740 "%outdata = OpVariable %bufptr Uniform\n"
7742 "%id = OpVariable %uvec3ptr Input\n"
7743 "%zero = OpConstant %u32 0\n"
7744 "%main = OpFunction %void None %voidf\n"
7745 "%label = OpLabel\n"
7746 "%struct_v = OpVariable %struct_p Function\n"
7747 "%idval = OpLoad %uvec3 %id\n"
7748 "%x = OpCompositeExtract %u32 %idval 0\n"
7749 // Create the input/output type
7750 "%inloc = OpInBoundsAccessChain %customptr %indata %zero %x\n"
7751 "%outloc = OpInBoundsAccessChain %customptr %outdata %zero %x\n"
7752 // Read the input value
7753 "%inval = OpLoad %custom %inloc\n"
7754 // Create the composite and fill it
7755 "${compositeConstruct}"
7756 // Create the struct and fill it with the composite
7757 "%struct = OpCompositeConstruct %struct_t${structConstruct}\n"
7759 "%comp_obj = OpCompositeInsert %struct_t %inval %struct ${insertIndexes}\n"
7761 " OpStore %struct_v %comp_obj\n"
7762 // Get deepest possible composite pointer
7763 "%inner_ptr = OpInBoundsAccessChain %composite_p %struct_v${accessChainIndexes}\n"
7764 "%read_obj = OpLoad %composite %inner_ptr\n"
7765 // Read back the stored value
7766 "%read_val = OpCompositeExtract %custom %read_obj${extractIndexes}\n"
7767 " OpStore %outloc %read_val\n"
7769 " OpFunctionEnd\n").specialize(parameters);
7772 tcu::TestCaseGroup* createOpInBoundsAccessChainGroup (tcu::TestContext& testCtx)
7774 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opinboundsaccesschain", "Test the OpInBoundsAccessChain instruction"));
7775 de::Random rnd (deStringHash(group->getName()));
7777 for (int type = NUMBERTYPE_INT32; type != NUMBERTYPE_END32; ++type)
7779 NumberType numberType = NumberType(type);
7780 const string typeName = getNumberTypeName(numberType);
7781 const string description = "Test the OpInBoundsAccessChain instruction with " + typeName + "s";
7782 de::MovePtr<tcu::TestCaseGroup> subGroup (new tcu::TestCaseGroup(testCtx, typeName.c_str(), description.c_str()));
7784 vector<map<string, string> > testCases;
7785 createCompositeCases(testCases, rnd, numberType);
7787 for (vector<map<string, string> >::const_iterator test = testCases.begin(); test != testCases.end(); ++test)
7789 ComputeShaderSpec spec;
7791 // Number of components inside of a struct
7792 deUint32 structComponents = rnd.getInt(2, 8);
7793 // Component index value
7794 deUint32 structIndex = rnd.getInt(0, structComponents - 1);
7795 AssemblyStructInfo structInfo(structComponents, structIndex);
7797 spec.assembly = specializeInBoundsShaderTemplate(numberType, structInfo, *test);
7801 case NUMBERTYPE_INT32:
7803 deInt32 number = getInt(rnd);
7804 spec.inputs.push_back(createCompositeBuffer<deInt32>(number));
7805 spec.outputs.push_back(createCompositeBuffer<deInt32>(number));
7808 case NUMBERTYPE_UINT32:
7810 deUint32 number = rnd.getUint32();
7811 spec.inputs.push_back(createCompositeBuffer<deUint32>(number));
7812 spec.outputs.push_back(createCompositeBuffer<deUint32>(number));
7815 case NUMBERTYPE_FLOAT32:
7817 float number = rnd.getFloat();
7818 spec.inputs.push_back(createCompositeBuffer<float>(number));
7819 spec.outputs.push_back(createCompositeBuffer<float>(number));
7825 spec.numWorkGroups = IVec3(1, 1, 1);
7826 subGroup->addChild(new SpvAsmComputeShaderCase(testCtx, test->at("name").c_str(), "OpInBoundsAccessChain test", spec));
7828 group->addChild(subGroup.release());
7830 return group.release();
7833 // If the params missing, uninitialized case
7834 const string specializeDefaultOutputShaderTemplate (const NumberType type, const map<string, string>& params = map<string, string>())
7836 map<string, string> parameters(params);
7838 parameters["typeDeclaration"] = getAssemblyTypeDeclaration(type);
7840 // Declare the const value, and use it in the initializer
7841 if (params.find("constValue") != params.end())
7843 parameters["constDeclaration"] = "%const = OpConstant %in_type " + params.at("constValue") + "\n";
7844 parameters["variableInitializer"] = "%const";
7846 // Uninitialized case
7849 parameters["constDeclaration"] = "";
7850 parameters["variableInitializer"] = "";
7853 return StringTemplate(
7854 "OpCapability Shader\n"
7855 "OpMemoryModel Logical GLSL450\n"
7856 "OpEntryPoint GLCompute %main \"main\" %id\n"
7857 "OpExecutionMode %main LocalSize 1 1 1\n"
7858 "OpSource GLSL 430\n"
7859 "OpName %main \"main\"\n"
7860 "OpName %id \"gl_GlobalInvocationID\"\n"
7862 "OpDecorate %id BuiltIn GlobalInvocationId\n"
7863 "OpDecorate %indata DescriptorSet 0\n"
7864 "OpDecorate %indata Binding 0\n"
7865 "OpDecorate %outdata DescriptorSet 0\n"
7866 "OpDecorate %outdata Binding 1\n"
7867 "OpDecorate %in_arr ArrayStride 4\n"
7868 "OpDecorate %in_buf BufferBlock\n"
7869 "OpMemberDecorate %in_buf 0 Offset 0\n"
7871 "%void = OpTypeVoid\n"
7872 "%voidf = OpTypeFunction %void\n"
7873 "%u32 = OpTypeInt 32 0\n"
7874 "%i32 = OpTypeInt 32 1\n"
7875 "%uvec3 = OpTypeVector %u32 3\n"
7876 "%uvec3ptr = OpTypePointer Input %uvec3\n"
7878 "%in_type = ${typeDeclaration}\n"
7879 // "%const = OpConstant %in_type ${constValue}\n"
7880 "${constDeclaration}\n"
7882 "%in_ptr = OpTypePointer Uniform %in_type\n"
7883 "%in_arr = OpTypeRuntimeArray %in_type\n"
7884 "%in_buf = OpTypeStruct %in_arr\n"
7885 "%in_bufptr = OpTypePointer Uniform %in_buf\n"
7886 "%indata = OpVariable %in_bufptr Uniform\n"
7887 "%outdata = OpVariable %in_bufptr Uniform\n"
7888 "%id = OpVariable %uvec3ptr Input\n"
7889 "%var_ptr = OpTypePointer Function %in_type\n"
7891 "%zero = OpConstant %i32 0\n"
7893 "%main = OpFunction %void None %voidf\n"
7894 "%label = OpLabel\n"
7895 "%out_var = OpVariable %var_ptr Function ${variableInitializer}\n"
7896 "%idval = OpLoad %uvec3 %id\n"
7897 "%x = OpCompositeExtract %u32 %idval 0\n"
7898 "%inloc = OpAccessChain %in_ptr %indata %zero %x\n"
7899 "%outloc = OpAccessChain %in_ptr %outdata %zero %x\n"
7901 "%outval = OpLoad %in_type %out_var\n"
7902 " OpStore %outloc %outval\n"
7905 ).specialize(parameters);
7908 bool compareFloats (const std::vector<BufferSp>&, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs, TestLog& log)
7910 DE_ASSERT(outputAllocs.size() != 0);
7911 DE_ASSERT(outputAllocs.size() == expectedOutputs.size());
7913 // Use custom epsilon because of the float->string conversion
7914 const float epsilon = 0.00001f;
7916 for (size_t outputNdx = 0; outputNdx < outputAllocs.size(); ++outputNdx)
7918 vector<deUint8> expectedBytes;
7922 expectedOutputs[outputNdx]->getBytes(expectedBytes);
7923 memcpy(&expected, &expectedBytes.front(), expectedBytes.size());
7924 memcpy(&actual, outputAllocs[outputNdx]->getHostPtr(), expectedBytes.size());
7926 // Test with epsilon
7927 if (fabs(expected - actual) > epsilon)
7929 log << TestLog::Message << "Error: The actual and expected values not matching."
7930 << " Expected: " << expected << " Actual: " << actual << " Epsilon: " << epsilon << TestLog::EndMessage;
7937 // Checks if the driver crash with uninitialized cases
7938 bool passthruVerify (const std::vector<BufferSp>&, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs, TestLog&)
7940 DE_ASSERT(outputAllocs.size() != 0);
7941 DE_ASSERT(outputAllocs.size() == expectedOutputs.size());
7943 // Copy and discard the result.
7944 for (size_t outputNdx = 0; outputNdx < outputAllocs.size(); ++outputNdx)
7946 vector<deUint8> expectedBytes;
7947 expectedOutputs[outputNdx]->getBytes(expectedBytes);
7949 const size_t width = expectedBytes.size();
7950 vector<char> data (width);
7952 memcpy(&data[0], outputAllocs[outputNdx]->getHostPtr(), width);
7957 tcu::TestCaseGroup* createShaderDefaultOutputGroup (tcu::TestContext& testCtx)
7959 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "shader_default_output", "Test shader default output."));
7960 de::Random rnd (deStringHash(group->getName()));
7962 for (int type = NUMBERTYPE_INT32; type != NUMBERTYPE_END32; ++type)
7964 NumberType numberType = NumberType(type);
7965 const string typeName = getNumberTypeName(numberType);
7966 const string description = "Test the OpVariable initializer with " + typeName + ".";
7967 de::MovePtr<tcu::TestCaseGroup> subGroup (new tcu::TestCaseGroup(testCtx, typeName.c_str(), description.c_str()));
7969 // 2 similar subcases (initialized and uninitialized)
7970 for (int subCase = 0; subCase < 2; ++subCase)
7972 ComputeShaderSpec spec;
7973 spec.numWorkGroups = IVec3(1, 1, 1);
7975 map<string, string> params;
7979 case NUMBERTYPE_INT32:
7981 deInt32 number = getInt(rnd);
7982 spec.inputs.push_back(createCompositeBuffer<deInt32>(number));
7983 spec.outputs.push_back(createCompositeBuffer<deInt32>(number));
7984 params["constValue"] = numberToString(number);
7987 case NUMBERTYPE_UINT32:
7989 deUint32 number = rnd.getUint32();
7990 spec.inputs.push_back(createCompositeBuffer<deUint32>(number));
7991 spec.outputs.push_back(createCompositeBuffer<deUint32>(number));
7992 params["constValue"] = numberToString(number);
7995 case NUMBERTYPE_FLOAT32:
7997 float number = rnd.getFloat();
7998 spec.inputs.push_back(createCompositeBuffer<float>(number));
7999 spec.outputs.push_back(createCompositeBuffer<float>(number));
8000 spec.verifyIO = &compareFloats;
8001 params["constValue"] = numberToString(number);
8008 // Initialized subcase
8011 spec.assembly = specializeDefaultOutputShaderTemplate(numberType, params);
8012 subGroup->addChild(new SpvAsmComputeShaderCase(testCtx, "initialized", "OpVariable initializer tests.", spec));
8014 // Uninitialized subcase
8017 spec.assembly = specializeDefaultOutputShaderTemplate(numberType);
8018 spec.verifyIO = &passthruVerify;
8019 subGroup->addChild(new SpvAsmComputeShaderCase(testCtx, "uninitialized", "OpVariable initializer tests.", spec));
8022 group->addChild(subGroup.release());
8024 return group.release();
8027 tcu::TestCaseGroup* createOpNopTests (tcu::TestContext& testCtx)
8029 de::MovePtr<tcu::TestCaseGroup> testGroup (new tcu::TestCaseGroup(testCtx, "opnop", "Test OpNop"));
8030 RGBA defaultColors[4];
8031 map<string, string> opNopFragments;
8033 getDefaultColors(defaultColors);
8035 opNopFragments["testfun"] =
8036 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
8037 "%param1 = OpFunctionParameter %v4f32\n"
8038 "%label_testfun = OpLabel\n"
8047 "%a = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
8048 "%b = OpFAdd %f32 %a %a\n"
8050 "%c = OpFSub %f32 %b %a\n"
8051 "%ret = OpVectorInsertDynamic %v4f32 %param1 %c %c_i32_0\n"
8054 "OpReturnValue %ret\n"
8057 createTestsForAllStages("opnop", defaultColors, defaultColors, opNopFragments, testGroup.get());
8059 return testGroup.release();
8062 tcu::TestCaseGroup* createInstructionTests (tcu::TestContext& testCtx)
8064 const bool testComputePipeline = true;
8066 de::MovePtr<tcu::TestCaseGroup> instructionTests (new tcu::TestCaseGroup(testCtx, "instruction", "Instructions with special opcodes/operands"));
8067 de::MovePtr<tcu::TestCaseGroup> computeTests (new tcu::TestCaseGroup(testCtx, "compute", "Compute Instructions with special opcodes/operands"));
8068 de::MovePtr<tcu::TestCaseGroup> graphicsTests (new tcu::TestCaseGroup(testCtx, "graphics", "Graphics Instructions with special opcodes/operands"));
8070 computeTests->addChild(createSpivVersionCheckTests(testCtx, testComputePipeline));
8071 computeTests->addChild(createOpNopGroup(testCtx));
8072 computeTests->addChild(createOpFUnordGroup(testCtx));
8073 computeTests->addChild(createOpAtomicGroup(testCtx, false));
8074 computeTests->addChild(createOpAtomicGroup(testCtx, true)); // Using new StorageBuffer decoration
8075 computeTests->addChild(createOpLineGroup(testCtx));
8076 computeTests->addChild(createOpModuleProcessedGroup(testCtx));
8077 computeTests->addChild(createOpNoLineGroup(testCtx));
8078 computeTests->addChild(createOpConstantNullGroup(testCtx));
8079 computeTests->addChild(createOpConstantCompositeGroup(testCtx));
8080 computeTests->addChild(createOpConstantUsageGroup(testCtx));
8081 computeTests->addChild(createSpecConstantGroup(testCtx));
8082 computeTests->addChild(createOpSourceGroup(testCtx));
8083 computeTests->addChild(createOpSourceExtensionGroup(testCtx));
8084 computeTests->addChild(createDecorationGroupGroup(testCtx));
8085 computeTests->addChild(createOpPhiGroup(testCtx));
8086 computeTests->addChild(createLoopControlGroup(testCtx));
8087 computeTests->addChild(createFunctionControlGroup(testCtx));
8088 computeTests->addChild(createSelectionControlGroup(testCtx));
8089 computeTests->addChild(createBlockOrderGroup(testCtx));
8090 computeTests->addChild(createMultipleShaderGroup(testCtx));
8091 computeTests->addChild(createMemoryAccessGroup(testCtx));
8092 computeTests->addChild(createOpCopyMemoryGroup(testCtx));
8093 computeTests->addChild(createOpCopyObjectGroup(testCtx));
8094 computeTests->addChild(createNoContractionGroup(testCtx));
8095 computeTests->addChild(createOpUndefGroup(testCtx));
8096 computeTests->addChild(createOpUnreachableGroup(testCtx));
8097 computeTests ->addChild(createOpQuantizeToF16Group(testCtx));
8098 computeTests ->addChild(createOpFRemGroup(testCtx));
8099 computeTests->addChild(createOpSRemComputeGroup(testCtx, QP_TEST_RESULT_PASS));
8100 computeTests->addChild(createOpSRemComputeGroup64(testCtx, QP_TEST_RESULT_PASS));
8101 computeTests->addChild(createOpSModComputeGroup(testCtx, QP_TEST_RESULT_PASS));
8102 computeTests->addChild(createOpSModComputeGroup64(testCtx, QP_TEST_RESULT_PASS));
8103 computeTests->addChild(createSConvertTests(testCtx));
8104 computeTests->addChild(createUConvertTests(testCtx));
8105 computeTests->addChild(createOpCompositeInsertGroup(testCtx));
8106 computeTests->addChild(createOpInBoundsAccessChainGroup(testCtx));
8107 computeTests->addChild(createShaderDefaultOutputGroup(testCtx));
8108 computeTests->addChild(createOpNMinGroup(testCtx));
8109 computeTests->addChild(createOpNMaxGroup(testCtx));
8110 computeTests->addChild(createOpNClampGroup(testCtx));
8112 de::MovePtr<tcu::TestCaseGroup> computeAndroidTests (new tcu::TestCaseGroup(testCtx, "android", "Android CTS Tests"));
8114 computeAndroidTests->addChild(createOpSRemComputeGroup(testCtx, QP_TEST_RESULT_QUALITY_WARNING));
8115 computeAndroidTests->addChild(createOpSModComputeGroup(testCtx, QP_TEST_RESULT_QUALITY_WARNING));
8117 computeTests->addChild(computeAndroidTests.release());
8120 computeTests->addChild(create16BitStorageComputeGroup(testCtx));
8121 computeTests->addChild(createUboMatrixPaddingComputeGroup(testCtx));
8122 computeTests->addChild(createConditionalBranchComputeGroup(testCtx));
8123 computeTests->addChild(createIndexingComputeGroup(testCtx));
8124 computeTests->addChild(createVariablePointersComputeGroup(testCtx));
8125 graphicsTests->addChild(createSpivVersionCheckTests(testCtx, !testComputePipeline));
8126 graphicsTests->addChild(createOpNopTests(testCtx));
8127 graphicsTests->addChild(createOpSourceTests(testCtx));
8128 graphicsTests->addChild(createOpSourceContinuedTests(testCtx));
8129 graphicsTests->addChild(createOpModuleProcessedTests(testCtx));
8130 graphicsTests->addChild(createOpLineTests(testCtx));
8131 graphicsTests->addChild(createOpNoLineTests(testCtx));
8132 graphicsTests->addChild(createOpConstantNullTests(testCtx));
8133 graphicsTests->addChild(createOpConstantCompositeTests(testCtx));
8134 graphicsTests->addChild(createMemoryAccessTests(testCtx));
8135 graphicsTests->addChild(createOpUndefTests(testCtx));
8136 graphicsTests->addChild(createSelectionBlockOrderTests(testCtx));
8137 graphicsTests->addChild(createModuleTests(testCtx));
8138 graphicsTests->addChild(createSwitchBlockOrderTests(testCtx));
8139 graphicsTests->addChild(createOpPhiTests(testCtx));
8140 graphicsTests->addChild(createNoContractionTests(testCtx));
8141 graphicsTests->addChild(createOpQuantizeTests(testCtx));
8142 graphicsTests->addChild(createLoopTests(testCtx));
8143 graphicsTests->addChild(createSpecConstantTests(testCtx));
8144 graphicsTests->addChild(createSpecConstantOpQuantizeToF16Group(testCtx));
8145 graphicsTests->addChild(createBarrierTests(testCtx));
8146 graphicsTests->addChild(createDecorationGroupTests(testCtx));
8147 graphicsTests->addChild(createFRemTests(testCtx));
8148 graphicsTests->addChild(createOpSRemGraphicsTests(testCtx, QP_TEST_RESULT_PASS));
8149 graphicsTests->addChild(createOpSModGraphicsTests(testCtx, QP_TEST_RESULT_PASS));
8152 de::MovePtr<tcu::TestCaseGroup> graphicsAndroidTests (new tcu::TestCaseGroup(testCtx, "android", "Android CTS Tests"));
8154 graphicsAndroidTests->addChild(createOpSRemGraphicsTests(testCtx, QP_TEST_RESULT_QUALITY_WARNING));
8155 graphicsAndroidTests->addChild(createOpSModGraphicsTests(testCtx, QP_TEST_RESULT_QUALITY_WARNING));
8157 graphicsTests->addChild(graphicsAndroidTests.release());
8160 graphicsTests->addChild(create16BitStorageGraphicsGroup(testCtx));
8161 graphicsTests->addChild(createUboMatrixPaddingGraphicsGroup(testCtx));
8162 graphicsTests->addChild(createConditionalBranchGraphicsGroup(testCtx));
8163 graphicsTests->addChild(createIndexingGraphicsGroup(testCtx));
8164 graphicsTests->addChild(createVariablePointersGraphicsGroup(testCtx));
8166 instructionTests->addChild(computeTests.release());
8167 instructionTests->addChild(graphicsTests.release());
8169 return instructionTests.release();