Merge vk-gl-cts/opengl-es-cts-3.2.4 into vk-gl-cts/master
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / modules / vulkan / api / vktApiSmokeTests.cpp
1 /*-------------------------------------------------------------------------
2  * Vulkan Conformance Tests
3  * ------------------------
4  *
5  * Copyright (c) 2015 Google Inc.
6  *
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  *//*!
20  * \file
21  * \brief Simple Smoke Tests
22  *//*--------------------------------------------------------------------*/
23
24 #include "vktApiTests.hpp"
25
26 #include "vktTestCaseUtil.hpp"
27
28 #include "vkDefs.hpp"
29 #include "vkPlatform.hpp"
30 #include "vkStrUtil.hpp"
31 #include "vkRef.hpp"
32 #include "vkRefUtil.hpp"
33 #include "vkQueryUtil.hpp"
34 #include "vkMemUtil.hpp"
35 #include "vkDeviceUtil.hpp"
36 #include "vkPrograms.hpp"
37 #include "vkTypeUtil.hpp"
38 #include "vkImageUtil.hpp"
39
40 #include "tcuTestLog.hpp"
41 #include "tcuFormatUtil.hpp"
42 #include "tcuTextureUtil.hpp"
43 #include "tcuImageCompare.hpp"
44
45 #include "rrRenderer.hpp"
46
47 #include "deUniquePtr.hpp"
48
49 namespace vkt
50 {
51 namespace api
52 {
53
54 namespace
55 {
56
57 using namespace vk;
58 using std::vector;
59 using tcu::TestLog;
60 using de::UniquePtr;
61
62 tcu::TestStatus createSamplerTest (Context& context)
63 {
64         const VkDevice                  vkDevice        = context.getDevice();
65         const DeviceInterface&  vk                      = context.getDeviceInterface();
66
67         {
68                 const struct VkSamplerCreateInfo                samplerInfo     =
69                 {
70                         VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,          // sType
71                         DE_NULL,                                                                        // pNext
72                         0u,                                                                                     // flags
73                         VK_FILTER_NEAREST,                                                      // magFilter
74                         VK_FILTER_NEAREST,                                                      // minFilter
75                         VK_SAMPLER_MIPMAP_MODE_NEAREST,                         // mipmapMode
76                         VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,          // addressModeU
77                         VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,          // addressModeV
78                         VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,          // addressModeW
79                         0.0f,                                                                           // mipLodBias
80                         VK_FALSE,                                                                       // anisotropyEnable
81                         1.0f,                                                                           // maxAnisotropy
82                         DE_FALSE,                                                                       // compareEnable
83                         VK_COMPARE_OP_ALWAYS,                                           // compareOp
84                         0.0f,                                                                           // minLod
85                         0.0f,                                                                           // maxLod
86                         VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK,        // borderColor
87                         VK_FALSE,                                                                       // unnormalizedCoords
88                 };
89
90                 Move<VkSampler>                 tmpSampler      = createSampler(vk, vkDevice, &samplerInfo);
91                 Move<VkSampler>                 tmp2Sampler;
92
93                 tmp2Sampler = tmpSampler;
94
95                 const Unique<VkSampler> sampler         (tmp2Sampler);
96         }
97
98         return tcu::TestStatus::pass("Creating sampler succeeded");
99 }
100
101 void createShaderProgs (SourceCollections& dst)
102 {
103         dst.glslSources.add("test") << glu::VertexSource(
104                 "#version 310 es\n"
105                 "layout(location = 0) in highp vec4 a_position;\n"
106                 "void main (void) { gl_Position = a_position; }\n");
107 }
108
109 tcu::TestStatus createShaderModuleTest (Context& context)
110 {
111         const VkDevice                                  vkDevice        = context.getDevice();
112         const DeviceInterface&                  vk                      = context.getDeviceInterface();
113         const Unique<VkShaderModule>    shader          (createShaderModule(vk, vkDevice, context.getBinaryCollection().get("test"), 0));
114
115         return tcu::TestStatus::pass("Creating shader module succeeded");
116 }
117
118 void createTriangleAsmProgs (SourceCollections& dst)
119 {
120         dst.spirvAsmSources.add("vert") <<
121                 "                OpCapability Shader\n"
122                 "%1 =    OpExtInstImport \"GLSL.std.450\"\n"
123                 "                OpMemoryModel Logical GLSL450\n"
124                 "                OpEntryPoint Vertex %4 \"main\" %10 %12 %16 %17\n"
125                 "                OpSource ESSL 300\n"
126                 "                OpName %4 \"main\"\n"
127                 "                OpName %10 \"gl_Position\"\n"
128                 "                OpName %12 \"a_position\"\n"
129                 "                OpName %16 \"gl_VertexIndex\"\n"
130                 "                OpName %17 \"gl_InstanceIndex\"\n"
131                 "                OpDecorate %10 BuiltIn Position\n"
132                 "                OpDecorate %12 Location 0\n"
133                 "                OpDecorate %16 BuiltIn VertexIndex\n"
134                 "                OpDecorate %17 BuiltIn InstanceIndex\n"
135                 "%2 =    OpTypeVoid\n"
136                 "%3 =    OpTypeFunction %2\n"
137                 "%7 =    OpTypeFloat 32\n"
138                 "%8 =    OpTypeVector %7 4\n"
139                 "%9 =    OpTypePointer Output %8\n"
140                 "%10 =   OpVariable %9 Output\n"
141                 "%11 =   OpTypePointer Input %8\n"
142                 "%12 =   OpVariable %11 Input\n"
143                 "%14 =   OpTypeInt 32 1\n"
144                 "%15 =   OpTypePointer Input %14\n"
145                 "%16 =   OpVariable %15 Input\n"
146                 "%17 =   OpVariable %15 Input\n"
147                 "%4 =    OpFunction %2 None %3\n"
148                 "%5 =    OpLabel\n"
149                 "%13 =   OpLoad %8 %12\n"
150                 "                OpStore %10 %13\n"
151                 "                OpBranch %6\n"
152                 "%6 =    OpLabel\n"
153                 "                OpReturn\n"
154                 "                OpFunctionEnd\n";
155         dst.spirvAsmSources.add("frag") <<
156                 "               OpCapability Shader\n"
157                 "%1 =   OpExtInstImport \"GLSL.std.450\"\n"
158                 "               OpMemoryModel Logical GLSL450\n"
159                 "               OpEntryPoint Fragment %4 \"main\" %10\n"
160                 "               OpExecutionMode %4 OriginLowerLeft\n"
161                 "               OpSource ESSL 300\n"
162                 "               OpName %4 \"main\"\n"
163                 "               OpName %10 \"o_color\"\n"
164                 "               OpDecorate %10 RelaxedPrecision\n"
165                 "               OpDecorate %10 Location 0\n"
166                 "%2 =   OpTypeVoid\n"
167                 "%3 =   OpTypeFunction %2\n"
168                 "%7 =   OpTypeFloat 32\n"
169                 "%8 =   OpTypeVector %7 4\n"
170                 "%9 =   OpTypePointer Output %8\n"
171                 "%10 =  OpVariable %9 Output\n"
172                 "%11 =  OpConstant %7 1065353216\n"
173                 "%12 =  OpConstant %7 0\n"
174                 "%13 =  OpConstantComposite %8 %11 %12 %11 %11\n"
175                 "%4 =   OpFunction %2 None %3\n"
176                 "%5 =   OpLabel\n"
177                 "               OpStore %10 %13\n"
178                 "               OpBranch %6\n"
179                 "%6 =   OpLabel\n"
180                 "               OpReturn\n"
181                 "               OpFunctionEnd\n";
182 }
183
184 void createTriangleProgs (SourceCollections& dst)
185 {
186         dst.glslSources.add("vert") << glu::VertexSource(
187                 "#version 310 es\n"
188                 "layout(location = 0) in highp vec4 a_position;\n"
189                 "void main (void) { gl_Position = a_position; }\n");
190         dst.glslSources.add("frag") << glu::FragmentSource(
191                 "#version 310 es\n"
192                 "layout(location = 0) out lowp vec4 o_color;\n"
193                 "void main (void) { o_color = vec4(1.0, 0.0, 1.0, 1.0); }\n");
194 }
195
196 void createProgsNoOpName (SourceCollections& dst)
197 {
198         dst.spirvAsmSources.add("vert") <<
199                 "OpCapability Shader\n"
200                 "%1 = OpExtInstImport \"GLSL.std.450\"\n"
201                 "OpMemoryModel Logical GLSL450\n"
202                 "OpEntryPoint Vertex %4 \"main\" %20 %22 %26\n"
203                 "OpSource ESSL 310\n"
204                 "OpMemberDecorate %18 0 BuiltIn Position\n"
205                 "OpMemberDecorate %18 1 BuiltIn PointSize\n"
206                 "OpDecorate %18 Block\n"
207                 "OpDecorate %22 Location 0\n"
208                 "OpDecorate %26 Location 2\n"
209                 "%2 = OpTypeVoid\n"
210                 "%3 = OpTypeFunction %2\n"
211                 "%6 = OpTypeFloat 32\n"
212                 "%7 = OpTypeVector %6 4\n"
213                 "%8 = OpTypeStruct %7\n"
214                 "%9 = OpTypePointer Function %8\n"
215                 "%11 = OpTypeInt 32 1\n"
216                 "%12 = OpConstant %11 0\n"
217                 "%13 = OpConstant %6 1\n"
218                 "%14 = OpConstant %6 0\n"
219                 "%15 = OpConstantComposite %7 %13 %14 %13 %13\n"
220                 "%16 = OpTypePointer Function %7\n"
221                 "%18 = OpTypeStruct %7 %6\n"
222                 "%19 = OpTypePointer Output %18\n"
223                 "%20 = OpVariable %19 Output\n"
224                 "%21 = OpTypePointer Input %7\n"
225                 "%22 = OpVariable %21 Input\n"
226                 "%24 = OpTypePointer Output %7\n"
227                 "%26 = OpVariable %24 Output\n"
228                 "%4 = OpFunction %2 None %3\n"
229                 "%5 = OpLabel\n"
230                 "%10 = OpVariable %9 Function\n"
231                 "%17 = OpAccessChain %16 %10 %12\n"
232                 "OpStore %17 %15\n"
233                 "%23 = OpLoad %7 %22\n"
234                 "%25 = OpAccessChain %24 %20 %12\n"
235                 "OpStore %25 %23\n"
236                 "%27 = OpAccessChain %16 %10 %12\n"
237                 "%28 = OpLoad %7 %27\n"
238                 "OpStore %26 %28\n"
239                 "OpReturn\n"
240                 "OpFunctionEnd\n";
241         dst.spirvAsmSources.add("frag") <<
242                 "OpCapability Shader\n"
243                 "%1 = OpExtInstImport \"GLSL.std.450\"\n"
244                 "OpMemoryModel Logical GLSL450\n"
245                 "OpEntryPoint Fragment %4 \"main\" %9 %11\n"
246                 "OpExecutionMode %4 OriginUpperLeft\n"
247                 "OpSource ESSL 310\n"
248                 "OpDecorate %9 RelaxedPrecision\n"
249                 "OpDecorate %9 Location 0\n"
250                 "OpDecorate %11 Location 2\n"
251                 "%2 = OpTypeVoid\n"
252                 "%3 = OpTypeFunction %2\n"
253                 "%6 = OpTypeFloat 32\n"
254                 "%7 = OpTypeVector %6 4\n"
255                 "%8 = OpTypePointer Output %7\n"
256                 "%9 = OpVariable %8 Output\n"
257                 "%10 = OpTypePointer Input %7\n"
258                 "%11 = OpVariable %10 Input\n"
259                 "%4 = OpFunction %2 None %3\n"
260                 "%5 = OpLabel\n"
261                 "%12 = OpLoad %7 %11\n"
262                 "OpStore %9 %12\n"
263                 "OpReturn\n"
264                 "OpFunctionEnd\n";
265 }
266
267 class RefVertexShader : public rr::VertexShader
268 {
269 public:
270         RefVertexShader (void)
271                 : rr::VertexShader(1, 0)
272         {
273                 m_inputs[0].type = rr::GENERICVECTYPE_FLOAT;
274         }
275
276         void shadeVertices (const rr::VertexAttrib* inputs, rr::VertexPacket* const* packets, const int numPackets) const
277         {
278                 for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
279                 {
280                         packets[packetNdx]->position = rr::readVertexAttribFloat(inputs[0],
281                                                                                                                                          packets[packetNdx]->instanceNdx,
282                                                                                                                                          packets[packetNdx]->vertexNdx);
283                 }
284         }
285 };
286
287 class RefFragmentShader : public rr::FragmentShader
288 {
289 public:
290         RefFragmentShader (void)
291                 : rr::FragmentShader(0, 1)
292         {
293                 m_outputs[0].type = rr::GENERICVECTYPE_FLOAT;
294         }
295
296         void shadeFragments (rr::FragmentPacket*, const int numPackets, const rr::FragmentShadingContext& context) const
297         {
298                 for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
299                 {
300                         for (int fragNdx = 0; fragNdx < rr::NUM_FRAGMENTS_PER_PACKET; ++fragNdx)
301                         {
302                                 rr::writeFragmentOutput(context, packetNdx, fragNdx, 0, tcu::Vec4(1.0f, 0.0f, 1.0f, 1.0f));
303                         }
304                 }
305         }
306 };
307
308 void renderReferenceTriangle (const tcu::PixelBufferAccess& dst, const tcu::Vec4 (&vertices)[3])
309 {
310         const RefVertexShader                                   vertShader;
311         const RefFragmentShader                                 fragShader;
312         const rr::Program                                               program                 (&vertShader, &fragShader);
313         const rr::MultisamplePixelBufferAccess  colorBuffer             = rr::MultisamplePixelBufferAccess::fromSinglesampleAccess(dst);
314         const rr::RenderTarget                                  renderTarget    (colorBuffer);
315         const rr::RenderState                                   renderState             ((rr::ViewportState(colorBuffer)), rr::VIEWPORTORIENTATION_UPPER_LEFT);
316         const rr::Renderer                                              renderer;
317         const rr::VertexAttrib                                  vertexAttribs[] =
318         {
319                 rr::VertexAttrib(rr::VERTEXATTRIBTYPE_FLOAT, 4, sizeof(tcu::Vec4), 0, vertices[0].getPtr())
320         };
321
322         renderer.draw(rr::DrawCommand(renderState,
323                                                                   renderTarget,
324                                                                   program,
325                                                                   DE_LENGTH_OF_ARRAY(vertexAttribs),
326                                                                   &vertexAttribs[0],
327                                                                   rr::PrimitiveList(rr::PRIMITIVETYPE_TRIANGLES, DE_LENGTH_OF_ARRAY(vertices), 0)));
328 }
329
330 tcu::TestStatus renderTriangleTest (Context& context)
331 {
332         const VkDevice                                                  vkDevice                                = context.getDevice();
333         const DeviceInterface&                                  vk                                              = context.getDeviceInterface();
334         const VkQueue                                                   queue                                   = context.getUniversalQueue();
335         const deUint32                                                  queueFamilyIndex                = context.getUniversalQueueFamilyIndex();
336         SimpleAllocator                                                 memAlloc                                (vk, vkDevice, getPhysicalDeviceMemoryProperties(context.getInstanceInterface(), context.getPhysicalDevice()));
337         const tcu::IVec2                                                renderSize                              (256, 256);
338         const VkFormat                                                  colorFormat                             = VK_FORMAT_R8G8B8A8_UNORM;
339         const tcu::Vec4                                                 clearColor                              (0.125f, 0.25f, 0.75f, 1.0f);
340
341         const tcu::Vec4                                                 vertices[]                              =
342         {
343                 tcu::Vec4(-0.5f, -0.5f, 0.0f, 1.0f),
344                 tcu::Vec4(+0.5f, -0.5f, 0.0f, 1.0f),
345                 tcu::Vec4( 0.0f, +0.5f, 0.0f, 1.0f)
346         };
347
348         const VkBufferCreateInfo                                vertexBufferParams              =
349         {
350                 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,   // sType
351                 DE_NULL,                                                                // pNext
352                 0u,                                                                             // flags
353                 (VkDeviceSize)sizeof(vertices),                 // size
354                 VK_BUFFER_USAGE_VERTEX_BUFFER_BIT,              // usage
355                 VK_SHARING_MODE_EXCLUSIVE,                              // sharingMode
356                 1u,                                                                             // queueFamilyIndexCount
357                 &queueFamilyIndex,                                              // pQueueFamilyIndices
358         };
359         const Unique<VkBuffer>                                  vertexBuffer                    (createBuffer(vk, vkDevice, &vertexBufferParams));
360         const UniquePtr<Allocation>                             vertexBufferMemory              (memAlloc.allocate(getBufferMemoryRequirements(vk, vkDevice, *vertexBuffer), MemoryRequirement::HostVisible));
361
362         VK_CHECK(vk.bindBufferMemory(vkDevice, *vertexBuffer, vertexBufferMemory->getMemory(), vertexBufferMemory->getOffset()));
363
364         const VkDeviceSize                                              imageSizeBytes                  = (VkDeviceSize)(sizeof(deUint32)*renderSize.x()*renderSize.y());
365         const VkBufferCreateInfo                                readImageBufferParams   =
366         {
367                 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,           // sType
368                 DE_NULL,                                                                        // pNext
369                 (VkBufferCreateFlags)0u,                                        // flags
370                 imageSizeBytes,                                                         // size
371                 VK_BUFFER_USAGE_TRANSFER_DST_BIT,                       // usage
372                 VK_SHARING_MODE_EXCLUSIVE,                                      // sharingMode
373                 1u,                                                                                     // queueFamilyIndexCount
374                 &queueFamilyIndex,                                                      // pQueueFamilyIndices
375         };
376         const Unique<VkBuffer>                                  readImageBuffer                 (createBuffer(vk, vkDevice, &readImageBufferParams));
377         const UniquePtr<Allocation>                             readImageBufferMemory   (memAlloc.allocate(getBufferMemoryRequirements(vk, vkDevice, *readImageBuffer), MemoryRequirement::HostVisible));
378
379         VK_CHECK(vk.bindBufferMemory(vkDevice, *readImageBuffer, readImageBufferMemory->getMemory(), readImageBufferMemory->getOffset()));
380
381         const VkImageCreateInfo                                 imageParams                             =
382         {
383                 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,                                                                    // sType
384                 DE_NULL,                                                                                                                                // pNext
385                 0u,                                                                                                                                             // flags
386                 VK_IMAGE_TYPE_2D,                                                                                                               // imageType
387                 VK_FORMAT_R8G8B8A8_UNORM,                                                                                               // format
388                 { (deUint32)renderSize.x(), (deUint32)renderSize.y(), 1 },                              // extent
389                 1u,                                                                                                                                             // mipLevels
390                 1u,                                                                                                                                             // arraySize
391                 VK_SAMPLE_COUNT_1_BIT,                                                                                                  // samples
392                 VK_IMAGE_TILING_OPTIMAL,                                                                                                // tiling
393                 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT|VK_IMAGE_USAGE_TRANSFER_SRC_BIT,    // usage
394                 VK_SHARING_MODE_EXCLUSIVE,                                                                                              // sharingMode
395                 1u,                                                                                                                                             // queueFamilyIndexCount
396                 &queueFamilyIndex,                                                                                                              // pQueueFamilyIndices
397                 VK_IMAGE_LAYOUT_UNDEFINED,                                                                                              // initialLayout
398         };
399
400         const Unique<VkImage>                                   image                                   (createImage(vk, vkDevice, &imageParams));
401         const UniquePtr<Allocation>                             imageMemory                             (memAlloc.allocate(getImageMemoryRequirements(vk, vkDevice, *image), MemoryRequirement::Any));
402
403         VK_CHECK(vk.bindImageMemory(vkDevice, *image, imageMemory->getMemory(), imageMemory->getOffset()));
404
405         const VkAttachmentDescription                   colorAttDesc                    =
406         {
407                 0u,                                                                                             // flags
408                 VK_FORMAT_R8G8B8A8_UNORM,                                               // format
409                 VK_SAMPLE_COUNT_1_BIT,                                                  // samples
410                 VK_ATTACHMENT_LOAD_OP_CLEAR,                                    // loadOp
411                 VK_ATTACHMENT_STORE_OP_STORE,                                   // storeOp
412                 VK_ATTACHMENT_LOAD_OP_DONT_CARE,                                // stencilLoadOp
413                 VK_ATTACHMENT_STORE_OP_DONT_CARE,                               // stencilStoreOp
414                 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,               // initialLayout
415                 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,               // finalLayout
416         };
417         const VkAttachmentReference                             colorAttRef                             =
418         {
419                 0u,                                                                                             // attachment
420                 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,               // layout
421         };
422         const VkSubpassDescription                              subpassDesc                             =
423         {
424                 (VkSubpassDescriptionFlags)0u,                                  // flags
425                 VK_PIPELINE_BIND_POINT_GRAPHICS,                                // pipelineBindPoint
426                 0u,                                                                                             // inputAttachmentCount
427                 DE_NULL,                                                                                // pInputAttachments
428                 1u,                                                                                             // colorAttachmentCount
429                 &colorAttRef,                                                                   // pColorAttachments
430                 DE_NULL,                                                                                // pResolveAttachments
431                 DE_NULL,                                                                                // depthStencilAttachment
432                 0u,                                                                                             // preserveAttachmentCount
433                 DE_NULL,                                                                                // pPreserveAttachments
434         };
435         const VkRenderPassCreateInfo                    renderPassParams                =
436         {
437                 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,              // sType
438                 DE_NULL,                                                                                // pNext
439                 0u,                                                                                             // flags
440                 1u,                                                                                             // attachmentCount
441                 &colorAttDesc,                                                                  // pAttachments
442                 1u,                                                                                             // subpassCount
443                 &subpassDesc,                                                                   // pSubpasses
444                 0u,                                                                                             // dependencyCount
445                 DE_NULL,                                                                                // pDependencies
446         };
447         const Unique<VkRenderPass>                              renderPass                              (createRenderPass(vk, vkDevice, &renderPassParams));
448
449         const VkImageViewCreateInfo                             colorAttViewParams              =
450         {
451                 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,               // sType
452                 DE_NULL,                                                                                // pNext
453                 0u,                                                                                             // flags
454                 *image,                                                                                 // image
455                 VK_IMAGE_VIEW_TYPE_2D,                                                  // viewType
456                 VK_FORMAT_R8G8B8A8_UNORM,                                               // format
457                 {
458                         VK_COMPONENT_SWIZZLE_R,
459                         VK_COMPONENT_SWIZZLE_G,
460                         VK_COMPONENT_SWIZZLE_B,
461                         VK_COMPONENT_SWIZZLE_A
462                 },                                                                                              // components
463                 {
464                         VK_IMAGE_ASPECT_COLOR_BIT,                                              // aspectMask
465                         0u,                                                                                             // baseMipLevel
466                         1u,                                                                                             // levelCount
467                         0u,                                                                                             // baseArrayLayer
468                         1u,                                                                                             // layerCount
469                 },                                                                                              // subresourceRange
470         };
471         const Unique<VkImageView>                               colorAttView                    (createImageView(vk, vkDevice, &colorAttViewParams));
472
473         // Pipeline layout
474         const VkPipelineLayoutCreateInfo                pipelineLayoutParams    =
475         {
476                 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,                  // sType
477                 DE_NULL,                                                                                                // pNext
478                 (vk::VkPipelineLayoutCreateFlags)0,
479                 0u,                                                                                                             // setLayoutCount
480                 DE_NULL,                                                                                                // pSetLayouts
481                 0u,                                                                                                             // pushConstantRangeCount
482                 DE_NULL,                                                                                                // pPushConstantRanges
483         };
484         const Unique<VkPipelineLayout>                  pipelineLayout                  (createPipelineLayout(vk, vkDevice, &pipelineLayoutParams));
485
486         // Shaders
487         const Unique<VkShaderModule>                    vertShaderModule                (createShaderModule(vk, vkDevice, context.getBinaryCollection().get("vert"), 0));
488         const Unique<VkShaderModule>                    fragShaderModule                (createShaderModule(vk, vkDevice, context.getBinaryCollection().get("frag"), 0));
489
490         // Pipeline
491         const VkSpecializationInfo                              emptyShaderSpecParams   =
492         {
493                 0u,                                                                                                             // mapEntryCount
494                 DE_NULL,                                                                                                // pMap
495                 0,                                                                                                              // dataSize
496                 DE_NULL,                                                                                                // pData
497         };
498         const VkPipelineShaderStageCreateInfo   shaderStageParams[]     =
499         {
500                 {
501                         VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,    // sType
502                         DE_NULL,                                                                                                // pNext
503                         0u,                                                                                                             // flags
504                         VK_SHADER_STAGE_VERTEX_BIT,                                                             // stage
505                         *vertShaderModule,                                                                              // module
506                         "main",                                                                                                 // pName
507                         &emptyShaderSpecParams,                                                                 // pSpecializationInfo
508                 },
509                 {
510                         VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,    // sType
511                         DE_NULL,                                                                                                // pNext
512                         0u,                                                                                                             // flags
513                         VK_SHADER_STAGE_FRAGMENT_BIT,                                                   // stage
514                         *fragShaderModule,                                                                              // module
515                         "main",                                                                                                 // pName
516                         &emptyShaderSpecParams,                                                                 // pSpecializationInfo
517                 }
518         };
519         const VkPipelineDepthStencilStateCreateInfo     depthStencilParams              =
520         {
521                 VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO,     // sType
522                 DE_NULL,                                                                                                        // pNext
523                 0u,                                                                                                                     // flags
524                 DE_FALSE,                                                                                                       // depthTestEnable
525                 DE_FALSE,                                                                                                       // depthWriteEnable
526                 VK_COMPARE_OP_ALWAYS,                                                                           // depthCompareOp
527                 DE_FALSE,                                                                                                       // depthBoundsTestEnable
528                 DE_FALSE,                                                                                                       // stencilTestEnable
529                 {
530                         VK_STENCIL_OP_KEEP,                                                                                     // failOp
531                         VK_STENCIL_OP_KEEP,                                                                                     // passOp
532                         VK_STENCIL_OP_KEEP,                                                                                     // depthFailOp
533                         VK_COMPARE_OP_ALWAYS,                                                                           // compareOp
534                         0u,                                                                                                                     // compareMask
535                         0u,                                                                                                                     // writeMask
536                         0u,                                                                                                                     // reference
537                 },                                                                                                                      // front
538                 {
539                         VK_STENCIL_OP_KEEP,                                                                                     // failOp
540                         VK_STENCIL_OP_KEEP,                                                                                     // passOp
541                         VK_STENCIL_OP_KEEP,                                                                                     // depthFailOp
542                         VK_COMPARE_OP_ALWAYS,                                                                           // compareOp
543                         0u,                                                                                                                     // compareMask
544                         0u,                                                                                                                     // writeMask
545                         0u,                                                                                                                     // reference
546                 },                                                                                                                      // back;
547                 0.0f,                                                                                                           //      float                           minDepthBounds;
548                 1.0f,                                                                                                           //      float                           maxDepthBounds;
549         };
550         const VkViewport                                                viewport0                               =
551         {
552                 0.0f,                                                                                                           // x
553                 0.0f,                                                                                                           // y
554                 (float)renderSize.x(),                                                                          // width
555                 (float)renderSize.y(),                                                                          // height
556                 0.0f,                                                                                                           // minDepth
557                 1.0f,                                                                                                           // maxDepth
558         };
559         const VkRect2D                                                  scissor0                                =
560         {
561                 {
562                         0u,                                                                                                                     // x
563                         0u,                                                                                                                     // y
564                 },                                                                                                                      // offset
565                 {
566                         (deUint32)renderSize.x(),                                                                       // width
567                         (deUint32)renderSize.y(),                                                                       // height
568                 },                                                                                                                      // extent;
569         };
570         const VkPipelineViewportStateCreateInfo         viewportParams                  =
571         {
572                 VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO,          // sType
573                 DE_NULL,                                                                                                        // pNext
574                 0u,                                                                                                                     // flags
575                 1u,                                                                                                                     // viewportCount
576                 &viewport0,                                                                                                     // pViewports
577                 1u,                                                                                                                     // scissorCount
578                 &scissor0                                                                                                       // pScissors
579         };
580         const VkSampleMask                                                      sampleMask                              = ~0u;
581         const VkPipelineMultisampleStateCreateInfo      multisampleParams               =
582         {
583                 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,       // sType
584                 DE_NULL,                                                                                                        // pNext
585                 0u,                                                                                                                     // flags
586                 VK_SAMPLE_COUNT_1_BIT,                                                                          // rasterizationSamples
587                 VK_FALSE,                                                                                                       // sampleShadingEnable
588                 0.0f,                                                                                                           // minSampleShading
589                 &sampleMask,                                                                                            // sampleMask
590                 VK_FALSE,                                                                                                       // alphaToCoverageEnable
591                 VK_FALSE,                                                                                                       // alphaToOneEnable
592         };
593         const VkPipelineRasterizationStateCreateInfo    rasterParams            =
594         {
595                 VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO,     // sType
596                 DE_NULL,                                                                                                        // pNext
597                 0u,                                                                                                                     // flags
598                 VK_TRUE,                                                                                                        // depthClampEnable
599                 VK_FALSE,                                                                                                       // rasterizerDiscardEnable
600                 VK_POLYGON_MODE_FILL,                                                                           // polygonMode
601                 VK_CULL_MODE_NONE,                                                                                      // cullMode
602                 VK_FRONT_FACE_COUNTER_CLOCKWISE,                                                        // frontFace
603                 VK_FALSE,                                                                                                       // depthBiasEnable
604                 0.0f,                                                                                                           // depthBiasConstantFactor
605                 0.0f,                                                                                                           // depthBiasClamp
606                 0.0f,                                                                                                           // depthBiasSlopeFactor
607                 1.0f,                                                                                                           // lineWidth
608         };
609         const VkPipelineInputAssemblyStateCreateInfo    inputAssemblyParams     =
610         {
611                 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,    // sType
612                 DE_NULL,                                                                                                                // pNext
613                 0u,                                                                                                                             // flags
614                 VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST,                                                    // topology
615                 DE_FALSE,                                                                                                               // primitiveRestartEnable
616         };
617         const VkVertexInputBindingDescription           vertexBinding0                  =
618         {
619                 0u,                                                                                                             // binding
620                 (deUint32)sizeof(tcu::Vec4),                                                    // stride
621                 VK_VERTEX_INPUT_RATE_VERTEX,                                                    // inputRate
622         };
623         const VkVertexInputAttributeDescription         vertexAttrib0                   =
624         {
625                 0u,                                                                                                             // location
626                 0u,                                                                                                             // binding
627                 VK_FORMAT_R32G32B32A32_SFLOAT,                                                  // format
628                 0u,                                                                                                             // offset
629         };
630         const VkPipelineVertexInputStateCreateInfo      vertexInputStateParams  =
631         {
632                 VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,      // sType
633                 DE_NULL,                                                                                                        // pNext
634                 0u,                                                                                                                     // flags
635                 1u,                                                                                                                     // vertexBindingDescriptionCount
636                 &vertexBinding0,                                                                                        // pVertexBindingDescriptions
637                 1u,                                                                                                                     // vertexAttributeDescriptionCount
638                 &vertexAttrib0,                                                                                         // pVertexAttributeDescriptions
639         };
640         const VkPipelineColorBlendAttachmentState       attBlendParams                  =
641         {
642                 VK_FALSE,                                                                                                       // blendEnable
643                 VK_BLEND_FACTOR_ONE,                                                                            // srcColorBlendFactor
644                 VK_BLEND_FACTOR_ZERO,                                                                           // dstColorBlendFactor
645                 VK_BLEND_OP_ADD,                                                                                        // colorBlendOp
646                 VK_BLEND_FACTOR_ONE,                                                                            // srcAlphaBlendFactor
647                 VK_BLEND_FACTOR_ZERO,                                                                           // dstAlphaBlendFactor
648                 VK_BLEND_OP_ADD,                                                                                        // alphaBlendOp
649                 (VK_COLOR_COMPONENT_R_BIT|
650                  VK_COLOR_COMPONENT_G_BIT|
651                  VK_COLOR_COMPONENT_B_BIT|
652                  VK_COLOR_COMPONENT_A_BIT),                                                                     // colorWriteMask
653         };
654         const VkPipelineColorBlendStateCreateInfo       blendParams                             =
655         {
656                 VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO,       // sType
657                 DE_NULL,                                                                                                        // pNext
658                 0u,                                                                                                                     // flags
659                 DE_FALSE,                                                                                                       // logicOpEnable
660                 VK_LOGIC_OP_COPY,                                                                                       // logicOp
661                 1u,                                                                                                                     // attachmentCount
662                 &attBlendParams,                                                                                        // pAttachments
663                 { 0.0f, 0.0f, 0.0f, 0.0f },                                                                     // blendConstants[4]
664         };
665         const VkGraphicsPipelineCreateInfo              pipelineParams                  =
666         {
667                 VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,                // sType
668                 DE_NULL,                                                                                                // pNext
669                 0u,                                                                                                             // flags
670                 (deUint32)DE_LENGTH_OF_ARRAY(shaderStageParams),                // stageCount
671                 shaderStageParams,                                                                              // pStages
672                 &vertexInputStateParams,                                                                // pVertexInputState
673                 &inputAssemblyParams,                                                                   // pInputAssemblyState
674                 DE_NULL,                                                                                                // pTessellationState
675                 &viewportParams,                                                                                // pViewportState
676                 &rasterParams,                                                                                  // pRasterizationState
677                 &multisampleParams,                                                                             // pMultisampleState
678                 &depthStencilParams,                                                                    // pDepthStencilState
679                 &blendParams,                                                                                   // pColorBlendState
680                 (const VkPipelineDynamicStateCreateInfo*)DE_NULL,               // pDynamicState
681                 *pipelineLayout,                                                                                // layout
682                 *renderPass,                                                                                    // renderPass
683                 0u,                                                                                                             // subpass
684                 DE_NULL,                                                                                                // basePipelineHandle
685                 0u,                                                                                                             // basePipelineIndex
686         };
687
688         const Unique<VkPipeline>                                pipeline                                (createGraphicsPipeline(vk, vkDevice, DE_NULL, &pipelineParams));
689
690         // Framebuffer
691         const VkFramebufferCreateInfo                   framebufferParams               =
692         {
693                 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,                              // sType
694                 DE_NULL,                                                                                                // pNext
695                 0u,                                                                                                             // flags
696                 *renderPass,                                                                                    // renderPass
697                 1u,                                                                                                             // attachmentCount
698                 &*colorAttView,                                                                                 // pAttachments
699                 (deUint32)renderSize.x(),                                                               // width
700                 (deUint32)renderSize.y(),                                                               // height
701                 1u,                                                                                                             // layers
702         };
703         const Unique<VkFramebuffer>                             framebuffer                             (createFramebuffer(vk, vkDevice, &framebufferParams));
704
705         const VkCommandPoolCreateInfo                   cmdPoolParams                   =
706         {
707                 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,                                     // sType
708                 DE_NULL,                                                                                                        // pNext
709                 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,                        // flags
710                 queueFamilyIndex,                                                                                       // queueFamilyIndex
711         };
712         const Unique<VkCommandPool>                             cmdPool                                 (createCommandPool(vk, vkDevice, &cmdPoolParams));
713
714         // Command buffer
715         const VkCommandBufferAllocateInfo               cmdBufParams                    =
716         {
717                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,                 // sType
718                 DE_NULL,                                                                                                // pNext
719                 *cmdPool,                                                                                               // pool
720                 VK_COMMAND_BUFFER_LEVEL_PRIMARY,                                                // level
721                 1u,                                                                                                             // bufferCount
722         };
723         const Unique<VkCommandBuffer>                   cmdBuf                                  (allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
724
725         const VkCommandBufferBeginInfo                  cmdBufBeginParams               =
726         {
727                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,                    // sType
728                 DE_NULL,                                                                                                // pNext
729                 0u,                                                                                                             // flags
730                 (const VkCommandBufferInheritanceInfo*)DE_NULL,
731         };
732
733         // Record commands
734         VK_CHECK(vk.beginCommandBuffer(*cmdBuf, &cmdBufBeginParams));
735
736         {
737                 const VkMemoryBarrier           vertFlushBarrier        =
738                 {
739                         VK_STRUCTURE_TYPE_MEMORY_BARRIER,                       // sType
740                         DE_NULL,                                                                        // pNext
741                         VK_ACCESS_HOST_WRITE_BIT,                                       // srcAccessMask
742                         VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT,            // dstAccessMask
743                 };
744                 const VkImageMemoryBarrier      colorAttBarrier         =
745                 {
746                         VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,         // sType
747                         DE_NULL,                                                                        // pNext
748                         0u,                                                                                     // srcAccessMask
749                         (VK_ACCESS_COLOR_ATTACHMENT_READ_BIT|
750                          VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT),         // dstAccessMask
751                         VK_IMAGE_LAYOUT_UNDEFINED,                                      // oldLayout
752                         VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,       // newLayout
753                         queueFamilyIndex,                                                       // srcQueueFamilyIndex
754                         queueFamilyIndex,                                                       // dstQueueFamilyIndex
755                         *image,                                                                         // image
756                         {
757                                 VK_IMAGE_ASPECT_COLOR_BIT,                                      // aspectMask
758                                 0u,                                                                                     // baseMipLevel
759                                 1u,                                                                                     // levelCount
760                                 0u,                                                                                     // baseArrayLayer
761                                 1u,                                                                                     // layerCount
762                         }                                                                                       // subresourceRange
763                 };
764                 vk.cmdPipelineBarrier(*cmdBuf, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, (VkDependencyFlags)0, 1, &vertFlushBarrier, 0, (const VkBufferMemoryBarrier*)DE_NULL, 1, &colorAttBarrier);
765         }
766
767         {
768                 const VkClearValue                      clearValue              = makeClearValueColorF32(clearColor[0],
769                                                                                                                                                          clearColor[1],
770                                                                                                                                                          clearColor[2],
771                                                                                                                                                          clearColor[3]);
772                 const VkRenderPassBeginInfo     passBeginParams =
773                 {
774                         VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,                       // sType
775                         DE_NULL,                                                                                        // pNext
776                         *renderPass,                                                                            // renderPass
777                         *framebuffer,                                                                           // framebuffer
778                         {
779                                 { 0, 0 },
780                                 { (deUint32)renderSize.x(), (deUint32)renderSize.y() }
781                         },                                                                                                      // renderArea
782                         1u,                                                                                                     // clearValueCount
783                         &clearValue,                                                                            // pClearValues
784                 };
785                 vk.cmdBeginRenderPass(*cmdBuf, &passBeginParams, VK_SUBPASS_CONTENTS_INLINE);
786         }
787
788         vk.cmdBindPipeline(*cmdBuf, VK_PIPELINE_BIND_POINT_GRAPHICS, *pipeline);
789         {
790                 const VkDeviceSize bindingOffset = 0;
791                 vk.cmdBindVertexBuffers(*cmdBuf, 0u, 1u, &vertexBuffer.get(), &bindingOffset);
792         }
793         vk.cmdDraw(*cmdBuf, 3u, 1u, 0u, 0u);
794         vk.cmdEndRenderPass(*cmdBuf);
795
796         {
797                 const VkImageMemoryBarrier      renderFinishBarrier     =
798                 {
799                         VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,         // sType
800                         DE_NULL,                                                                        // pNext
801                         VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,           // outputMask
802                         VK_ACCESS_TRANSFER_READ_BIT,                            // inputMask
803                         VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,       // oldLayout
804                         VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,           // newLayout
805                         queueFamilyIndex,                                                       // srcQueueFamilyIndex
806                         queueFamilyIndex,                                                       // dstQueueFamilyIndex
807                         *image,                                                                         // image
808                         {
809                                 VK_IMAGE_ASPECT_COLOR_BIT,                                      // aspectMask
810                                 0u,                                                                                     // baseMipLevel
811                                 1u,                                                                                     // mipLevels
812                                 0u,                                                                                     // baseArraySlice
813                                 1u,                                                                                     // arraySize
814                         }                                                                                       // subresourceRange
815                 };
816                 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);
817         }
818
819         {
820                 const VkBufferImageCopy copyParams      =
821                 {
822                         (VkDeviceSize)0u,                                               // bufferOffset
823                         (deUint32)renderSize.x(),                               // bufferRowLength
824                         (deUint32)renderSize.y(),                               // bufferImageHeight
825                         {
826                                 VK_IMAGE_ASPECT_COLOR_BIT,                              // aspectMask
827                                 0u,                                                                             // mipLevel
828                                 0u,                                                                             // baseArrayLayer
829                                 1u,                                                                             // layerCount
830                         },                                                                              // imageSubresource
831                         { 0u, 0u, 0u },                                                 // imageOffset
832                         {
833                                 (deUint32)renderSize.x(),
834                                 (deUint32)renderSize.y(),
835                                 1u
836                         }                                                                               // imageExtent
837                 };
838                 vk.cmdCopyImageToBuffer(*cmdBuf, *image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, *readImageBuffer, 1u, &copyParams);
839         }
840
841         {
842                 const VkBufferMemoryBarrier     copyFinishBarrier       =
843                 {
844                         VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,        // sType
845                         DE_NULL,                                                                        // pNext
846                         VK_ACCESS_TRANSFER_WRITE_BIT,                           // srcAccessMask
847                         VK_ACCESS_HOST_READ_BIT,                                        // dstAccessMask
848                         queueFamilyIndex,                                                       // srcQueueFamilyIndex
849                         queueFamilyIndex,                                                       // dstQueueFamilyIndex
850                         *readImageBuffer,                                                       // buffer
851                         0u,                                                                                     // offset
852                         imageSizeBytes                                                          // size
853                 };
854                 vk.cmdPipelineBarrier(*cmdBuf, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 1, &copyFinishBarrier, 0, (const VkImageMemoryBarrier*)DE_NULL);
855         }
856
857         VK_CHECK(vk.endCommandBuffer(*cmdBuf));
858
859         // Upload vertex data
860         {
861                 const VkMappedMemoryRange       range                   =
862                 {
863                         VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE,  // sType
864                         DE_NULL,                                                                // pNext
865                         vertexBufferMemory->getMemory(),                // memory
866                         0,                                                                              // offset
867                         (VkDeviceSize)sizeof(vertices),                 // size
868                 };
869                 void*                                           vertexBufPtr    = vertexBufferMemory->getHostPtr();
870
871                 deMemcpy(vertexBufPtr, &vertices[0], sizeof(vertices));
872                 VK_CHECK(vk.flushMappedMemoryRanges(vkDevice, 1u, &range));
873         }
874
875         // Submit & wait for completion
876         {
877                 const VkFenceCreateInfo fenceParams     =
878                 {
879                         VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,    // sType
880                         DE_NULL,                                                                // pNext
881                         0u,                                                                             // flags
882                 };
883                 const VkSubmitInfo              submitInfo      =
884                 {
885                         VK_STRUCTURE_TYPE_SUBMIT_INFO,                  // sType
886                         DE_NULL,                                                                // pNext
887                         0u,                                                                             // waitSemaphoreCount
888                         DE_NULL,                                                                // pWaitSemaphores
889                         (const VkPipelineStageFlags*)DE_NULL,
890                         1u,                                                                             // commandBufferCount
891                         &cmdBuf.get(),                                                  // pCommandBuffers
892                         0u,                                                                             // signalSemaphoreCount
893                         DE_NULL,                                                                // pSignalSemaphores
894                 };
895                 const Unique<VkFence>   fence           (createFence(vk, vkDevice, &fenceParams));
896
897                 VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence));
898                 VK_CHECK(vk.waitForFences(vkDevice, 1u, &fence.get(), DE_TRUE, ~0ull));
899         }
900
901         // Read results, render reference, compare
902         {
903                 const tcu::TextureFormat                        tcuFormat               = vk::mapVkFormat(colorFormat);
904                 const VkMappedMemoryRange                       range                   =
905                 {
906                         VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE,  // sType
907                         DE_NULL,                                                                // pNext
908                         readImageBufferMemory->getMemory(),             // memory
909                         0,                                                                              // offset
910                         imageSizeBytes,                                                 // size
911                 };
912                 const tcu::ConstPixelBufferAccess       resultAccess    (tcuFormat, renderSize.x(), renderSize.y(), 1, readImageBufferMemory->getHostPtr());
913
914                 VK_CHECK(vk.invalidateMappedMemoryRanges(vkDevice, 1u, &range));
915
916                 {
917                         tcu::TextureLevel       refImage                (tcuFormat, renderSize.x(), renderSize.y());
918                         const tcu::UVec4        threshold               (0u);
919                         const tcu::IVec3        posDeviation    (1,1,0);
920
921                         tcu::clear(refImage.getAccess(), clearColor);
922                         renderReferenceTriangle(refImage.getAccess(), vertices);
923
924                         if (tcu::intThresholdPositionDeviationCompare(context.getTestContext().getLog(),
925                                                                                                                   "ComparisonResult",
926                                                                                                                   "Image comparison result",
927                                                                                                                   refImage.getAccess(),
928                                                                                                                   resultAccess,
929                                                                                                                   threshold,
930                                                                                                                   posDeviation,
931                                                                                                                   false,
932                                                                                                                   tcu::COMPARE_LOG_RESULT))
933                                 return tcu::TestStatus::pass("Rendering succeeded");
934                         else
935                                 return tcu::TestStatus::fail("Image comparison failed");
936                 }
937         }
938
939         return tcu::TestStatus::pass("Rendering succeeded");
940 }
941
942 tcu::TestStatus renderTriangleUnusedResolveAttachmentTest (Context& context)
943 {
944         const VkDevice                                                  vkDevice                                = context.getDevice();
945         const DeviceInterface&                                  vk                                              = context.getDeviceInterface();
946         const VkQueue                                                   queue                                   = context.getUniversalQueue();
947         const deUint32                                                  queueFamilyIndex                = context.getUniversalQueueFamilyIndex();
948         SimpleAllocator                                                 memAlloc                                (vk, vkDevice, getPhysicalDeviceMemoryProperties(context.getInstanceInterface(), context.getPhysicalDevice()));
949         const tcu::IVec2                                                renderSize                              (256, 256);
950         const VkFormat                                                  colorFormat                             = VK_FORMAT_R8G8B8A8_UNORM;
951         const tcu::Vec4                                                 clearColor                              (0.125f, 0.25f, 0.75f, 1.0f);
952
953         const tcu::Vec4                                                 vertices[]                              =
954         {
955                 tcu::Vec4(-0.5f, -0.5f, 0.0f, 1.0f),
956                 tcu::Vec4(+0.5f, -0.5f, 0.0f, 1.0f),
957                 tcu::Vec4( 0.0f, +0.5f, 0.0f, 1.0f)
958         };
959
960         const VkBufferCreateInfo                                vertexBufferParams              =
961         {
962                 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,   // sType
963                 DE_NULL,                                                                // pNext
964                 0u,                                                                             // flags
965                 (VkDeviceSize)sizeof(vertices),                 // size
966                 VK_BUFFER_USAGE_VERTEX_BUFFER_BIT,              // usage
967                 VK_SHARING_MODE_EXCLUSIVE,                              // sharingMode
968                 1u,                                                                             // queueFamilyIndexCount
969                 &queueFamilyIndex,                                              // pQueueFamilyIndices
970         };
971         const Unique<VkBuffer>                                  vertexBuffer                    (createBuffer(vk, vkDevice, &vertexBufferParams));
972         const UniquePtr<Allocation>                             vertexBufferMemory              (memAlloc.allocate(getBufferMemoryRequirements(vk, vkDevice, *vertexBuffer), MemoryRequirement::HostVisible));
973
974         VK_CHECK(vk.bindBufferMemory(vkDevice, *vertexBuffer, vertexBufferMemory->getMemory(), vertexBufferMemory->getOffset()));
975
976         const VkDeviceSize                                              imageSizeBytes                  = (VkDeviceSize)(sizeof(deUint32)*renderSize.x()*renderSize.y());
977         const VkBufferCreateInfo                                readImageBufferParams   =
978         {
979                 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,           // sType
980                 DE_NULL,                                                                        // pNext
981                 (VkBufferCreateFlags)0u,                                        // flags
982                 imageSizeBytes,                                                         // size
983                 VK_BUFFER_USAGE_TRANSFER_DST_BIT,                       // usage
984                 VK_SHARING_MODE_EXCLUSIVE,                                      // sharingMode
985                 1u,                                                                                     // queueFamilyIndexCount
986                 &queueFamilyIndex,                                                      // pQueueFamilyIndices
987         };
988         const Unique<VkBuffer>                                  readImageBuffer                 (createBuffer(vk, vkDevice, &readImageBufferParams));
989         const UniquePtr<Allocation>                             readImageBufferMemory   (memAlloc.allocate(getBufferMemoryRequirements(vk, vkDevice, *readImageBuffer), MemoryRequirement::HostVisible));
990
991         VK_CHECK(vk.bindBufferMemory(vkDevice, *readImageBuffer, readImageBufferMemory->getMemory(), readImageBufferMemory->getOffset()));
992
993         const VkImageCreateInfo                                 imageParams                             =
994         {
995                 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,                                                                    // sType
996                 DE_NULL,                                                                                                                                // pNext
997                 0u,                                                                                                                                             // flags
998                 VK_IMAGE_TYPE_2D,                                                                                                               // imageType
999                 VK_FORMAT_R8G8B8A8_UNORM,                                                                                               // format
1000                 { (deUint32)renderSize.x(), (deUint32)renderSize.y(), 1 },                              // extent
1001                 1u,                                                                                                                                             // mipLevels
1002                 1u,                                                                                                                                             // arraySize
1003                 VK_SAMPLE_COUNT_1_BIT,                                                                                                  // samples
1004                 VK_IMAGE_TILING_OPTIMAL,                                                                                                // tiling
1005                 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT|VK_IMAGE_USAGE_TRANSFER_SRC_BIT,    // usage
1006                 VK_SHARING_MODE_EXCLUSIVE,                                                                                              // sharingMode
1007                 1u,                                                                                                                                             // queueFamilyIndexCount
1008                 &queueFamilyIndex,                                                                                                              // pQueueFamilyIndices
1009                 VK_IMAGE_LAYOUT_UNDEFINED,                                                                                              // initialLayout
1010         };
1011
1012         const Unique<VkImage>                                   image                                   (createImage(vk, vkDevice, &imageParams));
1013         const UniquePtr<Allocation>                             imageMemory                             (memAlloc.allocate(getImageMemoryRequirements(vk, vkDevice, *image), MemoryRequirement::Any));
1014
1015         VK_CHECK(vk.bindImageMemory(vkDevice, *image, imageMemory->getMemory(), imageMemory->getOffset()));
1016
1017         const VkAttachmentDescription                   colorAttDesc                    =
1018         {
1019                 0u,                                                                                             // flags
1020                 VK_FORMAT_R8G8B8A8_UNORM,                                               // format
1021                 VK_SAMPLE_COUNT_1_BIT,                                                  // samples
1022                 VK_ATTACHMENT_LOAD_OP_CLEAR,                                    // loadOp
1023                 VK_ATTACHMENT_STORE_OP_STORE,                                   // storeOp
1024                 VK_ATTACHMENT_LOAD_OP_DONT_CARE,                                // stencilLoadOp
1025                 VK_ATTACHMENT_STORE_OP_DONT_CARE,                               // stencilStoreOp
1026                 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,               // initialLayout
1027                 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,               // finalLayout
1028         };
1029         const VkAttachmentReference                             colorAttRef                             =
1030         {
1031                 0u,                                                                                             // attachment
1032                 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,               // layout
1033         };
1034         const VkAttachmentReference                             resolveAttRef                   =
1035         {
1036                 VK_ATTACHMENT_UNUSED,
1037                 VK_IMAGE_LAYOUT_GENERAL
1038         };
1039         const VkSubpassDescription                              subpassDesc                             =
1040         {
1041                 (VkSubpassDescriptionFlags)0u,                                  // flags
1042                 VK_PIPELINE_BIND_POINT_GRAPHICS,                                // pipelineBindPoint
1043                 0u,                                                                                             // inputAttachmentCount
1044                 DE_NULL,                                                                                // pInputAttachments
1045                 1u,                                                                                             // colorAttachmentCount
1046                 &colorAttRef,                                                                   // pColorAttachments
1047                 &resolveAttRef,                                                                 // pResolveAttachments
1048                 DE_NULL,                                                                                // depthStencilAttachment
1049                 0u,                                                                                             // preserveAttachmentCount
1050                 DE_NULL,                                                                                // pPreserveAttachments
1051         };
1052         const VkRenderPassCreateInfo                    renderPassParams                =
1053         {
1054                 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,              // sType
1055                 DE_NULL,                                                                                // pNext
1056                 0u,                                                                                             // flags
1057                 1u,                                                                                             // attachmentCount
1058                 &colorAttDesc,                                                                  // pAttachments
1059                 1u,                                                                                             // subpassCount
1060                 &subpassDesc,                                                                   // pSubpasses
1061                 0u,                                                                                             // dependencyCount
1062                 DE_NULL,                                                                                // pDependencies
1063         };
1064         const Unique<VkRenderPass>                              renderPass                              (createRenderPass(vk, vkDevice, &renderPassParams));
1065
1066         const VkImageViewCreateInfo                             colorAttViewParams              =
1067         {
1068                 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,               // sType
1069                 DE_NULL,                                                                                // pNext
1070                 0u,                                                                                             // flags
1071                 *image,                                                                                 // image
1072                 VK_IMAGE_VIEW_TYPE_2D,                                                  // viewType
1073                 VK_FORMAT_R8G8B8A8_UNORM,                                               // format
1074                 {
1075                         VK_COMPONENT_SWIZZLE_R,
1076                         VK_COMPONENT_SWIZZLE_G,
1077                         VK_COMPONENT_SWIZZLE_B,
1078                         VK_COMPONENT_SWIZZLE_A
1079                 },                                                                                              // components
1080                 {
1081                         VK_IMAGE_ASPECT_COLOR_BIT,                                              // aspectMask
1082                         0u,                                                                                             // baseMipLevel
1083                         1u,                                                                                             // levelCount
1084                         0u,                                                                                             // baseArrayLayer
1085                         1u,                                                                                             // layerCount
1086                 },                                                                                              // subresourceRange
1087         };
1088         const Unique<VkImageView>                               colorAttView                    (createImageView(vk, vkDevice, &colorAttViewParams));
1089
1090         // Pipeline layout
1091         const VkPipelineLayoutCreateInfo                pipelineLayoutParams    =
1092         {
1093                 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,                  // sType
1094                 DE_NULL,                                                                                                // pNext
1095                 (vk::VkPipelineLayoutCreateFlags)0,
1096                 0u,                                                                                                             // setLayoutCount
1097                 DE_NULL,                                                                                                // pSetLayouts
1098                 0u,                                                                                                             // pushConstantRangeCount
1099                 DE_NULL,                                                                                                // pPushConstantRanges
1100         };
1101         const Unique<VkPipelineLayout>                  pipelineLayout                  (createPipelineLayout(vk, vkDevice, &pipelineLayoutParams));
1102
1103         // Shaders
1104         const Unique<VkShaderModule>                    vertShaderModule                (createShaderModule(vk, vkDevice, context.getBinaryCollection().get("vert"), 0));
1105         const Unique<VkShaderModule>                    fragShaderModule                (createShaderModule(vk, vkDevice, context.getBinaryCollection().get("frag"), 0));
1106
1107         // Pipeline
1108         const VkSpecializationInfo                              emptyShaderSpecParams   =
1109         {
1110                 0u,                                                                                                             // mapEntryCount
1111                 DE_NULL,                                                                                                // pMap
1112                 0,                                                                                                              // dataSize
1113                 DE_NULL,                                                                                                // pData
1114         };
1115         const VkPipelineShaderStageCreateInfo   shaderStageParams[]     =
1116         {
1117                 {
1118                         VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,    // sType
1119                         DE_NULL,                                                                                                // pNext
1120                         0u,                                                                                                             // flags
1121                         VK_SHADER_STAGE_VERTEX_BIT,                                                             // stage
1122                         *vertShaderModule,                                                                              // module
1123                         "main",                                                                                                 // pName
1124                         &emptyShaderSpecParams,                                                                 // pSpecializationInfo
1125                 },
1126                 {
1127                         VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,    // sType
1128                         DE_NULL,                                                                                                // pNext
1129                         0u,                                                                                                             // flags
1130                         VK_SHADER_STAGE_FRAGMENT_BIT,                                                   // stage
1131                         *fragShaderModule,                                                                              // module
1132                         "main",                                                                                                 // pName
1133                         &emptyShaderSpecParams,                                                                 // pSpecializationInfo
1134                 }
1135         };
1136         const VkPipelineDepthStencilStateCreateInfo     depthStencilParams              =
1137         {
1138                 VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO,     // sType
1139                 DE_NULL,                                                                                                        // pNext
1140                 0u,                                                                                                                     // flags
1141                 DE_FALSE,                                                                                                       // depthTestEnable
1142                 DE_FALSE,                                                                                                       // depthWriteEnable
1143                 VK_COMPARE_OP_ALWAYS,                                                                           // depthCompareOp
1144                 DE_FALSE,                                                                                                       // depthBoundsTestEnable
1145                 DE_FALSE,                                                                                                       // stencilTestEnable
1146                 {
1147                         VK_STENCIL_OP_KEEP,                                                                                     // failOp
1148                         VK_STENCIL_OP_KEEP,                                                                                     // passOp
1149                         VK_STENCIL_OP_KEEP,                                                                                     // depthFailOp
1150                         VK_COMPARE_OP_ALWAYS,                                                                           // compareOp
1151                         0u,                                                                                                                     // compareMask
1152                         0u,                                                                                                                     // writeMask
1153                         0u,                                                                                                                     // reference
1154                 },                                                                                                                      // front
1155                 {
1156                         VK_STENCIL_OP_KEEP,                                                                                     // failOp
1157                         VK_STENCIL_OP_KEEP,                                                                                     // passOp
1158                         VK_STENCIL_OP_KEEP,                                                                                     // depthFailOp
1159                         VK_COMPARE_OP_ALWAYS,                                                                           // compareOp
1160                         0u,                                                                                                                     // compareMask
1161                         0u,                                                                                                                     // writeMask
1162                         0u,                                                                                                                     // reference
1163                 },                                                                                                                      // back;
1164                 -1.0f,                                                                                                          //      float                           minDepthBounds;
1165                 +1.0f,                                                                                                          //      float                           maxDepthBounds;
1166         };
1167         const VkViewport                                                viewport0                               =
1168         {
1169                 0.0f,                                                                                                           // x
1170                 0.0f,                                                                                                           // y
1171                 (float)renderSize.x(),                                                                          // width
1172                 (float)renderSize.y(),                                                                          // height
1173                 0.0f,                                                                                                           // minDepth
1174                 1.0f,                                                                                                           // maxDepth
1175         };
1176         const VkRect2D                                                  scissor0                                =
1177         {
1178                 {
1179                         0u,                                                                                                                     // x
1180                         0u,                                                                                                                     // y
1181                 },                                                                                                                      // offset
1182                 {
1183                         (deUint32)renderSize.x(),                                                                       // width
1184                         (deUint32)renderSize.y(),                                                                       // height
1185                 },                                                                                                                      // extent;
1186         };
1187         const VkPipelineViewportStateCreateInfo         viewportParams                  =
1188         {
1189                 VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO,          // sType
1190                 DE_NULL,                                                                                                        // pNext
1191                 0u,                                                                                                                     // flags
1192                 1u,                                                                                                                     // viewportCount
1193                 &viewport0,                                                                                                     // pViewports
1194                 1u,                                                                                                                     // scissorCount
1195                 &scissor0                                                                                                       // pScissors
1196         };
1197         const VkSampleMask                                                      sampleMask                              = ~0u;
1198         const VkPipelineMultisampleStateCreateInfo      multisampleParams               =
1199         {
1200                 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,       // sType
1201                 DE_NULL,                                                                                                        // pNext
1202                 0u,                                                                                                                     // flags
1203                 VK_SAMPLE_COUNT_1_BIT,                                                                          // rasterizationSamples
1204                 VK_FALSE,                                                                                                       // sampleShadingEnable
1205                 0.0f,                                                                                                           // minSampleShading
1206                 &sampleMask,                                                                                            // sampleMask
1207                 VK_FALSE,                                                                                                       // alphaToCoverageEnable
1208                 VK_FALSE,                                                                                                       // alphaToOneEnable
1209         };
1210         const VkPipelineRasterizationStateCreateInfo    rasterParams            =
1211         {
1212                 VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO,     // sType
1213                 DE_NULL,                                                                                                        // pNext
1214                 0u,                                                                                                                     // flags
1215                 VK_TRUE,                                                                                                        // depthClampEnable
1216                 VK_FALSE,                                                                                                       // rasterizerDiscardEnable
1217                 VK_POLYGON_MODE_FILL,                                                                           // polygonMode
1218                 VK_CULL_MODE_NONE,                                                                                      // cullMode
1219                 VK_FRONT_FACE_COUNTER_CLOCKWISE,                                                        // frontFace
1220                 VK_FALSE,                                                                                                       // depthBiasEnable
1221                 0.0f,                                                                                                           // depthBiasConstantFactor
1222                 0.0f,                                                                                                           // depthBiasClamp
1223                 0.0f,                                                                                                           // depthBiasSlopeFactor
1224                 1.0f,                                                                                                           // lineWidth
1225         };
1226         const VkPipelineInputAssemblyStateCreateInfo    inputAssemblyParams     =
1227         {
1228                 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,    // sType
1229                 DE_NULL,                                                                                                                // pNext
1230                 0u,                                                                                                                             // flags
1231                 VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST,                                                    // topology
1232                 DE_FALSE,                                                                                                               // primitiveRestartEnable
1233         };
1234         const VkVertexInputBindingDescription           vertexBinding0                  =
1235         {
1236                 0u,                                                                                                             // binding
1237                 (deUint32)sizeof(tcu::Vec4),                                                    // stride
1238                 VK_VERTEX_INPUT_RATE_VERTEX,                                                    // inputRate
1239         };
1240         const VkVertexInputAttributeDescription         vertexAttrib0                   =
1241         {
1242                 0u,                                                                                                             // location
1243                 0u,                                                                                                             // binding
1244                 VK_FORMAT_R32G32B32A32_SFLOAT,                                                  // format
1245                 0u,                                                                                                             // offset
1246         };
1247         const VkPipelineVertexInputStateCreateInfo      vertexInputStateParams  =
1248         {
1249                 VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,      // sType
1250                 DE_NULL,                                                                                                        // pNext
1251                 0u,                                                                                                                     // flags
1252                 1u,                                                                                                                     // vertexBindingDescriptionCount
1253                 &vertexBinding0,                                                                                        // pVertexBindingDescriptions
1254                 1u,                                                                                                                     // vertexAttributeDescriptionCount
1255                 &vertexAttrib0,                                                                                         // pVertexAttributeDescriptions
1256         };
1257         const VkPipelineColorBlendAttachmentState       attBlendParams                  =
1258         {
1259                 VK_FALSE,                                                                                                       // blendEnable
1260                 VK_BLEND_FACTOR_ONE,                                                                            // srcColorBlendFactor
1261                 VK_BLEND_FACTOR_ZERO,                                                                           // dstColorBlendFactor
1262                 VK_BLEND_OP_ADD,                                                                                        // colorBlendOp
1263                 VK_BLEND_FACTOR_ONE,                                                                            // srcAlphaBlendFactor
1264                 VK_BLEND_FACTOR_ZERO,                                                                           // dstAlphaBlendFactor
1265                 VK_BLEND_OP_ADD,                                                                                        // alphaBlendOp
1266                 (VK_COLOR_COMPONENT_R_BIT|
1267                  VK_COLOR_COMPONENT_G_BIT|
1268                  VK_COLOR_COMPONENT_B_BIT|
1269                  VK_COLOR_COMPONENT_A_BIT),                                                                     // colorWriteMask
1270         };
1271         const VkPipelineColorBlendStateCreateInfo       blendParams                             =
1272         {
1273                 VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO,       // sType
1274                 DE_NULL,                                                                                                        // pNext
1275                 0u,                                                                                                                     // flags
1276                 DE_FALSE,                                                                                                       // logicOpEnable
1277                 VK_LOGIC_OP_COPY,                                                                                       // logicOp
1278                 1u,                                                                                                                     // attachmentCount
1279                 &attBlendParams,                                                                                        // pAttachments
1280                 { 0.0f, 0.0f, 0.0f, 0.0f },                                                                     // blendConstants[4]
1281         };
1282         const VkGraphicsPipelineCreateInfo              pipelineParams                  =
1283         {
1284                 VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,                // sType
1285                 DE_NULL,                                                                                                // pNext
1286                 0u,                                                                                                             // flags
1287                 (deUint32)DE_LENGTH_OF_ARRAY(shaderStageParams),                // stageCount
1288                 shaderStageParams,                                                                              // pStages
1289                 &vertexInputStateParams,                                                                // pVertexInputState
1290                 &inputAssemblyParams,                                                                   // pInputAssemblyState
1291                 DE_NULL,                                                                                                // pTessellationState
1292                 &viewportParams,                                                                                // pViewportState
1293                 &rasterParams,                                                                                  // pRasterizationState
1294                 &multisampleParams,                                                                             // pMultisampleState
1295                 &depthStencilParams,                                                                    // pDepthStencilState
1296                 &blendParams,                                                                                   // pColorBlendState
1297                 (const VkPipelineDynamicStateCreateInfo*)DE_NULL,               // pDynamicState
1298                 *pipelineLayout,                                                                                // layout
1299                 *renderPass,                                                                                    // renderPass
1300                 0u,                                                                                                             // subpass
1301                 DE_NULL,                                                                                                // basePipelineHandle
1302                 0u,                                                                                                             // basePipelineIndex
1303         };
1304
1305         const Unique<VkPipeline>                                pipeline                                (createGraphicsPipeline(vk, vkDevice, DE_NULL, &pipelineParams));
1306
1307         // Framebuffer
1308         const VkFramebufferCreateInfo                   framebufferParams               =
1309         {
1310                 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,                              // sType
1311                 DE_NULL,                                                                                                // pNext
1312                 0u,                                                                                                             // flags
1313                 *renderPass,                                                                                    // renderPass
1314                 1u,                                                                                                             // attachmentCount
1315                 &*colorAttView,                                                                                 // pAttachments
1316                 (deUint32)renderSize.x(),                                                               // width
1317                 (deUint32)renderSize.y(),                                                               // height
1318                 1u,                                                                                                             // layers
1319         };
1320         const Unique<VkFramebuffer>                             framebuffer                             (createFramebuffer(vk, vkDevice, &framebufferParams));
1321
1322         const VkCommandPoolCreateInfo                   cmdPoolParams                   =
1323         {
1324                 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,                                     // sType
1325                 DE_NULL,                                                                                                        // pNext
1326                 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,                        // flags
1327                 queueFamilyIndex,                                                                                       // queueFamilyIndex
1328         };
1329         const Unique<VkCommandPool>                             cmdPool                                 (createCommandPool(vk, vkDevice, &cmdPoolParams));
1330
1331         // Command buffer
1332         const VkCommandBufferAllocateInfo               cmdBufParams                    =
1333         {
1334                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,                 // sType
1335                 DE_NULL,                                                                                                // pNext
1336                 *cmdPool,                                                                                               // pool
1337                 VK_COMMAND_BUFFER_LEVEL_PRIMARY,                                                // level
1338                 1u,                                                                                                             // bufferCount
1339         };
1340         const Unique<VkCommandBuffer>                   cmdBuf                                  (allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
1341
1342         const VkCommandBufferBeginInfo                  cmdBufBeginParams               =
1343         {
1344                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,                    // sType
1345                 DE_NULL,                                                                                                // pNext
1346                 0u,                                                                                                             // flags
1347                 (const VkCommandBufferInheritanceInfo*)DE_NULL,
1348         };
1349
1350         // Record commands
1351         VK_CHECK(vk.beginCommandBuffer(*cmdBuf, &cmdBufBeginParams));
1352
1353         {
1354                 const VkMemoryBarrier           vertFlushBarrier        =
1355                 {
1356                         VK_STRUCTURE_TYPE_MEMORY_BARRIER,                       // sType
1357                         DE_NULL,                                                                        // pNext
1358                         VK_ACCESS_HOST_WRITE_BIT,                                       // srcAccessMask
1359                         VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT,            // dstAccessMask
1360                 };
1361                 const VkImageMemoryBarrier      colorAttBarrier         =
1362                 {
1363                         VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,         // sType
1364                         DE_NULL,                                                                        // pNext
1365                         0u,                                                                                     // srcAccessMask
1366                         (VK_ACCESS_COLOR_ATTACHMENT_READ_BIT|
1367                          VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT),         // dstAccessMask
1368                         VK_IMAGE_LAYOUT_UNDEFINED,                                      // oldLayout
1369                         VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,       // newLayout
1370                         queueFamilyIndex,                                                       // srcQueueFamilyIndex
1371                         queueFamilyIndex,                                                       // dstQueueFamilyIndex
1372                         *image,                                                                         // image
1373                         {
1374                                 VK_IMAGE_ASPECT_COLOR_BIT,                                      // aspectMask
1375                                 0u,                                                                                     // baseMipLevel
1376                                 1u,                                                                                     // levelCount
1377                                 0u,                                                                                     // baseArrayLayer
1378                                 1u,                                                                                     // layerCount
1379                         }                                                                                       // subresourceRange
1380                 };
1381                 vk.cmdPipelineBarrier(*cmdBuf, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, (VkDependencyFlags)0, 1, &vertFlushBarrier, 0, (const VkBufferMemoryBarrier*)DE_NULL, 1, &colorAttBarrier);
1382         }
1383
1384         {
1385                 const VkClearValue                      clearValue              = makeClearValueColorF32(clearColor[0],
1386                                                                                                                                                          clearColor[1],
1387                                                                                                                                                          clearColor[2],
1388                                                                                                                                                          clearColor[3]);
1389                 const VkRenderPassBeginInfo     passBeginParams =
1390                 {
1391                         VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,                       // sType
1392                         DE_NULL,                                                                                        // pNext
1393                         *renderPass,                                                                            // renderPass
1394                         *framebuffer,                                                                           // framebuffer
1395                         {
1396                                 { 0, 0 },
1397                                 { (deUint32)renderSize.x(), (deUint32)renderSize.y() }
1398                         },                                                                                                      // renderArea
1399                         1u,                                                                                                     // clearValueCount
1400                         &clearValue,                                                                            // pClearValues
1401                 };
1402                 vk.cmdBeginRenderPass(*cmdBuf, &passBeginParams, VK_SUBPASS_CONTENTS_INLINE);
1403         }
1404
1405         vk.cmdBindPipeline(*cmdBuf, VK_PIPELINE_BIND_POINT_GRAPHICS, *pipeline);
1406         {
1407                 const VkDeviceSize bindingOffset = 0;
1408                 vk.cmdBindVertexBuffers(*cmdBuf, 0u, 1u, &vertexBuffer.get(), &bindingOffset);
1409         }
1410         vk.cmdDraw(*cmdBuf, 3u, 1u, 0u, 0u);
1411         vk.cmdEndRenderPass(*cmdBuf);
1412
1413         {
1414                 const VkImageMemoryBarrier      renderFinishBarrier     =
1415                 {
1416                         VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,         // sType
1417                         DE_NULL,                                                                        // pNext
1418                         VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,           // outputMask
1419                         VK_ACCESS_TRANSFER_READ_BIT,                            // inputMask
1420                         VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,       // oldLayout
1421                         VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,           // newLayout
1422                         queueFamilyIndex,                                                       // srcQueueFamilyIndex
1423                         queueFamilyIndex,                                                       // dstQueueFamilyIndex
1424                         *image,                                                                         // image
1425                         {
1426                                 VK_IMAGE_ASPECT_COLOR_BIT,                                      // aspectMask
1427                                 0u,                                                                                     // baseMipLevel
1428                                 1u,                                                                                     // mipLevels
1429                                 0u,                                                                                     // baseArraySlice
1430                                 1u,                                                                                     // arraySize
1431                         }                                                                                       // subresourceRange
1432                 };
1433                 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);
1434         }
1435
1436         {
1437                 const VkBufferImageCopy copyParams      =
1438                 {
1439                         (VkDeviceSize)0u,                                               // bufferOffset
1440                         (deUint32)renderSize.x(),                               // bufferRowLength
1441                         (deUint32)renderSize.y(),                               // bufferImageHeight
1442                         {
1443                                 VK_IMAGE_ASPECT_COLOR_BIT,                              // aspectMask
1444                                 0u,                                                                             // mipLevel
1445                                 0u,                                                                             // baseArrayLayer
1446                                 1u,                                                                             // layerCount
1447                         },                                                                              // imageSubresource
1448                         { 0u, 0u, 0u },                                                 // imageOffset
1449                         {
1450                                 (deUint32)renderSize.x(),
1451                                 (deUint32)renderSize.y(),
1452                                 1u
1453                         }                                                                               // imageExtent
1454                 };
1455                 vk.cmdCopyImageToBuffer(*cmdBuf, *image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, *readImageBuffer, 1u, &copyParams);
1456         }
1457
1458         {
1459                 const VkBufferMemoryBarrier     copyFinishBarrier       =
1460                 {
1461                         VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,        // sType
1462                         DE_NULL,                                                                        // pNext
1463                         VK_ACCESS_TRANSFER_WRITE_BIT,                           // srcAccessMask
1464                         VK_ACCESS_HOST_READ_BIT,                                        // dstAccessMask
1465                         queueFamilyIndex,                                                       // srcQueueFamilyIndex
1466                         queueFamilyIndex,                                                       // dstQueueFamilyIndex
1467                         *readImageBuffer,                                                       // buffer
1468                         0u,                                                                                     // offset
1469                         imageSizeBytes                                                          // size
1470                 };
1471                 vk.cmdPipelineBarrier(*cmdBuf, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 1, &copyFinishBarrier, 0, (const VkImageMemoryBarrier*)DE_NULL);
1472         }
1473
1474         VK_CHECK(vk.endCommandBuffer(*cmdBuf));
1475
1476         // Upload vertex data
1477         {
1478                 const VkMappedMemoryRange       range                   =
1479                 {
1480                         VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE,  // sType
1481                         DE_NULL,                                                                // pNext
1482                         vertexBufferMemory->getMemory(),                // memory
1483                         0,                                                                              // offset
1484                         (VkDeviceSize)sizeof(vertices),                 // size
1485                 };
1486                 void*                                           vertexBufPtr    = vertexBufferMemory->getHostPtr();
1487
1488                 deMemcpy(vertexBufPtr, &vertices[0], sizeof(vertices));
1489                 VK_CHECK(vk.flushMappedMemoryRanges(vkDevice, 1u, &range));
1490         }
1491
1492         // Submit & wait for completion
1493         {
1494                 const VkFenceCreateInfo fenceParams     =
1495                 {
1496                         VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,    // sType
1497                         DE_NULL,                                                                // pNext
1498                         0u,                                                                             // flags
1499                 };
1500                 const VkSubmitInfo              submitInfo      =
1501                 {
1502                         VK_STRUCTURE_TYPE_SUBMIT_INFO,                  // sType
1503                         DE_NULL,                                                                // pNext
1504                         0u,                                                                             // waitSemaphoreCount
1505                         DE_NULL,                                                                // pWaitSemaphores
1506                         (const VkPipelineStageFlags*)DE_NULL,
1507                         1u,                                                                             // commandBufferCount
1508                         &cmdBuf.get(),                                                  // pCommandBuffers
1509                         0u,                                                                             // signalSemaphoreCount
1510                         DE_NULL,                                                                // pSignalSemaphores
1511                 };
1512                 const Unique<VkFence>   fence           (createFence(vk, vkDevice, &fenceParams));
1513
1514                 VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence));
1515                 VK_CHECK(vk.waitForFences(vkDevice, 1u, &fence.get(), DE_TRUE, ~0ull));
1516         }
1517
1518         // Read results, render reference, compare
1519         {
1520                 const tcu::TextureFormat                        tcuFormat               = vk::mapVkFormat(colorFormat);
1521                 const VkMappedMemoryRange                       range                   =
1522                 {
1523                         VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE,  // sType
1524                         DE_NULL,                                                                // pNext
1525                         readImageBufferMemory->getMemory(),             // memory
1526                         0,                                                                              // offset
1527                         imageSizeBytes,                                                 // size
1528                 };
1529                 const tcu::ConstPixelBufferAccess       resultAccess    (tcuFormat, renderSize.x(), renderSize.y(), 1, readImageBufferMemory->getHostPtr());
1530
1531                 VK_CHECK(vk.invalidateMappedMemoryRanges(vkDevice, 1u, &range));
1532
1533                 {
1534                         tcu::TextureLevel       refImage                (tcuFormat, renderSize.x(), renderSize.y());
1535                         const tcu::UVec4        threshold               (0u);
1536                         const tcu::IVec3        posDeviation    (1,1,0);
1537
1538                         tcu::clear(refImage.getAccess(), clearColor);
1539                         renderReferenceTriangle(refImage.getAccess(), vertices);
1540
1541                         if (tcu::intThresholdPositionDeviationCompare(context.getTestContext().getLog(),
1542                                                                                                                   "ComparisonResult",
1543                                                                                                                   "Image comparison result",
1544                                                                                                                   refImage.getAccess(),
1545                                                                                                                   resultAccess,
1546                                                                                                                   threshold,
1547                                                                                                                   posDeviation,
1548                                                                                                                   false,
1549                                                                                                                   tcu::COMPARE_LOG_RESULT))
1550                                 return tcu::TestStatus::pass("Rendering succeeded");
1551                         else
1552                                 return tcu::TestStatus::fail("Image comparison failed");
1553                 }
1554         }
1555
1556         return tcu::TestStatus::pass("Rendering succeeded");
1557 }
1558
1559 } // anonymous
1560
1561 tcu::TestCaseGroup* createSmokeTests (tcu::TestContext& testCtx)
1562 {
1563         de::MovePtr<tcu::TestCaseGroup> smokeTests      (new tcu::TestCaseGroup(testCtx, "smoke", "Smoke Tests"));
1564
1565         addFunctionCase                         (smokeTests.get(), "create_sampler",                    "",     createSamplerTest);
1566         addFunctionCaseWithPrograms     (smokeTests.get(), "create_shader",                             "", createShaderProgs,          createShaderModuleTest);
1567         addFunctionCaseWithPrograms     (smokeTests.get(), "triangle",                                  "", createTriangleProgs,        renderTriangleTest);
1568         addFunctionCaseWithPrograms     (smokeTests.get(), "asm_triangle",                              "", createTriangleAsmProgs,     renderTriangleTest);
1569         addFunctionCaseWithPrograms     (smokeTests.get(), "asm_triangle_no_opname",    "", createProgsNoOpName,        renderTriangleTest);
1570         addFunctionCaseWithPrograms     (smokeTests.get(), "unused_resolve_attachment", "", createTriangleProgs,        renderTriangleUnusedResolveAttachmentTest);
1571
1572         return smokeTests.release();
1573 }
1574
1575 } // api
1576 } // vkt