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