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