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 | |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 34 | void SetLayout(core_validation::layer_data *device_data, GLOBAL_CB_NODE *pCB, ImageSubresourcePair imgpair, |
| 35 | const VkImageLayout &layout) { |
| 36 | if (std::find(pCB->imageSubresourceMap[imgpair.image].begin(), pCB->imageSubresourceMap[imgpair.image].end(), imgpair) != |
| 37 | pCB->imageSubresourceMap[imgpair.image].end()) { |
| 38 | pCB->imageLayoutMap[imgpair].layout = layout; |
| 39 | } else { |
| 40 | assert(imgpair.hasSubresource); |
| 41 | IMAGE_CMD_BUF_LAYOUT_NODE node; |
| 42 | if (!FindCmdBufLayout(device_data, pCB, imgpair.image, imgpair.subresource, node)) { |
| 43 | node.initialLayout = layout; |
| 44 | } |
| 45 | SetLayout(device_data, pCB, imgpair, {node.initialLayout, layout}); |
| 46 | } |
| 47 | } |
| 48 | template <class OBJECT, class LAYOUT> |
| 49 | void SetLayout(core_validation::layer_data *device_data, OBJECT *pObject, VkImage image, VkImageSubresource range, |
| 50 | const LAYOUT &layout) { |
| 51 | ImageSubresourcePair imgpair = {image, true, range}; |
| 52 | SetLayout(device_data, pObject, imgpair, layout, VK_IMAGE_ASPECT_COLOR_BIT); |
| 53 | SetLayout(device_data, pObject, imgpair, layout, VK_IMAGE_ASPECT_DEPTH_BIT); |
| 54 | SetLayout(device_data, pObject, imgpair, layout, VK_IMAGE_ASPECT_STENCIL_BIT); |
| 55 | SetLayout(device_data, pObject, imgpair, layout, VK_IMAGE_ASPECT_METADATA_BIT); |
| 56 | } |
| 57 | |
| 58 | template <class OBJECT, class LAYOUT> |
| 59 | void SetLayout(core_validation::layer_data *device_data, OBJECT *pObject, ImageSubresourcePair imgpair, const LAYOUT &layout, |
| 60 | VkImageAspectFlags aspectMask) { |
| 61 | if (imgpair.subresource.aspectMask & aspectMask) { |
| 62 | imgpair.subresource.aspectMask = aspectMask; |
| 63 | SetLayout(device_data, pObject, imgpair, layout); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | bool FindLayoutVerifyNode(core_validation::layer_data *device_data, GLOBAL_CB_NODE *pCB, ImageSubresourcePair imgpair, |
| 68 | IMAGE_CMD_BUF_LAYOUT_NODE &node, const VkImageAspectFlags aspectMask) { |
| 69 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 70 | |
| 71 | if (!(imgpair.subresource.aspectMask & aspectMask)) { |
| 72 | return false; |
| 73 | } |
| 74 | VkImageAspectFlags oldAspectMask = imgpair.subresource.aspectMask; |
| 75 | imgpair.subresource.aspectMask = aspectMask; |
| 76 | auto imgsubIt = pCB->imageLayoutMap.find(imgpair); |
| 77 | if (imgsubIt == pCB->imageLayoutMap.end()) { |
| 78 | return false; |
| 79 | } |
| 80 | if (node.layout != VK_IMAGE_LAYOUT_MAX_ENUM && node.layout != imgsubIt->second.layout) { |
| 81 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 82 | reinterpret_cast<uint64_t &>(imgpair.image), __LINE__, DRAWSTATE_INVALID_LAYOUT, "DS", |
| 83 | "Cannot query for VkImage 0x%" PRIx64 " layout when combined aspect mask %d has multiple layout types: %s and %s", |
| 84 | reinterpret_cast<uint64_t &>(imgpair.image), oldAspectMask, string_VkImageLayout(node.layout), |
| 85 | string_VkImageLayout(imgsubIt->second.layout)); |
| 86 | } |
| 87 | if (node.initialLayout != VK_IMAGE_LAYOUT_MAX_ENUM && node.initialLayout != imgsubIt->second.initialLayout) { |
| 88 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 89 | reinterpret_cast<uint64_t &>(imgpair.image), __LINE__, DRAWSTATE_INVALID_LAYOUT, "DS", |
| 90 | "Cannot query for VkImage 0x%" PRIx64 |
| 91 | " layout when combined aspect mask %d has multiple initial layout types: %s and %s", |
| 92 | reinterpret_cast<uint64_t &>(imgpair.image), oldAspectMask, string_VkImageLayout(node.initialLayout), |
| 93 | string_VkImageLayout(imgsubIt->second.initialLayout)); |
| 94 | } |
| 95 | node = imgsubIt->second; |
| 96 | return true; |
| 97 | } |
| 98 | |
| 99 | bool FindLayoutVerifyLayout(core_validation::layer_data *device_data, ImageSubresourcePair imgpair, VkImageLayout &layout, |
| 100 | const VkImageAspectFlags aspectMask) { |
| 101 | if (!(imgpair.subresource.aspectMask & aspectMask)) { |
| 102 | return false; |
| 103 | } |
| 104 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 105 | VkImageAspectFlags oldAspectMask = imgpair.subresource.aspectMask; |
| 106 | imgpair.subresource.aspectMask = aspectMask; |
| 107 | auto imgsubIt = (*core_validation::GetImageLayoutMap(device_data)).find(imgpair); |
| 108 | if (imgsubIt == (*core_validation::GetImageLayoutMap(device_data)).end()) { |
| 109 | return false; |
| 110 | } |
| 111 | if (layout != VK_IMAGE_LAYOUT_MAX_ENUM && layout != imgsubIt->second.layout) { |
| 112 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 113 | reinterpret_cast<uint64_t &>(imgpair.image), __LINE__, DRAWSTATE_INVALID_LAYOUT, "DS", |
| 114 | "Cannot query for VkImage 0x%" PRIx64 " layout when combined aspect mask %d has multiple layout types: %s and %s", |
| 115 | reinterpret_cast<uint64_t &>(imgpair.image), oldAspectMask, string_VkImageLayout(layout), |
| 116 | string_VkImageLayout(imgsubIt->second.layout)); |
| 117 | } |
| 118 | layout = imgsubIt->second.layout; |
| 119 | return true; |
| 120 | } |
| 121 | |
| 122 | // Find layout(s) on the command buffer level |
| 123 | bool FindCmdBufLayout(core_validation::layer_data *device_data, GLOBAL_CB_NODE *pCB, VkImage image, VkImageSubresource range, |
| 124 | IMAGE_CMD_BUF_LAYOUT_NODE &node) { |
| 125 | ImageSubresourcePair imgpair = {image, true, range}; |
| 126 | node = IMAGE_CMD_BUF_LAYOUT_NODE(VK_IMAGE_LAYOUT_MAX_ENUM, VK_IMAGE_LAYOUT_MAX_ENUM); |
| 127 | FindLayoutVerifyNode(device_data, pCB, imgpair, node, VK_IMAGE_ASPECT_COLOR_BIT); |
| 128 | FindLayoutVerifyNode(device_data, pCB, imgpair, node, VK_IMAGE_ASPECT_DEPTH_BIT); |
| 129 | FindLayoutVerifyNode(device_data, pCB, imgpair, node, VK_IMAGE_ASPECT_STENCIL_BIT); |
| 130 | FindLayoutVerifyNode(device_data, pCB, imgpair, node, VK_IMAGE_ASPECT_METADATA_BIT); |
| 131 | if (node.layout == VK_IMAGE_LAYOUT_MAX_ENUM) { |
| 132 | imgpair = {image, false, VkImageSubresource()}; |
| 133 | auto imgsubIt = pCB->imageLayoutMap.find(imgpair); |
| 134 | if (imgsubIt == pCB->imageLayoutMap.end()) return false; |
| 135 | // TODO: This is ostensibly a find function but it changes state here |
| 136 | node = imgsubIt->second; |
| 137 | } |
| 138 | return true; |
| 139 | } |
| 140 | |
| 141 | // Find layout(s) on the global level |
| 142 | bool FindGlobalLayout(core_validation::layer_data *device_data, ImageSubresourcePair imgpair, VkImageLayout &layout) { |
| 143 | layout = VK_IMAGE_LAYOUT_MAX_ENUM; |
| 144 | FindLayoutVerifyLayout(device_data, imgpair, layout, VK_IMAGE_ASPECT_COLOR_BIT); |
| 145 | FindLayoutVerifyLayout(device_data, imgpair, layout, VK_IMAGE_ASPECT_DEPTH_BIT); |
| 146 | FindLayoutVerifyLayout(device_data, imgpair, layout, VK_IMAGE_ASPECT_STENCIL_BIT); |
| 147 | FindLayoutVerifyLayout(device_data, imgpair, layout, VK_IMAGE_ASPECT_METADATA_BIT); |
| 148 | if (layout == VK_IMAGE_LAYOUT_MAX_ENUM) { |
| 149 | imgpair = {imgpair.image, false, VkImageSubresource()}; |
| 150 | auto imgsubIt = (*core_validation::GetImageLayoutMap(device_data)).find(imgpair); |
| 151 | if (imgsubIt == (*core_validation::GetImageLayoutMap(device_data)).end()) return false; |
| 152 | layout = imgsubIt->second.layout; |
| 153 | } |
| 154 | return true; |
| 155 | } |
| 156 | |
| 157 | bool FindLayouts(core_validation::layer_data *device_data, VkImage image, std::vector<VkImageLayout> &layouts) { |
| 158 | auto sub_data = (*core_validation::GetImageSubresourceMap(device_data)).find(image); |
| 159 | if (sub_data == (*core_validation::GetImageSubresourceMap(device_data)).end()) return false; |
| 160 | auto image_state = getImageState(device_data, image); |
| 161 | if (!image_state) return false; |
| 162 | bool ignoreGlobal = false; |
| 163 | // TODO: Make this robust for >1 aspect mask. Now it will just say ignore potential errors in this case. |
| 164 | if (sub_data->second.size() >= (image_state->createInfo.arrayLayers * image_state->createInfo.mipLevels + 1)) { |
| 165 | ignoreGlobal = true; |
| 166 | } |
| 167 | for (auto imgsubpair : sub_data->second) { |
| 168 | if (ignoreGlobal && !imgsubpair.hasSubresource) continue; |
| 169 | auto img_data = (*core_validation::GetImageLayoutMap(device_data)).find(imgsubpair); |
| 170 | if (img_data != (*core_validation::GetImageLayoutMap(device_data)).end()) { |
| 171 | layouts.push_back(img_data->second.layout); |
| 172 | } |
| 173 | } |
| 174 | return true; |
| 175 | } |
| 176 | |
| 177 | // Set the layout on the global level |
| 178 | void SetGlobalLayout(core_validation::layer_data *device_data, ImageSubresourcePair imgpair, const VkImageLayout &layout) { |
| 179 | VkImage &image = imgpair.image; |
| 180 | (*core_validation::GetImageLayoutMap(device_data))[imgpair].layout = layout; |
| 181 | auto &image_subresources = (*core_validation::GetImageSubresourceMap(device_data))[image]; |
| 182 | auto subresource = std::find(image_subresources.begin(), image_subresources.end(), imgpair); |
| 183 | if (subresource == image_subresources.end()) { |
| 184 | image_subresources.push_back(imgpair); |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | // Set the layout on the cmdbuf level |
| 189 | void SetLayout(core_validation::layer_data *device_data, GLOBAL_CB_NODE *pCB, ImageSubresourcePair imgpair, |
| 190 | const IMAGE_CMD_BUF_LAYOUT_NODE &node) { |
| 191 | pCB->imageLayoutMap[imgpair] = node; |
| 192 | auto subresource = |
| 193 | std::find(pCB->imageSubresourceMap[imgpair.image].begin(), pCB->imageSubresourceMap[imgpair.image].end(), imgpair); |
| 194 | if (subresource == pCB->imageSubresourceMap[imgpair.image].end()) { |
| 195 | pCB->imageSubresourceMap[imgpair.image].push_back(imgpair); |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | void SetImageViewLayout(core_validation::layer_data *device_data, GLOBAL_CB_NODE *pCB, VkImageView imageView, |
| 200 | const VkImageLayout &layout) { |
| 201 | auto view_state = getImageViewState(device_data, imageView); |
| 202 | assert(view_state); |
| 203 | auto image = view_state->create_info.image; |
| 204 | const VkImageSubresourceRange &subRange = view_state->create_info.subresourceRange; |
| 205 | // TODO: Do not iterate over every possibility - consolidate where possible |
| 206 | for (uint32_t j = 0; j < subRange.levelCount; j++) { |
| 207 | uint32_t level = subRange.baseMipLevel + j; |
| 208 | for (uint32_t k = 0; k < subRange.layerCount; k++) { |
| 209 | uint32_t layer = subRange.baseArrayLayer + k; |
| 210 | VkImageSubresource sub = {subRange.aspectMask, level, layer}; |
| 211 | // TODO: If ImageView was created with depth or stencil, transition both layouts as the aspectMask is ignored and both |
| 212 | // are used. Verify that the extra implicit layout is OK for descriptor set layout validation |
| 213 | if (subRange.aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) { |
| 214 | if (vk_format_is_depth_and_stencil(view_state->create_info.format)) { |
| 215 | sub.aspectMask |= (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT); |
| 216 | } |
| 217 | } |
| 218 | SetLayout(device_data, pCB, image, sub, layout); |
| 219 | } |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | bool VerifyFramebufferAndRenderPassLayouts(core_validation::layer_data *device_data, GLOBAL_CB_NODE *pCB, |
| 224 | const VkRenderPassBeginInfo *pRenderPassBegin, |
| 225 | const FRAMEBUFFER_STATE *framebuffer_state) { |
| 226 | bool skip_call = false; |
| 227 | auto const pRenderPassInfo = getRenderPassState(device_data, pRenderPassBegin->renderPass)->createInfo.ptr(); |
| 228 | auto const &framebufferInfo = framebuffer_state->createInfo; |
| 229 | const auto report_data = core_validation::GetReportData(device_data); |
| 230 | if (pRenderPassInfo->attachmentCount != framebufferInfo.attachmentCount) { |
| 231 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, |
| 232 | DRAWSTATE_INVALID_RENDERPASS, "DS", |
| 233 | "You cannot start a render pass using a framebuffer " |
| 234 | "with a different number of attachments."); |
| 235 | } |
| 236 | for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) { |
| 237 | const VkImageView &image_view = framebufferInfo.pAttachments[i]; |
| 238 | auto view_state = getImageViewState(device_data, image_view); |
| 239 | assert(view_state); |
| 240 | const VkImage &image = view_state->create_info.image; |
| 241 | const VkImageSubresourceRange &subRange = view_state->create_info.subresourceRange; |
| 242 | IMAGE_CMD_BUF_LAYOUT_NODE newNode = {pRenderPassInfo->pAttachments[i].initialLayout, |
| 243 | pRenderPassInfo->pAttachments[i].initialLayout}; |
| 244 | // TODO: Do not iterate over every possibility - consolidate where possible |
| 245 | for (uint32_t j = 0; j < subRange.levelCount; j++) { |
| 246 | uint32_t level = subRange.baseMipLevel + j; |
| 247 | for (uint32_t k = 0; k < subRange.layerCount; k++) { |
| 248 | uint32_t layer = subRange.baseArrayLayer + k; |
| 249 | VkImageSubresource sub = {subRange.aspectMask, level, layer}; |
| 250 | IMAGE_CMD_BUF_LAYOUT_NODE node; |
| 251 | if (!FindCmdBufLayout(device_data, pCB, image, sub, node)) { |
| 252 | SetLayout(device_data, pCB, image, sub, newNode); |
| 253 | continue; |
| 254 | } |
| 255 | if (newNode.layout != VK_IMAGE_LAYOUT_UNDEFINED && newNode.layout != node.layout) { |
| 256 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, |
| 257 | DRAWSTATE_INVALID_RENDERPASS, "DS", |
| 258 | "You cannot start a render pass using attachment %u " |
| 259 | "where the render pass initial layout is %s and the previous " |
| 260 | "known layout of the attachment is %s. The layouts must match, or " |
| 261 | "the render pass initial layout for the attachment must be " |
| 262 | "VK_IMAGE_LAYOUT_UNDEFINED", |
| 263 | i, string_VkImageLayout(newNode.layout), string_VkImageLayout(node.layout)); |
| 264 | } |
| 265 | } |
| 266 | } |
| 267 | } |
| 268 | return skip_call; |
| 269 | } |
| 270 | |
| 271 | void TransitionAttachmentRefLayout(core_validation::layer_data *device_data, GLOBAL_CB_NODE *pCB, FRAMEBUFFER_STATE *pFramebuffer, |
| 272 | VkAttachmentReference ref) { |
| 273 | if (ref.attachment != VK_ATTACHMENT_UNUSED) { |
| 274 | auto image_view = pFramebuffer->createInfo.pAttachments[ref.attachment]; |
| 275 | SetImageViewLayout(device_data, pCB, image_view, ref.layout); |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | void TransitionSubpassLayouts(core_validation::layer_data *device_data, GLOBAL_CB_NODE *pCB, |
| 280 | const VkRenderPassBeginInfo *pRenderPassBegin, const int subpass_index, |
| 281 | FRAMEBUFFER_STATE *framebuffer_state) { |
| 282 | auto renderPass = getRenderPassState(device_data, pRenderPassBegin->renderPass); |
| 283 | if (!renderPass) return; |
| 284 | |
| 285 | if (framebuffer_state) { |
| 286 | auto const &subpass = renderPass->createInfo.pSubpasses[subpass_index]; |
| 287 | for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) { |
| 288 | TransitionAttachmentRefLayout(device_data, pCB, framebuffer_state, subpass.pInputAttachments[j]); |
| 289 | } |
| 290 | for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) { |
| 291 | TransitionAttachmentRefLayout(device_data, pCB, framebuffer_state, subpass.pColorAttachments[j]); |
| 292 | } |
| 293 | if (subpass.pDepthStencilAttachment) { |
| 294 | TransitionAttachmentRefLayout(device_data, pCB, framebuffer_state, *subpass.pDepthStencilAttachment); |
| 295 | } |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | bool TransitionImageAspectLayout(core_validation::layer_data *device_data, GLOBAL_CB_NODE *pCB, |
| 300 | const VkImageMemoryBarrier *mem_barrier, uint32_t level, uint32_t layer, |
| 301 | VkImageAspectFlags aspect) { |
| 302 | if (!(mem_barrier->subresourceRange.aspectMask & aspect)) { |
| 303 | return false; |
| 304 | } |
| 305 | VkImageSubresource sub = {aspect, level, layer}; |
| 306 | IMAGE_CMD_BUF_LAYOUT_NODE node; |
| 307 | if (!FindCmdBufLayout(device_data, pCB, mem_barrier->image, sub, node)) { |
| 308 | SetLayout(device_data, pCB, mem_barrier->image, sub, |
| 309 | IMAGE_CMD_BUF_LAYOUT_NODE(mem_barrier->oldLayout, mem_barrier->newLayout)); |
| 310 | return false; |
| 311 | } |
| 312 | bool skip = false; |
| 313 | if (mem_barrier->oldLayout == VK_IMAGE_LAYOUT_UNDEFINED) { |
| 314 | // TODO: Set memory invalid which is in mem_tracker currently |
| 315 | } else if (node.layout != mem_barrier->oldLayout) { |
| 316 | skip |= log_msg(core_validation::GetReportData(device_data), VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, |
| 317 | 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", |
| 318 | "You cannot transition the layout of aspect %d from %s when current layout is %s.", aspect, |
| 319 | string_VkImageLayout(mem_barrier->oldLayout), string_VkImageLayout(node.layout)); |
| 320 | } |
| 321 | SetLayout(device_data, pCB, mem_barrier->image, sub, mem_barrier->newLayout); |
| 322 | return skip; |
| 323 | } |
| 324 | |
| 325 | // TODO: Separate validation and layout state updates |
| 326 | bool TransitionImageLayouts(core_validation::layer_data *device_data, VkCommandBuffer cmdBuffer, uint32_t memBarrierCount, |
| 327 | const VkImageMemoryBarrier *pImgMemBarriers) { |
| 328 | GLOBAL_CB_NODE *pCB = getCBNode(device_data, cmdBuffer); |
| 329 | bool skip = false; |
| 330 | uint32_t levelCount = 0; |
| 331 | uint32_t layerCount = 0; |
| 332 | |
| 333 | for (uint32_t i = 0; i < memBarrierCount; ++i) { |
| 334 | auto mem_barrier = &pImgMemBarriers[i]; |
| 335 | if (!mem_barrier) continue; |
| 336 | // TODO: Do not iterate over every possibility - consolidate where possible |
| 337 | ResolveRemainingLevelsLayers(device_data, &levelCount, &layerCount, mem_barrier->subresourceRange, |
| 338 | getImageState(device_data, mem_barrier->image)); |
| 339 | |
| 340 | for (uint32_t j = 0; j < levelCount; j++) { |
| 341 | uint32_t level = mem_barrier->subresourceRange.baseMipLevel + j; |
| 342 | for (uint32_t k = 0; k < layerCount; k++) { |
| 343 | uint32_t layer = mem_barrier->subresourceRange.baseArrayLayer + k; |
| 344 | skip |= TransitionImageAspectLayout(device_data, pCB, mem_barrier, level, layer, VK_IMAGE_ASPECT_COLOR_BIT); |
| 345 | skip |= TransitionImageAspectLayout(device_data, pCB, mem_barrier, level, layer, VK_IMAGE_ASPECT_DEPTH_BIT); |
| 346 | skip |= TransitionImageAspectLayout(device_data, pCB, mem_barrier, level, layer, VK_IMAGE_ASPECT_STENCIL_BIT); |
| 347 | skip |= TransitionImageAspectLayout(device_data, pCB, mem_barrier, level, layer, VK_IMAGE_ASPECT_METADATA_BIT); |
| 348 | } |
| 349 | } |
| 350 | } |
| 351 | return skip; |
| 352 | } |
| 353 | |
| 354 | bool VerifySourceImageLayout(core_validation::layer_data *device_data, GLOBAL_CB_NODE *cb_node, VkImage srcImage, |
| 355 | VkImageSubresourceLayers subLayers, VkImageLayout srcImageLayout, |
| 356 | UNIQUE_VALIDATION_ERROR_CODE msgCode) { |
| 357 | const auto report_data = core_validation::GetReportData(device_data); |
| 358 | bool skip_call = false; |
| 359 | |
| 360 | for (uint32_t i = 0; i < subLayers.layerCount; ++i) { |
| 361 | uint32_t layer = i + subLayers.baseArrayLayer; |
| 362 | VkImageSubresource sub = {subLayers.aspectMask, subLayers.mipLevel, layer}; |
| 363 | IMAGE_CMD_BUF_LAYOUT_NODE node; |
| 364 | if (!FindCmdBufLayout(device_data, cb_node, srcImage, sub, node)) { |
| 365 | SetLayout(device_data, cb_node, srcImage, sub, IMAGE_CMD_BUF_LAYOUT_NODE(srcImageLayout, srcImageLayout)); |
| 366 | continue; |
| 367 | } |
| 368 | if (node.layout != srcImageLayout) { |
| 369 | // TODO: Improve log message in the next pass |
| 370 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, |
| 371 | __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", |
| 372 | "Cannot copy from an image whose source layout is %s " |
| 373 | "and doesn't match the current layout %s.", |
| 374 | string_VkImageLayout(srcImageLayout), string_VkImageLayout(node.layout)); |
| 375 | } |
| 376 | } |
| 377 | if (srcImageLayout != VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL) { |
| 378 | if (srcImageLayout == VK_IMAGE_LAYOUT_GENERAL) { |
| 379 | // TODO : Can we deal with image node from the top of call tree and avoid map look-up here? |
| 380 | auto image_state = getImageState(device_data, srcImage); |
| 381 | if (image_state->createInfo.tiling != VK_IMAGE_TILING_LINEAR) { |
| 382 | // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning. |
| 383 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, |
| 384 | __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", |
| 385 | "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL."); |
| 386 | } |
| 387 | } else { |
| 388 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, msgCode, |
| 389 | "DS", "Layout for input image is %s but can only be TRANSFER_SRC_OPTIMAL or GENERAL. %s", |
| 390 | string_VkImageLayout(srcImageLayout), validation_error_map[msgCode]); |
| 391 | } |
| 392 | } |
| 393 | return skip_call; |
| 394 | } |
| 395 | |
| 396 | bool VerifyDestImageLayout(core_validation::layer_data *device_data, GLOBAL_CB_NODE *cb_node, VkImage destImage, |
| 397 | VkImageSubresourceLayers subLayers, VkImageLayout destImageLayout, |
| 398 | UNIQUE_VALIDATION_ERROR_CODE msgCode) { |
| 399 | const auto report_data = core_validation::GetReportData(device_data); |
| 400 | bool skip_call = false; |
| 401 | |
| 402 | for (uint32_t i = 0; i < subLayers.layerCount; ++i) { |
| 403 | uint32_t layer = i + subLayers.baseArrayLayer; |
| 404 | VkImageSubresource sub = {subLayers.aspectMask, subLayers.mipLevel, layer}; |
| 405 | IMAGE_CMD_BUF_LAYOUT_NODE node; |
| 406 | if (!FindCmdBufLayout(device_data, cb_node, destImage, sub, node)) { |
| 407 | SetLayout(device_data, cb_node, destImage, sub, IMAGE_CMD_BUF_LAYOUT_NODE(destImageLayout, destImageLayout)); |
| 408 | continue; |
| 409 | } |
| 410 | if (node.layout != destImageLayout) { |
| 411 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, |
| 412 | __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", |
| 413 | "Cannot copy from an image whose dest layout is %s and " |
| 414 | "doesn't match the current layout %s.", |
| 415 | string_VkImageLayout(destImageLayout), string_VkImageLayout(node.layout)); |
| 416 | } |
| 417 | } |
| 418 | if (destImageLayout != VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) { |
| 419 | if (destImageLayout == VK_IMAGE_LAYOUT_GENERAL) { |
| 420 | auto image_state = getImageState(device_data, destImage); |
| 421 | if (image_state->createInfo.tiling != VK_IMAGE_TILING_LINEAR) { |
| 422 | // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning. |
| 423 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, |
| 424 | __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", |
| 425 | "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL."); |
| 426 | } |
| 427 | } else { |
| 428 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, msgCode, |
| 429 | "DS", "Layout for output image is %s but can only be TRANSFER_DST_OPTIMAL or GENERAL. %s", |
| 430 | string_VkImageLayout(destImageLayout), validation_error_map[msgCode]); |
| 431 | } |
| 432 | } |
| 433 | return skip_call; |
| 434 | } |
| 435 | |
| 436 | void TransitionFinalSubpassLayouts(core_validation::layer_data *device_data, GLOBAL_CB_NODE *pCB, |
| 437 | const VkRenderPassBeginInfo *pRenderPassBegin, FRAMEBUFFER_STATE *framebuffer_state) { |
| 438 | auto renderPass = getRenderPassState(device_data, pRenderPassBegin->renderPass); |
| 439 | if (!renderPass) return; |
| 440 | |
| 441 | const VkRenderPassCreateInfo *pRenderPassInfo = renderPass->createInfo.ptr(); |
| 442 | if (framebuffer_state) { |
| 443 | for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) { |
| 444 | auto image_view = framebuffer_state->createInfo.pAttachments[i]; |
| 445 | SetImageViewLayout(device_data, pCB, image_view, pRenderPassInfo->pAttachments[i].finalLayout); |
| 446 | } |
| 447 | } |
| 448 | } |
| 449 | |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 450 | bool PreCallValidateCreateImage(core_validation::layer_data *device_data, const VkImageCreateInfo *pCreateInfo, |
| 451 | const VkAllocationCallbacks *pAllocator, VkImage *pImage) { |
| 452 | bool skip_call = false; |
| 453 | VkImageFormatProperties ImageFormatProperties; |
| 454 | const VkPhysicalDevice physical_device = core_validation::GetPhysicalDevice(device_data); |
| 455 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 456 | |
| 457 | if (pCreateInfo->format != VK_FORMAT_UNDEFINED) { |
| 458 | VkFormatProperties properties; |
| 459 | core_validation::GetFormatPropertiesPointer(device_data)(physical_device, pCreateInfo->format, &properties); |
| 460 | |
| 461 | if ((pCreateInfo->tiling == VK_IMAGE_TILING_LINEAR) && (properties.linearTilingFeatures == 0)) { |
| 462 | std::stringstream ss; |
| 463 | ss << "vkCreateImage format parameter (" << string_VkFormat(pCreateInfo->format) << ") is an unsupported format"; |
| 464 | skip_call |= |
| 465 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, |
| 466 | VALIDATION_ERROR_02150, "IMAGE", "%s. %s", ss.str().c_str(), validation_error_map[VALIDATION_ERROR_02150]); |
| 467 | } |
| 468 | |
| 469 | if ((pCreateInfo->tiling == VK_IMAGE_TILING_OPTIMAL) && (properties.optimalTilingFeatures == 0)) { |
| 470 | std::stringstream ss; |
| 471 | ss << "vkCreateImage format parameter (" << string_VkFormat(pCreateInfo->format) << ") is an unsupported format"; |
| 472 | skip_call |= |
| 473 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, |
| 474 | VALIDATION_ERROR_02155, "IMAGE", "%s. %s", ss.str().c_str(), validation_error_map[VALIDATION_ERROR_02155]); |
| 475 | } |
| 476 | |
| 477 | // Validate that format supports usage as color attachment |
| 478 | if (pCreateInfo->usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) { |
| 479 | if ((pCreateInfo->tiling == VK_IMAGE_TILING_OPTIMAL) && |
| 480 | ((properties.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) == 0)) { |
| 481 | std::stringstream ss; |
| 482 | ss << "vkCreateImage: VkFormat for TILING_OPTIMAL image (" << string_VkFormat(pCreateInfo->format) |
| 483 | << ") does not support requested Image usage type VK_IMAGE_USAGE_COLOR_ATTACHMENT"; |
| 484 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 485 | __LINE__, VALIDATION_ERROR_02158, "IMAGE", "%s. %s", ss.str().c_str(), |
| 486 | validation_error_map[VALIDATION_ERROR_02158]); |
| 487 | } |
| 488 | if ((pCreateInfo->tiling == VK_IMAGE_TILING_LINEAR) && |
| 489 | ((properties.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) == 0)) { |
| 490 | std::stringstream ss; |
| 491 | ss << "vkCreateImage: VkFormat for TILING_LINEAR image (" << string_VkFormat(pCreateInfo->format) |
| 492 | << ") does not support requested Image usage type VK_IMAGE_USAGE_COLOR_ATTACHMENT"; |
| 493 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 494 | __LINE__, VALIDATION_ERROR_02153, "IMAGE", "%s. %s", ss.str().c_str(), |
| 495 | validation_error_map[VALIDATION_ERROR_02153]); |
| 496 | } |
| 497 | } |
| 498 | // Validate that format supports usage as depth/stencil attachment |
| 499 | if (pCreateInfo->usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) { |
| 500 | if ((pCreateInfo->tiling == VK_IMAGE_TILING_OPTIMAL) && |
| 501 | ((properties.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) == 0)) { |
| 502 | std::stringstream ss; |
| 503 | ss << "vkCreateImage: VkFormat for TILING_OPTIMAL image (" << string_VkFormat(pCreateInfo->format) |
| 504 | << ") does not support requested Image usage type VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT"; |
| 505 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 506 | __LINE__, VALIDATION_ERROR_02159, "IMAGE", "%s. %s", ss.str().c_str(), |
| 507 | validation_error_map[VALIDATION_ERROR_02159]); |
| 508 | } |
| 509 | if ((pCreateInfo->tiling == VK_IMAGE_TILING_LINEAR) && |
| 510 | ((properties.linearTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) == 0)) { |
| 511 | std::stringstream ss; |
| 512 | ss << "vkCreateImage: VkFormat for TILING_LINEAR image (" << string_VkFormat(pCreateInfo->format) |
| 513 | << ") does not support requested Image usage type VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT"; |
| 514 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 515 | __LINE__, VALIDATION_ERROR_02154, "IMAGE", "%s. %s", ss.str().c_str(), |
| 516 | validation_error_map[VALIDATION_ERROR_02154]); |
| 517 | } |
| 518 | } |
| 519 | } else { |
| 520 | skip_call |= |
| 521 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, |
| 522 | VALIDATION_ERROR_00715, "IMAGE", "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED. %s", |
| 523 | validation_error_map[VALIDATION_ERROR_00715]); |
| 524 | } |
| 525 | |
| 526 | // Internal call to get format info. Still goes through layers, could potentially go directly to ICD. |
| 527 | core_validation::GetImageFormatPropertiesPointer(device_data)(physical_device, pCreateInfo->format, pCreateInfo->imageType, |
| 528 | pCreateInfo->tiling, pCreateInfo->usage, pCreateInfo->flags, |
| 529 | &ImageFormatProperties); |
| 530 | |
| 531 | VkDeviceSize imageGranularity = core_validation::GetPhysicalDeviceProperties(device_data)->limits.bufferImageGranularity; |
| 532 | imageGranularity = imageGranularity == 1 ? 0 : imageGranularity; |
| 533 | |
Mark Lobodzinski | 688ed32 | 2017-01-27 11:13:21 -0700 | [diff] [blame] | 534 | if ((pCreateInfo->extent.width <= 0) || (pCreateInfo->extent.height <= 0) || (pCreateInfo->extent.depth <= 0)) { |
| 535 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__, |
| 536 | VALIDATION_ERROR_00716, "Image", |
| 537 | "CreateImage extent is 0 for at least one required dimension for image: " |
| 538 | "Width = %d Height = %d Depth = %d. %s", |
| 539 | pCreateInfo->extent.width, pCreateInfo->extent.height, pCreateInfo->extent.depth, |
| 540 | validation_error_map[VALIDATION_ERROR_00716]); |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | // TODO: VALIDATION_ERROR_02125 VALIDATION_ERROR_02126 VALIDATION_ERROR_02128 VALIDATION_ERROR_00720 |
| 544 | // All these extent-related VUs should be checked here |
| 545 | if ((pCreateInfo->extent.depth > ImageFormatProperties.maxExtent.depth) || |
| 546 | (pCreateInfo->extent.width > ImageFormatProperties.maxExtent.width) || |
| 547 | (pCreateInfo->extent.height > ImageFormatProperties.maxExtent.height)) { |
| 548 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__, |
| 549 | IMAGE_INVALID_FORMAT_LIMITS_VIOLATION, "Image", |
| 550 | "CreateImage extents exceed allowable limits for format: " |
| 551 | "Width = %d Height = %d Depth = %d: Limits for Width = %d Height = %d Depth = %d for format %s.", |
| 552 | pCreateInfo->extent.width, pCreateInfo->extent.height, pCreateInfo->extent.depth, |
| 553 | ImageFormatProperties.maxExtent.width, ImageFormatProperties.maxExtent.height, |
| 554 | ImageFormatProperties.maxExtent.depth, string_VkFormat(pCreateInfo->format)); |
| 555 | } |
| 556 | |
| 557 | uint64_t totalSize = ((uint64_t)pCreateInfo->extent.width * (uint64_t)pCreateInfo->extent.height * |
| 558 | (uint64_t)pCreateInfo->extent.depth * (uint64_t)pCreateInfo->arrayLayers * |
| 559 | (uint64_t)pCreateInfo->samples * (uint64_t)vk_format_get_size(pCreateInfo->format) + |
| 560 | (uint64_t)imageGranularity) & |
| 561 | ~(uint64_t)imageGranularity; |
| 562 | |
| 563 | if (totalSize > ImageFormatProperties.maxResourceSize) { |
| 564 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__, |
| 565 | IMAGE_INVALID_FORMAT_LIMITS_VIOLATION, "Image", |
| 566 | "CreateImage resource size exceeds allowable maximum " |
| 567 | "Image resource size = 0x%" PRIxLEAST64 ", maximum resource size = 0x%" PRIxLEAST64 " ", |
| 568 | totalSize, ImageFormatProperties.maxResourceSize); |
| 569 | } |
| 570 | |
| 571 | // TODO: VALIDATION_ERROR_02132 |
| 572 | if (pCreateInfo->mipLevels > ImageFormatProperties.maxMipLevels) { |
| 573 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__, |
| 574 | IMAGE_INVALID_FORMAT_LIMITS_VIOLATION, "Image", |
| 575 | "CreateImage mipLevels=%d exceeds allowable maximum supported by format of %d", pCreateInfo->mipLevels, |
| 576 | ImageFormatProperties.maxMipLevels); |
| 577 | } |
| 578 | |
| 579 | if (pCreateInfo->arrayLayers > ImageFormatProperties.maxArrayLayers) { |
| 580 | skip_call |= log_msg( |
| 581 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__, VALIDATION_ERROR_02133, |
| 582 | "Image", "CreateImage arrayLayers=%d exceeds allowable maximum supported by format of %d. %s", pCreateInfo->arrayLayers, |
| 583 | ImageFormatProperties.maxArrayLayers, validation_error_map[VALIDATION_ERROR_02133]); |
| 584 | } |
| 585 | |
| 586 | if ((pCreateInfo->samples & ImageFormatProperties.sampleCounts) == 0) { |
| 587 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__, |
| 588 | VALIDATION_ERROR_02138, "Image", "CreateImage samples %s is not supported by format 0x%.8X. %s", |
| 589 | string_VkSampleCountFlagBits(pCreateInfo->samples), ImageFormatProperties.sampleCounts, |
| 590 | validation_error_map[VALIDATION_ERROR_02138]); |
| 591 | } |
| 592 | |
| 593 | if (pCreateInfo->initialLayout != VK_IMAGE_LAYOUT_UNDEFINED && pCreateInfo->initialLayout != VK_IMAGE_LAYOUT_PREINITIALIZED) { |
| 594 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__, |
| 595 | VALIDATION_ERROR_00731, "Image", |
| 596 | "vkCreateImage parameter, pCreateInfo->initialLayout, must be VK_IMAGE_LAYOUT_UNDEFINED or " |
| 597 | "VK_IMAGE_LAYOUT_PREINITIALIZED. %s", |
| 598 | validation_error_map[VALIDATION_ERROR_00731]); |
| 599 | } |
| 600 | |
| 601 | return skip_call; |
| 602 | } |
| 603 | |
Mark Lobodzinski | 214144a | 2017-01-27 14:25:32 -0700 | [diff] [blame] | 604 | void PostCallRecordCreateImage(core_validation::layer_data *device_data, const VkImageCreateInfo *pCreateInfo, VkImage *pImage) { |
Mark Lobodzinski | 42fe5f7 | 2017-01-11 11:36:16 -0700 | [diff] [blame] | 605 | IMAGE_LAYOUT_NODE image_state; |
| 606 | image_state.layout = pCreateInfo->initialLayout; |
| 607 | image_state.format = pCreateInfo->format; |
Mark Lobodzinski | 214144a | 2017-01-27 14:25:32 -0700 | [diff] [blame] | 608 | 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] | 609 | ImageSubresourcePair subpair{*pImage, false, VkImageSubresource()}; |
Mark Lobodzinski | 214144a | 2017-01-27 14:25:32 -0700 | [diff] [blame] | 610 | (*core_validation::GetImageSubresourceMap(device_data))[*pImage].push_back(subpair); |
| 611 | (*core_validation::GetImageLayoutMap(device_data))[subpair] = image_state; |
Mark Lobodzinski | 42fe5f7 | 2017-01-11 11:36:16 -0700 | [diff] [blame] | 612 | } |
Mark Lobodzinski | 9ef5d56 | 2017-01-27 12:28:30 -0700 | [diff] [blame] | 613 | |
| 614 | bool PreCallValidateDestroyImage(core_validation::layer_data *device_data, VkImage image, IMAGE_STATE **image_state, |
| 615 | VK_OBJECT *obj_struct) { |
| 616 | const CHECK_DISABLED *disabled = core_validation::GetDisables(device_data); |
| 617 | *image_state = core_validation::getImageState(device_data, image); |
| 618 | *obj_struct = {reinterpret_cast<uint64_t &>(image), VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT}; |
| 619 | if (disabled->destroy_image) return false; |
| 620 | bool skip = false; |
| 621 | if (*image_state) { |
| 622 | skip |= core_validation::ValidateObjectNotInUse(device_data, *image_state, *obj_struct, VALIDATION_ERROR_00743); |
| 623 | } |
| 624 | return skip; |
| 625 | } |
| 626 | |
| 627 | void PostCallRecordDestroyImage(core_validation::layer_data *device_data, VkImage image, IMAGE_STATE *image_state, |
| 628 | VK_OBJECT obj_struct) { |
| 629 | core_validation::invalidateCommandBuffers(device_data, image_state->cb_bindings, obj_struct); |
| 630 | // Clean up memory mapping, bindings and range references for image |
| 631 | for (auto mem_binding : image_state->GetBoundMemory()) { |
| 632 | auto mem_info = core_validation::getMemObjInfo(device_data, mem_binding); |
| 633 | if (mem_info) { |
| 634 | core_validation::RemoveImageMemoryRange(obj_struct.handle, mem_info); |
| 635 | } |
| 636 | } |
| 637 | core_validation::ClearMemoryObjectBindings(device_data, obj_struct.handle, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT); |
| 638 | // Remove image from imageMap |
| 639 | core_validation::GetImageMap(device_data)->erase(image); |
| 640 | std::unordered_map<VkImage, std::vector<ImageSubresourcePair>> *imageSubresourceMap = |
| 641 | core_validation::GetImageSubresourceMap(device_data); |
| 642 | |
| 643 | const auto &sub_entry = imageSubresourceMap->find(image); |
| 644 | if (sub_entry != imageSubresourceMap->end()) { |
| 645 | for (const auto &pair : sub_entry->second) { |
| 646 | core_validation::GetImageLayoutMap(device_data)->erase(pair); |
| 647 | } |
| 648 | imageSubresourceMap->erase(sub_entry); |
| 649 | } |
| 650 | } |
Mark Lobodzinski | c409a58 | 2017-01-27 15:16:01 -0700 | [diff] [blame] | 651 | |
| 652 | bool ValidateImageAttributes(core_validation::layer_data *device_data, IMAGE_STATE *image_state, VkImageSubresourceRange range) { |
| 653 | bool skip = false; |
| 654 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 655 | |
| 656 | if (range.aspectMask != VK_IMAGE_ASPECT_COLOR_BIT) { |
| 657 | char const str[] = "vkCmdClearColorImage aspectMasks for all subresource ranges must be set to VK_IMAGE_ASPECT_COLOR_BIT"; |
| 658 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 659 | reinterpret_cast<uint64_t &>(image_state->image), __LINE__, DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", str); |
| 660 | } |
| 661 | |
| 662 | if (vk_format_is_depth_or_stencil(image_state->createInfo.format)) { |
| 663 | char const str[] = "vkCmdClearColorImage called with depth/stencil image."; |
| 664 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 665 | reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01088, "IMAGE", "%s. %s", str, |
| 666 | validation_error_map[VALIDATION_ERROR_01088]); |
| 667 | } else if (vk_format_is_compressed(image_state->createInfo.format)) { |
| 668 | char const str[] = "vkCmdClearColorImage called with compressed image."; |
| 669 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 670 | reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01088, "IMAGE", "%s. %s", str, |
| 671 | validation_error_map[VALIDATION_ERROR_01088]); |
| 672 | } |
| 673 | |
| 674 | if (!(image_state->createInfo.usage & VK_IMAGE_USAGE_TRANSFER_DST_BIT)) { |
| 675 | char const str[] = "vkCmdClearColorImage called with image created without VK_IMAGE_USAGE_TRANSFER_DST_BIT."; |
| 676 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 677 | reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01084, "IMAGE", "%s. %s", str, |
| 678 | validation_error_map[VALIDATION_ERROR_01084]); |
| 679 | } |
| 680 | return skip; |
| 681 | } |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 682 | |
Mark Lobodzinski | 9c93dbd | 2017-02-02 08:31:18 -0700 | [diff] [blame] | 683 | void ResolveRemainingLevelsLayers(core_validation::layer_data *dev_data, VkImageSubresourceRange *range, IMAGE_STATE *image_state) { |
| 684 | // If the caller used the special values VK_REMAINING_MIP_LEVELS and VK_REMAINING_ARRAY_LAYERS, resolve them now in our |
| 685 | // internal state to the actual values. |
| 686 | if (range->levelCount == VK_REMAINING_MIP_LEVELS) { |
| 687 | range->levelCount = image_state->createInfo.mipLevels - range->baseMipLevel; |
| 688 | } |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 689 | |
Mark Lobodzinski | 9c93dbd | 2017-02-02 08:31:18 -0700 | [diff] [blame] | 690 | if (range->layerCount == VK_REMAINING_ARRAY_LAYERS) { |
| 691 | range->layerCount = image_state->createInfo.arrayLayers - range->baseArrayLayer; |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 692 | } |
| 693 | } |
| 694 | |
| 695 | // Return the correct layer/level counts if the caller used the special values VK_REMAINING_MIP_LEVELS or VK_REMAINING_ARRAY_LAYERS. |
| 696 | void ResolveRemainingLevelsLayers(core_validation::layer_data *dev_data, uint32_t *levels, uint32_t *layers, |
Mark Lobodzinski | 9c93dbd | 2017-02-02 08:31:18 -0700 | [diff] [blame] | 697 | VkImageSubresourceRange range, IMAGE_STATE *image_state) { |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 698 | *levels = range.levelCount; |
| 699 | *layers = range.layerCount; |
Mark Lobodzinski | 9c93dbd | 2017-02-02 08:31:18 -0700 | [diff] [blame] | 700 | if (range.levelCount == VK_REMAINING_MIP_LEVELS) { |
| 701 | *levels = image_state->createInfo.mipLevels - range.baseMipLevel; |
| 702 | } |
| 703 | if (range.layerCount == VK_REMAINING_ARRAY_LAYERS) { |
| 704 | *layers = image_state->createInfo.arrayLayers - range.baseArrayLayer; |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 705 | } |
| 706 | } |
| 707 | |
Mark Lobodzinski | 9c93dbd | 2017-02-02 08:31:18 -0700 | [diff] [blame] | 708 | bool VerifyClearImageLayout(core_validation::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] | 709 | VkImageSubresourceRange range, VkImageLayout dest_image_layout, const char *func_name) { |
| 710 | bool skip = false; |
| 711 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 712 | |
| 713 | VkImageSubresourceRange resolved_range = range; |
Mark Lobodzinski | 9c93dbd | 2017-02-02 08:31:18 -0700 | [diff] [blame] | 714 | ResolveRemainingLevelsLayers(device_data, &resolved_range, image_state); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 715 | |
| 716 | if (dest_image_layout != VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) { |
| 717 | if (dest_image_layout == VK_IMAGE_LAYOUT_GENERAL) { |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 718 | if (image_state->createInfo.tiling != VK_IMAGE_TILING_LINEAR) { |
| 719 | // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning. |
| 720 | skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, |
| 721 | __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", |
| 722 | "%s: Layout for cleared image should be TRANSFER_DST_OPTIMAL instead of GENERAL.", func_name); |
| 723 | } |
| 724 | } else { |
| 725 | UNIQUE_VALIDATION_ERROR_CODE error_code = VALIDATION_ERROR_01086; |
| 726 | if (strcmp(func_name, "vkCmdClearDepthStencilImage()") == 0) { |
| 727 | error_code = VALIDATION_ERROR_01101; |
| 728 | } else { |
| 729 | assert(strcmp(func_name, "vkCmdClearColorImage()") == 0); |
| 730 | } |
| 731 | skip |= |
| 732 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, error_code, "DS", |
| 733 | "%s: Layout for cleared image is %s but can only be " |
| 734 | "TRANSFER_DST_OPTIMAL or GENERAL. %s", |
| 735 | func_name, string_VkImageLayout(dest_image_layout), validation_error_map[error_code]); |
| 736 | } |
| 737 | } |
| 738 | |
| 739 | for (uint32_t level_index = 0; level_index < resolved_range.levelCount; ++level_index) { |
| 740 | uint32_t level = level_index + resolved_range.baseMipLevel; |
| 741 | for (uint32_t layer_index = 0; layer_index < resolved_range.layerCount; ++layer_index) { |
| 742 | uint32_t layer = layer_index + resolved_range.baseArrayLayer; |
| 743 | VkImageSubresource sub = {resolved_range.aspectMask, level, layer}; |
| 744 | IMAGE_CMD_BUF_LAYOUT_NODE node; |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 745 | if (FindCmdBufLayout(device_data, cb_node, image_state->image, sub, node)) { |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 746 | if (node.layout != dest_image_layout) { |
| 747 | UNIQUE_VALIDATION_ERROR_CODE error_code = VALIDATION_ERROR_01085; |
| 748 | if (strcmp(func_name, "vkCmdClearDepthStencilImage()") == 0) { |
| 749 | error_code = VALIDATION_ERROR_01100; |
| 750 | } else { |
| 751 | assert(strcmp(func_name, "vkCmdClearColorImage()") == 0); |
| 752 | } |
| 753 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, |
| 754 | __LINE__, error_code, "DS", |
| 755 | "%s: Cannot clear an image whose layout is %s and " |
| 756 | "doesn't match the current layout %s. %s", |
| 757 | func_name, string_VkImageLayout(dest_image_layout), string_VkImageLayout(node.layout), |
| 758 | validation_error_map[error_code]); |
| 759 | } |
| 760 | } |
| 761 | } |
| 762 | } |
| 763 | |
| 764 | return skip; |
| 765 | } |
| 766 | |
Mark Lobodzinski | 9c93dbd | 2017-02-02 08:31:18 -0700 | [diff] [blame] | 767 | void RecordClearImageLayout(core_validation::layer_data *device_data, GLOBAL_CB_NODE *cb_node, VkImage image, |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 768 | VkImageSubresourceRange range, VkImageLayout dest_image_layout) { |
| 769 | VkImageSubresourceRange resolved_range = range; |
Mark Lobodzinski | 9c93dbd | 2017-02-02 08:31:18 -0700 | [diff] [blame] | 770 | ResolveRemainingLevelsLayers(device_data, &resolved_range, getImageState(device_data, image)); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 771 | |
| 772 | for (uint32_t level_index = 0; level_index < resolved_range.levelCount; ++level_index) { |
| 773 | uint32_t level = level_index + resolved_range.baseMipLevel; |
| 774 | for (uint32_t layer_index = 0; layer_index < resolved_range.layerCount; ++layer_index) { |
| 775 | uint32_t layer = layer_index + resolved_range.baseArrayLayer; |
| 776 | VkImageSubresource sub = {resolved_range.aspectMask, level, layer}; |
| 777 | IMAGE_CMD_BUF_LAYOUT_NODE node; |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 778 | if (!FindCmdBufLayout(device_data, cb_node, image, sub, node)) { |
| 779 | 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] | 780 | } |
| 781 | } |
| 782 | } |
| 783 | } |
| 784 | |
| 785 | bool PreCallValidateCmdClearColorImage(core_validation::layer_data *dev_data, VkCommandBuffer commandBuffer, VkImage image, |
| 786 | VkImageLayout imageLayout, uint32_t rangeCount, const VkImageSubresourceRange *pRanges) { |
| 787 | bool skip = false; |
| 788 | // TODO : Verify memory is in VK_IMAGE_STATE_CLEAR state |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 789 | auto cb_node = getCBNode(dev_data, commandBuffer); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 790 | auto image_state = getImageState(dev_data, image); |
| 791 | if (cb_node && image_state) { |
| 792 | skip |= ValidateMemoryIsBoundToImage(dev_data, image_state, "vkCmdClearColorImage()", VALIDATION_ERROR_02527); |
| 793 | skip |= ValidateCmd(dev_data, cb_node, CMD_CLEARCOLORIMAGE, "vkCmdClearColorImage()"); |
| 794 | skip |= insideRenderPass(dev_data, cb_node, "vkCmdClearColorImage()", VALIDATION_ERROR_01096); |
| 795 | for (uint32_t i = 0; i < rangeCount; ++i) { |
| 796 | skip |= ValidateImageAttributes(dev_data, image_state, pRanges[i]); |
Mark Lobodzinski | 9c93dbd | 2017-02-02 08:31:18 -0700 | [diff] [blame] | 797 | skip |= VerifyClearImageLayout(dev_data, cb_node, image_state, pRanges[i], imageLayout, "vkCmdClearColorImage()"); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 798 | } |
| 799 | } |
| 800 | return skip; |
| 801 | } |
| 802 | |
| 803 | // This state recording routine is shared between ClearColorImage and ClearDepthStencilImage |
| 804 | void PreCallRecordCmdClearImage(core_validation::layer_data *dev_data, VkCommandBuffer commandBuffer, VkImage image, |
| 805 | VkImageLayout imageLayout, uint32_t rangeCount, const VkImageSubresourceRange *pRanges, |
| 806 | CMD_TYPE cmd_type) { |
| 807 | auto cb_node = getCBNode(dev_data, commandBuffer); |
| 808 | auto image_state = getImageState(dev_data, image); |
| 809 | if (cb_node && image_state) { |
| 810 | AddCommandBufferBindingImage(dev_data, cb_node, image_state); |
| 811 | std::function<bool()> function = [=]() { |
| 812 | SetImageMemoryValid(dev_data, image_state, true); |
| 813 | return false; |
| 814 | }; |
| 815 | cb_node->validate_functions.push_back(function); |
| 816 | UpdateCmdBufferLastCmd(dev_data, cb_node, cmd_type); |
| 817 | for (uint32_t i = 0; i < rangeCount; ++i) { |
| 818 | RecordClearImageLayout(dev_data, cb_node, image, pRanges[i], imageLayout); |
| 819 | } |
| 820 | } |
| 821 | } |
| 822 | |
Mark Lobodzinski | 1241a31 | 2017-02-01 10:57:21 -0700 | [diff] [blame] | 823 | bool PreCallValidateCmdClearDepthStencilImage(core_validation::layer_data *device_data, VkCommandBuffer commandBuffer, |
| 824 | VkImage image, VkImageLayout imageLayout, uint32_t rangeCount, |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 825 | const VkImageSubresourceRange *pRanges) { |
| 826 | bool skip = false; |
Mark Lobodzinski | 1241a31 | 2017-02-01 10:57:21 -0700 | [diff] [blame] | 827 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 828 | |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 829 | // TODO : Verify memory is in VK_IMAGE_STATE_CLEAR state |
Mark Lobodzinski | 1241a31 | 2017-02-01 10:57:21 -0700 | [diff] [blame] | 830 | auto cb_node = getCBNode(device_data, commandBuffer); |
| 831 | auto image_state = getImageState(device_data, image); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 832 | if (cb_node && image_state) { |
Mark Lobodzinski | 1241a31 | 2017-02-01 10:57:21 -0700 | [diff] [blame] | 833 | skip |= ValidateMemoryIsBoundToImage(device_data, image_state, "vkCmdClearDepthStencilImage()", VALIDATION_ERROR_02528); |
| 834 | skip |= ValidateCmd(device_data, cb_node, CMD_CLEARDEPTHSTENCILIMAGE, "vkCmdClearDepthStencilImage()"); |
| 835 | skip |= insideRenderPass(device_data, cb_node, "vkCmdClearDepthStencilImage()", VALIDATION_ERROR_01111); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 836 | for (uint32_t i = 0; i < rangeCount; ++i) { |
Mark Lobodzinski | 9c93dbd | 2017-02-02 08:31:18 -0700 | [diff] [blame] | 837 | skip |= |
| 838 | VerifyClearImageLayout(device_data, cb_node, image_state, pRanges[i], imageLayout, "vkCmdClearDepthStencilImage()"); |
Mark Lobodzinski | 1241a31 | 2017-02-01 10:57:21 -0700 | [diff] [blame] | 839 | // Image aspect must be depth or stencil or both |
| 840 | if (((pRanges[i].aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) != VK_IMAGE_ASPECT_DEPTH_BIT) && |
| 841 | ((pRanges[i].aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) != VK_IMAGE_ASPECT_STENCIL_BIT)) { |
| 842 | char const str[] = |
| 843 | "vkCmdClearDepthStencilImage aspectMasks for all subresource ranges must be " |
| 844 | "set to VK_IMAGE_ASPECT_DEPTH_BIT and/or VK_IMAGE_ASPECT_STENCIL_BIT"; |
| 845 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 846 | (uint64_t)commandBuffer, __LINE__, DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", str); |
| 847 | } |
| 848 | } |
| 849 | if (image_state && !vk_format_is_depth_or_stencil(image_state->createInfo.format)) { |
| 850 | char const str[] = "vkCmdClearDepthStencilImage called without a depth/stencil image."; |
| 851 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 852 | reinterpret_cast<uint64_t &>(image), __LINE__, VALIDATION_ERROR_01103, "IMAGE", "%s. %s", str, |
| 853 | validation_error_map[VALIDATION_ERROR_01103]); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 854 | } |
| 855 | } |
| 856 | return skip; |
| 857 | } |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 858 | |
| 859 | // Returns true if [x, xoffset] and [y, yoffset] overlap |
| 860 | static bool RangesIntersect(int32_t start, uint32_t start_offset, int32_t end, uint32_t end_offset) { |
| 861 | bool result = false; |
| 862 | uint32_t intersection_min = std::max(static_cast<uint32_t>(start), static_cast<uint32_t>(end)); |
| 863 | uint32_t intersection_max = std::min(static_cast<uint32_t>(start) + start_offset, static_cast<uint32_t>(end) + end_offset); |
| 864 | |
| 865 | if (intersection_max > intersection_min) { |
| 866 | result = true; |
| 867 | } |
| 868 | return result; |
| 869 | } |
| 870 | |
| 871 | // Returns true if two VkImageCopy structures overlap |
| 872 | static bool RegionIntersects(const VkImageCopy *src, const VkImageCopy *dst, VkImageType type) { |
| 873 | bool result = false; |
| 874 | if ((src->srcSubresource.mipLevel == dst->dstSubresource.mipLevel) && |
| 875 | (RangesIntersect(src->srcSubresource.baseArrayLayer, src->srcSubresource.layerCount, dst->dstSubresource.baseArrayLayer, |
| 876 | dst->dstSubresource.layerCount))) { |
| 877 | result = true; |
| 878 | switch (type) { |
| 879 | case VK_IMAGE_TYPE_3D: |
| 880 | result &= RangesIntersect(src->srcOffset.z, src->extent.depth, dst->dstOffset.z, dst->extent.depth); |
| 881 | // Intentionally fall through to 2D case |
| 882 | case VK_IMAGE_TYPE_2D: |
| 883 | result &= RangesIntersect(src->srcOffset.y, src->extent.height, dst->dstOffset.y, dst->extent.height); |
| 884 | // Intentionally fall through to 1D case |
| 885 | case VK_IMAGE_TYPE_1D: |
| 886 | result &= RangesIntersect(src->srcOffset.x, src->extent.width, dst->dstOffset.x, dst->extent.width); |
| 887 | break; |
| 888 | default: |
| 889 | // Unrecognized or new IMAGE_TYPE enums will be caught in parameter_validation |
| 890 | assert(false); |
| 891 | } |
| 892 | } |
| 893 | return result; |
| 894 | } |
| 895 | |
| 896 | // Returns true if offset and extent exceed image extents |
| 897 | static bool ExceedsBounds(const VkOffset3D *offset, const VkExtent3D *extent, const IMAGE_STATE *image_state) { |
| 898 | bool result = false; |
| 899 | // Extents/depths cannot be negative but checks left in for clarity |
| 900 | switch (image_state->createInfo.imageType) { |
| 901 | case VK_IMAGE_TYPE_3D: // Validate z and depth |
| 902 | if ((offset->z + extent->depth > image_state->createInfo.extent.depth) || (offset->z < 0) || |
| 903 | ((offset->z + static_cast<int32_t>(extent->depth)) < 0)) { |
| 904 | result = true; |
| 905 | } |
| 906 | // Intentionally fall through to 2D case to check height |
| 907 | case VK_IMAGE_TYPE_2D: // Validate y and height |
| 908 | if ((offset->y + extent->height > image_state->createInfo.extent.height) || (offset->y < 0) || |
| 909 | ((offset->y + static_cast<int32_t>(extent->height)) < 0)) { |
| 910 | result = true; |
| 911 | } |
| 912 | // Intentionally fall through to 1D case to check width |
| 913 | case VK_IMAGE_TYPE_1D: // Validate x and width |
| 914 | if ((offset->x + extent->width > image_state->createInfo.extent.width) || (offset->x < 0) || |
| 915 | ((offset->x + static_cast<int32_t>(extent->width)) < 0)) { |
| 916 | result = true; |
| 917 | } |
| 918 | break; |
| 919 | default: |
| 920 | assert(false); |
| 921 | } |
| 922 | return result; |
| 923 | } |
| 924 | |
| 925 | bool PreCallValidateCmdCopyImage(core_validation::layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state, |
| 926 | IMAGE_STATE *dst_image_state, uint32_t region_count, const VkImageCopy *regions) { |
| 927 | bool skip = false; |
| 928 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 929 | VkCommandBuffer command_buffer = cb_node->commandBuffer; |
| 930 | |
| 931 | // TODO: This does not cover swapchain-created images. This should fall out when this layer is moved into the core_validation |
| 932 | // layer |
| 933 | if (src_image_state && dst_image_state) { |
| 934 | for (uint32_t i = 0; i < region_count; i++) { |
| 935 | if (regions[i].srcSubresource.layerCount == 0) { |
| 936 | std::stringstream ss; |
| 937 | ss << "vkCmdCopyImage: number of layers in pRegions[" << i << "] srcSubresource is zero"; |
| 938 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 939 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", |
| 940 | "%s", ss.str().c_str()); |
| 941 | } |
| 942 | |
| 943 | if (regions[i].dstSubresource.layerCount == 0) { |
| 944 | std::stringstream ss; |
| 945 | ss << "vkCmdCopyImage: number of layers in pRegions[" << i << "] dstSubresource is zero"; |
| 946 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 947 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", |
| 948 | "%s", ss.str().c_str()); |
| 949 | } |
| 950 | |
| 951 | // For each region the layerCount member of srcSubresource and dstSubresource must match |
| 952 | if (regions[i].srcSubresource.layerCount != regions[i].dstSubresource.layerCount) { |
| 953 | std::stringstream ss; |
| 954 | ss << "vkCmdCopyImage: number of layers in source and destination subresources for pRegions[" << i |
| 955 | << "] do not match"; |
| 956 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 957 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01198, "IMAGE", "%s. %s", |
| 958 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01198]); |
| 959 | } |
| 960 | |
| 961 | // For each region, the aspectMask member of srcSubresource and dstSubresource must match |
| 962 | if (regions[i].srcSubresource.aspectMask != regions[i].dstSubresource.aspectMask) { |
| 963 | char const str[] = "vkCmdCopyImage: Src and dest aspectMasks for each region must match"; |
| 964 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 965 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01197, "IMAGE", "%s. %s", |
| 966 | str, validation_error_map[VALIDATION_ERROR_01197]); |
| 967 | } |
| 968 | |
| 969 | // AspectMask must not contain VK_IMAGE_ASPECT_METADATA_BIT |
| 970 | if ((regions[i].srcSubresource.aspectMask & VK_IMAGE_ASPECT_METADATA_BIT) || |
| 971 | (regions[i].dstSubresource.aspectMask & VK_IMAGE_ASPECT_METADATA_BIT)) { |
| 972 | std::stringstream ss; |
| 973 | ss << "vkCmdCopyImage: pRegions[" << i << "] may not specify aspectMask containing VK_IMAGE_ASPECT_METADATA_BIT"; |
| 974 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 975 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01222, "IMAGE", "%s. %s", |
| 976 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01222]); |
| 977 | } |
| 978 | |
| 979 | // For each region, if aspectMask contains VK_IMAGE_ASPECT_COLOR_BIT, it must not contain either of |
| 980 | // VK_IMAGE_ASPECT_DEPTH_BIT or VK_IMAGE_ASPECT_STENCIL_BIT |
| 981 | if ((regions[i].srcSubresource.aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) && |
| 982 | (regions[i].srcSubresource.aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT))) { |
| 983 | char const str[] = "vkCmdCopyImage aspectMask cannot specify both COLOR and DEPTH/STENCIL aspects"; |
| 984 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 985 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01221, "IMAGE", "%s. %s", |
| 986 | str, validation_error_map[VALIDATION_ERROR_01221]); |
| 987 | } |
| 988 | |
| 989 | // If either of the calling command's src_image or dst_image parameters are of VkImageType VK_IMAGE_TYPE_3D, |
| 990 | // the baseArrayLayer and layerCount members of both srcSubresource and dstSubresource must be 0 and 1, respectively |
| 991 | if (((src_image_state->createInfo.imageType == VK_IMAGE_TYPE_3D) || |
| 992 | (dst_image_state->createInfo.imageType == VK_IMAGE_TYPE_3D)) && |
| 993 | ((regions[i].srcSubresource.baseArrayLayer != 0) || (regions[i].srcSubresource.layerCount != 1) || |
| 994 | (regions[i].dstSubresource.baseArrayLayer != 0) || (regions[i].dstSubresource.layerCount != 1))) { |
| 995 | std::stringstream ss; |
| 996 | ss << "vkCmdCopyImage: src or dstImage type was IMAGE_TYPE_3D, but in subRegion[" << i |
| 997 | << "] baseArrayLayer was not zero or layerCount was not 1."; |
| 998 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 999 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01199, "IMAGE", "%s. %s", |
| 1000 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01199]); |
| 1001 | } |
| 1002 | |
| 1003 | // MipLevel must be less than the mipLevels specified in VkImageCreateInfo when the image was created |
| 1004 | if (regions[i].srcSubresource.mipLevel >= src_image_state->createInfo.mipLevels) { |
| 1005 | std::stringstream ss; |
| 1006 | ss << "vkCmdCopyImage: pRegions[" << i |
| 1007 | << "] specifies a src mipLevel greater than the number specified when the srcImage was created."; |
| 1008 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1009 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01223, "IMAGE", "%s. %s", |
| 1010 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01223]); |
| 1011 | } |
| 1012 | if (regions[i].dstSubresource.mipLevel >= dst_image_state->createInfo.mipLevels) { |
| 1013 | std::stringstream ss; |
| 1014 | ss << "vkCmdCopyImage: pRegions[" << i |
| 1015 | << "] specifies a dst mipLevel greater than the number specified when the dstImage was created."; |
| 1016 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1017 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01223, "IMAGE", "%s. %s", |
| 1018 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01223]); |
| 1019 | } |
| 1020 | |
| 1021 | // (baseArrayLayer + layerCount) must be less than or equal to the arrayLayers specified in VkImageCreateInfo when the |
| 1022 | // image was created |
| 1023 | if ((regions[i].srcSubresource.baseArrayLayer + regions[i].srcSubresource.layerCount) > |
| 1024 | src_image_state->createInfo.arrayLayers) { |
| 1025 | std::stringstream ss; |
| 1026 | ss << "vkCmdCopyImage: srcImage arrayLayers was " << src_image_state->createInfo.arrayLayers << " but subRegion[" |
| 1027 | << i << "] baseArrayLayer + layerCount is " |
| 1028 | << (regions[i].srcSubresource.baseArrayLayer + regions[i].srcSubresource.layerCount); |
| 1029 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1030 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01224, "IMAGE", "%s. %s", |
| 1031 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01224]); |
| 1032 | } |
| 1033 | if ((regions[i].dstSubresource.baseArrayLayer + regions[i].dstSubresource.layerCount) > |
| 1034 | dst_image_state->createInfo.arrayLayers) { |
| 1035 | std::stringstream ss; |
| 1036 | ss << "vkCmdCopyImage: dstImage arrayLayers was " << dst_image_state->createInfo.arrayLayers << " but subRegion[" |
| 1037 | << i << "] baseArrayLayer + layerCount is " |
| 1038 | << (regions[i].dstSubresource.baseArrayLayer + regions[i].dstSubresource.layerCount); |
| 1039 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1040 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01224, "IMAGE", "%s. %s", |
| 1041 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01224]); |
| 1042 | } |
| 1043 | |
| 1044 | // The source region specified by a given element of regions must be a region that is contained within srcImage |
| 1045 | if (ExceedsBounds(®ions[i].srcOffset, ®ions[i].extent, src_image_state)) { |
| 1046 | std::stringstream ss; |
| 1047 | ss << "vkCmdCopyImage: srcSubResource in pRegions[" << i << "] exceeds extents srcImage was created with"; |
| 1048 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1049 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01175, "IMAGE", "%s. %s", |
| 1050 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01175]); |
| 1051 | } |
| 1052 | |
| 1053 | // The destination region specified by a given element of regions must be a region that is contained within dst_image |
| 1054 | if (ExceedsBounds(®ions[i].dstOffset, ®ions[i].extent, dst_image_state)) { |
| 1055 | std::stringstream ss; |
| 1056 | ss << "vkCmdCopyImage: dstSubResource in pRegions[" << i << "] exceeds extents dstImage was created with"; |
| 1057 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1058 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01176, "IMAGE", "%s. %s", |
| 1059 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01176]); |
| 1060 | } |
| 1061 | |
| 1062 | // The union of all source regions, and the union of all destination regions, specified by the elements of regions, |
| 1063 | // must not overlap in memory |
| 1064 | if (src_image_state->image == dst_image_state->image) { |
| 1065 | for (uint32_t j = 0; j < region_count; j++) { |
| 1066 | if (RegionIntersects(®ions[i], ®ions[j], src_image_state->createInfo.imageType)) { |
| 1067 | std::stringstream ss; |
| 1068 | ss << "vkCmdCopyImage: pRegions[" << i << "] src overlaps with pRegions[" << j << "]."; |
| 1069 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1070 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01177, "IMAGE", |
| 1071 | "%s. %s", ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01177]); |
| 1072 | } |
| 1073 | } |
| 1074 | } |
| 1075 | } |
| 1076 | |
| 1077 | // The formats of src_image and dst_image must be compatible. Formats are considered compatible if their texel size in bytes |
| 1078 | // is the same between both formats. For example, VK_FORMAT_R8G8B8A8_UNORM is compatible with VK_FORMAT_R32_UINT because |
| 1079 | // because both texels are 4 bytes in size. Depth/stencil formats must match exactly. |
| 1080 | if (vk_format_is_depth_or_stencil(src_image_state->createInfo.format) || |
| 1081 | vk_format_is_depth_or_stencil(dst_image_state->createInfo.format)) { |
| 1082 | if (src_image_state->createInfo.format != dst_image_state->createInfo.format) { |
| 1083 | char const str[] = "vkCmdCopyImage called with unmatched source and dest image depth/stencil formats."; |
| 1084 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1085 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_FORMAT, "IMAGE", |
| 1086 | str); |
| 1087 | } |
| 1088 | } else { |
| 1089 | size_t srcSize = vk_format_get_size(src_image_state->createInfo.format); |
| 1090 | size_t destSize = vk_format_get_size(dst_image_state->createInfo.format); |
| 1091 | if (srcSize != destSize) { |
| 1092 | char const str[] = "vkCmdCopyImage called with unmatched source and dest image format sizes."; |
| 1093 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1094 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01184, "IMAGE", "%s. %s", |
| 1095 | str, validation_error_map[VALIDATION_ERROR_01184]); |
| 1096 | } |
| 1097 | } |
| 1098 | } |
| 1099 | return skip; |
| 1100 | } |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1101 | |
| 1102 | // TODO : Should be tracking lastBound per commandBuffer and when draws occur, report based on that cmd buffer lastBound |
| 1103 | // Then need to synchronize the accesses based on cmd buffer so that if I'm reading state on one cmd buffer, updates |
| 1104 | // to that same cmd buffer by separate thread are not changing state from underneath us |
| 1105 | // Track the last cmd buffer touched by this thread |
| 1106 | static bool hasDrawCmd(GLOBAL_CB_NODE *pCB) { |
| 1107 | for (uint32_t i = 0; i < NUM_DRAW_TYPES; i++) { |
| 1108 | if (pCB->drawCount[i]) return true; |
| 1109 | } |
| 1110 | return false; |
| 1111 | } |
| 1112 | |
| 1113 | // Returns true if sub_rect is entirely contained within rect |
| 1114 | static inline bool ContainsRect(VkRect2D rect, VkRect2D sub_rect) { |
| 1115 | if ((sub_rect.offset.x < rect.offset.x) || (sub_rect.offset.x + sub_rect.extent.width > rect.offset.x + rect.extent.width) || |
| 1116 | (sub_rect.offset.y < rect.offset.y) || (sub_rect.offset.y + sub_rect.extent.height > rect.offset.y + rect.extent.height)) |
| 1117 | return false; |
| 1118 | return true; |
| 1119 | } |
| 1120 | |
| 1121 | bool PreCallValidateCmdClearAttachments(core_validation::layer_data *device_data, VkCommandBuffer commandBuffer, |
| 1122 | uint32_t attachmentCount, const VkClearAttachment *pAttachments, uint32_t rectCount, |
| 1123 | const VkClearRect *pRects) { |
| 1124 | GLOBAL_CB_NODE *cb_node = getCBNode(device_data, commandBuffer); |
| 1125 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 1126 | |
| 1127 | bool skip = false; |
| 1128 | if (cb_node) { |
| 1129 | skip |= ValidateCmd(device_data, cb_node, CMD_CLEARATTACHMENTS, "vkCmdClearAttachments()"); |
| 1130 | UpdateCmdBufferLastCmd(device_data, cb_node, CMD_CLEARATTACHMENTS); |
| 1131 | // Warn if this is issued prior to Draw Cmd and clearing the entire attachment |
| 1132 | if (!hasDrawCmd(cb_node) && (cb_node->activeRenderPassBeginInfo.renderArea.extent.width == pRects[0].rect.extent.width) && |
| 1133 | (cb_node->activeRenderPassBeginInfo.renderArea.extent.height == pRects[0].rect.extent.height)) { |
| 1134 | // There are times where app needs to use ClearAttachments (generally when reusing a buffer inside of a render pass) |
| 1135 | // 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 |
| 1136 | // call CmdClearAttachments. Otherwise this seems more like a performance warning. |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 1137 | skip |= |
| 1138 | log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1139 | reinterpret_cast<uint64_t &>(commandBuffer), 0, DRAWSTATE_CLEAR_CMD_BEFORE_DRAW, "DS", |
| 1140 | "vkCmdClearAttachments() issued on command buffer object 0x%p prior to any Draw Cmds." |
| 1141 | " It is recommended you use RenderPass LOAD_OP_CLEAR on Attachments prior to any Draw.", |
| 1142 | commandBuffer); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1143 | } |
| 1144 | skip |= outsideRenderPass(device_data, cb_node, "vkCmdClearAttachments()", VALIDATION_ERROR_01122); |
| 1145 | } |
| 1146 | |
| 1147 | // Validate that attachment is in reference list of active subpass |
| 1148 | if (cb_node->activeRenderPass) { |
| 1149 | const VkRenderPassCreateInfo *renderpass_create_info = cb_node->activeRenderPass->createInfo.ptr(); |
| 1150 | const VkSubpassDescription *subpass_desc = &renderpass_create_info->pSubpasses[cb_node->activeSubpass]; |
| 1151 | auto framebuffer = getFramebufferState(device_data, cb_node->activeFramebuffer); |
| 1152 | |
| 1153 | for (uint32_t i = 0; i < attachmentCount; i++) { |
| 1154 | auto clear_desc = &pAttachments[i]; |
| 1155 | VkImageView image_view = VK_NULL_HANDLE; |
| 1156 | |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 1157 | if (0 == clear_desc->aspectMask) { |
| 1158 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1159 | (uint64_t)commandBuffer, __LINE__, VALIDATION_ERROR_01128, "IMAGE", "%s", |
| 1160 | validation_error_map[VALIDATION_ERROR_01128]); |
| 1161 | } else if (clear_desc->aspectMask & VK_IMAGE_ASPECT_METADATA_BIT) { |
| 1162 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1163 | (uint64_t)commandBuffer, __LINE__, VALIDATION_ERROR_01126, "IMAGE", "%s", |
| 1164 | validation_error_map[VALIDATION_ERROR_01126]); |
| 1165 | } else if (clear_desc->aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) { |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1166 | if (clear_desc->colorAttachment >= subpass_desc->colorAttachmentCount) { |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 1167 | skip |= |
| 1168 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1169 | (uint64_t)commandBuffer, __LINE__, VALIDATION_ERROR_01114, "DS", |
| 1170 | "vkCmdClearAttachments() color attachment index %d out of range for active subpass %d. %s", |
| 1171 | clear_desc->colorAttachment, cb_node->activeSubpass, validation_error_map[VALIDATION_ERROR_01114]); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1172 | } else if (subpass_desc->pColorAttachments[clear_desc->colorAttachment].attachment == VK_ATTACHMENT_UNUSED) { |
| 1173 | skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 1174 | VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer, __LINE__, |
| 1175 | DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS", |
| 1176 | "vkCmdClearAttachments() color attachment index %d is VK_ATTACHMENT_UNUSED; ignored.", |
| 1177 | clear_desc->colorAttachment); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1178 | } else { |
| 1179 | image_view = framebuffer->createInfo |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 1180 | .pAttachments[subpass_desc->pColorAttachments[clear_desc->colorAttachment].attachment]; |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1181 | } |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 1182 | if ((clear_desc->aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) || |
| 1183 | (clear_desc->aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT)) { |
| 1184 | char const str[] = |
| 1185 | "vkCmdClearAttachments aspectMask [%d] must set only VK_IMAGE_ASPECT_COLOR_BIT of a color attachment. %s"; |
| 1186 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1187 | (uint64_t)commandBuffer, __LINE__, VALIDATION_ERROR_01125, "IMAGE", str, i, |
| 1188 | validation_error_map[VALIDATION_ERROR_01125]); |
| 1189 | } |
| 1190 | } else { // Must be depth and/or stencil |
| 1191 | if (((clear_desc->aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) != VK_IMAGE_ASPECT_DEPTH_BIT) && |
| 1192 | ((clear_desc->aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) != VK_IMAGE_ASPECT_STENCIL_BIT)) { |
| 1193 | char const str[] = "vkCmdClearAttachments aspectMask [%d] is not a valid combination of bits. %s"; |
| 1194 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1195 | (uint64_t)commandBuffer, __LINE__, VALIDATION_ERROR_01127, "IMAGE", str, i, |
| 1196 | validation_error_map[VALIDATION_ERROR_01127]); |
| 1197 | } |
| 1198 | if (!subpass_desc->pDepthStencilAttachment || |
| 1199 | (subpass_desc->pDepthStencilAttachment->attachment == VK_ATTACHMENT_UNUSED)) { |
| 1200 | skip |= log_msg( |
| 1201 | report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1202 | (uint64_t)commandBuffer, __LINE__, DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS", |
| 1203 | "vkCmdClearAttachments() depth/stencil clear with no depth/stencil attachment in subpass; ignored"); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1204 | } else { |
| 1205 | image_view = framebuffer->createInfo.pAttachments[subpass_desc->pDepthStencilAttachment->attachment]; |
| 1206 | } |
| 1207 | } |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1208 | if (image_view) { |
| 1209 | auto image_view_state = getImageViewState(device_data, image_view); |
| 1210 | for (uint32_t j = 0; j < rectCount; j++) { |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 1211 | // The rectangular region specified by a given element of pRects must be contained within the render area of |
| 1212 | // the current render pass instance |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1213 | if (false == ContainsRect(cb_node->activeRenderPassBeginInfo.renderArea, pRects[j].rect)) { |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 1214 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 1215 | __LINE__, VALIDATION_ERROR_01115, "DS", |
| 1216 | "vkCmdClearAttachments(): The area defined by pRects[%d] is not contained in the area of " |
| 1217 | "the current render pass instance. %s", |
| 1218 | j, validation_error_map[VALIDATION_ERROR_01115]); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1219 | } |
| 1220 | // The layers specified by a given element of pRects must be contained within every attachment that |
| 1221 | // pAttachments refers to |
| 1222 | auto attachment_base_array_layer = image_view_state->create_info.subresourceRange.baseArrayLayer; |
| 1223 | auto attachment_layer_count = image_view_state->create_info.subresourceRange.layerCount; |
| 1224 | if ((pRects[j].baseArrayLayer < attachment_base_array_layer) || pRects[j].layerCount > attachment_layer_count) { |
| 1225 | skip |= |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 1226 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 1227 | __LINE__, VALIDATION_ERROR_01116, "DS", |
| 1228 | "vkCmdClearAttachments(): The layers defined in pRects[%d] are not contained in the layers of " |
| 1229 | "pAttachment[%d]. %s", |
| 1230 | j, i, validation_error_map[VALIDATION_ERROR_01116]); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1231 | } |
| 1232 | } |
| 1233 | } |
| 1234 | } |
| 1235 | } |
| 1236 | return skip; |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 1237 | } |
| 1238 | |
| 1239 | bool PreCallValidateCmdResolveImage(core_validation::layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state, |
Mark Lobodzinski | 2a3368e | 2017-02-06 15:29:37 -0700 | [diff] [blame^] | 1240 | IMAGE_STATE *dst_image_state, uint32_t regionCount, const VkImageResolve *pRegions) { |
| 1241 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 1242 | bool skip = false; |
| 1243 | if (cb_node && src_image_state && dst_image_state) { |
| 1244 | skip |= ValidateMemoryIsBoundToImage(device_data, src_image_state, "vkCmdResolveImage()", VALIDATION_ERROR_02541); |
| 1245 | skip |= ValidateMemoryIsBoundToImage(device_data, dst_image_state, "vkCmdResolveImage()", VALIDATION_ERROR_02542); |
| 1246 | skip |= ValidateCmd(device_data, cb_node, CMD_RESOLVEIMAGE, "vkCmdResolveImage()"); |
| 1247 | skip |= insideRenderPass(device_data, cb_node, "vkCmdResolveImage()", VALIDATION_ERROR_01335); |
Mark Lobodzinski | 2a3368e | 2017-02-06 15:29:37 -0700 | [diff] [blame^] | 1248 | |
| 1249 | // For each region, the number of layers in the image subresource should not be zero |
| 1250 | // For each region, src and dest image aspect must be color only |
| 1251 | for (uint32_t i = 0; i < regionCount; i++) { |
| 1252 | if (pRegions[i].srcSubresource.layerCount == 0) { |
| 1253 | char const str[] = "vkCmdResolveImage: number of layers in source subresource is zero"; |
| 1254 | // TODO: Verify against Valid Use section of spec. Generally if something yield an undefined result, it's |
| 1255 | // invalid/error |
| 1256 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1257 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_ASPECT, |
| 1258 | "IMAGE", str); |
| 1259 | } |
| 1260 | |
| 1261 | if (pRegions[i].dstSubresource.layerCount == 0) { |
| 1262 | char const str[] = "vkCmdResolveImage: number of layers in destination subresource is zero"; |
| 1263 | |
| 1264 | // TODO: Verify against Valid Use section of spec. Generally if something yield an undefined result, it's |
| 1265 | // invalid/error |
| 1266 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1267 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_ASPECT, |
| 1268 | "IMAGE", str); |
| 1269 | } |
| 1270 | |
| 1271 | // TODO: VALIDATION_ERROR_01339 |
| 1272 | |
| 1273 | if ((pRegions[i].srcSubresource.aspectMask != VK_IMAGE_ASPECT_COLOR_BIT) || |
| 1274 | (pRegions[i].dstSubresource.aspectMask != VK_IMAGE_ASPECT_COLOR_BIT)) { |
| 1275 | char const str[] = |
| 1276 | "vkCmdResolveImage: src and dest aspectMasks for each region must specify only VK_IMAGE_ASPECT_COLOR_BIT"; |
| 1277 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1278 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_01338, "IMAGE", |
| 1279 | "%s. %s", str, validation_error_map[VALIDATION_ERROR_01338]); |
| 1280 | } |
| 1281 | } |
| 1282 | |
| 1283 | if (src_image_state->createInfo.format != dst_image_state->createInfo.format) { |
| 1284 | char const str[] = "vkCmdResolveImage called with unmatched source and dest formats."; |
| 1285 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1286 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_FORMAT, |
| 1287 | "IMAGE", str); |
| 1288 | } |
| 1289 | if (src_image_state->createInfo.imageType != dst_image_state->createInfo.imageType) { |
| 1290 | char const str[] = "vkCmdResolveImage called with unmatched source and dest image types."; |
| 1291 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1292 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_TYPE, "IMAGE", |
| 1293 | str); |
| 1294 | } |
| 1295 | if (src_image_state->createInfo.samples == VK_SAMPLE_COUNT_1_BIT) { |
| 1296 | char const str[] = "vkCmdResolveImage called with source sample count less than 2."; |
| 1297 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1298 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_01320, "IMAGE", "%s. %s", |
| 1299 | str, validation_error_map[VALIDATION_ERROR_01320]); |
| 1300 | } |
| 1301 | if (dst_image_state->createInfo.samples != VK_SAMPLE_COUNT_1_BIT) { |
| 1302 | char const str[] = "vkCmdResolveImage called with dest sample count greater than 1."; |
| 1303 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1304 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_01321, "IMAGE", "%s. %s", |
| 1305 | str, validation_error_map[VALIDATION_ERROR_01321]); |
| 1306 | } |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 1307 | } else { |
| 1308 | assert(0); |
| 1309 | } |
| 1310 | return skip; |
| 1311 | } |
| 1312 | |
| 1313 | void PreCallRecordCmdResolveImage(core_validation::layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state, |
| 1314 | IMAGE_STATE *dst_image_state) { |
| 1315 | // Update bindings between images and cmd buffer |
| 1316 | AddCommandBufferBindingImage(device_data, cb_node, src_image_state); |
| 1317 | AddCommandBufferBindingImage(device_data, cb_node, dst_image_state); |
| 1318 | |
| 1319 | std::function<bool()> function = [=]() { |
| 1320 | return ValidateImageMemoryIsValid(device_data, src_image_state, "vkCmdResolveImage()"); |
| 1321 | }; |
| 1322 | cb_node->validate_functions.push_back(function); |
| 1323 | function = [=]() { |
| 1324 | SetImageMemoryValid(device_data, dst_image_state, true); |
| 1325 | return false; |
| 1326 | }; |
| 1327 | cb_node->validate_functions.push_back(function); |
| 1328 | UpdateCmdBufferLastCmd(device_data, cb_node, CMD_RESOLVEIMAGE); |
| 1329 | } |
| 1330 | |
| 1331 | bool PreCallValidateCmdBlitImage(core_validation::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] | 1332 | IMAGE_STATE *dst_image_state, uint32_t regionCount, const VkImageBlit *pRegions, VkFilter filter) { |
| 1333 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 1334 | |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 1335 | bool skip = false; |
| 1336 | if (cb_node && src_image_state && dst_image_state) { |
| 1337 | 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] | 1338 | VALIDATION_ERROR_02194); |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 1339 | 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] | 1340 | VALIDATION_ERROR_02195); |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 1341 | skip |= ValidateMemoryIsBoundToImage(device_data, src_image_state, "vkCmdBlitImage()", VALIDATION_ERROR_02539); |
| 1342 | skip |= ValidateMemoryIsBoundToImage(device_data, dst_image_state, "vkCmdBlitImage()", VALIDATION_ERROR_02540); |
| 1343 | 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] | 1344 | "vkCmdBlitImage()", "VK_IMAGE_USAGE_TRANSFER_SRC_BIT"); |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 1345 | 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] | 1346 | "vkCmdBlitImage()", "VK_IMAGE_USAGE_TRANSFER_DST_BIT"); |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 1347 | skip |= ValidateCmd(device_data, cb_node, CMD_BLITIMAGE, "vkCmdBlitImage()"); |
| 1348 | skip |= insideRenderPass(device_data, cb_node, "vkCmdBlitImage()", VALIDATION_ERROR_01300); |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 1349 | |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 1350 | for (uint32_t i = 0; i < regionCount; i++) { |
Mark Lobodzinski | 23c8114 | 2017-02-06 15:04:23 -0700 | [diff] [blame] | 1351 | |
| 1352 | // Warn for zero-sized regions |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 1353 | if ((pRegions[i].srcOffsets[0].x == pRegions[i].srcOffsets[1].x) || |
| 1354 | (pRegions[i].srcOffsets[0].y == pRegions[i].srcOffsets[1].y) || |
| 1355 | (pRegions[i].srcOffsets[0].z == pRegions[i].srcOffsets[1].z)) { |
| 1356 | std::stringstream ss; |
| 1357 | ss << "vkCmdBlitImage: pRegions[" << i << "].srcOffsets specify a zero-volume area."; |
| 1358 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1359 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_INVALID_EXTENTS, "IMAGE", |
| 1360 | "%s", ss.str().c_str()); |
| 1361 | } |
| 1362 | if ((pRegions[i].dstOffsets[0].x == pRegions[i].dstOffsets[1].x) || |
| 1363 | (pRegions[i].dstOffsets[0].y == pRegions[i].dstOffsets[1].y) || |
| 1364 | (pRegions[i].dstOffsets[0].z == pRegions[i].dstOffsets[1].z)) { |
| 1365 | std::stringstream ss; |
| 1366 | ss << "vkCmdBlitImage: pRegions[" << i << "].dstOffsets specify a zero-volume area."; |
| 1367 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1368 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_INVALID_EXTENTS, "IMAGE", |
| 1369 | "%s", ss.str().c_str()); |
| 1370 | } |
Mark Lobodzinski | 23c8114 | 2017-02-06 15:04:23 -0700 | [diff] [blame] | 1371 | if (pRegions[i].srcSubresource.layerCount == 0) { |
| 1372 | char const str[] = "vkCmdBlitImage: number of layers in source subresource is zero"; |
| 1373 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1374 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_ASPECT, |
| 1375 | "IMAGE", str); |
| 1376 | } |
| 1377 | if (pRegions[i].dstSubresource.layerCount == 0) { |
| 1378 | char const str[] = "vkCmdBlitImage: number of layers in destination subresource is zero"; |
| 1379 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1380 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_ASPECT, |
| 1381 | "IMAGE", str); |
| 1382 | } |
| 1383 | |
| 1384 | // Check that src/dst layercounts match |
| 1385 | if (pRegions[i].srcSubresource.layerCount != pRegions[i].dstSubresource.layerCount) { |
| 1386 | skip |= |
| 1387 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1388 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_01304, "IMAGE", |
| 1389 | "vkCmdBlitImage: layerCount in source and destination subresource of pRegions[%d] does not match. %s", |
| 1390 | i, validation_error_map[VALIDATION_ERROR_01304]); |
| 1391 | } |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 1392 | } |
| 1393 | |
| 1394 | VkFormat src_format = src_image_state->createInfo.format; |
| 1395 | VkFormat dst_format = dst_image_state->createInfo.format; |
| 1396 | |
| 1397 | // Validate consistency for unsigned formats |
| 1398 | if (vk_format_is_uint(src_format) != vk_format_is_uint(dst_format)) { |
| 1399 | std::stringstream ss; |
| 1400 | ss << "vkCmdBlitImage: If one of srcImage and dstImage images has unsigned integer format, " |
| 1401 | << "the other one must also have unsigned integer format. " |
| 1402 | << "Source format is " << string_VkFormat(src_format) << " Destination format is " << string_VkFormat(dst_format); |
| 1403 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1404 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_02191, "IMAGE", "%s. %s", |
| 1405 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_02191]); |
| 1406 | } |
| 1407 | |
| 1408 | // Validate consistency for signed formats |
| 1409 | if (vk_format_is_sint(src_format) != vk_format_is_sint(dst_format)) { |
| 1410 | std::stringstream ss; |
| 1411 | ss << "vkCmdBlitImage: If one of srcImage and dstImage images has signed integer format, " |
| 1412 | << "the other one must also have signed integer format. " |
| 1413 | << "Source format is " << string_VkFormat(src_format) << " Destination format is " << string_VkFormat(dst_format); |
| 1414 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1415 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_02190, "IMAGE", "%s. %s", |
| 1416 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_02190]); |
| 1417 | } |
| 1418 | |
| 1419 | // Validate aspect bits and formats for depth/stencil images |
| 1420 | 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] | 1421 | |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 1422 | if (src_format != dst_format) { |
| 1423 | std::stringstream ss; |
| 1424 | ss << "vkCmdBlitImage: If one of srcImage and dstImage images has a format of depth, stencil or depth " |
| 1425 | << "stencil, the other one must have exactly the same format. " |
| 1426 | << "Source format is " << string_VkFormat(src_format) << " Destination format is " |
| 1427 | << string_VkFormat(dst_format); |
| 1428 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1429 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_02192, "IMAGE", |
| 1430 | "%s. %s", ss.str().c_str(), validation_error_map[VALIDATION_ERROR_02192]); |
| 1431 | } |
| 1432 | |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 1433 | for (uint32_t i = 0; i < regionCount; i++) { |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 1434 | VkImageAspectFlags srcAspect = pRegions[i].srcSubresource.aspectMask; |
| 1435 | VkImageAspectFlags dstAspect = pRegions[i].dstSubresource.aspectMask; |
| 1436 | |
| 1437 | if (srcAspect != dstAspect) { |
| 1438 | std::stringstream ss; |
| 1439 | ss << "vkCmdBlitImage: Image aspects of depth/stencil images should match"; |
| 1440 | // TODO: Verify against Valid Use section of spec, if this case yields undefined results, then it's an error |
| 1441 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1442 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_INVALID_IMAGE_ASPECT, |
| 1443 | "IMAGE", "%s", ss.str().c_str()); |
| 1444 | } |
| 1445 | if (vk_format_is_depth_and_stencil(src_format)) { |
| 1446 | if ((srcAspect != VK_IMAGE_ASPECT_DEPTH_BIT) && (srcAspect != VK_IMAGE_ASPECT_STENCIL_BIT)) { |
| 1447 | std::stringstream ss; |
| 1448 | ss << "vkCmdBlitImage: Combination depth/stencil image formats must have only one of " |
| 1449 | "VK_IMAGE_ASPECT_DEPTH_BIT " |
| 1450 | << "and VK_IMAGE_ASPECT_STENCIL_BIT set in srcImage and dstImage"; |
| 1451 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1452 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, |
| 1453 | DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", "%s", ss.str().c_str()); |
| 1454 | } |
| 1455 | } else if (vk_format_is_stencil_only(src_format)) { |
| 1456 | if (srcAspect != VK_IMAGE_ASPECT_STENCIL_BIT) { |
| 1457 | std::stringstream ss; |
| 1458 | ss << "vkCmdBlitImage: Stencil-only image formats must have only the VK_IMAGE_ASPECT_STENCIL_BIT " |
| 1459 | << "set in both the srcImage and dstImage"; |
| 1460 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1461 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, |
| 1462 | DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", "%s", ss.str().c_str()); |
| 1463 | } |
| 1464 | } else if (vk_format_is_depth_only(src_format)) { |
| 1465 | if (srcAspect != VK_IMAGE_ASPECT_DEPTH_BIT) { |
| 1466 | std::stringstream ss; |
| 1467 | ss << "vkCmdBlitImage: Depth-only image formats must have only the VK_IMAGE_ASPECT_DEPTH " |
| 1468 | << "set in both the srcImage and dstImage"; |
| 1469 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1470 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, |
| 1471 | DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", "%s", ss.str().c_str()); |
| 1472 | } |
| 1473 | } |
| 1474 | } |
| 1475 | } |
| 1476 | |
| 1477 | // Validate filter |
| 1478 | if (vk_format_is_depth_or_stencil(src_format) && (filter != VK_FILTER_NEAREST)) { |
| 1479 | std::stringstream ss; |
| 1480 | ss << "vkCmdBlitImage: If the format of srcImage is a depth, stencil, or depth stencil " |
| 1481 | << "then filter must be VK_FILTER_NEAREST."; |
| 1482 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1483 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_02193, "IMAGE", "%s. %s", |
| 1484 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_02193]); |
| 1485 | } |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 1486 | } else { |
| 1487 | assert(0); |
| 1488 | } |
| 1489 | return skip; |
| 1490 | } |
| 1491 | |
| 1492 | void PreCallRecordCmdBlitImage(core_validation::layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state, |
| 1493 | IMAGE_STATE *dst_image_state) { |
| 1494 | // Update bindings between images and cmd buffer |
| 1495 | AddCommandBufferBindingImage(device_data, cb_node, src_image_state); |
| 1496 | AddCommandBufferBindingImage(device_data, cb_node, dst_image_state); |
| 1497 | |
| 1498 | std::function<bool()> function = [=]() { return ValidateImageMemoryIsValid(device_data, src_image_state, "vkCmdBlitImage()"); }; |
| 1499 | cb_node->validate_functions.push_back(function); |
| 1500 | function = [=]() { |
| 1501 | SetImageMemoryValid(device_data, dst_image_state, true); |
| 1502 | return false; |
| 1503 | }; |
| 1504 | cb_node->validate_functions.push_back(function); |
| 1505 | UpdateCmdBufferLastCmd(device_data, cb_node, CMD_BLITIMAGE); |
| 1506 | } |
| 1507 | |
| 1508 | |