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 "tcuRGBA.hpp"
29 #include "tcuStringTemplate.hpp"
30 #include "tcuTestLog.hpp"
31 #include "tcuVectorUtil.hpp"
34 #include "vkDeviceUtil.hpp"
35 #include "vkMemUtil.hpp"
36 #include "vkPlatform.hpp"
37 #include "vkPrograms.hpp"
38 #include "vkQueryUtil.hpp"
40 #include "vkRefUtil.hpp"
41 #include "vkStrUtil.hpp"
42 #include "vkTypeUtil.hpp"
44 #include "deRandom.hpp"
45 #include "deStringUtil.hpp"
46 #include "deUniquePtr.hpp"
47 #include "tcuStringTemplate.hpp"
50 #include "vktSpvAsmComputeShaderCase.hpp"
51 #include "vktSpvAsmComputeShaderTestUtil.hpp"
52 #include "vktTestCaseUtil.hpp"
62 namespace SpirVAssembly
76 using tcu::TestStatus;
79 using tcu::StringTemplate;
82 typedef Unique<VkShaderModule> ModuleHandleUp;
83 typedef de::SharedPtr<ModuleHandleUp> ModuleHandleSp;
85 template<typename T> T randomScalar (de::Random& rnd, T minValue, T maxValue);
86 template<> inline float randomScalar (de::Random& rnd, float minValue, float maxValue) { return rnd.getFloat(minValue, maxValue); }
87 template<> inline deInt32 randomScalar (de::Random& rnd, deInt32 minValue, deInt32 maxValue) { return rnd.getInt(minValue, maxValue); }
90 static void fillRandomScalars (de::Random& rnd, T minValue, T maxValue, void* dst, int numValues, int offset = 0)
92 T* const typedPtr = (T*)dst;
93 for (int ndx = 0; ndx < numValues; ndx++)
94 typedPtr[offset + ndx] = randomScalar<T>(rnd, minValue, maxValue);
97 static void floorAll (vector<float>& values)
99 for (size_t i = 0; i < values.size(); i++)
100 values[i] = deFloatFloor(values[i]);
103 static void floorAll (vector<Vec4>& values)
105 for (size_t i = 0; i < values.size(); i++)
106 values[i] = floor(values[i]);
114 CaseParameter (const char* case_, const string& param_) : name(case_), param(param_) {}
117 // Assembly code used for testing OpNop, OpConstant{Null|Composite}, Op[No]Line, OpSource[Continued], OpSourceExtension, OpUndef is based on GLSL source code:
121 // layout(std140, set = 0, binding = 0) readonly buffer Input {
124 // layout(std140, set = 0, binding = 1) writeonly buffer Output {
128 // layout (local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
131 // uint x = gl_GlobalInvocationID.x;
132 // output_data.elements[x] = -input_data.elements[x];
135 static const char* const s_ShaderPreamble =
136 "OpCapability Shader\n"
137 "OpMemoryModel Logical GLSL450\n"
138 "OpEntryPoint GLCompute %main \"main\" %id\n"
139 "OpExecutionMode %main LocalSize 1 1 1\n";
141 static const char* const s_CommonTypes =
142 "%bool = OpTypeBool\n"
143 "%void = OpTypeVoid\n"
144 "%voidf = OpTypeFunction %void\n"
145 "%u32 = OpTypeInt 32 0\n"
146 "%i32 = OpTypeInt 32 1\n"
147 "%f32 = OpTypeFloat 32\n"
148 "%uvec3 = OpTypeVector %u32 3\n"
149 "%fvec3 = OpTypeVector %f32 3\n"
150 "%uvec3ptr = OpTypePointer Input %uvec3\n"
151 "%f32ptr = OpTypePointer Uniform %f32\n"
152 "%f32arr = OpTypeRuntimeArray %f32\n";
154 // Declares two uniform variables (indata, outdata) of type "struct { float[] }". Depends on type "f32arr" (for "float[]").
155 static const char* const s_InputOutputBuffer =
156 "%buf = OpTypeStruct %f32arr\n"
157 "%bufptr = OpTypePointer Uniform %buf\n"
158 "%indata = OpVariable %bufptr Uniform\n"
159 "%outdata = OpVariable %bufptr Uniform\n";
161 // Declares buffer type and layout for uniform variables indata and outdata. Both of them are SSBO bounded to descriptor set 0.
162 // indata is at binding point 0, while outdata is at 1.
163 static const char* const s_InputOutputBufferTraits =
164 "OpDecorate %buf BufferBlock\n"
165 "OpDecorate %indata DescriptorSet 0\n"
166 "OpDecorate %indata Binding 0\n"
167 "OpDecorate %outdata DescriptorSet 0\n"
168 "OpDecorate %outdata Binding 1\n"
169 "OpDecorate %f32arr ArrayStride 4\n"
170 "OpMemberDecorate %buf 0 Offset 0\n";
172 tcu::TestCaseGroup* createOpNopGroup (tcu::TestContext& testCtx)
174 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opnop", "Test the OpNop instruction"));
175 ComputeShaderSpec spec;
176 de::Random rnd (deStringHash(group->getName()));
177 const int numElements = 100;
178 vector<float> positiveFloats (numElements, 0);
179 vector<float> negativeFloats (numElements, 0);
181 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
183 for (size_t ndx = 0; ndx < numElements; ++ndx)
184 negativeFloats[ndx] = -positiveFloats[ndx];
187 string(s_ShaderPreamble) +
189 "OpSource GLSL 430\n"
190 "OpName %main \"main\"\n"
191 "OpName %id \"gl_GlobalInvocationID\"\n"
193 "OpDecorate %id BuiltIn GlobalInvocationId\n"
195 + string(s_InputOutputBufferTraits) + string(s_CommonTypes)
197 + string(s_InputOutputBuffer) +
199 "%id = OpVariable %uvec3ptr Input\n"
200 "%zero = OpConstant %i32 0\n"
202 "%main = OpFunction %void None %voidf\n"
204 "%idval = OpLoad %uvec3 %id\n"
205 "%x = OpCompositeExtract %u32 %idval 0\n"
207 " OpNop\n" // Inside a function body
209 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
210 "%inval = OpLoad %f32 %inloc\n"
211 "%neg = OpFNegate %f32 %inval\n"
212 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
213 " OpStore %outloc %neg\n"
216 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
217 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
218 spec.numWorkGroups = IVec3(numElements, 1, 1);
220 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "OpNop appearing at different places", spec));
222 return group.release();
225 tcu::TestCaseGroup* createOpLineGroup (tcu::TestContext& testCtx)
227 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opline", "Test the OpLine instruction"));
228 ComputeShaderSpec spec;
229 de::Random rnd (deStringHash(group->getName()));
230 const int numElements = 100;
231 vector<float> positiveFloats (numElements, 0);
232 vector<float> negativeFloats (numElements, 0);
234 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
236 for (size_t ndx = 0; ndx < numElements; ++ndx)
237 negativeFloats[ndx] = -positiveFloats[ndx];
240 string(s_ShaderPreamble) +
242 "%fname1 = OpString \"negateInputs.comp\"\n"
243 "%fname2 = OpString \"negateInputs\"\n"
245 "OpSource GLSL 430\n"
246 "OpName %main \"main\"\n"
247 "OpName %id \"gl_GlobalInvocationID\"\n"
249 "OpDecorate %id BuiltIn GlobalInvocationId\n"
251 + string(s_InputOutputBufferTraits) +
253 "OpLine %fname1 0 0\n" // At the earliest possible position
255 + string(s_CommonTypes) + string(s_InputOutputBuffer) +
257 "OpLine %fname1 0 1\n" // Multiple OpLines in sequence
258 "OpLine %fname2 1 0\n" // Different filenames
259 "OpLine %fname1 1000 100000\n"
261 "%id = OpVariable %uvec3ptr Input\n"
262 "%zero = OpConstant %i32 0\n"
264 "OpLine %fname1 1 1\n" // Before a function
266 "%main = OpFunction %void None %voidf\n"
269 "OpLine %fname1 1 1\n" // In a function
271 "%idval = OpLoad %uvec3 %id\n"
272 "%x = OpCompositeExtract %u32 %idval 0\n"
273 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
274 "%inval = OpLoad %f32 %inloc\n"
275 "%neg = OpFNegate %f32 %inval\n"
276 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
277 " OpStore %outloc %neg\n"
280 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
281 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
282 spec.numWorkGroups = IVec3(numElements, 1, 1);
284 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "OpLine appearing at different places", spec));
286 return group.release();
289 tcu::TestCaseGroup* createOpNoLineGroup (tcu::TestContext& testCtx)
291 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opnoline", "Test the OpNoLine instruction"));
292 ComputeShaderSpec spec;
293 de::Random rnd (deStringHash(group->getName()));
294 const int numElements = 100;
295 vector<float> positiveFloats (numElements, 0);
296 vector<float> negativeFloats (numElements, 0);
298 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
300 for (size_t ndx = 0; ndx < numElements; ++ndx)
301 negativeFloats[ndx] = -positiveFloats[ndx];
304 string(s_ShaderPreamble) +
306 "%fname = OpString \"negateInputs.comp\"\n"
308 "OpSource GLSL 430\n"
309 "OpName %main \"main\"\n"
310 "OpName %id \"gl_GlobalInvocationID\"\n"
312 "OpDecorate %id BuiltIn GlobalInvocationId\n"
314 + string(s_InputOutputBufferTraits) +
316 "OpNoLine\n" // At the earliest possible position, without preceding OpLine
318 + string(s_CommonTypes) + string(s_InputOutputBuffer) +
320 "OpLine %fname 0 1\n"
321 "OpNoLine\n" // Immediately following a preceding OpLine
323 "OpLine %fname 1000 1\n"
325 "%id = OpVariable %uvec3ptr Input\n"
326 "%zero = OpConstant %i32 0\n"
328 "OpNoLine\n" // Contents after the previous OpLine
330 "%main = OpFunction %void None %voidf\n"
332 "%idval = OpLoad %uvec3 %id\n"
333 "%x = OpCompositeExtract %u32 %idval 0\n"
335 "OpNoLine\n" // Multiple OpNoLine
339 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
340 "%inval = OpLoad %f32 %inloc\n"
341 "%neg = OpFNegate %f32 %inval\n"
342 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
343 " OpStore %outloc %neg\n"
346 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
347 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
348 spec.numWorkGroups = IVec3(numElements, 1, 1);
350 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "OpNoLine appearing at different places", spec));
352 return group.release();
355 // Compare instruction for the contraction compute case.
356 // Returns true if the output is what is expected from the test case.
357 bool compareNoContractCase(const std::vector<BufferSp>&, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs)
359 if (outputAllocs.size() != 1)
362 // We really just need this for size because we are not comparing the exact values.
363 const BufferSp& expectedOutput = expectedOutputs[0];
364 const float* outputAsFloat = static_cast<const float*>(outputAllocs[0]->getHostPtr());;
366 for(size_t i = 0; i < expectedOutput->getNumBytes() / sizeof(float); ++i) {
367 if (outputAsFloat[i] != 0.f &&
368 outputAsFloat[i] != -ldexp(1, -24)) {
376 tcu::TestCaseGroup* createNoContractionGroup (tcu::TestContext& testCtx)
378 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "nocontraction", "Test the NoContraction decoration"));
379 vector<CaseParameter> cases;
380 const int numElements = 100;
381 vector<float> inputFloats1 (numElements, 0);
382 vector<float> inputFloats2 (numElements, 0);
383 vector<float> outputFloats (numElements, 0);
384 const StringTemplate shaderTemplate (
385 string(s_ShaderPreamble) +
387 "OpName %main \"main\"\n"
388 "OpName %id \"gl_GlobalInvocationID\"\n"
390 "OpDecorate %id BuiltIn GlobalInvocationId\n"
394 "OpDecorate %buf BufferBlock\n"
395 "OpDecorate %indata1 DescriptorSet 0\n"
396 "OpDecorate %indata1 Binding 0\n"
397 "OpDecorate %indata2 DescriptorSet 0\n"
398 "OpDecorate %indata2 Binding 1\n"
399 "OpDecorate %outdata DescriptorSet 0\n"
400 "OpDecorate %outdata Binding 2\n"
401 "OpDecorate %f32arr ArrayStride 4\n"
402 "OpMemberDecorate %buf 0 Offset 0\n"
404 + string(s_CommonTypes) +
406 "%buf = OpTypeStruct %f32arr\n"
407 "%bufptr = OpTypePointer Uniform %buf\n"
408 "%indata1 = OpVariable %bufptr Uniform\n"
409 "%indata2 = OpVariable %bufptr Uniform\n"
410 "%outdata = OpVariable %bufptr Uniform\n"
412 "%id = OpVariable %uvec3ptr Input\n"
413 "%zero = OpConstant %i32 0\n"
414 "%c_f_m1 = OpConstant %f32 -1.\n"
416 "%main = OpFunction %void None %voidf\n"
418 "%idval = OpLoad %uvec3 %id\n"
419 "%x = OpCompositeExtract %u32 %idval 0\n"
420 "%inloc1 = OpAccessChain %f32ptr %indata1 %zero %x\n"
421 "%inval1 = OpLoad %f32 %inloc1\n"
422 "%inloc2 = OpAccessChain %f32ptr %indata2 %zero %x\n"
423 "%inval2 = OpLoad %f32 %inloc2\n"
424 "%mul = OpFMul %f32 %inval1 %inval2\n"
425 "%add = OpFAdd %f32 %mul %c_f_m1\n"
426 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
427 " OpStore %outloc %add\n"
431 cases.push_back(CaseParameter("multiplication", "OpDecorate %mul NoContraction"));
432 cases.push_back(CaseParameter("addition", "OpDecorate %add NoContraction"));
433 cases.push_back(CaseParameter("both", "OpDecorate %mul NoContraction\nOpDecorate %add NoContraction"));
435 for (size_t ndx = 0; ndx < numElements; ++ndx)
437 inputFloats1[ndx] = 1.f + std::ldexp(1.f, -23); // 1 + 2^-23.
438 inputFloats2[ndx] = 1.f - std::ldexp(1.f, -23); // 1 - 2^-23.
439 // Result for (1 + 2^-23) * (1 - 2^-23) - 1. With NoContraction, the multiplication will be
440 // conducted separately and the result is rounded to 1, or 0x1.fffffcp-1
441 // So the final result will be 0.f or 0x1p-24.
442 // If the operation is combined into a precise fused multiply-add, then the result would be
443 // 2^-46 (0xa8800000).
444 outputFloats[ndx] = 0.f;
447 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
449 map<string, string> specializations;
450 ComputeShaderSpec spec;
452 specializations["DECORATION"] = cases[caseNdx].param;
453 spec.assembly = shaderTemplate.specialize(specializations);
454 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats1)));
455 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
456 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
457 spec.numWorkGroups = IVec3(numElements, 1, 1);
458 // Check against the two possible answers based on rounding mode.
459 spec.verifyIO = &compareNoContractCase;
461 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
463 return group.release();
466 bool compareFRem(const std::vector<BufferSp>&, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs)
468 if (outputAllocs.size() != 1)
471 const BufferSp& expectedOutput = expectedOutputs[0];
472 const float *expectedOutputAsFloat = static_cast<const float*>(expectedOutput->data());
473 const float* outputAsFloat = static_cast<const float*>(outputAllocs[0]->getHostPtr());;
475 for (size_t idx = 0; idx < expectedOutput->getNumBytes() / sizeof(float); ++idx)
477 const float f0 = expectedOutputAsFloat[idx];
478 const float f1 = outputAsFloat[idx];
479 // \todo relative error needs to be fairly high because FRem may be implemented as
480 // (roughly) frac(a/b)*b, so LSB errors can be magnified. But this should be fine for now.
481 if (deFloatAbs((f1 - f0) / f0) > 0.02)
488 tcu::TestCaseGroup* createOpFRemGroup (tcu::TestContext& testCtx)
490 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opfrem", "Test the OpFRem instruction"));
491 ComputeShaderSpec spec;
492 de::Random rnd (deStringHash(group->getName()));
493 const int numElements = 200;
494 vector<float> inputFloats1 (numElements, 0);
495 vector<float> inputFloats2 (numElements, 0);
496 vector<float> outputFloats (numElements, 0);
498 fillRandomScalars(rnd, -10000.f, 10000.f, &inputFloats1[0], numElements);
499 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats2[0], numElements);
501 for (size_t ndx = 0; ndx < numElements; ++ndx)
503 // Guard against divisors near zero.
504 if (std::fabs(inputFloats2[ndx]) < 1e-3)
505 inputFloats2[ndx] = 8.f;
507 // The return value of std::fmod() has the same sign as its first operand, which is how OpFRem spec'd.
508 outputFloats[ndx] = std::fmod(inputFloats1[ndx], inputFloats2[ndx]);
512 string(s_ShaderPreamble) +
514 "OpName %main \"main\"\n"
515 "OpName %id \"gl_GlobalInvocationID\"\n"
517 "OpDecorate %id BuiltIn GlobalInvocationId\n"
519 "OpDecorate %buf BufferBlock\n"
520 "OpDecorate %indata1 DescriptorSet 0\n"
521 "OpDecorate %indata1 Binding 0\n"
522 "OpDecorate %indata2 DescriptorSet 0\n"
523 "OpDecorate %indata2 Binding 1\n"
524 "OpDecorate %outdata DescriptorSet 0\n"
525 "OpDecorate %outdata Binding 2\n"
526 "OpDecorate %f32arr ArrayStride 4\n"
527 "OpMemberDecorate %buf 0 Offset 0\n"
529 + string(s_CommonTypes) +
531 "%buf = OpTypeStruct %f32arr\n"
532 "%bufptr = OpTypePointer Uniform %buf\n"
533 "%indata1 = OpVariable %bufptr Uniform\n"
534 "%indata2 = OpVariable %bufptr Uniform\n"
535 "%outdata = OpVariable %bufptr Uniform\n"
537 "%id = OpVariable %uvec3ptr Input\n"
538 "%zero = OpConstant %i32 0\n"
540 "%main = OpFunction %void None %voidf\n"
542 "%idval = OpLoad %uvec3 %id\n"
543 "%x = OpCompositeExtract %u32 %idval 0\n"
544 "%inloc1 = OpAccessChain %f32ptr %indata1 %zero %x\n"
545 "%inval1 = OpLoad %f32 %inloc1\n"
546 "%inloc2 = OpAccessChain %f32ptr %indata2 %zero %x\n"
547 "%inval2 = OpLoad %f32 %inloc2\n"
548 "%rem = OpFRem %f32 %inval1 %inval2\n"
549 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
550 " OpStore %outloc %rem\n"
554 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats1)));
555 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
556 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
557 spec.numWorkGroups = IVec3(numElements, 1, 1);
558 spec.verifyIO = &compareFRem;
560 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "", spec));
562 return group.release();
565 // Copy contents in the input buffer to the output buffer.
566 tcu::TestCaseGroup* createOpCopyMemoryGroup (tcu::TestContext& testCtx)
568 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opcopymemory", "Test the OpCopyMemory instruction"));
569 de::Random rnd (deStringHash(group->getName()));
570 const int numElements = 100;
572 // 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.
573 ComputeShaderSpec spec1;
574 vector<Vec4> inputFloats1 (numElements);
575 vector<Vec4> outputFloats1 (numElements);
577 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats1[0], numElements * 4);
579 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
580 floorAll(inputFloats1);
582 for (size_t ndx = 0; ndx < numElements; ++ndx)
583 outputFloats1[ndx] = inputFloats1[ndx] + Vec4(0.f, 0.5f, 1.5f, 2.5f);
586 string(s_ShaderPreamble) +
588 "OpName %main \"main\"\n"
589 "OpName %id \"gl_GlobalInvocationID\"\n"
591 "OpDecorate %id BuiltIn GlobalInvocationId\n"
592 "OpDecorate %vec4arr ArrayStride 16\n"
594 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) +
596 "%vec4 = OpTypeVector %f32 4\n"
597 "%vec4ptr_u = OpTypePointer Uniform %vec4\n"
598 "%vec4ptr_f = OpTypePointer Function %vec4\n"
599 "%vec4arr = OpTypeRuntimeArray %vec4\n"
600 "%buf = OpTypeStruct %vec4arr\n"
601 "%bufptr = OpTypePointer Uniform %buf\n"
602 "%indata = OpVariable %bufptr Uniform\n"
603 "%outdata = OpVariable %bufptr Uniform\n"
605 "%id = OpVariable %uvec3ptr Input\n"
606 "%zero = OpConstant %i32 0\n"
607 "%c_f_0 = OpConstant %f32 0.\n"
608 "%c_f_0_5 = OpConstant %f32 0.5\n"
609 "%c_f_1_5 = OpConstant %f32 1.5\n"
610 "%c_f_2_5 = OpConstant %f32 2.5\n"
611 "%c_vec4 = OpConstantComposite %vec4 %c_f_0 %c_f_0_5 %c_f_1_5 %c_f_2_5\n"
613 "%main = OpFunction %void None %voidf\n"
615 "%v_vec4 = OpVariable %vec4ptr_f Function\n"
616 "%idval = OpLoad %uvec3 %id\n"
617 "%x = OpCompositeExtract %u32 %idval 0\n"
618 "%inloc = OpAccessChain %vec4ptr_u %indata %zero %x\n"
619 "%outloc = OpAccessChain %vec4ptr_u %outdata %zero %x\n"
620 " OpCopyMemory %v_vec4 %inloc\n"
621 "%v_vec4_val = OpLoad %vec4 %v_vec4\n"
622 "%add = OpFAdd %vec4 %v_vec4_val %c_vec4\n"
623 " OpStore %outloc %add\n"
627 spec1.inputs.push_back(BufferSp(new Vec4Buffer(inputFloats1)));
628 spec1.outputs.push_back(BufferSp(new Vec4Buffer(outputFloats1)));
629 spec1.numWorkGroups = IVec3(numElements, 1, 1);
631 group->addChild(new SpvAsmComputeShaderCase(testCtx, "vector", "OpCopyMemory elements of vector type", spec1));
633 // The following case copies a float[100] variable from the input buffer to the output buffer.
634 ComputeShaderSpec spec2;
635 vector<float> inputFloats2 (numElements);
636 vector<float> outputFloats2 (numElements);
638 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats2[0], numElements);
640 for (size_t ndx = 0; ndx < numElements; ++ndx)
641 outputFloats2[ndx] = inputFloats2[ndx];
644 string(s_ShaderPreamble) +
646 "OpName %main \"main\"\n"
647 "OpName %id \"gl_GlobalInvocationID\"\n"
649 "OpDecorate %id BuiltIn GlobalInvocationId\n"
650 "OpDecorate %f32arr100 ArrayStride 4\n"
652 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) +
654 "%hundred = OpConstant %u32 100\n"
655 "%f32arr100 = OpTypeArray %f32 %hundred\n"
656 "%f32arr100ptr_f = OpTypePointer Function %f32arr100\n"
657 "%f32arr100ptr_u = OpTypePointer Uniform %f32arr100\n"
658 "%buf = OpTypeStruct %f32arr100\n"
659 "%bufptr = OpTypePointer Uniform %buf\n"
660 "%indata = OpVariable %bufptr Uniform\n"
661 "%outdata = OpVariable %bufptr Uniform\n"
663 "%id = OpVariable %uvec3ptr Input\n"
664 "%zero = OpConstant %i32 0\n"
666 "%main = OpFunction %void None %voidf\n"
668 "%var = OpVariable %f32arr100ptr_f Function\n"
669 "%inarr = OpAccessChain %f32arr100ptr_u %indata %zero\n"
670 "%outarr = OpAccessChain %f32arr100ptr_u %outdata %zero\n"
671 " OpCopyMemory %var %inarr\n"
672 " OpCopyMemory %outarr %var\n"
676 spec2.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
677 spec2.outputs.push_back(BufferSp(new Float32Buffer(outputFloats2)));
678 spec2.numWorkGroups = IVec3(1, 1, 1);
680 group->addChild(new SpvAsmComputeShaderCase(testCtx, "array", "OpCopyMemory elements of array type", spec2));
682 // The following case copies a struct{vec4, vec4, vec4, vec4} variable from the input buffer to the output buffer.
683 ComputeShaderSpec spec3;
684 vector<float> inputFloats3 (16);
685 vector<float> outputFloats3 (16);
687 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats3[0], 16);
689 for (size_t ndx = 0; ndx < 16; ++ndx)
690 outputFloats3[ndx] = inputFloats3[ndx];
693 string(s_ShaderPreamble) +
695 "OpName %main \"main\"\n"
696 "OpName %id \"gl_GlobalInvocationID\"\n"
698 "OpDecorate %id BuiltIn GlobalInvocationId\n"
699 "OpMemberDecorate %buf 0 Offset 0\n"
700 "OpMemberDecorate %buf 1 Offset 16\n"
701 "OpMemberDecorate %buf 2 Offset 32\n"
702 "OpMemberDecorate %buf 3 Offset 48\n"
704 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) +
706 "%vec4 = OpTypeVector %f32 4\n"
707 "%buf = OpTypeStruct %vec4 %vec4 %vec4 %vec4\n"
708 "%bufptr = OpTypePointer Uniform %buf\n"
709 "%indata = OpVariable %bufptr Uniform\n"
710 "%outdata = OpVariable %bufptr Uniform\n"
711 "%vec4stptr = OpTypePointer Function %buf\n"
713 "%id = OpVariable %uvec3ptr Input\n"
714 "%zero = OpConstant %i32 0\n"
716 "%main = OpFunction %void None %voidf\n"
718 "%var = OpVariable %vec4stptr Function\n"
719 " OpCopyMemory %var %indata\n"
720 " OpCopyMemory %outdata %var\n"
724 spec3.inputs.push_back(BufferSp(new Float32Buffer(inputFloats3)));
725 spec3.outputs.push_back(BufferSp(new Float32Buffer(outputFloats3)));
726 spec3.numWorkGroups = IVec3(1, 1, 1);
728 group->addChild(new SpvAsmComputeShaderCase(testCtx, "struct", "OpCopyMemory elements of struct type", spec3));
730 // The following case negates multiple float variables from the input buffer and stores the results to the output buffer.
731 ComputeShaderSpec spec4;
732 vector<float> inputFloats4 (numElements);
733 vector<float> outputFloats4 (numElements);
735 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats4[0], numElements);
737 for (size_t ndx = 0; ndx < numElements; ++ndx)
738 outputFloats4[ndx] = -inputFloats4[ndx];
741 string(s_ShaderPreamble) +
743 "OpName %main \"main\"\n"
744 "OpName %id \"gl_GlobalInvocationID\"\n"
746 "OpDecorate %id BuiltIn GlobalInvocationId\n"
748 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) + string(s_InputOutputBuffer) +
750 "%f32ptr_f = OpTypePointer Function %f32\n"
751 "%id = OpVariable %uvec3ptr Input\n"
752 "%zero = OpConstant %i32 0\n"
754 "%main = OpFunction %void None %voidf\n"
756 "%var = OpVariable %f32ptr_f Function\n"
757 "%idval = OpLoad %uvec3 %id\n"
758 "%x = OpCompositeExtract %u32 %idval 0\n"
759 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
760 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
761 " OpCopyMemory %var %inloc\n"
762 "%val = OpLoad %f32 %var\n"
763 "%neg = OpFNegate %f32 %val\n"
764 " OpStore %outloc %neg\n"
768 spec4.inputs.push_back(BufferSp(new Float32Buffer(inputFloats4)));
769 spec4.outputs.push_back(BufferSp(new Float32Buffer(outputFloats4)));
770 spec4.numWorkGroups = IVec3(numElements, 1, 1);
772 group->addChild(new SpvAsmComputeShaderCase(testCtx, "float", "OpCopyMemory elements of float type", spec4));
774 return group.release();
777 tcu::TestCaseGroup* createOpCopyObjectGroup (tcu::TestContext& testCtx)
779 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opcopyobject", "Test the OpCopyObject instruction"));
780 ComputeShaderSpec spec;
781 de::Random rnd (deStringHash(group->getName()));
782 const int numElements = 100;
783 vector<float> inputFloats (numElements, 0);
784 vector<float> outputFloats (numElements, 0);
786 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats[0], numElements);
788 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
789 floorAll(inputFloats);
791 for (size_t ndx = 0; ndx < numElements; ++ndx)
792 outputFloats[ndx] = inputFloats[ndx] + 7.5f;
795 string(s_ShaderPreamble) +
797 "OpName %main \"main\"\n"
798 "OpName %id \"gl_GlobalInvocationID\"\n"
800 "OpDecorate %id BuiltIn GlobalInvocationId\n"
802 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) +
804 "%fmat = OpTypeMatrix %fvec3 3\n"
805 "%three = OpConstant %u32 3\n"
806 "%farr = OpTypeArray %f32 %three\n"
807 "%fst = OpTypeStruct %f32 %f32\n"
809 + string(s_InputOutputBuffer) +
811 "%id = OpVariable %uvec3ptr Input\n"
812 "%zero = OpConstant %i32 0\n"
813 "%c_f = OpConstant %f32 1.5\n"
814 "%c_fvec3 = OpConstantComposite %fvec3 %c_f %c_f %c_f\n"
815 "%c_fmat = OpConstantComposite %fmat %c_fvec3 %c_fvec3 %c_fvec3\n"
816 "%c_farr = OpConstantComposite %farr %c_f %c_f %c_f\n"
817 "%c_fst = OpConstantComposite %fst %c_f %c_f\n"
819 "%main = OpFunction %void None %voidf\n"
821 "%c_f_copy = OpCopyObject %f32 %c_f\n"
822 "%c_fvec3_copy = OpCopyObject %fvec3 %c_fvec3\n"
823 "%c_fmat_copy = OpCopyObject %fmat %c_fmat\n"
824 "%c_farr_copy = OpCopyObject %farr %c_farr\n"
825 "%c_fst_copy = OpCopyObject %fst %c_fst\n"
826 "%fvec3_elem = OpCompositeExtract %f32 %c_fvec3_copy 0\n"
827 "%fmat_elem = OpCompositeExtract %f32 %c_fmat_copy 1 2\n"
828 "%farr_elem = OpCompositeExtract %f32 %c_farr_copy 2\n"
829 "%fst_elem = OpCompositeExtract %f32 %c_fst_copy 1\n"
830 // Add up. 1.5 * 5 = 7.5.
831 "%add1 = OpFAdd %f32 %c_f_copy %fvec3_elem\n"
832 "%add2 = OpFAdd %f32 %add1 %fmat_elem\n"
833 "%add3 = OpFAdd %f32 %add2 %farr_elem\n"
834 "%add4 = OpFAdd %f32 %add3 %fst_elem\n"
836 "%idval = OpLoad %uvec3 %id\n"
837 "%x = OpCompositeExtract %u32 %idval 0\n"
838 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
839 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
840 "%inval = OpLoad %f32 %inloc\n"
841 "%add = OpFAdd %f32 %add4 %inval\n"
842 " OpStore %outloc %add\n"
845 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
846 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
847 spec.numWorkGroups = IVec3(numElements, 1, 1);
849 group->addChild(new SpvAsmComputeShaderCase(testCtx, "spotcheck", "OpCopyObject on different types", spec));
851 return group.release();
853 // Assembly code used for testing OpUnreachable is based on GLSL source code:
857 // layout(std140, set = 0, binding = 0) readonly buffer Input {
860 // layout(std140, set = 0, binding = 1) writeonly buffer Output {
864 // void not_called_func() {
865 // // place OpUnreachable here
868 // uint modulo4(uint val) {
869 // switch (val % uint(4)) {
874 // default: return 100; // place OpUnreachable here
880 // // place OpUnreachable here
884 // uint x = gl_GlobalInvocationID.x;
885 // if (const5() > modulo4(1000)) {
886 // output_data.elements[x] = -input_data.elements[x];
888 // // place OpUnreachable here
889 // output_data.elements[x] = input_data.elements[x];
893 tcu::TestCaseGroup* createOpUnreachableGroup (tcu::TestContext& testCtx)
895 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opunreachable", "Test the OpUnreachable instruction"));
896 ComputeShaderSpec spec;
897 de::Random rnd (deStringHash(group->getName()));
898 const int numElements = 100;
899 vector<float> positiveFloats (numElements, 0);
900 vector<float> negativeFloats (numElements, 0);
902 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
904 for (size_t ndx = 0; ndx < numElements; ++ndx)
905 negativeFloats[ndx] = -positiveFloats[ndx];
908 string(s_ShaderPreamble) +
910 "OpSource GLSL 430\n"
911 "OpName %main \"main\"\n"
912 "OpName %func_not_called_func \"not_called_func(\"\n"
913 "OpName %func_modulo4 \"modulo4(u1;\"\n"
914 "OpName %func_const5 \"const5(\"\n"
915 "OpName %id \"gl_GlobalInvocationID\"\n"
917 "OpDecorate %id BuiltIn GlobalInvocationId\n"
919 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) +
921 "%u32ptr = OpTypePointer Function %u32\n"
922 "%uintfuint = OpTypeFunction %u32 %u32ptr\n"
923 "%unitf = OpTypeFunction %u32\n"
925 "%id = OpVariable %uvec3ptr Input\n"
926 "%zero = OpConstant %u32 0\n"
927 "%one = OpConstant %u32 1\n"
928 "%two = OpConstant %u32 2\n"
929 "%three = OpConstant %u32 3\n"
930 "%four = OpConstant %u32 4\n"
931 "%five = OpConstant %u32 5\n"
932 "%hundred = OpConstant %u32 100\n"
933 "%thousand = OpConstant %u32 1000\n"
935 + string(s_InputOutputBuffer) +
938 "%main = OpFunction %void None %voidf\n"
939 "%main_entry = OpLabel\n"
940 "%v_thousand = OpVariable %u32ptr Function %thousand\n"
941 "%idval = OpLoad %uvec3 %id\n"
942 "%x = OpCompositeExtract %u32 %idval 0\n"
943 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
944 "%inval = OpLoad %f32 %inloc\n"
945 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
946 "%ret_const5 = OpFunctionCall %u32 %func_const5\n"
947 "%ret_modulo4 = OpFunctionCall %u32 %func_modulo4 %v_thousand\n"
948 "%cmp_gt = OpUGreaterThan %bool %ret_const5 %ret_modulo4\n"
949 " OpSelectionMerge %if_end None\n"
950 " OpBranchConditional %cmp_gt %if_true %if_false\n"
951 "%if_true = OpLabel\n"
952 "%negate = OpFNegate %f32 %inval\n"
953 " OpStore %outloc %negate\n"
954 " OpBranch %if_end\n"
955 "%if_false = OpLabel\n"
956 " OpUnreachable\n" // Unreachable else branch for if statement
957 "%if_end = OpLabel\n"
961 // not_called_function()
962 "%func_not_called_func = OpFunction %void None %voidf\n"
963 "%not_called_func_entry = OpLabel\n"
964 " OpUnreachable\n" // Unreachable entry block in not called static function
968 "%func_modulo4 = OpFunction %u32 None %uintfuint\n"
969 "%valptr = OpFunctionParameter %u32ptr\n"
970 "%modulo4_entry = OpLabel\n"
971 "%val = OpLoad %u32 %valptr\n"
972 "%modulo = OpUMod %u32 %val %four\n"
973 " OpSelectionMerge %switch_merge None\n"
974 " OpSwitch %modulo %default 0 %case0 1 %case1 2 %case2 3 %case3\n"
976 " OpReturnValue %three\n"
978 " OpReturnValue %two\n"
980 " OpReturnValue %one\n"
982 " OpReturnValue %zero\n"
983 "%default = OpLabel\n"
984 " OpUnreachable\n" // Unreachable default case for switch statement
985 "%switch_merge = OpLabel\n"
986 " OpUnreachable\n" // Unreachable merge block for switch statement
990 "%func_const5 = OpFunction %u32 None %unitf\n"
991 "%const5_entry = OpLabel\n"
992 " OpReturnValue %five\n"
993 "%unreachable = OpLabel\n"
994 " OpUnreachable\n" // Unreachable block in function
996 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
997 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
998 spec.numWorkGroups = IVec3(numElements, 1, 1);
1000 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "OpUnreachable appearing at different places", spec));
1002 return group.release();
1005 // Assembly code used for testing decoration group is based on GLSL source code:
1009 // layout(std140, set = 0, binding = 0) readonly buffer Input0 {
1010 // float elements[];
1012 // layout(std140, set = 0, binding = 1) readonly buffer Input1 {
1013 // float elements[];
1015 // layout(std140, set = 0, binding = 2) readonly buffer Input2 {
1016 // float elements[];
1018 // layout(std140, set = 0, binding = 3) readonly buffer Input3 {
1019 // float elements[];
1021 // layout(std140, set = 0, binding = 4) readonly buffer Input4 {
1022 // float elements[];
1024 // layout(std140, set = 0, binding = 5) writeonly buffer Output {
1025 // float elements[];
1029 // uint x = gl_GlobalInvocationID.x;
1030 // output_data.elements[x] = input_data0.elements[x] + input_data1.elements[x] + input_data2.elements[x] + input_data3.elements[x] + input_data4.elements[x];
1032 tcu::TestCaseGroup* createDecorationGroupGroup (tcu::TestContext& testCtx)
1034 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "decoration_group", "Test the OpDecorationGroup & OpGroupDecorate instruction"));
1035 ComputeShaderSpec spec;
1036 de::Random rnd (deStringHash(group->getName()));
1037 const int numElements = 100;
1038 vector<float> inputFloats0 (numElements, 0);
1039 vector<float> inputFloats1 (numElements, 0);
1040 vector<float> inputFloats2 (numElements, 0);
1041 vector<float> inputFloats3 (numElements, 0);
1042 vector<float> inputFloats4 (numElements, 0);
1043 vector<float> outputFloats (numElements, 0);
1045 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats0[0], numElements);
1046 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats1[0], numElements);
1047 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats2[0], numElements);
1048 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats3[0], numElements);
1049 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats4[0], numElements);
1051 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
1052 floorAll(inputFloats0);
1053 floorAll(inputFloats1);
1054 floorAll(inputFloats2);
1055 floorAll(inputFloats3);
1056 floorAll(inputFloats4);
1058 for (size_t ndx = 0; ndx < numElements; ++ndx)
1059 outputFloats[ndx] = inputFloats0[ndx] + inputFloats1[ndx] + inputFloats2[ndx] + inputFloats3[ndx] + inputFloats4[ndx];
1062 string(s_ShaderPreamble) +
1064 "OpSource GLSL 430\n"
1065 "OpName %main \"main\"\n"
1066 "OpName %id \"gl_GlobalInvocationID\"\n"
1068 // Not using group decoration on variable.
1069 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1070 // Not using group decoration on type.
1071 "OpDecorate %f32arr ArrayStride 4\n"
1073 "OpDecorate %groups BufferBlock\n"
1074 "OpDecorate %groupm Offset 0\n"
1075 "%groups = OpDecorationGroup\n"
1076 "%groupm = OpDecorationGroup\n"
1078 // Group decoration on multiple structs.
1079 "OpGroupDecorate %groups %outbuf %inbuf0 %inbuf1 %inbuf2 %inbuf3 %inbuf4\n"
1080 // Group decoration on multiple struct members.
1081 "OpGroupMemberDecorate %groupm %outbuf 0 %inbuf0 0 %inbuf1 0 %inbuf2 0 %inbuf3 0 %inbuf4 0\n"
1083 "OpDecorate %group1 DescriptorSet 0\n"
1084 "OpDecorate %group3 DescriptorSet 0\n"
1085 "OpDecorate %group3 NonWritable\n"
1086 "OpDecorate %group3 Restrict\n"
1087 "%group0 = OpDecorationGroup\n"
1088 "%group1 = OpDecorationGroup\n"
1089 "%group3 = OpDecorationGroup\n"
1091 // Applying the same decoration group multiple times.
1092 "OpGroupDecorate %group1 %outdata\n"
1093 "OpGroupDecorate %group1 %outdata\n"
1094 "OpGroupDecorate %group1 %outdata\n"
1095 "OpDecorate %outdata DescriptorSet 0\n"
1096 "OpDecorate %outdata Binding 5\n"
1097 // Applying decoration group containing nothing.
1098 "OpGroupDecorate %group0 %indata0\n"
1099 "OpDecorate %indata0 DescriptorSet 0\n"
1100 "OpDecorate %indata0 Binding 0\n"
1101 // Applying decoration group containing one decoration.
1102 "OpGroupDecorate %group1 %indata1\n"
1103 "OpDecorate %indata1 Binding 1\n"
1104 // Applying decoration group containing multiple decorations.
1105 "OpGroupDecorate %group3 %indata2 %indata3\n"
1106 "OpDecorate %indata2 Binding 2\n"
1107 "OpDecorate %indata3 Binding 3\n"
1108 // Applying multiple decoration groups (with overlapping).
1109 "OpGroupDecorate %group0 %indata4\n"
1110 "OpGroupDecorate %group1 %indata4\n"
1111 "OpGroupDecorate %group3 %indata4\n"
1112 "OpDecorate %indata4 Binding 4\n"
1114 + string(s_CommonTypes) +
1116 "%id = OpVariable %uvec3ptr Input\n"
1117 "%zero = OpConstant %i32 0\n"
1119 "%outbuf = OpTypeStruct %f32arr\n"
1120 "%outbufptr = OpTypePointer Uniform %outbuf\n"
1121 "%outdata = OpVariable %outbufptr Uniform\n"
1122 "%inbuf0 = OpTypeStruct %f32arr\n"
1123 "%inbuf0ptr = OpTypePointer Uniform %inbuf0\n"
1124 "%indata0 = OpVariable %inbuf0ptr Uniform\n"
1125 "%inbuf1 = OpTypeStruct %f32arr\n"
1126 "%inbuf1ptr = OpTypePointer Uniform %inbuf1\n"
1127 "%indata1 = OpVariable %inbuf1ptr Uniform\n"
1128 "%inbuf2 = OpTypeStruct %f32arr\n"
1129 "%inbuf2ptr = OpTypePointer Uniform %inbuf2\n"
1130 "%indata2 = OpVariable %inbuf2ptr Uniform\n"
1131 "%inbuf3 = OpTypeStruct %f32arr\n"
1132 "%inbuf3ptr = OpTypePointer Uniform %inbuf3\n"
1133 "%indata3 = OpVariable %inbuf3ptr Uniform\n"
1134 "%inbuf4 = OpTypeStruct %f32arr\n"
1135 "%inbufptr = OpTypePointer Uniform %inbuf4\n"
1136 "%indata4 = OpVariable %inbufptr Uniform\n"
1138 "%main = OpFunction %void None %voidf\n"
1139 "%label = OpLabel\n"
1140 "%idval = OpLoad %uvec3 %id\n"
1141 "%x = OpCompositeExtract %u32 %idval 0\n"
1142 "%inloc0 = OpAccessChain %f32ptr %indata0 %zero %x\n"
1143 "%inloc1 = OpAccessChain %f32ptr %indata1 %zero %x\n"
1144 "%inloc2 = OpAccessChain %f32ptr %indata2 %zero %x\n"
1145 "%inloc3 = OpAccessChain %f32ptr %indata3 %zero %x\n"
1146 "%inloc4 = OpAccessChain %f32ptr %indata4 %zero %x\n"
1147 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
1148 "%inval0 = OpLoad %f32 %inloc0\n"
1149 "%inval1 = OpLoad %f32 %inloc1\n"
1150 "%inval2 = OpLoad %f32 %inloc2\n"
1151 "%inval3 = OpLoad %f32 %inloc3\n"
1152 "%inval4 = OpLoad %f32 %inloc4\n"
1153 "%add0 = OpFAdd %f32 %inval0 %inval1\n"
1154 "%add1 = OpFAdd %f32 %add0 %inval2\n"
1155 "%add2 = OpFAdd %f32 %add1 %inval3\n"
1156 "%add = OpFAdd %f32 %add2 %inval4\n"
1157 " OpStore %outloc %add\n"
1160 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats0)));
1161 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats1)));
1162 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2)));
1163 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats3)));
1164 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats4)));
1165 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
1166 spec.numWorkGroups = IVec3(numElements, 1, 1);
1168 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "decoration group cases", spec));
1170 return group.release();
1173 struct SpecConstantTwoIntCase
1175 const char* caseName;
1176 const char* scDefinition0;
1177 const char* scDefinition1;
1178 const char* scResultType;
1179 const char* scOperation;
1180 deInt32 scActualValue0;
1181 deInt32 scActualValue1;
1182 const char* resultOperation;
1183 vector<deInt32> expectedOutput;
1185 SpecConstantTwoIntCase (const char* name,
1186 const char* definition0,
1187 const char* definition1,
1188 const char* resultType,
1189 const char* operation,
1192 const char* resultOp,
1193 const vector<deInt32>& output)
1195 , scDefinition0 (definition0)
1196 , scDefinition1 (definition1)
1197 , scResultType (resultType)
1198 , scOperation (operation)
1199 , scActualValue0 (value0)
1200 , scActualValue1 (value1)
1201 , resultOperation (resultOp)
1202 , expectedOutput (output) {}
1205 tcu::TestCaseGroup* createSpecConstantGroup (tcu::TestContext& testCtx)
1207 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opspecconstantop", "Test the OpSpecConstantOp instruction"));
1208 vector<SpecConstantTwoIntCase> cases;
1209 de::Random rnd (deStringHash(group->getName()));
1210 const int numElements = 100;
1211 vector<deInt32> inputInts (numElements, 0);
1212 vector<deInt32> outputInts1 (numElements, 0);
1213 vector<deInt32> outputInts2 (numElements, 0);
1214 vector<deInt32> outputInts3 (numElements, 0);
1215 vector<deInt32> outputInts4 (numElements, 0);
1216 const StringTemplate shaderTemplate (
1217 string(s_ShaderPreamble) +
1219 "OpName %main \"main\"\n"
1220 "OpName %id \"gl_GlobalInvocationID\"\n"
1222 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1223 "OpDecorate %sc_0 SpecId 0\n"
1224 "OpDecorate %sc_1 SpecId 1\n"
1225 "OpDecorate %i32arr ArrayStride 4\n"
1227 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) +
1229 "%i32ptr = OpTypePointer Uniform %i32\n"
1230 "%i32arr = OpTypeRuntimeArray %i32\n"
1231 "%boolptr = OpTypePointer Uniform %bool\n"
1232 "%boolarr = OpTypeRuntimeArray %bool\n"
1233 "%buf = OpTypeStruct %i32arr\n"
1234 "%bufptr = OpTypePointer Uniform %buf\n"
1235 "%indata = OpVariable %bufptr Uniform\n"
1236 "%outdata = OpVariable %bufptr Uniform\n"
1238 "%id = OpVariable %uvec3ptr Input\n"
1239 "%zero = OpConstant %i32 0\n"
1241 "%sc_0 = OpSpecConstant${SC_DEF0}\n"
1242 "%sc_1 = OpSpecConstant${SC_DEF1}\n"
1243 "%sc_final = OpSpecConstantOp ${SC_RESULT_TYPE} ${SC_OP}\n"
1245 "%main = OpFunction %void None %voidf\n"
1246 "%label = OpLabel\n"
1247 "%idval = OpLoad %uvec3 %id\n"
1248 "%x = OpCompositeExtract %u32 %idval 0\n"
1249 "%inloc = OpAccessChain %i32ptr %indata %zero %x\n"
1250 "%inval = OpLoad %i32 %inloc\n"
1251 "%final = ${GEN_RESULT}\n"
1252 "%outloc = OpAccessChain %i32ptr %outdata %zero %x\n"
1253 " OpStore %outloc %final\n"
1255 " OpFunctionEnd\n");
1257 fillRandomScalars(rnd, -65536, 65536, &inputInts[0], numElements);
1259 for (size_t ndx = 0; ndx < numElements; ++ndx)
1261 outputInts1[ndx] = inputInts[ndx] + 42;
1262 outputInts2[ndx] = inputInts[ndx];
1263 outputInts3[ndx] = inputInts[ndx] - 11200;
1264 outputInts4[ndx] = inputInts[ndx] + 1;
1267 const char addScToInput[] = "OpIAdd %i32 %inval %sc_final";
1268 const char selectTrueUsingSc[] = "OpSelect %i32 %sc_final %inval %zero";
1269 const char selectFalseUsingSc[] = "OpSelect %i32 %sc_final %zero %inval";
1271 cases.push_back(SpecConstantTwoIntCase("iadd", " %i32 0", " %i32 0", "%i32", "IAdd %sc_0 %sc_1", 62, -20, addScToInput, outputInts1));
1272 cases.push_back(SpecConstantTwoIntCase("isub", " %i32 0", " %i32 0", "%i32", "ISub %sc_0 %sc_1", 100, 58, addScToInput, outputInts1));
1273 cases.push_back(SpecConstantTwoIntCase("imul", " %i32 0", " %i32 0", "%i32", "IMul %sc_0 %sc_1", -2, -21, addScToInput, outputInts1));
1274 cases.push_back(SpecConstantTwoIntCase("sdiv", " %i32 0", " %i32 0", "%i32", "SDiv %sc_0 %sc_1", -126, -3, addScToInput, outputInts1));
1275 cases.push_back(SpecConstantTwoIntCase("udiv", " %i32 0", " %i32 0", "%i32", "UDiv %sc_0 %sc_1", 126, 3, addScToInput, outputInts1));
1276 cases.push_back(SpecConstantTwoIntCase("srem", " %i32 0", " %i32 0", "%i32", "SRem %sc_0 %sc_1", 7, 3, addScToInput, outputInts4));
1277 cases.push_back(SpecConstantTwoIntCase("smod", " %i32 0", " %i32 0", "%i32", "SMod %sc_0 %sc_1", 7, 3, addScToInput, outputInts4));
1278 cases.push_back(SpecConstantTwoIntCase("umod", " %i32 0", " %i32 0", "%i32", "UMod %sc_0 %sc_1", 342, 50, addScToInput, outputInts1));
1279 cases.push_back(SpecConstantTwoIntCase("bitwiseand", " %i32 0", " %i32 0", "%i32", "BitwiseAnd %sc_0 %sc_1", 42, 63, addScToInput, outputInts1));
1280 cases.push_back(SpecConstantTwoIntCase("bitwiseor", " %i32 0", " %i32 0", "%i32", "BitwiseOr %sc_0 %sc_1", 34, 8, addScToInput, outputInts1));
1281 cases.push_back(SpecConstantTwoIntCase("bitwisexor", " %i32 0", " %i32 0", "%i32", "BitwiseXor %sc_0 %sc_1", 18, 56, addScToInput, outputInts1));
1282 cases.push_back(SpecConstantTwoIntCase("shiftrightlogical", " %i32 0", " %i32 0", "%i32", "ShiftRightLogical %sc_0 %sc_1", 168, 2, addScToInput, outputInts1));
1283 cases.push_back(SpecConstantTwoIntCase("shiftrightarithmetic", " %i32 0", " %i32 0", "%i32", "ShiftRightArithmetic %sc_0 %sc_1", 168, 2, addScToInput, outputInts1));
1284 cases.push_back(SpecConstantTwoIntCase("shiftleftlogical", " %i32 0", " %i32 0", "%i32", "ShiftLeftLogical %sc_0 %sc_1", 21, 1, addScToInput, outputInts1));
1285 cases.push_back(SpecConstantTwoIntCase("slessthan", " %i32 0", " %i32 0", "%bool", "SLessThan %sc_0 %sc_1", -20, -10, selectTrueUsingSc, outputInts2));
1286 cases.push_back(SpecConstantTwoIntCase("ulessthan", " %i32 0", " %i32 0", "%bool", "ULessThan %sc_0 %sc_1", 10, 20, selectTrueUsingSc, outputInts2));
1287 cases.push_back(SpecConstantTwoIntCase("sgreaterthan", " %i32 0", " %i32 0", "%bool", "SGreaterThan %sc_0 %sc_1", -1000, 50, selectFalseUsingSc, outputInts2));
1288 cases.push_back(SpecConstantTwoIntCase("ugreaterthan", " %i32 0", " %i32 0", "%bool", "UGreaterThan %sc_0 %sc_1", 10, 5, selectTrueUsingSc, outputInts2));
1289 cases.push_back(SpecConstantTwoIntCase("slessthanequal", " %i32 0", " %i32 0", "%bool", "SLessThanEqual %sc_0 %sc_1", -10, -10, selectTrueUsingSc, outputInts2));
1290 cases.push_back(SpecConstantTwoIntCase("ulessthanequal", " %i32 0", " %i32 0", "%bool", "ULessThanEqual %sc_0 %sc_1", 50, 100, selectTrueUsingSc, outputInts2));
1291 cases.push_back(SpecConstantTwoIntCase("sgreaterthanequal", " %i32 0", " %i32 0", "%bool", "SGreaterThanEqual %sc_0 %sc_1", -1000, 50, selectFalseUsingSc, outputInts2));
1292 cases.push_back(SpecConstantTwoIntCase("ugreaterthanequal", " %i32 0", " %i32 0", "%bool", "UGreaterThanEqual %sc_0 %sc_1", 10, 10, selectTrueUsingSc, outputInts2));
1293 cases.push_back(SpecConstantTwoIntCase("iequal", " %i32 0", " %i32 0", "%bool", "IEqual %sc_0 %sc_1", 42, 24, selectFalseUsingSc, outputInts2));
1294 cases.push_back(SpecConstantTwoIntCase("logicaland", "True %bool", "True %bool", "%bool", "LogicalAnd %sc_0 %sc_1", 0, 1, selectFalseUsingSc, outputInts2));
1295 cases.push_back(SpecConstantTwoIntCase("logicalor", "False %bool", "False %bool", "%bool", "LogicalOr %sc_0 %sc_1", 1, 0, selectTrueUsingSc, outputInts2));
1296 cases.push_back(SpecConstantTwoIntCase("logicalequal", "True %bool", "True %bool", "%bool", "LogicalEqual %sc_0 %sc_1", 0, 1, selectFalseUsingSc, outputInts2));
1297 cases.push_back(SpecConstantTwoIntCase("logicalnotequal", "False %bool", "False %bool", "%bool", "LogicalNotEqual %sc_0 %sc_1", 1, 0, selectTrueUsingSc, outputInts2));
1298 cases.push_back(SpecConstantTwoIntCase("snegate", " %i32 0", " %i32 0", "%i32", "SNegate %sc_0", -42, 0, addScToInput, outputInts1));
1299 cases.push_back(SpecConstantTwoIntCase("not", " %i32 0", " %i32 0", "%i32", "Not %sc_0", -43, 0, addScToInput, outputInts1));
1300 cases.push_back(SpecConstantTwoIntCase("logicalnot", "False %bool", "False %bool", "%bool", "LogicalNot %sc_0", 1, 0, selectFalseUsingSc, outputInts2));
1301 cases.push_back(SpecConstantTwoIntCase("select", "False %bool", " %i32 0", "%i32", "Select %sc_0 %sc_1 %zero", 1, 42, addScToInput, outputInts1));
1302 // OpSConvert, OpFConvert: these two instructions involve ints/floats of different bitwidths.
1304 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
1306 map<string, string> specializations;
1307 ComputeShaderSpec spec;
1309 specializations["SC_DEF0"] = cases[caseNdx].scDefinition0;
1310 specializations["SC_DEF1"] = cases[caseNdx].scDefinition1;
1311 specializations["SC_RESULT_TYPE"] = cases[caseNdx].scResultType;
1312 specializations["SC_OP"] = cases[caseNdx].scOperation;
1313 specializations["GEN_RESULT"] = cases[caseNdx].resultOperation;
1315 spec.assembly = shaderTemplate.specialize(specializations);
1316 spec.inputs.push_back(BufferSp(new Int32Buffer(inputInts)));
1317 spec.outputs.push_back(BufferSp(new Int32Buffer(cases[caseNdx].expectedOutput)));
1318 spec.numWorkGroups = IVec3(numElements, 1, 1);
1319 spec.specConstants.push_back(cases[caseNdx].scActualValue0);
1320 spec.specConstants.push_back(cases[caseNdx].scActualValue1);
1322 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].caseName, cases[caseNdx].caseName, spec));
1325 ComputeShaderSpec spec;
1328 string(s_ShaderPreamble) +
1330 "OpName %main \"main\"\n"
1331 "OpName %id \"gl_GlobalInvocationID\"\n"
1333 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1334 "OpDecorate %sc_0 SpecId 0\n"
1335 "OpDecorate %sc_1 SpecId 1\n"
1336 "OpDecorate %sc_2 SpecId 2\n"
1337 "OpDecorate %i32arr ArrayStride 4\n"
1339 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) +
1341 "%ivec3 = OpTypeVector %i32 3\n"
1342 "%i32ptr = OpTypePointer Uniform %i32\n"
1343 "%i32arr = OpTypeRuntimeArray %i32\n"
1344 "%boolptr = OpTypePointer Uniform %bool\n"
1345 "%boolarr = OpTypeRuntimeArray %bool\n"
1346 "%buf = OpTypeStruct %i32arr\n"
1347 "%bufptr = OpTypePointer Uniform %buf\n"
1348 "%indata = OpVariable %bufptr Uniform\n"
1349 "%outdata = OpVariable %bufptr Uniform\n"
1351 "%id = OpVariable %uvec3ptr Input\n"
1352 "%zero = OpConstant %i32 0\n"
1353 "%ivec3_0 = OpConstantComposite %ivec3 %zero %zero %zero\n"
1355 "%sc_0 = OpSpecConstant %i32 0\n"
1356 "%sc_1 = OpSpecConstant %i32 0\n"
1357 "%sc_2 = OpSpecConstant %i32 0\n"
1358 "%sc_vec3_0 = OpSpecConstantOp %ivec3 CompositeInsert %sc_0 %ivec3_0 0\n" // (sc_0, 0, 0)
1359 "%sc_vec3_1 = OpSpecConstantOp %ivec3 CompositeInsert %sc_1 %ivec3_0 1\n" // (0, sc_1, 0)
1360 "%sc_vec3_2 = OpSpecConstantOp %ivec3 CompositeInsert %sc_2 %ivec3_0 2\n" // (0, 0, sc_2)
1361 "%sc_vec3_01 = OpSpecConstantOp %ivec3 VectorShuffle %sc_vec3_0 %sc_vec3_1 1 0 4\n" // (0, sc_0, sc_1)
1362 "%sc_vec3_012 = OpSpecConstantOp %ivec3 VectorShuffle %sc_vec3_01 %sc_vec3_2 5 1 2\n" // (sc_2, sc_0, sc_1)
1363 "%sc_ext_0 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 0\n" // sc_2
1364 "%sc_ext_1 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 1\n" // sc_0
1365 "%sc_ext_2 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 2\n" // sc_1
1366 "%sc_sub = OpSpecConstantOp %i32 ISub %sc_ext_0 %sc_ext_1\n" // (sc_2 - sc_0)
1367 "%sc_final = OpSpecConstantOp %i32 IMul %sc_sub %sc_ext_2\n" // (sc_2 - sc_0) * sc_1
1369 "%main = OpFunction %void None %voidf\n"
1370 "%label = OpLabel\n"
1371 "%idval = OpLoad %uvec3 %id\n"
1372 "%x = OpCompositeExtract %u32 %idval 0\n"
1373 "%inloc = OpAccessChain %i32ptr %indata %zero %x\n"
1374 "%inval = OpLoad %i32 %inloc\n"
1375 "%final = OpIAdd %i32 %inval %sc_final\n"
1376 "%outloc = OpAccessChain %i32ptr %outdata %zero %x\n"
1377 " OpStore %outloc %final\n"
1380 spec.inputs.push_back(BufferSp(new Int32Buffer(inputInts)));
1381 spec.outputs.push_back(BufferSp(new Int32Buffer(outputInts3)));
1382 spec.numWorkGroups = IVec3(numElements, 1, 1);
1383 spec.specConstants.push_back(123);
1384 spec.specConstants.push_back(56);
1385 spec.specConstants.push_back(-77);
1387 group->addChild(new SpvAsmComputeShaderCase(testCtx, "vector_related", "VectorShuffle, CompositeExtract, & CompositeInsert", spec));
1389 return group.release();
1392 tcu::TestCaseGroup* createOpPhiGroup (tcu::TestContext& testCtx)
1394 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opphi", "Test the OpPhi instruction"));
1395 ComputeShaderSpec spec1;
1396 ComputeShaderSpec spec2;
1397 ComputeShaderSpec spec3;
1398 de::Random rnd (deStringHash(group->getName()));
1399 const int numElements = 100;
1400 vector<float> inputFloats (numElements, 0);
1401 vector<float> outputFloats1 (numElements, 0);
1402 vector<float> outputFloats2 (numElements, 0);
1403 vector<float> outputFloats3 (numElements, 0);
1405 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats[0], numElements);
1407 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
1408 floorAll(inputFloats);
1410 for (size_t ndx = 0; ndx < numElements; ++ndx)
1414 case 0: outputFloats1[ndx] = inputFloats[ndx] + 5.5f; break;
1415 case 1: outputFloats1[ndx] = inputFloats[ndx] + 20.5f; break;
1416 case 2: outputFloats1[ndx] = inputFloats[ndx] + 1.75f; break;
1419 outputFloats2[ndx] = inputFloats[ndx] + 6.5f * 3;
1420 outputFloats3[ndx] = 8.5f - inputFloats[ndx];
1424 string(s_ShaderPreamble) +
1426 "OpSource GLSL 430\n"
1427 "OpName %main \"main\"\n"
1428 "OpName %id \"gl_GlobalInvocationID\"\n"
1430 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1432 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) + string(s_InputOutputBuffer) +
1434 "%id = OpVariable %uvec3ptr Input\n"
1435 "%zero = OpConstant %i32 0\n"
1436 "%three = OpConstant %u32 3\n"
1437 "%constf5p5 = OpConstant %f32 5.5\n"
1438 "%constf20p5 = OpConstant %f32 20.5\n"
1439 "%constf1p75 = OpConstant %f32 1.75\n"
1440 "%constf8p5 = OpConstant %f32 8.5\n"
1441 "%constf6p5 = OpConstant %f32 6.5\n"
1443 "%main = OpFunction %void None %voidf\n"
1444 "%entry = OpLabel\n"
1445 "%idval = OpLoad %uvec3 %id\n"
1446 "%x = OpCompositeExtract %u32 %idval 0\n"
1447 "%selector = OpUMod %u32 %x %three\n"
1448 " OpSelectionMerge %phi None\n"
1449 " OpSwitch %selector %default 0 %case0 1 %case1 2 %case2\n"
1451 // Case 1 before OpPhi.
1452 "%case1 = OpLabel\n"
1455 "%default = OpLabel\n"
1459 "%operand = OpPhi %f32 %constf1p75 %case2 %constf20p5 %case1 %constf5p5 %case0\n" // not in the order of blocks
1460 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
1461 "%inval = OpLoad %f32 %inloc\n"
1462 "%add = OpFAdd %f32 %inval %operand\n"
1463 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
1464 " OpStore %outloc %add\n"
1467 // Case 0 after OpPhi.
1468 "%case0 = OpLabel\n"
1472 // Case 2 after OpPhi.
1473 "%case2 = OpLabel\n"
1477 spec1.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
1478 spec1.outputs.push_back(BufferSp(new Float32Buffer(outputFloats1)));
1479 spec1.numWorkGroups = IVec3(numElements, 1, 1);
1481 group->addChild(new SpvAsmComputeShaderCase(testCtx, "block", "out-of-order and unreachable blocks for OpPhi", spec1));
1484 string(s_ShaderPreamble) +
1486 "OpName %main \"main\"\n"
1487 "OpName %id \"gl_GlobalInvocationID\"\n"
1489 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1491 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) + string(s_InputOutputBuffer) +
1493 "%id = OpVariable %uvec3ptr Input\n"
1494 "%zero = OpConstant %i32 0\n"
1495 "%one = OpConstant %i32 1\n"
1496 "%three = OpConstant %i32 3\n"
1497 "%constf6p5 = OpConstant %f32 6.5\n"
1499 "%main = OpFunction %void None %voidf\n"
1500 "%entry = OpLabel\n"
1501 "%idval = OpLoad %uvec3 %id\n"
1502 "%x = OpCompositeExtract %u32 %idval 0\n"
1503 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
1504 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
1505 "%inval = OpLoad %f32 %inloc\n"
1509 "%step = OpPhi %i32 %zero %entry %step_next %phi\n"
1510 "%accum = OpPhi %f32 %inval %entry %accum_next %phi\n"
1511 "%step_next = OpIAdd %i32 %step %one\n"
1512 "%accum_next = OpFAdd %f32 %accum %constf6p5\n"
1513 "%still_loop = OpSLessThan %bool %step %three\n"
1514 " OpLoopMerge %exit %phi None\n"
1515 " OpBranchConditional %still_loop %phi %exit\n"
1518 " OpStore %outloc %accum\n"
1521 spec2.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
1522 spec2.outputs.push_back(BufferSp(new Float32Buffer(outputFloats2)));
1523 spec2.numWorkGroups = IVec3(numElements, 1, 1);
1525 group->addChild(new SpvAsmComputeShaderCase(testCtx, "induction", "The usual way induction variables are handled in LLVM IR", spec2));
1528 string(s_ShaderPreamble) +
1530 "OpName %main \"main\"\n"
1531 "OpName %id \"gl_GlobalInvocationID\"\n"
1533 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1535 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) + string(s_InputOutputBuffer) +
1537 "%f32ptr_f = OpTypePointer Function %f32\n"
1538 "%id = OpVariable %uvec3ptr Input\n"
1539 "%true = OpConstantTrue %bool\n"
1540 "%false = OpConstantFalse %bool\n"
1541 "%zero = OpConstant %i32 0\n"
1542 "%constf8p5 = OpConstant %f32 8.5\n"
1544 "%main = OpFunction %void None %voidf\n"
1545 "%entry = OpLabel\n"
1546 "%b = OpVariable %f32ptr_f Function %constf8p5\n"
1547 "%idval = OpLoad %uvec3 %id\n"
1548 "%x = OpCompositeExtract %u32 %idval 0\n"
1549 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
1550 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
1551 "%a_init = OpLoad %f32 %inloc\n"
1552 "%b_init = OpLoad %f32 %b\n"
1556 "%still_loop = OpPhi %bool %true %entry %false %phi\n"
1557 "%a_next = OpPhi %f32 %a_init %entry %b_next %phi\n"
1558 "%b_next = OpPhi %f32 %b_init %entry %a_next %phi\n"
1559 " OpLoopMerge %exit %phi None\n"
1560 " OpBranchConditional %still_loop %phi %exit\n"
1563 "%sub = OpFSub %f32 %a_next %b_next\n"
1564 " OpStore %outloc %sub\n"
1567 spec3.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
1568 spec3.outputs.push_back(BufferSp(new Float32Buffer(outputFloats3)));
1569 spec3.numWorkGroups = IVec3(numElements, 1, 1);
1571 group->addChild(new SpvAsmComputeShaderCase(testCtx, "swap", "Swap the values of two variables using OpPhi", spec3));
1573 return group.release();
1576 // Assembly code used for testing block order is based on GLSL source code:
1580 // layout(std140, set = 0, binding = 0) readonly buffer Input {
1581 // float elements[];
1583 // layout(std140, set = 0, binding = 1) writeonly buffer Output {
1584 // float elements[];
1588 // uint x = gl_GlobalInvocationID.x;
1589 // output_data.elements[x] = input_data.elements[x];
1590 // if (x > uint(50)) {
1591 // switch (x % uint(3)) {
1592 // case 0: output_data.elements[x] += 1.5f; break;
1593 // case 1: output_data.elements[x] += 42.f; break;
1594 // case 2: output_data.elements[x] -= 27.f; break;
1598 // output_data.elements[x] = -input_data.elements[x];
1601 tcu::TestCaseGroup* createBlockOrderGroup (tcu::TestContext& testCtx)
1603 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "block_order", "Test block orders"));
1604 ComputeShaderSpec spec;
1605 de::Random rnd (deStringHash(group->getName()));
1606 const int numElements = 100;
1607 vector<float> inputFloats (numElements, 0);
1608 vector<float> outputFloats (numElements, 0);
1610 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats[0], numElements);
1612 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
1613 floorAll(inputFloats);
1615 for (size_t ndx = 0; ndx <= 50; ++ndx)
1616 outputFloats[ndx] = -inputFloats[ndx];
1618 for (size_t ndx = 51; ndx < numElements; ++ndx)
1622 case 0: outputFloats[ndx] = inputFloats[ndx] + 1.5f; break;
1623 case 1: outputFloats[ndx] = inputFloats[ndx] + 42.f; break;
1624 case 2: outputFloats[ndx] = inputFloats[ndx] - 27.f; break;
1630 string(s_ShaderPreamble) +
1632 "OpSource GLSL 430\n"
1633 "OpName %main \"main\"\n"
1634 "OpName %id \"gl_GlobalInvocationID\"\n"
1636 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1638 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) +
1640 "%u32ptr = OpTypePointer Function %u32\n"
1641 "%u32ptr_input = OpTypePointer Input %u32\n"
1643 + string(s_InputOutputBuffer) +
1645 "%id = OpVariable %uvec3ptr Input\n"
1646 "%zero = OpConstant %i32 0\n"
1647 "%const3 = OpConstant %u32 3\n"
1648 "%const50 = OpConstant %u32 50\n"
1649 "%constf1p5 = OpConstant %f32 1.5\n"
1650 "%constf27 = OpConstant %f32 27.0\n"
1651 "%constf42 = OpConstant %f32 42.0\n"
1653 "%main = OpFunction %void None %voidf\n"
1656 "%entry = OpLabel\n"
1658 // Create a temporary variable to hold the value of gl_GlobalInvocationID.x.
1659 "%xvar = OpVariable %u32ptr Function\n"
1660 "%xptr = OpAccessChain %u32ptr_input %id %zero\n"
1661 "%x = OpLoad %u32 %xptr\n"
1662 " OpStore %xvar %x\n"
1664 "%cmp = OpUGreaterThan %bool %x %const50\n"
1665 " OpSelectionMerge %if_merge None\n"
1666 " OpBranchConditional %cmp %if_true %if_false\n"
1668 // Merge block for switch-statement: placed at the beginning.
1669 "%switch_merge = OpLabel\n"
1670 " OpBranch %if_merge\n"
1672 // Case 1 for switch-statement.
1673 "%case1 = OpLabel\n"
1674 "%x_1 = OpLoad %u32 %xvar\n"
1675 "%inloc_1 = OpAccessChain %f32ptr %indata %zero %x_1\n"
1676 "%inval_1 = OpLoad %f32 %inloc_1\n"
1677 "%addf42 = OpFAdd %f32 %inval_1 %constf42\n"
1678 "%outloc_1 = OpAccessChain %f32ptr %outdata %zero %x_1\n"
1679 " OpStore %outloc_1 %addf42\n"
1680 " OpBranch %switch_merge\n"
1682 // False branch for if-statement: placed in the middle of switch cases and before true branch.
1683 "%if_false = OpLabel\n"
1684 "%x_f = OpLoad %u32 %xvar\n"
1685 "%inloc_f = OpAccessChain %f32ptr %indata %zero %x_f\n"
1686 "%inval_f = OpLoad %f32 %inloc_f\n"
1687 "%negate = OpFNegate %f32 %inval_f\n"
1688 "%outloc_f = OpAccessChain %f32ptr %outdata %zero %x_f\n"
1689 " OpStore %outloc_f %negate\n"
1690 " OpBranch %if_merge\n"
1692 // Merge block for if-statement: placed in the middle of true and false branch.
1693 "%if_merge = OpLabel\n"
1696 // True branch for if-statement: placed in the middle of swtich cases and after the false branch.
1697 "%if_true = OpLabel\n"
1698 "%xval_t = OpLoad %u32 %xvar\n"
1699 "%mod = OpUMod %u32 %xval_t %const3\n"
1700 " OpSelectionMerge %switch_merge None\n"
1701 " OpSwitch %mod %default 0 %case0 1 %case1 2 %case2\n"
1703 // Case 2 for switch-statement.
1704 "%case2 = OpLabel\n"
1705 "%x_2 = OpLoad %u32 %xvar\n"
1706 "%inloc_2 = OpAccessChain %f32ptr %indata %zero %x_2\n"
1707 "%inval_2 = OpLoad %f32 %inloc_2\n"
1708 "%subf27 = OpFSub %f32 %inval_2 %constf27\n"
1709 "%outloc_2 = OpAccessChain %f32ptr %outdata %zero %x_2\n"
1710 " OpStore %outloc_2 %subf27\n"
1711 " OpBranch %switch_merge\n"
1713 // Default case for switch-statement: placed in the middle of normal cases.
1714 "%default = OpLabel\n"
1715 " OpBranch %switch_merge\n"
1717 // Case 0 for switch-statement: out of order.
1718 "%case0 = OpLabel\n"
1719 "%x_0 = OpLoad %u32 %xvar\n"
1720 "%inloc_0 = OpAccessChain %f32ptr %indata %zero %x_0\n"
1721 "%inval_0 = OpLoad %f32 %inloc_0\n"
1722 "%addf1p5 = OpFAdd %f32 %inval_0 %constf1p5\n"
1723 "%outloc_0 = OpAccessChain %f32ptr %outdata %zero %x_0\n"
1724 " OpStore %outloc_0 %addf1p5\n"
1725 " OpBranch %switch_merge\n"
1728 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
1729 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
1730 spec.numWorkGroups = IVec3(numElements, 1, 1);
1732 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "various out-of-order blocks", spec));
1734 return group.release();
1737 tcu::TestCaseGroup* createMultipleShaderGroup (tcu::TestContext& testCtx)
1739 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "multiple_shaders", "Test multiple shaders in the same module"));
1740 ComputeShaderSpec spec1;
1741 ComputeShaderSpec spec2;
1742 de::Random rnd (deStringHash(group->getName()));
1743 const int numElements = 100;
1744 vector<float> inputFloats (numElements, 0);
1745 vector<float> outputFloats1 (numElements, 0);
1746 vector<float> outputFloats2 (numElements, 0);
1747 fillRandomScalars(rnd, -500.f, 500.f, &inputFloats[0], numElements);
1749 for (size_t ndx = 0; ndx < numElements; ++ndx)
1751 outputFloats1[ndx] = inputFloats[ndx] + inputFloats[ndx];
1752 outputFloats2[ndx] = -inputFloats[ndx];
1755 const string assembly(
1756 "OpCapability Shader\n"
1757 "OpCapability ClipDistance\n"
1758 "OpMemoryModel Logical GLSL450\n"
1759 "OpEntryPoint GLCompute %comp_main1 \"entrypoint1\" %id\n"
1760 "OpEntryPoint GLCompute %comp_main2 \"entrypoint2\" %id\n"
1761 // A module cannot have two OpEntryPoint instructions with the same Execution Model and the same Name string.
1762 "OpEntryPoint Vertex %vert_main \"entrypoint2\" %vert_builtins %vertexIndex %instanceIndex\n"
1763 "OpExecutionMode %comp_main1 LocalSize 1 1 1\n"
1764 "OpExecutionMode %comp_main2 LocalSize 1 1 1\n"
1766 "OpName %comp_main1 \"entrypoint1\"\n"
1767 "OpName %comp_main2 \"entrypoint2\"\n"
1768 "OpName %vert_main \"entrypoint2\"\n"
1769 "OpName %id \"gl_GlobalInvocationID\"\n"
1770 "OpName %vert_builtin_st \"gl_PerVertex\"\n"
1771 "OpName %vertexIndex \"gl_VertexIndex\"\n"
1772 "OpName %instanceIndex \"gl_InstanceIndex\"\n"
1773 "OpMemberName %vert_builtin_st 0 \"gl_Position\"\n"
1774 "OpMemberName %vert_builtin_st 1 \"gl_PointSize\"\n"
1775 "OpMemberName %vert_builtin_st 2 \"gl_ClipDistance\"\n"
1777 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1778 "OpDecorate %vertexIndex BuiltIn VertexIndex\n"
1779 "OpDecorate %instanceIndex BuiltIn InstanceIndex\n"
1780 "OpDecorate %vert_builtin_st Block\n"
1781 "OpMemberDecorate %vert_builtin_st 0 BuiltIn Position\n"
1782 "OpMemberDecorate %vert_builtin_st 1 BuiltIn PointSize\n"
1783 "OpMemberDecorate %vert_builtin_st 2 BuiltIn ClipDistance\n"
1785 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) + string(s_InputOutputBuffer) +
1787 "%zero = OpConstant %i32 0\n"
1788 "%one = OpConstant %u32 1\n"
1789 "%c_f32_1 = OpConstant %f32 1\n"
1791 "%i32ptr = OpTypePointer Input %i32\n"
1792 "%vec4 = OpTypeVector %f32 4\n"
1793 "%vec4ptr = OpTypePointer Output %vec4\n"
1794 "%f32arr1 = OpTypeArray %f32 %one\n"
1795 "%vert_builtin_st = OpTypeStruct %vec4 %f32 %f32arr1\n"
1796 "%vert_builtin_st_ptr = OpTypePointer Output %vert_builtin_st\n"
1797 "%vert_builtins = OpVariable %vert_builtin_st_ptr Output\n"
1799 "%id = OpVariable %uvec3ptr Input\n"
1800 "%vertexIndex = OpVariable %i32ptr Input\n"
1801 "%instanceIndex = OpVariable %i32ptr Input\n"
1802 "%c_vec4_1 = OpConstantComposite %vec4 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_1\n"
1804 // gl_Position = vec4(1.);
1805 "%vert_main = OpFunction %void None %voidf\n"
1806 "%vert_entry = OpLabel\n"
1807 "%position = OpAccessChain %vec4ptr %vert_builtins %zero\n"
1808 " OpStore %position %c_vec4_1\n"
1813 "%comp_main1 = OpFunction %void None %voidf\n"
1814 "%comp1_entry = OpLabel\n"
1815 "%idval1 = OpLoad %uvec3 %id\n"
1816 "%x1 = OpCompositeExtract %u32 %idval1 0\n"
1817 "%inloc1 = OpAccessChain %f32ptr %indata %zero %x1\n"
1818 "%inval1 = OpLoad %f32 %inloc1\n"
1819 "%add = OpFAdd %f32 %inval1 %inval1\n"
1820 "%outloc1 = OpAccessChain %f32ptr %outdata %zero %x1\n"
1821 " OpStore %outloc1 %add\n"
1826 "%comp_main2 = OpFunction %void None %voidf\n"
1827 "%comp2_entry = OpLabel\n"
1828 "%idval2 = OpLoad %uvec3 %id\n"
1829 "%x2 = OpCompositeExtract %u32 %idval2 0\n"
1830 "%inloc2 = OpAccessChain %f32ptr %indata %zero %x2\n"
1831 "%inval2 = OpLoad %f32 %inloc2\n"
1832 "%neg = OpFNegate %f32 %inval2\n"
1833 "%outloc2 = OpAccessChain %f32ptr %outdata %zero %x2\n"
1834 " OpStore %outloc2 %neg\n"
1836 " OpFunctionEnd\n");
1838 spec1.assembly = assembly;
1839 spec1.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
1840 spec1.outputs.push_back(BufferSp(new Float32Buffer(outputFloats1)));
1841 spec1.numWorkGroups = IVec3(numElements, 1, 1);
1842 spec1.entryPoint = "entrypoint1";
1844 spec2.assembly = assembly;
1845 spec2.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
1846 spec2.outputs.push_back(BufferSp(new Float32Buffer(outputFloats2)));
1847 spec2.numWorkGroups = IVec3(numElements, 1, 1);
1848 spec2.entryPoint = "entrypoint2";
1850 group->addChild(new SpvAsmComputeShaderCase(testCtx, "shader1", "multiple shaders in the same module", spec1));
1851 group->addChild(new SpvAsmComputeShaderCase(testCtx, "shader2", "multiple shaders in the same module", spec2));
1853 return group.release();
1856 inline std::string makeLongUTF8String (size_t num4ByteChars)
1858 // An example of a longest valid UTF-8 character. Be explicit about the
1859 // character type because Microsoft compilers can otherwise interpret the
1860 // character string as being over wide (16-bit) characters. Ideally, we
1861 // would just use a C++11 UTF-8 string literal, but we want to support older
1862 // Microsoft compilers.
1863 const std::basic_string<char> earthAfrica("\xF0\x9F\x8C\x8D");
1864 std::string longString;
1865 longString.reserve(num4ByteChars * 4);
1866 for (size_t count = 0; count < num4ByteChars; count++)
1868 longString += earthAfrica;
1873 tcu::TestCaseGroup* createOpSourceGroup (tcu::TestContext& testCtx)
1875 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opsource", "Tests the OpSource & OpSourceContinued instruction"));
1876 vector<CaseParameter> cases;
1877 de::Random rnd (deStringHash(group->getName()));
1878 const int numElements = 100;
1879 vector<float> positiveFloats (numElements, 0);
1880 vector<float> negativeFloats (numElements, 0);
1881 const StringTemplate shaderTemplate (
1882 "OpCapability Shader\n"
1883 "OpMemoryModel Logical GLSL450\n"
1885 "OpEntryPoint GLCompute %main \"main\" %id\n"
1886 "OpExecutionMode %main LocalSize 1 1 1\n"
1890 "OpName %main \"main\"\n"
1891 "OpName %id \"gl_GlobalInvocationID\"\n"
1893 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1895 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) + string(s_InputOutputBuffer) +
1897 "%id = OpVariable %uvec3ptr Input\n"
1898 "%zero = OpConstant %i32 0\n"
1900 "%main = OpFunction %void None %voidf\n"
1901 "%label = OpLabel\n"
1902 "%idval = OpLoad %uvec3 %id\n"
1903 "%x = OpCompositeExtract %u32 %idval 0\n"
1904 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
1905 "%inval = OpLoad %f32 %inloc\n"
1906 "%neg = OpFNegate %f32 %inval\n"
1907 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
1908 " OpStore %outloc %neg\n"
1910 " OpFunctionEnd\n");
1912 cases.push_back(CaseParameter("unknown_source", "OpSource Unknown 0"));
1913 cases.push_back(CaseParameter("wrong_source", "OpSource OpenCL_C 210"));
1914 cases.push_back(CaseParameter("normal_filename", "%fname = OpString \"filename\"\n"
1915 "OpSource GLSL 430 %fname"));
1916 cases.push_back(CaseParameter("empty_filename", "%fname = OpString \"\"\n"
1917 "OpSource GLSL 430 %fname"));
1918 cases.push_back(CaseParameter("normal_source_code", "%fname = OpString \"filename\"\n"
1919 "OpSource GLSL 430 %fname \"#version 430\nvoid main() {}\""));
1920 cases.push_back(CaseParameter("empty_source_code", "%fname = OpString \"filename\"\n"
1921 "OpSource GLSL 430 %fname \"\""));
1922 cases.push_back(CaseParameter("long_source_code", "%fname = OpString \"filename\"\n"
1923 "OpSource GLSL 430 %fname \"" + makeLongUTF8String(65530) + "ccc\"")); // word count: 65535
1924 cases.push_back(CaseParameter("utf8_source_code", "%fname = OpString \"filename\"\n"
1925 "OpSource GLSL 430 %fname \"\xE2\x98\x82\xE2\x98\x85\"")); // umbrella & black star symbol
1926 cases.push_back(CaseParameter("normal_sourcecontinued", "%fname = OpString \"filename\"\n"
1927 "OpSource GLSL 430 %fname \"#version 430\nvo\"\n"
1928 "OpSourceContinued \"id main() {}\""));
1929 cases.push_back(CaseParameter("empty_sourcecontinued", "%fname = OpString \"filename\"\n"
1930 "OpSource GLSL 430 %fname \"#version 430\nvoid main() {}\"\n"
1931 "OpSourceContinued \"\""));
1932 cases.push_back(CaseParameter("long_sourcecontinued", "%fname = OpString \"filename\"\n"
1933 "OpSource GLSL 430 %fname \"#version 430\nvoid main() {}\"\n"
1934 "OpSourceContinued \"" + makeLongUTF8String(65533) + "ccc\"")); // word count: 65535
1935 cases.push_back(CaseParameter("utf8_sourcecontinued", "%fname = OpString \"filename\"\n"
1936 "OpSource GLSL 430 %fname \"#version 430\nvoid main() {}\"\n"
1937 "OpSourceContinued \"\xE2\x98\x8E\xE2\x9A\x91\"")); // white telephone & black flag symbol
1938 cases.push_back(CaseParameter("multi_sourcecontinued", "%fname = OpString \"filename\"\n"
1939 "OpSource GLSL 430 %fname \"#version 430\n\"\n"
1940 "OpSourceContinued \"void\"\n"
1941 "OpSourceContinued \"main()\"\n"
1942 "OpSourceContinued \"{}\""));
1943 cases.push_back(CaseParameter("empty_source_before_sourcecontinued", "%fname = OpString \"filename\"\n"
1944 "OpSource GLSL 430 %fname \"\"\n"
1945 "OpSourceContinued \"#version 430\nvoid main() {}\""));
1947 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
1949 for (size_t ndx = 0; ndx < numElements; ++ndx)
1950 negativeFloats[ndx] = -positiveFloats[ndx];
1952 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
1954 map<string, string> specializations;
1955 ComputeShaderSpec spec;
1957 specializations["SOURCE"] = cases[caseNdx].param;
1958 spec.assembly = shaderTemplate.specialize(specializations);
1959 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
1960 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
1961 spec.numWorkGroups = IVec3(numElements, 1, 1);
1963 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
1966 return group.release();
1969 tcu::TestCaseGroup* createOpSourceExtensionGroup (tcu::TestContext& testCtx)
1971 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opsourceextension", "Tests the OpSource instruction"));
1972 vector<CaseParameter> cases;
1973 de::Random rnd (deStringHash(group->getName()));
1974 const int numElements = 100;
1975 vector<float> inputFloats (numElements, 0);
1976 vector<float> outputFloats (numElements, 0);
1977 const StringTemplate shaderTemplate (
1978 string(s_ShaderPreamble) +
1980 "OpSourceExtension \"${EXTENSION}\"\n"
1982 "OpName %main \"main\"\n"
1983 "OpName %id \"gl_GlobalInvocationID\"\n"
1985 "OpDecorate %id BuiltIn GlobalInvocationId\n"
1987 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) + string(s_InputOutputBuffer) +
1989 "%id = OpVariable %uvec3ptr Input\n"
1990 "%zero = OpConstant %i32 0\n"
1992 "%main = OpFunction %void None %voidf\n"
1993 "%label = OpLabel\n"
1994 "%idval = OpLoad %uvec3 %id\n"
1995 "%x = OpCompositeExtract %u32 %idval 0\n"
1996 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
1997 "%inval = OpLoad %f32 %inloc\n"
1998 "%neg = OpFNegate %f32 %inval\n"
1999 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2000 " OpStore %outloc %neg\n"
2002 " OpFunctionEnd\n");
2004 cases.push_back(CaseParameter("empty_extension", ""));
2005 cases.push_back(CaseParameter("real_extension", "GL_ARB_texture_rectangle"));
2006 cases.push_back(CaseParameter("fake_extension", "GL_ARB_im_the_ultimate_extension"));
2007 cases.push_back(CaseParameter("utf8_extension", "GL_ARB_\xE2\x98\x82\xE2\x98\x85"));
2008 cases.push_back(CaseParameter("long_extension", makeLongUTF8String(65533) + "ccc")); // word count: 65535
2010 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats[0], numElements);
2012 for (size_t ndx = 0; ndx < numElements; ++ndx)
2013 outputFloats[ndx] = -inputFloats[ndx];
2015 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
2017 map<string, string> specializations;
2018 ComputeShaderSpec spec;
2020 specializations["EXTENSION"] = cases[caseNdx].param;
2021 spec.assembly = shaderTemplate.specialize(specializations);
2022 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
2023 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
2024 spec.numWorkGroups = IVec3(numElements, 1, 1);
2026 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
2029 return group.release();
2032 // Checks that a compute shader can generate a constant null value of various types, without exercising a computation on it.
2033 tcu::TestCaseGroup* createOpConstantNullGroup (tcu::TestContext& testCtx)
2035 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opconstantnull", "Tests the OpConstantNull instruction"));
2036 vector<CaseParameter> cases;
2037 de::Random rnd (deStringHash(group->getName()));
2038 const int numElements = 100;
2039 vector<float> positiveFloats (numElements, 0);
2040 vector<float> negativeFloats (numElements, 0);
2041 const StringTemplate shaderTemplate (
2042 string(s_ShaderPreamble) +
2044 "OpSource GLSL 430\n"
2045 "OpName %main \"main\"\n"
2046 "OpName %id \"gl_GlobalInvocationID\"\n"
2048 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2050 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) + string(s_InputOutputBuffer) +
2053 "%null = OpConstantNull %type\n"
2055 "%id = OpVariable %uvec3ptr Input\n"
2056 "%zero = OpConstant %i32 0\n"
2058 "%main = OpFunction %void None %voidf\n"
2059 "%label = OpLabel\n"
2060 "%idval = OpLoad %uvec3 %id\n"
2061 "%x = OpCompositeExtract %u32 %idval 0\n"
2062 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
2063 "%inval = OpLoad %f32 %inloc\n"
2064 "%neg = OpFNegate %f32 %inval\n"
2065 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2066 " OpStore %outloc %neg\n"
2068 " OpFunctionEnd\n");
2070 cases.push_back(CaseParameter("bool", "%type = OpTypeBool"));
2071 cases.push_back(CaseParameter("sint32", "%type = OpTypeInt 32 1"));
2072 cases.push_back(CaseParameter("uint32", "%type = OpTypeInt 32 0"));
2073 cases.push_back(CaseParameter("float32", "%type = OpTypeFloat 32"));
2074 cases.push_back(CaseParameter("vec4float32", "%type = OpTypeVector %f32 4"));
2075 cases.push_back(CaseParameter("vec3bool", "%type = OpTypeVector %bool 3"));
2076 cases.push_back(CaseParameter("vec2uint32", "%type = OpTypeVector %u32 2"));
2077 cases.push_back(CaseParameter("matrix", "%type = OpTypeMatrix %fvec3 3"));
2078 cases.push_back(CaseParameter("array", "%100 = OpConstant %u32 100\n"
2079 "%type = OpTypeArray %i32 %100"));
2080 cases.push_back(CaseParameter("struct", "%type = OpTypeStruct %f32 %i32 %u32"));
2081 cases.push_back(CaseParameter("pointer", "%type = OpTypePointer Function %i32"));
2083 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
2085 for (size_t ndx = 0; ndx < numElements; ++ndx)
2086 negativeFloats[ndx] = -positiveFloats[ndx];
2088 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
2090 map<string, string> specializations;
2091 ComputeShaderSpec spec;
2093 specializations["TYPE"] = cases[caseNdx].param;
2094 spec.assembly = shaderTemplate.specialize(specializations);
2095 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
2096 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
2097 spec.numWorkGroups = IVec3(numElements, 1, 1);
2099 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
2102 return group.release();
2105 // Checks that a compute shader can generate a constant composite value of various types, without exercising a computation on it.
2106 tcu::TestCaseGroup* createOpConstantCompositeGroup (tcu::TestContext& testCtx)
2108 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opconstantcomposite", "Tests the OpConstantComposite instruction"));
2109 vector<CaseParameter> cases;
2110 de::Random rnd (deStringHash(group->getName()));
2111 const int numElements = 100;
2112 vector<float> positiveFloats (numElements, 0);
2113 vector<float> negativeFloats (numElements, 0);
2114 const StringTemplate shaderTemplate (
2115 string(s_ShaderPreamble) +
2117 "OpSource GLSL 430\n"
2118 "OpName %main \"main\"\n"
2119 "OpName %id \"gl_GlobalInvocationID\"\n"
2121 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2123 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) + string(s_InputOutputBuffer) +
2125 "%id = OpVariable %uvec3ptr Input\n"
2126 "%zero = OpConstant %i32 0\n"
2130 "%main = OpFunction %void None %voidf\n"
2131 "%label = OpLabel\n"
2132 "%idval = OpLoad %uvec3 %id\n"
2133 "%x = OpCompositeExtract %u32 %idval 0\n"
2134 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
2135 "%inval = OpLoad %f32 %inloc\n"
2136 "%neg = OpFNegate %f32 %inval\n"
2137 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2138 " OpStore %outloc %neg\n"
2140 " OpFunctionEnd\n");
2142 cases.push_back(CaseParameter("vector", "%five = OpConstant %u32 5\n"
2143 "%const = OpConstantComposite %uvec3 %five %zero %five"));
2144 cases.push_back(CaseParameter("matrix", "%m3fvec3 = OpTypeMatrix %fvec3 3\n"
2145 "%ten = OpConstant %f32 10.\n"
2146 "%fzero = OpConstant %f32 0.\n"
2147 "%vec = OpConstantComposite %fvec3 %ten %fzero %ten\n"
2148 "%mat = OpConstantComposite %m3fvec3 %vec %vec %vec"));
2149 cases.push_back(CaseParameter("struct", "%m2vec3 = OpTypeMatrix %fvec3 2\n"
2150 "%struct = OpTypeStruct %i32 %f32 %fvec3 %m2vec3\n"
2151 "%fzero = OpConstant %f32 0.\n"
2152 "%one = OpConstant %f32 1.\n"
2153 "%point5 = OpConstant %f32 0.5\n"
2154 "%vec = OpConstantComposite %fvec3 %one %one %fzero\n"
2155 "%mat = OpConstantComposite %m2vec3 %vec %vec\n"
2156 "%const = OpConstantComposite %struct %zero %point5 %vec %mat"));
2157 cases.push_back(CaseParameter("nested_struct", "%st1 = OpTypeStruct %u32 %f32\n"
2158 "%st2 = OpTypeStruct %i32 %i32\n"
2159 "%struct = OpTypeStruct %st1 %st2\n"
2160 "%point5 = OpConstant %f32 0.5\n"
2161 "%one = OpConstant %u32 1\n"
2162 "%ten = OpConstant %i32 10\n"
2163 "%st1val = OpConstantComposite %st1 %one %point5\n"
2164 "%st2val = OpConstantComposite %st2 %ten %ten\n"
2165 "%const = OpConstantComposite %struct %st1val %st2val"));
2167 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
2169 for (size_t ndx = 0; ndx < numElements; ++ndx)
2170 negativeFloats[ndx] = -positiveFloats[ndx];
2172 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
2174 map<string, string> specializations;
2175 ComputeShaderSpec spec;
2177 specializations["CONSTANT"] = cases[caseNdx].param;
2178 spec.assembly = shaderTemplate.specialize(specializations);
2179 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
2180 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
2181 spec.numWorkGroups = IVec3(numElements, 1, 1);
2183 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
2186 return group.release();
2189 // Creates a floating point number with the given exponent, and significand
2190 // bits set. It can only create normalized numbers. Only the least significant
2191 // 24 bits of the significand will be examined. The final bit of the
2192 // significand will also be ignored. This allows alignment to be written
2193 // similarly to C99 hex-floats.
2194 // For example if you wanted to write 0x1.7f34p-12 you would call
2195 // constructNormalizedFloat(-12, 0x7f3400)
2196 float constructNormalizedFloat (deInt32 exponent, deUint32 significand)
2200 for (deInt32 idx = 0; idx < 23; ++idx)
2202 f += ((significand & 0x800000) == 0) ? 0.f : std::ldexp(1.0f, -(idx + 1));
2206 return std::ldexp(f, exponent);
2209 // Compare instruction for the OpQuantizeF16 compute exact case.
2210 // Returns true if the output is what is expected from the test case.
2211 bool compareOpQuantizeF16ComputeExactCase (const std::vector<BufferSp>&, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs)
2213 if (outputAllocs.size() != 1)
2216 // We really just need this for size because we cannot compare Nans.
2217 const BufferSp& expectedOutput = expectedOutputs[0];
2218 const float* outputAsFloat = static_cast<const float*>(outputAllocs[0]->getHostPtr());;
2220 if (expectedOutput->getNumBytes() != 4*sizeof(float)) {
2224 if (*outputAsFloat != constructNormalizedFloat(8, 0x304000) &&
2225 *outputAsFloat != constructNormalizedFloat(8, 0x300000)) {
2230 if (*outputAsFloat != -constructNormalizedFloat(-7, 0x600000) &&
2231 *outputAsFloat != -constructNormalizedFloat(-7, 0x604000)) {
2236 if (*outputAsFloat != constructNormalizedFloat(2, 0x01C000) &&
2237 *outputAsFloat != constructNormalizedFloat(2, 0x020000)) {
2242 if (*outputAsFloat != constructNormalizedFloat(1, 0xFFC000) &&
2243 *outputAsFloat != constructNormalizedFloat(2, 0x000000)) {
2250 // Checks that every output from a test-case is a float NaN.
2251 bool compareNan (const std::vector<BufferSp>&, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs)
2253 if (outputAllocs.size() != 1)
2256 // We really just need this for size because we cannot compare Nans.
2257 const BufferSp& expectedOutput = expectedOutputs[0];
2258 const float* output_as_float = static_cast<const float*>(outputAllocs[0]->getHostPtr());;
2260 for (size_t idx = 0; idx < expectedOutput->getNumBytes() / sizeof(float); ++idx)
2262 if (!isnan(output_as_float[idx]))
2271 // Checks that a compute shader can generate a constant composite value of various types, without exercising a computation on it.
2272 tcu::TestCaseGroup* createOpQuantizeToF16Group (tcu::TestContext& testCtx)
2274 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opquantize", "Tests the OpQuantizeToF16 instruction"));
2276 const std::string shader (
2277 string(s_ShaderPreamble) +
2279 "OpSource GLSL 430\n"
2280 "OpName %main \"main\"\n"
2281 "OpName %id \"gl_GlobalInvocationID\"\n"
2283 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2285 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) + string(s_InputOutputBuffer) +
2287 "%id = OpVariable %uvec3ptr Input\n"
2288 "%zero = OpConstant %i32 0\n"
2290 "%main = OpFunction %void None %voidf\n"
2291 "%label = OpLabel\n"
2292 "%idval = OpLoad %uvec3 %id\n"
2293 "%x = OpCompositeExtract %u32 %idval 0\n"
2294 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
2295 "%inval = OpLoad %f32 %inloc\n"
2296 "%quant = OpQuantizeToF16 %f32 %inval\n"
2297 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2298 " OpStore %outloc %quant\n"
2300 " OpFunctionEnd\n");
2303 ComputeShaderSpec spec;
2304 const deUint32 numElements = 100;
2305 vector<float> infinities;
2306 vector<float> results;
2308 infinities.reserve(numElements);
2309 results.reserve(numElements);
2311 for (size_t idx = 0; idx < numElements; ++idx)
2316 infinities.push_back(std::numeric_limits<float>::infinity());
2317 results.push_back(std::numeric_limits<float>::infinity());
2320 infinities.push_back(-std::numeric_limits<float>::infinity());
2321 results.push_back(-std::numeric_limits<float>::infinity());
2324 infinities.push_back(std::ldexp(1.0f, 16));
2325 results.push_back(std::numeric_limits<float>::infinity());
2328 infinities.push_back(std::ldexp(-1.0f, 32));
2329 results.push_back(-std::numeric_limits<float>::infinity());
2334 spec.assembly = shader;
2335 spec.inputs.push_back(BufferSp(new Float32Buffer(infinities)));
2336 spec.outputs.push_back(BufferSp(new Float32Buffer(results)));
2337 spec.numWorkGroups = IVec3(numElements, 1, 1);
2339 group->addChild(new SpvAsmComputeShaderCase(
2340 testCtx, "infinities", "Check that infinities propagated and created", spec));
2344 ComputeShaderSpec spec;
2346 const deUint32 numElements = 100;
2348 nans.reserve(numElements);
2350 for (size_t idx = 0; idx < numElements; ++idx)
2354 nans.push_back(std::numeric_limits<float>::quiet_NaN());
2358 nans.push_back(-std::numeric_limits<float>::quiet_NaN());
2362 spec.assembly = shader;
2363 spec.inputs.push_back(BufferSp(new Float32Buffer(nans)));
2364 spec.outputs.push_back(BufferSp(new Float32Buffer(nans)));
2365 spec.numWorkGroups = IVec3(numElements, 1, 1);
2366 spec.verifyIO = &compareNan;
2368 group->addChild(new SpvAsmComputeShaderCase(
2369 testCtx, "propagated_nans", "Check that nans are propagated", spec));
2373 ComputeShaderSpec spec;
2374 vector<float> small;
2375 vector<float> zeros;
2376 const deUint32 numElements = 100;
2378 small.reserve(numElements);
2379 zeros.reserve(numElements);
2381 for (size_t idx = 0; idx < numElements; ++idx)
2386 small.push_back(0.f);
2387 zeros.push_back(0.f);
2390 small.push_back(-0.f);
2391 zeros.push_back(-0.f);
2394 small.push_back(std::ldexp(1.0f, -16));
2395 zeros.push_back(0.f);
2398 small.push_back(std::ldexp(-1.0f, -32));
2399 zeros.push_back(-0.f);
2402 small.push_back(std::ldexp(1.0f, -127));
2403 zeros.push_back(0.f);
2406 small.push_back(-std::ldexp(1.0f, -128));
2407 zeros.push_back(-0.f);
2412 spec.assembly = shader;
2413 spec.inputs.push_back(BufferSp(new Float32Buffer(small)));
2414 spec.outputs.push_back(BufferSp(new Float32Buffer(zeros)));
2415 spec.numWorkGroups = IVec3(numElements, 1, 1);
2417 group->addChild(new SpvAsmComputeShaderCase(
2418 testCtx, "flush_to_zero", "Check that values are zeroed correctly", spec));
2422 ComputeShaderSpec spec;
2423 vector<float> exact;
2424 const deUint32 numElements = 200;
2426 exact.reserve(numElements);
2428 for (size_t idx = 0; idx < numElements; ++idx)
2429 exact.push_back(static_cast<float>(static_cast<int>(idx) - 100));
2431 spec.assembly = shader;
2432 spec.inputs.push_back(BufferSp(new Float32Buffer(exact)));
2433 spec.outputs.push_back(BufferSp(new Float32Buffer(exact)));
2434 spec.numWorkGroups = IVec3(numElements, 1, 1);
2436 group->addChild(new SpvAsmComputeShaderCase(
2437 testCtx, "exact", "Check that values exactly preserved where appropriate", spec));
2441 ComputeShaderSpec spec;
2442 vector<float> inputs;
2443 const deUint32 numElements = 4;
2445 inputs.push_back(constructNormalizedFloat(8, 0x300300));
2446 inputs.push_back(-constructNormalizedFloat(-7, 0x600800));
2447 inputs.push_back(constructNormalizedFloat(2, 0x01E000));
2448 inputs.push_back(constructNormalizedFloat(1, 0xFFE000));
2450 spec.assembly = shader;
2451 spec.verifyIO = &compareOpQuantizeF16ComputeExactCase;
2452 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs)));
2453 spec.outputs.push_back(BufferSp(new Float32Buffer(inputs)));
2454 spec.numWorkGroups = IVec3(numElements, 1, 1);
2456 group->addChild(new SpvAsmComputeShaderCase(
2457 testCtx, "rounded", "Check that are rounded when needed", spec));
2460 return group.release();
2463 // Performs a bitwise copy of source to the destination type Dest.
2464 template <typename Dest, typename Src>
2465 Dest bitwiseCast(Src source)
2468 DE_STATIC_ASSERT(sizeof(source) == sizeof(dest));
2469 deMemcpy(&dest, &source, sizeof(dest));
2473 tcu::TestCaseGroup* createSpecConstantOpQuantizeToF16Group (tcu::TestContext& testCtx)
2475 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opspecconstantop_opquantize", "Tests the OpQuantizeToF16 opcode for the OpSpecConstantOp instruction"));
2477 const std::string shader (
2478 string(s_ShaderPreamble) +
2480 "OpName %main \"main\"\n"
2481 "OpName %id \"gl_GlobalInvocationID\"\n"
2483 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2485 "OpDecorate %sc_0 SpecId 0\n"
2486 "OpDecorate %sc_1 SpecId 1\n"
2487 "OpDecorate %sc_2 SpecId 2\n"
2488 "OpDecorate %sc_3 SpecId 3\n"
2489 "OpDecorate %sc_4 SpecId 4\n"
2490 "OpDecorate %sc_5 SpecId 5\n"
2492 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) + string(s_InputOutputBuffer) +
2494 "%id = OpVariable %uvec3ptr Input\n"
2495 "%zero = OpConstant %i32 0\n"
2496 "%c_u32_6 = OpConstant %u32 6\n"
2498 "%sc_0 = OpSpecConstant %f32 0.\n"
2499 "%sc_1 = OpSpecConstant %f32 0.\n"
2500 "%sc_2 = OpSpecConstant %f32 0.\n"
2501 "%sc_3 = OpSpecConstant %f32 0.\n"
2502 "%sc_4 = OpSpecConstant %f32 0.\n"
2503 "%sc_5 = OpSpecConstant %f32 0.\n"
2505 "%sc_0_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_0\n"
2506 "%sc_1_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_1\n"
2507 "%sc_2_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_2\n"
2508 "%sc_3_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_3\n"
2509 "%sc_4_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_4\n"
2510 "%sc_5_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_5\n"
2512 "%main = OpFunction %void None %voidf\n"
2513 "%label = OpLabel\n"
2514 "%idval = OpLoad %uvec3 %id\n"
2515 "%x = OpCompositeExtract %u32 %idval 0\n"
2516 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2517 "%selector = OpUMod %u32 %x %c_u32_6\n"
2518 " OpSelectionMerge %exit None\n"
2519 " OpSwitch %selector %exit 0 %case0 1 %case1 2 %case2 3 %case3 4 %case4 5 %case5\n"
2521 "%case0 = OpLabel\n"
2522 " OpStore %outloc %sc_0_quant\n"
2525 "%case1 = OpLabel\n"
2526 " OpStore %outloc %sc_1_quant\n"
2529 "%case2 = OpLabel\n"
2530 " OpStore %outloc %sc_2_quant\n"
2533 "%case3 = OpLabel\n"
2534 " OpStore %outloc %sc_3_quant\n"
2537 "%case4 = OpLabel\n"
2538 " OpStore %outloc %sc_4_quant\n"
2541 "%case5 = OpLabel\n"
2542 " OpStore %outloc %sc_5_quant\n"
2548 " OpFunctionEnd\n");
2551 ComputeShaderSpec spec;
2552 const deUint8 numCases = 4;
2553 vector<float> inputs (numCases, 0.f);
2554 vector<float> outputs;
2556 spec.assembly = shader;
2557 spec.numWorkGroups = IVec3(numCases, 1, 1);
2559 spec.specConstants.push_back(bitwiseCast<deUint32>(std::numeric_limits<float>::infinity()));
2560 spec.specConstants.push_back(bitwiseCast<deUint32>(-std::numeric_limits<float>::infinity()));
2561 spec.specConstants.push_back(bitwiseCast<deUint32>(std::ldexp(1.0f, 16)));
2562 spec.specConstants.push_back(bitwiseCast<deUint32>(std::ldexp(-1.0f, 32)));
2564 outputs.push_back(std::numeric_limits<float>::infinity());
2565 outputs.push_back(-std::numeric_limits<float>::infinity());
2566 outputs.push_back(std::numeric_limits<float>::infinity());
2567 outputs.push_back(-std::numeric_limits<float>::infinity());
2569 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs)));
2570 spec.outputs.push_back(BufferSp(new Float32Buffer(outputs)));
2572 group->addChild(new SpvAsmComputeShaderCase(
2573 testCtx, "infinities", "Check that infinities propagated and created", spec));
2577 ComputeShaderSpec spec;
2578 const deUint8 numCases = 2;
2579 vector<float> inputs (numCases, 0.f);
2580 vector<float> outputs;
2582 spec.assembly = shader;
2583 spec.numWorkGroups = IVec3(numCases, 1, 1);
2584 spec.verifyIO = &compareNan;
2586 outputs.push_back(std::numeric_limits<float>::quiet_NaN());
2587 outputs.push_back(-std::numeric_limits<float>::quiet_NaN());
2589 for (deUint8 idx = 0; idx < numCases; ++idx)
2590 spec.specConstants.push_back(bitwiseCast<deUint32>(outputs[idx]));
2592 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs)));
2593 spec.outputs.push_back(BufferSp(new Float32Buffer(outputs)));
2595 group->addChild(new SpvAsmComputeShaderCase(
2596 testCtx, "propagated_nans", "Check that nans are propagated", spec));
2600 ComputeShaderSpec spec;
2601 const deUint8 numCases = 6;
2602 vector<float> inputs (numCases, 0.f);
2603 vector<float> outputs;
2605 spec.assembly = shader;
2606 spec.numWorkGroups = IVec3(numCases, 1, 1);
2608 spec.specConstants.push_back(bitwiseCast<deUint32>(0.f));
2609 spec.specConstants.push_back(bitwiseCast<deUint32>(-0.f));
2610 spec.specConstants.push_back(bitwiseCast<deUint32>(std::ldexp(1.0f, -16)));
2611 spec.specConstants.push_back(bitwiseCast<deUint32>(std::ldexp(-1.0f, -32)));
2612 spec.specConstants.push_back(bitwiseCast<deUint32>(std::ldexp(1.0f, -127)));
2613 spec.specConstants.push_back(bitwiseCast<deUint32>(-std::ldexp(1.0f, -128)));
2615 outputs.push_back(0.f);
2616 outputs.push_back(-0.f);
2617 outputs.push_back(0.f);
2618 outputs.push_back(-0.f);
2619 outputs.push_back(0.f);
2620 outputs.push_back(-0.f);
2622 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs)));
2623 spec.outputs.push_back(BufferSp(new Float32Buffer(outputs)));
2625 group->addChild(new SpvAsmComputeShaderCase(
2626 testCtx, "flush_to_zero", "Check that values are zeroed correctly", spec));
2630 ComputeShaderSpec spec;
2631 const deUint8 numCases = 6;
2632 vector<float> inputs (numCases, 0.f);
2633 vector<float> outputs;
2635 spec.assembly = shader;
2636 spec.numWorkGroups = IVec3(numCases, 1, 1);
2638 for (deUint8 idx = 0; idx < 6; ++idx)
2640 const float f = static_cast<float>(idx * 10 - 30) / 4.f;
2641 spec.specConstants.push_back(bitwiseCast<deUint32>(f));
2642 outputs.push_back(f);
2645 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs)));
2646 spec.outputs.push_back(BufferSp(new Float32Buffer(outputs)));
2648 group->addChild(new SpvAsmComputeShaderCase(
2649 testCtx, "exact", "Check that values exactly preserved where appropriate", spec));
2653 ComputeShaderSpec spec;
2654 const deUint8 numCases = 4;
2655 vector<float> inputs (numCases, 0.f);
2656 vector<float> outputs;
2658 spec.assembly = shader;
2659 spec.numWorkGroups = IVec3(numCases, 1, 1);
2660 spec.verifyIO = &compareOpQuantizeF16ComputeExactCase;
2662 outputs.push_back(constructNormalizedFloat(8, 0x300300));
2663 outputs.push_back(-constructNormalizedFloat(-7, 0x600800));
2664 outputs.push_back(constructNormalizedFloat(2, 0x01E000));
2665 outputs.push_back(constructNormalizedFloat(1, 0xFFE000));
2667 for (deUint8 idx = 0; idx < numCases; ++idx)
2668 spec.specConstants.push_back(bitwiseCast<deUint32>(outputs[idx]));
2670 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs)));
2671 spec.outputs.push_back(BufferSp(new Float32Buffer(outputs)));
2673 group->addChild(new SpvAsmComputeShaderCase(
2674 testCtx, "rounded", "Check that are rounded when needed", spec));
2677 return group.release();
2680 // Checks that constant null/composite values can be used in computation.
2681 tcu::TestCaseGroup* createOpConstantUsageGroup (tcu::TestContext& testCtx)
2683 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opconstantnullcomposite", "Spotcheck the OpConstantNull & OpConstantComposite instruction"));
2684 ComputeShaderSpec spec;
2685 de::Random rnd (deStringHash(group->getName()));
2686 const int numElements = 100;
2687 vector<float> positiveFloats (numElements, 0);
2688 vector<float> negativeFloats (numElements, 0);
2690 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
2692 for (size_t ndx = 0; ndx < numElements; ++ndx)
2693 negativeFloats[ndx] = -positiveFloats[ndx];
2696 "OpCapability Shader\n"
2697 "%std450 = OpExtInstImport \"GLSL.std.450\"\n"
2698 "OpMemoryModel Logical GLSL450\n"
2699 "OpEntryPoint GLCompute %main \"main\" %id\n"
2700 "OpExecutionMode %main LocalSize 1 1 1\n"
2702 "OpSource GLSL 430\n"
2703 "OpName %main \"main\"\n"
2704 "OpName %id \"gl_GlobalInvocationID\"\n"
2706 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2708 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) +
2710 "%fmat = OpTypeMatrix %fvec3 3\n"
2711 "%ten = OpConstant %u32 10\n"
2712 "%f32arr10 = OpTypeArray %f32 %ten\n"
2713 "%fst = OpTypeStruct %f32 %f32\n"
2715 + string(s_InputOutputBuffer) +
2717 "%id = OpVariable %uvec3ptr Input\n"
2718 "%zero = OpConstant %i32 0\n"
2720 // Create a bunch of null values
2721 "%unull = OpConstantNull %u32\n"
2722 "%fnull = OpConstantNull %f32\n"
2723 "%vnull = OpConstantNull %fvec3\n"
2724 "%mnull = OpConstantNull %fmat\n"
2725 "%anull = OpConstantNull %f32arr10\n"
2726 "%snull = OpConstantComposite %fst %fnull %fnull\n"
2728 "%main = OpFunction %void None %voidf\n"
2729 "%label = OpLabel\n"
2730 "%idval = OpLoad %uvec3 %id\n"
2731 "%x = OpCompositeExtract %u32 %idval 0\n"
2732 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
2733 "%inval = OpLoad %f32 %inloc\n"
2734 "%neg = OpFNegate %f32 %inval\n"
2736 // Get the abs() of (a certain element of) those null values
2737 "%unull_cov = OpConvertUToF %f32 %unull\n"
2738 "%unull_abs = OpExtInst %f32 %std450 FAbs %unull_cov\n"
2739 "%fnull_abs = OpExtInst %f32 %std450 FAbs %fnull\n"
2740 "%vnull_0 = OpCompositeExtract %f32 %vnull 0\n"
2741 "%vnull_abs = OpExtInst %f32 %std450 FAbs %vnull_0\n"
2742 "%mnull_12 = OpCompositeExtract %f32 %mnull 1 2\n"
2743 "%mnull_abs = OpExtInst %f32 %std450 FAbs %mnull_12\n"
2744 "%anull_3 = OpCompositeExtract %f32 %anull 3\n"
2745 "%anull_abs = OpExtInst %f32 %std450 FAbs %anull_3\n"
2746 "%snull_1 = OpCompositeExtract %f32 %snull 1\n"
2747 "%snull_abs = OpExtInst %f32 %std450 FAbs %snull_1\n"
2750 "%add1 = OpFAdd %f32 %neg %unull_abs\n"
2751 "%add2 = OpFAdd %f32 %add1 %fnull_abs\n"
2752 "%add3 = OpFAdd %f32 %add2 %vnull_abs\n"
2753 "%add4 = OpFAdd %f32 %add3 %mnull_abs\n"
2754 "%add5 = OpFAdd %f32 %add4 %anull_abs\n"
2755 "%final = OpFAdd %f32 %add5 %snull_abs\n"
2757 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2758 " OpStore %outloc %final\n" // write to output
2761 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
2762 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
2763 spec.numWorkGroups = IVec3(numElements, 1, 1);
2765 group->addChild(new SpvAsmComputeShaderCase(testCtx, "spotcheck", "Check that values constructed via OpConstantNull & OpConstantComposite can be used", spec));
2767 return group.release();
2770 // Assembly code used for testing loop control is based on GLSL source code:
2773 // layout(std140, set = 0, binding = 0) readonly buffer Input {
2774 // float elements[];
2776 // layout(std140, set = 0, binding = 1) writeonly buffer Output {
2777 // float elements[];
2781 // uint x = gl_GlobalInvocationID.x;
2782 // output_data.elements[x] = input_data.elements[x];
2783 // for (uint i = 0; i < 4; ++i)
2784 // output_data.elements[x] += 1.f;
2786 tcu::TestCaseGroup* createLoopControlGroup (tcu::TestContext& testCtx)
2788 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "loop_control", "Tests loop control cases"));
2789 vector<CaseParameter> cases;
2790 de::Random rnd (deStringHash(group->getName()));
2791 const int numElements = 100;
2792 vector<float> inputFloats (numElements, 0);
2793 vector<float> outputFloats (numElements, 0);
2794 const StringTemplate shaderTemplate (
2795 string(s_ShaderPreamble) +
2797 "OpSource GLSL 430\n"
2798 "OpName %main \"main\"\n"
2799 "OpName %id \"gl_GlobalInvocationID\"\n"
2801 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2803 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) + string(s_InputOutputBuffer) +
2805 "%u32ptr = OpTypePointer Function %u32\n"
2807 "%id = OpVariable %uvec3ptr Input\n"
2808 "%zero = OpConstant %i32 0\n"
2809 "%uzero = OpConstant %u32 0\n"
2810 "%one = OpConstant %i32 1\n"
2811 "%constf1 = OpConstant %f32 1.0\n"
2812 "%four = OpConstant %u32 4\n"
2814 "%main = OpFunction %void None %voidf\n"
2815 "%entry = OpLabel\n"
2816 "%i = OpVariable %u32ptr Function\n"
2817 " OpStore %i %uzero\n"
2819 "%idval = OpLoad %uvec3 %id\n"
2820 "%x = OpCompositeExtract %u32 %idval 0\n"
2821 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
2822 "%inval = OpLoad %f32 %inloc\n"
2823 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2824 " OpStore %outloc %inval\n"
2825 " OpBranch %loop_entry\n"
2827 "%loop_entry = OpLabel\n"
2828 "%i_val = OpLoad %u32 %i\n"
2829 "%cmp_lt = OpULessThan %bool %i_val %four\n"
2830 " OpLoopMerge %loop_merge %loop_entry ${CONTROL}\n"
2831 " OpBranchConditional %cmp_lt %loop_body %loop_merge\n"
2832 "%loop_body = OpLabel\n"
2833 "%outval = OpLoad %f32 %outloc\n"
2834 "%addf1 = OpFAdd %f32 %outval %constf1\n"
2835 " OpStore %outloc %addf1\n"
2836 "%new_i = OpIAdd %u32 %i_val %one\n"
2837 " OpStore %i %new_i\n"
2838 " OpBranch %loop_entry\n"
2839 "%loop_merge = OpLabel\n"
2841 " OpFunctionEnd\n");
2843 cases.push_back(CaseParameter("none", "None"));
2844 cases.push_back(CaseParameter("unroll", "Unroll"));
2845 cases.push_back(CaseParameter("dont_unroll", "DontUnroll"));
2846 cases.push_back(CaseParameter("unroll_dont_unroll", "Unroll|DontUnroll"));
2848 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats[0], numElements);
2850 for (size_t ndx = 0; ndx < numElements; ++ndx)
2851 outputFloats[ndx] = inputFloats[ndx] + 4.f;
2853 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
2855 map<string, string> specializations;
2856 ComputeShaderSpec spec;
2858 specializations["CONTROL"] = cases[caseNdx].param;
2859 spec.assembly = shaderTemplate.specialize(specializations);
2860 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
2861 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
2862 spec.numWorkGroups = IVec3(numElements, 1, 1);
2864 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
2867 return group.release();
2870 // Assembly code used for testing selection control is based on GLSL source code:
2873 // layout(std140, set = 0, binding = 0) readonly buffer Input {
2874 // float elements[];
2876 // layout(std140, set = 0, binding = 1) writeonly buffer Output {
2877 // float elements[];
2881 // uint x = gl_GlobalInvocationID.x;
2882 // float val = input_data.elements[x];
2884 // output_data.elements[x] = val + 1.f;
2886 // output_data.elements[x] = val - 1.f;
2888 tcu::TestCaseGroup* createSelectionControlGroup (tcu::TestContext& testCtx)
2890 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "selection_control", "Tests selection control cases"));
2891 vector<CaseParameter> cases;
2892 de::Random rnd (deStringHash(group->getName()));
2893 const int numElements = 100;
2894 vector<float> inputFloats (numElements, 0);
2895 vector<float> outputFloats (numElements, 0);
2896 const StringTemplate shaderTemplate (
2897 string(s_ShaderPreamble) +
2899 "OpSource GLSL 430\n"
2900 "OpName %main \"main\"\n"
2901 "OpName %id \"gl_GlobalInvocationID\"\n"
2903 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2905 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) + string(s_InputOutputBuffer) +
2907 "%id = OpVariable %uvec3ptr Input\n"
2908 "%zero = OpConstant %i32 0\n"
2909 "%constf1 = OpConstant %f32 1.0\n"
2910 "%constf10 = OpConstant %f32 10.0\n"
2912 "%main = OpFunction %void None %voidf\n"
2913 "%entry = OpLabel\n"
2914 "%idval = OpLoad %uvec3 %id\n"
2915 "%x = OpCompositeExtract %u32 %idval 0\n"
2916 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
2917 "%inval = OpLoad %f32 %inloc\n"
2918 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
2919 "%cmp_gt = OpFOrdGreaterThan %bool %inval %constf10\n"
2921 " OpSelectionMerge %if_end ${CONTROL}\n"
2922 " OpBranchConditional %cmp_gt %if_true %if_false\n"
2923 "%if_true = OpLabel\n"
2924 "%addf1 = OpFAdd %f32 %inval %constf1\n"
2925 " OpStore %outloc %addf1\n"
2926 " OpBranch %if_end\n"
2927 "%if_false = OpLabel\n"
2928 "%subf1 = OpFSub %f32 %inval %constf1\n"
2929 " OpStore %outloc %subf1\n"
2930 " OpBranch %if_end\n"
2931 "%if_end = OpLabel\n"
2933 " OpFunctionEnd\n");
2935 cases.push_back(CaseParameter("none", "None"));
2936 cases.push_back(CaseParameter("flatten", "Flatten"));
2937 cases.push_back(CaseParameter("dont_flatten", "DontFlatten"));
2938 cases.push_back(CaseParameter("flatten_dont_flatten", "DontFlatten|Flatten"));
2940 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats[0], numElements);
2942 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
2943 floorAll(inputFloats);
2945 for (size_t ndx = 0; ndx < numElements; ++ndx)
2946 outputFloats[ndx] = inputFloats[ndx] + (inputFloats[ndx] > 10.f ? 1.f : -1.f);
2948 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
2950 map<string, string> specializations;
2951 ComputeShaderSpec spec;
2953 specializations["CONTROL"] = cases[caseNdx].param;
2954 spec.assembly = shaderTemplate.specialize(specializations);
2955 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
2956 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
2957 spec.numWorkGroups = IVec3(numElements, 1, 1);
2959 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
2962 return group.release();
2965 // Assembly code used for testing function control is based on GLSL source code:
2969 // layout(std140, set = 0, binding = 0) readonly buffer Input {
2970 // float elements[];
2972 // layout(std140, set = 0, binding = 1) writeonly buffer Output {
2973 // float elements[];
2976 // float const10() { return 10.f; }
2979 // uint x = gl_GlobalInvocationID.x;
2980 // output_data.elements[x] = input_data.elements[x] + const10();
2982 tcu::TestCaseGroup* createFunctionControlGroup (tcu::TestContext& testCtx)
2984 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "function_control", "Tests function control cases"));
2985 vector<CaseParameter> cases;
2986 de::Random rnd (deStringHash(group->getName()));
2987 const int numElements = 100;
2988 vector<float> inputFloats (numElements, 0);
2989 vector<float> outputFloats (numElements, 0);
2990 const StringTemplate shaderTemplate (
2991 string(s_ShaderPreamble) +
2993 "OpSource GLSL 430\n"
2994 "OpName %main \"main\"\n"
2995 "OpName %func_const10 \"const10(\"\n"
2996 "OpName %id \"gl_GlobalInvocationID\"\n"
2998 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3000 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) + string(s_InputOutputBuffer) +
3002 "%f32f = OpTypeFunction %f32\n"
3003 "%id = OpVariable %uvec3ptr Input\n"
3004 "%zero = OpConstant %i32 0\n"
3005 "%constf10 = OpConstant %f32 10.0\n"
3007 "%main = OpFunction %void None %voidf\n"
3008 "%entry = OpLabel\n"
3009 "%idval = OpLoad %uvec3 %id\n"
3010 "%x = OpCompositeExtract %u32 %idval 0\n"
3011 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3012 "%inval = OpLoad %f32 %inloc\n"
3013 "%ret_10 = OpFunctionCall %f32 %func_const10\n"
3014 "%fadd = OpFAdd %f32 %inval %ret_10\n"
3015 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3016 " OpStore %outloc %fadd\n"
3020 "%func_const10 = OpFunction %f32 ${CONTROL} %f32f\n"
3021 "%label = OpLabel\n"
3022 " OpReturnValue %constf10\n"
3023 " OpFunctionEnd\n");
3025 cases.push_back(CaseParameter("none", "None"));
3026 cases.push_back(CaseParameter("inline", "Inline"));
3027 cases.push_back(CaseParameter("dont_inline", "DontInline"));
3028 cases.push_back(CaseParameter("pure", "Pure"));
3029 cases.push_back(CaseParameter("const", "Const"));
3030 cases.push_back(CaseParameter("inline_pure", "Inline|Pure"));
3031 cases.push_back(CaseParameter("const_dont_inline", "Const|DontInline"));
3032 cases.push_back(CaseParameter("inline_dont_inline", "Inline|DontInline"));
3033 cases.push_back(CaseParameter("pure_inline_dont_inline", "Pure|Inline|DontInline"));
3035 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats[0], numElements);
3037 // CPU might not use the same rounding mode as the GPU. Use whole numbers to avoid rounding differences.
3038 floorAll(inputFloats);
3040 for (size_t ndx = 0; ndx < numElements; ++ndx)
3041 outputFloats[ndx] = inputFloats[ndx] + 10.f;
3043 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
3045 map<string, string> specializations;
3046 ComputeShaderSpec spec;
3048 specializations["CONTROL"] = cases[caseNdx].param;
3049 spec.assembly = shaderTemplate.specialize(specializations);
3050 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
3051 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
3052 spec.numWorkGroups = IVec3(numElements, 1, 1);
3054 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
3057 return group.release();
3060 tcu::TestCaseGroup* createMemoryAccessGroup (tcu::TestContext& testCtx)
3062 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "memory_access", "Tests memory access cases"));
3063 vector<CaseParameter> cases;
3064 de::Random rnd (deStringHash(group->getName()));
3065 const int numElements = 100;
3066 vector<float> inputFloats (numElements, 0);
3067 vector<float> outputFloats (numElements, 0);
3068 const StringTemplate shaderTemplate (
3069 string(s_ShaderPreamble) +
3071 "OpSource GLSL 430\n"
3072 "OpName %main \"main\"\n"
3073 "OpName %id \"gl_GlobalInvocationID\"\n"
3075 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3077 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) + string(s_InputOutputBuffer) +
3079 "%f32ptr_f = OpTypePointer Function %f32\n"
3081 "%id = OpVariable %uvec3ptr Input\n"
3082 "%zero = OpConstant %i32 0\n"
3083 "%four = OpConstant %i32 4\n"
3085 "%main = OpFunction %void None %voidf\n"
3086 "%label = OpLabel\n"
3087 "%copy = OpVariable %f32ptr_f Function\n"
3088 "%idval = OpLoad %uvec3 %id ${ACCESS}\n"
3089 "%x = OpCompositeExtract %u32 %idval 0\n"
3090 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3091 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3092 " OpCopyMemory %copy %inloc ${ACCESS}\n"
3093 "%val1 = OpLoad %f32 %copy\n"
3094 "%val2 = OpLoad %f32 %inloc\n"
3095 "%add = OpFAdd %f32 %val1 %val2\n"
3096 " OpStore %outloc %add ${ACCESS}\n"
3098 " OpFunctionEnd\n");
3100 cases.push_back(CaseParameter("null", ""));
3101 cases.push_back(CaseParameter("none", "None"));
3102 cases.push_back(CaseParameter("volatile", "Volatile"));
3103 cases.push_back(CaseParameter("aligned", "Aligned 4"));
3104 cases.push_back(CaseParameter("nontemporal", "Nontemporal"));
3105 cases.push_back(CaseParameter("aligned_nontemporal", "Aligned|Nontemporal 4"));
3106 cases.push_back(CaseParameter("aligned_volatile", "Volatile|Aligned 4"));
3108 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats[0], numElements);
3110 for (size_t ndx = 0; ndx < numElements; ++ndx)
3111 outputFloats[ndx] = inputFloats[ndx] + inputFloats[ndx];
3113 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
3115 map<string, string> specializations;
3116 ComputeShaderSpec spec;
3118 specializations["ACCESS"] = cases[caseNdx].param;
3119 spec.assembly = shaderTemplate.specialize(specializations);
3120 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats)));
3121 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats)));
3122 spec.numWorkGroups = IVec3(numElements, 1, 1);
3124 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
3127 return group.release();
3130 // Checks that we can get undefined values for various types, without exercising a computation with it.
3131 tcu::TestCaseGroup* createOpUndefGroup (tcu::TestContext& testCtx)
3133 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opundef", "Tests the OpUndef instruction"));
3134 vector<CaseParameter> cases;
3135 de::Random rnd (deStringHash(group->getName()));
3136 const int numElements = 100;
3137 vector<float> positiveFloats (numElements, 0);
3138 vector<float> negativeFloats (numElements, 0);
3139 const StringTemplate shaderTemplate (
3140 string(s_ShaderPreamble) +
3142 "OpSource GLSL 430\n"
3143 "OpName %main \"main\"\n"
3144 "OpName %id \"gl_GlobalInvocationID\"\n"
3146 "OpDecorate %id BuiltIn GlobalInvocationId\n"
3148 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) + string(s_InputOutputBuffer) +
3152 "%id = OpVariable %uvec3ptr Input\n"
3153 "%zero = OpConstant %i32 0\n"
3155 "%main = OpFunction %void None %voidf\n"
3156 "%label = OpLabel\n"
3158 "%undef = OpUndef %type\n"
3160 "%idval = OpLoad %uvec3 %id\n"
3161 "%x = OpCompositeExtract %u32 %idval 0\n"
3163 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n"
3164 "%inval = OpLoad %f32 %inloc\n"
3165 "%neg = OpFNegate %f32 %inval\n"
3166 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n"
3167 " OpStore %outloc %neg\n"
3169 " OpFunctionEnd\n");
3171 cases.push_back(CaseParameter("bool", "%type = OpTypeBool"));
3172 cases.push_back(CaseParameter("sint32", "%type = OpTypeInt 32 1"));
3173 cases.push_back(CaseParameter("uint32", "%type = OpTypeInt 32 0"));
3174 cases.push_back(CaseParameter("float32", "%type = OpTypeFloat 32"));
3175 cases.push_back(CaseParameter("vec4float32", "%type = OpTypeVector %f32 4"));
3176 cases.push_back(CaseParameter("vec2uint32", "%type = OpTypeVector %u32 2"));
3177 cases.push_back(CaseParameter("matrix", "%type = OpTypeMatrix %fvec3 3"));
3178 cases.push_back(CaseParameter("image", "%type = OpTypeImage %f32 2D 0 0 0 1 Unknown"));
3179 cases.push_back(CaseParameter("sampler", "%type = OpTypeSampler"));
3180 cases.push_back(CaseParameter("sampledimage", "%img = OpTypeImage %f32 2D 0 0 0 1 Unknown\n"
3181 "%type = OpTypeSampledImage %img"));
3182 cases.push_back(CaseParameter("array", "%100 = OpConstant %u32 100\n"
3183 "%type = OpTypeArray %i32 %100"));
3184 cases.push_back(CaseParameter("runtimearray", "%type = OpTypeRuntimeArray %f32"));
3185 cases.push_back(CaseParameter("struct", "%type = OpTypeStruct %f32 %i32 %u32"));
3186 cases.push_back(CaseParameter("pointer", "%type = OpTypePointer Function %i32"));
3188 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements);
3190 for (size_t ndx = 0; ndx < numElements; ++ndx)
3191 negativeFloats[ndx] = -positiveFloats[ndx];
3193 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
3195 map<string, string> specializations;
3196 ComputeShaderSpec spec;
3198 specializations["TYPE"] = cases[caseNdx].param;
3199 spec.assembly = shaderTemplate.specialize(specializations);
3200 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats)));
3201 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats)));
3202 spec.numWorkGroups = IVec3(numElements, 1, 1);
3204 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec));
3207 return group.release();
3209 typedef std::pair<std::string, VkShaderStageFlagBits> EntryToStage;
3210 typedef map<string, vector<EntryToStage> > ModuleMap;
3211 typedef map<VkShaderStageFlagBits, vector<deInt32> > StageToSpecConstantMap;
3213 // Context for a specific test instantiation. For example, an instantiation
3214 // may test colors yellow/magenta/cyan/mauve in a tesselation shader
3215 // with an entry point named 'main_to_the_main'
3216 struct InstanceContext
3218 // Map of modules to what entry_points we care to use from those modules.
3219 ModuleMap moduleMap;
3220 RGBA inputColors[4];
3221 RGBA outputColors[4];
3222 // Concrete SPIR-V code to test via boilerplate specialization.
3223 map<string, string> testCodeFragments;
3224 StageToSpecConstantMap specConstants;
3225 bool hasTessellation;
3226 VkShaderStageFlagBits requiredStages;
3228 InstanceContext (const RGBA (&inputs)[4], const RGBA (&outputs)[4], const map<string, string>& testCodeFragments_, const StageToSpecConstantMap& specConstants_)
3229 : testCodeFragments (testCodeFragments_)
3230 , specConstants (specConstants_)
3231 , hasTessellation (false)
3232 , requiredStages (static_cast<VkShaderStageFlagBits>(0))
3234 inputColors[0] = inputs[0];
3235 inputColors[1] = inputs[1];
3236 inputColors[2] = inputs[2];
3237 inputColors[3] = inputs[3];
3239 outputColors[0] = outputs[0];
3240 outputColors[1] = outputs[1];
3241 outputColors[2] = outputs[2];
3242 outputColors[3] = outputs[3];
3245 InstanceContext (const InstanceContext& other)
3246 : moduleMap (other.moduleMap)
3247 , testCodeFragments (other.testCodeFragments)
3248 , specConstants (other.specConstants)
3249 , hasTessellation (other.hasTessellation)
3250 , requiredStages (other.requiredStages)
3252 inputColors[0] = other.inputColors[0];
3253 inputColors[1] = other.inputColors[1];
3254 inputColors[2] = other.inputColors[2];
3255 inputColors[3] = other.inputColors[3];
3257 outputColors[0] = other.outputColors[0];
3258 outputColors[1] = other.outputColors[1];
3259 outputColors[2] = other.outputColors[2];
3260 outputColors[3] = other.outputColors[3];
3264 // A description of a shader to be used for a single stage of the graphics pipeline.
3265 struct ShaderElement
3267 // The module that contains this shader entrypoint.
3270 // The name of the entrypoint.
3273 // Which shader stage this entry point represents.
3274 VkShaderStageFlagBits stage;
3276 ShaderElement (const string& moduleName_, const string& entryPoint_, VkShaderStageFlagBits shaderStage_)
3277 : moduleName(moduleName_)
3278 , entryName(entryPoint_)
3279 , stage(shaderStage_)
3284 void getDefaultColors (RGBA (&colors)[4])
3286 colors[0] = RGBA::white();
3287 colors[1] = RGBA::red();
3288 colors[2] = RGBA::green();
3289 colors[3] = RGBA::blue();
3292 void getHalfColorsFullAlpha (RGBA (&colors)[4])
3294 colors[0] = RGBA(127, 127, 127, 255);
3295 colors[1] = RGBA(127, 0, 0, 255);
3296 colors[2] = RGBA(0, 127, 0, 255);
3297 colors[3] = RGBA(0, 0, 127, 255);
3300 void getInvertedDefaultColors (RGBA (&colors)[4])
3302 colors[0] = RGBA(0, 0, 0, 255);
3303 colors[1] = RGBA(0, 255, 255, 255);
3304 colors[2] = RGBA(255, 0, 255, 255);
3305 colors[3] = RGBA(255, 255, 0, 255);
3308 // Turns a statically sized array of ShaderElements into an instance-context
3309 // by setting up the mapping of modules to their contained shaders and stages.
3310 // The inputs and expected outputs are given by inputColors and outputColors
3312 InstanceContext createInstanceContext (const ShaderElement (&elements)[N], const RGBA (&inputColors)[4], const RGBA (&outputColors)[4], const map<string, string>& testCodeFragments, const StageToSpecConstantMap& specConstants)
3314 InstanceContext ctx (inputColors, outputColors, testCodeFragments, specConstants);
3315 for (size_t i = 0; i < N; ++i)
3317 ctx.moduleMap[elements[i].moduleName].push_back(std::make_pair(elements[i].entryName, elements[i].stage));
3318 ctx.requiredStages = static_cast<VkShaderStageFlagBits>(ctx.requiredStages | elements[i].stage);
3324 inline InstanceContext createInstanceContext (const ShaderElement (&elements)[N], RGBA (&inputColors)[4], const RGBA (&outputColors)[4], const map<string, string>& testCodeFragments)
3326 return createInstanceContext(elements, inputColors, outputColors, testCodeFragments, StageToSpecConstantMap());
3329 // The same as createInstanceContext above, but with default colors.
3331 InstanceContext createInstanceContext (const ShaderElement (&elements)[N], const map<string, string>& testCodeFragments)
3333 RGBA defaultColors[4];
3334 getDefaultColors(defaultColors);
3335 return createInstanceContext(elements, defaultColors, defaultColors, testCodeFragments);
3338 // For the current InstanceContext, constructs the required modules and shader stage create infos.
3339 void createPipelineShaderStages (const DeviceInterface& vk, const VkDevice vkDevice, InstanceContext& instance, Context& context, vector<ModuleHandleSp>& modules, vector<VkPipelineShaderStageCreateInfo>& createInfos)
3341 for (ModuleMap::const_iterator moduleNdx = instance.moduleMap.begin(); moduleNdx != instance.moduleMap.end(); ++moduleNdx)
3343 const ModuleHandleSp mod(new Unique<VkShaderModule>(createShaderModule(vk, vkDevice, context.getBinaryCollection().get(moduleNdx->first), 0)));
3344 modules.push_back(ModuleHandleSp(mod));
3345 for (vector<EntryToStage>::const_iterator shaderNdx = moduleNdx->second.begin(); shaderNdx != moduleNdx->second.end(); ++shaderNdx)
3347 const EntryToStage& stage = *shaderNdx;
3348 const VkPipelineShaderStageCreateInfo shaderParam =
3350 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, // VkStructureType sType;
3351 DE_NULL, // const void* pNext;
3352 (VkPipelineShaderStageCreateFlags)0,
3353 stage.second, // VkShaderStageFlagBits stage;
3354 **modules.back(), // VkShaderModule module;
3355 stage.first.c_str(), // const char* pName;
3356 (const VkSpecializationInfo*)DE_NULL,
3358 createInfos.push_back(shaderParam);
3363 #define SPIRV_ASSEMBLY_TYPES \
3364 "%void = OpTypeVoid\n" \
3365 "%bool = OpTypeBool\n" \
3367 "%i32 = OpTypeInt 32 1\n" \
3368 "%u32 = OpTypeInt 32 0\n" \
3370 "%f32 = OpTypeFloat 32\n" \
3371 "%v3f32 = OpTypeVector %f32 3\n" \
3372 "%v4f32 = OpTypeVector %f32 4\n" \
3373 "%v4bool = OpTypeVector %bool 4\n" \
3375 "%v4f32_function = OpTypeFunction %v4f32 %v4f32\n" \
3376 "%fun = OpTypeFunction %void\n" \
3378 "%ip_f32 = OpTypePointer Input %f32\n" \
3379 "%ip_i32 = OpTypePointer Input %i32\n" \
3380 "%ip_v3f32 = OpTypePointer Input %v3f32\n" \
3381 "%ip_v4f32 = OpTypePointer Input %v4f32\n" \
3383 "%op_f32 = OpTypePointer Output %f32\n" \
3384 "%op_v4f32 = OpTypePointer Output %v4f32\n" \
3386 "%fp_f32 = OpTypePointer Function %f32\n" \
3387 "%fp_i32 = OpTypePointer Function %i32\n" \
3388 "%fp_v4f32 = OpTypePointer Function %v4f32\n"
3390 #define SPIRV_ASSEMBLY_CONSTANTS \
3391 "%c_f32_1 = OpConstant %f32 1.0\n" \
3392 "%c_f32_0 = OpConstant %f32 0.0\n" \
3393 "%c_f32_0_5 = OpConstant %f32 0.5\n" \
3394 "%c_f32_n1 = OpConstant %f32 -1.\n" \
3395 "%c_f32_7 = OpConstant %f32 7.0\n" \
3396 "%c_f32_8 = OpConstant %f32 8.0\n" \
3397 "%c_i32_0 = OpConstant %i32 0\n" \
3398 "%c_i32_1 = OpConstant %i32 1\n" \
3399 "%c_i32_2 = OpConstant %i32 2\n" \
3400 "%c_i32_3 = OpConstant %i32 3\n" \
3401 "%c_i32_4 = OpConstant %i32 4\n" \
3402 "%c_u32_0 = OpConstant %u32 0\n" \
3403 "%c_u32_1 = OpConstant %u32 1\n" \
3404 "%c_u32_2 = OpConstant %u32 2\n" \
3405 "%c_u32_3 = OpConstant %u32 3\n" \
3406 "%c_u32_32 = OpConstant %u32 32\n" \
3407 "%c_u32_4 = OpConstant %u32 4\n" \
3408 "%c_u32_31_bits = OpConstant %u32 0x7FFFFFFF\n" \
3409 "%c_v4f32_1_1_1_1 = OpConstantComposite %v4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_1\n" \
3410 "%c_v4f32_1_0_0_1 = OpConstantComposite %v4f32 %c_f32_1 %c_f32_0 %c_f32_0 %c_f32_1\n" \
3411 "%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"
3413 #define SPIRV_ASSEMBLY_ARRAYS \
3414 "%a1f32 = OpTypeArray %f32 %c_u32_1\n" \
3415 "%a2f32 = OpTypeArray %f32 %c_u32_2\n" \
3416 "%a3v4f32 = OpTypeArray %v4f32 %c_u32_3\n" \
3417 "%a4f32 = OpTypeArray %f32 %c_u32_4\n" \
3418 "%a32v4f32 = OpTypeArray %v4f32 %c_u32_32\n" \
3419 "%ip_a3v4f32 = OpTypePointer Input %a3v4f32\n" \
3420 "%ip_a32v4f32 = OpTypePointer Input %a32v4f32\n" \
3421 "%op_a2f32 = OpTypePointer Output %a2f32\n" \
3422 "%op_a3v4f32 = OpTypePointer Output %a3v4f32\n" \
3423 "%op_a4f32 = OpTypePointer Output %a4f32\n"
3425 // Creates vertex-shader assembly by specializing a boilerplate StringTemplate
3426 // on fragments, which must (at least) map "testfun" to an OpFunction definition
3427 // for %test_code that takes and returns a %v4f32. Boilerplate IDs are prefixed
3428 // with "BP_" to avoid collisions with fragments.
3430 // It corresponds roughly to this GLSL:
3432 // layout(location = 0) in vec4 position;
3433 // layout(location = 1) in vec4 color;
3434 // layout(location = 1) out highp vec4 vtxColor;
3435 // void main (void) { gl_Position = position; vtxColor = test_func(color); }
3436 string makeVertexShaderAssembly(const map<string, string>& fragments)
3438 // \todo [2015-11-23 awoloszyn] Remove OpName once these have stabalized
3439 static const char vertexShaderBoilerplate[] =
3440 "OpCapability Shader\n"
3441 "OpCapability ClipDistance\n"
3442 "OpCapability CullDistance\n"
3443 "OpMemoryModel Logical GLSL450\n"
3444 "OpEntryPoint Vertex %main \"main\" %BP_stream %BP_position %BP_vtx_color %BP_color %BP_gl_VertexIndex %BP_gl_InstanceIndex\n"
3446 "OpName %main \"main\"\n"
3447 "OpName %BP_gl_PerVertex \"gl_PerVertex\"\n"
3448 "OpMemberName %BP_gl_PerVertex 0 \"gl_Position\"\n"
3449 "OpMemberName %BP_gl_PerVertex 1 \"gl_PointSize\"\n"
3450 "OpMemberName %BP_gl_PerVertex 2 \"gl_ClipDistance\"\n"
3451 "OpMemberName %BP_gl_PerVertex 3 \"gl_CullDistance\"\n"
3452 "OpName %test_code \"testfun(vf4;\"\n"
3453 "OpName %BP_stream \"\"\n"
3454 "OpName %BP_position \"position\"\n"
3455 "OpName %BP_vtx_color \"vtxColor\"\n"
3456 "OpName %BP_color \"color\"\n"
3457 "OpName %BP_gl_VertexIndex \"gl_VertexIndex\"\n"
3458 "OpName %BP_gl_InstanceIndex \"gl_InstanceIndex\"\n"
3459 "OpMemberDecorate %BP_gl_PerVertex 0 BuiltIn Position\n"
3460 "OpMemberDecorate %BP_gl_PerVertex 1 BuiltIn PointSize\n"
3461 "OpMemberDecorate %BP_gl_PerVertex 2 BuiltIn ClipDistance\n"
3462 "OpMemberDecorate %BP_gl_PerVertex 3 BuiltIn CullDistance\n"
3463 "OpDecorate %BP_gl_PerVertex Block\n"
3464 "OpDecorate %BP_position Location 0\n"
3465 "OpDecorate %BP_vtx_color Location 1\n"
3466 "OpDecorate %BP_color Location 1\n"
3467 "OpDecorate %BP_gl_VertexIndex BuiltIn VertexIndex\n"
3468 "OpDecorate %BP_gl_InstanceIndex BuiltIn InstanceIndex\n"
3469 "${decoration:opt}\n"
3470 SPIRV_ASSEMBLY_TYPES
3471 SPIRV_ASSEMBLY_CONSTANTS
3472 SPIRV_ASSEMBLY_ARRAYS
3473 "%BP_gl_PerVertex = OpTypeStruct %v4f32 %f32 %a1f32 %a1f32\n"
3474 "%BP_op_gl_PerVertex = OpTypePointer Output %BP_gl_PerVertex\n"
3475 "%BP_stream = OpVariable %BP_op_gl_PerVertex Output\n"
3476 "%BP_position = OpVariable %ip_v4f32 Input\n"
3477 "%BP_vtx_color = OpVariable %op_v4f32 Output\n"
3478 "%BP_color = OpVariable %ip_v4f32 Input\n"
3479 "%BP_gl_VertexIndex = OpVariable %ip_i32 Input\n"
3480 "%BP_gl_InstanceIndex = OpVariable %ip_i32 Input\n"
3482 "%main = OpFunction %void None %fun\n"
3483 "%BP_label = OpLabel\n"
3484 "%BP_pos = OpLoad %v4f32 %BP_position\n"
3485 "%BP_gl_pos = OpAccessChain %op_v4f32 %BP_stream %c_i32_0\n"
3486 "OpStore %BP_gl_pos %BP_pos\n"
3487 "%BP_col = OpLoad %v4f32 %BP_color\n"
3488 "%BP_col_transformed = OpFunctionCall %v4f32 %test_code %BP_col\n"
3489 "OpStore %BP_vtx_color %BP_col_transformed\n"
3493 return tcu::StringTemplate(vertexShaderBoilerplate).specialize(fragments);
3496 // Creates tess-control-shader assembly by specializing a boilerplate
3497 // StringTemplate on fragments, which must (at least) map "testfun" to an
3498 // OpFunction definition for %test_code that takes and returns a %v4f32.
3499 // Boilerplate IDs are prefixed with "BP_" to avoid collisions with fragments.
3501 // It roughly corresponds to the following GLSL.
3504 // layout(vertices = 3) out;
3505 // layout(location = 1) in vec4 in_color[];
3506 // layout(location = 1) out vec4 out_color[];
3509 // out_color[gl_InvocationID] = testfun(in_color[gl_InvocationID]);
3510 // gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;
3511 // if (gl_InvocationID == 0) {
3512 // gl_TessLevelOuter[0] = 1.0;
3513 // gl_TessLevelOuter[1] = 1.0;
3514 // gl_TessLevelOuter[2] = 1.0;
3515 // gl_TessLevelInner[0] = 1.0;
3518 string makeTessControlShaderAssembly (const map<string, string>& fragments)
3520 static const char tessControlShaderBoilerplate[] =
3521 "OpCapability Tessellation\n"
3522 "OpCapability ClipDistance\n"
3523 "OpCapability CullDistance\n"
3524 "OpMemoryModel Logical GLSL450\n"
3525 "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"
3526 "OpExecutionMode %BP_main OutputVertices 3\n"
3528 "OpName %BP_main \"main\"\n"
3529 "OpName %test_code \"testfun(vf4;\"\n"
3530 "OpName %BP_out_color \"out_color\"\n"
3531 "OpName %BP_gl_InvocationID \"gl_InvocationID\"\n"
3532 "OpName %BP_in_color \"in_color\"\n"
3533 "OpName %BP_gl_PerVertex \"gl_PerVertex\"\n"
3534 "OpMemberName %BP_gl_PerVertex 0 \"gl_Position\"\n"
3535 "OpMemberName %BP_gl_PerVertex 1 \"gl_PointSize\"\n"
3536 "OpMemberName %BP_gl_PerVertex 2 \"gl_ClipDistance\"\n"
3537 "OpMemberName %BP_gl_PerVertex 3 \"gl_CullDistance\"\n"
3538 "OpName %BP_gl_out \"gl_out\"\n"
3539 "OpName %BP_gl_PVOut \"gl_PerVertex\"\n"
3540 "OpMemberName %BP_gl_PVOut 0 \"gl_Position\"\n"
3541 "OpMemberName %BP_gl_PVOut 1 \"gl_PointSize\"\n"
3542 "OpMemberName %BP_gl_PVOut 2 \"gl_ClipDistance\"\n"
3543 "OpMemberName %BP_gl_PVOut 3 \"gl_CullDistance\"\n"
3544 "OpName %BP_gl_in \"gl_in\"\n"
3545 "OpName %BP_gl_TessLevelOuter \"gl_TessLevelOuter\"\n"
3546 "OpName %BP_gl_TessLevelInner \"gl_TessLevelInner\"\n"
3547 "OpDecorate %BP_out_color Location 1\n"
3548 "OpDecorate %BP_gl_InvocationID BuiltIn InvocationId\n"
3549 "OpDecorate %BP_in_color Location 1\n"
3550 "OpMemberDecorate %BP_gl_PerVertex 0 BuiltIn Position\n"
3551 "OpMemberDecorate %BP_gl_PerVertex 1 BuiltIn PointSize\n"
3552 "OpMemberDecorate %BP_gl_PerVertex 2 BuiltIn ClipDistance\n"
3553 "OpMemberDecorate %BP_gl_PerVertex 3 BuiltIn CullDistance\n"
3554 "OpDecorate %BP_gl_PerVertex Block\n"
3555 "OpMemberDecorate %BP_gl_PVOut 0 BuiltIn Position\n"
3556 "OpMemberDecorate %BP_gl_PVOut 1 BuiltIn PointSize\n"
3557 "OpMemberDecorate %BP_gl_PVOut 2 BuiltIn ClipDistance\n"
3558 "OpMemberDecorate %BP_gl_PVOut 3 BuiltIn CullDistance\n"
3559 "OpDecorate %BP_gl_PVOut Block\n"
3560 "OpDecorate %BP_gl_TessLevelOuter Patch\n"
3561 "OpDecorate %BP_gl_TessLevelOuter BuiltIn TessLevelOuter\n"
3562 "OpDecorate %BP_gl_TessLevelInner Patch\n"
3563 "OpDecorate %BP_gl_TessLevelInner BuiltIn TessLevelInner\n"
3564 "${decoration:opt}\n"
3565 SPIRV_ASSEMBLY_TYPES
3566 SPIRV_ASSEMBLY_CONSTANTS
3567 SPIRV_ASSEMBLY_ARRAYS
3568 "%BP_out_color = OpVariable %op_a3v4f32 Output\n"
3569 "%BP_gl_InvocationID = OpVariable %ip_i32 Input\n"
3570 "%BP_in_color = OpVariable %ip_a32v4f32 Input\n"
3571 "%BP_gl_PerVertex = OpTypeStruct %v4f32 %f32 %a1f32 %a1f32\n"
3572 "%BP_a3_gl_PerVertex = OpTypeArray %BP_gl_PerVertex %c_u32_3\n"
3573 "%BP_op_a3_gl_PerVertex = OpTypePointer Output %BP_a3_gl_PerVertex\n"
3574 "%BP_gl_out = OpVariable %BP_op_a3_gl_PerVertex Output\n"
3575 "%BP_gl_PVOut = OpTypeStruct %v4f32 %f32 %a1f32 %a1f32\n"
3576 "%BP_a32_gl_PVOut = OpTypeArray %BP_gl_PVOut %c_u32_32\n"
3577 "%BP_ip_a32_gl_PVOut = OpTypePointer Input %BP_a32_gl_PVOut\n"
3578 "%BP_gl_in = OpVariable %BP_ip_a32_gl_PVOut Input\n"
3579 "%BP_gl_TessLevelOuter = OpVariable %op_a4f32 Output\n"
3580 "%BP_gl_TessLevelInner = OpVariable %op_a2f32 Output\n"
3583 "%BP_main = OpFunction %void None %fun\n"
3584 "%BP_label = OpLabel\n"
3586 "%BP_gl_Invoc = OpLoad %i32 %BP_gl_InvocationID\n"
3588 "%BP_in_col_loc = OpAccessChain %ip_v4f32 %BP_in_color %BP_gl_Invoc\n"
3589 "%BP_out_col_loc = OpAccessChain %op_v4f32 %BP_out_color %BP_gl_Invoc\n"
3590 "%BP_in_col_val = OpLoad %v4f32 %BP_in_col_loc\n"
3591 "%BP_clr_transformed = OpFunctionCall %v4f32 %test_code %BP_in_col_val\n"
3592 "OpStore %BP_out_col_loc %BP_clr_transformed\n"
3594 "%BP_in_pos_loc = OpAccessChain %ip_v4f32 %BP_gl_in %BP_gl_Invoc %c_i32_0\n"
3595 "%BP_out_pos_loc = OpAccessChain %op_v4f32 %BP_gl_out %BP_gl_Invoc %c_i32_0\n"
3596 "%BP_in_pos_val = OpLoad %v4f32 %BP_in_pos_loc\n"
3597 "OpStore %BP_out_pos_loc %BP_in_pos_val\n"
3599 "%BP_cmp = OpIEqual %bool %BP_gl_Invoc %c_i32_0\n"
3600 "OpSelectionMerge %BP_merge_label None\n"
3601 "OpBranchConditional %BP_cmp %BP_if_label %BP_merge_label\n"
3602 "%BP_if_label = OpLabel\n"
3603 "%BP_gl_TessLevelOuterPos_0 = OpAccessChain %op_f32 %BP_gl_TessLevelOuter %c_i32_0\n"
3604 "%BP_gl_TessLevelOuterPos_1 = OpAccessChain %op_f32 %BP_gl_TessLevelOuter %c_i32_1\n"
3605 "%BP_gl_TessLevelOuterPos_2 = OpAccessChain %op_f32 %BP_gl_TessLevelOuter %c_i32_2\n"
3606 "%BP_gl_TessLevelInnerPos_0 = OpAccessChain %op_f32 %BP_gl_TessLevelInner %c_i32_0\n"
3607 "OpStore %BP_gl_TessLevelOuterPos_0 %c_f32_1\n"
3608 "OpStore %BP_gl_TessLevelOuterPos_1 %c_f32_1\n"
3609 "OpStore %BP_gl_TessLevelOuterPos_2 %c_f32_1\n"
3610 "OpStore %BP_gl_TessLevelInnerPos_0 %c_f32_1\n"
3611 "OpBranch %BP_merge_label\n"
3612 "%BP_merge_label = OpLabel\n"
3616 return tcu::StringTemplate(tessControlShaderBoilerplate).specialize(fragments);
3619 // Creates tess-evaluation-shader assembly by specializing a boilerplate
3620 // StringTemplate on fragments, which must (at least) map "testfun" to an
3621 // OpFunction definition for %test_code that takes and returns a %v4f32.
3622 // Boilerplate IDs are prefixed with "BP_" to avoid collisions with fragments.
3624 // It roughly corresponds to the following glsl.
3628 // layout(triangles, equal_spacing, ccw) in;
3629 // layout(location = 1) in vec4 in_color[];
3630 // layout(location = 1) out vec4 out_color;
3632 // #define interpolate(val)
3633 // vec4(gl_TessCoord.x) * val[0] + vec4(gl_TessCoord.y) * val[1] +
3634 // vec4(gl_TessCoord.z) * val[2]
3637 // gl_Position = vec4(gl_TessCoord.x) * gl_in[0].gl_Position +
3638 // vec4(gl_TessCoord.y) * gl_in[1].gl_Position +
3639 // vec4(gl_TessCoord.z) * gl_in[2].gl_Position;
3640 // out_color = testfun(interpolate(in_color));
3642 string makeTessEvalShaderAssembly(const map<string, string>& fragments)
3644 static const char tessEvalBoilerplate[] =
3645 "OpCapability Tessellation\n"
3646 "OpCapability ClipDistance\n"
3647 "OpCapability CullDistance\n"
3648 "OpMemoryModel Logical GLSL450\n"
3649 "OpEntryPoint TessellationEvaluation %BP_main \"main\" %BP_stream %BP_gl_TessCoord %BP_gl_in %BP_out_color %BP_in_color\n"
3650 "OpExecutionMode %BP_main Triangles\n"
3651 "OpExecutionMode %BP_main SpacingEqual\n"
3652 "OpExecutionMode %BP_main VertexOrderCcw\n"
3654 "OpName %BP_main \"main\"\n"
3655 "OpName %test_code \"testfun(vf4;\"\n"
3656 "OpName %BP_gl_PerVertexOut \"gl_PerVertex\"\n"
3657 "OpMemberName %BP_gl_PerVertexOut 0 \"gl_Position\"\n"
3658 "OpMemberName %BP_gl_PerVertexOut 1 \"gl_PointSize\"\n"
3659 "OpMemberName %BP_gl_PerVertexOut 2 \"gl_ClipDistance\"\n"
3660 "OpMemberName %BP_gl_PerVertexOut 3 \"gl_CullDistance\"\n"
3661 "OpName %BP_stream \"\"\n"
3662 "OpName %BP_gl_TessCoord \"gl_TessCoord\"\n"
3663 "OpName %BP_gl_PerVertexIn \"gl_PerVertex\"\n"
3664 "OpMemberName %BP_gl_PerVertexIn 0 \"gl_Position\"\n"
3665 "OpMemberName %BP_gl_PerVertexIn 1 \"gl_PointSize\"\n"
3666 "OpMemberName %BP_gl_PerVertexIn 2 \"gl_ClipDistance\"\n"
3667 "OpMemberName %BP_gl_PerVertexIn 3 \"gl_CullDistance\"\n"
3668 "OpName %BP_gl_in \"gl_in\"\n"
3669 "OpName %BP_out_color \"out_color\"\n"
3670 "OpName %BP_in_color \"in_color\"\n"
3671 "OpMemberDecorate %BP_gl_PerVertexOut 0 BuiltIn Position\n"
3672 "OpMemberDecorate %BP_gl_PerVertexOut 1 BuiltIn PointSize\n"
3673 "OpMemberDecorate %BP_gl_PerVertexOut 2 BuiltIn ClipDistance\n"
3674 "OpMemberDecorate %BP_gl_PerVertexOut 3 BuiltIn CullDistance\n"
3675 "OpDecorate %BP_gl_PerVertexOut Block\n"
3676 "OpDecorate %BP_gl_TessCoord BuiltIn TessCoord\n"
3677 "OpMemberDecorate %BP_gl_PerVertexIn 0 BuiltIn Position\n"
3678 "OpMemberDecorate %BP_gl_PerVertexIn 1 BuiltIn PointSize\n"
3679 "OpMemberDecorate %BP_gl_PerVertexIn 2 BuiltIn ClipDistance\n"
3680 "OpMemberDecorate %BP_gl_PerVertexIn 3 BuiltIn CullDistance\n"
3681 "OpDecorate %BP_gl_PerVertexIn Block\n"
3682 "OpDecorate %BP_out_color Location 1\n"
3683 "OpDecorate %BP_in_color Location 1\n"
3684 "${decoration:opt}\n"
3685 SPIRV_ASSEMBLY_TYPES
3686 SPIRV_ASSEMBLY_CONSTANTS
3687 SPIRV_ASSEMBLY_ARRAYS
3688 "%BP_gl_PerVertexOut = OpTypeStruct %v4f32 %f32 %a1f32 %a1f32\n"
3689 "%BP_op_gl_PerVertexOut = OpTypePointer Output %BP_gl_PerVertexOut\n"
3690 "%BP_stream = OpVariable %BP_op_gl_PerVertexOut Output\n"
3691 "%BP_gl_TessCoord = OpVariable %ip_v3f32 Input\n"
3692 "%BP_gl_PerVertexIn = OpTypeStruct %v4f32 %f32 %a1f32 %a1f32\n"
3693 "%BP_a32_gl_PerVertexIn = OpTypeArray %BP_gl_PerVertexIn %c_u32_32\n"
3694 "%BP_ip_a32_gl_PerVertexIn = OpTypePointer Input %BP_a32_gl_PerVertexIn\n"
3695 "%BP_gl_in = OpVariable %BP_ip_a32_gl_PerVertexIn Input\n"
3696 "%BP_out_color = OpVariable %op_v4f32 Output\n"
3697 "%BP_in_color = OpVariable %ip_a32v4f32 Input\n"
3699 "%BP_main = OpFunction %void None %fun\n"
3700 "%BP_label = OpLabel\n"
3701 "%BP_gl_TC_0 = OpAccessChain %ip_f32 %BP_gl_TessCoord %c_u32_0\n"
3702 "%BP_gl_TC_1 = OpAccessChain %ip_f32 %BP_gl_TessCoord %c_u32_1\n"
3703 "%BP_gl_TC_2 = OpAccessChain %ip_f32 %BP_gl_TessCoord %c_u32_2\n"
3704 "%BP_gl_in_gl_Pos_0 = OpAccessChain %ip_v4f32 %BP_gl_in %c_i32_0 %c_i32_0\n"
3705 "%BP_gl_in_gl_Pos_1 = OpAccessChain %ip_v4f32 %BP_gl_in %c_i32_1 %c_i32_0\n"
3706 "%BP_gl_in_gl_Pos_2 = OpAccessChain %ip_v4f32 %BP_gl_in %c_i32_2 %c_i32_0\n"
3708 "%BP_gl_OPos = OpAccessChain %op_v4f32 %BP_stream %c_i32_0\n"
3709 "%BP_in_color_0 = OpAccessChain %ip_v4f32 %BP_in_color %c_i32_0\n"
3710 "%BP_in_color_1 = OpAccessChain %ip_v4f32 %BP_in_color %c_i32_1\n"
3711 "%BP_in_color_2 = OpAccessChain %ip_v4f32 %BP_in_color %c_i32_2\n"
3713 "%BP_TC_W_0 = OpLoad %f32 %BP_gl_TC_0\n"
3714 "%BP_TC_W_1 = OpLoad %f32 %BP_gl_TC_1\n"
3715 "%BP_TC_W_2 = OpLoad %f32 %BP_gl_TC_2\n"
3716 "%BP_v4f32_TC_0 = OpCompositeConstruct %v4f32 %BP_TC_W_0 %BP_TC_W_0 %BP_TC_W_0 %BP_TC_W_0\n"
3717 "%BP_v4f32_TC_1 = OpCompositeConstruct %v4f32 %BP_TC_W_1 %BP_TC_W_1 %BP_TC_W_1 %BP_TC_W_1\n"
3718 "%BP_v4f32_TC_2 = OpCompositeConstruct %v4f32 %BP_TC_W_2 %BP_TC_W_2 %BP_TC_W_2 %BP_TC_W_2\n"
3720 "%BP_gl_IP_0 = OpLoad %v4f32 %BP_gl_in_gl_Pos_0\n"
3721 "%BP_gl_IP_1 = OpLoad %v4f32 %BP_gl_in_gl_Pos_1\n"
3722 "%BP_gl_IP_2 = OpLoad %v4f32 %BP_gl_in_gl_Pos_2\n"
3724 "%BP_IP_W_0 = OpFMul %v4f32 %BP_v4f32_TC_0 %BP_gl_IP_0\n"
3725 "%BP_IP_W_1 = OpFMul %v4f32 %BP_v4f32_TC_1 %BP_gl_IP_1\n"
3726 "%BP_IP_W_2 = OpFMul %v4f32 %BP_v4f32_TC_2 %BP_gl_IP_2\n"
3728 "%BP_pos_sum_0 = OpFAdd %v4f32 %BP_IP_W_0 %BP_IP_W_1\n"
3729 "%BP_pos_sum_1 = OpFAdd %v4f32 %BP_pos_sum_0 %BP_IP_W_2\n"
3731 "OpStore %BP_gl_OPos %BP_pos_sum_1\n"
3733 "%BP_IC_0 = OpLoad %v4f32 %BP_in_color_0\n"
3734 "%BP_IC_1 = OpLoad %v4f32 %BP_in_color_1\n"
3735 "%BP_IC_2 = OpLoad %v4f32 %BP_in_color_2\n"
3737 "%BP_IC_W_0 = OpFMul %v4f32 %BP_v4f32_TC_0 %BP_IC_0\n"
3738 "%BP_IC_W_1 = OpFMul %v4f32 %BP_v4f32_TC_1 %BP_IC_1\n"
3739 "%BP_IC_W_2 = OpFMul %v4f32 %BP_v4f32_TC_2 %BP_IC_2\n"
3741 "%BP_col_sum_0 = OpFAdd %v4f32 %BP_IC_W_0 %BP_IC_W_1\n"
3742 "%BP_col_sum_1 = OpFAdd %v4f32 %BP_col_sum_0 %BP_IC_W_2\n"
3744 "%BP_clr_transformed = OpFunctionCall %v4f32 %test_code %BP_col_sum_1\n"
3746 "OpStore %BP_out_color %BP_clr_transformed\n"
3750 return tcu::StringTemplate(tessEvalBoilerplate).specialize(fragments);
3753 // Creates geometry-shader assembly by specializing a boilerplate StringTemplate
3754 // on fragments, which must (at least) map "testfun" to an OpFunction definition
3755 // for %test_code that takes and returns a %v4f32. Boilerplate IDs are prefixed
3756 // with "BP_" to avoid collisions with fragments.
3758 // Derived from this GLSL:
3761 // layout(triangles) in;
3762 // layout(triangle_strip, max_vertices = 3) out;
3764 // layout(location = 1) in vec4 in_color[];
3765 // layout(location = 1) out vec4 out_color;
3768 // gl_Position = gl_in[0].gl_Position;
3769 // out_color = test_fun(in_color[0]);
3771 // gl_Position = gl_in[1].gl_Position;
3772 // out_color = test_fun(in_color[1]);
3774 // gl_Position = gl_in[2].gl_Position;
3775 // out_color = test_fun(in_color[2]);
3779 string makeGeometryShaderAssembly(const map<string, string>& fragments)
3781 static const char geometryShaderBoilerplate[] =
3782 "OpCapability Geometry\n"
3783 "OpCapability ClipDistance\n"
3784 "OpCapability CullDistance\n"
3785 "OpMemoryModel Logical GLSL450\n"
3786 "OpEntryPoint Geometry %BP_main \"main\" %BP_out_gl_position %BP_gl_in %BP_out_color %BP_in_color\n"
3787 "OpExecutionMode %BP_main Triangles\n"
3788 "OpExecutionMode %BP_main OutputTriangleStrip\n"
3789 "OpExecutionMode %BP_main OutputVertices 3\n"
3791 "OpName %BP_main \"main\"\n"
3792 "OpName %BP_per_vertex_in \"gl_PerVertex\"\n"
3793 "OpMemberName %BP_per_vertex_in 0 \"gl_Position\"\n"
3794 "OpMemberName %BP_per_vertex_in 1 \"gl_PointSize\"\n"
3795 "OpMemberName %BP_per_vertex_in 2 \"gl_ClipDistance\"\n"
3796 "OpMemberName %BP_per_vertex_in 3 \"gl_CullDistance\"\n"
3797 "OpName %BP_gl_in \"gl_in\"\n"
3798 "OpName %BP_out_color \"out_color\"\n"
3799 "OpName %BP_in_color \"in_color\"\n"
3800 "OpName %test_code \"testfun(vf4;\"\n"
3801 "OpDecorate %BP_out_gl_position BuiltIn Position\n"
3802 "OpMemberDecorate %BP_per_vertex_in 0 BuiltIn Position\n"
3803 "OpMemberDecorate %BP_per_vertex_in 1 BuiltIn PointSize\n"
3804 "OpMemberDecorate %BP_per_vertex_in 2 BuiltIn ClipDistance\n"
3805 "OpMemberDecorate %BP_per_vertex_in 3 BuiltIn CullDistance\n"
3806 "OpDecorate %BP_per_vertex_in Block\n"
3807 "OpDecorate %BP_out_color Location 1\n"
3808 "OpDecorate %BP_in_color Location 1\n"
3809 "${decoration:opt}\n"
3810 SPIRV_ASSEMBLY_TYPES
3811 SPIRV_ASSEMBLY_CONSTANTS
3812 SPIRV_ASSEMBLY_ARRAYS
3813 "%BP_per_vertex_in = OpTypeStruct %v4f32 %f32 %a1f32 %a1f32\n"
3814 "%BP_a3_per_vertex_in = OpTypeArray %BP_per_vertex_in %c_u32_3\n"
3815 "%BP_ip_a3_per_vertex_in = OpTypePointer Input %BP_a3_per_vertex_in\n"
3817 "%BP_gl_in = OpVariable %BP_ip_a3_per_vertex_in Input\n"
3818 "%BP_out_color = OpVariable %op_v4f32 Output\n"
3819 "%BP_in_color = OpVariable %ip_a3v4f32 Input\n"
3820 "%BP_out_gl_position = OpVariable %op_v4f32 Output\n"
3823 "%BP_main = OpFunction %void None %fun\n"
3824 "%BP_label = OpLabel\n"
3825 "%BP_gl_in_0_gl_position = OpAccessChain %ip_v4f32 %BP_gl_in %c_i32_0 %c_i32_0\n"
3826 "%BP_gl_in_1_gl_position = OpAccessChain %ip_v4f32 %BP_gl_in %c_i32_1 %c_i32_0\n"
3827 "%BP_gl_in_2_gl_position = OpAccessChain %ip_v4f32 %BP_gl_in %c_i32_2 %c_i32_0\n"
3829 "%BP_in_position_0 = OpLoad %v4f32 %BP_gl_in_0_gl_position\n"
3830 "%BP_in_position_1 = OpLoad %v4f32 %BP_gl_in_1_gl_position\n"
3831 "%BP_in_position_2 = OpLoad %v4f32 %BP_gl_in_2_gl_position \n"
3833 "%BP_in_color_0_ptr = OpAccessChain %ip_v4f32 %BP_in_color %c_i32_0\n"
3834 "%BP_in_color_1_ptr = OpAccessChain %ip_v4f32 %BP_in_color %c_i32_1\n"
3835 "%BP_in_color_2_ptr = OpAccessChain %ip_v4f32 %BP_in_color %c_i32_2\n"
3837 "%BP_in_color_0 = OpLoad %v4f32 %BP_in_color_0_ptr\n"
3838 "%BP_in_color_1 = OpLoad %v4f32 %BP_in_color_1_ptr\n"
3839 "%BP_in_color_2 = OpLoad %v4f32 %BP_in_color_2_ptr\n"
3841 "%BP_transformed_in_color_0 = OpFunctionCall %v4f32 %test_code %BP_in_color_0\n"
3842 "%BP_transformed_in_color_1 = OpFunctionCall %v4f32 %test_code %BP_in_color_1\n"
3843 "%BP_transformed_in_color_2 = OpFunctionCall %v4f32 %test_code %BP_in_color_2\n"
3846 "OpStore %BP_out_gl_position %BP_in_position_0\n"
3847 "OpStore %BP_out_color %BP_transformed_in_color_0\n"
3850 "OpStore %BP_out_gl_position %BP_in_position_1\n"
3851 "OpStore %BP_out_color %BP_transformed_in_color_1\n"
3854 "OpStore %BP_out_gl_position %BP_in_position_2\n"
3855 "OpStore %BP_out_color %BP_transformed_in_color_2\n"
3862 return tcu::StringTemplate(geometryShaderBoilerplate).specialize(fragments);
3865 // Creates fragment-shader assembly by specializing a boilerplate StringTemplate
3866 // on fragments, which must (at least) map "testfun" to an OpFunction definition
3867 // for %test_code that takes and returns a %v4f32. Boilerplate IDs are prefixed
3868 // with "BP_" to avoid collisions with fragments.
3870 // Derived from this GLSL:
3872 // layout(location = 1) in highp vec4 vtxColor;
3873 // layout(location = 0) out highp vec4 fragColor;
3874 // highp vec4 testfun(highp vec4 x) { return x; }
3875 // void main(void) { fragColor = testfun(vtxColor); }
3877 // with modifications including passing vtxColor by value and ripping out
3878 // testfun() definition.
3879 string makeFragmentShaderAssembly(const map<string, string>& fragments)
3881 static const char fragmentShaderBoilerplate[] =
3882 "OpCapability Shader\n"
3883 "OpMemoryModel Logical GLSL450\n"
3884 "OpEntryPoint Fragment %BP_main \"main\" %BP_vtxColor %BP_fragColor\n"
3885 "OpExecutionMode %BP_main OriginUpperLeft\n"
3887 "OpName %BP_main \"main\"\n"
3888 "OpName %BP_fragColor \"fragColor\"\n"
3889 "OpName %BP_vtxColor \"vtxColor\"\n"
3890 "OpName %test_code \"testfun(vf4;\"\n"
3891 "OpDecorate %BP_fragColor Location 0\n"
3892 "OpDecorate %BP_vtxColor Location 1\n"
3893 "${decoration:opt}\n"
3894 SPIRV_ASSEMBLY_TYPES
3895 SPIRV_ASSEMBLY_CONSTANTS
3896 SPIRV_ASSEMBLY_ARRAYS
3897 "%BP_fragColor = OpVariable %op_v4f32 Output\n"
3898 "%BP_vtxColor = OpVariable %ip_v4f32 Input\n"
3900 "%BP_main = OpFunction %void None %fun\n"
3901 "%BP_label_main = OpLabel\n"
3902 "%BP_tmp1 = OpLoad %v4f32 %BP_vtxColor\n"
3903 "%BP_tmp2 = OpFunctionCall %v4f32 %test_code %BP_tmp1\n"
3904 "OpStore %BP_fragColor %BP_tmp2\n"
3908 return tcu::StringTemplate(fragmentShaderBoilerplate).specialize(fragments);
3911 // Creates fragments that specialize into a simple pass-through shader (of any kind).
3912 map<string, string> passthruFragments(void)
3914 map<string, string> fragments;
3915 fragments["testfun"] =
3916 // A %test_code function that returns its argument unchanged.
3917 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
3918 "%param1 = OpFunctionParameter %v4f32\n"
3919 "%label_testfun = OpLabel\n"
3920 "OpReturnValue %param1\n"
3925 // Adds shader assembly text to dst.spirvAsmSources for all shader kinds.
3926 // Vertex shader gets custom code from context, the rest are pass-through.
3927 void addShaderCodeCustomVertex(vk::SourceCollections& dst, InstanceContext context)
3929 map<string, string> passthru = passthruFragments();
3930 dst.spirvAsmSources.add("vert") << makeVertexShaderAssembly(context.testCodeFragments);
3931 dst.spirvAsmSources.add("frag") << makeFragmentShaderAssembly(passthru);
3934 // Adds shader assembly text to dst.spirvAsmSources for all shader kinds.
3935 // Tessellation control shader gets custom code from context, the rest are
3937 void addShaderCodeCustomTessControl(vk::SourceCollections& dst, InstanceContext context)
3939 map<string, string> passthru = passthruFragments();
3940 dst.spirvAsmSources.add("vert") << makeVertexShaderAssembly(passthru);
3941 dst.spirvAsmSources.add("tessc") << makeTessControlShaderAssembly(context.testCodeFragments);
3942 dst.spirvAsmSources.add("tesse") << makeTessEvalShaderAssembly(passthru);
3943 dst.spirvAsmSources.add("frag") << makeFragmentShaderAssembly(passthru);
3946 // Adds shader assembly text to dst.spirvAsmSources for all shader kinds.
3947 // Tessellation evaluation shader gets custom code from context, the rest are
3949 void addShaderCodeCustomTessEval(vk::SourceCollections& dst, InstanceContext context)
3951 map<string, string> passthru = passthruFragments();
3952 dst.spirvAsmSources.add("vert") << makeVertexShaderAssembly(passthru);
3953 dst.spirvAsmSources.add("tessc") << makeTessControlShaderAssembly(passthru);
3954 dst.spirvAsmSources.add("tesse") << makeTessEvalShaderAssembly(context.testCodeFragments);
3955 dst.spirvAsmSources.add("frag") << makeFragmentShaderAssembly(passthru);
3958 // Adds shader assembly text to dst.spirvAsmSources for all shader kinds.
3959 // Geometry shader gets custom code from context, the rest are pass-through.
3960 void addShaderCodeCustomGeometry(vk::SourceCollections& dst, InstanceContext context)
3962 map<string, string> passthru = passthruFragments();
3963 dst.spirvAsmSources.add("vert") << makeVertexShaderAssembly(passthru);
3964 dst.spirvAsmSources.add("geom") << makeGeometryShaderAssembly(context.testCodeFragments);
3965 dst.spirvAsmSources.add("frag") << makeFragmentShaderAssembly(passthru);
3968 // Adds shader assembly text to dst.spirvAsmSources for all shader kinds.
3969 // Fragment shader gets custom code from context, the rest are pass-through.
3970 void addShaderCodeCustomFragment(vk::SourceCollections& dst, InstanceContext context)
3972 map<string, string> passthru = passthruFragments();
3973 dst.spirvAsmSources.add("vert") << makeVertexShaderAssembly(passthru);
3974 dst.spirvAsmSources.add("frag") << makeFragmentShaderAssembly(context.testCodeFragments);
3977 void createCombinedModule(vk::SourceCollections& dst, InstanceContext)
3979 // \todo [2015-12-07 awoloszyn] Make tessellation / geometry conditional
3980 // \todo [2015-12-07 awoloszyn] Remove OpName and OpMemberName at some point
3981 dst.spirvAsmSources.add("module") <<
3982 "OpCapability Shader\n"
3983 "OpCapability ClipDistance\n"
3984 "OpCapability CullDistance\n"
3985 "OpCapability Geometry\n"
3986 "OpCapability Tessellation\n"
3987 "OpMemoryModel Logical GLSL450\n"
3989 "OpEntryPoint Vertex %vert_main \"main\" %vert_Position %vert_vtxColor %vert_color %vert_vtxPosition %vert_vertex_id %vert_instance_id\n"
3990 "OpEntryPoint Geometry %geom_main \"main\" %geom_out_gl_position %geom_gl_in %geom_out_color %geom_in_color\n"
3991 "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"
3992 "OpEntryPoint TessellationEvaluation %tesse_main \"main\" %tesse_stream %tesse_gl_tessCoord %tesse_in_position %tesse_out_color %tesse_in_color \n"
3993 "OpEntryPoint Fragment %frag_main \"main\" %frag_vtxColor %frag_fragColor\n"
3995 "OpExecutionMode %geom_main Triangles\n"
3996 "OpExecutionMode %geom_main OutputTriangleStrip\n"
3997 "OpExecutionMode %geom_main OutputVertices 3\n"
3999 "OpExecutionMode %tessc_main OutputVertices 3\n"
4001 "OpExecutionMode %tesse_main Triangles\n"
4002 "OpExecutionMode %tesse_main SpacingEqual\n"
4003 "OpExecutionMode %tesse_main VertexOrderCcw\n"
4005 "OpExecutionMode %frag_main OriginUpperLeft\n"
4007 "OpName %vert_main \"main\"\n"
4008 "OpName %vert_vtxPosition \"vtxPosition\"\n"
4009 "OpName %vert_Position \"position\"\n"
4010 "OpName %vert_vtxColor \"vtxColor\"\n"
4011 "OpName %vert_color \"color\"\n"
4012 "OpName %vert_vertex_id \"gl_VertexIndex\"\n"
4013 "OpName %vert_instance_id \"gl_InstanceIndex\"\n"
4014 "OpName %geom_main \"main\"\n"
4015 "OpName %geom_per_vertex_in \"gl_PerVertex\"\n"
4016 "OpMemberName %geom_per_vertex_in 0 \"gl_Position\"\n"
4017 "OpMemberName %geom_per_vertex_in 1 \"gl_PointSize\"\n"
4018 "OpMemberName %geom_per_vertex_in 2 \"gl_ClipDistance\"\n"
4019 "OpMemberName %geom_per_vertex_in 3 \"gl_CullDistance\"\n"
4020 "OpName %geom_gl_in \"gl_in\"\n"
4021 "OpName %geom_out_color \"out_color\"\n"
4022 "OpName %geom_in_color \"in_color\"\n"
4023 "OpName %tessc_main \"main\"\n"
4024 "OpName %tessc_out_color \"out_color\"\n"
4025 "OpName %tessc_gl_InvocationID \"gl_InvocationID\"\n"
4026 "OpName %tessc_in_color \"in_color\"\n"
4027 "OpName %tessc_out_position \"out_position\"\n"
4028 "OpName %tessc_in_position \"in_position\"\n"
4029 "OpName %tessc_gl_TessLevelOuter \"gl_TessLevelOuter\"\n"
4030 "OpName %tessc_gl_TessLevelInner \"gl_TessLevelInner\"\n"
4031 "OpName %tesse_main \"main\"\n"
4032 "OpName %tesse_per_vertex_out \"gl_PerVertex\"\n"
4033 "OpMemberName %tesse_per_vertex_out 0 \"gl_Position\"\n"
4034 "OpMemberName %tesse_per_vertex_out 1 \"gl_PointSize\"\n"
4035 "OpMemberName %tesse_per_vertex_out 2 \"gl_ClipDistance\"\n"
4036 "OpMemberName %tesse_per_vertex_out 3 \"gl_CullDistance\"\n"
4037 "OpName %tesse_stream \"\"\n"
4038 "OpName %tesse_gl_tessCoord \"gl_TessCoord\"\n"
4039 "OpName %tesse_in_position \"in_position\"\n"
4040 "OpName %tesse_out_color \"out_color\"\n"
4041 "OpName %tesse_in_color \"in_color\"\n"
4042 "OpName %frag_main \"main\"\n"
4043 "OpName %frag_fragColor \"fragColor\"\n"
4044 "OpName %frag_vtxColor \"vtxColor\"\n"
4046 "; Vertex decorations\n"
4047 "OpDecorate %vert_vtxPosition Location 2\n"
4048 "OpDecorate %vert_Position Location 0\n"
4049 "OpDecorate %vert_vtxColor Location 1\n"
4050 "OpDecorate %vert_color Location 1\n"
4051 "OpDecorate %vert_vertex_id BuiltIn VertexIndex\n"
4052 "OpDecorate %vert_instance_id BuiltIn InstanceIndex\n"
4054 "; Geometry decorations\n"
4055 "OpDecorate %geom_out_gl_position BuiltIn Position\n"
4056 "OpMemberDecorate %geom_per_vertex_in 0 BuiltIn Position\n"
4057 "OpMemberDecorate %geom_per_vertex_in 1 BuiltIn PointSize\n"
4058 "OpMemberDecorate %geom_per_vertex_in 2 BuiltIn ClipDistance\n"
4059 "OpMemberDecorate %geom_per_vertex_in 3 BuiltIn CullDistance\n"
4060 "OpDecorate %geom_per_vertex_in Block\n"
4061 "OpDecorate %geom_out_color Location 1\n"
4062 "OpDecorate %geom_in_color Location 1\n"
4064 "; Tessellation Control decorations\n"
4065 "OpDecorate %tessc_out_color Location 1\n"
4066 "OpDecorate %tessc_gl_InvocationID BuiltIn InvocationId\n"
4067 "OpDecorate %tessc_in_color Location 1\n"
4068 "OpDecorate %tessc_out_position Location 2\n"
4069 "OpDecorate %tessc_in_position Location 2\n"
4070 "OpDecorate %tessc_gl_TessLevelOuter Patch\n"
4071 "OpDecorate %tessc_gl_TessLevelOuter BuiltIn TessLevelOuter\n"
4072 "OpDecorate %tessc_gl_TessLevelInner Patch\n"
4073 "OpDecorate %tessc_gl_TessLevelInner BuiltIn TessLevelInner\n"
4075 "; Tessellation Evaluation decorations\n"
4076 "OpMemberDecorate %tesse_per_vertex_out 0 BuiltIn Position\n"
4077 "OpMemberDecorate %tesse_per_vertex_out 1 BuiltIn PointSize\n"
4078 "OpMemberDecorate %tesse_per_vertex_out 2 BuiltIn ClipDistance\n"
4079 "OpMemberDecorate %tesse_per_vertex_out 3 BuiltIn CullDistance\n"
4080 "OpDecorate %tesse_per_vertex_out Block\n"
4081 "OpDecorate %tesse_gl_tessCoord BuiltIn TessCoord\n"
4082 "OpDecorate %tesse_in_position Location 2\n"
4083 "OpDecorate %tesse_out_color Location 1\n"
4084 "OpDecorate %tesse_in_color Location 1\n"
4086 "; Fragment decorations\n"
4087 "OpDecorate %frag_fragColor Location 0\n"
4088 "OpDecorate %frag_vtxColor Location 1\n"
4090 SPIRV_ASSEMBLY_TYPES
4091 SPIRV_ASSEMBLY_CONSTANTS
4092 SPIRV_ASSEMBLY_ARRAYS
4094 "; Vertex Variables\n"
4095 "%vert_vtxPosition = OpVariable %op_v4f32 Output\n"
4096 "%vert_Position = OpVariable %ip_v4f32 Input\n"
4097 "%vert_vtxColor = OpVariable %op_v4f32 Output\n"
4098 "%vert_color = OpVariable %ip_v4f32 Input\n"
4099 "%vert_vertex_id = OpVariable %ip_i32 Input\n"
4100 "%vert_instance_id = OpVariable %ip_i32 Input\n"
4102 "; Geometry Variables\n"
4103 "%geom_per_vertex_in = OpTypeStruct %v4f32 %f32 %a1f32 %a1f32\n"
4104 "%geom_a3_per_vertex_in = OpTypeArray %geom_per_vertex_in %c_u32_3\n"
4105 "%geom_ip_a3_per_vertex_in = OpTypePointer Input %geom_a3_per_vertex_in\n"
4106 "%geom_gl_in = OpVariable %geom_ip_a3_per_vertex_in Input\n"
4107 "%geom_out_color = OpVariable %op_v4f32 Output\n"
4108 "%geom_in_color = OpVariable %ip_a3v4f32 Input\n"
4109 "%geom_out_gl_position = OpVariable %op_v4f32 Output\n"
4111 "; Tessellation Control Variables\n"
4112 "%tessc_out_color = OpVariable %op_a3v4f32 Output\n"
4113 "%tessc_gl_InvocationID = OpVariable %ip_i32 Input\n"
4114 "%tessc_in_color = OpVariable %ip_a32v4f32 Input\n"
4115 "%tessc_out_position = OpVariable %op_a3v4f32 Output\n"
4116 "%tessc_in_position = OpVariable %ip_a32v4f32 Input\n"
4117 "%tessc_gl_TessLevelOuter = OpVariable %op_a4f32 Output\n"
4118 "%tessc_gl_TessLevelInner = OpVariable %op_a2f32 Output\n"
4120 "; Tessellation Evaluation Decorations\n"
4121 "%tesse_per_vertex_out = OpTypeStruct %v4f32 %f32 %a1f32 %a1f32\n"
4122 "%tesse_op_per_vertex_out = OpTypePointer Output %tesse_per_vertex_out\n"
4123 "%tesse_stream = OpVariable %tesse_op_per_vertex_out Output\n"
4124 "%tesse_gl_tessCoord = OpVariable %ip_v3f32 Input\n"
4125 "%tesse_in_position = OpVariable %ip_a32v4f32 Input\n"
4126 "%tesse_out_color = OpVariable %op_v4f32 Output\n"
4127 "%tesse_in_color = OpVariable %ip_a32v4f32 Input\n"
4129 "; Fragment Variables\n"
4130 "%frag_fragColor = OpVariable %op_v4f32 Output\n"
4131 "%frag_vtxColor = OpVariable %ip_v4f32 Input\n"
4134 "%vert_main = OpFunction %void None %fun\n"
4135 "%vert_label = OpLabel\n"
4136 "%vert_tmp_position = OpLoad %v4f32 %vert_Position\n"
4137 "OpStore %vert_vtxPosition %vert_tmp_position\n"
4138 "%vert_tmp_color = OpLoad %v4f32 %vert_color\n"
4139 "OpStore %vert_vtxColor %vert_tmp_color\n"
4143 "; Geometry Entry\n"
4144 "%geom_main = OpFunction %void None %fun\n"
4145 "%geom_label = OpLabel\n"
4146 "%geom_gl_in_0_gl_position = OpAccessChain %ip_v4f32 %geom_gl_in %c_i32_0 %c_i32_0\n"
4147 "%geom_gl_in_1_gl_position = OpAccessChain %ip_v4f32 %geom_gl_in %c_i32_1 %c_i32_0\n"
4148 "%geom_gl_in_2_gl_position = OpAccessChain %ip_v4f32 %geom_gl_in %c_i32_2 %c_i32_0\n"
4149 "%geom_in_position_0 = OpLoad %v4f32 %geom_gl_in_0_gl_position\n"
4150 "%geom_in_position_1 = OpLoad %v4f32 %geom_gl_in_1_gl_position\n"
4151 "%geom_in_position_2 = OpLoad %v4f32 %geom_gl_in_2_gl_position \n"
4152 "%geom_in_color_0_ptr = OpAccessChain %ip_v4f32 %geom_in_color %c_i32_0\n"
4153 "%geom_in_color_1_ptr = OpAccessChain %ip_v4f32 %geom_in_color %c_i32_1\n"
4154 "%geom_in_color_2_ptr = OpAccessChain %ip_v4f32 %geom_in_color %c_i32_2\n"
4155 "%geom_in_color_0 = OpLoad %v4f32 %geom_in_color_0_ptr\n"
4156 "%geom_in_color_1 = OpLoad %v4f32 %geom_in_color_1_ptr\n"
4157 "%geom_in_color_2 = OpLoad %v4f32 %geom_in_color_2_ptr\n"
4158 "OpStore %geom_out_gl_position %geom_in_position_0\n"
4159 "OpStore %geom_out_color %geom_in_color_0\n"
4161 "OpStore %geom_out_gl_position %geom_in_position_1\n"
4162 "OpStore %geom_out_color %geom_in_color_1\n"
4164 "OpStore %geom_out_gl_position %geom_in_position_2\n"
4165 "OpStore %geom_out_color %geom_in_color_2\n"
4171 "; Tessellation Control Entry\n"
4172 "%tessc_main = OpFunction %void None %fun\n"
4173 "%tessc_label = OpLabel\n"
4174 "%tessc_invocation_id = OpLoad %i32 %tessc_gl_InvocationID\n"
4175 "%tessc_in_color_ptr = OpAccessChain %ip_v4f32 %tessc_in_color %tessc_invocation_id\n"
4176 "%tessc_in_position_ptr = OpAccessChain %ip_v4f32 %tessc_in_position %tessc_invocation_id\n"
4177 "%tessc_in_color_val = OpLoad %v4f32 %tessc_in_color_ptr\n"
4178 "%tessc_in_position_val = OpLoad %v4f32 %tessc_in_position_ptr\n"
4179 "%tessc_out_color_ptr = OpAccessChain %op_v4f32 %tessc_out_color %tessc_invocation_id\n"
4180 "%tessc_out_position_ptr = OpAccessChain %op_v4f32 %tessc_out_position %tessc_invocation_id\n"
4181 "OpStore %tessc_out_color_ptr %tessc_in_color_val\n"
4182 "OpStore %tessc_out_position_ptr %tessc_in_position_val\n"
4183 "%tessc_is_first_invocation = OpIEqual %bool %tessc_invocation_id %c_i32_0\n"
4184 "OpSelectionMerge %tessc_merge_label None\n"
4185 "OpBranchConditional %tessc_is_first_invocation %tessc_first_invocation %tessc_merge_label\n"
4186 "%tessc_first_invocation = OpLabel\n"
4187 "%tessc_tess_outer_0 = OpAccessChain %op_f32 %tessc_gl_TessLevelOuter %c_i32_0\n"
4188 "%tessc_tess_outer_1 = OpAccessChain %op_f32 %tessc_gl_TessLevelOuter %c_i32_1\n"
4189 "%tessc_tess_outer_2 = OpAccessChain %op_f32 %tessc_gl_TessLevelOuter %c_i32_2\n"
4190 "%tessc_tess_inner = OpAccessChain %op_f32 %tessc_gl_TessLevelInner %c_i32_0\n"
4191 "OpStore %tessc_tess_outer_0 %c_f32_1\n"
4192 "OpStore %tessc_tess_outer_1 %c_f32_1\n"
4193 "OpStore %tessc_tess_outer_2 %c_f32_1\n"
4194 "OpStore %tessc_tess_inner %c_f32_1\n"
4195 "OpBranch %tessc_merge_label\n"
4196 "%tessc_merge_label = OpLabel\n"
4200 "; Tessellation Evaluation Entry\n"
4201 "%tesse_main = OpFunction %void None %fun\n"
4202 "%tesse_label = OpLabel\n"
4203 "%tesse_tc_0_ptr = OpAccessChain %ip_f32 %tesse_gl_tessCoord %c_u32_0\n"
4204 "%tesse_tc_1_ptr = OpAccessChain %ip_f32 %tesse_gl_tessCoord %c_u32_1\n"
4205 "%tesse_tc_2_ptr = OpAccessChain %ip_f32 %tesse_gl_tessCoord %c_u32_2\n"
4206 "%tesse_tc_0 = OpLoad %f32 %tesse_tc_0_ptr\n"
4207 "%tesse_tc_1 = OpLoad %f32 %tesse_tc_1_ptr\n"
4208 "%tesse_tc_2 = OpLoad %f32 %tesse_tc_2_ptr\n"
4209 "%tesse_in_pos_0_ptr = OpAccessChain %ip_v4f32 %tesse_in_position %c_i32_0\n"
4210 "%tesse_in_pos_1_ptr = OpAccessChain %ip_v4f32 %tesse_in_position %c_i32_1\n"
4211 "%tesse_in_pos_2_ptr = OpAccessChain %ip_v4f32 %tesse_in_position %c_i32_2\n"
4212 "%tesse_in_pos_0 = OpLoad %v4f32 %tesse_in_pos_0_ptr\n"
4213 "%tesse_in_pos_1 = OpLoad %v4f32 %tesse_in_pos_1_ptr\n"
4214 "%tesse_in_pos_2 = OpLoad %v4f32 %tesse_in_pos_2_ptr\n"
4215 "%tesse_in_pos_0_weighted = OpVectorTimesScalar %v4f32 %tesse_tc_0 %tesse_in_pos_0\n"
4216 "%tesse_in_pos_1_weighted = OpVectorTimesScalar %v4f32 %tesse_tc_1 %tesse_in_pos_1\n"
4217 "%tesse_in_pos_2_weighted = OpVectorTimesScalar %v4f32 %tesse_tc_2 %tesse_in_pos_2\n"
4218 "%tesse_out_pos_ptr = OpAccessChain %op_v4f32 %tesse_stream %c_i32_0\n"
4219 "%tesse_in_pos_0_plus_pos_1 = OpFAdd %v4f32 %tesse_in_pos_0_weighted %tesse_in_pos_1_weighted\n"
4220 "%tesse_computed_out = OpFAdd %v4f32 %tesse_in_pos_0_plus_pos_1 %tesse_in_pos_2_weighted\n"
4221 "OpStore %tesse_out_pos_ptr %tesse_computed_out\n"
4222 "%tesse_in_clr_0_ptr = OpAccessChain %ip_v4f32 %tesse_in_color %c_i32_0\n"
4223 "%tesse_in_clr_1_ptr = OpAccessChain %ip_v4f32 %tesse_in_color %c_i32_1\n"
4224 "%tesse_in_clr_2_ptr = OpAccessChain %ip_v4f32 %tesse_in_color %c_i32_2\n"
4225 "%tesse_in_clr_0 = OpLoad %v4f32 %tesse_in_clr_0_ptr\n"
4226 "%tesse_in_clr_1 = OpLoad %v4f32 %tesse_in_clr_1_ptr\n"
4227 "%tesse_in_clr_2 = OpLoad %v4f32 %tesse_in_clr_2_ptr\n"
4228 "%tesse_in_clr_0_weighted = OpVectorTimesScalar %v4f32 %tesse_tc_0 %tesse_in_clr_0\n"
4229 "%tesse_in_clr_1_weighted = OpVectorTimesScalar %v4f32 %tesse_tc_1 %tesse_in_clr_1\n"
4230 "%tesse_in_clr_2_weighted = OpVectorTimesScalar %v4f32 %tesse_tc_2 %tesse_in_clr_2\n"
4231 "%tesse_in_clr_0_plus_col_1 = OpFAdd %v4f32 %tesse_in_clr_0_weighted %tesse_in_clr_1_weighted\n"
4232 "%tesse_computed_clr = OpFAdd %v4f32 %tesse_in_clr_0_plus_col_1 %tesse_in_clr_2_weighted\n"
4233 "OpStore %tesse_out_color %tesse_computed_clr\n"
4237 "; Fragment Entry\n"
4238 "%frag_main = OpFunction %void None %fun\n"
4239 "%frag_label_main = OpLabel\n"
4240 "%frag_tmp1 = OpLoad %v4f32 %frag_vtxColor\n"
4241 "OpStore %frag_fragColor %frag_tmp1\n"
4246 // This has two shaders of each stage. The first
4247 // is a passthrough, the second inverts the color.
4248 void createMultipleEntries(vk::SourceCollections& dst, InstanceContext)
4250 dst.spirvAsmSources.add("vert") <<
4251 // This module contains 2 vertex shaders. One that is a passthrough
4252 // and a second that inverts the color of the output (1.0 - color).
4253 "OpCapability Shader\n"
4254 "OpMemoryModel Logical GLSL450\n"
4255 "OpEntryPoint Vertex %main \"vert1\" %Position %vtxColor %color %vtxPosition %vertex_id %instance_id\n"
4256 "OpEntryPoint Vertex %main2 \"vert2\" %Position %vtxColor %color %vtxPosition %vertex_id %instance_id\n"
4258 "OpName %main \"vert1\"\n"
4259 "OpName %main2 \"vert2\"\n"
4260 "OpName %vtxPosition \"vtxPosition\"\n"
4261 "OpName %Position \"position\"\n"
4262 "OpName %vtxColor \"vtxColor\"\n"
4263 "OpName %color \"color\"\n"
4264 "OpName %vertex_id \"gl_VertexIndex\"\n"
4265 "OpName %instance_id \"gl_InstanceIndex\"\n"
4267 "OpDecorate %vtxPosition Location 2\n"
4268 "OpDecorate %Position Location 0\n"
4269 "OpDecorate %vtxColor Location 1\n"
4270 "OpDecorate %color Location 1\n"
4271 "OpDecorate %vertex_id BuiltIn VertexIndex\n"
4272 "OpDecorate %instance_id BuiltIn InstanceIndex\n"
4273 SPIRV_ASSEMBLY_TYPES
4274 SPIRV_ASSEMBLY_CONSTANTS
4275 SPIRV_ASSEMBLY_ARRAYS
4276 "%cval = OpConstantComposite %v4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_0\n"
4277 "%vtxPosition = OpVariable %op_v4f32 Output\n"
4278 "%Position = OpVariable %ip_v4f32 Input\n"
4279 "%vtxColor = OpVariable %op_v4f32 Output\n"
4280 "%color = OpVariable %ip_v4f32 Input\n"
4281 "%vertex_id = OpVariable %ip_i32 Input\n"
4282 "%instance_id = OpVariable %ip_i32 Input\n"
4284 "%main = OpFunction %void None %fun\n"
4285 "%label = OpLabel\n"
4286 "%tmp_position = OpLoad %v4f32 %Position\n"
4287 "OpStore %vtxPosition %tmp_position\n"
4288 "%tmp_color = OpLoad %v4f32 %color\n"
4289 "OpStore %vtxColor %tmp_color\n"
4293 "%main2 = OpFunction %void None %fun\n"
4294 "%label2 = OpLabel\n"
4295 "%tmp_position2 = OpLoad %v4f32 %Position\n"
4296 "OpStore %vtxPosition %tmp_position2\n"
4297 "%tmp_color2 = OpLoad %v4f32 %color\n"
4298 "%tmp_color3 = OpFSub %v4f32 %cval %tmp_color2\n"
4299 "%tmp_color4 = OpVectorInsertDynamic %v4f32 %tmp_color3 %c_f32_1 %c_i32_3\n"
4300 "OpStore %vtxColor %tmp_color4\n"
4304 dst.spirvAsmSources.add("frag") <<
4305 // This is a single module that contains 2 fragment shaders.
4306 // One that passes color through and the other that inverts the output
4307 // color (1.0 - color).
4308 "OpCapability Shader\n"
4309 "OpMemoryModel Logical GLSL450\n"
4310 "OpEntryPoint Fragment %main \"frag1\" %vtxColor %fragColor\n"
4311 "OpEntryPoint Fragment %main2 \"frag2\" %vtxColor %fragColor\n"
4312 "OpExecutionMode %main OriginUpperLeft\n"
4313 "OpExecutionMode %main2 OriginUpperLeft\n"
4315 "OpName %main \"frag1\"\n"
4316 "OpName %main2 \"frag2\"\n"
4317 "OpName %fragColor \"fragColor\"\n"
4318 "OpName %vtxColor \"vtxColor\"\n"
4319 "OpDecorate %fragColor Location 0\n"
4320 "OpDecorate %vtxColor Location 1\n"
4321 SPIRV_ASSEMBLY_TYPES
4322 SPIRV_ASSEMBLY_CONSTANTS
4323 SPIRV_ASSEMBLY_ARRAYS
4324 "%cval = OpConstantComposite %v4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_0\n"
4325 "%fragColor = OpVariable %op_v4f32 Output\n"
4326 "%vtxColor = OpVariable %ip_v4f32 Input\n"
4328 "%main = OpFunction %void None %fun\n"
4329 "%label_main = OpLabel\n"
4330 "%tmp1 = OpLoad %v4f32 %vtxColor\n"
4331 "OpStore %fragColor %tmp1\n"
4335 "%main2 = OpFunction %void None %fun\n"
4336 "%label_main2 = OpLabel\n"
4337 "%tmp2 = OpLoad %v4f32 %vtxColor\n"
4338 "%tmp3 = OpFSub %v4f32 %cval %tmp2\n"
4339 "%tmp4 = OpVectorInsertDynamic %v4f32 %tmp3 %c_f32_1 %c_i32_3\n"
4340 "OpStore %fragColor %tmp4\n"
4344 dst.spirvAsmSources.add("geom") <<
4345 "OpCapability Geometry\n"
4346 "OpCapability ClipDistance\n"
4347 "OpCapability CullDistance\n"
4348 "OpMemoryModel Logical GLSL450\n"
4349 "OpEntryPoint Geometry %geom1_main \"geom1\" %out_gl_position %gl_in %out_color %in_color\n"
4350 "OpEntryPoint Geometry %geom2_main \"geom2\" %out_gl_position %gl_in %out_color %in_color\n"
4351 "OpExecutionMode %geom1_main Triangles\n"
4352 "OpExecutionMode %geom2_main Triangles\n"
4353 "OpExecutionMode %geom1_main OutputTriangleStrip\n"
4354 "OpExecutionMode %geom2_main OutputTriangleStrip\n"
4355 "OpExecutionMode %geom1_main OutputVertices 3\n"
4356 "OpExecutionMode %geom2_main OutputVertices 3\n"
4357 "OpName %geom1_main \"geom1\"\n"
4358 "OpName %geom2_main \"geom2\"\n"
4359 "OpName %per_vertex_in \"gl_PerVertex\"\n"
4360 "OpMemberName %per_vertex_in 0 \"gl_Position\"\n"
4361 "OpMemberName %per_vertex_in 1 \"gl_PointSize\"\n"
4362 "OpMemberName %per_vertex_in 2 \"gl_ClipDistance\"\n"
4363 "OpMemberName %per_vertex_in 3 \"gl_CullDistance\"\n"
4364 "OpName %gl_in \"gl_in\"\n"
4365 "OpName %out_color \"out_color\"\n"
4366 "OpName %in_color \"in_color\"\n"
4367 "OpDecorate %out_gl_position BuiltIn Position\n"
4368 "OpMemberDecorate %per_vertex_in 0 BuiltIn Position\n"
4369 "OpMemberDecorate %per_vertex_in 1 BuiltIn PointSize\n"
4370 "OpMemberDecorate %per_vertex_in 2 BuiltIn ClipDistance\n"
4371 "OpMemberDecorate %per_vertex_in 3 BuiltIn CullDistance\n"
4372 "OpDecorate %per_vertex_in Block\n"
4373 "OpDecorate %out_color Location 1\n"
4374 "OpDecorate %in_color Location 1\n"
4375 SPIRV_ASSEMBLY_TYPES
4376 SPIRV_ASSEMBLY_CONSTANTS
4377 SPIRV_ASSEMBLY_ARRAYS
4378 "%cval = OpConstantComposite %v4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_0\n"
4379 "%per_vertex_in = OpTypeStruct %v4f32 %f32 %a1f32 %a1f32\n"
4380 "%a3_per_vertex_in = OpTypeArray %per_vertex_in %c_u32_3\n"
4381 "%ip_a3_per_vertex_in = OpTypePointer Input %a3_per_vertex_in\n"
4382 "%gl_in = OpVariable %ip_a3_per_vertex_in Input\n"
4383 "%out_color = OpVariable %op_v4f32 Output\n"
4384 "%in_color = OpVariable %ip_a3v4f32 Input\n"
4385 "%out_gl_position = OpVariable %op_v4f32 Output\n"
4387 "%geom1_main = OpFunction %void None %fun\n"
4388 "%geom1_label = OpLabel\n"
4389 "%geom1_gl_in_0_gl_position = OpAccessChain %ip_v4f32 %gl_in %c_i32_0 %c_i32_0\n"
4390 "%geom1_gl_in_1_gl_position = OpAccessChain %ip_v4f32 %gl_in %c_i32_1 %c_i32_0\n"
4391 "%geom1_gl_in_2_gl_position = OpAccessChain %ip_v4f32 %gl_in %c_i32_2 %c_i32_0\n"
4392 "%geom1_in_position_0 = OpLoad %v4f32 %geom1_gl_in_0_gl_position\n"
4393 "%geom1_in_position_1 = OpLoad %v4f32 %geom1_gl_in_1_gl_position\n"
4394 "%geom1_in_position_2 = OpLoad %v4f32 %geom1_gl_in_2_gl_position \n"
4395 "%geom1_in_color_0_ptr = OpAccessChain %ip_v4f32 %in_color %c_i32_0\n"
4396 "%geom1_in_color_1_ptr = OpAccessChain %ip_v4f32 %in_color %c_i32_1\n"
4397 "%geom1_in_color_2_ptr = OpAccessChain %ip_v4f32 %in_color %c_i32_2\n"
4398 "%geom1_in_color_0 = OpLoad %v4f32 %geom1_in_color_0_ptr\n"
4399 "%geom1_in_color_1 = OpLoad %v4f32 %geom1_in_color_1_ptr\n"
4400 "%geom1_in_color_2 = OpLoad %v4f32 %geom1_in_color_2_ptr\n"
4401 "OpStore %out_gl_position %geom1_in_position_0\n"
4402 "OpStore %out_color %geom1_in_color_0\n"
4404 "OpStore %out_gl_position %geom1_in_position_1\n"
4405 "OpStore %out_color %geom1_in_color_1\n"
4407 "OpStore %out_gl_position %geom1_in_position_2\n"
4408 "OpStore %out_color %geom1_in_color_2\n"
4414 "%geom2_main = OpFunction %void None %fun\n"
4415 "%geom2_label = OpLabel\n"
4416 "%geom2_gl_in_0_gl_position = OpAccessChain %ip_v4f32 %gl_in %c_i32_0 %c_i32_0\n"
4417 "%geom2_gl_in_1_gl_position = OpAccessChain %ip_v4f32 %gl_in %c_i32_1 %c_i32_0\n"
4418 "%geom2_gl_in_2_gl_position = OpAccessChain %ip_v4f32 %gl_in %c_i32_2 %c_i32_0\n"
4419 "%geom2_in_position_0 = OpLoad %v4f32 %geom2_gl_in_0_gl_position\n"
4420 "%geom2_in_position_1 = OpLoad %v4f32 %geom2_gl_in_1_gl_position\n"
4421 "%geom2_in_position_2 = OpLoad %v4f32 %geom2_gl_in_2_gl_position \n"
4422 "%geom2_in_color_0_ptr = OpAccessChain %ip_v4f32 %in_color %c_i32_0\n"
4423 "%geom2_in_color_1_ptr = OpAccessChain %ip_v4f32 %in_color %c_i32_1\n"
4424 "%geom2_in_color_2_ptr = OpAccessChain %ip_v4f32 %in_color %c_i32_2\n"
4425 "%geom2_in_color_0 = OpLoad %v4f32 %geom2_in_color_0_ptr\n"
4426 "%geom2_in_color_1 = OpLoad %v4f32 %geom2_in_color_1_ptr\n"
4427 "%geom2_in_color_2 = OpLoad %v4f32 %geom2_in_color_2_ptr\n"
4428 "%geom2_transformed_in_color_0 = OpFSub %v4f32 %cval %geom2_in_color_0\n"
4429 "%geom2_transformed_in_color_1 = OpFSub %v4f32 %cval %geom2_in_color_1\n"
4430 "%geom2_transformed_in_color_2 = OpFSub %v4f32 %cval %geom2_in_color_2\n"
4431 "%geom2_transformed_in_color_0_a = OpVectorInsertDynamic %v4f32 %geom2_transformed_in_color_0 %c_f32_1 %c_i32_3\n"
4432 "%geom2_transformed_in_color_1_a = OpVectorInsertDynamic %v4f32 %geom2_transformed_in_color_1 %c_f32_1 %c_i32_3\n"
4433 "%geom2_transformed_in_color_2_a = OpVectorInsertDynamic %v4f32 %geom2_transformed_in_color_2 %c_f32_1 %c_i32_3\n"
4434 "OpStore %out_gl_position %geom2_in_position_0\n"
4435 "OpStore %out_color %geom2_transformed_in_color_0_a\n"
4437 "OpStore %out_gl_position %geom2_in_position_1\n"
4438 "OpStore %out_color %geom2_transformed_in_color_1_a\n"
4440 "OpStore %out_gl_position %geom2_in_position_2\n"
4441 "OpStore %out_color %geom2_transformed_in_color_2_a\n"
4447 dst.spirvAsmSources.add("tessc") <<
4448 "OpCapability Tessellation\n"
4449 "OpMemoryModel Logical GLSL450\n"
4450 "OpEntryPoint TessellationControl %tessc1_main \"tessc1\" %out_color %gl_InvocationID %in_color %out_position %in_position %gl_TessLevelOuter %gl_TessLevelInner\n"
4451 "OpEntryPoint TessellationControl %tessc2_main \"tessc2\" %out_color %gl_InvocationID %in_color %out_position %in_position %gl_TessLevelOuter %gl_TessLevelInner\n"
4452 "OpExecutionMode %tessc1_main OutputVertices 3\n"
4453 "OpExecutionMode %tessc2_main OutputVertices 3\n"
4454 "OpName %tessc1_main \"tessc1\"\n"
4455 "OpName %tessc2_main \"tessc2\"\n"
4456 "OpName %out_color \"out_color\"\n"
4457 "OpName %gl_InvocationID \"gl_InvocationID\"\n"
4458 "OpName %in_color \"in_color\"\n"
4459 "OpName %out_position \"out_position\"\n"
4460 "OpName %in_position \"in_position\"\n"
4461 "OpName %gl_TessLevelOuter \"gl_TessLevelOuter\"\n"
4462 "OpName %gl_TessLevelInner \"gl_TessLevelInner\"\n"
4463 "OpDecorate %out_color Location 1\n"
4464 "OpDecorate %gl_InvocationID BuiltIn InvocationId\n"
4465 "OpDecorate %in_color Location 1\n"
4466 "OpDecorate %out_position Location 2\n"
4467 "OpDecorate %in_position Location 2\n"
4468 "OpDecorate %gl_TessLevelOuter Patch\n"
4469 "OpDecorate %gl_TessLevelOuter BuiltIn TessLevelOuter\n"
4470 "OpDecorate %gl_TessLevelInner Patch\n"
4471 "OpDecorate %gl_TessLevelInner BuiltIn TessLevelInner\n"
4472 SPIRV_ASSEMBLY_TYPES
4473 SPIRV_ASSEMBLY_CONSTANTS
4474 SPIRV_ASSEMBLY_ARRAYS
4475 "%cval = OpConstantComposite %v4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_0\n"
4476 "%out_color = OpVariable %op_a3v4f32 Output\n"
4477 "%gl_InvocationID = OpVariable %ip_i32 Input\n"
4478 "%in_color = OpVariable %ip_a32v4f32 Input\n"
4479 "%out_position = OpVariable %op_a3v4f32 Output\n"
4480 "%in_position = OpVariable %ip_a32v4f32 Input\n"
4481 "%gl_TessLevelOuter = OpVariable %op_a4f32 Output\n"
4482 "%gl_TessLevelInner = OpVariable %op_a2f32 Output\n"
4484 "%tessc1_main = OpFunction %void None %fun\n"
4485 "%tessc1_label = OpLabel\n"
4486 "%tessc1_invocation_id = OpLoad %i32 %gl_InvocationID\n"
4487 "%tessc1_in_color_ptr = OpAccessChain %ip_v4f32 %in_color %tessc1_invocation_id\n"
4488 "%tessc1_in_position_ptr = OpAccessChain %ip_v4f32 %in_position %tessc1_invocation_id\n"
4489 "%tessc1_in_color_val = OpLoad %v4f32 %tessc1_in_color_ptr\n"
4490 "%tessc1_in_position_val = OpLoad %v4f32 %tessc1_in_position_ptr\n"
4491 "%tessc1_out_color_ptr = OpAccessChain %op_v4f32 %out_color %tessc1_invocation_id\n"
4492 "%tessc1_out_position_ptr = OpAccessChain %op_v4f32 %out_position %tessc1_invocation_id\n"
4493 "OpStore %tessc1_out_color_ptr %tessc1_in_color_val\n"
4494 "OpStore %tessc1_out_position_ptr %tessc1_in_position_val\n"
4495 "%tessc1_is_first_invocation = OpIEqual %bool %tessc1_invocation_id %c_i32_0\n"
4496 "OpSelectionMerge %tessc1_merge_label None\n"
4497 "OpBranchConditional %tessc1_is_first_invocation %tessc1_first_invocation %tessc1_merge_label\n"
4498 "%tessc1_first_invocation = OpLabel\n"
4499 "%tessc1_tess_outer_0 = OpAccessChain %op_f32 %gl_TessLevelOuter %c_i32_0\n"
4500 "%tessc1_tess_outer_1 = OpAccessChain %op_f32 %gl_TessLevelOuter %c_i32_1\n"
4501 "%tessc1_tess_outer_2 = OpAccessChain %op_f32 %gl_TessLevelOuter %c_i32_2\n"
4502 "%tessc1_tess_inner = OpAccessChain %op_f32 %gl_TessLevelInner %c_i32_0\n"
4503 "OpStore %tessc1_tess_outer_0 %c_f32_1\n"
4504 "OpStore %tessc1_tess_outer_1 %c_f32_1\n"
4505 "OpStore %tessc1_tess_outer_2 %c_f32_1\n"
4506 "OpStore %tessc1_tess_inner %c_f32_1\n"
4507 "OpBranch %tessc1_merge_label\n"
4508 "%tessc1_merge_label = OpLabel\n"
4512 "%tessc2_main = OpFunction %void None %fun\n"
4513 "%tessc2_label = OpLabel\n"
4514 "%tessc2_invocation_id = OpLoad %i32 %gl_InvocationID\n"
4515 "%tessc2_in_color_ptr = OpAccessChain %ip_v4f32 %in_color %tessc2_invocation_id\n"
4516 "%tessc2_in_position_ptr = OpAccessChain %ip_v4f32 %in_position %tessc2_invocation_id\n"
4517 "%tessc2_in_color_val = OpLoad %v4f32 %tessc2_in_color_ptr\n"
4518 "%tessc2_in_position_val = OpLoad %v4f32 %tessc2_in_position_ptr\n"
4519 "%tessc2_out_color_ptr = OpAccessChain %op_v4f32 %out_color %tessc2_invocation_id\n"
4520 "%tessc2_out_position_ptr = OpAccessChain %op_v4f32 %out_position %tessc2_invocation_id\n"
4521 "%tessc2_transformed_color = OpFSub %v4f32 %cval %tessc2_in_color_val\n"
4522 "%tessc2_transformed_color_a = OpVectorInsertDynamic %v4f32 %tessc2_transformed_color %c_f32_1 %c_i32_3\n"
4523 "OpStore %tessc2_out_color_ptr %tessc2_transformed_color_a\n"
4524 "OpStore %tessc2_out_position_ptr %tessc2_in_position_val\n"
4525 "%tessc2_is_first_invocation = OpIEqual %bool %tessc2_invocation_id %c_i32_0\n"
4526 "OpSelectionMerge %tessc2_merge_label None\n"
4527 "OpBranchConditional %tessc2_is_first_invocation %tessc2_first_invocation %tessc2_merge_label\n"
4528 "%tessc2_first_invocation = OpLabel\n"
4529 "%tessc2_tess_outer_0 = OpAccessChain %op_f32 %gl_TessLevelOuter %c_i32_0\n"
4530 "%tessc2_tess_outer_1 = OpAccessChain %op_f32 %gl_TessLevelOuter %c_i32_1\n"
4531 "%tessc2_tess_outer_2 = OpAccessChain %op_f32 %gl_TessLevelOuter %c_i32_2\n"
4532 "%tessc2_tess_inner = OpAccessChain %op_f32 %gl_TessLevelInner %c_i32_0\n"
4533 "OpStore %tessc2_tess_outer_0 %c_f32_1\n"
4534 "OpStore %tessc2_tess_outer_1 %c_f32_1\n"
4535 "OpStore %tessc2_tess_outer_2 %c_f32_1\n"
4536 "OpStore %tessc2_tess_inner %c_f32_1\n"
4537 "OpBranch %tessc2_merge_label\n"
4538 "%tessc2_merge_label = OpLabel\n"
4542 dst.spirvAsmSources.add("tesse") <<
4543 "OpCapability Tessellation\n"
4544 "OpCapability ClipDistance\n"
4545 "OpCapability CullDistance\n"
4546 "OpMemoryModel Logical GLSL450\n"
4547 "OpEntryPoint TessellationEvaluation %tesse1_main \"tesse1\" %stream %gl_tessCoord %in_position %out_color %in_color \n"
4548 "OpEntryPoint TessellationEvaluation %tesse2_main \"tesse2\" %stream %gl_tessCoord %in_position %out_color %in_color \n"
4549 "OpExecutionMode %tesse1_main Triangles\n"
4550 "OpExecutionMode %tesse1_main SpacingEqual\n"
4551 "OpExecutionMode %tesse1_main VertexOrderCcw\n"
4552 "OpExecutionMode %tesse2_main Triangles\n"
4553 "OpExecutionMode %tesse2_main SpacingEqual\n"
4554 "OpExecutionMode %tesse2_main VertexOrderCcw\n"
4555 "OpName %tesse1_main \"tesse1\"\n"
4556 "OpName %tesse2_main \"tesse2\"\n"
4557 "OpName %per_vertex_out \"gl_PerVertex\"\n"
4558 "OpMemberName %per_vertex_out 0 \"gl_Position\"\n"
4559 "OpMemberName %per_vertex_out 1 \"gl_PointSize\"\n"
4560 "OpMemberName %per_vertex_out 2 \"gl_ClipDistance\"\n"
4561 "OpMemberName %per_vertex_out 3 \"gl_CullDistance\"\n"
4562 "OpName %stream \"\"\n"
4563 "OpName %gl_tessCoord \"gl_TessCoord\"\n"
4564 "OpName %in_position \"in_position\"\n"
4565 "OpName %out_color \"out_color\"\n"
4566 "OpName %in_color \"in_color\"\n"
4567 "OpMemberDecorate %per_vertex_out 0 BuiltIn Position\n"
4568 "OpMemberDecorate %per_vertex_out 1 BuiltIn PointSize\n"
4569 "OpMemberDecorate %per_vertex_out 2 BuiltIn ClipDistance\n"
4570 "OpMemberDecorate %per_vertex_out 3 BuiltIn CullDistance\n"
4571 "OpDecorate %per_vertex_out Block\n"
4572 "OpDecorate %gl_tessCoord BuiltIn TessCoord\n"
4573 "OpDecorate %in_position Location 2\n"
4574 "OpDecorate %out_color Location 1\n"
4575 "OpDecorate %in_color Location 1\n"
4576 SPIRV_ASSEMBLY_TYPES
4577 SPIRV_ASSEMBLY_CONSTANTS
4578 SPIRV_ASSEMBLY_ARRAYS
4579 "%cval = OpConstantComposite %v4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_0\n"
4580 "%per_vertex_out = OpTypeStruct %v4f32 %f32 %a1f32 %a1f32\n"
4581 "%op_per_vertex_out = OpTypePointer Output %per_vertex_out\n"
4582 "%stream = OpVariable %op_per_vertex_out Output\n"
4583 "%gl_tessCoord = OpVariable %ip_v3f32 Input\n"
4584 "%in_position = OpVariable %ip_a32v4f32 Input\n"
4585 "%out_color = OpVariable %op_v4f32 Output\n"
4586 "%in_color = OpVariable %ip_a32v4f32 Input\n"
4588 "%tesse1_main = OpFunction %void None %fun\n"
4589 "%tesse1_label = OpLabel\n"
4590 "%tesse1_tc_0_ptr = OpAccessChain %ip_f32 %gl_tessCoord %c_u32_0\n"
4591 "%tesse1_tc_1_ptr = OpAccessChain %ip_f32 %gl_tessCoord %c_u32_1\n"
4592 "%tesse1_tc_2_ptr = OpAccessChain %ip_f32 %gl_tessCoord %c_u32_2\n"
4593 "%tesse1_tc_0 = OpLoad %f32 %tesse1_tc_0_ptr\n"
4594 "%tesse1_tc_1 = OpLoad %f32 %tesse1_tc_1_ptr\n"
4595 "%tesse1_tc_2 = OpLoad %f32 %tesse1_tc_2_ptr\n"
4596 "%tesse1_in_pos_0_ptr = OpAccessChain %ip_v4f32 %in_position %c_i32_0\n"
4597 "%tesse1_in_pos_1_ptr = OpAccessChain %ip_v4f32 %in_position %c_i32_1\n"
4598 "%tesse1_in_pos_2_ptr = OpAccessChain %ip_v4f32 %in_position %c_i32_2\n"
4599 "%tesse1_in_pos_0 = OpLoad %v4f32 %tesse1_in_pos_0_ptr\n"
4600 "%tesse1_in_pos_1 = OpLoad %v4f32 %tesse1_in_pos_1_ptr\n"
4601 "%tesse1_in_pos_2 = OpLoad %v4f32 %tesse1_in_pos_2_ptr\n"
4602 "%tesse1_in_pos_0_weighted = OpVectorTimesScalar %v4f32 %tesse1_tc_0 %tesse1_in_pos_0\n"
4603 "%tesse1_in_pos_1_weighted = OpVectorTimesScalar %v4f32 %tesse1_tc_1 %tesse1_in_pos_1\n"
4604 "%tesse1_in_pos_2_weighted = OpVectorTimesScalar %v4f32 %tesse1_tc_2 %tesse1_in_pos_2\n"
4605 "%tesse1_out_pos_ptr = OpAccessChain %op_v4f32 %stream %c_i32_0\n"
4606 "%tesse1_in_pos_0_plus_pos_1 = OpFAdd %v4f32 %tesse1_in_pos_0_weighted %tesse1_in_pos_1_weighted\n"
4607 "%tesse1_computed_out = OpFAdd %v4f32 %tesse1_in_pos_0_plus_pos_1 %tesse1_in_pos_2_weighted\n"
4608 "OpStore %tesse1_out_pos_ptr %tesse1_computed_out\n"
4609 "%tesse1_in_clr_0_ptr = OpAccessChain %ip_v4f32 %in_color %c_i32_0\n"
4610 "%tesse1_in_clr_1_ptr = OpAccessChain %ip_v4f32 %in_color %c_i32_1\n"
4611 "%tesse1_in_clr_2_ptr = OpAccessChain %ip_v4f32 %in_color %c_i32_2\n"
4612 "%tesse1_in_clr_0 = OpLoad %v4f32 %tesse1_in_clr_0_ptr\n"
4613 "%tesse1_in_clr_1 = OpLoad %v4f32 %tesse1_in_clr_1_ptr\n"
4614 "%tesse1_in_clr_2 = OpLoad %v4f32 %tesse1_in_clr_2_ptr\n"
4615 "%tesse1_in_clr_0_weighted = OpVectorTimesScalar %v4f32 %tesse1_tc_0 %tesse1_in_clr_0\n"
4616 "%tesse1_in_clr_1_weighted = OpVectorTimesScalar %v4f32 %tesse1_tc_1 %tesse1_in_clr_1\n"
4617 "%tesse1_in_clr_2_weighted = OpVectorTimesScalar %v4f32 %tesse1_tc_2 %tesse1_in_clr_2\n"
4618 "%tesse1_in_clr_0_plus_col_1 = OpFAdd %v4f32 %tesse1_in_clr_0_weighted %tesse1_in_clr_1_weighted\n"
4619 "%tesse1_computed_clr = OpFAdd %v4f32 %tesse1_in_clr_0_plus_col_1 %tesse1_in_clr_2_weighted\n"
4620 "OpStore %out_color %tesse1_computed_clr\n"
4624 "%tesse2_main = OpFunction %void None %fun\n"
4625 "%tesse2_label = OpLabel\n"
4626 "%tesse2_tc_0_ptr = OpAccessChain %ip_f32 %gl_tessCoord %c_u32_0\n"
4627 "%tesse2_tc_1_ptr = OpAccessChain %ip_f32 %gl_tessCoord %c_u32_1\n"
4628 "%tesse2_tc_2_ptr = OpAccessChain %ip_f32 %gl_tessCoord %c_u32_2\n"
4629 "%tesse2_tc_0 = OpLoad %f32 %tesse2_tc_0_ptr\n"
4630 "%tesse2_tc_1 = OpLoad %f32 %tesse2_tc_1_ptr\n"
4631 "%tesse2_tc_2 = OpLoad %f32 %tesse2_tc_2_ptr\n"
4632 "%tesse2_in_pos_0_ptr = OpAccessChain %ip_v4f32 %in_position %c_i32_0\n"
4633 "%tesse2_in_pos_1_ptr = OpAccessChain %ip_v4f32 %in_position %c_i32_1\n"
4634 "%tesse2_in_pos_2_ptr = OpAccessChain %ip_v4f32 %in_position %c_i32_2\n"
4635 "%tesse2_in_pos_0 = OpLoad %v4f32 %tesse2_in_pos_0_ptr\n"
4636 "%tesse2_in_pos_1 = OpLoad %v4f32 %tesse2_in_pos_1_ptr\n"
4637 "%tesse2_in_pos_2 = OpLoad %v4f32 %tesse2_in_pos_2_ptr\n"
4638 "%tesse2_in_pos_0_weighted = OpVectorTimesScalar %v4f32 %tesse2_tc_0 %tesse2_in_pos_0\n"
4639 "%tesse2_in_pos_1_weighted = OpVectorTimesScalar %v4f32 %tesse2_tc_1 %tesse2_in_pos_1\n"
4640 "%tesse2_in_pos_2_weighted = OpVectorTimesScalar %v4f32 %tesse2_tc_2 %tesse2_in_pos_2\n"
4641 "%tesse2_out_pos_ptr = OpAccessChain %op_v4f32 %stream %c_i32_0\n"
4642 "%tesse2_in_pos_0_plus_pos_1 = OpFAdd %v4f32 %tesse2_in_pos_0_weighted %tesse2_in_pos_1_weighted\n"
4643 "%tesse2_computed_out = OpFAdd %v4f32 %tesse2_in_pos_0_plus_pos_1 %tesse2_in_pos_2_weighted\n"
4644 "OpStore %tesse2_out_pos_ptr %tesse2_computed_out\n"
4645 "%tesse2_in_clr_0_ptr = OpAccessChain %ip_v4f32 %in_color %c_i32_0\n"
4646 "%tesse2_in_clr_1_ptr = OpAccessChain %ip_v4f32 %in_color %c_i32_1\n"
4647 "%tesse2_in_clr_2_ptr = OpAccessChain %ip_v4f32 %in_color %c_i32_2\n"
4648 "%tesse2_in_clr_0 = OpLoad %v4f32 %tesse2_in_clr_0_ptr\n"
4649 "%tesse2_in_clr_1 = OpLoad %v4f32 %tesse2_in_clr_1_ptr\n"
4650 "%tesse2_in_clr_2 = OpLoad %v4f32 %tesse2_in_clr_2_ptr\n"
4651 "%tesse2_in_clr_0_weighted = OpVectorTimesScalar %v4f32 %tesse2_tc_0 %tesse2_in_clr_0\n"
4652 "%tesse2_in_clr_1_weighted = OpVectorTimesScalar %v4f32 %tesse2_tc_1 %tesse2_in_clr_1\n"
4653 "%tesse2_in_clr_2_weighted = OpVectorTimesScalar %v4f32 %tesse2_tc_2 %tesse2_in_clr_2\n"
4654 "%tesse2_in_clr_0_plus_col_1 = OpFAdd %v4f32 %tesse2_in_clr_0_weighted %tesse2_in_clr_1_weighted\n"
4655 "%tesse2_computed_clr = OpFAdd %v4f32 %tesse2_in_clr_0_plus_col_1 %tesse2_in_clr_2_weighted\n"
4656 "%tesse2_clr_transformed = OpFSub %v4f32 %cval %tesse2_computed_clr\n"
4657 "%tesse2_clr_transformed_a = OpVectorInsertDynamic %v4f32 %tesse2_clr_transformed %c_f32_1 %c_i32_3\n"
4658 "OpStore %out_color %tesse2_clr_transformed_a\n"
4663 // Sets up and runs a Vulkan pipeline, then spot-checks the resulting image.
4664 // Feeds the pipeline a set of colored triangles, which then must occur in the
4665 // rendered image. The surface is cleared before executing the pipeline, so
4666 // whatever the shaders draw can be directly spot-checked.
4667 TestStatus runAndVerifyDefaultPipeline (Context& context, InstanceContext instance)
4669 const VkDevice vkDevice = context.getDevice();
4670 const DeviceInterface& vk = context.getDeviceInterface();
4671 const VkQueue queue = context.getUniversalQueue();
4672 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
4673 const tcu::UVec2 renderSize (256, 256);
4674 vector<ModuleHandleSp> modules;
4675 map<VkShaderStageFlagBits, VkShaderModule> moduleByStage;
4676 const int testSpecificSeed = 31354125;
4677 const int seed = context.getTestContext().getCommandLine().getBaseSeed() ^ testSpecificSeed;
4678 bool supportsGeometry = false;
4679 bool supportsTessellation = false;
4680 bool hasTessellation = false;
4682 const VkPhysicalDeviceFeatures& features = context.getDeviceFeatures();
4683 supportsGeometry = features.geometryShader == VK_TRUE;
4684 supportsTessellation = features.tessellationShader == VK_TRUE;
4685 hasTessellation = (instance.requiredStages & VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT) ||
4686 (instance.requiredStages & VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT);
4688 if (hasTessellation && !supportsTessellation)
4690 throw tcu::NotSupportedError(std::string("Tessellation not supported"));
4693 if ((instance.requiredStages & VK_SHADER_STAGE_GEOMETRY_BIT) &&
4696 throw tcu::NotSupportedError(std::string("Geometry not supported"));
4699 de::Random(seed).shuffle(instance.inputColors, instance.inputColors+4);
4700 de::Random(seed).shuffle(instance.outputColors, instance.outputColors+4);
4701 const Vec4 vertexData[] =
4703 // Upper left corner:
4704 Vec4(-1.0f, -1.0f, 0.0f, 1.0f), instance.inputColors[0].toVec(),
4705 Vec4(-0.5f, -1.0f, 0.0f, 1.0f), instance.inputColors[0].toVec(),
4706 Vec4(-1.0f, -0.5f, 0.0f, 1.0f), instance.inputColors[0].toVec(),
4708 // Upper right corner:
4709 Vec4(+0.5f, -1.0f, 0.0f, 1.0f), instance.inputColors[1].toVec(),
4710 Vec4(+1.0f, -1.0f, 0.0f, 1.0f), instance.inputColors[1].toVec(),
4711 Vec4(+1.0f, -0.5f, 0.0f, 1.0f), instance.inputColors[1].toVec(),
4713 // Lower left corner:
4714 Vec4(-1.0f, +0.5f, 0.0f, 1.0f), instance.inputColors[2].toVec(),
4715 Vec4(-0.5f, +1.0f, 0.0f, 1.0f), instance.inputColors[2].toVec(),
4716 Vec4(-1.0f, +1.0f, 0.0f, 1.0f), instance.inputColors[2].toVec(),
4718 // Lower right corner:
4719 Vec4(+1.0f, +0.5f, 0.0f, 1.0f), instance.inputColors[3].toVec(),
4720 Vec4(+1.0f, +1.0f, 0.0f, 1.0f), instance.inputColors[3].toVec(),
4721 Vec4(+0.5f, +1.0f, 0.0f, 1.0f), instance.inputColors[3].toVec()
4723 const size_t singleVertexDataSize = 2 * sizeof(Vec4);
4724 const size_t vertexCount = sizeof(vertexData) / singleVertexDataSize;
4726 const VkBufferCreateInfo vertexBufferParams =
4728 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
4729 DE_NULL, // const void* pNext;
4730 0u, // VkBufferCreateFlags flags;
4731 (VkDeviceSize)sizeof(vertexData), // VkDeviceSize size;
4732 VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, // VkBufferUsageFlags usage;
4733 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
4734 1u, // deUint32 queueFamilyCount;
4735 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
4737 const Unique<VkBuffer> vertexBuffer (createBuffer(vk, vkDevice, &vertexBufferParams));
4738 const UniquePtr<Allocation> vertexBufferMemory (context.getDefaultAllocator().allocate(getBufferMemoryRequirements(vk, vkDevice, *vertexBuffer), MemoryRequirement::HostVisible));
4740 VK_CHECK(vk.bindBufferMemory(vkDevice, *vertexBuffer, vertexBufferMemory->getMemory(), vertexBufferMemory->getOffset()));
4742 const VkDeviceSize imageSizeBytes = (VkDeviceSize)(sizeof(deUint32)*renderSize.x()*renderSize.y());
4743 const VkBufferCreateInfo readImageBufferParams =
4745 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
4746 DE_NULL, // const void* pNext;
4747 0u, // VkBufferCreateFlags flags;
4748 imageSizeBytes, // VkDeviceSize size;
4749 VK_BUFFER_USAGE_TRANSFER_DST_BIT, // VkBufferUsageFlags usage;
4750 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
4751 1u, // deUint32 queueFamilyCount;
4752 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
4754 const Unique<VkBuffer> readImageBuffer (createBuffer(vk, vkDevice, &readImageBufferParams));
4755 const UniquePtr<Allocation> readImageBufferMemory (context.getDefaultAllocator().allocate(getBufferMemoryRequirements(vk, vkDevice, *readImageBuffer), MemoryRequirement::HostVisible));
4757 VK_CHECK(vk.bindBufferMemory(vkDevice, *readImageBuffer, readImageBufferMemory->getMemory(), readImageBufferMemory->getOffset()));
4759 const VkImageCreateInfo imageParams =
4761 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType;
4762 DE_NULL, // const void* pNext;
4763 0u, // VkImageCreateFlags flags;
4764 VK_IMAGE_TYPE_2D, // VkImageType imageType;
4765 VK_FORMAT_R8G8B8A8_UNORM, // VkFormat format;
4766 { renderSize.x(), renderSize.y(), 1 }, // VkExtent3D extent;
4767 1u, // deUint32 mipLevels;
4768 1u, // deUint32 arraySize;
4769 VK_SAMPLE_COUNT_1_BIT, // deUint32 samples;
4770 VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling;
4771 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT|VK_IMAGE_USAGE_TRANSFER_SRC_BIT, // VkImageUsageFlags usage;
4772 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
4773 1u, // deUint32 queueFamilyCount;
4774 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
4775 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout;
4778 const Unique<VkImage> image (createImage(vk, vkDevice, &imageParams));
4779 const UniquePtr<Allocation> imageMemory (context.getDefaultAllocator().allocate(getImageMemoryRequirements(vk, vkDevice, *image), MemoryRequirement::Any));
4781 VK_CHECK(vk.bindImageMemory(vkDevice, *image, imageMemory->getMemory(), imageMemory->getOffset()));
4783 const VkAttachmentDescription colorAttDesc =
4785 0u, // VkAttachmentDescriptionFlags flags;
4786 VK_FORMAT_R8G8B8A8_UNORM, // VkFormat format;
4787 VK_SAMPLE_COUNT_1_BIT, // deUint32 samples;
4788 VK_ATTACHMENT_LOAD_OP_CLEAR, // VkAttachmentLoadOp loadOp;
4789 VK_ATTACHMENT_STORE_OP_STORE, // VkAttachmentStoreOp storeOp;
4790 VK_ATTACHMENT_LOAD_OP_DONT_CARE, // VkAttachmentLoadOp stencilLoadOp;
4791 VK_ATTACHMENT_STORE_OP_DONT_CARE, // VkAttachmentStoreOp stencilStoreOp;
4792 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout initialLayout;
4793 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout finalLayout;
4795 const VkAttachmentReference colorAttRef =
4797 0u, // deUint32 attachment;
4798 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout layout;
4800 const VkSubpassDescription subpassDesc =
4802 0u, // VkSubpassDescriptionFlags flags;
4803 VK_PIPELINE_BIND_POINT_GRAPHICS, // VkPipelineBindPoint pipelineBindPoint;
4804 0u, // deUint32 inputCount;
4805 DE_NULL, // const VkAttachmentReference* pInputAttachments;
4806 1u, // deUint32 colorCount;
4807 &colorAttRef, // const VkAttachmentReference* pColorAttachments;
4808 DE_NULL, // const VkAttachmentReference* pResolveAttachments;
4809 DE_NULL, // const VkAttachmentReference* pDepthStencilAttachment;
4810 0u, // deUint32 preserveCount;
4811 DE_NULL, // const VkAttachmentReference* pPreserveAttachments;
4814 const VkRenderPassCreateInfo renderPassParams =
4816 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, // VkStructureType sType;
4817 DE_NULL, // const void* pNext;
4818 (VkRenderPassCreateFlags)0,
4819 1u, // deUint32 attachmentCount;
4820 &colorAttDesc, // const VkAttachmentDescription* pAttachments;
4821 1u, // deUint32 subpassCount;
4822 &subpassDesc, // const VkSubpassDescription* pSubpasses;
4823 0u, // deUint32 dependencyCount;
4824 DE_NULL, // const VkSubpassDependency* pDependencies;
4826 const Unique<VkRenderPass> renderPass (createRenderPass(vk, vkDevice, &renderPassParams));
4828 const VkImageViewCreateInfo colorAttViewParams =
4830 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, // VkStructureType sType;
4831 DE_NULL, // const void* pNext;
4832 0u, // VkImageViewCreateFlags flags;
4833 *image, // VkImage image;
4834 VK_IMAGE_VIEW_TYPE_2D, // VkImageViewType viewType;
4835 VK_FORMAT_R8G8B8A8_UNORM, // VkFormat format;
4837 VK_COMPONENT_SWIZZLE_R,
4838 VK_COMPONENT_SWIZZLE_G,
4839 VK_COMPONENT_SWIZZLE_B,
4840 VK_COMPONENT_SWIZZLE_A
4841 }, // VkChannelMapping channels;
4843 VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags aspectMask;
4844 0u, // deUint32 baseMipLevel;
4845 1u, // deUint32 mipLevels;
4846 0u, // deUint32 baseArrayLayer;
4847 1u, // deUint32 arraySize;
4848 }, // VkImageSubresourceRange subresourceRange;
4850 const Unique<VkImageView> colorAttView (createImageView(vk, vkDevice, &colorAttViewParams));
4854 const VkPipelineLayoutCreateInfo pipelineLayoutParams =
4856 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, // VkStructureType sType;
4857 DE_NULL, // const void* pNext;
4858 (VkPipelineLayoutCreateFlags)0,
4859 0u, // deUint32 descriptorSetCount;
4860 DE_NULL, // const VkDescriptorSetLayout* pSetLayouts;
4861 0u, // deUint32 pushConstantRangeCount;
4862 DE_NULL, // const VkPushConstantRange* pPushConstantRanges;
4864 const Unique<VkPipelineLayout> pipelineLayout (createPipelineLayout(vk, vkDevice, &pipelineLayoutParams));
4867 vector<VkPipelineShaderStageCreateInfo> shaderStageParams;
4868 // We need these vectors to make sure that information about specialization constants for each stage can outlive createGraphicsPipeline().
4869 vector<vector<VkSpecializationMapEntry> > specConstantEntries;
4870 vector<VkSpecializationInfo> specializationInfos;
4871 createPipelineShaderStages(vk, vkDevice, instance, context, modules, shaderStageParams);
4873 // And we don't want the reallocation of these vectors to invalidate pointers pointing to their contents.
4874 specConstantEntries.reserve(shaderStageParams.size());
4875 specializationInfos.reserve(shaderStageParams.size());
4877 // Patch the specialization info field in PipelineShaderStageCreateInfos.
4878 for (vector<VkPipelineShaderStageCreateInfo>::iterator stageInfo = shaderStageParams.begin(); stageInfo != shaderStageParams.end(); ++stageInfo)
4880 const StageToSpecConstantMap::const_iterator stageIt = instance.specConstants.find(stageInfo->stage);
4882 if (stageIt != instance.specConstants.end())
4884 const size_t numSpecConstants = stageIt->second.size();
4885 vector<VkSpecializationMapEntry> entries;
4886 VkSpecializationInfo specInfo;
4888 entries.resize(numSpecConstants);
4890 // Only support 32-bit integers as spec constants now. And their constant IDs are numbered sequentially starting from 0.
4891 for (size_t ndx = 0; ndx < numSpecConstants; ++ndx)
4893 entries[ndx].constantID = (deUint32)ndx;
4894 entries[ndx].offset = deUint32(ndx * sizeof(deInt32));
4895 entries[ndx].size = sizeof(deInt32);
4898 specConstantEntries.push_back(entries);
4900 specInfo.mapEntryCount = (deUint32)numSpecConstants;
4901 specInfo.pMapEntries = specConstantEntries.back().data();
4902 specInfo.dataSize = numSpecConstants * sizeof(deInt32);
4903 specInfo.pData = stageIt->second.data();
4904 specializationInfos.push_back(specInfo);
4906 stageInfo->pSpecializationInfo = &specializationInfos.back();
4909 const VkPipelineDepthStencilStateCreateInfo depthStencilParams =
4911 VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO, // VkStructureType sType;
4912 DE_NULL, // const void* pNext;
4913 (VkPipelineDepthStencilStateCreateFlags)0,
4914 DE_FALSE, // deUint32 depthTestEnable;
4915 DE_FALSE, // deUint32 depthWriteEnable;
4916 VK_COMPARE_OP_ALWAYS, // VkCompareOp depthCompareOp;
4917 DE_FALSE, // deUint32 depthBoundsTestEnable;
4918 DE_FALSE, // deUint32 stencilTestEnable;
4920 VK_STENCIL_OP_KEEP, // VkStencilOp stencilFailOp;
4921 VK_STENCIL_OP_KEEP, // VkStencilOp stencilPassOp;
4922 VK_STENCIL_OP_KEEP, // VkStencilOp stencilDepthFailOp;
4923 VK_COMPARE_OP_ALWAYS, // VkCompareOp stencilCompareOp;
4924 0u, // deUint32 stencilCompareMask;
4925 0u, // deUint32 stencilWriteMask;
4926 0u, // deUint32 stencilReference;
4927 }, // VkStencilOpState front;
4929 VK_STENCIL_OP_KEEP, // VkStencilOp stencilFailOp;
4930 VK_STENCIL_OP_KEEP, // VkStencilOp stencilPassOp;
4931 VK_STENCIL_OP_KEEP, // VkStencilOp stencilDepthFailOp;
4932 VK_COMPARE_OP_ALWAYS, // VkCompareOp stencilCompareOp;
4933 0u, // deUint32 stencilCompareMask;
4934 0u, // deUint32 stencilWriteMask;
4935 0u, // deUint32 stencilReference;
4936 }, // VkStencilOpState back;
4937 -1.0f, // float minDepthBounds;
4938 +1.0f, // float maxDepthBounds;
4940 const VkViewport viewport0 =
4942 0.0f, // float originX;
4943 0.0f, // float originY;
4944 (float)renderSize.x(), // float width;
4945 (float)renderSize.y(), // float height;
4946 0.0f, // float minDepth;
4947 1.0f, // float maxDepth;
4949 const VkRect2D scissor0 =
4954 }, // VkOffset2D offset;
4956 renderSize.x(), // deInt32 width;
4957 renderSize.y(), // deInt32 height;
4958 }, // VkExtent2D extent;
4960 const VkPipelineViewportStateCreateInfo viewportParams =
4962 VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO, // VkStructureType sType;
4963 DE_NULL, // const void* pNext;
4964 (VkPipelineViewportStateCreateFlags)0,
4965 1u, // deUint32 viewportCount;
4970 const VkSampleMask sampleMask = ~0u;
4971 const VkPipelineMultisampleStateCreateInfo multisampleParams =
4973 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, // VkStructureType sType;
4974 DE_NULL, // const void* pNext;
4975 (VkPipelineMultisampleStateCreateFlags)0,
4976 VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits rasterSamples;
4977 DE_FALSE, // deUint32 sampleShadingEnable;
4978 0.0f, // float minSampleShading;
4979 &sampleMask, // const VkSampleMask* pSampleMask;
4980 DE_FALSE, // VkBool32 alphaToCoverageEnable;
4981 DE_FALSE, // VkBool32 alphaToOneEnable;
4983 const VkPipelineRasterizationStateCreateInfo rasterParams =
4985 VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO, // VkStructureType sType;
4986 DE_NULL, // const void* pNext;
4987 (VkPipelineRasterizationStateCreateFlags)0,
4988 DE_TRUE, // deUint32 depthClipEnable;
4989 DE_FALSE, // deUint32 rasterizerDiscardEnable;
4990 VK_POLYGON_MODE_FILL, // VkFillMode fillMode;
4991 VK_CULL_MODE_NONE, // VkCullMode cullMode;
4992 VK_FRONT_FACE_COUNTER_CLOCKWISE, // VkFrontFace frontFace;
4993 VK_FALSE, // VkBool32 depthBiasEnable;
4994 0.0f, // float depthBias;
4995 0.0f, // float depthBiasClamp;
4996 0.0f, // float slopeScaledDepthBias;
4997 1.0f, // float lineWidth;
4999 const VkPrimitiveTopology topology = hasTessellation? VK_PRIMITIVE_TOPOLOGY_PATCH_LIST: VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
5000 const VkPipelineInputAssemblyStateCreateInfo inputAssemblyParams =
5002 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, // VkStructureType sType;
5003 DE_NULL, // const void* pNext;
5004 (VkPipelineInputAssemblyStateCreateFlags)0,
5005 topology, // VkPrimitiveTopology topology;
5006 DE_FALSE, // deUint32 primitiveRestartEnable;
5008 const VkVertexInputBindingDescription vertexBinding0 =
5010 0u, // deUint32 binding;
5011 deUint32(singleVertexDataSize), // deUint32 strideInBytes;
5012 VK_VERTEX_INPUT_RATE_VERTEX // VkVertexInputStepRate stepRate;
5014 const VkVertexInputAttributeDescription vertexAttrib0[2] =
5017 0u, // deUint32 location;
5018 0u, // deUint32 binding;
5019 VK_FORMAT_R32G32B32A32_SFLOAT, // VkFormat format;
5020 0u // deUint32 offsetInBytes;
5023 1u, // deUint32 location;
5024 0u, // deUint32 binding;
5025 VK_FORMAT_R32G32B32A32_SFLOAT, // VkFormat format;
5026 sizeof(Vec4), // deUint32 offsetInBytes;
5030 const VkPipelineVertexInputStateCreateInfo vertexInputStateParams =
5032 VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO, // VkStructureType sType;
5033 DE_NULL, // const void* pNext;
5034 (VkPipelineVertexInputStateCreateFlags)0,
5035 1u, // deUint32 bindingCount;
5036 &vertexBinding0, // const VkVertexInputBindingDescription* pVertexBindingDescriptions;
5037 2u, // deUint32 attributeCount;
5038 vertexAttrib0, // const VkVertexInputAttributeDescription* pVertexAttributeDescriptions;
5040 const VkPipelineColorBlendAttachmentState attBlendParams =
5042 DE_FALSE, // deUint32 blendEnable;
5043 VK_BLEND_FACTOR_ONE, // VkBlend srcBlendColor;
5044 VK_BLEND_FACTOR_ZERO, // VkBlend destBlendColor;
5045 VK_BLEND_OP_ADD, // VkBlendOp blendOpColor;
5046 VK_BLEND_FACTOR_ONE, // VkBlend srcBlendAlpha;
5047 VK_BLEND_FACTOR_ZERO, // VkBlend destBlendAlpha;
5048 VK_BLEND_OP_ADD, // VkBlendOp blendOpAlpha;
5049 (VK_COLOR_COMPONENT_R_BIT|
5050 VK_COLOR_COMPONENT_G_BIT|
5051 VK_COLOR_COMPONENT_B_BIT|
5052 VK_COLOR_COMPONENT_A_BIT), // VkChannelFlags channelWriteMask;
5054 const VkPipelineColorBlendStateCreateInfo blendParams =
5056 VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO, // VkStructureType sType;
5057 DE_NULL, // const void* pNext;
5058 (VkPipelineColorBlendStateCreateFlags)0,
5059 DE_FALSE, // VkBool32 logicOpEnable;
5060 VK_LOGIC_OP_COPY, // VkLogicOp logicOp;
5061 1u, // deUint32 attachmentCount;
5062 &attBlendParams, // const VkPipelineColorBlendAttachmentState* pAttachments;
5063 { 0.0f, 0.0f, 0.0f, 0.0f }, // float blendConst[4];
5065 const VkPipelineTessellationStateCreateInfo tessellationState =
5067 VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO,
5069 (VkPipelineTessellationStateCreateFlags)0,
5073 const VkPipelineTessellationStateCreateInfo* tessellationInfo = hasTessellation ? &tessellationState: DE_NULL;
5074 const VkGraphicsPipelineCreateInfo pipelineParams =
5076 VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO, // VkStructureType sType;
5077 DE_NULL, // const void* pNext;
5078 0u, // VkPipelineCreateFlags flags;
5079 (deUint32)shaderStageParams.size(), // deUint32 stageCount;
5080 &shaderStageParams[0], // const VkPipelineShaderStageCreateInfo* pStages;
5081 &vertexInputStateParams, // const VkPipelineVertexInputStateCreateInfo* pVertexInputState;
5082 &inputAssemblyParams, // const VkPipelineInputAssemblyStateCreateInfo* pInputAssemblyState;
5083 tessellationInfo, // const VkPipelineTessellationStateCreateInfo* pTessellationState;
5084 &viewportParams, // const VkPipelineViewportStateCreateInfo* pViewportState;
5085 &rasterParams, // const VkPipelineRasterStateCreateInfo* pRasterState;
5086 &multisampleParams, // const VkPipelineMultisampleStateCreateInfo* pMultisampleState;
5087 &depthStencilParams, // const VkPipelineDepthStencilStateCreateInfo* pDepthStencilState;
5088 &blendParams, // const VkPipelineColorBlendStateCreateInfo* pColorBlendState;
5089 (const VkPipelineDynamicStateCreateInfo*)DE_NULL, // const VkPipelineDynamicStateCreateInfo* pDynamicState;
5090 *pipelineLayout, // VkPipelineLayout layout;
5091 *renderPass, // VkRenderPass renderPass;
5092 0u, // deUint32 subpass;
5093 DE_NULL, // VkPipeline basePipelineHandle;
5094 0u, // deInt32 basePipelineIndex;
5097 const Unique<VkPipeline> pipeline (createGraphicsPipeline(vk, vkDevice, DE_NULL, &pipelineParams));
5100 const VkFramebufferCreateInfo framebufferParams =
5102 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, // VkStructureType sType;
5103 DE_NULL, // const void* pNext;
5104 (VkFramebufferCreateFlags)0,
5105 *renderPass, // VkRenderPass renderPass;
5106 1u, // deUint32 attachmentCount;
5107 &*colorAttView, // const VkImageView* pAttachments;
5108 (deUint32)renderSize.x(), // deUint32 width;
5109 (deUint32)renderSize.y(), // deUint32 height;
5110 1u, // deUint32 layers;
5112 const Unique<VkFramebuffer> framebuffer (createFramebuffer(vk, vkDevice, &framebufferParams));
5114 const VkCommandPoolCreateInfo cmdPoolParams =
5116 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // VkStructureType sType;
5117 DE_NULL, // const void* pNext;
5118 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // VkCmdPoolCreateFlags flags;
5119 queueFamilyIndex, // deUint32 queueFamilyIndex;
5121 const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams));
5124 const VkCommandBufferAllocateInfo cmdBufParams =
5126 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType;
5127 DE_NULL, // const void* pNext;
5128 *cmdPool, // VkCmdPool pool;
5129 VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCmdBufferLevel level;
5130 1u, // deUint32 count;
5132 const Unique<VkCommandBuffer> cmdBuf (allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
5134 const VkCommandBufferBeginInfo cmdBufBeginParams =
5136 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType;
5137 DE_NULL, // const void* pNext;
5138 (VkCommandBufferUsageFlags)0,
5139 (const VkCommandBufferInheritanceInfo*)DE_NULL,
5143 VK_CHECK(vk.beginCommandBuffer(*cmdBuf, &cmdBufBeginParams));
5146 const VkMemoryBarrier vertFlushBarrier =
5148 VK_STRUCTURE_TYPE_MEMORY_BARRIER, // VkStructureType sType;
5149 DE_NULL, // const void* pNext;
5150 VK_ACCESS_HOST_WRITE_BIT, // VkMemoryOutputFlags outputMask;
5151 VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT, // VkMemoryInputFlags inputMask;
5153 const VkImageMemoryBarrier colorAttBarrier =
5155 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
5156 DE_NULL, // const void* pNext;
5157 0u, // VkMemoryOutputFlags outputMask;
5158 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, // VkMemoryInputFlags inputMask;
5159 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout oldLayout;
5160 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout newLayout;
5161 queueFamilyIndex, // deUint32 srcQueueFamilyIndex;
5162 queueFamilyIndex, // deUint32 destQueueFamilyIndex;
5163 *image, // VkImage image;
5165 VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspect aspect;
5166 0u, // deUint32 baseMipLevel;
5167 1u, // deUint32 mipLevels;
5168 0u, // deUint32 baseArraySlice;
5169 1u, // deUint32 arraySize;
5170 } // VkImageSubresourceRange subresourceRange;
5172 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);
5176 const VkClearValue clearValue = makeClearValueColorF32(0.125f, 0.25f, 0.75f, 1.0f);
5177 const VkRenderPassBeginInfo passBeginParams =
5179 VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, // VkStructureType sType;
5180 DE_NULL, // const void* pNext;
5181 *renderPass, // VkRenderPass renderPass;
5182 *framebuffer, // VkFramebuffer framebuffer;
5183 { { 0, 0 }, { renderSize.x(), renderSize.y() } }, // VkRect2D renderArea;
5184 1u, // deUint32 clearValueCount;
5185 &clearValue, // const VkClearValue* pClearValues;
5187 vk.cmdBeginRenderPass(*cmdBuf, &passBeginParams, VK_SUBPASS_CONTENTS_INLINE);
5190 vk.cmdBindPipeline(*cmdBuf, VK_PIPELINE_BIND_POINT_GRAPHICS, *pipeline);
5192 const VkDeviceSize bindingOffset = 0;
5193 vk.cmdBindVertexBuffers(*cmdBuf, 0u, 1u, &vertexBuffer.get(), &bindingOffset);
5195 vk.cmdDraw(*cmdBuf, deUint32(vertexCount), 1u /*run pipeline once*/, 0u /*first vertex*/, 0u /*first instanceIndex*/);
5196 vk.cmdEndRenderPass(*cmdBuf);
5199 const VkImageMemoryBarrier renderFinishBarrier =
5201 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
5202 DE_NULL, // const void* pNext;
5203 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, // VkMemoryOutputFlags outputMask;
5204 VK_ACCESS_TRANSFER_READ_BIT, // VkMemoryInputFlags inputMask;
5205 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout oldLayout;
5206 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, // VkImageLayout newLayout;
5207 queueFamilyIndex, // deUint32 srcQueueFamilyIndex;
5208 queueFamilyIndex, // deUint32 destQueueFamilyIndex;
5209 *image, // VkImage image;
5211 VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags aspectMask;
5212 0u, // deUint32 baseMipLevel;
5213 1u, // deUint32 mipLevels;
5214 0u, // deUint32 baseArraySlice;
5215 1u, // deUint32 arraySize;
5216 } // VkImageSubresourceRange subresourceRange;
5218 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);
5222 const VkBufferImageCopy copyParams =
5224 (VkDeviceSize)0u, // VkDeviceSize bufferOffset;
5225 (deUint32)renderSize.x(), // deUint32 bufferRowLength;
5226 (deUint32)renderSize.y(), // deUint32 bufferImageHeight;
5228 VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspect aspect;
5229 0u, // deUint32 mipLevel;
5230 0u, // deUint32 arrayLayer;
5231 1u, // deUint32 arraySize;
5232 }, // VkImageSubresourceCopy imageSubresource;
5233 { 0u, 0u, 0u }, // VkOffset3D imageOffset;
5234 { renderSize.x(), renderSize.y(), 1u } // VkExtent3D imageExtent;
5236 vk.cmdCopyImageToBuffer(*cmdBuf, *image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, *readImageBuffer, 1u, ©Params);
5240 const VkBufferMemoryBarrier copyFinishBarrier =
5242 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER, // VkStructureType sType;
5243 DE_NULL, // const void* pNext;
5244 VK_ACCESS_TRANSFER_WRITE_BIT, // VkMemoryOutputFlags outputMask;
5245 VK_ACCESS_HOST_READ_BIT, // VkMemoryInputFlags inputMask;
5246 queueFamilyIndex, // deUint32 srcQueueFamilyIndex;
5247 queueFamilyIndex, // deUint32 destQueueFamilyIndex;
5248 *readImageBuffer, // VkBuffer buffer;
5249 0u, // VkDeviceSize offset;
5250 imageSizeBytes // VkDeviceSize size;
5252 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);
5255 VK_CHECK(vk.endCommandBuffer(*cmdBuf));
5257 // Upload vertex data
5259 const VkMappedMemoryRange range =
5261 VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE, // VkStructureType sType;
5262 DE_NULL, // const void* pNext;
5263 vertexBufferMemory->getMemory(), // VkDeviceMemory mem;
5264 0, // VkDeviceSize offset;
5265 (VkDeviceSize)sizeof(vertexData), // VkDeviceSize size;
5267 void* vertexBufPtr = vertexBufferMemory->getHostPtr();
5269 deMemcpy(vertexBufPtr, &vertexData[0], sizeof(vertexData));
5270 VK_CHECK(vk.flushMappedMemoryRanges(vkDevice, 1u, &range));
5273 // Submit & wait for completion
5275 const VkFenceCreateInfo fenceParams =
5277 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, // VkStructureType sType;
5278 DE_NULL, // const void* pNext;
5279 0u, // VkFenceCreateFlags flags;
5281 const Unique<VkFence> fence (createFence(vk, vkDevice, &fenceParams));
5282 const VkSubmitInfo submitInfo =
5284 VK_STRUCTURE_TYPE_SUBMIT_INFO,
5287 (const VkSemaphore*)DE_NULL,
5288 (const VkPipelineStageFlags*)DE_NULL,
5292 (const VkSemaphore*)DE_NULL,
5295 VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence));
5296 VK_CHECK(vk.waitForFences(vkDevice, 1u, &fence.get(), DE_TRUE, ~0ull));
5299 const void* imagePtr = readImageBufferMemory->getHostPtr();
5300 const tcu::ConstPixelBufferAccess pixelBuffer(tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8),
5301 renderSize.x(), renderSize.y(), 1, imagePtr);
5304 const VkMappedMemoryRange range =
5306 VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE, // VkStructureType sType;
5307 DE_NULL, // const void* pNext;
5308 readImageBufferMemory->getMemory(), // VkDeviceMemory mem;
5309 0, // VkDeviceSize offset;
5310 imageSizeBytes, // VkDeviceSize size;
5313 VK_CHECK(vk.invalidateMappedMemoryRanges(vkDevice, 1u, &range));
5314 context.getTestContext().getLog() << TestLog::Image("Result", "Result", pixelBuffer);
5317 const RGBA threshold(1, 1, 1, 1);
5318 const RGBA upperLeft(pixelBuffer.getPixel(1, 1));
5319 if (!tcu::compareThreshold(upperLeft, instance.outputColors[0], threshold))
5320 return TestStatus::fail("Upper left corner mismatch");
5322 const RGBA upperRight(pixelBuffer.getPixel(pixelBuffer.getWidth() - 1, 1));
5323 if (!tcu::compareThreshold(upperRight, instance.outputColors[1], threshold))
5324 return TestStatus::fail("Upper right corner mismatch");
5326 const RGBA lowerLeft(pixelBuffer.getPixel(1, pixelBuffer.getHeight() - 1));
5327 if (!tcu::compareThreshold(lowerLeft, instance.outputColors[2], threshold))
5328 return TestStatus::fail("Lower left corner mismatch");
5330 const RGBA lowerRight(pixelBuffer.getPixel(pixelBuffer.getWidth() - 1, pixelBuffer.getHeight() - 1));
5331 if (!tcu::compareThreshold(lowerRight, instance.outputColors[3], threshold))
5332 return TestStatus::fail("Lower right corner mismatch");
5334 return TestStatus::pass("Rendered output matches input");
5337 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)
5339 const ShaderElement vertFragPipelineStages[] =
5341 ShaderElement("vert", "main", VK_SHADER_STAGE_VERTEX_BIT),
5342 ShaderElement("frag", "main", VK_SHADER_STAGE_FRAGMENT_BIT),
5345 const ShaderElement tessPipelineStages[] =
5347 ShaderElement("vert", "main", VK_SHADER_STAGE_VERTEX_BIT),
5348 ShaderElement("tessc", "main", VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT),
5349 ShaderElement("tesse", "main", VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT),
5350 ShaderElement("frag", "main", VK_SHADER_STAGE_FRAGMENT_BIT),
5353 const ShaderElement geomPipelineStages[] =
5355 ShaderElement("vert", "main", VK_SHADER_STAGE_VERTEX_BIT),
5356 ShaderElement("geom", "main", VK_SHADER_STAGE_GEOMETRY_BIT),
5357 ShaderElement("frag", "main", VK_SHADER_STAGE_FRAGMENT_BIT),
5360 StageToSpecConstantMap specConstantMap;
5362 specConstantMap[VK_SHADER_STAGE_VERTEX_BIT] = specConstants;
5363 addFunctionCaseWithPrograms<InstanceContext>(tests, name + "_vert", "", addShaderCodeCustomVertex, runAndVerifyDefaultPipeline,
5364 createInstanceContext(vertFragPipelineStages, inputColors, outputColors, testCodeFragments, specConstantMap));
5366 specConstantMap.clear();
5367 specConstantMap[VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT] = specConstants;
5368 addFunctionCaseWithPrograms<InstanceContext>(tests, name + "_tessc", "", addShaderCodeCustomTessControl, runAndVerifyDefaultPipeline,
5369 createInstanceContext(tessPipelineStages, inputColors, outputColors, testCodeFragments, specConstantMap));
5371 specConstantMap.clear();
5372 specConstantMap[VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT] = specConstants;
5373 addFunctionCaseWithPrograms<InstanceContext>(tests, name + "_tesse", "", addShaderCodeCustomTessEval, runAndVerifyDefaultPipeline,
5374 createInstanceContext(tessPipelineStages, inputColors, outputColors, testCodeFragments, specConstantMap));
5376 specConstantMap.clear();
5377 specConstantMap[VK_SHADER_STAGE_GEOMETRY_BIT] = specConstants;
5378 addFunctionCaseWithPrograms<InstanceContext>(tests, name + "_geom", "", addShaderCodeCustomGeometry, runAndVerifyDefaultPipeline,
5379 createInstanceContext(geomPipelineStages, inputColors, outputColors, testCodeFragments, specConstantMap));
5381 specConstantMap.clear();
5382 specConstantMap[VK_SHADER_STAGE_FRAGMENT_BIT] = specConstants;
5383 addFunctionCaseWithPrograms<InstanceContext>(tests, name + "_frag", "", addShaderCodeCustomFragment, runAndVerifyDefaultPipeline,
5384 createInstanceContext(vertFragPipelineStages, inputColors, outputColors, testCodeFragments, specConstantMap));
5387 inline void createTestsForAllStages (const std::string& name, const RGBA (&inputColors)[4], const RGBA (&outputColors)[4], const map<string, string>& testCodeFragments, tcu::TestCaseGroup* tests)
5389 vector<deInt32> noSpecConstants;
5390 createTestsForAllStages(name, inputColors, outputColors, testCodeFragments, noSpecConstants, tests);
5395 tcu::TestCaseGroup* createOpSourceTests (tcu::TestContext& testCtx)
5397 struct NameCodePair { string name, code; };
5398 RGBA defaultColors[4];
5399 de::MovePtr<tcu::TestCaseGroup> opSourceTests (new tcu::TestCaseGroup(testCtx, "opsource", "OpSource instruction"));
5400 const std::string opsourceGLSLWithFile = "%opsrcfile = OpString \"foo.vert\"\nOpSource GLSL 450 %opsrcfile ";
5401 map<string, string> fragments = passthruFragments();
5402 const NameCodePair tests[] =
5404 {"unknown", "OpSource Unknown 321"},
5405 {"essl", "OpSource ESSL 310"},
5406 {"glsl", "OpSource GLSL 450"},
5407 {"opencl_cpp", "OpSource OpenCL_CPP 120"},
5408 {"opencl_c", "OpSource OpenCL_C 120"},
5409 {"multiple", "OpSource GLSL 450\nOpSource GLSL 450"},
5410 {"file", opsourceGLSLWithFile},
5411 {"source", opsourceGLSLWithFile + "\"void main(){}\""},
5412 // Longest possible source string: SPIR-V limits instructions to 65535
5413 // words, of which the first 4 are opsourceGLSLWithFile; the rest will
5414 // contain 65530 UTF8 characters (one word each) plus one last word
5415 // containing 3 ASCII characters and \0.
5416 {"longsource", opsourceGLSLWithFile + '"' + makeLongUTF8String(65530) + "ccc" + '"'}
5419 getDefaultColors(defaultColors);
5420 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameCodePair); ++testNdx)
5422 fragments["debug"] = tests[testNdx].code;
5423 createTestsForAllStages(tests[testNdx].name, defaultColors, defaultColors, fragments, opSourceTests.get());
5426 return opSourceTests.release();
5429 tcu::TestCaseGroup* createOpSourceContinuedTests (tcu::TestContext& testCtx)
5431 struct NameCodePair { string name, code; };
5432 RGBA defaultColors[4];
5433 de::MovePtr<tcu::TestCaseGroup> opSourceTests (new tcu::TestCaseGroup(testCtx, "opsourcecontinued", "OpSourceContinued instruction"));
5434 map<string, string> fragments = passthruFragments();
5435 const std::string opsource = "%opsrcfile = OpString \"foo.vert\"\nOpSource GLSL 450 %opsrcfile \"void main(){}\"\n";
5436 const NameCodePair tests[] =
5438 {"empty", opsource + "OpSourceContinued \"\""},
5439 {"short", opsource + "OpSourceContinued \"abcde\""},
5440 {"multiple", opsource + "OpSourceContinued \"abcde\"\nOpSourceContinued \"fghij\""},
5441 // Longest possible source string: SPIR-V limits instructions to 65535
5442 // words, of which the first one is OpSourceContinued/length; the rest
5443 // will contain 65533 UTF8 characters (one word each) plus one last word
5444 // containing 3 ASCII characters and \0.
5445 {"long", opsource + "OpSourceContinued \"" + makeLongUTF8String(65533) + "ccc\""}
5448 getDefaultColors(defaultColors);
5449 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameCodePair); ++testNdx)
5451 fragments["debug"] = tests[testNdx].code;
5452 createTestsForAllStages(tests[testNdx].name, defaultColors, defaultColors, fragments, opSourceTests.get());
5455 return opSourceTests.release();
5458 tcu::TestCaseGroup* createOpNoLineTests(tcu::TestContext& testCtx)
5460 RGBA defaultColors[4];
5461 de::MovePtr<tcu::TestCaseGroup> opLineTests (new tcu::TestCaseGroup(testCtx, "opnoline", "OpNoLine instruction"));
5462 map<string, string> fragments;
5463 getDefaultColors(defaultColors);
5464 fragments["debug"] =
5465 "%name = OpString \"name\"\n";
5467 fragments["pre_main"] =
5470 "OpLine %name 1 1\n"
5472 "OpLine %name 1 1\n"
5473 "OpLine %name 1 1\n"
5474 "%second_function = OpFunction %v4f32 None %v4f32_function\n"
5476 "OpLine %name 1 1\n"
5478 "OpLine %name 1 1\n"
5479 "OpLine %name 1 1\n"
5480 "%second_param1 = OpFunctionParameter %v4f32\n"
5483 "%label_secondfunction = OpLabel\n"
5485 "OpReturnValue %second_param1\n"
5490 fragments["testfun"] =
5491 // A %test_code function that returns its argument unchanged.
5494 "OpLine %name 1 1\n"
5495 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5497 "%param1 = OpFunctionParameter %v4f32\n"
5500 "%label_testfun = OpLabel\n"
5502 "%val1 = OpFunctionCall %v4f32 %second_function %param1\n"
5503 "OpReturnValue %val1\n"
5505 "OpLine %name 1 1\n"
5508 createTestsForAllStages("opnoline", defaultColors, defaultColors, fragments, opLineTests.get());
5510 return opLineTests.release();
5514 tcu::TestCaseGroup* createOpLineTests(tcu::TestContext& testCtx)
5516 RGBA defaultColors[4];
5517 de::MovePtr<tcu::TestCaseGroup> opLineTests (new tcu::TestCaseGroup(testCtx, "opline", "OpLine instruction"));
5518 map<string, string> fragments;
5519 std::vector<std::pair<std::string, std::string> > problemStrings;
5521 problemStrings.push_back(std::make_pair<std::string, std::string>("empty_name", ""));
5522 problemStrings.push_back(std::make_pair<std::string, std::string>("short_name", "short_name"));
5523 problemStrings.push_back(std::make_pair<std::string, std::string>("long_name", makeLongUTF8String(65530) + "ccc"));
5524 getDefaultColors(defaultColors);
5526 fragments["debug"] =
5527 "%other_name = OpString \"other_name\"\n";
5529 fragments["pre_main"] =
5530 "OpLine %file_name 32 0\n"
5531 "OpLine %file_name 32 32\n"
5532 "OpLine %file_name 32 40\n"
5533 "OpLine %other_name 32 40\n"
5534 "OpLine %other_name 0 100\n"
5535 "OpLine %other_name 0 4294967295\n"
5536 "OpLine %other_name 4294967295 0\n"
5537 "OpLine %other_name 32 40\n"
5538 "OpLine %file_name 0 0\n"
5539 "%second_function = OpFunction %v4f32 None %v4f32_function\n"
5540 "OpLine %file_name 1 0\n"
5541 "%second_param1 = OpFunctionParameter %v4f32\n"
5542 "OpLine %file_name 1 3\n"
5543 "OpLine %file_name 1 2\n"
5544 "%label_secondfunction = OpLabel\n"
5545 "OpLine %file_name 0 2\n"
5546 "OpReturnValue %second_param1\n"
5548 "OpLine %file_name 0 2\n"
5549 "OpLine %file_name 0 2\n";
5551 fragments["testfun"] =
5552 // A %test_code function that returns its argument unchanged.
5553 "OpLine %file_name 1 0\n"
5554 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5555 "OpLine %file_name 16 330\n"
5556 "%param1 = OpFunctionParameter %v4f32\n"
5557 "OpLine %file_name 14 442\n"
5558 "%label_testfun = OpLabel\n"
5559 "OpLine %file_name 11 1024\n"
5560 "%val1 = OpFunctionCall %v4f32 %second_function %param1\n"
5561 "OpLine %file_name 2 97\n"
5562 "OpReturnValue %val1\n"
5564 "OpLine %file_name 5 32\n";
5566 for (size_t i = 0; i < problemStrings.size(); ++i)
5568 map<string, string> testFragments = fragments;
5569 testFragments["debug"] += "%file_name = OpString \"" + problemStrings[i].second + "\"\n";
5570 createTestsForAllStages(string("opline") + "_" + problemStrings[i].first, defaultColors, defaultColors, testFragments, opLineTests.get());
5573 return opLineTests.release();
5576 tcu::TestCaseGroup* createOpConstantNullTests(tcu::TestContext& testCtx)
5578 de::MovePtr<tcu::TestCaseGroup> opConstantNullTests (new tcu::TestCaseGroup(testCtx, "opconstantnull", "OpConstantNull instruction"));
5582 const char functionStart[] =
5583 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5584 "%param1 = OpFunctionParameter %v4f32\n"
5587 const char functionEnd[] =
5588 "OpReturnValue %transformed_param\n"
5591 struct NameConstantsCode
5598 NameConstantsCode tests[] =
5602 "%cnull = OpConstantNull %v4f32\n",
5603 "%transformed_param = OpFAdd %v4f32 %param1 %cnull\n"
5607 "%cnull = OpConstantNull %f32\n",
5608 "%vp = OpVariable %fp_v4f32 Function\n"
5609 "%v = OpLoad %v4f32 %vp\n"
5610 "%v0 = OpVectorInsertDynamic %v4f32 %v %cnull %c_i32_0\n"
5611 "%v1 = OpVectorInsertDynamic %v4f32 %v0 %cnull %c_i32_1\n"
5612 "%v2 = OpVectorInsertDynamic %v4f32 %v1 %cnull %c_i32_2\n"
5613 "%v3 = OpVectorInsertDynamic %v4f32 %v2 %cnull %c_i32_3\n"
5614 "%transformed_param = OpFAdd %v4f32 %param1 %v3\n"
5618 "%cnull = OpConstantNull %bool\n",
5619 "%v = OpVariable %fp_v4f32 Function\n"
5620 " OpStore %v %param1\n"
5621 " OpSelectionMerge %false_label None\n"
5622 " OpBranchConditional %cnull %true_label %false_label\n"
5623 "%true_label = OpLabel\n"
5624 " OpStore %v %c_v4f32_0_5_0_5_0_5_0_5\n"
5625 " OpBranch %false_label\n"
5626 "%false_label = OpLabel\n"
5627 "%transformed_param = OpLoad %v4f32 %v\n"
5631 "%cnull = OpConstantNull %i32\n",
5632 "%v = OpVariable %fp_v4f32 Function %c_v4f32_0_5_0_5_0_5_0_5\n"
5633 "%b = OpIEqual %bool %cnull %c_i32_0\n"
5634 " OpSelectionMerge %false_label None\n"
5635 " OpBranchConditional %b %true_label %false_label\n"
5636 "%true_label = OpLabel\n"
5637 " OpStore %v %param1\n"
5638 " OpBranch %false_label\n"
5639 "%false_label = OpLabel\n"
5640 "%transformed_param = OpLoad %v4f32 %v\n"
5644 "%stype = OpTypeStruct %f32 %v4f32\n"
5645 "%fp_stype = OpTypePointer Function %stype\n"
5646 "%cnull = OpConstantNull %stype\n",
5647 "%v = OpVariable %fp_stype Function %cnull\n"
5648 "%f = OpAccessChain %fp_v4f32 %v %c_i32_1\n"
5649 "%f_val = OpLoad %v4f32 %f\n"
5650 "%transformed_param = OpFAdd %v4f32 %param1 %f_val\n"
5654 "%a4_v4f32 = OpTypeArray %v4f32 %c_u32_4\n"
5655 "%fp_a4_v4f32 = OpTypePointer Function %a4_v4f32\n"
5656 "%cnull = OpConstantNull %a4_v4f32\n",
5657 "%v = OpVariable %fp_a4_v4f32 Function %cnull\n"
5658 "%f = OpAccessChain %fp_v4f32 %v %c_u32_0\n"
5659 "%f1 = OpAccessChain %fp_v4f32 %v %c_u32_1\n"
5660 "%f2 = OpAccessChain %fp_v4f32 %v %c_u32_2\n"
5661 "%f3 = OpAccessChain %fp_v4f32 %v %c_u32_3\n"
5662 "%f_val = OpLoad %v4f32 %f\n"
5663 "%f1_val = OpLoad %v4f32 %f1\n"
5664 "%f2_val = OpLoad %v4f32 %f2\n"
5665 "%f3_val = OpLoad %v4f32 %f3\n"
5666 "%t0 = OpFAdd %v4f32 %param1 %f_val\n"
5667 "%t1 = OpFAdd %v4f32 %t0 %f1_val\n"
5668 "%t2 = OpFAdd %v4f32 %t1 %f2_val\n"
5669 "%transformed_param = OpFAdd %v4f32 %t2 %f3_val\n"
5673 "%mat4x4_f32 = OpTypeMatrix %v4f32 4\n"
5674 "%cnull = OpConstantNull %mat4x4_f32\n",
5675 // Our null matrix * any vector should result in a zero vector.
5676 "%v = OpVectorTimesMatrix %v4f32 %param1 %cnull\n"
5677 "%transformed_param = OpFAdd %v4f32 %param1 %v\n"
5681 getHalfColorsFullAlpha(colors);
5683 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameConstantsCode); ++testNdx)
5685 map<string, string> fragments;
5686 fragments["pre_main"] = tests[testNdx].constants;
5687 fragments["testfun"] = string(functionStart) + tests[testNdx].code + functionEnd;
5688 createTestsForAllStages(tests[testNdx].name, colors, colors, fragments, opConstantNullTests.get());
5690 return opConstantNullTests.release();
5692 tcu::TestCaseGroup* createOpConstantCompositeTests(tcu::TestContext& testCtx)
5694 de::MovePtr<tcu::TestCaseGroup> opConstantCompositeTests (new tcu::TestCaseGroup(testCtx, "opconstantcomposite", "OpConstantComposite instruction"));
5695 RGBA inputColors[4];
5696 RGBA outputColors[4];
5699 const char functionStart[] =
5700 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5701 "%param1 = OpFunctionParameter %v4f32\n"
5704 const char functionEnd[] =
5705 "OpReturnValue %transformed_param\n"
5708 struct NameConstantsCode
5715 NameConstantsCode tests[] =
5720 "%cval = OpConstantComposite %v4f32 %c_f32_0_5 %c_f32_0_5 %c_f32_0_5 %c_f32_0\n",
5721 "%transformed_param = OpFAdd %v4f32 %param1 %cval\n"
5726 "%stype = OpTypeStruct %v4f32 %f32\n"
5727 "%fp_stype = OpTypePointer Function %stype\n"
5728 "%f32_n_1 = OpConstant %f32 -1.0\n"
5729 "%f32_1_5 = OpConstant %f32 !0x3fc00000\n" // +1.5
5730 "%cvec = OpConstantComposite %v4f32 %f32_1_5 %f32_1_5 %f32_1_5 %c_f32_1\n"
5731 "%cval = OpConstantComposite %stype %cvec %f32_n_1\n",
5733 "%v = OpVariable %fp_stype Function %cval\n"
5734 "%vec_ptr = OpAccessChain %fp_v4f32 %v %c_u32_0\n"
5735 "%f32_ptr = OpAccessChain %fp_f32 %v %c_u32_1\n"
5736 "%vec_val = OpLoad %v4f32 %vec_ptr\n"
5737 "%f32_val = OpLoad %f32 %f32_ptr\n"
5738 "%tmp1 = OpVectorTimesScalar %v4f32 %c_v4f32_1_1_1_1 %f32_val\n" // vec4(-1)
5739 "%tmp2 = OpFAdd %v4f32 %tmp1 %param1\n" // param1 + vec4(-1)
5740 "%transformed_param = OpFAdd %v4f32 %tmp2 %vec_val\n" // param1 + vec4(-1) + vec4(1.5, 1.5, 1.5, 1.0)
5743 // [1|0|0|0.5] [x] = x + 0.5
5744 // [0|1|0|0.5] [y] = y + 0.5
5745 // [0|0|1|0.5] [z] = z + 0.5
5746 // [0|0|0|1 ] [1] = 1
5749 "%mat4x4_f32 = OpTypeMatrix %v4f32 4\n"
5750 "%v4f32_1_0_0_0 = OpConstantComposite %v4f32 %c_f32_1 %c_f32_0 %c_f32_0 %c_f32_0\n"
5751 "%v4f32_0_1_0_0 = OpConstantComposite %v4f32 %c_f32_0 %c_f32_1 %c_f32_0 %c_f32_0\n"
5752 "%v4f32_0_0_1_0 = OpConstantComposite %v4f32 %c_f32_0 %c_f32_0 %c_f32_1 %c_f32_0\n"
5753 "%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"
5754 "%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",
5756 "%transformed_param = OpMatrixTimesVector %v4f32 %cval %param1\n"
5761 "%c_v4f32_1_1_1_0 = OpConstantComposite %v4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_0\n"
5762 "%fp_a4f32 = OpTypePointer Function %a4f32\n"
5763 "%f32_n_1 = OpConstant %f32 -1.0\n"
5764 "%f32_1_5 = OpConstant %f32 !0x3fc00000\n" // +1.5
5765 "%carr = OpConstantComposite %a4f32 %c_f32_0 %f32_n_1 %f32_1_5 %c_f32_0\n",
5767 "%v = OpVariable %fp_a4f32 Function %carr\n"
5768 "%f = OpAccessChain %fp_f32 %v %c_u32_0\n"
5769 "%f1 = OpAccessChain %fp_f32 %v %c_u32_1\n"
5770 "%f2 = OpAccessChain %fp_f32 %v %c_u32_2\n"
5771 "%f3 = OpAccessChain %fp_f32 %v %c_u32_3\n"
5772 "%f_val = OpLoad %f32 %f\n"
5773 "%f1_val = OpLoad %f32 %f1\n"
5774 "%f2_val = OpLoad %f32 %f2\n"
5775 "%f3_val = OpLoad %f32 %f3\n"
5776 "%ftot1 = OpFAdd %f32 %f_val %f1_val\n"
5777 "%ftot2 = OpFAdd %f32 %ftot1 %f2_val\n"
5778 "%ftot3 = OpFAdd %f32 %ftot2 %f3_val\n" // 0 - 1 + 1.5 + 0
5779 "%add_vec = OpVectorTimesScalar %v4f32 %c_v4f32_1_1_1_0 %ftot3\n"
5780 "%transformed_param = OpFAdd %v4f32 %param1 %add_vec\n"
5787 // [ 1.0, 1.0, 1.0, 1.0]
5791 // [ 0.0, 0.5, 0.0, 0.0]
5795 // [ 1.0, 1.0, 1.0, 1.0]
5798 "array_of_struct_of_array",
5800 "%c_v4f32_1_1_1_0 = OpConstantComposite %v4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_0\n"
5801 "%fp_a4f32 = OpTypePointer Function %a4f32\n"
5802 "%stype = OpTypeStruct %f32 %a4f32\n"
5803 "%a3stype = OpTypeArray %stype %c_u32_3\n"
5804 "%fp_a3stype = OpTypePointer Function %a3stype\n"
5805 "%ca4f32_0 = OpConstantComposite %a4f32 %c_f32_0 %c_f32_0_5 %c_f32_0 %c_f32_0\n"
5806 "%ca4f32_1 = OpConstantComposite %a4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_1\n"
5807 "%cstype1 = OpConstantComposite %stype %c_f32_0 %ca4f32_1\n"
5808 "%cstype2 = OpConstantComposite %stype %c_f32_1 %ca4f32_0\n"
5809 "%carr = OpConstantComposite %a3stype %cstype1 %cstype2 %cstype1",
5811 "%v = OpVariable %fp_a3stype Function %carr\n"
5812 "%f = OpAccessChain %fp_f32 %v %c_u32_1 %c_u32_1 %c_u32_1\n"
5813 "%f_l = OpLoad %f32 %f\n"
5814 "%add_vec = OpVectorTimesScalar %v4f32 %c_v4f32_1_1_1_0 %f_l\n"
5815 "%transformed_param = OpFAdd %v4f32 %param1 %add_vec\n"
5819 getHalfColorsFullAlpha(inputColors);
5820 outputColors[0] = RGBA(255, 255, 255, 255);
5821 outputColors[1] = RGBA(255, 127, 127, 255);
5822 outputColors[2] = RGBA(127, 255, 127, 255);
5823 outputColors[3] = RGBA(127, 127, 255, 255);
5825 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameConstantsCode); ++testNdx)
5827 map<string, string> fragments;
5828 fragments["pre_main"] = tests[testNdx].constants;
5829 fragments["testfun"] = string(functionStart) + tests[testNdx].code + functionEnd;
5830 createTestsForAllStages(tests[testNdx].name, inputColors, outputColors, fragments, opConstantCompositeTests.get());
5832 return opConstantCompositeTests.release();
5835 tcu::TestCaseGroup* createSelectionBlockOrderTests(tcu::TestContext& testCtx)
5837 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "selection_block_order", "Out-of-order blocks for selection"));
5838 RGBA inputColors[4];
5839 RGBA outputColors[4];
5840 map<string, string> fragments;
5842 // vec4 test_code(vec4 param) {
5843 // vec4 result = param;
5844 // for (int i = 0; i < 4; ++i) {
5845 // if (i == 0) result[i] = 0.;
5846 // else result[i] = 1. - result[i];
5850 const char function[] =
5851 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5852 "%param1 = OpFunctionParameter %v4f32\n"
5854 "%iptr = OpVariable %fp_i32 Function\n"
5855 "%result = OpVariable %fp_v4f32 Function\n"
5856 " OpStore %iptr %c_i32_0\n"
5857 " OpStore %result %param1\n"
5860 // Loop entry block.
5862 "%ival = OpLoad %i32 %iptr\n"
5863 "%lt_4 = OpSLessThan %bool %ival %c_i32_4\n"
5864 " OpLoopMerge %exit %loop None\n"
5865 " OpBranchConditional %lt_4 %if_entry %exit\n"
5867 // Merge block for loop.
5869 "%ret = OpLoad %v4f32 %result\n"
5870 " OpReturnValue %ret\n"
5872 // If-statement entry block.
5873 "%if_entry = OpLabel\n"
5874 "%loc = OpAccessChain %fp_f32 %result %ival\n"
5875 "%eq_0 = OpIEqual %bool %ival %c_i32_0\n"
5876 " OpSelectionMerge %if_exit None\n"
5877 " OpBranchConditional %eq_0 %if_true %if_false\n"
5879 // False branch for if-statement.
5880 "%if_false = OpLabel\n"
5881 "%val = OpLoad %f32 %loc\n"
5882 "%sub = OpFSub %f32 %c_f32_1 %val\n"
5883 " OpStore %loc %sub\n"
5884 " OpBranch %if_exit\n"
5886 // Merge block for if-statement.
5887 "%if_exit = OpLabel\n"
5888 "%ival_next = OpIAdd %i32 %ival %c_i32_1\n"
5889 " OpStore %iptr %ival_next\n"
5892 // True branch for if-statement.
5893 "%if_true = OpLabel\n"
5894 " OpStore %loc %c_f32_0\n"
5895 " OpBranch %if_exit\n"
5899 fragments["testfun"] = function;
5901 inputColors[0] = RGBA(127, 127, 127, 0);
5902 inputColors[1] = RGBA(127, 0, 0, 0);
5903 inputColors[2] = RGBA(0, 127, 0, 0);
5904 inputColors[3] = RGBA(0, 0, 127, 0);
5906 outputColors[0] = RGBA(0, 128, 128, 255);
5907 outputColors[1] = RGBA(0, 255, 255, 255);
5908 outputColors[2] = RGBA(0, 128, 255, 255);
5909 outputColors[3] = RGBA(0, 255, 128, 255);
5911 createTestsForAllStages("out_of_order", inputColors, outputColors, fragments, group.get());
5913 return group.release();
5916 tcu::TestCaseGroup* createSwitchBlockOrderTests(tcu::TestContext& testCtx)
5918 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "switch_block_order", "Out-of-order blocks for switch"));
5919 RGBA inputColors[4];
5920 RGBA outputColors[4];
5921 map<string, string> fragments;
5923 const char typesAndConstants[] =
5924 "%c_f32_p2 = OpConstant %f32 0.2\n"
5925 "%c_f32_p4 = OpConstant %f32 0.4\n"
5926 "%c_f32_p6 = OpConstant %f32 0.6\n"
5927 "%c_f32_p8 = OpConstant %f32 0.8\n";
5929 // vec4 test_code(vec4 param) {
5930 // vec4 result = param;
5931 // for (int i = 0; i < 4; ++i) {
5933 // case 0: result[i] += .2; break;
5934 // case 1: result[i] += .6; break;
5935 // case 2: result[i] += .4; break;
5936 // case 3: result[i] += .8; break;
5937 // default: break; // unreachable
5942 const char function[] =
5943 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
5944 "%param1 = OpFunctionParameter %v4f32\n"
5946 "%iptr = OpVariable %fp_i32 Function\n"
5947 "%result = OpVariable %fp_v4f32 Function\n"
5948 " OpStore %iptr %c_i32_0\n"
5949 " OpStore %result %param1\n"
5952 // Loop entry block.
5954 "%ival = OpLoad %i32 %iptr\n"
5955 "%lt_4 = OpSLessThan %bool %ival %c_i32_4\n"
5956 " OpLoopMerge %exit %loop None\n"
5957 " OpBranchConditional %lt_4 %switch_entry %exit\n"
5959 // Merge block for loop.
5961 "%ret = OpLoad %v4f32 %result\n"
5962 " OpReturnValue %ret\n"
5964 // Switch-statement entry block.
5965 "%switch_entry = OpLabel\n"
5966 "%loc = OpAccessChain %fp_f32 %result %ival\n"
5967 "%val = OpLoad %f32 %loc\n"
5968 " OpSelectionMerge %switch_exit None\n"
5969 " OpSwitch %ival %switch_default 0 %case0 1 %case1 2 %case2 3 %case3\n"
5971 "%case2 = OpLabel\n"
5972 "%addp4 = OpFAdd %f32 %val %c_f32_p4\n"
5973 " OpStore %loc %addp4\n"
5974 " OpBranch %switch_exit\n"
5976 "%switch_default = OpLabel\n"
5979 "%case3 = OpLabel\n"
5980 "%addp8 = OpFAdd %f32 %val %c_f32_p8\n"
5981 " OpStore %loc %addp8\n"
5982 " OpBranch %switch_exit\n"
5984 "%case0 = OpLabel\n"
5985 "%addp2 = OpFAdd %f32 %val %c_f32_p2\n"
5986 " OpStore %loc %addp2\n"
5987 " OpBranch %switch_exit\n"
5989 // Merge block for switch-statement.
5990 "%switch_exit = OpLabel\n"
5991 "%ival_next = OpIAdd %i32 %ival %c_i32_1\n"
5992 " OpStore %iptr %ival_next\n"
5995 "%case1 = OpLabel\n"
5996 "%addp6 = OpFAdd %f32 %val %c_f32_p6\n"
5997 " OpStore %loc %addp6\n"
5998 " OpBranch %switch_exit\n"
6002 fragments["pre_main"] = typesAndConstants;
6003 fragments["testfun"] = function;
6005 inputColors[0] = RGBA(127, 27, 127, 51);
6006 inputColors[1] = RGBA(127, 0, 0, 51);
6007 inputColors[2] = RGBA(0, 27, 0, 51);
6008 inputColors[3] = RGBA(0, 0, 127, 51);
6010 outputColors[0] = RGBA(178, 180, 229, 255);
6011 outputColors[1] = RGBA(178, 153, 102, 255);
6012 outputColors[2] = RGBA(51, 180, 102, 255);
6013 outputColors[3] = RGBA(51, 153, 229, 255);
6015 createTestsForAllStages("out_of_order", inputColors, outputColors, fragments, group.get());
6017 return group.release();
6020 tcu::TestCaseGroup* createDecorationGroupTests(tcu::TestContext& testCtx)
6022 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "decoration_group", "Decoration group tests"));
6023 RGBA inputColors[4];
6024 RGBA outputColors[4];
6025 map<string, string> fragments;
6027 const char decorations[] =
6028 "OpDecorate %array_group ArrayStride 4\n"
6029 "OpDecorate %struct_member_group Offset 0\n"
6030 "%array_group = OpDecorationGroup\n"
6031 "%struct_member_group = OpDecorationGroup\n"
6033 "OpDecorate %group1 RelaxedPrecision\n"
6034 "OpDecorate %group3 RelaxedPrecision\n"
6035 "OpDecorate %group3 Invariant\n"
6036 "OpDecorate %group3 Restrict\n"
6037 "%group0 = OpDecorationGroup\n"
6038 "%group1 = OpDecorationGroup\n"
6039 "%group3 = OpDecorationGroup\n";
6041 const char typesAndConstants[] =
6042 "%a3f32 = OpTypeArray %f32 %c_u32_3\n"
6043 "%struct1 = OpTypeStruct %a3f32\n"
6044 "%struct2 = OpTypeStruct %a3f32\n"
6045 "%fp_struct1 = OpTypePointer Function %struct1\n"
6046 "%fp_struct2 = OpTypePointer Function %struct2\n"
6047 "%c_f32_2 = OpConstant %f32 2.\n"
6048 "%c_f32_n2 = OpConstant %f32 -2.\n"
6050 "%c_a3f32_1 = OpConstantComposite %a3f32 %c_f32_1 %c_f32_2 %c_f32_1\n"
6051 "%c_a3f32_2 = OpConstantComposite %a3f32 %c_f32_n1 %c_f32_n2 %c_f32_n1\n"
6052 "%c_struct1 = OpConstantComposite %struct1 %c_a3f32_1\n"
6053 "%c_struct2 = OpConstantComposite %struct2 %c_a3f32_2\n";
6055 const char function[] =
6056 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6057 "%param = OpFunctionParameter %v4f32\n"
6058 "%entry = OpLabel\n"
6059 "%result = OpVariable %fp_v4f32 Function\n"
6060 "%v_struct1 = OpVariable %fp_struct1 Function\n"
6061 "%v_struct2 = OpVariable %fp_struct2 Function\n"
6062 " OpStore %result %param\n"
6063 " OpStore %v_struct1 %c_struct1\n"
6064 " OpStore %v_struct2 %c_struct2\n"
6065 "%ptr1 = OpAccessChain %fp_f32 %v_struct1 %c_i32_0 %c_i32_2\n"
6066 "%val1 = OpLoad %f32 %ptr1\n"
6067 "%ptr2 = OpAccessChain %fp_f32 %v_struct2 %c_i32_0 %c_i32_2\n"
6068 "%val2 = OpLoad %f32 %ptr2\n"
6069 "%addvalues = OpFAdd %f32 %val1 %val2\n"
6070 "%ptr = OpAccessChain %fp_f32 %result %c_i32_1\n"
6071 "%val = OpLoad %f32 %ptr\n"
6072 "%addresult = OpFAdd %f32 %addvalues %val\n"
6073 " OpStore %ptr %addresult\n"
6074 "%ret = OpLoad %v4f32 %result\n"
6075 " OpReturnValue %ret\n"
6078 struct CaseNameDecoration
6084 CaseNameDecoration tests[] =
6087 "same_decoration_group_on_multiple_types",
6088 "OpGroupMemberDecorate %struct_member_group %struct1 0 %struct2 0\n"
6091 "empty_decoration_group",
6092 "OpGroupDecorate %group0 %a3f32\n"
6093 "OpGroupDecorate %group0 %result\n"
6096 "one_element_decoration_group",
6097 "OpGroupDecorate %array_group %a3f32\n"
6100 "multiple_elements_decoration_group",
6101 "OpGroupDecorate %group3 %v_struct1\n"
6104 "multiple_decoration_groups_on_same_variable",
6105 "OpGroupDecorate %group0 %v_struct2\n"
6106 "OpGroupDecorate %group1 %v_struct2\n"
6107 "OpGroupDecorate %group3 %v_struct2\n"
6110 "same_decoration_group_multiple_times",
6111 "OpGroupDecorate %group1 %addvalues\n"
6112 "OpGroupDecorate %group1 %addvalues\n"
6113 "OpGroupDecorate %group1 %addvalues\n"
6118 getHalfColorsFullAlpha(inputColors);
6119 getHalfColorsFullAlpha(outputColors);
6121 for (size_t idx = 0; idx < (sizeof(tests) / sizeof(tests[0])); ++idx)
6123 fragments["decoration"] = decorations + tests[idx].decoration;
6124 fragments["pre_main"] = typesAndConstants;
6125 fragments["testfun"] = function;
6127 createTestsForAllStages(tests[idx].name, inputColors, outputColors, fragments, group.get());
6130 return group.release();
6133 struct SpecConstantTwoIntGraphicsCase
6135 const char* caseName;
6136 const char* scDefinition0;
6137 const char* scDefinition1;
6138 const char* scResultType;
6139 const char* scOperation;
6140 deInt32 scActualValue0;
6141 deInt32 scActualValue1;
6142 const char* resultOperation;
6143 RGBA expectedColors[4];
6145 SpecConstantTwoIntGraphicsCase (const char* name,
6146 const char* definition0,
6147 const char* definition1,
6148 const char* resultType,
6149 const char* operation,
6152 const char* resultOp,
6153 const RGBA (&output)[4])
6155 , scDefinition0 (definition0)
6156 , scDefinition1 (definition1)
6157 , scResultType (resultType)
6158 , scOperation (operation)
6159 , scActualValue0 (value0)
6160 , scActualValue1 (value1)
6161 , resultOperation (resultOp)
6163 expectedColors[0] = output[0];
6164 expectedColors[1] = output[1];
6165 expectedColors[2] = output[2];
6166 expectedColors[3] = output[3];
6170 tcu::TestCaseGroup* createSpecConstantTests (tcu::TestContext& testCtx)
6172 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opspecconstantop", "Test the OpSpecConstantOp instruction"));
6173 vector<SpecConstantTwoIntGraphicsCase> cases;
6174 RGBA inputColors[4];
6175 RGBA outputColors0[4];
6176 RGBA outputColors1[4];
6177 RGBA outputColors2[4];
6179 const char decorations1[] =
6180 "OpDecorate %sc_0 SpecId 0\n"
6181 "OpDecorate %sc_1 SpecId 1\n";
6183 const char typesAndConstants1[] =
6184 "%sc_0 = OpSpecConstant${SC_DEF0}\n"
6185 "%sc_1 = OpSpecConstant${SC_DEF1}\n"
6186 "%sc_op = OpSpecConstantOp ${SC_RESULT_TYPE} ${SC_OP}\n";
6188 const char function1[] =
6189 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6190 "%param = OpFunctionParameter %v4f32\n"
6191 "%label = OpLabel\n"
6192 "%result = OpVariable %fp_v4f32 Function\n"
6193 " OpStore %result %param\n"
6194 "%gen = ${GEN_RESULT}\n"
6195 "%index = OpIAdd %i32 %gen %c_i32_1\n"
6196 "%loc = OpAccessChain %fp_f32 %result %index\n"
6197 "%val = OpLoad %f32 %loc\n"
6198 "%add = OpFAdd %f32 %val %c_f32_0_5\n"
6199 " OpStore %loc %add\n"
6200 "%ret = OpLoad %v4f32 %result\n"
6201 " OpReturnValue %ret\n"
6204 inputColors[0] = RGBA(127, 127, 127, 255);
6205 inputColors[1] = RGBA(127, 0, 0, 255);
6206 inputColors[2] = RGBA(0, 127, 0, 255);
6207 inputColors[3] = RGBA(0, 0, 127, 255);
6209 // Derived from inputColors[x] by adding 128 to inputColors[x][0].
6210 outputColors0[0] = RGBA(255, 127, 127, 255);
6211 outputColors0[1] = RGBA(255, 0, 0, 255);
6212 outputColors0[2] = RGBA(128, 127, 0, 255);
6213 outputColors0[3] = RGBA(128, 0, 127, 255);
6215 // Derived from inputColors[x] by adding 128 to inputColors[x][1].
6216 outputColors1[0] = RGBA(127, 255, 127, 255);
6217 outputColors1[1] = RGBA(127, 128, 0, 255);
6218 outputColors1[2] = RGBA(0, 255, 0, 255);
6219 outputColors1[3] = RGBA(0, 128, 127, 255);
6221 // Derived from inputColors[x] by adding 128 to inputColors[x][2].
6222 outputColors2[0] = RGBA(127, 127, 255, 255);
6223 outputColors2[1] = RGBA(127, 0, 128, 255);
6224 outputColors2[2] = RGBA(0, 127, 128, 255);
6225 outputColors2[3] = RGBA(0, 0, 255, 255);
6227 const char addZeroToSc[] = "OpIAdd %i32 %c_i32_0 %sc_op";
6228 const char selectTrueUsingSc[] = "OpSelect %i32 %sc_op %c_i32_1 %c_i32_0";
6229 const char selectFalseUsingSc[] = "OpSelect %i32 %sc_op %c_i32_0 %c_i32_1";
6231 cases.push_back(SpecConstantTwoIntGraphicsCase("iadd", " %i32 0", " %i32 0", "%i32", "IAdd %sc_0 %sc_1", 19, -20, addZeroToSc, outputColors0));
6232 cases.push_back(SpecConstantTwoIntGraphicsCase("isub", " %i32 0", " %i32 0", "%i32", "ISub %sc_0 %sc_1", 19, 20, addZeroToSc, outputColors0));
6233 cases.push_back(SpecConstantTwoIntGraphicsCase("imul", " %i32 0", " %i32 0", "%i32", "IMul %sc_0 %sc_1", -1, -1, addZeroToSc, outputColors2));
6234 cases.push_back(SpecConstantTwoIntGraphicsCase("sdiv", " %i32 0", " %i32 0", "%i32", "SDiv %sc_0 %sc_1", -126, 126, addZeroToSc, outputColors0));
6235 cases.push_back(SpecConstantTwoIntGraphicsCase("udiv", " %i32 0", " %i32 0", "%i32", "UDiv %sc_0 %sc_1", 126, 126, addZeroToSc, outputColors2));
6236 cases.push_back(SpecConstantTwoIntGraphicsCase("srem", " %i32 0", " %i32 0", "%i32", "SRem %sc_0 %sc_1", 3, 2, addZeroToSc, outputColors2));
6237 cases.push_back(SpecConstantTwoIntGraphicsCase("smod", " %i32 0", " %i32 0", "%i32", "SMod %sc_0 %sc_1", 3, 2, addZeroToSc, outputColors2));
6238 cases.push_back(SpecConstantTwoIntGraphicsCase("umod", " %i32 0", " %i32 0", "%i32", "UMod %sc_0 %sc_1", 1001, 500, addZeroToSc, outputColors2));
6239 cases.push_back(SpecConstantTwoIntGraphicsCase("bitwiseand", " %i32 0", " %i32 0", "%i32", "BitwiseAnd %sc_0 %sc_1", 0x33, 0x0d, addZeroToSc, outputColors2));
6240 cases.push_back(SpecConstantTwoIntGraphicsCase("bitwiseor", " %i32 0", " %i32 0", "%i32", "BitwiseOr %sc_0 %sc_1", 0, 1, addZeroToSc, outputColors2));
6241 cases.push_back(SpecConstantTwoIntGraphicsCase("bitwisexor", " %i32 0", " %i32 0", "%i32", "BitwiseXor %sc_0 %sc_1", 0x2e, 0x2f, addZeroToSc, outputColors2));
6242 cases.push_back(SpecConstantTwoIntGraphicsCase("shiftrightlogical", " %i32 0", " %i32 0", "%i32", "ShiftRightLogical %sc_0 %sc_1", 2, 1, addZeroToSc, outputColors2));
6243 cases.push_back(SpecConstantTwoIntGraphicsCase("shiftrightarithmetic", " %i32 0", " %i32 0", "%i32", "ShiftRightArithmetic %sc_0 %sc_1", -4, 2, addZeroToSc, outputColors0));
6244 cases.push_back(SpecConstantTwoIntGraphicsCase("shiftleftlogical", " %i32 0", " %i32 0", "%i32", "ShiftLeftLogical %sc_0 %sc_1", 1, 0, addZeroToSc, outputColors2));
6245 cases.push_back(SpecConstantTwoIntGraphicsCase("slessthan", " %i32 0", " %i32 0", "%bool", "SLessThan %sc_0 %sc_1", -20, -10, selectTrueUsingSc, outputColors2));
6246 cases.push_back(SpecConstantTwoIntGraphicsCase("ulessthan", " %i32 0", " %i32 0", "%bool", "ULessThan %sc_0 %sc_1", 10, 20, selectTrueUsingSc, outputColors2));
6247 cases.push_back(SpecConstantTwoIntGraphicsCase("sgreaterthan", " %i32 0", " %i32 0", "%bool", "SGreaterThan %sc_0 %sc_1", -1000, 50, selectFalseUsingSc, outputColors2));
6248 cases.push_back(SpecConstantTwoIntGraphicsCase("ugreaterthan", " %i32 0", " %i32 0", "%bool", "UGreaterThan %sc_0 %sc_1", 10, 5, selectTrueUsingSc, outputColors2));
6249 cases.push_back(SpecConstantTwoIntGraphicsCase("slessthanequal", " %i32 0", " %i32 0", "%bool", "SLessThanEqual %sc_0 %sc_1", -10, -10, selectTrueUsingSc, outputColors2));
6250 cases.push_back(SpecConstantTwoIntGraphicsCase("ulessthanequal", " %i32 0", " %i32 0", "%bool", "ULessThanEqual %sc_0 %sc_1", 50, 100, selectTrueUsingSc, outputColors2));
6251 cases.push_back(SpecConstantTwoIntGraphicsCase("sgreaterthanequal", " %i32 0", " %i32 0", "%bool", "SGreaterThanEqual %sc_0 %sc_1", -1000, 50, selectFalseUsingSc, outputColors2));
6252 cases.push_back(SpecConstantTwoIntGraphicsCase("ugreaterthanequal", " %i32 0", " %i32 0", "%bool", "UGreaterThanEqual %sc_0 %sc_1", 10, 10, selectTrueUsingSc, outputColors2));
6253 cases.push_back(SpecConstantTwoIntGraphicsCase("iequal", " %i32 0", " %i32 0", "%bool", "IEqual %sc_0 %sc_1", 42, 24, selectFalseUsingSc, outputColors2));
6254 cases.push_back(SpecConstantTwoIntGraphicsCase("logicaland", "True %bool", "True %bool", "%bool", "LogicalAnd %sc_0 %sc_1", 0, 1, selectFalseUsingSc, outputColors2));
6255 cases.push_back(SpecConstantTwoIntGraphicsCase("logicalor", "False %bool", "False %bool", "%bool", "LogicalOr %sc_0 %sc_1", 1, 0, selectTrueUsingSc, outputColors2));
6256 cases.push_back(SpecConstantTwoIntGraphicsCase("logicalequal", "True %bool", "True %bool", "%bool", "LogicalEqual %sc_0 %sc_1", 0, 1, selectFalseUsingSc, outputColors2));
6257 cases.push_back(SpecConstantTwoIntGraphicsCase("logicalnotequal", "False %bool", "False %bool", "%bool", "LogicalNotEqual %sc_0 %sc_1", 1, 0, selectTrueUsingSc, outputColors2));
6258 cases.push_back(SpecConstantTwoIntGraphicsCase("snegate", " %i32 0", " %i32 0", "%i32", "SNegate %sc_0", -1, 0, addZeroToSc, outputColors2));
6259 cases.push_back(SpecConstantTwoIntGraphicsCase("not", " %i32 0", " %i32 0", "%i32", "Not %sc_0", -2, 0, addZeroToSc, outputColors2));
6260 cases.push_back(SpecConstantTwoIntGraphicsCase("logicalnot", "False %bool", "False %bool", "%bool", "LogicalNot %sc_0", 1, 0, selectFalseUsingSc, outputColors2));
6261 cases.push_back(SpecConstantTwoIntGraphicsCase("select", "False %bool", " %i32 0", "%i32", "Select %sc_0 %sc_1 %c_i32_0", 1, 1, addZeroToSc, outputColors2));
6262 // OpSConvert, OpFConvert: these two instructions involve ints/floats of different bitwidths.
6263 // \todo[2015-12-1 antiagainst] OpQuantizeToF16
6265 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
6267 map<string, string> specializations;
6268 map<string, string> fragments;
6269 vector<deInt32> specConstants;
6271 specializations["SC_DEF0"] = cases[caseNdx].scDefinition0;
6272 specializations["SC_DEF1"] = cases[caseNdx].scDefinition1;
6273 specializations["SC_RESULT_TYPE"] = cases[caseNdx].scResultType;
6274 specializations["SC_OP"] = cases[caseNdx].scOperation;
6275 specializations["GEN_RESULT"] = cases[caseNdx].resultOperation;
6277 fragments["decoration"] = tcu::StringTemplate(decorations1).specialize(specializations);
6278 fragments["pre_main"] = tcu::StringTemplate(typesAndConstants1).specialize(specializations);
6279 fragments["testfun"] = tcu::StringTemplate(function1).specialize(specializations);
6281 specConstants.push_back(cases[caseNdx].scActualValue0);
6282 specConstants.push_back(cases[caseNdx].scActualValue1);
6284 createTestsForAllStages(cases[caseNdx].caseName, inputColors, cases[caseNdx].expectedColors, fragments, specConstants, group.get());
6287 const char decorations2[] =
6288 "OpDecorate %sc_0 SpecId 0\n"
6289 "OpDecorate %sc_1 SpecId 1\n"
6290 "OpDecorate %sc_2 SpecId 2\n";
6292 const char typesAndConstants2[] =
6293 "%v3i32 = OpTypeVector %i32 3\n"
6295 "%sc_0 = OpSpecConstant %i32 0\n"
6296 "%sc_1 = OpSpecConstant %i32 0\n"
6297 "%sc_2 = OpSpecConstant %i32 0\n"
6299 "%vec3_0 = OpConstantComposite %v3i32 %c_i32_0 %c_i32_0 %c_i32_0\n"
6300 "%sc_vec3_0 = OpSpecConstantOp %v3i32 CompositeInsert %sc_0 %vec3_0 0\n" // (sc_0, 0, 0)
6301 "%sc_vec3_1 = OpSpecConstantOp %v3i32 CompositeInsert %sc_1 %vec3_0 1\n" // (0, sc_1, 0)
6302 "%sc_vec3_2 = OpSpecConstantOp %v3i32 CompositeInsert %sc_2 %vec3_0 2\n" // (0, 0, sc_2)
6303 "%sc_vec3_01 = OpSpecConstantOp %v3i32 VectorShuffle %sc_vec3_0 %sc_vec3_1 1 0 4\n" // (0, sc_0, sc_1)
6304 "%sc_vec3_012 = OpSpecConstantOp %v3i32 VectorShuffle %sc_vec3_01 %sc_vec3_2 5 1 2\n" // (sc_2, sc_0, sc_1)
6305 "%sc_ext_0 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 0\n" // sc_2
6306 "%sc_ext_1 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 1\n" // sc_0
6307 "%sc_ext_2 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 2\n" // sc_1
6308 "%sc_sub = OpSpecConstantOp %i32 ISub %sc_ext_0 %sc_ext_1\n" // (sc_2 - sc_0)
6309 "%sc_final = OpSpecConstantOp %i32 IMul %sc_sub %sc_ext_2\n"; // (sc_2 - sc_0) * sc_1
6311 const char function2[] =
6312 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6313 "%param = OpFunctionParameter %v4f32\n"
6314 "%label = OpLabel\n"
6315 "%result = OpVariable %fp_v4f32 Function\n"
6316 " OpStore %result %param\n"
6317 "%loc = OpAccessChain %fp_f32 %result %sc_final\n"
6318 "%val = OpLoad %f32 %loc\n"
6319 "%add = OpFAdd %f32 %val %c_f32_0_5\n"
6320 " OpStore %loc %add\n"
6321 "%ret = OpLoad %v4f32 %result\n"
6322 " OpReturnValue %ret\n"
6325 map<string, string> fragments;
6326 vector<deInt32> specConstants;
6328 fragments["decoration"] = decorations2;
6329 fragments["pre_main"] = typesAndConstants2;
6330 fragments["testfun"] = function2;
6332 specConstants.push_back(56789);
6333 specConstants.push_back(-2);
6334 specConstants.push_back(56788);
6336 createTestsForAllStages("vector_related", inputColors, outputColors2, fragments, specConstants, group.get());
6338 return group.release();
6341 tcu::TestCaseGroup* createOpPhiTests(tcu::TestContext& testCtx)
6343 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opphi", "Test the OpPhi instruction"));
6344 RGBA inputColors[4];
6345 RGBA outputColors1[4];
6346 RGBA outputColors2[4];
6347 RGBA outputColors3[4];
6348 map<string, string> fragments1;
6349 map<string, string> fragments2;
6350 map<string, string> fragments3;
6352 const char typesAndConstants1[] =
6353 "%c_f32_p2 = OpConstant %f32 0.2\n"
6354 "%c_f32_p4 = OpConstant %f32 0.4\n"
6355 "%c_f32_p5 = OpConstant %f32 0.5\n"
6356 "%c_f32_p8 = OpConstant %f32 0.8\n";
6358 // vec4 test_code(vec4 param) {
6359 // vec4 result = param;
6360 // for (int i = 0; i < 4; ++i) {
6363 // case 0: operand = .2; break;
6364 // case 1: operand = .5; break;
6365 // case 2: operand = .4; break;
6366 // case 3: operand = .0; break;
6367 // default: break; // unreachable
6369 // result[i] += operand;
6373 const char function1[] =
6374 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6375 "%param1 = OpFunctionParameter %v4f32\n"
6377 "%iptr = OpVariable %fp_i32 Function\n"
6378 "%result = OpVariable %fp_v4f32 Function\n"
6379 " OpStore %iptr %c_i32_0\n"
6380 " OpStore %result %param1\n"
6384 "%ival = OpLoad %i32 %iptr\n"
6385 "%lt_4 = OpSLessThan %bool %ival %c_i32_4\n"
6386 " OpLoopMerge %exit %loop None\n"
6387 " OpBranchConditional %lt_4 %entry %exit\n"
6389 "%entry = OpLabel\n"
6390 "%loc = OpAccessChain %fp_f32 %result %ival\n"
6391 "%val = OpLoad %f32 %loc\n"
6392 " OpSelectionMerge %phi None\n"
6393 " OpSwitch %ival %default 0 %case0 1 %case1 2 %case2 3 %case3\n"
6395 "%case0 = OpLabel\n"
6397 "%case1 = OpLabel\n"
6399 "%case2 = OpLabel\n"
6401 "%case3 = OpLabel\n"
6404 "%default = OpLabel\n"
6408 "%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
6409 "%add = OpFAdd %f32 %val %operand\n"
6410 " OpStore %loc %add\n"
6411 "%ival_next = OpIAdd %i32 %ival %c_i32_1\n"
6412 " OpStore %iptr %ival_next\n"
6416 "%ret = OpLoad %v4f32 %result\n"
6417 " OpReturnValue %ret\n"
6421 fragments1["pre_main"] = typesAndConstants1;
6422 fragments1["testfun"] = function1;
6424 getHalfColorsFullAlpha(inputColors);
6426 outputColors1[0] = RGBA(178, 255, 229, 255);
6427 outputColors1[1] = RGBA(178, 127, 102, 255);
6428 outputColors1[2] = RGBA(51, 255, 102, 255);
6429 outputColors1[3] = RGBA(51, 127, 229, 255);
6431 createTestsForAllStages("out_of_order", inputColors, outputColors1, fragments1, group.get());
6433 const char typesAndConstants2[] =
6434 "%c_f32_p2 = OpConstant %f32 0.2\n";
6436 // Add .4 to the second element of the given parameter.
6437 const char function2[] =
6438 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6439 "%param = OpFunctionParameter %v4f32\n"
6440 "%entry = OpLabel\n"
6441 "%result = OpVariable %fp_v4f32 Function\n"
6442 " OpStore %result %param\n"
6443 "%loc = OpAccessChain %fp_f32 %result %c_i32_1\n"
6444 "%val = OpLoad %f32 %loc\n"
6448 "%step = OpPhi %i32 %c_i32_0 %entry %step_next %phi\n"
6449 "%accum = OpPhi %f32 %val %entry %accum_next %phi\n"
6450 "%step_next = OpIAdd %i32 %step %c_i32_1\n"
6451 "%accum_next = OpFAdd %f32 %accum %c_f32_p2\n"
6452 "%still_loop = OpSLessThan %bool %step %c_i32_2\n"
6453 " OpLoopMerge %exit %phi None\n"
6454 " OpBranchConditional %still_loop %phi %exit\n"
6457 " OpStore %loc %accum\n"
6458 "%ret = OpLoad %v4f32 %result\n"
6459 " OpReturnValue %ret\n"
6463 fragments2["pre_main"] = typesAndConstants2;
6464 fragments2["testfun"] = function2;
6466 outputColors2[0] = RGBA(127, 229, 127, 255);
6467 outputColors2[1] = RGBA(127, 102, 0, 255);
6468 outputColors2[2] = RGBA(0, 229, 0, 255);
6469 outputColors2[3] = RGBA(0, 102, 127, 255);
6471 createTestsForAllStages("induction", inputColors, outputColors2, fragments2, group.get());
6473 const char typesAndConstants3[] =
6474 "%true = OpConstantTrue %bool\n"
6475 "%false = OpConstantFalse %bool\n"
6476 "%c_f32_p2 = OpConstant %f32 0.2\n";
6478 // Swap the second and the third element of the given parameter.
6479 const char function3[] =
6480 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6481 "%param = OpFunctionParameter %v4f32\n"
6482 "%entry = OpLabel\n"
6483 "%result = OpVariable %fp_v4f32 Function\n"
6484 " OpStore %result %param\n"
6485 "%a_loc = OpAccessChain %fp_f32 %result %c_i32_1\n"
6486 "%a_init = OpLoad %f32 %a_loc\n"
6487 "%b_loc = OpAccessChain %fp_f32 %result %c_i32_2\n"
6488 "%b_init = OpLoad %f32 %b_loc\n"
6492 "%still_loop = OpPhi %bool %true %entry %false %phi\n"
6493 "%a_next = OpPhi %f32 %a_init %entry %b_next %phi\n"
6494 "%b_next = OpPhi %f32 %b_init %entry %a_next %phi\n"
6495 " OpLoopMerge %exit %phi None\n"
6496 " OpBranchConditional %still_loop %phi %exit\n"
6499 " OpStore %a_loc %a_next\n"
6500 " OpStore %b_loc %b_next\n"
6501 "%ret = OpLoad %v4f32 %result\n"
6502 " OpReturnValue %ret\n"
6506 fragments3["pre_main"] = typesAndConstants3;
6507 fragments3["testfun"] = function3;
6509 outputColors3[0] = RGBA(127, 127, 127, 255);
6510 outputColors3[1] = RGBA(127, 0, 0, 255);
6511 outputColors3[2] = RGBA(0, 0, 127, 255);
6512 outputColors3[3] = RGBA(0, 127, 0, 255);
6514 createTestsForAllStages("swap", inputColors, outputColors3, fragments3, group.get());
6516 return group.release();
6519 tcu::TestCaseGroup* createNoContractionTests(tcu::TestContext& testCtx)
6521 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "nocontraction", "Test the NoContraction decoration"));
6522 RGBA inputColors[4];
6523 RGBA outputColors[4];
6525 // With NoContraction, (1 + 2^-23) * (1 - 2^-23) - 1 should be conducted as a multiplication and an addition separately.
6526 // For the multiplication, the result is 1 - 2^-46, which is out of the precision range for 32-bit float. (32-bit float
6527 // only have 23-bit fraction.) So it will be rounded to 1. Or 0x1.fffffc. Then the final result is 0 or -0x1p-24.
6528 // On the contrary, the result will be 2^-46, which is a normalized number perfectly representable as 32-bit float.
6529 const char constantsAndTypes[] =
6530 "%c_vec4_0 = OpConstantComposite %v4f32 %c_f32_0 %c_f32_0 %c_f32_0 %c_f32_1\n"
6531 "%c_vec4_1 = OpConstantComposite %v4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_1\n"
6532 "%c_f32_1pl2_23 = OpConstant %f32 0x1.000002p+0\n" // 1 + 2^-23
6533 "%c_f32_1mi2_23 = OpConstant %f32 0x1.fffffcp-1\n" // 1 - 2^-23
6534 "%c_f32_n1pn24 = OpConstant %f32 -0x1p-24\n"
6537 const char function[] =
6538 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6539 "%param = OpFunctionParameter %v4f32\n"
6540 "%label = OpLabel\n"
6541 "%var1 = OpVariable %fp_f32 Function %c_f32_1pl2_23\n"
6542 "%var2 = OpVariable %fp_f32 Function\n"
6543 "%red = OpCompositeExtract %f32 %param 0\n"
6544 "%plus_red = OpFAdd %f32 %c_f32_1mi2_23 %red\n"
6545 " OpStore %var2 %plus_red\n"
6546 "%val1 = OpLoad %f32 %var1\n"
6547 "%val2 = OpLoad %f32 %var2\n"
6548 "%mul = OpFMul %f32 %val1 %val2\n"
6549 "%add = OpFAdd %f32 %mul %c_f32_n1\n"
6550 "%is0 = OpFOrdEqual %bool %add %c_f32_0\n"
6551 "%isn1n24 = OpFOrdEqual %bool %add %c_f32_n1pn24\n"
6552 "%success = OpLogicalOr %bool %is0 %isn1n24\n"
6553 "%v4success = OpCompositeConstruct %v4bool %success %success %success %success\n"
6554 "%ret = OpSelect %v4f32 %v4success %c_vec4_0 %c_vec4_1\n"
6555 " OpReturnValue %ret\n"
6558 struct CaseNameDecoration
6565 CaseNameDecoration tests[] = {
6566 {"multiplication", "OpDecorate %mul NoContraction"},
6567 {"addition", "OpDecorate %add NoContraction"},
6568 {"both", "OpDecorate %mul NoContraction\nOpDecorate %add NoContraction"},
6571 getHalfColorsFullAlpha(inputColors);
6573 for (deUint8 idx = 0; idx < 4; ++idx)
6575 inputColors[idx].setRed(0);
6576 outputColors[idx] = RGBA(0, 0, 0, 255);
6579 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(CaseNameDecoration); ++testNdx)
6581 map<string, string> fragments;
6583 fragments["decoration"] = tests[testNdx].decoration;
6584 fragments["pre_main"] = constantsAndTypes;
6585 fragments["testfun"] = function;
6587 createTestsForAllStages(tests[testNdx].name, inputColors, outputColors, fragments, group.get());
6590 return group.release();
6593 tcu::TestCaseGroup* createMemoryAccessTests(tcu::TestContext& testCtx)
6595 de::MovePtr<tcu::TestCaseGroup> memoryAccessTests (new tcu::TestCaseGroup(testCtx, "opmemoryaccess", "Memory Semantics"));
6598 const char constantsAndTypes[] =
6599 "%c_a2f32_1 = OpConstantComposite %a2f32 %c_f32_1 %c_f32_1\n"
6600 "%fp_a2f32 = OpTypePointer Function %a2f32\n"
6601 "%stype = OpTypeStruct %v4f32 %a2f32 %f32\n"
6602 "%fp_stype = OpTypePointer Function %stype\n";
6604 const char function[] =
6605 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6606 "%param1 = OpFunctionParameter %v4f32\n"
6608 "%v1 = OpVariable %fp_v4f32 Function\n"
6609 "%v2 = OpVariable %fp_a2f32 Function\n"
6610 "%v3 = OpVariable %fp_f32 Function\n"
6611 "%v = OpVariable %fp_stype Function\n"
6612 "%vv = OpVariable %fp_stype Function\n"
6613 "%vvv = OpVariable %fp_f32 Function\n"
6615 " OpStore %v1 %c_v4f32_1_1_1_1\n"
6616 " OpStore %v2 %c_a2f32_1\n"
6617 " OpStore %v3 %c_f32_1\n"
6619 "%p_v4f32 = OpAccessChain %fp_v4f32 %v %c_u32_0\n"
6620 "%p_a2f32 = OpAccessChain %fp_a2f32 %v %c_u32_1\n"
6621 "%p_f32 = OpAccessChain %fp_f32 %v %c_u32_2\n"
6622 "%v1_v = OpLoad %v4f32 %v1 ${access_type}\n"
6623 "%v2_v = OpLoad %a2f32 %v2 ${access_type}\n"
6624 "%v3_v = OpLoad %f32 %v3 ${access_type}\n"
6626 " OpStore %p_v4f32 %v1_v ${access_type}\n"
6627 " OpStore %p_a2f32 %v2_v ${access_type}\n"
6628 " OpStore %p_f32 %v3_v ${access_type}\n"
6630 " OpCopyMemory %vv %v ${access_type}\n"
6631 " OpCopyMemory %vvv %p_f32 ${access_type}\n"
6633 "%p_f32_2 = OpAccessChain %fp_f32 %vv %c_u32_2\n"
6634 "%v_f32_2 = OpLoad %f32 %p_f32_2\n"
6635 "%v_f32_3 = OpLoad %f32 %vvv\n"
6637 "%ret1 = OpVectorTimesScalar %v4f32 %param1 %v_f32_2\n"
6638 "%ret2 = OpVectorTimesScalar %v4f32 %ret1 %v_f32_3\n"
6639 " OpReturnValue %ret2\n"
6642 struct NameMemoryAccess
6649 NameMemoryAccess tests[] =
6652 { "volatile", "Volatile" },
6653 { "aligned", "Aligned 1" },
6654 { "volatile_aligned", "Volatile|Aligned 1" },
6655 { "nontemporal_aligned", "Nontemporal|Aligned 1" },
6656 { "volatile_nontemporal", "Volatile|Nontemporal" },
6657 { "volatile_nontermporal_aligned", "Volatile|Nontemporal|Aligned 1" },
6660 getHalfColorsFullAlpha(colors);
6662 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameMemoryAccess); ++testNdx)
6664 map<string, string> fragments;
6665 map<string, string> memoryAccess;
6666 memoryAccess["access_type"] = tests[testNdx].accessType;
6668 fragments["pre_main"] = constantsAndTypes;
6669 fragments["testfun"] = tcu::StringTemplate(function).specialize(memoryAccess);
6670 createTestsForAllStages(tests[testNdx].name, colors, colors, fragments, memoryAccessTests.get());
6672 return memoryAccessTests.release();
6674 tcu::TestCaseGroup* createOpUndefTests(tcu::TestContext& testCtx)
6676 de::MovePtr<tcu::TestCaseGroup> opUndefTests (new tcu::TestCaseGroup(testCtx, "opundef", "Test OpUndef"));
6677 RGBA defaultColors[4];
6678 map<string, string> fragments;
6679 getDefaultColors(defaultColors);
6681 // First, simple cases that don't do anything with the OpUndef result.
6682 fragments["testfun"] =
6683 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6684 "%param1 = OpFunctionParameter %v4f32\n"
6685 "%label_testfun = OpLabel\n"
6686 "%undef = OpUndef %type\n"
6687 "OpReturnValue %param1\n"
6690 struct NameCodePair { string name, code; };
6691 const NameCodePair tests[] =
6693 {"bool", "%type = OpTypeBool"},
6694 {"vec2uint32", "%type = OpTypeVector %u32 2"},
6695 {"image", "%type = OpTypeImage %f32 2D 0 0 0 1 Unknown"},
6696 {"sampler", "%type = OpTypeSampler"},
6697 {"sampledimage", "%img = OpTypeImage %f32 2D 0 0 0 1 Unknown\n" "%type = OpTypeSampledImage %img"},
6698 {"pointer", "%type = OpTypePointer Function %i32"},
6699 {"runtimearray", "%type = OpTypeRuntimeArray %f32"},
6700 {"array", "%c_u32_100 = OpConstant %u32 100\n" "%type = OpTypeArray %i32 %c_u32_100"},
6701 {"struct", "%type = OpTypeStruct %f32 %i32 %u32"}};
6702 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameCodePair); ++testNdx)
6704 fragments["pre_main"] = tests[testNdx].code;
6705 createTestsForAllStages(tests[testNdx].name, defaultColors, defaultColors, fragments, opUndefTests.get());
6709 fragments["testfun"] =
6710 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6711 "%param1 = OpFunctionParameter %v4f32\n"
6712 "%label_testfun = OpLabel\n"
6713 "%undef = OpUndef %f32\n"
6714 "%zero = OpFMul %f32 %undef %c_f32_0\n"
6715 "%is_nan = OpIsNan %bool %zero\n" //OpUndef may result in NaN which may turn %zero into Nan.
6716 "%actually_zero = OpSelect %f32 %is_nan %c_f32_0 %zero\n"
6717 "%a = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
6718 "%b = OpFAdd %f32 %a %actually_zero\n"
6719 "%ret = OpVectorInsertDynamic %v4f32 %param1 %b %c_i32_0\n"
6720 "OpReturnValue %ret\n"
6723 createTestsForAllStages("float32", defaultColors, defaultColors, fragments, opUndefTests.get());
6725 fragments["testfun"] =
6726 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6727 "%param1 = OpFunctionParameter %v4f32\n"
6728 "%label_testfun = OpLabel\n"
6729 "%undef = OpUndef %i32\n"
6730 "%zero = OpIMul %i32 %undef %c_i32_0\n"
6731 "%a = OpVectorExtractDynamic %f32 %param1 %zero\n"
6732 "%ret = OpVectorInsertDynamic %v4f32 %param1 %a %c_i32_0\n"
6733 "OpReturnValue %ret\n"
6736 createTestsForAllStages("sint32", defaultColors, defaultColors, fragments, opUndefTests.get());
6738 fragments["testfun"] =
6739 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6740 "%param1 = OpFunctionParameter %v4f32\n"
6741 "%label_testfun = OpLabel\n"
6742 "%undef = OpUndef %u32\n"
6743 "%zero = OpIMul %u32 %undef %c_i32_0\n"
6744 "%a = OpVectorExtractDynamic %f32 %param1 %zero\n"
6745 "%ret = OpVectorInsertDynamic %v4f32 %param1 %a %c_i32_0\n"
6746 "OpReturnValue %ret\n"
6749 createTestsForAllStages("uint32", defaultColors, defaultColors, fragments, opUndefTests.get());
6751 fragments["testfun"] =
6752 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6753 "%param1 = OpFunctionParameter %v4f32\n"
6754 "%label_testfun = OpLabel\n"
6755 "%undef = OpUndef %v4f32\n"
6756 "%vzero = OpVectorTimesScalar %v4f32 %undef %c_f32_0\n"
6757 "%zero_0 = OpVectorExtractDynamic %f32 %vzero %c_i32_0\n"
6758 "%zero_1 = OpVectorExtractDynamic %f32 %vzero %c_i32_1\n"
6759 "%zero_2 = OpVectorExtractDynamic %f32 %vzero %c_i32_2\n"
6760 "%zero_3 = OpVectorExtractDynamic %f32 %vzero %c_i32_3\n"
6761 "%is_nan_0 = OpIsNan %bool %zero_0\n"
6762 "%is_nan_1 = OpIsNan %bool %zero_1\n"
6763 "%is_nan_2 = OpIsNan %bool %zero_2\n"
6764 "%is_nan_3 = OpIsNan %bool %zero_3\n"
6765 "%actually_zero_0 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_0\n"
6766 "%actually_zero_1 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_1\n"
6767 "%actually_zero_2 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_2\n"
6768 "%actually_zero_3 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_3\n"
6769 "%param1_0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
6770 "%param1_1 = OpVectorExtractDynamic %f32 %param1 %c_i32_1\n"
6771 "%param1_2 = OpVectorExtractDynamic %f32 %param1 %c_i32_2\n"
6772 "%param1_3 = OpVectorExtractDynamic %f32 %param1 %c_i32_3\n"
6773 "%sum_0 = OpFAdd %f32 %param1_0 %actually_zero_0\n"
6774 "%sum_1 = OpFAdd %f32 %param1_1 %actually_zero_1\n"
6775 "%sum_2 = OpFAdd %f32 %param1_2 %actually_zero_2\n"
6776 "%sum_3 = OpFAdd %f32 %param1_3 %actually_zero_3\n"
6777 "%ret3 = OpVectorInsertDynamic %v4f32 %param1 %sum_3 %c_i32_3\n"
6778 "%ret2 = OpVectorInsertDynamic %v4f32 %ret3 %sum_2 %c_i32_2\n"
6779 "%ret1 = OpVectorInsertDynamic %v4f32 %ret2 %sum_1 %c_i32_1\n"
6780 "%ret = OpVectorInsertDynamic %v4f32 %ret1 %sum_0 %c_i32_0\n"
6781 "OpReturnValue %ret\n"
6784 createTestsForAllStages("vec4float32", defaultColors, defaultColors, fragments, opUndefTests.get());
6786 fragments["pre_main"] =
6787 "%v2f32 = OpTypeVector %f32 2\n"
6788 "%m2x2f32 = OpTypeMatrix %v2f32 2\n";
6789 fragments["testfun"] =
6790 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6791 "%param1 = OpFunctionParameter %v4f32\n"
6792 "%label_testfun = OpLabel\n"
6793 "%undef = OpUndef %m2x2f32\n"
6794 "%mzero = OpMatrixTimesScalar %m2x2f32 %undef %c_f32_0\n"
6795 "%zero_0 = OpCompositeExtract %f32 %mzero 0 0\n"
6796 "%zero_1 = OpCompositeExtract %f32 %mzero 0 1\n"
6797 "%zero_2 = OpCompositeExtract %f32 %mzero 1 0\n"
6798 "%zero_3 = OpCompositeExtract %f32 %mzero 1 1\n"
6799 "%is_nan_0 = OpIsNan %bool %zero_0\n"
6800 "%is_nan_1 = OpIsNan %bool %zero_1\n"
6801 "%is_nan_2 = OpIsNan %bool %zero_2\n"
6802 "%is_nan_3 = OpIsNan %bool %zero_3\n"
6803 "%actually_zero_0 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_0\n"
6804 "%actually_zero_1 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_1\n"
6805 "%actually_zero_2 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_2\n"
6806 "%actually_zero_3 = OpSelect %f32 %is_nan_0 %c_f32_0 %zero_3\n"
6807 "%param1_0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
6808 "%param1_1 = OpVectorExtractDynamic %f32 %param1 %c_i32_1\n"
6809 "%param1_2 = OpVectorExtractDynamic %f32 %param1 %c_i32_2\n"
6810 "%param1_3 = OpVectorExtractDynamic %f32 %param1 %c_i32_3\n"
6811 "%sum_0 = OpFAdd %f32 %param1_0 %actually_zero_0\n"
6812 "%sum_1 = OpFAdd %f32 %param1_1 %actually_zero_1\n"
6813 "%sum_2 = OpFAdd %f32 %param1_2 %actually_zero_2\n"
6814 "%sum_3 = OpFAdd %f32 %param1_3 %actually_zero_3\n"
6815 "%ret3 = OpVectorInsertDynamic %v4f32 %param1 %sum_3 %c_i32_3\n"
6816 "%ret2 = OpVectorInsertDynamic %v4f32 %ret3 %sum_2 %c_i32_2\n"
6817 "%ret1 = OpVectorInsertDynamic %v4f32 %ret2 %sum_1 %c_i32_1\n"
6818 "%ret = OpVectorInsertDynamic %v4f32 %ret1 %sum_0 %c_i32_0\n"
6819 "OpReturnValue %ret\n"
6822 createTestsForAllStages("matrix", defaultColors, defaultColors, fragments, opUndefTests.get());
6824 return opUndefTests.release();
6827 void createOpQuantizeSingleOptionTests(tcu::TestCaseGroup* testCtx)
6829 const RGBA inputColors[4] =
6832 RGBA(0, 0, 255, 255),
6833 RGBA(0, 255, 0, 255),
6834 RGBA(0, 255, 255, 255)
6837 const RGBA expectedColors[4] =
6839 RGBA(255, 0, 0, 255),
6840 RGBA(255, 0, 0, 255),
6841 RGBA(255, 0, 0, 255),
6842 RGBA(255, 0, 0, 255)
6845 const struct SingleFP16Possibility
6848 const char* constant; // Value to assign to %test_constant.
6850 const char* condition; // Must assign to %cond an expression that evaluates to true after %c = OpQuantizeToF16(%test_constant + 0).
6856 -constructNormalizedFloat(1, 0x300000),
6857 "%cond = OpFOrdEqual %bool %c %test_constant\n"
6862 constructNormalizedFloat(7, 0x000000),
6863 "%cond = OpFOrdEqual %bool %c %test_constant\n"
6865 // SPIR-V requires that OpQuantizeToF16 flushes
6866 // any numbers that would end up denormalized in F16 to zero.
6870 std::ldexp(1.5f, -140),
6871 "%cond = OpFOrdEqual %bool %c %c_f32_0\n"
6876 -std::ldexp(1.5f, -140),
6877 "%cond = OpFOrdEqual %bool %c %c_f32_0\n"
6882 std::ldexp(1.0f, -16),
6883 "%cond = OpFOrdEqual %bool %c %c_f32_0\n"
6884 }, // too small positive
6886 "negative_too_small",
6888 -std::ldexp(1.0f, -32),
6889 "%cond = OpFOrdEqual %bool %c %c_f32_0\n"
6890 }, // too small negative
6894 -std::ldexp(1.0f, 128),
6896 "%gz = OpFOrdLessThan %bool %c %c_f32_0\n"
6897 "%inf = OpIsInf %bool %c\n"
6898 "%cond = OpLogicalAnd %bool %gz %inf\n"
6903 std::ldexp(1.0f, 128),
6905 "%gz = OpFOrdGreaterThan %bool %c %c_f32_0\n"
6906 "%inf = OpIsInf %bool %c\n"
6907 "%cond = OpLogicalAnd %bool %gz %inf\n"
6910 "round_to_negative_inf",
6912 -std::ldexp(1.0f, 32),
6914 "%gz = OpFOrdLessThan %bool %c %c_f32_0\n"
6915 "%inf = OpIsInf %bool %c\n"
6916 "%cond = OpLogicalAnd %bool %gz %inf\n"
6921 std::ldexp(1.0f, 16),
6923 "%gz = OpFOrdGreaterThan %bool %c %c_f32_0\n"
6924 "%inf = OpIsInf %bool %c\n"
6925 "%cond = OpLogicalAnd %bool %gz %inf\n"
6930 std::numeric_limits<float>::quiet_NaN(),
6932 // Test for any NaN value, as NaNs are not preserved
6933 "%direct_quant = OpQuantizeToF16 %f32 %test_constant\n"
6934 "%cond = OpIsNan %bool %direct_quant\n"
6939 std::numeric_limits<float>::quiet_NaN(),
6941 // Test for any NaN value, as NaNs are not preserved
6942 "%direct_quant = OpQuantizeToF16 %f32 %test_constant\n"
6943 "%cond = OpIsNan %bool %direct_quant\n"
6946 const char* constants =
6947 "%test_constant = OpConstant %f32 "; // The value will be test.constant.
6949 StringTemplate function (
6950 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6951 "%param1 = OpFunctionParameter %v4f32\n"
6952 "%label_testfun = OpLabel\n"
6953 "%a = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
6954 "%b = OpFAdd %f32 %test_constant %a\n"
6955 "%c = OpQuantizeToF16 %f32 %b\n"
6957 "%v4cond = OpCompositeConstruct %v4bool %cond %cond %cond %cond\n"
6958 "%retval = OpSelect %v4f32 %v4cond %c_v4f32_1_0_0_1 %param1\n"
6959 " OpReturnValue %retval\n"
6963 const char* specDecorations = "OpDecorate %test_constant SpecId 0\n";
6964 const char* specConstants =
6965 "%test_constant = OpSpecConstant %f32 0.\n"
6966 "%c = OpSpecConstantOp %f32 QuantizeToF16 %test_constant\n";
6968 StringTemplate specConstantFunction(
6969 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
6970 "%param1 = OpFunctionParameter %v4f32\n"
6971 "%label_testfun = OpLabel\n"
6973 "%v4cond = OpCompositeConstruct %v4bool %cond %cond %cond %cond\n"
6974 "%retval = OpSelect %v4f32 %v4cond %c_v4f32_1_0_0_1 %param1\n"
6975 " OpReturnValue %retval\n"
6979 for (size_t idx = 0; idx < (sizeof(tests)/sizeof(tests[0])); ++idx)
6981 map<string, string> codeSpecialization;
6982 map<string, string> fragments;
6983 codeSpecialization["condition"] = tests[idx].condition;
6984 fragments["testfun"] = function.specialize(codeSpecialization);
6985 fragments["pre_main"] = string(constants) + tests[idx].constant + "\n";
6986 createTestsForAllStages(tests[idx].name, inputColors, expectedColors, fragments, testCtx);
6989 for (size_t idx = 0; idx < (sizeof(tests)/sizeof(tests[0])); ++idx)
6991 map<string, string> codeSpecialization;
6992 map<string, string> fragments;
6993 vector<deInt32> passConstants;
6994 deInt32 specConstant;
6996 codeSpecialization["condition"] = tests[idx].condition;
6997 fragments["testfun"] = specConstantFunction.specialize(codeSpecialization);
6998 fragments["decoration"] = specDecorations;
6999 fragments["pre_main"] = specConstants;
7001 memcpy(&specConstant, &tests[idx].valueAsFloat, sizeof(float));
7002 passConstants.push_back(specConstant);
7004 createTestsForAllStages(string("spec_const_") + tests[idx].name, inputColors, expectedColors, fragments, passConstants, testCtx);
7008 void createOpQuantizeTwoPossibilityTests(tcu::TestCaseGroup* testCtx)
7010 RGBA inputColors[4] = {
7012 RGBA(0, 0, 255, 255),
7013 RGBA(0, 255, 0, 255),
7014 RGBA(0, 255, 255, 255)
7017 RGBA expectedColors[4] =
7019 RGBA(255, 0, 0, 255),
7020 RGBA(255, 0, 0, 255),
7021 RGBA(255, 0, 0, 255),
7022 RGBA(255, 0, 0, 255)
7025 struct DualFP16Possibility
7030 const char* possibleOutput1;
7031 const char* possibleOutput2;
7034 "positive_round_up_or_round_down",
7036 constructNormalizedFloat(8, 0x300300),
7041 "negative_round_up_or_round_down",
7043 -constructNormalizedFloat(-7, 0x600800),
7050 constructNormalizedFloat(2, 0x01e000),
7055 "carry_to_exponent",
7057 constructNormalizedFloat(1, 0xffe000),
7062 StringTemplate constants (
7063 "%input_const = OpConstant %f32 ${input}\n"
7064 "%possible_solution1 = OpConstant %f32 ${output1}\n"
7065 "%possible_solution2 = OpConstant %f32 ${output2}\n"
7068 StringTemplate specConstants (
7069 "%input_const = OpSpecConstant %f32 0.\n"
7070 "%possible_solution1 = OpConstant %f32 ${output1}\n"
7071 "%possible_solution2 = OpConstant %f32 ${output2}\n"
7074 const char* specDecorations = "OpDecorate %input_const SpecId 0\n";
7076 const char* function =
7077 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
7078 "%param1 = OpFunctionParameter %v4f32\n"
7079 "%label_testfun = OpLabel\n"
7080 "%a = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
7081 // For the purposes of this test we assume that 0.f will always get
7082 // faithfully passed through the pipeline stages.
7083 "%b = OpFAdd %f32 %input_const %a\n"
7084 "%c = OpQuantizeToF16 %f32 %b\n"
7085 "%eq_1 = OpFOrdEqual %bool %c %possible_solution1\n"
7086 "%eq_2 = OpFOrdEqual %bool %c %possible_solution2\n"
7087 "%cond = OpLogicalOr %bool %eq_1 %eq_2\n"
7088 "%v4cond = OpCompositeConstruct %v4bool %cond %cond %cond %cond\n"
7089 "%retval = OpSelect %v4f32 %v4cond %c_v4f32_1_0_0_1 %param1"
7090 " OpReturnValue %retval\n"
7093 for(size_t idx = 0; idx < (sizeof(tests)/sizeof(tests[0])); ++idx) {
7094 map<string, string> fragments;
7095 map<string, string> constantSpecialization;
7097 constantSpecialization["input"] = tests[idx].input;
7098 constantSpecialization["output1"] = tests[idx].possibleOutput1;
7099 constantSpecialization["output2"] = tests[idx].possibleOutput2;
7100 fragments["testfun"] = function;
7101 fragments["pre_main"] = constants.specialize(constantSpecialization);
7102 createTestsForAllStages(tests[idx].name, inputColors, expectedColors, fragments, testCtx);
7105 for(size_t idx = 0; idx < (sizeof(tests)/sizeof(tests[0])); ++idx) {
7106 map<string, string> fragments;
7107 map<string, string> constantSpecialization;
7108 vector<deInt32> passConstants;
7109 deInt32 specConstant;
7111 constantSpecialization["output1"] = tests[idx].possibleOutput1;
7112 constantSpecialization["output2"] = tests[idx].possibleOutput2;
7113 fragments["testfun"] = function;
7114 fragments["decoration"] = specDecorations;
7115 fragments["pre_main"] = specConstants.specialize(constantSpecialization);
7117 memcpy(&specConstant, &tests[idx].inputAsFloat, sizeof(float));
7118 passConstants.push_back(specConstant);
7120 createTestsForAllStages(string("spec_const_") + tests[idx].name, inputColors, expectedColors, fragments, passConstants, testCtx);
7124 tcu::TestCaseGroup* createOpQuantizeTests(tcu::TestContext& testCtx)
7126 de::MovePtr<tcu::TestCaseGroup> opQuantizeTests (new tcu::TestCaseGroup(testCtx, "opquantize", "Test OpQuantizeToF16"));
7127 createOpQuantizeSingleOptionTests(opQuantizeTests.get());
7128 createOpQuantizeTwoPossibilityTests(opQuantizeTests.get());
7129 return opQuantizeTests.release();
7132 struct ShaderPermutation
7134 deUint8 vertexPermutation;
7135 deUint8 geometryPermutation;
7136 deUint8 tesscPermutation;
7137 deUint8 tessePermutation;
7138 deUint8 fragmentPermutation;
7141 ShaderPermutation getShaderPermutation(deUint8 inputValue)
7143 ShaderPermutation permutation =
7145 static_cast<deUint8>(inputValue & 0x10? 1u: 0u),
7146 static_cast<deUint8>(inputValue & 0x08? 1u: 0u),
7147 static_cast<deUint8>(inputValue & 0x04? 1u: 0u),
7148 static_cast<deUint8>(inputValue & 0x02? 1u: 0u),
7149 static_cast<deUint8>(inputValue & 0x01? 1u: 0u)
7154 tcu::TestCaseGroup* createModuleTests(tcu::TestContext& testCtx)
7156 RGBA defaultColors[4];
7157 RGBA invertedColors[4];
7158 de::MovePtr<tcu::TestCaseGroup> moduleTests (new tcu::TestCaseGroup(testCtx, "module", "Multiple entry points into shaders"));
7160 const ShaderElement combinedPipeline[] =
7162 ShaderElement("module", "main", VK_SHADER_STAGE_VERTEX_BIT),
7163 ShaderElement("module", "main", VK_SHADER_STAGE_GEOMETRY_BIT),
7164 ShaderElement("module", "main", VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT),
7165 ShaderElement("module", "main", VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT),
7166 ShaderElement("module", "main", VK_SHADER_STAGE_FRAGMENT_BIT)
7169 getDefaultColors(defaultColors);
7170 getInvertedDefaultColors(invertedColors);
7171 addFunctionCaseWithPrograms<InstanceContext>(moduleTests.get(), "same_module", "", createCombinedModule, runAndVerifyDefaultPipeline, createInstanceContext(combinedPipeline, map<string, string>()));
7173 const char* numbers[] =
7178 for (deInt8 idx = 0; idx < 32; ++idx)
7180 ShaderPermutation permutation = getShaderPermutation(idx);
7181 string name = string("vert") + numbers[permutation.vertexPermutation] + "_geom" + numbers[permutation.geometryPermutation] + "_tessc" + numbers[permutation.tesscPermutation] + "_tesse" + numbers[permutation.tessePermutation] + "_frag" + numbers[permutation.fragmentPermutation];
7182 const ShaderElement pipeline[] =
7184 ShaderElement("vert", string("vert") + numbers[permutation.vertexPermutation], VK_SHADER_STAGE_VERTEX_BIT),
7185 ShaderElement("geom", string("geom") + numbers[permutation.geometryPermutation], VK_SHADER_STAGE_GEOMETRY_BIT),
7186 ShaderElement("tessc", string("tessc") + numbers[permutation.tesscPermutation], VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT),
7187 ShaderElement("tesse", string("tesse") + numbers[permutation.tessePermutation], VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT),
7188 ShaderElement("frag", string("frag") + numbers[permutation.fragmentPermutation], VK_SHADER_STAGE_FRAGMENT_BIT)
7191 // If there are an even number of swaps, then it should be no-op.
7192 // If there are an odd number, the color should be flipped.
7193 if ((permutation.vertexPermutation + permutation.geometryPermutation + permutation.tesscPermutation + permutation.tessePermutation + permutation.fragmentPermutation) % 2 == 0)
7195 addFunctionCaseWithPrograms<InstanceContext>(moduleTests.get(), name, "", createMultipleEntries, runAndVerifyDefaultPipeline, createInstanceContext(pipeline, defaultColors, defaultColors, map<string, string>()));
7199 addFunctionCaseWithPrograms<InstanceContext>(moduleTests.get(), name, "", createMultipleEntries, runAndVerifyDefaultPipeline, createInstanceContext(pipeline, defaultColors, invertedColors, map<string, string>()));
7202 return moduleTests.release();
7205 tcu::TestCaseGroup* createLoopTests(tcu::TestContext& testCtx)
7207 de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, "loop", "Looping control flow"));
7208 RGBA defaultColors[4];
7209 getDefaultColors(defaultColors);
7210 map<string, string> fragments;
7211 fragments["pre_main"] =
7212 "%c_f32_5 = OpConstant %f32 5.\n";
7214 // A loop with a single block. The Continue Target is the loop block
7215 // itself. In SPIR-V terms, the "loop construct" contains no blocks at all
7216 // -- the "continue construct" forms the entire loop.
7217 fragments["testfun"] =
7218 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
7219 "%param1 = OpFunctionParameter %v4f32\n"
7221 "%entry = OpLabel\n"
7222 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
7225 ";adds and subtracts 1.0 to %val in alternate iterations\n"
7227 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %loop\n"
7228 "%delta = OpPhi %f32 %c_f32_1 %entry %minus_delta %loop\n"
7229 "%val1 = OpPhi %f32 %val0 %entry %val %loop\n"
7230 "%val = OpFAdd %f32 %val1 %delta\n"
7231 "%minus_delta = OpFSub %f32 %c_f32_0 %delta\n"
7232 "%count__ = OpISub %i32 %count %c_i32_1\n"
7233 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
7234 "OpLoopMerge %exit %loop None\n"
7235 "OpBranchConditional %again %loop %exit\n"
7238 "%result = OpVectorInsertDynamic %v4f32 %param1 %val %c_i32_0\n"
7239 "OpReturnValue %result\n"
7243 createTestsForAllStages("single_block", defaultColors, defaultColors, fragments, testGroup.get());
7245 // Body comprised of multiple basic blocks.
7246 const StringTemplate multiBlock(
7247 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
7248 "%param1 = OpFunctionParameter %v4f32\n"
7250 "%entry = OpLabel\n"
7251 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
7254 ";adds and subtracts 1.0 to %val in alternate iterations\n"
7256 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %gather\n"
7257 "%delta = OpPhi %f32 %c_f32_1 %entry %delta_next %gather\n"
7258 "%val1 = OpPhi %f32 %val0 %entry %val %gather\n"
7259 // There are several possibilities for the Continue Target below. Each
7260 // will be specialized into a separate test case.
7261 "OpLoopMerge %exit ${continue_target} None\n"
7265 ";delta_next = (delta > 0) ? -1 : 1;\n"
7266 "%gt0 = OpFOrdGreaterThan %bool %delta %c_f32_0\n"
7267 "OpSelectionMerge %gather DontFlatten\n"
7268 "OpBranchConditional %gt0 %even %odd ;tells us if %count is even or odd\n"
7271 "OpBranch %gather\n"
7274 "OpBranch %gather\n"
7276 "%gather = OpLabel\n"
7277 "%delta_next = OpPhi %f32 %c_f32_n1 %even %c_f32_1 %odd\n"
7278 "%val = OpFAdd %f32 %val1 %delta\n"
7279 "%count__ = OpISub %i32 %count %c_i32_1\n"
7280 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
7281 "OpBranchConditional %again %loop %exit\n"
7284 "%result = OpVectorInsertDynamic %v4f32 %param1 %val %c_i32_0\n"
7285 "OpReturnValue %result\n"
7289 map<string, string> continue_target;
7291 // The Continue Target is the loop block itself.
7292 continue_target["continue_target"] = "%loop";
7293 fragments["testfun"] = multiBlock.specialize(continue_target);
7294 createTestsForAllStages("multi_block_continue_construct", defaultColors, defaultColors, fragments, testGroup.get());
7296 // The Continue Target is at the end of the loop.
7297 continue_target["continue_target"] = "%gather";
7298 fragments["testfun"] = multiBlock.specialize(continue_target);
7299 createTestsForAllStages("multi_block_loop_construct", defaultColors, defaultColors, fragments, testGroup.get());
7301 // A loop with continue statement.
7302 fragments["testfun"] =
7303 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
7304 "%param1 = OpFunctionParameter %v4f32\n"
7306 "%entry = OpLabel\n"
7307 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
7310 ";adds 4, 3, and 1 to %val0 (skips 2)\n"
7312 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %continue\n"
7313 "%val1 = OpPhi %f32 %val0 %entry %val %continue\n"
7314 "OpLoopMerge %exit %continue None\n"
7318 ";skip if %count==2\n"
7319 "%eq2 = OpIEqual %bool %count %c_i32_2\n"
7320 "OpSelectionMerge %continue DontFlatten\n"
7321 "OpBranchConditional %eq2 %continue %body\n"
7324 "%fcount = OpConvertSToF %f32 %count\n"
7325 "%val2 = OpFAdd %f32 %val1 %fcount\n"
7326 "OpBranch %continue\n"
7328 "%continue = OpLabel\n"
7329 "%val = OpPhi %f32 %val2 %body %val1 %if\n"
7330 "%count__ = OpISub %i32 %count %c_i32_1\n"
7331 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
7332 "OpBranchConditional %again %loop %exit\n"
7335 "%same = OpFSub %f32 %val %c_f32_8\n"
7336 "%result = OpVectorInsertDynamic %v4f32 %param1 %same %c_i32_0\n"
7337 "OpReturnValue %result\n"
7339 createTestsForAllStages("continue", defaultColors, defaultColors, fragments, testGroup.get());
7341 // A loop with break.
7342 fragments["testfun"] =
7343 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
7344 "%param1 = OpFunctionParameter %v4f32\n"
7346 "%entry = OpLabel\n"
7347 ";param1 components are between 0 and 1, so dot product is 4 or less\n"
7348 "%dot = OpDot %f32 %param1 %param1\n"
7349 "%div = OpFDiv %f32 %dot %c_f32_5\n"
7350 "%zero = OpConvertFToU %u32 %div\n"
7351 "%two = OpIAdd %i32 %zero %c_i32_2\n"
7352 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
7355 ";adds 4 and 3 to %val0 (exits early)\n"
7357 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %continue\n"
7358 "%val1 = OpPhi %f32 %val0 %entry %val2 %continue\n"
7359 "OpLoopMerge %exit %continue None\n"
7363 ";end loop if %count==%two\n"
7364 "%above2 = OpSGreaterThan %bool %count %two\n"
7365 "OpSelectionMerge %continue DontFlatten\n"
7366 "OpBranchConditional %above2 %body %exit\n"
7369 "%fcount = OpConvertSToF %f32 %count\n"
7370 "%val2 = OpFAdd %f32 %val1 %fcount\n"
7371 "OpBranch %continue\n"
7373 "%continue = OpLabel\n"
7374 "%count__ = OpISub %i32 %count %c_i32_1\n"
7375 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
7376 "OpBranchConditional %again %loop %exit\n"
7379 "%val_post = OpPhi %f32 %val2 %continue %val1 %if\n"
7380 "%same = OpFSub %f32 %val_post %c_f32_7\n"
7381 "%result = OpVectorInsertDynamic %v4f32 %param1 %same %c_i32_0\n"
7382 "OpReturnValue %result\n"
7384 createTestsForAllStages("break", defaultColors, defaultColors, fragments, testGroup.get());
7386 // A loop with return.
7387 fragments["testfun"] =
7388 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
7389 "%param1 = OpFunctionParameter %v4f32\n"
7391 "%entry = OpLabel\n"
7392 ";param1 components are between 0 and 1, so dot product is 4 or less\n"
7393 "%dot = OpDot %f32 %param1 %param1\n"
7394 "%div = OpFDiv %f32 %dot %c_f32_5\n"
7395 "%zero = OpConvertFToU %u32 %div\n"
7396 "%two = OpIAdd %i32 %zero %c_i32_2\n"
7397 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
7400 ";returns early without modifying %param1\n"
7402 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %continue\n"
7403 "%val1 = OpPhi %f32 %val0 %entry %val2 %continue\n"
7404 "OpLoopMerge %exit %continue None\n"
7408 ";return if %count==%two\n"
7409 "%above2 = OpSGreaterThan %bool %count %two\n"
7410 "OpSelectionMerge %continue DontFlatten\n"
7411 "OpBranchConditional %above2 %body %early_exit\n"
7413 "%early_exit = OpLabel\n"
7414 "OpReturnValue %param1\n"
7417 "%fcount = OpConvertSToF %f32 %count\n"
7418 "%val2 = OpFAdd %f32 %val1 %fcount\n"
7419 "OpBranch %continue\n"
7421 "%continue = OpLabel\n"
7422 "%count__ = OpISub %i32 %count %c_i32_1\n"
7423 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
7424 "OpBranchConditional %again %loop %exit\n"
7427 ";should never get here, so return an incorrect result\n"
7428 "%result = OpVectorInsertDynamic %v4f32 %param1 %val2 %c_i32_0\n"
7429 "OpReturnValue %result\n"
7431 createTestsForAllStages("return", defaultColors, defaultColors, fragments, testGroup.get());
7433 return testGroup.release();
7436 // Adds a new test to group using custom fragments for the tessellation-control
7437 // stage and passthrough fragments for all other stages. Uses default colors
7438 // for input and expected output.
7439 void addTessCtrlTest(tcu::TestCaseGroup* group, const char* name, const map<string, string>& fragments)
7441 RGBA defaultColors[4];
7442 getDefaultColors(defaultColors);
7443 const ShaderElement pipelineStages[] =
7445 ShaderElement("vert", "main", VK_SHADER_STAGE_VERTEX_BIT),
7446 ShaderElement("tessc", "main", VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT),
7447 ShaderElement("tesse", "main", VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT),
7448 ShaderElement("frag", "main", VK_SHADER_STAGE_FRAGMENT_BIT),
7451 addFunctionCaseWithPrograms<InstanceContext>(group, name, "", addShaderCodeCustomTessControl,
7452 runAndVerifyDefaultPipeline, createInstanceContext(
7453 pipelineStages, defaultColors, defaultColors, fragments, StageToSpecConstantMap()));
7456 // A collection of tests putting OpControlBarrier in places GLSL forbids but SPIR-V allows.
7457 tcu::TestCaseGroup* createBarrierTests(tcu::TestContext& testCtx)
7459 de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, "barrier", "OpControlBarrier"));
7460 map<string, string> fragments;
7462 // A barrier inside a function body.
7463 fragments["pre_main"] =
7464 "%Workgroup = OpConstant %i32 2\n"
7465 "%SequentiallyConsistent = OpConstant %i32 0x10\n";
7466 fragments["testfun"] =
7467 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
7468 "%param1 = OpFunctionParameter %v4f32\n"
7469 "%label_testfun = OpLabel\n"
7470 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n"
7471 "OpReturnValue %param1\n"
7473 addTessCtrlTest(testGroup.get(), "in_function", fragments);
7475 // Common setup code for the following tests.
7476 fragments["pre_main"] =
7477 "%Workgroup = OpConstant %i32 2\n"
7478 "%SequentiallyConsistent = OpConstant %i32 0x10\n"
7479 "%c_f32_5 = OpConstant %f32 5.\n";
7480 const string setupPercentZero = // Begins %test_code function with code that sets %zero to 0u but cannot be optimized away.
7481 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
7482 "%param1 = OpFunctionParameter %v4f32\n"
7483 "%entry = OpLabel\n"
7484 ";param1 components are between 0 and 1, so dot product is 4 or less\n"
7485 "%dot = OpDot %f32 %param1 %param1\n"
7486 "%div = OpFDiv %f32 %dot %c_f32_5\n"
7487 "%zero = OpConvertFToU %u32 %div\n";
7489 // Barriers inside OpSwitch branches.
7490 fragments["testfun"] =
7492 "OpSelectionMerge %switch_exit None\n"
7493 "OpSwitch %zero %switch_default 0 %case0 1 %case1 ;should always go to %case0\n"
7495 "%case1 = OpLabel\n"
7496 ";This barrier should never be executed, but its presence makes test failure more likely when there's a bug.\n"
7497 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n"
7498 "%wrong_branch_alert1 = OpVectorInsertDynamic %v4f32 %param1 %c_f32_0_5 %c_i32_0\n"
7499 "OpBranch %switch_exit\n"
7501 "%switch_default = OpLabel\n"
7502 "%wrong_branch_alert2 = OpVectorInsertDynamic %v4f32 %param1 %c_f32_0_5 %c_i32_0\n"
7503 ";This barrier should never be executed, but its presence makes test failure more likely when there's a bug.\n"
7504 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n"
7505 "OpBranch %switch_exit\n"
7507 "%case0 = OpLabel\n"
7508 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n"
7509 "OpBranch %switch_exit\n"
7511 "%switch_exit = OpLabel\n"
7512 "%ret = OpPhi %v4f32 %param1 %case0 %wrong_branch_alert1 %case1 %wrong_branch_alert2 %switch_default\n"
7513 "OpReturnValue %ret\n"
7515 addTessCtrlTest(testGroup.get(), "in_switch", fragments);
7517 // Barriers inside if-then-else.
7518 fragments["testfun"] =
7520 "%eq0 = OpIEqual %bool %zero %c_u32_0\n"
7521 "OpSelectionMerge %exit DontFlatten\n"
7522 "OpBranchConditional %eq0 %then %else\n"
7525 ";This barrier should never be executed, but its presence makes test failure more likely when there's a bug.\n"
7526 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n"
7527 "%wrong_branch_alert = OpVectorInsertDynamic %v4f32 %param1 %c_f32_0_5 %c_i32_0\n"
7531 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n"
7535 "%ret = OpPhi %v4f32 %param1 %then %wrong_branch_alert %else\n"
7536 "OpReturnValue %ret\n"
7538 addTessCtrlTest(testGroup.get(), "in_if", fragments);
7540 // A barrier after control-flow reconvergence, tempting the compiler to attempt something like this:
7541 // http://lists.llvm.org/pipermail/llvm-dev/2009-October/026317.html.
7542 fragments["testfun"] =
7544 "%thread_id = OpLoad %i32 %BP_gl_InvocationID\n"
7545 "%thread0 = OpIEqual %bool %thread_id %c_i32_0\n"
7546 "OpSelectionMerge %exit DontFlatten\n"
7547 "OpBranchConditional %thread0 %then %else\n"
7550 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
7554 "%val1 = OpVectorExtractDynamic %f32 %param1 %zero\n"
7558 "%val = OpPhi %f32 %val0 %else %val1 %then\n"
7559 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n"
7560 "%ret = OpVectorInsertDynamic %v4f32 %param1 %val %zero\n"
7561 "OpReturnValue %ret\n"
7563 addTessCtrlTest(testGroup.get(), "after_divergent_if", fragments);
7565 // A barrier inside a loop.
7566 fragments["pre_main"] =
7567 "%Workgroup = OpConstant %i32 2\n"
7568 "%SequentiallyConsistent = OpConstant %i32 0x10\n"
7569 "%c_f32_10 = OpConstant %f32 10.\n";
7570 fragments["testfun"] =
7571 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
7572 "%param1 = OpFunctionParameter %v4f32\n"
7573 "%entry = OpLabel\n"
7574 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
7577 ";adds 4, 3, 2, and 1 to %val0\n"
7579 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %loop\n"
7580 "%val1 = OpPhi %f32 %val0 %entry %val %loop\n"
7581 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n"
7582 "%fcount = OpConvertSToF %f32 %count\n"
7583 "%val = OpFAdd %f32 %val1 %fcount\n"
7584 "%count__ = OpISub %i32 %count %c_i32_1\n"
7585 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n"
7586 "OpLoopMerge %exit %loop None\n"
7587 "OpBranchConditional %again %loop %exit\n"
7590 "%same = OpFSub %f32 %val %c_f32_10\n"
7591 "%ret = OpVectorInsertDynamic %v4f32 %param1 %same %c_i32_0\n"
7592 "OpReturnValue %ret\n"
7594 addTessCtrlTest(testGroup.get(), "in_loop", fragments);
7596 return testGroup.release();
7599 // Test for the OpFRem instruction.
7600 tcu::TestCaseGroup* createFRemTests(tcu::TestContext& testCtx)
7602 de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, "frem", "OpFRem"));
7603 map<string, string> fragments;
7604 RGBA inputColors[4];
7605 RGBA outputColors[4];
7607 fragments["pre_main"] =
7608 "%c_f32_3 = OpConstant %f32 3.0\n"
7609 "%c_f32_n3 = OpConstant %f32 -3.0\n"
7610 "%c_f32_4 = OpConstant %f32 4.0\n"
7611 "%c_f32_p75 = OpConstant %f32 0.75\n"
7612 "%c_v4f32_p75_p75_p75_p75 = OpConstantComposite %v4f32 %c_f32_p75 %c_f32_p75 %c_f32_p75 %c_f32_p75 \n"
7613 "%c_v4f32_4_4_4_4 = OpConstantComposite %v4f32 %c_f32_4 %c_f32_4 %c_f32_4 %c_f32_4\n"
7614 "%c_v4f32_3_n3_3_n3 = OpConstantComposite %v4f32 %c_f32_3 %c_f32_n3 %c_f32_3 %c_f32_n3\n";
7616 // The test does the following.
7617 // vec4 result = (param1 * 8.0) - 4.0;
7618 // return (frem(result.x,3) + 0.75, frem(result.y, -3) + 0.75, 0, 1)
7619 fragments["testfun"] =
7620 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
7621 "%param1 = OpFunctionParameter %v4f32\n"
7622 "%label_testfun = OpLabel\n"
7623 "%v_times_8 = OpVectorTimesScalar %v4f32 %param1 %c_f32_8\n"
7624 "%minus_4 = OpFSub %v4f32 %v_times_8 %c_v4f32_4_4_4_4\n"
7625 "%frem = OpFRem %v4f32 %minus_4 %c_v4f32_3_n3_3_n3\n"
7626 "%added = OpFAdd %v4f32 %frem %c_v4f32_p75_p75_p75_p75\n"
7627 "%xyz_1 = OpVectorInsertDynamic %v4f32 %added %c_f32_1 %c_i32_3\n"
7628 "%xy_0_1 = OpVectorInsertDynamic %v4f32 %xyz_1 %c_f32_0 %c_i32_2\n"
7629 "OpReturnValue %xy_0_1\n"
7633 inputColors[0] = RGBA(16, 16, 0, 255);
7634 inputColors[1] = RGBA(232, 232, 0, 255);
7635 inputColors[2] = RGBA(232, 16, 0, 255);
7636 inputColors[3] = RGBA(16, 232, 0, 255);
7638 outputColors[0] = RGBA(64, 64, 0, 255);
7639 outputColors[1] = RGBA(255, 255, 0, 255);
7640 outputColors[2] = RGBA(255, 64, 0, 255);
7641 outputColors[3] = RGBA(64, 255, 0, 255);
7643 createTestsForAllStages("frem", inputColors, outputColors, fragments, testGroup.get());
7644 return testGroup.release();
7647 tcu::TestCaseGroup* createInstructionTests (tcu::TestContext& testCtx)
7649 de::MovePtr<tcu::TestCaseGroup> instructionTests (new tcu::TestCaseGroup(testCtx, "instruction", "Instructions with special opcodes/operands"));
7650 de::MovePtr<tcu::TestCaseGroup> computeTests (new tcu::TestCaseGroup(testCtx, "compute", "Compute Instructions with special opcodes/operands"));
7651 de::MovePtr<tcu::TestCaseGroup> graphicsTests (new tcu::TestCaseGroup(testCtx, "graphics", "Graphics Instructions with special opcodes/operands"));
7653 computeTests->addChild(createOpNopGroup(testCtx));
7654 computeTests->addChild(createOpLineGroup(testCtx));
7655 computeTests->addChild(createOpNoLineGroup(testCtx));
7656 computeTests->addChild(createOpConstantNullGroup(testCtx));
7657 computeTests->addChild(createOpConstantCompositeGroup(testCtx));
7658 computeTests->addChild(createOpConstantUsageGroup(testCtx));
7659 computeTests->addChild(createSpecConstantGroup(testCtx));
7660 computeTests->addChild(createOpSourceGroup(testCtx));
7661 computeTests->addChild(createOpSourceExtensionGroup(testCtx));
7662 computeTests->addChild(createDecorationGroupGroup(testCtx));
7663 computeTests->addChild(createOpPhiGroup(testCtx));
7664 computeTests->addChild(createLoopControlGroup(testCtx));
7665 computeTests->addChild(createFunctionControlGroup(testCtx));
7666 computeTests->addChild(createSelectionControlGroup(testCtx));
7667 computeTests->addChild(createBlockOrderGroup(testCtx));
7668 computeTests->addChild(createMultipleShaderGroup(testCtx));
7669 computeTests->addChild(createMemoryAccessGroup(testCtx));
7670 computeTests->addChild(createOpCopyMemoryGroup(testCtx));
7671 computeTests->addChild(createOpCopyObjectGroup(testCtx));
7672 computeTests->addChild(createNoContractionGroup(testCtx));
7673 computeTests->addChild(createOpUndefGroup(testCtx));
7674 computeTests->addChild(createOpUnreachableGroup(testCtx));
7675 computeTests ->addChild(createOpQuantizeToF16Group(testCtx));
7676 computeTests ->addChild(createOpFRemGroup(testCtx));
7678 RGBA defaultColors[4];
7679 getDefaultColors(defaultColors);
7681 de::MovePtr<tcu::TestCaseGroup> opnopTests (new tcu::TestCaseGroup(testCtx, "opnop", "Test OpNop"));
7682 map<string, string> opNopFragments;
7683 opNopFragments["testfun"] =
7684 "%test_code = OpFunction %v4f32 None %v4f32_function\n"
7685 "%param1 = OpFunctionParameter %v4f32\n"
7686 "%label_testfun = OpLabel\n"
7695 "%a = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n"
7696 "%b = OpFAdd %f32 %a %a\n"
7698 "%c = OpFSub %f32 %b %a\n"
7699 "%ret = OpVectorInsertDynamic %v4f32 %param1 %c %c_i32_0\n"
7702 "OpReturnValue %ret\n"
7705 createTestsForAllStages("opnop", defaultColors, defaultColors, opNopFragments, opnopTests.get());
7708 graphicsTests->addChild(opnopTests.release());
7709 graphicsTests->addChild(createOpSourceTests(testCtx));
7710 graphicsTests->addChild(createOpSourceContinuedTests(testCtx));
7711 graphicsTests->addChild(createOpLineTests(testCtx));
7712 graphicsTests->addChild(createOpNoLineTests(testCtx));
7713 graphicsTests->addChild(createOpConstantNullTests(testCtx));
7714 graphicsTests->addChild(createOpConstantCompositeTests(testCtx));
7715 graphicsTests->addChild(createMemoryAccessTests(testCtx));
7716 graphicsTests->addChild(createOpUndefTests(testCtx));
7717 graphicsTests->addChild(createSelectionBlockOrderTests(testCtx));
7718 graphicsTests->addChild(createModuleTests(testCtx));
7719 graphicsTests->addChild(createSwitchBlockOrderTests(testCtx));
7720 graphicsTests->addChild(createOpPhiTests(testCtx));
7721 graphicsTests->addChild(createNoContractionTests(testCtx));
7722 graphicsTests->addChild(createOpQuantizeTests(testCtx));
7723 graphicsTests->addChild(createLoopTests(testCtx));
7724 graphicsTests->addChild(createSpecConstantTests(testCtx));
7725 graphicsTests->addChild(createSpecConstantOpQuantizeToF16Group(testCtx));
7726 graphicsTests->addChild(createBarrierTests(testCtx));
7727 graphicsTests->addChild(createDecorationGroupTests(testCtx));
7728 graphicsTests->addChild(createFRemTests(testCtx));
7730 instructionTests->addChild(computeTests.release());
7731 instructionTests->addChild(graphicsTests.release());
7733 return instructionTests.release();