From 2ca0a769a06cb6fec403593e23ab086a2bb14743 Mon Sep 17 00:00:00 2001 From: Mark Lobodzinski Date: Tue, 22 Nov 2016 11:18:46 -0700 Subject: [PATCH] layers: Moved image/buffer aspect check Moved this validation check into a routine shared by both copyImageToBuffer and copyBufferToImage. Change-Id: If53581cb7dd847492f52b9c2c95b0be25654074f --- layers/image.cpp | 28 ++++++++++++---------------- layers/vk_validation_error_database.txt | 2 +- tests/layer_validation_tests.cpp | 10 ---------- 3 files changed, 13 insertions(+), 27 deletions(-) diff --git a/layers/image.cpp b/layers/image.cpp index 536932b..242c0a6 100644 --- a/layers/image.cpp +++ b/layers/image.cpp @@ -32,8 +32,10 @@ #include #include #include +#include #include #include +#include #include "vk_loader_platform.h" #include "vk_dispatch_table_helper.h" @@ -885,6 +887,16 @@ static bool ValidateBufferImageCopyData(layer_data *dev_data, uint32_t regionCou function, i, pRegions[i].bufferImageHeight, pRegions[i].imageExtent.height, validation_error_map[VALIDATION_ERROR_01266]); } + + const int num_bits = sizeof(VkFlags) * CHAR_BIT; + std::bitset aspect_mask_bits (pRegions[i].imageSubresource.aspectMask); + if (aspect_mask_bits.count() != 1) { + skip |= + log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, + reinterpret_cast(image), __LINE__, VALIDATION_ERROR_01280, "IMAGE", + "%s: aspectMasks for imageSubresource in each region must have only a single bit set. %s", function, + validation_error_map[VALIDATION_ERROR_01280]); + } } } @@ -907,14 +919,6 @@ static bool PreCallValidateCmdCopyImageToBuffer(layer_data *dev_data, VkCommandB skip |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer, __LINE__, IMAGE_MISMATCHED_IMAGE_ASPECT, "IMAGE", str); } - - VkImageAspectFlags aspectMask = pRegions[i].imageSubresource.aspectMask; - if ((aspectMask != VK_IMAGE_ASPECT_COLOR_BIT) && (aspectMask != VK_IMAGE_ASPECT_DEPTH_BIT) && - (aspectMask != VK_IMAGE_ASPECT_STENCIL_BIT)) { - char const str[] = "vkCmdCopyImageToBuffer: aspectMasks for each region must specify only COLOR or DEPTH or STENCIL"; - skip |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, - (uint64_t)commandBuffer, __LINE__, IMAGE_INVALID_IMAGE_ASPECT, "IMAGE", str); - } } return skip; } @@ -946,14 +950,6 @@ static bool PreCallValidateCmdCopyBufferToImage(layer_data *dev_data, VkCommandB skip |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer, __LINE__, IMAGE_MISMATCHED_IMAGE_ASPECT, "IMAGE", str); } - - VkImageAspectFlags aspectMask = pRegions[i].imageSubresource.aspectMask; - if ((aspectMask != VK_IMAGE_ASPECT_COLOR_BIT) && (aspectMask != VK_IMAGE_ASPECT_DEPTH_BIT) && - (aspectMask != VK_IMAGE_ASPECT_STENCIL_BIT)) { - char const str[] = "vkCmdCopyBufferToImage: aspectMasks for each region must specify only COLOR or DEPTH or STENCIL"; - skip |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, - (uint64_t)commandBuffer, __LINE__, IMAGE_INVALID_IMAGE_ASPECT, "IMAGE", str); - } } return skip; } diff --git a/layers/vk_validation_error_database.txt b/layers/vk_validation_error_database.txt index 7155521..e0d31fb 100644 --- a/layers/vk_validation_error_database.txt +++ b/layers/vk_validation_error_database.txt @@ -1270,7 +1270,7 @@ VALIDATION_ERROR_01276~^~U~^~Unknown~^~vkCmdCopyImageToBuffer~^~For more informa VALIDATION_ERROR_01277~^~U~^~Unknown~^~vkCmdCopyImageToBuffer~^~For more information refer to Vulkan Spec Section '18.4. Copying Data Between Buffers and Images' which states 'imageExtent.depth must be a multiple of the compressed texel block depth or (imageExtent.depth + imageOffset.z) must equal the image subresource depth' (https://www.khronos.org/registry/vulkan/specs/1.0-extensions/xhtml/vkspec.html#VkBufferImageCopy)~^~ VALIDATION_ERROR_01278~^~U~^~Unknown~^~vkCmdCopyImageToBuffer~^~For more information refer to Vulkan Spec Section '18.4. Copying Data Between Buffers and Images' which states 'bufferOffset, bufferRowLength, bufferImageHeight and all members of imageOffset and imageExtent must respect the image transfer granularity requirements of the queue family that it will be submitted against, as described in Physical Device Enumeration' (https://www.khronos.org/registry/vulkan/specs/1.0-extensions/xhtml/vkspec.html#VkBufferImageCopy)~^~ VALIDATION_ERROR_01279~^~U~^~Unknown~^~vkCmdCopyImageToBuffer~^~For more information refer to Vulkan Spec Section '18.4. Copying Data Between Buffers and Images' which states 'The aspectMask member of imageSubresource must specify aspects present in the calling commands VkImage parameter' (https://www.khronos.org/registry/vulkan/specs/1.0-extensions/xhtml/vkspec.html#VkBufferImageCopy)~^~ -VALIDATION_ERROR_01280~^~U~^~Unknown~^~vkCmdCopyImageToBuffer~^~For more information refer to Vulkan Spec Section '18.4. Copying Data Between Buffers and Images' which states 'The aspectMask member of imageSubresource must only have a single bit set' (https://www.khronos.org/registry/vulkan/specs/1.0-extensions/xhtml/vkspec.html#VkBufferImageCopy)~^~ +VALIDATION_ERROR_01280~^~Y~^~None~^~vkCmdCopyImageToBuffer~^~For more information refer to Vulkan Spec Section '18.4. Copying Data Between Buffers and Images' which states 'The aspectMask member of imageSubresource must only have a single bit set' (https://www.khronos.org/registry/vulkan/specs/1.0-extensions/xhtml/vkspec.html#VkBufferImageCopy)~^~ VALIDATION_ERROR_01281~^~U~^~Unknown~^~vkCmdCopyImageToBuffer~^~For more information refer to Vulkan Spec Section '18.4. Copying Data Between Buffers and Images' which states 'If the calling commands VkImage parameter is of VkImageType VK_IMAGE_TYPE_3D, the baseArrayLayer and layerCount members of imageSubresource must be 0 and 1, respectively' (https://www.khronos.org/registry/vulkan/specs/1.0-extensions/xhtml/vkspec.html#VkBufferImageCopy)~^~ VALIDATION_ERROR_01282~^~U~^~Unknown~^~vkCmdCopyImageToBuffer~^~For more information refer to Vulkan Spec Section '18.4. Copying Data Between Buffers and Images' which states 'When copying to the depth aspect of an image subresource, the data in the source buffer must be in the range [0,1]' (https://www.khronos.org/registry/vulkan/specs/1.0-extensions/xhtml/vkspec.html#VkBufferImageCopy)~^~ VALIDATION_ERROR_01283~^~U~^~Unknown~^~vkCmdCopyImageToBuffer~^~For more information refer to Vulkan Spec Section '18.4. Copying Data Between Buffers and Images' which states 'imageSubresource must be a valid VkImageSubresourceLayers structure' (https://www.khronos.org/registry/vulkan/specs/1.0-extensions/xhtml/vkspec.html#VkBufferImageCopy)~^~ diff --git a/tests/layer_validation_tests.cpp b/tests/layer_validation_tests.cpp index a7086ff..99f50bf 100644 --- a/tests/layer_validation_tests.cpp +++ b/tests/layer_validation_tests.cpp @@ -14277,16 +14277,6 @@ TEST_F(VkLayerTest, MiscImageLayerTests) { m_errorMonitor->VerifyFound(); region.bufferImageHeight = 128; - m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "aspectMasks for each region must " - "specify only COLOR or DEPTH or " - "STENCIL"); - // Expect MISMATCHED_IMAGE_ASPECT - region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT; - vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(), - VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ®ion); - m_errorMonitor->VerifyFound(); - region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; - m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "If the format of srcImage is a depth, stencil, depth stencil or " "integer-based format then filter must be VK_FILTER_NEAREST"); -- 2.7.4