Mark Lobodzinski | d42e4d2 | 2017-01-17 14:14:22 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2015-2017 The Khronos Group Inc. |
| 2 | * Copyright (c) 2015-2017 Valve Corporation |
| 3 | * Copyright (c) 2015-2017 LunarG, Inc. |
| 4 | * Copyright (C) 2015-2017 Google Inc. |
| 5 | * |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | * |
| 18 | * Author: Mark Lobodzinski <mark@lunarg.com> |
| 19 | */ |
| 20 | |
| 21 | // Allow use of STL min and max functions in Windows |
| 22 | #define NOMINMAX |
| 23 | |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 24 | #include <sstream> |
| 25 | |
| 26 | #include "vk_enum_string_helper.h" |
| 27 | #include "vk_layer_data.h" |
| 28 | #include "vk_layer_utils.h" |
| 29 | #include "vk_layer_logging.h" |
| 30 | |
| 31 | |
Mark Lobodzinski | d42e4d2 | 2017-01-17 14:14:22 -0700 | [diff] [blame] | 32 | #include "buffer_validation.h" |
Mark Lobodzinski | 42fe5f7 | 2017-01-11 11:36:16 -0700 | [diff] [blame] | 33 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 34 | void SetLayout(layer_data *device_data, GLOBAL_CB_NODE *pCB, ImageSubresourcePair imgpair, const VkImageLayout &layout) { |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 35 | if (std::find(pCB->imageSubresourceMap[imgpair.image].begin(), pCB->imageSubresourceMap[imgpair.image].end(), imgpair) != |
| 36 | pCB->imageSubresourceMap[imgpair.image].end()) { |
| 37 | pCB->imageLayoutMap[imgpair].layout = layout; |
| 38 | } else { |
| 39 | assert(imgpair.hasSubresource); |
| 40 | IMAGE_CMD_BUF_LAYOUT_NODE node; |
| 41 | if (!FindCmdBufLayout(device_data, pCB, imgpair.image, imgpair.subresource, node)) { |
| 42 | node.initialLayout = layout; |
| 43 | } |
| 44 | SetLayout(device_data, pCB, imgpair, {node.initialLayout, layout}); |
| 45 | } |
| 46 | } |
| 47 | template <class OBJECT, class LAYOUT> |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 48 | void SetLayout(layer_data *device_data, OBJECT *pObject, VkImage image, VkImageSubresource range, const LAYOUT &layout) { |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 49 | ImageSubresourcePair imgpair = {image, true, range}; |
| 50 | SetLayout(device_data, pObject, imgpair, layout, VK_IMAGE_ASPECT_COLOR_BIT); |
| 51 | SetLayout(device_data, pObject, imgpair, layout, VK_IMAGE_ASPECT_DEPTH_BIT); |
| 52 | SetLayout(device_data, pObject, imgpair, layout, VK_IMAGE_ASPECT_STENCIL_BIT); |
| 53 | SetLayout(device_data, pObject, imgpair, layout, VK_IMAGE_ASPECT_METADATA_BIT); |
| 54 | } |
| 55 | |
| 56 | template <class OBJECT, class LAYOUT> |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 57 | void SetLayout(layer_data *device_data, OBJECT *pObject, ImageSubresourcePair imgpair, const LAYOUT &layout, |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 58 | VkImageAspectFlags aspectMask) { |
| 59 | if (imgpair.subresource.aspectMask & aspectMask) { |
| 60 | imgpair.subresource.aspectMask = aspectMask; |
| 61 | SetLayout(device_data, pObject, imgpair, layout); |
| 62 | } |
| 63 | } |
| 64 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 65 | bool FindLayoutVerifyNode(layer_data *device_data, GLOBAL_CB_NODE *pCB, ImageSubresourcePair imgpair, |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 66 | IMAGE_CMD_BUF_LAYOUT_NODE &node, const VkImageAspectFlags aspectMask) { |
| 67 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 68 | |
| 69 | if (!(imgpair.subresource.aspectMask & aspectMask)) { |
| 70 | return false; |
| 71 | } |
| 72 | VkImageAspectFlags oldAspectMask = imgpair.subresource.aspectMask; |
| 73 | imgpair.subresource.aspectMask = aspectMask; |
| 74 | auto imgsubIt = pCB->imageLayoutMap.find(imgpair); |
| 75 | if (imgsubIt == pCB->imageLayoutMap.end()) { |
| 76 | return false; |
| 77 | } |
| 78 | if (node.layout != VK_IMAGE_LAYOUT_MAX_ENUM && node.layout != imgsubIt->second.layout) { |
| 79 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 80 | reinterpret_cast<uint64_t &>(imgpair.image), __LINE__, DRAWSTATE_INVALID_LAYOUT, "DS", |
| 81 | "Cannot query for VkImage 0x%" PRIx64 " layout when combined aspect mask %d has multiple layout types: %s and %s", |
| 82 | reinterpret_cast<uint64_t &>(imgpair.image), oldAspectMask, string_VkImageLayout(node.layout), |
| 83 | string_VkImageLayout(imgsubIt->second.layout)); |
| 84 | } |
| 85 | if (node.initialLayout != VK_IMAGE_LAYOUT_MAX_ENUM && node.initialLayout != imgsubIt->second.initialLayout) { |
| 86 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 87 | reinterpret_cast<uint64_t &>(imgpair.image), __LINE__, DRAWSTATE_INVALID_LAYOUT, "DS", |
| 88 | "Cannot query for VkImage 0x%" PRIx64 |
| 89 | " layout when combined aspect mask %d has multiple initial layout types: %s and %s", |
| 90 | reinterpret_cast<uint64_t &>(imgpair.image), oldAspectMask, string_VkImageLayout(node.initialLayout), |
| 91 | string_VkImageLayout(imgsubIt->second.initialLayout)); |
| 92 | } |
| 93 | node = imgsubIt->second; |
| 94 | return true; |
| 95 | } |
| 96 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 97 | bool FindLayoutVerifyLayout(layer_data *device_data, ImageSubresourcePair imgpair, VkImageLayout &layout, |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 98 | const VkImageAspectFlags aspectMask) { |
| 99 | if (!(imgpair.subresource.aspectMask & aspectMask)) { |
| 100 | return false; |
| 101 | } |
| 102 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 103 | VkImageAspectFlags oldAspectMask = imgpair.subresource.aspectMask; |
| 104 | imgpair.subresource.aspectMask = aspectMask; |
| 105 | auto imgsubIt = (*core_validation::GetImageLayoutMap(device_data)).find(imgpair); |
| 106 | if (imgsubIt == (*core_validation::GetImageLayoutMap(device_data)).end()) { |
| 107 | return false; |
| 108 | } |
| 109 | if (layout != VK_IMAGE_LAYOUT_MAX_ENUM && layout != imgsubIt->second.layout) { |
| 110 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 111 | reinterpret_cast<uint64_t &>(imgpair.image), __LINE__, DRAWSTATE_INVALID_LAYOUT, "DS", |
| 112 | "Cannot query for VkImage 0x%" PRIx64 " layout when combined aspect mask %d has multiple layout types: %s and %s", |
| 113 | reinterpret_cast<uint64_t &>(imgpair.image), oldAspectMask, string_VkImageLayout(layout), |
| 114 | string_VkImageLayout(imgsubIt->second.layout)); |
| 115 | } |
| 116 | layout = imgsubIt->second.layout; |
| 117 | return true; |
| 118 | } |
| 119 | |
| 120 | // Find layout(s) on the command buffer level |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 121 | bool FindCmdBufLayout(layer_data *device_data, GLOBAL_CB_NODE *pCB, VkImage image, VkImageSubresource range, |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 122 | IMAGE_CMD_BUF_LAYOUT_NODE &node) { |
| 123 | ImageSubresourcePair imgpair = {image, true, range}; |
| 124 | node = IMAGE_CMD_BUF_LAYOUT_NODE(VK_IMAGE_LAYOUT_MAX_ENUM, VK_IMAGE_LAYOUT_MAX_ENUM); |
| 125 | FindLayoutVerifyNode(device_data, pCB, imgpair, node, VK_IMAGE_ASPECT_COLOR_BIT); |
| 126 | FindLayoutVerifyNode(device_data, pCB, imgpair, node, VK_IMAGE_ASPECT_DEPTH_BIT); |
| 127 | FindLayoutVerifyNode(device_data, pCB, imgpair, node, VK_IMAGE_ASPECT_STENCIL_BIT); |
| 128 | FindLayoutVerifyNode(device_data, pCB, imgpair, node, VK_IMAGE_ASPECT_METADATA_BIT); |
| 129 | if (node.layout == VK_IMAGE_LAYOUT_MAX_ENUM) { |
| 130 | imgpair = {image, false, VkImageSubresource()}; |
| 131 | auto imgsubIt = pCB->imageLayoutMap.find(imgpair); |
| 132 | if (imgsubIt == pCB->imageLayoutMap.end()) return false; |
| 133 | // TODO: This is ostensibly a find function but it changes state here |
| 134 | node = imgsubIt->second; |
| 135 | } |
| 136 | return true; |
| 137 | } |
| 138 | |
| 139 | // Find layout(s) on the global level |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 140 | bool FindGlobalLayout(layer_data *device_data, ImageSubresourcePair imgpair, VkImageLayout &layout) { |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 141 | layout = VK_IMAGE_LAYOUT_MAX_ENUM; |
| 142 | FindLayoutVerifyLayout(device_data, imgpair, layout, VK_IMAGE_ASPECT_COLOR_BIT); |
| 143 | FindLayoutVerifyLayout(device_data, imgpair, layout, VK_IMAGE_ASPECT_DEPTH_BIT); |
| 144 | FindLayoutVerifyLayout(device_data, imgpair, layout, VK_IMAGE_ASPECT_STENCIL_BIT); |
| 145 | FindLayoutVerifyLayout(device_data, imgpair, layout, VK_IMAGE_ASPECT_METADATA_BIT); |
| 146 | if (layout == VK_IMAGE_LAYOUT_MAX_ENUM) { |
| 147 | imgpair = {imgpair.image, false, VkImageSubresource()}; |
| 148 | auto imgsubIt = (*core_validation::GetImageLayoutMap(device_data)).find(imgpair); |
| 149 | if (imgsubIt == (*core_validation::GetImageLayoutMap(device_data)).end()) return false; |
| 150 | layout = imgsubIt->second.layout; |
| 151 | } |
| 152 | return true; |
| 153 | } |
| 154 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 155 | bool FindLayouts(layer_data *device_data, VkImage image, std::vector<VkImageLayout> &layouts) { |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 156 | auto sub_data = (*core_validation::GetImageSubresourceMap(device_data)).find(image); |
| 157 | if (sub_data == (*core_validation::GetImageSubresourceMap(device_data)).end()) return false; |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 158 | auto image_state = GetImageState(device_data, image); |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 159 | if (!image_state) return false; |
| 160 | bool ignoreGlobal = false; |
| 161 | // TODO: Make this robust for >1 aspect mask. Now it will just say ignore potential errors in this case. |
| 162 | if (sub_data->second.size() >= (image_state->createInfo.arrayLayers * image_state->createInfo.mipLevels + 1)) { |
| 163 | ignoreGlobal = true; |
| 164 | } |
| 165 | for (auto imgsubpair : sub_data->second) { |
| 166 | if (ignoreGlobal && !imgsubpair.hasSubresource) continue; |
| 167 | auto img_data = (*core_validation::GetImageLayoutMap(device_data)).find(imgsubpair); |
| 168 | if (img_data != (*core_validation::GetImageLayoutMap(device_data)).end()) { |
| 169 | layouts.push_back(img_data->second.layout); |
| 170 | } |
| 171 | } |
| 172 | return true; |
| 173 | } |
| 174 | |
| 175 | // Set the layout on the global level |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 176 | void SetGlobalLayout(layer_data *device_data, ImageSubresourcePair imgpair, const VkImageLayout &layout) { |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 177 | VkImage &image = imgpair.image; |
| 178 | (*core_validation::GetImageLayoutMap(device_data))[imgpair].layout = layout; |
| 179 | auto &image_subresources = (*core_validation::GetImageSubresourceMap(device_data))[image]; |
| 180 | auto subresource = std::find(image_subresources.begin(), image_subresources.end(), imgpair); |
| 181 | if (subresource == image_subresources.end()) { |
| 182 | image_subresources.push_back(imgpair); |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | // Set the layout on the cmdbuf level |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 187 | void SetLayout(layer_data *device_data, GLOBAL_CB_NODE *pCB, ImageSubresourcePair imgpair, const IMAGE_CMD_BUF_LAYOUT_NODE &node) { |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 188 | pCB->imageLayoutMap[imgpair] = node; |
| 189 | auto subresource = |
| 190 | std::find(pCB->imageSubresourceMap[imgpair.image].begin(), pCB->imageSubresourceMap[imgpair.image].end(), imgpair); |
| 191 | if (subresource == pCB->imageSubresourceMap[imgpair.image].end()) { |
| 192 | pCB->imageSubresourceMap[imgpair.image].push_back(imgpair); |
| 193 | } |
| 194 | } |
| 195 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 196 | void SetImageViewLayout(layer_data *device_data, GLOBAL_CB_NODE *pCB, VkImageView imageView, const VkImageLayout &layout) { |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 197 | auto view_state = GetImageViewState(device_data, imageView); |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 198 | assert(view_state); |
| 199 | auto image = view_state->create_info.image; |
| 200 | const VkImageSubresourceRange &subRange = view_state->create_info.subresourceRange; |
| 201 | // TODO: Do not iterate over every possibility - consolidate where possible |
| 202 | for (uint32_t j = 0; j < subRange.levelCount; j++) { |
| 203 | uint32_t level = subRange.baseMipLevel + j; |
| 204 | for (uint32_t k = 0; k < subRange.layerCount; k++) { |
| 205 | uint32_t layer = subRange.baseArrayLayer + k; |
| 206 | VkImageSubresource sub = {subRange.aspectMask, level, layer}; |
| 207 | // TODO: If ImageView was created with depth or stencil, transition both layouts as the aspectMask is ignored and both |
| 208 | // are used. Verify that the extra implicit layout is OK for descriptor set layout validation |
| 209 | if (subRange.aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) { |
| 210 | if (vk_format_is_depth_and_stencil(view_state->create_info.format)) { |
| 211 | sub.aspectMask |= (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT); |
| 212 | } |
| 213 | } |
| 214 | SetLayout(device_data, pCB, image, sub, layout); |
| 215 | } |
| 216 | } |
| 217 | } |
| 218 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 219 | bool VerifyFramebufferAndRenderPassLayouts(layer_data *device_data, GLOBAL_CB_NODE *pCB, |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 220 | const VkRenderPassBeginInfo *pRenderPassBegin, |
| 221 | const FRAMEBUFFER_STATE *framebuffer_state) { |
| 222 | bool skip_call = false; |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 223 | auto const pRenderPassInfo = GetRenderPassState(device_data, pRenderPassBegin->renderPass)->createInfo.ptr(); |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 224 | auto const &framebufferInfo = framebuffer_state->createInfo; |
| 225 | const auto report_data = core_validation::GetReportData(device_data); |
| 226 | if (pRenderPassInfo->attachmentCount != framebufferInfo.attachmentCount) { |
| 227 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, |
| 228 | DRAWSTATE_INVALID_RENDERPASS, "DS", |
| 229 | "You cannot start a render pass using a framebuffer " |
| 230 | "with a different number of attachments."); |
| 231 | } |
| 232 | for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) { |
| 233 | const VkImageView &image_view = framebufferInfo.pAttachments[i]; |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 234 | auto view_state = GetImageViewState(device_data, image_view); |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 235 | assert(view_state); |
| 236 | const VkImage &image = view_state->create_info.image; |
| 237 | const VkImageSubresourceRange &subRange = view_state->create_info.subresourceRange; |
| 238 | IMAGE_CMD_BUF_LAYOUT_NODE newNode = {pRenderPassInfo->pAttachments[i].initialLayout, |
| 239 | pRenderPassInfo->pAttachments[i].initialLayout}; |
| 240 | // TODO: Do not iterate over every possibility - consolidate where possible |
| 241 | for (uint32_t j = 0; j < subRange.levelCount; j++) { |
| 242 | uint32_t level = subRange.baseMipLevel + j; |
| 243 | for (uint32_t k = 0; k < subRange.layerCount; k++) { |
| 244 | uint32_t layer = subRange.baseArrayLayer + k; |
| 245 | VkImageSubresource sub = {subRange.aspectMask, level, layer}; |
| 246 | IMAGE_CMD_BUF_LAYOUT_NODE node; |
| 247 | if (!FindCmdBufLayout(device_data, pCB, image, sub, node)) { |
| 248 | SetLayout(device_data, pCB, image, sub, newNode); |
| 249 | continue; |
| 250 | } |
| 251 | if (newNode.layout != VK_IMAGE_LAYOUT_UNDEFINED && newNode.layout != node.layout) { |
| 252 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, |
| 253 | DRAWSTATE_INVALID_RENDERPASS, "DS", |
| 254 | "You cannot start a render pass using attachment %u " |
| 255 | "where the render pass initial layout is %s and the previous " |
| 256 | "known layout of the attachment is %s. The layouts must match, or " |
| 257 | "the render pass initial layout for the attachment must be " |
| 258 | "VK_IMAGE_LAYOUT_UNDEFINED", |
| 259 | i, string_VkImageLayout(newNode.layout), string_VkImageLayout(node.layout)); |
| 260 | } |
| 261 | } |
| 262 | } |
| 263 | } |
| 264 | return skip_call; |
| 265 | } |
| 266 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 267 | void TransitionAttachmentRefLayout(layer_data *device_data, GLOBAL_CB_NODE *pCB, FRAMEBUFFER_STATE *pFramebuffer, |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 268 | VkAttachmentReference ref) { |
| 269 | if (ref.attachment != VK_ATTACHMENT_UNUSED) { |
| 270 | auto image_view = pFramebuffer->createInfo.pAttachments[ref.attachment]; |
| 271 | SetImageViewLayout(device_data, pCB, image_view, ref.layout); |
| 272 | } |
| 273 | } |
| 274 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 275 | void TransitionSubpassLayouts(layer_data *device_data, GLOBAL_CB_NODE *pCB, const VkRenderPassBeginInfo *pRenderPassBegin, |
| 276 | const int subpass_index, FRAMEBUFFER_STATE *framebuffer_state) { |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 277 | auto renderPass = GetRenderPassState(device_data, pRenderPassBegin->renderPass); |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 278 | if (!renderPass) return; |
| 279 | |
| 280 | if (framebuffer_state) { |
| 281 | auto const &subpass = renderPass->createInfo.pSubpasses[subpass_index]; |
| 282 | for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) { |
| 283 | TransitionAttachmentRefLayout(device_data, pCB, framebuffer_state, subpass.pInputAttachments[j]); |
| 284 | } |
| 285 | for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) { |
| 286 | TransitionAttachmentRefLayout(device_data, pCB, framebuffer_state, subpass.pColorAttachments[j]); |
| 287 | } |
| 288 | if (subpass.pDepthStencilAttachment) { |
| 289 | TransitionAttachmentRefLayout(device_data, pCB, framebuffer_state, *subpass.pDepthStencilAttachment); |
| 290 | } |
| 291 | } |
| 292 | } |
| 293 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 294 | bool TransitionImageAspectLayout(layer_data *device_data, GLOBAL_CB_NODE *pCB, const VkImageMemoryBarrier *mem_barrier, |
| 295 | uint32_t level, uint32_t layer, VkImageAspectFlags aspect) { |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 296 | if (!(mem_barrier->subresourceRange.aspectMask & aspect)) { |
| 297 | return false; |
| 298 | } |
| 299 | VkImageSubresource sub = {aspect, level, layer}; |
| 300 | IMAGE_CMD_BUF_LAYOUT_NODE node; |
| 301 | if (!FindCmdBufLayout(device_data, pCB, mem_barrier->image, sub, node)) { |
| 302 | SetLayout(device_data, pCB, mem_barrier->image, sub, |
| 303 | IMAGE_CMD_BUF_LAYOUT_NODE(mem_barrier->oldLayout, mem_barrier->newLayout)); |
| 304 | return false; |
| 305 | } |
| 306 | bool skip = false; |
| 307 | if (mem_barrier->oldLayout == VK_IMAGE_LAYOUT_UNDEFINED) { |
| 308 | // TODO: Set memory invalid which is in mem_tracker currently |
| 309 | } else if (node.layout != mem_barrier->oldLayout) { |
| 310 | skip |= log_msg(core_validation::GetReportData(device_data), VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, |
| 311 | 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", |
| 312 | "You cannot transition the layout of aspect %d from %s when current layout is %s.", aspect, |
| 313 | string_VkImageLayout(mem_barrier->oldLayout), string_VkImageLayout(node.layout)); |
| 314 | } |
| 315 | SetLayout(device_data, pCB, mem_barrier->image, sub, mem_barrier->newLayout); |
| 316 | return skip; |
| 317 | } |
| 318 | |
| 319 | // TODO: Separate validation and layout state updates |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 320 | bool TransitionImageLayouts(layer_data *device_data, VkCommandBuffer cmdBuffer, uint32_t memBarrierCount, |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 321 | const VkImageMemoryBarrier *pImgMemBarriers) { |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 322 | GLOBAL_CB_NODE *pCB = GetCBNode(device_data, cmdBuffer); |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 323 | bool skip = false; |
| 324 | uint32_t levelCount = 0; |
| 325 | uint32_t layerCount = 0; |
| 326 | |
| 327 | for (uint32_t i = 0; i < memBarrierCount; ++i) { |
| 328 | auto mem_barrier = &pImgMemBarriers[i]; |
| 329 | if (!mem_barrier) continue; |
| 330 | // TODO: Do not iterate over every possibility - consolidate where possible |
| 331 | ResolveRemainingLevelsLayers(device_data, &levelCount, &layerCount, mem_barrier->subresourceRange, |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 332 | GetImageState(device_data, mem_barrier->image)); |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 333 | |
| 334 | for (uint32_t j = 0; j < levelCount; j++) { |
| 335 | uint32_t level = mem_barrier->subresourceRange.baseMipLevel + j; |
| 336 | for (uint32_t k = 0; k < layerCount; k++) { |
| 337 | uint32_t layer = mem_barrier->subresourceRange.baseArrayLayer + k; |
| 338 | skip |= TransitionImageAspectLayout(device_data, pCB, mem_barrier, level, layer, VK_IMAGE_ASPECT_COLOR_BIT); |
| 339 | skip |= TransitionImageAspectLayout(device_data, pCB, mem_barrier, level, layer, VK_IMAGE_ASPECT_DEPTH_BIT); |
| 340 | skip |= TransitionImageAspectLayout(device_data, pCB, mem_barrier, level, layer, VK_IMAGE_ASPECT_STENCIL_BIT); |
| 341 | skip |= TransitionImageAspectLayout(device_data, pCB, mem_barrier, level, layer, VK_IMAGE_ASPECT_METADATA_BIT); |
| 342 | } |
| 343 | } |
| 344 | } |
| 345 | return skip; |
| 346 | } |
| 347 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 348 | bool VerifySourceImageLayout(layer_data *device_data, GLOBAL_CB_NODE *cb_node, VkImage srcImage, VkImageSubresourceLayers subLayers, |
| 349 | VkImageLayout srcImageLayout, UNIQUE_VALIDATION_ERROR_CODE msgCode) { |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 350 | const auto report_data = core_validation::GetReportData(device_data); |
| 351 | bool skip_call = false; |
| 352 | |
| 353 | for (uint32_t i = 0; i < subLayers.layerCount; ++i) { |
| 354 | uint32_t layer = i + subLayers.baseArrayLayer; |
| 355 | VkImageSubresource sub = {subLayers.aspectMask, subLayers.mipLevel, layer}; |
| 356 | IMAGE_CMD_BUF_LAYOUT_NODE node; |
| 357 | if (!FindCmdBufLayout(device_data, cb_node, srcImage, sub, node)) { |
| 358 | SetLayout(device_data, cb_node, srcImage, sub, IMAGE_CMD_BUF_LAYOUT_NODE(srcImageLayout, srcImageLayout)); |
| 359 | continue; |
| 360 | } |
| 361 | if (node.layout != srcImageLayout) { |
| 362 | // TODO: Improve log message in the next pass |
| 363 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, |
| 364 | __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", |
| 365 | "Cannot copy from an image whose source layout is %s " |
| 366 | "and doesn't match the current layout %s.", |
| 367 | string_VkImageLayout(srcImageLayout), string_VkImageLayout(node.layout)); |
| 368 | } |
| 369 | } |
| 370 | if (srcImageLayout != VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL) { |
| 371 | if (srcImageLayout == VK_IMAGE_LAYOUT_GENERAL) { |
| 372 | // TODO : Can we deal with image node from the top of call tree and avoid map look-up here? |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 373 | auto image_state = GetImageState(device_data, srcImage); |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 374 | if (image_state->createInfo.tiling != VK_IMAGE_TILING_LINEAR) { |
| 375 | // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning. |
| 376 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, |
| 377 | __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", |
| 378 | "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL."); |
| 379 | } |
| 380 | } else { |
| 381 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, msgCode, |
| 382 | "DS", "Layout for input image is %s but can only be TRANSFER_SRC_OPTIMAL or GENERAL. %s", |
| 383 | string_VkImageLayout(srcImageLayout), validation_error_map[msgCode]); |
| 384 | } |
| 385 | } |
| 386 | return skip_call; |
| 387 | } |
| 388 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 389 | bool VerifyDestImageLayout(layer_data *device_data, GLOBAL_CB_NODE *cb_node, VkImage destImage, VkImageSubresourceLayers subLayers, |
| 390 | VkImageLayout destImageLayout, UNIQUE_VALIDATION_ERROR_CODE msgCode) { |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 391 | const auto report_data = core_validation::GetReportData(device_data); |
| 392 | bool skip_call = false; |
| 393 | |
| 394 | for (uint32_t i = 0; i < subLayers.layerCount; ++i) { |
| 395 | uint32_t layer = i + subLayers.baseArrayLayer; |
| 396 | VkImageSubresource sub = {subLayers.aspectMask, subLayers.mipLevel, layer}; |
| 397 | IMAGE_CMD_BUF_LAYOUT_NODE node; |
| 398 | if (!FindCmdBufLayout(device_data, cb_node, destImage, sub, node)) { |
| 399 | SetLayout(device_data, cb_node, destImage, sub, IMAGE_CMD_BUF_LAYOUT_NODE(destImageLayout, destImageLayout)); |
| 400 | continue; |
| 401 | } |
| 402 | if (node.layout != destImageLayout) { |
| 403 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, |
| 404 | __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", |
| 405 | "Cannot copy from an image whose dest layout is %s and " |
| 406 | "doesn't match the current layout %s.", |
| 407 | string_VkImageLayout(destImageLayout), string_VkImageLayout(node.layout)); |
| 408 | } |
| 409 | } |
| 410 | if (destImageLayout != VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) { |
| 411 | if (destImageLayout == VK_IMAGE_LAYOUT_GENERAL) { |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 412 | auto image_state = GetImageState(device_data, destImage); |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 413 | if (image_state->createInfo.tiling != VK_IMAGE_TILING_LINEAR) { |
| 414 | // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning. |
| 415 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, |
| 416 | __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", |
| 417 | "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL."); |
| 418 | } |
| 419 | } else { |
| 420 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, msgCode, |
| 421 | "DS", "Layout for output image is %s but can only be TRANSFER_DST_OPTIMAL or GENERAL. %s", |
| 422 | string_VkImageLayout(destImageLayout), validation_error_map[msgCode]); |
| 423 | } |
| 424 | } |
| 425 | return skip_call; |
| 426 | } |
| 427 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 428 | void TransitionFinalSubpassLayouts(layer_data *device_data, GLOBAL_CB_NODE *pCB, const VkRenderPassBeginInfo *pRenderPassBegin, |
| 429 | FRAMEBUFFER_STATE *framebuffer_state) { |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 430 | auto renderPass = GetRenderPassState(device_data, pRenderPassBegin->renderPass); |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 431 | if (!renderPass) return; |
| 432 | |
| 433 | const VkRenderPassCreateInfo *pRenderPassInfo = renderPass->createInfo.ptr(); |
| 434 | if (framebuffer_state) { |
| 435 | for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) { |
| 436 | auto image_view = framebuffer_state->createInfo.pAttachments[i]; |
| 437 | SetImageViewLayout(device_data, pCB, image_view, pRenderPassInfo->pAttachments[i].finalLayout); |
| 438 | } |
| 439 | } |
| 440 | } |
| 441 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 442 | bool PreCallValidateCreateImage(layer_data *device_data, const VkImageCreateInfo *pCreateInfo, |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 443 | const VkAllocationCallbacks *pAllocator, VkImage *pImage) { |
| 444 | bool skip_call = false; |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 445 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 446 | |
| 447 | if (pCreateInfo->format != VK_FORMAT_UNDEFINED) { |
Mark Lobodzinski | efd933b | 2017-02-10 12:09:23 -0700 | [diff] [blame] | 448 | const VkFormatProperties *properties = GetFormatProperties(device_data, pCreateInfo->format); |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 449 | |
Mark Lobodzinski | efd933b | 2017-02-10 12:09:23 -0700 | [diff] [blame] | 450 | if ((pCreateInfo->tiling == VK_IMAGE_TILING_LINEAR) && (properties->linearTilingFeatures == 0)) { |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 451 | std::stringstream ss; |
| 452 | ss << "vkCreateImage format parameter (" << string_VkFormat(pCreateInfo->format) << ") is an unsupported format"; |
| 453 | skip_call |= |
| 454 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, |
| 455 | VALIDATION_ERROR_02150, "IMAGE", "%s. %s", ss.str().c_str(), validation_error_map[VALIDATION_ERROR_02150]); |
| 456 | } |
| 457 | |
Mark Lobodzinski | efd933b | 2017-02-10 12:09:23 -0700 | [diff] [blame] | 458 | if ((pCreateInfo->tiling == VK_IMAGE_TILING_OPTIMAL) && (properties->optimalTilingFeatures == 0)) { |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 459 | std::stringstream ss; |
| 460 | ss << "vkCreateImage format parameter (" << string_VkFormat(pCreateInfo->format) << ") is an unsupported format"; |
| 461 | skip_call |= |
| 462 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, |
| 463 | VALIDATION_ERROR_02155, "IMAGE", "%s. %s", ss.str().c_str(), validation_error_map[VALIDATION_ERROR_02155]); |
| 464 | } |
| 465 | |
| 466 | // Validate that format supports usage as color attachment |
| 467 | if (pCreateInfo->usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) { |
| 468 | if ((pCreateInfo->tiling == VK_IMAGE_TILING_OPTIMAL) && |
Mark Lobodzinski | efd933b | 2017-02-10 12:09:23 -0700 | [diff] [blame] | 469 | ((properties->optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) == 0)) { |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 470 | std::stringstream ss; |
| 471 | ss << "vkCreateImage: VkFormat for TILING_OPTIMAL image (" << string_VkFormat(pCreateInfo->format) |
| 472 | << ") does not support requested Image usage type VK_IMAGE_USAGE_COLOR_ATTACHMENT"; |
| 473 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 474 | __LINE__, VALIDATION_ERROR_02158, "IMAGE", "%s. %s", ss.str().c_str(), |
| 475 | validation_error_map[VALIDATION_ERROR_02158]); |
| 476 | } |
| 477 | if ((pCreateInfo->tiling == VK_IMAGE_TILING_LINEAR) && |
Mark Lobodzinski | efd933b | 2017-02-10 12:09:23 -0700 | [diff] [blame] | 478 | ((properties->linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) == 0)) { |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 479 | std::stringstream ss; |
| 480 | ss << "vkCreateImage: VkFormat for TILING_LINEAR image (" << string_VkFormat(pCreateInfo->format) |
| 481 | << ") does not support requested Image usage type VK_IMAGE_USAGE_COLOR_ATTACHMENT"; |
| 482 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 483 | __LINE__, VALIDATION_ERROR_02153, "IMAGE", "%s. %s", ss.str().c_str(), |
| 484 | validation_error_map[VALIDATION_ERROR_02153]); |
| 485 | } |
| 486 | } |
| 487 | // Validate that format supports usage as depth/stencil attachment |
| 488 | if (pCreateInfo->usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) { |
| 489 | if ((pCreateInfo->tiling == VK_IMAGE_TILING_OPTIMAL) && |
Mark Lobodzinski | efd933b | 2017-02-10 12:09:23 -0700 | [diff] [blame] | 490 | ((properties->optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) == 0)) { |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 491 | std::stringstream ss; |
| 492 | ss << "vkCreateImage: VkFormat for TILING_OPTIMAL image (" << string_VkFormat(pCreateInfo->format) |
| 493 | << ") does not support requested Image usage type VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT"; |
| 494 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 495 | __LINE__, VALIDATION_ERROR_02159, "IMAGE", "%s. %s", ss.str().c_str(), |
| 496 | validation_error_map[VALIDATION_ERROR_02159]); |
| 497 | } |
| 498 | if ((pCreateInfo->tiling == VK_IMAGE_TILING_LINEAR) && |
Mark Lobodzinski | efd933b | 2017-02-10 12:09:23 -0700 | [diff] [blame] | 499 | ((properties->linearTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) == 0)) { |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 500 | std::stringstream ss; |
| 501 | ss << "vkCreateImage: VkFormat for TILING_LINEAR image (" << string_VkFormat(pCreateInfo->format) |
| 502 | << ") does not support requested Image usage type VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT"; |
| 503 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 504 | __LINE__, VALIDATION_ERROR_02154, "IMAGE", "%s. %s", ss.str().c_str(), |
| 505 | validation_error_map[VALIDATION_ERROR_02154]); |
| 506 | } |
| 507 | } |
| 508 | } else { |
| 509 | skip_call |= |
| 510 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, |
| 511 | VALIDATION_ERROR_00715, "IMAGE", "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED. %s", |
| 512 | validation_error_map[VALIDATION_ERROR_00715]); |
| 513 | } |
| 514 | |
Mark Lobodzinski | efd933b | 2017-02-10 12:09:23 -0700 | [diff] [blame] | 515 | const VkImageFormatProperties *ImageFormatProperties = GetImageFormatProperties( |
| 516 | device_data, pCreateInfo->format, pCreateInfo->imageType, pCreateInfo->tiling, pCreateInfo->usage, pCreateInfo->flags); |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 517 | |
Mark Lobodzinski | efd933b | 2017-02-10 12:09:23 -0700 | [diff] [blame] | 518 | VkDeviceSize imageGranularity = GetPhysicalDeviceProperties(device_data)->limits.bufferImageGranularity; |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 519 | imageGranularity = imageGranularity == 1 ? 0 : imageGranularity; |
| 520 | |
Mark Lobodzinski | 688ed32 | 2017-01-27 11:13:21 -0700 | [diff] [blame] | 521 | if ((pCreateInfo->extent.width <= 0) || (pCreateInfo->extent.height <= 0) || (pCreateInfo->extent.depth <= 0)) { |
| 522 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__, |
| 523 | VALIDATION_ERROR_00716, "Image", |
| 524 | "CreateImage extent is 0 for at least one required dimension for image: " |
| 525 | "Width = %d Height = %d Depth = %d. %s", |
| 526 | pCreateInfo->extent.width, pCreateInfo->extent.height, pCreateInfo->extent.depth, |
| 527 | validation_error_map[VALIDATION_ERROR_00716]); |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | // TODO: VALIDATION_ERROR_02125 VALIDATION_ERROR_02126 VALIDATION_ERROR_02128 VALIDATION_ERROR_00720 |
| 531 | // All these extent-related VUs should be checked here |
Mark Lobodzinski | efd933b | 2017-02-10 12:09:23 -0700 | [diff] [blame] | 532 | if ((pCreateInfo->extent.depth > ImageFormatProperties->maxExtent.depth) || |
| 533 | (pCreateInfo->extent.width > ImageFormatProperties->maxExtent.width) || |
| 534 | (pCreateInfo->extent.height > ImageFormatProperties->maxExtent.height)) { |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 535 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__, |
| 536 | IMAGE_INVALID_FORMAT_LIMITS_VIOLATION, "Image", |
| 537 | "CreateImage extents exceed allowable limits for format: " |
| 538 | "Width = %d Height = %d Depth = %d: Limits for Width = %d Height = %d Depth = %d for format %s.", |
| 539 | pCreateInfo->extent.width, pCreateInfo->extent.height, pCreateInfo->extent.depth, |
Mark Lobodzinski | efd933b | 2017-02-10 12:09:23 -0700 | [diff] [blame] | 540 | ImageFormatProperties->maxExtent.width, ImageFormatProperties->maxExtent.height, |
| 541 | ImageFormatProperties->maxExtent.depth, string_VkFormat(pCreateInfo->format)); |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | uint64_t totalSize = ((uint64_t)pCreateInfo->extent.width * (uint64_t)pCreateInfo->extent.height * |
| 545 | (uint64_t)pCreateInfo->extent.depth * (uint64_t)pCreateInfo->arrayLayers * |
| 546 | (uint64_t)pCreateInfo->samples * (uint64_t)vk_format_get_size(pCreateInfo->format) + |
| 547 | (uint64_t)imageGranularity) & |
| 548 | ~(uint64_t)imageGranularity; |
| 549 | |
Mark Lobodzinski | efd933b | 2017-02-10 12:09:23 -0700 | [diff] [blame] | 550 | if (totalSize > ImageFormatProperties->maxResourceSize) { |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 551 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__, |
| 552 | IMAGE_INVALID_FORMAT_LIMITS_VIOLATION, "Image", |
| 553 | "CreateImage resource size exceeds allowable maximum " |
| 554 | "Image resource size = 0x%" PRIxLEAST64 ", maximum resource size = 0x%" PRIxLEAST64 " ", |
Mark Lobodzinski | efd933b | 2017-02-10 12:09:23 -0700 | [diff] [blame] | 555 | totalSize, ImageFormatProperties->maxResourceSize); |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | // TODO: VALIDATION_ERROR_02132 |
Mark Lobodzinski | efd933b | 2017-02-10 12:09:23 -0700 | [diff] [blame] | 559 | if (pCreateInfo->mipLevels > ImageFormatProperties->maxMipLevels) { |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 560 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__, |
| 561 | IMAGE_INVALID_FORMAT_LIMITS_VIOLATION, "Image", |
| 562 | "CreateImage mipLevels=%d exceeds allowable maximum supported by format of %d", pCreateInfo->mipLevels, |
Mark Lobodzinski | efd933b | 2017-02-10 12:09:23 -0700 | [diff] [blame] | 563 | ImageFormatProperties->maxMipLevels); |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 564 | } |
| 565 | |
Mark Lobodzinski | efd933b | 2017-02-10 12:09:23 -0700 | [diff] [blame] | 566 | if (pCreateInfo->arrayLayers > ImageFormatProperties->maxArrayLayers) { |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 567 | skip_call |= log_msg( |
| 568 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__, VALIDATION_ERROR_02133, |
| 569 | "Image", "CreateImage arrayLayers=%d exceeds allowable maximum supported by format of %d. %s", pCreateInfo->arrayLayers, |
Mark Lobodzinski | efd933b | 2017-02-10 12:09:23 -0700 | [diff] [blame] | 570 | ImageFormatProperties->maxArrayLayers, validation_error_map[VALIDATION_ERROR_02133]); |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 571 | } |
| 572 | |
Mark Lobodzinski | efd933b | 2017-02-10 12:09:23 -0700 | [diff] [blame] | 573 | if ((pCreateInfo->samples & ImageFormatProperties->sampleCounts) == 0) { |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 574 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__, |
| 575 | VALIDATION_ERROR_02138, "Image", "CreateImage samples %s is not supported by format 0x%.8X. %s", |
Mark Lobodzinski | efd933b | 2017-02-10 12:09:23 -0700 | [diff] [blame] | 576 | string_VkSampleCountFlagBits(pCreateInfo->samples), ImageFormatProperties->sampleCounts, |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 577 | validation_error_map[VALIDATION_ERROR_02138]); |
| 578 | } |
| 579 | |
| 580 | if (pCreateInfo->initialLayout != VK_IMAGE_LAYOUT_UNDEFINED && pCreateInfo->initialLayout != VK_IMAGE_LAYOUT_PREINITIALIZED) { |
| 581 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__, |
| 582 | VALIDATION_ERROR_00731, "Image", |
| 583 | "vkCreateImage parameter, pCreateInfo->initialLayout, must be VK_IMAGE_LAYOUT_UNDEFINED or " |
| 584 | "VK_IMAGE_LAYOUT_PREINITIALIZED. %s", |
| 585 | validation_error_map[VALIDATION_ERROR_00731]); |
| 586 | } |
| 587 | |
| 588 | return skip_call; |
| 589 | } |
| 590 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 591 | void PostCallRecordCreateImage(layer_data *device_data, const VkImageCreateInfo *pCreateInfo, VkImage *pImage) { |
Mark Lobodzinski | 42fe5f7 | 2017-01-11 11:36:16 -0700 | [diff] [blame] | 592 | IMAGE_LAYOUT_NODE image_state; |
| 593 | image_state.layout = pCreateInfo->initialLayout; |
| 594 | image_state.format = pCreateInfo->format; |
Mark Lobodzinski | 214144a | 2017-01-27 14:25:32 -0700 | [diff] [blame] | 595 | GetImageMap(device_data)->insert(std::make_pair(*pImage, std::unique_ptr<IMAGE_STATE>(new IMAGE_STATE(*pImage, pCreateInfo)))); |
Mark Lobodzinski | 42fe5f7 | 2017-01-11 11:36:16 -0700 | [diff] [blame] | 596 | ImageSubresourcePair subpair{*pImage, false, VkImageSubresource()}; |
Mark Lobodzinski | 214144a | 2017-01-27 14:25:32 -0700 | [diff] [blame] | 597 | (*core_validation::GetImageSubresourceMap(device_data))[*pImage].push_back(subpair); |
| 598 | (*core_validation::GetImageLayoutMap(device_data))[subpair] = image_state; |
Mark Lobodzinski | 42fe5f7 | 2017-01-11 11:36:16 -0700 | [diff] [blame] | 599 | } |
Mark Lobodzinski | 9ef5d56 | 2017-01-27 12:28:30 -0700 | [diff] [blame] | 600 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 601 | bool PreCallValidateDestroyImage(layer_data *device_data, VkImage image, IMAGE_STATE **image_state, VK_OBJECT *obj_struct) { |
Mark Lobodzinski | 9ef5d56 | 2017-01-27 12:28:30 -0700 | [diff] [blame] | 602 | const CHECK_DISABLED *disabled = core_validation::GetDisables(device_data); |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 603 | *image_state = core_validation::GetImageState(device_data, image); |
Mark Lobodzinski | 9ef5d56 | 2017-01-27 12:28:30 -0700 | [diff] [blame] | 604 | *obj_struct = {reinterpret_cast<uint64_t &>(image), VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT}; |
| 605 | if (disabled->destroy_image) return false; |
| 606 | bool skip = false; |
| 607 | if (*image_state) { |
| 608 | skip |= core_validation::ValidateObjectNotInUse(device_data, *image_state, *obj_struct, VALIDATION_ERROR_00743); |
| 609 | } |
| 610 | return skip; |
| 611 | } |
| 612 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 613 | void PostCallRecordDestroyImage(layer_data *device_data, VkImage image, IMAGE_STATE *image_state, VK_OBJECT obj_struct) { |
Mark Lobodzinski | 9ef5d56 | 2017-01-27 12:28:30 -0700 | [diff] [blame] | 614 | core_validation::invalidateCommandBuffers(device_data, image_state->cb_bindings, obj_struct); |
| 615 | // Clean up memory mapping, bindings and range references for image |
| 616 | for (auto mem_binding : image_state->GetBoundMemory()) { |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 617 | auto mem_info = core_validation::GetMemObjInfo(device_data, mem_binding); |
Mark Lobodzinski | 9ef5d56 | 2017-01-27 12:28:30 -0700 | [diff] [blame] | 618 | if (mem_info) { |
| 619 | core_validation::RemoveImageMemoryRange(obj_struct.handle, mem_info); |
| 620 | } |
| 621 | } |
| 622 | core_validation::ClearMemoryObjectBindings(device_data, obj_struct.handle, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT); |
| 623 | // Remove image from imageMap |
| 624 | core_validation::GetImageMap(device_data)->erase(image); |
| 625 | std::unordered_map<VkImage, std::vector<ImageSubresourcePair>> *imageSubresourceMap = |
| 626 | core_validation::GetImageSubresourceMap(device_data); |
| 627 | |
| 628 | const auto &sub_entry = imageSubresourceMap->find(image); |
| 629 | if (sub_entry != imageSubresourceMap->end()) { |
| 630 | for (const auto &pair : sub_entry->second) { |
| 631 | core_validation::GetImageLayoutMap(device_data)->erase(pair); |
| 632 | } |
| 633 | imageSubresourceMap->erase(sub_entry); |
| 634 | } |
| 635 | } |
Mark Lobodzinski | c409a58 | 2017-01-27 15:16:01 -0700 | [diff] [blame] | 636 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 637 | bool ValidateImageAttributes(layer_data *device_data, IMAGE_STATE *image_state, VkImageSubresourceRange range) { |
Mark Lobodzinski | c409a58 | 2017-01-27 15:16:01 -0700 | [diff] [blame] | 638 | bool skip = false; |
| 639 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 640 | |
| 641 | if (range.aspectMask != VK_IMAGE_ASPECT_COLOR_BIT) { |
| 642 | char const str[] = "vkCmdClearColorImage aspectMasks for all subresource ranges must be set to VK_IMAGE_ASPECT_COLOR_BIT"; |
| 643 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 644 | reinterpret_cast<uint64_t &>(image_state->image), __LINE__, DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", str); |
| 645 | } |
| 646 | |
| 647 | if (vk_format_is_depth_or_stencil(image_state->createInfo.format)) { |
| 648 | char const str[] = "vkCmdClearColorImage called with depth/stencil image."; |
| 649 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 650 | reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01088, "IMAGE", "%s. %s", str, |
| 651 | validation_error_map[VALIDATION_ERROR_01088]); |
| 652 | } else if (vk_format_is_compressed(image_state->createInfo.format)) { |
| 653 | char const str[] = "vkCmdClearColorImage called with compressed image."; |
| 654 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 655 | reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01088, "IMAGE", "%s. %s", str, |
| 656 | validation_error_map[VALIDATION_ERROR_01088]); |
| 657 | } |
| 658 | |
| 659 | if (!(image_state->createInfo.usage & VK_IMAGE_USAGE_TRANSFER_DST_BIT)) { |
| 660 | char const str[] = "vkCmdClearColorImage called with image created without VK_IMAGE_USAGE_TRANSFER_DST_BIT."; |
| 661 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 662 | reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01084, "IMAGE", "%s. %s", str, |
| 663 | validation_error_map[VALIDATION_ERROR_01084]); |
| 664 | } |
| 665 | return skip; |
| 666 | } |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 667 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 668 | void ResolveRemainingLevelsLayers(layer_data *dev_data, VkImageSubresourceRange *range, IMAGE_STATE *image_state) { |
Mark Lobodzinski | 9c93dbd | 2017-02-02 08:31:18 -0700 | [diff] [blame] | 669 | // If the caller used the special values VK_REMAINING_MIP_LEVELS and VK_REMAINING_ARRAY_LAYERS, resolve them now in our |
| 670 | // internal state to the actual values. |
| 671 | if (range->levelCount == VK_REMAINING_MIP_LEVELS) { |
| 672 | range->levelCount = image_state->createInfo.mipLevels - range->baseMipLevel; |
| 673 | } |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 674 | |
Mark Lobodzinski | 9c93dbd | 2017-02-02 08:31:18 -0700 | [diff] [blame] | 675 | if (range->layerCount == VK_REMAINING_ARRAY_LAYERS) { |
| 676 | range->layerCount = image_state->createInfo.arrayLayers - range->baseArrayLayer; |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 677 | } |
| 678 | } |
| 679 | |
| 680 | // Return the correct layer/level counts if the caller used the special values VK_REMAINING_MIP_LEVELS or VK_REMAINING_ARRAY_LAYERS. |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 681 | void ResolveRemainingLevelsLayers(layer_data *dev_data, uint32_t *levels, uint32_t *layers, VkImageSubresourceRange range, |
| 682 | IMAGE_STATE *image_state) { |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 683 | *levels = range.levelCount; |
| 684 | *layers = range.layerCount; |
Mark Lobodzinski | 9c93dbd | 2017-02-02 08:31:18 -0700 | [diff] [blame] | 685 | if (range.levelCount == VK_REMAINING_MIP_LEVELS) { |
| 686 | *levels = image_state->createInfo.mipLevels - range.baseMipLevel; |
| 687 | } |
| 688 | if (range.layerCount == VK_REMAINING_ARRAY_LAYERS) { |
| 689 | *layers = image_state->createInfo.arrayLayers - range.baseArrayLayer; |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 690 | } |
| 691 | } |
| 692 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 693 | bool VerifyClearImageLayout(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *image_state, |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 694 | VkImageSubresourceRange range, VkImageLayout dest_image_layout, const char *func_name) { |
| 695 | bool skip = false; |
| 696 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 697 | |
| 698 | VkImageSubresourceRange resolved_range = range; |
Mark Lobodzinski | 9c93dbd | 2017-02-02 08:31:18 -0700 | [diff] [blame] | 699 | ResolveRemainingLevelsLayers(device_data, &resolved_range, image_state); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 700 | |
| 701 | if (dest_image_layout != VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) { |
| 702 | if (dest_image_layout == VK_IMAGE_LAYOUT_GENERAL) { |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 703 | if (image_state->createInfo.tiling != VK_IMAGE_TILING_LINEAR) { |
| 704 | // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning. |
| 705 | skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, |
| 706 | __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", |
| 707 | "%s: Layout for cleared image should be TRANSFER_DST_OPTIMAL instead of GENERAL.", func_name); |
| 708 | } |
| 709 | } else { |
| 710 | UNIQUE_VALIDATION_ERROR_CODE error_code = VALIDATION_ERROR_01086; |
| 711 | if (strcmp(func_name, "vkCmdClearDepthStencilImage()") == 0) { |
| 712 | error_code = VALIDATION_ERROR_01101; |
| 713 | } else { |
| 714 | assert(strcmp(func_name, "vkCmdClearColorImage()") == 0); |
| 715 | } |
| 716 | skip |= |
| 717 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, error_code, "DS", |
| 718 | "%s: Layout for cleared image is %s but can only be " |
| 719 | "TRANSFER_DST_OPTIMAL or GENERAL. %s", |
| 720 | func_name, string_VkImageLayout(dest_image_layout), validation_error_map[error_code]); |
| 721 | } |
| 722 | } |
| 723 | |
| 724 | for (uint32_t level_index = 0; level_index < resolved_range.levelCount; ++level_index) { |
| 725 | uint32_t level = level_index + resolved_range.baseMipLevel; |
| 726 | for (uint32_t layer_index = 0; layer_index < resolved_range.layerCount; ++layer_index) { |
| 727 | uint32_t layer = layer_index + resolved_range.baseArrayLayer; |
| 728 | VkImageSubresource sub = {resolved_range.aspectMask, level, layer}; |
| 729 | IMAGE_CMD_BUF_LAYOUT_NODE node; |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 730 | if (FindCmdBufLayout(device_data, cb_node, image_state->image, sub, node)) { |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 731 | if (node.layout != dest_image_layout) { |
| 732 | UNIQUE_VALIDATION_ERROR_CODE error_code = VALIDATION_ERROR_01085; |
| 733 | if (strcmp(func_name, "vkCmdClearDepthStencilImage()") == 0) { |
| 734 | error_code = VALIDATION_ERROR_01100; |
| 735 | } else { |
| 736 | assert(strcmp(func_name, "vkCmdClearColorImage()") == 0); |
| 737 | } |
| 738 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, |
| 739 | __LINE__, error_code, "DS", |
| 740 | "%s: Cannot clear an image whose layout is %s and " |
| 741 | "doesn't match the current layout %s. %s", |
| 742 | func_name, string_VkImageLayout(dest_image_layout), string_VkImageLayout(node.layout), |
| 743 | validation_error_map[error_code]); |
| 744 | } |
| 745 | } |
| 746 | } |
| 747 | } |
| 748 | |
| 749 | return skip; |
| 750 | } |
| 751 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 752 | void RecordClearImageLayout(layer_data *device_data, GLOBAL_CB_NODE *cb_node, VkImage image, VkImageSubresourceRange range, |
| 753 | VkImageLayout dest_image_layout) { |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 754 | VkImageSubresourceRange resolved_range = range; |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 755 | ResolveRemainingLevelsLayers(device_data, &resolved_range, GetImageState(device_data, image)); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 756 | |
| 757 | for (uint32_t level_index = 0; level_index < resolved_range.levelCount; ++level_index) { |
| 758 | uint32_t level = level_index + resolved_range.baseMipLevel; |
| 759 | for (uint32_t layer_index = 0; layer_index < resolved_range.layerCount; ++layer_index) { |
| 760 | uint32_t layer = layer_index + resolved_range.baseArrayLayer; |
| 761 | VkImageSubresource sub = {resolved_range.aspectMask, level, layer}; |
| 762 | IMAGE_CMD_BUF_LAYOUT_NODE node; |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 763 | if (!FindCmdBufLayout(device_data, cb_node, image, sub, node)) { |
| 764 | SetLayout(device_data, cb_node, image, sub, IMAGE_CMD_BUF_LAYOUT_NODE(dest_image_layout, dest_image_layout)); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 765 | } |
| 766 | } |
| 767 | } |
| 768 | } |
| 769 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 770 | bool PreCallValidateCmdClearColorImage(layer_data *dev_data, VkCommandBuffer commandBuffer, VkImage image, |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 771 | VkImageLayout imageLayout, uint32_t rangeCount, const VkImageSubresourceRange *pRanges) { |
| 772 | bool skip = false; |
| 773 | // TODO : Verify memory is in VK_IMAGE_STATE_CLEAR state |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 774 | auto cb_node = GetCBNode(dev_data, commandBuffer); |
| 775 | auto image_state = GetImageState(dev_data, image); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 776 | if (cb_node && image_state) { |
| 777 | skip |= ValidateMemoryIsBoundToImage(dev_data, image_state, "vkCmdClearColorImage()", VALIDATION_ERROR_02527); |
| 778 | skip |= ValidateCmd(dev_data, cb_node, CMD_CLEARCOLORIMAGE, "vkCmdClearColorImage()"); |
| 779 | skip |= insideRenderPass(dev_data, cb_node, "vkCmdClearColorImage()", VALIDATION_ERROR_01096); |
| 780 | for (uint32_t i = 0; i < rangeCount; ++i) { |
| 781 | skip |= ValidateImageAttributes(dev_data, image_state, pRanges[i]); |
Mark Lobodzinski | 9c93dbd | 2017-02-02 08:31:18 -0700 | [diff] [blame] | 782 | skip |= VerifyClearImageLayout(dev_data, cb_node, image_state, pRanges[i], imageLayout, "vkCmdClearColorImage()"); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 783 | } |
| 784 | } |
| 785 | return skip; |
| 786 | } |
| 787 | |
| 788 | // This state recording routine is shared between ClearColorImage and ClearDepthStencilImage |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 789 | void PreCallRecordCmdClearImage(layer_data *dev_data, VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, |
| 790 | uint32_t rangeCount, const VkImageSubresourceRange *pRanges, CMD_TYPE cmd_type) { |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 791 | auto cb_node = GetCBNode(dev_data, commandBuffer); |
| 792 | auto image_state = GetImageState(dev_data, image); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 793 | if (cb_node && image_state) { |
| 794 | AddCommandBufferBindingImage(dev_data, cb_node, image_state); |
| 795 | std::function<bool()> function = [=]() { |
| 796 | SetImageMemoryValid(dev_data, image_state, true); |
| 797 | return false; |
| 798 | }; |
| 799 | cb_node->validate_functions.push_back(function); |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 800 | core_validation::UpdateCmdBufferLastCmd(cb_node, cmd_type); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 801 | for (uint32_t i = 0; i < rangeCount; ++i) { |
| 802 | RecordClearImageLayout(dev_data, cb_node, image, pRanges[i], imageLayout); |
| 803 | } |
| 804 | } |
| 805 | } |
| 806 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 807 | bool PreCallValidateCmdClearDepthStencilImage(layer_data *device_data, VkCommandBuffer commandBuffer, VkImage image, |
| 808 | VkImageLayout imageLayout, uint32_t rangeCount, |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 809 | const VkImageSubresourceRange *pRanges) { |
| 810 | bool skip = false; |
Mark Lobodzinski | 1241a31 | 2017-02-01 10:57:21 -0700 | [diff] [blame] | 811 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 812 | |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 813 | // TODO : Verify memory is in VK_IMAGE_STATE_CLEAR state |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 814 | auto cb_node = GetCBNode(device_data, commandBuffer); |
| 815 | auto image_state = GetImageState(device_data, image); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 816 | if (cb_node && image_state) { |
Mark Lobodzinski | 1241a31 | 2017-02-01 10:57:21 -0700 | [diff] [blame] | 817 | skip |= ValidateMemoryIsBoundToImage(device_data, image_state, "vkCmdClearDepthStencilImage()", VALIDATION_ERROR_02528); |
| 818 | skip |= ValidateCmd(device_data, cb_node, CMD_CLEARDEPTHSTENCILIMAGE, "vkCmdClearDepthStencilImage()"); |
| 819 | skip |= insideRenderPass(device_data, cb_node, "vkCmdClearDepthStencilImage()", VALIDATION_ERROR_01111); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 820 | for (uint32_t i = 0; i < rangeCount; ++i) { |
Mark Lobodzinski | 9c93dbd | 2017-02-02 08:31:18 -0700 | [diff] [blame] | 821 | skip |= |
| 822 | VerifyClearImageLayout(device_data, cb_node, image_state, pRanges[i], imageLayout, "vkCmdClearDepthStencilImage()"); |
Mark Lobodzinski | 1241a31 | 2017-02-01 10:57:21 -0700 | [diff] [blame] | 823 | // Image aspect must be depth or stencil or both |
| 824 | if (((pRanges[i].aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) != VK_IMAGE_ASPECT_DEPTH_BIT) && |
| 825 | ((pRanges[i].aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) != VK_IMAGE_ASPECT_STENCIL_BIT)) { |
| 826 | char const str[] = |
| 827 | "vkCmdClearDepthStencilImage aspectMasks for all subresource ranges must be " |
| 828 | "set to VK_IMAGE_ASPECT_DEPTH_BIT and/or VK_IMAGE_ASPECT_STENCIL_BIT"; |
| 829 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 830 | (uint64_t)commandBuffer, __LINE__, DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", str); |
| 831 | } |
| 832 | } |
| 833 | if (image_state && !vk_format_is_depth_or_stencil(image_state->createInfo.format)) { |
| 834 | char const str[] = "vkCmdClearDepthStencilImage called without a depth/stencil image."; |
| 835 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 836 | reinterpret_cast<uint64_t &>(image), __LINE__, VALIDATION_ERROR_01103, "IMAGE", "%s. %s", str, |
| 837 | validation_error_map[VALIDATION_ERROR_01103]); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 838 | } |
| 839 | } |
| 840 | return skip; |
| 841 | } |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 842 | |
| 843 | // Returns true if [x, xoffset] and [y, yoffset] overlap |
| 844 | static bool RangesIntersect(int32_t start, uint32_t start_offset, int32_t end, uint32_t end_offset) { |
| 845 | bool result = false; |
| 846 | uint32_t intersection_min = std::max(static_cast<uint32_t>(start), static_cast<uint32_t>(end)); |
| 847 | uint32_t intersection_max = std::min(static_cast<uint32_t>(start) + start_offset, static_cast<uint32_t>(end) + end_offset); |
| 848 | |
| 849 | if (intersection_max > intersection_min) { |
| 850 | result = true; |
| 851 | } |
| 852 | return result; |
| 853 | } |
| 854 | |
| 855 | // Returns true if two VkImageCopy structures overlap |
| 856 | static bool RegionIntersects(const VkImageCopy *src, const VkImageCopy *dst, VkImageType type) { |
| 857 | bool result = false; |
| 858 | if ((src->srcSubresource.mipLevel == dst->dstSubresource.mipLevel) && |
| 859 | (RangesIntersect(src->srcSubresource.baseArrayLayer, src->srcSubresource.layerCount, dst->dstSubresource.baseArrayLayer, |
| 860 | dst->dstSubresource.layerCount))) { |
| 861 | result = true; |
| 862 | switch (type) { |
| 863 | case VK_IMAGE_TYPE_3D: |
| 864 | result &= RangesIntersect(src->srcOffset.z, src->extent.depth, dst->dstOffset.z, dst->extent.depth); |
| 865 | // Intentionally fall through to 2D case |
| 866 | case VK_IMAGE_TYPE_2D: |
| 867 | result &= RangesIntersect(src->srcOffset.y, src->extent.height, dst->dstOffset.y, dst->extent.height); |
| 868 | // Intentionally fall through to 1D case |
| 869 | case VK_IMAGE_TYPE_1D: |
| 870 | result &= RangesIntersect(src->srcOffset.x, src->extent.width, dst->dstOffset.x, dst->extent.width); |
| 871 | break; |
| 872 | default: |
| 873 | // Unrecognized or new IMAGE_TYPE enums will be caught in parameter_validation |
| 874 | assert(false); |
| 875 | } |
| 876 | } |
| 877 | return result; |
| 878 | } |
| 879 | |
| 880 | // Returns true if offset and extent exceed image extents |
| 881 | static bool ExceedsBounds(const VkOffset3D *offset, const VkExtent3D *extent, const IMAGE_STATE *image_state) { |
| 882 | bool result = false; |
| 883 | // Extents/depths cannot be negative but checks left in for clarity |
| 884 | switch (image_state->createInfo.imageType) { |
| 885 | case VK_IMAGE_TYPE_3D: // Validate z and depth |
| 886 | if ((offset->z + extent->depth > image_state->createInfo.extent.depth) || (offset->z < 0) || |
| 887 | ((offset->z + static_cast<int32_t>(extent->depth)) < 0)) { |
| 888 | result = true; |
| 889 | } |
| 890 | // Intentionally fall through to 2D case to check height |
| 891 | case VK_IMAGE_TYPE_2D: // Validate y and height |
| 892 | if ((offset->y + extent->height > image_state->createInfo.extent.height) || (offset->y < 0) || |
| 893 | ((offset->y + static_cast<int32_t>(extent->height)) < 0)) { |
| 894 | result = true; |
| 895 | } |
| 896 | // Intentionally fall through to 1D case to check width |
| 897 | case VK_IMAGE_TYPE_1D: // Validate x and width |
| 898 | if ((offset->x + extent->width > image_state->createInfo.extent.width) || (offset->x < 0) || |
| 899 | ((offset->x + static_cast<int32_t>(extent->width)) < 0)) { |
| 900 | result = true; |
| 901 | } |
| 902 | break; |
| 903 | default: |
| 904 | assert(false); |
| 905 | } |
| 906 | return result; |
| 907 | } |
| 908 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 909 | // Test if two VkExtent3D structs are equivalent |
| 910 | static inline bool IsExtentEqual(const VkExtent3D *extent, const VkExtent3D *other_extent) { |
| 911 | bool result = true; |
| 912 | if ((extent->width != other_extent->width) || (extent->height != other_extent->height) || |
| 913 | (extent->depth != other_extent->depth)) { |
| 914 | result = false; |
| 915 | } |
| 916 | return result; |
| 917 | } |
| 918 | |
| 919 | // Returns the image extent of a specific subresource. |
| 920 | static inline VkExtent3D GetImageSubresourceExtent(const IMAGE_STATE *img, const VkImageSubresourceLayers *subresource) { |
| 921 | const uint32_t mip = subresource->mipLevel; |
| 922 | VkExtent3D extent = img->createInfo.extent; |
| 923 | extent.width = std::max(1U, extent.width >> mip); |
| 924 | extent.height = std::max(1U, extent.height >> mip); |
| 925 | extent.depth = std::max(1U, extent.depth >> mip); |
| 926 | return extent; |
| 927 | } |
| 928 | |
| 929 | // Test if the extent argument has all dimensions set to 0. |
| 930 | static inline bool IsExtentZero(const VkExtent3D *extent) { |
| 931 | return ((extent->width == 0) && (extent->height == 0) && (extent->depth == 0)); |
| 932 | } |
| 933 | |
| 934 | // Returns the image transfer granularity for a specific image scaled by compressed block size if necessary. |
| 935 | static inline VkExtent3D GetScaledItg(layer_data *device_data, const GLOBAL_CB_NODE *cb_node, const IMAGE_STATE *img) { |
| 936 | // Default to (0, 0, 0) granularity in case we can't find the real granularity for the physical device. |
| 937 | VkExtent3D granularity = {0, 0, 0}; |
| 938 | auto pPool = GetCommandPoolNode(device_data, cb_node->createInfo.commandPool); |
| 939 | if (pPool) { |
| 940 | granularity = |
| 941 | GetPhysDevProperties(device_data)->queue_family_properties[pPool->queueFamilyIndex].minImageTransferGranularity; |
| 942 | if (vk_format_is_compressed(img->createInfo.format)) { |
| 943 | auto block_size = vk_format_compressed_block_size(img->createInfo.format); |
| 944 | granularity.width *= block_size.width; |
| 945 | granularity.height *= block_size.height; |
| 946 | } |
| 947 | } |
| 948 | return granularity; |
| 949 | } |
| 950 | |
| 951 | // Test elements of a VkExtent3D structure against alignment constraints contained in another VkExtent3D structure |
| 952 | static inline bool IsExtentAligned(const VkExtent3D *extent, const VkExtent3D *granularity) { |
| 953 | bool valid = true; |
| 954 | if ((vk_safe_modulo(extent->depth, granularity->depth) != 0) || (vk_safe_modulo(extent->width, granularity->width) != 0) || |
| 955 | (vk_safe_modulo(extent->height, granularity->height) != 0)) { |
| 956 | valid = false; |
| 957 | } |
| 958 | return valid; |
| 959 | } |
| 960 | |
| 961 | // Check elements of a VkOffset3D structure against a queue family's Image Transfer Granularity values |
| 962 | static inline bool CheckItgOffset(layer_data *device_data, const GLOBAL_CB_NODE *cb_node, const VkOffset3D *offset, |
| 963 | const VkExtent3D *granularity, const uint32_t i, const char *function, const char *member) { |
| 964 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 965 | bool skip = false; |
| 966 | VkExtent3D offset_extent = {}; |
| 967 | offset_extent.width = static_cast<uint32_t>(abs(offset->x)); |
| 968 | offset_extent.height = static_cast<uint32_t>(abs(offset->y)); |
| 969 | offset_extent.depth = static_cast<uint32_t>(abs(offset->z)); |
| 970 | if (IsExtentZero(granularity)) { |
| 971 | // If the queue family image transfer granularity is (0, 0, 0), then the offset must always be (0, 0, 0) |
| 972 | if (IsExtentZero(&offset_extent) == false) { |
| 973 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, |
| 974 | DRAWSTATE_IMAGE_TRANSFER_GRANULARITY, "DS", |
| 975 | "%s: pRegion[%d].%s (x=%d, y=%d, z=%d) must be (x=0, y=0, z=0) " |
| 976 | "when the command buffer's queue family image transfer granularity is (w=0, h=0, d=0).", |
| 977 | function, i, member, offset->x, offset->y, offset->z); |
| 978 | } |
| 979 | } else { |
| 980 | // If the queue family image transfer granularity is not (0, 0, 0), then the offset dimensions must always be even |
| 981 | // integer multiples of the image transfer granularity. |
| 982 | if (IsExtentAligned(&offset_extent, granularity) == false) { |
| 983 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, |
| 984 | DRAWSTATE_IMAGE_TRANSFER_GRANULARITY, "DS", |
| 985 | "%s: pRegion[%d].%s (x=%d, y=%d, z=%d) dimensions must be even integer " |
| 986 | "multiples of this command buffer's queue family image transfer granularity (w=%d, h=%d, d=%d).", |
| 987 | function, i, member, offset->x, offset->y, offset->z, granularity->width, granularity->height, |
| 988 | granularity->depth); |
| 989 | } |
| 990 | } |
| 991 | return skip; |
| 992 | } |
| 993 | |
| 994 | // Check elements of a VkExtent3D structure against a queue family's Image Transfer Granularity values |
| 995 | static inline bool CheckItgExtent(layer_data *device_data, const GLOBAL_CB_NODE *cb_node, const VkExtent3D *extent, |
| 996 | const VkOffset3D *offset, const VkExtent3D *granularity, const VkExtent3D *subresource_extent, |
| 997 | const uint32_t i, const char *function, const char *member) { |
| 998 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 999 | bool skip = false; |
| 1000 | if (IsExtentZero(granularity)) { |
| 1001 | // If the queue family image transfer granularity is (0, 0, 0), then the extent must always match the image |
| 1002 | // subresource extent. |
| 1003 | if (IsExtentEqual(extent, subresource_extent) == false) { |
| 1004 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, |
| 1005 | DRAWSTATE_IMAGE_TRANSFER_GRANULARITY, "DS", |
| 1006 | "%s: pRegion[%d].%s (w=%d, h=%d, d=%d) must match the image subresource extents (w=%d, h=%d, d=%d) " |
| 1007 | "when the command buffer's queue family image transfer granularity is (w=0, h=0, d=0).", |
| 1008 | function, i, member, extent->width, extent->height, extent->depth, subresource_extent->width, |
| 1009 | subresource_extent->height, subresource_extent->depth); |
| 1010 | } |
| 1011 | } else { |
| 1012 | // If the queue family image transfer granularity is not (0, 0, 0), then the extent dimensions must always be even |
| 1013 | // integer multiples of the image transfer granularity or the offset + extent dimensions must always match the image |
| 1014 | // subresource extent dimensions. |
| 1015 | VkExtent3D offset_extent_sum = {}; |
| 1016 | offset_extent_sum.width = static_cast<uint32_t>(abs(offset->x)) + extent->width; |
| 1017 | offset_extent_sum.height = static_cast<uint32_t>(abs(offset->y)) + extent->height; |
| 1018 | offset_extent_sum.depth = static_cast<uint32_t>(abs(offset->z)) + extent->depth; |
| 1019 | if ((IsExtentAligned(extent, granularity) == false) && (IsExtentEqual(&offset_extent_sum, subresource_extent) == false)) { |
| 1020 | skip |= |
| 1021 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, |
| 1022 | DRAWSTATE_IMAGE_TRANSFER_GRANULARITY, "DS", |
| 1023 | "%s: pRegion[%d].%s (w=%d, h=%d, d=%d) dimensions must be even integer multiples of this command buffer's " |
| 1024 | "queue family image transfer granularity (w=%d, h=%d, d=%d) or offset (x=%d, y=%d, z=%d) + " |
| 1025 | "extent (w=%d, h=%d, d=%d) must match the image subresource extents (w=%d, h=%d, d=%d).", |
| 1026 | function, i, member, extent->width, extent->height, extent->depth, granularity->width, granularity->height, |
| 1027 | granularity->depth, offset->x, offset->y, offset->z, extent->width, extent->height, extent->depth, |
| 1028 | subresource_extent->width, subresource_extent->height, subresource_extent->depth); |
| 1029 | } |
| 1030 | } |
| 1031 | return skip; |
| 1032 | } |
| 1033 | |
| 1034 | // Check a uint32_t width or stride value against a queue family's Image Transfer Granularity width value |
| 1035 | static inline bool CheckItgInt(layer_data *device_data, const GLOBAL_CB_NODE *cb_node, const uint32_t value, |
| 1036 | const uint32_t granularity, const uint32_t i, const char *function, const char *member) { |
| 1037 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 1038 | |
| 1039 | bool skip = false; |
| 1040 | if (vk_safe_modulo(value, granularity) != 0) { |
| 1041 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, |
| 1042 | DRAWSTATE_IMAGE_TRANSFER_GRANULARITY, "DS", |
| 1043 | "%s: pRegion[%d].%s (%d) must be an even integer multiple of this command buffer's queue family image " |
| 1044 | "transfer granularity width (%d).", |
| 1045 | function, i, member, value, granularity); |
| 1046 | } |
| 1047 | return skip; |
| 1048 | } |
| 1049 | |
| 1050 | // Check a VkDeviceSize value against a queue family's Image Transfer Granularity width value |
| 1051 | static inline bool CheckItgSize(layer_data *device_data, const GLOBAL_CB_NODE *cb_node, const VkDeviceSize value, |
| 1052 | const uint32_t granularity, const uint32_t i, const char *function, const char *member) { |
| 1053 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 1054 | bool skip = false; |
| 1055 | if (vk_safe_modulo(value, granularity) != 0) { |
| 1056 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, |
| 1057 | DRAWSTATE_IMAGE_TRANSFER_GRANULARITY, "DS", |
| 1058 | "%s: pRegion[%d].%s (%" PRIdLEAST64 |
| 1059 | ") must be an even integer multiple of this command buffer's queue family image transfer " |
| 1060 | "granularity width (%d).", |
| 1061 | function, i, member, value, granularity); |
| 1062 | } |
| 1063 | return skip; |
| 1064 | } |
| 1065 | |
| 1066 | // Check valid usage Image Tranfer Granularity requirements for elements of a VkBufferImageCopy structure |
| 1067 | bool ValidateCopyBufferImageTransferGranularityRequirements(layer_data *device_data, const GLOBAL_CB_NODE *cb_node, |
| 1068 | const IMAGE_STATE *img, const VkBufferImageCopy *region, |
| 1069 | const uint32_t i, const char *function) { |
| 1070 | bool skip = false; |
| 1071 | if (vk_format_is_compressed(img->createInfo.format) == true) { |
| 1072 | // TODO: Add granularity checking for compressed formats |
| 1073 | |
| 1074 | // bufferRowLength must be a multiple of the compressed texel block width |
| 1075 | // bufferImageHeight must be a multiple of the compressed texel block height |
| 1076 | // all members of imageOffset must be a multiple of the corresponding dimensions of the compressed texel block |
| 1077 | // bufferOffset must be a multiple of the compressed texel block size in bytes |
| 1078 | // imageExtent.width must be a multiple of the compressed texel block width or (imageExtent.width + imageOffset.x) |
| 1079 | // must equal the image subresource width |
| 1080 | // imageExtent.height must be a multiple of the compressed texel block height or (imageExtent.height + imageOffset.y) |
| 1081 | // must equal the image subresource height |
| 1082 | // imageExtent.depth must be a multiple of the compressed texel block depth or (imageExtent.depth + imageOffset.z) |
| 1083 | // must equal the image subresource depth |
| 1084 | } else { |
| 1085 | VkExtent3D granularity = GetScaledItg(device_data, cb_node, img); |
| 1086 | skip |= CheckItgSize(device_data, cb_node, region->bufferOffset, granularity.width, i, function, "bufferOffset"); |
| 1087 | skip |= CheckItgInt(device_data, cb_node, region->bufferRowLength, granularity.width, i, function, "bufferRowLength"); |
| 1088 | skip |= CheckItgInt(device_data, cb_node, region->bufferImageHeight, granularity.width, i, function, "bufferImageHeight"); |
| 1089 | skip |= CheckItgOffset(device_data, cb_node, ®ion->imageOffset, &granularity, i, function, "imageOffset"); |
| 1090 | VkExtent3D subresource_extent = GetImageSubresourceExtent(img, ®ion->imageSubresource); |
| 1091 | skip |= CheckItgExtent(device_data, cb_node, ®ion->imageExtent, ®ion->imageOffset, &granularity, &subresource_extent, |
| 1092 | i, function, "imageExtent"); |
| 1093 | } |
| 1094 | return skip; |
| 1095 | } |
| 1096 | |
| 1097 | // Check valid usage Image Tranfer Granularity requirements for elements of a VkImageCopy structure |
| 1098 | bool ValidateCopyImageTransferGranularityRequirements(layer_data *device_data, const GLOBAL_CB_NODE *cb_node, |
| 1099 | const IMAGE_STATE *img, const VkImageCopy *region, const uint32_t i, |
| 1100 | const char *function) { |
| 1101 | bool skip = false; |
| 1102 | VkExtent3D granularity = GetScaledItg(device_data, cb_node, img); |
| 1103 | skip |= CheckItgOffset(device_data, cb_node, ®ion->srcOffset, &granularity, i, function, "srcOffset"); |
| 1104 | skip |= CheckItgOffset(device_data, cb_node, ®ion->dstOffset, &granularity, i, function, "dstOffset"); |
| 1105 | VkExtent3D subresource_extent = GetImageSubresourceExtent(img, ®ion->dstSubresource); |
| 1106 | skip |= CheckItgExtent(device_data, cb_node, ®ion->extent, ®ion->dstOffset, &granularity, &subresource_extent, i, |
| 1107 | function, "extent"); |
| 1108 | return skip; |
| 1109 | } |
| 1110 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 1111 | bool PreCallValidateCmdCopyImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state, |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1112 | IMAGE_STATE *dst_image_state, uint32_t region_count, const VkImageCopy *regions, |
| 1113 | VkImageLayout src_image_layout, VkImageLayout dst_image_layout) { |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1114 | bool skip = false; |
| 1115 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 1116 | VkCommandBuffer command_buffer = cb_node->commandBuffer; |
| 1117 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1118 | for (uint32_t i = 0; i < region_count; i++) { |
| 1119 | if (regions[i].srcSubresource.layerCount == 0) { |
| 1120 | std::stringstream ss; |
| 1121 | ss << "vkCmdCopyImage: number of layers in pRegions[" << i << "] srcSubresource is zero"; |
| 1122 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1123 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", "%s", |
| 1124 | ss.str().c_str()); |
| 1125 | } |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1126 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1127 | if (regions[i].dstSubresource.layerCount == 0) { |
| 1128 | std::stringstream ss; |
| 1129 | ss << "vkCmdCopyImage: number of layers in pRegions[" << i << "] dstSubresource is zero"; |
| 1130 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1131 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", "%s", |
| 1132 | ss.str().c_str()); |
| 1133 | } |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1134 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1135 | // For each region the layerCount member of srcSubresource and dstSubresource must match |
| 1136 | if (regions[i].srcSubresource.layerCount != regions[i].dstSubresource.layerCount) { |
| 1137 | std::stringstream ss; |
| 1138 | ss << "vkCmdCopyImage: number of layers in source and destination subresources for pRegions[" << i << "] do not match"; |
| 1139 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1140 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01198, "IMAGE", "%s. %s", |
| 1141 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01198]); |
| 1142 | } |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1143 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1144 | // For each region, the aspectMask member of srcSubresource and dstSubresource must match |
| 1145 | if (regions[i].srcSubresource.aspectMask != regions[i].dstSubresource.aspectMask) { |
| 1146 | char const str[] = "vkCmdCopyImage: Src and dest aspectMasks for each region must match"; |
| 1147 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1148 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01197, "IMAGE", "%s. %s", str, |
| 1149 | validation_error_map[VALIDATION_ERROR_01197]); |
| 1150 | } |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1151 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1152 | // AspectMask must not contain VK_IMAGE_ASPECT_METADATA_BIT |
| 1153 | if ((regions[i].srcSubresource.aspectMask & VK_IMAGE_ASPECT_METADATA_BIT) || |
| 1154 | (regions[i].dstSubresource.aspectMask & VK_IMAGE_ASPECT_METADATA_BIT)) { |
| 1155 | std::stringstream ss; |
| 1156 | ss << "vkCmdCopyImage: pRegions[" << i << "] may not specify aspectMask containing VK_IMAGE_ASPECT_METADATA_BIT"; |
| 1157 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1158 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01222, "IMAGE", "%s. %s", |
| 1159 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01222]); |
| 1160 | } |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1161 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1162 | // For each region, if aspectMask contains VK_IMAGE_ASPECT_COLOR_BIT, it must not contain either of |
| 1163 | // VK_IMAGE_ASPECT_DEPTH_BIT or VK_IMAGE_ASPECT_STENCIL_BIT |
| 1164 | if ((regions[i].srcSubresource.aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) && |
| 1165 | (regions[i].srcSubresource.aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT))) { |
| 1166 | char const str[] = "vkCmdCopyImage aspectMask cannot specify both COLOR and DEPTH/STENCIL aspects"; |
| 1167 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1168 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01221, "IMAGE", "%s. %s", str, |
| 1169 | validation_error_map[VALIDATION_ERROR_01221]); |
| 1170 | } |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1171 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1172 | // If either of the calling command's src_image or dst_image parameters are of VkImageType VK_IMAGE_TYPE_3D, |
| 1173 | // the baseArrayLayer and layerCount members of both srcSubresource and dstSubresource must be 0 and 1, respectively |
| 1174 | if (((src_image_state->createInfo.imageType == VK_IMAGE_TYPE_3D) || |
| 1175 | (dst_image_state->createInfo.imageType == VK_IMAGE_TYPE_3D)) && |
| 1176 | ((regions[i].srcSubresource.baseArrayLayer != 0) || (regions[i].srcSubresource.layerCount != 1) || |
| 1177 | (regions[i].dstSubresource.baseArrayLayer != 0) || (regions[i].dstSubresource.layerCount != 1))) { |
| 1178 | std::stringstream ss; |
| 1179 | ss << "vkCmdCopyImage: src or dstImage type was IMAGE_TYPE_3D, but in subRegion[" << i |
| 1180 | << "] baseArrayLayer was not zero or layerCount was not 1."; |
| 1181 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1182 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01199, "IMAGE", "%s. %s", |
| 1183 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01199]); |
| 1184 | } |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1185 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1186 | // MipLevel must be less than the mipLevels specified in VkImageCreateInfo when the image was created |
| 1187 | if (regions[i].srcSubresource.mipLevel >= src_image_state->createInfo.mipLevels) { |
| 1188 | std::stringstream ss; |
| 1189 | ss << "vkCmdCopyImage: pRegions[" << i |
| 1190 | << "] specifies a src mipLevel greater than the number specified when the srcImage was created."; |
| 1191 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1192 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01223, "IMAGE", "%s. %s", |
| 1193 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01223]); |
| 1194 | } |
| 1195 | if (regions[i].dstSubresource.mipLevel >= dst_image_state->createInfo.mipLevels) { |
| 1196 | std::stringstream ss; |
| 1197 | ss << "vkCmdCopyImage: pRegions[" << i |
| 1198 | << "] specifies a dst mipLevel greater than the number specified when the dstImage was created."; |
| 1199 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1200 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01223, "IMAGE", "%s. %s", |
| 1201 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01223]); |
| 1202 | } |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1203 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1204 | // (baseArrayLayer + layerCount) must be less than or equal to the arrayLayers specified in VkImageCreateInfo when the |
| 1205 | // image was created |
| 1206 | if ((regions[i].srcSubresource.baseArrayLayer + regions[i].srcSubresource.layerCount) > |
| 1207 | src_image_state->createInfo.arrayLayers) { |
| 1208 | std::stringstream ss; |
| 1209 | ss << "vkCmdCopyImage: srcImage arrayLayers was " << src_image_state->createInfo.arrayLayers << " but subRegion[" << i |
| 1210 | << "] baseArrayLayer + layerCount is " |
| 1211 | << (regions[i].srcSubresource.baseArrayLayer + regions[i].srcSubresource.layerCount); |
| 1212 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1213 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01224, "IMAGE", "%s. %s", |
| 1214 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01224]); |
| 1215 | } |
| 1216 | if ((regions[i].dstSubresource.baseArrayLayer + regions[i].dstSubresource.layerCount) > |
| 1217 | dst_image_state->createInfo.arrayLayers) { |
| 1218 | std::stringstream ss; |
| 1219 | ss << "vkCmdCopyImage: dstImage arrayLayers was " << dst_image_state->createInfo.arrayLayers << " but subRegion[" << i |
| 1220 | << "] baseArrayLayer + layerCount is " |
| 1221 | << (regions[i].dstSubresource.baseArrayLayer + regions[i].dstSubresource.layerCount); |
| 1222 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1223 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01224, "IMAGE", "%s. %s", |
| 1224 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01224]); |
| 1225 | } |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1226 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1227 | // The source region specified by a given element of regions must be a region that is contained within srcImage |
| 1228 | if (ExceedsBounds(®ions[i].srcOffset, ®ions[i].extent, src_image_state)) { |
| 1229 | std::stringstream ss; |
| 1230 | ss << "vkCmdCopyImage: srcSubResource in pRegions[" << i << "] exceeds extents srcImage was created with"; |
| 1231 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1232 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01175, "IMAGE", "%s. %s", |
| 1233 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01175]); |
| 1234 | } |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1235 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1236 | // The destination region specified by a given element of regions must be a region that is contained within dst_image |
| 1237 | if (ExceedsBounds(®ions[i].dstOffset, ®ions[i].extent, dst_image_state)) { |
| 1238 | std::stringstream ss; |
| 1239 | ss << "vkCmdCopyImage: dstSubResource in pRegions[" << i << "] exceeds extents dstImage was created with"; |
| 1240 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1241 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01176, "IMAGE", "%s. %s", |
| 1242 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01176]); |
| 1243 | } |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1244 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1245 | // The union of all source regions, and the union of all destination regions, specified by the elements of regions, |
| 1246 | // must not overlap in memory |
| 1247 | if (src_image_state->image == dst_image_state->image) { |
| 1248 | for (uint32_t j = 0; j < region_count; j++) { |
| 1249 | if (RegionIntersects(®ions[i], ®ions[j], src_image_state->createInfo.imageType)) { |
| 1250 | std::stringstream ss; |
| 1251 | ss << "vkCmdCopyImage: pRegions[" << i << "] src overlaps with pRegions[" << j << "]."; |
| 1252 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1253 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01177, "IMAGE", |
| 1254 | "%s. %s", ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01177]); |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1255 | } |
| 1256 | } |
| 1257 | } |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1258 | } |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1259 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1260 | // The formats of src_image and dst_image must be compatible. Formats are considered compatible if their texel size in bytes |
| 1261 | // is the same between both formats. For example, VK_FORMAT_R8G8B8A8_UNORM is compatible with VK_FORMAT_R32_UINT because |
| 1262 | // because both texels are 4 bytes in size. Depth/stencil formats must match exactly. |
| 1263 | if (vk_format_is_depth_or_stencil(src_image_state->createInfo.format) || |
| 1264 | vk_format_is_depth_or_stencil(dst_image_state->createInfo.format)) { |
| 1265 | if (src_image_state->createInfo.format != dst_image_state->createInfo.format) { |
| 1266 | char const str[] = "vkCmdCopyImage called with unmatched source and dest image depth/stencil formats."; |
| 1267 | skip |= |
| 1268 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1269 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_FORMAT, "IMAGE", str); |
| 1270 | } |
| 1271 | } else { |
| 1272 | size_t srcSize = vk_format_get_size(src_image_state->createInfo.format); |
| 1273 | size_t destSize = vk_format_get_size(dst_image_state->createInfo.format); |
| 1274 | if (srcSize != destSize) { |
| 1275 | char const str[] = "vkCmdCopyImage called with unmatched source and dest image format sizes."; |
| 1276 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1277 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01184, "IMAGE", "%s. %s", str, |
| 1278 | validation_error_map[VALIDATION_ERROR_01184]); |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1279 | } |
| 1280 | } |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1281 | |
| 1282 | skip |= ValidateMemoryIsBoundToImage(device_data, src_image_state, "vkCmdCopyImage()", VALIDATION_ERROR_02533); |
| 1283 | skip |= ValidateMemoryIsBoundToImage(device_data, dst_image_state, "vkCmdCopyImage()", VALIDATION_ERROR_02534); |
| 1284 | // Validate that SRC & DST images have correct usage flags set |
| 1285 | skip |= ValidateImageUsageFlags(device_data, src_image_state, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, true, VALIDATION_ERROR_01178, |
| 1286 | "vkCmdCopyImage()", "VK_IMAGE_USAGE_TRANSFER_SRC_BIT"); |
| 1287 | skip |= ValidateImageUsageFlags(device_data, dst_image_state, VK_IMAGE_USAGE_TRANSFER_DST_BIT, true, VALIDATION_ERROR_01181, |
| 1288 | "vkCmdCopyImage()", "VK_IMAGE_USAGE_TRANSFER_DST_BIT"); |
| 1289 | skip |= ValidateCmd(device_data, cb_node, CMD_COPYIMAGE, "vkCmdCopyImage()"); |
| 1290 | skip |= insideRenderPass(device_data, cb_node, "vkCmdCopyImage()", VALIDATION_ERROR_01194); |
| 1291 | for (uint32_t i = 0; i < region_count; ++i) { |
| 1292 | skip |= VerifySourceImageLayout(device_data, cb_node, src_image_state->image, regions[i].srcSubresource, src_image_layout, |
| 1293 | VALIDATION_ERROR_01180); |
| 1294 | skip |= VerifyDestImageLayout(device_data, cb_node, dst_image_state->image, regions[i].dstSubresource, dst_image_layout, |
| 1295 | VALIDATION_ERROR_01183); |
| 1296 | skip |= ValidateCopyImageTransferGranularityRequirements(device_data, cb_node, dst_image_state, ®ions[i], i, |
| 1297 | "vkCmdCopyImage()"); |
| 1298 | } |
| 1299 | |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1300 | return skip; |
| 1301 | } |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1302 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1303 | void PreCallRecordCmdCopyImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state, |
| 1304 | IMAGE_STATE *dst_image_state) { |
| 1305 | // Update bindings between images and cmd buffer |
| 1306 | AddCommandBufferBindingImage(device_data, cb_node, src_image_state); |
| 1307 | AddCommandBufferBindingImage(device_data, cb_node, dst_image_state); |
| 1308 | std::function<bool()> function = [=]() { |
| 1309 | return ValidateImageMemoryIsValid(device_data, src_image_state, "vkCmdCopyImage()"); |
| 1310 | }; |
| 1311 | cb_node->validate_functions.push_back(function); |
| 1312 | function = [=]() { |
| 1313 | SetImageMemoryValid(device_data, dst_image_state, true); |
| 1314 | return false; |
| 1315 | }; |
| 1316 | cb_node->validate_functions.push_back(function); |
| 1317 | core_validation::UpdateCmdBufferLastCmd(cb_node, CMD_COPYIMAGE); |
| 1318 | } |
| 1319 | |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1320 | // TODO : Should be tracking lastBound per commandBuffer and when draws occur, report based on that cmd buffer lastBound |
| 1321 | // Then need to synchronize the accesses based on cmd buffer so that if I'm reading state on one cmd buffer, updates |
| 1322 | // to that same cmd buffer by separate thread are not changing state from underneath us |
| 1323 | // Track the last cmd buffer touched by this thread |
| 1324 | static bool hasDrawCmd(GLOBAL_CB_NODE *pCB) { |
| 1325 | for (uint32_t i = 0; i < NUM_DRAW_TYPES; i++) { |
| 1326 | if (pCB->drawCount[i]) return true; |
| 1327 | } |
| 1328 | return false; |
| 1329 | } |
| 1330 | |
| 1331 | // Returns true if sub_rect is entirely contained within rect |
| 1332 | static inline bool ContainsRect(VkRect2D rect, VkRect2D sub_rect) { |
| 1333 | if ((sub_rect.offset.x < rect.offset.x) || (sub_rect.offset.x + sub_rect.extent.width > rect.offset.x + rect.extent.width) || |
| 1334 | (sub_rect.offset.y < rect.offset.y) || (sub_rect.offset.y + sub_rect.extent.height > rect.offset.y + rect.extent.height)) |
| 1335 | return false; |
| 1336 | return true; |
| 1337 | } |
| 1338 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 1339 | bool PreCallValidateCmdClearAttachments(layer_data *device_data, VkCommandBuffer commandBuffer, uint32_t attachmentCount, |
| 1340 | const VkClearAttachment *pAttachments, uint32_t rectCount, const VkClearRect *pRects) { |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 1341 | GLOBAL_CB_NODE *cb_node = GetCBNode(device_data, commandBuffer); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1342 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 1343 | |
| 1344 | bool skip = false; |
| 1345 | if (cb_node) { |
| 1346 | skip |= ValidateCmd(device_data, cb_node, CMD_CLEARATTACHMENTS, "vkCmdClearAttachments()"); |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 1347 | core_validation::UpdateCmdBufferLastCmd(cb_node, CMD_CLEARATTACHMENTS); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1348 | // Warn if this is issued prior to Draw Cmd and clearing the entire attachment |
| 1349 | if (!hasDrawCmd(cb_node) && (cb_node->activeRenderPassBeginInfo.renderArea.extent.width == pRects[0].rect.extent.width) && |
| 1350 | (cb_node->activeRenderPassBeginInfo.renderArea.extent.height == pRects[0].rect.extent.height)) { |
| 1351 | // There are times where app needs to use ClearAttachments (generally when reusing a buffer inside of a render pass) |
| 1352 | // Can we make this warning more specific? I'd like to avoid triggering this test if we can tell it's a use that must |
| 1353 | // call CmdClearAttachments. Otherwise this seems more like a performance warning. |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 1354 | skip |= |
| 1355 | log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1356 | reinterpret_cast<uint64_t &>(commandBuffer), 0, DRAWSTATE_CLEAR_CMD_BEFORE_DRAW, "DS", |
| 1357 | "vkCmdClearAttachments() issued on command buffer object 0x%p prior to any Draw Cmds." |
| 1358 | " It is recommended you use RenderPass LOAD_OP_CLEAR on Attachments prior to any Draw.", |
| 1359 | commandBuffer); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1360 | } |
| 1361 | skip |= outsideRenderPass(device_data, cb_node, "vkCmdClearAttachments()", VALIDATION_ERROR_01122); |
| 1362 | } |
| 1363 | |
| 1364 | // Validate that attachment is in reference list of active subpass |
| 1365 | if (cb_node->activeRenderPass) { |
| 1366 | const VkRenderPassCreateInfo *renderpass_create_info = cb_node->activeRenderPass->createInfo.ptr(); |
| 1367 | const VkSubpassDescription *subpass_desc = &renderpass_create_info->pSubpasses[cb_node->activeSubpass]; |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 1368 | auto framebuffer = GetFramebufferState(device_data, cb_node->activeFramebuffer); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1369 | |
| 1370 | for (uint32_t i = 0; i < attachmentCount; i++) { |
| 1371 | auto clear_desc = &pAttachments[i]; |
| 1372 | VkImageView image_view = VK_NULL_HANDLE; |
| 1373 | |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 1374 | if (0 == clear_desc->aspectMask) { |
| 1375 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1376 | (uint64_t)commandBuffer, __LINE__, VALIDATION_ERROR_01128, "IMAGE", "%s", |
| 1377 | validation_error_map[VALIDATION_ERROR_01128]); |
| 1378 | } else if (clear_desc->aspectMask & VK_IMAGE_ASPECT_METADATA_BIT) { |
| 1379 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1380 | (uint64_t)commandBuffer, __LINE__, VALIDATION_ERROR_01126, "IMAGE", "%s", |
| 1381 | validation_error_map[VALIDATION_ERROR_01126]); |
| 1382 | } else if (clear_desc->aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) { |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1383 | if (clear_desc->colorAttachment >= subpass_desc->colorAttachmentCount) { |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 1384 | skip |= |
| 1385 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1386 | (uint64_t)commandBuffer, __LINE__, VALIDATION_ERROR_01114, "DS", |
| 1387 | "vkCmdClearAttachments() color attachment index %d out of range for active subpass %d. %s", |
| 1388 | clear_desc->colorAttachment, cb_node->activeSubpass, validation_error_map[VALIDATION_ERROR_01114]); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1389 | } else if (subpass_desc->pColorAttachments[clear_desc->colorAttachment].attachment == VK_ATTACHMENT_UNUSED) { |
| 1390 | skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 1391 | VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer, __LINE__, |
| 1392 | DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS", |
| 1393 | "vkCmdClearAttachments() color attachment index %d is VK_ATTACHMENT_UNUSED; ignored.", |
| 1394 | clear_desc->colorAttachment); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1395 | } else { |
| 1396 | image_view = framebuffer->createInfo |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 1397 | .pAttachments[subpass_desc->pColorAttachments[clear_desc->colorAttachment].attachment]; |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1398 | } |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 1399 | if ((clear_desc->aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) || |
| 1400 | (clear_desc->aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT)) { |
| 1401 | char const str[] = |
| 1402 | "vkCmdClearAttachments aspectMask [%d] must set only VK_IMAGE_ASPECT_COLOR_BIT of a color attachment. %s"; |
| 1403 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1404 | (uint64_t)commandBuffer, __LINE__, VALIDATION_ERROR_01125, "IMAGE", str, i, |
| 1405 | validation_error_map[VALIDATION_ERROR_01125]); |
| 1406 | } |
| 1407 | } else { // Must be depth and/or stencil |
| 1408 | if (((clear_desc->aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) != VK_IMAGE_ASPECT_DEPTH_BIT) && |
| 1409 | ((clear_desc->aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) != VK_IMAGE_ASPECT_STENCIL_BIT)) { |
| 1410 | char const str[] = "vkCmdClearAttachments aspectMask [%d] is not a valid combination of bits. %s"; |
| 1411 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1412 | (uint64_t)commandBuffer, __LINE__, VALIDATION_ERROR_01127, "IMAGE", str, i, |
| 1413 | validation_error_map[VALIDATION_ERROR_01127]); |
| 1414 | } |
| 1415 | if (!subpass_desc->pDepthStencilAttachment || |
| 1416 | (subpass_desc->pDepthStencilAttachment->attachment == VK_ATTACHMENT_UNUSED)) { |
| 1417 | skip |= log_msg( |
| 1418 | report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1419 | (uint64_t)commandBuffer, __LINE__, DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS", |
| 1420 | "vkCmdClearAttachments() depth/stencil clear with no depth/stencil attachment in subpass; ignored"); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1421 | } else { |
| 1422 | image_view = framebuffer->createInfo.pAttachments[subpass_desc->pDepthStencilAttachment->attachment]; |
| 1423 | } |
| 1424 | } |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1425 | if (image_view) { |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 1426 | auto image_view_state = GetImageViewState(device_data, image_view); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1427 | for (uint32_t j = 0; j < rectCount; j++) { |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 1428 | // The rectangular region specified by a given element of pRects must be contained within the render area of |
| 1429 | // the current render pass instance |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1430 | if (false == ContainsRect(cb_node->activeRenderPassBeginInfo.renderArea, pRects[j].rect)) { |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 1431 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 1432 | __LINE__, VALIDATION_ERROR_01115, "DS", |
| 1433 | "vkCmdClearAttachments(): The area defined by pRects[%d] is not contained in the area of " |
| 1434 | "the current render pass instance. %s", |
| 1435 | j, validation_error_map[VALIDATION_ERROR_01115]); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1436 | } |
| 1437 | // The layers specified by a given element of pRects must be contained within every attachment that |
| 1438 | // pAttachments refers to |
| 1439 | auto attachment_base_array_layer = image_view_state->create_info.subresourceRange.baseArrayLayer; |
| 1440 | auto attachment_layer_count = image_view_state->create_info.subresourceRange.layerCount; |
| 1441 | if ((pRects[j].baseArrayLayer < attachment_base_array_layer) || pRects[j].layerCount > attachment_layer_count) { |
| 1442 | skip |= |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 1443 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 1444 | __LINE__, VALIDATION_ERROR_01116, "DS", |
| 1445 | "vkCmdClearAttachments(): The layers defined in pRects[%d] are not contained in the layers of " |
| 1446 | "pAttachment[%d]. %s", |
| 1447 | j, i, validation_error_map[VALIDATION_ERROR_01116]); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1448 | } |
| 1449 | } |
| 1450 | } |
| 1451 | } |
| 1452 | } |
| 1453 | return skip; |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 1454 | } |
| 1455 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 1456 | bool PreCallValidateCmdResolveImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state, |
Mark Lobodzinski | 50fbef1 | 2017-02-06 15:31:33 -0700 | [diff] [blame] | 1457 | IMAGE_STATE *dst_image_state, uint32_t regionCount, const VkImageResolve *pRegions) { |
Mark Lobodzinski | 2a3368e | 2017-02-06 15:29:37 -0700 | [diff] [blame] | 1458 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 1459 | bool skip = false; |
| 1460 | if (cb_node && src_image_state && dst_image_state) { |
| 1461 | skip |= ValidateMemoryIsBoundToImage(device_data, src_image_state, "vkCmdResolveImage()", VALIDATION_ERROR_02541); |
| 1462 | skip |= ValidateMemoryIsBoundToImage(device_data, dst_image_state, "vkCmdResolveImage()", VALIDATION_ERROR_02542); |
| 1463 | skip |= ValidateCmd(device_data, cb_node, CMD_RESOLVEIMAGE, "vkCmdResolveImage()"); |
| 1464 | skip |= insideRenderPass(device_data, cb_node, "vkCmdResolveImage()", VALIDATION_ERROR_01335); |
Mark Lobodzinski | 2a3368e | 2017-02-06 15:29:37 -0700 | [diff] [blame] | 1465 | |
| 1466 | // For each region, the number of layers in the image subresource should not be zero |
| 1467 | // For each region, src and dest image aspect must be color only |
| 1468 | for (uint32_t i = 0; i < regionCount; i++) { |
| 1469 | if (pRegions[i].srcSubresource.layerCount == 0) { |
| 1470 | char const str[] = "vkCmdResolveImage: number of layers in source subresource is zero"; |
Mark Lobodzinski | 50fbef1 | 2017-02-06 15:31:33 -0700 | [diff] [blame] | 1471 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 2a3368e | 2017-02-06 15:29:37 -0700 | [diff] [blame] | 1472 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_ASPECT, |
| 1473 | "IMAGE", str); |
| 1474 | } |
Mark Lobodzinski | 2a3368e | 2017-02-06 15:29:37 -0700 | [diff] [blame] | 1475 | if (pRegions[i].dstSubresource.layerCount == 0) { |
| 1476 | char const str[] = "vkCmdResolveImage: number of layers in destination subresource is zero"; |
Mark Lobodzinski | 50fbef1 | 2017-02-06 15:31:33 -0700 | [diff] [blame] | 1477 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 2a3368e | 2017-02-06 15:29:37 -0700 | [diff] [blame] | 1478 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_ASPECT, |
| 1479 | "IMAGE", str); |
| 1480 | } |
Mark Lobodzinski | 50fbef1 | 2017-02-06 15:31:33 -0700 | [diff] [blame] | 1481 | if (pRegions[i].srcSubresource.layerCount != pRegions[i].dstSubresource.layerCount) { |
| 1482 | skip |= log_msg( |
| 1483 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1484 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_01339, "IMAGE", |
| 1485 | "vkCmdResolveImage: layerCount in source and destination subresource of pRegions[%d] does not match. %s", i, |
| 1486 | validation_error_map[VALIDATION_ERROR_01339]); |
| 1487 | } |
Mark Lobodzinski | 2a3368e | 2017-02-06 15:29:37 -0700 | [diff] [blame] | 1488 | if ((pRegions[i].srcSubresource.aspectMask != VK_IMAGE_ASPECT_COLOR_BIT) || |
| 1489 | (pRegions[i].dstSubresource.aspectMask != VK_IMAGE_ASPECT_COLOR_BIT)) { |
| 1490 | char const str[] = |
| 1491 | "vkCmdResolveImage: src and dest aspectMasks for each region must specify only VK_IMAGE_ASPECT_COLOR_BIT"; |
| 1492 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1493 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_01338, "IMAGE", |
| 1494 | "%s. %s", str, validation_error_map[VALIDATION_ERROR_01338]); |
| 1495 | } |
| 1496 | } |
| 1497 | |
| 1498 | if (src_image_state->createInfo.format != dst_image_state->createInfo.format) { |
| 1499 | char const str[] = "vkCmdResolveImage called with unmatched source and dest formats."; |
Mark Lobodzinski | 50fbef1 | 2017-02-06 15:31:33 -0700 | [diff] [blame] | 1500 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 2a3368e | 2017-02-06 15:29:37 -0700 | [diff] [blame] | 1501 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_FORMAT, |
| 1502 | "IMAGE", str); |
| 1503 | } |
| 1504 | if (src_image_state->createInfo.imageType != dst_image_state->createInfo.imageType) { |
| 1505 | char const str[] = "vkCmdResolveImage called with unmatched source and dest image types."; |
Mark Lobodzinski | 50fbef1 | 2017-02-06 15:31:33 -0700 | [diff] [blame] | 1506 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 2a3368e | 2017-02-06 15:29:37 -0700 | [diff] [blame] | 1507 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_TYPE, "IMAGE", |
| 1508 | str); |
| 1509 | } |
| 1510 | if (src_image_state->createInfo.samples == VK_SAMPLE_COUNT_1_BIT) { |
| 1511 | char const str[] = "vkCmdResolveImage called with source sample count less than 2."; |
| 1512 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1513 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_01320, "IMAGE", "%s. %s", |
| 1514 | str, validation_error_map[VALIDATION_ERROR_01320]); |
| 1515 | } |
| 1516 | if (dst_image_state->createInfo.samples != VK_SAMPLE_COUNT_1_BIT) { |
| 1517 | char const str[] = "vkCmdResolveImage called with dest sample count greater than 1."; |
| 1518 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1519 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_01321, "IMAGE", "%s. %s", |
| 1520 | str, validation_error_map[VALIDATION_ERROR_01321]); |
| 1521 | } |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 1522 | } else { |
| 1523 | assert(0); |
| 1524 | } |
| 1525 | return skip; |
| 1526 | } |
| 1527 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 1528 | void PreCallRecordCmdResolveImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state, |
| 1529 | IMAGE_STATE *dst_image_state) { |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 1530 | // Update bindings between images and cmd buffer |
| 1531 | AddCommandBufferBindingImage(device_data, cb_node, src_image_state); |
| 1532 | AddCommandBufferBindingImage(device_data, cb_node, dst_image_state); |
| 1533 | |
| 1534 | std::function<bool()> function = [=]() { |
| 1535 | return ValidateImageMemoryIsValid(device_data, src_image_state, "vkCmdResolveImage()"); |
| 1536 | }; |
| 1537 | cb_node->validate_functions.push_back(function); |
| 1538 | function = [=]() { |
| 1539 | SetImageMemoryValid(device_data, dst_image_state, true); |
| 1540 | return false; |
| 1541 | }; |
| 1542 | cb_node->validate_functions.push_back(function); |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 1543 | core_validation::UpdateCmdBufferLastCmd(cb_node, CMD_RESOLVEIMAGE); |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 1544 | } |
| 1545 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 1546 | bool PreCallValidateCmdBlitImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state, |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 1547 | IMAGE_STATE *dst_image_state, uint32_t regionCount, const VkImageBlit *pRegions, VkFilter filter) { |
| 1548 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 1549 | |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 1550 | bool skip = false; |
| 1551 | if (cb_node && src_image_state && dst_image_state) { |
| 1552 | skip |= ValidateImageSampleCount(device_data, src_image_state, VK_SAMPLE_COUNT_1_BIT, "vkCmdBlitImage(): srcImage", |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 1553 | VALIDATION_ERROR_02194); |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 1554 | skip |= ValidateImageSampleCount(device_data, dst_image_state, VK_SAMPLE_COUNT_1_BIT, "vkCmdBlitImage(): dstImage", |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 1555 | VALIDATION_ERROR_02195); |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 1556 | skip |= ValidateMemoryIsBoundToImage(device_data, src_image_state, "vkCmdBlitImage()", VALIDATION_ERROR_02539); |
| 1557 | skip |= ValidateMemoryIsBoundToImage(device_data, dst_image_state, "vkCmdBlitImage()", VALIDATION_ERROR_02540); |
| 1558 | skip |= ValidateImageUsageFlags(device_data, src_image_state, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, true, VALIDATION_ERROR_02182, |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 1559 | "vkCmdBlitImage()", "VK_IMAGE_USAGE_TRANSFER_SRC_BIT"); |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 1560 | skip |= ValidateImageUsageFlags(device_data, dst_image_state, VK_IMAGE_USAGE_TRANSFER_DST_BIT, true, VALIDATION_ERROR_02186, |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 1561 | "vkCmdBlitImage()", "VK_IMAGE_USAGE_TRANSFER_DST_BIT"); |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 1562 | skip |= ValidateCmd(device_data, cb_node, CMD_BLITIMAGE, "vkCmdBlitImage()"); |
| 1563 | skip |= insideRenderPass(device_data, cb_node, "vkCmdBlitImage()", VALIDATION_ERROR_01300); |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 1564 | |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 1565 | for (uint32_t i = 0; i < regionCount; i++) { |
Mark Lobodzinski | 23c8114 | 2017-02-06 15:04:23 -0700 | [diff] [blame] | 1566 | |
| 1567 | // Warn for zero-sized regions |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 1568 | if ((pRegions[i].srcOffsets[0].x == pRegions[i].srcOffsets[1].x) || |
| 1569 | (pRegions[i].srcOffsets[0].y == pRegions[i].srcOffsets[1].y) || |
| 1570 | (pRegions[i].srcOffsets[0].z == pRegions[i].srcOffsets[1].z)) { |
| 1571 | std::stringstream ss; |
| 1572 | ss << "vkCmdBlitImage: pRegions[" << i << "].srcOffsets specify a zero-volume area."; |
| 1573 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1574 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_INVALID_EXTENTS, "IMAGE", |
| 1575 | "%s", ss.str().c_str()); |
| 1576 | } |
| 1577 | if ((pRegions[i].dstOffsets[0].x == pRegions[i].dstOffsets[1].x) || |
| 1578 | (pRegions[i].dstOffsets[0].y == pRegions[i].dstOffsets[1].y) || |
| 1579 | (pRegions[i].dstOffsets[0].z == pRegions[i].dstOffsets[1].z)) { |
| 1580 | std::stringstream ss; |
| 1581 | ss << "vkCmdBlitImage: pRegions[" << i << "].dstOffsets specify a zero-volume area."; |
| 1582 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1583 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_INVALID_EXTENTS, "IMAGE", |
| 1584 | "%s", ss.str().c_str()); |
| 1585 | } |
Mark Lobodzinski | 23c8114 | 2017-02-06 15:04:23 -0700 | [diff] [blame] | 1586 | if (pRegions[i].srcSubresource.layerCount == 0) { |
| 1587 | char const str[] = "vkCmdBlitImage: number of layers in source subresource is zero"; |
| 1588 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1589 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_ASPECT, |
| 1590 | "IMAGE", str); |
| 1591 | } |
| 1592 | if (pRegions[i].dstSubresource.layerCount == 0) { |
| 1593 | char const str[] = "vkCmdBlitImage: number of layers in destination subresource is zero"; |
| 1594 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1595 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_ASPECT, |
| 1596 | "IMAGE", str); |
| 1597 | } |
| 1598 | |
| 1599 | // Check that src/dst layercounts match |
| 1600 | if (pRegions[i].srcSubresource.layerCount != pRegions[i].dstSubresource.layerCount) { |
| 1601 | skip |= |
| 1602 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1603 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_01304, "IMAGE", |
| 1604 | "vkCmdBlitImage: layerCount in source and destination subresource of pRegions[%d] does not match. %s", |
| 1605 | i, validation_error_map[VALIDATION_ERROR_01304]); |
| 1606 | } |
Mark Lobodzinski | e7e85fd | 2017-02-07 13:44:57 -0700 | [diff] [blame] | 1607 | |
| 1608 | if (pRegions[i].srcSubresource.aspectMask != pRegions[i].dstSubresource.aspectMask) { |
| 1609 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1610 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_01303, "IMAGE", |
| 1611 | "vkCmdBlitImage: aspectMask members for pRegion[%d] do not match. %s", i, |
| 1612 | validation_error_map[VALIDATION_ERROR_01303]); |
| 1613 | } |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 1614 | } |
| 1615 | |
| 1616 | VkFormat src_format = src_image_state->createInfo.format; |
| 1617 | VkFormat dst_format = dst_image_state->createInfo.format; |
| 1618 | |
| 1619 | // Validate consistency for unsigned formats |
| 1620 | if (vk_format_is_uint(src_format) != vk_format_is_uint(dst_format)) { |
| 1621 | std::stringstream ss; |
| 1622 | ss << "vkCmdBlitImage: If one of srcImage and dstImage images has unsigned integer format, " |
| 1623 | << "the other one must also have unsigned integer format. " |
| 1624 | << "Source format is " << string_VkFormat(src_format) << " Destination format is " << string_VkFormat(dst_format); |
| 1625 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1626 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_02191, "IMAGE", "%s. %s", |
| 1627 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_02191]); |
| 1628 | } |
| 1629 | |
| 1630 | // Validate consistency for signed formats |
| 1631 | if (vk_format_is_sint(src_format) != vk_format_is_sint(dst_format)) { |
| 1632 | std::stringstream ss; |
| 1633 | ss << "vkCmdBlitImage: If one of srcImage and dstImage images has signed integer format, " |
| 1634 | << "the other one must also have signed integer format. " |
| 1635 | << "Source format is " << string_VkFormat(src_format) << " Destination format is " << string_VkFormat(dst_format); |
| 1636 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1637 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_02190, "IMAGE", "%s. %s", |
| 1638 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_02190]); |
| 1639 | } |
| 1640 | |
| 1641 | // Validate aspect bits and formats for depth/stencil images |
| 1642 | if (vk_format_is_depth_or_stencil(src_format) || vk_format_is_depth_or_stencil(dst_format)) { |
Mark Lobodzinski | 23c8114 | 2017-02-06 15:04:23 -0700 | [diff] [blame] | 1643 | |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 1644 | if (src_format != dst_format) { |
| 1645 | std::stringstream ss; |
| 1646 | ss << "vkCmdBlitImage: If one of srcImage and dstImage images has a format of depth, stencil or depth " |
| 1647 | << "stencil, the other one must have exactly the same format. " |
| 1648 | << "Source format is " << string_VkFormat(src_format) << " Destination format is " |
| 1649 | << string_VkFormat(dst_format); |
| 1650 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1651 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_02192, "IMAGE", |
| 1652 | "%s. %s", ss.str().c_str(), validation_error_map[VALIDATION_ERROR_02192]); |
| 1653 | } |
| 1654 | |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 1655 | for (uint32_t i = 0; i < regionCount; i++) { |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 1656 | VkImageAspectFlags srcAspect = pRegions[i].srcSubresource.aspectMask; |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 1657 | |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 1658 | if (vk_format_is_depth_and_stencil(src_format)) { |
| 1659 | if ((srcAspect != VK_IMAGE_ASPECT_DEPTH_BIT) && (srcAspect != VK_IMAGE_ASPECT_STENCIL_BIT)) { |
| 1660 | std::stringstream ss; |
| 1661 | ss << "vkCmdBlitImage: Combination depth/stencil image formats must have only one of " |
| 1662 | "VK_IMAGE_ASPECT_DEPTH_BIT " |
| 1663 | << "and VK_IMAGE_ASPECT_STENCIL_BIT set in srcImage and dstImage"; |
| 1664 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1665 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, |
| 1666 | DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", "%s", ss.str().c_str()); |
| 1667 | } |
| 1668 | } else if (vk_format_is_stencil_only(src_format)) { |
| 1669 | if (srcAspect != VK_IMAGE_ASPECT_STENCIL_BIT) { |
| 1670 | std::stringstream ss; |
| 1671 | ss << "vkCmdBlitImage: Stencil-only image formats must have only the VK_IMAGE_ASPECT_STENCIL_BIT " |
| 1672 | << "set in both the srcImage and dstImage"; |
| 1673 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1674 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, |
| 1675 | DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", "%s", ss.str().c_str()); |
| 1676 | } |
| 1677 | } else if (vk_format_is_depth_only(src_format)) { |
| 1678 | if (srcAspect != VK_IMAGE_ASPECT_DEPTH_BIT) { |
| 1679 | std::stringstream ss; |
| 1680 | ss << "vkCmdBlitImage: Depth-only image formats must have only the VK_IMAGE_ASPECT_DEPTH " |
| 1681 | << "set in both the srcImage and dstImage"; |
| 1682 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1683 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, |
| 1684 | DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", "%s", ss.str().c_str()); |
| 1685 | } |
| 1686 | } |
| 1687 | } |
| 1688 | } |
| 1689 | |
| 1690 | // Validate filter |
| 1691 | if (vk_format_is_depth_or_stencil(src_format) && (filter != VK_FILTER_NEAREST)) { |
| 1692 | std::stringstream ss; |
| 1693 | ss << "vkCmdBlitImage: If the format of srcImage is a depth, stencil, or depth stencil " |
| 1694 | << "then filter must be VK_FILTER_NEAREST."; |
| 1695 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1696 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_02193, "IMAGE", "%s. %s", |
| 1697 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_02193]); |
| 1698 | } |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 1699 | } else { |
| 1700 | assert(0); |
| 1701 | } |
| 1702 | return skip; |
| 1703 | } |
| 1704 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 1705 | void PreCallRecordCmdBlitImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state, |
| 1706 | IMAGE_STATE *dst_image_state) { |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 1707 | // Update bindings between images and cmd buffer |
| 1708 | AddCommandBufferBindingImage(device_data, cb_node, src_image_state); |
| 1709 | AddCommandBufferBindingImage(device_data, cb_node, dst_image_state); |
| 1710 | |
| 1711 | std::function<bool()> function = [=]() { return ValidateImageMemoryIsValid(device_data, src_image_state, "vkCmdBlitImage()"); }; |
| 1712 | cb_node->validate_functions.push_back(function); |
| 1713 | function = [=]() { |
| 1714 | SetImageMemoryValid(device_data, dst_image_state, true); |
| 1715 | return false; |
| 1716 | }; |
| 1717 | cb_node->validate_functions.push_back(function); |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 1718 | core_validation::UpdateCmdBufferLastCmd(cb_node, CMD_BLITIMAGE); |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 1719 | } |
| 1720 | |
Mark Lobodzinski | b0dd947 | 2017-02-07 16:38:17 -0700 | [diff] [blame] | 1721 | // This validates that the initial layout specified in the command buffer for the IMAGE is the same as the global IMAGE layout |
| 1722 | bool ValidateCmdBufImageLayouts(core_validation::layer_data *device_data, GLOBAL_CB_NODE *pCB) { |
| 1723 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 1724 | bool skip = false; |
Mark Lobodzinski | 4a3065e | 2017-02-07 16:36:03 -0700 | [diff] [blame] | 1725 | for (auto cb_image_data : pCB->imageLayoutMap) { |
| 1726 | VkImageLayout imageLayout; |
Mark Lobodzinski | b0dd947 | 2017-02-07 16:38:17 -0700 | [diff] [blame] | 1727 | if (!FindGlobalLayout(device_data, cb_image_data.first, imageLayout)) { |
| 1728 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__, |
| 1729 | DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", "Cannot submit cmd buffer using deleted image 0x%" PRIx64 ".", |
| 1730 | reinterpret_cast<const uint64_t &>(cb_image_data.first)); |
Mark Lobodzinski | 4a3065e | 2017-02-07 16:36:03 -0700 | [diff] [blame] | 1731 | } else { |
| 1732 | if (cb_image_data.second.initialLayout == VK_IMAGE_LAYOUT_UNDEFINED) { |
| 1733 | // TODO: Set memory invalid which is in mem_tracker currently |
| 1734 | } else if (imageLayout != cb_image_data.second.initialLayout) { |
| 1735 | if (cb_image_data.first.hasSubresource) { |
Mark Lobodzinski | b0dd947 | 2017-02-07 16:38:17 -0700 | [diff] [blame] | 1736 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1737 | reinterpret_cast<uint64_t &>(pCB->commandBuffer), __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, |
| 1738 | "DS", "Cannot submit cmd buffer using image (0x%" PRIx64 |
| 1739 | ") [sub-resource: aspectMask 0x%X array layer %u, mip level %u], " |
| 1740 | "with layout %s when first use is %s.", |
| 1741 | reinterpret_cast<const uint64_t &>(cb_image_data.first.image), |
| 1742 | cb_image_data.first.subresource.aspectMask, cb_image_data.first.subresource.arrayLayer, |
| 1743 | cb_image_data.first.subresource.mipLevel, string_VkImageLayout(imageLayout), |
| 1744 | string_VkImageLayout(cb_image_data.second.initialLayout)); |
Mark Lobodzinski | 4a3065e | 2017-02-07 16:36:03 -0700 | [diff] [blame] | 1745 | } else { |
Mark Lobodzinski | b0dd947 | 2017-02-07 16:38:17 -0700 | [diff] [blame] | 1746 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1747 | reinterpret_cast<uint64_t &>(pCB->commandBuffer), __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, |
| 1748 | "DS", "Cannot submit cmd buffer using image (0x%" PRIx64 |
| 1749 | ") with layout %s when " |
| 1750 | "first use is %s.", |
| 1751 | reinterpret_cast<const uint64_t &>(cb_image_data.first.image), |
| 1752 | string_VkImageLayout(imageLayout), string_VkImageLayout(cb_image_data.second.initialLayout)); |
Mark Lobodzinski | 4a3065e | 2017-02-07 16:36:03 -0700 | [diff] [blame] | 1753 | } |
| 1754 | } |
Mark Lobodzinski | b0dd947 | 2017-02-07 16:38:17 -0700 | [diff] [blame] | 1755 | SetGlobalLayout(device_data, cb_image_data.first, cb_image_data.second.layout); |
Mark Lobodzinski | 4a3065e | 2017-02-07 16:36:03 -0700 | [diff] [blame] | 1756 | } |
| 1757 | } |
Mark Lobodzinski | b0dd947 | 2017-02-07 16:38:17 -0700 | [diff] [blame] | 1758 | return skip; |
Mark Lobodzinski | 4a3065e | 2017-02-07 16:36:03 -0700 | [diff] [blame] | 1759 | } |
Mark Lobodzinski | b3829a5 | 2017-02-07 16:55:53 -0700 | [diff] [blame] | 1760 | |
| 1761 | // Print readable FlagBits in FlagMask |
| 1762 | static std::string string_VkAccessFlags(VkAccessFlags accessMask) { |
| 1763 | std::string result; |
| 1764 | std::string separator; |
| 1765 | |
| 1766 | if (accessMask == 0) { |
| 1767 | result = "[None]"; |
| 1768 | } else { |
| 1769 | result = "["; |
| 1770 | for (auto i = 0; i < 32; i++) { |
| 1771 | if (accessMask & (1 << i)) { |
| 1772 | result = result + separator + string_VkAccessFlagBits((VkAccessFlagBits)(1 << i)); |
| 1773 | separator = " | "; |
| 1774 | } |
| 1775 | } |
| 1776 | result = result + "]"; |
| 1777 | } |
| 1778 | return result; |
| 1779 | } |
| 1780 | |
Mark Lobodzinski | 9a8d40f | 2017-02-07 17:00:12 -0700 | [diff] [blame] | 1781 | // AccessFlags MUST have 'required_bit' set, and may have one or more of 'optional_bits' set. If required_bit is zero, accessMask |
| 1782 | // must have at least one of 'optional_bits' set |
Mark Lobodzinski | b3829a5 | 2017-02-07 16:55:53 -0700 | [diff] [blame] | 1783 | // TODO: Add tracking to ensure that at least one barrier has been set for these layout transitions |
Mark Lobodzinski | 9a8d40f | 2017-02-07 17:00:12 -0700 | [diff] [blame] | 1784 | static bool ValidateMaskBits(core_validation::layer_data *device_data, VkCommandBuffer cmdBuffer, const VkAccessFlags &accessMask, |
| 1785 | const VkImageLayout &layout, VkAccessFlags required_bit, VkAccessFlags optional_bits, |
| 1786 | const char *type) { |
| 1787 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 1788 | bool skip = false; |
Mark Lobodzinski | b3829a5 | 2017-02-07 16:55:53 -0700 | [diff] [blame] | 1789 | |
| 1790 | if ((accessMask & required_bit) || (!required_bit && (accessMask & optional_bits))) { |
| 1791 | if (accessMask & ~(required_bit | optional_bits)) { |
| 1792 | // TODO: Verify against Valid Use |
Mark Lobodzinski | 9a8d40f | 2017-02-07 17:00:12 -0700 | [diff] [blame] | 1793 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, |
| 1794 | DRAWSTATE_INVALID_BARRIER, "DS", |
| 1795 | "Additional bits in %s accessMask 0x%X %s are specified when layout is %s.", type, accessMask, |
| 1796 | string_VkAccessFlags(accessMask).c_str(), string_VkImageLayout(layout)); |
Mark Lobodzinski | b3829a5 | 2017-02-07 16:55:53 -0700 | [diff] [blame] | 1797 | } |
| 1798 | } else { |
| 1799 | if (!required_bit) { |
Mark Lobodzinski | 9a8d40f | 2017-02-07 17:00:12 -0700 | [diff] [blame] | 1800 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, |
| 1801 | DRAWSTATE_INVALID_BARRIER, "DS", |
| 1802 | "%s AccessMask %d %s must contain at least one of access bits %d " |
| 1803 | "%s when layout is %s, unless the app has previously added a " |
| 1804 | "barrier for this transition.", |
| 1805 | type, accessMask, string_VkAccessFlags(accessMask).c_str(), optional_bits, |
| 1806 | string_VkAccessFlags(optional_bits).c_str(), string_VkImageLayout(layout)); |
Mark Lobodzinski | b3829a5 | 2017-02-07 16:55:53 -0700 | [diff] [blame] | 1807 | } else { |
| 1808 | std::string opt_bits; |
| 1809 | if (optional_bits != 0) { |
| 1810 | std::stringstream ss; |
| 1811 | ss << optional_bits; |
| 1812 | opt_bits = "and may have optional bits " + ss.str() + ' ' + string_VkAccessFlags(optional_bits); |
| 1813 | } |
Mark Lobodzinski | 9a8d40f | 2017-02-07 17:00:12 -0700 | [diff] [blame] | 1814 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, |
| 1815 | DRAWSTATE_INVALID_BARRIER, "DS", |
| 1816 | "%s AccessMask %d %s must have required access bit %d %s %s when " |
| 1817 | "layout is %s, unless the app has previously added a barrier for " |
| 1818 | "this transition.", |
| 1819 | type, accessMask, string_VkAccessFlags(accessMask).c_str(), required_bit, |
| 1820 | string_VkAccessFlags(required_bit).c_str(), opt_bits.c_str(), string_VkImageLayout(layout)); |
Mark Lobodzinski | b3829a5 | 2017-02-07 16:55:53 -0700 | [diff] [blame] | 1821 | } |
| 1822 | } |
Mark Lobodzinski | 9a8d40f | 2017-02-07 17:00:12 -0700 | [diff] [blame] | 1823 | return skip; |
Mark Lobodzinski | b3829a5 | 2017-02-07 16:55:53 -0700 | [diff] [blame] | 1824 | } |
| 1825 | |
Mark Lobodzinski | 9a8d40f | 2017-02-07 17:00:12 -0700 | [diff] [blame] | 1826 | bool ValidateMaskBitsFromLayouts(core_validation::layer_data *device_data, VkCommandBuffer cmdBuffer, |
| 1827 | const VkAccessFlags &accessMask, const VkImageLayout &layout, const char *type) { |
| 1828 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
Mark Lobodzinski | b3829a5 | 2017-02-07 16:55:53 -0700 | [diff] [blame] | 1829 | |
Mark Lobodzinski | 9a8d40f | 2017-02-07 17:00:12 -0700 | [diff] [blame] | 1830 | bool skip = false; |
Mark Lobodzinski | b3829a5 | 2017-02-07 16:55:53 -0700 | [diff] [blame] | 1831 | switch (layout) { |
Mark Lobodzinski | 9a8d40f | 2017-02-07 17:00:12 -0700 | [diff] [blame] | 1832 | case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: { |
| 1833 | skip |= ValidateMaskBits(device_data, cmdBuffer, accessMask, layout, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, |
| 1834 | VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT, type); |
| 1835 | break; |
Mark Lobodzinski | b3829a5 | 2017-02-07 16:55:53 -0700 | [diff] [blame] | 1836 | } |
Mark Lobodzinski | 9a8d40f | 2017-02-07 17:00:12 -0700 | [diff] [blame] | 1837 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: { |
| 1838 | skip |= ValidateMaskBits(device_data, cmdBuffer, accessMask, layout, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, |
| 1839 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT, type); |
| 1840 | break; |
| 1841 | } |
| 1842 | case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL: { |
| 1843 | skip |= ValidateMaskBits(device_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_WRITE_BIT, 0, type); |
| 1844 | break; |
| 1845 | } |
| 1846 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: { |
| 1847 | skip |= ValidateMaskBits( |
| 1848 | device_data, cmdBuffer, accessMask, layout, 0, |
| 1849 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT, |
| 1850 | type); |
| 1851 | break; |
| 1852 | } |
| 1853 | case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: { |
| 1854 | skip |= ValidateMaskBits(device_data, cmdBuffer, accessMask, layout, 0, |
| 1855 | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT | VK_ACCESS_SHADER_READ_BIT, type); |
| 1856 | break; |
| 1857 | } |
| 1858 | case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL: { |
| 1859 | skip |= ValidateMaskBits(device_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_READ_BIT, 0, type); |
| 1860 | break; |
| 1861 | } |
| 1862 | case VK_IMAGE_LAYOUT_PRESENT_SRC_KHR: { |
| 1863 | skip |= ValidateMaskBits(device_data, cmdBuffer, accessMask, layout, VK_ACCESS_MEMORY_READ_BIT, 0, type); |
| 1864 | break; |
| 1865 | } |
| 1866 | case VK_IMAGE_LAYOUT_UNDEFINED: { |
| 1867 | if (accessMask != 0) { |
| 1868 | // TODO: Verify against Valid Use section spec |
| 1869 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, |
| 1870 | DRAWSTATE_INVALID_BARRIER, "DS", |
| 1871 | "Additional bits in %s accessMask 0x%X %s are specified when layout is %s.", type, accessMask, |
| 1872 | string_VkAccessFlags(accessMask).c_str(), string_VkImageLayout(layout)); |
| 1873 | } |
| 1874 | break; |
| 1875 | } |
| 1876 | case VK_IMAGE_LAYOUT_GENERAL: |
| 1877 | default: { break; } |
Mark Lobodzinski | b3829a5 | 2017-02-07 16:55:53 -0700 | [diff] [blame] | 1878 | } |
Mark Lobodzinski | 9a8d40f | 2017-02-07 17:00:12 -0700 | [diff] [blame] | 1879 | return skip; |
Mark Lobodzinski | b3829a5 | 2017-02-07 16:55:53 -0700 | [diff] [blame] | 1880 | } |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 1881 | |
| 1882 | // ValidateLayoutVsAttachmentDescription is a general function where we can validate various state associated with the |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 1883 | // VkAttachmentDescription structs that are used by the sub-passes of a renderpass. Initial check is to make sure that READ_ONLY |
| 1884 | // layout attachments don't have CLEAR as their loadOp. |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 1885 | bool ValidateLayoutVsAttachmentDescription(const debug_report_data *report_data, const VkImageLayout first_layout, |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 1886 | const uint32_t attachment, const VkAttachmentDescription &attachment_description) { |
| 1887 | bool skip = false; |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 1888 | // Verify that initial loadOp on READ_ONLY attachments is not CLEAR |
| 1889 | if (attachment_description.loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR) { |
| 1890 | if ((first_layout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL) || |
| 1891 | (first_layout == VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL)) { |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 1892 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, |
| 1893 | VkDebugReportObjectTypeEXT(0), __LINE__, VALIDATION_ERROR_02351, "DS", |
| 1894 | "Cannot clear attachment %d with invalid first layout %s. %s", attachment, |
| 1895 | string_VkImageLayout(first_layout), validation_error_map[VALIDATION_ERROR_02351]); |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 1896 | } |
| 1897 | } |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 1898 | return skip; |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 1899 | } |
| 1900 | |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 1901 | bool ValidateLayouts(core_validation::layer_data *device_data, VkDevice device, const VkRenderPassCreateInfo *pCreateInfo) { |
| 1902 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 1903 | bool skip = false; |
| 1904 | |
| 1905 | // Track when we're observing the first use of an attachment |
| 1906 | std::vector<bool> attach_first_use(pCreateInfo->attachmentCount, true); |
| 1907 | for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) { |
| 1908 | const VkSubpassDescription &subpass = pCreateInfo->pSubpasses[i]; |
| 1909 | for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) { |
| 1910 | auto attach_index = subpass.pColorAttachments[j].attachment; |
| 1911 | if (attach_index == VK_ATTACHMENT_UNUSED) continue; |
| 1912 | |
| 1913 | switch (subpass.pColorAttachments[j].layout) { |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 1914 | case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: |
| 1915 | // This is ideal. |
| 1916 | break; |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 1917 | |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 1918 | case VK_IMAGE_LAYOUT_GENERAL: |
| 1919 | // May not be optimal; TODO: reconsider this warning based on other constraints? |
| 1920 | skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 1921 | VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", |
| 1922 | "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL."); |
| 1923 | break; |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 1924 | |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 1925 | default: |
| 1926 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 1927 | __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", |
| 1928 | "Layout for color attachment is %s but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.", |
| 1929 | string_VkImageLayout(subpass.pColorAttachments[j].layout)); |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 1930 | } |
| 1931 | |
| 1932 | if (attach_first_use[attach_index]) { |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 1933 | skip |= ValidateLayoutVsAttachmentDescription(report_data, subpass.pColorAttachments[j].layout, attach_index, |
| 1934 | pCreateInfo->pAttachments[attach_index]); |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 1935 | } |
| 1936 | attach_first_use[attach_index] = false; |
| 1937 | } |
| 1938 | if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) { |
| 1939 | switch (subpass.pDepthStencilAttachment->layout) { |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 1940 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: |
| 1941 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: |
| 1942 | // These are ideal. |
| 1943 | break; |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 1944 | |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 1945 | case VK_IMAGE_LAYOUT_GENERAL: |
| 1946 | // May not be optimal; TODO: reconsider this warning based on other constraints? GENERAL can be better than |
| 1947 | // doing a bunch of transitions. |
| 1948 | skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 1949 | VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", |
| 1950 | "GENERAL layout for depth attachment may not give optimal performance."); |
| 1951 | break; |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 1952 | |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 1953 | default: |
| 1954 | // No other layouts are acceptable |
| 1955 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 1956 | __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", |
| 1957 | "Layout for depth attachment is %s but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL, " |
| 1958 | "DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.", |
| 1959 | string_VkImageLayout(subpass.pDepthStencilAttachment->layout)); |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 1960 | } |
| 1961 | |
| 1962 | auto attach_index = subpass.pDepthStencilAttachment->attachment; |
| 1963 | if (attach_first_use[attach_index]) { |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 1964 | skip |= ValidateLayoutVsAttachmentDescription(report_data, subpass.pDepthStencilAttachment->layout, attach_index, |
| 1965 | pCreateInfo->pAttachments[attach_index]); |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 1966 | } |
| 1967 | attach_first_use[attach_index] = false; |
| 1968 | } |
| 1969 | for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) { |
| 1970 | auto attach_index = subpass.pInputAttachments[j].attachment; |
| 1971 | if (attach_index == VK_ATTACHMENT_UNUSED) continue; |
| 1972 | |
| 1973 | switch (subpass.pInputAttachments[j].layout) { |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 1974 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: |
| 1975 | case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: |
| 1976 | // These are ideal. |
| 1977 | break; |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 1978 | |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 1979 | case VK_IMAGE_LAYOUT_GENERAL: |
| 1980 | // May not be optimal. TODO: reconsider this warning based on other constraints. |
| 1981 | skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 1982 | VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", |
| 1983 | "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL."); |
| 1984 | break; |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 1985 | |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 1986 | default: |
| 1987 | // No other layouts are acceptable |
| 1988 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, |
| 1989 | DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", |
| 1990 | "Layout for input attachment is %s but can only be READ_ONLY_OPTIMAL or GENERAL.", |
| 1991 | string_VkImageLayout(subpass.pInputAttachments[j].layout)); |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 1992 | } |
| 1993 | |
| 1994 | if (attach_first_use[attach_index]) { |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 1995 | skip |= ValidateLayoutVsAttachmentDescription(report_data, subpass.pInputAttachments[j].layout, attach_index, |
| 1996 | pCreateInfo->pAttachments[attach_index]); |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 1997 | } |
| 1998 | attach_first_use[attach_index] = false; |
| 1999 | } |
| 2000 | } |
| 2001 | return skip; |
| 2002 | } |
Mark Lobodzinski | 08f14fa | 2017-02-07 17:20:06 -0700 | [diff] [blame] | 2003 | |
| 2004 | // For any image objects that overlap mapped memory, verify that their layouts are PREINIT or GENERAL |
Mark Lobodzinski | ac23ec8 | 2017-02-07 17:21:55 -0700 | [diff] [blame] | 2005 | bool ValidateMapImageLayouts(core_validation::layer_data *device_data, VkDevice device, DEVICE_MEM_INFO const *mem_info, |
| 2006 | VkDeviceSize offset, VkDeviceSize end_offset) { |
| 2007 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 2008 | bool skip = false; |
| 2009 | // Iterate over all bound image ranges and verify that for any that overlap the map ranges, the layouts are |
| 2010 | // VK_IMAGE_LAYOUT_PREINITIALIZED or VK_IMAGE_LAYOUT_GENERAL |
Mark Lobodzinski | 08f14fa | 2017-02-07 17:20:06 -0700 | [diff] [blame] | 2011 | // TODO : This can be optimized if we store ranges based on starting address and early exit when we pass our range |
| 2012 | for (auto image_handle : mem_info->bound_images) { |
| 2013 | auto img_it = mem_info->bound_ranges.find(image_handle); |
| 2014 | if (img_it != mem_info->bound_ranges.end()) { |
Mark Lobodzinski | ac23ec8 | 2017-02-07 17:21:55 -0700 | [diff] [blame] | 2015 | if (rangesIntersect(device_data, &img_it->second, offset, end_offset)) { |
Mark Lobodzinski | 08f14fa | 2017-02-07 17:20:06 -0700 | [diff] [blame] | 2016 | std::vector<VkImageLayout> layouts; |
Mark Lobodzinski | ac23ec8 | 2017-02-07 17:21:55 -0700 | [diff] [blame] | 2017 | if (FindLayouts(device_data, VkImage(image_handle), layouts)) { |
Mark Lobodzinski | 08f14fa | 2017-02-07 17:20:06 -0700 | [diff] [blame] | 2018 | for (auto layout : layouts) { |
| 2019 | if (layout != VK_IMAGE_LAYOUT_PREINITIALIZED && layout != VK_IMAGE_LAYOUT_GENERAL) { |
Michael Lentine | c174b93 | 2017-02-10 14:57:15 -0600 | [diff] [blame] | 2020 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, |
Mark Lobodzinski | ac23ec8 | 2017-02-07 17:21:55 -0700 | [diff] [blame] | 2021 | DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", |
Michael Lentine | c174b93 | 2017-02-10 14:57:15 -0600 | [diff] [blame] | 2022 | "Mapping an image with layout %s can result in undefined behavior if this memory is " |
| 2023 | "used by the device. Only GENERAL or PREINITIALIZED should be used.", |
Mark Lobodzinski | ac23ec8 | 2017-02-07 17:21:55 -0700 | [diff] [blame] | 2024 | string_VkImageLayout(layout)); |
Mark Lobodzinski | 08f14fa | 2017-02-07 17:20:06 -0700 | [diff] [blame] | 2025 | } |
| 2026 | } |
| 2027 | } |
| 2028 | } |
| 2029 | } |
| 2030 | } |
Mark Lobodzinski | ac23ec8 | 2017-02-07 17:21:55 -0700 | [diff] [blame] | 2031 | return skip; |
Mark Lobodzinski | 08f14fa | 2017-02-07 17:20:06 -0700 | [diff] [blame] | 2032 | } |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 2033 | |
| 2034 | // Helper function to validate correct usage bits set for buffers or images. Verify that (actual & desired) flags != 0 or, if strict |
| 2035 | // is true, verify that (actual & desired) flags == desired |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 2036 | static bool validate_usage_flags(layer_data *device_data, VkFlags actual, VkFlags desired, VkBool32 strict, uint64_t obj_handle, |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 2037 | VkDebugReportObjectTypeEXT obj_type, int32_t const msgCode, char const *ty_str, |
| 2038 | char const *func_name, char const *usage_str) { |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 2039 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 2040 | |
| 2041 | bool correct_usage = false; |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 2042 | bool skip = false; |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 2043 | if (strict) { |
| 2044 | correct_usage = ((actual & desired) == desired); |
| 2045 | } else { |
| 2046 | correct_usage = ((actual & desired) != 0); |
| 2047 | } |
| 2048 | if (!correct_usage) { |
| 2049 | if (msgCode == -1) { |
| 2050 | // TODO: Fix callers with msgCode == -1 to use correct validation checks. |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 2051 | skip = log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, obj_type, obj_handle, __LINE__, MEMTRACK_INVALID_USAGE_FLAG, |
| 2052 | "MEM", "Invalid usage flag for %s 0x%" PRIxLEAST64 |
| 2053 | " used by %s. In this case, %s should have %s set during creation.", |
| 2054 | ty_str, obj_handle, func_name, ty_str, usage_str); |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 2055 | } else { |
| 2056 | const char *valid_usage = (msgCode == -1) ? "" : validation_error_map[msgCode]; |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 2057 | skip = log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, obj_type, obj_handle, __LINE__, msgCode, "MEM", |
| 2058 | "Invalid usage flag for %s 0x%" PRIxLEAST64 |
| 2059 | " used by %s. In this case, %s should have %s set during creation. %s", |
| 2060 | ty_str, obj_handle, func_name, ty_str, usage_str, valid_usage); |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 2061 | } |
| 2062 | } |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 2063 | return skip; |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 2064 | } |
| 2065 | |
| 2066 | // Helper function to validate usage flags for buffers. For given buffer_state send actual vs. desired usage off to helper above |
| 2067 | // where an error will be flagged if usage is not correct |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 2068 | bool ValidateImageUsageFlags(layer_data *device_data, IMAGE_STATE const *image_state, VkFlags desired, VkBool32 strict, |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 2069 | int32_t const msgCode, char const *func_name, char const *usage_string) { |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 2070 | return validate_usage_flags(device_data, image_state->createInfo.usage, desired, strict, |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 2071 | reinterpret_cast<const uint64_t &>(image_state->image), VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 2072 | msgCode, "image", func_name, usage_string); |
| 2073 | } |
| 2074 | |
| 2075 | // Helper function to validate usage flags for buffers. For given buffer_state send actual vs. desired usage off to helper above |
| 2076 | // where an error will be flagged if usage is not correct |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 2077 | bool ValidateBufferUsageFlags(layer_data *device_data, BUFFER_STATE const *buffer_state, VkFlags desired, VkBool32 strict, |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 2078 | int32_t const msgCode, char const *func_name, char const *usage_string) { |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 2079 | return validate_usage_flags(device_data, buffer_state->createInfo.usage, desired, strict, |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 2080 | reinterpret_cast<const uint64_t &>(buffer_state->buffer), VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, |
| 2081 | msgCode, "buffer", func_name, usage_string); |
| 2082 | } |
| 2083 | |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 2084 | bool PreCallValidateCreateBuffer(layer_data *device_data, const VkBufferCreateInfo *pCreateInfo) { |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 2085 | bool skip = false; |
| 2086 | // TODO: Add check for VALIDATION_ERROR_00658 |
| 2087 | // TODO: Add check for VALIDATION_ERROR_00666 |
| 2088 | // TODO: Add check for VALIDATION_ERROR_00667 |
| 2089 | // TODO: Add check for VALIDATION_ERROR_00668 |
| 2090 | // TODO: Add check for VALIDATION_ERROR_00669 |
| 2091 | return skip; |
| 2092 | } |
| 2093 | |
| 2094 | void PostCallRecordCreateBuffer(layer_data *device_data, const VkBufferCreateInfo *pCreateInfo, VkBuffer *pBuffer) { |
| 2095 | // TODO : This doesn't create deep copy of pQueueFamilyIndices so need to fix that if/when we want that data to be valid |
| 2096 | GetBufferMap(device_data) |
| 2097 | ->insert(std::make_pair(*pBuffer, std::unique_ptr<BUFFER_STATE>(new BUFFER_STATE(*pBuffer, pCreateInfo)))); |
| 2098 | } |
| 2099 | |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 2100 | bool PreCallValidateCreateBufferView(layer_data *device_data, const VkBufferViewCreateInfo *pCreateInfo) { |
| 2101 | bool skip = false; |
| 2102 | BUFFER_STATE *buffer_state = GetBufferState(device_data, pCreateInfo->buffer); |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 2103 | // If this isn't a sparse buffer, it needs to have memory backing it at CreateBufferView time |
| 2104 | if (buffer_state) { |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 2105 | skip |= ValidateMemoryIsBoundToBuffer(device_data, buffer_state, "vkCreateBufferView()", VALIDATION_ERROR_02522); |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 2106 | // In order to create a valid buffer view, the buffer must have been created with at least one of the following flags: |
| 2107 | // UNIFORM_TEXEL_BUFFER_BIT or STORAGE_TEXEL_BUFFER_BIT |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 2108 | skip |= ValidateBufferUsageFlags( |
| 2109 | device_data, buffer_state, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT, false, |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 2110 | VALIDATION_ERROR_00694, "vkCreateBufferView()", "VK_BUFFER_USAGE_[STORAGE|UNIFORM]_TEXEL_BUFFER_BIT"); |
| 2111 | } |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 2112 | return skip; |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 2113 | } |
| 2114 | |
| 2115 | void PostCallRecordCreateBufferView(layer_data *device_data, const VkBufferViewCreateInfo *pCreateInfo, VkBufferView *pView) { |
| 2116 | (*GetBufferViewMap(device_data))[*pView] = std::unique_ptr<BUFFER_VIEW_STATE>(new BUFFER_VIEW_STATE(*pView, pCreateInfo)); |
| 2117 | } |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 2118 | |
| 2119 | // For the given format verify that the aspect masks make sense |
| 2120 | bool ValidateImageAspectMask(layer_data *device_data, VkImage image, VkFormat format, VkImageAspectFlags aspect_mask, |
| 2121 | const char *func_name) { |
| 2122 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 2123 | bool skip = false; |
| 2124 | if (vk_format_is_color(format)) { |
| 2125 | if ((aspect_mask & VK_IMAGE_ASPECT_COLOR_BIT) != VK_IMAGE_ASPECT_COLOR_BIT) { |
| 2126 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, (uint64_t)image, |
| 2127 | __LINE__, VALIDATION_ERROR_00741, "IMAGE", |
| 2128 | "%s: Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set. %s", func_name, |
| 2129 | validation_error_map[VALIDATION_ERROR_00741]); |
| 2130 | } else if ((aspect_mask & VK_IMAGE_ASPECT_COLOR_BIT) != aspect_mask) { |
| 2131 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, (uint64_t)image, |
| 2132 | __LINE__, VALIDATION_ERROR_00741, "IMAGE", |
| 2133 | "%s: Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set. %s", func_name, |
| 2134 | validation_error_map[VALIDATION_ERROR_00741]); |
| 2135 | } |
| 2136 | } else if (vk_format_is_depth_and_stencil(format)) { |
| 2137 | if ((aspect_mask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) == 0) { |
| 2138 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, (uint64_t)image, |
| 2139 | __LINE__, VALIDATION_ERROR_00741, "IMAGE", |
| 2140 | "%s: Depth/stencil image formats must have " |
| 2141 | "at least one of VK_IMAGE_ASPECT_DEPTH_BIT " |
| 2142 | "and VK_IMAGE_ASPECT_STENCIL_BIT set. %s", |
| 2143 | func_name, validation_error_map[VALIDATION_ERROR_00741]); |
| 2144 | } else if ((aspect_mask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) != aspect_mask) { |
| 2145 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, (uint64_t)image, |
| 2146 | __LINE__, VALIDATION_ERROR_00741, "IMAGE", |
| 2147 | "%s: Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and " |
| 2148 | "VK_IMAGE_ASPECT_STENCIL_BIT set. %s", |
| 2149 | func_name, validation_error_map[VALIDATION_ERROR_00741]); |
| 2150 | } |
| 2151 | } else if (vk_format_is_depth_only(format)) { |
| 2152 | if ((aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) != VK_IMAGE_ASPECT_DEPTH_BIT) { |
| 2153 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, (uint64_t)image, |
| 2154 | __LINE__, VALIDATION_ERROR_00741, "IMAGE", |
| 2155 | "%s: Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set. %s", func_name, |
| 2156 | validation_error_map[VALIDATION_ERROR_00741]); |
| 2157 | } else if ((aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) != aspect_mask) { |
| 2158 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, (uint64_t)image, |
| 2159 | __LINE__, VALIDATION_ERROR_00741, "IMAGE", |
| 2160 | "%s: Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set. %s", func_name, |
| 2161 | validation_error_map[VALIDATION_ERROR_00741]); |
| 2162 | } |
| 2163 | } else if (vk_format_is_stencil_only(format)) { |
| 2164 | if ((aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) != VK_IMAGE_ASPECT_STENCIL_BIT) { |
| 2165 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, (uint64_t)image, |
| 2166 | __LINE__, VALIDATION_ERROR_00741, "IMAGE", |
| 2167 | "%s: Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set. %s", func_name, |
| 2168 | validation_error_map[VALIDATION_ERROR_00741]); |
| 2169 | } else if ((aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) != aspect_mask) { |
| 2170 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, (uint64_t)image, |
| 2171 | __LINE__, VALIDATION_ERROR_00741, "IMAGE", |
| 2172 | "%s: Stencil-only image formats can have only the VK_IMAGE_ASPECT_STENCIL_BIT set. %s", func_name, |
| 2173 | validation_error_map[VALIDATION_ERROR_00741]); |
| 2174 | } |
| 2175 | } |
| 2176 | return skip; |
| 2177 | } |
| 2178 | |
| 2179 | bool ValidateImageSubrangeLevelLayerCounts(layer_data *device_data, const VkImageSubresourceRange &subresourceRange, |
| 2180 | const char *func_name) { |
| 2181 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 2182 | bool skip = false; |
| 2183 | if (subresourceRange.levelCount == 0) { |
| 2184 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, |
| 2185 | VALIDATION_ERROR_00768, "IMAGE", "%s called with 0 in subresourceRange.levelCount. %s", func_name, |
| 2186 | validation_error_map[VALIDATION_ERROR_00768]); |
| 2187 | } |
| 2188 | if (subresourceRange.layerCount == 0) { |
| 2189 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, |
| 2190 | VALIDATION_ERROR_00769, "IMAGE", "%s called with 0 in subresourceRange.layerCount. %s", func_name, |
| 2191 | validation_error_map[VALIDATION_ERROR_00769]); |
| 2192 | } |
| 2193 | return skip; |
| 2194 | } |
| 2195 | |
| 2196 | bool PreCallValidateCreateImageView(layer_data *device_data, const VkImageViewCreateInfo *create_info) { |
| 2197 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 2198 | bool skip = false; |
| 2199 | IMAGE_STATE *image_state = GetImageState(device_data, create_info->image); |
| 2200 | if (image_state) { |
| 2201 | skip |= ValidateImageUsageFlags( |
| 2202 | device_data, image_state, |
| 2203 | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT | |
| 2204 | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, |
| 2205 | false, -1, "vkCreateImageView()", |
| 2206 | "VK_IMAGE_USAGE_[SAMPLED|STORAGE|COLOR_ATTACHMENT|DEPTH_STENCIL_ATTACHMENT|INPUT_ATTACHMENT]_BIT"); |
| 2207 | // If this isn't a sparse image, it needs to have memory backing it at CreateImageView time |
| 2208 | skip |= ValidateMemoryIsBoundToImage(device_data, image_state, "vkCreateImageView()", VALIDATION_ERROR_02524); |
| 2209 | // Checks imported from image layer |
| 2210 | if (create_info->subresourceRange.baseMipLevel >= image_state->createInfo.mipLevels) { |
| 2211 | std::stringstream ss; |
| 2212 | ss << "vkCreateImageView called with baseMipLevel " << create_info->subresourceRange.baseMipLevel << " for image " |
| 2213 | << create_info->image << " that only has " << image_state->createInfo.mipLevels << " mip levels."; |
| 2214 | skip |= |
| 2215 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, |
| 2216 | VALIDATION_ERROR_00768, "IMAGE", "%s %s", ss.str().c_str(), validation_error_map[VALIDATION_ERROR_00768]); |
| 2217 | } |
| 2218 | if (create_info->subresourceRange.baseArrayLayer >= image_state->createInfo.arrayLayers) { |
| 2219 | std::stringstream ss; |
| 2220 | ss << "vkCreateImageView called with baseArrayLayer " << create_info->subresourceRange.baseArrayLayer << " for image " |
| 2221 | << create_info->image << " that only has " << image_state->createInfo.arrayLayers << " array layers."; |
| 2222 | skip |= |
| 2223 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, |
| 2224 | VALIDATION_ERROR_00769, "IMAGE", "%s %s", ss.str().c_str(), validation_error_map[VALIDATION_ERROR_00769]); |
| 2225 | } |
| 2226 | // TODO: Need new valid usage language for levelCount == 0 & layerCount == 0 |
| 2227 | skip |= ValidateImageSubrangeLevelLayerCounts(device_data, create_info->subresourceRange, "vkCreateImageView()"); |
| 2228 | |
| 2229 | VkImageCreateFlags image_flags = image_state->createInfo.flags; |
| 2230 | VkFormat image_format = image_state->createInfo.format; |
| 2231 | VkFormat view_format = create_info->format; |
| 2232 | VkImageAspectFlags aspect_mask = create_info->subresourceRange.aspectMask; |
| 2233 | |
| 2234 | // Validate VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT state |
| 2235 | if (image_flags & VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT) { |
| 2236 | // Format MUST be compatible (in the same format compatibility class) as the format the image was created with |
| 2237 | if (vk_format_get_compatibility_class(image_format) != vk_format_get_compatibility_class(view_format)) { |
| 2238 | std::stringstream ss; |
| 2239 | ss << "vkCreateImageView(): ImageView format " << string_VkFormat(view_format) |
| 2240 | << " is not in the same format compatibility class as image (" << (uint64_t)create_info->image << ") format " |
| 2241 | << string_VkFormat(image_format) << ". Images created with the VK_IMAGE_CREATE_MUTABLE_FORMAT BIT " |
| 2242 | << "can support ImageViews with differing formats but they must be in the same compatibility class."; |
| 2243 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, |
| 2244 | VALIDATION_ERROR_02171, "IMAGE", "%s %s", ss.str().c_str(), |
| 2245 | validation_error_map[VALIDATION_ERROR_02171]); |
| 2246 | } |
| 2247 | } else { |
| 2248 | // Format MUST be IDENTICAL to the format the image was created with |
| 2249 | if (image_format != view_format) { |
| 2250 | std::stringstream ss; |
| 2251 | ss << "vkCreateImageView() format " << string_VkFormat(view_format) << " differs from image " |
| 2252 | << (uint64_t)create_info->image << " format " << string_VkFormat(image_format) |
| 2253 | << ". Formats MUST be IDENTICAL unless VK_IMAGE_CREATE_MUTABLE_FORMAT BIT was set on image creation."; |
| 2254 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, |
| 2255 | VALIDATION_ERROR_02172, "IMAGE", "%s %s", ss.str().c_str(), |
| 2256 | validation_error_map[VALIDATION_ERROR_02172]); |
| 2257 | } |
| 2258 | } |
| 2259 | |
| 2260 | // Validate correct image aspect bits for desired formats and format consistency |
| 2261 | skip |= ValidateImageAspectMask(device_data, image_state->image, image_format, aspect_mask, "vkCreateImageView()"); |
| 2262 | } |
| 2263 | return skip; |
| 2264 | } |
| 2265 | |
Mark Lobodzinski | efd933b | 2017-02-10 12:09:23 -0700 | [diff] [blame] | 2266 | void PostCallRecordCreateImageView(layer_data *device_data, const VkImageViewCreateInfo *create_info, VkImageView view) { |
| 2267 | auto image_view_map = GetImageViewMap(device_data); |
| 2268 | (*image_view_map)[view] = std::unique_ptr<IMAGE_VIEW_STATE>(new IMAGE_VIEW_STATE(view, create_info)); |
| 2269 | |
| 2270 | auto image_state = GetImageState(device_data, create_info->image); |
| 2271 | auto sub_res_range = (*image_view_map)[view].get()->create_info.subresourceRange; |
| 2272 | ResolveRemainingLevelsLayers(device_data, &sub_res_range, image_state); |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 2273 | } |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 2274 | |
Mark Lobodzinski | 680421d | 2017-02-09 13:06:56 -0700 | [diff] [blame] | 2275 | bool PreCallValidateCmdCopyBuffer(layer_data *device_data, GLOBAL_CB_NODE *cb_node, BUFFER_STATE *src_buffer_state, |
| 2276 | BUFFER_STATE *dst_buffer_state) { |
| 2277 | bool skip = false; |
| 2278 | skip |= ValidateMemoryIsBoundToBuffer(device_data, src_buffer_state, "vkCmdCopyBuffer()", VALIDATION_ERROR_02531); |
| 2279 | skip |= ValidateMemoryIsBoundToBuffer(device_data, dst_buffer_state, "vkCmdCopyBuffer()", VALIDATION_ERROR_02532); |
| 2280 | // Validate that SRC & DST buffers have correct usage flags set |
| 2281 | skip |= ValidateBufferUsageFlags(device_data, src_buffer_state, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, true, VALIDATION_ERROR_01164, |
| 2282 | "vkCmdCopyBuffer()", "VK_BUFFER_USAGE_TRANSFER_SRC_BIT"); |
| 2283 | skip |= ValidateBufferUsageFlags(device_data, dst_buffer_state, VK_BUFFER_USAGE_TRANSFER_DST_BIT, true, VALIDATION_ERROR_01165, |
| 2284 | "vkCmdCopyBuffer()", "VK_BUFFER_USAGE_TRANSFER_DST_BIT"); |
| 2285 | skip |= ValidateCmd(device_data, cb_node, CMD_COPYBUFFER, "vkCmdCopyBuffer()"); |
| 2286 | skip |= insideRenderPass(device_data, cb_node, "vkCmdCopyBuffer()", VALIDATION_ERROR_01172); |
| 2287 | return skip; |
| 2288 | } |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 2289 | |
Mark Lobodzinski | 680421d | 2017-02-09 13:06:56 -0700 | [diff] [blame] | 2290 | void PreCallRecordCmdCopyBuffer(layer_data *device_data, GLOBAL_CB_NODE *cb_node, BUFFER_STATE *src_buffer_state, |
| 2291 | BUFFER_STATE *dst_buffer_state) { |
| 2292 | // Update bindings between buffers and cmd buffer |
| 2293 | AddCommandBufferBindingBuffer(device_data, cb_node, src_buffer_state); |
| 2294 | AddCommandBufferBindingBuffer(device_data, cb_node, dst_buffer_state); |
| 2295 | |
| 2296 | std::function<bool()> function = [=]() { |
| 2297 | return ValidateBufferMemoryIsValid(device_data, src_buffer_state, "vkCmdCopyBuffer()"); |
| 2298 | }; |
| 2299 | cb_node->validate_functions.push_back(function); |
| 2300 | function = [=]() { |
| 2301 | SetBufferMemoryValid(device_data, dst_buffer_state, true); |
| 2302 | return false; |
| 2303 | }; |
| 2304 | cb_node->validate_functions.push_back(function); |
| 2305 | core_validation::UpdateCmdBufferLastCmd(cb_node, CMD_COPYBUFFER); |
| 2306 | } |
Mark Lobodzinski | 306441e | 2017-02-10 13:48:38 -0700 | [diff] [blame] | 2307 | |
| 2308 | static bool validateIdleBuffer(layer_data *device_data, VkBuffer buffer) { |
| 2309 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 2310 | bool skip = false; |
| 2311 | auto buffer_state = GetBufferState(device_data, buffer); |
| 2312 | if (!buffer_state) { |
| 2313 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, (uint64_t)(buffer), |
| 2314 | __LINE__, DRAWSTATE_DOUBLE_DESTROY, "DS", |
| 2315 | "Cannot free buffer 0x%" PRIxLEAST64 " that has not been allocated.", (uint64_t)(buffer)); |
| 2316 | } else { |
| 2317 | if (buffer_state->in_use.load()) { |
| 2318 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, (uint64_t)(buffer), |
| 2319 | __LINE__, VALIDATION_ERROR_00676, "DS", |
| 2320 | "Cannot free buffer 0x%" PRIxLEAST64 " that is in use by a command buffer. %s", (uint64_t)(buffer), |
| 2321 | validation_error_map[VALIDATION_ERROR_00676]); |
| 2322 | } |
| 2323 | } |
| 2324 | return skip; |
| 2325 | } |
| 2326 | |
| 2327 | bool PreCallValidateDestroyImageView(layer_data *device_data, VkImageView image_view, IMAGE_VIEW_STATE **image_view_state, |
| 2328 | VK_OBJECT *obj_struct) { |
| 2329 | *image_view_state = GetImageViewState(device_data, image_view); |
| 2330 | *obj_struct = {reinterpret_cast<uint64_t &>(image_view), VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT}; |
| 2331 | if (GetDisables(device_data)->destroy_image_view) return false; |
| 2332 | bool skip = false; |
| 2333 | if (*image_view_state) { |
| 2334 | skip |= ValidateObjectNotInUse(device_data, *image_view_state, *obj_struct, VALIDATION_ERROR_00776); |
| 2335 | } |
| 2336 | return skip; |
| 2337 | } |
| 2338 | |
| 2339 | void PostCallRecordDestroyImageView(layer_data *device_data, VkImageView image_view, IMAGE_VIEW_STATE *image_view_state, |
| 2340 | VK_OBJECT obj_struct) { |
| 2341 | // Any bound cmd buffers are now invalid |
| 2342 | invalidateCommandBuffers(device_data, image_view_state->cb_bindings, obj_struct); |
| 2343 | (*GetImageViewMap(device_data)).erase(image_view); |
| 2344 | } |
| 2345 | |
| 2346 | bool PreCallValidateDestroyBuffer(layer_data *device_data, VkBuffer buffer, BUFFER_STATE **buffer_state, VK_OBJECT *obj_struct) { |
| 2347 | *buffer_state = GetBufferState(device_data, buffer); |
| 2348 | *obj_struct = {reinterpret_cast<uint64_t &>(buffer), VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT}; |
| 2349 | if (GetDisables(device_data)->destroy_buffer) return false; |
| 2350 | bool skip = false; |
| 2351 | if (*buffer_state) { |
| 2352 | skip |= validateIdleBuffer(device_data, buffer); |
| 2353 | } |
| 2354 | return skip; |
| 2355 | } |
| 2356 | |
| 2357 | void PostCallRecordDestroyBuffer(layer_data *device_data, VkBuffer buffer, BUFFER_STATE *buffer_state, VK_OBJECT obj_struct) { |
| 2358 | invalidateCommandBuffers(device_data, buffer_state->cb_bindings, obj_struct); |
| 2359 | for (auto mem_binding : buffer_state->GetBoundMemory()) { |
| 2360 | auto mem_info = GetMemObjInfo(device_data, mem_binding); |
| 2361 | if (mem_info) { |
| 2362 | core_validation::RemoveBufferMemoryRange(reinterpret_cast<uint64_t &>(buffer), mem_info); |
| 2363 | } |
| 2364 | } |
| 2365 | ClearMemoryObjectBindings(device_data, reinterpret_cast<uint64_t &>(buffer), VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT); |
| 2366 | GetBufferMap(device_data)->erase(buffer_state->buffer); |
| 2367 | } |
| 2368 | |
| 2369 | bool PreCallValidateDestroyBufferView(layer_data *device_data, VkBufferView buffer_view, BUFFER_VIEW_STATE **buffer_view_state, |
| 2370 | VK_OBJECT *obj_struct) { |
| 2371 | *buffer_view_state = GetBufferViewState(device_data, buffer_view); |
| 2372 | *obj_struct = {reinterpret_cast<uint64_t &>(buffer_view), VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_VIEW_EXT}; |
| 2373 | if (GetDisables(device_data)->destroy_buffer_view) return false; |
| 2374 | bool skip = false; |
| 2375 | if (*buffer_view_state) { |
| 2376 | skip |= ValidateObjectNotInUse(device_data, *buffer_view_state, *obj_struct, VALIDATION_ERROR_00701); |
| 2377 | } |
| 2378 | return skip; |
| 2379 | } |
| 2380 | |
| 2381 | void PostCallRecordDestroyBufferView(layer_data *device_data, VkBufferView buffer_view, BUFFER_VIEW_STATE *buffer_view_state, |
| 2382 | VK_OBJECT obj_struct) { |
| 2383 | // Any bound cmd buffers are now invalid |
| 2384 | invalidateCommandBuffers(device_data, buffer_view_state->cb_bindings, obj_struct); |
| 2385 | GetBufferViewMap(device_data)->erase(buffer_view); |
| 2386 | } |
Mark Lobodzinski | df0acbf | 2017-02-10 14:01:27 -0700 | [diff] [blame^] | 2387 | |
| 2388 | bool PreCallValidateCmdFillBuffer(layer_data *device_data, GLOBAL_CB_NODE *cb_node, BUFFER_STATE *buffer_state) { |
| 2389 | bool skip = false; |
| 2390 | skip |= ValidateMemoryIsBoundToBuffer(device_data, buffer_state, "vkCmdFillBuffer()", VALIDATION_ERROR_02529); |
| 2391 | skip |= ValidateCmd(device_data, cb_node, CMD_FILLBUFFER, "vkCmdFillBuffer()"); |
| 2392 | // Validate that DST buffer has correct usage flags set |
| 2393 | skip |= ValidateBufferUsageFlags(device_data, buffer_state, VK_BUFFER_USAGE_TRANSFER_DST_BIT, true, VALIDATION_ERROR_01137, |
| 2394 | "vkCmdFillBuffer()", "VK_BUFFER_USAGE_TRANSFER_DST_BIT"); |
| 2395 | skip |= insideRenderPass(device_data, cb_node, "vkCmdFillBuffer()", VALIDATION_ERROR_01142); |
| 2396 | return skip; |
| 2397 | } |
| 2398 | |
| 2399 | void PreCallRecordCmdFillBuffer(layer_data *device_data, GLOBAL_CB_NODE *cb_node, BUFFER_STATE *buffer_state) { |
| 2400 | std::function<bool()> function = [=]() { |
| 2401 | SetBufferMemoryValid(device_data, buffer_state, true); |
| 2402 | return false; |
| 2403 | }; |
| 2404 | cb_node->validate_functions.push_back(function); |
| 2405 | // Update bindings between buffer and cmd buffer |
| 2406 | AddCommandBufferBindingBuffer(device_data, cb_node, buffer_state); |
| 2407 | core_validation::UpdateCmdBufferLastCmd(cb_node, CMD_FILLBUFFER); |
| 2408 | } |