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