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