Merge "Merge "Try to determine renderable format in lifetime tests am: c0a5dc217f...
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / modules / vulkan / pipeline / vktPipelineMultisampleBaseResolve.cpp
1 /*------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
4 *
5 * Copyright (c) 2016 The Khronos Group 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 vktPipelineMultisampleBaseResolve.cpp
21 * \brief Base class for tests that check results of multisample resolve
22 *//*--------------------------------------------------------------------*/
23
24 #include "vktPipelineMultisampleBaseResolve.hpp"
25 #include "vktPipelineMakeUtil.hpp"
26 #include "vkBuilderUtil.hpp"
27 #include "vkQueryUtil.hpp"
28 #include "tcuTestLog.hpp"
29 #include <vector>
30
31 namespace vkt
32 {
33 namespace pipeline
34 {
35 namespace multisample
36 {
37
38 using namespace vk;
39
40 tcu::TestStatus MSInstanceBaseResolve::iterate (void)
41 {
42         const InstanceInterface&        instance                        = m_context.getInstanceInterface();
43         const DeviceInterface&          deviceInterface         = m_context.getDeviceInterface();
44         const VkDevice                          device                          = m_context.getDevice();
45         const VkPhysicalDevice          physicalDevice          = m_context.getPhysicalDevice();
46         Allocator&                                      allocator                       = m_context.getDefaultAllocator();
47         const VkQueue                           queue                           = m_context.getUniversalQueue();
48         const deUint32                          queueFamilyIndex        = m_context.getUniversalQueueFamilyIndex();
49
50         VkImageCreateInfo                       imageMSInfo;
51         VkImageCreateInfo                       imageRSInfo;
52
53         // Check if image size does not exceed device limits
54         validateImageSize(instance, physicalDevice, m_imageType, m_imageMSParams.imageSize);
55
56         // Check if device supports image format as color attachment
57         validateImageFeatureFlags(instance, physicalDevice, mapTextureFormat(m_imageFormat), VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
58
59         imageMSInfo.sType                                       = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
60         imageMSInfo.pNext                                       = DE_NULL;
61         imageMSInfo.flags                                       = 0u;
62         imageMSInfo.imageType                           = mapImageType(m_imageType);
63         imageMSInfo.format                                      = mapTextureFormat(m_imageFormat);
64         imageMSInfo.extent                                      = makeExtent3D(getLayerSize(m_imageType, m_imageMSParams.imageSize));
65         imageMSInfo.arrayLayers                         = getNumLayers(m_imageType, m_imageMSParams.imageSize);
66         imageMSInfo.mipLevels                           = 1u;
67         imageMSInfo.samples                                     = m_imageMSParams.numSamples;
68         imageMSInfo.tiling                                      = VK_IMAGE_TILING_OPTIMAL;
69         imageMSInfo.initialLayout                       = VK_IMAGE_LAYOUT_UNDEFINED;
70         imageMSInfo.usage                                       = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
71         imageMSInfo.sharingMode                         = VK_SHARING_MODE_EXCLUSIVE;
72         imageMSInfo.queueFamilyIndexCount       = 0u;
73         imageMSInfo.pQueueFamilyIndices         = DE_NULL;
74
75         if (m_imageType == IMAGE_TYPE_CUBE || m_imageType == IMAGE_TYPE_CUBE_ARRAY)
76         {
77                 imageMSInfo.flags |= VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT;
78         }
79
80         validateImageInfo(instance, physicalDevice, imageMSInfo);
81
82         const de::UniquePtr<Image> imageMS(new Image(deviceInterface, device, allocator, imageMSInfo, MemoryRequirement::Any));
83
84         imageRSInfo                     = imageMSInfo;
85         imageRSInfo.samples     = VK_SAMPLE_COUNT_1_BIT;
86
87         validateImageInfo(instance, physicalDevice, imageRSInfo);
88
89         const de::UniquePtr<Image> imageRS(new Image(deviceInterface, device, allocator, imageRSInfo, MemoryRequirement::Any));
90
91         // Create render pass
92         const VkAttachmentDescription attachmentMSDesc =
93         {
94                 (VkAttachmentDescriptionFlags)0u,                       // VkAttachmentDescriptionFlags         flags;
95                 imageMSInfo.format,                                                     // VkFormat                                                     format;
96                 imageMSInfo.samples,                                            // VkSampleCountFlagBits                        samples;
97                 VK_ATTACHMENT_LOAD_OP_CLEAR,                            // VkAttachmentLoadOp                           loadOp;
98                 VK_ATTACHMENT_STORE_OP_STORE,                           // VkAttachmentStoreOp                          storeOp;
99                 VK_ATTACHMENT_LOAD_OP_DONT_CARE,                        // VkAttachmentLoadOp                           stencilLoadOp;
100                 VK_ATTACHMENT_STORE_OP_DONT_CARE,                       // VkAttachmentStoreOp                          stencilStoreOp;
101                 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,       // VkImageLayout                                        initialLayout;
102                 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL        // VkImageLayout                                        finalLayout;
103         };
104
105         const VkAttachmentDescription attachmentRSDesc =
106         {
107                 (VkAttachmentDescriptionFlags)0u,                       // VkAttachmentDescriptionFlags         flags;
108                 imageRSInfo.format,                                                     // VkFormat                                                     format;
109                 imageRSInfo.samples,                                            // VkSampleCountFlagBits                        samples;
110                 VK_ATTACHMENT_LOAD_OP_CLEAR,                    // VkAttachmentLoadOp                           loadOp;
111                 VK_ATTACHMENT_STORE_OP_STORE,                           // VkAttachmentStoreOp                          storeOp;
112                 VK_ATTACHMENT_LOAD_OP_DONT_CARE,                        // VkAttachmentLoadOp                           stencilLoadOp;
113                 VK_ATTACHMENT_STORE_OP_DONT_CARE,                       // VkAttachmentStoreOp                          stencilStoreOp;
114                 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,       // VkImageLayout                                        initialLayout;
115                 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL        // VkImageLayout                                        finalLayout;
116         };
117
118         const VkAttachmentDescription attachments[] = { attachmentMSDesc, attachmentRSDesc };
119
120         const VkAttachmentReference attachmentMSRef =
121         {
122                 0u,                                                                                     // deUint32                     attachment;
123                 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL        // VkImageLayout        layout;
124         };
125
126         const VkAttachmentReference attachmentRSRef =
127         {
128                 1u,                                                                                     // deUint32                     attachment;
129                 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL        // VkImageLayout        layout;
130         };
131
132         const VkAttachmentReference* resolveAttachment = m_imageMSParams.numSamples == VK_SAMPLE_COUNT_1_BIT ? DE_NULL : &attachmentRSRef;
133
134         const VkSubpassDescription subpassDescription =
135         {
136                 (VkSubpassDescriptionFlags)0u,                                          // VkSubpassDescriptionFlags            flags;
137                 VK_PIPELINE_BIND_POINT_GRAPHICS,                                        // VkPipelineBindPoint                          pipelineBindPoint;
138                 0u,                                                                                                     // deUint32                                                     inputAttachmentCount;
139                 DE_NULL,                                                                                        // const VkAttachmentReference*         pInputAttachments;
140                 1u,                                                                                                     // deUint32                                                     colorAttachmentCount;
141                 &attachmentMSRef,                                                                       // const VkAttachmentReference*         pColorAttachments;
142                 resolveAttachment,                                                              // const VkAttachmentReference*         pResolveAttachments;
143                 DE_NULL,                                                                                        // const VkAttachmentReference*         pDepthStencilAttachment;
144                 0u,                                                                                                     // deUint32                                                     preserveAttachmentCount;
145                 DE_NULL                                                                                         // const deUint32*                                      pPreserveAttachments;
146         };
147
148         const VkRenderPassCreateInfo renderPassInfo =
149         {
150                 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,                      // VkStructureType                                      sType;
151                 DE_NULL,                                                                                        // const void*                                          pNext;
152                 (VkRenderPassCreateFlags)0u,                                            // VkRenderPassCreateFlags                      flags;
153                 2u,                                                                                                     // deUint32                                                     attachmentCount;
154                 attachments,                                                                            // const VkAttachmentDescription*       pAttachments;
155                 1u,                                                                                                     // deUint32                                                     subpassCount;
156                 &subpassDescription,                                                            // const VkSubpassDescription*          pSubpasses;
157                 0u,                                                                                                     // deUint32                                                     dependencyCount;
158                 DE_NULL                                                                                         // const VkSubpassDependency*           pDependencies;
159         };
160
161         const Unique<VkRenderPass> renderPass(createRenderPass(deviceInterface, device, &renderPassInfo));
162
163         const VkImageSubresourceRange fullImageRange = makeImageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT, 0u, imageMSInfo.mipLevels, 0u, imageMSInfo.arrayLayers);
164
165         // Create color attachments image views
166         const Unique<VkImageView> imageMSView(makeImageView(deviceInterface, device, **imageMS, mapImageViewType(m_imageType), imageMSInfo.format, fullImageRange));
167         const Unique<VkImageView> imageRSView(makeImageView(deviceInterface, device, **imageRS, mapImageViewType(m_imageType), imageMSInfo.format, fullImageRange));
168
169         const VkImageView attachmentsViews[] = { *imageMSView, *imageRSView };
170
171         // Create framebuffer
172         const VkFramebufferCreateInfo framebufferInfo =
173         {
174                 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,      // VkStructureType                             sType;
175                 DE_NULL,                                                                        // const void*                                 pNext;
176                 (VkFramebufferCreateFlags)0u,                           // VkFramebufferCreateFlags                    flags;
177                 *renderPass,                                                            // VkRenderPass                                renderPass;
178                 2u,                                                                                     // uint32_t                                    attachmentCount;
179                 attachmentsViews,                                                       // const VkImageView*                          pAttachments;
180                 imageMSInfo.extent.width,                                       // uint32_t                                    width;
181                 imageMSInfo.extent.height,                                      // uint32_t                                    height;
182                 imageMSInfo.arrayLayers,                                        // uint32_t                                    layers;
183         };
184
185         const Unique<VkFramebuffer> framebuffer(createFramebuffer(deviceInterface, device, &framebufferInfo));
186
187         // Create pipeline layout
188         const VkPipelineLayoutCreateInfo pipelineLayoutParams =
189         {
190                 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,          // VkStructureType                                      sType;
191                 DE_NULL,                                                                                        // const void*                                          pNext;
192                 (VkPipelineLayoutCreateFlags)0u,                                        // VkPipelineLayoutCreateFlags          flags;
193                 0u,                                                                                                     // deUint32                                                     setLayoutCount;
194                 DE_NULL,                                                                                        // const VkDescriptorSetLayout*         pSetLayouts;
195                 0u,                                                                                                     // deUint32                                                     pushConstantRangeCount;
196                 DE_NULL,                                                                                        // const VkPushConstantRange*           pPushConstantRanges;
197         };
198
199         const Unique<VkPipelineLayout> pipelineLayout(createPipelineLayout(deviceInterface, device, &pipelineLayoutParams));
200
201         // Create vertex attributes data
202         const VertexDataDesc vertexDataDesc = getVertexDataDescripton();
203
204         de::SharedPtr<Buffer> vertexBuffer = de::SharedPtr<Buffer>(new Buffer(deviceInterface, device, allocator, makeBufferCreateInfo(vertexDataDesc.dataSize, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT), MemoryRequirement::HostVisible));
205         const Allocation& vertexBufferAllocation = vertexBuffer->getAllocation();
206
207         uploadVertexData(vertexBufferAllocation, vertexDataDesc);
208
209         flushMappedMemoryRange(deviceInterface, device, vertexBufferAllocation.getMemory(), vertexBufferAllocation.getOffset(), VK_WHOLE_SIZE);
210
211         const VkVertexInputBindingDescription vertexBinding =
212         {
213                 0u,                                                     // deUint32                             binding;
214                 vertexDataDesc.dataStride,      // deUint32                             stride;
215                 VK_VERTEX_INPUT_RATE_VERTEX     // VkVertexInputRate    inputRate;
216         };
217
218         const VkPipelineVertexInputStateCreateInfo vertexInputStateInfo =
219         {
220                 VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,                      // VkStructureType                             sType;
221                 DE_NULL,                                                                                                                        // const void*                                 pNext;
222                 (VkPipelineVertexInputStateCreateFlags)0u,                                                      // VkPipelineVertexInputStateCreateFlags       flags;
223                 1u,                                                                                                                                     // uint32_t                                    vertexBindingDescriptionCount;
224                 &vertexBinding,                                                                                                         // const VkVertexInputBindingDescription*      pVertexBindingDescriptions;
225                 static_cast<deUint32>(vertexDataDesc.vertexAttribDescVec.size()),       // uint32_t                                    vertexAttributeDescriptionCount;
226                 dataPointer(vertexDataDesc.vertexAttribDescVec),                                        // const VkVertexInputAttributeDescription*    pVertexAttributeDescriptions;
227         };
228
229         const VkPipelineInputAssemblyStateCreateInfo inputAssemblyStateInfo =
230         {
231                 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,    // VkStructureType                             sType;
232                 DE_NULL,                                                                                                                // const void*                                 pNext;
233                 (VkPipelineInputAssemblyStateCreateFlags)0u,                                    // VkPipelineInputAssemblyStateCreateFlags     flags;
234                 vertexDataDesc.primitiveTopology,                                                               // VkPrimitiveTopology                         topology;
235                 VK_FALSE,                                                                                                               // VkBool32                                    primitiveRestartEnable;
236         };
237
238         const VkViewport viewport =
239         {
240                 0.0f, 0.0f,
241                 static_cast<float>(imageMSInfo.extent.width), static_cast<float>(imageMSInfo.extent.height),
242                 0.0f, 1.0f
243         };
244
245         const VkRect2D scissor =
246         {
247                 makeOffset2D(0, 0),
248                 makeExtent2D(imageMSInfo.extent.width, imageMSInfo.extent.height),
249         };
250
251         const VkPipelineViewportStateCreateInfo viewportStateInfo =
252         {
253                 VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO,                  // VkStructureType                             sType;
254                 DE_NULL,                                                                                                                // const void*                                 pNext;
255                 (VkPipelineViewportStateCreateFlags)0u,                                                 // VkPipelineViewportStateCreateFlags          flags;
256                 1u,                                                                                                                             // uint32_t                                    viewportCount;
257                 &viewport,                                                                                                              // const VkViewport*                           pViewports;
258                 1u,                                                                                                                             // uint32_t                                    scissorCount;
259                 &scissor,                                                                                                               // const VkRect2D*                             pScissors;
260         };
261
262         const VkPipelineRasterizationStateCreateInfo rasterizationStateInfo =
263         {
264                 VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO,             // VkStructureType                          sType;
265                 DE_NULL,                                                                                                                // const void*                              pNext;
266                 (VkPipelineRasterizationStateCreateFlags)0u,                                    // VkPipelineRasterizationStateCreateFlags  flags;
267                 VK_FALSE,                                                                                                               // VkBool32                                 depthClampEnable;
268                 VK_FALSE,                                                                                                               // VkBool32                                 rasterizerDiscardEnable;
269                 VK_POLYGON_MODE_FILL,                                                                                   // VkPolygonMode                                                        polygonMode;
270                 VK_CULL_MODE_NONE,                                                                                              // VkCullModeFlags                                                      cullMode;
271                 VK_FRONT_FACE_COUNTER_CLOCKWISE,                                                                // VkFrontFace                                                          frontFace;
272                 VK_FALSE,                                                                                                               // VkBool32                                                                     depthBiasEnable;
273                 0.0f,                                                                                                                   // float                                                                        depthBiasConstantFactor;
274                 0.0f,                                                                                                                   // float                                                                        depthBiasClamp;
275                 0.0f,                                                                                                                   // float                                                                        depthBiasSlopeFactor;
276                 1.0f,                                                                                                                   // float                                                                        lineWidth;
277         };
278
279         const VkPipelineMultisampleStateCreateInfo multisampleStateInfo =
280         {
281                 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,               // VkStructureType                                                      sType;
282                 DE_NULL,                                                                                                                // const void*                                                          pNext;
283                 (VkPipelineMultisampleStateCreateFlags)0u,                                              // VkPipelineMultisampleStateCreateFlags        flags;
284                 imageMSInfo.samples,                                                                                    // VkSampleCountFlagBits                                        rasterizationSamples;
285                 VK_TRUE,                                                                                                                // VkBool32                                                                     sampleShadingEnable;
286                 1.0f,                                                                                                                   // float                                                                        minSampleShading;
287                 DE_NULL,                                                                                                                // const VkSampleMask*                                          pSampleMask;
288                 VK_FALSE,                                                                                                               // VkBool32                                                                     alphaToCoverageEnable;
289                 VK_FALSE,                                                                                                               // VkBool32                                                                     alphaToOneEnable;
290         };
291
292         const VkStencilOpState stencilOpState = makeStencilOpState
293         (
294                 VK_STENCIL_OP_KEEP,             // stencil fail
295                 VK_STENCIL_OP_KEEP,             // depth & stencil pass
296                 VK_STENCIL_OP_KEEP,             // depth only fail
297                 VK_COMPARE_OP_ALWAYS,   // compare op
298                 0u,                                             // compare mask
299                 0u,                                             // write mask
300                 0u                                              // reference
301         );
302
303         const VkPipelineDepthStencilStateCreateInfo depthStencilStateInfo =
304         {
305                 VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO,             // VkStructureType                                                      sType;
306                 DE_NULL,                                                                                                                // const void*                                                          pNext;
307                 (VkPipelineDepthStencilStateCreateFlags)0u,                                             // VkPipelineDepthStencilStateCreateFlags       flags;
308                 VK_FALSE,                                                                                                               // VkBool32                                                                     depthTestEnable;
309                 VK_FALSE,                                                                                                               // VkBool32                                                                     depthWriteEnable;
310                 VK_COMPARE_OP_LESS,                                                                                             // VkCompareOp                                                          depthCompareOp;
311                 VK_FALSE,                                                                                                               // VkBool32                                                                     depthBoundsTestEnable;
312                 VK_FALSE,                                                                                                               // VkBool32                                                                     stencilTestEnable;
313                 stencilOpState,                                                                                                 // VkStencilOpState                                                     front;
314                 stencilOpState,                                                                                                 // VkStencilOpState                                                     back;
315                 0.0f,                                                                                                                   // float                                                                        minDepthBounds;
316                 1.0f,                                                                                                                   // float                                                                        maxDepthBounds;
317         };
318
319         const VkColorComponentFlags colorComponentsAll = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT;
320
321         const VkPipelineColorBlendAttachmentState colorBlendAttachmentState =
322         {
323                 VK_FALSE,                                                                                                               // VkBool32                                     blendEnable;
324                 VK_BLEND_FACTOR_ONE,                                                                                    // VkBlendFactor                        srcColorBlendFactor;
325                 VK_BLEND_FACTOR_ZERO,                                                                                   // VkBlendFactor                        dstColorBlendFactor;
326                 VK_BLEND_OP_ADD,                                                                                                // VkBlendOp                            colorBlendOp;
327                 VK_BLEND_FACTOR_ONE,                                                                                    // VkBlendFactor                        srcAlphaBlendFactor;
328                 VK_BLEND_FACTOR_ZERO,                                                                                   // VkBlendFactor                        dstAlphaBlendFactor;
329                 VK_BLEND_OP_ADD,                                                                                                // VkBlendOp                            alphaBlendOp;
330                 colorComponentsAll,                                                                                             // VkColorComponentFlags        colorWriteMask;
331         };
332
333         const VkPipelineColorBlendStateCreateInfo colorBlendStateInfo =
334         {
335                 VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO,               // VkStructureType                                                              sType;
336                 DE_NULL,                                                                                                                // const void*                                                                  pNext;
337                 (VkPipelineColorBlendStateCreateFlags)0u,                                               // VkPipelineColorBlendStateCreateFlags                 flags;
338                 VK_FALSE,                                                                                                               // VkBool32                                                                             logicOpEnable;
339                 VK_LOGIC_OP_COPY,                                                                                               // VkLogicOp                                                                    logicOp;
340                 1u,                                                                                                                             // deUint32                                                                             attachmentCount;
341                 &colorBlendAttachmentState,                                                                             // const VkPipelineColorBlendAttachmentState*   pAttachments;
342                 { 0.0f, 0.0f, 0.0f, 0.0f },                                                                             // float                                                                                blendConstants[4];
343         };
344
345         const Unique<VkShaderModule> vsModule(createShaderModule(deviceInterface, device, m_context.getBinaryCollection().get("vertex_shader"), (VkShaderModuleCreateFlags)0));
346
347         const VkPipelineShaderStageCreateInfo vsShaderStageInfo =
348         {
349                 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,                    // VkStructureType                                              sType;
350                 DE_NULL,                                                                                                                // const void*                                                  pNext;
351                 (VkPipelineShaderStageCreateFlags)0u,                                                   // VkPipelineShaderStageCreateFlags             flags;
352                 VK_SHADER_STAGE_VERTEX_BIT,                                                                             // VkShaderStageFlagBits                                stage;
353                 *vsModule,                                                                                                              // VkShaderModule                                               module;
354                 "main",                                                                                                                 // const char*                                                  pName;
355                 DE_NULL,                                                                                                                // const VkSpecializationInfo*                  pSpecializationInfo;
356         };
357
358         const Unique<VkShaderModule> fsModule(createShaderModule(deviceInterface, device, m_context.getBinaryCollection().get("fragment_shader"), (VkShaderModuleCreateFlags)0));
359
360         const VkPipelineShaderStageCreateInfo fsShaderStageInfo =
361         {
362                 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,                    // VkStructureType                                              sType;
363                 DE_NULL,                                                                                                                // const void*                                                  pNext;
364                 (VkPipelineShaderStageCreateFlags)0u,                                                   // VkPipelineShaderStageCreateFlags             flags;
365                 VK_SHADER_STAGE_FRAGMENT_BIT,                                                                   // VkShaderStageFlagBits                                stage;
366                 *fsModule,                                                                                                              // VkShaderModule                                               module;
367                 "main",                                                                                                                 // const char*                                                  pName;
368                 DE_NULL,                                                                                                                // const VkSpecializationInfo*                  pSpecializationInfo;
369         };
370
371         const VkPipelineShaderStageCreateInfo shaderStageInfos[] = { vsShaderStageInfo, fsShaderStageInfo };
372
373         const VkGraphicsPipelineCreateInfo graphicsPipelineInfo =
374         {
375                 VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,                                // VkStructureType                                                                      sType;
376                 DE_NULL,                                                                                                                // const void*                                                                          pNext;
377                 (VkPipelineCreateFlags)0,                                                                               // VkPipelineCreateFlags                                                        flags;
378                 2u,                                                                                                                             // deUint32                                                                                     stageCount;
379                 shaderStageInfos,                                                                                               // const VkPipelineShaderStageCreateInfo*                       pStages;
380                 &vertexInputStateInfo,                                                                                  // const VkPipelineVertexInputStateCreateInfo*          pVertexInputState;
381                 &inputAssemblyStateInfo,                                                                                // const VkPipelineInputAssemblyStateCreateInfo*        pInputAssemblyState;
382                 DE_NULL,                                                                                                                // const VkPipelineTessellationStateCreateInfo*         pTessellationState;
383                 &viewportStateInfo,                                                                                             // const VkPipelineViewportStateCreateInfo*                     pViewportState;
384                 &rasterizationStateInfo,                                                                                // const VkPipelineRasterizationStateCreateInfo*        pRasterizationState;
385                 &multisampleStateInfo,                                                                                  // const VkPipelineMultisampleStateCreateInfo*          pMultisampleState;
386                 &depthStencilStateInfo,                                                                                 // const VkPipelineDepthStencilStateCreateInfo*         pDepthStencilState;
387                 &colorBlendStateInfo,                                                                                   // const VkPipelineColorBlendStateCreateInfo*           pColorBlendState;
388                 DE_NULL,                                                                                                                // const VkPipelineDynamicStateCreateInfo*                      pDynamicState;
389                 *pipelineLayout,                                                                                                // VkPipelineLayout                                                                     layout;
390                 *renderPass,                                                                                                    // VkRenderPass                                                                         renderPass;
391                 0u,                                                                                                                             // deUint32                                                                                     subpass;
392                 DE_NULL,                                                                                                                // VkPipeline                                                                           basePipelineHandle;
393                 0u,                                                                                                                             // deInt32                                                                                      basePipelineIndex;
394         };
395
396         // Create graphics pipeline
397         const Unique<VkPipeline> graphicsPipeline(createGraphicsPipeline(deviceInterface, device, DE_NULL, &graphicsPipelineInfo));
398
399         // Create command buffer for compute and transfer oparations
400         const Unique<VkCommandPool>       commandPool(createCommandPool(deviceInterface, device, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,  queueFamilyIndex));
401         const Unique<VkCommandBuffer> commandBuffer(makeCommandBuffer(deviceInterface, device, *commandPool));
402
403         // Start recording commands
404         beginCommandBuffer(deviceInterface, *commandBuffer);
405
406         {
407                 VkImageMemoryBarrier imageOutputAttachmentBarriers[2];
408
409                 imageOutputAttachmentBarriers[0] = makeImageMemoryBarrier
410                 (
411                         0u,
412                         VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
413                         VK_IMAGE_LAYOUT_UNDEFINED,
414                         VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
415                         **imageMS,
416                         fullImageRange
417                 );
418
419                 imageOutputAttachmentBarriers[1] = makeImageMemoryBarrier
420                 (
421                         0u,
422                         VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
423                         VK_IMAGE_LAYOUT_UNDEFINED,
424                         VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
425                         **imageRS,
426                         fullImageRange
427                 );
428
429                 deviceInterface.cmdPipelineBarrier(*commandBuffer, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, 0u, 0u, DE_NULL, 0u, DE_NULL, 2u, imageOutputAttachmentBarriers);
430         }
431
432         {
433                 const VkDeviceSize vertexStartOffset = 0u;
434
435                 std::vector<VkClearValue> clearValues;
436                 clearValues.push_back(makeClearValueColor(tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f)));
437                 clearValues.push_back(makeClearValueColor(tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f)));
438
439                 const vk::VkRect2D renderArea =
440                 {
441                         makeOffset2D(0u, 0u),
442                         makeExtent2D(imageMSInfo.extent.width, imageMSInfo.extent.height),
443                 };
444
445                 // Begin render pass
446                 const VkRenderPassBeginInfo renderPassBeginInfo =
447                 {
448                         VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,               // VkStructureType         sType;
449                         DE_NULL,                                                                                // const void*             pNext;
450                         *renderPass,                                                                            // VkRenderPass            renderPass;
451                         *framebuffer,                                                                   // VkFramebuffer           framebuffer;
452                         renderArea,                                                                             // VkRect2D                renderArea;
453                         static_cast<deUint32>(clearValues.size()),              // deUint32                clearValueCount;
454                         &clearValues[0],                                                                // const VkClearValue*     pClearValues;
455                 };
456
457                 deviceInterface.cmdBeginRenderPass(*commandBuffer, &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
458
459                 // Bind graphics pipeline
460                 deviceInterface.cmdBindPipeline(*commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *graphicsPipeline);
461
462                 // Bind vertex buffer
463                 deviceInterface.cmdBindVertexBuffers(*commandBuffer, 0u, 1u, &vertexBuffer->get(), &vertexStartOffset);
464
465                 // Draw full screen quad
466                 deviceInterface.cmdDraw(*commandBuffer, vertexDataDesc.verticesCount, 1u, 0u, 0u);
467
468                 // End render pass
469                 deviceInterface.cmdEndRenderPass(*commandBuffer);
470         }
471
472         const VkImage sourceImage = m_imageMSParams.numSamples == VK_SAMPLE_COUNT_1_BIT ? **imageMS : **imageRS;
473
474         {
475                 const VkImageMemoryBarrier imageTransferSrcBarrier = makeImageMemoryBarrier
476                 (
477                         VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
478                         VK_ACCESS_TRANSFER_READ_BIT,
479                         VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
480                         VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
481                         sourceImage,
482                         fullImageRange
483                 );
484
485                 deviceInterface.cmdPipelineBarrier(*commandBuffer, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0u, 0u, DE_NULL, 0u, DE_NULL, 1u, &imageTransferSrcBarrier);
486         }
487
488         // Copy data from resolve image to buffer
489         const deUint32                          imageRSSizeInBytes = getImageSizeInBytes(imageRSInfo.extent, imageRSInfo.arrayLayers, m_imageFormat, imageRSInfo.mipLevels);
490
491         const VkBufferCreateInfo        bufferRSInfo = makeBufferCreateInfo(imageRSSizeInBytes, VK_BUFFER_USAGE_TRANSFER_DST_BIT);
492         const de::UniquePtr<Buffer>     bufferRS(new Buffer(deviceInterface, device, allocator, bufferRSInfo, MemoryRequirement::HostVisible));
493
494         {
495                 const VkBufferImageCopy bufferImageCopy =
496                 {
497                         0u,                                                                                                                                                                             //      VkDeviceSize                            bufferOffset;
498                         0u,                                                                                                                                                                             //      deUint32                                        bufferRowLength;
499                         0u,                                                                                                                                                                             //      deUint32                                        bufferImageHeight;
500                         makeImageSubresourceLayers(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 0u, imageRSInfo.arrayLayers), //      VkImageSubresourceLayers        imageSubresource;
501                         makeOffset3D(0, 0, 0),                                                                                                                                  //      VkOffset3D                                      imageOffset;
502                         imageRSInfo.extent,                                                                                                                                             //      VkExtent3D                                      imageExtent;
503                 };
504
505                 deviceInterface.cmdCopyImageToBuffer(*commandBuffer, sourceImage, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, bufferRS->get(), 1u, &bufferImageCopy);
506         }
507
508         {
509                 const VkBufferMemoryBarrier bufferRSHostReadBarrier = makeBufferMemoryBarrier
510                 (
511                         VK_ACCESS_TRANSFER_WRITE_BIT,
512                         VK_ACCESS_HOST_READ_BIT,
513                         bufferRS->get(),
514                         0u,
515                         imageRSSizeInBytes
516                 );
517
518                 deviceInterface.cmdPipelineBarrier(*commandBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0u, 0u, DE_NULL, 1u, &bufferRSHostReadBarrier, 0u, DE_NULL);
519         }
520
521         // End recording commands
522         VK_CHECK(deviceInterface.endCommandBuffer(*commandBuffer));
523
524         // Submit commands for execution and wait for completion
525         submitCommandsAndWait(deviceInterface, device, queue, *commandBuffer);
526
527         // Retrieve data from buffer to host memory
528         const Allocation& bufferRSAllocation = bufferRS->getAllocation();
529
530         invalidateMappedMemoryRange(deviceInterface, device, bufferRSAllocation.getMemory(), bufferRSAllocation.getOffset(), VK_WHOLE_SIZE);
531
532         const tcu::ConstPixelBufferAccess bufferRSData (m_imageFormat,
533                                                                                                         imageRSInfo.extent.width,
534                                                                                                         imageRSInfo.extent.height,
535                                                                                                         imageRSInfo.extent.depth * imageRSInfo.arrayLayers,
536                                                                                                         bufferRSAllocation.getHostPtr());
537
538         std::stringstream imageName;
539         imageName << getImageTypeName(m_imageType) << "_" << bufferRSData.getWidth() << "_" << bufferRSData.getHeight() << "_" << bufferRSData.getDepth() << std::endl;
540
541         m_context.getTestContext().getLog()
542                 << tcu::TestLog::Section(imageName.str(), imageName.str())
543                 << tcu::LogImage("image", "", bufferRSData)
544                 << tcu::TestLog::EndSection;
545
546         return verifyImageData(imageRSInfo, bufferRSData);
547 }
548
549 } // multisample
550 } // pipeline
551 } // vkt