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