layers: Fix a bug in depth/stencil packing
authorDave Houlton <daveh@lunarg.com>
Tue, 21 Feb 2017 22:59:08 +0000 (15:59 -0700)
committerDave Houlton <daveh@lunarg.com>
Wed, 22 Feb 2017 22:11:12 +0000 (15:11 -0700)
Fixed incorrect size calculations for image<->buffer copies
due to special packing rules of depth and stencil formats.
Added test code to layer_validation_tests ImageBufferCopyTests to
exercise these checks.

Change-Id: I90446379ba8888bf91eda6567e18fa1aae9593b1

layers/buffer_validation.cpp
layers/vk_layer_utils.cpp

index 76389cf..41bfb9d 100644 (file)
@@ -2685,6 +2685,27 @@ static inline bool ValidtateBufferBounds(const debug_report_data *report_data, I
         VkDeviceSize buffer_height = (0 == pRegions[i].bufferImageHeight ? copy_extent.height : pRegions[i].bufferImageHeight);
         VkDeviceSize unit_size = vk_format_get_size(image_state->createInfo.format);  // size (bytes) of texel or block
 
+        // Handle special buffer packing rules for specific depth/stencil formats
+        if (pRegions[i].imageSubresource.aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) {
+            unit_size = vk_format_get_size(VK_FORMAT_S8_UINT);
+        } else if (pRegions[i].imageSubresource.aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) {
+            switch (image_state->createInfo.format) {
+                case VK_FORMAT_D16_UNORM_S8_UINT:
+                    unit_size = vk_format_get_size(VK_FORMAT_D16_UNORM);
+                    break;
+                case VK_FORMAT_D32_SFLOAT_S8_UINT:
+                    unit_size = vk_format_get_size(VK_FORMAT_D32_SFLOAT);
+                    break;
+                case VK_FORMAT_X8_D24_UNORM_PACK32:
+                    // Intentionally fall through
+                case VK_FORMAT_D24_UNORM_S8_UINT:
+                    unit_size = 4;
+                    break;
+                default:
+                    break;
+            }
+        }
+
         if (vk_format_is_compressed(image_state->createInfo.format)) {
             VkExtent2D texel_block_extent = vk_format_compressed_block_size(image_state->createInfo.format);
             buffer_width /= texel_block_extent.width;  // switch to texel block units
index e83e4f9..18a42b9 100644 (file)
@@ -167,7 +167,7 @@ const std::map<VkFormat, VULKAN_FORMAT_INFO> vk_format_table = {
     {VK_FORMAT_S8_UINT,                     {1, 1, VK_FORMAT_COMPATIBILITY_CLASS_NONE_BIT}},
     {VK_FORMAT_D16_UNORM_S8_UINT,           {3, 2, VK_FORMAT_COMPATIBILITY_CLASS_NONE_BIT}},
     {VK_FORMAT_D24_UNORM_S8_UINT,           {4, 2, VK_FORMAT_COMPATIBILITY_CLASS_NONE_BIT}},
-    {VK_FORMAT_D32_SFLOAT_S8_UINT,          {4, 2, VK_FORMAT_COMPATIBILITY_CLASS_NONE_BIT}},
+    {VK_FORMAT_D32_SFLOAT_S8_UINT,          {5, 2, VK_FORMAT_COMPATIBILITY_CLASS_NONE_BIT}},
     {VK_FORMAT_BC1_RGB_UNORM_BLOCK,         {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_BC1_RGB_BIT}},
     {VK_FORMAT_BC1_RGB_SRGB_BLOCK,          {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_BC1_RGB_BIT}},
     {VK_FORMAT_BC1_RGBA_UNORM_BLOCK,        {8, 4, VK_FORMAT_COMPATIBILITY_CLASS_BC1_RGBA_BIT}},