From 57fb625663db6fe1d11c6fa0f6047b29695aac78 Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Sun, 3 Dec 2017 20:16:32 -0800 Subject: [PATCH] layers: Add warning for LOAD_OP_LOAD+LAYOUT_UNDEFINED While not technically an error (VK_IMAGE_LAYOUT_UNDEFINED is always allowed as an initial layout), this combination is almost never what you actually want. If nothing else, it's a potential performance problem because VK_ATTACHMENT_LOAD_OP_LOAD is liable to be more expensive than VK_ATTACHMENT_LOAD_OP_DONT_CARE. Give developers a helpful warning in this case. This would have caught an actual bug in some of the Sascha Willems demos as fixed in this PR: https://github.com/SaschaWillems/Vulkan/pull/400 Change-Id: I73c64ae60a65cfb200db00707d650ec8da7ba130 --- layers/buffer_validation.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/layers/buffer_validation.cpp b/layers/buffer_validation.cpp index 60e7842..77314a2 100644 --- a/layers/buffer_validation.cpp +++ b/layers/buffer_validation.cpp @@ -2793,6 +2793,32 @@ bool ValidateLayouts(core_validation::layer_data *device_data, VkDevice device, const debug_report_data *report_data = core_validation::GetReportData(device_data); bool skip = false; + for (uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) { + VkFormat format = pCreateInfo->pAttachments[i].format; + if (pCreateInfo->pAttachments[i].initialLayout == VK_IMAGE_LAYOUT_UNDEFINED) { + if ((FormatIsColor(format) || FormatHasDepth(format)) && + pCreateInfo->pAttachments[i].loadOp == VK_ATTACHMENT_LOAD_OP_LOAD) { + skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, + VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, + __LINE__, DRAWSTATE_INVALID_RENDERPASS, "DS", + "Render pass has an attachment with loadOp == VK_ATTACHMENT_LOAD_OP_LOAD and " + "initialLayout == VK_IMAGE_LAYOUT_UNDEFINED. This is probably not what you " + "intended. Consider using VK_ATTACHMENT_LOAD_OP_DONT_CARE instead if the " + "image truely is undefined at the start of the render pass."); + } + if (FormatHasStencil(format) && + pCreateInfo->pAttachments[i].stencilLoadOp == VK_ATTACHMENT_LOAD_OP_LOAD) { + skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, + VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, + __LINE__, DRAWSTATE_INVALID_RENDERPASS, "DS", + "Render pass has an attachment with stencilLoadOp == VK_ATTACHMENT_LOAD_OP_LOAD " + "and initialLayout == VK_IMAGE_LAYOUT_UNDEFINED. This is probably not what you " + "intended. Consider using VK_ATTACHMENT_LOAD_OP_DONT_CARE instead if the " + "image truely is undefined at the start of the render pass."); + } + } + } + // Track when we're observing the first use of an attachment std::vector attach_first_use(pCreateInfo->attachmentCount, true); for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) { -- 2.7.4