1 /*------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
5 * Copyright (c) 2015 The Khronos Group Inc.
6 * Copyright (c) 2015 Imagination Technologies Ltd.
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 * \brief Multisample Tests
23 *//*--------------------------------------------------------------------*/
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"
39 #include "vkRefUtil.hpp"
40 #include "tcuImageCompare.hpp"
41 #include "tcuTestLog.hpp"
42 #include "deUniquePtr.hpp"
43 #include "deSharedPtr.hpp"
44 #include "deStringUtil.hpp"
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
75 TEST_MODE_DEPTH_BIT = 1u,
76 TEST_MODE_STENCIL_BIT = 2u,
78 typedef deUint32 TestModeFlags;
82 // resolve multisample rendering to single sampled image
83 RENDER_TYPE_RESOLVE = 0u,
85 // copy samples to an array of single sampled images
86 RENDER_TYPE_COPY_SAMPLES
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);
99 class MultisampleTest : public vkt::TestCase
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) {}
111 virtual void initPrograms (SourceCollections& programCollection) const;
112 virtual TestInstance* createInstance (Context& context) const;
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;
126 class RasterizationSamplesTest : public MultisampleTest
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) {}
138 virtual TestInstance* createMultisampleTestInstance (Context& context,
139 VkPrimitiveTopology topology,
140 const std::vector<Vertex4RGBA>& vertices,
141 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
142 const VkPipelineColorBlendAttachmentState& colorBlendState) const;
144 static VkPipelineMultisampleStateCreateInfo getRasterizationSamplesStateParams (VkSampleCountFlagBits rasterizationSamples);
146 const TestModeFlags m_modeFlags;
149 class MinSampleShadingTest : public MultisampleTest
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) {}
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;
168 static VkPipelineMultisampleStateCreateInfo getMinSampleShadingStateParams (VkSampleCountFlagBits rasterizationSamples, float minSampleShading);
171 class SampleMaskTest : public MultisampleTest
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);
181 virtual ~SampleMaskTest (void) {}
184 virtual TestInstance* createMultisampleTestInstance (Context& context,
185 VkPrimitiveTopology topology,
186 const std::vector<Vertex4RGBA>& vertices,
187 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
188 const VkPipelineColorBlendAttachmentState& colorBlendState) const;
190 static VkPipelineMultisampleStateCreateInfo getSampleMaskStateParams (VkSampleCountFlagBits rasterizationSamples, const std::vector<VkSampleMask>& sampleMask);
193 class AlphaToOneTest : public MultisampleTest
196 AlphaToOneTest (tcu::TestContext& testContext,
197 const std::string& name,
198 const std::string& description,
199 VkSampleCountFlagBits rasterizationSamples);
201 virtual ~AlphaToOneTest (void) {}
204 virtual TestInstance* createMultisampleTestInstance (Context& context,
205 VkPrimitiveTopology topology,
206 const std::vector<Vertex4RGBA>& vertices,
207 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
208 const VkPipelineColorBlendAttachmentState& colorBlendState) const;
210 static VkPipelineMultisampleStateCreateInfo getAlphaToOneStateParams (VkSampleCountFlagBits rasterizationSamples);
211 static VkPipelineColorBlendAttachmentState getAlphaToOneBlendState (void);
214 class AlphaToCoverageTest : public MultisampleTest
217 AlphaToCoverageTest (tcu::TestContext& testContext,
218 const std::string& name,
219 const std::string& description,
220 VkSampleCountFlagBits rasterizationSamples,
221 GeometryType geometryType);
223 virtual ~AlphaToCoverageTest (void) {}
226 virtual TestInstance* createMultisampleTestInstance (Context& context,
227 VkPrimitiveTopology topology,
228 const std::vector<Vertex4RGBA>& vertices,
229 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
230 const VkPipelineColorBlendAttachmentState& colorBlendState) const;
232 static VkPipelineMultisampleStateCreateInfo getAlphaToCoverageStateParams (VkSampleCountFlagBits rasterizationSamples);
234 GeometryType m_geometryType;
237 typedef de::SharedPtr<Unique<VkPipeline> > VkPipelineSp;
239 class MultisampleRenderer
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);
251 MultisampleRenderer (Context& context,
252 const VkFormat colorFormat,
253 const VkFormat depthStencilFormat,
254 const tcu::IVec2& renderSize,
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);
264 virtual ~MultisampleRenderer (void);
266 de::MovePtr<tcu::TextureLevel> render (void);
267 de::MovePtr<tcu::TextureLevel> getSingleSampledImage (deUint32 sampleId);
270 void initialize (Context& context,
271 const deUint32 numTopologies,
272 const VkPrimitiveTopology* pTopology,
273 const std::vector<Vertex4RGBA>* pVertices);
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;
283 const VkPipelineMultisampleStateCreateInfo m_multisampleStateParams;
284 const VkPipelineColorBlendAttachmentState m_colorBlendState;
286 const RenderType m_renderType;
288 Move<VkImage> m_colorImage;
289 de::MovePtr<Allocation> m_colorImageAlloc;
290 Move<VkImageView> m_colorAttachmentView;
292 Move<VkImage> m_resolveImage;
293 de::MovePtr<Allocation> m_resolveImageAlloc;
294 Move<VkImageView> m_resolveAttachmentView;
296 struct PerSampleImage
298 Move<VkImage> m_image;
299 de::MovePtr<Allocation> m_imageAlloc;
300 Move<VkImageView> m_attachmentView;
302 std::vector<de::SharedPtr<PerSampleImage> > m_perSampleImages;
304 Move<VkImage> m_depthStencilImage;
305 de::MovePtr<Allocation> m_depthStencilImageAlloc;
306 Move<VkImageView> m_depthStencilAttachmentView;
308 Move<VkRenderPass> m_renderPass;
309 Move<VkFramebuffer> m_framebuffer;
311 Move<VkShaderModule> m_vertexShaderModule;
312 Move<VkShaderModule> m_fragmentShaderModule;
314 Move<VkShaderModule> m_copySampleVertexShaderModule;
315 Move<VkShaderModule> m_copySampleFragmentShaderModule;
317 Move<VkBuffer> m_vertexBuffer;
318 de::MovePtr<Allocation> m_vertexBufferAlloc;
320 Move<VkPipelineLayout> m_pipelineLayout;
321 std::vector<VkPipelineSp> m_graphicsPipelines;
323 Move<VkDescriptorSetLayout> m_copySampleDesciptorLayout;
324 Move<VkDescriptorPool> m_copySampleDesciptorPool;
325 Move<VkDescriptorSet> m_copySampleDesciptorSet;
327 Move<VkPipelineLayout> m_copySamplePipelineLayout;
328 std::vector<VkPipelineSp> m_copySamplePipelines;
330 Move<VkCommandPool> m_cmdPool;
331 Move<VkCommandBuffer> m_cmdBuffer;
333 Move<VkFence> m_fence;
336 class RasterizationSamplesInstance : public vkt::TestInstance
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) {}
347 virtual tcu::TestStatus iterate (void);
350 virtual tcu::TestStatus verifyImage (const tcu::ConstPixelBufferAccess& result);
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;
361 class MinSampleShadingInstance : public vkt::TestInstance
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) {}
371 virtual tcu::TestStatus iterate (void);
374 virtual tcu::TestStatus verifySampleShadedImage (const std::vector<tcu::TextureLevel>& testShadingImages,
375 const tcu::ConstPixelBufferAccess& noSampleshadingImage);
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;
385 class SampleMaskInstance : public vkt::TestInstance
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) {}
395 virtual tcu::TestStatus iterate (void);
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;
409 class AlphaToOneInstance : public vkt::TestInstance
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) {}
419 virtual tcu::TestStatus iterate (void);
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;
432 class AlphaToCoverageInstance : public vkt::TestInstance
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) {}
443 virtual tcu::TestStatus iterate (void);
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;
459 void initMultisamplePrograms (SourceCollections& sources, GeometryType geometryType)
461 std::ostringstream vertexSource;
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"
470 " gl_Position = position;\n"
471 " vtxColor = color;\n"
472 << (geometryType == GEOMETRY_TYPE_OPAQUE_POINT ? " gl_PointSize = 3.0f;\n"
476 static const char* fragmentSource =
478 "layout(location = 0) in highp vec4 vtxColor;\n"
479 "layout(location = 0) out highp vec4 fragColor;\n"
482 " fragColor = vtxColor;\n"
485 sources.glslSources.add("color_vert") << glu::VertexSource(vertexSource.str());
486 sources.glslSources.add("color_frag") << glu::FragmentSource(fragmentSource);
489 void initSampleShadingPrograms (SourceCollections& sources, GeometryType geometryType)
492 std::ostringstream vertexSource;
496 "layout(location = 0) in vec4 position;\n"
497 "layout(location = 1) in vec4 color;\n"
500 " gl_Position = position;\n"
501 << (geometryType == GEOMETRY_TYPE_OPAQUE_POINT ? " gl_PointSize = 3.0f;\n"
505 static const char* fragmentSource =
507 "layout(location = 0) out highp vec4 fragColor;\n"
510 " fragColor = vec4(fract(gl_FragCoord.xy), 0.0, 1.0);\n"
513 sources.glslSources.add("color_vert") << glu::VertexSource(vertexSource.str());
514 sources.glslSources.add("color_frag") << glu::FragmentSource(fragmentSource);
518 static const char* vertexSource =
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"
528 " gl_Position = positions[gl_VertexIndex];\n"
531 static const char* fragmentSource =
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"
542 " fragColor = subpassLoad(imageMS, pushConstants.sampleId);\n"
545 sources.glslSources.add("quad_vert") << glu::VertexSource(vertexSource);
546 sources.glslSources.add("copy_sample_frag") << glu::FragmentSource(fragmentSource);
550 bool isSupportedSampleCount (const InstanceInterface& instanceInterface, VkPhysicalDevice physicalDevice, VkSampleCountFlagBits rasterizationSamples)
552 VkPhysicalDeviceProperties deviceProperties;
554 instanceInterface.getPhysicalDeviceProperties(physicalDevice, &deviceProperties);
556 return !!(deviceProperties.limits.framebufferColorSampleCounts & rasterizationSamples);
559 VkPipelineColorBlendAttachmentState getDefaultColorBlendAttachmentState (void)
561 const VkPipelineColorBlendAttachmentState colorBlendState =
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
574 return colorBlendState;
577 deUint32 getUniqueColorsCount (const tcu::ConstPixelBufferAccess& image)
579 DE_ASSERT(image.getFormat().getPixelSize() == 4);
581 std::map<deUint32, deUint32> histogram; // map<pixel value, number of occurrences>
582 const deUint32 pixelCount = image.getWidth() * image.getHeight() * image.getDepth();
584 for (deUint32 pixelNdx = 0; pixelNdx < pixelCount; pixelNdx++)
586 const deUint32 pixelValue = *((const deUint32*)image.getDataPtr() + pixelNdx);
588 if (histogram.find(pixelValue) != histogram.end())
589 histogram[pixelValue]++;
591 histogram[pixelValue] = 1;
594 return (deUint32)histogram.size();
597 VkImageAspectFlags getImageAspectFlags (const VkFormat format)
599 const tcu::TextureFormat tcuFormat = mapVkFormat(format);
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;
609 std::vector<Vertex4RGBA> generateVertices (const GeometryType geometryType)
611 std::vector<Vertex4RGBA> vertices;
613 switch (geometryType)
615 case GEOMETRY_TYPE_OPAQUE_TRIANGLE:
616 case GEOMETRY_TYPE_INVISIBLE_TRIANGLE:
618 Vertex4RGBA vertexData[3] =
621 tcu::Vec4(-0.75f, 0.0f, 0.0f, 1.0f),
622 tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f)
625 tcu::Vec4(0.75f, 0.125f, 0.0f, 1.0f),
626 tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f)
629 tcu::Vec4(0.75f, -0.125f, 0.0f, 1.0f),
630 tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f)
634 if (geometryType == GEOMETRY_TYPE_INVISIBLE_TRIANGLE)
636 for (int i = 0; i < 3; i++)
637 vertexData[i].color = tcu::Vec4();
640 vertices = std::vector<Vertex4RGBA>(vertexData, vertexData + 3);
644 case GEOMETRY_TYPE_OPAQUE_LINE:
646 const Vertex4RGBA vertexData[2] =
649 tcu::Vec4(-0.75f, 0.25f, 0.0f, 1.0f),
650 tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f)
653 tcu::Vec4(0.75f, -0.25f, 0.0f, 1.0f),
654 tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f)
658 vertices = std::vector<Vertex4RGBA>(vertexData, vertexData + 2);
662 case GEOMETRY_TYPE_OPAQUE_POINT:
664 const Vertex4RGBA vertex =
666 tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f),
667 tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f)
670 vertices = std::vector<Vertex4RGBA>(1, vertex);
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:
680 Vertex4RGBA vertexData[4] =
683 tcu::Vec4(-1.0f, -1.0f, 0.0f, 1.0f),
684 tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f)
687 tcu::Vec4(1.0f, -1.0f, 0.0f, 1.0f),
688 tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f)
691 tcu::Vec4(-1.0f, 1.0f, 0.0f, 1.0f),
692 tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f)
695 tcu::Vec4(1.0f, 1.0f, 0.0f, 1.0f),
696 tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f)
700 if (geometryType == GEOMETRY_TYPE_TRANSLUCENT_QUAD)
702 for (int i = 0; i < 4; i++)
703 vertexData[i].color.w() = 0.25f;
705 else if (geometryType == GEOMETRY_TYPE_INVISIBLE_QUAD)
707 for (int i = 0; i < 4; i++)
708 vertexData[i].color.w() = 0.0f;
710 else if (geometryType == GEOMETRY_TYPE_GRADIENT_QUAD)
712 vertexData[0].color.w() = 0.0f;
713 vertexData[2].color.w() = 0.0f;
715 else if (geometryType == GEOMETRY_TYPE_OPAQUE_QUAD_NONZERO_DEPTH)
717 for (int i = 0; i < 4; i++)
718 vertexData[i].position.z() = 0.5f;
721 vertices = std::vector<Vertex4RGBA>(vertexData, vertexData + 4);
731 VkPrimitiveTopology getPrimitiveTopology (const GeometryType geometryType)
733 switch (geometryType)
735 case GEOMETRY_TYPE_OPAQUE_TRIANGLE:
736 case GEOMETRY_TYPE_INVISIBLE_TRIANGLE: return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
738 case GEOMETRY_TYPE_OPAQUE_LINE: return VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
739 case GEOMETRY_TYPE_OPAQUE_POINT: return VK_PRIMITIVE_TOPOLOGY_POINT_LIST;
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;
749 return VK_PRIMITIVE_TOPOLOGY_LAST;
753 bool isSupportedDepthStencilFormat (const InstanceInterface& vki, const VkPhysicalDevice physDevice, const VkFormat format)
755 VkFormatProperties formatProps;
756 vki.getPhysicalDeviceFormatProperties(physDevice, format, &formatProps);
757 return (formatProps.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) != 0;
760 VkFormat findSupportedDepthStencilFormat (Context& context, const bool useDepth, const bool useStencil)
762 if (useDepth && !useStencil)
763 return VK_FORMAT_D16_UNORM; // must be supported
765 const InstanceInterface& vki = context.getInstanceInterface();
766 const VkPhysicalDevice physDevice = context.getPhysicalDevice();
768 // One of these formats must be supported.
770 if (isSupportedDepthStencilFormat(vki, physDevice, VK_FORMAT_D24_UNORM_S8_UINT))
771 return VK_FORMAT_D24_UNORM_S8_UINT;
773 if (isSupportedDepthStencilFormat(vki, physDevice, VK_FORMAT_D32_SFLOAT_S8_UINT))
774 return VK_FORMAT_D32_SFLOAT_S8_UINT;
776 return VK_FORMAT_UNDEFINED;
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)
793 if (m_multisampleStateParams.pSampleMask)
795 // Copy pSampleMask to avoid dependencies with other classes
797 const deUint32 maskCount = deCeilFloatToInt32(float(m_multisampleStateParams.rasterizationSamples) / 32);
799 for (deUint32 maskNdx = 0; maskNdx < maskCount; maskNdx++)
800 m_sampleMask.push_back(m_multisampleStateParams.pSampleMask[maskNdx]);
802 m_multisampleStateParams.pSampleMask = m_sampleMask.data();
806 void MultisampleTest::initPrograms (SourceCollections& programCollection) const
808 initMultisamplePrograms(programCollection, m_geometryType);
811 TestInstance* MultisampleTest::createInstance (Context& context) const
813 return createMultisampleTestInstance(context, getPrimitiveTopology(m_geometryType), generateVertices(m_geometryType), m_multisampleStateParams, m_colorBlendState);
817 // RasterizationSamplesTest
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)
830 VkPipelineMultisampleStateCreateInfo RasterizationSamplesTest::getRasterizationSamplesStateParams (VkSampleCountFlagBits rasterizationSamples)
832 const VkPipelineMultisampleStateCreateInfo multisampleStateParams =
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;
845 return multisampleStateParams;
848 TestInstance* RasterizationSamplesTest::createMultisampleTestInstance (Context& context,
849 VkPrimitiveTopology topology,
850 const std::vector<Vertex4RGBA>& vertices,
851 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
852 const VkPipelineColorBlendAttachmentState& colorBlendState) const
854 return new RasterizationSamplesInstance(context, topology, vertices, multisampleStateParams, colorBlendState, m_modeFlags);
858 // MinSampleShadingTest
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)
870 void MinSampleShadingTest::initPrograms (SourceCollections& programCollection) const
872 initSampleShadingPrograms(programCollection, m_geometryType);
875 TestInstance* MinSampleShadingTest::createMultisampleTestInstance (Context& context,
876 VkPrimitiveTopology topology,
877 const std::vector<Vertex4RGBA>& vertices,
878 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
879 const VkPipelineColorBlendAttachmentState& colorBlendState) const
881 return new MinSampleShadingInstance(context, topology, vertices, multisampleStateParams, colorBlendState);
884 VkPipelineMultisampleStateCreateInfo MinSampleShadingTest::getMinSampleShadingStateParams (VkSampleCountFlagBits rasterizationSamples, float minSampleShading)
886 const VkPipelineMultisampleStateCreateInfo multisampleStateParams =
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;
899 return multisampleStateParams;
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)
915 TestInstance* SampleMaskTest::createMultisampleTestInstance (Context& context,
916 VkPrimitiveTopology topology,
917 const std::vector<Vertex4RGBA>& vertices,
918 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
919 const VkPipelineColorBlendAttachmentState& colorBlendState) const
921 return new SampleMaskInstance(context, topology,vertices, multisampleStateParams, colorBlendState);
924 VkPipelineMultisampleStateCreateInfo SampleMaskTest::getSampleMaskStateParams (VkSampleCountFlagBits rasterizationSamples, const std::vector<VkSampleMask>& sampleMask)
926 const VkPipelineMultisampleStateCreateInfo multisampleStateParams =
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;
939 return multisampleStateParams;
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)
953 TestInstance* AlphaToOneTest::createMultisampleTestInstance (Context& context,
954 VkPrimitiveTopology topology,
955 const std::vector<Vertex4RGBA>& vertices,
956 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
957 const VkPipelineColorBlendAttachmentState& colorBlendState) const
959 return new AlphaToOneInstance(context, topology, vertices, multisampleStateParams, colorBlendState);
962 VkPipelineMultisampleStateCreateInfo AlphaToOneTest::getAlphaToOneStateParams (VkSampleCountFlagBits rasterizationSamples)
964 const VkPipelineMultisampleStateCreateInfo multisampleStateParams =
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;
977 return multisampleStateParams;
980 VkPipelineColorBlendAttachmentState AlphaToOneTest::getAlphaToOneBlendState (void)
982 const VkPipelineColorBlendAttachmentState colorBlendState =
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
995 return colorBlendState;
999 // AlphaToCoverageTest
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)
1011 TestInstance* AlphaToCoverageTest::createMultisampleTestInstance (Context& context,
1012 VkPrimitiveTopology topology,
1013 const std::vector<Vertex4RGBA>& vertices,
1014 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
1015 const VkPipelineColorBlendAttachmentState& colorBlendState) const
1017 return new AlphaToCoverageInstance(context, topology, vertices, multisampleStateParams, colorBlendState, m_geometryType);
1020 VkPipelineMultisampleStateCreateInfo AlphaToCoverageTest::getAlphaToCoverageStateParams (VkSampleCountFlagBits rasterizationSamples)
1022 const VkPipelineMultisampleStateCreateInfo multisampleStateParams =
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;
1035 return multisampleStateParams;
1038 // RasterizationSamplesInstance
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)
1054 if (m_modeFlags != 0)
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);
1060 if (depthStencilFormat == VK_FORMAT_UNDEFINED)
1061 TCU_THROW(NotSupportedError, "Required depth/stencil format is not supported");
1063 const VkPrimitiveTopology pTopology[2] = { m_primitiveTopology, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP };
1064 const std::vector<Vertex4RGBA> pVertices[2] = { m_vertices, m_fullQuadVertices };
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));
1072 m_multisampleRenderer = de::MovePtr<MultisampleRenderer>(
1073 new MultisampleRenderer(context, m_colorFormat, m_renderSize, topology, vertices, multisampleStateParams, blendState, RENDER_TYPE_RESOLVE));
1077 tcu::TestStatus RasterizationSamplesInstance::iterate (void)
1079 de::MovePtr<tcu::TextureLevel> level(m_multisampleRenderer->render());
1080 return verifyImage(level->getAccess());
1083 tcu::TestStatus RasterizationSamplesInstance::verifyImage (const tcu::ConstPixelBufferAccess& result)
1085 // Verify range of unique pixels
1087 const deUint32 numUniqueColors = getUniqueColorsCount(result);
1088 const deUint32 minUniqueColors = 3;
1090 tcu::TestLog& log = m_context.getTestContext().getLog();
1092 log << tcu::TestLog::Message
1093 << "\nMin. unique colors expected: " << minUniqueColors << "\n"
1094 << "Unique colors found: " << numUniqueColors << "\n"
1095 << tcu::TestLog::EndMessage;
1097 if (numUniqueColors < minUniqueColors)
1098 return tcu::TestStatus::fail("Unique colors out of expected bounds");
1101 // Verify shape of the rendered primitive (fuzzy-compare)
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());
1111 if (m_primitiveTopology == VK_PRIMITIVE_TOPOLOGY_POINT_LIST)
1113 VkPhysicalDeviceProperties deviceProperties;
1115 m_context.getInstanceInterface().getPhysicalDeviceProperties(m_context.getPhysicalDevice(), &deviceProperties);
1117 // gl_PointSize is clamped to pointSizeRange
1118 renderState.point.pointSize = deFloatMin(3.0f, deviceProperties.limits.pointSizeRange[1]);
1121 if (m_modeFlags == 0)
1123 refRenderer.colorClear(tcu::Vec4(0.0f));
1124 refRenderer.draw(renderState, mapVkPrimitiveTopology(m_primitiveTopology), m_vertices);
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);
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");
1137 return tcu::TestStatus::pass("Primitive rendered, unique colors within expected bounds");
1141 // MinSampleShadingInstance
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)
1156 VkPhysicalDeviceFeatures deviceFeatures;
1158 m_context.getInstanceInterface().getPhysicalDeviceFeatures(m_context.getPhysicalDevice(), &deviceFeatures);
1160 if (!deviceFeatures.sampleRateShading)
1161 throw tcu::NotSupportedError("Sample shading is not supported");
1164 tcu::TestStatus MinSampleShadingInstance::iterate (void)
1166 de::MovePtr<tcu::TextureLevel> noSampleshadingImage;
1167 std::vector<tcu::TextureLevel> sampleShadedImages;
1169 // Render and resolve without sample shading
1171 VkPipelineMultisampleStateCreateInfo multisampleStateParms = m_multisampleStateParams;
1172 multisampleStateParms.sampleShadingEnable = VK_FALSE;
1173 multisampleStateParms.minSampleShading = 0.0;
1175 MultisampleRenderer renderer (m_context, m_colorFormat, m_renderSize, m_primitiveTopology, m_vertices, multisampleStateParms, m_colorBlendState, RENDER_TYPE_RESOLVE);
1176 noSampleshadingImage = renderer.render();
1179 // Render with test minSampleShading and collect per-sample images
1181 MultisampleRenderer renderer (m_context, m_colorFormat, m_renderSize, m_primitiveTopology, m_vertices, m_multisampleStateParams, m_colorBlendState, RENDER_TYPE_COPY_SAMPLES);
1184 sampleShadedImages.resize(m_multisampleStateParams.rasterizationSamples);
1185 for (deUint32 sampleId = 0; sampleId < sampleShadedImages.size(); sampleId++)
1187 sampleShadedImages[sampleId] = *renderer.getSingleSampledImage(sampleId);
1193 tcu::TestLog& testLog = m_context.getTestContext().getLog();
1195 testLog << tcu::TestLog::ImageSet("Images", "Images")
1196 << tcu::TestLog::Image("noSampleshadingImage", "Image rendered without sample shading", noSampleshadingImage->getAccess());
1198 for (deUint32 sampleId = 0; sampleId < sampleShadedImages.size(); sampleId++)
1200 testLog << tcu::TestLog::Image("sampleShadedImage", "One sample of sample shaded image", sampleShadedImages[sampleId].getAccess());
1202 testLog << tcu::TestLog::EndImageSet;
1205 return verifySampleShadedImage(sampleShadedImages, noSampleshadingImage->getAccess());
1208 tcu::TestStatus MinSampleShadingInstance::verifySampleShadedImage (const std::vector<tcu::TextureLevel>& sampleShadedImages, const tcu::ConstPixelBufferAccess& noSampleshadingImage)
1210 const deUint32 pixelCount = noSampleshadingImage.getWidth() * noSampleshadingImage.getHeight() * noSampleshadingImage.getDepth();
1212 bool anyPixelCovered = false;
1214 for (deUint32 pixelNdx = 0; pixelNdx < pixelCount; pixelNdx++)
1216 const deUint32 noSampleShadingValue = *((const deUint32*)noSampleshadingImage.getDataPtr() + pixelNdx);
1218 if (noSampleShadingValue == 0)
1220 // non-covered pixel, continue
1225 anyPixelCovered = true;
1228 int numNotCoveredSamples = 0;
1230 std::map<deUint32, deUint32> histogram; // map<pixel value, number of occurrences>
1232 // Collect histogram of occurrences or each pixel across all samples
1233 for (size_t i = 0; i < sampleShadedImages.size(); ++i)
1235 const deUint32 sampleShadedValue = *((const deUint32*)sampleShadedImages[i].getAccess().getDataPtr() + pixelNdx);
1237 if (sampleShadedValue == 0)
1239 numNotCoveredSamples++;
1243 if (histogram.find(sampleShadedValue) != histogram.end())
1244 histogram[sampleShadedValue]++;
1246 histogram[sampleShadedValue] = 1;
1249 if (numNotCoveredSamples == static_cast<int>(sampleShadedImages.size()))
1251 return tcu::TestStatus::fail("Got uncovered pixel, where covered samples were expected");
1254 const int uniqueColorsCount = (int)histogram.size();
1255 const int expectedUniqueSamplesCount = static_cast<int>(m_multisampleStateParams.minSampleShading * static_cast<float>(sampleShadedImages.size()) + 0.5f);
1257 if (uniqueColorsCount + numNotCoveredSamples < expectedUniqueSamplesCount)
1259 return tcu::TestStatus::fail("Got less unique colors than requested through minSampleShading");
1263 if (!anyPixelCovered)
1265 return tcu::TestStatus::fail("Did not get any covered pixel, cannot test minSampleShading");
1268 return tcu::TestStatus::pass("Got proper count of unique colors");
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)
1286 tcu::TestStatus SampleMaskInstance::iterate (void)
1288 de::MovePtr<tcu::TextureLevel> testSampleMaskImage;
1289 de::MovePtr<tcu::TextureLevel> minSampleMaskImage;
1290 de::MovePtr<tcu::TextureLevel> maxSampleMaskImage;
1292 // Render with test flags
1294 MultisampleRenderer renderer (m_context, m_colorFormat, m_renderSize, m_primitiveTopology, m_vertices, m_multisampleStateParams, m_colorBlendState, RENDER_TYPE_RESOLVE);
1295 testSampleMaskImage = renderer.render();
1298 // Render with all flags off
1300 VkPipelineMultisampleStateCreateInfo multisampleParams = m_multisampleStateParams;
1301 const std::vector<VkSampleMask> sampleMask (multisampleParams.rasterizationSamples / 32, (VkSampleMask)0);
1303 multisampleParams.pSampleMask = sampleMask.data();
1305 MultisampleRenderer renderer (m_context, m_colorFormat, m_renderSize, m_primitiveTopology, m_vertices, multisampleParams, m_colorBlendState, RENDER_TYPE_RESOLVE);
1306 minSampleMaskImage = renderer.render();
1309 // Render with all flags on
1311 VkPipelineMultisampleStateCreateInfo multisampleParams = m_multisampleStateParams;
1312 const std::vector<VkSampleMask> sampleMask (multisampleParams.rasterizationSamples / 32, ~((VkSampleMask)0));
1314 multisampleParams.pSampleMask = sampleMask.data();
1316 MultisampleRenderer renderer (m_context, m_colorFormat, m_renderSize, m_primitiveTopology, m_vertices, multisampleParams, m_colorBlendState, RENDER_TYPE_RESOLVE);
1317 maxSampleMaskImage = renderer.render();
1320 return verifyImage(testSampleMaskImage->getAccess(), minSampleMaskImage->getAccess(), maxSampleMaskImage->getAccess());
1323 tcu::TestStatus SampleMaskInstance::verifyImage (const tcu::ConstPixelBufferAccess& testSampleMaskImage,
1324 const tcu::ConstPixelBufferAccess& minSampleMaskImage,
1325 const tcu::ConstPixelBufferAccess& maxSampleMaskImage)
1327 const deUint32 testColorCount = getUniqueColorsCount(testSampleMaskImage);
1328 const deUint32 minColorCount = getUniqueColorsCount(minSampleMaskImage);
1329 const deUint32 maxColorCount = getUniqueColorsCount(maxSampleMaskImage);
1331 tcu::TestLog& log = m_context.getTestContext().getLog();
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;
1339 if (minColorCount > testColorCount || testColorCount > maxColorCount)
1340 return tcu::TestStatus::fail("Unique colors out of expected bounds");
1342 return tcu::TestStatus::pass("Unique colors within expected bounds");
1345 tcu::TestStatus testRasterSamplesConsistency (Context& context, GeometryType geometryType)
1347 // Use triangle only.
1348 DE_UNREF(geometryType);
1350 const VkSampleCountFlagBits samples[] =
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
1361 const Vertex4RGBA vertexData[3] =
1364 tcu::Vec4(-0.75f, 0.0f, 0.0f, 1.0f),
1365 tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f)
1368 tcu::Vec4(0.75f, 0.125f, 0.0f, 1.0f),
1369 tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f)
1372 tcu::Vec4(0.75f, -0.125f, 0.0f, 1.0f),
1373 tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f)
1377 const std::vector<Vertex4RGBA> vertices (vertexData, vertexData + 3);
1378 deUint32 prevUniqueColors = 2;
1379 int renderCount = 0;
1381 // Do not render with 1 sample (start with samplesNdx = 1).
1382 for (int samplesNdx = 1; samplesNdx < DE_LENGTH_OF_ARRAY(samples); samplesNdx++)
1384 if (!isSupportedSampleCount(context.getInstanceInterface(), context.getPhysicalDevice(), samples[samplesNdx]))
1387 const VkPipelineMultisampleStateCreateInfo multisampleStateParams =
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;
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());
1406 if (prevUniqueColors > uniqueColors)
1408 std::ostringstream message;
1410 message << "More unique colors generated with " << samples[samplesNdx - 1] << " than with " << samples[samplesNdx];
1411 return tcu::TestStatus::fail(message.str());
1414 prevUniqueColors = uniqueColors;
1417 if (renderCount == 0)
1418 throw tcu::NotSupportedError("Multisampling is unsupported");
1420 return tcu::TestStatus::pass("Number of unique colors increases as the sample count increases");
1424 // AlphaToOneInstance
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)
1439 VkPhysicalDeviceFeatures deviceFeatures;
1441 context.getInstanceInterface().getPhysicalDeviceFeatures(context.getPhysicalDevice(), &deviceFeatures);
1443 if (!deviceFeatures.alphaToOne)
1444 throw tcu::NotSupportedError("Alpha-to-one is not supported");
1447 tcu::TestStatus AlphaToOneInstance::iterate (void)
1449 DE_ASSERT(m_multisampleStateParams.alphaToOneEnable);
1450 DE_ASSERT(m_colorBlendState.blendEnable);
1452 de::MovePtr<tcu::TextureLevel> alphaOneImage;
1453 de::MovePtr<tcu::TextureLevel> noAlphaOneImage;
1455 // Render with blend enabled and alpha to one on
1457 MultisampleRenderer renderer (m_context, m_colorFormat, m_renderSize, m_primitiveTopology, m_vertices, m_multisampleStateParams, m_colorBlendState, RENDER_TYPE_RESOLVE);
1458 alphaOneImage = renderer.render();
1461 // Render with blend enabled and alpha to one off
1463 VkPipelineMultisampleStateCreateInfo multisampleParams = m_multisampleStateParams;
1464 multisampleParams.alphaToOneEnable = false;
1466 MultisampleRenderer renderer (m_context, m_colorFormat, m_renderSize, m_primitiveTopology, m_vertices, multisampleParams, m_colorBlendState, RENDER_TYPE_RESOLVE);
1467 noAlphaOneImage = renderer.render();
1470 return verifyImage(alphaOneImage->getAccess(), noAlphaOneImage->getAccess());
1473 tcu::TestStatus AlphaToOneInstance::verifyImage (const tcu::ConstPixelBufferAccess& alphaOneImage,
1474 const tcu::ConstPixelBufferAccess& noAlphaOneImage)
1476 for (int y = 0; y < m_renderSize.y(); y++)
1478 for (int x = 0; x < m_renderSize.x(); x++)
1480 if (!tcu::boolAll(tcu::greaterThanEqual(alphaOneImage.getPixel(x, y), noAlphaOneImage.getPixel(x, y))))
1482 std::ostringstream message;
1483 message << "Unsatisfied condition: " << alphaOneImage.getPixel(x, y) << " >= " << noAlphaOneImage.getPixel(x, y);
1484 return tcu::TestStatus::fail(message.str());
1489 return tcu::TestStatus::pass("Image rendered with alpha-to-one contains pixels of image rendered with no alpha-to-one");
1493 // AlphaToCoverageInstance
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)
1512 tcu::TestStatus AlphaToCoverageInstance::iterate (void)
1514 DE_ASSERT(m_multisampleStateParams.alphaToCoverageEnable);
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);
1519 result = renderer.render();
1521 return verifyImage(result->getAccess());
1524 tcu::TestStatus AlphaToCoverageInstance::verifyImage (const tcu::ConstPixelBufferAccess& result)
1526 float maxColorValue;
1528 switch (m_geometryType)
1530 case GEOMETRY_TYPE_OPAQUE_QUAD:
1531 maxColorValue = 1.01f;
1534 case GEOMETRY_TYPE_TRANSLUCENT_QUAD:
1535 maxColorValue = 0.52f;
1538 case GEOMETRY_TYPE_INVISIBLE_QUAD:
1539 maxColorValue = 0.01f;
1543 maxColorValue = 0.0f;
1547 for (int y = 0; y < m_renderSize.y(); y++)
1549 for (int x = 0; x < m_renderSize.x(); x++)
1551 if (result.getPixel(x, y).x() > maxColorValue)
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());
1560 return tcu::TestStatus::pass("Image matches reference value");
1564 // MultisampleRenderer
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)
1584 initialize(context, 1u, &topology, &vertices);
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)
1609 initialize(context, numTopologies, pTopology, pVertices);
1612 void MultisampleRenderer::initialize (Context& context,
1613 const deUint32 numTopologies,
1614 const VkPrimitiveTopology* pTopology,
1615 const std::vector<Vertex4RGBA>* pVertices)
1617 if (!isSupportedSampleCount(context.getInstanceInterface(), context.getPhysicalDevice(), m_multisampleStateParams.rasterizationSamples))
1618 throw tcu::NotSupportedError("Unsupported number of rasterization samples");
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 };
1626 // Create color image
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);
1632 const VkImageCreateInfo colorImageParams =
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;
1651 m_colorImage = createImage(vk, vkDevice, &colorImageParams);
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()));
1658 // Create resolve image
1659 if (m_renderType == RENDER_TYPE_RESOLVE)
1661 const VkImageCreateInfo resolveImageParams =
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;
1681 m_resolveImage = createImage(vk, vkDevice, &resolveImageParams);
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()));
1687 // Create resolve attachment view
1689 const VkImageViewCreateInfo resolveAttachmentViewParams =
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;
1701 m_resolveAttachmentView = createImageView(vk, vkDevice, &resolveAttachmentViewParams);
1705 // Create per-sample output images
1706 if (m_renderType == RENDER_TYPE_COPY_SAMPLES)
1708 const VkImageCreateInfo perSampleImageParams =
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;
1728 m_perSampleImages.resize(static_cast<size_t>(m_multisampleStateParams.rasterizationSamples));
1730 for (size_t i = 0; i < m_perSampleImages.size(); ++i)
1732 m_perSampleImages[i] = de::SharedPtr<PerSampleImage>(new PerSampleImage);
1733 PerSampleImage& image = *m_perSampleImages[i];
1735 image.m_image = createImage(vk, vkDevice, &perSampleImageParams);
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()));
1741 // Create per-sample attachment view
1743 const VkImageViewCreateInfo perSampleAttachmentViewParams =
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;
1755 image.m_attachmentView = createImageView(vk, vkDevice, &perSampleAttachmentViewParams);
1760 // Create a depth/stencil image
1761 if (m_useDepth || m_useStencil)
1763 const VkImageCreateInfo depthStencilImageParams =
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;
1782 m_depthStencilImage = createImage(vk, vkDevice, &depthStencilImageParams);
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()));
1789 // Create color attachment view
1791 const VkImageViewCreateInfo colorAttachmentViewParams =
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;
1803 m_colorAttachmentView = createImageView(vk, vkDevice, &colorAttachmentViewParams);
1806 VkImageAspectFlags depthStencilAttachmentAspect = (VkImageAspectFlagBits)0;
1808 // Create depth/stencil attachment view
1809 if (m_useDepth || m_useStencil)
1811 depthStencilAttachmentAspect = getImageAspectFlags(m_depthStencilFormat);
1813 const VkImageViewCreateInfo depthStencilAttachmentViewParams =
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;
1825 m_depthStencilAttachmentView = createImageView(vk, vkDevice, &depthStencilAttachmentViewParams);
1828 // Create render pass
1830 std::vector<VkAttachmentDescription> attachmentDescriptions;
1832 const VkAttachmentDescription colorAttachmentDescription =
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;
1844 attachmentDescriptions.push_back(colorAttachmentDescription);
1847 deUint32 resolveAttachmentIndex = VK_ATTACHMENT_UNUSED;
1849 if (m_renderType == RENDER_TYPE_RESOLVE)
1851 resolveAttachmentIndex = static_cast<deUint32>(attachmentDescriptions.size());
1853 const VkAttachmentDescription resolveAttachmentDescription =
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;
1865 attachmentDescriptions.push_back(resolveAttachmentDescription);
1868 deUint32 perSampleAttachmentIndex = VK_ATTACHMENT_UNUSED;
1870 if (m_renderType == RENDER_TYPE_COPY_SAMPLES)
1872 perSampleAttachmentIndex = static_cast<deUint32>(attachmentDescriptions.size());
1874 const VkAttachmentDescription perSampleAttachmentDescription =
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;
1887 for (size_t i = 0; i < m_perSampleImages.size(); ++i)
1889 attachmentDescriptions.push_back(perSampleAttachmentDescription);
1893 deUint32 depthStencilAttachmentIndex = VK_ATTACHMENT_UNUSED;
1895 if (m_useDepth || m_useStencil)
1897 depthStencilAttachmentIndex = static_cast<deUint32>(attachmentDescriptions.size());
1899 const VkAttachmentDescription depthStencilAttachmentDescription =
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;
1911 attachmentDescriptions.push_back(depthStencilAttachmentDescription);
1914 const VkAttachmentReference colorAttachmentReference =
1916 0u, // deUint32 attachment;
1917 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL // VkImageLayout layout;
1920 const VkAttachmentReference inputAttachmentReference =
1922 0u, // deUint32 attachment;
1923 VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL // VkImageLayout layout;
1926 const VkAttachmentReference resolveAttachmentReference =
1928 resolveAttachmentIndex, // deUint32 attachment;
1929 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL // VkImageLayout layout;
1932 std::vector<VkAttachmentReference> perSampleAttachmentReferences(m_perSampleImages.size());
1933 if (m_renderType == RENDER_TYPE_COPY_SAMPLES)
1935 for (size_t i = 0; i < m_perSampleImages.size(); ++i)
1937 const VkAttachmentReference perSampleAttachmentReference =
1939 perSampleAttachmentIndex + static_cast<deUint32>(i), // deUint32 attachment;
1940 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL // VkImageLayout layout;
1942 perSampleAttachmentReferences[i] = perSampleAttachmentReference;
1946 const VkAttachmentReference depthStencilAttachmentReference =
1948 depthStencilAttachmentIndex, // deUint32 attachment;
1949 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL // VkImageLayout layout;
1952 std::vector<VkSubpassDescription> subpassDescriptions;
1953 std::vector<VkSubpassDependency> subpassDependencies;
1956 const VkSubpassDescription renderSubpassDescription =
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;
1969 subpassDescriptions.push_back(renderSubpassDescription);
1972 if (m_renderType == RENDER_TYPE_COPY_SAMPLES)
1975 for (size_t i = 0; i < m_perSampleImages.size(); ++i)
1977 const VkSubpassDescription copySampleSubpassDescription =
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;
1990 subpassDescriptions.push_back(copySampleSubpassDescription);
1992 const VkSubpassDependency copySampleSubpassDependency =
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
2002 subpassDependencies.push_back(copySampleSubpassDependency);
2006 const VkRenderPassCreateInfo renderPassParams =
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
2019 m_renderPass = createRenderPass(vk, vkDevice, &renderPassParams);
2022 // Create framebuffer
2024 std::vector<VkImageView> attachments;
2025 attachments.push_back(*m_colorAttachmentView);
2026 if (m_renderType == RENDER_TYPE_RESOLVE)
2028 attachments.push_back(*m_resolveAttachmentView);
2030 if (m_renderType == RENDER_TYPE_COPY_SAMPLES)
2032 for (size_t i = 0; i < m_perSampleImages.size(); ++i)
2034 attachments.push_back(*m_perSampleImages[i]->m_attachmentView);
2038 if (m_useDepth || m_useStencil)
2040 attachments.push_back(*m_depthStencilAttachmentView);
2043 const VkFramebufferCreateInfo framebufferParams =
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;
2056 m_framebuffer = createFramebuffer(vk, vkDevice, &framebufferParams);
2059 // Create pipeline layout
2061 const VkPipelineLayoutCreateInfo pipelineLayoutParams =
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;
2072 m_pipelineLayout = createPipelineLayout(vk, vkDevice, &pipelineLayoutParams);
2074 if (m_renderType == RENDER_TYPE_COPY_SAMPLES)
2077 // Create descriptor set layout
2078 const VkDescriptorSetLayoutBinding layoutBinding =
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;
2087 const VkDescriptorSetLayoutCreateInfo descriptorSetLayoutParams =
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
2095 m_copySampleDesciptorLayout = createDescriptorSetLayout(vk, vkDevice, &descriptorSetLayoutParams);
2097 // Create pipeline layout
2099 const VkPushConstantRange pushConstantRange =
2101 VK_SHADER_STAGE_FRAGMENT_BIT, // VkShaderStageFlags stageFlags;
2102 0u, // deUint32 offset;
2103 sizeof(deInt32) // deUint32 size;
2105 const VkPipelineLayoutCreateInfo copySamplePipelineLayoutParams =
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;
2115 m_copySamplePipelineLayout = createPipelineLayout(vk, vkDevice, ©SamplePipelineLayoutParams);
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);
2122 if (m_renderType == RENDER_TYPE_COPY_SAMPLES)
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);
2130 const VkPipelineShaderStageCreateInfo shaderStageParams[2] =
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;
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;
2152 const VkVertexInputBindingDescription vertexInputBindingDescription =
2154 0u, // deUint32 binding;
2155 sizeof(Vertex4RGBA), // deUint32 stride;
2156 VK_VERTEX_INPUT_RATE_VERTEX // VkVertexInputRate inputRate;
2159 const VkVertexInputAttributeDescription vertexInputAttributeDescriptions[2] =
2162 0u, // deUint32 location;
2163 0u, // deUint32 binding;
2164 VK_FORMAT_R32G32B32A32_SFLOAT, // VkFormat format;
2165 0u // deUint32 offset;
2168 1u, // deUint32 location;
2169 0u, // deUint32 binding;
2170 VK_FORMAT_R32G32B32A32_SFLOAT, // VkFormat format;
2171 DE_OFFSET_OF(Vertex4RGBA, color), // deUint32 offset;
2175 const VkPipelineVertexInputStateCreateInfo vertexInputStateParams =
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;
2186 // Topology is set before the pipeline creation.
2187 VkPipelineInputAssemblyStateCreateInfo inputAssemblyStateParams =
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;
2196 const VkViewport viewport =
2200 (float)m_renderSize.x(), // float width;
2201 (float)m_renderSize.y(), // float height;
2202 0.0f, // float minDepth;
2203 1.0f // float maxDepth;
2206 const VkRect2D scissor =
2208 { 0, 0 }, // VkOffset2D offset;
2209 { (deUint32)m_renderSize.x(), (deUint32)m_renderSize.y() } // VkExtent2D extent;
2212 const VkPipelineViewportStateCreateInfo viewportStateParams =
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;
2223 const VkPipelineRasterizationStateCreateInfo rasterStateParams =
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;
2240 const VkPipelineColorBlendStateCreateInfo colorBlendStateParams =
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];
2252 const VkStencilOpState stencilOpState =
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;
2263 const VkPipelineDepthStencilStateCreateInfo depthStencilStateParams =
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;
2279 const VkGraphicsPipelineCreateInfo graphicsPipelineParams =
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;
2302 for (deUint32 i = 0u; i < numTopologies; ++i)
2304 inputAssemblyStateParams.topology = pTopology[i];
2305 m_graphicsPipelines.push_back(VkPipelineSp(new Unique<VkPipeline>(createGraphicsPipeline(vk, vkDevice, DE_NULL, &graphicsPipelineParams))));
2309 if (m_renderType == RENDER_TYPE_COPY_SAMPLES)
2311 // Create pipelines for copying samples to single sampled images
2313 const VkPipelineShaderStageCreateInfo shaderStageParams[2] =
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;
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;
2335 const VkPipelineVertexInputStateCreateInfo vertexInputStateParams =
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;
2346 // Topology is set before the pipeline creation.
2347 VkPipelineInputAssemblyStateCreateInfo inputAssemblyStateParams =
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;
2356 const VkViewport viewport =
2360 (float)m_renderSize.x(), // float width;
2361 (float)m_renderSize.y(), // float height;
2362 0.0f, // float minDepth;
2363 1.0f // float maxDepth;
2366 const VkRect2D scissor =
2368 { 0, 0 }, // VkOffset2D offset;
2369 { (deUint32)m_renderSize.x(), (deUint32)m_renderSize.y() } // VkExtent2D extent;
2372 const VkPipelineViewportStateCreateInfo viewportStateParams =
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;
2383 const VkPipelineRasterizationStateCreateInfo rasterStateParams =
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;
2400 const VkPipelineColorBlendStateCreateInfo colorBlendStateParams =
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];
2412 const VkPipelineMultisampleStateCreateInfo multisampleStateParams =
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
2425 const VkGraphicsPipelineCreateInfo graphicsPipelineTemplate =
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;
2448 for (size_t i = 0; i < m_perSampleImages.size(); ++i)
2450 VkGraphicsPipelineCreateInfo graphicsPipelineParams = graphicsPipelineTemplate;
2452 // Pipeline is to be used in subpasses subsequent to sample-shading subpass
2453 graphicsPipelineParams.subpass = 1u + (deUint32)i;
2455 m_copySamplePipelines.push_back(VkPipelineSp(new Unique<VkPipeline>(createGraphicsPipeline(vk, vkDevice, DE_NULL, &graphicsPipelineParams))));
2460 const VkDescriptorPoolSize descriptorPoolSize =
2462 VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, // VkDescriptorType type;
2463 1u // deUint32 descriptorCount;
2466 const VkDescriptorPoolCreateInfo descriptorPoolCreateInfo =
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
2476 m_copySampleDesciptorPool = createDescriptorPool(vk, vkDevice, &descriptorPoolCreateInfo);
2478 const VkDescriptorSetAllocateInfo descriptorSetAllocateInfo =
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
2487 m_copySampleDesciptorSet = allocateDescriptorSet(vk, vkDevice, &descriptorSetAllocateInfo);
2489 const VkDescriptorImageInfo imageInfo =
2492 *m_colorAttachmentView,
2493 VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
2495 const VkWriteDescriptorSet descriptorWrite =
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;
2508 vk.updateDescriptorSets(vkDevice, 1u, &descriptorWrite, 0u, DE_NULL);
2511 // Create vertex buffer
2513 const VkBufferCreateInfo vertexBufferParams =
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;
2525 m_vertexBuffer = createBuffer(vk, vkDevice, &vertexBufferParams);
2526 m_vertexBufferAlloc = memAlloc.allocate(getBufferMemoryRequirements(vk, vkDevice, *m_vertexBuffer), MemoryRequirement::HostVisible);
2528 VK_CHECK(vk.bindBufferMemory(vkDevice, *m_vertexBuffer, m_vertexBufferAlloc->getMemory(), m_vertexBufferAlloc->getOffset()));
2530 // Load vertices into vertex buffer
2532 Vertex4RGBA* pDst = static_cast<Vertex4RGBA*>(m_vertexBufferAlloc->getHostPtr());
2533 for (deUint32 i = 0u; i < numTopologies; ++i)
2535 deMemcpy(pDst, &pVertices[i][0], pVertices[i].size() * sizeof(Vertex4RGBA));
2536 pDst += pVertices[i].size();
2539 flushMappedMemoryRange(vk, vkDevice, m_vertexBufferAlloc->getMemory(), m_vertexBufferAlloc->getOffset(), vertexBufferParams.size);
2542 // Create command pool
2543 m_cmdPool = createCommandPool(vk, vkDevice, VK_COMMAND_POOL_CREATE_TRANSIENT_BIT, queueFamilyIndex);
2545 // Create command buffer
2547 const VkCommandBufferBeginInfo cmdBufferBeginInfo =
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,
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;
2561 VkClearValue depthStencilClearValue;
2562 depthStencilClearValue.depthStencil.depth = 1.0f;
2563 depthStencilClearValue.depthStencil.stencil = 0u;
2565 std::vector<VkClearValue> clearValues;
2566 clearValues.push_back(colorClearValue);
2567 if (m_renderType == RENDER_TYPE_RESOLVE)
2569 clearValues.push_back(colorClearValue);
2571 if (m_renderType == RENDER_TYPE_COPY_SAMPLES)
2573 for (size_t i = 0; i < m_perSampleImages.size(); ++i)
2575 clearValues.push_back(colorClearValue);
2578 if (m_useDepth || m_useStencil)
2580 clearValues.push_back(depthStencilClearValue);
2583 const VkRenderPassBeginInfo renderPassBeginInfo =
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;
2591 { (deUint32)m_renderSize.x(), (deUint32)m_renderSize.y() }
2592 }, // VkRect2D renderArea;
2593 (deUint32)clearValues.size(), // deUint32 clearValueCount;
2594 &clearValues[0] // const VkClearValue* pClearValues;
2597 std::vector<VkImageMemoryBarrier> imageLayoutBarriers;
2600 const VkImageMemoryBarrier colorImageBarrier =
2601 // color attachment image
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;
2614 imageLayoutBarriers.push_back(colorImageBarrier);
2616 if (m_renderType == RENDER_TYPE_RESOLVE)
2618 const VkImageMemoryBarrier resolveImageBarrier =
2619 // resolve attachment image
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;
2632 imageLayoutBarriers.push_back(resolveImageBarrier);
2634 if (m_renderType == RENDER_TYPE_COPY_SAMPLES)
2636 for (size_t i = 0; i < m_perSampleImages.size(); ++i)
2638 const VkImageMemoryBarrier perSampleImageBarrier =
2639 // resolve attachment image
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;
2652 imageLayoutBarriers.push_back(perSampleImageBarrier);
2655 if (m_useDepth || m_useStencil)
2657 const VkImageMemoryBarrier depthStencilImageBarrier =
2658 // depth/stencil attachment image
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;
2671 imageLayoutBarriers.push_back(depthStencilImageBarrier);
2674 m_cmdBuffer = allocateCommandBuffer(vk, vkDevice, *m_cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY);
2676 VK_CHECK(vk.beginCommandBuffer(*m_cmdBuffer, &cmdBufferBeginInfo));
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]);
2681 vk.cmdBeginRenderPass(*m_cmdBuffer, &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
2683 VkDeviceSize vertexBufferOffset = 0u;
2685 for (deUint32 i = 0u; i < numTopologies; ++i)
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);
2691 vertexBufferOffset += static_cast<VkDeviceSize>(pVertices[i].size() * sizeof(Vertex4RGBA));
2694 if (m_renderType == RENDER_TYPE_COPY_SAMPLES)
2696 // Copy each sample id to single sampled image
2697 for (deInt32 sampleId = 0; sampleId < (deInt32)m_perSampleImages.size(); ++sampleId)
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);
2707 vk.cmdEndRenderPass(*m_cmdBuffer);
2709 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
2713 m_fence = createFence(vk, vkDevice);
2716 MultisampleRenderer::~MultisampleRenderer (void)
2720 de::MovePtr<tcu::TextureLevel> MultisampleRenderer::render (void)
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 =
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;
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*/));
2744 if (m_renderType == RENDER_TYPE_RESOLVE)
2746 return readColorAttachment(vk, vkDevice, queue, queueFamilyIndex, allocator, *m_resolveImage, m_colorFormat, m_renderSize.cast<deUint32>());
2750 return de::MovePtr<tcu::TextureLevel>();
2754 de::MovePtr<tcu::TextureLevel> MultisampleRenderer::getSingleSampledImage (deUint32 sampleId)
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()));
2762 return readColorAttachment(vk, vkDevice, queue, queueFamilyIndex, allocator, *m_perSampleImages[sampleId]->m_image, m_colorFormat, m_renderSize.cast<deUint32>());
2767 tcu::TestCaseGroup* createMultisampleTests (tcu::TestContext& testCtx)
2769 const VkSampleCountFlagBits samples[] =
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
2779 de::MovePtr<tcu::TestCaseGroup> multisampleTests (new tcu::TestCaseGroup(testCtx, "multisample", ""));
2781 // Rasterization samples tests
2783 de::MovePtr<tcu::TestCaseGroup> rasterizationSamplesTests(new tcu::TestCaseGroup(testCtx, "raster_samples", ""));
2785 for (int samplesNdx = 0; samplesNdx < DE_LENGTH_OF_ARRAY(samples); samplesNdx++)
2787 std::ostringstream caseName;
2788 caseName << "samples_" << samples[samplesNdx];
2790 de::MovePtr<tcu::TestCaseGroup> samplesTests (new tcu::TestCaseGroup(testCtx, caseName.str().c_str(), ""));
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));
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));
2800 rasterizationSamplesTests->addChild(samplesTests.release());
2803 multisampleTests->addChild(rasterizationSamplesTests.release());
2806 // Raster samples consistency check
2808 de::MovePtr<tcu::TestCaseGroup> rasterSamplesConsistencyTests(new tcu::TestCaseGroup(testCtx, "raster_samples_consistency", ""));
2810 addFunctionCaseWithPrograms(rasterSamplesConsistencyTests.get(),
2811 "unique_colors_check",
2813 initMultisamplePrograms,
2814 testRasterSamplesConsistency,
2815 GEOMETRY_TYPE_OPAQUE_TRIANGLE);
2817 multisampleTests->addChild(rasterSamplesConsistencyTests.release());
2820 // minSampleShading tests
2825 float minSampleShading;
2828 const TestConfig testConfigs[] =
2830 { "min_0_0", 0.0f },
2831 { "min_0_25", 0.25f },
2832 { "min_0_5", 0.5f },
2833 { "min_0_75", 0.75f },
2837 de::MovePtr<tcu::TestCaseGroup> minSampleShadingTests(new tcu::TestCaseGroup(testCtx, "min_sample_shading", ""));
2839 for (int configNdx = 0; configNdx < DE_LENGTH_OF_ARRAY(testConfigs); configNdx++)
2841 const TestConfig& testConfig = testConfigs[configNdx];
2842 de::MovePtr<tcu::TestCaseGroup> minShadingValueTests (new tcu::TestCaseGroup(testCtx, testConfigs[configNdx].name, ""));
2844 for (int samplesNdx = 0; samplesNdx < DE_LENGTH_OF_ARRAY(samples); samplesNdx++)
2846 std::ostringstream caseName;
2847 caseName << "samples_" << samples[samplesNdx];
2849 de::MovePtr<tcu::TestCaseGroup> samplesTests (new tcu::TestCaseGroup(testCtx, caseName.str().c_str(), ""));
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));
2855 minShadingValueTests->addChild(samplesTests.release());
2858 minSampleShadingTests->addChild(minShadingValueTests.release());
2861 multisampleTests->addChild(minSampleShadingTests.release());
2864 // pSampleMask tests
2869 const char* description;
2870 VkSampleMask sampleMask;
2873 const TestConfig testConfigs[] =
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 },
2881 de::MovePtr<tcu::TestCaseGroup> sampleMaskTests(new tcu::TestCaseGroup(testCtx, "sample_mask", ""));
2883 for (int configNdx = 0; configNdx < DE_LENGTH_OF_ARRAY(testConfigs); configNdx++)
2885 const TestConfig& testConfig = testConfigs[configNdx];
2886 de::MovePtr<tcu::TestCaseGroup> sampleMaskValueTests (new tcu::TestCaseGroup(testCtx, testConfig.name, testConfig.description));
2888 for (int samplesNdx = 0; samplesNdx < DE_LENGTH_OF_ARRAY(samples); samplesNdx++)
2890 std::ostringstream caseName;
2891 caseName << "samples_" << samples[samplesNdx];
2893 const deUint32 sampleMaskCount = samples[samplesNdx] / 32;
2894 de::MovePtr<tcu::TestCaseGroup> samplesTests (new tcu::TestCaseGroup(testCtx, caseName.str().c_str(), ""));
2896 std::vector<VkSampleMask> mask;
2897 for (deUint32 maskNdx = 0; maskNdx < sampleMaskCount; maskNdx++)
2898 mask.push_back(testConfig.sampleMask);
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));
2904 sampleMaskValueTests->addChild(samplesTests.release());
2907 sampleMaskTests->addChild(sampleMaskValueTests.release());
2910 multisampleTests->addChild(sampleMaskTests.release());
2916 de::MovePtr<tcu::TestCaseGroup> alphaToOneTests(new tcu::TestCaseGroup(testCtx, "alpha_to_one", ""));
2918 for (int samplesNdx = 0; samplesNdx < DE_LENGTH_OF_ARRAY(samples); samplesNdx++)
2920 std::ostringstream caseName;
2921 caseName << "samples_" << samples[samplesNdx];
2923 alphaToOneTests->addChild(new AlphaToOneTest(testCtx, caseName.str(), "", samples[samplesNdx]));
2926 multisampleTests->addChild(alphaToOneTests.release());
2929 // AlphaToCoverageEnable tests
2931 de::MovePtr<tcu::TestCaseGroup> alphaToCoverageTests (new tcu::TestCaseGroup(testCtx, "alpha_to_coverage", ""));
2933 for (int samplesNdx = 0; samplesNdx < DE_LENGTH_OF_ARRAY(samples); samplesNdx++)
2935 std::ostringstream caseName;
2936 caseName << "samples_" << samples[samplesNdx];
2938 de::MovePtr<tcu::TestCaseGroup> samplesTests (new tcu::TestCaseGroup(testCtx, caseName.str().c_str(), ""));
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));
2944 alphaToCoverageTests->addChild(samplesTests.release());
2946 multisampleTests->addChild(alphaToCoverageTests.release());
2949 // Sampling from a multisampled image texture (texelFetch)
2951 multisampleTests->addChild(createMultisampleSampledImageTests(testCtx));
2954 // Load/store on a multisampled rendered image (different kinds of access: color attachment write, storage image, etc.)
2956 multisampleTests->addChild(createMultisampleStorageImageTests(testCtx));
2959 // VK_EXT_sample_locations
2961 multisampleTests->addChild(createMultisampleSampleLocationsExtTests(testCtx));
2964 return multisampleTests.release();