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 "vktSpvAsmImageSamplerTests.hpp"
57 #include "vktSpvAsmComputeShaderCase.hpp"
58 #include "vktSpvAsmComputeShaderTestUtil.hpp"
59 #include "vktSpvAsmGraphicsShaderTestUtil.hpp"
60 #include "vktSpvAsmVariablePointersTests.hpp"
61 #include "vktTestCaseUtil.hpp"
73 namespace SpirVAssembly
87 using tcu::TestStatus;
90 using tcu::StringTemplate;
94 static void fillRandomScalars (de::Random& rnd, T minValue, T maxValue, void* dst, int numValues, int offset = 0)
96 T* const typedPtr = (T*)dst;
97 for (int ndx = 0; ndx < numValues; ndx++)
98 typedPtr[offset + ndx] = randomScalar<T>(rnd, minValue, maxValue);
101 // Filter is a function that returns true if a value should pass, false otherwise.
102 template<typename T, typename FilterT>
103 static void fillRandomScalars (de::Random& rnd, T minValue, T maxValue, void* dst, int numValues, FilterT filter, int offset = 0)
105 T* const typedPtr = (T*)dst;
107 for (int ndx = 0; ndx < numValues; ndx++)
110 value = randomScalar<T>(rnd, minValue, maxValue);
111 while (!filter(value));
113 typedPtr[offset + ndx] = value;
117 // Gets a 64-bit integer with a more logarithmic distribution
118 deInt64 randomInt64LogDistributed (de::Random& rnd)
120 deInt64 val = rnd.getUint64();
121 val &= (1ull << rnd.getInt(1, 63)) - 1;
127 static void fillRandomInt64sLogDistributed (de::Random& rnd, vector<deInt64>& dst, int numValues)
129 for (int ndx = 0; ndx < numValues; ndx++)
130 dst[ndx] = randomInt64LogDistributed(rnd);
133 template<typename FilterT>
134 static void fillRandomInt64sLogDistributed (de::Random& rnd, vector<deInt64>& dst, int numValues, FilterT filter)
136 for (int ndx = 0; ndx < numValues; ndx++)
140 value = randomInt64LogDistributed(rnd);
141 } while (!filter(value));
146 inline bool filterNonNegative (const deInt64 value)
151 inline bool filterPositive (const deInt64 value)
156 inline bool filterNotZero (const deInt64 value)
161 static void floorAll (vector<float>& values)
163 for (size_t i = 0; i < values.size(); i++)
164 values[i] = deFloatFloor(values[i]);
167 static void floorAll (vector<Vec4>& values)
169 for (size_t i = 0; i < values.size(); i++)
170 values[i] = floor(values[i]);
178 CaseParameter (const char* case_, const string& param_) : name(case_), param(param_) {}
181 // Assembly code used for testing OpNop, OpConstant{Null|Composite}, Op[No]Line, OpSource[Continued], OpSourceExtension, OpUndef is based on GLSL source code:
185 // layout(std140, set = 0, binding = 0) readonly buffer Input {
188 // layout(std140, set = 0, binding = 1) writeonly buffer Output {
192 // layout (local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
195 // uint x = gl_GlobalInvocationID.x;
196 // output_data.elements[x] = -input_data.elements[x];
200 static string getAsmForOpNopTest(bool useLiteralLocalSize, bool useSpecConstantWorkgroupSize) {
201 std::ostringstream out;
202 out << getComputeAsmShaderPreambleWithoutLocalSize();
203 if (useLiteralLocalSize) {
204 out << "OpExecutionMode %main LocalSize 1 1 1\n";
207 out << "OpSource GLSL 430\n"
208 "OpName %main \"main\"\n"
209 "OpName %id \"gl_GlobalInvocationID\"\n"
210 "OpDecorate %id BuiltIn GlobalInvocationId\n";
212 if (useSpecConstantWorkgroupSize) {
213 out << "OpDecorate %spec_0 SpecId 100\n"
214 "OpDecorate %spec_0 SpecId 100\n"
215 "OpDecorate %spec_1 SpecId 101\n"
216 "OpDecorate %spec_2 SpecId 102\n"
217 "OpDecorate %gl_WorkGroupSize BuiltIn WorkgroupSize\n";
220 out << getComputeAsmInputOutputBufferTraits()
221 << getComputeAsmCommonTypes()
222 << getComputeAsmInputOutputBuffer()
223 << "%id = OpVariable %uvec3ptr Input\n"
224 << "%zero = OpConstant %i32 0\n";
226 if (useSpecConstantWorkgroupSize) {
227 out << "%spec_0 = OpSpecConstant %u32 1\n"
228 "%spec_1 = OpSpecConstant %u32 1\n"
229 "%spec_2 = OpSpecConstant %u32 1\n"
230 "%gl_WorkGroupSize = OpSpecConstantComposite %uvec3 %spec_0 %spec_1 %spec_2\n";
233 out << "%main = OpFunction %void None %voidf\n"
235 "%idval = OpLoad %uvec3 %id\n"
236 "%x = OpCompositeExtract %u32 %idval 0\n"
238 " OpNop\n" // Inside a function body
240 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
241 "%inval = OpLoad %f32 %inloc\n"
242 "%neg = OpFNegate %f32 %inval\n"
243 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
244 " OpStore %outloc %neg\n"
250 tcu::TestCaseGroup* createOpNopGroup (tcu::TestContext& testCtx)
252 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opnop", "Test the OpNop instruction"));
253 ComputeShaderSpec spec;
254 de::Random rnd (deStringHash(group->getName()));
255 const int numElements = 100;
256 vector<float> positiveFloats (numElements, 0);
257 vector<float> negativeFloats (numElements, 0);
259 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
261 for (size_t ndx = 0; ndx < numElements; ++ndx)
262 negativeFloats[ndx] = -positiveFloats[ndx];
264 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
265 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
266 spec.numWorkGroups = IVec3(numElements, 1, 1);
268 spec.assembly = getAsmForOpNopTest(true, false);
269 group->addChild(new SpvAsmComputeShaderCase(testCtx, "literal_localsize", "OpNop appearing at different places", spec));
271 spec.assembly = getAsmForOpNopTest(true, true);
272 group->addChild(new SpvAsmComputeShaderCase(testCtx, "literal_and_specid_localsize", "OpNop appearing at different places", spec));
274 spec.assembly = getAsmForOpNopTest(false, true);
275 group->addChild(new SpvAsmComputeShaderCase(testCtx, "specid_localsize", "OpNop appearing at different places", spec));
277 return group.release();
280 bool compareFUnord (const std::vector<BufferSp>& inputs, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs, TestLog& log)
282 if (outputAllocs.size() != 1)
285 vector<deUint8> input1Bytes;
286 vector<deUint8> input2Bytes;
287 vector<deUint8> expectedBytes;
289 inputs[0]->getBytes(input1Bytes);
290 inputs[1]->getBytes(input2Bytes);
291 expectedOutputs[0]->getBytes(expectedBytes);
293 const deInt32* const expectedOutputAsInt = reinterpret_cast<const deInt32* const>(&expectedBytes.front());
294 const deInt32* const outputAsInt = static_cast<const deInt32* const>(outputAllocs[0]->getHostPtr());
295 const float* const input1AsFloat = reinterpret_cast<const float* const>(&input1Bytes.front());
296 const float* const input2AsFloat = reinterpret_cast<const float* const>(&input2Bytes.front());
297 bool returnValue = true;
299 for (size_t idx = 0; idx < expectedBytes.size() / sizeof(deInt32); ++idx)
301 if (outputAsInt[idx] != expectedOutputAsInt[idx])
303 log << TestLog::Message << "ERROR: Sub-case failed. inputs: " << input1AsFloat[idx] << "," << input2AsFloat[idx] << " output: " << outputAsInt[idx]<< " expected output: " << expectedOutputAsInt[idx] << TestLog::EndMessage;
310 typedef VkBool32 (*compareFuncType) (float, float);
316 compareFuncType compareFunc;
318 OpFUnordCase (const char* _name, const char* _opCode, compareFuncType _compareFunc)
321 , compareFunc (_compareFunc) {}
324 #define ADD_OPFUNORD_CASE(NAME, OPCODE, OPERATOR) \
326 struct compare_##NAME { static VkBool32 compare(float x, float y) { return (x OPERATOR y) ? VK_TRUE : VK_FALSE; } }; \
327 cases.push_back(OpFUnordCase(#NAME, OPCODE, compare_##NAME::compare)); \
328 } while (deGetFalse())
330 tcu::TestCaseGroup* createOpFUnordGroup (tcu::TestContext& testCtx)
332 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opfunord", "Test the OpFUnord* opcodes"));
333 de::Random rnd (deStringHash(group->getName()));
334 const int numElements = 100;
335 vector<OpFUnordCase> cases;
337 const StringTemplate shaderTemplate (
339 string(getComputeAsmShaderPreamble()) +
341 "OpSource GLSL 430\n"
342 "OpName %main \"main\"\n"
343 "OpName %id \"gl_GlobalInvocationID\"\n"
345 "OpDecorate %id BuiltIn GlobalInvocationId\n"
347 "OpDecorate %buf BufferBlock\n"
348 "OpDecorate %buf2 BufferBlock\n"
349 "OpDecorate %indata1 DescriptorSet 0\n"
350 "OpDecorate %indata1 Binding 0\n"
351 "OpDecorate %indata2 DescriptorSet 0\n"
352 "OpDecorate %indata2 Binding 1\n"
353 "OpDecorate %outdata DescriptorSet 0\n"
354 "OpDecorate %outdata Binding 2\n"
355 "OpDecorate %f32arr ArrayStride 4\n"
356 "OpDecorate %i32arr ArrayStride 4\n"
357 "OpMemberDecorate %buf 0 Offset 0\n"
358 "OpMemberDecorate %buf2 0 Offset 0\n"
360 + string(getComputeAsmCommonTypes()) +
362 "%buf = OpTypeStruct %f32arr\n"
363 "%bufptr = OpTypePointer Uniform %buf\n"
364 "%indata1 = OpVariable %bufptr Uniform\n"
365 "%indata2 = OpVariable %bufptr Uniform\n"
367 "%buf2 = OpTypeStruct %i32arr\n"
368 "%buf2ptr = OpTypePointer Uniform %buf2\n"
369 "%outdata = OpVariable %buf2ptr Uniform\n"
371 "%id = OpVariable %uvec3ptr Input\n"
372 "%zero = OpConstant %i32 0\n"
373 "%consti1 = OpConstant %i32 1\n"
374 "%constf1 = OpConstant %f32 1.0\n"
376 "%main = OpFunction %void None %voidf\n"
378 "%idval = OpLoad %uvec3 %id\n"
379 "%x = OpCompositeExtract %u32 %idval 0\n"
381 "%inloc1 = OpAccessChain %f32ptr %indata1 %zero %x\n"
382 "%inval1 = OpLoad %f32 %inloc1\n"
383 "%inloc2 = OpAccessChain %f32ptr %indata2 %zero %x\n"
384 "%inval2 = OpLoad %f32 %inloc2\n"
385 "%outloc = OpAccessChain %i32ptr %outdata %zero %x\n"
387 "%result = ${OPCODE} %bool %inval1 %inval2\n"
388 "%int_res = OpSelect %i32 %result %consti1 %zero\n"
389 " OpStore %outloc %int_res\n"
394 ADD_OPFUNORD_CASE(equal, "OpFUnordEqual", ==);
395 ADD_OPFUNORD_CASE(less, "OpFUnordLessThan", <);
396 ADD_OPFUNORD_CASE(lessequal, "OpFUnordLessThanEqual", <=);
397 ADD_OPFUNORD_CASE(greater, "OpFUnordGreaterThan", >);
398 ADD_OPFUNORD_CASE(greaterequal, "OpFUnordGreaterThanEqual", >=);
399 ADD_OPFUNORD_CASE(notequal, "OpFUnordNotEqual", !=);
401 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
403 map<string, string> specializations;
404 ComputeShaderSpec spec;
405 const float NaN = std::numeric_limits<float>::quiet_NaN();
406 vector<float> inputFloats1 (numElements, 0);
407 vector<float> inputFloats2 (numElements, 0);
408 vector<deInt32> expectedInts (numElements, 0);
410 specializations["OPCODE"] = cases[caseNdx].opCode;
411 spec.assembly = shaderTemplate.specialize(specializations);
413 fillRandomScalars(rnd, 1.f, 100.f, &inputFloats1[0], numElements);
414 for (size_t ndx = 0; ndx < numElements; ++ndx)
418 case 0: inputFloats2[ndx] = inputFloats1[ndx] + 1.0f; break;
419 case 1: inputFloats2[ndx] = inputFloats1[ndx] - 1.0f; break;
420 case 2: inputFloats2[ndx] = inputFloats1[ndx]; break;
421 case 3: inputFloats2[ndx] = NaN; break;
422 case 4: inputFloats2[ndx] = inputFloats1[ndx]; inputFloats1[ndx] = NaN; break;
423 case 5: inputFloats2[ndx] = NaN; inputFloats1[ndx] = NaN; break;
425 expectedInts[ndx] = tcu::Float32(inputFloats1[ndx]).isNaN() || tcu::Float32(inputFloats2[ndx]).isNaN() || cases[caseNdx].compareFunc(inputFloats1[ndx], inputFloats2[ndx]);
428 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats1)));
429 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
430 spec.outputs.push_back(BufferSp(new Int32Buffer(expectedInts)));
431 spec.numWorkGroups = IVec3(numElements, 1, 1);
432 spec.verifyIO = &compareFUnord;
433 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
436 return group.release();
442 const char* assembly;
443 OpAtomicType opAtomic;
444 deInt32 numOutputElements;
446 OpAtomicCase (const char* _name, const char* _assembly, OpAtomicType _opAtomic, deInt32 _numOutputElements)
448 , assembly (_assembly)
449 , opAtomic (_opAtomic)
450 , numOutputElements (_numOutputElements) {}
453 tcu::TestCaseGroup* createOpAtomicGroup (tcu::TestContext& testCtx, bool useStorageBuffer)
455 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx,
456 useStorageBuffer ? "opatomic_storage_buffer" : "opatomic",
457 "Test the OpAtomic* opcodes"));
458 const int numElements = 65535;
459 vector<OpAtomicCase> cases;
461 const StringTemplate shaderTemplate (
463 string("OpCapability Shader\n") +
464 (useStorageBuffer ? "OpExtension \"SPV_KHR_storage_buffer_storage_class\"\n" : "") +
465 "OpMemoryModel Logical GLSL450\n"
466 "OpEntryPoint GLCompute %main \"main\" %id\n"
467 "OpExecutionMode %main LocalSize 1 1 1\n" +
469 "OpSource GLSL 430\n"
470 "OpName %main \"main\"\n"
471 "OpName %id \"gl_GlobalInvocationID\"\n"
473 "OpDecorate %id BuiltIn GlobalInvocationId\n"
475 "OpDecorate %buf ${BLOCK_DECORATION}\n"
476 "OpDecorate %indata DescriptorSet 0\n"
477 "OpDecorate %indata Binding 0\n"
478 "OpDecorate %i32arr ArrayStride 4\n"
479 "OpMemberDecorate %buf 0 Offset 0\n"
481 "OpDecorate %sumbuf ${BLOCK_DECORATION}\n"
482 "OpDecorate %sum DescriptorSet 0\n"
483 "OpDecorate %sum Binding 1\n"
484 "OpMemberDecorate %sumbuf 0 Coherent\n"
485 "OpMemberDecorate %sumbuf 0 Offset 0\n"
487 + getComputeAsmCommonTypes("${BLOCK_POINTER_TYPE}") +
489 "%buf = OpTypeStruct %i32arr\n"
490 "%bufptr = OpTypePointer ${BLOCK_POINTER_TYPE} %buf\n"
491 "%indata = OpVariable %bufptr ${BLOCK_POINTER_TYPE}\n"
493 "%sumbuf = OpTypeStruct %i32arr\n"
494 "%sumbufptr = OpTypePointer ${BLOCK_POINTER_TYPE} %sumbuf\n"
495 "%sum = OpVariable %sumbufptr ${BLOCK_POINTER_TYPE}\n"
497 "%id = OpVariable %uvec3ptr Input\n"
498 "%minusone = OpConstant %i32 -1\n"
499 "%zero = OpConstant %i32 0\n"
500 "%one = OpConstant %u32 1\n"
501 "%two = OpConstant %i32 2\n"
503 "%main = OpFunction %void None %voidf\n"
505 "%idval = OpLoad %uvec3 %id\n"
506 "%x = OpCompositeExtract %u32 %idval 0\n"
508 "%inloc = OpAccessChain %i32ptr %indata %zero %x\n"
509 "%inval = OpLoad %i32 %inloc\n"
511 "%outloc = OpAccessChain %i32ptr %sum %zero ${INDEX}\n"
517 #define ADD_OPATOMIC_CASE(NAME, ASSEMBLY, OPATOMIC, NUM_OUTPUT_ELEMENTS) \
519 DE_STATIC_ASSERT((NUM_OUTPUT_ELEMENTS) == 1 || (NUM_OUTPUT_ELEMENTS) == numElements); \
520 cases.push_back(OpAtomicCase(#NAME, ASSEMBLY, OPATOMIC, NUM_OUTPUT_ELEMENTS)); \
521 } while (deGetFalse())
522 #define ADD_OPATOMIC_CASE_1(NAME, ASSEMBLY, OPATOMIC) ADD_OPATOMIC_CASE(NAME, ASSEMBLY, OPATOMIC, 1)
523 #define ADD_OPATOMIC_CASE_N(NAME, ASSEMBLY, OPATOMIC) ADD_OPATOMIC_CASE(NAME, ASSEMBLY, OPATOMIC, numElements)
525 ADD_OPATOMIC_CASE_1(iadd, "%unused = OpAtomicIAdd %i32 %outloc %one %zero %inval\n", OPATOMIC_IADD );
526 ADD_OPATOMIC_CASE_1(isub, "%unused = OpAtomicISub %i32 %outloc %one %zero %inval\n", OPATOMIC_ISUB );
527 ADD_OPATOMIC_CASE_1(iinc, "%unused = OpAtomicIIncrement %i32 %outloc %one %zero\n", OPATOMIC_IINC );
528 ADD_OPATOMIC_CASE_1(idec, "%unused = OpAtomicIDecrement %i32 %outloc %one %zero\n", OPATOMIC_IDEC );
529 ADD_OPATOMIC_CASE_N(load, "%inval2 = OpAtomicLoad %i32 %inloc %zero %zero\n"
530 " OpStore %outloc %inval2\n", OPATOMIC_LOAD );
531 ADD_OPATOMIC_CASE_N(store, " OpAtomicStore %outloc %zero %zero %inval\n", OPATOMIC_STORE );
532 ADD_OPATOMIC_CASE_N(compex, "%even = OpSMod %i32 %inval %two\n"
533 " OpStore %outloc %even\n"
534 "%unused = OpAtomicCompareExchange %i32 %outloc %one %zero %zero %minusone %zero\n", OPATOMIC_COMPEX );
536 #undef ADD_OPATOMIC_CASE
537 #undef ADD_OPATOMIC_CASE_1
538 #undef ADD_OPATOMIC_CASE_N
540 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
542 map<string, string> specializations;
543 ComputeShaderSpec spec;
544 vector<deInt32> inputInts (numElements, 0);
545 vector<deInt32> expected (cases[caseNdx].numOutputElements, -1);
547 specializations["INDEX"] = (cases[caseNdx].numOutputElements == 1) ? "%zero" : "%x";
548 specializations["INSTRUCTION"] = cases[caseNdx].assembly;
549 specializations["BLOCK_DECORATION"] = useStorageBuffer ? "Block" : "BufferBlock";
550 specializations["BLOCK_POINTER_TYPE"] = useStorageBuffer ? "StorageBuffer" : "Uniform";
551 spec.assembly = shaderTemplate.specialize(specializations);
553 if (useStorageBuffer)
554 spec.extensions.push_back("VK_KHR_storage_buffer_storage_class");
556 spec.inputs.push_back(BufferSp(new OpAtomicBuffer(numElements, cases[caseNdx].numOutputElements, cases[caseNdx].opAtomic, BUFFERTYPE_INPUT)));
557 spec.outputs.push_back(BufferSp(new OpAtomicBuffer(numElements, cases[caseNdx].numOutputElements, cases[caseNdx].opAtomic, BUFFERTYPE_EXPECTED)));
558 spec.numWorkGroups = IVec3(numElements, 1, 1);
559 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
562 return group.release();
565 tcu::TestCaseGroup* createOpLineGroup (tcu::TestContext& testCtx)
567 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opline", "Test the OpLine instruction"));
568 ComputeShaderSpec spec;
569 de::Random rnd (deStringHash(group->getName()));
570 const int numElements = 100;
571 vector<float> positiveFloats (numElements, 0);
572 vector<float> negativeFloats (numElements, 0);
574 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
576 for (size_t ndx = 0; ndx < numElements; ++ndx)
577 negativeFloats[ndx] = -positiveFloats[ndx];
580 string(getComputeAsmShaderPreamble()) +
582 "%fname1 = OpString \"negateInputs.comp\"\n"
583 "%fname2 = OpString \"negateInputs\"\n"
585 "OpSource GLSL 430\n"
586 "OpName %main \"main\"\n"
587 "OpName %id \"gl_GlobalInvocationID\"\n"
589 "OpDecorate %id BuiltIn GlobalInvocationId\n"
591 + string(getComputeAsmInputOutputBufferTraits()) +
593 "OpLine %fname1 0 0\n" // At the earliest possible position
595 + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
597 "OpLine %fname1 0 1\n" // Multiple OpLines in sequence
598 "OpLine %fname2 1 0\n" // Different filenames
599 "OpLine %fname1 1000 100000\n"
601 "%id = OpVariable %uvec3ptr Input\n"
602 "%zero = OpConstant %i32 0\n"
604 "OpLine %fname1 1 1\n" // Before a function
606 "%main = OpFunction %void None %voidf\n"
609 "OpLine %fname1 1 1\n" // In a function
611 "%idval = OpLoad %uvec3 %id\n"
612 "%x = OpCompositeExtract %u32 %idval 0\n"
613 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
614 "%inval = OpLoad %f32 %inloc\n"
615 "%neg = OpFNegate %f32 %inval\n"
616 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
617 " OpStore %outloc %neg\n"
620 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
621 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
622 spec.numWorkGroups = IVec3(numElements, 1, 1);
624 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "OpLine appearing at different places", spec));
626 return group.release();
629 tcu::TestCaseGroup* createOpNoLineGroup (tcu::TestContext& testCtx)
631 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opnoline", "Test the OpNoLine instruction"));
632 ComputeShaderSpec spec;
633 de::Random rnd (deStringHash(group->getName()));
634 const int numElements = 100;
635 vector<float> positiveFloats (numElements, 0);
636 vector<float> negativeFloats (numElements, 0);
638 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
640 for (size_t ndx = 0; ndx < numElements; ++ndx)
641 negativeFloats[ndx] = -positiveFloats[ndx];
644 string(getComputeAsmShaderPreamble()) +
646 "%fname = OpString \"negateInputs.comp\"\n"
648 "OpSource GLSL 430\n"
649 "OpName %main \"main\"\n"
650 "OpName %id \"gl_GlobalInvocationID\"\n"
652 "OpDecorate %id BuiltIn GlobalInvocationId\n"
654 + string(getComputeAsmInputOutputBufferTraits()) +
656 "OpNoLine\n" // At the earliest possible position, without preceding OpLine
658 + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
660 "OpLine %fname 0 1\n"
661 "OpNoLine\n" // Immediately following a preceding OpLine
663 "OpLine %fname 1000 1\n"
665 "%id = OpVariable %uvec3ptr Input\n"
666 "%zero = OpConstant %i32 0\n"
668 "OpNoLine\n" // Contents after the previous OpLine
670 "%main = OpFunction %void None %voidf\n"
672 "%idval = OpLoad %uvec3 %id\n"
673 "%x = OpCompositeExtract %u32 %idval 0\n"
675 "OpNoLine\n" // Multiple OpNoLine
679 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
680 "%inval = OpLoad %f32 %inloc\n"
681 "%neg = OpFNegate %f32 %inval\n"
682 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
683 " OpStore %outloc %neg\n"
686 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
687 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
688 spec.numWorkGroups = IVec3(numElements, 1, 1);
690 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "OpNoLine appearing at different places", spec));
692 return group.release();
695 // Compare instruction for the contraction compute case.
696 // Returns true if the output is what is expected from the test case.
697 bool compareNoContractCase(const std::vector<BufferSp>&, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs, TestLog&)
699 if (outputAllocs.size() != 1)
702 // Only size is needed because we are not comparing the exact values.
703 size_t byteSize = expectedOutputs[0]->getByteSize();
705 const float* outputAsFloat = static_cast<const float*>(outputAllocs[0]->getHostPtr());
707 for(size_t i = 0; i < byteSize / sizeof(float); ++i) {
708 if (outputAsFloat[i] != 0.f &&
709 outputAsFloat[i] != -ldexp(1, -24)) {
717 tcu::TestCaseGroup* createNoContractionGroup (tcu::TestContext& testCtx)
719 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "nocontraction", "Test the NoContraction decoration"));
720 vector<CaseParameter> cases;
721 const int numElements = 100;
722 vector<float> inputFloats1 (numElements, 0);
723 vector<float> inputFloats2 (numElements, 0);
724 vector<float> outputFloats (numElements, 0);
725 const StringTemplate shaderTemplate (
726 string(getComputeAsmShaderPreamble()) +
728 "OpName %main \"main\"\n"
729 "OpName %id \"gl_GlobalInvocationID\"\n"
731 "OpDecorate %id BuiltIn GlobalInvocationId\n"
735 "OpDecorate %buf BufferBlock\n"
736 "OpDecorate %indata1 DescriptorSet 0\n"
737 "OpDecorate %indata1 Binding 0\n"
738 "OpDecorate %indata2 DescriptorSet 0\n"
739 "OpDecorate %indata2 Binding 1\n"
740 "OpDecorate %outdata DescriptorSet 0\n"
741 "OpDecorate %outdata Binding 2\n"
742 "OpDecorate %f32arr ArrayStride 4\n"
743 "OpMemberDecorate %buf 0 Offset 0\n"
745 + string(getComputeAsmCommonTypes()) +
747 "%buf = OpTypeStruct %f32arr\n"
748 "%bufptr = OpTypePointer Uniform %buf\n"
749 "%indata1 = OpVariable %bufptr Uniform\n"
750 "%indata2 = OpVariable %bufptr Uniform\n"
751 "%outdata = OpVariable %bufptr Uniform\n"
753 "%id = OpVariable %uvec3ptr Input\n"
754 "%zero = OpConstant %i32 0\n"
755 "%c_f_m1 = OpConstant %f32 -1.\n"
757 "%main = OpFunction %void None %voidf\n"
759 "%idval = OpLoad %uvec3 %id\n"
760 "%x = OpCompositeExtract %u32 %idval 0\n"
761 "%inloc1 = OpAccessChain %f32ptr %indata1 %zero %x\n"
762 "%inval1 = OpLoad %f32 %inloc1\n"
763 "%inloc2 = OpAccessChain %f32ptr %indata2 %zero %x\n"
764 "%inval2 = OpLoad %f32 %inloc2\n"
765 "%mul = OpFMul %f32 %inval1 %inval2\n"
766 "%add = OpFAdd %f32 %mul %c_f_m1\n"
767 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
768 " OpStore %outloc %add\n"
772 cases.push_back(CaseParameter("multiplication", "OpDecorate %mul NoContraction"));
773 cases.push_back(CaseParameter("addition", "OpDecorate %add NoContraction"));
774 cases.push_back(CaseParameter("both", "OpDecorate %mul NoContraction\nOpDecorate %add NoContraction"));
776 for (size_t ndx = 0; ndx < numElements; ++ndx)
778 inputFloats1[ndx] = 1.f + std::ldexp(1.f, -23); // 1 + 2^-23.
779 inputFloats2[ndx] = 1.f - std::ldexp(1.f, -23); // 1 - 2^-23.
780 // Result for (1 + 2^-23) * (1 - 2^-23) - 1. With NoContraction, the multiplication will be
781 // conducted separately and the result is rounded to 1, or 0x1.fffffcp-1
782 // So the final result will be 0.f or 0x1p-24.
783 // If the operation is combined into a precise fused multiply-add, then the result would be
784 // 2^-46 (0xa8800000).
785 outputFloats[ndx] = 0.f;
788 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
790 map<string, string> specializations;
791 ComputeShaderSpec spec;
793 specializations["DECORATION"] = cases[caseNdx].param;
794 spec.assembly = shaderTemplate.specialize(specializations);
795 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats1)));
796 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
797 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
798 spec.numWorkGroups = IVec3(numElements, 1, 1);
799 // Check against the two possible answers based on rounding mode.
800 spec.verifyIO = &compareNoContractCase;
802 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
804 return group.release();
807 bool compareFRem(const std::vector<BufferSp>&, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs, TestLog&)
809 if (outputAllocs.size() != 1)
812 vector<deUint8> expectedBytes;
813 expectedOutputs[0]->getBytes(expectedBytes);
815 const float* expectedOutputAsFloat = reinterpret_cast<const float*>(&expectedBytes.front());
816 const float* outputAsFloat = static_cast<const float*>(outputAllocs[0]->getHostPtr());
818 for (size_t idx = 0; idx < expectedBytes.size() / sizeof(float); ++idx)
820 const float f0 = expectedOutputAsFloat[idx];
821 const float f1 = outputAsFloat[idx];
822 // \todo relative error needs to be fairly high because FRem may be implemented as
823 // (roughly) frac(a/b)*b, so LSB errors can be magnified. But this should be fine for now.
824 if (deFloatAbs((f1 - f0) / f0) > 0.02)
831 tcu::TestCaseGroup* createOpFRemGroup (tcu::TestContext& testCtx)
833 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opfrem", "Test the OpFRem instruction"));
834 ComputeShaderSpec spec;
835 de::Random rnd (deStringHash(group->getName()));
836 const int numElements = 200;
837 vector<float> inputFloats1 (numElements, 0);
838 vector<float> inputFloats2 (numElements, 0);
839 vector<float> outputFloats (numElements, 0);
841 fillRandomScalars(rnd, -10000.f, 10000.f, &inputFloats1[0], numElements);
842 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats2[0], numElements);
844 for (size_t ndx = 0; ndx < numElements; ++ndx)
846 // Guard against divisors near zero.
847 if (std::fabs(inputFloats2[ndx]) < 1e-3)
848 inputFloats2[ndx] = 8.f;
850 // The return value of std::fmod() has the same sign as its first operand, which is how OpFRem spec'd.
851 outputFloats[ndx] = std::fmod(inputFloats1[ndx], inputFloats2[ndx]);
855 string(getComputeAsmShaderPreamble()) +
857 "OpName %main \"main\"\n"
858 "OpName %id \"gl_GlobalInvocationID\"\n"
860 "OpDecorate %id BuiltIn GlobalInvocationId\n"
862 "OpDecorate %buf BufferBlock\n"
863 "OpDecorate %indata1 DescriptorSet 0\n"
864 "OpDecorate %indata1 Binding 0\n"
865 "OpDecorate %indata2 DescriptorSet 0\n"
866 "OpDecorate %indata2 Binding 1\n"
867 "OpDecorate %outdata DescriptorSet 0\n"
868 "OpDecorate %outdata Binding 2\n"
869 "OpDecorate %f32arr ArrayStride 4\n"
870 "OpMemberDecorate %buf 0 Offset 0\n"
872 + string(getComputeAsmCommonTypes()) +
874 "%buf = OpTypeStruct %f32arr\n"
875 "%bufptr = OpTypePointer Uniform %buf\n"
876 "%indata1 = OpVariable %bufptr Uniform\n"
877 "%indata2 = OpVariable %bufptr Uniform\n"
878 "%outdata = OpVariable %bufptr Uniform\n"
880 "%id = OpVariable %uvec3ptr Input\n"
881 "%zero = OpConstant %i32 0\n"
883 "%main = OpFunction %void None %voidf\n"
885 "%idval = OpLoad %uvec3 %id\n"
886 "%x = OpCompositeExtract %u32 %idval 0\n"
887 "%inloc1 = OpAccessChain %f32ptr %indata1 %zero %x\n"
888 "%inval1 = OpLoad %f32 %inloc1\n"
889 "%inloc2 = OpAccessChain %f32ptr %indata2 %zero %x\n"
890 "%inval2 = OpLoad %f32 %inloc2\n"
891 "%rem = OpFRem %f32 %inval1 %inval2\n"
892 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
893 " OpStore %outloc %rem\n"
897 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats1)));
898 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
899 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
900 spec.numWorkGroups = IVec3(numElements, 1, 1);
901 spec.verifyIO = &compareFRem;
903 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "", spec));
905 return group.release();
908 bool compareNMin (const std::vector<BufferSp>&, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs, TestLog&)
910 if (outputAllocs.size() != 1)
913 const BufferSp& expectedOutput (expectedOutputs[0]);
914 std::vector<deUint8> data;
915 expectedOutput->getBytes(data);
917 const float* const expectedOutputAsFloat = reinterpret_cast<const float*>(&data.front());
918 const float* const outputAsFloat = static_cast<const float*>(outputAllocs[0]->getHostPtr());
920 for (size_t idx = 0; idx < expectedOutput->getByteSize() / sizeof(float); ++idx)
922 const float f0 = expectedOutputAsFloat[idx];
923 const float f1 = outputAsFloat[idx];
925 // For NMin, we accept NaN as output if both inputs were NaN.
926 // Otherwise the NaN is the wrong choise, as on architectures that
927 // do not handle NaN, those are huge values.
928 if (!(tcu::Float32(f1).isNaN() && tcu::Float32(f0).isNaN()) && deFloatAbs(f1 - f0) > 0.00001f)
935 tcu::TestCaseGroup* createOpNMinGroup (tcu::TestContext& testCtx)
937 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opnmin", "Test the OpNMin instruction"));
938 ComputeShaderSpec spec;
939 de::Random rnd (deStringHash(group->getName()));
940 const int numElements = 200;
941 vector<float> inputFloats1 (numElements, 0);
942 vector<float> inputFloats2 (numElements, 0);
943 vector<float> outputFloats (numElements, 0);
945 fillRandomScalars(rnd, -10000.f, 10000.f, &inputFloats1[0], numElements);
946 fillRandomScalars(rnd, -10000.f, 10000.f, &inputFloats2[0], numElements);
948 // Make the first case a full-NAN case.
949 inputFloats1[0] = TCU_NAN;
950 inputFloats2[0] = TCU_NAN;
952 for (size_t ndx = 0; ndx < numElements; ++ndx)
954 // By default, pick the smallest
955 outputFloats[ndx] = std::min(inputFloats1[ndx], inputFloats2[ndx]);
957 // Make half of the cases NaN cases
960 // Alternate between the NaN operand
963 outputFloats[ndx] = inputFloats2[ndx];
964 inputFloats1[ndx] = TCU_NAN;
968 outputFloats[ndx] = inputFloats1[ndx];
969 inputFloats2[ndx] = TCU_NAN;
975 "OpCapability Shader\n"
976 "%std450 = OpExtInstImport \"GLSL.std.450\"\n"
977 "OpMemoryModel Logical GLSL450\n"
978 "OpEntryPoint GLCompute %main \"main\" %id\n"
979 "OpExecutionMode %main LocalSize 1 1 1\n"
981 "OpName %main \"main\"\n"
982 "OpName %id \"gl_GlobalInvocationID\"\n"
984 "OpDecorate %id BuiltIn GlobalInvocationId\n"
986 "OpDecorate %buf BufferBlock\n"
987 "OpDecorate %indata1 DescriptorSet 0\n"
988 "OpDecorate %indata1 Binding 0\n"
989 "OpDecorate %indata2 DescriptorSet 0\n"
990 "OpDecorate %indata2 Binding 1\n"
991 "OpDecorate %outdata DescriptorSet 0\n"
992 "OpDecorate %outdata Binding 2\n"
993 "OpDecorate %f32arr ArrayStride 4\n"
994 "OpMemberDecorate %buf 0 Offset 0\n"
996 + string(getComputeAsmCommonTypes()) +
998 "%buf = OpTypeStruct %f32arr\n"
999 "%bufptr = OpTypePointer Uniform %buf\n"
1000 "%indata1 = OpVariable %bufptr Uniform\n"
1001 "%indata2 = OpVariable %bufptr Uniform\n"
1002 "%outdata = OpVariable %bufptr Uniform\n"
1004 "%id = OpVariable %uvec3ptr Input\n"
1005 "%zero = OpConstant %i32 0\n"
1007 "%main = OpFunction %void None %voidf\n"
1008 "%label = OpLabel\n"
1009 "%idval = OpLoad %uvec3 %id\n"
1010 "%x = OpCompositeExtract %u32 %idval 0\n"
1011 "%inloc1 = OpAccessChain %f32ptr %indata1 %zero %x\n"
1012 "%inval1 = OpLoad %f32 %inloc1\n"
1013 "%inloc2 = OpAccessChain %f32ptr %indata2 %zero %x\n"
1014 "%inval2 = OpLoad %f32 %inloc2\n"
1015 "%rem = OpExtInst %f32 %std450 NMin %inval1 %inval2\n"
1016 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
1017 " OpStore %outloc %rem\n"
1021 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats1)));
1022 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
1023 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
1024 spec.numWorkGroups = IVec3(numElements, 1, 1);
1025 spec.verifyIO = &compareNMin;
1027 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "", spec));
1029 return group.release();
1032 bool compareNMax (const std::vector<BufferSp>&, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs, TestLog&)
1034 if (outputAllocs.size() != 1)
1037 const BufferSp& expectedOutput = expectedOutputs[0];
1038 std::vector<deUint8> data;
1039 expectedOutput->getBytes(data);
1041 const float* const expectedOutputAsFloat = reinterpret_cast<const float*>(&data.front());
1042 const float* const outputAsFloat = static_cast<const float*>(outputAllocs[0]->getHostPtr());
1044 for (size_t idx = 0; idx < expectedOutput->getByteSize() / sizeof(float); ++idx)
1046 const float f0 = expectedOutputAsFloat[idx];
1047 const float f1 = outputAsFloat[idx];
1049 // For NMax, NaN is considered acceptable result, since in
1050 // architectures that do not handle NaNs, those are huge values.
1051 if (!tcu::Float32(f1).isNaN() && deFloatAbs(f1 - f0) > 0.00001f)
1058 tcu::TestCaseGroup* createOpNMaxGroup (tcu::TestContext& testCtx)
1060 de::MovePtr<tcu::TestCaseGroup> group(new tcu::TestCaseGroup(testCtx, "opnmax", "Test the OpNMax instruction"));
1061 ComputeShaderSpec spec;
1062 de::Random rnd (deStringHash(group->getName()));
1063 const int numElements = 200;
1064 vector<float> inputFloats1 (numElements, 0);
1065 vector<float> inputFloats2 (numElements, 0);
1066 vector<float> outputFloats (numElements, 0);
1068 fillRandomScalars(rnd, -10000.f, 10000.f, &inputFloats1[0], numElements);
1069 fillRandomScalars(rnd, -10000.f, 10000.f, &inputFloats2[0], numElements);
1071 // Make the first case a full-NAN case.
1072 inputFloats1[0] = TCU_NAN;
1073 inputFloats2[0] = TCU_NAN;
1075 for (size_t ndx = 0; ndx < numElements; ++ndx)
1077 // By default, pick the biggest
1078 outputFloats[ndx] = std::max(inputFloats1[ndx], inputFloats2[ndx]);
1080 // Make half of the cases NaN cases
1083 // Alternate between the NaN operand
1086 outputFloats[ndx] = inputFloats2[ndx];
1087 inputFloats1[ndx] = TCU_NAN;
1091 outputFloats[ndx] = inputFloats1[ndx];
1092 inputFloats2[ndx] = TCU_NAN;
1098 "OpCapability Shader\n"
1099 "%std450 = OpExtInstImport \"GLSL.std.450\"\n"
1100 "OpMemoryModel Logical GLSL450\n"
1101 "OpEntryPoint GLCompute %main \"main\" %id\n"
1102 "OpExecutionMode %main LocalSize 1 1 1\n"
1104 "OpName %main \"main\"\n"
1105 "OpName %id \"gl_GlobalInvocationID\"\n"
1107 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1109 "OpDecorate %buf BufferBlock\n"
1110 "OpDecorate %indata1 DescriptorSet 0\n"
1111 "OpDecorate %indata1 Binding 0\n"
1112 "OpDecorate %indata2 DescriptorSet 0\n"
1113 "OpDecorate %indata2 Binding 1\n"
1114 "OpDecorate %outdata DescriptorSet 0\n"
1115 "OpDecorate %outdata Binding 2\n"
1116 "OpDecorate %f32arr ArrayStride 4\n"
1117 "OpMemberDecorate %buf 0 Offset 0\n"
1119 + string(getComputeAsmCommonTypes()) +
1121 "%buf = OpTypeStruct %f32arr\n"
1122 "%bufptr = OpTypePointer Uniform %buf\n"
1123 "%indata1 = OpVariable %bufptr Uniform\n"
1124 "%indata2 = OpVariable %bufptr Uniform\n"
1125 "%outdata = OpVariable %bufptr Uniform\n"
1127 "%id = OpVariable %uvec3ptr Input\n"
1128 "%zero = OpConstant %i32 0\n"
1130 "%main = OpFunction %void None %voidf\n"
1131 "%label = OpLabel\n"
1132 "%idval = OpLoad %uvec3 %id\n"
1133 "%x = OpCompositeExtract %u32 %idval 0\n"
1134 "%inloc1 = OpAccessChain %f32ptr %indata1 %zero %x\n"
1135 "%inval1 = OpLoad %f32 %inloc1\n"
1136 "%inloc2 = OpAccessChain %f32ptr %indata2 %zero %x\n"
1137 "%inval2 = OpLoad %f32 %inloc2\n"
1138 "%rem = OpExtInst %f32 %std450 NMax %inval1 %inval2\n"
1139 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
1140 " OpStore %outloc %rem\n"
1144 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats1)));
1145 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
1146 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
1147 spec.numWorkGroups = IVec3(numElements, 1, 1);
1148 spec.verifyIO = &compareNMax;
1150 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "", spec));
1152 return group.release();
1155 bool compareNClamp (const std::vector<BufferSp>&, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs, TestLog&)
1157 if (outputAllocs.size() != 1)
1160 const BufferSp& expectedOutput = expectedOutputs[0];
1161 std::vector<deUint8> data;
1162 expectedOutput->getBytes(data);
1164 const float* const expectedOutputAsFloat = reinterpret_cast<const float*>(&data.front());
1165 const float* const outputAsFloat = static_cast<const float*>(outputAllocs[0]->getHostPtr());
1167 for (size_t idx = 0; idx < expectedOutput->getByteSize() / sizeof(float) / 2; ++idx)
1169 const float e0 = expectedOutputAsFloat[idx * 2];
1170 const float e1 = expectedOutputAsFloat[idx * 2 + 1];
1171 const float res = outputAsFloat[idx];
1173 // For NClamp, we have two possible outcomes based on
1174 // whether NaNs are handled or not.
1175 // If either min or max value is NaN, the result is undefined,
1176 // so this test doesn't stress those. If the clamped value is
1177 // NaN, and NaNs are handled, the result is min; if NaNs are not
1178 // handled, they are big values that result in max.
1179 // If all three parameters are NaN, the result should be NaN.
1180 if (!((tcu::Float32(e0).isNaN() && tcu::Float32(res).isNaN()) ||
1181 (deFloatAbs(e0 - res) < 0.00001f) ||
1182 (deFloatAbs(e1 - res) < 0.00001f)))
1189 tcu::TestCaseGroup* createOpNClampGroup (tcu::TestContext& testCtx)
1191 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opnclamp", "Test the OpNClamp instruction"));
1192 ComputeShaderSpec spec;
1193 de::Random rnd (deStringHash(group->getName()));
1194 const int numElements = 200;
1195 vector<float> inputFloats1 (numElements, 0);
1196 vector<float> inputFloats2 (numElements, 0);
1197 vector<float> inputFloats3 (numElements, 0);
1198 vector<float> outputFloats (numElements * 2, 0);
1200 fillRandomScalars(rnd, -10000.f, 10000.f, &inputFloats1[0], numElements);
1201 fillRandomScalars(rnd, -10000.f, 10000.f, &inputFloats2[0], numElements);
1202 fillRandomScalars(rnd, -10000.f, 10000.f, &inputFloats3[0], numElements);
1204 for (size_t ndx = 0; ndx < numElements; ++ndx)
1206 // Results are only defined if max value is bigger than min value.
1207 if (inputFloats2[ndx] > inputFloats3[ndx])
1209 float t = inputFloats2[ndx];
1210 inputFloats2[ndx] = inputFloats3[ndx];
1211 inputFloats3[ndx] = t;
1214 // By default, do the clamp, setting both possible answers
1215 float defaultRes = std::min(std::max(inputFloats1[ndx], inputFloats2[ndx]), inputFloats3[ndx]);
1217 float maxResA = std::max(inputFloats1[ndx], inputFloats2[ndx]);
1218 float maxResB = maxResA;
1220 // Alternate between the NaN cases
1223 inputFloats1[ndx] = TCU_NAN;
1224 // If NaN is handled, the result should be same as the clamp minimum.
1225 // If NaN is not handled, the result should clamp to the clamp maximum.
1226 maxResA = inputFloats2[ndx];
1227 maxResB = inputFloats3[ndx];
1231 // Not a NaN case - only one legal result.
1232 maxResA = defaultRes;
1233 maxResB = defaultRes;
1236 outputFloats[ndx * 2] = maxResA;
1237 outputFloats[ndx * 2 + 1] = maxResB;
1240 // Make the first case a full-NAN case.
1241 inputFloats1[0] = TCU_NAN;
1242 inputFloats2[0] = TCU_NAN;
1243 inputFloats3[0] = TCU_NAN;
1244 outputFloats[0] = TCU_NAN;
1245 outputFloats[1] = TCU_NAN;
1248 "OpCapability Shader\n"
1249 "%std450 = OpExtInstImport \"GLSL.std.450\"\n"
1250 "OpMemoryModel Logical GLSL450\n"
1251 "OpEntryPoint GLCompute %main \"main\" %id\n"
1252 "OpExecutionMode %main LocalSize 1 1 1\n"
1254 "OpName %main \"main\"\n"
1255 "OpName %id \"gl_GlobalInvocationID\"\n"
1257 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1259 "OpDecorate %buf BufferBlock\n"
1260 "OpDecorate %indata1 DescriptorSet 0\n"
1261 "OpDecorate %indata1 Binding 0\n"
1262 "OpDecorate %indata2 DescriptorSet 0\n"
1263 "OpDecorate %indata2 Binding 1\n"
1264 "OpDecorate %indata3 DescriptorSet 0\n"
1265 "OpDecorate %indata3 Binding 2\n"
1266 "OpDecorate %outdata DescriptorSet 0\n"
1267 "OpDecorate %outdata Binding 3\n"
1268 "OpDecorate %f32arr ArrayStride 4\n"
1269 "OpMemberDecorate %buf 0 Offset 0\n"
1271 + string(getComputeAsmCommonTypes()) +
1273 "%buf = OpTypeStruct %f32arr\n"
1274 "%bufptr = OpTypePointer Uniform %buf\n"
1275 "%indata1 = OpVariable %bufptr Uniform\n"
1276 "%indata2 = OpVariable %bufptr Uniform\n"
1277 "%indata3 = OpVariable %bufptr Uniform\n"
1278 "%outdata = OpVariable %bufptr Uniform\n"
1280 "%id = OpVariable %uvec3ptr Input\n"
1281 "%zero = OpConstant %i32 0\n"
1283 "%main = OpFunction %void None %voidf\n"
1284 "%label = OpLabel\n"
1285 "%idval = OpLoad %uvec3 %id\n"
1286 "%x = OpCompositeExtract %u32 %idval 0\n"
1287 "%inloc1 = OpAccessChain %f32ptr %indata1 %zero %x\n"
1288 "%inval1 = OpLoad %f32 %inloc1\n"
1289 "%inloc2 = OpAccessChain %f32ptr %indata2 %zero %x\n"
1290 "%inval2 = OpLoad %f32 %inloc2\n"
1291 "%inloc3 = OpAccessChain %f32ptr %indata3 %zero %x\n"
1292 "%inval3 = OpLoad %f32 %inloc3\n"
1293 "%rem = OpExtInst %f32 %std450 NClamp %inval1 %inval2 %inval3\n"
1294 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
1295 " OpStore %outloc %rem\n"
1299 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats1)));
1300 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
1301 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats3)));
1302 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
1303 spec.numWorkGroups = IVec3(numElements, 1, 1);
1304 spec.verifyIO = &compareNClamp;
1306 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "", spec));
1308 return group.release();
1311 tcu::TestCaseGroup* createOpSRemComputeGroup (tcu::TestContext& testCtx, qpTestResult negFailResult)
1313 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opsrem", "Test the OpSRem instruction"));
1314 de::Random rnd (deStringHash(group->getName()));
1315 const int numElements = 200;
1317 const struct CaseParams
1320 const char* failMessage; // customized status message
1321 qpTestResult failResult; // override status on failure
1322 int op1Min, op1Max; // operand ranges
1326 { "positive", "Output doesn't match with expected", QP_TEST_RESULT_FAIL, 0, 65536, 0, 100 },
1327 { "all", "Inconsistent results, but within specification", negFailResult, -65536, 65536, -100, 100 }, // see below
1329 // If either operand is negative the result is undefined. Some implementations may still return correct values.
1331 for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(cases); ++caseNdx)
1333 const CaseParams& params = cases[caseNdx];
1334 ComputeShaderSpec spec;
1335 vector<deInt32> inputInts1 (numElements, 0);
1336 vector<deInt32> inputInts2 (numElements, 0);
1337 vector<deInt32> outputInts (numElements, 0);
1339 fillRandomScalars(rnd, params.op1Min, params.op1Max, &inputInts1[0], numElements);
1340 fillRandomScalars(rnd, params.op2Min, params.op2Max, &inputInts2[0], numElements, filterNotZero);
1342 for (int ndx = 0; ndx < numElements; ++ndx)
1344 // The return value of std::fmod() has the same sign as its first operand, which is how OpFRem spec'd.
1345 outputInts[ndx] = inputInts1[ndx] % inputInts2[ndx];
1349 string(getComputeAsmShaderPreamble()) +
1351 "OpName %main \"main\"\n"
1352 "OpName %id \"gl_GlobalInvocationID\"\n"
1354 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1356 "OpDecorate %buf BufferBlock\n"
1357 "OpDecorate %indata1 DescriptorSet 0\n"
1358 "OpDecorate %indata1 Binding 0\n"
1359 "OpDecorate %indata2 DescriptorSet 0\n"
1360 "OpDecorate %indata2 Binding 1\n"
1361 "OpDecorate %outdata DescriptorSet 0\n"
1362 "OpDecorate %outdata Binding 2\n"
1363 "OpDecorate %i32arr ArrayStride 4\n"
1364 "OpMemberDecorate %buf 0 Offset 0\n"
1366 + string(getComputeAsmCommonTypes()) +
1368 "%buf = OpTypeStruct %i32arr\n"
1369 "%bufptr = OpTypePointer Uniform %buf\n"
1370 "%indata1 = OpVariable %bufptr Uniform\n"
1371 "%indata2 = OpVariable %bufptr Uniform\n"
1372 "%outdata = OpVariable %bufptr Uniform\n"
1374 "%id = OpVariable %uvec3ptr Input\n"
1375 "%zero = OpConstant %i32 0\n"
1377 "%main = OpFunction %void None %voidf\n"
1378 "%label = OpLabel\n"
1379 "%idval = OpLoad %uvec3 %id\n"
1380 "%x = OpCompositeExtract %u32 %idval 0\n"
1381 "%inloc1 = OpAccessChain %i32ptr %indata1 %zero %x\n"
1382 "%inval1 = OpLoad %i32 %inloc1\n"
1383 "%inloc2 = OpAccessChain %i32ptr %indata2 %zero %x\n"
1384 "%inval2 = OpLoad %i32 %inloc2\n"
1385 "%rem = OpSRem %i32 %inval1 %inval2\n"
1386 "%outloc = OpAccessChain %i32ptr %outdata %zero %x\n"
1387 " OpStore %outloc %rem\n"
1391 spec.inputs.push_back (BufferSp(new Int32Buffer(inputInts1)));
1392 spec.inputs.push_back (BufferSp(new Int32Buffer(inputInts2)));
1393 spec.outputs.push_back (BufferSp(new Int32Buffer(outputInts)));
1394 spec.numWorkGroups = IVec3(numElements, 1, 1);
1395 spec.failResult = params.failResult;
1396 spec.failMessage = params.failMessage;
1398 group->addChild(new SpvAsmComputeShaderCase(testCtx, params.name, "", spec));
1401 return group.release();
1404 tcu::TestCaseGroup* createOpSRemComputeGroup64 (tcu::TestContext& testCtx, qpTestResult negFailResult)
1406 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opsrem64", "Test the 64-bit OpSRem instruction"));
1407 de::Random rnd (deStringHash(group->getName()));
1408 const int numElements = 200;
1410 const struct CaseParams
1413 const char* failMessage; // customized status message
1414 qpTestResult failResult; // override status on failure
1418 { "positive", "Output doesn't match with expected", QP_TEST_RESULT_FAIL, true },
1419 { "all", "Inconsistent results, but within specification", negFailResult, false }, // see below
1421 // If either operand is negative the result is undefined. Some implementations may still return correct values.
1423 for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(cases); ++caseNdx)
1425 const CaseParams& params = cases[caseNdx];
1426 ComputeShaderSpec spec;
1427 vector<deInt64> inputInts1 (numElements, 0);
1428 vector<deInt64> inputInts2 (numElements, 0);
1429 vector<deInt64> outputInts (numElements, 0);
1431 if (params.positive)
1433 fillRandomInt64sLogDistributed(rnd, inputInts1, numElements, filterNonNegative);
1434 fillRandomInt64sLogDistributed(rnd, inputInts2, numElements, filterPositive);
1438 fillRandomInt64sLogDistributed(rnd, inputInts1, numElements);
1439 fillRandomInt64sLogDistributed(rnd, inputInts2, numElements, filterNotZero);
1442 for (int ndx = 0; ndx < numElements; ++ndx)
1444 // The return value of std::fmod() has the same sign as its first operand, which is how OpFRem spec'd.
1445 outputInts[ndx] = inputInts1[ndx] % inputInts2[ndx];
1449 "OpCapability Int64\n"
1451 + string(getComputeAsmShaderPreamble()) +
1453 "OpName %main \"main\"\n"
1454 "OpName %id \"gl_GlobalInvocationID\"\n"
1456 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1458 "OpDecorate %buf BufferBlock\n"
1459 "OpDecorate %indata1 DescriptorSet 0\n"
1460 "OpDecorate %indata1 Binding 0\n"
1461 "OpDecorate %indata2 DescriptorSet 0\n"
1462 "OpDecorate %indata2 Binding 1\n"
1463 "OpDecorate %outdata DescriptorSet 0\n"
1464 "OpDecorate %outdata Binding 2\n"
1465 "OpDecorate %i64arr ArrayStride 8\n"
1466 "OpMemberDecorate %buf 0 Offset 0\n"
1468 + string(getComputeAsmCommonTypes())
1469 + string(getComputeAsmCommonInt64Types()) +
1471 "%buf = OpTypeStruct %i64arr\n"
1472 "%bufptr = OpTypePointer Uniform %buf\n"
1473 "%indata1 = OpVariable %bufptr Uniform\n"
1474 "%indata2 = OpVariable %bufptr Uniform\n"
1475 "%outdata = OpVariable %bufptr Uniform\n"
1477 "%id = OpVariable %uvec3ptr Input\n"
1478 "%zero = OpConstant %i64 0\n"
1480 "%main = OpFunction %void None %voidf\n"
1481 "%label = OpLabel\n"
1482 "%idval = OpLoad %uvec3 %id\n"
1483 "%x = OpCompositeExtract %u32 %idval 0\n"
1484 "%inloc1 = OpAccessChain %i64ptr %indata1 %zero %x\n"
1485 "%inval1 = OpLoad %i64 %inloc1\n"
1486 "%inloc2 = OpAccessChain %i64ptr %indata2 %zero %x\n"
1487 "%inval2 = OpLoad %i64 %inloc2\n"
1488 "%rem = OpSRem %i64 %inval1 %inval2\n"
1489 "%outloc = OpAccessChain %i64ptr %outdata %zero %x\n"
1490 " OpStore %outloc %rem\n"
1494 spec.inputs.push_back (BufferSp(new Int64Buffer(inputInts1)));
1495 spec.inputs.push_back (BufferSp(new Int64Buffer(inputInts2)));
1496 spec.outputs.push_back (BufferSp(new Int64Buffer(outputInts)));
1497 spec.numWorkGroups = IVec3(numElements, 1, 1);
1498 spec.failResult = params.failResult;
1499 spec.failMessage = params.failMessage;
1501 group->addChild(new SpvAsmComputeShaderCase(testCtx, params.name, "", spec, COMPUTE_TEST_USES_INT64));
1504 return group.release();
1507 tcu::TestCaseGroup* createOpSModComputeGroup (tcu::TestContext& testCtx, qpTestResult negFailResult)
1509 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opsmod", "Test the OpSMod instruction"));
1510 de::Random rnd (deStringHash(group->getName()));
1511 const int numElements = 200;
1513 const struct CaseParams
1516 const char* failMessage; // customized status message
1517 qpTestResult failResult; // override status on failure
1518 int op1Min, op1Max; // operand ranges
1522 { "positive", "Output doesn't match with expected", QP_TEST_RESULT_FAIL, 0, 65536, 0, 100 },
1523 { "all", "Inconsistent results, but within specification", negFailResult, -65536, 65536, -100, 100 }, // see below
1525 // If either operand is negative the result is undefined. Some implementations may still return correct values.
1527 for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(cases); ++caseNdx)
1529 const CaseParams& params = cases[caseNdx];
1531 ComputeShaderSpec spec;
1532 vector<deInt32> inputInts1 (numElements, 0);
1533 vector<deInt32> inputInts2 (numElements, 0);
1534 vector<deInt32> outputInts (numElements, 0);
1536 fillRandomScalars(rnd, params.op1Min, params.op1Max, &inputInts1[0], numElements);
1537 fillRandomScalars(rnd, params.op2Min, params.op2Max, &inputInts2[0], numElements, filterNotZero);
1539 for (int ndx = 0; ndx < numElements; ++ndx)
1541 deInt32 rem = inputInts1[ndx] % inputInts2[ndx];
1544 outputInts[ndx] = 0;
1546 else if ((inputInts1[ndx] >= 0) == (inputInts2[ndx] >= 0))
1548 // They have the same sign
1549 outputInts[ndx] = rem;
1553 // They have opposite sign. The remainder operation takes the
1554 // sign inputInts1[ndx] but OpSMod is supposed to take ths sign
1555 // of inputInts2[ndx]. Adding inputInts2[ndx] will ensure that
1556 // the result has the correct sign and that it is still
1557 // congruent to inputInts1[ndx] modulo inputInts2[ndx]
1559 // See also http://mathforum.org/library/drmath/view/52343.html
1560 outputInts[ndx] = rem + inputInts2[ndx];
1565 string(getComputeAsmShaderPreamble()) +
1567 "OpName %main \"main\"\n"
1568 "OpName %id \"gl_GlobalInvocationID\"\n"
1570 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1572 "OpDecorate %buf BufferBlock\n"
1573 "OpDecorate %indata1 DescriptorSet 0\n"
1574 "OpDecorate %indata1 Binding 0\n"
1575 "OpDecorate %indata2 DescriptorSet 0\n"
1576 "OpDecorate %indata2 Binding 1\n"
1577 "OpDecorate %outdata DescriptorSet 0\n"
1578 "OpDecorate %outdata Binding 2\n"
1579 "OpDecorate %i32arr ArrayStride 4\n"
1580 "OpMemberDecorate %buf 0 Offset 0\n"
1582 + string(getComputeAsmCommonTypes()) +
1584 "%buf = OpTypeStruct %i32arr\n"
1585 "%bufptr = OpTypePointer Uniform %buf\n"
1586 "%indata1 = OpVariable %bufptr Uniform\n"
1587 "%indata2 = OpVariable %bufptr Uniform\n"
1588 "%outdata = OpVariable %bufptr Uniform\n"
1590 "%id = OpVariable %uvec3ptr Input\n"
1591 "%zero = OpConstant %i32 0\n"
1593 "%main = OpFunction %void None %voidf\n"
1594 "%label = OpLabel\n"
1595 "%idval = OpLoad %uvec3 %id\n"
1596 "%x = OpCompositeExtract %u32 %idval 0\n"
1597 "%inloc1 = OpAccessChain %i32ptr %indata1 %zero %x\n"
1598 "%inval1 = OpLoad %i32 %inloc1\n"
1599 "%inloc2 = OpAccessChain %i32ptr %indata2 %zero %x\n"
1600 "%inval2 = OpLoad %i32 %inloc2\n"
1601 "%rem = OpSMod %i32 %inval1 %inval2\n"
1602 "%outloc = OpAccessChain %i32ptr %outdata %zero %x\n"
1603 " OpStore %outloc %rem\n"
1607 spec.inputs.push_back (BufferSp(new Int32Buffer(inputInts1)));
1608 spec.inputs.push_back (BufferSp(new Int32Buffer(inputInts2)));
1609 spec.outputs.push_back (BufferSp(new Int32Buffer(outputInts)));
1610 spec.numWorkGroups = IVec3(numElements, 1, 1);
1611 spec.failResult = params.failResult;
1612 spec.failMessage = params.failMessage;
1614 group->addChild(new SpvAsmComputeShaderCase(testCtx, params.name, "", spec));
1617 return group.release();
1620 tcu::TestCaseGroup* createOpSModComputeGroup64 (tcu::TestContext& testCtx, qpTestResult negFailResult)
1622 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opsmod64", "Test the OpSMod instruction"));
1623 de::Random rnd (deStringHash(group->getName()));
1624 const int numElements = 200;
1626 const struct CaseParams
1629 const char* failMessage; // customized status message
1630 qpTestResult failResult; // override status on failure
1634 { "positive", "Output doesn't match with expected", QP_TEST_RESULT_FAIL, true },
1635 { "all", "Inconsistent results, but within specification", negFailResult, false }, // see below
1637 // If either operand is negative the result is undefined. Some implementations may still return correct values.
1639 for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(cases); ++caseNdx)
1641 const CaseParams& params = cases[caseNdx];
1643 ComputeShaderSpec spec;
1644 vector<deInt64> inputInts1 (numElements, 0);
1645 vector<deInt64> inputInts2 (numElements, 0);
1646 vector<deInt64> outputInts (numElements, 0);
1649 if (params.positive)
1651 fillRandomInt64sLogDistributed(rnd, inputInts1, numElements, filterNonNegative);
1652 fillRandomInt64sLogDistributed(rnd, inputInts2, numElements, filterPositive);
1656 fillRandomInt64sLogDistributed(rnd, inputInts1, numElements);
1657 fillRandomInt64sLogDistributed(rnd, inputInts2, numElements, filterNotZero);
1660 for (int ndx = 0; ndx < numElements; ++ndx)
1662 deInt64 rem = inputInts1[ndx] % inputInts2[ndx];
1665 outputInts[ndx] = 0;
1667 else if ((inputInts1[ndx] >= 0) == (inputInts2[ndx] >= 0))
1669 // They have the same sign
1670 outputInts[ndx] = rem;
1674 // They have opposite sign. The remainder operation takes the
1675 // sign inputInts1[ndx] but OpSMod is supposed to take ths sign
1676 // of inputInts2[ndx]. Adding inputInts2[ndx] will ensure that
1677 // the result has the correct sign and that it is still
1678 // congruent to inputInts1[ndx] modulo inputInts2[ndx]
1680 // See also http://mathforum.org/library/drmath/view/52343.html
1681 outputInts[ndx] = rem + inputInts2[ndx];
1686 "OpCapability Int64\n"
1688 + string(getComputeAsmShaderPreamble()) +
1690 "OpName %main \"main\"\n"
1691 "OpName %id \"gl_GlobalInvocationID\"\n"
1693 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1695 "OpDecorate %buf BufferBlock\n"
1696 "OpDecorate %indata1 DescriptorSet 0\n"
1697 "OpDecorate %indata1 Binding 0\n"
1698 "OpDecorate %indata2 DescriptorSet 0\n"
1699 "OpDecorate %indata2 Binding 1\n"
1700 "OpDecorate %outdata DescriptorSet 0\n"
1701 "OpDecorate %outdata Binding 2\n"
1702 "OpDecorate %i64arr ArrayStride 8\n"
1703 "OpMemberDecorate %buf 0 Offset 0\n"
1705 + string(getComputeAsmCommonTypes())
1706 + string(getComputeAsmCommonInt64Types()) +
1708 "%buf = OpTypeStruct %i64arr\n"
1709 "%bufptr = OpTypePointer Uniform %buf\n"
1710 "%indata1 = OpVariable %bufptr Uniform\n"
1711 "%indata2 = OpVariable %bufptr Uniform\n"
1712 "%outdata = OpVariable %bufptr Uniform\n"
1714 "%id = OpVariable %uvec3ptr Input\n"
1715 "%zero = OpConstant %i64 0\n"
1717 "%main = OpFunction %void None %voidf\n"
1718 "%label = OpLabel\n"
1719 "%idval = OpLoad %uvec3 %id\n"
1720 "%x = OpCompositeExtract %u32 %idval 0\n"
1721 "%inloc1 = OpAccessChain %i64ptr %indata1 %zero %x\n"
1722 "%inval1 = OpLoad %i64 %inloc1\n"
1723 "%inloc2 = OpAccessChain %i64ptr %indata2 %zero %x\n"
1724 "%inval2 = OpLoad %i64 %inloc2\n"
1725 "%rem = OpSMod %i64 %inval1 %inval2\n"
1726 "%outloc = OpAccessChain %i64ptr %outdata %zero %x\n"
1727 " OpStore %outloc %rem\n"
1731 spec.inputs.push_back (BufferSp(new Int64Buffer(inputInts1)));
1732 spec.inputs.push_back (BufferSp(new Int64Buffer(inputInts2)));
1733 spec.outputs.push_back (BufferSp(new Int64Buffer(outputInts)));
1734 spec.numWorkGroups = IVec3(numElements, 1, 1);
1735 spec.failResult = params.failResult;
1736 spec.failMessage = params.failMessage;
1738 group->addChild(new SpvAsmComputeShaderCase(testCtx, params.name, "", spec, COMPUTE_TEST_USES_INT64));
1741 return group.release();
1744 // Copy contents in the input buffer to the output buffer.
1745 tcu::TestCaseGroup* createOpCopyMemoryGroup (tcu::TestContext& testCtx)
1747 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opcopymemory", "Test the OpCopyMemory instruction"));
1748 de::Random rnd (deStringHash(group->getName()));
1749 const int numElements = 100;
1751 // 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.
1752 ComputeShaderSpec spec1;
1753 vector<Vec4> inputFloats1 (numElements);
1754 vector<Vec4> outputFloats1 (numElements);
1756 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats1[0], numElements * 4);
1758 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
1759 floorAll(inputFloats1);
1761 for (size_t ndx = 0; ndx < numElements; ++ndx)
1762 outputFloats1[ndx] = inputFloats1[ndx] + Vec4(0.f, 0.5f, 1.5f, 2.5f);
1765 string(getComputeAsmShaderPreamble()) +
1767 "OpName %main \"main\"\n"
1768 "OpName %id \"gl_GlobalInvocationID\"\n"
1770 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1771 "OpDecorate %vec4arr ArrayStride 16\n"
1773 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
1775 "%vec4 = OpTypeVector %f32 4\n"
1776 "%vec4ptr_u = OpTypePointer Uniform %vec4\n"
1777 "%vec4ptr_f = OpTypePointer Function %vec4\n"
1778 "%vec4arr = OpTypeRuntimeArray %vec4\n"
1779 "%buf = OpTypeStruct %vec4arr\n"
1780 "%bufptr = OpTypePointer Uniform %buf\n"
1781 "%indata = OpVariable %bufptr Uniform\n"
1782 "%outdata = OpVariable %bufptr Uniform\n"
1784 "%id = OpVariable %uvec3ptr Input\n"
1785 "%zero = OpConstant %i32 0\n"
1786 "%c_f_0 = OpConstant %f32 0.\n"
1787 "%c_f_0_5 = OpConstant %f32 0.5\n"
1788 "%c_f_1_5 = OpConstant %f32 1.5\n"
1789 "%c_f_2_5 = OpConstant %f32 2.5\n"
1790 "%c_vec4 = OpConstantComposite %vec4 %c_f_0 %c_f_0_5 %c_f_1_5 %c_f_2_5\n"
1792 "%main = OpFunction %void None %voidf\n"
1793 "%label = OpLabel\n"
1794 "%v_vec4 = OpVariable %vec4ptr_f Function\n"
1795 "%idval = OpLoad %uvec3 %id\n"
1796 "%x = OpCompositeExtract %u32 %idval 0\n"
1797 "%inloc = OpAccessChain %vec4ptr_u %indata %zero %x\n"
1798 "%outloc = OpAccessChain %vec4ptr_u %outdata %zero %x\n"
1799 " OpCopyMemory %v_vec4 %inloc\n"
1800 "%v_vec4_val = OpLoad %vec4 %v_vec4\n"
1801 "%add = OpFAdd %vec4 %v_vec4_val %c_vec4\n"
1802 " OpStore %outloc %add\n"
1806 spec1.inputs.push_back(BufferSp(new Vec4Buffer(inputFloats1)));
1807 spec1.outputs.push_back(BufferSp(new Vec4Buffer(outputFloats1)));
1808 spec1.numWorkGroups = IVec3(numElements, 1, 1);
1810 group->addChild(new SpvAsmComputeShaderCase(testCtx, "vector", "OpCopyMemory elements of vector type", spec1));
1812 // The following case copies a float[100] variable from the input buffer to the output buffer.
1813 ComputeShaderSpec spec2;
1814 vector<float> inputFloats2 (numElements);
1815 vector<float> outputFloats2 (numElements);
1817 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats2[0], numElements);
1819 for (size_t ndx = 0; ndx < numElements; ++ndx)
1820 outputFloats2[ndx] = inputFloats2[ndx];
1823 string(getComputeAsmShaderPreamble()) +
1825 "OpName %main \"main\"\n"
1826 "OpName %id \"gl_GlobalInvocationID\"\n"
1828 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1829 "OpDecorate %f32arr100 ArrayStride 4\n"
1831 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
1833 "%hundred = OpConstant %u32 100\n"
1834 "%f32arr100 = OpTypeArray %f32 %hundred\n"
1835 "%f32arr100ptr_f = OpTypePointer Function %f32arr100\n"
1836 "%f32arr100ptr_u = OpTypePointer Uniform %f32arr100\n"
1837 "%buf = OpTypeStruct %f32arr100\n"
1838 "%bufptr = OpTypePointer Uniform %buf\n"
1839 "%indata = OpVariable %bufptr Uniform\n"
1840 "%outdata = OpVariable %bufptr Uniform\n"
1842 "%id = OpVariable %uvec3ptr Input\n"
1843 "%zero = OpConstant %i32 0\n"
1845 "%main = OpFunction %void None %voidf\n"
1846 "%label = OpLabel\n"
1847 "%var = OpVariable %f32arr100ptr_f Function\n"
1848 "%inarr = OpAccessChain %f32arr100ptr_u %indata %zero\n"
1849 "%outarr = OpAccessChain %f32arr100ptr_u %outdata %zero\n"
1850 " OpCopyMemory %var %inarr\n"
1851 " OpCopyMemory %outarr %var\n"
1855 spec2.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
1856 spec2.outputs.push_back(BufferSp(new Float32Buffer(outputFloats2)));
1857 spec2.numWorkGroups = IVec3(1, 1, 1);
1859 group->addChild(new SpvAsmComputeShaderCase(testCtx, "array", "OpCopyMemory elements of array type", spec2));
1861 // The following case copies a struct{vec4, vec4, vec4, vec4} variable from the input buffer to the output buffer.
1862 ComputeShaderSpec spec3;
1863 vector<float> inputFloats3 (16);
1864 vector<float> outputFloats3 (16);
1866 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats3[0], 16);
1868 for (size_t ndx = 0; ndx < 16; ++ndx)
1869 outputFloats3[ndx] = inputFloats3[ndx];
1872 string(getComputeAsmShaderPreamble()) +
1874 "OpName %main \"main\"\n"
1875 "OpName %id \"gl_GlobalInvocationID\"\n"
1877 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1878 "OpMemberDecorate %buf 0 Offset 0\n"
1879 "OpMemberDecorate %buf 1 Offset 16\n"
1880 "OpMemberDecorate %buf 2 Offset 32\n"
1881 "OpMemberDecorate %buf 3 Offset 48\n"
1883 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
1885 "%vec4 = OpTypeVector %f32 4\n"
1886 "%buf = OpTypeStruct %vec4 %vec4 %vec4 %vec4\n"
1887 "%bufptr = OpTypePointer Uniform %buf\n"
1888 "%indata = OpVariable %bufptr Uniform\n"
1889 "%outdata = OpVariable %bufptr Uniform\n"
1890 "%vec4stptr = OpTypePointer Function %buf\n"
1892 "%id = OpVariable %uvec3ptr Input\n"
1893 "%zero = OpConstant %i32 0\n"
1895 "%main = OpFunction %void None %voidf\n"
1896 "%label = OpLabel\n"
1897 "%var = OpVariable %vec4stptr Function\n"
1898 " OpCopyMemory %var %indata\n"
1899 " OpCopyMemory %outdata %var\n"
1903 spec3.inputs.push_back(BufferSp(new Float32Buffer(inputFloats3)));
1904 spec3.outputs.push_back(BufferSp(new Float32Buffer(outputFloats3)));
1905 spec3.numWorkGroups = IVec3(1, 1, 1);
1907 group->addChild(new SpvAsmComputeShaderCase(testCtx, "struct", "OpCopyMemory elements of struct type", spec3));
1909 // The following case negates multiple float variables from the input buffer and stores the results to the output buffer.
1910 ComputeShaderSpec spec4;
1911 vector<float> inputFloats4 (numElements);
1912 vector<float> outputFloats4 (numElements);
1914 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats4[0], numElements);
1916 for (size_t ndx = 0; ndx < numElements; ++ndx)
1917 outputFloats4[ndx] = -inputFloats4[ndx];
1920 string(getComputeAsmShaderPreamble()) +
1922 "OpName %main \"main\"\n"
1923 "OpName %id \"gl_GlobalInvocationID\"\n"
1925 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1927 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
1929 "%f32ptr_f = OpTypePointer Function %f32\n"
1930 "%id = OpVariable %uvec3ptr Input\n"
1931 "%zero = OpConstant %i32 0\n"
1933 "%main = OpFunction %void None %voidf\n"
1934 "%label = OpLabel\n"
1935 "%var = OpVariable %f32ptr_f Function\n"
1936 "%idval = OpLoad %uvec3 %id\n"
1937 "%x = OpCompositeExtract %u32 %idval 0\n"
1938 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
1939 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
1940 " OpCopyMemory %var %inloc\n"
1941 "%val = OpLoad %f32 %var\n"
1942 "%neg = OpFNegate %f32 %val\n"
1943 " OpStore %outloc %neg\n"
1947 spec4.inputs.push_back(BufferSp(new Float32Buffer(inputFloats4)));
1948 spec4.outputs.push_back(BufferSp(new Float32Buffer(outputFloats4)));
1949 spec4.numWorkGroups = IVec3(numElements, 1, 1);
1951 group->addChild(new SpvAsmComputeShaderCase(testCtx, "float", "OpCopyMemory elements of float type", spec4));
1953 return group.release();
1956 tcu::TestCaseGroup* createOpCopyObjectGroup (tcu::TestContext& testCtx)
1958 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opcopyobject", "Test the OpCopyObject instruction"));
1959 ComputeShaderSpec spec;
1960 de::Random rnd (deStringHash(group->getName()));
1961 const int numElements = 100;
1962 vector<float> inputFloats (numElements, 0);
1963 vector<float> outputFloats (numElements, 0);
1965 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats[0], numElements);
1967 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
1968 floorAll(inputFloats);
1970 for (size_t ndx = 0; ndx < numElements; ++ndx)
1971 outputFloats[ndx] = inputFloats[ndx] + 7.5f;
1974 string(getComputeAsmShaderPreamble()) +
1976 "OpName %main \"main\"\n"
1977 "OpName %id \"gl_GlobalInvocationID\"\n"
1979 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1981 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
1983 "%fmat = OpTypeMatrix %fvec3 3\n"
1984 "%three = OpConstant %u32 3\n"
1985 "%farr = OpTypeArray %f32 %three\n"
1986 "%fst = OpTypeStruct %f32 %f32\n"
1988 + string(getComputeAsmInputOutputBuffer()) +
1990 "%id = OpVariable %uvec3ptr Input\n"
1991 "%zero = OpConstant %i32 0\n"
1992 "%c_f = OpConstant %f32 1.5\n"
1993 "%c_fvec3 = OpConstantComposite %fvec3 %c_f %c_f %c_f\n"
1994 "%c_fmat = OpConstantComposite %fmat %c_fvec3 %c_fvec3 %c_fvec3\n"
1995 "%c_farr = OpConstantComposite %farr %c_f %c_f %c_f\n"
1996 "%c_fst = OpConstantComposite %fst %c_f %c_f\n"
1998 "%main = OpFunction %void None %voidf\n"
1999 "%label = OpLabel\n"
2000 "%c_f_copy = OpCopyObject %f32 %c_f\n"
2001 "%c_fvec3_copy = OpCopyObject %fvec3 %c_fvec3\n"
2002 "%c_fmat_copy = OpCopyObject %fmat %c_fmat\n"
2003 "%c_farr_copy = OpCopyObject %farr %c_farr\n"
2004 "%c_fst_copy = OpCopyObject %fst %c_fst\n"
2005 "%fvec3_elem = OpCompositeExtract %f32 %c_fvec3_copy 0\n"
2006 "%fmat_elem = OpCompositeExtract %f32 %c_fmat_copy 1 2\n"
2007 "%farr_elem = OpCompositeExtract %f32 %c_farr_copy 2\n"
2008 "%fst_elem = OpCompositeExtract %f32 %c_fst_copy 1\n"
2009 // Add up. 1.5 * 5 = 7.5.
2010 "%add1 = OpFAdd %f32 %c_f_copy %fvec3_elem\n"
2011 "%add2 = OpFAdd %f32 %add1 %fmat_elem\n"
2012 "%add3 = OpFAdd %f32 %add2 %farr_elem\n"
2013 "%add4 = OpFAdd %f32 %add3 %fst_elem\n"
2015 "%idval = OpLoad %uvec3 %id\n"
2016 "%x = OpCompositeExtract %u32 %idval 0\n"
2017 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
2018 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2019 "%inval = OpLoad %f32 %inloc\n"
2020 "%add = OpFAdd %f32 %add4 %inval\n"
2021 " OpStore %outloc %add\n"
2024 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
2025 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
2026 spec.numWorkGroups = IVec3(numElements, 1, 1);
2028 group->addChild(new SpvAsmComputeShaderCase(testCtx, "spotcheck", "OpCopyObject on different types", spec));
2030 return group.release();
2032 // Assembly code used for testing OpUnreachable is based on GLSL source code:
2036 // layout(std140, set = 0, binding = 0) readonly buffer Input {
2037 // float elements[];
2039 // layout(std140, set = 0, binding = 1) writeonly buffer Output {
2040 // float elements[];
2043 // void not_called_func() {
2044 // // place OpUnreachable here
2047 // uint modulo4(uint val) {
2048 // switch (val % uint(4)) {
2049 // case 0: return 3;
2050 // case 1: return 2;
2051 // case 2: return 1;
2052 // case 3: return 0;
2053 // default: return 100; // place OpUnreachable here
2059 // // place OpUnreachable here
2063 // uint x = gl_GlobalInvocationID.x;
2064 // if (const5() > modulo4(1000)) {
2065 // output_data.elements[x] = -input_data.elements[x];
2067 // // place OpUnreachable here
2068 // output_data.elements[x] = input_data.elements[x];
2072 tcu::TestCaseGroup* createOpUnreachableGroup (tcu::TestContext& testCtx)
2074 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opunreachable", "Test the OpUnreachable instruction"));
2075 ComputeShaderSpec spec;
2076 de::Random rnd (deStringHash(group->getName()));
2077 const int numElements = 100;
2078 vector<float> positiveFloats (numElements, 0);
2079 vector<float> negativeFloats (numElements, 0);
2081 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
2083 for (size_t ndx = 0; ndx < numElements; ++ndx)
2084 negativeFloats[ndx] = -positiveFloats[ndx];
2087 string(getComputeAsmShaderPreamble()) +
2089 "OpSource GLSL 430\n"
2090 "OpName %main \"main\"\n"
2091 "OpName %func_not_called_func \"not_called_func(\"\n"
2092 "OpName %func_modulo4 \"modulo4(u1;\"\n"
2093 "OpName %func_const5 \"const5(\"\n"
2094 "OpName %id \"gl_GlobalInvocationID\"\n"
2096 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2098 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
2100 "%u32ptr = OpTypePointer Function %u32\n"
2101 "%uintfuint = OpTypeFunction %u32 %u32ptr\n"
2102 "%unitf = OpTypeFunction %u32\n"
2104 "%id = OpVariable %uvec3ptr Input\n"
2105 "%zero = OpConstant %u32 0\n"
2106 "%one = OpConstant %u32 1\n"
2107 "%two = OpConstant %u32 2\n"
2108 "%three = OpConstant %u32 3\n"
2109 "%four = OpConstant %u32 4\n"
2110 "%five = OpConstant %u32 5\n"
2111 "%hundred = OpConstant %u32 100\n"
2112 "%thousand = OpConstant %u32 1000\n"
2114 + string(getComputeAsmInputOutputBuffer()) +
2117 "%main = OpFunction %void None %voidf\n"
2118 "%main_entry = OpLabel\n"
2119 "%v_thousand = OpVariable %u32ptr Function %thousand\n"
2120 "%idval = OpLoad %uvec3 %id\n"
2121 "%x = OpCompositeExtract %u32 %idval 0\n"
2122 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
2123 "%inval = OpLoad %f32 %inloc\n"
2124 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2125 "%ret_const5 = OpFunctionCall %u32 %func_const5\n"
2126 "%ret_modulo4 = OpFunctionCall %u32 %func_modulo4 %v_thousand\n"
2127 "%cmp_gt = OpUGreaterThan %bool %ret_const5 %ret_modulo4\n"
2128 " OpSelectionMerge %if_end None\n"
2129 " OpBranchConditional %cmp_gt %if_true %if_false\n"
2130 "%if_true = OpLabel\n"
2131 "%negate = OpFNegate %f32 %inval\n"
2132 " OpStore %outloc %negate\n"
2133 " OpBranch %if_end\n"
2134 "%if_false = OpLabel\n"
2135 " OpUnreachable\n" // Unreachable else branch for if statement
2136 "%if_end = OpLabel\n"
2140 // not_called_function()
2141 "%func_not_called_func = OpFunction %void None %voidf\n"
2142 "%not_called_func_entry = OpLabel\n"
2143 " OpUnreachable\n" // Unreachable entry block in not called static function
2147 "%func_modulo4 = OpFunction %u32 None %uintfuint\n"
2148 "%valptr = OpFunctionParameter %u32ptr\n"
2149 "%modulo4_entry = OpLabel\n"
2150 "%val = OpLoad %u32 %valptr\n"
2151 "%modulo = OpUMod %u32 %val %four\n"
2152 " OpSelectionMerge %switch_merge None\n"
2153 " OpSwitch %modulo %default 0 %case0 1 %case1 2 %case2 3 %case3\n"
2154 "%case0 = OpLabel\n"
2155 " OpReturnValue %three\n"
2156 "%case1 = OpLabel\n"
2157 " OpReturnValue %two\n"
2158 "%case2 = OpLabel\n"
2159 " OpReturnValue %one\n"
2160 "%case3 = OpLabel\n"
2161 " OpReturnValue %zero\n"
2162 "%default = OpLabel\n"
2163 " OpUnreachable\n" // Unreachable default case for switch statement
2164 "%switch_merge = OpLabel\n"
2165 " OpUnreachable\n" // Unreachable merge block for switch statement
2169 "%func_const5 = OpFunction %u32 None %unitf\n"
2170 "%const5_entry = OpLabel\n"
2171 " OpReturnValue %five\n"
2172 "%unreachable = OpLabel\n"
2173 " OpUnreachable\n" // Unreachable block in function
2175 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
2176 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
2177 spec.numWorkGroups = IVec3(numElements, 1, 1);
2179 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "OpUnreachable appearing at different places", spec));
2181 return group.release();
2184 // Assembly code used for testing decoration group is based on GLSL source code:
2188 // layout(std140, set = 0, binding = 0) readonly buffer Input0 {
2189 // float elements[];
2191 // layout(std140, set = 0, binding = 1) readonly buffer Input1 {
2192 // float elements[];
2194 // layout(std140, set = 0, binding = 2) readonly buffer Input2 {
2195 // float elements[];
2197 // layout(std140, set = 0, binding = 3) readonly buffer Input3 {
2198 // float elements[];
2200 // layout(std140, set = 0, binding = 4) readonly buffer Input4 {
2201 // float elements[];
2203 // layout(std140, set = 0, binding = 5) writeonly buffer Output {
2204 // float elements[];
2208 // uint x = gl_GlobalInvocationID.x;
2209 // output_data.elements[x] = input_data0.elements[x] + input_data1.elements[x] + input_data2.elements[x] + input_data3.elements[x] + input_data4.elements[x];
2211 tcu::TestCaseGroup* createDecorationGroupGroup (tcu::TestContext& testCtx)
2213 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "decoration_group", "Test the OpDecorationGroup & OpGroupDecorate instruction"));
2214 ComputeShaderSpec spec;
2215 de::Random rnd (deStringHash(group->getName()));
2216 const int numElements = 100;
2217 vector<float> inputFloats0 (numElements, 0);
2218 vector<float> inputFloats1 (numElements, 0);
2219 vector<float> inputFloats2 (numElements, 0);
2220 vector<float> inputFloats3 (numElements, 0);
2221 vector<float> inputFloats4 (numElements, 0);
2222 vector<float> outputFloats (numElements, 0);
2224 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats0[0], numElements);
2225 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats1[0], numElements);
2226 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats2[0], numElements);
2227 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats3[0], numElements);
2228 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats4[0], numElements);
2230 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
2231 floorAll(inputFloats0);
2232 floorAll(inputFloats1);
2233 floorAll(inputFloats2);
2234 floorAll(inputFloats3);
2235 floorAll(inputFloats4);
2237 for (size_t ndx = 0; ndx < numElements; ++ndx)
2238 outputFloats[ndx] = inputFloats0[ndx] + inputFloats1[ndx] + inputFloats2[ndx] + inputFloats3[ndx] + inputFloats4[ndx];
2241 string(getComputeAsmShaderPreamble()) +
2243 "OpSource GLSL 430\n"
2244 "OpName %main \"main\"\n"
2245 "OpName %id \"gl_GlobalInvocationID\"\n"
2247 // Not using group decoration on variable.
2248 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2249 // Not using group decoration on type.
2250 "OpDecorate %f32arr ArrayStride 4\n"
2252 "OpDecorate %groups BufferBlock\n"
2253 "OpDecorate %groupm Offset 0\n"
2254 "%groups = OpDecorationGroup\n"
2255 "%groupm = OpDecorationGroup\n"
2257 // Group decoration on multiple structs.
2258 "OpGroupDecorate %groups %outbuf %inbuf0 %inbuf1 %inbuf2 %inbuf3 %inbuf4\n"
2259 // Group decoration on multiple struct members.
2260 "OpGroupMemberDecorate %groupm %outbuf 0 %inbuf0 0 %inbuf1 0 %inbuf2 0 %inbuf3 0 %inbuf4 0\n"
2262 "OpDecorate %group1 DescriptorSet 0\n"
2263 "OpDecorate %group3 DescriptorSet 0\n"
2264 "OpDecorate %group3 NonWritable\n"
2265 "OpDecorate %group3 Restrict\n"
2266 "%group0 = OpDecorationGroup\n"
2267 "%group1 = OpDecorationGroup\n"
2268 "%group3 = OpDecorationGroup\n"
2270 // Applying the same decoration group multiple times.
2271 "OpGroupDecorate %group1 %outdata\n"
2272 "OpGroupDecorate %group1 %outdata\n"
2273 "OpGroupDecorate %group1 %outdata\n"
2274 "OpDecorate %outdata DescriptorSet 0\n"
2275 "OpDecorate %outdata Binding 5\n"
2276 // Applying decoration group containing nothing.
2277 "OpGroupDecorate %group0 %indata0\n"
2278 "OpDecorate %indata0 DescriptorSet 0\n"
2279 "OpDecorate %indata0 Binding 0\n"
2280 // Applying decoration group containing one decoration.
2281 "OpGroupDecorate %group1 %indata1\n"
2282 "OpDecorate %indata1 Binding 1\n"
2283 // Applying decoration group containing multiple decorations.
2284 "OpGroupDecorate %group3 %indata2 %indata3\n"
2285 "OpDecorate %indata2 Binding 2\n"
2286 "OpDecorate %indata3 Binding 3\n"
2287 // Applying multiple decoration groups (with overlapping).
2288 "OpGroupDecorate %group0 %indata4\n"
2289 "OpGroupDecorate %group1 %indata4\n"
2290 "OpGroupDecorate %group3 %indata4\n"
2291 "OpDecorate %indata4 Binding 4\n"
2293 + string(getComputeAsmCommonTypes()) +
2295 "%id = OpVariable %uvec3ptr Input\n"
2296 "%zero = OpConstant %i32 0\n"
2298 "%outbuf = OpTypeStruct %f32arr\n"
2299 "%outbufptr = OpTypePointer Uniform %outbuf\n"
2300 "%outdata = OpVariable %outbufptr Uniform\n"
2301 "%inbuf0 = OpTypeStruct %f32arr\n"
2302 "%inbuf0ptr = OpTypePointer Uniform %inbuf0\n"
2303 "%indata0 = OpVariable %inbuf0ptr Uniform\n"
2304 "%inbuf1 = OpTypeStruct %f32arr\n"
2305 "%inbuf1ptr = OpTypePointer Uniform %inbuf1\n"
2306 "%indata1 = OpVariable %inbuf1ptr Uniform\n"
2307 "%inbuf2 = OpTypeStruct %f32arr\n"
2308 "%inbuf2ptr = OpTypePointer Uniform %inbuf2\n"
2309 "%indata2 = OpVariable %inbuf2ptr Uniform\n"
2310 "%inbuf3 = OpTypeStruct %f32arr\n"
2311 "%inbuf3ptr = OpTypePointer Uniform %inbuf3\n"
2312 "%indata3 = OpVariable %inbuf3ptr Uniform\n"
2313 "%inbuf4 = OpTypeStruct %f32arr\n"
2314 "%inbufptr = OpTypePointer Uniform %inbuf4\n"
2315 "%indata4 = OpVariable %inbufptr Uniform\n"
2317 "%main = OpFunction %void None %voidf\n"
2318 "%label = OpLabel\n"
2319 "%idval = OpLoad %uvec3 %id\n"
2320 "%x = OpCompositeExtract %u32 %idval 0\n"
2321 "%inloc0 = OpAccessChain %f32ptr %indata0 %zero %x\n"
2322 "%inloc1 = OpAccessChain %f32ptr %indata1 %zero %x\n"
2323 "%inloc2 = OpAccessChain %f32ptr %indata2 %zero %x\n"
2324 "%inloc3 = OpAccessChain %f32ptr %indata3 %zero %x\n"
2325 "%inloc4 = OpAccessChain %f32ptr %indata4 %zero %x\n"
2326 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2327 "%inval0 = OpLoad %f32 %inloc0\n"
2328 "%inval1 = OpLoad %f32 %inloc1\n"
2329 "%inval2 = OpLoad %f32 %inloc2\n"
2330 "%inval3 = OpLoad %f32 %inloc3\n"
2331 "%inval4 = OpLoad %f32 %inloc4\n"
2332 "%add0 = OpFAdd %f32 %inval0 %inval1\n"
2333 "%add1 = OpFAdd %f32 %add0 %inval2\n"
2334 "%add2 = OpFAdd %f32 %add1 %inval3\n"
2335 "%add = OpFAdd %f32 %add2 %inval4\n"
2336 " OpStore %outloc %add\n"
2339 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats0)));
2340 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats1)));
2341 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
2342 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats3)));
2343 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats4)));
2344 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
2345 spec.numWorkGroups = IVec3(numElements, 1, 1);
2347 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "decoration group cases", spec));
2349 return group.release();
2352 struct SpecConstantTwoIntCase
2354 const char* caseName;
2355 const char* scDefinition0;
2356 const char* scDefinition1;
2357 const char* scResultType;
2358 const char* scOperation;
2359 deInt32 scActualValue0;
2360 deInt32 scActualValue1;
2361 const char* resultOperation;
2362 vector<deInt32> expectedOutput;
2364 SpecConstantTwoIntCase (const char* name,
2365 const char* definition0,
2366 const char* definition1,
2367 const char* resultType,
2368 const char* operation,
2371 const char* resultOp,
2372 const vector<deInt32>& output)
2374 , scDefinition0 (definition0)
2375 , scDefinition1 (definition1)
2376 , scResultType (resultType)
2377 , scOperation (operation)
2378 , scActualValue0 (value0)
2379 , scActualValue1 (value1)
2380 , resultOperation (resultOp)
2381 , expectedOutput (output) {}
2384 tcu::TestCaseGroup* createSpecConstantGroup (tcu::TestContext& testCtx)
2386 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opspecconstantop", "Test the OpSpecConstantOp instruction"));
2387 vector<SpecConstantTwoIntCase> cases;
2388 de::Random rnd (deStringHash(group->getName()));
2389 const int numElements = 100;
2390 vector<deInt32> inputInts (numElements, 0);
2391 vector<deInt32> outputInts1 (numElements, 0);
2392 vector<deInt32> outputInts2 (numElements, 0);
2393 vector<deInt32> outputInts3 (numElements, 0);
2394 vector<deInt32> outputInts4 (numElements, 0);
2395 const StringTemplate shaderTemplate (
2396 string(getComputeAsmShaderPreamble()) +
2398 "OpName %main \"main\"\n"
2399 "OpName %id \"gl_GlobalInvocationID\"\n"
2401 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2402 "OpDecorate %sc_0 SpecId 0\n"
2403 "OpDecorate %sc_1 SpecId 1\n"
2404 "OpDecorate %i32arr ArrayStride 4\n"
2406 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
2408 "%buf = OpTypeStruct %i32arr\n"
2409 "%bufptr = OpTypePointer Uniform %buf\n"
2410 "%indata = OpVariable %bufptr Uniform\n"
2411 "%outdata = OpVariable %bufptr Uniform\n"
2413 "%id = OpVariable %uvec3ptr Input\n"
2414 "%zero = OpConstant %i32 0\n"
2416 "%sc_0 = OpSpecConstant${SC_DEF0}\n"
2417 "%sc_1 = OpSpecConstant${SC_DEF1}\n"
2418 "%sc_final = OpSpecConstantOp ${SC_RESULT_TYPE} ${SC_OP}\n"
2420 "%main = OpFunction %void None %voidf\n"
2421 "%label = OpLabel\n"
2422 "%idval = OpLoad %uvec3 %id\n"
2423 "%x = OpCompositeExtract %u32 %idval 0\n"
2424 "%inloc = OpAccessChain %i32ptr %indata %zero %x\n"
2425 "%inval = OpLoad %i32 %inloc\n"
2426 "%final = ${GEN_RESULT}\n"
2427 "%outloc = OpAccessChain %i32ptr %outdata %zero %x\n"
2428 " OpStore %outloc %final\n"
2430 " OpFunctionEnd\n");
2432 fillRandomScalars(rnd, -65536, 65536, &inputInts[0], numElements);
2434 for (size_t ndx = 0; ndx < numElements; ++ndx)
2436 outputInts1[ndx] = inputInts[ndx] + 42;
2437 outputInts2[ndx] = inputInts[ndx];
2438 outputInts3[ndx] = inputInts[ndx] - 11200;
2439 outputInts4[ndx] = inputInts[ndx] + 1;
2442 const char addScToInput[] = "OpIAdd %i32 %inval %sc_final";
2443 const char selectTrueUsingSc[] = "OpSelect %i32 %sc_final %inval %zero";
2444 const char selectFalseUsingSc[] = "OpSelect %i32 %sc_final %zero %inval";
2446 cases.push_back(SpecConstantTwoIntCase("iadd", " %i32 0", " %i32 0", "%i32", "IAdd %sc_0 %sc_1", 62, -20, addScToInput, outputInts1));
2447 cases.push_back(SpecConstantTwoIntCase("isub", " %i32 0", " %i32 0", "%i32", "ISub %sc_0 %sc_1", 100, 58, addScToInput, outputInts1));
2448 cases.push_back(SpecConstantTwoIntCase("imul", " %i32 0", " %i32 0", "%i32", "IMul %sc_0 %sc_1", -2, -21, addScToInput, outputInts1));
2449 cases.push_back(SpecConstantTwoIntCase("sdiv", " %i32 0", " %i32 0", "%i32", "SDiv %sc_0 %sc_1", -126, -3, addScToInput, outputInts1));
2450 cases.push_back(SpecConstantTwoIntCase("udiv", " %i32 0", " %i32 0", "%i32", "UDiv %sc_0 %sc_1", 126, 3, addScToInput, outputInts1));
2451 cases.push_back(SpecConstantTwoIntCase("srem", " %i32 0", " %i32 0", "%i32", "SRem %sc_0 %sc_1", 7, 3, addScToInput, outputInts4));
2452 cases.push_back(SpecConstantTwoIntCase("smod", " %i32 0", " %i32 0", "%i32", "SMod %sc_0 %sc_1", 7, 3, addScToInput, outputInts4));
2453 cases.push_back(SpecConstantTwoIntCase("umod", " %i32 0", " %i32 0", "%i32", "UMod %sc_0 %sc_1", 342, 50, addScToInput, outputInts1));
2454 cases.push_back(SpecConstantTwoIntCase("bitwiseand", " %i32 0", " %i32 0", "%i32", "BitwiseAnd %sc_0 %sc_1", 42, 63, addScToInput, outputInts1));
2455 cases.push_back(SpecConstantTwoIntCase("bitwiseor", " %i32 0", " %i32 0", "%i32", "BitwiseOr %sc_0 %sc_1", 34, 8, addScToInput, outputInts1));
2456 cases.push_back(SpecConstantTwoIntCase("bitwisexor", " %i32 0", " %i32 0", "%i32", "BitwiseXor %sc_0 %sc_1", 18, 56, addScToInput, outputInts1));
2457 cases.push_back(SpecConstantTwoIntCase("shiftrightlogical", " %i32 0", " %i32 0", "%i32", "ShiftRightLogical %sc_0 %sc_1", 168, 2, addScToInput, outputInts1));
2458 cases.push_back(SpecConstantTwoIntCase("shiftrightarithmetic", " %i32 0", " %i32 0", "%i32", "ShiftRightArithmetic %sc_0 %sc_1", 168, 2, addScToInput, outputInts1));
2459 cases.push_back(SpecConstantTwoIntCase("shiftleftlogical", " %i32 0", " %i32 0", "%i32", "ShiftLeftLogical %sc_0 %sc_1", 21, 1, addScToInput, outputInts1));
2460 cases.push_back(SpecConstantTwoIntCase("slessthan", " %i32 0", " %i32 0", "%bool", "SLessThan %sc_0 %sc_1", -20, -10, selectTrueUsingSc, outputInts2));
2461 cases.push_back(SpecConstantTwoIntCase("ulessthan", " %i32 0", " %i32 0", "%bool", "ULessThan %sc_0 %sc_1", 10, 20, selectTrueUsingSc, outputInts2));
2462 cases.push_back(SpecConstantTwoIntCase("sgreaterthan", " %i32 0", " %i32 0", "%bool", "SGreaterThan %sc_0 %sc_1", -1000, 50, selectFalseUsingSc, outputInts2));
2463 cases.push_back(SpecConstantTwoIntCase("ugreaterthan", " %i32 0", " %i32 0", "%bool", "UGreaterThan %sc_0 %sc_1", 10, 5, selectTrueUsingSc, outputInts2));
2464 cases.push_back(SpecConstantTwoIntCase("slessthanequal", " %i32 0", " %i32 0", "%bool", "SLessThanEqual %sc_0 %sc_1", -10, -10, selectTrueUsingSc, outputInts2));
2465 cases.push_back(SpecConstantTwoIntCase("ulessthanequal", " %i32 0", " %i32 0", "%bool", "ULessThanEqual %sc_0 %sc_1", 50, 100, selectTrueUsingSc, outputInts2));
2466 cases.push_back(SpecConstantTwoIntCase("sgreaterthanequal", " %i32 0", " %i32 0", "%bool", "SGreaterThanEqual %sc_0 %sc_1", -1000, 50, selectFalseUsingSc, outputInts2));
2467 cases.push_back(SpecConstantTwoIntCase("ugreaterthanequal", " %i32 0", " %i32 0", "%bool", "UGreaterThanEqual %sc_0 %sc_1", 10, 10, selectTrueUsingSc, outputInts2));
2468 cases.push_back(SpecConstantTwoIntCase("iequal", " %i32 0", " %i32 0", "%bool", "IEqual %sc_0 %sc_1", 42, 24, selectFalseUsingSc, outputInts2));
2469 cases.push_back(SpecConstantTwoIntCase("logicaland", "True %bool", "True %bool", "%bool", "LogicalAnd %sc_0 %sc_1", 0, 1, selectFalseUsingSc, outputInts2));
2470 cases.push_back(SpecConstantTwoIntCase("logicalor", "False %bool", "False %bool", "%bool", "LogicalOr %sc_0 %sc_1", 1, 0, selectTrueUsingSc, outputInts2));
2471 cases.push_back(SpecConstantTwoIntCase("logicalequal", "True %bool", "True %bool", "%bool", "LogicalEqual %sc_0 %sc_1", 0, 1, selectFalseUsingSc, outputInts2));
2472 cases.push_back(SpecConstantTwoIntCase("logicalnotequal", "False %bool", "False %bool", "%bool", "LogicalNotEqual %sc_0 %sc_1", 1, 0, selectTrueUsingSc, outputInts2));
2473 cases.push_back(SpecConstantTwoIntCase("snegate", " %i32 0", " %i32 0", "%i32", "SNegate %sc_0", -42, 0, addScToInput, outputInts1));
2474 cases.push_back(SpecConstantTwoIntCase("not", " %i32 0", " %i32 0", "%i32", "Not %sc_0", -43, 0, addScToInput, outputInts1));
2475 cases.push_back(SpecConstantTwoIntCase("logicalnot", "False %bool", "False %bool", "%bool", "LogicalNot %sc_0", 1, 0, selectFalseUsingSc, outputInts2));
2476 cases.push_back(SpecConstantTwoIntCase("select", "False %bool", " %i32 0", "%i32", "Select %sc_0 %sc_1 %zero", 1, 42, addScToInput, outputInts1));
2477 // OpSConvert, OpFConvert: these two instructions involve ints/floats of different bitwidths.
2479 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
2481 map<string, string> specializations;
2482 ComputeShaderSpec spec;
2484 specializations["SC_DEF0"] = cases[caseNdx].scDefinition0;
2485 specializations["SC_DEF1"] = cases[caseNdx].scDefinition1;
2486 specializations["SC_RESULT_TYPE"] = cases[caseNdx].scResultType;
2487 specializations["SC_OP"] = cases[caseNdx].scOperation;
2488 specializations["GEN_RESULT"] = cases[caseNdx].resultOperation;
2490 spec.assembly = shaderTemplate.specialize(specializations);
2491 spec.inputs.push_back(BufferSp(new Int32Buffer(inputInts)));
2492 spec.outputs.push_back(BufferSp(new Int32Buffer(cases[caseNdx].expectedOutput)));
2493 spec.numWorkGroups = IVec3(numElements, 1, 1);
2494 spec.specConstants.push_back(cases[caseNdx].scActualValue0);
2495 spec.specConstants.push_back(cases[caseNdx].scActualValue1);
2497 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].caseName, cases[caseNdx].caseName, spec));
2500 ComputeShaderSpec spec;
2503 string(getComputeAsmShaderPreamble()) +
2505 "OpName %main \"main\"\n"
2506 "OpName %id \"gl_GlobalInvocationID\"\n"
2508 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2509 "OpDecorate %sc_0 SpecId 0\n"
2510 "OpDecorate %sc_1 SpecId 1\n"
2511 "OpDecorate %sc_2 SpecId 2\n"
2512 "OpDecorate %i32arr ArrayStride 4\n"
2514 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
2516 "%ivec3 = OpTypeVector %i32 3\n"
2517 "%buf = OpTypeStruct %i32arr\n"
2518 "%bufptr = OpTypePointer Uniform %buf\n"
2519 "%indata = OpVariable %bufptr Uniform\n"
2520 "%outdata = OpVariable %bufptr Uniform\n"
2522 "%id = OpVariable %uvec3ptr Input\n"
2523 "%zero = OpConstant %i32 0\n"
2524 "%ivec3_0 = OpConstantComposite %ivec3 %zero %zero %zero\n"
2525 "%vec3_undef = OpUndef %ivec3\n"
2527 "%sc_0 = OpSpecConstant %i32 0\n"
2528 "%sc_1 = OpSpecConstant %i32 0\n"
2529 "%sc_2 = OpSpecConstant %i32 0\n"
2530 "%sc_vec3_0 = OpSpecConstantOp %ivec3 CompositeInsert %sc_0 %ivec3_0 0\n" // (sc_0, 0, 0)
2531 "%sc_vec3_1 = OpSpecConstantOp %ivec3 CompositeInsert %sc_1 %ivec3_0 1\n" // (0, sc_1, 0)
2532 "%sc_vec3_2 = OpSpecConstantOp %ivec3 CompositeInsert %sc_2 %ivec3_0 2\n" // (0, 0, sc_2)
2533 "%sc_vec3_0_s = OpSpecConstantOp %ivec3 VectorShuffle %sc_vec3_0 %vec3_undef 0 0xFFFFFFFF 2\n" // (sc_0, ???, 0)
2534 "%sc_vec3_1_s = OpSpecConstantOp %ivec3 VectorShuffle %sc_vec3_1 %vec3_undef 0xFFFFFFFF 1 0\n" // (???, sc_1, 0)
2535 "%sc_vec3_2_s = OpSpecConstantOp %ivec3 VectorShuffle %vec3_undef %sc_vec3_2 5 0xFFFFFFFF 5\n" // (sc_2, ???, sc_2)
2536 "%sc_vec3_01 = OpSpecConstantOp %ivec3 VectorShuffle %sc_vec3_0_s %sc_vec3_1_s 1 0 4\n" // (0, sc_0, sc_1)
2537 "%sc_vec3_012 = OpSpecConstantOp %ivec3 VectorShuffle %sc_vec3_01 %sc_vec3_2_s 5 1 2\n" // (sc_2, sc_0, sc_1)
2538 "%sc_ext_0 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 0\n" // sc_2
2539 "%sc_ext_1 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 1\n" // sc_0
2540 "%sc_ext_2 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 2\n" // sc_1
2541 "%sc_sub = OpSpecConstantOp %i32 ISub %sc_ext_0 %sc_ext_1\n" // (sc_2 - sc_0)
2542 "%sc_final = OpSpecConstantOp %i32 IMul %sc_sub %sc_ext_2\n" // (sc_2 - sc_0) * sc_1
2544 "%main = OpFunction %void None %voidf\n"
2545 "%label = OpLabel\n"
2546 "%idval = OpLoad %uvec3 %id\n"
2547 "%x = OpCompositeExtract %u32 %idval 0\n"
2548 "%inloc = OpAccessChain %i32ptr %indata %zero %x\n"
2549 "%inval = OpLoad %i32 %inloc\n"
2550 "%final = OpIAdd %i32 %inval %sc_final\n"
2551 "%outloc = OpAccessChain %i32ptr %outdata %zero %x\n"
2552 " OpStore %outloc %final\n"
2555 spec.inputs.push_back(BufferSp(new Int32Buffer(inputInts)));
2556 spec.outputs.push_back(BufferSp(new Int32Buffer(outputInts3)));
2557 spec.numWorkGroups = IVec3(numElements, 1, 1);
2558 spec.specConstants.push_back(123);
2559 spec.specConstants.push_back(56);
2560 spec.specConstants.push_back(-77);
2562 group->addChild(new SpvAsmComputeShaderCase(testCtx, "vector_related", "VectorShuffle, CompositeExtract, & CompositeInsert", spec));
2564 return group.release();
2567 void createOpPhiVartypeTests (de::MovePtr<tcu::TestCaseGroup>& group, tcu::TestContext& testCtx)
2569 ComputeShaderSpec specInt;
2570 ComputeShaderSpec specFloat;
2571 ComputeShaderSpec specVec3;
2572 ComputeShaderSpec specMat4;
2573 ComputeShaderSpec specArray;
2574 ComputeShaderSpec specStruct;
2575 de::Random rnd (deStringHash(group->getName()));
2576 const int numElements = 100;
2577 vector<float> inputFloats (numElements, 0);
2578 vector<float> outputFloats (numElements, 0);
2580 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats[0], numElements);
2582 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
2583 floorAll(inputFloats);
2585 for (size_t ndx = 0; ndx < numElements; ++ndx)
2587 // Just check if the value is positive or not
2588 outputFloats[ndx] = (inputFloats[ndx] > 0) ? 1.0f : -1.0f;
2591 // All of the tests are of the form:
2595 // if (inputdata > 0)
2602 specFloat.assembly =
2603 string(getComputeAsmShaderPreamble()) +
2605 "OpSource GLSL 430\n"
2606 "OpName %main \"main\"\n"
2607 "OpName %id \"gl_GlobalInvocationID\"\n"
2609 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2611 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
2613 "%id = OpVariable %uvec3ptr Input\n"
2614 "%zero = OpConstant %i32 0\n"
2615 "%float_0 = OpConstant %f32 0.0\n"
2616 "%float_1 = OpConstant %f32 1.0\n"
2617 "%float_n1 = OpConstant %f32 -1.0\n"
2619 "%main = OpFunction %void None %voidf\n"
2620 "%entry = OpLabel\n"
2621 "%idval = OpLoad %uvec3 %id\n"
2622 "%x = OpCompositeExtract %u32 %idval 0\n"
2623 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
2624 "%inval = OpLoad %f32 %inloc\n"
2626 "%comp = OpFOrdGreaterThan %bool %inval %float_0\n"
2627 " OpSelectionMerge %cm None\n"
2628 " OpBranchConditional %comp %tb %fb\n"
2634 "%res = OpPhi %f32 %float_1 %tb %float_n1 %fb\n"
2636 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2637 " OpStore %outloc %res\n"
2641 specFloat.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
2642 specFloat.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
2643 specFloat.numWorkGroups = IVec3(numElements, 1, 1);
2646 string(getComputeAsmShaderPreamble()) +
2648 "OpSource GLSL 430\n"
2649 "OpName %main \"main\"\n"
2650 "OpName %id \"gl_GlobalInvocationID\"\n"
2652 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2654 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
2656 "%id = OpVariable %uvec3ptr Input\n"
2657 "%v4f32 = OpTypeVector %f32 4\n"
2658 "%mat4v4f32 = OpTypeMatrix %v4f32 4\n"
2659 "%zero = OpConstant %i32 0\n"
2660 "%float_0 = OpConstant %f32 0.0\n"
2661 "%float_1 = OpConstant %f32 1.0\n"
2662 "%float_n1 = OpConstant %f32 -1.0\n"
2663 "%m11 = OpConstantComposite %v4f32 %float_1 %float_0 %float_0 %float_0\n"
2664 "%m12 = OpConstantComposite %v4f32 %float_0 %float_1 %float_0 %float_0\n"
2665 "%m13 = OpConstantComposite %v4f32 %float_0 %float_0 %float_1 %float_0\n"
2666 "%m14 = OpConstantComposite %v4f32 %float_0 %float_0 %float_0 %float_1\n"
2667 "%m1 = OpConstantComposite %mat4v4f32 %m11 %m12 %m13 %m14\n"
2668 "%m21 = OpConstantComposite %v4f32 %float_n1 %float_0 %float_0 %float_0\n"
2669 "%m22 = OpConstantComposite %v4f32 %float_0 %float_n1 %float_0 %float_0\n"
2670 "%m23 = OpConstantComposite %v4f32 %float_0 %float_0 %float_n1 %float_0\n"
2671 "%m24 = OpConstantComposite %v4f32 %float_0 %float_0 %float_0 %float_n1\n"
2672 "%m2 = OpConstantComposite %mat4v4f32 %m21 %m22 %m23 %m24\n"
2674 "%main = OpFunction %void None %voidf\n"
2675 "%entry = OpLabel\n"
2676 "%idval = OpLoad %uvec3 %id\n"
2677 "%x = OpCompositeExtract %u32 %idval 0\n"
2678 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
2679 "%inval = OpLoad %f32 %inloc\n"
2681 "%comp = OpFOrdGreaterThan %bool %inval %float_0\n"
2682 " OpSelectionMerge %cm None\n"
2683 " OpBranchConditional %comp %tb %fb\n"
2689 "%mres = OpPhi %mat4v4f32 %m1 %tb %m2 %fb\n"
2690 "%res = OpCompositeExtract %f32 %mres 2 2\n"
2692 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2693 " OpStore %outloc %res\n"
2697 specMat4.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
2698 specMat4.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
2699 specMat4.numWorkGroups = IVec3(numElements, 1, 1);
2702 string(getComputeAsmShaderPreamble()) +
2704 "OpSource GLSL 430\n"
2705 "OpName %main \"main\"\n"
2706 "OpName %id \"gl_GlobalInvocationID\"\n"
2708 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2710 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
2712 "%id = OpVariable %uvec3ptr Input\n"
2713 "%v3f32 = OpTypeVector %f32 3\n"
2714 "%zero = OpConstant %i32 0\n"
2715 "%float_0 = OpConstant %f32 0.0\n"
2716 "%float_1 = OpConstant %f32 1.0\n"
2717 "%float_n1 = OpConstant %f32 -1.0\n"
2718 "%v1 = OpConstantComposite %v3f32 %float_1 %float_1 %float_1\n"
2719 "%v2 = OpConstantComposite %v3f32 %float_n1 %float_n1 %float_n1\n"
2721 "%main = OpFunction %void None %voidf\n"
2722 "%entry = OpLabel\n"
2723 "%idval = OpLoad %uvec3 %id\n"
2724 "%x = OpCompositeExtract %u32 %idval 0\n"
2725 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
2726 "%inval = OpLoad %f32 %inloc\n"
2728 "%comp = OpFOrdGreaterThan %bool %inval %float_0\n"
2729 " OpSelectionMerge %cm None\n"
2730 " OpBranchConditional %comp %tb %fb\n"
2736 "%vres = OpPhi %v3f32 %v1 %tb %v2 %fb\n"
2737 "%res = OpCompositeExtract %f32 %vres 2\n"
2739 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2740 " OpStore %outloc %res\n"
2744 specVec3.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
2745 specVec3.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
2746 specVec3.numWorkGroups = IVec3(numElements, 1, 1);
2749 string(getComputeAsmShaderPreamble()) +
2751 "OpSource GLSL 430\n"
2752 "OpName %main \"main\"\n"
2753 "OpName %id \"gl_GlobalInvocationID\"\n"
2755 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2757 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
2759 "%id = OpVariable %uvec3ptr Input\n"
2760 "%zero = OpConstant %i32 0\n"
2761 "%float_0 = OpConstant %f32 0.0\n"
2762 "%i1 = OpConstant %i32 1\n"
2763 "%i2 = OpConstant %i32 -1\n"
2765 "%main = OpFunction %void None %voidf\n"
2766 "%entry = OpLabel\n"
2767 "%idval = OpLoad %uvec3 %id\n"
2768 "%x = OpCompositeExtract %u32 %idval 0\n"
2769 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
2770 "%inval = OpLoad %f32 %inloc\n"
2772 "%comp = OpFOrdGreaterThan %bool %inval %float_0\n"
2773 " OpSelectionMerge %cm None\n"
2774 " OpBranchConditional %comp %tb %fb\n"
2780 "%ires = OpPhi %i32 %i1 %tb %i2 %fb\n"
2781 "%res = OpConvertSToF %f32 %ires\n"
2783 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2784 " OpStore %outloc %res\n"
2788 specInt.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
2789 specInt.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
2790 specInt.numWorkGroups = IVec3(numElements, 1, 1);
2792 specArray.assembly =
2793 string(getComputeAsmShaderPreamble()) +
2795 "OpSource GLSL 430\n"
2796 "OpName %main \"main\"\n"
2797 "OpName %id \"gl_GlobalInvocationID\"\n"
2799 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2801 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
2803 "%id = OpVariable %uvec3ptr Input\n"
2804 "%zero = OpConstant %i32 0\n"
2805 "%u7 = OpConstant %u32 7\n"
2806 "%float_0 = OpConstant %f32 0.0\n"
2807 "%float_1 = OpConstant %f32 1.0\n"
2808 "%float_n1 = OpConstant %f32 -1.0\n"
2809 "%f32a7 = OpTypeArray %f32 %u7\n"
2810 "%a1 = OpConstantComposite %f32a7 %float_1 %float_1 %float_1 %float_1 %float_1 %float_1 %float_1\n"
2811 "%a2 = OpConstantComposite %f32a7 %float_n1 %float_n1 %float_n1 %float_n1 %float_n1 %float_n1 %float_n1\n"
2812 "%main = OpFunction %void None %voidf\n"
2813 "%entry = OpLabel\n"
2814 "%idval = OpLoad %uvec3 %id\n"
2815 "%x = OpCompositeExtract %u32 %idval 0\n"
2816 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
2817 "%inval = OpLoad %f32 %inloc\n"
2819 "%comp = OpFOrdGreaterThan %bool %inval %float_0\n"
2820 " OpSelectionMerge %cm None\n"
2821 " OpBranchConditional %comp %tb %fb\n"
2827 "%ares = OpPhi %f32a7 %a1 %tb %a2 %fb\n"
2828 "%res = OpCompositeExtract %f32 %ares 5\n"
2830 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2831 " OpStore %outloc %res\n"
2835 specArray.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
2836 specArray.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
2837 specArray.numWorkGroups = IVec3(numElements, 1, 1);
2839 specStruct.assembly =
2840 string(getComputeAsmShaderPreamble()) +
2842 "OpSource GLSL 430\n"
2843 "OpName %main \"main\"\n"
2844 "OpName %id \"gl_GlobalInvocationID\"\n"
2846 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2848 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
2850 "%id = OpVariable %uvec3ptr Input\n"
2851 "%v3f32 = OpTypeVector %f32 3\n"
2852 "%zero = OpConstant %i32 0\n"
2853 "%float_0 = OpConstant %f32 0.0\n"
2854 "%float_1 = OpConstant %f32 1.0\n"
2855 "%float_n1 = OpConstant %f32 -1.0\n"
2857 "%v2f32 = OpTypeVector %f32 2\n"
2858 "%Data2 = OpTypeStruct %f32 %v2f32\n"
2859 "%Data = OpTypeStruct %Data2 %f32\n"
2861 "%in1a = OpConstantComposite %v2f32 %float_1 %float_1\n"
2862 "%in1b = OpConstantComposite %Data2 %float_1 %in1a\n"
2863 "%s1 = OpConstantComposite %Data %in1b %float_1\n"
2864 "%in2a = OpConstantComposite %v2f32 %float_n1 %float_n1\n"
2865 "%in2b = OpConstantComposite %Data2 %float_n1 %in2a\n"
2866 "%s2 = OpConstantComposite %Data %in2b %float_n1\n"
2868 "%main = OpFunction %void None %voidf\n"
2869 "%entry = OpLabel\n"
2870 "%idval = OpLoad %uvec3 %id\n"
2871 "%x = OpCompositeExtract %u32 %idval 0\n"
2872 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
2873 "%inval = OpLoad %f32 %inloc\n"
2875 "%comp = OpFOrdGreaterThan %bool %inval %float_0\n"
2876 " OpSelectionMerge %cm None\n"
2877 " OpBranchConditional %comp %tb %fb\n"
2883 "%sres = OpPhi %Data %s1 %tb %s2 %fb\n"
2884 "%res = OpCompositeExtract %f32 %sres 0 0\n"
2886 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2887 " OpStore %outloc %res\n"
2891 specStruct.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
2892 specStruct.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
2893 specStruct.numWorkGroups = IVec3(numElements, 1, 1);
2895 group->addChild(new SpvAsmComputeShaderCase(testCtx, "vartype_int", "OpPhi with int variables", specInt));
2896 group->addChild(new SpvAsmComputeShaderCase(testCtx, "vartype_float", "OpPhi with float variables", specFloat));
2897 group->addChild(new SpvAsmComputeShaderCase(testCtx, "vartype_vec3", "OpPhi with vec3 variables", specVec3));
2898 group->addChild(new SpvAsmComputeShaderCase(testCtx, "vartype_mat4", "OpPhi with mat4 variables", specMat4));
2899 group->addChild(new SpvAsmComputeShaderCase(testCtx, "vartype_array", "OpPhi with array variables", specArray));
2900 group->addChild(new SpvAsmComputeShaderCase(testCtx, "vartype_struct", "OpPhi with struct variables", specStruct));
2903 string generateConstantDefinitions (int count)
2905 std::ostringstream r;
2906 for (int i = 0; i < count; i++)
2907 r << "%cf" << (i * 10 + 5) << " = OpConstant %f32 " <<(i * 10 + 5) << ".0\n";
2912 string generateSwitchCases (int count)
2914 std::ostringstream r;
2915 for (int i = 0; i < count; i++)
2916 r << " " << i << " %case" << i;
2921 string generateSwitchTargets (int count)
2923 std::ostringstream r;
2924 for (int i = 0; i < count; i++)
2925 r << "%case" << i << " = OpLabel\n OpBranch %phi\n";
2930 string generateOpPhiParams (int count)
2932 std::ostringstream r;
2933 for (int i = 0; i < count; i++)
2934 r << " %cf" << (i * 10 + 5) << " %case" << i;
2939 string generateIntWidth (int value)
2941 std::ostringstream r;
2946 // Expand input string by injecting "ABC" between the input
2947 // string characters. The acc/add/treshold parameters are used
2948 // to skip some of the injections to make the result less
2949 // uniform (and a lot shorter).
2950 string expandOpPhiCase5 (const string& s, int &acc, int add, int treshold)
2952 std::ostringstream res;
2953 const char* p = s.c_str();
2969 // Calculate expected result based on the code string
2970 float calcOpPhiCase5 (float val, const string& s)
2972 const char* p = s.c_str();
2975 const float tv[8] = { 0.5f, 1.5f, 3.5f, 7.5f, 15.5f, 31.5f, 63.5f, 127.5f };
2976 const float v = deFloatAbs(val);
2981 for (int i = 7; i >= 0; --i)
2982 x[i] = std::fmod((float)v, (float)(2 << i));
2983 for (int i = 7; i >= 0; --i)
2984 b[i] = x[i] > tv[i];
2991 if (skip == 0 && b[depth])
3002 if (b[depth] || skip)
3016 // In the code string, the letters represent the following:
3019 // if (certain bit is set)
3030 // AABCBC leads to if(){r++;if(){r++;}else{}}else{}
3031 // ABABCC leads to if(){r++;}else{if(){r++;}else{}}
3032 // ABCABC leads to if(){r++;}else{}if(){r++;}else{}
3034 // Code generation gets a bit complicated due to the else-branches,
3035 // which do not generate new values. Thus, the generator needs to
3036 // keep track of the previous variable change seen by the else
3038 string generateOpPhiCase5 (const string& s)
3040 std::stack<int> idStack;
3041 std::stack<std::string> value;
3042 std::stack<std::string> valueLabel;
3043 std::stack<std::string> mergeLeft;
3044 std::stack<std::string> mergeRight;
3045 std::ostringstream res;
3046 const char* p = s.c_str();
3052 value.push("%f32_0");
3053 valueLabel.push("%f32_0 %entry");
3061 idStack.push(currId);
3062 res << "\tOpSelectionMerge %m" << currId << " None\n";
3063 res << "\tOpBranchConditional %b" << depth << " %t" << currId << " %f" << currId << "\n";
3064 res << "%t" << currId << " = OpLabel\n";
3065 res << "%rt" << currId << " = OpFAdd %f32 " << value.top() << " %f32_1\n";
3066 std::ostringstream tag;
3067 tag << "%rt" << currId;
3068 value.push(tag.str());
3069 tag << " %t" << currId;
3070 valueLabel.push(tag.str());
3075 mergeLeft.push(valueLabel.top());
3078 res << "\tOpBranch %m" << currId << "\n";
3079 res << "%f" << currId << " = OpLabel\n";
3080 std::ostringstream tag;
3081 tag << value.top() << " %f" << currId;
3083 valueLabel.push(tag.str());
3088 mergeRight.push(valueLabel.top());
3089 res << "\tOpBranch %m" << currId << "\n";
3090 res << "%m" << currId << " = OpLabel\n";
3092 res << "%res"; // last result goes to %res
3094 res << "%rm" << currId;
3095 res << " = OpPhi %f32 " << mergeLeft.top() << " " << mergeRight.top() << "\n";
3096 std::ostringstream tag;
3097 tag << "%rm" << currId;
3099 value.push(tag.str());
3100 tag << " %m" << currId;
3102 valueLabel.push(tag.str());
3107 currId = idStack.top();
3115 tcu::TestCaseGroup* createOpPhiGroup (tcu::TestContext& testCtx)
3117 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opphi", "Test the OpPhi instruction"));
3118 ComputeShaderSpec spec1;
3119 ComputeShaderSpec spec2;
3120 ComputeShaderSpec spec3;
3121 ComputeShaderSpec spec4;
3122 ComputeShaderSpec spec5;
3123 de::Random rnd (deStringHash(group->getName()));
3124 const int numElements = 100;
3125 vector<float> inputFloats (numElements, 0);
3126 vector<float> outputFloats1 (numElements, 0);
3127 vector<float> outputFloats2 (numElements, 0);
3128 vector<float> outputFloats3 (numElements, 0);
3129 vector<float> outputFloats4 (numElements, 0);
3130 vector<float> outputFloats5 (numElements, 0);
3131 std::string codestring = "ABC";
3132 const int test4Width = 1024;
3134 // Build case 5 code string. Each iteration makes the hierarchy more complicated.
3135 // 9 iterations with (7, 24) parameters makes the hierarchy 8 deep with about 1500 lines of
3137 for (int i = 0, acc = 0; i < 9; i++)
3138 codestring = expandOpPhiCase5(codestring, acc, 7, 24);
3140 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats[0], numElements);
3142 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
3143 floorAll(inputFloats);
3145 for (size_t ndx = 0; ndx < numElements; ++ndx)
3149 case 0: outputFloats1[ndx] = inputFloats[ndx] + 5.5f; break;
3150 case 1: outputFloats1[ndx] = inputFloats[ndx] + 20.5f; break;
3151 case 2: outputFloats1[ndx] = inputFloats[ndx] + 1.75f; break;
3154 outputFloats2[ndx] = inputFloats[ndx] + 6.5f * 3;
3155 outputFloats3[ndx] = 8.5f - inputFloats[ndx];
3157 int index4 = (int)deFloor(deAbs((float)ndx * inputFloats[ndx]));
3158 outputFloats4[ndx] = (float)(index4 % test4Width) * 10.0f + 5.0f;
3160 outputFloats5[ndx] = calcOpPhiCase5(inputFloats[ndx], codestring);
3164 string(getComputeAsmShaderPreamble()) +
3166 "OpSource GLSL 430\n"
3167 "OpName %main \"main\"\n"
3168 "OpName %id \"gl_GlobalInvocationID\"\n"
3170 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3172 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
3174 "%id = OpVariable %uvec3ptr Input\n"
3175 "%zero = OpConstant %i32 0\n"
3176 "%three = OpConstant %u32 3\n"
3177 "%constf5p5 = OpConstant %f32 5.5\n"
3178 "%constf20p5 = OpConstant %f32 20.5\n"
3179 "%constf1p75 = OpConstant %f32 1.75\n"
3180 "%constf8p5 = OpConstant %f32 8.5\n"
3181 "%constf6p5 = OpConstant %f32 6.5\n"
3183 "%main = OpFunction %void None %voidf\n"
3184 "%entry = OpLabel\n"
3185 "%idval = OpLoad %uvec3 %id\n"
3186 "%x = OpCompositeExtract %u32 %idval 0\n"
3187 "%selector = OpUMod %u32 %x %three\n"
3188 " OpSelectionMerge %phi None\n"
3189 " OpSwitch %selector %default 0 %case0 1 %case1 2 %case2\n"
3191 // Case 1 before OpPhi.
3192 "%case1 = OpLabel\n"
3195 "%default = OpLabel\n"
3199 "%operand = OpPhi %f32 %constf1p75 %case2 %constf20p5 %case1 %constf5p5 %case0\n" // not in the order of blocks
3200 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3201 "%inval = OpLoad %f32 %inloc\n"
3202 "%add = OpFAdd %f32 %inval %operand\n"
3203 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3204 " OpStore %outloc %add\n"
3207 // Case 0 after OpPhi.
3208 "%case0 = OpLabel\n"
3212 // Case 2 after OpPhi.
3213 "%case2 = OpLabel\n"
3217 spec1.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
3218 spec1.outputs.push_back(BufferSp(new Float32Buffer(outputFloats1)));
3219 spec1.numWorkGroups = IVec3(numElements, 1, 1);
3221 group->addChild(new SpvAsmComputeShaderCase(testCtx, "block", "out-of-order and unreachable blocks for OpPhi", spec1));
3224 string(getComputeAsmShaderPreamble()) +
3226 "OpName %main \"main\"\n"
3227 "OpName %id \"gl_GlobalInvocationID\"\n"
3229 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3231 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
3233 "%id = OpVariable %uvec3ptr Input\n"
3234 "%zero = OpConstant %i32 0\n"
3235 "%one = OpConstant %i32 1\n"
3236 "%three = OpConstant %i32 3\n"
3237 "%constf6p5 = OpConstant %f32 6.5\n"
3239 "%main = OpFunction %void None %voidf\n"
3240 "%entry = OpLabel\n"
3241 "%idval = OpLoad %uvec3 %id\n"
3242 "%x = OpCompositeExtract %u32 %idval 0\n"
3243 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3244 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3245 "%inval = OpLoad %f32 %inloc\n"
3249 "%step = OpPhi %i32 %zero %entry %step_next %phi\n"
3250 "%accum = OpPhi %f32 %inval %entry %accum_next %phi\n"
3251 "%step_next = OpIAdd %i32 %step %one\n"
3252 "%accum_next = OpFAdd %f32 %accum %constf6p5\n"
3253 "%still_loop = OpSLessThan %bool %step %three\n"
3254 " OpLoopMerge %exit %phi None\n"
3255 " OpBranchConditional %still_loop %phi %exit\n"
3258 " OpStore %outloc %accum\n"
3261 spec2.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
3262 spec2.outputs.push_back(BufferSp(new Float32Buffer(outputFloats2)));
3263 spec2.numWorkGroups = IVec3(numElements, 1, 1);
3265 group->addChild(new SpvAsmComputeShaderCase(testCtx, "induction", "The usual way induction variables are handled in LLVM IR", spec2));
3268 string(getComputeAsmShaderPreamble()) +
3270 "OpName %main \"main\"\n"
3271 "OpName %id \"gl_GlobalInvocationID\"\n"
3273 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3275 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
3277 "%f32ptr_f = OpTypePointer Function %f32\n"
3278 "%id = OpVariable %uvec3ptr Input\n"
3279 "%true = OpConstantTrue %bool\n"
3280 "%false = OpConstantFalse %bool\n"
3281 "%zero = OpConstant %i32 0\n"
3282 "%constf8p5 = OpConstant %f32 8.5\n"
3284 "%main = OpFunction %void None %voidf\n"
3285 "%entry = OpLabel\n"
3286 "%b = OpVariable %f32ptr_f Function %constf8p5\n"
3287 "%idval = OpLoad %uvec3 %id\n"
3288 "%x = OpCompositeExtract %u32 %idval 0\n"
3289 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3290 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3291 "%a_init = OpLoad %f32 %inloc\n"
3292 "%b_init = OpLoad %f32 %b\n"
3296 "%still_loop = OpPhi %bool %true %entry %false %phi\n"
3297 "%a_next = OpPhi %f32 %a_init %entry %b_next %phi\n"
3298 "%b_next = OpPhi %f32 %b_init %entry %a_next %phi\n"
3299 " OpLoopMerge %exit %phi None\n"
3300 " OpBranchConditional %still_loop %phi %exit\n"
3303 "%sub = OpFSub %f32 %a_next %b_next\n"
3304 " OpStore %outloc %sub\n"
3307 spec3.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
3308 spec3.outputs.push_back(BufferSp(new Float32Buffer(outputFloats3)));
3309 spec3.numWorkGroups = IVec3(numElements, 1, 1);
3311 group->addChild(new SpvAsmComputeShaderCase(testCtx, "swap", "Swap the values of two variables using OpPhi", spec3));
3314 "OpCapability Shader\n"
3315 "%ext = OpExtInstImport \"GLSL.std.450\"\n"
3316 "OpMemoryModel Logical GLSL450\n"
3317 "OpEntryPoint GLCompute %main \"main\" %id\n"
3318 "OpExecutionMode %main LocalSize 1 1 1\n"
3320 "OpSource GLSL 430\n"
3321 "OpName %main \"main\"\n"
3322 "OpName %id \"gl_GlobalInvocationID\"\n"
3324 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3326 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
3328 "%id = OpVariable %uvec3ptr Input\n"
3329 "%zero = OpConstant %i32 0\n"
3330 "%cimod = OpConstant %u32 " + generateIntWidth(test4Width) + "\n"
3332 + generateConstantDefinitions(test4Width) +
3334 "%main = OpFunction %void None %voidf\n"
3335 "%entry = OpLabel\n"
3336 "%idval = OpLoad %uvec3 %id\n"
3337 "%x = OpCompositeExtract %u32 %idval 0\n"
3338 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3339 "%inval = OpLoad %f32 %inloc\n"
3340 "%xf = OpConvertUToF %f32 %x\n"
3341 "%xm = OpFMul %f32 %xf %inval\n"
3342 "%xa = OpExtInst %f32 %ext FAbs %xm\n"
3343 "%xi = OpConvertFToU %u32 %xa\n"
3344 "%selector = OpUMod %u32 %xi %cimod\n"
3345 " OpSelectionMerge %phi None\n"
3346 " OpSwitch %selector %default "
3348 + generateSwitchCases(test4Width) +
3350 "%default = OpLabel\n"
3353 + generateSwitchTargets(test4Width) +
3356 "%result = OpPhi %f32"
3358 + generateOpPhiParams(test4Width) +
3360 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3361 " OpStore %outloc %result\n"
3365 spec4.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
3366 spec4.outputs.push_back(BufferSp(new Float32Buffer(outputFloats4)));
3367 spec4.numWorkGroups = IVec3(numElements, 1, 1);
3369 group->addChild(new SpvAsmComputeShaderCase(testCtx, "wide", "OpPhi with a lot of parameters", spec4));
3372 "OpCapability Shader\n"
3373 "%ext = OpExtInstImport \"GLSL.std.450\"\n"
3374 "OpMemoryModel Logical GLSL450\n"
3375 "OpEntryPoint GLCompute %main \"main\" %id\n"
3376 "OpExecutionMode %main LocalSize 1 1 1\n"
3377 "%code = OpString \"" + codestring + "\"\n"
3379 "OpSource GLSL 430\n"
3380 "OpName %main \"main\"\n"
3381 "OpName %id \"gl_GlobalInvocationID\"\n"
3383 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3385 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
3387 "%id = OpVariable %uvec3ptr Input\n"
3388 "%zero = OpConstant %i32 0\n"
3389 "%f32_0 = OpConstant %f32 0.0\n"
3390 "%f32_0_5 = OpConstant %f32 0.5\n"
3391 "%f32_1 = OpConstant %f32 1.0\n"
3392 "%f32_1_5 = OpConstant %f32 1.5\n"
3393 "%f32_2 = OpConstant %f32 2.0\n"
3394 "%f32_3_5 = OpConstant %f32 3.5\n"
3395 "%f32_4 = OpConstant %f32 4.0\n"
3396 "%f32_7_5 = OpConstant %f32 7.5\n"
3397 "%f32_8 = OpConstant %f32 8.0\n"
3398 "%f32_15_5 = OpConstant %f32 15.5\n"
3399 "%f32_16 = OpConstant %f32 16.0\n"
3400 "%f32_31_5 = OpConstant %f32 31.5\n"
3401 "%f32_32 = OpConstant %f32 32.0\n"
3402 "%f32_63_5 = OpConstant %f32 63.5\n"
3403 "%f32_64 = OpConstant %f32 64.0\n"
3404 "%f32_127_5 = OpConstant %f32 127.5\n"
3405 "%f32_128 = OpConstant %f32 128.0\n"
3406 "%f32_256 = OpConstant %f32 256.0\n"
3408 "%main = OpFunction %void None %voidf\n"
3409 "%entry = OpLabel\n"
3410 "%idval = OpLoad %uvec3 %id\n"
3411 "%x = OpCompositeExtract %u32 %idval 0\n"
3412 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3413 "%inval = OpLoad %f32 %inloc\n"
3415 "%xabs = OpExtInst %f32 %ext FAbs %inval\n"
3416 "%x8 = OpFMod %f32 %xabs %f32_256\n"
3417 "%x7 = OpFMod %f32 %xabs %f32_128\n"
3418 "%x6 = OpFMod %f32 %xabs %f32_64\n"
3419 "%x5 = OpFMod %f32 %xabs %f32_32\n"
3420 "%x4 = OpFMod %f32 %xabs %f32_16\n"
3421 "%x3 = OpFMod %f32 %xabs %f32_8\n"
3422 "%x2 = OpFMod %f32 %xabs %f32_4\n"
3423 "%x1 = OpFMod %f32 %xabs %f32_2\n"
3425 "%b7 = OpFOrdGreaterThanEqual %bool %x8 %f32_127_5\n"
3426 "%b6 = OpFOrdGreaterThanEqual %bool %x7 %f32_63_5\n"
3427 "%b5 = OpFOrdGreaterThanEqual %bool %x6 %f32_31_5\n"
3428 "%b4 = OpFOrdGreaterThanEqual %bool %x5 %f32_15_5\n"
3429 "%b3 = OpFOrdGreaterThanEqual %bool %x4 %f32_7_5\n"
3430 "%b2 = OpFOrdGreaterThanEqual %bool %x3 %f32_3_5\n"
3431 "%b1 = OpFOrdGreaterThanEqual %bool %x2 %f32_1_5\n"
3432 "%b0 = OpFOrdGreaterThanEqual %bool %x1 %f32_0_5\n"
3434 + generateOpPhiCase5(codestring) +
3436 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3437 " OpStore %outloc %res\n"
3441 spec5.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
3442 spec5.outputs.push_back(BufferSp(new Float32Buffer(outputFloats5)));
3443 spec5.numWorkGroups = IVec3(numElements, 1, 1);
3445 group->addChild(new SpvAsmComputeShaderCase(testCtx, "nested", "Stress OpPhi with a lot of nesting", spec5));
3447 createOpPhiVartypeTests(group, testCtx);
3449 return group.release();
3452 // Assembly code used for testing block order is based on GLSL source code:
3456 // layout(std140, set = 0, binding = 0) readonly buffer Input {
3457 // float elements[];
3459 // layout(std140, set = 0, binding = 1) writeonly buffer Output {
3460 // float elements[];
3464 // uint x = gl_GlobalInvocationID.x;
3465 // output_data.elements[x] = input_data.elements[x];
3466 // if (x > uint(50)) {
3467 // switch (x % uint(3)) {
3468 // case 0: output_data.elements[x] += 1.5f; break;
3469 // case 1: output_data.elements[x] += 42.f; break;
3470 // case 2: output_data.elements[x] -= 27.f; break;
3474 // output_data.elements[x] = -input_data.elements[x];
3477 tcu::TestCaseGroup* createBlockOrderGroup (tcu::TestContext& testCtx)
3479 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "block_order", "Test block orders"));
3480 ComputeShaderSpec spec;
3481 de::Random rnd (deStringHash(group->getName()));
3482 const int numElements = 100;
3483 vector<float> inputFloats (numElements, 0);
3484 vector<float> outputFloats (numElements, 0);
3486 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats[0], numElements);
3488 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
3489 floorAll(inputFloats);
3491 for (size_t ndx = 0; ndx <= 50; ++ndx)
3492 outputFloats[ndx] = -inputFloats[ndx];
3494 for (size_t ndx = 51; ndx < numElements; ++ndx)
3498 case 0: outputFloats[ndx] = inputFloats[ndx] + 1.5f; break;
3499 case 1: outputFloats[ndx] = inputFloats[ndx] + 42.f; break;
3500 case 2: outputFloats[ndx] = inputFloats[ndx] - 27.f; break;
3506 string(getComputeAsmShaderPreamble()) +
3508 "OpSource GLSL 430\n"
3509 "OpName %main \"main\"\n"
3510 "OpName %id \"gl_GlobalInvocationID\"\n"
3512 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3514 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
3516 "%u32ptr = OpTypePointer Function %u32\n"
3517 "%u32ptr_input = OpTypePointer Input %u32\n"
3519 + string(getComputeAsmInputOutputBuffer()) +
3521 "%id = OpVariable %uvec3ptr Input\n"
3522 "%zero = OpConstant %i32 0\n"
3523 "%const3 = OpConstant %u32 3\n"
3524 "%const50 = OpConstant %u32 50\n"
3525 "%constf1p5 = OpConstant %f32 1.5\n"
3526 "%constf27 = OpConstant %f32 27.0\n"
3527 "%constf42 = OpConstant %f32 42.0\n"
3529 "%main = OpFunction %void None %voidf\n"
3532 "%entry = OpLabel\n"
3534 // Create a temporary variable to hold the value of gl_GlobalInvocationID.x.
3535 "%xvar = OpVariable %u32ptr Function\n"
3536 "%xptr = OpAccessChain %u32ptr_input %id %zero\n"
3537 "%x = OpLoad %u32 %xptr\n"
3538 " OpStore %xvar %x\n"
3540 "%cmp = OpUGreaterThan %bool %x %const50\n"
3541 " OpSelectionMerge %if_merge None\n"
3542 " OpBranchConditional %cmp %if_true %if_false\n"
3544 // False branch for if-statement: placed in the middle of switch cases and before true branch.
3545 "%if_false = OpLabel\n"
3546 "%x_f = OpLoad %u32 %xvar\n"
3547 "%inloc_f = OpAccessChain %f32ptr %indata %zero %x_f\n"
3548 "%inval_f = OpLoad %f32 %inloc_f\n"
3549 "%negate = OpFNegate %f32 %inval_f\n"
3550 "%outloc_f = OpAccessChain %f32ptr %outdata %zero %x_f\n"
3551 " OpStore %outloc_f %negate\n"
3552 " OpBranch %if_merge\n"
3554 // Merge block for if-statement: placed in the middle of true and false branch.
3555 "%if_merge = OpLabel\n"
3558 // True branch for if-statement: placed in the middle of swtich cases and after the false branch.
3559 "%if_true = OpLabel\n"
3560 "%xval_t = OpLoad %u32 %xvar\n"
3561 "%mod = OpUMod %u32 %xval_t %const3\n"
3562 " OpSelectionMerge %switch_merge None\n"
3563 " OpSwitch %mod %default 0 %case0 1 %case1 2 %case2\n"
3565 // Merge block for switch-statement: placed before the case
3566 // bodies. But it must follow OpSwitch which dominates it.
3567 "%switch_merge = OpLabel\n"
3568 " OpBranch %if_merge\n"
3570 // Case 1 for switch-statement: placed before case 0.
3571 // It must follow the OpSwitch that dominates it.
3572 "%case1 = OpLabel\n"
3573 "%x_1 = OpLoad %u32 %xvar\n"
3574 "%inloc_1 = OpAccessChain %f32ptr %indata %zero %x_1\n"
3575 "%inval_1 = OpLoad %f32 %inloc_1\n"
3576 "%addf42 = OpFAdd %f32 %inval_1 %constf42\n"
3577 "%outloc_1 = OpAccessChain %f32ptr %outdata %zero %x_1\n"
3578 " OpStore %outloc_1 %addf42\n"
3579 " OpBranch %switch_merge\n"
3581 // Case 2 for switch-statement.
3582 "%case2 = OpLabel\n"
3583 "%x_2 = OpLoad %u32 %xvar\n"
3584 "%inloc_2 = OpAccessChain %f32ptr %indata %zero %x_2\n"
3585 "%inval_2 = OpLoad %f32 %inloc_2\n"
3586 "%subf27 = OpFSub %f32 %inval_2 %constf27\n"
3587 "%outloc_2 = OpAccessChain %f32ptr %outdata %zero %x_2\n"
3588 " OpStore %outloc_2 %subf27\n"
3589 " OpBranch %switch_merge\n"
3591 // Default case for switch-statement: placed in the middle of normal cases.
3592 "%default = OpLabel\n"
3593 " OpBranch %switch_merge\n"
3595 // Case 0 for switch-statement: out of order.
3596 "%case0 = OpLabel\n"
3597 "%x_0 = OpLoad %u32 %xvar\n"
3598 "%inloc_0 = OpAccessChain %f32ptr %indata %zero %x_0\n"
3599 "%inval_0 = OpLoad %f32 %inloc_0\n"
3600 "%addf1p5 = OpFAdd %f32 %inval_0 %constf1p5\n"
3601 "%outloc_0 = OpAccessChain %f32ptr %outdata %zero %x_0\n"
3602 " OpStore %outloc_0 %addf1p5\n"
3603 " OpBranch %switch_merge\n"
3606 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
3607 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
3608 spec.numWorkGroups = IVec3(numElements, 1, 1);
3610 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "various out-of-order blocks", spec));
3612 return group.release();
3615 tcu::TestCaseGroup* createMultipleShaderGroup (tcu::TestContext& testCtx)
3617 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "multiple_shaders", "Test multiple shaders in the same module"));
3618 ComputeShaderSpec spec1;
3619 ComputeShaderSpec spec2;
3620 de::Random rnd (deStringHash(group->getName()));
3621 const int numElements = 100;
3622 vector<float> inputFloats (numElements, 0);
3623 vector<float> outputFloats1 (numElements, 0);
3624 vector<float> outputFloats2 (numElements, 0);
3625 fillRandomScalars(rnd, -500.f, 500.f, &inputFloats[0], numElements);
3627 for (size_t ndx = 0; ndx < numElements; ++ndx)
3629 outputFloats1[ndx] = inputFloats[ndx] + inputFloats[ndx];
3630 outputFloats2[ndx] = -inputFloats[ndx];
3633 const string assembly(
3634 "OpCapability Shader\n"
3635 "OpCapability ClipDistance\n"
3636 "OpMemoryModel Logical GLSL450\n"
3637 "OpEntryPoint GLCompute %comp_main1 \"entrypoint1\" %id\n"
3638 "OpEntryPoint GLCompute %comp_main2 \"entrypoint2\" %id\n"
3639 // A module cannot have two OpEntryPoint instructions with the same Execution Model and the same Name string.
3640 "OpEntryPoint Vertex %vert_main \"entrypoint2\" %vert_builtins %vertexIndex %instanceIndex\n"
3641 "OpExecutionMode %comp_main1 LocalSize 1 1 1\n"
3642 "OpExecutionMode %comp_main2 LocalSize 1 1 1\n"
3644 "OpName %comp_main1 \"entrypoint1\"\n"
3645 "OpName %comp_main2 \"entrypoint2\"\n"
3646 "OpName %vert_main \"entrypoint2\"\n"
3647 "OpName %id \"gl_GlobalInvocationID\"\n"
3648 "OpName %vert_builtin_st \"gl_PerVertex\"\n"
3649 "OpName %vertexIndex \"gl_VertexIndex\"\n"
3650 "OpName %instanceIndex \"gl_InstanceIndex\"\n"
3651 "OpMemberName %vert_builtin_st 0 \"gl_Position\"\n"
3652 "OpMemberName %vert_builtin_st 1 \"gl_PointSize\"\n"
3653 "OpMemberName %vert_builtin_st 2 \"gl_ClipDistance\"\n"
3655 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3656 "OpDecorate %vertexIndex BuiltIn VertexIndex\n"
3657 "OpDecorate %instanceIndex BuiltIn InstanceIndex\n"
3658 "OpDecorate %vert_builtin_st Block\n"
3659 "OpMemberDecorate %vert_builtin_st 0 BuiltIn Position\n"
3660 "OpMemberDecorate %vert_builtin_st 1 BuiltIn PointSize\n"
3661 "OpMemberDecorate %vert_builtin_st 2 BuiltIn ClipDistance\n"
3663 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
3665 "%zero = OpConstant %i32 0\n"
3666 "%one = OpConstant %u32 1\n"
3667 "%c_f32_1 = OpConstant %f32 1\n"
3669 "%i32inputptr = OpTypePointer Input %i32\n"
3670 "%vec4 = OpTypeVector %f32 4\n"
3671 "%vec4ptr = OpTypePointer Output %vec4\n"
3672 "%f32arr1 = OpTypeArray %f32 %one\n"
3673 "%vert_builtin_st = OpTypeStruct %vec4 %f32 %f32arr1\n"
3674 "%vert_builtin_st_ptr = OpTypePointer Output %vert_builtin_st\n"
3675 "%vert_builtins = OpVariable %vert_builtin_st_ptr Output\n"
3677 "%id = OpVariable %uvec3ptr Input\n"
3678 "%vertexIndex = OpVariable %i32inputptr Input\n"
3679 "%instanceIndex = OpVariable %i32inputptr Input\n"
3680 "%c_vec4_1 = OpConstantComposite %vec4 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_1\n"
3682 // gl_Position = vec4(1.);
3683 "%vert_main = OpFunction %void None %voidf\n"
3684 "%vert_entry = OpLabel\n"
3685 "%position = OpAccessChain %vec4ptr %vert_builtins %zero\n"
3686 " OpStore %position %c_vec4_1\n"
3691 "%comp_main1 = OpFunction %void None %voidf\n"
3692 "%comp1_entry = OpLabel\n"
3693 "%idval1 = OpLoad %uvec3 %id\n"
3694 "%x1 = OpCompositeExtract %u32 %idval1 0\n"
3695 "%inloc1 = OpAccessChain %f32ptr %indata %zero %x1\n"
3696 "%inval1 = OpLoad %f32 %inloc1\n"
3697 "%add = OpFAdd %f32 %inval1 %inval1\n"
3698 "%outloc1 = OpAccessChain %f32ptr %outdata %zero %x1\n"
3699 " OpStore %outloc1 %add\n"
3704 "%comp_main2 = OpFunction %void None %voidf\n"
3705 "%comp2_entry = OpLabel\n"
3706 "%idval2 = OpLoad %uvec3 %id\n"
3707 "%x2 = OpCompositeExtract %u32 %idval2 0\n"
3708 "%inloc2 = OpAccessChain %f32ptr %indata %zero %x2\n"
3709 "%inval2 = OpLoad %f32 %inloc2\n"
3710 "%neg = OpFNegate %f32 %inval2\n"
3711 "%outloc2 = OpAccessChain %f32ptr %outdata %zero %x2\n"
3712 " OpStore %outloc2 %neg\n"
3714 " OpFunctionEnd\n");
3716 spec1.assembly = assembly;
3717 spec1.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
3718 spec1.outputs.push_back(BufferSp(new Float32Buffer(outputFloats1)));
3719 spec1.numWorkGroups = IVec3(numElements, 1, 1);
3720 spec1.entryPoint = "entrypoint1";
3722 spec2.assembly = assembly;
3723 spec2.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
3724 spec2.outputs.push_back(BufferSp(new Float32Buffer(outputFloats2)));
3725 spec2.numWorkGroups = IVec3(numElements, 1, 1);
3726 spec2.entryPoint = "entrypoint2";
3728 group->addChild(new SpvAsmComputeShaderCase(testCtx, "shader1", "multiple shaders in the same module", spec1));
3729 group->addChild(new SpvAsmComputeShaderCase(testCtx, "shader2", "multiple shaders in the same module", spec2));
3731 return group.release();
3734 inline std::string makeLongUTF8String (size_t num4ByteChars)
3736 // An example of a longest valid UTF-8 character. Be explicit about the
3737 // character type because Microsoft compilers can otherwise interpret the
3738 // character string as being over wide (16-bit) characters. Ideally, we
3739 // would just use a C++11 UTF-8 string literal, but we want to support older
3740 // Microsoft compilers.
3741 const std::basic_string<char> earthAfrica("\xF0\x9F\x8C\x8D");
3742 std::string longString;
3743 longString.reserve(num4ByteChars * 4);
3744 for (size_t count = 0; count < num4ByteChars; count++)
3746 longString += earthAfrica;
3751 tcu::TestCaseGroup* createOpSourceGroup (tcu::TestContext& testCtx)
3753 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opsource", "Tests the OpSource & OpSourceContinued instruction"));
3754 vector<CaseParameter> cases;
3755 de::Random rnd (deStringHash(group->getName()));
3756 const int numElements = 100;
3757 vector<float> positiveFloats (numElements, 0);
3758 vector<float> negativeFloats (numElements, 0);
3759 const StringTemplate shaderTemplate (
3760 "OpCapability Shader\n"
3761 "OpMemoryModel Logical GLSL450\n"
3763 "OpEntryPoint GLCompute %main \"main\" %id\n"
3764 "OpExecutionMode %main LocalSize 1 1 1\n"
3768 "OpName %main \"main\"\n"
3769 "OpName %id \"gl_GlobalInvocationID\"\n"
3771 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3773 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
3775 "%id = OpVariable %uvec3ptr Input\n"
3776 "%zero = OpConstant %i32 0\n"
3778 "%main = OpFunction %void None %voidf\n"
3779 "%label = OpLabel\n"
3780 "%idval = OpLoad %uvec3 %id\n"
3781 "%x = OpCompositeExtract %u32 %idval 0\n"
3782 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3783 "%inval = OpLoad %f32 %inloc\n"
3784 "%neg = OpFNegate %f32 %inval\n"
3785 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3786 " OpStore %outloc %neg\n"
3788 " OpFunctionEnd\n");
3790 cases.push_back(CaseParameter("unknown_source", "OpSource Unknown 0"));
3791 cases.push_back(CaseParameter("wrong_source", "OpSource OpenCL_C 210"));
3792 cases.push_back(CaseParameter("normal_filename", "%fname = OpString \"filename\"\n"
3793 "OpSource GLSL 430 %fname"));
3794 cases.push_back(CaseParameter("empty_filename", "%fname = OpString \"\"\n"
3795 "OpSource GLSL 430 %fname"));
3796 cases.push_back(CaseParameter("normal_source_code", "%fname = OpString \"filename\"\n"
3797 "OpSource GLSL 430 %fname \"#version 430\nvoid main() {}\""));
3798 cases.push_back(CaseParameter("empty_source_code", "%fname = OpString \"filename\"\n"
3799 "OpSource GLSL 430 %fname \"\""));
3800 cases.push_back(CaseParameter("long_source_code", "%fname = OpString \"filename\"\n"
3801 "OpSource GLSL 430 %fname \"" + makeLongUTF8String(65530) + "ccc\"")); // word count: 65535
3802 cases.push_back(CaseParameter("utf8_source_code", "%fname = OpString \"filename\"\n"
3803 "OpSource GLSL 430 %fname \"\xE2\x98\x82\xE2\x98\x85\"")); // umbrella & black star symbol
3804 cases.push_back(CaseParameter("normal_sourcecontinued", "%fname = OpString \"filename\"\n"
3805 "OpSource GLSL 430 %fname \"#version 430\nvo\"\n"
3806 "OpSourceContinued \"id main() {}\""));
3807 cases.push_back(CaseParameter("empty_sourcecontinued", "%fname = OpString \"filename\"\n"
3808 "OpSource GLSL 430 %fname \"#version 430\nvoid main() {}\"\n"
3809 "OpSourceContinued \"\""));
3810 cases.push_back(CaseParameter("long_sourcecontinued", "%fname = OpString \"filename\"\n"
3811 "OpSource GLSL 430 %fname \"#version 430\nvoid main() {}\"\n"
3812 "OpSourceContinued \"" + makeLongUTF8String(65533) + "ccc\"")); // word count: 65535
3813 cases.push_back(CaseParameter("utf8_sourcecontinued", "%fname = OpString \"filename\"\n"
3814 "OpSource GLSL 430 %fname \"#version 430\nvoid main() {}\"\n"
3815 "OpSourceContinued \"\xE2\x98\x8E\xE2\x9A\x91\"")); // white telephone & black flag symbol
3816 cases.push_back(CaseParameter("multi_sourcecontinued", "%fname = OpString \"filename\"\n"
3817 "OpSource GLSL 430 %fname \"#version 430\n\"\n"
3818 "OpSourceContinued \"void\"\n"
3819 "OpSourceContinued \"main()\"\n"
3820 "OpSourceContinued \"{}\""));
3821 cases.push_back(CaseParameter("empty_source_before_sourcecontinued", "%fname = OpString \"filename\"\n"
3822 "OpSource GLSL 430 %fname \"\"\n"
3823 "OpSourceContinued \"#version 430\nvoid main() {}\""));
3825 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
3827 for (size_t ndx = 0; ndx < numElements; ++ndx)
3828 negativeFloats[ndx] = -positiveFloats[ndx];
3830 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
3832 map<string, string> specializations;
3833 ComputeShaderSpec spec;
3835 specializations["SOURCE"] = cases[caseNdx].param;
3836 spec.assembly = shaderTemplate.specialize(specializations);
3837 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
3838 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
3839 spec.numWorkGroups = IVec3(numElements, 1, 1);
3841 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
3844 return group.release();
3847 tcu::TestCaseGroup* createOpSourceExtensionGroup (tcu::TestContext& testCtx)
3849 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opsourceextension", "Tests the OpSource instruction"));
3850 vector<CaseParameter> cases;
3851 de::Random rnd (deStringHash(group->getName()));
3852 const int numElements = 100;
3853 vector<float> inputFloats (numElements, 0);
3854 vector<float> outputFloats (numElements, 0);
3855 const StringTemplate shaderTemplate (
3856 string(getComputeAsmShaderPreamble()) +
3858 "OpSourceExtension \"${EXTENSION}\"\n"
3860 "OpName %main \"main\"\n"
3861 "OpName %id \"gl_GlobalInvocationID\"\n"
3863 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3865 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
3867 "%id = OpVariable %uvec3ptr Input\n"
3868 "%zero = OpConstant %i32 0\n"
3870 "%main = OpFunction %void None %voidf\n"
3871 "%label = OpLabel\n"
3872 "%idval = OpLoad %uvec3 %id\n"
3873 "%x = OpCompositeExtract %u32 %idval 0\n"
3874 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3875 "%inval = OpLoad %f32 %inloc\n"
3876 "%neg = OpFNegate %f32 %inval\n"
3877 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3878 " OpStore %outloc %neg\n"
3880 " OpFunctionEnd\n");
3882 cases.push_back(CaseParameter("empty_extension", ""));
3883 cases.push_back(CaseParameter("real_extension", "GL_ARB_texture_rectangle"));
3884 cases.push_back(CaseParameter("fake_extension", "GL_ARB_im_the_ultimate_extension"));
3885 cases.push_back(CaseParameter("utf8_extension", "GL_ARB_\xE2\x98\x82\xE2\x98\x85"));
3886 cases.push_back(CaseParameter("long_extension", makeLongUTF8String(65533) + "ccc")); // word count: 65535
3888 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats[0], numElements);
3890 for (size_t ndx = 0; ndx < numElements; ++ndx)
3891 outputFloats[ndx] = -inputFloats[ndx];
3893 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
3895 map<string, string> specializations;
3896 ComputeShaderSpec spec;
3898 specializations["EXTENSION"] = cases[caseNdx].param;
3899 spec.assembly = shaderTemplate.specialize(specializations);
3900 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
3901 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
3902 spec.numWorkGroups = IVec3(numElements, 1, 1);
3904 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
3907 return group.release();
3910 // Checks that a compute shader can generate a constant null value of various types, without exercising a computation on it.
3911 tcu::TestCaseGroup* createOpConstantNullGroup (tcu::TestContext& testCtx)
3913 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opconstantnull", "Tests the OpConstantNull instruction"));
3914 vector<CaseParameter> cases;
3915 de::Random rnd (deStringHash(group->getName()));
3916 const int numElements = 100;
3917 vector<float> positiveFloats (numElements, 0);
3918 vector<float> negativeFloats (numElements, 0);
3919 const StringTemplate shaderTemplate (
3920 string(getComputeAsmShaderPreamble()) +
3922 "OpSource GLSL 430\n"
3923 "OpName %main \"main\"\n"
3924 "OpName %id \"gl_GlobalInvocationID\"\n"
3926 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3928 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
3929 "%uvec2 = OpTypeVector %u32 2\n"
3930 "%bvec3 = OpTypeVector %bool 3\n"
3931 "%fvec4 = OpTypeVector %f32 4\n"
3932 "%fmat33 = OpTypeMatrix %fvec3 3\n"
3933 "%const100 = OpConstant %u32 100\n"
3934 "%uarr100 = OpTypeArray %i32 %const100\n"
3935 "%struct = OpTypeStruct %f32 %i32 %u32\n"
3936 "%pointer = OpTypePointer Function %i32\n"
3937 + string(getComputeAsmInputOutputBuffer()) +
3939 "%null = OpConstantNull ${TYPE}\n"
3941 "%id = OpVariable %uvec3ptr Input\n"
3942 "%zero = OpConstant %i32 0\n"
3944 "%main = OpFunction %void None %voidf\n"
3945 "%label = OpLabel\n"
3946 "%idval = OpLoad %uvec3 %id\n"
3947 "%x = OpCompositeExtract %u32 %idval 0\n"
3948 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3949 "%inval = OpLoad %f32 %inloc\n"
3950 "%neg = OpFNegate %f32 %inval\n"
3951 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3952 " OpStore %outloc %neg\n"
3954 " OpFunctionEnd\n");
3956 cases.push_back(CaseParameter("bool", "%bool"));
3957 cases.push_back(CaseParameter("sint32", "%i32"));
3958 cases.push_back(CaseParameter("uint32", "%u32"));
3959 cases.push_back(CaseParameter("float32", "%f32"));
3960 cases.push_back(CaseParameter("vec4float32", "%fvec4"));
3961 cases.push_back(CaseParameter("vec3bool", "%bvec3"));
3962 cases.push_back(CaseParameter("vec2uint32", "%uvec2"));
3963 cases.push_back(CaseParameter("matrix", "%fmat33"));
3964 cases.push_back(CaseParameter("array", "%uarr100"));
3965 cases.push_back(CaseParameter("struct", "%struct"));
3966 cases.push_back(CaseParameter("pointer", "%pointer"));
3968 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
3970 for (size_t ndx = 0; ndx < numElements; ++ndx)
3971 negativeFloats[ndx] = -positiveFloats[ndx];
3973 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
3975 map<string, string> specializations;
3976 ComputeShaderSpec spec;
3978 specializations["TYPE"] = cases[caseNdx].param;
3979 spec.assembly = shaderTemplate.specialize(specializations);
3980 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
3981 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
3982 spec.numWorkGroups = IVec3(numElements, 1, 1);
3984 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
3987 return group.release();
3990 // Checks that a compute shader can generate a constant composite value of various types, without exercising a computation on it.
3991 tcu::TestCaseGroup* createOpConstantCompositeGroup (tcu::TestContext& testCtx)
3993 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opconstantcomposite", "Tests the OpConstantComposite instruction"));
3994 vector<CaseParameter> cases;
3995 de::Random rnd (deStringHash(group->getName()));
3996 const int numElements = 100;
3997 vector<float> positiveFloats (numElements, 0);
3998 vector<float> negativeFloats (numElements, 0);
3999 const StringTemplate shaderTemplate (
4000 string(getComputeAsmShaderPreamble()) +
4002 "OpSource GLSL 430\n"
4003 "OpName %main \"main\"\n"
4004 "OpName %id \"gl_GlobalInvocationID\"\n"
4006 "OpDecorate %id BuiltIn GlobalInvocationId\n"
4008 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
4010 "%id = OpVariable %uvec3ptr Input\n"
4011 "%zero = OpConstant %i32 0\n"
4015 "%main = OpFunction %void None %voidf\n"
4016 "%label = OpLabel\n"
4017 "%idval = OpLoad %uvec3 %id\n"
4018 "%x = OpCompositeExtract %u32 %idval 0\n"
4019 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
4020 "%inval = OpLoad %f32 %inloc\n"
4021 "%neg = OpFNegate %f32 %inval\n"
4022 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
4023 " OpStore %outloc %neg\n"
4025 " OpFunctionEnd\n");
4027 cases.push_back(CaseParameter("vector", "%five = OpConstant %u32 5\n"
4028 "%const = OpConstantComposite %uvec3 %five %zero %five"));
4029 cases.push_back(CaseParameter("matrix", "%m3fvec3 = OpTypeMatrix %fvec3 3\n"
4030 "%ten = OpConstant %f32 10.\n"
4031 "%fzero = OpConstant %f32 0.\n"
4032 "%vec = OpConstantComposite %fvec3 %ten %fzero %ten\n"
4033 "%mat = OpConstantComposite %m3fvec3 %vec %vec %vec"));
4034 cases.push_back(CaseParameter("struct", "%m2vec3 = OpTypeMatrix %fvec3 2\n"
4035 "%struct = OpTypeStruct %i32 %f32 %fvec3 %m2vec3\n"
4036 "%fzero = OpConstant %f32 0.\n"
4037 "%one = OpConstant %f32 1.\n"
4038 "%point5 = OpConstant %f32 0.5\n"
4039 "%vec = OpConstantComposite %fvec3 %one %one %fzero\n"
4040 "%mat = OpConstantComposite %m2vec3 %vec %vec\n"
4041 "%const = OpConstantComposite %struct %zero %point5 %vec %mat"));
4042 cases.push_back(CaseParameter("nested_struct", "%st1 = OpTypeStruct %u32 %f32\n"
4043 "%st2 = OpTypeStruct %i32 %i32\n"
4044 "%struct = OpTypeStruct %st1 %st2\n"
4045 "%point5 = OpConstant %f32 0.5\n"
4046 "%one = OpConstant %u32 1\n"
4047 "%ten = OpConstant %i32 10\n"
4048 "%st1val = OpConstantComposite %st1 %one %point5\n"
4049 "%st2val = OpConstantComposite %st2 %ten %ten\n"
4050 "%const = OpConstantComposite %struct %st1val %st2val"));
4052 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
4054 for (size_t ndx = 0; ndx < numElements; ++ndx)
4055 negativeFloats[ndx] = -positiveFloats[ndx];
4057 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
4059 map<string, string> specializations;
4060 ComputeShaderSpec spec;
4062 specializations["CONSTANT"] = cases[caseNdx].param;
4063 spec.assembly = shaderTemplate.specialize(specializations);
4064 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
4065 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
4066 spec.numWorkGroups = IVec3(numElements, 1, 1);
4068 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
4071 return group.release();
4074 // Creates a floating point number with the given exponent, and significand
4075 // bits set. It can only create normalized numbers. Only the least significant
4076 // 24 bits of the significand will be examined. The final bit of the
4077 // significand will also be ignored. This allows alignment to be written
4078 // similarly to C99 hex-floats.
4079 // For example if you wanted to write 0x1.7f34p-12 you would call
4080 // constructNormalizedFloat(-12, 0x7f3400)
4081 float constructNormalizedFloat (deInt32 exponent, deUint32 significand)
4085 for (deInt32 idx = 0; idx < 23; ++idx)
4087 f += ((significand & 0x800000) == 0) ? 0.f : std::ldexp(1.0f, -(idx + 1));
4091 return std::ldexp(f, exponent);
4094 // Compare instruction for the OpQuantizeF16 compute exact case.
4095 // Returns true if the output is what is expected from the test case.
4096 bool compareOpQuantizeF16ComputeExactCase (const std::vector<BufferSp>&, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs, TestLog&)
4098 if (outputAllocs.size() != 1)
4101 // Only size is needed because we cannot compare Nans.
4102 size_t byteSize = expectedOutputs[0]->getByteSize();
4104 const float* outputAsFloat = static_cast<const float*>(outputAllocs[0]->getHostPtr());
4106 if (byteSize != 4*sizeof(float)) {
4110 if (*outputAsFloat != constructNormalizedFloat(8, 0x304000) &&
4111 *outputAsFloat != constructNormalizedFloat(8, 0x300000)) {
4116 if (*outputAsFloat != -constructNormalizedFloat(-7, 0x600000) &&
4117 *outputAsFloat != -constructNormalizedFloat(-7, 0x604000)) {
4122 if (*outputAsFloat != constructNormalizedFloat(2, 0x01C000) &&
4123 *outputAsFloat != constructNormalizedFloat(2, 0x020000)) {
4128 if (*outputAsFloat != constructNormalizedFloat(1, 0xFFC000) &&
4129 *outputAsFloat != constructNormalizedFloat(2, 0x000000)) {
4136 // Checks that every output from a test-case is a float NaN.
4137 bool compareNan (const std::vector<BufferSp>&, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs, TestLog&)
4139 if (outputAllocs.size() != 1)
4142 // Only size is needed because we cannot compare Nans.
4143 size_t byteSize = expectedOutputs[0]->getByteSize();
4145 const float* const output_as_float = static_cast<const float* const>(outputAllocs[0]->getHostPtr());
4147 for (size_t idx = 0; idx < byteSize / sizeof(float); ++idx)
4149 if (!deFloatIsNaN(output_as_float[idx]))
4158 // Checks that a compute shader can generate a constant composite value of various types, without exercising a computation on it.
4159 tcu::TestCaseGroup* createOpQuantizeToF16Group (tcu::TestContext& testCtx)
4161 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opquantize", "Tests the OpQuantizeToF16 instruction"));
4163 const std::string shader (
4164 string(getComputeAsmShaderPreamble()) +
4166 "OpSource GLSL 430\n"
4167 "OpName %main \"main\"\n"
4168 "OpName %id \"gl_GlobalInvocationID\"\n"
4170 "OpDecorate %id BuiltIn GlobalInvocationId\n"
4172 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
4174 "%id = OpVariable %uvec3ptr Input\n"
4175 "%zero = OpConstant %i32 0\n"
4177 "%main = OpFunction %void None %voidf\n"
4178 "%label = OpLabel\n"
4179 "%idval = OpLoad %uvec3 %id\n"
4180 "%x = OpCompositeExtract %u32 %idval 0\n"
4181 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
4182 "%inval = OpLoad %f32 %inloc\n"
4183 "%quant = OpQuantizeToF16 %f32 %inval\n"
4184 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
4185 " OpStore %outloc %quant\n"
4187 " OpFunctionEnd\n");
4190 ComputeShaderSpec spec;
4191 const deUint32 numElements = 100;
4192 vector<float> infinities;
4193 vector<float> results;
4195 infinities.reserve(numElements);
4196 results.reserve(numElements);
4198 for (size_t idx = 0; idx < numElements; ++idx)
4203 infinities.push_back(std::numeric_limits<float>::infinity());
4204 results.push_back(std::numeric_limits<float>::infinity());
4207 infinities.push_back(-std::numeric_limits<float>::infinity());
4208 results.push_back(-std::numeric_limits<float>::infinity());
4211 infinities.push_back(std::ldexp(1.0f, 16));
4212 results.push_back(std::numeric_limits<float>::infinity());
4215 infinities.push_back(std::ldexp(-1.0f, 32));
4216 results.push_back(-std::numeric_limits<float>::infinity());
4221 spec.assembly = shader;
4222 spec.inputs.push_back(BufferSp(new Float32Buffer(infinities)));
4223 spec.outputs.push_back(BufferSp(new Float32Buffer(results)));
4224 spec.numWorkGroups = IVec3(numElements, 1, 1);
4226 group->addChild(new SpvAsmComputeShaderCase(
4227 testCtx, "infinities", "Check that infinities propagated and created", spec));
4231 ComputeShaderSpec spec;
4233 const deUint32 numElements = 100;
4235 nans.reserve(numElements);
4237 for (size_t idx = 0; idx < numElements; ++idx)
4241 nans.push_back(std::numeric_limits<float>::quiet_NaN());
4245 nans.push_back(-std::numeric_limits<float>::quiet_NaN());
4249 spec.assembly = shader;
4250 spec.inputs.push_back(BufferSp(new Float32Buffer(nans)));
4251 spec.outputs.push_back(BufferSp(new Float32Buffer(nans)));
4252 spec.numWorkGroups = IVec3(numElements, 1, 1);
4253 spec.verifyIO = &compareNan;
4255 group->addChild(new SpvAsmComputeShaderCase(
4256 testCtx, "propagated_nans", "Check that nans are propagated", spec));
4260 ComputeShaderSpec spec;
4261 vector<float> small;
4262 vector<float> zeros;
4263 const deUint32 numElements = 100;
4265 small.reserve(numElements);
4266 zeros.reserve(numElements);
4268 for (size_t idx = 0; idx < numElements; ++idx)
4273 small.push_back(0.f);
4274 zeros.push_back(0.f);
4277 small.push_back(-0.f);
4278 zeros.push_back(-0.f);
4281 small.push_back(std::ldexp(1.0f, -16));
4282 zeros.push_back(0.f);
4285 small.push_back(std::ldexp(-1.0f, -32));
4286 zeros.push_back(-0.f);
4289 small.push_back(std::ldexp(1.0f, -127));
4290 zeros.push_back(0.f);
4293 small.push_back(-std::ldexp(1.0f, -128));
4294 zeros.push_back(-0.f);
4299 spec.assembly = shader;
4300 spec.inputs.push_back(BufferSp(new Float32Buffer(small)));
4301 spec.outputs.push_back(BufferSp(new Float32Buffer(zeros)));
4302 spec.numWorkGroups = IVec3(numElements, 1, 1);
4304 group->addChild(new SpvAsmComputeShaderCase(
4305 testCtx, "flush_to_zero", "Check that values are zeroed correctly", spec));
4309 ComputeShaderSpec spec;
4310 vector<float> exact;
4311 const deUint32 numElements = 200;
4313 exact.reserve(numElements);
4315 for (size_t idx = 0; idx < numElements; ++idx)
4316 exact.push_back(static_cast<float>(static_cast<int>(idx) - 100));
4318 spec.assembly = shader;
4319 spec.inputs.push_back(BufferSp(new Float32Buffer(exact)));
4320 spec.outputs.push_back(BufferSp(new Float32Buffer(exact)));
4321 spec.numWorkGroups = IVec3(numElements, 1, 1);
4323 group->addChild(new SpvAsmComputeShaderCase(
4324 testCtx, "exact", "Check that values exactly preserved where appropriate", spec));
4328 ComputeShaderSpec spec;
4329 vector<float> inputs;
4330 const deUint32 numElements = 4;
4332 inputs.push_back(constructNormalizedFloat(8, 0x300300));
4333 inputs.push_back(-constructNormalizedFloat(-7, 0x600800));
4334 inputs.push_back(constructNormalizedFloat(2, 0x01E000));
4335 inputs.push_back(constructNormalizedFloat(1, 0xFFE000));
4337 spec.assembly = shader;
4338 spec.verifyIO = &compareOpQuantizeF16ComputeExactCase;
4339 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs)));
4340 spec.outputs.push_back(BufferSp(new Float32Buffer(inputs)));
4341 spec.numWorkGroups = IVec3(numElements, 1, 1);
4343 group->addChild(new SpvAsmComputeShaderCase(
4344 testCtx, "rounded", "Check that are rounded when needed", spec));
4347 return group.release();
4350 tcu::TestCaseGroup* createSpecConstantOpQuantizeToF16Group (tcu::TestContext& testCtx)
4352 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opspecconstantop_opquantize", "Tests the OpQuantizeToF16 opcode for the OpSpecConstantOp instruction"));
4354 const std::string shader (
4355 string(getComputeAsmShaderPreamble()) +
4357 "OpName %main \"main\"\n"
4358 "OpName %id \"gl_GlobalInvocationID\"\n"
4360 "OpDecorate %id BuiltIn GlobalInvocationId\n"
4362 "OpDecorate %sc_0 SpecId 0\n"
4363 "OpDecorate %sc_1 SpecId 1\n"
4364 "OpDecorate %sc_2 SpecId 2\n"
4365 "OpDecorate %sc_3 SpecId 3\n"
4366 "OpDecorate %sc_4 SpecId 4\n"
4367 "OpDecorate %sc_5 SpecId 5\n"
4369 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
4371 "%id = OpVariable %uvec3ptr Input\n"
4372 "%zero = OpConstant %i32 0\n"
4373 "%c_u32_6 = OpConstant %u32 6\n"
4375 "%sc_0 = OpSpecConstant %f32 0.\n"
4376 "%sc_1 = OpSpecConstant %f32 0.\n"
4377 "%sc_2 = OpSpecConstant %f32 0.\n"
4378 "%sc_3 = OpSpecConstant %f32 0.\n"
4379 "%sc_4 = OpSpecConstant %f32 0.\n"
4380 "%sc_5 = OpSpecConstant %f32 0.\n"
4382 "%sc_0_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_0\n"
4383 "%sc_1_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_1\n"
4384 "%sc_2_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_2\n"
4385 "%sc_3_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_3\n"
4386 "%sc_4_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_4\n"
4387 "%sc_5_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_5\n"
4389 "%main = OpFunction %void None %voidf\n"
4390 "%label = OpLabel\n"
4391 "%idval = OpLoad %uvec3 %id\n"
4392 "%x = OpCompositeExtract %u32 %idval 0\n"
4393 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
4394 "%selector = OpUMod %u32 %x %c_u32_6\n"
4395 " OpSelectionMerge %exit None\n"
4396 " OpSwitch %selector %exit 0 %case0 1 %case1 2 %case2 3 %case3 4 %case4 5 %case5\n"
4398 "%case0 = OpLabel\n"
4399 " OpStore %outloc %sc_0_quant\n"
4402 "%case1 = OpLabel\n"
4403 " OpStore %outloc %sc_1_quant\n"
4406 "%case2 = OpLabel\n"
4407 " OpStore %outloc %sc_2_quant\n"
4410 "%case3 = OpLabel\n"
4411 " OpStore %outloc %sc_3_quant\n"
4414 "%case4 = OpLabel\n"
4415 " OpStore %outloc %sc_4_quant\n"
4418 "%case5 = OpLabel\n"
4419 " OpStore %outloc %sc_5_quant\n"
4425 " OpFunctionEnd\n");
4428 ComputeShaderSpec spec;
4429 const deUint8 numCases = 4;
4430 vector<float> inputs (numCases, 0.f);
4431 vector<float> outputs;
4433 spec.assembly = shader;
4434 spec.numWorkGroups = IVec3(numCases, 1, 1);
4436 spec.specConstants.push_back(bitwiseCast<deUint32>(std::numeric_limits<float>::infinity()));
4437 spec.specConstants.push_back(bitwiseCast<deUint32>(-std::numeric_limits<float>::infinity()));
4438 spec.specConstants.push_back(bitwiseCast<deUint32>(std::ldexp(1.0f, 16)));
4439 spec.specConstants.push_back(bitwiseCast<deUint32>(std::ldexp(-1.0f, 32)));
4441 outputs.push_back(std::numeric_limits<float>::infinity());
4442 outputs.push_back(-std::numeric_limits<float>::infinity());
4443 outputs.push_back(std::numeric_limits<float>::infinity());
4444 outputs.push_back(-std::numeric_limits<float>::infinity());
4446 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs)));
4447 spec.outputs.push_back(BufferSp(new Float32Buffer(outputs)));
4449 group->addChild(new SpvAsmComputeShaderCase(
4450 testCtx, "infinities", "Check that infinities propagated and created", spec));
4454 ComputeShaderSpec spec;
4455 const deUint8 numCases = 2;
4456 vector<float> inputs (numCases, 0.f);
4457 vector<float> outputs;
4459 spec.assembly = shader;
4460 spec.numWorkGroups = IVec3(numCases, 1, 1);
4461 spec.verifyIO = &compareNan;
4463 outputs.push_back(std::numeric_limits<float>::quiet_NaN());
4464 outputs.push_back(-std::numeric_limits<float>::quiet_NaN());
4466 for (deUint8 idx = 0; idx < numCases; ++idx)
4467 spec.specConstants.push_back(bitwiseCast<deUint32>(outputs[idx]));
4469 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs)));
4470 spec.outputs.push_back(BufferSp(new Float32Buffer(outputs)));
4472 group->addChild(new SpvAsmComputeShaderCase(
4473 testCtx, "propagated_nans", "Check that nans are propagated", spec));
4477 ComputeShaderSpec spec;
4478 const deUint8 numCases = 6;
4479 vector<float> inputs (numCases, 0.f);
4480 vector<float> outputs;
4482 spec.assembly = shader;
4483 spec.numWorkGroups = IVec3(numCases, 1, 1);
4485 spec.specConstants.push_back(bitwiseCast<deUint32>(0.f));
4486 spec.specConstants.push_back(bitwiseCast<deUint32>(-0.f));
4487 spec.specConstants.push_back(bitwiseCast<deUint32>(std::ldexp(1.0f, -16)));
4488 spec.specConstants.push_back(bitwiseCast<deUint32>(std::ldexp(-1.0f, -32)));
4489 spec.specConstants.push_back(bitwiseCast<deUint32>(std::ldexp(1.0f, -127)));
4490 spec.specConstants.push_back(bitwiseCast<deUint32>(-std::ldexp(1.0f, -128)));
4492 outputs.push_back(0.f);
4493 outputs.push_back(-0.f);
4494 outputs.push_back(0.f);
4495 outputs.push_back(-0.f);
4496 outputs.push_back(0.f);
4497 outputs.push_back(-0.f);
4499 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs)));
4500 spec.outputs.push_back(BufferSp(new Float32Buffer(outputs)));
4502 group->addChild(new SpvAsmComputeShaderCase(
4503 testCtx, "flush_to_zero", "Check that values are zeroed correctly", spec));
4507 ComputeShaderSpec spec;
4508 const deUint8 numCases = 6;
4509 vector<float> inputs (numCases, 0.f);
4510 vector<float> outputs;
4512 spec.assembly = shader;
4513 spec.numWorkGroups = IVec3(numCases, 1, 1);
4515 for (deUint8 idx = 0; idx < 6; ++idx)
4517 const float f = static_cast<float>(idx * 10 - 30) / 4.f;
4518 spec.specConstants.push_back(bitwiseCast<deUint32>(f));
4519 outputs.push_back(f);
4522 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs)));
4523 spec.outputs.push_back(BufferSp(new Float32Buffer(outputs)));
4525 group->addChild(new SpvAsmComputeShaderCase(
4526 testCtx, "exact", "Check that values exactly preserved where appropriate", spec));
4530 ComputeShaderSpec spec;
4531 const deUint8 numCases = 4;
4532 vector<float> inputs (numCases, 0.f);
4533 vector<float> outputs;
4535 spec.assembly = shader;
4536 spec.numWorkGroups = IVec3(numCases, 1, 1);
4537 spec.verifyIO = &compareOpQuantizeF16ComputeExactCase;
4539 outputs.push_back(constructNormalizedFloat(8, 0x300300));
4540 outputs.push_back(-constructNormalizedFloat(-7, 0x600800));
4541 outputs.push_back(constructNormalizedFloat(2, 0x01E000));
4542 outputs.push_back(constructNormalizedFloat(1, 0xFFE000));
4544 for (deUint8 idx = 0; idx < numCases; ++idx)
4545 spec.specConstants.push_back(bitwiseCast<deUint32>(outputs[idx]));
4547 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs)));
4548 spec.outputs.push_back(BufferSp(new Float32Buffer(outputs)));
4550 group->addChild(new SpvAsmComputeShaderCase(
4551 testCtx, "rounded", "Check that are rounded when needed", spec));
4554 return group.release();
4557 // Checks that constant null/composite values can be used in computation.
4558 tcu::TestCaseGroup* createOpConstantUsageGroup (tcu::TestContext& testCtx)
4560 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opconstantnullcomposite", "Spotcheck the OpConstantNull & OpConstantComposite instruction"));
4561 ComputeShaderSpec spec;
4562 de::Random rnd (deStringHash(group->getName()));
4563 const int numElements = 100;
4564 vector<float> positiveFloats (numElements, 0);
4565 vector<float> negativeFloats (numElements, 0);
4567 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
4569 for (size_t ndx = 0; ndx < numElements; ++ndx)
4570 negativeFloats[ndx] = -positiveFloats[ndx];
4573 "OpCapability Shader\n"
4574 "%std450 = OpExtInstImport \"GLSL.std.450\"\n"
4575 "OpMemoryModel Logical GLSL450\n"
4576 "OpEntryPoint GLCompute %main \"main\" %id\n"
4577 "OpExecutionMode %main LocalSize 1 1 1\n"
4579 "OpSource GLSL 430\n"
4580 "OpName %main \"main\"\n"
4581 "OpName %id \"gl_GlobalInvocationID\"\n"
4583 "OpDecorate %id BuiltIn GlobalInvocationId\n"
4585 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
4587 "%fmat = OpTypeMatrix %fvec3 3\n"
4588 "%ten = OpConstant %u32 10\n"
4589 "%f32arr10 = OpTypeArray %f32 %ten\n"
4590 "%fst = OpTypeStruct %f32 %f32\n"
4592 + string(getComputeAsmInputOutputBuffer()) +
4594 "%id = OpVariable %uvec3ptr Input\n"
4595 "%zero = OpConstant %i32 0\n"
4597 // Create a bunch of null values
4598 "%unull = OpConstantNull %u32\n"
4599 "%fnull = OpConstantNull %f32\n"
4600 "%vnull = OpConstantNull %fvec3\n"
4601 "%mnull = OpConstantNull %fmat\n"
4602 "%anull = OpConstantNull %f32arr10\n"
4603 "%snull = OpConstantComposite %fst %fnull %fnull\n"
4605 "%main = OpFunction %void None %voidf\n"
4606 "%label = OpLabel\n"
4607 "%idval = OpLoad %uvec3 %id\n"
4608 "%x = OpCompositeExtract %u32 %idval 0\n"
4609 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
4610 "%inval = OpLoad %f32 %inloc\n"
4611 "%neg = OpFNegate %f32 %inval\n"
4613 // Get the abs() of (a certain element of) those null values
4614 "%unull_cov = OpConvertUToF %f32 %unull\n"
4615 "%unull_abs = OpExtInst %f32 %std450 FAbs %unull_cov\n"
4616 "%fnull_abs = OpExtInst %f32 %std450 FAbs %fnull\n"
4617 "%vnull_0 = OpCompositeExtract %f32 %vnull 0\n"
4618 "%vnull_abs = OpExtInst %f32 %std450 FAbs %vnull_0\n"
4619 "%mnull_12 = OpCompositeExtract %f32 %mnull 1 2\n"
4620 "%mnull_abs = OpExtInst %f32 %std450 FAbs %mnull_12\n"
4621 "%anull_3 = OpCompositeExtract %f32 %anull 3\n"
4622 "%anull_abs = OpExtInst %f32 %std450 FAbs %anull_3\n"
4623 "%snull_1 = OpCompositeExtract %f32 %snull 1\n"
4624 "%snull_abs = OpExtInst %f32 %std450 FAbs %snull_1\n"
4627 "%add1 = OpFAdd %f32 %neg %unull_abs\n"
4628 "%add2 = OpFAdd %f32 %add1 %fnull_abs\n"
4629 "%add3 = OpFAdd %f32 %add2 %vnull_abs\n"
4630 "%add4 = OpFAdd %f32 %add3 %mnull_abs\n"
4631 "%add5 = OpFAdd %f32 %add4 %anull_abs\n"
4632 "%final = OpFAdd %f32 %add5 %snull_abs\n"
4634 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
4635 " OpStore %outloc %final\n" // write to output
4638 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
4639 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
4640 spec.numWorkGroups = IVec3(numElements, 1, 1);
4642 group->addChild(new SpvAsmComputeShaderCase(testCtx, "spotcheck", "Check that values constructed via OpConstantNull & OpConstantComposite can be used", spec));
4644 return group.release();
4647 // Assembly code used for testing loop control is based on GLSL source code:
4650 // layout(std140, set = 0, binding = 0) readonly buffer Input {
4651 // float elements[];
4653 // layout(std140, set = 0, binding = 1) writeonly buffer Output {
4654 // float elements[];
4658 // uint x = gl_GlobalInvocationID.x;
4659 // output_data.elements[x] = input_data.elements[x];
4660 // for (uint i = 0; i < 4; ++i)
4661 // output_data.elements[x] += 1.f;
4663 tcu::TestCaseGroup* createLoopControlGroup (tcu::TestContext& testCtx)
4665 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "loop_control", "Tests loop control cases"));
4666 vector<CaseParameter> cases;
4667 de::Random rnd (deStringHash(group->getName()));
4668 const int numElements = 100;
4669 vector<float> inputFloats (numElements, 0);
4670 vector<float> outputFloats (numElements, 0);
4671 const StringTemplate shaderTemplate (
4672 string(getComputeAsmShaderPreamble()) +
4674 "OpSource GLSL 430\n"
4675 "OpName %main \"main\"\n"
4676 "OpName %id \"gl_GlobalInvocationID\"\n"
4678 "OpDecorate %id BuiltIn GlobalInvocationId\n"
4680 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
4682 "%u32ptr = OpTypePointer Function %u32\n"
4684 "%id = OpVariable %uvec3ptr Input\n"
4685 "%zero = OpConstant %i32 0\n"
4686 "%uzero = OpConstant %u32 0\n"
4687 "%one = OpConstant %i32 1\n"
4688 "%constf1 = OpConstant %f32 1.0\n"
4689 "%four = OpConstant %u32 4\n"
4691 "%main = OpFunction %void None %voidf\n"
4692 "%entry = OpLabel\n"
4693 "%i = OpVariable %u32ptr Function\n"
4694 " OpStore %i %uzero\n"
4696 "%idval = OpLoad %uvec3 %id\n"
4697 "%x = OpCompositeExtract %u32 %idval 0\n"
4698 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
4699 "%inval = OpLoad %f32 %inloc\n"
4700 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
4701 " OpStore %outloc %inval\n"
4702 " OpBranch %loop_entry\n"
4704 "%loop_entry = OpLabel\n"
4705 "%i_val = OpLoad %u32 %i\n"
4706 "%cmp_lt = OpULessThan %bool %i_val %four\n"
4707 " OpLoopMerge %loop_merge %loop_body ${CONTROL}\n"
4708 " OpBranchConditional %cmp_lt %loop_body %loop_merge\n"
4709 "%loop_body = OpLabel\n"
4710 "%outval = OpLoad %f32 %outloc\n"
4711 "%addf1 = OpFAdd %f32 %outval %constf1\n"
4712 " OpStore %outloc %addf1\n"
4713 "%new_i = OpIAdd %u32 %i_val %one\n"
4714 " OpStore %i %new_i\n"
4715 " OpBranch %loop_entry\n"
4716 "%loop_merge = OpLabel\n"
4718 " OpFunctionEnd\n");
4720 cases.push_back(CaseParameter("none", "None"));
4721 cases.push_back(CaseParameter("unroll", "Unroll"));
4722 cases.push_back(CaseParameter("dont_unroll", "DontUnroll"));
4723 cases.push_back(CaseParameter("unroll_dont_unroll", "Unroll|DontUnroll"));
4725 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats[0], numElements);
4727 for (size_t ndx = 0; ndx < numElements; ++ndx)
4728 outputFloats[ndx] = inputFloats[ndx] + 4.f;
4730 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
4732 map<string, string> specializations;
4733 ComputeShaderSpec spec;
4735 specializations["CONTROL"] = cases[caseNdx].param;
4736 spec.assembly = shaderTemplate.specialize(specializations);
4737 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
4738 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
4739 spec.numWorkGroups = IVec3(numElements, 1, 1);
4741 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
4744 return group.release();
4747 // Assembly code used for testing selection control is based on GLSL source code:
4750 // layout(std140, set = 0, binding = 0) readonly buffer Input {
4751 // float elements[];
4753 // layout(std140, set = 0, binding = 1) writeonly buffer Output {
4754 // float elements[];
4758 // uint x = gl_GlobalInvocationID.x;
4759 // float val = input_data.elements[x];
4761 // output_data.elements[x] = val + 1.f;
4763 // output_data.elements[x] = val - 1.f;
4765 tcu::TestCaseGroup* createSelectionControlGroup (tcu::TestContext& testCtx)
4767 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "selection_control", "Tests selection control cases"));
4768 vector<CaseParameter> cases;
4769 de::Random rnd (deStringHash(group->getName()));
4770 const int numElements = 100;
4771 vector<float> inputFloats (numElements, 0);
4772 vector<float> outputFloats (numElements, 0);
4773 const StringTemplate shaderTemplate (
4774 string(getComputeAsmShaderPreamble()) +
4776 "OpSource GLSL 430\n"
4777 "OpName %main \"main\"\n"
4778 "OpName %id \"gl_GlobalInvocationID\"\n"
4780 "OpDecorate %id BuiltIn GlobalInvocationId\n"
4782 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
4784 "%id = OpVariable %uvec3ptr Input\n"
4785 "%zero = OpConstant %i32 0\n"
4786 "%constf1 = OpConstant %f32 1.0\n"
4787 "%constf10 = OpConstant %f32 10.0\n"
4789 "%main = OpFunction %void None %voidf\n"
4790 "%entry = OpLabel\n"
4791 "%idval = OpLoad %uvec3 %id\n"
4792 "%x = OpCompositeExtract %u32 %idval 0\n"
4793 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
4794 "%inval = OpLoad %f32 %inloc\n"
4795 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
4796 "%cmp_gt = OpFOrdGreaterThan %bool %inval %constf10\n"
4798 " OpSelectionMerge %if_end ${CONTROL}\n"
4799 " OpBranchConditional %cmp_gt %if_true %if_false\n"
4800 "%if_true = OpLabel\n"
4801 "%addf1 = OpFAdd %f32 %inval %constf1\n"
4802 " OpStore %outloc %addf1\n"
4803 " OpBranch %if_end\n"
4804 "%if_false = OpLabel\n"
4805 "%subf1 = OpFSub %f32 %inval %constf1\n"
4806 " OpStore %outloc %subf1\n"
4807 " OpBranch %if_end\n"
4808 "%if_end = OpLabel\n"
4810 " OpFunctionEnd\n");
4812 cases.push_back(CaseParameter("none", "None"));
4813 cases.push_back(CaseParameter("flatten", "Flatten"));
4814 cases.push_back(CaseParameter("dont_flatten", "DontFlatten"));
4815 cases.push_back(CaseParameter("flatten_dont_flatten", "DontFlatten|Flatten"));
4817 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats[0], numElements);
4819 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
4820 floorAll(inputFloats);
4822 for (size_t ndx = 0; ndx < numElements; ++ndx)
4823 outputFloats[ndx] = inputFloats[ndx] + (inputFloats[ndx] > 10.f ? 1.f : -1.f);
4825 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
4827 map<string, string> specializations;
4828 ComputeShaderSpec spec;
4830 specializations["CONTROL"] = cases[caseNdx].param;
4831 spec.assembly = shaderTemplate.specialize(specializations);
4832 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
4833 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
4834 spec.numWorkGroups = IVec3(numElements, 1, 1);
4836 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
4839 return group.release();
4842 // Assembly code used for testing function control is based on GLSL source code:
4846 // layout(std140, set = 0, binding = 0) readonly buffer Input {
4847 // float elements[];
4849 // layout(std140, set = 0, binding = 1) writeonly buffer Output {
4850 // float elements[];
4853 // float const10() { return 10.f; }
4856 // uint x = gl_GlobalInvocationID.x;
4857 // output_data.elements[x] = input_data.elements[x] + const10();
4859 tcu::TestCaseGroup* createFunctionControlGroup (tcu::TestContext& testCtx)
4861 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "function_control", "Tests function control cases"));
4862 vector<CaseParameter> cases;
4863 de::Random rnd (deStringHash(group->getName()));
4864 const int numElements = 100;
4865 vector<float> inputFloats (numElements, 0);
4866 vector<float> outputFloats (numElements, 0);
4867 const StringTemplate shaderTemplate (
4868 string(getComputeAsmShaderPreamble()) +
4870 "OpSource GLSL 430\n"
4871 "OpName %main \"main\"\n"
4872 "OpName %func_const10 \"const10(\"\n"
4873 "OpName %id \"gl_GlobalInvocationID\"\n"
4875 "OpDecorate %id BuiltIn GlobalInvocationId\n"
4877 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
4879 "%f32f = OpTypeFunction %f32\n"
4880 "%id = OpVariable %uvec3ptr Input\n"
4881 "%zero = OpConstant %i32 0\n"
4882 "%constf10 = OpConstant %f32 10.0\n"
4884 "%main = OpFunction %void None %voidf\n"
4885 "%entry = OpLabel\n"
4886 "%idval = OpLoad %uvec3 %id\n"
4887 "%x = OpCompositeExtract %u32 %idval 0\n"
4888 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
4889 "%inval = OpLoad %f32 %inloc\n"
4890 "%ret_10 = OpFunctionCall %f32 %func_const10\n"
4891 "%fadd = OpFAdd %f32 %inval %ret_10\n"
4892 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
4893 " OpStore %outloc %fadd\n"
4897 "%func_const10 = OpFunction %f32 ${CONTROL} %f32f\n"
4898 "%label = OpLabel\n"
4899 " OpReturnValue %constf10\n"
4900 " OpFunctionEnd\n");
4902 cases.push_back(CaseParameter("none", "None"));
4903 cases.push_back(CaseParameter("inline", "Inline"));
4904 cases.push_back(CaseParameter("dont_inline", "DontInline"));
4905 cases.push_back(CaseParameter("pure", "Pure"));
4906 cases.push_back(CaseParameter("const", "Const"));
4907 cases.push_back(CaseParameter("inline_pure", "Inline|Pure"));
4908 cases.push_back(CaseParameter("const_dont_inline", "Const|DontInline"));
4909 cases.push_back(CaseParameter("inline_dont_inline", "Inline|DontInline"));
4910 cases.push_back(CaseParameter("pure_inline_dont_inline", "Pure|Inline|DontInline"));
4912 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats[0], numElements);
4914 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
4915 floorAll(inputFloats);
4917 for (size_t ndx = 0; ndx < numElements; ++ndx)
4918 outputFloats[ndx] = inputFloats[ndx] + 10.f;
4920 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
4922 map<string, string> specializations;
4923 ComputeShaderSpec spec;
4925 specializations["CONTROL"] = cases[caseNdx].param;
4926 spec.assembly = shaderTemplate.specialize(specializations);
4927 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
4928 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
4929 spec.numWorkGroups = IVec3(numElements, 1, 1);
4931 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
4934 return group.release();
4937 tcu::TestCaseGroup* createMemoryAccessGroup (tcu::TestContext& testCtx)
4939 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "memory_access", "Tests memory access cases"));
4940 vector<CaseParameter> cases;
4941 de::Random rnd (deStringHash(group->getName()));
4942 const int numElements = 100;
4943 vector<float> inputFloats (numElements, 0);
4944 vector<float> outputFloats (numElements, 0);
4945 const StringTemplate shaderTemplate (
4946 string(getComputeAsmShaderPreamble()) +
4948 "OpSource GLSL 430\n"
4949 "OpName %main \"main\"\n"
4950 "OpName %id \"gl_GlobalInvocationID\"\n"
4952 "OpDecorate %id BuiltIn GlobalInvocationId\n"
4954 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) + string(getComputeAsmInputOutputBuffer()) +
4956 "%f32ptr_f = OpTypePointer Function %f32\n"
4958 "%id = OpVariable %uvec3ptr Input\n"
4959 "%zero = OpConstant %i32 0\n"
4960 "%four = OpConstant %i32 4\n"
4962 "%main = OpFunction %void None %voidf\n"
4963 "%label = OpLabel\n"
4964 "%copy = OpVariable %f32ptr_f Function\n"
4965 "%idval = OpLoad %uvec3 %id ${ACCESS}\n"
4966 "%x = OpCompositeExtract %u32 %idval 0\n"
4967 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
4968 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
4969 " OpCopyMemory %copy %inloc ${ACCESS}\n"
4970 "%val1 = OpLoad %f32 %copy\n"
4971 "%val2 = OpLoad %f32 %inloc\n"
4972 "%add = OpFAdd %f32 %val1 %val2\n"
4973 " OpStore %outloc %add ${ACCESS}\n"
4975 " OpFunctionEnd\n");
4977 cases.push_back(CaseParameter("null", ""));
4978 cases.push_back(CaseParameter("none", "None"));
4979 cases.push_back(CaseParameter("volatile", "Volatile"));
4980 cases.push_back(CaseParameter("aligned", "Aligned 4"));
4981 cases.push_back(CaseParameter("nontemporal", "Nontemporal"));
4982 cases.push_back(CaseParameter("aligned_nontemporal", "Aligned|Nontemporal 4"));
4983 cases.push_back(CaseParameter("aligned_volatile", "Volatile|Aligned 4"));
4985 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats[0], numElements);
4987 for (size_t ndx = 0; ndx < numElements; ++ndx)
4988 outputFloats[ndx] = inputFloats[ndx] + inputFloats[ndx];
4990 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
4992 map<string, string> specializations;
4993 ComputeShaderSpec spec;
4995 specializations["ACCESS"] = cases[caseNdx].param;
4996 spec.assembly = shaderTemplate.specialize(specializations);
4997 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
4998 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
4999 spec.numWorkGroups = IVec3(numElements, 1, 1);
5001 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
5004 return group.release();
5007 // Checks that we can get undefined values for various types, without exercising a computation with it.
5008 tcu::TestCaseGroup* createOpUndefGroup (tcu::TestContext& testCtx)
5010 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opundef", "Tests the OpUndef instruction"));
5011 vector<CaseParameter> cases;
5012 de::Random rnd (deStringHash(group->getName()));
5013 const int numElements = 100;
5014 vector<float> positiveFloats (numElements, 0);
5015 vector<float> negativeFloats (numElements, 0);
5016 const StringTemplate shaderTemplate (
5017 string(getComputeAsmShaderPreamble()) +
5019 "OpSource GLSL 430\n"
5020 "OpName %main \"main\"\n"
5021 "OpName %id \"gl_GlobalInvocationID\"\n"
5023 "OpDecorate %id BuiltIn GlobalInvocationId\n"
5025 + string(getComputeAsmInputOutputBufferTraits()) + string(getComputeAsmCommonTypes()) +
5026 "%uvec2 = OpTypeVector %u32 2\n"
5027 "%fvec4 = OpTypeVector %f32 4\n"
5028 "%fmat33 = OpTypeMatrix %fvec3 3\n"
5029 "%image = OpTypeImage %f32 2D 0 0 0 1 Unknown\n"
5030 "%sampler = OpTypeSampler\n"
5031 "%simage = OpTypeSampledImage %image\n"
5032 "%const100 = OpConstant %u32 100\n"
5033 "%uarr100 = OpTypeArray %i32 %const100\n"
5034 "%struct = OpTypeStruct %f32 %i32 %u32\n"
5035 "%pointer = OpTypePointer Function %i32\n"
5036 + string(getComputeAsmInputOutputBuffer()) +
5038 "%id = OpVariable %uvec3ptr Input\n"
5039 "%zero = OpConstant %i32 0\n"
5041 "%main = OpFunction %void None %voidf\n"
5042 "%label = OpLabel\n"
5044 "%undef = OpUndef ${TYPE}\n"
5046 "%idval = OpLoad %uvec3 %id\n"
5047 "%x = OpCompositeExtract %u32 %idval 0\n"
5049 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
5050 "%inval = OpLoad %f32 %inloc\n"
5051 "%neg = OpFNegate %f32 %inval\n"
5052 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
5053 " OpStore %outloc %neg\n"
5055 " OpFunctionEnd\n");
5057 cases.push_back(CaseParameter("bool", "%bool"));
5058 cases.push_back(CaseParameter("sint32", "%i32"));
5059 cases.push_back(CaseParameter("uint32", "%u32"));
5060 cases.push_back(CaseParameter("float32", "%f32"));
5061 cases.push_back(CaseParameter("vec4float32", "%fvec4"));
5062 cases.push_back(CaseParameter("vec2uint32", "%uvec2"));
5063 cases.push_back(CaseParameter("matrix", "%fmat33"));
5064 cases.push_back(CaseParameter("image", "%image"));
5065 cases.push_back(CaseParameter("sampler", "%sampler"));
5066 cases.push_back(CaseParameter("sampledimage", "%simage"));
5067 cases.push_back(CaseParameter("array", "%uarr100"));
5068 cases.push_back(CaseParameter("runtimearray", "%f32arr"));
5069 cases.push_back(CaseParameter("struct", "%struct"));
5070 cases.push_back(CaseParameter("pointer", "%pointer"));
5072 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
5074 for (size_t ndx = 0; ndx < numElements; ++ndx)
5075 negativeFloats[ndx] = -positiveFloats[ndx];
5077 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
5079 map<string, string> specializations;
5080 ComputeShaderSpec spec;
5082 specializations["TYPE"] = cases[caseNdx].param;
5083 spec.assembly = shaderTemplate.specialize(specializations);
5084 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
5085 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
5086 spec.numWorkGroups = IVec3(numElements, 1, 1);
5088 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
5091 return group.release();
5096 tcu::TestCaseGroup* createOpSourceTests (tcu::TestContext& testCtx)
5098 struct NameCodePair { string name, code; };
5099 RGBA defaultColors[4];
5100 de::MovePtr<tcu::TestCaseGroup> opSourceTests (new tcu::TestCaseGroup(testCtx, "opsource", "OpSource instruction"));
5101 const std::string opsourceGLSLWithFile = "%opsrcfile = OpString \"foo.vert\"\nOpSource GLSL 450 %opsrcfile ";
5102 map<string, string> fragments = passthruFragments();
5103 const NameCodePair tests[] =
5105 {"unknown", "OpSource Unknown 321"},
5106 {"essl", "OpSource ESSL 310"},
5107 {"glsl", "OpSource GLSL 450"},
5108 {"opencl_cpp", "OpSource OpenCL_CPP 120"},
5109 {"opencl_c", "OpSource OpenCL_C 120"},
5110 {"multiple", "OpSource GLSL 450\nOpSource GLSL 450"},
5111 {"file", opsourceGLSLWithFile},
5112 {"source", opsourceGLSLWithFile + "\"void main(){}\""},
5113 // Longest possible source string: SPIR-V limits instructions to 65535
5114 // words, of which the first 4 are opsourceGLSLWithFile; the rest will
5115 // contain 65530 UTF8 characters (one word each) plus one last word
5116 // containing 3 ASCII characters and \0.
5117 {"longsource", opsourceGLSLWithFile + '"' + makeLongUTF8String(65530) + "ccc" + '"'}
5120 getDefaultColors(defaultColors);
5121 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameCodePair); ++testNdx)
5123 fragments["debug"] = tests[testNdx].code;
5124 createTestsForAllStages(tests[testNdx].name, defaultColors, defaultColors, fragments, opSourceTests.get());
5127 return opSourceTests.release();
5130 tcu::TestCaseGroup* createOpSourceContinuedTests (tcu::TestContext& testCtx)
5132 struct NameCodePair { string name, code; };
5133 RGBA defaultColors[4];
5134 de::MovePtr<tcu::TestCaseGroup> opSourceTests (new tcu::TestCaseGroup(testCtx, "opsourcecontinued", "OpSourceContinued instruction"));
5135 map<string, string> fragments = passthruFragments();
5136 const std::string opsource = "%opsrcfile = OpString \"foo.vert\"\nOpSource GLSL 450 %opsrcfile \"void main(){}\"\n";
5137 const NameCodePair tests[] =
5139 {"empty", opsource + "OpSourceContinued \"\""},
5140 {"short", opsource + "OpSourceContinued \"abcde\""},
5141 {"multiple", opsource + "OpSourceContinued \"abcde\"\nOpSourceContinued \"fghij\""},
5142 // Longest possible source string: SPIR-V limits instructions to 65535
5143 // words, of which the first one is OpSourceContinued/length; the rest
5144 // will contain 65533 UTF8 characters (one word each) plus one last word
5145 // containing 3 ASCII characters and \0.
5146 {"long", opsource + "OpSourceContinued \"" + makeLongUTF8String(65533) + "ccc\""}
5149 getDefaultColors(defaultColors);
5150 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameCodePair); ++testNdx)
5152 fragments["debug"] = tests[testNdx].code;
5153 createTestsForAllStages(tests[testNdx].name, defaultColors, defaultColors, fragments, opSourceTests.get());
5156 return opSourceTests.release();
5159 tcu::TestCaseGroup* createOpNoLineTests(tcu::TestContext& testCtx)
5161 RGBA defaultColors[4];
5162 de::MovePtr<tcu::TestCaseGroup> opLineTests (new tcu::TestCaseGroup(testCtx, "opnoline", "OpNoLine instruction"));
5163 map<string, string> fragments;
5164 getDefaultColors(defaultColors);
5165 fragments["debug"] =
5166 "%name = OpString \"name\"\n";
5168 fragments["pre_main"] =
5171 "OpLine %name 1 1\n"
5173 "OpLine %name 1 1\n"
5174 "OpLine %name 1 1\n"
5175 "%second_function = OpFunction %v4f32 None %v4f32_function\n"
5177 "OpLine %name 1 1\n"
5179 "OpLine %name 1 1\n"
5180 "OpLine %name 1 1\n"
5181 "%second_param1 = OpFunctionParameter %v4f32\n"
5184 "%label_secondfunction = OpLabel\n"
5186 "OpReturnValue %second_param1\n"
5191 fragments["testfun"] =
5192 // A %test_code function that returns its argument unchanged.
5195 "OpLine %name 1 1\n"
5196 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5198 "%param1 = OpFunctionParameter %v4f32\n"
5201 "%label_testfun = OpLabel\n"
5203 "%val1 = OpFunctionCall %v4f32 %second_function %param1\n"
5204 "OpReturnValue %val1\n"
5206 "OpLine %name 1 1\n"
5209 createTestsForAllStages("opnoline", defaultColors, defaultColors, fragments, opLineTests.get());
5211 return opLineTests.release();
5215 tcu::TestCaseGroup* createOpLineTests(tcu::TestContext& testCtx)
5217 RGBA defaultColors[4];
5218 de::MovePtr<tcu::TestCaseGroup> opLineTests (new tcu::TestCaseGroup(testCtx, "opline", "OpLine instruction"));
5219 map<string, string> fragments;
5220 std::vector<std::pair<std::string, std::string> > problemStrings;
5222 problemStrings.push_back(std::make_pair<std::string, std::string>("empty_name", ""));
5223 problemStrings.push_back(std::make_pair<std::string, std::string>("short_name", "short_name"));
5224 problemStrings.push_back(std::make_pair<std::string, std::string>("long_name", makeLongUTF8String(65530) + "ccc"));
5225 getDefaultColors(defaultColors);
5227 fragments["debug"] =
5228 "%other_name = OpString \"other_name\"\n";
5230 fragments["pre_main"] =
5231 "OpLine %file_name 32 0\n"
5232 "OpLine %file_name 32 32\n"
5233 "OpLine %file_name 32 40\n"
5234 "OpLine %other_name 32 40\n"
5235 "OpLine %other_name 0 100\n"
5236 "OpLine %other_name 0 4294967295\n"
5237 "OpLine %other_name 4294967295 0\n"
5238 "OpLine %other_name 32 40\n"
5239 "OpLine %file_name 0 0\n"
5240 "%second_function = OpFunction %v4f32 None %v4f32_function\n"
5241 "OpLine %file_name 1 0\n"
5242 "%second_param1 = OpFunctionParameter %v4f32\n"
5243 "OpLine %file_name 1 3\n"
5244 "OpLine %file_name 1 2\n"
5245 "%label_secondfunction = OpLabel\n"
5246 "OpLine %file_name 0 2\n"
5247 "OpReturnValue %second_param1\n"
5249 "OpLine %file_name 0 2\n"
5250 "OpLine %file_name 0 2\n";
5252 fragments["testfun"] =
5253 // A %test_code function that returns its argument unchanged.
5254 "OpLine %file_name 1 0\n"
5255 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5256 "OpLine %file_name 16 330\n"
5257 "%param1 = OpFunctionParameter %v4f32\n"
5258 "OpLine %file_name 14 442\n"
5259 "%label_testfun = OpLabel\n"
5260 "OpLine %file_name 11 1024\n"
5261 "%val1 = OpFunctionCall %v4f32 %second_function %param1\n"
5262 "OpLine %file_name 2 97\n"
5263 "OpReturnValue %val1\n"
5265 "OpLine %file_name 5 32\n";
5267 for (size_t i = 0; i < problemStrings.size(); ++i)
5269 map<string, string> testFragments = fragments;
5270 testFragments["debug"] += "%file_name = OpString \"" + problemStrings[i].second + "\"\n";
5271 createTestsForAllStages(string("opline") + "_" + problemStrings[i].first, defaultColors, defaultColors, testFragments, opLineTests.get());
5274 return opLineTests.release();
5277 tcu::TestCaseGroup* createOpConstantNullTests(tcu::TestContext& testCtx)
5279 de::MovePtr<tcu::TestCaseGroup> opConstantNullTests (new tcu::TestCaseGroup(testCtx, "opconstantnull", "OpConstantNull instruction"));
5283 const char functionStart[] =
5284 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5285 "%param1 = OpFunctionParameter %v4f32\n"
5288 const char functionEnd[] =
5289 "OpReturnValue %transformed_param\n"
5292 struct NameConstantsCode
5299 NameConstantsCode tests[] =
5303 "%cnull = OpConstantNull %v4f32\n",
5304 "%transformed_param = OpFAdd %v4f32 %param1 %cnull\n"
5308 "%cnull = OpConstantNull %f32\n",
5309 "%vp = OpVariable %fp_v4f32 Function\n"
5310 "%v = OpLoad %v4f32 %vp\n"
5311 "%v0 = OpVectorInsertDynamic %v4f32 %v %cnull %c_i32_0\n"
5312 "%v1 = OpVectorInsertDynamic %v4f32 %v0 %cnull %c_i32_1\n"
5313 "%v2 = OpVectorInsertDynamic %v4f32 %v1 %cnull %c_i32_2\n"
5314 "%v3 = OpVectorInsertDynamic %v4f32 %v2 %cnull %c_i32_3\n"
5315 "%transformed_param = OpFAdd %v4f32 %param1 %v3\n"
5319 "%cnull = OpConstantNull %bool\n",
5320 "%v = OpVariable %fp_v4f32 Function\n"
5321 " OpStore %v %param1\n"
5322 " OpSelectionMerge %false_label None\n"
5323 " OpBranchConditional %cnull %true_label %false_label\n"
5324 "%true_label = OpLabel\n"
5325 " OpStore %v %c_v4f32_0_5_0_5_0_5_0_5\n"
5326 " OpBranch %false_label\n"
5327 "%false_label = OpLabel\n"
5328 "%transformed_param = OpLoad %v4f32 %v\n"
5332 "%cnull = OpConstantNull %i32\n",
5333 "%v = OpVariable %fp_v4f32 Function %c_v4f32_0_5_0_5_0_5_0_5\n"
5334 "%b = OpIEqual %bool %cnull %c_i32_0\n"
5335 " OpSelectionMerge %false_label None\n"
5336 " OpBranchConditional %b %true_label %false_label\n"
5337 "%true_label = OpLabel\n"
5338 " OpStore %v %param1\n"
5339 " OpBranch %false_label\n"
5340 "%false_label = OpLabel\n"
5341 "%transformed_param = OpLoad %v4f32 %v\n"
5345 "%stype = OpTypeStruct %f32 %v4f32\n"
5346 "%fp_stype = OpTypePointer Function %stype\n"
5347 "%cnull = OpConstantNull %stype\n",
5348 "%v = OpVariable %fp_stype Function %cnull\n"
5349 "%f = OpAccessChain %fp_v4f32 %v %c_i32_1\n"
5350 "%f_val = OpLoad %v4f32 %f\n"
5351 "%transformed_param = OpFAdd %v4f32 %param1 %f_val\n"
5355 "%a4_v4f32 = OpTypeArray %v4f32 %c_u32_4\n"
5356 "%fp_a4_v4f32 = OpTypePointer Function %a4_v4f32\n"
5357 "%cnull = OpConstantNull %a4_v4f32\n",
5358 "%v = OpVariable %fp_a4_v4f32 Function %cnull\n"
5359 "%f = OpAccessChain %fp_v4f32 %v %c_u32_0\n"
5360 "%f1 = OpAccessChain %fp_v4f32 %v %c_u32_1\n"
5361 "%f2 = OpAccessChain %fp_v4f32 %v %c_u32_2\n"
5362 "%f3 = OpAccessChain %fp_v4f32 %v %c_u32_3\n"
5363 "%f_val = OpLoad %v4f32 %f\n"
5364 "%f1_val = OpLoad %v4f32 %f1\n"
5365 "%f2_val = OpLoad %v4f32 %f2\n"
5366 "%f3_val = OpLoad %v4f32 %f3\n"
5367 "%t0 = OpFAdd %v4f32 %param1 %f_val\n"
5368 "%t1 = OpFAdd %v4f32 %t0 %f1_val\n"
5369 "%t2 = OpFAdd %v4f32 %t1 %f2_val\n"
5370 "%transformed_param = OpFAdd %v4f32 %t2 %f3_val\n"
5374 "%mat4x4_f32 = OpTypeMatrix %v4f32 4\n"
5375 "%cnull = OpConstantNull %mat4x4_f32\n",
5376 // Our null matrix * any vector should result in a zero vector.
5377 "%v = OpVectorTimesMatrix %v4f32 %param1 %cnull\n"
5378 "%transformed_param = OpFAdd %v4f32 %param1 %v\n"
5382 getHalfColorsFullAlpha(colors);
5384 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameConstantsCode); ++testNdx)
5386 map<string, string> fragments;
5387 fragments["pre_main"] = tests[testNdx].constants;
5388 fragments["testfun"] = string(functionStart) + tests[testNdx].code + functionEnd;
5389 createTestsForAllStages(tests[testNdx].name, colors, colors, fragments, opConstantNullTests.get());
5391 return opConstantNullTests.release();
5393 tcu::TestCaseGroup* createOpConstantCompositeTests(tcu::TestContext& testCtx)
5395 de::MovePtr<tcu::TestCaseGroup> opConstantCompositeTests (new tcu::TestCaseGroup(testCtx, "opconstantcomposite", "OpConstantComposite instruction"));
5396 RGBA inputColors[4];
5397 RGBA outputColors[4];
5400 const char functionStart[] =
5401 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5402 "%param1 = OpFunctionParameter %v4f32\n"
5405 const char functionEnd[] =
5406 "OpReturnValue %transformed_param\n"
5409 struct NameConstantsCode
5416 NameConstantsCode tests[] =
5421 "%cval = OpConstantComposite %v4f32 %c_f32_0_5 %c_f32_0_5 %c_f32_0_5 %c_f32_0\n",
5422 "%transformed_param = OpFAdd %v4f32 %param1 %cval\n"
5427 "%stype = OpTypeStruct %v4f32 %f32\n"
5428 "%fp_stype = OpTypePointer Function %stype\n"
5429 "%f32_n_1 = OpConstant %f32 -1.0\n"
5430 "%f32_1_5 = OpConstant %f32 !0x3fc00000\n" // +1.5
5431 "%cvec = OpConstantComposite %v4f32 %f32_1_5 %f32_1_5 %f32_1_5 %c_f32_1\n"
5432 "%cval = OpConstantComposite %stype %cvec %f32_n_1\n",
5434 "%v = OpVariable %fp_stype Function %cval\n"
5435 "%vec_ptr = OpAccessChain %fp_v4f32 %v %c_u32_0\n"
5436 "%f32_ptr = OpAccessChain %fp_f32 %v %c_u32_1\n"
5437 "%vec_val = OpLoad %v4f32 %vec_ptr\n"
5438 "%f32_val = OpLoad %f32 %f32_ptr\n"
5439 "%tmp1 = OpVectorTimesScalar %v4f32 %c_v4f32_1_1_1_1 %f32_val\n" // vec4(-1)
5440 "%tmp2 = OpFAdd %v4f32 %tmp1 %param1\n" // param1 + vec4(-1)
5441 "%transformed_param = OpFAdd %v4f32 %tmp2 %vec_val\n" // param1 + vec4(-1) + vec4(1.5, 1.5, 1.5, 1.0)
5444 // [1|0|0|0.5] [x] = x + 0.5
5445 // [0|1|0|0.5] [y] = y + 0.5
5446 // [0|0|1|0.5] [z] = z + 0.5
5447 // [0|0|0|1 ] [1] = 1
5450 "%mat4x4_f32 = OpTypeMatrix %v4f32 4\n"
5451 "%v4f32_1_0_0_0 = OpConstantComposite %v4f32 %c_f32_1 %c_f32_0 %c_f32_0 %c_f32_0\n"
5452 "%v4f32_0_1_0_0 = OpConstantComposite %v4f32 %c_f32_0 %c_f32_1 %c_f32_0 %c_f32_0\n"
5453 "%v4f32_0_0_1_0 = OpConstantComposite %v4f32 %c_f32_0 %c_f32_0 %c_f32_1 %c_f32_0\n"
5454 "%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"
5455 "%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",
5457 "%transformed_param = OpMatrixTimesVector %v4f32 %cval %param1\n"
5462 "%c_v4f32_1_1_1_0 = OpConstantComposite %v4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_0\n"
5463 "%fp_a4f32 = OpTypePointer Function %a4f32\n"
5464 "%f32_n_1 = OpConstant %f32 -1.0\n"
5465 "%f32_1_5 = OpConstant %f32 !0x3fc00000\n" // +1.5
5466 "%carr = OpConstantComposite %a4f32 %c_f32_0 %f32_n_1 %f32_1_5 %c_f32_0\n",
5468 "%v = OpVariable %fp_a4f32 Function %carr\n"
5469 "%f = OpAccessChain %fp_f32 %v %c_u32_0\n"
5470 "%f1 = OpAccessChain %fp_f32 %v %c_u32_1\n"
5471 "%f2 = OpAccessChain %fp_f32 %v %c_u32_2\n"
5472 "%f3 = OpAccessChain %fp_f32 %v %c_u32_3\n"
5473 "%f_val = OpLoad %f32 %f\n"
5474 "%f1_val = OpLoad %f32 %f1\n"
5475 "%f2_val = OpLoad %f32 %f2\n"
5476 "%f3_val = OpLoad %f32 %f3\n"
5477 "%ftot1 = OpFAdd %f32 %f_val %f1_val\n"
5478 "%ftot2 = OpFAdd %f32 %ftot1 %f2_val\n"
5479 "%ftot3 = OpFAdd %f32 %ftot2 %f3_val\n" // 0 - 1 + 1.5 + 0
5480 "%add_vec = OpVectorTimesScalar %v4f32 %c_v4f32_1_1_1_0 %ftot3\n"
5481 "%transformed_param = OpFAdd %v4f32 %param1 %add_vec\n"
5488 // [ 1.0, 1.0, 1.0, 1.0]
5492 // [ 0.0, 0.5, 0.0, 0.0]
5496 // [ 1.0, 1.0, 1.0, 1.0]
5499 "array_of_struct_of_array",
5501 "%c_v4f32_1_1_1_0 = OpConstantComposite %v4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_0\n"
5502 "%fp_a4f32 = OpTypePointer Function %a4f32\n"
5503 "%stype = OpTypeStruct %f32 %a4f32\n"
5504 "%a3stype = OpTypeArray %stype %c_u32_3\n"
5505 "%fp_a3stype = OpTypePointer Function %a3stype\n"
5506 "%ca4f32_0 = OpConstantComposite %a4f32 %c_f32_0 %c_f32_0_5 %c_f32_0 %c_f32_0\n"
5507 "%ca4f32_1 = OpConstantComposite %a4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_1\n"
5508 "%cstype1 = OpConstantComposite %stype %c_f32_0 %ca4f32_1\n"
5509 "%cstype2 = OpConstantComposite %stype %c_f32_1 %ca4f32_0\n"
5510 "%carr = OpConstantComposite %a3stype %cstype1 %cstype2 %cstype1",
5512 "%v = OpVariable %fp_a3stype Function %carr\n"
5513 "%f = OpAccessChain %fp_f32 %v %c_u32_1 %c_u32_1 %c_u32_1\n"
5514 "%f_l = OpLoad %f32 %f\n"
5515 "%add_vec = OpVectorTimesScalar %v4f32 %c_v4f32_1_1_1_0 %f_l\n"
5516 "%transformed_param = OpFAdd %v4f32 %param1 %add_vec\n"
5520 getHalfColorsFullAlpha(inputColors);
5521 outputColors[0] = RGBA(255, 255, 255, 255);
5522 outputColors[1] = RGBA(255, 127, 127, 255);
5523 outputColors[2] = RGBA(127, 255, 127, 255);
5524 outputColors[3] = RGBA(127, 127, 255, 255);
5526 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameConstantsCode); ++testNdx)
5528 map<string, string> fragments;
5529 fragments["pre_main"] = tests[testNdx].constants;
5530 fragments["testfun"] = string(functionStart) + tests[testNdx].code + functionEnd;
5531 createTestsForAllStages(tests[testNdx].name, inputColors, outputColors, fragments, opConstantCompositeTests.get());
5533 return opConstantCompositeTests.release();
5536 tcu::TestCaseGroup* createSelectionBlockOrderTests(tcu::TestContext& testCtx)
5538 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "selection_block_order", "Out-of-order blocks for selection"));
5539 RGBA inputColors[4];
5540 RGBA outputColors[4];
5541 map<string, string> fragments;
5543 // vec4 test_code(vec4 param) {
5544 // vec4 result = param;
5545 // for (int i = 0; i < 4; ++i) {
5546 // if (i == 0) result[i] = 0.;
5547 // else result[i] = 1. - result[i];
5551 const char function[] =
5552 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5553 "%param1 = OpFunctionParameter %v4f32\n"
5555 "%iptr = OpVariable %fp_i32 Function\n"
5556 "%result = OpVariable %fp_v4f32 Function\n"
5557 " OpStore %iptr %c_i32_0\n"
5558 " OpStore %result %param1\n"
5561 // Loop entry block.
5563 "%ival = OpLoad %i32 %iptr\n"
5564 "%lt_4 = OpSLessThan %bool %ival %c_i32_4\n"
5565 " OpLoopMerge %exit %if_entry None\n"
5566 " OpBranchConditional %lt_4 %if_entry %exit\n"
5568 // Merge block for loop.
5570 "%ret = OpLoad %v4f32 %result\n"
5571 " OpReturnValue %ret\n"
5573 // If-statement entry block.
5574 "%if_entry = OpLabel\n"
5575 "%loc = OpAccessChain %fp_f32 %result %ival\n"
5576 "%eq_0 = OpIEqual %bool %ival %c_i32_0\n"
5577 " OpSelectionMerge %if_exit None\n"
5578 " OpBranchConditional %eq_0 %if_true %if_false\n"
5580 // False branch for if-statement.
5581 "%if_false = OpLabel\n"
5582 "%val = OpLoad %f32 %loc\n"
5583 "%sub = OpFSub %f32 %c_f32_1 %val\n"
5584 " OpStore %loc %sub\n"
5585 " OpBranch %if_exit\n"
5587 // Merge block for if-statement.
5588 "%if_exit = OpLabel\n"
5589 "%ival_next = OpIAdd %i32 %ival %c_i32_1\n"
5590 " OpStore %iptr %ival_next\n"
5593 // True branch for if-statement.
5594 "%if_true = OpLabel\n"
5595 " OpStore %loc %c_f32_0\n"
5596 " OpBranch %if_exit\n"
5600 fragments["testfun"] = function;
5602 inputColors[0] = RGBA(127, 127, 127, 0);
5603 inputColors[1] = RGBA(127, 0, 0, 0);
5604 inputColors[2] = RGBA(0, 127, 0, 0);
5605 inputColors[3] = RGBA(0, 0, 127, 0);
5607 outputColors[0] = RGBA(0, 128, 128, 255);
5608 outputColors[1] = RGBA(0, 255, 255, 255);
5609 outputColors[2] = RGBA(0, 128, 255, 255);
5610 outputColors[3] = RGBA(0, 255, 128, 255);
5612 createTestsForAllStages("out_of_order", inputColors, outputColors, fragments, group.get());
5614 return group.release();
5617 tcu::TestCaseGroup* createSwitchBlockOrderTests(tcu::TestContext& testCtx)
5619 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "switch_block_order", "Out-of-order blocks for switch"));
5620 RGBA inputColors[4];
5621 RGBA outputColors[4];
5622 map<string, string> fragments;
5624 const char typesAndConstants[] =
5625 "%c_f32_p2 = OpConstant %f32 0.2\n"
5626 "%c_f32_p4 = OpConstant %f32 0.4\n"
5627 "%c_f32_p6 = OpConstant %f32 0.6\n"
5628 "%c_f32_p8 = OpConstant %f32 0.8\n";
5630 // vec4 test_code(vec4 param) {
5631 // vec4 result = param;
5632 // for (int i = 0; i < 4; ++i) {
5634 // case 0: result[i] += .2; break;
5635 // case 1: result[i] += .6; break;
5636 // case 2: result[i] += .4; break;
5637 // case 3: result[i] += .8; break;
5638 // default: break; // unreachable
5643 const char function[] =
5644 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5645 "%param1 = OpFunctionParameter %v4f32\n"
5647 "%iptr = OpVariable %fp_i32 Function\n"
5648 "%result = OpVariable %fp_v4f32 Function\n"
5649 " OpStore %iptr %c_i32_0\n"
5650 " OpStore %result %param1\n"
5653 // Loop entry block.
5655 "%ival = OpLoad %i32 %iptr\n"
5656 "%lt_4 = OpSLessThan %bool %ival %c_i32_4\n"
5657 " OpLoopMerge %exit %switch_exit None\n"
5658 " OpBranchConditional %lt_4 %switch_entry %exit\n"
5660 // Merge block for loop.
5662 "%ret = OpLoad %v4f32 %result\n"
5663 " OpReturnValue %ret\n"
5665 // Switch-statement entry block.
5666 "%switch_entry = OpLabel\n"
5667 "%loc = OpAccessChain %fp_f32 %result %ival\n"
5668 "%val = OpLoad %f32 %loc\n"
5669 " OpSelectionMerge %switch_exit None\n"
5670 " OpSwitch %ival %switch_default 0 %case0 1 %case1 2 %case2 3 %case3\n"
5672 "%case2 = OpLabel\n"
5673 "%addp4 = OpFAdd %f32 %val %c_f32_p4\n"
5674 " OpStore %loc %addp4\n"
5675 " OpBranch %switch_exit\n"
5677 "%switch_default = OpLabel\n"
5680 "%case3 = OpLabel\n"
5681 "%addp8 = OpFAdd %f32 %val %c_f32_p8\n"
5682 " OpStore %loc %addp8\n"
5683 " OpBranch %switch_exit\n"
5685 "%case0 = OpLabel\n"
5686 "%addp2 = OpFAdd %f32 %val %c_f32_p2\n"
5687 " OpStore %loc %addp2\n"
5688 " OpBranch %switch_exit\n"
5690 // Merge block for switch-statement.
5691 "%switch_exit = OpLabel\n"
5692 "%ival_next = OpIAdd %i32 %ival %c_i32_1\n"
5693 " OpStore %iptr %ival_next\n"
5696 "%case1 = OpLabel\n"
5697 "%addp6 = OpFAdd %f32 %val %c_f32_p6\n"
5698 " OpStore %loc %addp6\n"
5699 " OpBranch %switch_exit\n"
5703 fragments["pre_main"] = typesAndConstants;
5704 fragments["testfun"] = function;
5706 inputColors[0] = RGBA(127, 27, 127, 51);
5707 inputColors[1] = RGBA(127, 0, 0, 51);
5708 inputColors[2] = RGBA(0, 27, 0, 51);
5709 inputColors[3] = RGBA(0, 0, 127, 51);
5711 outputColors[0] = RGBA(178, 180, 229, 255);
5712 outputColors[1] = RGBA(178, 153, 102, 255);
5713 outputColors[2] = RGBA(51, 180, 102, 255);
5714 outputColors[3] = RGBA(51, 153, 229, 255);
5716 createTestsForAllStages("out_of_order", inputColors, outputColors, fragments, group.get());
5718 return group.release();
5721 tcu::TestCaseGroup* createDecorationGroupTests(tcu::TestContext& testCtx)
5723 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "decoration_group", "Decoration group tests"));
5724 RGBA inputColors[4];
5725 RGBA outputColors[4];
5726 map<string, string> fragments;
5728 const char decorations[] =
5729 "OpDecorate %array_group ArrayStride 4\n"
5730 "OpDecorate %struct_member_group Offset 0\n"
5731 "%array_group = OpDecorationGroup\n"
5732 "%struct_member_group = OpDecorationGroup\n"
5734 "OpDecorate %group1 RelaxedPrecision\n"
5735 "OpDecorate %group3 RelaxedPrecision\n"
5736 "OpDecorate %group3 Invariant\n"
5737 "OpDecorate %group3 Restrict\n"
5738 "%group0 = OpDecorationGroup\n"
5739 "%group1 = OpDecorationGroup\n"
5740 "%group3 = OpDecorationGroup\n";
5742 const char typesAndConstants[] =
5743 "%a3f32 = OpTypeArray %f32 %c_u32_3\n"
5744 "%struct1 = OpTypeStruct %a3f32\n"
5745 "%struct2 = OpTypeStruct %a3f32\n"
5746 "%fp_struct1 = OpTypePointer Function %struct1\n"
5747 "%fp_struct2 = OpTypePointer Function %struct2\n"
5748 "%c_f32_2 = OpConstant %f32 2.\n"
5749 "%c_f32_n2 = OpConstant %f32 -2.\n"
5751 "%c_a3f32_1 = OpConstantComposite %a3f32 %c_f32_1 %c_f32_2 %c_f32_1\n"
5752 "%c_a3f32_2 = OpConstantComposite %a3f32 %c_f32_n1 %c_f32_n2 %c_f32_n1\n"
5753 "%c_struct1 = OpConstantComposite %struct1 %c_a3f32_1\n"
5754 "%c_struct2 = OpConstantComposite %struct2 %c_a3f32_2\n";
5756 const char function[] =
5757 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5758 "%param = OpFunctionParameter %v4f32\n"
5759 "%entry = OpLabel\n"
5760 "%result = OpVariable %fp_v4f32 Function\n"
5761 "%v_struct1 = OpVariable %fp_struct1 Function\n"
5762 "%v_struct2 = OpVariable %fp_struct2 Function\n"
5763 " OpStore %result %param\n"
5764 " OpStore %v_struct1 %c_struct1\n"
5765 " OpStore %v_struct2 %c_struct2\n"
5766 "%ptr1 = OpAccessChain %fp_f32 %v_struct1 %c_i32_0 %c_i32_2\n"
5767 "%val1 = OpLoad %f32 %ptr1\n"
5768 "%ptr2 = OpAccessChain %fp_f32 %v_struct2 %c_i32_0 %c_i32_2\n"
5769 "%val2 = OpLoad %f32 %ptr2\n"
5770 "%addvalues = OpFAdd %f32 %val1 %val2\n"
5771 "%ptr = OpAccessChain %fp_f32 %result %c_i32_1\n"
5772 "%val = OpLoad %f32 %ptr\n"
5773 "%addresult = OpFAdd %f32 %addvalues %val\n"
5774 " OpStore %ptr %addresult\n"
5775 "%ret = OpLoad %v4f32 %result\n"
5776 " OpReturnValue %ret\n"
5779 struct CaseNameDecoration
5785 CaseNameDecoration tests[] =
5788 "same_decoration_group_on_multiple_types",
5789 "OpGroupMemberDecorate %struct_member_group %struct1 0 %struct2 0\n"
5792 "empty_decoration_group",
5793 "OpGroupDecorate %group0 %a3f32\n"
5794 "OpGroupDecorate %group0 %result\n"
5797 "one_element_decoration_group",
5798 "OpGroupDecorate %array_group %a3f32\n"
5801 "multiple_elements_decoration_group",
5802 "OpGroupDecorate %group3 %v_struct1\n"
5805 "multiple_decoration_groups_on_same_variable",
5806 "OpGroupDecorate %group0 %v_struct2\n"
5807 "OpGroupDecorate %group1 %v_struct2\n"
5808 "OpGroupDecorate %group3 %v_struct2\n"
5811 "same_decoration_group_multiple_times",
5812 "OpGroupDecorate %group1 %addvalues\n"
5813 "OpGroupDecorate %group1 %addvalues\n"
5814 "OpGroupDecorate %group1 %addvalues\n"
5819 getHalfColorsFullAlpha(inputColors);
5820 getHalfColorsFullAlpha(outputColors);
5822 for (size_t idx = 0; idx < (sizeof(tests) / sizeof(tests[0])); ++idx)
5824 fragments["decoration"] = decorations + tests[idx].decoration;
5825 fragments["pre_main"] = typesAndConstants;
5826 fragments["testfun"] = function;
5828 createTestsForAllStages(tests[idx].name, inputColors, outputColors, fragments, group.get());
5831 return group.release();
5834 struct SpecConstantTwoIntGraphicsCase
5836 const char* caseName;
5837 const char* scDefinition0;
5838 const char* scDefinition1;
5839 const char* scResultType;
5840 const char* scOperation;
5841 deInt32 scActualValue0;
5842 deInt32 scActualValue1;
5843 const char* resultOperation;
5844 RGBA expectedColors[4];
5846 SpecConstantTwoIntGraphicsCase (const char* name,
5847 const char* definition0,
5848 const char* definition1,
5849 const char* resultType,
5850 const char* operation,
5853 const char* resultOp,
5854 const RGBA (&output)[4])
5856 , scDefinition0 (definition0)
5857 , scDefinition1 (definition1)
5858 , scResultType (resultType)
5859 , scOperation (operation)
5860 , scActualValue0 (value0)
5861 , scActualValue1 (value1)
5862 , resultOperation (resultOp)
5864 expectedColors[0] = output[0];
5865 expectedColors[1] = output[1];
5866 expectedColors[2] = output[2];
5867 expectedColors[3] = output[3];
5871 tcu::TestCaseGroup* createSpecConstantTests (tcu::TestContext& testCtx)
5873 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opspecconstantop", "Test the OpSpecConstantOp instruction"));
5874 vector<SpecConstantTwoIntGraphicsCase> cases;
5875 RGBA inputColors[4];
5876 RGBA outputColors0[4];
5877 RGBA outputColors1[4];
5878 RGBA outputColors2[4];
5880 const char decorations1[] =
5881 "OpDecorate %sc_0 SpecId 0\n"
5882 "OpDecorate %sc_1 SpecId 1\n";
5884 const char typesAndConstants1[] =
5885 "%sc_0 = OpSpecConstant${SC_DEF0}\n"
5886 "%sc_1 = OpSpecConstant${SC_DEF1}\n"
5887 "%sc_op = OpSpecConstantOp ${SC_RESULT_TYPE} ${SC_OP}\n";
5889 const char function1[] =
5890 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5891 "%param = OpFunctionParameter %v4f32\n"
5892 "%label = OpLabel\n"
5893 "%result = OpVariable %fp_v4f32 Function\n"
5894 " OpStore %result %param\n"
5895 "%gen = ${GEN_RESULT}\n"
5896 "%index = OpIAdd %i32 %gen %c_i32_1\n"
5897 "%loc = OpAccessChain %fp_f32 %result %index\n"
5898 "%val = OpLoad %f32 %loc\n"
5899 "%add = OpFAdd %f32 %val %c_f32_0_5\n"
5900 " OpStore %loc %add\n"
5901 "%ret = OpLoad %v4f32 %result\n"
5902 " OpReturnValue %ret\n"
5905 inputColors[0] = RGBA(127, 127, 127, 255);
5906 inputColors[1] = RGBA(127, 0, 0, 255);
5907 inputColors[2] = RGBA(0, 127, 0, 255);
5908 inputColors[3] = RGBA(0, 0, 127, 255);
5910 // Derived from inputColors[x] by adding 128 to inputColors[x][0].
5911 outputColors0[0] = RGBA(255, 127, 127, 255);
5912 outputColors0[1] = RGBA(255, 0, 0, 255);
5913 outputColors0[2] = RGBA(128, 127, 0, 255);
5914 outputColors0[3] = RGBA(128, 0, 127, 255);
5916 // Derived from inputColors[x] by adding 128 to inputColors[x][1].
5917 outputColors1[0] = RGBA(127, 255, 127, 255);
5918 outputColors1[1] = RGBA(127, 128, 0, 255);
5919 outputColors1[2] = RGBA(0, 255, 0, 255);
5920 outputColors1[3] = RGBA(0, 128, 127, 255);
5922 // Derived from inputColors[x] by adding 128 to inputColors[x][2].
5923 outputColors2[0] = RGBA(127, 127, 255, 255);
5924 outputColors2[1] = RGBA(127, 0, 128, 255);
5925 outputColors2[2] = RGBA(0, 127, 128, 255);
5926 outputColors2[3] = RGBA(0, 0, 255, 255);
5928 const char addZeroToSc[] = "OpIAdd %i32 %c_i32_0 %sc_op";
5929 const char selectTrueUsingSc[] = "OpSelect %i32 %sc_op %c_i32_1 %c_i32_0";
5930 const char selectFalseUsingSc[] = "OpSelect %i32 %sc_op %c_i32_0 %c_i32_1";
5932 cases.push_back(SpecConstantTwoIntGraphicsCase("iadd", " %i32 0", " %i32 0", "%i32", "IAdd %sc_0 %sc_1", 19, -20, addZeroToSc, outputColors0));
5933 cases.push_back(SpecConstantTwoIntGraphicsCase("isub", " %i32 0", " %i32 0", "%i32", "ISub %sc_0 %sc_1", 19, 20, addZeroToSc, outputColors0));
5934 cases.push_back(SpecConstantTwoIntGraphicsCase("imul", " %i32 0", " %i32 0", "%i32", "IMul %sc_0 %sc_1", -1, -1, addZeroToSc, outputColors2));
5935 cases.push_back(SpecConstantTwoIntGraphicsCase("sdiv", " %i32 0", " %i32 0", "%i32", "SDiv %sc_0 %sc_1", -126, 126, addZeroToSc, outputColors0));
5936 cases.push_back(SpecConstantTwoIntGraphicsCase("udiv", " %i32 0", " %i32 0", "%i32", "UDiv %sc_0 %sc_1", 126, 126, addZeroToSc, outputColors2));
5937 cases.push_back(SpecConstantTwoIntGraphicsCase("srem", " %i32 0", " %i32 0", "%i32", "SRem %sc_0 %sc_1", 3, 2, addZeroToSc, outputColors2));
5938 cases.push_back(SpecConstantTwoIntGraphicsCase("smod", " %i32 0", " %i32 0", "%i32", "SMod %sc_0 %sc_1", 3, 2, addZeroToSc, outputColors2));
5939 cases.push_back(SpecConstantTwoIntGraphicsCase("umod", " %i32 0", " %i32 0", "%i32", "UMod %sc_0 %sc_1", 1001, 500, addZeroToSc, outputColors2));
5940 cases.push_back(SpecConstantTwoIntGraphicsCase("bitwiseand", " %i32 0", " %i32 0", "%i32", "BitwiseAnd %sc_0 %sc_1", 0x33, 0x0d, addZeroToSc, outputColors2));
5941 cases.push_back(SpecConstantTwoIntGraphicsCase("bitwiseor", " %i32 0", " %i32 0", "%i32", "BitwiseOr %sc_0 %sc_1", 0, 1, addZeroToSc, outputColors2));
5942 cases.push_back(SpecConstantTwoIntGraphicsCase("bitwisexor", " %i32 0", " %i32 0", "%i32", "BitwiseXor %sc_0 %sc_1", 0x2e, 0x2f, addZeroToSc, outputColors2));
5943 cases.push_back(SpecConstantTwoIntGraphicsCase("shiftrightlogical", " %i32 0", " %i32 0", "%i32", "ShiftRightLogical %sc_0 %sc_1", 2, 1, addZeroToSc, outputColors2));
5944 cases.push_back(SpecConstantTwoIntGraphicsCase("shiftrightarithmetic", " %i32 0", " %i32 0", "%i32", "ShiftRightArithmetic %sc_0 %sc_1", -4, 2, addZeroToSc, outputColors0));
5945 cases.push_back(SpecConstantTwoIntGraphicsCase("shiftleftlogical", " %i32 0", " %i32 0", "%i32", "ShiftLeftLogical %sc_0 %sc_1", 1, 0, addZeroToSc, outputColors2));
5946 cases.push_back(SpecConstantTwoIntGraphicsCase("slessthan", " %i32 0", " %i32 0", "%bool", "SLessThan %sc_0 %sc_1", -20, -10, selectTrueUsingSc, outputColors2));
5947 cases.push_back(SpecConstantTwoIntGraphicsCase("ulessthan", " %i32 0", " %i32 0", "%bool", "ULessThan %sc_0 %sc_1", 10, 20, selectTrueUsingSc, outputColors2));
5948 cases.push_back(SpecConstantTwoIntGraphicsCase("sgreaterthan", " %i32 0", " %i32 0", "%bool", "SGreaterThan %sc_0 %sc_1", -1000, 50, selectFalseUsingSc, outputColors2));
5949 cases.push_back(SpecConstantTwoIntGraphicsCase("ugreaterthan", " %i32 0", " %i32 0", "%bool", "UGreaterThan %sc_0 %sc_1", 10, 5, selectTrueUsingSc, outputColors2));
5950 cases.push_back(SpecConstantTwoIntGraphicsCase("slessthanequal", " %i32 0", " %i32 0", "%bool", "SLessThanEqual %sc_0 %sc_1", -10, -10, selectTrueUsingSc, outputColors2));
5951 cases.push_back(SpecConstantTwoIntGraphicsCase("ulessthanequal", " %i32 0", " %i32 0", "%bool", "ULessThanEqual %sc_0 %sc_1", 50, 100, selectTrueUsingSc, outputColors2));
5952 cases.push_back(SpecConstantTwoIntGraphicsCase("sgreaterthanequal", " %i32 0", " %i32 0", "%bool", "SGreaterThanEqual %sc_0 %sc_1", -1000, 50, selectFalseUsingSc, outputColors2));
5953 cases.push_back(SpecConstantTwoIntGraphicsCase("ugreaterthanequal", " %i32 0", " %i32 0", "%bool", "UGreaterThanEqual %sc_0 %sc_1", 10, 10, selectTrueUsingSc, outputColors2));
5954 cases.push_back(SpecConstantTwoIntGraphicsCase("iequal", " %i32 0", " %i32 0", "%bool", "IEqual %sc_0 %sc_1", 42, 24, selectFalseUsingSc, outputColors2));
5955 cases.push_back(SpecConstantTwoIntGraphicsCase("logicaland", "True %bool", "True %bool", "%bool", "LogicalAnd %sc_0 %sc_1", 0, 1, selectFalseUsingSc, outputColors2));
5956 cases.push_back(SpecConstantTwoIntGraphicsCase("logicalor", "False %bool", "False %bool", "%bool", "LogicalOr %sc_0 %sc_1", 1, 0, selectTrueUsingSc, outputColors2));
5957 cases.push_back(SpecConstantTwoIntGraphicsCase("logicalequal", "True %bool", "True %bool", "%bool", "LogicalEqual %sc_0 %sc_1", 0, 1, selectFalseUsingSc, outputColors2));
5958 cases.push_back(SpecConstantTwoIntGraphicsCase("logicalnotequal", "False %bool", "False %bool", "%bool", "LogicalNotEqual %sc_0 %sc_1", 1, 0, selectTrueUsingSc, outputColors2));
5959 cases.push_back(SpecConstantTwoIntGraphicsCase("snegate", " %i32 0", " %i32 0", "%i32", "SNegate %sc_0", -1, 0, addZeroToSc, outputColors2));
5960 cases.push_back(SpecConstantTwoIntGraphicsCase("not", " %i32 0", " %i32 0", "%i32", "Not %sc_0", -2, 0, addZeroToSc, outputColors2));
5961 cases.push_back(SpecConstantTwoIntGraphicsCase("logicalnot", "False %bool", "False %bool", "%bool", "LogicalNot %sc_0", 1, 0, selectFalseUsingSc, outputColors2));
5962 cases.push_back(SpecConstantTwoIntGraphicsCase("select", "False %bool", " %i32 0", "%i32", "Select %sc_0 %sc_1 %c_i32_0", 1, 1, addZeroToSc, outputColors2));
5963 // OpSConvert, OpFConvert: these two instructions involve ints/floats of different bitwidths.
5964 // \todo[2015-12-1 antiagainst] OpQuantizeToF16
5966 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
5968 map<string, string> specializations;
5969 map<string, string> fragments;
5970 vector<deInt32> specConstants;
5972 specializations["SC_DEF0"] = cases[caseNdx].scDefinition0;
5973 specializations["SC_DEF1"] = cases[caseNdx].scDefinition1;
5974 specializations["SC_RESULT_TYPE"] = cases[caseNdx].scResultType;
5975 specializations["SC_OP"] = cases[caseNdx].scOperation;
5976 specializations["GEN_RESULT"] = cases[caseNdx].resultOperation;
5978 fragments["decoration"] = tcu::StringTemplate(decorations1).specialize(specializations);
5979 fragments["pre_main"] = tcu::StringTemplate(typesAndConstants1).specialize(specializations);
5980 fragments["testfun"] = tcu::StringTemplate(function1).specialize(specializations);
5982 specConstants.push_back(cases[caseNdx].scActualValue0);
5983 specConstants.push_back(cases[caseNdx].scActualValue1);
5985 createTestsForAllStages(cases[caseNdx].caseName, inputColors, cases[caseNdx].expectedColors, fragments, specConstants, group.get());
5988 const char decorations2[] =
5989 "OpDecorate %sc_0 SpecId 0\n"
5990 "OpDecorate %sc_1 SpecId 1\n"
5991 "OpDecorate %sc_2 SpecId 2\n";
5993 const char typesAndConstants2[] =
5994 "%v3i32 = OpTypeVector %i32 3\n"
5995 "%vec3_0 = OpConstantComposite %v3i32 %c_i32_0 %c_i32_0 %c_i32_0\n"
5996 "%vec3_undef = OpUndef %v3i32\n"
5998 "%sc_0 = OpSpecConstant %i32 0\n"
5999 "%sc_1 = OpSpecConstant %i32 0\n"
6000 "%sc_2 = OpSpecConstant %i32 0\n"
6001 "%sc_vec3_0 = OpSpecConstantOp %v3i32 CompositeInsert %sc_0 %vec3_0 0\n" // (sc_0, 0, 0)
6002 "%sc_vec3_1 = OpSpecConstantOp %v3i32 CompositeInsert %sc_1 %vec3_0 1\n" // (0, sc_1, 0)
6003 "%sc_vec3_2 = OpSpecConstantOp %v3i32 CompositeInsert %sc_2 %vec3_0 2\n" // (0, 0, sc_2)
6004 "%sc_vec3_0_s = OpSpecConstantOp %v3i32 VectorShuffle %sc_vec3_0 %vec3_undef 0 0xFFFFFFFF 2\n" // (sc_0, ???, 0)
6005 "%sc_vec3_1_s = OpSpecConstantOp %v3i32 VectorShuffle %sc_vec3_1 %vec3_undef 0xFFFFFFFF 1 0\n" // (???, sc_1, 0)
6006 "%sc_vec3_2_s = OpSpecConstantOp %v3i32 VectorShuffle %vec3_undef %sc_vec3_2 5 0xFFFFFFFF 5\n" // (sc_2, ???, sc_2)
6007 "%sc_vec3_01 = OpSpecConstantOp %v3i32 VectorShuffle %sc_vec3_0_s %sc_vec3_1_s 1 0 4\n" // (0, sc_0, sc_1)
6008 "%sc_vec3_012 = OpSpecConstantOp %v3i32 VectorShuffle %sc_vec3_01 %sc_vec3_2_s 5 1 2\n" // (sc_2, sc_0, sc_1)
6009 "%sc_ext_0 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 0\n" // sc_2
6010 "%sc_ext_1 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 1\n" // sc_0
6011 "%sc_ext_2 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 2\n" // sc_1
6012 "%sc_sub = OpSpecConstantOp %i32 ISub %sc_ext_0 %sc_ext_1\n" // (sc_2 - sc_0)
6013 "%sc_final = OpSpecConstantOp %i32 IMul %sc_sub %sc_ext_2\n"; // (sc_2 - sc_0) * sc_1
6015 const char function2[] =
6016 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6017 "%param = OpFunctionParameter %v4f32\n"
6018 "%label = OpLabel\n"
6019 "%result = OpVariable %fp_v4f32 Function\n"
6020 " OpStore %result %param\n"
6021 "%loc = OpAccessChain %fp_f32 %result %sc_final\n"
6022 "%val = OpLoad %f32 %loc\n"
6023 "%add = OpFAdd %f32 %val %c_f32_0_5\n"
6024 " OpStore %loc %add\n"
6025 "%ret = OpLoad %v4f32 %result\n"
6026 " OpReturnValue %ret\n"
6029 map<string, string> fragments;
6030 vector<deInt32> specConstants;
6032 fragments["decoration"] = decorations2;
6033 fragments["pre_main"] = typesAndConstants2;
6034 fragments["testfun"] = function2;
6036 specConstants.push_back(56789);
6037 specConstants.push_back(-2);
6038 specConstants.push_back(56788);
6040 createTestsForAllStages("vector_related", inputColors, outputColors2, fragments, specConstants, group.get());
6042 return group.release();
6045 tcu::TestCaseGroup* createOpPhiTests(tcu::TestContext& testCtx)
6047 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opphi", "Test the OpPhi instruction"));
6048 RGBA inputColors[4];
6049 RGBA outputColors1[4];
6050 RGBA outputColors2[4];
6051 RGBA outputColors3[4];
6052 map<string, string> fragments1;
6053 map<string, string> fragments2;
6054 map<string, string> fragments3;
6056 const char typesAndConstants1[] =
6057 "%c_f32_p2 = OpConstant %f32 0.2\n"
6058 "%c_f32_p4 = OpConstant %f32 0.4\n"
6059 "%c_f32_p5 = OpConstant %f32 0.5\n"
6060 "%c_f32_p8 = OpConstant %f32 0.8\n";
6062 // vec4 test_code(vec4 param) {
6063 // vec4 result = param;
6064 // for (int i = 0; i < 4; ++i) {
6067 // case 0: operand = .2; break;
6068 // case 1: operand = .5; break;
6069 // case 2: operand = .4; break;
6070 // case 3: operand = .0; break;
6071 // default: break; // unreachable
6073 // result[i] += operand;
6077 const char function1[] =
6078 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6079 "%param1 = OpFunctionParameter %v4f32\n"
6081 "%iptr = OpVariable %fp_i32 Function\n"
6082 "%result = OpVariable %fp_v4f32 Function\n"
6083 " OpStore %iptr %c_i32_0\n"
6084 " OpStore %result %param1\n"
6088 "%ival = OpLoad %i32 %iptr\n"
6089 "%lt_4 = OpSLessThan %bool %ival %c_i32_4\n"
6090 " OpLoopMerge %exit %phi None\n"
6091 " OpBranchConditional %lt_4 %entry %exit\n"
6093 "%entry = OpLabel\n"
6094 "%loc = OpAccessChain %fp_f32 %result %ival\n"
6095 "%val = OpLoad %f32 %loc\n"
6096 " OpSelectionMerge %phi None\n"
6097 " OpSwitch %ival %default 0 %case0 1 %case1 2 %case2 3 %case3\n"
6099 "%case0 = OpLabel\n"
6101 "%case1 = OpLabel\n"
6103 "%case2 = OpLabel\n"
6105 "%case3 = OpLabel\n"
6108 "%default = OpLabel\n"
6112 "%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
6113 "%add = OpFAdd %f32 %val %operand\n"
6114 " OpStore %loc %add\n"
6115 "%ival_next = OpIAdd %i32 %ival %c_i32_1\n"
6116 " OpStore %iptr %ival_next\n"
6120 "%ret = OpLoad %v4f32 %result\n"
6121 " OpReturnValue %ret\n"
6125 fragments1["pre_main"] = typesAndConstants1;
6126 fragments1["testfun"] = function1;
6128 getHalfColorsFullAlpha(inputColors);
6130 outputColors1[0] = RGBA(178, 255, 229, 255);
6131 outputColors1[1] = RGBA(178, 127, 102, 255);
6132 outputColors1[2] = RGBA(51, 255, 102, 255);
6133 outputColors1[3] = RGBA(51, 127, 229, 255);
6135 createTestsForAllStages("out_of_order", inputColors, outputColors1, fragments1, group.get());
6137 const char typesAndConstants2[] =
6138 "%c_f32_p2 = OpConstant %f32 0.2\n";
6140 // Add .4 to the second element of the given parameter.
6141 const char function2[] =
6142 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6143 "%param = OpFunctionParameter %v4f32\n"
6144 "%entry = OpLabel\n"
6145 "%result = OpVariable %fp_v4f32 Function\n"
6146 " OpStore %result %param\n"
6147 "%loc = OpAccessChain %fp_f32 %result %c_i32_1\n"
6148 "%val = OpLoad %f32 %loc\n"
6152 "%step = OpPhi %i32 %c_i32_0 %entry %step_next %phi\n"
6153 "%accum = OpPhi %f32 %val %entry %accum_next %phi\n"
6154 "%step_next = OpIAdd %i32 %step %c_i32_1\n"
6155 "%accum_next = OpFAdd %f32 %accum %c_f32_p2\n"
6156 "%still_loop = OpSLessThan %bool %step %c_i32_2\n"
6157 " OpLoopMerge %exit %phi None\n"
6158 " OpBranchConditional %still_loop %phi %exit\n"
6161 " OpStore %loc %accum\n"
6162 "%ret = OpLoad %v4f32 %result\n"
6163 " OpReturnValue %ret\n"
6167 fragments2["pre_main"] = typesAndConstants2;
6168 fragments2["testfun"] = function2;
6170 outputColors2[0] = RGBA(127, 229, 127, 255);
6171 outputColors2[1] = RGBA(127, 102, 0, 255);
6172 outputColors2[2] = RGBA(0, 229, 0, 255);
6173 outputColors2[3] = RGBA(0, 102, 127, 255);
6175 createTestsForAllStages("induction", inputColors, outputColors2, fragments2, group.get());
6177 const char typesAndConstants3[] =
6178 "%true = OpConstantTrue %bool\n"
6179 "%false = OpConstantFalse %bool\n"
6180 "%c_f32_p2 = OpConstant %f32 0.2\n";
6182 // Swap the second and the third element of the given parameter.
6183 const char function3[] =
6184 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6185 "%param = OpFunctionParameter %v4f32\n"
6186 "%entry = OpLabel\n"
6187 "%result = OpVariable %fp_v4f32 Function\n"
6188 " OpStore %result %param\n"
6189 "%a_loc = OpAccessChain %fp_f32 %result %c_i32_1\n"
6190 "%a_init = OpLoad %f32 %a_loc\n"
6191 "%b_loc = OpAccessChain %fp_f32 %result %c_i32_2\n"
6192 "%b_init = OpLoad %f32 %b_loc\n"
6196 "%still_loop = OpPhi %bool %true %entry %false %phi\n"
6197 "%a_next = OpPhi %f32 %a_init %entry %b_next %phi\n"
6198 "%b_next = OpPhi %f32 %b_init %entry %a_next %phi\n"
6199 " OpLoopMerge %exit %phi None\n"
6200 " OpBranchConditional %still_loop %phi %exit\n"
6203 " OpStore %a_loc %a_next\n"
6204 " OpStore %b_loc %b_next\n"
6205 "%ret = OpLoad %v4f32 %result\n"
6206 " OpReturnValue %ret\n"
6210 fragments3["pre_main"] = typesAndConstants3;
6211 fragments3["testfun"] = function3;
6213 outputColors3[0] = RGBA(127, 127, 127, 255);
6214 outputColors3[1] = RGBA(127, 0, 0, 255);
6215 outputColors3[2] = RGBA(0, 0, 127, 255);
6216 outputColors3[3] = RGBA(0, 127, 0, 255);
6218 createTestsForAllStages("swap", inputColors, outputColors3, fragments3, group.get());
6220 return group.release();
6223 tcu::TestCaseGroup* createNoContractionTests(tcu::TestContext& testCtx)
6225 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "nocontraction", "Test the NoContraction decoration"));
6226 RGBA inputColors[4];
6227 RGBA outputColors[4];
6229 // With NoContraction, (1 + 2^-23) * (1 - 2^-23) - 1 should be conducted as a multiplication and an addition separately.
6230 // For the multiplication, the result is 1 - 2^-46, which is out of the precision range for 32-bit float. (32-bit float
6231 // only have 23-bit fraction.) So it will be rounded to 1. Or 0x1.fffffc. Then the final result is 0 or -0x1p-24.
6232 // On the contrary, the result will be 2^-46, which is a normalized number perfectly representable as 32-bit float.
6233 const char constantsAndTypes[] =
6234 "%c_vec4_0 = OpConstantComposite %v4f32 %c_f32_0 %c_f32_0 %c_f32_0 %c_f32_1\n"
6235 "%c_vec4_1 = OpConstantComposite %v4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_1\n"
6236 "%c_f32_1pl2_23 = OpConstant %f32 0x1.000002p+0\n" // 1 + 2^-23
6237 "%c_f32_1mi2_23 = OpConstant %f32 0x1.fffffcp-1\n" // 1 - 2^-23
6238 "%c_f32_n1pn24 = OpConstant %f32 -0x1p-24\n";
6240 const char function[] =
6241 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6242 "%param = OpFunctionParameter %v4f32\n"
6243 "%label = OpLabel\n"
6244 "%var1 = OpVariable %fp_f32 Function %c_f32_1pl2_23\n"
6245 "%var2 = OpVariable %fp_f32 Function\n"
6246 "%red = OpCompositeExtract %f32 %param 0\n"
6247 "%plus_red = OpFAdd %f32 %c_f32_1mi2_23 %red\n"
6248 " OpStore %var2 %plus_red\n"
6249 "%val1 = OpLoad %f32 %var1\n"
6250 "%val2 = OpLoad %f32 %var2\n"
6251 "%mul = OpFMul %f32 %val1 %val2\n"
6252 "%add = OpFAdd %f32 %mul %c_f32_n1\n"
6253 "%is0 = OpFOrdEqual %bool %add %c_f32_0\n"
6254 "%isn1n24 = OpFOrdEqual %bool %add %c_f32_n1pn24\n"
6255 "%success = OpLogicalOr %bool %is0 %isn1n24\n"
6256 "%v4success = OpCompositeConstruct %v4bool %success %success %success %success\n"
6257 "%ret = OpSelect %v4f32 %v4success %c_vec4_0 %c_vec4_1\n"
6258 " OpReturnValue %ret\n"
6261 struct CaseNameDecoration
6268 CaseNameDecoration tests[] = {
6269 {"multiplication", "OpDecorate %mul NoContraction"},
6270 {"addition", "OpDecorate %add NoContraction"},
6271 {"both", "OpDecorate %mul NoContraction\nOpDecorate %add NoContraction"},
6274 getHalfColorsFullAlpha(inputColors);
6276 for (deUint8 idx = 0; idx < 4; ++idx)
6278 inputColors[idx].setRed(0);
6279 outputColors[idx] = RGBA(0, 0, 0, 255);
6282 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(CaseNameDecoration); ++testNdx)
6284 map<string, string> fragments;
6286 fragments["decoration"] = tests[testNdx].decoration;
6287 fragments["pre_main"] = constantsAndTypes;
6288 fragments["testfun"] = function;
6290 createTestsForAllStages(tests[testNdx].name, inputColors, outputColors, fragments, group.get());
6293 return group.release();
6296 tcu::TestCaseGroup* createMemoryAccessTests(tcu::TestContext& testCtx)
6298 de::MovePtr<tcu::TestCaseGroup> memoryAccessTests (new tcu::TestCaseGroup(testCtx, "opmemoryaccess", "Memory Semantics"));
6301 const char constantsAndTypes[] =
6302 "%c_a2f32_1 = OpConstantComposite %a2f32 %c_f32_1 %c_f32_1\n"
6303 "%fp_a2f32 = OpTypePointer Function %a2f32\n"
6304 "%stype = OpTypeStruct %v4f32 %a2f32 %f32\n"
6305 "%fp_stype = OpTypePointer Function %stype\n";
6307 const char function[] =
6308 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6309 "%param1 = OpFunctionParameter %v4f32\n"
6311 "%v1 = OpVariable %fp_v4f32 Function\n"
6312 "%v2 = OpVariable %fp_a2f32 Function\n"
6313 "%v3 = OpVariable %fp_f32 Function\n"
6314 "%v = OpVariable %fp_stype Function\n"
6315 "%vv = OpVariable %fp_stype Function\n"
6316 "%vvv = OpVariable %fp_f32 Function\n"
6318 " OpStore %v1 %c_v4f32_1_1_1_1\n"
6319 " OpStore %v2 %c_a2f32_1\n"
6320 " OpStore %v3 %c_f32_1\n"
6322 "%p_v4f32 = OpAccessChain %fp_v4f32 %v %c_u32_0\n"
6323 "%p_a2f32 = OpAccessChain %fp_a2f32 %v %c_u32_1\n"
6324 "%p_f32 = OpAccessChain %fp_f32 %v %c_u32_2\n"
6325 "%v1_v = OpLoad %v4f32 %v1 ${access_type}\n"
6326 "%v2_v = OpLoad %a2f32 %v2 ${access_type}\n"
6327 "%v3_v = OpLoad %f32 %v3 ${access_type}\n"
6329 " OpStore %p_v4f32 %v1_v ${access_type}\n"
6330 " OpStore %p_a2f32 %v2_v ${access_type}\n"
6331 " OpStore %p_f32 %v3_v ${access_type}\n"
6333 " OpCopyMemory %vv %v ${access_type}\n"
6334 " OpCopyMemory %vvv %p_f32 ${access_type}\n"
6336 "%p_f32_2 = OpAccessChain %fp_f32 %vv %c_u32_2\n"
6337 "%v_f32_2 = OpLoad %f32 %p_f32_2\n"
6338 "%v_f32_3 = OpLoad %f32 %vvv\n"
6340 "%ret1 = OpVectorTimesScalar %v4f32 %param1 %v_f32_2\n"
6341 "%ret2 = OpVectorTimesScalar %v4f32 %ret1 %v_f32_3\n"
6342 " OpReturnValue %ret2\n"
6345 struct NameMemoryAccess
6352 NameMemoryAccess tests[] =
6355 { "volatile", "Volatile" },
6356 { "aligned", "Aligned 1" },
6357 { "volatile_aligned", "Volatile|Aligned 1" },
6358 { "nontemporal_aligned", "Nontemporal|Aligned 1" },
6359 { "volatile_nontemporal", "Volatile|Nontemporal" },
6360 { "volatile_nontermporal_aligned", "Volatile|Nontemporal|Aligned 1" },
6363 getHalfColorsFullAlpha(colors);
6365 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameMemoryAccess); ++testNdx)
6367 map<string, string> fragments;
6368 map<string, string> memoryAccess;
6369 memoryAccess["access_type"] = tests[testNdx].accessType;
6371 fragments["pre_main"] = constantsAndTypes;
6372 fragments["testfun"] = tcu::StringTemplate(function).specialize(memoryAccess);
6373 createTestsForAllStages(tests[testNdx].name, colors, colors, fragments, memoryAccessTests.get());
6375 return memoryAccessTests.release();
6377 tcu::TestCaseGroup* createOpUndefTests(tcu::TestContext& testCtx)
6379 de::MovePtr<tcu::TestCaseGroup> opUndefTests (new tcu::TestCaseGroup(testCtx, "opundef", "Test OpUndef"));
6380 RGBA defaultColors[4];
6381 map<string, string> fragments;
6382 getDefaultColors(defaultColors);
6384 // First, simple cases that don't do anything with the OpUndef result.
6385 struct NameCodePair { string name, decl, type; };
6386 const NameCodePair tests[] =
6388 {"bool", "", "%bool"},
6389 {"vec2uint32", "", "%v2u32"},
6390 {"image", "%type = OpTypeImage %f32 2D 0 0 0 1 Unknown", "%type"},
6391 {"sampler", "%type = OpTypeSampler", "%type"},
6392 {"sampledimage", "%img = OpTypeImage %f32 2D 0 0 0 1 Unknown\n" "%type = OpTypeSampledImage %img", "%type"},
6393 {"pointer", "", "%fp_i32"},
6394 {"runtimearray", "%type = OpTypeRuntimeArray %f32", "%type"},
6395 {"array", "%c_u32_100 = OpConstant %u32 100\n" "%type = OpTypeArray %i32 %c_u32_100", "%type"},
6396 {"struct", "%type = OpTypeStruct %f32 %i32 %u32", "%type"}};
6397 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameCodePair); ++testNdx)
6399 fragments["undef_type"] = tests[testNdx].type;
6400 fragments["testfun"] = StringTemplate(
6401 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6402 "%param1 = OpFunctionParameter %v4f32\n"
6403 "%label_testfun = OpLabel\n"
6404 "%undef = OpUndef ${undef_type}\n"
6405 "OpReturnValue %param1\n"
6406 "OpFunctionEnd\n").specialize(fragments);
6407 fragments["pre_main"] = tests[testNdx].decl;
6408 createTestsForAllStages(tests[testNdx].name, defaultColors, defaultColors, fragments, opUndefTests.get());
6412 fragments["testfun"] =
6413 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6414 "%param1 = OpFunctionParameter %v4f32\n"
6415 "%label_testfun = OpLabel\n"
6416 "%undef = OpUndef %f32\n"
6417 "%zero = OpFMul %f32 %undef %c_f32_0\n"
6418 "%is_nan = OpIsNan %bool %zero\n" //OpUndef may result in NaN which may turn %zero into Nan.
6419 "%actually_zero = OpSelect %f32 %is_nan %c_f32_0 %zero\n"
6420 "%a = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
6421 "%b = OpFAdd %f32 %a %actually_zero\n"
6422 "%ret = OpVectorInsertDynamic %v4f32 %param1 %b %c_i32_0\n"
6423 "OpReturnValue %ret\n"
6426 createTestsForAllStages("float32", defaultColors, defaultColors, fragments, opUndefTests.get());
6428 fragments["testfun"] =
6429 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6430 "%param1 = OpFunctionParameter %v4f32\n"
6431 "%label_testfun = OpLabel\n"
6432 "%undef = OpUndef %i32\n"
6433 "%zero = OpIMul %i32 %undef %c_i32_0\n"
6434 "%a = OpVectorExtractDynamic %f32 %param1 %zero\n"
6435 "%ret = OpVectorInsertDynamic %v4f32 %param1 %a %c_i32_0\n"
6436 "OpReturnValue %ret\n"
6439 createTestsForAllStages("sint32", defaultColors, defaultColors, fragments, opUndefTests.get());
6441 fragments["testfun"] =
6442 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6443 "%param1 = OpFunctionParameter %v4f32\n"
6444 "%label_testfun = OpLabel\n"
6445 "%undef = OpUndef %u32\n"
6446 "%zero = OpIMul %u32 %undef %c_i32_0\n"
6447 "%a = OpVectorExtractDynamic %f32 %param1 %zero\n"
6448 "%ret = OpVectorInsertDynamic %v4f32 %param1 %a %c_i32_0\n"
6449 "OpReturnValue %ret\n"
6452 createTestsForAllStages("uint32", defaultColors, defaultColors, fragments, opUndefTests.get());
6454 fragments["testfun"] =
6455 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6456 "%param1 = OpFunctionParameter %v4f32\n"
6457 "%label_testfun = OpLabel\n"
6458 "%undef = OpUndef %v4f32\n"
6459 "%vzero = OpVectorTimesScalar %v4f32 %undef %c_f32_0\n"
6460 "%zero_0 = OpVectorExtractDynamic %f32 %vzero %c_i32_0\n"
6461 "%zero_1 = OpVectorExtractDynamic %f32 %vzero %c_i32_1\n"
6462 "%zero_2 = OpVectorExtractDynamic %f32 %vzero %c_i32_2\n"
6463 "%zero_3 = OpVectorExtractDynamic %f32 %vzero %c_i32_3\n"
6464 "%is_nan_0 = OpIsNan %bool %zero_0\n"
6465 "%is_nan_1 = OpIsNan %bool %zero_1\n"
6466 "%is_nan_2 = OpIsNan %bool %zero_2\n"
6467 "%is_nan_3 = OpIsNan %bool %zero_3\n"
6468 "%actually_zero_0 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_0\n"
6469 "%actually_zero_1 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_1\n"
6470 "%actually_zero_2 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_2\n"
6471 "%actually_zero_3 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_3\n"
6472 "%param1_0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
6473 "%param1_1 = OpVectorExtractDynamic %f32 %param1 %c_i32_1\n"
6474 "%param1_2 = OpVectorExtractDynamic %f32 %param1 %c_i32_2\n"
6475 "%param1_3 = OpVectorExtractDynamic %f32 %param1 %c_i32_3\n"
6476 "%sum_0 = OpFAdd %f32 %param1_0 %actually_zero_0\n"
6477 "%sum_1 = OpFAdd %f32 %param1_1 %actually_zero_1\n"
6478 "%sum_2 = OpFAdd %f32 %param1_2 %actually_zero_2\n"
6479 "%sum_3 = OpFAdd %f32 %param1_3 %actually_zero_3\n"
6480 "%ret3 = OpVectorInsertDynamic %v4f32 %param1 %sum_3 %c_i32_3\n"
6481 "%ret2 = OpVectorInsertDynamic %v4f32 %ret3 %sum_2 %c_i32_2\n"
6482 "%ret1 = OpVectorInsertDynamic %v4f32 %ret2 %sum_1 %c_i32_1\n"
6483 "%ret = OpVectorInsertDynamic %v4f32 %ret1 %sum_0 %c_i32_0\n"
6484 "OpReturnValue %ret\n"
6487 createTestsForAllStages("vec4float32", defaultColors, defaultColors, fragments, opUndefTests.get());
6489 fragments["pre_main"] =
6490 "%m2x2f32 = OpTypeMatrix %v2f32 2\n";
6491 fragments["testfun"] =
6492 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6493 "%param1 = OpFunctionParameter %v4f32\n"
6494 "%label_testfun = OpLabel\n"
6495 "%undef = OpUndef %m2x2f32\n"
6496 "%mzero = OpMatrixTimesScalar %m2x2f32 %undef %c_f32_0\n"
6497 "%zero_0 = OpCompositeExtract %f32 %mzero 0 0\n"
6498 "%zero_1 = OpCompositeExtract %f32 %mzero 0 1\n"
6499 "%zero_2 = OpCompositeExtract %f32 %mzero 1 0\n"
6500 "%zero_3 = OpCompositeExtract %f32 %mzero 1 1\n"
6501 "%is_nan_0 = OpIsNan %bool %zero_0\n"
6502 "%is_nan_1 = OpIsNan %bool %zero_1\n"
6503 "%is_nan_2 = OpIsNan %bool %zero_2\n"
6504 "%is_nan_3 = OpIsNan %bool %zero_3\n"
6505 "%actually_zero_0 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_0\n"
6506 "%actually_zero_1 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_1\n"
6507 "%actually_zero_2 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_2\n"
6508 "%actually_zero_3 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_3\n"
6509 "%param1_0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
6510 "%param1_1 = OpVectorExtractDynamic %f32 %param1 %c_i32_1\n"
6511 "%param1_2 = OpVectorExtractDynamic %f32 %param1 %c_i32_2\n"
6512 "%param1_3 = OpVectorExtractDynamic %f32 %param1 %c_i32_3\n"
6513 "%sum_0 = OpFAdd %f32 %param1_0 %actually_zero_0\n"
6514 "%sum_1 = OpFAdd %f32 %param1_1 %actually_zero_1\n"
6515 "%sum_2 = OpFAdd %f32 %param1_2 %actually_zero_2\n"
6516 "%sum_3 = OpFAdd %f32 %param1_3 %actually_zero_3\n"
6517 "%ret3 = OpVectorInsertDynamic %v4f32 %param1 %sum_3 %c_i32_3\n"
6518 "%ret2 = OpVectorInsertDynamic %v4f32 %ret3 %sum_2 %c_i32_2\n"
6519 "%ret1 = OpVectorInsertDynamic %v4f32 %ret2 %sum_1 %c_i32_1\n"
6520 "%ret = OpVectorInsertDynamic %v4f32 %ret1 %sum_0 %c_i32_0\n"
6521 "OpReturnValue %ret\n"
6524 createTestsForAllStages("matrix", defaultColors, defaultColors, fragments, opUndefTests.get());
6526 return opUndefTests.release();
6529 void createOpQuantizeSingleOptionTests(tcu::TestCaseGroup* testCtx)
6531 const RGBA inputColors[4] =
6534 RGBA(0, 0, 255, 255),
6535 RGBA(0, 255, 0, 255),
6536 RGBA(0, 255, 255, 255)
6539 const RGBA expectedColors[4] =
6541 RGBA(255, 0, 0, 255),
6542 RGBA(255, 0, 0, 255),
6543 RGBA(255, 0, 0, 255),
6544 RGBA(255, 0, 0, 255)
6547 const struct SingleFP16Possibility
6550 const char* constant; // Value to assign to %test_constant.
6552 const char* condition; // Must assign to %cond an expression that evaluates to true after %c = OpQuantizeToF16(%test_constant + 0).
6558 -constructNormalizedFloat(1, 0x300000),
6559 "%cond = OpFOrdEqual %bool %c %test_constant\n"
6564 constructNormalizedFloat(7, 0x000000),
6565 "%cond = OpFOrdEqual %bool %c %test_constant\n"
6567 // SPIR-V requires that OpQuantizeToF16 flushes
6568 // any numbers that would end up denormalized in F16 to zero.
6572 std::ldexp(1.5f, -140),
6573 "%cond = OpFOrdEqual %bool %c %c_f32_0\n"
6578 -std::ldexp(1.5f, -140),
6579 "%cond = OpFOrdEqual %bool %c %c_f32_0\n"
6584 std::ldexp(1.0f, -16),
6585 "%cond = OpFOrdEqual %bool %c %c_f32_0\n"
6586 }, // too small positive
6588 "negative_too_small",
6590 -std::ldexp(1.0f, -32),
6591 "%cond = OpFOrdEqual %bool %c %c_f32_0\n"
6592 }, // too small negative
6596 -std::ldexp(1.0f, 128),
6598 "%gz = OpFOrdLessThan %bool %c %c_f32_0\n"
6599 "%inf = OpIsInf %bool %c\n"
6600 "%cond = OpLogicalAnd %bool %gz %inf\n"
6605 std::ldexp(1.0f, 128),
6607 "%gz = OpFOrdGreaterThan %bool %c %c_f32_0\n"
6608 "%inf = OpIsInf %bool %c\n"
6609 "%cond = OpLogicalAnd %bool %gz %inf\n"
6612 "round_to_negative_inf",
6614 -std::ldexp(1.0f, 32),
6616 "%gz = OpFOrdLessThan %bool %c %c_f32_0\n"
6617 "%inf = OpIsInf %bool %c\n"
6618 "%cond = OpLogicalAnd %bool %gz %inf\n"
6623 std::ldexp(1.0f, 16),
6625 "%gz = OpFOrdGreaterThan %bool %c %c_f32_0\n"
6626 "%inf = OpIsInf %bool %c\n"
6627 "%cond = OpLogicalAnd %bool %gz %inf\n"
6632 std::numeric_limits<float>::quiet_NaN(),
6634 // Test for any NaN value, as NaNs are not preserved
6635 "%direct_quant = OpQuantizeToF16 %f32 %test_constant\n"
6636 "%cond = OpIsNan %bool %direct_quant\n"
6641 std::numeric_limits<float>::quiet_NaN(),
6643 // Test for any NaN value, as NaNs are not preserved
6644 "%direct_quant = OpQuantizeToF16 %f32 %test_constant\n"
6645 "%cond = OpIsNan %bool %direct_quant\n"
6648 const char* constants =
6649 "%test_constant = OpConstant %f32 "; // The value will be test.constant.
6651 StringTemplate function (
6652 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6653 "%param1 = OpFunctionParameter %v4f32\n"
6654 "%label_testfun = OpLabel\n"
6655 "%a = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
6656 "%b = OpFAdd %f32 %test_constant %a\n"
6657 "%c = OpQuantizeToF16 %f32 %b\n"
6659 "%v4cond = OpCompositeConstruct %v4bool %cond %cond %cond %cond\n"
6660 "%retval = OpSelect %v4f32 %v4cond %c_v4f32_1_0_0_1 %param1\n"
6661 " OpReturnValue %retval\n"
6665 const char* specDecorations = "OpDecorate %test_constant SpecId 0\n";
6666 const char* specConstants =
6667 "%test_constant = OpSpecConstant %f32 0.\n"
6668 "%c = OpSpecConstantOp %f32 QuantizeToF16 %test_constant\n";
6670 StringTemplate specConstantFunction(
6671 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6672 "%param1 = OpFunctionParameter %v4f32\n"
6673 "%label_testfun = OpLabel\n"
6675 "%v4cond = OpCompositeConstruct %v4bool %cond %cond %cond %cond\n"
6676 "%retval = OpSelect %v4f32 %v4cond %c_v4f32_1_0_0_1 %param1\n"
6677 " OpReturnValue %retval\n"
6681 for (size_t idx = 0; idx < (sizeof(tests)/sizeof(tests[0])); ++idx)
6683 map<string, string> codeSpecialization;
6684 map<string, string> fragments;
6685 codeSpecialization["condition"] = tests[idx].condition;
6686 fragments["testfun"] = function.specialize(codeSpecialization);
6687 fragments["pre_main"] = string(constants) + tests[idx].constant + "\n";
6688 createTestsForAllStages(tests[idx].name, inputColors, expectedColors, fragments, testCtx);
6691 for (size_t idx = 0; idx < (sizeof(tests)/sizeof(tests[0])); ++idx)
6693 map<string, string> codeSpecialization;
6694 map<string, string> fragments;
6695 vector<deInt32> passConstants;
6696 deInt32 specConstant;
6698 codeSpecialization["condition"] = tests[idx].condition;
6699 fragments["testfun"] = specConstantFunction.specialize(codeSpecialization);
6700 fragments["decoration"] = specDecorations;
6701 fragments["pre_main"] = specConstants;
6703 memcpy(&specConstant, &tests[idx].valueAsFloat, sizeof(float));
6704 passConstants.push_back(specConstant);
6706 createTestsForAllStages(string("spec_const_") + tests[idx].name, inputColors, expectedColors, fragments, passConstants, testCtx);
6710 void createOpQuantizeTwoPossibilityTests(tcu::TestCaseGroup* testCtx)
6712 RGBA inputColors[4] = {
6714 RGBA(0, 0, 255, 255),
6715 RGBA(0, 255, 0, 255),
6716 RGBA(0, 255, 255, 255)
6719 RGBA expectedColors[4] =
6721 RGBA(255, 0, 0, 255),
6722 RGBA(255, 0, 0, 255),
6723 RGBA(255, 0, 0, 255),
6724 RGBA(255, 0, 0, 255)
6727 struct DualFP16Possibility
6732 const char* possibleOutput1;
6733 const char* possibleOutput2;
6736 "positive_round_up_or_round_down",
6738 constructNormalizedFloat(8, 0x300300),
6743 "negative_round_up_or_round_down",
6745 -constructNormalizedFloat(-7, 0x600800),
6752 constructNormalizedFloat(2, 0x01e000),
6757 "carry_to_exponent",
6759 constructNormalizedFloat(1, 0xffe000),
6764 StringTemplate constants (
6765 "%input_const = OpConstant %f32 ${input}\n"
6766 "%possible_solution1 = OpConstant %f32 ${output1}\n"
6767 "%possible_solution2 = OpConstant %f32 ${output2}\n"
6770 StringTemplate specConstants (
6771 "%input_const = OpSpecConstant %f32 0.\n"
6772 "%possible_solution1 = OpConstant %f32 ${output1}\n"
6773 "%possible_solution2 = OpConstant %f32 ${output2}\n"
6776 const char* specDecorations = "OpDecorate %input_const SpecId 0\n";
6778 const char* function =
6779 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6780 "%param1 = OpFunctionParameter %v4f32\n"
6781 "%label_testfun = OpLabel\n"
6782 "%a = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
6783 // For the purposes of this test we assume that 0.f will always get
6784 // faithfully passed through the pipeline stages.
6785 "%b = OpFAdd %f32 %input_const %a\n"
6786 "%c = OpQuantizeToF16 %f32 %b\n"
6787 "%eq_1 = OpFOrdEqual %bool %c %possible_solution1\n"
6788 "%eq_2 = OpFOrdEqual %bool %c %possible_solution2\n"
6789 "%cond = OpLogicalOr %bool %eq_1 %eq_2\n"
6790 "%v4cond = OpCompositeConstruct %v4bool %cond %cond %cond %cond\n"
6791 "%retval = OpSelect %v4f32 %v4cond %c_v4f32_1_0_0_1 %param1"
6792 " OpReturnValue %retval\n"
6795 for(size_t idx = 0; idx < (sizeof(tests)/sizeof(tests[0])); ++idx) {
6796 map<string, string> fragments;
6797 map<string, string> constantSpecialization;
6799 constantSpecialization["input"] = tests[idx].input;
6800 constantSpecialization["output1"] = tests[idx].possibleOutput1;
6801 constantSpecialization["output2"] = tests[idx].possibleOutput2;
6802 fragments["testfun"] = function;
6803 fragments["pre_main"] = constants.specialize(constantSpecialization);
6804 createTestsForAllStages(tests[idx].name, inputColors, expectedColors, fragments, testCtx);
6807 for(size_t idx = 0; idx < (sizeof(tests)/sizeof(tests[0])); ++idx) {
6808 map<string, string> fragments;
6809 map<string, string> constantSpecialization;
6810 vector<deInt32> passConstants;
6811 deInt32 specConstant;
6813 constantSpecialization["output1"] = tests[idx].possibleOutput1;
6814 constantSpecialization["output2"] = tests[idx].possibleOutput2;
6815 fragments["testfun"] = function;
6816 fragments["decoration"] = specDecorations;
6817 fragments["pre_main"] = specConstants.specialize(constantSpecialization);
6819 memcpy(&specConstant, &tests[idx].inputAsFloat, sizeof(float));
6820 passConstants.push_back(specConstant);
6822 createTestsForAllStages(string("spec_const_") + tests[idx].name, inputColors, expectedColors, fragments, passConstants, testCtx);
6826 tcu::TestCaseGroup* createOpQuantizeTests(tcu::TestContext& testCtx)
6828 de::MovePtr<tcu::TestCaseGroup> opQuantizeTests (new tcu::TestCaseGroup(testCtx, "opquantize", "Test OpQuantizeToF16"));
6829 createOpQuantizeSingleOptionTests(opQuantizeTests.get());
6830 createOpQuantizeTwoPossibilityTests(opQuantizeTests.get());
6831 return opQuantizeTests.release();
6834 struct ShaderPermutation
6836 deUint8 vertexPermutation;
6837 deUint8 geometryPermutation;
6838 deUint8 tesscPermutation;
6839 deUint8 tessePermutation;
6840 deUint8 fragmentPermutation;
6843 ShaderPermutation getShaderPermutation(deUint8 inputValue)
6845 ShaderPermutation permutation =
6847 static_cast<deUint8>(inputValue & 0x10? 1u: 0u),
6848 static_cast<deUint8>(inputValue & 0x08? 1u: 0u),
6849 static_cast<deUint8>(inputValue & 0x04? 1u: 0u),
6850 static_cast<deUint8>(inputValue & 0x02? 1u: 0u),
6851 static_cast<deUint8>(inputValue & 0x01? 1u: 0u)
6856 tcu::TestCaseGroup* createModuleTests(tcu::TestContext& testCtx)
6858 RGBA defaultColors[4];
6859 RGBA invertedColors[4];
6860 de::MovePtr<tcu::TestCaseGroup> moduleTests (new tcu::TestCaseGroup(testCtx, "module", "Multiple entry points into shaders"));
6862 const ShaderElement combinedPipeline[] =
6864 ShaderElement("module", "main", VK_SHADER_STAGE_VERTEX_BIT),
6865 ShaderElement("module", "main", VK_SHADER_STAGE_GEOMETRY_BIT),
6866 ShaderElement("module", "main", VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT),
6867 ShaderElement("module", "main", VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT),
6868 ShaderElement("module", "main", VK_SHADER_STAGE_FRAGMENT_BIT)
6871 getDefaultColors(defaultColors);
6872 getInvertedDefaultColors(invertedColors);
6873 addFunctionCaseWithPrograms<InstanceContext>(
6874 moduleTests.get(), "same_module", "", createCombinedModule, runAndVerifyDefaultPipeline,
6875 createInstanceContext(combinedPipeline, map<string, string>()));
6877 const char* numbers[] =
6882 for (deInt8 idx = 0; idx < 32; ++idx)
6884 ShaderPermutation permutation = getShaderPermutation(idx);
6885 string name = string("vert") + numbers[permutation.vertexPermutation] + "_geom" + numbers[permutation.geometryPermutation] + "_tessc" + numbers[permutation.tesscPermutation] + "_tesse" + numbers[permutation.tessePermutation] + "_frag" + numbers[permutation.fragmentPermutation];
6886 const ShaderElement pipeline[] =
6888 ShaderElement("vert", string("vert") + numbers[permutation.vertexPermutation], VK_SHADER_STAGE_VERTEX_BIT),
6889 ShaderElement("geom", string("geom") + numbers[permutation.geometryPermutation], VK_SHADER_STAGE_GEOMETRY_BIT),
6890 ShaderElement("tessc", string("tessc") + numbers[permutation.tesscPermutation], VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT),
6891 ShaderElement("tesse", string("tesse") + numbers[permutation.tessePermutation], VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT),
6892 ShaderElement("frag", string("frag") + numbers[permutation.fragmentPermutation], VK_SHADER_STAGE_FRAGMENT_BIT)
6895 // If there are an even number of swaps, then it should be no-op.
6896 // If there are an odd number, the color should be flipped.
6897 if ((permutation.vertexPermutation + permutation.geometryPermutation + permutation.tesscPermutation + permutation.tessePermutation + permutation.fragmentPermutation) % 2 == 0)
6899 addFunctionCaseWithPrograms<InstanceContext>(
6900 moduleTests.get(), name, "", createMultipleEntries, runAndVerifyDefaultPipeline,
6901 createInstanceContext(pipeline, defaultColors, defaultColors, map<string, string>()));
6905 addFunctionCaseWithPrograms<InstanceContext>(
6906 moduleTests.get(), name, "", createMultipleEntries, runAndVerifyDefaultPipeline,
6907 createInstanceContext(pipeline, defaultColors, invertedColors, map<string, string>()));
6910 return moduleTests.release();
6913 tcu::TestCaseGroup* createLoopTests(tcu::TestContext& testCtx)
6915 de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, "loop", "Looping control flow"));
6916 RGBA defaultColors[4];
6917 getDefaultColors(defaultColors);
6918 map<string, string> fragments;
6919 fragments["pre_main"] =
6920 "%c_f32_5 = OpConstant %f32 5.\n";
6922 // A loop with a single block. The Continue Target is the loop block
6923 // itself. In SPIR-V terms, the "loop construct" contains no blocks at all
6924 // -- the "continue construct" forms the entire loop.
6925 fragments["testfun"] =
6926 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6927 "%param1 = OpFunctionParameter %v4f32\n"
6929 "%entry = OpLabel\n"
6930 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
6933 ";adds and subtracts 1.0 to %val in alternate iterations\n"
6935 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %loop\n"
6936 "%delta = OpPhi %f32 %c_f32_1 %entry %minus_delta %loop\n"
6937 "%val1 = OpPhi %f32 %val0 %entry %val %loop\n"
6938 "%val = OpFAdd %f32 %val1 %delta\n"
6939 "%minus_delta = OpFSub %f32 %c_f32_0 %delta\n"
6940 "%count__ = OpISub %i32 %count %c_i32_1\n"
6941 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
6942 "OpLoopMerge %exit %loop None\n"
6943 "OpBranchConditional %again %loop %exit\n"
6946 "%result = OpVectorInsertDynamic %v4f32 %param1 %val %c_i32_0\n"
6947 "OpReturnValue %result\n"
6951 createTestsForAllStages("single_block", defaultColors, defaultColors, fragments, testGroup.get());
6953 // Body comprised of multiple basic blocks.
6954 const StringTemplate multiBlock(
6955 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6956 "%param1 = OpFunctionParameter %v4f32\n"
6958 "%entry = OpLabel\n"
6959 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
6962 ";adds and subtracts 1.0 to %val in alternate iterations\n"
6964 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %gather\n"
6965 "%delta = OpPhi %f32 %c_f32_1 %entry %delta_next %gather\n"
6966 "%val1 = OpPhi %f32 %val0 %entry %val %gather\n"
6967 // There are several possibilities for the Continue Target below. Each
6968 // will be specialized into a separate test case.
6969 "OpLoopMerge %exit ${continue_target} None\n"
6973 ";delta_next = (delta > 0) ? -1 : 1;\n"
6974 "%gt0 = OpFOrdGreaterThan %bool %delta %c_f32_0\n"
6975 "OpSelectionMerge %gather DontFlatten\n"
6976 "OpBranchConditional %gt0 %even %odd ;tells us if %count is even or odd\n"
6979 "OpBranch %gather\n"
6982 "OpBranch %gather\n"
6984 "%gather = OpLabel\n"
6985 "%delta_next = OpPhi %f32 %c_f32_n1 %even %c_f32_1 %odd\n"
6986 "%val = OpFAdd %f32 %val1 %delta\n"
6987 "%count__ = OpISub %i32 %count %c_i32_1\n"
6988 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
6989 "OpBranchConditional %again %loop %exit\n"
6992 "%result = OpVectorInsertDynamic %v4f32 %param1 %val %c_i32_0\n"
6993 "OpReturnValue %result\n"
6997 map<string, string> continue_target;
6999 // The Continue Target is the loop block itself.
7000 continue_target["continue_target"] = "%loop";
7001 fragments["testfun"] = multiBlock.specialize(continue_target);
7002 createTestsForAllStages("multi_block_continue_construct", defaultColors, defaultColors, fragments, testGroup.get());
7004 // The Continue Target is at the end of the loop.
7005 continue_target["continue_target"] = "%gather";
7006 fragments["testfun"] = multiBlock.specialize(continue_target);
7007 createTestsForAllStages("multi_block_loop_construct", defaultColors, defaultColors, fragments, testGroup.get());
7009 // A loop with continue statement.
7010 fragments["testfun"] =
7011 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
7012 "%param1 = OpFunctionParameter %v4f32\n"
7014 "%entry = OpLabel\n"
7015 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
7018 ";adds 4, 3, and 1 to %val0 (skips 2)\n"
7020 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %continue\n"
7021 "%val1 = OpPhi %f32 %val0 %entry %val %continue\n"
7022 "OpLoopMerge %exit %continue None\n"
7026 ";skip if %count==2\n"
7027 "%eq2 = OpIEqual %bool %count %c_i32_2\n"
7028 "OpSelectionMerge %continue DontFlatten\n"
7029 "OpBranchConditional %eq2 %continue %body\n"
7032 "%fcount = OpConvertSToF %f32 %count\n"
7033 "%val2 = OpFAdd %f32 %val1 %fcount\n"
7034 "OpBranch %continue\n"
7036 "%continue = OpLabel\n"
7037 "%val = OpPhi %f32 %val2 %body %val1 %if\n"
7038 "%count__ = OpISub %i32 %count %c_i32_1\n"
7039 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
7040 "OpBranchConditional %again %loop %exit\n"
7043 "%same = OpFSub %f32 %val %c_f32_8\n"
7044 "%result = OpVectorInsertDynamic %v4f32 %param1 %same %c_i32_0\n"
7045 "OpReturnValue %result\n"
7047 createTestsForAllStages("continue", defaultColors, defaultColors, fragments, testGroup.get());
7049 // A loop with break.
7050 fragments["testfun"] =
7051 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
7052 "%param1 = OpFunctionParameter %v4f32\n"
7054 "%entry = OpLabel\n"
7055 ";param1 components are between 0 and 1, so dot product is 4 or less\n"
7056 "%dot = OpDot %f32 %param1 %param1\n"
7057 "%div = OpFDiv %f32 %dot %c_f32_5\n"
7058 "%zero = OpConvertFToU %u32 %div\n"
7059 "%two = OpIAdd %i32 %zero %c_i32_2\n"
7060 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
7063 ";adds 4 and 3 to %val0 (exits early)\n"
7065 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %continue\n"
7066 "%val1 = OpPhi %f32 %val0 %entry %val2 %continue\n"
7067 "OpLoopMerge %exit %continue None\n"
7071 ";end loop if %count==%two\n"
7072 "%above2 = OpSGreaterThan %bool %count %two\n"
7073 "OpSelectionMerge %continue DontFlatten\n"
7074 "OpBranchConditional %above2 %body %exit\n"
7077 "%fcount = OpConvertSToF %f32 %count\n"
7078 "%val2 = OpFAdd %f32 %val1 %fcount\n"
7079 "OpBranch %continue\n"
7081 "%continue = OpLabel\n"
7082 "%count__ = OpISub %i32 %count %c_i32_1\n"
7083 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
7084 "OpBranchConditional %again %loop %exit\n"
7087 "%val_post = OpPhi %f32 %val2 %continue %val1 %if\n"
7088 "%same = OpFSub %f32 %val_post %c_f32_7\n"
7089 "%result = OpVectorInsertDynamic %v4f32 %param1 %same %c_i32_0\n"
7090 "OpReturnValue %result\n"
7092 createTestsForAllStages("break", defaultColors, defaultColors, fragments, testGroup.get());
7094 // A loop with return.
7095 fragments["testfun"] =
7096 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
7097 "%param1 = OpFunctionParameter %v4f32\n"
7099 "%entry = OpLabel\n"
7100 ";param1 components are between 0 and 1, so dot product is 4 or less\n"
7101 "%dot = OpDot %f32 %param1 %param1\n"
7102 "%div = OpFDiv %f32 %dot %c_f32_5\n"
7103 "%zero = OpConvertFToU %u32 %div\n"
7104 "%two = OpIAdd %i32 %zero %c_i32_2\n"
7105 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
7108 ";returns early without modifying %param1\n"
7110 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %continue\n"
7111 "%val1 = OpPhi %f32 %val0 %entry %val2 %continue\n"
7112 "OpLoopMerge %exit %continue None\n"
7116 ";return if %count==%two\n"
7117 "%above2 = OpSGreaterThan %bool %count %two\n"
7118 "OpSelectionMerge %continue DontFlatten\n"
7119 "OpBranchConditional %above2 %body %early_exit\n"
7121 "%early_exit = OpLabel\n"
7122 "OpReturnValue %param1\n"
7125 "%fcount = OpConvertSToF %f32 %count\n"
7126 "%val2 = OpFAdd %f32 %val1 %fcount\n"
7127 "OpBranch %continue\n"
7129 "%continue = OpLabel\n"
7130 "%count__ = OpISub %i32 %count %c_i32_1\n"
7131 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
7132 "OpBranchConditional %again %loop %exit\n"
7135 ";should never get here, so return an incorrect result\n"
7136 "%result = OpVectorInsertDynamic %v4f32 %param1 %val2 %c_i32_0\n"
7137 "OpReturnValue %result\n"
7139 createTestsForAllStages("return", defaultColors, defaultColors, fragments, testGroup.get());
7141 return testGroup.release();
7144 // A collection of tests putting OpControlBarrier in places GLSL forbids but SPIR-V allows.
7145 tcu::TestCaseGroup* createBarrierTests(tcu::TestContext& testCtx)
7147 de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, "barrier", "OpControlBarrier"));
7148 map<string, string> fragments;
7150 // A barrier inside a function body.
7151 fragments["pre_main"] =
7152 "%Workgroup = OpConstant %i32 2\n"
7153 "%SequentiallyConsistent = OpConstant %i32 0x10\n";
7154 fragments["testfun"] =
7155 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
7156 "%param1 = OpFunctionParameter %v4f32\n"
7157 "%label_testfun = OpLabel\n"
7158 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n"
7159 "OpReturnValue %param1\n"
7161 addTessCtrlTest(testGroup.get(), "in_function", fragments);
7163 // Common setup code for the following tests.
7164 fragments["pre_main"] =
7165 "%Workgroup = OpConstant %i32 2\n"
7166 "%SequentiallyConsistent = OpConstant %i32 0x10\n"
7167 "%c_f32_5 = OpConstant %f32 5.\n";
7168 const string setupPercentZero = // Begins %test_code function with code that sets %zero to 0u but cannot be optimized away.
7169 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
7170 "%param1 = OpFunctionParameter %v4f32\n"
7171 "%entry = OpLabel\n"
7172 ";param1 components are between 0 and 1, so dot product is 4 or less\n"
7173 "%dot = OpDot %f32 %param1 %param1\n"
7174 "%div = OpFDiv %f32 %dot %c_f32_5\n"
7175 "%zero = OpConvertFToU %u32 %div\n";
7177 // Barriers inside OpSwitch branches.
7178 fragments["testfun"] =
7180 "OpSelectionMerge %switch_exit None\n"
7181 "OpSwitch %zero %switch_default 0 %case0 1 %case1 ;should always go to %case0\n"
7183 "%case1 = OpLabel\n"
7184 ";This barrier should never be executed, but its presence makes test failure more likely when there's a bug.\n"
7185 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n"
7186 "%wrong_branch_alert1 = OpVectorInsertDynamic %v4f32 %param1 %c_f32_0_5 %c_i32_0\n"
7187 "OpBranch %switch_exit\n"
7189 "%switch_default = OpLabel\n"
7190 "%wrong_branch_alert2 = OpVectorInsertDynamic %v4f32 %param1 %c_f32_0_5 %c_i32_0\n"
7191 ";This barrier should never be executed, but its presence makes test failure more likely when there's a bug.\n"
7192 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n"
7193 "OpBranch %switch_exit\n"
7195 "%case0 = OpLabel\n"
7196 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n"
7197 "OpBranch %switch_exit\n"
7199 "%switch_exit = OpLabel\n"
7200 "%ret = OpPhi %v4f32 %param1 %case0 %wrong_branch_alert1 %case1 %wrong_branch_alert2 %switch_default\n"
7201 "OpReturnValue %ret\n"
7203 addTessCtrlTest(testGroup.get(), "in_switch", fragments);
7205 // Barriers inside if-then-else.
7206 fragments["testfun"] =
7208 "%eq0 = OpIEqual %bool %zero %c_u32_0\n"
7209 "OpSelectionMerge %exit DontFlatten\n"
7210 "OpBranchConditional %eq0 %then %else\n"
7213 ";This barrier should never be executed, but its presence makes test failure more likely when there's a bug.\n"
7214 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n"
7215 "%wrong_branch_alert = OpVectorInsertDynamic %v4f32 %param1 %c_f32_0_5 %c_i32_0\n"
7219 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n"
7223 "%ret = OpPhi %v4f32 %param1 %then %wrong_branch_alert %else\n"
7224 "OpReturnValue %ret\n"
7226 addTessCtrlTest(testGroup.get(), "in_if", fragments);
7228 // A barrier after control-flow reconvergence, tempting the compiler to attempt something like this:
7229 // http://lists.llvm.org/pipermail/llvm-dev/2009-October/026317.html.
7230 fragments["testfun"] =
7232 "%thread_id = OpLoad %i32 %BP_gl_InvocationID\n"
7233 "%thread0 = OpIEqual %bool %thread_id %c_i32_0\n"
7234 "OpSelectionMerge %exit DontFlatten\n"
7235 "OpBranchConditional %thread0 %then %else\n"
7238 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
7242 "%val1 = OpVectorExtractDynamic %f32 %param1 %zero\n"
7246 "%val = OpPhi %f32 %val0 %else %val1 %then\n"
7247 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n"
7248 "%ret = OpVectorInsertDynamic %v4f32 %param1 %val %zero\n"
7249 "OpReturnValue %ret\n"
7251 addTessCtrlTest(testGroup.get(), "after_divergent_if", fragments);
7253 // A barrier inside a loop.
7254 fragments["pre_main"] =
7255 "%Workgroup = OpConstant %i32 2\n"
7256 "%SequentiallyConsistent = OpConstant %i32 0x10\n"
7257 "%c_f32_10 = OpConstant %f32 10.\n";
7258 fragments["testfun"] =
7259 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
7260 "%param1 = OpFunctionParameter %v4f32\n"
7261 "%entry = OpLabel\n"
7262 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
7265 ";adds 4, 3, 2, and 1 to %val0\n"
7267 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %loop\n"
7268 "%val1 = OpPhi %f32 %val0 %entry %val %loop\n"
7269 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n"
7270 "%fcount = OpConvertSToF %f32 %count\n"
7271 "%val = OpFAdd %f32 %val1 %fcount\n"
7272 "%count__ = OpISub %i32 %count %c_i32_1\n"
7273 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
7274 "OpLoopMerge %exit %loop None\n"
7275 "OpBranchConditional %again %loop %exit\n"
7278 "%same = OpFSub %f32 %val %c_f32_10\n"
7279 "%ret = OpVectorInsertDynamic %v4f32 %param1 %same %c_i32_0\n"
7280 "OpReturnValue %ret\n"
7282 addTessCtrlTest(testGroup.get(), "in_loop", fragments);
7284 return testGroup.release();
7287 // Test for the OpFRem instruction.
7288 tcu::TestCaseGroup* createFRemTests(tcu::TestContext& testCtx)
7290 de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, "frem", "OpFRem"));
7291 map<string, string> fragments;
7292 RGBA inputColors[4];
7293 RGBA outputColors[4];
7295 fragments["pre_main"] =
7296 "%c_f32_3 = OpConstant %f32 3.0\n"
7297 "%c_f32_n3 = OpConstant %f32 -3.0\n"
7298 "%c_f32_4 = OpConstant %f32 4.0\n"
7299 "%c_f32_p75 = OpConstant %f32 0.75\n"
7300 "%c_v4f32_p75_p75_p75_p75 = OpConstantComposite %v4f32 %c_f32_p75 %c_f32_p75 %c_f32_p75 %c_f32_p75 \n"
7301 "%c_v4f32_4_4_4_4 = OpConstantComposite %v4f32 %c_f32_4 %c_f32_4 %c_f32_4 %c_f32_4\n"
7302 "%c_v4f32_3_n3_3_n3 = OpConstantComposite %v4f32 %c_f32_3 %c_f32_n3 %c_f32_3 %c_f32_n3\n";
7304 // The test does the following.
7305 // vec4 result = (param1 * 8.0) - 4.0;
7306 // return (frem(result.x,3) + 0.75, frem(result.y, -3) + 0.75, 0, 1)
7307 fragments["testfun"] =
7308 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
7309 "%param1 = OpFunctionParameter %v4f32\n"
7310 "%label_testfun = OpLabel\n"
7311 "%v_times_8 = OpVectorTimesScalar %v4f32 %param1 %c_f32_8\n"
7312 "%minus_4 = OpFSub %v4f32 %v_times_8 %c_v4f32_4_4_4_4\n"
7313 "%frem = OpFRem %v4f32 %minus_4 %c_v4f32_3_n3_3_n3\n"
7314 "%added = OpFAdd %v4f32 %frem %c_v4f32_p75_p75_p75_p75\n"
7315 "%xyz_1 = OpVectorInsertDynamic %v4f32 %added %c_f32_1 %c_i32_3\n"
7316 "%xy_0_1 = OpVectorInsertDynamic %v4f32 %xyz_1 %c_f32_0 %c_i32_2\n"
7317 "OpReturnValue %xy_0_1\n"
7321 inputColors[0] = RGBA(16, 16, 0, 255);
7322 inputColors[1] = RGBA(232, 232, 0, 255);
7323 inputColors[2] = RGBA(232, 16, 0, 255);
7324 inputColors[3] = RGBA(16, 232, 0, 255);
7326 outputColors[0] = RGBA(64, 64, 0, 255);
7327 outputColors[1] = RGBA(255, 255, 0, 255);
7328 outputColors[2] = RGBA(255, 64, 0, 255);
7329 outputColors[3] = RGBA(64, 255, 0, 255);
7331 createTestsForAllStages("frem", inputColors, outputColors, fragments, testGroup.get());
7332 return testGroup.release();
7335 // Test for the OpSRem instruction.
7336 tcu::TestCaseGroup* createOpSRemGraphicsTests(tcu::TestContext& testCtx, qpTestResult negFailResult)
7338 de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, "srem", "OpSRem"));
7339 map<string, string> fragments;
7341 fragments["pre_main"] =
7342 "%c_f32_255 = OpConstant %f32 255.0\n"
7343 "%c_i32_128 = OpConstant %i32 128\n"
7344 "%c_i32_255 = OpConstant %i32 255\n"
7345 "%c_v4f32_255 = OpConstantComposite %v4f32 %c_f32_255 %c_f32_255 %c_f32_255 %c_f32_255 \n"
7346 "%c_v4f32_0_5 = OpConstantComposite %v4f32 %c_f32_0_5 %c_f32_0_5 %c_f32_0_5 %c_f32_0_5 \n"
7347 "%c_v4i32_128 = OpConstantComposite %v4i32 %c_i32_128 %c_i32_128 %c_i32_128 %c_i32_128 \n";
7349 // The test does the following.
7350 // ivec4 ints = int(param1 * 255.0 + 0.5) - 128;
7351 // ivec4 result = ivec4(srem(ints.x, ints.y), srem(ints.y, ints.z), srem(ints.z, ints.x), 255);
7352 // return float(result + 128) / 255.0;
7353 fragments["testfun"] =
7354 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
7355 "%param1 = OpFunctionParameter %v4f32\n"
7356 "%label_testfun = OpLabel\n"
7357 "%div255 = OpFMul %v4f32 %param1 %c_v4f32_255\n"
7358 "%add0_5 = OpFAdd %v4f32 %div255 %c_v4f32_0_5\n"
7359 "%uints_in = OpConvertFToS %v4i32 %add0_5\n"
7360 "%ints_in = OpISub %v4i32 %uints_in %c_v4i32_128\n"
7361 "%x_in = OpCompositeExtract %i32 %ints_in 0\n"
7362 "%y_in = OpCompositeExtract %i32 %ints_in 1\n"
7363 "%z_in = OpCompositeExtract %i32 %ints_in 2\n"
7364 "%x_out = OpSRem %i32 %x_in %y_in\n"
7365 "%y_out = OpSRem %i32 %y_in %z_in\n"
7366 "%z_out = OpSRem %i32 %z_in %x_in\n"
7367 "%ints_out = OpCompositeConstruct %v4i32 %x_out %y_out %z_out %c_i32_255\n"
7368 "%ints_offset = OpIAdd %v4i32 %ints_out %c_v4i32_128\n"
7369 "%f_ints_offset = OpConvertSToF %v4f32 %ints_offset\n"
7370 "%float_out = OpFDiv %v4f32 %f_ints_offset %c_v4f32_255\n"
7371 "OpReturnValue %float_out\n"
7374 const struct CaseParams
7377 const char* failMessageTemplate; // customized status message
7378 qpTestResult failResult; // override status on failure
7379 int operands[4][3]; // four (x, y, z) vectors of operands
7380 int results[4][3]; // four (x, y, z) vectors of results
7386 QP_TEST_RESULT_FAIL,
7387 { { 5, 12, 17 }, { 5, 5, 7 }, { 75, 8, 81 }, { 25, 60, 100 } }, // operands
7388 { { 5, 12, 2 }, { 0, 5, 2 }, { 3, 8, 6 }, { 25, 60, 0 } }, // results
7392 "Inconsistent results, but within specification: ${reason}",
7393 negFailResult, // negative operands, not required by the spec
7394 { { 5, 12, -17 }, { -5, -5, 7 }, { 75, 8, -81 }, { 25, -60, 100 } }, // operands
7395 { { 5, 12, -2 }, { 0, -5, 2 }, { 3, 8, -6 }, { 25, -60, 0 } }, // results
7398 // If either operand is negative the result is undefined. Some implementations may still return correct values.
7400 for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(cases); ++caseNdx)
7402 const CaseParams& params = cases[caseNdx];
7403 RGBA inputColors[4];
7404 RGBA outputColors[4];
7406 for (int i = 0; i < 4; ++i)
7408 inputColors [i] = RGBA(params.operands[i][0] + 128, params.operands[i][1] + 128, params.operands[i][2] + 128, 255);
7409 outputColors[i] = RGBA(params.results [i][0] + 128, params.results [i][1] + 128, params.results [i][2] + 128, 255);
7412 createTestsForAllStages(params.name, inputColors, outputColors, fragments, testGroup.get(), params.failResult, params.failMessageTemplate);
7415 return testGroup.release();
7418 // Test for the OpSMod instruction.
7419 tcu::TestCaseGroup* createOpSModGraphicsTests(tcu::TestContext& testCtx, qpTestResult negFailResult)
7421 de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, "smod", "OpSMod"));
7422 map<string, string> fragments;
7424 fragments["pre_main"] =
7425 "%c_f32_255 = OpConstant %f32 255.0\n"
7426 "%c_i32_128 = OpConstant %i32 128\n"
7427 "%c_i32_255 = OpConstant %i32 255\n"
7428 "%c_v4f32_255 = OpConstantComposite %v4f32 %c_f32_255 %c_f32_255 %c_f32_255 %c_f32_255 \n"
7429 "%c_v4f32_0_5 = OpConstantComposite %v4f32 %c_f32_0_5 %c_f32_0_5 %c_f32_0_5 %c_f32_0_5 \n"
7430 "%c_v4i32_128 = OpConstantComposite %v4i32 %c_i32_128 %c_i32_128 %c_i32_128 %c_i32_128 \n";
7432 // The test does the following.
7433 // ivec4 ints = int(param1 * 255.0 + 0.5) - 128;
7434 // ivec4 result = ivec4(smod(ints.x, ints.y), smod(ints.y, ints.z), smod(ints.z, ints.x), 255);
7435 // return float(result + 128) / 255.0;
7436 fragments["testfun"] =
7437 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
7438 "%param1 = OpFunctionParameter %v4f32\n"
7439 "%label_testfun = OpLabel\n"
7440 "%div255 = OpFMul %v4f32 %param1 %c_v4f32_255\n"
7441 "%add0_5 = OpFAdd %v4f32 %div255 %c_v4f32_0_5\n"
7442 "%uints_in = OpConvertFToS %v4i32 %add0_5\n"
7443 "%ints_in = OpISub %v4i32 %uints_in %c_v4i32_128\n"
7444 "%x_in = OpCompositeExtract %i32 %ints_in 0\n"
7445 "%y_in = OpCompositeExtract %i32 %ints_in 1\n"
7446 "%z_in = OpCompositeExtract %i32 %ints_in 2\n"
7447 "%x_out = OpSMod %i32 %x_in %y_in\n"
7448 "%y_out = OpSMod %i32 %y_in %z_in\n"
7449 "%z_out = OpSMod %i32 %z_in %x_in\n"
7450 "%ints_out = OpCompositeConstruct %v4i32 %x_out %y_out %z_out %c_i32_255\n"
7451 "%ints_offset = OpIAdd %v4i32 %ints_out %c_v4i32_128\n"
7452 "%f_ints_offset = OpConvertSToF %v4f32 %ints_offset\n"
7453 "%float_out = OpFDiv %v4f32 %f_ints_offset %c_v4f32_255\n"
7454 "OpReturnValue %float_out\n"
7457 const struct CaseParams
7460 const char* failMessageTemplate; // customized status message
7461 qpTestResult failResult; // override status on failure
7462 int operands[4][3]; // four (x, y, z) vectors of operands
7463 int results[4][3]; // four (x, y, z) vectors of results
7469 QP_TEST_RESULT_FAIL,
7470 { { 5, 12, 17 }, { 5, 5, 7 }, { 75, 8, 81 }, { 25, 60, 100 } }, // operands
7471 { { 5, 12, 2 }, { 0, 5, 2 }, { 3, 8, 6 }, { 25, 60, 0 } }, // results
7475 "Inconsistent results, but within specification: ${reason}",
7476 negFailResult, // negative operands, not required by the spec
7477 { { 5, 12, -17 }, { -5, -5, 7 }, { 75, 8, -81 }, { 25, -60, 100 } }, // operands
7478 { { 5, -5, 3 }, { 0, 2, -3 }, { 3, -73, 69 }, { -35, 40, 0 } }, // results
7481 // If either operand is negative the result is undefined. Some implementations may still return correct values.
7483 for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(cases); ++caseNdx)
7485 const CaseParams& params = cases[caseNdx];
7486 RGBA inputColors[4];
7487 RGBA outputColors[4];
7489 for (int i = 0; i < 4; ++i)
7491 inputColors [i] = RGBA(params.operands[i][0] + 128, params.operands[i][1] + 128, params.operands[i][2] + 128, 255);
7492 outputColors[i] = RGBA(params.results [i][0] + 128, params.results [i][1] + 128, params.results [i][2] + 128, 255);
7495 createTestsForAllStages(params.name, inputColors, outputColors, fragments, testGroup.get(), params.failResult, params.failMessageTemplate);
7498 return testGroup.release();
7503 INTEGER_TYPE_SIGNED_16,
7504 INTEGER_TYPE_SIGNED_32,
7505 INTEGER_TYPE_SIGNED_64,
7507 INTEGER_TYPE_UNSIGNED_16,
7508 INTEGER_TYPE_UNSIGNED_32,
7509 INTEGER_TYPE_UNSIGNED_64,
7512 const string getBitWidthStr (IntegerType type)
7516 case INTEGER_TYPE_SIGNED_16:
7517 case INTEGER_TYPE_UNSIGNED_16: return "16";
7519 case INTEGER_TYPE_SIGNED_32:
7520 case INTEGER_TYPE_UNSIGNED_32: return "32";
7522 case INTEGER_TYPE_SIGNED_64:
7523 case INTEGER_TYPE_UNSIGNED_64: return "64";
7525 default: DE_ASSERT(false);
7530 const string getByteWidthStr (IntegerType type)
7534 case INTEGER_TYPE_SIGNED_16:
7535 case INTEGER_TYPE_UNSIGNED_16: return "2";
7537 case INTEGER_TYPE_SIGNED_32:
7538 case INTEGER_TYPE_UNSIGNED_32: return "4";
7540 case INTEGER_TYPE_SIGNED_64:
7541 case INTEGER_TYPE_UNSIGNED_64: return "8";
7543 default: DE_ASSERT(false);
7548 bool isSigned (IntegerType type)
7550 return (type <= INTEGER_TYPE_SIGNED_64);
7553 const string getTypeName (IntegerType type)
7555 string prefix = isSigned(type) ? "" : "u";
7556 return prefix + "int" + getBitWidthStr(type);
7559 const string getTestName (IntegerType from, IntegerType to)
7561 return getTypeName(from) + "_to_" + getTypeName(to);
7564 const string getAsmTypeDeclaration (IntegerType type)
7566 string sign = isSigned(type) ? " 1" : " 0";
7567 return "OpTypeInt " + getBitWidthStr(type) + sign;
7570 const string getAsmTypeName (IntegerType type)
7572 const string prefix = isSigned(type) ? "%i" : "%u";
7573 return prefix + getBitWidthStr(type);
7576 template<typename T>
7577 BufferSp getSpecializedBuffer (deInt64 number)
7579 return BufferSp(new Buffer<T>(vector<T>(1, (T)number)));
7582 BufferSp getBuffer (IntegerType type, deInt64 number)
7586 case INTEGER_TYPE_SIGNED_16: return getSpecializedBuffer<deInt16>(number);
7587 case INTEGER_TYPE_SIGNED_32: return getSpecializedBuffer<deInt32>(number);
7588 case INTEGER_TYPE_SIGNED_64: return getSpecializedBuffer<deInt64>(number);
7590 case INTEGER_TYPE_UNSIGNED_16: return getSpecializedBuffer<deUint16>(number);
7591 case INTEGER_TYPE_UNSIGNED_32: return getSpecializedBuffer<deUint32>(number);
7592 case INTEGER_TYPE_UNSIGNED_64: return getSpecializedBuffer<deUint64>(number);
7594 default: DE_ASSERT(false);
7595 return BufferSp(new Buffer<deInt32>(vector<deInt32>(1, 0)));
7599 bool usesInt16 (IntegerType from, IntegerType to)
7601 return (from == INTEGER_TYPE_SIGNED_16 || from == INTEGER_TYPE_UNSIGNED_16
7602 || to == INTEGER_TYPE_SIGNED_16 || to == INTEGER_TYPE_UNSIGNED_16);
7605 bool usesInt64 (IntegerType from, IntegerType to)
7607 return (from == INTEGER_TYPE_SIGNED_64 || from == INTEGER_TYPE_UNSIGNED_64
7608 || to == INTEGER_TYPE_SIGNED_64 || to == INTEGER_TYPE_UNSIGNED_64);
7611 ComputeTestFeatures getConversionUsedFeatures (IntegerType from, IntegerType to)
7613 if (usesInt16(from, to))
7615 if (usesInt64(from, to))
7617 return COMPUTE_TEST_USES_INT16_INT64;
7621 return COMPUTE_TEST_USES_INT16;
7626 return COMPUTE_TEST_USES_INT64;
7632 ConvertCase (IntegerType from, IntegerType to, deInt64 number)
7635 , m_features (getConversionUsedFeatures(from, to))
7636 , m_name (getTestName(from, to))
7637 , m_inputBuffer (getBuffer(from, number))
7638 , m_outputBuffer (getBuffer(to, number))
7640 m_asmTypes["inputType"] = getAsmTypeName(from);
7641 m_asmTypes["outputType"] = getAsmTypeName(to);
7643 if (m_features == COMPUTE_TEST_USES_INT16)
7645 m_asmTypes["int_capabilities"] = "OpCapability Int16\n";
7646 m_asmTypes["int_additional_decl"] = "%i16 = OpTypeInt 16 1\n%u16 = OpTypeInt 16 0\n";
7648 else if (m_features == COMPUTE_TEST_USES_INT64)
7650 m_asmTypes["int_capabilities"] = "OpCapability Int64\n";
7651 m_asmTypes["int_additional_decl"] = "%i64 = OpTypeInt 64 1\n%u64 = OpTypeInt 64 0\n";
7653 else if (m_features == COMPUTE_TEST_USES_INT16_INT64)
7655 m_asmTypes["int_capabilities"] = string("OpCapability Int16\n") +
7656 "OpCapability Int64\n";
7657 m_asmTypes["int_additional_decl"] = "%i16 = OpTypeInt 16 1\n%u16 = OpTypeInt 16 0\n"
7658 "%i64 = OpTypeInt 64 1\n%u64 = OpTypeInt 64 0\n";
7666 IntegerType m_fromType;
7667 IntegerType m_toType;
7668 ComputeTestFeatures m_features;
7670 map<string, string> m_asmTypes;
7671 BufferSp m_inputBuffer;
7672 BufferSp m_outputBuffer;
7675 const string getConvertCaseShaderStr (const string& instruction, const ConvertCase& convertCase)
7677 map<string, string> params = convertCase.m_asmTypes;
7679 params["instruction"] = instruction;
7681 params["inDecorator"] = getByteWidthStr(convertCase.m_fromType);
7682 params["outDecorator"] = getByteWidthStr(convertCase.m_toType);
7684 const StringTemplate shader (
7685 "OpCapability Shader\n"
7686 "${int_capabilities}"
7687 "OpMemoryModel Logical GLSL450\n"
7688 "OpEntryPoint GLCompute %main \"main\" %id\n"
7689 "OpExecutionMode %main LocalSize 1 1 1\n"
7690 "OpSource GLSL 430\n"
7691 "OpName %main \"main\"\n"
7692 "OpName %id \"gl_GlobalInvocationID\"\n"
7694 "OpDecorate %id BuiltIn GlobalInvocationId\n"
7695 "OpDecorate %indata DescriptorSet 0\n"
7696 "OpDecorate %indata Binding 0\n"
7697 "OpDecorate %outdata DescriptorSet 0\n"
7698 "OpDecorate %outdata Binding 1\n"
7699 "OpDecorate %in_arr ArrayStride ${inDecorator}\n"
7700 "OpDecorate %out_arr ArrayStride ${outDecorator}\n"
7701 "OpDecorate %in_buf BufferBlock\n"
7702 "OpDecorate %out_buf BufferBlock\n"
7703 "OpMemberDecorate %in_buf 0 Offset 0\n"
7704 "OpMemberDecorate %out_buf 0 Offset 0\n"
7706 "%void = OpTypeVoid\n"
7707 "%voidf = OpTypeFunction %void\n"
7708 "%u32 = OpTypeInt 32 0\n"
7709 "%i32 = OpTypeInt 32 1\n"
7710 "${int_additional_decl}"
7711 "%uvec3 = OpTypeVector %u32 3\n"
7712 "%uvec3ptr = OpTypePointer Input %uvec3\n"
7714 "%in_ptr = OpTypePointer Uniform ${inputType}\n"
7715 "%out_ptr = OpTypePointer Uniform ${outputType}\n"
7716 "%in_arr = OpTypeRuntimeArray ${inputType}\n"
7717 "%out_arr = OpTypeRuntimeArray ${outputType}\n"
7718 "%in_buf = OpTypeStruct %in_arr\n"
7719 "%out_buf = OpTypeStruct %out_arr\n"
7720 "%in_bufptr = OpTypePointer Uniform %in_buf\n"
7721 "%out_bufptr = OpTypePointer Uniform %out_buf\n"
7722 "%indata = OpVariable %in_bufptr Uniform\n"
7723 "%outdata = OpVariable %out_bufptr Uniform\n"
7724 "%inputptr = OpTypePointer Input ${inputType}\n"
7725 "%id = OpVariable %uvec3ptr Input\n"
7727 "%zero = OpConstant %i32 0\n"
7729 "%main = OpFunction %void None %voidf\n"
7730 "%label = OpLabel\n"
7731 "%idval = OpLoad %uvec3 %id\n"
7732 "%x = OpCompositeExtract %u32 %idval 0\n"
7733 "%inloc = OpAccessChain %in_ptr %indata %zero %x\n"
7734 "%outloc = OpAccessChain %out_ptr %outdata %zero %x\n"
7735 "%inval = OpLoad ${inputType} %inloc\n"
7736 "%conv = ${instruction} ${outputType} %inval\n"
7737 " OpStore %outloc %conv\n"
7742 return shader.specialize(params);
7745 void createSConvertCases (vector<ConvertCase>& testCases)
7747 // Convert int to int
7748 testCases.push_back(ConvertCase(INTEGER_TYPE_SIGNED_16, INTEGER_TYPE_SIGNED_32, 14669));
7749 testCases.push_back(ConvertCase(INTEGER_TYPE_SIGNED_16, INTEGER_TYPE_SIGNED_64, 3341));
7751 testCases.push_back(ConvertCase(INTEGER_TYPE_SIGNED_32, INTEGER_TYPE_SIGNED_64, 973610259));
7753 // Convert int to unsigned int
7754 testCases.push_back(ConvertCase(INTEGER_TYPE_SIGNED_16, INTEGER_TYPE_UNSIGNED_32, 9288));
7755 testCases.push_back(ConvertCase(INTEGER_TYPE_SIGNED_16, INTEGER_TYPE_UNSIGNED_64, 15460));
7757 testCases.push_back(ConvertCase(INTEGER_TYPE_SIGNED_32, INTEGER_TYPE_UNSIGNED_64, 346213461));
7760 // Test for the OpSConvert instruction.
7761 tcu::TestCaseGroup* createSConvertTests (tcu::TestContext& testCtx)
7763 const string instruction ("OpSConvert");
7764 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "sconvert", "OpSConvert"));
7765 vector<ConvertCase> testCases;
7766 createSConvertCases(testCases);
7768 for (vector<ConvertCase>::const_iterator test = testCases.begin(); test != testCases.end(); ++test)
7770 ComputeShaderSpec spec;
7772 spec.assembly = getConvertCaseShaderStr(instruction, *test);
7773 spec.inputs.push_back(test->m_inputBuffer);
7774 spec.outputs.push_back(test->m_outputBuffer);
7775 spec.numWorkGroups = IVec3(1, 1, 1);
7777 group->addChild(new SpvAsmComputeShaderCase(testCtx, test->m_name.c_str(), "Convert integers with OpSConvert.", spec, test->m_features));
7780 return group.release();
7783 void createUConvertCases (vector<ConvertCase>& testCases)
7785 // Convert unsigned int to unsigned int
7786 testCases.push_back(ConvertCase(INTEGER_TYPE_UNSIGNED_16, INTEGER_TYPE_UNSIGNED_32, 60653));
7787 testCases.push_back(ConvertCase(INTEGER_TYPE_UNSIGNED_16, INTEGER_TYPE_UNSIGNED_64, 17991));
7789 testCases.push_back(ConvertCase(INTEGER_TYPE_UNSIGNED_32, INTEGER_TYPE_UNSIGNED_64, 904256275));
7791 // Convert unsigned int to int
7792 testCases.push_back(ConvertCase(INTEGER_TYPE_UNSIGNED_16, INTEGER_TYPE_SIGNED_32, 38002));
7793 testCases.push_back(ConvertCase(INTEGER_TYPE_UNSIGNED_16, INTEGER_TYPE_SIGNED_64, 64921));
7795 testCases.push_back(ConvertCase(INTEGER_TYPE_UNSIGNED_32, INTEGER_TYPE_SIGNED_64, 4294956295ll));
7798 // Test for the OpUConvert instruction.
7799 tcu::TestCaseGroup* createUConvertTests (tcu::TestContext& testCtx)
7801 const string instruction ("OpUConvert");
7802 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "uconvert", "OpUConvert"));
7803 vector<ConvertCase> testCases;
7804 createUConvertCases(testCases);
7806 for (vector<ConvertCase>::const_iterator test = testCases.begin(); test != testCases.end(); ++test)
7808 ComputeShaderSpec spec;
7810 spec.assembly = getConvertCaseShaderStr(instruction, *test);
7811 spec.inputs.push_back(test->m_inputBuffer);
7812 spec.outputs.push_back(test->m_outputBuffer);
7813 spec.numWorkGroups = IVec3(1, 1, 1);
7815 group->addChild(new SpvAsmComputeShaderCase(testCtx, test->m_name.c_str(), "Convert integers with OpUConvert.", spec, test->m_features));
7817 return group.release();
7820 const string getNumberTypeName (const NumberType type)
7822 if (type == NUMBERTYPE_INT32)
7826 else if (type == NUMBERTYPE_UINT32)
7830 else if (type == NUMBERTYPE_FLOAT32)
7841 deInt32 getInt(de::Random& rnd)
7843 return rnd.getInt(std::numeric_limits<int>::min(), std::numeric_limits<int>::max());
7846 const string repeatString (const string& str, int times)
7849 for (int i = 0; i < times; ++i)
7856 const string getRandomConstantString (const NumberType type, de::Random& rnd)
7858 if (type == NUMBERTYPE_INT32)
7860 return numberToString<deInt32>(getInt(rnd));
7862 else if (type == NUMBERTYPE_UINT32)
7864 return numberToString<deUint32>(rnd.getUint32());
7866 else if (type == NUMBERTYPE_FLOAT32)
7868 return numberToString<float>(rnd.getFloat());
7877 void createVectorCompositeCases (vector<map<string, string> >& testCases, de::Random& rnd, const NumberType type)
7879 map<string, string> params;
7882 for (int width = 2; width <= 4; ++width)
7884 const string randomConst = numberToString(getInt(rnd));
7885 const string widthStr = numberToString(width);
7886 const string composite_type = "${customType}vec" + widthStr;
7887 const int index = rnd.getInt(0, width-1);
7889 params["type"] = "vec";
7890 params["name"] = params["type"] + "_" + widthStr;
7891 params["compositeDecl"] = composite_type + " = OpTypeVector ${customType} " + widthStr +"\n";
7892 params["compositeType"] = composite_type;
7893 params["filler"] = string("%filler = OpConstant ${customType} ") + getRandomConstantString(type, rnd) + "\n";
7894 params["compositeConstruct"] = "%instance = OpCompositeConstruct " + composite_type + repeatString(" %filler", width) + "\n";
7895 params["indexes"] = numberToString(index);
7896 testCases.push_back(params);
7900 void createArrayCompositeCases (vector<map<string, string> >& testCases, de::Random& rnd, const NumberType type)
7902 const int limit = 10;
7903 map<string, string> params;
7905 for (int width = 2; width <= limit; ++width)
7907 string randomConst = numberToString(getInt(rnd));
7908 string widthStr = numberToString(width);
7909 int index = rnd.getInt(0, width-1);
7911 params["type"] = "array";
7912 params["name"] = params["type"] + "_" + widthStr;
7913 params["compositeDecl"] = string("%arraywidth = OpConstant %u32 " + widthStr + "\n")
7914 + "%composite = OpTypeArray ${customType} %arraywidth\n";
7915 params["compositeType"] = "%composite";
7916 params["filler"] = string("%filler = OpConstant ${customType} ") + getRandomConstantString(type, rnd) + "\n";
7917 params["compositeConstruct"] = "%instance = OpCompositeConstruct %composite" + repeatString(" %filler", width) + "\n";
7918 params["indexes"] = numberToString(index);
7919 testCases.push_back(params);
7923 void createStructCompositeCases (vector<map<string, string> >& testCases, de::Random& rnd, const NumberType type)
7925 const int limit = 10;
7926 map<string, string> params;
7928 for (int width = 2; width <= limit; ++width)
7930 string randomConst = numberToString(getInt(rnd));
7931 int index = rnd.getInt(0, width-1);
7933 params["type"] = "struct";
7934 params["name"] = params["type"] + "_" + numberToString(width);
7935 params["compositeDecl"] = "%composite = OpTypeStruct" + repeatString(" ${customType}", width) + "\n";
7936 params["compositeType"] = "%composite";
7937 params["filler"] = string("%filler = OpConstant ${customType} ") + getRandomConstantString(type, rnd) + "\n";
7938 params["compositeConstruct"] = "%instance = OpCompositeConstruct %composite" + repeatString(" %filler", width) + "\n";
7939 params["indexes"] = numberToString(index);
7940 testCases.push_back(params);
7944 void createMatrixCompositeCases (vector<map<string, string> >& testCases, de::Random& rnd, const NumberType type)
7946 map<string, string> params;
7949 for (int width = 2; width <= 4; ++width)
7951 string widthStr = numberToString(width);
7953 for (int column = 2 ; column <= 4; ++column)
7955 int index_0 = rnd.getInt(0, column-1);
7956 int index_1 = rnd.getInt(0, width-1);
7957 string columnStr = numberToString(column);
7959 params["type"] = "matrix";
7960 params["name"] = params["type"] + "_" + widthStr + "x" + columnStr;
7961 params["compositeDecl"] = string("%vectype = OpTypeVector ${customType} " + widthStr + "\n")
7962 + "%composite = OpTypeMatrix %vectype " + columnStr + "\n";
7963 params["compositeType"] = "%composite";
7965 params["filler"] = string("%filler = OpConstant ${customType} ") + getRandomConstantString(type, rnd) + "\n"
7966 + "%fillerVec = OpConstantComposite %vectype" + repeatString(" %filler", width) + "\n";
7968 params["compositeConstruct"] = "%instance = OpCompositeConstruct %composite" + repeatString(" %fillerVec", column) + "\n";
7969 params["indexes"] = numberToString(index_0) + " " + numberToString(index_1);
7970 testCases.push_back(params);
7975 void createCompositeCases (vector<map<string, string> >& testCases, de::Random& rnd, const NumberType type)
7977 createVectorCompositeCases(testCases, rnd, type);
7978 createArrayCompositeCases(testCases, rnd, type);
7979 createStructCompositeCases(testCases, rnd, type);
7980 // Matrix only supports float types
7981 if (type == NUMBERTYPE_FLOAT32)
7983 createMatrixCompositeCases(testCases, rnd, type);
7987 const string getAssemblyTypeDeclaration (const NumberType type)
7991 case NUMBERTYPE_INT32: return "OpTypeInt 32 1";
7992 case NUMBERTYPE_UINT32: return "OpTypeInt 32 0";
7993 case NUMBERTYPE_FLOAT32: return "OpTypeFloat 32";
7994 default: DE_ASSERT(false); return "";
7998 const string getAssemblyTypeName (const NumberType type)
8002 case NUMBERTYPE_INT32: return "%i32";
8003 case NUMBERTYPE_UINT32: return "%u32";
8004 case NUMBERTYPE_FLOAT32: return "%f32";
8005 default: DE_ASSERT(false); return "";
8009 const string specializeCompositeInsertShaderTemplate (const NumberType type, const map<string, string>& params)
8011 map<string, string> parameters(params);
8013 const string customType = getAssemblyTypeName(type);
8014 map<string, string> substCustomType;
8015 substCustomType["customType"] = customType;
8016 parameters["compositeDecl"] = StringTemplate(parameters.at("compositeDecl")).specialize(substCustomType);
8017 parameters["compositeType"] = StringTemplate(parameters.at("compositeType")).specialize(substCustomType);
8018 parameters["compositeConstruct"] = StringTemplate(parameters.at("compositeConstruct")).specialize(substCustomType);
8019 parameters["filler"] = StringTemplate(parameters.at("filler")).specialize(substCustomType);
8020 parameters["customType"] = customType;
8021 parameters["compositeDecorator"] = (parameters["type"] == "array") ? "OpDecorate %composite ArrayStride 4\n" : "";
8023 if (parameters.at("compositeType") != "%u32vec3")
8025 parameters["u32vec3Decl"] = "%u32vec3 = OpTypeVector %u32 3\n";
8028 return StringTemplate(
8029 "OpCapability Shader\n"
8030 "OpCapability Matrix\n"
8031 "OpMemoryModel Logical GLSL450\n"
8032 "OpEntryPoint GLCompute %main \"main\" %id\n"
8033 "OpExecutionMode %main LocalSize 1 1 1\n"
8035 "OpSource GLSL 430\n"
8036 "OpName %main \"main\"\n"
8037 "OpName %id \"gl_GlobalInvocationID\"\n"
8040 "OpDecorate %id BuiltIn GlobalInvocationId\n"
8041 "OpDecorate %buf BufferBlock\n"
8042 "OpDecorate %indata DescriptorSet 0\n"
8043 "OpDecorate %indata Binding 0\n"
8044 "OpDecorate %outdata DescriptorSet 0\n"
8045 "OpDecorate %outdata Binding 1\n"
8046 "OpDecorate %customarr ArrayStride 4\n"
8047 "${compositeDecorator}"
8048 "OpMemberDecorate %buf 0 Offset 0\n"
8051 "%void = OpTypeVoid\n"
8052 "%voidf = OpTypeFunction %void\n"
8053 "%u32 = OpTypeInt 32 0\n"
8054 "%i32 = OpTypeInt 32 1\n"
8055 "%f32 = OpTypeFloat 32\n"
8057 // Composite declaration
8063 "${u32vec3Decl:opt}"
8064 "%uvec3ptr = OpTypePointer Input %u32vec3\n"
8066 // Inherited from custom
8067 "%customptr = OpTypePointer Uniform ${customType}\n"
8068 "%customarr = OpTypeRuntimeArray ${customType}\n"
8069 "%buf = OpTypeStruct %customarr\n"
8070 "%bufptr = OpTypePointer Uniform %buf\n"
8072 "%indata = OpVariable %bufptr Uniform\n"
8073 "%outdata = OpVariable %bufptr Uniform\n"
8075 "%id = OpVariable %uvec3ptr Input\n"
8076 "%zero = OpConstant %i32 0\n"
8078 "%main = OpFunction %void None %voidf\n"
8079 "%label = OpLabel\n"
8080 "%idval = OpLoad %u32vec3 %id\n"
8081 "%x = OpCompositeExtract %u32 %idval 0\n"
8083 "%inloc = OpAccessChain %customptr %indata %zero %x\n"
8084 "%outloc = OpAccessChain %customptr %outdata %zero %x\n"
8085 // Read the input value
8086 "%inval = OpLoad ${customType} %inloc\n"
8087 // Create the composite and fill it
8088 "${compositeConstruct}"
8089 // Insert the input value to a place
8090 "%instance2 = OpCompositeInsert ${compositeType} %inval %instance ${indexes}\n"
8091 // Read back the value from the position
8092 "%out_val = OpCompositeExtract ${customType} %instance2 ${indexes}\n"
8093 // Store it in the output position
8094 " OpStore %outloc %out_val\n"
8097 ).specialize(parameters);
8100 template<typename T>
8101 BufferSp createCompositeBuffer(T number)
8103 return BufferSp(new Buffer<T>(vector<T>(1, number)));
8106 tcu::TestCaseGroup* createOpCompositeInsertGroup (tcu::TestContext& testCtx)
8108 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opcompositeinsert", "Test the OpCompositeInsert instruction"));
8109 de::Random rnd (deStringHash(group->getName()));
8111 for (int type = NUMBERTYPE_INT32; type != NUMBERTYPE_END32; ++type)
8113 NumberType numberType = NumberType(type);
8114 const string typeName = getNumberTypeName(numberType);
8115 const string description = "Test the OpCompositeInsert instruction with " + typeName + "s";
8116 de::MovePtr<tcu::TestCaseGroup> subGroup (new tcu::TestCaseGroup(testCtx, typeName.c_str(), description.c_str()));
8117 vector<map<string, string> > testCases;
8119 createCompositeCases(testCases, rnd, numberType);
8121 for (vector<map<string, string> >::const_iterator test = testCases.begin(); test != testCases.end(); ++test)
8123 ComputeShaderSpec spec;
8125 spec.assembly = specializeCompositeInsertShaderTemplate(numberType, *test);
8129 case NUMBERTYPE_INT32:
8131 deInt32 number = getInt(rnd);
8132 spec.inputs.push_back(createCompositeBuffer<deInt32>(number));
8133 spec.outputs.push_back(createCompositeBuffer<deInt32>(number));
8136 case NUMBERTYPE_UINT32:
8138 deUint32 number = rnd.getUint32();
8139 spec.inputs.push_back(createCompositeBuffer<deUint32>(number));
8140 spec.outputs.push_back(createCompositeBuffer<deUint32>(number));
8143 case NUMBERTYPE_FLOAT32:
8145 float number = rnd.getFloat();
8146 spec.inputs.push_back(createCompositeBuffer<float>(number));
8147 spec.outputs.push_back(createCompositeBuffer<float>(number));
8154 spec.numWorkGroups = IVec3(1, 1, 1);
8155 subGroup->addChild(new SpvAsmComputeShaderCase(testCtx, test->at("name").c_str(), "OpCompositeInsert test", spec));
8157 group->addChild(subGroup.release());
8159 return group.release();
8162 struct AssemblyStructInfo
8164 AssemblyStructInfo (const deUint32 comp, const deUint32 idx)
8169 deUint32 components;
8173 const string specializeInBoundsShaderTemplate (const NumberType type, const AssemblyStructInfo& structInfo, const map<string, string>& params)
8175 // Create the full index string
8176 string fullIndex = numberToString(structInfo.index) + " " + params.at("indexes");
8177 // Convert it to list of indexes
8178 vector<string> indexes = de::splitString(fullIndex, ' ');
8180 map<string, string> parameters (params);
8181 parameters["structType"] = repeatString(" ${compositeType}", structInfo.components);
8182 parameters["structConstruct"] = repeatString(" %instance", structInfo.components);
8183 parameters["insertIndexes"] = fullIndex;
8185 // In matrix cases the last two index is the CompositeExtract indexes
8186 const deUint32 extractIndexes = (parameters["type"] == "matrix") ? 2 : 1;
8188 // Construct the extractIndex
8189 for (vector<string>::const_iterator index = indexes.end() - extractIndexes; index != indexes.end(); ++index)
8191 parameters["extractIndexes"] += " " + *index;
8194 // Remove the last 1 or 2 element depends on matrix case or not
8195 indexes.erase(indexes.end() - extractIndexes, indexes.end());
8198 // Generate AccessChain index expressions (except for the last one, because we use ptr to the composite)
8199 for (vector<string>::const_iterator index = indexes.begin(); index != indexes.end(); ++index)
8201 string indexId = "%index_" + numberToString(id++);
8202 parameters["accessChainConstDeclaration"] += indexId + " = OpConstant %u32 " + *index + "\n";
8203 parameters["accessChainIndexes"] += " " + indexId;
8206 parameters["compositeDecorator"] = (parameters["type"] == "array") ? "OpDecorate %composite ArrayStride 4\n" : "";
8208 const string customType = getAssemblyTypeName(type);
8209 map<string, string> substCustomType;
8210 substCustomType["customType"] = customType;
8211 parameters["compositeDecl"] = StringTemplate(parameters.at("compositeDecl")).specialize(substCustomType);
8212 parameters["compositeType"] = StringTemplate(parameters.at("compositeType")).specialize(substCustomType);
8213 parameters["compositeConstruct"] = StringTemplate(parameters.at("compositeConstruct")).specialize(substCustomType);
8214 parameters["filler"] = StringTemplate(parameters.at("filler")).specialize(substCustomType);
8215 parameters["customType"] = customType;
8217 const string compositeType = parameters.at("compositeType");
8218 map<string, string> substCompositeType;
8219 substCompositeType["compositeType"] = compositeType;
8220 parameters["structType"] = StringTemplate(parameters.at("structType")).specialize(substCompositeType);
8221 if (compositeType != "%u32vec3")
8223 parameters["u32vec3Decl"] = "%u32vec3 = OpTypeVector %u32 3\n";
8226 return StringTemplate(
8227 "OpCapability Shader\n"
8228 "OpCapability Matrix\n"
8229 "OpMemoryModel Logical GLSL450\n"
8230 "OpEntryPoint GLCompute %main \"main\" %id\n"
8231 "OpExecutionMode %main LocalSize 1 1 1\n"
8233 "OpSource GLSL 430\n"
8234 "OpName %main \"main\"\n"
8235 "OpName %id \"gl_GlobalInvocationID\"\n"
8237 "OpDecorate %id BuiltIn GlobalInvocationId\n"
8238 "OpDecorate %buf BufferBlock\n"
8239 "OpDecorate %indata DescriptorSet 0\n"
8240 "OpDecorate %indata Binding 0\n"
8241 "OpDecorate %outdata DescriptorSet 0\n"
8242 "OpDecorate %outdata Binding 1\n"
8243 "OpDecorate %customarr ArrayStride 4\n"
8244 "${compositeDecorator}"
8245 "OpMemberDecorate %buf 0 Offset 0\n"
8247 "%void = OpTypeVoid\n"
8248 "%voidf = OpTypeFunction %void\n"
8249 "%i32 = OpTypeInt 32 1\n"
8250 "%u32 = OpTypeInt 32 0\n"
8251 "%f32 = OpTypeFloat 32\n"
8254 // %u32vec3 if not already declared in ${compositeDecl}
8255 "${u32vec3Decl:opt}"
8256 "%uvec3ptr = OpTypePointer Input %u32vec3\n"
8257 // Inherited from composite
8258 "%composite_p = OpTypePointer Function ${compositeType}\n"
8259 "%struct_t = OpTypeStruct${structType}\n"
8260 "%struct_p = OpTypePointer Function %struct_t\n"
8263 "${accessChainConstDeclaration}"
8264 // Inherited from custom
8265 "%customptr = OpTypePointer Uniform ${customType}\n"
8266 "%customarr = OpTypeRuntimeArray ${customType}\n"
8267 "%buf = OpTypeStruct %customarr\n"
8268 "%bufptr = OpTypePointer Uniform %buf\n"
8269 "%indata = OpVariable %bufptr Uniform\n"
8270 "%outdata = OpVariable %bufptr Uniform\n"
8272 "%id = OpVariable %uvec3ptr Input\n"
8273 "%zero = OpConstant %u32 0\n"
8274 "%main = OpFunction %void None %voidf\n"
8275 "%label = OpLabel\n"
8276 "%struct_v = OpVariable %struct_p Function\n"
8277 "%idval = OpLoad %u32vec3 %id\n"
8278 "%x = OpCompositeExtract %u32 %idval 0\n"
8279 // Create the input/output type
8280 "%inloc = OpInBoundsAccessChain %customptr %indata %zero %x\n"
8281 "%outloc = OpInBoundsAccessChain %customptr %outdata %zero %x\n"
8282 // Read the input value
8283 "%inval = OpLoad ${customType} %inloc\n"
8284 // Create the composite and fill it
8285 "${compositeConstruct}"
8286 // Create the struct and fill it with the composite
8287 "%struct = OpCompositeConstruct %struct_t${structConstruct}\n"
8289 "%comp_obj = OpCompositeInsert %struct_t %inval %struct ${insertIndexes}\n"
8291 " OpStore %struct_v %comp_obj\n"
8292 // Get deepest possible composite pointer
8293 "%inner_ptr = OpInBoundsAccessChain %composite_p %struct_v${accessChainIndexes}\n"
8294 "%read_obj = OpLoad ${compositeType} %inner_ptr\n"
8295 // Read back the stored value
8296 "%read_val = OpCompositeExtract ${customType} %read_obj${extractIndexes}\n"
8297 " OpStore %outloc %read_val\n"
8300 ).specialize(parameters);
8303 tcu::TestCaseGroup* createOpInBoundsAccessChainGroup (tcu::TestContext& testCtx)
8305 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opinboundsaccesschain", "Test the OpInBoundsAccessChain instruction"));
8306 de::Random rnd (deStringHash(group->getName()));
8308 for (int type = NUMBERTYPE_INT32; type != NUMBERTYPE_END32; ++type)
8310 NumberType numberType = NumberType(type);
8311 const string typeName = getNumberTypeName(numberType);
8312 const string description = "Test the OpInBoundsAccessChain instruction with " + typeName + "s";
8313 de::MovePtr<tcu::TestCaseGroup> subGroup (new tcu::TestCaseGroup(testCtx, typeName.c_str(), description.c_str()));
8315 vector<map<string, string> > testCases;
8316 createCompositeCases(testCases, rnd, numberType);
8318 for (vector<map<string, string> >::const_iterator test = testCases.begin(); test != testCases.end(); ++test)
8320 ComputeShaderSpec spec;
8322 // Number of components inside of a struct
8323 deUint32 structComponents = rnd.getInt(2, 8);
8324 // Component index value
8325 deUint32 structIndex = rnd.getInt(0, structComponents - 1);
8326 AssemblyStructInfo structInfo(structComponents, structIndex);
8328 spec.assembly = specializeInBoundsShaderTemplate(numberType, structInfo, *test);
8332 case NUMBERTYPE_INT32:
8334 deInt32 number = getInt(rnd);
8335 spec.inputs.push_back(createCompositeBuffer<deInt32>(number));
8336 spec.outputs.push_back(createCompositeBuffer<deInt32>(number));
8339 case NUMBERTYPE_UINT32:
8341 deUint32 number = rnd.getUint32();
8342 spec.inputs.push_back(createCompositeBuffer<deUint32>(number));
8343 spec.outputs.push_back(createCompositeBuffer<deUint32>(number));
8346 case NUMBERTYPE_FLOAT32:
8348 float number = rnd.getFloat();
8349 spec.inputs.push_back(createCompositeBuffer<float>(number));
8350 spec.outputs.push_back(createCompositeBuffer<float>(number));
8356 spec.numWorkGroups = IVec3(1, 1, 1);
8357 subGroup->addChild(new SpvAsmComputeShaderCase(testCtx, test->at("name").c_str(), "OpInBoundsAccessChain test", spec));
8359 group->addChild(subGroup.release());
8361 return group.release();
8364 // If the params missing, uninitialized case
8365 const string specializeDefaultOutputShaderTemplate (const NumberType type, const map<string, string>& params = map<string, string>())
8367 map<string, string> parameters(params);
8369 parameters["customType"] = getAssemblyTypeName(type);
8371 // Declare the const value, and use it in the initializer
8372 if (params.find("constValue") != params.end())
8374 parameters["variableInitializer"] = " %const";
8376 // Uninitialized case
8379 parameters["commentDecl"] = ";";
8382 return StringTemplate(
8383 "OpCapability Shader\n"
8384 "OpMemoryModel Logical GLSL450\n"
8385 "OpEntryPoint GLCompute %main \"main\" %id\n"
8386 "OpExecutionMode %main LocalSize 1 1 1\n"
8387 "OpSource GLSL 430\n"
8388 "OpName %main \"main\"\n"
8389 "OpName %id \"gl_GlobalInvocationID\"\n"
8391 "OpDecorate %id BuiltIn GlobalInvocationId\n"
8392 "OpDecorate %indata DescriptorSet 0\n"
8393 "OpDecorate %indata Binding 0\n"
8394 "OpDecorate %outdata DescriptorSet 0\n"
8395 "OpDecorate %outdata Binding 1\n"
8396 "OpDecorate %in_arr ArrayStride 4\n"
8397 "OpDecorate %in_buf BufferBlock\n"
8398 "OpMemberDecorate %in_buf 0 Offset 0\n"
8400 "%void = OpTypeVoid\n"
8401 "%voidf = OpTypeFunction %void\n"
8402 "%u32 = OpTypeInt 32 0\n"
8403 "%i32 = OpTypeInt 32 1\n"
8404 "%f32 = OpTypeFloat 32\n"
8405 "%uvec3 = OpTypeVector %u32 3\n"
8406 "%uvec3ptr = OpTypePointer Input %uvec3\n"
8407 "${commentDecl:opt}%const = OpConstant ${customType} ${constValue:opt}\n"
8409 "%in_ptr = OpTypePointer Uniform ${customType}\n"
8410 "%in_arr = OpTypeRuntimeArray ${customType}\n"
8411 "%in_buf = OpTypeStruct %in_arr\n"
8412 "%in_bufptr = OpTypePointer Uniform %in_buf\n"
8413 "%indata = OpVariable %in_bufptr Uniform\n"
8414 "%outdata = OpVariable %in_bufptr Uniform\n"
8415 "%id = OpVariable %uvec3ptr Input\n"
8416 "%var_ptr = OpTypePointer Function ${customType}\n"
8418 "%zero = OpConstant %i32 0\n"
8420 "%main = OpFunction %void None %voidf\n"
8421 "%label = OpLabel\n"
8422 "%out_var = OpVariable %var_ptr Function${variableInitializer:opt}\n"
8423 "%idval = OpLoad %uvec3 %id\n"
8424 "%x = OpCompositeExtract %u32 %idval 0\n"
8425 "%inloc = OpAccessChain %in_ptr %indata %zero %x\n"
8426 "%outloc = OpAccessChain %in_ptr %outdata %zero %x\n"
8428 "%outval = OpLoad ${customType} %out_var\n"
8429 " OpStore %outloc %outval\n"
8432 ).specialize(parameters);
8435 bool compareFloats (const std::vector<BufferSp>&, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs, TestLog& log)
8437 DE_ASSERT(outputAllocs.size() != 0);
8438 DE_ASSERT(outputAllocs.size() == expectedOutputs.size());
8440 // Use custom epsilon because of the float->string conversion
8441 const float epsilon = 0.00001f;
8443 for (size_t outputNdx = 0; outputNdx < outputAllocs.size(); ++outputNdx)
8445 vector<deUint8> expectedBytes;
8449 expectedOutputs[outputNdx]->getBytes(expectedBytes);
8450 memcpy(&expected, &expectedBytes.front(), expectedBytes.size());
8451 memcpy(&actual, outputAllocs[outputNdx]->getHostPtr(), expectedBytes.size());
8453 // Test with epsilon
8454 if (fabs(expected - actual) > epsilon)
8456 log << TestLog::Message << "Error: The actual and expected values not matching."
8457 << " Expected: " << expected << " Actual: " << actual << " Epsilon: " << epsilon << TestLog::EndMessage;
8464 // Checks if the driver crash with uninitialized cases
8465 bool passthruVerify (const std::vector<BufferSp>&, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs, TestLog&)
8467 DE_ASSERT(outputAllocs.size() != 0);
8468 DE_ASSERT(outputAllocs.size() == expectedOutputs.size());
8470 // Copy and discard the result.
8471 for (size_t outputNdx = 0; outputNdx < outputAllocs.size(); ++outputNdx)
8473 vector<deUint8> expectedBytes;
8474 expectedOutputs[outputNdx]->getBytes(expectedBytes);
8476 const size_t width = expectedBytes.size();
8477 vector<char> data (width);
8479 memcpy(&data[0], outputAllocs[outputNdx]->getHostPtr(), width);
8484 tcu::TestCaseGroup* createShaderDefaultOutputGroup (tcu::TestContext& testCtx)
8486 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "shader_default_output", "Test shader default output."));
8487 de::Random rnd (deStringHash(group->getName()));
8489 for (int type = NUMBERTYPE_INT32; type != NUMBERTYPE_END32; ++type)
8491 NumberType numberType = NumberType(type);
8492 const string typeName = getNumberTypeName(numberType);
8493 const string description = "Test the OpVariable initializer with " + typeName + ".";
8494 de::MovePtr<tcu::TestCaseGroup> subGroup (new tcu::TestCaseGroup(testCtx, typeName.c_str(), description.c_str()));
8496 // 2 similar subcases (initialized and uninitialized)
8497 for (int subCase = 0; subCase < 2; ++subCase)
8499 ComputeShaderSpec spec;
8500 spec.numWorkGroups = IVec3(1, 1, 1);
8502 map<string, string> params;
8506 case NUMBERTYPE_INT32:
8508 deInt32 number = getInt(rnd);
8509 spec.inputs.push_back(createCompositeBuffer<deInt32>(number));
8510 spec.outputs.push_back(createCompositeBuffer<deInt32>(number));
8511 params["constValue"] = numberToString(number);
8514 case NUMBERTYPE_UINT32:
8516 deUint32 number = rnd.getUint32();
8517 spec.inputs.push_back(createCompositeBuffer<deUint32>(number));
8518 spec.outputs.push_back(createCompositeBuffer<deUint32>(number));
8519 params["constValue"] = numberToString(number);
8522 case NUMBERTYPE_FLOAT32:
8524 float number = rnd.getFloat();
8525 spec.inputs.push_back(createCompositeBuffer<float>(number));
8526 spec.outputs.push_back(createCompositeBuffer<float>(number));
8527 spec.verifyIO = &compareFloats;
8528 params["constValue"] = numberToString(number);
8535 // Initialized subcase
8538 spec.assembly = specializeDefaultOutputShaderTemplate(numberType, params);
8539 subGroup->addChild(new SpvAsmComputeShaderCase(testCtx, "initialized", "OpVariable initializer tests.", spec));
8541 // Uninitialized subcase
8544 spec.assembly = specializeDefaultOutputShaderTemplate(numberType);
8545 spec.verifyIO = &passthruVerify;
8546 subGroup->addChild(new SpvAsmComputeShaderCase(testCtx, "uninitialized", "OpVariable initializer tests.", spec));
8549 group->addChild(subGroup.release());
8551 return group.release();
8554 tcu::TestCaseGroup* createOpNopTests (tcu::TestContext& testCtx)
8556 de::MovePtr<tcu::TestCaseGroup> testGroup (new tcu::TestCaseGroup(testCtx, "opnop", "Test OpNop"));
8557 RGBA defaultColors[4];
8558 map<string, string> opNopFragments;
8560 getDefaultColors(defaultColors);
8562 opNopFragments["testfun"] =
8563 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
8564 "%param1 = OpFunctionParameter %v4f32\n"
8565 "%label_testfun = OpLabel\n"
8574 "%a = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
8575 "%b = OpFAdd %f32 %a %a\n"
8577 "%c = OpFSub %f32 %b %a\n"
8578 "%ret = OpVectorInsertDynamic %v4f32 %param1 %c %c_i32_0\n"
8581 "OpReturnValue %ret\n"
8584 createTestsForAllStages("opnop", defaultColors, defaultColors, opNopFragments, testGroup.get());
8586 return testGroup.release();
8589 tcu::TestCaseGroup* createInstructionTests (tcu::TestContext& testCtx)
8591 de::MovePtr<tcu::TestCaseGroup> instructionTests (new tcu::TestCaseGroup(testCtx, "instruction", "Instructions with special opcodes/operands"));
8592 de::MovePtr<tcu::TestCaseGroup> computeTests (new tcu::TestCaseGroup(testCtx, "compute", "Compute Instructions with special opcodes/operands"));
8593 de::MovePtr<tcu::TestCaseGroup> graphicsTests (new tcu::TestCaseGroup(testCtx, "graphics", "Graphics Instructions with special opcodes/operands"));
8595 computeTests->addChild(createOpNopGroup(testCtx));
8596 computeTests->addChild(createOpFUnordGroup(testCtx));
8597 computeTests->addChild(createOpAtomicGroup(testCtx, false));
8598 computeTests->addChild(createOpAtomicGroup(testCtx, true)); // Using new StorageBuffer decoration
8599 computeTests->addChild(createOpLineGroup(testCtx));
8600 computeTests->addChild(createOpNoLineGroup(testCtx));
8601 computeTests->addChild(createOpConstantNullGroup(testCtx));
8602 computeTests->addChild(createOpConstantCompositeGroup(testCtx));
8603 computeTests->addChild(createOpConstantUsageGroup(testCtx));
8604 computeTests->addChild(createSpecConstantGroup(testCtx));
8605 computeTests->addChild(createOpSourceGroup(testCtx));
8606 computeTests->addChild(createOpSourceExtensionGroup(testCtx));
8607 computeTests->addChild(createDecorationGroupGroup(testCtx));
8608 computeTests->addChild(createOpPhiGroup(testCtx));
8609 computeTests->addChild(createLoopControlGroup(testCtx));
8610 computeTests->addChild(createFunctionControlGroup(testCtx));
8611 computeTests->addChild(createSelectionControlGroup(testCtx));
8612 computeTests->addChild(createBlockOrderGroup(testCtx));
8613 computeTests->addChild(createMultipleShaderGroup(testCtx));
8614 computeTests->addChild(createMemoryAccessGroup(testCtx));
8615 computeTests->addChild(createOpCopyMemoryGroup(testCtx));
8616 computeTests->addChild(createOpCopyObjectGroup(testCtx));
8617 computeTests->addChild(createNoContractionGroup(testCtx));
8618 computeTests->addChild(createOpUndefGroup(testCtx));
8619 computeTests->addChild(createOpUnreachableGroup(testCtx));
8620 computeTests ->addChild(createOpQuantizeToF16Group(testCtx));
8621 computeTests ->addChild(createOpFRemGroup(testCtx));
8622 computeTests->addChild(createOpSRemComputeGroup(testCtx, QP_TEST_RESULT_PASS));
8623 computeTests->addChild(createOpSRemComputeGroup64(testCtx, QP_TEST_RESULT_PASS));
8624 computeTests->addChild(createOpSModComputeGroup(testCtx, QP_TEST_RESULT_PASS));
8625 computeTests->addChild(createOpSModComputeGroup64(testCtx, QP_TEST_RESULT_PASS));
8626 computeTests->addChild(createSConvertTests(testCtx));
8627 computeTests->addChild(createUConvertTests(testCtx));
8628 computeTests->addChild(createOpCompositeInsertGroup(testCtx));
8629 computeTests->addChild(createOpInBoundsAccessChainGroup(testCtx));
8630 computeTests->addChild(createShaderDefaultOutputGroup(testCtx));
8631 computeTests->addChild(createOpNMinGroup(testCtx));
8632 computeTests->addChild(createOpNMaxGroup(testCtx));
8633 computeTests->addChild(createOpNClampGroup(testCtx));
8635 de::MovePtr<tcu::TestCaseGroup> computeAndroidTests (new tcu::TestCaseGroup(testCtx, "android", "Android CTS Tests"));
8637 computeAndroidTests->addChild(createOpSRemComputeGroup(testCtx, QP_TEST_RESULT_QUALITY_WARNING));
8638 computeAndroidTests->addChild(createOpSModComputeGroup(testCtx, QP_TEST_RESULT_QUALITY_WARNING));
8640 computeTests->addChild(computeAndroidTests.release());
8643 computeTests->addChild(create16BitStorageComputeGroup(testCtx));
8644 computeTests->addChild(createUboMatrixPaddingComputeGroup(testCtx));
8645 computeTests->addChild(createConditionalBranchComputeGroup(testCtx));
8646 computeTests->addChild(createIndexingComputeGroup(testCtx));
8647 computeTests->addChild(createVariablePointersComputeGroup(testCtx));
8648 computeTests->addChild(createImageSamplerComputeGroup(testCtx));
8649 graphicsTests->addChild(createOpNopTests(testCtx));
8650 graphicsTests->addChild(createOpSourceTests(testCtx));
8651 graphicsTests->addChild(createOpSourceContinuedTests(testCtx));
8652 graphicsTests->addChild(createOpLineTests(testCtx));
8653 graphicsTests->addChild(createOpNoLineTests(testCtx));
8654 graphicsTests->addChild(createOpConstantNullTests(testCtx));
8655 graphicsTests->addChild(createOpConstantCompositeTests(testCtx));
8656 graphicsTests->addChild(createMemoryAccessTests(testCtx));
8657 graphicsTests->addChild(createOpUndefTests(testCtx));
8658 graphicsTests->addChild(createSelectionBlockOrderTests(testCtx));
8659 graphicsTests->addChild(createModuleTests(testCtx));
8660 graphicsTests->addChild(createSwitchBlockOrderTests(testCtx));
8661 graphicsTests->addChild(createOpPhiTests(testCtx));
8662 graphicsTests->addChild(createNoContractionTests(testCtx));
8663 graphicsTests->addChild(createOpQuantizeTests(testCtx));
8664 graphicsTests->addChild(createLoopTests(testCtx));
8665 graphicsTests->addChild(createSpecConstantTests(testCtx));
8666 graphicsTests->addChild(createSpecConstantOpQuantizeToF16Group(testCtx));
8667 graphicsTests->addChild(createBarrierTests(testCtx));
8668 graphicsTests->addChild(createDecorationGroupTests(testCtx));
8669 graphicsTests->addChild(createFRemTests(testCtx));
8670 graphicsTests->addChild(createOpSRemGraphicsTests(testCtx, QP_TEST_RESULT_PASS));
8671 graphicsTests->addChild(createOpSModGraphicsTests(testCtx, QP_TEST_RESULT_PASS));
8674 de::MovePtr<tcu::TestCaseGroup> graphicsAndroidTests (new tcu::TestCaseGroup(testCtx, "android", "Android CTS Tests"));
8676 graphicsAndroidTests->addChild(createOpSRemGraphicsTests(testCtx, QP_TEST_RESULT_QUALITY_WARNING));
8677 graphicsAndroidTests->addChild(createOpSModGraphicsTests(testCtx, QP_TEST_RESULT_QUALITY_WARNING));
8679 graphicsTests->addChild(graphicsAndroidTests.release());
8682 graphicsTests->addChild(create16BitStorageGraphicsGroup(testCtx));
8683 graphicsTests->addChild(createUboMatrixPaddingGraphicsGroup(testCtx));
8684 graphicsTests->addChild(createConditionalBranchGraphicsGroup(testCtx));
8685 graphicsTests->addChild(createIndexingGraphicsGroup(testCtx));
8686 graphicsTests->addChild(createVariablePointersGraphicsGroup(testCtx));
8687 graphicsTests->addChild(createImageSamplerGraphicsGroup(testCtx));
8689 instructionTests->addChild(computeTests.release());
8690 instructionTests->addChild(graphicsTests.release());
8692 return instructionTests.release();