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 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 914 | bool PreCallValidateCmdCopyImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state, |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 915 | IMAGE_STATE *dst_image_state, uint32_t region_count, const VkImageCopy *regions) { |
| 916 | bool skip = false; |
| 917 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 918 | VkCommandBuffer command_buffer = cb_node->commandBuffer; |
| 919 | |
| 920 | // TODO: This does not cover swapchain-created images. This should fall out when this layer is moved into the core_validation |
| 921 | // layer |
| 922 | if (src_image_state && dst_image_state) { |
| 923 | for (uint32_t i = 0; i < region_count; i++) { |
| 924 | if (regions[i].srcSubresource.layerCount == 0) { |
| 925 | std::stringstream ss; |
| 926 | ss << "vkCmdCopyImage: number of layers in pRegions[" << i << "] srcSubresource is zero"; |
| 927 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 928 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", |
| 929 | "%s", ss.str().c_str()); |
| 930 | } |
| 931 | |
| 932 | if (regions[i].dstSubresource.layerCount == 0) { |
| 933 | std::stringstream ss; |
| 934 | ss << "vkCmdCopyImage: number of layers in pRegions[" << i << "] dstSubresource is zero"; |
| 935 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 936 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", |
| 937 | "%s", ss.str().c_str()); |
| 938 | } |
| 939 | |
| 940 | // For each region the layerCount member of srcSubresource and dstSubresource must match |
| 941 | if (regions[i].srcSubresource.layerCount != regions[i].dstSubresource.layerCount) { |
| 942 | std::stringstream ss; |
| 943 | ss << "vkCmdCopyImage: number of layers in source and destination subresources for pRegions[" << i |
| 944 | << "] do not match"; |
| 945 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 946 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01198, "IMAGE", "%s. %s", |
| 947 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01198]); |
| 948 | } |
| 949 | |
| 950 | // For each region, the aspectMask member of srcSubresource and dstSubresource must match |
| 951 | if (regions[i].srcSubresource.aspectMask != regions[i].dstSubresource.aspectMask) { |
| 952 | char const str[] = "vkCmdCopyImage: Src and dest aspectMasks for each region must match"; |
| 953 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 954 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01197, "IMAGE", "%s. %s", |
| 955 | str, validation_error_map[VALIDATION_ERROR_01197]); |
| 956 | } |
| 957 | |
| 958 | // AspectMask must not contain VK_IMAGE_ASPECT_METADATA_BIT |
| 959 | if ((regions[i].srcSubresource.aspectMask & VK_IMAGE_ASPECT_METADATA_BIT) || |
| 960 | (regions[i].dstSubresource.aspectMask & VK_IMAGE_ASPECT_METADATA_BIT)) { |
| 961 | std::stringstream ss; |
| 962 | ss << "vkCmdCopyImage: pRegions[" << i << "] may not specify aspectMask containing VK_IMAGE_ASPECT_METADATA_BIT"; |
| 963 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 964 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01222, "IMAGE", "%s. %s", |
| 965 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01222]); |
| 966 | } |
| 967 | |
| 968 | // For each region, if aspectMask contains VK_IMAGE_ASPECT_COLOR_BIT, it must not contain either of |
| 969 | // VK_IMAGE_ASPECT_DEPTH_BIT or VK_IMAGE_ASPECT_STENCIL_BIT |
| 970 | if ((regions[i].srcSubresource.aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) && |
| 971 | (regions[i].srcSubresource.aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT))) { |
| 972 | char const str[] = "vkCmdCopyImage aspectMask cannot specify both COLOR and DEPTH/STENCIL aspects"; |
| 973 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 974 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01221, "IMAGE", "%s. %s", |
| 975 | str, validation_error_map[VALIDATION_ERROR_01221]); |
| 976 | } |
| 977 | |
| 978 | // If either of the calling command's src_image or dst_image parameters are of VkImageType VK_IMAGE_TYPE_3D, |
| 979 | // the baseArrayLayer and layerCount members of both srcSubresource and dstSubresource must be 0 and 1, respectively |
| 980 | if (((src_image_state->createInfo.imageType == VK_IMAGE_TYPE_3D) || |
| 981 | (dst_image_state->createInfo.imageType == VK_IMAGE_TYPE_3D)) && |
| 982 | ((regions[i].srcSubresource.baseArrayLayer != 0) || (regions[i].srcSubresource.layerCount != 1) || |
| 983 | (regions[i].dstSubresource.baseArrayLayer != 0) || (regions[i].dstSubresource.layerCount != 1))) { |
| 984 | std::stringstream ss; |
| 985 | ss << "vkCmdCopyImage: src or dstImage type was IMAGE_TYPE_3D, but in subRegion[" << i |
| 986 | << "] baseArrayLayer was not zero or layerCount was not 1."; |
| 987 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 988 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01199, "IMAGE", "%s. %s", |
| 989 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01199]); |
| 990 | } |
| 991 | |
| 992 | // MipLevel must be less than the mipLevels specified in VkImageCreateInfo when the image was created |
| 993 | if (regions[i].srcSubresource.mipLevel >= src_image_state->createInfo.mipLevels) { |
| 994 | std::stringstream ss; |
| 995 | ss << "vkCmdCopyImage: pRegions[" << i |
| 996 | << "] specifies a src mipLevel greater than the number specified when the srcImage was created."; |
| 997 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 998 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01223, "IMAGE", "%s. %s", |
| 999 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01223]); |
| 1000 | } |
| 1001 | if (regions[i].dstSubresource.mipLevel >= dst_image_state->createInfo.mipLevels) { |
| 1002 | std::stringstream ss; |
| 1003 | ss << "vkCmdCopyImage: pRegions[" << i |
| 1004 | << "] specifies a dst mipLevel greater than the number specified when the dstImage was created."; |
| 1005 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1006 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01223, "IMAGE", "%s. %s", |
| 1007 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01223]); |
| 1008 | } |
| 1009 | |
| 1010 | // (baseArrayLayer + layerCount) must be less than or equal to the arrayLayers specified in VkImageCreateInfo when the |
| 1011 | // image was created |
| 1012 | if ((regions[i].srcSubresource.baseArrayLayer + regions[i].srcSubresource.layerCount) > |
| 1013 | src_image_state->createInfo.arrayLayers) { |
| 1014 | std::stringstream ss; |
| 1015 | ss << "vkCmdCopyImage: srcImage arrayLayers was " << src_image_state->createInfo.arrayLayers << " but subRegion[" |
| 1016 | << i << "] baseArrayLayer + layerCount is " |
| 1017 | << (regions[i].srcSubresource.baseArrayLayer + regions[i].srcSubresource.layerCount); |
| 1018 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1019 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01224, "IMAGE", "%s. %s", |
| 1020 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01224]); |
| 1021 | } |
| 1022 | if ((regions[i].dstSubresource.baseArrayLayer + regions[i].dstSubresource.layerCount) > |
| 1023 | dst_image_state->createInfo.arrayLayers) { |
| 1024 | std::stringstream ss; |
| 1025 | ss << "vkCmdCopyImage: dstImage arrayLayers was " << dst_image_state->createInfo.arrayLayers << " but subRegion[" |
| 1026 | << i << "] baseArrayLayer + layerCount is " |
| 1027 | << (regions[i].dstSubresource.baseArrayLayer + regions[i].dstSubresource.layerCount); |
| 1028 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1029 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01224, "IMAGE", "%s. %s", |
| 1030 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01224]); |
| 1031 | } |
| 1032 | |
| 1033 | // The source region specified by a given element of regions must be a region that is contained within srcImage |
| 1034 | if (ExceedsBounds(®ions[i].srcOffset, ®ions[i].extent, src_image_state)) { |
| 1035 | std::stringstream ss; |
| 1036 | ss << "vkCmdCopyImage: srcSubResource in pRegions[" << i << "] exceeds extents srcImage was created with"; |
| 1037 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1038 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01175, "IMAGE", "%s. %s", |
| 1039 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01175]); |
| 1040 | } |
| 1041 | |
| 1042 | // The destination region specified by a given element of regions must be a region that is contained within dst_image |
| 1043 | if (ExceedsBounds(®ions[i].dstOffset, ®ions[i].extent, dst_image_state)) { |
| 1044 | std::stringstream ss; |
| 1045 | ss << "vkCmdCopyImage: dstSubResource in pRegions[" << i << "] exceeds extents dstImage was created with"; |
| 1046 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1047 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01176, "IMAGE", "%s. %s", |
| 1048 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01176]); |
| 1049 | } |
| 1050 | |
| 1051 | // The union of all source regions, and the union of all destination regions, specified by the elements of regions, |
| 1052 | // must not overlap in memory |
| 1053 | if (src_image_state->image == dst_image_state->image) { |
| 1054 | for (uint32_t j = 0; j < region_count; j++) { |
| 1055 | if (RegionIntersects(®ions[i], ®ions[j], src_image_state->createInfo.imageType)) { |
| 1056 | std::stringstream ss; |
| 1057 | ss << "vkCmdCopyImage: pRegions[" << i << "] src overlaps with pRegions[" << j << "]."; |
| 1058 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1059 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01177, "IMAGE", |
| 1060 | "%s. %s", ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01177]); |
| 1061 | } |
| 1062 | } |
| 1063 | } |
| 1064 | } |
| 1065 | |
| 1066 | // The formats of src_image and dst_image must be compatible. Formats are considered compatible if their texel size in bytes |
| 1067 | // is the same between both formats. For example, VK_FORMAT_R8G8B8A8_UNORM is compatible with VK_FORMAT_R32_UINT because |
| 1068 | // because both texels are 4 bytes in size. Depth/stencil formats must match exactly. |
| 1069 | if (vk_format_is_depth_or_stencil(src_image_state->createInfo.format) || |
| 1070 | vk_format_is_depth_or_stencil(dst_image_state->createInfo.format)) { |
| 1071 | if (src_image_state->createInfo.format != dst_image_state->createInfo.format) { |
| 1072 | char const str[] = "vkCmdCopyImage called with unmatched source and dest image depth/stencil formats."; |
| 1073 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1074 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_FORMAT, "IMAGE", |
| 1075 | str); |
| 1076 | } |
| 1077 | } else { |
| 1078 | size_t srcSize = vk_format_get_size(src_image_state->createInfo.format); |
| 1079 | size_t destSize = vk_format_get_size(dst_image_state->createInfo.format); |
| 1080 | if (srcSize != destSize) { |
| 1081 | char const str[] = "vkCmdCopyImage called with unmatched source and dest image format sizes."; |
| 1082 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1083 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01184, "IMAGE", "%s. %s", |
| 1084 | str, validation_error_map[VALIDATION_ERROR_01184]); |
| 1085 | } |
| 1086 | } |
| 1087 | } |
| 1088 | return skip; |
| 1089 | } |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1090 | |
| 1091 | // TODO : Should be tracking lastBound per commandBuffer and when draws occur, report based on that cmd buffer lastBound |
| 1092 | // Then need to synchronize the accesses based on cmd buffer so that if I'm reading state on one cmd buffer, updates |
| 1093 | // to that same cmd buffer by separate thread are not changing state from underneath us |
| 1094 | // Track the last cmd buffer touched by this thread |
| 1095 | static bool hasDrawCmd(GLOBAL_CB_NODE *pCB) { |
| 1096 | for (uint32_t i = 0; i < NUM_DRAW_TYPES; i++) { |
| 1097 | if (pCB->drawCount[i]) return true; |
| 1098 | } |
| 1099 | return false; |
| 1100 | } |
| 1101 | |
| 1102 | // Returns true if sub_rect is entirely contained within rect |
| 1103 | static inline bool ContainsRect(VkRect2D rect, VkRect2D sub_rect) { |
| 1104 | if ((sub_rect.offset.x < rect.offset.x) || (sub_rect.offset.x + sub_rect.extent.width > rect.offset.x + rect.extent.width) || |
| 1105 | (sub_rect.offset.y < rect.offset.y) || (sub_rect.offset.y + sub_rect.extent.height > rect.offset.y + rect.extent.height)) |
| 1106 | return false; |
| 1107 | return true; |
| 1108 | } |
| 1109 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 1110 | bool PreCallValidateCmdClearAttachments(layer_data *device_data, VkCommandBuffer commandBuffer, uint32_t attachmentCount, |
| 1111 | const VkClearAttachment *pAttachments, uint32_t rectCount, const VkClearRect *pRects) { |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 1112 | GLOBAL_CB_NODE *cb_node = GetCBNode(device_data, commandBuffer); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1113 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 1114 | |
| 1115 | bool skip = false; |
| 1116 | if (cb_node) { |
| 1117 | skip |= ValidateCmd(device_data, cb_node, CMD_CLEARATTACHMENTS, "vkCmdClearAttachments()"); |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 1118 | core_validation::UpdateCmdBufferLastCmd(cb_node, CMD_CLEARATTACHMENTS); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1119 | // Warn if this is issued prior to Draw Cmd and clearing the entire attachment |
| 1120 | if (!hasDrawCmd(cb_node) && (cb_node->activeRenderPassBeginInfo.renderArea.extent.width == pRects[0].rect.extent.width) && |
| 1121 | (cb_node->activeRenderPassBeginInfo.renderArea.extent.height == pRects[0].rect.extent.height)) { |
| 1122 | // There are times where app needs to use ClearAttachments (generally when reusing a buffer inside of a render pass) |
| 1123 | // 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 |
| 1124 | // call CmdClearAttachments. Otherwise this seems more like a performance warning. |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 1125 | skip |= |
| 1126 | log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1127 | reinterpret_cast<uint64_t &>(commandBuffer), 0, DRAWSTATE_CLEAR_CMD_BEFORE_DRAW, "DS", |
| 1128 | "vkCmdClearAttachments() issued on command buffer object 0x%p prior to any Draw Cmds." |
| 1129 | " It is recommended you use RenderPass LOAD_OP_CLEAR on Attachments prior to any Draw.", |
| 1130 | commandBuffer); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1131 | } |
| 1132 | skip |= outsideRenderPass(device_data, cb_node, "vkCmdClearAttachments()", VALIDATION_ERROR_01122); |
| 1133 | } |
| 1134 | |
| 1135 | // Validate that attachment is in reference list of active subpass |
| 1136 | if (cb_node->activeRenderPass) { |
| 1137 | const VkRenderPassCreateInfo *renderpass_create_info = cb_node->activeRenderPass->createInfo.ptr(); |
| 1138 | const VkSubpassDescription *subpass_desc = &renderpass_create_info->pSubpasses[cb_node->activeSubpass]; |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 1139 | auto framebuffer = GetFramebufferState(device_data, cb_node->activeFramebuffer); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1140 | |
| 1141 | for (uint32_t i = 0; i < attachmentCount; i++) { |
| 1142 | auto clear_desc = &pAttachments[i]; |
| 1143 | VkImageView image_view = VK_NULL_HANDLE; |
| 1144 | |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 1145 | if (0 == clear_desc->aspectMask) { |
| 1146 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1147 | (uint64_t)commandBuffer, __LINE__, VALIDATION_ERROR_01128, "IMAGE", "%s", |
| 1148 | validation_error_map[VALIDATION_ERROR_01128]); |
| 1149 | } else if (clear_desc->aspectMask & VK_IMAGE_ASPECT_METADATA_BIT) { |
| 1150 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1151 | (uint64_t)commandBuffer, __LINE__, VALIDATION_ERROR_01126, "IMAGE", "%s", |
| 1152 | validation_error_map[VALIDATION_ERROR_01126]); |
| 1153 | } else if (clear_desc->aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) { |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1154 | if (clear_desc->colorAttachment >= subpass_desc->colorAttachmentCount) { |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 1155 | skip |= |
| 1156 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1157 | (uint64_t)commandBuffer, __LINE__, VALIDATION_ERROR_01114, "DS", |
| 1158 | "vkCmdClearAttachments() color attachment index %d out of range for active subpass %d. %s", |
| 1159 | clear_desc->colorAttachment, cb_node->activeSubpass, validation_error_map[VALIDATION_ERROR_01114]); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1160 | } else if (subpass_desc->pColorAttachments[clear_desc->colorAttachment].attachment == VK_ATTACHMENT_UNUSED) { |
| 1161 | skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 1162 | VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer, __LINE__, |
| 1163 | DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS", |
| 1164 | "vkCmdClearAttachments() color attachment index %d is VK_ATTACHMENT_UNUSED; ignored.", |
| 1165 | clear_desc->colorAttachment); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1166 | } else { |
| 1167 | image_view = framebuffer->createInfo |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 1168 | .pAttachments[subpass_desc->pColorAttachments[clear_desc->colorAttachment].attachment]; |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1169 | } |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 1170 | if ((clear_desc->aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) || |
| 1171 | (clear_desc->aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT)) { |
| 1172 | char const str[] = |
| 1173 | "vkCmdClearAttachments aspectMask [%d] must set only VK_IMAGE_ASPECT_COLOR_BIT of a color attachment. %s"; |
| 1174 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1175 | (uint64_t)commandBuffer, __LINE__, VALIDATION_ERROR_01125, "IMAGE", str, i, |
| 1176 | validation_error_map[VALIDATION_ERROR_01125]); |
| 1177 | } |
| 1178 | } else { // Must be depth and/or stencil |
| 1179 | if (((clear_desc->aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) != VK_IMAGE_ASPECT_DEPTH_BIT) && |
| 1180 | ((clear_desc->aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) != VK_IMAGE_ASPECT_STENCIL_BIT)) { |
| 1181 | char const str[] = "vkCmdClearAttachments aspectMask [%d] is not a valid combination of bits. %s"; |
| 1182 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1183 | (uint64_t)commandBuffer, __LINE__, VALIDATION_ERROR_01127, "IMAGE", str, i, |
| 1184 | validation_error_map[VALIDATION_ERROR_01127]); |
| 1185 | } |
| 1186 | if (!subpass_desc->pDepthStencilAttachment || |
| 1187 | (subpass_desc->pDepthStencilAttachment->attachment == VK_ATTACHMENT_UNUSED)) { |
| 1188 | skip |= log_msg( |
| 1189 | report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1190 | (uint64_t)commandBuffer, __LINE__, DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS", |
| 1191 | "vkCmdClearAttachments() depth/stencil clear with no depth/stencil attachment in subpass; ignored"); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1192 | } else { |
| 1193 | image_view = framebuffer->createInfo.pAttachments[subpass_desc->pDepthStencilAttachment->attachment]; |
| 1194 | } |
| 1195 | } |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1196 | if (image_view) { |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 1197 | auto image_view_state = GetImageViewState(device_data, image_view); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1198 | for (uint32_t j = 0; j < rectCount; j++) { |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 1199 | // The rectangular region specified by a given element of pRects must be contained within the render area of |
| 1200 | // the current render pass instance |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1201 | if (false == ContainsRect(cb_node->activeRenderPassBeginInfo.renderArea, pRects[j].rect)) { |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 1202 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 1203 | __LINE__, VALIDATION_ERROR_01115, "DS", |
| 1204 | "vkCmdClearAttachments(): The area defined by pRects[%d] is not contained in the area of " |
| 1205 | "the current render pass instance. %s", |
| 1206 | j, validation_error_map[VALIDATION_ERROR_01115]); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1207 | } |
| 1208 | // The layers specified by a given element of pRects must be contained within every attachment that |
| 1209 | // pAttachments refers to |
| 1210 | auto attachment_base_array_layer = image_view_state->create_info.subresourceRange.baseArrayLayer; |
| 1211 | auto attachment_layer_count = image_view_state->create_info.subresourceRange.layerCount; |
| 1212 | if ((pRects[j].baseArrayLayer < attachment_base_array_layer) || pRects[j].layerCount > attachment_layer_count) { |
| 1213 | skip |= |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 1214 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 1215 | __LINE__, VALIDATION_ERROR_01116, "DS", |
| 1216 | "vkCmdClearAttachments(): The layers defined in pRects[%d] are not contained in the layers of " |
| 1217 | "pAttachment[%d]. %s", |
| 1218 | j, i, validation_error_map[VALIDATION_ERROR_01116]); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1219 | } |
| 1220 | } |
| 1221 | } |
| 1222 | } |
| 1223 | } |
| 1224 | return skip; |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 1225 | } |
| 1226 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 1227 | 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] | 1228 | IMAGE_STATE *dst_image_state, uint32_t regionCount, const VkImageResolve *pRegions) { |
Mark Lobodzinski | 2a3368e | 2017-02-06 15:29:37 -0700 | [diff] [blame] | 1229 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 1230 | bool skip = false; |
| 1231 | if (cb_node && src_image_state && dst_image_state) { |
| 1232 | skip |= ValidateMemoryIsBoundToImage(device_data, src_image_state, "vkCmdResolveImage()", VALIDATION_ERROR_02541); |
| 1233 | skip |= ValidateMemoryIsBoundToImage(device_data, dst_image_state, "vkCmdResolveImage()", VALIDATION_ERROR_02542); |
| 1234 | skip |= ValidateCmd(device_data, cb_node, CMD_RESOLVEIMAGE, "vkCmdResolveImage()"); |
| 1235 | skip |= insideRenderPass(device_data, cb_node, "vkCmdResolveImage()", VALIDATION_ERROR_01335); |
Mark Lobodzinski | 2a3368e | 2017-02-06 15:29:37 -0700 | [diff] [blame] | 1236 | |
| 1237 | // For each region, the number of layers in the image subresource should not be zero |
| 1238 | // For each region, src and dest image aspect must be color only |
| 1239 | for (uint32_t i = 0; i < regionCount; i++) { |
| 1240 | if (pRegions[i].srcSubresource.layerCount == 0) { |
| 1241 | char const str[] = "vkCmdResolveImage: number of layers in source subresource is zero"; |
Mark Lobodzinski | 50fbef1 | 2017-02-06 15:31:33 -0700 | [diff] [blame] | 1242 | 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] | 1243 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_ASPECT, |
| 1244 | "IMAGE", str); |
| 1245 | } |
Mark Lobodzinski | 2a3368e | 2017-02-06 15:29:37 -0700 | [diff] [blame] | 1246 | if (pRegions[i].dstSubresource.layerCount == 0) { |
| 1247 | char const str[] = "vkCmdResolveImage: number of layers in destination subresource is zero"; |
Mark Lobodzinski | 50fbef1 | 2017-02-06 15:31:33 -0700 | [diff] [blame] | 1248 | 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] | 1249 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_ASPECT, |
| 1250 | "IMAGE", str); |
| 1251 | } |
Mark Lobodzinski | 50fbef1 | 2017-02-06 15:31:33 -0700 | [diff] [blame] | 1252 | if (pRegions[i].srcSubresource.layerCount != pRegions[i].dstSubresource.layerCount) { |
| 1253 | skip |= log_msg( |
| 1254 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1255 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_01339, "IMAGE", |
| 1256 | "vkCmdResolveImage: layerCount in source and destination subresource of pRegions[%d] does not match. %s", i, |
| 1257 | validation_error_map[VALIDATION_ERROR_01339]); |
| 1258 | } |
Mark Lobodzinski | 2a3368e | 2017-02-06 15:29:37 -0700 | [diff] [blame] | 1259 | if ((pRegions[i].srcSubresource.aspectMask != VK_IMAGE_ASPECT_COLOR_BIT) || |
| 1260 | (pRegions[i].dstSubresource.aspectMask != VK_IMAGE_ASPECT_COLOR_BIT)) { |
| 1261 | char const str[] = |
| 1262 | "vkCmdResolveImage: src and dest aspectMasks for each region must specify only VK_IMAGE_ASPECT_COLOR_BIT"; |
| 1263 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1264 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_01338, "IMAGE", |
| 1265 | "%s. %s", str, validation_error_map[VALIDATION_ERROR_01338]); |
| 1266 | } |
| 1267 | } |
| 1268 | |
| 1269 | if (src_image_state->createInfo.format != dst_image_state->createInfo.format) { |
| 1270 | char const str[] = "vkCmdResolveImage called with unmatched source and dest formats."; |
Mark Lobodzinski | 50fbef1 | 2017-02-06 15:31:33 -0700 | [diff] [blame] | 1271 | 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] | 1272 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_FORMAT, |
| 1273 | "IMAGE", str); |
| 1274 | } |
| 1275 | if (src_image_state->createInfo.imageType != dst_image_state->createInfo.imageType) { |
| 1276 | char const str[] = "vkCmdResolveImage called with unmatched source and dest image types."; |
Mark Lobodzinski | 50fbef1 | 2017-02-06 15:31:33 -0700 | [diff] [blame] | 1277 | 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] | 1278 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_TYPE, "IMAGE", |
| 1279 | str); |
| 1280 | } |
| 1281 | if (src_image_state->createInfo.samples == VK_SAMPLE_COUNT_1_BIT) { |
| 1282 | char const str[] = "vkCmdResolveImage called with source sample count less than 2."; |
| 1283 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1284 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_01320, "IMAGE", "%s. %s", |
| 1285 | str, validation_error_map[VALIDATION_ERROR_01320]); |
| 1286 | } |
| 1287 | if (dst_image_state->createInfo.samples != VK_SAMPLE_COUNT_1_BIT) { |
| 1288 | char const str[] = "vkCmdResolveImage called with dest sample count greater than 1."; |
| 1289 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1290 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_01321, "IMAGE", "%s. %s", |
| 1291 | str, validation_error_map[VALIDATION_ERROR_01321]); |
| 1292 | } |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 1293 | } else { |
| 1294 | assert(0); |
| 1295 | } |
| 1296 | return skip; |
| 1297 | } |
| 1298 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 1299 | void PreCallRecordCmdResolveImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state, |
| 1300 | IMAGE_STATE *dst_image_state) { |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 1301 | // Update bindings between images and cmd buffer |
| 1302 | AddCommandBufferBindingImage(device_data, cb_node, src_image_state); |
| 1303 | AddCommandBufferBindingImage(device_data, cb_node, dst_image_state); |
| 1304 | |
| 1305 | std::function<bool()> function = [=]() { |
| 1306 | return ValidateImageMemoryIsValid(device_data, src_image_state, "vkCmdResolveImage()"); |
| 1307 | }; |
| 1308 | cb_node->validate_functions.push_back(function); |
| 1309 | function = [=]() { |
| 1310 | SetImageMemoryValid(device_data, dst_image_state, true); |
| 1311 | return false; |
| 1312 | }; |
| 1313 | cb_node->validate_functions.push_back(function); |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 1314 | core_validation::UpdateCmdBufferLastCmd(cb_node, CMD_RESOLVEIMAGE); |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 1315 | } |
| 1316 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 1317 | 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] | 1318 | IMAGE_STATE *dst_image_state, uint32_t regionCount, const VkImageBlit *pRegions, VkFilter filter) { |
| 1319 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 1320 | |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 1321 | bool skip = false; |
| 1322 | if (cb_node && src_image_state && dst_image_state) { |
| 1323 | 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] | 1324 | VALIDATION_ERROR_02194); |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 1325 | 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] | 1326 | VALIDATION_ERROR_02195); |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 1327 | skip |= ValidateMemoryIsBoundToImage(device_data, src_image_state, "vkCmdBlitImage()", VALIDATION_ERROR_02539); |
| 1328 | skip |= ValidateMemoryIsBoundToImage(device_data, dst_image_state, "vkCmdBlitImage()", VALIDATION_ERROR_02540); |
| 1329 | 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] | 1330 | "vkCmdBlitImage()", "VK_IMAGE_USAGE_TRANSFER_SRC_BIT"); |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 1331 | 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] | 1332 | "vkCmdBlitImage()", "VK_IMAGE_USAGE_TRANSFER_DST_BIT"); |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 1333 | skip |= ValidateCmd(device_data, cb_node, CMD_BLITIMAGE, "vkCmdBlitImage()"); |
| 1334 | skip |= insideRenderPass(device_data, cb_node, "vkCmdBlitImage()", VALIDATION_ERROR_01300); |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 1335 | |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 1336 | for (uint32_t i = 0; i < regionCount; i++) { |
Mark Lobodzinski | 23c8114 | 2017-02-06 15:04:23 -0700 | [diff] [blame] | 1337 | |
| 1338 | // Warn for zero-sized regions |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 1339 | if ((pRegions[i].srcOffsets[0].x == pRegions[i].srcOffsets[1].x) || |
| 1340 | (pRegions[i].srcOffsets[0].y == pRegions[i].srcOffsets[1].y) || |
| 1341 | (pRegions[i].srcOffsets[0].z == pRegions[i].srcOffsets[1].z)) { |
| 1342 | std::stringstream ss; |
| 1343 | ss << "vkCmdBlitImage: pRegions[" << i << "].srcOffsets specify a zero-volume area."; |
| 1344 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1345 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_INVALID_EXTENTS, "IMAGE", |
| 1346 | "%s", ss.str().c_str()); |
| 1347 | } |
| 1348 | if ((pRegions[i].dstOffsets[0].x == pRegions[i].dstOffsets[1].x) || |
| 1349 | (pRegions[i].dstOffsets[0].y == pRegions[i].dstOffsets[1].y) || |
| 1350 | (pRegions[i].dstOffsets[0].z == pRegions[i].dstOffsets[1].z)) { |
| 1351 | std::stringstream ss; |
| 1352 | ss << "vkCmdBlitImage: pRegions[" << i << "].dstOffsets specify a zero-volume area."; |
| 1353 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1354 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_INVALID_EXTENTS, "IMAGE", |
| 1355 | "%s", ss.str().c_str()); |
| 1356 | } |
Mark Lobodzinski | 23c8114 | 2017-02-06 15:04:23 -0700 | [diff] [blame] | 1357 | if (pRegions[i].srcSubresource.layerCount == 0) { |
| 1358 | char const str[] = "vkCmdBlitImage: number of layers in source subresource is zero"; |
| 1359 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1360 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_ASPECT, |
| 1361 | "IMAGE", str); |
| 1362 | } |
| 1363 | if (pRegions[i].dstSubresource.layerCount == 0) { |
| 1364 | char const str[] = "vkCmdBlitImage: number of layers in destination subresource is zero"; |
| 1365 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1366 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_ASPECT, |
| 1367 | "IMAGE", str); |
| 1368 | } |
| 1369 | |
| 1370 | // Check that src/dst layercounts match |
| 1371 | if (pRegions[i].srcSubresource.layerCount != pRegions[i].dstSubresource.layerCount) { |
| 1372 | skip |= |
| 1373 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1374 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_01304, "IMAGE", |
| 1375 | "vkCmdBlitImage: layerCount in source and destination subresource of pRegions[%d] does not match. %s", |
| 1376 | i, validation_error_map[VALIDATION_ERROR_01304]); |
| 1377 | } |
Mark Lobodzinski | e7e85fd | 2017-02-07 13:44:57 -0700 | [diff] [blame] | 1378 | |
| 1379 | if (pRegions[i].srcSubresource.aspectMask != pRegions[i].dstSubresource.aspectMask) { |
| 1380 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1381 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_01303, "IMAGE", |
| 1382 | "vkCmdBlitImage: aspectMask members for pRegion[%d] do not match. %s", i, |
| 1383 | validation_error_map[VALIDATION_ERROR_01303]); |
| 1384 | } |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 1385 | } |
| 1386 | |
| 1387 | VkFormat src_format = src_image_state->createInfo.format; |
| 1388 | VkFormat dst_format = dst_image_state->createInfo.format; |
| 1389 | |
| 1390 | // Validate consistency for unsigned formats |
| 1391 | if (vk_format_is_uint(src_format) != vk_format_is_uint(dst_format)) { |
| 1392 | std::stringstream ss; |
| 1393 | ss << "vkCmdBlitImage: If one of srcImage and dstImage images has unsigned integer format, " |
| 1394 | << "the other one must also have unsigned integer format. " |
| 1395 | << "Source format is " << string_VkFormat(src_format) << " Destination format is " << string_VkFormat(dst_format); |
| 1396 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1397 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_02191, "IMAGE", "%s. %s", |
| 1398 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_02191]); |
| 1399 | } |
| 1400 | |
| 1401 | // Validate consistency for signed formats |
| 1402 | if (vk_format_is_sint(src_format) != vk_format_is_sint(dst_format)) { |
| 1403 | std::stringstream ss; |
| 1404 | ss << "vkCmdBlitImage: If one of srcImage and dstImage images has signed integer format, " |
| 1405 | << "the other one must also have signed integer format. " |
| 1406 | << "Source format is " << string_VkFormat(src_format) << " Destination format is " << string_VkFormat(dst_format); |
| 1407 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1408 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_02190, "IMAGE", "%s. %s", |
| 1409 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_02190]); |
| 1410 | } |
| 1411 | |
| 1412 | // Validate aspect bits and formats for depth/stencil images |
| 1413 | 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] | 1414 | |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 1415 | if (src_format != dst_format) { |
| 1416 | std::stringstream ss; |
| 1417 | ss << "vkCmdBlitImage: If one of srcImage and dstImage images has a format of depth, stencil or depth " |
| 1418 | << "stencil, the other one must have exactly the same format. " |
| 1419 | << "Source format is " << string_VkFormat(src_format) << " Destination format is " |
| 1420 | << string_VkFormat(dst_format); |
| 1421 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1422 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_02192, "IMAGE", |
| 1423 | "%s. %s", ss.str().c_str(), validation_error_map[VALIDATION_ERROR_02192]); |
| 1424 | } |
| 1425 | |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 1426 | for (uint32_t i = 0; i < regionCount; i++) { |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 1427 | VkImageAspectFlags srcAspect = pRegions[i].srcSubresource.aspectMask; |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 1428 | |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 1429 | if (vk_format_is_depth_and_stencil(src_format)) { |
| 1430 | if ((srcAspect != VK_IMAGE_ASPECT_DEPTH_BIT) && (srcAspect != VK_IMAGE_ASPECT_STENCIL_BIT)) { |
| 1431 | std::stringstream ss; |
| 1432 | ss << "vkCmdBlitImage: Combination depth/stencil image formats must have only one of " |
| 1433 | "VK_IMAGE_ASPECT_DEPTH_BIT " |
| 1434 | << "and VK_IMAGE_ASPECT_STENCIL_BIT set in srcImage and dstImage"; |
| 1435 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1436 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, |
| 1437 | DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", "%s", ss.str().c_str()); |
| 1438 | } |
| 1439 | } else if (vk_format_is_stencil_only(src_format)) { |
| 1440 | if (srcAspect != VK_IMAGE_ASPECT_STENCIL_BIT) { |
| 1441 | std::stringstream ss; |
| 1442 | ss << "vkCmdBlitImage: Stencil-only image formats must have only the VK_IMAGE_ASPECT_STENCIL_BIT " |
| 1443 | << "set in both the srcImage and dstImage"; |
| 1444 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1445 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, |
| 1446 | DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", "%s", ss.str().c_str()); |
| 1447 | } |
| 1448 | } else if (vk_format_is_depth_only(src_format)) { |
| 1449 | if (srcAspect != VK_IMAGE_ASPECT_DEPTH_BIT) { |
| 1450 | std::stringstream ss; |
| 1451 | ss << "vkCmdBlitImage: Depth-only image formats must have only the VK_IMAGE_ASPECT_DEPTH " |
| 1452 | << "set in both the srcImage and dstImage"; |
| 1453 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1454 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, |
| 1455 | DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", "%s", ss.str().c_str()); |
| 1456 | } |
| 1457 | } |
| 1458 | } |
| 1459 | } |
| 1460 | |
| 1461 | // Validate filter |
| 1462 | if (vk_format_is_depth_or_stencil(src_format) && (filter != VK_FILTER_NEAREST)) { |
| 1463 | std::stringstream ss; |
| 1464 | ss << "vkCmdBlitImage: If the format of srcImage is a depth, stencil, or depth stencil " |
| 1465 | << "then filter must be VK_FILTER_NEAREST."; |
| 1466 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1467 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_02193, "IMAGE", "%s. %s", |
| 1468 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_02193]); |
| 1469 | } |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 1470 | } else { |
| 1471 | assert(0); |
| 1472 | } |
| 1473 | return skip; |
| 1474 | } |
| 1475 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 1476 | void PreCallRecordCmdBlitImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state, |
| 1477 | IMAGE_STATE *dst_image_state) { |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 1478 | // Update bindings between images and cmd buffer |
| 1479 | AddCommandBufferBindingImage(device_data, cb_node, src_image_state); |
| 1480 | AddCommandBufferBindingImage(device_data, cb_node, dst_image_state); |
| 1481 | |
| 1482 | std::function<bool()> function = [=]() { return ValidateImageMemoryIsValid(device_data, src_image_state, "vkCmdBlitImage()"); }; |
| 1483 | cb_node->validate_functions.push_back(function); |
| 1484 | function = [=]() { |
| 1485 | SetImageMemoryValid(device_data, dst_image_state, true); |
| 1486 | return false; |
| 1487 | }; |
| 1488 | cb_node->validate_functions.push_back(function); |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 1489 | core_validation::UpdateCmdBufferLastCmd(cb_node, CMD_BLITIMAGE); |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 1490 | } |
| 1491 | |
Mark Lobodzinski | b0dd947 | 2017-02-07 16:38:17 -0700 | [diff] [blame] | 1492 | // This validates that the initial layout specified in the command buffer for the IMAGE is the same as the global IMAGE layout |
| 1493 | bool ValidateCmdBufImageLayouts(core_validation::layer_data *device_data, GLOBAL_CB_NODE *pCB) { |
| 1494 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 1495 | bool skip = false; |
Mark Lobodzinski | 4a3065e | 2017-02-07 16:36:03 -0700 | [diff] [blame] | 1496 | for (auto cb_image_data : pCB->imageLayoutMap) { |
| 1497 | VkImageLayout imageLayout; |
Mark Lobodzinski | b0dd947 | 2017-02-07 16:38:17 -0700 | [diff] [blame] | 1498 | if (!FindGlobalLayout(device_data, cb_image_data.first, imageLayout)) { |
| 1499 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__, |
| 1500 | DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", "Cannot submit cmd buffer using deleted image 0x%" PRIx64 ".", |
| 1501 | reinterpret_cast<const uint64_t &>(cb_image_data.first)); |
Mark Lobodzinski | 4a3065e | 2017-02-07 16:36:03 -0700 | [diff] [blame] | 1502 | } else { |
| 1503 | if (cb_image_data.second.initialLayout == VK_IMAGE_LAYOUT_UNDEFINED) { |
| 1504 | // TODO: Set memory invalid which is in mem_tracker currently |
| 1505 | } else if (imageLayout != cb_image_data.second.initialLayout) { |
| 1506 | if (cb_image_data.first.hasSubresource) { |
Mark Lobodzinski | b0dd947 | 2017-02-07 16:38:17 -0700 | [diff] [blame] | 1507 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1508 | reinterpret_cast<uint64_t &>(pCB->commandBuffer), __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, |
| 1509 | "DS", "Cannot submit cmd buffer using image (0x%" PRIx64 |
| 1510 | ") [sub-resource: aspectMask 0x%X array layer %u, mip level %u], " |
| 1511 | "with layout %s when first use is %s.", |
| 1512 | reinterpret_cast<const uint64_t &>(cb_image_data.first.image), |
| 1513 | cb_image_data.first.subresource.aspectMask, cb_image_data.first.subresource.arrayLayer, |
| 1514 | cb_image_data.first.subresource.mipLevel, string_VkImageLayout(imageLayout), |
| 1515 | string_VkImageLayout(cb_image_data.second.initialLayout)); |
Mark Lobodzinski | 4a3065e | 2017-02-07 16:36:03 -0700 | [diff] [blame] | 1516 | } else { |
Mark Lobodzinski | b0dd947 | 2017-02-07 16:38:17 -0700 | [diff] [blame] | 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 &>(pCB->commandBuffer), __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, |
| 1519 | "DS", "Cannot submit cmd buffer using image (0x%" PRIx64 |
| 1520 | ") with layout %s when " |
| 1521 | "first use is %s.", |
| 1522 | reinterpret_cast<const uint64_t &>(cb_image_data.first.image), |
| 1523 | string_VkImageLayout(imageLayout), string_VkImageLayout(cb_image_data.second.initialLayout)); |
Mark Lobodzinski | 4a3065e | 2017-02-07 16:36:03 -0700 | [diff] [blame] | 1524 | } |
| 1525 | } |
Mark Lobodzinski | b0dd947 | 2017-02-07 16:38:17 -0700 | [diff] [blame] | 1526 | SetGlobalLayout(device_data, cb_image_data.first, cb_image_data.second.layout); |
Mark Lobodzinski | 4a3065e | 2017-02-07 16:36:03 -0700 | [diff] [blame] | 1527 | } |
| 1528 | } |
Mark Lobodzinski | b0dd947 | 2017-02-07 16:38:17 -0700 | [diff] [blame] | 1529 | return skip; |
Mark Lobodzinski | 4a3065e | 2017-02-07 16:36:03 -0700 | [diff] [blame] | 1530 | } |
Mark Lobodzinski | b3829a5 | 2017-02-07 16:55:53 -0700 | [diff] [blame] | 1531 | |
| 1532 | // Print readable FlagBits in FlagMask |
| 1533 | static std::string string_VkAccessFlags(VkAccessFlags accessMask) { |
| 1534 | std::string result; |
| 1535 | std::string separator; |
| 1536 | |
| 1537 | if (accessMask == 0) { |
| 1538 | result = "[None]"; |
| 1539 | } else { |
| 1540 | result = "["; |
| 1541 | for (auto i = 0; i < 32; i++) { |
| 1542 | if (accessMask & (1 << i)) { |
| 1543 | result = result + separator + string_VkAccessFlagBits((VkAccessFlagBits)(1 << i)); |
| 1544 | separator = " | "; |
| 1545 | } |
| 1546 | } |
| 1547 | result = result + "]"; |
| 1548 | } |
| 1549 | return result; |
| 1550 | } |
| 1551 | |
Mark Lobodzinski | 9a8d40f | 2017-02-07 17:00:12 -0700 | [diff] [blame] | 1552 | // AccessFlags MUST have 'required_bit' set, and may have one or more of 'optional_bits' set. If required_bit is zero, accessMask |
| 1553 | // must have at least one of 'optional_bits' set |
Mark Lobodzinski | b3829a5 | 2017-02-07 16:55:53 -0700 | [diff] [blame] | 1554 | // 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] | 1555 | static bool ValidateMaskBits(core_validation::layer_data *device_data, VkCommandBuffer cmdBuffer, const VkAccessFlags &accessMask, |
| 1556 | const VkImageLayout &layout, VkAccessFlags required_bit, VkAccessFlags optional_bits, |
| 1557 | const char *type) { |
| 1558 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 1559 | bool skip = false; |
Mark Lobodzinski | b3829a5 | 2017-02-07 16:55:53 -0700 | [diff] [blame] | 1560 | |
| 1561 | if ((accessMask & required_bit) || (!required_bit && (accessMask & optional_bits))) { |
| 1562 | if (accessMask & ~(required_bit | optional_bits)) { |
| 1563 | // TODO: Verify against Valid Use |
Mark Lobodzinski | 9a8d40f | 2017-02-07 17:00:12 -0700 | [diff] [blame] | 1564 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, |
| 1565 | DRAWSTATE_INVALID_BARRIER, "DS", |
| 1566 | "Additional bits in %s accessMask 0x%X %s are specified when layout is %s.", type, accessMask, |
| 1567 | string_VkAccessFlags(accessMask).c_str(), string_VkImageLayout(layout)); |
Mark Lobodzinski | b3829a5 | 2017-02-07 16:55:53 -0700 | [diff] [blame] | 1568 | } |
| 1569 | } else { |
| 1570 | if (!required_bit) { |
Mark Lobodzinski | 9a8d40f | 2017-02-07 17:00:12 -0700 | [diff] [blame] | 1571 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, |
| 1572 | DRAWSTATE_INVALID_BARRIER, "DS", |
| 1573 | "%s AccessMask %d %s must contain at least one of access bits %d " |
| 1574 | "%s when layout is %s, unless the app has previously added a " |
| 1575 | "barrier for this transition.", |
| 1576 | type, accessMask, string_VkAccessFlags(accessMask).c_str(), optional_bits, |
| 1577 | string_VkAccessFlags(optional_bits).c_str(), string_VkImageLayout(layout)); |
Mark Lobodzinski | b3829a5 | 2017-02-07 16:55:53 -0700 | [diff] [blame] | 1578 | } else { |
| 1579 | std::string opt_bits; |
| 1580 | if (optional_bits != 0) { |
| 1581 | std::stringstream ss; |
| 1582 | ss << optional_bits; |
| 1583 | opt_bits = "and may have optional bits " + ss.str() + ' ' + string_VkAccessFlags(optional_bits); |
| 1584 | } |
Mark Lobodzinski | 9a8d40f | 2017-02-07 17:00:12 -0700 | [diff] [blame] | 1585 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, |
| 1586 | DRAWSTATE_INVALID_BARRIER, "DS", |
| 1587 | "%s AccessMask %d %s must have required access bit %d %s %s when " |
| 1588 | "layout is %s, unless the app has previously added a barrier for " |
| 1589 | "this transition.", |
| 1590 | type, accessMask, string_VkAccessFlags(accessMask).c_str(), required_bit, |
| 1591 | 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] | 1592 | } |
| 1593 | } |
Mark Lobodzinski | 9a8d40f | 2017-02-07 17:00:12 -0700 | [diff] [blame] | 1594 | return skip; |
Mark Lobodzinski | b3829a5 | 2017-02-07 16:55:53 -0700 | [diff] [blame] | 1595 | } |
| 1596 | |
Mark Lobodzinski | 9a8d40f | 2017-02-07 17:00:12 -0700 | [diff] [blame] | 1597 | bool ValidateMaskBitsFromLayouts(core_validation::layer_data *device_data, VkCommandBuffer cmdBuffer, |
| 1598 | const VkAccessFlags &accessMask, const VkImageLayout &layout, const char *type) { |
| 1599 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
Mark Lobodzinski | b3829a5 | 2017-02-07 16:55:53 -0700 | [diff] [blame] | 1600 | |
Mark Lobodzinski | 9a8d40f | 2017-02-07 17:00:12 -0700 | [diff] [blame] | 1601 | bool skip = false; |
Mark Lobodzinski | b3829a5 | 2017-02-07 16:55:53 -0700 | [diff] [blame] | 1602 | switch (layout) { |
Mark Lobodzinski | 9a8d40f | 2017-02-07 17:00:12 -0700 | [diff] [blame] | 1603 | case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: { |
| 1604 | skip |= ValidateMaskBits(device_data, cmdBuffer, accessMask, layout, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, |
| 1605 | VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT, type); |
| 1606 | break; |
Mark Lobodzinski | b3829a5 | 2017-02-07 16:55:53 -0700 | [diff] [blame] | 1607 | } |
Mark Lobodzinski | 9a8d40f | 2017-02-07 17:00:12 -0700 | [diff] [blame] | 1608 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: { |
| 1609 | skip |= ValidateMaskBits(device_data, cmdBuffer, accessMask, layout, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, |
| 1610 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT, type); |
| 1611 | break; |
| 1612 | } |
| 1613 | case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL: { |
| 1614 | skip |= ValidateMaskBits(device_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_WRITE_BIT, 0, type); |
| 1615 | break; |
| 1616 | } |
| 1617 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: { |
| 1618 | skip |= ValidateMaskBits( |
| 1619 | device_data, cmdBuffer, accessMask, layout, 0, |
| 1620 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT, |
| 1621 | type); |
| 1622 | break; |
| 1623 | } |
| 1624 | case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: { |
| 1625 | skip |= ValidateMaskBits(device_data, cmdBuffer, accessMask, layout, 0, |
| 1626 | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT | VK_ACCESS_SHADER_READ_BIT, type); |
| 1627 | break; |
| 1628 | } |
| 1629 | case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL: { |
| 1630 | skip |= ValidateMaskBits(device_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_READ_BIT, 0, type); |
| 1631 | break; |
| 1632 | } |
| 1633 | case VK_IMAGE_LAYOUT_PRESENT_SRC_KHR: { |
| 1634 | skip |= ValidateMaskBits(device_data, cmdBuffer, accessMask, layout, VK_ACCESS_MEMORY_READ_BIT, 0, type); |
| 1635 | break; |
| 1636 | } |
| 1637 | case VK_IMAGE_LAYOUT_UNDEFINED: { |
| 1638 | if (accessMask != 0) { |
| 1639 | // TODO: Verify against Valid Use section spec |
| 1640 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, |
| 1641 | DRAWSTATE_INVALID_BARRIER, "DS", |
| 1642 | "Additional bits in %s accessMask 0x%X %s are specified when layout is %s.", type, accessMask, |
| 1643 | string_VkAccessFlags(accessMask).c_str(), string_VkImageLayout(layout)); |
| 1644 | } |
| 1645 | break; |
| 1646 | } |
| 1647 | case VK_IMAGE_LAYOUT_GENERAL: |
| 1648 | default: { break; } |
Mark Lobodzinski | b3829a5 | 2017-02-07 16:55:53 -0700 | [diff] [blame] | 1649 | } |
Mark Lobodzinski | 9a8d40f | 2017-02-07 17:00:12 -0700 | [diff] [blame] | 1650 | return skip; |
Mark Lobodzinski | b3829a5 | 2017-02-07 16:55:53 -0700 | [diff] [blame] | 1651 | } |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 1652 | |
| 1653 | // 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] | 1654 | // VkAttachmentDescription structs that are used by the sub-passes of a renderpass. Initial check is to make sure that READ_ONLY |
| 1655 | // layout attachments don't have CLEAR as their loadOp. |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 1656 | bool ValidateLayoutVsAttachmentDescription(const debug_report_data *report_data, const VkImageLayout first_layout, |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 1657 | const uint32_t attachment, const VkAttachmentDescription &attachment_description) { |
| 1658 | bool skip = false; |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 1659 | // Verify that initial loadOp on READ_ONLY attachments is not CLEAR |
| 1660 | if (attachment_description.loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR) { |
| 1661 | if ((first_layout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL) || |
| 1662 | (first_layout == VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL)) { |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 1663 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, |
| 1664 | VkDebugReportObjectTypeEXT(0), __LINE__, VALIDATION_ERROR_02351, "DS", |
| 1665 | "Cannot clear attachment %d with invalid first layout %s. %s", attachment, |
| 1666 | string_VkImageLayout(first_layout), validation_error_map[VALIDATION_ERROR_02351]); |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 1667 | } |
| 1668 | } |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 1669 | return skip; |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 1670 | } |
| 1671 | |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 1672 | bool ValidateLayouts(core_validation::layer_data *device_data, VkDevice device, const VkRenderPassCreateInfo *pCreateInfo) { |
| 1673 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 1674 | bool skip = false; |
| 1675 | |
| 1676 | // Track when we're observing the first use of an attachment |
| 1677 | std::vector<bool> attach_first_use(pCreateInfo->attachmentCount, true); |
| 1678 | for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) { |
| 1679 | const VkSubpassDescription &subpass = pCreateInfo->pSubpasses[i]; |
| 1680 | for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) { |
| 1681 | auto attach_index = subpass.pColorAttachments[j].attachment; |
| 1682 | if (attach_index == VK_ATTACHMENT_UNUSED) continue; |
| 1683 | |
| 1684 | switch (subpass.pColorAttachments[j].layout) { |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 1685 | case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: |
| 1686 | // This is ideal. |
| 1687 | break; |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 1688 | |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 1689 | case VK_IMAGE_LAYOUT_GENERAL: |
| 1690 | // May not be optimal; TODO: reconsider this warning based on other constraints? |
| 1691 | skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 1692 | VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", |
| 1693 | "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL."); |
| 1694 | break; |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 1695 | |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 1696 | default: |
| 1697 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 1698 | __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", |
| 1699 | "Layout for color attachment is %s but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.", |
| 1700 | string_VkImageLayout(subpass.pColorAttachments[j].layout)); |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 1701 | } |
| 1702 | |
| 1703 | if (attach_first_use[attach_index]) { |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 1704 | skip |= ValidateLayoutVsAttachmentDescription(report_data, subpass.pColorAttachments[j].layout, attach_index, |
| 1705 | pCreateInfo->pAttachments[attach_index]); |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 1706 | } |
| 1707 | attach_first_use[attach_index] = false; |
| 1708 | } |
| 1709 | if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) { |
| 1710 | switch (subpass.pDepthStencilAttachment->layout) { |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 1711 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: |
| 1712 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: |
| 1713 | // These are ideal. |
| 1714 | break; |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 1715 | |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 1716 | case VK_IMAGE_LAYOUT_GENERAL: |
| 1717 | // May not be optimal; TODO: reconsider this warning based on other constraints? GENERAL can be better than |
| 1718 | // doing a bunch of transitions. |
| 1719 | skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 1720 | VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", |
| 1721 | "GENERAL layout for depth attachment may not give optimal performance."); |
| 1722 | break; |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 1723 | |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 1724 | default: |
| 1725 | // No other layouts are acceptable |
| 1726 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 1727 | __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", |
| 1728 | "Layout for depth attachment is %s but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL, " |
| 1729 | "DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.", |
| 1730 | string_VkImageLayout(subpass.pDepthStencilAttachment->layout)); |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 1731 | } |
| 1732 | |
| 1733 | auto attach_index = subpass.pDepthStencilAttachment->attachment; |
| 1734 | if (attach_first_use[attach_index]) { |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 1735 | skip |= ValidateLayoutVsAttachmentDescription(report_data, subpass.pDepthStencilAttachment->layout, attach_index, |
| 1736 | pCreateInfo->pAttachments[attach_index]); |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 1737 | } |
| 1738 | attach_first_use[attach_index] = false; |
| 1739 | } |
| 1740 | for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) { |
| 1741 | auto attach_index = subpass.pInputAttachments[j].attachment; |
| 1742 | if (attach_index == VK_ATTACHMENT_UNUSED) continue; |
| 1743 | |
| 1744 | switch (subpass.pInputAttachments[j].layout) { |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 1745 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: |
| 1746 | case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: |
| 1747 | // These are ideal. |
| 1748 | break; |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 1749 | |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 1750 | case VK_IMAGE_LAYOUT_GENERAL: |
| 1751 | // May not be optimal. TODO: reconsider this warning based on other constraints. |
| 1752 | skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 1753 | VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", |
| 1754 | "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL."); |
| 1755 | break; |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 1756 | |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 1757 | default: |
| 1758 | // No other layouts are acceptable |
| 1759 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, |
| 1760 | DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", |
| 1761 | "Layout for input attachment is %s but can only be READ_ONLY_OPTIMAL or GENERAL.", |
| 1762 | string_VkImageLayout(subpass.pInputAttachments[j].layout)); |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 1763 | } |
| 1764 | |
| 1765 | if (attach_first_use[attach_index]) { |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 1766 | skip |= ValidateLayoutVsAttachmentDescription(report_data, subpass.pInputAttachments[j].layout, attach_index, |
| 1767 | pCreateInfo->pAttachments[attach_index]); |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 1768 | } |
| 1769 | attach_first_use[attach_index] = false; |
| 1770 | } |
| 1771 | } |
| 1772 | return skip; |
| 1773 | } |
Mark Lobodzinski | 08f14fa | 2017-02-07 17:20:06 -0700 | [diff] [blame] | 1774 | |
| 1775 | // 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] | 1776 | bool ValidateMapImageLayouts(core_validation::layer_data *device_data, VkDevice device, DEVICE_MEM_INFO const *mem_info, |
| 1777 | VkDeviceSize offset, VkDeviceSize end_offset) { |
| 1778 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 1779 | bool skip = false; |
| 1780 | // Iterate over all bound image ranges and verify that for any that overlap the map ranges, the layouts are |
| 1781 | // VK_IMAGE_LAYOUT_PREINITIALIZED or VK_IMAGE_LAYOUT_GENERAL |
Mark Lobodzinski | 08f14fa | 2017-02-07 17:20:06 -0700 | [diff] [blame] | 1782 | // TODO : This can be optimized if we store ranges based on starting address and early exit when we pass our range |
| 1783 | for (auto image_handle : mem_info->bound_images) { |
| 1784 | auto img_it = mem_info->bound_ranges.find(image_handle); |
| 1785 | if (img_it != mem_info->bound_ranges.end()) { |
Mark Lobodzinski | ac23ec8 | 2017-02-07 17:21:55 -0700 | [diff] [blame] | 1786 | if (rangesIntersect(device_data, &img_it->second, offset, end_offset)) { |
Mark Lobodzinski | 08f14fa | 2017-02-07 17:20:06 -0700 | [diff] [blame] | 1787 | std::vector<VkImageLayout> layouts; |
Mark Lobodzinski | ac23ec8 | 2017-02-07 17:21:55 -0700 | [diff] [blame] | 1788 | if (FindLayouts(device_data, VkImage(image_handle), layouts)) { |
Mark Lobodzinski | 08f14fa | 2017-02-07 17:20:06 -0700 | [diff] [blame] | 1789 | for (auto layout : layouts) { |
| 1790 | if (layout != VK_IMAGE_LAYOUT_PREINITIALIZED && layout != VK_IMAGE_LAYOUT_GENERAL) { |
Mark Lobodzinski | ac23ec8 | 2017-02-07 17:21:55 -0700 | [diff] [blame] | 1791 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, |
| 1792 | DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", |
| 1793 | "Cannot map an image with layout %s. Only " |
| 1794 | "GENERAL or PREINITIALIZED are supported.", |
| 1795 | string_VkImageLayout(layout)); |
Mark Lobodzinski | 08f14fa | 2017-02-07 17:20:06 -0700 | [diff] [blame] | 1796 | } |
| 1797 | } |
| 1798 | } |
| 1799 | } |
| 1800 | } |
| 1801 | } |
Mark Lobodzinski | ac23ec8 | 2017-02-07 17:21:55 -0700 | [diff] [blame] | 1802 | return skip; |
Mark Lobodzinski | 08f14fa | 2017-02-07 17:20:06 -0700 | [diff] [blame] | 1803 | } |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 1804 | |
| 1805 | // Helper function to validate correct usage bits set for buffers or images. Verify that (actual & desired) flags != 0 or, if strict |
| 1806 | // is true, verify that (actual & desired) flags == desired |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 1807 | 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] | 1808 | VkDebugReportObjectTypeEXT obj_type, int32_t const msgCode, char const *ty_str, |
| 1809 | char const *func_name, char const *usage_str) { |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 1810 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 1811 | |
| 1812 | bool correct_usage = false; |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 1813 | bool skip = false; |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 1814 | if (strict) { |
| 1815 | correct_usage = ((actual & desired) == desired); |
| 1816 | } else { |
| 1817 | correct_usage = ((actual & desired) != 0); |
| 1818 | } |
| 1819 | if (!correct_usage) { |
| 1820 | if (msgCode == -1) { |
| 1821 | // TODO: Fix callers with msgCode == -1 to use correct validation checks. |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 1822 | skip = log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, obj_type, obj_handle, __LINE__, MEMTRACK_INVALID_USAGE_FLAG, |
| 1823 | "MEM", "Invalid usage flag for %s 0x%" PRIxLEAST64 |
| 1824 | " used by %s. In this case, %s should have %s set during creation.", |
| 1825 | ty_str, obj_handle, func_name, ty_str, usage_str); |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 1826 | } else { |
| 1827 | const char *valid_usage = (msgCode == -1) ? "" : validation_error_map[msgCode]; |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 1828 | skip = log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, obj_type, obj_handle, __LINE__, msgCode, "MEM", |
| 1829 | "Invalid usage flag for %s 0x%" PRIxLEAST64 |
| 1830 | " used by %s. In this case, %s should have %s set during creation. %s", |
| 1831 | ty_str, obj_handle, func_name, ty_str, usage_str, valid_usage); |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 1832 | } |
| 1833 | } |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 1834 | return skip; |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 1835 | } |
| 1836 | |
| 1837 | // Helper function to validate usage flags for buffers. For given buffer_state send actual vs. desired usage off to helper above |
| 1838 | // where an error will be flagged if usage is not correct |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 1839 | 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] | 1840 | int32_t const msgCode, char const *func_name, char const *usage_string) { |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 1841 | return validate_usage_flags(device_data, image_state->createInfo.usage, desired, strict, |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 1842 | reinterpret_cast<const uint64_t &>(image_state->image), VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 1843 | msgCode, "image", func_name, usage_string); |
| 1844 | } |
| 1845 | |
| 1846 | // Helper function to validate usage flags for buffers. For given buffer_state send actual vs. desired usage off to helper above |
| 1847 | // where an error will be flagged if usage is not correct |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 1848 | 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] | 1849 | int32_t const msgCode, char const *func_name, char const *usage_string) { |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 1850 | return validate_usage_flags(device_data, buffer_state->createInfo.usage, desired, strict, |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 1851 | reinterpret_cast<const uint64_t &>(buffer_state->buffer), VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, |
| 1852 | msgCode, "buffer", func_name, usage_string); |
| 1853 | } |
| 1854 | |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 1855 | bool PreCallValidateCreateBuffer(layer_data *device_data, const VkBufferCreateInfo *pCreateInfo) { |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 1856 | bool skip = false; |
| 1857 | // TODO: Add check for VALIDATION_ERROR_00658 |
| 1858 | // TODO: Add check for VALIDATION_ERROR_00666 |
| 1859 | // TODO: Add check for VALIDATION_ERROR_00667 |
| 1860 | // TODO: Add check for VALIDATION_ERROR_00668 |
| 1861 | // TODO: Add check for VALIDATION_ERROR_00669 |
| 1862 | return skip; |
| 1863 | } |
| 1864 | |
| 1865 | void PostCallRecordCreateBuffer(layer_data *device_data, const VkBufferCreateInfo *pCreateInfo, VkBuffer *pBuffer) { |
| 1866 | // TODO : This doesn't create deep copy of pQueueFamilyIndices so need to fix that if/when we want that data to be valid |
| 1867 | GetBufferMap(device_data) |
| 1868 | ->insert(std::make_pair(*pBuffer, std::unique_ptr<BUFFER_STATE>(new BUFFER_STATE(*pBuffer, pCreateInfo)))); |
| 1869 | } |
| 1870 | |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 1871 | bool PreCallValidateCreateBufferView(layer_data *device_data, const VkBufferViewCreateInfo *pCreateInfo) { |
| 1872 | bool skip = false; |
| 1873 | BUFFER_STATE *buffer_state = GetBufferState(device_data, pCreateInfo->buffer); |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 1874 | // If this isn't a sparse buffer, it needs to have memory backing it at CreateBufferView time |
| 1875 | if (buffer_state) { |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 1876 | skip |= ValidateMemoryIsBoundToBuffer(device_data, buffer_state, "vkCreateBufferView()", VALIDATION_ERROR_02522); |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 1877 | // In order to create a valid buffer view, the buffer must have been created with at least one of the following flags: |
| 1878 | // UNIFORM_TEXEL_BUFFER_BIT or STORAGE_TEXEL_BUFFER_BIT |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 1879 | skip |= ValidateBufferUsageFlags( |
| 1880 | 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] | 1881 | VALIDATION_ERROR_00694, "vkCreateBufferView()", "VK_BUFFER_USAGE_[STORAGE|UNIFORM]_TEXEL_BUFFER_BIT"); |
| 1882 | } |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 1883 | return skip; |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 1884 | } |
| 1885 | |
| 1886 | void PostCallRecordCreateBufferView(layer_data *device_data, const VkBufferViewCreateInfo *pCreateInfo, VkBufferView *pView) { |
| 1887 | (*GetBufferViewMap(device_data))[*pView] = std::unique_ptr<BUFFER_VIEW_STATE>(new BUFFER_VIEW_STATE(*pView, pCreateInfo)); |
| 1888 | } |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame^] | 1889 | |
| 1890 | // For the given format verify that the aspect masks make sense |
| 1891 | bool ValidateImageAspectMask(layer_data *device_data, VkImage image, VkFormat format, VkImageAspectFlags aspect_mask, |
| 1892 | const char *func_name) { |
| 1893 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 1894 | bool skip = false; |
| 1895 | if (vk_format_is_color(format)) { |
| 1896 | if ((aspect_mask & VK_IMAGE_ASPECT_COLOR_BIT) != VK_IMAGE_ASPECT_COLOR_BIT) { |
| 1897 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, (uint64_t)image, |
| 1898 | __LINE__, VALIDATION_ERROR_00741, "IMAGE", |
| 1899 | "%s: Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set. %s", func_name, |
| 1900 | validation_error_map[VALIDATION_ERROR_00741]); |
| 1901 | } else if ((aspect_mask & VK_IMAGE_ASPECT_COLOR_BIT) != aspect_mask) { |
| 1902 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, (uint64_t)image, |
| 1903 | __LINE__, VALIDATION_ERROR_00741, "IMAGE", |
| 1904 | "%s: Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set. %s", func_name, |
| 1905 | validation_error_map[VALIDATION_ERROR_00741]); |
| 1906 | } |
| 1907 | } else if (vk_format_is_depth_and_stencil(format)) { |
| 1908 | if ((aspect_mask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) == 0) { |
| 1909 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, (uint64_t)image, |
| 1910 | __LINE__, VALIDATION_ERROR_00741, "IMAGE", |
| 1911 | "%s: Depth/stencil image formats must have " |
| 1912 | "at least one of VK_IMAGE_ASPECT_DEPTH_BIT " |
| 1913 | "and VK_IMAGE_ASPECT_STENCIL_BIT set. %s", |
| 1914 | func_name, validation_error_map[VALIDATION_ERROR_00741]); |
| 1915 | } else if ((aspect_mask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) != aspect_mask) { |
| 1916 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, (uint64_t)image, |
| 1917 | __LINE__, VALIDATION_ERROR_00741, "IMAGE", |
| 1918 | "%s: Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and " |
| 1919 | "VK_IMAGE_ASPECT_STENCIL_BIT set. %s", |
| 1920 | func_name, validation_error_map[VALIDATION_ERROR_00741]); |
| 1921 | } |
| 1922 | } else if (vk_format_is_depth_only(format)) { |
| 1923 | if ((aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) != VK_IMAGE_ASPECT_DEPTH_BIT) { |
| 1924 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, (uint64_t)image, |
| 1925 | __LINE__, VALIDATION_ERROR_00741, "IMAGE", |
| 1926 | "%s: Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set. %s", func_name, |
| 1927 | validation_error_map[VALIDATION_ERROR_00741]); |
| 1928 | } else if ((aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) != aspect_mask) { |
| 1929 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, (uint64_t)image, |
| 1930 | __LINE__, VALIDATION_ERROR_00741, "IMAGE", |
| 1931 | "%s: Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set. %s", func_name, |
| 1932 | validation_error_map[VALIDATION_ERROR_00741]); |
| 1933 | } |
| 1934 | } else if (vk_format_is_stencil_only(format)) { |
| 1935 | if ((aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) != VK_IMAGE_ASPECT_STENCIL_BIT) { |
| 1936 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, (uint64_t)image, |
| 1937 | __LINE__, VALIDATION_ERROR_00741, "IMAGE", |
| 1938 | "%s: Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set. %s", func_name, |
| 1939 | validation_error_map[VALIDATION_ERROR_00741]); |
| 1940 | } else if ((aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) != aspect_mask) { |
| 1941 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, (uint64_t)image, |
| 1942 | __LINE__, VALIDATION_ERROR_00741, "IMAGE", |
| 1943 | "%s: Stencil-only image formats can have only the VK_IMAGE_ASPECT_STENCIL_BIT set. %s", func_name, |
| 1944 | validation_error_map[VALIDATION_ERROR_00741]); |
| 1945 | } |
| 1946 | } |
| 1947 | return skip; |
| 1948 | } |
| 1949 | |
| 1950 | bool ValidateImageSubrangeLevelLayerCounts(layer_data *device_data, const VkImageSubresourceRange &subresourceRange, |
| 1951 | const char *func_name) { |
| 1952 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 1953 | bool skip = false; |
| 1954 | if (subresourceRange.levelCount == 0) { |
| 1955 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, |
| 1956 | VALIDATION_ERROR_00768, "IMAGE", "%s called with 0 in subresourceRange.levelCount. %s", func_name, |
| 1957 | validation_error_map[VALIDATION_ERROR_00768]); |
| 1958 | } |
| 1959 | if (subresourceRange.layerCount == 0) { |
| 1960 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, |
| 1961 | VALIDATION_ERROR_00769, "IMAGE", "%s called with 0 in subresourceRange.layerCount. %s", func_name, |
| 1962 | validation_error_map[VALIDATION_ERROR_00769]); |
| 1963 | } |
| 1964 | return skip; |
| 1965 | } |
| 1966 | |
| 1967 | bool PreCallValidateCreateImageView(layer_data *device_data, const VkImageViewCreateInfo *create_info) { |
| 1968 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 1969 | bool skip = false; |
| 1970 | IMAGE_STATE *image_state = GetImageState(device_data, create_info->image); |
| 1971 | if (image_state) { |
| 1972 | skip |= ValidateImageUsageFlags( |
| 1973 | device_data, image_state, |
| 1974 | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT | |
| 1975 | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, |
| 1976 | false, -1, "vkCreateImageView()", |
| 1977 | "VK_IMAGE_USAGE_[SAMPLED|STORAGE|COLOR_ATTACHMENT|DEPTH_STENCIL_ATTACHMENT|INPUT_ATTACHMENT]_BIT"); |
| 1978 | // If this isn't a sparse image, it needs to have memory backing it at CreateImageView time |
| 1979 | skip |= ValidateMemoryIsBoundToImage(device_data, image_state, "vkCreateImageView()", VALIDATION_ERROR_02524); |
| 1980 | // Checks imported from image layer |
| 1981 | if (create_info->subresourceRange.baseMipLevel >= image_state->createInfo.mipLevels) { |
| 1982 | std::stringstream ss; |
| 1983 | ss << "vkCreateImageView called with baseMipLevel " << create_info->subresourceRange.baseMipLevel << " for image " |
| 1984 | << create_info->image << " that only has " << image_state->createInfo.mipLevels << " mip levels."; |
| 1985 | skip |= |
| 1986 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, |
| 1987 | VALIDATION_ERROR_00768, "IMAGE", "%s %s", ss.str().c_str(), validation_error_map[VALIDATION_ERROR_00768]); |
| 1988 | } |
| 1989 | if (create_info->subresourceRange.baseArrayLayer >= image_state->createInfo.arrayLayers) { |
| 1990 | std::stringstream ss; |
| 1991 | ss << "vkCreateImageView called with baseArrayLayer " << create_info->subresourceRange.baseArrayLayer << " for image " |
| 1992 | << create_info->image << " that only has " << image_state->createInfo.arrayLayers << " array layers."; |
| 1993 | skip |= |
| 1994 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, |
| 1995 | VALIDATION_ERROR_00769, "IMAGE", "%s %s", ss.str().c_str(), validation_error_map[VALIDATION_ERROR_00769]); |
| 1996 | } |
| 1997 | // TODO: Need new valid usage language for levelCount == 0 & layerCount == 0 |
| 1998 | skip |= ValidateImageSubrangeLevelLayerCounts(device_data, create_info->subresourceRange, "vkCreateImageView()"); |
| 1999 | |
| 2000 | VkImageCreateFlags image_flags = image_state->createInfo.flags; |
| 2001 | VkFormat image_format = image_state->createInfo.format; |
| 2002 | VkFormat view_format = create_info->format; |
| 2003 | VkImageAspectFlags aspect_mask = create_info->subresourceRange.aspectMask; |
| 2004 | |
| 2005 | // Validate VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT state |
| 2006 | if (image_flags & VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT) { |
| 2007 | // Format MUST be compatible (in the same format compatibility class) as the format the image was created with |
| 2008 | if (vk_format_get_compatibility_class(image_format) != vk_format_get_compatibility_class(view_format)) { |
| 2009 | std::stringstream ss; |
| 2010 | ss << "vkCreateImageView(): ImageView format " << string_VkFormat(view_format) |
| 2011 | << " is not in the same format compatibility class as image (" << (uint64_t)create_info->image << ") format " |
| 2012 | << string_VkFormat(image_format) << ". Images created with the VK_IMAGE_CREATE_MUTABLE_FORMAT BIT " |
| 2013 | << "can support ImageViews with differing formats but they must be in the same compatibility class."; |
| 2014 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, |
| 2015 | VALIDATION_ERROR_02171, "IMAGE", "%s %s", ss.str().c_str(), |
| 2016 | validation_error_map[VALIDATION_ERROR_02171]); |
| 2017 | } |
| 2018 | } else { |
| 2019 | // Format MUST be IDENTICAL to the format the image was created with |
| 2020 | if (image_format != view_format) { |
| 2021 | std::stringstream ss; |
| 2022 | ss << "vkCreateImageView() format " << string_VkFormat(view_format) << " differs from image " |
| 2023 | << (uint64_t)create_info->image << " format " << string_VkFormat(image_format) |
| 2024 | << ". Formats MUST be IDENTICAL unless VK_IMAGE_CREATE_MUTABLE_FORMAT BIT was set on image creation."; |
| 2025 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, |
| 2026 | VALIDATION_ERROR_02172, "IMAGE", "%s %s", ss.str().c_str(), |
| 2027 | validation_error_map[VALIDATION_ERROR_02172]); |
| 2028 | } |
| 2029 | } |
| 2030 | |
| 2031 | // Validate correct image aspect bits for desired formats and format consistency |
| 2032 | skip |= ValidateImageAspectMask(device_data, image_state->image, image_format, aspect_mask, "vkCreateImageView()"); |
| 2033 | } |
| 2034 | return skip; |
| 2035 | } |
| 2036 | |
| 2037 | void PostCallRecordCreateImageView(layer_data *device_data, const VkImageViewCreateInfo *create_info, |
| 2038 | VkImageView view) { |
| 2039 | (*GetImageViewMap(device_data))[view] = std::unique_ptr<IMAGE_VIEW_STATE>(new IMAGE_VIEW_STATE(view, create_info)); |
| 2040 | ResolveRemainingLevelsLayers(device_data, &(*GetImageViewMap(device_data))[view].get()->create_info.subresourceRange, |
| 2041 | GetImageState(device_data, create_info->image)); |
| 2042 | } |