Merge vk-gl-cts/vulkan-cts-1.1.0 into vk-gl-cts/vulkan-cts-next-dev
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / modules / vulkan / pipeline / vktPipelineMultisampleTests.cpp
1 /*------------------------------------------------------------------------
2  * Vulkan Conformance Tests
3  * ------------------------
4  *
5  * Copyright (c) 2015 The Khronos Group Inc.
6  * Copyright (c) 2015 Imagination Technologies Ltd.
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  *//*!
21  * \file
22  * \brief Multisample Tests
23  *//*--------------------------------------------------------------------*/
24
25 #include "vktPipelineMultisampleTests.hpp"
26 #include "vktPipelineMultisampleImageTests.hpp"
27 #include "vktPipelineMultisampleSampleLocationsExtTests.hpp"
28 #include "vktPipelineClearUtil.hpp"
29 #include "vktPipelineImageUtil.hpp"
30 #include "vktPipelineVertexUtil.hpp"
31 #include "vktPipelineReferenceRenderer.hpp"
32 #include "vktTestCase.hpp"
33 #include "vktTestCaseUtil.hpp"
34 #include "vkImageUtil.hpp"
35 #include "vkMemUtil.hpp"
36 #include "vkPrograms.hpp"
37 #include "vkQueryUtil.hpp"
38 #include "vkRef.hpp"
39 #include "vkRefUtil.hpp"
40 #include "tcuImageCompare.hpp"
41 #include "tcuTestLog.hpp"
42 #include "deUniquePtr.hpp"
43 #include "deSharedPtr.hpp"
44 #include "deStringUtil.hpp"
45 #include "deMemory.h"
46
47 #include <sstream>
48 #include <vector>
49 #include <map>
50
51 namespace vkt
52 {
53 namespace pipeline
54 {
55
56 using namespace vk;
57
58 namespace
59 {
60 enum GeometryType
61 {
62         GEOMETRY_TYPE_OPAQUE_TRIANGLE,
63         GEOMETRY_TYPE_OPAQUE_LINE,
64         GEOMETRY_TYPE_OPAQUE_POINT,
65         GEOMETRY_TYPE_OPAQUE_QUAD,
66         GEOMETRY_TYPE_OPAQUE_QUAD_NONZERO_DEPTH,        //!< placed at z = 0.5
67         GEOMETRY_TYPE_TRANSLUCENT_QUAD,
68         GEOMETRY_TYPE_INVISIBLE_TRIANGLE,
69         GEOMETRY_TYPE_INVISIBLE_QUAD,
70         GEOMETRY_TYPE_GRADIENT_QUAD
71 };
72
73 enum TestModeBits
74 {
75         TEST_MODE_DEPTH_BIT             = 1u,
76         TEST_MODE_STENCIL_BIT   = 2u,
77 };
78 typedef deUint32 TestModeFlags;
79
80 enum RenderType
81 {
82         // resolve multisample rendering to single sampled image
83         RENDER_TYPE_RESOLVE             = 0u,
84
85         // copy samples to an array of single sampled images
86         RENDER_TYPE_COPY_SAMPLES
87 };
88
89 void                                                                    initMultisamplePrograms                         (SourceCollections& sources, GeometryType geometryType);
90 bool                                                                    isSupportedSampleCount                          (const InstanceInterface& instanceInterface, VkPhysicalDevice physicalDevice, VkSampleCountFlagBits rasterizationSamples);
91 bool                                                                    isSupportedDepthStencilFormat           (const InstanceInterface& vki, const VkPhysicalDevice physDevice, const VkFormat format);
92 VkPipelineColorBlendAttachmentState             getDefaultColorBlendAttachmentState     (void);
93 deUint32                                                                getUniqueColorsCount                            (const tcu::ConstPixelBufferAccess& image);
94 VkImageAspectFlags                                              getImageAspectFlags                                     (const VkFormat format);
95 VkPrimitiveTopology                                             getPrimitiveTopology                            (const GeometryType geometryType);
96 std::vector<Vertex4RGBA>                                generateVertices                                        (const GeometryType geometryType);
97 VkFormat                                                                findSupportedDepthStencilFormat         (Context& context, const bool useDepth, const bool useStencil);
98
99 class MultisampleTest : public vkt::TestCase
100 {
101 public:
102
103                                                                                                 MultisampleTest                                         (tcu::TestContext&                                                              testContext,
104                                                                                                                                                                          const std::string&                                                             name,
105                                                                                                                                                                          const std::string&                                                             description,
106                                                                                                                                                                          const VkPipelineMultisampleStateCreateInfo&    multisampleStateParams,
107                                                                                                                                                                          const VkPipelineColorBlendAttachmentState&             blendState,
108                                                                                                                                                                          GeometryType                                                                   geometryType);
109         virtual                                                                         ~MultisampleTest                                        (void) {}
110
111         virtual void                                                            initPrograms                                            (SourceCollections& programCollection) const;
112         virtual TestInstance*                                           createInstance                                          (Context& context) const;
113
114 protected:
115         virtual TestInstance*                                           createMultisampleTestInstance           (Context&                                                                               context,
116                                                                                                                                                                          VkPrimitiveTopology                                                    topology,
117                                                                                                                                                                          const std::vector<Vertex4RGBA>&                                vertices,
118                                                                                                                                                                          const VkPipelineMultisampleStateCreateInfo&    multisampleStateParams,
119                                                                                                                                                                          const VkPipelineColorBlendAttachmentState&             colorBlendState) const = 0;
120         VkPipelineMultisampleStateCreateInfo            m_multisampleStateParams;
121         const VkPipelineColorBlendAttachmentState       m_colorBlendState;
122         const GeometryType                                                      m_geometryType;
123         std::vector<VkSampleMask>                                       m_sampleMask;
124 };
125
126 class RasterizationSamplesTest : public MultisampleTest
127 {
128 public:
129                                                                                                 RasterizationSamplesTest                        (tcu::TestContext&              testContext,
130                                                                                                                                                                          const std::string&             name,
131                                                                                                                                                                          const std::string&             description,
132                                                                                                                                                                          VkSampleCountFlagBits  rasterizationSamples,
133                                                                                                                                                                          GeometryType                   geometryType,
134                                                                                                                                                                          TestModeFlags                  modeFlags                               = 0u);
135         virtual                                                                         ~RasterizationSamplesTest                       (void) {}
136
137 protected:
138         virtual TestInstance*                                           createMultisampleTestInstance           (Context&                                                                               context,
139                                                                                                                                                                          VkPrimitiveTopology                                                    topology,
140                                                                                                                                                                          const std::vector<Vertex4RGBA>&                                vertices,
141                                                                                                                                                                          const VkPipelineMultisampleStateCreateInfo&    multisampleStateParams,
142                                                                                                                                                                          const VkPipelineColorBlendAttachmentState&             colorBlendState) const;
143
144         static VkPipelineMultisampleStateCreateInfo     getRasterizationSamplesStateParams      (VkSampleCountFlagBits rasterizationSamples);
145
146         const TestModeFlags                                                     m_modeFlags;
147 };
148
149 class MinSampleShadingTest : public MultisampleTest
150 {
151 public:
152                                                                                                 MinSampleShadingTest                            (tcu::TestContext&              testContext,
153                                                                                                                                                                          const std::string&             name,
154                                                                                                                                                                          const std::string&             description,
155                                                                                                                                                                          VkSampleCountFlagBits  rasterizationSamples,
156                                                                                                                                                                          float                                  minSampleShading,
157                                                                                                                                                                          GeometryType                   geometryType);
158         virtual                                                                         ~MinSampleShadingTest                           (void) {}
159
160 protected:
161         virtual void                                                            initPrograms                                            (SourceCollections& programCollection) const;
162         virtual TestInstance*                                           createMultisampleTestInstance           (Context&                                                                               context,
163                                                                                                                                                                          VkPrimitiveTopology                                                    topology,
164                                                                                                                                                                          const std::vector<Vertex4RGBA>&                                vertices,
165                                                                                                                                                                          const VkPipelineMultisampleStateCreateInfo&    multisampleStateParams,
166                                                                                                                                                                          const VkPipelineColorBlendAttachmentState&             colorBlendState) const;
167
168         static VkPipelineMultisampleStateCreateInfo     getMinSampleShadingStateParams          (VkSampleCountFlagBits rasterizationSamples, float minSampleShading);
169 };
170
171 class SampleMaskTest : public MultisampleTest
172 {
173 public:
174                                                                                                 SampleMaskTest                                          (tcu::TestContext&                                      testContext,
175                                                                                                                                                                          const std::string&                                     name,
176                                                                                                                                                                          const std::string&                                     description,
177                                                                                                                                                                          VkSampleCountFlagBits                          rasterizationSamples,
178                                                                                                                                                                          const std::vector<VkSampleMask>&       sampleMask,
179                                                                                                                                                                          GeometryType                                           geometryType);
180
181         virtual                                                                         ~SampleMaskTest                                         (void) {}
182
183 protected:
184         virtual TestInstance*                                           createMultisampleTestInstance           (Context&                                                                               context,
185                                                                                                                                                                          VkPrimitiveTopology                                                    topology,
186                                                                                                                                                                          const std::vector<Vertex4RGBA>&                                vertices,
187                                                                                                                                                                          const VkPipelineMultisampleStateCreateInfo&    multisampleStateParams,
188                                                                                                                                                                          const VkPipelineColorBlendAttachmentState&             colorBlendState) const;
189
190         static VkPipelineMultisampleStateCreateInfo     getSampleMaskStateParams                        (VkSampleCountFlagBits rasterizationSamples, const std::vector<VkSampleMask>& sampleMask);
191 };
192
193 class AlphaToOneTest : public MultisampleTest
194 {
195 public:
196                                                                                                 AlphaToOneTest                                  (tcu::TestContext&                                      testContext,
197                                                                                                                                                                  const std::string&                                     name,
198                                                                                                                                                                  const std::string&                                     description,
199                                                                                                                                                                  VkSampleCountFlagBits                          rasterizationSamples);
200
201         virtual                                                                         ~AlphaToOneTest                                 (void) {}
202
203 protected:
204         virtual TestInstance*                                           createMultisampleTestInstance   (Context&                                                                               context,
205                                                                                                                                                                  VkPrimitiveTopology                                                    topology,
206                                                                                                                                                                  const std::vector<Vertex4RGBA>&                                vertices,
207                                                                                                                                                                  const VkPipelineMultisampleStateCreateInfo&    multisampleStateParams,
208                                                                                                                                                                  const VkPipelineColorBlendAttachmentState&             colorBlendState) const;
209
210         static VkPipelineMultisampleStateCreateInfo     getAlphaToOneStateParams                (VkSampleCountFlagBits rasterizationSamples);
211         static VkPipelineColorBlendAttachmentState      getAlphaToOneBlendState                 (void);
212 };
213
214 class AlphaToCoverageTest : public MultisampleTest
215 {
216 public:
217                                                                                                 AlphaToCoverageTest                             (tcu::TestContext&              testContext,
218                                                                                                                                                                  const std::string&             name,
219                                                                                                                                                                  const std::string&             description,
220                                                                                                                                                                  VkSampleCountFlagBits  rasterizationSamples,
221                                                                                                                                                                  GeometryType                   geometryType);
222
223         virtual                                                                         ~AlphaToCoverageTest                    (void) {}
224
225 protected:
226         virtual TestInstance*                                           createMultisampleTestInstance   (Context&                                                                               context,
227                                                                                                                                                                  VkPrimitiveTopology                                                    topology,
228                                                                                                                                                                  const std::vector<Vertex4RGBA>&                                vertices,
229                                                                                                                                                                  const VkPipelineMultisampleStateCreateInfo&    multisampleStateParams,
230                                                                                                                                                                  const VkPipelineColorBlendAttachmentState&             colorBlendState) const;
231
232         static VkPipelineMultisampleStateCreateInfo     getAlphaToCoverageStateParams   (VkSampleCountFlagBits rasterizationSamples);
233
234         GeometryType                                                            m_geometryType;
235 };
236
237 typedef de::SharedPtr<Unique<VkPipeline> > VkPipelineSp;
238
239 class MultisampleRenderer
240 {
241 public:
242                                                                                                 MultisampleRenderer                     (Context&                                                                               context,
243                                                                                                                                                          const VkFormat                                                                 colorFormat,
244                                                                                                                                                          const tcu::IVec2&                                                              renderSize,
245                                                                                                                                                          const VkPrimitiveTopology                                              topology,
246                                                                                                                                                          const std::vector<Vertex4RGBA>&                                vertices,
247                                                                                                                                                          const VkPipelineMultisampleStateCreateInfo&    multisampleStateParams,
248                                                                                                                                                          const VkPipelineColorBlendAttachmentState&             blendState,
249                                                                                                                                                          const RenderType                                                               renderType);
250
251                                                                                                 MultisampleRenderer                     (Context&                                                                               context,
252                                                                                                                                                          const VkFormat                                                                 colorFormat,
253                                                                                                                                                          const VkFormat                                                                 depthStencilFormat,
254                                                                                                                                                          const tcu::IVec2&                                                              renderSize,
255                                                                                                                                                          const bool                                                                             useDepth,
256                                                                                                                                                          const bool                                                                             useStencil,
257                                                                                                                                                          const deUint32                                                                 numTopologies,
258                                                                                                                                                          const VkPrimitiveTopology*                                             pTopology,
259                                                                                                                                                          const std::vector<Vertex4RGBA>*                                pVertices,
260                                                                                                                                                          const VkPipelineMultisampleStateCreateInfo&    multisampleStateParams,
261                                                                                                                                                          const VkPipelineColorBlendAttachmentState&             blendState,
262                                                                                                                                                      const RenderType                                                           renderType);
263
264         virtual                                                                         ~MultisampleRenderer            (void);
265
266         de::MovePtr<tcu::TextureLevel>                          render                                          (void);
267         de::MovePtr<tcu::TextureLevel>                          getSingleSampledImage           (deUint32 sampleId);
268
269 protected:
270         void                                                                            initialize                                      (Context&                                                                               context,
271                                                                                                                                                          const deUint32                                                                 numTopologies,
272                                                                                                                                                          const VkPrimitiveTopology*                                             pTopology,
273                                                                                                                                                          const std::vector<Vertex4RGBA>*                                pVertices);
274
275         Context&                                                                        m_context;
276
277         const VkFormat                                                          m_colorFormat;
278         const VkFormat                                                          m_depthStencilFormat;
279         tcu::IVec2                                                                      m_renderSize;
280         const bool                                                                      m_useDepth;
281         const bool                                                                      m_useStencil;
282
283         const VkPipelineMultisampleStateCreateInfo      m_multisampleStateParams;
284         const VkPipelineColorBlendAttachmentState       m_colorBlendState;
285
286         const RenderType                                                        m_renderType;
287
288         Move<VkImage>                                                           m_colorImage;
289         de::MovePtr<Allocation>                                         m_colorImageAlloc;
290         Move<VkImageView>                                                       m_colorAttachmentView;
291
292         Move<VkImage>                                                           m_resolveImage;
293         de::MovePtr<Allocation>                                         m_resolveImageAlloc;
294         Move<VkImageView>                                                       m_resolveAttachmentView;
295
296         struct PerSampleImage
297         {
298                 Move<VkImage>                                                           m_image;
299                 de::MovePtr<Allocation>                                         m_imageAlloc;
300                 Move<VkImageView>                                                       m_attachmentView;
301         };
302         std::vector<de::SharedPtr<PerSampleImage> >     m_perSampleImages;
303
304         Move<VkImage>                                                           m_depthStencilImage;
305         de::MovePtr<Allocation>                                         m_depthStencilImageAlloc;
306         Move<VkImageView>                                                       m_depthStencilAttachmentView;
307
308         Move<VkRenderPass>                                                      m_renderPass;
309         Move<VkFramebuffer>                                                     m_framebuffer;
310
311         Move<VkShaderModule>                                            m_vertexShaderModule;
312         Move<VkShaderModule>                                            m_fragmentShaderModule;
313
314         Move<VkShaderModule>                                            m_copySampleVertexShaderModule;
315         Move<VkShaderModule>                                            m_copySampleFragmentShaderModule;
316
317         Move<VkBuffer>                                                          m_vertexBuffer;
318         de::MovePtr<Allocation>                                         m_vertexBufferAlloc;
319
320         Move<VkPipelineLayout>                                          m_pipelineLayout;
321         std::vector<VkPipelineSp>                                       m_graphicsPipelines;
322
323         Move<VkDescriptorSetLayout>                                     m_copySampleDesciptorLayout;
324         Move<VkDescriptorPool>                                          m_copySampleDesciptorPool;
325         Move<VkDescriptorSet>                                           m_copySampleDesciptorSet;
326
327         Move<VkPipelineLayout>                                          m_copySamplePipelineLayout;
328         std::vector<VkPipelineSp>                                       m_copySamplePipelines;
329
330         Move<VkCommandPool>                                                     m_cmdPool;
331         Move<VkCommandBuffer>                                           m_cmdBuffer;
332
333         Move<VkFence>                                                           m_fence;
334 };
335
336 class RasterizationSamplesInstance : public vkt::TestInstance
337 {
338 public:
339                                                                                 RasterizationSamplesInstance    (Context&                                                                               context,
340                                                                                                                                                  VkPrimitiveTopology                                                    topology,
341                                                                                                                                                  const std::vector<Vertex4RGBA>&                                vertices,
342                                                                                                                                                  const VkPipelineMultisampleStateCreateInfo&    multisampleStateParams,
343                                                                                                                                                  const VkPipelineColorBlendAttachmentState&             blendState,
344                                                                                                                                                  const TestModeFlags                                                    modeFlags);
345         virtual                                                         ~RasterizationSamplesInstance   (void) {}
346
347         virtual tcu::TestStatus                         iterate                                                 (void);
348
349 protected:
350         virtual tcu::TestStatus                         verifyImage                                             (const tcu::ConstPixelBufferAccess& result);
351
352         const VkFormat                                          m_colorFormat;
353         const tcu::IVec2                                        m_renderSize;
354         const VkPrimitiveTopology                       m_primitiveTopology;
355         const std::vector<Vertex4RGBA>          m_vertices;
356         const std::vector<Vertex4RGBA>          m_fullQuadVertices;                     //!< used by depth/stencil case
357         const TestModeFlags                                     m_modeFlags;
358         de::MovePtr<MultisampleRenderer>        m_multisampleRenderer;
359 };
360
361 class MinSampleShadingInstance : public vkt::TestInstance
362 {
363 public:
364                                                                                                 MinSampleShadingInstance        (Context&                                                                               context,
365                                                                                                                                                          VkPrimitiveTopology                                                    topology,
366                                                                                                                                                          const std::vector<Vertex4RGBA>&                                vertices,
367                                                                                                                                                          const VkPipelineMultisampleStateCreateInfo&    multisampleStateParams,
368                                                                                                                                                          const VkPipelineColorBlendAttachmentState&             blendState);
369         virtual                                                                         ~MinSampleShadingInstance       (void) {}
370
371         virtual tcu::TestStatus                                         iterate                                         (void);
372
373 protected:
374         virtual tcu::TestStatus                                         verifySampleShadedImage         (const std::vector<tcu::TextureLevel>& testShadingImages,
375                                                                                                                                                          const tcu::ConstPixelBufferAccess& noSampleshadingImage);
376
377         const VkFormat                                                          m_colorFormat;
378         const tcu::IVec2                                                        m_renderSize;
379         const VkPrimitiveTopology                                       m_primitiveTopology;
380         const std::vector<Vertex4RGBA>                          m_vertices;
381         const VkPipelineMultisampleStateCreateInfo      m_multisampleStateParams;
382         const VkPipelineColorBlendAttachmentState       m_colorBlendState;
383 };
384
385 class SampleMaskInstance : public vkt::TestInstance
386 {
387 public:
388                                                                                                 SampleMaskInstance                      (Context&                                                                               context,
389                                                                                                                                                          VkPrimitiveTopology                                                    topology,
390                                                                                                                                                          const std::vector<Vertex4RGBA>&                                vertices,
391                                                                                                                                                          const VkPipelineMultisampleStateCreateInfo&    multisampleStateParams,
392                                                                                                                                                          const VkPipelineColorBlendAttachmentState&             blendState);
393         virtual                                                                         ~SampleMaskInstance                     (void) {}
394
395         virtual tcu::TestStatus                                         iterate                                         (void);
396
397 protected:
398         virtual tcu::TestStatus                                         verifyImage                                     (const tcu::ConstPixelBufferAccess& testShadingImage,
399                                                                                                                                                          const tcu::ConstPixelBufferAccess& minShadingImage,
400                                                                                                                                                          const tcu::ConstPixelBufferAccess& maxShadingImage);
401         const VkFormat                                                          m_colorFormat;
402         const tcu::IVec2                                                        m_renderSize;
403         const VkPrimitiveTopology                                       m_primitiveTopology;
404         const std::vector<Vertex4RGBA>                          m_vertices;
405         const VkPipelineMultisampleStateCreateInfo      m_multisampleStateParams;
406         const VkPipelineColorBlendAttachmentState       m_colorBlendState;
407 };
408
409 class AlphaToOneInstance : public vkt::TestInstance
410 {
411 public:
412                                                                                                 AlphaToOneInstance                      (Context&                                                                               context,
413                                                                                                                                                          VkPrimitiveTopology                                                    topology,
414                                                                                                                                                          const std::vector<Vertex4RGBA>&                                vertices,
415                                                                                                                                                          const VkPipelineMultisampleStateCreateInfo&    multisampleStateParams,
416                                                                                                                                                          const VkPipelineColorBlendAttachmentState&             blendState);
417         virtual                                                                         ~AlphaToOneInstance                     (void) {}
418
419         virtual tcu::TestStatus                                         iterate                                         (void);
420
421 protected:
422         virtual tcu::TestStatus                                         verifyImage                                     (const tcu::ConstPixelBufferAccess& alphaOneImage,
423                                                                                                                                                          const tcu::ConstPixelBufferAccess& noAlphaOneImage);
424         const VkFormat                                                          m_colorFormat;
425         const tcu::IVec2                                                        m_renderSize;
426         const VkPrimitiveTopology                                       m_primitiveTopology;
427         const std::vector<Vertex4RGBA>                          m_vertices;
428         const VkPipelineMultisampleStateCreateInfo      m_multisampleStateParams;
429         const VkPipelineColorBlendAttachmentState       m_colorBlendState;
430 };
431
432 class AlphaToCoverageInstance : public vkt::TestInstance
433 {
434 public:
435                                                                                                 AlphaToCoverageInstance         (Context&                                                                               context,
436                                                                                                                                                          VkPrimitiveTopology                                                    topology,
437                                                                                                                                                          const std::vector<Vertex4RGBA>&                                vertices,
438                                                                                                                                                          const VkPipelineMultisampleStateCreateInfo&    multisampleStateParams,
439                                                                                                                                                          const VkPipelineColorBlendAttachmentState&             blendState,
440                                                                                                                                                          GeometryType                                                                   geometryType);
441         virtual                                                                         ~AlphaToCoverageInstance        (void) {}
442
443         virtual tcu::TestStatus                                         iterate                                         (void);
444
445 protected:
446         virtual tcu::TestStatus                                         verifyImage                                     (const tcu::ConstPixelBufferAccess& result);
447         const VkFormat                                                          m_colorFormat;
448         const tcu::IVec2                                                        m_renderSize;
449         const VkPrimitiveTopology                                       m_primitiveTopology;
450         const std::vector<Vertex4RGBA>                          m_vertices;
451         const VkPipelineMultisampleStateCreateInfo      m_multisampleStateParams;
452         const VkPipelineColorBlendAttachmentState       m_colorBlendState;
453         const GeometryType                                                      m_geometryType;
454 };
455
456
457 // Helper functions
458
459 void initMultisamplePrograms (SourceCollections& sources, GeometryType geometryType)
460 {
461         std::ostringstream vertexSource;
462
463         vertexSource <<
464                 "#version 310 es\n"
465                 "layout(location = 0) in vec4 position;\n"
466                 "layout(location = 1) in vec4 color;\n"
467                 "layout(location = 0) out highp vec4 vtxColor;\n"
468                 "void main (void)\n"
469                 "{\n"
470                 "       gl_Position = position;\n"
471                 "       vtxColor = color;\n"
472                 << (geometryType == GEOMETRY_TYPE_OPAQUE_POINT ? "      gl_PointSize = 3.0f;\n"
473                         : "")
474                 << "}\n";
475
476         static const char* fragmentSource =
477                 "#version 310 es\n"
478                 "layout(location = 0) in highp vec4 vtxColor;\n"
479                 "layout(location = 0) out highp vec4 fragColor;\n"
480                 "void main (void)\n"
481                 "{\n"
482                 "       fragColor = vtxColor;\n"
483                 "}\n";
484
485         sources.glslSources.add("color_vert") << glu::VertexSource(vertexSource.str());
486         sources.glslSources.add("color_frag") << glu::FragmentSource(fragmentSource);
487 }
488
489 void initSampleShadingPrograms (SourceCollections& sources, GeometryType geometryType)
490 {
491         {
492                 std::ostringstream vertexSource;
493
494                 vertexSource <<
495                         "#version 440\n"
496                         "layout(location = 0) in vec4 position;\n"
497                         "layout(location = 1) in vec4 color;\n"
498                         "void main (void)\n"
499                         "{\n"
500                         "       gl_Position = position;\n"
501                         << (geometryType == GEOMETRY_TYPE_OPAQUE_POINT ? "      gl_PointSize = 3.0f;\n"
502                                 : "")
503                         << "}\n";
504
505                 static const char* fragmentSource =
506                         "#version 440\n"
507                         "layout(location = 0) out highp vec4 fragColor;\n"
508                         "void main (void)\n"
509                         "{\n"
510                         "       fragColor = vec4(fract(gl_FragCoord.xy), 0.0, 1.0);\n"
511                         "}\n";
512
513                 sources.glslSources.add("color_vert") << glu::VertexSource(vertexSource.str());
514                 sources.glslSources.add("color_frag") << glu::FragmentSource(fragmentSource);
515         }
516
517         {
518                 static const char*  vertexSource =
519                         "#version 440\n"
520                         "void main (void)\n"
521                         "{\n"
522                         "       const vec4 positions[4] = vec4[4](\n"
523                         "               vec4(-1.0, -1.0, 0.0, 1.0),\n"
524                         "               vec4(-1.0,  1.0, 0.0, 1.0),\n"
525                         "               vec4( 1.0, -1.0, 0.0, 1.0),\n"
526                         "               vec4( 1.0,  1.0, 0.0, 1.0)\n"
527                         "       );\n"
528                         "       gl_Position = positions[gl_VertexIndex];\n"
529                         "}\n";
530
531                 static const char* fragmentSource =
532                         "#version 440\n"
533                         "precision highp float;\n"
534                         "layout(location = 0) out highp vec4 fragColor;\n"
535                         "layout(set = 0, binding = 0, input_attachment_index = 0) uniform subpassInputMS imageMS;\n"
536                         "layout(push_constant) uniform PushConstantsBlock\n"
537                         "{\n"
538                         "       int sampleId;\n"
539                         "} pushConstants;\n"
540                         "void main (void)\n"
541                         "{\n"
542                         "       fragColor = subpassLoad(imageMS, pushConstants.sampleId);\n"
543                         "}\n";
544
545                 sources.glslSources.add("quad_vert") << glu::VertexSource(vertexSource);
546                 sources.glslSources.add("copy_sample_frag") << glu::FragmentSource(fragmentSource);
547         }
548 }
549
550 bool isSupportedSampleCount (const InstanceInterface& instanceInterface, VkPhysicalDevice physicalDevice, VkSampleCountFlagBits rasterizationSamples)
551 {
552         VkPhysicalDeviceProperties deviceProperties;
553
554         instanceInterface.getPhysicalDeviceProperties(physicalDevice, &deviceProperties);
555
556         return !!(deviceProperties.limits.framebufferColorSampleCounts & rasterizationSamples);
557 }
558
559 VkPipelineColorBlendAttachmentState getDefaultColorBlendAttachmentState (void)
560 {
561         const VkPipelineColorBlendAttachmentState colorBlendState =
562         {
563                 false,                                                                                                          // VkBool32                                     blendEnable;
564                 VK_BLEND_FACTOR_ONE,                                                                            // VkBlendFactor                        srcColorBlendFactor;
565                 VK_BLEND_FACTOR_ZERO,                                                                           // VkBlendFactor                        dstColorBlendFactor;
566                 VK_BLEND_OP_ADD,                                                                                        // VkBlendOp                            colorBlendOp;
567                 VK_BLEND_FACTOR_ONE,                                                                            // VkBlendFactor                        srcAlphaBlendFactor;
568                 VK_BLEND_FACTOR_ZERO,                                                                           // VkBlendFactor                        dstAlphaBlendFactor;
569                 VK_BLEND_OP_ADD,                                                                                        // VkBlendOp                            alphaBlendOp;
570                 VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT |           // VkColorComponentFlags        colorWriteMask;
571                         VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT
572         };
573
574         return colorBlendState;
575 }
576
577 deUint32 getUniqueColorsCount (const tcu::ConstPixelBufferAccess& image)
578 {
579         DE_ASSERT(image.getFormat().getPixelSize() == 4);
580
581         std::map<deUint32, deUint32>    histogram; // map<pixel value, number of occurrences>
582         const deUint32                                  pixelCount      = image.getWidth() * image.getHeight() * image.getDepth();
583
584         for (deUint32 pixelNdx = 0; pixelNdx < pixelCount; pixelNdx++)
585         {
586                 const deUint32 pixelValue = *((const deUint32*)image.getDataPtr() + pixelNdx);
587
588                 if (histogram.find(pixelValue) != histogram.end())
589                         histogram[pixelValue]++;
590                 else
591                         histogram[pixelValue] = 1;
592         }
593
594         return (deUint32)histogram.size();
595 }
596
597 VkImageAspectFlags getImageAspectFlags (const VkFormat format)
598 {
599         const tcu::TextureFormat tcuFormat = mapVkFormat(format);
600
601         if      (tcuFormat.order == tcu::TextureFormat::DS)             return VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
602         else if (tcuFormat.order == tcu::TextureFormat::D)              return VK_IMAGE_ASPECT_DEPTH_BIT;
603         else if (tcuFormat.order == tcu::TextureFormat::S)              return VK_IMAGE_ASPECT_STENCIL_BIT;
604
605         DE_ASSERT(false);
606         return 0u;
607 }
608
609 std::vector<Vertex4RGBA> generateVertices (const GeometryType geometryType)
610 {
611         std::vector<Vertex4RGBA> vertices;
612
613         switch (geometryType)
614         {
615                 case GEOMETRY_TYPE_OPAQUE_TRIANGLE:
616                 case GEOMETRY_TYPE_INVISIBLE_TRIANGLE:
617                 {
618                         Vertex4RGBA vertexData[3] =
619                         {
620                                 {
621                                         tcu::Vec4(-0.75f, 0.0f, 0.0f, 1.0f),
622                                         tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f)
623                                 },
624                                 {
625                                         tcu::Vec4(0.75f, 0.125f, 0.0f, 1.0f),
626                                         tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f)
627                                 },
628                                 {
629                                         tcu::Vec4(0.75f, -0.125f, 0.0f, 1.0f),
630                                         tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f)
631                                 }
632                         };
633
634                         if (geometryType == GEOMETRY_TYPE_INVISIBLE_TRIANGLE)
635                         {
636                                 for (int i = 0; i < 3; i++)
637                                         vertexData[i].color = tcu::Vec4();
638                         }
639
640                         vertices = std::vector<Vertex4RGBA>(vertexData, vertexData + 3);
641                         break;
642                 }
643
644                 case GEOMETRY_TYPE_OPAQUE_LINE:
645                 {
646                         const Vertex4RGBA vertexData[2] =
647                         {
648                                 {
649                                         tcu::Vec4(-0.75f, 0.25f, 0.0f, 1.0f),
650                                         tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f)
651                                 },
652                                 {
653                                         tcu::Vec4(0.75f, -0.25f, 0.0f, 1.0f),
654                                         tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f)
655                                 }
656                         };
657
658                         vertices = std::vector<Vertex4RGBA>(vertexData, vertexData + 2);
659                         break;
660                 }
661
662                 case GEOMETRY_TYPE_OPAQUE_POINT:
663                 {
664                         const Vertex4RGBA vertex =
665                         {
666                                 tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f),
667                                 tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f)
668                         };
669
670                         vertices = std::vector<Vertex4RGBA>(1, vertex);
671                         break;
672                 }
673
674                 case GEOMETRY_TYPE_OPAQUE_QUAD:
675                 case GEOMETRY_TYPE_OPAQUE_QUAD_NONZERO_DEPTH:
676                 case GEOMETRY_TYPE_TRANSLUCENT_QUAD:
677                 case GEOMETRY_TYPE_INVISIBLE_QUAD:
678                 case GEOMETRY_TYPE_GRADIENT_QUAD:
679                 {
680                         Vertex4RGBA vertexData[4] =
681                         {
682                                 {
683                                         tcu::Vec4(-1.0f, -1.0f, 0.0f, 1.0f),
684                                         tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f)
685                                 },
686                                 {
687                                         tcu::Vec4(1.0f, -1.0f, 0.0f, 1.0f),
688                                         tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f)
689                                 },
690                                 {
691                                         tcu::Vec4(-1.0f, 1.0f, 0.0f, 1.0f),
692                                         tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f)
693                                 },
694                                 {
695                                         tcu::Vec4(1.0f, 1.0f, 0.0f, 1.0f),
696                                         tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f)
697                                 }
698                         };
699
700                         if (geometryType == GEOMETRY_TYPE_TRANSLUCENT_QUAD)
701                         {
702                                 for (int i = 0; i < 4; i++)
703                                         vertexData[i].color.w() = 0.25f;
704                         }
705                         else if (geometryType == GEOMETRY_TYPE_INVISIBLE_QUAD)
706                         {
707                                 for (int i = 0; i < 4; i++)
708                                         vertexData[i].color.w() = 0.0f;
709                         }
710                         else if (geometryType == GEOMETRY_TYPE_GRADIENT_QUAD)
711                         {
712                                 vertexData[0].color.w() = 0.0f;
713                                 vertexData[2].color.w() = 0.0f;
714                         }
715                         else if (geometryType == GEOMETRY_TYPE_OPAQUE_QUAD_NONZERO_DEPTH)
716                         {
717                                 for (int i = 0; i < 4; i++)
718                                         vertexData[i].position.z() = 0.5f;
719                         }
720
721                         vertices = std::vector<Vertex4RGBA>(vertexData, vertexData + 4);
722                         break;
723                 }
724
725                 default:
726                         DE_ASSERT(false);
727         }
728         return vertices;
729 }
730
731 VkPrimitiveTopology getPrimitiveTopology (const GeometryType geometryType)
732 {
733         switch (geometryType)
734         {
735                 case GEOMETRY_TYPE_OPAQUE_TRIANGLE:
736                 case GEOMETRY_TYPE_INVISIBLE_TRIANGLE:                  return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
737
738                 case GEOMETRY_TYPE_OPAQUE_LINE:                                 return VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
739                 case GEOMETRY_TYPE_OPAQUE_POINT:                                return VK_PRIMITIVE_TOPOLOGY_POINT_LIST;
740
741                 case GEOMETRY_TYPE_OPAQUE_QUAD:
742                 case GEOMETRY_TYPE_OPAQUE_QUAD_NONZERO_DEPTH:
743                 case GEOMETRY_TYPE_TRANSLUCENT_QUAD:
744                 case GEOMETRY_TYPE_INVISIBLE_QUAD:
745                 case GEOMETRY_TYPE_GRADIENT_QUAD:                               return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
746
747                 default:
748                         DE_ASSERT(false);
749                         return VK_PRIMITIVE_TOPOLOGY_LAST;
750         }
751 }
752
753 bool isSupportedDepthStencilFormat (const InstanceInterface& vki, const VkPhysicalDevice physDevice, const VkFormat format)
754 {
755         VkFormatProperties formatProps;
756         vki.getPhysicalDeviceFormatProperties(physDevice, format, &formatProps);
757         return (formatProps.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) != 0;
758 }
759
760 VkFormat findSupportedDepthStencilFormat (Context& context, const bool useDepth, const bool useStencil)
761 {
762         if (useDepth && !useStencil)
763                 return VK_FORMAT_D16_UNORM;             // must be supported
764
765         const InstanceInterface&        vki                     = context.getInstanceInterface();
766         const VkPhysicalDevice          physDevice      = context.getPhysicalDevice();
767
768         // One of these formats must be supported.
769
770         if (isSupportedDepthStencilFormat(vki, physDevice, VK_FORMAT_D24_UNORM_S8_UINT))
771                 return VK_FORMAT_D24_UNORM_S8_UINT;
772
773         if (isSupportedDepthStencilFormat(vki, physDevice, VK_FORMAT_D32_SFLOAT_S8_UINT))
774                 return VK_FORMAT_D32_SFLOAT_S8_UINT;
775
776         return VK_FORMAT_UNDEFINED;
777 }
778
779
780 // MultisampleTest
781
782 MultisampleTest::MultisampleTest (tcu::TestContext&                                                             testContext,
783                                                                   const std::string&                                                    name,
784                                                                   const std::string&                                                    description,
785                                                                   const VkPipelineMultisampleStateCreateInfo&   multisampleStateParams,
786                                                                   const VkPipelineColorBlendAttachmentState&    blendState,
787                                                                   GeometryType                                                                  geometryType)
788         : vkt::TestCase                         (testContext, name, description)
789         , m_multisampleStateParams      (multisampleStateParams)
790         , m_colorBlendState                     (blendState)
791         , m_geometryType                        (geometryType)
792 {
793         if (m_multisampleStateParams.pSampleMask)
794         {
795                 // Copy pSampleMask to avoid dependencies with other classes
796
797                 const deUint32 maskCount = deCeilFloatToInt32(float(m_multisampleStateParams.rasterizationSamples) / 32);
798
799                 for (deUint32 maskNdx = 0; maskNdx < maskCount; maskNdx++)
800                         m_sampleMask.push_back(m_multisampleStateParams.pSampleMask[maskNdx]);
801
802                 m_multisampleStateParams.pSampleMask = m_sampleMask.data();
803         }
804 }
805
806 void MultisampleTest::initPrograms (SourceCollections& programCollection) const
807 {
808         initMultisamplePrograms(programCollection, m_geometryType);
809 }
810
811 TestInstance* MultisampleTest::createInstance (Context& context) const
812 {
813         return createMultisampleTestInstance(context, getPrimitiveTopology(m_geometryType), generateVertices(m_geometryType), m_multisampleStateParams, m_colorBlendState);
814 }
815
816
817 // RasterizationSamplesTest
818
819 RasterizationSamplesTest::RasterizationSamplesTest (tcu::TestContext&           testContext,
820                                                                                                         const std::string&              name,
821                                                                                                         const std::string&              description,
822                                                                                                         VkSampleCountFlagBits   rasterizationSamples,
823                                                                                                         GeometryType                    geometryType,
824                                                                                                         TestModeFlags                   modeFlags)
825         : MultisampleTest       (testContext, name, description, getRasterizationSamplesStateParams(rasterizationSamples), getDefaultColorBlendAttachmentState(), geometryType)
826         , m_modeFlags           (modeFlags)
827 {
828 }
829
830 VkPipelineMultisampleStateCreateInfo RasterizationSamplesTest::getRasterizationSamplesStateParams (VkSampleCountFlagBits rasterizationSamples)
831 {
832         const VkPipelineMultisampleStateCreateInfo multisampleStateParams =
833         {
834                 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,       // VkStructureType                                                      sType;
835                 DE_NULL,                                                                                                        // const void*                                                          pNext;
836                 0u,                                                                                                                     // VkPipelineMultisampleStateCreateFlags        flags;
837                 rasterizationSamples,                                                                           // VkSampleCountFlagBits                                        rasterizationSamples;
838                 false,                                                                                                          // VkBool32                                                                     sampleShadingEnable;
839                 0.0f,                                                                                                           // float                                                                        minSampleShading;
840                 DE_NULL,                                                                                                        // const VkSampleMask*                                          pSampleMask;
841                 false,                                                                                                          // VkBool32                                                                     alphaToCoverageEnable;
842                 false                                                                                                           // VkBool32                                                                     alphaToOneEnable;
843         };
844
845         return multisampleStateParams;
846 }
847
848 TestInstance* RasterizationSamplesTest::createMultisampleTestInstance (Context&                                                                         context,
849                                                                                                                                            VkPrimitiveTopology                                                  topology,
850                                                                                                                                            const std::vector<Vertex4RGBA>&                              vertices,
851                                                                                                                                            const VkPipelineMultisampleStateCreateInfo&  multisampleStateParams,
852                                                                                                                                            const VkPipelineColorBlendAttachmentState&   colorBlendState) const
853 {
854         return new RasterizationSamplesInstance(context, topology, vertices, multisampleStateParams, colorBlendState, m_modeFlags);
855 }
856
857
858 // MinSampleShadingTest
859
860 MinSampleShadingTest::MinSampleShadingTest (tcu::TestContext&           testContext,
861                                                                                         const std::string&              name,
862                                                                                         const std::string&              description,
863                                                                                         VkSampleCountFlagBits   rasterizationSamples,
864                                                                                         float                                   minSampleShading,
865                                                                                         GeometryType                    geometryType)
866         : MultisampleTest       (testContext, name, description, getMinSampleShadingStateParams(rasterizationSamples, minSampleShading), getDefaultColorBlendAttachmentState(), geometryType)
867 {
868 }
869
870 void MinSampleShadingTest::initPrograms (SourceCollections& programCollection) const
871 {
872         initSampleShadingPrograms(programCollection, m_geometryType);
873 }
874
875 TestInstance* MinSampleShadingTest::createMultisampleTestInstance (Context&                                                                             context,
876                                                                                                                                    VkPrimitiveTopology                                                  topology,
877                                                                                                                                    const std::vector<Vertex4RGBA>&                              vertices,
878                                                                                                                                    const VkPipelineMultisampleStateCreateInfo&  multisampleStateParams,
879                                                                                                                                    const VkPipelineColorBlendAttachmentState&   colorBlendState) const
880 {
881         return new MinSampleShadingInstance(context, topology, vertices, multisampleStateParams, colorBlendState);
882 }
883
884 VkPipelineMultisampleStateCreateInfo MinSampleShadingTest::getMinSampleShadingStateParams (VkSampleCountFlagBits rasterizationSamples, float minSampleShading)
885 {
886         const VkPipelineMultisampleStateCreateInfo multisampleStateParams =
887         {
888                 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,       // VkStructureType                                                      sType;
889                 DE_NULL,                                                                                                        // const void*                                                          pNext;
890                 0u,                                                                                                                     // VkPipelineMultisampleStateCreateFlags        flags;
891                 rasterizationSamples,                                                                           // VkSampleCountFlagBits                                        rasterizationSamples;
892                 true,                                                                                                           // VkBool32                                                                     sampleShadingEnable;
893                 minSampleShading,                                                                                       // float                                                                        minSampleShading;
894                 DE_NULL,                                                                                                        // const VkSampleMask*                                          pSampleMask;
895                 false,                                                                                                          //  VkBool32                                                            alphaToCoverageEnable;
896                 false                                                                                                           //  VkBool32                                                            alphaToOneEnable;
897         };
898
899         return multisampleStateParams;
900 }
901
902
903 // SampleMaskTest
904
905 SampleMaskTest::SampleMaskTest (tcu::TestContext&                                       testContext,
906                                                                 const std::string&                                      name,
907                                                                 const std::string&                                      description,
908                                                                 VkSampleCountFlagBits                           rasterizationSamples,
909                                                                 const std::vector<VkSampleMask>&        sampleMask,
910                                                                 GeometryType                                            geometryType)
911         : MultisampleTest       (testContext, name, description, getSampleMaskStateParams(rasterizationSamples, sampleMask), getDefaultColorBlendAttachmentState(), geometryType)
912 {
913 }
914
915 TestInstance* SampleMaskTest::createMultisampleTestInstance (Context&                                                                           context,
916                                                                                                                          VkPrimitiveTopology                                                    topology,
917                                                                                                                          const std::vector<Vertex4RGBA>&                                vertices,
918                                                                                                                          const VkPipelineMultisampleStateCreateInfo&    multisampleStateParams,
919                                                                                                                          const VkPipelineColorBlendAttachmentState&             colorBlendState) const
920 {
921         return new SampleMaskInstance(context, topology,vertices, multisampleStateParams, colorBlendState);
922 }
923
924 VkPipelineMultisampleStateCreateInfo SampleMaskTest::getSampleMaskStateParams (VkSampleCountFlagBits rasterizationSamples, const std::vector<VkSampleMask>& sampleMask)
925 {
926         const VkPipelineMultisampleStateCreateInfo multisampleStateParams =
927         {
928                 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,       // VkStructureType                                                      sType;
929                 DE_NULL,                                                                                                        // const void*                                                          pNext;
930                 0u,                                                                                                                     // VkPipelineMultisampleStateCreateFlags        flags;
931                 rasterizationSamples,                                                                           // VkSampleCountFlagBits                                        rasterizationSamples;
932                 false,                                                                                                          // VkBool32                                                                     sampleShadingEnable;
933                 0.0f,                                                                                                           // float                                                                        minSampleShading;
934                 sampleMask.data(),                                                                                      // const VkSampleMask*                                          pSampleMask;
935                 false,                                                                                                          // VkBool32                                                                     alphaToCoverageEnable;
936                 false                                                                                                           // VkBool32                                                                     alphaToOneEnable;
937         };
938
939         return multisampleStateParams;
940 }
941
942
943 // AlphaToOneTest
944
945 AlphaToOneTest::AlphaToOneTest (tcu::TestContext&               testContext,
946                                                                 const std::string&              name,
947                                                                 const std::string&              description,
948                                                                 VkSampleCountFlagBits   rasterizationSamples)
949         : MultisampleTest       (testContext, name, description, getAlphaToOneStateParams(rasterizationSamples), getAlphaToOneBlendState(), GEOMETRY_TYPE_GRADIENT_QUAD)
950 {
951 }
952
953 TestInstance* AlphaToOneTest::createMultisampleTestInstance (Context&                                                                           context,
954                                                                                                                          VkPrimitiveTopology                                                    topology,
955                                                                                                                          const std::vector<Vertex4RGBA>&                                vertices,
956                                                                                                                          const VkPipelineMultisampleStateCreateInfo&    multisampleStateParams,
957                                                                                                                          const VkPipelineColorBlendAttachmentState&             colorBlendState) const
958 {
959         return new AlphaToOneInstance(context, topology, vertices, multisampleStateParams, colorBlendState);
960 }
961
962 VkPipelineMultisampleStateCreateInfo AlphaToOneTest::getAlphaToOneStateParams (VkSampleCountFlagBits rasterizationSamples)
963 {
964         const VkPipelineMultisampleStateCreateInfo multisampleStateParams =
965         {
966                 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,       // VkStructureType                                                      sType;
967                 DE_NULL,                                                                                                        // const void*                                                          pNext;
968                 0u,                                                                                                                     // VkPipelineMultisampleStateCreateFlags        flags;
969                 rasterizationSamples,                                                                           // VkSampleCountFlagBits                                        rasterizationSamples;
970                 false,                                                                                                          // VkBool32                                                                     sampleShadingEnable;
971                 0.0f,                                                                                                           // float                                                                        minSampleShading;
972                 DE_NULL,                                                                                                        // const VkSampleMask*                                          pSampleMask;
973                 false,                                                                                                          // VkBool32                                                                     alphaToCoverageEnable;
974                 true                                                                                                            // VkBool32                                                                     alphaToOneEnable;
975         };
976
977         return multisampleStateParams;
978 }
979
980 VkPipelineColorBlendAttachmentState AlphaToOneTest::getAlphaToOneBlendState (void)
981 {
982         const VkPipelineColorBlendAttachmentState colorBlendState =
983         {
984                 true,                                                                                                           // VkBool32                                     blendEnable;
985                 VK_BLEND_FACTOR_SRC_ALPHA,                                                                      // VkBlendFactor                        srcColorBlendFactor;
986                 VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,                                            // VkBlendFactor                        dstColorBlendFactor;
987                 VK_BLEND_OP_ADD,                                                                                        // VkBlendOp                            colorBlendOp;
988                 VK_BLEND_FACTOR_SRC_ALPHA,                                                                      // VkBlendFactor                        srcAlphaBlendFactor;
989                 VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,                                            // VkBlendFactor                        dstAlphaBlendFactor;
990                 VK_BLEND_OP_ADD,                                                                                        // VkBlendOp                            alphaBlendOp;
991                 VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT |           // VkColorComponentFlags        colorWriteMask;
992                         VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT
993         };
994
995         return colorBlendState;
996 }
997
998
999 // AlphaToCoverageTest
1000
1001 AlphaToCoverageTest::AlphaToCoverageTest (tcu::TestContext&                     testContext,
1002                                                                                   const std::string&            name,
1003                                                                                   const std::string&            description,
1004                                                                                   VkSampleCountFlagBits         rasterizationSamples,
1005                                                                                   GeometryType                          geometryType)
1006         : MultisampleTest       (testContext, name, description, getAlphaToCoverageStateParams(rasterizationSamples), getDefaultColorBlendAttachmentState(), geometryType)
1007         , m_geometryType        (geometryType)
1008 {
1009 }
1010
1011 TestInstance* AlphaToCoverageTest::createMultisampleTestInstance (Context&                                                                              context,
1012                                                                                                                                   VkPrimitiveTopology                                                   topology,
1013                                                                                                                                   const std::vector<Vertex4RGBA>&                               vertices,
1014                                                                                                                                   const VkPipelineMultisampleStateCreateInfo&   multisampleStateParams,
1015                                                                                                                                   const VkPipelineColorBlendAttachmentState&    colorBlendState) const
1016 {
1017         return new AlphaToCoverageInstance(context, topology, vertices, multisampleStateParams, colorBlendState, m_geometryType);
1018 }
1019
1020 VkPipelineMultisampleStateCreateInfo AlphaToCoverageTest::getAlphaToCoverageStateParams (VkSampleCountFlagBits rasterizationSamples)
1021 {
1022         const VkPipelineMultisampleStateCreateInfo multisampleStateParams =
1023         {
1024                 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,       // VkStructureType                                                      sType;
1025                 DE_NULL,                                                                                                        // const void*                                                          pNext;
1026                 0u,                                                                                                                     // VkPipelineMultisampleStateCreateFlags        flags;
1027                 rasterizationSamples,                                                                           // VkSampleCountFlagBits                                        rasterizationSamples;
1028                 false,                                                                                                          // VkBool32                                                                     sampleShadingEnable;
1029                 0.0f,                                                                                                           // float                                                                        minSampleShading;
1030                 DE_NULL,                                                                                                        // const VkSampleMask*                                          pSampleMask;
1031                 true,                                                                                                           // VkBool32                                                                     alphaToCoverageEnable;
1032                 false                                                                                                           // VkBool32                                                                     alphaToOneEnable;
1033         };
1034
1035         return multisampleStateParams;
1036 }
1037
1038 // RasterizationSamplesInstance
1039
1040 RasterizationSamplesInstance::RasterizationSamplesInstance (Context&                                                                            context,
1041                                                                                                                         VkPrimitiveTopology                                                             topology,
1042                                                                                                                         const std::vector<Vertex4RGBA>&                                 vertices,
1043                                                                                                                         const VkPipelineMultisampleStateCreateInfo&             multisampleStateParams,
1044                                                                                                                         const VkPipelineColorBlendAttachmentState&              blendState,
1045                                                                                                                         const TestModeFlags                                                             modeFlags)
1046         : vkt::TestInstance             (context)
1047         , m_colorFormat                 (VK_FORMAT_R8G8B8A8_UNORM)
1048         , m_renderSize                  (32, 32)
1049         , m_primitiveTopology   (topology)
1050         , m_vertices                    (vertices)
1051         , m_fullQuadVertices    (generateVertices(GEOMETRY_TYPE_OPAQUE_QUAD_NONZERO_DEPTH))
1052         , m_modeFlags                   (modeFlags)
1053 {
1054         if (m_modeFlags != 0)
1055         {
1056                 const bool              useDepth                        = (m_modeFlags & TEST_MODE_DEPTH_BIT) != 0;
1057                 const bool              useStencil                      = (m_modeFlags & TEST_MODE_STENCIL_BIT) != 0;
1058                 const VkFormat  depthStencilFormat      = findSupportedDepthStencilFormat(context, useDepth, useStencil);
1059
1060                 if (depthStencilFormat == VK_FORMAT_UNDEFINED)
1061                         TCU_THROW(NotSupportedError, "Required depth/stencil format is not supported");
1062
1063                 const VkPrimitiveTopology               pTopology[2] = { m_primitiveTopology, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP };
1064                 const std::vector<Vertex4RGBA>  pVertices[2] = { m_vertices, m_fullQuadVertices };
1065
1066                 m_multisampleRenderer = de::MovePtr<MultisampleRenderer>(
1067                         new MultisampleRenderer(
1068                                 context, m_colorFormat, depthStencilFormat, m_renderSize, useDepth, useStencil, 2u, pTopology, pVertices, multisampleStateParams, blendState, RENDER_TYPE_RESOLVE));
1069         }
1070         else
1071         {
1072                 m_multisampleRenderer = de::MovePtr<MultisampleRenderer>(
1073                         new MultisampleRenderer(context, m_colorFormat, m_renderSize, topology, vertices, multisampleStateParams, blendState, RENDER_TYPE_RESOLVE));
1074         }
1075 }
1076
1077 tcu::TestStatus RasterizationSamplesInstance::iterate (void)
1078 {
1079         de::MovePtr<tcu::TextureLevel> level(m_multisampleRenderer->render());
1080         return verifyImage(level->getAccess());
1081 }
1082
1083 tcu::TestStatus RasterizationSamplesInstance::verifyImage (const tcu::ConstPixelBufferAccess& result)
1084 {
1085         // Verify range of unique pixels
1086         {
1087                 const deUint32  numUniqueColors = getUniqueColorsCount(result);
1088                 const deUint32  minUniqueColors = 3;
1089
1090                 tcu::TestLog& log = m_context.getTestContext().getLog();
1091
1092                 log << tcu::TestLog::Message
1093                         << "\nMin. unique colors expected: " << minUniqueColors << "\n"
1094                         << "Unique colors found: " << numUniqueColors << "\n"
1095                         << tcu::TestLog::EndMessage;
1096
1097                 if (numUniqueColors < minUniqueColors)
1098                         return tcu::TestStatus::fail("Unique colors out of expected bounds");
1099         }
1100
1101         // Verify shape of the rendered primitive (fuzzy-compare)
1102         {
1103                 const tcu::TextureFormat        tcuColorFormat  = mapVkFormat(m_colorFormat);
1104                 const tcu::TextureFormat        tcuDepthFormat  = tcu::TextureFormat();
1105                 const ColorVertexShader         vertexShader;
1106                 const ColorFragmentShader       fragmentShader  (tcuColorFormat, tcuDepthFormat);
1107                 const rr::Program                       program                 (&vertexShader, &fragmentShader);
1108                 ReferenceRenderer                       refRenderer             (m_renderSize.x(), m_renderSize.y(), 1, tcuColorFormat, tcuDepthFormat, &program);
1109                 rr::RenderState                         renderState             (refRenderer.getViewportState());
1110
1111                 if (m_primitiveTopology == VK_PRIMITIVE_TOPOLOGY_POINT_LIST)
1112                 {
1113                         VkPhysicalDeviceProperties deviceProperties;
1114
1115                         m_context.getInstanceInterface().getPhysicalDeviceProperties(m_context.getPhysicalDevice(), &deviceProperties);
1116
1117                         // gl_PointSize is clamped to pointSizeRange
1118                         renderState.point.pointSize = deFloatMin(3.0f, deviceProperties.limits.pointSizeRange[1]);
1119                 }
1120
1121                 if (m_modeFlags == 0)
1122                 {
1123                         refRenderer.colorClear(tcu::Vec4(0.0f));
1124                         refRenderer.draw(renderState, mapVkPrimitiveTopology(m_primitiveTopology), m_vertices);
1125                 }
1126                 else
1127                 {
1128                         // For depth/stencil case the primitive is invisible and the surroundings are filled red.
1129                         refRenderer.colorClear(tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f));
1130                         refRenderer.draw(renderState, mapVkPrimitiveTopology(m_primitiveTopology), m_vertices);
1131                 }
1132
1133                 if (!tcu::fuzzyCompare(m_context.getTestContext().getLog(), "FuzzyImageCompare", "Image comparison", refRenderer.getAccess(), result, 0.05f, tcu::COMPARE_LOG_RESULT))
1134                         return tcu::TestStatus::fail("Primitive has unexpected shape");
1135         }
1136
1137         return tcu::TestStatus::pass("Primitive rendered, unique colors within expected bounds");
1138 }
1139
1140
1141 // MinSampleShadingInstance
1142
1143 MinSampleShadingInstance::MinSampleShadingInstance (Context&                                                                    context,
1144                                                                                                         VkPrimitiveTopology                                                     topology,
1145                                                                                                         const std::vector<Vertex4RGBA>&                         vertices,
1146                                                                                                         const VkPipelineMultisampleStateCreateInfo&     multisampleStateParams,
1147                                                                                                         const VkPipelineColorBlendAttachmentState&      colorBlendState)
1148         : vkt::TestInstance                     (context)
1149         , m_colorFormat                         (VK_FORMAT_R8G8B8A8_UNORM)
1150         , m_renderSize                          (32, 32)
1151         , m_primitiveTopology           (topology)
1152         , m_vertices                            (vertices)
1153         , m_multisampleStateParams      (multisampleStateParams)
1154         , m_colorBlendState                     (colorBlendState)
1155 {
1156         VkPhysicalDeviceFeatures deviceFeatures;
1157
1158         m_context.getInstanceInterface().getPhysicalDeviceFeatures(m_context.getPhysicalDevice(), &deviceFeatures);
1159
1160         if (!deviceFeatures.sampleRateShading)
1161                 throw tcu::NotSupportedError("Sample shading is not supported");
1162 }
1163
1164 tcu::TestStatus MinSampleShadingInstance::iterate (void)
1165 {
1166         de::MovePtr<tcu::TextureLevel>  noSampleshadingImage;
1167         std::vector<tcu::TextureLevel>  sampleShadedImages;
1168
1169         // Render and resolve without sample shading
1170         {
1171                 VkPipelineMultisampleStateCreateInfo multisampleStateParms = m_multisampleStateParams;
1172                 multisampleStateParms.sampleShadingEnable       = VK_FALSE;
1173                 multisampleStateParms.minSampleShading          = 0.0;
1174
1175                 MultisampleRenderer renderer (m_context, m_colorFormat, m_renderSize, m_primitiveTopology, m_vertices, multisampleStateParms, m_colorBlendState, RENDER_TYPE_RESOLVE);
1176                 noSampleshadingImage  = renderer.render();
1177         }
1178
1179         // Render with test minSampleShading and collect per-sample images
1180         {
1181                 MultisampleRenderer renderer (m_context, m_colorFormat, m_renderSize, m_primitiveTopology, m_vertices, m_multisampleStateParams, m_colorBlendState, RENDER_TYPE_COPY_SAMPLES);
1182                 renderer.render();
1183
1184                 sampleShadedImages.resize(m_multisampleStateParams.rasterizationSamples);
1185                 for (deUint32 sampleId = 0; sampleId < sampleShadedImages.size(); sampleId++)
1186                 {
1187                         sampleShadedImages[sampleId] = *renderer.getSingleSampledImage(sampleId);
1188                 }
1189         }
1190
1191         // Log images
1192         {
1193                 tcu::TestLog& testLog   = m_context.getTestContext().getLog();
1194
1195                 testLog << tcu::TestLog::ImageSet("Images", "Images")
1196                                 << tcu::TestLog::Image("noSampleshadingImage", "Image rendered without sample shading", noSampleshadingImage->getAccess());
1197
1198                 for (deUint32 sampleId = 0; sampleId < sampleShadedImages.size(); sampleId++)
1199                 {
1200                         testLog << tcu::TestLog::Image("sampleShadedImage", "One sample of sample shaded image", sampleShadedImages[sampleId].getAccess());
1201                 }
1202                 testLog << tcu::TestLog::EndImageSet;
1203         }
1204
1205         return verifySampleShadedImage(sampleShadedImages, noSampleshadingImage->getAccess());
1206 }
1207
1208 tcu::TestStatus MinSampleShadingInstance::verifySampleShadedImage (const std::vector<tcu::TextureLevel>& sampleShadedImages, const tcu::ConstPixelBufferAccess& noSampleshadingImage)
1209 {
1210         const deUint32  pixelCount      = noSampleshadingImage.getWidth() * noSampleshadingImage.getHeight() * noSampleshadingImage.getDepth();
1211
1212         bool anyPixelCovered            = false;
1213
1214         for (deUint32 pixelNdx = 0; pixelNdx < pixelCount; pixelNdx++)
1215         {
1216                 const deUint32 noSampleShadingValue = *((const deUint32*)noSampleshadingImage.getDataPtr() + pixelNdx);
1217
1218                 if (noSampleShadingValue == 0)
1219                 {
1220                         // non-covered pixel, continue
1221                         continue;
1222                 }
1223                 else
1224                 {
1225                         anyPixelCovered = true;
1226                 }
1227
1228                 int numNotCoveredSamples = 0;
1229
1230                 std::map<deUint32, deUint32>    histogram; // map<pixel value, number of occurrences>
1231
1232                 // Collect histogram of occurrences or each pixel across all samples
1233                 for (size_t i = 0; i < sampleShadedImages.size(); ++i)
1234                 {
1235                         const deUint32 sampleShadedValue = *((const deUint32*)sampleShadedImages[i].getAccess().getDataPtr() + pixelNdx);
1236
1237                         if (sampleShadedValue == 0)
1238                         {
1239                                 numNotCoveredSamples++;
1240                                 continue;
1241                         }
1242
1243                         if (histogram.find(sampleShadedValue) != histogram.end())
1244                                 histogram[sampleShadedValue]++;
1245                         else
1246                                 histogram[sampleShadedValue] = 1;
1247                 }
1248
1249                 if (numNotCoveredSamples == static_cast<int>(sampleShadedImages.size()))
1250                 {
1251                         return tcu::TestStatus::fail("Got uncovered pixel, where covered samples were expected");
1252                 }
1253
1254                 const int uniqueColorsCount                             = (int)histogram.size();
1255                 const int expectedUniqueSamplesCount    = static_cast<int>(m_multisampleStateParams.minSampleShading * static_cast<float>(sampleShadedImages.size()) + 0.5f);
1256
1257                 if (uniqueColorsCount + numNotCoveredSamples < expectedUniqueSamplesCount)
1258                 {
1259                         return tcu::TestStatus::fail("Got less unique colors than requested through minSampleShading");
1260                 }
1261         }
1262
1263         if (!anyPixelCovered)
1264         {
1265                 return tcu::TestStatus::fail("Did not get any covered pixel, cannot test minSampleShading");
1266         }
1267
1268         return tcu::TestStatus::pass("Got proper count of unique colors");
1269 }
1270
1271 SampleMaskInstance::SampleMaskInstance (Context&                                                                                context,
1272                                                                                 VkPrimitiveTopology                                                             topology,
1273                                                                                 const std::vector<Vertex4RGBA>&                                 vertices,
1274                                                                                 const VkPipelineMultisampleStateCreateInfo&             multisampleStateParams,
1275                                                                                 const VkPipelineColorBlendAttachmentState&              blendState)
1276         : vkt::TestInstance                     (context)
1277         , m_colorFormat                         (VK_FORMAT_R8G8B8A8_UNORM)
1278         , m_renderSize                          (32, 32)
1279         , m_primitiveTopology           (topology)
1280         , m_vertices                            (vertices)
1281         , m_multisampleStateParams      (multisampleStateParams)
1282         , m_colorBlendState                     (blendState)
1283 {
1284 }
1285
1286 tcu::TestStatus SampleMaskInstance::iterate (void)
1287 {
1288         de::MovePtr<tcu::TextureLevel>                          testSampleMaskImage;
1289         de::MovePtr<tcu::TextureLevel>                          minSampleMaskImage;
1290         de::MovePtr<tcu::TextureLevel>                          maxSampleMaskImage;
1291
1292         // Render with test flags
1293         {
1294                 MultisampleRenderer renderer (m_context, m_colorFormat, m_renderSize, m_primitiveTopology, m_vertices, m_multisampleStateParams, m_colorBlendState, RENDER_TYPE_RESOLVE);
1295                 testSampleMaskImage = renderer.render();
1296         }
1297
1298         // Render with all flags off
1299         {
1300                 VkPipelineMultisampleStateCreateInfo    multisampleParams       = m_multisampleStateParams;
1301                 const std::vector<VkSampleMask>                 sampleMask                      (multisampleParams.rasterizationSamples / 32, (VkSampleMask)0);
1302
1303                 multisampleParams.pSampleMask = sampleMask.data();
1304
1305                 MultisampleRenderer renderer (m_context, m_colorFormat, m_renderSize, m_primitiveTopology, m_vertices, multisampleParams, m_colorBlendState, RENDER_TYPE_RESOLVE);
1306                 minSampleMaskImage = renderer.render();
1307         }
1308
1309         // Render with all flags on
1310         {
1311                 VkPipelineMultisampleStateCreateInfo    multisampleParams       = m_multisampleStateParams;
1312                 const std::vector<VkSampleMask>                 sampleMask                      (multisampleParams.rasterizationSamples / 32, ~((VkSampleMask)0));
1313
1314                 multisampleParams.pSampleMask = sampleMask.data();
1315
1316                 MultisampleRenderer renderer (m_context, m_colorFormat, m_renderSize, m_primitiveTopology, m_vertices, multisampleParams, m_colorBlendState, RENDER_TYPE_RESOLVE);
1317                 maxSampleMaskImage = renderer.render();
1318         }
1319
1320         return verifyImage(testSampleMaskImage->getAccess(), minSampleMaskImage->getAccess(), maxSampleMaskImage->getAccess());
1321 }
1322
1323 tcu::TestStatus SampleMaskInstance::verifyImage (const tcu::ConstPixelBufferAccess& testSampleMaskImage,
1324                                                                                                  const tcu::ConstPixelBufferAccess& minSampleMaskImage,
1325                                                                                                  const tcu::ConstPixelBufferAccess& maxSampleMaskImage)
1326 {
1327         const deUint32  testColorCount  = getUniqueColorsCount(testSampleMaskImage);
1328         const deUint32  minColorCount   = getUniqueColorsCount(minSampleMaskImage);
1329         const deUint32  maxColorCount   = getUniqueColorsCount(maxSampleMaskImage);
1330
1331         tcu::TestLog& log = m_context.getTestContext().getLog();
1332
1333         log << tcu::TestLog::Message
1334                 << "\nColors found: " << testColorCount << "\n"
1335                 << "Min. colors expected: " << minColorCount << "\n"
1336                 << "Max. colors expected: " << maxColorCount << "\n"
1337                 << tcu::TestLog::EndMessage;
1338
1339         if (minColorCount > testColorCount || testColorCount > maxColorCount)
1340                 return tcu::TestStatus::fail("Unique colors out of expected bounds");
1341         else
1342                 return tcu::TestStatus::pass("Unique colors within expected bounds");
1343 }
1344
1345 tcu::TestStatus testRasterSamplesConsistency (Context& context, GeometryType geometryType)
1346 {
1347         // Use triangle only.
1348         DE_UNREF(geometryType);
1349
1350         const VkSampleCountFlagBits samples[] =
1351         {
1352                 VK_SAMPLE_COUNT_1_BIT,
1353                 VK_SAMPLE_COUNT_2_BIT,
1354                 VK_SAMPLE_COUNT_4_BIT,
1355                 VK_SAMPLE_COUNT_8_BIT,
1356                 VK_SAMPLE_COUNT_16_BIT,
1357                 VK_SAMPLE_COUNT_32_BIT,
1358                 VK_SAMPLE_COUNT_64_BIT
1359         };
1360
1361         const Vertex4RGBA vertexData[3] =
1362         {
1363                 {
1364                         tcu::Vec4(-0.75f, 0.0f, 0.0f, 1.0f),
1365                         tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f)
1366                 },
1367                 {
1368                         tcu::Vec4(0.75f, 0.125f, 0.0f, 1.0f),
1369                         tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f)
1370                 },
1371                 {
1372                         tcu::Vec4(0.75f, -0.125f, 0.0f, 1.0f),
1373                         tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f)
1374                 }
1375         };
1376
1377         const std::vector<Vertex4RGBA>  vertices                        (vertexData, vertexData + 3);
1378         deUint32                                                prevUniqueColors        = 2;
1379         int                                                             renderCount                     = 0;
1380
1381         // Do not render with 1 sample (start with samplesNdx = 1).
1382         for (int samplesNdx = 1; samplesNdx < DE_LENGTH_OF_ARRAY(samples); samplesNdx++)
1383         {
1384                 if (!isSupportedSampleCount(context.getInstanceInterface(), context.getPhysicalDevice(), samples[samplesNdx]))
1385                         continue;
1386
1387                 const VkPipelineMultisampleStateCreateInfo multisampleStateParams =
1388                 {
1389                         VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,       // VkStructureType                                                      sType;
1390                         DE_NULL,                                                                                                        // const void*                                                          pNext;
1391                         0u,                                                                                                                     // VkPipelineMultisampleStateCreateFlags        flags;
1392                         samples[samplesNdx],                                                                            // VkSampleCountFlagBits                                        rasterizationSamples;
1393                         false,                                                                                                          // VkBool32                                                                     sampleShadingEnable;
1394                         0.0f,                                                                                                           // float                                                                        minSampleShading;
1395                         DE_NULL,                                                                                                        // const VkSampleMask*                                          pSampleMask;
1396                         false,                                                                                                          // VkBool32                                                                     alphaToCoverageEnable;
1397                         false                                                                                                           // VkBool32                                                                     alphaToOneEnable;
1398                 };
1399
1400                 MultisampleRenderer                             renderer                (context, VK_FORMAT_R8G8B8A8_UNORM, tcu::IVec2(32, 32), VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, vertices, multisampleStateParams, getDefaultColorBlendAttachmentState(), RENDER_TYPE_RESOLVE);
1401                 de::MovePtr<tcu::TextureLevel>  result                  = renderer.render();
1402                 const deUint32                                  uniqueColors    = getUniqueColorsCount(result->getAccess());
1403
1404                 renderCount++;
1405
1406                 if (prevUniqueColors > uniqueColors)
1407                 {
1408                         std::ostringstream message;
1409
1410                         message << "More unique colors generated with " << samples[samplesNdx - 1] << " than with " << samples[samplesNdx];
1411                         return tcu::TestStatus::fail(message.str());
1412                 }
1413
1414                 prevUniqueColors = uniqueColors;
1415         }
1416
1417         if (renderCount == 0)
1418                 throw tcu::NotSupportedError("Multisampling is unsupported");
1419
1420         return tcu::TestStatus::pass("Number of unique colors increases as the sample count increases");
1421 }
1422
1423
1424 // AlphaToOneInstance
1425
1426 AlphaToOneInstance::AlphaToOneInstance (Context&                                                                        context,
1427                                                                                 VkPrimitiveTopology                                                     topology,
1428                                                                                 const std::vector<Vertex4RGBA>&                         vertices,
1429                                                                                 const VkPipelineMultisampleStateCreateInfo&     multisampleStateParams,
1430                                                                                 const VkPipelineColorBlendAttachmentState&      blendState)
1431         : vkt::TestInstance                     (context)
1432         , m_colorFormat                         (VK_FORMAT_R8G8B8A8_UNORM)
1433         , m_renderSize                          (32, 32)
1434         , m_primitiveTopology           (topology)
1435         , m_vertices                            (vertices)
1436         , m_multisampleStateParams      (multisampleStateParams)
1437         , m_colorBlendState                     (blendState)
1438 {
1439         VkPhysicalDeviceFeatures deviceFeatures;
1440
1441         context.getInstanceInterface().getPhysicalDeviceFeatures(context.getPhysicalDevice(), &deviceFeatures);
1442
1443         if (!deviceFeatures.alphaToOne)
1444                 throw tcu::NotSupportedError("Alpha-to-one is not supported");
1445 }
1446
1447 tcu::TestStatus AlphaToOneInstance::iterate     (void)
1448 {
1449         DE_ASSERT(m_multisampleStateParams.alphaToOneEnable);
1450         DE_ASSERT(m_colorBlendState.blendEnable);
1451
1452         de::MovePtr<tcu::TextureLevel>  alphaOneImage;
1453         de::MovePtr<tcu::TextureLevel>  noAlphaOneImage;
1454
1455         // Render with blend enabled and alpha to one on
1456         {
1457                 MultisampleRenderer renderer (m_context, m_colorFormat, m_renderSize, m_primitiveTopology, m_vertices, m_multisampleStateParams, m_colorBlendState, RENDER_TYPE_RESOLVE);
1458                 alphaOneImage = renderer.render();
1459         }
1460
1461         // Render with blend enabled and alpha to one off
1462         {
1463                 VkPipelineMultisampleStateCreateInfo    multisampleParams       = m_multisampleStateParams;
1464                 multisampleParams.alphaToOneEnable = false;
1465
1466                 MultisampleRenderer renderer (m_context, m_colorFormat, m_renderSize, m_primitiveTopology, m_vertices, multisampleParams, m_colorBlendState, RENDER_TYPE_RESOLVE);
1467                 noAlphaOneImage = renderer.render();
1468         }
1469
1470         return verifyImage(alphaOneImage->getAccess(), noAlphaOneImage->getAccess());
1471 }
1472
1473 tcu::TestStatus AlphaToOneInstance::verifyImage (const tcu::ConstPixelBufferAccess&     alphaOneImage,
1474                                                                                                  const tcu::ConstPixelBufferAccess&     noAlphaOneImage)
1475 {
1476         for (int y = 0; y < m_renderSize.y(); y++)
1477         {
1478                 for (int x = 0; x < m_renderSize.x(); x++)
1479                 {
1480                         if (!tcu::boolAll(tcu::greaterThanEqual(alphaOneImage.getPixel(x, y), noAlphaOneImage.getPixel(x, y))))
1481                         {
1482                                 std::ostringstream message;
1483                                 message << "Unsatisfied condition: " << alphaOneImage.getPixel(x, y) << " >= " << noAlphaOneImage.getPixel(x, y);
1484                                 return tcu::TestStatus::fail(message.str());
1485                         }
1486                 }
1487         }
1488
1489         return tcu::TestStatus::pass("Image rendered with alpha-to-one contains pixels of image rendered with no alpha-to-one");
1490 }
1491
1492
1493 // AlphaToCoverageInstance
1494
1495 AlphaToCoverageInstance::AlphaToCoverageInstance (Context&                                                                              context,
1496                                                                                                   VkPrimitiveTopology                                                   topology,
1497                                                                                                   const std::vector<Vertex4RGBA>&                               vertices,
1498                                                                                                   const VkPipelineMultisampleStateCreateInfo&   multisampleStateParams,
1499                                                                                                   const VkPipelineColorBlendAttachmentState&    blendState,
1500                                                                                                   GeometryType                                                                  geometryType)
1501         : vkt::TestInstance                     (context)
1502         , m_colorFormat                         (VK_FORMAT_R8G8B8A8_UNORM)
1503         , m_renderSize                          (32, 32)
1504         , m_primitiveTopology           (topology)
1505         , m_vertices                            (vertices)
1506         , m_multisampleStateParams      (multisampleStateParams)
1507         , m_colorBlendState                     (blendState)
1508         , m_geometryType                        (geometryType)
1509 {
1510 }
1511
1512 tcu::TestStatus AlphaToCoverageInstance::iterate (void)
1513 {
1514         DE_ASSERT(m_multisampleStateParams.alphaToCoverageEnable);
1515
1516         de::MovePtr<tcu::TextureLevel>  result;
1517         MultisampleRenderer                             renderer        (m_context, m_colorFormat, m_renderSize, m_primitiveTopology, m_vertices, m_multisampleStateParams, m_colorBlendState, RENDER_TYPE_RESOLVE);
1518
1519         result = renderer.render();
1520
1521         return verifyImage(result->getAccess());
1522 }
1523
1524 tcu::TestStatus AlphaToCoverageInstance::verifyImage (const tcu::ConstPixelBufferAccess&        result)
1525 {
1526         float maxColorValue;
1527
1528         switch (m_geometryType)
1529         {
1530                 case GEOMETRY_TYPE_OPAQUE_QUAD:
1531                         maxColorValue = 1.01f;
1532                         break;
1533
1534                 case GEOMETRY_TYPE_TRANSLUCENT_QUAD:
1535                         maxColorValue = 0.52f;
1536                         break;
1537
1538                 case GEOMETRY_TYPE_INVISIBLE_QUAD:
1539                         maxColorValue = 0.01f;
1540                         break;
1541
1542                 default:
1543                         maxColorValue = 0.0f;
1544                         DE_ASSERT(false);
1545         }
1546
1547         for (int y = 0; y < m_renderSize.y(); y++)
1548         {
1549                 for (int x = 0; x < m_renderSize.x(); x++)
1550                 {
1551                         if (result.getPixel(x, y).x() > maxColorValue)
1552                         {
1553                                 std::ostringstream message;
1554                                 message << "Pixel is not below the threshold value (" << result.getPixel(x, y).x() << " > " << maxColorValue << ")";
1555                                 return tcu::TestStatus::fail(message.str());
1556                         }
1557                 }
1558         }
1559
1560         return tcu::TestStatus::pass("Image matches reference value");
1561 }
1562
1563
1564 // MultisampleRenderer
1565
1566 MultisampleRenderer::MultisampleRenderer (Context&                                                                              context,
1567                                                                                   const VkFormat                                                                colorFormat,
1568                                                                                   const tcu::IVec2&                                                             renderSize,
1569                                                                                   const VkPrimitiveTopology                                             topology,
1570                                                                                   const std::vector<Vertex4RGBA>&                               vertices,
1571                                                                                   const VkPipelineMultisampleStateCreateInfo&   multisampleStateParams,
1572                                                                                   const VkPipelineColorBlendAttachmentState&    blendState,
1573                                                                                   const RenderType                                                              renderType)
1574         : m_context                                     (context)
1575         , m_colorFormat                         (colorFormat)
1576         , m_depthStencilFormat          (VK_FORMAT_UNDEFINED)
1577         , m_renderSize                          (renderSize)
1578         , m_useDepth                            (false)
1579         , m_useStencil                          (false)
1580         , m_multisampleStateParams      (multisampleStateParams)
1581         , m_colorBlendState                     (blendState)
1582         , m_renderType                          (renderType)
1583 {
1584         initialize(context, 1u, &topology, &vertices);
1585 }
1586
1587 MultisampleRenderer::MultisampleRenderer (Context&                                                                              context,
1588                                                                                   const VkFormat                                                                colorFormat,
1589                                                                                   const VkFormat                                                                depthStencilFormat,
1590                                                                                   const tcu::IVec2&                                                             renderSize,
1591                                                                                   const bool                                                                    useDepth,
1592                                                                                   const bool                                                                    useStencil,
1593                                                                                   const deUint32                                                                numTopologies,
1594                                                                                   const VkPrimitiveTopology*                                    pTopology,
1595                                                                                   const std::vector<Vertex4RGBA>*                               pVertices,
1596                                                                                   const VkPipelineMultisampleStateCreateInfo&   multisampleStateParams,
1597                                                                                   const VkPipelineColorBlendAttachmentState&    blendState,
1598                                                                                   const RenderType                                                              renderType)
1599         : m_context                                     (context)
1600         , m_colorFormat                         (colorFormat)
1601         , m_depthStencilFormat          (depthStencilFormat)
1602         , m_renderSize                          (renderSize)
1603         , m_useDepth                            (useDepth)
1604         , m_useStencil                          (useStencil)
1605         , m_multisampleStateParams      (multisampleStateParams)
1606         , m_colorBlendState                     (blendState)
1607         , m_renderType                          (renderType)
1608 {
1609         initialize(context, numTopologies, pTopology, pVertices);
1610 }
1611
1612 void MultisampleRenderer::initialize (Context&                                                                  context,
1613                                                                           const deUint32                                                        numTopologies,
1614                                                                           const VkPrimitiveTopology*                            pTopology,
1615                                                                           const std::vector<Vertex4RGBA>*                       pVertices)
1616 {
1617         if (!isSupportedSampleCount(context.getInstanceInterface(), context.getPhysicalDevice(), m_multisampleStateParams.rasterizationSamples))
1618                 throw tcu::NotSupportedError("Unsupported number of rasterization samples");
1619
1620         const DeviceInterface&          vk                                              = context.getDeviceInterface();
1621         const VkDevice                          vkDevice                                = context.getDevice();
1622         const deUint32                          queueFamilyIndex                = context.getUniversalQueueFamilyIndex();
1623         SimpleAllocator                         memAlloc                                (vk, vkDevice, getPhysicalDeviceMemoryProperties(context.getInstanceInterface(), context.getPhysicalDevice()));
1624         const VkComponentMapping        componentMappingRGBA    = { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A };
1625
1626         // Create color image
1627         {
1628
1629                 const VkImageUsageFlags imageUsageFlags = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
1630                         (m_renderType == RENDER_TYPE_COPY_SAMPLES ? VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT : (VkImageUsageFlagBits)0u);
1631
1632                 const VkImageCreateInfo colorImageParams =
1633                 {
1634                         VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,                                                                            // VkStructureType                      sType;
1635                         DE_NULL,                                                                                                                                        // const void*                          pNext;
1636                         0u,                                                                                                                                                     // VkImageCreateFlags           flags;
1637                         VK_IMAGE_TYPE_2D,                                                                                                                       // VkImageType                          imageType;
1638                         m_colorFormat,                                                                                                                          // VkFormat                                     format;
1639                         { (deUint32)m_renderSize.x(), (deUint32)m_renderSize.y(), 1u },                         // VkExtent3D                           extent;
1640                         1u,                                                                                                                                                     // deUint32                                     mipLevels;
1641                         1u,                                                                                                                                                     // deUint32                                     arrayLayers;
1642                         m_multisampleStateParams.rasterizationSamples,                                                          // VkSampleCountFlagBits        samples;
1643                         VK_IMAGE_TILING_OPTIMAL,                                                                                                        // VkImageTiling                        tiling;
1644                         imageUsageFlags,                                                                                                                        // VkImageUsageFlags            usage;
1645                         VK_SHARING_MODE_EXCLUSIVE,                                                                                                      // VkSharingMode                        sharingMode;
1646                         1u,                                                                                                                                                     // deUint32                                     queueFamilyIndexCount;
1647                         &queueFamilyIndex,                                                                                                                      // const deUint32*                      pQueueFamilyIndices;
1648                         VK_IMAGE_LAYOUT_UNDEFINED,                                                                                                      // VkImageLayout                        initialLayout;
1649                 };
1650
1651                 m_colorImage                    = createImage(vk, vkDevice, &colorImageParams);
1652
1653                 // Allocate and bind color image memory
1654                 m_colorImageAlloc               = memAlloc.allocate(getImageMemoryRequirements(vk, vkDevice, *m_colorImage), MemoryRequirement::Any);
1655                 VK_CHECK(vk.bindImageMemory(vkDevice, *m_colorImage, m_colorImageAlloc->getMemory(), m_colorImageAlloc->getOffset()));
1656         }
1657
1658         // Create resolve image
1659         if (m_renderType == RENDER_TYPE_RESOLVE)
1660         {
1661                 const VkImageCreateInfo resolveImageParams =
1662                 {
1663                         VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,                                                                                    // VkStructureType                      sType;
1664                         DE_NULL,                                                                                                                                                // const void*                          pNext;
1665                         0u,                                                                                                                                                             // VkImageCreateFlags           flags;
1666                         VK_IMAGE_TYPE_2D,                                                                                                                               // VkImageType                          imageType;
1667                         m_colorFormat,                                                                                                                                  // VkFormat                                     format;
1668                         { (deUint32)m_renderSize.x(), (deUint32)m_renderSize.y(), 1u },                                 // VkExtent3D                           extent;
1669                         1u,                                                                                                                                                             // deUint32                                     mipLevels;
1670                         1u,                                                                                                                                                             // deUint32                                     arrayLayers;
1671                         VK_SAMPLE_COUNT_1_BIT,                                                                                                                  // VkSampleCountFlagBits        samples;
1672                         VK_IMAGE_TILING_OPTIMAL,                                                                                                                // VkImageTiling                        tiling;
1673                         VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT |                 // VkImageUsageFlags            usage;
1674                                 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
1675                         VK_SHARING_MODE_EXCLUSIVE,                                                                                                              // VkSharingMode                        sharingMode;
1676                         1u,                                                                                                                                                             // deUint32                                     queueFamilyIndexCount;
1677                         &queueFamilyIndex,                                                                                                                              // const deUint32*                      pQueueFamilyIndices;
1678                         VK_IMAGE_LAYOUT_UNDEFINED                                                                                                               // VkImageLayout                        initialLayout;
1679                 };
1680
1681                 m_resolveImage = createImage(vk, vkDevice, &resolveImageParams);
1682
1683                 // Allocate and bind resolve image memory
1684                 m_resolveImageAlloc = memAlloc.allocate(getImageMemoryRequirements(vk, vkDevice, *m_resolveImage), MemoryRequirement::Any);
1685                 VK_CHECK(vk.bindImageMemory(vkDevice, *m_resolveImage, m_resolveImageAlloc->getMemory(), m_resolveImageAlloc->getOffset()));
1686
1687                 // Create resolve attachment view
1688                 {
1689                         const VkImageViewCreateInfo resolveAttachmentViewParams =
1690                         {
1691                                 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,               // VkStructureType                      sType;
1692                                 DE_NULL,                                                                                // const void*                          pNext;
1693                                 0u,                                                                                             // VkImageViewCreateFlags       flags;
1694                                 *m_resolveImage,                                                                // VkImage                                      image;
1695                                 VK_IMAGE_VIEW_TYPE_2D,                                                  // VkImageViewType                      viewType;
1696                                 m_colorFormat,                                                                  // VkFormat                                     format;
1697                                 componentMappingRGBA,                                                   // VkComponentMapping           components;
1698                                 { VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, 1u }   // VkImageSubresourceRange      subresourceRange;
1699                         };
1700
1701                         m_resolveAttachmentView = createImageView(vk, vkDevice, &resolveAttachmentViewParams);
1702                 }
1703         }
1704
1705         // Create per-sample output images
1706         if (m_renderType == RENDER_TYPE_COPY_SAMPLES)
1707         {
1708                 const VkImageCreateInfo perSampleImageParams =
1709                 {
1710                         VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,                                                                                    // VkStructureType                      sType;
1711                         DE_NULL,                                                                                                                                                // const void*                          pNext;
1712                         0u,                                                                                                                                                             // VkImageCreateFlags           flags;
1713                         VK_IMAGE_TYPE_2D,                                                                                                                               // VkImageType                          imageType;
1714                         m_colorFormat,                                                                                                                                  // VkFormat                                     format;
1715                         { (deUint32)m_renderSize.x(), (deUint32)m_renderSize.y(), 1u },                                 // VkExtent3D                           extent;
1716                         1u,                                                                                                                                                             // deUint32                                     mipLevels;
1717                         1u,                                                                                                                                                             // deUint32                                     arrayLayers;
1718                         VK_SAMPLE_COUNT_1_BIT,                                                                                                                  // VkSampleCountFlagBits        samples;
1719                         VK_IMAGE_TILING_OPTIMAL,                                                                                                                // VkImageTiling                        tiling;
1720                         VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT |                 // VkImageUsageFlags            usage;
1721                         VK_IMAGE_USAGE_TRANSFER_DST_BIT,
1722                         VK_SHARING_MODE_EXCLUSIVE,                                                                                                              // VkSharingMode                        sharingMode;
1723                         1u,                                                                                                                                                             // deUint32                                     queueFamilyIndexCount;
1724                         &queueFamilyIndex,                                                                                                                              // const deUint32*                      pQueueFamilyIndices;
1725                         VK_IMAGE_LAYOUT_UNDEFINED                                                                                                               // VkImageLayout                        initialLayout;
1726                 };
1727
1728                 m_perSampleImages.resize(static_cast<size_t>(m_multisampleStateParams.rasterizationSamples));
1729
1730                 for (size_t i = 0; i < m_perSampleImages.size(); ++i)
1731                 {
1732                         m_perSampleImages[i]    = de::SharedPtr<PerSampleImage>(new PerSampleImage);
1733                         PerSampleImage& image   = *m_perSampleImages[i];
1734
1735                         image.m_image                   = createImage(vk, vkDevice, &perSampleImageParams);
1736
1737                         // Allocate and bind image memory
1738                         image.m_imageAlloc              = memAlloc.allocate(getImageMemoryRequirements(vk, vkDevice, *image.m_image), MemoryRequirement::Any);
1739                         VK_CHECK(vk.bindImageMemory(vkDevice, *image.m_image, image.m_imageAlloc->getMemory(), image.m_imageAlloc->getOffset()));
1740
1741                         // Create per-sample attachment view
1742                         {
1743                                 const VkImageViewCreateInfo perSampleAttachmentViewParams =
1744                                 {
1745                                         VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,               // VkStructureType                      sType;
1746                                         DE_NULL,                                                                                // const void*                          pNext;
1747                                         0u,                                                                                             // VkImageViewCreateFlags       flags;
1748                                         *image.m_image,                                                                 // VkImage                                      image;
1749                                         VK_IMAGE_VIEW_TYPE_2D,                                                  // VkImageViewType                      viewType;
1750                                         m_colorFormat,                                                                  // VkFormat                                     format;
1751                                         componentMappingRGBA,                                                   // VkComponentMapping           components;
1752                                         { VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, 1u }   // VkImageSubresourceRange      subresourceRange;
1753                                 };
1754
1755                                 image.m_attachmentView = createImageView(vk, vkDevice, &perSampleAttachmentViewParams);
1756                         }
1757                 }
1758         }
1759
1760         // Create a depth/stencil image
1761         if (m_useDepth || m_useStencil)
1762         {
1763                 const VkImageCreateInfo depthStencilImageParams =
1764                 {
1765                         VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,                                                                                    // VkStructureType                      sType;
1766                         DE_NULL,                                                                                                                                                // const void*                          pNext;
1767                         0u,                                                                                                                                                             // VkImageCreateFlags           flags;
1768                         VK_IMAGE_TYPE_2D,                                                                                                                               // VkImageType                          imageType;
1769                         m_depthStencilFormat,                                                                                                                   // VkFormat                                     format;
1770                         { (deUint32)m_renderSize.x(), (deUint32)m_renderSize.y(), 1u },                                 // VkExtent3D                           extent;
1771                         1u,                                                                                                                                                             // deUint32                                     mipLevels;
1772                         1u,                                                                                                                                                             // deUint32                                     arrayLayers;
1773                         m_multisampleStateParams.rasterizationSamples,                                                                  // VkSampleCountFlagBits        samples;
1774                         VK_IMAGE_TILING_OPTIMAL,                                                                                                                // VkImageTiling                        tiling;
1775                         VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,                                                                    // VkImageUsageFlags            usage;
1776                         VK_SHARING_MODE_EXCLUSIVE,                                                                                                              // VkSharingMode                        sharingMode;
1777                         1u,                                                                                                                                                             // deUint32                                     queueFamilyIndexCount;
1778                         &queueFamilyIndex,                                                                                                                              // const deUint32*                      pQueueFamilyIndices;
1779                         VK_IMAGE_LAYOUT_UNDEFINED                                                                                                               // VkImageLayout                        initialLayout;
1780                 };
1781
1782                 m_depthStencilImage = createImage(vk, vkDevice, &depthStencilImageParams);
1783
1784                 // Allocate and bind depth/stencil image memory
1785                 m_depthStencilImageAlloc = memAlloc.allocate(getImageMemoryRequirements(vk, vkDevice, *m_depthStencilImage), MemoryRequirement::Any);
1786                 VK_CHECK(vk.bindImageMemory(vkDevice, *m_depthStencilImage, m_depthStencilImageAlloc->getMemory(), m_depthStencilImageAlloc->getOffset()));
1787         }
1788
1789         // Create color attachment view
1790         {
1791                 const VkImageViewCreateInfo colorAttachmentViewParams =
1792                 {
1793                         VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,               // VkStructureType                      sType;
1794                         DE_NULL,                                                                                // const void*                          pNext;
1795                         0u,                                                                                             // VkImageViewCreateFlags       flags;
1796                         *m_colorImage,                                                                  // VkImage                                      image;
1797                         VK_IMAGE_VIEW_TYPE_2D,                                                  // VkImageViewType                      viewType;
1798                         m_colorFormat,                                                                  // VkFormat                                     format;
1799                         componentMappingRGBA,                                                   // VkComponentMapping           components;
1800                         { VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, 1u }   // VkImageSubresourceRange      subresourceRange;
1801                 };
1802
1803                 m_colorAttachmentView = createImageView(vk, vkDevice, &colorAttachmentViewParams);
1804         }
1805
1806         VkImageAspectFlags      depthStencilAttachmentAspect    = (VkImageAspectFlagBits)0;
1807
1808         // Create depth/stencil attachment view
1809         if (m_useDepth || m_useStencil)
1810         {
1811                 depthStencilAttachmentAspect = getImageAspectFlags(m_depthStencilFormat);
1812
1813                 const VkImageViewCreateInfo depthStencilAttachmentViewParams =
1814                 {
1815                         VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,                       // VkStructureType                      sType;
1816                         DE_NULL,                                                                                        // const void*                          pNext;
1817                         0u,                                                                                                     // VkImageViewCreateFlags       flags;
1818                         *m_depthStencilImage,                                                           // VkImage                                      image;
1819                         VK_IMAGE_VIEW_TYPE_2D,                                                          // VkImageViewType                      viewType;
1820                         m_depthStencilFormat,                                                           // VkFormat                                     format;
1821                         componentMappingRGBA,                                                           // VkComponentMapping           components;
1822                         { depthStencilAttachmentAspect, 0u, 1u, 0u, 1u }        // VkImageSubresourceRange      subresourceRange;
1823                 };
1824
1825                 m_depthStencilAttachmentView = createImageView(vk, vkDevice, &depthStencilAttachmentViewParams);
1826         }
1827
1828         // Create render pass
1829         {
1830                 std::vector<VkAttachmentDescription> attachmentDescriptions;
1831                 {
1832                         const VkAttachmentDescription colorAttachmentDescription =
1833                         {
1834                                 0u,                                                                                                     // VkAttachmentDescriptionFlags         flags;
1835                                 m_colorFormat,                                                                          // VkFormat                                                     format;
1836                                 m_multisampleStateParams.rasterizationSamples,          // VkSampleCountFlagBits                        samples;
1837                                 VK_ATTACHMENT_LOAD_OP_CLEAR,                                            // VkAttachmentLoadOp                           loadOp;
1838                                 VK_ATTACHMENT_STORE_OP_STORE,                                           // VkAttachmentStoreOp                          storeOp;
1839                                 VK_ATTACHMENT_LOAD_OP_DONT_CARE,                                        // VkAttachmentLoadOp                           stencilLoadOp;
1840                                 VK_ATTACHMENT_STORE_OP_DONT_CARE,                                       // VkAttachmentStoreOp                          stencilStoreOp;
1841                                 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,                       // VkImageLayout                                        initialLayout;
1842                                 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL                        // VkImageLayout                                        finalLayout;
1843                         };
1844                         attachmentDescriptions.push_back(colorAttachmentDescription);
1845                 }
1846
1847                 deUint32 resolveAttachmentIndex = VK_ATTACHMENT_UNUSED;
1848
1849                 if (m_renderType == RENDER_TYPE_RESOLVE)
1850                 {
1851                         resolveAttachmentIndex = static_cast<deUint32>(attachmentDescriptions.size());
1852
1853                         const VkAttachmentDescription resolveAttachmentDescription =
1854                         {
1855                                 0u,                                                                                                     // VkAttachmentDescriptionFlags         flags;
1856                                 m_colorFormat,                                                                          // VkFormat                                                     format;
1857                                 VK_SAMPLE_COUNT_1_BIT,                                                          // VkSampleCountFlagBits                        samples;
1858                                 VK_ATTACHMENT_LOAD_OP_CLEAR,                                            // VkAttachmentLoadOp                           loadOp;
1859                                 VK_ATTACHMENT_STORE_OP_STORE,                                           // VkAttachmentStoreOp                          storeOp;
1860                                 VK_ATTACHMENT_LOAD_OP_DONT_CARE,                                        // VkAttachmentLoadOp                           stencilLoadOp;
1861                                 VK_ATTACHMENT_STORE_OP_DONT_CARE,                                       // VkAttachmentStoreOp                          stencilStoreOp;
1862                                 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,                       // VkImageLayout                                        initialLayout;
1863                                 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL                        // VkImageLayout                                        finalLayout;
1864                         };
1865                         attachmentDescriptions.push_back(resolveAttachmentDescription);
1866                 }
1867
1868                 deUint32 perSampleAttachmentIndex = VK_ATTACHMENT_UNUSED;
1869
1870                 if (m_renderType == RENDER_TYPE_COPY_SAMPLES)
1871                 {
1872                         perSampleAttachmentIndex = static_cast<deUint32>(attachmentDescriptions.size());
1873
1874                         const VkAttachmentDescription perSampleAttachmentDescription =
1875                         {
1876                                 0u,                                                                                                     // VkAttachmentDescriptionFlags         flags;
1877                                 m_colorFormat,                                                                          // VkFormat                                                     format;
1878                                 VK_SAMPLE_COUNT_1_BIT,                                                          // VkSampleCountFlagBits                        samples;
1879                                 VK_ATTACHMENT_LOAD_OP_CLEAR,                                            // VkAttachmentLoadOp                           loadOp;
1880                                 VK_ATTACHMENT_STORE_OP_STORE,                                           // VkAttachmentStoreOp                          storeOp;
1881                                 VK_ATTACHMENT_LOAD_OP_DONT_CARE,                                        // VkAttachmentLoadOp                           stencilLoadOp;
1882                                 VK_ATTACHMENT_STORE_OP_DONT_CARE,                                       // VkAttachmentStoreOp                          stencilStoreOp;
1883                                 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,                       // VkImageLayout                                        initialLayout;
1884                                 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL                        // VkImageLayout                                        finalLayout;
1885                         };
1886
1887                         for (size_t i = 0; i < m_perSampleImages.size(); ++i)
1888                         {
1889                                 attachmentDescriptions.push_back(perSampleAttachmentDescription);
1890                         }
1891                 }
1892
1893                 deUint32 depthStencilAttachmentIndex = VK_ATTACHMENT_UNUSED;
1894
1895                 if (m_useDepth || m_useStencil)
1896                 {
1897                         depthStencilAttachmentIndex = static_cast<deUint32>(attachmentDescriptions.size());
1898
1899                         const VkAttachmentDescription depthStencilAttachmentDescription =
1900                         {
1901                                 0u,                                                                                                                                                                     // VkAttachmentDescriptionFlags         flags;
1902                                 m_depthStencilFormat,                                                                                                                           // VkFormat                                                     format;
1903                                 m_multisampleStateParams.rasterizationSamples,                                                                          // VkSampleCountFlagBits                        samples;
1904                                 (m_useDepth ? VK_ATTACHMENT_LOAD_OP_CLEAR : VK_ATTACHMENT_LOAD_OP_DONT_CARE),           // VkAttachmentLoadOp                           loadOp;
1905                                 (m_useDepth ? VK_ATTACHMENT_STORE_OP_STORE : VK_ATTACHMENT_STORE_OP_DONT_CARE),         // VkAttachmentStoreOp                          storeOp;
1906                                 (m_useStencil ? VK_ATTACHMENT_LOAD_OP_CLEAR : VK_ATTACHMENT_LOAD_OP_DONT_CARE),         // VkAttachmentStoreOp                          stencilLoadOp;
1907                                 (m_useStencil ? VK_ATTACHMENT_STORE_OP_STORE : VK_ATTACHMENT_STORE_OP_DONT_CARE),       // VkAttachmentStoreOp                          stencilStoreOp;
1908                                 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,                                                                       // VkImageLayout                                        initialLayout;
1909                                 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL                                                                        // VkImageLayout                                        finalLayout;
1910                         };
1911                         attachmentDescriptions.push_back(depthStencilAttachmentDescription);
1912                 };
1913
1914                 const VkAttachmentReference colorAttachmentReference =
1915                 {
1916                         0u,                                                                                                     // deUint32                     attachment;
1917                         VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL                        // VkImageLayout        layout;
1918                 };
1919
1920                 const VkAttachmentReference inputAttachmentReference =
1921                 {
1922                         0u,                                                                                                     // deUint32                     attachment;
1923                         VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL                        // VkImageLayout        layout;
1924                 };
1925
1926                 const VkAttachmentReference resolveAttachmentReference =
1927                 {
1928                         resolveAttachmentIndex,                                                         // deUint32                     attachment;
1929                         VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL                        // VkImageLayout        layout;
1930                 };
1931
1932                 std::vector<VkAttachmentReference> perSampleAttachmentReferences(m_perSampleImages.size());
1933                 if (m_renderType == RENDER_TYPE_COPY_SAMPLES)
1934                 {
1935                         for (size_t i = 0; i < m_perSampleImages.size(); ++i)
1936                         {
1937                                 const VkAttachmentReference perSampleAttachmentReference =
1938                                 {
1939                                         perSampleAttachmentIndex + static_cast<deUint32>(i),    // deUint32                     attachment;
1940                                         VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL                                // VkImageLayout        layout;
1941                                 };
1942                                 perSampleAttachmentReferences[i] = perSampleAttachmentReference;
1943                         }
1944                 }
1945
1946                 const VkAttachmentReference depthStencilAttachmentReference =
1947                 {
1948                         depthStencilAttachmentIndex,                                            // deUint32                     attachment;
1949                         VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL        // VkImageLayout        layout;
1950                 };
1951
1952                 std::vector<VkSubpassDescription>       subpassDescriptions;
1953                 std::vector<VkSubpassDependency>        subpassDependencies;
1954
1955                 {
1956                         const VkSubpassDescription renderSubpassDescription =
1957                         {
1958                                 0u,                                                                                                                                                             // VkSubpassDescriptionFlags    flags;
1959                                 VK_PIPELINE_BIND_POINT_GRAPHICS,                                                                                                // VkPipelineBindPoint                  pipelineBindPoint;
1960                                 0u,                                                                                                                                                             // deUint32                                             inputAttachmentCount;
1961                                 DE_NULL,                                                                                                                                                // const VkAttachmentReference* pInputAttachments;
1962                                 1u,                                                                                                                                                             // deUint32                                             colorAttachmentCount;
1963                                 &colorAttachmentReference,                                                                                                              // const VkAttachmentReference* pColorAttachments;
1964                                 (m_renderType == RENDER_TYPE_RESOLVE) ? &resolveAttachmentReference : DE_NULL,  // const VkAttachmentReference* pResolveAttachments;
1965                                 (m_useDepth || m_useStencil ? &depthStencilAttachmentReference : DE_NULL),              // const VkAttachmentReference* pDepthStencilAttachment;
1966                                 0u,                                                                                                                                                             // deUint32                                             preserveAttachmentCount;
1967                                 DE_NULL                                                                                                                                                 // const VkAttachmentReference* pPreserveAttachments;
1968                         };
1969                         subpassDescriptions.push_back(renderSubpassDescription);
1970                 }
1971
1972                 if (m_renderType == RENDER_TYPE_COPY_SAMPLES)
1973                 {
1974
1975                         for (size_t i = 0; i < m_perSampleImages.size(); ++i)
1976                         {
1977                                 const VkSubpassDescription copySampleSubpassDescription =
1978                                 {
1979                                         0u,                                                                                                     // VkSubpassDescriptionFlags            flags;
1980                                         VK_PIPELINE_BIND_POINT_GRAPHICS,                                        // VkPipelineBindPoint                          pipelineBindPoint;
1981                                         1u,                                                                                                     // deUint32                                                     inputAttachmentCount;
1982                                         &inputAttachmentReference,                                                      // const VkAttachmentReference*         pInputAttachments;
1983                                         1u,                                                                                                     // deUint32                                                     colorAttachmentCount;
1984                                         &perSampleAttachmentReferences[i],                                      // const VkAttachmentReference*         pColorAttachments;
1985                                         DE_NULL,                                                                                        // const VkAttachmentReference*         pResolveAttachments;
1986                                         DE_NULL,                                                                                        // const VkAttachmentReference*         pDepthStencilAttachment;
1987                                         0u,                                                                                                     // deUint32                                                     preserveAttachmentCount;
1988                                         DE_NULL                                                                                         // const VkAttachmentReference*         pPreserveAttachments;
1989                                 };
1990                                 subpassDescriptions.push_back(copySampleSubpassDescription);
1991
1992                                 const VkSubpassDependency copySampleSubpassDependency =
1993                                 {
1994                                         0u,                                                                                                     // deUint32                                                     srcSubpass
1995                                         1u + static_cast<deUint32>(i),                                          // deUint32                                                     dstSubpass
1996                                         VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,                                      // VkPipelineStageFlags                         srcStageMask
1997                                         VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,                          // VkPipelineStageFlags                         dstStageMask
1998                                         VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,                           // VkAccessFlags                                        srcAccessMask
1999                                         VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,                            // VkAccessFlags                                        dstAccessMask
2000                                         0u,                                                                                                     // VkDependencyFlags                            dependencyFlags
2001                                 };
2002                                 subpassDependencies.push_back(copySampleSubpassDependency);
2003                         }
2004                 }
2005
2006                 const VkRenderPassCreateInfo renderPassParams =
2007                 {
2008                         VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,                                      // VkStructureType                                      sType;
2009                         DE_NULL,                                                                                                        // const void*                                          pNext;
2010                         0u,                                                                                                                     // VkRenderPassCreateFlags                      flags;
2011                         (deUint32)attachmentDescriptions.size(),                                        // deUint32                                                     attachmentCount;
2012                         &attachmentDescriptions[0],                                                                     // const VkAttachmentDescription*       pAttachments;
2013                         (deUint32)subpassDescriptions.size(),                                           // deUint32                                                     subpassCount;
2014                         &subpassDescriptions[0],                                                                        // const VkSubpassDescription*          pSubpasses;
2015                         (deUint32)subpassDependencies.size(),                                           // deUint32                                                     dependencyCount;
2016                         subpassDependencies.size() != 0 ? &subpassDependencies[0] : DE_NULL
2017                 };
2018
2019                 m_renderPass = createRenderPass(vk, vkDevice, &renderPassParams);
2020         }
2021
2022         // Create framebuffer
2023         {
2024                 std::vector<VkImageView> attachments;
2025                 attachments.push_back(*m_colorAttachmentView);
2026                 if (m_renderType == RENDER_TYPE_RESOLVE)
2027                 {
2028                         attachments.push_back(*m_resolveAttachmentView);
2029                 }
2030                 if (m_renderType == RENDER_TYPE_COPY_SAMPLES)
2031                 {
2032                         for (size_t i = 0; i < m_perSampleImages.size(); ++i)
2033                         {
2034                                 attachments.push_back(*m_perSampleImages[i]->m_attachmentView);
2035                         }
2036                 }
2037
2038                 if (m_useDepth || m_useStencil)
2039                 {
2040                         attachments.push_back(*m_depthStencilAttachmentView);
2041                 }
2042
2043                 const VkFramebufferCreateInfo framebufferParams =
2044                 {
2045                         VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,                      // VkStructureType                                      sType;
2046                         DE_NULL,                                                                                        // const void*                                          pNext;
2047                         0u,                                                                                                     // VkFramebufferCreateFlags                     flags;
2048                         *m_renderPass,                                                                          // VkRenderPass                                         renderPass;
2049                         (deUint32)attachments.size(),                                           // deUint32                                                     attachmentCount;
2050                         &attachments[0],                                                                        // const VkImageView*                           pAttachments;
2051                         (deUint32)m_renderSize.x(),                                                     // deUint32                                                     width;
2052                         (deUint32)m_renderSize.y(),                                                     // deUint32                                                     height;
2053                         1u                                                                                                      // deUint32                                                     layers;
2054                 };
2055
2056                 m_framebuffer = createFramebuffer(vk, vkDevice, &framebufferParams);
2057         }
2058
2059         // Create pipeline layout
2060         {
2061                 const VkPipelineLayoutCreateInfo pipelineLayoutParams =
2062                 {
2063                         VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,          // VkStructureType                                      sType;
2064                         DE_NULL,                                                                                        // const void*                                          pNext;
2065                         0u,                                                                                                     // VkPipelineLayoutCreateFlags          flags;
2066                         0u,                                                                                                     // deUint32                                                     setLayoutCount;
2067                         DE_NULL,                                                                                        // const VkDescriptorSetLayout*         pSetLayouts;
2068                         0u,                                                                                                     // deUint32                                                     pushConstantRangeCount;
2069                         DE_NULL                                                                                         // const VkPushConstantRange*           pPushConstantRanges;
2070                 };
2071
2072                 m_pipelineLayout = createPipelineLayout(vk, vkDevice, &pipelineLayoutParams);
2073
2074                 if (m_renderType == RENDER_TYPE_COPY_SAMPLES)
2075                 {
2076
2077                         // Create descriptor set layout
2078                         const VkDescriptorSetLayoutBinding              layoutBinding                                   =
2079                         {
2080                                 0u,                                                                                                                     // deUint32                                                             binding;
2081                                 VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,                                            // VkDescriptorType                                             descriptorType;
2082                                 1u,                                                                                                                     // deUint32                                                             descriptorCount;
2083                                 VK_SHADER_STAGE_FRAGMENT_BIT,                                                           // VkShaderStageFlags                                   stageFlags;
2084                                 DE_NULL,                                                                                                        // const VkSampler*                                             pImmutableSamplers;
2085                         };
2086
2087                         const VkDescriptorSetLayoutCreateInfo   descriptorSetLayoutParams               =
2088                         {
2089                                 VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,            // VkStructureType                                              sType
2090                                 DE_NULL,                                                                                                        // const void*                                                  pNext
2091                                 0u,                                                                                                                     // VkDescriptorSetLayoutCreateFlags             flags
2092                                 1u,                                                                                                                     // deUint32                                                             bindingCount
2093                                 &layoutBinding                                                                                          // const VkDescriptorSetLayoutBinding*  pBindings
2094                         };
2095                         m_copySampleDesciptorLayout     = createDescriptorSetLayout(vk, vkDevice, &descriptorSetLayoutParams);
2096
2097                         // Create pipeline layout
2098
2099                         const VkPushConstantRange                               pushConstantRange                               =
2100                         {
2101                                 VK_SHADER_STAGE_FRAGMENT_BIT,                                                           // VkShaderStageFlags                                   stageFlags;
2102                                 0u,                                                                                                                     // deUint32                                                             offset;
2103                                 sizeof(deInt32)                                                                                         // deUint32                                                             size;
2104                         };
2105                         const VkPipelineLayoutCreateInfo                copySamplePipelineLayoutParams  =
2106                         {
2107                                 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,                          // VkStructureType                                              sType;
2108                                 DE_NULL,                                                                                                        // const void*                                                  pNext;
2109                                 0u,                                                                                                                     // VkPipelineLayoutCreateFlags                  flags;
2110                                 1u,                                                                                                                     // deUint32                                                             setLayoutCount;
2111                                 &m_copySampleDesciptorLayout.get(),                                                     // const VkDescriptorSetLayout*                 pSetLayouts;
2112                                 1u,                                                                                                                     // deUint32                                                             pushConstantRangeCount;
2113                                 &pushConstantRange                                                                                      // const VkPushConstantRange*                   pPushConstantRanges;
2114                         };
2115                         m_copySamplePipelineLayout              = createPipelineLayout(vk, vkDevice, &copySamplePipelineLayoutParams);
2116                 }
2117         }
2118
2119         m_vertexShaderModule    = createShaderModule(vk, vkDevice, m_context.getBinaryCollection().get("color_vert"), 0);
2120         m_fragmentShaderModule  = createShaderModule(vk, vkDevice, m_context.getBinaryCollection().get("color_frag"), 0);
2121
2122         if (m_renderType == RENDER_TYPE_COPY_SAMPLES)
2123         {
2124                 m_copySampleVertexShaderModule          = createShaderModule(vk, vkDevice, m_context.getBinaryCollection().get("quad_vert"), 0);
2125                 m_copySampleFragmentShaderModule        = createShaderModule(vk, vkDevice, m_context.getBinaryCollection().get("copy_sample_frag"), 0);
2126         }
2127
2128         // Create pipeline
2129         {
2130                 const VkPipelineShaderStageCreateInfo   shaderStageParams[2] =
2131                 {
2132                         {
2133                                 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,            // VkStructureType                                              sType;
2134                                 DE_NULL,                                                                                                        // const void*                                                  pNext;
2135                                 0u,                                                                                                                     // VkPipelineShaderStageCreateFlags             flags;
2136                                 VK_SHADER_STAGE_VERTEX_BIT,                                                                     // VkShaderStageFlagBits                                stage;
2137                                 *m_vertexShaderModule,                                                                          // VkShaderModule                                               module;
2138                                 "main",                                                                                                         // const char*                                                  pName;
2139                                 DE_NULL                                                                                                         // const VkSpecializationInfo*                  pSpecializationInfo;
2140                         },
2141                         {
2142                                 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,            // VkStructureType                                              sType;
2143                                 DE_NULL,                                                                                                        // const void*                                                  pNext;
2144                                 0u,                                                                                                                     // VkPipelineShaderStageCreateFlags             flags;
2145                                 VK_SHADER_STAGE_FRAGMENT_BIT,                                                           // VkShaderStageFlagBits                                stage;
2146                                 *m_fragmentShaderModule,                                                                        // VkShaderModule                                               module;
2147                                 "main",                                                                                                         // const char*                                                  pName;
2148                                 DE_NULL                                                                                                         // const VkSpecializationInfo*                  pSpecializationInfo;
2149                         }
2150                 };
2151
2152                 const VkVertexInputBindingDescription   vertexInputBindingDescription =
2153                 {
2154                         0u,                                                                     // deUint32                             binding;
2155                         sizeof(Vertex4RGBA),                            // deUint32                             stride;
2156                         VK_VERTEX_INPUT_RATE_VERTEX                     // VkVertexInputRate    inputRate;
2157                 };
2158
2159                 const VkVertexInputAttributeDescription vertexInputAttributeDescriptions[2] =
2160                 {
2161                         {
2162                                 0u,                                                                     // deUint32     location;
2163                                 0u,                                                                     // deUint32     binding;
2164                                 VK_FORMAT_R32G32B32A32_SFLOAT,          // VkFormat     format;
2165                                 0u                                                                      // deUint32     offset;
2166                         },
2167                         {
2168                                 1u,                                                                     // deUint32     location;
2169                                 0u,                                                                     // deUint32     binding;
2170                                 VK_FORMAT_R32G32B32A32_SFLOAT,          // VkFormat     format;
2171                                 DE_OFFSET_OF(Vertex4RGBA, color),       // deUint32     offset;
2172                         }
2173                 };
2174
2175                 const VkPipelineVertexInputStateCreateInfo vertexInputStateParams =
2176                 {
2177                         VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,              // VkStructureType                                                      sType;
2178                         DE_NULL,                                                                                                                // const void*                                                          pNext;
2179                         0u,                                                                                                                             // VkPipelineVertexInputStateCreateFlags        flags;
2180                         1u,                                                                                                                             // deUint32                                                                     vertexBindingDescriptionCount;
2181                         &vertexInputBindingDescription,                                                                 // const VkVertexInputBindingDescription*       pVertexBindingDescriptions;
2182                         2u,                                                                                                                             // deUint32                                                                     vertexAttributeDescriptionCount;
2183                         vertexInputAttributeDescriptions                                                                // const VkVertexInputAttributeDescription*     pVertexAttributeDescriptions;
2184                 };
2185
2186                 // Topology is set before the pipeline creation.
2187                 VkPipelineInputAssemblyStateCreateInfo inputAssemblyStateParams =
2188                 {
2189                         VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,    // VkStructureType                                                      sType;
2190                         DE_NULL,                                                                                                                // const void*                                                          pNext;
2191                         0u,                                                                                                                             // VkPipelineInputAssemblyStateCreateFlags      flags;
2192                         VK_PRIMITIVE_TOPOLOGY_LAST,                                                                             // VkPrimitiveTopology                                          topology;
2193                         false                                                                                                                   // VkBool32                                                                     primitiveRestartEnable;
2194                 };
2195
2196                 const VkViewport viewport =
2197                 {
2198                         0.0f,                                           // float        x;
2199                         0.0f,                                           // float        y;
2200                         (float)m_renderSize.x(),        // float        width;
2201                         (float)m_renderSize.y(),        // float        height;
2202                         0.0f,                                           // float        minDepth;
2203                         1.0f                                            // float        maxDepth;
2204                 };
2205
2206                 const VkRect2D scissor =
2207                 {
2208                         { 0, 0 },                                                                                                       // VkOffset2D  offset;
2209                         { (deUint32)m_renderSize.x(), (deUint32)m_renderSize.y() }      // VkExtent2D  extent;
2210                 };
2211
2212                 const VkPipelineViewportStateCreateInfo viewportStateParams =
2213                 {
2214                         VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO,                  // VkStructureType                                              sType;
2215                         DE_NULL,                                                                                                                // const void*                                                  pNext;
2216                         0u,                                                                                                                             // VkPipelineViewportStateCreateFlags   flags;
2217                         1u,                                                                                                                             // deUint32                                                             viewportCount;
2218                         &viewport,                                                                                                              // const VkViewport*                                    pViewports;
2219                         1u,                                                                                                                             // deUint32                                                             scissorCount;
2220                         &scissor                                                                                                                // const VkRect2D*                                              pScissors;
2221                 };
2222
2223                 const VkPipelineRasterizationStateCreateInfo rasterStateParams =
2224                 {
2225                         VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO,             // VkStructureType                                                      sType;
2226                         DE_NULL,                                                                                                                // const void*                                                          pNext;
2227                         0u,                                                                                                                             // VkPipelineRasterizationStateCreateFlags      flags;
2228                         false,                                                                                                                  // VkBool32                                                                     depthClampEnable;
2229                         false,                                                                                                                  // VkBool32                                                                     rasterizerDiscardEnable;
2230                         VK_POLYGON_MODE_FILL,                                                                                   // VkPolygonMode                                                        polygonMode;
2231                         VK_CULL_MODE_NONE,                                                                                              // VkCullModeFlags                                                      cullMode;
2232                         VK_FRONT_FACE_COUNTER_CLOCKWISE,                                                                // VkFrontFace                                                          frontFace;
2233                         VK_FALSE,                                                                                                               // VkBool32                                                                     depthBiasEnable;
2234                         0.0f,                                                                                                                   // float                                                                        depthBiasConstantFactor;
2235                         0.0f,                                                                                                                   // float                                                                        depthBiasClamp;
2236                         0.0f,                                                                                                                   // float                                                                        depthBiasSlopeFactor;
2237                         1.0f                                                                                                                    // float                                                                        lineWidth;
2238                 };
2239
2240                 const VkPipelineColorBlendStateCreateInfo colorBlendStateParams =
2241                 {
2242                         VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO,       // VkStructureType                                                              sType;
2243                         DE_NULL,                                                                                                        // const void*                                                                  pNext;
2244                         0u,                                                                                                                     // VkPipelineColorBlendStateCreateFlags                 flags;
2245                         false,                                                                                                          // VkBool32                                                                             logicOpEnable;
2246                         VK_LOGIC_OP_COPY,                                                                                       // VkLogicOp                                                                    logicOp;
2247                         1u,                                                                                                                     // deUint32                                                                             attachmentCount;
2248                         &m_colorBlendState,                                                                                     // const VkPipelineColorBlendAttachmentState*   pAttachments;
2249                         { 0.0f, 0.0f, 0.0f, 0.0f }                                                                      // float                                                                                blendConstants[4];
2250                 };
2251
2252                 const VkStencilOpState stencilOpState =
2253                 {
2254                         VK_STENCIL_OP_KEEP,                                             // VkStencilOp  failOp;
2255                         VK_STENCIL_OP_REPLACE,                                  // VkStencilOp  passOp;
2256                         VK_STENCIL_OP_KEEP,                                             // VkStencilOp  depthFailOp;
2257                         VK_COMPARE_OP_GREATER,                                  // VkCompareOp  compareOp;
2258                         1u,                                                                             // deUint32             compareMask;
2259                         1u,                                                                             // deUint32             writeMask;
2260                         1u,                                                                             // deUint32             reference;
2261                 };
2262
2263                 const VkPipelineDepthStencilStateCreateInfo depthStencilStateParams =
2264                 {
2265                         VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO,     // VkStructureType                                                      sType;
2266                         DE_NULL,                                                                                                        // const void*                                                          pNext;
2267                         0u,                                                                                                                     // VkPipelineDepthStencilStateCreateFlags       flags;
2268                         m_useDepth,                                                                                                     // VkBool32                                                                     depthTestEnable;
2269                         m_useDepth,                                                                                                     // VkBool32                                                                     depthWriteEnable;
2270                         VK_COMPARE_OP_LESS,                                                                                     // VkCompareOp                                                          depthCompareOp;
2271                         false,                                                                                                          // VkBool32                                                                     depthBoundsTestEnable;
2272                         m_useStencil,                                                                                           // VkBool32                                                                     stencilTestEnable;
2273                         stencilOpState,                                                                                         // VkStencilOpState     front;
2274                         stencilOpState,                                                                                         // VkStencilOpState     back;
2275                         0.0f,                                                                                                           // float                        minDepthBounds;
2276                         1.0f,                                                                                                           // float                        maxDepthBounds;
2277                 };
2278
2279                 const VkGraphicsPipelineCreateInfo graphicsPipelineParams =
2280                 {
2281                         VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,        // VkStructureType                                                                      sType;
2282                         DE_NULL,                                                                                        // const void*                                                                          pNext;
2283                         0u,                                                                                                     // VkPipelineCreateFlags                                                        flags;
2284                         2u,                                                                                                     // deUint32                                                                                     stageCount;
2285                         shaderStageParams,                                                                      // const VkPipelineShaderStageCreateInfo*                       pStages;
2286                         &vertexInputStateParams,                                                        // const VkPipelineVertexInputStateCreateInfo*          pVertexInputState;
2287                         &inputAssemblyStateParams,                                                      // const VkPipelineInputAssemblyStateCreateInfo*        pInputAssemblyState;
2288                         DE_NULL,                                                                                        // const VkPipelineTessellationStateCreateInfo*         pTessellationState;
2289                         &viewportStateParams,                                                           // const VkPipelineViewportStateCreateInfo*                     pViewportState;
2290                         &rasterStateParams,                                                                     // const VkPipelineRasterizationStateCreateInfo*        pRasterizationState;
2291                         &m_multisampleStateParams,                                                      // const VkPipelineMultisampleStateCreateInfo*          pMultisampleState;
2292                         &depthStencilStateParams,                                                       // const VkPipelineDepthStencilStateCreateInfo*         pDepthStencilState;
2293                         &colorBlendStateParams,                                                         // const VkPipelineColorBlendStateCreateInfo*           pColorBlendState;
2294                         (const VkPipelineDynamicStateCreateInfo*)DE_NULL,       // const VkPipelineDynamicStateCreateInfo*                      pDynamicState;
2295                         *m_pipelineLayout,                                                                      // VkPipelineLayout                                                                     layout;
2296                         *m_renderPass,                                                                          // VkRenderPass                                                                         renderPass;
2297                         0u,                                                                                                     // deUint32                                                                                     subpass;
2298                         0u,                                                                                                     // VkPipeline                                                                           basePipelineHandle;
2299                         0u                                                                                                      // deInt32                                                                                      basePipelineIndex;
2300                 };
2301
2302                 for (deUint32 i = 0u; i < numTopologies; ++i)
2303                 {
2304                         inputAssemblyStateParams.topology = pTopology[i];
2305                         m_graphicsPipelines.push_back(VkPipelineSp(new Unique<VkPipeline>(createGraphicsPipeline(vk, vkDevice, DE_NULL, &graphicsPipelineParams))));
2306                 }
2307         }
2308
2309         if (m_renderType == RENDER_TYPE_COPY_SAMPLES)
2310         {
2311                 // Create pipelines for copying samples to single sampled images
2312                 {
2313                         const VkPipelineShaderStageCreateInfo shaderStageParams[2] =
2314                         {
2315                                 {
2316                                         VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,            // VkStructureType                                                      sType;
2317                                         DE_NULL,                                                                                                        // const void*                                                          pNext;
2318                                         0u,                                                                                                                     // VkPipelineShaderStageCreateFlags                     flags;
2319                                         VK_SHADER_STAGE_VERTEX_BIT,                                                                     // VkShaderStageFlagBits                                        stage;
2320                                         *m_copySampleVertexShaderModule,                                                        // VkShaderModule                                                       module;
2321                                         "main",                                                                                                         // const char*                                                          pName;
2322                                         DE_NULL                                                                                                         // const VkSpecializationInfo*                          pSpecializationInfo;
2323                                 },
2324                                 {
2325                                         VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,            // VkStructureType                                                      sType;
2326                                         DE_NULL,                                                                                                        // const void*                                                          pNext;
2327                                         0u,                                                                                                                     // VkPipelineShaderStageCreateFlags                     flags;
2328                                         VK_SHADER_STAGE_FRAGMENT_BIT,                                                           // VkShaderStageFlagBits                                        stage;
2329                                         *m_copySampleFragmentShaderModule,                                                      // VkShaderModule                                                       module;
2330                                         "main",                                                                                                         // const char*                                                          pName;
2331                                         DE_NULL                                                                                                         // const VkSpecializationInfo*                          pSpecializationInfo;
2332                                 }
2333                         };
2334
2335                         const VkPipelineVertexInputStateCreateInfo vertexInputStateParams =
2336                         {
2337                                 VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,              // VkStructureType                                                      sType;
2338                                 DE_NULL,                                                                                                                // const void*                                                          pNext;
2339                                 0u,                                                                                                                             // VkPipelineVertexInputStateCreateFlags        flags;
2340                                 0u,                                                                                                                             // deUint32                                                                     vertexBindingDescriptionCount;
2341                                 DE_NULL,                                                                                                                // const VkVertexInputBindingDescription*       pVertexBindingDescriptions;
2342                                 0u,                                                                                                                             // deUint32                                                                     vertexAttributeDescriptionCount;
2343                                 DE_NULL                                                                                                                 // const VkVertexInputAttributeDescription*     pVertexAttributeDescriptions;
2344                         };
2345
2346                         // Topology is set before the pipeline creation.
2347                         VkPipelineInputAssemblyStateCreateInfo inputAssemblyStateParams =
2348                         {
2349                                 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,    // VkStructureType                                                      sType;
2350                                 DE_NULL,                                                                                                                // const void*                                                          pNext;
2351                                 0u,                                                                                                                             // VkPipelineInputAssemblyStateCreateFlags      flags;
2352                                 VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP,                                                   // VkPrimitiveTopology                                          topology;
2353                                 false                                                                                                                   // VkBool32                                                                     primitiveRestartEnable;
2354                         };
2355
2356                         const VkViewport viewport =
2357                         {
2358                                 0.0f,                                           // float        x;
2359                                 0.0f,                                           // float        y;
2360                                 (float)m_renderSize.x(),        // float        width;
2361                                 (float)m_renderSize.y(),        // float        height;
2362                                 0.0f,                                           // float        minDepth;
2363                                 1.0f                                            // float        maxDepth;
2364                         };
2365
2366                         const VkRect2D scissor =
2367                         {
2368                                 { 0, 0 },                                                                                                       // VkOffset2D  offset;
2369                                 { (deUint32)m_renderSize.x(), (deUint32)m_renderSize.y() }      // VkExtent2D  extent;
2370                         };
2371
2372                         const VkPipelineViewportStateCreateInfo viewportStateParams =
2373                         {
2374                                 VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO,                  // VkStructureType                                                      sType;
2375                                 DE_NULL,                                                                                                                // const void*                                                          pNext;
2376                                 0u,                                                                                                                             // VkPipelineViewportStateCreateFlags           flags;
2377                                 1u,                                                                                                                             // deUint32                                                                     viewportCount;
2378                                 &viewport,                                                                                                              // const VkViewport*                                            pViewports;
2379                                 1u,                                                                                                                             // deUint32                                                                     scissorCount;
2380                                 &scissor                                                                                                                // const VkRect2D*                                                      pScissors;
2381                         };
2382
2383                         const VkPipelineRasterizationStateCreateInfo rasterStateParams =
2384                         {
2385                                 VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO,             // VkStructureType                                                      sType;
2386                                 DE_NULL,                                                                                                                // const void*                                                          pNext;
2387                                 0u,                                                                                                                             // VkPipelineRasterizationStateCreateFlags      flags;
2388                                 false,                                                                                                                  // VkBool32                                                                     depthClampEnable;
2389                                 false,                                                                                                                  // VkBool32                                                                     rasterizerDiscardEnable;
2390                                 VK_POLYGON_MODE_FILL,                                                                                   // VkPolygonMode                                                        polygonMode;
2391                                 VK_CULL_MODE_NONE,                                                                                              // VkCullModeFlags                                                      cullMode;
2392                                 VK_FRONT_FACE_COUNTER_CLOCKWISE,                                                                // VkFrontFace                                                          frontFace;
2393                                 VK_FALSE,                                                                                                               // VkBool32                                                                     depthBiasEnable;
2394                                 0.0f,                                                                                                                   // float                                                                        depthBiasConstantFactor;
2395                                 0.0f,                                                                                                                   // float                                                                        depthBiasClamp;
2396                                 0.0f,                                                                                                                   // float                                                                        depthBiasSlopeFactor;
2397                                 1.0f                                                                                                                    // float                                                                        lineWidth;
2398                         };
2399
2400                         const VkPipelineColorBlendStateCreateInfo colorBlendStateParams =
2401                         {
2402                                 VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO,       // VkStructureType                                                              sType;
2403                                 DE_NULL,                                                                                                        // const void*                                                                  pNext;
2404                                 0u,                                                                                                                     // VkPipelineColorBlendStateCreateFlags                 flags;
2405                                 false,                                                                                                          // VkBool32                                                                             logicOpEnable;
2406                                 VK_LOGIC_OP_COPY,                                                                                       // VkLogicOp                                                                    logicOp;
2407                                 1u,                                                                                                                     // deUint32                                                                             attachmentCount;
2408                                 &m_colorBlendState,                                                                                     // const VkPipelineColorBlendAttachmentState*   pAttachments;
2409                                 { 0.0f, 0.0f, 0.0f, 0.0f }                                                                      // float                                                                                blendConstants[4];
2410                         };
2411
2412                         const  VkPipelineMultisampleStateCreateInfo multisampleStateParams =
2413                         {
2414                                 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,       // VkStructureType                                                      sType
2415                                 DE_NULL,                                                                                                        // const void*                                                          pNext
2416                                 0u,                                                                                                                     // VkPipelineMultisampleStateCreateFlags        flags
2417                                 VK_SAMPLE_COUNT_1_BIT,                                                                          // VkSampleCountFlagBits                                        rasterizationSamples
2418                                 VK_FALSE,                                                                                                       // VkBool32                                                                     sampleShadingEnable
2419                                 0.0f,                                                                                                           // float                                                                        minSampleShading
2420                                 DE_NULL,                                                                                                        // const VkSampleMask*                                          pSampleMask
2421                                 VK_FALSE,                                                                                                       // VkBool32                                                                     alphaToCoverageEnable
2422                                 VK_FALSE,                                                                                                       // VkBool32                                                                     alphaToOneEnable
2423                         };
2424
2425                         const VkGraphicsPipelineCreateInfo graphicsPipelineTemplate =
2426                         {
2427                                 VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,        // VkStructureType                                                                      sType;
2428                                 DE_NULL,                                                                                        // const void*                                                                          pNext;
2429                                 0u,                                                                                                     // VkPipelineCreateFlags                                                        flags;
2430                                 2u,                                                                                                     // deUint32                                                                                     stageCount;
2431                                 shaderStageParams,                                                                      // const VkPipelineShaderStageCreateInfo*                       pStages;
2432                                 &vertexInputStateParams,                                                        // const VkPipelineVertexInputStateCreateInfo*          pVertexInputState;
2433                                 &inputAssemblyStateParams,                                                      // const VkPipelineInputAssemblyStateCreateInfo*        pInputAssemblyState;
2434                                 DE_NULL,                                                                                        // const VkPipelineTessellationStateCreateInfo*         pTessellationState;
2435                                 &viewportStateParams,                                                           // const VkPipelineViewportStateCreateInfo*                     pViewportState;
2436                                 &rasterStateParams,                                                                     // const VkPipelineRasterizationStateCreateInfo*        pRasterizationState;
2437                                 &multisampleStateParams,                                                        // const VkPipelineMultisampleStateCreateInfo*          pMultisampleState;
2438                                 DE_NULL,                                                                                        // const VkPipelineDepthStencilStateCreateInfo*         pDepthStencilState;
2439                                 &colorBlendStateParams,                                                         // const VkPipelineColorBlendStateCreateInfo*           pColorBlendState;
2440                                 (const VkPipelineDynamicStateCreateInfo*)DE_NULL,       // const VkPipelineDynamicStateCreateInfo*                      pDynamicState;
2441                                 *m_copySamplePipelineLayout,                                            // VkPipelineLayout                                                                     layout;
2442                                 *m_renderPass,                                                                          // VkRenderPass                                                                         renderPass;
2443                                 0u,                                                                                                     // deUint32                                                                                     subpass;
2444                                 0u,                                                                                                     // VkPipeline                                                                           basePipelineHandle;
2445                                 0u                                                                                                      // deInt32                                                                                      basePipelineIndex;
2446                         };
2447
2448                         for (size_t i = 0; i < m_perSampleImages.size(); ++i)
2449                         {
2450                                 VkGraphicsPipelineCreateInfo graphicsPipelineParams = graphicsPipelineTemplate;
2451
2452                                 // Pipeline is to be used in subpasses subsequent to sample-shading subpass
2453                                 graphicsPipelineParams.subpass = 1u + (deUint32)i;
2454
2455                                 m_copySamplePipelines.push_back(VkPipelineSp(new Unique<VkPipeline>(createGraphicsPipeline(vk, vkDevice, DE_NULL, &graphicsPipelineParams))));
2456                         }
2457                 }
2458
2459
2460                 const VkDescriptorPoolSize                      descriptorPoolSize                      =
2461                 {
2462                         VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,                                    // VkDescriptorType                                     type;
2463                         1u                                                                                                              // deUint32                                                     descriptorCount;
2464                 };
2465
2466                 const VkDescriptorPoolCreateInfo        descriptorPoolCreateInfo        =
2467                 {
2468                         VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,                  // VkStructureType                                      sType
2469                         DE_NULL,                                                                                                // const void*                                          pNext
2470                         VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT,              // VkDescriptorPoolCreateFlags          flags
2471                         1u,                                                                                                     // deUint32                                                     maxSets
2472                         1u,                                                                                                             // deUint32                                                     poolSizeCount
2473                         &descriptorPoolSize                                                                             // const VkDescriptorPoolSize*          pPoolSizes
2474                 };
2475
2476                 m_copySampleDesciptorPool = createDescriptorPool(vk, vkDevice, &descriptorPoolCreateInfo);
2477
2478                 const VkDescriptorSetAllocateInfo       descriptorSetAllocateInfo       =
2479                 {
2480                         VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,                 // VkStructureType                                      sType
2481                         DE_NULL,                                                                                                // const void*                                          pNext
2482                         *m_copySampleDesciptorPool,                                                             // VkDescriptorPool                                     descriptorPool
2483                         1u,                                                                                                             // deUint32                                                     descriptorSetCount
2484                         &m_copySampleDesciptorLayout.get(),                                             // const VkDescriptorSetLayout*         pSetLayouts
2485                 };
2486
2487                 m_copySampleDesciptorSet = allocateDescriptorSet(vk, vkDevice, &descriptorSetAllocateInfo);
2488
2489                 const VkDescriptorImageInfo                     imageInfo                                       =
2490                 {
2491                         DE_NULL,
2492                         *m_colorAttachmentView,
2493                         VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
2494                 };
2495                 const VkWriteDescriptorSet                      descriptorWrite                         =
2496                 {
2497                         VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,                 // VkStructureType                                      sType;
2498                         DE_NULL,                                                                                // const void*                                          pNext;
2499                         *m_copySampleDesciptorSet,                                              // VkDescriptorSet                                      dstSet;
2500                         0u,                                                                                             // deUint32                                                     dstBinding;
2501                         0u,                                                                                             // deUint32                                                     dstArrayElement;
2502                         1u,                                                                                             // deUint32                                                     descriptorCount;
2503                         VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,                    // VkDescriptorType                                     descriptorType;
2504                         &imageInfo,                                                                             // const VkDescriptorImageInfo*         pImageInfo;
2505                         DE_NULL,                                                                                // const VkDescriptorBufferInfo*        pBufferInfo;
2506                         DE_NULL,                                                                                // const VkBufferView*                          pTexelBufferView;
2507                 };
2508                 vk.updateDescriptorSets(vkDevice, 1u, &descriptorWrite, 0u, DE_NULL);
2509         }
2510
2511         // Create vertex buffer
2512         {
2513                 const VkBufferCreateInfo vertexBufferParams =
2514                 {
2515                         VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,           // VkStructureType              sType;
2516                         DE_NULL,                                                                        // const void*                  pNext;
2517                         0u,                                                                                     // VkBufferCreateFlags  flags;
2518                         1024u,                                                                          // VkDeviceSize                 size;
2519                         VK_BUFFER_USAGE_VERTEX_BUFFER_BIT,                      // VkBufferUsageFlags   usage;
2520                         VK_SHARING_MODE_EXCLUSIVE,                                      // VkSharingMode                sharingMode;
2521                         1u,                                                                                     // deUint32                             queueFamilyIndexCount;
2522                         &queueFamilyIndex                                                       // const deUint32*              pQueueFamilyIndices;
2523                 };
2524
2525                 m_vertexBuffer          = createBuffer(vk, vkDevice, &vertexBufferParams);
2526                 m_vertexBufferAlloc     = memAlloc.allocate(getBufferMemoryRequirements(vk, vkDevice, *m_vertexBuffer), MemoryRequirement::HostVisible);
2527
2528                 VK_CHECK(vk.bindBufferMemory(vkDevice, *m_vertexBuffer, m_vertexBufferAlloc->getMemory(), m_vertexBufferAlloc->getOffset()));
2529
2530                 // Load vertices into vertex buffer
2531                 {
2532                         Vertex4RGBA* pDst = static_cast<Vertex4RGBA*>(m_vertexBufferAlloc->getHostPtr());
2533                         for (deUint32 i = 0u; i < numTopologies; ++i)
2534                         {
2535                                 deMemcpy(pDst, &pVertices[i][0], pVertices[i].size() * sizeof(Vertex4RGBA));
2536                                 pDst += pVertices[i].size();
2537                         }
2538                 }
2539                 flushMappedMemoryRange(vk, vkDevice, m_vertexBufferAlloc->getMemory(), m_vertexBufferAlloc->getOffset(), vertexBufferParams.size);
2540         }
2541
2542         // Create command pool
2543         m_cmdPool = createCommandPool(vk, vkDevice, VK_COMMAND_POOL_CREATE_TRANSIENT_BIT, queueFamilyIndex);
2544
2545         // Create command buffer
2546         {
2547                 const VkCommandBufferBeginInfo cmdBufferBeginInfo =
2548                 {
2549                         VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,    // VkStructureType                                      sType;
2550                         DE_NULL,                                                                                // const void*                                          pNext;
2551                         0u,                                                                                             // VkCommandBufferUsageFlags            flags;
2552                         (const VkCommandBufferInheritanceInfo*)DE_NULL,
2553                 };
2554
2555                 VkClearValue colorClearValue;
2556                 colorClearValue.color.float32[0] = 0.0f;
2557                 colorClearValue.color.float32[1] = 0.0f;
2558                 colorClearValue.color.float32[2] = 0.0f;
2559                 colorClearValue.color.float32[3] = 0.0f;
2560
2561                 VkClearValue depthStencilClearValue;
2562                 depthStencilClearValue.depthStencil.depth = 1.0f;
2563                 depthStencilClearValue.depthStencil.stencil = 0u;
2564
2565                 std::vector<VkClearValue> clearValues;
2566                 clearValues.push_back(colorClearValue);
2567                 if (m_renderType == RENDER_TYPE_RESOLVE)
2568                 {
2569                         clearValues.push_back(colorClearValue);
2570                 }
2571                 if (m_renderType == RENDER_TYPE_COPY_SAMPLES)
2572                 {
2573                         for (size_t i = 0; i < m_perSampleImages.size(); ++i)
2574                         {
2575                                 clearValues.push_back(colorClearValue);
2576                         }
2577                 }
2578                 if (m_useDepth || m_useStencil)
2579                 {
2580                         clearValues.push_back(depthStencilClearValue);
2581                 }
2582
2583                 const VkRenderPassBeginInfo renderPassBeginInfo =
2584                 {
2585                         VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,                               // VkStructureType              sType;
2586                         DE_NULL,                                                                                                // const void*                  pNext;
2587                         *m_renderPass,                                                                                  // VkRenderPass                 renderPass;
2588                         *m_framebuffer,                                                                                 // VkFramebuffer                framebuffer;
2589                         {
2590                                 { 0, 0 },
2591                                 { (deUint32)m_renderSize.x(), (deUint32)m_renderSize.y() }
2592                         },                                                                                                              // VkRect2D                             renderArea;
2593                         (deUint32)clearValues.size(),                                                   // deUint32                             clearValueCount;
2594                         &clearValues[0]                                                                                 // const VkClearValue*  pClearValues;
2595                 };
2596
2597                 std::vector<VkImageMemoryBarrier> imageLayoutBarriers;
2598
2599                 {
2600                         const VkImageMemoryBarrier colorImageBarrier =
2601                                 // color attachment image
2602                         {
2603                                 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,                 // VkStructureType                      sType;
2604                                 DE_NULL,                                                                                // const void*                          pNext;
2605                                 0u,                                                                                             // VkAccessFlags                        srcAccessMask;
2606                                 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,                   // VkAccessFlags                        dstAccessMask;
2607                                 VK_IMAGE_LAYOUT_UNDEFINED,                                              // VkImageLayout                        oldLayout;
2608                                 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,               // VkImageLayout                        newLayout;
2609                                 VK_QUEUE_FAMILY_IGNORED,                                                // deUint32                                     srcQueueFamilyIndex;
2610                                 VK_QUEUE_FAMILY_IGNORED,                                                // deUint32                                     dstQueueFamilyIndex;
2611                                 *m_colorImage,                                                                  // VkImage                                      image;
2612                                 { VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, 1u },  // VkImageSubresourceRange      subresourceRange;
2613                         };
2614                         imageLayoutBarriers.push_back(colorImageBarrier);
2615                 }
2616                 if (m_renderType == RENDER_TYPE_RESOLVE)
2617                 {
2618                         const VkImageMemoryBarrier resolveImageBarrier =
2619                         // resolve attachment image
2620                         {
2621                                 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,                 // VkStructureType                      sType;
2622                                 DE_NULL,                                                                                // const void*                          pNext;
2623                                 0u,                                                                                             // VkAccessFlags                        srcAccessMask;
2624                                 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,                   // VkAccessFlags                        dstAccessMask;
2625                                 VK_IMAGE_LAYOUT_UNDEFINED,                                              // VkImageLayout                        oldLayout;
2626                                 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,               // VkImageLayout                        newLayout;
2627                                 VK_QUEUE_FAMILY_IGNORED,                                                // deUint32                                     srcQueueFamilyIndex;
2628                                 VK_QUEUE_FAMILY_IGNORED,                                                // deUint32                                     dstQueueFamilyIndex;
2629                                 *m_resolveImage,                                                                // VkImage                                      image;
2630                                 { VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, 1u },  // VkImageSubresourceRange      subresourceRange;
2631                         };
2632                         imageLayoutBarriers.push_back(resolveImageBarrier);
2633                 }
2634                 if (m_renderType == RENDER_TYPE_COPY_SAMPLES)
2635                 {
2636                         for (size_t i = 0; i < m_perSampleImages.size(); ++i)
2637                         {
2638                                 const VkImageMemoryBarrier perSampleImageBarrier =
2639                                 // resolve attachment image
2640                                 {
2641                                         VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,                 // VkStructureType                      sType;
2642                                         DE_NULL,                                                                                // const void*                          pNext;
2643                                         0u,                                                                                             // VkAccessFlags                        srcAccessMask;
2644                                         VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,                   // VkAccessFlags                        dstAccessMask;
2645                                         VK_IMAGE_LAYOUT_UNDEFINED,                                              // VkImageLayout                        oldLayout;
2646                                         VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,               // VkImageLayout                        newLayout;
2647                                         VK_QUEUE_FAMILY_IGNORED,                                                // deUint32                                     srcQueueFamilyIndex;
2648                                         VK_QUEUE_FAMILY_IGNORED,                                                // deUint32                                     dstQueueFamilyIndex;
2649                                         *m_perSampleImages[i]->m_image,                                 // VkImage                                      image;
2650                                         { VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, 1u },  // VkImageSubresourceRange      subresourceRange;
2651                                 };
2652                                 imageLayoutBarriers.push_back(perSampleImageBarrier);
2653                         }
2654                 }
2655                 if (m_useDepth || m_useStencil)
2656                 {
2657                         const VkImageMemoryBarrier depthStencilImageBarrier =
2658                         // depth/stencil attachment image
2659                         {
2660                                 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,                         // VkStructureType                      sType;
2661                                 DE_NULL,                                                                                        // const void*                          pNext;
2662                                 0u,                                                                                                     // VkAccessFlags                        srcAccessMask;
2663                                 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,           // VkAccessFlags                        dstAccessMask;
2664                                 VK_IMAGE_LAYOUT_UNDEFINED,                                                      // VkImageLayout                        oldLayout;
2665                                 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,       // VkImageLayout                        newLayout;
2666                                 VK_QUEUE_FAMILY_IGNORED,                                                        // deUint32                                     srcQueueFamilyIndex;
2667                                 VK_QUEUE_FAMILY_IGNORED,                                                        // deUint32                                     dstQueueFamilyIndex;
2668                                 *m_depthStencilImage,                                                           // VkImage                                      image;
2669                                 { depthStencilAttachmentAspect, 0u, 1u, 0u, 1u },       // VkImageSubresourceRange      subresourceRange;
2670                         };
2671                         imageLayoutBarriers.push_back(depthStencilImageBarrier);
2672                 };
2673
2674                 m_cmdBuffer = allocateCommandBuffer(vk, vkDevice, *m_cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY);
2675
2676                 VK_CHECK(vk.beginCommandBuffer(*m_cmdBuffer, &cmdBufferBeginInfo));
2677
2678                 vk.cmdPipelineBarrier(*m_cmdBuffer, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, (VkDependencyFlags)0,
2679                         0u, DE_NULL, 0u, DE_NULL, (deUint32)imageLayoutBarriers.size(), &imageLayoutBarriers[0]);
2680
2681                 vk.cmdBeginRenderPass(*m_cmdBuffer, &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
2682
2683                 VkDeviceSize vertexBufferOffset = 0u;
2684
2685                 for (deUint32 i = 0u; i < numTopologies; ++i)
2686                 {
2687                         vk.cmdBindPipeline(*m_cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, **m_graphicsPipelines[i]);
2688                         vk.cmdBindVertexBuffers(*m_cmdBuffer, 0, 1, &m_vertexBuffer.get(), &vertexBufferOffset);
2689                         vk.cmdDraw(*m_cmdBuffer, (deUint32)pVertices[i].size(), 1, 0, 0);
2690
2691                         vertexBufferOffset += static_cast<VkDeviceSize>(pVertices[i].size() * sizeof(Vertex4RGBA));
2692                 }
2693
2694                 if (m_renderType == RENDER_TYPE_COPY_SAMPLES)
2695                 {
2696                         // Copy each sample id to single sampled image
2697                         for (deInt32 sampleId = 0; sampleId < (deInt32)m_perSampleImages.size(); ++sampleId)
2698                         {
2699                                 vk.cmdNextSubpass(*m_cmdBuffer, VK_SUBPASS_CONTENTS_INLINE);
2700                                 vk.cmdBindPipeline(*m_cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, **m_copySamplePipelines[sampleId]);
2701                                 vk.cmdBindDescriptorSets(*m_cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *m_copySamplePipelineLayout, 0u, 1u, &m_copySampleDesciptorSet.get(), 0u, DE_NULL);
2702                                 vk.cmdPushConstants(*m_cmdBuffer, *m_copySamplePipelineLayout, VK_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof(deInt32), &sampleId);
2703                                 vk.cmdDraw(*m_cmdBuffer, 4, 1, 0, 0);
2704                         }
2705                 }
2706
2707                 vk.cmdEndRenderPass(*m_cmdBuffer);
2708
2709                 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
2710         }
2711
2712         // Create fence
2713         m_fence = createFence(vk, vkDevice);
2714 }
2715
2716 MultisampleRenderer::~MultisampleRenderer (void)
2717 {
2718 }
2719
2720 de::MovePtr<tcu::TextureLevel> MultisampleRenderer::render (void)
2721 {
2722         const DeviceInterface&          vk                                      = m_context.getDeviceInterface();
2723         const VkDevice                          vkDevice                        = m_context.getDevice();
2724         const VkQueue                           queue                           = m_context.getUniversalQueue();
2725         const deUint32                          queueFamilyIndex        = m_context.getUniversalQueueFamilyIndex();
2726         SimpleAllocator                         allocator                       (vk, vkDevice, getPhysicalDeviceMemoryProperties(m_context.getInstanceInterface(), m_context.getPhysicalDevice()));
2727         const VkSubmitInfo                      submitInfo      =
2728         {
2729                 VK_STRUCTURE_TYPE_SUBMIT_INFO,  // VkStructureType                      sType;
2730                 DE_NULL,                                                // const void*                          pNext;
2731                 0u,                                                             // deUint32                                     waitSemaphoreCount;
2732                 DE_NULL,                                                // const VkSemaphore*           pWaitSemaphores;
2733                 (const VkPipelineStageFlags*)DE_NULL,
2734                 1u,                                                             // deUint32                                     commandBufferCount;
2735                 &m_cmdBuffer.get(),                             // const VkCommandBuffer*       pCommandBuffers;
2736                 0u,                                                             // deUint32                                     signalSemaphoreCount;
2737                 DE_NULL                                                 // const VkSemaphore*           pSignalSemaphores;
2738         };
2739
2740         VK_CHECK(vk.resetFences(vkDevice, 1, &m_fence.get()));
2741         VK_CHECK(vk.queueSubmit(queue, 1, &submitInfo, *m_fence));
2742         VK_CHECK(vk.waitForFences(vkDevice, 1, &m_fence.get(), true, ~(0ull) /* infinity*/));
2743
2744         if (m_renderType == RENDER_TYPE_RESOLVE)
2745         {
2746                 return readColorAttachment(vk, vkDevice, queue, queueFamilyIndex, allocator, *m_resolveImage, m_colorFormat, m_renderSize.cast<deUint32>());
2747         }
2748         else
2749         {
2750                 return de::MovePtr<tcu::TextureLevel>();
2751         }
2752 }
2753
2754 de::MovePtr<tcu::TextureLevel> MultisampleRenderer::getSingleSampledImage (deUint32 sampleId)
2755 {
2756         const DeviceInterface&          vk                                      = m_context.getDeviceInterface();
2757         const VkDevice                          vkDevice                        = m_context.getDevice();
2758         const VkQueue                           queue                           = m_context.getUniversalQueue();
2759         const deUint32                          queueFamilyIndex        = m_context.getUniversalQueueFamilyIndex();
2760         SimpleAllocator                         allocator                       (vk, vkDevice, getPhysicalDeviceMemoryProperties(m_context.getInstanceInterface(), m_context.getPhysicalDevice()));
2761
2762         return readColorAttachment(vk, vkDevice, queue, queueFamilyIndex, allocator, *m_perSampleImages[sampleId]->m_image, m_colorFormat, m_renderSize.cast<deUint32>());
2763 }
2764
2765 } // anonymous
2766
2767 tcu::TestCaseGroup* createMultisampleTests (tcu::TestContext& testCtx)
2768 {
2769         const VkSampleCountFlagBits samples[] =
2770         {
2771                 VK_SAMPLE_COUNT_2_BIT,
2772                 VK_SAMPLE_COUNT_4_BIT,
2773                 VK_SAMPLE_COUNT_8_BIT,
2774                 VK_SAMPLE_COUNT_16_BIT,
2775                 VK_SAMPLE_COUNT_32_BIT,
2776                 VK_SAMPLE_COUNT_64_BIT
2777         };
2778
2779         de::MovePtr<tcu::TestCaseGroup> multisampleTests (new tcu::TestCaseGroup(testCtx, "multisample", ""));
2780
2781         // Rasterization samples tests
2782         {
2783                 de::MovePtr<tcu::TestCaseGroup> rasterizationSamplesTests(new tcu::TestCaseGroup(testCtx, "raster_samples", ""));
2784
2785                 for (int samplesNdx = 0; samplesNdx < DE_LENGTH_OF_ARRAY(samples); samplesNdx++)
2786                 {
2787                         std::ostringstream caseName;
2788                         caseName << "samples_" << samples[samplesNdx];
2789
2790                         de::MovePtr<tcu::TestCaseGroup> samplesTests    (new tcu::TestCaseGroup(testCtx, caseName.str().c_str(), ""));
2791
2792                         samplesTests->addChild(new RasterizationSamplesTest(testCtx, "primitive_triangle", "",  samples[samplesNdx], GEOMETRY_TYPE_OPAQUE_TRIANGLE));
2793                         samplesTests->addChild(new RasterizationSamplesTest(testCtx, "primitive_line", "",              samples[samplesNdx], GEOMETRY_TYPE_OPAQUE_LINE));
2794                         samplesTests->addChild(new RasterizationSamplesTest(testCtx, "primitive_point", "",             samples[samplesNdx], GEOMETRY_TYPE_OPAQUE_POINT));
2795
2796                         samplesTests->addChild(new RasterizationSamplesTest(testCtx, "depth", "",                       samples[samplesNdx], GEOMETRY_TYPE_INVISIBLE_TRIANGLE, TEST_MODE_DEPTH_BIT));
2797                         samplesTests->addChild(new RasterizationSamplesTest(testCtx, "stencil", "",                     samples[samplesNdx], GEOMETRY_TYPE_INVISIBLE_TRIANGLE, TEST_MODE_STENCIL_BIT));
2798                         samplesTests->addChild(new RasterizationSamplesTest(testCtx, "depth_stencil", "",       samples[samplesNdx], GEOMETRY_TYPE_INVISIBLE_TRIANGLE, TEST_MODE_DEPTH_BIT | TEST_MODE_STENCIL_BIT));
2799
2800                         rasterizationSamplesTests->addChild(samplesTests.release());
2801                 }
2802
2803                 multisampleTests->addChild(rasterizationSamplesTests.release());
2804         }
2805
2806         // Raster samples consistency check
2807         {
2808                 de::MovePtr<tcu::TestCaseGroup> rasterSamplesConsistencyTests(new tcu::TestCaseGroup(testCtx, "raster_samples_consistency", ""));
2809
2810                 addFunctionCaseWithPrograms(rasterSamplesConsistencyTests.get(),
2811                                                                         "unique_colors_check",
2812                                                                         "",
2813                                                                         initMultisamplePrograms,
2814                                                                         testRasterSamplesConsistency,
2815                                                                         GEOMETRY_TYPE_OPAQUE_TRIANGLE);
2816
2817                 multisampleTests->addChild(rasterSamplesConsistencyTests.release());
2818         }
2819
2820         // minSampleShading tests
2821         {
2822                 struct TestConfig
2823                 {
2824                         const char*     name;
2825                         float           minSampleShading;
2826                 };
2827
2828                 const TestConfig testConfigs[] =
2829                 {
2830                         { "min_0_0",    0.0f },
2831                         { "min_0_25",   0.25f },
2832                         { "min_0_5",    0.5f },
2833                         { "min_0_75",   0.75f },
2834                         { "min_1_0",    1.0f }
2835                 };
2836
2837                 de::MovePtr<tcu::TestCaseGroup> minSampleShadingTests(new tcu::TestCaseGroup(testCtx, "min_sample_shading", ""));
2838
2839                 for (int configNdx = 0; configNdx < DE_LENGTH_OF_ARRAY(testConfigs); configNdx++)
2840                 {
2841                         const TestConfig&                               testConfig                              = testConfigs[configNdx];
2842                         de::MovePtr<tcu::TestCaseGroup> minShadingValueTests    (new tcu::TestCaseGroup(testCtx, testConfigs[configNdx].name, ""));
2843
2844                         for (int samplesNdx = 0; samplesNdx < DE_LENGTH_OF_ARRAY(samples); samplesNdx++)
2845                         {
2846                                 std::ostringstream caseName;
2847                                 caseName << "samples_" << samples[samplesNdx];
2848
2849                                 de::MovePtr<tcu::TestCaseGroup> samplesTests    (new tcu::TestCaseGroup(testCtx, caseName.str().c_str(), ""));
2850
2851                                 samplesTests->addChild(new MinSampleShadingTest(testCtx, "primitive_triangle", "", samples[samplesNdx], testConfig.minSampleShading, GEOMETRY_TYPE_OPAQUE_TRIANGLE));
2852                                 samplesTests->addChild(new MinSampleShadingTest(testCtx, "primitive_line", "", samples[samplesNdx], testConfig.minSampleShading, GEOMETRY_TYPE_OPAQUE_LINE));
2853                                 samplesTests->addChild(new MinSampleShadingTest(testCtx, "primitive_point", "", samples[samplesNdx], testConfig.minSampleShading, GEOMETRY_TYPE_OPAQUE_POINT));
2854
2855                                 minShadingValueTests->addChild(samplesTests.release());
2856                         }
2857
2858                         minSampleShadingTests->addChild(minShadingValueTests.release());
2859                 }
2860
2861                 multisampleTests->addChild(minSampleShadingTests.release());
2862         }
2863
2864         // pSampleMask tests
2865         {
2866                 struct TestConfig
2867                 {
2868                         const char*             name;
2869                         const char*             description;
2870                         VkSampleMask    sampleMask;
2871                 };
2872
2873                 const TestConfig testConfigs[] =
2874                 {
2875                         { "mask_all_on",        "All mask bits are off",                        0x0 },
2876                         { "mask_all_off",       "All mask bits are on",                         0xFFFFFFFF },
2877                         { "mask_one",           "All mask elements are 0x1",            0x1},
2878                         { "mask_random",        "All mask elements are 0xAAAAAAAA",     0xAAAAAAAA },
2879                 };
2880
2881                 de::MovePtr<tcu::TestCaseGroup> sampleMaskTests(new tcu::TestCaseGroup(testCtx, "sample_mask", ""));
2882
2883                 for (int configNdx = 0; configNdx < DE_LENGTH_OF_ARRAY(testConfigs); configNdx++)
2884                 {
2885                         const TestConfig&                               testConfig                              = testConfigs[configNdx];
2886                         de::MovePtr<tcu::TestCaseGroup> sampleMaskValueTests    (new tcu::TestCaseGroup(testCtx, testConfig.name, testConfig.description));
2887
2888                         for (int samplesNdx = 0; samplesNdx < DE_LENGTH_OF_ARRAY(samples); samplesNdx++)
2889                         {
2890                                 std::ostringstream caseName;
2891                                 caseName << "samples_" << samples[samplesNdx];
2892
2893                                 const deUint32                                  sampleMaskCount = samples[samplesNdx] / 32;
2894                                 de::MovePtr<tcu::TestCaseGroup> samplesTests    (new tcu::TestCaseGroup(testCtx, caseName.str().c_str(), ""));
2895
2896                                 std::vector<VkSampleMask> mask;
2897                                 for (deUint32 maskNdx = 0; maskNdx < sampleMaskCount; maskNdx++)
2898                                         mask.push_back(testConfig.sampleMask);
2899
2900                                 samplesTests->addChild(new SampleMaskTest(testCtx, "primitive_triangle", "", samples[samplesNdx], mask, GEOMETRY_TYPE_OPAQUE_TRIANGLE));
2901                                 samplesTests->addChild(new SampleMaskTest(testCtx, "primitive_line", "", samples[samplesNdx], mask, GEOMETRY_TYPE_OPAQUE_LINE));
2902                                 samplesTests->addChild(new SampleMaskTest(testCtx, "primitive_point", "", samples[samplesNdx], mask, GEOMETRY_TYPE_OPAQUE_POINT));
2903
2904                                 sampleMaskValueTests->addChild(samplesTests.release());
2905                         }
2906
2907                         sampleMaskTests->addChild(sampleMaskValueTests.release());
2908                 }
2909
2910                 multisampleTests->addChild(sampleMaskTests.release());
2911
2912         }
2913
2914         // AlphaToOne tests
2915         {
2916                 de::MovePtr<tcu::TestCaseGroup> alphaToOneTests(new tcu::TestCaseGroup(testCtx, "alpha_to_one", ""));
2917
2918                 for (int samplesNdx = 0; samplesNdx < DE_LENGTH_OF_ARRAY(samples); samplesNdx++)
2919                 {
2920                         std::ostringstream caseName;
2921                         caseName << "samples_" << samples[samplesNdx];
2922
2923                         alphaToOneTests->addChild(new AlphaToOneTest(testCtx, caseName.str(), "", samples[samplesNdx]));
2924                 }
2925
2926                 multisampleTests->addChild(alphaToOneTests.release());
2927         }
2928
2929         // AlphaToCoverageEnable tests
2930         {
2931                 de::MovePtr<tcu::TestCaseGroup> alphaToCoverageTests (new tcu::TestCaseGroup(testCtx, "alpha_to_coverage", ""));
2932
2933                 for (int samplesNdx = 0; samplesNdx < DE_LENGTH_OF_ARRAY(samples); samplesNdx++)
2934                 {
2935                         std::ostringstream caseName;
2936                         caseName << "samples_" << samples[samplesNdx];
2937
2938                         de::MovePtr<tcu::TestCaseGroup> samplesTests    (new tcu::TestCaseGroup(testCtx, caseName.str().c_str(), ""));
2939
2940                         samplesTests->addChild(new AlphaToCoverageTest(testCtx, "alpha_opaque", "", samples[samplesNdx], GEOMETRY_TYPE_OPAQUE_QUAD));
2941                         samplesTests->addChild(new AlphaToCoverageTest(testCtx, "alpha_translucent", "", samples[samplesNdx], GEOMETRY_TYPE_TRANSLUCENT_QUAD));
2942                         samplesTests->addChild(new AlphaToCoverageTest(testCtx, "alpha_invisible", "", samples[samplesNdx], GEOMETRY_TYPE_INVISIBLE_QUAD));
2943
2944                         alphaToCoverageTests->addChild(samplesTests.release());
2945                 }
2946                 multisampleTests->addChild(alphaToCoverageTests.release());
2947         }
2948
2949         // Sampling from a multisampled image texture (texelFetch)
2950         {
2951                 multisampleTests->addChild(createMultisampleSampledImageTests(testCtx));
2952         }
2953
2954         // Load/store on a multisampled rendered image (different kinds of access: color attachment write, storage image, etc.)
2955         {
2956                 multisampleTests->addChild(createMultisampleStorageImageTests(testCtx));
2957         }
2958
2959         // VK_EXT_sample_locations
2960         {
2961                 multisampleTests->addChild(createMultisampleSampleLocationsExtTests(testCtx));
2962         }
2963
2964         return multisampleTests.release();
2965 }
2966
2967 } // pipeline
2968 } // vkt