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 "vktPipelineClearUtil.hpp"
28 #include "vktPipelineImageUtil.hpp"
29 #include "vktPipelineVertexUtil.hpp"
30 #include "vktPipelineReferenceRenderer.hpp"
31 #include "vktTestCase.hpp"
32 #include "vktTestCaseUtil.hpp"
33 #include "vkImageUtil.hpp"
34 #include "vkMemUtil.hpp"
35 #include "vkPrograms.hpp"
36 #include "vkQueryUtil.hpp"
38 #include "vkRefUtil.hpp"
39 #include "tcuImageCompare.hpp"
40 #include "tcuTestLog.hpp"
41 #include "deUniquePtr.hpp"
42 #include "deSharedPtr.hpp"
43 #include "deStringUtil.hpp"
61 GEOMETRY_TYPE_OPAQUE_TRIANGLE,
62 GEOMETRY_TYPE_OPAQUE_LINE,
63 GEOMETRY_TYPE_OPAQUE_POINT,
64 GEOMETRY_TYPE_OPAQUE_QUAD,
65 GEOMETRY_TYPE_OPAQUE_QUAD_NONZERO_DEPTH, //!< placed at z = 0.5
66 GEOMETRY_TYPE_TRANSLUCENT_QUAD,
67 GEOMETRY_TYPE_INVISIBLE_TRIANGLE,
68 GEOMETRY_TYPE_INVISIBLE_QUAD,
69 GEOMETRY_TYPE_GRADIENT_QUAD
74 TEST_MODE_DEPTH_BIT = 1u,
75 TEST_MODE_STENCIL_BIT = 2u,
77 typedef deUint32 TestModeFlags;
79 void initMultisamplePrograms (SourceCollections& sources, GeometryType geometryType);
80 bool isSupportedSampleCount (const InstanceInterface& instanceInterface, VkPhysicalDevice physicalDevice, VkSampleCountFlagBits rasterizationSamples);
81 bool isSupportedDepthStencilFormat (const InstanceInterface& vki, const VkPhysicalDevice physDevice, const VkFormat format);
82 VkPipelineColorBlendAttachmentState getDefaultColorBlendAttachmentState (void);
83 deUint32 getUniqueColorsCount (const tcu::ConstPixelBufferAccess& image);
84 VkImageAspectFlags getImageAspectFlags (const VkFormat format);
85 VkPrimitiveTopology getPrimitiveTopology (const GeometryType geometryType);
86 std::vector<Vertex4RGBA> generateVertices (const GeometryType geometryType);
87 VkFormat findSupportedDepthStencilFormat (Context& context, const bool useDepth, const bool useStencil);
89 class MultisampleTest : public vkt::TestCase
93 MultisampleTest (tcu::TestContext& testContext,
94 const std::string& name,
95 const std::string& description,
96 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
97 const VkPipelineColorBlendAttachmentState& blendState,
98 GeometryType geometryType);
99 virtual ~MultisampleTest (void) {}
101 virtual void initPrograms (SourceCollections& programCollection) const;
102 virtual TestInstance* createInstance (Context& context) const;
105 virtual TestInstance* createMultisampleTestInstance (Context& context,
106 VkPrimitiveTopology topology,
107 const std::vector<Vertex4RGBA>& vertices,
108 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
109 const VkPipelineColorBlendAttachmentState& colorBlendState) const = 0;
110 VkPipelineMultisampleStateCreateInfo m_multisampleStateParams;
111 const VkPipelineColorBlendAttachmentState m_colorBlendState;
112 const GeometryType m_geometryType;
113 std::vector<VkSampleMask> m_sampleMask;
116 class RasterizationSamplesTest : public MultisampleTest
119 RasterizationSamplesTest (tcu::TestContext& testContext,
120 const std::string& name,
121 const std::string& description,
122 VkSampleCountFlagBits rasterizationSamples,
123 GeometryType geometryType,
124 TestModeFlags modeFlags = 0u);
125 virtual ~RasterizationSamplesTest (void) {}
128 virtual TestInstance* createMultisampleTestInstance (Context& context,
129 VkPrimitiveTopology topology,
130 const std::vector<Vertex4RGBA>& vertices,
131 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
132 const VkPipelineColorBlendAttachmentState& colorBlendState) const;
134 static VkPipelineMultisampleStateCreateInfo getRasterizationSamplesStateParams (VkSampleCountFlagBits rasterizationSamples);
136 const TestModeFlags m_modeFlags;
139 class MinSampleShadingTest : public MultisampleTest
142 MinSampleShadingTest (tcu::TestContext& testContext,
143 const std::string& name,
144 const std::string& description,
145 VkSampleCountFlagBits rasterizationSamples,
146 float minSampleShading,
147 GeometryType geometryType);
148 virtual ~MinSampleShadingTest (void) {}
151 virtual TestInstance* createMultisampleTestInstance (Context& context,
152 VkPrimitiveTopology topology,
153 const std::vector<Vertex4RGBA>& vertices,
154 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
155 const VkPipelineColorBlendAttachmentState& colorBlendState) const;
157 static VkPipelineMultisampleStateCreateInfo getMinSampleShadingStateParams (VkSampleCountFlagBits rasterizationSamples, float minSampleShading);
160 class SampleMaskTest : public MultisampleTest
163 SampleMaskTest (tcu::TestContext& testContext,
164 const std::string& name,
165 const std::string& description,
166 VkSampleCountFlagBits rasterizationSamples,
167 const std::vector<VkSampleMask>& sampleMask,
168 GeometryType geometryType);
170 virtual ~SampleMaskTest (void) {}
173 virtual TestInstance* createMultisampleTestInstance (Context& context,
174 VkPrimitiveTopology topology,
175 const std::vector<Vertex4RGBA>& vertices,
176 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
177 const VkPipelineColorBlendAttachmentState& colorBlendState) const;
179 static VkPipelineMultisampleStateCreateInfo getSampleMaskStateParams (VkSampleCountFlagBits rasterizationSamples, const std::vector<VkSampleMask>& sampleMask);
182 class AlphaToOneTest : public MultisampleTest
185 AlphaToOneTest (tcu::TestContext& testContext,
186 const std::string& name,
187 const std::string& description,
188 VkSampleCountFlagBits rasterizationSamples);
190 virtual ~AlphaToOneTest (void) {}
193 virtual TestInstance* createMultisampleTestInstance (Context& context,
194 VkPrimitiveTopology topology,
195 const std::vector<Vertex4RGBA>& vertices,
196 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
197 const VkPipelineColorBlendAttachmentState& colorBlendState) const;
199 static VkPipelineMultisampleStateCreateInfo getAlphaToOneStateParams (VkSampleCountFlagBits rasterizationSamples);
200 static VkPipelineColorBlendAttachmentState getAlphaToOneBlendState (void);
203 class AlphaToCoverageTest : public MultisampleTest
206 AlphaToCoverageTest (tcu::TestContext& testContext,
207 const std::string& name,
208 const std::string& description,
209 VkSampleCountFlagBits rasterizationSamples,
210 GeometryType geometryType);
212 virtual ~AlphaToCoverageTest (void) {}
215 virtual TestInstance* createMultisampleTestInstance (Context& context,
216 VkPrimitiveTopology topology,
217 const std::vector<Vertex4RGBA>& vertices,
218 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
219 const VkPipelineColorBlendAttachmentState& colorBlendState) const;
221 static VkPipelineMultisampleStateCreateInfo getAlphaToCoverageStateParams (VkSampleCountFlagBits rasterizationSamples);
223 GeometryType m_geometryType;
226 typedef de::SharedPtr<Unique<VkPipeline> > VkPipelineSp;
228 class MultisampleRenderer
231 MultisampleRenderer (Context& context,
232 const VkFormat colorFormat,
233 const tcu::IVec2& renderSize,
234 const VkPrimitiveTopology topology,
235 const std::vector<Vertex4RGBA>& vertices,
236 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
237 const VkPipelineColorBlendAttachmentState& blendState);
239 MultisampleRenderer (Context& context,
240 const VkFormat colorFormat,
241 const VkFormat depthStencilFormat,
242 const tcu::IVec2& renderSize,
244 const bool useStencil,
245 const deUint32 numTopologies,
246 const VkPrimitiveTopology* pTopology,
247 const std::vector<Vertex4RGBA>* pVertices,
248 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
249 const VkPipelineColorBlendAttachmentState& blendState);
251 virtual ~MultisampleRenderer (void);
253 de::MovePtr<tcu::TextureLevel> render (void);
256 void initialize (Context& context,
257 const deUint32 numTopologies,
258 const VkPrimitiveTopology* pTopology,
259 const std::vector<Vertex4RGBA>* pVertices);
263 const VkFormat m_colorFormat;
264 const VkFormat m_depthStencilFormat;
265 tcu::IVec2 m_renderSize;
266 const bool m_useDepth;
267 const bool m_useStencil;
269 const VkPipelineMultisampleStateCreateInfo m_multisampleStateParams;
270 const VkPipelineColorBlendAttachmentState m_colorBlendState;
272 Move<VkImage> m_colorImage;
273 de::MovePtr<Allocation> m_colorImageAlloc;
274 Move<VkImageView> m_colorAttachmentView;
276 Move<VkImage> m_resolveImage;
277 de::MovePtr<Allocation> m_resolveImageAlloc;
278 Move<VkImageView> m_resolveAttachmentView;
280 Move<VkImage> m_depthStencilImage;
281 de::MovePtr<Allocation> m_depthStencilImageAlloc;
282 Move<VkImageView> m_depthStencilAttachmentView;
284 Move<VkRenderPass> m_renderPass;
285 Move<VkFramebuffer> m_framebuffer;
287 Move<VkShaderModule> m_vertexShaderModule;
288 Move<VkShaderModule> m_fragmentShaderModule;
290 Move<VkBuffer> m_vertexBuffer;
291 de::MovePtr<Allocation> m_vertexBufferAlloc;
293 Move<VkPipelineLayout> m_pipelineLayout;
294 std::vector<VkPipelineSp> m_graphicsPipelines;
296 Move<VkCommandPool> m_cmdPool;
297 Move<VkCommandBuffer> m_cmdBuffer;
299 Move<VkFence> m_fence;
302 class RasterizationSamplesInstance : public vkt::TestInstance
305 RasterizationSamplesInstance (Context& context,
306 VkPrimitiveTopology topology,
307 const std::vector<Vertex4RGBA>& vertices,
308 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
309 const VkPipelineColorBlendAttachmentState& blendState,
310 const TestModeFlags modeFlags);
311 virtual ~RasterizationSamplesInstance (void) {}
313 virtual tcu::TestStatus iterate (void);
316 virtual tcu::TestStatus verifyImage (const tcu::ConstPixelBufferAccess& result);
318 const VkFormat m_colorFormat;
319 const tcu::IVec2 m_renderSize;
320 const VkPrimitiveTopology m_primitiveTopology;
321 const std::vector<Vertex4RGBA> m_vertices;
322 const std::vector<Vertex4RGBA> m_fullQuadVertices; //!< used by depth/stencil case
323 const TestModeFlags m_modeFlags;
324 de::MovePtr<MultisampleRenderer> m_multisampleRenderer;
327 class MinSampleShadingInstance : public vkt::TestInstance
330 MinSampleShadingInstance (Context& context,
331 VkPrimitiveTopology topology,
332 const std::vector<Vertex4RGBA>& vertices,
333 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
334 const VkPipelineColorBlendAttachmentState& blendState);
335 virtual ~MinSampleShadingInstance (void) {}
337 virtual tcu::TestStatus iterate (void);
340 virtual tcu::TestStatus verifyImage (const tcu::ConstPixelBufferAccess& testShadingImage,
341 const tcu::ConstPixelBufferAccess& minShadingImage,
342 const tcu::ConstPixelBufferAccess& maxShadingImage);
343 const VkFormat m_colorFormat;
344 const tcu::IVec2 m_renderSize;
345 const VkPrimitiveTopology m_primitiveTopology;
346 const std::vector<Vertex4RGBA> m_vertices;
347 const VkPipelineMultisampleStateCreateInfo m_multisampleStateParams;
348 const VkPipelineColorBlendAttachmentState m_colorBlendState;
351 class SampleMaskInstance : public vkt::TestInstance
354 SampleMaskInstance (Context& context,
355 VkPrimitiveTopology topology,
356 const std::vector<Vertex4RGBA>& vertices,
357 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
358 const VkPipelineColorBlendAttachmentState& blendState);
359 virtual ~SampleMaskInstance (void) {}
361 virtual tcu::TestStatus iterate (void);
364 virtual tcu::TestStatus verifyImage (const tcu::ConstPixelBufferAccess& testShadingImage,
365 const tcu::ConstPixelBufferAccess& minShadingImage,
366 const tcu::ConstPixelBufferAccess& maxShadingImage);
367 const VkFormat m_colorFormat;
368 const tcu::IVec2 m_renderSize;
369 const VkPrimitiveTopology m_primitiveTopology;
370 const std::vector<Vertex4RGBA> m_vertices;
371 const VkPipelineMultisampleStateCreateInfo m_multisampleStateParams;
372 const VkPipelineColorBlendAttachmentState m_colorBlendState;
375 class AlphaToOneInstance : public vkt::TestInstance
378 AlphaToOneInstance (Context& context,
379 VkPrimitiveTopology topology,
380 const std::vector<Vertex4RGBA>& vertices,
381 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
382 const VkPipelineColorBlendAttachmentState& blendState);
383 virtual ~AlphaToOneInstance (void) {}
385 virtual tcu::TestStatus iterate (void);
388 virtual tcu::TestStatus verifyImage (const tcu::ConstPixelBufferAccess& alphaOneImage,
389 const tcu::ConstPixelBufferAccess& noAlphaOneImage);
390 const VkFormat m_colorFormat;
391 const tcu::IVec2 m_renderSize;
392 const VkPrimitiveTopology m_primitiveTopology;
393 const std::vector<Vertex4RGBA> m_vertices;
394 const VkPipelineMultisampleStateCreateInfo m_multisampleStateParams;
395 const VkPipelineColorBlendAttachmentState m_colorBlendState;
398 class AlphaToCoverageInstance : public vkt::TestInstance
401 AlphaToCoverageInstance (Context& context,
402 VkPrimitiveTopology topology,
403 const std::vector<Vertex4RGBA>& vertices,
404 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
405 const VkPipelineColorBlendAttachmentState& blendState,
406 GeometryType geometryType);
407 virtual ~AlphaToCoverageInstance (void) {}
409 virtual tcu::TestStatus iterate (void);
412 virtual tcu::TestStatus verifyImage (const tcu::ConstPixelBufferAccess& result);
413 const VkFormat m_colorFormat;
414 const tcu::IVec2 m_renderSize;
415 const VkPrimitiveTopology m_primitiveTopology;
416 const std::vector<Vertex4RGBA> m_vertices;
417 const VkPipelineMultisampleStateCreateInfo m_multisampleStateParams;
418 const VkPipelineColorBlendAttachmentState m_colorBlendState;
419 const GeometryType m_geometryType;
425 void initMultisamplePrograms (SourceCollections& sources, GeometryType geometryType)
427 std::ostringstream vertexSource;
431 "layout(location = 0) in vec4 position;\n"
432 "layout(location = 1) in vec4 color;\n"
433 "layout(location = 0) out highp vec4 vtxColor;\n"
436 " gl_Position = position;\n"
437 " vtxColor = color;\n"
438 << (geometryType == GEOMETRY_TYPE_OPAQUE_POINT ? " gl_PointSize = 3.0f;\n"
442 static const char* fragmentSource =
444 "layout(location = 0) in highp vec4 vtxColor;\n"
445 "layout(location = 0) out highp vec4 fragColor;\n"
448 " fragColor = vtxColor;\n"
451 sources.glslSources.add("color_vert") << glu::VertexSource(vertexSource.str());
452 sources.glslSources.add("color_frag") << glu::FragmentSource(fragmentSource);
455 bool isSupportedSampleCount (const InstanceInterface& instanceInterface, VkPhysicalDevice physicalDevice, VkSampleCountFlagBits rasterizationSamples)
457 VkPhysicalDeviceProperties deviceProperties;
459 instanceInterface.getPhysicalDeviceProperties(physicalDevice, &deviceProperties);
461 return !!(deviceProperties.limits.framebufferColorSampleCounts & rasterizationSamples);
464 VkPipelineColorBlendAttachmentState getDefaultColorBlendAttachmentState (void)
466 const VkPipelineColorBlendAttachmentState colorBlendState =
468 false, // VkBool32 blendEnable;
469 VK_BLEND_FACTOR_ONE, // VkBlendFactor srcColorBlendFactor;
470 VK_BLEND_FACTOR_ZERO, // VkBlendFactor dstColorBlendFactor;
471 VK_BLEND_OP_ADD, // VkBlendOp colorBlendOp;
472 VK_BLEND_FACTOR_ONE, // VkBlendFactor srcAlphaBlendFactor;
473 VK_BLEND_FACTOR_ZERO, // VkBlendFactor dstAlphaBlendFactor;
474 VK_BLEND_OP_ADD, // VkBlendOp alphaBlendOp;
475 VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | // VkColorComponentFlags colorWriteMask;
476 VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT
479 return colorBlendState;
482 deUint32 getUniqueColorsCount (const tcu::ConstPixelBufferAccess& image)
484 DE_ASSERT(image.getFormat().getPixelSize() == 4);
486 std::map<deUint32, deUint32> histogram; // map<pixel value, number of occurrences>
487 const deUint32 pixelCount = image.getWidth() * image.getHeight() * image.getDepth();
489 for (deUint32 pixelNdx = 0; pixelNdx < pixelCount; pixelNdx++)
491 const deUint32 pixelValue = *((const deUint32*)image.getDataPtr() + pixelNdx);
493 if (histogram.find(pixelValue) != histogram.end())
494 histogram[pixelValue]++;
496 histogram[pixelValue] = 1;
499 return (deUint32)histogram.size();
502 VkImageAspectFlags getImageAspectFlags (const VkFormat format)
504 const tcu::TextureFormat tcuFormat = mapVkFormat(format);
506 if (tcuFormat.order == tcu::TextureFormat::DS) return VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
507 else if (tcuFormat.order == tcu::TextureFormat::D) return VK_IMAGE_ASPECT_DEPTH_BIT;
508 else if (tcuFormat.order == tcu::TextureFormat::S) return VK_IMAGE_ASPECT_STENCIL_BIT;
514 std::vector<Vertex4RGBA> generateVertices (const GeometryType geometryType)
516 std::vector<Vertex4RGBA> vertices;
518 switch (geometryType)
520 case GEOMETRY_TYPE_OPAQUE_TRIANGLE:
521 case GEOMETRY_TYPE_INVISIBLE_TRIANGLE:
523 Vertex4RGBA vertexData[3] =
526 tcu::Vec4(-0.75f, 0.0f, 0.0f, 1.0f),
527 tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f)
530 tcu::Vec4(0.75f, 0.125f, 0.0f, 1.0f),
531 tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f)
534 tcu::Vec4(0.75f, -0.125f, 0.0f, 1.0f),
535 tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f)
539 if (geometryType == GEOMETRY_TYPE_INVISIBLE_TRIANGLE)
541 for (int i = 0; i < 3; i++)
542 vertexData[i].color = tcu::Vec4();
545 vertices = std::vector<Vertex4RGBA>(vertexData, vertexData + 3);
549 case GEOMETRY_TYPE_OPAQUE_LINE:
551 const Vertex4RGBA vertexData[2] =
554 tcu::Vec4(-0.75f, 0.25f, 0.0f, 1.0f),
555 tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f)
558 tcu::Vec4(0.75f, -0.25f, 0.0f, 1.0f),
559 tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f)
563 vertices = std::vector<Vertex4RGBA>(vertexData, vertexData + 2);
567 case GEOMETRY_TYPE_OPAQUE_POINT:
569 const Vertex4RGBA vertex =
571 tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f),
572 tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f)
575 vertices = std::vector<Vertex4RGBA>(1, vertex);
579 case GEOMETRY_TYPE_OPAQUE_QUAD:
580 case GEOMETRY_TYPE_OPAQUE_QUAD_NONZERO_DEPTH:
581 case GEOMETRY_TYPE_TRANSLUCENT_QUAD:
582 case GEOMETRY_TYPE_INVISIBLE_QUAD:
583 case GEOMETRY_TYPE_GRADIENT_QUAD:
585 Vertex4RGBA vertexData[4] =
588 tcu::Vec4(-1.0f, -1.0f, 0.0f, 1.0f),
589 tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f)
592 tcu::Vec4(1.0f, -1.0f, 0.0f, 1.0f),
593 tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f)
596 tcu::Vec4(-1.0f, 1.0f, 0.0f, 1.0f),
597 tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f)
600 tcu::Vec4(1.0f, 1.0f, 0.0f, 1.0f),
601 tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f)
605 if (geometryType == GEOMETRY_TYPE_TRANSLUCENT_QUAD)
607 for (int i = 0; i < 4; i++)
608 vertexData[i].color.w() = 0.25f;
610 else if (geometryType == GEOMETRY_TYPE_INVISIBLE_QUAD)
612 for (int i = 0; i < 4; i++)
613 vertexData[i].color.w() = 0.0f;
615 else if (geometryType == GEOMETRY_TYPE_GRADIENT_QUAD)
617 vertexData[0].color.w() = 0.0f;
618 vertexData[2].color.w() = 0.0f;
620 else if (geometryType == GEOMETRY_TYPE_OPAQUE_QUAD_NONZERO_DEPTH)
622 for (int i = 0; i < 4; i++)
623 vertexData[i].position.z() = 0.5f;
626 vertices = std::vector<Vertex4RGBA>(vertexData, vertexData + 4);
636 VkPrimitiveTopology getPrimitiveTopology (const GeometryType geometryType)
638 switch (geometryType)
640 case GEOMETRY_TYPE_OPAQUE_TRIANGLE:
641 case GEOMETRY_TYPE_INVISIBLE_TRIANGLE: return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
643 case GEOMETRY_TYPE_OPAQUE_LINE: return VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
644 case GEOMETRY_TYPE_OPAQUE_POINT: return VK_PRIMITIVE_TOPOLOGY_POINT_LIST;
646 case GEOMETRY_TYPE_OPAQUE_QUAD:
647 case GEOMETRY_TYPE_OPAQUE_QUAD_NONZERO_DEPTH:
648 case GEOMETRY_TYPE_TRANSLUCENT_QUAD:
649 case GEOMETRY_TYPE_INVISIBLE_QUAD:
650 case GEOMETRY_TYPE_GRADIENT_QUAD: return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
654 return VK_PRIMITIVE_TOPOLOGY_LAST;
658 bool isSupportedDepthStencilFormat (const InstanceInterface& vki, const VkPhysicalDevice physDevice, const VkFormat format)
660 VkFormatProperties formatProps;
661 vki.getPhysicalDeviceFormatProperties(physDevice, format, &formatProps);
662 return (formatProps.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) != 0;
665 VkFormat findSupportedDepthStencilFormat (Context& context, const bool useDepth, const bool useStencil)
667 if (useDepth && !useStencil)
668 return VK_FORMAT_D16_UNORM; // must be supported
670 const InstanceInterface& vki = context.getInstanceInterface();
671 const VkPhysicalDevice physDevice = context.getPhysicalDevice();
673 // One of these formats must be supported.
675 if (isSupportedDepthStencilFormat(vki, physDevice, VK_FORMAT_D24_UNORM_S8_UINT))
676 return VK_FORMAT_D24_UNORM_S8_UINT;
678 if (isSupportedDepthStencilFormat(vki, physDevice, VK_FORMAT_D32_SFLOAT_S8_UINT))
679 return VK_FORMAT_D32_SFLOAT_S8_UINT;
681 return VK_FORMAT_UNDEFINED;
687 MultisampleTest::MultisampleTest (tcu::TestContext& testContext,
688 const std::string& name,
689 const std::string& description,
690 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
691 const VkPipelineColorBlendAttachmentState& blendState,
692 GeometryType geometryType)
693 : vkt::TestCase (testContext, name, description)
694 , m_multisampleStateParams (multisampleStateParams)
695 , m_colorBlendState (blendState)
696 , m_geometryType (geometryType)
698 if (m_multisampleStateParams.pSampleMask)
700 // Copy pSampleMask to avoid dependencies with other classes
702 const deUint32 maskCount = deCeilFloatToInt32(float(m_multisampleStateParams.rasterizationSamples) / 32);
704 for (deUint32 maskNdx = 0; maskNdx < maskCount; maskNdx++)
705 m_sampleMask.push_back(m_multisampleStateParams.pSampleMask[maskNdx]);
707 m_multisampleStateParams.pSampleMask = m_sampleMask.data();
711 void MultisampleTest::initPrograms (SourceCollections& programCollection) const
713 initMultisamplePrograms(programCollection, m_geometryType);
716 TestInstance* MultisampleTest::createInstance (Context& context) const
718 return createMultisampleTestInstance(context, getPrimitiveTopology(m_geometryType), generateVertices(m_geometryType), m_multisampleStateParams, m_colorBlendState);
722 // RasterizationSamplesTest
724 RasterizationSamplesTest::RasterizationSamplesTest (tcu::TestContext& testContext,
725 const std::string& name,
726 const std::string& description,
727 VkSampleCountFlagBits rasterizationSamples,
728 GeometryType geometryType,
729 TestModeFlags modeFlags)
730 : MultisampleTest (testContext, name, description, getRasterizationSamplesStateParams(rasterizationSamples), getDefaultColorBlendAttachmentState(), geometryType)
731 , m_modeFlags (modeFlags)
735 VkPipelineMultisampleStateCreateInfo RasterizationSamplesTest::getRasterizationSamplesStateParams (VkSampleCountFlagBits rasterizationSamples)
737 const VkPipelineMultisampleStateCreateInfo multisampleStateParams =
739 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, // VkStructureType sType;
740 DE_NULL, // const void* pNext;
741 0u, // VkPipelineMultisampleStateCreateFlags flags;
742 rasterizationSamples, // VkSampleCountFlagBits rasterizationSamples;
743 false, // VkBool32 sampleShadingEnable;
744 0.0f, // float minSampleShading;
745 DE_NULL, // const VkSampleMask* pSampleMask;
746 false, // VkBool32 alphaToCoverageEnable;
747 false // VkBool32 alphaToOneEnable;
750 return multisampleStateParams;
753 TestInstance* RasterizationSamplesTest::createMultisampleTestInstance (Context& context,
754 VkPrimitiveTopology topology,
755 const std::vector<Vertex4RGBA>& vertices,
756 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
757 const VkPipelineColorBlendAttachmentState& colorBlendState) const
759 return new RasterizationSamplesInstance(context, topology, vertices, multisampleStateParams, colorBlendState, m_modeFlags);
763 // MinSampleShadingTest
765 MinSampleShadingTest::MinSampleShadingTest (tcu::TestContext& testContext,
766 const std::string& name,
767 const std::string& description,
768 VkSampleCountFlagBits rasterizationSamples,
769 float minSampleShading,
770 GeometryType geometryType)
771 : MultisampleTest (testContext, name, description, getMinSampleShadingStateParams(rasterizationSamples, minSampleShading), getDefaultColorBlendAttachmentState(), geometryType)
775 TestInstance* MinSampleShadingTest::createMultisampleTestInstance (Context& context,
776 VkPrimitiveTopology topology,
777 const std::vector<Vertex4RGBA>& vertices,
778 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
779 const VkPipelineColorBlendAttachmentState& colorBlendState) const
781 return new MinSampleShadingInstance(context, topology, vertices, multisampleStateParams, colorBlendState);
784 VkPipelineMultisampleStateCreateInfo MinSampleShadingTest::getMinSampleShadingStateParams (VkSampleCountFlagBits rasterizationSamples, float minSampleShading)
786 const VkPipelineMultisampleStateCreateInfo multisampleStateParams =
788 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, // VkStructureType sType;
789 DE_NULL, // const void* pNext;
790 0u, // VkPipelineMultisampleStateCreateFlags flags;
791 rasterizationSamples, // VkSampleCountFlagBits rasterizationSamples;
792 true, // VkBool32 sampleShadingEnable;
793 minSampleShading, // float minSampleShading;
794 DE_NULL, // const VkSampleMask* pSampleMask;
795 false, // VkBool32 alphaToCoverageEnable;
796 false // VkBool32 alphaToOneEnable;
799 return multisampleStateParams;
805 SampleMaskTest::SampleMaskTest (tcu::TestContext& testContext,
806 const std::string& name,
807 const std::string& description,
808 VkSampleCountFlagBits rasterizationSamples,
809 const std::vector<VkSampleMask>& sampleMask,
810 GeometryType geometryType)
811 : MultisampleTest (testContext, name, description, getSampleMaskStateParams(rasterizationSamples, sampleMask), getDefaultColorBlendAttachmentState(), geometryType)
815 TestInstance* SampleMaskTest::createMultisampleTestInstance (Context& context,
816 VkPrimitiveTopology topology,
817 const std::vector<Vertex4RGBA>& vertices,
818 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
819 const VkPipelineColorBlendAttachmentState& colorBlendState) const
821 return new SampleMaskInstance(context, topology,vertices, multisampleStateParams, colorBlendState);
824 VkPipelineMultisampleStateCreateInfo SampleMaskTest::getSampleMaskStateParams (VkSampleCountFlagBits rasterizationSamples, const std::vector<VkSampleMask>& sampleMask)
826 const VkPipelineMultisampleStateCreateInfo multisampleStateParams =
828 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, // VkStructureType sType;
829 DE_NULL, // const void* pNext;
830 0u, // VkPipelineMultisampleStateCreateFlags flags;
831 rasterizationSamples, // VkSampleCountFlagBits rasterizationSamples;
832 false, // VkBool32 sampleShadingEnable;
833 0.0f, // float minSampleShading;
834 sampleMask.data(), // const VkSampleMask* pSampleMask;
835 false, // VkBool32 alphaToCoverageEnable;
836 false // VkBool32 alphaToOneEnable;
839 return multisampleStateParams;
845 AlphaToOneTest::AlphaToOneTest (tcu::TestContext& testContext,
846 const std::string& name,
847 const std::string& description,
848 VkSampleCountFlagBits rasterizationSamples)
849 : MultisampleTest (testContext, name, description, getAlphaToOneStateParams(rasterizationSamples), getAlphaToOneBlendState(), GEOMETRY_TYPE_GRADIENT_QUAD)
853 TestInstance* AlphaToOneTest::createMultisampleTestInstance (Context& context,
854 VkPrimitiveTopology topology,
855 const std::vector<Vertex4RGBA>& vertices,
856 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
857 const VkPipelineColorBlendAttachmentState& colorBlendState) const
859 return new AlphaToOneInstance(context, topology, vertices, multisampleStateParams, colorBlendState);
862 VkPipelineMultisampleStateCreateInfo AlphaToOneTest::getAlphaToOneStateParams (VkSampleCountFlagBits rasterizationSamples)
864 const VkPipelineMultisampleStateCreateInfo multisampleStateParams =
866 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, // VkStructureType sType;
867 DE_NULL, // const void* pNext;
868 0u, // VkPipelineMultisampleStateCreateFlags flags;
869 rasterizationSamples, // VkSampleCountFlagBits rasterizationSamples;
870 false, // VkBool32 sampleShadingEnable;
871 0.0f, // float minSampleShading;
872 DE_NULL, // const VkSampleMask* pSampleMask;
873 false, // VkBool32 alphaToCoverageEnable;
874 true // VkBool32 alphaToOneEnable;
877 return multisampleStateParams;
880 VkPipelineColorBlendAttachmentState AlphaToOneTest::getAlphaToOneBlendState (void)
882 const VkPipelineColorBlendAttachmentState colorBlendState =
884 true, // VkBool32 blendEnable;
885 VK_BLEND_FACTOR_SRC_ALPHA, // VkBlendFactor srcColorBlendFactor;
886 VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA, // VkBlendFactor dstColorBlendFactor;
887 VK_BLEND_OP_ADD, // VkBlendOp colorBlendOp;
888 VK_BLEND_FACTOR_SRC_ALPHA, // VkBlendFactor srcAlphaBlendFactor;
889 VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA, // VkBlendFactor dstAlphaBlendFactor;
890 VK_BLEND_OP_ADD, // VkBlendOp alphaBlendOp;
891 VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | // VkColorComponentFlags colorWriteMask;
892 VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT
895 return colorBlendState;
899 // AlphaToCoverageTest
901 AlphaToCoverageTest::AlphaToCoverageTest (tcu::TestContext& testContext,
902 const std::string& name,
903 const std::string& description,
904 VkSampleCountFlagBits rasterizationSamples,
905 GeometryType geometryType)
906 : MultisampleTest (testContext, name, description, getAlphaToCoverageStateParams(rasterizationSamples), getDefaultColorBlendAttachmentState(), geometryType)
907 , m_geometryType (geometryType)
911 TestInstance* AlphaToCoverageTest::createMultisampleTestInstance (Context& context,
912 VkPrimitiveTopology topology,
913 const std::vector<Vertex4RGBA>& vertices,
914 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
915 const VkPipelineColorBlendAttachmentState& colorBlendState) const
917 return new AlphaToCoverageInstance(context, topology, vertices, multisampleStateParams, colorBlendState, m_geometryType);
920 VkPipelineMultisampleStateCreateInfo AlphaToCoverageTest::getAlphaToCoverageStateParams (VkSampleCountFlagBits rasterizationSamples)
922 const VkPipelineMultisampleStateCreateInfo multisampleStateParams =
924 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, // VkStructureType sType;
925 DE_NULL, // const void* pNext;
926 0u, // VkPipelineMultisampleStateCreateFlags flags;
927 rasterizationSamples, // VkSampleCountFlagBits rasterizationSamples;
928 false, // VkBool32 sampleShadingEnable;
929 0.0f, // float minSampleShading;
930 DE_NULL, // const VkSampleMask* pSampleMask;
931 true, // VkBool32 alphaToCoverageEnable;
932 false // VkBool32 alphaToOneEnable;
935 return multisampleStateParams;
938 // RasterizationSamplesInstance
940 RasterizationSamplesInstance::RasterizationSamplesInstance (Context& context,
941 VkPrimitiveTopology topology,
942 const std::vector<Vertex4RGBA>& vertices,
943 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
944 const VkPipelineColorBlendAttachmentState& blendState,
945 const TestModeFlags modeFlags)
946 : vkt::TestInstance (context)
947 , m_colorFormat (VK_FORMAT_R8G8B8A8_UNORM)
948 , m_renderSize (32, 32)
949 , m_primitiveTopology (topology)
950 , m_vertices (vertices)
951 , m_fullQuadVertices (generateVertices(GEOMETRY_TYPE_OPAQUE_QUAD_NONZERO_DEPTH))
952 , m_modeFlags (modeFlags)
954 if (m_modeFlags != 0)
956 const bool useDepth = (m_modeFlags & TEST_MODE_DEPTH_BIT) != 0;
957 const bool useStencil = (m_modeFlags & TEST_MODE_STENCIL_BIT) != 0;
958 const VkFormat depthStencilFormat = findSupportedDepthStencilFormat(context, useDepth, useStencil);
960 if (depthStencilFormat == VK_FORMAT_UNDEFINED)
961 TCU_THROW(NotSupportedError, "Required depth/stencil format is not supported");
963 const VkPrimitiveTopology pTopology[2] = { m_primitiveTopology, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP };
964 const std::vector<Vertex4RGBA> pVertices[2] = { m_vertices, m_fullQuadVertices };
966 m_multisampleRenderer = de::MovePtr<MultisampleRenderer>(
967 new MultisampleRenderer(
968 context, m_colorFormat, depthStencilFormat, m_renderSize, useDepth, useStencil, 2u, pTopology, pVertices, multisampleStateParams, blendState));
972 m_multisampleRenderer = de::MovePtr<MultisampleRenderer>(
973 new MultisampleRenderer(context, m_colorFormat, m_renderSize, topology, vertices, multisampleStateParams, blendState));
977 tcu::TestStatus RasterizationSamplesInstance::iterate (void)
979 de::MovePtr<tcu::TextureLevel> level(m_multisampleRenderer->render());
980 return verifyImage(level->getAccess());
983 tcu::TestStatus RasterizationSamplesInstance::verifyImage (const tcu::ConstPixelBufferAccess& result)
985 // Verify range of unique pixels
987 const deUint32 numUniqueColors = getUniqueColorsCount(result);
988 const deUint32 minUniqueColors = 3;
990 tcu::TestLog& log = m_context.getTestContext().getLog();
992 log << tcu::TestLog::Message
993 << "\nMin. unique colors expected: " << minUniqueColors << "\n"
994 << "Unique colors found: " << numUniqueColors << "\n"
995 << tcu::TestLog::EndMessage;
997 if (numUniqueColors < minUniqueColors)
998 return tcu::TestStatus::fail("Unique colors out of expected bounds");
1001 // Verify shape of the rendered primitive (fuzzy-compare)
1003 const tcu::TextureFormat tcuColorFormat = mapVkFormat(m_colorFormat);
1004 const tcu::TextureFormat tcuDepthFormat = tcu::TextureFormat();
1005 const ColorVertexShader vertexShader;
1006 const ColorFragmentShader fragmentShader (tcuColorFormat, tcuDepthFormat);
1007 const rr::Program program (&vertexShader, &fragmentShader);
1008 ReferenceRenderer refRenderer (m_renderSize.x(), m_renderSize.y(), 1, tcuColorFormat, tcuDepthFormat, &program);
1009 rr::RenderState renderState (refRenderer.getViewportState());
1011 if (m_primitiveTopology == VK_PRIMITIVE_TOPOLOGY_POINT_LIST)
1013 VkPhysicalDeviceProperties deviceProperties;
1015 m_context.getInstanceInterface().getPhysicalDeviceProperties(m_context.getPhysicalDevice(), &deviceProperties);
1017 // gl_PointSize is clamped to pointSizeRange
1018 renderState.point.pointSize = deFloatMin(3.0f, deviceProperties.limits.pointSizeRange[1]);
1021 if (m_modeFlags == 0)
1023 refRenderer.colorClear(tcu::Vec4(0.0f));
1024 refRenderer.draw(renderState, mapVkPrimitiveTopology(m_primitiveTopology), m_vertices);
1028 // For depth/stencil case the primitive is invisible and the surroundings are filled red.
1029 refRenderer.colorClear(tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f));
1030 refRenderer.draw(renderState, mapVkPrimitiveTopology(m_primitiveTopology), m_vertices);
1033 if (!tcu::fuzzyCompare(m_context.getTestContext().getLog(), "FuzzyImageCompare", "Image comparison", refRenderer.getAccess(), result, 0.05f, tcu::COMPARE_LOG_RESULT))
1034 return tcu::TestStatus::fail("Primitive has unexpected shape");
1037 return tcu::TestStatus::pass("Primitive rendered, unique colors within expected bounds");
1041 // MinSampleShadingInstance
1043 MinSampleShadingInstance::MinSampleShadingInstance (Context& context,
1044 VkPrimitiveTopology topology,
1045 const std::vector<Vertex4RGBA>& vertices,
1046 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
1047 const VkPipelineColorBlendAttachmentState& colorBlendState)
1048 : vkt::TestInstance (context)
1049 , m_colorFormat (VK_FORMAT_R8G8B8A8_UNORM)
1050 , m_renderSize (32, 32)
1051 , m_primitiveTopology (topology)
1052 , m_vertices (vertices)
1053 , m_multisampleStateParams (multisampleStateParams)
1054 , m_colorBlendState (colorBlendState)
1056 VkPhysicalDeviceFeatures deviceFeatures;
1058 m_context.getInstanceInterface().getPhysicalDeviceFeatures(m_context.getPhysicalDevice(), &deviceFeatures);
1060 if (!deviceFeatures.sampleRateShading)
1061 throw tcu::NotSupportedError("Sample shading is not supported");
1064 tcu::TestStatus MinSampleShadingInstance::iterate (void)
1066 de::MovePtr<tcu::TextureLevel> testShadingImage;
1067 de::MovePtr<tcu::TextureLevel> minShadingImage;
1068 de::MovePtr<tcu::TextureLevel> maxShadingImage;
1070 // Render with test minSampleShading
1072 MultisampleRenderer renderer (m_context, m_colorFormat, m_renderSize, m_primitiveTopology, m_vertices, m_multisampleStateParams, m_colorBlendState);
1073 testShadingImage = renderer.render();
1076 // Render with minSampleShading = 0.0f
1078 VkPipelineMultisampleStateCreateInfo multisampleParams = m_multisampleStateParams;
1079 multisampleParams.minSampleShading = 0.0f;
1081 MultisampleRenderer renderer (m_context, m_colorFormat, m_renderSize, m_primitiveTopology, m_vertices, multisampleParams, m_colorBlendState);
1082 minShadingImage = renderer.render();
1085 // Render with minSampleShading = 1.0f
1087 VkPipelineMultisampleStateCreateInfo multisampleParams = m_multisampleStateParams;
1088 multisampleParams.minSampleShading = 1.0f;
1090 MultisampleRenderer renderer (m_context, m_colorFormat, m_renderSize, m_primitiveTopology, m_vertices, multisampleParams, m_colorBlendState);
1091 maxShadingImage = renderer.render();
1094 return verifyImage(testShadingImage->getAccess(), minShadingImage->getAccess(), maxShadingImage->getAccess());
1097 tcu::TestStatus MinSampleShadingInstance::verifyImage (const tcu::ConstPixelBufferAccess& testShadingImage, const tcu::ConstPixelBufferAccess& minShadingImage, const tcu::ConstPixelBufferAccess& maxShadingImage)
1099 const deUint32 testColorCount = getUniqueColorsCount(testShadingImage);
1100 const deUint32 minColorCount = getUniqueColorsCount(minShadingImage);
1101 const deUint32 maxColorCount = getUniqueColorsCount(maxShadingImage);
1103 tcu::TestLog& log = m_context.getTestContext().getLog();
1105 log << tcu::TestLog::Message
1106 << "\nColors found: " << testColorCount << "\n"
1107 << "Min. colors expected: " << minColorCount << "\n"
1108 << "Max. colors expected: " << maxColorCount << "\n"
1109 << tcu::TestLog::EndMessage;
1111 if (minColorCount > testColorCount || testColorCount > maxColorCount)
1112 return tcu::TestStatus::fail("Unique colors out of expected bounds");
1114 return tcu::TestStatus::pass("Unique colors within expected bounds");
1117 SampleMaskInstance::SampleMaskInstance (Context& context,
1118 VkPrimitiveTopology topology,
1119 const std::vector<Vertex4RGBA>& vertices,
1120 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
1121 const VkPipelineColorBlendAttachmentState& blendState)
1122 : vkt::TestInstance (context)
1123 , m_colorFormat (VK_FORMAT_R8G8B8A8_UNORM)
1124 , m_renderSize (32, 32)
1125 , m_primitiveTopology (topology)
1126 , m_vertices (vertices)
1127 , m_multisampleStateParams (multisampleStateParams)
1128 , m_colorBlendState (blendState)
1132 tcu::TestStatus SampleMaskInstance::iterate (void)
1134 de::MovePtr<tcu::TextureLevel> testSampleMaskImage;
1135 de::MovePtr<tcu::TextureLevel> minSampleMaskImage;
1136 de::MovePtr<tcu::TextureLevel> maxSampleMaskImage;
1138 // Render with test flags
1140 MultisampleRenderer renderer (m_context, m_colorFormat, m_renderSize, m_primitiveTopology, m_vertices, m_multisampleStateParams, m_colorBlendState);
1141 testSampleMaskImage = renderer.render();
1144 // Render with all flags off
1146 VkPipelineMultisampleStateCreateInfo multisampleParams = m_multisampleStateParams;
1147 const std::vector<VkSampleMask> sampleMask (multisampleParams.rasterizationSamples / 32, (VkSampleMask)0);
1149 multisampleParams.pSampleMask = sampleMask.data();
1151 MultisampleRenderer renderer (m_context, m_colorFormat, m_renderSize, m_primitiveTopology, m_vertices, multisampleParams, m_colorBlendState);
1152 minSampleMaskImage = renderer.render();
1155 // Render with all flags on
1157 VkPipelineMultisampleStateCreateInfo multisampleParams = m_multisampleStateParams;
1158 const std::vector<VkSampleMask> sampleMask (multisampleParams.rasterizationSamples / 32, ~((VkSampleMask)0));
1160 multisampleParams.pSampleMask = sampleMask.data();
1162 MultisampleRenderer renderer (m_context, m_colorFormat, m_renderSize, m_primitiveTopology, m_vertices, multisampleParams, m_colorBlendState);
1163 maxSampleMaskImage = renderer.render();
1166 return verifyImage(testSampleMaskImage->getAccess(), minSampleMaskImage->getAccess(), maxSampleMaskImage->getAccess());
1169 tcu::TestStatus SampleMaskInstance::verifyImage (const tcu::ConstPixelBufferAccess& testSampleMaskImage,
1170 const tcu::ConstPixelBufferAccess& minSampleMaskImage,
1171 const tcu::ConstPixelBufferAccess& maxSampleMaskImage)
1173 const deUint32 testColorCount = getUniqueColorsCount(testSampleMaskImage);
1174 const deUint32 minColorCount = getUniqueColorsCount(minSampleMaskImage);
1175 const deUint32 maxColorCount = getUniqueColorsCount(maxSampleMaskImage);
1177 tcu::TestLog& log = m_context.getTestContext().getLog();
1179 log << tcu::TestLog::Message
1180 << "\nColors found: " << testColorCount << "\n"
1181 << "Min. colors expected: " << minColorCount << "\n"
1182 << "Max. colors expected: " << maxColorCount << "\n"
1183 << tcu::TestLog::EndMessage;
1185 if (minColorCount > testColorCount || testColorCount > maxColorCount)
1186 return tcu::TestStatus::fail("Unique colors out of expected bounds");
1188 return tcu::TestStatus::pass("Unique colors within expected bounds");
1191 tcu::TestStatus testRasterSamplesConsistency (Context& context, GeometryType geometryType)
1193 // Use triangle only.
1194 DE_UNREF(geometryType);
1196 const VkSampleCountFlagBits samples[] =
1198 VK_SAMPLE_COUNT_1_BIT,
1199 VK_SAMPLE_COUNT_2_BIT,
1200 VK_SAMPLE_COUNT_4_BIT,
1201 VK_SAMPLE_COUNT_8_BIT,
1202 VK_SAMPLE_COUNT_16_BIT,
1203 VK_SAMPLE_COUNT_32_BIT,
1204 VK_SAMPLE_COUNT_64_BIT
1207 const Vertex4RGBA vertexData[3] =
1210 tcu::Vec4(-0.75f, 0.0f, 0.0f, 1.0f),
1211 tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f)
1214 tcu::Vec4(0.75f, 0.125f, 0.0f, 1.0f),
1215 tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f)
1218 tcu::Vec4(0.75f, -0.125f, 0.0f, 1.0f),
1219 tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f)
1223 const std::vector<Vertex4RGBA> vertices (vertexData, vertexData + 3);
1224 deUint32 prevUniqueColors = 2;
1225 int renderCount = 0;
1227 // Do not render with 1 sample (start with samplesNdx = 1).
1228 for (int samplesNdx = 1; samplesNdx < DE_LENGTH_OF_ARRAY(samples); samplesNdx++)
1230 if (!isSupportedSampleCount(context.getInstanceInterface(), context.getPhysicalDevice(), samples[samplesNdx]))
1233 const VkPipelineMultisampleStateCreateInfo multisampleStateParams =
1235 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, // VkStructureType sType;
1236 DE_NULL, // const void* pNext;
1237 0u, // VkPipelineMultisampleStateCreateFlags flags;
1238 samples[samplesNdx], // VkSampleCountFlagBits rasterizationSamples;
1239 false, // VkBool32 sampleShadingEnable;
1240 0.0f, // float minSampleShading;
1241 DE_NULL, // const VkSampleMask* pSampleMask;
1242 false, // VkBool32 alphaToCoverageEnable;
1243 false // VkBool32 alphaToOneEnable;
1246 MultisampleRenderer renderer (context, VK_FORMAT_R8G8B8A8_UNORM, tcu::IVec2(32, 32), VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, vertices, multisampleStateParams, getDefaultColorBlendAttachmentState());
1247 de::MovePtr<tcu::TextureLevel> result = renderer.render();
1248 const deUint32 uniqueColors = getUniqueColorsCount(result->getAccess());
1252 if (prevUniqueColors > uniqueColors)
1254 std::ostringstream message;
1256 message << "More unique colors generated with " << samples[samplesNdx - 1] << " than with " << samples[samplesNdx];
1257 return tcu::TestStatus::fail(message.str());
1260 prevUniqueColors = uniqueColors;
1263 if (renderCount == 0)
1264 throw tcu::NotSupportedError("Multisampling is unsupported");
1266 return tcu::TestStatus::pass("Number of unique colors increases as the sample count increases");
1270 // AlphaToOneInstance
1272 AlphaToOneInstance::AlphaToOneInstance (Context& context,
1273 VkPrimitiveTopology topology,
1274 const std::vector<Vertex4RGBA>& vertices,
1275 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
1276 const VkPipelineColorBlendAttachmentState& blendState)
1277 : vkt::TestInstance (context)
1278 , m_colorFormat (VK_FORMAT_R8G8B8A8_UNORM)
1279 , m_renderSize (32, 32)
1280 , m_primitiveTopology (topology)
1281 , m_vertices (vertices)
1282 , m_multisampleStateParams (multisampleStateParams)
1283 , m_colorBlendState (blendState)
1285 VkPhysicalDeviceFeatures deviceFeatures;
1287 context.getInstanceInterface().getPhysicalDeviceFeatures(context.getPhysicalDevice(), &deviceFeatures);
1289 if (!deviceFeatures.alphaToOne)
1290 throw tcu::NotSupportedError("Alpha-to-one is not supported");
1293 tcu::TestStatus AlphaToOneInstance::iterate (void)
1295 DE_ASSERT(m_multisampleStateParams.alphaToOneEnable);
1296 DE_ASSERT(m_colorBlendState.blendEnable);
1298 de::MovePtr<tcu::TextureLevel> alphaOneImage;
1299 de::MovePtr<tcu::TextureLevel> noAlphaOneImage;
1301 // Render with blend enabled and alpha to one on
1303 MultisampleRenderer renderer (m_context, m_colorFormat, m_renderSize, m_primitiveTopology, m_vertices, m_multisampleStateParams, m_colorBlendState);
1304 alphaOneImage = renderer.render();
1307 // Render with blend enabled and alpha to one off
1309 VkPipelineMultisampleStateCreateInfo multisampleParams = m_multisampleStateParams;
1310 multisampleParams.alphaToOneEnable = false;
1312 MultisampleRenderer renderer (m_context, m_colorFormat, m_renderSize, m_primitiveTopology, m_vertices, multisampleParams, m_colorBlendState);
1313 noAlphaOneImage = renderer.render();
1316 return verifyImage(alphaOneImage->getAccess(), noAlphaOneImage->getAccess());
1319 tcu::TestStatus AlphaToOneInstance::verifyImage (const tcu::ConstPixelBufferAccess& alphaOneImage,
1320 const tcu::ConstPixelBufferAccess& noAlphaOneImage)
1322 for (int y = 0; y < m_renderSize.y(); y++)
1324 for (int x = 0; x < m_renderSize.x(); x++)
1326 if (!tcu::boolAll(tcu::greaterThanEqual(alphaOneImage.getPixel(x, y), noAlphaOneImage.getPixel(x, y))))
1328 std::ostringstream message;
1329 message << "Unsatisfied condition: " << alphaOneImage.getPixel(x, y) << " >= " << noAlphaOneImage.getPixel(x, y);
1330 return tcu::TestStatus::fail(message.str());
1335 return tcu::TestStatus::pass("Image rendered with alpha-to-one contains pixels of image rendered with no alpha-to-one");
1339 // AlphaToCoverageInstance
1341 AlphaToCoverageInstance::AlphaToCoverageInstance (Context& context,
1342 VkPrimitiveTopology topology,
1343 const std::vector<Vertex4RGBA>& vertices,
1344 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
1345 const VkPipelineColorBlendAttachmentState& blendState,
1346 GeometryType geometryType)
1347 : vkt::TestInstance (context)
1348 , m_colorFormat (VK_FORMAT_R8G8B8A8_UNORM)
1349 , m_renderSize (32, 32)
1350 , m_primitiveTopology (topology)
1351 , m_vertices (vertices)
1352 , m_multisampleStateParams (multisampleStateParams)
1353 , m_colorBlendState (blendState)
1354 , m_geometryType (geometryType)
1358 tcu::TestStatus AlphaToCoverageInstance::iterate (void)
1360 DE_ASSERT(m_multisampleStateParams.alphaToCoverageEnable);
1362 de::MovePtr<tcu::TextureLevel> result;
1363 MultisampleRenderer renderer (m_context, m_colorFormat, m_renderSize, m_primitiveTopology, m_vertices, m_multisampleStateParams, m_colorBlendState);
1365 result = renderer.render();
1367 return verifyImage(result->getAccess());
1370 tcu::TestStatus AlphaToCoverageInstance::verifyImage (const tcu::ConstPixelBufferAccess& result)
1372 float maxColorValue;
1374 switch (m_geometryType)
1376 case GEOMETRY_TYPE_OPAQUE_QUAD:
1377 maxColorValue = 1.01f;
1380 case GEOMETRY_TYPE_TRANSLUCENT_QUAD:
1381 maxColorValue = 0.52f;
1384 case GEOMETRY_TYPE_INVISIBLE_QUAD:
1385 maxColorValue = 0.01f;
1389 maxColorValue = 0.0f;
1393 for (int y = 0; y < m_renderSize.y(); y++)
1395 for (int x = 0; x < m_renderSize.x(); x++)
1397 if (result.getPixel(x, y).x() > maxColorValue)
1399 std::ostringstream message;
1400 message << "Pixel is not below the threshold value (" << result.getPixel(x, y).x() << " > " << maxColorValue << ")";
1401 return tcu::TestStatus::fail(message.str());
1406 return tcu::TestStatus::pass("Image matches reference value");
1410 // MultisampleRenderer
1412 MultisampleRenderer::MultisampleRenderer (Context& context,
1413 const VkFormat colorFormat,
1414 const tcu::IVec2& renderSize,
1415 const VkPrimitiveTopology topology,
1416 const std::vector<Vertex4RGBA>& vertices,
1417 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
1418 const VkPipelineColorBlendAttachmentState& blendState)
1419 : m_context (context)
1420 , m_colorFormat (colorFormat)
1421 , m_depthStencilFormat (VK_FORMAT_UNDEFINED)
1422 , m_renderSize (renderSize)
1423 , m_useDepth (false)
1424 , m_useStencil (false)
1425 , m_multisampleStateParams (multisampleStateParams)
1426 , m_colorBlendState (blendState)
1428 initialize(context, 1u, &topology, &vertices);
1431 MultisampleRenderer::MultisampleRenderer (Context& context,
1432 const VkFormat colorFormat,
1433 const VkFormat depthStencilFormat,
1434 const tcu::IVec2& renderSize,
1435 const bool useDepth,
1436 const bool useStencil,
1437 const deUint32 numTopologies,
1438 const VkPrimitiveTopology* pTopology,
1439 const std::vector<Vertex4RGBA>* pVertices,
1440 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
1441 const VkPipelineColorBlendAttachmentState& blendState)
1442 : m_context (context)
1443 , m_colorFormat (colorFormat)
1444 , m_depthStencilFormat (depthStencilFormat)
1445 , m_renderSize (renderSize)
1446 , m_useDepth (useDepth)
1447 , m_useStencil (useStencil)
1448 , m_multisampleStateParams (multisampleStateParams)
1449 , m_colorBlendState (blendState)
1451 initialize(context, numTopologies, pTopology, pVertices);
1454 void MultisampleRenderer::initialize (Context& context,
1455 const deUint32 numTopologies,
1456 const VkPrimitiveTopology* pTopology,
1457 const std::vector<Vertex4RGBA>* pVertices)
1459 if (!isSupportedSampleCount(context.getInstanceInterface(), context.getPhysicalDevice(), m_multisampleStateParams.rasterizationSamples))
1460 throw tcu::NotSupportedError("Unsupported number of rasterization samples");
1462 const DeviceInterface& vk = context.getDeviceInterface();
1463 const VkDevice vkDevice = context.getDevice();
1464 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
1465 SimpleAllocator memAlloc (vk, vkDevice, getPhysicalDeviceMemoryProperties(context.getInstanceInterface(), context.getPhysicalDevice()));
1466 const VkComponentMapping componentMappingRGBA = { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A };
1468 // Create color image
1470 const VkImageCreateInfo colorImageParams =
1472 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType;
1473 DE_NULL, // const void* pNext;
1474 0u, // VkImageCreateFlags flags;
1475 VK_IMAGE_TYPE_2D, // VkImageType imageType;
1476 m_colorFormat, // VkFormat format;
1477 { (deUint32)m_renderSize.x(), (deUint32)m_renderSize.y(), 1u }, // VkExtent3D extent;
1478 1u, // deUint32 mipLevels;
1479 1u, // deUint32 arrayLayers;
1480 m_multisampleStateParams.rasterizationSamples, // VkSampleCountFlagBits samples;
1481 VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling;
1482 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, // VkImageUsageFlags usage;
1483 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
1484 1u, // deUint32 queueFamilyIndexCount;
1485 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
1486 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout;
1489 m_colorImage = createImage(vk, vkDevice, &colorImageParams);
1491 // Allocate and bind color image memory
1492 m_colorImageAlloc = memAlloc.allocate(getImageMemoryRequirements(vk, vkDevice, *m_colorImage), MemoryRequirement::Any);
1493 VK_CHECK(vk.bindImageMemory(vkDevice, *m_colorImage, m_colorImageAlloc->getMemory(), m_colorImageAlloc->getOffset()));
1496 // Create resolve image
1498 const VkImageCreateInfo resolveImageParams =
1500 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType;
1501 DE_NULL, // const void* pNext;
1502 0u, // VkImageCreateFlags flags;
1503 VK_IMAGE_TYPE_2D, // VkImageType imageType;
1504 m_colorFormat, // VkFormat format;
1505 { (deUint32)m_renderSize.x(), (deUint32)m_renderSize.y(), 1u }, // VkExtent3D extent;
1506 1u, // deUint32 mipLevels;
1507 1u, // deUint32 arrayLayers;
1508 VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits samples;
1509 VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling;
1510 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | // VkImageUsageFlags usage;
1511 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
1512 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
1513 1u, // deUint32 queueFamilyIndexCount;
1514 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
1515 VK_IMAGE_LAYOUT_UNDEFINED // VkImageLayout initialLayout;
1518 m_resolveImage = createImage(vk, vkDevice, &resolveImageParams);
1520 // Allocate and bind resolve image memory
1521 m_resolveImageAlloc = memAlloc.allocate(getImageMemoryRequirements(vk, vkDevice, *m_resolveImage), MemoryRequirement::Any);
1522 VK_CHECK(vk.bindImageMemory(vkDevice, *m_resolveImage, m_resolveImageAlloc->getMemory(), m_resolveImageAlloc->getOffset()));
1525 // Create a depth/stencil image
1526 if (m_useDepth || m_useStencil)
1528 const VkImageCreateInfo depthStencilImageParams =
1530 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType;
1531 DE_NULL, // const void* pNext;
1532 0u, // VkImageCreateFlags flags;
1533 VK_IMAGE_TYPE_2D, // VkImageType imageType;
1534 m_depthStencilFormat, // VkFormat format;
1535 { (deUint32)m_renderSize.x(), (deUint32)m_renderSize.y(), 1u }, // VkExtent3D extent;
1536 1u, // deUint32 mipLevels;
1537 1u, // deUint32 arrayLayers;
1538 m_multisampleStateParams.rasterizationSamples, // VkSampleCountFlagBits samples;
1539 VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling;
1540 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, // VkImageUsageFlags usage;
1541 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
1542 1u, // deUint32 queueFamilyIndexCount;
1543 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
1544 VK_IMAGE_LAYOUT_UNDEFINED // VkImageLayout initialLayout;
1547 m_depthStencilImage = createImage(vk, vkDevice, &depthStencilImageParams);
1549 // Allocate and bind depth/stencil image memory
1550 m_depthStencilImageAlloc = memAlloc.allocate(getImageMemoryRequirements(vk, vkDevice, *m_depthStencilImage), MemoryRequirement::Any);
1551 VK_CHECK(vk.bindImageMemory(vkDevice, *m_depthStencilImage, m_depthStencilImageAlloc->getMemory(), m_depthStencilImageAlloc->getOffset()));
1554 // Create color attachment view
1556 const VkImageViewCreateInfo colorAttachmentViewParams =
1558 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, // VkStructureType sType;
1559 DE_NULL, // const void* pNext;
1560 0u, // VkImageViewCreateFlags flags;
1561 *m_colorImage, // VkImage image;
1562 VK_IMAGE_VIEW_TYPE_2D, // VkImageViewType viewType;
1563 m_colorFormat, // VkFormat format;
1564 componentMappingRGBA, // VkComponentMapping components;
1565 { VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, 1u } // VkImageSubresourceRange subresourceRange;
1568 m_colorAttachmentView = createImageView(vk, vkDevice, &colorAttachmentViewParams);
1571 // Create resolve attachment view
1573 const VkImageViewCreateInfo resolveAttachmentViewParams =
1575 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, // VkStructureType sType;
1576 DE_NULL, // const void* pNext;
1577 0u, // VkImageViewCreateFlags flags;
1578 *m_resolveImage, // VkImage image;
1579 VK_IMAGE_VIEW_TYPE_2D, // VkImageViewType viewType;
1580 m_colorFormat, // VkFormat format;
1581 componentMappingRGBA, // VkComponentMapping components;
1582 { VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, 1u } // VkImageSubresourceRange subresourceRange;
1585 m_resolveAttachmentView = createImageView(vk, vkDevice, &resolveAttachmentViewParams);
1588 VkImageAspectFlags depthStencilAttachmentAspect = (VkImageAspectFlagBits)0;
1589 const deUint32 numUsedAttachments = (m_useDepth || m_useStencil ? 3u : 2u);
1591 // Create depth/stencil attachment view
1592 if (m_useDepth || m_useStencil)
1594 depthStencilAttachmentAspect = getImageAspectFlags(m_depthStencilFormat);
1596 const VkImageViewCreateInfo depthStencilAttachmentViewParams =
1598 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, // VkStructureType sType;
1599 DE_NULL, // const void* pNext;
1600 0u, // VkImageViewCreateFlags flags;
1601 *m_depthStencilImage, // VkImage image;
1602 VK_IMAGE_VIEW_TYPE_2D, // VkImageViewType viewType;
1603 m_depthStencilFormat, // VkFormat format;
1604 componentMappingRGBA, // VkComponentMapping components;
1605 { depthStencilAttachmentAspect, 0u, 1u, 0u, 1u } // VkImageSubresourceRange subresourceRange;
1608 m_depthStencilAttachmentView = createImageView(vk, vkDevice, &depthStencilAttachmentViewParams);
1611 // Create render pass
1613 const VkAttachmentDescription attachmentDescriptions[3] =
1616 0u, // VkAttachmentDescriptionFlags flags;
1617 m_colorFormat, // VkFormat format;
1618 m_multisampleStateParams.rasterizationSamples, // VkSampleCountFlagBits samples;
1619 VK_ATTACHMENT_LOAD_OP_CLEAR, // VkAttachmentLoadOp loadOp;
1620 VK_ATTACHMENT_STORE_OP_STORE, // VkAttachmentStoreOp storeOp;
1621 VK_ATTACHMENT_LOAD_OP_DONT_CARE, // VkAttachmentLoadOp stencilLoadOp;
1622 VK_ATTACHMENT_STORE_OP_DONT_CARE, // VkAttachmentStoreOp stencilStoreOp;
1623 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout initialLayout;
1624 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL // VkImageLayout finalLayout;
1627 0u, // VkAttachmentDescriptionFlags flags;
1628 m_colorFormat, // VkFormat format;
1629 VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits samples;
1630 VK_ATTACHMENT_LOAD_OP_CLEAR, // VkAttachmentLoadOp loadOp;
1631 VK_ATTACHMENT_STORE_OP_STORE, // VkAttachmentStoreOp storeOp;
1632 VK_ATTACHMENT_LOAD_OP_DONT_CARE, // VkAttachmentLoadOp stencilLoadOp;
1633 VK_ATTACHMENT_STORE_OP_DONT_CARE, // VkAttachmentStoreOp stencilStoreOp;
1634 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout initialLayout;
1635 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL // VkImageLayout finalLayout;
1638 0u, // VkAttachmentDescriptionFlags flags;
1639 m_depthStencilFormat, // VkFormat format;
1640 m_multisampleStateParams.rasterizationSamples, // VkSampleCountFlagBits samples;
1641 (m_useDepth ? VK_ATTACHMENT_LOAD_OP_CLEAR : VK_ATTACHMENT_LOAD_OP_DONT_CARE), // VkAttachmentLoadOp loadOp;
1642 (m_useDepth ? VK_ATTACHMENT_STORE_OP_STORE : VK_ATTACHMENT_STORE_OP_DONT_CARE), // VkAttachmentStoreOp storeOp;
1643 (m_useStencil ? VK_ATTACHMENT_LOAD_OP_CLEAR : VK_ATTACHMENT_LOAD_OP_DONT_CARE), // VkAttachmentStoreOp stencilLoadOp;
1644 (m_useStencil ? VK_ATTACHMENT_STORE_OP_STORE : VK_ATTACHMENT_STORE_OP_DONT_CARE), // VkAttachmentStoreOp stencilStoreOp;
1645 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, // VkImageLayout initialLayout;
1646 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL // VkImageLayout finalLayout;
1650 const VkAttachmentReference colorAttachmentReference =
1652 0u, // deUint32 attachment;
1653 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL // VkImageLayout layout;
1656 const VkAttachmentReference resolveAttachmentReference =
1658 1u, // deUint32 attachment;
1659 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL // VkImageLayout layout;
1662 const VkAttachmentReference depthStencilAttachmentReference =
1664 2u, // deUint32 attachment;
1665 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL // VkImageLayout layout;
1668 const VkSubpassDescription subpassDescription =
1670 0u, // VkSubpassDescriptionFlags flags;
1671 VK_PIPELINE_BIND_POINT_GRAPHICS, // VkPipelineBindPoint pipelineBindPoint;
1672 0u, // deUint32 inputAttachmentCount;
1673 DE_NULL, // const VkAttachmentReference* pInputAttachments;
1674 1u, // deUint32 colorAttachmentCount;
1675 &colorAttachmentReference, // const VkAttachmentReference* pColorAttachments;
1676 &resolveAttachmentReference, // const VkAttachmentReference* pResolveAttachments;
1677 (m_useDepth || m_useStencil ? &depthStencilAttachmentReference : DE_NULL), // const VkAttachmentReference* pDepthStencilAttachment;
1678 0u, // deUint32 preserveAttachmentCount;
1679 DE_NULL // const VkAttachmentReference* pPreserveAttachments;
1682 const VkRenderPassCreateInfo renderPassParams =
1684 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, // VkStructureType sType;
1685 DE_NULL, // const void* pNext;
1686 0u, // VkRenderPassCreateFlags flags;
1687 numUsedAttachments, // deUint32 attachmentCount;
1688 attachmentDescriptions, // const VkAttachmentDescription* pAttachments;
1689 1u, // deUint32 subpassCount;
1690 &subpassDescription, // const VkSubpassDescription* pSubpasses;
1691 0u, // deUint32 dependencyCount;
1692 DE_NULL // const VkSubpassDependency* pDependencies;
1695 m_renderPass = createRenderPass(vk, vkDevice, &renderPassParams);
1698 // Create framebuffer
1700 const VkImageView attachments[3] =
1702 *m_colorAttachmentView,
1703 *m_resolveAttachmentView,
1704 *m_depthStencilAttachmentView
1707 const VkFramebufferCreateInfo framebufferParams =
1709 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, // VkStructureType sType;
1710 DE_NULL, // const void* pNext;
1711 0u, // VkFramebufferCreateFlags flags;
1712 *m_renderPass, // VkRenderPass renderPass;
1713 numUsedAttachments, // deUint32 attachmentCount;
1714 attachments, // const VkImageView* pAttachments;
1715 (deUint32)m_renderSize.x(), // deUint32 width;
1716 (deUint32)m_renderSize.y(), // deUint32 height;
1717 1u // deUint32 layers;
1720 m_framebuffer = createFramebuffer(vk, vkDevice, &framebufferParams);
1723 // Create pipeline layout
1725 const VkPipelineLayoutCreateInfo pipelineLayoutParams =
1727 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, // VkStructureType sType;
1728 DE_NULL, // const void* pNext;
1729 0u, // VkPipelineLayoutCreateFlags flags;
1730 0u, // deUint32 setLayoutCount;
1731 DE_NULL, // const VkDescriptorSetLayout* pSetLayouts;
1732 0u, // deUint32 pushConstantRangeCount;
1733 DE_NULL // const VkPushConstantRange* pPushConstantRanges;
1736 m_pipelineLayout = createPipelineLayout(vk, vkDevice, &pipelineLayoutParams);
1739 m_vertexShaderModule = createShaderModule(vk, vkDevice, m_context.getBinaryCollection().get("color_vert"), 0);
1740 m_fragmentShaderModule = createShaderModule(vk, vkDevice, m_context.getBinaryCollection().get("color_frag"), 0);
1744 const VkPipelineShaderStageCreateInfo shaderStageParams[2] =
1747 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, // VkStructureType sType;
1748 DE_NULL, // const void* pNext;
1749 0u, // VkPipelineShaderStageCreateFlags flags;
1750 VK_SHADER_STAGE_VERTEX_BIT, // VkShaderStageFlagBits stage;
1751 *m_vertexShaderModule, // VkShaderModule module;
1752 "main", // const char* pName;
1753 DE_NULL // const VkSpecializationInfo* pSpecializationInfo;
1756 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, // VkStructureType sType;
1757 DE_NULL, // const void* pNext;
1758 0u, // VkPipelineShaderStageCreateFlags flags;
1759 VK_SHADER_STAGE_FRAGMENT_BIT, // VkShaderStageFlagBits stage;
1760 *m_fragmentShaderModule, // VkShaderModule module;
1761 "main", // const char* pName;
1762 DE_NULL // const VkSpecializationInfo* pSpecializationInfo;
1766 const VkVertexInputBindingDescription vertexInputBindingDescription =
1768 0u, // deUint32 binding;
1769 sizeof(Vertex4RGBA), // deUint32 stride;
1770 VK_VERTEX_INPUT_RATE_VERTEX // VkVertexInputRate inputRate;
1773 const VkVertexInputAttributeDescription vertexInputAttributeDescriptions[2] =
1776 0u, // deUint32 location;
1777 0u, // deUint32 binding;
1778 VK_FORMAT_R32G32B32A32_SFLOAT, // VkFormat format;
1779 0u // deUint32 offset;
1782 1u, // deUint32 location;
1783 0u, // deUint32 binding;
1784 VK_FORMAT_R32G32B32A32_SFLOAT, // VkFormat format;
1785 DE_OFFSET_OF(Vertex4RGBA, color), // deUint32 offset;
1789 const VkPipelineVertexInputStateCreateInfo vertexInputStateParams =
1791 VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO, // VkStructureType sType;
1792 DE_NULL, // const void* pNext;
1793 0u, // VkPipelineVertexInputStateCreateFlags flags;
1794 1u, // deUint32 vertexBindingDescriptionCount;
1795 &vertexInputBindingDescription, // const VkVertexInputBindingDescription* pVertexBindingDescriptions;
1796 2u, // deUint32 vertexAttributeDescriptionCount;
1797 vertexInputAttributeDescriptions // const VkVertexInputAttributeDescription* pVertexAttributeDescriptions;
1800 // Topology is set before the pipeline creation.
1801 VkPipelineInputAssemblyStateCreateInfo inputAssemblyStateParams =
1803 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, // VkStructureType sType;
1804 DE_NULL, // const void* pNext;
1805 0u, // VkPipelineInputAssemblyStateCreateFlags flags;
1806 VK_PRIMITIVE_TOPOLOGY_LAST, // VkPrimitiveTopology topology;
1807 false // VkBool32 primitiveRestartEnable;
1810 const VkViewport viewport =
1814 (float)m_renderSize.x(), // float width;
1815 (float)m_renderSize.y(), // float height;
1816 0.0f, // float minDepth;
1817 1.0f // float maxDepth;
1820 const VkRect2D scissor =
1822 { 0, 0 }, // VkOffset2D offset;
1823 { (deUint32)m_renderSize.x(), (deUint32)m_renderSize.y() } // VkExtent2D extent;
1826 const VkPipelineViewportStateCreateInfo viewportStateParams =
1828 VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO, // VkStructureType sType;
1829 DE_NULL, // const void* pNext;
1830 0u, // VkPipelineViewportStateCreateFlags flags;
1831 1u, // deUint32 viewportCount;
1832 &viewport, // const VkViewport* pViewports;
1833 1u, // deUint32 scissorCount;
1834 &scissor // const VkRect2D* pScissors;
1837 const VkPipelineRasterizationStateCreateInfo rasterStateParams =
1839 VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO, // VkStructureType sType;
1840 DE_NULL, // const void* pNext;
1841 0u, // VkPipelineRasterizationStateCreateFlags flags;
1842 false, // VkBool32 depthClampEnable;
1843 false, // VkBool32 rasterizerDiscardEnable;
1844 VK_POLYGON_MODE_FILL, // VkPolygonMode polygonMode;
1845 VK_CULL_MODE_NONE, // VkCullModeFlags cullMode;
1846 VK_FRONT_FACE_COUNTER_CLOCKWISE, // VkFrontFace frontFace;
1847 VK_FALSE, // VkBool32 depthBiasEnable;
1848 0.0f, // float depthBiasConstantFactor;
1849 0.0f, // float depthBiasClamp;
1850 0.0f, // float depthBiasSlopeFactor;
1851 1.0f // float lineWidth;
1854 const VkPipelineColorBlendStateCreateInfo colorBlendStateParams =
1856 VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO, // VkStructureType sType;
1857 DE_NULL, // const void* pNext;
1858 0u, // VkPipelineColorBlendStateCreateFlags flags;
1859 false, // VkBool32 logicOpEnable;
1860 VK_LOGIC_OP_COPY, // VkLogicOp logicOp;
1861 1u, // deUint32 attachmentCount;
1862 &m_colorBlendState, // const VkPipelineColorBlendAttachmentState* pAttachments;
1863 { 0.0f, 0.0f, 0.0f, 0.0f } // float blendConstants[4];
1866 const VkStencilOpState stencilOpState =
1868 VK_STENCIL_OP_KEEP, // VkStencilOp failOp;
1869 VK_STENCIL_OP_REPLACE, // VkStencilOp passOp;
1870 VK_STENCIL_OP_KEEP, // VkStencilOp depthFailOp;
1871 VK_COMPARE_OP_GREATER, // VkCompareOp compareOp;
1872 1u, // deUint32 compareMask;
1873 1u, // deUint32 writeMask;
1874 1u, // deUint32 reference;
1877 const VkPipelineDepthStencilStateCreateInfo depthStencilStateParams =
1879 VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO, // VkStructureType sType;
1880 DE_NULL, // const void* pNext;
1881 0u, // VkPipelineDepthStencilStateCreateFlags flags;
1882 m_useDepth, // VkBool32 depthTestEnable;
1883 m_useDepth, // VkBool32 depthWriteEnable;
1884 VK_COMPARE_OP_LESS, // VkCompareOp depthCompareOp;
1885 false, // VkBool32 depthBoundsTestEnable;
1886 m_useStencil, // VkBool32 stencilTestEnable;
1887 stencilOpState, // VkStencilOpState front;
1888 stencilOpState, // VkStencilOpState back;
1889 0.0f, // float minDepthBounds;
1890 1.0f, // float maxDepthBounds;
1893 const VkGraphicsPipelineCreateInfo graphicsPipelineParams =
1895 VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO, // VkStructureType sType;
1896 DE_NULL, // const void* pNext;
1897 0u, // VkPipelineCreateFlags flags;
1898 2u, // deUint32 stageCount;
1899 shaderStageParams, // const VkPipelineShaderStageCreateInfo* pStages;
1900 &vertexInputStateParams, // const VkPipelineVertexInputStateCreateInfo* pVertexInputState;
1901 &inputAssemblyStateParams, // const VkPipelineInputAssemblyStateCreateInfo* pInputAssemblyState;
1902 DE_NULL, // const VkPipelineTessellationStateCreateInfo* pTessellationState;
1903 &viewportStateParams, // const VkPipelineViewportStateCreateInfo* pViewportState;
1904 &rasterStateParams, // const VkPipelineRasterizationStateCreateInfo* pRasterizationState;
1905 &m_multisampleStateParams, // const VkPipelineMultisampleStateCreateInfo* pMultisampleState;
1906 &depthStencilStateParams, // const VkPipelineDepthStencilStateCreateInfo* pDepthStencilState;
1907 &colorBlendStateParams, // const VkPipelineColorBlendStateCreateInfo* pColorBlendState;
1908 (const VkPipelineDynamicStateCreateInfo*)DE_NULL, // const VkPipelineDynamicStateCreateInfo* pDynamicState;
1909 *m_pipelineLayout, // VkPipelineLayout layout;
1910 *m_renderPass, // VkRenderPass renderPass;
1911 0u, // deUint32 subpass;
1912 0u, // VkPipeline basePipelineHandle;
1913 0u // deInt32 basePipelineIndex;
1916 for (deUint32 i = 0u; i < numTopologies; ++i)
1918 inputAssemblyStateParams.topology = pTopology[i];
1919 m_graphicsPipelines.push_back(VkPipelineSp(new Unique<VkPipeline>(createGraphicsPipeline(vk, vkDevice, DE_NULL, &graphicsPipelineParams))));
1923 // Create vertex buffer
1925 const VkBufferCreateInfo vertexBufferParams =
1927 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
1928 DE_NULL, // const void* pNext;
1929 0u, // VkBufferCreateFlags flags;
1930 1024u, // VkDeviceSize size;
1931 VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, // VkBufferUsageFlags usage;
1932 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
1933 1u, // deUint32 queueFamilyIndexCount;
1934 &queueFamilyIndex // const deUint32* pQueueFamilyIndices;
1937 m_vertexBuffer = createBuffer(vk, vkDevice, &vertexBufferParams);
1938 m_vertexBufferAlloc = memAlloc.allocate(getBufferMemoryRequirements(vk, vkDevice, *m_vertexBuffer), MemoryRequirement::HostVisible);
1940 VK_CHECK(vk.bindBufferMemory(vkDevice, *m_vertexBuffer, m_vertexBufferAlloc->getMemory(), m_vertexBufferAlloc->getOffset()));
1942 // Load vertices into vertex buffer
1944 Vertex4RGBA* pDst = static_cast<Vertex4RGBA*>(m_vertexBufferAlloc->getHostPtr());
1945 for (deUint32 i = 0u; i < numTopologies; ++i)
1947 deMemcpy(pDst, &pVertices[i][0], pVertices[i].size() * sizeof(Vertex4RGBA));
1948 pDst += pVertices[i].size();
1951 flushMappedMemoryRange(vk, vkDevice, m_vertexBufferAlloc->getMemory(), m_vertexBufferAlloc->getOffset(), vertexBufferParams.size);
1954 // Create command pool
1955 m_cmdPool = createCommandPool(vk, vkDevice, VK_COMMAND_POOL_CREATE_TRANSIENT_BIT, queueFamilyIndex);
1957 // Create command buffer
1959 const VkCommandBufferBeginInfo cmdBufferBeginInfo =
1961 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType;
1962 DE_NULL, // const void* pNext;
1963 0u, // VkCommandBufferUsageFlags flags;
1964 (const VkCommandBufferInheritanceInfo*)DE_NULL,
1967 VkClearValue colorClearValue;
1968 colorClearValue.color.float32[0] = 0.0f;
1969 colorClearValue.color.float32[1] = 0.0f;
1970 colorClearValue.color.float32[2] = 0.0f;
1971 colorClearValue.color.float32[3] = 0.0f;
1973 VkClearValue depthStencilClearValue;
1974 depthStencilClearValue.depthStencil.depth = 1.0f;
1975 depthStencilClearValue.depthStencil.stencil = 0u;
1977 const VkClearValue clearValues[3] =
1981 depthStencilClearValue
1984 const VkRenderPassBeginInfo renderPassBeginInfo =
1986 VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, // VkStructureType sType;
1987 DE_NULL, // const void* pNext;
1988 *m_renderPass, // VkRenderPass renderPass;
1989 *m_framebuffer, // VkFramebuffer framebuffer;
1992 { (deUint32)m_renderSize.x(), (deUint32)m_renderSize.y() }
1993 }, // VkRect2D renderArea;
1994 numUsedAttachments, // deUint32 clearValueCount;
1995 clearValues // const VkClearValue* pClearValues;
1998 const VkImageMemoryBarrier imageLayoutBarriers[] =
2000 // color attachment image
2002 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
2003 DE_NULL, // const void* pNext;
2004 0u, // VkAccessFlags srcAccessMask;
2005 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, // VkAccessFlags dstAccessMask;
2006 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout oldLayout;
2007 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout newLayout;
2008 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
2009 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
2010 *m_colorImage, // VkImage image;
2011 { VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, 1u }, // VkImageSubresourceRange subresourceRange;
2013 // resolve attachment image
2015 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
2016 DE_NULL, // const void* pNext;
2017 0u, // VkAccessFlags srcAccessMask;
2018 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, // VkAccessFlags dstAccessMask;
2019 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout oldLayout;
2020 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout newLayout;
2021 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
2022 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
2023 *m_resolveImage, // VkImage image;
2024 { VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, 1u }, // VkImageSubresourceRange subresourceRange;
2026 // depth/stencil attachment image
2028 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
2029 DE_NULL, // const void* pNext;
2030 0u, // VkAccessFlags srcAccessMask;
2031 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, // VkAccessFlags dstAccessMask;
2032 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout oldLayout;
2033 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, // VkImageLayout newLayout;
2034 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
2035 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
2036 *m_depthStencilImage, // VkImage image;
2037 { depthStencilAttachmentAspect, 0u, 1u, 0u, 1u }, // VkImageSubresourceRange subresourceRange;
2041 m_cmdBuffer = allocateCommandBuffer(vk, vkDevice, *m_cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY);
2043 VK_CHECK(vk.beginCommandBuffer(*m_cmdBuffer, &cmdBufferBeginInfo));
2045 vk.cmdPipelineBarrier(*m_cmdBuffer, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, (VkDependencyFlags)0,
2046 0u, DE_NULL, 0u, DE_NULL, numUsedAttachments, imageLayoutBarriers);
2048 vk.cmdBeginRenderPass(*m_cmdBuffer, &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
2050 VkDeviceSize vertexBufferOffset = 0u;
2052 for (deUint32 i = 0u; i < numTopologies; ++i)
2054 vk.cmdBindPipeline(*m_cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, **m_graphicsPipelines[i]);
2055 vk.cmdBindVertexBuffers(*m_cmdBuffer, 0, 1, &m_vertexBuffer.get(), &vertexBufferOffset);
2056 vk.cmdDraw(*m_cmdBuffer, (deUint32)pVertices[i].size(), 1, 0, 0);
2058 vertexBufferOffset += static_cast<VkDeviceSize>(pVertices[i].size() * sizeof(Vertex4RGBA));
2061 vk.cmdEndRenderPass(*m_cmdBuffer);
2063 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
2067 m_fence = createFence(vk, vkDevice);
2070 MultisampleRenderer::~MultisampleRenderer (void)
2074 de::MovePtr<tcu::TextureLevel> MultisampleRenderer::render (void)
2076 const DeviceInterface& vk = m_context.getDeviceInterface();
2077 const VkDevice vkDevice = m_context.getDevice();
2078 const VkQueue queue = m_context.getUniversalQueue();
2079 const deUint32 queueFamilyIndex = m_context.getUniversalQueueFamilyIndex();
2080 SimpleAllocator allocator (vk, vkDevice, getPhysicalDeviceMemoryProperties(m_context.getInstanceInterface(), m_context.getPhysicalDevice()));
2081 const VkSubmitInfo submitInfo =
2083 VK_STRUCTURE_TYPE_SUBMIT_INFO, // VkStructureType sType;
2084 DE_NULL, // const void* pNext;
2085 0u, // deUint32 waitSemaphoreCount;
2086 DE_NULL, // const VkSemaphore* pWaitSemaphores;
2087 (const VkPipelineStageFlags*)DE_NULL,
2088 1u, // deUint32 commandBufferCount;
2089 &m_cmdBuffer.get(), // const VkCommandBuffer* pCommandBuffers;
2090 0u, // deUint32 signalSemaphoreCount;
2091 DE_NULL // const VkSemaphore* pSignalSemaphores;
2094 VK_CHECK(vk.resetFences(vkDevice, 1, &m_fence.get()));
2095 VK_CHECK(vk.queueSubmit(queue, 1, &submitInfo, *m_fence));
2096 VK_CHECK(vk.waitForFences(vkDevice, 1, &m_fence.get(), true, ~(0ull) /* infinity*/));
2098 return readColorAttachment(vk, vkDevice, queue, queueFamilyIndex, allocator, *m_resolveImage, m_colorFormat, m_renderSize.cast<deUint32>());
2103 tcu::TestCaseGroup* createMultisampleTests (tcu::TestContext& testCtx)
2105 const VkSampleCountFlagBits samples[] =
2107 VK_SAMPLE_COUNT_2_BIT,
2108 VK_SAMPLE_COUNT_4_BIT,
2109 VK_SAMPLE_COUNT_8_BIT,
2110 VK_SAMPLE_COUNT_16_BIT,
2111 VK_SAMPLE_COUNT_32_BIT,
2112 VK_SAMPLE_COUNT_64_BIT
2115 de::MovePtr<tcu::TestCaseGroup> multisampleTests (new tcu::TestCaseGroup(testCtx, "multisample", ""));
2117 // Rasterization samples tests
2119 de::MovePtr<tcu::TestCaseGroup> rasterizationSamplesTests(new tcu::TestCaseGroup(testCtx, "raster_samples", ""));
2121 for (int samplesNdx = 0; samplesNdx < DE_LENGTH_OF_ARRAY(samples); samplesNdx++)
2123 std::ostringstream caseName;
2124 caseName << "samples_" << samples[samplesNdx];
2126 de::MovePtr<tcu::TestCaseGroup> samplesTests (new tcu::TestCaseGroup(testCtx, caseName.str().c_str(), ""));
2128 samplesTests->addChild(new RasterizationSamplesTest(testCtx, "primitive_triangle", "", samples[samplesNdx], GEOMETRY_TYPE_OPAQUE_TRIANGLE));
2129 samplesTests->addChild(new RasterizationSamplesTest(testCtx, "primitive_line", "", samples[samplesNdx], GEOMETRY_TYPE_OPAQUE_LINE));
2130 samplesTests->addChild(new RasterizationSamplesTest(testCtx, "primitive_point", "", samples[samplesNdx], GEOMETRY_TYPE_OPAQUE_POINT));
2132 samplesTests->addChild(new RasterizationSamplesTest(testCtx, "depth", "", samples[samplesNdx], GEOMETRY_TYPE_INVISIBLE_TRIANGLE, TEST_MODE_DEPTH_BIT));
2133 samplesTests->addChild(new RasterizationSamplesTest(testCtx, "stencil", "", samples[samplesNdx], GEOMETRY_TYPE_INVISIBLE_TRIANGLE, TEST_MODE_STENCIL_BIT));
2134 samplesTests->addChild(new RasterizationSamplesTest(testCtx, "depth_stencil", "", samples[samplesNdx], GEOMETRY_TYPE_INVISIBLE_TRIANGLE, TEST_MODE_DEPTH_BIT | TEST_MODE_STENCIL_BIT));
2136 rasterizationSamplesTests->addChild(samplesTests.release());
2139 multisampleTests->addChild(rasterizationSamplesTests.release());
2142 // Raster samples consistency check
2144 de::MovePtr<tcu::TestCaseGroup> rasterSamplesConsistencyTests(new tcu::TestCaseGroup(testCtx, "raster_samples_consistency", ""));
2146 addFunctionCaseWithPrograms(rasterSamplesConsistencyTests.get(),
2147 "unique_colors_check",
2149 initMultisamplePrograms,
2150 testRasterSamplesConsistency,
2151 GEOMETRY_TYPE_OPAQUE_TRIANGLE);
2153 multisampleTests->addChild(rasterSamplesConsistencyTests.release());
2156 // minSampleShading tests
2161 float minSampleShading;
2164 const TestConfig testConfigs[] =
2166 { "min_0_0", 0.0f },
2167 { "min_0_25", 0.25f },
2168 { "min_0_5", 0.5f },
2169 { "min_0_75", 0.75f },
2173 de::MovePtr<tcu::TestCaseGroup> minSampleShadingTests(new tcu::TestCaseGroup(testCtx, "min_sample_shading", ""));
2175 for (int configNdx = 0; configNdx < DE_LENGTH_OF_ARRAY(testConfigs); configNdx++)
2177 const TestConfig& testConfig = testConfigs[configNdx];
2178 de::MovePtr<tcu::TestCaseGroup> minShadingValueTests (new tcu::TestCaseGroup(testCtx, testConfigs[configNdx].name, ""));
2180 for (int samplesNdx = 0; samplesNdx < DE_LENGTH_OF_ARRAY(samples); samplesNdx++)
2182 std::ostringstream caseName;
2183 caseName << "samples_" << samples[samplesNdx];
2185 de::MovePtr<tcu::TestCaseGroup> samplesTests (new tcu::TestCaseGroup(testCtx, caseName.str().c_str(), ""));
2187 samplesTests->addChild(new MinSampleShadingTest(testCtx, "primitive_triangle", "", samples[samplesNdx], testConfig.minSampleShading, GEOMETRY_TYPE_OPAQUE_TRIANGLE));
2188 samplesTests->addChild(new MinSampleShadingTest(testCtx, "primitive_line", "", samples[samplesNdx], testConfig.minSampleShading, GEOMETRY_TYPE_OPAQUE_LINE));
2189 samplesTests->addChild(new MinSampleShadingTest(testCtx, "primitive_point", "", samples[samplesNdx], testConfig.minSampleShading, GEOMETRY_TYPE_OPAQUE_POINT));
2191 minShadingValueTests->addChild(samplesTests.release());
2194 minSampleShadingTests->addChild(minShadingValueTests.release());
2197 multisampleTests->addChild(minSampleShadingTests.release());
2200 // pSampleMask tests
2205 const char* description;
2206 VkSampleMask sampleMask;
2209 const TestConfig testConfigs[] =
2211 { "mask_all_on", "All mask bits are off", 0x0 },
2212 { "mask_all_off", "All mask bits are on", 0xFFFFFFFF },
2213 { "mask_one", "All mask elements are 0x1", 0x1},
2214 { "mask_random", "All mask elements are 0xAAAAAAAA", 0xAAAAAAAA },
2217 de::MovePtr<tcu::TestCaseGroup> sampleMaskTests(new tcu::TestCaseGroup(testCtx, "sample_mask", ""));
2219 for (int configNdx = 0; configNdx < DE_LENGTH_OF_ARRAY(testConfigs); configNdx++)
2221 const TestConfig& testConfig = testConfigs[configNdx];
2222 de::MovePtr<tcu::TestCaseGroup> sampleMaskValueTests (new tcu::TestCaseGroup(testCtx, testConfig.name, testConfig.description));
2224 for (int samplesNdx = 0; samplesNdx < DE_LENGTH_OF_ARRAY(samples); samplesNdx++)
2226 std::ostringstream caseName;
2227 caseName << "samples_" << samples[samplesNdx];
2229 const deUint32 sampleMaskCount = samples[samplesNdx] / 32;
2230 de::MovePtr<tcu::TestCaseGroup> samplesTests (new tcu::TestCaseGroup(testCtx, caseName.str().c_str(), ""));
2232 std::vector<VkSampleMask> mask;
2233 for (deUint32 maskNdx = 0; maskNdx < sampleMaskCount; maskNdx++)
2234 mask.push_back(testConfig.sampleMask);
2236 samplesTests->addChild(new SampleMaskTest(testCtx, "primitive_triangle", "", samples[samplesNdx], mask, GEOMETRY_TYPE_OPAQUE_TRIANGLE));
2237 samplesTests->addChild(new SampleMaskTest(testCtx, "primitive_line", "", samples[samplesNdx], mask, GEOMETRY_TYPE_OPAQUE_LINE));
2238 samplesTests->addChild(new SampleMaskTest(testCtx, "primitive_point", "", samples[samplesNdx], mask, GEOMETRY_TYPE_OPAQUE_POINT));
2240 sampleMaskValueTests->addChild(samplesTests.release());
2243 sampleMaskTests->addChild(sampleMaskValueTests.release());
2246 multisampleTests->addChild(sampleMaskTests.release());
2252 de::MovePtr<tcu::TestCaseGroup> alphaToOneTests(new tcu::TestCaseGroup(testCtx, "alpha_to_one", ""));
2254 for (int samplesNdx = 0; samplesNdx < DE_LENGTH_OF_ARRAY(samples); samplesNdx++)
2256 std::ostringstream caseName;
2257 caseName << "samples_" << samples[samplesNdx];
2259 alphaToOneTests->addChild(new AlphaToOneTest(testCtx, caseName.str(), "", samples[samplesNdx]));
2262 multisampleTests->addChild(alphaToOneTests.release());
2265 // AlphaToCoverageEnable tests
2267 de::MovePtr<tcu::TestCaseGroup> alphaToCoverageTests (new tcu::TestCaseGroup(testCtx, "alpha_to_coverage", ""));
2269 for (int samplesNdx = 0; samplesNdx < DE_LENGTH_OF_ARRAY(samples); samplesNdx++)
2271 std::ostringstream caseName;
2272 caseName << "samples_" << samples[samplesNdx];
2274 de::MovePtr<tcu::TestCaseGroup> samplesTests (new tcu::TestCaseGroup(testCtx, caseName.str().c_str(), ""));
2276 samplesTests->addChild(new AlphaToCoverageTest(testCtx, "alpha_opaque", "", samples[samplesNdx], GEOMETRY_TYPE_OPAQUE_QUAD));
2277 samplesTests->addChild(new AlphaToCoverageTest(testCtx, "alpha_translucent", "", samples[samplesNdx], GEOMETRY_TYPE_TRANSLUCENT_QUAD));
2278 samplesTests->addChild(new AlphaToCoverageTest(testCtx, "alpha_invisible", "", samples[samplesNdx], GEOMETRY_TYPE_INVISIBLE_QUAD));
2280 alphaToCoverageTests->addChild(samplesTests.release());
2282 multisampleTests->addChild(alphaToCoverageTests.release());
2285 // Sampling from a multisampled image texture (texelFetch)
2287 multisampleTests->addChild(createMultisampleSampledImageTests(testCtx));
2290 // Load/store on a multisampled rendered image (different kinds of access: color attachment write, storage image, etc.)
2292 multisampleTests->addChild(createMultisampleStorageImageTests(testCtx));
2295 return multisampleTests.release();