diff options
| author | Tobin Ehlis <tobine@google.com> | 2017-03-14 15:38:48 -0600 |
|---|---|---|
| committer | Tobin Ehlis <tobine@google.com> | 2017-03-22 10:19:45 -0600 |
| commit | 4ed818a0ae67be5bdb70d7d772e4faac2ee0199a (patch) | |
| tree | 2fd2da8f5caf10aceb4859af7b729cad8de34a22 | |
| parent | 2b7b39d0d0b56c5ad70297021d9cc833c028d1fb (diff) | |
| download | usermoji-4ed818a0ae67be5bdb70d7d772e4faac2ee0199a.tar.xz | |
layers:Unify image layout validation functions
VerifySourceImageLayout() and VerifyDestImageLayout() were nearly
identical so I generalized a couple of pieces and combined them in the
single VerifyImageLayout() function.
| -rw-r--r-- | layers/buffer_validation.cpp | 92 |
1 files changed, 28 insertions, 64 deletions
diff --git a/layers/buffer_validation.cpp b/layers/buffer_validation.cpp index 29776051..9ccecfa9 100644 --- a/layers/buffer_validation.cpp +++ b/layers/buffer_validation.cpp @@ -504,81 +504,45 @@ void TransitionImageLayouts(layer_data *device_data, VkCommandBuffer cmdBuffer, } } -bool VerifySourceImageLayout(layer_data *device_data, GLOBAL_CB_NODE *cb_node, VkImage srcImage, VkImageSubresourceLayers subLayers, - VkImageLayout srcImageLayout, UNIQUE_VALIDATION_ERROR_CODE msgCode) { +bool VerifyImageLayout(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *image_state, + VkImageSubresourceLayers subLayers, VkImageLayout explicit_layout, VkImageLayout optimal_layout, + const char *caller, UNIQUE_VALIDATION_ERROR_CODE msgCode) { const auto report_data = core_validation::GetReportData(device_data); + const auto image = image_state->image; bool skip_call = false; for (uint32_t i = 0; i < subLayers.layerCount; ++i) { uint32_t layer = i + subLayers.baseArrayLayer; VkImageSubresource sub = {subLayers.aspectMask, subLayers.mipLevel, layer}; IMAGE_CMD_BUF_LAYOUT_NODE node; - if (!FindCmdBufLayout(device_data, cb_node, srcImage, sub, node)) { - SetLayout(device_data, cb_node, srcImage, sub, IMAGE_CMD_BUF_LAYOUT_NODE(srcImageLayout, srcImageLayout)); + if (!FindCmdBufLayout(device_data, cb_node, image, sub, node)) { + SetLayout(device_data, cb_node, image, sub, IMAGE_CMD_BUF_LAYOUT_NODE(explicit_layout, explicit_layout)); continue; } - if (node.layout != srcImageLayout) { + if (node.layout != explicit_layout) { // TODO: Improve log message in the next pass skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", - "Cannot copy from an image whose source layout is %s " - "and doesn't match the current layout %s.", - string_VkImageLayout(srcImageLayout), string_VkImageLayout(node.layout)); + "%s: Cannot use an image with specific layout %s " + "that doesn't match the actual current layout %s.", + caller, string_VkImageLayout(explicit_layout), string_VkImageLayout(node.layout)); } } - if (srcImageLayout != VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL) { - if (srcImageLayout == VK_IMAGE_LAYOUT_GENERAL) { - // TODO : Can we deal with image node from the top of call tree and avoid map look-up here? - auto image_state = GetImageState(device_data, srcImage); + // If optimal_layout is not UNDEFINED, check that layout matches optimal for this case + if ((VK_IMAGE_LAYOUT_UNDEFINED != optimal_layout) && (explicit_layout != optimal_layout)) { + if (VK_IMAGE_LAYOUT_GENERAL == explicit_layout) { if (image_state->createInfo.tiling != VK_IMAGE_TILING_LINEAR) { // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning. skip_call |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", - "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL."); + "%s: For optimal performance image layout should be %s instead of GENERAL.", caller, + string_VkImageLayout(optimal_layout)); } } else { - skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, msgCode, - "DS", "Layout for input image is %s but can only be TRANSFER_SRC_OPTIMAL or GENERAL. %s", - string_VkImageLayout(srcImageLayout), validation_error_map[msgCode]); - } - } - return skip_call; -} - -bool VerifyDestImageLayout(layer_data *device_data, GLOBAL_CB_NODE *cb_node, VkImage destImage, VkImageSubresourceLayers subLayers, - VkImageLayout destImageLayout, UNIQUE_VALIDATION_ERROR_CODE msgCode) { - const auto report_data = core_validation::GetReportData(device_data); - bool skip_call = false; - - for (uint32_t i = 0; i < subLayers.layerCount; ++i) { - uint32_t layer = i + subLayers.baseArrayLayer; - VkImageSubresource sub = {subLayers.aspectMask, subLayers.mipLevel, layer}; - IMAGE_CMD_BUF_LAYOUT_NODE node; - if (!FindCmdBufLayout(device_data, cb_node, destImage, sub, node)) { - SetLayout(device_data, cb_node, destImage, sub, IMAGE_CMD_BUF_LAYOUT_NODE(destImageLayout, destImageLayout)); - continue; - } - if (node.layout != destImageLayout) { - skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, - __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", - "Cannot copy from an image whose dest layout is %s and " - "doesn't match the current layout %s.", - string_VkImageLayout(destImageLayout), string_VkImageLayout(node.layout)); - } - } - if (destImageLayout != VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) { - if (destImageLayout == VK_IMAGE_LAYOUT_GENERAL) { - auto image_state = GetImageState(device_data, destImage); - if (image_state->createInfo.tiling != VK_IMAGE_TILING_LINEAR) { - // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning. - skip_call |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, - __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", - "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL."); - } - } else { - skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, msgCode, - "DS", "Layout for output image is %s but can only be TRANSFER_DST_OPTIMAL or GENERAL. %s", - string_VkImageLayout(destImageLayout), validation_error_map[msgCode]); + skip_call |= + log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, msgCode, "DS", + "%s: Layout for image is %s but can only be %s or VK_IMAGE_LAYOUT_GENERAL. %s", caller, + string_VkImageLayout(explicit_layout), string_VkImageLayout(optimal_layout), validation_error_map[msgCode]); } } return skip_call; @@ -1494,10 +1458,10 @@ bool PreCallValidateCmdCopyImage(layer_data *device_data, GLOBAL_CB_NODE *cb_nod skip |= ValidateCmd(device_data, cb_node, CMD_COPYIMAGE, "vkCmdCopyImage()"); skip |= insideRenderPass(device_data, cb_node, "vkCmdCopyImage()", VALIDATION_ERROR_01194); for (uint32_t i = 0; i < region_count; ++i) { - skip |= VerifySourceImageLayout(device_data, cb_node, src_image_state->image, regions[i].srcSubresource, src_image_layout, - VALIDATION_ERROR_01180); - skip |= VerifyDestImageLayout(device_data, cb_node, dst_image_state->image, regions[i].dstSubresource, dst_image_layout, - VALIDATION_ERROR_01183); + skip |= VerifyImageLayout(device_data, cb_node, src_image_state, regions[i].srcSubresource, src_image_layout, + VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, "vkCmdCopyImage()", VALIDATION_ERROR_01180); + skip |= VerifyImageLayout(device_data, cb_node, dst_image_state, regions[i].dstSubresource, dst_image_layout, + VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, "vkCmdCopyImage()", VALIDATION_ERROR_01183); skip |= ValidateCopyImageTransferGranularityRequirements(device_data, cb_node, dst_image_state, ®ions[i], i, "vkCmdCopyImage()"); } @@ -2986,10 +2950,10 @@ bool PreCallValidateCmdCopyImageToBuffer(layer_data *device_data, VkImageLayout "vkCmdCopyImageToBuffer()", "VK_BUFFER_USAGE_TRANSFER_DST_BIT"); skip |= insideRenderPass(device_data, cb_node, "vkCmdCopyImageToBuffer()", VALIDATION_ERROR_01260); for (uint32_t i = 0; i < regionCount; ++i) { - skip |= VerifySourceImageLayout(device_data, cb_node, src_image_state->image, pRegions[i].imageSubresource, srcImageLayout, - VALIDATION_ERROR_01251); + skip |= VerifyImageLayout(device_data, cb_node, src_image_state, pRegions[i].imageSubresource, srcImageLayout, + VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, "vkCmdCopyImageToBuffer()", VALIDATION_ERROR_01251); skip |= ValidateCopyBufferImageTransferGranularityRequirements(device_data, cb_node, src_image_state, &pRegions[i], i, - "CmdCopyImageToBuffer"); + "vkCmdCopyImageToBuffer()"); } return skip; } @@ -3053,8 +3017,8 @@ bool PreCallValidateCmdCopyBufferToImage(layer_data *device_data, VkImageLayout "vkCmdCopyBufferToImage()", "VK_IMAGE_USAGE_TRANSFER_DST_BIT"); skip |= insideRenderPass(device_data, cb_node, "vkCmdCopyBufferToImage()", VALIDATION_ERROR_01242); for (uint32_t i = 0; i < regionCount; ++i) { - skip |= VerifyDestImageLayout(device_data, cb_node, dst_image_state->image, pRegions[i].imageSubresource, dstImageLayout, - VALIDATION_ERROR_01234); + skip |= VerifyImageLayout(device_data, cb_node, dst_image_state, pRegions[i].imageSubresource, dstImageLayout, + VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, "vkCmdCopyBufferToImage()", VALIDATION_ERROR_01234); skip |= ValidateCopyBufferImageTransferGranularityRequirements(device_data, cb_node, dst_image_state, &pRegions[i], i, "vkCmdCopyBufferToImage()"); } |
