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> |
Dave Houlton | 4eaaf3a | 2017-03-14 11:31:20 -0600 | [diff] [blame] | 19 | * Author: Dave Houlton <daveh@lunarg.com> |
Mark Lobodzinski | d42e4d2 | 2017-01-17 14:14:22 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | // Allow use of STL min and max functions in Windows |
| 23 | #define NOMINMAX |
| 24 | |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 25 | #include <sstream> |
| 26 | |
| 27 | #include "vk_enum_string_helper.h" |
| 28 | #include "vk_layer_data.h" |
| 29 | #include "vk_layer_utils.h" |
| 30 | #include "vk_layer_logging.h" |
| 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 | |
Tony Barbour | df013b9 | 2017-01-25 12:53:48 -0700 | [diff] [blame] | 65 | // Set the layout in supplied map |
Tony Barbour | e0c5cc9 | 2017-02-08 13:53:39 -0700 | [diff] [blame] | 66 | void SetLayout(std::unordered_map<ImageSubresourcePair, IMAGE_LAYOUT_NODE> &imageLayoutMap, ImageSubresourcePair imgpair, |
| 67 | VkImageLayout layout) { |
Tony Barbour | df013b9 | 2017-01-25 12:53:48 -0700 | [diff] [blame] | 68 | imageLayoutMap[imgpair].layout = layout; |
| 69 | } |
| 70 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 71 | bool FindLayoutVerifyNode(layer_data *device_data, GLOBAL_CB_NODE *pCB, ImageSubresourcePair imgpair, |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 72 | IMAGE_CMD_BUF_LAYOUT_NODE &node, const VkImageAspectFlags aspectMask) { |
| 73 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 74 | |
| 75 | if (!(imgpair.subresource.aspectMask & aspectMask)) { |
| 76 | return false; |
| 77 | } |
| 78 | VkImageAspectFlags oldAspectMask = imgpair.subresource.aspectMask; |
| 79 | imgpair.subresource.aspectMask = aspectMask; |
| 80 | auto imgsubIt = pCB->imageLayoutMap.find(imgpair); |
| 81 | if (imgsubIt == pCB->imageLayoutMap.end()) { |
| 82 | return false; |
| 83 | } |
| 84 | if (node.layout != VK_IMAGE_LAYOUT_MAX_ENUM && node.layout != imgsubIt->second.layout) { |
| 85 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 86 | reinterpret_cast<uint64_t &>(imgpair.image), __LINE__, DRAWSTATE_INVALID_LAYOUT, "DS", |
| 87 | "Cannot query for VkImage 0x%" PRIx64 " layout when combined aspect mask %d has multiple layout types: %s and %s", |
| 88 | reinterpret_cast<uint64_t &>(imgpair.image), oldAspectMask, string_VkImageLayout(node.layout), |
| 89 | string_VkImageLayout(imgsubIt->second.layout)); |
| 90 | } |
| 91 | if (node.initialLayout != VK_IMAGE_LAYOUT_MAX_ENUM && node.initialLayout != imgsubIt->second.initialLayout) { |
| 92 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 93 | reinterpret_cast<uint64_t &>(imgpair.image), __LINE__, DRAWSTATE_INVALID_LAYOUT, "DS", |
| 94 | "Cannot query for VkImage 0x%" PRIx64 |
| 95 | " layout when combined aspect mask %d has multiple initial layout types: %s and %s", |
| 96 | reinterpret_cast<uint64_t &>(imgpair.image), oldAspectMask, string_VkImageLayout(node.initialLayout), |
| 97 | string_VkImageLayout(imgsubIt->second.initialLayout)); |
| 98 | } |
| 99 | node = imgsubIt->second; |
| 100 | return true; |
| 101 | } |
| 102 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 103 | bool FindLayoutVerifyLayout(layer_data *device_data, ImageSubresourcePair imgpair, VkImageLayout &layout, |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 104 | const VkImageAspectFlags aspectMask) { |
| 105 | if (!(imgpair.subresource.aspectMask & aspectMask)) { |
| 106 | return false; |
| 107 | } |
| 108 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 109 | VkImageAspectFlags oldAspectMask = imgpair.subresource.aspectMask; |
| 110 | imgpair.subresource.aspectMask = aspectMask; |
| 111 | auto imgsubIt = (*core_validation::GetImageLayoutMap(device_data)).find(imgpair); |
| 112 | if (imgsubIt == (*core_validation::GetImageLayoutMap(device_data)).end()) { |
| 113 | return false; |
| 114 | } |
| 115 | if (layout != VK_IMAGE_LAYOUT_MAX_ENUM && layout != imgsubIt->second.layout) { |
| 116 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 117 | reinterpret_cast<uint64_t &>(imgpair.image), __LINE__, DRAWSTATE_INVALID_LAYOUT, "DS", |
| 118 | "Cannot query for VkImage 0x%" PRIx64 " layout when combined aspect mask %d has multiple layout types: %s and %s", |
| 119 | reinterpret_cast<uint64_t &>(imgpair.image), oldAspectMask, string_VkImageLayout(layout), |
| 120 | string_VkImageLayout(imgsubIt->second.layout)); |
| 121 | } |
| 122 | layout = imgsubIt->second.layout; |
| 123 | return true; |
| 124 | } |
| 125 | |
| 126 | // Find layout(s) on the command buffer level |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 127 | 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] | 128 | IMAGE_CMD_BUF_LAYOUT_NODE &node) { |
| 129 | ImageSubresourcePair imgpair = {image, true, range}; |
| 130 | node = IMAGE_CMD_BUF_LAYOUT_NODE(VK_IMAGE_LAYOUT_MAX_ENUM, VK_IMAGE_LAYOUT_MAX_ENUM); |
| 131 | FindLayoutVerifyNode(device_data, pCB, imgpair, node, VK_IMAGE_ASPECT_COLOR_BIT); |
| 132 | FindLayoutVerifyNode(device_data, pCB, imgpair, node, VK_IMAGE_ASPECT_DEPTH_BIT); |
| 133 | FindLayoutVerifyNode(device_data, pCB, imgpair, node, VK_IMAGE_ASPECT_STENCIL_BIT); |
| 134 | FindLayoutVerifyNode(device_data, pCB, imgpair, node, VK_IMAGE_ASPECT_METADATA_BIT); |
| 135 | if (node.layout == VK_IMAGE_LAYOUT_MAX_ENUM) { |
| 136 | imgpair = {image, false, VkImageSubresource()}; |
| 137 | auto imgsubIt = pCB->imageLayoutMap.find(imgpair); |
| 138 | if (imgsubIt == pCB->imageLayoutMap.end()) return false; |
| 139 | // TODO: This is ostensibly a find function but it changes state here |
| 140 | node = imgsubIt->second; |
| 141 | } |
| 142 | return true; |
| 143 | } |
| 144 | |
| 145 | // Find layout(s) on the global level |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 146 | bool FindGlobalLayout(layer_data *device_data, ImageSubresourcePair imgpair, VkImageLayout &layout) { |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 147 | layout = VK_IMAGE_LAYOUT_MAX_ENUM; |
| 148 | FindLayoutVerifyLayout(device_data, imgpair, layout, VK_IMAGE_ASPECT_COLOR_BIT); |
| 149 | FindLayoutVerifyLayout(device_data, imgpair, layout, VK_IMAGE_ASPECT_DEPTH_BIT); |
| 150 | FindLayoutVerifyLayout(device_data, imgpair, layout, VK_IMAGE_ASPECT_STENCIL_BIT); |
| 151 | FindLayoutVerifyLayout(device_data, imgpair, layout, VK_IMAGE_ASPECT_METADATA_BIT); |
| 152 | if (layout == VK_IMAGE_LAYOUT_MAX_ENUM) { |
| 153 | imgpair = {imgpair.image, false, VkImageSubresource()}; |
| 154 | auto imgsubIt = (*core_validation::GetImageLayoutMap(device_data)).find(imgpair); |
| 155 | if (imgsubIt == (*core_validation::GetImageLayoutMap(device_data)).end()) return false; |
| 156 | layout = imgsubIt->second.layout; |
| 157 | } |
| 158 | return true; |
| 159 | } |
| 160 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 161 | bool FindLayouts(layer_data *device_data, VkImage image, std::vector<VkImageLayout> &layouts) { |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 162 | auto sub_data = (*core_validation::GetImageSubresourceMap(device_data)).find(image); |
| 163 | if (sub_data == (*core_validation::GetImageSubresourceMap(device_data)).end()) return false; |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 164 | auto image_state = GetImageState(device_data, image); |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 165 | if (!image_state) return false; |
| 166 | bool ignoreGlobal = false; |
| 167 | // TODO: Make this robust for >1 aspect mask. Now it will just say ignore potential errors in this case. |
| 168 | if (sub_data->second.size() >= (image_state->createInfo.arrayLayers * image_state->createInfo.mipLevels + 1)) { |
| 169 | ignoreGlobal = true; |
| 170 | } |
| 171 | for (auto imgsubpair : sub_data->second) { |
| 172 | if (ignoreGlobal && !imgsubpair.hasSubresource) continue; |
| 173 | auto img_data = (*core_validation::GetImageLayoutMap(device_data)).find(imgsubpair); |
| 174 | if (img_data != (*core_validation::GetImageLayoutMap(device_data)).end()) { |
| 175 | layouts.push_back(img_data->second.layout); |
| 176 | } |
| 177 | } |
| 178 | return true; |
| 179 | } |
Tony Barbour | e0c5cc9 | 2017-02-08 13:53:39 -0700 | [diff] [blame] | 180 | bool FindLayout(const std::unordered_map<ImageSubresourcePair, IMAGE_LAYOUT_NODE> &imageLayoutMap, ImageSubresourcePair imgpair, |
| 181 | VkImageLayout &layout, const VkImageAspectFlags aspectMask) { |
Tony Barbour | df013b9 | 2017-01-25 12:53:48 -0700 | [diff] [blame] | 182 | if (!(imgpair.subresource.aspectMask & aspectMask)) { |
| 183 | return false; |
| 184 | } |
| 185 | imgpair.subresource.aspectMask = aspectMask; |
| 186 | auto imgsubIt = imageLayoutMap.find(imgpair); |
| 187 | if (imgsubIt == imageLayoutMap.end()) { |
| 188 | return false; |
| 189 | } |
| 190 | layout = imgsubIt->second.layout; |
| 191 | return true; |
Tony Barbour | e0c5cc9 | 2017-02-08 13:53:39 -0700 | [diff] [blame] | 192 | } |
Tony Barbour | df013b9 | 2017-01-25 12:53:48 -0700 | [diff] [blame] | 193 | |
| 194 | // find layout in supplied map |
Tony Barbour | e0c5cc9 | 2017-02-08 13:53:39 -0700 | [diff] [blame] | 195 | bool FindLayout(const std::unordered_map<ImageSubresourcePair, IMAGE_LAYOUT_NODE> &imageLayoutMap, ImageSubresourcePair imgpair, |
| 196 | VkImageLayout &layout) { |
Tony Barbour | df013b9 | 2017-01-25 12:53:48 -0700 | [diff] [blame] | 197 | layout = VK_IMAGE_LAYOUT_MAX_ENUM; |
| 198 | FindLayout(imageLayoutMap, imgpair, layout, VK_IMAGE_ASPECT_COLOR_BIT); |
| 199 | FindLayout(imageLayoutMap, imgpair, layout, VK_IMAGE_ASPECT_DEPTH_BIT); |
| 200 | FindLayout(imageLayoutMap, imgpair, layout, VK_IMAGE_ASPECT_STENCIL_BIT); |
| 201 | FindLayout(imageLayoutMap, imgpair, layout, VK_IMAGE_ASPECT_METADATA_BIT); |
| 202 | if (layout == VK_IMAGE_LAYOUT_MAX_ENUM) { |
| 203 | imgpair = {imgpair.image, false, VkImageSubresource()}; |
| 204 | auto imgsubIt = imageLayoutMap.find(imgpair); |
| 205 | if (imgsubIt == imageLayoutMap.end()) return false; |
| 206 | layout = imgsubIt->second.layout; |
| 207 | } |
| 208 | return true; |
| 209 | } |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 210 | |
| 211 | // Set the layout on the global level |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 212 | void SetGlobalLayout(layer_data *device_data, ImageSubresourcePair imgpair, const VkImageLayout &layout) { |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 213 | VkImage &image = imgpair.image; |
| 214 | (*core_validation::GetImageLayoutMap(device_data))[imgpair].layout = layout; |
| 215 | auto &image_subresources = (*core_validation::GetImageSubresourceMap(device_data))[image]; |
| 216 | auto subresource = std::find(image_subresources.begin(), image_subresources.end(), imgpair); |
| 217 | if (subresource == image_subresources.end()) { |
| 218 | image_subresources.push_back(imgpair); |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | // Set the layout on the cmdbuf level |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 223 | 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] | 224 | pCB->imageLayoutMap[imgpair] = node; |
| 225 | auto subresource = |
| 226 | std::find(pCB->imageSubresourceMap[imgpair.image].begin(), pCB->imageSubresourceMap[imgpair.image].end(), imgpair); |
| 227 | if (subresource == pCB->imageSubresourceMap[imgpair.image].end()) { |
| 228 | pCB->imageSubresourceMap[imgpair.image].push_back(imgpair); |
| 229 | } |
| 230 | } |
| 231 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 232 | 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] | 233 | auto view_state = GetImageViewState(device_data, imageView); |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 234 | assert(view_state); |
| 235 | auto image = view_state->create_info.image; |
| 236 | const VkImageSubresourceRange &subRange = view_state->create_info.subresourceRange; |
| 237 | // TODO: Do not iterate over every possibility - consolidate where possible |
| 238 | for (uint32_t j = 0; j < subRange.levelCount; j++) { |
| 239 | uint32_t level = subRange.baseMipLevel + j; |
| 240 | for (uint32_t k = 0; k < subRange.layerCount; k++) { |
| 241 | uint32_t layer = subRange.baseArrayLayer + k; |
| 242 | VkImageSubresource sub = {subRange.aspectMask, level, layer}; |
| 243 | // TODO: If ImageView was created with depth or stencil, transition both layouts as the aspectMask is ignored and both |
| 244 | // are used. Verify that the extra implicit layout is OK for descriptor set layout validation |
| 245 | if (subRange.aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) { |
| 246 | if (vk_format_is_depth_and_stencil(view_state->create_info.format)) { |
| 247 | sub.aspectMask |= (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT); |
| 248 | } |
| 249 | } |
| 250 | SetLayout(device_data, pCB, image, sub, layout); |
| 251 | } |
| 252 | } |
| 253 | } |
| 254 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 255 | bool VerifyFramebufferAndRenderPassLayouts(layer_data *device_data, GLOBAL_CB_NODE *pCB, |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 256 | const VkRenderPassBeginInfo *pRenderPassBegin, |
| 257 | const FRAMEBUFFER_STATE *framebuffer_state) { |
| 258 | bool skip_call = false; |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 259 | auto const pRenderPassInfo = GetRenderPassState(device_data, pRenderPassBegin->renderPass)->createInfo.ptr(); |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 260 | auto const &framebufferInfo = framebuffer_state->createInfo; |
| 261 | const auto report_data = core_validation::GetReportData(device_data); |
| 262 | if (pRenderPassInfo->attachmentCount != framebufferInfo.attachmentCount) { |
| 263 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, |
| 264 | DRAWSTATE_INVALID_RENDERPASS, "DS", |
| 265 | "You cannot start a render pass using a framebuffer " |
| 266 | "with a different number of attachments."); |
| 267 | } |
| 268 | for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) { |
| 269 | const VkImageView &image_view = framebufferInfo.pAttachments[i]; |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 270 | auto view_state = GetImageViewState(device_data, image_view); |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 271 | assert(view_state); |
| 272 | const VkImage &image = view_state->create_info.image; |
| 273 | const VkImageSubresourceRange &subRange = view_state->create_info.subresourceRange; |
| 274 | IMAGE_CMD_BUF_LAYOUT_NODE newNode = {pRenderPassInfo->pAttachments[i].initialLayout, |
| 275 | pRenderPassInfo->pAttachments[i].initialLayout}; |
| 276 | // TODO: Do not iterate over every possibility - consolidate where possible |
Tobin Ehlis | 2b716cb | 2017-02-16 13:21:20 -0700 | [diff] [blame] | 277 | // TODO: Consolidate this with SetImageViewLayout() function above |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 278 | for (uint32_t j = 0; j < subRange.levelCount; j++) { |
| 279 | uint32_t level = subRange.baseMipLevel + j; |
| 280 | for (uint32_t k = 0; k < subRange.layerCount; k++) { |
| 281 | uint32_t layer = subRange.baseArrayLayer + k; |
| 282 | VkImageSubresource sub = {subRange.aspectMask, level, layer}; |
| 283 | IMAGE_CMD_BUF_LAYOUT_NODE node; |
| 284 | if (!FindCmdBufLayout(device_data, pCB, image, sub, node)) { |
Tobin Ehlis | 2b716cb | 2017-02-16 13:21:20 -0700 | [diff] [blame] | 285 | // If ImageView was created with depth or stencil, transition both aspects if it's a DS image |
| 286 | if (subRange.aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) { |
| 287 | if (vk_format_is_depth_and_stencil(view_state->create_info.format)) { |
| 288 | sub.aspectMask |= (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT); |
| 289 | } |
| 290 | } |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 291 | SetLayout(device_data, pCB, image, sub, newNode); |
| 292 | continue; |
| 293 | } |
| 294 | if (newNode.layout != VK_IMAGE_LAYOUT_UNDEFINED && newNode.layout != node.layout) { |
| 295 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, |
| 296 | DRAWSTATE_INVALID_RENDERPASS, "DS", |
| 297 | "You cannot start a render pass using attachment %u " |
| 298 | "where the render pass initial layout is %s and the previous " |
| 299 | "known layout of the attachment is %s. The layouts must match, or " |
| 300 | "the render pass initial layout for the attachment must be " |
| 301 | "VK_IMAGE_LAYOUT_UNDEFINED", |
| 302 | i, string_VkImageLayout(newNode.layout), string_VkImageLayout(node.layout)); |
| 303 | } |
| 304 | } |
| 305 | } |
| 306 | } |
| 307 | return skip_call; |
| 308 | } |
| 309 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 310 | 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] | 311 | VkAttachmentReference ref) { |
| 312 | if (ref.attachment != VK_ATTACHMENT_UNUSED) { |
| 313 | auto image_view = pFramebuffer->createInfo.pAttachments[ref.attachment]; |
| 314 | SetImageViewLayout(device_data, pCB, image_view, ref.layout); |
| 315 | } |
| 316 | } |
| 317 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 318 | void TransitionSubpassLayouts(layer_data *device_data, GLOBAL_CB_NODE *pCB, const VkRenderPassBeginInfo *pRenderPassBegin, |
| 319 | const int subpass_index, FRAMEBUFFER_STATE *framebuffer_state) { |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 320 | auto renderPass = GetRenderPassState(device_data, pRenderPassBegin->renderPass); |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 321 | if (!renderPass) return; |
| 322 | |
| 323 | if (framebuffer_state) { |
| 324 | auto const &subpass = renderPass->createInfo.pSubpasses[subpass_index]; |
| 325 | for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) { |
| 326 | TransitionAttachmentRefLayout(device_data, pCB, framebuffer_state, subpass.pInputAttachments[j]); |
| 327 | } |
| 328 | for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) { |
| 329 | TransitionAttachmentRefLayout(device_data, pCB, framebuffer_state, subpass.pColorAttachments[j]); |
| 330 | } |
| 331 | if (subpass.pDepthStencilAttachment) { |
| 332 | TransitionAttachmentRefLayout(device_data, pCB, framebuffer_state, *subpass.pDepthStencilAttachment); |
| 333 | } |
| 334 | } |
| 335 | } |
| 336 | |
Mark Lobodzinski | 6b6c50a | 2017-02-27 12:56:14 -0700 | [diff] [blame] | 337 | bool ValidateImageAspectLayout(layer_data *device_data, GLOBAL_CB_NODE *pCB, const VkImageMemoryBarrier *mem_barrier, |
| 338 | uint32_t level, uint32_t layer, VkImageAspectFlags aspect) { |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 339 | if (!(mem_barrier->subresourceRange.aspectMask & aspect)) { |
| 340 | return false; |
| 341 | } |
| 342 | VkImageSubresource sub = {aspect, level, layer}; |
| 343 | IMAGE_CMD_BUF_LAYOUT_NODE node; |
| 344 | if (!FindCmdBufLayout(device_data, pCB, mem_barrier->image, sub, node)) { |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 345 | return false; |
| 346 | } |
| 347 | bool skip = false; |
| 348 | if (mem_barrier->oldLayout == VK_IMAGE_LAYOUT_UNDEFINED) { |
| 349 | // TODO: Set memory invalid which is in mem_tracker currently |
| 350 | } else if (node.layout != mem_barrier->oldLayout) { |
| 351 | skip |= log_msg(core_validation::GetReportData(device_data), VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, |
| 352 | 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", |
| 353 | "You cannot transition the layout of aspect %d from %s when current layout is %s.", aspect, |
| 354 | string_VkImageLayout(mem_barrier->oldLayout), string_VkImageLayout(node.layout)); |
| 355 | } |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 356 | return skip; |
| 357 | } |
| 358 | |
Mark Lobodzinski | 6b6c50a | 2017-02-27 12:56:14 -0700 | [diff] [blame] | 359 | void TransitionImageAspectLayout(layer_data *device_data, GLOBAL_CB_NODE *pCB, const VkImageMemoryBarrier *mem_barrier, |
| 360 | uint32_t level, uint32_t layer, VkImageAspectFlags aspect) { |
| 361 | if (!(mem_barrier->subresourceRange.aspectMask & aspect)) { |
| 362 | return; |
| 363 | } |
| 364 | VkImageSubresource sub = {aspect, level, layer}; |
| 365 | IMAGE_CMD_BUF_LAYOUT_NODE node; |
| 366 | if (!FindCmdBufLayout(device_data, pCB, mem_barrier->image, sub, node)) { |
| 367 | SetLayout(device_data, pCB, mem_barrier->image, sub, |
| 368 | IMAGE_CMD_BUF_LAYOUT_NODE(mem_barrier->oldLayout, mem_barrier->newLayout)); |
| 369 | return; |
| 370 | } |
| 371 | if (mem_barrier->oldLayout == VK_IMAGE_LAYOUT_UNDEFINED) { |
| 372 | // TODO: Set memory invalid |
| 373 | } |
| 374 | SetLayout(device_data, pCB, mem_barrier->image, sub, mem_barrier->newLayout); |
| 375 | } |
| 376 | |
Dave Houlton | 10b3948 | 2017-03-16 13:18:15 -0600 | [diff] [blame^] | 377 | bool VerifyAspectsPresent(VkImageAspectFlags aspect_mask, VkFormat format) { |
Dave Houlton | 4eaaf3a | 2017-03-14 11:31:20 -0600 | [diff] [blame] | 378 | if ((aspect_mask & VK_IMAGE_ASPECT_COLOR_BIT) != 0) { |
| 379 | if (!vk_format_is_color(format)) return false; |
| 380 | } |
| 381 | if ((aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) != 0) { |
| 382 | if (!vk_format_has_depth(format)) return false; |
| 383 | } |
| 384 | if ((aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) != 0) { |
| 385 | if (!vk_format_has_stencil(format)) return false; |
| 386 | } |
| 387 | return true; |
| 388 | } |
| 389 | |
Mike Weiblen | 62d08a3 | 2017-03-07 22:18:27 -0700 | [diff] [blame] | 390 | // Verify an ImageMemoryBarrier's old/new ImageLayouts are compatible with the Image's ImageUsageFlags. |
| 391 | bool ValidateBarrierLayoutToImageUsage(layer_data *device_data, const VkImageMemoryBarrier *img_barrier, bool new_not_old, |
| 392 | VkImageUsageFlags usage_flags, const char *func_name) { |
| 393 | const auto report_data = core_validation::GetReportData(device_data); |
| 394 | bool skip = false; |
| 395 | const VkImageLayout layout = (new_not_old) ? img_barrier->newLayout : img_barrier->oldLayout; |
| 396 | UNIQUE_VALIDATION_ERROR_CODE msg_code = VALIDATION_ERROR_UNDEFINED; // sentinel value meaning "no error" |
| 397 | |
| 398 | switch (layout) { |
| 399 | case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: |
| 400 | if ((usage_flags & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) == 0) { |
| 401 | msg_code = VALIDATION_ERROR_00303; |
| 402 | } |
| 403 | break; |
| 404 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: |
| 405 | if ((usage_flags & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) == 0) { |
| 406 | msg_code = VALIDATION_ERROR_00304; |
| 407 | } |
| 408 | break; |
| 409 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: |
| 410 | if ((usage_flags & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) == 0) { |
| 411 | msg_code = VALIDATION_ERROR_00305; |
| 412 | } |
| 413 | break; |
| 414 | case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: |
| 415 | if ((usage_flags & (VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT)) == 0) { |
| 416 | msg_code = VALIDATION_ERROR_00306; |
| 417 | } |
| 418 | break; |
| 419 | case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL: |
| 420 | if ((usage_flags & VK_IMAGE_USAGE_TRANSFER_SRC_BIT) == 0) { |
| 421 | msg_code = VALIDATION_ERROR_00307; |
| 422 | } |
| 423 | break; |
| 424 | case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL: |
| 425 | if ((usage_flags & VK_IMAGE_USAGE_TRANSFER_DST_BIT) == 0) { |
| 426 | msg_code = VALIDATION_ERROR_00308; |
| 427 | } |
| 428 | break; |
| 429 | default: |
| 430 | // Other VkImageLayout values do not have VUs defined in this context. |
| 431 | break; |
| 432 | } |
| 433 | |
| 434 | if (msg_code != VALIDATION_ERROR_UNDEFINED) { |
| 435 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, msg_code, |
| 436 | "DS", "%s: Image barrier 0x%p %sLayout=%s is not compatible with image 0x%" PRIx64 " usage flags 0x%" PRIx32 |
| 437 | ". %s", |
| 438 | func_name, img_barrier, ((new_not_old) ? "new" : "old"), string_VkImageLayout(layout), |
| 439 | (uint64_t)(img_barrier->image), usage_flags, validation_error_map[msg_code]); |
| 440 | } |
| 441 | return skip; |
| 442 | } |
| 443 | |
| 444 | // Verify image barriers are compatible with the images they reference. |
| 445 | bool ValidateBarriersToImages(layer_data *device_data, VkCommandBuffer cmdBuffer, uint32_t imageMemoryBarrierCount, |
| 446 | const VkImageMemoryBarrier *pImageMemoryBarriers, const char *func_name) { |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 447 | GLOBAL_CB_NODE *pCB = GetCBNode(device_data, cmdBuffer); |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 448 | bool skip = false; |
Mike Weiblen | 62d08a3 | 2017-03-07 22:18:27 -0700 | [diff] [blame] | 449 | uint32_t level_count = 0; |
| 450 | uint32_t layer_count = 0; |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 451 | |
Mike Weiblen | 62d08a3 | 2017-03-07 22:18:27 -0700 | [diff] [blame] | 452 | for (uint32_t i = 0; i < imageMemoryBarrierCount; ++i) { |
| 453 | auto img_barrier = &pImageMemoryBarriers[i]; |
| 454 | if (!img_barrier) continue; |
| 455 | |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 456 | // TODO: Do not iterate over every possibility - consolidate where possible |
Mike Weiblen | 62d08a3 | 2017-03-07 22:18:27 -0700 | [diff] [blame] | 457 | ResolveRemainingLevelsLayers(device_data, &level_count, &layer_count, img_barrier->subresourceRange, |
| 458 | GetImageState(device_data, img_barrier->image)); |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 459 | |
Mike Weiblen | 62d08a3 | 2017-03-07 22:18:27 -0700 | [diff] [blame] | 460 | for (uint32_t j = 0; j < level_count; j++) { |
| 461 | uint32_t level = img_barrier->subresourceRange.baseMipLevel + j; |
| 462 | for (uint32_t k = 0; k < layer_count; k++) { |
| 463 | uint32_t layer = img_barrier->subresourceRange.baseArrayLayer + k; |
| 464 | skip |= ValidateImageAspectLayout(device_data, pCB, img_barrier, level, layer, VK_IMAGE_ASPECT_COLOR_BIT); |
| 465 | skip |= ValidateImageAspectLayout(device_data, pCB, img_barrier, level, layer, VK_IMAGE_ASPECT_DEPTH_BIT); |
| 466 | skip |= ValidateImageAspectLayout(device_data, pCB, img_barrier, level, layer, VK_IMAGE_ASPECT_STENCIL_BIT); |
| 467 | skip |= ValidateImageAspectLayout(device_data, pCB, img_barrier, level, layer, VK_IMAGE_ASPECT_METADATA_BIT); |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 468 | } |
| 469 | } |
Mike Weiblen | 62d08a3 | 2017-03-07 22:18:27 -0700 | [diff] [blame] | 470 | |
| 471 | IMAGE_STATE *image_state = GetImageState(device_data, img_barrier->image); |
| 472 | if (image_state) { |
| 473 | VkImageUsageFlags usage_flags = image_state->createInfo.usage; |
| 474 | skip |= ValidateBarrierLayoutToImageUsage(device_data, img_barrier, false, usage_flags, func_name); |
| 475 | skip |= ValidateBarrierLayoutToImageUsage(device_data, img_barrier, true, usage_flags, func_name); |
| 476 | } |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 477 | } |
| 478 | return skip; |
| 479 | } |
| 480 | |
Mark Lobodzinski | 6b6c50a | 2017-02-27 12:56:14 -0700 | [diff] [blame] | 481 | void TransitionImageLayouts(layer_data *device_data, VkCommandBuffer cmdBuffer, uint32_t memBarrierCount, |
| 482 | const VkImageMemoryBarrier *pImgMemBarriers) { |
| 483 | GLOBAL_CB_NODE *pCB = GetCBNode(device_data, cmdBuffer); |
| 484 | uint32_t levelCount = 0; |
| 485 | uint32_t layerCount = 0; |
| 486 | |
| 487 | for (uint32_t i = 0; i < memBarrierCount; ++i) { |
| 488 | auto mem_barrier = &pImgMemBarriers[i]; |
| 489 | if (!mem_barrier) continue; |
| 490 | // TODO: Do not iterate over every possibility - consolidate where possible |
| 491 | ResolveRemainingLevelsLayers(device_data, &levelCount, &layerCount, mem_barrier->subresourceRange, |
| 492 | GetImageState(device_data, mem_barrier->image)); |
| 493 | |
| 494 | for (uint32_t j = 0; j < levelCount; j++) { |
| 495 | uint32_t level = mem_barrier->subresourceRange.baseMipLevel + j; |
| 496 | for (uint32_t k = 0; k < layerCount; k++) { |
| 497 | uint32_t layer = mem_barrier->subresourceRange.baseArrayLayer + k; |
| 498 | TransitionImageAspectLayout(device_data, pCB, mem_barrier, level, layer, VK_IMAGE_ASPECT_COLOR_BIT); |
| 499 | TransitionImageAspectLayout(device_data, pCB, mem_barrier, level, layer, VK_IMAGE_ASPECT_DEPTH_BIT); |
| 500 | TransitionImageAspectLayout(device_data, pCB, mem_barrier, level, layer, VK_IMAGE_ASPECT_STENCIL_BIT); |
| 501 | TransitionImageAspectLayout(device_data, pCB, mem_barrier, level, layer, VK_IMAGE_ASPECT_METADATA_BIT); |
| 502 | } |
| 503 | } |
| 504 | } |
| 505 | } |
| 506 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 507 | bool VerifySourceImageLayout(layer_data *device_data, GLOBAL_CB_NODE *cb_node, VkImage srcImage, VkImageSubresourceLayers subLayers, |
| 508 | VkImageLayout srcImageLayout, UNIQUE_VALIDATION_ERROR_CODE msgCode) { |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 509 | const auto report_data = core_validation::GetReportData(device_data); |
| 510 | bool skip_call = false; |
| 511 | |
| 512 | for (uint32_t i = 0; i < subLayers.layerCount; ++i) { |
| 513 | uint32_t layer = i + subLayers.baseArrayLayer; |
| 514 | VkImageSubresource sub = {subLayers.aspectMask, subLayers.mipLevel, layer}; |
| 515 | IMAGE_CMD_BUF_LAYOUT_NODE node; |
| 516 | if (!FindCmdBufLayout(device_data, cb_node, srcImage, sub, node)) { |
| 517 | SetLayout(device_data, cb_node, srcImage, sub, IMAGE_CMD_BUF_LAYOUT_NODE(srcImageLayout, srcImageLayout)); |
| 518 | continue; |
| 519 | } |
| 520 | if (node.layout != srcImageLayout) { |
| 521 | // TODO: Improve log message in the next pass |
| 522 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, |
| 523 | __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", |
| 524 | "Cannot copy from an image whose source layout is %s " |
| 525 | "and doesn't match the current layout %s.", |
| 526 | string_VkImageLayout(srcImageLayout), string_VkImageLayout(node.layout)); |
| 527 | } |
| 528 | } |
| 529 | if (srcImageLayout != VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL) { |
| 530 | if (srcImageLayout == VK_IMAGE_LAYOUT_GENERAL) { |
| 531 | // 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] | 532 | auto image_state = GetImageState(device_data, srcImage); |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 533 | if (image_state->createInfo.tiling != VK_IMAGE_TILING_LINEAR) { |
| 534 | // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning. |
| 535 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, |
| 536 | __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", |
| 537 | "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL."); |
| 538 | } |
| 539 | } else { |
| 540 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, msgCode, |
| 541 | "DS", "Layout for input image is %s but can only be TRANSFER_SRC_OPTIMAL or GENERAL. %s", |
| 542 | string_VkImageLayout(srcImageLayout), validation_error_map[msgCode]); |
| 543 | } |
| 544 | } |
| 545 | return skip_call; |
| 546 | } |
| 547 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 548 | bool VerifyDestImageLayout(layer_data *device_data, GLOBAL_CB_NODE *cb_node, VkImage destImage, VkImageSubresourceLayers subLayers, |
| 549 | VkImageLayout destImageLayout, UNIQUE_VALIDATION_ERROR_CODE msgCode) { |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 550 | const auto report_data = core_validation::GetReportData(device_data); |
| 551 | bool skip_call = false; |
| 552 | |
| 553 | for (uint32_t i = 0; i < subLayers.layerCount; ++i) { |
| 554 | uint32_t layer = i + subLayers.baseArrayLayer; |
| 555 | VkImageSubresource sub = {subLayers.aspectMask, subLayers.mipLevel, layer}; |
| 556 | IMAGE_CMD_BUF_LAYOUT_NODE node; |
| 557 | if (!FindCmdBufLayout(device_data, cb_node, destImage, sub, node)) { |
| 558 | SetLayout(device_data, cb_node, destImage, sub, IMAGE_CMD_BUF_LAYOUT_NODE(destImageLayout, destImageLayout)); |
| 559 | continue; |
| 560 | } |
| 561 | if (node.layout != destImageLayout) { |
| 562 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, |
| 563 | __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", |
| 564 | "Cannot copy from an image whose dest layout is %s and " |
| 565 | "doesn't match the current layout %s.", |
| 566 | string_VkImageLayout(destImageLayout), string_VkImageLayout(node.layout)); |
| 567 | } |
| 568 | } |
| 569 | if (destImageLayout != VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) { |
| 570 | if (destImageLayout == VK_IMAGE_LAYOUT_GENERAL) { |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 571 | auto image_state = GetImageState(device_data, destImage); |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 572 | if (image_state->createInfo.tiling != VK_IMAGE_TILING_LINEAR) { |
| 573 | // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning. |
| 574 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, |
| 575 | __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", |
| 576 | "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL."); |
| 577 | } |
| 578 | } else { |
| 579 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, msgCode, |
| 580 | "DS", "Layout for output image is %s but can only be TRANSFER_DST_OPTIMAL or GENERAL. %s", |
| 581 | string_VkImageLayout(destImageLayout), validation_error_map[msgCode]); |
| 582 | } |
| 583 | } |
| 584 | return skip_call; |
| 585 | } |
| 586 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 587 | void TransitionFinalSubpassLayouts(layer_data *device_data, GLOBAL_CB_NODE *pCB, const VkRenderPassBeginInfo *pRenderPassBegin, |
| 588 | FRAMEBUFFER_STATE *framebuffer_state) { |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 589 | auto renderPass = GetRenderPassState(device_data, pRenderPassBegin->renderPass); |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 590 | if (!renderPass) return; |
| 591 | |
| 592 | const VkRenderPassCreateInfo *pRenderPassInfo = renderPass->createInfo.ptr(); |
| 593 | if (framebuffer_state) { |
| 594 | for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) { |
| 595 | auto image_view = framebuffer_state->createInfo.pAttachments[i]; |
| 596 | SetImageViewLayout(device_data, pCB, image_view, pRenderPassInfo->pAttachments[i].finalLayout); |
| 597 | } |
| 598 | } |
| 599 | } |
| 600 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 601 | bool PreCallValidateCreateImage(layer_data *device_data, const VkImageCreateInfo *pCreateInfo, |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 602 | const VkAllocationCallbacks *pAllocator, VkImage *pImage) { |
| 603 | bool skip_call = false; |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 604 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 605 | |
Jeremy Hayes | 96dcd81 | 2017-03-14 14:04:19 -0600 | [diff] [blame] | 606 | if (pCreateInfo->format == VK_FORMAT_UNDEFINED) { |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 607 | skip_call |= |
| 608 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, |
| 609 | VALIDATION_ERROR_00715, "IMAGE", "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED. %s", |
| 610 | validation_error_map[VALIDATION_ERROR_00715]); |
Jeremy Hayes | 96dcd81 | 2017-03-14 14:04:19 -0600 | [diff] [blame] | 611 | |
| 612 | return skip_call; |
| 613 | } |
| 614 | |
| 615 | const VkFormatProperties *properties = GetFormatProperties(device_data, pCreateInfo->format); |
| 616 | |
| 617 | if ((pCreateInfo->tiling == VK_IMAGE_TILING_LINEAR) && (properties->linearTilingFeatures == 0)) { |
| 618 | std::stringstream ss; |
| 619 | ss << "vkCreateImage format parameter (" << string_VkFormat(pCreateInfo->format) << ") is an unsupported format"; |
| 620 | skip_call |= |
| 621 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, |
| 622 | VALIDATION_ERROR_02150, "IMAGE", "%s. %s", ss.str().c_str(), validation_error_map[VALIDATION_ERROR_02150]); |
| 623 | |
| 624 | return skip_call; |
| 625 | } |
| 626 | |
| 627 | if ((pCreateInfo->tiling == VK_IMAGE_TILING_OPTIMAL) && (properties->optimalTilingFeatures == 0)) { |
| 628 | std::stringstream ss; |
| 629 | ss << "vkCreateImage format parameter (" << string_VkFormat(pCreateInfo->format) << ") is an unsupported format"; |
| 630 | skip_call |= |
| 631 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, |
| 632 | VALIDATION_ERROR_02155, "IMAGE", "%s. %s", ss.str().c_str(), validation_error_map[VALIDATION_ERROR_02155]); |
| 633 | |
| 634 | return skip_call; |
| 635 | } |
| 636 | |
| 637 | // Validate that format supports usage as color attachment |
| 638 | if (pCreateInfo->usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) { |
| 639 | if ((pCreateInfo->tiling == VK_IMAGE_TILING_OPTIMAL) && |
| 640 | ((properties->optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) == 0)) { |
| 641 | std::stringstream ss; |
| 642 | ss << "vkCreateImage: VkFormat for TILING_OPTIMAL image (" << string_VkFormat(pCreateInfo->format) |
| 643 | << ") does not support requested Image usage type VK_IMAGE_USAGE_COLOR_ATTACHMENT"; |
| 644 | skip_call |= |
| 645 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, |
| 646 | VALIDATION_ERROR_02158, "IMAGE", "%s. %s", ss.str().c_str(), validation_error_map[VALIDATION_ERROR_02158]); |
| 647 | } |
| 648 | if ((pCreateInfo->tiling == VK_IMAGE_TILING_LINEAR) && |
| 649 | ((properties->linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) == 0)) { |
| 650 | std::stringstream ss; |
| 651 | ss << "vkCreateImage: VkFormat for TILING_LINEAR image (" << string_VkFormat(pCreateInfo->format) |
| 652 | << ") does not support requested Image usage type VK_IMAGE_USAGE_COLOR_ATTACHMENT"; |
| 653 | skip_call |= |
| 654 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, |
| 655 | VALIDATION_ERROR_02153, "IMAGE", "%s. %s", ss.str().c_str(), validation_error_map[VALIDATION_ERROR_02153]); |
| 656 | } |
| 657 | } |
| 658 | |
| 659 | // Validate that format supports usage as depth/stencil attachment |
| 660 | if (pCreateInfo->usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) { |
| 661 | if ((pCreateInfo->tiling == VK_IMAGE_TILING_OPTIMAL) && |
| 662 | ((properties->optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) == 0)) { |
| 663 | std::stringstream ss; |
| 664 | ss << "vkCreateImage: VkFormat for TILING_OPTIMAL image (" << string_VkFormat(pCreateInfo->format) |
| 665 | << ") does not support requested Image usage type VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT"; |
| 666 | skip_call |= |
| 667 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, |
| 668 | VALIDATION_ERROR_02159, "IMAGE", "%s. %s", ss.str().c_str(), validation_error_map[VALIDATION_ERROR_02159]); |
| 669 | } |
| 670 | if ((pCreateInfo->tiling == VK_IMAGE_TILING_LINEAR) && |
| 671 | ((properties->linearTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) == 0)) { |
| 672 | std::stringstream ss; |
| 673 | ss << "vkCreateImage: VkFormat for TILING_LINEAR image (" << string_VkFormat(pCreateInfo->format) |
| 674 | << ") does not support requested Image usage type VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT"; |
| 675 | skip_call |= |
| 676 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, |
| 677 | VALIDATION_ERROR_02154, "IMAGE", "%s. %s", ss.str().c_str(), validation_error_map[VALIDATION_ERROR_02154]); |
| 678 | } |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 679 | } |
| 680 | |
Mark Lobodzinski | efd933b | 2017-02-10 12:09:23 -0700 | [diff] [blame] | 681 | const VkImageFormatProperties *ImageFormatProperties = GetImageFormatProperties( |
| 682 | device_data, pCreateInfo->format, pCreateInfo->imageType, pCreateInfo->tiling, pCreateInfo->usage, pCreateInfo->flags); |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 683 | |
Mark Lobodzinski | efd933b | 2017-02-10 12:09:23 -0700 | [diff] [blame] | 684 | VkDeviceSize imageGranularity = GetPhysicalDeviceProperties(device_data)->limits.bufferImageGranularity; |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 685 | imageGranularity = imageGranularity == 1 ? 0 : imageGranularity; |
| 686 | |
Mark Lobodzinski | 688ed32 | 2017-01-27 11:13:21 -0700 | [diff] [blame] | 687 | if ((pCreateInfo->extent.width <= 0) || (pCreateInfo->extent.height <= 0) || (pCreateInfo->extent.depth <= 0)) { |
| 688 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__, |
| 689 | VALIDATION_ERROR_00716, "Image", |
| 690 | "CreateImage extent is 0 for at least one required dimension for image: " |
| 691 | "Width = %d Height = %d Depth = %d. %s", |
| 692 | pCreateInfo->extent.width, pCreateInfo->extent.height, pCreateInfo->extent.depth, |
| 693 | validation_error_map[VALIDATION_ERROR_00716]); |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 694 | } |
| 695 | |
| 696 | // TODO: VALIDATION_ERROR_02125 VALIDATION_ERROR_02126 VALIDATION_ERROR_02128 VALIDATION_ERROR_00720 |
| 697 | // All these extent-related VUs should be checked here |
Mark Lobodzinski | efd933b | 2017-02-10 12:09:23 -0700 | [diff] [blame] | 698 | if ((pCreateInfo->extent.depth > ImageFormatProperties->maxExtent.depth) || |
| 699 | (pCreateInfo->extent.width > ImageFormatProperties->maxExtent.width) || |
| 700 | (pCreateInfo->extent.height > ImageFormatProperties->maxExtent.height)) { |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 701 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__, |
| 702 | IMAGE_INVALID_FORMAT_LIMITS_VIOLATION, "Image", |
| 703 | "CreateImage extents exceed allowable limits for format: " |
| 704 | "Width = %d Height = %d Depth = %d: Limits for Width = %d Height = %d Depth = %d for format %s.", |
| 705 | pCreateInfo->extent.width, pCreateInfo->extent.height, pCreateInfo->extent.depth, |
Mark Lobodzinski | efd933b | 2017-02-10 12:09:23 -0700 | [diff] [blame] | 706 | ImageFormatProperties->maxExtent.width, ImageFormatProperties->maxExtent.height, |
| 707 | ImageFormatProperties->maxExtent.depth, string_VkFormat(pCreateInfo->format)); |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | uint64_t totalSize = ((uint64_t)pCreateInfo->extent.width * (uint64_t)pCreateInfo->extent.height * |
| 711 | (uint64_t)pCreateInfo->extent.depth * (uint64_t)pCreateInfo->arrayLayers * |
| 712 | (uint64_t)pCreateInfo->samples * (uint64_t)vk_format_get_size(pCreateInfo->format) + |
| 713 | (uint64_t)imageGranularity) & |
| 714 | ~(uint64_t)imageGranularity; |
| 715 | |
Mark Lobodzinski | efd933b | 2017-02-10 12:09:23 -0700 | [diff] [blame] | 716 | if (totalSize > ImageFormatProperties->maxResourceSize) { |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 717 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__, |
| 718 | IMAGE_INVALID_FORMAT_LIMITS_VIOLATION, "Image", |
| 719 | "CreateImage resource size exceeds allowable maximum " |
| 720 | "Image resource size = 0x%" PRIxLEAST64 ", maximum resource size = 0x%" PRIxLEAST64 " ", |
Mark Lobodzinski | efd933b | 2017-02-10 12:09:23 -0700 | [diff] [blame] | 721 | totalSize, ImageFormatProperties->maxResourceSize); |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | // TODO: VALIDATION_ERROR_02132 |
Mark Lobodzinski | efd933b | 2017-02-10 12:09:23 -0700 | [diff] [blame] | 725 | if (pCreateInfo->mipLevels > ImageFormatProperties->maxMipLevels) { |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 726 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__, |
| 727 | IMAGE_INVALID_FORMAT_LIMITS_VIOLATION, "Image", |
| 728 | "CreateImage mipLevels=%d exceeds allowable maximum supported by format of %d", pCreateInfo->mipLevels, |
Mark Lobodzinski | efd933b | 2017-02-10 12:09:23 -0700 | [diff] [blame] | 729 | ImageFormatProperties->maxMipLevels); |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 730 | } |
| 731 | |
Mark Lobodzinski | efd933b | 2017-02-10 12:09:23 -0700 | [diff] [blame] | 732 | if (pCreateInfo->arrayLayers > ImageFormatProperties->maxArrayLayers) { |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 733 | skip_call |= log_msg( |
| 734 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__, VALIDATION_ERROR_02133, |
| 735 | "Image", "CreateImage arrayLayers=%d exceeds allowable maximum supported by format of %d. %s", pCreateInfo->arrayLayers, |
Mark Lobodzinski | efd933b | 2017-02-10 12:09:23 -0700 | [diff] [blame] | 736 | ImageFormatProperties->maxArrayLayers, validation_error_map[VALIDATION_ERROR_02133]); |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 737 | } |
| 738 | |
Mark Lobodzinski | efd933b | 2017-02-10 12:09:23 -0700 | [diff] [blame] | 739 | if ((pCreateInfo->samples & ImageFormatProperties->sampleCounts) == 0) { |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 740 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__, |
| 741 | VALIDATION_ERROR_02138, "Image", "CreateImage samples %s is not supported by format 0x%.8X. %s", |
Mark Lobodzinski | efd933b | 2017-02-10 12:09:23 -0700 | [diff] [blame] | 742 | string_VkSampleCountFlagBits(pCreateInfo->samples), ImageFormatProperties->sampleCounts, |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 743 | validation_error_map[VALIDATION_ERROR_02138]); |
| 744 | } |
| 745 | |
| 746 | if (pCreateInfo->initialLayout != VK_IMAGE_LAYOUT_UNDEFINED && pCreateInfo->initialLayout != VK_IMAGE_LAYOUT_PREINITIALIZED) { |
| 747 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__, |
| 748 | VALIDATION_ERROR_00731, "Image", |
| 749 | "vkCreateImage parameter, pCreateInfo->initialLayout, must be VK_IMAGE_LAYOUT_UNDEFINED or " |
| 750 | "VK_IMAGE_LAYOUT_PREINITIALIZED. %s", |
| 751 | validation_error_map[VALIDATION_ERROR_00731]); |
| 752 | } |
| 753 | |
Mark Lobodzinski | 847b60c | 2017-03-13 09:32:45 -0600 | [diff] [blame] | 754 | if ((pCreateInfo->flags & VK_IMAGE_CREATE_SPARSE_BINDING_BIT) && (!GetEnabledFeatures(device_data)->sparseBinding)) { |
| 755 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, |
| 756 | VALIDATION_ERROR_02143, "DS", |
| 757 | "vkCreateImage(): the sparseBinding device feature is disabled: Images cannot be created with the " |
| 758 | "VK_IMAGE_CREATE_SPARSE_BINDING_BIT set. %s", |
| 759 | validation_error_map[VALIDATION_ERROR_02143]); |
| 760 | } |
| 761 | |
Mark Lobodzinski | 035a4cf | 2017-03-13 09:45:07 -0600 | [diff] [blame] | 762 | if ((pCreateInfo->flags & VK_IMAGE_CREATE_SPARSE_ALIASED_BIT) && (!GetEnabledFeatures(device_data)->sparseResidencyAliased)) { |
| 763 | skip_call |= |
| 764 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, |
| 765 | DRAWSTATE_INVALID_FEATURE, "DS", |
| 766 | "vkCreateImage(): the sparseResidencyAliased device feature is disabled: Images cannot be created with the " |
| 767 | "VK_IMAGE_CREATE_SPARSE_ALIASED_BIT set."); |
| 768 | } |
| 769 | |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 770 | return skip_call; |
| 771 | } |
| 772 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 773 | void PostCallRecordCreateImage(layer_data *device_data, const VkImageCreateInfo *pCreateInfo, VkImage *pImage) { |
Mark Lobodzinski | 42fe5f7 | 2017-01-11 11:36:16 -0700 | [diff] [blame] | 774 | IMAGE_LAYOUT_NODE image_state; |
| 775 | image_state.layout = pCreateInfo->initialLayout; |
| 776 | image_state.format = pCreateInfo->format; |
Mark Lobodzinski | 214144a | 2017-01-27 14:25:32 -0700 | [diff] [blame] | 777 | 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] | 778 | ImageSubresourcePair subpair{*pImage, false, VkImageSubresource()}; |
Mark Lobodzinski | 214144a | 2017-01-27 14:25:32 -0700 | [diff] [blame] | 779 | (*core_validation::GetImageSubresourceMap(device_data))[*pImage].push_back(subpair); |
| 780 | (*core_validation::GetImageLayoutMap(device_data))[subpair] = image_state; |
Mark Lobodzinski | 42fe5f7 | 2017-01-11 11:36:16 -0700 | [diff] [blame] | 781 | } |
Mark Lobodzinski | 9ef5d56 | 2017-01-27 12:28:30 -0700 | [diff] [blame] | 782 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 783 | 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] | 784 | const CHECK_DISABLED *disabled = core_validation::GetDisables(device_data); |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 785 | *image_state = core_validation::GetImageState(device_data, image); |
Mark Lobodzinski | 9ef5d56 | 2017-01-27 12:28:30 -0700 | [diff] [blame] | 786 | *obj_struct = {reinterpret_cast<uint64_t &>(image), VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT}; |
| 787 | if (disabled->destroy_image) return false; |
| 788 | bool skip = false; |
| 789 | if (*image_state) { |
| 790 | skip |= core_validation::ValidateObjectNotInUse(device_data, *image_state, *obj_struct, VALIDATION_ERROR_00743); |
| 791 | } |
| 792 | return skip; |
| 793 | } |
| 794 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 795 | 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] | 796 | core_validation::invalidateCommandBuffers(device_data, image_state->cb_bindings, obj_struct); |
| 797 | // Clean up memory mapping, bindings and range references for image |
| 798 | for (auto mem_binding : image_state->GetBoundMemory()) { |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 799 | auto mem_info = core_validation::GetMemObjInfo(device_data, mem_binding); |
Mark Lobodzinski | 9ef5d56 | 2017-01-27 12:28:30 -0700 | [diff] [blame] | 800 | if (mem_info) { |
| 801 | core_validation::RemoveImageMemoryRange(obj_struct.handle, mem_info); |
| 802 | } |
| 803 | } |
| 804 | core_validation::ClearMemoryObjectBindings(device_data, obj_struct.handle, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT); |
| 805 | // Remove image from imageMap |
| 806 | core_validation::GetImageMap(device_data)->erase(image); |
| 807 | std::unordered_map<VkImage, std::vector<ImageSubresourcePair>> *imageSubresourceMap = |
| 808 | core_validation::GetImageSubresourceMap(device_data); |
| 809 | |
| 810 | const auto &sub_entry = imageSubresourceMap->find(image); |
| 811 | if (sub_entry != imageSubresourceMap->end()) { |
| 812 | for (const auto &pair : sub_entry->second) { |
| 813 | core_validation::GetImageLayoutMap(device_data)->erase(pair); |
| 814 | } |
| 815 | imageSubresourceMap->erase(sub_entry); |
| 816 | } |
| 817 | } |
Mark Lobodzinski | c409a58 | 2017-01-27 15:16:01 -0700 | [diff] [blame] | 818 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 819 | bool ValidateImageAttributes(layer_data *device_data, IMAGE_STATE *image_state, VkImageSubresourceRange range) { |
Mark Lobodzinski | c409a58 | 2017-01-27 15:16:01 -0700 | [diff] [blame] | 820 | bool skip = false; |
| 821 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 822 | |
| 823 | if (range.aspectMask != VK_IMAGE_ASPECT_COLOR_BIT) { |
| 824 | char const str[] = "vkCmdClearColorImage aspectMasks for all subresource ranges must be set to VK_IMAGE_ASPECT_COLOR_BIT"; |
| 825 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 826 | reinterpret_cast<uint64_t &>(image_state->image), __LINE__, DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", str); |
| 827 | } |
| 828 | |
| 829 | if (vk_format_is_depth_or_stencil(image_state->createInfo.format)) { |
| 830 | char const str[] = "vkCmdClearColorImage called with depth/stencil image."; |
| 831 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 832 | reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01088, "IMAGE", "%s. %s", str, |
| 833 | validation_error_map[VALIDATION_ERROR_01088]); |
| 834 | } else if (vk_format_is_compressed(image_state->createInfo.format)) { |
| 835 | char const str[] = "vkCmdClearColorImage called with compressed image."; |
| 836 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 837 | reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01088, "IMAGE", "%s. %s", str, |
| 838 | validation_error_map[VALIDATION_ERROR_01088]); |
| 839 | } |
| 840 | |
| 841 | if (!(image_state->createInfo.usage & VK_IMAGE_USAGE_TRANSFER_DST_BIT)) { |
| 842 | char const str[] = "vkCmdClearColorImage called with image created without VK_IMAGE_USAGE_TRANSFER_DST_BIT."; |
| 843 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 844 | reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01084, "IMAGE", "%s. %s", str, |
| 845 | validation_error_map[VALIDATION_ERROR_01084]); |
| 846 | } |
| 847 | return skip; |
| 848 | } |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 849 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 850 | void ResolveRemainingLevelsLayers(layer_data *dev_data, VkImageSubresourceRange *range, IMAGE_STATE *image_state) { |
Mark Lobodzinski | 9c93dbd | 2017-02-02 08:31:18 -0700 | [diff] [blame] | 851 | // If the caller used the special values VK_REMAINING_MIP_LEVELS and VK_REMAINING_ARRAY_LAYERS, resolve them now in our |
| 852 | // internal state to the actual values. |
| 853 | if (range->levelCount == VK_REMAINING_MIP_LEVELS) { |
| 854 | range->levelCount = image_state->createInfo.mipLevels - range->baseMipLevel; |
| 855 | } |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 856 | |
Mark Lobodzinski | 9c93dbd | 2017-02-02 08:31:18 -0700 | [diff] [blame] | 857 | if (range->layerCount == VK_REMAINING_ARRAY_LAYERS) { |
| 858 | range->layerCount = image_state->createInfo.arrayLayers - range->baseArrayLayer; |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 859 | } |
| 860 | } |
| 861 | |
| 862 | // 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] | 863 | void ResolveRemainingLevelsLayers(layer_data *dev_data, uint32_t *levels, uint32_t *layers, VkImageSubresourceRange range, |
| 864 | IMAGE_STATE *image_state) { |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 865 | *levels = range.levelCount; |
| 866 | *layers = range.layerCount; |
Mark Lobodzinski | 9c93dbd | 2017-02-02 08:31:18 -0700 | [diff] [blame] | 867 | if (range.levelCount == VK_REMAINING_MIP_LEVELS) { |
| 868 | *levels = image_state->createInfo.mipLevels - range.baseMipLevel; |
| 869 | } |
| 870 | if (range.layerCount == VK_REMAINING_ARRAY_LAYERS) { |
| 871 | *layers = image_state->createInfo.arrayLayers - range.baseArrayLayer; |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 872 | } |
| 873 | } |
| 874 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 875 | 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] | 876 | VkImageSubresourceRange range, VkImageLayout dest_image_layout, const char *func_name) { |
| 877 | bool skip = false; |
| 878 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 879 | |
| 880 | VkImageSubresourceRange resolved_range = range; |
Mark Lobodzinski | 9c93dbd | 2017-02-02 08:31:18 -0700 | [diff] [blame] | 881 | ResolveRemainingLevelsLayers(device_data, &resolved_range, image_state); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 882 | |
| 883 | if (dest_image_layout != VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) { |
| 884 | if (dest_image_layout == VK_IMAGE_LAYOUT_GENERAL) { |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 885 | if (image_state->createInfo.tiling != VK_IMAGE_TILING_LINEAR) { |
| 886 | // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning. |
| 887 | skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, |
| 888 | __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", |
| 889 | "%s: Layout for cleared image should be TRANSFER_DST_OPTIMAL instead of GENERAL.", func_name); |
| 890 | } |
| 891 | } else { |
| 892 | UNIQUE_VALIDATION_ERROR_CODE error_code = VALIDATION_ERROR_01086; |
| 893 | if (strcmp(func_name, "vkCmdClearDepthStencilImage()") == 0) { |
| 894 | error_code = VALIDATION_ERROR_01101; |
| 895 | } else { |
| 896 | assert(strcmp(func_name, "vkCmdClearColorImage()") == 0); |
| 897 | } |
| 898 | skip |= |
| 899 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, error_code, "DS", |
| 900 | "%s: Layout for cleared image is %s but can only be " |
| 901 | "TRANSFER_DST_OPTIMAL or GENERAL. %s", |
| 902 | func_name, string_VkImageLayout(dest_image_layout), validation_error_map[error_code]); |
| 903 | } |
| 904 | } |
| 905 | |
| 906 | for (uint32_t level_index = 0; level_index < resolved_range.levelCount; ++level_index) { |
| 907 | uint32_t level = level_index + resolved_range.baseMipLevel; |
| 908 | for (uint32_t layer_index = 0; layer_index < resolved_range.layerCount; ++layer_index) { |
| 909 | uint32_t layer = layer_index + resolved_range.baseArrayLayer; |
| 910 | VkImageSubresource sub = {resolved_range.aspectMask, level, layer}; |
| 911 | IMAGE_CMD_BUF_LAYOUT_NODE node; |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 912 | if (FindCmdBufLayout(device_data, cb_node, image_state->image, sub, node)) { |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 913 | if (node.layout != dest_image_layout) { |
| 914 | UNIQUE_VALIDATION_ERROR_CODE error_code = VALIDATION_ERROR_01085; |
| 915 | if (strcmp(func_name, "vkCmdClearDepthStencilImage()") == 0) { |
| 916 | error_code = VALIDATION_ERROR_01100; |
| 917 | } else { |
| 918 | assert(strcmp(func_name, "vkCmdClearColorImage()") == 0); |
| 919 | } |
| 920 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, |
| 921 | __LINE__, error_code, "DS", |
| 922 | "%s: Cannot clear an image whose layout is %s and " |
| 923 | "doesn't match the current layout %s. %s", |
| 924 | func_name, string_VkImageLayout(dest_image_layout), string_VkImageLayout(node.layout), |
| 925 | validation_error_map[error_code]); |
| 926 | } |
| 927 | } |
| 928 | } |
| 929 | } |
| 930 | |
| 931 | return skip; |
| 932 | } |
| 933 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 934 | void RecordClearImageLayout(layer_data *device_data, GLOBAL_CB_NODE *cb_node, VkImage image, VkImageSubresourceRange range, |
| 935 | VkImageLayout dest_image_layout) { |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 936 | VkImageSubresourceRange resolved_range = range; |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 937 | ResolveRemainingLevelsLayers(device_data, &resolved_range, GetImageState(device_data, image)); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 938 | |
| 939 | for (uint32_t level_index = 0; level_index < resolved_range.levelCount; ++level_index) { |
| 940 | uint32_t level = level_index + resolved_range.baseMipLevel; |
| 941 | for (uint32_t layer_index = 0; layer_index < resolved_range.layerCount; ++layer_index) { |
| 942 | uint32_t layer = layer_index + resolved_range.baseArrayLayer; |
| 943 | VkImageSubresource sub = {resolved_range.aspectMask, level, layer}; |
| 944 | IMAGE_CMD_BUF_LAYOUT_NODE node; |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 945 | if (!FindCmdBufLayout(device_data, cb_node, image, sub, node)) { |
| 946 | 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] | 947 | } |
| 948 | } |
| 949 | } |
| 950 | } |
| 951 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 952 | bool PreCallValidateCmdClearColorImage(layer_data *dev_data, VkCommandBuffer commandBuffer, VkImage image, |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 953 | VkImageLayout imageLayout, uint32_t rangeCount, const VkImageSubresourceRange *pRanges) { |
| 954 | bool skip = false; |
| 955 | // TODO : Verify memory is in VK_IMAGE_STATE_CLEAR state |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 956 | auto cb_node = GetCBNode(dev_data, commandBuffer); |
| 957 | auto image_state = GetImageState(dev_data, image); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 958 | if (cb_node && image_state) { |
| 959 | skip |= ValidateMemoryIsBoundToImage(dev_data, image_state, "vkCmdClearColorImage()", VALIDATION_ERROR_02527); |
| 960 | skip |= ValidateCmd(dev_data, cb_node, CMD_CLEARCOLORIMAGE, "vkCmdClearColorImage()"); |
| 961 | skip |= insideRenderPass(dev_data, cb_node, "vkCmdClearColorImage()", VALIDATION_ERROR_01096); |
| 962 | for (uint32_t i = 0; i < rangeCount; ++i) { |
| 963 | skip |= ValidateImageAttributes(dev_data, image_state, pRanges[i]); |
Mark Lobodzinski | 9c93dbd | 2017-02-02 08:31:18 -0700 | [diff] [blame] | 964 | skip |= VerifyClearImageLayout(dev_data, cb_node, image_state, pRanges[i], imageLayout, "vkCmdClearColorImage()"); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 965 | } |
| 966 | } |
| 967 | return skip; |
| 968 | } |
| 969 | |
| 970 | // This state recording routine is shared between ClearColorImage and ClearDepthStencilImage |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 971 | void PreCallRecordCmdClearImage(layer_data *dev_data, VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, |
| 972 | uint32_t rangeCount, const VkImageSubresourceRange *pRanges, CMD_TYPE cmd_type) { |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 973 | auto cb_node = GetCBNode(dev_data, commandBuffer); |
| 974 | auto image_state = GetImageState(dev_data, image); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 975 | if (cb_node && image_state) { |
| 976 | AddCommandBufferBindingImage(dev_data, cb_node, image_state); |
| 977 | std::function<bool()> function = [=]() { |
| 978 | SetImageMemoryValid(dev_data, image_state, true); |
| 979 | return false; |
| 980 | }; |
| 981 | cb_node->validate_functions.push_back(function); |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 982 | core_validation::UpdateCmdBufferLastCmd(cb_node, cmd_type); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 983 | for (uint32_t i = 0; i < rangeCount; ++i) { |
| 984 | RecordClearImageLayout(dev_data, cb_node, image, pRanges[i], imageLayout); |
| 985 | } |
| 986 | } |
| 987 | } |
| 988 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 989 | bool PreCallValidateCmdClearDepthStencilImage(layer_data *device_data, VkCommandBuffer commandBuffer, VkImage image, |
| 990 | VkImageLayout imageLayout, uint32_t rangeCount, |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 991 | const VkImageSubresourceRange *pRanges) { |
| 992 | bool skip = false; |
Mark Lobodzinski | 1241a31 | 2017-02-01 10:57:21 -0700 | [diff] [blame] | 993 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 994 | |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 995 | // TODO : Verify memory is in VK_IMAGE_STATE_CLEAR state |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 996 | auto cb_node = GetCBNode(device_data, commandBuffer); |
| 997 | auto image_state = GetImageState(device_data, image); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 998 | if (cb_node && image_state) { |
Mark Lobodzinski | 1241a31 | 2017-02-01 10:57:21 -0700 | [diff] [blame] | 999 | skip |= ValidateMemoryIsBoundToImage(device_data, image_state, "vkCmdClearDepthStencilImage()", VALIDATION_ERROR_02528); |
| 1000 | skip |= ValidateCmd(device_data, cb_node, CMD_CLEARDEPTHSTENCILIMAGE, "vkCmdClearDepthStencilImage()"); |
| 1001 | skip |= insideRenderPass(device_data, cb_node, "vkCmdClearDepthStencilImage()", VALIDATION_ERROR_01111); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1002 | for (uint32_t i = 0; i < rangeCount; ++i) { |
Mark Lobodzinski | 9c93dbd | 2017-02-02 08:31:18 -0700 | [diff] [blame] | 1003 | skip |= |
| 1004 | VerifyClearImageLayout(device_data, cb_node, image_state, pRanges[i], imageLayout, "vkCmdClearDepthStencilImage()"); |
Mark Lobodzinski | 1241a31 | 2017-02-01 10:57:21 -0700 | [diff] [blame] | 1005 | // Image aspect must be depth or stencil or both |
| 1006 | if (((pRanges[i].aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) != VK_IMAGE_ASPECT_DEPTH_BIT) && |
| 1007 | ((pRanges[i].aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) != VK_IMAGE_ASPECT_STENCIL_BIT)) { |
| 1008 | char const str[] = |
| 1009 | "vkCmdClearDepthStencilImage aspectMasks for all subresource ranges must be " |
| 1010 | "set to VK_IMAGE_ASPECT_DEPTH_BIT and/or VK_IMAGE_ASPECT_STENCIL_BIT"; |
| 1011 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1012 | (uint64_t)commandBuffer, __LINE__, DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", str); |
| 1013 | } |
| 1014 | } |
| 1015 | if (image_state && !vk_format_is_depth_or_stencil(image_state->createInfo.format)) { |
| 1016 | char const str[] = "vkCmdClearDepthStencilImage called without a depth/stencil image."; |
| 1017 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 1018 | reinterpret_cast<uint64_t &>(image), __LINE__, VALIDATION_ERROR_01103, "IMAGE", "%s. %s", str, |
| 1019 | validation_error_map[VALIDATION_ERROR_01103]); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1020 | } |
| 1021 | } |
| 1022 | return skip; |
| 1023 | } |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1024 | |
| 1025 | // Returns true if [x, xoffset] and [y, yoffset] overlap |
| 1026 | static bool RangesIntersect(int32_t start, uint32_t start_offset, int32_t end, uint32_t end_offset) { |
| 1027 | bool result = false; |
| 1028 | uint32_t intersection_min = std::max(static_cast<uint32_t>(start), static_cast<uint32_t>(end)); |
| 1029 | uint32_t intersection_max = std::min(static_cast<uint32_t>(start) + start_offset, static_cast<uint32_t>(end) + end_offset); |
| 1030 | |
| 1031 | if (intersection_max > intersection_min) { |
| 1032 | result = true; |
| 1033 | } |
| 1034 | return result; |
| 1035 | } |
| 1036 | |
| 1037 | // Returns true if two VkImageCopy structures overlap |
| 1038 | static bool RegionIntersects(const VkImageCopy *src, const VkImageCopy *dst, VkImageType type) { |
| 1039 | bool result = false; |
| 1040 | if ((src->srcSubresource.mipLevel == dst->dstSubresource.mipLevel) && |
| 1041 | (RangesIntersect(src->srcSubresource.baseArrayLayer, src->srcSubresource.layerCount, dst->dstSubresource.baseArrayLayer, |
| 1042 | dst->dstSubresource.layerCount))) { |
| 1043 | result = true; |
| 1044 | switch (type) { |
| 1045 | case VK_IMAGE_TYPE_3D: |
| 1046 | result &= RangesIntersect(src->srcOffset.z, src->extent.depth, dst->dstOffset.z, dst->extent.depth); |
| 1047 | // Intentionally fall through to 2D case |
| 1048 | case VK_IMAGE_TYPE_2D: |
| 1049 | result &= RangesIntersect(src->srcOffset.y, src->extent.height, dst->dstOffset.y, dst->extent.height); |
| 1050 | // Intentionally fall through to 1D case |
| 1051 | case VK_IMAGE_TYPE_1D: |
| 1052 | result &= RangesIntersect(src->srcOffset.x, src->extent.width, dst->dstOffset.x, dst->extent.width); |
| 1053 | break; |
| 1054 | default: |
| 1055 | // Unrecognized or new IMAGE_TYPE enums will be caught in parameter_validation |
| 1056 | assert(false); |
| 1057 | } |
| 1058 | } |
| 1059 | return result; |
| 1060 | } |
| 1061 | |
| 1062 | // Returns true if offset and extent exceed image extents |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 1063 | static bool ExceedsBounds(const VkOffset3D *offset, const VkExtent3D *extent, const VkExtent3D *image_extent) { |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1064 | bool result = false; |
| 1065 | // Extents/depths cannot be negative but checks left in for clarity |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 1066 | if ((offset->z + extent->depth > image_extent->depth) || (offset->z < 0) || |
| 1067 | ((offset->z + static_cast<int32_t>(extent->depth)) < 0)) { |
| 1068 | result = true; |
| 1069 | } |
| 1070 | if ((offset->y + extent->height > image_extent->height) || (offset->y < 0) || |
| 1071 | ((offset->y + static_cast<int32_t>(extent->height)) < 0)) { |
| 1072 | result = true; |
| 1073 | } |
| 1074 | if ((offset->x + extent->width > image_extent->width) || (offset->x < 0) || |
| 1075 | ((offset->x + static_cast<int32_t>(extent->width)) < 0)) { |
| 1076 | result = true; |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1077 | } |
| 1078 | return result; |
| 1079 | } |
| 1080 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1081 | // Test if two VkExtent3D structs are equivalent |
| 1082 | static inline bool IsExtentEqual(const VkExtent3D *extent, const VkExtent3D *other_extent) { |
| 1083 | bool result = true; |
| 1084 | if ((extent->width != other_extent->width) || (extent->height != other_extent->height) || |
| 1085 | (extent->depth != other_extent->depth)) { |
| 1086 | result = false; |
| 1087 | } |
| 1088 | return result; |
| 1089 | } |
| 1090 | |
| 1091 | // Returns the image extent of a specific subresource. |
| 1092 | static inline VkExtent3D GetImageSubresourceExtent(const IMAGE_STATE *img, const VkImageSubresourceLayers *subresource) { |
| 1093 | const uint32_t mip = subresource->mipLevel; |
| 1094 | VkExtent3D extent = img->createInfo.extent; |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 1095 | // Don't allow mip adjustment to create 0 dim, but pass along a 0 if that's what subresource specified |
| 1096 | extent.width = (0 == extent.width ? 0 : std::max(1U, extent.width >> mip)); |
| 1097 | extent.height = (0 == extent.height ? 0 : std::max(1U, extent.height >> mip)); |
| 1098 | extent.depth = (0 == extent.depth ? 0 : std::max(1U, extent.depth >> mip)); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1099 | return extent; |
| 1100 | } |
| 1101 | |
| 1102 | // Test if the extent argument has all dimensions set to 0. |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 1103 | static inline bool IsExtentAllZeroes(const VkExtent3D *extent) { |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1104 | return ((extent->width == 0) && (extent->height == 0) && (extent->depth == 0)); |
| 1105 | } |
| 1106 | |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 1107 | // Test if the extent argument has any dimensions set to 0. |
| 1108 | static inline bool IsExtentSizeZero(const VkExtent3D *extent) { |
| 1109 | return ((extent->width == 0) || (extent->height == 0) || (extent->depth == 0)); |
| 1110 | } |
| 1111 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1112 | // Returns the image transfer granularity for a specific image scaled by compressed block size if necessary. |
| 1113 | static inline VkExtent3D GetScaledItg(layer_data *device_data, const GLOBAL_CB_NODE *cb_node, const IMAGE_STATE *img) { |
| 1114 | // Default to (0, 0, 0) granularity in case we can't find the real granularity for the physical device. |
| 1115 | VkExtent3D granularity = {0, 0, 0}; |
| 1116 | auto pPool = GetCommandPoolNode(device_data, cb_node->createInfo.commandPool); |
| 1117 | if (pPool) { |
| 1118 | granularity = |
| 1119 | GetPhysDevProperties(device_data)->queue_family_properties[pPool->queueFamilyIndex].minImageTransferGranularity; |
| 1120 | if (vk_format_is_compressed(img->createInfo.format)) { |
Mark Lobodzinski | 1308644 | 2017-02-24 08:53:14 -0700 | [diff] [blame] | 1121 | auto block_size = vk_format_compressed_texel_block_extents(img->createInfo.format); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1122 | granularity.width *= block_size.width; |
| 1123 | granularity.height *= block_size.height; |
| 1124 | } |
| 1125 | } |
| 1126 | return granularity; |
| 1127 | } |
| 1128 | |
| 1129 | // Test elements of a VkExtent3D structure against alignment constraints contained in another VkExtent3D structure |
| 1130 | static inline bool IsExtentAligned(const VkExtent3D *extent, const VkExtent3D *granularity) { |
| 1131 | bool valid = true; |
| 1132 | if ((vk_safe_modulo(extent->depth, granularity->depth) != 0) || (vk_safe_modulo(extent->width, granularity->width) != 0) || |
| 1133 | (vk_safe_modulo(extent->height, granularity->height) != 0)) { |
| 1134 | valid = false; |
| 1135 | } |
| 1136 | return valid; |
| 1137 | } |
| 1138 | |
| 1139 | // Check elements of a VkOffset3D structure against a queue family's Image Transfer Granularity values |
| 1140 | static inline bool CheckItgOffset(layer_data *device_data, const GLOBAL_CB_NODE *cb_node, const VkOffset3D *offset, |
| 1141 | const VkExtent3D *granularity, const uint32_t i, const char *function, const char *member) { |
| 1142 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 1143 | bool skip = false; |
| 1144 | VkExtent3D offset_extent = {}; |
| 1145 | offset_extent.width = static_cast<uint32_t>(abs(offset->x)); |
| 1146 | offset_extent.height = static_cast<uint32_t>(abs(offset->y)); |
| 1147 | offset_extent.depth = static_cast<uint32_t>(abs(offset->z)); |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 1148 | if (IsExtentAllZeroes(granularity)) { |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1149 | // If the queue family image transfer granularity is (0, 0, 0), then the offset must always be (0, 0, 0) |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 1150 | if (IsExtentAllZeroes(&offset_extent) == false) { |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1151 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, |
| 1152 | DRAWSTATE_IMAGE_TRANSFER_GRANULARITY, "DS", |
| 1153 | "%s: pRegion[%d].%s (x=%d, y=%d, z=%d) must be (x=0, y=0, z=0) " |
| 1154 | "when the command buffer's queue family image transfer granularity is (w=0, h=0, d=0).", |
| 1155 | function, i, member, offset->x, offset->y, offset->z); |
| 1156 | } |
| 1157 | } else { |
| 1158 | // If the queue family image transfer granularity is not (0, 0, 0), then the offset dimensions must always be even |
| 1159 | // integer multiples of the image transfer granularity. |
| 1160 | if (IsExtentAligned(&offset_extent, granularity) == false) { |
| 1161 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, |
| 1162 | DRAWSTATE_IMAGE_TRANSFER_GRANULARITY, "DS", |
| 1163 | "%s: pRegion[%d].%s (x=%d, y=%d, z=%d) dimensions must be even integer " |
| 1164 | "multiples of this command buffer's queue family image transfer granularity (w=%d, h=%d, d=%d).", |
| 1165 | function, i, member, offset->x, offset->y, offset->z, granularity->width, granularity->height, |
| 1166 | granularity->depth); |
| 1167 | } |
| 1168 | } |
| 1169 | return skip; |
| 1170 | } |
| 1171 | |
| 1172 | // Check elements of a VkExtent3D structure against a queue family's Image Transfer Granularity values |
| 1173 | static inline bool CheckItgExtent(layer_data *device_data, const GLOBAL_CB_NODE *cb_node, const VkExtent3D *extent, |
| 1174 | const VkOffset3D *offset, const VkExtent3D *granularity, const VkExtent3D *subresource_extent, |
| 1175 | const uint32_t i, const char *function, const char *member) { |
| 1176 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 1177 | bool skip = false; |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 1178 | if (IsExtentAllZeroes(granularity)) { |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1179 | // If the queue family image transfer granularity is (0, 0, 0), then the extent must always match the image |
| 1180 | // subresource extent. |
| 1181 | if (IsExtentEqual(extent, subresource_extent) == false) { |
| 1182 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, |
| 1183 | DRAWSTATE_IMAGE_TRANSFER_GRANULARITY, "DS", |
| 1184 | "%s: pRegion[%d].%s (w=%d, h=%d, d=%d) must match the image subresource extents (w=%d, h=%d, d=%d) " |
| 1185 | "when the command buffer's queue family image transfer granularity is (w=0, h=0, d=0).", |
| 1186 | function, i, member, extent->width, extent->height, extent->depth, subresource_extent->width, |
| 1187 | subresource_extent->height, subresource_extent->depth); |
| 1188 | } |
| 1189 | } else { |
| 1190 | // If the queue family image transfer granularity is not (0, 0, 0), then the extent dimensions must always be even |
| 1191 | // integer multiples of the image transfer granularity or the offset + extent dimensions must always match the image |
| 1192 | // subresource extent dimensions. |
| 1193 | VkExtent3D offset_extent_sum = {}; |
| 1194 | offset_extent_sum.width = static_cast<uint32_t>(abs(offset->x)) + extent->width; |
| 1195 | offset_extent_sum.height = static_cast<uint32_t>(abs(offset->y)) + extent->height; |
| 1196 | offset_extent_sum.depth = static_cast<uint32_t>(abs(offset->z)) + extent->depth; |
| 1197 | if ((IsExtentAligned(extent, granularity) == false) && (IsExtentEqual(&offset_extent_sum, subresource_extent) == false)) { |
| 1198 | skip |= |
| 1199 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, |
| 1200 | DRAWSTATE_IMAGE_TRANSFER_GRANULARITY, "DS", |
| 1201 | "%s: pRegion[%d].%s (w=%d, h=%d, d=%d) dimensions must be even integer multiples of this command buffer's " |
| 1202 | "queue family image transfer granularity (w=%d, h=%d, d=%d) or offset (x=%d, y=%d, z=%d) + " |
| 1203 | "extent (w=%d, h=%d, d=%d) must match the image subresource extents (w=%d, h=%d, d=%d).", |
| 1204 | function, i, member, extent->width, extent->height, extent->depth, granularity->width, granularity->height, |
| 1205 | granularity->depth, offset->x, offset->y, offset->z, extent->width, extent->height, extent->depth, |
| 1206 | subresource_extent->width, subresource_extent->height, subresource_extent->depth); |
| 1207 | } |
| 1208 | } |
| 1209 | return skip; |
| 1210 | } |
| 1211 | |
| 1212 | // Check a uint32_t width or stride value against a queue family's Image Transfer Granularity width value |
| 1213 | static inline bool CheckItgInt(layer_data *device_data, const GLOBAL_CB_NODE *cb_node, const uint32_t value, |
| 1214 | const uint32_t granularity, const uint32_t i, const char *function, const char *member) { |
| 1215 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 1216 | |
| 1217 | bool skip = false; |
| 1218 | if (vk_safe_modulo(value, granularity) != 0) { |
| 1219 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, |
| 1220 | DRAWSTATE_IMAGE_TRANSFER_GRANULARITY, "DS", |
| 1221 | "%s: pRegion[%d].%s (%d) must be an even integer multiple of this command buffer's queue family image " |
| 1222 | "transfer granularity width (%d).", |
| 1223 | function, i, member, value, granularity); |
| 1224 | } |
| 1225 | return skip; |
| 1226 | } |
| 1227 | |
| 1228 | // Check a VkDeviceSize value against a queue family's Image Transfer Granularity width value |
| 1229 | static inline bool CheckItgSize(layer_data *device_data, const GLOBAL_CB_NODE *cb_node, const VkDeviceSize value, |
| 1230 | const uint32_t granularity, const uint32_t i, const char *function, const char *member) { |
| 1231 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 1232 | bool skip = false; |
| 1233 | if (vk_safe_modulo(value, granularity) != 0) { |
| 1234 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, |
| 1235 | DRAWSTATE_IMAGE_TRANSFER_GRANULARITY, "DS", |
| 1236 | "%s: pRegion[%d].%s (%" PRIdLEAST64 |
| 1237 | ") must be an even integer multiple of this command buffer's queue family image transfer " |
| 1238 | "granularity width (%d).", |
| 1239 | function, i, member, value, granularity); |
| 1240 | } |
| 1241 | return skip; |
| 1242 | } |
| 1243 | |
| 1244 | // Check valid usage Image Tranfer Granularity requirements for elements of a VkBufferImageCopy structure |
| 1245 | bool ValidateCopyBufferImageTransferGranularityRequirements(layer_data *device_data, const GLOBAL_CB_NODE *cb_node, |
| 1246 | const IMAGE_STATE *img, const VkBufferImageCopy *region, |
| 1247 | const uint32_t i, const char *function) { |
| 1248 | bool skip = false; |
| 1249 | if (vk_format_is_compressed(img->createInfo.format) == true) { |
| 1250 | // TODO: Add granularity checking for compressed formats |
| 1251 | |
| 1252 | // bufferRowLength must be a multiple of the compressed texel block width |
| 1253 | // bufferImageHeight must be a multiple of the compressed texel block height |
| 1254 | // all members of imageOffset must be a multiple of the corresponding dimensions of the compressed texel block |
| 1255 | // bufferOffset must be a multiple of the compressed texel block size in bytes |
| 1256 | // imageExtent.width must be a multiple of the compressed texel block width or (imageExtent.width + imageOffset.x) |
| 1257 | // must equal the image subresource width |
| 1258 | // imageExtent.height must be a multiple of the compressed texel block height or (imageExtent.height + imageOffset.y) |
| 1259 | // must equal the image subresource height |
| 1260 | // imageExtent.depth must be a multiple of the compressed texel block depth or (imageExtent.depth + imageOffset.z) |
| 1261 | // must equal the image subresource depth |
| 1262 | } else { |
| 1263 | VkExtent3D granularity = GetScaledItg(device_data, cb_node, img); |
| 1264 | skip |= CheckItgSize(device_data, cb_node, region->bufferOffset, granularity.width, i, function, "bufferOffset"); |
| 1265 | skip |= CheckItgInt(device_data, cb_node, region->bufferRowLength, granularity.width, i, function, "bufferRowLength"); |
| 1266 | skip |= CheckItgInt(device_data, cb_node, region->bufferImageHeight, granularity.width, i, function, "bufferImageHeight"); |
| 1267 | skip |= CheckItgOffset(device_data, cb_node, ®ion->imageOffset, &granularity, i, function, "imageOffset"); |
| 1268 | VkExtent3D subresource_extent = GetImageSubresourceExtent(img, ®ion->imageSubresource); |
| 1269 | skip |= CheckItgExtent(device_data, cb_node, ®ion->imageExtent, ®ion->imageOffset, &granularity, &subresource_extent, |
| 1270 | i, function, "imageExtent"); |
| 1271 | } |
| 1272 | return skip; |
| 1273 | } |
| 1274 | |
| 1275 | // Check valid usage Image Tranfer Granularity requirements for elements of a VkImageCopy structure |
| 1276 | bool ValidateCopyImageTransferGranularityRequirements(layer_data *device_data, const GLOBAL_CB_NODE *cb_node, |
| 1277 | const IMAGE_STATE *img, const VkImageCopy *region, const uint32_t i, |
| 1278 | const char *function) { |
| 1279 | bool skip = false; |
| 1280 | VkExtent3D granularity = GetScaledItg(device_data, cb_node, img); |
| 1281 | skip |= CheckItgOffset(device_data, cb_node, ®ion->srcOffset, &granularity, i, function, "srcOffset"); |
| 1282 | skip |= CheckItgOffset(device_data, cb_node, ®ion->dstOffset, &granularity, i, function, "dstOffset"); |
| 1283 | VkExtent3D subresource_extent = GetImageSubresourceExtent(img, ®ion->dstSubresource); |
| 1284 | skip |= CheckItgExtent(device_data, cb_node, ®ion->extent, ®ion->dstOffset, &granularity, &subresource_extent, i, |
| 1285 | function, "extent"); |
| 1286 | return skip; |
| 1287 | } |
| 1288 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 1289 | bool PreCallValidateCmdCopyImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state, |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1290 | IMAGE_STATE *dst_image_state, uint32_t region_count, const VkImageCopy *regions, |
| 1291 | VkImageLayout src_image_layout, VkImageLayout dst_image_layout) { |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1292 | bool skip = false; |
| 1293 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 1294 | VkCommandBuffer command_buffer = cb_node->commandBuffer; |
| 1295 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1296 | for (uint32_t i = 0; i < region_count; i++) { |
| 1297 | if (regions[i].srcSubresource.layerCount == 0) { |
| 1298 | std::stringstream ss; |
| 1299 | ss << "vkCmdCopyImage: number of layers in pRegions[" << i << "] srcSubresource is zero"; |
| 1300 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1301 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", "%s", |
| 1302 | ss.str().c_str()); |
| 1303 | } |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1304 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1305 | if (regions[i].dstSubresource.layerCount == 0) { |
| 1306 | std::stringstream ss; |
| 1307 | ss << "vkCmdCopyImage: number of layers in pRegions[" << i << "] dstSubresource is zero"; |
| 1308 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1309 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", "%s", |
| 1310 | ss.str().c_str()); |
| 1311 | } |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1312 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1313 | // For each region the layerCount member of srcSubresource and dstSubresource must match |
| 1314 | if (regions[i].srcSubresource.layerCount != regions[i].dstSubresource.layerCount) { |
| 1315 | std::stringstream ss; |
| 1316 | ss << "vkCmdCopyImage: number of layers in source and destination subresources for pRegions[" << i << "] do not match"; |
| 1317 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1318 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01198, "IMAGE", "%s. %s", |
| 1319 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01198]); |
| 1320 | } |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1321 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1322 | // For each region, the aspectMask member of srcSubresource and dstSubresource must match |
| 1323 | if (regions[i].srcSubresource.aspectMask != regions[i].dstSubresource.aspectMask) { |
| 1324 | char const str[] = "vkCmdCopyImage: Src and dest aspectMasks for each region must match"; |
| 1325 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1326 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01197, "IMAGE", "%s. %s", str, |
| 1327 | validation_error_map[VALIDATION_ERROR_01197]); |
| 1328 | } |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1329 | |
Dave Houlton | 4eaaf3a | 2017-03-14 11:31:20 -0600 | [diff] [blame] | 1330 | // For each region, the aspectMask member of srcSubresource must be present in the source image |
| 1331 | if (!VerifyAspectsPresent(regions[i].srcSubresource.aspectMask, src_image_state->createInfo.format)) { |
| 1332 | std::stringstream ss; |
| 1333 | ss << "vkCmdCopyImage: pRegion[" << i |
| 1334 | << "] srcSubresource.aspectMask cannot specify aspects not present in source image"; |
| 1335 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1336 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01200, "IMAGE", "%s. %s", |
| 1337 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01200]); |
| 1338 | } |
| 1339 | |
| 1340 | // For each region, the aspectMask member of dstSubresource must be present in the destination image |
| 1341 | if (!VerifyAspectsPresent(regions[i].dstSubresource.aspectMask, dst_image_state->createInfo.format)) { |
| 1342 | std::stringstream ss; |
| 1343 | ss << "vkCmdCopyImage: pRegion[" << i << "] dstSubresource.aspectMask cannot specify aspects not present in dest image"; |
| 1344 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1345 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01201, "IMAGE", "%s. %s", |
| 1346 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01201]); |
| 1347 | } |
| 1348 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1349 | // AspectMask must not contain VK_IMAGE_ASPECT_METADATA_BIT |
| 1350 | if ((regions[i].srcSubresource.aspectMask & VK_IMAGE_ASPECT_METADATA_BIT) || |
| 1351 | (regions[i].dstSubresource.aspectMask & VK_IMAGE_ASPECT_METADATA_BIT)) { |
| 1352 | std::stringstream ss; |
| 1353 | ss << "vkCmdCopyImage: pRegions[" << i << "] may not specify aspectMask containing VK_IMAGE_ASPECT_METADATA_BIT"; |
| 1354 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1355 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01222, "IMAGE", "%s. %s", |
| 1356 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01222]); |
| 1357 | } |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1358 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1359 | // For each region, if aspectMask contains VK_IMAGE_ASPECT_COLOR_BIT, it must not contain either of |
| 1360 | // VK_IMAGE_ASPECT_DEPTH_BIT or VK_IMAGE_ASPECT_STENCIL_BIT |
| 1361 | if ((regions[i].srcSubresource.aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) && |
| 1362 | (regions[i].srcSubresource.aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT))) { |
| 1363 | char const str[] = "vkCmdCopyImage aspectMask cannot specify both COLOR and DEPTH/STENCIL aspects"; |
| 1364 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1365 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01221, "IMAGE", "%s. %s", str, |
| 1366 | validation_error_map[VALIDATION_ERROR_01221]); |
| 1367 | } |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1368 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1369 | // If either of the calling command's src_image or dst_image parameters are of VkImageType VK_IMAGE_TYPE_3D, |
| 1370 | // the baseArrayLayer and layerCount members of both srcSubresource and dstSubresource must be 0 and 1, respectively |
| 1371 | if (((src_image_state->createInfo.imageType == VK_IMAGE_TYPE_3D) || |
| 1372 | (dst_image_state->createInfo.imageType == VK_IMAGE_TYPE_3D)) && |
| 1373 | ((regions[i].srcSubresource.baseArrayLayer != 0) || (regions[i].srcSubresource.layerCount != 1) || |
| 1374 | (regions[i].dstSubresource.baseArrayLayer != 0) || (regions[i].dstSubresource.layerCount != 1))) { |
| 1375 | std::stringstream ss; |
| 1376 | ss << "vkCmdCopyImage: src or dstImage type was IMAGE_TYPE_3D, but in subRegion[" << i |
| 1377 | << "] baseArrayLayer was not zero or layerCount was not 1."; |
| 1378 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1379 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01199, "IMAGE", "%s. %s", |
| 1380 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01199]); |
| 1381 | } |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1382 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1383 | // MipLevel must be less than the mipLevels specified in VkImageCreateInfo when the image was created |
| 1384 | if (regions[i].srcSubresource.mipLevel >= src_image_state->createInfo.mipLevels) { |
| 1385 | std::stringstream ss; |
| 1386 | ss << "vkCmdCopyImage: pRegions[" << i |
| 1387 | << "] specifies a src mipLevel greater than the number specified when the srcImage was created."; |
| 1388 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1389 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01223, "IMAGE", "%s. %s", |
| 1390 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01223]); |
| 1391 | } |
| 1392 | if (regions[i].dstSubresource.mipLevel >= dst_image_state->createInfo.mipLevels) { |
| 1393 | std::stringstream ss; |
| 1394 | ss << "vkCmdCopyImage: pRegions[" << i |
| 1395 | << "] specifies a dst mipLevel greater than the number specified when the dstImage was created."; |
| 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 &>(command_buffer), __LINE__, VALIDATION_ERROR_01223, "IMAGE", "%s. %s", |
| 1398 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01223]); |
| 1399 | } |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1400 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1401 | // (baseArrayLayer + layerCount) must be less than or equal to the arrayLayers specified in VkImageCreateInfo when the |
| 1402 | // image was created |
| 1403 | if ((regions[i].srcSubresource.baseArrayLayer + regions[i].srcSubresource.layerCount) > |
| 1404 | src_image_state->createInfo.arrayLayers) { |
| 1405 | std::stringstream ss; |
| 1406 | ss << "vkCmdCopyImage: srcImage arrayLayers was " << src_image_state->createInfo.arrayLayers << " but subRegion[" << i |
| 1407 | << "] baseArrayLayer + layerCount is " |
| 1408 | << (regions[i].srcSubresource.baseArrayLayer + regions[i].srcSubresource.layerCount); |
| 1409 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1410 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01224, "IMAGE", "%s. %s", |
| 1411 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01224]); |
| 1412 | } |
| 1413 | if ((regions[i].dstSubresource.baseArrayLayer + regions[i].dstSubresource.layerCount) > |
| 1414 | dst_image_state->createInfo.arrayLayers) { |
| 1415 | std::stringstream ss; |
| 1416 | ss << "vkCmdCopyImage: dstImage arrayLayers was " << dst_image_state->createInfo.arrayLayers << " but subRegion[" << i |
| 1417 | << "] baseArrayLayer + layerCount is " |
| 1418 | << (regions[i].dstSubresource.baseArrayLayer + regions[i].dstSubresource.layerCount); |
| 1419 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1420 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01224, "IMAGE", "%s. %s", |
| 1421 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01224]); |
| 1422 | } |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1423 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1424 | // The source region specified by a given element of regions must be a region that is contained within srcImage |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 1425 | if (ExceedsBounds(®ions[i].srcOffset, ®ions[i].extent, &(src_image_state->createInfo.extent))) { |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1426 | std::stringstream ss; |
| 1427 | ss << "vkCmdCopyImage: srcSubResource in pRegions[" << i << "] exceeds extents srcImage was created with"; |
| 1428 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1429 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01175, "IMAGE", "%s. %s", |
| 1430 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01175]); |
| 1431 | } |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1432 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1433 | // The destination region specified by a given element of regions must be a region that is contained within dst_image |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 1434 | if (ExceedsBounds(®ions[i].dstOffset, ®ions[i].extent, &(dst_image_state->createInfo.extent))) { |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1435 | std::stringstream ss; |
| 1436 | ss << "vkCmdCopyImage: dstSubResource in pRegions[" << i << "] exceeds extents dstImage was created with"; |
| 1437 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1438 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01176, "IMAGE", "%s. %s", |
| 1439 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01176]); |
| 1440 | } |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1441 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1442 | // The union of all source regions, and the union of all destination regions, specified by the elements of regions, |
| 1443 | // must not overlap in memory |
| 1444 | if (src_image_state->image == dst_image_state->image) { |
| 1445 | for (uint32_t j = 0; j < region_count; j++) { |
| 1446 | if (RegionIntersects(®ions[i], ®ions[j], src_image_state->createInfo.imageType)) { |
| 1447 | std::stringstream ss; |
| 1448 | ss << "vkCmdCopyImage: pRegions[" << i << "] src overlaps with pRegions[" << j << "]."; |
| 1449 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1450 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01177, "IMAGE", |
| 1451 | "%s. %s", ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01177]); |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1452 | } |
| 1453 | } |
| 1454 | } |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1455 | } |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1456 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1457 | // The formats of src_image and dst_image must be compatible. Formats are considered compatible if their texel size in bytes |
| 1458 | // is the same between both formats. For example, VK_FORMAT_R8G8B8A8_UNORM is compatible with VK_FORMAT_R32_UINT because |
| 1459 | // because both texels are 4 bytes in size. Depth/stencil formats must match exactly. |
| 1460 | if (vk_format_is_depth_or_stencil(src_image_state->createInfo.format) || |
| 1461 | vk_format_is_depth_or_stencil(dst_image_state->createInfo.format)) { |
| 1462 | if (src_image_state->createInfo.format != dst_image_state->createInfo.format) { |
| 1463 | char const str[] = "vkCmdCopyImage called with unmatched source and dest image depth/stencil formats."; |
| 1464 | skip |= |
| 1465 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1466 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_FORMAT, "IMAGE", str); |
| 1467 | } |
| 1468 | } else { |
| 1469 | size_t srcSize = vk_format_get_size(src_image_state->createInfo.format); |
| 1470 | size_t destSize = vk_format_get_size(dst_image_state->createInfo.format); |
| 1471 | if (srcSize != destSize) { |
| 1472 | char const str[] = "vkCmdCopyImage called with unmatched source and dest image format sizes."; |
| 1473 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1474 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01184, "IMAGE", "%s. %s", str, |
| 1475 | validation_error_map[VALIDATION_ERROR_01184]); |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1476 | } |
| 1477 | } |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1478 | |
Dave Houlton | 33c22b7 | 2017-02-28 13:16:02 -0700 | [diff] [blame] | 1479 | // Source and dest image sample counts must match |
| 1480 | if (src_image_state->createInfo.samples != dst_image_state->createInfo.samples) { |
| 1481 | char const str[] = "vkCmdCopyImage() called on image pair with non-identical sample counts."; |
| 1482 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Dave Houlton | 4eaaf3a | 2017-03-14 11:31:20 -0600 | [diff] [blame] | 1483 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01185, "IMAGE", "%s %s", str, |
| 1484 | validation_error_map[VALIDATION_ERROR_01185]); |
Dave Houlton | 33c22b7 | 2017-02-28 13:16:02 -0700 | [diff] [blame] | 1485 | } |
| 1486 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1487 | skip |= ValidateMemoryIsBoundToImage(device_data, src_image_state, "vkCmdCopyImage()", VALIDATION_ERROR_02533); |
| 1488 | skip |= ValidateMemoryIsBoundToImage(device_data, dst_image_state, "vkCmdCopyImage()", VALIDATION_ERROR_02534); |
| 1489 | // Validate that SRC & DST images have correct usage flags set |
| 1490 | skip |= ValidateImageUsageFlags(device_data, src_image_state, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, true, VALIDATION_ERROR_01178, |
| 1491 | "vkCmdCopyImage()", "VK_IMAGE_USAGE_TRANSFER_SRC_BIT"); |
| 1492 | skip |= ValidateImageUsageFlags(device_data, dst_image_state, VK_IMAGE_USAGE_TRANSFER_DST_BIT, true, VALIDATION_ERROR_01181, |
| 1493 | "vkCmdCopyImage()", "VK_IMAGE_USAGE_TRANSFER_DST_BIT"); |
| 1494 | skip |= ValidateCmd(device_data, cb_node, CMD_COPYIMAGE, "vkCmdCopyImage()"); |
| 1495 | skip |= insideRenderPass(device_data, cb_node, "vkCmdCopyImage()", VALIDATION_ERROR_01194); |
| 1496 | for (uint32_t i = 0; i < region_count; ++i) { |
| 1497 | skip |= VerifySourceImageLayout(device_data, cb_node, src_image_state->image, regions[i].srcSubresource, src_image_layout, |
| 1498 | VALIDATION_ERROR_01180); |
| 1499 | skip |= VerifyDestImageLayout(device_data, cb_node, dst_image_state->image, regions[i].dstSubresource, dst_image_layout, |
| 1500 | VALIDATION_ERROR_01183); |
| 1501 | skip |= ValidateCopyImageTransferGranularityRequirements(device_data, cb_node, dst_image_state, ®ions[i], i, |
| 1502 | "vkCmdCopyImage()"); |
| 1503 | } |
| 1504 | |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1505 | return skip; |
| 1506 | } |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1507 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1508 | void PreCallRecordCmdCopyImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state, |
| 1509 | IMAGE_STATE *dst_image_state) { |
| 1510 | // Update bindings between images and cmd buffer |
| 1511 | AddCommandBufferBindingImage(device_data, cb_node, src_image_state); |
| 1512 | AddCommandBufferBindingImage(device_data, cb_node, dst_image_state); |
Dave Houlton | eba86e2 | 2017-03-02 14:56:23 -0700 | [diff] [blame] | 1513 | std::function<bool()> function = [=]() { return ValidateImageMemoryIsValid(device_data, src_image_state, "vkCmdCopyImage()"); }; |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1514 | cb_node->validate_functions.push_back(function); |
| 1515 | function = [=]() { |
| 1516 | SetImageMemoryValid(device_data, dst_image_state, true); |
| 1517 | return false; |
| 1518 | }; |
| 1519 | cb_node->validate_functions.push_back(function); |
| 1520 | core_validation::UpdateCmdBufferLastCmd(cb_node, CMD_COPYIMAGE); |
| 1521 | } |
| 1522 | |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1523 | // TODO : Should be tracking lastBound per commandBuffer and when draws occur, report based on that cmd buffer lastBound |
| 1524 | // Then need to synchronize the accesses based on cmd buffer so that if I'm reading state on one cmd buffer, updates |
| 1525 | // to that same cmd buffer by separate thread are not changing state from underneath us |
| 1526 | // Track the last cmd buffer touched by this thread |
| 1527 | static bool hasDrawCmd(GLOBAL_CB_NODE *pCB) { |
| 1528 | for (uint32_t i = 0; i < NUM_DRAW_TYPES; i++) { |
| 1529 | if (pCB->drawCount[i]) return true; |
| 1530 | } |
| 1531 | return false; |
| 1532 | } |
| 1533 | |
| 1534 | // Returns true if sub_rect is entirely contained within rect |
| 1535 | static inline bool ContainsRect(VkRect2D rect, VkRect2D sub_rect) { |
| 1536 | if ((sub_rect.offset.x < rect.offset.x) || (sub_rect.offset.x + sub_rect.extent.width > rect.offset.x + rect.extent.width) || |
| 1537 | (sub_rect.offset.y < rect.offset.y) || (sub_rect.offset.y + sub_rect.extent.height > rect.offset.y + rect.extent.height)) |
| 1538 | return false; |
| 1539 | return true; |
| 1540 | } |
| 1541 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 1542 | bool PreCallValidateCmdClearAttachments(layer_data *device_data, VkCommandBuffer commandBuffer, uint32_t attachmentCount, |
| 1543 | const VkClearAttachment *pAttachments, uint32_t rectCount, const VkClearRect *pRects) { |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 1544 | GLOBAL_CB_NODE *cb_node = GetCBNode(device_data, commandBuffer); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1545 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 1546 | |
| 1547 | bool skip = false; |
| 1548 | if (cb_node) { |
| 1549 | skip |= ValidateCmd(device_data, cb_node, CMD_CLEARATTACHMENTS, "vkCmdClearAttachments()"); |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 1550 | core_validation::UpdateCmdBufferLastCmd(cb_node, CMD_CLEARATTACHMENTS); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1551 | // Warn if this is issued prior to Draw Cmd and clearing the entire attachment |
| 1552 | if (!hasDrawCmd(cb_node) && (cb_node->activeRenderPassBeginInfo.renderArea.extent.width == pRects[0].rect.extent.width) && |
| 1553 | (cb_node->activeRenderPassBeginInfo.renderArea.extent.height == pRects[0].rect.extent.height)) { |
| 1554 | // There are times where app needs to use ClearAttachments (generally when reusing a buffer inside of a render pass) |
Mark Lobodzinski | d833bb7 | 2017-02-22 10:55:30 -0700 | [diff] [blame] | 1555 | // This warning should be made more specific. It'd be best to avoid triggering this test if it's a use that must call |
| 1556 | // CmdClearAttachments. |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 1557 | skip |= |
| 1558 | log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1559 | reinterpret_cast<uint64_t &>(commandBuffer), 0, DRAWSTATE_CLEAR_CMD_BEFORE_DRAW, "DS", |
| 1560 | "vkCmdClearAttachments() issued on command buffer object 0x%p prior to any Draw Cmds." |
| 1561 | " It is recommended you use RenderPass LOAD_OP_CLEAR on Attachments prior to any Draw.", |
| 1562 | commandBuffer); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1563 | } |
| 1564 | skip |= outsideRenderPass(device_data, cb_node, "vkCmdClearAttachments()", VALIDATION_ERROR_01122); |
| 1565 | } |
| 1566 | |
| 1567 | // Validate that attachment is in reference list of active subpass |
| 1568 | if (cb_node->activeRenderPass) { |
| 1569 | const VkRenderPassCreateInfo *renderpass_create_info = cb_node->activeRenderPass->createInfo.ptr(); |
| 1570 | const VkSubpassDescription *subpass_desc = &renderpass_create_info->pSubpasses[cb_node->activeSubpass]; |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 1571 | auto framebuffer = GetFramebufferState(device_data, cb_node->activeFramebuffer); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1572 | |
| 1573 | for (uint32_t i = 0; i < attachmentCount; i++) { |
| 1574 | auto clear_desc = &pAttachments[i]; |
| 1575 | VkImageView image_view = VK_NULL_HANDLE; |
| 1576 | |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 1577 | if (0 == clear_desc->aspectMask) { |
| 1578 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1579 | (uint64_t)commandBuffer, __LINE__, VALIDATION_ERROR_01128, "IMAGE", "%s", |
| 1580 | validation_error_map[VALIDATION_ERROR_01128]); |
| 1581 | } else if (clear_desc->aspectMask & VK_IMAGE_ASPECT_METADATA_BIT) { |
| 1582 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1583 | (uint64_t)commandBuffer, __LINE__, VALIDATION_ERROR_01126, "IMAGE", "%s", |
| 1584 | validation_error_map[VALIDATION_ERROR_01126]); |
| 1585 | } else if (clear_desc->aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) { |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1586 | if (clear_desc->colorAttachment >= subpass_desc->colorAttachmentCount) { |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 1587 | skip |= |
| 1588 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1589 | (uint64_t)commandBuffer, __LINE__, VALIDATION_ERROR_01114, "DS", |
| 1590 | "vkCmdClearAttachments() color attachment index %d out of range for active subpass %d. %s", |
| 1591 | clear_desc->colorAttachment, cb_node->activeSubpass, validation_error_map[VALIDATION_ERROR_01114]); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1592 | } else if (subpass_desc->pColorAttachments[clear_desc->colorAttachment].attachment == VK_ATTACHMENT_UNUSED) { |
| 1593 | skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 1594 | VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer, __LINE__, |
| 1595 | DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS", |
| 1596 | "vkCmdClearAttachments() color attachment index %d is VK_ATTACHMENT_UNUSED; ignored.", |
| 1597 | clear_desc->colorAttachment); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1598 | } else { |
| 1599 | image_view = framebuffer->createInfo |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 1600 | .pAttachments[subpass_desc->pColorAttachments[clear_desc->colorAttachment].attachment]; |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1601 | } |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 1602 | if ((clear_desc->aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) || |
| 1603 | (clear_desc->aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT)) { |
| 1604 | char const str[] = |
| 1605 | "vkCmdClearAttachments aspectMask [%d] must set only VK_IMAGE_ASPECT_COLOR_BIT of a color attachment. %s"; |
| 1606 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1607 | (uint64_t)commandBuffer, __LINE__, VALIDATION_ERROR_01125, "IMAGE", str, i, |
| 1608 | validation_error_map[VALIDATION_ERROR_01125]); |
| 1609 | } |
| 1610 | } else { // Must be depth and/or stencil |
| 1611 | if (((clear_desc->aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) != VK_IMAGE_ASPECT_DEPTH_BIT) && |
| 1612 | ((clear_desc->aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) != VK_IMAGE_ASPECT_STENCIL_BIT)) { |
| 1613 | char const str[] = "vkCmdClearAttachments aspectMask [%d] is not a valid combination of bits. %s"; |
| 1614 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1615 | (uint64_t)commandBuffer, __LINE__, VALIDATION_ERROR_01127, "IMAGE", str, i, |
| 1616 | validation_error_map[VALIDATION_ERROR_01127]); |
| 1617 | } |
| 1618 | if (!subpass_desc->pDepthStencilAttachment || |
| 1619 | (subpass_desc->pDepthStencilAttachment->attachment == VK_ATTACHMENT_UNUSED)) { |
| 1620 | skip |= log_msg( |
| 1621 | report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1622 | (uint64_t)commandBuffer, __LINE__, DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS", |
| 1623 | "vkCmdClearAttachments() depth/stencil clear with no depth/stencil attachment in subpass; ignored"); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1624 | } else { |
| 1625 | image_view = framebuffer->createInfo.pAttachments[subpass_desc->pDepthStencilAttachment->attachment]; |
| 1626 | } |
| 1627 | } |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1628 | if (image_view) { |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 1629 | auto image_view_state = GetImageViewState(device_data, image_view); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1630 | for (uint32_t j = 0; j < rectCount; j++) { |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 1631 | // The rectangular region specified by a given element of pRects must be contained within the render area of |
| 1632 | // the current render pass instance |
Mark Lobodzinski | d833bb7 | 2017-02-22 10:55:30 -0700 | [diff] [blame] | 1633 | // TODO: This check should be moved to CmdExecuteCommands or QueueSubmit to cover secondary CB cases |
| 1634 | if ((cb_node->createInfo.level == VK_COMMAND_BUFFER_LEVEL_PRIMARY) && |
| 1635 | (false == ContainsRect(cb_node->activeRenderPassBeginInfo.renderArea, pRects[j].rect))) { |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 1636 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 1637 | __LINE__, VALIDATION_ERROR_01115, "DS", |
| 1638 | "vkCmdClearAttachments(): The area defined by pRects[%d] is not contained in the area of " |
| 1639 | "the current render pass instance. %s", |
| 1640 | j, validation_error_map[VALIDATION_ERROR_01115]); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1641 | } |
| 1642 | // The layers specified by a given element of pRects must be contained within every attachment that |
| 1643 | // pAttachments refers to |
| 1644 | auto attachment_base_array_layer = image_view_state->create_info.subresourceRange.baseArrayLayer; |
| 1645 | auto attachment_layer_count = image_view_state->create_info.subresourceRange.layerCount; |
| 1646 | if ((pRects[j].baseArrayLayer < attachment_base_array_layer) || pRects[j].layerCount > attachment_layer_count) { |
| 1647 | skip |= |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 1648 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 1649 | __LINE__, VALIDATION_ERROR_01116, "DS", |
| 1650 | "vkCmdClearAttachments(): The layers defined in pRects[%d] are not contained in the layers of " |
| 1651 | "pAttachment[%d]. %s", |
| 1652 | j, i, validation_error_map[VALIDATION_ERROR_01116]); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1653 | } |
| 1654 | } |
| 1655 | } |
| 1656 | } |
| 1657 | } |
| 1658 | return skip; |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 1659 | } |
| 1660 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 1661 | 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] | 1662 | IMAGE_STATE *dst_image_state, uint32_t regionCount, const VkImageResolve *pRegions) { |
Mark Lobodzinski | 2a3368e | 2017-02-06 15:29:37 -0700 | [diff] [blame] | 1663 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 1664 | bool skip = false; |
| 1665 | if (cb_node && src_image_state && dst_image_state) { |
| 1666 | skip |= ValidateMemoryIsBoundToImage(device_data, src_image_state, "vkCmdResolveImage()", VALIDATION_ERROR_02541); |
| 1667 | skip |= ValidateMemoryIsBoundToImage(device_data, dst_image_state, "vkCmdResolveImage()", VALIDATION_ERROR_02542); |
| 1668 | skip |= ValidateCmd(device_data, cb_node, CMD_RESOLVEIMAGE, "vkCmdResolveImage()"); |
| 1669 | skip |= insideRenderPass(device_data, cb_node, "vkCmdResolveImage()", VALIDATION_ERROR_01335); |
Mark Lobodzinski | 2a3368e | 2017-02-06 15:29:37 -0700 | [diff] [blame] | 1670 | |
| 1671 | // For each region, the number of layers in the image subresource should not be zero |
| 1672 | // For each region, src and dest image aspect must be color only |
| 1673 | for (uint32_t i = 0; i < regionCount; i++) { |
| 1674 | if (pRegions[i].srcSubresource.layerCount == 0) { |
| 1675 | char const str[] = "vkCmdResolveImage: number of layers in source subresource is zero"; |
Mark Lobodzinski | 50fbef1 | 2017-02-06 15:31:33 -0700 | [diff] [blame] | 1676 | 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] | 1677 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_ASPECT, |
| 1678 | "IMAGE", str); |
| 1679 | } |
Mark Lobodzinski | 2a3368e | 2017-02-06 15:29:37 -0700 | [diff] [blame] | 1680 | if (pRegions[i].dstSubresource.layerCount == 0) { |
| 1681 | char const str[] = "vkCmdResolveImage: number of layers in destination subresource is zero"; |
Mark Lobodzinski | 50fbef1 | 2017-02-06 15:31:33 -0700 | [diff] [blame] | 1682 | 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] | 1683 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_ASPECT, |
| 1684 | "IMAGE", str); |
| 1685 | } |
Mark Lobodzinski | 50fbef1 | 2017-02-06 15:31:33 -0700 | [diff] [blame] | 1686 | if (pRegions[i].srcSubresource.layerCount != pRegions[i].dstSubresource.layerCount) { |
| 1687 | skip |= log_msg( |
| 1688 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1689 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_01339, "IMAGE", |
| 1690 | "vkCmdResolveImage: layerCount in source and destination subresource of pRegions[%d] does not match. %s", i, |
| 1691 | validation_error_map[VALIDATION_ERROR_01339]); |
| 1692 | } |
Mark Lobodzinski | 2a3368e | 2017-02-06 15:29:37 -0700 | [diff] [blame] | 1693 | if ((pRegions[i].srcSubresource.aspectMask != VK_IMAGE_ASPECT_COLOR_BIT) || |
| 1694 | (pRegions[i].dstSubresource.aspectMask != VK_IMAGE_ASPECT_COLOR_BIT)) { |
| 1695 | char const str[] = |
| 1696 | "vkCmdResolveImage: src and dest aspectMasks for each region must specify only VK_IMAGE_ASPECT_COLOR_BIT"; |
| 1697 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1698 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_01338, "IMAGE", |
| 1699 | "%s. %s", str, validation_error_map[VALIDATION_ERROR_01338]); |
| 1700 | } |
| 1701 | } |
| 1702 | |
| 1703 | if (src_image_state->createInfo.format != dst_image_state->createInfo.format) { |
| 1704 | char const str[] = "vkCmdResolveImage called with unmatched source and dest formats."; |
Mark Lobodzinski | 50fbef1 | 2017-02-06 15:31:33 -0700 | [diff] [blame] | 1705 | 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] | 1706 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_FORMAT, |
| 1707 | "IMAGE", str); |
| 1708 | } |
| 1709 | if (src_image_state->createInfo.imageType != dst_image_state->createInfo.imageType) { |
| 1710 | char const str[] = "vkCmdResolveImage called with unmatched source and dest image types."; |
Mark Lobodzinski | 50fbef1 | 2017-02-06 15:31:33 -0700 | [diff] [blame] | 1711 | 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] | 1712 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_TYPE, "IMAGE", |
| 1713 | str); |
| 1714 | } |
| 1715 | if (src_image_state->createInfo.samples == VK_SAMPLE_COUNT_1_BIT) { |
| 1716 | char const str[] = "vkCmdResolveImage called with source sample count less than 2."; |
| 1717 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1718 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_01320, "IMAGE", "%s. %s", |
| 1719 | str, validation_error_map[VALIDATION_ERROR_01320]); |
| 1720 | } |
| 1721 | if (dst_image_state->createInfo.samples != VK_SAMPLE_COUNT_1_BIT) { |
| 1722 | char const str[] = "vkCmdResolveImage called with dest sample count greater than 1."; |
| 1723 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1724 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_01321, "IMAGE", "%s. %s", |
| 1725 | str, validation_error_map[VALIDATION_ERROR_01321]); |
| 1726 | } |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 1727 | } else { |
| 1728 | assert(0); |
| 1729 | } |
| 1730 | return skip; |
| 1731 | } |
| 1732 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 1733 | void PreCallRecordCmdResolveImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state, |
| 1734 | IMAGE_STATE *dst_image_state) { |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 1735 | // Update bindings between images and cmd buffer |
| 1736 | AddCommandBufferBindingImage(device_data, cb_node, src_image_state); |
| 1737 | AddCommandBufferBindingImage(device_data, cb_node, dst_image_state); |
| 1738 | |
| 1739 | std::function<bool()> function = [=]() { |
| 1740 | return ValidateImageMemoryIsValid(device_data, src_image_state, "vkCmdResolveImage()"); |
| 1741 | }; |
| 1742 | cb_node->validate_functions.push_back(function); |
| 1743 | function = [=]() { |
| 1744 | SetImageMemoryValid(device_data, dst_image_state, true); |
| 1745 | return false; |
| 1746 | }; |
| 1747 | cb_node->validate_functions.push_back(function); |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 1748 | core_validation::UpdateCmdBufferLastCmd(cb_node, CMD_RESOLVEIMAGE); |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 1749 | } |
| 1750 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 1751 | 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] | 1752 | IMAGE_STATE *dst_image_state, uint32_t regionCount, const VkImageBlit *pRegions, VkFilter filter) { |
| 1753 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 1754 | |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 1755 | bool skip = false; |
| 1756 | if (cb_node && src_image_state && dst_image_state) { |
| 1757 | 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] | 1758 | VALIDATION_ERROR_02194); |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 1759 | 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] | 1760 | VALIDATION_ERROR_02195); |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 1761 | skip |= ValidateMemoryIsBoundToImage(device_data, src_image_state, "vkCmdBlitImage()", VALIDATION_ERROR_02539); |
| 1762 | skip |= ValidateMemoryIsBoundToImage(device_data, dst_image_state, "vkCmdBlitImage()", VALIDATION_ERROR_02540); |
| 1763 | 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] | 1764 | "vkCmdBlitImage()", "VK_IMAGE_USAGE_TRANSFER_SRC_BIT"); |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 1765 | 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] | 1766 | "vkCmdBlitImage()", "VK_IMAGE_USAGE_TRANSFER_DST_BIT"); |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 1767 | skip |= ValidateCmd(device_data, cb_node, CMD_BLITIMAGE, "vkCmdBlitImage()"); |
| 1768 | skip |= insideRenderPass(device_data, cb_node, "vkCmdBlitImage()", VALIDATION_ERROR_01300); |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 1769 | |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 1770 | for (uint32_t i = 0; i < regionCount; i++) { |
Mark Lobodzinski | 23c8114 | 2017-02-06 15:04:23 -0700 | [diff] [blame] | 1771 | // Warn for zero-sized regions |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 1772 | if ((pRegions[i].srcOffsets[0].x == pRegions[i].srcOffsets[1].x) || |
| 1773 | (pRegions[i].srcOffsets[0].y == pRegions[i].srcOffsets[1].y) || |
| 1774 | (pRegions[i].srcOffsets[0].z == pRegions[i].srcOffsets[1].z)) { |
| 1775 | std::stringstream ss; |
| 1776 | ss << "vkCmdBlitImage: pRegions[" << i << "].srcOffsets specify a zero-volume area."; |
| 1777 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1778 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_INVALID_EXTENTS, "IMAGE", |
| 1779 | "%s", ss.str().c_str()); |
| 1780 | } |
| 1781 | if ((pRegions[i].dstOffsets[0].x == pRegions[i].dstOffsets[1].x) || |
| 1782 | (pRegions[i].dstOffsets[0].y == pRegions[i].dstOffsets[1].y) || |
| 1783 | (pRegions[i].dstOffsets[0].z == pRegions[i].dstOffsets[1].z)) { |
| 1784 | std::stringstream ss; |
| 1785 | ss << "vkCmdBlitImage: pRegions[" << i << "].dstOffsets specify a zero-volume area."; |
| 1786 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1787 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_INVALID_EXTENTS, "IMAGE", |
| 1788 | "%s", ss.str().c_str()); |
| 1789 | } |
Mark Lobodzinski | 23c8114 | 2017-02-06 15:04:23 -0700 | [diff] [blame] | 1790 | if (pRegions[i].srcSubresource.layerCount == 0) { |
| 1791 | char const str[] = "vkCmdBlitImage: number of layers in source subresource is zero"; |
| 1792 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Dave Houlton | eba86e2 | 2017-03-02 14:56:23 -0700 | [diff] [blame] | 1793 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_ASPECT, |
| 1794 | "IMAGE", str); |
Mark Lobodzinski | 23c8114 | 2017-02-06 15:04:23 -0700 | [diff] [blame] | 1795 | } |
| 1796 | if (pRegions[i].dstSubresource.layerCount == 0) { |
| 1797 | char const str[] = "vkCmdBlitImage: number of layers in destination subresource is zero"; |
| 1798 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Dave Houlton | eba86e2 | 2017-03-02 14:56:23 -0700 | [diff] [blame] | 1799 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_ASPECT, |
| 1800 | "IMAGE", str); |
Mark Lobodzinski | 23c8114 | 2017-02-06 15:04:23 -0700 | [diff] [blame] | 1801 | } |
| 1802 | |
| 1803 | // Check that src/dst layercounts match |
| 1804 | if (pRegions[i].srcSubresource.layerCount != pRegions[i].dstSubresource.layerCount) { |
| 1805 | skip |= |
| 1806 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1807 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_01304, "IMAGE", |
| 1808 | "vkCmdBlitImage: layerCount in source and destination subresource of pRegions[%d] does not match. %s", |
| 1809 | i, validation_error_map[VALIDATION_ERROR_01304]); |
| 1810 | } |
Mark Lobodzinski | e7e85fd | 2017-02-07 13:44:57 -0700 | [diff] [blame] | 1811 | |
| 1812 | if (pRegions[i].srcSubresource.aspectMask != pRegions[i].dstSubresource.aspectMask) { |
| 1813 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1814 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_01303, "IMAGE", |
| 1815 | "vkCmdBlitImage: aspectMask members for pRegion[%d] do not match. %s", i, |
| 1816 | validation_error_map[VALIDATION_ERROR_01303]); |
| 1817 | } |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 1818 | } |
| 1819 | |
| 1820 | VkFormat src_format = src_image_state->createInfo.format; |
| 1821 | VkFormat dst_format = dst_image_state->createInfo.format; |
| 1822 | |
| 1823 | // Validate consistency for unsigned formats |
| 1824 | if (vk_format_is_uint(src_format) != vk_format_is_uint(dst_format)) { |
| 1825 | std::stringstream ss; |
| 1826 | ss << "vkCmdBlitImage: If one of srcImage and dstImage images has unsigned integer format, " |
| 1827 | << "the other one must also have unsigned integer format. " |
| 1828 | << "Source format is " << string_VkFormat(src_format) << " Destination format is " << string_VkFormat(dst_format); |
| 1829 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1830 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_02191, "IMAGE", "%s. %s", |
| 1831 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_02191]); |
| 1832 | } |
| 1833 | |
| 1834 | // Validate consistency for signed formats |
| 1835 | if (vk_format_is_sint(src_format) != vk_format_is_sint(dst_format)) { |
| 1836 | std::stringstream ss; |
| 1837 | ss << "vkCmdBlitImage: If one of srcImage and dstImage images has signed integer format, " |
| 1838 | << "the other one must also have signed integer format. " |
| 1839 | << "Source format is " << string_VkFormat(src_format) << " Destination format is " << string_VkFormat(dst_format); |
| 1840 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1841 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_02190, "IMAGE", "%s. %s", |
| 1842 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_02190]); |
| 1843 | } |
| 1844 | |
| 1845 | // Validate aspect bits and formats for depth/stencil images |
| 1846 | if (vk_format_is_depth_or_stencil(src_format) || vk_format_is_depth_or_stencil(dst_format)) { |
| 1847 | if (src_format != dst_format) { |
| 1848 | std::stringstream ss; |
| 1849 | ss << "vkCmdBlitImage: If one of srcImage and dstImage images has a format of depth, stencil or depth " |
| 1850 | << "stencil, the other one must have exactly the same format. " |
| 1851 | << "Source format is " << string_VkFormat(src_format) << " Destination format is " |
| 1852 | << string_VkFormat(dst_format); |
| 1853 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1854 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_02192, "IMAGE", |
| 1855 | "%s. %s", ss.str().c_str(), validation_error_map[VALIDATION_ERROR_02192]); |
| 1856 | } |
| 1857 | |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 1858 | for (uint32_t i = 0; i < regionCount; i++) { |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 1859 | VkImageAspectFlags srcAspect = pRegions[i].srcSubresource.aspectMask; |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 1860 | |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 1861 | if (vk_format_is_depth_and_stencil(src_format)) { |
| 1862 | if ((srcAspect != VK_IMAGE_ASPECT_DEPTH_BIT) && (srcAspect != VK_IMAGE_ASPECT_STENCIL_BIT)) { |
| 1863 | std::stringstream ss; |
| 1864 | ss << "vkCmdBlitImage: Combination depth/stencil image formats must have only one of " |
| 1865 | "VK_IMAGE_ASPECT_DEPTH_BIT " |
| 1866 | << "and VK_IMAGE_ASPECT_STENCIL_BIT set in srcImage and dstImage"; |
| 1867 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1868 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, |
| 1869 | DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", "%s", ss.str().c_str()); |
| 1870 | } |
| 1871 | } else if (vk_format_is_stencil_only(src_format)) { |
| 1872 | if (srcAspect != VK_IMAGE_ASPECT_STENCIL_BIT) { |
| 1873 | std::stringstream ss; |
| 1874 | ss << "vkCmdBlitImage: Stencil-only image formats must have only the VK_IMAGE_ASPECT_STENCIL_BIT " |
| 1875 | << "set in both the srcImage and dstImage"; |
| 1876 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1877 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, |
| 1878 | DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", "%s", ss.str().c_str()); |
| 1879 | } |
| 1880 | } else if (vk_format_is_depth_only(src_format)) { |
| 1881 | if (srcAspect != VK_IMAGE_ASPECT_DEPTH_BIT) { |
| 1882 | std::stringstream ss; |
| 1883 | ss << "vkCmdBlitImage: Depth-only image formats must have only the VK_IMAGE_ASPECT_DEPTH " |
| 1884 | << "set in both the srcImage and dstImage"; |
| 1885 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1886 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, |
| 1887 | DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", "%s", ss.str().c_str()); |
| 1888 | } |
| 1889 | } |
| 1890 | } |
| 1891 | } |
| 1892 | |
| 1893 | // Validate filter |
| 1894 | if (vk_format_is_depth_or_stencil(src_format) && (filter != VK_FILTER_NEAREST)) { |
| 1895 | std::stringstream ss; |
| 1896 | ss << "vkCmdBlitImage: If the format of srcImage is a depth, stencil, or depth stencil " |
| 1897 | << "then filter must be VK_FILTER_NEAREST."; |
| 1898 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1899 | reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_02193, "IMAGE", "%s. %s", |
| 1900 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_02193]); |
| 1901 | } |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 1902 | } else { |
| 1903 | assert(0); |
| 1904 | } |
| 1905 | return skip; |
| 1906 | } |
| 1907 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 1908 | void PreCallRecordCmdBlitImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state, |
| 1909 | IMAGE_STATE *dst_image_state) { |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 1910 | // Update bindings between images and cmd buffer |
| 1911 | AddCommandBufferBindingImage(device_data, cb_node, src_image_state); |
| 1912 | AddCommandBufferBindingImage(device_data, cb_node, dst_image_state); |
| 1913 | |
| 1914 | std::function<bool()> function = [=]() { return ValidateImageMemoryIsValid(device_data, src_image_state, "vkCmdBlitImage()"); }; |
| 1915 | cb_node->validate_functions.push_back(function); |
| 1916 | function = [=]() { |
| 1917 | SetImageMemoryValid(device_data, dst_image_state, true); |
| 1918 | return false; |
| 1919 | }; |
| 1920 | cb_node->validate_functions.push_back(function); |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 1921 | core_validation::UpdateCmdBufferLastCmd(cb_node, CMD_BLITIMAGE); |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 1922 | } |
| 1923 | |
Tony Barbour | df013b9 | 2017-01-25 12:53:48 -0700 | [diff] [blame] | 1924 | // This validates that the initial layout specified in the command buffer for |
| 1925 | // the IMAGE is the same |
| 1926 | // as the global IMAGE layout |
Tony Barbour | e0c5cc9 | 2017-02-08 13:53:39 -0700 | [diff] [blame] | 1927 | bool ValidateCmdBufImageLayouts(layer_data *device_data, GLOBAL_CB_NODE *pCB, |
| 1928 | std::unordered_map<ImageSubresourcePair, IMAGE_LAYOUT_NODE> &imageLayoutMap) { |
Mark Lobodzinski | b0dd947 | 2017-02-07 16:38:17 -0700 | [diff] [blame] | 1929 | bool skip = false; |
Tony Barbour | df013b9 | 2017-01-25 12:53:48 -0700 | [diff] [blame] | 1930 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
Mark Lobodzinski | 4a3065e | 2017-02-07 16:36:03 -0700 | [diff] [blame] | 1931 | for (auto cb_image_data : pCB->imageLayoutMap) { |
| 1932 | VkImageLayout imageLayout; |
Tony Barbour | df013b9 | 2017-01-25 12:53:48 -0700 | [diff] [blame] | 1933 | |
Jeremy Hayes | 55b6c29 | 2017-02-28 09:44:45 -0700 | [diff] [blame] | 1934 | if (FindLayout(imageLayoutMap, cb_image_data.first, imageLayout)) { |
Mark Lobodzinski | 4a3065e | 2017-02-07 16:36:03 -0700 | [diff] [blame] | 1935 | if (cb_image_data.second.initialLayout == VK_IMAGE_LAYOUT_UNDEFINED) { |
| 1936 | // TODO: Set memory invalid which is in mem_tracker currently |
| 1937 | } else if (imageLayout != cb_image_data.second.initialLayout) { |
| 1938 | if (cb_image_data.first.hasSubresource) { |
Dave Houlton | eba86e2 | 2017-03-02 14:56:23 -0700 | [diff] [blame] | 1939 | skip |= log_msg( |
| 1940 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1941 | reinterpret_cast<uint64_t &>(pCB->commandBuffer), __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", |
| 1942 | "Cannot submit cmd buffer using image (0x%" PRIx64 |
| 1943 | ") [sub-resource: aspectMask 0x%X array layer %u, mip level %u], " |
| 1944 | "with layout %s when first use is %s.", |
| 1945 | reinterpret_cast<const uint64_t &>(cb_image_data.first.image), cb_image_data.first.subresource.aspectMask, |
| 1946 | cb_image_data.first.subresource.arrayLayer, cb_image_data.first.subresource.mipLevel, |
| 1947 | string_VkImageLayout(imageLayout), string_VkImageLayout(cb_image_data.second.initialLayout)); |
Mark Lobodzinski | 4a3065e | 2017-02-07 16:36:03 -0700 | [diff] [blame] | 1948 | } else { |
Dave Houlton | eba86e2 | 2017-03-02 14:56:23 -0700 | [diff] [blame] | 1949 | skip |= |
| 1950 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1951 | reinterpret_cast<uint64_t &>(pCB->commandBuffer), __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", |
| 1952 | "Cannot submit cmd buffer using image (0x%" PRIx64 |
| 1953 | ") with layout %s when " |
| 1954 | "first use is %s.", |
| 1955 | reinterpret_cast<const uint64_t &>(cb_image_data.first.image), string_VkImageLayout(imageLayout), |
| 1956 | string_VkImageLayout(cb_image_data.second.initialLayout)); |
Mark Lobodzinski | 4a3065e | 2017-02-07 16:36:03 -0700 | [diff] [blame] | 1957 | } |
| 1958 | } |
Tony Barbour | df013b9 | 2017-01-25 12:53:48 -0700 | [diff] [blame] | 1959 | SetLayout(imageLayoutMap, cb_image_data.first, cb_image_data.second.layout); |
Mark Lobodzinski | 4a3065e | 2017-02-07 16:36:03 -0700 | [diff] [blame] | 1960 | } |
| 1961 | } |
Mark Lobodzinski | b0dd947 | 2017-02-07 16:38:17 -0700 | [diff] [blame] | 1962 | return skip; |
Mark Lobodzinski | 4a3065e | 2017-02-07 16:36:03 -0700 | [diff] [blame] | 1963 | } |
Mark Lobodzinski | b3829a5 | 2017-02-07 16:55:53 -0700 | [diff] [blame] | 1964 | |
Tony Barbour | df013b9 | 2017-01-25 12:53:48 -0700 | [diff] [blame] | 1965 | void UpdateCmdBufImageLayouts(layer_data *device_data, GLOBAL_CB_NODE *pCB) { |
| 1966 | for (auto cb_image_data : pCB->imageLayoutMap) { |
| 1967 | VkImageLayout imageLayout; |
| 1968 | FindGlobalLayout(device_data, cb_image_data.first, imageLayout); |
| 1969 | SetGlobalLayout(device_data, cb_image_data.first, cb_image_data.second.layout); |
| 1970 | } |
| 1971 | } |
| 1972 | |
Mark Lobodzinski | b3829a5 | 2017-02-07 16:55:53 -0700 | [diff] [blame] | 1973 | // Print readable FlagBits in FlagMask |
| 1974 | static std::string string_VkAccessFlags(VkAccessFlags accessMask) { |
| 1975 | std::string result; |
| 1976 | std::string separator; |
| 1977 | |
| 1978 | if (accessMask == 0) { |
| 1979 | result = "[None]"; |
| 1980 | } else { |
| 1981 | result = "["; |
| 1982 | for (auto i = 0; i < 32; i++) { |
| 1983 | if (accessMask & (1 << i)) { |
| 1984 | result = result + separator + string_VkAccessFlagBits((VkAccessFlagBits)(1 << i)); |
| 1985 | separator = " | "; |
| 1986 | } |
| 1987 | } |
| 1988 | result = result + "]"; |
| 1989 | } |
| 1990 | return result; |
| 1991 | } |
| 1992 | |
Mark Lobodzinski | 9a8d40f | 2017-02-07 17:00:12 -0700 | [diff] [blame] | 1993 | // AccessFlags MUST have 'required_bit' set, and may have one or more of 'optional_bits' set. If required_bit is zero, accessMask |
| 1994 | // must have at least one of 'optional_bits' set |
Mark Lobodzinski | b3829a5 | 2017-02-07 16:55:53 -0700 | [diff] [blame] | 1995 | // 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] | 1996 | static bool ValidateMaskBits(core_validation::layer_data *device_data, VkCommandBuffer cmdBuffer, const VkAccessFlags &accessMask, |
| 1997 | const VkImageLayout &layout, VkAccessFlags required_bit, VkAccessFlags optional_bits, |
| 1998 | const char *type) { |
| 1999 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 2000 | bool skip = false; |
Mark Lobodzinski | b3829a5 | 2017-02-07 16:55:53 -0700 | [diff] [blame] | 2001 | |
| 2002 | if ((accessMask & required_bit) || (!required_bit && (accessMask & optional_bits))) { |
| 2003 | if (accessMask & ~(required_bit | optional_bits)) { |
| 2004 | // TODO: Verify against Valid Use |
Mark Lobodzinski | 9a8d40f | 2017-02-07 17:00:12 -0700 | [diff] [blame] | 2005 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, |
| 2006 | DRAWSTATE_INVALID_BARRIER, "DS", |
| 2007 | "Additional bits in %s accessMask 0x%X %s are specified when layout is %s.", type, accessMask, |
| 2008 | string_VkAccessFlags(accessMask).c_str(), string_VkImageLayout(layout)); |
Mark Lobodzinski | b3829a5 | 2017-02-07 16:55:53 -0700 | [diff] [blame] | 2009 | } |
| 2010 | } else { |
| 2011 | if (!required_bit) { |
Mark Lobodzinski | 9a8d40f | 2017-02-07 17:00:12 -0700 | [diff] [blame] | 2012 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, |
| 2013 | DRAWSTATE_INVALID_BARRIER, "DS", |
| 2014 | "%s AccessMask %d %s must contain at least one of access bits %d " |
| 2015 | "%s when layout is %s, unless the app has previously added a " |
| 2016 | "barrier for this transition.", |
| 2017 | type, accessMask, string_VkAccessFlags(accessMask).c_str(), optional_bits, |
| 2018 | string_VkAccessFlags(optional_bits).c_str(), string_VkImageLayout(layout)); |
Mark Lobodzinski | b3829a5 | 2017-02-07 16:55:53 -0700 | [diff] [blame] | 2019 | } else { |
| 2020 | std::string opt_bits; |
| 2021 | if (optional_bits != 0) { |
| 2022 | std::stringstream ss; |
| 2023 | ss << optional_bits; |
| 2024 | opt_bits = "and may have optional bits " + ss.str() + ' ' + string_VkAccessFlags(optional_bits); |
| 2025 | } |
Mark Lobodzinski | 9a8d40f | 2017-02-07 17:00:12 -0700 | [diff] [blame] | 2026 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, |
| 2027 | DRAWSTATE_INVALID_BARRIER, "DS", |
| 2028 | "%s AccessMask %d %s must have required access bit %d %s %s when " |
| 2029 | "layout is %s, unless the app has previously added a barrier for " |
| 2030 | "this transition.", |
| 2031 | type, accessMask, string_VkAccessFlags(accessMask).c_str(), required_bit, |
| 2032 | 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] | 2033 | } |
| 2034 | } |
Mark Lobodzinski | 9a8d40f | 2017-02-07 17:00:12 -0700 | [diff] [blame] | 2035 | return skip; |
Mark Lobodzinski | b3829a5 | 2017-02-07 16:55:53 -0700 | [diff] [blame] | 2036 | } |
| 2037 | |
Mark Lobodzinski | 9a8d40f | 2017-02-07 17:00:12 -0700 | [diff] [blame] | 2038 | bool ValidateMaskBitsFromLayouts(core_validation::layer_data *device_data, VkCommandBuffer cmdBuffer, |
| 2039 | const VkAccessFlags &accessMask, const VkImageLayout &layout, const char *type) { |
| 2040 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
Mark Lobodzinski | b3829a5 | 2017-02-07 16:55:53 -0700 | [diff] [blame] | 2041 | |
Mark Lobodzinski | 9a8d40f | 2017-02-07 17:00:12 -0700 | [diff] [blame] | 2042 | bool skip = false; |
Mark Lobodzinski | b3829a5 | 2017-02-07 16:55:53 -0700 | [diff] [blame] | 2043 | switch (layout) { |
Mark Lobodzinski | 9a8d40f | 2017-02-07 17:00:12 -0700 | [diff] [blame] | 2044 | case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: { |
| 2045 | skip |= ValidateMaskBits(device_data, cmdBuffer, accessMask, layout, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, |
| 2046 | VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT, type); |
| 2047 | break; |
Mark Lobodzinski | b3829a5 | 2017-02-07 16:55:53 -0700 | [diff] [blame] | 2048 | } |
Mark Lobodzinski | 9a8d40f | 2017-02-07 17:00:12 -0700 | [diff] [blame] | 2049 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: { |
| 2050 | skip |= ValidateMaskBits(device_data, cmdBuffer, accessMask, layout, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, |
| 2051 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT, type); |
| 2052 | break; |
| 2053 | } |
| 2054 | case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL: { |
| 2055 | skip |= ValidateMaskBits(device_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_WRITE_BIT, 0, type); |
| 2056 | break; |
| 2057 | } |
| 2058 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: { |
| 2059 | skip |= ValidateMaskBits( |
| 2060 | device_data, cmdBuffer, accessMask, layout, 0, |
| 2061 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT, |
| 2062 | type); |
| 2063 | break; |
| 2064 | } |
| 2065 | case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: { |
| 2066 | skip |= ValidateMaskBits(device_data, cmdBuffer, accessMask, layout, 0, |
| 2067 | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT | VK_ACCESS_SHADER_READ_BIT, type); |
| 2068 | break; |
| 2069 | } |
| 2070 | case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL: { |
| 2071 | skip |= ValidateMaskBits(device_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_READ_BIT, 0, type); |
| 2072 | break; |
| 2073 | } |
| 2074 | case VK_IMAGE_LAYOUT_PRESENT_SRC_KHR: { |
| 2075 | skip |= ValidateMaskBits(device_data, cmdBuffer, accessMask, layout, VK_ACCESS_MEMORY_READ_BIT, 0, type); |
| 2076 | break; |
| 2077 | } |
| 2078 | case VK_IMAGE_LAYOUT_UNDEFINED: { |
| 2079 | if (accessMask != 0) { |
| 2080 | // TODO: Verify against Valid Use section spec |
| 2081 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, |
| 2082 | DRAWSTATE_INVALID_BARRIER, "DS", |
| 2083 | "Additional bits in %s accessMask 0x%X %s are specified when layout is %s.", type, accessMask, |
| 2084 | string_VkAccessFlags(accessMask).c_str(), string_VkImageLayout(layout)); |
| 2085 | } |
| 2086 | break; |
| 2087 | } |
| 2088 | case VK_IMAGE_LAYOUT_GENERAL: |
| 2089 | default: { break; } |
Mark Lobodzinski | b3829a5 | 2017-02-07 16:55:53 -0700 | [diff] [blame] | 2090 | } |
Mark Lobodzinski | 9a8d40f | 2017-02-07 17:00:12 -0700 | [diff] [blame] | 2091 | return skip; |
Mark Lobodzinski | b3829a5 | 2017-02-07 16:55:53 -0700 | [diff] [blame] | 2092 | } |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 2093 | |
| 2094 | // 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] | 2095 | // VkAttachmentDescription structs that are used by the sub-passes of a renderpass. Initial check is to make sure that READ_ONLY |
| 2096 | // layout attachments don't have CLEAR as their loadOp. |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 2097 | bool ValidateLayoutVsAttachmentDescription(const debug_report_data *report_data, const VkImageLayout first_layout, |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 2098 | const uint32_t attachment, const VkAttachmentDescription &attachment_description) { |
| 2099 | bool skip = false; |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 2100 | // Verify that initial loadOp on READ_ONLY attachments is not CLEAR |
| 2101 | if (attachment_description.loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR) { |
| 2102 | if ((first_layout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL) || |
| 2103 | (first_layout == VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL)) { |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 2104 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, |
| 2105 | VkDebugReportObjectTypeEXT(0), __LINE__, VALIDATION_ERROR_02351, "DS", |
| 2106 | "Cannot clear attachment %d with invalid first layout %s. %s", attachment, |
| 2107 | string_VkImageLayout(first_layout), validation_error_map[VALIDATION_ERROR_02351]); |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 2108 | } |
| 2109 | } |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 2110 | return skip; |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 2111 | } |
| 2112 | |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 2113 | bool ValidateLayouts(core_validation::layer_data *device_data, VkDevice device, const VkRenderPassCreateInfo *pCreateInfo) { |
| 2114 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 2115 | bool skip = false; |
| 2116 | |
| 2117 | // Track when we're observing the first use of an attachment |
| 2118 | std::vector<bool> attach_first_use(pCreateInfo->attachmentCount, true); |
| 2119 | for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) { |
| 2120 | const VkSubpassDescription &subpass = pCreateInfo->pSubpasses[i]; |
| 2121 | for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) { |
| 2122 | auto attach_index = subpass.pColorAttachments[j].attachment; |
| 2123 | if (attach_index == VK_ATTACHMENT_UNUSED) continue; |
| 2124 | |
| 2125 | switch (subpass.pColorAttachments[j].layout) { |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 2126 | case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: |
| 2127 | // This is ideal. |
| 2128 | break; |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 2129 | |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 2130 | case VK_IMAGE_LAYOUT_GENERAL: |
| 2131 | // May not be optimal; TODO: reconsider this warning based on other constraints? |
| 2132 | skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 2133 | VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", |
| 2134 | "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL."); |
| 2135 | break; |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 2136 | |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 2137 | default: |
| 2138 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 2139 | __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", |
| 2140 | "Layout for color attachment is %s but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.", |
| 2141 | string_VkImageLayout(subpass.pColorAttachments[j].layout)); |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 2142 | } |
| 2143 | |
| 2144 | if (attach_first_use[attach_index]) { |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 2145 | skip |= ValidateLayoutVsAttachmentDescription(report_data, subpass.pColorAttachments[j].layout, attach_index, |
| 2146 | pCreateInfo->pAttachments[attach_index]); |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 2147 | } |
| 2148 | attach_first_use[attach_index] = false; |
| 2149 | } |
| 2150 | if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) { |
| 2151 | switch (subpass.pDepthStencilAttachment->layout) { |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 2152 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: |
| 2153 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: |
| 2154 | // These are ideal. |
| 2155 | break; |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 2156 | |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 2157 | case VK_IMAGE_LAYOUT_GENERAL: |
| 2158 | // May not be optimal; TODO: reconsider this warning based on other constraints? GENERAL can be better than |
| 2159 | // doing a bunch of transitions. |
| 2160 | skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 2161 | VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", |
| 2162 | "GENERAL layout for depth attachment may not give optimal performance."); |
| 2163 | break; |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 2164 | |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 2165 | default: |
| 2166 | // No other layouts are acceptable |
| 2167 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 2168 | __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", |
| 2169 | "Layout for depth attachment is %s but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL, " |
| 2170 | "DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.", |
| 2171 | string_VkImageLayout(subpass.pDepthStencilAttachment->layout)); |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 2172 | } |
| 2173 | |
| 2174 | auto attach_index = subpass.pDepthStencilAttachment->attachment; |
| 2175 | if (attach_first_use[attach_index]) { |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 2176 | skip |= ValidateLayoutVsAttachmentDescription(report_data, subpass.pDepthStencilAttachment->layout, attach_index, |
| 2177 | pCreateInfo->pAttachments[attach_index]); |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 2178 | } |
| 2179 | attach_first_use[attach_index] = false; |
| 2180 | } |
| 2181 | for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) { |
| 2182 | auto attach_index = subpass.pInputAttachments[j].attachment; |
| 2183 | if (attach_index == VK_ATTACHMENT_UNUSED) continue; |
| 2184 | |
| 2185 | switch (subpass.pInputAttachments[j].layout) { |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 2186 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: |
| 2187 | case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: |
| 2188 | // These are ideal. |
| 2189 | break; |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 2190 | |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 2191 | case VK_IMAGE_LAYOUT_GENERAL: |
| 2192 | // May not be optimal. TODO: reconsider this warning based on other constraints. |
| 2193 | skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 2194 | VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", |
| 2195 | "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL."); |
| 2196 | break; |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 2197 | |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 2198 | default: |
| 2199 | // No other layouts are acceptable |
| 2200 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, |
| 2201 | DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", |
| 2202 | "Layout for input attachment is %s but can only be READ_ONLY_OPTIMAL or GENERAL.", |
| 2203 | string_VkImageLayout(subpass.pInputAttachments[j].layout)); |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 2204 | } |
| 2205 | |
| 2206 | if (attach_first_use[attach_index]) { |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 2207 | skip |= ValidateLayoutVsAttachmentDescription(report_data, subpass.pInputAttachments[j].layout, attach_index, |
| 2208 | pCreateInfo->pAttachments[attach_index]); |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 2209 | } |
| 2210 | attach_first_use[attach_index] = false; |
| 2211 | } |
| 2212 | } |
| 2213 | return skip; |
| 2214 | } |
Mark Lobodzinski | 08f14fa | 2017-02-07 17:20:06 -0700 | [diff] [blame] | 2215 | |
| 2216 | // 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] | 2217 | bool ValidateMapImageLayouts(core_validation::layer_data *device_data, VkDevice device, DEVICE_MEM_INFO const *mem_info, |
| 2218 | VkDeviceSize offset, VkDeviceSize end_offset) { |
| 2219 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 2220 | bool skip = false; |
| 2221 | // Iterate over all bound image ranges and verify that for any that overlap the map ranges, the layouts are |
| 2222 | // VK_IMAGE_LAYOUT_PREINITIALIZED or VK_IMAGE_LAYOUT_GENERAL |
Mark Lobodzinski | 08f14fa | 2017-02-07 17:20:06 -0700 | [diff] [blame] | 2223 | // TODO : This can be optimized if we store ranges based on starting address and early exit when we pass our range |
| 2224 | for (auto image_handle : mem_info->bound_images) { |
| 2225 | auto img_it = mem_info->bound_ranges.find(image_handle); |
| 2226 | if (img_it != mem_info->bound_ranges.end()) { |
Mark Lobodzinski | ac23ec8 | 2017-02-07 17:21:55 -0700 | [diff] [blame] | 2227 | if (rangesIntersect(device_data, &img_it->second, offset, end_offset)) { |
Mark Lobodzinski | 08f14fa | 2017-02-07 17:20:06 -0700 | [diff] [blame] | 2228 | std::vector<VkImageLayout> layouts; |
Mark Lobodzinski | ac23ec8 | 2017-02-07 17:21:55 -0700 | [diff] [blame] | 2229 | if (FindLayouts(device_data, VkImage(image_handle), layouts)) { |
Mark Lobodzinski | 08f14fa | 2017-02-07 17:20:06 -0700 | [diff] [blame] | 2230 | for (auto layout : layouts) { |
| 2231 | if (layout != VK_IMAGE_LAYOUT_PREINITIALIZED && layout != VK_IMAGE_LAYOUT_GENERAL) { |
Dave Houlton | eba86e2 | 2017-03-02 14:56:23 -0700 | [diff] [blame] | 2232 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, |
| 2233 | __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", |
Michael Lentine | c174b93 | 2017-02-10 14:57:15 -0600 | [diff] [blame] | 2234 | "Mapping an image with layout %s can result in undefined behavior if this memory is " |
| 2235 | "used by the device. Only GENERAL or PREINITIALIZED should be used.", |
Mark Lobodzinski | ac23ec8 | 2017-02-07 17:21:55 -0700 | [diff] [blame] | 2236 | string_VkImageLayout(layout)); |
Mark Lobodzinski | 08f14fa | 2017-02-07 17:20:06 -0700 | [diff] [blame] | 2237 | } |
| 2238 | } |
| 2239 | } |
| 2240 | } |
| 2241 | } |
| 2242 | } |
Mark Lobodzinski | ac23ec8 | 2017-02-07 17:21:55 -0700 | [diff] [blame] | 2243 | return skip; |
Mark Lobodzinski | 08f14fa | 2017-02-07 17:20:06 -0700 | [diff] [blame] | 2244 | } |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 2245 | |
| 2246 | // Helper function to validate correct usage bits set for buffers or images. Verify that (actual & desired) flags != 0 or, if strict |
| 2247 | // is true, verify that (actual & desired) flags == desired |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 2248 | 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] | 2249 | VkDebugReportObjectTypeEXT obj_type, int32_t const msgCode, char const *ty_str, |
| 2250 | char const *func_name, char const *usage_str) { |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 2251 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 2252 | |
| 2253 | bool correct_usage = false; |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 2254 | bool skip = false; |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 2255 | if (strict) { |
| 2256 | correct_usage = ((actual & desired) == desired); |
| 2257 | } else { |
| 2258 | correct_usage = ((actual & desired) != 0); |
| 2259 | } |
| 2260 | if (!correct_usage) { |
| 2261 | if (msgCode == -1) { |
| 2262 | // TODO: Fix callers with msgCode == -1 to use correct validation checks. |
Dave Houlton | eba86e2 | 2017-03-02 14:56:23 -0700 | [diff] [blame] | 2263 | skip = log_msg( |
| 2264 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, obj_type, obj_handle, __LINE__, MEMTRACK_INVALID_USAGE_FLAG, "MEM", |
| 2265 | "Invalid usage flag for %s 0x%" PRIxLEAST64 " used by %s. In this case, %s should have %s set during creation.", |
| 2266 | ty_str, obj_handle, func_name, ty_str, usage_str); |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 2267 | } else { |
| 2268 | const char *valid_usage = (msgCode == -1) ? "" : validation_error_map[msgCode]; |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 2269 | skip = log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, obj_type, obj_handle, __LINE__, msgCode, "MEM", |
| 2270 | "Invalid usage flag for %s 0x%" PRIxLEAST64 |
| 2271 | " used by %s. In this case, %s should have %s set during creation. %s", |
| 2272 | ty_str, obj_handle, func_name, ty_str, usage_str, valid_usage); |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 2273 | } |
| 2274 | } |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 2275 | return skip; |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 2276 | } |
| 2277 | |
| 2278 | // Helper function to validate usage flags for buffers. For given buffer_state send actual vs. desired usage off to helper above |
| 2279 | // where an error will be flagged if usage is not correct |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 2280 | 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] | 2281 | int32_t const msgCode, char const *func_name, char const *usage_string) { |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 2282 | return validate_usage_flags(device_data, image_state->createInfo.usage, desired, strict, |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 2283 | reinterpret_cast<const uint64_t &>(image_state->image), VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 2284 | msgCode, "image", func_name, usage_string); |
| 2285 | } |
| 2286 | |
| 2287 | // Helper function to validate usage flags for buffers. For given buffer_state send actual vs. desired usage off to helper above |
| 2288 | // where an error will be flagged if usage is not correct |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 2289 | 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] | 2290 | int32_t const msgCode, char const *func_name, char const *usage_string) { |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 2291 | return validate_usage_flags(device_data, buffer_state->createInfo.usage, desired, strict, |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 2292 | reinterpret_cast<const uint64_t &>(buffer_state->buffer), VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, |
| 2293 | msgCode, "buffer", func_name, usage_string); |
| 2294 | } |
| 2295 | |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 2296 | bool PreCallValidateCreateBuffer(layer_data *device_data, const VkBufferCreateInfo *pCreateInfo) { |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 2297 | bool skip = false; |
Mark Lobodzinski | 847b60c | 2017-03-13 09:32:45 -0600 | [diff] [blame] | 2298 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 2299 | |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 2300 | // TODO: Add check for VALIDATION_ERROR_00658 |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 2301 | // TODO: Add check for VALIDATION_ERROR_00667 |
| 2302 | // TODO: Add check for VALIDATION_ERROR_00668 |
| 2303 | // TODO: Add check for VALIDATION_ERROR_00669 |
Mark Lobodzinski | 847b60c | 2017-03-13 09:32:45 -0600 | [diff] [blame] | 2304 | |
| 2305 | if ((pCreateInfo->flags & VK_BUFFER_CREATE_SPARSE_BINDING_BIT) && (!GetEnabledFeatures(device_data)->sparseBinding)) { |
| 2306 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, |
| 2307 | VALIDATION_ERROR_00666, "DS", |
| 2308 | "vkCreateBuffer(): the sparseBinding device feature is disabled: Buffers cannot be created with the " |
| 2309 | "VK_BUFFER_CREATE_SPARSE_BINDING_BIT set. %s", |
| 2310 | validation_error_map[VALIDATION_ERROR_00666]); |
| 2311 | } |
Mark Lobodzinski | af35506 | 2017-03-13 09:35:01 -0600 | [diff] [blame] | 2312 | |
| 2313 | if ((pCreateInfo->flags & VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT) && (!GetEnabledFeatures(device_data)->sparseResidencyBuffer)) { |
| 2314 | skip |= |
| 2315 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, |
| 2316 | DRAWSTATE_INVALID_FEATURE, "DS", |
| 2317 | "vkCreateBuffer(): the sparseResidencyBuffer device feature is disabled: Buffers cannot be created with the " |
| 2318 | "VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT set."); |
| 2319 | } |
Mark Lobodzinski | 035a4cf | 2017-03-13 09:45:07 -0600 | [diff] [blame] | 2320 | |
| 2321 | if ((pCreateInfo->flags & VK_BUFFER_CREATE_SPARSE_ALIASED_BIT) && (!GetEnabledFeatures(device_data)->sparseResidencyAliased)) { |
| 2322 | skip |= |
| 2323 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, |
| 2324 | DRAWSTATE_INVALID_FEATURE, "DS", |
| 2325 | "vkCreateBuffer(): the sparseResidencyAliased device feature is disabled: Buffers cannot be created with the " |
| 2326 | "VK_BUFFER_CREATE_SPARSE_ALIASED_BIT set."); |
| 2327 | } |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 2328 | return skip; |
| 2329 | } |
| 2330 | |
| 2331 | void PostCallRecordCreateBuffer(layer_data *device_data, const VkBufferCreateInfo *pCreateInfo, VkBuffer *pBuffer) { |
| 2332 | // TODO : This doesn't create deep copy of pQueueFamilyIndices so need to fix that if/when we want that data to be valid |
| 2333 | GetBufferMap(device_data) |
| 2334 | ->insert(std::make_pair(*pBuffer, std::unique_ptr<BUFFER_STATE>(new BUFFER_STATE(*pBuffer, pCreateInfo)))); |
| 2335 | } |
| 2336 | |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 2337 | bool PreCallValidateCreateBufferView(layer_data *device_data, const VkBufferViewCreateInfo *pCreateInfo) { |
| 2338 | bool skip = false; |
| 2339 | BUFFER_STATE *buffer_state = GetBufferState(device_data, pCreateInfo->buffer); |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 2340 | // If this isn't a sparse buffer, it needs to have memory backing it at CreateBufferView time |
| 2341 | if (buffer_state) { |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 2342 | skip |= ValidateMemoryIsBoundToBuffer(device_data, buffer_state, "vkCreateBufferView()", VALIDATION_ERROR_02522); |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 2343 | // In order to create a valid buffer view, the buffer must have been created with at least one of the following flags: |
| 2344 | // UNIFORM_TEXEL_BUFFER_BIT or STORAGE_TEXEL_BUFFER_BIT |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 2345 | skip |= ValidateBufferUsageFlags( |
| 2346 | 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] | 2347 | VALIDATION_ERROR_00694, "vkCreateBufferView()", "VK_BUFFER_USAGE_[STORAGE|UNIFORM]_TEXEL_BUFFER_BIT"); |
| 2348 | } |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 2349 | return skip; |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 2350 | } |
| 2351 | |
| 2352 | void PostCallRecordCreateBufferView(layer_data *device_data, const VkBufferViewCreateInfo *pCreateInfo, VkBufferView *pView) { |
| 2353 | (*GetBufferViewMap(device_data))[*pView] = std::unique_ptr<BUFFER_VIEW_STATE>(new BUFFER_VIEW_STATE(*pView, pCreateInfo)); |
| 2354 | } |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 2355 | |
| 2356 | // For the given format verify that the aspect masks make sense |
| 2357 | bool ValidateImageAspectMask(layer_data *device_data, VkImage image, VkFormat format, VkImageAspectFlags aspect_mask, |
| 2358 | const char *func_name) { |
| 2359 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 2360 | bool skip = false; |
| 2361 | if (vk_format_is_color(format)) { |
| 2362 | if ((aspect_mask & VK_IMAGE_ASPECT_COLOR_BIT) != VK_IMAGE_ASPECT_COLOR_BIT) { |
| 2363 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, (uint64_t)image, |
| 2364 | __LINE__, VALIDATION_ERROR_00741, "IMAGE", |
| 2365 | "%s: Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set. %s", func_name, |
| 2366 | validation_error_map[VALIDATION_ERROR_00741]); |
| 2367 | } else if ((aspect_mask & VK_IMAGE_ASPECT_COLOR_BIT) != aspect_mask) { |
| 2368 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, (uint64_t)image, |
| 2369 | __LINE__, VALIDATION_ERROR_00741, "IMAGE", |
| 2370 | "%s: Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set. %s", func_name, |
| 2371 | validation_error_map[VALIDATION_ERROR_00741]); |
| 2372 | } |
| 2373 | } else if (vk_format_is_depth_and_stencil(format)) { |
| 2374 | if ((aspect_mask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) == 0) { |
| 2375 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, (uint64_t)image, |
| 2376 | __LINE__, VALIDATION_ERROR_00741, "IMAGE", |
| 2377 | "%s: Depth/stencil image formats must have " |
| 2378 | "at least one of VK_IMAGE_ASPECT_DEPTH_BIT " |
| 2379 | "and VK_IMAGE_ASPECT_STENCIL_BIT set. %s", |
| 2380 | func_name, validation_error_map[VALIDATION_ERROR_00741]); |
| 2381 | } else if ((aspect_mask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) != aspect_mask) { |
| 2382 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, (uint64_t)image, |
| 2383 | __LINE__, VALIDATION_ERROR_00741, "IMAGE", |
| 2384 | "%s: Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and " |
| 2385 | "VK_IMAGE_ASPECT_STENCIL_BIT set. %s", |
| 2386 | func_name, validation_error_map[VALIDATION_ERROR_00741]); |
| 2387 | } |
| 2388 | } else if (vk_format_is_depth_only(format)) { |
| 2389 | if ((aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) != VK_IMAGE_ASPECT_DEPTH_BIT) { |
| 2390 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, (uint64_t)image, |
| 2391 | __LINE__, VALIDATION_ERROR_00741, "IMAGE", |
| 2392 | "%s: Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set. %s", func_name, |
| 2393 | validation_error_map[VALIDATION_ERROR_00741]); |
| 2394 | } else if ((aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) != aspect_mask) { |
| 2395 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, (uint64_t)image, |
| 2396 | __LINE__, VALIDATION_ERROR_00741, "IMAGE", |
| 2397 | "%s: Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set. %s", func_name, |
| 2398 | validation_error_map[VALIDATION_ERROR_00741]); |
| 2399 | } |
| 2400 | } else if (vk_format_is_stencil_only(format)) { |
| 2401 | if ((aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) != VK_IMAGE_ASPECT_STENCIL_BIT) { |
| 2402 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, (uint64_t)image, |
| 2403 | __LINE__, VALIDATION_ERROR_00741, "IMAGE", |
| 2404 | "%s: Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set. %s", func_name, |
| 2405 | validation_error_map[VALIDATION_ERROR_00741]); |
| 2406 | } else if ((aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) != aspect_mask) { |
| 2407 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, (uint64_t)image, |
| 2408 | __LINE__, VALIDATION_ERROR_00741, "IMAGE", |
| 2409 | "%s: Stencil-only image formats can have only the VK_IMAGE_ASPECT_STENCIL_BIT set. %s", func_name, |
| 2410 | validation_error_map[VALIDATION_ERROR_00741]); |
| 2411 | } |
| 2412 | } |
| 2413 | return skip; |
| 2414 | } |
| 2415 | |
| 2416 | bool ValidateImageSubrangeLevelLayerCounts(layer_data *device_data, const VkImageSubresourceRange &subresourceRange, |
| 2417 | const char *func_name) { |
| 2418 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 2419 | bool skip = false; |
| 2420 | if (subresourceRange.levelCount == 0) { |
| 2421 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, |
| 2422 | VALIDATION_ERROR_00768, "IMAGE", "%s called with 0 in subresourceRange.levelCount. %s", func_name, |
| 2423 | validation_error_map[VALIDATION_ERROR_00768]); |
| 2424 | } |
| 2425 | if (subresourceRange.layerCount == 0) { |
| 2426 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, |
| 2427 | VALIDATION_ERROR_00769, "IMAGE", "%s called with 0 in subresourceRange.layerCount. %s", func_name, |
| 2428 | validation_error_map[VALIDATION_ERROR_00769]); |
| 2429 | } |
| 2430 | return skip; |
| 2431 | } |
| 2432 | |
| 2433 | bool PreCallValidateCreateImageView(layer_data *device_data, const VkImageViewCreateInfo *create_info) { |
| 2434 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 2435 | bool skip = false; |
| 2436 | IMAGE_STATE *image_state = GetImageState(device_data, create_info->image); |
| 2437 | if (image_state) { |
| 2438 | skip |= ValidateImageUsageFlags( |
| 2439 | device_data, image_state, |
| 2440 | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT | |
| 2441 | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, |
| 2442 | false, -1, "vkCreateImageView()", |
| 2443 | "VK_IMAGE_USAGE_[SAMPLED|STORAGE|COLOR_ATTACHMENT|DEPTH_STENCIL_ATTACHMENT|INPUT_ATTACHMENT]_BIT"); |
| 2444 | // If this isn't a sparse image, it needs to have memory backing it at CreateImageView time |
| 2445 | skip |= ValidateMemoryIsBoundToImage(device_data, image_state, "vkCreateImageView()", VALIDATION_ERROR_02524); |
| 2446 | // Checks imported from image layer |
| 2447 | if (create_info->subresourceRange.baseMipLevel >= image_state->createInfo.mipLevels) { |
| 2448 | std::stringstream ss; |
| 2449 | ss << "vkCreateImageView called with baseMipLevel " << create_info->subresourceRange.baseMipLevel << " for image " |
| 2450 | << create_info->image << " that only has " << image_state->createInfo.mipLevels << " mip levels."; |
| 2451 | skip |= |
| 2452 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, |
| 2453 | VALIDATION_ERROR_00768, "IMAGE", "%s %s", ss.str().c_str(), validation_error_map[VALIDATION_ERROR_00768]); |
| 2454 | } |
| 2455 | if (create_info->subresourceRange.baseArrayLayer >= image_state->createInfo.arrayLayers) { |
| 2456 | std::stringstream ss; |
| 2457 | ss << "vkCreateImageView called with baseArrayLayer " << create_info->subresourceRange.baseArrayLayer << " for image " |
| 2458 | << create_info->image << " that only has " << image_state->createInfo.arrayLayers << " array layers."; |
| 2459 | skip |= |
| 2460 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, |
| 2461 | VALIDATION_ERROR_00769, "IMAGE", "%s %s", ss.str().c_str(), validation_error_map[VALIDATION_ERROR_00769]); |
| 2462 | } |
| 2463 | // TODO: Need new valid usage language for levelCount == 0 & layerCount == 0 |
| 2464 | skip |= ValidateImageSubrangeLevelLayerCounts(device_data, create_info->subresourceRange, "vkCreateImageView()"); |
| 2465 | |
| 2466 | VkImageCreateFlags image_flags = image_state->createInfo.flags; |
| 2467 | VkFormat image_format = image_state->createInfo.format; |
| 2468 | VkFormat view_format = create_info->format; |
| 2469 | VkImageAspectFlags aspect_mask = create_info->subresourceRange.aspectMask; |
| 2470 | |
| 2471 | // Validate VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT state |
| 2472 | if (image_flags & VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT) { |
| 2473 | // Format MUST be compatible (in the same format compatibility class) as the format the image was created with |
| 2474 | if (vk_format_get_compatibility_class(image_format) != vk_format_get_compatibility_class(view_format)) { |
| 2475 | std::stringstream ss; |
| 2476 | ss << "vkCreateImageView(): ImageView format " << string_VkFormat(view_format) |
| 2477 | << " is not in the same format compatibility class as image (" << (uint64_t)create_info->image << ") format " |
| 2478 | << string_VkFormat(image_format) << ". Images created with the VK_IMAGE_CREATE_MUTABLE_FORMAT BIT " |
| 2479 | << "can support ImageViews with differing formats but they must be in the same compatibility class."; |
| 2480 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, |
| 2481 | VALIDATION_ERROR_02171, "IMAGE", "%s %s", ss.str().c_str(), |
| 2482 | validation_error_map[VALIDATION_ERROR_02171]); |
| 2483 | } |
| 2484 | } else { |
| 2485 | // Format MUST be IDENTICAL to the format the image was created with |
| 2486 | if (image_format != view_format) { |
| 2487 | std::stringstream ss; |
| 2488 | ss << "vkCreateImageView() format " << string_VkFormat(view_format) << " differs from image " |
| 2489 | << (uint64_t)create_info->image << " format " << string_VkFormat(image_format) |
| 2490 | << ". Formats MUST be IDENTICAL unless VK_IMAGE_CREATE_MUTABLE_FORMAT BIT was set on image creation."; |
| 2491 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, |
| 2492 | VALIDATION_ERROR_02172, "IMAGE", "%s %s", ss.str().c_str(), |
| 2493 | validation_error_map[VALIDATION_ERROR_02172]); |
| 2494 | } |
| 2495 | } |
| 2496 | |
| 2497 | // Validate correct image aspect bits for desired formats and format consistency |
| 2498 | skip |= ValidateImageAspectMask(device_data, image_state->image, image_format, aspect_mask, "vkCreateImageView()"); |
| 2499 | } |
| 2500 | return skip; |
| 2501 | } |
| 2502 | |
Mark Lobodzinski | efd933b | 2017-02-10 12:09:23 -0700 | [diff] [blame] | 2503 | void PostCallRecordCreateImageView(layer_data *device_data, const VkImageViewCreateInfo *create_info, VkImageView view) { |
| 2504 | auto image_view_map = GetImageViewMap(device_data); |
| 2505 | (*image_view_map)[view] = std::unique_ptr<IMAGE_VIEW_STATE>(new IMAGE_VIEW_STATE(view, create_info)); |
| 2506 | |
| 2507 | auto image_state = GetImageState(device_data, create_info->image); |
Dave Houlton | 4eaaf3a | 2017-03-14 11:31:20 -0600 | [diff] [blame] | 2508 | auto &sub_res_range = (*image_view_map)[view].get()->create_info.subresourceRange; |
Mark Lobodzinski | efd933b | 2017-02-10 12:09:23 -0700 | [diff] [blame] | 2509 | ResolveRemainingLevelsLayers(device_data, &sub_res_range, image_state); |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 2510 | } |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 2511 | |
Mark Lobodzinski | 680421d | 2017-02-09 13:06:56 -0700 | [diff] [blame] | 2512 | bool PreCallValidateCmdCopyBuffer(layer_data *device_data, GLOBAL_CB_NODE *cb_node, BUFFER_STATE *src_buffer_state, |
| 2513 | BUFFER_STATE *dst_buffer_state) { |
| 2514 | bool skip = false; |
| 2515 | skip |= ValidateMemoryIsBoundToBuffer(device_data, src_buffer_state, "vkCmdCopyBuffer()", VALIDATION_ERROR_02531); |
| 2516 | skip |= ValidateMemoryIsBoundToBuffer(device_data, dst_buffer_state, "vkCmdCopyBuffer()", VALIDATION_ERROR_02532); |
| 2517 | // Validate that SRC & DST buffers have correct usage flags set |
| 2518 | skip |= ValidateBufferUsageFlags(device_data, src_buffer_state, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, true, VALIDATION_ERROR_01164, |
| 2519 | "vkCmdCopyBuffer()", "VK_BUFFER_USAGE_TRANSFER_SRC_BIT"); |
| 2520 | skip |= ValidateBufferUsageFlags(device_data, dst_buffer_state, VK_BUFFER_USAGE_TRANSFER_DST_BIT, true, VALIDATION_ERROR_01165, |
| 2521 | "vkCmdCopyBuffer()", "VK_BUFFER_USAGE_TRANSFER_DST_BIT"); |
| 2522 | skip |= ValidateCmd(device_data, cb_node, CMD_COPYBUFFER, "vkCmdCopyBuffer()"); |
| 2523 | skip |= insideRenderPass(device_data, cb_node, "vkCmdCopyBuffer()", VALIDATION_ERROR_01172); |
| 2524 | return skip; |
| 2525 | } |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 2526 | |
Mark Lobodzinski | 680421d | 2017-02-09 13:06:56 -0700 | [diff] [blame] | 2527 | void PreCallRecordCmdCopyBuffer(layer_data *device_data, GLOBAL_CB_NODE *cb_node, BUFFER_STATE *src_buffer_state, |
| 2528 | BUFFER_STATE *dst_buffer_state) { |
| 2529 | // Update bindings between buffers and cmd buffer |
| 2530 | AddCommandBufferBindingBuffer(device_data, cb_node, src_buffer_state); |
| 2531 | AddCommandBufferBindingBuffer(device_data, cb_node, dst_buffer_state); |
| 2532 | |
| 2533 | std::function<bool()> function = [=]() { |
| 2534 | return ValidateBufferMemoryIsValid(device_data, src_buffer_state, "vkCmdCopyBuffer()"); |
| 2535 | }; |
| 2536 | cb_node->validate_functions.push_back(function); |
| 2537 | function = [=]() { |
| 2538 | SetBufferMemoryValid(device_data, dst_buffer_state, true); |
| 2539 | return false; |
| 2540 | }; |
| 2541 | cb_node->validate_functions.push_back(function); |
| 2542 | core_validation::UpdateCmdBufferLastCmd(cb_node, CMD_COPYBUFFER); |
| 2543 | } |
Mark Lobodzinski | 306441e | 2017-02-10 13:48:38 -0700 | [diff] [blame] | 2544 | |
| 2545 | static bool validateIdleBuffer(layer_data *device_data, VkBuffer buffer) { |
| 2546 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 2547 | bool skip = false; |
| 2548 | auto buffer_state = GetBufferState(device_data, buffer); |
| 2549 | if (!buffer_state) { |
| 2550 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, (uint64_t)(buffer), |
| 2551 | __LINE__, DRAWSTATE_DOUBLE_DESTROY, "DS", |
| 2552 | "Cannot free buffer 0x%" PRIxLEAST64 " that has not been allocated.", (uint64_t)(buffer)); |
| 2553 | } else { |
| 2554 | if (buffer_state->in_use.load()) { |
| 2555 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, (uint64_t)(buffer), |
| 2556 | __LINE__, VALIDATION_ERROR_00676, "DS", |
| 2557 | "Cannot free buffer 0x%" PRIxLEAST64 " that is in use by a command buffer. %s", (uint64_t)(buffer), |
| 2558 | validation_error_map[VALIDATION_ERROR_00676]); |
| 2559 | } |
| 2560 | } |
| 2561 | return skip; |
| 2562 | } |
| 2563 | |
| 2564 | bool PreCallValidateDestroyImageView(layer_data *device_data, VkImageView image_view, IMAGE_VIEW_STATE **image_view_state, |
| 2565 | VK_OBJECT *obj_struct) { |
| 2566 | *image_view_state = GetImageViewState(device_data, image_view); |
| 2567 | *obj_struct = {reinterpret_cast<uint64_t &>(image_view), VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT}; |
| 2568 | if (GetDisables(device_data)->destroy_image_view) return false; |
| 2569 | bool skip = false; |
| 2570 | if (*image_view_state) { |
| 2571 | skip |= ValidateObjectNotInUse(device_data, *image_view_state, *obj_struct, VALIDATION_ERROR_00776); |
| 2572 | } |
| 2573 | return skip; |
| 2574 | } |
| 2575 | |
| 2576 | void PostCallRecordDestroyImageView(layer_data *device_data, VkImageView image_view, IMAGE_VIEW_STATE *image_view_state, |
| 2577 | VK_OBJECT obj_struct) { |
| 2578 | // Any bound cmd buffers are now invalid |
| 2579 | invalidateCommandBuffers(device_data, image_view_state->cb_bindings, obj_struct); |
| 2580 | (*GetImageViewMap(device_data)).erase(image_view); |
| 2581 | } |
| 2582 | |
| 2583 | bool PreCallValidateDestroyBuffer(layer_data *device_data, VkBuffer buffer, BUFFER_STATE **buffer_state, VK_OBJECT *obj_struct) { |
| 2584 | *buffer_state = GetBufferState(device_data, buffer); |
| 2585 | *obj_struct = {reinterpret_cast<uint64_t &>(buffer), VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT}; |
| 2586 | if (GetDisables(device_data)->destroy_buffer) return false; |
| 2587 | bool skip = false; |
| 2588 | if (*buffer_state) { |
| 2589 | skip |= validateIdleBuffer(device_data, buffer); |
| 2590 | } |
| 2591 | return skip; |
| 2592 | } |
| 2593 | |
| 2594 | void PostCallRecordDestroyBuffer(layer_data *device_data, VkBuffer buffer, BUFFER_STATE *buffer_state, VK_OBJECT obj_struct) { |
| 2595 | invalidateCommandBuffers(device_data, buffer_state->cb_bindings, obj_struct); |
| 2596 | for (auto mem_binding : buffer_state->GetBoundMemory()) { |
| 2597 | auto mem_info = GetMemObjInfo(device_data, mem_binding); |
| 2598 | if (mem_info) { |
| 2599 | core_validation::RemoveBufferMemoryRange(reinterpret_cast<uint64_t &>(buffer), mem_info); |
| 2600 | } |
| 2601 | } |
| 2602 | ClearMemoryObjectBindings(device_data, reinterpret_cast<uint64_t &>(buffer), VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT); |
| 2603 | GetBufferMap(device_data)->erase(buffer_state->buffer); |
| 2604 | } |
| 2605 | |
| 2606 | bool PreCallValidateDestroyBufferView(layer_data *device_data, VkBufferView buffer_view, BUFFER_VIEW_STATE **buffer_view_state, |
| 2607 | VK_OBJECT *obj_struct) { |
| 2608 | *buffer_view_state = GetBufferViewState(device_data, buffer_view); |
| 2609 | *obj_struct = {reinterpret_cast<uint64_t &>(buffer_view), VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_VIEW_EXT}; |
| 2610 | if (GetDisables(device_data)->destroy_buffer_view) return false; |
| 2611 | bool skip = false; |
| 2612 | if (*buffer_view_state) { |
| 2613 | skip |= ValidateObjectNotInUse(device_data, *buffer_view_state, *obj_struct, VALIDATION_ERROR_00701); |
| 2614 | } |
| 2615 | return skip; |
| 2616 | } |
| 2617 | |
| 2618 | void PostCallRecordDestroyBufferView(layer_data *device_data, VkBufferView buffer_view, BUFFER_VIEW_STATE *buffer_view_state, |
| 2619 | VK_OBJECT obj_struct) { |
| 2620 | // Any bound cmd buffers are now invalid |
| 2621 | invalidateCommandBuffers(device_data, buffer_view_state->cb_bindings, obj_struct); |
| 2622 | GetBufferViewMap(device_data)->erase(buffer_view); |
| 2623 | } |
Mark Lobodzinski | df0acbf | 2017-02-10 14:01:27 -0700 | [diff] [blame] | 2624 | |
| 2625 | bool PreCallValidateCmdFillBuffer(layer_data *device_data, GLOBAL_CB_NODE *cb_node, BUFFER_STATE *buffer_state) { |
| 2626 | bool skip = false; |
| 2627 | skip |= ValidateMemoryIsBoundToBuffer(device_data, buffer_state, "vkCmdFillBuffer()", VALIDATION_ERROR_02529); |
| 2628 | skip |= ValidateCmd(device_data, cb_node, CMD_FILLBUFFER, "vkCmdFillBuffer()"); |
| 2629 | // Validate that DST buffer has correct usage flags set |
| 2630 | skip |= ValidateBufferUsageFlags(device_data, buffer_state, VK_BUFFER_USAGE_TRANSFER_DST_BIT, true, VALIDATION_ERROR_01137, |
| 2631 | "vkCmdFillBuffer()", "VK_BUFFER_USAGE_TRANSFER_DST_BIT"); |
| 2632 | skip |= insideRenderPass(device_data, cb_node, "vkCmdFillBuffer()", VALIDATION_ERROR_01142); |
| 2633 | return skip; |
| 2634 | } |
| 2635 | |
| 2636 | void PreCallRecordCmdFillBuffer(layer_data *device_data, GLOBAL_CB_NODE *cb_node, BUFFER_STATE *buffer_state) { |
| 2637 | std::function<bool()> function = [=]() { |
| 2638 | SetBufferMemoryValid(device_data, buffer_state, true); |
| 2639 | return false; |
| 2640 | }; |
| 2641 | cb_node->validate_functions.push_back(function); |
| 2642 | // Update bindings between buffer and cmd buffer |
| 2643 | AddCommandBufferBindingBuffer(device_data, cb_node, buffer_state); |
| 2644 | core_validation::UpdateCmdBufferLastCmd(cb_node, CMD_FILLBUFFER); |
| 2645 | } |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 2646 | |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 2647 | bool ValidateBufferImageCopyData(const debug_report_data *report_data, uint32_t regionCount, const VkBufferImageCopy *pRegions, |
| 2648 | IMAGE_STATE *image_state, const char *function) { |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 2649 | bool skip = false; |
| 2650 | |
| 2651 | for (uint32_t i = 0; i < regionCount; i++) { |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 2652 | if (image_state->createInfo.imageType == VK_IMAGE_TYPE_1D) { |
| 2653 | if ((pRegions[i].imageOffset.y != 0) || (pRegions[i].imageExtent.height != 1)) { |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 2654 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 2655 | reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01746, "IMAGE", |
| 2656 | "%s(): pRegion[%d] imageOffset.y is %d and imageExtent.height is %d. For 1D images these " |
| 2657 | "must be 0 and 1, respectively. %s", |
| 2658 | function, i, pRegions[i].imageOffset.y, pRegions[i].imageExtent.height, |
| 2659 | validation_error_map[VALIDATION_ERROR_01746]); |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 2660 | } |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 2661 | } |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 2662 | |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 2663 | if ((image_state->createInfo.imageType == VK_IMAGE_TYPE_1D) || (image_state->createInfo.imageType == VK_IMAGE_TYPE_2D)) { |
| 2664 | if ((pRegions[i].imageOffset.z != 0) || (pRegions[i].imageExtent.depth != 1)) { |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 2665 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 2666 | reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01747, "IMAGE", |
| 2667 | "%s(): pRegion[%d] imageOffset.z is %d and imageExtent.depth is %d. For 1D and 2D images these " |
| 2668 | "must be 0 and 1, respectively. %s", |
| 2669 | function, i, pRegions[i].imageOffset.z, pRegions[i].imageExtent.depth, |
| 2670 | validation_error_map[VALIDATION_ERROR_01747]); |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 2671 | } |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 2672 | } |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 2673 | |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 2674 | if (image_state->createInfo.imageType == VK_IMAGE_TYPE_3D) { |
| 2675 | if ((0 != pRegions[i].imageSubresource.baseArrayLayer) || (1 != pRegions[i].imageSubresource.layerCount)) { |
| 2676 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 2677 | reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01281, "IMAGE", |
| 2678 | "%s(): pRegion[%d] imageSubresource.baseArrayLayer is %d and imageSubresource.layerCount is " |
| 2679 | "%d. For 3D images these must be 0 and 1, respectively. %s", |
| 2680 | function, i, pRegions[i].imageSubresource.baseArrayLayer, pRegions[i].imageSubresource.layerCount, |
| 2681 | validation_error_map[VALIDATION_ERROR_01281]); |
| 2682 | } |
| 2683 | } |
| 2684 | |
| 2685 | // If the the calling command's VkImage parameter's format is not a depth/stencil format, |
| 2686 | // then bufferOffset must be a multiple of the calling command's VkImage parameter's texel size |
| 2687 | auto texel_size = vk_format_get_size(image_state->createInfo.format); |
| 2688 | if (!vk_format_is_depth_and_stencil(image_state->createInfo.format) && |
| 2689 | vk_safe_modulo(pRegions[i].bufferOffset, texel_size) != 0) { |
| 2690 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 2691 | reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01263, "IMAGE", |
| 2692 | "%s(): pRegion[%d] bufferOffset 0x%" PRIxLEAST64 |
| 2693 | " must be a multiple of this format's texel size (" PRINTF_SIZE_T_SPECIFIER "). %s", |
| 2694 | function, i, pRegions[i].bufferOffset, texel_size, validation_error_map[VALIDATION_ERROR_01263]); |
| 2695 | } |
| 2696 | |
| 2697 | // BufferOffset must be a multiple of 4 |
| 2698 | if (vk_safe_modulo(pRegions[i].bufferOffset, 4) != 0) { |
| 2699 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 2700 | reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01264, "IMAGE", |
| 2701 | "%s(): pRegion[%d] bufferOffset 0x%" PRIxLEAST64 " must be a multiple of 4. %s", function, i, |
| 2702 | pRegions[i].bufferOffset, validation_error_map[VALIDATION_ERROR_01264]); |
| 2703 | } |
| 2704 | |
| 2705 | // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent |
| 2706 | if ((pRegions[i].bufferRowLength != 0) && (pRegions[i].bufferRowLength < pRegions[i].imageExtent.width)) { |
| 2707 | skip |= log_msg( |
| 2708 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 2709 | reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01265, "IMAGE", |
| 2710 | "%s(): pRegion[%d] bufferRowLength (%d) must be zero or greater-than-or-equal-to imageExtent.width (%d). %s", |
| 2711 | function, i, pRegions[i].bufferRowLength, pRegions[i].imageExtent.width, |
| 2712 | validation_error_map[VALIDATION_ERROR_01265]); |
| 2713 | } |
| 2714 | |
| 2715 | // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent |
| 2716 | if ((pRegions[i].bufferImageHeight != 0) && (pRegions[i].bufferImageHeight < pRegions[i].imageExtent.height)) { |
| 2717 | skip |= log_msg( |
| 2718 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 2719 | reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01266, "IMAGE", |
| 2720 | "%s(): pRegion[%d] bufferImageHeight (%d) must be zero or greater-than-or-equal-to imageExtent.height (%d). %s", |
| 2721 | function, i, pRegions[i].bufferImageHeight, pRegions[i].imageExtent.height, |
| 2722 | validation_error_map[VALIDATION_ERROR_01266]); |
| 2723 | } |
| 2724 | |
| 2725 | // subresource aspectMask must have exactly 1 bit set |
| 2726 | const int num_bits = sizeof(VkFlags) * CHAR_BIT; |
| 2727 | std::bitset<num_bits> aspect_mask_bits(pRegions[i].imageSubresource.aspectMask); |
| 2728 | if (aspect_mask_bits.count() != 1) { |
| 2729 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 2730 | reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01280, "IMAGE", |
| 2731 | "%s: aspectMasks for imageSubresource in each region must have only a single bit set. %s", function, |
| 2732 | validation_error_map[VALIDATION_ERROR_01280]); |
| 2733 | } |
| 2734 | |
| 2735 | // image subresource aspect bit must match format |
Dave Houlton | 4eaaf3a | 2017-03-14 11:31:20 -0600 | [diff] [blame] | 2736 | if (!VerifyAspectsPresent(pRegions[i].imageSubresource.aspectMask, image_state->createInfo.format)) { |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 2737 | skip |= log_msg( |
| 2738 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 2739 | reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01279, "IMAGE", |
| 2740 | "%s(): pRegion[%d] subresource aspectMask 0x%x specifies aspects that are not present in image format 0x%x. %s", |
| 2741 | function, i, pRegions[i].imageSubresource.aspectMask, image_state->createInfo.format, |
| 2742 | validation_error_map[VALIDATION_ERROR_01279]); |
| 2743 | } |
| 2744 | |
| 2745 | // Checks that apply only to compressed images |
| 2746 | // TODO: there is a comment in ValidateCopyBufferImageTransferGranularityRequirements() in core_validation.cpp that |
| 2747 | // reserves a place for these compressed image checks. This block of code could move there once the image |
| 2748 | // stuff is moved into core validation. |
| 2749 | if (vk_format_is_compressed(image_state->createInfo.format)) { |
| 2750 | auto block_size = vk_format_compressed_texel_block_extents(image_state->createInfo.format); |
| 2751 | |
| 2752 | // BufferRowLength must be a multiple of block width |
| 2753 | if (vk_safe_modulo(pRegions[i].bufferRowLength, block_size.width) != 0) { |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 2754 | skip |= log_msg( |
| 2755 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 2756 | reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01271, "IMAGE", |
| 2757 | "%s(): pRegion[%d] bufferRowLength (%d) must be a multiple of the compressed image's texel width (%d). %s.", |
| 2758 | function, i, pRegions[i].bufferRowLength, block_size.width, validation_error_map[VALIDATION_ERROR_01271]); |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 2759 | } |
| 2760 | |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 2761 | // BufferRowHeight must be a multiple of block height |
| 2762 | if (vk_safe_modulo(pRegions[i].bufferImageHeight, block_size.height) != 0) { |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 2763 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 2764 | reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01272, "IMAGE", |
| 2765 | "%s(): pRegion[%d] bufferImageHeight (%d) must be a multiple of the compressed image's texel " |
| 2766 | "height (%d). %s.", |
| 2767 | function, i, pRegions[i].bufferImageHeight, block_size.height, |
| 2768 | validation_error_map[VALIDATION_ERROR_01272]); |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 2769 | } |
| 2770 | |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 2771 | // image offsets must be multiples of block dimensions |
| 2772 | if ((vk_safe_modulo(pRegions[i].imageOffset.x, block_size.width) != 0) || |
Dave Houlton | 75967fc | 2017-03-06 17:21:16 -0700 | [diff] [blame] | 2773 | (vk_safe_modulo(pRegions[i].imageOffset.y, block_size.height) != 0) || |
| 2774 | (vk_safe_modulo(pRegions[i].imageOffset.z, block_size.depth) != 0)) { |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 2775 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 2776 | reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01273, "IMAGE", |
| 2777 | "%s(): pRegion[%d] imageOffset(x,y) (%d, %d) must be multiples of the compressed image's texel " |
| 2778 | "width & height (%d, %d). %s.", |
| 2779 | function, i, pRegions[i].imageOffset.x, pRegions[i].imageOffset.y, block_size.width, |
| 2780 | block_size.height, validation_error_map[VALIDATION_ERROR_01273]); |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 2781 | } |
| 2782 | |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 2783 | // bufferOffset must be a multiple of block size (linear bytes) |
| 2784 | size_t block_size_in_bytes = vk_format_get_size(image_state->createInfo.format); |
| 2785 | if (vk_safe_modulo(pRegions[i].bufferOffset, block_size_in_bytes) != 0) { |
| 2786 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 2787 | reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01274, "IMAGE", |
| 2788 | "%s(): pRegion[%d] bufferOffset (0x%" PRIxLEAST64 |
| 2789 | ") must be a multiple of the compressed image's texel block " |
| 2790 | "size (" PRINTF_SIZE_T_SPECIFIER "). %s.", |
| 2791 | function, i, pRegions[i].bufferOffset, block_size_in_bytes, |
| 2792 | validation_error_map[VALIDATION_ERROR_01274]); |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 2793 | } |
Dave Houlton | 67e9b53 | 2017-03-02 17:00:10 -0700 | [diff] [blame] | 2794 | |
| 2795 | // imageExtent width must be a multiple of block width, or extent+offset width must equal subresource width |
Dave Houlton | 75967fc | 2017-03-06 17:21:16 -0700 | [diff] [blame] | 2796 | VkExtent3D mip_extent = GetImageSubresourceExtent(image_state, &(pRegions[i].imageSubresource)); |
Dave Houlton | 67e9b53 | 2017-03-02 17:00:10 -0700 | [diff] [blame] | 2797 | if ((vk_safe_modulo(pRegions[i].imageExtent.width, block_size.width) != 0) && |
Dave Houlton | 75967fc | 2017-03-06 17:21:16 -0700 | [diff] [blame] | 2798 | (pRegions[i].imageExtent.width + pRegions[i].imageOffset.x != mip_extent.width)) { |
| 2799 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 2800 | reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01275, "IMAGE", |
| 2801 | "%s(): pRegion[%d] extent width (%d) must be a multiple of the compressed texture block width " |
| 2802 | "(%d), or when added to offset.x (%d) must equal the image subresource width (%d). %s.", |
| 2803 | function, i, pRegions[i].imageExtent.width, block_size.width, pRegions[i].imageOffset.x, |
| 2804 | mip_extent.width, validation_error_map[VALIDATION_ERROR_01275]); |
Dave Houlton | 67e9b53 | 2017-03-02 17:00:10 -0700 | [diff] [blame] | 2805 | } |
| 2806 | |
| 2807 | // imageExtent height must be a multiple of block height, or extent+offset height must equal subresource height |
| 2808 | if ((vk_safe_modulo(pRegions[i].imageExtent.height, block_size.height) != 0) && |
Dave Houlton | 75967fc | 2017-03-06 17:21:16 -0700 | [diff] [blame] | 2809 | (pRegions[i].imageExtent.height + pRegions[i].imageOffset.y != mip_extent.height)) { |
| 2810 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 2811 | reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01276, "IMAGE", |
| 2812 | "%s(): pRegion[%d] extent height (%d) must be a multiple of the compressed texture block height " |
| 2813 | "(%d), or when added to offset.y (%d) must equal the image subresource height (%d). %s.", |
| 2814 | function, i, pRegions[i].imageExtent.height, block_size.height, pRegions[i].imageOffset.y, |
| 2815 | mip_extent.height, validation_error_map[VALIDATION_ERROR_01276]); |
Dave Houlton | 67e9b53 | 2017-03-02 17:00:10 -0700 | [diff] [blame] | 2816 | } |
| 2817 | |
| 2818 | // imageExtent depth must be a multiple of block depth, or extent+offset depth must equal subresource depth |
| 2819 | if ((vk_safe_modulo(pRegions[i].imageExtent.depth, block_size.depth) != 0) && |
Dave Houlton | 75967fc | 2017-03-06 17:21:16 -0700 | [diff] [blame] | 2820 | (pRegions[i].imageExtent.depth + pRegions[i].imageOffset.z != mip_extent.depth)) { |
| 2821 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 2822 | reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01277, "IMAGE", |
| 2823 | "%s(): pRegion[%d] extent width (%d) must be a multiple of the compressed texture block depth " |
| 2824 | "(%d), or when added to offset.z (%d) must equal the image subresource depth (%d). %s.", |
| 2825 | function, i, pRegions[i].imageExtent.depth, block_size.depth, pRegions[i].imageOffset.z, |
| 2826 | mip_extent.depth, validation_error_map[VALIDATION_ERROR_01277]); |
Dave Houlton | 67e9b53 | 2017-03-02 17:00:10 -0700 | [diff] [blame] | 2827 | } |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 2828 | } |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 2829 | } |
| 2830 | |
| 2831 | return skip; |
| 2832 | } |
| 2833 | |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 2834 | static bool ValidateImageBounds(const debug_report_data *report_data, const IMAGE_STATE *image_state, const uint32_t regionCount, |
| 2835 | const VkBufferImageCopy *pRegions, const char *func_name, UNIQUE_VALIDATION_ERROR_CODE msg_code) { |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 2836 | bool skip = false; |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 2837 | const VkImageCreateInfo *image_info = &(image_state->createInfo); |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 2838 | |
| 2839 | for (uint32_t i = 0; i < regionCount; i++) { |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 2840 | VkExtent3D extent = pRegions[i].imageExtent; |
| 2841 | VkOffset3D offset = pRegions[i].imageOffset; |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 2842 | |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 2843 | if (IsExtentSizeZero(&extent)) // Warn on zero area subresource |
| 2844 | { |
| 2845 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 2846 | (uint64_t)0, __LINE__, IMAGE_ZERO_AREA_SUBREGION, "IMAGE", |
| 2847 | "%s: pRegion[%d] imageExtent of {%1d, %1d, %1d} has zero area", func_name, i, extent.width, |
| 2848 | extent.height, extent.depth); |
| 2849 | } |
| 2850 | |
| 2851 | VkExtent3D image_extent = GetImageSubresourceExtent(image_state, &(pRegions[i].imageSubresource)); |
| 2852 | |
| 2853 | // If we're using a compressed format, valid extent is rounded up to multiple of block size (per 18.1) |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 2854 | if (vk_format_is_compressed(image_info->format)) { |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 2855 | auto block_extent = vk_format_compressed_texel_block_extents(image_info->format); |
| 2856 | if (image_extent.width % block_extent.width) { |
| 2857 | image_extent.width += (block_extent.width - (image_extent.width % block_extent.width)); |
| 2858 | } |
| 2859 | if (image_extent.height % block_extent.height) { |
| 2860 | image_extent.height += (block_extent.height - (image_extent.height % block_extent.height)); |
| 2861 | } |
| 2862 | if (image_extent.depth % block_extent.depth) { |
| 2863 | image_extent.depth += (block_extent.depth - (image_extent.depth % block_extent.depth)); |
| 2864 | } |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 2865 | } |
| 2866 | |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 2867 | if (ExceedsBounds(&offset, &extent, &image_extent)) { |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 2868 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)0, |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 2869 | __LINE__, msg_code, "IMAGE", "%s: pRegion[%d] exceeds image bounds. %s.", func_name, i, |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 2870 | validation_error_map[msg_code]); |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 2871 | } |
| 2872 | } |
| 2873 | |
| 2874 | return skip; |
| 2875 | } |
| 2876 | |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 2877 | static inline bool ValidtateBufferBounds(const debug_report_data *report_data, IMAGE_STATE *image_state, BUFFER_STATE *buff_state, |
| 2878 | uint32_t regionCount, const VkBufferImageCopy *pRegions, const char *func_name, |
| 2879 | UNIQUE_VALIDATION_ERROR_CODE msg_code) { |
| 2880 | bool skip = false; |
| 2881 | |
| 2882 | VkDeviceSize buffer_size = buff_state->createInfo.size; |
| 2883 | |
| 2884 | for (uint32_t i = 0; i < regionCount; i++) { |
| 2885 | VkExtent3D copy_extent = pRegions[i].imageExtent; |
| 2886 | |
| 2887 | VkDeviceSize buffer_width = (0 == pRegions[i].bufferRowLength ? copy_extent.width : pRegions[i].bufferRowLength); |
| 2888 | VkDeviceSize buffer_height = (0 == pRegions[i].bufferImageHeight ? copy_extent.height : pRegions[i].bufferImageHeight); |
| 2889 | VkDeviceSize unit_size = vk_format_get_size(image_state->createInfo.format); // size (bytes) of texel or block |
| 2890 | |
Dave Houlton | f3229d5 | 2017-02-21 15:59:08 -0700 | [diff] [blame] | 2891 | // Handle special buffer packing rules for specific depth/stencil formats |
| 2892 | if (pRegions[i].imageSubresource.aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) { |
| 2893 | unit_size = vk_format_get_size(VK_FORMAT_S8_UINT); |
| 2894 | } else if (pRegions[i].imageSubresource.aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) { |
| 2895 | switch (image_state->createInfo.format) { |
| 2896 | case VK_FORMAT_D16_UNORM_S8_UINT: |
| 2897 | unit_size = vk_format_get_size(VK_FORMAT_D16_UNORM); |
| 2898 | break; |
| 2899 | case VK_FORMAT_D32_SFLOAT_S8_UINT: |
| 2900 | unit_size = vk_format_get_size(VK_FORMAT_D32_SFLOAT); |
| 2901 | break; |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 2902 | case VK_FORMAT_X8_D24_UNORM_PACK32: // Fall through |
Dave Houlton | f3229d5 | 2017-02-21 15:59:08 -0700 | [diff] [blame] | 2903 | case VK_FORMAT_D24_UNORM_S8_UINT: |
| 2904 | unit_size = 4; |
| 2905 | break; |
| 2906 | default: |
| 2907 | break; |
| 2908 | } |
| 2909 | } |
| 2910 | |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 2911 | if (vk_format_is_compressed(image_state->createInfo.format)) { |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 2912 | // Switch to texel block units, rounding up for any partially-used blocks |
| 2913 | auto block_dim = vk_format_compressed_texel_block_extents(image_state->createInfo.format); |
| 2914 | buffer_width = (buffer_width + block_dim.width - 1) / block_dim.width; |
| 2915 | buffer_height = (buffer_height + block_dim.height - 1) / block_dim.height; |
| 2916 | |
| 2917 | copy_extent.width = (copy_extent.width + block_dim.width - 1) / block_dim.width; |
| 2918 | copy_extent.height = (copy_extent.height + block_dim.height - 1) / block_dim.height; |
| 2919 | copy_extent.depth = (copy_extent.depth + block_dim.depth - 1) / block_dim.depth; |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 2920 | } |
| 2921 | |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 2922 | // Either depth or layerCount may be greater than 1 (not both). This is the number of 'slices' to copy |
| 2923 | uint32_t z_copies = std::max(copy_extent.depth, pRegions[i].imageSubresource.layerCount); |
| 2924 | if (IsExtentSizeZero(©_extent) || (0 == z_copies)) { |
| 2925 | // TODO: Issure warning here? Already warned in ValidateImageBounds()... |
| 2926 | } else { |
| 2927 | // Calculate buffer offset of final copied byte, + 1. |
| 2928 | VkDeviceSize max_buffer_offset = (z_copies - 1) * buffer_height * buffer_width; // offset to slice |
| 2929 | max_buffer_offset += ((copy_extent.height - 1) * buffer_width) + copy_extent.width; // add row,col |
| 2930 | max_buffer_offset *= unit_size; // convert to bytes |
| 2931 | max_buffer_offset += pRegions[i].bufferOffset; // add initial offset (bytes) |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 2932 | |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 2933 | if (buffer_size < max_buffer_offset) { |
| 2934 | skip |= |
| 2935 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)0, |
| 2936 | __LINE__, msg_code, "IMAGE", "%s: pRegion[%d] exceeds buffer size of %" PRIu64 " bytes. %s.", func_name, |
| 2937 | i, buffer_size, validation_error_map[msg_code]); |
| 2938 | } |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 2939 | } |
| 2940 | } |
| 2941 | |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 2942 | return skip; |
| 2943 | } |
| 2944 | |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 2945 | bool PreCallValidateCmdCopyImageToBuffer(layer_data *device_data, VkImageLayout srcImageLayout, GLOBAL_CB_NODE *cb_node, |
Mark Lobodzinski | 1fe9b00 | 2017-02-15 14:11:12 -0700 | [diff] [blame] | 2946 | IMAGE_STATE *src_image_state, BUFFER_STATE *dst_buffer_state, uint32_t regionCount, |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 2947 | const VkBufferImageCopy *pRegions, const char *func_name) { |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 2948 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 2949 | bool skip = ValidateBufferImageCopyData(report_data, regionCount, pRegions, src_image_state, "vkCmdCopyImageToBuffer"); |
| 2950 | |
| 2951 | // Validate command buffer state |
| 2952 | if (CB_RECORDING != cb_node->state) { |
| 2953 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 2954 | (uint64_t)cb_node->commandBuffer, __LINE__, VALIDATION_ERROR_01258, "DS", |
| 2955 | "Cannot call vkCmdCopyImageToBuffer() on command buffer which is not in recording state. %s.", |
| 2956 | validation_error_map[VALIDATION_ERROR_01258]); |
| 2957 | } else { |
| 2958 | skip |= ValidateCmdSubpassState(device_data, cb_node, CMD_COPYIMAGETOBUFFER); |
| 2959 | } |
| 2960 | |
| 2961 | // Command pool must support graphics, compute, or transfer operations |
| 2962 | auto pPool = GetCommandPoolNode(device_data, cb_node->createInfo.commandPool); |
| 2963 | |
| 2964 | VkQueueFlags queue_flags = GetPhysDevProperties(device_data)->queue_family_properties[pPool->queueFamilyIndex].queueFlags; |
| 2965 | if (0 == (queue_flags & (VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT | VK_QUEUE_TRANSFER_BIT))) { |
| 2966 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 2967 | (uint64_t)cb_node->createInfo.commandPool, __LINE__, VALIDATION_ERROR_01259, "DS", |
| 2968 | "Cannot call vkCmdCopyImageToBuffer() on a command buffer allocated from a pool without graphics, compute, " |
| 2969 | "or transfer capabilities. %s.", |
| 2970 | validation_error_map[VALIDATION_ERROR_01259]); |
| 2971 | } |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 2972 | skip |= ValidateImageBounds(report_data, src_image_state, regionCount, pRegions, "vkCmdCopyBufferToImage()", |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 2973 | VALIDATION_ERROR_01245); |
Mark Lobodzinski | 1fe9b00 | 2017-02-15 14:11:12 -0700 | [diff] [blame] | 2974 | skip |= ValidtateBufferBounds(report_data, src_image_state, dst_buffer_state, regionCount, pRegions, "vkCmdCopyImageToBuffer()", |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 2975 | VALIDATION_ERROR_01246); |
| 2976 | |
| 2977 | skip |= ValidateImageSampleCount(device_data, src_image_state, VK_SAMPLE_COUNT_1_BIT, "vkCmdCopyImageToBuffer(): srcImage", |
| 2978 | VALIDATION_ERROR_01249); |
| 2979 | skip |= ValidateMemoryIsBoundToImage(device_data, src_image_state, "vkCmdCopyImageToBuffer()", VALIDATION_ERROR_02537); |
Mark Lobodzinski | 1fe9b00 | 2017-02-15 14:11:12 -0700 | [diff] [blame] | 2980 | skip |= ValidateMemoryIsBoundToBuffer(device_data, dst_buffer_state, "vkCmdCopyImageToBuffer()", VALIDATION_ERROR_02538); |
Mark Lobodzinski | 033c90b | 2017-02-15 13:58:23 -0700 | [diff] [blame] | 2981 | |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 2982 | // Validate that SRC image & DST buffer have correct usage flags set |
| 2983 | skip |= ValidateImageUsageFlags(device_data, src_image_state, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, true, VALIDATION_ERROR_01248, |
| 2984 | "vkCmdCopyImageToBuffer()", "VK_IMAGE_USAGE_TRANSFER_SRC_BIT"); |
Mark Lobodzinski | 1fe9b00 | 2017-02-15 14:11:12 -0700 | [diff] [blame] | 2985 | skip |= ValidateBufferUsageFlags(device_data, dst_buffer_state, VK_BUFFER_USAGE_TRANSFER_DST_BIT, true, VALIDATION_ERROR_01252, |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 2986 | "vkCmdCopyImageToBuffer()", "VK_BUFFER_USAGE_TRANSFER_DST_BIT"); |
Mark Lobodzinski | 033c90b | 2017-02-15 13:58:23 -0700 | [diff] [blame] | 2987 | skip |= insideRenderPass(device_data, cb_node, "vkCmdCopyImageToBuffer()", VALIDATION_ERROR_01260); |
| 2988 | for (uint32_t i = 0; i < regionCount; ++i) { |
| 2989 | skip |= VerifySourceImageLayout(device_data, cb_node, src_image_state->image, pRegions[i].imageSubresource, srcImageLayout, |
| 2990 | VALIDATION_ERROR_01251); |
| 2991 | skip |= ValidateCopyBufferImageTransferGranularityRequirements(device_data, cb_node, src_image_state, &pRegions[i], i, |
| 2992 | "CmdCopyImageToBuffer"); |
| 2993 | } |
| 2994 | return skip; |
| 2995 | } |
| 2996 | |
| 2997 | void PreCallRecordCmdCopyImageToBuffer(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state, |
Mark Lobodzinski | 1fe9b00 | 2017-02-15 14:11:12 -0700 | [diff] [blame] | 2998 | BUFFER_STATE *dst_buffer_state) { |
Mark Lobodzinski | 033c90b | 2017-02-15 13:58:23 -0700 | [diff] [blame] | 2999 | // Update bindings between buffer/image and cmd buffer |
| 3000 | AddCommandBufferBindingImage(device_data, cb_node, src_image_state); |
Mark Lobodzinski | 1fe9b00 | 2017-02-15 14:11:12 -0700 | [diff] [blame] | 3001 | AddCommandBufferBindingBuffer(device_data, cb_node, dst_buffer_state); |
Mark Lobodzinski | 033c90b | 2017-02-15 13:58:23 -0700 | [diff] [blame] | 3002 | |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 3003 | std::function<bool()> function = [=]() { |
| 3004 | return ValidateImageMemoryIsValid(device_data, src_image_state, "vkCmdCopyImageToBuffer()"); |
| 3005 | }; |
| 3006 | cb_node->validate_functions.push_back(function); |
| 3007 | function = [=]() { |
Mark Lobodzinski | 1fe9b00 | 2017-02-15 14:11:12 -0700 | [diff] [blame] | 3008 | SetBufferMemoryValid(device_data, dst_buffer_state, true); |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 3009 | return false; |
| 3010 | }; |
| 3011 | cb_node->validate_functions.push_back(function); |
| 3012 | |
| 3013 | core_validation::UpdateCmdBufferLastCmd(cb_node, CMD_COPYIMAGETOBUFFER); |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 3014 | } |
| 3015 | |
| 3016 | bool PreCallValidateCmdCopyBufferToImage(layer_data *device_data, VkImageLayout dstImageLayout, GLOBAL_CB_NODE *cb_node, |
Mark Lobodzinski | 1fe9b00 | 2017-02-15 14:11:12 -0700 | [diff] [blame] | 3017 | BUFFER_STATE *src_buffer_state, IMAGE_STATE *dst_image_state, uint32_t regionCount, |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 3018 | const VkBufferImageCopy *pRegions, const char *func_name) { |
| 3019 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 3020 | bool skip = ValidateBufferImageCopyData(report_data, regionCount, pRegions, dst_image_state, "vkCmdCopyBufferToImage"); |
| 3021 | |
| 3022 | // Validate command buffer state |
| 3023 | if (CB_RECORDING != cb_node->state) { |
| 3024 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 3025 | (uint64_t)cb_node->commandBuffer, __LINE__, VALIDATION_ERROR_01240, "DS", |
| 3026 | "Cannot call vkCmdCopyBufferToImage() on command buffer which is not in recording state. %s.", |
| 3027 | validation_error_map[VALIDATION_ERROR_01240]); |
| 3028 | } else { |
| 3029 | skip |= ValidateCmdSubpassState(device_data, cb_node, CMD_COPYBUFFERTOIMAGE); |
| 3030 | } |
| 3031 | |
| 3032 | // Command pool must support graphics, compute, or transfer operations |
| 3033 | auto pPool = GetCommandPoolNode(device_data, cb_node->createInfo.commandPool); |
| 3034 | VkQueueFlags queue_flags = GetPhysDevProperties(device_data)->queue_family_properties[pPool->queueFamilyIndex].queueFlags; |
| 3035 | if (0 == (queue_flags & (VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT | VK_QUEUE_TRANSFER_BIT))) { |
| 3036 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 3037 | (uint64_t)cb_node->createInfo.commandPool, __LINE__, VALIDATION_ERROR_01241, "DS", |
| 3038 | "Cannot call vkCmdCopyBufferToImage() on a command buffer allocated from a pool without graphics, compute, " |
| 3039 | "or transfer capabilities. %s.", |
| 3040 | validation_error_map[VALIDATION_ERROR_01241]); |
| 3041 | } |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3042 | skip |= ValidateImageBounds(report_data, dst_image_state, regionCount, pRegions, "vkCmdCopyBufferToImage()", |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 3043 | VALIDATION_ERROR_01228); |
Mark Lobodzinski | 1fe9b00 | 2017-02-15 14:11:12 -0700 | [diff] [blame] | 3044 | skip |= ValidtateBufferBounds(report_data, dst_image_state, src_buffer_state, regionCount, pRegions, "vkCmdCopyBufferToImage()", |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 3045 | VALIDATION_ERROR_01227); |
| 3046 | skip |= ValidateImageSampleCount(device_data, dst_image_state, VK_SAMPLE_COUNT_1_BIT, "vkCmdCopyBufferToImage(): dstImage", |
| 3047 | VALIDATION_ERROR_01232); |
Mark Lobodzinski | 1fe9b00 | 2017-02-15 14:11:12 -0700 | [diff] [blame] | 3048 | skip |= ValidateMemoryIsBoundToBuffer(device_data, src_buffer_state, "vkCmdCopyBufferToImage()", VALIDATION_ERROR_02535); |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 3049 | skip |= ValidateMemoryIsBoundToImage(device_data, dst_image_state, "vkCmdCopyBufferToImage()", VALIDATION_ERROR_02536); |
Mark Lobodzinski | 1fe9b00 | 2017-02-15 14:11:12 -0700 | [diff] [blame] | 3050 | skip |= ValidateBufferUsageFlags(device_data, src_buffer_state, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, true, VALIDATION_ERROR_01230, |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 3051 | "vkCmdCopyBufferToImage()", "VK_BUFFER_USAGE_TRANSFER_SRC_BIT"); |
| 3052 | skip |= ValidateImageUsageFlags(device_data, dst_image_state, VK_IMAGE_USAGE_TRANSFER_DST_BIT, true, VALIDATION_ERROR_01231, |
| 3053 | "vkCmdCopyBufferToImage()", "VK_IMAGE_USAGE_TRANSFER_DST_BIT"); |
Mark Lobodzinski | 033c90b | 2017-02-15 13:58:23 -0700 | [diff] [blame] | 3054 | skip |= insideRenderPass(device_data, cb_node, "vkCmdCopyBufferToImage()", VALIDATION_ERROR_01242); |
| 3055 | for (uint32_t i = 0; i < regionCount; ++i) { |
| 3056 | skip |= VerifyDestImageLayout(device_data, cb_node, dst_image_state->image, pRegions[i].imageSubresource, dstImageLayout, |
| 3057 | VALIDATION_ERROR_01234); |
| 3058 | skip |= ValidateCopyBufferImageTransferGranularityRequirements(device_data, cb_node, dst_image_state, &pRegions[i], i, |
| 3059 | "vkCmdCopyBufferToImage()"); |
| 3060 | } |
| 3061 | return skip; |
| 3062 | } |
| 3063 | |
Mark Lobodzinski | 1fe9b00 | 2017-02-15 14:11:12 -0700 | [diff] [blame] | 3064 | void PreCallRecordCmdCopyBufferToImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, BUFFER_STATE *src_buffer_state, |
Mark Lobodzinski | 033c90b | 2017-02-15 13:58:23 -0700 | [diff] [blame] | 3065 | IMAGE_STATE *dst_image_state) { |
Mark Lobodzinski | 1fe9b00 | 2017-02-15 14:11:12 -0700 | [diff] [blame] | 3066 | AddCommandBufferBindingBuffer(device_data, cb_node, src_buffer_state); |
Mark Lobodzinski | 033c90b | 2017-02-15 13:58:23 -0700 | [diff] [blame] | 3067 | AddCommandBufferBindingImage(device_data, cb_node, dst_image_state); |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 3068 | std::function<bool()> function = [=]() { |
| 3069 | SetImageMemoryValid(device_data, dst_image_state, true); |
| 3070 | return false; |
| 3071 | }; |
| 3072 | cb_node->validate_functions.push_back(function); |
Mark Lobodzinski | 1fe9b00 | 2017-02-15 14:11:12 -0700 | [diff] [blame] | 3073 | function = [=]() { return ValidateBufferMemoryIsValid(device_data, src_buffer_state, "vkCmdCopyBufferToImage()"); }; |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 3074 | cb_node->validate_functions.push_back(function); |
| 3075 | |
| 3076 | core_validation::UpdateCmdBufferLastCmd(cb_node, CMD_COPYBUFFERTOIMAGE); |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 3077 | } |
Mike Weiblen | 672b58b | 2017-02-21 14:32:53 -0700 | [diff] [blame] | 3078 | |
| 3079 | bool PreCallValidateGetImageSubresourceLayout(layer_data *device_data, VkImage image, const VkImageSubresource *pSubresource) { |
| 3080 | const auto report_data = core_validation::GetReportData(device_data); |
| 3081 | bool skip = false; |
| 3082 | const VkImageAspectFlags sub_aspect = pSubresource->aspectMask; |
| 3083 | |
| 3084 | // VU 00733: The aspectMask member of pSubresource must only have a single bit set |
| 3085 | const int num_bits = sizeof(sub_aspect) * CHAR_BIT; |
| 3086 | std::bitset<num_bits> aspect_mask_bits(sub_aspect); |
| 3087 | if (aspect_mask_bits.count() != 1) { |
| 3088 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, |
| 3089 | VALIDATION_ERROR_00733, "IMAGE", |
| 3090 | "vkGetImageSubresourceLayout(): VkImageSubresource.aspectMask must have exactly 1 bit set. %s", |
| 3091 | validation_error_map[VALIDATION_ERROR_00733]); |
| 3092 | } |
| 3093 | |
| 3094 | IMAGE_STATE *image_entry = GetImageState(device_data, image); |
| 3095 | if (!image_entry) { |
| 3096 | return skip; |
| 3097 | } |
| 3098 | |
| 3099 | // VU 00732: image must have been created with tiling equal to VK_IMAGE_TILING_LINEAR |
| 3100 | if (image_entry->createInfo.tiling != VK_IMAGE_TILING_LINEAR) { |
| 3101 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, (uint64_t)image, |
| 3102 | __LINE__, VALIDATION_ERROR_00732, "IMAGE", |
| 3103 | "vkGetImageSubresourceLayout(): Image must have tiling of VK_IMAGE_TILING_LINEAR. %s", |
| 3104 | validation_error_map[VALIDATION_ERROR_00732]); |
| 3105 | } |
| 3106 | |
| 3107 | // VU 00739: mipLevel must be less than the mipLevels specified in VkImageCreateInfo when the image was created |
| 3108 | if (pSubresource->mipLevel >= image_entry->createInfo.mipLevels) { |
| 3109 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, (uint64_t)image, |
| 3110 | __LINE__, VALIDATION_ERROR_00739, "IMAGE", |
| 3111 | "vkGetImageSubresourceLayout(): pSubresource.mipLevel (%d) must be less than %d. %s", |
| 3112 | pSubresource->mipLevel, image_entry->createInfo.mipLevels, validation_error_map[VALIDATION_ERROR_00739]); |
| 3113 | } |
| 3114 | |
| 3115 | // VU 00740: arrayLayer must be less than the arrayLayers specified in VkImageCreateInfo when the image was created |
| 3116 | if (pSubresource->arrayLayer >= image_entry->createInfo.arrayLayers) { |
| 3117 | skip |= log_msg( |
| 3118 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, (uint64_t)image, __LINE__, |
| 3119 | VALIDATION_ERROR_00740, "IMAGE", "vkGetImageSubresourceLayout(): pSubresource.arrayLayer (%d) must be less than %d. %s", |
| 3120 | pSubresource->arrayLayer, image_entry->createInfo.arrayLayers, validation_error_map[VALIDATION_ERROR_00740]); |
| 3121 | } |
| 3122 | |
| 3123 | // VU 00741: subresource's aspect must be compatible with image's format. |
| 3124 | const VkFormat img_format = image_entry->createInfo.format; |
| 3125 | if (vk_format_is_color(img_format)) { |
| 3126 | if (sub_aspect != VK_IMAGE_ASPECT_COLOR_BIT) { |
| 3127 | skip |= log_msg( |
| 3128 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, (uint64_t)image, __LINE__, |
| 3129 | VALIDATION_ERROR_00741, "IMAGE", |
| 3130 | "vkGetImageSubresourceLayout(): For color formats, VkImageSubresource.aspectMask must be VK_IMAGE_ASPECT_COLOR. %s", |
| 3131 | validation_error_map[VALIDATION_ERROR_00741]); |
| 3132 | } |
| 3133 | } else if (vk_format_is_depth_or_stencil(img_format)) { |
| 3134 | if ((sub_aspect != VK_IMAGE_ASPECT_DEPTH_BIT) && (sub_aspect != VK_IMAGE_ASPECT_STENCIL_BIT)) { |
| 3135 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, (uint64_t)image, |
| 3136 | __LINE__, VALIDATION_ERROR_00741, "IMAGE", |
| 3137 | "vkGetImageSubresourceLayout(): For depth/stencil formats, VkImageSubresource.aspectMask must be " |
| 3138 | "either VK_IMAGE_ASPECT_DEPTH_BIT or VK_IMAGE_ASPECT_STENCIL_BIT. %s", |
| 3139 | validation_error_map[VALIDATION_ERROR_00741]); |
| 3140 | } |
| 3141 | } |
| 3142 | return skip; |
| 3143 | } |