Add functions to get depth/stencil format in buffer memory
authorJeff Bolz <jbolz@nvidia.com>
Tue, 15 Dec 2015 19:58:19 +0000 (19:58 +0000)
committerJeff Bolz <jbolz@nvidia.com>
Tue, 15 Dec 2015 19:58:19 +0000 (19:58 +0000)
external/vulkancts/framework/vulkan/vkImageUtil.cpp
external/vulkancts/framework/vulkan/vkImageUtil.hpp
external/vulkancts/modules/vulkan/vktRenderPassTests.cpp

index 7eb7a08..3ae21b9 100644 (file)
@@ -889,4 +889,47 @@ tcu::UVec4 mapVkComponentMapping (const vk::VkComponentMapping& mapping)
        return swizzle;
 }
 
+// Get a format the matches the layout in buffer memory used for a
+// buffer<->image copy on a depth/stencil format.
+tcu::TextureFormat getDepthCopyFormat(VkFormat combinedFormat)
+{
+       switch (combinedFormat) {
+       case VK_FORMAT_D16_UNORM:
+       case VK_FORMAT_X8_D24_UNORM_PACK32:
+       case VK_FORMAT_D32_SFLOAT:
+               return mapVkFormat(combinedFormat);
+
+       case VK_FORMAT_D16_UNORM_S8_UINT:
+               return mapVkFormat(VK_FORMAT_D16_UNORM);
+       case VK_FORMAT_D24_UNORM_S8_UINT:
+               return mapVkFormat(VK_FORMAT_X8_D24_UNORM_PACK32);
+       case VK_FORMAT_D32_SFLOAT_S8_UINT:
+               return mapVkFormat(VK_FORMAT_D32_SFLOAT);
+
+       case VK_FORMAT_S8_UINT:
+       default:
+               DE_FATAL("Unexpected depth/stencil format");
+               return tcu::TextureFormat();
+       }
+}
+
+// Get a format the matches the layout in buffer memory used for a
+// buffer<->image copy on a depth/stencil format.
+tcu::TextureFormat getStencilCopyFormat(VkFormat combinedFormat)
+{
+       switch (combinedFormat) {
+       case VK_FORMAT_D16_UNORM_S8_UINT:
+       case VK_FORMAT_D24_UNORM_S8_UINT:
+       case VK_FORMAT_D32_SFLOAT_S8_UINT:
+       case VK_FORMAT_S8_UINT:
+               return mapVkFormat(VK_FORMAT_S8_UINT);
+       case VK_FORMAT_D16_UNORM:
+       case VK_FORMAT_X8_D24_UNORM_PACK32:
+       case VK_FORMAT_D32_SFLOAT:
+       default:
+               DE_FATAL("Unexpected depth/stencil format");
+               return tcu::TextureFormat();
+       }
+}
+
 } // vk
index 6084945..c130b57 100644 (file)
@@ -53,6 +53,8 @@ bool                                          isCompressedFormat                      (VkFormat format);
 
 tcu::TextureFormat                     mapVkFormat                                     (VkFormat format);
 tcu::CompressedTexFormat       mapVkCompressedFormat           (VkFormat format);
+tcu::TextureFormat                     getDepthCopyFormat                      (VkFormat combinedFormat);
+tcu::TextureFormat                     getStencilCopyFormat            (VkFormat combinedFormat);
 
 tcu::Sampler                           mapVkSampler                            (const VkSamplerCreateInfo& samplerCreateInfo);
 tcu::Sampler::CompareMode      mapVkSamplerCompareOp           (VkCompareOp compareOp);
index b72fe1d..f7f1748 100644 (file)
@@ -1186,8 +1186,8 @@ public:
 
                        if (tcu::hasDepthComponent(format.order) && tcu::hasStencilComponent(format.order))
                        {
-                               const tcu::TextureFormat        depthFormat             = tcu::getEffectiveDepthStencilTextureFormat(format, tcu::Sampler::MODE_DEPTH);
-                               const tcu::TextureFormat        stencilFormat   = tcu::getEffectiveDepthStencilTextureFormat(format, tcu::Sampler::MODE_STENCIL);
+                               const tcu::TextureFormat        depthFormat             = getDepthCopyFormat(attachmentInfo.getFormat());
+                               const tcu::TextureFormat        stencilFormat   = getStencilCopyFormat(attachmentInfo.getFormat());
 
                                m_bufferSize                    = size.x() * size.y() * depthFormat.getPixelSize();
                                m_secondaryBufferSize   = size.x() * size.y() * stencilFormat.getPixelSize();
@@ -3250,11 +3250,11 @@ bool logAndVerifyImages (TestLog&                                                                                       log,
 
                        if (tcu::hasDepthComponent(format.order) && tcu::hasStencilComponent(format.order))
                        {
-                               const tcu::TextureFormat        depthFormat             = tcu::getEffectiveDepthStencilTextureFormat(format, tcu::Sampler::MODE_DEPTH);
+                               const tcu::TextureFormat        depthFormat             = getDepthCopyFormat(attachment.getFormat());
                                const VkDeviceSize                      depthBufferSize = targetSize.x() * targetSize.y() * depthFormat.getPixelSize();
                                void* const                                     depthPtr                = attachmentResources[attachmentNdx]->getResultMemory().getHostPtr();
 
-                               const tcu::TextureFormat        stencilFormat           = tcu::getEffectiveDepthStencilTextureFormat(format, tcu::Sampler::MODE_STENCIL);
+                               const tcu::TextureFormat        stencilFormat           = getStencilCopyFormat(attachment.getFormat());
                                const VkDeviceSize                      stencilBufferSize       = targetSize.x() * targetSize.y() * stencilFormat.getPixelSize();
                                void* const                                     stencilPtr                      = attachmentResources[attachmentNdx]->getSecondaryResultMemory().getHostPtr();
 
@@ -3278,8 +3278,7 @@ bool logAndVerifyImages (TestLog&                                                                                 log,
                                VK_CHECK(vk.invalidateMappedMemoryRanges(device, 2u, ranges));
 
                                {
-                                       const ConstPixelBufferAccess    depthAccess             (depthFormat, tcu::IVec3(targetSize.x(), targetSize.y(), 1),
-                                                                                                                                                                 tcu::IVec3(format.getPixelSize(), format.getPixelSize() * targetSize.x(), 0), depthPtr);
+                                       const ConstPixelBufferAccess    depthAccess             (depthFormat, targetSize.x(), targetSize.y(), 1, depthPtr);
                                        const ConstPixelBufferAccess    stencilAccess   (stencilFormat, targetSize.x(), targetSize.y(), 1, stencilPtr);
                                        tcu::TextureLevel                               errorImage              (tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8), targetSize.x(), targetSize.y());