1 /*-------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
5 * Copyright (c) 2015 Google Inc.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
21 * \brief SPIR-V Assembly Tests for Instructions (special opcode/operand)
22 *//*--------------------------------------------------------------------*/
24 #include "vktSpvAsmInstructionTests.hpp"
26 #include "tcuCommandLine.hpp"
27 #include "tcuFormatUtil.hpp"
28 #include "tcuFloat.hpp"
29 #include "tcuRGBA.hpp"
30 #include "tcuStringTemplate.hpp"
31 #include "tcuTestLog.hpp"
32 #include "tcuVectorUtil.hpp"
35 #include "vkDeviceUtil.hpp"
36 #include "vkMemUtil.hpp"
37 #include "vkPlatform.hpp"
38 #include "vkPrograms.hpp"
39 #include "vkQueryUtil.hpp"
41 #include "vkRefUtil.hpp"
42 #include "vkStrUtil.hpp"
43 #include "vkTypeUtil.hpp"
45 #include "deRandom.hpp"
46 #include "deStringUtil.hpp"
47 #include "deUniquePtr.hpp"
48 #include "tcuStringTemplate.hpp"
51 #include "vktSpvAsmComputeShaderCase.hpp"
52 #include "vktSpvAsmComputeShaderTestUtil.hpp"
53 #include "vktTestCaseUtil.hpp"
63 namespace SpirVAssembly
77 using tcu::TestStatus;
80 using tcu::StringTemplate;
83 typedef Unique<VkShaderModule> ModuleHandleUp;
84 typedef de::SharedPtr<ModuleHandleUp> ModuleHandleSp;
86 template<typename T> T randomScalar (de::Random& rnd, T minValue, T maxValue);
87 template<> inline float randomScalar (de::Random& rnd, float minValue, float maxValue) { return rnd.getFloat(minValue, maxValue); }
88 template<> inline deInt32 randomScalar (de::Random& rnd, deInt32 minValue, deInt32 maxValue) { return rnd.getInt(minValue, maxValue); }
91 static void fillRandomScalars (de::Random& rnd, T minValue, T maxValue, void* dst, int numValues, int offset = 0)
93 T* const typedPtr = (T*)dst;
94 for (int ndx = 0; ndx < numValues; ndx++)
95 typedPtr[offset + ndx] = randomScalar<T>(rnd, minValue, maxValue);
98 static void floorAll (vector<float>& values)
100 for (size_t i = 0; i < values.size(); i++)
101 values[i] = deFloatFloor(values[i]);
104 static void floorAll (vector<Vec4>& values)
106 for (size_t i = 0; i < values.size(); i++)
107 values[i] = floor(values[i]);
115 CaseParameter (const char* case_, const string& param_) : name(case_), param(param_) {}
118 // Assembly code used for testing OpNop, OpConstant{Null|Composite}, Op[No]Line, OpSource[Continued], OpSourceExtension, OpUndef is based on GLSL source code:
122 // layout(std140, set = 0, binding = 0) readonly buffer Input {
125 // layout(std140, set = 0, binding = 1) writeonly buffer Output {
129 // layout (local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
132 // uint x = gl_GlobalInvocationID.x;
133 // output_data.elements[x] = -input_data.elements[x];
136 static const char* const s_ShaderPreamble =
137 "OpCapability Shader\n"
138 "OpMemoryModel Logical GLSL450\n"
139 "OpEntryPoint GLCompute %main \"main\" %id\n"
140 "OpExecutionMode %main LocalSize 1 1 1\n";
142 static const char* const s_CommonTypes =
143 "%bool = OpTypeBool\n"
144 "%void = OpTypeVoid\n"
145 "%voidf = OpTypeFunction %void\n"
146 "%u32 = OpTypeInt 32 0\n"
147 "%i32 = OpTypeInt 32 1\n"
148 "%f32 = OpTypeFloat 32\n"
149 "%uvec3 = OpTypeVector %u32 3\n"
150 "%fvec3 = OpTypeVector %f32 3\n"
151 "%uvec3ptr = OpTypePointer Input %uvec3\n"
152 "%i32ptr = OpTypePointer Uniform %i32\n"
153 "%f32ptr = OpTypePointer Uniform %f32\n"
154 "%i32arr = OpTypeRuntimeArray %i32\n"
155 "%f32arr = OpTypeRuntimeArray %f32\n";
157 // Declares two uniform variables (indata, outdata) of type "struct { float[] }". Depends on type "f32arr" (for "float[]").
158 static const char* const s_InputOutputBuffer =
159 "%buf = OpTypeStruct %f32arr\n"
160 "%bufptr = OpTypePointer Uniform %buf\n"
161 "%indata = OpVariable %bufptr Uniform\n"
162 "%outdata = OpVariable %bufptr Uniform\n";
164 // Declares buffer type and layout for uniform variables indata and outdata. Both of them are SSBO bounded to descriptor set 0.
165 // indata is at binding point 0, while outdata is at 1.
166 static const char* const s_InputOutputBufferTraits =
167 "OpDecorate %buf BufferBlock\n"
168 "OpDecorate %indata DescriptorSet 0\n"
169 "OpDecorate %indata Binding 0\n"
170 "OpDecorate %outdata DescriptorSet 0\n"
171 "OpDecorate %outdata Binding 1\n"
172 "OpDecorate %f32arr ArrayStride 4\n"
173 "OpMemberDecorate %buf 0 Offset 0\n";
175 tcu::TestCaseGroup* createOpNopGroup (tcu::TestContext& testCtx)
177 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opnop", "Test the OpNop instruction"));
178 ComputeShaderSpec spec;
179 de::Random rnd (deStringHash(group->getName()));
180 const int numElements = 100;
181 vector<float> positiveFloats (numElements, 0);
182 vector<float> negativeFloats (numElements, 0);
184 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
186 for (size_t ndx = 0; ndx < numElements; ++ndx)
187 negativeFloats[ndx] = -positiveFloats[ndx];
190 string(s_ShaderPreamble) +
192 "OpSource GLSL 430\n"
193 "OpName %main \"main\"\n"
194 "OpName %id \"gl_GlobalInvocationID\"\n"
196 "OpDecorate %id BuiltIn GlobalInvocationId\n"
198 + string(s_InputOutputBufferTraits) + string(s_CommonTypes)
200 + string(s_InputOutputBuffer) +
202 "%id = OpVariable %uvec3ptr Input\n"
203 "%zero = OpConstant %i32 0\n"
205 "%main = OpFunction %void None %voidf\n"
207 "%idval = OpLoad %uvec3 %id\n"
208 "%x = OpCompositeExtract %u32 %idval 0\n"
210 " OpNop\n" // Inside a function body
212 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
213 "%inval = OpLoad %f32 %inloc\n"
214 "%neg = OpFNegate %f32 %inval\n"
215 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
216 " OpStore %outloc %neg\n"
219 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
220 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
221 spec.numWorkGroups = IVec3(numElements, 1, 1);
223 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "OpNop appearing at different places", spec));
225 return group.release();
228 bool compareFUnord (const std::vector<BufferSp>& inputs, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs, TestLog& log)
230 if (outputAllocs.size() != 1)
233 const BufferSp& expectedOutput = expectedOutputs[0];
234 const deInt32* expectedOutputAsInt = static_cast<const deInt32*>(expectedOutputs[0]->data());
235 const deInt32* outputAsInt = static_cast<const deInt32*>(outputAllocs[0]->getHostPtr());
236 const float* input1AsFloat = static_cast<const float*>(inputs[0]->data());
237 const float* input2AsFloat = static_cast<const float*>(inputs[1]->data());
238 bool returnValue = true;
240 for (size_t idx = 0; idx < expectedOutput->getNumBytes() / sizeof(deInt32); ++idx)
242 if (outputAsInt[idx] != expectedOutputAsInt[idx])
244 log << TestLog::Message << "ERROR: Sub-case failed. inputs: " << input1AsFloat[idx] << "," << input2AsFloat[idx] << " output: " << outputAsInt[idx]<< " expected output: " << expectedOutputAsInt[idx] << TestLog::EndMessage;
251 typedef VkBool32 (*compareFuncType) (float, float);
257 compareFuncType compareFunc;
259 OpFUnordCase (const char* _name, const char* _opCode, compareFuncType _compareFunc)
262 , compareFunc (_compareFunc) {}
265 #define ADD_OPFUNORD_CASE(NAME, OPCODE, OPERATOR) \
267 struct compare_##NAME { static VkBool32 compare(float x, float y) { return (x OPERATOR y) ? VK_TRUE : VK_FALSE; } }; \
268 cases.push_back(OpFUnordCase(#NAME, OPCODE, compare_##NAME::compare)); \
269 } while (deGetFalse())
271 tcu::TestCaseGroup* createOpFUnordGroup (tcu::TestContext& testCtx)
273 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opfunord", "Test the OpFUnord* opcodes"));
274 de::Random rnd (deStringHash(group->getName()));
275 const int numElements = 100;
276 vector<OpFUnordCase> cases;
278 const StringTemplate shaderTemplate (
280 string(s_ShaderPreamble) +
282 "OpSource GLSL 430\n"
283 "OpName %main \"main\"\n"
284 "OpName %id \"gl_GlobalInvocationID\"\n"
286 "OpDecorate %id BuiltIn GlobalInvocationId\n"
288 "OpDecorate %buf BufferBlock\n"
289 "OpDecorate %buf2 BufferBlock\n"
290 "OpDecorate %indata1 DescriptorSet 0\n"
291 "OpDecorate %indata1 Binding 0\n"
292 "OpDecorate %indata2 DescriptorSet 0\n"
293 "OpDecorate %indata2 Binding 1\n"
294 "OpDecorate %outdata DescriptorSet 0\n"
295 "OpDecorate %outdata Binding 2\n"
296 "OpDecorate %f32arr ArrayStride 4\n"
297 "OpDecorate %i32arr ArrayStride 4\n"
298 "OpMemberDecorate %buf 0 Offset 0\n"
299 "OpMemberDecorate %buf2 0 Offset 0\n"
301 + string(s_CommonTypes) +
303 "%buf = OpTypeStruct %f32arr\n"
304 "%bufptr = OpTypePointer Uniform %buf\n"
305 "%indata1 = OpVariable %bufptr Uniform\n"
306 "%indata2 = OpVariable %bufptr Uniform\n"
308 "%buf2 = OpTypeStruct %i32arr\n"
309 "%buf2ptr = OpTypePointer Uniform %buf2\n"
310 "%outdata = OpVariable %buf2ptr Uniform\n"
312 "%id = OpVariable %uvec3ptr Input\n"
313 "%zero = OpConstant %i32 0\n"
314 "%consti1 = OpConstant %i32 1\n"
315 "%constf1 = OpConstant %f32 1.0\n"
317 "%main = OpFunction %void None %voidf\n"
319 "%idval = OpLoad %uvec3 %id\n"
320 "%x = OpCompositeExtract %u32 %idval 0\n"
322 "%inloc1 = OpAccessChain %f32ptr %indata1 %zero %x\n"
323 "%inval1 = OpLoad %f32 %inloc1\n"
324 "%inloc2 = OpAccessChain %f32ptr %indata2 %zero %x\n"
325 "%inval2 = OpLoad %f32 %inloc2\n"
326 "%outloc = OpAccessChain %i32ptr %outdata %zero %x\n"
328 "%result = ${OPCODE} %bool %inval1 %inval2\n"
329 "%int_res = OpSelect %i32 %result %consti1 %zero\n"
330 " OpStore %outloc %int_res\n"
335 ADD_OPFUNORD_CASE(equal, "OpFUnordEqual", ==);
336 ADD_OPFUNORD_CASE(less, "OpFUnordLessThan", <);
337 ADD_OPFUNORD_CASE(lessequal, "OpFUnordLessThanEqual", <=);
338 ADD_OPFUNORD_CASE(greater, "OpFUnordGreaterThan", >);
339 ADD_OPFUNORD_CASE(greaterequal, "OpFUnordGreaterThanEqual", >=);
340 ADD_OPFUNORD_CASE(notequal, "OpFUnordNotEqual", !=);
342 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
344 map<string, string> specializations;
345 ComputeShaderSpec spec;
346 const float NaN = std::numeric_limits<float>::quiet_NaN();
347 vector<float> inputFloats1 (numElements, 0);
348 vector<float> inputFloats2 (numElements, 0);
349 vector<deInt32> expectedInts (numElements, 0);
351 specializations["OPCODE"] = cases[caseNdx].opCode;
352 spec.assembly = shaderTemplate.specialize(specializations);
354 fillRandomScalars(rnd, 1.f, 100.f, &inputFloats1[0], numElements);
355 for (size_t ndx = 0; ndx < numElements; ++ndx)
359 case 0: inputFloats2[ndx] = inputFloats1[ndx] + 1.0f; break;
360 case 1: inputFloats2[ndx] = inputFloats1[ndx] - 1.0f; break;
361 case 2: inputFloats2[ndx] = inputFloats1[ndx]; break;
362 case 3: inputFloats2[ndx] = NaN; break;
363 case 4: inputFloats2[ndx] = inputFloats1[ndx]; inputFloats1[ndx] = NaN; break;
364 case 5: inputFloats2[ndx] = NaN; inputFloats1[ndx] = NaN; break;
366 expectedInts[ndx] = tcu::Float32(inputFloats1[ndx]).isNaN() || tcu::Float32(inputFloats2[ndx]).isNaN() || cases[caseNdx].compareFunc(inputFloats1[ndx], inputFloats2[ndx]);
369 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats1)));
370 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
371 spec.outputs.push_back(BufferSp(new Int32Buffer(expectedInts)));
372 spec.numWorkGroups = IVec3(numElements, 1, 1);
373 spec.verifyIO = &compareFUnord;
374 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
377 return group.release();
383 const char* assembly;
384 void (*calculateExpected)(deInt32&, deInt32);
385 deInt32 numOutputElements;
387 OpAtomicCase (const char* _name, const char* _assembly, void (*_calculateExpected)(deInt32&, deInt32), deInt32 _numOutputElements)
389 , assembly (_assembly)
390 , calculateExpected (_calculateExpected)
391 , numOutputElements (_numOutputElements) {}
394 tcu::TestCaseGroup* createOpAtomicGroup (tcu::TestContext& testCtx)
396 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opatomic", "Test the OpAtomic* opcodes"));
397 de::Random rnd (deStringHash(group->getName()));
398 const int numElements = 1000000;
399 vector<OpAtomicCase> cases;
401 const StringTemplate shaderTemplate (
403 string(s_ShaderPreamble) +
405 "OpSource GLSL 430\n"
406 "OpName %main \"main\"\n"
407 "OpName %id \"gl_GlobalInvocationID\"\n"
409 "OpDecorate %id BuiltIn GlobalInvocationId\n"
411 "OpDecorate %buf BufferBlock\n"
412 "OpDecorate %indata DescriptorSet 0\n"
413 "OpDecorate %indata Binding 0\n"
414 "OpDecorate %i32arr ArrayStride 4\n"
415 "OpMemberDecorate %buf 0 Offset 0\n"
417 "OpDecorate %sumbuf BufferBlock\n"
418 "OpDecorate %sum DescriptorSet 0\n"
419 "OpDecorate %sum Binding 1\n"
420 "OpMemberDecorate %sumbuf 0 Coherent\n"
421 "OpMemberDecorate %sumbuf 0 Offset 0\n"
423 + string(s_CommonTypes) +
425 "%buf = OpTypeStruct %i32arr\n"
426 "%bufptr = OpTypePointer Uniform %buf\n"
427 "%indata = OpVariable %bufptr Uniform\n"
429 "%sumbuf = OpTypeStruct %i32arr\n"
430 "%sumbufptr = OpTypePointer Uniform %sumbuf\n"
431 "%sum = OpVariable %sumbufptr Uniform\n"
433 "%id = OpVariable %uvec3ptr Input\n"
434 "%minusone = OpConstant %i32 -1\n"
435 "%zero = OpConstant %i32 0\n"
436 "%one = OpConstant %u32 1\n"
437 "%two = OpConstant %i32 2\n"
439 "%main = OpFunction %void None %voidf\n"
441 "%idval = OpLoad %uvec3 %id\n"
442 "%x = OpCompositeExtract %u32 %idval 0\n"
444 "%inloc = OpAccessChain %i32ptr %indata %zero %x\n"
445 "%inval = OpLoad %i32 %inloc\n"
447 "%outloc = OpAccessChain %i32ptr %sum %zero ${INDEX}\n"
453 #define ADD_OPATOMIC_CASE(NAME, ASSEMBLY, CALCULATE_EXPECTED, NUM_OUTPUT_ELEMENTS) \
455 DE_STATIC_ASSERT(NUM_OUTPUT_ELEMENTS == 1 || NUM_OUTPUT_ELEMENTS == numElements); \
456 struct calculateExpected_##NAME { static void calculateExpected(deInt32& expected, deInt32 input) CALCULATE_EXPECTED }; \
457 cases.push_back(OpAtomicCase(#NAME, ASSEMBLY, calculateExpected_##NAME::calculateExpected, NUM_OUTPUT_ELEMENTS)); \
458 } while (deGetFalse())
459 #define ADD_OPATOMIC_CASE_1(NAME, ASSEMBLY, CALCULATE_EXPECTED) ADD_OPATOMIC_CASE(NAME, ASSEMBLY, CALCULATE_EXPECTED, 1)
460 #define ADD_OPATOMIC_CASE_N(NAME, ASSEMBLY, CALCULATE_EXPECTED) ADD_OPATOMIC_CASE(NAME, ASSEMBLY, CALCULATE_EXPECTED, numElements)
462 ADD_OPATOMIC_CASE_1(iadd, "%unused = OpAtomicIAdd %i32 %outloc %one %zero %inval\n", { expected += input; } );
463 ADD_OPATOMIC_CASE_1(isub, "%unused = OpAtomicISub %i32 %outloc %one %zero %inval\n", { expected -= input; } );
464 ADD_OPATOMIC_CASE_1(iinc, "%unused = OpAtomicIIncrement %i32 %outloc %one %zero\n", { ++expected; (void)input;} );
465 ADD_OPATOMIC_CASE_1(idec, "%unused = OpAtomicIDecrement %i32 %outloc %one %zero\n", { --expected; (void)input;} );
466 ADD_OPATOMIC_CASE_N(load, "%inval2 = OpAtomicLoad %i32 %inloc %zero %zero\n"
467 " OpStore %outloc %inval2\n", { expected = input;} );
468 ADD_OPATOMIC_CASE_N(store, " OpAtomicStore %outloc %zero %zero %inval\n", { expected = input;} );
469 ADD_OPATOMIC_CASE_N(compex, "%even = OpSMod %i32 %inval %two\n"
470 " OpStore %outloc %even\n"
471 "%unused = OpAtomicCompareExchange %i32 %outloc %one %zero %zero %minusone %zero\n", { expected = (input % 2) == 0 ? -1 : 1;} );
473 #undef ADD_OPATOMIC_CASE
474 #undef ADD_OPATOMIC_CASE_1
475 #undef ADD_OPATOMIC_CASE_N
477 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
479 map<string, string> specializations;
480 ComputeShaderSpec spec;
481 vector<deInt32> inputInts (numElements, 0);
482 vector<deInt32> expected (cases[caseNdx].numOutputElements, -1);
484 specializations["INDEX"] = (cases[caseNdx].numOutputElements == 1) ? "%zero" : "%x";
485 specializations["INSTRUCTION"] = cases[caseNdx].assembly;
486 spec.assembly = shaderTemplate.specialize(specializations);
488 fillRandomScalars(rnd, 1, 100, &inputInts[0], numElements);
489 for (size_t ndx = 0; ndx < numElements; ++ndx)
491 cases[caseNdx].calculateExpected((cases[caseNdx].numOutputElements == 1) ? expected[0] : expected[ndx], inputInts[ndx]);
494 spec.inputs.push_back(BufferSp(new Int32Buffer(inputInts)));
495 spec.outputs.push_back(BufferSp(new Int32Buffer(expected)));
496 spec.numWorkGroups = IVec3(numElements, 1, 1);
497 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
500 return group.release();
503 tcu::TestCaseGroup* createOpLineGroup (tcu::TestContext& testCtx)
505 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opline", "Test the OpLine instruction"));
506 ComputeShaderSpec spec;
507 de::Random rnd (deStringHash(group->getName()));
508 const int numElements = 100;
509 vector<float> positiveFloats (numElements, 0);
510 vector<float> negativeFloats (numElements, 0);
512 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
514 for (size_t ndx = 0; ndx < numElements; ++ndx)
515 negativeFloats[ndx] = -positiveFloats[ndx];
518 string(s_ShaderPreamble) +
520 "%fname1 = OpString \"negateInputs.comp\"\n"
521 "%fname2 = OpString \"negateInputs\"\n"
523 "OpSource GLSL 430\n"
524 "OpName %main \"main\"\n"
525 "OpName %id \"gl_GlobalInvocationID\"\n"
527 "OpDecorate %id BuiltIn GlobalInvocationId\n"
529 + string(s_InputOutputBufferTraits) +
531 "OpLine %fname1 0 0\n" // At the earliest possible position
533 + string(s_CommonTypes) + string(s_InputOutputBuffer) +
535 "OpLine %fname1 0 1\n" // Multiple OpLines in sequence
536 "OpLine %fname2 1 0\n" // Different filenames
537 "OpLine %fname1 1000 100000\n"
539 "%id = OpVariable %uvec3ptr Input\n"
540 "%zero = OpConstant %i32 0\n"
542 "OpLine %fname1 1 1\n" // Before a function
544 "%main = OpFunction %void None %voidf\n"
547 "OpLine %fname1 1 1\n" // In a function
549 "%idval = OpLoad %uvec3 %id\n"
550 "%x = OpCompositeExtract %u32 %idval 0\n"
551 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
552 "%inval = OpLoad %f32 %inloc\n"
553 "%neg = OpFNegate %f32 %inval\n"
554 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
555 " OpStore %outloc %neg\n"
558 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
559 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
560 spec.numWorkGroups = IVec3(numElements, 1, 1);
562 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "OpLine appearing at different places", spec));
564 return group.release();
567 tcu::TestCaseGroup* createOpNoLineGroup (tcu::TestContext& testCtx)
569 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opnoline", "Test the OpNoLine instruction"));
570 ComputeShaderSpec spec;
571 de::Random rnd (deStringHash(group->getName()));
572 const int numElements = 100;
573 vector<float> positiveFloats (numElements, 0);
574 vector<float> negativeFloats (numElements, 0);
576 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
578 for (size_t ndx = 0; ndx < numElements; ++ndx)
579 negativeFloats[ndx] = -positiveFloats[ndx];
582 string(s_ShaderPreamble) +
584 "%fname = OpString \"negateInputs.comp\"\n"
586 "OpSource GLSL 430\n"
587 "OpName %main \"main\"\n"
588 "OpName %id \"gl_GlobalInvocationID\"\n"
590 "OpDecorate %id BuiltIn GlobalInvocationId\n"
592 + string(s_InputOutputBufferTraits) +
594 "OpNoLine\n" // At the earliest possible position, without preceding OpLine
596 + string(s_CommonTypes) + string(s_InputOutputBuffer) +
598 "OpLine %fname 0 1\n"
599 "OpNoLine\n" // Immediately following a preceding OpLine
601 "OpLine %fname 1000 1\n"
603 "%id = OpVariable %uvec3ptr Input\n"
604 "%zero = OpConstant %i32 0\n"
606 "OpNoLine\n" // Contents after the previous OpLine
608 "%main = OpFunction %void None %voidf\n"
610 "%idval = OpLoad %uvec3 %id\n"
611 "%x = OpCompositeExtract %u32 %idval 0\n"
613 "OpNoLine\n" // Multiple OpNoLine
617 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
618 "%inval = OpLoad %f32 %inloc\n"
619 "%neg = OpFNegate %f32 %inval\n"
620 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
621 " OpStore %outloc %neg\n"
624 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
625 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
626 spec.numWorkGroups = IVec3(numElements, 1, 1);
628 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "OpNoLine appearing at different places", spec));
630 return group.release();
633 // Compare instruction for the contraction compute case.
634 // Returns true if the output is what is expected from the test case.
635 bool compareNoContractCase(const std::vector<BufferSp>&, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs, TestLog&)
637 if (outputAllocs.size() != 1)
640 // We really just need this for size because we are not comparing the exact values.
641 const BufferSp& expectedOutput = expectedOutputs[0];
642 const float* outputAsFloat = static_cast<const float*>(outputAllocs[0]->getHostPtr());;
644 for(size_t i = 0; i < expectedOutput->getNumBytes() / sizeof(float); ++i) {
645 if (outputAsFloat[i] != 0.f &&
646 outputAsFloat[i] != -ldexp(1, -24)) {
654 tcu::TestCaseGroup* createNoContractionGroup (tcu::TestContext& testCtx)
656 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "nocontraction", "Test the NoContraction decoration"));
657 vector<CaseParameter> cases;
658 const int numElements = 100;
659 vector<float> inputFloats1 (numElements, 0);
660 vector<float> inputFloats2 (numElements, 0);
661 vector<float> outputFloats (numElements, 0);
662 const StringTemplate shaderTemplate (
663 string(s_ShaderPreamble) +
665 "OpName %main \"main\"\n"
666 "OpName %id \"gl_GlobalInvocationID\"\n"
668 "OpDecorate %id BuiltIn GlobalInvocationId\n"
672 "OpDecorate %buf BufferBlock\n"
673 "OpDecorate %indata1 DescriptorSet 0\n"
674 "OpDecorate %indata1 Binding 0\n"
675 "OpDecorate %indata2 DescriptorSet 0\n"
676 "OpDecorate %indata2 Binding 1\n"
677 "OpDecorate %outdata DescriptorSet 0\n"
678 "OpDecorate %outdata Binding 2\n"
679 "OpDecorate %f32arr ArrayStride 4\n"
680 "OpMemberDecorate %buf 0 Offset 0\n"
682 + string(s_CommonTypes) +
684 "%buf = OpTypeStruct %f32arr\n"
685 "%bufptr = OpTypePointer Uniform %buf\n"
686 "%indata1 = OpVariable %bufptr Uniform\n"
687 "%indata2 = OpVariable %bufptr Uniform\n"
688 "%outdata = OpVariable %bufptr Uniform\n"
690 "%id = OpVariable %uvec3ptr Input\n"
691 "%zero = OpConstant %i32 0\n"
692 "%c_f_m1 = OpConstant %f32 -1.\n"
694 "%main = OpFunction %void None %voidf\n"
696 "%idval = OpLoad %uvec3 %id\n"
697 "%x = OpCompositeExtract %u32 %idval 0\n"
698 "%inloc1 = OpAccessChain %f32ptr %indata1 %zero %x\n"
699 "%inval1 = OpLoad %f32 %inloc1\n"
700 "%inloc2 = OpAccessChain %f32ptr %indata2 %zero %x\n"
701 "%inval2 = OpLoad %f32 %inloc2\n"
702 "%mul = OpFMul %f32 %inval1 %inval2\n"
703 "%add = OpFAdd %f32 %mul %c_f_m1\n"
704 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
705 " OpStore %outloc %add\n"
709 cases.push_back(CaseParameter("multiplication", "OpDecorate %mul NoContraction"));
710 cases.push_back(CaseParameter("addition", "OpDecorate %add NoContraction"));
711 cases.push_back(CaseParameter("both", "OpDecorate %mul NoContraction\nOpDecorate %add NoContraction"));
713 for (size_t ndx = 0; ndx < numElements; ++ndx)
715 inputFloats1[ndx] = 1.f + std::ldexp(1.f, -23); // 1 + 2^-23.
716 inputFloats2[ndx] = 1.f - std::ldexp(1.f, -23); // 1 - 2^-23.
717 // Result for (1 + 2^-23) * (1 - 2^-23) - 1. With NoContraction, the multiplication will be
718 // conducted separately and the result is rounded to 1, or 0x1.fffffcp-1
719 // So the final result will be 0.f or 0x1p-24.
720 // If the operation is combined into a precise fused multiply-add, then the result would be
721 // 2^-46 (0xa8800000).
722 outputFloats[ndx] = 0.f;
725 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
727 map<string, string> specializations;
728 ComputeShaderSpec spec;
730 specializations["DECORATION"] = cases[caseNdx].param;
731 spec.assembly = shaderTemplate.specialize(specializations);
732 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats1)));
733 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
734 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
735 spec.numWorkGroups = IVec3(numElements, 1, 1);
736 // Check against the two possible answers based on rounding mode.
737 spec.verifyIO = &compareNoContractCase;
739 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
741 return group.release();
744 bool compareFRem(const std::vector<BufferSp>&, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs, TestLog&)
746 if (outputAllocs.size() != 1)
749 const BufferSp& expectedOutput = expectedOutputs[0];
750 const float *expectedOutputAsFloat = static_cast<const float*>(expectedOutput->data());
751 const float* outputAsFloat = static_cast<const float*>(outputAllocs[0]->getHostPtr());;
753 for (size_t idx = 0; idx < expectedOutput->getNumBytes() / sizeof(float); ++idx)
755 const float f0 = expectedOutputAsFloat[idx];
756 const float f1 = outputAsFloat[idx];
757 // \todo relative error needs to be fairly high because FRem may be implemented as
758 // (roughly) frac(a/b)*b, so LSB errors can be magnified. But this should be fine for now.
759 if (deFloatAbs((f1 - f0) / f0) > 0.02)
766 tcu::TestCaseGroup* createOpFRemGroup (tcu::TestContext& testCtx)
768 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opfrem", "Test the OpFRem instruction"));
769 ComputeShaderSpec spec;
770 de::Random rnd (deStringHash(group->getName()));
771 const int numElements = 200;
772 vector<float> inputFloats1 (numElements, 0);
773 vector<float> inputFloats2 (numElements, 0);
774 vector<float> outputFloats (numElements, 0);
776 fillRandomScalars(rnd, -10000.f, 10000.f, &inputFloats1[0], numElements);
777 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats2[0], numElements);
779 for (size_t ndx = 0; ndx < numElements; ++ndx)
781 // Guard against divisors near zero.
782 if (std::fabs(inputFloats2[ndx]) < 1e-3)
783 inputFloats2[ndx] = 8.f;
785 // The return value of std::fmod() has the same sign as its first operand, which is how OpFRem spec'd.
786 outputFloats[ndx] = std::fmod(inputFloats1[ndx], inputFloats2[ndx]);
790 string(s_ShaderPreamble) +
792 "OpName %main \"main\"\n"
793 "OpName %id \"gl_GlobalInvocationID\"\n"
795 "OpDecorate %id BuiltIn GlobalInvocationId\n"
797 "OpDecorate %buf BufferBlock\n"
798 "OpDecorate %indata1 DescriptorSet 0\n"
799 "OpDecorate %indata1 Binding 0\n"
800 "OpDecorate %indata2 DescriptorSet 0\n"
801 "OpDecorate %indata2 Binding 1\n"
802 "OpDecorate %outdata DescriptorSet 0\n"
803 "OpDecorate %outdata Binding 2\n"
804 "OpDecorate %f32arr ArrayStride 4\n"
805 "OpMemberDecorate %buf 0 Offset 0\n"
807 + string(s_CommonTypes) +
809 "%buf = OpTypeStruct %f32arr\n"
810 "%bufptr = OpTypePointer Uniform %buf\n"
811 "%indata1 = OpVariable %bufptr Uniform\n"
812 "%indata2 = OpVariable %bufptr Uniform\n"
813 "%outdata = OpVariable %bufptr Uniform\n"
815 "%id = OpVariable %uvec3ptr Input\n"
816 "%zero = OpConstant %i32 0\n"
818 "%main = OpFunction %void None %voidf\n"
820 "%idval = OpLoad %uvec3 %id\n"
821 "%x = OpCompositeExtract %u32 %idval 0\n"
822 "%inloc1 = OpAccessChain %f32ptr %indata1 %zero %x\n"
823 "%inval1 = OpLoad %f32 %inloc1\n"
824 "%inloc2 = OpAccessChain %f32ptr %indata2 %zero %x\n"
825 "%inval2 = OpLoad %f32 %inloc2\n"
826 "%rem = OpFRem %f32 %inval1 %inval2\n"
827 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
828 " OpStore %outloc %rem\n"
832 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats1)));
833 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
834 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
835 spec.numWorkGroups = IVec3(numElements, 1, 1);
836 spec.verifyIO = &compareFRem;
838 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "", spec));
840 return group.release();
843 // Copy contents in the input buffer to the output buffer.
844 tcu::TestCaseGroup* createOpCopyMemoryGroup (tcu::TestContext& testCtx)
846 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opcopymemory", "Test the OpCopyMemory instruction"));
847 de::Random rnd (deStringHash(group->getName()));
848 const int numElements = 100;
850 // 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.
851 ComputeShaderSpec spec1;
852 vector<Vec4> inputFloats1 (numElements);
853 vector<Vec4> outputFloats1 (numElements);
855 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats1[0], numElements * 4);
857 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
858 floorAll(inputFloats1);
860 for (size_t ndx = 0; ndx < numElements; ++ndx)
861 outputFloats1[ndx] = inputFloats1[ndx] + Vec4(0.f, 0.5f, 1.5f, 2.5f);
864 string(s_ShaderPreamble) +
866 "OpName %main \"main\"\n"
867 "OpName %id \"gl_GlobalInvocationID\"\n"
869 "OpDecorate %id BuiltIn GlobalInvocationId\n"
870 "OpDecorate %vec4arr ArrayStride 16\n"
872 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) +
874 "%vec4 = OpTypeVector %f32 4\n"
875 "%vec4ptr_u = OpTypePointer Uniform %vec4\n"
876 "%vec4ptr_f = OpTypePointer Function %vec4\n"
877 "%vec4arr = OpTypeRuntimeArray %vec4\n"
878 "%buf = OpTypeStruct %vec4arr\n"
879 "%bufptr = OpTypePointer Uniform %buf\n"
880 "%indata = OpVariable %bufptr Uniform\n"
881 "%outdata = OpVariable %bufptr Uniform\n"
883 "%id = OpVariable %uvec3ptr Input\n"
884 "%zero = OpConstant %i32 0\n"
885 "%c_f_0 = OpConstant %f32 0.\n"
886 "%c_f_0_5 = OpConstant %f32 0.5\n"
887 "%c_f_1_5 = OpConstant %f32 1.5\n"
888 "%c_f_2_5 = OpConstant %f32 2.5\n"
889 "%c_vec4 = OpConstantComposite %vec4 %c_f_0 %c_f_0_5 %c_f_1_5 %c_f_2_5\n"
891 "%main = OpFunction %void None %voidf\n"
893 "%v_vec4 = OpVariable %vec4ptr_f Function\n"
894 "%idval = OpLoad %uvec3 %id\n"
895 "%x = OpCompositeExtract %u32 %idval 0\n"
896 "%inloc = OpAccessChain %vec4ptr_u %indata %zero %x\n"
897 "%outloc = OpAccessChain %vec4ptr_u %outdata %zero %x\n"
898 " OpCopyMemory %v_vec4 %inloc\n"
899 "%v_vec4_val = OpLoad %vec4 %v_vec4\n"
900 "%add = OpFAdd %vec4 %v_vec4_val %c_vec4\n"
901 " OpStore %outloc %add\n"
905 spec1.inputs.push_back(BufferSp(new Vec4Buffer(inputFloats1)));
906 spec1.outputs.push_back(BufferSp(new Vec4Buffer(outputFloats1)));
907 spec1.numWorkGroups = IVec3(numElements, 1, 1);
909 group->addChild(new SpvAsmComputeShaderCase(testCtx, "vector", "OpCopyMemory elements of vector type", spec1));
911 // The following case copies a float[100] variable from the input buffer to the output buffer.
912 ComputeShaderSpec spec2;
913 vector<float> inputFloats2 (numElements);
914 vector<float> outputFloats2 (numElements);
916 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats2[0], numElements);
918 for (size_t ndx = 0; ndx < numElements; ++ndx)
919 outputFloats2[ndx] = inputFloats2[ndx];
922 string(s_ShaderPreamble) +
924 "OpName %main \"main\"\n"
925 "OpName %id \"gl_GlobalInvocationID\"\n"
927 "OpDecorate %id BuiltIn GlobalInvocationId\n"
928 "OpDecorate %f32arr100 ArrayStride 4\n"
930 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) +
932 "%hundred = OpConstant %u32 100\n"
933 "%f32arr100 = OpTypeArray %f32 %hundred\n"
934 "%f32arr100ptr_f = OpTypePointer Function %f32arr100\n"
935 "%f32arr100ptr_u = OpTypePointer Uniform %f32arr100\n"
936 "%buf = OpTypeStruct %f32arr100\n"
937 "%bufptr = OpTypePointer Uniform %buf\n"
938 "%indata = OpVariable %bufptr Uniform\n"
939 "%outdata = OpVariable %bufptr Uniform\n"
941 "%id = OpVariable %uvec3ptr Input\n"
942 "%zero = OpConstant %i32 0\n"
944 "%main = OpFunction %void None %voidf\n"
946 "%var = OpVariable %f32arr100ptr_f Function\n"
947 "%inarr = OpAccessChain %f32arr100ptr_u %indata %zero\n"
948 "%outarr = OpAccessChain %f32arr100ptr_u %outdata %zero\n"
949 " OpCopyMemory %var %inarr\n"
950 " OpCopyMemory %outarr %var\n"
954 spec2.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
955 spec2.outputs.push_back(BufferSp(new Float32Buffer(outputFloats2)));
956 spec2.numWorkGroups = IVec3(1, 1, 1);
958 group->addChild(new SpvAsmComputeShaderCase(testCtx, "array", "OpCopyMemory elements of array type", spec2));
960 // The following case copies a struct{vec4, vec4, vec4, vec4} variable from the input buffer to the output buffer.
961 ComputeShaderSpec spec3;
962 vector<float> inputFloats3 (16);
963 vector<float> outputFloats3 (16);
965 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats3[0], 16);
967 for (size_t ndx = 0; ndx < 16; ++ndx)
968 outputFloats3[ndx] = inputFloats3[ndx];
971 string(s_ShaderPreamble) +
973 "OpName %main \"main\"\n"
974 "OpName %id \"gl_GlobalInvocationID\"\n"
976 "OpDecorate %id BuiltIn GlobalInvocationId\n"
977 "OpMemberDecorate %buf 0 Offset 0\n"
978 "OpMemberDecorate %buf 1 Offset 16\n"
979 "OpMemberDecorate %buf 2 Offset 32\n"
980 "OpMemberDecorate %buf 3 Offset 48\n"
982 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) +
984 "%vec4 = OpTypeVector %f32 4\n"
985 "%buf = OpTypeStruct %vec4 %vec4 %vec4 %vec4\n"
986 "%bufptr = OpTypePointer Uniform %buf\n"
987 "%indata = OpVariable %bufptr Uniform\n"
988 "%outdata = OpVariable %bufptr Uniform\n"
989 "%vec4stptr = OpTypePointer Function %buf\n"
991 "%id = OpVariable %uvec3ptr Input\n"
992 "%zero = OpConstant %i32 0\n"
994 "%main = OpFunction %void None %voidf\n"
996 "%var = OpVariable %vec4stptr Function\n"
997 " OpCopyMemory %var %indata\n"
998 " OpCopyMemory %outdata %var\n"
1002 spec3.inputs.push_back(BufferSp(new Float32Buffer(inputFloats3)));
1003 spec3.outputs.push_back(BufferSp(new Float32Buffer(outputFloats3)));
1004 spec3.numWorkGroups = IVec3(1, 1, 1);
1006 group->addChild(new SpvAsmComputeShaderCase(testCtx, "struct", "OpCopyMemory elements of struct type", spec3));
1008 // The following case negates multiple float variables from the input buffer and stores the results to the output buffer.
1009 ComputeShaderSpec spec4;
1010 vector<float> inputFloats4 (numElements);
1011 vector<float> outputFloats4 (numElements);
1013 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats4[0], numElements);
1015 for (size_t ndx = 0; ndx < numElements; ++ndx)
1016 outputFloats4[ndx] = -inputFloats4[ndx];
1019 string(s_ShaderPreamble) +
1021 "OpName %main \"main\"\n"
1022 "OpName %id \"gl_GlobalInvocationID\"\n"
1024 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1026 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) + string(s_InputOutputBuffer) +
1028 "%f32ptr_f = OpTypePointer Function %f32\n"
1029 "%id = OpVariable %uvec3ptr Input\n"
1030 "%zero = OpConstant %i32 0\n"
1032 "%main = OpFunction %void None %voidf\n"
1033 "%label = OpLabel\n"
1034 "%var = OpVariable %f32ptr_f Function\n"
1035 "%idval = OpLoad %uvec3 %id\n"
1036 "%x = OpCompositeExtract %u32 %idval 0\n"
1037 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
1038 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
1039 " OpCopyMemory %var %inloc\n"
1040 "%val = OpLoad %f32 %var\n"
1041 "%neg = OpFNegate %f32 %val\n"
1042 " OpStore %outloc %neg\n"
1046 spec4.inputs.push_back(BufferSp(new Float32Buffer(inputFloats4)));
1047 spec4.outputs.push_back(BufferSp(new Float32Buffer(outputFloats4)));
1048 spec4.numWorkGroups = IVec3(numElements, 1, 1);
1050 group->addChild(new SpvAsmComputeShaderCase(testCtx, "float", "OpCopyMemory elements of float type", spec4));
1052 return group.release();
1055 tcu::TestCaseGroup* createOpCopyObjectGroup (tcu::TestContext& testCtx)
1057 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opcopyobject", "Test the OpCopyObject instruction"));
1058 ComputeShaderSpec spec;
1059 de::Random rnd (deStringHash(group->getName()));
1060 const int numElements = 100;
1061 vector<float> inputFloats (numElements, 0);
1062 vector<float> outputFloats (numElements, 0);
1064 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats[0], numElements);
1066 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
1067 floorAll(inputFloats);
1069 for (size_t ndx = 0; ndx < numElements; ++ndx)
1070 outputFloats[ndx] = inputFloats[ndx] + 7.5f;
1073 string(s_ShaderPreamble) +
1075 "OpName %main \"main\"\n"
1076 "OpName %id \"gl_GlobalInvocationID\"\n"
1078 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1080 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) +
1082 "%fmat = OpTypeMatrix %fvec3 3\n"
1083 "%three = OpConstant %u32 3\n"
1084 "%farr = OpTypeArray %f32 %three\n"
1085 "%fst = OpTypeStruct %f32 %f32\n"
1087 + string(s_InputOutputBuffer) +
1089 "%id = OpVariable %uvec3ptr Input\n"
1090 "%zero = OpConstant %i32 0\n"
1091 "%c_f = OpConstant %f32 1.5\n"
1092 "%c_fvec3 = OpConstantComposite %fvec3 %c_f %c_f %c_f\n"
1093 "%c_fmat = OpConstantComposite %fmat %c_fvec3 %c_fvec3 %c_fvec3\n"
1094 "%c_farr = OpConstantComposite %farr %c_f %c_f %c_f\n"
1095 "%c_fst = OpConstantComposite %fst %c_f %c_f\n"
1097 "%main = OpFunction %void None %voidf\n"
1098 "%label = OpLabel\n"
1099 "%c_f_copy = OpCopyObject %f32 %c_f\n"
1100 "%c_fvec3_copy = OpCopyObject %fvec3 %c_fvec3\n"
1101 "%c_fmat_copy = OpCopyObject %fmat %c_fmat\n"
1102 "%c_farr_copy = OpCopyObject %farr %c_farr\n"
1103 "%c_fst_copy = OpCopyObject %fst %c_fst\n"
1104 "%fvec3_elem = OpCompositeExtract %f32 %c_fvec3_copy 0\n"
1105 "%fmat_elem = OpCompositeExtract %f32 %c_fmat_copy 1 2\n"
1106 "%farr_elem = OpCompositeExtract %f32 %c_farr_copy 2\n"
1107 "%fst_elem = OpCompositeExtract %f32 %c_fst_copy 1\n"
1108 // Add up. 1.5 * 5 = 7.5.
1109 "%add1 = OpFAdd %f32 %c_f_copy %fvec3_elem\n"
1110 "%add2 = OpFAdd %f32 %add1 %fmat_elem\n"
1111 "%add3 = OpFAdd %f32 %add2 %farr_elem\n"
1112 "%add4 = OpFAdd %f32 %add3 %fst_elem\n"
1114 "%idval = OpLoad %uvec3 %id\n"
1115 "%x = OpCompositeExtract %u32 %idval 0\n"
1116 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
1117 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
1118 "%inval = OpLoad %f32 %inloc\n"
1119 "%add = OpFAdd %f32 %add4 %inval\n"
1120 " OpStore %outloc %add\n"
1123 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
1124 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
1125 spec.numWorkGroups = IVec3(numElements, 1, 1);
1127 group->addChild(new SpvAsmComputeShaderCase(testCtx, "spotcheck", "OpCopyObject on different types", spec));
1129 return group.release();
1131 // Assembly code used for testing OpUnreachable is based on GLSL source code:
1135 // layout(std140, set = 0, binding = 0) readonly buffer Input {
1136 // float elements[];
1138 // layout(std140, set = 0, binding = 1) writeonly buffer Output {
1139 // float elements[];
1142 // void not_called_func() {
1143 // // place OpUnreachable here
1146 // uint modulo4(uint val) {
1147 // switch (val % uint(4)) {
1148 // case 0: return 3;
1149 // case 1: return 2;
1150 // case 2: return 1;
1151 // case 3: return 0;
1152 // default: return 100; // place OpUnreachable here
1158 // // place OpUnreachable here
1162 // uint x = gl_GlobalInvocationID.x;
1163 // if (const5() > modulo4(1000)) {
1164 // output_data.elements[x] = -input_data.elements[x];
1166 // // place OpUnreachable here
1167 // output_data.elements[x] = input_data.elements[x];
1171 tcu::TestCaseGroup* createOpUnreachableGroup (tcu::TestContext& testCtx)
1173 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opunreachable", "Test the OpUnreachable instruction"));
1174 ComputeShaderSpec spec;
1175 de::Random rnd (deStringHash(group->getName()));
1176 const int numElements = 100;
1177 vector<float> positiveFloats (numElements, 0);
1178 vector<float> negativeFloats (numElements, 0);
1180 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
1182 for (size_t ndx = 0; ndx < numElements; ++ndx)
1183 negativeFloats[ndx] = -positiveFloats[ndx];
1186 string(s_ShaderPreamble) +
1188 "OpSource GLSL 430\n"
1189 "OpName %main \"main\"\n"
1190 "OpName %func_not_called_func \"not_called_func(\"\n"
1191 "OpName %func_modulo4 \"modulo4(u1;\"\n"
1192 "OpName %func_const5 \"const5(\"\n"
1193 "OpName %id \"gl_GlobalInvocationID\"\n"
1195 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1197 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) +
1199 "%u32ptr = OpTypePointer Function %u32\n"
1200 "%uintfuint = OpTypeFunction %u32 %u32ptr\n"
1201 "%unitf = OpTypeFunction %u32\n"
1203 "%id = OpVariable %uvec3ptr Input\n"
1204 "%zero = OpConstant %u32 0\n"
1205 "%one = OpConstant %u32 1\n"
1206 "%two = OpConstant %u32 2\n"
1207 "%three = OpConstant %u32 3\n"
1208 "%four = OpConstant %u32 4\n"
1209 "%five = OpConstant %u32 5\n"
1210 "%hundred = OpConstant %u32 100\n"
1211 "%thousand = OpConstant %u32 1000\n"
1213 + string(s_InputOutputBuffer) +
1216 "%main = OpFunction %void None %voidf\n"
1217 "%main_entry = OpLabel\n"
1218 "%v_thousand = OpVariable %u32ptr Function %thousand\n"
1219 "%idval = OpLoad %uvec3 %id\n"
1220 "%x = OpCompositeExtract %u32 %idval 0\n"
1221 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
1222 "%inval = OpLoad %f32 %inloc\n"
1223 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
1224 "%ret_const5 = OpFunctionCall %u32 %func_const5\n"
1225 "%ret_modulo4 = OpFunctionCall %u32 %func_modulo4 %v_thousand\n"
1226 "%cmp_gt = OpUGreaterThan %bool %ret_const5 %ret_modulo4\n"
1227 " OpSelectionMerge %if_end None\n"
1228 " OpBranchConditional %cmp_gt %if_true %if_false\n"
1229 "%if_true = OpLabel\n"
1230 "%negate = OpFNegate %f32 %inval\n"
1231 " OpStore %outloc %negate\n"
1232 " OpBranch %if_end\n"
1233 "%if_false = OpLabel\n"
1234 " OpUnreachable\n" // Unreachable else branch for if statement
1235 "%if_end = OpLabel\n"
1239 // not_called_function()
1240 "%func_not_called_func = OpFunction %void None %voidf\n"
1241 "%not_called_func_entry = OpLabel\n"
1242 " OpUnreachable\n" // Unreachable entry block in not called static function
1246 "%func_modulo4 = OpFunction %u32 None %uintfuint\n"
1247 "%valptr = OpFunctionParameter %u32ptr\n"
1248 "%modulo4_entry = OpLabel\n"
1249 "%val = OpLoad %u32 %valptr\n"
1250 "%modulo = OpUMod %u32 %val %four\n"
1251 " OpSelectionMerge %switch_merge None\n"
1252 " OpSwitch %modulo %default 0 %case0 1 %case1 2 %case2 3 %case3\n"
1253 "%case0 = OpLabel\n"
1254 " OpReturnValue %three\n"
1255 "%case1 = OpLabel\n"
1256 " OpReturnValue %two\n"
1257 "%case2 = OpLabel\n"
1258 " OpReturnValue %one\n"
1259 "%case3 = OpLabel\n"
1260 " OpReturnValue %zero\n"
1261 "%default = OpLabel\n"
1262 " OpUnreachable\n" // Unreachable default case for switch statement
1263 "%switch_merge = OpLabel\n"
1264 " OpUnreachable\n" // Unreachable merge block for switch statement
1268 "%func_const5 = OpFunction %u32 None %unitf\n"
1269 "%const5_entry = OpLabel\n"
1270 " OpReturnValue %five\n"
1271 "%unreachable = OpLabel\n"
1272 " OpUnreachable\n" // Unreachable block in function
1274 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
1275 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
1276 spec.numWorkGroups = IVec3(numElements, 1, 1);
1278 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "OpUnreachable appearing at different places", spec));
1280 return group.release();
1283 // Assembly code used for testing decoration group is based on GLSL source code:
1287 // layout(std140, set = 0, binding = 0) readonly buffer Input0 {
1288 // float elements[];
1290 // layout(std140, set = 0, binding = 1) readonly buffer Input1 {
1291 // float elements[];
1293 // layout(std140, set = 0, binding = 2) readonly buffer Input2 {
1294 // float elements[];
1296 // layout(std140, set = 0, binding = 3) readonly buffer Input3 {
1297 // float elements[];
1299 // layout(std140, set = 0, binding = 4) readonly buffer Input4 {
1300 // float elements[];
1302 // layout(std140, set = 0, binding = 5) writeonly buffer Output {
1303 // float elements[];
1307 // uint x = gl_GlobalInvocationID.x;
1308 // output_data.elements[x] = input_data0.elements[x] + input_data1.elements[x] + input_data2.elements[x] + input_data3.elements[x] + input_data4.elements[x];
1310 tcu::TestCaseGroup* createDecorationGroupGroup (tcu::TestContext& testCtx)
1312 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "decoration_group", "Test the OpDecorationGroup & OpGroupDecorate instruction"));
1313 ComputeShaderSpec spec;
1314 de::Random rnd (deStringHash(group->getName()));
1315 const int numElements = 100;
1316 vector<float> inputFloats0 (numElements, 0);
1317 vector<float> inputFloats1 (numElements, 0);
1318 vector<float> inputFloats2 (numElements, 0);
1319 vector<float> inputFloats3 (numElements, 0);
1320 vector<float> inputFloats4 (numElements, 0);
1321 vector<float> outputFloats (numElements, 0);
1323 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats0[0], numElements);
1324 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats1[0], numElements);
1325 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats2[0], numElements);
1326 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats3[0], numElements);
1327 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats4[0], numElements);
1329 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
1330 floorAll(inputFloats0);
1331 floorAll(inputFloats1);
1332 floorAll(inputFloats2);
1333 floorAll(inputFloats3);
1334 floorAll(inputFloats4);
1336 for (size_t ndx = 0; ndx < numElements; ++ndx)
1337 outputFloats[ndx] = inputFloats0[ndx] + inputFloats1[ndx] + inputFloats2[ndx] + inputFloats3[ndx] + inputFloats4[ndx];
1340 string(s_ShaderPreamble) +
1342 "OpSource GLSL 430\n"
1343 "OpName %main \"main\"\n"
1344 "OpName %id \"gl_GlobalInvocationID\"\n"
1346 // Not using group decoration on variable.
1347 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1348 // Not using group decoration on type.
1349 "OpDecorate %f32arr ArrayStride 4\n"
1351 "OpDecorate %groups BufferBlock\n"
1352 "OpDecorate %groupm Offset 0\n"
1353 "%groups = OpDecorationGroup\n"
1354 "%groupm = OpDecorationGroup\n"
1356 // Group decoration on multiple structs.
1357 "OpGroupDecorate %groups %outbuf %inbuf0 %inbuf1 %inbuf2 %inbuf3 %inbuf4\n"
1358 // Group decoration on multiple struct members.
1359 "OpGroupMemberDecorate %groupm %outbuf 0 %inbuf0 0 %inbuf1 0 %inbuf2 0 %inbuf3 0 %inbuf4 0\n"
1361 "OpDecorate %group1 DescriptorSet 0\n"
1362 "OpDecorate %group3 DescriptorSet 0\n"
1363 "OpDecorate %group3 NonWritable\n"
1364 "OpDecorate %group3 Restrict\n"
1365 "%group0 = OpDecorationGroup\n"
1366 "%group1 = OpDecorationGroup\n"
1367 "%group3 = OpDecorationGroup\n"
1369 // Applying the same decoration group multiple times.
1370 "OpGroupDecorate %group1 %outdata\n"
1371 "OpGroupDecorate %group1 %outdata\n"
1372 "OpGroupDecorate %group1 %outdata\n"
1373 "OpDecorate %outdata DescriptorSet 0\n"
1374 "OpDecorate %outdata Binding 5\n"
1375 // Applying decoration group containing nothing.
1376 "OpGroupDecorate %group0 %indata0\n"
1377 "OpDecorate %indata0 DescriptorSet 0\n"
1378 "OpDecorate %indata0 Binding 0\n"
1379 // Applying decoration group containing one decoration.
1380 "OpGroupDecorate %group1 %indata1\n"
1381 "OpDecorate %indata1 Binding 1\n"
1382 // Applying decoration group containing multiple decorations.
1383 "OpGroupDecorate %group3 %indata2 %indata3\n"
1384 "OpDecorate %indata2 Binding 2\n"
1385 "OpDecorate %indata3 Binding 3\n"
1386 // Applying multiple decoration groups (with overlapping).
1387 "OpGroupDecorate %group0 %indata4\n"
1388 "OpGroupDecorate %group1 %indata4\n"
1389 "OpGroupDecorate %group3 %indata4\n"
1390 "OpDecorate %indata4 Binding 4\n"
1392 + string(s_CommonTypes) +
1394 "%id = OpVariable %uvec3ptr Input\n"
1395 "%zero = OpConstant %i32 0\n"
1397 "%outbuf = OpTypeStruct %f32arr\n"
1398 "%outbufptr = OpTypePointer Uniform %outbuf\n"
1399 "%outdata = OpVariable %outbufptr Uniform\n"
1400 "%inbuf0 = OpTypeStruct %f32arr\n"
1401 "%inbuf0ptr = OpTypePointer Uniform %inbuf0\n"
1402 "%indata0 = OpVariable %inbuf0ptr Uniform\n"
1403 "%inbuf1 = OpTypeStruct %f32arr\n"
1404 "%inbuf1ptr = OpTypePointer Uniform %inbuf1\n"
1405 "%indata1 = OpVariable %inbuf1ptr Uniform\n"
1406 "%inbuf2 = OpTypeStruct %f32arr\n"
1407 "%inbuf2ptr = OpTypePointer Uniform %inbuf2\n"
1408 "%indata2 = OpVariable %inbuf2ptr Uniform\n"
1409 "%inbuf3 = OpTypeStruct %f32arr\n"
1410 "%inbuf3ptr = OpTypePointer Uniform %inbuf3\n"
1411 "%indata3 = OpVariable %inbuf3ptr Uniform\n"
1412 "%inbuf4 = OpTypeStruct %f32arr\n"
1413 "%inbufptr = OpTypePointer Uniform %inbuf4\n"
1414 "%indata4 = OpVariable %inbufptr Uniform\n"
1416 "%main = OpFunction %void None %voidf\n"
1417 "%label = OpLabel\n"
1418 "%idval = OpLoad %uvec3 %id\n"
1419 "%x = OpCompositeExtract %u32 %idval 0\n"
1420 "%inloc0 = OpAccessChain %f32ptr %indata0 %zero %x\n"
1421 "%inloc1 = OpAccessChain %f32ptr %indata1 %zero %x\n"
1422 "%inloc2 = OpAccessChain %f32ptr %indata2 %zero %x\n"
1423 "%inloc3 = OpAccessChain %f32ptr %indata3 %zero %x\n"
1424 "%inloc4 = OpAccessChain %f32ptr %indata4 %zero %x\n"
1425 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
1426 "%inval0 = OpLoad %f32 %inloc0\n"
1427 "%inval1 = OpLoad %f32 %inloc1\n"
1428 "%inval2 = OpLoad %f32 %inloc2\n"
1429 "%inval3 = OpLoad %f32 %inloc3\n"
1430 "%inval4 = OpLoad %f32 %inloc4\n"
1431 "%add0 = OpFAdd %f32 %inval0 %inval1\n"
1432 "%add1 = OpFAdd %f32 %add0 %inval2\n"
1433 "%add2 = OpFAdd %f32 %add1 %inval3\n"
1434 "%add = OpFAdd %f32 %add2 %inval4\n"
1435 " OpStore %outloc %add\n"
1438 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats0)));
1439 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats1)));
1440 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
1441 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats3)));
1442 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats4)));
1443 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
1444 spec.numWorkGroups = IVec3(numElements, 1, 1);
1446 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "decoration group cases", spec));
1448 return group.release();
1451 struct SpecConstantTwoIntCase
1453 const char* caseName;
1454 const char* scDefinition0;
1455 const char* scDefinition1;
1456 const char* scResultType;
1457 const char* scOperation;
1458 deInt32 scActualValue0;
1459 deInt32 scActualValue1;
1460 const char* resultOperation;
1461 vector<deInt32> expectedOutput;
1463 SpecConstantTwoIntCase (const char* name,
1464 const char* definition0,
1465 const char* definition1,
1466 const char* resultType,
1467 const char* operation,
1470 const char* resultOp,
1471 const vector<deInt32>& output)
1473 , scDefinition0 (definition0)
1474 , scDefinition1 (definition1)
1475 , scResultType (resultType)
1476 , scOperation (operation)
1477 , scActualValue0 (value0)
1478 , scActualValue1 (value1)
1479 , resultOperation (resultOp)
1480 , expectedOutput (output) {}
1483 tcu::TestCaseGroup* createSpecConstantGroup (tcu::TestContext& testCtx)
1485 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opspecconstantop", "Test the OpSpecConstantOp instruction"));
1486 vector<SpecConstantTwoIntCase> cases;
1487 de::Random rnd (deStringHash(group->getName()));
1488 const int numElements = 100;
1489 vector<deInt32> inputInts (numElements, 0);
1490 vector<deInt32> outputInts1 (numElements, 0);
1491 vector<deInt32> outputInts2 (numElements, 0);
1492 vector<deInt32> outputInts3 (numElements, 0);
1493 vector<deInt32> outputInts4 (numElements, 0);
1494 const StringTemplate shaderTemplate (
1495 string(s_ShaderPreamble) +
1497 "OpName %main \"main\"\n"
1498 "OpName %id \"gl_GlobalInvocationID\"\n"
1500 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1501 "OpDecorate %sc_0 SpecId 0\n"
1502 "OpDecorate %sc_1 SpecId 1\n"
1503 "OpDecorate %i32arr ArrayStride 4\n"
1505 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) +
1507 "%buf = OpTypeStruct %i32arr\n"
1508 "%bufptr = OpTypePointer Uniform %buf\n"
1509 "%indata = OpVariable %bufptr Uniform\n"
1510 "%outdata = OpVariable %bufptr Uniform\n"
1512 "%id = OpVariable %uvec3ptr Input\n"
1513 "%zero = OpConstant %i32 0\n"
1515 "%sc_0 = OpSpecConstant${SC_DEF0}\n"
1516 "%sc_1 = OpSpecConstant${SC_DEF1}\n"
1517 "%sc_final = OpSpecConstantOp ${SC_RESULT_TYPE} ${SC_OP}\n"
1519 "%main = OpFunction %void None %voidf\n"
1520 "%label = OpLabel\n"
1521 "%idval = OpLoad %uvec3 %id\n"
1522 "%x = OpCompositeExtract %u32 %idval 0\n"
1523 "%inloc = OpAccessChain %i32ptr %indata %zero %x\n"
1524 "%inval = OpLoad %i32 %inloc\n"
1525 "%final = ${GEN_RESULT}\n"
1526 "%outloc = OpAccessChain %i32ptr %outdata %zero %x\n"
1527 " OpStore %outloc %final\n"
1529 " OpFunctionEnd\n");
1531 fillRandomScalars(rnd, -65536, 65536, &inputInts[0], numElements);
1533 for (size_t ndx = 0; ndx < numElements; ++ndx)
1535 outputInts1[ndx] = inputInts[ndx] + 42;
1536 outputInts2[ndx] = inputInts[ndx];
1537 outputInts3[ndx] = inputInts[ndx] - 11200;
1538 outputInts4[ndx] = inputInts[ndx] + 1;
1541 const char addScToInput[] = "OpIAdd %i32 %inval %sc_final";
1542 const char selectTrueUsingSc[] = "OpSelect %i32 %sc_final %inval %zero";
1543 const char selectFalseUsingSc[] = "OpSelect %i32 %sc_final %zero %inval";
1545 cases.push_back(SpecConstantTwoIntCase("iadd", " %i32 0", " %i32 0", "%i32", "IAdd %sc_0 %sc_1", 62, -20, addScToInput, outputInts1));
1546 cases.push_back(SpecConstantTwoIntCase("isub", " %i32 0", " %i32 0", "%i32", "ISub %sc_0 %sc_1", 100, 58, addScToInput, outputInts1));
1547 cases.push_back(SpecConstantTwoIntCase("imul", " %i32 0", " %i32 0", "%i32", "IMul %sc_0 %sc_1", -2, -21, addScToInput, outputInts1));
1548 cases.push_back(SpecConstantTwoIntCase("sdiv", " %i32 0", " %i32 0", "%i32", "SDiv %sc_0 %sc_1", -126, -3, addScToInput, outputInts1));
1549 cases.push_back(SpecConstantTwoIntCase("udiv", " %i32 0", " %i32 0", "%i32", "UDiv %sc_0 %sc_1", 126, 3, addScToInput, outputInts1));
1550 cases.push_back(SpecConstantTwoIntCase("srem", " %i32 0", " %i32 0", "%i32", "SRem %sc_0 %sc_1", 7, 3, addScToInput, outputInts4));
1551 cases.push_back(SpecConstantTwoIntCase("smod", " %i32 0", " %i32 0", "%i32", "SMod %sc_0 %sc_1", 7, 3, addScToInput, outputInts4));
1552 cases.push_back(SpecConstantTwoIntCase("umod", " %i32 0", " %i32 0", "%i32", "UMod %sc_0 %sc_1", 342, 50, addScToInput, outputInts1));
1553 cases.push_back(SpecConstantTwoIntCase("bitwiseand", " %i32 0", " %i32 0", "%i32", "BitwiseAnd %sc_0 %sc_1", 42, 63, addScToInput, outputInts1));
1554 cases.push_back(SpecConstantTwoIntCase("bitwiseor", " %i32 0", " %i32 0", "%i32", "BitwiseOr %sc_0 %sc_1", 34, 8, addScToInput, outputInts1));
1555 cases.push_back(SpecConstantTwoIntCase("bitwisexor", " %i32 0", " %i32 0", "%i32", "BitwiseXor %sc_0 %sc_1", 18, 56, addScToInput, outputInts1));
1556 cases.push_back(SpecConstantTwoIntCase("shiftrightlogical", " %i32 0", " %i32 0", "%i32", "ShiftRightLogical %sc_0 %sc_1", 168, 2, addScToInput, outputInts1));
1557 cases.push_back(SpecConstantTwoIntCase("shiftrightarithmetic", " %i32 0", " %i32 0", "%i32", "ShiftRightArithmetic %sc_0 %sc_1", 168, 2, addScToInput, outputInts1));
1558 cases.push_back(SpecConstantTwoIntCase("shiftleftlogical", " %i32 0", " %i32 0", "%i32", "ShiftLeftLogical %sc_0 %sc_1", 21, 1, addScToInput, outputInts1));
1559 cases.push_back(SpecConstantTwoIntCase("slessthan", " %i32 0", " %i32 0", "%bool", "SLessThan %sc_0 %sc_1", -20, -10, selectTrueUsingSc, outputInts2));
1560 cases.push_back(SpecConstantTwoIntCase("ulessthan", " %i32 0", " %i32 0", "%bool", "ULessThan %sc_0 %sc_1", 10, 20, selectTrueUsingSc, outputInts2));
1561 cases.push_back(SpecConstantTwoIntCase("sgreaterthan", " %i32 0", " %i32 0", "%bool", "SGreaterThan %sc_0 %sc_1", -1000, 50, selectFalseUsingSc, outputInts2));
1562 cases.push_back(SpecConstantTwoIntCase("ugreaterthan", " %i32 0", " %i32 0", "%bool", "UGreaterThan %sc_0 %sc_1", 10, 5, selectTrueUsingSc, outputInts2));
1563 cases.push_back(SpecConstantTwoIntCase("slessthanequal", " %i32 0", " %i32 0", "%bool", "SLessThanEqual %sc_0 %sc_1", -10, -10, selectTrueUsingSc, outputInts2));
1564 cases.push_back(SpecConstantTwoIntCase("ulessthanequal", " %i32 0", " %i32 0", "%bool", "ULessThanEqual %sc_0 %sc_1", 50, 100, selectTrueUsingSc, outputInts2));
1565 cases.push_back(SpecConstantTwoIntCase("sgreaterthanequal", " %i32 0", " %i32 0", "%bool", "SGreaterThanEqual %sc_0 %sc_1", -1000, 50, selectFalseUsingSc, outputInts2));
1566 cases.push_back(SpecConstantTwoIntCase("ugreaterthanequal", " %i32 0", " %i32 0", "%bool", "UGreaterThanEqual %sc_0 %sc_1", 10, 10, selectTrueUsingSc, outputInts2));
1567 cases.push_back(SpecConstantTwoIntCase("iequal", " %i32 0", " %i32 0", "%bool", "IEqual %sc_0 %sc_1", 42, 24, selectFalseUsingSc, outputInts2));
1568 cases.push_back(SpecConstantTwoIntCase("logicaland", "True %bool", "True %bool", "%bool", "LogicalAnd %sc_0 %sc_1", 0, 1, selectFalseUsingSc, outputInts2));
1569 cases.push_back(SpecConstantTwoIntCase("logicalor", "False %bool", "False %bool", "%bool", "LogicalOr %sc_0 %sc_1", 1, 0, selectTrueUsingSc, outputInts2));
1570 cases.push_back(SpecConstantTwoIntCase("logicalequal", "True %bool", "True %bool", "%bool", "LogicalEqual %sc_0 %sc_1", 0, 1, selectFalseUsingSc, outputInts2));
1571 cases.push_back(SpecConstantTwoIntCase("logicalnotequal", "False %bool", "False %bool", "%bool", "LogicalNotEqual %sc_0 %sc_1", 1, 0, selectTrueUsingSc, outputInts2));
1572 cases.push_back(SpecConstantTwoIntCase("snegate", " %i32 0", " %i32 0", "%i32", "SNegate %sc_0", -42, 0, addScToInput, outputInts1));
1573 cases.push_back(SpecConstantTwoIntCase("not", " %i32 0", " %i32 0", "%i32", "Not %sc_0", -43, 0, addScToInput, outputInts1));
1574 cases.push_back(SpecConstantTwoIntCase("logicalnot", "False %bool", "False %bool", "%bool", "LogicalNot %sc_0", 1, 0, selectFalseUsingSc, outputInts2));
1575 cases.push_back(SpecConstantTwoIntCase("select", "False %bool", " %i32 0", "%i32", "Select %sc_0 %sc_1 %zero", 1, 42, addScToInput, outputInts1));
1576 // OpSConvert, OpFConvert: these two instructions involve ints/floats of different bitwidths.
1578 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
1580 map<string, string> specializations;
1581 ComputeShaderSpec spec;
1583 specializations["SC_DEF0"] = cases[caseNdx].scDefinition0;
1584 specializations["SC_DEF1"] = cases[caseNdx].scDefinition1;
1585 specializations["SC_RESULT_TYPE"] = cases[caseNdx].scResultType;
1586 specializations["SC_OP"] = cases[caseNdx].scOperation;
1587 specializations["GEN_RESULT"] = cases[caseNdx].resultOperation;
1589 spec.assembly = shaderTemplate.specialize(specializations);
1590 spec.inputs.push_back(BufferSp(new Int32Buffer(inputInts)));
1591 spec.outputs.push_back(BufferSp(new Int32Buffer(cases[caseNdx].expectedOutput)));
1592 spec.numWorkGroups = IVec3(numElements, 1, 1);
1593 spec.specConstants.push_back(cases[caseNdx].scActualValue0);
1594 spec.specConstants.push_back(cases[caseNdx].scActualValue1);
1596 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].caseName, cases[caseNdx].caseName, spec));
1599 ComputeShaderSpec spec;
1602 string(s_ShaderPreamble) +
1604 "OpName %main \"main\"\n"
1605 "OpName %id \"gl_GlobalInvocationID\"\n"
1607 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1608 "OpDecorate %sc_0 SpecId 0\n"
1609 "OpDecorate %sc_1 SpecId 1\n"
1610 "OpDecorate %sc_2 SpecId 2\n"
1611 "OpDecorate %i32arr ArrayStride 4\n"
1613 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) +
1615 "%ivec3 = OpTypeVector %i32 3\n"
1616 "%buf = OpTypeStruct %i32arr\n"
1617 "%bufptr = OpTypePointer Uniform %buf\n"
1618 "%indata = OpVariable %bufptr Uniform\n"
1619 "%outdata = OpVariable %bufptr Uniform\n"
1621 "%id = OpVariable %uvec3ptr Input\n"
1622 "%zero = OpConstant %i32 0\n"
1623 "%ivec3_0 = OpConstantComposite %ivec3 %zero %zero %zero\n"
1625 "%sc_0 = OpSpecConstant %i32 0\n"
1626 "%sc_1 = OpSpecConstant %i32 0\n"
1627 "%sc_2 = OpSpecConstant %i32 0\n"
1628 "%sc_vec3_0 = OpSpecConstantOp %ivec3 CompositeInsert %sc_0 %ivec3_0 0\n" // (sc_0, 0, 0)
1629 "%sc_vec3_1 = OpSpecConstantOp %ivec3 CompositeInsert %sc_1 %ivec3_0 1\n" // (0, sc_1, 0)
1630 "%sc_vec3_2 = OpSpecConstantOp %ivec3 CompositeInsert %sc_2 %ivec3_0 2\n" // (0, 0, sc_2)
1631 "%sc_vec3_01 = OpSpecConstantOp %ivec3 VectorShuffle %sc_vec3_0 %sc_vec3_1 1 0 4\n" // (0, sc_0, sc_1)
1632 "%sc_vec3_012 = OpSpecConstantOp %ivec3 VectorShuffle %sc_vec3_01 %sc_vec3_2 5 1 2\n" // (sc_2, sc_0, sc_1)
1633 "%sc_ext_0 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 0\n" // sc_2
1634 "%sc_ext_1 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 1\n" // sc_0
1635 "%sc_ext_2 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 2\n" // sc_1
1636 "%sc_sub = OpSpecConstantOp %i32 ISub %sc_ext_0 %sc_ext_1\n" // (sc_2 - sc_0)
1637 "%sc_final = OpSpecConstantOp %i32 IMul %sc_sub %sc_ext_2\n" // (sc_2 - sc_0) * sc_1
1639 "%main = OpFunction %void None %voidf\n"
1640 "%label = OpLabel\n"
1641 "%idval = OpLoad %uvec3 %id\n"
1642 "%x = OpCompositeExtract %u32 %idval 0\n"
1643 "%inloc = OpAccessChain %i32ptr %indata %zero %x\n"
1644 "%inval = OpLoad %i32 %inloc\n"
1645 "%final = OpIAdd %i32 %inval %sc_final\n"
1646 "%outloc = OpAccessChain %i32ptr %outdata %zero %x\n"
1647 " OpStore %outloc %final\n"
1650 spec.inputs.push_back(BufferSp(new Int32Buffer(inputInts)));
1651 spec.outputs.push_back(BufferSp(new Int32Buffer(outputInts3)));
1652 spec.numWorkGroups = IVec3(numElements, 1, 1);
1653 spec.specConstants.push_back(123);
1654 spec.specConstants.push_back(56);
1655 spec.specConstants.push_back(-77);
1657 group->addChild(new SpvAsmComputeShaderCase(testCtx, "vector_related", "VectorShuffle, CompositeExtract, & CompositeInsert", spec));
1659 return group.release();
1662 tcu::TestCaseGroup* createOpPhiGroup (tcu::TestContext& testCtx)
1664 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opphi", "Test the OpPhi instruction"));
1665 ComputeShaderSpec spec1;
1666 ComputeShaderSpec spec2;
1667 ComputeShaderSpec spec3;
1668 de::Random rnd (deStringHash(group->getName()));
1669 const int numElements = 100;
1670 vector<float> inputFloats (numElements, 0);
1671 vector<float> outputFloats1 (numElements, 0);
1672 vector<float> outputFloats2 (numElements, 0);
1673 vector<float> outputFloats3 (numElements, 0);
1675 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats[0], numElements);
1677 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
1678 floorAll(inputFloats);
1680 for (size_t ndx = 0; ndx < numElements; ++ndx)
1684 case 0: outputFloats1[ndx] = inputFloats[ndx] + 5.5f; break;
1685 case 1: outputFloats1[ndx] = inputFloats[ndx] + 20.5f; break;
1686 case 2: outputFloats1[ndx] = inputFloats[ndx] + 1.75f; break;
1689 outputFloats2[ndx] = inputFloats[ndx] + 6.5f * 3;
1690 outputFloats3[ndx] = 8.5f - inputFloats[ndx];
1694 string(s_ShaderPreamble) +
1696 "OpSource GLSL 430\n"
1697 "OpName %main \"main\"\n"
1698 "OpName %id \"gl_GlobalInvocationID\"\n"
1700 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1702 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) + string(s_InputOutputBuffer) +
1704 "%id = OpVariable %uvec3ptr Input\n"
1705 "%zero = OpConstant %i32 0\n"
1706 "%three = OpConstant %u32 3\n"
1707 "%constf5p5 = OpConstant %f32 5.5\n"
1708 "%constf20p5 = OpConstant %f32 20.5\n"
1709 "%constf1p75 = OpConstant %f32 1.75\n"
1710 "%constf8p5 = OpConstant %f32 8.5\n"
1711 "%constf6p5 = OpConstant %f32 6.5\n"
1713 "%main = OpFunction %void None %voidf\n"
1714 "%entry = OpLabel\n"
1715 "%idval = OpLoad %uvec3 %id\n"
1716 "%x = OpCompositeExtract %u32 %idval 0\n"
1717 "%selector = OpUMod %u32 %x %three\n"
1718 " OpSelectionMerge %phi None\n"
1719 " OpSwitch %selector %default 0 %case0 1 %case1 2 %case2\n"
1721 // Case 1 before OpPhi.
1722 "%case1 = OpLabel\n"
1725 "%default = OpLabel\n"
1729 "%operand = OpPhi %f32 %constf1p75 %case2 %constf20p5 %case1 %constf5p5 %case0\n" // not in the order of blocks
1730 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
1731 "%inval = OpLoad %f32 %inloc\n"
1732 "%add = OpFAdd %f32 %inval %operand\n"
1733 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
1734 " OpStore %outloc %add\n"
1737 // Case 0 after OpPhi.
1738 "%case0 = OpLabel\n"
1742 // Case 2 after OpPhi.
1743 "%case2 = OpLabel\n"
1747 spec1.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
1748 spec1.outputs.push_back(BufferSp(new Float32Buffer(outputFloats1)));
1749 spec1.numWorkGroups = IVec3(numElements, 1, 1);
1751 group->addChild(new SpvAsmComputeShaderCase(testCtx, "block", "out-of-order and unreachable blocks for OpPhi", spec1));
1754 string(s_ShaderPreamble) +
1756 "OpName %main \"main\"\n"
1757 "OpName %id \"gl_GlobalInvocationID\"\n"
1759 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1761 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) + string(s_InputOutputBuffer) +
1763 "%id = OpVariable %uvec3ptr Input\n"
1764 "%zero = OpConstant %i32 0\n"
1765 "%one = OpConstant %i32 1\n"
1766 "%three = OpConstant %i32 3\n"
1767 "%constf6p5 = OpConstant %f32 6.5\n"
1769 "%main = OpFunction %void None %voidf\n"
1770 "%entry = OpLabel\n"
1771 "%idval = OpLoad %uvec3 %id\n"
1772 "%x = OpCompositeExtract %u32 %idval 0\n"
1773 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
1774 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
1775 "%inval = OpLoad %f32 %inloc\n"
1779 "%step = OpPhi %i32 %zero %entry %step_next %phi\n"
1780 "%accum = OpPhi %f32 %inval %entry %accum_next %phi\n"
1781 "%step_next = OpIAdd %i32 %step %one\n"
1782 "%accum_next = OpFAdd %f32 %accum %constf6p5\n"
1783 "%still_loop = OpSLessThan %bool %step %three\n"
1784 " OpLoopMerge %exit %phi None\n"
1785 " OpBranchConditional %still_loop %phi %exit\n"
1788 " OpStore %outloc %accum\n"
1791 spec2.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
1792 spec2.outputs.push_back(BufferSp(new Float32Buffer(outputFloats2)));
1793 spec2.numWorkGroups = IVec3(numElements, 1, 1);
1795 group->addChild(new SpvAsmComputeShaderCase(testCtx, "induction", "The usual way induction variables are handled in LLVM IR", spec2));
1798 string(s_ShaderPreamble) +
1800 "OpName %main \"main\"\n"
1801 "OpName %id \"gl_GlobalInvocationID\"\n"
1803 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1805 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) + string(s_InputOutputBuffer) +
1807 "%f32ptr_f = OpTypePointer Function %f32\n"
1808 "%id = OpVariable %uvec3ptr Input\n"
1809 "%true = OpConstantTrue %bool\n"
1810 "%false = OpConstantFalse %bool\n"
1811 "%zero = OpConstant %i32 0\n"
1812 "%constf8p5 = OpConstant %f32 8.5\n"
1814 "%main = OpFunction %void None %voidf\n"
1815 "%entry = OpLabel\n"
1816 "%b = OpVariable %f32ptr_f Function %constf8p5\n"
1817 "%idval = OpLoad %uvec3 %id\n"
1818 "%x = OpCompositeExtract %u32 %idval 0\n"
1819 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
1820 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
1821 "%a_init = OpLoad %f32 %inloc\n"
1822 "%b_init = OpLoad %f32 %b\n"
1826 "%still_loop = OpPhi %bool %true %entry %false %phi\n"
1827 "%a_next = OpPhi %f32 %a_init %entry %b_next %phi\n"
1828 "%b_next = OpPhi %f32 %b_init %entry %a_next %phi\n"
1829 " OpLoopMerge %exit %phi None\n"
1830 " OpBranchConditional %still_loop %phi %exit\n"
1833 "%sub = OpFSub %f32 %a_next %b_next\n"
1834 " OpStore %outloc %sub\n"
1837 spec3.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
1838 spec3.outputs.push_back(BufferSp(new Float32Buffer(outputFloats3)));
1839 spec3.numWorkGroups = IVec3(numElements, 1, 1);
1841 group->addChild(new SpvAsmComputeShaderCase(testCtx, "swap", "Swap the values of two variables using OpPhi", spec3));
1843 return group.release();
1846 // Assembly code used for testing block order is based on GLSL source code:
1850 // layout(std140, set = 0, binding = 0) readonly buffer Input {
1851 // float elements[];
1853 // layout(std140, set = 0, binding = 1) writeonly buffer Output {
1854 // float elements[];
1858 // uint x = gl_GlobalInvocationID.x;
1859 // output_data.elements[x] = input_data.elements[x];
1860 // if (x > uint(50)) {
1861 // switch (x % uint(3)) {
1862 // case 0: output_data.elements[x] += 1.5f; break;
1863 // case 1: output_data.elements[x] += 42.f; break;
1864 // case 2: output_data.elements[x] -= 27.f; break;
1868 // output_data.elements[x] = -input_data.elements[x];
1871 tcu::TestCaseGroup* createBlockOrderGroup (tcu::TestContext& testCtx)
1873 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "block_order", "Test block orders"));
1874 ComputeShaderSpec spec;
1875 de::Random rnd (deStringHash(group->getName()));
1876 const int numElements = 100;
1877 vector<float> inputFloats (numElements, 0);
1878 vector<float> outputFloats (numElements, 0);
1880 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats[0], numElements);
1882 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
1883 floorAll(inputFloats);
1885 for (size_t ndx = 0; ndx <= 50; ++ndx)
1886 outputFloats[ndx] = -inputFloats[ndx];
1888 for (size_t ndx = 51; ndx < numElements; ++ndx)
1892 case 0: outputFloats[ndx] = inputFloats[ndx] + 1.5f; break;
1893 case 1: outputFloats[ndx] = inputFloats[ndx] + 42.f; break;
1894 case 2: outputFloats[ndx] = inputFloats[ndx] - 27.f; break;
1900 string(s_ShaderPreamble) +
1902 "OpSource GLSL 430\n"
1903 "OpName %main \"main\"\n"
1904 "OpName %id \"gl_GlobalInvocationID\"\n"
1906 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1908 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) +
1910 "%u32ptr = OpTypePointer Function %u32\n"
1911 "%u32ptr_input = OpTypePointer Input %u32\n"
1913 + string(s_InputOutputBuffer) +
1915 "%id = OpVariable %uvec3ptr Input\n"
1916 "%zero = OpConstant %i32 0\n"
1917 "%const3 = OpConstant %u32 3\n"
1918 "%const50 = OpConstant %u32 50\n"
1919 "%constf1p5 = OpConstant %f32 1.5\n"
1920 "%constf27 = OpConstant %f32 27.0\n"
1921 "%constf42 = OpConstant %f32 42.0\n"
1923 "%main = OpFunction %void None %voidf\n"
1926 "%entry = OpLabel\n"
1928 // Create a temporary variable to hold the value of gl_GlobalInvocationID.x.
1929 "%xvar = OpVariable %u32ptr Function\n"
1930 "%xptr = OpAccessChain %u32ptr_input %id %zero\n"
1931 "%x = OpLoad %u32 %xptr\n"
1932 " OpStore %xvar %x\n"
1934 "%cmp = OpUGreaterThan %bool %x %const50\n"
1935 " OpSelectionMerge %if_merge None\n"
1936 " OpBranchConditional %cmp %if_true %if_false\n"
1938 // Merge block for switch-statement: placed at the beginning.
1939 "%switch_merge = OpLabel\n"
1940 " OpBranch %if_merge\n"
1942 // Case 1 for switch-statement.
1943 "%case1 = OpLabel\n"
1944 "%x_1 = OpLoad %u32 %xvar\n"
1945 "%inloc_1 = OpAccessChain %f32ptr %indata %zero %x_1\n"
1946 "%inval_1 = OpLoad %f32 %inloc_1\n"
1947 "%addf42 = OpFAdd %f32 %inval_1 %constf42\n"
1948 "%outloc_1 = OpAccessChain %f32ptr %outdata %zero %x_1\n"
1949 " OpStore %outloc_1 %addf42\n"
1950 " OpBranch %switch_merge\n"
1952 // False branch for if-statement: placed in the middle of switch cases and before true branch.
1953 "%if_false = OpLabel\n"
1954 "%x_f = OpLoad %u32 %xvar\n"
1955 "%inloc_f = OpAccessChain %f32ptr %indata %zero %x_f\n"
1956 "%inval_f = OpLoad %f32 %inloc_f\n"
1957 "%negate = OpFNegate %f32 %inval_f\n"
1958 "%outloc_f = OpAccessChain %f32ptr %outdata %zero %x_f\n"
1959 " OpStore %outloc_f %negate\n"
1960 " OpBranch %if_merge\n"
1962 // Merge block for if-statement: placed in the middle of true and false branch.
1963 "%if_merge = OpLabel\n"
1966 // True branch for if-statement: placed in the middle of swtich cases and after the false branch.
1967 "%if_true = OpLabel\n"
1968 "%xval_t = OpLoad %u32 %xvar\n"
1969 "%mod = OpUMod %u32 %xval_t %const3\n"
1970 " OpSelectionMerge %switch_merge None\n"
1971 " OpSwitch %mod %default 0 %case0 1 %case1 2 %case2\n"
1973 // Case 2 for switch-statement.
1974 "%case2 = OpLabel\n"
1975 "%x_2 = OpLoad %u32 %xvar\n"
1976 "%inloc_2 = OpAccessChain %f32ptr %indata %zero %x_2\n"
1977 "%inval_2 = OpLoad %f32 %inloc_2\n"
1978 "%subf27 = OpFSub %f32 %inval_2 %constf27\n"
1979 "%outloc_2 = OpAccessChain %f32ptr %outdata %zero %x_2\n"
1980 " OpStore %outloc_2 %subf27\n"
1981 " OpBranch %switch_merge\n"
1983 // Default case for switch-statement: placed in the middle of normal cases.
1984 "%default = OpLabel\n"
1985 " OpBranch %switch_merge\n"
1987 // Case 0 for switch-statement: out of order.
1988 "%case0 = OpLabel\n"
1989 "%x_0 = OpLoad %u32 %xvar\n"
1990 "%inloc_0 = OpAccessChain %f32ptr %indata %zero %x_0\n"
1991 "%inval_0 = OpLoad %f32 %inloc_0\n"
1992 "%addf1p5 = OpFAdd %f32 %inval_0 %constf1p5\n"
1993 "%outloc_0 = OpAccessChain %f32ptr %outdata %zero %x_0\n"
1994 " OpStore %outloc_0 %addf1p5\n"
1995 " OpBranch %switch_merge\n"
1998 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
1999 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
2000 spec.numWorkGroups = IVec3(numElements, 1, 1);
2002 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "various out-of-order blocks", spec));
2004 return group.release();
2007 tcu::TestCaseGroup* createMultipleShaderGroup (tcu::TestContext& testCtx)
2009 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "multiple_shaders", "Test multiple shaders in the same module"));
2010 ComputeShaderSpec spec1;
2011 ComputeShaderSpec spec2;
2012 de::Random rnd (deStringHash(group->getName()));
2013 const int numElements = 100;
2014 vector<float> inputFloats (numElements, 0);
2015 vector<float> outputFloats1 (numElements, 0);
2016 vector<float> outputFloats2 (numElements, 0);
2017 fillRandomScalars(rnd, -500.f, 500.f, &inputFloats[0], numElements);
2019 for (size_t ndx = 0; ndx < numElements; ++ndx)
2021 outputFloats1[ndx] = inputFloats[ndx] + inputFloats[ndx];
2022 outputFloats2[ndx] = -inputFloats[ndx];
2025 const string assembly(
2026 "OpCapability Shader\n"
2027 "OpCapability ClipDistance\n"
2028 "OpMemoryModel Logical GLSL450\n"
2029 "OpEntryPoint GLCompute %comp_main1 \"entrypoint1\" %id\n"
2030 "OpEntryPoint GLCompute %comp_main2 \"entrypoint2\" %id\n"
2031 // A module cannot have two OpEntryPoint instructions with the same Execution Model and the same Name string.
2032 "OpEntryPoint Vertex %vert_main \"entrypoint2\" %vert_builtins %vertexIndex %instanceIndex\n"
2033 "OpExecutionMode %comp_main1 LocalSize 1 1 1\n"
2034 "OpExecutionMode %comp_main2 LocalSize 1 1 1\n"
2036 "OpName %comp_main1 \"entrypoint1\"\n"
2037 "OpName %comp_main2 \"entrypoint2\"\n"
2038 "OpName %vert_main \"entrypoint2\"\n"
2039 "OpName %id \"gl_GlobalInvocationID\"\n"
2040 "OpName %vert_builtin_st \"gl_PerVertex\"\n"
2041 "OpName %vertexIndex \"gl_VertexIndex\"\n"
2042 "OpName %instanceIndex \"gl_InstanceIndex\"\n"
2043 "OpMemberName %vert_builtin_st 0 \"gl_Position\"\n"
2044 "OpMemberName %vert_builtin_st 1 \"gl_PointSize\"\n"
2045 "OpMemberName %vert_builtin_st 2 \"gl_ClipDistance\"\n"
2047 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2048 "OpDecorate %vertexIndex BuiltIn VertexIndex\n"
2049 "OpDecorate %instanceIndex BuiltIn InstanceIndex\n"
2050 "OpDecorate %vert_builtin_st Block\n"
2051 "OpMemberDecorate %vert_builtin_st 0 BuiltIn Position\n"
2052 "OpMemberDecorate %vert_builtin_st 1 BuiltIn PointSize\n"
2053 "OpMemberDecorate %vert_builtin_st 2 BuiltIn ClipDistance\n"
2055 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) + string(s_InputOutputBuffer) +
2057 "%zero = OpConstant %i32 0\n"
2058 "%one = OpConstant %u32 1\n"
2059 "%c_f32_1 = OpConstant %f32 1\n"
2061 "%i32inputptr = OpTypePointer Input %i32\n"
2062 "%vec4 = OpTypeVector %f32 4\n"
2063 "%vec4ptr = OpTypePointer Output %vec4\n"
2064 "%f32arr1 = OpTypeArray %f32 %one\n"
2065 "%vert_builtin_st = OpTypeStruct %vec4 %f32 %f32arr1\n"
2066 "%vert_builtin_st_ptr = OpTypePointer Output %vert_builtin_st\n"
2067 "%vert_builtins = OpVariable %vert_builtin_st_ptr Output\n"
2069 "%id = OpVariable %uvec3ptr Input\n"
2070 "%vertexIndex = OpVariable %i32inputptr Input\n"
2071 "%instanceIndex = OpVariable %i32inputptr Input\n"
2072 "%c_vec4_1 = OpConstantComposite %vec4 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_1\n"
2074 // gl_Position = vec4(1.);
2075 "%vert_main = OpFunction %void None %voidf\n"
2076 "%vert_entry = OpLabel\n"
2077 "%position = OpAccessChain %vec4ptr %vert_builtins %zero\n"
2078 " OpStore %position %c_vec4_1\n"
2083 "%comp_main1 = OpFunction %void None %voidf\n"
2084 "%comp1_entry = OpLabel\n"
2085 "%idval1 = OpLoad %uvec3 %id\n"
2086 "%x1 = OpCompositeExtract %u32 %idval1 0\n"
2087 "%inloc1 = OpAccessChain %f32ptr %indata %zero %x1\n"
2088 "%inval1 = OpLoad %f32 %inloc1\n"
2089 "%add = OpFAdd %f32 %inval1 %inval1\n"
2090 "%outloc1 = OpAccessChain %f32ptr %outdata %zero %x1\n"
2091 " OpStore %outloc1 %add\n"
2096 "%comp_main2 = OpFunction %void None %voidf\n"
2097 "%comp2_entry = OpLabel\n"
2098 "%idval2 = OpLoad %uvec3 %id\n"
2099 "%x2 = OpCompositeExtract %u32 %idval2 0\n"
2100 "%inloc2 = OpAccessChain %f32ptr %indata %zero %x2\n"
2101 "%inval2 = OpLoad %f32 %inloc2\n"
2102 "%neg = OpFNegate %f32 %inval2\n"
2103 "%outloc2 = OpAccessChain %f32ptr %outdata %zero %x2\n"
2104 " OpStore %outloc2 %neg\n"
2106 " OpFunctionEnd\n");
2108 spec1.assembly = assembly;
2109 spec1.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
2110 spec1.outputs.push_back(BufferSp(new Float32Buffer(outputFloats1)));
2111 spec1.numWorkGroups = IVec3(numElements, 1, 1);
2112 spec1.entryPoint = "entrypoint1";
2114 spec2.assembly = assembly;
2115 spec2.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
2116 spec2.outputs.push_back(BufferSp(new Float32Buffer(outputFloats2)));
2117 spec2.numWorkGroups = IVec3(numElements, 1, 1);
2118 spec2.entryPoint = "entrypoint2";
2120 group->addChild(new SpvAsmComputeShaderCase(testCtx, "shader1", "multiple shaders in the same module", spec1));
2121 group->addChild(new SpvAsmComputeShaderCase(testCtx, "shader2", "multiple shaders in the same module", spec2));
2123 return group.release();
2126 inline std::string makeLongUTF8String (size_t num4ByteChars)
2128 // An example of a longest valid UTF-8 character. Be explicit about the
2129 // character type because Microsoft compilers can otherwise interpret the
2130 // character string as being over wide (16-bit) characters. Ideally, we
2131 // would just use a C++11 UTF-8 string literal, but we want to support older
2132 // Microsoft compilers.
2133 const std::basic_string<char> earthAfrica("\xF0\x9F\x8C\x8D");
2134 std::string longString;
2135 longString.reserve(num4ByteChars * 4);
2136 for (size_t count = 0; count < num4ByteChars; count++)
2138 longString += earthAfrica;
2143 tcu::TestCaseGroup* createOpSourceGroup (tcu::TestContext& testCtx)
2145 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opsource", "Tests the OpSource & OpSourceContinued instruction"));
2146 vector<CaseParameter> cases;
2147 de::Random rnd (deStringHash(group->getName()));
2148 const int numElements = 100;
2149 vector<float> positiveFloats (numElements, 0);
2150 vector<float> negativeFloats (numElements, 0);
2151 const StringTemplate shaderTemplate (
2152 "OpCapability Shader\n"
2153 "OpMemoryModel Logical GLSL450\n"
2155 "OpEntryPoint GLCompute %main \"main\" %id\n"
2156 "OpExecutionMode %main LocalSize 1 1 1\n"
2160 "OpName %main \"main\"\n"
2161 "OpName %id \"gl_GlobalInvocationID\"\n"
2163 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2165 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) + string(s_InputOutputBuffer) +
2167 "%id = OpVariable %uvec3ptr Input\n"
2168 "%zero = OpConstant %i32 0\n"
2170 "%main = OpFunction %void None %voidf\n"
2171 "%label = OpLabel\n"
2172 "%idval = OpLoad %uvec3 %id\n"
2173 "%x = OpCompositeExtract %u32 %idval 0\n"
2174 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
2175 "%inval = OpLoad %f32 %inloc\n"
2176 "%neg = OpFNegate %f32 %inval\n"
2177 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2178 " OpStore %outloc %neg\n"
2180 " OpFunctionEnd\n");
2182 cases.push_back(CaseParameter("unknown_source", "OpSource Unknown 0"));
2183 cases.push_back(CaseParameter("wrong_source", "OpSource OpenCL_C 210"));
2184 cases.push_back(CaseParameter("normal_filename", "%fname = OpString \"filename\"\n"
2185 "OpSource GLSL 430 %fname"));
2186 cases.push_back(CaseParameter("empty_filename", "%fname = OpString \"\"\n"
2187 "OpSource GLSL 430 %fname"));
2188 cases.push_back(CaseParameter("normal_source_code", "%fname = OpString \"filename\"\n"
2189 "OpSource GLSL 430 %fname \"#version 430\nvoid main() {}\""));
2190 cases.push_back(CaseParameter("empty_source_code", "%fname = OpString \"filename\"\n"
2191 "OpSource GLSL 430 %fname \"\""));
2192 cases.push_back(CaseParameter("long_source_code", "%fname = OpString \"filename\"\n"
2193 "OpSource GLSL 430 %fname \"" + makeLongUTF8String(65530) + "ccc\"")); // word count: 65535
2194 cases.push_back(CaseParameter("utf8_source_code", "%fname = OpString \"filename\"\n"
2195 "OpSource GLSL 430 %fname \"\xE2\x98\x82\xE2\x98\x85\"")); // umbrella & black star symbol
2196 cases.push_back(CaseParameter("normal_sourcecontinued", "%fname = OpString \"filename\"\n"
2197 "OpSource GLSL 430 %fname \"#version 430\nvo\"\n"
2198 "OpSourceContinued \"id main() {}\""));
2199 cases.push_back(CaseParameter("empty_sourcecontinued", "%fname = OpString \"filename\"\n"
2200 "OpSource GLSL 430 %fname \"#version 430\nvoid main() {}\"\n"
2201 "OpSourceContinued \"\""));
2202 cases.push_back(CaseParameter("long_sourcecontinued", "%fname = OpString \"filename\"\n"
2203 "OpSource GLSL 430 %fname \"#version 430\nvoid main() {}\"\n"
2204 "OpSourceContinued \"" + makeLongUTF8String(65533) + "ccc\"")); // word count: 65535
2205 cases.push_back(CaseParameter("utf8_sourcecontinued", "%fname = OpString \"filename\"\n"
2206 "OpSource GLSL 430 %fname \"#version 430\nvoid main() {}\"\n"
2207 "OpSourceContinued \"\xE2\x98\x8E\xE2\x9A\x91\"")); // white telephone & black flag symbol
2208 cases.push_back(CaseParameter("multi_sourcecontinued", "%fname = OpString \"filename\"\n"
2209 "OpSource GLSL 430 %fname \"#version 430\n\"\n"
2210 "OpSourceContinued \"void\"\n"
2211 "OpSourceContinued \"main()\"\n"
2212 "OpSourceContinued \"{}\""));
2213 cases.push_back(CaseParameter("empty_source_before_sourcecontinued", "%fname = OpString \"filename\"\n"
2214 "OpSource GLSL 430 %fname \"\"\n"
2215 "OpSourceContinued \"#version 430\nvoid main() {}\""));
2217 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
2219 for (size_t ndx = 0; ndx < numElements; ++ndx)
2220 negativeFloats[ndx] = -positiveFloats[ndx];
2222 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
2224 map<string, string> specializations;
2225 ComputeShaderSpec spec;
2227 specializations["SOURCE"] = cases[caseNdx].param;
2228 spec.assembly = shaderTemplate.specialize(specializations);
2229 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
2230 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
2231 spec.numWorkGroups = IVec3(numElements, 1, 1);
2233 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
2236 return group.release();
2239 tcu::TestCaseGroup* createOpSourceExtensionGroup (tcu::TestContext& testCtx)
2241 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opsourceextension", "Tests the OpSource instruction"));
2242 vector<CaseParameter> cases;
2243 de::Random rnd (deStringHash(group->getName()));
2244 const int numElements = 100;
2245 vector<float> inputFloats (numElements, 0);
2246 vector<float> outputFloats (numElements, 0);
2247 const StringTemplate shaderTemplate (
2248 string(s_ShaderPreamble) +
2250 "OpSourceExtension \"${EXTENSION}\"\n"
2252 "OpName %main \"main\"\n"
2253 "OpName %id \"gl_GlobalInvocationID\"\n"
2255 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2257 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) + string(s_InputOutputBuffer) +
2259 "%id = OpVariable %uvec3ptr Input\n"
2260 "%zero = OpConstant %i32 0\n"
2262 "%main = OpFunction %void None %voidf\n"
2263 "%label = OpLabel\n"
2264 "%idval = OpLoad %uvec3 %id\n"
2265 "%x = OpCompositeExtract %u32 %idval 0\n"
2266 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
2267 "%inval = OpLoad %f32 %inloc\n"
2268 "%neg = OpFNegate %f32 %inval\n"
2269 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2270 " OpStore %outloc %neg\n"
2272 " OpFunctionEnd\n");
2274 cases.push_back(CaseParameter("empty_extension", ""));
2275 cases.push_back(CaseParameter("real_extension", "GL_ARB_texture_rectangle"));
2276 cases.push_back(CaseParameter("fake_extension", "GL_ARB_im_the_ultimate_extension"));
2277 cases.push_back(CaseParameter("utf8_extension", "GL_ARB_\xE2\x98\x82\xE2\x98\x85"));
2278 cases.push_back(CaseParameter("long_extension", makeLongUTF8String(65533) + "ccc")); // word count: 65535
2280 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats[0], numElements);
2282 for (size_t ndx = 0; ndx < numElements; ++ndx)
2283 outputFloats[ndx] = -inputFloats[ndx];
2285 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
2287 map<string, string> specializations;
2288 ComputeShaderSpec spec;
2290 specializations["EXTENSION"] = cases[caseNdx].param;
2291 spec.assembly = shaderTemplate.specialize(specializations);
2292 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
2293 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
2294 spec.numWorkGroups = IVec3(numElements, 1, 1);
2296 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
2299 return group.release();
2302 // Checks that a compute shader can generate a constant null value of various types, without exercising a computation on it.
2303 tcu::TestCaseGroup* createOpConstantNullGroup (tcu::TestContext& testCtx)
2305 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opconstantnull", "Tests the OpConstantNull instruction"));
2306 vector<CaseParameter> cases;
2307 de::Random rnd (deStringHash(group->getName()));
2308 const int numElements = 100;
2309 vector<float> positiveFloats (numElements, 0);
2310 vector<float> negativeFloats (numElements, 0);
2311 const StringTemplate shaderTemplate (
2312 string(s_ShaderPreamble) +
2314 "OpSource GLSL 430\n"
2315 "OpName %main \"main\"\n"
2316 "OpName %id \"gl_GlobalInvocationID\"\n"
2318 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2320 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) + string(s_InputOutputBuffer) +
2323 "%null = OpConstantNull %type\n"
2325 "%id = OpVariable %uvec3ptr Input\n"
2326 "%zero = OpConstant %i32 0\n"
2328 "%main = OpFunction %void None %voidf\n"
2329 "%label = OpLabel\n"
2330 "%idval = OpLoad %uvec3 %id\n"
2331 "%x = OpCompositeExtract %u32 %idval 0\n"
2332 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
2333 "%inval = OpLoad %f32 %inloc\n"
2334 "%neg = OpFNegate %f32 %inval\n"
2335 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2336 " OpStore %outloc %neg\n"
2338 " OpFunctionEnd\n");
2340 cases.push_back(CaseParameter("bool", "%type = OpTypeBool"));
2341 cases.push_back(CaseParameter("sint32", "%type = OpTypeInt 32 1"));
2342 cases.push_back(CaseParameter("uint32", "%type = OpTypeInt 32 0"));
2343 cases.push_back(CaseParameter("float32", "%type = OpTypeFloat 32"));
2344 cases.push_back(CaseParameter("vec4float32", "%type = OpTypeVector %f32 4"));
2345 cases.push_back(CaseParameter("vec3bool", "%type = OpTypeVector %bool 3"));
2346 cases.push_back(CaseParameter("vec2uint32", "%type = OpTypeVector %u32 2"));
2347 cases.push_back(CaseParameter("matrix", "%type = OpTypeMatrix %fvec3 3"));
2348 cases.push_back(CaseParameter("array", "%100 = OpConstant %u32 100\n"
2349 "%type = OpTypeArray %i32 %100"));
2350 cases.push_back(CaseParameter("struct", "%type = OpTypeStruct %f32 %i32 %u32"));
2351 cases.push_back(CaseParameter("pointer", "%type = OpTypePointer Function %i32"));
2353 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
2355 for (size_t ndx = 0; ndx < numElements; ++ndx)
2356 negativeFloats[ndx] = -positiveFloats[ndx];
2358 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
2360 map<string, string> specializations;
2361 ComputeShaderSpec spec;
2363 specializations["TYPE"] = cases[caseNdx].param;
2364 spec.assembly = shaderTemplate.specialize(specializations);
2365 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
2366 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
2367 spec.numWorkGroups = IVec3(numElements, 1, 1);
2369 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
2372 return group.release();
2375 // Checks that a compute shader can generate a constant composite value of various types, without exercising a computation on it.
2376 tcu::TestCaseGroup* createOpConstantCompositeGroup (tcu::TestContext& testCtx)
2378 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opconstantcomposite", "Tests the OpConstantComposite instruction"));
2379 vector<CaseParameter> cases;
2380 de::Random rnd (deStringHash(group->getName()));
2381 const int numElements = 100;
2382 vector<float> positiveFloats (numElements, 0);
2383 vector<float> negativeFloats (numElements, 0);
2384 const StringTemplate shaderTemplate (
2385 string(s_ShaderPreamble) +
2387 "OpSource GLSL 430\n"
2388 "OpName %main \"main\"\n"
2389 "OpName %id \"gl_GlobalInvocationID\"\n"
2391 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2393 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) + string(s_InputOutputBuffer) +
2395 "%id = OpVariable %uvec3ptr Input\n"
2396 "%zero = OpConstant %i32 0\n"
2400 "%main = OpFunction %void None %voidf\n"
2401 "%label = OpLabel\n"
2402 "%idval = OpLoad %uvec3 %id\n"
2403 "%x = OpCompositeExtract %u32 %idval 0\n"
2404 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
2405 "%inval = OpLoad %f32 %inloc\n"
2406 "%neg = OpFNegate %f32 %inval\n"
2407 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2408 " OpStore %outloc %neg\n"
2410 " OpFunctionEnd\n");
2412 cases.push_back(CaseParameter("vector", "%five = OpConstant %u32 5\n"
2413 "%const = OpConstantComposite %uvec3 %five %zero %five"));
2414 cases.push_back(CaseParameter("matrix", "%m3fvec3 = OpTypeMatrix %fvec3 3\n"
2415 "%ten = OpConstant %f32 10.\n"
2416 "%fzero = OpConstant %f32 0.\n"
2417 "%vec = OpConstantComposite %fvec3 %ten %fzero %ten\n"
2418 "%mat = OpConstantComposite %m3fvec3 %vec %vec %vec"));
2419 cases.push_back(CaseParameter("struct", "%m2vec3 = OpTypeMatrix %fvec3 2\n"
2420 "%struct = OpTypeStruct %i32 %f32 %fvec3 %m2vec3\n"
2421 "%fzero = OpConstant %f32 0.\n"
2422 "%one = OpConstant %f32 1.\n"
2423 "%point5 = OpConstant %f32 0.5\n"
2424 "%vec = OpConstantComposite %fvec3 %one %one %fzero\n"
2425 "%mat = OpConstantComposite %m2vec3 %vec %vec\n"
2426 "%const = OpConstantComposite %struct %zero %point5 %vec %mat"));
2427 cases.push_back(CaseParameter("nested_struct", "%st1 = OpTypeStruct %u32 %f32\n"
2428 "%st2 = OpTypeStruct %i32 %i32\n"
2429 "%struct = OpTypeStruct %st1 %st2\n"
2430 "%point5 = OpConstant %f32 0.5\n"
2431 "%one = OpConstant %u32 1\n"
2432 "%ten = OpConstant %i32 10\n"
2433 "%st1val = OpConstantComposite %st1 %one %point5\n"
2434 "%st2val = OpConstantComposite %st2 %ten %ten\n"
2435 "%const = OpConstantComposite %struct %st1val %st2val"));
2437 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
2439 for (size_t ndx = 0; ndx < numElements; ++ndx)
2440 negativeFloats[ndx] = -positiveFloats[ndx];
2442 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
2444 map<string, string> specializations;
2445 ComputeShaderSpec spec;
2447 specializations["CONSTANT"] = cases[caseNdx].param;
2448 spec.assembly = shaderTemplate.specialize(specializations);
2449 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
2450 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
2451 spec.numWorkGroups = IVec3(numElements, 1, 1);
2453 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
2456 return group.release();
2459 // Creates a floating point number with the given exponent, and significand
2460 // bits set. It can only create normalized numbers. Only the least significant
2461 // 24 bits of the significand will be examined. The final bit of the
2462 // significand will also be ignored. This allows alignment to be written
2463 // similarly to C99 hex-floats.
2464 // For example if you wanted to write 0x1.7f34p-12 you would call
2465 // constructNormalizedFloat(-12, 0x7f3400)
2466 float constructNormalizedFloat (deInt32 exponent, deUint32 significand)
2470 for (deInt32 idx = 0; idx < 23; ++idx)
2472 f += ((significand & 0x800000) == 0) ? 0.f : std::ldexp(1.0f, -(idx + 1));
2476 return std::ldexp(f, exponent);
2479 // Compare instruction for the OpQuantizeF16 compute exact case.
2480 // Returns true if the output is what is expected from the test case.
2481 bool compareOpQuantizeF16ComputeExactCase (const std::vector<BufferSp>&, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs, TestLog&)
2483 if (outputAllocs.size() != 1)
2486 // We really just need this for size because we cannot compare Nans.
2487 const BufferSp& expectedOutput = expectedOutputs[0];
2488 const float* outputAsFloat = static_cast<const float*>(outputAllocs[0]->getHostPtr());;
2490 if (expectedOutput->getNumBytes() != 4*sizeof(float)) {
2494 if (*outputAsFloat != constructNormalizedFloat(8, 0x304000) &&
2495 *outputAsFloat != constructNormalizedFloat(8, 0x300000)) {
2500 if (*outputAsFloat != -constructNormalizedFloat(-7, 0x600000) &&
2501 *outputAsFloat != -constructNormalizedFloat(-7, 0x604000)) {
2506 if (*outputAsFloat != constructNormalizedFloat(2, 0x01C000) &&
2507 *outputAsFloat != constructNormalizedFloat(2, 0x020000)) {
2512 if (*outputAsFloat != constructNormalizedFloat(1, 0xFFC000) &&
2513 *outputAsFloat != constructNormalizedFloat(2, 0x000000)) {
2520 // Checks that every output from a test-case is a float NaN.
2521 bool compareNan (const std::vector<BufferSp>&, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs, TestLog&)
2523 if (outputAllocs.size() != 1)
2526 // We really just need this for size because we cannot compare Nans.
2527 const BufferSp& expectedOutput = expectedOutputs[0];
2528 const float* output_as_float = static_cast<const float*>(outputAllocs[0]->getHostPtr());;
2530 for (size_t idx = 0; idx < expectedOutput->getNumBytes() / sizeof(float); ++idx)
2532 if (!isnan(output_as_float[idx]))
2541 // Checks that a compute shader can generate a constant composite value of various types, without exercising a computation on it.
2542 tcu::TestCaseGroup* createOpQuantizeToF16Group (tcu::TestContext& testCtx)
2544 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opquantize", "Tests the OpQuantizeToF16 instruction"));
2546 const std::string shader (
2547 string(s_ShaderPreamble) +
2549 "OpSource GLSL 430\n"
2550 "OpName %main \"main\"\n"
2551 "OpName %id \"gl_GlobalInvocationID\"\n"
2553 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2555 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) + string(s_InputOutputBuffer) +
2557 "%id = OpVariable %uvec3ptr Input\n"
2558 "%zero = OpConstant %i32 0\n"
2560 "%main = OpFunction %void None %voidf\n"
2561 "%label = OpLabel\n"
2562 "%idval = OpLoad %uvec3 %id\n"
2563 "%x = OpCompositeExtract %u32 %idval 0\n"
2564 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
2565 "%inval = OpLoad %f32 %inloc\n"
2566 "%quant = OpQuantizeToF16 %f32 %inval\n"
2567 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2568 " OpStore %outloc %quant\n"
2570 " OpFunctionEnd\n");
2573 ComputeShaderSpec spec;
2574 const deUint32 numElements = 100;
2575 vector<float> infinities;
2576 vector<float> results;
2578 infinities.reserve(numElements);
2579 results.reserve(numElements);
2581 for (size_t idx = 0; idx < numElements; ++idx)
2586 infinities.push_back(std::numeric_limits<float>::infinity());
2587 results.push_back(std::numeric_limits<float>::infinity());
2590 infinities.push_back(-std::numeric_limits<float>::infinity());
2591 results.push_back(-std::numeric_limits<float>::infinity());
2594 infinities.push_back(std::ldexp(1.0f, 16));
2595 results.push_back(std::numeric_limits<float>::infinity());
2598 infinities.push_back(std::ldexp(-1.0f, 32));
2599 results.push_back(-std::numeric_limits<float>::infinity());
2604 spec.assembly = shader;
2605 spec.inputs.push_back(BufferSp(new Float32Buffer(infinities)));
2606 spec.outputs.push_back(BufferSp(new Float32Buffer(results)));
2607 spec.numWorkGroups = IVec3(numElements, 1, 1);
2609 group->addChild(new SpvAsmComputeShaderCase(
2610 testCtx, "infinities", "Check that infinities propagated and created", spec));
2614 ComputeShaderSpec spec;
2616 const deUint32 numElements = 100;
2618 nans.reserve(numElements);
2620 for (size_t idx = 0; idx < numElements; ++idx)
2624 nans.push_back(std::numeric_limits<float>::quiet_NaN());
2628 nans.push_back(-std::numeric_limits<float>::quiet_NaN());
2632 spec.assembly = shader;
2633 spec.inputs.push_back(BufferSp(new Float32Buffer(nans)));
2634 spec.outputs.push_back(BufferSp(new Float32Buffer(nans)));
2635 spec.numWorkGroups = IVec3(numElements, 1, 1);
2636 spec.verifyIO = &compareNan;
2638 group->addChild(new SpvAsmComputeShaderCase(
2639 testCtx, "propagated_nans", "Check that nans are propagated", spec));
2643 ComputeShaderSpec spec;
2644 vector<float> small;
2645 vector<float> zeros;
2646 const deUint32 numElements = 100;
2648 small.reserve(numElements);
2649 zeros.reserve(numElements);
2651 for (size_t idx = 0; idx < numElements; ++idx)
2656 small.push_back(0.f);
2657 zeros.push_back(0.f);
2660 small.push_back(-0.f);
2661 zeros.push_back(-0.f);
2664 small.push_back(std::ldexp(1.0f, -16));
2665 zeros.push_back(0.f);
2668 small.push_back(std::ldexp(-1.0f, -32));
2669 zeros.push_back(-0.f);
2672 small.push_back(std::ldexp(1.0f, -127));
2673 zeros.push_back(0.f);
2676 small.push_back(-std::ldexp(1.0f, -128));
2677 zeros.push_back(-0.f);
2682 spec.assembly = shader;
2683 spec.inputs.push_back(BufferSp(new Float32Buffer(small)));
2684 spec.outputs.push_back(BufferSp(new Float32Buffer(zeros)));
2685 spec.numWorkGroups = IVec3(numElements, 1, 1);
2687 group->addChild(new SpvAsmComputeShaderCase(
2688 testCtx, "flush_to_zero", "Check that values are zeroed correctly", spec));
2692 ComputeShaderSpec spec;
2693 vector<float> exact;
2694 const deUint32 numElements = 200;
2696 exact.reserve(numElements);
2698 for (size_t idx = 0; idx < numElements; ++idx)
2699 exact.push_back(static_cast<float>(static_cast<int>(idx) - 100));
2701 spec.assembly = shader;
2702 spec.inputs.push_back(BufferSp(new Float32Buffer(exact)));
2703 spec.outputs.push_back(BufferSp(new Float32Buffer(exact)));
2704 spec.numWorkGroups = IVec3(numElements, 1, 1);
2706 group->addChild(new SpvAsmComputeShaderCase(
2707 testCtx, "exact", "Check that values exactly preserved where appropriate", spec));
2711 ComputeShaderSpec spec;
2712 vector<float> inputs;
2713 const deUint32 numElements = 4;
2715 inputs.push_back(constructNormalizedFloat(8, 0x300300));
2716 inputs.push_back(-constructNormalizedFloat(-7, 0x600800));
2717 inputs.push_back(constructNormalizedFloat(2, 0x01E000));
2718 inputs.push_back(constructNormalizedFloat(1, 0xFFE000));
2720 spec.assembly = shader;
2721 spec.verifyIO = &compareOpQuantizeF16ComputeExactCase;
2722 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs)));
2723 spec.outputs.push_back(BufferSp(new Float32Buffer(inputs)));
2724 spec.numWorkGroups = IVec3(numElements, 1, 1);
2726 group->addChild(new SpvAsmComputeShaderCase(
2727 testCtx, "rounded", "Check that are rounded when needed", spec));
2730 return group.release();
2733 // Performs a bitwise copy of source to the destination type Dest.
2734 template <typename Dest, typename Src>
2735 Dest bitwiseCast(Src source)
2738 DE_STATIC_ASSERT(sizeof(source) == sizeof(dest));
2739 deMemcpy(&dest, &source, sizeof(dest));
2743 tcu::TestCaseGroup* createSpecConstantOpQuantizeToF16Group (tcu::TestContext& testCtx)
2745 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opspecconstantop_opquantize", "Tests the OpQuantizeToF16 opcode for the OpSpecConstantOp instruction"));
2747 const std::string shader (
2748 string(s_ShaderPreamble) +
2750 "OpName %main \"main\"\n"
2751 "OpName %id \"gl_GlobalInvocationID\"\n"
2753 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2755 "OpDecorate %sc_0 SpecId 0\n"
2756 "OpDecorate %sc_1 SpecId 1\n"
2757 "OpDecorate %sc_2 SpecId 2\n"
2758 "OpDecorate %sc_3 SpecId 3\n"
2759 "OpDecorate %sc_4 SpecId 4\n"
2760 "OpDecorate %sc_5 SpecId 5\n"
2762 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) + string(s_InputOutputBuffer) +
2764 "%id = OpVariable %uvec3ptr Input\n"
2765 "%zero = OpConstant %i32 0\n"
2766 "%c_u32_6 = OpConstant %u32 6\n"
2768 "%sc_0 = OpSpecConstant %f32 0.\n"
2769 "%sc_1 = OpSpecConstant %f32 0.\n"
2770 "%sc_2 = OpSpecConstant %f32 0.\n"
2771 "%sc_3 = OpSpecConstant %f32 0.\n"
2772 "%sc_4 = OpSpecConstant %f32 0.\n"
2773 "%sc_5 = OpSpecConstant %f32 0.\n"
2775 "%sc_0_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_0\n"
2776 "%sc_1_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_1\n"
2777 "%sc_2_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_2\n"
2778 "%sc_3_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_3\n"
2779 "%sc_4_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_4\n"
2780 "%sc_5_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_5\n"
2782 "%main = OpFunction %void None %voidf\n"
2783 "%label = OpLabel\n"
2784 "%idval = OpLoad %uvec3 %id\n"
2785 "%x = OpCompositeExtract %u32 %idval 0\n"
2786 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2787 "%selector = OpUMod %u32 %x %c_u32_6\n"
2788 " OpSelectionMerge %exit None\n"
2789 " OpSwitch %selector %exit 0 %case0 1 %case1 2 %case2 3 %case3 4 %case4 5 %case5\n"
2791 "%case0 = OpLabel\n"
2792 " OpStore %outloc %sc_0_quant\n"
2795 "%case1 = OpLabel\n"
2796 " OpStore %outloc %sc_1_quant\n"
2799 "%case2 = OpLabel\n"
2800 " OpStore %outloc %sc_2_quant\n"
2803 "%case3 = OpLabel\n"
2804 " OpStore %outloc %sc_3_quant\n"
2807 "%case4 = OpLabel\n"
2808 " OpStore %outloc %sc_4_quant\n"
2811 "%case5 = OpLabel\n"
2812 " OpStore %outloc %sc_5_quant\n"
2818 " OpFunctionEnd\n");
2821 ComputeShaderSpec spec;
2822 const deUint8 numCases = 4;
2823 vector<float> inputs (numCases, 0.f);
2824 vector<float> outputs;
2826 spec.assembly = shader;
2827 spec.numWorkGroups = IVec3(numCases, 1, 1);
2829 spec.specConstants.push_back(bitwiseCast<deUint32>(std::numeric_limits<float>::infinity()));
2830 spec.specConstants.push_back(bitwiseCast<deUint32>(-std::numeric_limits<float>::infinity()));
2831 spec.specConstants.push_back(bitwiseCast<deUint32>(std::ldexp(1.0f, 16)));
2832 spec.specConstants.push_back(bitwiseCast<deUint32>(std::ldexp(-1.0f, 32)));
2834 outputs.push_back(std::numeric_limits<float>::infinity());
2835 outputs.push_back(-std::numeric_limits<float>::infinity());
2836 outputs.push_back(std::numeric_limits<float>::infinity());
2837 outputs.push_back(-std::numeric_limits<float>::infinity());
2839 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs)));
2840 spec.outputs.push_back(BufferSp(new Float32Buffer(outputs)));
2842 group->addChild(new SpvAsmComputeShaderCase(
2843 testCtx, "infinities", "Check that infinities propagated and created", spec));
2847 ComputeShaderSpec spec;
2848 const deUint8 numCases = 2;
2849 vector<float> inputs (numCases, 0.f);
2850 vector<float> outputs;
2852 spec.assembly = shader;
2853 spec.numWorkGroups = IVec3(numCases, 1, 1);
2854 spec.verifyIO = &compareNan;
2856 outputs.push_back(std::numeric_limits<float>::quiet_NaN());
2857 outputs.push_back(-std::numeric_limits<float>::quiet_NaN());
2859 for (deUint8 idx = 0; idx < numCases; ++idx)
2860 spec.specConstants.push_back(bitwiseCast<deUint32>(outputs[idx]));
2862 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs)));
2863 spec.outputs.push_back(BufferSp(new Float32Buffer(outputs)));
2865 group->addChild(new SpvAsmComputeShaderCase(
2866 testCtx, "propagated_nans", "Check that nans are propagated", spec));
2870 ComputeShaderSpec spec;
2871 const deUint8 numCases = 6;
2872 vector<float> inputs (numCases, 0.f);
2873 vector<float> outputs;
2875 spec.assembly = shader;
2876 spec.numWorkGroups = IVec3(numCases, 1, 1);
2878 spec.specConstants.push_back(bitwiseCast<deUint32>(0.f));
2879 spec.specConstants.push_back(bitwiseCast<deUint32>(-0.f));
2880 spec.specConstants.push_back(bitwiseCast<deUint32>(std::ldexp(1.0f, -16)));
2881 spec.specConstants.push_back(bitwiseCast<deUint32>(std::ldexp(-1.0f, -32)));
2882 spec.specConstants.push_back(bitwiseCast<deUint32>(std::ldexp(1.0f, -127)));
2883 spec.specConstants.push_back(bitwiseCast<deUint32>(-std::ldexp(1.0f, -128)));
2885 outputs.push_back(0.f);
2886 outputs.push_back(-0.f);
2887 outputs.push_back(0.f);
2888 outputs.push_back(-0.f);
2889 outputs.push_back(0.f);
2890 outputs.push_back(-0.f);
2892 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs)));
2893 spec.outputs.push_back(BufferSp(new Float32Buffer(outputs)));
2895 group->addChild(new SpvAsmComputeShaderCase(
2896 testCtx, "flush_to_zero", "Check that values are zeroed correctly", spec));
2900 ComputeShaderSpec spec;
2901 const deUint8 numCases = 6;
2902 vector<float> inputs (numCases, 0.f);
2903 vector<float> outputs;
2905 spec.assembly = shader;
2906 spec.numWorkGroups = IVec3(numCases, 1, 1);
2908 for (deUint8 idx = 0; idx < 6; ++idx)
2910 const float f = static_cast<float>(idx * 10 - 30) / 4.f;
2911 spec.specConstants.push_back(bitwiseCast<deUint32>(f));
2912 outputs.push_back(f);
2915 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs)));
2916 spec.outputs.push_back(BufferSp(new Float32Buffer(outputs)));
2918 group->addChild(new SpvAsmComputeShaderCase(
2919 testCtx, "exact", "Check that values exactly preserved where appropriate", spec));
2923 ComputeShaderSpec spec;
2924 const deUint8 numCases = 4;
2925 vector<float> inputs (numCases, 0.f);
2926 vector<float> outputs;
2928 spec.assembly = shader;
2929 spec.numWorkGroups = IVec3(numCases, 1, 1);
2930 spec.verifyIO = &compareOpQuantizeF16ComputeExactCase;
2932 outputs.push_back(constructNormalizedFloat(8, 0x300300));
2933 outputs.push_back(-constructNormalizedFloat(-7, 0x600800));
2934 outputs.push_back(constructNormalizedFloat(2, 0x01E000));
2935 outputs.push_back(constructNormalizedFloat(1, 0xFFE000));
2937 for (deUint8 idx = 0; idx < numCases; ++idx)
2938 spec.specConstants.push_back(bitwiseCast<deUint32>(outputs[idx]));
2940 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs)));
2941 spec.outputs.push_back(BufferSp(new Float32Buffer(outputs)));
2943 group->addChild(new SpvAsmComputeShaderCase(
2944 testCtx, "rounded", "Check that are rounded when needed", spec));
2947 return group.release();
2950 // Checks that constant null/composite values can be used in computation.
2951 tcu::TestCaseGroup* createOpConstantUsageGroup (tcu::TestContext& testCtx)
2953 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opconstantnullcomposite", "Spotcheck the OpConstantNull & OpConstantComposite instruction"));
2954 ComputeShaderSpec spec;
2955 de::Random rnd (deStringHash(group->getName()));
2956 const int numElements = 100;
2957 vector<float> positiveFloats (numElements, 0);
2958 vector<float> negativeFloats (numElements, 0);
2960 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
2962 for (size_t ndx = 0; ndx < numElements; ++ndx)
2963 negativeFloats[ndx] = -positiveFloats[ndx];
2966 "OpCapability Shader\n"
2967 "%std450 = OpExtInstImport \"GLSL.std.450\"\n"
2968 "OpMemoryModel Logical GLSL450\n"
2969 "OpEntryPoint GLCompute %main \"main\" %id\n"
2970 "OpExecutionMode %main LocalSize 1 1 1\n"
2972 "OpSource GLSL 430\n"
2973 "OpName %main \"main\"\n"
2974 "OpName %id \"gl_GlobalInvocationID\"\n"
2976 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2978 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) +
2980 "%fmat = OpTypeMatrix %fvec3 3\n"
2981 "%ten = OpConstant %u32 10\n"
2982 "%f32arr10 = OpTypeArray %f32 %ten\n"
2983 "%fst = OpTypeStruct %f32 %f32\n"
2985 + string(s_InputOutputBuffer) +
2987 "%id = OpVariable %uvec3ptr Input\n"
2988 "%zero = OpConstant %i32 0\n"
2990 // Create a bunch of null values
2991 "%unull = OpConstantNull %u32\n"
2992 "%fnull = OpConstantNull %f32\n"
2993 "%vnull = OpConstantNull %fvec3\n"
2994 "%mnull = OpConstantNull %fmat\n"
2995 "%anull = OpConstantNull %f32arr10\n"
2996 "%snull = OpConstantComposite %fst %fnull %fnull\n"
2998 "%main = OpFunction %void None %voidf\n"
2999 "%label = OpLabel\n"
3000 "%idval = OpLoad %uvec3 %id\n"
3001 "%x = OpCompositeExtract %u32 %idval 0\n"
3002 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3003 "%inval = OpLoad %f32 %inloc\n"
3004 "%neg = OpFNegate %f32 %inval\n"
3006 // Get the abs() of (a certain element of) those null values
3007 "%unull_cov = OpConvertUToF %f32 %unull\n"
3008 "%unull_abs = OpExtInst %f32 %std450 FAbs %unull_cov\n"
3009 "%fnull_abs = OpExtInst %f32 %std450 FAbs %fnull\n"
3010 "%vnull_0 = OpCompositeExtract %f32 %vnull 0\n"
3011 "%vnull_abs = OpExtInst %f32 %std450 FAbs %vnull_0\n"
3012 "%mnull_12 = OpCompositeExtract %f32 %mnull 1 2\n"
3013 "%mnull_abs = OpExtInst %f32 %std450 FAbs %mnull_12\n"
3014 "%anull_3 = OpCompositeExtract %f32 %anull 3\n"
3015 "%anull_abs = OpExtInst %f32 %std450 FAbs %anull_3\n"
3016 "%snull_1 = OpCompositeExtract %f32 %snull 1\n"
3017 "%snull_abs = OpExtInst %f32 %std450 FAbs %snull_1\n"
3020 "%add1 = OpFAdd %f32 %neg %unull_abs\n"
3021 "%add2 = OpFAdd %f32 %add1 %fnull_abs\n"
3022 "%add3 = OpFAdd %f32 %add2 %vnull_abs\n"
3023 "%add4 = OpFAdd %f32 %add3 %mnull_abs\n"
3024 "%add5 = OpFAdd %f32 %add4 %anull_abs\n"
3025 "%final = OpFAdd %f32 %add5 %snull_abs\n"
3027 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3028 " OpStore %outloc %final\n" // write to output
3031 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
3032 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
3033 spec.numWorkGroups = IVec3(numElements, 1, 1);
3035 group->addChild(new SpvAsmComputeShaderCase(testCtx, "spotcheck", "Check that values constructed via OpConstantNull & OpConstantComposite can be used", spec));
3037 return group.release();
3040 // Assembly code used for testing loop control is based on GLSL source code:
3043 // layout(std140, set = 0, binding = 0) readonly buffer Input {
3044 // float elements[];
3046 // layout(std140, set = 0, binding = 1) writeonly buffer Output {
3047 // float elements[];
3051 // uint x = gl_GlobalInvocationID.x;
3052 // output_data.elements[x] = input_data.elements[x];
3053 // for (uint i = 0; i < 4; ++i)
3054 // output_data.elements[x] += 1.f;
3056 tcu::TestCaseGroup* createLoopControlGroup (tcu::TestContext& testCtx)
3058 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "loop_control", "Tests loop control cases"));
3059 vector<CaseParameter> cases;
3060 de::Random rnd (deStringHash(group->getName()));
3061 const int numElements = 100;
3062 vector<float> inputFloats (numElements, 0);
3063 vector<float> outputFloats (numElements, 0);
3064 const StringTemplate shaderTemplate (
3065 string(s_ShaderPreamble) +
3067 "OpSource GLSL 430\n"
3068 "OpName %main \"main\"\n"
3069 "OpName %id \"gl_GlobalInvocationID\"\n"
3071 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3073 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) + string(s_InputOutputBuffer) +
3075 "%u32ptr = OpTypePointer Function %u32\n"
3077 "%id = OpVariable %uvec3ptr Input\n"
3078 "%zero = OpConstant %i32 0\n"
3079 "%uzero = OpConstant %u32 0\n"
3080 "%one = OpConstant %i32 1\n"
3081 "%constf1 = OpConstant %f32 1.0\n"
3082 "%four = OpConstant %u32 4\n"
3084 "%main = OpFunction %void None %voidf\n"
3085 "%entry = OpLabel\n"
3086 "%i = OpVariable %u32ptr Function\n"
3087 " OpStore %i %uzero\n"
3089 "%idval = OpLoad %uvec3 %id\n"
3090 "%x = OpCompositeExtract %u32 %idval 0\n"
3091 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3092 "%inval = OpLoad %f32 %inloc\n"
3093 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3094 " OpStore %outloc %inval\n"
3095 " OpBranch %loop_entry\n"
3097 "%loop_entry = OpLabel\n"
3098 "%i_val = OpLoad %u32 %i\n"
3099 "%cmp_lt = OpULessThan %bool %i_val %four\n"
3100 " OpLoopMerge %loop_merge %loop_entry ${CONTROL}\n"
3101 " OpBranchConditional %cmp_lt %loop_body %loop_merge\n"
3102 "%loop_body = OpLabel\n"
3103 "%outval = OpLoad %f32 %outloc\n"
3104 "%addf1 = OpFAdd %f32 %outval %constf1\n"
3105 " OpStore %outloc %addf1\n"
3106 "%new_i = OpIAdd %u32 %i_val %one\n"
3107 " OpStore %i %new_i\n"
3108 " OpBranch %loop_entry\n"
3109 "%loop_merge = OpLabel\n"
3111 " OpFunctionEnd\n");
3113 cases.push_back(CaseParameter("none", "None"));
3114 cases.push_back(CaseParameter("unroll", "Unroll"));
3115 cases.push_back(CaseParameter("dont_unroll", "DontUnroll"));
3116 cases.push_back(CaseParameter("unroll_dont_unroll", "Unroll|DontUnroll"));
3118 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats[0], numElements);
3120 for (size_t ndx = 0; ndx < numElements; ++ndx)
3121 outputFloats[ndx] = inputFloats[ndx] + 4.f;
3123 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
3125 map<string, string> specializations;
3126 ComputeShaderSpec spec;
3128 specializations["CONTROL"] = cases[caseNdx].param;
3129 spec.assembly = shaderTemplate.specialize(specializations);
3130 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
3131 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
3132 spec.numWorkGroups = IVec3(numElements, 1, 1);
3134 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
3137 return group.release();
3140 // Assembly code used for testing selection control is based on GLSL source code:
3143 // layout(std140, set = 0, binding = 0) readonly buffer Input {
3144 // float elements[];
3146 // layout(std140, set = 0, binding = 1) writeonly buffer Output {
3147 // float elements[];
3151 // uint x = gl_GlobalInvocationID.x;
3152 // float val = input_data.elements[x];
3154 // output_data.elements[x] = val + 1.f;
3156 // output_data.elements[x] = val - 1.f;
3158 tcu::TestCaseGroup* createSelectionControlGroup (tcu::TestContext& testCtx)
3160 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "selection_control", "Tests selection control cases"));
3161 vector<CaseParameter> cases;
3162 de::Random rnd (deStringHash(group->getName()));
3163 const int numElements = 100;
3164 vector<float> inputFloats (numElements, 0);
3165 vector<float> outputFloats (numElements, 0);
3166 const StringTemplate shaderTemplate (
3167 string(s_ShaderPreamble) +
3169 "OpSource GLSL 430\n"
3170 "OpName %main \"main\"\n"
3171 "OpName %id \"gl_GlobalInvocationID\"\n"
3173 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3175 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) + string(s_InputOutputBuffer) +
3177 "%id = OpVariable %uvec3ptr Input\n"
3178 "%zero = OpConstant %i32 0\n"
3179 "%constf1 = OpConstant %f32 1.0\n"
3180 "%constf10 = OpConstant %f32 10.0\n"
3182 "%main = OpFunction %void None %voidf\n"
3183 "%entry = OpLabel\n"
3184 "%idval = OpLoad %uvec3 %id\n"
3185 "%x = OpCompositeExtract %u32 %idval 0\n"
3186 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3187 "%inval = OpLoad %f32 %inloc\n"
3188 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3189 "%cmp_gt = OpFOrdGreaterThan %bool %inval %constf10\n"
3191 " OpSelectionMerge %if_end ${CONTROL}\n"
3192 " OpBranchConditional %cmp_gt %if_true %if_false\n"
3193 "%if_true = OpLabel\n"
3194 "%addf1 = OpFAdd %f32 %inval %constf1\n"
3195 " OpStore %outloc %addf1\n"
3196 " OpBranch %if_end\n"
3197 "%if_false = OpLabel\n"
3198 "%subf1 = OpFSub %f32 %inval %constf1\n"
3199 " OpStore %outloc %subf1\n"
3200 " OpBranch %if_end\n"
3201 "%if_end = OpLabel\n"
3203 " OpFunctionEnd\n");
3205 cases.push_back(CaseParameter("none", "None"));
3206 cases.push_back(CaseParameter("flatten", "Flatten"));
3207 cases.push_back(CaseParameter("dont_flatten", "DontFlatten"));
3208 cases.push_back(CaseParameter("flatten_dont_flatten", "DontFlatten|Flatten"));
3210 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats[0], numElements);
3212 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
3213 floorAll(inputFloats);
3215 for (size_t ndx = 0; ndx < numElements; ++ndx)
3216 outputFloats[ndx] = inputFloats[ndx] + (inputFloats[ndx] > 10.f ? 1.f : -1.f);
3218 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
3220 map<string, string> specializations;
3221 ComputeShaderSpec spec;
3223 specializations["CONTROL"] = cases[caseNdx].param;
3224 spec.assembly = shaderTemplate.specialize(specializations);
3225 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
3226 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
3227 spec.numWorkGroups = IVec3(numElements, 1, 1);
3229 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
3232 return group.release();
3235 // Assembly code used for testing function control is based on GLSL source code:
3239 // layout(std140, set = 0, binding = 0) readonly buffer Input {
3240 // float elements[];
3242 // layout(std140, set = 0, binding = 1) writeonly buffer Output {
3243 // float elements[];
3246 // float const10() { return 10.f; }
3249 // uint x = gl_GlobalInvocationID.x;
3250 // output_data.elements[x] = input_data.elements[x] + const10();
3252 tcu::TestCaseGroup* createFunctionControlGroup (tcu::TestContext& testCtx)
3254 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "function_control", "Tests function control cases"));
3255 vector<CaseParameter> cases;
3256 de::Random rnd (deStringHash(group->getName()));
3257 const int numElements = 100;
3258 vector<float> inputFloats (numElements, 0);
3259 vector<float> outputFloats (numElements, 0);
3260 const StringTemplate shaderTemplate (
3261 string(s_ShaderPreamble) +
3263 "OpSource GLSL 430\n"
3264 "OpName %main \"main\"\n"
3265 "OpName %func_const10 \"const10(\"\n"
3266 "OpName %id \"gl_GlobalInvocationID\"\n"
3268 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3270 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) + string(s_InputOutputBuffer) +
3272 "%f32f = OpTypeFunction %f32\n"
3273 "%id = OpVariable %uvec3ptr Input\n"
3274 "%zero = OpConstant %i32 0\n"
3275 "%constf10 = OpConstant %f32 10.0\n"
3277 "%main = OpFunction %void None %voidf\n"
3278 "%entry = OpLabel\n"
3279 "%idval = OpLoad %uvec3 %id\n"
3280 "%x = OpCompositeExtract %u32 %idval 0\n"
3281 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3282 "%inval = OpLoad %f32 %inloc\n"
3283 "%ret_10 = OpFunctionCall %f32 %func_const10\n"
3284 "%fadd = OpFAdd %f32 %inval %ret_10\n"
3285 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3286 " OpStore %outloc %fadd\n"
3290 "%func_const10 = OpFunction %f32 ${CONTROL} %f32f\n"
3291 "%label = OpLabel\n"
3292 " OpReturnValue %constf10\n"
3293 " OpFunctionEnd\n");
3295 cases.push_back(CaseParameter("none", "None"));
3296 cases.push_back(CaseParameter("inline", "Inline"));
3297 cases.push_back(CaseParameter("dont_inline", "DontInline"));
3298 cases.push_back(CaseParameter("pure", "Pure"));
3299 cases.push_back(CaseParameter("const", "Const"));
3300 cases.push_back(CaseParameter("inline_pure", "Inline|Pure"));
3301 cases.push_back(CaseParameter("const_dont_inline", "Const|DontInline"));
3302 cases.push_back(CaseParameter("inline_dont_inline", "Inline|DontInline"));
3303 cases.push_back(CaseParameter("pure_inline_dont_inline", "Pure|Inline|DontInline"));
3305 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats[0], numElements);
3307 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
3308 floorAll(inputFloats);
3310 for (size_t ndx = 0; ndx < numElements; ++ndx)
3311 outputFloats[ndx] = inputFloats[ndx] + 10.f;
3313 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
3315 map<string, string> specializations;
3316 ComputeShaderSpec spec;
3318 specializations["CONTROL"] = cases[caseNdx].param;
3319 spec.assembly = shaderTemplate.specialize(specializations);
3320 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
3321 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
3322 spec.numWorkGroups = IVec3(numElements, 1, 1);
3324 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
3327 return group.release();
3330 tcu::TestCaseGroup* createMemoryAccessGroup (tcu::TestContext& testCtx)
3332 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "memory_access", "Tests memory access cases"));
3333 vector<CaseParameter> cases;
3334 de::Random rnd (deStringHash(group->getName()));
3335 const int numElements = 100;
3336 vector<float> inputFloats (numElements, 0);
3337 vector<float> outputFloats (numElements, 0);
3338 const StringTemplate shaderTemplate (
3339 string(s_ShaderPreamble) +
3341 "OpSource GLSL 430\n"
3342 "OpName %main \"main\"\n"
3343 "OpName %id \"gl_GlobalInvocationID\"\n"
3345 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3347 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) + string(s_InputOutputBuffer) +
3349 "%f32ptr_f = OpTypePointer Function %f32\n"
3351 "%id = OpVariable %uvec3ptr Input\n"
3352 "%zero = OpConstant %i32 0\n"
3353 "%four = OpConstant %i32 4\n"
3355 "%main = OpFunction %void None %voidf\n"
3356 "%label = OpLabel\n"
3357 "%copy = OpVariable %f32ptr_f Function\n"
3358 "%idval = OpLoad %uvec3 %id ${ACCESS}\n"
3359 "%x = OpCompositeExtract %u32 %idval 0\n"
3360 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3361 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3362 " OpCopyMemory %copy %inloc ${ACCESS}\n"
3363 "%val1 = OpLoad %f32 %copy\n"
3364 "%val2 = OpLoad %f32 %inloc\n"
3365 "%add = OpFAdd %f32 %val1 %val2\n"
3366 " OpStore %outloc %add ${ACCESS}\n"
3368 " OpFunctionEnd\n");
3370 cases.push_back(CaseParameter("null", ""));
3371 cases.push_back(CaseParameter("none", "None"));
3372 cases.push_back(CaseParameter("volatile", "Volatile"));
3373 cases.push_back(CaseParameter("aligned", "Aligned 4"));
3374 cases.push_back(CaseParameter("nontemporal", "Nontemporal"));
3375 cases.push_back(CaseParameter("aligned_nontemporal", "Aligned|Nontemporal 4"));
3376 cases.push_back(CaseParameter("aligned_volatile", "Volatile|Aligned 4"));
3378 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats[0], numElements);
3380 for (size_t ndx = 0; ndx < numElements; ++ndx)
3381 outputFloats[ndx] = inputFloats[ndx] + inputFloats[ndx];
3383 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
3385 map<string, string> specializations;
3386 ComputeShaderSpec spec;
3388 specializations["ACCESS"] = cases[caseNdx].param;
3389 spec.assembly = shaderTemplate.specialize(specializations);
3390 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
3391 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
3392 spec.numWorkGroups = IVec3(numElements, 1, 1);
3394 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
3397 return group.release();
3400 // Checks that we can get undefined values for various types, without exercising a computation with it.
3401 tcu::TestCaseGroup* createOpUndefGroup (tcu::TestContext& testCtx)
3403 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opundef", "Tests the OpUndef instruction"));
3404 vector<CaseParameter> cases;
3405 de::Random rnd (deStringHash(group->getName()));
3406 const int numElements = 100;
3407 vector<float> positiveFloats (numElements, 0);
3408 vector<float> negativeFloats (numElements, 0);
3409 const StringTemplate shaderTemplate (
3410 string(s_ShaderPreamble) +
3412 "OpSource GLSL 430\n"
3413 "OpName %main \"main\"\n"
3414 "OpName %id \"gl_GlobalInvocationID\"\n"
3416 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3418 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) + string(s_InputOutputBuffer) +
3422 "%id = OpVariable %uvec3ptr Input\n"
3423 "%zero = OpConstant %i32 0\n"
3425 "%main = OpFunction %void None %voidf\n"
3426 "%label = OpLabel\n"
3428 "%undef = OpUndef %type\n"
3430 "%idval = OpLoad %uvec3 %id\n"
3431 "%x = OpCompositeExtract %u32 %idval 0\n"
3433 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3434 "%inval = OpLoad %f32 %inloc\n"
3435 "%neg = OpFNegate %f32 %inval\n"
3436 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3437 " OpStore %outloc %neg\n"
3439 " OpFunctionEnd\n");
3441 cases.push_back(CaseParameter("bool", "%type = OpTypeBool"));
3442 cases.push_back(CaseParameter("sint32", "%type = OpTypeInt 32 1"));
3443 cases.push_back(CaseParameter("uint32", "%type = OpTypeInt 32 0"));
3444 cases.push_back(CaseParameter("float32", "%type = OpTypeFloat 32"));
3445 cases.push_back(CaseParameter("vec4float32", "%type = OpTypeVector %f32 4"));
3446 cases.push_back(CaseParameter("vec2uint32", "%type = OpTypeVector %u32 2"));
3447 cases.push_back(CaseParameter("matrix", "%type = OpTypeMatrix %fvec3 3"));
3448 cases.push_back(CaseParameter("image", "%type = OpTypeImage %f32 2D 0 0 0 1 Unknown"));
3449 cases.push_back(CaseParameter("sampler", "%type = OpTypeSampler"));
3450 cases.push_back(CaseParameter("sampledimage", "%img = OpTypeImage %f32 2D 0 0 0 1 Unknown\n"
3451 "%type = OpTypeSampledImage %img"));
3452 cases.push_back(CaseParameter("array", "%100 = OpConstant %u32 100\n"
3453 "%type = OpTypeArray %i32 %100"));
3454 cases.push_back(CaseParameter("runtimearray", "%type = OpTypeRuntimeArray %f32"));
3455 cases.push_back(CaseParameter("struct", "%type = OpTypeStruct %f32 %i32 %u32"));
3456 cases.push_back(CaseParameter("pointer", "%type = OpTypePointer Function %i32"));
3458 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
3460 for (size_t ndx = 0; ndx < numElements; ++ndx)
3461 negativeFloats[ndx] = -positiveFloats[ndx];
3463 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
3465 map<string, string> specializations;
3466 ComputeShaderSpec spec;
3468 specializations["TYPE"] = cases[caseNdx].param;
3469 spec.assembly = shaderTemplate.specialize(specializations);
3470 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
3471 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
3472 spec.numWorkGroups = IVec3(numElements, 1, 1);
3474 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
3477 return group.release();
3479 typedef std::pair<std::string, VkShaderStageFlagBits> EntryToStage;
3480 typedef map<string, vector<EntryToStage> > ModuleMap;
3481 typedef map<VkShaderStageFlagBits, vector<deInt32> > StageToSpecConstantMap;
3483 // Context for a specific test instantiation. For example, an instantiation
3484 // may test colors yellow/magenta/cyan/mauve in a tesselation shader
3485 // with an entry point named 'main_to_the_main'
3486 struct InstanceContext
3488 // Map of modules to what entry_points we care to use from those modules.
3489 ModuleMap moduleMap;
3490 RGBA inputColors[4];
3491 RGBA outputColors[4];
3492 // Concrete SPIR-V code to test via boilerplate specialization.
3493 map<string, string> testCodeFragments;
3494 StageToSpecConstantMap specConstants;
3495 bool hasTessellation;
3496 VkShaderStageFlagBits requiredStages;
3498 InstanceContext (const RGBA (&inputs)[4], const RGBA (&outputs)[4], const map<string, string>& testCodeFragments_, const StageToSpecConstantMap& specConstants_)
3499 : testCodeFragments (testCodeFragments_)
3500 , specConstants (specConstants_)
3501 , hasTessellation (false)
3502 , requiredStages (static_cast<VkShaderStageFlagBits>(0))
3504 inputColors[0] = inputs[0];
3505 inputColors[1] = inputs[1];
3506 inputColors[2] = inputs[2];
3507 inputColors[3] = inputs[3];
3509 outputColors[0] = outputs[0];
3510 outputColors[1] = outputs[1];
3511 outputColors[2] = outputs[2];
3512 outputColors[3] = outputs[3];
3515 InstanceContext (const InstanceContext& other)
3516 : moduleMap (other.moduleMap)
3517 , testCodeFragments (other.testCodeFragments)
3518 , specConstants (other.specConstants)
3519 , hasTessellation (other.hasTessellation)
3520 , requiredStages (other.requiredStages)
3522 inputColors[0] = other.inputColors[0];
3523 inputColors[1] = other.inputColors[1];
3524 inputColors[2] = other.inputColors[2];
3525 inputColors[3] = other.inputColors[3];
3527 outputColors[0] = other.outputColors[0];
3528 outputColors[1] = other.outputColors[1];
3529 outputColors[2] = other.outputColors[2];
3530 outputColors[3] = other.outputColors[3];
3534 // A description of a shader to be used for a single stage of the graphics pipeline.
3535 struct ShaderElement
3537 // The module that contains this shader entrypoint.
3540 // The name of the entrypoint.
3543 // Which shader stage this entry point represents.
3544 VkShaderStageFlagBits stage;
3546 ShaderElement (const string& moduleName_, const string& entryPoint_, VkShaderStageFlagBits shaderStage_)
3547 : moduleName(moduleName_)
3548 , entryName(entryPoint_)
3549 , stage(shaderStage_)
3554 void getDefaultColors (RGBA (&colors)[4])
3556 colors[0] = RGBA::white();
3557 colors[1] = RGBA::red();
3558 colors[2] = RGBA::green();
3559 colors[3] = RGBA::blue();
3562 void getHalfColorsFullAlpha (RGBA (&colors)[4])
3564 colors[0] = RGBA(127, 127, 127, 255);
3565 colors[1] = RGBA(127, 0, 0, 255);
3566 colors[2] = RGBA(0, 127, 0, 255);
3567 colors[3] = RGBA(0, 0, 127, 255);
3570 void getInvertedDefaultColors (RGBA (&colors)[4])
3572 colors[0] = RGBA(0, 0, 0, 255);
3573 colors[1] = RGBA(0, 255, 255, 255);
3574 colors[2] = RGBA(255, 0, 255, 255);
3575 colors[3] = RGBA(255, 255, 0, 255);
3578 // Turns a statically sized array of ShaderElements into an instance-context
3579 // by setting up the mapping of modules to their contained shaders and stages.
3580 // The inputs and expected outputs are given by inputColors and outputColors
3582 InstanceContext createInstanceContext (const ShaderElement (&elements)[N], const RGBA (&inputColors)[4], const RGBA (&outputColors)[4], const map<string, string>& testCodeFragments, const StageToSpecConstantMap& specConstants)
3584 InstanceContext ctx (inputColors, outputColors, testCodeFragments, specConstants);
3585 for (size_t i = 0; i < N; ++i)
3587 ctx.moduleMap[elements[i].moduleName].push_back(std::make_pair(elements[i].entryName, elements[i].stage));
3588 ctx.requiredStages = static_cast<VkShaderStageFlagBits>(ctx.requiredStages | elements[i].stage);
3594 inline InstanceContext createInstanceContext (const ShaderElement (&elements)[N], RGBA (&inputColors)[4], const RGBA (&outputColors)[4], const map<string, string>& testCodeFragments)
3596 return createInstanceContext(elements, inputColors, outputColors, testCodeFragments, StageToSpecConstantMap());
3599 // The same as createInstanceContext above, but with default colors.
3601 InstanceContext createInstanceContext (const ShaderElement (&elements)[N], const map<string, string>& testCodeFragments)
3603 RGBA defaultColors[4];
3604 getDefaultColors(defaultColors);
3605 return createInstanceContext(elements, defaultColors, defaultColors, testCodeFragments);
3608 // For the current InstanceContext, constructs the required modules and shader stage create infos.
3609 void createPipelineShaderStages (const DeviceInterface& vk, const VkDevice vkDevice, InstanceContext& instance, Context& context, vector<ModuleHandleSp>& modules, vector<VkPipelineShaderStageCreateInfo>& createInfos)
3611 for (ModuleMap::const_iterator moduleNdx = instance.moduleMap.begin(); moduleNdx != instance.moduleMap.end(); ++moduleNdx)
3613 const ModuleHandleSp mod(new Unique<VkShaderModule>(createShaderModule(vk, vkDevice, context.getBinaryCollection().get(moduleNdx->first), 0)));
3614 modules.push_back(ModuleHandleSp(mod));
3615 for (vector<EntryToStage>::const_iterator shaderNdx = moduleNdx->second.begin(); shaderNdx != moduleNdx->second.end(); ++shaderNdx)
3617 const EntryToStage& stage = *shaderNdx;
3618 const VkPipelineShaderStageCreateInfo shaderParam =
3620 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, // VkStructureType sType;
3621 DE_NULL, // const void* pNext;
3622 (VkPipelineShaderStageCreateFlags)0,
3623 stage.second, // VkShaderStageFlagBits stage;
3624 **modules.back(), // VkShaderModule module;
3625 stage.first.c_str(), // const char* pName;
3626 (const VkSpecializationInfo*)DE_NULL,
3628 createInfos.push_back(shaderParam);
3633 #define SPIRV_ASSEMBLY_TYPES \
3634 "%void = OpTypeVoid\n" \
3635 "%bool = OpTypeBool\n" \
3637 "%i32 = OpTypeInt 32 1\n" \
3638 "%u32 = OpTypeInt 32 0\n" \
3640 "%f32 = OpTypeFloat 32\n" \
3641 "%v3f32 = OpTypeVector %f32 3\n" \
3642 "%v4f32 = OpTypeVector %f32 4\n" \
3643 "%v4bool = OpTypeVector %bool 4\n" \
3645 "%v4f32_function = OpTypeFunction %v4f32 %v4f32\n" \
3646 "%fun = OpTypeFunction %void\n" \
3648 "%ip_f32 = OpTypePointer Input %f32\n" \
3649 "%ip_i32 = OpTypePointer Input %i32\n" \
3650 "%ip_v3f32 = OpTypePointer Input %v3f32\n" \
3651 "%ip_v4f32 = OpTypePointer Input %v4f32\n" \
3653 "%op_f32 = OpTypePointer Output %f32\n" \
3654 "%op_v4f32 = OpTypePointer Output %v4f32\n" \
3656 "%fp_f32 = OpTypePointer Function %f32\n" \
3657 "%fp_i32 = OpTypePointer Function %i32\n" \
3658 "%fp_v4f32 = OpTypePointer Function %v4f32\n"
3660 #define SPIRV_ASSEMBLY_CONSTANTS \
3661 "%c_f32_1 = OpConstant %f32 1.0\n" \
3662 "%c_f32_0 = OpConstant %f32 0.0\n" \
3663 "%c_f32_0_5 = OpConstant %f32 0.5\n" \
3664 "%c_f32_n1 = OpConstant %f32 -1.\n" \
3665 "%c_f32_7 = OpConstant %f32 7.0\n" \
3666 "%c_f32_8 = OpConstant %f32 8.0\n" \
3667 "%c_i32_0 = OpConstant %i32 0\n" \
3668 "%c_i32_1 = OpConstant %i32 1\n" \
3669 "%c_i32_2 = OpConstant %i32 2\n" \
3670 "%c_i32_3 = OpConstant %i32 3\n" \
3671 "%c_i32_4 = OpConstant %i32 4\n" \
3672 "%c_u32_0 = OpConstant %u32 0\n" \
3673 "%c_u32_1 = OpConstant %u32 1\n" \
3674 "%c_u32_2 = OpConstant %u32 2\n" \
3675 "%c_u32_3 = OpConstant %u32 3\n" \
3676 "%c_u32_32 = OpConstant %u32 32\n" \
3677 "%c_u32_4 = OpConstant %u32 4\n" \
3678 "%c_u32_31_bits = OpConstant %u32 0x7FFFFFFF\n" \
3679 "%c_v4f32_1_1_1_1 = OpConstantComposite %v4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_1\n" \
3680 "%c_v4f32_1_0_0_1 = OpConstantComposite %v4f32 %c_f32_1 %c_f32_0 %c_f32_0 %c_f32_1\n" \
3681 "%c_v4f32_0_5_0_5_0_5_0_5 = OpConstantComposite %v4f32 %c_f32_0_5 %c_f32_0_5 %c_f32_0_5 %c_f32_0_5\n"
3683 #define SPIRV_ASSEMBLY_ARRAYS \
3684 "%a1f32 = OpTypeArray %f32 %c_u32_1\n" \
3685 "%a2f32 = OpTypeArray %f32 %c_u32_2\n" \
3686 "%a3v4f32 = OpTypeArray %v4f32 %c_u32_3\n" \
3687 "%a4f32 = OpTypeArray %f32 %c_u32_4\n" \
3688 "%a32v4f32 = OpTypeArray %v4f32 %c_u32_32\n" \
3689 "%ip_a3v4f32 = OpTypePointer Input %a3v4f32\n" \
3690 "%ip_a32v4f32 = OpTypePointer Input %a32v4f32\n" \
3691 "%op_a2f32 = OpTypePointer Output %a2f32\n" \
3692 "%op_a3v4f32 = OpTypePointer Output %a3v4f32\n" \
3693 "%op_a4f32 = OpTypePointer Output %a4f32\n"
3695 // Creates vertex-shader assembly by specializing a boilerplate StringTemplate
3696 // on fragments, which must (at least) map "testfun" to an OpFunction definition
3697 // for %test_code that takes and returns a %v4f32. Boilerplate IDs are prefixed
3698 // with "BP_" to avoid collisions with fragments.
3700 // It corresponds roughly to this GLSL:
3702 // layout(location = 0) in vec4 position;
3703 // layout(location = 1) in vec4 color;
3704 // layout(location = 1) out highp vec4 vtxColor;
3705 // void main (void) { gl_Position = position; vtxColor = test_func(color); }
3706 string makeVertexShaderAssembly(const map<string, string>& fragments)
3708 // \todo [2015-11-23 awoloszyn] Remove OpName once these have stabalized
3709 static const char vertexShaderBoilerplate[] =
3710 "OpCapability Shader\n"
3711 "OpCapability ClipDistance\n"
3712 "OpCapability CullDistance\n"
3713 "OpMemoryModel Logical GLSL450\n"
3714 "OpEntryPoint Vertex %main \"main\" %BP_stream %BP_position %BP_vtx_color %BP_color %BP_gl_VertexIndex %BP_gl_InstanceIndex\n"
3716 "OpName %main \"main\"\n"
3717 "OpName %BP_gl_PerVertex \"gl_PerVertex\"\n"
3718 "OpMemberName %BP_gl_PerVertex 0 \"gl_Position\"\n"
3719 "OpMemberName %BP_gl_PerVertex 1 \"gl_PointSize\"\n"
3720 "OpMemberName %BP_gl_PerVertex 2 \"gl_ClipDistance\"\n"
3721 "OpMemberName %BP_gl_PerVertex 3 \"gl_CullDistance\"\n"
3722 "OpName %test_code \"testfun(vf4;\"\n"
3723 "OpName %BP_stream \"\"\n"
3724 "OpName %BP_position \"position\"\n"
3725 "OpName %BP_vtx_color \"vtxColor\"\n"
3726 "OpName %BP_color \"color\"\n"
3727 "OpName %BP_gl_VertexIndex \"gl_VertexIndex\"\n"
3728 "OpName %BP_gl_InstanceIndex \"gl_InstanceIndex\"\n"
3729 "OpMemberDecorate %BP_gl_PerVertex 0 BuiltIn Position\n"
3730 "OpMemberDecorate %BP_gl_PerVertex 1 BuiltIn PointSize\n"
3731 "OpMemberDecorate %BP_gl_PerVertex 2 BuiltIn ClipDistance\n"
3732 "OpMemberDecorate %BP_gl_PerVertex 3 BuiltIn CullDistance\n"
3733 "OpDecorate %BP_gl_PerVertex Block\n"
3734 "OpDecorate %BP_position Location 0\n"
3735 "OpDecorate %BP_vtx_color Location 1\n"
3736 "OpDecorate %BP_color Location 1\n"
3737 "OpDecorate %BP_gl_VertexIndex BuiltIn VertexIndex\n"
3738 "OpDecorate %BP_gl_InstanceIndex BuiltIn InstanceIndex\n"
3739 "${decoration:opt}\n"
3740 SPIRV_ASSEMBLY_TYPES
3741 SPIRV_ASSEMBLY_CONSTANTS
3742 SPIRV_ASSEMBLY_ARRAYS
3743 "%BP_gl_PerVertex = OpTypeStruct %v4f32 %f32 %a1f32 %a1f32\n"
3744 "%BP_op_gl_PerVertex = OpTypePointer Output %BP_gl_PerVertex\n"
3745 "%BP_stream = OpVariable %BP_op_gl_PerVertex Output\n"
3746 "%BP_position = OpVariable %ip_v4f32 Input\n"
3747 "%BP_vtx_color = OpVariable %op_v4f32 Output\n"
3748 "%BP_color = OpVariable %ip_v4f32 Input\n"
3749 "%BP_gl_VertexIndex = OpVariable %ip_i32 Input\n"
3750 "%BP_gl_InstanceIndex = OpVariable %ip_i32 Input\n"
3752 "%main = OpFunction %void None %fun\n"
3753 "%BP_label = OpLabel\n"
3754 "%BP_pos = OpLoad %v4f32 %BP_position\n"
3755 "%BP_gl_pos = OpAccessChain %op_v4f32 %BP_stream %c_i32_0\n"
3756 "OpStore %BP_gl_pos %BP_pos\n"
3757 "%BP_col = OpLoad %v4f32 %BP_color\n"
3758 "%BP_col_transformed = OpFunctionCall %v4f32 %test_code %BP_col\n"
3759 "OpStore %BP_vtx_color %BP_col_transformed\n"
3763 return tcu::StringTemplate(vertexShaderBoilerplate).specialize(fragments);
3766 // Creates tess-control-shader assembly by specializing a boilerplate
3767 // StringTemplate on fragments, which must (at least) map "testfun" to an
3768 // OpFunction definition for %test_code that takes and returns a %v4f32.
3769 // Boilerplate IDs are prefixed with "BP_" to avoid collisions with fragments.
3771 // It roughly corresponds to the following GLSL.
3774 // layout(vertices = 3) out;
3775 // layout(location = 1) in vec4 in_color[];
3776 // layout(location = 1) out vec4 out_color[];
3779 // out_color[gl_InvocationID] = testfun(in_color[gl_InvocationID]);
3780 // gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;
3781 // if (gl_InvocationID == 0) {
3782 // gl_TessLevelOuter[0] = 1.0;
3783 // gl_TessLevelOuter[1] = 1.0;
3784 // gl_TessLevelOuter[2] = 1.0;
3785 // gl_TessLevelInner[0] = 1.0;
3788 string makeTessControlShaderAssembly (const map<string, string>& fragments)
3790 static const char tessControlShaderBoilerplate[] =
3791 "OpCapability Tessellation\n"
3792 "OpCapability ClipDistance\n"
3793 "OpCapability CullDistance\n"
3794 "OpMemoryModel Logical GLSL450\n"
3795 "OpEntryPoint TessellationControl %BP_main \"main\" %BP_out_color %BP_gl_InvocationID %BP_in_color %BP_gl_out %BP_gl_in %BP_gl_TessLevelOuter %BP_gl_TessLevelInner\n"
3796 "OpExecutionMode %BP_main OutputVertices 3\n"
3798 "OpName %BP_main \"main\"\n"
3799 "OpName %test_code \"testfun(vf4;\"\n"
3800 "OpName %BP_out_color \"out_color\"\n"
3801 "OpName %BP_gl_InvocationID \"gl_InvocationID\"\n"
3802 "OpName %BP_in_color \"in_color\"\n"
3803 "OpName %BP_gl_PerVertex \"gl_PerVertex\"\n"
3804 "OpMemberName %BP_gl_PerVertex 0 \"gl_Position\"\n"
3805 "OpMemberName %BP_gl_PerVertex 1 \"gl_PointSize\"\n"
3806 "OpMemberName %BP_gl_PerVertex 2 \"gl_ClipDistance\"\n"
3807 "OpMemberName %BP_gl_PerVertex 3 \"gl_CullDistance\"\n"
3808 "OpName %BP_gl_out \"gl_out\"\n"
3809 "OpName %BP_gl_PVOut \"gl_PerVertex\"\n"
3810 "OpMemberName %BP_gl_PVOut 0 \"gl_Position\"\n"
3811 "OpMemberName %BP_gl_PVOut 1 \"gl_PointSize\"\n"
3812 "OpMemberName %BP_gl_PVOut 2 \"gl_ClipDistance\"\n"
3813 "OpMemberName %BP_gl_PVOut 3 \"gl_CullDistance\"\n"
3814 "OpName %BP_gl_in \"gl_in\"\n"
3815 "OpName %BP_gl_TessLevelOuter \"gl_TessLevelOuter\"\n"
3816 "OpName %BP_gl_TessLevelInner \"gl_TessLevelInner\"\n"
3817 "OpDecorate %BP_out_color Location 1\n"
3818 "OpDecorate %BP_gl_InvocationID BuiltIn InvocationId\n"
3819 "OpDecorate %BP_in_color Location 1\n"
3820 "OpMemberDecorate %BP_gl_PerVertex 0 BuiltIn Position\n"
3821 "OpMemberDecorate %BP_gl_PerVertex 1 BuiltIn PointSize\n"
3822 "OpMemberDecorate %BP_gl_PerVertex 2 BuiltIn ClipDistance\n"
3823 "OpMemberDecorate %BP_gl_PerVertex 3 BuiltIn CullDistance\n"
3824 "OpDecorate %BP_gl_PerVertex Block\n"
3825 "OpMemberDecorate %BP_gl_PVOut 0 BuiltIn Position\n"
3826 "OpMemberDecorate %BP_gl_PVOut 1 BuiltIn PointSize\n"
3827 "OpMemberDecorate %BP_gl_PVOut 2 BuiltIn ClipDistance\n"
3828 "OpMemberDecorate %BP_gl_PVOut 3 BuiltIn CullDistance\n"
3829 "OpDecorate %BP_gl_PVOut Block\n"
3830 "OpDecorate %BP_gl_TessLevelOuter Patch\n"
3831 "OpDecorate %BP_gl_TessLevelOuter BuiltIn TessLevelOuter\n"
3832 "OpDecorate %BP_gl_TessLevelInner Patch\n"
3833 "OpDecorate %BP_gl_TessLevelInner BuiltIn TessLevelInner\n"
3834 "${decoration:opt}\n"
3835 SPIRV_ASSEMBLY_TYPES
3836 SPIRV_ASSEMBLY_CONSTANTS
3837 SPIRV_ASSEMBLY_ARRAYS
3838 "%BP_out_color = OpVariable %op_a3v4f32 Output\n"
3839 "%BP_gl_InvocationID = OpVariable %ip_i32 Input\n"
3840 "%BP_in_color = OpVariable %ip_a32v4f32 Input\n"
3841 "%BP_gl_PerVertex = OpTypeStruct %v4f32 %f32 %a1f32 %a1f32\n"
3842 "%BP_a3_gl_PerVertex = OpTypeArray %BP_gl_PerVertex %c_u32_3\n"
3843 "%BP_op_a3_gl_PerVertex = OpTypePointer Output %BP_a3_gl_PerVertex\n"
3844 "%BP_gl_out = OpVariable %BP_op_a3_gl_PerVertex Output\n"
3845 "%BP_gl_PVOut = OpTypeStruct %v4f32 %f32 %a1f32 %a1f32\n"
3846 "%BP_a32_gl_PVOut = OpTypeArray %BP_gl_PVOut %c_u32_32\n"
3847 "%BP_ip_a32_gl_PVOut = OpTypePointer Input %BP_a32_gl_PVOut\n"
3848 "%BP_gl_in = OpVariable %BP_ip_a32_gl_PVOut Input\n"
3849 "%BP_gl_TessLevelOuter = OpVariable %op_a4f32 Output\n"
3850 "%BP_gl_TessLevelInner = OpVariable %op_a2f32 Output\n"
3853 "%BP_main = OpFunction %void None %fun\n"
3854 "%BP_label = OpLabel\n"
3856 "%BP_gl_Invoc = OpLoad %i32 %BP_gl_InvocationID\n"
3858 "%BP_in_col_loc = OpAccessChain %ip_v4f32 %BP_in_color %BP_gl_Invoc\n"
3859 "%BP_out_col_loc = OpAccessChain %op_v4f32 %BP_out_color %BP_gl_Invoc\n"
3860 "%BP_in_col_val = OpLoad %v4f32 %BP_in_col_loc\n"
3861 "%BP_clr_transformed = OpFunctionCall %v4f32 %test_code %BP_in_col_val\n"
3862 "OpStore %BP_out_col_loc %BP_clr_transformed\n"
3864 "%BP_in_pos_loc = OpAccessChain %ip_v4f32 %BP_gl_in %BP_gl_Invoc %c_i32_0\n"
3865 "%BP_out_pos_loc = OpAccessChain %op_v4f32 %BP_gl_out %BP_gl_Invoc %c_i32_0\n"
3866 "%BP_in_pos_val = OpLoad %v4f32 %BP_in_pos_loc\n"
3867 "OpStore %BP_out_pos_loc %BP_in_pos_val\n"
3869 "%BP_cmp = OpIEqual %bool %BP_gl_Invoc %c_i32_0\n"
3870 "OpSelectionMerge %BP_merge_label None\n"
3871 "OpBranchConditional %BP_cmp %BP_if_label %BP_merge_label\n"
3872 "%BP_if_label = OpLabel\n"
3873 "%BP_gl_TessLevelOuterPos_0 = OpAccessChain %op_f32 %BP_gl_TessLevelOuter %c_i32_0\n"
3874 "%BP_gl_TessLevelOuterPos_1 = OpAccessChain %op_f32 %BP_gl_TessLevelOuter %c_i32_1\n"
3875 "%BP_gl_TessLevelOuterPos_2 = OpAccessChain %op_f32 %BP_gl_TessLevelOuter %c_i32_2\n"
3876 "%BP_gl_TessLevelInnerPos_0 = OpAccessChain %op_f32 %BP_gl_TessLevelInner %c_i32_0\n"
3877 "OpStore %BP_gl_TessLevelOuterPos_0 %c_f32_1\n"
3878 "OpStore %BP_gl_TessLevelOuterPos_1 %c_f32_1\n"
3879 "OpStore %BP_gl_TessLevelOuterPos_2 %c_f32_1\n"
3880 "OpStore %BP_gl_TessLevelInnerPos_0 %c_f32_1\n"
3881 "OpBranch %BP_merge_label\n"
3882 "%BP_merge_label = OpLabel\n"
3886 return tcu::StringTemplate(tessControlShaderBoilerplate).specialize(fragments);
3889 // Creates tess-evaluation-shader assembly by specializing a boilerplate
3890 // StringTemplate on fragments, which must (at least) map "testfun" to an
3891 // OpFunction definition for %test_code that takes and returns a %v4f32.
3892 // Boilerplate IDs are prefixed with "BP_" to avoid collisions with fragments.
3894 // It roughly corresponds to the following glsl.
3898 // layout(triangles, equal_spacing, ccw) in;
3899 // layout(location = 1) in vec4 in_color[];
3900 // layout(location = 1) out vec4 out_color;
3902 // #define interpolate(val)
3903 // vec4(gl_TessCoord.x) * val[0] + vec4(gl_TessCoord.y) * val[1] +
3904 // vec4(gl_TessCoord.z) * val[2]
3907 // gl_Position = vec4(gl_TessCoord.x) * gl_in[0].gl_Position +
3908 // vec4(gl_TessCoord.y) * gl_in[1].gl_Position +
3909 // vec4(gl_TessCoord.z) * gl_in[2].gl_Position;
3910 // out_color = testfun(interpolate(in_color));
3912 string makeTessEvalShaderAssembly(const map<string, string>& fragments)
3914 static const char tessEvalBoilerplate[] =
3915 "OpCapability Tessellation\n"
3916 "OpCapability ClipDistance\n"
3917 "OpCapability CullDistance\n"
3918 "OpMemoryModel Logical GLSL450\n"
3919 "OpEntryPoint TessellationEvaluation %BP_main \"main\" %BP_stream %BP_gl_TessCoord %BP_gl_in %BP_out_color %BP_in_color\n"
3920 "OpExecutionMode %BP_main Triangles\n"
3921 "OpExecutionMode %BP_main SpacingEqual\n"
3922 "OpExecutionMode %BP_main VertexOrderCcw\n"
3924 "OpName %BP_main \"main\"\n"
3925 "OpName %test_code \"testfun(vf4;\"\n"
3926 "OpName %BP_gl_PerVertexOut \"gl_PerVertex\"\n"
3927 "OpMemberName %BP_gl_PerVertexOut 0 \"gl_Position\"\n"
3928 "OpMemberName %BP_gl_PerVertexOut 1 \"gl_PointSize\"\n"
3929 "OpMemberName %BP_gl_PerVertexOut 2 \"gl_ClipDistance\"\n"
3930 "OpMemberName %BP_gl_PerVertexOut 3 \"gl_CullDistance\"\n"
3931 "OpName %BP_stream \"\"\n"
3932 "OpName %BP_gl_TessCoord \"gl_TessCoord\"\n"
3933 "OpName %BP_gl_PerVertexIn \"gl_PerVertex\"\n"
3934 "OpMemberName %BP_gl_PerVertexIn 0 \"gl_Position\"\n"
3935 "OpMemberName %BP_gl_PerVertexIn 1 \"gl_PointSize\"\n"
3936 "OpMemberName %BP_gl_PerVertexIn 2 \"gl_ClipDistance\"\n"
3937 "OpMemberName %BP_gl_PerVertexIn 3 \"gl_CullDistance\"\n"
3938 "OpName %BP_gl_in \"gl_in\"\n"
3939 "OpName %BP_out_color \"out_color\"\n"
3940 "OpName %BP_in_color \"in_color\"\n"
3941 "OpMemberDecorate %BP_gl_PerVertexOut 0 BuiltIn Position\n"
3942 "OpMemberDecorate %BP_gl_PerVertexOut 1 BuiltIn PointSize\n"
3943 "OpMemberDecorate %BP_gl_PerVertexOut 2 BuiltIn ClipDistance\n"
3944 "OpMemberDecorate %BP_gl_PerVertexOut 3 BuiltIn CullDistance\n"
3945 "OpDecorate %BP_gl_PerVertexOut Block\n"
3946 "OpDecorate %BP_gl_TessCoord BuiltIn TessCoord\n"
3947 "OpMemberDecorate %BP_gl_PerVertexIn 0 BuiltIn Position\n"
3948 "OpMemberDecorate %BP_gl_PerVertexIn 1 BuiltIn PointSize\n"
3949 "OpMemberDecorate %BP_gl_PerVertexIn 2 BuiltIn ClipDistance\n"
3950 "OpMemberDecorate %BP_gl_PerVertexIn 3 BuiltIn CullDistance\n"
3951 "OpDecorate %BP_gl_PerVertexIn Block\n"
3952 "OpDecorate %BP_out_color Location 1\n"
3953 "OpDecorate %BP_in_color Location 1\n"
3954 "${decoration:opt}\n"
3955 SPIRV_ASSEMBLY_TYPES
3956 SPIRV_ASSEMBLY_CONSTANTS
3957 SPIRV_ASSEMBLY_ARRAYS
3958 "%BP_gl_PerVertexOut = OpTypeStruct %v4f32 %f32 %a1f32 %a1f32\n"
3959 "%BP_op_gl_PerVertexOut = OpTypePointer Output %BP_gl_PerVertexOut\n"
3960 "%BP_stream = OpVariable %BP_op_gl_PerVertexOut Output\n"
3961 "%BP_gl_TessCoord = OpVariable %ip_v3f32 Input\n"
3962 "%BP_gl_PerVertexIn = OpTypeStruct %v4f32 %f32 %a1f32 %a1f32\n"
3963 "%BP_a32_gl_PerVertexIn = OpTypeArray %BP_gl_PerVertexIn %c_u32_32\n"
3964 "%BP_ip_a32_gl_PerVertexIn = OpTypePointer Input %BP_a32_gl_PerVertexIn\n"
3965 "%BP_gl_in = OpVariable %BP_ip_a32_gl_PerVertexIn Input\n"
3966 "%BP_out_color = OpVariable %op_v4f32 Output\n"
3967 "%BP_in_color = OpVariable %ip_a32v4f32 Input\n"
3969 "%BP_main = OpFunction %void None %fun\n"
3970 "%BP_label = OpLabel\n"
3971 "%BP_gl_TC_0 = OpAccessChain %ip_f32 %BP_gl_TessCoord %c_u32_0\n"
3972 "%BP_gl_TC_1 = OpAccessChain %ip_f32 %BP_gl_TessCoord %c_u32_1\n"
3973 "%BP_gl_TC_2 = OpAccessChain %ip_f32 %BP_gl_TessCoord %c_u32_2\n"
3974 "%BP_gl_in_gl_Pos_0 = OpAccessChain %ip_v4f32 %BP_gl_in %c_i32_0 %c_i32_0\n"
3975 "%BP_gl_in_gl_Pos_1 = OpAccessChain %ip_v4f32 %BP_gl_in %c_i32_1 %c_i32_0\n"
3976 "%BP_gl_in_gl_Pos_2 = OpAccessChain %ip_v4f32 %BP_gl_in %c_i32_2 %c_i32_0\n"
3978 "%BP_gl_OPos = OpAccessChain %op_v4f32 %BP_stream %c_i32_0\n"
3979 "%BP_in_color_0 = OpAccessChain %ip_v4f32 %BP_in_color %c_i32_0\n"
3980 "%BP_in_color_1 = OpAccessChain %ip_v4f32 %BP_in_color %c_i32_1\n"
3981 "%BP_in_color_2 = OpAccessChain %ip_v4f32 %BP_in_color %c_i32_2\n"
3983 "%BP_TC_W_0 = OpLoad %f32 %BP_gl_TC_0\n"
3984 "%BP_TC_W_1 = OpLoad %f32 %BP_gl_TC_1\n"
3985 "%BP_TC_W_2 = OpLoad %f32 %BP_gl_TC_2\n"
3986 "%BP_v4f32_TC_0 = OpCompositeConstruct %v4f32 %BP_TC_W_0 %BP_TC_W_0 %BP_TC_W_0 %BP_TC_W_0\n"
3987 "%BP_v4f32_TC_1 = OpCompositeConstruct %v4f32 %BP_TC_W_1 %BP_TC_W_1 %BP_TC_W_1 %BP_TC_W_1\n"
3988 "%BP_v4f32_TC_2 = OpCompositeConstruct %v4f32 %BP_TC_W_2 %BP_TC_W_2 %BP_TC_W_2 %BP_TC_W_2\n"
3990 "%BP_gl_IP_0 = OpLoad %v4f32 %BP_gl_in_gl_Pos_0\n"
3991 "%BP_gl_IP_1 = OpLoad %v4f32 %BP_gl_in_gl_Pos_1\n"
3992 "%BP_gl_IP_2 = OpLoad %v4f32 %BP_gl_in_gl_Pos_2\n"
3994 "%BP_IP_W_0 = OpFMul %v4f32 %BP_v4f32_TC_0 %BP_gl_IP_0\n"
3995 "%BP_IP_W_1 = OpFMul %v4f32 %BP_v4f32_TC_1 %BP_gl_IP_1\n"
3996 "%BP_IP_W_2 = OpFMul %v4f32 %BP_v4f32_TC_2 %BP_gl_IP_2\n"
3998 "%BP_pos_sum_0 = OpFAdd %v4f32 %BP_IP_W_0 %BP_IP_W_1\n"
3999 "%BP_pos_sum_1 = OpFAdd %v4f32 %BP_pos_sum_0 %BP_IP_W_2\n"
4001 "OpStore %BP_gl_OPos %BP_pos_sum_1\n"
4003 "%BP_IC_0 = OpLoad %v4f32 %BP_in_color_0\n"
4004 "%BP_IC_1 = OpLoad %v4f32 %BP_in_color_1\n"
4005 "%BP_IC_2 = OpLoad %v4f32 %BP_in_color_2\n"
4007 "%BP_IC_W_0 = OpFMul %v4f32 %BP_v4f32_TC_0 %BP_IC_0\n"
4008 "%BP_IC_W_1 = OpFMul %v4f32 %BP_v4f32_TC_1 %BP_IC_1\n"
4009 "%BP_IC_W_2 = OpFMul %v4f32 %BP_v4f32_TC_2 %BP_IC_2\n"
4011 "%BP_col_sum_0 = OpFAdd %v4f32 %BP_IC_W_0 %BP_IC_W_1\n"
4012 "%BP_col_sum_1 = OpFAdd %v4f32 %BP_col_sum_0 %BP_IC_W_2\n"
4014 "%BP_clr_transformed = OpFunctionCall %v4f32 %test_code %BP_col_sum_1\n"
4016 "OpStore %BP_out_color %BP_clr_transformed\n"
4020 return tcu::StringTemplate(tessEvalBoilerplate).specialize(fragments);
4023 // Creates geometry-shader assembly by specializing a boilerplate StringTemplate
4024 // on fragments, which must (at least) map "testfun" to an OpFunction definition
4025 // for %test_code that takes and returns a %v4f32. Boilerplate IDs are prefixed
4026 // with "BP_" to avoid collisions with fragments.
4028 // Derived from this GLSL:
4031 // layout(triangles) in;
4032 // layout(triangle_strip, max_vertices = 3) out;
4034 // layout(location = 1) in vec4 in_color[];
4035 // layout(location = 1) out vec4 out_color;
4038 // gl_Position = gl_in[0].gl_Position;
4039 // out_color = test_fun(in_color[0]);
4041 // gl_Position = gl_in[1].gl_Position;
4042 // out_color = test_fun(in_color[1]);
4044 // gl_Position = gl_in[2].gl_Position;
4045 // out_color = test_fun(in_color[2]);
4049 string makeGeometryShaderAssembly(const map<string, string>& fragments)
4051 static const char geometryShaderBoilerplate[] =
4052 "OpCapability Geometry\n"
4053 "OpCapability ClipDistance\n"
4054 "OpCapability CullDistance\n"
4055 "OpMemoryModel Logical GLSL450\n"
4056 "OpEntryPoint Geometry %BP_main \"main\" %BP_out_gl_position %BP_gl_in %BP_out_color %BP_in_color\n"
4057 "OpExecutionMode %BP_main Triangles\n"
4058 "OpExecutionMode %BP_main OutputTriangleStrip\n"
4059 "OpExecutionMode %BP_main OutputVertices 3\n"
4061 "OpName %BP_main \"main\"\n"
4062 "OpName %BP_per_vertex_in \"gl_PerVertex\"\n"
4063 "OpMemberName %BP_per_vertex_in 0 \"gl_Position\"\n"
4064 "OpMemberName %BP_per_vertex_in 1 \"gl_PointSize\"\n"
4065 "OpMemberName %BP_per_vertex_in 2 \"gl_ClipDistance\"\n"
4066 "OpMemberName %BP_per_vertex_in 3 \"gl_CullDistance\"\n"
4067 "OpName %BP_gl_in \"gl_in\"\n"
4068 "OpName %BP_out_color \"out_color\"\n"
4069 "OpName %BP_in_color \"in_color\"\n"
4070 "OpName %test_code \"testfun(vf4;\"\n"
4071 "OpDecorate %BP_out_gl_position BuiltIn Position\n"
4072 "OpMemberDecorate %BP_per_vertex_in 0 BuiltIn Position\n"
4073 "OpMemberDecorate %BP_per_vertex_in 1 BuiltIn PointSize\n"
4074 "OpMemberDecorate %BP_per_vertex_in 2 BuiltIn ClipDistance\n"
4075 "OpMemberDecorate %BP_per_vertex_in 3 BuiltIn CullDistance\n"
4076 "OpDecorate %BP_per_vertex_in Block\n"
4077 "OpDecorate %BP_out_color Location 1\n"
4078 "OpDecorate %BP_in_color Location 1\n"
4079 "${decoration:opt}\n"
4080 SPIRV_ASSEMBLY_TYPES
4081 SPIRV_ASSEMBLY_CONSTANTS
4082 SPIRV_ASSEMBLY_ARRAYS
4083 "%BP_per_vertex_in = OpTypeStruct %v4f32 %f32 %a1f32 %a1f32\n"
4084 "%BP_a3_per_vertex_in = OpTypeArray %BP_per_vertex_in %c_u32_3\n"
4085 "%BP_ip_a3_per_vertex_in = OpTypePointer Input %BP_a3_per_vertex_in\n"
4087 "%BP_gl_in = OpVariable %BP_ip_a3_per_vertex_in Input\n"
4088 "%BP_out_color = OpVariable %op_v4f32 Output\n"
4089 "%BP_in_color = OpVariable %ip_a3v4f32 Input\n"
4090 "%BP_out_gl_position = OpVariable %op_v4f32 Output\n"
4093 "%BP_main = OpFunction %void None %fun\n"
4094 "%BP_label = OpLabel\n"
4095 "%BP_gl_in_0_gl_position = OpAccessChain %ip_v4f32 %BP_gl_in %c_i32_0 %c_i32_0\n"
4096 "%BP_gl_in_1_gl_position = OpAccessChain %ip_v4f32 %BP_gl_in %c_i32_1 %c_i32_0\n"
4097 "%BP_gl_in_2_gl_position = OpAccessChain %ip_v4f32 %BP_gl_in %c_i32_2 %c_i32_0\n"
4099 "%BP_in_position_0 = OpLoad %v4f32 %BP_gl_in_0_gl_position\n"
4100 "%BP_in_position_1 = OpLoad %v4f32 %BP_gl_in_1_gl_position\n"
4101 "%BP_in_position_2 = OpLoad %v4f32 %BP_gl_in_2_gl_position \n"
4103 "%BP_in_color_0_ptr = OpAccessChain %ip_v4f32 %BP_in_color %c_i32_0\n"
4104 "%BP_in_color_1_ptr = OpAccessChain %ip_v4f32 %BP_in_color %c_i32_1\n"
4105 "%BP_in_color_2_ptr = OpAccessChain %ip_v4f32 %BP_in_color %c_i32_2\n"
4107 "%BP_in_color_0 = OpLoad %v4f32 %BP_in_color_0_ptr\n"
4108 "%BP_in_color_1 = OpLoad %v4f32 %BP_in_color_1_ptr\n"
4109 "%BP_in_color_2 = OpLoad %v4f32 %BP_in_color_2_ptr\n"
4111 "%BP_transformed_in_color_0 = OpFunctionCall %v4f32 %test_code %BP_in_color_0\n"
4112 "%BP_transformed_in_color_1 = OpFunctionCall %v4f32 %test_code %BP_in_color_1\n"
4113 "%BP_transformed_in_color_2 = OpFunctionCall %v4f32 %test_code %BP_in_color_2\n"
4116 "OpStore %BP_out_gl_position %BP_in_position_0\n"
4117 "OpStore %BP_out_color %BP_transformed_in_color_0\n"
4120 "OpStore %BP_out_gl_position %BP_in_position_1\n"
4121 "OpStore %BP_out_color %BP_transformed_in_color_1\n"
4124 "OpStore %BP_out_gl_position %BP_in_position_2\n"
4125 "OpStore %BP_out_color %BP_transformed_in_color_2\n"
4132 return tcu::StringTemplate(geometryShaderBoilerplate).specialize(fragments);
4135 // Creates fragment-shader assembly by specializing a boilerplate StringTemplate
4136 // on fragments, which must (at least) map "testfun" to an OpFunction definition
4137 // for %test_code that takes and returns a %v4f32. Boilerplate IDs are prefixed
4138 // with "BP_" to avoid collisions with fragments.
4140 // Derived from this GLSL:
4142 // layout(location = 1) in highp vec4 vtxColor;
4143 // layout(location = 0) out highp vec4 fragColor;
4144 // highp vec4 testfun(highp vec4 x) { return x; }
4145 // void main(void) { fragColor = testfun(vtxColor); }
4147 // with modifications including passing vtxColor by value and ripping out
4148 // testfun() definition.
4149 string makeFragmentShaderAssembly(const map<string, string>& fragments)
4151 static const char fragmentShaderBoilerplate[] =
4152 "OpCapability Shader\n"
4153 "OpMemoryModel Logical GLSL450\n"
4154 "OpEntryPoint Fragment %BP_main \"main\" %BP_vtxColor %BP_fragColor\n"
4155 "OpExecutionMode %BP_main OriginUpperLeft\n"
4157 "OpName %BP_main \"main\"\n"
4158 "OpName %BP_fragColor \"fragColor\"\n"
4159 "OpName %BP_vtxColor \"vtxColor\"\n"
4160 "OpName %test_code \"testfun(vf4;\"\n"
4161 "OpDecorate %BP_fragColor Location 0\n"
4162 "OpDecorate %BP_vtxColor Location 1\n"
4163 "${decoration:opt}\n"
4164 SPIRV_ASSEMBLY_TYPES
4165 SPIRV_ASSEMBLY_CONSTANTS
4166 SPIRV_ASSEMBLY_ARRAYS
4167 "%BP_fragColor = OpVariable %op_v4f32 Output\n"
4168 "%BP_vtxColor = OpVariable %ip_v4f32 Input\n"
4170 "%BP_main = OpFunction %void None %fun\n"
4171 "%BP_label_main = OpLabel\n"
4172 "%BP_tmp1 = OpLoad %v4f32 %BP_vtxColor\n"
4173 "%BP_tmp2 = OpFunctionCall %v4f32 %test_code %BP_tmp1\n"
4174 "OpStore %BP_fragColor %BP_tmp2\n"
4178 return tcu::StringTemplate(fragmentShaderBoilerplate).specialize(fragments);
4181 // Creates fragments that specialize into a simple pass-through shader (of any kind).
4182 map<string, string> passthruFragments(void)
4184 map<string, string> fragments;
4185 fragments["testfun"] =
4186 // A %test_code function that returns its argument unchanged.
4187 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
4188 "%param1 = OpFunctionParameter %v4f32\n"
4189 "%label_testfun = OpLabel\n"
4190 "OpReturnValue %param1\n"
4195 // Adds shader assembly text to dst.spirvAsmSources for all shader kinds.
4196 // Vertex shader gets custom code from context, the rest are pass-through.
4197 void addShaderCodeCustomVertex(vk::SourceCollections& dst, InstanceContext context)
4199 map<string, string> passthru = passthruFragments();
4200 dst.spirvAsmSources.add("vert") << makeVertexShaderAssembly(context.testCodeFragments);
4201 dst.spirvAsmSources.add("frag") << makeFragmentShaderAssembly(passthru);
4204 // Adds shader assembly text to dst.spirvAsmSources for all shader kinds.
4205 // Tessellation control shader gets custom code from context, the rest are
4207 void addShaderCodeCustomTessControl(vk::SourceCollections& dst, InstanceContext context)
4209 map<string, string> passthru = passthruFragments();
4210 dst.spirvAsmSources.add("vert") << makeVertexShaderAssembly(passthru);
4211 dst.spirvAsmSources.add("tessc") << makeTessControlShaderAssembly(context.testCodeFragments);
4212 dst.spirvAsmSources.add("tesse") << makeTessEvalShaderAssembly(passthru);
4213 dst.spirvAsmSources.add("frag") << makeFragmentShaderAssembly(passthru);
4216 // Adds shader assembly text to dst.spirvAsmSources for all shader kinds.
4217 // Tessellation evaluation shader gets custom code from context, the rest are
4219 void addShaderCodeCustomTessEval(vk::SourceCollections& dst, InstanceContext context)
4221 map<string, string> passthru = passthruFragments();
4222 dst.spirvAsmSources.add("vert") << makeVertexShaderAssembly(passthru);
4223 dst.spirvAsmSources.add("tessc") << makeTessControlShaderAssembly(passthru);
4224 dst.spirvAsmSources.add("tesse") << makeTessEvalShaderAssembly(context.testCodeFragments);
4225 dst.spirvAsmSources.add("frag") << makeFragmentShaderAssembly(passthru);
4228 // Adds shader assembly text to dst.spirvAsmSources for all shader kinds.
4229 // Geometry shader gets custom code from context, the rest are pass-through.
4230 void addShaderCodeCustomGeometry(vk::SourceCollections& dst, InstanceContext context)
4232 map<string, string> passthru = passthruFragments();
4233 dst.spirvAsmSources.add("vert") << makeVertexShaderAssembly(passthru);
4234 dst.spirvAsmSources.add("geom") << makeGeometryShaderAssembly(context.testCodeFragments);
4235 dst.spirvAsmSources.add("frag") << makeFragmentShaderAssembly(passthru);
4238 // Adds shader assembly text to dst.spirvAsmSources for all shader kinds.
4239 // Fragment shader gets custom code from context, the rest are pass-through.
4240 void addShaderCodeCustomFragment(vk::SourceCollections& dst, InstanceContext context)
4242 map<string, string> passthru = passthruFragments();
4243 dst.spirvAsmSources.add("vert") << makeVertexShaderAssembly(passthru);
4244 dst.spirvAsmSources.add("frag") << makeFragmentShaderAssembly(context.testCodeFragments);
4247 void createCombinedModule(vk::SourceCollections& dst, InstanceContext)
4249 // \todo [2015-12-07 awoloszyn] Make tessellation / geometry conditional
4250 // \todo [2015-12-07 awoloszyn] Remove OpName and OpMemberName at some point
4251 dst.spirvAsmSources.add("module") <<
4252 "OpCapability Shader\n"
4253 "OpCapability ClipDistance\n"
4254 "OpCapability CullDistance\n"
4255 "OpCapability Geometry\n"
4256 "OpCapability Tessellation\n"
4257 "OpMemoryModel Logical GLSL450\n"
4259 "OpEntryPoint Vertex %vert_main \"main\" %vert_Position %vert_vtxColor %vert_color %vert_vtxPosition %vert_vertex_id %vert_instance_id\n"
4260 "OpEntryPoint Geometry %geom_main \"main\" %geom_out_gl_position %geom_gl_in %geom_out_color %geom_in_color\n"
4261 "OpEntryPoint TessellationControl %tessc_main \"main\" %tessc_out_color %tessc_gl_InvocationID %tessc_in_color %tessc_out_position %tessc_in_position %tessc_gl_TessLevelOuter %tessc_gl_TessLevelInner\n"
4262 "OpEntryPoint TessellationEvaluation %tesse_main \"main\" %tesse_stream %tesse_gl_tessCoord %tesse_in_position %tesse_out_color %tesse_in_color \n"
4263 "OpEntryPoint Fragment %frag_main \"main\" %frag_vtxColor %frag_fragColor\n"
4265 "OpExecutionMode %geom_main Triangles\n"
4266 "OpExecutionMode %geom_main OutputTriangleStrip\n"
4267 "OpExecutionMode %geom_main OutputVertices 3\n"
4269 "OpExecutionMode %tessc_main OutputVertices 3\n"
4271 "OpExecutionMode %tesse_main Triangles\n"
4273 "OpExecutionMode %frag_main OriginUpperLeft\n"
4275 "OpName %vert_main \"main\"\n"
4276 "OpName %vert_vtxPosition \"vtxPosition\"\n"
4277 "OpName %vert_Position \"position\"\n"
4278 "OpName %vert_vtxColor \"vtxColor\"\n"
4279 "OpName %vert_color \"color\"\n"
4280 "OpName %vert_vertex_id \"gl_VertexIndex\"\n"
4281 "OpName %vert_instance_id \"gl_InstanceIndex\"\n"
4282 "OpName %geom_main \"main\"\n"
4283 "OpName %geom_per_vertex_in \"gl_PerVertex\"\n"
4284 "OpMemberName %geom_per_vertex_in 0 \"gl_Position\"\n"
4285 "OpMemberName %geom_per_vertex_in 1 \"gl_PointSize\"\n"
4286 "OpMemberName %geom_per_vertex_in 2 \"gl_ClipDistance\"\n"
4287 "OpMemberName %geom_per_vertex_in 3 \"gl_CullDistance\"\n"
4288 "OpName %geom_gl_in \"gl_in\"\n"
4289 "OpName %geom_out_color \"out_color\"\n"
4290 "OpName %geom_in_color \"in_color\"\n"
4291 "OpName %tessc_main \"main\"\n"
4292 "OpName %tessc_out_color \"out_color\"\n"
4293 "OpName %tessc_gl_InvocationID \"gl_InvocationID\"\n"
4294 "OpName %tessc_in_color \"in_color\"\n"
4295 "OpName %tessc_out_position \"out_position\"\n"
4296 "OpName %tessc_in_position \"in_position\"\n"
4297 "OpName %tessc_gl_TessLevelOuter \"gl_TessLevelOuter\"\n"
4298 "OpName %tessc_gl_TessLevelInner \"gl_TessLevelInner\"\n"
4299 "OpName %tesse_main \"main\"\n"
4300 "OpName %tesse_per_vertex_out \"gl_PerVertex\"\n"
4301 "OpMemberName %tesse_per_vertex_out 0 \"gl_Position\"\n"
4302 "OpMemberName %tesse_per_vertex_out 1 \"gl_PointSize\"\n"
4303 "OpMemberName %tesse_per_vertex_out 2 \"gl_ClipDistance\"\n"
4304 "OpMemberName %tesse_per_vertex_out 3 \"gl_CullDistance\"\n"
4305 "OpName %tesse_stream \"\"\n"
4306 "OpName %tesse_gl_tessCoord \"gl_TessCoord\"\n"
4307 "OpName %tesse_in_position \"in_position\"\n"
4308 "OpName %tesse_out_color \"out_color\"\n"
4309 "OpName %tesse_in_color \"in_color\"\n"
4310 "OpName %frag_main \"main\"\n"
4311 "OpName %frag_fragColor \"fragColor\"\n"
4312 "OpName %frag_vtxColor \"vtxColor\"\n"
4314 "; Vertex decorations\n"
4315 "OpDecorate %vert_vtxPosition Location 2\n"
4316 "OpDecorate %vert_Position Location 0\n"
4317 "OpDecorate %vert_vtxColor Location 1\n"
4318 "OpDecorate %vert_color Location 1\n"
4319 "OpDecorate %vert_vertex_id BuiltIn VertexIndex\n"
4320 "OpDecorate %vert_instance_id BuiltIn InstanceIndex\n"
4322 "; Geometry decorations\n"
4323 "OpDecorate %geom_out_gl_position BuiltIn Position\n"
4324 "OpMemberDecorate %geom_per_vertex_in 0 BuiltIn Position\n"
4325 "OpMemberDecorate %geom_per_vertex_in 1 BuiltIn PointSize\n"
4326 "OpMemberDecorate %geom_per_vertex_in 2 BuiltIn ClipDistance\n"
4327 "OpMemberDecorate %geom_per_vertex_in 3 BuiltIn CullDistance\n"
4328 "OpDecorate %geom_per_vertex_in Block\n"
4329 "OpDecorate %geom_out_color Location 1\n"
4330 "OpDecorate %geom_in_color Location 1\n"
4332 "; Tessellation Control decorations\n"
4333 "OpDecorate %tessc_out_color Location 1\n"
4334 "OpDecorate %tessc_gl_InvocationID BuiltIn InvocationId\n"
4335 "OpDecorate %tessc_in_color Location 1\n"
4336 "OpDecorate %tessc_out_position Location 2\n"
4337 "OpDecorate %tessc_in_position Location 2\n"
4338 "OpDecorate %tessc_gl_TessLevelOuter Patch\n"
4339 "OpDecorate %tessc_gl_TessLevelOuter BuiltIn TessLevelOuter\n"
4340 "OpDecorate %tessc_gl_TessLevelInner Patch\n"
4341 "OpDecorate %tessc_gl_TessLevelInner BuiltIn TessLevelInner\n"
4343 "; Tessellation Evaluation decorations\n"
4344 "OpMemberDecorate %tesse_per_vertex_out 0 BuiltIn Position\n"
4345 "OpMemberDecorate %tesse_per_vertex_out 1 BuiltIn PointSize\n"
4346 "OpMemberDecorate %tesse_per_vertex_out 2 BuiltIn ClipDistance\n"
4347 "OpMemberDecorate %tesse_per_vertex_out 3 BuiltIn CullDistance\n"
4348 "OpDecorate %tesse_per_vertex_out Block\n"
4349 "OpDecorate %tesse_gl_tessCoord BuiltIn TessCoord\n"
4350 "OpDecorate %tesse_in_position Location 2\n"
4351 "OpDecorate %tesse_out_color Location 1\n"
4352 "OpDecorate %tesse_in_color Location 1\n"
4354 "; Fragment decorations\n"
4355 "OpDecorate %frag_fragColor Location 0\n"
4356 "OpDecorate %frag_vtxColor Location 1\n"
4358 SPIRV_ASSEMBLY_TYPES
4359 SPIRV_ASSEMBLY_CONSTANTS
4360 SPIRV_ASSEMBLY_ARRAYS
4362 "; Vertex Variables\n"
4363 "%vert_vtxPosition = OpVariable %op_v4f32 Output\n"
4364 "%vert_Position = OpVariable %ip_v4f32 Input\n"
4365 "%vert_vtxColor = OpVariable %op_v4f32 Output\n"
4366 "%vert_color = OpVariable %ip_v4f32 Input\n"
4367 "%vert_vertex_id = OpVariable %ip_i32 Input\n"
4368 "%vert_instance_id = OpVariable %ip_i32 Input\n"
4370 "; Geometry Variables\n"
4371 "%geom_per_vertex_in = OpTypeStruct %v4f32 %f32 %a1f32 %a1f32\n"
4372 "%geom_a3_per_vertex_in = OpTypeArray %geom_per_vertex_in %c_u32_3\n"
4373 "%geom_ip_a3_per_vertex_in = OpTypePointer Input %geom_a3_per_vertex_in\n"
4374 "%geom_gl_in = OpVariable %geom_ip_a3_per_vertex_in Input\n"
4375 "%geom_out_color = OpVariable %op_v4f32 Output\n"
4376 "%geom_in_color = OpVariable %ip_a3v4f32 Input\n"
4377 "%geom_out_gl_position = OpVariable %op_v4f32 Output\n"
4379 "; Tessellation Control Variables\n"
4380 "%tessc_out_color = OpVariable %op_a3v4f32 Output\n"
4381 "%tessc_gl_InvocationID = OpVariable %ip_i32 Input\n"
4382 "%tessc_in_color = OpVariable %ip_a32v4f32 Input\n"
4383 "%tessc_out_position = OpVariable %op_a3v4f32 Output\n"
4384 "%tessc_in_position = OpVariable %ip_a32v4f32 Input\n"
4385 "%tessc_gl_TessLevelOuter = OpVariable %op_a4f32 Output\n"
4386 "%tessc_gl_TessLevelInner = OpVariable %op_a2f32 Output\n"
4388 "; Tessellation Evaluation Decorations\n"
4389 "%tesse_per_vertex_out = OpTypeStruct %v4f32 %f32 %a1f32 %a1f32\n"
4390 "%tesse_op_per_vertex_out = OpTypePointer Output %tesse_per_vertex_out\n"
4391 "%tesse_stream = OpVariable %tesse_op_per_vertex_out Output\n"
4392 "%tesse_gl_tessCoord = OpVariable %ip_v3f32 Input\n"
4393 "%tesse_in_position = OpVariable %ip_a32v4f32 Input\n"
4394 "%tesse_out_color = OpVariable %op_v4f32 Output\n"
4395 "%tesse_in_color = OpVariable %ip_a32v4f32 Input\n"
4397 "; Fragment Variables\n"
4398 "%frag_fragColor = OpVariable %op_v4f32 Output\n"
4399 "%frag_vtxColor = OpVariable %ip_v4f32 Input\n"
4402 "%vert_main = OpFunction %void None %fun\n"
4403 "%vert_label = OpLabel\n"
4404 "%vert_tmp_position = OpLoad %v4f32 %vert_Position\n"
4405 "OpStore %vert_vtxPosition %vert_tmp_position\n"
4406 "%vert_tmp_color = OpLoad %v4f32 %vert_color\n"
4407 "OpStore %vert_vtxColor %vert_tmp_color\n"
4411 "; Geometry Entry\n"
4412 "%geom_main = OpFunction %void None %fun\n"
4413 "%geom_label = OpLabel\n"
4414 "%geom_gl_in_0_gl_position = OpAccessChain %ip_v4f32 %geom_gl_in %c_i32_0 %c_i32_0\n"
4415 "%geom_gl_in_1_gl_position = OpAccessChain %ip_v4f32 %geom_gl_in %c_i32_1 %c_i32_0\n"
4416 "%geom_gl_in_2_gl_position = OpAccessChain %ip_v4f32 %geom_gl_in %c_i32_2 %c_i32_0\n"
4417 "%geom_in_position_0 = OpLoad %v4f32 %geom_gl_in_0_gl_position\n"
4418 "%geom_in_position_1 = OpLoad %v4f32 %geom_gl_in_1_gl_position\n"
4419 "%geom_in_position_2 = OpLoad %v4f32 %geom_gl_in_2_gl_position \n"
4420 "%geom_in_color_0_ptr = OpAccessChain %ip_v4f32 %geom_in_color %c_i32_0\n"
4421 "%geom_in_color_1_ptr = OpAccessChain %ip_v4f32 %geom_in_color %c_i32_1\n"
4422 "%geom_in_color_2_ptr = OpAccessChain %ip_v4f32 %geom_in_color %c_i32_2\n"
4423 "%geom_in_color_0 = OpLoad %v4f32 %geom_in_color_0_ptr\n"
4424 "%geom_in_color_1 = OpLoad %v4f32 %geom_in_color_1_ptr\n"
4425 "%geom_in_color_2 = OpLoad %v4f32 %geom_in_color_2_ptr\n"
4426 "OpStore %geom_out_gl_position %geom_in_position_0\n"
4427 "OpStore %geom_out_color %geom_in_color_0\n"
4429 "OpStore %geom_out_gl_position %geom_in_position_1\n"
4430 "OpStore %geom_out_color %geom_in_color_1\n"
4432 "OpStore %geom_out_gl_position %geom_in_position_2\n"
4433 "OpStore %geom_out_color %geom_in_color_2\n"
4439 "; Tessellation Control Entry\n"
4440 "%tessc_main = OpFunction %void None %fun\n"
4441 "%tessc_label = OpLabel\n"
4442 "%tessc_invocation_id = OpLoad %i32 %tessc_gl_InvocationID\n"
4443 "%tessc_in_color_ptr = OpAccessChain %ip_v4f32 %tessc_in_color %tessc_invocation_id\n"
4444 "%tessc_in_position_ptr = OpAccessChain %ip_v4f32 %tessc_in_position %tessc_invocation_id\n"
4445 "%tessc_in_color_val = OpLoad %v4f32 %tessc_in_color_ptr\n"
4446 "%tessc_in_position_val = OpLoad %v4f32 %tessc_in_position_ptr\n"
4447 "%tessc_out_color_ptr = OpAccessChain %op_v4f32 %tessc_out_color %tessc_invocation_id\n"
4448 "%tessc_out_position_ptr = OpAccessChain %op_v4f32 %tessc_out_position %tessc_invocation_id\n"
4449 "OpStore %tessc_out_color_ptr %tessc_in_color_val\n"
4450 "OpStore %tessc_out_position_ptr %tessc_in_position_val\n"
4451 "%tessc_is_first_invocation = OpIEqual %bool %tessc_invocation_id %c_i32_0\n"
4452 "OpSelectionMerge %tessc_merge_label None\n"
4453 "OpBranchConditional %tessc_is_first_invocation %tessc_first_invocation %tessc_merge_label\n"
4454 "%tessc_first_invocation = OpLabel\n"
4455 "%tessc_tess_outer_0 = OpAccessChain %op_f32 %tessc_gl_TessLevelOuter %c_i32_0\n"
4456 "%tessc_tess_outer_1 = OpAccessChain %op_f32 %tessc_gl_TessLevelOuter %c_i32_1\n"
4457 "%tessc_tess_outer_2 = OpAccessChain %op_f32 %tessc_gl_TessLevelOuter %c_i32_2\n"
4458 "%tessc_tess_inner = OpAccessChain %op_f32 %tessc_gl_TessLevelInner %c_i32_0\n"
4459 "OpStore %tessc_tess_outer_0 %c_f32_1\n"
4460 "OpStore %tessc_tess_outer_1 %c_f32_1\n"
4461 "OpStore %tessc_tess_outer_2 %c_f32_1\n"
4462 "OpStore %tessc_tess_inner %c_f32_1\n"
4463 "OpBranch %tessc_merge_label\n"
4464 "%tessc_merge_label = OpLabel\n"
4468 "; Tessellation Evaluation Entry\n"
4469 "%tesse_main = OpFunction %void None %fun\n"
4470 "%tesse_label = OpLabel\n"
4471 "%tesse_tc_0_ptr = OpAccessChain %ip_f32 %tesse_gl_tessCoord %c_u32_0\n"
4472 "%tesse_tc_1_ptr = OpAccessChain %ip_f32 %tesse_gl_tessCoord %c_u32_1\n"
4473 "%tesse_tc_2_ptr = OpAccessChain %ip_f32 %tesse_gl_tessCoord %c_u32_2\n"
4474 "%tesse_tc_0 = OpLoad %f32 %tesse_tc_0_ptr\n"
4475 "%tesse_tc_1 = OpLoad %f32 %tesse_tc_1_ptr\n"
4476 "%tesse_tc_2 = OpLoad %f32 %tesse_tc_2_ptr\n"
4477 "%tesse_in_pos_0_ptr = OpAccessChain %ip_v4f32 %tesse_in_position %c_i32_0\n"
4478 "%tesse_in_pos_1_ptr = OpAccessChain %ip_v4f32 %tesse_in_position %c_i32_1\n"
4479 "%tesse_in_pos_2_ptr = OpAccessChain %ip_v4f32 %tesse_in_position %c_i32_2\n"
4480 "%tesse_in_pos_0 = OpLoad %v4f32 %tesse_in_pos_0_ptr\n"
4481 "%tesse_in_pos_1 = OpLoad %v4f32 %tesse_in_pos_1_ptr\n"
4482 "%tesse_in_pos_2 = OpLoad %v4f32 %tesse_in_pos_2_ptr\n"
4483 "%tesse_in_pos_0_weighted = OpVectorTimesScalar %v4f32 %tesse_tc_0 %tesse_in_pos_0\n"
4484 "%tesse_in_pos_1_weighted = OpVectorTimesScalar %v4f32 %tesse_tc_1 %tesse_in_pos_1\n"
4485 "%tesse_in_pos_2_weighted = OpVectorTimesScalar %v4f32 %tesse_tc_2 %tesse_in_pos_2\n"
4486 "%tesse_out_pos_ptr = OpAccessChain %op_v4f32 %tesse_stream %c_i32_0\n"
4487 "%tesse_in_pos_0_plus_pos_1 = OpFAdd %v4f32 %tesse_in_pos_0_weighted %tesse_in_pos_1_weighted\n"
4488 "%tesse_computed_out = OpFAdd %v4f32 %tesse_in_pos_0_plus_pos_1 %tesse_in_pos_2_weighted\n"
4489 "OpStore %tesse_out_pos_ptr %tesse_computed_out\n"
4490 "%tesse_in_clr_0_ptr = OpAccessChain %ip_v4f32 %tesse_in_color %c_i32_0\n"
4491 "%tesse_in_clr_1_ptr = OpAccessChain %ip_v4f32 %tesse_in_color %c_i32_1\n"
4492 "%tesse_in_clr_2_ptr = OpAccessChain %ip_v4f32 %tesse_in_color %c_i32_2\n"
4493 "%tesse_in_clr_0 = OpLoad %v4f32 %tesse_in_clr_0_ptr\n"
4494 "%tesse_in_clr_1 = OpLoad %v4f32 %tesse_in_clr_1_ptr\n"
4495 "%tesse_in_clr_2 = OpLoad %v4f32 %tesse_in_clr_2_ptr\n"
4496 "%tesse_in_clr_0_weighted = OpVectorTimesScalar %v4f32 %tesse_tc_0 %tesse_in_clr_0\n"
4497 "%tesse_in_clr_1_weighted = OpVectorTimesScalar %v4f32 %tesse_tc_1 %tesse_in_clr_1\n"
4498 "%tesse_in_clr_2_weighted = OpVectorTimesScalar %v4f32 %tesse_tc_2 %tesse_in_clr_2\n"
4499 "%tesse_in_clr_0_plus_col_1 = OpFAdd %v4f32 %tesse_in_clr_0_weighted %tesse_in_clr_1_weighted\n"
4500 "%tesse_computed_clr = OpFAdd %v4f32 %tesse_in_clr_0_plus_col_1 %tesse_in_clr_2_weighted\n"
4501 "OpStore %tesse_out_color %tesse_computed_clr\n"
4505 "; Fragment Entry\n"
4506 "%frag_main = OpFunction %void None %fun\n"
4507 "%frag_label_main = OpLabel\n"
4508 "%frag_tmp1 = OpLoad %v4f32 %frag_vtxColor\n"
4509 "OpStore %frag_fragColor %frag_tmp1\n"
4514 // This has two shaders of each stage. The first
4515 // is a passthrough, the second inverts the color.
4516 void createMultipleEntries(vk::SourceCollections& dst, InstanceContext)
4518 dst.spirvAsmSources.add("vert") <<
4519 // This module contains 2 vertex shaders. One that is a passthrough
4520 // and a second that inverts the color of the output (1.0 - color).
4521 "OpCapability Shader\n"
4522 "OpMemoryModel Logical GLSL450\n"
4523 "OpEntryPoint Vertex %main \"vert1\" %Position %vtxColor %color %vtxPosition %vertex_id %instance_id\n"
4524 "OpEntryPoint Vertex %main2 \"vert2\" %Position %vtxColor %color %vtxPosition %vertex_id %instance_id\n"
4526 "OpName %main \"vert1\"\n"
4527 "OpName %main2 \"vert2\"\n"
4528 "OpName %vtxPosition \"vtxPosition\"\n"
4529 "OpName %Position \"position\"\n"
4530 "OpName %vtxColor \"vtxColor\"\n"
4531 "OpName %color \"color\"\n"
4532 "OpName %vertex_id \"gl_VertexIndex\"\n"
4533 "OpName %instance_id \"gl_InstanceIndex\"\n"
4535 "OpDecorate %vtxPosition Location 2\n"
4536 "OpDecorate %Position Location 0\n"
4537 "OpDecorate %vtxColor Location 1\n"
4538 "OpDecorate %color Location 1\n"
4539 "OpDecorate %vertex_id BuiltIn VertexIndex\n"
4540 "OpDecorate %instance_id BuiltIn InstanceIndex\n"
4541 SPIRV_ASSEMBLY_TYPES
4542 SPIRV_ASSEMBLY_CONSTANTS
4543 SPIRV_ASSEMBLY_ARRAYS
4544 "%cval = OpConstantComposite %v4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_0\n"
4545 "%vtxPosition = OpVariable %op_v4f32 Output\n"
4546 "%Position = OpVariable %ip_v4f32 Input\n"
4547 "%vtxColor = OpVariable %op_v4f32 Output\n"
4548 "%color = OpVariable %ip_v4f32 Input\n"
4549 "%vertex_id = OpVariable %ip_i32 Input\n"
4550 "%instance_id = OpVariable %ip_i32 Input\n"
4552 "%main = OpFunction %void None %fun\n"
4553 "%label = OpLabel\n"
4554 "%tmp_position = OpLoad %v4f32 %Position\n"
4555 "OpStore %vtxPosition %tmp_position\n"
4556 "%tmp_color = OpLoad %v4f32 %color\n"
4557 "OpStore %vtxColor %tmp_color\n"
4561 "%main2 = OpFunction %void None %fun\n"
4562 "%label2 = OpLabel\n"
4563 "%tmp_position2 = OpLoad %v4f32 %Position\n"
4564 "OpStore %vtxPosition %tmp_position2\n"
4565 "%tmp_color2 = OpLoad %v4f32 %color\n"
4566 "%tmp_color3 = OpFSub %v4f32 %cval %tmp_color2\n"
4567 "%tmp_color4 = OpVectorInsertDynamic %v4f32 %tmp_color3 %c_f32_1 %c_i32_3\n"
4568 "OpStore %vtxColor %tmp_color4\n"
4572 dst.spirvAsmSources.add("frag") <<
4573 // This is a single module that contains 2 fragment shaders.
4574 // One that passes color through and the other that inverts the output
4575 // color (1.0 - color).
4576 "OpCapability Shader\n"
4577 "OpMemoryModel Logical GLSL450\n"
4578 "OpEntryPoint Fragment %main \"frag1\" %vtxColor %fragColor\n"
4579 "OpEntryPoint Fragment %main2 \"frag2\" %vtxColor %fragColor\n"
4580 "OpExecutionMode %main OriginUpperLeft\n"
4581 "OpExecutionMode %main2 OriginUpperLeft\n"
4583 "OpName %main \"frag1\"\n"
4584 "OpName %main2 \"frag2\"\n"
4585 "OpName %fragColor \"fragColor\"\n"
4586 "OpName %vtxColor \"vtxColor\"\n"
4587 "OpDecorate %fragColor Location 0\n"
4588 "OpDecorate %vtxColor Location 1\n"
4589 SPIRV_ASSEMBLY_TYPES
4590 SPIRV_ASSEMBLY_CONSTANTS
4591 SPIRV_ASSEMBLY_ARRAYS
4592 "%cval = OpConstantComposite %v4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_0\n"
4593 "%fragColor = OpVariable %op_v4f32 Output\n"
4594 "%vtxColor = OpVariable %ip_v4f32 Input\n"
4596 "%main = OpFunction %void None %fun\n"
4597 "%label_main = OpLabel\n"
4598 "%tmp1 = OpLoad %v4f32 %vtxColor\n"
4599 "OpStore %fragColor %tmp1\n"
4603 "%main2 = OpFunction %void None %fun\n"
4604 "%label_main2 = OpLabel\n"
4605 "%tmp2 = OpLoad %v4f32 %vtxColor\n"
4606 "%tmp3 = OpFSub %v4f32 %cval %tmp2\n"
4607 "%tmp4 = OpVectorInsertDynamic %v4f32 %tmp3 %c_f32_1 %c_i32_3\n"
4608 "OpStore %fragColor %tmp4\n"
4612 dst.spirvAsmSources.add("geom") <<
4613 "OpCapability Geometry\n"
4614 "OpCapability ClipDistance\n"
4615 "OpCapability CullDistance\n"
4616 "OpMemoryModel Logical GLSL450\n"
4617 "OpEntryPoint Geometry %geom1_main \"geom1\" %out_gl_position %gl_in %out_color %in_color\n"
4618 "OpEntryPoint Geometry %geom2_main \"geom2\" %out_gl_position %gl_in %out_color %in_color\n"
4619 "OpExecutionMode %geom1_main Triangles\n"
4620 "OpExecutionMode %geom2_main Triangles\n"
4621 "OpExecutionMode %geom1_main OutputTriangleStrip\n"
4622 "OpExecutionMode %geom2_main OutputTriangleStrip\n"
4623 "OpExecutionMode %geom1_main OutputVertices 3\n"
4624 "OpExecutionMode %geom2_main OutputVertices 3\n"
4625 "OpName %geom1_main \"geom1\"\n"
4626 "OpName %geom2_main \"geom2\"\n"
4627 "OpName %per_vertex_in \"gl_PerVertex\"\n"
4628 "OpMemberName %per_vertex_in 0 \"gl_Position\"\n"
4629 "OpMemberName %per_vertex_in 1 \"gl_PointSize\"\n"
4630 "OpMemberName %per_vertex_in 2 \"gl_ClipDistance\"\n"
4631 "OpMemberName %per_vertex_in 3 \"gl_CullDistance\"\n"
4632 "OpName %gl_in \"gl_in\"\n"
4633 "OpName %out_color \"out_color\"\n"
4634 "OpName %in_color \"in_color\"\n"
4635 "OpDecorate %out_gl_position BuiltIn Position\n"
4636 "OpMemberDecorate %per_vertex_in 0 BuiltIn Position\n"
4637 "OpMemberDecorate %per_vertex_in 1 BuiltIn PointSize\n"
4638 "OpMemberDecorate %per_vertex_in 2 BuiltIn ClipDistance\n"
4639 "OpMemberDecorate %per_vertex_in 3 BuiltIn CullDistance\n"
4640 "OpDecorate %per_vertex_in Block\n"
4641 "OpDecorate %out_color Location 1\n"
4642 "OpDecorate %in_color Location 1\n"
4643 SPIRV_ASSEMBLY_TYPES
4644 SPIRV_ASSEMBLY_CONSTANTS
4645 SPIRV_ASSEMBLY_ARRAYS
4646 "%cval = OpConstantComposite %v4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_0\n"
4647 "%per_vertex_in = OpTypeStruct %v4f32 %f32 %a1f32 %a1f32\n"
4648 "%a3_per_vertex_in = OpTypeArray %per_vertex_in %c_u32_3\n"
4649 "%ip_a3_per_vertex_in = OpTypePointer Input %a3_per_vertex_in\n"
4650 "%gl_in = OpVariable %ip_a3_per_vertex_in Input\n"
4651 "%out_color = OpVariable %op_v4f32 Output\n"
4652 "%in_color = OpVariable %ip_a3v4f32 Input\n"
4653 "%out_gl_position = OpVariable %op_v4f32 Output\n"
4655 "%geom1_main = OpFunction %void None %fun\n"
4656 "%geom1_label = OpLabel\n"
4657 "%geom1_gl_in_0_gl_position = OpAccessChain %ip_v4f32 %gl_in %c_i32_0 %c_i32_0\n"
4658 "%geom1_gl_in_1_gl_position = OpAccessChain %ip_v4f32 %gl_in %c_i32_1 %c_i32_0\n"
4659 "%geom1_gl_in_2_gl_position = OpAccessChain %ip_v4f32 %gl_in %c_i32_2 %c_i32_0\n"
4660 "%geom1_in_position_0 = OpLoad %v4f32 %geom1_gl_in_0_gl_position\n"
4661 "%geom1_in_position_1 = OpLoad %v4f32 %geom1_gl_in_1_gl_position\n"
4662 "%geom1_in_position_2 = OpLoad %v4f32 %geom1_gl_in_2_gl_position \n"
4663 "%geom1_in_color_0_ptr = OpAccessChain %ip_v4f32 %in_color %c_i32_0\n"
4664 "%geom1_in_color_1_ptr = OpAccessChain %ip_v4f32 %in_color %c_i32_1\n"
4665 "%geom1_in_color_2_ptr = OpAccessChain %ip_v4f32 %in_color %c_i32_2\n"
4666 "%geom1_in_color_0 = OpLoad %v4f32 %geom1_in_color_0_ptr\n"
4667 "%geom1_in_color_1 = OpLoad %v4f32 %geom1_in_color_1_ptr\n"
4668 "%geom1_in_color_2 = OpLoad %v4f32 %geom1_in_color_2_ptr\n"
4669 "OpStore %out_gl_position %geom1_in_position_0\n"
4670 "OpStore %out_color %geom1_in_color_0\n"
4672 "OpStore %out_gl_position %geom1_in_position_1\n"
4673 "OpStore %out_color %geom1_in_color_1\n"
4675 "OpStore %out_gl_position %geom1_in_position_2\n"
4676 "OpStore %out_color %geom1_in_color_2\n"
4682 "%geom2_main = OpFunction %void None %fun\n"
4683 "%geom2_label = OpLabel\n"
4684 "%geom2_gl_in_0_gl_position = OpAccessChain %ip_v4f32 %gl_in %c_i32_0 %c_i32_0\n"
4685 "%geom2_gl_in_1_gl_position = OpAccessChain %ip_v4f32 %gl_in %c_i32_1 %c_i32_0\n"
4686 "%geom2_gl_in_2_gl_position = OpAccessChain %ip_v4f32 %gl_in %c_i32_2 %c_i32_0\n"
4687 "%geom2_in_position_0 = OpLoad %v4f32 %geom2_gl_in_0_gl_position\n"
4688 "%geom2_in_position_1 = OpLoad %v4f32 %geom2_gl_in_1_gl_position\n"
4689 "%geom2_in_position_2 = OpLoad %v4f32 %geom2_gl_in_2_gl_position \n"
4690 "%geom2_in_color_0_ptr = OpAccessChain %ip_v4f32 %in_color %c_i32_0\n"
4691 "%geom2_in_color_1_ptr = OpAccessChain %ip_v4f32 %in_color %c_i32_1\n"
4692 "%geom2_in_color_2_ptr = OpAccessChain %ip_v4f32 %in_color %c_i32_2\n"
4693 "%geom2_in_color_0 = OpLoad %v4f32 %geom2_in_color_0_ptr\n"
4694 "%geom2_in_color_1 = OpLoad %v4f32 %geom2_in_color_1_ptr\n"
4695 "%geom2_in_color_2 = OpLoad %v4f32 %geom2_in_color_2_ptr\n"
4696 "%geom2_transformed_in_color_0 = OpFSub %v4f32 %cval %geom2_in_color_0\n"
4697 "%geom2_transformed_in_color_1 = OpFSub %v4f32 %cval %geom2_in_color_1\n"
4698 "%geom2_transformed_in_color_2 = OpFSub %v4f32 %cval %geom2_in_color_2\n"
4699 "%geom2_transformed_in_color_0_a = OpVectorInsertDynamic %v4f32 %geom2_transformed_in_color_0 %c_f32_1 %c_i32_3\n"
4700 "%geom2_transformed_in_color_1_a = OpVectorInsertDynamic %v4f32 %geom2_transformed_in_color_1 %c_f32_1 %c_i32_3\n"
4701 "%geom2_transformed_in_color_2_a = OpVectorInsertDynamic %v4f32 %geom2_transformed_in_color_2 %c_f32_1 %c_i32_3\n"
4702 "OpStore %out_gl_position %geom2_in_position_0\n"
4703 "OpStore %out_color %geom2_transformed_in_color_0_a\n"
4705 "OpStore %out_gl_position %geom2_in_position_1\n"
4706 "OpStore %out_color %geom2_transformed_in_color_1_a\n"
4708 "OpStore %out_gl_position %geom2_in_position_2\n"
4709 "OpStore %out_color %geom2_transformed_in_color_2_a\n"
4715 dst.spirvAsmSources.add("tessc") <<
4716 "OpCapability Tessellation\n"
4717 "OpMemoryModel Logical GLSL450\n"
4718 "OpEntryPoint TessellationControl %tessc1_main \"tessc1\" %out_color %gl_InvocationID %in_color %out_position %in_position %gl_TessLevelOuter %gl_TessLevelInner\n"
4719 "OpEntryPoint TessellationControl %tessc2_main \"tessc2\" %out_color %gl_InvocationID %in_color %out_position %in_position %gl_TessLevelOuter %gl_TessLevelInner\n"
4720 "OpExecutionMode %tessc1_main OutputVertices 3\n"
4721 "OpExecutionMode %tessc2_main OutputVertices 3\n"
4722 "OpName %tessc1_main \"tessc1\"\n"
4723 "OpName %tessc2_main \"tessc2\"\n"
4724 "OpName %out_color \"out_color\"\n"
4725 "OpName %gl_InvocationID \"gl_InvocationID\"\n"
4726 "OpName %in_color \"in_color\"\n"
4727 "OpName %out_position \"out_position\"\n"
4728 "OpName %in_position \"in_position\"\n"
4729 "OpName %gl_TessLevelOuter \"gl_TessLevelOuter\"\n"
4730 "OpName %gl_TessLevelInner \"gl_TessLevelInner\"\n"
4731 "OpDecorate %out_color Location 1\n"
4732 "OpDecorate %gl_InvocationID BuiltIn InvocationId\n"
4733 "OpDecorate %in_color Location 1\n"
4734 "OpDecorate %out_position Location 2\n"
4735 "OpDecorate %in_position Location 2\n"
4736 "OpDecorate %gl_TessLevelOuter Patch\n"
4737 "OpDecorate %gl_TessLevelOuter BuiltIn TessLevelOuter\n"
4738 "OpDecorate %gl_TessLevelInner Patch\n"
4739 "OpDecorate %gl_TessLevelInner BuiltIn TessLevelInner\n"
4740 SPIRV_ASSEMBLY_TYPES
4741 SPIRV_ASSEMBLY_CONSTANTS
4742 SPIRV_ASSEMBLY_ARRAYS
4743 "%cval = OpConstantComposite %v4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_0\n"
4744 "%out_color = OpVariable %op_a3v4f32 Output\n"
4745 "%gl_InvocationID = OpVariable %ip_i32 Input\n"
4746 "%in_color = OpVariable %ip_a32v4f32 Input\n"
4747 "%out_position = OpVariable %op_a3v4f32 Output\n"
4748 "%in_position = OpVariable %ip_a32v4f32 Input\n"
4749 "%gl_TessLevelOuter = OpVariable %op_a4f32 Output\n"
4750 "%gl_TessLevelInner = OpVariable %op_a2f32 Output\n"
4752 "%tessc1_main = OpFunction %void None %fun\n"
4753 "%tessc1_label = OpLabel\n"
4754 "%tessc1_invocation_id = OpLoad %i32 %gl_InvocationID\n"
4755 "%tessc1_in_color_ptr = OpAccessChain %ip_v4f32 %in_color %tessc1_invocation_id\n"
4756 "%tessc1_in_position_ptr = OpAccessChain %ip_v4f32 %in_position %tessc1_invocation_id\n"
4757 "%tessc1_in_color_val = OpLoad %v4f32 %tessc1_in_color_ptr\n"
4758 "%tessc1_in_position_val = OpLoad %v4f32 %tessc1_in_position_ptr\n"
4759 "%tessc1_out_color_ptr = OpAccessChain %op_v4f32 %out_color %tessc1_invocation_id\n"
4760 "%tessc1_out_position_ptr = OpAccessChain %op_v4f32 %out_position %tessc1_invocation_id\n"
4761 "OpStore %tessc1_out_color_ptr %tessc1_in_color_val\n"
4762 "OpStore %tessc1_out_position_ptr %tessc1_in_position_val\n"
4763 "%tessc1_is_first_invocation = OpIEqual %bool %tessc1_invocation_id %c_i32_0\n"
4764 "OpSelectionMerge %tessc1_merge_label None\n"
4765 "OpBranchConditional %tessc1_is_first_invocation %tessc1_first_invocation %tessc1_merge_label\n"
4766 "%tessc1_first_invocation = OpLabel\n"
4767 "%tessc1_tess_outer_0 = OpAccessChain %op_f32 %gl_TessLevelOuter %c_i32_0\n"
4768 "%tessc1_tess_outer_1 = OpAccessChain %op_f32 %gl_TessLevelOuter %c_i32_1\n"
4769 "%tessc1_tess_outer_2 = OpAccessChain %op_f32 %gl_TessLevelOuter %c_i32_2\n"
4770 "%tessc1_tess_inner = OpAccessChain %op_f32 %gl_TessLevelInner %c_i32_0\n"
4771 "OpStore %tessc1_tess_outer_0 %c_f32_1\n"
4772 "OpStore %tessc1_tess_outer_1 %c_f32_1\n"
4773 "OpStore %tessc1_tess_outer_2 %c_f32_1\n"
4774 "OpStore %tessc1_tess_inner %c_f32_1\n"
4775 "OpBranch %tessc1_merge_label\n"
4776 "%tessc1_merge_label = OpLabel\n"
4780 "%tessc2_main = OpFunction %void None %fun\n"
4781 "%tessc2_label = OpLabel\n"
4782 "%tessc2_invocation_id = OpLoad %i32 %gl_InvocationID\n"
4783 "%tessc2_in_color_ptr = OpAccessChain %ip_v4f32 %in_color %tessc2_invocation_id\n"
4784 "%tessc2_in_position_ptr = OpAccessChain %ip_v4f32 %in_position %tessc2_invocation_id\n"
4785 "%tessc2_in_color_val = OpLoad %v4f32 %tessc2_in_color_ptr\n"
4786 "%tessc2_in_position_val = OpLoad %v4f32 %tessc2_in_position_ptr\n"
4787 "%tessc2_out_color_ptr = OpAccessChain %op_v4f32 %out_color %tessc2_invocation_id\n"
4788 "%tessc2_out_position_ptr = OpAccessChain %op_v4f32 %out_position %tessc2_invocation_id\n"
4789 "%tessc2_transformed_color = OpFSub %v4f32 %cval %tessc2_in_color_val\n"
4790 "%tessc2_transformed_color_a = OpVectorInsertDynamic %v4f32 %tessc2_transformed_color %c_f32_1 %c_i32_3\n"
4791 "OpStore %tessc2_out_color_ptr %tessc2_transformed_color_a\n"
4792 "OpStore %tessc2_out_position_ptr %tessc2_in_position_val\n"
4793 "%tessc2_is_first_invocation = OpIEqual %bool %tessc2_invocation_id %c_i32_0\n"
4794 "OpSelectionMerge %tessc2_merge_label None\n"
4795 "OpBranchConditional %tessc2_is_first_invocation %tessc2_first_invocation %tessc2_merge_label\n"
4796 "%tessc2_first_invocation = OpLabel\n"
4797 "%tessc2_tess_outer_0 = OpAccessChain %op_f32 %gl_TessLevelOuter %c_i32_0\n"
4798 "%tessc2_tess_outer_1 = OpAccessChain %op_f32 %gl_TessLevelOuter %c_i32_1\n"
4799 "%tessc2_tess_outer_2 = OpAccessChain %op_f32 %gl_TessLevelOuter %c_i32_2\n"
4800 "%tessc2_tess_inner = OpAccessChain %op_f32 %gl_TessLevelInner %c_i32_0\n"
4801 "OpStore %tessc2_tess_outer_0 %c_f32_1\n"
4802 "OpStore %tessc2_tess_outer_1 %c_f32_1\n"
4803 "OpStore %tessc2_tess_outer_2 %c_f32_1\n"
4804 "OpStore %tessc2_tess_inner %c_f32_1\n"
4805 "OpBranch %tessc2_merge_label\n"
4806 "%tessc2_merge_label = OpLabel\n"
4810 dst.spirvAsmSources.add("tesse") <<
4811 "OpCapability Tessellation\n"
4812 "OpCapability ClipDistance\n"
4813 "OpCapability CullDistance\n"
4814 "OpMemoryModel Logical GLSL450\n"
4815 "OpEntryPoint TessellationEvaluation %tesse1_main \"tesse1\" %stream %gl_tessCoord %in_position %out_color %in_color \n"
4816 "OpEntryPoint TessellationEvaluation %tesse2_main \"tesse2\" %stream %gl_tessCoord %in_position %out_color %in_color \n"
4817 "OpExecutionMode %tesse1_main Triangles\n"
4818 "OpExecutionMode %tesse2_main Triangles\n"
4819 "OpName %tesse1_main \"tesse1\"\n"
4820 "OpName %tesse2_main \"tesse2\"\n"
4821 "OpName %per_vertex_out \"gl_PerVertex\"\n"
4822 "OpMemberName %per_vertex_out 0 \"gl_Position\"\n"
4823 "OpMemberName %per_vertex_out 1 \"gl_PointSize\"\n"
4824 "OpMemberName %per_vertex_out 2 \"gl_ClipDistance\"\n"
4825 "OpMemberName %per_vertex_out 3 \"gl_CullDistance\"\n"
4826 "OpName %stream \"\"\n"
4827 "OpName %gl_tessCoord \"gl_TessCoord\"\n"
4828 "OpName %in_position \"in_position\"\n"
4829 "OpName %out_color \"out_color\"\n"
4830 "OpName %in_color \"in_color\"\n"
4831 "OpMemberDecorate %per_vertex_out 0 BuiltIn Position\n"
4832 "OpMemberDecorate %per_vertex_out 1 BuiltIn PointSize\n"
4833 "OpMemberDecorate %per_vertex_out 2 BuiltIn ClipDistance\n"
4834 "OpMemberDecorate %per_vertex_out 3 BuiltIn CullDistance\n"
4835 "OpDecorate %per_vertex_out Block\n"
4836 "OpDecorate %gl_tessCoord BuiltIn TessCoord\n"
4837 "OpDecorate %in_position Location 2\n"
4838 "OpDecorate %out_color Location 1\n"
4839 "OpDecorate %in_color Location 1\n"
4840 SPIRV_ASSEMBLY_TYPES
4841 SPIRV_ASSEMBLY_CONSTANTS
4842 SPIRV_ASSEMBLY_ARRAYS
4843 "%cval = OpConstantComposite %v4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_0\n"
4844 "%per_vertex_out = OpTypeStruct %v4f32 %f32 %a1f32 %a1f32\n"
4845 "%op_per_vertex_out = OpTypePointer Output %per_vertex_out\n"
4846 "%stream = OpVariable %op_per_vertex_out Output\n"
4847 "%gl_tessCoord = OpVariable %ip_v3f32 Input\n"
4848 "%in_position = OpVariable %ip_a32v4f32 Input\n"
4849 "%out_color = OpVariable %op_v4f32 Output\n"
4850 "%in_color = OpVariable %ip_a32v4f32 Input\n"
4852 "%tesse1_main = OpFunction %void None %fun\n"
4853 "%tesse1_label = OpLabel\n"
4854 "%tesse1_tc_0_ptr = OpAccessChain %ip_f32 %gl_tessCoord %c_u32_0\n"
4855 "%tesse1_tc_1_ptr = OpAccessChain %ip_f32 %gl_tessCoord %c_u32_1\n"
4856 "%tesse1_tc_2_ptr = OpAccessChain %ip_f32 %gl_tessCoord %c_u32_2\n"
4857 "%tesse1_tc_0 = OpLoad %f32 %tesse1_tc_0_ptr\n"
4858 "%tesse1_tc_1 = OpLoad %f32 %tesse1_tc_1_ptr\n"
4859 "%tesse1_tc_2 = OpLoad %f32 %tesse1_tc_2_ptr\n"
4860 "%tesse1_in_pos_0_ptr = OpAccessChain %ip_v4f32 %in_position %c_i32_0\n"
4861 "%tesse1_in_pos_1_ptr = OpAccessChain %ip_v4f32 %in_position %c_i32_1\n"
4862 "%tesse1_in_pos_2_ptr = OpAccessChain %ip_v4f32 %in_position %c_i32_2\n"
4863 "%tesse1_in_pos_0 = OpLoad %v4f32 %tesse1_in_pos_0_ptr\n"
4864 "%tesse1_in_pos_1 = OpLoad %v4f32 %tesse1_in_pos_1_ptr\n"
4865 "%tesse1_in_pos_2 = OpLoad %v4f32 %tesse1_in_pos_2_ptr\n"
4866 "%tesse1_in_pos_0_weighted = OpVectorTimesScalar %v4f32 %tesse1_tc_0 %tesse1_in_pos_0\n"
4867 "%tesse1_in_pos_1_weighted = OpVectorTimesScalar %v4f32 %tesse1_tc_1 %tesse1_in_pos_1\n"
4868 "%tesse1_in_pos_2_weighted = OpVectorTimesScalar %v4f32 %tesse1_tc_2 %tesse1_in_pos_2\n"
4869 "%tesse1_out_pos_ptr = OpAccessChain %op_v4f32 %stream %c_i32_0\n"
4870 "%tesse1_in_pos_0_plus_pos_1 = OpFAdd %v4f32 %tesse1_in_pos_0_weighted %tesse1_in_pos_1_weighted\n"
4871 "%tesse1_computed_out = OpFAdd %v4f32 %tesse1_in_pos_0_plus_pos_1 %tesse1_in_pos_2_weighted\n"
4872 "OpStore %tesse1_out_pos_ptr %tesse1_computed_out\n"
4873 "%tesse1_in_clr_0_ptr = OpAccessChain %ip_v4f32 %in_color %c_i32_0\n"
4874 "%tesse1_in_clr_1_ptr = OpAccessChain %ip_v4f32 %in_color %c_i32_1\n"
4875 "%tesse1_in_clr_2_ptr = OpAccessChain %ip_v4f32 %in_color %c_i32_2\n"
4876 "%tesse1_in_clr_0 = OpLoad %v4f32 %tesse1_in_clr_0_ptr\n"
4877 "%tesse1_in_clr_1 = OpLoad %v4f32 %tesse1_in_clr_1_ptr\n"
4878 "%tesse1_in_clr_2 = OpLoad %v4f32 %tesse1_in_clr_2_ptr\n"
4879 "%tesse1_in_clr_0_weighted = OpVectorTimesScalar %v4f32 %tesse1_tc_0 %tesse1_in_clr_0\n"
4880 "%tesse1_in_clr_1_weighted = OpVectorTimesScalar %v4f32 %tesse1_tc_1 %tesse1_in_clr_1\n"
4881 "%tesse1_in_clr_2_weighted = OpVectorTimesScalar %v4f32 %tesse1_tc_2 %tesse1_in_clr_2\n"
4882 "%tesse1_in_clr_0_plus_col_1 = OpFAdd %v4f32 %tesse1_in_clr_0_weighted %tesse1_in_clr_1_weighted\n"
4883 "%tesse1_computed_clr = OpFAdd %v4f32 %tesse1_in_clr_0_plus_col_1 %tesse1_in_clr_2_weighted\n"
4884 "OpStore %out_color %tesse1_computed_clr\n"
4888 "%tesse2_main = OpFunction %void None %fun\n"
4889 "%tesse2_label = OpLabel\n"
4890 "%tesse2_tc_0_ptr = OpAccessChain %ip_f32 %gl_tessCoord %c_u32_0\n"
4891 "%tesse2_tc_1_ptr = OpAccessChain %ip_f32 %gl_tessCoord %c_u32_1\n"
4892 "%tesse2_tc_2_ptr = OpAccessChain %ip_f32 %gl_tessCoord %c_u32_2\n"
4893 "%tesse2_tc_0 = OpLoad %f32 %tesse2_tc_0_ptr\n"
4894 "%tesse2_tc_1 = OpLoad %f32 %tesse2_tc_1_ptr\n"
4895 "%tesse2_tc_2 = OpLoad %f32 %tesse2_tc_2_ptr\n"
4896 "%tesse2_in_pos_0_ptr = OpAccessChain %ip_v4f32 %in_position %c_i32_0\n"
4897 "%tesse2_in_pos_1_ptr = OpAccessChain %ip_v4f32 %in_position %c_i32_1\n"
4898 "%tesse2_in_pos_2_ptr = OpAccessChain %ip_v4f32 %in_position %c_i32_2\n"
4899 "%tesse2_in_pos_0 = OpLoad %v4f32 %tesse2_in_pos_0_ptr\n"
4900 "%tesse2_in_pos_1 = OpLoad %v4f32 %tesse2_in_pos_1_ptr\n"
4901 "%tesse2_in_pos_2 = OpLoad %v4f32 %tesse2_in_pos_2_ptr\n"
4902 "%tesse2_in_pos_0_weighted = OpVectorTimesScalar %v4f32 %tesse2_tc_0 %tesse2_in_pos_0\n"
4903 "%tesse2_in_pos_1_weighted = OpVectorTimesScalar %v4f32 %tesse2_tc_1 %tesse2_in_pos_1\n"
4904 "%tesse2_in_pos_2_weighted = OpVectorTimesScalar %v4f32 %tesse2_tc_2 %tesse2_in_pos_2\n"
4905 "%tesse2_out_pos_ptr = OpAccessChain %op_v4f32 %stream %c_i32_0\n"
4906 "%tesse2_in_pos_0_plus_pos_1 = OpFAdd %v4f32 %tesse2_in_pos_0_weighted %tesse2_in_pos_1_weighted\n"
4907 "%tesse2_computed_out = OpFAdd %v4f32 %tesse2_in_pos_0_plus_pos_1 %tesse2_in_pos_2_weighted\n"
4908 "OpStore %tesse2_out_pos_ptr %tesse2_computed_out\n"
4909 "%tesse2_in_clr_0_ptr = OpAccessChain %ip_v4f32 %in_color %c_i32_0\n"
4910 "%tesse2_in_clr_1_ptr = OpAccessChain %ip_v4f32 %in_color %c_i32_1\n"
4911 "%tesse2_in_clr_2_ptr = OpAccessChain %ip_v4f32 %in_color %c_i32_2\n"
4912 "%tesse2_in_clr_0 = OpLoad %v4f32 %tesse2_in_clr_0_ptr\n"
4913 "%tesse2_in_clr_1 = OpLoad %v4f32 %tesse2_in_clr_1_ptr\n"
4914 "%tesse2_in_clr_2 = OpLoad %v4f32 %tesse2_in_clr_2_ptr\n"
4915 "%tesse2_in_clr_0_weighted = OpVectorTimesScalar %v4f32 %tesse2_tc_0 %tesse2_in_clr_0\n"
4916 "%tesse2_in_clr_1_weighted = OpVectorTimesScalar %v4f32 %tesse2_tc_1 %tesse2_in_clr_1\n"
4917 "%tesse2_in_clr_2_weighted = OpVectorTimesScalar %v4f32 %tesse2_tc_2 %tesse2_in_clr_2\n"
4918 "%tesse2_in_clr_0_plus_col_1 = OpFAdd %v4f32 %tesse2_in_clr_0_weighted %tesse2_in_clr_1_weighted\n"
4919 "%tesse2_computed_clr = OpFAdd %v4f32 %tesse2_in_clr_0_plus_col_1 %tesse2_in_clr_2_weighted\n"
4920 "%tesse2_clr_transformed = OpFSub %v4f32 %cval %tesse2_computed_clr\n"
4921 "%tesse2_clr_transformed_a = OpVectorInsertDynamic %v4f32 %tesse2_clr_transformed %c_f32_1 %c_i32_3\n"
4922 "OpStore %out_color %tesse2_clr_transformed_a\n"
4927 // Sets up and runs a Vulkan pipeline, then spot-checks the resulting image.
4928 // Feeds the pipeline a set of colored triangles, which then must occur in the
4929 // rendered image. The surface is cleared before executing the pipeline, so
4930 // whatever the shaders draw can be directly spot-checked.
4931 TestStatus runAndVerifyDefaultPipeline (Context& context, InstanceContext instance)
4933 const VkDevice vkDevice = context.getDevice();
4934 const DeviceInterface& vk = context.getDeviceInterface();
4935 const VkQueue queue = context.getUniversalQueue();
4936 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
4937 const tcu::UVec2 renderSize (256, 256);
4938 vector<ModuleHandleSp> modules;
4939 map<VkShaderStageFlagBits, VkShaderModule> moduleByStage;
4940 const int testSpecificSeed = 31354125;
4941 const int seed = context.getTestContext().getCommandLine().getBaseSeed() ^ testSpecificSeed;
4942 bool supportsGeometry = false;
4943 bool supportsTessellation = false;
4944 bool hasTessellation = false;
4946 const VkPhysicalDeviceFeatures& features = context.getDeviceFeatures();
4947 supportsGeometry = features.geometryShader == VK_TRUE;
4948 supportsTessellation = features.tessellationShader == VK_TRUE;
4949 hasTessellation = (instance.requiredStages & VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT) ||
4950 (instance.requiredStages & VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT);
4952 if (hasTessellation && !supportsTessellation)
4954 throw tcu::NotSupportedError(std::string("Tessellation not supported"));
4957 if ((instance.requiredStages & VK_SHADER_STAGE_GEOMETRY_BIT) &&
4960 throw tcu::NotSupportedError(std::string("Geometry not supported"));
4963 de::Random(seed).shuffle(instance.inputColors, instance.inputColors+4);
4964 de::Random(seed).shuffle(instance.outputColors, instance.outputColors+4);
4965 const Vec4 vertexData[] =
4967 // Upper left corner:
4968 Vec4(-1.0f, -1.0f, 0.0f, 1.0f), instance.inputColors[0].toVec(),
4969 Vec4(-0.5f, -1.0f, 0.0f, 1.0f), instance.inputColors[0].toVec(),
4970 Vec4(-1.0f, -0.5f, 0.0f, 1.0f), instance.inputColors[0].toVec(),
4972 // Upper right corner:
4973 Vec4(+0.5f, -1.0f, 0.0f, 1.0f), instance.inputColors[1].toVec(),
4974 Vec4(+1.0f, -1.0f, 0.0f, 1.0f), instance.inputColors[1].toVec(),
4975 Vec4(+1.0f, -0.5f, 0.0f, 1.0f), instance.inputColors[1].toVec(),
4977 // Lower left corner:
4978 Vec4(-1.0f, +0.5f, 0.0f, 1.0f), instance.inputColors[2].toVec(),
4979 Vec4(-0.5f, +1.0f, 0.0f, 1.0f), instance.inputColors[2].toVec(),
4980 Vec4(-1.0f, +1.0f, 0.0f, 1.0f), instance.inputColors[2].toVec(),
4982 // Lower right corner:
4983 Vec4(+1.0f, +0.5f, 0.0f, 1.0f), instance.inputColors[3].toVec(),
4984 Vec4(+1.0f, +1.0f, 0.0f, 1.0f), instance.inputColors[3].toVec(),
4985 Vec4(+0.5f, +1.0f, 0.0f, 1.0f), instance.inputColors[3].toVec()
4987 const size_t singleVertexDataSize = 2 * sizeof(Vec4);
4988 const size_t vertexCount = sizeof(vertexData) / singleVertexDataSize;
4990 const VkBufferCreateInfo vertexBufferParams =
4992 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
4993 DE_NULL, // const void* pNext;
4994 0u, // VkBufferCreateFlags flags;
4995 (VkDeviceSize)sizeof(vertexData), // VkDeviceSize size;
4996 VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, // VkBufferUsageFlags usage;
4997 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
4998 1u, // deUint32 queueFamilyCount;
4999 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
5001 const Unique<VkBuffer> vertexBuffer (createBuffer(vk, vkDevice, &vertexBufferParams));
5002 const UniquePtr<Allocation> vertexBufferMemory (context.getDefaultAllocator().allocate(getBufferMemoryRequirements(vk, vkDevice, *vertexBuffer), MemoryRequirement::HostVisible));
5004 VK_CHECK(vk.bindBufferMemory(vkDevice, *vertexBuffer, vertexBufferMemory->getMemory(), vertexBufferMemory->getOffset()));
5006 const VkDeviceSize imageSizeBytes = (VkDeviceSize)(sizeof(deUint32)*renderSize.x()*renderSize.y());
5007 const VkBufferCreateInfo readImageBufferParams =
5009 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
5010 DE_NULL, // const void* pNext;
5011 0u, // VkBufferCreateFlags flags;
5012 imageSizeBytes, // VkDeviceSize size;
5013 VK_BUFFER_USAGE_TRANSFER_DST_BIT, // VkBufferUsageFlags usage;
5014 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
5015 1u, // deUint32 queueFamilyCount;
5016 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
5018 const Unique<VkBuffer> readImageBuffer (createBuffer(vk, vkDevice, &readImageBufferParams));
5019 const UniquePtr<Allocation> readImageBufferMemory (context.getDefaultAllocator().allocate(getBufferMemoryRequirements(vk, vkDevice, *readImageBuffer), MemoryRequirement::HostVisible));
5021 VK_CHECK(vk.bindBufferMemory(vkDevice, *readImageBuffer, readImageBufferMemory->getMemory(), readImageBufferMemory->getOffset()));
5023 const VkImageCreateInfo imageParams =
5025 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType;
5026 DE_NULL, // const void* pNext;
5027 0u, // VkImageCreateFlags flags;
5028 VK_IMAGE_TYPE_2D, // VkImageType imageType;
5029 VK_FORMAT_R8G8B8A8_UNORM, // VkFormat format;
5030 { renderSize.x(), renderSize.y(), 1 }, // VkExtent3D extent;
5031 1u, // deUint32 mipLevels;
5032 1u, // deUint32 arraySize;
5033 VK_SAMPLE_COUNT_1_BIT, // deUint32 samples;
5034 VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling;
5035 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT|VK_IMAGE_USAGE_TRANSFER_SRC_BIT, // VkImageUsageFlags usage;
5036 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
5037 1u, // deUint32 queueFamilyCount;
5038 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
5039 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout;
5042 const Unique<VkImage> image (createImage(vk, vkDevice, &imageParams));
5043 const UniquePtr<Allocation> imageMemory (context.getDefaultAllocator().allocate(getImageMemoryRequirements(vk, vkDevice, *image), MemoryRequirement::Any));
5045 VK_CHECK(vk.bindImageMemory(vkDevice, *image, imageMemory->getMemory(), imageMemory->getOffset()));
5047 const VkAttachmentDescription colorAttDesc =
5049 0u, // VkAttachmentDescriptionFlags flags;
5050 VK_FORMAT_R8G8B8A8_UNORM, // VkFormat format;
5051 VK_SAMPLE_COUNT_1_BIT, // deUint32 samples;
5052 VK_ATTACHMENT_LOAD_OP_CLEAR, // VkAttachmentLoadOp loadOp;
5053 VK_ATTACHMENT_STORE_OP_STORE, // VkAttachmentStoreOp storeOp;
5054 VK_ATTACHMENT_LOAD_OP_DONT_CARE, // VkAttachmentLoadOp stencilLoadOp;
5055 VK_ATTACHMENT_STORE_OP_DONT_CARE, // VkAttachmentStoreOp stencilStoreOp;
5056 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout initialLayout;
5057 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout finalLayout;
5059 const VkAttachmentReference colorAttRef =
5061 0u, // deUint32 attachment;
5062 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout layout;
5064 const VkSubpassDescription subpassDesc =
5066 0u, // VkSubpassDescriptionFlags flags;
5067 VK_PIPELINE_BIND_POINT_GRAPHICS, // VkPipelineBindPoint pipelineBindPoint;
5068 0u, // deUint32 inputCount;
5069 DE_NULL, // const VkAttachmentReference* pInputAttachments;
5070 1u, // deUint32 colorCount;
5071 &colorAttRef, // const VkAttachmentReference* pColorAttachments;
5072 DE_NULL, // const VkAttachmentReference* pResolveAttachments;
5073 DE_NULL, // const VkAttachmentReference* pDepthStencilAttachment;
5074 0u, // deUint32 preserveCount;
5075 DE_NULL, // const VkAttachmentReference* pPreserveAttachments;
5078 const VkRenderPassCreateInfo renderPassParams =
5080 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, // VkStructureType sType;
5081 DE_NULL, // const void* pNext;
5082 (VkRenderPassCreateFlags)0,
5083 1u, // deUint32 attachmentCount;
5084 &colorAttDesc, // const VkAttachmentDescription* pAttachments;
5085 1u, // deUint32 subpassCount;
5086 &subpassDesc, // const VkSubpassDescription* pSubpasses;
5087 0u, // deUint32 dependencyCount;
5088 DE_NULL, // const VkSubpassDependency* pDependencies;
5090 const Unique<VkRenderPass> renderPass (createRenderPass(vk, vkDevice, &renderPassParams));
5092 const VkImageViewCreateInfo colorAttViewParams =
5094 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, // VkStructureType sType;
5095 DE_NULL, // const void* pNext;
5096 0u, // VkImageViewCreateFlags flags;
5097 *image, // VkImage image;
5098 VK_IMAGE_VIEW_TYPE_2D, // VkImageViewType viewType;
5099 VK_FORMAT_R8G8B8A8_UNORM, // VkFormat format;
5101 VK_COMPONENT_SWIZZLE_R,
5102 VK_COMPONENT_SWIZZLE_G,
5103 VK_COMPONENT_SWIZZLE_B,
5104 VK_COMPONENT_SWIZZLE_A
5105 }, // VkChannelMapping channels;
5107 VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags aspectMask;
5108 0u, // deUint32 baseMipLevel;
5109 1u, // deUint32 mipLevels;
5110 0u, // deUint32 baseArrayLayer;
5111 1u, // deUint32 arraySize;
5112 }, // VkImageSubresourceRange subresourceRange;
5114 const Unique<VkImageView> colorAttView (createImageView(vk, vkDevice, &colorAttViewParams));
5118 const VkPipelineLayoutCreateInfo pipelineLayoutParams =
5120 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, // VkStructureType sType;
5121 DE_NULL, // const void* pNext;
5122 (VkPipelineLayoutCreateFlags)0,
5123 0u, // deUint32 descriptorSetCount;
5124 DE_NULL, // const VkDescriptorSetLayout* pSetLayouts;
5125 0u, // deUint32 pushConstantRangeCount;
5126 DE_NULL, // const VkPushConstantRange* pPushConstantRanges;
5128 const Unique<VkPipelineLayout> pipelineLayout (createPipelineLayout(vk, vkDevice, &pipelineLayoutParams));
5131 vector<VkPipelineShaderStageCreateInfo> shaderStageParams;
5132 // We need these vectors to make sure that information about specialization constants for each stage can outlive createGraphicsPipeline().
5133 vector<vector<VkSpecializationMapEntry> > specConstantEntries;
5134 vector<VkSpecializationInfo> specializationInfos;
5135 createPipelineShaderStages(vk, vkDevice, instance, context, modules, shaderStageParams);
5137 // And we don't want the reallocation of these vectors to invalidate pointers pointing to their contents.
5138 specConstantEntries.reserve(shaderStageParams.size());
5139 specializationInfos.reserve(shaderStageParams.size());
5141 // Patch the specialization info field in PipelineShaderStageCreateInfos.
5142 for (vector<VkPipelineShaderStageCreateInfo>::iterator stageInfo = shaderStageParams.begin(); stageInfo != shaderStageParams.end(); ++stageInfo)
5144 const StageToSpecConstantMap::const_iterator stageIt = instance.specConstants.find(stageInfo->stage);
5146 if (stageIt != instance.specConstants.end())
5148 const size_t numSpecConstants = stageIt->second.size();
5149 vector<VkSpecializationMapEntry> entries;
5150 VkSpecializationInfo specInfo;
5152 entries.resize(numSpecConstants);
5154 // Only support 32-bit integers as spec constants now. And their constant IDs are numbered sequentially starting from 0.
5155 for (size_t ndx = 0; ndx < numSpecConstants; ++ndx)
5157 entries[ndx].constantID = (deUint32)ndx;
5158 entries[ndx].offset = deUint32(ndx * sizeof(deInt32));
5159 entries[ndx].size = sizeof(deInt32);
5162 specConstantEntries.push_back(entries);
5164 specInfo.mapEntryCount = (deUint32)numSpecConstants;
5165 specInfo.pMapEntries = specConstantEntries.back().data();
5166 specInfo.dataSize = numSpecConstants * sizeof(deInt32);
5167 specInfo.pData = stageIt->second.data();
5168 specializationInfos.push_back(specInfo);
5170 stageInfo->pSpecializationInfo = &specializationInfos.back();
5173 const VkPipelineDepthStencilStateCreateInfo depthStencilParams =
5175 VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO, // VkStructureType sType;
5176 DE_NULL, // const void* pNext;
5177 (VkPipelineDepthStencilStateCreateFlags)0,
5178 DE_FALSE, // deUint32 depthTestEnable;
5179 DE_FALSE, // deUint32 depthWriteEnable;
5180 VK_COMPARE_OP_ALWAYS, // VkCompareOp depthCompareOp;
5181 DE_FALSE, // deUint32 depthBoundsTestEnable;
5182 DE_FALSE, // deUint32 stencilTestEnable;
5184 VK_STENCIL_OP_KEEP, // VkStencilOp stencilFailOp;
5185 VK_STENCIL_OP_KEEP, // VkStencilOp stencilPassOp;
5186 VK_STENCIL_OP_KEEP, // VkStencilOp stencilDepthFailOp;
5187 VK_COMPARE_OP_ALWAYS, // VkCompareOp stencilCompareOp;
5188 0u, // deUint32 stencilCompareMask;
5189 0u, // deUint32 stencilWriteMask;
5190 0u, // deUint32 stencilReference;
5191 }, // VkStencilOpState front;
5193 VK_STENCIL_OP_KEEP, // VkStencilOp stencilFailOp;
5194 VK_STENCIL_OP_KEEP, // VkStencilOp stencilPassOp;
5195 VK_STENCIL_OP_KEEP, // VkStencilOp stencilDepthFailOp;
5196 VK_COMPARE_OP_ALWAYS, // VkCompareOp stencilCompareOp;
5197 0u, // deUint32 stencilCompareMask;
5198 0u, // deUint32 stencilWriteMask;
5199 0u, // deUint32 stencilReference;
5200 }, // VkStencilOpState back;
5201 -1.0f, // float minDepthBounds;
5202 +1.0f, // float maxDepthBounds;
5204 const VkViewport viewport0 =
5206 0.0f, // float originX;
5207 0.0f, // float originY;
5208 (float)renderSize.x(), // float width;
5209 (float)renderSize.y(), // float height;
5210 0.0f, // float minDepth;
5211 1.0f, // float maxDepth;
5213 const VkRect2D scissor0 =
5218 }, // VkOffset2D offset;
5220 renderSize.x(), // deInt32 width;
5221 renderSize.y(), // deInt32 height;
5222 }, // VkExtent2D extent;
5224 const VkPipelineViewportStateCreateInfo viewportParams =
5226 VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO, // VkStructureType sType;
5227 DE_NULL, // const void* pNext;
5228 (VkPipelineViewportStateCreateFlags)0,
5229 1u, // deUint32 viewportCount;
5234 const VkSampleMask sampleMask = ~0u;
5235 const VkPipelineMultisampleStateCreateInfo multisampleParams =
5237 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, // VkStructureType sType;
5238 DE_NULL, // const void* pNext;
5239 (VkPipelineMultisampleStateCreateFlags)0,
5240 VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits rasterSamples;
5241 DE_FALSE, // deUint32 sampleShadingEnable;
5242 0.0f, // float minSampleShading;
5243 &sampleMask, // const VkSampleMask* pSampleMask;
5244 DE_FALSE, // VkBool32 alphaToCoverageEnable;
5245 DE_FALSE, // VkBool32 alphaToOneEnable;
5247 const VkPipelineRasterizationStateCreateInfo rasterParams =
5249 VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO, // VkStructureType sType;
5250 DE_NULL, // const void* pNext;
5251 (VkPipelineRasterizationStateCreateFlags)0,
5252 DE_TRUE, // deUint32 depthClipEnable;
5253 DE_FALSE, // deUint32 rasterizerDiscardEnable;
5254 VK_POLYGON_MODE_FILL, // VkFillMode fillMode;
5255 VK_CULL_MODE_NONE, // VkCullMode cullMode;
5256 VK_FRONT_FACE_COUNTER_CLOCKWISE, // VkFrontFace frontFace;
5257 VK_FALSE, // VkBool32 depthBiasEnable;
5258 0.0f, // float depthBias;
5259 0.0f, // float depthBiasClamp;
5260 0.0f, // float slopeScaledDepthBias;
5261 1.0f, // float lineWidth;
5263 const VkPrimitiveTopology topology = hasTessellation? VK_PRIMITIVE_TOPOLOGY_PATCH_LIST: VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
5264 const VkPipelineInputAssemblyStateCreateInfo inputAssemblyParams =
5266 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, // VkStructureType sType;
5267 DE_NULL, // const void* pNext;
5268 (VkPipelineInputAssemblyStateCreateFlags)0,
5269 topology, // VkPrimitiveTopology topology;
5270 DE_FALSE, // deUint32 primitiveRestartEnable;
5272 const VkVertexInputBindingDescription vertexBinding0 =
5274 0u, // deUint32 binding;
5275 deUint32(singleVertexDataSize), // deUint32 strideInBytes;
5276 VK_VERTEX_INPUT_RATE_VERTEX // VkVertexInputStepRate stepRate;
5278 const VkVertexInputAttributeDescription vertexAttrib0[2] =
5281 0u, // deUint32 location;
5282 0u, // deUint32 binding;
5283 VK_FORMAT_R32G32B32A32_SFLOAT, // VkFormat format;
5284 0u // deUint32 offsetInBytes;
5287 1u, // deUint32 location;
5288 0u, // deUint32 binding;
5289 VK_FORMAT_R32G32B32A32_SFLOAT, // VkFormat format;
5290 sizeof(Vec4), // deUint32 offsetInBytes;
5294 const VkPipelineVertexInputStateCreateInfo vertexInputStateParams =
5296 VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO, // VkStructureType sType;
5297 DE_NULL, // const void* pNext;
5298 (VkPipelineVertexInputStateCreateFlags)0,
5299 1u, // deUint32 bindingCount;
5300 &vertexBinding0, // const VkVertexInputBindingDescription* pVertexBindingDescriptions;
5301 2u, // deUint32 attributeCount;
5302 vertexAttrib0, // const VkVertexInputAttributeDescription* pVertexAttributeDescriptions;
5304 const VkPipelineColorBlendAttachmentState attBlendParams =
5306 DE_FALSE, // deUint32 blendEnable;
5307 VK_BLEND_FACTOR_ONE, // VkBlend srcBlendColor;
5308 VK_BLEND_FACTOR_ZERO, // VkBlend destBlendColor;
5309 VK_BLEND_OP_ADD, // VkBlendOp blendOpColor;
5310 VK_BLEND_FACTOR_ONE, // VkBlend srcBlendAlpha;
5311 VK_BLEND_FACTOR_ZERO, // VkBlend destBlendAlpha;
5312 VK_BLEND_OP_ADD, // VkBlendOp blendOpAlpha;
5313 (VK_COLOR_COMPONENT_R_BIT|
5314 VK_COLOR_COMPONENT_G_BIT|
5315 VK_COLOR_COMPONENT_B_BIT|
5316 VK_COLOR_COMPONENT_A_BIT), // VkChannelFlags channelWriteMask;
5318 const VkPipelineColorBlendStateCreateInfo blendParams =
5320 VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO, // VkStructureType sType;
5321 DE_NULL, // const void* pNext;
5322 (VkPipelineColorBlendStateCreateFlags)0,
5323 DE_FALSE, // VkBool32 logicOpEnable;
5324 VK_LOGIC_OP_COPY, // VkLogicOp logicOp;
5325 1u, // deUint32 attachmentCount;
5326 &attBlendParams, // const VkPipelineColorBlendAttachmentState* pAttachments;
5327 { 0.0f, 0.0f, 0.0f, 0.0f }, // float blendConst[4];
5329 const VkPipelineTessellationStateCreateInfo tessellationState =
5331 VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO,
5333 (VkPipelineTessellationStateCreateFlags)0,
5337 const VkPipelineTessellationStateCreateInfo* tessellationInfo = hasTessellation ? &tessellationState: DE_NULL;
5338 const VkGraphicsPipelineCreateInfo pipelineParams =
5340 VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO, // VkStructureType sType;
5341 DE_NULL, // const void* pNext;
5342 0u, // VkPipelineCreateFlags flags;
5343 (deUint32)shaderStageParams.size(), // deUint32 stageCount;
5344 &shaderStageParams[0], // const VkPipelineShaderStageCreateInfo* pStages;
5345 &vertexInputStateParams, // const VkPipelineVertexInputStateCreateInfo* pVertexInputState;
5346 &inputAssemblyParams, // const VkPipelineInputAssemblyStateCreateInfo* pInputAssemblyState;
5347 tessellationInfo, // const VkPipelineTessellationStateCreateInfo* pTessellationState;
5348 &viewportParams, // const VkPipelineViewportStateCreateInfo* pViewportState;
5349 &rasterParams, // const VkPipelineRasterStateCreateInfo* pRasterState;
5350 &multisampleParams, // const VkPipelineMultisampleStateCreateInfo* pMultisampleState;
5351 &depthStencilParams, // const VkPipelineDepthStencilStateCreateInfo* pDepthStencilState;
5352 &blendParams, // const VkPipelineColorBlendStateCreateInfo* pColorBlendState;
5353 (const VkPipelineDynamicStateCreateInfo*)DE_NULL, // const VkPipelineDynamicStateCreateInfo* pDynamicState;
5354 *pipelineLayout, // VkPipelineLayout layout;
5355 *renderPass, // VkRenderPass renderPass;
5356 0u, // deUint32 subpass;
5357 DE_NULL, // VkPipeline basePipelineHandle;
5358 0u, // deInt32 basePipelineIndex;
5361 const Unique<VkPipeline> pipeline (createGraphicsPipeline(vk, vkDevice, DE_NULL, &pipelineParams));
5364 const VkFramebufferCreateInfo framebufferParams =
5366 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, // VkStructureType sType;
5367 DE_NULL, // const void* pNext;
5368 (VkFramebufferCreateFlags)0,
5369 *renderPass, // VkRenderPass renderPass;
5370 1u, // deUint32 attachmentCount;
5371 &*colorAttView, // const VkImageView* pAttachments;
5372 (deUint32)renderSize.x(), // deUint32 width;
5373 (deUint32)renderSize.y(), // deUint32 height;
5374 1u, // deUint32 layers;
5376 const Unique<VkFramebuffer> framebuffer (createFramebuffer(vk, vkDevice, &framebufferParams));
5378 const VkCommandPoolCreateInfo cmdPoolParams =
5380 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // VkStructureType sType;
5381 DE_NULL, // const void* pNext;
5382 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // VkCmdPoolCreateFlags flags;
5383 queueFamilyIndex, // deUint32 queueFamilyIndex;
5385 const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams));
5388 const VkCommandBufferAllocateInfo cmdBufParams =
5390 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType;
5391 DE_NULL, // const void* pNext;
5392 *cmdPool, // VkCmdPool pool;
5393 VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCmdBufferLevel level;
5394 1u, // deUint32 count;
5396 const Unique<VkCommandBuffer> cmdBuf (allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
5398 const VkCommandBufferBeginInfo cmdBufBeginParams =
5400 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType;
5401 DE_NULL, // const void* pNext;
5402 (VkCommandBufferUsageFlags)0,
5403 (const VkCommandBufferInheritanceInfo*)DE_NULL,
5407 VK_CHECK(vk.beginCommandBuffer(*cmdBuf, &cmdBufBeginParams));
5410 const VkMemoryBarrier vertFlushBarrier =
5412 VK_STRUCTURE_TYPE_MEMORY_BARRIER, // VkStructureType sType;
5413 DE_NULL, // const void* pNext;
5414 VK_ACCESS_HOST_WRITE_BIT, // VkMemoryOutputFlags outputMask;
5415 VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT, // VkMemoryInputFlags inputMask;
5417 const VkImageMemoryBarrier colorAttBarrier =
5419 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
5420 DE_NULL, // const void* pNext;
5421 0u, // VkMemoryOutputFlags outputMask;
5422 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, // VkMemoryInputFlags inputMask;
5423 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout oldLayout;
5424 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout newLayout;
5425 queueFamilyIndex, // deUint32 srcQueueFamilyIndex;
5426 queueFamilyIndex, // deUint32 destQueueFamilyIndex;
5427 *image, // VkImage image;
5429 VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspect aspect;
5430 0u, // deUint32 baseMipLevel;
5431 1u, // deUint32 mipLevels;
5432 0u, // deUint32 baseArraySlice;
5433 1u, // deUint32 arraySize;
5434 } // VkImageSubresourceRange subresourceRange;
5436 vk.cmdPipelineBarrier(*cmdBuf, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, (VkDependencyFlags)0, 1, &vertFlushBarrier, 0, (const VkBufferMemoryBarrier*)DE_NULL, 1, &colorAttBarrier);
5440 const VkClearValue clearValue = makeClearValueColorF32(0.125f, 0.25f, 0.75f, 1.0f);
5441 const VkRenderPassBeginInfo passBeginParams =
5443 VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, // VkStructureType sType;
5444 DE_NULL, // const void* pNext;
5445 *renderPass, // VkRenderPass renderPass;
5446 *framebuffer, // VkFramebuffer framebuffer;
5447 { { 0, 0 }, { renderSize.x(), renderSize.y() } }, // VkRect2D renderArea;
5448 1u, // deUint32 clearValueCount;
5449 &clearValue, // const VkClearValue* pClearValues;
5451 vk.cmdBeginRenderPass(*cmdBuf, &passBeginParams, VK_SUBPASS_CONTENTS_INLINE);
5454 vk.cmdBindPipeline(*cmdBuf, VK_PIPELINE_BIND_POINT_GRAPHICS, *pipeline);
5456 const VkDeviceSize bindingOffset = 0;
5457 vk.cmdBindVertexBuffers(*cmdBuf, 0u, 1u, &vertexBuffer.get(), &bindingOffset);
5459 vk.cmdDraw(*cmdBuf, deUint32(vertexCount), 1u /*run pipeline once*/, 0u /*first vertex*/, 0u /*first instanceIndex*/);
5460 vk.cmdEndRenderPass(*cmdBuf);
5463 const VkImageMemoryBarrier renderFinishBarrier =
5465 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
5466 DE_NULL, // const void* pNext;
5467 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, // VkMemoryOutputFlags outputMask;
5468 VK_ACCESS_TRANSFER_READ_BIT, // VkMemoryInputFlags inputMask;
5469 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout oldLayout;
5470 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, // VkImageLayout newLayout;
5471 queueFamilyIndex, // deUint32 srcQueueFamilyIndex;
5472 queueFamilyIndex, // deUint32 destQueueFamilyIndex;
5473 *image, // VkImage image;
5475 VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags aspectMask;
5476 0u, // deUint32 baseMipLevel;
5477 1u, // deUint32 mipLevels;
5478 0u, // deUint32 baseArraySlice;
5479 1u, // deUint32 arraySize;
5480 } // VkImageSubresourceRange subresourceRange;
5482 vk.cmdPipelineBarrier(*cmdBuf, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 0, (const VkBufferMemoryBarrier*)DE_NULL, 1, &renderFinishBarrier);
5486 const VkBufferImageCopy copyParams =
5488 (VkDeviceSize)0u, // VkDeviceSize bufferOffset;
5489 (deUint32)renderSize.x(), // deUint32 bufferRowLength;
5490 (deUint32)renderSize.y(), // deUint32 bufferImageHeight;
5492 VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspect aspect;
5493 0u, // deUint32 mipLevel;
5494 0u, // deUint32 arrayLayer;
5495 1u, // deUint32 arraySize;
5496 }, // VkImageSubresourceCopy imageSubresource;
5497 { 0u, 0u, 0u }, // VkOffset3D imageOffset;
5498 { renderSize.x(), renderSize.y(), 1u } // VkExtent3D imageExtent;
5500 vk.cmdCopyImageToBuffer(*cmdBuf, *image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, *readImageBuffer, 1u, ©Params);
5504 const VkBufferMemoryBarrier copyFinishBarrier =
5506 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER, // VkStructureType sType;
5507 DE_NULL, // const void* pNext;
5508 VK_ACCESS_TRANSFER_WRITE_BIT, // VkMemoryOutputFlags outputMask;
5509 VK_ACCESS_HOST_READ_BIT, // VkMemoryInputFlags inputMask;
5510 queueFamilyIndex, // deUint32 srcQueueFamilyIndex;
5511 queueFamilyIndex, // deUint32 destQueueFamilyIndex;
5512 *readImageBuffer, // VkBuffer buffer;
5513 0u, // VkDeviceSize offset;
5514 imageSizeBytes // VkDeviceSize size;
5516 vk.cmdPipelineBarrier(*cmdBuf, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 1, ©FinishBarrier, 0, (const VkImageMemoryBarrier*)DE_NULL);
5519 VK_CHECK(vk.endCommandBuffer(*cmdBuf));
5521 // Upload vertex data
5523 const VkMappedMemoryRange range =
5525 VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE, // VkStructureType sType;
5526 DE_NULL, // const void* pNext;
5527 vertexBufferMemory->getMemory(), // VkDeviceMemory mem;
5528 0, // VkDeviceSize offset;
5529 (VkDeviceSize)sizeof(vertexData), // VkDeviceSize size;
5531 void* vertexBufPtr = vertexBufferMemory->getHostPtr();
5533 deMemcpy(vertexBufPtr, &vertexData[0], sizeof(vertexData));
5534 VK_CHECK(vk.flushMappedMemoryRanges(vkDevice, 1u, &range));
5537 // Submit & wait for completion
5539 const VkFenceCreateInfo fenceParams =
5541 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, // VkStructureType sType;
5542 DE_NULL, // const void* pNext;
5543 0u, // VkFenceCreateFlags flags;
5545 const Unique<VkFence> fence (createFence(vk, vkDevice, &fenceParams));
5546 const VkSubmitInfo submitInfo =
5548 VK_STRUCTURE_TYPE_SUBMIT_INFO,
5551 (const VkSemaphore*)DE_NULL,
5552 (const VkPipelineStageFlags*)DE_NULL,
5556 (const VkSemaphore*)DE_NULL,
5559 VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence));
5560 VK_CHECK(vk.waitForFences(vkDevice, 1u, &fence.get(), DE_TRUE, ~0ull));
5563 const void* imagePtr = readImageBufferMemory->getHostPtr();
5564 const tcu::ConstPixelBufferAccess pixelBuffer(tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8),
5565 renderSize.x(), renderSize.y(), 1, imagePtr);
5568 const VkMappedMemoryRange range =
5570 VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE, // VkStructureType sType;
5571 DE_NULL, // const void* pNext;
5572 readImageBufferMemory->getMemory(), // VkDeviceMemory mem;
5573 0, // VkDeviceSize offset;
5574 imageSizeBytes, // VkDeviceSize size;
5577 VK_CHECK(vk.invalidateMappedMemoryRanges(vkDevice, 1u, &range));
5578 context.getTestContext().getLog() << TestLog::Image("Result", "Result", pixelBuffer);
5581 const RGBA threshold(1, 1, 1, 1);
5582 const RGBA upperLeft(pixelBuffer.getPixel(1, 1));
5583 if (!tcu::compareThreshold(upperLeft, instance.outputColors[0], threshold))
5584 return TestStatus::fail("Upper left corner mismatch");
5586 const RGBA upperRight(pixelBuffer.getPixel(pixelBuffer.getWidth() - 1, 1));
5587 if (!tcu::compareThreshold(upperRight, instance.outputColors[1], threshold))
5588 return TestStatus::fail("Upper right corner mismatch");
5590 const RGBA lowerLeft(pixelBuffer.getPixel(1, pixelBuffer.getHeight() - 1));
5591 if (!tcu::compareThreshold(lowerLeft, instance.outputColors[2], threshold))
5592 return TestStatus::fail("Lower left corner mismatch");
5594 const RGBA lowerRight(pixelBuffer.getPixel(pixelBuffer.getWidth() - 1, pixelBuffer.getHeight() - 1));
5595 if (!tcu::compareThreshold(lowerRight, instance.outputColors[3], threshold))
5596 return TestStatus::fail("Lower right corner mismatch");
5598 return TestStatus::pass("Rendered output matches input");
5601 void createTestsForAllStages (const std::string& name, const RGBA (&inputColors)[4], const RGBA (&outputColors)[4], const map<string, string>& testCodeFragments, const vector<deInt32>& specConstants, tcu::TestCaseGroup* tests)
5603 const ShaderElement vertFragPipelineStages[] =
5605 ShaderElement("vert", "main", VK_SHADER_STAGE_VERTEX_BIT),
5606 ShaderElement("frag", "main", VK_SHADER_STAGE_FRAGMENT_BIT),
5609 const ShaderElement tessPipelineStages[] =
5611 ShaderElement("vert", "main", VK_SHADER_STAGE_VERTEX_BIT),
5612 ShaderElement("tessc", "main", VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT),
5613 ShaderElement("tesse", "main", VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT),
5614 ShaderElement("frag", "main", VK_SHADER_STAGE_FRAGMENT_BIT),
5617 const ShaderElement geomPipelineStages[] =
5619 ShaderElement("vert", "main", VK_SHADER_STAGE_VERTEX_BIT),
5620 ShaderElement("geom", "main", VK_SHADER_STAGE_GEOMETRY_BIT),
5621 ShaderElement("frag", "main", VK_SHADER_STAGE_FRAGMENT_BIT),
5624 StageToSpecConstantMap specConstantMap;
5626 specConstantMap[VK_SHADER_STAGE_VERTEX_BIT] = specConstants;
5627 addFunctionCaseWithPrograms<InstanceContext>(tests, name + "_vert", "", addShaderCodeCustomVertex, runAndVerifyDefaultPipeline,
5628 createInstanceContext(vertFragPipelineStages, inputColors, outputColors, testCodeFragments, specConstantMap));
5630 specConstantMap.clear();
5631 specConstantMap[VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT] = specConstants;
5632 addFunctionCaseWithPrograms<InstanceContext>(tests, name + "_tessc", "", addShaderCodeCustomTessControl, runAndVerifyDefaultPipeline,
5633 createInstanceContext(tessPipelineStages, inputColors, outputColors, testCodeFragments, specConstantMap));
5635 specConstantMap.clear();
5636 specConstantMap[VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT] = specConstants;
5637 addFunctionCaseWithPrograms<InstanceContext>(tests, name + "_tesse", "", addShaderCodeCustomTessEval, runAndVerifyDefaultPipeline,
5638 createInstanceContext(tessPipelineStages, inputColors, outputColors, testCodeFragments, specConstantMap));
5640 specConstantMap.clear();
5641 specConstantMap[VK_SHADER_STAGE_GEOMETRY_BIT] = specConstants;
5642 addFunctionCaseWithPrograms<InstanceContext>(tests, name + "_geom", "", addShaderCodeCustomGeometry, runAndVerifyDefaultPipeline,
5643 createInstanceContext(geomPipelineStages, inputColors, outputColors, testCodeFragments, specConstantMap));
5645 specConstantMap.clear();
5646 specConstantMap[VK_SHADER_STAGE_FRAGMENT_BIT] = specConstants;
5647 addFunctionCaseWithPrograms<InstanceContext>(tests, name + "_frag", "", addShaderCodeCustomFragment, runAndVerifyDefaultPipeline,
5648 createInstanceContext(vertFragPipelineStages, inputColors, outputColors, testCodeFragments, specConstantMap));
5651 inline void createTestsForAllStages (const std::string& name, const RGBA (&inputColors)[4], const RGBA (&outputColors)[4], const map<string, string>& testCodeFragments, tcu::TestCaseGroup* tests)
5653 vector<deInt32> noSpecConstants;
5654 createTestsForAllStages(name, inputColors, outputColors, testCodeFragments, noSpecConstants, tests);
5659 tcu::TestCaseGroup* createOpSourceTests (tcu::TestContext& testCtx)
5661 struct NameCodePair { string name, code; };
5662 RGBA defaultColors[4];
5663 de::MovePtr<tcu::TestCaseGroup> opSourceTests (new tcu::TestCaseGroup(testCtx, "opsource", "OpSource instruction"));
5664 const std::string opsourceGLSLWithFile = "%opsrcfile = OpString \"foo.vert\"\nOpSource GLSL 450 %opsrcfile ";
5665 map<string, string> fragments = passthruFragments();
5666 const NameCodePair tests[] =
5668 {"unknown", "OpSource Unknown 321"},
5669 {"essl", "OpSource ESSL 310"},
5670 {"glsl", "OpSource GLSL 450"},
5671 {"opencl_cpp", "OpSource OpenCL_CPP 120"},
5672 {"opencl_c", "OpSource OpenCL_C 120"},
5673 {"multiple", "OpSource GLSL 450\nOpSource GLSL 450"},
5674 {"file", opsourceGLSLWithFile},
5675 {"source", opsourceGLSLWithFile + "\"void main(){}\""},
5676 // Longest possible source string: SPIR-V limits instructions to 65535
5677 // words, of which the first 4 are opsourceGLSLWithFile; the rest will
5678 // contain 65530 UTF8 characters (one word each) plus one last word
5679 // containing 3 ASCII characters and \0.
5680 {"longsource", opsourceGLSLWithFile + '"' + makeLongUTF8String(65530) + "ccc" + '"'}
5683 getDefaultColors(defaultColors);
5684 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameCodePair); ++testNdx)
5686 fragments["debug"] = tests[testNdx].code;
5687 createTestsForAllStages(tests[testNdx].name, defaultColors, defaultColors, fragments, opSourceTests.get());
5690 return opSourceTests.release();
5693 tcu::TestCaseGroup* createOpSourceContinuedTests (tcu::TestContext& testCtx)
5695 struct NameCodePair { string name, code; };
5696 RGBA defaultColors[4];
5697 de::MovePtr<tcu::TestCaseGroup> opSourceTests (new tcu::TestCaseGroup(testCtx, "opsourcecontinued", "OpSourceContinued instruction"));
5698 map<string, string> fragments = passthruFragments();
5699 const std::string opsource = "%opsrcfile = OpString \"foo.vert\"\nOpSource GLSL 450 %opsrcfile \"void main(){}\"\n";
5700 const NameCodePair tests[] =
5702 {"empty", opsource + "OpSourceContinued \"\""},
5703 {"short", opsource + "OpSourceContinued \"abcde\""},
5704 {"multiple", opsource + "OpSourceContinued \"abcde\"\nOpSourceContinued \"fghij\""},
5705 // Longest possible source string: SPIR-V limits instructions to 65535
5706 // words, of which the first one is OpSourceContinued/length; the rest
5707 // will contain 65533 UTF8 characters (one word each) plus one last word
5708 // containing 3 ASCII characters and \0.
5709 {"long", opsource + "OpSourceContinued \"" + makeLongUTF8String(65533) + "ccc\""}
5712 getDefaultColors(defaultColors);
5713 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameCodePair); ++testNdx)
5715 fragments["debug"] = tests[testNdx].code;
5716 createTestsForAllStages(tests[testNdx].name, defaultColors, defaultColors, fragments, opSourceTests.get());
5719 return opSourceTests.release();
5722 tcu::TestCaseGroup* createOpNoLineTests(tcu::TestContext& testCtx)
5724 RGBA defaultColors[4];
5725 de::MovePtr<tcu::TestCaseGroup> opLineTests (new tcu::TestCaseGroup(testCtx, "opnoline", "OpNoLine instruction"));
5726 map<string, string> fragments;
5727 getDefaultColors(defaultColors);
5728 fragments["debug"] =
5729 "%name = OpString \"name\"\n";
5731 fragments["pre_main"] =
5734 "OpLine %name 1 1\n"
5736 "OpLine %name 1 1\n"
5737 "OpLine %name 1 1\n"
5738 "%second_function = OpFunction %v4f32 None %v4f32_function\n"
5740 "OpLine %name 1 1\n"
5742 "OpLine %name 1 1\n"
5743 "OpLine %name 1 1\n"
5744 "%second_param1 = OpFunctionParameter %v4f32\n"
5747 "%label_secondfunction = OpLabel\n"
5749 "OpReturnValue %second_param1\n"
5754 fragments["testfun"] =
5755 // A %test_code function that returns its argument unchanged.
5758 "OpLine %name 1 1\n"
5759 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5761 "%param1 = OpFunctionParameter %v4f32\n"
5764 "%label_testfun = OpLabel\n"
5766 "%val1 = OpFunctionCall %v4f32 %second_function %param1\n"
5767 "OpReturnValue %val1\n"
5769 "OpLine %name 1 1\n"
5772 createTestsForAllStages("opnoline", defaultColors, defaultColors, fragments, opLineTests.get());
5774 return opLineTests.release();
5778 tcu::TestCaseGroup* createOpLineTests(tcu::TestContext& testCtx)
5780 RGBA defaultColors[4];
5781 de::MovePtr<tcu::TestCaseGroup> opLineTests (new tcu::TestCaseGroup(testCtx, "opline", "OpLine instruction"));
5782 map<string, string> fragments;
5783 std::vector<std::pair<std::string, std::string> > problemStrings;
5785 problemStrings.push_back(std::make_pair<std::string, std::string>("empty_name", ""));
5786 problemStrings.push_back(std::make_pair<std::string, std::string>("short_name", "short_name"));
5787 problemStrings.push_back(std::make_pair<std::string, std::string>("long_name", makeLongUTF8String(65530) + "ccc"));
5788 getDefaultColors(defaultColors);
5790 fragments["debug"] =
5791 "%other_name = OpString \"other_name\"\n";
5793 fragments["pre_main"] =
5794 "OpLine %file_name 32 0\n"
5795 "OpLine %file_name 32 32\n"
5796 "OpLine %file_name 32 40\n"
5797 "OpLine %other_name 32 40\n"
5798 "OpLine %other_name 0 100\n"
5799 "OpLine %other_name 0 4294967295\n"
5800 "OpLine %other_name 4294967295 0\n"
5801 "OpLine %other_name 32 40\n"
5802 "OpLine %file_name 0 0\n"
5803 "%second_function = OpFunction %v4f32 None %v4f32_function\n"
5804 "OpLine %file_name 1 0\n"
5805 "%second_param1 = OpFunctionParameter %v4f32\n"
5806 "OpLine %file_name 1 3\n"
5807 "OpLine %file_name 1 2\n"
5808 "%label_secondfunction = OpLabel\n"
5809 "OpLine %file_name 0 2\n"
5810 "OpReturnValue %second_param1\n"
5812 "OpLine %file_name 0 2\n"
5813 "OpLine %file_name 0 2\n";
5815 fragments["testfun"] =
5816 // A %test_code function that returns its argument unchanged.
5817 "OpLine %file_name 1 0\n"
5818 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5819 "OpLine %file_name 16 330\n"
5820 "%param1 = OpFunctionParameter %v4f32\n"
5821 "OpLine %file_name 14 442\n"
5822 "%label_testfun = OpLabel\n"
5823 "OpLine %file_name 11 1024\n"
5824 "%val1 = OpFunctionCall %v4f32 %second_function %param1\n"
5825 "OpLine %file_name 2 97\n"
5826 "OpReturnValue %val1\n"
5828 "OpLine %file_name 5 32\n";
5830 for (size_t i = 0; i < problemStrings.size(); ++i)
5832 map<string, string> testFragments = fragments;
5833 testFragments["debug"] += "%file_name = OpString \"" + problemStrings[i].second + "\"\n";
5834 createTestsForAllStages(string("opline") + "_" + problemStrings[i].first, defaultColors, defaultColors, testFragments, opLineTests.get());
5837 return opLineTests.release();
5840 tcu::TestCaseGroup* createOpConstantNullTests(tcu::TestContext& testCtx)
5842 de::MovePtr<tcu::TestCaseGroup> opConstantNullTests (new tcu::TestCaseGroup(testCtx, "opconstantnull", "OpConstantNull instruction"));
5846 const char functionStart[] =
5847 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5848 "%param1 = OpFunctionParameter %v4f32\n"
5851 const char functionEnd[] =
5852 "OpReturnValue %transformed_param\n"
5855 struct NameConstantsCode
5862 NameConstantsCode tests[] =
5866 "%cnull = OpConstantNull %v4f32\n",
5867 "%transformed_param = OpFAdd %v4f32 %param1 %cnull\n"
5871 "%cnull = OpConstantNull %f32\n",
5872 "%vp = OpVariable %fp_v4f32 Function\n"
5873 "%v = OpLoad %v4f32 %vp\n"
5874 "%v0 = OpVectorInsertDynamic %v4f32 %v %cnull %c_i32_0\n"
5875 "%v1 = OpVectorInsertDynamic %v4f32 %v0 %cnull %c_i32_1\n"
5876 "%v2 = OpVectorInsertDynamic %v4f32 %v1 %cnull %c_i32_2\n"
5877 "%v3 = OpVectorInsertDynamic %v4f32 %v2 %cnull %c_i32_3\n"
5878 "%transformed_param = OpFAdd %v4f32 %param1 %v3\n"
5882 "%cnull = OpConstantNull %bool\n",
5883 "%v = OpVariable %fp_v4f32 Function\n"
5884 " OpStore %v %param1\n"
5885 " OpSelectionMerge %false_label None\n"
5886 " OpBranchConditional %cnull %true_label %false_label\n"
5887 "%true_label = OpLabel\n"
5888 " OpStore %v %c_v4f32_0_5_0_5_0_5_0_5\n"
5889 " OpBranch %false_label\n"
5890 "%false_label = OpLabel\n"
5891 "%transformed_param = OpLoad %v4f32 %v\n"
5895 "%cnull = OpConstantNull %i32\n",
5896 "%v = OpVariable %fp_v4f32 Function %c_v4f32_0_5_0_5_0_5_0_5\n"
5897 "%b = OpIEqual %bool %cnull %c_i32_0\n"
5898 " OpSelectionMerge %false_label None\n"
5899 " OpBranchConditional %b %true_label %false_label\n"
5900 "%true_label = OpLabel\n"
5901 " OpStore %v %param1\n"
5902 " OpBranch %false_label\n"
5903 "%false_label = OpLabel\n"
5904 "%transformed_param = OpLoad %v4f32 %v\n"
5908 "%stype = OpTypeStruct %f32 %v4f32\n"
5909 "%fp_stype = OpTypePointer Function %stype\n"
5910 "%cnull = OpConstantNull %stype\n",
5911 "%v = OpVariable %fp_stype Function %cnull\n"
5912 "%f = OpAccessChain %fp_v4f32 %v %c_i32_1\n"
5913 "%f_val = OpLoad %v4f32 %f\n"
5914 "%transformed_param = OpFAdd %v4f32 %param1 %f_val\n"
5918 "%a4_v4f32 = OpTypeArray %v4f32 %c_u32_4\n"
5919 "%fp_a4_v4f32 = OpTypePointer Function %a4_v4f32\n"
5920 "%cnull = OpConstantNull %a4_v4f32\n",
5921 "%v = OpVariable %fp_a4_v4f32 Function %cnull\n"
5922 "%f = OpAccessChain %fp_v4f32 %v %c_u32_0\n"
5923 "%f1 = OpAccessChain %fp_v4f32 %v %c_u32_1\n"
5924 "%f2 = OpAccessChain %fp_v4f32 %v %c_u32_2\n"
5925 "%f3 = OpAccessChain %fp_v4f32 %v %c_u32_3\n"
5926 "%f_val = OpLoad %v4f32 %f\n"
5927 "%f1_val = OpLoad %v4f32 %f1\n"
5928 "%f2_val = OpLoad %v4f32 %f2\n"
5929 "%f3_val = OpLoad %v4f32 %f3\n"
5930 "%t0 = OpFAdd %v4f32 %param1 %f_val\n"
5931 "%t1 = OpFAdd %v4f32 %t0 %f1_val\n"
5932 "%t2 = OpFAdd %v4f32 %t1 %f2_val\n"
5933 "%transformed_param = OpFAdd %v4f32 %t2 %f3_val\n"
5937 "%mat4x4_f32 = OpTypeMatrix %v4f32 4\n"
5938 "%cnull = OpConstantNull %mat4x4_f32\n",
5939 // Our null matrix * any vector should result in a zero vector.
5940 "%v = OpVectorTimesMatrix %v4f32 %param1 %cnull\n"
5941 "%transformed_param = OpFAdd %v4f32 %param1 %v\n"
5945 getHalfColorsFullAlpha(colors);
5947 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameConstantsCode); ++testNdx)
5949 map<string, string> fragments;
5950 fragments["pre_main"] = tests[testNdx].constants;
5951 fragments["testfun"] = string(functionStart) + tests[testNdx].code + functionEnd;
5952 createTestsForAllStages(tests[testNdx].name, colors, colors, fragments, opConstantNullTests.get());
5954 return opConstantNullTests.release();
5956 tcu::TestCaseGroup* createOpConstantCompositeTests(tcu::TestContext& testCtx)
5958 de::MovePtr<tcu::TestCaseGroup> opConstantCompositeTests (new tcu::TestCaseGroup(testCtx, "opconstantcomposite", "OpConstantComposite instruction"));
5959 RGBA inputColors[4];
5960 RGBA outputColors[4];
5963 const char functionStart[] =
5964 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5965 "%param1 = OpFunctionParameter %v4f32\n"
5968 const char functionEnd[] =
5969 "OpReturnValue %transformed_param\n"
5972 struct NameConstantsCode
5979 NameConstantsCode tests[] =
5984 "%cval = OpConstantComposite %v4f32 %c_f32_0_5 %c_f32_0_5 %c_f32_0_5 %c_f32_0\n",
5985 "%transformed_param = OpFAdd %v4f32 %param1 %cval\n"
5990 "%stype = OpTypeStruct %v4f32 %f32\n"
5991 "%fp_stype = OpTypePointer Function %stype\n"
5992 "%f32_n_1 = OpConstant %f32 -1.0\n"
5993 "%f32_1_5 = OpConstant %f32 !0x3fc00000\n" // +1.5
5994 "%cvec = OpConstantComposite %v4f32 %f32_1_5 %f32_1_5 %f32_1_5 %c_f32_1\n"
5995 "%cval = OpConstantComposite %stype %cvec %f32_n_1\n",
5997 "%v = OpVariable %fp_stype Function %cval\n"
5998 "%vec_ptr = OpAccessChain %fp_v4f32 %v %c_u32_0\n"
5999 "%f32_ptr = OpAccessChain %fp_f32 %v %c_u32_1\n"
6000 "%vec_val = OpLoad %v4f32 %vec_ptr\n"
6001 "%f32_val = OpLoad %f32 %f32_ptr\n"
6002 "%tmp1 = OpVectorTimesScalar %v4f32 %c_v4f32_1_1_1_1 %f32_val\n" // vec4(-1)
6003 "%tmp2 = OpFAdd %v4f32 %tmp1 %param1\n" // param1 + vec4(-1)
6004 "%transformed_param = OpFAdd %v4f32 %tmp2 %vec_val\n" // param1 + vec4(-1) + vec4(1.5, 1.5, 1.5, 1.0)
6007 // [1|0|0|0.5] [x] = x + 0.5
6008 // [0|1|0|0.5] [y] = y + 0.5
6009 // [0|0|1|0.5] [z] = z + 0.5
6010 // [0|0|0|1 ] [1] = 1
6013 "%mat4x4_f32 = OpTypeMatrix %v4f32 4\n"
6014 "%v4f32_1_0_0_0 = OpConstantComposite %v4f32 %c_f32_1 %c_f32_0 %c_f32_0 %c_f32_0\n"
6015 "%v4f32_0_1_0_0 = OpConstantComposite %v4f32 %c_f32_0 %c_f32_1 %c_f32_0 %c_f32_0\n"
6016 "%v4f32_0_0_1_0 = OpConstantComposite %v4f32 %c_f32_0 %c_f32_0 %c_f32_1 %c_f32_0\n"
6017 "%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"
6018 "%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",
6020 "%transformed_param = OpMatrixTimesVector %v4f32 %cval %param1\n"
6025 "%c_v4f32_1_1_1_0 = OpConstantComposite %v4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_0\n"
6026 "%fp_a4f32 = OpTypePointer Function %a4f32\n"
6027 "%f32_n_1 = OpConstant %f32 -1.0\n"
6028 "%f32_1_5 = OpConstant %f32 !0x3fc00000\n" // +1.5
6029 "%carr = OpConstantComposite %a4f32 %c_f32_0 %f32_n_1 %f32_1_5 %c_f32_0\n",
6031 "%v = OpVariable %fp_a4f32 Function %carr\n"
6032 "%f = OpAccessChain %fp_f32 %v %c_u32_0\n"
6033 "%f1 = OpAccessChain %fp_f32 %v %c_u32_1\n"
6034 "%f2 = OpAccessChain %fp_f32 %v %c_u32_2\n"
6035 "%f3 = OpAccessChain %fp_f32 %v %c_u32_3\n"
6036 "%f_val = OpLoad %f32 %f\n"
6037 "%f1_val = OpLoad %f32 %f1\n"
6038 "%f2_val = OpLoad %f32 %f2\n"
6039 "%f3_val = OpLoad %f32 %f3\n"
6040 "%ftot1 = OpFAdd %f32 %f_val %f1_val\n"
6041 "%ftot2 = OpFAdd %f32 %ftot1 %f2_val\n"
6042 "%ftot3 = OpFAdd %f32 %ftot2 %f3_val\n" // 0 - 1 + 1.5 + 0
6043 "%add_vec = OpVectorTimesScalar %v4f32 %c_v4f32_1_1_1_0 %ftot3\n"
6044 "%transformed_param = OpFAdd %v4f32 %param1 %add_vec\n"
6051 // [ 1.0, 1.0, 1.0, 1.0]
6055 // [ 0.0, 0.5, 0.0, 0.0]
6059 // [ 1.0, 1.0, 1.0, 1.0]
6062 "array_of_struct_of_array",
6064 "%c_v4f32_1_1_1_0 = OpConstantComposite %v4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_0\n"
6065 "%fp_a4f32 = OpTypePointer Function %a4f32\n"
6066 "%stype = OpTypeStruct %f32 %a4f32\n"
6067 "%a3stype = OpTypeArray %stype %c_u32_3\n"
6068 "%fp_a3stype = OpTypePointer Function %a3stype\n"
6069 "%ca4f32_0 = OpConstantComposite %a4f32 %c_f32_0 %c_f32_0_5 %c_f32_0 %c_f32_0\n"
6070 "%ca4f32_1 = OpConstantComposite %a4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_1\n"
6071 "%cstype1 = OpConstantComposite %stype %c_f32_0 %ca4f32_1\n"
6072 "%cstype2 = OpConstantComposite %stype %c_f32_1 %ca4f32_0\n"
6073 "%carr = OpConstantComposite %a3stype %cstype1 %cstype2 %cstype1",
6075 "%v = OpVariable %fp_a3stype Function %carr\n"
6076 "%f = OpAccessChain %fp_f32 %v %c_u32_1 %c_u32_1 %c_u32_1\n"
6077 "%f_l = OpLoad %f32 %f\n"
6078 "%add_vec = OpVectorTimesScalar %v4f32 %c_v4f32_1_1_1_0 %f_l\n"
6079 "%transformed_param = OpFAdd %v4f32 %param1 %add_vec\n"
6083 getHalfColorsFullAlpha(inputColors);
6084 outputColors[0] = RGBA(255, 255, 255, 255);
6085 outputColors[1] = RGBA(255, 127, 127, 255);
6086 outputColors[2] = RGBA(127, 255, 127, 255);
6087 outputColors[3] = RGBA(127, 127, 255, 255);
6089 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameConstantsCode); ++testNdx)
6091 map<string, string> fragments;
6092 fragments["pre_main"] = tests[testNdx].constants;
6093 fragments["testfun"] = string(functionStart) + tests[testNdx].code + functionEnd;
6094 createTestsForAllStages(tests[testNdx].name, inputColors, outputColors, fragments, opConstantCompositeTests.get());
6096 return opConstantCompositeTests.release();
6099 tcu::TestCaseGroup* createSelectionBlockOrderTests(tcu::TestContext& testCtx)
6101 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "selection_block_order", "Out-of-order blocks for selection"));
6102 RGBA inputColors[4];
6103 RGBA outputColors[4];
6104 map<string, string> fragments;
6106 // vec4 test_code(vec4 param) {
6107 // vec4 result = param;
6108 // for (int i = 0; i < 4; ++i) {
6109 // if (i == 0) result[i] = 0.;
6110 // else result[i] = 1. - result[i];
6114 const char function[] =
6115 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6116 "%param1 = OpFunctionParameter %v4f32\n"
6118 "%iptr = OpVariable %fp_i32 Function\n"
6119 "%result = OpVariable %fp_v4f32 Function\n"
6120 " OpStore %iptr %c_i32_0\n"
6121 " OpStore %result %param1\n"
6124 // Loop entry block.
6126 "%ival = OpLoad %i32 %iptr\n"
6127 "%lt_4 = OpSLessThan %bool %ival %c_i32_4\n"
6128 " OpLoopMerge %exit %loop None\n"
6129 " OpBranchConditional %lt_4 %if_entry %exit\n"
6131 // Merge block for loop.
6133 "%ret = OpLoad %v4f32 %result\n"
6134 " OpReturnValue %ret\n"
6136 // If-statement entry block.
6137 "%if_entry = OpLabel\n"
6138 "%loc = OpAccessChain %fp_f32 %result %ival\n"
6139 "%eq_0 = OpIEqual %bool %ival %c_i32_0\n"
6140 " OpSelectionMerge %if_exit None\n"
6141 " OpBranchConditional %eq_0 %if_true %if_false\n"
6143 // False branch for if-statement.
6144 "%if_false = OpLabel\n"
6145 "%val = OpLoad %f32 %loc\n"
6146 "%sub = OpFSub %f32 %c_f32_1 %val\n"
6147 " OpStore %loc %sub\n"
6148 " OpBranch %if_exit\n"
6150 // Merge block for if-statement.
6151 "%if_exit = OpLabel\n"
6152 "%ival_next = OpIAdd %i32 %ival %c_i32_1\n"
6153 " OpStore %iptr %ival_next\n"
6156 // True branch for if-statement.
6157 "%if_true = OpLabel\n"
6158 " OpStore %loc %c_f32_0\n"
6159 " OpBranch %if_exit\n"
6163 fragments["testfun"] = function;
6165 inputColors[0] = RGBA(127, 127, 127, 0);
6166 inputColors[1] = RGBA(127, 0, 0, 0);
6167 inputColors[2] = RGBA(0, 127, 0, 0);
6168 inputColors[3] = RGBA(0, 0, 127, 0);
6170 outputColors[0] = RGBA(0, 128, 128, 255);
6171 outputColors[1] = RGBA(0, 255, 255, 255);
6172 outputColors[2] = RGBA(0, 128, 255, 255);
6173 outputColors[3] = RGBA(0, 255, 128, 255);
6175 createTestsForAllStages("out_of_order", inputColors, outputColors, fragments, group.get());
6177 return group.release();
6180 tcu::TestCaseGroup* createSwitchBlockOrderTests(tcu::TestContext& testCtx)
6182 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "switch_block_order", "Out-of-order blocks for switch"));
6183 RGBA inputColors[4];
6184 RGBA outputColors[4];
6185 map<string, string> fragments;
6187 const char typesAndConstants[] =
6188 "%c_f32_p2 = OpConstant %f32 0.2\n"
6189 "%c_f32_p4 = OpConstant %f32 0.4\n"
6190 "%c_f32_p6 = OpConstant %f32 0.6\n"
6191 "%c_f32_p8 = OpConstant %f32 0.8\n";
6193 // vec4 test_code(vec4 param) {
6194 // vec4 result = param;
6195 // for (int i = 0; i < 4; ++i) {
6197 // case 0: result[i] += .2; break;
6198 // case 1: result[i] += .6; break;
6199 // case 2: result[i] += .4; break;
6200 // case 3: result[i] += .8; break;
6201 // default: break; // unreachable
6206 const char function[] =
6207 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6208 "%param1 = OpFunctionParameter %v4f32\n"
6210 "%iptr = OpVariable %fp_i32 Function\n"
6211 "%result = OpVariable %fp_v4f32 Function\n"
6212 " OpStore %iptr %c_i32_0\n"
6213 " OpStore %result %param1\n"
6216 // Loop entry block.
6218 "%ival = OpLoad %i32 %iptr\n"
6219 "%lt_4 = OpSLessThan %bool %ival %c_i32_4\n"
6220 " OpLoopMerge %exit %loop None\n"
6221 " OpBranchConditional %lt_4 %switch_entry %exit\n"
6223 // Merge block for loop.
6225 "%ret = OpLoad %v4f32 %result\n"
6226 " OpReturnValue %ret\n"
6228 // Switch-statement entry block.
6229 "%switch_entry = OpLabel\n"
6230 "%loc = OpAccessChain %fp_f32 %result %ival\n"
6231 "%val = OpLoad %f32 %loc\n"
6232 " OpSelectionMerge %switch_exit None\n"
6233 " OpSwitch %ival %switch_default 0 %case0 1 %case1 2 %case2 3 %case3\n"
6235 "%case2 = OpLabel\n"
6236 "%addp4 = OpFAdd %f32 %val %c_f32_p4\n"
6237 " OpStore %loc %addp4\n"
6238 " OpBranch %switch_exit\n"
6240 "%switch_default = OpLabel\n"
6243 "%case3 = OpLabel\n"
6244 "%addp8 = OpFAdd %f32 %val %c_f32_p8\n"
6245 " OpStore %loc %addp8\n"
6246 " OpBranch %switch_exit\n"
6248 "%case0 = OpLabel\n"
6249 "%addp2 = OpFAdd %f32 %val %c_f32_p2\n"
6250 " OpStore %loc %addp2\n"
6251 " OpBranch %switch_exit\n"
6253 // Merge block for switch-statement.
6254 "%switch_exit = OpLabel\n"
6255 "%ival_next = OpIAdd %i32 %ival %c_i32_1\n"
6256 " OpStore %iptr %ival_next\n"
6259 "%case1 = OpLabel\n"
6260 "%addp6 = OpFAdd %f32 %val %c_f32_p6\n"
6261 " OpStore %loc %addp6\n"
6262 " OpBranch %switch_exit\n"
6266 fragments["pre_main"] = typesAndConstants;
6267 fragments["testfun"] = function;
6269 inputColors[0] = RGBA(127, 27, 127, 51);
6270 inputColors[1] = RGBA(127, 0, 0, 51);
6271 inputColors[2] = RGBA(0, 27, 0, 51);
6272 inputColors[3] = RGBA(0, 0, 127, 51);
6274 outputColors[0] = RGBA(178, 180, 229, 255);
6275 outputColors[1] = RGBA(178, 153, 102, 255);
6276 outputColors[2] = RGBA(51, 180, 102, 255);
6277 outputColors[3] = RGBA(51, 153, 229, 255);
6279 createTestsForAllStages("out_of_order", inputColors, outputColors, fragments, group.get());
6281 return group.release();
6284 tcu::TestCaseGroup* createDecorationGroupTests(tcu::TestContext& testCtx)
6286 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "decoration_group", "Decoration group tests"));
6287 RGBA inputColors[4];
6288 RGBA outputColors[4];
6289 map<string, string> fragments;
6291 const char decorations[] =
6292 "OpDecorate %array_group ArrayStride 4\n"
6293 "OpDecorate %struct_member_group Offset 0\n"
6294 "%array_group = OpDecorationGroup\n"
6295 "%struct_member_group = OpDecorationGroup\n"
6297 "OpDecorate %group1 RelaxedPrecision\n"
6298 "OpDecorate %group3 RelaxedPrecision\n"
6299 "OpDecorate %group3 Invariant\n"
6300 "OpDecorate %group3 Restrict\n"
6301 "%group0 = OpDecorationGroup\n"
6302 "%group1 = OpDecorationGroup\n"
6303 "%group3 = OpDecorationGroup\n";
6305 const char typesAndConstants[] =
6306 "%a3f32 = OpTypeArray %f32 %c_u32_3\n"
6307 "%struct1 = OpTypeStruct %a3f32\n"
6308 "%struct2 = OpTypeStruct %a3f32\n"
6309 "%fp_struct1 = OpTypePointer Function %struct1\n"
6310 "%fp_struct2 = OpTypePointer Function %struct2\n"
6311 "%c_f32_2 = OpConstant %f32 2.\n"
6312 "%c_f32_n2 = OpConstant %f32 -2.\n"
6314 "%c_a3f32_1 = OpConstantComposite %a3f32 %c_f32_1 %c_f32_2 %c_f32_1\n"
6315 "%c_a3f32_2 = OpConstantComposite %a3f32 %c_f32_n1 %c_f32_n2 %c_f32_n1\n"
6316 "%c_struct1 = OpConstantComposite %struct1 %c_a3f32_1\n"
6317 "%c_struct2 = OpConstantComposite %struct2 %c_a3f32_2\n";
6319 const char function[] =
6320 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6321 "%param = OpFunctionParameter %v4f32\n"
6322 "%entry = OpLabel\n"
6323 "%result = OpVariable %fp_v4f32 Function\n"
6324 "%v_struct1 = OpVariable %fp_struct1 Function\n"
6325 "%v_struct2 = OpVariable %fp_struct2 Function\n"
6326 " OpStore %result %param\n"
6327 " OpStore %v_struct1 %c_struct1\n"
6328 " OpStore %v_struct2 %c_struct2\n"
6329 "%ptr1 = OpAccessChain %fp_f32 %v_struct1 %c_i32_0 %c_i32_2\n"
6330 "%val1 = OpLoad %f32 %ptr1\n"
6331 "%ptr2 = OpAccessChain %fp_f32 %v_struct2 %c_i32_0 %c_i32_2\n"
6332 "%val2 = OpLoad %f32 %ptr2\n"
6333 "%addvalues = OpFAdd %f32 %val1 %val2\n"
6334 "%ptr = OpAccessChain %fp_f32 %result %c_i32_1\n"
6335 "%val = OpLoad %f32 %ptr\n"
6336 "%addresult = OpFAdd %f32 %addvalues %val\n"
6337 " OpStore %ptr %addresult\n"
6338 "%ret = OpLoad %v4f32 %result\n"
6339 " OpReturnValue %ret\n"
6342 struct CaseNameDecoration
6348 CaseNameDecoration tests[] =
6351 "same_decoration_group_on_multiple_types",
6352 "OpGroupMemberDecorate %struct_member_group %struct1 0 %struct2 0\n"
6355 "empty_decoration_group",
6356 "OpGroupDecorate %group0 %a3f32\n"
6357 "OpGroupDecorate %group0 %result\n"
6360 "one_element_decoration_group",
6361 "OpGroupDecorate %array_group %a3f32\n"
6364 "multiple_elements_decoration_group",
6365 "OpGroupDecorate %group3 %v_struct1\n"
6368 "multiple_decoration_groups_on_same_variable",
6369 "OpGroupDecorate %group0 %v_struct2\n"
6370 "OpGroupDecorate %group1 %v_struct2\n"
6371 "OpGroupDecorate %group3 %v_struct2\n"
6374 "same_decoration_group_multiple_times",
6375 "OpGroupDecorate %group1 %addvalues\n"
6376 "OpGroupDecorate %group1 %addvalues\n"
6377 "OpGroupDecorate %group1 %addvalues\n"
6382 getHalfColorsFullAlpha(inputColors);
6383 getHalfColorsFullAlpha(outputColors);
6385 for (size_t idx = 0; idx < (sizeof(tests) / sizeof(tests[0])); ++idx)
6387 fragments["decoration"] = decorations + tests[idx].decoration;
6388 fragments["pre_main"] = typesAndConstants;
6389 fragments["testfun"] = function;
6391 createTestsForAllStages(tests[idx].name, inputColors, outputColors, fragments, group.get());
6394 return group.release();
6397 struct SpecConstantTwoIntGraphicsCase
6399 const char* caseName;
6400 const char* scDefinition0;
6401 const char* scDefinition1;
6402 const char* scResultType;
6403 const char* scOperation;
6404 deInt32 scActualValue0;
6405 deInt32 scActualValue1;
6406 const char* resultOperation;
6407 RGBA expectedColors[4];
6409 SpecConstantTwoIntGraphicsCase (const char* name,
6410 const char* definition0,
6411 const char* definition1,
6412 const char* resultType,
6413 const char* operation,
6416 const char* resultOp,
6417 const RGBA (&output)[4])
6419 , scDefinition0 (definition0)
6420 , scDefinition1 (definition1)
6421 , scResultType (resultType)
6422 , scOperation (operation)
6423 , scActualValue0 (value0)
6424 , scActualValue1 (value1)
6425 , resultOperation (resultOp)
6427 expectedColors[0] = output[0];
6428 expectedColors[1] = output[1];
6429 expectedColors[2] = output[2];
6430 expectedColors[3] = output[3];
6434 tcu::TestCaseGroup* createSpecConstantTests (tcu::TestContext& testCtx)
6436 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opspecconstantop", "Test the OpSpecConstantOp instruction"));
6437 vector<SpecConstantTwoIntGraphicsCase> cases;
6438 RGBA inputColors[4];
6439 RGBA outputColors0[4];
6440 RGBA outputColors1[4];
6441 RGBA outputColors2[4];
6443 const char decorations1[] =
6444 "OpDecorate %sc_0 SpecId 0\n"
6445 "OpDecorate %sc_1 SpecId 1\n";
6447 const char typesAndConstants1[] =
6448 "%sc_0 = OpSpecConstant${SC_DEF0}\n"
6449 "%sc_1 = OpSpecConstant${SC_DEF1}\n"
6450 "%sc_op = OpSpecConstantOp ${SC_RESULT_TYPE} ${SC_OP}\n";
6452 const char function1[] =
6453 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6454 "%param = OpFunctionParameter %v4f32\n"
6455 "%label = OpLabel\n"
6456 "%result = OpVariable %fp_v4f32 Function\n"
6457 " OpStore %result %param\n"
6458 "%gen = ${GEN_RESULT}\n"
6459 "%index = OpIAdd %i32 %gen %c_i32_1\n"
6460 "%loc = OpAccessChain %fp_f32 %result %index\n"
6461 "%val = OpLoad %f32 %loc\n"
6462 "%add = OpFAdd %f32 %val %c_f32_0_5\n"
6463 " OpStore %loc %add\n"
6464 "%ret = OpLoad %v4f32 %result\n"
6465 " OpReturnValue %ret\n"
6468 inputColors[0] = RGBA(127, 127, 127, 255);
6469 inputColors[1] = RGBA(127, 0, 0, 255);
6470 inputColors[2] = RGBA(0, 127, 0, 255);
6471 inputColors[3] = RGBA(0, 0, 127, 255);
6473 // Derived from inputColors[x] by adding 128 to inputColors[x][0].
6474 outputColors0[0] = RGBA(255, 127, 127, 255);
6475 outputColors0[1] = RGBA(255, 0, 0, 255);
6476 outputColors0[2] = RGBA(128, 127, 0, 255);
6477 outputColors0[3] = RGBA(128, 0, 127, 255);
6479 // Derived from inputColors[x] by adding 128 to inputColors[x][1].
6480 outputColors1[0] = RGBA(127, 255, 127, 255);
6481 outputColors1[1] = RGBA(127, 128, 0, 255);
6482 outputColors1[2] = RGBA(0, 255, 0, 255);
6483 outputColors1[3] = RGBA(0, 128, 127, 255);
6485 // Derived from inputColors[x] by adding 128 to inputColors[x][2].
6486 outputColors2[0] = RGBA(127, 127, 255, 255);
6487 outputColors2[1] = RGBA(127, 0, 128, 255);
6488 outputColors2[2] = RGBA(0, 127, 128, 255);
6489 outputColors2[3] = RGBA(0, 0, 255, 255);
6491 const char addZeroToSc[] = "OpIAdd %i32 %c_i32_0 %sc_op";
6492 const char selectTrueUsingSc[] = "OpSelect %i32 %sc_op %c_i32_1 %c_i32_0";
6493 const char selectFalseUsingSc[] = "OpSelect %i32 %sc_op %c_i32_0 %c_i32_1";
6495 cases.push_back(SpecConstantTwoIntGraphicsCase("iadd", " %i32 0", " %i32 0", "%i32", "IAdd %sc_0 %sc_1", 19, -20, addZeroToSc, outputColors0));
6496 cases.push_back(SpecConstantTwoIntGraphicsCase("isub", " %i32 0", " %i32 0", "%i32", "ISub %sc_0 %sc_1", 19, 20, addZeroToSc, outputColors0));
6497 cases.push_back(SpecConstantTwoIntGraphicsCase("imul", " %i32 0", " %i32 0", "%i32", "IMul %sc_0 %sc_1", -1, -1, addZeroToSc, outputColors2));
6498 cases.push_back(SpecConstantTwoIntGraphicsCase("sdiv", " %i32 0", " %i32 0", "%i32", "SDiv %sc_0 %sc_1", -126, 126, addZeroToSc, outputColors0));
6499 cases.push_back(SpecConstantTwoIntGraphicsCase("udiv", " %i32 0", " %i32 0", "%i32", "UDiv %sc_0 %sc_1", 126, 126, addZeroToSc, outputColors2));
6500 cases.push_back(SpecConstantTwoIntGraphicsCase("srem", " %i32 0", " %i32 0", "%i32", "SRem %sc_0 %sc_1", 3, 2, addZeroToSc, outputColors2));
6501 cases.push_back(SpecConstantTwoIntGraphicsCase("smod", " %i32 0", " %i32 0", "%i32", "SMod %sc_0 %sc_1", 3, 2, addZeroToSc, outputColors2));
6502 cases.push_back(SpecConstantTwoIntGraphicsCase("umod", " %i32 0", " %i32 0", "%i32", "UMod %sc_0 %sc_1", 1001, 500, addZeroToSc, outputColors2));
6503 cases.push_back(SpecConstantTwoIntGraphicsCase("bitwiseand", " %i32 0", " %i32 0", "%i32", "BitwiseAnd %sc_0 %sc_1", 0x33, 0x0d, addZeroToSc, outputColors2));
6504 cases.push_back(SpecConstantTwoIntGraphicsCase("bitwiseor", " %i32 0", " %i32 0", "%i32", "BitwiseOr %sc_0 %sc_1", 0, 1, addZeroToSc, outputColors2));
6505 cases.push_back(SpecConstantTwoIntGraphicsCase("bitwisexor", " %i32 0", " %i32 0", "%i32", "BitwiseXor %sc_0 %sc_1", 0x2e, 0x2f, addZeroToSc, outputColors2));
6506 cases.push_back(SpecConstantTwoIntGraphicsCase("shiftrightlogical", " %i32 0", " %i32 0", "%i32", "ShiftRightLogical %sc_0 %sc_1", 2, 1, addZeroToSc, outputColors2));
6507 cases.push_back(SpecConstantTwoIntGraphicsCase("shiftrightarithmetic", " %i32 0", " %i32 0", "%i32", "ShiftRightArithmetic %sc_0 %sc_1", -4, 2, addZeroToSc, outputColors0));
6508 cases.push_back(SpecConstantTwoIntGraphicsCase("shiftleftlogical", " %i32 0", " %i32 0", "%i32", "ShiftLeftLogical %sc_0 %sc_1", 1, 0, addZeroToSc, outputColors2));
6509 cases.push_back(SpecConstantTwoIntGraphicsCase("slessthan", " %i32 0", " %i32 0", "%bool", "SLessThan %sc_0 %sc_1", -20, -10, selectTrueUsingSc, outputColors2));
6510 cases.push_back(SpecConstantTwoIntGraphicsCase("ulessthan", " %i32 0", " %i32 0", "%bool", "ULessThan %sc_0 %sc_1", 10, 20, selectTrueUsingSc, outputColors2));
6511 cases.push_back(SpecConstantTwoIntGraphicsCase("sgreaterthan", " %i32 0", " %i32 0", "%bool", "SGreaterThan %sc_0 %sc_1", -1000, 50, selectFalseUsingSc, outputColors2));
6512 cases.push_back(SpecConstantTwoIntGraphicsCase("ugreaterthan", " %i32 0", " %i32 0", "%bool", "UGreaterThan %sc_0 %sc_1", 10, 5, selectTrueUsingSc, outputColors2));
6513 cases.push_back(SpecConstantTwoIntGraphicsCase("slessthanequal", " %i32 0", " %i32 0", "%bool", "SLessThanEqual %sc_0 %sc_1", -10, -10, selectTrueUsingSc, outputColors2));
6514 cases.push_back(SpecConstantTwoIntGraphicsCase("ulessthanequal", " %i32 0", " %i32 0", "%bool", "ULessThanEqual %sc_0 %sc_1", 50, 100, selectTrueUsingSc, outputColors2));
6515 cases.push_back(SpecConstantTwoIntGraphicsCase("sgreaterthanequal", " %i32 0", " %i32 0", "%bool", "SGreaterThanEqual %sc_0 %sc_1", -1000, 50, selectFalseUsingSc, outputColors2));
6516 cases.push_back(SpecConstantTwoIntGraphicsCase("ugreaterthanequal", " %i32 0", " %i32 0", "%bool", "UGreaterThanEqual %sc_0 %sc_1", 10, 10, selectTrueUsingSc, outputColors2));
6517 cases.push_back(SpecConstantTwoIntGraphicsCase("iequal", " %i32 0", " %i32 0", "%bool", "IEqual %sc_0 %sc_1", 42, 24, selectFalseUsingSc, outputColors2));
6518 cases.push_back(SpecConstantTwoIntGraphicsCase("logicaland", "True %bool", "True %bool", "%bool", "LogicalAnd %sc_0 %sc_1", 0, 1, selectFalseUsingSc, outputColors2));
6519 cases.push_back(SpecConstantTwoIntGraphicsCase("logicalor", "False %bool", "False %bool", "%bool", "LogicalOr %sc_0 %sc_1", 1, 0, selectTrueUsingSc, outputColors2));
6520 cases.push_back(SpecConstantTwoIntGraphicsCase("logicalequal", "True %bool", "True %bool", "%bool", "LogicalEqual %sc_0 %sc_1", 0, 1, selectFalseUsingSc, outputColors2));
6521 cases.push_back(SpecConstantTwoIntGraphicsCase("logicalnotequal", "False %bool", "False %bool", "%bool", "LogicalNotEqual %sc_0 %sc_1", 1, 0, selectTrueUsingSc, outputColors2));
6522 cases.push_back(SpecConstantTwoIntGraphicsCase("snegate", " %i32 0", " %i32 0", "%i32", "SNegate %sc_0", -1, 0, addZeroToSc, outputColors2));
6523 cases.push_back(SpecConstantTwoIntGraphicsCase("not", " %i32 0", " %i32 0", "%i32", "Not %sc_0", -2, 0, addZeroToSc, outputColors2));
6524 cases.push_back(SpecConstantTwoIntGraphicsCase("logicalnot", "False %bool", "False %bool", "%bool", "LogicalNot %sc_0", 1, 0, selectFalseUsingSc, outputColors2));
6525 cases.push_back(SpecConstantTwoIntGraphicsCase("select", "False %bool", " %i32 0", "%i32", "Select %sc_0 %sc_1 %c_i32_0", 1, 1, addZeroToSc, outputColors2));
6526 // OpSConvert, OpFConvert: these two instructions involve ints/floats of different bitwidths.
6527 // \todo[2015-12-1 antiagainst] OpQuantizeToF16
6529 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
6531 map<string, string> specializations;
6532 map<string, string> fragments;
6533 vector<deInt32> specConstants;
6535 specializations["SC_DEF0"] = cases[caseNdx].scDefinition0;
6536 specializations["SC_DEF1"] = cases[caseNdx].scDefinition1;
6537 specializations["SC_RESULT_TYPE"] = cases[caseNdx].scResultType;
6538 specializations["SC_OP"] = cases[caseNdx].scOperation;
6539 specializations["GEN_RESULT"] = cases[caseNdx].resultOperation;
6541 fragments["decoration"] = tcu::StringTemplate(decorations1).specialize(specializations);
6542 fragments["pre_main"] = tcu::StringTemplate(typesAndConstants1).specialize(specializations);
6543 fragments["testfun"] = tcu::StringTemplate(function1).specialize(specializations);
6545 specConstants.push_back(cases[caseNdx].scActualValue0);
6546 specConstants.push_back(cases[caseNdx].scActualValue1);
6548 createTestsForAllStages(cases[caseNdx].caseName, inputColors, cases[caseNdx].expectedColors, fragments, specConstants, group.get());
6551 const char decorations2[] =
6552 "OpDecorate %sc_0 SpecId 0\n"
6553 "OpDecorate %sc_1 SpecId 1\n"
6554 "OpDecorate %sc_2 SpecId 2\n";
6556 const char typesAndConstants2[] =
6557 "%v3i32 = OpTypeVector %i32 3\n"
6559 "%sc_0 = OpSpecConstant %i32 0\n"
6560 "%sc_1 = OpSpecConstant %i32 0\n"
6561 "%sc_2 = OpSpecConstant %i32 0\n"
6563 "%vec3_0 = OpConstantComposite %v3i32 %c_i32_0 %c_i32_0 %c_i32_0\n"
6564 "%sc_vec3_0 = OpSpecConstantOp %v3i32 CompositeInsert %sc_0 %vec3_0 0\n" // (sc_0, 0, 0)
6565 "%sc_vec3_1 = OpSpecConstantOp %v3i32 CompositeInsert %sc_1 %vec3_0 1\n" // (0, sc_1, 0)
6566 "%sc_vec3_2 = OpSpecConstantOp %v3i32 CompositeInsert %sc_2 %vec3_0 2\n" // (0, 0, sc_2)
6567 "%sc_vec3_01 = OpSpecConstantOp %v3i32 VectorShuffle %sc_vec3_0 %sc_vec3_1 1 0 4\n" // (0, sc_0, sc_1)
6568 "%sc_vec3_012 = OpSpecConstantOp %v3i32 VectorShuffle %sc_vec3_01 %sc_vec3_2 5 1 2\n" // (sc_2, sc_0, sc_1)
6569 "%sc_ext_0 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 0\n" // sc_2
6570 "%sc_ext_1 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 1\n" // sc_0
6571 "%sc_ext_2 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 2\n" // sc_1
6572 "%sc_sub = OpSpecConstantOp %i32 ISub %sc_ext_0 %sc_ext_1\n" // (sc_2 - sc_0)
6573 "%sc_final = OpSpecConstantOp %i32 IMul %sc_sub %sc_ext_2\n"; // (sc_2 - sc_0) * sc_1
6575 const char function2[] =
6576 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6577 "%param = OpFunctionParameter %v4f32\n"
6578 "%label = OpLabel\n"
6579 "%result = OpVariable %fp_v4f32 Function\n"
6580 " OpStore %result %param\n"
6581 "%loc = OpAccessChain %fp_f32 %result %sc_final\n"
6582 "%val = OpLoad %f32 %loc\n"
6583 "%add = OpFAdd %f32 %val %c_f32_0_5\n"
6584 " OpStore %loc %add\n"
6585 "%ret = OpLoad %v4f32 %result\n"
6586 " OpReturnValue %ret\n"
6589 map<string, string> fragments;
6590 vector<deInt32> specConstants;
6592 fragments["decoration"] = decorations2;
6593 fragments["pre_main"] = typesAndConstants2;
6594 fragments["testfun"] = function2;
6596 specConstants.push_back(56789);
6597 specConstants.push_back(-2);
6598 specConstants.push_back(56788);
6600 createTestsForAllStages("vector_related", inputColors, outputColors2, fragments, specConstants, group.get());
6602 return group.release();
6605 tcu::TestCaseGroup* createOpPhiTests(tcu::TestContext& testCtx)
6607 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opphi", "Test the OpPhi instruction"));
6608 RGBA inputColors[4];
6609 RGBA outputColors1[4];
6610 RGBA outputColors2[4];
6611 RGBA outputColors3[4];
6612 map<string, string> fragments1;
6613 map<string, string> fragments2;
6614 map<string, string> fragments3;
6616 const char typesAndConstants1[] =
6617 "%c_f32_p2 = OpConstant %f32 0.2\n"
6618 "%c_f32_p4 = OpConstant %f32 0.4\n"
6619 "%c_f32_p5 = OpConstant %f32 0.5\n"
6620 "%c_f32_p8 = OpConstant %f32 0.8\n";
6622 // vec4 test_code(vec4 param) {
6623 // vec4 result = param;
6624 // for (int i = 0; i < 4; ++i) {
6627 // case 0: operand = .2; break;
6628 // case 1: operand = .5; break;
6629 // case 2: operand = .4; break;
6630 // case 3: operand = .0; break;
6631 // default: break; // unreachable
6633 // result[i] += operand;
6637 const char function1[] =
6638 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6639 "%param1 = OpFunctionParameter %v4f32\n"
6641 "%iptr = OpVariable %fp_i32 Function\n"
6642 "%result = OpVariable %fp_v4f32 Function\n"
6643 " OpStore %iptr %c_i32_0\n"
6644 " OpStore %result %param1\n"
6648 "%ival = OpLoad %i32 %iptr\n"
6649 "%lt_4 = OpSLessThan %bool %ival %c_i32_4\n"
6650 " OpLoopMerge %exit %loop None\n"
6651 " OpBranchConditional %lt_4 %entry %exit\n"
6653 "%entry = OpLabel\n"
6654 "%loc = OpAccessChain %fp_f32 %result %ival\n"
6655 "%val = OpLoad %f32 %loc\n"
6656 " OpSelectionMerge %phi None\n"
6657 " OpSwitch %ival %default 0 %case0 1 %case1 2 %case2 3 %case3\n"
6659 "%case0 = OpLabel\n"
6661 "%case1 = OpLabel\n"
6663 "%case2 = OpLabel\n"
6665 "%case3 = OpLabel\n"
6668 "%default = OpLabel\n"
6672 "%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
6673 "%add = OpFAdd %f32 %val %operand\n"
6674 " OpStore %loc %add\n"
6675 "%ival_next = OpIAdd %i32 %ival %c_i32_1\n"
6676 " OpStore %iptr %ival_next\n"
6680 "%ret = OpLoad %v4f32 %result\n"
6681 " OpReturnValue %ret\n"
6685 fragments1["pre_main"] = typesAndConstants1;
6686 fragments1["testfun"] = function1;
6688 getHalfColorsFullAlpha(inputColors);
6690 outputColors1[0] = RGBA(178, 255, 229, 255);
6691 outputColors1[1] = RGBA(178, 127, 102, 255);
6692 outputColors1[2] = RGBA(51, 255, 102, 255);
6693 outputColors1[3] = RGBA(51, 127, 229, 255);
6695 createTestsForAllStages("out_of_order", inputColors, outputColors1, fragments1, group.get());
6697 const char typesAndConstants2[] =
6698 "%c_f32_p2 = OpConstant %f32 0.2\n";
6700 // Add .4 to the second element of the given parameter.
6701 const char function2[] =
6702 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6703 "%param = OpFunctionParameter %v4f32\n"
6704 "%entry = OpLabel\n"
6705 "%result = OpVariable %fp_v4f32 Function\n"
6706 " OpStore %result %param\n"
6707 "%loc = OpAccessChain %fp_f32 %result %c_i32_1\n"
6708 "%val = OpLoad %f32 %loc\n"
6712 "%step = OpPhi %i32 %c_i32_0 %entry %step_next %phi\n"
6713 "%accum = OpPhi %f32 %val %entry %accum_next %phi\n"
6714 "%step_next = OpIAdd %i32 %step %c_i32_1\n"
6715 "%accum_next = OpFAdd %f32 %accum %c_f32_p2\n"
6716 "%still_loop = OpSLessThan %bool %step %c_i32_2\n"
6717 " OpLoopMerge %exit %phi None\n"
6718 " OpBranchConditional %still_loop %phi %exit\n"
6721 " OpStore %loc %accum\n"
6722 "%ret = OpLoad %v4f32 %result\n"
6723 " OpReturnValue %ret\n"
6727 fragments2["pre_main"] = typesAndConstants2;
6728 fragments2["testfun"] = function2;
6730 outputColors2[0] = RGBA(127, 229, 127, 255);
6731 outputColors2[1] = RGBA(127, 102, 0, 255);
6732 outputColors2[2] = RGBA(0, 229, 0, 255);
6733 outputColors2[3] = RGBA(0, 102, 127, 255);
6735 createTestsForAllStages("induction", inputColors, outputColors2, fragments2, group.get());
6737 const char typesAndConstants3[] =
6738 "%true = OpConstantTrue %bool\n"
6739 "%false = OpConstantFalse %bool\n"
6740 "%c_f32_p2 = OpConstant %f32 0.2\n";
6742 // Swap the second and the third element of the given parameter.
6743 const char function3[] =
6744 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6745 "%param = OpFunctionParameter %v4f32\n"
6746 "%entry = OpLabel\n"
6747 "%result = OpVariable %fp_v4f32 Function\n"
6748 " OpStore %result %param\n"
6749 "%a_loc = OpAccessChain %fp_f32 %result %c_i32_1\n"
6750 "%a_init = OpLoad %f32 %a_loc\n"
6751 "%b_loc = OpAccessChain %fp_f32 %result %c_i32_2\n"
6752 "%b_init = OpLoad %f32 %b_loc\n"
6756 "%still_loop = OpPhi %bool %true %entry %false %phi\n"
6757 "%a_next = OpPhi %f32 %a_init %entry %b_next %phi\n"
6758 "%b_next = OpPhi %f32 %b_init %entry %a_next %phi\n"
6759 " OpLoopMerge %exit %phi None\n"
6760 " OpBranchConditional %still_loop %phi %exit\n"
6763 " OpStore %a_loc %a_next\n"
6764 " OpStore %b_loc %b_next\n"
6765 "%ret = OpLoad %v4f32 %result\n"
6766 " OpReturnValue %ret\n"
6770 fragments3["pre_main"] = typesAndConstants3;
6771 fragments3["testfun"] = function3;
6773 outputColors3[0] = RGBA(127, 127, 127, 255);
6774 outputColors3[1] = RGBA(127, 0, 0, 255);
6775 outputColors3[2] = RGBA(0, 0, 127, 255);
6776 outputColors3[3] = RGBA(0, 127, 0, 255);
6778 createTestsForAllStages("swap", inputColors, outputColors3, fragments3, group.get());
6780 return group.release();
6783 tcu::TestCaseGroup* createNoContractionTests(tcu::TestContext& testCtx)
6785 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "nocontraction", "Test the NoContraction decoration"));
6786 RGBA inputColors[4];
6787 RGBA outputColors[4];
6789 // With NoContraction, (1 + 2^-23) * (1 - 2^-23) - 1 should be conducted as a multiplication and an addition separately.
6790 // For the multiplication, the result is 1 - 2^-46, which is out of the precision range for 32-bit float. (32-bit float
6791 // only have 23-bit fraction.) So it will be rounded to 1. Or 0x1.fffffc. Then the final result is 0 or -0x1p-24.
6792 // On the contrary, the result will be 2^-46, which is a normalized number perfectly representable as 32-bit float.
6793 const char constantsAndTypes[] =
6794 "%c_vec4_0 = OpConstantComposite %v4f32 %c_f32_0 %c_f32_0 %c_f32_0 %c_f32_1\n"
6795 "%c_vec4_1 = OpConstantComposite %v4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_1\n"
6796 "%c_f32_1pl2_23 = OpConstant %f32 0x1.000002p+0\n" // 1 + 2^-23
6797 "%c_f32_1mi2_23 = OpConstant %f32 0x1.fffffcp-1\n" // 1 - 2^-23
6798 "%c_f32_n1pn24 = OpConstant %f32 -0x1p-24\n"
6801 const char function[] =
6802 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6803 "%param = OpFunctionParameter %v4f32\n"
6804 "%label = OpLabel\n"
6805 "%var1 = OpVariable %fp_f32 Function %c_f32_1pl2_23\n"
6806 "%var2 = OpVariable %fp_f32 Function\n"
6807 "%red = OpCompositeExtract %f32 %param 0\n"
6808 "%plus_red = OpFAdd %f32 %c_f32_1mi2_23 %red\n"
6809 " OpStore %var2 %plus_red\n"
6810 "%val1 = OpLoad %f32 %var1\n"
6811 "%val2 = OpLoad %f32 %var2\n"
6812 "%mul = OpFMul %f32 %val1 %val2\n"
6813 "%add = OpFAdd %f32 %mul %c_f32_n1\n"
6814 "%is0 = OpFOrdEqual %bool %add %c_f32_0\n"
6815 "%isn1n24 = OpFOrdEqual %bool %add %c_f32_n1pn24\n"
6816 "%success = OpLogicalOr %bool %is0 %isn1n24\n"
6817 "%v4success = OpCompositeConstruct %v4bool %success %success %success %success\n"
6818 "%ret = OpSelect %v4f32 %v4success %c_vec4_0 %c_vec4_1\n"
6819 " OpReturnValue %ret\n"
6822 struct CaseNameDecoration
6829 CaseNameDecoration tests[] = {
6830 {"multiplication", "OpDecorate %mul NoContraction"},
6831 {"addition", "OpDecorate %add NoContraction"},
6832 {"both", "OpDecorate %mul NoContraction\nOpDecorate %add NoContraction"},
6835 getHalfColorsFullAlpha(inputColors);
6837 for (deUint8 idx = 0; idx < 4; ++idx)
6839 inputColors[idx].setRed(0);
6840 outputColors[idx] = RGBA(0, 0, 0, 255);
6843 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(CaseNameDecoration); ++testNdx)
6845 map<string, string> fragments;
6847 fragments["decoration"] = tests[testNdx].decoration;
6848 fragments["pre_main"] = constantsAndTypes;
6849 fragments["testfun"] = function;
6851 createTestsForAllStages(tests[testNdx].name, inputColors, outputColors, fragments, group.get());
6854 return group.release();
6857 tcu::TestCaseGroup* createMemoryAccessTests(tcu::TestContext& testCtx)
6859 de::MovePtr<tcu::TestCaseGroup> memoryAccessTests (new tcu::TestCaseGroup(testCtx, "opmemoryaccess", "Memory Semantics"));
6862 const char constantsAndTypes[] =
6863 "%c_a2f32_1 = OpConstantComposite %a2f32 %c_f32_1 %c_f32_1\n"
6864 "%fp_a2f32 = OpTypePointer Function %a2f32\n"
6865 "%stype = OpTypeStruct %v4f32 %a2f32 %f32\n"
6866 "%fp_stype = OpTypePointer Function %stype\n";
6868 const char function[] =
6869 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6870 "%param1 = OpFunctionParameter %v4f32\n"
6872 "%v1 = OpVariable %fp_v4f32 Function\n"
6873 "%v2 = OpVariable %fp_a2f32 Function\n"
6874 "%v3 = OpVariable %fp_f32 Function\n"
6875 "%v = OpVariable %fp_stype Function\n"
6876 "%vv = OpVariable %fp_stype Function\n"
6877 "%vvv = OpVariable %fp_f32 Function\n"
6879 " OpStore %v1 %c_v4f32_1_1_1_1\n"
6880 " OpStore %v2 %c_a2f32_1\n"
6881 " OpStore %v3 %c_f32_1\n"
6883 "%p_v4f32 = OpAccessChain %fp_v4f32 %v %c_u32_0\n"
6884 "%p_a2f32 = OpAccessChain %fp_a2f32 %v %c_u32_1\n"
6885 "%p_f32 = OpAccessChain %fp_f32 %v %c_u32_2\n"
6886 "%v1_v = OpLoad %v4f32 %v1 ${access_type}\n"
6887 "%v2_v = OpLoad %a2f32 %v2 ${access_type}\n"
6888 "%v3_v = OpLoad %f32 %v3 ${access_type}\n"
6890 " OpStore %p_v4f32 %v1_v ${access_type}\n"
6891 " OpStore %p_a2f32 %v2_v ${access_type}\n"
6892 " OpStore %p_f32 %v3_v ${access_type}\n"
6894 " OpCopyMemory %vv %v ${access_type}\n"
6895 " OpCopyMemory %vvv %p_f32 ${access_type}\n"
6897 "%p_f32_2 = OpAccessChain %fp_f32 %vv %c_u32_2\n"
6898 "%v_f32_2 = OpLoad %f32 %p_f32_2\n"
6899 "%v_f32_3 = OpLoad %f32 %vvv\n"
6901 "%ret1 = OpVectorTimesScalar %v4f32 %param1 %v_f32_2\n"
6902 "%ret2 = OpVectorTimesScalar %v4f32 %ret1 %v_f32_3\n"
6903 " OpReturnValue %ret2\n"
6906 struct NameMemoryAccess
6913 NameMemoryAccess tests[] =
6916 { "volatile", "Volatile" },
6917 { "aligned", "Aligned 1" },
6918 { "volatile_aligned", "Volatile|Aligned 1" },
6919 { "nontemporal_aligned", "Nontemporal|Aligned 1" },
6920 { "volatile_nontemporal", "Volatile|Nontemporal" },
6921 { "volatile_nontermporal_aligned", "Volatile|Nontemporal|Aligned 1" },
6924 getHalfColorsFullAlpha(colors);
6926 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameMemoryAccess); ++testNdx)
6928 map<string, string> fragments;
6929 map<string, string> memoryAccess;
6930 memoryAccess["access_type"] = tests[testNdx].accessType;
6932 fragments["pre_main"] = constantsAndTypes;
6933 fragments["testfun"] = tcu::StringTemplate(function).specialize(memoryAccess);
6934 createTestsForAllStages(tests[testNdx].name, colors, colors, fragments, memoryAccessTests.get());
6936 return memoryAccessTests.release();
6938 tcu::TestCaseGroup* createOpUndefTests(tcu::TestContext& testCtx)
6940 de::MovePtr<tcu::TestCaseGroup> opUndefTests (new tcu::TestCaseGroup(testCtx, "opundef", "Test OpUndef"));
6941 RGBA defaultColors[4];
6942 map<string, string> fragments;
6943 getDefaultColors(defaultColors);
6945 // First, simple cases that don't do anything with the OpUndef result.
6946 fragments["testfun"] =
6947 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6948 "%param1 = OpFunctionParameter %v4f32\n"
6949 "%label_testfun = OpLabel\n"
6950 "%undef = OpUndef %type\n"
6951 "OpReturnValue %param1\n"
6954 struct NameCodePair { string name, code; };
6955 const NameCodePair tests[] =
6957 {"bool", "%type = OpTypeBool"},
6958 {"vec2uint32", "%type = OpTypeVector %u32 2"},
6959 {"image", "%type = OpTypeImage %f32 2D 0 0 0 1 Unknown"},
6960 {"sampler", "%type = OpTypeSampler"},
6961 {"sampledimage", "%img = OpTypeImage %f32 2D 0 0 0 1 Unknown\n" "%type = OpTypeSampledImage %img"},
6962 {"pointer", "%type = OpTypePointer Function %i32"},
6963 {"runtimearray", "%type = OpTypeRuntimeArray %f32"},
6964 {"array", "%c_u32_100 = OpConstant %u32 100\n" "%type = OpTypeArray %i32 %c_u32_100"},
6965 {"struct", "%type = OpTypeStruct %f32 %i32 %u32"}};
6966 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameCodePair); ++testNdx)
6968 fragments["pre_main"] = tests[testNdx].code;
6969 createTestsForAllStages(tests[testNdx].name, defaultColors, defaultColors, fragments, opUndefTests.get());
6973 fragments["testfun"] =
6974 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6975 "%param1 = OpFunctionParameter %v4f32\n"
6976 "%label_testfun = OpLabel\n"
6977 "%undef = OpUndef %f32\n"
6978 "%zero = OpFMul %f32 %undef %c_f32_0\n"
6979 "%is_nan = OpIsNan %bool %zero\n" //OpUndef may result in NaN which may turn %zero into Nan.
6980 "%actually_zero = OpSelect %f32 %is_nan %c_f32_0 %zero\n"
6981 "%a = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
6982 "%b = OpFAdd %f32 %a %actually_zero\n"
6983 "%ret = OpVectorInsertDynamic %v4f32 %param1 %b %c_i32_0\n"
6984 "OpReturnValue %ret\n"
6987 createTestsForAllStages("float32", defaultColors, defaultColors, fragments, opUndefTests.get());
6989 fragments["testfun"] =
6990 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6991 "%param1 = OpFunctionParameter %v4f32\n"
6992 "%label_testfun = OpLabel\n"
6993 "%undef = OpUndef %i32\n"
6994 "%zero = OpIMul %i32 %undef %c_i32_0\n"
6995 "%a = OpVectorExtractDynamic %f32 %param1 %zero\n"
6996 "%ret = OpVectorInsertDynamic %v4f32 %param1 %a %c_i32_0\n"
6997 "OpReturnValue %ret\n"
7000 createTestsForAllStages("sint32", defaultColors, defaultColors, fragments, opUndefTests.get());
7002 fragments["testfun"] =
7003 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
7004 "%param1 = OpFunctionParameter %v4f32\n"
7005 "%label_testfun = OpLabel\n"
7006 "%undef = OpUndef %u32\n"
7007 "%zero = OpIMul %u32 %undef %c_i32_0\n"
7008 "%a = OpVectorExtractDynamic %f32 %param1 %zero\n"
7009 "%ret = OpVectorInsertDynamic %v4f32 %param1 %a %c_i32_0\n"
7010 "OpReturnValue %ret\n"
7013 createTestsForAllStages("uint32", defaultColors, defaultColors, fragments, opUndefTests.get());
7015 fragments["testfun"] =
7016 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
7017 "%param1 = OpFunctionParameter %v4f32\n"
7018 "%label_testfun = OpLabel\n"
7019 "%undef = OpUndef %v4f32\n"
7020 "%vzero = OpVectorTimesScalar %v4f32 %undef %c_f32_0\n"
7021 "%zero_0 = OpVectorExtractDynamic %f32 %vzero %c_i32_0\n"
7022 "%zero_1 = OpVectorExtractDynamic %f32 %vzero %c_i32_1\n"
7023 "%zero_2 = OpVectorExtractDynamic %f32 %vzero %c_i32_2\n"
7024 "%zero_3 = OpVectorExtractDynamic %f32 %vzero %c_i32_3\n"
7025 "%is_nan_0 = OpIsNan %bool %zero_0\n"
7026 "%is_nan_1 = OpIsNan %bool %zero_1\n"
7027 "%is_nan_2 = OpIsNan %bool %zero_2\n"
7028 "%is_nan_3 = OpIsNan %bool %zero_3\n"
7029 "%actually_zero_0 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_0\n"
7030 "%actually_zero_1 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_1\n"
7031 "%actually_zero_2 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_2\n"
7032 "%actually_zero_3 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_3\n"
7033 "%param1_0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
7034 "%param1_1 = OpVectorExtractDynamic %f32 %param1 %c_i32_1\n"
7035 "%param1_2 = OpVectorExtractDynamic %f32 %param1 %c_i32_2\n"
7036 "%param1_3 = OpVectorExtractDynamic %f32 %param1 %c_i32_3\n"
7037 "%sum_0 = OpFAdd %f32 %param1_0 %actually_zero_0\n"
7038 "%sum_1 = OpFAdd %f32 %param1_1 %actually_zero_1\n"
7039 "%sum_2 = OpFAdd %f32 %param1_2 %actually_zero_2\n"
7040 "%sum_3 = OpFAdd %f32 %param1_3 %actually_zero_3\n"
7041 "%ret3 = OpVectorInsertDynamic %v4f32 %param1 %sum_3 %c_i32_3\n"
7042 "%ret2 = OpVectorInsertDynamic %v4f32 %ret3 %sum_2 %c_i32_2\n"
7043 "%ret1 = OpVectorInsertDynamic %v4f32 %ret2 %sum_1 %c_i32_1\n"
7044 "%ret = OpVectorInsertDynamic %v4f32 %ret1 %sum_0 %c_i32_0\n"
7045 "OpReturnValue %ret\n"
7048 createTestsForAllStages("vec4float32", defaultColors, defaultColors, fragments, opUndefTests.get());
7050 fragments["pre_main"] =
7051 "%v2f32 = OpTypeVector %f32 2\n"
7052 "%m2x2f32 = OpTypeMatrix %v2f32 2\n";
7053 fragments["testfun"] =
7054 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
7055 "%param1 = OpFunctionParameter %v4f32\n"
7056 "%label_testfun = OpLabel\n"
7057 "%undef = OpUndef %m2x2f32\n"
7058 "%mzero = OpMatrixTimesScalar %m2x2f32 %undef %c_f32_0\n"
7059 "%zero_0 = OpCompositeExtract %f32 %mzero 0 0\n"
7060 "%zero_1 = OpCompositeExtract %f32 %mzero 0 1\n"
7061 "%zero_2 = OpCompositeExtract %f32 %mzero 1 0\n"
7062 "%zero_3 = OpCompositeExtract %f32 %mzero 1 1\n"
7063 "%is_nan_0 = OpIsNan %bool %zero_0\n"
7064 "%is_nan_1 = OpIsNan %bool %zero_1\n"
7065 "%is_nan_2 = OpIsNan %bool %zero_2\n"
7066 "%is_nan_3 = OpIsNan %bool %zero_3\n"
7067 "%actually_zero_0 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_0\n"
7068 "%actually_zero_1 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_1\n"
7069 "%actually_zero_2 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_2\n"
7070 "%actually_zero_3 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_3\n"
7071 "%param1_0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
7072 "%param1_1 = OpVectorExtractDynamic %f32 %param1 %c_i32_1\n"
7073 "%param1_2 = OpVectorExtractDynamic %f32 %param1 %c_i32_2\n"
7074 "%param1_3 = OpVectorExtractDynamic %f32 %param1 %c_i32_3\n"
7075 "%sum_0 = OpFAdd %f32 %param1_0 %actually_zero_0\n"
7076 "%sum_1 = OpFAdd %f32 %param1_1 %actually_zero_1\n"
7077 "%sum_2 = OpFAdd %f32 %param1_2 %actually_zero_2\n"
7078 "%sum_3 = OpFAdd %f32 %param1_3 %actually_zero_3\n"
7079 "%ret3 = OpVectorInsertDynamic %v4f32 %param1 %sum_3 %c_i32_3\n"
7080 "%ret2 = OpVectorInsertDynamic %v4f32 %ret3 %sum_2 %c_i32_2\n"
7081 "%ret1 = OpVectorInsertDynamic %v4f32 %ret2 %sum_1 %c_i32_1\n"
7082 "%ret = OpVectorInsertDynamic %v4f32 %ret1 %sum_0 %c_i32_0\n"
7083 "OpReturnValue %ret\n"
7086 createTestsForAllStages("matrix", defaultColors, defaultColors, fragments, opUndefTests.get());
7088 return opUndefTests.release();
7091 void createOpQuantizeSingleOptionTests(tcu::TestCaseGroup* testCtx)
7093 const RGBA inputColors[4] =
7096 RGBA(0, 0, 255, 255),
7097 RGBA(0, 255, 0, 255),
7098 RGBA(0, 255, 255, 255)
7101 const RGBA expectedColors[4] =
7103 RGBA(255, 0, 0, 255),
7104 RGBA(255, 0, 0, 255),
7105 RGBA(255, 0, 0, 255),
7106 RGBA(255, 0, 0, 255)
7109 const struct SingleFP16Possibility
7112 const char* constant; // Value to assign to %test_constant.
7114 const char* condition; // Must assign to %cond an expression that evaluates to true after %c = OpQuantizeToF16(%test_constant + 0).
7120 -constructNormalizedFloat(1, 0x300000),
7121 "%cond = OpFOrdEqual %bool %c %test_constant\n"
7126 constructNormalizedFloat(7, 0x000000),
7127 "%cond = OpFOrdEqual %bool %c %test_constant\n"
7129 // SPIR-V requires that OpQuantizeToF16 flushes
7130 // any numbers that would end up denormalized in F16 to zero.
7134 std::ldexp(1.5f, -140),
7135 "%cond = OpFOrdEqual %bool %c %c_f32_0\n"
7140 -std::ldexp(1.5f, -140),
7141 "%cond = OpFOrdEqual %bool %c %c_f32_0\n"
7146 std::ldexp(1.0f, -16),
7147 "%cond = OpFOrdEqual %bool %c %c_f32_0\n"
7148 }, // too small positive
7150 "negative_too_small",
7152 -std::ldexp(1.0f, -32),
7153 "%cond = OpFOrdEqual %bool %c %c_f32_0\n"
7154 }, // too small negative
7158 -std::ldexp(1.0f, 128),
7160 "%gz = OpFOrdLessThan %bool %c %c_f32_0\n"
7161 "%inf = OpIsInf %bool %c\n"
7162 "%cond = OpLogicalAnd %bool %gz %inf\n"
7167 std::ldexp(1.0f, 128),
7169 "%gz = OpFOrdGreaterThan %bool %c %c_f32_0\n"
7170 "%inf = OpIsInf %bool %c\n"
7171 "%cond = OpLogicalAnd %bool %gz %inf\n"
7174 "round_to_negative_inf",
7176 -std::ldexp(1.0f, 32),
7178 "%gz = OpFOrdLessThan %bool %c %c_f32_0\n"
7179 "%inf = OpIsInf %bool %c\n"
7180 "%cond = OpLogicalAnd %bool %gz %inf\n"
7185 std::ldexp(1.0f, 16),
7187 "%gz = OpFOrdGreaterThan %bool %c %c_f32_0\n"
7188 "%inf = OpIsInf %bool %c\n"
7189 "%cond = OpLogicalAnd %bool %gz %inf\n"
7194 std::numeric_limits<float>::quiet_NaN(),
7196 // Test for any NaN value, as NaNs are not preserved
7197 "%direct_quant = OpQuantizeToF16 %f32 %test_constant\n"
7198 "%cond = OpIsNan %bool %direct_quant\n"
7203 std::numeric_limits<float>::quiet_NaN(),
7205 // Test for any NaN value, as NaNs are not preserved
7206 "%direct_quant = OpQuantizeToF16 %f32 %test_constant\n"
7207 "%cond = OpIsNan %bool %direct_quant\n"
7210 const char* constants =
7211 "%test_constant = OpConstant %f32 "; // The value will be test.constant.
7213 StringTemplate function (
7214 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
7215 "%param1 = OpFunctionParameter %v4f32\n"
7216 "%label_testfun = OpLabel\n"
7217 "%a = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
7218 "%b = OpFAdd %f32 %test_constant %a\n"
7219 "%c = OpQuantizeToF16 %f32 %b\n"
7221 "%v4cond = OpCompositeConstruct %v4bool %cond %cond %cond %cond\n"
7222 "%retval = OpSelect %v4f32 %v4cond %c_v4f32_1_0_0_1 %param1\n"
7223 " OpReturnValue %retval\n"
7227 const char* specDecorations = "OpDecorate %test_constant SpecId 0\n";
7228 const char* specConstants =
7229 "%test_constant = OpSpecConstant %f32 0.\n"
7230 "%c = OpSpecConstantOp %f32 QuantizeToF16 %test_constant\n";
7232 StringTemplate specConstantFunction(
7233 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
7234 "%param1 = OpFunctionParameter %v4f32\n"
7235 "%label_testfun = OpLabel\n"
7237 "%v4cond = OpCompositeConstruct %v4bool %cond %cond %cond %cond\n"
7238 "%retval = OpSelect %v4f32 %v4cond %c_v4f32_1_0_0_1 %param1\n"
7239 " OpReturnValue %retval\n"
7243 for (size_t idx = 0; idx < (sizeof(tests)/sizeof(tests[0])); ++idx)
7245 map<string, string> codeSpecialization;
7246 map<string, string> fragments;
7247 codeSpecialization["condition"] = tests[idx].condition;
7248 fragments["testfun"] = function.specialize(codeSpecialization);
7249 fragments["pre_main"] = string(constants) + tests[idx].constant + "\n";
7250 createTestsForAllStages(tests[idx].name, inputColors, expectedColors, fragments, testCtx);
7253 for (size_t idx = 0; idx < (sizeof(tests)/sizeof(tests[0])); ++idx)
7255 map<string, string> codeSpecialization;
7256 map<string, string> fragments;
7257 vector<deInt32> passConstants;
7258 deInt32 specConstant;
7260 codeSpecialization["condition"] = tests[idx].condition;
7261 fragments["testfun"] = specConstantFunction.specialize(codeSpecialization);
7262 fragments["decoration"] = specDecorations;
7263 fragments["pre_main"] = specConstants;
7265 memcpy(&specConstant, &tests[idx].valueAsFloat, sizeof(float));
7266 passConstants.push_back(specConstant);
7268 createTestsForAllStages(string("spec_const_") + tests[idx].name, inputColors, expectedColors, fragments, passConstants, testCtx);
7272 void createOpQuantizeTwoPossibilityTests(tcu::TestCaseGroup* testCtx)
7274 RGBA inputColors[4] = {
7276 RGBA(0, 0, 255, 255),
7277 RGBA(0, 255, 0, 255),
7278 RGBA(0, 255, 255, 255)
7281 RGBA expectedColors[4] =
7283 RGBA(255, 0, 0, 255),
7284 RGBA(255, 0, 0, 255),
7285 RGBA(255, 0, 0, 255),
7286 RGBA(255, 0, 0, 255)
7289 struct DualFP16Possibility
7294 const char* possibleOutput1;
7295 const char* possibleOutput2;
7298 "positive_round_up_or_round_down",
7300 constructNormalizedFloat(8, 0x300300),
7305 "negative_round_up_or_round_down",
7307 -constructNormalizedFloat(-7, 0x600800),
7314 constructNormalizedFloat(2, 0x01e000),
7319 "carry_to_exponent",
7321 constructNormalizedFloat(1, 0xffe000),
7326 StringTemplate constants (
7327 "%input_const = OpConstant %f32 ${input}\n"
7328 "%possible_solution1 = OpConstant %f32 ${output1}\n"
7329 "%possible_solution2 = OpConstant %f32 ${output2}\n"
7332 StringTemplate specConstants (
7333 "%input_const = OpSpecConstant %f32 0.\n"
7334 "%possible_solution1 = OpConstant %f32 ${output1}\n"
7335 "%possible_solution2 = OpConstant %f32 ${output2}\n"
7338 const char* specDecorations = "OpDecorate %input_const SpecId 0\n";
7340 const char* function =
7341 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
7342 "%param1 = OpFunctionParameter %v4f32\n"
7343 "%label_testfun = OpLabel\n"
7344 "%a = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
7345 // For the purposes of this test we assume that 0.f will always get
7346 // faithfully passed through the pipeline stages.
7347 "%b = OpFAdd %f32 %input_const %a\n"
7348 "%c = OpQuantizeToF16 %f32 %b\n"
7349 "%eq_1 = OpFOrdEqual %bool %c %possible_solution1\n"
7350 "%eq_2 = OpFOrdEqual %bool %c %possible_solution2\n"
7351 "%cond = OpLogicalOr %bool %eq_1 %eq_2\n"
7352 "%v4cond = OpCompositeConstruct %v4bool %cond %cond %cond %cond\n"
7353 "%retval = OpSelect %v4f32 %v4cond %c_v4f32_1_0_0_1 %param1"
7354 " OpReturnValue %retval\n"
7357 for(size_t idx = 0; idx < (sizeof(tests)/sizeof(tests[0])); ++idx) {
7358 map<string, string> fragments;
7359 map<string, string> constantSpecialization;
7361 constantSpecialization["input"] = tests[idx].input;
7362 constantSpecialization["output1"] = tests[idx].possibleOutput1;
7363 constantSpecialization["output2"] = tests[idx].possibleOutput2;
7364 fragments["testfun"] = function;
7365 fragments["pre_main"] = constants.specialize(constantSpecialization);
7366 createTestsForAllStages(tests[idx].name, inputColors, expectedColors, fragments, testCtx);
7369 for(size_t idx = 0; idx < (sizeof(tests)/sizeof(tests[0])); ++idx) {
7370 map<string, string> fragments;
7371 map<string, string> constantSpecialization;
7372 vector<deInt32> passConstants;
7373 deInt32 specConstant;
7375 constantSpecialization["output1"] = tests[idx].possibleOutput1;
7376 constantSpecialization["output2"] = tests[idx].possibleOutput2;
7377 fragments["testfun"] = function;
7378 fragments["decoration"] = specDecorations;
7379 fragments["pre_main"] = specConstants.specialize(constantSpecialization);
7381 memcpy(&specConstant, &tests[idx].inputAsFloat, sizeof(float));
7382 passConstants.push_back(specConstant);
7384 createTestsForAllStages(string("spec_const_") + tests[idx].name, inputColors, expectedColors, fragments, passConstants, testCtx);
7388 tcu::TestCaseGroup* createOpQuantizeTests(tcu::TestContext& testCtx)
7390 de::MovePtr<tcu::TestCaseGroup> opQuantizeTests (new tcu::TestCaseGroup(testCtx, "opquantize", "Test OpQuantizeToF16"));
7391 createOpQuantizeSingleOptionTests(opQuantizeTests.get());
7392 createOpQuantizeTwoPossibilityTests(opQuantizeTests.get());
7393 return opQuantizeTests.release();
7396 struct ShaderPermutation
7398 deUint8 vertexPermutation;
7399 deUint8 geometryPermutation;
7400 deUint8 tesscPermutation;
7401 deUint8 tessePermutation;
7402 deUint8 fragmentPermutation;
7405 ShaderPermutation getShaderPermutation(deUint8 inputValue)
7407 ShaderPermutation permutation =
7409 static_cast<deUint8>(inputValue & 0x10? 1u: 0u),
7410 static_cast<deUint8>(inputValue & 0x08? 1u: 0u),
7411 static_cast<deUint8>(inputValue & 0x04? 1u: 0u),
7412 static_cast<deUint8>(inputValue & 0x02? 1u: 0u),
7413 static_cast<deUint8>(inputValue & 0x01? 1u: 0u)
7418 tcu::TestCaseGroup* createModuleTests(tcu::TestContext& testCtx)
7420 RGBA defaultColors[4];
7421 RGBA invertedColors[4];
7422 de::MovePtr<tcu::TestCaseGroup> moduleTests (new tcu::TestCaseGroup(testCtx, "module", "Multiple entry points into shaders"));
7424 const ShaderElement combinedPipeline[] =
7426 ShaderElement("module", "main", VK_SHADER_STAGE_VERTEX_BIT),
7427 ShaderElement("module", "main", VK_SHADER_STAGE_GEOMETRY_BIT),
7428 ShaderElement("module", "main", VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT),
7429 ShaderElement("module", "main", VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT),
7430 ShaderElement("module", "main", VK_SHADER_STAGE_FRAGMENT_BIT)
7433 getDefaultColors(defaultColors);
7434 getInvertedDefaultColors(invertedColors);
7435 addFunctionCaseWithPrograms<InstanceContext>(moduleTests.get(), "same_module", "", createCombinedModule, runAndVerifyDefaultPipeline, createInstanceContext(combinedPipeline, map<string, string>()));
7437 const char* numbers[] =
7442 for (deInt8 idx = 0; idx < 32; ++idx)
7444 ShaderPermutation permutation = getShaderPermutation(idx);
7445 string name = string("vert") + numbers[permutation.vertexPermutation] + "_geom" + numbers[permutation.geometryPermutation] + "_tessc" + numbers[permutation.tesscPermutation] + "_tesse" + numbers[permutation.tessePermutation] + "_frag" + numbers[permutation.fragmentPermutation];
7446 const ShaderElement pipeline[] =
7448 ShaderElement("vert", string("vert") + numbers[permutation.vertexPermutation], VK_SHADER_STAGE_VERTEX_BIT),
7449 ShaderElement("geom", string("geom") + numbers[permutation.geometryPermutation], VK_SHADER_STAGE_GEOMETRY_BIT),
7450 ShaderElement("tessc", string("tessc") + numbers[permutation.tesscPermutation], VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT),
7451 ShaderElement("tesse", string("tesse") + numbers[permutation.tessePermutation], VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT),
7452 ShaderElement("frag", string("frag") + numbers[permutation.fragmentPermutation], VK_SHADER_STAGE_FRAGMENT_BIT)
7455 // If there are an even number of swaps, then it should be no-op.
7456 // If there are an odd number, the color should be flipped.
7457 if ((permutation.vertexPermutation + permutation.geometryPermutation + permutation.tesscPermutation + permutation.tessePermutation + permutation.fragmentPermutation) % 2 == 0)
7459 addFunctionCaseWithPrograms<InstanceContext>(moduleTests.get(), name, "", createMultipleEntries, runAndVerifyDefaultPipeline, createInstanceContext(pipeline, defaultColors, defaultColors, map<string, string>()));
7463 addFunctionCaseWithPrograms<InstanceContext>(moduleTests.get(), name, "", createMultipleEntries, runAndVerifyDefaultPipeline, createInstanceContext(pipeline, defaultColors, invertedColors, map<string, string>()));
7466 return moduleTests.release();
7469 tcu::TestCaseGroup* createLoopTests(tcu::TestContext& testCtx)
7471 de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, "loop", "Looping control flow"));
7472 RGBA defaultColors[4];
7473 getDefaultColors(defaultColors);
7474 map<string, string> fragments;
7475 fragments["pre_main"] =
7476 "%c_f32_5 = OpConstant %f32 5.\n";
7478 // A loop with a single block. The Continue Target is the loop block
7479 // itself. In SPIR-V terms, the "loop construct" contains no blocks at all
7480 // -- the "continue construct" forms the entire loop.
7481 fragments["testfun"] =
7482 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
7483 "%param1 = OpFunctionParameter %v4f32\n"
7485 "%entry = OpLabel\n"
7486 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
7489 ";adds and subtracts 1.0 to %val in alternate iterations\n"
7491 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %loop\n"
7492 "%delta = OpPhi %f32 %c_f32_1 %entry %minus_delta %loop\n"
7493 "%val1 = OpPhi %f32 %val0 %entry %val %loop\n"
7494 "%val = OpFAdd %f32 %val1 %delta\n"
7495 "%minus_delta = OpFSub %f32 %c_f32_0 %delta\n"
7496 "%count__ = OpISub %i32 %count %c_i32_1\n"
7497 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
7498 "OpLoopMerge %exit %loop None\n"
7499 "OpBranchConditional %again %loop %exit\n"
7502 "%result = OpVectorInsertDynamic %v4f32 %param1 %val %c_i32_0\n"
7503 "OpReturnValue %result\n"
7507 createTestsForAllStages("single_block", defaultColors, defaultColors, fragments, testGroup.get());
7509 // Body comprised of multiple basic blocks.
7510 const StringTemplate multiBlock(
7511 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
7512 "%param1 = OpFunctionParameter %v4f32\n"
7514 "%entry = OpLabel\n"
7515 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
7518 ";adds and subtracts 1.0 to %val in alternate iterations\n"
7520 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %gather\n"
7521 "%delta = OpPhi %f32 %c_f32_1 %entry %delta_next %gather\n"
7522 "%val1 = OpPhi %f32 %val0 %entry %val %gather\n"
7523 // There are several possibilities for the Continue Target below. Each
7524 // will be specialized into a separate test case.
7525 "OpLoopMerge %exit ${continue_target} None\n"
7529 ";delta_next = (delta > 0) ? -1 : 1;\n"
7530 "%gt0 = OpFOrdGreaterThan %bool %delta %c_f32_0\n"
7531 "OpSelectionMerge %gather DontFlatten\n"
7532 "OpBranchConditional %gt0 %even %odd ;tells us if %count is even or odd\n"
7535 "OpBranch %gather\n"
7538 "OpBranch %gather\n"
7540 "%gather = OpLabel\n"
7541 "%delta_next = OpPhi %f32 %c_f32_n1 %even %c_f32_1 %odd\n"
7542 "%val = OpFAdd %f32 %val1 %delta\n"
7543 "%count__ = OpISub %i32 %count %c_i32_1\n"
7544 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
7545 "OpBranchConditional %again %loop %exit\n"
7548 "%result = OpVectorInsertDynamic %v4f32 %param1 %val %c_i32_0\n"
7549 "OpReturnValue %result\n"
7553 map<string, string> continue_target;
7555 // The Continue Target is the loop block itself.
7556 continue_target["continue_target"] = "%loop";
7557 fragments["testfun"] = multiBlock.specialize(continue_target);
7558 createTestsForAllStages("multi_block_continue_construct", defaultColors, defaultColors, fragments, testGroup.get());
7560 // The Continue Target is at the end of the loop.
7561 continue_target["continue_target"] = "%gather";
7562 fragments["testfun"] = multiBlock.specialize(continue_target);
7563 createTestsForAllStages("multi_block_loop_construct", defaultColors, defaultColors, fragments, testGroup.get());
7565 // A loop with continue statement.
7566 fragments["testfun"] =
7567 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
7568 "%param1 = OpFunctionParameter %v4f32\n"
7570 "%entry = OpLabel\n"
7571 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
7574 ";adds 4, 3, and 1 to %val0 (skips 2)\n"
7576 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %continue\n"
7577 "%val1 = OpPhi %f32 %val0 %entry %val %continue\n"
7578 "OpLoopMerge %exit %continue None\n"
7582 ";skip if %count==2\n"
7583 "%eq2 = OpIEqual %bool %count %c_i32_2\n"
7584 "OpSelectionMerge %continue DontFlatten\n"
7585 "OpBranchConditional %eq2 %continue %body\n"
7588 "%fcount = OpConvertSToF %f32 %count\n"
7589 "%val2 = OpFAdd %f32 %val1 %fcount\n"
7590 "OpBranch %continue\n"
7592 "%continue = OpLabel\n"
7593 "%val = OpPhi %f32 %val2 %body %val1 %if\n"
7594 "%count__ = OpISub %i32 %count %c_i32_1\n"
7595 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
7596 "OpBranchConditional %again %loop %exit\n"
7599 "%same = OpFSub %f32 %val %c_f32_8\n"
7600 "%result = OpVectorInsertDynamic %v4f32 %param1 %same %c_i32_0\n"
7601 "OpReturnValue %result\n"
7603 createTestsForAllStages("continue", defaultColors, defaultColors, fragments, testGroup.get());
7605 // A loop with break.
7606 fragments["testfun"] =
7607 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
7608 "%param1 = OpFunctionParameter %v4f32\n"
7610 "%entry = OpLabel\n"
7611 ";param1 components are between 0 and 1, so dot product is 4 or less\n"
7612 "%dot = OpDot %f32 %param1 %param1\n"
7613 "%div = OpFDiv %f32 %dot %c_f32_5\n"
7614 "%zero = OpConvertFToU %u32 %div\n"
7615 "%two = OpIAdd %i32 %zero %c_i32_2\n"
7616 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
7619 ";adds 4 and 3 to %val0 (exits early)\n"
7621 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %continue\n"
7622 "%val1 = OpPhi %f32 %val0 %entry %val2 %continue\n"
7623 "OpLoopMerge %exit %continue None\n"
7627 ";end loop if %count==%two\n"
7628 "%above2 = OpSGreaterThan %bool %count %two\n"
7629 "OpSelectionMerge %continue DontFlatten\n"
7630 "OpBranchConditional %above2 %body %exit\n"
7633 "%fcount = OpConvertSToF %f32 %count\n"
7634 "%val2 = OpFAdd %f32 %val1 %fcount\n"
7635 "OpBranch %continue\n"
7637 "%continue = OpLabel\n"
7638 "%count__ = OpISub %i32 %count %c_i32_1\n"
7639 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
7640 "OpBranchConditional %again %loop %exit\n"
7643 "%val_post = OpPhi %f32 %val2 %continue %val1 %if\n"
7644 "%same = OpFSub %f32 %val_post %c_f32_7\n"
7645 "%result = OpVectorInsertDynamic %v4f32 %param1 %same %c_i32_0\n"
7646 "OpReturnValue %result\n"
7648 createTestsForAllStages("break", defaultColors, defaultColors, fragments, testGroup.get());
7650 // A loop with return.
7651 fragments["testfun"] =
7652 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
7653 "%param1 = OpFunctionParameter %v4f32\n"
7655 "%entry = OpLabel\n"
7656 ";param1 components are between 0 and 1, so dot product is 4 or less\n"
7657 "%dot = OpDot %f32 %param1 %param1\n"
7658 "%div = OpFDiv %f32 %dot %c_f32_5\n"
7659 "%zero = OpConvertFToU %u32 %div\n"
7660 "%two = OpIAdd %i32 %zero %c_i32_2\n"
7661 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
7664 ";returns early without modifying %param1\n"
7666 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %continue\n"
7667 "%val1 = OpPhi %f32 %val0 %entry %val2 %continue\n"
7668 "OpLoopMerge %exit %continue None\n"
7672 ";return if %count==%two\n"
7673 "%above2 = OpSGreaterThan %bool %count %two\n"
7674 "OpSelectionMerge %continue DontFlatten\n"
7675 "OpBranchConditional %above2 %body %early_exit\n"
7677 "%early_exit = OpLabel\n"
7678 "OpReturnValue %param1\n"
7681 "%fcount = OpConvertSToF %f32 %count\n"
7682 "%val2 = OpFAdd %f32 %val1 %fcount\n"
7683 "OpBranch %continue\n"
7685 "%continue = OpLabel\n"
7686 "%count__ = OpISub %i32 %count %c_i32_1\n"
7687 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
7688 "OpBranchConditional %again %loop %exit\n"
7691 ";should never get here, so return an incorrect result\n"
7692 "%result = OpVectorInsertDynamic %v4f32 %param1 %val2 %c_i32_0\n"
7693 "OpReturnValue %result\n"
7695 createTestsForAllStages("return", defaultColors, defaultColors, fragments, testGroup.get());
7697 return testGroup.release();
7700 // Adds a new test to group using custom fragments for the tessellation-control
7701 // stage and passthrough fragments for all other stages. Uses default colors
7702 // for input and expected output.
7703 void addTessCtrlTest(tcu::TestCaseGroup* group, const char* name, const map<string, string>& fragments)
7705 RGBA defaultColors[4];
7706 getDefaultColors(defaultColors);
7707 const ShaderElement pipelineStages[] =
7709 ShaderElement("vert", "main", VK_SHADER_STAGE_VERTEX_BIT),
7710 ShaderElement("tessc", "main", VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT),
7711 ShaderElement("tesse", "main", VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT),
7712 ShaderElement("frag", "main", VK_SHADER_STAGE_FRAGMENT_BIT),
7715 addFunctionCaseWithPrograms<InstanceContext>(group, name, "", addShaderCodeCustomTessControl,
7716 runAndVerifyDefaultPipeline, createInstanceContext(
7717 pipelineStages, defaultColors, defaultColors, fragments, StageToSpecConstantMap()));
7720 // A collection of tests putting OpControlBarrier in places GLSL forbids but SPIR-V allows.
7721 tcu::TestCaseGroup* createBarrierTests(tcu::TestContext& testCtx)
7723 de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, "barrier", "OpControlBarrier"));
7724 map<string, string> fragments;
7726 // A barrier inside a function body.
7727 fragments["pre_main"] =
7728 "%Workgroup = OpConstant %i32 2\n"
7729 "%SequentiallyConsistent = OpConstant %i32 0x10\n";
7730 fragments["testfun"] =
7731 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
7732 "%param1 = OpFunctionParameter %v4f32\n"
7733 "%label_testfun = OpLabel\n"
7734 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n"
7735 "OpReturnValue %param1\n"
7737 addTessCtrlTest(testGroup.get(), "in_function", fragments);
7739 // Common setup code for the following tests.
7740 fragments["pre_main"] =
7741 "%Workgroup = OpConstant %i32 2\n"
7742 "%SequentiallyConsistent = OpConstant %i32 0x10\n"
7743 "%c_f32_5 = OpConstant %f32 5.\n";
7744 const string setupPercentZero = // Begins %test_code function with code that sets %zero to 0u but cannot be optimized away.
7745 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
7746 "%param1 = OpFunctionParameter %v4f32\n"
7747 "%entry = OpLabel\n"
7748 ";param1 components are between 0 and 1, so dot product is 4 or less\n"
7749 "%dot = OpDot %f32 %param1 %param1\n"
7750 "%div = OpFDiv %f32 %dot %c_f32_5\n"
7751 "%zero = OpConvertFToU %u32 %div\n";
7753 // Barriers inside OpSwitch branches.
7754 fragments["testfun"] =
7756 "OpSelectionMerge %switch_exit None\n"
7757 "OpSwitch %zero %switch_default 0 %case0 1 %case1 ;should always go to %case0\n"
7759 "%case1 = OpLabel\n"
7760 ";This barrier should never be executed, but its presence makes test failure more likely when there's a bug.\n"
7761 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n"
7762 "%wrong_branch_alert1 = OpVectorInsertDynamic %v4f32 %param1 %c_f32_0_5 %c_i32_0\n"
7763 "OpBranch %switch_exit\n"
7765 "%switch_default = OpLabel\n"
7766 "%wrong_branch_alert2 = OpVectorInsertDynamic %v4f32 %param1 %c_f32_0_5 %c_i32_0\n"
7767 ";This barrier should never be executed, but its presence makes test failure more likely when there's a bug.\n"
7768 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n"
7769 "OpBranch %switch_exit\n"
7771 "%case0 = OpLabel\n"
7772 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n"
7773 "OpBranch %switch_exit\n"
7775 "%switch_exit = OpLabel\n"
7776 "%ret = OpPhi %v4f32 %param1 %case0 %wrong_branch_alert1 %case1 %wrong_branch_alert2 %switch_default\n"
7777 "OpReturnValue %ret\n"
7779 addTessCtrlTest(testGroup.get(), "in_switch", fragments);
7781 // Barriers inside if-then-else.
7782 fragments["testfun"] =
7784 "%eq0 = OpIEqual %bool %zero %c_u32_0\n"
7785 "OpSelectionMerge %exit DontFlatten\n"
7786 "OpBranchConditional %eq0 %then %else\n"
7789 ";This barrier should never be executed, but its presence makes test failure more likely when there's a bug.\n"
7790 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n"
7791 "%wrong_branch_alert = OpVectorInsertDynamic %v4f32 %param1 %c_f32_0_5 %c_i32_0\n"
7795 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n"
7799 "%ret = OpPhi %v4f32 %param1 %then %wrong_branch_alert %else\n"
7800 "OpReturnValue %ret\n"
7802 addTessCtrlTest(testGroup.get(), "in_if", fragments);
7804 // A barrier after control-flow reconvergence, tempting the compiler to attempt something like this:
7805 // http://lists.llvm.org/pipermail/llvm-dev/2009-October/026317.html.
7806 fragments["testfun"] =
7808 "%thread_id = OpLoad %i32 %BP_gl_InvocationID\n"
7809 "%thread0 = OpIEqual %bool %thread_id %c_i32_0\n"
7810 "OpSelectionMerge %exit DontFlatten\n"
7811 "OpBranchConditional %thread0 %then %else\n"
7814 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
7818 "%val1 = OpVectorExtractDynamic %f32 %param1 %zero\n"
7822 "%val = OpPhi %f32 %val0 %else %val1 %then\n"
7823 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n"
7824 "%ret = OpVectorInsertDynamic %v4f32 %param1 %val %zero\n"
7825 "OpReturnValue %ret\n"
7827 addTessCtrlTest(testGroup.get(), "after_divergent_if", fragments);
7829 // A barrier inside a loop.
7830 fragments["pre_main"] =
7831 "%Workgroup = OpConstant %i32 2\n"
7832 "%SequentiallyConsistent = OpConstant %i32 0x10\n"
7833 "%c_f32_10 = OpConstant %f32 10.\n";
7834 fragments["testfun"] =
7835 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
7836 "%param1 = OpFunctionParameter %v4f32\n"
7837 "%entry = OpLabel\n"
7838 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
7841 ";adds 4, 3, 2, and 1 to %val0\n"
7843 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %loop\n"
7844 "%val1 = OpPhi %f32 %val0 %entry %val %loop\n"
7845 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n"
7846 "%fcount = OpConvertSToF %f32 %count\n"
7847 "%val = OpFAdd %f32 %val1 %fcount\n"
7848 "%count__ = OpISub %i32 %count %c_i32_1\n"
7849 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
7850 "OpLoopMerge %exit %loop None\n"
7851 "OpBranchConditional %again %loop %exit\n"
7854 "%same = OpFSub %f32 %val %c_f32_10\n"
7855 "%ret = OpVectorInsertDynamic %v4f32 %param1 %same %c_i32_0\n"
7856 "OpReturnValue %ret\n"
7858 addTessCtrlTest(testGroup.get(), "in_loop", fragments);
7860 return testGroup.release();
7863 // Test for the OpFRem instruction.
7864 tcu::TestCaseGroup* createFRemTests(tcu::TestContext& testCtx)
7866 de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, "frem", "OpFRem"));
7867 map<string, string> fragments;
7868 RGBA inputColors[4];
7869 RGBA outputColors[4];
7871 fragments["pre_main"] =
7872 "%c_f32_3 = OpConstant %f32 3.0\n"
7873 "%c_f32_n3 = OpConstant %f32 -3.0\n"
7874 "%c_f32_4 = OpConstant %f32 4.0\n"
7875 "%c_f32_p75 = OpConstant %f32 0.75\n"
7876 "%c_v4f32_p75_p75_p75_p75 = OpConstantComposite %v4f32 %c_f32_p75 %c_f32_p75 %c_f32_p75 %c_f32_p75 \n"
7877 "%c_v4f32_4_4_4_4 = OpConstantComposite %v4f32 %c_f32_4 %c_f32_4 %c_f32_4 %c_f32_4\n"
7878 "%c_v4f32_3_n3_3_n3 = OpConstantComposite %v4f32 %c_f32_3 %c_f32_n3 %c_f32_3 %c_f32_n3\n";
7880 // The test does the following.
7881 // vec4 result = (param1 * 8.0) - 4.0;
7882 // return (frem(result.x,3) + 0.75, frem(result.y, -3) + 0.75, 0, 1)
7883 fragments["testfun"] =
7884 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
7885 "%param1 = OpFunctionParameter %v4f32\n"
7886 "%label_testfun = OpLabel\n"
7887 "%v_times_8 = OpVectorTimesScalar %v4f32 %param1 %c_f32_8\n"
7888 "%minus_4 = OpFSub %v4f32 %v_times_8 %c_v4f32_4_4_4_4\n"
7889 "%frem = OpFRem %v4f32 %minus_4 %c_v4f32_3_n3_3_n3\n"
7890 "%added = OpFAdd %v4f32 %frem %c_v4f32_p75_p75_p75_p75\n"
7891 "%xyz_1 = OpVectorInsertDynamic %v4f32 %added %c_f32_1 %c_i32_3\n"
7892 "%xy_0_1 = OpVectorInsertDynamic %v4f32 %xyz_1 %c_f32_0 %c_i32_2\n"
7893 "OpReturnValue %xy_0_1\n"
7897 inputColors[0] = RGBA(16, 16, 0, 255);
7898 inputColors[1] = RGBA(232, 232, 0, 255);
7899 inputColors[2] = RGBA(232, 16, 0, 255);
7900 inputColors[3] = RGBA(16, 232, 0, 255);
7902 outputColors[0] = RGBA(64, 64, 0, 255);
7903 outputColors[1] = RGBA(255, 255, 0, 255);
7904 outputColors[2] = RGBA(255, 64, 0, 255);
7905 outputColors[3] = RGBA(64, 255, 0, 255);
7907 createTestsForAllStages("frem", inputColors, outputColors, fragments, testGroup.get());
7908 return testGroup.release();
7913 INTEGER_TYPE_SIGNED_16,
7914 INTEGER_TYPE_SIGNED_32,
7915 INTEGER_TYPE_SIGNED_64,
7917 INTEGER_TYPE_UNSIGNED_16,
7918 INTEGER_TYPE_UNSIGNED_32,
7919 INTEGER_TYPE_UNSIGNED_64,
7922 const string getBitWidthStr (IntegerType type)
7926 case INTEGER_TYPE_SIGNED_16:
7927 case INTEGER_TYPE_UNSIGNED_16: return "16";
7929 case INTEGER_TYPE_SIGNED_32:
7930 case INTEGER_TYPE_UNSIGNED_32: return "32";
7932 case INTEGER_TYPE_SIGNED_64:
7933 case INTEGER_TYPE_UNSIGNED_64: return "64";
7935 default: DE_ASSERT(false);
7940 const string getByteWidthStr (IntegerType type)
7944 case INTEGER_TYPE_SIGNED_16:
7945 case INTEGER_TYPE_UNSIGNED_16: return "2";
7947 case INTEGER_TYPE_SIGNED_32:
7948 case INTEGER_TYPE_UNSIGNED_32: return "4";
7950 case INTEGER_TYPE_SIGNED_64:
7951 case INTEGER_TYPE_UNSIGNED_64: return "8";
7953 default: DE_ASSERT(false);
7958 bool isSigned (IntegerType type)
7960 return (type <= INTEGER_TYPE_SIGNED_64);
7963 const string getTypeName (IntegerType type)
7965 string prefix = isSigned(type) ? "" : "u";
7966 return prefix + "int" + getBitWidthStr(type);
7969 const string getTestName (IntegerType from, IntegerType to)
7971 return getTypeName(from) + "_to_" + getTypeName(to);
7974 const string getAsmTypeDeclaration (IntegerType type)
7976 string sign = isSigned(type) ? " 1" : " 0";
7977 return "OpTypeInt " + getBitWidthStr(type) + sign;
7980 template<typename T>
7981 BufferSp getSpecializedBuffer (deInt64 number)
7983 return BufferSp(new Buffer<T>(vector<T>(1, (T)number)));
7986 BufferSp getBuffer (IntegerType type, deInt64 number)
7990 case INTEGER_TYPE_SIGNED_16: return getSpecializedBuffer<deInt16>(number);
7991 case INTEGER_TYPE_SIGNED_32: return getSpecializedBuffer<deInt32>(number);
7992 case INTEGER_TYPE_SIGNED_64: return getSpecializedBuffer<deInt64>(number);
7994 case INTEGER_TYPE_UNSIGNED_16: return getSpecializedBuffer<deUint16>(number);
7995 case INTEGER_TYPE_UNSIGNED_32: return getSpecializedBuffer<deUint32>(number);
7996 case INTEGER_TYPE_UNSIGNED_64: return getSpecializedBuffer<deUint64>(number);
7998 default: DE_ASSERT(false);
7999 return BufferSp(new Buffer<deInt32>(vector<deInt32>(1, 0)));
8003 bool usesInt16 (IntegerType from, IntegerType to)
8005 return (from == INTEGER_TYPE_SIGNED_16 || from == INTEGER_TYPE_UNSIGNED_16
8006 || to == INTEGER_TYPE_SIGNED_16 || to == INTEGER_TYPE_UNSIGNED_16);
8009 bool usesInt64 (IntegerType from, IntegerType to)
8011 return (from == INTEGER_TYPE_SIGNED_64 || from == INTEGER_TYPE_UNSIGNED_64
8012 || to == INTEGER_TYPE_SIGNED_64 || to == INTEGER_TYPE_UNSIGNED_64);
8015 ConvertTestFeatures getUsedFeatures (IntegerType from, IntegerType to)
8017 if (usesInt16(from, to))
8019 if (usesInt64(from, to))
8021 return CONVERT_TEST_USES_INT16_INT64;
8025 return CONVERT_TEST_USES_INT16;
8030 return CONVERT_TEST_USES_INT64;
8036 ConvertCase (IntegerType from, IntegerType to, deInt64 number)
8039 , m_features (getUsedFeatures(from, to))
8040 , m_name (getTestName(from, to))
8041 , m_inputBuffer (getBuffer(from, number))
8042 , m_outputBuffer (getBuffer(to, number))
8044 m_asmTypes["inputType"] = getAsmTypeDeclaration(from);
8045 m_asmTypes["outputType"] = getAsmTypeDeclaration(to);
8047 if (m_features == CONVERT_TEST_USES_INT16)
8049 m_asmTypes["int_capabilities"] = "OpCapability Int16\n";
8051 else if (m_features == CONVERT_TEST_USES_INT64)
8053 m_asmTypes["int_capabilities"] = "OpCapability Int64\n";
8055 else if (m_features == CONVERT_TEST_USES_INT16_INT64)
8057 m_asmTypes["int_capabilities"] = string("OpCapability Int16\n") +
8058 "OpCapability Int64\n";
8066 IntegerType m_fromType;
8067 IntegerType m_toType;
8068 ConvertTestFeatures m_features;
8070 map<string, string> m_asmTypes;
8071 BufferSp m_inputBuffer;
8072 BufferSp m_outputBuffer;
8075 const string getConvertCaseShaderStr (const string& instruction, const ConvertCase& convertCase)
8077 map<string, string> params = convertCase.m_asmTypes;
8079 params["instruction"] = instruction;
8081 params["inDecorator"] = getByteWidthStr(convertCase.m_fromType);
8082 params["outDecorator"] = getByteWidthStr(convertCase.m_toType);
8084 const StringTemplate shader (
8085 "OpCapability Shader\n"
8086 "${int_capabilities}"
8087 "OpMemoryModel Logical GLSL450\n"
8088 "OpEntryPoint GLCompute %main \"main\" %id\n"
8089 "OpExecutionMode %main LocalSize 1 1 1\n"
8090 "OpSource GLSL 430\n"
8091 "OpName %main \"main\"\n"
8092 "OpName %id \"gl_GlobalInvocationID\"\n"
8094 "OpDecorate %id BuiltIn GlobalInvocationId\n"
8095 "OpDecorate %indata DescriptorSet 0\n"
8096 "OpDecorate %indata Binding 0\n"
8097 "OpDecorate %outdata DescriptorSet 0\n"
8098 "OpDecorate %outdata Binding 1\n"
8099 "OpDecorate %in_arr ArrayStride ${inDecorator}\n"
8100 "OpDecorate %out_arr ArrayStride ${outDecorator}\n"
8101 "OpDecorate %in_buf BufferBlock\n"
8102 "OpDecorate %out_buf BufferBlock\n"
8103 "OpMemberDecorate %in_buf 0 Offset 0\n"
8104 "OpMemberDecorate %out_buf 0 Offset 0\n"
8106 "%void = OpTypeVoid\n"
8107 "%voidf = OpTypeFunction %void\n"
8108 "%u32 = OpTypeInt 32 0\n"
8109 "%i32 = OpTypeInt 32 1\n"
8110 "%uvec3 = OpTypeVector %u32 3\n"
8111 "%uvec3ptr = OpTypePointer Input %uvec3\n"
8113 "%in_type = ${inputType}\n"
8114 "%out_type = ${outputType}\n"
8116 "%in_ptr = OpTypePointer Uniform %in_type\n"
8117 "%out_ptr = OpTypePointer Uniform %out_type\n"
8118 "%in_arr = OpTypeRuntimeArray %in_type\n"
8119 "%out_arr = OpTypeRuntimeArray %out_type\n"
8120 "%in_buf = OpTypeStruct %in_arr\n"
8121 "%out_buf = OpTypeStruct %out_arr\n"
8122 "%in_bufptr = OpTypePointer Uniform %in_buf\n"
8123 "%out_bufptr = OpTypePointer Uniform %out_buf\n"
8124 "%indata = OpVariable %in_bufptr Uniform\n"
8125 "%outdata = OpVariable %out_bufptr Uniform\n"
8126 "%inputptr = OpTypePointer Input %in_type\n"
8127 "%id = OpVariable %uvec3ptr Input\n"
8129 "%zero = OpConstant %i32 0\n"
8131 "%main = OpFunction %void None %voidf\n"
8132 "%label = OpLabel\n"
8133 "%idval = OpLoad %uvec3 %id\n"
8134 "%x = OpCompositeExtract %u32 %idval 0\n"
8135 "%inloc = OpAccessChain %in_ptr %indata %zero %x\n"
8136 "%outloc = OpAccessChain %out_ptr %outdata %zero %x\n"
8137 "%inval = OpLoad %in_type %inloc\n"
8138 "%conv = ${instruction} %out_type %inval\n"
8139 " OpStore %outloc %conv\n"
8144 return shader.specialize(params);
8147 void createSConvertCases (vector<ConvertCase>& testCases)
8149 // Convert int to int
8150 testCases.push_back(ConvertCase(INTEGER_TYPE_SIGNED_16, INTEGER_TYPE_SIGNED_32, 14669));
8151 testCases.push_back(ConvertCase(INTEGER_TYPE_SIGNED_16, INTEGER_TYPE_SIGNED_64, 3341));
8153 testCases.push_back(ConvertCase(INTEGER_TYPE_SIGNED_32, INTEGER_TYPE_SIGNED_64, 973610259));
8155 // Convert int to unsigned int
8156 testCases.push_back(ConvertCase(INTEGER_TYPE_SIGNED_16, INTEGER_TYPE_UNSIGNED_32, 9288));
8157 testCases.push_back(ConvertCase(INTEGER_TYPE_SIGNED_16, INTEGER_TYPE_UNSIGNED_64, 15460));
8159 testCases.push_back(ConvertCase(INTEGER_TYPE_SIGNED_32, INTEGER_TYPE_UNSIGNED_64, 346213461));
8162 // Test for the OpSConvert instruction.
8163 tcu::TestCaseGroup* createSConvertTests (tcu::TestContext& testCtx)
8165 const string instruction ("OpSConvert");
8166 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "sconvert", "OpSConvert"));
8167 vector<ConvertCase> testCases;
8168 createSConvertCases(testCases);
8170 for (vector<ConvertCase>::const_iterator test = testCases.begin(); test != testCases.end(); ++test)
8172 ComputeShaderSpec spec;
8174 spec.assembly = getConvertCaseShaderStr(instruction, *test);
8175 spec.inputs.push_back(test->m_inputBuffer);
8176 spec.outputs.push_back(test->m_outputBuffer);
8177 spec.numWorkGroups = IVec3(1, 1, 1);
8179 group->addChild(new ConvertTestCase(testCtx, test->m_name.c_str(), "Convert integers with OpSConvert.", spec, test->m_features));
8182 return group.release();
8185 void createUConvertCases (vector<ConvertCase>& testCases)
8187 // Convert unsigned int to unsigned int
8188 testCases.push_back(ConvertCase(INTEGER_TYPE_UNSIGNED_16, INTEGER_TYPE_UNSIGNED_32, 60653));
8189 testCases.push_back(ConvertCase(INTEGER_TYPE_UNSIGNED_16, INTEGER_TYPE_UNSIGNED_64, 17991));
8191 testCases.push_back(ConvertCase(INTEGER_TYPE_UNSIGNED_32, INTEGER_TYPE_UNSIGNED_64, 904256275));
8193 // Convert unsigned int to int
8194 testCases.push_back(ConvertCase(INTEGER_TYPE_UNSIGNED_16, INTEGER_TYPE_SIGNED_32, 38002));
8195 testCases.push_back(ConvertCase(INTEGER_TYPE_UNSIGNED_16, INTEGER_TYPE_SIGNED_64, 64921));
8197 testCases.push_back(ConvertCase(INTEGER_TYPE_UNSIGNED_32, INTEGER_TYPE_SIGNED_64, 4294956295ll));
8200 // Test for the OpUConvert instruction.
8201 tcu::TestCaseGroup* createUConvertTests (tcu::TestContext& testCtx)
8203 const string instruction ("OpUConvert");
8204 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "uconvert", "OpUConvert"));
8205 vector<ConvertCase> testCases;
8206 createUConvertCases(testCases);
8208 for (vector<ConvertCase>::const_iterator test = testCases.begin(); test != testCases.end(); ++test)
8210 ComputeShaderSpec spec;
8212 spec.assembly = getConvertCaseShaderStr(instruction, *test);
8213 spec.inputs.push_back(test->m_inputBuffer);
8214 spec.outputs.push_back(test->m_outputBuffer);
8215 spec.numWorkGroups = IVec3(1, 1, 1);
8217 group->addChild(new ConvertTestCase(testCtx, test->m_name.c_str(), "Convert integers with OpUConvert.", spec, test->m_features));
8219 return group.release();
8230 const string getNumberTypeName (const NumberType type)
8232 if (type == TYPE_INT)
8236 else if (type == TYPE_UINT)
8240 else if (type == TYPE_FLOAT)
8251 deInt32 getInt(de::Random& rnd)
8253 return rnd.getInt(std::numeric_limits<int>::min(), std::numeric_limits<int>::max());
8256 template <typename T>
8257 const string numberToString (T number)
8259 std::stringstream ss;
8264 const string repeatString (const string& str, int times)
8267 for (int i = 0; i < times; ++i)
8274 const string getRandomConstantString (const NumberType type, de::Random& rnd)
8276 if (type == TYPE_INT)
8278 return numberToString<deInt32>(getInt(rnd));
8280 else if (type == TYPE_UINT)
8282 return numberToString<deUint32>(rnd.getUint32());
8284 else if (type == TYPE_FLOAT)
8286 return numberToString<float>(rnd.getFloat());
8295 void createVectorCompositeCases (vector<map<string, string> >& testCases, de::Random& rnd, const NumberType type)
8297 map<string, string> params;
8300 for (int width = 2; width <= 4; ++width)
8302 string randomConst = numberToString(getInt(rnd));
8303 string widthStr = numberToString(width);
8304 int index = rnd.getInt(0, width-1);
8306 params["type"] = "vec";
8307 params["name"] = params["type"] + "_" + widthStr;
8308 params["compositeType"] = "%composite = OpTypeVector %custom " + widthStr +"\n";
8309 params["filler"] = string("%filler = OpConstant %custom ") + getRandomConstantString(type, rnd) + "\n";
8310 params["compositeConstruct"] = "%instance = OpCompositeConstruct %composite" + repeatString(" %filler", width) + "\n";
8311 params["indexes"] = numberToString(index);
8312 testCases.push_back(params);
8316 void createArrayCompositeCases (vector<map<string, string> >& testCases, de::Random& rnd, const NumberType type)
8318 const int limit = 10;
8319 map<string, string> params;
8321 for (int width = 2; width <= limit; ++width)
8323 string randomConst = numberToString(getInt(rnd));
8324 string widthStr = numberToString(width);
8325 int index = rnd.getInt(0, width-1);
8327 params["type"] = "array";
8328 params["name"] = params["type"] + "_" + widthStr;
8329 params["compositeType"] = string("%arraywidth = OpConstant %u32 " + widthStr + "\n")
8330 + "%composite = OpTypeArray %custom %arraywidth\n";
8332 params["filler"] = string("%filler = OpConstant %custom ") + getRandomConstantString(type, rnd) + "\n";
8333 params["compositeConstruct"] = "%instance = OpCompositeConstruct %composite" + repeatString(" %filler", width) + "\n";
8334 params["indexes"] = numberToString(index);
8335 testCases.push_back(params);
8339 void createStructCompositeCases (vector<map<string, string> >& testCases, de::Random& rnd, const NumberType type)
8341 const int limit = 10;
8342 map<string, string> params;
8344 for (int width = 2; width <= limit; ++width)
8346 string randomConst = numberToString(getInt(rnd));
8347 int index = rnd.getInt(0, width-1);
8349 params["type"] = "struct";
8350 params["name"] = params["type"] + "_" + numberToString(width);
8351 params["compositeType"] = "%composite = OpTypeStruct" + repeatString(" %custom", width) + "\n";
8352 params["filler"] = string("%filler = OpConstant %custom ") + getRandomConstantString(type, rnd) + "\n";
8353 params["compositeConstruct"] = "%instance = OpCompositeConstruct %composite" + repeatString(" %filler", width) + "\n";
8354 params["indexes"] = numberToString(index);
8355 testCases.push_back(params);
8359 void createMatrixCompositeCases (vector<map<string, string> >& testCases, de::Random& rnd, const NumberType type)
8361 map<string, string> params;
8364 for (int width = 2; width <= 4; ++width)
8366 string widthStr = numberToString(width);
8368 for (int column = 2 ; column <= 4; ++column)
8370 int index_0 = rnd.getInt(0, column-1);
8371 int index_1 = rnd.getInt(0, width-1);
8372 string columnStr = numberToString(column);
8374 params["type"] = "matrix";
8375 params["name"] = params["type"] + "_" + widthStr + "x" + columnStr;
8376 params["compositeType"] = string("%vectype = OpTypeVector %custom " + widthStr + "\n")
8377 + "%composite = OpTypeMatrix %vectype " + columnStr + "\n";
8379 params["filler"] = string("%filler = OpConstant %custom ") + getRandomConstantString(type, rnd) + "\n"
8380 + "%fillerVec = OpConstantComposite %vectype" + repeatString(" %filler", width) + "\n";
8382 params["compositeConstruct"] = "%instance = OpCompositeConstruct %composite" + repeatString(" %fillerVec", column) + "\n";
8383 params["indexes"] = numberToString(index_0) + " " + numberToString(index_1);
8384 testCases.push_back(params);
8389 void createCompositeCases (vector<map<string, string> >& testCases, de::Random& rnd, const NumberType type)
8391 createVectorCompositeCases(testCases, rnd, type);
8392 createArrayCompositeCases(testCases, rnd, type);
8393 createStructCompositeCases(testCases, rnd, type);
8394 // Matrix only supports float types
8395 if (type == TYPE_FLOAT)
8397 createMatrixCompositeCases(testCases, rnd, type);
8401 const string getAssemblyTypeDeclaration (const NumberType type)
8405 case TYPE_INT: return "OpTypeInt 32 1";
8406 case TYPE_UINT: return "OpTypeInt 32 0";
8407 case TYPE_FLOAT: return "OpTypeFloat 32";
8408 default: DE_ASSERT(false); return "";
8412 const string specializeCompositeInsertShaderTemplate (const NumberType type, const map<string, string>& params)
8414 map<string, string> parameters(params);
8416 parameters["typeDeclaration"] = getAssemblyTypeDeclaration(type);
8418 parameters["compositeDecorator"] = (parameters["type"] == "array") ? "OpDecorate %composite ArrayStride 4\n" : "";
8420 return StringTemplate (
8421 "OpCapability Shader\n"
8422 "OpCapability Matrix\n"
8423 "OpMemoryModel Logical GLSL450\n"
8424 "OpEntryPoint GLCompute %main \"main\" %id\n"
8425 "OpExecutionMode %main LocalSize 1 1 1\n"
8427 "OpSource GLSL 430\n"
8428 "OpName %main \"main\"\n"
8429 "OpName %id \"gl_GlobalInvocationID\"\n"
8432 "OpDecorate %id BuiltIn GlobalInvocationId\n"
8433 "OpDecorate %buf BufferBlock\n"
8434 "OpDecorate %indata DescriptorSet 0\n"
8435 "OpDecorate %indata Binding 0\n"
8436 "OpDecorate %outdata DescriptorSet 0\n"
8437 "OpDecorate %outdata Binding 1\n"
8438 "OpDecorate %customarr ArrayStride 4\n"
8439 "${compositeDecorator}"
8440 "OpMemberDecorate %buf 0 Offset 0\n"
8443 "%void = OpTypeVoid\n"
8444 "%voidf = OpTypeFunction %void\n"
8445 "%u32 = OpTypeInt 32 0\n"
8446 "%i32 = OpTypeInt 32 1\n"
8447 "%uvec3 = OpTypeVector %u32 3\n"
8448 "%uvec3ptr = OpTypePointer Input %uvec3\n"
8451 "%custom = ${typeDeclaration}\n"
8457 // Inherited from custom
8458 "%customptr = OpTypePointer Uniform %custom\n"
8459 "%customarr = OpTypeRuntimeArray %custom\n"
8460 "%buf = OpTypeStruct %customarr\n"
8461 "%bufptr = OpTypePointer Uniform %buf\n"
8463 "%indata = OpVariable %bufptr Uniform\n"
8464 "%outdata = OpVariable %bufptr Uniform\n"
8466 "%id = OpVariable %uvec3ptr Input\n"
8467 "%zero = OpConstant %i32 0\n"
8469 "%main = OpFunction %void None %voidf\n"
8470 "%label = OpLabel\n"
8471 "%idval = OpLoad %uvec3 %id\n"
8472 "%x = OpCompositeExtract %u32 %idval 0\n"
8474 "%inloc = OpAccessChain %customptr %indata %zero %x\n"
8475 "%outloc = OpAccessChain %customptr %outdata %zero %x\n"
8476 // Read the input value
8477 "%inval = OpLoad %custom %inloc\n"
8478 // Create the composite and fill it
8479 "${compositeConstruct}"
8480 // Insert the input value to a place
8481 "%instance2 = OpCompositeInsert %composite %inval %instance ${indexes}\n"
8482 // Read back the value from the position
8483 "%out_val = OpCompositeExtract %custom %instance2 ${indexes}\n"
8484 // Store it in the output position
8485 " OpStore %outloc %out_val\n"
8488 ).specialize(parameters);
8491 template<typename T>
8492 BufferSp createCompositeBuffer(T number)
8494 return BufferSp(new Buffer<T>(vector<T>(1, number)));
8497 tcu::TestCaseGroup* createOpCompositeInsertGroup (tcu::TestContext& testCtx)
8499 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opcompositeinsert", "Test the OpCompositeInsert instruction"));
8500 de::Random rnd (deStringHash(group->getName()));
8502 for (int type = TYPE_INT; type != TYPE_END; ++type)
8504 NumberType numberType = NumberType(type);
8505 const string typeName = getNumberTypeName(numberType);
8506 const string description = "Test the OpCompositeInsert instruction with " + typeName + "s";
8507 de::MovePtr<tcu::TestCaseGroup> subGroup (new tcu::TestCaseGroup(testCtx, typeName.c_str(), description.c_str()));
8508 vector<map<string, string> > testCases;
8510 createCompositeCases(testCases, rnd, numberType);
8512 for (vector<map<string, string> >::const_iterator test = testCases.begin(); test != testCases.end(); ++test)
8514 ComputeShaderSpec spec;
8516 spec.assembly = specializeCompositeInsertShaderTemplate(numberType, *test);
8522 deInt32 number = getInt(rnd);
8523 spec.inputs.push_back(createCompositeBuffer<deInt32>(number));
8524 spec.outputs.push_back(createCompositeBuffer<deInt32>(number));
8529 deUint32 number = rnd.getUint32();
8530 spec.inputs.push_back(createCompositeBuffer<deUint32>(number));
8531 spec.outputs.push_back(createCompositeBuffer<deUint32>(number));
8536 float number = rnd.getFloat();
8537 spec.inputs.push_back(createCompositeBuffer<float>(number));
8538 spec.outputs.push_back(createCompositeBuffer<float>(number));
8545 spec.numWorkGroups = IVec3(1, 1, 1);
8546 subGroup->addChild(new SpvAsmComputeShaderCase(testCtx, test->at("name").c_str(), "OpCompositeInsert test", spec));
8548 group->addChild(subGroup.release());
8550 return group.release();
8553 struct AssemblyStructInfo
8555 AssemblyStructInfo (const deUint32 comp, const deUint32 idx)
8560 deUint32 components;
8564 const string specializeInBoundsShaderTemplate (const NumberType type, const AssemblyStructInfo& structInfo, const map<string, string>& params)
8566 // Create the full index string
8567 string fullIndex = numberToString(structInfo.index) + " " + params.at("indexes");
8568 // Convert it to list of indexes
8569 vector<string> indexes = de::splitString(fullIndex, ' ');
8571 map<string, string> parameters (params);
8572 parameters["typeDeclaration"] = getAssemblyTypeDeclaration(type);
8573 parameters["structType"] = repeatString(" %composite", structInfo.components);
8574 parameters["structConstruct"] = repeatString(" %instance", structInfo.components);
8575 parameters["insertIndexes"] = fullIndex;
8577 // In matrix cases the last two index is the CompositeExtract indexes
8578 const deUint32 extractIndexes = (parameters["type"] == "matrix") ? 2 : 1;
8580 // Construct the extractIndex
8581 for (vector<string>::const_iterator index = indexes.end() - extractIndexes; index != indexes.end(); ++index)
8583 parameters["extractIndexes"] += " " + *index;
8586 // Remove the last 1 or 2 element depends on matrix case or not
8587 indexes.erase(indexes.end() - extractIndexes, indexes.end());
8590 // Generate AccessChain index expressions (except for the last one, because we use ptr to the composite)
8591 for (vector<string>::const_iterator index = indexes.begin(); index != indexes.end(); ++index)
8593 string indexId = "%index_" + numberToString(id++);
8594 parameters["accessChainConstDeclaration"] += indexId + " = OpConstant %u32 " + *index + "\n";
8595 parameters["accessChainIndexes"] += " " + indexId;
8598 parameters["compositeDecorator"] = (parameters["type"] == "array") ? "OpDecorate %composite ArrayStride 4\n" : "";
8600 return StringTemplate (
8601 "OpCapability Shader\n"
8602 "OpCapability Matrix\n"
8603 "OpMemoryModel Logical GLSL450\n"
8604 "OpEntryPoint GLCompute %main \"main\" %id\n"
8605 "OpExecutionMode %main LocalSize 1 1 1\n"
8607 "OpSource GLSL 430\n"
8608 "OpName %main \"main\"\n"
8609 "OpName %id \"gl_GlobalInvocationID\"\n"
8611 "OpDecorate %id BuiltIn GlobalInvocationId\n"
8612 "OpDecorate %buf BufferBlock\n"
8613 "OpDecorate %indata DescriptorSet 0\n"
8614 "OpDecorate %indata Binding 0\n"
8615 "OpDecorate %outdata DescriptorSet 0\n"
8616 "OpDecorate %outdata Binding 1\n"
8617 "OpDecorate %customarr ArrayStride 4\n"
8618 "${compositeDecorator}"
8619 "OpMemberDecorate %buf 0 Offset 0\n"
8621 "%void = OpTypeVoid\n"
8622 "%voidf = OpTypeFunction %void\n"
8623 "%u32 = OpTypeInt 32 0\n"
8624 "%uvec3 = OpTypeVector %u32 3\n"
8625 "%uvec3ptr = OpTypePointer Input %uvec3\n"
8627 "%custom = ${typeDeclaration}\n"
8630 // Inherited from composite
8631 "%composite_p = OpTypePointer Function %composite\n"
8632 "%struct_t = OpTypeStruct${structType}\n"
8633 "%struct_p = OpTypePointer Function %struct_t\n"
8636 "${accessChainConstDeclaration}"
8637 // Inherited from custom
8638 "%customptr = OpTypePointer Uniform %custom\n"
8639 "%customarr = OpTypeRuntimeArray %custom\n"
8640 "%buf = OpTypeStruct %customarr\n"
8641 "%bufptr = OpTypePointer Uniform %buf\n"
8642 "%indata = OpVariable %bufptr Uniform\n"
8643 "%outdata = OpVariable %bufptr Uniform\n"
8645 "%id = OpVariable %uvec3ptr Input\n"
8646 "%zero = OpConstant %u32 0\n"
8647 "%main = OpFunction %void None %voidf\n"
8648 "%label = OpLabel\n"
8649 "%idval = OpLoad %uvec3 %id\n"
8650 "%x = OpCompositeExtract %u32 %idval 0\n"
8651 // Create the input/output type
8652 "%inloc = OpInBoundsAccessChain %customptr %indata %zero %x\n"
8653 "%outloc = OpInBoundsAccessChain %customptr %outdata %zero %x\n"
8654 // Read the input value
8655 "%inval = OpLoad %custom %inloc\n"
8656 // Create the composite and fill it
8657 "${compositeConstruct}"
8658 // Create the struct and fill it with the composite
8659 "%struct = OpCompositeConstruct %struct_t${structConstruct}\n"
8661 "%comp_obj = OpCompositeInsert %struct_t %inval %struct ${insertIndexes}\n"
8663 "%struct_v = OpVariable %struct_p Function\n"
8664 " OpStore %struct_v %comp_obj\n"
8665 // Get deepest possible composite pointer
8666 "%inner_ptr = OpInBoundsAccessChain %composite_p %struct_v${accessChainIndexes}\n"
8667 "%read_obj = OpLoad %composite %inner_ptr\n"
8668 // Read back the stored value
8669 "%read_val = OpCompositeExtract %custom %read_obj${extractIndexes}\n"
8670 " OpStore %outloc %read_val\n"
8672 " OpFunctionEnd\n").specialize(parameters);
8675 tcu::TestCaseGroup* createOpInBoundsAccessChainGroup (tcu::TestContext& testCtx)
8677 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opinboundsaccesschain", "Test the OpInBoundsAccessChain instruction"));
8678 de::Random rnd (deStringHash(group->getName()));
8680 for (int type = TYPE_INT; type != TYPE_END; ++type)
8682 NumberType numberType = NumberType(type);
8683 const string typeName = getNumberTypeName(numberType);
8684 const string description = "Test the OpInBoundsAccessChain instruction with " + typeName + "s";
8685 de::MovePtr<tcu::TestCaseGroup> subGroup (new tcu::TestCaseGroup(testCtx, typeName.c_str(), description.c_str()));
8687 vector<map<string, string> > testCases;
8688 createCompositeCases(testCases, rnd, numberType);
8690 for (vector<map<string, string> >::const_iterator test = testCases.begin(); test != testCases.end(); ++test)
8692 ComputeShaderSpec spec;
8694 // Number of components inside of a struct
8695 deUint32 structComponents = rnd.getInt(2, 8);
8696 // Component index value
8697 deUint32 structIndex = rnd.getInt(0, structComponents - 1);
8698 AssemblyStructInfo structInfo(structComponents, structIndex);
8700 spec.assembly = specializeInBoundsShaderTemplate(numberType, structInfo, *test);
8706 deInt32 number = getInt(rnd);
8707 spec.inputs.push_back(createCompositeBuffer<deInt32>(number));
8708 spec.outputs.push_back(createCompositeBuffer<deInt32>(number));
8713 deUint32 number = rnd.getUint32();
8714 spec.inputs.push_back(createCompositeBuffer<deUint32>(number));
8715 spec.outputs.push_back(createCompositeBuffer<deUint32>(number));
8720 float number = rnd.getFloat();
8721 spec.inputs.push_back(createCompositeBuffer<float>(number));
8722 spec.outputs.push_back(createCompositeBuffer<float>(number));
8728 spec.numWorkGroups = IVec3(1, 1, 1);
8729 subGroup->addChild(new SpvAsmComputeShaderCase(testCtx, test->at("name").c_str(), "OpInBoundsAccessChain test", spec));
8731 group->addChild(subGroup.release());
8733 return group.release();
8736 tcu::TestCaseGroup* createInstructionTests (tcu::TestContext& testCtx)
8738 de::MovePtr<tcu::TestCaseGroup> instructionTests (new tcu::TestCaseGroup(testCtx, "instruction", "Instructions with special opcodes/operands"));
8739 de::MovePtr<tcu::TestCaseGroup> computeTests (new tcu::TestCaseGroup(testCtx, "compute", "Compute Instructions with special opcodes/operands"));
8740 de::MovePtr<tcu::TestCaseGroup> graphicsTests (new tcu::TestCaseGroup(testCtx, "graphics", "Graphics Instructions with special opcodes/operands"));
8742 computeTests->addChild(createOpNopGroup(testCtx));
8743 computeTests->addChild(createOpFUnordGroup(testCtx));
8744 computeTests->addChild(createOpAtomicGroup(testCtx));
8745 computeTests->addChild(createOpLineGroup(testCtx));
8746 computeTests->addChild(createOpNoLineGroup(testCtx));
8747 computeTests->addChild(createOpConstantNullGroup(testCtx));
8748 computeTests->addChild(createOpConstantCompositeGroup(testCtx));
8749 computeTests->addChild(createOpConstantUsageGroup(testCtx));
8750 computeTests->addChild(createSpecConstantGroup(testCtx));
8751 computeTests->addChild(createOpSourceGroup(testCtx));
8752 computeTests->addChild(createOpSourceExtensionGroup(testCtx));
8753 computeTests->addChild(createDecorationGroupGroup(testCtx));
8754 computeTests->addChild(createOpPhiGroup(testCtx));
8755 computeTests->addChild(createLoopControlGroup(testCtx));
8756 computeTests->addChild(createFunctionControlGroup(testCtx));
8757 computeTests->addChild(createSelectionControlGroup(testCtx));
8758 computeTests->addChild(createBlockOrderGroup(testCtx));
8759 computeTests->addChild(createMultipleShaderGroup(testCtx));
8760 computeTests->addChild(createMemoryAccessGroup(testCtx));
8761 computeTests->addChild(createOpCopyMemoryGroup(testCtx));
8762 computeTests->addChild(createOpCopyObjectGroup(testCtx));
8763 computeTests->addChild(createNoContractionGroup(testCtx));
8764 computeTests->addChild(createOpUndefGroup(testCtx));
8765 computeTests->addChild(createOpUnreachableGroup(testCtx));
8766 computeTests ->addChild(createOpQuantizeToF16Group(testCtx));
8767 computeTests ->addChild(createOpFRemGroup(testCtx));
8768 computeTests->addChild(createSConvertTests(testCtx));
8769 computeTests->addChild(createUConvertTests(testCtx));
8770 computeTests->addChild(createOpCompositeInsertGroup(testCtx));
8771 computeTests->addChild(createOpInBoundsAccessChainGroup(testCtx));
8773 RGBA defaultColors[4];
8774 getDefaultColors(defaultColors);
8776 de::MovePtr<tcu::TestCaseGroup> opnopTests (new tcu::TestCaseGroup(testCtx, "opnop", "Test OpNop"));
8777 map<string, string> opNopFragments;
8778 opNopFragments["testfun"] =
8779 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
8780 "%param1 = OpFunctionParameter %v4f32\n"
8781 "%label_testfun = OpLabel\n"
8790 "%a = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
8791 "%b = OpFAdd %f32 %a %a\n"
8793 "%c = OpFSub %f32 %b %a\n"
8794 "%ret = OpVectorInsertDynamic %v4f32 %param1 %c %c_i32_0\n"
8797 "OpReturnValue %ret\n"
8800 createTestsForAllStages("opnop", defaultColors, defaultColors, opNopFragments, opnopTests.get());
8803 graphicsTests->addChild(opnopTests.release());
8804 graphicsTests->addChild(createOpSourceTests(testCtx));
8805 graphicsTests->addChild(createOpSourceContinuedTests(testCtx));
8806 graphicsTests->addChild(createOpLineTests(testCtx));
8807 graphicsTests->addChild(createOpNoLineTests(testCtx));
8808 graphicsTests->addChild(createOpConstantNullTests(testCtx));
8809 graphicsTests->addChild(createOpConstantCompositeTests(testCtx));
8810 graphicsTests->addChild(createMemoryAccessTests(testCtx));
8811 graphicsTests->addChild(createOpUndefTests(testCtx));
8812 graphicsTests->addChild(createSelectionBlockOrderTests(testCtx));
8813 graphicsTests->addChild(createModuleTests(testCtx));
8814 graphicsTests->addChild(createSwitchBlockOrderTests(testCtx));
8815 graphicsTests->addChild(createOpPhiTests(testCtx));
8816 graphicsTests->addChild(createNoContractionTests(testCtx));
8817 graphicsTests->addChild(createOpQuantizeTests(testCtx));
8818 graphicsTests->addChild(createLoopTests(testCtx));
8819 graphicsTests->addChild(createSpecConstantTests(testCtx));
8820 graphicsTests->addChild(createSpecConstantOpQuantizeToF16Group(testCtx));
8821 graphicsTests->addChild(createBarrierTests(testCtx));
8822 graphicsTests->addChild(createDecorationGroupTests(testCtx));
8823 graphicsTests->addChild(createFRemTests(testCtx));
8825 instructionTests->addChild(computeTests.release());
8826 instructionTests->addChild(graphicsTests.release());
8828 return instructionTests.release();