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