1 /*------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
5 * Copyright (c) 2015 The Khronos Group Inc.
6 * Copyright (c) 2015 Imagination Technologies Ltd.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and/or associated documentation files (the
10 * "Materials"), to deal in the Materials without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sublicense, and/or sell copies of the Materials, and to
13 * permit persons to whom the Materials are furnished to do so, subject to
14 * the following conditions:
16 * The above copyright notice(s) and this permission notice shall be included
17 * in all copies or substantial portions of the Materials.
19 * The Materials are Confidential Information as defined by the
20 * Khronos Membership Agreement until designated non-confidential by Khronos,
21 * at which point this condition clause shall be removed.
23 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
26 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
27 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
28 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
29 * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
33 * \brief Multisample Tests
34 *//*--------------------------------------------------------------------*/
36 #include "vktPipelineMultisampleTests.hpp"
37 #include "vktPipelineClearUtil.hpp"
38 #include "vktPipelineImageUtil.hpp"
39 #include "vktPipelineVertexUtil.hpp"
40 #include "vktPipelineReferenceRenderer.hpp"
41 #include "vktTestCase.hpp"
42 #include "vktTestCaseUtil.hpp"
43 #include "vkImageUtil.hpp"
44 #include "vkMemUtil.hpp"
45 #include "vkPrograms.hpp"
46 #include "vkQueryUtil.hpp"
48 #include "vkRefUtil.hpp"
49 #include "tcuImageCompare.hpp"
50 #include "deUniquePtr.hpp"
51 #include "deStringUtil.hpp"
69 GEOMETRY_TYPE_OPAQUE_TRIANGLE,
70 GEOMETRY_TYPE_OPAQUE_LINE,
71 GEOMETRY_TYPE_OPAQUE_POINT,
72 GEOMETRY_TYPE_OPAQUE_QUAD,
73 GEOMETRY_TYPE_TRANSLUCENT_QUAD,
74 GEOMETRY_TYPE_INVISIBLE_QUAD,
75 GEOMETRY_TYPE_GRADIENT_QUAD
79 bool isSupportedSampleCount (const InstanceInterface& instanceInterface, VkPhysicalDevice physicalDevice, VkSampleCountFlagBits rasterizationSamples);
80 VkPipelineColorBlendAttachmentState getDefaultColorBlendAttachmentState (void);
81 deUint32 getUniqueColorsCount (const tcu::ConstPixelBufferAccess& image);
82 void initMultisamplePrograms (SourceCollections& sources, GeometryType geometryType);
84 class MultisampleTest : public vkt::TestCase
88 MultisampleTest (tcu::TestContext& testContext,
89 const std::string& name,
90 const std::string& description,
91 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
92 const VkPipelineColorBlendAttachmentState& blendState,
93 GeometryType geometryType);
94 virtual ~MultisampleTest (void);
96 virtual void initPrograms (SourceCollections& programCollection) const;
97 virtual TestInstance* createInstance (Context& context) const;
100 virtual TestInstance* createMultisampleTestInstance (Context& context,
101 VkPrimitiveTopology topology,
102 const std::vector<Vertex4RGBA>& vertices,
103 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
104 const VkPipelineColorBlendAttachmentState& colorBlendState) const = 0;
105 VkPipelineMultisampleStateCreateInfo m_multisampleStateParams;
106 const VkPipelineColorBlendAttachmentState m_colorBlendState;
107 const GeometryType m_geometryType;
108 std::vector<VkSampleMask> m_sampleMask;
111 class RasterizationSamplesTest : public MultisampleTest
114 RasterizationSamplesTest (tcu::TestContext& testContext,
115 const std::string& name,
116 const std::string& description,
117 VkSampleCountFlagBits rasterizationSamples,
118 GeometryType geometryType);
119 virtual ~RasterizationSamplesTest (void) {}
122 virtual TestInstance* createMultisampleTestInstance (Context& context,
123 VkPrimitiveTopology topology,
124 const std::vector<Vertex4RGBA>& vertices,
125 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
126 const VkPipelineColorBlendAttachmentState& colorBlendState) const;
128 static VkPipelineMultisampleStateCreateInfo getRasterizationSamplesStateParams (VkSampleCountFlagBits rasterizationSamples);
131 class MinSampleShadingTest : public MultisampleTest
134 MinSampleShadingTest (tcu::TestContext& testContext,
135 const std::string& name,
136 const std::string& description,
137 VkSampleCountFlagBits rasterizationSamples,
138 float minSampleShading,
139 GeometryType geometryType);
140 virtual ~MinSampleShadingTest (void) {}
143 virtual TestInstance* createMultisampleTestInstance (Context& context,
144 VkPrimitiveTopology topology,
145 const std::vector<Vertex4RGBA>& vertices,
146 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
147 const VkPipelineColorBlendAttachmentState& colorBlendState) const;
149 static VkPipelineMultisampleStateCreateInfo getMinSampleShadingStateParams (VkSampleCountFlagBits rasterizationSamples, float minSampleShading);
152 class SampleMaskTest : public MultisampleTest
155 SampleMaskTest (tcu::TestContext& testContext,
156 const std::string& name,
157 const std::string& description,
158 VkSampleCountFlagBits rasterizationSamples,
159 const std::vector<VkSampleMask>& sampleMask,
160 GeometryType geometryType);
162 virtual ~SampleMaskTest (void) {}
165 virtual TestInstance* createMultisampleTestInstance (Context& context,
166 VkPrimitiveTopology topology,
167 const std::vector<Vertex4RGBA>& vertices,
168 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
169 const VkPipelineColorBlendAttachmentState& colorBlendState) const;
171 static VkPipelineMultisampleStateCreateInfo getSampleMaskStateParams (VkSampleCountFlagBits rasterizationSamples, const std::vector<VkSampleMask>& sampleMask);
174 class AlphaToOneTest : public MultisampleTest
177 AlphaToOneTest (tcu::TestContext& testContext,
178 const std::string& name,
179 const std::string& description,
180 VkSampleCountFlagBits rasterizationSamples);
182 virtual ~AlphaToOneTest (void) {}
185 virtual TestInstance* createMultisampleTestInstance (Context& context,
186 VkPrimitiveTopology topology,
187 const std::vector<Vertex4RGBA>& vertices,
188 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
189 const VkPipelineColorBlendAttachmentState& colorBlendState) const;
191 static VkPipelineMultisampleStateCreateInfo getAlphaToOneStateParams (VkSampleCountFlagBits rasterizationSamples);
192 static VkPipelineColorBlendAttachmentState getAlphaToOneBlendState (void);
195 class AlphaToCoverageTest : public MultisampleTest
198 AlphaToCoverageTest (tcu::TestContext& testContext,
199 const std::string& name,
200 const std::string& description,
201 VkSampleCountFlagBits rasterizationSamples,
202 GeometryType geometryType);
204 virtual ~AlphaToCoverageTest (void) {}
207 virtual TestInstance* createMultisampleTestInstance (Context& context,
208 VkPrimitiveTopology topology,
209 const std::vector<Vertex4RGBA>& vertices,
210 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
211 const VkPipelineColorBlendAttachmentState& colorBlendState) const;
213 static VkPipelineMultisampleStateCreateInfo getAlphaToCoverageStateParams (VkSampleCountFlagBits rasterizationSamples);
215 GeometryType m_geometryType;
218 class MultisampleRenderer
221 MultisampleRenderer (Context& context,
222 VkFormat colorFormat,
223 const tcu::IVec2& renderSize,
224 VkPrimitiveTopology topology,
225 const std::vector<Vertex4RGBA>& vertices,
226 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
227 const VkPipelineColorBlendAttachmentState& blendState);
229 virtual ~MultisampleRenderer (void);
231 de::MovePtr<tcu::TextureLevel> render (void);
236 const VkFormat m_colorFormat;
237 tcu::IVec2 m_renderSize;
239 const VkPipelineMultisampleStateCreateInfo m_multisampleStateParams;
240 const VkPipelineColorBlendAttachmentState m_colorBlendState;
242 Move<VkImage> m_colorImage;
243 de::MovePtr<Allocation> m_colorImageAlloc;
244 Move<VkImageView> m_colorAttachmentView;
246 Move<VkImage> m_resolveImage;
247 de::MovePtr<Allocation> m_resolveImageAlloc;
248 Move<VkImageView> m_resolveAttachmentView;
250 Move<VkRenderPass> m_renderPass;
251 Move<VkFramebuffer> m_framebuffer;
253 Move<VkShaderModule> m_vertexShaderModule;
254 Move<VkShaderModule> m_fragmentShaderModule;
256 Move<VkBuffer> m_vertexBuffer;
257 de::MovePtr<Allocation> m_vertexBufferAlloc;
259 Move<VkPipelineLayout> m_pipelineLayout;
260 Move<VkPipeline> m_graphicsPipeline;
262 Move<VkCommandPool> m_cmdPool;
263 Move<VkCommandBuffer> m_cmdBuffer;
265 Move<VkFence> m_fence;
268 class RasterizationSamplesInstance : public vkt::TestInstance
271 RasterizationSamplesInstance (Context& context,
272 VkPrimitiveTopology topology,
273 const std::vector<Vertex4RGBA>& vertices,
274 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
275 const VkPipelineColorBlendAttachmentState& blendState);
276 virtual ~RasterizationSamplesInstance (void) {}
278 virtual tcu::TestStatus iterate (void);
281 virtual tcu::TestStatus verifyImage (const tcu::ConstPixelBufferAccess& result);
283 const VkFormat m_colorFormat;
284 const tcu::IVec2 m_renderSize;
285 const VkPrimitiveTopology m_primitiveTopology;
286 const std::vector<Vertex4RGBA> m_vertices;
287 MultisampleRenderer m_multisampleRenderer;
290 class MinSampleShadingInstance : public vkt::TestInstance
293 MinSampleShadingInstance (Context& context,
294 VkPrimitiveTopology topology,
295 const std::vector<Vertex4RGBA>& vertices,
296 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
297 const VkPipelineColorBlendAttachmentState& blendState);
298 virtual ~MinSampleShadingInstance (void) {}
300 virtual tcu::TestStatus iterate (void);
303 virtual tcu::TestStatus verifyImage (const tcu::ConstPixelBufferAccess& testShadingImage,
304 const tcu::ConstPixelBufferAccess& minShadingImage,
305 const tcu::ConstPixelBufferAccess& maxShadingImage);
306 const VkFormat m_colorFormat;
307 const tcu::IVec2 m_renderSize;
308 const VkPrimitiveTopology m_primitiveTopology;
309 const std::vector<Vertex4RGBA> m_vertices;
310 const VkPipelineMultisampleStateCreateInfo m_multisampleStateParams;
311 const VkPipelineColorBlendAttachmentState m_colorBlendState;
314 class SampleMaskInstance : public vkt::TestInstance
317 SampleMaskInstance (Context& context,
318 VkPrimitiveTopology topology,
319 const std::vector<Vertex4RGBA>& vertices,
320 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
321 const VkPipelineColorBlendAttachmentState& blendState);
322 virtual ~SampleMaskInstance (void) {}
324 virtual tcu::TestStatus iterate (void);
327 virtual tcu::TestStatus verifyImage (const tcu::ConstPixelBufferAccess& testShadingImage,
328 const tcu::ConstPixelBufferAccess& minShadingImage,
329 const tcu::ConstPixelBufferAccess& maxShadingImage);
330 const VkFormat m_colorFormat;
331 const tcu::IVec2 m_renderSize;
332 const VkPrimitiveTopology m_primitiveTopology;
333 const std::vector<Vertex4RGBA> m_vertices;
334 const VkPipelineMultisampleStateCreateInfo m_multisampleStateParams;
335 const VkPipelineColorBlendAttachmentState m_colorBlendState;
338 class AlphaToOneInstance : public vkt::TestInstance
341 AlphaToOneInstance (Context& context,
342 VkPrimitiveTopology topology,
343 const std::vector<Vertex4RGBA>& vertices,
344 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
345 const VkPipelineColorBlendAttachmentState& blendState);
346 virtual ~AlphaToOneInstance (void) {}
348 virtual tcu::TestStatus iterate (void);
351 virtual tcu::TestStatus verifyImage (const tcu::ConstPixelBufferAccess& alphaOneImage,
352 const tcu::ConstPixelBufferAccess& noAlphaOneImage);
353 const VkFormat m_colorFormat;
354 const tcu::IVec2 m_renderSize;
355 const VkPrimitiveTopology m_primitiveTopology;
356 const std::vector<Vertex4RGBA> m_vertices;
357 const VkPipelineMultisampleStateCreateInfo m_multisampleStateParams;
358 const VkPipelineColorBlendAttachmentState m_colorBlendState;
361 class AlphaToCoverageInstance : public vkt::TestInstance
364 AlphaToCoverageInstance (Context& context,
365 VkPrimitiveTopology topology,
366 const std::vector<Vertex4RGBA>& vertices,
367 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
368 const VkPipelineColorBlendAttachmentState& blendState,
369 GeometryType geometryType);
370 virtual ~AlphaToCoverageInstance (void) {}
372 virtual tcu::TestStatus iterate (void);
375 virtual tcu::TestStatus verifyImage (const tcu::ConstPixelBufferAccess& result);
376 const VkFormat m_colorFormat;
377 const tcu::IVec2 m_renderSize;
378 const VkPrimitiveTopology m_primitiveTopology;
379 const std::vector<Vertex4RGBA> m_vertices;
380 const VkPipelineMultisampleStateCreateInfo m_multisampleStateParams;
381 const VkPipelineColorBlendAttachmentState m_colorBlendState;
382 const GeometryType m_geometryType;
388 void initMultisamplePrograms (SourceCollections& sources, GeometryType geometryType)
390 std::ostringstream vertexSource;
394 "layout(location = 0) in vec4 position;\n"
395 "layout(location = 1) in vec4 color;\n"
396 "layout(location = 0) out highp vec4 vtxColor;\n"
399 " gl_Position = position;\n"
400 " vtxColor = color;\n"
401 << (geometryType == GEOMETRY_TYPE_OPAQUE_POINT ? " gl_PointSize = 3.0f;\n"
405 static const char* fragmentSource =
407 "layout(location = 0) in highp vec4 vtxColor;\n"
408 "layout(location = 0) out highp vec4 fragColor;\n"
411 " fragColor = vtxColor;\n"
414 sources.glslSources.add("color_vert") << glu::VertexSource(vertexSource.str());
415 sources.glslSources.add("color_frag") << glu::FragmentSource(fragmentSource);
418 bool isSupportedSampleCount (const InstanceInterface& instanceInterface, VkPhysicalDevice physicalDevice, VkSampleCountFlagBits rasterizationSamples)
420 VkPhysicalDeviceProperties deviceProperties;
422 instanceInterface.getPhysicalDeviceProperties(physicalDevice, &deviceProperties);
424 return !!(deviceProperties.limits.framebufferColorSampleCounts & rasterizationSamples);
427 VkPipelineColorBlendAttachmentState getDefaultColorBlendAttachmentState (void)
429 const VkPipelineColorBlendAttachmentState colorBlendState =
431 false, // VkBool32 blendEnable;
432 VK_BLEND_FACTOR_ONE, // VkBlendFactor srcColorBlendFactor;
433 VK_BLEND_FACTOR_ZERO, // VkBlendFactor dstColorBlendFactor;
434 VK_BLEND_OP_ADD, // VkBlendOp colorBlendOp;
435 VK_BLEND_FACTOR_ONE, // VkBlendFactor srcAlphaBlendFactor;
436 VK_BLEND_FACTOR_ZERO, // VkBlendFactor dstAlphaBlendFactor;
437 VK_BLEND_OP_ADD, // VkBlendOp alphaBlendOp;
438 VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | // VkColorComponentFlags colorWriteMask;
439 VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT
442 return colorBlendState;
445 deUint32 getUniqueColorsCount (const tcu::ConstPixelBufferAccess& image)
447 DE_ASSERT(image.getFormat().getPixelSize() == 4);
449 std::map<deUint32, deUint32> histogram; // map<pixel value, number of occurrences>
450 const deUint32 pixelCount = image.getWidth() * image.getHeight() * image.getDepth();
452 for (deUint32 pixelNdx = 0; pixelNdx < pixelCount; pixelNdx++)
454 const deUint32 pixelValue = *((const deUint32*)image.getDataPtr() + pixelNdx);
456 if (histogram.find(pixelValue) != histogram.end())
457 histogram[pixelValue]++;
459 histogram[pixelValue] = 1;
462 return (deUint32)histogram.size();
468 MultisampleTest::MultisampleTest (tcu::TestContext& testContext,
469 const std::string& name,
470 const std::string& description,
471 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
472 const VkPipelineColorBlendAttachmentState& blendState,
473 GeometryType geometryType)
474 : vkt::TestCase (testContext, name, description)
475 , m_multisampleStateParams (multisampleStateParams)
476 , m_colorBlendState (blendState)
477 , m_geometryType (geometryType)
479 if (m_multisampleStateParams.pSampleMask)
481 // Copy pSampleMask to avoid dependencies with other classes
483 const deUint32 maskCount = deCeilFloatToInt32(float(m_multisampleStateParams.rasterizationSamples) / 32);
485 for (deUint32 maskNdx = 0; maskNdx < maskCount; maskNdx++)
486 m_sampleMask.push_back(m_multisampleStateParams.pSampleMask[maskNdx]);
488 m_multisampleStateParams.pSampleMask = m_sampleMask.data();
492 MultisampleTest::~MultisampleTest (void)
496 void MultisampleTest::initPrograms (SourceCollections& programCollection) const
498 initMultisamplePrograms(programCollection, m_geometryType);
501 TestInstance* MultisampleTest::createInstance (Context& context) const
503 VkPrimitiveTopology topology;
504 std::vector<Vertex4RGBA> vertices;
506 switch (m_geometryType)
508 case GEOMETRY_TYPE_OPAQUE_TRIANGLE:
510 topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
511 const Vertex4RGBA vertexData[3] =
514 tcu::Vec4(-0.75f, 0.0f, 0.0f, 1.0f),
515 tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f)
518 tcu::Vec4(0.75f, 0.125f, 0.0f, 1.0f),
519 tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f)
522 tcu::Vec4(0.75f, -0.125f, 0.0f, 1.0f),
523 tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f)
527 vertices = std::vector<Vertex4RGBA>(vertexData, vertexData + 3);
531 case GEOMETRY_TYPE_OPAQUE_LINE:
533 topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
535 const Vertex4RGBA vertexData[2] =
538 tcu::Vec4(-0.75f, 0.25f, 0.0f, 1.0f),
539 tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f)
542 tcu::Vec4(0.75f, -0.25f, 0.0f, 1.0f),
543 tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f)
547 vertices = std::vector<Vertex4RGBA>(vertexData, vertexData + 2);
551 case GEOMETRY_TYPE_OPAQUE_POINT:
553 topology = VK_PRIMITIVE_TOPOLOGY_POINT_LIST;
555 const Vertex4RGBA vertex =
557 tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f),
558 tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f)
561 vertices = std::vector<Vertex4RGBA>(1, vertex);
565 case GEOMETRY_TYPE_OPAQUE_QUAD:
566 case GEOMETRY_TYPE_TRANSLUCENT_QUAD:
567 case GEOMETRY_TYPE_INVISIBLE_QUAD:
568 case GEOMETRY_TYPE_GRADIENT_QUAD:
570 topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
572 Vertex4RGBA vertexData[4] =
575 tcu::Vec4(-1.0f, -1.0f, 0.0f, 1.0f),
576 tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f)
579 tcu::Vec4(1.0f, -1.0f, 0.0f, 1.0f),
580 tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f)
583 tcu::Vec4(-1.0f, 1.0f, 0.0f, 1.0f),
584 tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f)
587 tcu::Vec4(1.0f, 1.0f, 0.0f, 1.0f),
588 tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f)
592 if (m_geometryType == GEOMETRY_TYPE_TRANSLUCENT_QUAD)
594 for (int i = 0; i < 4; i++)
595 vertexData[i].color.w() = 0.25f;
597 else if (m_geometryType == GEOMETRY_TYPE_INVISIBLE_QUAD)
599 for (int i = 0; i < 4; i++)
600 vertexData[i].color.w() = 0.0f;
602 else if (m_geometryType == GEOMETRY_TYPE_GRADIENT_QUAD)
604 vertexData[0].color.w() = 0.0f;
605 vertexData[2].color.w() = 0.0f;
608 vertices = std::vector<Vertex4RGBA>(vertexData, vertexData + 4);
613 topology = VK_PRIMITIVE_TOPOLOGY_LAST;
617 return createMultisampleTestInstance(context, topology, vertices, m_multisampleStateParams, m_colorBlendState);
621 // RasterizationSamplesTest
623 RasterizationSamplesTest::RasterizationSamplesTest (tcu::TestContext& testContext,
624 const std::string& name,
625 const std::string& description,
626 VkSampleCountFlagBits rasterizationSamples,
627 GeometryType geometryType)
628 : MultisampleTest (testContext, name, description, getRasterizationSamplesStateParams(rasterizationSamples), getDefaultColorBlendAttachmentState(), geometryType)
632 VkPipelineMultisampleStateCreateInfo RasterizationSamplesTest::getRasterizationSamplesStateParams (VkSampleCountFlagBits rasterizationSamples)
634 const VkPipelineMultisampleStateCreateInfo multisampleStateParams =
636 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, // VkStructureType sType;
637 DE_NULL, // const void* pNext;
638 0u, // VkPipelineMultisampleStateCreateFlags flags;
639 rasterizationSamples, // VkSampleCountFlagBits rasterizationSamples;
640 false, // VkBool32 sampleShadingEnable;
641 0.0f, // float minSampleShading;
642 DE_NULL, // const VkSampleMask* pSampleMask;
643 false, // VkBool32 alphaToCoverageEnable;
644 false // VkBool32 alphaToOneEnable;
647 return multisampleStateParams;
650 TestInstance* RasterizationSamplesTest::createMultisampleTestInstance (Context& context,
651 VkPrimitiveTopology topology,
652 const std::vector<Vertex4RGBA>& vertices,
653 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
654 const VkPipelineColorBlendAttachmentState& colorBlendState) const
656 return new RasterizationSamplesInstance(context, topology, vertices, multisampleStateParams, colorBlendState);
660 // MinSampleShadingTest
662 MinSampleShadingTest::MinSampleShadingTest (tcu::TestContext& testContext,
663 const std::string& name,
664 const std::string& description,
665 VkSampleCountFlagBits rasterizationSamples,
666 float minSampleShading,
667 GeometryType geometryType)
668 : MultisampleTest (testContext, name, description, getMinSampleShadingStateParams(rasterizationSamples, minSampleShading), getDefaultColorBlendAttachmentState(), geometryType)
672 TestInstance* MinSampleShadingTest::createMultisampleTestInstance (Context& context,
673 VkPrimitiveTopology topology,
674 const std::vector<Vertex4RGBA>& vertices,
675 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
676 const VkPipelineColorBlendAttachmentState& colorBlendState) const
678 return new MinSampleShadingInstance(context, topology, vertices, multisampleStateParams, colorBlendState);
681 VkPipelineMultisampleStateCreateInfo MinSampleShadingTest::getMinSampleShadingStateParams (VkSampleCountFlagBits rasterizationSamples, float minSampleShading)
683 const VkPipelineMultisampleStateCreateInfo multisampleStateParams =
685 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, // VkStructureType sType;
686 DE_NULL, // const void* pNext;
687 0u, // VkPipelineMultisampleStateCreateFlags flags;
688 rasterizationSamples, // VkSampleCountFlagBits rasterizationSamples;
689 true, // VkBool32 sampleShadingEnable;
690 minSampleShading, // float minSampleShading;
691 DE_NULL, // const VkSampleMask* pSampleMask;
692 false, // VkBool32 alphaToCoverageEnable;
693 false // VkBool32 alphaToOneEnable;
696 return multisampleStateParams;
702 SampleMaskTest::SampleMaskTest (tcu::TestContext& testContext,
703 const std::string& name,
704 const std::string& description,
705 VkSampleCountFlagBits rasterizationSamples,
706 const std::vector<VkSampleMask>& sampleMask,
707 GeometryType geometryType)
708 : MultisampleTest (testContext, name, description, getSampleMaskStateParams(rasterizationSamples, sampleMask), getDefaultColorBlendAttachmentState(), geometryType)
712 TestInstance* SampleMaskTest::createMultisampleTestInstance (Context& context,
713 VkPrimitiveTopology topology,
714 const std::vector<Vertex4RGBA>& vertices,
715 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
716 const VkPipelineColorBlendAttachmentState& colorBlendState) const
718 return new SampleMaskInstance(context, topology,vertices, multisampleStateParams, colorBlendState);
721 VkPipelineMultisampleStateCreateInfo SampleMaskTest::getSampleMaskStateParams (VkSampleCountFlagBits rasterizationSamples, const std::vector<VkSampleMask>& sampleMask)
723 const VkPipelineMultisampleStateCreateInfo multisampleStateParams =
725 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, // VkStructureType sType;
726 DE_NULL, // const void* pNext;
727 0u, // VkPipelineMultisampleStateCreateFlags flags;
728 rasterizationSamples, // VkSampleCountFlagBits rasterizationSamples;
729 false, // VkBool32 sampleShadingEnable;
730 0.0f, // float minSampleShading;
731 sampleMask.data(), // const VkSampleMask* pSampleMask;
732 false, // VkBool32 alphaToCoverageEnable;
733 false // VkBool32 alphaToOneEnable;
736 return multisampleStateParams;
742 AlphaToOneTest::AlphaToOneTest (tcu::TestContext& testContext,
743 const std::string& name,
744 const std::string& description,
745 VkSampleCountFlagBits rasterizationSamples)
746 : MultisampleTest (testContext, name, description, getAlphaToOneStateParams(rasterizationSamples), getAlphaToOneBlendState(), GEOMETRY_TYPE_GRADIENT_QUAD)
750 TestInstance* AlphaToOneTest::createMultisampleTestInstance (Context& context,
751 VkPrimitiveTopology topology,
752 const std::vector<Vertex4RGBA>& vertices,
753 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
754 const VkPipelineColorBlendAttachmentState& colorBlendState) const
756 return new AlphaToOneInstance(context, topology, vertices, multisampleStateParams, colorBlendState);
759 VkPipelineMultisampleStateCreateInfo AlphaToOneTest::getAlphaToOneStateParams (VkSampleCountFlagBits rasterizationSamples)
761 const VkPipelineMultisampleStateCreateInfo multisampleStateParams =
763 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, // VkStructureType sType;
764 DE_NULL, // const void* pNext;
765 0u, // VkPipelineMultisampleStateCreateFlags flags;
766 rasterizationSamples, // VkSampleCountFlagBits rasterizationSamples;
767 false, // VkBool32 sampleShadingEnable;
768 0.0f, // float minSampleShading;
769 DE_NULL, // const VkSampleMask* pSampleMask;
770 false, // VkBool32 alphaToCoverageEnable;
771 true // VkBool32 alphaToOneEnable;
774 return multisampleStateParams;
777 VkPipelineColorBlendAttachmentState AlphaToOneTest::getAlphaToOneBlendState (void)
779 const VkPipelineColorBlendAttachmentState colorBlendState =
781 true, // VkBool32 blendEnable;
782 VK_BLEND_FACTOR_SRC_ALPHA, // VkBlendFactor srcColorBlendFactor;
783 VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA, // VkBlendFactor dstColorBlendFactor;
784 VK_BLEND_OP_ADD, // VkBlendOp colorBlendOp;
785 VK_BLEND_FACTOR_SRC_ALPHA, // VkBlendFactor srcAlphaBlendFactor;
786 VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA, // VkBlendFactor dstAlphaBlendFactor;
787 VK_BLEND_OP_ADD, // VkBlendOp alphaBlendOp;
788 VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | // VkColorComponentFlags colorWriteMask;
789 VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT
792 return colorBlendState;
796 // AlphaToCoverageTest
798 AlphaToCoverageTest::AlphaToCoverageTest (tcu::TestContext& testContext,
799 const std::string& name,
800 const std::string& description,
801 VkSampleCountFlagBits rasterizationSamples,
802 GeometryType geometryType)
803 : MultisampleTest (testContext, name, description, getAlphaToCoverageStateParams(rasterizationSamples), getDefaultColorBlendAttachmentState(), geometryType)
804 , m_geometryType (geometryType)
808 TestInstance* AlphaToCoverageTest::createMultisampleTestInstance (Context& context,
809 VkPrimitiveTopology topology,
810 const std::vector<Vertex4RGBA>& vertices,
811 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
812 const VkPipelineColorBlendAttachmentState& colorBlendState) const
814 return new AlphaToCoverageInstance(context, topology, vertices, multisampleStateParams, colorBlendState, m_geometryType);
817 VkPipelineMultisampleStateCreateInfo AlphaToCoverageTest::getAlphaToCoverageStateParams (VkSampleCountFlagBits rasterizationSamples)
819 const VkPipelineMultisampleStateCreateInfo multisampleStateParams =
821 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, // VkStructureType sType;
822 DE_NULL, // const void* pNext;
823 0u, // VkPipelineMultisampleStateCreateFlags flags;
824 rasterizationSamples, // VkSampleCountFlagBits rasterizationSamples;
825 false, // VkBool32 sampleShadingEnable;
826 0.0f, // float minSampleShading;
827 DE_NULL, // const VkSampleMask* pSampleMask;
828 true, // VkBool32 alphaToCoverageEnable;
829 false // VkBool32 alphaToOneEnable;
832 return multisampleStateParams;
835 // RasterizationSamplesInstance
837 RasterizationSamplesInstance::RasterizationSamplesInstance (Context& context,
838 VkPrimitiveTopology topology,
839 const std::vector<Vertex4RGBA>& vertices,
840 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
841 const VkPipelineColorBlendAttachmentState& blendState)
842 : vkt::TestInstance (context)
843 , m_colorFormat (VK_FORMAT_R8G8B8A8_UNORM)
844 , m_renderSize (32, 32)
845 , m_primitiveTopology (topology)
846 , m_vertices (vertices)
847 , m_multisampleRenderer (context, m_colorFormat, m_renderSize, topology, vertices, multisampleStateParams, blendState)
851 tcu::TestStatus RasterizationSamplesInstance::iterate (void)
853 de::MovePtr<tcu::TextureLevel> level(m_multisampleRenderer.render());
854 return verifyImage(level->getAccess());
857 tcu::TestStatus RasterizationSamplesInstance::verifyImage (const tcu::ConstPixelBufferAccess& result)
859 // Verify range of unique pixels
861 const deUint32 numUniqueColors = getUniqueColorsCount(result);
862 const deUint32 minUniqueColors = 3;
864 tcu::TestLog& log = m_context.getTestContext().getLog();
866 log << tcu::TestLog::Message
867 << "\nMin. unique colors expected: " << minUniqueColors << "\n"
868 << "Unique colors found: " << numUniqueColors << "\n"
869 << tcu::TestLog::EndMessage;
871 if (numUniqueColors < minUniqueColors)
872 return tcu::TestStatus::fail("Unique colors out of expected bounds");
875 // Verify shape of the rendered primitive (fuzzy-compare)
877 const tcu::TextureFormat tcuColorFormat = mapVkFormat(m_colorFormat);
878 const tcu::TextureFormat tcuDepthFormat = tcu::TextureFormat();
879 const ColorVertexShader vertexShader;
880 const ColorFragmentShader fragmentShader (tcuColorFormat, tcuDepthFormat);
881 const rr::Program program (&vertexShader, &fragmentShader);
882 ReferenceRenderer refRenderer (m_renderSize.x(), m_renderSize.y(), 1, tcuColorFormat, tcuDepthFormat, &program);
883 rr::RenderState renderState (refRenderer.getViewportState());
885 if (m_primitiveTopology == VK_PRIMITIVE_TOPOLOGY_POINT_LIST)
887 VkPhysicalDeviceProperties deviceProperties;
889 m_context.getInstanceInterface().getPhysicalDeviceProperties(m_context.getPhysicalDevice(), &deviceProperties);
891 // gl_PointSize is clamped to pointSizeRange
892 renderState.point.pointSize = deFloatMin(3.0f, deviceProperties.limits.pointSizeRange[1]);
895 refRenderer.colorClear(tcu::Vec4(0.0f));
896 refRenderer.draw(renderState, mapVkPrimitiveTopology(m_primitiveTopology), m_vertices);
898 if (!tcu::fuzzyCompare(m_context.getTestContext().getLog(), "FuzzyImageCompare", "Image comparison", refRenderer.getAccess(), result, 0.05f, tcu::COMPARE_LOG_RESULT))
899 return tcu::TestStatus::fail("Primitive has unexpected shape");
903 return tcu::TestStatus::pass("Primitive rendered, unique colors within expected bounds");
907 // MinSampleShadingInstance
909 MinSampleShadingInstance::MinSampleShadingInstance (Context& context,
910 VkPrimitiveTopology topology,
911 const std::vector<Vertex4RGBA>& vertices,
912 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
913 const VkPipelineColorBlendAttachmentState& colorBlendState)
914 : vkt::TestInstance (context)
915 , m_colorFormat (VK_FORMAT_R8G8B8A8_UNORM)
916 , m_renderSize (32, 32)
917 , m_primitiveTopology (topology)
918 , m_vertices (vertices)
919 , m_multisampleStateParams (multisampleStateParams)
920 , m_colorBlendState (colorBlendState)
922 VkPhysicalDeviceFeatures deviceFeatures;
924 m_context.getInstanceInterface().getPhysicalDeviceFeatures(m_context.getPhysicalDevice(), &deviceFeatures);
926 if (!deviceFeatures.sampleRateShading)
927 throw tcu::NotSupportedError("Sample shading is not supported");
930 tcu::TestStatus MinSampleShadingInstance::iterate (void)
932 de::MovePtr<tcu::TextureLevel> testShadingImage;
933 de::MovePtr<tcu::TextureLevel> minShadingImage;
934 de::MovePtr<tcu::TextureLevel> maxShadingImage;
936 // Render with test minSampleShading
938 MultisampleRenderer renderer (m_context, m_colorFormat, m_renderSize, m_primitiveTopology, m_vertices, m_multisampleStateParams, m_colorBlendState);
939 testShadingImage = renderer.render();
942 // Render with minSampleShading = 0.0f
944 VkPipelineMultisampleStateCreateInfo multisampleParams = m_multisampleStateParams;
945 multisampleParams.minSampleShading = 0.0f;
947 MultisampleRenderer renderer (m_context, m_colorFormat, m_renderSize, m_primitiveTopology, m_vertices, multisampleParams, m_colorBlendState);
948 minShadingImage = renderer.render();
951 // Render with minSampleShading = 1.0f
953 VkPipelineMultisampleStateCreateInfo multisampleParams = m_multisampleStateParams;
954 multisampleParams.minSampleShading = 1.0f;
956 MultisampleRenderer renderer (m_context, m_colorFormat, m_renderSize, m_primitiveTopology, m_vertices, multisampleParams, m_colorBlendState);
957 maxShadingImage = renderer.render();
960 return verifyImage(testShadingImage->getAccess(), minShadingImage->getAccess(), maxShadingImage->getAccess());
963 tcu::TestStatus MinSampleShadingInstance::verifyImage (const tcu::ConstPixelBufferAccess& testShadingImage, const tcu::ConstPixelBufferAccess& minShadingImage, const tcu::ConstPixelBufferAccess& maxShadingImage)
965 const deUint32 testColorCount = getUniqueColorsCount(testShadingImage);
966 const deUint32 minColorCount = getUniqueColorsCount(minShadingImage);
967 const deUint32 maxColorCount = getUniqueColorsCount(maxShadingImage);
969 tcu::TestLog& log = m_context.getTestContext().getLog();
971 log << tcu::TestLog::Message
972 << "\nColors found: " << testColorCount << "\n"
973 << "Min. colors expected: " << minColorCount << "\n"
974 << "Max. colors expected: " << maxColorCount << "\n"
975 << tcu::TestLog::EndMessage;
977 if (minColorCount > testColorCount || testColorCount > maxColorCount)
978 return tcu::TestStatus::fail("Unique colors out of expected bounds");
980 return tcu::TestStatus::pass("Unique colors within expected bounds");
983 SampleMaskInstance::SampleMaskInstance (Context& context,
984 VkPrimitiveTopology topology,
985 const std::vector<Vertex4RGBA>& vertices,
986 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
987 const VkPipelineColorBlendAttachmentState& blendState)
988 : vkt::TestInstance (context)
989 , m_colorFormat (VK_FORMAT_R8G8B8A8_UNORM)
990 , m_renderSize (32, 32)
991 , m_primitiveTopology (topology)
992 , m_vertices (vertices)
993 , m_multisampleStateParams (multisampleStateParams)
994 , m_colorBlendState (blendState)
998 tcu::TestStatus SampleMaskInstance::iterate (void)
1000 de::MovePtr<tcu::TextureLevel> testSampleMaskImage;
1001 de::MovePtr<tcu::TextureLevel> minSampleMaskImage;
1002 de::MovePtr<tcu::TextureLevel> maxSampleMaskImage;
1004 // Render with test flags
1006 MultisampleRenderer renderer (m_context, m_colorFormat, m_renderSize, m_primitiveTopology, m_vertices, m_multisampleStateParams, m_colorBlendState);
1007 testSampleMaskImage = renderer.render();
1010 // Render with all flags off
1012 VkPipelineMultisampleStateCreateInfo multisampleParams = m_multisampleStateParams;
1013 const std::vector<VkSampleMask> sampleMask (multisampleParams.rasterizationSamples / 32, (VkSampleMask)0);
1015 multisampleParams.pSampleMask = sampleMask.data();
1017 MultisampleRenderer renderer (m_context, m_colorFormat, m_renderSize, m_primitiveTopology, m_vertices, multisampleParams, m_colorBlendState);
1018 minSampleMaskImage = renderer.render();
1021 // Render with all flags on
1023 VkPipelineMultisampleStateCreateInfo multisampleParams = m_multisampleStateParams;
1024 const std::vector<VkSampleMask> sampleMask (multisampleParams.rasterizationSamples / 32, ~((VkSampleMask)0));
1026 multisampleParams.pSampleMask = sampleMask.data();
1028 MultisampleRenderer renderer (m_context, m_colorFormat, m_renderSize, m_primitiveTopology, m_vertices, multisampleParams, m_colorBlendState);
1029 maxSampleMaskImage = renderer.render();
1032 return verifyImage(testSampleMaskImage->getAccess(), minSampleMaskImage->getAccess(), maxSampleMaskImage->getAccess());
1035 tcu::TestStatus SampleMaskInstance::verifyImage (const tcu::ConstPixelBufferAccess& testSampleMaskImage,
1036 const tcu::ConstPixelBufferAccess& minSampleMaskImage,
1037 const tcu::ConstPixelBufferAccess& maxSampleMaskImage)
1039 const deUint32 testColorCount = getUniqueColorsCount(testSampleMaskImage);
1040 const deUint32 minColorCount = getUniqueColorsCount(minSampleMaskImage);
1041 const deUint32 maxColorCount = getUniqueColorsCount(maxSampleMaskImage);
1043 tcu::TestLog& log = m_context.getTestContext().getLog();
1045 log << tcu::TestLog::Message
1046 << "\nColors found: " << testColorCount << "\n"
1047 << "Min. colors expected: " << minColorCount << "\n"
1048 << "Max. colors expected: " << maxColorCount << "\n"
1049 << tcu::TestLog::EndMessage;
1051 if (minColorCount > testColorCount || testColorCount > maxColorCount)
1052 return tcu::TestStatus::fail("Unique colors out of expected bounds");
1054 return tcu::TestStatus::pass("Unique colors within expected bounds");
1057 tcu::TestStatus testRasterSamplesConsistency (Context& context, GeometryType geometryType)
1059 // Use triangle only.
1060 DE_UNREF(geometryType);
1062 const VkSampleCountFlagBits samples[] =
1064 VK_SAMPLE_COUNT_1_BIT,
1065 VK_SAMPLE_COUNT_2_BIT,
1066 VK_SAMPLE_COUNT_4_BIT,
1067 VK_SAMPLE_COUNT_8_BIT,
1068 VK_SAMPLE_COUNT_16_BIT,
1069 VK_SAMPLE_COUNT_32_BIT,
1070 VK_SAMPLE_COUNT_64_BIT
1073 const Vertex4RGBA vertexData[3] =
1076 tcu::Vec4(-0.75f, 0.0f, 0.0f, 1.0f),
1077 tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f)
1080 tcu::Vec4(0.75f, 0.125f, 0.0f, 1.0f),
1081 tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f)
1084 tcu::Vec4(0.75f, -0.125f, 0.0f, 1.0f),
1085 tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f)
1089 const std::vector<Vertex4RGBA> vertices (vertexData, vertexData + 3);
1090 deUint32 prevUniqueColors = 2;
1091 int renderCount = 0;
1093 // Do not render with 1 sample (start with samplesNdx = 1).
1094 for (int samplesNdx = 1; samplesNdx < DE_LENGTH_OF_ARRAY(samples); samplesNdx++)
1096 if (!isSupportedSampleCount(context.getInstanceInterface(), context.getPhysicalDevice(), samples[samplesNdx]))
1099 const VkPipelineMultisampleStateCreateInfo multisampleStateParams =
1101 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, // VkStructureType sType;
1102 DE_NULL, // const void* pNext;
1103 0u, // VkPipelineMultisampleStateCreateFlags flags;
1104 samples[samplesNdx], // VkSampleCountFlagBits rasterizationSamples;
1105 false, // VkBool32 sampleShadingEnable;
1106 0.0f, // float minSampleShading;
1107 DE_NULL, // const VkSampleMask* pSampleMask;
1108 false, // VkBool32 alphaToCoverageEnable;
1109 false // VkBool32 alphaToOneEnable;
1112 MultisampleRenderer renderer (context, VK_FORMAT_R8G8B8A8_UNORM, tcu::IVec2(32, 32), VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, vertices, multisampleStateParams, getDefaultColorBlendAttachmentState());
1113 de::MovePtr<tcu::TextureLevel> result = renderer.render();
1114 const deUint32 uniqueColors = getUniqueColorsCount(result->getAccess());
1118 if (prevUniqueColors > uniqueColors)
1120 std::ostringstream message;
1122 message << "More unique colors generated with " << samples[samplesNdx - 1] << " than with " << samples[samplesNdx];
1123 return tcu::TestStatus::fail(message.str());
1126 prevUniqueColors = uniqueColors;
1129 if (renderCount == 0)
1130 throw tcu::NotSupportedError("Multisampling is unsupported");
1132 return tcu::TestStatus::pass("Number of unique colors increases as the sample count increases");
1136 // AlphaToOneInstance
1138 AlphaToOneInstance::AlphaToOneInstance (Context& context,
1139 VkPrimitiveTopology topology,
1140 const std::vector<Vertex4RGBA>& vertices,
1141 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
1142 const VkPipelineColorBlendAttachmentState& blendState)
1143 : vkt::TestInstance (context)
1144 , m_colorFormat (VK_FORMAT_R8G8B8A8_UNORM)
1145 , m_renderSize (32, 32)
1146 , m_primitiveTopology (topology)
1147 , m_vertices (vertices)
1148 , m_multisampleStateParams (multisampleStateParams)
1149 , m_colorBlendState (blendState)
1151 VkPhysicalDeviceFeatures deviceFeatures;
1153 context.getInstanceInterface().getPhysicalDeviceFeatures(context.getPhysicalDevice(), &deviceFeatures);
1155 if (!deviceFeatures.alphaToOne)
1156 throw tcu::NotSupportedError("Alpha-to-one is not supported");
1159 tcu::TestStatus AlphaToOneInstance::iterate (void)
1161 DE_ASSERT(m_multisampleStateParams.alphaToOneEnable);
1162 DE_ASSERT(m_colorBlendState.blendEnable);
1164 de::MovePtr<tcu::TextureLevel> alphaOneImage;
1165 de::MovePtr<tcu::TextureLevel> noAlphaOneImage;
1167 // Render with blend enabled and alpha to one on
1169 MultisampleRenderer renderer (m_context, m_colorFormat, m_renderSize, m_primitiveTopology, m_vertices, m_multisampleStateParams, m_colorBlendState);
1170 alphaOneImage = renderer.render();
1173 // Render with blend enabled and alpha to one off
1175 VkPipelineMultisampleStateCreateInfo multisampleParams = m_multisampleStateParams;
1176 multisampleParams.alphaToOneEnable = false;
1178 MultisampleRenderer renderer (m_context, m_colorFormat, m_renderSize, m_primitiveTopology, m_vertices, multisampleParams, m_colorBlendState);
1179 noAlphaOneImage = renderer.render();
1182 return verifyImage(alphaOneImage->getAccess(), noAlphaOneImage->getAccess());
1185 tcu::TestStatus AlphaToOneInstance::verifyImage (const tcu::ConstPixelBufferAccess& alphaOneImage,
1186 const tcu::ConstPixelBufferAccess& noAlphaOneImage)
1188 for (int y = 0; y < m_renderSize.y(); y++)
1190 for (int x = 0; x < m_renderSize.x(); x++)
1192 if (!tcu::boolAll(tcu::greaterThanEqual(alphaOneImage.getPixel(x, y), noAlphaOneImage.getPixel(x, y))))
1194 std::ostringstream message;
1195 message << "Unsatisfied condition: " << alphaOneImage.getPixel(x, y) << " >= " << noAlphaOneImage.getPixel(x, y);
1196 return tcu::TestStatus::fail(message.str());
1201 return tcu::TestStatus::pass("Image rendered with alpha-to-one contains pixels of image rendered with no alpha-to-one");
1205 // AlphaToCoverageInstance
1207 AlphaToCoverageInstance::AlphaToCoverageInstance (Context& context,
1208 VkPrimitiveTopology topology,
1209 const std::vector<Vertex4RGBA>& vertices,
1210 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
1211 const VkPipelineColorBlendAttachmentState& blendState,
1212 GeometryType geometryType)
1213 : vkt::TestInstance (context)
1214 , m_colorFormat (VK_FORMAT_R8G8B8A8_UNORM)
1215 , m_renderSize (32, 32)
1216 , m_primitiveTopology (topology)
1217 , m_vertices (vertices)
1218 , m_multisampleStateParams (multisampleStateParams)
1219 , m_colorBlendState (blendState)
1220 , m_geometryType (geometryType)
1224 tcu::TestStatus AlphaToCoverageInstance::iterate (void)
1226 DE_ASSERT(m_multisampleStateParams.alphaToCoverageEnable);
1228 de::MovePtr<tcu::TextureLevel> result;
1229 MultisampleRenderer renderer (m_context, m_colorFormat, m_renderSize, m_primitiveTopology, m_vertices, m_multisampleStateParams, m_colorBlendState);
1231 result = renderer.render();
1233 return verifyImage(result->getAccess());
1236 tcu::TestStatus AlphaToCoverageInstance::verifyImage (const tcu::ConstPixelBufferAccess& result)
1238 float maxColorValue;
1240 switch (m_geometryType)
1242 case GEOMETRY_TYPE_OPAQUE_QUAD:
1243 maxColorValue = 1.01f;
1246 case GEOMETRY_TYPE_TRANSLUCENT_QUAD:
1247 maxColorValue = 0.5f;
1250 case GEOMETRY_TYPE_INVISIBLE_QUAD:
1251 maxColorValue = 0.01f;
1255 maxColorValue = 0.0f; // Garbage
1259 for (int y = 0; y < m_renderSize.y(); y++)
1261 for (int x = 0; x < m_renderSize.x(); x++)
1263 if (result.getPixel(x, y).x() > maxColorValue)
1265 std::ostringstream message;
1266 message << "Pixel is not below the threshold value (" << result.getPixel(x, y).x() << " > " << maxColorValue << ")";
1267 return tcu::TestStatus::fail(message.str());
1272 return tcu::TestStatus::pass("Image matches reference value");
1276 // MultisampleRenderer
1278 MultisampleRenderer::MultisampleRenderer (Context& context,
1279 VkFormat colorFormat,
1280 const tcu::IVec2& renderSize,
1281 VkPrimitiveTopology topology,
1282 const std::vector<Vertex4RGBA>& vertices,
1283 const VkPipelineMultisampleStateCreateInfo& multisampleStateParams,
1284 const VkPipelineColorBlendAttachmentState& blendState)
1286 : m_context (context)
1287 , m_colorFormat (colorFormat)
1288 , m_renderSize (renderSize)
1289 , m_multisampleStateParams (multisampleStateParams)
1290 , m_colorBlendState (blendState)
1292 if (!isSupportedSampleCount(context.getInstanceInterface(), context.getPhysicalDevice(), multisampleStateParams.rasterizationSamples))
1293 throw tcu::NotSupportedError("Unsupported number of rasterization samples");
1295 const DeviceInterface& vk = context.getDeviceInterface();
1296 const VkDevice vkDevice = context.getDevice();
1297 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
1298 SimpleAllocator memAlloc (vk, vkDevice, getPhysicalDeviceMemoryProperties(context.getInstanceInterface(), context.getPhysicalDevice()));
1299 const VkComponentMapping componentMappingRGBA = { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A };
1301 // Create color image
1303 const VkImageCreateInfo colorImageParams =
1305 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType;
1306 DE_NULL, // const void* pNext;
1307 0u, // VkImageCreateFlags flags;
1308 VK_IMAGE_TYPE_2D, // VkImageType imageType;
1309 m_colorFormat, // VkFormat format;
1310 { m_renderSize.x(), m_renderSize.y(), 1u }, // VkExtent3D extent;
1311 1u, // deUint32 mipLevels;
1312 1u, // deUint32 arrayLayers;
1313 m_multisampleStateParams.rasterizationSamples, // VkSampleCountFlagBits samples;
1314 VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling;
1315 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, // VkImageUsageFlags usage;
1316 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
1317 1u, // deUint32 queueFamilyIndexCount;
1318 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
1319 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout;
1322 m_colorImage = createImage(vk, vkDevice, &colorImageParams);
1324 // Allocate and bind color image memory
1325 m_colorImageAlloc = memAlloc.allocate(getImageMemoryRequirements(vk, vkDevice, *m_colorImage), MemoryRequirement::Any);
1326 VK_CHECK(vk.bindImageMemory(vkDevice, *m_colorImage, m_colorImageAlloc->getMemory(), m_colorImageAlloc->getOffset()));
1329 // Create resolve image
1331 const VkImageCreateInfo resolveImageParams =
1333 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType;
1334 DE_NULL, // const void* pNext;
1335 0u, // VkImageCreateFlags flags;
1336 VK_IMAGE_TYPE_2D, // VkImageType imageType;
1337 m_colorFormat, // VkFormat format;
1338 { m_renderSize.x(), m_renderSize.y(), 1u }, // VkExtent3D extent;
1339 1u, // deUint32 mipLevels;
1340 1u, // deUint32 arrayLayers;
1341 VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits samples;
1342 VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling;
1343 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | // VkImageUsageFlags usage;
1344 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
1345 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
1346 1u, // deUint32 queueFamilyIndexCount;
1347 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
1348 VK_IMAGE_LAYOUT_UNDEFINED // VkImageLayout initialLayout;
1351 m_resolveImage = createImage(vk, vkDevice, &resolveImageParams);
1353 // Allocate and bind resolve image memory
1354 m_resolveImageAlloc = memAlloc.allocate(getImageMemoryRequirements(vk, vkDevice, *m_resolveImage), MemoryRequirement::Any);
1355 VK_CHECK(vk.bindImageMemory(vkDevice, *m_resolveImage, m_resolveImageAlloc->getMemory(), m_resolveImageAlloc->getOffset()));
1358 // Create color attachment view
1360 const VkImageViewCreateInfo colorAttachmentViewParams =
1362 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, // VkStructureType sType;
1363 DE_NULL, // const void* pNext;
1364 0u, // VkImageViewCreateFlags flags;
1365 *m_colorImage, // VkImage image;
1366 VK_IMAGE_VIEW_TYPE_2D, // VkImageViewType viewType;
1367 m_colorFormat, // VkFormat format;
1368 componentMappingRGBA, // VkComponentMapping components;
1369 { VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, 1u } // VkImageSubresourceRange subresourceRange;
1372 m_colorAttachmentView = createImageView(vk, vkDevice, &colorAttachmentViewParams);
1375 // Create resolve attachment view
1377 const VkImageViewCreateInfo resolveAttachmentViewParams =
1379 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, // VkStructureType sType;
1380 DE_NULL, // const void* pNext;
1381 0u, // VkImageViewCreateFlags flags;
1382 *m_resolveImage, // VkImage image;
1383 VK_IMAGE_VIEW_TYPE_2D, // VkImageViewType viewType;
1384 m_colorFormat, // VkFormat format;
1385 componentMappingRGBA, // VkComponentMapping components;
1386 { VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, 1u } // VkImageSubresourceRange subresourceRange;
1389 m_resolveAttachmentView = createImageView(vk, vkDevice, &resolveAttachmentViewParams);
1392 // Create render pass
1394 const VkAttachmentDescription attachmentDescriptions[2] =
1397 0u, // VkAttachmentDescriptionFlags flags;
1398 m_colorFormat, // VkFormat format;
1399 m_multisampleStateParams.rasterizationSamples, // VkSampleCountFlagBits samples;
1400 VK_ATTACHMENT_LOAD_OP_CLEAR, // VkAttachmentLoadOp loadOp;
1401 VK_ATTACHMENT_STORE_OP_STORE, // VkAttachmentStoreOp storeOp;
1402 VK_ATTACHMENT_LOAD_OP_DONT_CARE, // VkAttachmentLoadOp stencilLoadOp;
1403 VK_ATTACHMENT_STORE_OP_DONT_CARE, // VkAttachmentStoreOp stencilStoreOp;
1404 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout initialLayout;
1405 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL // VkImageLayout finalLayout;
1408 0u, // VkAttachmentDescriptionFlags flags;
1409 m_colorFormat, // VkFormat format;
1410 VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits samples;
1411 VK_ATTACHMENT_LOAD_OP_CLEAR, // VkAttachmentLoadOp loadOp;
1412 VK_ATTACHMENT_STORE_OP_STORE, // VkAttachmentStoreOp storeOp;
1413 VK_ATTACHMENT_LOAD_OP_DONT_CARE, // VkAttachmentLoadOp stencilLoadOp;
1414 VK_ATTACHMENT_STORE_OP_DONT_CARE, // VkAttachmentStoreOp stencilStoreOp;
1415 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout initialLayout;
1416 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL // VkImageLayout finalLayout;
1420 const VkAttachmentReference colorAttachmentReference =
1422 0u, // deUint32 attachment;
1423 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL // VkImageLayout layout;
1426 const VkAttachmentReference resolveAttachmentReference =
1428 1u, // deUint32 attachment;
1429 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL // VkImageLayout layout;
1432 const VkSubpassDescription subpassDescription =
1434 0u, // VkSubpassDescriptionFlags flags;
1435 VK_PIPELINE_BIND_POINT_GRAPHICS, // VkPipelineBindPoint pipelineBindPoint;
1436 0u, // deUint32 inputAttachmentCount;
1437 DE_NULL, // const VkAttachmentReference* pInputAttachments;
1438 1u, // deUint32 colorAttachmentCount;
1439 &colorAttachmentReference, // const VkAttachmentReference* pColorAttachments;
1440 &resolveAttachmentReference, // const VkAttachmentReference* pResolveAttachments;
1441 DE_NULL, // const VkAttachmentReference* pDepthStencilAttachment;
1442 0u, // deUint32 preserveAttachmentCount;
1443 DE_NULL // const VkAttachmentReference* pPreserveAttachments;
1446 const VkRenderPassCreateInfo renderPassParams =
1448 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, // VkStructureType sType;
1449 DE_NULL, // const void* pNext;
1450 0u, // VkRenderPassCreateFlags flags;
1451 2u, // deUint32 attachmentCount;
1452 attachmentDescriptions, // const VkAttachmentDescription* pAttachments;
1453 1u, // deUint32 subpassCount;
1454 &subpassDescription, // const VkSubpassDescription* pSubpasses;
1455 0u, // deUint32 dependencyCount;
1456 DE_NULL // const VkSubpassDependency* pDependencies;
1459 m_renderPass = createRenderPass(vk, vkDevice, &renderPassParams);
1462 // Create framebuffer
1464 const VkImageView attachments[2] =
1466 *m_colorAttachmentView,
1467 *m_resolveAttachmentView
1470 const VkFramebufferCreateInfo framebufferParams =
1472 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, // VkStructureType sType;
1473 DE_NULL, // const void* pNext;
1474 0u, // VkFramebufferCreateFlags flags;
1475 *m_renderPass, // VkRenderPass renderPass;
1476 2u, // deUint32 attachmentCount;
1477 attachments, // const VkImageView* pAttachments;
1478 (deUint32)m_renderSize.x(), // deUint32 width;
1479 (deUint32)m_renderSize.y(), // deUint32 height;
1480 1u // deUint32 layers;
1483 m_framebuffer = createFramebuffer(vk, vkDevice, &framebufferParams);
1486 // Create pipeline layout
1488 const VkPipelineLayoutCreateInfo pipelineLayoutParams =
1490 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, // VkStructureType sType;
1491 DE_NULL, // const void* pNext;
1492 0u, // VkPipelineLayoutCreateFlags flags;
1493 0u, // deUint32 setLayoutCount;
1494 DE_NULL, // const VkDescriptorSetLayout* pSetLayouts;
1495 0u, // deUint32 pushConstantRangeCount;
1496 DE_NULL // const VkPushConstantRange* pPushConstantRanges;
1499 m_pipelineLayout = createPipelineLayout(vk, vkDevice, &pipelineLayoutParams);
1502 m_vertexShaderModule = createShaderModule(vk, vkDevice, m_context.getBinaryCollection().get("color_vert"), 0);
1503 m_fragmentShaderModule = createShaderModule(vk, vkDevice, m_context.getBinaryCollection().get("color_frag"), 0);
1507 const VkPipelineShaderStageCreateInfo shaderStageParams[2] =
1510 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, // VkStructureType sType;
1511 DE_NULL, // const void* pNext;
1512 0u, // VkPipelineShaderStageCreateFlags flags;
1513 VK_SHADER_STAGE_VERTEX_BIT, // VkShaderStageFlagBits stage;
1514 *m_vertexShaderModule, // VkShaderModule module;
1515 "main", // const char* pName;
1516 DE_NULL // const VkSpecializationInfo* pSpecializationInfo;
1519 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, // VkStructureType sType;
1520 DE_NULL, // const void* pNext;
1521 0u, // VkPipelineShaderStageCreateFlags flags;
1522 VK_SHADER_STAGE_FRAGMENT_BIT, // VkShaderStageFlagBits stage;
1523 *m_fragmentShaderModule, // VkShaderModule module;
1524 "main", // const char* pName;
1525 DE_NULL // const VkSpecializationInfo* pSpecializationInfo;
1529 const VkVertexInputBindingDescription vertexInputBindingDescription =
1531 0u, // deUint32 binding;
1532 sizeof(Vertex4RGBA), // deUint32 stride;
1533 VK_VERTEX_INPUT_RATE_VERTEX // VkVertexInputRate inputRate;
1536 const VkVertexInputAttributeDescription vertexInputAttributeDescriptions[2] =
1539 0u, // deUint32 location;
1540 0u, // deUint32 binding;
1541 VK_FORMAT_R32G32B32A32_SFLOAT, // VkFormat format;
1542 0u // deUint32 offset;
1545 1u, // deUint32 location;
1546 0u, // deUint32 binding;
1547 VK_FORMAT_R32G32B32A32_SFLOAT, // VkFormat format;
1548 DE_OFFSET_OF(Vertex4RGBA, color), // deUint32 offset;
1552 const VkPipelineVertexInputStateCreateInfo vertexInputStateParams =
1554 VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO, // VkStructureType sType;
1555 DE_NULL, // const void* pNext;
1556 0u, // VkPipelineVertexInputStateCreateFlags flags;
1557 1u, // deUint32 vertexBindingDescriptionCount;
1558 &vertexInputBindingDescription, // const VkVertexInputBindingDescription* pVertexBindingDescriptions;
1559 2u, // deUint32 vertexAttributeDescriptionCount;
1560 vertexInputAttributeDescriptions // const VkVertexInputAttributeDescription* pVertexAttributeDescriptions;
1563 const VkPipelineInputAssemblyStateCreateInfo inputAssemblyStateParams =
1565 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, // VkStructureType sType;
1566 DE_NULL, // const void* pNext;
1567 0u, // VkPipelineInputAssemblyStateCreateFlags flags;
1568 topology, // VkPrimitiveTopology topology;
1569 false // VkBool32 primitiveRestartEnable;
1572 const VkViewport viewport =
1576 (float)m_renderSize.x(), // float width;
1577 (float)m_renderSize.y(), // float height;
1578 0.0f, // float minDepth;
1579 1.0f // float maxDepth;
1582 const VkRect2D scissor =
1584 { 0, 0 }, // VkOffset2D offset;
1585 { m_renderSize.x(), m_renderSize.y() } // VkExtent2D extent;
1588 const VkPipelineViewportStateCreateInfo viewportStateParams =
1590 VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO, // VkStructureType sType;
1591 DE_NULL, // const void* pNext;
1592 0u, // VkPipelineViewportStateCreateFlags flags;
1593 1u, // deUint32 viewportCount;
1594 &viewport, // const VkViewport* pViewports;
1595 1u, // deUint32 scissorCount;
1596 &scissor // const VkRect2D* pScissors;
1599 const VkPipelineRasterizationStateCreateInfo rasterStateParams =
1601 VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO, // VkStructureType sType;
1602 DE_NULL, // const void* pNext;
1603 0u, // VkPipelineRasterizationStateCreateFlags flags;
1604 false, // VkBool32 depthClampEnable;
1605 false, // VkBool32 rasterizerDiscardEnable;
1606 VK_POLYGON_MODE_FILL, // VkPolygonMode polygonMode;
1607 VK_CULL_MODE_NONE, // VkCullModeFlags cullMode;
1608 VK_FRONT_FACE_COUNTER_CLOCKWISE, // VkFrontFace frontFace;
1609 VK_FALSE, // VkBool32 depthBiasEnable;
1610 0.0f, // float depthBiasConstantFactor;
1611 0.0f, // float depthBiasClamp;
1612 0.0f, // float depthBiasSlopeFactor;
1613 1.0f // float lineWidth;
1616 const VkPipelineColorBlendStateCreateInfo colorBlendStateParams =
1618 VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO, // VkStructureType sType;
1619 DE_NULL, // const void* pNext;
1620 0u, // VkPipelineColorBlendStateCreateFlags flags;
1621 false, // VkBool32 logicOpEnable;
1622 VK_LOGIC_OP_COPY, // VkLogicOp logicOp;
1623 1u, // deUint32 attachmentCount;
1624 &m_colorBlendState, // const VkPipelineColorBlendAttachmentState* pAttachments;
1625 { 0.0f, 0.0f, 0.0f, 0.0f } // float blendConstants[4];
1628 const VkPipelineDynamicStateCreateInfo dynamicStateParams =
1630 VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO, // VkStructureType sType;
1631 DE_NULL, // const void* pNext;
1632 0u, // VkPipelineDynamicStateCreateFlags flags;
1633 0u, // deUint32 dynamicStateCount;
1634 DE_NULL // const VkDynamicState* pDynamicStates;
1637 const VkPipelineDepthStencilStateCreateInfo depthStencilStateParams =
1639 VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO, // VkStructureType sType;
1640 DE_NULL, // const void* pNext;
1641 0u, // VkPipelineDepthStencilStateCreateFlags flags;
1642 false, // VkBool32 depthTestEnable;
1643 false, // VkBool32 depthWriteEnable;
1644 VK_COMPARE_OP_LESS, // VkCompareOp depthCompareOp;
1645 false, // VkBool32 depthBoundsTestEnable;
1646 false, // VkBool32 stencilTestEnable;
1647 // VkStencilOpState front;
1649 VK_STENCIL_OP_KEEP, // VkStencilOp failOp;
1650 VK_STENCIL_OP_KEEP, // VkStencilOp passOp;
1651 VK_STENCIL_OP_KEEP, // VkStencilOp depthFailOp;
1652 VK_COMPARE_OP_NEVER, // VkCompareOp compareOp;
1653 0u, // deUint32 compareMask;
1654 0u, // deUint32 writeMask;
1655 0u, // deUint32 reference;
1657 // VkStencilOpState back;
1659 VK_STENCIL_OP_KEEP, // VkStencilOp failOp;
1660 VK_STENCIL_OP_KEEP, // VkStencilOp passOp;
1661 VK_STENCIL_OP_KEEP, // VkStencilOp depthFailOp;
1662 VK_COMPARE_OP_NEVER, // VkCompareOp compareOp;
1663 0u, // deUint32 compareMask;
1664 0u, // deUint32 writeMask;
1665 0u, // deUint32 reference;
1667 -1.0f, // float minDepthBounds;
1668 +1.0f, // float maxDepthBounds;
1671 const VkGraphicsPipelineCreateInfo graphicsPipelineParams =
1673 VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO, // VkStructureType sType;
1674 DE_NULL, // const void* pNext;
1675 0u, // VkPipelineCreateFlags flags;
1676 2u, // deUint32 stageCount;
1677 shaderStageParams, // const VkPipelineShaderStageCreateInfo* pStages;
1678 &vertexInputStateParams, // const VkPipelineVertexInputStateCreateInfo* pVertexInputState;
1679 &inputAssemblyStateParams, // const VkPipelineInputAssemblyStateCreateInfo* pInputAssemblyState;
1680 DE_NULL, // const VkPipelineTessellationStateCreateInfo* pTessellationState;
1681 &viewportStateParams, // const VkPipelineViewportStateCreateInfo* pViewportState;
1682 &rasterStateParams, // const VkPipelineRasterizationStateCreateInfo* pRasterizationState;
1683 &m_multisampleStateParams, // const VkPipelineMultisampleStateCreateInfo* pMultisampleState;
1684 &depthStencilStateParams, // const VkPipelineDepthStencilStateCreateInfo* pDepthStencilState;
1685 &colorBlendStateParams, // const VkPipelineColorBlendStateCreateInfo* pColorBlendState;
1686 &dynamicStateParams, // const VkPipelineDynamicStateCreateInfo* pDynamicState;
1687 *m_pipelineLayout, // VkPipelineLayout layout;
1688 *m_renderPass, // VkRenderPass renderPass;
1689 0u, // deUint32 subpass;
1690 0u, // VkPipeline basePipelineHandle;
1691 0u // deInt32 basePipelineIndex;
1694 m_graphicsPipeline = createGraphicsPipeline(vk, vkDevice, DE_NULL, &graphicsPipelineParams);
1697 // Create vertex buffer
1699 const VkBufferCreateInfo vertexBufferParams =
1701 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
1702 DE_NULL, // const void* pNext;
1703 0u, // VkBufferCreateFlags flags;
1704 1024u, // VkDeviceSize size;
1705 VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, // VkBufferUsageFlags usage;
1706 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
1707 1u, // deUint32 queueFamilyIndexCount;
1708 &queueFamilyIndex // const deUint32* pQueueFamilyIndices;
1711 m_vertexBuffer = createBuffer(vk, vkDevice, &vertexBufferParams);
1712 m_vertexBufferAlloc = memAlloc.allocate(getBufferMemoryRequirements(vk, vkDevice, *m_vertexBuffer), MemoryRequirement::HostVisible);
1714 VK_CHECK(vk.bindBufferMemory(vkDevice, *m_vertexBuffer, m_vertexBufferAlloc->getMemory(), m_vertexBufferAlloc->getOffset()));
1716 // Load vertices into vertex buffer
1717 deMemcpy(m_vertexBufferAlloc->getHostPtr(), vertices.data(), vertices.size() * sizeof(Vertex4RGBA));
1718 flushMappedMemoryRange(vk, vkDevice, m_vertexBufferAlloc->getMemory(), m_vertexBufferAlloc->getOffset(), vertexBufferParams.size);
1721 // Create command pool
1723 const VkCommandPoolCreateInfo cmdPoolParams =
1725 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // VkStructureType sType;
1726 DE_NULL, // const void* pNext;
1727 VK_COMMAND_POOL_CREATE_TRANSIENT_BIT, // VkCommandPoolCreateFlags flags;
1728 queueFamilyIndex, // deUint32 queueFamilyIndex;
1731 m_cmdPool = createCommandPool(vk, vkDevice, &cmdPoolParams);
1734 // Create command buffer
1736 const VkCommandBufferAllocateInfo cmdBufferAllocateInfo =
1738 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType;
1739 DE_NULL, // const void* pNext;
1740 *m_cmdPool, // VkCommandPool commandPool;
1741 VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCommandBufferLevel level;
1742 1u // deUint32 bufferCount;
1745 const VkCommandBufferBeginInfo cmdBufferBeginInfo =
1747 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType;
1748 DE_NULL, // const void* pNext;
1749 0u, // VkCommandBufferUsageFlags flags;
1750 DE_NULL, // VkRenderPass renderPass;
1751 0u, // deUint32 subpass;
1752 DE_NULL, // VkFramebuffer framebuffer;
1753 false, // VkBool32 occlusionQueryEnable;
1754 0u, // VkQueryControlFlags queryFlags;
1755 0u // VkQueryPipelineStatisticFlags pipelineStatistics;
1758 VkClearValue colorClearValue;
1759 colorClearValue.color.float32[0] = 0.0f;
1760 colorClearValue.color.float32[1] = 0.0f;
1761 colorClearValue.color.float32[2] = 0.0f;
1762 colorClearValue.color.float32[3] = 0.0f;
1764 const VkClearValue clearValues[2] =
1770 const VkRenderPassBeginInfo renderPassBeginInfo =
1772 VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, // VkStructureType sType;
1773 DE_NULL, // const void* pNext;
1774 *m_renderPass, // VkRenderPass renderPass;
1775 *m_framebuffer, // VkFramebuffer framebuffer;
1776 { { 0, 0 }, { m_renderSize.x(), m_renderSize.y() } }, // VkRect2D renderArea;
1777 2, // deUint32 clearValueCount;
1778 clearValues // const VkClearValue* pClearValues;
1781 m_cmdBuffer = allocateCommandBuffer(vk, vkDevice, &cmdBufferAllocateInfo);
1783 VK_CHECK(vk.beginCommandBuffer(*m_cmdBuffer, &cmdBufferBeginInfo));
1784 vk.cmdBeginRenderPass(*m_cmdBuffer, &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
1786 VkDeviceSize vertexBufferOffset = 0u;
1788 vk.cmdBindPipeline(*m_cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *m_graphicsPipeline);
1789 vk.cmdBindVertexBuffers(*m_cmdBuffer, 0, 1, &m_vertexBuffer.get(), &vertexBufferOffset);
1790 vk.cmdDraw(*m_cmdBuffer, (deUint32)vertices.size(), 1, 0, 0);
1792 vk.cmdEndRenderPass(*m_cmdBuffer);
1794 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
1799 const VkFenceCreateInfo fenceParams =
1801 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, // VkStructureType sType;
1802 DE_NULL, // const void* pNext;
1803 0u // VkFenceCreateFlags flags;
1806 m_fence = createFence(vk, vkDevice, &fenceParams);
1810 MultisampleRenderer::~MultisampleRenderer (void)
1814 de::MovePtr<tcu::TextureLevel> MultisampleRenderer::render (void)
1816 const DeviceInterface& vk = m_context.getDeviceInterface();
1817 const VkDevice vkDevice = m_context.getDevice();
1818 const VkQueue queue = m_context.getUniversalQueue();
1819 const deUint32 queueFamilyIndex = m_context.getUniversalQueueFamilyIndex();
1820 SimpleAllocator allocator (vk, vkDevice, getPhysicalDeviceMemoryProperties(m_context.getInstanceInterface(), m_context.getPhysicalDevice()));
1821 const VkSubmitInfo submitInfo =
1823 VK_STRUCTURE_TYPE_SUBMIT_INFO, // VkStructureType sType;
1824 DE_NULL, // const void* pNext;
1825 0u, // deUint32 waitSemaphoreCount;
1826 DE_NULL, // const VkSemaphore* pWaitSemaphores;
1827 1u, // deUint32 commandBufferCount;
1828 &m_cmdBuffer.get(), // const VkCommandBuffer* pCommandBuffers;
1829 0u, // deUint32 signalSemaphoreCount;
1830 DE_NULL // const VkSemaphore* pSignalSemaphores;
1833 VK_CHECK(vk.resetFences(vkDevice, 1, &m_fence.get()));
1834 VK_CHECK(vk.queueSubmit(queue, 1, &submitInfo, *m_fence));
1835 VK_CHECK(vk.waitForFences(vkDevice, 1, &m_fence.get(), true, ~(0ull) /* infinity*/));
1837 return readColorAttachment(vk, vkDevice, queue, queueFamilyIndex, allocator, *m_resolveImage, m_colorFormat, m_renderSize);
1842 tcu::TestCaseGroup* createMultisampleTests (tcu::TestContext& testCtx)
1844 const VkSampleCountFlagBits samples[] =
1846 VK_SAMPLE_COUNT_2_BIT,
1847 VK_SAMPLE_COUNT_4_BIT,
1848 VK_SAMPLE_COUNT_8_BIT,
1849 VK_SAMPLE_COUNT_16_BIT,
1850 VK_SAMPLE_COUNT_32_BIT,
1851 VK_SAMPLE_COUNT_64_BIT
1854 de::MovePtr<tcu::TestCaseGroup> multisampleTests (new tcu::TestCaseGroup(testCtx, "multisample", ""));
1856 // Rasterization samples tests
1858 de::MovePtr<tcu::TestCaseGroup> rasterizationSamplesTests(new tcu::TestCaseGroup(testCtx, "raster_samples", ""));
1860 for (int samplesNdx = 0; samplesNdx < DE_LENGTH_OF_ARRAY(samples); samplesNdx++)
1862 std::ostringstream caseName;
1863 caseName << "samples_" << samples[samplesNdx];
1865 de::MovePtr<tcu::TestCaseGroup> samplesTests (new tcu::TestCaseGroup(testCtx, caseName.str().c_str(), ""));
1867 samplesTests->addChild(new RasterizationSamplesTest(testCtx, "primitive_triangle", "", samples[samplesNdx], GEOMETRY_TYPE_OPAQUE_TRIANGLE));
1868 samplesTests->addChild(new RasterizationSamplesTest(testCtx, "primitive_line", "", samples[samplesNdx], GEOMETRY_TYPE_OPAQUE_LINE));
1869 samplesTests->addChild(new RasterizationSamplesTest(testCtx, "primitive_point", "", samples[samplesNdx], GEOMETRY_TYPE_OPAQUE_POINT));
1871 rasterizationSamplesTests->addChild(samplesTests.release());
1874 multisampleTests->addChild(rasterizationSamplesTests.release());
1877 // Raster samples consistency check
1879 de::MovePtr<tcu::TestCaseGroup> rasterSamplesConsistencyTests(new tcu::TestCaseGroup(testCtx, "raster_samples_consistency", ""));
1881 addFunctionCaseWithPrograms(rasterSamplesConsistencyTests.get(),
1882 "unique_colors_check",
1884 initMultisamplePrograms,
1885 testRasterSamplesConsistency,
1886 GEOMETRY_TYPE_OPAQUE_TRIANGLE);
1888 multisampleTests->addChild(rasterSamplesConsistencyTests.release());
1891 // minSampleShading tests
1896 float minSampleShading;
1899 const TestConfig testConfigs[] =
1901 { "min_0_0", 0.0f },
1902 { "min_0_25", 0.25f },
1903 { "min_0_5", 0.5f },
1904 { "min_0_75", 0.75f },
1908 de::MovePtr<tcu::TestCaseGroup> minSampleShadingTests(new tcu::TestCaseGroup(testCtx, "min_sample_shading", ""));
1910 for (int configNdx = 0; configNdx < DE_LENGTH_OF_ARRAY(testConfigs); configNdx++)
1912 const TestConfig& testConfig = testConfigs[configNdx];
1913 de::MovePtr<tcu::TestCaseGroup> minShadingValueTests (new tcu::TestCaseGroup(testCtx, testConfigs[configNdx].name, ""));
1915 for (int samplesNdx = 0; samplesNdx < DE_LENGTH_OF_ARRAY(samples); samplesNdx++)
1917 std::ostringstream caseName;
1918 caseName << "samples_" << samples[samplesNdx];
1920 de::MovePtr<tcu::TestCaseGroup> samplesTests (new tcu::TestCaseGroup(testCtx, caseName.str().c_str(), ""));
1922 samplesTests->addChild(new MinSampleShadingTest(testCtx, "primitive_triangle", "", samples[samplesNdx], testConfig.minSampleShading, GEOMETRY_TYPE_OPAQUE_TRIANGLE));
1923 samplesTests->addChild(new MinSampleShadingTest(testCtx, "primitive_line", "", samples[samplesNdx], testConfig.minSampleShading, GEOMETRY_TYPE_OPAQUE_LINE));
1924 samplesTests->addChild(new MinSampleShadingTest(testCtx, "primitive_point", "", samples[samplesNdx], testConfig.minSampleShading, GEOMETRY_TYPE_OPAQUE_POINT));
1926 minShadingValueTests->addChild(samplesTests.release());
1929 minSampleShadingTests->addChild(minShadingValueTests.release());
1932 multisampleTests->addChild(minSampleShadingTests.release());
1935 // pSampleMask tests
1940 const char* description;
1941 VkSampleMask sampleMask;
1944 const TestConfig testConfigs[] =
1946 { "mask_all_on", "All mask bits are off", 0x0 },
1947 { "mask_all_off", "All mask bits are on", 0xFFFFFFFF },
1948 { "mask_one", "All mask elements are 0x1", 0x1},
1949 { "mask_random", "All mask elements are 0xAAAAAAAA", 0xAAAAAAAA },
1952 de::MovePtr<tcu::TestCaseGroup> sampleMaskTests(new tcu::TestCaseGroup(testCtx, "sample_mask", ""));
1954 for (int configNdx = 0; configNdx < DE_LENGTH_OF_ARRAY(testConfigs); configNdx++)
1956 const TestConfig& testConfig = testConfigs[configNdx];
1957 de::MovePtr<tcu::TestCaseGroup> sampleMaskValueTests (new tcu::TestCaseGroup(testCtx, testConfig.name, testConfig.description));
1959 for (int samplesNdx = 0; samplesNdx < DE_LENGTH_OF_ARRAY(samples); samplesNdx++)
1961 std::ostringstream caseName;
1962 caseName << "samples_" << samples[samplesNdx];
1964 const deUint32 sampleMaskCount = samples[samplesNdx] / 32;
1965 de::MovePtr<tcu::TestCaseGroup> samplesTests (new tcu::TestCaseGroup(testCtx, caseName.str().c_str(), ""));
1967 std::vector<VkSampleMask> mask;
1968 for (deUint32 maskNdx = 0; maskNdx < sampleMaskCount; maskNdx++)
1969 mask.push_back(testConfig.sampleMask);
1971 samplesTests->addChild(new SampleMaskTest(testCtx, "primitive_triangle", "", samples[samplesNdx], mask, GEOMETRY_TYPE_OPAQUE_TRIANGLE));
1972 samplesTests->addChild(new SampleMaskTest(testCtx, "primitive_line", "", samples[samplesNdx], mask, GEOMETRY_TYPE_OPAQUE_LINE));
1973 samplesTests->addChild(new SampleMaskTest(testCtx, "primitive_point", "", samples[samplesNdx], mask, GEOMETRY_TYPE_OPAQUE_POINT));
1975 sampleMaskValueTests->addChild(samplesTests.release());
1978 sampleMaskTests->addChild(sampleMaskValueTests.release());
1981 multisampleTests->addChild(sampleMaskTests.release());
1987 de::MovePtr<tcu::TestCaseGroup> alphaToOneTests(new tcu::TestCaseGroup(testCtx, "alpha_to_one", ""));
1989 for (int samplesNdx = 0; samplesNdx < DE_LENGTH_OF_ARRAY(samples); samplesNdx++)
1991 std::ostringstream caseName;
1992 caseName << "samples_" << samples[samplesNdx];
1994 alphaToOneTests->addChild(new AlphaToOneTest(testCtx, caseName.str(), "", samples[samplesNdx]));
1997 multisampleTests->addChild(alphaToOneTests.release());
2000 // AlphaToCoverageEnable tests
2002 de::MovePtr<tcu::TestCaseGroup> alphaToCoverageTests (new tcu::TestCaseGroup(testCtx, "alpha_to_coverage", ""));
2004 for (int samplesNdx = 0; samplesNdx < DE_LENGTH_OF_ARRAY(samples); samplesNdx++)
2006 std::ostringstream caseName;
2007 caseName << "samples_" << samples[samplesNdx];
2009 de::MovePtr<tcu::TestCaseGroup> samplesTests (new tcu::TestCaseGroup(testCtx, caseName.str().c_str(), ""));
2011 samplesTests->addChild(new AlphaToCoverageTest(testCtx, "alpha_opaque", "", samples[samplesNdx], GEOMETRY_TYPE_OPAQUE_QUAD));
2012 samplesTests->addChild(new AlphaToCoverageTest(testCtx, "alpha_translucent", "", samples[samplesNdx], GEOMETRY_TYPE_TRANSLUCENT_QUAD));
2013 samplesTests->addChild(new AlphaToCoverageTest(testCtx, "alpha_invisible", "", samples[samplesNdx], GEOMETRY_TYPE_INVISIBLE_QUAD));
2015 alphaToCoverageTests->addChild(samplesTests.release());
2017 multisampleTests->addChild(alphaToCoverageTests.release());
2020 return multisampleTests.release();