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