1 /*-------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
5 * Copyright (c) 2018 The Khronos Group Inc.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
21 * \brief VK_KHR_depth_stencil_resolve tests.
22 *//*--------------------------------------------------------------------*/
24 #include "vktRenderPassDepthStencilResolveTests.hpp"
25 #include "vktRenderPassTestsUtil.hpp"
27 #include "vktTestCaseUtil.hpp"
28 #include "vktTestGroupUtil.hpp"
31 #include "vkDeviceUtil.hpp"
32 #include "vkImageUtil.hpp"
33 #include "vkMemUtil.hpp"
34 #include "vkPlatform.hpp"
35 #include "vkPrograms.hpp"
36 #include "vkQueryUtil.hpp"
38 #include "vkRefUtil.hpp"
39 #include "vkTypeUtil.hpp"
40 #include "vkCmdUtil.hpp"
41 #include "vkObjUtil.hpp"
43 #include "tcuImageCompare.hpp"
44 #include "tcuFormatUtil.hpp"
45 #include "tcuResultCollector.hpp"
46 #include "tcuTestLog.hpp"
47 #include "tcuTextureUtil.hpp"
49 #include "deUniquePtr.hpp"
50 #include "deSharedPtr.hpp"
59 typedef de::SharedPtr<vk::Unique<VkImage> > VkImageSp;
60 typedef de::SharedPtr<vk::Unique<VkImageView> > VkImageViewSp;
61 typedef de::SharedPtr<vk::Unique<VkBuffer> > VkBufferSp;
62 typedef de::SharedPtr<vk::Unique<VkPipeline> > VkPipelineSp;
63 typedef de::SharedPtr<Allocation> AllocationSp;
70 using namespace renderpass;
73 de::SharedPtr<T> safeSharedPtr (T* ptr)
77 return de::SharedPtr<T>(ptr);
99 deUint32 resolveBaseLayer;
101 VkImageAspectFlags aspectFlag;
102 deUint32 sampleCount;
103 VkResolveModeFlagBits depthResolveMode;
104 VkResolveModeFlagBits stencilResolveMode;
105 VerifyBuffer verifyBuffer;
106 VkClearDepthStencilValue clearValue;
107 float depthExpectedValue;
108 deUint8 stencilExpectedValue;
109 bool separateDepthStencilLayouts;
113 float get16bitDepthComponent(deUint8* pixelPtr)
115 deUint16* value = reinterpret_cast<deUint16*>(pixelPtr);
116 return static_cast<float>(*value) / 65535.0f;
119 float get24bitDepthComponent(deUint8* pixelPtr)
121 const bool littleEndian = (DE_ENDIANNESS == DE_LITTLE_ENDIAN);
122 deUint32 value = (((deUint32)pixelPtr[0]) << (!littleEndian * 16u)) |
123 (((deUint32)pixelPtr[1]) << 8u) |
124 (((deUint32)pixelPtr[2]) << ( littleEndian * 16u));
125 return static_cast<float>(value) / 16777215.0f;
128 float get32bitDepthComponent(deUint8* pixelPtr)
130 return *(reinterpret_cast<float*>(pixelPtr));
133 class DepthStencilResolveTest : public TestInstance
136 DepthStencilResolveTest (Context& context, TestConfig config);
137 virtual ~DepthStencilResolveTest (void);
139 virtual tcu::TestStatus iterate (void);
142 bool isFeaturesSupported (void);
143 VkSampleCountFlagBits sampleCountBitFromSampleCount (deUint32 count) const;
145 VkImageSp createImage (deUint32 sampleCount, VkImageUsageFlags additionalUsage = 0u);
146 AllocationSp createImageMemory (VkImageSp image);
147 VkImageViewSp createImageView (VkImageSp image, deUint32 baseArrayLayer);
148 AllocationSp createBufferMemory (void);
149 VkBufferSp createBuffer (void);
151 Move<VkRenderPass> createRenderPass (void);
152 Move<VkFramebuffer> createFramebuffer (VkRenderPass renderPass, VkImageViewSp multisampleImageView, VkImageViewSp singlesampleImageView);
153 Move<VkPipelineLayout> createRenderPipelineLayout (void);
154 Move<VkPipeline> createRenderPipeline (VkRenderPass renderPass, VkPipelineLayout renderPipelineLayout);
157 bool verifyDepth (void);
158 bool verifyStencil (void);
161 const TestConfig m_config;
162 const bool m_featureSupported;
164 const InstanceInterface& m_vki;
165 const DeviceInterface& m_vkd;
167 VkPhysicalDevice m_physicalDevice;
169 const Unique<VkCommandPool> m_commandPool;
171 VkImageSp m_multisampleImage;
172 AllocationSp m_multisampleImageMemory;
173 VkImageViewSp m_multisampleImageView;
174 VkImageSp m_singlesampleImage;
175 AllocationSp m_singlesampleImageMemory;
176 VkImageViewSp m_singlesampleImageView;
178 AllocationSp m_bufferMemory;
180 Unique<VkRenderPass> m_renderPass;
181 Unique<VkFramebuffer> m_framebuffer;
182 Unique<VkPipelineLayout> m_renderPipelineLayout;
183 Unique<VkPipeline> m_renderPipeline;
186 DepthStencilResolveTest::DepthStencilResolveTest (Context& context, TestConfig config)
187 : TestInstance (context)
189 , m_featureSupported (isFeaturesSupported())
190 , m_vki (context.getInstanceInterface())
191 , m_vkd (context.getDeviceInterface())
192 , m_device (context.getDevice())
193 , m_physicalDevice (context.getPhysicalDevice())
195 , m_commandPool (createCommandPool(context.getDeviceInterface(), context.getDevice(), VK_COMMAND_POOL_CREATE_TRANSIENT_BIT, context.getUniversalQueueFamilyIndex()))
197 , m_multisampleImage (createImage(m_config.sampleCount, VK_IMAGE_USAGE_TRANSFER_SRC_BIT))
198 , m_multisampleImageMemory (createImageMemory(m_multisampleImage))
199 , m_multisampleImageView (createImageView(m_multisampleImage, 0u))
201 , m_singlesampleImage (createImage(1, (VK_IMAGE_USAGE_TRANSFER_SRC_BIT | (config.unusedResolve ? static_cast<vk::VkImageUsageFlags>(VK_IMAGE_USAGE_TRANSFER_DST_BIT) : 0u))))
202 , m_singlesampleImageMemory (createImageMemory(m_singlesampleImage))
203 , m_singlesampleImageView (createImageView(m_singlesampleImage, m_config.resolveBaseLayer))
205 , m_buffer (createBuffer())
206 , m_bufferMemory (createBufferMemory())
208 , m_renderPass (createRenderPass())
209 , m_framebuffer (createFramebuffer(*m_renderPass, m_multisampleImageView, m_singlesampleImageView))
210 , m_renderPipelineLayout (createRenderPipelineLayout())
211 , m_renderPipeline (createRenderPipeline(*m_renderPass, *m_renderPipelineLayout))
215 DepthStencilResolveTest::~DepthStencilResolveTest (void)
219 bool DepthStencilResolveTest::isFeaturesSupported()
221 m_context.requireDeviceFunctionality("VK_KHR_depth_stencil_resolve");
222 if (m_config.imageLayers > 1)
223 m_context.requireDeviceCoreFeature(DEVICE_CORE_FEATURE_GEOMETRY_SHADER);
225 if (m_config.separateDepthStencilLayouts)
226 m_context.requireDeviceFunctionality("VK_KHR_separate_depth_stencil_layouts");
228 VkPhysicalDeviceDepthStencilResolveProperties dsResolveProperties;
229 deMemset(&dsResolveProperties, 0, sizeof(VkPhysicalDeviceDepthStencilResolveProperties));
230 dsResolveProperties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_STENCIL_RESOLVE_PROPERTIES;
231 dsResolveProperties.pNext = DE_NULL;
233 VkPhysicalDeviceProperties2 deviceProperties;
234 deviceProperties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;
235 deviceProperties.pNext = &dsResolveProperties;
237 // perform query to get supported float control properties
238 const VkPhysicalDevice physicalDevice = m_context.getPhysicalDevice();
239 const vk::InstanceInterface& instanceInterface = m_context.getInstanceInterface();
240 instanceInterface.getPhysicalDeviceProperties2(physicalDevice, &deviceProperties);
242 // check if both modes are supported
243 VkResolveModeFlagBits depthResolveMode = m_config.depthResolveMode;
244 VkResolveModeFlagBits stencilResolveMode = m_config.stencilResolveMode;
245 if ((depthResolveMode != VK_RESOLVE_MODE_NONE) &&
246 !(depthResolveMode & dsResolveProperties.supportedDepthResolveModes))
247 TCU_THROW(NotSupportedError, "Depth resolve mode not supported");
248 if ((stencilResolveMode != VK_RESOLVE_MODE_NONE) &&
249 !(stencilResolveMode & dsResolveProperties.supportedStencilResolveModes))
250 TCU_THROW(NotSupportedError, "Stencil resolve mode not supported");
252 // check if the implementation supports setting the depth and stencil resolve
253 // modes to different values when one of those modes is VK_RESOLVE_MODE_NONE
254 if (dsResolveProperties.independentResolveNone)
256 if ((!dsResolveProperties.independentResolve) &&
257 (depthResolveMode != stencilResolveMode) &&
258 (depthResolveMode != VK_RESOLVE_MODE_NONE) &&
259 (stencilResolveMode != VK_RESOLVE_MODE_NONE))
260 TCU_THROW(NotSupportedError, "Implementation doesn't support diferent resolve modes");
262 else if (!dsResolveProperties.independentResolve && (depthResolveMode != stencilResolveMode))
264 // when independentResolveNone and independentResolve are VK_FALSE then both modes must be the same
265 TCU_THROW(NotSupportedError, "Implementation doesn't support diferent resolve modes");
271 VkSampleCountFlagBits DepthStencilResolveTest::sampleCountBitFromSampleCount (deUint32 count) const
275 case 1: return VK_SAMPLE_COUNT_1_BIT;
276 case 2: return VK_SAMPLE_COUNT_2_BIT;
277 case 4: return VK_SAMPLE_COUNT_4_BIT;
278 case 8: return VK_SAMPLE_COUNT_8_BIT;
279 case 16: return VK_SAMPLE_COUNT_16_BIT;
280 case 32: return VK_SAMPLE_COUNT_32_BIT;
281 case 64: return VK_SAMPLE_COUNT_64_BIT;
284 DE_FATAL("Invalid sample count");
285 return (VkSampleCountFlagBits)0x0;
289 VkImageSp DepthStencilResolveTest::createImage (deUint32 sampleCount, VkImageUsageFlags additionalUsage)
291 const tcu::TextureFormat format(mapVkFormat(m_config.format));
292 const VkImageTiling imageTiling(VK_IMAGE_TILING_OPTIMAL);
293 VkSampleCountFlagBits sampleCountBit(sampleCountBitFromSampleCount(sampleCount));
294 VkImageUsageFlags usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | additionalUsage;
296 VkImageFormatProperties imageFormatProperties;
297 if (m_vki.getPhysicalDeviceImageFormatProperties(m_physicalDevice, m_config.format, VK_IMAGE_TYPE_2D, imageTiling,
298 usage, 0u, &imageFormatProperties) == VK_ERROR_FORMAT_NOT_SUPPORTED)
300 TCU_THROW(NotSupportedError, "Format not supported");
302 if (imageFormatProperties.sampleCounts < sampleCount)
304 TCU_THROW(NotSupportedError, "Sample count not supported");
306 if (imageFormatProperties.maxArrayLayers < m_config.imageLayers)
308 TCU_THROW(NotSupportedError, "Layers count not supported");
311 const VkExtent3D imageExtent =
318 if (!(tcu::hasDepthComponent(format.order) || tcu::hasStencilComponent(format.order)))
319 TCU_THROW(NotSupportedError, "Format can't be used as depth/stencil attachment");
321 if (imageFormatProperties.maxExtent.width < imageExtent.width
322 || imageFormatProperties.maxExtent.height < imageExtent.height
323 || ((imageFormatProperties.sampleCounts & sampleCountBit) == 0)
324 || imageFormatProperties.maxArrayLayers < m_config.imageLayers)
326 TCU_THROW(NotSupportedError, "Image type not supported");
329 const VkImageCreateInfo pCreateInfo =
331 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
338 m_config.imageLayers,
342 VK_SHARING_MODE_EXCLUSIVE,
345 VK_IMAGE_LAYOUT_UNDEFINED
348 return safeSharedPtr(new Unique<VkImage>(vk::createImage(m_vkd, m_device, &pCreateInfo)));
351 AllocationSp DepthStencilResolveTest::createImageMemory (VkImageSp image)
353 Allocator& allocator = m_context.getDefaultAllocator();
355 de::MovePtr<Allocation> allocation (allocator.allocate(getImageMemoryRequirements(m_vkd, m_device, **image), MemoryRequirement::Any));
356 VK_CHECK(m_vkd.bindImageMemory(m_device, **image, allocation->getMemory(), allocation->getOffset()));
357 return safeSharedPtr(allocation.release());
360 VkImageViewSp DepthStencilResolveTest::createImageView (VkImageSp image, deUint32 baseArrayLayer)
362 const VkImageSubresourceRange range =
371 const VkImageViewCreateInfo pCreateInfo =
373 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
377 (m_config.viewLayers > 1) ? VK_IMAGE_VIEW_TYPE_2D_ARRAY : VK_IMAGE_VIEW_TYPE_2D,
379 makeComponentMappingRGBA(),
382 return safeSharedPtr(new Unique<VkImageView>(vk::createImageView(m_vkd, m_device, &pCreateInfo)));
385 Move<VkRenderPass> DepthStencilResolveTest::createRenderPass (void)
387 // When the depth/stencil resolve attachment is unused, it needs to be cleared outside the render pass so it has the expected values.
388 if (m_config.unusedResolve)
390 const tcu::TextureFormat format (mapVkFormat(m_config.format));
391 const Unique<VkCommandBuffer> commandBuffer (allocateCommandBuffer(m_vkd, m_device, *m_commandPool, vk::VK_COMMAND_BUFFER_LEVEL_PRIMARY));
392 const vk::VkImageSubresourceRange imageRange =
394 ((tcu::hasDepthComponent(format.order) ? static_cast<vk::VkImageAspectFlags>(vk::VK_IMAGE_ASPECT_DEPTH_BIT) : 0u) |
395 (tcu::hasStencilComponent(format.order) ? static_cast<vk::VkImageAspectFlags>(vk::VK_IMAGE_ASPECT_STENCIL_BIT) : 0u)),
397 VK_REMAINING_MIP_LEVELS,
399 VK_REMAINING_ARRAY_LAYERS,
401 const vk::VkImageMemoryBarrier preBarrier =
403 vk::VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
406 // src and dst access masks.
408 vk::VK_ACCESS_TRANSFER_WRITE_BIT,
410 // old and new layouts.
411 vk::VK_IMAGE_LAYOUT_UNDEFINED,
412 vk::VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
414 VK_QUEUE_FAMILY_IGNORED,
415 VK_QUEUE_FAMILY_IGNORED,
417 **m_singlesampleImage,
420 const vk::VkImageMemoryBarrier postBarrier =
422 vk::VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
425 // src and dst access masks.
426 vk::VK_ACCESS_TRANSFER_WRITE_BIT,
429 // old and new layouts.
430 vk::VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
431 vk::VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
433 VK_QUEUE_FAMILY_IGNORED,
434 VK_QUEUE_FAMILY_IGNORED,
436 **m_singlesampleImage,
440 vk::beginCommandBuffer(m_vkd, commandBuffer.get());
441 m_vkd.cmdPipelineBarrier(commandBuffer.get(), vk::VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, vk::VK_PIPELINE_STAGE_TRANSFER_BIT, 0u, 0u, DE_NULL, 0u, DE_NULL, 1u, &preBarrier);
442 m_vkd.cmdClearDepthStencilImage(commandBuffer.get(), **m_singlesampleImage, vk::VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &m_config.clearValue, 1u, &imageRange);
443 m_vkd.cmdPipelineBarrier(commandBuffer.get(), vk::VK_PIPELINE_STAGE_TRANSFER_BIT, vk::VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0u, 0u, DE_NULL, 0u, DE_NULL, 1u, &postBarrier);
444 vk::endCommandBuffer(m_vkd, commandBuffer.get());
446 vk::submitCommandsAndWait(m_vkd, m_device, m_context.getUniversalQueue(), commandBuffer.get());
449 const VkSampleCountFlagBits samples(sampleCountBitFromSampleCount(m_config.sampleCount));
451 VkImageLayout layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
452 VkAttachmentReferenceStencilLayoutKHR stencilLayout =
454 VK_STRUCTURE_TYPE_ATTACHMENT_REFERENCE_STENCIL_LAYOUT_KHR,
456 VK_IMAGE_LAYOUT_UNDEFINED,
458 void * attachmentRefStencil = DE_NULL;
459 VkImageLayout finalLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
460 VkAttachmentDescriptionStencilLayoutKHR stencilFinalLayout =
462 VK_STRUCTURE_TYPE_ATTACHMENT_DESCRIPTION_STENCIL_LAYOUT_KHR,
464 VK_IMAGE_LAYOUT_UNDEFINED,
465 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
467 void * attachmentDescriptionStencil = DE_NULL;
469 if (m_config.separateDepthStencilLayouts)
471 if (m_config.verifyBuffer == VB_DEPTH)
473 layout = VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL_KHR;
474 stencilLayout.stencilLayout = VK_IMAGE_LAYOUT_GENERAL;
475 finalLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
476 stencilFinalLayout.stencilFinalLayout = VK_IMAGE_LAYOUT_STENCIL_READ_ONLY_OPTIMAL_KHR; // This aspect should be unused.
480 layout = VK_IMAGE_LAYOUT_GENERAL;
481 stencilLayout.stencilLayout = VK_IMAGE_LAYOUT_STENCIL_ATTACHMENT_OPTIMAL_KHR;
482 finalLayout = VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_OPTIMAL_KHR; // This aspect should be unused.
483 stencilFinalLayout.stencilFinalLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
485 attachmentRefStencil = &stencilLayout;
486 attachmentDescriptionStencil = &stencilFinalLayout;
489 const AttachmentDescription2 multisampleAttachment // VkAttachmentDescription2
491 // VkStructureType sType;
492 attachmentDescriptionStencil, // const void* pNext;
493 0u, // VkAttachmentDescriptionFlags flags;
494 m_config.format, // VkFormat format;
495 samples, // VkSampleCountFlagBits samples;
496 VK_ATTACHMENT_LOAD_OP_CLEAR, // VkAttachmentLoadOp loadOp;
497 VK_ATTACHMENT_STORE_OP_DONT_CARE, // VkAttachmentStoreOp storeOp;
498 VK_ATTACHMENT_LOAD_OP_CLEAR, // VkAttachmentLoadOp stencilLoadOp;
499 VK_ATTACHMENT_STORE_OP_DONT_CARE, // VkAttachmentStoreOp stencilStoreOp;
500 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout;
501 finalLayout // VkImageLayout finalLayout;
503 const AttachmentReference2 multisampleAttachmentRef // VkAttachmentReference2
505 // VkStructureType sType;
506 attachmentRefStencil, // const void* pNext;
507 0u, // deUint32 attachment;
508 layout, // VkImageLayout layout;
509 0u // VkImageAspectFlags aspectMask;
512 const vk::VkImageLayout singleSampleInitialLayout = (m_config.unusedResolve ? VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL : VK_IMAGE_LAYOUT_UNDEFINED);
514 const AttachmentDescription2 singlesampleAttachment // VkAttachmentDescription2
516 // VkStructureType sType;
517 attachmentDescriptionStencil, // const void* pNext;
518 0u, // VkAttachmentDescriptionFlags flags;
519 m_config.format, // VkFormat format;
520 VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits samples;
521 VK_ATTACHMENT_LOAD_OP_CLEAR, // VkAttachmentLoadOp loadOp;
522 VK_ATTACHMENT_STORE_OP_STORE, // VkAttachmentStoreOp storeOp;
523 VK_ATTACHMENT_LOAD_OP_CLEAR, // VkAttachmentLoadOp stencilLoadOp;
524 VK_ATTACHMENT_STORE_OP_STORE, // VkAttachmentStoreOp stencilStoreOp;
525 singleSampleInitialLayout, // VkImageLayout initialLayout;
526 finalLayout // VkImageLayout finalLayout;
528 AttachmentReference2 singlesampleAttachmentRef // VkAttachmentReference2
530 // VkStructureType sType;
531 DE_NULL, // const void* pNext;
532 (m_config.unusedResolve ? VK_ATTACHMENT_UNUSED : 1u), // deUint32 attachment;
533 layout, // VkImageLayout layout;
534 0u // VkImageAspectFlags aspectMask;
537 std::vector<AttachmentDescription2> attachments;
538 attachments.push_back(multisampleAttachment);
539 attachments.push_back(singlesampleAttachment);
541 VkSubpassDescriptionDepthStencilResolve dsResolveDescription =
543 VK_STRUCTURE_TYPE_SUBPASS_DESCRIPTION_DEPTH_STENCIL_RESOLVE,
544 DE_NULL, // const void* pNext;
545 m_config.depthResolveMode, // VkResolveModeFlagBits depthResolveMode;
546 m_config.stencilResolveMode, // VkResolveModeFlagBits stencilResolveMode;
547 &singlesampleAttachmentRef // VkAttachmentReference2 pDepthStencilResolveAttachment;
550 const SubpassDescription2 subpass // VkSubpassDescription2
552 // VkStructureType sType;
553 &dsResolveDescription, // const void* pNext;
554 (VkSubpassDescriptionFlags)0, // VkSubpassDescriptionFlags flags;
555 VK_PIPELINE_BIND_POINT_GRAPHICS, // VkPipelineBindPoint pipelineBindPoint;
556 0u, // deUint32 viewMask;
557 0u, // deUint32 inputAttachmentCount;
558 DE_NULL, // const VkAttachmentReference2* pInputAttachments;
559 0u, // deUint32 colorAttachmentCount;
560 DE_NULL, // const VkAttachmentReference2* pColorAttachments;
561 DE_NULL, // const VkAttachmentReference2* pResolveAttachments;
562 &multisampleAttachmentRef, // const VkAttachmentReference2* pDepthStencilAttachment;
563 0u, // deUint32 preserveAttachmentCount;
564 DE_NULL // const deUint32* pPreserveAttachments;
567 const RenderPassCreateInfo2 renderPassCreator // VkRenderPassCreateInfo2
569 // VkStructureType sType;
570 DE_NULL, // const void* pNext;
571 (VkRenderPassCreateFlags)0u, // VkRenderPassCreateFlags flags;
572 (deUint32)attachments.size(), // deUint32 attachmentCount;
573 &attachments[0], // const VkAttachmentDescription2* pAttachments;
574 1u, // deUint32 subpassCount;
575 &subpass, // const VkSubpassDescription2* pSubpasses;
576 0u, // deUint32 dependencyCount;
577 DE_NULL, // const VkSubpassDependency2* pDependencies;
578 0u, // deUint32 correlatedViewMaskCount;
579 DE_NULL // const deUint32* pCorrelatedViewMasks;
582 return renderPassCreator.createRenderPass(m_vkd, m_device);
585 Move<VkFramebuffer> DepthStencilResolveTest::createFramebuffer (VkRenderPass renderPass, VkImageViewSp multisampleImageView, VkImageViewSp singlesampleImageView)
587 std::vector<VkImageView> attachments;
588 attachments.push_back(**multisampleImageView);
589 attachments.push_back(**singlesampleImageView);
591 const VkFramebufferCreateInfo createInfo =
593 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,
598 (deUint32)attachments.size(),
606 return vk::createFramebuffer(m_vkd, m_device, &createInfo);
609 Move<VkPipelineLayout> DepthStencilResolveTest::createRenderPipelineLayout (void)
611 VkPushConstantRange pushConstant =
613 VK_SHADER_STAGE_FRAGMENT_BIT,
618 deUint32 pushConstantRangeCount = 0u;
619 VkPushConstantRange* pPushConstantRanges = DE_NULL;
620 if (m_config.verifyBuffer == VB_STENCIL)
622 pushConstantRangeCount = 1u;
623 pPushConstantRanges = &pushConstant;
626 const VkPipelineLayoutCreateInfo createInfo =
628 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
630 (vk::VkPipelineLayoutCreateFlags)0,
635 pushConstantRangeCount,
639 return vk::createPipelineLayout(m_vkd, m_device, &createInfo);
642 Move<VkPipeline> DepthStencilResolveTest::createRenderPipeline (VkRenderPass renderPass, VkPipelineLayout renderPipelineLayout)
644 const bool testingStencil = (m_config.verifyBuffer == VB_STENCIL);
645 const vk::BinaryCollection& binaryCollection = m_context.getBinaryCollection();
647 const Unique<VkShaderModule> vertexShaderModule (createShaderModule(m_vkd, m_device, binaryCollection.get("quad-vert"), 0u));
648 const Unique<VkShaderModule> fragmentShaderModule (createShaderModule(m_vkd, m_device, binaryCollection.get("quad-frag"), 0u));
649 const Move<VkShaderModule> geometryShaderModule (m_config.imageLayers == 1 ? Move<VkShaderModule>() : createShaderModule(m_vkd, m_device, binaryCollection.get("quad-geom"), 0u));
651 const VkPipelineVertexInputStateCreateInfo vertexInputState =
653 VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
655 (VkPipelineVertexInputStateCreateFlags)0u,
663 const tcu::UVec2 view (m_config.width, m_config.height);
664 const std::vector<VkViewport> viewports (1, makeViewport(view));
665 const std::vector<VkRect2D> scissors (1, m_config.renderArea);
667 const VkPipelineMultisampleStateCreateInfo multisampleState =
669 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,
671 (VkPipelineMultisampleStateCreateFlags)0u,
673 sampleCountBitFromSampleCount(m_config.sampleCount),
680 const VkPipelineDepthStencilStateCreateInfo depthStencilState =
682 VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO,
684 (VkPipelineDepthStencilStateCreateFlags)0u,
686 VK_TRUE, // depthTestEnable
688 VK_COMPARE_OP_ALWAYS,
690 testingStencil, // stencilTestEnable
692 VK_STENCIL_OP_REPLACE, // failOp
693 VK_STENCIL_OP_REPLACE, // passOp
694 VK_STENCIL_OP_REPLACE, // depthFailOp
695 VK_COMPARE_OP_ALWAYS, // compareOp
696 0xFFu, // compareMask
701 VK_STENCIL_OP_REPLACE,
702 VK_STENCIL_OP_REPLACE,
703 VK_STENCIL_OP_REPLACE,
704 VK_COMPARE_OP_ALWAYS,
713 std::vector<VkDynamicState> dynamicState;
714 dynamicState.push_back(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
715 const VkPipelineDynamicStateCreateInfo dynamicStateCreateInfo =
717 VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO, // VkStructureType sType;
718 DE_NULL, // const void* pNext;
719 (VkPipelineDynamicStateCreateFlags)0u, // VkPipelineDynamicStateCreateFlags flags;
720 static_cast<deUint32>(dynamicState.size()), // deUint32 dynamicStateCount;
721 &dynamicState[0] // const VkDynamicState* pDynamicStates;
724 return makeGraphicsPipeline(m_vkd, // const DeviceInterface& vk
725 m_device, // const VkDevice device
726 renderPipelineLayout, // const VkPipelineLayout pipelineLayout
727 *vertexShaderModule, // const VkShaderModule vertexShaderModule
728 DE_NULL, // const VkShaderModule tessellationControlShaderModule
729 DE_NULL, // const VkShaderModule tessellationEvalShaderModule
730 m_config.imageLayers == 1 ? DE_NULL : *geometryShaderModule, // const VkShaderModule geometryShaderModule
731 *fragmentShaderModule, // const VkShaderModule fragmentShaderModule
732 renderPass, // const VkRenderPass renderPass
733 viewports, // const std::vector<VkViewport>& viewports
734 scissors, // const std::vector<VkRect2D>& scissors
735 VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, // const VkPrimitiveTopology topology
736 0u, // const deUint32 subpass
737 0u, // const deUint32 patchControlPoints
738 &vertexInputState, // const VkPipelineVertexInputStateCreateInfo* vertexInputStateCreateInfo
739 DE_NULL, // const VkPipelineRasterizationStateCreateInfo* rasterizationStateCreateInfo
740 &multisampleState, // const VkPipelineMultisampleStateCreateInfo* multisampleStateCreateInfo
741 &depthStencilState, // const VkPipelineDepthStencilStateCreateInfo* depthStencilStateCreateInfo
742 DE_NULL, // const VkPipelineColorBlendStateCreateInfo* colorBlendStateCreateInfo
743 testingStencil ? &dynamicStateCreateInfo : DE_NULL); // const VkPipelineDynamicStateCreateInfo* dynamicStateCreateInfo
746 AllocationSp DepthStencilResolveTest::createBufferMemory (void)
748 Allocator& allocator = m_context.getDefaultAllocator();
749 de::MovePtr<Allocation> allocation(allocator.allocate(getBufferMemoryRequirements(m_vkd, m_device, **m_buffer), MemoryRequirement::HostVisible));
750 VK_CHECK(m_vkd.bindBufferMemory(m_device, **m_buffer, allocation->getMemory(), allocation->getOffset()));
751 return safeSharedPtr(allocation.release());
754 VkBufferSp DepthStencilResolveTest::createBuffer (void)
756 const VkBufferUsageFlags bufferUsage (VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT);
757 const tcu::TextureFormat textureFormat (mapVkFormat(m_config.format));
758 const VkDeviceSize pixelSize (textureFormat.getPixelSize());
759 const VkBufferCreateInfo createInfo =
761 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
765 m_config.width * m_config.height * m_config.imageLayers * pixelSize,
768 VK_SHARING_MODE_EXCLUSIVE,
772 return safeSharedPtr(new Unique<VkBuffer>(vk::createBuffer(m_vkd, m_device, &createInfo)));
775 void DepthStencilResolveTest::submit (void)
777 const DeviceInterface& vkd (m_context.getDeviceInterface());
778 const VkDevice device (m_context.getDevice());
779 const Unique<VkCommandBuffer> commandBuffer (allocateCommandBuffer(vkd, device, *m_commandPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY));
780 const RenderpassSubpass2::SubpassBeginInfo subpassBeginInfo (DE_NULL, VK_SUBPASS_CONTENTS_INLINE);
781 const RenderpassSubpass2::SubpassEndInfo subpassEndInfo (DE_NULL);
783 beginCommandBuffer(vkd, *commandBuffer);
786 VkClearValue clearValues[2];
787 clearValues[0].depthStencil = m_config.clearValue;
788 clearValues[1].depthStencil = m_config.clearValue;
790 const VkRenderPassBeginInfo beginInfo =
792 VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
800 { m_config.width, m_config.height }
806 RenderpassSubpass2::cmdBeginRenderPass(vkd, *commandBuffer, &beginInfo, &subpassBeginInfo);
810 bool testingDepth = (m_config.verifyBuffer == VB_DEPTH);
813 vkd.cmdBindPipeline(*commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *m_renderPipeline);
814 vkd.cmdDraw(*commandBuffer, 6u, 1u, 0u, 0u);
818 // For stencil we can set reference value for just one sample at a time
819 // so we need to do as many passes as there are samples, first half
820 // of samples is initialized with 1 and second half with 255
821 const deUint32 halfOfSamples = m_config.sampleCount >> 1;
822 for (deUint32 renderPass = 0 ; renderPass < m_config.sampleCount ; renderPass++)
824 deUint32 stencilReference = 1 + 254 * (renderPass >= halfOfSamples);
825 vkd.cmdBindPipeline(*commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *m_renderPipeline);
826 vkd.cmdPushConstants(*commandBuffer, *m_renderPipelineLayout, VK_SHADER_STAGE_FRAGMENT_BIT, 0u, sizeof(renderPass), &renderPass);
827 vkd.cmdSetStencilReference(*commandBuffer, VK_STENCIL_FRONT_AND_BACK, stencilReference);
828 vkd.cmdDraw(*commandBuffer, 6u, 1u, 0u, 0u);
832 RenderpassSubpass2::cmdEndRenderPass(vkd, *commandBuffer, &subpassEndInfo);
834 // Memory barriers between rendering and copying
836 const VkImageMemoryBarrier barrier =
838 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
841 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
842 VK_ACCESS_TRANSFER_READ_BIT,
844 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
845 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
847 VK_QUEUE_FAMILY_IGNORED,
848 VK_QUEUE_FAMILY_IGNORED,
850 **m_singlesampleImage,
852 (m_config.separateDepthStencilLayouts) ? VkImageAspectFlags(testingDepth ? VK_IMAGE_ASPECT_DEPTH_BIT : VK_IMAGE_ASPECT_STENCIL_BIT) : m_config.aspectFlag,
860 vkd.cmdPipelineBarrier(*commandBuffer, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0u, 0u, DE_NULL, 0u, DE_NULL, 1u, &barrier);
863 // Copy image memory to buffers
864 const VkBufferImageCopy region =
870 VkImageAspectFlags(testingDepth ? VK_IMAGE_ASPECT_DEPTH_BIT : VK_IMAGE_ASPECT_STENCIL_BIT),
876 { m_config.width, m_config.height, 1u }
879 vkd.cmdCopyImageToBuffer(*commandBuffer, **m_singlesampleImage, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, **m_buffer, 1u, ®ion);
881 // Memory barriers between copies and host access
883 const VkBufferMemoryBarrier barrier =
885 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
888 VK_ACCESS_TRANSFER_WRITE_BIT,
889 VK_ACCESS_HOST_READ_BIT,
891 VK_QUEUE_FAMILY_IGNORED,
892 VK_QUEUE_FAMILY_IGNORED,
899 vkd.cmdPipelineBarrier(*commandBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0u, 0u, DE_NULL, 1u, &barrier, 0u, DE_NULL);
902 endCommandBuffer(vkd, *commandBuffer);
904 submitCommandsAndWait(vkd, device, m_context.getUniversalQueue(), *commandBuffer);
907 bool DepthStencilResolveTest::verifyDepth (void)
909 // Invalidate allocation before attempting to read buffer memory.
910 invalidateAlloc(m_context.getDeviceInterface(), m_context.getDevice(), *m_bufferMemory);
912 deUint32 layerSize = m_config.width * m_config.height;
913 deUint32 valuesCount = layerSize * m_config.viewLayers;
914 deUint8* pixelPtr = static_cast<deUint8*>(m_bufferMemory->getHostPtr());
916 const DeviceInterface& vkd (m_context.getDeviceInterface());
917 invalidateMappedMemoryRange(vkd, m_context.getDevice(), m_bufferMemory->getMemory(), m_bufferMemory->getOffset(), VK_WHOLE_SIZE);
919 float expectedValue = m_config.depthExpectedValue;
920 if (m_config.depthResolveMode == VK_RESOLVE_MODE_NONE || m_config.unusedResolve)
921 expectedValue = m_config.clearValue.depth;
923 // depth data in buffer is tightly packed, ConstPixelBufferAccess
924 // coludn't be used for depth value extraction as it cant interpret
925 // formats containing just depth component
927 typedef float (*DepthComponentGetterFn)(deUint8*);
928 VkFormat format = m_config.format;
929 DepthComponentGetterFn getDepthComponent = &get16bitDepthComponent;
930 deUint32 pixelStep = 2;
931 float epsilon = 0.002f;
933 if ((format == VK_FORMAT_X8_D24_UNORM_PACK32) ||
934 (format == VK_FORMAT_D24_UNORM_S8_UINT))
936 getDepthComponent = &get24bitDepthComponent;
939 else if ((format == VK_FORMAT_D32_SFLOAT) ||
940 (format == VK_FORMAT_D32_SFLOAT_S8_UINT))
942 getDepthComponent = &get32bitDepthComponent;
946 for (deUint32 valueIndex = 0; valueIndex < valuesCount; valueIndex++)
948 float depth = (*getDepthComponent)(pixelPtr);
949 pixelPtr += pixelStep;
951 // check if pixel data is outside of render area
952 deInt32 layerIndex = valueIndex / layerSize;
953 deInt32 inLayerIndex = valueIndex % layerSize;
954 deInt32 x = inLayerIndex % m_config.width;
955 deInt32 y = (inLayerIndex - x) / m_config.width;
956 deInt32 x1 = m_config.renderArea.offset.x;
957 deInt32 y1 = m_config.renderArea.offset.y;
958 deInt32 x2 = x1 + m_config.renderArea.extent.width;
959 deInt32 y2 = y1 + m_config.renderArea.extent.height;
960 if ((x < x1) || (x >= x2) || (y < y1) || (y >= y2))
962 // verify that outside of render area there are clear values
963 float error = deFloatAbs(depth - m_config.clearValue.depth);
966 m_context.getTestContext().getLog()
967 << TestLog::Message << "(" << x << ", " << y
968 << ", layer: " << layerIndex << ") is outside of render area but depth value is: "
969 << depth << " (expected " << m_config.clearValue.depth << ")" << TestLog::EndMessage;
973 // value is correct, go to next one
977 float error = deFloatAbs(depth - expectedValue);
980 m_context.getTestContext().getLog() << TestLog::Message
981 << "At (" << x << ", " << y << ", layer: " << layerIndex
982 << ") depth value is: " << depth << " expected: "
983 << expectedValue << TestLog::EndMessage;
987 m_context.getTestContext().getLog() << TestLog::Message
988 << "Depth value is " << expectedValue
989 << TestLog::EndMessage;
994 bool DepthStencilResolveTest::verifyStencil (void)
996 // Invalidate allocation before attempting to read buffer memory.
997 invalidateAlloc(m_context.getDeviceInterface(), m_context.getDevice(), *m_bufferMemory);
999 deUint32 layerSize = m_config.width * m_config.height;
1000 deUint32 valuesCount = layerSize * m_config.viewLayers;
1001 deUint8* pixelPtr = static_cast<deUint8*>(m_bufferMemory->getHostPtr());
1003 const DeviceInterface& vkd (m_context.getDeviceInterface());
1004 invalidateMappedMemoryRange(vkd, m_context.getDevice(), m_bufferMemory->getMemory(), m_bufferMemory->getOffset(), VK_WHOLE_SIZE);
1006 // when stencil is tested we are discarding invocations and
1007 // because of that depth and stencil need to be tested separately
1009 deUint8 expectedValue = m_config.stencilExpectedValue;
1010 if (m_config.stencilResolveMode == VK_RESOLVE_MODE_NONE || m_config.unusedResolve)
1011 expectedValue = static_cast<deUint8>(m_config.clearValue.stencil);
1013 for (deUint32 valueIndex = 0; valueIndex < valuesCount; valueIndex++)
1015 deUint8 stencil = *pixelPtr++;
1016 deInt32 layerIndex = valueIndex / layerSize;
1017 deInt32 inLayerIndex = valueIndex % layerSize;
1018 deInt32 x = inLayerIndex % m_config.width;
1019 deInt32 y = (inLayerIndex - x) / m_config.width;
1020 deInt32 x1 = m_config.renderArea.offset.x;
1021 deInt32 y1 = m_config.renderArea.offset.y;
1022 deInt32 x2 = x1 + m_config.renderArea.extent.width;
1023 deInt32 y2 = y1 + m_config.renderArea.extent.height;
1024 if ((x < x1) || (x >= x2) || (y < y1) || (y >= y2))
1026 if (stencil != m_config.clearValue.stencil)
1028 m_context.getTestContext().getLog()
1029 << TestLog::Message << "(" << x << ", " << y << ", layer: " << layerIndex
1030 << ") is outside of render area but stencil value is: "
1031 << stencil << " (expected " << m_config.clearValue.stencil << ")" << TestLog::EndMessage;
1035 // value is correct, go to next one
1039 if (stencil != expectedValue)
1041 m_context.getTestContext().getLog() << TestLog::Message
1042 << "At (" << x << ", " << y << ", layer: " << layerIndex
1043 << ") stencil value is: " << static_cast<deUint32>(stencil)
1044 << " expected: " << static_cast<deUint32>(expectedValue)
1045 << TestLog::EndMessage;
1049 m_context.getTestContext().getLog() << TestLog::Message
1050 << "Stencil value is "
1051 << static_cast<deUint32>(expectedValue)
1052 << TestLog::EndMessage;
1057 tcu::TestStatus DepthStencilResolveTest::iterate (void)
1061 bool result = false;
1062 if (m_config.verifyBuffer == VB_DEPTH)
1063 result = verifyDepth();
1065 result = verifyStencil();
1068 return tcu::TestStatus::pass("Pass");
1069 return tcu::TestStatus::fail("Fail");
1074 void init (vk::SourceCollections& dst, TestConfig config) const
1076 // geometry shader is only needed in multi-layer framebuffer resolve tests
1077 if (config.imageLayers > 1)
1079 const deUint32 layerCount = 3;
1081 std::ostringstream src;
1082 src << "#version 450\n"
1085 << "layout(triangles) in;\n"
1086 << "layout(triangle_strip, max_vertices = " << 3 * 2 * layerCount << ") out;\n"
1088 << "in gl_PerVertex {\n"
1089 << " vec4 gl_Position;\n"
1092 << "out gl_PerVertex {\n"
1093 << " vec4 gl_Position;\n"
1096 << "void main (void) {\n"
1097 << " for (int layerNdx = 0; layerNdx < " << layerCount << "; ++layerNdx) {\n"
1098 << " for(int vertexNdx = 0; vertexNdx < gl_in.length(); vertexNdx++) {\n"
1099 << " gl_Position = gl_in[vertexNdx].gl_Position;\n"
1100 << " gl_Layer = layerNdx;\n"
1101 << " EmitVertex();\n"
1103 << " EndPrimitive();\n"
1107 dst.glslSources.add("quad-geom") << glu::GeometrySource(src.str());
1110 dst.glslSources.add("quad-vert") << glu::VertexSource(
1112 "out gl_PerVertex {\n"
1113 "\tvec4 gl_Position;\n"
1116 "void main (void) {\n"
1117 "\tgl_Position = vec4(((gl_VertexIndex + 2) / 3) % 2 == 0 ? -1.0 : 1.0,\n"
1118 "\t ((gl_VertexIndex + 1) / 3) % 2 == 0 ? -1.0 : 1.0, 0.0, 1.0);\n"
1121 if (config.verifyBuffer == VB_DEPTH)
1123 dst.glslSources.add("quad-frag") << glu::FragmentSource(
1125 "precision highp float;\n"
1126 "precision highp int;\n"
1127 "void main (void)\n"
1129 " float sampleIndex = float(gl_SampleID);\n" // sampleIndex is integer in range <0, 63>
1130 " float valueIndex = round(mod(sampleIndex, 4.0));\n" // limit possible depth values - count to 4
1131 " float value = valueIndex + 2.0;\n" // value is one of [2, 3, 4, 5]
1132 " value = round(exp2(value));\n" // value is one of [4, 8, 16, 32]
1133 " bool condition = (int(value) == 8);\n" // select second sample value (to make it smallest)
1134 " value = round(value - float(condition) * 6.0);\n" // value is one of [4, 2, 16, 32]
1135 " gl_FragDepth = value / 100.0;\n" // sample depth is one of [0.04, 0.02, 0.16, 0.32]
1140 dst.glslSources.add("quad-frag") << glu::FragmentSource(
1142 "precision highp float;\n"
1143 "precision highp int;\n"
1144 "layout(push_constant) uniform PushConstant {\n"
1145 " highp int sampleID;\n"
1146 "} pushConstants;\n"
1147 "void main (void)\n"
1149 " if(gl_SampleID != pushConstants.sampleID)\n"
1151 " gl_FragDepth = 0.5;\n"
1157 class PropertiesTestCase : public vkt::TestCase
1160 PropertiesTestCase (tcu::TestContext& testCtx, const std::string& name, const std::string& description)
1161 : vkt::TestCase(testCtx, name, description)
1163 virtual ~PropertiesTestCase (void) {}
1165 virtual TestInstance* createInstance (Context& context) const;
1166 virtual void checkSupport (Context& context) const;
1169 class PropertiesTestInstance : public vkt::TestInstance
1172 PropertiesTestInstance (Context& context)
1173 : vkt::TestInstance(context)
1175 virtual ~PropertiesTestInstance (void) {}
1177 virtual tcu::TestStatus iterate (void);
1181 TestInstance* PropertiesTestCase::createInstance (Context& context) const
1183 return new PropertiesTestInstance(context);
1186 void PropertiesTestCase::checkSupport (Context& context) const
1188 context.requireDeviceFunctionality("VK_KHR_depth_stencil_resolve");
1191 tcu::TestStatus PropertiesTestInstance::iterate (void)
1193 vk::VkPhysicalDeviceDepthStencilResolvePropertiesKHR dsrProperties;
1194 dsrProperties.sType = vk::VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_STENCIL_RESOLVE_PROPERTIES_KHR;
1195 dsrProperties.pNext = nullptr;
1197 vk::VkPhysicalDeviceProperties2 properties2;
1198 properties2.sType = vk::VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;
1199 properties2.pNext = &dsrProperties;
1201 m_context.getInstanceInterface().getPhysicalDeviceProperties2(m_context.getPhysicalDevice(), &properties2);
1203 if ((dsrProperties.supportedDepthResolveModes & vk::VK_RESOLVE_MODE_SAMPLE_ZERO_BIT_KHR) == 0)
1204 TCU_FAIL("supportedDepthResolveModes does not include VK_RESOLVE_MODE_SAMPLE_ZERO_BIT_KHR");
1206 if ((dsrProperties.supportedStencilResolveModes & vk::VK_RESOLVE_MODE_SAMPLE_ZERO_BIT_KHR) == 0)
1207 TCU_FAIL("supportedStencilResolveModes does not include VK_RESOLVE_MODE_SAMPLE_ZERO_BIT_KHR");
1209 if ((dsrProperties.supportedStencilResolveModes & vk::VK_RESOLVE_MODE_AVERAGE_BIT_KHR) != 0)
1210 TCU_FAIL("supportedStencilResolveModes includes forbidden VK_RESOLVE_MODE_AVERAGE_BIT_KHR");
1212 if (dsrProperties.independentResolve == VK_TRUE && dsrProperties.independentResolveNone != VK_TRUE)
1213 TCU_FAIL("independentResolve supported but independentResolveNone not supported");
1215 return tcu::TestStatus::pass("Pass");
1219 void initTests (tcu::TestCaseGroup* group)
1221 typedef InstanceFactory1<DepthStencilResolveTest, TestConfig, Programs> DSResolveTestInstance;
1230 FormatData formats[] =
1232 { VK_FORMAT_D16_UNORM, "d16_unorm", true, false },
1233 { VK_FORMAT_X8_D24_UNORM_PACK32, "x8_d24_unorm_pack32", true, false },
1234 { VK_FORMAT_D32_SFLOAT, "d32_sfloat", true, false },
1235 { VK_FORMAT_S8_UINT, "s8_uint", false, true },
1236 { VK_FORMAT_D16_UNORM_S8_UINT, "d16_unorm_s8_uint", true, true },
1237 { VK_FORMAT_D24_UNORM_S8_UINT, "d24_unorm_s8_uint", true, true },
1238 { VK_FORMAT_D32_SFLOAT_S8_UINT, "d32_sfloat_s8_uint", true, true },
1241 struct ResolveModeData
1243 VkResolveModeFlagBits flag;
1246 ResolveModeData resolveModes[] =
1248 { VK_RESOLVE_MODE_NONE, "none" },
1249 { VK_RESOLVE_MODE_SAMPLE_ZERO_BIT, "zero" },
1250 { VK_RESOLVE_MODE_AVERAGE_BIT, "average" },
1251 { VK_RESOLVE_MODE_MIN_BIT, "min" },
1252 { VK_RESOLVE_MODE_MAX_BIT, "max" },
1255 struct ImageTestData
1257 const char* groupName;
1260 deUint32 imageLayers;
1261 VkRect2D renderArea;
1262 VkClearDepthStencilValue clearValue;
1265 // NOTE: tests cant be executed for 1D and 3D images:
1266 // 1D images are not tested because acording to specyfication sampleCounts
1267 // will be set to VK_SAMPLE_COUNT_1_BIT when type is not VK_IMAGE_TYPE_2D
1268 // 3D images are not tested because VkFramebufferCreateInfo specification
1269 // states that: each element of pAttachments that is a 2D or 2D array image
1270 // view taken from a 3D image must not be a depth/stencil format
1271 ImageTestData imagesTestData[] =
1273 { "image_2d_32_32", 32, 32, 1, {{ 0, 0}, {32, 32}}, {0.000f, 0x00} },
1274 { "image_2d_8_32", 8, 32, 1, {{ 1, 1}, { 6, 30}}, {0.123f, 0x01} },
1275 { "image_2d_49_13", 49, 13, 1, {{10, 5}, {20, 8}}, {1.000f, 0x05} },
1276 { "image_2d_5_1", 5, 1, 1, {{ 0, 0}, { 5, 1}}, {0.500f, 0x00} },
1277 { "image_2d_17_1", 17, 1, 1, {{ 1, 0}, {15, 1}}, {0.789f, 0xfa} },
1279 const deUint32 sampleCounts[] =
1281 2u, 4u, 8u, 16u, 32u, 64u
1283 const float depthExpectedValue[][6] =
1285 // 2 samples 4 8 16 32 64
1286 { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }, // RESOLVE_MODE_NONE - expect clear value
1287 { 0.04f, 0.04f, 0.04f, 0.04f, 0.04f, 0.04f }, // RESOLVE_MODE_SAMPLE_ZERO_BIT
1288 { 0.03f, 0.135f, 0.135f, 0.135f, 0.135f, 0.135f }, // RESOLVE_MODE_AVERAGE_BIT
1289 { 0.02f, 0.02f, 0.02f, 0.02f, 0.02f, 0.02f }, // RESOLVE_MODE_MIN_BIT
1290 { 0.04f, 0.32f, 0.32f, 0.32f, 0.32f, 0.32f }, // RESOLVE_MODE_MAX_BIT
1292 const deUint8 stencilExpectedValue[][6] =
1294 // 2 samples 4 8 16 32 64
1295 { 0u, 0u, 0u, 0u, 0u, 0u }, // RESOLVE_MODE_NONE - expect clear value
1296 { 1u, 1u, 1u, 1u, 1u, 1u }, // RESOLVE_MODE_SAMPLE_ZERO_BIT
1297 { 0u, 0u, 0u, 0u, 0u, 0u }, // RESOLVE_MODE_AVERAGE_BIT - not supported
1298 { 1u, 1u, 1u, 1u, 1u, 1u }, // RESOLVE_MODE_MIN_BIT
1299 { 255u, 255u, 255u, 255u, 255u, 255u }, // RESOLVE_MODE_MAX_BIT
1302 tcu::TestContext& testCtx(group->getTestContext());
1306 de::MovePtr<tcu::TestCaseGroup> miscGroup(new tcu::TestCaseGroup(testCtx, "misc", "Miscellaneous depth/stencil resolve tests"));
1307 miscGroup->addChild(new PropertiesTestCase(testCtx, "properties", "Check reported depth/stencil resolve properties"));
1308 group->addChild(miscGroup.release());
1311 // iterate over image data
1312 for (deUint32 imageDataNdx = 0; imageDataNdx < DE_LENGTH_OF_ARRAY(imagesTestData); imageDataNdx++)
1314 ImageTestData imageData = imagesTestData[imageDataNdx];
1316 // create test group for image data
1317 de::MovePtr<tcu::TestCaseGroup> imageGroup(new tcu::TestCaseGroup(testCtx, imageData.groupName, imageData.groupName));
1319 // iterate over sampleCounts
1320 for (size_t sampleCountNdx = 0; sampleCountNdx < DE_LENGTH_OF_ARRAY(sampleCounts); sampleCountNdx++)
1322 const deUint32 sampleCount (sampleCounts[sampleCountNdx]);
1323 const std::string sampleName ("samples_" + de::toString(sampleCount));
1325 // create test group for sample count
1326 de::MovePtr<tcu::TestCaseGroup> sampleGroup(new tcu::TestCaseGroup(testCtx, sampleName.c_str(), sampleName.c_str()));
1328 // iterate over depth/stencil formats
1329 for (size_t formatNdx = 0; formatNdx < DE_LENGTH_OF_ARRAY(formats); formatNdx++)
1331 const FormatData& formatData = formats[formatNdx];
1332 VkFormat format = formatData.format;
1333 const char* formatName = formatData.name;
1334 const bool hasDepth = formatData.hasDepth;
1335 const bool hasStencil = formatData.hasStencil;
1336 VkImageAspectFlags aspectFlags = (hasDepth * VK_IMAGE_ASPECT_DEPTH_BIT) |
1337 (hasStencil * VK_IMAGE_ASPECT_STENCIL_BIT);
1338 const int separateLayoutsLoopCount = (hasDepth && hasStencil) ? 2 : 1;
1340 for (int separateDepthStencilLayouts = 0; separateDepthStencilLayouts < separateLayoutsLoopCount; ++separateDepthStencilLayouts)
1342 const bool useSeparateDepthStencilLayouts = bool(separateDepthStencilLayouts);
1343 const std::string groupName = std::string(formatName) + ((useSeparateDepthStencilLayouts) ? "_separate_layouts" : "");
1345 // create test group for format
1346 de::MovePtr<tcu::TestCaseGroup> formatGroup(new tcu::TestCaseGroup(testCtx, groupName.c_str(), groupName.c_str()));
1348 // iterate over depth resolve modes
1349 for (size_t depthResolveModeNdx = 0; depthResolveModeNdx < DE_LENGTH_OF_ARRAY(resolveModes); depthResolveModeNdx++)
1351 // iterate over stencil resolve modes
1352 for (size_t stencilResolveModeNdx = 0; stencilResolveModeNdx < DE_LENGTH_OF_ARRAY(resolveModes); stencilResolveModeNdx++)
1354 for (int unusedIdx = 0; unusedIdx < 2; ++unusedIdx)
1356 // there is no average resolve mode for stencil - go to next iteration
1357 ResolveModeData& sResolve = resolveModes[stencilResolveModeNdx];
1358 if (sResolve.flag == VK_RESOLVE_MODE_AVERAGE_BIT)
1361 // if pDepthStencilResolveAttachment is not NULL and does not have the value VK_ATTACHMENT_UNUSED,
1362 // depthResolveMode and stencilResolveMode must not both be VK_RESOLVE_MODE_NONE_KHR
1363 ResolveModeData& dResolve = resolveModes[depthResolveModeNdx];
1364 if ((dResolve.flag == VK_RESOLVE_MODE_NONE) && (sResolve.flag == VK_RESOLVE_MODE_NONE))
1367 // If there is no depth, the depth resolve mode should be NONE, or
1368 // match the stencil resolve mode.
1369 if (!hasDepth && (dResolve.flag != VK_RESOLVE_MODE_NONE) &&
1370 (dResolve.flag != sResolve.flag))
1373 // If there is no stencil, the stencil resolve mode should be NONE, or
1374 // match the depth resolve mode.
1375 if (!hasStencil && (sResolve.flag != VK_RESOLVE_MODE_NONE) &&
1376 (dResolve.flag != sResolve.flag))
1379 const bool unusedResolve = (unusedIdx > 0);
1381 std::string baseName = "depth_" + dResolve.name + "_stencil_" + sResolve.name;
1383 baseName += "_unused_resolve";
1387 std::string name = baseName + "_testing_depth";
1388 const char* testName = name.c_str();
1389 float expectedValue = depthExpectedValue[depthResolveModeNdx][sampleCountNdx];
1391 const TestConfig testConfig =
1399 imageData.renderArea,
1405 imageData.clearValue,
1408 useSeparateDepthStencilLayouts,
1411 formatGroup->addChild(new DSResolveTestInstance(testCtx, tcu::NODETYPE_SELF_VALIDATE, testName, testName, testConfig));
1415 std::string name = baseName + "_testing_stencil";
1416 const char* testName = name.c_str();
1417 deUint8 expectedValue = stencilExpectedValue[stencilResolveModeNdx][sampleCountNdx];
1419 const TestConfig testConfig =
1427 imageData.renderArea,
1433 imageData.clearValue,
1436 useSeparateDepthStencilLayouts,
1439 formatGroup->addChild(new DSResolveTestInstance(testCtx, tcu::NODETYPE_SELF_VALIDATE, testName, testName, testConfig));
1444 sampleGroup->addChild(formatGroup.release());
1448 imageGroup->addChild(sampleGroup.release());
1451 group->addChild(imageGroup.release());
1455 // layered texture tests are done for all stencil modes and depth modes - not all combinations
1456 // Test checks if all layer are resolved in multi-layered framebuffer and if we can have a framebuffer
1457 // which starts at a layer other than zero. Both parts are tested together by rendering to layers
1458 // 4-6 and resolving to layers 1-3.
1459 ImageTestData layeredTextureTestData =
1461 "image_2d_16_64_6", 16, 64, 6, {{ 10, 10}, {6, 54}}, {1.0f, 0x0}
1464 de::MovePtr<tcu::TestCaseGroup> imageGroup(new tcu::TestCaseGroup(testCtx, layeredTextureTestData.groupName, layeredTextureTestData.groupName));
1466 for (size_t sampleCountNdx = 0; sampleCountNdx < DE_LENGTH_OF_ARRAY(sampleCounts); sampleCountNdx++)
1468 const deUint32 sampleCount (sampleCounts[sampleCountNdx]);
1469 const std::string sampleName ("samples_" + de::toString(sampleCount));
1471 // create test group for sample count
1472 de::MovePtr<tcu::TestCaseGroup> sampleGroup(new tcu::TestCaseGroup(testCtx, sampleName.c_str(), sampleName.c_str()));
1474 // iterate over depth/stencil formats
1475 for (size_t formatNdx = 0; formatNdx < DE_LENGTH_OF_ARRAY(formats); formatNdx++)
1477 const FormatData& formatData = formats[formatNdx];
1478 VkFormat format = formatData.format;
1479 const char* formatName = formatData.name;
1480 const bool hasDepth = formatData.hasDepth;
1481 const bool hasStencil = formatData.hasStencil;
1482 VkImageAspectFlags aspectFlags = (hasDepth * VK_IMAGE_ASPECT_DEPTH_BIT) |
1483 (hasStencil * VK_IMAGE_ASPECT_STENCIL_BIT);
1484 const int separateLayoutsLoopCount = (hasDepth && hasStencil) ? 2 : 1;
1486 for (int separateDepthStencilLayouts = 0; separateDepthStencilLayouts < separateLayoutsLoopCount; ++separateDepthStencilLayouts)
1488 const bool useSeparateDepthStencilLayouts = bool(separateDepthStencilLayouts);
1489 const std::string groupName = std::string(formatName) + ((useSeparateDepthStencilLayouts) ? "_separate_layouts" : "");
1491 // create test group for format
1492 de::MovePtr<tcu::TestCaseGroup> formatGroup(new tcu::TestCaseGroup(testCtx, groupName.c_str(), groupName.c_str()));
1494 for (size_t resolveModeNdx = 0; resolveModeNdx < DE_LENGTH_OF_ARRAY(resolveModes); resolveModeNdx++)
1496 for (int unusedIdx = 0; unusedIdx < 2; ++unusedIdx)
1498 ResolveModeData& mode = resolveModes[resolveModeNdx];
1500 const bool unusedResolve = (unusedIdx > 0);
1501 const std::string unusedSuffix = (unusedResolve ? "_unused_resolve" : "");
1505 std::string name = "depth_" + mode.name + unusedSuffix;
1506 const char* testName = name.c_str();
1507 float expectedValue = depthExpectedValue[resolveModeNdx][sampleCountNdx];
1508 const TestConfig testConfig =
1511 layeredTextureTestData.width,
1512 layeredTextureTestData.height,
1513 layeredTextureTestData.imageLayers,
1516 layeredTextureTestData.renderArea,
1520 VK_RESOLVE_MODE_SAMPLE_ZERO_BIT,
1522 layeredTextureTestData.clearValue,
1525 useSeparateDepthStencilLayouts,
1528 formatGroup->addChild(new DSResolveTestInstance(testCtx, tcu::NODETYPE_SELF_VALIDATE, testName, testName, testConfig));
1531 // there is no average resolve mode for stencil - go to next iteration
1532 if (mode.flag == VK_RESOLVE_MODE_AVERAGE_BIT)
1537 std::string name = "stencil_" + mode.name + unusedSuffix;
1538 const char* testName = name.c_str();
1539 deUint8 expectedValue = stencilExpectedValue[resolveModeNdx][sampleCountNdx];
1540 const TestConfig testConfig =
1543 layeredTextureTestData.width,
1544 layeredTextureTestData.height,
1545 layeredTextureTestData.imageLayers,
1548 layeredTextureTestData.renderArea,
1551 VK_RESOLVE_MODE_SAMPLE_ZERO_BIT,
1554 layeredTextureTestData.clearValue,
1557 useSeparateDepthStencilLayouts,
1560 formatGroup->addChild(new DSResolveTestInstance(testCtx, tcu::NODETYPE_SELF_VALIDATE, testName, testName, testConfig));
1564 sampleGroup->addChild(formatGroup.release());
1567 imageGroup->addChild(sampleGroup.release());
1570 group->addChild(imageGroup.release());
1576 tcu::TestCaseGroup* createRenderPass2DepthStencilResolveTests (tcu::TestContext& testCtx)
1578 return createTestGroup(testCtx, "depth_stencil_resolve", "Depth/stencil resolve tests", initTests);