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