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