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 | } |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 46 | } // namespace std |
Petr Kraus | 4d71868 | 2017-05-18 03:38:41 +0200 | [diff] [blame] | 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 | |
Tobin Ehlis | 9c0df96 | 2017-07-17 10:14:27 -0600 | [diff] [blame] | 354 | bool ValidateImageAspectLayout(layer_data *device_data, GLOBAL_CB_NODE const *pCB, const VkImageMemoryBarrier *mem_barrier, |
Mark Lobodzinski | 6b6c50a | 2017-02-27 12:56:14 -0700 | [diff] [blame] | 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) { |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 436 | msg_code = VALIDATION_ERROR_0a000970; |
Mike Weiblen | 62d08a3 | 2017-03-07 22:18:27 -0700 | [diff] [blame] | 437 | } |
| 438 | break; |
| 439 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: |
| 440 | if ((usage_flags & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) == 0) { |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 441 | msg_code = VALIDATION_ERROR_0a000972; |
Mike Weiblen | 62d08a3 | 2017-03-07 22:18:27 -0700 | [diff] [blame] | 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) { |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 446 | msg_code = VALIDATION_ERROR_0a000974; |
Mike Weiblen | 62d08a3 | 2017-03-07 22:18:27 -0700 | [diff] [blame] | 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) { |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 451 | msg_code = VALIDATION_ERROR_0a000976; |
Mike Weiblen | 62d08a3 | 2017-03-07 22:18:27 -0700 | [diff] [blame] | 452 | } |
| 453 | break; |
| 454 | case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL: |
| 455 | if ((usage_flags & VK_IMAGE_USAGE_TRANSFER_SRC_BIT) == 0) { |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 456 | msg_code = VALIDATION_ERROR_0a000978; |
Mike Weiblen | 62d08a3 | 2017-03-07 22:18:27 -0700 | [diff] [blame] | 457 | } |
| 458 | break; |
| 459 | case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL: |
| 460 | if ((usage_flags & VK_IMAGE_USAGE_TRANSFER_DST_BIT) == 0) { |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 461 | msg_code = VALIDATION_ERROR_0a00097a; |
Mike Weiblen | 62d08a3 | 2017-03-07 22:18:27 -0700 | [diff] [blame] | 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. |
Tobin Ehlis | 9c0df96 | 2017-07-17 10:14:27 -0600 | [diff] [blame] | 481 | bool ValidateBarriersToImages(layer_data *device_data, GLOBAL_CB_NODE const *cb_state, uint32_t imageMemoryBarrierCount, |
Mike Weiblen | 62d08a3 | 2017-03-07 22:18:27 -0700 | [diff] [blame] | 482 | const VkImageMemoryBarrier *pImageMemoryBarriers, const char *func_name) { |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 483 | bool skip = false; |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 484 | |
Mike Weiblen | 62d08a3 | 2017-03-07 22:18:27 -0700 | [diff] [blame] | 485 | for (uint32_t i = 0; i < imageMemoryBarrierCount; ++i) { |
| 486 | auto img_barrier = &pImageMemoryBarriers[i]; |
| 487 | if (!img_barrier) continue; |
| 488 | |
Tobin Ehlis | bb03e5f | 2017-05-11 08:52:51 -0600 | [diff] [blame] | 489 | auto image_state = GetImageState(device_data, img_barrier->image); |
| 490 | if (image_state) { |
| 491 | VkImageUsageFlags usage_flags = image_state->createInfo.usage; |
| 492 | skip |= ValidateBarrierLayoutToImageUsage(device_data, img_barrier, false, usage_flags, func_name); |
| 493 | skip |= ValidateBarrierLayoutToImageUsage(device_data, img_barrier, true, usage_flags, func_name); |
| 494 | |
| 495 | // Make sure layout is able to be transitioned, currently only presented shared presentable images are locked |
| 496 | if (image_state->layout_locked) { |
| 497 | // TODO: Add unique id for error when available |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 498 | skip |= log_msg( |
| 499 | core_validation::GetReportData(device_data), VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | bb03e5f | 2017-05-11 08:52:51 -0600 | [diff] [blame] | 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__, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 517 | VALIDATION_ERROR_0a00096e, "DS", |
| 518 | "%s: Image barrier 0x%p references image 0x%" PRIx64 |
| 519 | " of format %s that must have the depth and stencil aspects set, but its " |
| 520 | "aspectMask is 0x%" PRIx32 ". %s", |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 521 | func_name, img_barrier, HandleToUint64(img_barrier->image), string_VkFormat(image_create_info->format), |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 522 | aspect_mask, validation_error_map[VALIDATION_ERROR_0a00096e]); |
Tobin Ehlis | 7ee9cbd | 2017-04-26 16:51:48 -0600 | [diff] [blame] | 523 | } |
| 524 | } |
Mark Lobodzinski | 903e5ff | 2017-03-23 09:43:35 -0600 | [diff] [blame] | 525 | uint32_t level_count = ResolveRemainingLevels(&img_barrier->subresourceRange, image_create_info->mipLevels); |
| 526 | uint32_t layer_count = ResolveRemainingLayers(&img_barrier->subresourceRange, image_create_info->arrayLayers); |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 527 | |
Mike Weiblen | 62d08a3 | 2017-03-07 22:18:27 -0700 | [diff] [blame] | 528 | for (uint32_t j = 0; j < level_count; j++) { |
| 529 | uint32_t level = img_barrier->subresourceRange.baseMipLevel + j; |
| 530 | for (uint32_t k = 0; k < layer_count; k++) { |
| 531 | uint32_t layer = img_barrier->subresourceRange.baseArrayLayer + k; |
Tobin Ehlis | 9c0df96 | 2017-07-17 10:14:27 -0600 | [diff] [blame] | 532 | skip |= ValidateImageAspectLayout(device_data, cb_state, img_barrier, level, layer, VK_IMAGE_ASPECT_COLOR_BIT); |
| 533 | skip |= ValidateImageAspectLayout(device_data, cb_state, img_barrier, level, layer, VK_IMAGE_ASPECT_DEPTH_BIT); |
| 534 | skip |= ValidateImageAspectLayout(device_data, cb_state, img_barrier, level, layer, VK_IMAGE_ASPECT_STENCIL_BIT); |
| 535 | skip |= ValidateImageAspectLayout(device_data, cb_state, img_barrier, level, layer, VK_IMAGE_ASPECT_METADATA_BIT); |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 536 | } |
| 537 | } |
| 538 | } |
| 539 | return skip; |
| 540 | } |
| 541 | |
Mark Lobodzinski | 6b6c50a | 2017-02-27 12:56:14 -0700 | [diff] [blame] | 542 | void TransitionImageLayouts(layer_data *device_data, VkCommandBuffer cmdBuffer, uint32_t memBarrierCount, |
| 543 | const VkImageMemoryBarrier *pImgMemBarriers) { |
| 544 | GLOBAL_CB_NODE *pCB = GetCBNode(device_data, cmdBuffer); |
Mark Lobodzinski | 6b6c50a | 2017-02-27 12:56:14 -0700 | [diff] [blame] | 545 | |
| 546 | for (uint32_t i = 0; i < memBarrierCount; ++i) { |
| 547 | auto mem_barrier = &pImgMemBarriers[i]; |
| 548 | if (!mem_barrier) continue; |
Mark Lobodzinski | 6b6c50a | 2017-02-27 12:56:14 -0700 | [diff] [blame] | 549 | |
Mark Lobodzinski | 903e5ff | 2017-03-23 09:43:35 -0600 | [diff] [blame] | 550 | VkImageCreateInfo *image_create_info = &(GetImageState(device_data, mem_barrier->image)->createInfo); |
| 551 | uint32_t level_count = ResolveRemainingLevels(&mem_barrier->subresourceRange, image_create_info->mipLevels); |
| 552 | uint32_t layer_count = ResolveRemainingLayers(&mem_barrier->subresourceRange, image_create_info->arrayLayers); |
| 553 | |
| 554 | for (uint32_t j = 0; j < level_count; j++) { |
Mark Lobodzinski | 6b6c50a | 2017-02-27 12:56:14 -0700 | [diff] [blame] | 555 | uint32_t level = mem_barrier->subresourceRange.baseMipLevel + j; |
Mark Lobodzinski | 903e5ff | 2017-03-23 09:43:35 -0600 | [diff] [blame] | 556 | for (uint32_t k = 0; k < layer_count; k++) { |
Mark Lobodzinski | 6b6c50a | 2017-02-27 12:56:14 -0700 | [diff] [blame] | 557 | uint32_t layer = mem_barrier->subresourceRange.baseArrayLayer + k; |
| 558 | TransitionImageAspectLayout(device_data, pCB, mem_barrier, level, layer, VK_IMAGE_ASPECT_COLOR_BIT); |
| 559 | TransitionImageAspectLayout(device_data, pCB, mem_barrier, level, layer, VK_IMAGE_ASPECT_DEPTH_BIT); |
| 560 | TransitionImageAspectLayout(device_data, pCB, mem_barrier, level, layer, VK_IMAGE_ASPECT_STENCIL_BIT); |
| 561 | TransitionImageAspectLayout(device_data, pCB, mem_barrier, level, layer, VK_IMAGE_ASPECT_METADATA_BIT); |
| 562 | } |
| 563 | } |
| 564 | } |
| 565 | } |
| 566 | |
Tobin Ehlis | c826645 | 2017-04-07 12:20:30 -0600 | [diff] [blame] | 567 | 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] | 568 | VkImageSubresourceLayers subLayers, VkImageLayout explicit_layout, VkImageLayout optimal_layout, |
Tobin Ehlis | c826645 | 2017-04-07 12:20:30 -0600 | [diff] [blame] | 569 | const char *caller, UNIQUE_VALIDATION_ERROR_CODE msg_code, bool *error) { |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 570 | const auto report_data = core_validation::GetReportData(device_data); |
Tobin Ehlis | 2d85ec6 | 2017-03-14 15:38:48 -0600 | [diff] [blame] | 571 | const auto image = image_state->image; |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 572 | bool skip = false; |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 573 | |
| 574 | for (uint32_t i = 0; i < subLayers.layerCount; ++i) { |
| 575 | uint32_t layer = i + subLayers.baseArrayLayer; |
| 576 | VkImageSubresource sub = {subLayers.aspectMask, subLayers.mipLevel, layer}; |
| 577 | IMAGE_CMD_BUF_LAYOUT_NODE node; |
Tobin Ehlis | e35b66a | 2017-03-15 12:18:31 -0600 | [diff] [blame] | 578 | if (FindCmdBufLayout(device_data, cb_node, image, sub, node)) { |
| 579 | if (node.layout != explicit_layout) { |
Tobin Ehlis | c826645 | 2017-04-07 12:20:30 -0600 | [diff] [blame] | 580 | *error = true; |
Tobin Ehlis | e35b66a | 2017-03-15 12:18:31 -0600 | [diff] [blame] | 581 | // TODO: Improve log message in the next pass |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 582 | 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] | 583 | HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 584 | "%s: Cannot use image 0x%" PRIxLEAST64 |
| 585 | " 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] | 586 | caller, HandleToUint64(image), string_VkImageLayout(explicit_layout), |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 587 | string_VkImageLayout(node.layout)); |
Tobin Ehlis | e35b66a | 2017-03-15 12:18:31 -0600 | [diff] [blame] | 588 | } |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 589 | } |
| 590 | } |
Tobin Ehlis | 2d85ec6 | 2017-03-14 15:38:48 -0600 | [diff] [blame] | 591 | // If optimal_layout is not UNDEFINED, check that layout matches optimal for this case |
| 592 | if ((VK_IMAGE_LAYOUT_UNDEFINED != optimal_layout) && (explicit_layout != optimal_layout)) { |
| 593 | if (VK_IMAGE_LAYOUT_GENERAL == explicit_layout) { |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 594 | if (image_state->createInfo.tiling != VK_IMAGE_TILING_LINEAR) { |
| 595 | // 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] | 596 | skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 597 | VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, HandleToUint64(cb_node->commandBuffer), __LINE__, |
| 598 | DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 599 | "%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] | 600 | caller, HandleToUint64(image), string_VkImageLayout(optimal_layout)); |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 601 | } |
Mark Lobodzinski | 28426ae | 2017-06-01 07:56:38 -0600 | [diff] [blame] | 602 | } else if (GetDeviceExtensions(device_data)->vk_khr_shared_presentable_image) { |
Mark Lobodzinski | 087380c | 2017-05-16 14:42:25 -0600 | [diff] [blame] | 603 | if (image_state->shared_presentable) { |
| 604 | if (VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR != explicit_layout) { |
| 605 | // TODO: Add unique error id when available. |
| 606 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 607 | __LINE__, msg_code, "DS", |
| 608 | "Layout for shared presentable image is %s but must be VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR.", |
| 609 | string_VkImageLayout(optimal_layout)); |
| 610 | } |
Tobin Ehlis | bb03e5f | 2017-05-11 08:52:51 -0600 | [diff] [blame] | 611 | } |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 612 | } else { |
Tobin Ehlis | c826645 | 2017-04-07 12:20:30 -0600 | [diff] [blame] | 613 | *error = true; |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 614 | 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] | 615 | HandleToUint64(cb_node->commandBuffer), __LINE__, msg_code, "DS", |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 616 | "%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] | 617 | caller, HandleToUint64(image), string_VkImageLayout(explicit_layout), |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 618 | string_VkImageLayout(optimal_layout), validation_error_map[msg_code]); |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 619 | } |
| 620 | } |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 621 | return skip; |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 622 | } |
| 623 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 624 | void TransitionFinalSubpassLayouts(layer_data *device_data, GLOBAL_CB_NODE *pCB, const VkRenderPassBeginInfo *pRenderPassBegin, |
| 625 | FRAMEBUFFER_STATE *framebuffer_state) { |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 626 | auto renderPass = GetRenderPassState(device_data, pRenderPassBegin->renderPass); |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 627 | if (!renderPass) return; |
| 628 | |
| 629 | const VkRenderPassCreateInfo *pRenderPassInfo = renderPass->createInfo.ptr(); |
| 630 | if (framebuffer_state) { |
| 631 | for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) { |
| 632 | auto image_view = framebuffer_state->createInfo.pAttachments[i]; |
| 633 | SetImageViewLayout(device_data, pCB, image_view, pRenderPassInfo->pAttachments[i].finalLayout); |
| 634 | } |
| 635 | } |
| 636 | } |
| 637 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 638 | bool PreCallValidateCreateImage(layer_data *device_data, const VkImageCreateInfo *pCreateInfo, |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 639 | const VkAllocationCallbacks *pAllocator, VkImage *pImage) { |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 640 | bool skip = false; |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 641 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 642 | |
Jeremy Hayes | 96dcd81 | 2017-03-14 14:04:19 -0600 | [diff] [blame] | 643 | if (pCreateInfo->format == VK_FORMAT_UNDEFINED) { |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 644 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 645 | VALIDATION_ERROR_09e0075e, "IMAGE", "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED. %s", |
| 646 | validation_error_map[VALIDATION_ERROR_09e0075e]); |
Jeremy Hayes | 96dcd81 | 2017-03-14 14:04:19 -0600 | [diff] [blame] | 647 | |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 648 | return skip; |
Jeremy Hayes | 96dcd81 | 2017-03-14 14:04:19 -0600 | [diff] [blame] | 649 | } |
| 650 | |
Jeremy Kniager | 7ec550f | 2017-08-16 14:57:42 -0600 | [diff] [blame^] | 651 | VkFormatProperties properties = GetFormatProperties(device_data, pCreateInfo->format); |
Jeremy Hayes | 96dcd81 | 2017-03-14 14:04:19 -0600 | [diff] [blame] | 652 | |
Jeremy Kniager | 7ec550f | 2017-08-16 14:57:42 -0600 | [diff] [blame^] | 653 | if ((pCreateInfo->tiling == VK_IMAGE_TILING_LINEAR) && (properties.linearTilingFeatures == 0)) { |
Jeremy Hayes | 96dcd81 | 2017-03-14 14:04:19 -0600 | [diff] [blame] | 654 | std::stringstream ss; |
| 655 | ss << "vkCreateImage format parameter (" << string_VkFormat(pCreateInfo->format) << ") is an unsupported format"; |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 656 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 657 | VALIDATION_ERROR_09e007a2, "IMAGE", "%s. %s", ss.str().c_str(), |
| 658 | validation_error_map[VALIDATION_ERROR_09e007a2]); |
Jeremy Hayes | 96dcd81 | 2017-03-14 14:04:19 -0600 | [diff] [blame] | 659 | |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 660 | return skip; |
Jeremy Hayes | 96dcd81 | 2017-03-14 14:04:19 -0600 | [diff] [blame] | 661 | } |
| 662 | |
Jeremy Kniager | 7ec550f | 2017-08-16 14:57:42 -0600 | [diff] [blame^] | 663 | if ((pCreateInfo->tiling == VK_IMAGE_TILING_OPTIMAL) && (properties.optimalTilingFeatures == 0)) { |
Jeremy Hayes | 96dcd81 | 2017-03-14 14:04:19 -0600 | [diff] [blame] | 664 | std::stringstream ss; |
| 665 | ss << "vkCreateImage format parameter (" << string_VkFormat(pCreateInfo->format) << ") is an unsupported format"; |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 666 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 667 | VALIDATION_ERROR_09e007ac, "IMAGE", "%s. %s", ss.str().c_str(), |
| 668 | validation_error_map[VALIDATION_ERROR_09e007ac]); |
Jeremy Hayes | 96dcd81 | 2017-03-14 14:04:19 -0600 | [diff] [blame] | 669 | |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 670 | return skip; |
Jeremy Hayes | 96dcd81 | 2017-03-14 14:04:19 -0600 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | // Validate that format supports usage as color attachment |
| 674 | if (pCreateInfo->usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) { |
| 675 | if ((pCreateInfo->tiling == VK_IMAGE_TILING_OPTIMAL) && |
Jeremy Kniager | 7ec550f | 2017-08-16 14:57:42 -0600 | [diff] [blame^] | 676 | ((properties.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) == 0)) { |
Jeremy Hayes | 96dcd81 | 2017-03-14 14:04:19 -0600 | [diff] [blame] | 677 | std::stringstream ss; |
| 678 | ss << "vkCreateImage: VkFormat for TILING_OPTIMAL image (" << string_VkFormat(pCreateInfo->format) |
| 679 | << ") does not support requested Image usage type VK_IMAGE_USAGE_COLOR_ATTACHMENT"; |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 680 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, |
| 681 | VALIDATION_ERROR_09e007b2, "IMAGE", "%s. %s", ss.str().c_str(), |
| 682 | validation_error_map[VALIDATION_ERROR_09e007b2]); |
Jeremy Hayes | 96dcd81 | 2017-03-14 14:04:19 -0600 | [diff] [blame] | 683 | } |
| 684 | if ((pCreateInfo->tiling == VK_IMAGE_TILING_LINEAR) && |
Jeremy Kniager | 7ec550f | 2017-08-16 14:57:42 -0600 | [diff] [blame^] | 685 | ((properties.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) == 0)) { |
Jeremy Hayes | 96dcd81 | 2017-03-14 14:04:19 -0600 | [diff] [blame] | 686 | std::stringstream ss; |
| 687 | ss << "vkCreateImage: VkFormat for TILING_LINEAR image (" << string_VkFormat(pCreateInfo->format) |
| 688 | << ") does not support requested Image usage type VK_IMAGE_USAGE_COLOR_ATTACHMENT"; |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 689 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, |
| 690 | VALIDATION_ERROR_09e007a8, "IMAGE", "%s. %s", ss.str().c_str(), |
| 691 | validation_error_map[VALIDATION_ERROR_09e007a8]); |
Jeremy Hayes | 96dcd81 | 2017-03-14 14:04:19 -0600 | [diff] [blame] | 692 | } |
| 693 | } |
| 694 | |
| 695 | // Validate that format supports usage as depth/stencil attachment |
| 696 | if (pCreateInfo->usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) { |
| 697 | if ((pCreateInfo->tiling == VK_IMAGE_TILING_OPTIMAL) && |
Jeremy Kniager | 7ec550f | 2017-08-16 14:57:42 -0600 | [diff] [blame^] | 698 | ((properties.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) == 0)) { |
Jeremy Hayes | 96dcd81 | 2017-03-14 14:04:19 -0600 | [diff] [blame] | 699 | std::stringstream ss; |
| 700 | ss << "vkCreateImage: VkFormat for TILING_OPTIMAL image (" << string_VkFormat(pCreateInfo->format) |
| 701 | << ") does not support requested Image usage type VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT"; |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 702 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, |
| 703 | VALIDATION_ERROR_09e007b4, "IMAGE", "%s. %s", ss.str().c_str(), |
| 704 | validation_error_map[VALIDATION_ERROR_09e007b4]); |
Jeremy Hayes | 96dcd81 | 2017-03-14 14:04:19 -0600 | [diff] [blame] | 705 | } |
| 706 | if ((pCreateInfo->tiling == VK_IMAGE_TILING_LINEAR) && |
Jeremy Kniager | 7ec550f | 2017-08-16 14:57:42 -0600 | [diff] [blame^] | 707 | ((properties.linearTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) == 0)) { |
Jeremy Hayes | 96dcd81 | 2017-03-14 14:04:19 -0600 | [diff] [blame] | 708 | std::stringstream ss; |
| 709 | ss << "vkCreateImage: VkFormat for TILING_LINEAR image (" << string_VkFormat(pCreateInfo->format) |
| 710 | << ") does not support requested Image usage type VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT"; |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 711 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, |
| 712 | VALIDATION_ERROR_09e007aa, "IMAGE", "%s. %s", ss.str().c_str(), |
| 713 | validation_error_map[VALIDATION_ERROR_09e007aa]); |
Jeremy Hayes | 96dcd81 | 2017-03-14 14:04:19 -0600 | [diff] [blame] | 714 | } |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 715 | } |
| 716 | |
Jeremy Kniager | 7ec550f | 2017-08-16 14:57:42 -0600 | [diff] [blame^] | 717 | VkImageFormatProperties ImageFormatProperties = GetImageFormatProperties( |
Mark Lobodzinski | efd933b | 2017-02-10 12:09:23 -0700 | [diff] [blame] | 718 | device_data, pCreateInfo->format, pCreateInfo->imageType, pCreateInfo->tiling, pCreateInfo->usage, pCreateInfo->flags); |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 719 | |
Mark Lobodzinski | efd933b | 2017-02-10 12:09:23 -0700 | [diff] [blame] | 720 | VkDeviceSize imageGranularity = GetPhysicalDeviceProperties(device_data)->limits.bufferImageGranularity; |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 721 | imageGranularity = imageGranularity == 1 ? 0 : imageGranularity; |
Tobin Ehlis | a55b1d4 | 2017-04-04 12:23:48 -0600 | [diff] [blame] | 722 | // TODO : This is also covering 2918 & 2919. Break out into separate checks |
Mark Lobodzinski | 688ed32 | 2017-01-27 11:13:21 -0700 | [diff] [blame] | 723 | 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] | 724 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 725 | VALIDATION_ERROR_09e007b8, "Image", |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 726 | "CreateImage extent is 0 for at least one required dimension for image: " |
| 727 | "Width = %d Height = %d Depth = %d. %s", |
| 728 | pCreateInfo->extent.width, pCreateInfo->extent.height, pCreateInfo->extent.depth, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 729 | validation_error_map[VALIDATION_ERROR_09e007b8]); |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 730 | } |
| 731 | |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 732 | // TODO: VALIDATION_ERROR_09e00770 VALIDATION_ERROR_09e00772 VALIDATION_ERROR_09e00776 VALIDATION_ERROR_09e0076e |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 733 | // All these extent-related VUs should be checked here |
Jeremy Kniager | 7ec550f | 2017-08-16 14:57:42 -0600 | [diff] [blame^] | 734 | if ((pCreateInfo->extent.depth > ImageFormatProperties.maxExtent.depth) || |
| 735 | (pCreateInfo->extent.width > ImageFormatProperties.maxExtent.width) || |
| 736 | (pCreateInfo->extent.height > ImageFormatProperties.maxExtent.height)) { |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 737 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__, |
| 738 | IMAGE_INVALID_FORMAT_LIMITS_VIOLATION, "Image", |
| 739 | "CreateImage extents exceed allowable limits for format: " |
| 740 | "Width = %d Height = %d Depth = %d: Limits for Width = %d Height = %d Depth = %d for format %s.", |
| 741 | pCreateInfo->extent.width, pCreateInfo->extent.height, pCreateInfo->extent.depth, |
Jeremy Kniager | 7ec550f | 2017-08-16 14:57:42 -0600 | [diff] [blame^] | 742 | ImageFormatProperties.maxExtent.width, ImageFormatProperties.maxExtent.height, |
| 743 | ImageFormatProperties.maxExtent.depth, string_VkFormat(pCreateInfo->format)); |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 744 | } |
| 745 | |
Dave Houlton | 1150cf5 | 2017-04-27 14:38:11 -0600 | [diff] [blame] | 746 | uint64_t totalSize = |
| 747 | ((uint64_t)pCreateInfo->extent.width * (uint64_t)pCreateInfo->extent.height * (uint64_t)pCreateInfo->extent.depth * |
| 748 | (uint64_t)pCreateInfo->arrayLayers * (uint64_t)pCreateInfo->samples * (uint64_t)FormatSize(pCreateInfo->format) + |
| 749 | (uint64_t)imageGranularity) & |
| 750 | ~(uint64_t)imageGranularity; |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 751 | |
Jeremy Kniager | 7ec550f | 2017-08-16 14:57:42 -0600 | [diff] [blame^] | 752 | if (totalSize > ImageFormatProperties.maxResourceSize) { |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 753 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__, |
| 754 | IMAGE_INVALID_FORMAT_LIMITS_VIOLATION, "Image", |
| 755 | "CreateImage resource size exceeds allowable maximum " |
| 756 | "Image resource size = 0x%" PRIxLEAST64 ", maximum resource size = 0x%" PRIxLEAST64 " ", |
Jeremy Kniager | 7ec550f | 2017-08-16 14:57:42 -0600 | [diff] [blame^] | 757 | totalSize, ImageFormatProperties.maxResourceSize); |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 758 | } |
| 759 | |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 760 | // TODO: VALIDATION_ERROR_09e0077e |
Jeremy Kniager | 7ec550f | 2017-08-16 14:57:42 -0600 | [diff] [blame^] | 761 | if (pCreateInfo->mipLevels > ImageFormatProperties.maxMipLevels) { |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 762 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__, |
| 763 | IMAGE_INVALID_FORMAT_LIMITS_VIOLATION, "Image", |
| 764 | "CreateImage mipLevels=%d exceeds allowable maximum supported by format of %d", pCreateInfo->mipLevels, |
Jeremy Kniager | 7ec550f | 2017-08-16 14:57:42 -0600 | [diff] [blame^] | 765 | ImageFormatProperties.maxMipLevels); |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 766 | } |
| 767 | |
Jeremy Kniager | 7ec550f | 2017-08-16 14:57:42 -0600 | [diff] [blame^] | 768 | if (pCreateInfo->arrayLayers > ImageFormatProperties.maxArrayLayers) { |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 769 | skip |= |
| 770 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__, |
| 771 | VALIDATION_ERROR_09e00780, "Image", |
| 772 | "CreateImage arrayLayers=%d exceeds allowable maximum supported by format of %d. %s", pCreateInfo->arrayLayers, |
Jeremy Kniager | 7ec550f | 2017-08-16 14:57:42 -0600 | [diff] [blame^] | 773 | ImageFormatProperties.maxArrayLayers, validation_error_map[VALIDATION_ERROR_09e00780]); |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 774 | } |
| 775 | |
Jeremy Kniager | 7ec550f | 2017-08-16 14:57:42 -0600 | [diff] [blame^] | 776 | if ((pCreateInfo->samples & ImageFormatProperties.sampleCounts) == 0) { |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 777 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 778 | VALIDATION_ERROR_09e0078e, "Image", "CreateImage samples %s is not supported by format 0x%.8X. %s", |
Jeremy Kniager | 7ec550f | 2017-08-16 14:57:42 -0600 | [diff] [blame^] | 779 | string_VkSampleCountFlagBits(pCreateInfo->samples), ImageFormatProperties.sampleCounts, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 780 | validation_error_map[VALIDATION_ERROR_09e0078e]); |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 781 | } |
| 782 | |
| 783 | 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] | 784 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 785 | VALIDATION_ERROR_09e0b801, "Image", |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 786 | "vkCreateImage parameter, pCreateInfo->initialLayout, must be VK_IMAGE_LAYOUT_UNDEFINED or " |
| 787 | "VK_IMAGE_LAYOUT_PREINITIALIZED. %s", |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 788 | validation_error_map[VALIDATION_ERROR_09e0b801]); |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 789 | } |
| 790 | |
Mark Lobodzinski | 847b60c | 2017-03-13 09:32:45 -0600 | [diff] [blame] | 791 | 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] | 792 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 793 | VALIDATION_ERROR_09e00792, "DS", |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 794 | "vkCreateImage(): the sparseBinding device feature is disabled: Images cannot be created with the " |
| 795 | "VK_IMAGE_CREATE_SPARSE_BINDING_BIT set. %s", |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 796 | validation_error_map[VALIDATION_ERROR_09e00792]); |
Mark Lobodzinski | 847b60c | 2017-03-13 09:32:45 -0600 | [diff] [blame] | 797 | } |
| 798 | |
Mark Lobodzinski | 035a4cf | 2017-03-13 09:45:07 -0600 | [diff] [blame] | 799 | 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] | 800 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, |
| 801 | DRAWSTATE_INVALID_FEATURE, "DS", |
| 802 | "vkCreateImage(): the sparseResidencyAliased device feature is disabled: Images cannot be created with the " |
| 803 | "VK_IMAGE_CREATE_SPARSE_ALIASED_BIT set."); |
Mark Lobodzinski | 035a4cf | 2017-03-13 09:45:07 -0600 | [diff] [blame] | 804 | } |
| 805 | |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 806 | return skip; |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 807 | } |
| 808 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 809 | void PostCallRecordCreateImage(layer_data *device_data, const VkImageCreateInfo *pCreateInfo, VkImage *pImage) { |
Mark Lobodzinski | 42fe5f7 | 2017-01-11 11:36:16 -0700 | [diff] [blame] | 810 | IMAGE_LAYOUT_NODE image_state; |
| 811 | image_state.layout = pCreateInfo->initialLayout; |
| 812 | image_state.format = pCreateInfo->format; |
Mark Lobodzinski | 214144a | 2017-01-27 14:25:32 -0700 | [diff] [blame] | 813 | 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] | 814 | ImageSubresourcePair subpair{*pImage, false, VkImageSubresource()}; |
Mark Lobodzinski | 214144a | 2017-01-27 14:25:32 -0700 | [diff] [blame] | 815 | (*core_validation::GetImageSubresourceMap(device_data))[*pImage].push_back(subpair); |
| 816 | (*core_validation::GetImageLayoutMap(device_data))[subpair] = image_state; |
Mark Lobodzinski | 42fe5f7 | 2017-01-11 11:36:16 -0700 | [diff] [blame] | 817 | } |
Mark Lobodzinski | 9ef5d56 | 2017-01-27 12:28:30 -0700 | [diff] [blame] | 818 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 819 | 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] | 820 | const CHECK_DISABLED *disabled = core_validation::GetDisables(device_data); |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 821 | *image_state = core_validation::GetImageState(device_data, image); |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 822 | *obj_struct = {HandleToUint64(image), kVulkanObjectTypeImage}; |
Mark Lobodzinski | 9ef5d56 | 2017-01-27 12:28:30 -0700 | [diff] [blame] | 823 | if (disabled->destroy_image) return false; |
| 824 | bool skip = false; |
| 825 | if (*image_state) { |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 826 | skip |= core_validation::ValidateObjectNotInUse(device_data, *image_state, *obj_struct, VALIDATION_ERROR_252007d0); |
Mark Lobodzinski | 9ef5d56 | 2017-01-27 12:28:30 -0700 | [diff] [blame] | 827 | } |
| 828 | return skip; |
| 829 | } |
| 830 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 831 | 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] | 832 | core_validation::invalidateCommandBuffers(device_data, image_state->cb_bindings, obj_struct); |
| 833 | // Clean up memory mapping, bindings and range references for image |
| 834 | for (auto mem_binding : image_state->GetBoundMemory()) { |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 835 | auto mem_info = core_validation::GetMemObjInfo(device_data, mem_binding); |
Mark Lobodzinski | 9ef5d56 | 2017-01-27 12:28:30 -0700 | [diff] [blame] | 836 | if (mem_info) { |
| 837 | core_validation::RemoveImageMemoryRange(obj_struct.handle, mem_info); |
| 838 | } |
| 839 | } |
Mark Lobodzinski | 3382637 | 2017-04-13 11:10:11 -0600 | [diff] [blame] | 840 | core_validation::ClearMemoryObjectBindings(device_data, obj_struct.handle, kVulkanObjectTypeImage); |
Mark Lobodzinski | 9ef5d56 | 2017-01-27 12:28:30 -0700 | [diff] [blame] | 841 | // Remove image from imageMap |
| 842 | core_validation::GetImageMap(device_data)->erase(image); |
| 843 | std::unordered_map<VkImage, std::vector<ImageSubresourcePair>> *imageSubresourceMap = |
| 844 | core_validation::GetImageSubresourceMap(device_data); |
| 845 | |
| 846 | const auto &sub_entry = imageSubresourceMap->find(image); |
| 847 | if (sub_entry != imageSubresourceMap->end()) { |
| 848 | for (const auto &pair : sub_entry->second) { |
| 849 | core_validation::GetImageLayoutMap(device_data)->erase(pair); |
| 850 | } |
| 851 | imageSubresourceMap->erase(sub_entry); |
| 852 | } |
| 853 | } |
Mark Lobodzinski | c409a58 | 2017-01-27 15:16:01 -0700 | [diff] [blame] | 854 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 855 | bool ValidateImageAttributes(layer_data *device_data, IMAGE_STATE *image_state, VkImageSubresourceRange range) { |
Mark Lobodzinski | c409a58 | 2017-01-27 15:16:01 -0700 | [diff] [blame] | 856 | bool skip = false; |
| 857 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 858 | |
| 859 | if (range.aspectMask != VK_IMAGE_ASPECT_COLOR_BIT) { |
| 860 | char const str[] = "vkCmdClearColorImage aspectMasks for all subresource ranges must be set to VK_IMAGE_ASPECT_COLOR_BIT"; |
| 861 | 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] | 862 | HandleToUint64(image_state->image), __LINE__, DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", str); |
Mark Lobodzinski | c409a58 | 2017-01-27 15:16:01 -0700 | [diff] [blame] | 863 | } |
| 864 | |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 865 | if (FormatIsDepthOrStencil(image_state->createInfo.format)) { |
Mark Lobodzinski | c409a58 | 2017-01-27 15:16:01 -0700 | [diff] [blame] | 866 | char const str[] = "vkCmdClearColorImage called with depth/stencil image."; |
| 867 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 868 | HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_1880000e, "IMAGE", "%s. %s", str, |
| 869 | validation_error_map[VALIDATION_ERROR_1880000e]); |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 870 | } else if (FormatIsCompressed(image_state->createInfo.format)) { |
Mark Lobodzinski | c409a58 | 2017-01-27 15:16:01 -0700 | [diff] [blame] | 871 | char const str[] = "vkCmdClearColorImage called with compressed image."; |
| 872 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 873 | HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_1880000e, "IMAGE", "%s. %s", str, |
| 874 | validation_error_map[VALIDATION_ERROR_1880000e]); |
Mark Lobodzinski | c409a58 | 2017-01-27 15:16:01 -0700 | [diff] [blame] | 875 | } |
| 876 | |
| 877 | if (!(image_state->createInfo.usage & VK_IMAGE_USAGE_TRANSFER_DST_BIT)) { |
| 878 | char const str[] = "vkCmdClearColorImage called with image created without VK_IMAGE_USAGE_TRANSFER_DST_BIT."; |
| 879 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 880 | HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_18800004, "IMAGE", "%s. %s", str, |
| 881 | validation_error_map[VALIDATION_ERROR_18800004]); |
Mark Lobodzinski | c409a58 | 2017-01-27 15:16:01 -0700 | [diff] [blame] | 882 | } |
| 883 | return skip; |
| 884 | } |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 885 | |
Mark Lobodzinski | 903e5ff | 2017-03-23 09:43:35 -0600 | [diff] [blame] | 886 | uint32_t ResolveRemainingLevels(const VkImageSubresourceRange *range, uint32_t mip_levels) { |
| 887 | // Return correct number of mip levels taking into account VK_REMAINING_MIP_LEVELS |
| 888 | uint32_t mip_level_count = range->levelCount; |
Mark Lobodzinski | 9c93dbd | 2017-02-02 08:31:18 -0700 | [diff] [blame] | 889 | if (range->levelCount == VK_REMAINING_MIP_LEVELS) { |
Mark Lobodzinski | 903e5ff | 2017-03-23 09:43:35 -0600 | [diff] [blame] | 890 | mip_level_count = mip_levels - range->baseMipLevel; |
Mark Lobodzinski | 9c93dbd | 2017-02-02 08:31:18 -0700 | [diff] [blame] | 891 | } |
Mark Lobodzinski | 903e5ff | 2017-03-23 09:43:35 -0600 | [diff] [blame] | 892 | return mip_level_count; |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 893 | } |
| 894 | |
Mark Lobodzinski | 903e5ff | 2017-03-23 09:43:35 -0600 | [diff] [blame] | 895 | uint32_t ResolveRemainingLayers(const VkImageSubresourceRange *range, uint32_t layers) { |
| 896 | // Return correct number of layers taking into account VK_REMAINING_ARRAY_LAYERS |
| 897 | uint32_t array_layer_count = range->layerCount; |
| 898 | if (range->layerCount == VK_REMAINING_ARRAY_LAYERS) { |
| 899 | array_layer_count = layers - range->baseArrayLayer; |
Mark Lobodzinski | 9c93dbd | 2017-02-02 08:31:18 -0700 | [diff] [blame] | 900 | } |
Mark Lobodzinski | 903e5ff | 2017-03-23 09:43:35 -0600 | [diff] [blame] | 901 | return array_layer_count; |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 902 | } |
| 903 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 904 | 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] | 905 | VkImageSubresourceRange range, VkImageLayout dest_image_layout, const char *func_name) { |
| 906 | bool skip = false; |
| 907 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 908 | |
Mark Lobodzinski | 903e5ff | 2017-03-23 09:43:35 -0600 | [diff] [blame] | 909 | uint32_t level_count = ResolveRemainingLevels(&range, image_state->createInfo.mipLevels); |
| 910 | uint32_t layer_count = ResolveRemainingLayers(&range, image_state->createInfo.arrayLayers); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 911 | |
| 912 | if (dest_image_layout != VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) { |
| 913 | if (dest_image_layout == VK_IMAGE_LAYOUT_GENERAL) { |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 914 | if (image_state->createInfo.tiling != VK_IMAGE_TILING_LINEAR) { |
| 915 | // 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] | 916 | 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] | 917 | HandleToUint64(image_state->image), __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 918 | "%s: Layout for cleared image should be TRANSFER_DST_OPTIMAL instead of GENERAL.", func_name); |
| 919 | } |
Mark Lobodzinski | 087380c | 2017-05-16 14:42:25 -0600 | [diff] [blame] | 920 | } else if (VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR == dest_image_layout) { |
Mark Lobodzinski | 28426ae | 2017-06-01 07:56:38 -0600 | [diff] [blame] | 921 | if (!GetDeviceExtensions(device_data)->vk_khr_shared_presentable_image) { |
Tobin Ehlis | fb0661c | 2017-05-11 08:52:51 -0600 | [diff] [blame] | 922 | // TODO: Add unique error id when available. |
Mark Lobodzinski | 087380c | 2017-05-16 14:42:25 -0600 | [diff] [blame] | 923 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 924 | HandleToUint64(image_state->image), __LINE__, 0, "DS", |
| 925 | "Must enable VK_KHR_shared_presentable_image extension before creating images with a layout type " |
| 926 | "of VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR."); |
Mark Lobodzinski | 087380c | 2017-05-16 14:42:25 -0600 | [diff] [blame] | 927 | |
| 928 | } else { |
| 929 | if (image_state->shared_presentable) { |
| 930 | skip |= log_msg( |
| 931 | 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] | 932 | HandleToUint64(image_state->image), __LINE__, 0, "DS", |
Mark Lobodzinski | 087380c | 2017-05-16 14:42:25 -0600 | [diff] [blame] | 933 | "Layout for shared presentable cleared image is %s but can only be VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR.", |
| 934 | string_VkImageLayout(dest_image_layout)); |
| 935 | } |
Tobin Ehlis | bb03e5f | 2017-05-11 08:52:51 -0600 | [diff] [blame] | 936 | } |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 937 | } else { |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 938 | UNIQUE_VALIDATION_ERROR_CODE error_code = VALIDATION_ERROR_1880000a; |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 939 | if (strcmp(func_name, "vkCmdClearDepthStencilImage()") == 0) { |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 940 | error_code = VALIDATION_ERROR_18a00018; |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 941 | } else { |
| 942 | assert(strcmp(func_name, "vkCmdClearColorImage()") == 0); |
| 943 | } |
Mark Lobodzinski | 0827aec | 2017-03-21 16:41:45 -0600 | [diff] [blame] | 944 | 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] | 945 | HandleToUint64(image_state->image), __LINE__, error_code, "DS", |
Mark Lobodzinski | 0827aec | 2017-03-21 16:41:45 -0600 | [diff] [blame] | 946 | "%s: Layout for cleared image is %s but can only be " |
| 947 | "TRANSFER_DST_OPTIMAL or GENERAL. %s", |
| 948 | func_name, string_VkImageLayout(dest_image_layout), validation_error_map[error_code]); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 949 | } |
| 950 | } |
| 951 | |
Mark Lobodzinski | 903e5ff | 2017-03-23 09:43:35 -0600 | [diff] [blame] | 952 | for (uint32_t level_index = 0; level_index < level_count; ++level_index) { |
| 953 | uint32_t level = level_index + range.baseMipLevel; |
| 954 | for (uint32_t layer_index = 0; layer_index < layer_count; ++layer_index) { |
| 955 | uint32_t layer = layer_index + range.baseArrayLayer; |
| 956 | VkImageSubresource sub = {range.aspectMask, level, layer}; |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 957 | IMAGE_CMD_BUF_LAYOUT_NODE node; |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 958 | if (FindCmdBufLayout(device_data, cb_node, image_state->image, sub, node)) { |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 959 | if (node.layout != dest_image_layout) { |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 960 | UNIQUE_VALIDATION_ERROR_CODE error_code = VALIDATION_ERROR_18800008; |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 961 | if (strcmp(func_name, "vkCmdClearDepthStencilImage()") == 0) { |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 962 | error_code = VALIDATION_ERROR_18a00016; |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 963 | } else { |
| 964 | assert(strcmp(func_name, "vkCmdClearColorImage()") == 0); |
| 965 | } |
| 966 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, |
| 967 | __LINE__, error_code, "DS", |
| 968 | "%s: Cannot clear an image whose layout is %s and " |
| 969 | "doesn't match the current layout %s. %s", |
| 970 | func_name, string_VkImageLayout(dest_image_layout), string_VkImageLayout(node.layout), |
| 971 | validation_error_map[error_code]); |
| 972 | } |
| 973 | } |
| 974 | } |
| 975 | } |
| 976 | |
| 977 | return skip; |
| 978 | } |
| 979 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 980 | void RecordClearImageLayout(layer_data *device_data, GLOBAL_CB_NODE *cb_node, VkImage image, VkImageSubresourceRange range, |
| 981 | VkImageLayout dest_image_layout) { |
Mark Lobodzinski | 903e5ff | 2017-03-23 09:43:35 -0600 | [diff] [blame] | 982 | VkImageCreateInfo *image_create_info = &(GetImageState(device_data, image)->createInfo); |
| 983 | uint32_t level_count = ResolveRemainingLevels(&range, image_create_info->mipLevels); |
| 984 | uint32_t layer_count = ResolveRemainingLayers(&range, image_create_info->arrayLayers); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 985 | |
Mark Lobodzinski | 903e5ff | 2017-03-23 09:43:35 -0600 | [diff] [blame] | 986 | for (uint32_t level_index = 0; level_index < level_count; ++level_index) { |
| 987 | uint32_t level = level_index + range.baseMipLevel; |
| 988 | for (uint32_t layer_index = 0; layer_index < layer_count; ++layer_index) { |
| 989 | uint32_t layer = layer_index + range.baseArrayLayer; |
| 990 | VkImageSubresource sub = {range.aspectMask, level, layer}; |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 991 | IMAGE_CMD_BUF_LAYOUT_NODE node; |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 992 | if (!FindCmdBufLayout(device_data, cb_node, image, sub, node)) { |
| 993 | 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] | 994 | } |
| 995 | } |
| 996 | } |
| 997 | } |
| 998 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 999 | bool PreCallValidateCmdClearColorImage(layer_data *dev_data, VkCommandBuffer commandBuffer, VkImage image, |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1000 | VkImageLayout imageLayout, uint32_t rangeCount, const VkImageSubresourceRange *pRanges) { |
| 1001 | bool skip = false; |
| 1002 | // TODO : Verify memory is in VK_IMAGE_STATE_CLEAR state |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 1003 | auto cb_node = GetCBNode(dev_data, commandBuffer); |
| 1004 | auto image_state = GetImageState(dev_data, image); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1005 | if (cb_node && image_state) { |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1006 | skip |= ValidateMemoryIsBoundToImage(dev_data, image_state, "vkCmdClearColorImage()", VALIDATION_ERROR_18800006); |
Mike Schuchardt | 9c58240 | 2017-02-23 15:57:37 -0700 | [diff] [blame] | 1007 | skip |= ValidateCmdQueueFlags(dev_data, cb_node, "vkCmdClearColorImage()", VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1008 | VALIDATION_ERROR_18802415); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1009 | skip |= ValidateCmd(dev_data, cb_node, CMD_CLEARCOLORIMAGE, "vkCmdClearColorImage()"); |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1010 | skip |= insideRenderPass(dev_data, cb_node, "vkCmdClearColorImage()", VALIDATION_ERROR_18800017); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1011 | for (uint32_t i = 0; i < rangeCount; ++i) { |
Petr Kraus | 4d71868 | 2017-05-18 03:38:41 +0200 | [diff] [blame] | 1012 | std::string param_name = "pRanges[" + std::to_string(i) + "]"; |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 1013 | skip |= ValidateCmdClearColorSubresourceRange(dev_data, image_state, pRanges[i], param_name.c_str()); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1014 | skip |= ValidateImageAttributes(dev_data, image_state, pRanges[i]); |
Mark Lobodzinski | 9c93dbd | 2017-02-02 08:31:18 -0700 | [diff] [blame] | 1015 | skip |= VerifyClearImageLayout(dev_data, cb_node, image_state, pRanges[i], imageLayout, "vkCmdClearColorImage()"); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1016 | } |
| 1017 | } |
| 1018 | return skip; |
| 1019 | } |
| 1020 | |
| 1021 | // This state recording routine is shared between ClearColorImage and ClearDepthStencilImage |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 1022 | void PreCallRecordCmdClearImage(layer_data *dev_data, VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, |
Chris Forbes | 38c2e79 | 2017-06-16 16:42:35 -0700 | [diff] [blame] | 1023 | uint32_t rangeCount, const VkImageSubresourceRange *pRanges) { |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 1024 | auto cb_node = GetCBNode(dev_data, commandBuffer); |
| 1025 | auto image_state = GetImageState(dev_data, image); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1026 | if (cb_node && image_state) { |
| 1027 | AddCommandBufferBindingImage(dev_data, cb_node, image_state); |
| 1028 | std::function<bool()> function = [=]() { |
| 1029 | SetImageMemoryValid(dev_data, image_state, true); |
| 1030 | return false; |
| 1031 | }; |
Tobin Ehlis | a17a529 | 2017-07-28 12:11:30 -0600 | [diff] [blame] | 1032 | cb_node->queue_submit_functions.push_back(function); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1033 | for (uint32_t i = 0; i < rangeCount; ++i) { |
| 1034 | RecordClearImageLayout(dev_data, cb_node, image, pRanges[i], imageLayout); |
| 1035 | } |
| 1036 | } |
| 1037 | } |
| 1038 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 1039 | bool PreCallValidateCmdClearDepthStencilImage(layer_data *device_data, VkCommandBuffer commandBuffer, VkImage image, |
| 1040 | VkImageLayout imageLayout, uint32_t rangeCount, |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1041 | const VkImageSubresourceRange *pRanges) { |
| 1042 | bool skip = false; |
Mark Lobodzinski | 1241a31 | 2017-02-01 10:57:21 -0700 | [diff] [blame] | 1043 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 1044 | |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1045 | // TODO : Verify memory is in VK_IMAGE_STATE_CLEAR state |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 1046 | auto cb_node = GetCBNode(device_data, commandBuffer); |
| 1047 | auto image_state = GetImageState(device_data, image); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1048 | if (cb_node && image_state) { |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1049 | skip |= ValidateMemoryIsBoundToImage(device_data, image_state, "vkCmdClearDepthStencilImage()", VALIDATION_ERROR_18a00014); |
Mike Schuchardt | 9c58240 | 2017-02-23 15:57:37 -0700 | [diff] [blame] | 1050 | skip |= ValidateCmdQueueFlags(device_data, cb_node, "vkCmdClearDepthStencilImage()", VK_QUEUE_GRAPHICS_BIT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1051 | VALIDATION_ERROR_18a02415); |
Mark Lobodzinski | 1241a31 | 2017-02-01 10:57:21 -0700 | [diff] [blame] | 1052 | skip |= ValidateCmd(device_data, cb_node, CMD_CLEARDEPTHSTENCILIMAGE, "vkCmdClearDepthStencilImage()"); |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1053 | skip |= insideRenderPass(device_data, cb_node, "vkCmdClearDepthStencilImage()", VALIDATION_ERROR_18a00017); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1054 | for (uint32_t i = 0; i < rangeCount; ++i) { |
Petr Kraus | 4d71868 | 2017-05-18 03:38:41 +0200 | [diff] [blame] | 1055 | std::string param_name = "pRanges[" + std::to_string(i) + "]"; |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 1056 | skip |= ValidateCmdClearDepthSubresourceRange(device_data, image_state, pRanges[i], param_name.c_str()); |
Mark Lobodzinski | 9c93dbd | 2017-02-02 08:31:18 -0700 | [diff] [blame] | 1057 | skip |= |
| 1058 | VerifyClearImageLayout(device_data, cb_node, image_state, pRanges[i], imageLayout, "vkCmdClearDepthStencilImage()"); |
Mark Lobodzinski | 1241a31 | 2017-02-01 10:57:21 -0700 | [diff] [blame] | 1059 | // Image aspect must be depth or stencil or both |
| 1060 | if (((pRanges[i].aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) != VK_IMAGE_ASPECT_DEPTH_BIT) && |
| 1061 | ((pRanges[i].aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) != VK_IMAGE_ASPECT_STENCIL_BIT)) { |
| 1062 | char const str[] = |
| 1063 | "vkCmdClearDepthStencilImage aspectMasks for all subresource ranges must be " |
| 1064 | "set to VK_IMAGE_ASPECT_DEPTH_BIT and/or VK_IMAGE_ASPECT_STENCIL_BIT"; |
| 1065 | 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] | 1066 | HandleToUint64(commandBuffer), __LINE__, DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", str); |
Mark Lobodzinski | 1241a31 | 2017-02-01 10:57:21 -0700 | [diff] [blame] | 1067 | } |
| 1068 | } |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 1069 | if (image_state && !FormatIsDepthOrStencil(image_state->createInfo.format)) { |
Mark Lobodzinski | 1241a31 | 2017-02-01 10:57:21 -0700 | [diff] [blame] | 1070 | char const str[] = "vkCmdClearDepthStencilImage called without a depth/stencil image."; |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1071 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 1072 | HandleToUint64(image), __LINE__, VALIDATION_ERROR_18a0001c, "IMAGE", "%s. %s", str, |
| 1073 | validation_error_map[VALIDATION_ERROR_18a0001c]); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1074 | } |
| 1075 | } |
| 1076 | return skip; |
| 1077 | } |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1078 | |
| 1079 | // Returns true if [x, xoffset] and [y, yoffset] overlap |
| 1080 | static bool RangesIntersect(int32_t start, uint32_t start_offset, int32_t end, uint32_t end_offset) { |
| 1081 | bool result = false; |
| 1082 | uint32_t intersection_min = std::max(static_cast<uint32_t>(start), static_cast<uint32_t>(end)); |
| 1083 | uint32_t intersection_max = std::min(static_cast<uint32_t>(start) + start_offset, static_cast<uint32_t>(end) + end_offset); |
| 1084 | |
| 1085 | if (intersection_max > intersection_min) { |
| 1086 | result = true; |
| 1087 | } |
| 1088 | return result; |
| 1089 | } |
| 1090 | |
| 1091 | // Returns true if two VkImageCopy structures overlap |
| 1092 | static bool RegionIntersects(const VkImageCopy *src, const VkImageCopy *dst, VkImageType type) { |
| 1093 | bool result = false; |
| 1094 | if ((src->srcSubresource.mipLevel == dst->dstSubresource.mipLevel) && |
| 1095 | (RangesIntersect(src->srcSubresource.baseArrayLayer, src->srcSubresource.layerCount, dst->dstSubresource.baseArrayLayer, |
| 1096 | dst->dstSubresource.layerCount))) { |
| 1097 | result = true; |
| 1098 | switch (type) { |
| 1099 | case VK_IMAGE_TYPE_3D: |
| 1100 | result &= RangesIntersect(src->srcOffset.z, src->extent.depth, dst->dstOffset.z, dst->extent.depth); |
| 1101 | // Intentionally fall through to 2D case |
| 1102 | case VK_IMAGE_TYPE_2D: |
| 1103 | result &= RangesIntersect(src->srcOffset.y, src->extent.height, dst->dstOffset.y, dst->extent.height); |
| 1104 | // Intentionally fall through to 1D case |
| 1105 | case VK_IMAGE_TYPE_1D: |
| 1106 | result &= RangesIntersect(src->srcOffset.x, src->extent.width, dst->dstOffset.x, dst->extent.width); |
| 1107 | break; |
| 1108 | default: |
| 1109 | // Unrecognized or new IMAGE_TYPE enums will be caught in parameter_validation |
| 1110 | assert(false); |
| 1111 | } |
| 1112 | } |
| 1113 | return result; |
| 1114 | } |
| 1115 | |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 1116 | // Returns non-zero if offset and extent exceed image extents |
| 1117 | static const uint32_t x_bit = 1; |
| 1118 | static const uint32_t y_bit = 2; |
| 1119 | static const uint32_t z_bit = 4; |
Dave Houlton | 1150cf5 | 2017-04-27 14:38:11 -0600 | [diff] [blame] | 1120 | 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] | 1121 | uint32_t result = 0; |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1122 | // Extents/depths cannot be negative but checks left in for clarity |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 1123 | if ((offset->z + extent->depth > image_extent->depth) || (offset->z < 0) || |
| 1124 | ((offset->z + static_cast<int32_t>(extent->depth)) < 0)) { |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 1125 | result |= z_bit; |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 1126 | } |
| 1127 | if ((offset->y + extent->height > image_extent->height) || (offset->y < 0) || |
| 1128 | ((offset->y + static_cast<int32_t>(extent->height)) < 0)) { |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 1129 | result |= y_bit; |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 1130 | } |
| 1131 | if ((offset->x + extent->width > image_extent->width) || (offset->x < 0) || |
| 1132 | ((offset->x + static_cast<int32_t>(extent->width)) < 0)) { |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 1133 | result |= x_bit; |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1134 | } |
| 1135 | return result; |
| 1136 | } |
| 1137 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1138 | // Test if two VkExtent3D structs are equivalent |
| 1139 | static inline bool IsExtentEqual(const VkExtent3D *extent, const VkExtent3D *other_extent) { |
| 1140 | bool result = true; |
| 1141 | if ((extent->width != other_extent->width) || (extent->height != other_extent->height) || |
| 1142 | (extent->depth != other_extent->depth)) { |
| 1143 | result = false; |
| 1144 | } |
| 1145 | return result; |
| 1146 | } |
| 1147 | |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1148 | // 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] | 1149 | static inline VkExtent3D GetImageSubresourceExtent(const IMAGE_STATE *img, const VkImageSubresourceLayers *subresource) { |
| 1150 | const uint32_t mip = subresource->mipLevel; |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 1151 | |
| 1152 | // Return zero extent if mip level doesn't exist |
Dave Houlton | 1150cf5 | 2017-04-27 14:38:11 -0600 | [diff] [blame] | 1153 | if (mip >= img->createInfo.mipLevels) { |
| 1154 | return VkExtent3D{0, 0, 0}; |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 1155 | } |
Dave Houlton | 1150cf5 | 2017-04-27 14:38:11 -0600 | [diff] [blame] | 1156 | |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 1157 | // 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] | 1158 | VkExtent3D extent = img->createInfo.extent; |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 1159 | extent.width = (0 == extent.width ? 0 : std::max(1U, extent.width >> mip)); |
| 1160 | extent.height = (0 == extent.height ? 0 : std::max(1U, extent.height >> mip)); |
| 1161 | extent.depth = (0 == extent.depth ? 0 : std::max(1U, extent.depth >> mip)); |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 1162 | |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1163 | // Image arrays have an effective z extent that isn't diminished by mip level |
| 1164 | if (VK_IMAGE_TYPE_3D != img->createInfo.imageType) { |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 1165 | extent.depth = img->createInfo.arrayLayers; |
| 1166 | } |
| 1167 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1168 | return extent; |
| 1169 | } |
| 1170 | |
| 1171 | // Test if the extent argument has all dimensions set to 0. |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 1172 | static inline bool IsExtentAllZeroes(const VkExtent3D *extent) { |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1173 | return ((extent->width == 0) && (extent->height == 0) && (extent->depth == 0)); |
| 1174 | } |
| 1175 | |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 1176 | // Test if the extent argument has any dimensions set to 0. |
| 1177 | static inline bool IsExtentSizeZero(const VkExtent3D *extent) { |
| 1178 | return ((extent->width == 0) || (extent->height == 0) || (extent->depth == 0)); |
| 1179 | } |
| 1180 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1181 | // Returns the image transfer granularity for a specific image scaled by compressed block size if necessary. |
| 1182 | static inline VkExtent3D GetScaledItg(layer_data *device_data, const GLOBAL_CB_NODE *cb_node, const IMAGE_STATE *img) { |
| 1183 | // Default to (0, 0, 0) granularity in case we can't find the real granularity for the physical device. |
| 1184 | VkExtent3D granularity = {0, 0, 0}; |
| 1185 | auto pPool = GetCommandPoolNode(device_data, cb_node->createInfo.commandPool); |
| 1186 | if (pPool) { |
| 1187 | granularity = |
| 1188 | GetPhysDevProperties(device_data)->queue_family_properties[pPool->queueFamilyIndex].minImageTransferGranularity; |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 1189 | if (FormatIsCompressed(img->createInfo.format)) { |
| 1190 | auto block_size = FormatCompressedTexelBlockExtent(img->createInfo.format); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1191 | granularity.width *= block_size.width; |
| 1192 | granularity.height *= block_size.height; |
| 1193 | } |
| 1194 | } |
| 1195 | return granularity; |
| 1196 | } |
| 1197 | |
| 1198 | // Test elements of a VkExtent3D structure against alignment constraints contained in another VkExtent3D structure |
| 1199 | static inline bool IsExtentAligned(const VkExtent3D *extent, const VkExtent3D *granularity) { |
| 1200 | bool valid = true; |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 1201 | if ((SafeModulo(extent->depth, granularity->depth) != 0) || (SafeModulo(extent->width, granularity->width) != 0) || |
| 1202 | (SafeModulo(extent->height, granularity->height) != 0)) { |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1203 | valid = false; |
| 1204 | } |
| 1205 | return valid; |
| 1206 | } |
| 1207 | |
| 1208 | // Check elements of a VkOffset3D structure against a queue family's Image Transfer Granularity values |
| 1209 | static inline bool CheckItgOffset(layer_data *device_data, const GLOBAL_CB_NODE *cb_node, const VkOffset3D *offset, |
| 1210 | const VkExtent3D *granularity, const uint32_t i, const char *function, const char *member) { |
| 1211 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 1212 | bool skip = false; |
| 1213 | VkExtent3D offset_extent = {}; |
| 1214 | offset_extent.width = static_cast<uint32_t>(abs(offset->x)); |
| 1215 | offset_extent.height = static_cast<uint32_t>(abs(offset->y)); |
| 1216 | offset_extent.depth = static_cast<uint32_t>(abs(offset->z)); |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 1217 | if (IsExtentAllZeroes(granularity)) { |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1218 | // 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] | 1219 | if (IsExtentAllZeroes(&offset_extent) == false) { |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 1220 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1221 | HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_IMAGE_TRANSFER_GRANULARITY, "DS", |
| 1222 | "%s: pRegion[%d].%s (x=%d, y=%d, z=%d) must be (x=0, y=0, z=0) " |
| 1223 | "when the command buffer's queue family image transfer granularity is (w=0, h=0, d=0).", |
| 1224 | function, i, member, offset->x, offset->y, offset->z); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1225 | } |
| 1226 | } else { |
| 1227 | // If the queue family image transfer granularity is not (0, 0, 0), then the offset dimensions must always be even |
| 1228 | // integer multiples of the image transfer granularity. |
| 1229 | if (IsExtentAligned(&offset_extent, granularity) == false) { |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 1230 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1231 | HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_IMAGE_TRANSFER_GRANULARITY, "DS", |
| 1232 | "%s: pRegion[%d].%s (x=%d, y=%d, z=%d) dimensions must be even integer " |
| 1233 | "multiples of this command buffer's queue family image transfer granularity (w=%d, h=%d, d=%d).", |
| 1234 | function, i, member, offset->x, offset->y, offset->z, granularity->width, granularity->height, |
| 1235 | granularity->depth); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1236 | } |
| 1237 | } |
| 1238 | return skip; |
| 1239 | } |
| 1240 | |
| 1241 | // Check elements of a VkExtent3D structure against a queue family's Image Transfer Granularity values |
| 1242 | static inline bool CheckItgExtent(layer_data *device_data, const GLOBAL_CB_NODE *cb_node, const VkExtent3D *extent, |
| 1243 | const VkOffset3D *offset, const VkExtent3D *granularity, const VkExtent3D *subresource_extent, |
| 1244 | const uint32_t i, const char *function, const char *member) { |
| 1245 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 1246 | bool skip = false; |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 1247 | if (IsExtentAllZeroes(granularity)) { |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1248 | // If the queue family image transfer granularity is (0, 0, 0), then the extent must always match the image |
| 1249 | // subresource extent. |
| 1250 | if (IsExtentEqual(extent, subresource_extent) == false) { |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 1251 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1252 | HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_IMAGE_TRANSFER_GRANULARITY, "DS", |
| 1253 | "%s: pRegion[%d].%s (w=%d, h=%d, d=%d) must match the image subresource extents (w=%d, h=%d, d=%d) " |
| 1254 | "when the command buffer's queue family image transfer granularity is (w=0, h=0, d=0).", |
| 1255 | function, i, member, extent->width, extent->height, extent->depth, subresource_extent->width, |
| 1256 | subresource_extent->height, subresource_extent->depth); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1257 | } |
| 1258 | } else { |
| 1259 | // If the queue family image transfer granularity is not (0, 0, 0), then the extent dimensions must always be even |
| 1260 | // integer multiples of the image transfer granularity or the offset + extent dimensions must always match the image |
| 1261 | // subresource extent dimensions. |
| 1262 | VkExtent3D offset_extent_sum = {}; |
| 1263 | offset_extent_sum.width = static_cast<uint32_t>(abs(offset->x)) + extent->width; |
| 1264 | offset_extent_sum.height = static_cast<uint32_t>(abs(offset->y)) + extent->height; |
| 1265 | 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] | 1266 | |
| 1267 | bool x_ok = |
| 1268 | ((0 == SafeModulo(extent->width, granularity->width)) || (subresource_extent->width == offset_extent_sum.width)); |
| 1269 | bool y_ok = |
| 1270 | ((0 == SafeModulo(extent->height, granularity->height)) || (subresource_extent->height == offset_extent_sum.height)); |
| 1271 | bool z_ok = |
| 1272 | ((0 == SafeModulo(extent->depth, granularity->depth)) || (subresource_extent->depth == offset_extent_sum.depth)); |
| 1273 | |
| 1274 | if (!(x_ok && y_ok && z_ok)) { |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1275 | skip |= |
Mark Lobodzinski | 0827aec | 2017-03-21 16:41:45 -0600 | [diff] [blame] | 1276 | 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] | 1277 | HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_IMAGE_TRANSFER_GRANULARITY, "DS", |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1278 | "%s: pRegion[%d].%s (w=%d, h=%d, d=%d) dimensions must be even integer multiples of this command buffer's " |
| 1279 | "queue family image transfer granularity (w=%d, h=%d, d=%d) or offset (x=%d, y=%d, z=%d) + " |
| 1280 | "extent (w=%d, h=%d, d=%d) must match the image subresource extents (w=%d, h=%d, d=%d).", |
| 1281 | function, i, member, extent->width, extent->height, extent->depth, granularity->width, granularity->height, |
| 1282 | granularity->depth, offset->x, offset->y, offset->z, extent->width, extent->height, extent->depth, |
| 1283 | subresource_extent->width, subresource_extent->height, subresource_extent->depth); |
| 1284 | } |
| 1285 | } |
| 1286 | return skip; |
| 1287 | } |
| 1288 | |
| 1289 | // Check a uint32_t width or stride value against a queue family's Image Transfer Granularity width value |
| 1290 | static inline bool CheckItgInt(layer_data *device_data, const GLOBAL_CB_NODE *cb_node, const uint32_t value, |
| 1291 | const uint32_t granularity, const uint32_t i, const char *function, const char *member) { |
| 1292 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 1293 | |
| 1294 | bool skip = false; |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 1295 | if (SafeModulo(value, granularity) != 0) { |
Mark Lobodzinski | 0827aec | 2017-03-21 16:41:45 -0600 | [diff] [blame] | 1296 | 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] | 1297 | HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_IMAGE_TRANSFER_GRANULARITY, "DS", |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1298 | "%s: pRegion[%d].%s (%d) must be an even integer multiple of this command buffer's queue family image " |
| 1299 | "transfer granularity width (%d).", |
| 1300 | function, i, member, value, granularity); |
| 1301 | } |
| 1302 | return skip; |
| 1303 | } |
| 1304 | |
| 1305 | // Check a VkDeviceSize value against a queue family's Image Transfer Granularity width value |
| 1306 | static inline bool CheckItgSize(layer_data *device_data, const GLOBAL_CB_NODE *cb_node, const VkDeviceSize value, |
| 1307 | const uint32_t granularity, const uint32_t i, const char *function, const char *member) { |
| 1308 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 1309 | bool skip = false; |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 1310 | if (SafeModulo(value, granularity) != 0) { |
Mark Lobodzinski | 0827aec | 2017-03-21 16:41:45 -0600 | [diff] [blame] | 1311 | 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] | 1312 | HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_IMAGE_TRANSFER_GRANULARITY, "DS", |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1313 | "%s: pRegion[%d].%s (%" PRIdLEAST64 |
| 1314 | ") must be an even integer multiple of this command buffer's queue family image transfer " |
| 1315 | "granularity width (%d).", |
| 1316 | function, i, member, value, granularity); |
| 1317 | } |
| 1318 | return skip; |
| 1319 | } |
| 1320 | |
| 1321 | // Check valid usage Image Tranfer Granularity requirements for elements of a VkBufferImageCopy structure |
| 1322 | bool ValidateCopyBufferImageTransferGranularityRequirements(layer_data *device_data, const GLOBAL_CB_NODE *cb_node, |
| 1323 | const IMAGE_STATE *img, const VkBufferImageCopy *region, |
| 1324 | const uint32_t i, const char *function) { |
| 1325 | bool skip = false; |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 1326 | if (FormatIsCompressed(img->createInfo.format) == true) { |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1327 | // TODO: Add granularity checking for compressed formats |
| 1328 | |
| 1329 | // bufferRowLength must be a multiple of the compressed texel block width |
| 1330 | // bufferImageHeight must be a multiple of the compressed texel block height |
| 1331 | // all members of imageOffset must be a multiple of the corresponding dimensions of the compressed texel block |
| 1332 | // bufferOffset must be a multiple of the compressed texel block size in bytes |
| 1333 | // imageExtent.width must be a multiple of the compressed texel block width or (imageExtent.width + imageOffset.x) |
| 1334 | // must equal the image subresource width |
| 1335 | // imageExtent.height must be a multiple of the compressed texel block height or (imageExtent.height + imageOffset.y) |
| 1336 | // must equal the image subresource height |
| 1337 | // imageExtent.depth must be a multiple of the compressed texel block depth or (imageExtent.depth + imageOffset.z) |
| 1338 | // must equal the image subresource depth |
| 1339 | } else { |
| 1340 | VkExtent3D granularity = GetScaledItg(device_data, cb_node, img); |
| 1341 | skip |= CheckItgSize(device_data, cb_node, region->bufferOffset, granularity.width, i, function, "bufferOffset"); |
| 1342 | skip |= CheckItgInt(device_data, cb_node, region->bufferRowLength, granularity.width, i, function, "bufferRowLength"); |
| 1343 | skip |= CheckItgInt(device_data, cb_node, region->bufferImageHeight, granularity.width, i, function, "bufferImageHeight"); |
| 1344 | skip |= CheckItgOffset(device_data, cb_node, ®ion->imageOffset, &granularity, i, function, "imageOffset"); |
| 1345 | VkExtent3D subresource_extent = GetImageSubresourceExtent(img, ®ion->imageSubresource); |
| 1346 | skip |= CheckItgExtent(device_data, cb_node, ®ion->imageExtent, ®ion->imageOffset, &granularity, &subresource_extent, |
| 1347 | i, function, "imageExtent"); |
| 1348 | } |
| 1349 | return skip; |
| 1350 | } |
| 1351 | |
| 1352 | // Check valid usage Image Tranfer Granularity requirements for elements of a VkImageCopy structure |
| 1353 | bool ValidateCopyImageTransferGranularityRequirements(layer_data *device_data, const GLOBAL_CB_NODE *cb_node, |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1354 | const IMAGE_STATE *src_img, const IMAGE_STATE *dst_img, |
| 1355 | const VkImageCopy *region, const uint32_t i, const char *function) { |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1356 | bool skip = false; |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1357 | VkExtent3D granularity = GetScaledItg(device_data, cb_node, src_img); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1358 | skip |= CheckItgOffset(device_data, cb_node, ®ion->srcOffset, &granularity, i, function, "srcOffset"); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1359 | VkExtent3D subresource_extent = GetImageSubresourceExtent(src_img, ®ion->srcSubresource); |
| 1360 | skip |= CheckItgExtent(device_data, cb_node, ®ion->extent, ®ion->srcOffset, &granularity, &subresource_extent, i, |
| 1361 | function, "extent"); |
| 1362 | |
| 1363 | granularity = GetScaledItg(device_data, cb_node, dst_img); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1364 | skip |= CheckItgOffset(device_data, cb_node, ®ion->dstOffset, &granularity, i, function, "dstOffset"); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1365 | subresource_extent = GetImageSubresourceExtent(dst_img, ®ion->dstSubresource); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1366 | skip |= CheckItgExtent(device_data, cb_node, ®ion->extent, ®ion->dstOffset, &granularity, &subresource_extent, i, |
| 1367 | function, "extent"); |
| 1368 | return skip; |
| 1369 | } |
| 1370 | |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1371 | // Validate contents of a VkImageCopy struct |
| 1372 | bool ValidateImageCopyData(const layer_data *device_data, const debug_report_data *report_data, const uint32_t regionCount, |
| 1373 | const VkImageCopy *ic_regions, const IMAGE_STATE *src_state, const IMAGE_STATE *dst_state) { |
| 1374 | bool skip = false; |
| 1375 | |
| 1376 | for (uint32_t i = 0; i < regionCount; i++) { |
| 1377 | VkImageCopy image_copy = ic_regions[i]; |
| 1378 | bool slice_override = false; |
| 1379 | uint32_t depth_slices = 0; |
| 1380 | |
| 1381 | // Special case for copying between a 1D/2D array and a 3D image |
| 1382 | // TBD: This seems like the only way to reconcile 3 mutually-exclusive VU checks for 2D/3D copies. Heads up. |
| 1383 | if ((VK_IMAGE_TYPE_3D == src_state->createInfo.imageType) && (VK_IMAGE_TYPE_3D != dst_state->createInfo.imageType)) { |
| 1384 | depth_slices = image_copy.dstSubresource.layerCount; // Slice count from 2D subresource |
| 1385 | slice_override = (depth_slices != 1); |
| 1386 | } else if ((VK_IMAGE_TYPE_3D == dst_state->createInfo.imageType) && (VK_IMAGE_TYPE_3D != src_state->createInfo.imageType)) { |
| 1387 | depth_slices = image_copy.srcSubresource.layerCount; // Slice count from 2D subresource |
| 1388 | slice_override = (depth_slices != 1); |
| 1389 | } |
| 1390 | |
| 1391 | // Do all checks on source image |
| 1392 | // |
| 1393 | if (src_state->createInfo.imageType == VK_IMAGE_TYPE_1D) { |
| 1394 | if ((0 != image_copy.srcOffset.y) || (1 != image_copy.extent.height)) { |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1395 | skip |= |
| 1396 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 1397 | reinterpret_cast<const uint64_t &>(src_state->image), __LINE__, VALIDATION_ERROR_09c00124, "IMAGE", |
| 1398 | "vkCmdCopyImage(): pRegion[%d] srcOffset.y is %d and extent.height is %d. For 1D images these must " |
| 1399 | "be 0 and 1, respectively. %s", |
| 1400 | i, image_copy.srcOffset.y, image_copy.extent.height, validation_error_map[VALIDATION_ERROR_09c00124]); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1401 | } |
| 1402 | } |
| 1403 | |
| 1404 | if ((src_state->createInfo.imageType == VK_IMAGE_TYPE_1D) || (src_state->createInfo.imageType == VK_IMAGE_TYPE_2D)) { |
| 1405 | if ((0 != image_copy.srcOffset.z) || (1 != image_copy.extent.depth)) { |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1406 | skip |= |
| 1407 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 1408 | reinterpret_cast<const uint64_t &>(src_state->image), __LINE__, VALIDATION_ERROR_09c00128, "IMAGE", |
| 1409 | "vkCmdCopyImage(): pRegion[%d] srcOffset.z is %d and extent.depth is %d. For 1D and 2D images " |
| 1410 | "these must be 0 and 1, respectively. %s", |
| 1411 | i, image_copy.srcOffset.z, image_copy.extent.depth, validation_error_map[VALIDATION_ERROR_09c00128]); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1412 | } |
| 1413 | } |
| 1414 | |
| 1415 | // VU01199 changed with mnt1 |
Mark Lobodzinski | 28426ae | 2017-06-01 07:56:38 -0600 | [diff] [blame] | 1416 | if (GetDeviceExtensions(device_data)->vk_khr_maintenance1) { |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1417 | if (src_state->createInfo.imageType == VK_IMAGE_TYPE_3D) { |
| 1418 | if ((0 != image_copy.srcSubresource.baseArrayLayer) || (1 != image_copy.srcSubresource.layerCount)) { |
| 1419 | skip |= |
| 1420 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1421 | reinterpret_cast<const uint64_t &>(src_state->image), __LINE__, VALIDATION_ERROR_09c0011a, "IMAGE", |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1422 | "vkCmdCopyImage(): pRegion[%d] srcSubresource.baseArrayLayer is %d and srcSubresource.layerCount " |
| 1423 | "is %d. For VK_IMAGE_TYPE_3D images these must be 0 and 1, respectively. %s", |
| 1424 | i, image_copy.srcSubresource.baseArrayLayer, image_copy.srcSubresource.layerCount, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1425 | validation_error_map[VALIDATION_ERROR_09c0011a]); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1426 | } |
| 1427 | } |
| 1428 | } else { // Pre maint 1 |
| 1429 | if (src_state->createInfo.imageType == VK_IMAGE_TYPE_3D || dst_state->createInfo.imageType == VK_IMAGE_TYPE_3D) { |
| 1430 | if ((0 != image_copy.srcSubresource.baseArrayLayer) || (1 != image_copy.srcSubresource.layerCount)) { |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1431 | skip |= |
| 1432 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 1433 | reinterpret_cast<const uint64_t &>(src_state->image), __LINE__, VALIDATION_ERROR_09c0011a, "IMAGE", |
| 1434 | "vkCmdCopyImage(): pRegion[%d] srcSubresource.baseArrayLayer is %d and " |
| 1435 | "srcSubresource.layerCount is %d. For copies with either source or dest of type " |
| 1436 | "VK_IMAGE_TYPE_3D, these must be 0 and 1, respectively. %s", |
| 1437 | i, image_copy.srcSubresource.baseArrayLayer, image_copy.srcSubresource.layerCount, |
| 1438 | validation_error_map[VALIDATION_ERROR_09c0011a]); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1439 | } |
| 1440 | } |
| 1441 | } |
| 1442 | |
| 1443 | // TODO: this VU is redundant with VU01224. Gitlab issue 812 submitted to get it removed from the spec. |
| 1444 | if ((image_copy.srcSubresource.baseArrayLayer >= src_state->createInfo.arrayLayers) || |
| 1445 | (image_copy.srcSubresource.baseArrayLayer + image_copy.srcSubresource.layerCount > src_state->createInfo.arrayLayers)) { |
| 1446 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1447 | reinterpret_cast<const uint64_t &>(src_state->image), __LINE__, VALIDATION_ERROR_09c0012a, "IMAGE", |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1448 | "vkCmdCopyImage(): pRegion[%d] srcSubresource.baseArrayLayer (%d) must be less than the source image's " |
| 1449 | "arrayLayers (%d), and the sum of baseArrayLayer and srcSubresource.layerCount (%d) must be less than " |
| 1450 | "or equal to the source image's arrayLayers. %s", |
| 1451 | i, image_copy.srcSubresource.baseArrayLayer, src_state->createInfo.arrayLayers, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1452 | image_copy.srcSubresource.layerCount, validation_error_map[VALIDATION_ERROR_09c0012a]); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1453 | } |
| 1454 | |
| 1455 | // Checks that apply only to compressed images |
| 1456 | if (FormatIsCompressed(src_state->createInfo.format)) { |
| 1457 | VkExtent3D block_size = FormatCompressedTexelBlockExtent(src_state->createInfo.format); |
| 1458 | |
| 1459 | // image offsets must be multiples of block dimensions |
| 1460 | if ((SafeModulo(image_copy.srcOffset.x, block_size.width) != 0) || |
| 1461 | (SafeModulo(image_copy.srcOffset.y, block_size.height) != 0) || |
| 1462 | (SafeModulo(image_copy.srcOffset.z, block_size.depth) != 0)) { |
| 1463 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1464 | reinterpret_cast<const uint64_t &>(src_state->image), __LINE__, VALIDATION_ERROR_09c0013a, "IMAGE", |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1465 | "vkCmdCopyImage(): pRegion[%d] srcOffset (%d, %d) must be multiples of the compressed image's " |
| 1466 | "texel width & height (%d, %d). %s.", |
| 1467 | i, image_copy.srcOffset.x, image_copy.srcOffset.y, block_size.width, block_size.height, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1468 | validation_error_map[VALIDATION_ERROR_09c0013a]); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1469 | } |
| 1470 | |
| 1471 | // extent width must be a multiple of block width, or extent+offset width must equal subresource width |
| 1472 | VkExtent3D mip_extent = GetImageSubresourceExtent(src_state, &(image_copy.srcSubresource)); |
| 1473 | if ((SafeModulo(image_copy.extent.width, block_size.width) != 0) && |
| 1474 | (image_copy.extent.width + image_copy.srcOffset.x != mip_extent.width)) { |
| 1475 | skip |= |
| 1476 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1477 | reinterpret_cast<const uint64_t &>(src_state->image), __LINE__, VALIDATION_ERROR_09c0013c, "IMAGE", |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1478 | "vkCmdCopyImage(): pRegion[%d] extent width (%d) must be a multiple of the compressed texture block " |
| 1479 | "width (%d), or when added to srcOffset.x (%d) must equal the image subresource width (%d). %s.", |
| 1480 | i, image_copy.extent.width, block_size.width, image_copy.srcOffset.x, mip_extent.width, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1481 | validation_error_map[VALIDATION_ERROR_09c0013c]); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1482 | } |
| 1483 | |
| 1484 | // extent height must be a multiple of block height, or extent+offset height must equal subresource height |
| 1485 | if ((SafeModulo(image_copy.extent.height, block_size.height) != 0) && |
| 1486 | (image_copy.extent.height + image_copy.srcOffset.y != mip_extent.height)) { |
| 1487 | skip |= |
| 1488 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1489 | reinterpret_cast<const uint64_t &>(src_state->image), __LINE__, VALIDATION_ERROR_09c0013e, "IMAGE", |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1490 | "vkCmdCopyImage(): pRegion[%d] extent height (%d) must be a multiple of the compressed texture block " |
| 1491 | "height (%d), or when added to srcOffset.y (%d) must equal the image subresource height (%d). %s.", |
| 1492 | i, image_copy.extent.height, block_size.height, image_copy.srcOffset.y, mip_extent.height, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1493 | validation_error_map[VALIDATION_ERROR_09c0013e]); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1494 | } |
| 1495 | |
| 1496 | // extent depth must be a multiple of block depth, or extent+offset depth must equal subresource depth |
| 1497 | uint32_t copy_depth = (slice_override ? depth_slices : image_copy.extent.depth); |
| 1498 | if ((SafeModulo(copy_depth, block_size.depth) != 0) && (copy_depth + image_copy.srcOffset.z != mip_extent.depth)) { |
| 1499 | skip |= |
| 1500 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1501 | reinterpret_cast<const uint64_t &>(src_state->image), __LINE__, VALIDATION_ERROR_09c00140, "IMAGE", |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1502 | "vkCmdCopyImage(): pRegion[%d] extent width (%d) must be a multiple of the compressed texture block " |
| 1503 | "depth (%d), or when added to srcOffset.z (%d) must equal the image subresource depth (%d). %s.", |
| 1504 | i, image_copy.extent.depth, block_size.depth, image_copy.srcOffset.z, mip_extent.depth, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1505 | validation_error_map[VALIDATION_ERROR_09c00140]); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1506 | } |
| 1507 | } // Compressed |
| 1508 | |
| 1509 | // Do all checks on dest image |
| 1510 | // |
| 1511 | if (dst_state->createInfo.imageType == VK_IMAGE_TYPE_1D) { |
| 1512 | if ((0 != image_copy.dstOffset.y) || (1 != image_copy.extent.height)) { |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1513 | skip |= |
| 1514 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 1515 | reinterpret_cast<const uint64_t &>(dst_state->image), __LINE__, VALIDATION_ERROR_09c00130, "IMAGE", |
| 1516 | "vkCmdCopyImage(): pRegion[%d] dstOffset.y is %d and extent.height is %d. For 1D images these must " |
| 1517 | "be 0 and 1, respectively. %s", |
| 1518 | i, image_copy.dstOffset.y, image_copy.extent.height, validation_error_map[VALIDATION_ERROR_09c00130]); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1519 | } |
| 1520 | } |
| 1521 | |
| 1522 | if ((dst_state->createInfo.imageType == VK_IMAGE_TYPE_1D) || (dst_state->createInfo.imageType == VK_IMAGE_TYPE_2D)) { |
| 1523 | if ((0 != image_copy.dstOffset.z) || (1 != image_copy.extent.depth)) { |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1524 | skip |= |
| 1525 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 1526 | reinterpret_cast<const uint64_t &>(dst_state->image), __LINE__, VALIDATION_ERROR_09c00134, "IMAGE", |
| 1527 | "vkCmdCopyImage(): pRegion[%d] dstOffset.z is %d and extent.depth is %d. For 1D and 2D images " |
| 1528 | "these must be 0 and 1, respectively. %s", |
| 1529 | i, image_copy.dstOffset.z, image_copy.extent.depth, validation_error_map[VALIDATION_ERROR_09c00134]); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1530 | } |
| 1531 | } |
| 1532 | |
| 1533 | if (dst_state->createInfo.imageType == VK_IMAGE_TYPE_3D) { |
| 1534 | if ((0 != image_copy.dstSubresource.baseArrayLayer) || (1 != image_copy.dstSubresource.layerCount)) { |
| 1535 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1536 | reinterpret_cast<const uint64_t &>(dst_state->image), __LINE__, VALIDATION_ERROR_09c0011a, "IMAGE", |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1537 | "vkCmdCopyImage(): pRegion[%d] dstSubresource.baseArrayLayer is %d and dstSubresource.layerCount " |
| 1538 | "is %d. For VK_IMAGE_TYPE_3D images these must be 0 and 1, respectively. %s", |
| 1539 | i, image_copy.dstSubresource.baseArrayLayer, image_copy.dstSubresource.layerCount, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1540 | validation_error_map[VALIDATION_ERROR_09c0011a]); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1541 | } |
| 1542 | } |
| 1543 | // VU01199 changed with mnt1 |
Mark Lobodzinski | 28426ae | 2017-06-01 07:56:38 -0600 | [diff] [blame] | 1544 | if (GetDeviceExtensions(device_data)->vk_khr_maintenance1) { |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1545 | if (dst_state->createInfo.imageType == VK_IMAGE_TYPE_3D) { |
| 1546 | if ((0 != image_copy.dstSubresource.baseArrayLayer) || (1 != image_copy.dstSubresource.layerCount)) { |
| 1547 | skip |= |
| 1548 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1549 | reinterpret_cast<const uint64_t &>(dst_state->image), __LINE__, VALIDATION_ERROR_09c0011a, "IMAGE", |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1550 | "vkCmdCopyImage(): pRegion[%d] dstSubresource.baseArrayLayer is %d and dstSubresource.layerCount " |
| 1551 | "is %d. For VK_IMAGE_TYPE_3D images these must be 0 and 1, respectively. %s", |
| 1552 | i, image_copy.dstSubresource.baseArrayLayer, image_copy.dstSubresource.layerCount, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1553 | validation_error_map[VALIDATION_ERROR_09c0011a]); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1554 | } |
| 1555 | } |
| 1556 | } else { // Pre maint 1 |
| 1557 | if (src_state->createInfo.imageType == VK_IMAGE_TYPE_3D || dst_state->createInfo.imageType == VK_IMAGE_TYPE_3D) { |
| 1558 | if ((0 != image_copy.dstSubresource.baseArrayLayer) || (1 != image_copy.dstSubresource.layerCount)) { |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1559 | skip |= |
| 1560 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 1561 | reinterpret_cast<const uint64_t &>(dst_state->image), __LINE__, VALIDATION_ERROR_09c0011a, "IMAGE", |
| 1562 | "vkCmdCopyImage(): pRegion[%d] dstSubresource.baseArrayLayer is %d and " |
| 1563 | "dstSubresource.layerCount is %d. For copies with either source or dest of type " |
| 1564 | "VK_IMAGE_TYPE_3D, these must be 0 and 1, respectively. %s", |
| 1565 | i, image_copy.dstSubresource.baseArrayLayer, image_copy.dstSubresource.layerCount, |
| 1566 | validation_error_map[VALIDATION_ERROR_09c0011a]); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1567 | } |
| 1568 | } |
| 1569 | } |
| 1570 | |
| 1571 | // TODO: this VU is redundant with VU01224. Gitlab issue 812 submitted to get it removed from the spec. |
| 1572 | if ((image_copy.dstSubresource.baseArrayLayer >= dst_state->createInfo.arrayLayers) || |
| 1573 | (image_copy.dstSubresource.baseArrayLayer + image_copy.dstSubresource.layerCount > dst_state->createInfo.arrayLayers)) { |
| 1574 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1575 | reinterpret_cast<const uint64_t &>(dst_state->image), __LINE__, VALIDATION_ERROR_09c00136, "IMAGE", |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1576 | "vkCmdCopyImage(): pRegion[%d] dstSubresource.baseArrayLayer (%d) must be less than the dest image's " |
| 1577 | "arrayLayers (%d), and the sum of baseArrayLayer and dstSubresource.layerCount (%d) must be less than " |
| 1578 | "or equal to the dest image's arrayLayers. %s", |
| 1579 | i, image_copy.dstSubresource.baseArrayLayer, dst_state->createInfo.arrayLayers, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1580 | image_copy.dstSubresource.layerCount, validation_error_map[VALIDATION_ERROR_09c00136]); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1581 | } |
| 1582 | |
| 1583 | // Checks that apply only to compressed images |
| 1584 | if (FormatIsCompressed(dst_state->createInfo.format)) { |
| 1585 | VkExtent3D block_size = FormatCompressedTexelBlockExtent(dst_state->createInfo.format); |
| 1586 | |
| 1587 | // image offsets must be multiples of block dimensions |
| 1588 | if ((SafeModulo(image_copy.dstOffset.x, block_size.width) != 0) || |
| 1589 | (SafeModulo(image_copy.dstOffset.y, block_size.height) != 0) || |
| 1590 | (SafeModulo(image_copy.dstOffset.z, block_size.depth) != 0)) { |
| 1591 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1592 | reinterpret_cast<const uint64_t &>(dst_state->image), __LINE__, VALIDATION_ERROR_09c00144, "IMAGE", |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1593 | "vkCmdCopyImage(): pRegion[%d] dstOffset (%d, %d) must be multiples of the compressed image's " |
| 1594 | "texel width & height (%d, %d). %s.", |
| 1595 | i, image_copy.dstOffset.x, image_copy.dstOffset.y, block_size.width, block_size.height, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1596 | validation_error_map[VALIDATION_ERROR_09c00144]); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1597 | } |
| 1598 | |
| 1599 | // extent width must be a multiple of block width, or extent+offset width must equal subresource width |
| 1600 | VkExtent3D mip_extent = GetImageSubresourceExtent(dst_state, &(image_copy.dstSubresource)); |
| 1601 | if ((SafeModulo(image_copy.extent.width, block_size.width) != 0) && |
| 1602 | (image_copy.extent.width + image_copy.dstOffset.x != mip_extent.width)) { |
| 1603 | skip |= |
| 1604 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1605 | reinterpret_cast<const uint64_t &>(dst_state->image), __LINE__, VALIDATION_ERROR_09c00146, "IMAGE", |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1606 | "vkCmdCopyImage(): pRegion[%d] extent width (%d) must be a multiple of the compressed texture block " |
| 1607 | "width (%d), or when added to dstOffset.x (%d) must equal the image subresource width (%d). %s.", |
| 1608 | i, image_copy.extent.width, block_size.width, image_copy.dstOffset.x, mip_extent.width, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1609 | validation_error_map[VALIDATION_ERROR_09c00146]); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1610 | } |
| 1611 | |
| 1612 | // extent height must be a multiple of block height, or extent+offset height must equal subresource height |
| 1613 | if ((SafeModulo(image_copy.extent.height, block_size.height) != 0) && |
| 1614 | (image_copy.extent.height + image_copy.dstOffset.y != mip_extent.height)) { |
| 1615 | skip |= |
| 1616 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1617 | reinterpret_cast<const uint64_t &>(dst_state->image), __LINE__, VALIDATION_ERROR_09c00148, "IMAGE", |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1618 | "vkCmdCopyImage(): pRegion[%d] extent height (%d) must be a multiple of the compressed texture block " |
| 1619 | "height (%d), or when added to dstOffset.y (%d) must equal the image subresource height (%d). %s.", |
| 1620 | i, image_copy.extent.height, block_size.height, image_copy.dstOffset.y, mip_extent.height, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1621 | validation_error_map[VALIDATION_ERROR_09c00148]); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1622 | } |
| 1623 | |
| 1624 | // extent depth must be a multiple of block depth, or extent+offset depth must equal subresource depth |
| 1625 | uint32_t copy_depth = (slice_override ? depth_slices : image_copy.extent.depth); |
| 1626 | if ((SafeModulo(copy_depth, block_size.depth) != 0) && (copy_depth + image_copy.dstOffset.z != mip_extent.depth)) { |
| 1627 | skip |= |
| 1628 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1629 | reinterpret_cast<const uint64_t &>(dst_state->image), __LINE__, VALIDATION_ERROR_09c0014a, "IMAGE", |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1630 | "vkCmdCopyImage(): pRegion[%d] extent width (%d) must be a multiple of the compressed texture block " |
| 1631 | "depth (%d), or when added to dstOffset.z (%d) must equal the image subresource depth (%d). %s.", |
| 1632 | i, image_copy.extent.depth, block_size.depth, image_copy.dstOffset.z, mip_extent.depth, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1633 | validation_error_map[VALIDATION_ERROR_09c0014a]); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1634 | } |
| 1635 | } // Compressed |
| 1636 | } |
| 1637 | return skip; |
| 1638 | } |
| 1639 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 1640 | 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] | 1641 | IMAGE_STATE *dst_image_state, uint32_t region_count, const VkImageCopy *regions, |
| 1642 | VkImageLayout src_image_layout, VkImageLayout dst_image_layout) { |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1643 | bool skip = false; |
| 1644 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1645 | skip = ValidateImageCopyData(device_data, report_data, region_count, regions, src_image_state, dst_image_state); |
| 1646 | |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1647 | VkCommandBuffer command_buffer = cb_node->commandBuffer; |
| 1648 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1649 | for (uint32_t i = 0; i < region_count; i++) { |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1650 | bool slice_override = false; |
| 1651 | uint32_t depth_slices = 0; |
| 1652 | |
| 1653 | // Special case for copying between a 1D/2D array and a 3D image |
| 1654 | // TBD: This seems like the only way to reconcile 3 mutually-exclusive VU checks for 2D/3D copies. Heads up. |
| 1655 | if ((VK_IMAGE_TYPE_3D == src_image_state->createInfo.imageType) && |
| 1656 | (VK_IMAGE_TYPE_3D != dst_image_state->createInfo.imageType)) { |
| 1657 | depth_slices = regions[i].dstSubresource.layerCount; // Slice count from 2D subresource |
| 1658 | slice_override = (depth_slices != 1); |
| 1659 | } else if ((VK_IMAGE_TYPE_3D == dst_image_state->createInfo.imageType) && |
| 1660 | (VK_IMAGE_TYPE_3D != src_image_state->createInfo.imageType)) { |
| 1661 | depth_slices = regions[i].srcSubresource.layerCount; // Slice count from 2D subresource |
| 1662 | slice_override = (depth_slices != 1); |
| 1663 | } |
| 1664 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1665 | if (regions[i].srcSubresource.layerCount == 0) { |
| 1666 | std::stringstream ss; |
| 1667 | ss << "vkCmdCopyImage: number of layers in pRegions[" << i << "] srcSubresource is zero"; |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 1668 | skip |= |
| 1669 | log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1670 | 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] | 1671 | } |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1672 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1673 | if (regions[i].dstSubresource.layerCount == 0) { |
| 1674 | std::stringstream ss; |
| 1675 | ss << "vkCmdCopyImage: number of layers in pRegions[" << i << "] dstSubresource is zero"; |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 1676 | skip |= |
| 1677 | log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1678 | 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] | 1679 | } |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1680 | |
Mark Lobodzinski | 28426ae | 2017-06-01 07:56:38 -0600 | [diff] [blame] | 1681 | if (GetDeviceExtensions(device_data)->vk_khr_maintenance1) { |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1682 | // No chance of mismatch if we're overriding depth slice count |
| 1683 | if (!slice_override) { |
| 1684 | // The number of depth slices in srcSubresource and dstSubresource must match |
| 1685 | // Depth comes from layerCount for 1D,2D resources, from extent.depth for 3D |
| 1686 | uint32_t src_slices = |
| 1687 | (VK_IMAGE_TYPE_3D == src_image_state->createInfo.imageType ? regions[i].extent.depth |
| 1688 | : regions[i].srcSubresource.layerCount); |
| 1689 | uint32_t dst_slices = |
| 1690 | (VK_IMAGE_TYPE_3D == dst_image_state->createInfo.imageType ? regions[i].extent.depth |
| 1691 | : regions[i].dstSubresource.layerCount); |
| 1692 | if (src_slices != dst_slices) { |
| 1693 | std::stringstream ss; |
| 1694 | ss << "vkCmdCopyImage: number of depth slices in source and destination subresources for pRegions[" << i |
| 1695 | << "] do not match"; |
| 1696 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1697 | reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_09c00118, "IMAGE", |
| 1698 | "%s. %s", ss.str().c_str(), validation_error_map[VALIDATION_ERROR_09c00118]); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1699 | } |
| 1700 | } |
| 1701 | } else { |
Mike Schuchardt | 64b5bb7 | 2017-03-21 16:33:26 -0600 | [diff] [blame] | 1702 | // For each region the layerCount member of srcSubresource and dstSubresource must match |
| 1703 | if (regions[i].srcSubresource.layerCount != regions[i].dstSubresource.layerCount) { |
| 1704 | std::stringstream ss; |
| 1705 | ss << "vkCmdCopyImage: number of layers in source and destination subresources for pRegions[" << i |
| 1706 | << "] do not match"; |
| 1707 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1708 | HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_09c00118, "IMAGE", "%s. %s", |
| 1709 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_09c00118]); |
Mike Schuchardt | 64b5bb7 | 2017-03-21 16:33:26 -0600 | [diff] [blame] | 1710 | } |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1711 | } |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1712 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1713 | // For each region, the aspectMask member of srcSubresource and dstSubresource must match |
| 1714 | if (regions[i].srcSubresource.aspectMask != regions[i].dstSubresource.aspectMask) { |
| 1715 | char const str[] = "vkCmdCopyImage: Src and dest aspectMasks for each region must match"; |
| 1716 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1717 | HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_09c00112, "IMAGE", "%s. %s", str, |
| 1718 | validation_error_map[VALIDATION_ERROR_09c00112]); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1719 | } |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1720 | |
Dave Houlton | 4eaaf3a | 2017-03-14 11:31:20 -0600 | [diff] [blame] | 1721 | // For each region, the aspectMask member of srcSubresource must be present in the source image |
| 1722 | if (!VerifyAspectsPresent(regions[i].srcSubresource.aspectMask, src_image_state->createInfo.format)) { |
| 1723 | std::stringstream ss; |
| 1724 | ss << "vkCmdCopyImage: pRegion[" << i |
| 1725 | << "] srcSubresource.aspectMask cannot specify aspects not present in source image"; |
| 1726 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1727 | HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_09c0011c, "IMAGE", "%s. %s", |
| 1728 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_09c0011c]); |
Dave Houlton | 4eaaf3a | 2017-03-14 11:31:20 -0600 | [diff] [blame] | 1729 | } |
| 1730 | |
| 1731 | // For each region, the aspectMask member of dstSubresource must be present in the destination image |
| 1732 | if (!VerifyAspectsPresent(regions[i].dstSubresource.aspectMask, dst_image_state->createInfo.format)) { |
| 1733 | std::stringstream ss; |
| 1734 | ss << "vkCmdCopyImage: pRegion[" << i << "] dstSubresource.aspectMask cannot specify aspects not present in dest image"; |
| 1735 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1736 | HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_09c0011e, "IMAGE", "%s. %s", |
| 1737 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_09c0011e]); |
Dave Houlton | 4eaaf3a | 2017-03-14 11:31:20 -0600 | [diff] [blame] | 1738 | } |
| 1739 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1740 | // AspectMask must not contain VK_IMAGE_ASPECT_METADATA_BIT |
| 1741 | if ((regions[i].srcSubresource.aspectMask & VK_IMAGE_ASPECT_METADATA_BIT) || |
| 1742 | (regions[i].dstSubresource.aspectMask & VK_IMAGE_ASPECT_METADATA_BIT)) { |
| 1743 | std::stringstream ss; |
| 1744 | ss << "vkCmdCopyImage: pRegions[" << i << "] may not specify aspectMask containing VK_IMAGE_ASPECT_METADATA_BIT"; |
| 1745 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1746 | HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_0a600150, "IMAGE", "%s. %s", |
| 1747 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_0a600150]); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1748 | } |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1749 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1750 | // For each region, if aspectMask contains VK_IMAGE_ASPECT_COLOR_BIT, it must not contain either of |
| 1751 | // VK_IMAGE_ASPECT_DEPTH_BIT or VK_IMAGE_ASPECT_STENCIL_BIT |
| 1752 | if ((regions[i].srcSubresource.aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) && |
| 1753 | (regions[i].srcSubresource.aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT))) { |
| 1754 | char const str[] = "vkCmdCopyImage aspectMask cannot specify both COLOR and DEPTH/STENCIL aspects"; |
| 1755 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1756 | HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_0a60014e, "IMAGE", "%s. %s", str, |
| 1757 | validation_error_map[VALIDATION_ERROR_0a60014e]); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1758 | } |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1759 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1760 | // MipLevel must be less than the mipLevels specified in VkImageCreateInfo when the image was created |
| 1761 | if (regions[i].srcSubresource.mipLevel >= src_image_state->createInfo.mipLevels) { |
| 1762 | std::stringstream ss; |
| 1763 | ss << "vkCmdCopyImage: pRegions[" << i |
| 1764 | << "] specifies a src mipLevel greater than the number specified when the srcImage was created."; |
| 1765 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1766 | HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_0a600152, "IMAGE", "%s. %s", |
| 1767 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_0a600152]); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1768 | } |
| 1769 | if (regions[i].dstSubresource.mipLevel >= dst_image_state->createInfo.mipLevels) { |
| 1770 | std::stringstream ss; |
| 1771 | ss << "vkCmdCopyImage: pRegions[" << i |
| 1772 | << "] specifies a dst mipLevel greater than the number specified when the dstImage was created."; |
| 1773 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1774 | HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_0a600152, "IMAGE", "%s. %s", |
| 1775 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_0a600152]); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1776 | } |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1777 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1778 | // (baseArrayLayer + layerCount) must be less than or equal to the arrayLayers specified in VkImageCreateInfo when the |
| 1779 | // image was created |
| 1780 | if ((regions[i].srcSubresource.baseArrayLayer + regions[i].srcSubresource.layerCount) > |
| 1781 | src_image_state->createInfo.arrayLayers) { |
| 1782 | std::stringstream ss; |
| 1783 | ss << "vkCmdCopyImage: srcImage arrayLayers was " << src_image_state->createInfo.arrayLayers << " but subRegion[" << i |
| 1784 | << "] baseArrayLayer + layerCount is " |
| 1785 | << (regions[i].srcSubresource.baseArrayLayer + regions[i].srcSubresource.layerCount); |
| 1786 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1787 | HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_0a600154, "IMAGE", "%s. %s", |
| 1788 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_0a600154]); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1789 | } |
| 1790 | if ((regions[i].dstSubresource.baseArrayLayer + regions[i].dstSubresource.layerCount) > |
| 1791 | dst_image_state->createInfo.arrayLayers) { |
| 1792 | std::stringstream ss; |
| 1793 | ss << "vkCmdCopyImage: dstImage arrayLayers was " << dst_image_state->createInfo.arrayLayers << " but subRegion[" << i |
| 1794 | << "] baseArrayLayer + layerCount is " |
| 1795 | << (regions[i].dstSubresource.baseArrayLayer + regions[i].dstSubresource.layerCount); |
| 1796 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1797 | HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_0a600154, "IMAGE", "%s. %s", |
| 1798 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_0a600154]); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1799 | } |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1800 | |
Mike Schuchardt | 64b5bb7 | 2017-03-21 16:33:26 -0600 | [diff] [blame] | 1801 | // Check region extents for 1D-1D, 2D-2D, and 3D-3D copies |
| 1802 | if (src_image_state->createInfo.imageType == dst_image_state->createInfo.imageType) { |
| 1803 | // 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] | 1804 | VkExtent3D img_extent = GetImageSubresourceExtent(src_image_state, &(regions[i].srcSubresource)); |
| 1805 | if (0 != ExceedsBounds(®ions[i].srcOffset, ®ions[i].extent, &img_extent)) { |
Mike Schuchardt | 64b5bb7 | 2017-03-21 16:33:26 -0600 | [diff] [blame] | 1806 | std::stringstream ss; |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 1807 | ss << "vkCmdCopyImage: Source pRegion[" << i << "] with mipLevel [ " << regions[i].srcSubresource.mipLevel |
| 1808 | << " ], offset [ " << regions[i].srcOffset.x << ", " << regions[i].srcOffset.y << ", " << regions[i].srcOffset.z |
| 1809 | << " ], extent [ " << regions[i].extent.width << ", " << regions[i].extent.height << ", " |
| 1810 | << regions[i].extent.depth << " ] exceeds the source image dimensions"; |
Mike Schuchardt | 64b5bb7 | 2017-03-21 16:33:26 -0600 | [diff] [blame] | 1811 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1812 | HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_190000f4, "IMAGE", "%s. %s", |
| 1813 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_190000f4]); |
Mike Schuchardt | 64b5bb7 | 2017-03-21 16:33:26 -0600 | [diff] [blame] | 1814 | } |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1815 | |
Mike Schuchardt | 64b5bb7 | 2017-03-21 16:33:26 -0600 | [diff] [blame] | 1816 | // 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] | 1817 | img_extent = GetImageSubresourceExtent(dst_image_state, &(regions[i].dstSubresource)); |
| 1818 | if (0 != ExceedsBounds(®ions[i].dstOffset, ®ions[i].extent, &img_extent)) { |
Mike Schuchardt | 64b5bb7 | 2017-03-21 16:33:26 -0600 | [diff] [blame] | 1819 | std::stringstream ss; |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 1820 | ss << "vkCmdCopyImage: Dest pRegion[" << i << "] with mipLevel [ " << regions[i].dstSubresource.mipLevel |
| 1821 | << " ], offset [ " << regions[i].dstOffset.x << ", " << regions[i].dstOffset.y << ", " << regions[i].dstOffset.z |
| 1822 | << " ], extent [ " << regions[i].extent.width << ", " << regions[i].extent.height << ", " |
| 1823 | << regions[i].extent.depth << " ] exceeds the destination image dimensions"; |
Mike Schuchardt | 64b5bb7 | 2017-03-21 16:33:26 -0600 | [diff] [blame] | 1824 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1825 | HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_190000f6, "IMAGE", "%s. %s", |
| 1826 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_190000f6]); |
Mike Schuchardt | 64b5bb7 | 2017-03-21 16:33:26 -0600 | [diff] [blame] | 1827 | } |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1828 | } |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1829 | |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 1830 | // Each dimension offset + extent limits must fall with image subresource extent |
| 1831 | VkExtent3D subresource_extent = GetImageSubresourceExtent(src_image_state, &(regions[i].srcSubresource)); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1832 | VkExtent3D copy_extent = regions[i].extent; |
| 1833 | if (slice_override) copy_extent.depth = depth_slices; |
| 1834 | uint32_t extent_check = ExceedsBounds(&(regions[i].srcOffset), ©_extent, &subresource_extent); |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 1835 | if (extent_check & x_bit) { |
| 1836 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1837 | HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_09c00120, "IMAGE", |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 1838 | "vkCmdCopyImage: Source image pRegion %1d x-dimension offset [%1d] + extent [%1d] exceeds subResource " |
| 1839 | "width [%1d]. %s", |
| 1840 | i, regions[i].srcOffset.x, regions[i].extent.width, subresource_extent.width, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1841 | validation_error_map[VALIDATION_ERROR_09c00120]); |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 1842 | } |
| 1843 | |
| 1844 | if (extent_check & y_bit) { |
| 1845 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1846 | HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_09c00122, "IMAGE", |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 1847 | "vkCmdCopyImage: Source image pRegion %1d y-dimension offset [%1d] + extent [%1d] exceeds subResource " |
| 1848 | "height [%1d]. %s", |
| 1849 | i, regions[i].srcOffset.y, regions[i].extent.height, subresource_extent.height, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1850 | validation_error_map[VALIDATION_ERROR_09c00122]); |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 1851 | } |
| 1852 | if (extent_check & z_bit) { |
| 1853 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1854 | HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_09c00126, "IMAGE", |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 1855 | "vkCmdCopyImage: Source image pRegion %1d z-dimension offset [%1d] + extent [%1d] exceeds subResource " |
| 1856 | "depth [%1d]. %s", |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1857 | i, regions[i].srcOffset.z, copy_extent.depth, subresource_extent.depth, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1858 | validation_error_map[VALIDATION_ERROR_09c00126]); |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 1859 | } |
| 1860 | |
| 1861 | subresource_extent = GetImageSubresourceExtent(dst_image_state, &(regions[i].dstSubresource)); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1862 | copy_extent = regions[i].extent; |
| 1863 | if (slice_override) copy_extent.depth = depth_slices; |
| 1864 | extent_check = ExceedsBounds(&(regions[i].dstOffset), ©_extent, &subresource_extent); |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 1865 | if (extent_check & x_bit) { |
| 1866 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1867 | HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_09c0012c, "IMAGE", |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 1868 | "vkCmdCopyImage: Dest image pRegion %1d x-dimension offset [%1d] + extent [%1d] exceeds subResource " |
| 1869 | "width [%1d]. %s", |
| 1870 | i, regions[i].dstOffset.x, regions[i].extent.width, subresource_extent.width, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1871 | validation_error_map[VALIDATION_ERROR_09c0012c]); |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 1872 | } |
| 1873 | if (extent_check & y_bit) { |
| 1874 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1875 | HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_09c0012e, "IMAGE", |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 1876 | "vkCmdCopyImage: Dest image pRegion %1d y-dimension offset [%1d] + extent [%1d] exceeds subResource " |
| 1877 | "height [%1d]. %s", |
| 1878 | i, regions[i].dstOffset.y, regions[i].extent.height, subresource_extent.height, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1879 | validation_error_map[VALIDATION_ERROR_09c0012e]); |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 1880 | } |
| 1881 | if (extent_check & z_bit) { |
| 1882 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1883 | HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_09c00132, "IMAGE", |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 1884 | "vkCmdCopyImage: Dest image pRegion %1d z-dimension offset [%1d] + extent [%1d] exceeds subResource " |
| 1885 | "depth [%1d]. %s", |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1886 | i, regions[i].dstOffset.z, copy_extent.depth, subresource_extent.depth, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1887 | validation_error_map[VALIDATION_ERROR_09c00132]); |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 1888 | } |
| 1889 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1890 | // The union of all source regions, and the union of all destination regions, specified by the elements of regions, |
| 1891 | // must not overlap in memory |
| 1892 | if (src_image_state->image == dst_image_state->image) { |
| 1893 | for (uint32_t j = 0; j < region_count; j++) { |
| 1894 | if (RegionIntersects(®ions[i], ®ions[j], src_image_state->createInfo.imageType)) { |
| 1895 | std::stringstream ss; |
| 1896 | ss << "vkCmdCopyImage: pRegions[" << i << "] src overlaps with pRegions[" << j << "]."; |
| 1897 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1898 | HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_190000f8, "IMAGE", "%s. %s", |
| 1899 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_190000f8]); |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1900 | } |
| 1901 | } |
| 1902 | } |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1903 | } |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1904 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1905 | // The formats of src_image and dst_image must be compatible. Formats are considered compatible if their texel size in bytes |
| 1906 | // is the same between both formats. For example, VK_FORMAT_R8G8B8A8_UNORM is compatible with VK_FORMAT_R32_UINT because |
| 1907 | // 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] | 1908 | 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] | 1909 | if (src_image_state->createInfo.format != dst_image_state->createInfo.format) { |
| 1910 | 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] | 1911 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1912 | HandleToUint64(command_buffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_FORMAT, "IMAGE", str); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1913 | } |
| 1914 | } else { |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 1915 | size_t srcSize = FormatSize(src_image_state->createInfo.format); |
| 1916 | size_t destSize = FormatSize(dst_image_state->createInfo.format); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1917 | if (srcSize != destSize) { |
| 1918 | char const str[] = "vkCmdCopyImage called with unmatched source and dest image format sizes."; |
| 1919 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1920 | HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_1900010e, "IMAGE", "%s. %s", str, |
| 1921 | validation_error_map[VALIDATION_ERROR_1900010e]); |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1922 | } |
| 1923 | } |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1924 | |
Dave Houlton | 33c22b7 | 2017-02-28 13:16:02 -0700 | [diff] [blame] | 1925 | // Source and dest image sample counts must match |
| 1926 | if (src_image_state->createInfo.samples != dst_image_state->createInfo.samples) { |
| 1927 | char const str[] = "vkCmdCopyImage() called on image pair with non-identical sample counts."; |
| 1928 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1929 | HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_19000110, "IMAGE", "%s %s", str, |
| 1930 | validation_error_map[VALIDATION_ERROR_19000110]); |
Dave Houlton | 33c22b7 | 2017-02-28 13:16:02 -0700 | [diff] [blame] | 1931 | } |
| 1932 | |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1933 | skip |= ValidateMemoryIsBoundToImage(device_data, src_image_state, "vkCmdCopyImage()", VALIDATION_ERROR_190000fe); |
| 1934 | skip |= ValidateMemoryIsBoundToImage(device_data, dst_image_state, "vkCmdCopyImage()", VALIDATION_ERROR_19000108); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1935 | // Validate that SRC & DST images have correct usage flags set |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1936 | skip |= ValidateImageUsageFlags(device_data, src_image_state, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, true, VALIDATION_ERROR_190000fc, |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1937 | "vkCmdCopyImage()", "VK_IMAGE_USAGE_TRANSFER_SRC_BIT"); |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1938 | skip |= ValidateImageUsageFlags(device_data, dst_image_state, VK_IMAGE_USAGE_TRANSFER_DST_BIT, true, VALIDATION_ERROR_19000106, |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1939 | "vkCmdCopyImage()", "VK_IMAGE_USAGE_TRANSFER_DST_BIT"); |
Mike Schuchardt | 9c58240 | 2017-02-23 15:57:37 -0700 | [diff] [blame] | 1940 | skip |= ValidateCmdQueueFlags(device_data, cb_node, "vkCmdCopyImage()", |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1941 | VK_QUEUE_TRANSFER_BIT | VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT, VALIDATION_ERROR_19002415); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1942 | skip |= ValidateCmd(device_data, cb_node, CMD_COPYIMAGE, "vkCmdCopyImage()"); |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1943 | skip |= insideRenderPass(device_data, cb_node, "vkCmdCopyImage()", VALIDATION_ERROR_19000017); |
Tobin Ehlis | c826645 | 2017-04-07 12:20:30 -0600 | [diff] [blame] | 1944 | bool hit_error = false; |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1945 | for (uint32_t i = 0; i < region_count; ++i) { |
Tobin Ehlis | 2d85ec6 | 2017-03-14 15:38:48 -0600 | [diff] [blame] | 1946 | skip |= VerifyImageLayout(device_data, cb_node, src_image_state, regions[i].srcSubresource, src_image_layout, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1947 | VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, "vkCmdCopyImage()", VALIDATION_ERROR_19000102, &hit_error); |
Tobin Ehlis | 2d85ec6 | 2017-03-14 15:38:48 -0600 | [diff] [blame] | 1948 | skip |= VerifyImageLayout(device_data, cb_node, dst_image_state, regions[i].dstSubresource, dst_image_layout, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1949 | VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, "vkCmdCopyImage()", VALIDATION_ERROR_1900010c, &hit_error); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1950 | skip |= ValidateCopyImageTransferGranularityRequirements(device_data, cb_node, src_image_state, dst_image_state, |
| 1951 | ®ions[i], i, "vkCmdCopyImage()"); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1952 | } |
| 1953 | |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1954 | return skip; |
| 1955 | } |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1956 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1957 | 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] | 1958 | IMAGE_STATE *dst_image_state, uint32_t region_count, const VkImageCopy *regions, |
| 1959 | VkImageLayout src_image_layout, VkImageLayout dst_image_layout) { |
| 1960 | // Make sure that all image slices are updated to correct layout |
| 1961 | for (uint32_t i = 0; i < region_count; ++i) { |
| 1962 | SetImageLayout(device_data, cb_node, src_image_state, regions[i].srcSubresource, src_image_layout); |
| 1963 | SetImageLayout(device_data, cb_node, dst_image_state, regions[i].dstSubresource, dst_image_layout); |
| 1964 | } |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1965 | // Update bindings between images and cmd buffer |
| 1966 | AddCommandBufferBindingImage(device_data, cb_node, src_image_state); |
| 1967 | AddCommandBufferBindingImage(device_data, cb_node, dst_image_state); |
Dave Houlton | eba86e2 | 2017-03-02 14:56:23 -0700 | [diff] [blame] | 1968 | std::function<bool()> function = [=]() { return ValidateImageMemoryIsValid(device_data, src_image_state, "vkCmdCopyImage()"); }; |
Tobin Ehlis | a17a529 | 2017-07-28 12:11:30 -0600 | [diff] [blame] | 1969 | cb_node->queue_submit_functions.push_back(function); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1970 | function = [=]() { |
| 1971 | SetImageMemoryValid(device_data, dst_image_state, true); |
| 1972 | return false; |
| 1973 | }; |
Tobin Ehlis | a17a529 | 2017-07-28 12:11:30 -0600 | [diff] [blame] | 1974 | cb_node->queue_submit_functions.push_back(function); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1975 | } |
| 1976 | |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1977 | // Returns true if sub_rect is entirely contained within rect |
| 1978 | static inline bool ContainsRect(VkRect2D rect, VkRect2D sub_rect) { |
| 1979 | if ((sub_rect.offset.x < rect.offset.x) || (sub_rect.offset.x + sub_rect.extent.width > rect.offset.x + rect.extent.width) || |
| 1980 | (sub_rect.offset.y < rect.offset.y) || (sub_rect.offset.y + sub_rect.extent.height > rect.offset.y + rect.extent.height)) |
| 1981 | return false; |
| 1982 | return true; |
| 1983 | } |
| 1984 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 1985 | bool PreCallValidateCmdClearAttachments(layer_data *device_data, VkCommandBuffer commandBuffer, uint32_t attachmentCount, |
| 1986 | const VkClearAttachment *pAttachments, uint32_t rectCount, const VkClearRect *pRects) { |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 1987 | GLOBAL_CB_NODE *cb_node = GetCBNode(device_data, commandBuffer); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1988 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 1989 | |
| 1990 | bool skip = false; |
| 1991 | if (cb_node) { |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1992 | skip |= ValidateCmdQueueFlags(device_data, cb_node, "vkCmdClearAttachments()", VK_QUEUE_GRAPHICS_BIT, |
| 1993 | VALIDATION_ERROR_18602415); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1994 | skip |= ValidateCmd(device_data, cb_node, CMD_CLEARATTACHMENTS, "vkCmdClearAttachments()"); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 1995 | // 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] | 1996 | 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] | 1997 | (cb_node->activeRenderPassBeginInfo.renderArea.extent.height == pRects[0].rect.extent.height)) { |
| 1998 | // 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] | 1999 | // This warning should be made more specific. It'd be best to avoid triggering this test if it's a use that must call |
| 2000 | // CmdClearAttachments. |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 2001 | skip |= |
| 2002 | 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] | 2003 | HandleToUint64(commandBuffer), 0, DRAWSTATE_CLEAR_CMD_BEFORE_DRAW, "DS", |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 2004 | "vkCmdClearAttachments() issued on command buffer object 0x%p prior to any Draw Cmds." |
| 2005 | " It is recommended you use RenderPass LOAD_OP_CLEAR on Attachments prior to any Draw.", |
| 2006 | commandBuffer); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 2007 | } |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 2008 | skip |= outsideRenderPass(device_data, cb_node, "vkCmdClearAttachments()", VALIDATION_ERROR_18600017); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 2009 | } |
| 2010 | |
| 2011 | // Validate that attachment is in reference list of active subpass |
| 2012 | if (cb_node->activeRenderPass) { |
| 2013 | const VkRenderPassCreateInfo *renderpass_create_info = cb_node->activeRenderPass->createInfo.ptr(); |
| 2014 | const VkSubpassDescription *subpass_desc = &renderpass_create_info->pSubpasses[cb_node->activeSubpass]; |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 2015 | auto framebuffer = GetFramebufferState(device_data, cb_node->activeFramebuffer); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 2016 | |
| 2017 | for (uint32_t i = 0; i < attachmentCount; i++) { |
| 2018 | auto clear_desc = &pAttachments[i]; |
| 2019 | VkImageView image_view = VK_NULL_HANDLE; |
| 2020 | |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 2021 | if (0 == clear_desc->aspectMask) { |
| 2022 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 2023 | HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_01c00c03, "IMAGE", "%s", |
| 2024 | validation_error_map[VALIDATION_ERROR_01c00c03]); |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 2025 | } else if (clear_desc->aspectMask & VK_IMAGE_ASPECT_METADATA_BIT) { |
| 2026 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 2027 | HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_01c00028, "IMAGE", "%s", |
| 2028 | validation_error_map[VALIDATION_ERROR_01c00028]); |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 2029 | } else if (clear_desc->aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) { |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 2030 | if (clear_desc->colorAttachment >= subpass_desc->colorAttachmentCount) { |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 2031 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 2032 | HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1860001e, "DS", |
| 2033 | "vkCmdClearAttachments() color attachment index %d out of range for active subpass %d. %s", |
| 2034 | clear_desc->colorAttachment, cb_node->activeSubpass, |
| 2035 | validation_error_map[VALIDATION_ERROR_1860001e]); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 2036 | } else if (subpass_desc->pColorAttachments[clear_desc->colorAttachment].attachment == VK_ATTACHMENT_UNUSED) { |
| 2037 | skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 2038 | VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, HandleToUint64(commandBuffer), __LINE__, |
| 2039 | DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS", |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 2040 | "vkCmdClearAttachments() color attachment index %d is VK_ATTACHMENT_UNUSED; ignored.", |
| 2041 | clear_desc->colorAttachment); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 2042 | } else { |
| 2043 | image_view = framebuffer->createInfo |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 2044 | .pAttachments[subpass_desc->pColorAttachments[clear_desc->colorAttachment].attachment]; |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 2045 | } |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 2046 | if ((clear_desc->aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) || |
| 2047 | (clear_desc->aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT)) { |
| 2048 | char const str[] = |
| 2049 | "vkCmdClearAttachments aspectMask [%d] must set only VK_IMAGE_ASPECT_COLOR_BIT of a color attachment. %s"; |
| 2050 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 2051 | HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_01c00026, "IMAGE", str, i, |
| 2052 | validation_error_map[VALIDATION_ERROR_01c00026]); |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 2053 | } |
| 2054 | } else { // Must be depth and/or stencil |
| 2055 | if (((clear_desc->aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) != VK_IMAGE_ASPECT_DEPTH_BIT) && |
| 2056 | ((clear_desc->aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) != VK_IMAGE_ASPECT_STENCIL_BIT)) { |
| 2057 | char const str[] = "vkCmdClearAttachments aspectMask [%d] is not a valid combination of bits. %s"; |
| 2058 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 2059 | HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_01c00c01, "IMAGE", str, i, |
| 2060 | validation_error_map[VALIDATION_ERROR_01c00c01]); |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 2061 | } |
| 2062 | if (!subpass_desc->pDepthStencilAttachment || |
| 2063 | (subpass_desc->pDepthStencilAttachment->attachment == VK_ATTACHMENT_UNUSED)) { |
| 2064 | skip |= log_msg( |
| 2065 | 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] | 2066 | HandleToUint64(commandBuffer), __LINE__, DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS", |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 2067 | "vkCmdClearAttachments() depth/stencil clear with no depth/stencil attachment in subpass; ignored"); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 2068 | } else { |
| 2069 | image_view = framebuffer->createInfo.pAttachments[subpass_desc->pDepthStencilAttachment->attachment]; |
| 2070 | } |
| 2071 | } |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 2072 | if (image_view) { |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 2073 | auto image_view_state = GetImageViewState(device_data, image_view); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 2074 | for (uint32_t j = 0; j < rectCount; j++) { |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 2075 | // The rectangular region specified by a given element of pRects must be contained within the render area of |
| 2076 | // the current render pass instance |
Mark Lobodzinski | d833bb7 | 2017-02-22 10:55:30 -0700 | [diff] [blame] | 2077 | // TODO: This check should be moved to CmdExecuteCommands or QueueSubmit to cover secondary CB cases |
| 2078 | if ((cb_node->createInfo.level == VK_COMMAND_BUFFER_LEVEL_PRIMARY) && |
| 2079 | (false == ContainsRect(cb_node->activeRenderPassBeginInfo.renderArea, pRects[j].rect))) { |
Mark Lobodzinski | 0827aec | 2017-03-21 16:41:45 -0600 | [diff] [blame] | 2080 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 2081 | HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_18600020, "DS", |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 2082 | "vkCmdClearAttachments(): The area defined by pRects[%d] is not contained in the area of " |
| 2083 | "the current render pass instance. %s", |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 2084 | j, validation_error_map[VALIDATION_ERROR_18600020]); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 2085 | } |
| 2086 | // The layers specified by a given element of pRects must be contained within every attachment that |
| 2087 | // pAttachments refers to |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 2088 | auto attachment_layer_count = image_view_state->create_info.subresourceRange.layerCount; |
Dave Houlton | 8e15703 | 2017-05-22 16:16:27 -0600 | [diff] [blame] | 2089 | if ((pRects[j].baseArrayLayer >= attachment_layer_count) || |
| 2090 | (pRects[j].baseArrayLayer + pRects[j].layerCount > attachment_layer_count)) { |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 2091 | skip |= |
Mark Lobodzinski | 0827aec | 2017-03-21 16:41:45 -0600 | [diff] [blame] | 2092 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 2093 | HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_18600022, "DS", |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 2094 | "vkCmdClearAttachments(): The layers defined in pRects[%d] are not contained in the layers of " |
| 2095 | "pAttachment[%d]. %s", |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 2096 | j, i, validation_error_map[VALIDATION_ERROR_18600022]); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 2097 | } |
| 2098 | } |
| 2099 | } |
| 2100 | } |
| 2101 | } |
| 2102 | return skip; |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 2103 | } |
| 2104 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 2105 | 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] | 2106 | IMAGE_STATE *dst_image_state, uint32_t regionCount, const VkImageResolve *pRegions) { |
Mark Lobodzinski | 2a3368e | 2017-02-06 15:29:37 -0700 | [diff] [blame] | 2107 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 2108 | bool skip = false; |
| 2109 | if (cb_node && src_image_state && dst_image_state) { |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 2110 | skip |= ValidateMemoryIsBoundToImage(device_data, src_image_state, "vkCmdResolveImage()", VALIDATION_ERROR_1c800200); |
| 2111 | skip |= ValidateMemoryIsBoundToImage(device_data, dst_image_state, "vkCmdResolveImage()", VALIDATION_ERROR_1c800204); |
| 2112 | skip |= |
| 2113 | ValidateCmdQueueFlags(device_data, cb_node, "vkCmdResolveImage()", VK_QUEUE_GRAPHICS_BIT, VALIDATION_ERROR_1c802415); |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 2114 | skip |= ValidateCmd(device_data, cb_node, CMD_RESOLVEIMAGE, "vkCmdResolveImage()"); |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 2115 | skip |= insideRenderPass(device_data, cb_node, "vkCmdResolveImage()", VALIDATION_ERROR_1c800017); |
Mark Lobodzinski | 2a3368e | 2017-02-06 15:29:37 -0700 | [diff] [blame] | 2116 | |
| 2117 | // For each region, the number of layers in the image subresource should not be zero |
| 2118 | // For each region, src and dest image aspect must be color only |
| 2119 | for (uint32_t i = 0; i < regionCount; i++) { |
| 2120 | if (pRegions[i].srcSubresource.layerCount == 0) { |
| 2121 | char const str[] = "vkCmdResolveImage: number of layers in source subresource is zero"; |
Mark Lobodzinski | 50fbef1 | 2017-02-06 15:31:33 -0700 | [diff] [blame] | 2122 | 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] | 2123 | HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_ASPECT, "IMAGE", str); |
Mark Lobodzinski | 2a3368e | 2017-02-06 15:29:37 -0700 | [diff] [blame] | 2124 | } |
Mark Lobodzinski | 2a3368e | 2017-02-06 15:29:37 -0700 | [diff] [blame] | 2125 | if (pRegions[i].dstSubresource.layerCount == 0) { |
| 2126 | char const str[] = "vkCmdResolveImage: number of layers in destination subresource is zero"; |
Mark Lobodzinski | 50fbef1 | 2017-02-06 15:31:33 -0700 | [diff] [blame] | 2127 | 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] | 2128 | HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_ASPECT, "IMAGE", str); |
Mark Lobodzinski | 2a3368e | 2017-02-06 15:29:37 -0700 | [diff] [blame] | 2129 | } |
Mark Lobodzinski | 50fbef1 | 2017-02-06 15:31:33 -0700 | [diff] [blame] | 2130 | if (pRegions[i].srcSubresource.layerCount != pRegions[i].dstSubresource.layerCount) { |
| 2131 | skip |= log_msg( |
| 2132 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 2133 | HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_0a200216, "IMAGE", |
Mark Lobodzinski | 50fbef1 | 2017-02-06 15:31:33 -0700 | [diff] [blame] | 2134 | "vkCmdResolveImage: layerCount in source and destination subresource of pRegions[%d] does not match. %s", i, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 2135 | validation_error_map[VALIDATION_ERROR_0a200216]); |
Mark Lobodzinski | 50fbef1 | 2017-02-06 15:31:33 -0700 | [diff] [blame] | 2136 | } |
Mark Lobodzinski | 2a3368e | 2017-02-06 15:29:37 -0700 | [diff] [blame] | 2137 | if ((pRegions[i].srcSubresource.aspectMask != VK_IMAGE_ASPECT_COLOR_BIT) || |
| 2138 | (pRegions[i].dstSubresource.aspectMask != VK_IMAGE_ASPECT_COLOR_BIT)) { |
| 2139 | char const str[] = |
| 2140 | "vkCmdResolveImage: src and dest aspectMasks for each region must specify only VK_IMAGE_ASPECT_COLOR_BIT"; |
| 2141 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 2142 | HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_0a200214, "IMAGE", "%s. %s", str, |
| 2143 | validation_error_map[VALIDATION_ERROR_0a200214]); |
Mark Lobodzinski | 2a3368e | 2017-02-06 15:29:37 -0700 | [diff] [blame] | 2144 | } |
| 2145 | } |
| 2146 | |
| 2147 | if (src_image_state->createInfo.format != dst_image_state->createInfo.format) { |
| 2148 | char const str[] = "vkCmdResolveImage called with unmatched source and dest formats."; |
Mark Lobodzinski | 50fbef1 | 2017-02-06 15:31:33 -0700 | [diff] [blame] | 2149 | 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] | 2150 | HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_FORMAT, "IMAGE", str); |
Mark Lobodzinski | 2a3368e | 2017-02-06 15:29:37 -0700 | [diff] [blame] | 2151 | } |
| 2152 | if (src_image_state->createInfo.imageType != dst_image_state->createInfo.imageType) { |
| 2153 | char const str[] = "vkCmdResolveImage called with unmatched source and dest image types."; |
Mark Lobodzinski | 50fbef1 | 2017-02-06 15:31:33 -0700 | [diff] [blame] | 2154 | 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] | 2155 | HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_TYPE, "IMAGE", str); |
Mark Lobodzinski | 2a3368e | 2017-02-06 15:29:37 -0700 | [diff] [blame] | 2156 | } |
| 2157 | if (src_image_state->createInfo.samples == VK_SAMPLE_COUNT_1_BIT) { |
| 2158 | char const str[] = "vkCmdResolveImage called with source sample count less than 2."; |
| 2159 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 2160 | HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_1c800202, "IMAGE", "%s. %s", str, |
| 2161 | validation_error_map[VALIDATION_ERROR_1c800202]); |
Mark Lobodzinski | 2a3368e | 2017-02-06 15:29:37 -0700 | [diff] [blame] | 2162 | } |
| 2163 | if (dst_image_state->createInfo.samples != VK_SAMPLE_COUNT_1_BIT) { |
| 2164 | char const str[] = "vkCmdResolveImage called with dest sample count greater than 1."; |
| 2165 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 2166 | HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_1c800206, "IMAGE", "%s. %s", str, |
| 2167 | validation_error_map[VALIDATION_ERROR_1c800206]); |
Mark Lobodzinski | 2a3368e | 2017-02-06 15:29:37 -0700 | [diff] [blame] | 2168 | } |
Tobin Ehlis | bb03e5f | 2017-05-11 08:52:51 -0600 | [diff] [blame] | 2169 | // 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] | 2170 | } else { |
| 2171 | assert(0); |
| 2172 | } |
| 2173 | return skip; |
| 2174 | } |
| 2175 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 2176 | void PreCallRecordCmdResolveImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state, |
| 2177 | IMAGE_STATE *dst_image_state) { |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 2178 | // Update bindings between images and cmd buffer |
| 2179 | AddCommandBufferBindingImage(device_data, cb_node, src_image_state); |
| 2180 | AddCommandBufferBindingImage(device_data, cb_node, dst_image_state); |
| 2181 | |
| 2182 | std::function<bool()> function = [=]() { |
| 2183 | return ValidateImageMemoryIsValid(device_data, src_image_state, "vkCmdResolveImage()"); |
| 2184 | }; |
Tobin Ehlis | a17a529 | 2017-07-28 12:11:30 -0600 | [diff] [blame] | 2185 | cb_node->queue_submit_functions.push_back(function); |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 2186 | function = [=]() { |
| 2187 | SetImageMemoryValid(device_data, dst_image_state, true); |
| 2188 | return false; |
| 2189 | }; |
Tobin Ehlis | a17a529 | 2017-07-28 12:11:30 -0600 | [diff] [blame] | 2190 | cb_node->queue_submit_functions.push_back(function); |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 2191 | } |
| 2192 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 2193 | 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] | 2194 | IMAGE_STATE *dst_image_state, uint32_t regionCount, const VkImageBlit *pRegions, VkFilter filter) { |
| 2195 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 2196 | |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 2197 | bool skip = false; |
| 2198 | if (cb_node && src_image_state && dst_image_state) { |
| 2199 | skip |= ValidateImageSampleCount(device_data, src_image_state, VK_SAMPLE_COUNT_1_BIT, "vkCmdBlitImage(): srcImage", |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 2200 | VALIDATION_ERROR_184001d2); |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 2201 | skip |= ValidateImageSampleCount(device_data, dst_image_state, VK_SAMPLE_COUNT_1_BIT, "vkCmdBlitImage(): dstImage", |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 2202 | VALIDATION_ERROR_184001d4); |
| 2203 | skip |= ValidateMemoryIsBoundToImage(device_data, src_image_state, "vkCmdBlitImage()", VALIDATION_ERROR_184001b8); |
| 2204 | skip |= ValidateMemoryIsBoundToImage(device_data, dst_image_state, "vkCmdBlitImage()", VALIDATION_ERROR_184001c2); |
| 2205 | skip |= ValidateImageUsageFlags(device_data, src_image_state, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, true, |
| 2206 | VALIDATION_ERROR_184001b6, "vkCmdBlitImage()", "VK_IMAGE_USAGE_TRANSFER_SRC_BIT"); |
| 2207 | skip |= ValidateImageUsageFlags(device_data, dst_image_state, VK_IMAGE_USAGE_TRANSFER_DST_BIT, true, |
| 2208 | VALIDATION_ERROR_184001c0, "vkCmdBlitImage()", "VK_IMAGE_USAGE_TRANSFER_DST_BIT"); |
| 2209 | skip |= ValidateCmdQueueFlags(device_data, cb_node, "vkCmdBlitImage()", VK_QUEUE_GRAPHICS_BIT, VALIDATION_ERROR_18402415); |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 2210 | skip |= ValidateCmd(device_data, cb_node, CMD_BLITIMAGE, "vkCmdBlitImage()"); |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 2211 | skip |= insideRenderPass(device_data, cb_node, "vkCmdBlitImage()", VALIDATION_ERROR_18400017); |
Tobin Ehlis | bb03e5f | 2017-05-11 08:52:51 -0600 | [diff] [blame] | 2212 | // 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] | 2213 | |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2214 | VkFormat src_format = src_image_state->createInfo.format; |
| 2215 | VkFormat dst_format = dst_image_state->createInfo.format; |
| 2216 | VkImageType src_type = src_image_state->createInfo.imageType; |
| 2217 | VkImageType dst_type = dst_image_state->createInfo.imageType; |
| 2218 | |
Jeremy Kniager | 7ec550f | 2017-08-16 14:57:42 -0600 | [diff] [blame^] | 2219 | VkFormatProperties props = GetFormatProperties(device_data, src_format); |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2220 | VkImageTiling tiling = src_image_state->createInfo.tiling; |
| 2221 | VkFormatFeatureFlags flags = |
Jeremy Kniager | 7ec550f | 2017-08-16 14:57:42 -0600 | [diff] [blame^] | 2222 | (tiling == VK_IMAGE_TILING_LINEAR ? props.linearTilingFeatures : props.optimalTilingFeatures); |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2223 | if (VK_FORMAT_FEATURE_BLIT_SRC_BIT != (flags & VK_FORMAT_FEATURE_BLIT_SRC_BIT)) { |
| 2224 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 2225 | HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_184001b4, "IMAGE", |
| 2226 | "vkCmdBlitImage: source image format %s does not support VK_FORMAT_FEATURE_BLIT_SRC_BIT feature. %s", |
| 2227 | string_VkFormat(src_format), validation_error_map[VALIDATION_ERROR_184001b4]); |
| 2228 | } |
| 2229 | |
| 2230 | if ((VK_FILTER_LINEAR == filter) && |
| 2231 | (VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT != (flags & VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT))) { |
| 2232 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 2233 | HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_184001d6, "IMAGE", |
| 2234 | "vkCmdBlitImage: source image format %s does not support linear filtering. %s", |
| 2235 | string_VkFormat(src_format), validation_error_map[VALIDATION_ERROR_184001d6]); |
| 2236 | } |
| 2237 | |
| 2238 | if ((VK_FILTER_CUBIC_IMG == filter) && (VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_CUBIC_BIT_IMG != |
| 2239 | (flags & VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_CUBIC_BIT_IMG))) { |
| 2240 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 2241 | HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_184001d8, "IMAGE", |
| 2242 | "vkCmdBlitImage: source image format %s does not support cubic filtering. %s", |
| 2243 | string_VkFormat(src_format), validation_error_map[VALIDATION_ERROR_184001d8]); |
| 2244 | } |
| 2245 | |
| 2246 | if ((VK_FILTER_CUBIC_IMG == filter) && (VK_IMAGE_TYPE_3D != src_type)) { |
| 2247 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 2248 | HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_184001da, "IMAGE", |
| 2249 | "vkCmdBlitImage: source image type must be VK_IMAGE_TYPE_3D when cubic filtering is specified. %s", |
| 2250 | validation_error_map[VALIDATION_ERROR_184001da]); |
| 2251 | } |
| 2252 | |
| 2253 | props = GetFormatProperties(device_data, dst_format); |
| 2254 | tiling = dst_image_state->createInfo.tiling; |
Jeremy Kniager | 7ec550f | 2017-08-16 14:57:42 -0600 | [diff] [blame^] | 2255 | flags = (tiling == VK_IMAGE_TILING_LINEAR ? props.linearTilingFeatures : props.optimalTilingFeatures); |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2256 | if (VK_FORMAT_FEATURE_BLIT_DST_BIT != (flags & VK_FORMAT_FEATURE_BLIT_DST_BIT)) { |
| 2257 | skip |= |
| 2258 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 2259 | HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_184001be, "IMAGE", |
| 2260 | "vkCmdBlitImage: destination image format %s does not support VK_FORMAT_FEATURE_BLIT_DST_BIT feature. %s", |
| 2261 | string_VkFormat(dst_format), validation_error_map[VALIDATION_ERROR_184001be]); |
| 2262 | } |
| 2263 | |
| 2264 | if ((VK_SAMPLE_COUNT_1_BIT != src_image_state->createInfo.samples) || |
| 2265 | (VK_SAMPLE_COUNT_1_BIT != dst_image_state->createInfo.samples)) { |
| 2266 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 2267 | HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_184001c8, "IMAGE", |
| 2268 | "vkCmdBlitImage: source or dest image has sample count other than VK_SAMPLE_COUNT_1_BIT. %s", |
| 2269 | validation_error_map[VALIDATION_ERROR_184001c8]); |
| 2270 | } |
| 2271 | |
| 2272 | // Validate consistency for unsigned formats |
| 2273 | if (FormatIsUInt(src_format) != FormatIsUInt(dst_format)) { |
| 2274 | std::stringstream ss; |
| 2275 | ss << "vkCmdBlitImage: If one of srcImage and dstImage images has unsigned integer format, " |
| 2276 | << "the other one must also have unsigned integer format. " |
| 2277 | << "Source format is " << string_VkFormat(src_format) << " Destination format is " << string_VkFormat(dst_format); |
| 2278 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 2279 | HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_184001cc, "IMAGE", "%s. %s", |
| 2280 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_184001cc]); |
| 2281 | } |
| 2282 | |
| 2283 | // Validate consistency for signed formats |
| 2284 | if (FormatIsSInt(src_format) != FormatIsSInt(dst_format)) { |
| 2285 | std::stringstream ss; |
| 2286 | ss << "vkCmdBlitImage: If one of srcImage and dstImage images has signed integer format, " |
| 2287 | << "the other one must also have signed integer format. " |
| 2288 | << "Source format is " << string_VkFormat(src_format) << " Destination format is " << string_VkFormat(dst_format); |
| 2289 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 2290 | HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_184001ca, "IMAGE", "%s. %s", |
| 2291 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_184001ca]); |
| 2292 | } |
| 2293 | |
| 2294 | // Validate filter for Depth/Stencil formats |
| 2295 | if (FormatIsDepthOrStencil(src_format) && (filter != VK_FILTER_NEAREST)) { |
| 2296 | std::stringstream ss; |
| 2297 | ss << "vkCmdBlitImage: If the format of srcImage is a depth, stencil, or depth stencil " |
| 2298 | << "then filter must be VK_FILTER_NEAREST."; |
| 2299 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 2300 | HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_184001d0, "IMAGE", "%s. %s", |
| 2301 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_184001d0]); |
| 2302 | } |
| 2303 | |
| 2304 | // Validate aspect bits and formats for depth/stencil images |
| 2305 | if (FormatIsDepthOrStencil(src_format) || FormatIsDepthOrStencil(dst_format)) { |
| 2306 | if (src_format != dst_format) { |
| 2307 | std::stringstream ss; |
| 2308 | ss << "vkCmdBlitImage: If one of srcImage and dstImage images has a format of depth, stencil or depth " |
| 2309 | << "stencil, the other one must have exactly the same format. " |
| 2310 | << "Source format is " << string_VkFormat(src_format) << " Destination format is " |
| 2311 | << string_VkFormat(dst_format); |
| 2312 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 2313 | HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_184001ce, "IMAGE", "%s. %s", |
| 2314 | ss.str().c_str(), validation_error_map[VALIDATION_ERROR_184001ce]); |
| 2315 | } |
| 2316 | |
| 2317 | #if 0 // TODO: Cannot find VU statements or spec language for these in CmdBlitImage. Verify or remove. |
| 2318 | for (uint32_t i = 0; i < regionCount; i++) { |
| 2319 | VkImageAspectFlags srcAspect = pRegions[i].srcSubresource.aspectMask; |
| 2320 | |
| 2321 | if (FormatIsDepthAndStencil(src_format)) { |
| 2322 | if ((srcAspect != VK_IMAGE_ASPECT_DEPTH_BIT) && (srcAspect != VK_IMAGE_ASPECT_STENCIL_BIT)) { |
| 2323 | std::stringstream ss; |
| 2324 | ss << "vkCmdBlitImage: Combination depth/stencil image formats must have only one of " |
| 2325 | "VK_IMAGE_ASPECT_DEPTH_BIT " |
| 2326 | << "and VK_IMAGE_ASPECT_STENCIL_BIT set in srcImage and dstImage"; |
| 2327 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 2328 | HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", |
| 2329 | "%s", ss.str().c_str()); |
| 2330 | } |
| 2331 | } |
| 2332 | else if (FormatIsStencilOnly(src_format)) { |
| 2333 | if (srcAspect != VK_IMAGE_ASPECT_STENCIL_BIT) { |
| 2334 | std::stringstream ss; |
| 2335 | ss << "vkCmdBlitImage: Stencil-only image formats must have only the VK_IMAGE_ASPECT_STENCIL_BIT " |
| 2336 | << "set in both the srcImage and dstImage"; |
| 2337 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 2338 | HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", |
| 2339 | "%s", ss.str().c_str()); |
| 2340 | } |
| 2341 | } |
| 2342 | else if (FormatIsDepthOnly(src_format)) { |
| 2343 | if (srcAspect != VK_IMAGE_ASPECT_DEPTH_BIT) { |
| 2344 | std::stringstream ss; |
| 2345 | ss << "vkCmdBlitImage: Depth-only image formats must have only the VK_IMAGE_ASPECT_DEPTH " |
| 2346 | << "set in both the srcImage and dstImage"; |
| 2347 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 2348 | HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", |
| 2349 | "%s", ss.str().c_str()); |
| 2350 | } |
| 2351 | } |
| 2352 | } |
| 2353 | #endif |
| 2354 | } // Depth or Stencil |
| 2355 | |
| 2356 | // Do per-region checks |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 2357 | for (uint32_t i = 0; i < regionCount; i++) { |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 2358 | VkImageBlit rgn = pRegions[i]; |
| 2359 | |
Mark Lobodzinski | 23c8114 | 2017-02-06 15:04:23 -0700 | [diff] [blame] | 2360 | // Warn for zero-sized regions |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 2361 | if ((rgn.srcOffsets[0].x == rgn.srcOffsets[1].x) || (rgn.srcOffsets[0].y == rgn.srcOffsets[1].y) || |
| 2362 | (rgn.srcOffsets[0].z == rgn.srcOffsets[1].z)) { |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 2363 | std::stringstream ss; |
| 2364 | ss << "vkCmdBlitImage: pRegions[" << i << "].srcOffsets specify a zero-volume area."; |
| 2365 | 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] | 2366 | HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_INVALID_EXTENTS, "IMAGE", "%s", |
| 2367 | ss.str().c_str()); |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 2368 | } |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 2369 | if ((rgn.dstOffsets[0].x == rgn.dstOffsets[1].x) || (rgn.dstOffsets[0].y == rgn.dstOffsets[1].y) || |
| 2370 | (rgn.dstOffsets[0].z == rgn.dstOffsets[1].z)) { |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 2371 | std::stringstream ss; |
| 2372 | ss << "vkCmdBlitImage: pRegions[" << i << "].dstOffsets specify a zero-volume area."; |
| 2373 | 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] | 2374 | HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_INVALID_EXTENTS, "IMAGE", "%s", |
| 2375 | ss.str().c_str()); |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 2376 | } |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 2377 | if (rgn.srcSubresource.layerCount == 0) { |
Mark Lobodzinski | 23c8114 | 2017-02-06 15:04:23 -0700 | [diff] [blame] | 2378 | char const str[] = "vkCmdBlitImage: number of layers in source subresource is zero"; |
| 2379 | 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] | 2380 | HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_ASPECT, "IMAGE", str); |
Mark Lobodzinski | 23c8114 | 2017-02-06 15:04:23 -0700 | [diff] [blame] | 2381 | } |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 2382 | if (rgn.dstSubresource.layerCount == 0) { |
Mark Lobodzinski | 23c8114 | 2017-02-06 15:04:23 -0700 | [diff] [blame] | 2383 | char const str[] = "vkCmdBlitImage: number of layers in destination subresource is zero"; |
| 2384 | 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] | 2385 | HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_ASPECT, "IMAGE", str); |
Mark Lobodzinski | 23c8114 | 2017-02-06 15:04:23 -0700 | [diff] [blame] | 2386 | } |
| 2387 | |
| 2388 | // Check that src/dst layercounts match |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 2389 | if (rgn.srcSubresource.layerCount != rgn.dstSubresource.layerCount) { |
Mark Lobodzinski | 23c8114 | 2017-02-06 15:04:23 -0700 | [diff] [blame] | 2390 | skip |= |
| 2391 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 2392 | HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_09a001de, "IMAGE", |
Mark Lobodzinski | 23c8114 | 2017-02-06 15:04:23 -0700 | [diff] [blame] | 2393 | "vkCmdBlitImage: layerCount in source and destination subresource of pRegions[%d] does not match. %s", |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 2394 | i, validation_error_map[VALIDATION_ERROR_09a001de]); |
Mark Lobodzinski | 23c8114 | 2017-02-06 15:04:23 -0700 | [diff] [blame] | 2395 | } |
Mark Lobodzinski | e7e85fd | 2017-02-07 13:44:57 -0700 | [diff] [blame] | 2396 | |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 2397 | if (rgn.srcSubresource.aspectMask != rgn.dstSubresource.aspectMask) { |
Mark Lobodzinski | e7e85fd | 2017-02-07 13:44:57 -0700 | [diff] [blame] | 2398 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 2399 | HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_09a001dc, "IMAGE", |
Mark Lobodzinski | e7e85fd | 2017-02-07 13:44:57 -0700 | [diff] [blame] | 2400 | "vkCmdBlitImage: aspectMask members for pRegion[%d] do not match. %s", i, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 2401 | validation_error_map[VALIDATION_ERROR_09a001dc]); |
Mark Lobodzinski | e7e85fd | 2017-02-07 13:44:57 -0700 | [diff] [blame] | 2402 | } |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 2403 | |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2404 | if (!VerifyAspectsPresent(rgn.srcSubresource.aspectMask, src_format)) { |
| 2405 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 2406 | HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_09a001e2, "IMAGE", |
| 2407 | "vkCmdBlitImage: region [%d] source aspectMask (0x%x) specifies aspects not present in source " |
| 2408 | "image format %s. %s", |
| 2409 | i, rgn.srcSubresource.aspectMask, string_VkFormat(src_format), |
| 2410 | validation_error_map[VALIDATION_ERROR_09a001e2]); |
| 2411 | } |
| 2412 | |
| 2413 | if (!VerifyAspectsPresent(rgn.dstSubresource.aspectMask, dst_format)) { |
| 2414 | skip |= log_msg( |
| 2415 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 2416 | HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_09a001e4, "IMAGE", |
| 2417 | "vkCmdBlitImage: region [%d] dest aspectMask (0x%x) specifies aspects not present in dest image format %s. %s", |
| 2418 | i, rgn.dstSubresource.aspectMask, string_VkFormat(dst_format), validation_error_map[VALIDATION_ERROR_09a001e4]); |
| 2419 | } |
| 2420 | |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 2421 | // Validate source image offsets |
| 2422 | VkExtent3D src_extent = GetImageSubresourceExtent(src_image_state, &(rgn.srcSubresource)); |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2423 | if (VK_IMAGE_TYPE_1D == src_type) { |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 2424 | if ((0 != rgn.srcOffsets[0].y) || (1 != rgn.srcOffsets[1].y)) { |
| 2425 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 2426 | HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_09a001ea, "IMAGE", |
| 2427 | "vkCmdBlitImage: region [%d], source image of type VK_IMAGE_TYPE_1D with srcOffset[].y values " |
| 2428 | "of (%1d, %1d). These must be (0, 1). %s", |
| 2429 | i, rgn.srcOffsets[0].y, rgn.srcOffsets[1].y, validation_error_map[VALIDATION_ERROR_09a001ea]); |
| 2430 | } |
| 2431 | } |
| 2432 | |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2433 | if ((VK_IMAGE_TYPE_1D == src_type) || (VK_IMAGE_TYPE_2D == src_type)) { |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 2434 | if ((0 != rgn.srcOffsets[0].z) || (1 != rgn.srcOffsets[1].z)) { |
| 2435 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 2436 | HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_09a001ee, "IMAGE", |
| 2437 | "vkCmdBlitImage: region [%d], source image of type VK_IMAGE_TYPE_1D or VK_IMAGE_TYPE_2D with " |
| 2438 | "srcOffset[].z values of (%1d, %1d). These must be (0, 1). %s", |
| 2439 | i, rgn.srcOffsets[0].z, rgn.srcOffsets[1].z, validation_error_map[VALIDATION_ERROR_09a001ee]); |
| 2440 | } |
| 2441 | } |
| 2442 | |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2443 | bool oob = false; |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 2444 | if ((rgn.srcOffsets[0].x < 0) || (rgn.srcOffsets[0].x > static_cast<int32_t>(src_extent.width)) || |
| 2445 | (rgn.srcOffsets[1].x < 0) || (rgn.srcOffsets[1].x > static_cast<int32_t>(src_extent.width))) { |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2446 | oob = true; |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 2447 | skip |= log_msg( |
| 2448 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 2449 | HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_09a001e6, "IMAGE", |
| 2450 | "vkCmdBlitImage: region [%d] srcOffset[].x values (%1d, %1d) exceed srcSubresource width extent (%1d). %s", i, |
| 2451 | rgn.srcOffsets[0].x, rgn.srcOffsets[1].x, src_extent.width, validation_error_map[VALIDATION_ERROR_09a001e6]); |
| 2452 | } |
| 2453 | if ((rgn.srcOffsets[0].y < 0) || (rgn.srcOffsets[0].y > static_cast<int32_t>(src_extent.height)) || |
| 2454 | (rgn.srcOffsets[1].y < 0) || (rgn.srcOffsets[1].y > static_cast<int32_t>(src_extent.height))) { |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2455 | oob = true; |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 2456 | skip |= log_msg( |
| 2457 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 2458 | HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_09a001e8, "IMAGE", |
| 2459 | "vkCmdBlitImage: region [%d] srcOffset[].y values (%1d, %1d) exceed srcSubresource height extent (%1d). %s", i, |
| 2460 | rgn.srcOffsets[0].y, rgn.srcOffsets[1].y, src_extent.height, validation_error_map[VALIDATION_ERROR_09a001e8]); |
| 2461 | } |
| 2462 | if ((rgn.srcOffsets[0].z < 0) || (rgn.srcOffsets[0].z > static_cast<int32_t>(src_extent.depth)) || |
| 2463 | (rgn.srcOffsets[1].z < 0) || (rgn.srcOffsets[1].z > static_cast<int32_t>(src_extent.depth))) { |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2464 | oob = true; |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 2465 | skip |= log_msg( |
| 2466 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 2467 | HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_09a001ec, "IMAGE", |
| 2468 | "vkCmdBlitImage: region [%d] srcOffset[].z values (%1d, %1d) exceed srcSubresource depth extent (%1d). %s", i, |
| 2469 | rgn.srcOffsets[0].z, rgn.srcOffsets[1].z, src_extent.depth, validation_error_map[VALIDATION_ERROR_09a001ec]); |
| 2470 | } |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2471 | if (rgn.srcSubresource.mipLevel >= src_image_state->createInfo.mipLevels) { |
| 2472 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 2473 | HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_184001ae, "IMAGE", |
| 2474 | "vkCmdBlitImage: region [%d] source image, attempt to access a non-existant mip level %1d. %s", i, |
| 2475 | rgn.srcSubresource.mipLevel, validation_error_map[VALIDATION_ERROR_184001ae]); |
| 2476 | } else if (oob) { |
| 2477 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 2478 | HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_184001ae, "IMAGE", |
| 2479 | "vkCmdBlitImage: region [%d] source image blit region exceeds image dimensions. %s", i, |
| 2480 | validation_error_map[VALIDATION_ERROR_184001ae]); |
| 2481 | } |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 2482 | |
| 2483 | // Validate dest image offsets |
| 2484 | VkExtent3D dst_extent = GetImageSubresourceExtent(dst_image_state, &(rgn.dstSubresource)); |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2485 | if (VK_IMAGE_TYPE_1D == dst_type) { |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 2486 | if ((0 != rgn.dstOffsets[0].y) || (1 != rgn.dstOffsets[1].y)) { |
| 2487 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 2488 | HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_09a001f4, "IMAGE", |
| 2489 | "vkCmdBlitImage: region [%d], dest image of type VK_IMAGE_TYPE_1D with dstOffset[].y values of " |
| 2490 | "(%1d, %1d). These must be (0, 1). %s", |
| 2491 | i, rgn.dstOffsets[0].y, rgn.dstOffsets[1].y, validation_error_map[VALIDATION_ERROR_09a001f4]); |
| 2492 | } |
| 2493 | } |
| 2494 | |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2495 | if ((VK_IMAGE_TYPE_1D == dst_type) || (VK_IMAGE_TYPE_2D == dst_type)) { |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 2496 | if ((0 != rgn.dstOffsets[0].z) || (1 != rgn.dstOffsets[1].z)) { |
| 2497 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 2498 | HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_09a001f8, "IMAGE", |
| 2499 | "vkCmdBlitImage: region [%d], dest image of type VK_IMAGE_TYPE_1D or VK_IMAGE_TYPE_2D with " |
| 2500 | "dstOffset[].z values of (%1d, %1d). These must be (0, 1). %s", |
| 2501 | i, rgn.dstOffsets[0].z, rgn.dstOffsets[1].z, validation_error_map[VALIDATION_ERROR_09a001f8]); |
| 2502 | } |
| 2503 | } |
| 2504 | |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2505 | oob = false; |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 2506 | if ((rgn.dstOffsets[0].x < 0) || (rgn.dstOffsets[0].x > static_cast<int32_t>(dst_extent.width)) || |
| 2507 | (rgn.dstOffsets[1].x < 0) || (rgn.dstOffsets[1].x > static_cast<int32_t>(dst_extent.width))) { |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2508 | oob = true; |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 2509 | skip |= log_msg( |
| 2510 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 2511 | HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_09a001f0, "IMAGE", |
| 2512 | "vkCmdBlitImage: region [%d] dstOffset[].x values (%1d, %1d) exceed dstSubresource width extent (%1d). %s", i, |
| 2513 | rgn.dstOffsets[0].x, rgn.dstOffsets[1].x, dst_extent.width, validation_error_map[VALIDATION_ERROR_09a001f0]); |
| 2514 | } |
| 2515 | if ((rgn.dstOffsets[0].y < 0) || (rgn.dstOffsets[0].y > static_cast<int32_t>(dst_extent.height)) || |
| 2516 | (rgn.dstOffsets[1].y < 0) || (rgn.dstOffsets[1].y > static_cast<int32_t>(dst_extent.height))) { |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2517 | oob = true; |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 2518 | skip |= log_msg( |
| 2519 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 2520 | HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_09a001f2, "IMAGE", |
| 2521 | "vkCmdBlitImage: region [%d] dstOffset[].y values (%1d, %1d) exceed dstSubresource height extent (%1d). %s", i, |
| 2522 | rgn.dstOffsets[0].y, rgn.dstOffsets[1].y, dst_extent.height, validation_error_map[VALIDATION_ERROR_09a001f2]); |
| 2523 | } |
| 2524 | if ((rgn.dstOffsets[0].z < 0) || (rgn.dstOffsets[0].z > static_cast<int32_t>(dst_extent.depth)) || |
| 2525 | (rgn.dstOffsets[1].z < 0) || (rgn.dstOffsets[1].z > static_cast<int32_t>(dst_extent.depth))) { |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2526 | oob = true; |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 2527 | skip |= log_msg( |
| 2528 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 2529 | HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_09a001f6, "IMAGE", |
| 2530 | "vkCmdBlitImage: region [%d] dstOffset[].z values (%1d, %1d) exceed dstSubresource depth extent (%1d). %s", i, |
| 2531 | rgn.dstOffsets[0].z, rgn.dstOffsets[1].z, dst_extent.depth, validation_error_map[VALIDATION_ERROR_09a001f6]); |
| 2532 | } |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2533 | if (rgn.dstSubresource.mipLevel >= dst_image_state->createInfo.mipLevels) { |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 2534 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2535 | HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_184001b0, "IMAGE", |
| 2536 | "vkCmdBlitImage: region [%d] destination image, attempt to access a non-existant mip level %1d. %s", |
| 2537 | i, rgn.dstSubresource.mipLevel, validation_error_map[VALIDATION_ERROR_184001b0]); |
| 2538 | } else if (oob) { |
| 2539 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 2540 | HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_184001b0, "IMAGE", |
| 2541 | "vkCmdBlitImage: region [%d] destination image blit region exceeds image dimensions. %s", i, |
| 2542 | validation_error_map[VALIDATION_ERROR_184001b0]); |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 2543 | } |
| 2544 | |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2545 | if ((VK_IMAGE_TYPE_3D == src_type) || (VK_IMAGE_TYPE_3D == dst_type)) { |
| 2546 | if ((0 != rgn.srcSubresource.baseArrayLayer) || (1 != rgn.srcSubresource.layerCount) || |
| 2547 | (0 != rgn.dstSubresource.baseArrayLayer) || (1 != rgn.dstSubresource.layerCount)) { |
| 2548 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 2549 | HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_09a001e0, "IMAGE", |
| 2550 | "vkCmdBlitImage: region [%d] blit to/from a 3D image type with a non-zero baseArrayLayer, or a " |
| 2551 | "layerCount other than 1. %s", |
| 2552 | i, validation_error_map[VALIDATION_ERROR_09a001e0]); |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 2553 | } |
| 2554 | } |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2555 | } // per-region checks |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 2556 | } else { |
| 2557 | assert(0); |
| 2558 | } |
| 2559 | return skip; |
| 2560 | } |
| 2561 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 2562 | void PreCallRecordCmdBlitImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state, |
| 2563 | IMAGE_STATE *dst_image_state) { |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 2564 | // Update bindings between images and cmd buffer |
| 2565 | AddCommandBufferBindingImage(device_data, cb_node, src_image_state); |
| 2566 | AddCommandBufferBindingImage(device_data, cb_node, dst_image_state); |
| 2567 | |
| 2568 | std::function<bool()> function = [=]() { return ValidateImageMemoryIsValid(device_data, src_image_state, "vkCmdBlitImage()"); }; |
Tobin Ehlis | a17a529 | 2017-07-28 12:11:30 -0600 | [diff] [blame] | 2569 | cb_node->queue_submit_functions.push_back(function); |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 2570 | function = [=]() { |
| 2571 | SetImageMemoryValid(device_data, dst_image_state, true); |
| 2572 | return false; |
| 2573 | }; |
Tobin Ehlis | a17a529 | 2017-07-28 12:11:30 -0600 | [diff] [blame] | 2574 | cb_node->queue_submit_functions.push_back(function); |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 2575 | } |
| 2576 | |
Tony Barbour | df013b9 | 2017-01-25 12:53:48 -0700 | [diff] [blame] | 2577 | // This validates that the initial layout specified in the command buffer for |
| 2578 | // the IMAGE is the same |
| 2579 | // as the global IMAGE layout |
Tony Barbour | e0c5cc9 | 2017-02-08 13:53:39 -0700 | [diff] [blame] | 2580 | bool ValidateCmdBufImageLayouts(layer_data *device_data, GLOBAL_CB_NODE *pCB, |
Chris Forbes | f9d7acd | 2017-06-26 17:57:39 -0700 | [diff] [blame] | 2581 | std::unordered_map<ImageSubresourcePair, IMAGE_LAYOUT_NODE> const & globalImageLayoutMap, |
| 2582 | std::unordered_map<ImageSubresourcePair, IMAGE_LAYOUT_NODE> & overlayLayoutMap) { |
Mark Lobodzinski | b0dd947 | 2017-02-07 16:38:17 -0700 | [diff] [blame] | 2583 | bool skip = false; |
Tony Barbour | df013b9 | 2017-01-25 12:53:48 -0700 | [diff] [blame] | 2584 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
Mark Lobodzinski | 4a3065e | 2017-02-07 16:36:03 -0700 | [diff] [blame] | 2585 | for (auto cb_image_data : pCB->imageLayoutMap) { |
| 2586 | VkImageLayout imageLayout; |
Tony Barbour | df013b9 | 2017-01-25 12:53:48 -0700 | [diff] [blame] | 2587 | |
Chris Forbes | f9d7acd | 2017-06-26 17:57:39 -0700 | [diff] [blame] | 2588 | if (FindLayout(overlayLayoutMap, cb_image_data.first, imageLayout) || |
| 2589 | FindLayout(globalImageLayoutMap, cb_image_data.first, imageLayout)) { |
Mark Lobodzinski | 4a3065e | 2017-02-07 16:36:03 -0700 | [diff] [blame] | 2590 | if (cb_image_data.second.initialLayout == VK_IMAGE_LAYOUT_UNDEFINED) { |
| 2591 | // TODO: Set memory invalid which is in mem_tracker currently |
| 2592 | } else if (imageLayout != cb_image_data.second.initialLayout) { |
| 2593 | if (cb_image_data.first.hasSubresource) { |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 2594 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 2595 | HandleToUint64(pCB->commandBuffer), __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", |
| 2596 | "Cannot submit cmd buffer using image (0x%" PRIx64 |
| 2597 | ") [sub-resource: aspectMask 0x%X array layer %u, mip level %u], " |
| 2598 | "with layout %s when first use is %s.", |
| 2599 | HandleToUint64(cb_image_data.first.image), cb_image_data.first.subresource.aspectMask, |
| 2600 | cb_image_data.first.subresource.arrayLayer, cb_image_data.first.subresource.mipLevel, |
| 2601 | string_VkImageLayout(imageLayout), string_VkImageLayout(cb_image_data.second.initialLayout)); |
Mark Lobodzinski | 4a3065e | 2017-02-07 16:36:03 -0700 | [diff] [blame] | 2602 | } else { |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 2603 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 2604 | HandleToUint64(pCB->commandBuffer), __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", |
| 2605 | "Cannot submit cmd buffer using image (0x%" PRIx64 |
| 2606 | ") with layout %s when " |
| 2607 | "first use is %s.", |
| 2608 | HandleToUint64(cb_image_data.first.image), string_VkImageLayout(imageLayout), |
| 2609 | string_VkImageLayout(cb_image_data.second.initialLayout)); |
Mark Lobodzinski | 4a3065e | 2017-02-07 16:36:03 -0700 | [diff] [blame] | 2610 | } |
| 2611 | } |
Chris Forbes | f9d7acd | 2017-06-26 17:57:39 -0700 | [diff] [blame] | 2612 | SetLayout(overlayLayoutMap, cb_image_data.first, cb_image_data.second.layout); |
Mark Lobodzinski | 4a3065e | 2017-02-07 16:36:03 -0700 | [diff] [blame] | 2613 | } |
| 2614 | } |
Mark Lobodzinski | b0dd947 | 2017-02-07 16:38:17 -0700 | [diff] [blame] | 2615 | return skip; |
Mark Lobodzinski | 4a3065e | 2017-02-07 16:36:03 -0700 | [diff] [blame] | 2616 | } |
Mark Lobodzinski | b3829a5 | 2017-02-07 16:55:53 -0700 | [diff] [blame] | 2617 | |
Tony Barbour | df013b9 | 2017-01-25 12:53:48 -0700 | [diff] [blame] | 2618 | void UpdateCmdBufImageLayouts(layer_data *device_data, GLOBAL_CB_NODE *pCB) { |
| 2619 | for (auto cb_image_data : pCB->imageLayoutMap) { |
| 2620 | VkImageLayout imageLayout; |
| 2621 | FindGlobalLayout(device_data, cb_image_data.first, imageLayout); |
| 2622 | SetGlobalLayout(device_data, cb_image_data.first, cb_image_data.second.layout); |
| 2623 | } |
| 2624 | } |
| 2625 | |
Mark Lobodzinski | b3829a5 | 2017-02-07 16:55:53 -0700 | [diff] [blame] | 2626 | // Print readable FlagBits in FlagMask |
| 2627 | static std::string string_VkAccessFlags(VkAccessFlags accessMask) { |
| 2628 | std::string result; |
| 2629 | std::string separator; |
| 2630 | |
| 2631 | if (accessMask == 0) { |
| 2632 | result = "[None]"; |
| 2633 | } else { |
| 2634 | result = "["; |
| 2635 | for (auto i = 0; i < 32; i++) { |
| 2636 | if (accessMask & (1 << i)) { |
| 2637 | result = result + separator + string_VkAccessFlagBits((VkAccessFlagBits)(1 << i)); |
| 2638 | separator = " | "; |
| 2639 | } |
| 2640 | } |
| 2641 | result = result + "]"; |
| 2642 | } |
| 2643 | return result; |
| 2644 | } |
| 2645 | |
Mark Lobodzinski | 9a8d40f | 2017-02-07 17:00:12 -0700 | [diff] [blame] | 2646 | // AccessFlags MUST have 'required_bit' set, and may have one or more of 'optional_bits' set. If required_bit is zero, accessMask |
| 2647 | // must have at least one of 'optional_bits' set |
Mark Lobodzinski | b3829a5 | 2017-02-07 16:55:53 -0700 | [diff] [blame] | 2648 | // 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] | 2649 | static bool ValidateMaskBits(core_validation::layer_data *device_data, VkCommandBuffer cmdBuffer, const VkAccessFlags &accessMask, |
| 2650 | const VkImageLayout &layout, VkAccessFlags required_bit, VkAccessFlags optional_bits, |
| 2651 | const char *type) { |
| 2652 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 2653 | bool skip = false; |
Mark Lobodzinski | b3829a5 | 2017-02-07 16:55:53 -0700 | [diff] [blame] | 2654 | |
| 2655 | if ((accessMask & required_bit) || (!required_bit && (accessMask & optional_bits))) { |
| 2656 | if (accessMask & ~(required_bit | optional_bits)) { |
| 2657 | // TODO: Verify against Valid Use |
Mark Lobodzinski | 0827aec | 2017-03-21 16:41:45 -0600 | [diff] [blame] | 2658 | 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] | 2659 | HandleToUint64(cmdBuffer), __LINE__, DRAWSTATE_INVALID_BARRIER, "DS", |
Mark Lobodzinski | 9a8d40f | 2017-02-07 17:00:12 -0700 | [diff] [blame] | 2660 | "Additional bits in %s accessMask 0x%X %s are specified when layout is %s.", type, accessMask, |
| 2661 | string_VkAccessFlags(accessMask).c_str(), string_VkImageLayout(layout)); |
Mark Lobodzinski | b3829a5 | 2017-02-07 16:55:53 -0700 | [diff] [blame] | 2662 | } |
| 2663 | } else { |
| 2664 | if (!required_bit) { |
Mark Lobodzinski | 0827aec | 2017-03-21 16:41:45 -0600 | [diff] [blame] | 2665 | 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] | 2666 | HandleToUint64(cmdBuffer), __LINE__, DRAWSTATE_INVALID_BARRIER, "DS", |
Mark Lobodzinski | 9a8d40f | 2017-02-07 17:00:12 -0700 | [diff] [blame] | 2667 | "%s AccessMask %d %s must contain at least one of access bits %d " |
| 2668 | "%s when layout is %s, unless the app has previously added a " |
| 2669 | "barrier for this transition.", |
| 2670 | type, accessMask, string_VkAccessFlags(accessMask).c_str(), optional_bits, |
| 2671 | string_VkAccessFlags(optional_bits).c_str(), string_VkImageLayout(layout)); |
Mark Lobodzinski | b3829a5 | 2017-02-07 16:55:53 -0700 | [diff] [blame] | 2672 | } else { |
| 2673 | std::string opt_bits; |
| 2674 | if (optional_bits != 0) { |
| 2675 | std::stringstream ss; |
| 2676 | ss << optional_bits; |
| 2677 | opt_bits = "and may have optional bits " + ss.str() + ' ' + string_VkAccessFlags(optional_bits); |
| 2678 | } |
Mark Lobodzinski | 0827aec | 2017-03-21 16:41:45 -0600 | [diff] [blame] | 2679 | 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] | 2680 | HandleToUint64(cmdBuffer), __LINE__, DRAWSTATE_INVALID_BARRIER, "DS", |
Mark Lobodzinski | 9a8d40f | 2017-02-07 17:00:12 -0700 | [diff] [blame] | 2681 | "%s AccessMask %d %s must have required access bit %d %s %s when " |
| 2682 | "layout is %s, unless the app has previously added a barrier for " |
| 2683 | "this transition.", |
| 2684 | type, accessMask, string_VkAccessFlags(accessMask).c_str(), required_bit, |
| 2685 | 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] | 2686 | } |
| 2687 | } |
Mark Lobodzinski | 9a8d40f | 2017-02-07 17:00:12 -0700 | [diff] [blame] | 2688 | return skip; |
Mark Lobodzinski | b3829a5 | 2017-02-07 16:55:53 -0700 | [diff] [blame] | 2689 | } |
| 2690 | |
Mark Lobodzinski | 9a8d40f | 2017-02-07 17:00:12 -0700 | [diff] [blame] | 2691 | bool ValidateMaskBitsFromLayouts(core_validation::layer_data *device_data, VkCommandBuffer cmdBuffer, |
| 2692 | const VkAccessFlags &accessMask, const VkImageLayout &layout, const char *type) { |
| 2693 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
Mark Lobodzinski | b3829a5 | 2017-02-07 16:55:53 -0700 | [diff] [blame] | 2694 | |
Mark Lobodzinski | 9a8d40f | 2017-02-07 17:00:12 -0700 | [diff] [blame] | 2695 | bool skip = false; |
Mark Lobodzinski | b3829a5 | 2017-02-07 16:55:53 -0700 | [diff] [blame] | 2696 | switch (layout) { |
Mark Lobodzinski | 9a8d40f | 2017-02-07 17:00:12 -0700 | [diff] [blame] | 2697 | case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: { |
| 2698 | skip |= ValidateMaskBits(device_data, cmdBuffer, accessMask, layout, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, |
| 2699 | VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT, type); |
| 2700 | break; |
Mark Lobodzinski | b3829a5 | 2017-02-07 16:55:53 -0700 | [diff] [blame] | 2701 | } |
Mark Lobodzinski | 9a8d40f | 2017-02-07 17:00:12 -0700 | [diff] [blame] | 2702 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: { |
| 2703 | skip |= ValidateMaskBits(device_data, cmdBuffer, accessMask, layout, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, |
| 2704 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT, type); |
| 2705 | break; |
| 2706 | } |
| 2707 | case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL: { |
| 2708 | skip |= ValidateMaskBits(device_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_WRITE_BIT, 0, type); |
| 2709 | break; |
| 2710 | } |
| 2711 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: { |
| 2712 | skip |= ValidateMaskBits( |
| 2713 | device_data, cmdBuffer, accessMask, layout, 0, |
| 2714 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT, |
| 2715 | type); |
| 2716 | break; |
| 2717 | } |
| 2718 | case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: { |
| 2719 | skip |= ValidateMaskBits(device_data, cmdBuffer, accessMask, layout, 0, |
| 2720 | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT | VK_ACCESS_SHADER_READ_BIT, type); |
| 2721 | break; |
| 2722 | } |
| 2723 | case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL: { |
| 2724 | skip |= ValidateMaskBits(device_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_READ_BIT, 0, type); |
| 2725 | break; |
| 2726 | } |
Mark Lobodzinski | 9a8d40f | 2017-02-07 17:00:12 -0700 | [diff] [blame] | 2727 | case VK_IMAGE_LAYOUT_UNDEFINED: { |
| 2728 | if (accessMask != 0) { |
| 2729 | // TODO: Verify against Valid Use section spec |
Mark Lobodzinski | 0827aec | 2017-03-21 16:41:45 -0600 | [diff] [blame] | 2730 | 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] | 2731 | HandleToUint64(cmdBuffer), __LINE__, DRAWSTATE_INVALID_BARRIER, "DS", |
Mark Lobodzinski | 9a8d40f | 2017-02-07 17:00:12 -0700 | [diff] [blame] | 2732 | "Additional bits in %s accessMask 0x%X %s are specified when layout is %s.", type, accessMask, |
| 2733 | string_VkAccessFlags(accessMask).c_str(), string_VkImageLayout(layout)); |
| 2734 | } |
| 2735 | break; |
| 2736 | } |
Chris Forbes | bfd831d | 2017-04-28 17:29:10 -0700 | [diff] [blame] | 2737 | case VK_IMAGE_LAYOUT_PRESENT_SRC_KHR: |
Dave Houlton | 1150cf5 | 2017-04-27 14:38:11 -0600 | [diff] [blame] | 2738 | // Notes: QueuePresentKHR performs automatic visibility operations, |
| 2739 | // so the app is /NOT/ required to include VK_ACCESS_MEMORY_READ_BIT |
| 2740 | // when transitioning to this layout. |
| 2741 | // |
| 2742 | // When transitioning /from/ this layout, the application needs to |
| 2743 | // avoid only a WAR hazard -- any writes need to be ordered after |
| 2744 | // the PE's reads. There is no need for a memory dependency for this |
| 2745 | // case. |
Mark Lobodzinski | 087380c | 2017-05-16 14:42:25 -0600 | [diff] [blame] | 2746 | // Intentionally fall through |
| 2747 | |
| 2748 | case VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR: |
| 2749 | // Todo -- shouldn't be valid unless extension is enabled |
| 2750 | // Intentionally fall through |
Chris Forbes | bfd831d | 2017-04-28 17:29:10 -0700 | [diff] [blame] | 2751 | |
Mark Lobodzinski | 9a8d40f | 2017-02-07 17:00:12 -0700 | [diff] [blame] | 2752 | case VK_IMAGE_LAYOUT_GENERAL: |
| 2753 | default: { break; } |
Mark Lobodzinski | b3829a5 | 2017-02-07 16:55:53 -0700 | [diff] [blame] | 2754 | } |
Mark Lobodzinski | 9a8d40f | 2017-02-07 17:00:12 -0700 | [diff] [blame] | 2755 | return skip; |
Mark Lobodzinski | b3829a5 | 2017-02-07 16:55:53 -0700 | [diff] [blame] | 2756 | } |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 2757 | |
| 2758 | // 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] | 2759 | // VkAttachmentDescription structs that are used by the sub-passes of a renderpass. Initial check is to make sure that READ_ONLY |
| 2760 | // layout attachments don't have CLEAR as their loadOp. |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 2761 | bool ValidateLayoutVsAttachmentDescription(const debug_report_data *report_data, const VkImageLayout first_layout, |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 2762 | const uint32_t attachment, const VkAttachmentDescription &attachment_description) { |
| 2763 | bool skip = false; |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 2764 | // Verify that initial loadOp on READ_ONLY attachments is not CLEAR |
| 2765 | if (attachment_description.loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR) { |
| 2766 | if ((first_layout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL) || |
| 2767 | (first_layout == VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL)) { |
Mark Lobodzinski | eb9e73f | 2017-04-13 10:06:48 -0600 | [diff] [blame] | 2768 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 2769 | VALIDATION_ERROR_12200688, "DS", "Cannot clear attachment %d with invalid first layout %s. %s", |
| 2770 | attachment, string_VkImageLayout(first_layout), validation_error_map[VALIDATION_ERROR_12200688]); |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 2771 | } |
| 2772 | } |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 2773 | return skip; |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 2774 | } |
| 2775 | |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 2776 | bool ValidateLayouts(core_validation::layer_data *device_data, VkDevice device, const VkRenderPassCreateInfo *pCreateInfo) { |
| 2777 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 2778 | bool skip = false; |
| 2779 | |
| 2780 | // Track when we're observing the first use of an attachment |
| 2781 | std::vector<bool> attach_first_use(pCreateInfo->attachmentCount, true); |
| 2782 | for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) { |
| 2783 | const VkSubpassDescription &subpass = pCreateInfo->pSubpasses[i]; |
Cort Stratton | 7547f77 | 2017-05-04 15:18:52 -0700 | [diff] [blame] | 2784 | |
| 2785 | // Check input attachments first, so we can detect first-use-as-input for VU #00349 |
| 2786 | for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) { |
| 2787 | auto attach_index = subpass.pInputAttachments[j].attachment; |
| 2788 | if (attach_index == VK_ATTACHMENT_UNUSED) continue; |
| 2789 | |
| 2790 | switch (subpass.pInputAttachments[j].layout) { |
| 2791 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: |
| 2792 | case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: |
| 2793 | // These are ideal. |
| 2794 | break; |
| 2795 | |
| 2796 | case VK_IMAGE_LAYOUT_GENERAL: |
| 2797 | // May not be optimal. TODO: reconsider this warning based on other constraints. |
| 2798 | skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 2799 | VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", |
| 2800 | "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL."); |
| 2801 | break; |
| 2802 | |
| 2803 | default: |
| 2804 | // No other layouts are acceptable |
| 2805 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 2806 | __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", |
| 2807 | "Layout for input attachment is %s but can only be READ_ONLY_OPTIMAL or GENERAL.", |
| 2808 | string_VkImageLayout(subpass.pInputAttachments[j].layout)); |
| 2809 | } |
| 2810 | |
| 2811 | VkImageLayout layout = subpass.pInputAttachments[j].layout; |
| 2812 | bool found_layout_mismatch = subpass.pDepthStencilAttachment && |
| 2813 | subpass.pDepthStencilAttachment->attachment == attach_index && |
| 2814 | subpass.pDepthStencilAttachment->layout != layout; |
| 2815 | for (uint32_t c = 0; !found_layout_mismatch && c < subpass.colorAttachmentCount; ++c) { |
| 2816 | found_layout_mismatch = |
| 2817 | (subpass.pColorAttachments[c].attachment == attach_index && subpass.pColorAttachments[c].layout != layout); |
| 2818 | } |
| 2819 | if (found_layout_mismatch) { |
| 2820 | skip |= log_msg( |
| 2821 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 2822 | VALIDATION_ERROR_140006ae, "DS", |
Cort Stratton | 7547f77 | 2017-05-04 15:18:52 -0700 | [diff] [blame] | 2823 | "CreateRenderPass: Subpass %u pInputAttachments[%u] (%u) has layout %u, but is also used as a depth/color " |
| 2824 | "attachment with a different layout. %s", |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 2825 | i, j, attach_index, layout, validation_error_map[VALIDATION_ERROR_140006ae]); |
Cort Stratton | 7547f77 | 2017-05-04 15:18:52 -0700 | [diff] [blame] | 2826 | } |
| 2827 | |
| 2828 | if (attach_first_use[attach_index]) { |
| 2829 | skip |= ValidateLayoutVsAttachmentDescription(report_data, subpass.pInputAttachments[j].layout, attach_index, |
| 2830 | pCreateInfo->pAttachments[attach_index]); |
| 2831 | |
| 2832 | bool used_as_depth = |
| 2833 | (subpass.pDepthStencilAttachment != NULL && subpass.pDepthStencilAttachment->attachment == attach_index); |
| 2834 | bool used_as_color = false; |
| 2835 | for (uint32_t k = 0; !used_as_depth && !used_as_color && k < subpass.colorAttachmentCount; ++k) { |
| 2836 | used_as_color = (subpass.pColorAttachments[k].attachment == attach_index); |
| 2837 | } |
| 2838 | if (!used_as_depth && !used_as_color && |
| 2839 | pCreateInfo->pAttachments[attach_index].loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR) { |
| 2840 | skip |= log_msg( |
| 2841 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 2842 | VALIDATION_ERROR_1400069c, "DS", |
Cort Stratton | 7547f77 | 2017-05-04 15:18:52 -0700 | [diff] [blame] | 2843 | "CreateRenderPass: attachment %u is first used as an input attachment in subpass %u with loadOp=CLEAR. %s", |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 2844 | attach_index, attach_index, validation_error_map[VALIDATION_ERROR_1400069c]); |
Cort Stratton | 7547f77 | 2017-05-04 15:18:52 -0700 | [diff] [blame] | 2845 | } |
| 2846 | } |
| 2847 | attach_first_use[attach_index] = false; |
| 2848 | } |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 2849 | for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) { |
| 2850 | auto attach_index = subpass.pColorAttachments[j].attachment; |
| 2851 | if (attach_index == VK_ATTACHMENT_UNUSED) continue; |
| 2852 | |
Tobin Ehlis | bb03e5f | 2017-05-11 08:52:51 -0600 | [diff] [blame] | 2853 | // TODO: Need a way to validate shared presentable images here, currently just allowing |
| 2854 | // VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR |
| 2855 | // 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] | 2856 | switch (subpass.pColorAttachments[j].layout) { |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 2857 | case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2858 | // This is ideal. |
Tobin Ehlis | bb03e5f | 2017-05-11 08:52:51 -0600 | [diff] [blame] | 2859 | case VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR: |
| 2860 | // 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] | 2861 | break; |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 2862 | |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 2863 | case VK_IMAGE_LAYOUT_GENERAL: |
| 2864 | // May not be optimal; TODO: reconsider this warning based on other constraints? |
| 2865 | skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 2866 | VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", |
| 2867 | "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL."); |
| 2868 | break; |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 2869 | |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 2870 | default: |
| 2871 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 2872 | __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", |
| 2873 | "Layout for color attachment is %s but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.", |
| 2874 | string_VkImageLayout(subpass.pColorAttachments[j].layout)); |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 2875 | } |
| 2876 | |
| 2877 | if (attach_first_use[attach_index]) { |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 2878 | skip |= ValidateLayoutVsAttachmentDescription(report_data, subpass.pColorAttachments[j].layout, attach_index, |
| 2879 | pCreateInfo->pAttachments[attach_index]); |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 2880 | } |
| 2881 | attach_first_use[attach_index] = false; |
| 2882 | } |
| 2883 | if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) { |
| 2884 | switch (subpass.pDepthStencilAttachment->layout) { |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 2885 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: |
| 2886 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: |
| 2887 | // These are ideal. |
| 2888 | break; |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 2889 | |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 2890 | case VK_IMAGE_LAYOUT_GENERAL: |
| 2891 | // May not be optimal; TODO: reconsider this warning based on other constraints? GENERAL can be better than |
| 2892 | // doing a bunch of transitions. |
| 2893 | skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 2894 | VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", |
| 2895 | "GENERAL layout for depth attachment may not give optimal performance."); |
| 2896 | break; |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 2897 | |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 2898 | default: |
| 2899 | // No other layouts are acceptable |
| 2900 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 2901 | __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", |
| 2902 | "Layout for depth attachment is %s but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL, " |
| 2903 | "DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.", |
| 2904 | string_VkImageLayout(subpass.pDepthStencilAttachment->layout)); |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 2905 | } |
| 2906 | |
| 2907 | auto attach_index = subpass.pDepthStencilAttachment->attachment; |
| 2908 | if (attach_first_use[attach_index]) { |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 2909 | skip |= ValidateLayoutVsAttachmentDescription(report_data, subpass.pDepthStencilAttachment->layout, attach_index, |
| 2910 | pCreateInfo->pAttachments[attach_index]); |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 2911 | } |
| 2912 | attach_first_use[attach_index] = false; |
| 2913 | } |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 2914 | } |
| 2915 | return skip; |
| 2916 | } |
Mark Lobodzinski | 08f14fa | 2017-02-07 17:20:06 -0700 | [diff] [blame] | 2917 | |
| 2918 | // 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] | 2919 | bool ValidateMapImageLayouts(core_validation::layer_data *device_data, VkDevice device, DEVICE_MEM_INFO const *mem_info, |
| 2920 | VkDeviceSize offset, VkDeviceSize end_offset) { |
| 2921 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 2922 | bool skip = false; |
| 2923 | // Iterate over all bound image ranges and verify that for any that overlap the map ranges, the layouts are |
| 2924 | // VK_IMAGE_LAYOUT_PREINITIALIZED or VK_IMAGE_LAYOUT_GENERAL |
Mark Lobodzinski | 08f14fa | 2017-02-07 17:20:06 -0700 | [diff] [blame] | 2925 | // TODO : This can be optimized if we store ranges based on starting address and early exit when we pass our range |
| 2926 | for (auto image_handle : mem_info->bound_images) { |
| 2927 | auto img_it = mem_info->bound_ranges.find(image_handle); |
| 2928 | if (img_it != mem_info->bound_ranges.end()) { |
Mark Lobodzinski | ac23ec8 | 2017-02-07 17:21:55 -0700 | [diff] [blame] | 2929 | if (rangesIntersect(device_data, &img_it->second, offset, end_offset)) { |
Mark Lobodzinski | 08f14fa | 2017-02-07 17:20:06 -0700 | [diff] [blame] | 2930 | std::vector<VkImageLayout> layouts; |
Mark Lobodzinski | ac23ec8 | 2017-02-07 17:21:55 -0700 | [diff] [blame] | 2931 | if (FindLayouts(device_data, VkImage(image_handle), layouts)) { |
Mark Lobodzinski | 08f14fa | 2017-02-07 17:20:06 -0700 | [diff] [blame] | 2932 | for (auto layout : layouts) { |
| 2933 | if (layout != VK_IMAGE_LAYOUT_PREINITIALIZED && layout != VK_IMAGE_LAYOUT_GENERAL) { |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 2934 | skip |= |
| 2935 | log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_MEMORY_EXT, |
| 2936 | HandleToUint64(mem_info->mem), __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", |
| 2937 | "Mapping an image with layout %s can result in undefined behavior if this memory is " |
| 2938 | "used by the device. Only GENERAL or PREINITIALIZED should be used.", |
| 2939 | string_VkImageLayout(layout)); |
Mark Lobodzinski | 08f14fa | 2017-02-07 17:20:06 -0700 | [diff] [blame] | 2940 | } |
| 2941 | } |
| 2942 | } |
| 2943 | } |
| 2944 | } |
| 2945 | } |
Mark Lobodzinski | ac23ec8 | 2017-02-07 17:21:55 -0700 | [diff] [blame] | 2946 | return skip; |
Mark Lobodzinski | 08f14fa | 2017-02-07 17:20:06 -0700 | [diff] [blame] | 2947 | } |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 2948 | |
| 2949 | // Helper function to validate correct usage bits set for buffers or images. Verify that (actual & desired) flags != 0 or, if strict |
| 2950 | // is true, verify that (actual & desired) flags == desired |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 2951 | 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] | 2952 | 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] | 2953 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 2954 | |
| 2955 | bool correct_usage = false; |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 2956 | bool skip = false; |
Mark Lobodzinski | 3382637 | 2017-04-13 11:10:11 -0600 | [diff] [blame] | 2957 | const char *type_str = object_string[obj_type]; |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 2958 | if (strict) { |
| 2959 | correct_usage = ((actual & desired) == desired); |
| 2960 | } else { |
| 2961 | correct_usage = ((actual & desired) != 0); |
| 2962 | } |
| 2963 | if (!correct_usage) { |
| 2964 | if (msgCode == -1) { |
| 2965 | // TODO: Fix callers with msgCode == -1 to use correct validation checks. |
Mark Lobodzinski | c51dbb7 | 2017-04-13 14:25:39 -0600 | [diff] [blame] | 2966 | 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] | 2967 | MEMTRACK_INVALID_USAGE_FLAG, "MEM", |
| 2968 | "Invalid usage flag for %s 0x%" PRIxLEAST64 |
| 2969 | " used by %s. In this case, %s should have %s set during creation.", |
| 2970 | type_str, obj_handle, func_name, type_str, usage_str); |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 2971 | } else { |
| 2972 | const char *valid_usage = (msgCode == -1) ? "" : validation_error_map[msgCode]; |
Mark Lobodzinski | 3382637 | 2017-04-13 11:10:11 -0600 | [diff] [blame] | 2973 | skip = log_msg( |
Mark Lobodzinski | c51dbb7 | 2017-04-13 14:25:39 -0600 | [diff] [blame] | 2974 | 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] | 2975 | "Invalid usage flag for %s 0x%" PRIxLEAST64 " used by %s. In this case, %s should have %s set during creation. %s", |
| 2976 | type_str, obj_handle, func_name, type_str, usage_str, valid_usage); |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 2977 | } |
| 2978 | } |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 2979 | return skip; |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 2980 | } |
| 2981 | |
| 2982 | // Helper function to validate usage flags for buffers. For given buffer_state send actual vs. desired usage off to helper above |
| 2983 | // where an error will be flagged if usage is not correct |
Chris Forbes | 8fdba30 | 2017-04-24 18:34:28 -0700 | [diff] [blame] | 2984 | 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] | 2985 | int32_t const msgCode, char const *func_name, char const *usage_string) { |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 2986 | return validate_usage_flags(device_data, image_state->createInfo.usage, desired, strict, HandleToUint64(image_state->image), |
| 2987 | kVulkanObjectTypeImage, msgCode, func_name, usage_string); |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 2988 | } |
| 2989 | |
| 2990 | // Helper function to validate usage flags for buffers. For given buffer_state send actual vs. desired usage off to helper above |
| 2991 | // where an error will be flagged if usage is not correct |
Chris Forbes | 8fdba30 | 2017-04-24 18:34:28 -0700 | [diff] [blame] | 2992 | 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] | 2993 | int32_t const msgCode, char const *func_name, char const *usage_string) { |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 2994 | return validate_usage_flags(device_data, buffer_state->createInfo.usage, desired, strict, HandleToUint64(buffer_state->buffer), |
| 2995 | kVulkanObjectTypeBuffer, msgCode, func_name, usage_string); |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 2996 | } |
| 2997 | |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 2998 | bool PreCallValidateCreateBuffer(layer_data *device_data, const VkBufferCreateInfo *pCreateInfo) { |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 2999 | bool skip = false; |
Mark Lobodzinski | 847b60c | 2017-03-13 09:32:45 -0600 | [diff] [blame] | 3000 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 3001 | |
Chris Forbes | e0f511c | 2017-06-14 12:38:01 -0700 | [diff] [blame] | 3002 | // TODO: Add check for VALIDATION_ERROR_1ec0071e (sparse address space accounting) |
Mark Lobodzinski | 847b60c | 2017-03-13 09:32:45 -0600 | [diff] [blame] | 3003 | |
| 3004 | if ((pCreateInfo->flags & VK_BUFFER_CREATE_SPARSE_BINDING_BIT) && (!GetEnabledFeatures(device_data)->sparseBinding)) { |
| 3005 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3006 | VALIDATION_ERROR_01400726, "DS", |
Mark Lobodzinski | 847b60c | 2017-03-13 09:32:45 -0600 | [diff] [blame] | 3007 | "vkCreateBuffer(): the sparseBinding device feature is disabled: Buffers cannot be created with the " |
| 3008 | "VK_BUFFER_CREATE_SPARSE_BINDING_BIT set. %s", |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3009 | validation_error_map[VALIDATION_ERROR_01400726]); |
Mark Lobodzinski | 847b60c | 2017-03-13 09:32:45 -0600 | [diff] [blame] | 3010 | } |
Mark Lobodzinski | af35506 | 2017-03-13 09:35:01 -0600 | [diff] [blame] | 3011 | |
| 3012 | if ((pCreateInfo->flags & VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT) && (!GetEnabledFeatures(device_data)->sparseResidencyBuffer)) { |
| 3013 | skip |= |
| 3014 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, |
Chris Forbes | e0f511c | 2017-06-14 12:38:01 -0700 | [diff] [blame] | 3015 | VALIDATION_ERROR_01400728, "DS", |
Mark Lobodzinski | af35506 | 2017-03-13 09:35:01 -0600 | [diff] [blame] | 3016 | "vkCreateBuffer(): the sparseResidencyBuffer device feature is disabled: Buffers cannot be created with the " |
Chris Forbes | e0f511c | 2017-06-14 12:38:01 -0700 | [diff] [blame] | 3017 | "VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT set. %s", |
| 3018 | validation_error_map[VALIDATION_ERROR_01400728]); |
Mark Lobodzinski | af35506 | 2017-03-13 09:35:01 -0600 | [diff] [blame] | 3019 | } |
Mark Lobodzinski | 035a4cf | 2017-03-13 09:45:07 -0600 | [diff] [blame] | 3020 | |
| 3021 | if ((pCreateInfo->flags & VK_BUFFER_CREATE_SPARSE_ALIASED_BIT) && (!GetEnabledFeatures(device_data)->sparseResidencyAliased)) { |
| 3022 | skip |= |
| 3023 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, |
Chris Forbes | e0f511c | 2017-06-14 12:38:01 -0700 | [diff] [blame] | 3024 | VALIDATION_ERROR_0140072a, "DS", |
Mark Lobodzinski | 035a4cf | 2017-03-13 09:45:07 -0600 | [diff] [blame] | 3025 | "vkCreateBuffer(): the sparseResidencyAliased device feature is disabled: Buffers cannot be created with the " |
Chris Forbes | e0f511c | 2017-06-14 12:38:01 -0700 | [diff] [blame] | 3026 | "VK_BUFFER_CREATE_SPARSE_ALIASED_BIT set. %s", |
| 3027 | validation_error_map[VALIDATION_ERROR_0140072a]); |
Mark Lobodzinski | 035a4cf | 2017-03-13 09:45:07 -0600 | [diff] [blame] | 3028 | } |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 3029 | return skip; |
| 3030 | } |
| 3031 | |
| 3032 | void PostCallRecordCreateBuffer(layer_data *device_data, const VkBufferCreateInfo *pCreateInfo, VkBuffer *pBuffer) { |
| 3033 | // TODO : This doesn't create deep copy of pQueueFamilyIndices so need to fix that if/when we want that data to be valid |
| 3034 | GetBufferMap(device_data) |
| 3035 | ->insert(std::make_pair(*pBuffer, std::unique_ptr<BUFFER_STATE>(new BUFFER_STATE(*pBuffer, pCreateInfo)))); |
| 3036 | } |
| 3037 | |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 3038 | bool PreCallValidateCreateBufferView(layer_data *device_data, const VkBufferViewCreateInfo *pCreateInfo) { |
| 3039 | bool skip = false; |
| 3040 | BUFFER_STATE *buffer_state = GetBufferState(device_data, pCreateInfo->buffer); |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 3041 | // If this isn't a sparse buffer, it needs to have memory backing it at CreateBufferView time |
| 3042 | if (buffer_state) { |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3043 | skip |= ValidateMemoryIsBoundToBuffer(device_data, buffer_state, "vkCreateBufferView()", VALIDATION_ERROR_01a0074e); |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 3044 | // In order to create a valid buffer view, the buffer must have been created with at least one of the following flags: |
| 3045 | // UNIFORM_TEXEL_BUFFER_BIT or STORAGE_TEXEL_BUFFER_BIT |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 3046 | skip |= ValidateBufferUsageFlags( |
| 3047 | device_data, buffer_state, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT, false, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3048 | VALIDATION_ERROR_01a00748, "vkCreateBufferView()", "VK_BUFFER_USAGE_[STORAGE|UNIFORM]_TEXEL_BUFFER_BIT"); |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 3049 | } |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 3050 | return skip; |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 3051 | } |
| 3052 | |
| 3053 | void PostCallRecordCreateBufferView(layer_data *device_data, const VkBufferViewCreateInfo *pCreateInfo, VkBufferView *pView) { |
| 3054 | (*GetBufferViewMap(device_data))[*pView] = std::unique_ptr<BUFFER_VIEW_STATE>(new BUFFER_VIEW_STATE(*pView, pCreateInfo)); |
| 3055 | } |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3056 | |
| 3057 | // For the given format verify that the aspect masks make sense |
| 3058 | bool ValidateImageAspectMask(layer_data *device_data, VkImage image, VkFormat format, VkImageAspectFlags aspect_mask, |
| 3059 | const char *func_name) { |
| 3060 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 3061 | bool skip = false; |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 3062 | if (FormatIsColor(format)) { |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3063 | 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] | 3064 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3065 | HandleToUint64(image), __LINE__, VALIDATION_ERROR_0a400c01, "IMAGE", |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3066 | "%s: Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set. %s", func_name, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3067 | validation_error_map[VALIDATION_ERROR_0a400c01]); |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3068 | } else if ((aspect_mask & VK_IMAGE_ASPECT_COLOR_BIT) != aspect_mask) { |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 3069 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3070 | HandleToUint64(image), __LINE__, VALIDATION_ERROR_0a400c01, "IMAGE", |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3071 | "%s: Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set. %s", func_name, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3072 | validation_error_map[VALIDATION_ERROR_0a400c01]); |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3073 | } |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 3074 | } else if (FormatIsDepthAndStencil(format)) { |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3075 | 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] | 3076 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3077 | HandleToUint64(image), __LINE__, VALIDATION_ERROR_0a400c01, "IMAGE", |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3078 | "%s: Depth/stencil image formats must have " |
| 3079 | "at least one of VK_IMAGE_ASPECT_DEPTH_BIT " |
| 3080 | "and VK_IMAGE_ASPECT_STENCIL_BIT set. %s", |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3081 | func_name, validation_error_map[VALIDATION_ERROR_0a400c01]); |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3082 | } 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] | 3083 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3084 | HandleToUint64(image), __LINE__, VALIDATION_ERROR_0a400c01, "IMAGE", |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3085 | "%s: Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and " |
| 3086 | "VK_IMAGE_ASPECT_STENCIL_BIT set. %s", |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3087 | func_name, validation_error_map[VALIDATION_ERROR_0a400c01]); |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3088 | } |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 3089 | } else if (FormatIsDepthOnly(format)) { |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3090 | 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] | 3091 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3092 | HandleToUint64(image), __LINE__, VALIDATION_ERROR_0a400c01, "IMAGE", |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3093 | "%s: Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set. %s", func_name, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3094 | validation_error_map[VALIDATION_ERROR_0a400c01]); |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3095 | } else if ((aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) != aspect_mask) { |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 3096 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3097 | HandleToUint64(image), __LINE__, VALIDATION_ERROR_0a400c01, "IMAGE", |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3098 | "%s: Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set. %s", func_name, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3099 | validation_error_map[VALIDATION_ERROR_0a400c01]); |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3100 | } |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 3101 | } else if (FormatIsStencilOnly(format)) { |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3102 | 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] | 3103 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3104 | HandleToUint64(image), __LINE__, VALIDATION_ERROR_0a400c01, "IMAGE", |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3105 | "%s: Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set. %s", func_name, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3106 | validation_error_map[VALIDATION_ERROR_0a400c01]); |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3107 | } else if ((aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) != aspect_mask) { |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 3108 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3109 | HandleToUint64(image), __LINE__, VALIDATION_ERROR_0a400c01, "IMAGE", |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3110 | "%s: Stencil-only image formats can have only the VK_IMAGE_ASPECT_STENCIL_BIT set. %s", func_name, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3111 | validation_error_map[VALIDATION_ERROR_0a400c01]); |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3112 | } |
| 3113 | } |
| 3114 | return skip; |
| 3115 | } |
| 3116 | |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 3117 | struct SubresourceRangeErrorCodes { |
| 3118 | UNIQUE_VALIDATION_ERROR_CODE base_mip_err, mip_count_err, base_layer_err, layer_count_err; |
| 3119 | }; |
| 3120 | |
| 3121 | bool ValidateImageSubresourceRange(const layer_data *device_data, const uint32_t image_mip_count, const uint32_t image_layer_count, |
| 3122 | const VkImageSubresourceRange &subresourceRange, const char *cmd_name, const char *param_name, |
| 3123 | const char *image_layer_count_var_name, const uint64_t image_handle, |
| 3124 | SubresourceRangeErrorCodes errorCodes) { |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3125 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 3126 | bool skip = false; |
Petr Kraus | 4d71868 | 2017-05-18 03:38:41 +0200 | [diff] [blame] | 3127 | |
| 3128 | // Validate mip levels |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 3129 | if (subresourceRange.baseMipLevel >= image_mip_count) { |
| 3130 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, image_handle, __LINE__, |
| 3131 | errorCodes.base_mip_err, "IMAGE", |
| 3132 | "%s: %s.baseMipLevel (= %" PRIu32 |
| 3133 | ") is greater or equal to the mip level count of the image (i.e. greater or equal to %" PRIu32 "). %s", |
| 3134 | cmd_name, param_name, subresourceRange.baseMipLevel, image_mip_count, |
| 3135 | validation_error_map[errorCodes.base_mip_err]); |
| 3136 | } |
Petr Kraus | 4d71868 | 2017-05-18 03:38:41 +0200 | [diff] [blame] | 3137 | |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 3138 | if (subresourceRange.levelCount != VK_REMAINING_MIP_LEVELS) { |
| 3139 | if (subresourceRange.levelCount == 0) { |
| 3140 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, image_handle, |
| 3141 | __LINE__, errorCodes.mip_count_err, "IMAGE", "%s: %s.levelCount is 0. %s", cmd_name, param_name, |
| 3142 | validation_error_map[errorCodes.mip_count_err]); |
| 3143 | } else { |
| 3144 | const uint64_t necessary_mip_count = uint64_t{subresourceRange.baseMipLevel} + uint64_t{subresourceRange.levelCount}; |
Petr Kraus | 4d71868 | 2017-05-18 03:38:41 +0200 | [diff] [blame] | 3145 | |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 3146 | if (necessary_mip_count > image_mip_count) { |
| 3147 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, image_handle, |
| 3148 | __LINE__, errorCodes.mip_count_err, "IMAGE", |
| 3149 | "%s: %s.baseMipLevel + .levelCount (= %" PRIu32 " + %" PRIu32 " = %" PRIu64 |
| 3150 | ") is greater than the mip level count of the image (i.e. greater than %" PRIu32 "). %s", |
| 3151 | cmd_name, param_name, subresourceRange.baseMipLevel, subresourceRange.levelCount, |
| 3152 | necessary_mip_count, image_mip_count, validation_error_map[errorCodes.mip_count_err]); |
| 3153 | } |
Petr Kraus | 4d71868 | 2017-05-18 03:38:41 +0200 | [diff] [blame] | 3154 | } |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3155 | } |
Petr Kraus | 4d71868 | 2017-05-18 03:38:41 +0200 | [diff] [blame] | 3156 | |
| 3157 | // Validate array layers |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 3158 | if (subresourceRange.baseArrayLayer >= image_layer_count) { |
| 3159 | skip |= |
| 3160 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, image_handle, __LINE__, |
| 3161 | errorCodes.base_layer_err, "IMAGE", |
| 3162 | "%s: %s.baseArrayLayer (= %" PRIu32 |
| 3163 | ") is greater or equal to the %s of the image when it was created (i.e. greater or equal to %" PRIu32 "). %s", |
| 3164 | cmd_name, param_name, subresourceRange.baseArrayLayer, image_layer_count_var_name, image_layer_count, |
| 3165 | validation_error_map[errorCodes.base_layer_err]); |
| 3166 | } |
Petr Kraus | 4d71868 | 2017-05-18 03:38:41 +0200 | [diff] [blame] | 3167 | |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 3168 | if (subresourceRange.layerCount != VK_REMAINING_ARRAY_LAYERS) { |
| 3169 | if (subresourceRange.layerCount == 0) { |
| 3170 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, image_handle, |
| 3171 | __LINE__, errorCodes.layer_count_err, "IMAGE", "%s: %s.layerCount is 0. %s", cmd_name, param_name, |
| 3172 | validation_error_map[errorCodes.layer_count_err]); |
| 3173 | } else { |
| 3174 | const uint64_t necessary_layer_count = |
| 3175 | uint64_t{subresourceRange.baseArrayLayer} + uint64_t{subresourceRange.layerCount}; |
Petr Kraus | 8423f15 | 2017-05-26 01:20:04 +0200 | [diff] [blame] | 3176 | |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 3177 | if (necessary_layer_count > image_layer_count) { |
| 3178 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, image_handle, |
| 3179 | __LINE__, errorCodes.layer_count_err, "IMAGE", |
| 3180 | "%s: %s.baseArrayLayer + .layerCount (= %" PRIu32 " + %" PRIu32 " = %" PRIu64 |
| 3181 | ") is greater than the %s of the image when it was created (i.e. greater than %" PRIu32 "). %s", |
| 3182 | cmd_name, param_name, subresourceRange.baseArrayLayer, subresourceRange.layerCount, |
| 3183 | necessary_layer_count, image_layer_count_var_name, image_layer_count, |
| 3184 | validation_error_map[errorCodes.layer_count_err]); |
| 3185 | } |
Petr Kraus | 4d71868 | 2017-05-18 03:38:41 +0200 | [diff] [blame] | 3186 | } |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3187 | } |
Petr Kraus | 4d71868 | 2017-05-18 03:38:41 +0200 | [diff] [blame] | 3188 | |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3189 | return skip; |
| 3190 | } |
| 3191 | |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 3192 | bool ValidateCreateImageViewSubresourceRange(const layer_data *device_data, const IMAGE_STATE *image_state, |
| 3193 | bool is_imageview_2d_type, const VkImageSubresourceRange &subresourceRange) { |
| 3194 | bool is_khr_maintenance1 = GetDeviceExtensions(device_data)->vk_khr_maintenance1; |
| 3195 | bool is_image_slicable = image_state->createInfo.imageType == VK_IMAGE_TYPE_3D && |
| 3196 | (image_state->createInfo.flags & VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT_KHR); |
| 3197 | bool is_3D_to_2D_map = is_khr_maintenance1 && is_image_slicable && is_imageview_2d_type; |
| 3198 | |
| 3199 | const auto image_layer_count = is_3D_to_2D_map ? image_state->createInfo.extent.depth : image_state->createInfo.arrayLayers; |
| 3200 | const auto image_layer_count_var_name = is_3D_to_2D_map ? "extent.depth" : "arrayLayers"; |
| 3201 | |
| 3202 | SubresourceRangeErrorCodes subresourceRangeErrorCodes = {}; |
| 3203 | subresourceRangeErrorCodes.base_mip_err = VALIDATION_ERROR_0ac00b8c; |
| 3204 | subresourceRangeErrorCodes.mip_count_err = VALIDATION_ERROR_0ac00b8e; |
| 3205 | subresourceRangeErrorCodes.base_layer_err = |
| 3206 | is_khr_maintenance1 ? (is_3D_to_2D_map ? VALIDATION_ERROR_0ac00b98 : VALIDATION_ERROR_0ac00b94) : VALIDATION_ERROR_0ac00b90; |
| 3207 | subresourceRangeErrorCodes.layer_count_err = |
| 3208 | is_khr_maintenance1 ? (is_3D_to_2D_map ? VALIDATION_ERROR_0ac00b9a : VALIDATION_ERROR_0ac00b96) : VALIDATION_ERROR_0ac00b92; |
| 3209 | |
| 3210 | return ValidateImageSubresourceRange(device_data, image_state->createInfo.mipLevels, image_layer_count, subresourceRange, |
| 3211 | "vkCreateImageView", "pCreateInfo->subresourceRange", image_layer_count_var_name, |
| 3212 | HandleToUint64(image_state->image), subresourceRangeErrorCodes); |
| 3213 | } |
| 3214 | |
| 3215 | bool ValidateCmdClearColorSubresourceRange(const layer_data *device_data, const IMAGE_STATE *image_state, |
| 3216 | const VkImageSubresourceRange &subresourceRange, const char *param_name) { |
| 3217 | SubresourceRangeErrorCodes subresourceRangeErrorCodes = {}; |
| 3218 | subresourceRangeErrorCodes.base_mip_err = VALIDATION_ERROR_18800b7c; |
| 3219 | subresourceRangeErrorCodes.mip_count_err = VALIDATION_ERROR_18800b7e; |
| 3220 | subresourceRangeErrorCodes.base_layer_err = VALIDATION_ERROR_18800b80; |
| 3221 | subresourceRangeErrorCodes.layer_count_err = VALIDATION_ERROR_18800b82; |
| 3222 | |
| 3223 | return ValidateImageSubresourceRange(device_data, image_state->createInfo.mipLevels, image_state->createInfo.arrayLayers, |
| 3224 | subresourceRange, "vkCmdClearColorImage", param_name, "arrayLayers", |
| 3225 | HandleToUint64(image_state->image), subresourceRangeErrorCodes); |
| 3226 | } |
| 3227 | |
| 3228 | bool ValidateCmdClearDepthSubresourceRange(const layer_data *device_data, const IMAGE_STATE *image_state, |
| 3229 | const VkImageSubresourceRange &subresourceRange, const char *param_name) { |
| 3230 | SubresourceRangeErrorCodes subresourceRangeErrorCodes = {}; |
| 3231 | subresourceRangeErrorCodes.base_mip_err = VALIDATION_ERROR_18a00b84; |
| 3232 | subresourceRangeErrorCodes.mip_count_err = VALIDATION_ERROR_18a00b86; |
| 3233 | subresourceRangeErrorCodes.base_layer_err = VALIDATION_ERROR_18a00b88; |
| 3234 | subresourceRangeErrorCodes.layer_count_err = VALIDATION_ERROR_18a00b8a; |
| 3235 | |
| 3236 | return ValidateImageSubresourceRange(device_data, image_state->createInfo.mipLevels, image_state->createInfo.arrayLayers, |
| 3237 | subresourceRange, "vkCmdClearDepthStencilImage", param_name, "arrayLayers", |
| 3238 | HandleToUint64(image_state->image), subresourceRangeErrorCodes); |
| 3239 | } |
| 3240 | |
| 3241 | bool ValidateImageBarrierSubresourceRange(const layer_data *device_data, const IMAGE_STATE *image_state, |
| 3242 | const VkImageSubresourceRange &subresourceRange, const char *cmd_name, |
| 3243 | const char *param_name) { |
| 3244 | SubresourceRangeErrorCodes subresourceRangeErrorCodes = {}; |
| 3245 | subresourceRangeErrorCodes.base_mip_err = VALIDATION_ERROR_0a000b9c; |
| 3246 | subresourceRangeErrorCodes.mip_count_err = VALIDATION_ERROR_0a000b9e; |
| 3247 | subresourceRangeErrorCodes.base_layer_err = VALIDATION_ERROR_0a000ba0; |
| 3248 | subresourceRangeErrorCodes.layer_count_err = VALIDATION_ERROR_0a000ba2; |
| 3249 | |
| 3250 | return ValidateImageSubresourceRange(device_data, image_state->createInfo.mipLevels, image_state->createInfo.arrayLayers, |
| 3251 | subresourceRange, cmd_name, param_name, "arrayLayers", HandleToUint64(image_state->image), |
| 3252 | subresourceRangeErrorCodes); |
| 3253 | } |
| 3254 | |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3255 | bool PreCallValidateCreateImageView(layer_data *device_data, const VkImageViewCreateInfo *create_info) { |
| 3256 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 3257 | bool skip = false; |
| 3258 | IMAGE_STATE *image_state = GetImageState(device_data, create_info->image); |
| 3259 | if (image_state) { |
| 3260 | skip |= ValidateImageUsageFlags( |
| 3261 | device_data, image_state, |
| 3262 | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT | |
Jeremy Kniager | 846ab73 | 2017-07-10 13:12:04 -0600 | [diff] [blame] | 3263 | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3264 | false, -1, "vkCreateImageView()", |
| 3265 | "VK_IMAGE_USAGE_[SAMPLED|STORAGE|COLOR_ATTACHMENT|DEPTH_STENCIL_ATTACHMENT|INPUT_ATTACHMENT]_BIT"); |
| 3266 | // If this isn't a sparse image, it needs to have memory backing it at CreateImageView time |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3267 | skip |= ValidateMemoryIsBoundToImage(device_data, image_state, "vkCreateImageView()", VALIDATION_ERROR_0ac007f8); |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3268 | // Checks imported from image layer |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 3269 | skip |= ValidateCreateImageViewSubresourceRange( |
| 3270 | device_data, image_state, |
| 3271 | create_info->viewType == VK_IMAGE_VIEW_TYPE_2D || create_info->viewType == VK_IMAGE_VIEW_TYPE_2D_ARRAY, |
| 3272 | create_info->subresourceRange); |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3273 | |
| 3274 | VkImageCreateFlags image_flags = image_state->createInfo.flags; |
| 3275 | VkFormat image_format = image_state->createInfo.format; |
Jeremy Kniager | cef491c | 2017-07-18 11:10:28 -0600 | [diff] [blame] | 3276 | VkImageUsageFlags image_usage = image_state->createInfo.usage; |
| 3277 | VkImageTiling image_tiling = image_state->createInfo.tiling; |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3278 | VkFormat view_format = create_info->format; |
| 3279 | VkImageAspectFlags aspect_mask = create_info->subresourceRange.aspectMask; |
Jeremy Kniager | 846ab73 | 2017-07-10 13:12:04 -0600 | [diff] [blame] | 3280 | VkImageType image_type = image_state->createInfo.imageType; |
| 3281 | VkImageViewType view_type = create_info->viewType; |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3282 | |
| 3283 | // Validate VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT state |
| 3284 | if (image_flags & VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT) { |
| 3285 | // 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] | 3286 | if (FormatCompatibilityClass(image_format) != FormatCompatibilityClass(view_format)) { |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3287 | std::stringstream ss; |
| 3288 | ss << "vkCreateImageView(): ImageView format " << string_VkFormat(view_format) |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 3289 | << " is not in the same format compatibility class as image (" << HandleToUint64(create_info->image) |
| 3290 | << ") format " << string_VkFormat(image_format) |
| 3291 | << ". Images created with the VK_IMAGE_CREATE_MUTABLE_FORMAT BIT " |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3292 | << "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] | 3293 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3294 | VALIDATION_ERROR_0ac007f4, "IMAGE", "%s %s", ss.str().c_str(), |
| 3295 | validation_error_map[VALIDATION_ERROR_0ac007f4]); |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3296 | } |
| 3297 | } else { |
| 3298 | // Format MUST be IDENTICAL to the format the image was created with |
| 3299 | if (image_format != view_format) { |
| 3300 | std::stringstream ss; |
| 3301 | ss << "vkCreateImageView() format " << string_VkFormat(view_format) << " differs from image " |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 3302 | << HandleToUint64(create_info->image) << " format " << string_VkFormat(image_format) |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3303 | << ". 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] | 3304 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3305 | VALIDATION_ERROR_0ac007f6, "IMAGE", "%s %s", ss.str().c_str(), |
| 3306 | validation_error_map[VALIDATION_ERROR_0ac007f6]); |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3307 | } |
| 3308 | } |
| 3309 | |
| 3310 | // Validate correct image aspect bits for desired formats and format consistency |
| 3311 | skip |= ValidateImageAspectMask(device_data, image_state->image, image_format, aspect_mask, "vkCreateImageView()"); |
Jeremy Kniager | 846ab73 | 2017-07-10 13:12:04 -0600 | [diff] [blame] | 3312 | |
| 3313 | switch (image_type) { |
| 3314 | case VK_IMAGE_TYPE_1D: |
| 3315 | if (view_type != VK_IMAGE_VIEW_TYPE_1D && view_type != VK_IMAGE_VIEW_TYPE_1D_ARRAY) { |
| 3316 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 3317 | __LINE__, VALIDATION_ERROR_0ac007fa, "IMAGE", |
| 3318 | "vkCreateImageView(): pCreateInfo->viewType %s is not compatible with image type %s. %s", |
| 3319 | string_VkImageViewType(view_type), string_VkImageType(image_type), |
| 3320 | validation_error_map[VALIDATION_ERROR_0ac007fa]); |
| 3321 | } |
| 3322 | break; |
| 3323 | case VK_IMAGE_TYPE_2D: |
| 3324 | if (view_type != VK_IMAGE_VIEW_TYPE_2D && view_type != VK_IMAGE_VIEW_TYPE_2D_ARRAY) { |
| 3325 | if ((view_type == VK_IMAGE_VIEW_TYPE_CUBE || view_type == VK_IMAGE_VIEW_TYPE_CUBE_ARRAY) && |
| 3326 | !(image_flags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT)) { |
| 3327 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 3328 | __LINE__, VALIDATION_ERROR_0ac007d6, "IMAGE", |
| 3329 | "vkCreateImageView(): pCreateInfo->viewType %s is not compatible with image type %s. %s", |
| 3330 | string_VkImageViewType(view_type), string_VkImageType(image_type), |
| 3331 | validation_error_map[VALIDATION_ERROR_0ac007d6]); |
| 3332 | } else if (view_type != VK_IMAGE_VIEW_TYPE_CUBE && view_type != VK_IMAGE_VIEW_TYPE_CUBE_ARRAY) { |
| 3333 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 3334 | __LINE__, VALIDATION_ERROR_0ac007fa, "IMAGE", |
| 3335 | "vkCreateImageView(): pCreateInfo->viewType %s is not compatible with image type %s. %s", |
| 3336 | string_VkImageViewType(view_type), string_VkImageType(image_type), |
| 3337 | validation_error_map[VALIDATION_ERROR_0ac007fa]); |
| 3338 | } |
| 3339 | } |
| 3340 | break; |
| 3341 | case VK_IMAGE_TYPE_3D: |
| 3342 | if (GetDeviceExtensions(device_data)->vk_khr_maintenance1) { |
| 3343 | if (view_type != VK_IMAGE_VIEW_TYPE_3D) { |
| 3344 | if ((view_type == VK_IMAGE_VIEW_TYPE_2D || view_type == VK_IMAGE_VIEW_TYPE_2D_ARRAY)) { |
| 3345 | if (!(image_flags & VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT_KHR)) { |
| 3346 | skip |= log_msg( |
| 3347 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 3348 | __LINE__, VALIDATION_ERROR_0ac007da, "IMAGE", |
| 3349 | "vkCreateImageView(): pCreateInfo->viewType %s is not compatible with image type %s. %s", |
| 3350 | string_VkImageViewType(view_type), string_VkImageType(image_type), |
| 3351 | validation_error_map[VALIDATION_ERROR_0ac007da]); |
| 3352 | } else if ((image_flags & (VK_IMAGE_CREATE_SPARSE_BINDING_BIT | VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | |
| 3353 | VK_IMAGE_CREATE_SPARSE_ALIASED_BIT))) { |
| 3354 | skip |= log_msg( |
| 3355 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 3356 | __LINE__, VALIDATION_ERROR_0ac007fa, "IMAGE", |
| 3357 | "vkCreateImageView(): pCreateInfo->viewType %s is not compatible with image type %s when the " |
| 3358 | "VK_IMAGE_CREATE_SPARSE_BINDING_BIT, VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT, or " |
| 3359 | "VK_IMAGE_CREATE_SPARSE_ALIASED_BIT flags are enabled. %s", |
| 3360 | string_VkImageViewType(view_type), string_VkImageType(image_type), |
| 3361 | validation_error_map[VALIDATION_ERROR_0ac007fa]); |
| 3362 | } |
| 3363 | } else { |
| 3364 | skip |= |
| 3365 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 3366 | __LINE__, VALIDATION_ERROR_0ac007fa, "IMAGE", |
| 3367 | "vkCreateImageView(): pCreateInfo->viewType %s is not compatible with image type %s. %s", |
| 3368 | string_VkImageViewType(view_type), string_VkImageType(image_type), |
| 3369 | validation_error_map[VALIDATION_ERROR_0ac007fa]); |
| 3370 | } |
| 3371 | } |
| 3372 | } else { |
| 3373 | if (view_type != VK_IMAGE_VIEW_TYPE_3D) { |
| 3374 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 3375 | __LINE__, VALIDATION_ERROR_0ac007fa, "IMAGE", |
| 3376 | "vkCreateImageView(): pCreateInfo->viewType %s is not compatible with image type %s. %s", |
| 3377 | string_VkImageViewType(view_type), string_VkImageType(image_type), |
| 3378 | validation_error_map[VALIDATION_ERROR_0ac007fa]); |
| 3379 | } |
| 3380 | } |
| 3381 | break; |
| 3382 | default: |
| 3383 | break; |
| 3384 | } |
Jeremy Kniager | cef491c | 2017-07-18 11:10:28 -0600 | [diff] [blame] | 3385 | |
Jeremy Kniager | 7ec550f | 2017-08-16 14:57:42 -0600 | [diff] [blame^] | 3386 | VkFormatProperties format_properties = GetFormatProperties(device_data, view_format); |
Jeremy Kniager | cef491c | 2017-07-18 11:10:28 -0600 | [diff] [blame] | 3387 | bool check_tiling_features = false; |
| 3388 | VkFormatFeatureFlags tiling_features = 0; |
| 3389 | UNIQUE_VALIDATION_ERROR_CODE linear_error_codes[] = { |
| 3390 | VALIDATION_ERROR_0ac007dc, VALIDATION_ERROR_0ac007e0, VALIDATION_ERROR_0ac007e2, |
| 3391 | VALIDATION_ERROR_0ac007e4, VALIDATION_ERROR_0ac007e6, |
| 3392 | }; |
| 3393 | UNIQUE_VALIDATION_ERROR_CODE optimal_error_codes[] = { |
| 3394 | VALIDATION_ERROR_0ac007e8, VALIDATION_ERROR_0ac007ea, VALIDATION_ERROR_0ac007ec, |
| 3395 | VALIDATION_ERROR_0ac007ee, VALIDATION_ERROR_0ac007f0, |
| 3396 | }; |
| 3397 | UNIQUE_VALIDATION_ERROR_CODE *error_codes = nullptr; |
| 3398 | if (image_tiling == VK_IMAGE_TILING_LINEAR) { |
Jeremy Kniager | 7ec550f | 2017-08-16 14:57:42 -0600 | [diff] [blame^] | 3399 | tiling_features = format_properties.linearTilingFeatures; |
Jeremy Kniager | cef491c | 2017-07-18 11:10:28 -0600 | [diff] [blame] | 3400 | error_codes = linear_error_codes; |
| 3401 | check_tiling_features = true; |
| 3402 | } else if (image_tiling == VK_IMAGE_TILING_OPTIMAL) { |
Jeremy Kniager | 7ec550f | 2017-08-16 14:57:42 -0600 | [diff] [blame^] | 3403 | tiling_features = format_properties.optimalTilingFeatures; |
Jeremy Kniager | cef491c | 2017-07-18 11:10:28 -0600 | [diff] [blame] | 3404 | error_codes = optimal_error_codes; |
| 3405 | check_tiling_features = true; |
| 3406 | } |
| 3407 | |
| 3408 | if (check_tiling_features) { |
| 3409 | if (tiling_features == 0) { |
| 3410 | skip |= |
| 3411 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, |
| 3412 | error_codes[0], "IMAGE", |
| 3413 | "vkCreateImageView() pCreateInfo->format %s cannot be used with an image having the " |
| 3414 | "%s flag set. %s", |
| 3415 | string_VkFormat(view_format), string_VkImageTiling(image_tiling), validation_error_map[error_codes[0]]); |
| 3416 | } else if ((image_usage & VK_IMAGE_USAGE_SAMPLED_BIT) && !(tiling_features & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) { |
| 3417 | skip |= |
| 3418 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, |
| 3419 | error_codes[1], "IMAGE", |
| 3420 | "vkCreateImageView() pCreateInfo->format %s cannot be used with an image having the " |
| 3421 | "%s and VK_IMAGE_USAGE_SAMPLED_BIT flags set. %s", |
| 3422 | string_VkFormat(view_format), string_VkImageTiling(image_tiling), validation_error_map[error_codes[1]]); |
| 3423 | } else if ((image_usage & VK_IMAGE_USAGE_STORAGE_BIT) && !(tiling_features & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT)) { |
| 3424 | skip |= |
| 3425 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, |
| 3426 | error_codes[2], "IMAGE", |
| 3427 | "vkCreateImageView() pCreateInfo->format %s cannot be used with an image having the " |
| 3428 | "%s and VK_IMAGE_USAGE_STORAGE_BIT flags set. %s", |
| 3429 | string_VkFormat(view_format), string_VkImageTiling(image_tiling), validation_error_map[error_codes[2]]); |
| 3430 | } else if ((image_usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) && |
| 3431 | !(tiling_features & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT)) { |
| 3432 | skip |= |
| 3433 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, |
| 3434 | error_codes[3], "IMAGE", |
| 3435 | "vkCreateImageView() pCreateInfo->format %s cannot be used with an image having the " |
| 3436 | "%s and VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT flags set. %s", |
| 3437 | string_VkFormat(view_format), string_VkImageTiling(image_tiling), validation_error_map[error_codes[3]]); |
| 3438 | } else if ((image_usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) && |
| 3439 | !(tiling_features & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)) { |
| 3440 | skip |= |
| 3441 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, |
| 3442 | error_codes[4], "IMAGE", |
| 3443 | "vkCreateImageView() pCreateInfo->format %s cannot be used with an image having the " |
| 3444 | "%s and VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT flags set. %s", |
| 3445 | string_VkFormat(view_format), string_VkImageTiling(image_tiling), validation_error_map[error_codes[4]]); |
| 3446 | } |
| 3447 | } |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3448 | } |
| 3449 | return skip; |
| 3450 | } |
| 3451 | |
Mark Lobodzinski | efd933b | 2017-02-10 12:09:23 -0700 | [diff] [blame] | 3452 | void PostCallRecordCreateImageView(layer_data *device_data, const VkImageViewCreateInfo *create_info, VkImageView view) { |
| 3453 | auto image_view_map = GetImageViewMap(device_data); |
| 3454 | (*image_view_map)[view] = std::unique_ptr<IMAGE_VIEW_STATE>(new IMAGE_VIEW_STATE(view, create_info)); |
| 3455 | |
| 3456 | auto image_state = GetImageState(device_data, create_info->image); |
Dave Houlton | 4eaaf3a | 2017-03-14 11:31:20 -0600 | [diff] [blame] | 3457 | auto &sub_res_range = (*image_view_map)[view].get()->create_info.subresourceRange; |
Mark Lobodzinski | 903e5ff | 2017-03-23 09:43:35 -0600 | [diff] [blame] | 3458 | sub_res_range.levelCount = ResolveRemainingLevels(&sub_res_range, image_state->createInfo.mipLevels); |
| 3459 | sub_res_range.layerCount = ResolveRemainingLayers(&sub_res_range, image_state->createInfo.arrayLayers); |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3460 | } |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 3461 | |
Mark Lobodzinski | 680421d | 2017-02-09 13:06:56 -0700 | [diff] [blame] | 3462 | bool PreCallValidateCmdCopyBuffer(layer_data *device_data, GLOBAL_CB_NODE *cb_node, BUFFER_STATE *src_buffer_state, |
| 3463 | BUFFER_STATE *dst_buffer_state) { |
| 3464 | bool skip = false; |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3465 | skip |= ValidateMemoryIsBoundToBuffer(device_data, src_buffer_state, "vkCmdCopyBuffer()", VALIDATION_ERROR_18c000ee); |
| 3466 | skip |= ValidateMemoryIsBoundToBuffer(device_data, dst_buffer_state, "vkCmdCopyBuffer()", VALIDATION_ERROR_18c000f2); |
Mark Lobodzinski | 680421d | 2017-02-09 13:06:56 -0700 | [diff] [blame] | 3467 | // Validate that SRC & DST buffers have correct usage flags set |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3468 | skip |= ValidateBufferUsageFlags(device_data, src_buffer_state, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, true, |
| 3469 | VALIDATION_ERROR_18c000ec, "vkCmdCopyBuffer()", "VK_BUFFER_USAGE_TRANSFER_SRC_BIT"); |
| 3470 | skip |= ValidateBufferUsageFlags(device_data, dst_buffer_state, VK_BUFFER_USAGE_TRANSFER_DST_BIT, true, |
| 3471 | VALIDATION_ERROR_18c000f0, "vkCmdCopyBuffer()", "VK_BUFFER_USAGE_TRANSFER_DST_BIT"); |
Mike Schuchardt | 9c58240 | 2017-02-23 15:57:37 -0700 | [diff] [blame] | 3472 | skip |= ValidateCmdQueueFlags(device_data, cb_node, "vkCmdCopyBuffer()", |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3473 | VK_QUEUE_TRANSFER_BIT | VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT, VALIDATION_ERROR_18c02415); |
Mark Lobodzinski | 680421d | 2017-02-09 13:06:56 -0700 | [diff] [blame] | 3474 | skip |= ValidateCmd(device_data, cb_node, CMD_COPYBUFFER, "vkCmdCopyBuffer()"); |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3475 | skip |= insideRenderPass(device_data, cb_node, "vkCmdCopyBuffer()", VALIDATION_ERROR_18c00017); |
Mark Lobodzinski | 680421d | 2017-02-09 13:06:56 -0700 | [diff] [blame] | 3476 | return skip; |
| 3477 | } |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 3478 | |
Mark Lobodzinski | 680421d | 2017-02-09 13:06:56 -0700 | [diff] [blame] | 3479 | void PreCallRecordCmdCopyBuffer(layer_data *device_data, GLOBAL_CB_NODE *cb_node, BUFFER_STATE *src_buffer_state, |
| 3480 | BUFFER_STATE *dst_buffer_state) { |
| 3481 | // Update bindings between buffers and cmd buffer |
| 3482 | AddCommandBufferBindingBuffer(device_data, cb_node, src_buffer_state); |
| 3483 | AddCommandBufferBindingBuffer(device_data, cb_node, dst_buffer_state); |
| 3484 | |
| 3485 | std::function<bool()> function = [=]() { |
| 3486 | return ValidateBufferMemoryIsValid(device_data, src_buffer_state, "vkCmdCopyBuffer()"); |
| 3487 | }; |
Tobin Ehlis | a17a529 | 2017-07-28 12:11:30 -0600 | [diff] [blame] | 3488 | cb_node->queue_submit_functions.push_back(function); |
Mark Lobodzinski | 680421d | 2017-02-09 13:06:56 -0700 | [diff] [blame] | 3489 | function = [=]() { |
| 3490 | SetBufferMemoryValid(device_data, dst_buffer_state, true); |
| 3491 | return false; |
| 3492 | }; |
Tobin Ehlis | a17a529 | 2017-07-28 12:11:30 -0600 | [diff] [blame] | 3493 | cb_node->queue_submit_functions.push_back(function); |
Mark Lobodzinski | 680421d | 2017-02-09 13:06:56 -0700 | [diff] [blame] | 3494 | } |
Mark Lobodzinski | 306441e | 2017-02-10 13:48:38 -0700 | [diff] [blame] | 3495 | |
| 3496 | static bool validateIdleBuffer(layer_data *device_data, VkBuffer buffer) { |
| 3497 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 3498 | bool skip = false; |
| 3499 | auto buffer_state = GetBufferState(device_data, buffer); |
| 3500 | if (!buffer_state) { |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 3501 | 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] | 3502 | __LINE__, DRAWSTATE_DOUBLE_DESTROY, "DS", |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 3503 | "Cannot free buffer 0x%" PRIxLEAST64 " that has not been allocated.", HandleToUint64(buffer)); |
Mark Lobodzinski | 306441e | 2017-02-10 13:48:38 -0700 | [diff] [blame] | 3504 | } else { |
| 3505 | if (buffer_state->in_use.load()) { |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 3506 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3507 | HandleToUint64(buffer), __LINE__, VALIDATION_ERROR_23c00734, "DS", |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 3508 | "Cannot free buffer 0x%" PRIxLEAST64 " that is in use by a command buffer. %s", HandleToUint64(buffer), |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3509 | validation_error_map[VALIDATION_ERROR_23c00734]); |
Mark Lobodzinski | 306441e | 2017-02-10 13:48:38 -0700 | [diff] [blame] | 3510 | } |
| 3511 | } |
| 3512 | return skip; |
| 3513 | } |
| 3514 | |
| 3515 | bool PreCallValidateDestroyImageView(layer_data *device_data, VkImageView image_view, IMAGE_VIEW_STATE **image_view_state, |
| 3516 | VK_OBJECT *obj_struct) { |
| 3517 | *image_view_state = GetImageViewState(device_data, image_view); |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 3518 | *obj_struct = {HandleToUint64(image_view), kVulkanObjectTypeImageView}; |
Mark Lobodzinski | 306441e | 2017-02-10 13:48:38 -0700 | [diff] [blame] | 3519 | if (GetDisables(device_data)->destroy_image_view) return false; |
| 3520 | bool skip = false; |
| 3521 | if (*image_view_state) { |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3522 | skip |= ValidateObjectNotInUse(device_data, *image_view_state, *obj_struct, VALIDATION_ERROR_25400804); |
Mark Lobodzinski | 306441e | 2017-02-10 13:48:38 -0700 | [diff] [blame] | 3523 | } |
| 3524 | return skip; |
| 3525 | } |
| 3526 | |
| 3527 | void PostCallRecordDestroyImageView(layer_data *device_data, VkImageView image_view, IMAGE_VIEW_STATE *image_view_state, |
| 3528 | VK_OBJECT obj_struct) { |
| 3529 | // Any bound cmd buffers are now invalid |
| 3530 | invalidateCommandBuffers(device_data, image_view_state->cb_bindings, obj_struct); |
| 3531 | (*GetImageViewMap(device_data)).erase(image_view); |
| 3532 | } |
| 3533 | |
| 3534 | bool PreCallValidateDestroyBuffer(layer_data *device_data, VkBuffer buffer, BUFFER_STATE **buffer_state, VK_OBJECT *obj_struct) { |
| 3535 | *buffer_state = GetBufferState(device_data, buffer); |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 3536 | *obj_struct = {HandleToUint64(buffer), kVulkanObjectTypeBuffer}; |
Mark Lobodzinski | 306441e | 2017-02-10 13:48:38 -0700 | [diff] [blame] | 3537 | if (GetDisables(device_data)->destroy_buffer) return false; |
| 3538 | bool skip = false; |
| 3539 | if (*buffer_state) { |
| 3540 | skip |= validateIdleBuffer(device_data, buffer); |
| 3541 | } |
| 3542 | return skip; |
| 3543 | } |
| 3544 | |
| 3545 | void PostCallRecordDestroyBuffer(layer_data *device_data, VkBuffer buffer, BUFFER_STATE *buffer_state, VK_OBJECT obj_struct) { |
| 3546 | invalidateCommandBuffers(device_data, buffer_state->cb_bindings, obj_struct); |
| 3547 | for (auto mem_binding : buffer_state->GetBoundMemory()) { |
| 3548 | auto mem_info = GetMemObjInfo(device_data, mem_binding); |
| 3549 | if (mem_info) { |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 3550 | core_validation::RemoveBufferMemoryRange(HandleToUint64(buffer), mem_info); |
Mark Lobodzinski | 306441e | 2017-02-10 13:48:38 -0700 | [diff] [blame] | 3551 | } |
| 3552 | } |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 3553 | ClearMemoryObjectBindings(device_data, HandleToUint64(buffer), kVulkanObjectTypeBuffer); |
Mark Lobodzinski | 306441e | 2017-02-10 13:48:38 -0700 | [diff] [blame] | 3554 | GetBufferMap(device_data)->erase(buffer_state->buffer); |
| 3555 | } |
| 3556 | |
| 3557 | bool PreCallValidateDestroyBufferView(layer_data *device_data, VkBufferView buffer_view, BUFFER_VIEW_STATE **buffer_view_state, |
| 3558 | VK_OBJECT *obj_struct) { |
| 3559 | *buffer_view_state = GetBufferViewState(device_data, buffer_view); |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 3560 | *obj_struct = {HandleToUint64(buffer_view), kVulkanObjectTypeBufferView}; |
Mark Lobodzinski | 306441e | 2017-02-10 13:48:38 -0700 | [diff] [blame] | 3561 | if (GetDisables(device_data)->destroy_buffer_view) return false; |
| 3562 | bool skip = false; |
| 3563 | if (*buffer_view_state) { |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3564 | skip |= ValidateObjectNotInUse(device_data, *buffer_view_state, *obj_struct, VALIDATION_ERROR_23e00750); |
Mark Lobodzinski | 306441e | 2017-02-10 13:48:38 -0700 | [diff] [blame] | 3565 | } |
| 3566 | return skip; |
| 3567 | } |
| 3568 | |
| 3569 | void PostCallRecordDestroyBufferView(layer_data *device_data, VkBufferView buffer_view, BUFFER_VIEW_STATE *buffer_view_state, |
| 3570 | VK_OBJECT obj_struct) { |
| 3571 | // Any bound cmd buffers are now invalid |
| 3572 | invalidateCommandBuffers(device_data, buffer_view_state->cb_bindings, obj_struct); |
| 3573 | GetBufferViewMap(device_data)->erase(buffer_view); |
| 3574 | } |
Mark Lobodzinski | df0acbf | 2017-02-10 14:01:27 -0700 | [diff] [blame] | 3575 | |
| 3576 | bool PreCallValidateCmdFillBuffer(layer_data *device_data, GLOBAL_CB_NODE *cb_node, BUFFER_STATE *buffer_state) { |
| 3577 | bool skip = false; |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3578 | skip |= ValidateMemoryIsBoundToBuffer(device_data, buffer_state, "vkCmdFillBuffer()", VALIDATION_ERROR_1b40003e); |
Mike Schuchardt | 9c58240 | 2017-02-23 15:57:37 -0700 | [diff] [blame] | 3579 | skip |= ValidateCmdQueueFlags(device_data, cb_node, "vkCmdFillBuffer()", |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3580 | VK_QUEUE_TRANSFER_BIT | VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT, VALIDATION_ERROR_1b402415); |
Mark Lobodzinski | df0acbf | 2017-02-10 14:01:27 -0700 | [diff] [blame] | 3581 | skip |= ValidateCmd(device_data, cb_node, CMD_FILLBUFFER, "vkCmdFillBuffer()"); |
| 3582 | // Validate that DST buffer has correct usage flags set |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3583 | skip |= ValidateBufferUsageFlags(device_data, buffer_state, VK_BUFFER_USAGE_TRANSFER_DST_BIT, true, VALIDATION_ERROR_1b40003a, |
Mark Lobodzinski | df0acbf | 2017-02-10 14:01:27 -0700 | [diff] [blame] | 3584 | "vkCmdFillBuffer()", "VK_BUFFER_USAGE_TRANSFER_DST_BIT"); |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3585 | skip |= insideRenderPass(device_data, cb_node, "vkCmdFillBuffer()", VALIDATION_ERROR_1b400017); |
Mark Lobodzinski | df0acbf | 2017-02-10 14:01:27 -0700 | [diff] [blame] | 3586 | return skip; |
| 3587 | } |
| 3588 | |
| 3589 | void PreCallRecordCmdFillBuffer(layer_data *device_data, GLOBAL_CB_NODE *cb_node, BUFFER_STATE *buffer_state) { |
| 3590 | std::function<bool()> function = [=]() { |
| 3591 | SetBufferMemoryValid(device_data, buffer_state, true); |
| 3592 | return false; |
| 3593 | }; |
Tobin Ehlis | a17a529 | 2017-07-28 12:11:30 -0600 | [diff] [blame] | 3594 | cb_node->queue_submit_functions.push_back(function); |
Mark Lobodzinski | df0acbf | 2017-02-10 14:01:27 -0700 | [diff] [blame] | 3595 | // Update bindings between buffer and cmd buffer |
| 3596 | AddCommandBufferBindingBuffer(device_data, cb_node, buffer_state); |
Mark Lobodzinski | df0acbf | 2017-02-10 14:01:27 -0700 | [diff] [blame] | 3597 | } |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 3598 | |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 3599 | bool ValidateBufferImageCopyData(const debug_report_data *report_data, uint32_t regionCount, const VkBufferImageCopy *pRegions, |
| 3600 | IMAGE_STATE *image_state, const char *function) { |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 3601 | bool skip = false; |
| 3602 | |
| 3603 | for (uint32_t i = 0; i < regionCount; i++) { |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3604 | if (image_state->createInfo.imageType == VK_IMAGE_TYPE_1D) { |
| 3605 | if ((pRegions[i].imageOffset.y != 0) || (pRegions[i].imageExtent.height != 1)) { |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 3606 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3607 | HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_0160018e, "IMAGE", |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3608 | "%s(): pRegion[%d] imageOffset.y is %d and imageExtent.height is %d. For 1D images these " |
| 3609 | "must be 0 and 1, respectively. %s", |
| 3610 | function, i, pRegions[i].imageOffset.y, pRegions[i].imageExtent.height, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3611 | validation_error_map[VALIDATION_ERROR_0160018e]); |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 3612 | } |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3613 | } |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 3614 | |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3615 | if ((image_state->createInfo.imageType == VK_IMAGE_TYPE_1D) || (image_state->createInfo.imageType == VK_IMAGE_TYPE_2D)) { |
| 3616 | if ((pRegions[i].imageOffset.z != 0) || (pRegions[i].imageExtent.depth != 1)) { |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 3617 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3618 | HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_01600192, "IMAGE", |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3619 | "%s(): pRegion[%d] imageOffset.z is %d and imageExtent.depth is %d. For 1D and 2D images these " |
| 3620 | "must be 0 and 1, respectively. %s", |
| 3621 | function, i, pRegions[i].imageOffset.z, pRegions[i].imageExtent.depth, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3622 | validation_error_map[VALIDATION_ERROR_01600192]); |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 3623 | } |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3624 | } |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 3625 | |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3626 | if (image_state->createInfo.imageType == VK_IMAGE_TYPE_3D) { |
| 3627 | if ((0 != pRegions[i].imageSubresource.baseArrayLayer) || (1 != pRegions[i].imageSubresource.layerCount)) { |
| 3628 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3629 | HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_016001aa, "IMAGE", |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3630 | "%s(): pRegion[%d] imageSubresource.baseArrayLayer is %d and imageSubresource.layerCount is " |
| 3631 | "%d. For 3D images these must be 0 and 1, respectively. %s", |
| 3632 | function, i, pRegions[i].imageSubresource.baseArrayLayer, pRegions[i].imageSubresource.layerCount, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3633 | validation_error_map[VALIDATION_ERROR_016001aa]); |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3634 | } |
| 3635 | } |
| 3636 | |
| 3637 | // If the the calling command's VkImage parameter's format is not a depth/stencil format, |
| 3638 | // 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] | 3639 | auto texel_size = FormatSize(image_state->createInfo.format); |
Dave Houlton | 1150cf5 | 2017-04-27 14:38:11 -0600 | [diff] [blame] | 3640 | 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] | 3641 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3642 | HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_01600182, "IMAGE", |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3643 | "%s(): pRegion[%d] bufferOffset 0x%" PRIxLEAST64 |
| 3644 | " must be a multiple of this format's texel size (" PRINTF_SIZE_T_SPECIFIER "). %s", |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3645 | function, i, pRegions[i].bufferOffset, texel_size, validation_error_map[VALIDATION_ERROR_01600182]); |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3646 | } |
| 3647 | |
| 3648 | // BufferOffset must be a multiple of 4 |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 3649 | if (SafeModulo(pRegions[i].bufferOffset, 4) != 0) { |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3650 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3651 | HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_01600184, "IMAGE", |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3652 | "%s(): pRegion[%d] bufferOffset 0x%" PRIxLEAST64 " must be a multiple of 4. %s", function, i, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3653 | pRegions[i].bufferOffset, validation_error_map[VALIDATION_ERROR_01600184]); |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3654 | } |
| 3655 | |
| 3656 | // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent |
| 3657 | if ((pRegions[i].bufferRowLength != 0) && (pRegions[i].bufferRowLength < pRegions[i].imageExtent.width)) { |
| 3658 | skip |= log_msg( |
| 3659 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3660 | HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_01600186, "IMAGE", |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3661 | "%s(): pRegion[%d] bufferRowLength (%d) must be zero or greater-than-or-equal-to imageExtent.width (%d). %s", |
| 3662 | function, i, pRegions[i].bufferRowLength, pRegions[i].imageExtent.width, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3663 | validation_error_map[VALIDATION_ERROR_01600186]); |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3664 | } |
| 3665 | |
| 3666 | // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent |
| 3667 | if ((pRegions[i].bufferImageHeight != 0) && (pRegions[i].bufferImageHeight < pRegions[i].imageExtent.height)) { |
| 3668 | skip |= log_msg( |
| 3669 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3670 | HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_01600188, "IMAGE", |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3671 | "%s(): pRegion[%d] bufferImageHeight (%d) must be zero or greater-than-or-equal-to imageExtent.height (%d). %s", |
| 3672 | function, i, pRegions[i].bufferImageHeight, pRegions[i].imageExtent.height, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3673 | validation_error_map[VALIDATION_ERROR_01600188]); |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3674 | } |
| 3675 | |
| 3676 | // subresource aspectMask must have exactly 1 bit set |
| 3677 | const int num_bits = sizeof(VkFlags) * CHAR_BIT; |
| 3678 | std::bitset<num_bits> aspect_mask_bits(pRegions[i].imageSubresource.aspectMask); |
| 3679 | if (aspect_mask_bits.count() != 1) { |
| 3680 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3681 | HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_016001a8, "IMAGE", |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3682 | "%s: aspectMasks for imageSubresource in each region must have only a single bit set. %s", function, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3683 | validation_error_map[VALIDATION_ERROR_016001a8]); |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3684 | } |
| 3685 | |
| 3686 | // image subresource aspect bit must match format |
Dave Houlton | 4eaaf3a | 2017-03-14 11:31:20 -0600 | [diff] [blame] | 3687 | if (!VerifyAspectsPresent(pRegions[i].imageSubresource.aspectMask, image_state->createInfo.format)) { |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3688 | skip |= log_msg( |
| 3689 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3690 | HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_016001a6, "IMAGE", |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3691 | "%s(): pRegion[%d] subresource aspectMask 0x%x specifies aspects that are not present in image format 0x%x. %s", |
| 3692 | function, i, pRegions[i].imageSubresource.aspectMask, image_state->createInfo.format, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3693 | validation_error_map[VALIDATION_ERROR_016001a6]); |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3694 | } |
| 3695 | |
| 3696 | // Checks that apply only to compressed images |
| 3697 | // TODO: there is a comment in ValidateCopyBufferImageTransferGranularityRequirements() in core_validation.cpp that |
| 3698 | // reserves a place for these compressed image checks. This block of code could move there once the image |
| 3699 | // stuff is moved into core validation. |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 3700 | if (FormatIsCompressed(image_state->createInfo.format)) { |
| 3701 | auto block_size = FormatCompressedTexelBlockExtent(image_state->createInfo.format); |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3702 | |
| 3703 | // BufferRowLength must be a multiple of block width |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 3704 | if (SafeModulo(pRegions[i].bufferRowLength, block_size.width) != 0) { |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 3705 | skip |= log_msg( |
| 3706 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3707 | HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_01600196, "IMAGE", |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3708 | "%s(): pRegion[%d] bufferRowLength (%d) must be a multiple of the compressed image's texel width (%d). %s.", |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3709 | function, i, pRegions[i].bufferRowLength, block_size.width, validation_error_map[VALIDATION_ERROR_01600196]); |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 3710 | } |
| 3711 | |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3712 | // BufferRowHeight must be a multiple of block height |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 3713 | if (SafeModulo(pRegions[i].bufferImageHeight, block_size.height) != 0) { |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 3714 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3715 | HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_01600198, "IMAGE", |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3716 | "%s(): pRegion[%d] bufferImageHeight (%d) must be a multiple of the compressed image's texel " |
| 3717 | "height (%d). %s.", |
| 3718 | function, i, pRegions[i].bufferImageHeight, block_size.height, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3719 | validation_error_map[VALIDATION_ERROR_01600198]); |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 3720 | } |
| 3721 | |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3722 | // image offsets must be multiples of block dimensions |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 3723 | if ((SafeModulo(pRegions[i].imageOffset.x, block_size.width) != 0) || |
| 3724 | (SafeModulo(pRegions[i].imageOffset.y, block_size.height) != 0) || |
| 3725 | (SafeModulo(pRegions[i].imageOffset.z, block_size.depth) != 0)) { |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3726 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3727 | HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_0160019a, "IMAGE", |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3728 | "%s(): pRegion[%d] imageOffset(x,y) (%d, %d) must be multiples of the compressed image's texel " |
| 3729 | "width & height (%d, %d). %s.", |
| 3730 | function, i, pRegions[i].imageOffset.x, pRegions[i].imageOffset.y, block_size.width, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3731 | block_size.height, validation_error_map[VALIDATION_ERROR_0160019a]); |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 3732 | } |
| 3733 | |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3734 | // bufferOffset must be a multiple of block size (linear bytes) |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 3735 | size_t block_size_in_bytes = FormatSize(image_state->createInfo.format); |
| 3736 | if (SafeModulo(pRegions[i].bufferOffset, block_size_in_bytes) != 0) { |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3737 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3738 | HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_0160019c, "IMAGE", |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3739 | "%s(): pRegion[%d] bufferOffset (0x%" PRIxLEAST64 |
| 3740 | ") must be a multiple of the compressed image's texel block " |
| 3741 | "size (" PRINTF_SIZE_T_SPECIFIER "). %s.", |
| 3742 | function, i, pRegions[i].bufferOffset, block_size_in_bytes, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3743 | validation_error_map[VALIDATION_ERROR_0160019c]); |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 3744 | } |
Dave Houlton | 67e9b53 | 2017-03-02 17:00:10 -0700 | [diff] [blame] | 3745 | |
| 3746 | // 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] | 3747 | VkExtent3D mip_extent = GetImageSubresourceExtent(image_state, &(pRegions[i].imageSubresource)); |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 3748 | if ((SafeModulo(pRegions[i].imageExtent.width, block_size.width) != 0) && |
Dave Houlton | 75967fc | 2017-03-06 17:21:16 -0700 | [diff] [blame] | 3749 | (pRegions[i].imageExtent.width + pRegions[i].imageOffset.x != mip_extent.width)) { |
| 3750 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3751 | HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_0160019e, "IMAGE", |
Dave Houlton | 75967fc | 2017-03-06 17:21:16 -0700 | [diff] [blame] | 3752 | "%s(): pRegion[%d] extent width (%d) must be a multiple of the compressed texture block width " |
| 3753 | "(%d), or when added to offset.x (%d) must equal the image subresource width (%d). %s.", |
| 3754 | function, i, pRegions[i].imageExtent.width, block_size.width, pRegions[i].imageOffset.x, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3755 | mip_extent.width, validation_error_map[VALIDATION_ERROR_0160019e]); |
Dave Houlton | 67e9b53 | 2017-03-02 17:00:10 -0700 | [diff] [blame] | 3756 | } |
| 3757 | |
| 3758 | // 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] | 3759 | if ((SafeModulo(pRegions[i].imageExtent.height, block_size.height) != 0) && |
Dave Houlton | 75967fc | 2017-03-06 17:21:16 -0700 | [diff] [blame] | 3760 | (pRegions[i].imageExtent.height + pRegions[i].imageOffset.y != mip_extent.height)) { |
| 3761 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3762 | HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_016001a0, "IMAGE", |
Dave Houlton | 75967fc | 2017-03-06 17:21:16 -0700 | [diff] [blame] | 3763 | "%s(): pRegion[%d] extent height (%d) must be a multiple of the compressed texture block height " |
| 3764 | "(%d), or when added to offset.y (%d) must equal the image subresource height (%d). %s.", |
| 3765 | function, i, pRegions[i].imageExtent.height, block_size.height, pRegions[i].imageOffset.y, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3766 | mip_extent.height, validation_error_map[VALIDATION_ERROR_016001a0]); |
Dave Houlton | 67e9b53 | 2017-03-02 17:00:10 -0700 | [diff] [blame] | 3767 | } |
| 3768 | |
| 3769 | // 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] | 3770 | if ((SafeModulo(pRegions[i].imageExtent.depth, block_size.depth) != 0) && |
Dave Houlton | 75967fc | 2017-03-06 17:21:16 -0700 | [diff] [blame] | 3771 | (pRegions[i].imageExtent.depth + pRegions[i].imageOffset.z != mip_extent.depth)) { |
| 3772 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3773 | HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_016001a2, "IMAGE", |
Dave Houlton | 75967fc | 2017-03-06 17:21:16 -0700 | [diff] [blame] | 3774 | "%s(): pRegion[%d] extent width (%d) must be a multiple of the compressed texture block depth " |
| 3775 | "(%d), or when added to offset.z (%d) must equal the image subresource depth (%d). %s.", |
| 3776 | function, i, pRegions[i].imageExtent.depth, block_size.depth, pRegions[i].imageOffset.z, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3777 | mip_extent.depth, validation_error_map[VALIDATION_ERROR_016001a2]); |
Dave Houlton | 67e9b53 | 2017-03-02 17:00:10 -0700 | [diff] [blame] | 3778 | } |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3779 | } |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 3780 | } |
| 3781 | |
| 3782 | return skip; |
| 3783 | } |
| 3784 | |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3785 | static bool ValidateImageBounds(const debug_report_data *report_data, const IMAGE_STATE *image_state, const uint32_t regionCount, |
| 3786 | 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] | 3787 | bool skip = false; |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3788 | const VkImageCreateInfo *image_info = &(image_state->createInfo); |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 3789 | |
| 3790 | for (uint32_t i = 0; i < regionCount; i++) { |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 3791 | VkExtent3D extent = pRegions[i].imageExtent; |
| 3792 | VkOffset3D offset = pRegions[i].imageOffset; |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 3793 | |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3794 | if (IsExtentSizeZero(&extent)) // Warn on zero area subresource |
| 3795 | { |
| 3796 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 3797 | (uint64_t)0, __LINE__, IMAGE_ZERO_AREA_SUBREGION, "IMAGE", |
| 3798 | "%s: pRegion[%d] imageExtent of {%1d, %1d, %1d} has zero area", func_name, i, extent.width, |
| 3799 | extent.height, extent.depth); |
| 3800 | } |
| 3801 | |
| 3802 | VkExtent3D image_extent = GetImageSubresourceExtent(image_state, &(pRegions[i].imageSubresource)); |
| 3803 | |
| 3804 | // 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] | 3805 | if (FormatIsCompressed(image_info->format)) { |
| 3806 | auto block_extent = FormatCompressedTexelBlockExtent(image_info->format); |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3807 | if (image_extent.width % block_extent.width) { |
| 3808 | image_extent.width += (block_extent.width - (image_extent.width % block_extent.width)); |
| 3809 | } |
| 3810 | if (image_extent.height % block_extent.height) { |
| 3811 | image_extent.height += (block_extent.height - (image_extent.height % block_extent.height)); |
| 3812 | } |
| 3813 | if (image_extent.depth % block_extent.depth) { |
| 3814 | image_extent.depth += (block_extent.depth - (image_extent.depth % block_extent.depth)); |
| 3815 | } |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 3816 | } |
| 3817 | |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 3818 | if (0 != ExceedsBounds(&offset, &extent, &image_extent)) { |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 3819 | 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] | 3820 | __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] | 3821 | validation_error_map[msg_code]); |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 3822 | } |
| 3823 | } |
| 3824 | |
| 3825 | return skip; |
| 3826 | } |
| 3827 | |
Chris Forbes | e8ba09a | 2017-06-01 17:39:02 -0700 | [diff] [blame] | 3828 | static inline bool ValidateBufferBounds(const debug_report_data *report_data, IMAGE_STATE *image_state, BUFFER_STATE *buff_state, |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 3829 | uint32_t regionCount, const VkBufferImageCopy *pRegions, const char *func_name, |
| 3830 | UNIQUE_VALIDATION_ERROR_CODE msg_code) { |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 3831 | bool skip = false; |
| 3832 | |
| 3833 | VkDeviceSize buffer_size = buff_state->createInfo.size; |
| 3834 | |
| 3835 | for (uint32_t i = 0; i < regionCount; i++) { |
| 3836 | VkExtent3D copy_extent = pRegions[i].imageExtent; |
| 3837 | |
| 3838 | VkDeviceSize buffer_width = (0 == pRegions[i].bufferRowLength ? copy_extent.width : pRegions[i].bufferRowLength); |
| 3839 | 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] | 3840 | 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] | 3841 | |
Dave Houlton | f3229d5 | 2017-02-21 15:59:08 -0700 | [diff] [blame] | 3842 | // Handle special buffer packing rules for specific depth/stencil formats |
| 3843 | if (pRegions[i].imageSubresource.aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) { |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 3844 | unit_size = FormatSize(VK_FORMAT_S8_UINT); |
Dave Houlton | f3229d5 | 2017-02-21 15:59:08 -0700 | [diff] [blame] | 3845 | } else if (pRegions[i].imageSubresource.aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) { |
| 3846 | switch (image_state->createInfo.format) { |
| 3847 | case VK_FORMAT_D16_UNORM_S8_UINT: |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 3848 | unit_size = FormatSize(VK_FORMAT_D16_UNORM); |
Dave Houlton | f3229d5 | 2017-02-21 15:59:08 -0700 | [diff] [blame] | 3849 | break; |
| 3850 | case VK_FORMAT_D32_SFLOAT_S8_UINT: |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 3851 | unit_size = FormatSize(VK_FORMAT_D32_SFLOAT); |
Dave Houlton | f3229d5 | 2017-02-21 15:59:08 -0700 | [diff] [blame] | 3852 | break; |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3853 | case VK_FORMAT_X8_D24_UNORM_PACK32: // Fall through |
Dave Houlton | f3229d5 | 2017-02-21 15:59:08 -0700 | [diff] [blame] | 3854 | case VK_FORMAT_D24_UNORM_S8_UINT: |
| 3855 | unit_size = 4; |
| 3856 | break; |
| 3857 | default: |
| 3858 | break; |
| 3859 | } |
| 3860 | } |
| 3861 | |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 3862 | if (FormatIsCompressed(image_state->createInfo.format)) { |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3863 | // Switch to texel block units, rounding up for any partially-used blocks |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 3864 | auto block_dim = FormatCompressedTexelBlockExtent(image_state->createInfo.format); |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3865 | buffer_width = (buffer_width + block_dim.width - 1) / block_dim.width; |
| 3866 | buffer_height = (buffer_height + block_dim.height - 1) / block_dim.height; |
| 3867 | |
| 3868 | copy_extent.width = (copy_extent.width + block_dim.width - 1) / block_dim.width; |
| 3869 | copy_extent.height = (copy_extent.height + block_dim.height - 1) / block_dim.height; |
| 3870 | 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] | 3871 | } |
| 3872 | |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3873 | // Either depth or layerCount may be greater than 1 (not both). This is the number of 'slices' to copy |
| 3874 | uint32_t z_copies = std::max(copy_extent.depth, pRegions[i].imageSubresource.layerCount); |
| 3875 | if (IsExtentSizeZero(©_extent) || (0 == z_copies)) { |
Chris Forbes | e8ba09a | 2017-06-01 17:39:02 -0700 | [diff] [blame] | 3876 | // TODO: Issue warning here? Already warned in ValidateImageBounds()... |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3877 | } else { |
| 3878 | // Calculate buffer offset of final copied byte, + 1. |
| 3879 | VkDeviceSize max_buffer_offset = (z_copies - 1) * buffer_height * buffer_width; // offset to slice |
| 3880 | max_buffer_offset += ((copy_extent.height - 1) * buffer_width) + copy_extent.width; // add row,col |
| 3881 | max_buffer_offset *= unit_size; // convert to bytes |
| 3882 | max_buffer_offset += pRegions[i].bufferOffset; // add initial offset (bytes) |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 3883 | |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3884 | if (buffer_size < max_buffer_offset) { |
| 3885 | skip |= |
| 3886 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)0, |
| 3887 | __LINE__, msg_code, "IMAGE", "%s: pRegion[%d] exceeds buffer size of %" PRIu64 " bytes. %s.", func_name, |
| 3888 | i, buffer_size, validation_error_map[msg_code]); |
| 3889 | } |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 3890 | } |
| 3891 | } |
| 3892 | |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 3893 | return skip; |
| 3894 | } |
| 3895 | |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 3896 | 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] | 3897 | 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] | 3898 | const VkBufferImageCopy *pRegions, const char *func_name) { |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 3899 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 3900 | bool skip = ValidateBufferImageCopyData(report_data, regionCount, pRegions, src_image_state, "vkCmdCopyImageToBuffer"); |
| 3901 | |
| 3902 | // Validate command buffer state |
| 3903 | if (CB_RECORDING != cb_node->state) { |
| 3904 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3905 | HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_19202413, "DS", |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 3906 | "Cannot call vkCmdCopyImageToBuffer() on command buffer which is not in recording state. %s.", |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3907 | validation_error_map[VALIDATION_ERROR_19202413]); |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 3908 | } else { |
| 3909 | skip |= ValidateCmdSubpassState(device_data, cb_node, CMD_COPYIMAGETOBUFFER); |
| 3910 | } |
| 3911 | |
| 3912 | // Command pool must support graphics, compute, or transfer operations |
| 3913 | auto pPool = GetCommandPoolNode(device_data, cb_node->createInfo.commandPool); |
| 3914 | |
| 3915 | VkQueueFlags queue_flags = GetPhysDevProperties(device_data)->queue_family_properties[pPool->queueFamilyIndex].queueFlags; |
| 3916 | if (0 == (queue_flags & (VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT | VK_QUEUE_TRANSFER_BIT))) { |
| 3917 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3918 | HandleToUint64(cb_node->createInfo.commandPool), __LINE__, VALIDATION_ERROR_19202415, "DS", |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 3919 | "Cannot call vkCmdCopyImageToBuffer() on a command buffer allocated from a pool without graphics, compute, " |
| 3920 | "or transfer capabilities. %s.", |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3921 | validation_error_map[VALIDATION_ERROR_19202415]); |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 3922 | } |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3923 | skip |= ValidateImageBounds(report_data, src_image_state, regionCount, pRegions, "vkCmdCopyBufferToImage()", |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3924 | VALIDATION_ERROR_1920016c); |
Chris Forbes | e8ba09a | 2017-06-01 17:39:02 -0700 | [diff] [blame] | 3925 | skip |= ValidateBufferBounds(report_data, src_image_state, dst_buffer_state, regionCount, pRegions, "vkCmdCopyImageToBuffer()", |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 3926 | VALIDATION_ERROR_1920016e); |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 3927 | |
| 3928 | skip |= ValidateImageSampleCount(device_data, src_image_state, VK_SAMPLE_COUNT_1_BIT, "vkCmdCopyImageToBuffer(): srcImage", |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3929 | VALIDATION_ERROR_19200178); |
| 3930 | skip |= ValidateMemoryIsBoundToImage(device_data, src_image_state, "vkCmdCopyImageToBuffer()", VALIDATION_ERROR_19200176); |
| 3931 | skip |= ValidateMemoryIsBoundToBuffer(device_data, dst_buffer_state, "vkCmdCopyImageToBuffer()", VALIDATION_ERROR_19200180); |
Mark Lobodzinski | 033c90b | 2017-02-15 13:58:23 -0700 | [diff] [blame] | 3932 | |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 3933 | // Validate that SRC image & DST buffer have correct usage flags set |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3934 | skip |= ValidateImageUsageFlags(device_data, src_image_state, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, true, VALIDATION_ERROR_19200174, |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 3935 | "vkCmdCopyImageToBuffer()", "VK_IMAGE_USAGE_TRANSFER_SRC_BIT"); |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3936 | skip |= ValidateBufferUsageFlags(device_data, dst_buffer_state, VK_BUFFER_USAGE_TRANSFER_DST_BIT, true, |
| 3937 | VALIDATION_ERROR_1920017e, "vkCmdCopyImageToBuffer()", "VK_BUFFER_USAGE_TRANSFER_DST_BIT"); |
| 3938 | skip |= insideRenderPass(device_data, cb_node, "vkCmdCopyImageToBuffer()", VALIDATION_ERROR_19200017); |
Tobin Ehlis | c826645 | 2017-04-07 12:20:30 -0600 | [diff] [blame] | 3939 | bool hit_error = false; |
Mark Lobodzinski | 033c90b | 2017-02-15 13:58:23 -0700 | [diff] [blame] | 3940 | for (uint32_t i = 0; i < regionCount; ++i) { |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3941 | skip |= VerifyImageLayout(device_data, cb_node, src_image_state, pRegions[i].imageSubresource, srcImageLayout, |
| 3942 | VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, "vkCmdCopyImageToBuffer()", VALIDATION_ERROR_1920017c, |
| 3943 | &hit_error); |
Mark Lobodzinski | 033c90b | 2017-02-15 13:58:23 -0700 | [diff] [blame] | 3944 | skip |= ValidateCopyBufferImageTransferGranularityRequirements(device_data, cb_node, src_image_state, &pRegions[i], i, |
Tobin Ehlis | 2d85ec6 | 2017-03-14 15:38:48 -0600 | [diff] [blame] | 3945 | "vkCmdCopyImageToBuffer()"); |
Mark Lobodzinski | 033c90b | 2017-02-15 13:58:23 -0700 | [diff] [blame] | 3946 | } |
| 3947 | return skip; |
| 3948 | } |
| 3949 | |
| 3950 | 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] | 3951 | BUFFER_STATE *dst_buffer_state, uint32_t region_count, const VkBufferImageCopy *regions, |
| 3952 | VkImageLayout src_image_layout) { |
| 3953 | // Make sure that all image slices are updated to correct layout |
| 3954 | for (uint32_t i = 0; i < region_count; ++i) { |
| 3955 | SetImageLayout(device_data, cb_node, src_image_state, regions[i].imageSubresource, src_image_layout); |
| 3956 | } |
Mark Lobodzinski | 033c90b | 2017-02-15 13:58:23 -0700 | [diff] [blame] | 3957 | // Update bindings between buffer/image and cmd buffer |
| 3958 | AddCommandBufferBindingImage(device_data, cb_node, src_image_state); |
Mark Lobodzinski | 1fe9b00 | 2017-02-15 14:11:12 -0700 | [diff] [blame] | 3959 | AddCommandBufferBindingBuffer(device_data, cb_node, dst_buffer_state); |
Mark Lobodzinski | 033c90b | 2017-02-15 13:58:23 -0700 | [diff] [blame] | 3960 | |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 3961 | std::function<bool()> function = [=]() { |
| 3962 | return ValidateImageMemoryIsValid(device_data, src_image_state, "vkCmdCopyImageToBuffer()"); |
| 3963 | }; |
Tobin Ehlis | a17a529 | 2017-07-28 12:11:30 -0600 | [diff] [blame] | 3964 | cb_node->queue_submit_functions.push_back(function); |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 3965 | function = [=]() { |
Mark Lobodzinski | 1fe9b00 | 2017-02-15 14:11:12 -0700 | [diff] [blame] | 3966 | SetBufferMemoryValid(device_data, dst_buffer_state, true); |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 3967 | return false; |
| 3968 | }; |
Tobin Ehlis | a17a529 | 2017-07-28 12:11:30 -0600 | [diff] [blame] | 3969 | cb_node->queue_submit_functions.push_back(function); |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 3970 | } |
| 3971 | |
| 3972 | 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] | 3973 | 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] | 3974 | const VkBufferImageCopy *pRegions, const char *func_name) { |
| 3975 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 3976 | bool skip = ValidateBufferImageCopyData(report_data, regionCount, pRegions, dst_image_state, "vkCmdCopyBufferToImage"); |
| 3977 | |
| 3978 | // Validate command buffer state |
| 3979 | if (CB_RECORDING != cb_node->state) { |
| 3980 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3981 | HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_18e02413, "DS", |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 3982 | "Cannot call vkCmdCopyBufferToImage() on command buffer which is not in recording state. %s.", |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3983 | validation_error_map[VALIDATION_ERROR_18e02413]); |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 3984 | } else { |
| 3985 | skip |= ValidateCmdSubpassState(device_data, cb_node, CMD_COPYBUFFERTOIMAGE); |
| 3986 | } |
| 3987 | |
| 3988 | // Command pool must support graphics, compute, or transfer operations |
| 3989 | auto pPool = GetCommandPoolNode(device_data, cb_node->createInfo.commandPool); |
| 3990 | VkQueueFlags queue_flags = GetPhysDevProperties(device_data)->queue_family_properties[pPool->queueFamilyIndex].queueFlags; |
| 3991 | if (0 == (queue_flags & (VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT | VK_QUEUE_TRANSFER_BIT))) { |
| 3992 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3993 | HandleToUint64(cb_node->createInfo.commandPool), __LINE__, VALIDATION_ERROR_18e02415, "DS", |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 3994 | "Cannot call vkCmdCopyBufferToImage() on a command buffer allocated from a pool without graphics, compute, " |
| 3995 | "or transfer capabilities. %s.", |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3996 | validation_error_map[VALIDATION_ERROR_18e02415]); |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 3997 | } |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3998 | skip |= ValidateImageBounds(report_data, dst_image_state, regionCount, pRegions, "vkCmdCopyBufferToImage()", |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3999 | VALIDATION_ERROR_18e00158); |
Chris Forbes | e8ba09a | 2017-06-01 17:39:02 -0700 | [diff] [blame] | 4000 | skip |= ValidateBufferBounds(report_data, dst_image_state, src_buffer_state, regionCount, pRegions, "vkCmdCopyBufferToImage()", |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 4001 | VALIDATION_ERROR_18e00156); |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 4002 | skip |= ValidateImageSampleCount(device_data, dst_image_state, VK_SAMPLE_COUNT_1_BIT, "vkCmdCopyBufferToImage(): dstImage", |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 4003 | VALIDATION_ERROR_18e00166); |
| 4004 | skip |= ValidateMemoryIsBoundToBuffer(device_data, src_buffer_state, "vkCmdCopyBufferToImage()", VALIDATION_ERROR_18e00160); |
| 4005 | skip |= ValidateMemoryIsBoundToImage(device_data, dst_image_state, "vkCmdCopyBufferToImage()", VALIDATION_ERROR_18e00164); |
| 4006 | skip |= ValidateBufferUsageFlags(device_data, src_buffer_state, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, true, |
| 4007 | VALIDATION_ERROR_18e0015c, "vkCmdCopyBufferToImage()", "VK_BUFFER_USAGE_TRANSFER_SRC_BIT"); |
| 4008 | skip |= ValidateImageUsageFlags(device_data, dst_image_state, VK_IMAGE_USAGE_TRANSFER_DST_BIT, true, VALIDATION_ERROR_18e00162, |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 4009 | "vkCmdCopyBufferToImage()", "VK_IMAGE_USAGE_TRANSFER_DST_BIT"); |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 4010 | skip |= insideRenderPass(device_data, cb_node, "vkCmdCopyBufferToImage()", VALIDATION_ERROR_18e00017); |
Tobin Ehlis | c826645 | 2017-04-07 12:20:30 -0600 | [diff] [blame] | 4011 | bool hit_error = false; |
Mark Lobodzinski | 033c90b | 2017-02-15 13:58:23 -0700 | [diff] [blame] | 4012 | for (uint32_t i = 0; i < regionCount; ++i) { |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 4013 | skip |= VerifyImageLayout(device_data, cb_node, dst_image_state, pRegions[i].imageSubresource, dstImageLayout, |
| 4014 | VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, "vkCmdCopyBufferToImage()", VALIDATION_ERROR_18e0016a, |
| 4015 | &hit_error); |
Mark Lobodzinski | 033c90b | 2017-02-15 13:58:23 -0700 | [diff] [blame] | 4016 | skip |= ValidateCopyBufferImageTransferGranularityRequirements(device_data, cb_node, dst_image_state, &pRegions[i], i, |
| 4017 | "vkCmdCopyBufferToImage()"); |
| 4018 | } |
| 4019 | return skip; |
| 4020 | } |
| 4021 | |
Mark Lobodzinski | 1fe9b00 | 2017-02-15 14:11:12 -0700 | [diff] [blame] | 4022 | 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] | 4023 | IMAGE_STATE *dst_image_state, uint32_t region_count, const VkBufferImageCopy *regions, |
| 4024 | VkImageLayout dst_image_layout) { |
| 4025 | // Make sure that all image slices are updated to correct layout |
| 4026 | for (uint32_t i = 0; i < region_count; ++i) { |
| 4027 | SetImageLayout(device_data, cb_node, dst_image_state, regions[i].imageSubresource, dst_image_layout); |
| 4028 | } |
Mark Lobodzinski | 1fe9b00 | 2017-02-15 14:11:12 -0700 | [diff] [blame] | 4029 | AddCommandBufferBindingBuffer(device_data, cb_node, src_buffer_state); |
Mark Lobodzinski | 033c90b | 2017-02-15 13:58:23 -0700 | [diff] [blame] | 4030 | AddCommandBufferBindingImage(device_data, cb_node, dst_image_state); |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 4031 | std::function<bool()> function = [=]() { |
| 4032 | SetImageMemoryValid(device_data, dst_image_state, true); |
| 4033 | return false; |
| 4034 | }; |
Tobin Ehlis | a17a529 | 2017-07-28 12:11:30 -0600 | [diff] [blame] | 4035 | cb_node->queue_submit_functions.push_back(function); |
Mark Lobodzinski | 1fe9b00 | 2017-02-15 14:11:12 -0700 | [diff] [blame] | 4036 | function = [=]() { return ValidateBufferMemoryIsValid(device_data, src_buffer_state, "vkCmdCopyBufferToImage()"); }; |
Tobin Ehlis | a17a529 | 2017-07-28 12:11:30 -0600 | [diff] [blame] | 4037 | cb_node->queue_submit_functions.push_back(function); |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 4038 | } |
Mike Weiblen | 672b58b | 2017-02-21 14:32:53 -0700 | [diff] [blame] | 4039 | |
| 4040 | bool PreCallValidateGetImageSubresourceLayout(layer_data *device_data, VkImage image, const VkImageSubresource *pSubresource) { |
| 4041 | const auto report_data = core_validation::GetReportData(device_data); |
| 4042 | bool skip = false; |
| 4043 | const VkImageAspectFlags sub_aspect = pSubresource->aspectMask; |
| 4044 | |
| 4045 | // VU 00733: The aspectMask member of pSubresource must only have a single bit set |
| 4046 | const int num_bits = sizeof(sub_aspect) * CHAR_BIT; |
| 4047 | std::bitset<num_bits> aspect_mask_bits(sub_aspect); |
| 4048 | if (aspect_mask_bits.count() != 1) { |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 4049 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, HandleToUint64(image), |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 4050 | __LINE__, VALIDATION_ERROR_2a6007ca, "IMAGE", |
Mike Weiblen | 672b58b | 2017-02-21 14:32:53 -0700 | [diff] [blame] | 4051 | "vkGetImageSubresourceLayout(): VkImageSubresource.aspectMask must have exactly 1 bit set. %s", |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 4052 | validation_error_map[VALIDATION_ERROR_2a6007ca]); |
Mike Weiblen | 672b58b | 2017-02-21 14:32:53 -0700 | [diff] [blame] | 4053 | } |
| 4054 | |
| 4055 | IMAGE_STATE *image_entry = GetImageState(device_data, image); |
| 4056 | if (!image_entry) { |
| 4057 | return skip; |
| 4058 | } |
| 4059 | |
| 4060 | // VU 00732: image must have been created with tiling equal to VK_IMAGE_TILING_LINEAR |
| 4061 | if (image_entry->createInfo.tiling != VK_IMAGE_TILING_LINEAR) { |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 4062 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, HandleToUint64(image), |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 4063 | __LINE__, VALIDATION_ERROR_2a6007c8, "IMAGE", |
Mike Weiblen | 672b58b | 2017-02-21 14:32:53 -0700 | [diff] [blame] | 4064 | "vkGetImageSubresourceLayout(): Image must have tiling of VK_IMAGE_TILING_LINEAR. %s", |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 4065 | validation_error_map[VALIDATION_ERROR_2a6007c8]); |
Mike Weiblen | 672b58b | 2017-02-21 14:32:53 -0700 | [diff] [blame] | 4066 | } |
| 4067 | |
| 4068 | // VU 00739: mipLevel must be less than the mipLevels specified in VkImageCreateInfo when the image was created |
| 4069 | if (pSubresource->mipLevel >= image_entry->createInfo.mipLevels) { |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 4070 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, HandleToUint64(image), |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 4071 | __LINE__, VALIDATION_ERROR_0a4007cc, "IMAGE", |
Mike Weiblen | 672b58b | 2017-02-21 14:32:53 -0700 | [diff] [blame] | 4072 | "vkGetImageSubresourceLayout(): pSubresource.mipLevel (%d) must be less than %d. %s", |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 4073 | pSubresource->mipLevel, image_entry->createInfo.mipLevels, validation_error_map[VALIDATION_ERROR_0a4007cc]); |
Mike Weiblen | 672b58b | 2017-02-21 14:32:53 -0700 | [diff] [blame] | 4074 | } |
| 4075 | |
| 4076 | // VU 00740: arrayLayer must be less than the arrayLayers specified in VkImageCreateInfo when the image was created |
| 4077 | if (pSubresource->arrayLayer >= image_entry->createInfo.arrayLayers) { |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 4078 | skip |= |
| 4079 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, HandleToUint64(image), |
| 4080 | __LINE__, VALIDATION_ERROR_0a4007ce, "IMAGE", |
| 4081 | "vkGetImageSubresourceLayout(): pSubresource.arrayLayer (%d) must be less than %d. %s", |
| 4082 | pSubresource->arrayLayer, image_entry->createInfo.arrayLayers, validation_error_map[VALIDATION_ERROR_0a4007ce]); |
Mike Weiblen | 672b58b | 2017-02-21 14:32:53 -0700 | [diff] [blame] | 4083 | } |
| 4084 | |
| 4085 | // VU 00741: subresource's aspect must be compatible with image's format. |
| 4086 | const VkFormat img_format = image_entry->createInfo.format; |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 4087 | if (FormatIsColor(img_format)) { |
Mike Weiblen | 672b58b | 2017-02-21 14:32:53 -0700 | [diff] [blame] | 4088 | if (sub_aspect != VK_IMAGE_ASPECT_COLOR_BIT) { |
| 4089 | skip |= log_msg( |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 4090 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, HandleToUint64(image), __LINE__, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 4091 | VALIDATION_ERROR_0a400c01, "IMAGE", |
Mike Weiblen | 672b58b | 2017-02-21 14:32:53 -0700 | [diff] [blame] | 4092 | "vkGetImageSubresourceLayout(): For color formats, VkImageSubresource.aspectMask must be VK_IMAGE_ASPECT_COLOR. %s", |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 4093 | validation_error_map[VALIDATION_ERROR_0a400c01]); |
Mike Weiblen | 672b58b | 2017-02-21 14:32:53 -0700 | [diff] [blame] | 4094 | } |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 4095 | } else if (FormatIsDepthOrStencil(img_format)) { |
Mike Weiblen | 672b58b | 2017-02-21 14:32:53 -0700 | [diff] [blame] | 4096 | 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] | 4097 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 4098 | HandleToUint64(image), __LINE__, VALIDATION_ERROR_0a400c01, "IMAGE", |
Mike Weiblen | 672b58b | 2017-02-21 14:32:53 -0700 | [diff] [blame] | 4099 | "vkGetImageSubresourceLayout(): For depth/stencil formats, VkImageSubresource.aspectMask must be " |
| 4100 | "either VK_IMAGE_ASPECT_DEPTH_BIT or VK_IMAGE_ASPECT_STENCIL_BIT. %s", |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 4101 | validation_error_map[VALIDATION_ERROR_0a400c01]); |
Mike Weiblen | 672b58b | 2017-02-21 14:32:53 -0700 | [diff] [blame] | 4102 | } |
| 4103 | } |
| 4104 | return skip; |
| 4105 | } |