Mark Lobodzinski | d42e4d2 | 2017-01-17 14:14:22 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2015-2017 The Khronos Group Inc. |
| 2 | * Copyright (c) 2015-2017 Valve Corporation |
| 3 | * Copyright (c) 2015-2017 LunarG, Inc. |
| 4 | * Copyright (C) 2015-2017 Google Inc. |
| 5 | * |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | * |
| 18 | * Author: Mark Lobodzinski <mark@lunarg.com> |
Dave Houlton | 4eaaf3a | 2017-03-14 11:31:20 -0600 | [diff] [blame] | 19 | * Author: Dave Houlton <daveh@lunarg.com> |
Mark Lobodzinski | d42e4d2 | 2017-01-17 14:14:22 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | // Allow use of STL min and max functions in Windows |
| 23 | #define NOMINMAX |
| 24 | |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 25 | #include <sstream> |
Petr Kraus | 4d71868 | 2017-05-18 03:38:41 +0200 | [diff] [blame] | 26 | #include <string> |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 27 | |
| 28 | #include "vk_enum_string_helper.h" |
| 29 | #include "vk_layer_data.h" |
| 30 | #include "vk_layer_utils.h" |
| 31 | #include "vk_layer_logging.h" |
Dave Houlton | bd2e262 | 2018-04-10 16:41:14 -0600 | [diff] [blame] | 32 | #include "vk_typemap_helper.h" |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 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 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 36 | void SetLayout(layer_data *device_data, GLOBAL_CB_NODE *pCB, ImageSubresourcePair imgpair, const VkImageLayout &layout) { |
Dave Houlton | b3f4b28 | 2018-02-22 16:25:16 -0700 | [diff] [blame] | 37 | auto it = pCB->imageLayoutMap.find(imgpair); |
| 38 | if (it != pCB->imageLayoutMap.end()) { |
| 39 | it->second.layout = layout; |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 40 | } else { |
| 41 | assert(imgpair.hasSubresource); |
| 42 | IMAGE_CMD_BUF_LAYOUT_NODE node; |
| 43 | if (!FindCmdBufLayout(device_data, pCB, imgpair.image, imgpair.subresource, node)) { |
| 44 | node.initialLayout = layout; |
| 45 | } |
| 46 | SetLayout(device_data, pCB, imgpair, {node.initialLayout, layout}); |
| 47 | } |
| 48 | } |
| 49 | template <class OBJECT, class LAYOUT> |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 50 | 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] | 51 | ImageSubresourcePair imgpair = {image, true, range}; |
| 52 | SetLayout(device_data, pObject, imgpair, layout, VK_IMAGE_ASPECT_COLOR_BIT); |
| 53 | SetLayout(device_data, pObject, imgpair, layout, VK_IMAGE_ASPECT_DEPTH_BIT); |
| 54 | SetLayout(device_data, pObject, imgpair, layout, VK_IMAGE_ASPECT_STENCIL_BIT); |
| 55 | SetLayout(device_data, pObject, imgpair, layout, VK_IMAGE_ASPECT_METADATA_BIT); |
Dave Houlton | b3f4b28 | 2018-02-22 16:25:16 -0700 | [diff] [blame] | 56 | if (GetDeviceExtensions(device_data)->vk_khr_sampler_ycbcr_conversion) { |
| 57 | SetLayout(device_data, pObject, imgpair, layout, VK_IMAGE_ASPECT_PLANE_0_BIT_KHR); |
| 58 | SetLayout(device_data, pObject, imgpair, layout, VK_IMAGE_ASPECT_PLANE_1_BIT_KHR); |
| 59 | SetLayout(device_data, pObject, imgpair, layout, VK_IMAGE_ASPECT_PLANE_2_BIT_KHR); |
| 60 | } |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | template <class OBJECT, class LAYOUT> |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 64 | 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] | 65 | VkImageAspectFlags aspectMask) { |
| 66 | if (imgpair.subresource.aspectMask & aspectMask) { |
| 67 | imgpair.subresource.aspectMask = aspectMask; |
| 68 | SetLayout(device_data, pObject, imgpair, layout); |
| 69 | } |
| 70 | } |
| 71 | |
Tony Barbour | df013b9 | 2017-01-25 12:53:48 -0700 | [diff] [blame] | 72 | // Set the layout in supplied map |
Tony Barbour | e0c5cc9 | 2017-02-08 13:53:39 -0700 | [diff] [blame] | 73 | void SetLayout(std::unordered_map<ImageSubresourcePair, IMAGE_LAYOUT_NODE> &imageLayoutMap, ImageSubresourcePair imgpair, |
| 74 | VkImageLayout layout) { |
Dave Houlton | b3f4b28 | 2018-02-22 16:25:16 -0700 | [diff] [blame] | 75 | auto it = imageLayoutMap.find(imgpair); |
| 76 | if (it != imageLayoutMap.end()) { |
| 77 | it->second.layout = layout; // Update |
| 78 | } else { |
| 79 | imageLayoutMap[imgpair].layout = layout; // Insert |
| 80 | } |
Tony Barbour | df013b9 | 2017-01-25 12:53:48 -0700 | [diff] [blame] | 81 | } |
| 82 | |
Tobin Ehlis | c826645 | 2017-04-07 12:20:30 -0600 | [diff] [blame] | 83 | 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] | 84 | IMAGE_CMD_BUF_LAYOUT_NODE &node, const VkImageAspectFlags aspectMask) { |
| 85 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 86 | |
| 87 | if (!(imgpair.subresource.aspectMask & aspectMask)) { |
| 88 | return false; |
| 89 | } |
| 90 | VkImageAspectFlags oldAspectMask = imgpair.subresource.aspectMask; |
| 91 | imgpair.subresource.aspectMask = aspectMask; |
| 92 | auto imgsubIt = pCB->imageLayoutMap.find(imgpair); |
| 93 | if (imgsubIt == pCB->imageLayoutMap.end()) { |
| 94 | return false; |
| 95 | } |
| 96 | 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] | 97 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, HandleToUint64(imgpair.image), |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 98 | DRAWSTATE_INVALID_LAYOUT, |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 99 | "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] | 100 | HandleToUint64(imgpair.image), oldAspectMask, string_VkImageLayout(node.layout), |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 101 | string_VkImageLayout(imgsubIt->second.layout)); |
| 102 | } |
| 103 | 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] | 104 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, HandleToUint64(imgpair.image), |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 105 | DRAWSTATE_INVALID_LAYOUT, |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 106 | "Cannot query for VkImage 0x%" PRIx64 |
| 107 | " 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] | 108 | HandleToUint64(imgpair.image), oldAspectMask, string_VkImageLayout(node.initialLayout), |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 109 | string_VkImageLayout(imgsubIt->second.initialLayout)); |
| 110 | } |
| 111 | node = imgsubIt->second; |
| 112 | return true; |
| 113 | } |
| 114 | |
Tobin Ehlis | c826645 | 2017-04-07 12:20:30 -0600 | [diff] [blame] | 115 | bool FindLayoutVerifyLayout(layer_data const *device_data, ImageSubresourcePair imgpair, VkImageLayout &layout, |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 116 | const VkImageAspectFlags aspectMask) { |
| 117 | if (!(imgpair.subresource.aspectMask & aspectMask)) { |
| 118 | return false; |
| 119 | } |
| 120 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 121 | VkImageAspectFlags oldAspectMask = imgpair.subresource.aspectMask; |
| 122 | imgpair.subresource.aspectMask = aspectMask; |
| 123 | auto imgsubIt = (*core_validation::GetImageLayoutMap(device_data)).find(imgpair); |
| 124 | if (imgsubIt == (*core_validation::GetImageLayoutMap(device_data)).end()) { |
| 125 | return false; |
| 126 | } |
| 127 | if (layout != VK_IMAGE_LAYOUT_MAX_ENUM && layout != imgsubIt->second.layout) { |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 128 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, HandleToUint64(imgpair.image), |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 129 | DRAWSTATE_INVALID_LAYOUT, |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 130 | "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] | 131 | HandleToUint64(imgpair.image), oldAspectMask, string_VkImageLayout(layout), |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 132 | string_VkImageLayout(imgsubIt->second.layout)); |
| 133 | } |
| 134 | layout = imgsubIt->second.layout; |
| 135 | return true; |
| 136 | } |
| 137 | |
| 138 | // Find layout(s) on the command buffer level |
Tobin Ehlis | c826645 | 2017-04-07 12:20:30 -0600 | [diff] [blame] | 139 | 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] | 140 | IMAGE_CMD_BUF_LAYOUT_NODE &node) { |
| 141 | ImageSubresourcePair imgpair = {image, true, range}; |
| 142 | node = IMAGE_CMD_BUF_LAYOUT_NODE(VK_IMAGE_LAYOUT_MAX_ENUM, VK_IMAGE_LAYOUT_MAX_ENUM); |
| 143 | FindLayoutVerifyNode(device_data, pCB, imgpair, node, VK_IMAGE_ASPECT_COLOR_BIT); |
| 144 | FindLayoutVerifyNode(device_data, pCB, imgpair, node, VK_IMAGE_ASPECT_DEPTH_BIT); |
| 145 | FindLayoutVerifyNode(device_data, pCB, imgpair, node, VK_IMAGE_ASPECT_STENCIL_BIT); |
| 146 | FindLayoutVerifyNode(device_data, pCB, imgpair, node, VK_IMAGE_ASPECT_METADATA_BIT); |
Dave Houlton | b3f4b28 | 2018-02-22 16:25:16 -0700 | [diff] [blame] | 147 | if (GetDeviceExtensions(device_data)->vk_khr_sampler_ycbcr_conversion) { |
| 148 | FindLayoutVerifyNode(device_data, pCB, imgpair, node, VK_IMAGE_ASPECT_PLANE_0_BIT_KHR); |
| 149 | FindLayoutVerifyNode(device_data, pCB, imgpair, node, VK_IMAGE_ASPECT_PLANE_1_BIT_KHR); |
| 150 | FindLayoutVerifyNode(device_data, pCB, imgpair, node, VK_IMAGE_ASPECT_PLANE_2_BIT_KHR); |
| 151 | } |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 152 | if (node.layout == VK_IMAGE_LAYOUT_MAX_ENUM) { |
| 153 | imgpair = {image, false, VkImageSubresource()}; |
| 154 | auto imgsubIt = pCB->imageLayoutMap.find(imgpair); |
| 155 | if (imgsubIt == pCB->imageLayoutMap.end()) return false; |
| 156 | // TODO: This is ostensibly a find function but it changes state here |
| 157 | node = imgsubIt->second; |
| 158 | } |
| 159 | return true; |
| 160 | } |
| 161 | |
| 162 | // Find layout(s) on the global level |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 163 | bool FindGlobalLayout(layer_data *device_data, ImageSubresourcePair imgpair, VkImageLayout &layout) { |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 164 | layout = VK_IMAGE_LAYOUT_MAX_ENUM; |
| 165 | FindLayoutVerifyLayout(device_data, imgpair, layout, VK_IMAGE_ASPECT_COLOR_BIT); |
| 166 | FindLayoutVerifyLayout(device_data, imgpair, layout, VK_IMAGE_ASPECT_DEPTH_BIT); |
| 167 | FindLayoutVerifyLayout(device_data, imgpair, layout, VK_IMAGE_ASPECT_STENCIL_BIT); |
| 168 | FindLayoutVerifyLayout(device_data, imgpair, layout, VK_IMAGE_ASPECT_METADATA_BIT); |
Dave Houlton | b3f4b28 | 2018-02-22 16:25:16 -0700 | [diff] [blame] | 169 | if (GetDeviceExtensions(device_data)->vk_khr_sampler_ycbcr_conversion) { |
| 170 | FindLayoutVerifyLayout(device_data, imgpair, layout, VK_IMAGE_ASPECT_PLANE_0_BIT_KHR); |
| 171 | FindLayoutVerifyLayout(device_data, imgpair, layout, VK_IMAGE_ASPECT_PLANE_1_BIT_KHR); |
| 172 | FindLayoutVerifyLayout(device_data, imgpair, layout, VK_IMAGE_ASPECT_PLANE_2_BIT_KHR); |
| 173 | } |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 174 | if (layout == VK_IMAGE_LAYOUT_MAX_ENUM) { |
| 175 | imgpair = {imgpair.image, false, VkImageSubresource()}; |
| 176 | auto imgsubIt = (*core_validation::GetImageLayoutMap(device_data)).find(imgpair); |
| 177 | if (imgsubIt == (*core_validation::GetImageLayoutMap(device_data)).end()) return false; |
| 178 | layout = imgsubIt->second.layout; |
| 179 | } |
| 180 | return true; |
| 181 | } |
| 182 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 183 | bool FindLayouts(layer_data *device_data, VkImage image, std::vector<VkImageLayout> &layouts) { |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 184 | auto sub_data = (*core_validation::GetImageSubresourceMap(device_data)).find(image); |
| 185 | if (sub_data == (*core_validation::GetImageSubresourceMap(device_data)).end()) return false; |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 186 | auto image_state = GetImageState(device_data, image); |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 187 | if (!image_state) return false; |
| 188 | bool ignoreGlobal = false; |
| 189 | // TODO: Make this robust for >1 aspect mask. Now it will just say ignore potential errors in this case. |
| 190 | if (sub_data->second.size() >= (image_state->createInfo.arrayLayers * image_state->createInfo.mipLevels + 1)) { |
| 191 | ignoreGlobal = true; |
| 192 | } |
| 193 | for (auto imgsubpair : sub_data->second) { |
| 194 | if (ignoreGlobal && !imgsubpair.hasSubresource) continue; |
| 195 | auto img_data = (*core_validation::GetImageLayoutMap(device_data)).find(imgsubpair); |
| 196 | if (img_data != (*core_validation::GetImageLayoutMap(device_data)).end()) { |
| 197 | layouts.push_back(img_data->second.layout); |
| 198 | } |
| 199 | } |
| 200 | return true; |
| 201 | } |
Tony Barbour | e0c5cc9 | 2017-02-08 13:53:39 -0700 | [diff] [blame] | 202 | bool FindLayout(const std::unordered_map<ImageSubresourcePair, IMAGE_LAYOUT_NODE> &imageLayoutMap, ImageSubresourcePair imgpair, |
| 203 | VkImageLayout &layout, const VkImageAspectFlags aspectMask) { |
Tony Barbour | df013b9 | 2017-01-25 12:53:48 -0700 | [diff] [blame] | 204 | if (!(imgpair.subresource.aspectMask & aspectMask)) { |
| 205 | return false; |
| 206 | } |
| 207 | imgpair.subresource.aspectMask = aspectMask; |
| 208 | auto imgsubIt = imageLayoutMap.find(imgpair); |
| 209 | if (imgsubIt == imageLayoutMap.end()) { |
| 210 | return false; |
| 211 | } |
| 212 | layout = imgsubIt->second.layout; |
| 213 | return true; |
Tony Barbour | e0c5cc9 | 2017-02-08 13:53:39 -0700 | [diff] [blame] | 214 | } |
Tony Barbour | df013b9 | 2017-01-25 12:53:48 -0700 | [diff] [blame] | 215 | |
| 216 | // find layout in supplied map |
Dave Houlton | b3f4b28 | 2018-02-22 16:25:16 -0700 | [diff] [blame] | 217 | bool FindLayout(layer_data *device_data, const std::unordered_map<ImageSubresourcePair, IMAGE_LAYOUT_NODE> &imageLayoutMap, |
| 218 | ImageSubresourcePair imgpair, VkImageLayout &layout) { |
Tony Barbour | df013b9 | 2017-01-25 12:53:48 -0700 | [diff] [blame] | 219 | layout = VK_IMAGE_LAYOUT_MAX_ENUM; |
| 220 | FindLayout(imageLayoutMap, imgpair, layout, VK_IMAGE_ASPECT_COLOR_BIT); |
| 221 | FindLayout(imageLayoutMap, imgpair, layout, VK_IMAGE_ASPECT_DEPTH_BIT); |
| 222 | FindLayout(imageLayoutMap, imgpair, layout, VK_IMAGE_ASPECT_STENCIL_BIT); |
| 223 | FindLayout(imageLayoutMap, imgpair, layout, VK_IMAGE_ASPECT_METADATA_BIT); |
Dave Houlton | b3f4b28 | 2018-02-22 16:25:16 -0700 | [diff] [blame] | 224 | if (GetDeviceExtensions(device_data)->vk_khr_sampler_ycbcr_conversion) { |
| 225 | FindLayout(imageLayoutMap, imgpair, layout, VK_IMAGE_ASPECT_PLANE_0_BIT_KHR); |
| 226 | FindLayout(imageLayoutMap, imgpair, layout, VK_IMAGE_ASPECT_PLANE_1_BIT_KHR); |
| 227 | FindLayout(imageLayoutMap, imgpair, layout, VK_IMAGE_ASPECT_PLANE_2_BIT_KHR); |
| 228 | } |
| 229 | // Image+subresource not found, look for image handle w/o subresource |
Tony Barbour | df013b9 | 2017-01-25 12:53:48 -0700 | [diff] [blame] | 230 | if (layout == VK_IMAGE_LAYOUT_MAX_ENUM) { |
| 231 | imgpair = {imgpair.image, false, VkImageSubresource()}; |
| 232 | auto imgsubIt = imageLayoutMap.find(imgpair); |
| 233 | if (imgsubIt == imageLayoutMap.end()) return false; |
| 234 | layout = imgsubIt->second.layout; |
| 235 | } |
| 236 | return true; |
| 237 | } |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 238 | |
| 239 | // Set the layout on the global level |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 240 | void SetGlobalLayout(layer_data *device_data, ImageSubresourcePair imgpair, const VkImageLayout &layout) { |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 241 | VkImage &image = imgpair.image; |
Dave Houlton | b3f4b28 | 2018-02-22 16:25:16 -0700 | [diff] [blame] | 242 | auto &lmap = (*core_validation::GetImageLayoutMap(device_data)); |
| 243 | auto data = lmap.find(imgpair); |
| 244 | if (data != lmap.end()) { |
| 245 | data->second.layout = layout; // Update |
| 246 | } else { |
| 247 | lmap[imgpair].layout = layout; // Insert |
| 248 | } |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 249 | auto &image_subresources = (*core_validation::GetImageSubresourceMap(device_data))[image]; |
| 250 | auto subresource = std::find(image_subresources.begin(), image_subresources.end(), imgpair); |
| 251 | if (subresource == image_subresources.end()) { |
| 252 | image_subresources.push_back(imgpair); |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | // Set the layout on the cmdbuf level |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 257 | void SetLayout(layer_data *device_data, GLOBAL_CB_NODE *pCB, ImageSubresourcePair imgpair, const IMAGE_CMD_BUF_LAYOUT_NODE &node) { |
Dave Houlton | b3f4b28 | 2018-02-22 16:25:16 -0700 | [diff] [blame] | 258 | auto it = pCB->imageLayoutMap.find(imgpair); |
| 259 | if (it != pCB->imageLayoutMap.end()) { |
| 260 | it->second = node; // Update |
| 261 | } else { |
| 262 | pCB->imageLayoutMap[imgpair] = node; // Insert |
| 263 | } |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 264 | } |
Tobin Ehlis | e35b66a | 2017-03-15 12:18:31 -0600 | [diff] [blame] | 265 | // Set image layout for given VkImageSubresourceRange struct |
| 266 | void SetImageLayout(layer_data *device_data, GLOBAL_CB_NODE *cb_node, const IMAGE_STATE *image_state, |
| 267 | VkImageSubresourceRange image_subresource_range, const VkImageLayout &layout) { |
| 268 | assert(image_state); |
John Zulauf | 48a6a70 | 2017-12-22 17:14:54 -0700 | [diff] [blame] | 269 | cb_node->image_layout_change_count++; // Change the version of this data to force revalidation |
Tobin Ehlis | e35b66a | 2017-03-15 12:18:31 -0600 | [diff] [blame] | 270 | for (uint32_t level_index = 0; level_index < image_subresource_range.levelCount; ++level_index) { |
| 271 | uint32_t level = image_subresource_range.baseMipLevel + level_index; |
| 272 | for (uint32_t layer_index = 0; layer_index < image_subresource_range.layerCount; layer_index++) { |
| 273 | uint32_t layer = image_subresource_range.baseArrayLayer + layer_index; |
| 274 | VkImageSubresource sub = {image_subresource_range.aspectMask, level, layer}; |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 275 | // TODO: If ImageView was created with depth or stencil, transition both layouts as the aspectMask is ignored and both |
| 276 | // 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] | 277 | 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] | 278 | if (FormatIsDepthAndStencil(image_state->createInfo.format)) { |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 279 | sub.aspectMask |= (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT); |
| 280 | } |
| 281 | } |
Tobin Ehlis | e35b66a | 2017-03-15 12:18:31 -0600 | [diff] [blame] | 282 | SetLayout(device_data, cb_node, image_state->image, sub, layout); |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 283 | } |
| 284 | } |
| 285 | } |
Tobin Ehlis | e35b66a | 2017-03-15 12:18:31 -0600 | [diff] [blame] | 286 | // Set image layout for given VkImageSubresourceLayers struct |
| 287 | void SetImageLayout(layer_data *device_data, GLOBAL_CB_NODE *cb_node, const IMAGE_STATE *image_state, |
| 288 | VkImageSubresourceLayers image_subresource_layers, const VkImageLayout &layout) { |
| 289 | // Transfer VkImageSubresourceLayers into VkImageSubresourceRange struct |
| 290 | VkImageSubresourceRange image_subresource_range; |
| 291 | image_subresource_range.aspectMask = image_subresource_layers.aspectMask; |
| 292 | image_subresource_range.baseArrayLayer = image_subresource_layers.baseArrayLayer; |
| 293 | image_subresource_range.layerCount = image_subresource_layers.layerCount; |
| 294 | image_subresource_range.baseMipLevel = image_subresource_layers.mipLevel; |
| 295 | image_subresource_range.levelCount = 1; |
| 296 | SetImageLayout(device_data, cb_node, image_state, image_subresource_range, layout); |
| 297 | } |
| 298 | // Set image layout for all slices of an image view |
| 299 | void SetImageViewLayout(layer_data *device_data, GLOBAL_CB_NODE *cb_node, VkImageView imageView, const VkImageLayout &layout) { |
| 300 | auto view_state = GetImageViewState(device_data, imageView); |
| 301 | assert(view_state); |
| 302 | |
| 303 | SetImageLayout(device_data, cb_node, GetImageState(device_data, view_state->create_info.image), |
| 304 | view_state->create_info.subresourceRange, layout); |
| 305 | } |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 306 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 307 | bool VerifyFramebufferAndRenderPassLayouts(layer_data *device_data, GLOBAL_CB_NODE *pCB, |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 308 | const VkRenderPassBeginInfo *pRenderPassBegin, |
| 309 | const FRAMEBUFFER_STATE *framebuffer_state) { |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 310 | bool skip = false; |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 311 | auto const pRenderPassInfo = GetRenderPassState(device_data, pRenderPassBegin->renderPass)->createInfo.ptr(); |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 312 | auto const &framebufferInfo = framebuffer_state->createInfo; |
| 313 | const auto report_data = core_validation::GetReportData(device_data); |
| 314 | if (pRenderPassInfo->attachmentCount != framebufferInfo.attachmentCount) { |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 315 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 316 | HandleToUint64(pCB->commandBuffer), DRAWSTATE_INVALID_RENDERPASS, |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 317 | "You cannot start a render pass using a framebuffer with a different number of attachments."); |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 318 | } |
| 319 | for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) { |
| 320 | const VkImageView &image_view = framebufferInfo.pAttachments[i]; |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 321 | auto view_state = GetImageViewState(device_data, image_view); |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 322 | assert(view_state); |
| 323 | const VkImage &image = view_state->create_info.image; |
| 324 | const VkImageSubresourceRange &subRange = view_state->create_info.subresourceRange; |
Tobin Ehlis | 0d4274b | 2017-02-17 15:17:04 -0700 | [diff] [blame] | 325 | auto initial_layout = pRenderPassInfo->pAttachments[i].initialLayout; |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 326 | // TODO: Do not iterate over every possibility - consolidate where possible |
| 327 | for (uint32_t j = 0; j < subRange.levelCount; j++) { |
| 328 | uint32_t level = subRange.baseMipLevel + j; |
| 329 | for (uint32_t k = 0; k < subRange.layerCount; k++) { |
| 330 | uint32_t layer = subRange.baseArrayLayer + k; |
| 331 | VkImageSubresource sub = {subRange.aspectMask, level, layer}; |
| 332 | IMAGE_CMD_BUF_LAYOUT_NODE node; |
| 333 | if (!FindCmdBufLayout(device_data, pCB, image, sub, node)) { |
Tobin Ehlis | 0d4274b | 2017-02-17 15:17:04 -0700 | [diff] [blame] | 334 | // Missing layouts will be added during state update |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 335 | continue; |
| 336 | } |
Tobin Ehlis | 0d4274b | 2017-02-17 15:17:04 -0700 | [diff] [blame] | 337 | if (initial_layout != VK_IMAGE_LAYOUT_UNDEFINED && initial_layout != node.layout) { |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 338 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 339 | DRAWSTATE_INVALID_RENDERPASS, |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 340 | "You cannot start a render pass using attachment %u where the render pass initial layout is %s " |
| 341 | "and the previous known layout of the attachment is %s. The layouts must match, or the render " |
| 342 | "pass initial layout for the attachment must be VK_IMAGE_LAYOUT_UNDEFINED", |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 343 | i, string_VkImageLayout(initial_layout), string_VkImageLayout(node.layout)); |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 344 | } |
| 345 | } |
| 346 | } |
| 347 | } |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 348 | return skip; |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 349 | } |
| 350 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 351 | 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] | 352 | VkAttachmentReference ref) { |
| 353 | if (ref.attachment != VK_ATTACHMENT_UNUSED) { |
| 354 | auto image_view = pFramebuffer->createInfo.pAttachments[ref.attachment]; |
| 355 | SetImageViewLayout(device_data, pCB, image_view, ref.layout); |
| 356 | } |
| 357 | } |
| 358 | |
Tobin Ehlis | 0d4274b | 2017-02-17 15:17:04 -0700 | [diff] [blame] | 359 | 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] | 360 | const int subpass_index, FRAMEBUFFER_STATE *framebuffer_state) { |
Tobin Ehlis | 0d4274b | 2017-02-17 15:17:04 -0700 | [diff] [blame] | 361 | assert(render_pass_state); |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 362 | |
| 363 | if (framebuffer_state) { |
Tobin Ehlis | 0d4274b | 2017-02-17 15:17:04 -0700 | [diff] [blame] | 364 | auto const &subpass = render_pass_state->createInfo.pSubpasses[subpass_index]; |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 365 | for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) { |
| 366 | TransitionAttachmentRefLayout(device_data, pCB, framebuffer_state, subpass.pInputAttachments[j]); |
| 367 | } |
| 368 | for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) { |
| 369 | TransitionAttachmentRefLayout(device_data, pCB, framebuffer_state, subpass.pColorAttachments[j]); |
| 370 | } |
| 371 | if (subpass.pDepthStencilAttachment) { |
| 372 | TransitionAttachmentRefLayout(device_data, pCB, framebuffer_state, *subpass.pDepthStencilAttachment); |
| 373 | } |
| 374 | } |
| 375 | } |
| 376 | |
Tobin Ehlis | 9c0df96 | 2017-07-17 10:14:27 -0600 | [diff] [blame] | 377 | bool ValidateImageAspectLayout(layer_data *device_data, GLOBAL_CB_NODE const *pCB, const VkImageMemoryBarrier *mem_barrier, |
Mark Lobodzinski | 6b6c50a | 2017-02-27 12:56:14 -0700 | [diff] [blame] | 378 | uint32_t level, uint32_t layer, VkImageAspectFlags aspect) { |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 379 | if (!(mem_barrier->subresourceRange.aspectMask & aspect)) { |
| 380 | return false; |
| 381 | } |
| 382 | VkImageSubresource sub = {aspect, level, layer}; |
| 383 | IMAGE_CMD_BUF_LAYOUT_NODE node; |
| 384 | if (!FindCmdBufLayout(device_data, pCB, mem_barrier->image, sub, node)) { |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 385 | return false; |
| 386 | } |
| 387 | bool skip = false; |
| 388 | if (mem_barrier->oldLayout == VK_IMAGE_LAYOUT_UNDEFINED) { |
| 389 | // TODO: Set memory invalid which is in mem_tracker currently |
| 390 | } else if (node.layout != mem_barrier->oldLayout) { |
Cort Stratton | d46dcb5 | 2018-04-10 14:52:49 -0700 | [diff] [blame] | 391 | skip = |
| 392 | log_msg(core_validation::GetReportData(device_data), VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 393 | VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, HandleToUint64(pCB->commandBuffer), VALIDATION_ERROR_0a00095a, |
| 394 | "For image 0x%" PRIx64 |
| 395 | " you cannot transition the layout of aspect=%d level=%d layer=%d from %s when current layout is %s.", |
| 396 | HandleToUint64(mem_barrier->image), aspect, level, layer, string_VkImageLayout(mem_barrier->oldLayout), |
| 397 | string_VkImageLayout(node.layout)); |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 398 | } |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 399 | return skip; |
| 400 | } |
| 401 | |
Tobin Ehlis | 0d4274b | 2017-02-17 15:17:04 -0700 | [diff] [blame] | 402 | // Transition the layout state for renderpass attachments based on the BeginRenderPass() call. This includes: |
| 403 | // 1. Transition into initialLayout state |
| 404 | // 2. Transition from initialLayout to layout used in subpass 0 |
| 405 | void TransitionBeginRenderPassLayouts(layer_data *device_data, GLOBAL_CB_NODE *cb_state, const RENDER_PASS_STATE *render_pass_state, |
| 406 | FRAMEBUFFER_STATE *framebuffer_state) { |
| 407 | // First transition into initialLayout |
| 408 | auto const rpci = render_pass_state->createInfo.ptr(); |
| 409 | for (uint32_t i = 0; i < rpci->attachmentCount; ++i) { |
| 410 | VkImageView image_view = framebuffer_state->createInfo.pAttachments[i]; |
| 411 | SetImageViewLayout(device_data, cb_state, image_view, rpci->pAttachments[i].initialLayout); |
| 412 | } |
| 413 | // Now transition for first subpass (index 0) |
| 414 | TransitionSubpassLayouts(device_data, cb_state, render_pass_state, 0, framebuffer_state); |
| 415 | } |
| 416 | |
Mark Lobodzinski | 6b6c50a | 2017-02-27 12:56:14 -0700 | [diff] [blame] | 417 | void TransitionImageAspectLayout(layer_data *device_data, GLOBAL_CB_NODE *pCB, const VkImageMemoryBarrier *mem_barrier, |
| 418 | uint32_t level, uint32_t layer, VkImageAspectFlags aspect) { |
| 419 | if (!(mem_barrier->subresourceRange.aspectMask & aspect)) { |
| 420 | return; |
| 421 | } |
| 422 | VkImageSubresource sub = {aspect, level, layer}; |
| 423 | IMAGE_CMD_BUF_LAYOUT_NODE node; |
| 424 | if (!FindCmdBufLayout(device_data, pCB, mem_barrier->image, sub, node)) { |
John Zulauf | 48a6a70 | 2017-12-22 17:14:54 -0700 | [diff] [blame] | 425 | pCB->image_layout_change_count++; // Change the version of this data to force revalidation |
Mark Lobodzinski | 6b6c50a | 2017-02-27 12:56:14 -0700 | [diff] [blame] | 426 | SetLayout(device_data, pCB, mem_barrier->image, sub, |
| 427 | IMAGE_CMD_BUF_LAYOUT_NODE(mem_barrier->oldLayout, mem_barrier->newLayout)); |
| 428 | return; |
| 429 | } |
| 430 | if (mem_barrier->oldLayout == VK_IMAGE_LAYOUT_UNDEFINED) { |
| 431 | // TODO: Set memory invalid |
| 432 | } |
| 433 | SetLayout(device_data, pCB, mem_barrier->image, sub, mem_barrier->newLayout); |
| 434 | } |
| 435 | |
Dave Houlton | 10b3948 | 2017-03-16 13:18:15 -0600 | [diff] [blame] | 436 | bool VerifyAspectsPresent(VkImageAspectFlags aspect_mask, VkFormat format) { |
Dave Houlton | 4eaaf3a | 2017-03-14 11:31:20 -0600 | [diff] [blame] | 437 | if ((aspect_mask & VK_IMAGE_ASPECT_COLOR_BIT) != 0) { |
Dave Houlton | e2fca55 | 2018-04-05 16:20:33 -0600 | [diff] [blame] | 438 | if (!(FormatIsColor(format) || FormatIsMultiplane(format))) return false; |
Dave Houlton | 4eaaf3a | 2017-03-14 11:31:20 -0600 | [diff] [blame] | 439 | } |
| 440 | if ((aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) != 0) { |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 441 | if (!FormatHasDepth(format)) return false; |
Dave Houlton | 4eaaf3a | 2017-03-14 11:31:20 -0600 | [diff] [blame] | 442 | } |
| 443 | if ((aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) != 0) { |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 444 | if (!FormatHasStencil(format)) return false; |
Dave Houlton | 4eaaf3a | 2017-03-14 11:31:20 -0600 | [diff] [blame] | 445 | } |
Dave Houlton | b3f4b28 | 2018-02-22 16:25:16 -0700 | [diff] [blame] | 446 | if (0 != |
| 447 | (aspect_mask & (VK_IMAGE_ASPECT_PLANE_0_BIT_KHR | VK_IMAGE_ASPECT_PLANE_1_BIT_KHR | VK_IMAGE_ASPECT_PLANE_2_BIT_KHR))) { |
| 448 | if (FormatPlaneCount(format) == 1) return false; |
| 449 | } |
Dave Houlton | 4eaaf3a | 2017-03-14 11:31:20 -0600 | [diff] [blame] | 450 | return true; |
| 451 | } |
| 452 | |
Mike Weiblen | 62d08a3 | 2017-03-07 22:18:27 -0700 | [diff] [blame] | 453 | // Verify an ImageMemoryBarrier's old/new ImageLayouts are compatible with the Image's ImageUsageFlags. |
| 454 | bool ValidateBarrierLayoutToImageUsage(layer_data *device_data, const VkImageMemoryBarrier *img_barrier, bool new_not_old, |
| 455 | VkImageUsageFlags usage_flags, const char *func_name) { |
| 456 | const auto report_data = core_validation::GetReportData(device_data); |
| 457 | bool skip = false; |
| 458 | const VkImageLayout layout = (new_not_old) ? img_barrier->newLayout : img_barrier->oldLayout; |
| 459 | UNIQUE_VALIDATION_ERROR_CODE msg_code = VALIDATION_ERROR_UNDEFINED; // sentinel value meaning "no error" |
| 460 | |
| 461 | switch (layout) { |
| 462 | case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: |
| 463 | if ((usage_flags & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) == 0) { |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 464 | msg_code = VALIDATION_ERROR_0a000970; |
Mike Weiblen | 62d08a3 | 2017-03-07 22:18:27 -0700 | [diff] [blame] | 465 | } |
| 466 | break; |
| 467 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: |
| 468 | if ((usage_flags & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) == 0) { |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 469 | msg_code = VALIDATION_ERROR_0a000972; |
Mike Weiblen | 62d08a3 | 2017-03-07 22:18:27 -0700 | [diff] [blame] | 470 | } |
| 471 | break; |
| 472 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: |
| 473 | if ((usage_flags & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) == 0) { |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 474 | msg_code = VALIDATION_ERROR_0a000974; |
Mike Weiblen | 62d08a3 | 2017-03-07 22:18:27 -0700 | [diff] [blame] | 475 | } |
| 476 | break; |
| 477 | case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: |
| 478 | 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] | 479 | msg_code = VALIDATION_ERROR_0a000976; |
Mike Weiblen | 62d08a3 | 2017-03-07 22:18:27 -0700 | [diff] [blame] | 480 | } |
| 481 | break; |
| 482 | case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL: |
| 483 | if ((usage_flags & VK_IMAGE_USAGE_TRANSFER_SRC_BIT) == 0) { |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 484 | msg_code = VALIDATION_ERROR_0a000978; |
Mike Weiblen | 62d08a3 | 2017-03-07 22:18:27 -0700 | [diff] [blame] | 485 | } |
| 486 | break; |
| 487 | case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL: |
| 488 | if ((usage_flags & VK_IMAGE_USAGE_TRANSFER_DST_BIT) == 0) { |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 489 | msg_code = VALIDATION_ERROR_0a00097a; |
Mike Weiblen | 62d08a3 | 2017-03-07 22:18:27 -0700 | [diff] [blame] | 490 | } |
| 491 | break; |
| 492 | default: |
| 493 | // Other VkImageLayout values do not have VUs defined in this context. |
| 494 | break; |
| 495 | } |
| 496 | |
| 497 | if (msg_code != VALIDATION_ERROR_UNDEFINED) { |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 498 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 499 | HandleToUint64(img_barrier->image), msg_code, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 500 | "%s: Image barrier 0x%p %sLayout=%s is not compatible with image 0x%" PRIx64 " usage flags 0x%" PRIx32 ".", |
| 501 | func_name, static_cast<const void *>(img_barrier), ((new_not_old) ? "new" : "old"), |
| 502 | string_VkImageLayout(layout), HandleToUint64(img_barrier->image), usage_flags); |
Mike Weiblen | 62d08a3 | 2017-03-07 22:18:27 -0700 | [diff] [blame] | 503 | } |
| 504 | return skip; |
| 505 | } |
| 506 | |
| 507 | // Verify image barriers are compatible with the images they reference. |
Tobin Ehlis | 9c0df96 | 2017-07-17 10:14:27 -0600 | [diff] [blame] | 508 | bool ValidateBarriersToImages(layer_data *device_data, GLOBAL_CB_NODE const *cb_state, uint32_t imageMemoryBarrierCount, |
Mike Weiblen | 62d08a3 | 2017-03-07 22:18:27 -0700 | [diff] [blame] | 509 | const VkImageMemoryBarrier *pImageMemoryBarriers, const char *func_name) { |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 510 | bool skip = false; |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 511 | |
Mike Weiblen | 62d08a3 | 2017-03-07 22:18:27 -0700 | [diff] [blame] | 512 | for (uint32_t i = 0; i < imageMemoryBarrierCount; ++i) { |
| 513 | auto img_barrier = &pImageMemoryBarriers[i]; |
| 514 | if (!img_barrier) continue; |
| 515 | |
Tobin Ehlis | bb03e5f | 2017-05-11 08:52:51 -0600 | [diff] [blame] | 516 | auto image_state = GetImageState(device_data, img_barrier->image); |
| 517 | if (image_state) { |
| 518 | VkImageUsageFlags usage_flags = image_state->createInfo.usage; |
| 519 | skip |= ValidateBarrierLayoutToImageUsage(device_data, img_barrier, false, usage_flags, func_name); |
| 520 | skip |= ValidateBarrierLayoutToImageUsage(device_data, img_barrier, true, usage_flags, func_name); |
| 521 | |
| 522 | // Make sure layout is able to be transitioned, currently only presented shared presentable images are locked |
| 523 | if (image_state->layout_locked) { |
| 524 | // TODO: Add unique id for error when available |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 525 | skip |= log_msg( |
| 526 | core_validation::GetReportData(device_data), VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 527 | VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, 0, |
Petr Kraus | 13c98a6 | 2017-12-09 00:22:39 +0100 | [diff] [blame] | 528 | "Attempting to transition shared presentable image 0x%" PRIx64 |
Tobin Ehlis | bb03e5f | 2017-05-11 08:52:51 -0600 | [diff] [blame] | 529 | " from layout %s to layout %s, but image has already been presented and cannot have its layout transitioned.", |
Petr Kraus | 13c98a6 | 2017-12-09 00:22:39 +0100 | [diff] [blame] | 530 | HandleToUint64(img_barrier->image), string_VkImageLayout(img_barrier->oldLayout), |
Tobin Ehlis | bb03e5f | 2017-05-11 08:52:51 -0600 | [diff] [blame] | 531 | string_VkImageLayout(img_barrier->newLayout)); |
| 532 | } |
| 533 | } |
| 534 | |
Mark Lobodzinski | 903e5ff | 2017-03-23 09:43:35 -0600 | [diff] [blame] | 535 | VkImageCreateInfo *image_create_info = &(GetImageState(device_data, img_barrier->image)->createInfo); |
Tobin Ehlis | 7ee9cbd | 2017-04-26 16:51:48 -0600 | [diff] [blame] | 536 | // For a Depth/Stencil image both aspects MUST be set |
| 537 | if (FormatIsDepthAndStencil(image_create_info->format)) { |
| 538 | auto const aspect_mask = img_barrier->subresourceRange.aspectMask; |
| 539 | auto const ds_mask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
| 540 | if ((aspect_mask & ds_mask) != (ds_mask)) { |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 541 | skip |= |
| 542 | log_msg(core_validation::GetReportData(device_data), VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 543 | VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, HandleToUint64(img_barrier->image), VALIDATION_ERROR_0a00096e, |
| 544 | "%s: Image barrier 0x%p references image 0x%" PRIx64 |
| 545 | " of format %s that must have the depth and stencil aspects set, but its aspectMask is 0x%" PRIx32 ".", |
| 546 | func_name, static_cast<const void *>(img_barrier), HandleToUint64(img_barrier->image), |
| 547 | string_VkFormat(image_create_info->format), aspect_mask); |
Tobin Ehlis | 7ee9cbd | 2017-04-26 16:51:48 -0600 | [diff] [blame] | 548 | } |
| 549 | } |
Mark Lobodzinski | 903e5ff | 2017-03-23 09:43:35 -0600 | [diff] [blame] | 550 | uint32_t level_count = ResolveRemainingLevels(&img_barrier->subresourceRange, image_create_info->mipLevels); |
| 551 | uint32_t layer_count = ResolveRemainingLayers(&img_barrier->subresourceRange, image_create_info->arrayLayers); |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 552 | |
Mike Weiblen | 62d08a3 | 2017-03-07 22:18:27 -0700 | [diff] [blame] | 553 | for (uint32_t j = 0; j < level_count; j++) { |
| 554 | uint32_t level = img_barrier->subresourceRange.baseMipLevel + j; |
| 555 | for (uint32_t k = 0; k < layer_count; k++) { |
| 556 | uint32_t layer = img_barrier->subresourceRange.baseArrayLayer + k; |
Tobin Ehlis | 9c0df96 | 2017-07-17 10:14:27 -0600 | [diff] [blame] | 557 | skip |= ValidateImageAspectLayout(device_data, cb_state, img_barrier, level, layer, VK_IMAGE_ASPECT_COLOR_BIT); |
| 558 | skip |= ValidateImageAspectLayout(device_data, cb_state, img_barrier, level, layer, VK_IMAGE_ASPECT_DEPTH_BIT); |
| 559 | skip |= ValidateImageAspectLayout(device_data, cb_state, img_barrier, level, layer, VK_IMAGE_ASPECT_STENCIL_BIT); |
| 560 | skip |= ValidateImageAspectLayout(device_data, cb_state, img_barrier, level, layer, VK_IMAGE_ASPECT_METADATA_BIT); |
Dave Houlton | b3f4b28 | 2018-02-22 16:25:16 -0700 | [diff] [blame] | 561 | if (GetDeviceExtensions(device_data)->vk_khr_sampler_ycbcr_conversion) { |
| 562 | skip |= ValidateImageAspectLayout(device_data, cb_state, img_barrier, level, layer, |
| 563 | VK_IMAGE_ASPECT_PLANE_0_BIT_KHR); |
| 564 | skip |= ValidateImageAspectLayout(device_data, cb_state, img_barrier, level, layer, |
| 565 | VK_IMAGE_ASPECT_PLANE_1_BIT_KHR); |
| 566 | skip |= ValidateImageAspectLayout(device_data, cb_state, img_barrier, level, layer, |
| 567 | VK_IMAGE_ASPECT_PLANE_2_BIT_KHR); |
| 568 | } |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 569 | } |
| 570 | } |
| 571 | } |
| 572 | return skip; |
| 573 | } |
| 574 | |
Chris Forbes | 4de4b13 | 2017-08-21 11:27:08 -0700 | [diff] [blame] | 575 | static bool IsReleaseOp(layer_data *device_data, GLOBAL_CB_NODE *cb_state, VkImageMemoryBarrier const *barrier) { |
John Zulauf | 1b33d5a | 2018-03-24 19:52:19 -0600 | [diff] [blame] | 576 | if (!IsTransferOp(barrier)) return false; |
Chris Forbes | 4de4b13 | 2017-08-21 11:27:08 -0700 | [diff] [blame] | 577 | |
| 578 | auto pool = GetCommandPoolNode(device_data, cb_state->createInfo.commandPool); |
John Zulauf | 1b33d5a | 2018-03-24 19:52:19 -0600 | [diff] [blame] | 579 | return pool && IsReleaseOp<VkImageMemoryBarrier, true>(pool, barrier); |
Chris Forbes | 4de4b13 | 2017-08-21 11:27:08 -0700 | [diff] [blame] | 580 | } |
| 581 | |
Chris Forbes | 399a678 | 2017-08-18 15:00:48 -0700 | [diff] [blame] | 582 | void TransitionImageLayouts(layer_data *device_data, GLOBAL_CB_NODE *cb_state, uint32_t memBarrierCount, |
Mark Lobodzinski | 6b6c50a | 2017-02-27 12:56:14 -0700 | [diff] [blame] | 583 | const VkImageMemoryBarrier *pImgMemBarriers) { |
Mark Lobodzinski | 6b6c50a | 2017-02-27 12:56:14 -0700 | [diff] [blame] | 584 | for (uint32_t i = 0; i < memBarrierCount; ++i) { |
| 585 | auto mem_barrier = &pImgMemBarriers[i]; |
| 586 | if (!mem_barrier) continue; |
Mark Lobodzinski | 6b6c50a | 2017-02-27 12:56:14 -0700 | [diff] [blame] | 587 | |
Chris Forbes | 4de4b13 | 2017-08-21 11:27:08 -0700 | [diff] [blame] | 588 | // For ownership transfers, the barrier is specified twice; as a release |
| 589 | // operation on the yielding queue family, and as an acquire operation |
| 590 | // on the acquiring queue family. This barrier may also include a layout |
| 591 | // transition, which occurs 'between' the two operations. For validation |
| 592 | // purposes it doesn't seem important which side performs the layout |
| 593 | // transition, but it must not be performed twice. We'll arbitrarily |
| 594 | // choose to perform it as part of the acquire operation. |
| 595 | if (IsReleaseOp(device_data, cb_state, mem_barrier)) { |
| 596 | continue; |
| 597 | } |
| 598 | |
Mark Lobodzinski | 903e5ff | 2017-03-23 09:43:35 -0600 | [diff] [blame] | 599 | VkImageCreateInfo *image_create_info = &(GetImageState(device_data, mem_barrier->image)->createInfo); |
| 600 | uint32_t level_count = ResolveRemainingLevels(&mem_barrier->subresourceRange, image_create_info->mipLevels); |
| 601 | uint32_t layer_count = ResolveRemainingLayers(&mem_barrier->subresourceRange, image_create_info->arrayLayers); |
| 602 | |
Dave Houlton | b3f4b28 | 2018-02-22 16:25:16 -0700 | [diff] [blame] | 603 | // Special case for 3D images with VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT_KHR flag bit, where <extent.depth> and |
| 604 | // <arrayLayers> can potentially alias. When recording layout for the entire image, pre-emptively record layouts |
| 605 | // for all (potential) layer sub_resources. |
| 606 | if ((0 != (image_create_info->flags & VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT_KHR)) && |
| 607 | (mem_barrier->subresourceRange.baseArrayLayer == 0) && (layer_count == 1)) { |
| 608 | layer_count = image_create_info->extent.depth; // Treat each depth slice as a layer subresource |
| 609 | } |
| 610 | |
Mark Lobodzinski | 903e5ff | 2017-03-23 09:43:35 -0600 | [diff] [blame] | 611 | for (uint32_t j = 0; j < level_count; j++) { |
Mark Lobodzinski | 6b6c50a | 2017-02-27 12:56:14 -0700 | [diff] [blame] | 612 | uint32_t level = mem_barrier->subresourceRange.baseMipLevel + j; |
Mark Lobodzinski | 903e5ff | 2017-03-23 09:43:35 -0600 | [diff] [blame] | 613 | for (uint32_t k = 0; k < layer_count; k++) { |
Mark Lobodzinski | 6b6c50a | 2017-02-27 12:56:14 -0700 | [diff] [blame] | 614 | uint32_t layer = mem_barrier->subresourceRange.baseArrayLayer + k; |
Chris Forbes | 399a678 | 2017-08-18 15:00:48 -0700 | [diff] [blame] | 615 | TransitionImageAspectLayout(device_data, cb_state, mem_barrier, level, layer, VK_IMAGE_ASPECT_COLOR_BIT); |
| 616 | TransitionImageAspectLayout(device_data, cb_state, mem_barrier, level, layer, VK_IMAGE_ASPECT_DEPTH_BIT); |
| 617 | TransitionImageAspectLayout(device_data, cb_state, mem_barrier, level, layer, VK_IMAGE_ASPECT_STENCIL_BIT); |
| 618 | TransitionImageAspectLayout(device_data, cb_state, mem_barrier, level, layer, VK_IMAGE_ASPECT_METADATA_BIT); |
Dave Houlton | b3f4b28 | 2018-02-22 16:25:16 -0700 | [diff] [blame] | 619 | if (GetDeviceExtensions(device_data)->vk_khr_sampler_ycbcr_conversion) { |
Chris Forbes | 399a678 | 2017-08-18 15:00:48 -0700 | [diff] [blame] | 620 | TransitionImageAspectLayout(device_data, cb_state, mem_barrier, level, layer, VK_IMAGE_ASPECT_PLANE_0_BIT_KHR); |
| 621 | TransitionImageAspectLayout(device_data, cb_state, mem_barrier, level, layer, VK_IMAGE_ASPECT_PLANE_1_BIT_KHR); |
| 622 | TransitionImageAspectLayout(device_data, cb_state, mem_barrier, level, layer, VK_IMAGE_ASPECT_PLANE_2_BIT_KHR); |
Dave Houlton | b3f4b28 | 2018-02-22 16:25:16 -0700 | [diff] [blame] | 623 | } |
Mark Lobodzinski | 6b6c50a | 2017-02-27 12:56:14 -0700 | [diff] [blame] | 624 | } |
| 625 | } |
| 626 | } |
| 627 | } |
| 628 | |
Tobin Ehlis | c826645 | 2017-04-07 12:20:30 -0600 | [diff] [blame] | 629 | 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] | 630 | VkImageSubresourceLayers subLayers, VkImageLayout explicit_layout, VkImageLayout optimal_layout, |
Tobin Ehlis | c826645 | 2017-04-07 12:20:30 -0600 | [diff] [blame] | 631 | const char *caller, UNIQUE_VALIDATION_ERROR_CODE msg_code, bool *error) { |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 632 | const auto report_data = core_validation::GetReportData(device_data); |
Tobin Ehlis | 2d85ec6 | 2017-03-14 15:38:48 -0600 | [diff] [blame] | 633 | const auto image = image_state->image; |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 634 | bool skip = false; |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 635 | |
| 636 | for (uint32_t i = 0; i < subLayers.layerCount; ++i) { |
| 637 | uint32_t layer = i + subLayers.baseArrayLayer; |
| 638 | VkImageSubresource sub = {subLayers.aspectMask, subLayers.mipLevel, layer}; |
| 639 | IMAGE_CMD_BUF_LAYOUT_NODE node; |
Tobin Ehlis | e35b66a | 2017-03-15 12:18:31 -0600 | [diff] [blame] | 640 | if (FindCmdBufLayout(device_data, cb_node, image, sub, node)) { |
| 641 | if (node.layout != explicit_layout) { |
Tobin Ehlis | c826645 | 2017-04-07 12:20:30 -0600 | [diff] [blame] | 642 | *error = true; |
Tobin Ehlis | e35b66a | 2017-03-15 12:18:31 -0600 | [diff] [blame] | 643 | // TODO: Improve log message in the next pass |
Petr Kraus | 13c98a6 | 2017-12-09 00:22:39 +0100 | [diff] [blame] | 644 | skip |= log_msg( |
| 645 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 646 | HandleToUint64(cb_node->commandBuffer), DRAWSTATE_INVALID_IMAGE_LAYOUT, |
Petr Kraus | 13c98a6 | 2017-12-09 00:22:39 +0100 | [diff] [blame] | 647 | "%s: Cannot use image 0x%" PRIx64 " with specific layout %s that doesn't match the actual current layout %s.", |
| 648 | caller, HandleToUint64(image), string_VkImageLayout(explicit_layout), string_VkImageLayout(node.layout)); |
Tobin Ehlis | e35b66a | 2017-03-15 12:18:31 -0600 | [diff] [blame] | 649 | } |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 650 | } |
| 651 | } |
Tobin Ehlis | 2d85ec6 | 2017-03-14 15:38:48 -0600 | [diff] [blame] | 652 | // If optimal_layout is not UNDEFINED, check that layout matches optimal for this case |
| 653 | if ((VK_IMAGE_LAYOUT_UNDEFINED != optimal_layout) && (explicit_layout != optimal_layout)) { |
| 654 | if (VK_IMAGE_LAYOUT_GENERAL == explicit_layout) { |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 655 | if (image_state->createInfo.tiling != VK_IMAGE_TILING_LINEAR) { |
| 656 | // 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] | 657 | skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 658 | VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, HandleToUint64(cb_node->commandBuffer), |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 659 | DRAWSTATE_INVALID_IMAGE_LAYOUT, |
Petr Kraus | 13c98a6 | 2017-12-09 00:22:39 +0100 | [diff] [blame] | 660 | "%s: For optimal performance image 0x%" PRIx64 " layout should be %s instead of GENERAL.", caller, |
| 661 | HandleToUint64(image), string_VkImageLayout(optimal_layout)); |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 662 | } |
Mark Lobodzinski | 28426ae | 2017-06-01 07:56:38 -0600 | [diff] [blame] | 663 | } else if (GetDeviceExtensions(device_data)->vk_khr_shared_presentable_image) { |
Mark Lobodzinski | 087380c | 2017-05-16 14:42:25 -0600 | [diff] [blame] | 664 | if (image_state->shared_presentable) { |
| 665 | if (VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR != explicit_layout) { |
| 666 | // TODO: Add unique error id when available. |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 667 | skip |= |
| 668 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, msg_code, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 669 | "Layout for shared presentable image is %s but must be VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR.", |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 670 | string_VkImageLayout(optimal_layout)); |
Mark Lobodzinski | 087380c | 2017-05-16 14:42:25 -0600 | [diff] [blame] | 671 | } |
Tobin Ehlis | bb03e5f | 2017-05-11 08:52:51 -0600 | [diff] [blame] | 672 | } |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 673 | } else { |
Tobin Ehlis | c826645 | 2017-04-07 12:20:30 -0600 | [diff] [blame] | 674 | *error = true; |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 675 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 676 | HandleToUint64(cb_node->commandBuffer), msg_code, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 677 | "%s: Layout for image 0x%" PRIx64 " is %s but can only be %s or VK_IMAGE_LAYOUT_GENERAL.", caller, |
| 678 | HandleToUint64(image), string_VkImageLayout(explicit_layout), string_VkImageLayout(optimal_layout)); |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 679 | } |
| 680 | } |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 681 | return skip; |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 682 | } |
| 683 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 684 | void TransitionFinalSubpassLayouts(layer_data *device_data, GLOBAL_CB_NODE *pCB, const VkRenderPassBeginInfo *pRenderPassBegin, |
| 685 | FRAMEBUFFER_STATE *framebuffer_state) { |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 686 | auto renderPass = GetRenderPassState(device_data, pRenderPassBegin->renderPass); |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 687 | if (!renderPass) return; |
| 688 | |
| 689 | const VkRenderPassCreateInfo *pRenderPassInfo = renderPass->createInfo.ptr(); |
| 690 | if (framebuffer_state) { |
| 691 | for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) { |
| 692 | auto image_view = framebuffer_state->createInfo.pAttachments[i]; |
| 693 | SetImageViewLayout(device_data, pCB, image_view, pRenderPassInfo->pAttachments[i].finalLayout); |
| 694 | } |
| 695 | } |
| 696 | } |
Dave Houlton | e19e20d | 2018-02-02 16:32:41 -0700 | [diff] [blame] | 697 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 698 | bool PreCallValidateCreateImage(layer_data *device_data, const VkImageCreateInfo *pCreateInfo, |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 699 | const VkAllocationCallbacks *pAllocator, VkImage *pImage) { |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 700 | bool skip = false; |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 701 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 702 | |
Jeremy Hayes | 96dcd81 | 2017-03-14 14:04:19 -0600 | [diff] [blame] | 703 | if (pCreateInfo->format == VK_FORMAT_UNDEFINED) { |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 704 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 705 | VALIDATION_ERROR_09e0075e, "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED."); |
Jeremy Hayes | 96dcd81 | 2017-03-14 14:04:19 -0600 | [diff] [blame] | 706 | |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 707 | return skip; |
Jeremy Hayes | 96dcd81 | 2017-03-14 14:04:19 -0600 | [diff] [blame] | 708 | } |
| 709 | |
Dave Houlton | 130c021 | 2018-01-29 13:39:56 -0700 | [diff] [blame] | 710 | bool optimal_tiling = (VK_IMAGE_TILING_OPTIMAL == pCreateInfo->tiling); |
| 711 | const char *tiling_string = string_VkImageTiling(pCreateInfo->tiling); |
| 712 | const char *format_string = string_VkFormat(pCreateInfo->format); |
Jeremy Kniager | 7ec550f | 2017-08-16 14:57:42 -0600 | [diff] [blame] | 713 | VkFormatProperties properties = GetFormatProperties(device_data, pCreateInfo->format); |
Dave Houlton | 130c021 | 2018-01-29 13:39:56 -0700 | [diff] [blame] | 714 | VkFormatFeatureFlags features = (optimal_tiling ? properties.optimalTilingFeatures : properties.linearTilingFeatures); |
Jeremy Hayes | 96dcd81 | 2017-03-14 14:04:19 -0600 | [diff] [blame] | 715 | |
Dave Houlton | 130c021 | 2018-01-29 13:39:56 -0700 | [diff] [blame] | 716 | if (0 == features) { |
Jeremy Hayes | 96dcd81 | 2017-03-14 14:04:19 -0600 | [diff] [blame] | 717 | std::stringstream ss; |
Dave Houlton | 130c021 | 2018-01-29 13:39:56 -0700 | [diff] [blame] | 718 | UNIQUE_VALIDATION_ERROR_CODE vuid = (optimal_tiling ? VALIDATION_ERROR_09e007ac : VALIDATION_ERROR_09e007a2); |
| 719 | ss << "vkCreateImage format parameter " << format_string << " is an unsupported format"; |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 720 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, vuid, "%s.", |
| 721 | ss.str().c_str()); |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 722 | return skip; |
Jeremy Hayes | 96dcd81 | 2017-03-14 14:04:19 -0600 | [diff] [blame] | 723 | } |
| 724 | |
Lenny Komow | b79f04a | 2017-09-18 17:07:00 -0600 | [diff] [blame] | 725 | // TODO: Add checks for EXTENDED_USAGE images to validate images are compatible |
Dave Houlton | bd2e262 | 2018-04-10 16:41:14 -0600 | [diff] [blame] | 726 | // For EXTENDED_USAGE images, any usage bit set for any format compatible with image format becomes legal |
| 727 | // For now we'll just avoid the usage bit checks for EXTENDED_USAGE images, pending an implementation of |
| 728 | // an exhaustive search of compatible formats |
Lenny Komow | b79f04a | 2017-09-18 17:07:00 -0600 | [diff] [blame] | 729 | if (!GetDeviceExtensions(device_data)->vk_khr_maintenance2 || !(pCreateInfo->flags & VK_IMAGE_CREATE_EXTENDED_USAGE_BIT_KHR)) { |
Dave Houlton | bd2e262 | 2018-04-10 16:41:14 -0600 | [diff] [blame] | 730 | if ((pCreateInfo->usage & VK_IMAGE_USAGE_SAMPLED_BIT) && !(features & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) { |
| 731 | std::stringstream ss; |
| 732 | UNIQUE_VALIDATION_ERROR_CODE vuid = (optimal_tiling ? VALIDATION_ERROR_09e007ae : VALIDATION_ERROR_09e007a4); |
| 733 | ss << "vkCreateImage: usage bit VK_IMAGE_USAGE_SAMPLED_BIT is not supported for format " << format_string |
| 734 | << " with tiling " << tiling_string; |
| 735 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, vuid, "%s.", |
| 736 | ss.str().c_str()); |
| 737 | } |
| 738 | |
| 739 | if ((pCreateInfo->usage & VK_IMAGE_USAGE_STORAGE_BIT) && !(features & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT)) { |
| 740 | std::stringstream ss; |
| 741 | UNIQUE_VALIDATION_ERROR_CODE vuid = (optimal_tiling ? VALIDATION_ERROR_09e007b0 : VALIDATION_ERROR_09e007a6); |
| 742 | ss << "vkCreateImage: usage bit VK_IMAGE_USAGE_STORAGE_BIT is not supported for format " << format_string |
| 743 | << " with tiling " << tiling_string; |
| 744 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, vuid, "%s.", |
| 745 | ss.str().c_str()); |
| 746 | } |
| 747 | |
Lenny Komow | b79f04a | 2017-09-18 17:07:00 -0600 | [diff] [blame] | 748 | // Validate that format supports usage as color attachment |
Dave Houlton | 130c021 | 2018-01-29 13:39:56 -0700 | [diff] [blame] | 749 | if ((pCreateInfo->usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) && |
| 750 | (0 == (features & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT))) { |
| 751 | UNIQUE_VALIDATION_ERROR_CODE vuid = (optimal_tiling ? VALIDATION_ERROR_09e007b2 : VALIDATION_ERROR_09e007a8); |
| 752 | std::stringstream ss; |
| 753 | ss << "vkCreateImage: usage bit VK_IMAGE_USAGE_COLOR_ATTACHMENT is not supported for format " << format_string |
| 754 | << " with tiling " << tiling_string; |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 755 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, vuid, "%s.", |
| 756 | ss.str().c_str()); |
Jeremy Hayes | 96dcd81 | 2017-03-14 14:04:19 -0600 | [diff] [blame] | 757 | } |
Jeremy Hayes | 96dcd81 | 2017-03-14 14:04:19 -0600 | [diff] [blame] | 758 | |
Lenny Komow | b79f04a | 2017-09-18 17:07:00 -0600 | [diff] [blame] | 759 | // Validate that format supports usage as depth/stencil attachment |
Dave Houlton | 130c021 | 2018-01-29 13:39:56 -0700 | [diff] [blame] | 760 | if ((pCreateInfo->usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) && |
| 761 | (0 == (features & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT))) { |
| 762 | UNIQUE_VALIDATION_ERROR_CODE vuid = (optimal_tiling ? VALIDATION_ERROR_09e007b4 : VALIDATION_ERROR_09e007aa); |
| 763 | std::stringstream ss; |
| 764 | ss << "vkCreateImage: usage bit VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT is not supported for format " << format_string |
| 765 | << " with tiling " << tiling_string; |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 766 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, vuid, "%s.", |
| 767 | ss.str().c_str()); |
Dave Houlton | 130c021 | 2018-01-29 13:39:56 -0700 | [diff] [blame] | 768 | } |
| 769 | } |
| 770 | |
| 771 | if ((pCreateInfo->flags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT) && (VK_IMAGE_TYPE_2D != pCreateInfo->imageType)) { |
| 772 | std::stringstream ss; |
| 773 | ss << "vkCreateImage: Image type must be VK_IMAGE_TYPE_2D when VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT flag bit is set"; |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 774 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 775 | VALIDATION_ERROR_09e0076a, "%s.", ss.str().c_str()); |
Dave Houlton | 130c021 | 2018-01-29 13:39:56 -0700 | [diff] [blame] | 776 | } |
| 777 | |
| 778 | const VkPhysicalDeviceLimits *device_limits = &(GetPhysicalDeviceProperties(device_data)->limits); |
| 779 | VkImageFormatProperties format_limits; // Format limits may exceed general device limits |
| 780 | VkResult err = GetImageFormatProperties(device_data, pCreateInfo, &format_limits); |
| 781 | if (VK_SUCCESS != err) { |
| 782 | std::stringstream ss; |
| 783 | ss << "vkCreateImage: The combination of format, type, tiling, usage and flags supplied in the VkImageCreateInfo struct is " |
| 784 | "reported by vkGetPhysicalDeviceImageFormatProperties() as unsupported"; |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 785 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 786 | VALIDATION_ERROR_09e00758, "%s.", ss.str().c_str()); |
Dave Houlton | 130c021 | 2018-01-29 13:39:56 -0700 | [diff] [blame] | 787 | return skip; |
| 788 | } |
| 789 | |
| 790 | if ((VK_IMAGE_TYPE_1D == pCreateInfo->imageType) && |
| 791 | (pCreateInfo->extent.width > std::max(device_limits->maxImageDimension1D, format_limits.maxExtent.width))) { |
| 792 | std::stringstream ss; |
| 793 | ss << "vkCreateImage: 1D image width exceeds maximum supported width for format " << format_string; |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 794 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 795 | VALIDATION_ERROR_09e0076e, "%s.", ss.str().c_str()); |
Dave Houlton | 130c021 | 2018-01-29 13:39:56 -0700 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | if (VK_IMAGE_TYPE_2D == pCreateInfo->imageType) { |
| 799 | if (0 == (pCreateInfo->flags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT)) { |
| 800 | if (pCreateInfo->extent.width > std::max(device_limits->maxImageDimension2D, format_limits.maxExtent.width) || |
| 801 | pCreateInfo->extent.height > std::max(device_limits->maxImageDimension2D, format_limits.maxExtent.height)) { |
Lenny Komow | b79f04a | 2017-09-18 17:07:00 -0600 | [diff] [blame] | 802 | std::stringstream ss; |
Dave Houlton | 130c021 | 2018-01-29 13:39:56 -0700 | [diff] [blame] | 803 | ss << "vkCreateImage: 2D image extent exceeds maximum supported width or height for format " << format_string; |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 804 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 805 | VALIDATION_ERROR_09e00770, "%s.", ss.str().c_str()); |
Lenny Komow | b79f04a | 2017-09-18 17:07:00 -0600 | [diff] [blame] | 806 | } |
Dave Houlton | 130c021 | 2018-01-29 13:39:56 -0700 | [diff] [blame] | 807 | } else { |
| 808 | if (pCreateInfo->extent.width > std::max(device_limits->maxImageDimensionCube, format_limits.maxExtent.width) || |
| 809 | pCreateInfo->extent.height > std::max(device_limits->maxImageDimensionCube, format_limits.maxExtent.height)) { |
Lenny Komow | b79f04a | 2017-09-18 17:07:00 -0600 | [diff] [blame] | 810 | std::stringstream ss; |
Dave Houlton | 130c021 | 2018-01-29 13:39:56 -0700 | [diff] [blame] | 811 | ss << "vkCreateImage: 2D image extent exceeds maximum supported width or height for cube-compatible images with " |
| 812 | "format " |
| 813 | << format_string; |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 814 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 815 | VALIDATION_ERROR_09e00772, "%s.", ss.str().c_str()); |
Lenny Komow | b79f04a | 2017-09-18 17:07:00 -0600 | [diff] [blame] | 816 | } |
Jeremy Hayes | 96dcd81 | 2017-03-14 14:04:19 -0600 | [diff] [blame] | 817 | } |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 818 | } |
| 819 | |
Dave Houlton | 130c021 | 2018-01-29 13:39:56 -0700 | [diff] [blame] | 820 | if (VK_IMAGE_TYPE_3D == pCreateInfo->imageType) { |
| 821 | if ((pCreateInfo->extent.width > std::max(device_limits->maxImageDimension3D, format_limits.maxExtent.width)) || |
| 822 | (pCreateInfo->extent.height > std::max(device_limits->maxImageDimension3D, format_limits.maxExtent.height)) || |
| 823 | (pCreateInfo->extent.depth > std::max(device_limits->maxImageDimension3D, format_limits.maxExtent.depth))) { |
| 824 | std::stringstream ss; |
| 825 | ss << "vkCreateImage: 3D image extent exceeds maximum supported width, height, or depth for format " << format_string; |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 826 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 827 | VALIDATION_ERROR_09e00776, "%s.", ss.str().c_str()); |
Dave Houlton | 130c021 | 2018-01-29 13:39:56 -0700 | [diff] [blame] | 828 | } |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 829 | } |
| 830 | |
Dave Houlton | 130c021 | 2018-01-29 13:39:56 -0700 | [diff] [blame] | 831 | // NOTE: As of 1/30/2018 the spec VU language is as in the commented code below. I believe this is an |
Dave Houlton | e19e20d | 2018-02-02 16:32:41 -0700 | [diff] [blame] | 832 | // error in the spec, and have submitted Gitlab Vulkan issue #1151 to have it changed to match the |
Dave Houlton | 130c021 | 2018-01-29 13:39:56 -0700 | [diff] [blame] | 833 | // implementation shown. DJH |
| 834 | // |
| 835 | // if ((pCreateInfo->mipLevels > format_limits.maxMipLevels) && |
| 836 | // (std::max({ pCreateInfo->extent.width, pCreateInfo->extent.height, pCreateInfo->extent.depth }) > |
| 837 | // device_limits->maxImageDimension3D)) { |
| 838 | if (pCreateInfo->mipLevels > format_limits.maxMipLevels) { |
| 839 | std::stringstream ss; |
| 840 | ss << "vkCreateImage: Image mip levels exceed image format maxMipLevels for format " << format_string; |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 841 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 842 | VALIDATION_ERROR_09e0077e, "%s.", ss.str().c_str()); |
Dave Houlton | 130c021 | 2018-01-29 13:39:56 -0700 | [diff] [blame] | 843 | } |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 844 | |
Dave Houlton | 130c021 | 2018-01-29 13:39:56 -0700 | [diff] [blame] | 845 | VkImageUsageFlags attach_flags = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 846 | VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT; |
| 847 | if ((pCreateInfo->usage & attach_flags) && (pCreateInfo->extent.width > device_limits->maxFramebufferWidth)) { |
| 848 | std::stringstream ss; |
| 849 | ss << "vkCreateImage: Image usage flags include a frame buffer attachment bit and image width exceeds device " |
| 850 | "maxFramebufferWidth"; |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 851 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 852 | VALIDATION_ERROR_09e00788, "%s.", ss.str().c_str()); |
Dave Houlton | 130c021 | 2018-01-29 13:39:56 -0700 | [diff] [blame] | 853 | } |
| 854 | |
| 855 | if ((pCreateInfo->usage & attach_flags) && (pCreateInfo->extent.height > device_limits->maxFramebufferHeight)) { |
| 856 | std::stringstream ss; |
| 857 | ss << "vkCreateImage: Image usage flags include a frame buffer attachment bit and image height exceeds device " |
| 858 | "maxFramebufferHeight"; |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 859 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 860 | VALIDATION_ERROR_09e0078a, "%s.", ss.str().c_str()); |
Dave Houlton | 130c021 | 2018-01-29 13:39:56 -0700 | [diff] [blame] | 861 | } |
| 862 | |
| 863 | uint64_t total_size = (uint64_t)pCreateInfo->extent.width * (uint64_t)pCreateInfo->extent.height * |
| 864 | (uint64_t)pCreateInfo->extent.depth * (uint64_t)pCreateInfo->arrayLayers * |
| 865 | (uint64_t)pCreateInfo->samples * (uint64_t)FormatSize(pCreateInfo->format); |
| 866 | |
| 867 | // Round up to imageGranularity boundary |
| 868 | VkDeviceSize imageGranularity = GetPhysicalDeviceProperties(device_data)->limits.bufferImageGranularity; |
| 869 | uint64_t ig_mask = imageGranularity - 1; |
| 870 | total_size = (total_size + ig_mask) & ~ig_mask; |
| 871 | |
| 872 | if (total_size > format_limits.maxResourceSize) { |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 873 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 874 | IMAGE_INVALID_FORMAT_LIMITS_VIOLATION, |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 875 | "CreateImage resource size exceeds allowable maximum Image resource size = 0x%" PRIxLEAST64 |
| 876 | ", maximum resource size = 0x%" PRIxLEAST64 " ", |
Dave Houlton | 130c021 | 2018-01-29 13:39:56 -0700 | [diff] [blame] | 877 | total_size, format_limits.maxResourceSize); |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 878 | } |
| 879 | |
Dave Houlton | 130c021 | 2018-01-29 13:39:56 -0700 | [diff] [blame] | 880 | if (pCreateInfo->arrayLayers > format_limits.maxArrayLayers) { |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 881 | skip |= |
| 882 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, VALIDATION_ERROR_09e00780, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 883 | "CreateImage arrayLayers=%d exceeds allowable maximum supported by format of %d.", pCreateInfo->arrayLayers, |
| 884 | format_limits.maxArrayLayers); |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 885 | } |
| 886 | |
Dave Houlton | 130c021 | 2018-01-29 13:39:56 -0700 | [diff] [blame] | 887 | if ((pCreateInfo->samples & format_limits.sampleCounts) == 0) { |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 888 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 889 | VALIDATION_ERROR_09e0078e, "CreateImage samples %s is not supported by format 0x%.8X.", |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 890 | string_VkSampleCountFlagBits(pCreateInfo->samples), format_limits.sampleCounts); |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 891 | } |
| 892 | |
Mark Lobodzinski | 035a4cf | 2017-03-13 09:45:07 -0600 | [diff] [blame] | 893 | if ((pCreateInfo->flags & VK_IMAGE_CREATE_SPARSE_ALIASED_BIT) && (!GetEnabledFeatures(device_data)->sparseResidencyAliased)) { |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 894 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 895 | DRAWSTATE_INVALID_FEATURE, |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 896 | "vkCreateImage(): the sparseResidencyAliased device feature is disabled: Images cannot be created with the " |
| 897 | "VK_IMAGE_CREATE_SPARSE_ALIASED_BIT set."); |
Mark Lobodzinski | 035a4cf | 2017-03-13 09:45:07 -0600 | [diff] [blame] | 898 | } |
| 899 | |
Lenny Komow | b79f04a | 2017-09-18 17:07:00 -0600 | [diff] [blame] | 900 | if (GetDeviceExtensions(device_data)->vk_khr_maintenance2) { |
| 901 | if (pCreateInfo->flags & VK_IMAGE_CREATE_BLOCK_TEXEL_VIEW_COMPATIBLE_BIT_KHR) { |
| 902 | if (!(FormatIsCompressed_BC(pCreateInfo->format) || FormatIsCompressed_ASTC_LDR(pCreateInfo->format) || |
| 903 | FormatIsCompressed_ETC2_EAC(pCreateInfo->format))) { |
| 904 | // TODO: Add Maintenance2 VUID |
| 905 | skip |= |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 906 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 907 | VALIDATION_ERROR_UNDEFINED, |
Lenny Komow | b79f04a | 2017-09-18 17:07:00 -0600 | [diff] [blame] | 908 | "vkCreateImage(): If pCreateInfo->flags contains VK_IMAGE_CREATE_BLOCK_TEXEL_VIEW_COMPATIBLE_BIT_KHR, " |
| 909 | "format must be block, ETC or ASTC compressed, but is %s", |
| 910 | string_VkFormat(pCreateInfo->format)); |
| 911 | } |
| 912 | if (!(pCreateInfo->flags & VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT)) { |
| 913 | // TODO: Add Maintenance2 VUID |
| 914 | skip |= |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 915 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 916 | VALIDATION_ERROR_UNDEFINED, |
Lenny Komow | b79f04a | 2017-09-18 17:07:00 -0600 | [diff] [blame] | 917 | "vkCreateImage(): If pCreateInfo->flags contains VK_IMAGE_CREATE_BLOCK_TEXEL_VIEW_COMPATIBLE_BIT_KHR, " |
| 918 | "flags must also contain VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT."); |
| 919 | } |
| 920 | } |
| 921 | } |
| 922 | |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 923 | return skip; |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 924 | } |
| 925 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 926 | void PostCallRecordCreateImage(layer_data *device_data, const VkImageCreateInfo *pCreateInfo, VkImage *pImage) { |
Mark Lobodzinski | 42fe5f7 | 2017-01-11 11:36:16 -0700 | [diff] [blame] | 927 | IMAGE_LAYOUT_NODE image_state; |
| 928 | image_state.layout = pCreateInfo->initialLayout; |
| 929 | image_state.format = pCreateInfo->format; |
Mark Lobodzinski | 214144a | 2017-01-27 14:25:32 -0700 | [diff] [blame] | 930 | 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] | 931 | ImageSubresourcePair subpair{*pImage, false, VkImageSubresource()}; |
Mark Lobodzinski | 214144a | 2017-01-27 14:25:32 -0700 | [diff] [blame] | 932 | (*core_validation::GetImageSubresourceMap(device_data))[*pImage].push_back(subpair); |
| 933 | (*core_validation::GetImageLayoutMap(device_data))[subpair] = image_state; |
Mark Lobodzinski | 42fe5f7 | 2017-01-11 11:36:16 -0700 | [diff] [blame] | 934 | } |
Mark Lobodzinski | 9ef5d56 | 2017-01-27 12:28:30 -0700 | [diff] [blame] | 935 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 936 | 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] | 937 | const CHECK_DISABLED *disabled = core_validation::GetDisables(device_data); |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 938 | *image_state = core_validation::GetImageState(device_data, image); |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 939 | *obj_struct = {HandleToUint64(image), kVulkanObjectTypeImage}; |
Mark Lobodzinski | 9ef5d56 | 2017-01-27 12:28:30 -0700 | [diff] [blame] | 940 | if (disabled->destroy_image) return false; |
| 941 | bool skip = false; |
| 942 | if (*image_state) { |
Mike Schuchardt | a502565 | 2017-09-27 14:56:21 -0600 | [diff] [blame] | 943 | skip |= core_validation::ValidateObjectNotInUse(device_data, *image_state, *obj_struct, "vkDestroyImage", |
| 944 | VALIDATION_ERROR_252007d0); |
Mark Lobodzinski | 9ef5d56 | 2017-01-27 12:28:30 -0700 | [diff] [blame] | 945 | } |
| 946 | return skip; |
| 947 | } |
| 948 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 949 | 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] | 950 | core_validation::invalidateCommandBuffers(device_data, image_state->cb_bindings, obj_struct); |
| 951 | // Clean up memory mapping, bindings and range references for image |
| 952 | for (auto mem_binding : image_state->GetBoundMemory()) { |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 953 | auto mem_info = core_validation::GetMemObjInfo(device_data, mem_binding); |
Mark Lobodzinski | 9ef5d56 | 2017-01-27 12:28:30 -0700 | [diff] [blame] | 954 | if (mem_info) { |
| 955 | core_validation::RemoveImageMemoryRange(obj_struct.handle, mem_info); |
| 956 | } |
| 957 | } |
Mark Lobodzinski | 3382637 | 2017-04-13 11:10:11 -0600 | [diff] [blame] | 958 | core_validation::ClearMemoryObjectBindings(device_data, obj_struct.handle, kVulkanObjectTypeImage); |
Mark Lobodzinski | 9ef5d56 | 2017-01-27 12:28:30 -0700 | [diff] [blame] | 959 | // Remove image from imageMap |
| 960 | core_validation::GetImageMap(device_data)->erase(image); |
| 961 | std::unordered_map<VkImage, std::vector<ImageSubresourcePair>> *imageSubresourceMap = |
| 962 | core_validation::GetImageSubresourceMap(device_data); |
| 963 | |
| 964 | const auto &sub_entry = imageSubresourceMap->find(image); |
| 965 | if (sub_entry != imageSubresourceMap->end()) { |
| 966 | for (const auto &pair : sub_entry->second) { |
| 967 | core_validation::GetImageLayoutMap(device_data)->erase(pair); |
| 968 | } |
| 969 | imageSubresourceMap->erase(sub_entry); |
| 970 | } |
| 971 | } |
Mark Lobodzinski | c409a58 | 2017-01-27 15:16:01 -0700 | [diff] [blame] | 972 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 973 | bool ValidateImageAttributes(layer_data *device_data, IMAGE_STATE *image_state, VkImageSubresourceRange range) { |
Mark Lobodzinski | c409a58 | 2017-01-27 15:16:01 -0700 | [diff] [blame] | 974 | bool skip = false; |
| 975 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 976 | |
| 977 | if (range.aspectMask != VK_IMAGE_ASPECT_COLOR_BIT) { |
| 978 | char const str[] = "vkCmdClearColorImage aspectMasks for all subresource ranges must be set to VK_IMAGE_ASPECT_COLOR_BIT"; |
| 979 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 980 | HandleToUint64(image_state->image), DRAWSTATE_INVALID_IMAGE_ASPECT, str); |
Mark Lobodzinski | c409a58 | 2017-01-27 15:16:01 -0700 | [diff] [blame] | 981 | } |
| 982 | |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 983 | if (FormatIsDepthOrStencil(image_state->createInfo.format)) { |
Mark Lobodzinski | c409a58 | 2017-01-27 15:16:01 -0700 | [diff] [blame] | 984 | char const str[] = "vkCmdClearColorImage called with depth/stencil image."; |
| 985 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 986 | HandleToUint64(image_state->image), VALIDATION_ERROR_1880000e, "%s.", str); |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 987 | } else if (FormatIsCompressed(image_state->createInfo.format)) { |
Mark Lobodzinski | c409a58 | 2017-01-27 15:16:01 -0700 | [diff] [blame] | 988 | char const str[] = "vkCmdClearColorImage called with compressed image."; |
| 989 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 990 | HandleToUint64(image_state->image), VALIDATION_ERROR_1880000e, "%s.", str); |
Mark Lobodzinski | c409a58 | 2017-01-27 15:16:01 -0700 | [diff] [blame] | 991 | } |
| 992 | |
| 993 | if (!(image_state->createInfo.usage & VK_IMAGE_USAGE_TRANSFER_DST_BIT)) { |
| 994 | char const str[] = "vkCmdClearColorImage called with image created without VK_IMAGE_USAGE_TRANSFER_DST_BIT."; |
| 995 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 996 | HandleToUint64(image_state->image), VALIDATION_ERROR_18800004, "%s.", str); |
Mark Lobodzinski | c409a58 | 2017-01-27 15:16:01 -0700 | [diff] [blame] | 997 | } |
| 998 | return skip; |
| 999 | } |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1000 | |
Mark Lobodzinski | 903e5ff | 2017-03-23 09:43:35 -0600 | [diff] [blame] | 1001 | uint32_t ResolveRemainingLevels(const VkImageSubresourceRange *range, uint32_t mip_levels) { |
| 1002 | // Return correct number of mip levels taking into account VK_REMAINING_MIP_LEVELS |
| 1003 | uint32_t mip_level_count = range->levelCount; |
Mark Lobodzinski | 9c93dbd | 2017-02-02 08:31:18 -0700 | [diff] [blame] | 1004 | if (range->levelCount == VK_REMAINING_MIP_LEVELS) { |
Mark Lobodzinski | 903e5ff | 2017-03-23 09:43:35 -0600 | [diff] [blame] | 1005 | mip_level_count = mip_levels - range->baseMipLevel; |
Mark Lobodzinski | 9c93dbd | 2017-02-02 08:31:18 -0700 | [diff] [blame] | 1006 | } |
Mark Lobodzinski | 903e5ff | 2017-03-23 09:43:35 -0600 | [diff] [blame] | 1007 | return mip_level_count; |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1008 | } |
| 1009 | |
Mark Lobodzinski | 903e5ff | 2017-03-23 09:43:35 -0600 | [diff] [blame] | 1010 | uint32_t ResolveRemainingLayers(const VkImageSubresourceRange *range, uint32_t layers) { |
| 1011 | // Return correct number of layers taking into account VK_REMAINING_ARRAY_LAYERS |
| 1012 | uint32_t array_layer_count = range->layerCount; |
| 1013 | if (range->layerCount == VK_REMAINING_ARRAY_LAYERS) { |
| 1014 | array_layer_count = layers - range->baseArrayLayer; |
Mark Lobodzinski | 9c93dbd | 2017-02-02 08:31:18 -0700 | [diff] [blame] | 1015 | } |
Mark Lobodzinski | 903e5ff | 2017-03-23 09:43:35 -0600 | [diff] [blame] | 1016 | return array_layer_count; |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1017 | } |
| 1018 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 1019 | 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] | 1020 | VkImageSubresourceRange range, VkImageLayout dest_image_layout, const char *func_name) { |
| 1021 | bool skip = false; |
| 1022 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 1023 | |
Mark Lobodzinski | 903e5ff | 2017-03-23 09:43:35 -0600 | [diff] [blame] | 1024 | uint32_t level_count = ResolveRemainingLevels(&range, image_state->createInfo.mipLevels); |
| 1025 | uint32_t layer_count = ResolveRemainingLayers(&range, image_state->createInfo.arrayLayers); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1026 | |
| 1027 | if (dest_image_layout != VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) { |
| 1028 | if (dest_image_layout == VK_IMAGE_LAYOUT_GENERAL) { |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1029 | if (image_state->createInfo.tiling != VK_IMAGE_TILING_LINEAR) { |
| 1030 | // 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] | 1031 | skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 1032 | HandleToUint64(image_state->image), DRAWSTATE_INVALID_IMAGE_LAYOUT, |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1033 | "%s: Layout for cleared image should be TRANSFER_DST_OPTIMAL instead of GENERAL.", func_name); |
| 1034 | } |
Mark Lobodzinski | 087380c | 2017-05-16 14:42:25 -0600 | [diff] [blame] | 1035 | } else if (VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR == dest_image_layout) { |
Mark Lobodzinski | 28426ae | 2017-06-01 07:56:38 -0600 | [diff] [blame] | 1036 | if (!GetDeviceExtensions(device_data)->vk_khr_shared_presentable_image) { |
Tobin Ehlis | fb0661c | 2017-05-11 08:52:51 -0600 | [diff] [blame] | 1037 | // TODO: Add unique error id when available. |
Mark Lobodzinski | 087380c | 2017-05-16 14:42:25 -0600 | [diff] [blame] | 1038 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 1039 | HandleToUint64(image_state->image), 0, |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 1040 | "Must enable VK_KHR_shared_presentable_image extension before creating images with a layout type " |
| 1041 | "of VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR."); |
Mark Lobodzinski | 087380c | 2017-05-16 14:42:25 -0600 | [diff] [blame] | 1042 | |
| 1043 | } else { |
| 1044 | if (image_state->shared_presentable) { |
| 1045 | skip |= log_msg( |
| 1046 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 1047 | HandleToUint64(image_state->image), 0, |
Mark Lobodzinski | 087380c | 2017-05-16 14:42:25 -0600 | [diff] [blame] | 1048 | "Layout for shared presentable cleared image is %s but can only be VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR.", |
| 1049 | string_VkImageLayout(dest_image_layout)); |
| 1050 | } |
Tobin Ehlis | bb03e5f | 2017-05-11 08:52:51 -0600 | [diff] [blame] | 1051 | } |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1052 | } else { |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1053 | UNIQUE_VALIDATION_ERROR_CODE error_code = VALIDATION_ERROR_1880000a; |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1054 | if (strcmp(func_name, "vkCmdClearDepthStencilImage()") == 0) { |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1055 | error_code = VALIDATION_ERROR_18a00018; |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1056 | } else { |
| 1057 | assert(strcmp(func_name, "vkCmdClearColorImage()") == 0); |
| 1058 | } |
Mark Lobodzinski | 0827aec | 2017-03-21 16:41:45 -0600 | [diff] [blame] | 1059 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 1060 | HandleToUint64(image_state->image), error_code, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 1061 | "%s: Layout for cleared image is %s but can only be TRANSFER_DST_OPTIMAL or GENERAL.", func_name, |
| 1062 | string_VkImageLayout(dest_image_layout)); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1063 | } |
| 1064 | } |
| 1065 | |
Mark Lobodzinski | 903e5ff | 2017-03-23 09:43:35 -0600 | [diff] [blame] | 1066 | for (uint32_t level_index = 0; level_index < level_count; ++level_index) { |
| 1067 | uint32_t level = level_index + range.baseMipLevel; |
| 1068 | for (uint32_t layer_index = 0; layer_index < layer_count; ++layer_index) { |
| 1069 | uint32_t layer = layer_index + range.baseArrayLayer; |
| 1070 | VkImageSubresource sub = {range.aspectMask, level, layer}; |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1071 | IMAGE_CMD_BUF_LAYOUT_NODE node; |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 1072 | if (FindCmdBufLayout(device_data, cb_node, image_state->image, sub, node)) { |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1073 | if (node.layout != dest_image_layout) { |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1074 | UNIQUE_VALIDATION_ERROR_CODE error_code = VALIDATION_ERROR_18800008; |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1075 | if (strcmp(func_name, "vkCmdClearDepthStencilImage()") == 0) { |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1076 | error_code = VALIDATION_ERROR_18a00016; |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1077 | } else { |
| 1078 | assert(strcmp(func_name, "vkCmdClearColorImage()") == 0); |
| 1079 | } |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 1080 | skip |= |
| 1081 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, |
| 1082 | error_code, "%s: Cannot clear an image whose layout is %s and doesn't match the current layout %s.", |
| 1083 | func_name, string_VkImageLayout(dest_image_layout), string_VkImageLayout(node.layout)); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1084 | } |
| 1085 | } |
| 1086 | } |
| 1087 | } |
| 1088 | |
| 1089 | return skip; |
| 1090 | } |
| 1091 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 1092 | void RecordClearImageLayout(layer_data *device_data, GLOBAL_CB_NODE *cb_node, VkImage image, VkImageSubresourceRange range, |
| 1093 | VkImageLayout dest_image_layout) { |
Mark Lobodzinski | 903e5ff | 2017-03-23 09:43:35 -0600 | [diff] [blame] | 1094 | VkImageCreateInfo *image_create_info = &(GetImageState(device_data, image)->createInfo); |
| 1095 | uint32_t level_count = ResolveRemainingLevels(&range, image_create_info->mipLevels); |
| 1096 | uint32_t layer_count = ResolveRemainingLayers(&range, image_create_info->arrayLayers); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1097 | |
Mark Lobodzinski | 903e5ff | 2017-03-23 09:43:35 -0600 | [diff] [blame] | 1098 | for (uint32_t level_index = 0; level_index < level_count; ++level_index) { |
| 1099 | uint32_t level = level_index + range.baseMipLevel; |
| 1100 | for (uint32_t layer_index = 0; layer_index < layer_count; ++layer_index) { |
| 1101 | uint32_t layer = layer_index + range.baseArrayLayer; |
| 1102 | VkImageSubresource sub = {range.aspectMask, level, layer}; |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1103 | IMAGE_CMD_BUF_LAYOUT_NODE node; |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 1104 | if (!FindCmdBufLayout(device_data, cb_node, image, sub, node)) { |
| 1105 | 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] | 1106 | } |
| 1107 | } |
| 1108 | } |
| 1109 | } |
| 1110 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 1111 | bool PreCallValidateCmdClearColorImage(layer_data *dev_data, VkCommandBuffer commandBuffer, VkImage image, |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1112 | VkImageLayout imageLayout, uint32_t rangeCount, const VkImageSubresourceRange *pRanges) { |
| 1113 | bool skip = false; |
| 1114 | // TODO : Verify memory is in VK_IMAGE_STATE_CLEAR state |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 1115 | auto cb_node = GetCBNode(dev_data, commandBuffer); |
| 1116 | auto image_state = GetImageState(dev_data, image); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1117 | if (cb_node && image_state) { |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1118 | skip |= ValidateMemoryIsBoundToImage(dev_data, image_state, "vkCmdClearColorImage()", VALIDATION_ERROR_18800006); |
Mike Schuchardt | 9c58240 | 2017-02-23 15:57:37 -0700 | [diff] [blame] | 1119 | 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] | 1120 | VALIDATION_ERROR_18802415); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1121 | skip |= ValidateCmd(dev_data, cb_node, CMD_CLEARCOLORIMAGE, "vkCmdClearColorImage()"); |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1122 | skip |= insideRenderPass(dev_data, cb_node, "vkCmdClearColorImage()", VALIDATION_ERROR_18800017); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1123 | for (uint32_t i = 0; i < rangeCount; ++i) { |
Petr Kraus | 4d71868 | 2017-05-18 03:38:41 +0200 | [diff] [blame] | 1124 | std::string param_name = "pRanges[" + std::to_string(i) + "]"; |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 1125 | skip |= ValidateCmdClearColorSubresourceRange(dev_data, image_state, pRanges[i], param_name.c_str()); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1126 | skip |= ValidateImageAttributes(dev_data, image_state, pRanges[i]); |
Mark Lobodzinski | 9c93dbd | 2017-02-02 08:31:18 -0700 | [diff] [blame] | 1127 | skip |= VerifyClearImageLayout(dev_data, cb_node, image_state, pRanges[i], imageLayout, "vkCmdClearColorImage()"); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1128 | } |
| 1129 | } |
| 1130 | return skip; |
| 1131 | } |
| 1132 | |
| 1133 | // This state recording routine is shared between ClearColorImage and ClearDepthStencilImage |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 1134 | void PreCallRecordCmdClearImage(layer_data *dev_data, VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, |
Chris Forbes | 38c2e79 | 2017-06-16 16:42:35 -0700 | [diff] [blame] | 1135 | uint32_t rangeCount, const VkImageSubresourceRange *pRanges) { |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 1136 | auto cb_node = GetCBNode(dev_data, commandBuffer); |
| 1137 | auto image_state = GetImageState(dev_data, image); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1138 | if (cb_node && image_state) { |
| 1139 | AddCommandBufferBindingImage(dev_data, cb_node, image_state); |
| 1140 | std::function<bool()> function = [=]() { |
| 1141 | SetImageMemoryValid(dev_data, image_state, true); |
| 1142 | return false; |
| 1143 | }; |
Tobin Ehlis | a17a529 | 2017-07-28 12:11:30 -0600 | [diff] [blame] | 1144 | cb_node->queue_submit_functions.push_back(function); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1145 | for (uint32_t i = 0; i < rangeCount; ++i) { |
| 1146 | RecordClearImageLayout(dev_data, cb_node, image, pRanges[i], imageLayout); |
| 1147 | } |
| 1148 | } |
| 1149 | } |
| 1150 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 1151 | bool PreCallValidateCmdClearDepthStencilImage(layer_data *device_data, VkCommandBuffer commandBuffer, VkImage image, |
| 1152 | VkImageLayout imageLayout, uint32_t rangeCount, |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1153 | const VkImageSubresourceRange *pRanges) { |
| 1154 | bool skip = false; |
Mark Lobodzinski | 1241a31 | 2017-02-01 10:57:21 -0700 | [diff] [blame] | 1155 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 1156 | |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1157 | // TODO : Verify memory is in VK_IMAGE_STATE_CLEAR state |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 1158 | auto cb_node = GetCBNode(device_data, commandBuffer); |
| 1159 | auto image_state = GetImageState(device_data, image); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1160 | if (cb_node && image_state) { |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1161 | skip |= ValidateMemoryIsBoundToImage(device_data, image_state, "vkCmdClearDepthStencilImage()", VALIDATION_ERROR_18a00014); |
Mike Schuchardt | 9c58240 | 2017-02-23 15:57:37 -0700 | [diff] [blame] | 1162 | skip |= ValidateCmdQueueFlags(device_data, cb_node, "vkCmdClearDepthStencilImage()", VK_QUEUE_GRAPHICS_BIT, |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1163 | VALIDATION_ERROR_18a02415); |
Mark Lobodzinski | 1241a31 | 2017-02-01 10:57:21 -0700 | [diff] [blame] | 1164 | skip |= ValidateCmd(device_data, cb_node, CMD_CLEARDEPTHSTENCILIMAGE, "vkCmdClearDepthStencilImage()"); |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1165 | skip |= insideRenderPass(device_data, cb_node, "vkCmdClearDepthStencilImage()", VALIDATION_ERROR_18a00017); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1166 | for (uint32_t i = 0; i < rangeCount; ++i) { |
Petr Kraus | 4d71868 | 2017-05-18 03:38:41 +0200 | [diff] [blame] | 1167 | std::string param_name = "pRanges[" + std::to_string(i) + "]"; |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 1168 | skip |= ValidateCmdClearDepthSubresourceRange(device_data, image_state, pRanges[i], param_name.c_str()); |
Mark Lobodzinski | 9c93dbd | 2017-02-02 08:31:18 -0700 | [diff] [blame] | 1169 | skip |= |
| 1170 | VerifyClearImageLayout(device_data, cb_node, image_state, pRanges[i], imageLayout, "vkCmdClearDepthStencilImage()"); |
Mark Lobodzinski | 1241a31 | 2017-02-01 10:57:21 -0700 | [diff] [blame] | 1171 | // Image aspect must be depth or stencil or both |
| 1172 | if (((pRanges[i].aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) != VK_IMAGE_ASPECT_DEPTH_BIT) && |
| 1173 | ((pRanges[i].aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) != VK_IMAGE_ASPECT_STENCIL_BIT)) { |
| 1174 | char const str[] = |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 1175 | "vkCmdClearDepthStencilImage aspectMasks for all subresource ranges must be set to VK_IMAGE_ASPECT_DEPTH_BIT " |
| 1176 | "and/or VK_IMAGE_ASPECT_STENCIL_BIT"; |
Mark Lobodzinski | 1241a31 | 2017-02-01 10:57:21 -0700 | [diff] [blame] | 1177 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 1178 | HandleToUint64(commandBuffer), DRAWSTATE_INVALID_IMAGE_ASPECT, str); |
Mark Lobodzinski | 1241a31 | 2017-02-01 10:57:21 -0700 | [diff] [blame] | 1179 | } |
| 1180 | } |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 1181 | if (image_state && !FormatIsDepthOrStencil(image_state->createInfo.format)) { |
Mark Lobodzinski | 1241a31 | 2017-02-01 10:57:21 -0700 | [diff] [blame] | 1182 | char const str[] = "vkCmdClearDepthStencilImage called without a depth/stencil image."; |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1183 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 1184 | HandleToUint64(image), VALIDATION_ERROR_18a0001c, "%s.", str); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1185 | } |
Tobin Ehlis | 4af8c24 | 2017-11-30 13:47:11 -0700 | [diff] [blame] | 1186 | if (VK_IMAGE_USAGE_TRANSFER_DST_BIT != (VK_IMAGE_USAGE_TRANSFER_DST_BIT & image_state->createInfo.usage)) { |
| 1187 | char const str[] = |
| 1188 | "vkCmdClearDepthStencilImage() called with an image that was not created with the VK_IMAGE_USAGE_TRANSFER_DST_BIT " |
| 1189 | "set."; |
| 1190 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 1191 | HandleToUint64(image), VALIDATION_ERROR_18a00012, "%s.", str); |
Tobin Ehlis | 4af8c24 | 2017-11-30 13:47:11 -0700 | [diff] [blame] | 1192 | } |
| 1193 | VkFormatProperties props = GetFormatProperties(device_data, image_state->createInfo.format); |
| 1194 | VkImageTiling tiling = image_state->createInfo.tiling; |
| 1195 | VkFormatFeatureFlags flags = (tiling == VK_IMAGE_TILING_LINEAR ? props.linearTilingFeatures : props.optimalTilingFeatures); |
| 1196 | if ((GetDeviceExtensions(device_data)->vk_khr_maintenance1) && |
| 1197 | (VK_FORMAT_FEATURE_TRANSFER_DST_BIT_KHR != (flags & VK_FORMAT_FEATURE_TRANSFER_DST_BIT_KHR))) { |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 1198 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 1199 | HandleToUint64(image), VALIDATION_ERROR_18a00010, |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 1200 | "vkCmdClearDepthStencilImage() called with an image of format %s and tiling %s that does not support " |
| 1201 | "VK_FORMAT_FEATURE_TRANSFER_DST_BIT_KHR.", |
| 1202 | string_VkFormat(image_state->createInfo.format), string_VkImageTiling(image_state->createInfo.tiling)); |
Tobin Ehlis | 4af8c24 | 2017-11-30 13:47:11 -0700 | [diff] [blame] | 1203 | } |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1204 | } |
| 1205 | return skip; |
| 1206 | } |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1207 | |
| 1208 | // Returns true if [x, xoffset] and [y, yoffset] overlap |
| 1209 | static bool RangesIntersect(int32_t start, uint32_t start_offset, int32_t end, uint32_t end_offset) { |
| 1210 | bool result = false; |
| 1211 | uint32_t intersection_min = std::max(static_cast<uint32_t>(start), static_cast<uint32_t>(end)); |
| 1212 | uint32_t intersection_max = std::min(static_cast<uint32_t>(start) + start_offset, static_cast<uint32_t>(end) + end_offset); |
| 1213 | |
| 1214 | if (intersection_max > intersection_min) { |
| 1215 | result = true; |
| 1216 | } |
| 1217 | return result; |
| 1218 | } |
| 1219 | |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 1220 | // Returns true if source area of first copy region intersects dest area of second region |
| 1221 | // It is assumed that these are copy regions within a single image (otherwise no possibility of collision) |
| 1222 | static bool RegionIntersects(const VkImageCopy *rgn0, const VkImageCopy *rgn1, VkImageType type, bool is_multiplane) { |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1223 | bool result = false; |
Dave Houlton | f521761 | 2018-02-02 16:18:52 -0700 | [diff] [blame] | 1224 | |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 1225 | // Separate planes within a multiplane image cannot intersect |
| 1226 | if (is_multiplane && (rgn0->srcSubresource.aspectMask != rgn1->dstSubresource.aspectMask)) { |
Dave Houlton | f521761 | 2018-02-02 16:18:52 -0700 | [diff] [blame] | 1227 | return result; |
| 1228 | } |
| 1229 | |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 1230 | if ((rgn0->srcSubresource.mipLevel == rgn1->dstSubresource.mipLevel) && |
| 1231 | (RangesIntersect(rgn0->srcSubresource.baseArrayLayer, rgn0->srcSubresource.layerCount, rgn1->dstSubresource.baseArrayLayer, |
| 1232 | rgn1->dstSubresource.layerCount))) { |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1233 | result = true; |
| 1234 | switch (type) { |
| 1235 | case VK_IMAGE_TYPE_3D: |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 1236 | result &= RangesIntersect(rgn0->srcOffset.z, rgn0->extent.depth, rgn1->dstOffset.z, rgn1->extent.depth); |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1237 | // Intentionally fall through to 2D case |
| 1238 | case VK_IMAGE_TYPE_2D: |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 1239 | result &= RangesIntersect(rgn0->srcOffset.y, rgn0->extent.height, rgn1->dstOffset.y, rgn1->extent.height); |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1240 | // Intentionally fall through to 1D case |
| 1241 | case VK_IMAGE_TYPE_1D: |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 1242 | result &= RangesIntersect(rgn0->srcOffset.x, rgn0->extent.width, rgn1->dstOffset.x, rgn1->extent.width); |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1243 | break; |
| 1244 | default: |
| 1245 | // Unrecognized or new IMAGE_TYPE enums will be caught in parameter_validation |
| 1246 | assert(false); |
| 1247 | } |
| 1248 | } |
| 1249 | return result; |
| 1250 | } |
| 1251 | |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 1252 | // Returns non-zero if offset and extent exceed image extents |
| 1253 | static const uint32_t x_bit = 1; |
| 1254 | static const uint32_t y_bit = 2; |
| 1255 | static const uint32_t z_bit = 4; |
Dave Houlton | 1150cf5 | 2017-04-27 14:38:11 -0600 | [diff] [blame] | 1256 | 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] | 1257 | uint32_t result = 0; |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1258 | // Extents/depths cannot be negative but checks left in for clarity |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 1259 | if ((offset->z + extent->depth > image_extent->depth) || (offset->z < 0) || |
| 1260 | ((offset->z + static_cast<int32_t>(extent->depth)) < 0)) { |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 1261 | result |= z_bit; |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 1262 | } |
| 1263 | if ((offset->y + extent->height > image_extent->height) || (offset->y < 0) || |
| 1264 | ((offset->y + static_cast<int32_t>(extent->height)) < 0)) { |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 1265 | result |= y_bit; |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 1266 | } |
| 1267 | if ((offset->x + extent->width > image_extent->width) || (offset->x < 0) || |
| 1268 | ((offset->x + static_cast<int32_t>(extent->width)) < 0)) { |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 1269 | result |= x_bit; |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1270 | } |
| 1271 | return result; |
| 1272 | } |
| 1273 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1274 | // Test if two VkExtent3D structs are equivalent |
| 1275 | static inline bool IsExtentEqual(const VkExtent3D *extent, const VkExtent3D *other_extent) { |
| 1276 | bool result = true; |
| 1277 | if ((extent->width != other_extent->width) || (extent->height != other_extent->height) || |
| 1278 | (extent->depth != other_extent->depth)) { |
| 1279 | result = false; |
| 1280 | } |
| 1281 | return result; |
| 1282 | } |
| 1283 | |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 1284 | // For image copies between compressed/uncompressed formats, the extent is provided in source image texels |
| 1285 | // Destination image texel extents must be adjusted by block size for the dest validation checks |
| 1286 | VkExtent3D GetAdjustedDestImageExtent(VkFormat src_format, VkFormat dst_format, VkExtent3D extent) { |
| 1287 | VkExtent3D adjusted_extent = extent; |
| 1288 | if ((FormatIsCompressed(src_format) && (!FormatIsCompressed(dst_format)))) { |
| 1289 | VkExtent3D block_size = FormatCompressedTexelBlockExtent(src_format); |
| 1290 | adjusted_extent.width /= block_size.width; |
| 1291 | adjusted_extent.height /= block_size.height; |
| 1292 | adjusted_extent.depth /= block_size.depth; |
| 1293 | } else if ((!FormatIsCompressed(src_format) && (FormatIsCompressed(dst_format)))) { |
| 1294 | VkExtent3D block_size = FormatCompressedTexelBlockExtent(dst_format); |
| 1295 | adjusted_extent.width *= block_size.width; |
| 1296 | adjusted_extent.height *= block_size.height; |
| 1297 | adjusted_extent.depth *= block_size.depth; |
| 1298 | } |
| 1299 | return adjusted_extent; |
| 1300 | } |
| 1301 | |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1302 | // 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] | 1303 | static inline VkExtent3D GetImageSubresourceExtent(const IMAGE_STATE *img, const VkImageSubresourceLayers *subresource) { |
| 1304 | const uint32_t mip = subresource->mipLevel; |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 1305 | |
| 1306 | // Return zero extent if mip level doesn't exist |
Dave Houlton | 1150cf5 | 2017-04-27 14:38:11 -0600 | [diff] [blame] | 1307 | if (mip >= img->createInfo.mipLevels) { |
| 1308 | return VkExtent3D{0, 0, 0}; |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 1309 | } |
Dave Houlton | 1150cf5 | 2017-04-27 14:38:11 -0600 | [diff] [blame] | 1310 | |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 1311 | // 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] | 1312 | VkExtent3D extent = img->createInfo.extent; |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 1313 | extent.width = (0 == extent.width ? 0 : std::max(1U, extent.width >> mip)); |
| 1314 | extent.height = (0 == extent.height ? 0 : std::max(1U, extent.height >> mip)); |
| 1315 | extent.depth = (0 == extent.depth ? 0 : std::max(1U, extent.depth >> mip)); |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 1316 | |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1317 | // Image arrays have an effective z extent that isn't diminished by mip level |
| 1318 | if (VK_IMAGE_TYPE_3D != img->createInfo.imageType) { |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 1319 | extent.depth = img->createInfo.arrayLayers; |
| 1320 | } |
| 1321 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1322 | return extent; |
| 1323 | } |
| 1324 | |
| 1325 | // Test if the extent argument has all dimensions set to 0. |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 1326 | static inline bool IsExtentAllZeroes(const VkExtent3D *extent) { |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1327 | return ((extent->width == 0) && (extent->height == 0) && (extent->depth == 0)); |
| 1328 | } |
| 1329 | |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 1330 | // Test if the extent argument has any dimensions set to 0. |
| 1331 | static inline bool IsExtentSizeZero(const VkExtent3D *extent) { |
| 1332 | return ((extent->width == 0) || (extent->height == 0) || (extent->depth == 0)); |
| 1333 | } |
| 1334 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1335 | // Returns the image transfer granularity for a specific image scaled by compressed block size if necessary. |
| 1336 | static inline VkExtent3D GetScaledItg(layer_data *device_data, const GLOBAL_CB_NODE *cb_node, const IMAGE_STATE *img) { |
| 1337 | // Default to (0, 0, 0) granularity in case we can't find the real granularity for the physical device. |
| 1338 | VkExtent3D granularity = {0, 0, 0}; |
| 1339 | auto pPool = GetCommandPoolNode(device_data, cb_node->createInfo.commandPool); |
| 1340 | if (pPool) { |
| 1341 | granularity = |
| 1342 | GetPhysDevProperties(device_data)->queue_family_properties[pPool->queueFamilyIndex].minImageTransferGranularity; |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 1343 | if (FormatIsCompressed(img->createInfo.format)) { |
| 1344 | auto block_size = FormatCompressedTexelBlockExtent(img->createInfo.format); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1345 | granularity.width *= block_size.width; |
| 1346 | granularity.height *= block_size.height; |
| 1347 | } |
| 1348 | } |
| 1349 | return granularity; |
| 1350 | } |
| 1351 | |
| 1352 | // Test elements of a VkExtent3D structure against alignment constraints contained in another VkExtent3D structure |
| 1353 | static inline bool IsExtentAligned(const VkExtent3D *extent, const VkExtent3D *granularity) { |
| 1354 | bool valid = true; |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 1355 | if ((SafeModulo(extent->depth, granularity->depth) != 0) || (SafeModulo(extent->width, granularity->width) != 0) || |
| 1356 | (SafeModulo(extent->height, granularity->height) != 0)) { |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1357 | valid = false; |
| 1358 | } |
| 1359 | return valid; |
| 1360 | } |
| 1361 | |
| 1362 | // Check elements of a VkOffset3D structure against a queue family's Image Transfer Granularity values |
| 1363 | static inline bool CheckItgOffset(layer_data *device_data, const GLOBAL_CB_NODE *cb_node, const VkOffset3D *offset, |
| 1364 | const VkExtent3D *granularity, const uint32_t i, const char *function, const char *member) { |
| 1365 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 1366 | bool skip = false; |
| 1367 | VkExtent3D offset_extent = {}; |
| 1368 | offset_extent.width = static_cast<uint32_t>(abs(offset->x)); |
| 1369 | offset_extent.height = static_cast<uint32_t>(abs(offset->y)); |
| 1370 | offset_extent.depth = static_cast<uint32_t>(abs(offset->z)); |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 1371 | if (IsExtentAllZeroes(granularity)) { |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1372 | // 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] | 1373 | if (IsExtentAllZeroes(&offset_extent) == false) { |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 1374 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 1375 | HandleToUint64(cb_node->commandBuffer), DRAWSTATE_IMAGE_TRANSFER_GRANULARITY, |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 1376 | "%s: pRegion[%d].%s (x=%d, y=%d, z=%d) must be (x=0, y=0, z=0) when the command buffer's queue family " |
| 1377 | "image transfer granularity is (w=0, h=0, d=0).", |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 1378 | function, i, member, offset->x, offset->y, offset->z); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1379 | } |
| 1380 | } else { |
| 1381 | // If the queue family image transfer granularity is not (0, 0, 0), then the offset dimensions must always be even |
| 1382 | // integer multiples of the image transfer granularity. |
| 1383 | if (IsExtentAligned(&offset_extent, granularity) == false) { |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 1384 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 1385 | HandleToUint64(cb_node->commandBuffer), DRAWSTATE_IMAGE_TRANSFER_GRANULARITY, |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 1386 | "%s: pRegion[%d].%s (x=%d, y=%d, z=%d) dimensions must be even integer multiples of this command " |
| 1387 | "buffer's queue family image transfer granularity (w=%d, h=%d, d=%d).", |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 1388 | function, i, member, offset->x, offset->y, offset->z, granularity->width, granularity->height, |
| 1389 | granularity->depth); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1390 | } |
| 1391 | } |
| 1392 | return skip; |
| 1393 | } |
| 1394 | |
| 1395 | // Check elements of a VkExtent3D structure against a queue family's Image Transfer Granularity values |
| 1396 | static inline bool CheckItgExtent(layer_data *device_data, const GLOBAL_CB_NODE *cb_node, const VkExtent3D *extent, |
| 1397 | const VkOffset3D *offset, const VkExtent3D *granularity, const VkExtent3D *subresource_extent, |
Mark Lobodzinski | 283ade6 | 2017-10-09 16:36:49 -0600 | [diff] [blame] | 1398 | const VkImageType image_type, const uint32_t i, const char *function, const char *member) { |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1399 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 1400 | bool skip = false; |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 1401 | if (IsExtentAllZeroes(granularity)) { |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1402 | // If the queue family image transfer granularity is (0, 0, 0), then the extent must always match the image |
| 1403 | // subresource extent. |
| 1404 | if (IsExtentEqual(extent, subresource_extent) == false) { |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 1405 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 1406 | HandleToUint64(cb_node->commandBuffer), DRAWSTATE_IMAGE_TRANSFER_GRANULARITY, |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 1407 | "%s: pRegion[%d].%s (w=%d, h=%d, d=%d) must match the image subresource extents (w=%d, h=%d, d=%d) " |
| 1408 | "when the command buffer's queue family image transfer granularity is (w=0, h=0, d=0).", |
| 1409 | function, i, member, extent->width, extent->height, extent->depth, subresource_extent->width, |
| 1410 | subresource_extent->height, subresource_extent->depth); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1411 | } |
| 1412 | } else { |
| 1413 | // If the queue family image transfer granularity is not (0, 0, 0), then the extent dimensions must always be even |
| 1414 | // integer multiples of the image transfer granularity or the offset + extent dimensions must always match the image |
| 1415 | // subresource extent dimensions. |
| 1416 | VkExtent3D offset_extent_sum = {}; |
| 1417 | offset_extent_sum.width = static_cast<uint32_t>(abs(offset->x)) + extent->width; |
| 1418 | offset_extent_sum.height = static_cast<uint32_t>(abs(offset->y)) + extent->height; |
| 1419 | offset_extent_sum.depth = static_cast<uint32_t>(abs(offset->z)) + extent->depth; |
Mark Lobodzinski | 283ade6 | 2017-10-09 16:36:49 -0600 | [diff] [blame] | 1420 | bool x_ok = true; |
| 1421 | bool y_ok = true; |
| 1422 | bool z_ok = true; |
| 1423 | switch (image_type) { |
| 1424 | case VK_IMAGE_TYPE_3D: |
| 1425 | z_ok = ((0 == SafeModulo(extent->depth, granularity->depth)) || |
| 1426 | (subresource_extent->depth == offset_extent_sum.depth)); |
| 1427 | // Intentionally fall through to 2D case |
| 1428 | case VK_IMAGE_TYPE_2D: |
| 1429 | y_ok = ((0 == SafeModulo(extent->height, granularity->height)) || |
| 1430 | (subresource_extent->height == offset_extent_sum.height)); |
| 1431 | // Intentionally fall through to 1D case |
| 1432 | case VK_IMAGE_TYPE_1D: |
| 1433 | x_ok = ((0 == SafeModulo(extent->width, granularity->width)) || |
| 1434 | (subresource_extent->width == offset_extent_sum.width)); |
| 1435 | break; |
| 1436 | default: |
| 1437 | // Unrecognized or new IMAGE_TYPE enums will be caught in parameter_validation |
| 1438 | assert(false); |
| 1439 | } |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1440 | if (!(x_ok && y_ok && z_ok)) { |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 1441 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 1442 | HandleToUint64(cb_node->commandBuffer), DRAWSTATE_IMAGE_TRANSFER_GRANULARITY, |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 1443 | "%s: pRegion[%d].%s (w=%d, h=%d, d=%d) dimensions must be even integer multiples of this command " |
| 1444 | "buffer's queue family image transfer granularity (w=%d, h=%d, d=%d) or offset (x=%d, y=%d, z=%d) + " |
| 1445 | "extent (w=%d, h=%d, d=%d) must match the image subresource extents (w=%d, h=%d, d=%d).", |
| 1446 | function, i, member, extent->width, extent->height, extent->depth, granularity->width, |
| 1447 | granularity->height, granularity->depth, offset->x, offset->y, offset->z, extent->width, extent->height, |
| 1448 | extent->depth, subresource_extent->width, subresource_extent->height, subresource_extent->depth); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1449 | } |
| 1450 | } |
| 1451 | return skip; |
| 1452 | } |
| 1453 | |
Mark Lobodzinski | bf0042d | 2018-02-26 16:01:22 -0700 | [diff] [blame] | 1454 | // Check valid usage Image Transfer Granularity requirements for elements of a VkBufferImageCopy structure |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1455 | bool ValidateCopyBufferImageTransferGranularityRequirements(layer_data *device_data, const GLOBAL_CB_NODE *cb_node, |
| 1456 | const IMAGE_STATE *img, const VkBufferImageCopy *region, |
| 1457 | const uint32_t i, const char *function) { |
| 1458 | bool skip = false; |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 1459 | if (FormatIsCompressed(img->createInfo.format) == true) { |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1460 | // TODO: Add granularity checking for compressed formats |
| 1461 | |
| 1462 | // bufferRowLength must be a multiple of the compressed texel block width |
| 1463 | // bufferImageHeight must be a multiple of the compressed texel block height |
| 1464 | // all members of imageOffset must be a multiple of the corresponding dimensions of the compressed texel block |
| 1465 | // bufferOffset must be a multiple of the compressed texel block size in bytes |
| 1466 | // imageExtent.width must be a multiple of the compressed texel block width or (imageExtent.width + imageOffset.x) |
| 1467 | // must equal the image subresource width |
| 1468 | // imageExtent.height must be a multiple of the compressed texel block height or (imageExtent.height + imageOffset.y) |
| 1469 | // must equal the image subresource height |
| 1470 | // imageExtent.depth must be a multiple of the compressed texel block depth or (imageExtent.depth + imageOffset.z) |
| 1471 | // must equal the image subresource depth |
| 1472 | } else { |
| 1473 | VkExtent3D granularity = GetScaledItg(device_data, cb_node, img); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1474 | skip |= CheckItgOffset(device_data, cb_node, ®ion->imageOffset, &granularity, i, function, "imageOffset"); |
| 1475 | VkExtent3D subresource_extent = GetImageSubresourceExtent(img, ®ion->imageSubresource); |
| 1476 | skip |= CheckItgExtent(device_data, cb_node, ®ion->imageExtent, ®ion->imageOffset, &granularity, &subresource_extent, |
Mark Lobodzinski | 283ade6 | 2017-10-09 16:36:49 -0600 | [diff] [blame] | 1477 | img->createInfo.imageType, i, function, "imageExtent"); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1478 | } |
| 1479 | return skip; |
| 1480 | } |
| 1481 | |
Mark Lobodzinski | bf0042d | 2018-02-26 16:01:22 -0700 | [diff] [blame] | 1482 | // Check valid usage Image Transfer Granularity requirements for elements of a VkImageCopy structure |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1483 | bool ValidateCopyImageTransferGranularityRequirements(layer_data *device_data, const GLOBAL_CB_NODE *cb_node, |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1484 | const IMAGE_STATE *src_img, const IMAGE_STATE *dst_img, |
| 1485 | const VkImageCopy *region, const uint32_t i, const char *function) { |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1486 | bool skip = false; |
Mark Lobodzinski | d078880 | 2017-10-19 15:38:59 -0600 | [diff] [blame] | 1487 | // Source image checks |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1488 | VkExtent3D granularity = GetScaledItg(device_data, cb_node, src_img); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1489 | skip |= CheckItgOffset(device_data, cb_node, ®ion->srcOffset, &granularity, i, function, "srcOffset"); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1490 | VkExtent3D subresource_extent = GetImageSubresourceExtent(src_img, ®ion->srcSubresource); |
Dave Houlton | 94a0037 | 2017-12-14 15:08:47 -0700 | [diff] [blame] | 1491 | const VkExtent3D extent = region->extent; |
Mark Lobodzinski | d078880 | 2017-10-19 15:38:59 -0600 | [diff] [blame] | 1492 | skip |= CheckItgExtent(device_data, cb_node, &extent, ®ion->srcOffset, &granularity, &subresource_extent, |
Mark Lobodzinski | 283ade6 | 2017-10-09 16:36:49 -0600 | [diff] [blame] | 1493 | src_img->createInfo.imageType, i, function, "extent"); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1494 | |
Mark Lobodzinski | d078880 | 2017-10-19 15:38:59 -0600 | [diff] [blame] | 1495 | // Destination image checks |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1496 | granularity = GetScaledItg(device_data, cb_node, dst_img); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1497 | skip |= CheckItgOffset(device_data, cb_node, ®ion->dstOffset, &granularity, i, function, "dstOffset"); |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 1498 | // Adjust dest extent, if necessary |
Dave Houlton | 94a0037 | 2017-12-14 15:08:47 -0700 | [diff] [blame] | 1499 | const VkExtent3D dest_effective_extent = |
| 1500 | GetAdjustedDestImageExtent(src_img->createInfo.format, dst_img->createInfo.format, extent); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1501 | subresource_extent = GetImageSubresourceExtent(dst_img, ®ion->dstSubresource); |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 1502 | skip |= CheckItgExtent(device_data, cb_node, &dest_effective_extent, ®ion->dstOffset, &granularity, &subresource_extent, |
Mark Lobodzinski | 283ade6 | 2017-10-09 16:36:49 -0600 | [diff] [blame] | 1503 | dst_img->createInfo.imageType, i, function, "extent"); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1504 | return skip; |
| 1505 | } |
| 1506 | |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1507 | // Validate contents of a VkImageCopy struct |
| 1508 | bool ValidateImageCopyData(const layer_data *device_data, const debug_report_data *report_data, const uint32_t regionCount, |
| 1509 | const VkImageCopy *ic_regions, const IMAGE_STATE *src_state, const IMAGE_STATE *dst_state) { |
| 1510 | bool skip = false; |
| 1511 | |
| 1512 | for (uint32_t i = 0; i < regionCount; i++) { |
Dave Houlton | 94a0037 | 2017-12-14 15:08:47 -0700 | [diff] [blame] | 1513 | const VkImageCopy region = ic_regions[i]; |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 1514 | |
| 1515 | // For comp<->uncomp copies, the copy extent for the dest image must be adjusted |
Dave Houlton | 94a0037 | 2017-12-14 15:08:47 -0700 | [diff] [blame] | 1516 | const VkExtent3D src_copy_extent = region.extent; |
| 1517 | const VkExtent3D dst_copy_extent = |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 1518 | GetAdjustedDestImageExtent(src_state->createInfo.format, dst_state->createInfo.format, region.extent); |
| 1519 | |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1520 | bool slice_override = false; |
| 1521 | uint32_t depth_slices = 0; |
| 1522 | |
| 1523 | // Special case for copying between a 1D/2D array and a 3D image |
| 1524 | // TBD: This seems like the only way to reconcile 3 mutually-exclusive VU checks for 2D/3D copies. Heads up. |
| 1525 | if ((VK_IMAGE_TYPE_3D == src_state->createInfo.imageType) && (VK_IMAGE_TYPE_3D != dst_state->createInfo.imageType)) { |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 1526 | depth_slices = region.dstSubresource.layerCount; // Slice count from 2D subresource |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1527 | slice_override = (depth_slices != 1); |
| 1528 | } else if ((VK_IMAGE_TYPE_3D == dst_state->createInfo.imageType) && (VK_IMAGE_TYPE_3D != src_state->createInfo.imageType)) { |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 1529 | depth_slices = region.srcSubresource.layerCount; // Slice count from 2D subresource |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1530 | slice_override = (depth_slices != 1); |
| 1531 | } |
| 1532 | |
| 1533 | // Do all checks on source image |
| 1534 | // |
| 1535 | if (src_state->createInfo.imageType == VK_IMAGE_TYPE_1D) { |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 1536 | if ((0 != region.srcOffset.y) || (1 != src_copy_extent.height)) { |
| 1537 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 1538 | HandleToUint64(src_state->image), VALIDATION_ERROR_09c00124, |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 1539 | "vkCmdCopyImage(): pRegion[%d] srcOffset.y is %d and extent.height is %d. For 1D images these must " |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 1540 | "be 0 and 1, respectively.", |
| 1541 | i, region.srcOffset.y, src_copy_extent.height); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1542 | } |
| 1543 | } |
| 1544 | |
Dave Houlton | 533be9f | 2018-03-26 17:08:30 -0600 | [diff] [blame] | 1545 | // VUID-VkImageCopy-srcImage-01785 |
| 1546 | if ((src_state->createInfo.imageType == VK_IMAGE_TYPE_1D) && ((0 != region.srcOffset.z) || (1 != src_copy_extent.depth))) { |
| 1547 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 1548 | HandleToUint64(src_state->image), VALIDATION_ERROR_09c00df2, |
Dave Houlton | 533be9f | 2018-03-26 17:08:30 -0600 | [diff] [blame] | 1549 | "vkCmdCopyImage(): pRegion[%d] srcOffset.z is %d and extent.depth is %d. For 1D images " |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 1550 | "these must be 0 and 1, respectively.", |
| 1551 | i, region.srcOffset.z, src_copy_extent.depth); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1552 | } |
| 1553 | |
Dave Houlton | 533be9f | 2018-03-26 17:08:30 -0600 | [diff] [blame] | 1554 | // VUID-VkImageCopy-srcImage-01787 |
| 1555 | if ((src_state->createInfo.imageType == VK_IMAGE_TYPE_2D) && (0 != region.srcOffset.z)) { |
| 1556 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 1557 | HandleToUint64(src_state->image), VALIDATION_ERROR_09c00df6, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 1558 | "vkCmdCopyImage(): pRegion[%d] srcOffset.z is %d. For 2D images the z-offset must be 0.", i, |
| 1559 | region.srcOffset.z); |
Dave Houlton | 533be9f | 2018-03-26 17:08:30 -0600 | [diff] [blame] | 1560 | } |
| 1561 | |
Mark Lobodzinski | 28426ae | 2017-06-01 07:56:38 -0600 | [diff] [blame] | 1562 | if (GetDeviceExtensions(device_data)->vk_khr_maintenance1) { |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1563 | if (src_state->createInfo.imageType == VK_IMAGE_TYPE_3D) { |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 1564 | if ((0 != region.srcSubresource.baseArrayLayer) || (1 != region.srcSubresource.layerCount)) { |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1565 | skip |= |
| 1566 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 1567 | HandleToUint64(src_state->image), VALIDATION_ERROR_09c0011a, |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1568 | "vkCmdCopyImage(): pRegion[%d] srcSubresource.baseArrayLayer is %d and srcSubresource.layerCount " |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 1569 | "is %d. For VK_IMAGE_TYPE_3D images these must be 0 and 1, respectively.", |
| 1570 | i, region.srcSubresource.baseArrayLayer, region.srcSubresource.layerCount); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1571 | } |
| 1572 | } |
| 1573 | } else { // Pre maint 1 |
| 1574 | if (src_state->createInfo.imageType == VK_IMAGE_TYPE_3D || dst_state->createInfo.imageType == VK_IMAGE_TYPE_3D) { |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 1575 | if ((0 != region.srcSubresource.baseArrayLayer) || (1 != region.srcSubresource.layerCount)) { |
Petr Kraus | 13c98a6 | 2017-12-09 00:22:39 +0100 | [diff] [blame] | 1576 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 1577 | HandleToUint64(src_state->image), VALIDATION_ERROR_09c0011a, |
Petr Kraus | 13c98a6 | 2017-12-09 00:22:39 +0100 | [diff] [blame] | 1578 | "vkCmdCopyImage(): pRegion[%d] srcSubresource.baseArrayLayer is %d and " |
| 1579 | "srcSubresource.layerCount is %d. For copies with either source or dest of type " |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 1580 | "VK_IMAGE_TYPE_3D, these must be 0 and 1, respectively.", |
| 1581 | i, region.srcSubresource.baseArrayLayer, region.srcSubresource.layerCount); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1582 | } |
| 1583 | } |
| 1584 | } |
| 1585 | |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 1586 | // Source checks that apply only to compressed images (or to _422 images if ycbcr enabled) |
| 1587 | bool ext_ycbcr = GetDeviceExtensions(device_data)->vk_khr_sampler_ycbcr_conversion; |
| 1588 | if (FormatIsCompressed(src_state->createInfo.format) || |
| 1589 | (ext_ycbcr && FormatIsSinglePlane_422(src_state->createInfo.format))) { |
Dave Houlton | 94a0037 | 2017-12-14 15:08:47 -0700 | [diff] [blame] | 1590 | const VkExtent3D block_size = FormatCompressedTexelBlockExtent(src_state->createInfo.format); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1591 | // image offsets must be multiples of block dimensions |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 1592 | if ((SafeModulo(region.srcOffset.x, block_size.width) != 0) || |
| 1593 | (SafeModulo(region.srcOffset.y, block_size.height) != 0) || |
| 1594 | (SafeModulo(region.srcOffset.z, block_size.depth) != 0)) { |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 1595 | UNIQUE_VALIDATION_ERROR_CODE vuid = ext_ycbcr ? VALIDATION_ERROR_09c00d7e : VALIDATION_ERROR_09c0013a; |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1596 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 1597 | HandleToUint64(src_state->image), vuid, |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1598 | "vkCmdCopyImage(): pRegion[%d] srcOffset (%d, %d) must be multiples of the compressed image's " |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 1599 | "texel width & height (%d, %d).", |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 1600 | i, region.srcOffset.x, region.srcOffset.y, block_size.width, block_size.height); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1601 | } |
| 1602 | |
Dave Houlton | 94a0037 | 2017-12-14 15:08:47 -0700 | [diff] [blame] | 1603 | const VkExtent3D mip_extent = GetImageSubresourceExtent(src_state, &(region.srcSubresource)); |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 1604 | if ((SafeModulo(src_copy_extent.width, block_size.width) != 0) && |
| 1605 | (src_copy_extent.width + region.srcOffset.x != mip_extent.width)) { |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 1606 | UNIQUE_VALIDATION_ERROR_CODE vuid = ext_ycbcr ? VALIDATION_ERROR_09c00d80 : VALIDATION_ERROR_09c0013c; |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1607 | skip |= |
| 1608 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 1609 | HandleToUint64(src_state->image), vuid, |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1610 | "vkCmdCopyImage(): pRegion[%d] extent width (%d) must be a multiple of the compressed texture block " |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 1611 | "width (%d), or when added to srcOffset.x (%d) must equal the image subresource width (%d).", |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 1612 | i, src_copy_extent.width, block_size.width, region.srcOffset.x, mip_extent.width); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1613 | } |
| 1614 | |
Mark Lobodzinski | d078880 | 2017-10-19 15:38:59 -0600 | [diff] [blame] | 1615 | // Extent height must be a multiple of block height, or extent+offset height must equal subresource height |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 1616 | if ((SafeModulo(src_copy_extent.height, block_size.height) != 0) && |
| 1617 | (src_copy_extent.height + region.srcOffset.y != mip_extent.height)) { |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 1618 | UNIQUE_VALIDATION_ERROR_CODE vuid = ext_ycbcr ? VALIDATION_ERROR_09c00d82 : VALIDATION_ERROR_09c0013e; |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1619 | skip |= |
| 1620 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 1621 | HandleToUint64(src_state->image), vuid, |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1622 | "vkCmdCopyImage(): pRegion[%d] extent height (%d) must be a multiple of the compressed texture block " |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 1623 | "height (%d), or when added to srcOffset.y (%d) must equal the image subresource height (%d).", |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 1624 | i, src_copy_extent.height, block_size.height, region.srcOffset.y, mip_extent.height); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1625 | } |
| 1626 | |
Mark Lobodzinski | d078880 | 2017-10-19 15:38:59 -0600 | [diff] [blame] | 1627 | // Extent depth must be a multiple of block depth, or extent+offset depth must equal subresource depth |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 1628 | uint32_t copy_depth = (slice_override ? depth_slices : src_copy_extent.depth); |
| 1629 | if ((SafeModulo(copy_depth, block_size.depth) != 0) && (copy_depth + region.srcOffset.z != mip_extent.depth)) { |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 1630 | UNIQUE_VALIDATION_ERROR_CODE vuid = ext_ycbcr ? VALIDATION_ERROR_09c00d84 : VALIDATION_ERROR_09c00140; |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1631 | skip |= |
| 1632 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 1633 | HandleToUint64(src_state->image), vuid, |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1634 | "vkCmdCopyImage(): pRegion[%d] extent width (%d) must be a multiple of the compressed texture block " |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 1635 | "depth (%d), or when added to srcOffset.z (%d) must equal the image subresource depth (%d).", |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 1636 | i, src_copy_extent.depth, block_size.depth, region.srcOffset.z, mip_extent.depth); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1637 | } |
| 1638 | } // Compressed |
| 1639 | |
| 1640 | // Do all checks on dest image |
| 1641 | // |
| 1642 | if (dst_state->createInfo.imageType == VK_IMAGE_TYPE_1D) { |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 1643 | if ((0 != region.dstOffset.y) || (1 != dst_copy_extent.height)) { |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 1644 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 1645 | HandleToUint64(dst_state->image), VALIDATION_ERROR_09c00130, |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 1646 | "vkCmdCopyImage(): pRegion[%d] dstOffset.y is %d and dst_copy_extent.height is %d. For 1D images " |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 1647 | "these must be 0 and 1, respectively.", |
| 1648 | i, region.dstOffset.y, dst_copy_extent.height); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1649 | } |
| 1650 | } |
| 1651 | |
Dave Houlton | 533be9f | 2018-03-26 17:08:30 -0600 | [diff] [blame] | 1652 | // VUID-VkImageCopy-dstImage-01786 |
| 1653 | if ((dst_state->createInfo.imageType == VK_IMAGE_TYPE_1D) && ((0 != region.dstOffset.z) || (1 != dst_copy_extent.depth))) { |
| 1654 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 1655 | HandleToUint64(dst_state->image), VALIDATION_ERROR_09c00df4, |
Dave Houlton | 533be9f | 2018-03-26 17:08:30 -0600 | [diff] [blame] | 1656 | "vkCmdCopyImage(): pRegion[%d] dstOffset.z is %d and extent.depth is %d. For 1D images these must be 0 " |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 1657 | "and 1, respectively.", |
| 1658 | i, region.dstOffset.z, dst_copy_extent.depth); |
Dave Houlton | 533be9f | 2018-03-26 17:08:30 -0600 | [diff] [blame] | 1659 | } |
| 1660 | |
| 1661 | // VUID-VkImageCopy-dstImage-01788 |
| 1662 | if ((dst_state->createInfo.imageType == VK_IMAGE_TYPE_2D) && (0 != region.dstOffset.z)) { |
| 1663 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 1664 | HandleToUint64(dst_state->image), VALIDATION_ERROR_09c00df8, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 1665 | "vkCmdCopyImage(): pRegion[%d] dstOffset.z is %d. For 2D images the z-offset must be 0.", i, |
| 1666 | region.dstOffset.z); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1667 | } |
| 1668 | |
| 1669 | if (dst_state->createInfo.imageType == VK_IMAGE_TYPE_3D) { |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 1670 | if ((0 != region.dstSubresource.baseArrayLayer) || (1 != region.dstSubresource.layerCount)) { |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1671 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 1672 | HandleToUint64(dst_state->image), VALIDATION_ERROR_09c0011a, |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1673 | "vkCmdCopyImage(): pRegion[%d] dstSubresource.baseArrayLayer is %d and dstSubresource.layerCount " |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 1674 | "is %d. For VK_IMAGE_TYPE_3D images these must be 0 and 1, respectively.", |
| 1675 | i, region.dstSubresource.baseArrayLayer, region.dstSubresource.layerCount); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1676 | } |
| 1677 | } |
| 1678 | // VU01199 changed with mnt1 |
Mark Lobodzinski | 28426ae | 2017-06-01 07:56:38 -0600 | [diff] [blame] | 1679 | if (GetDeviceExtensions(device_data)->vk_khr_maintenance1) { |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1680 | if (dst_state->createInfo.imageType == VK_IMAGE_TYPE_3D) { |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 1681 | if ((0 != region.dstSubresource.baseArrayLayer) || (1 != region.dstSubresource.layerCount)) { |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1682 | skip |= |
| 1683 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 1684 | HandleToUint64(dst_state->image), VALIDATION_ERROR_09c0011a, |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1685 | "vkCmdCopyImage(): pRegion[%d] dstSubresource.baseArrayLayer is %d and dstSubresource.layerCount " |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 1686 | "is %d. For VK_IMAGE_TYPE_3D images these must be 0 and 1, respectively.", |
| 1687 | i, region.dstSubresource.baseArrayLayer, region.dstSubresource.layerCount); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1688 | } |
| 1689 | } |
| 1690 | } else { // Pre maint 1 |
| 1691 | if (src_state->createInfo.imageType == VK_IMAGE_TYPE_3D || dst_state->createInfo.imageType == VK_IMAGE_TYPE_3D) { |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 1692 | if ((0 != region.dstSubresource.baseArrayLayer) || (1 != region.dstSubresource.layerCount)) { |
Petr Kraus | 13c98a6 | 2017-12-09 00:22:39 +0100 | [diff] [blame] | 1693 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 1694 | HandleToUint64(dst_state->image), VALIDATION_ERROR_09c0011a, |
Petr Kraus | 13c98a6 | 2017-12-09 00:22:39 +0100 | [diff] [blame] | 1695 | "vkCmdCopyImage(): pRegion[%d] dstSubresource.baseArrayLayer is %d and " |
| 1696 | "dstSubresource.layerCount is %d. For copies with either source or dest of type " |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 1697 | "VK_IMAGE_TYPE_3D, these must be 0 and 1, respectively.", |
| 1698 | i, region.dstSubresource.baseArrayLayer, region.dstSubresource.layerCount); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1699 | } |
| 1700 | } |
| 1701 | } |
| 1702 | |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 1703 | // Dest checks that apply only to compressed images (or to _422 images if ycbcr enabled) |
| 1704 | if (FormatIsCompressed(dst_state->createInfo.format) || |
| 1705 | (ext_ycbcr && FormatIsSinglePlane_422(dst_state->createInfo.format))) { |
Dave Houlton | 94a0037 | 2017-12-14 15:08:47 -0700 | [diff] [blame] | 1706 | const VkExtent3D block_size = FormatCompressedTexelBlockExtent(dst_state->createInfo.format); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1707 | |
| 1708 | // image offsets must be multiples of block dimensions |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 1709 | if ((SafeModulo(region.dstOffset.x, block_size.width) != 0) || |
| 1710 | (SafeModulo(region.dstOffset.y, block_size.height) != 0) || |
| 1711 | (SafeModulo(region.dstOffset.z, block_size.depth) != 0)) { |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 1712 | UNIQUE_VALIDATION_ERROR_CODE vuid = ext_ycbcr ? VALIDATION_ERROR_09c00d86 : VALIDATION_ERROR_09c00144; |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1713 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 1714 | HandleToUint64(dst_state->image), vuid, |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1715 | "vkCmdCopyImage(): pRegion[%d] dstOffset (%d, %d) must be multiples of the compressed image's " |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 1716 | "texel width & height (%d, %d).", |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 1717 | i, region.dstOffset.x, region.dstOffset.y, block_size.width, block_size.height); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1718 | } |
| 1719 | |
Dave Houlton | 94a0037 | 2017-12-14 15:08:47 -0700 | [diff] [blame] | 1720 | const VkExtent3D mip_extent = GetImageSubresourceExtent(dst_state, &(region.dstSubresource)); |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 1721 | if ((SafeModulo(dst_copy_extent.width, block_size.width) != 0) && |
| 1722 | (dst_copy_extent.width + region.dstOffset.x != mip_extent.width)) { |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 1723 | UNIQUE_VALIDATION_ERROR_CODE vuid = ext_ycbcr ? VALIDATION_ERROR_09c00d88 : VALIDATION_ERROR_09c00146; |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 1724 | skip |= |
| 1725 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 1726 | HandleToUint64(dst_state->image), vuid, |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 1727 | "vkCmdCopyImage(): pRegion[%d] dst_copy_extent width (%d) must be a multiple of the compressed texture " |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 1728 | "block width (%d), or when added to dstOffset.x (%d) must equal the image subresource width (%d).", |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 1729 | i, dst_copy_extent.width, block_size.width, region.dstOffset.x, mip_extent.width); |
Mark Lobodzinski | d078880 | 2017-10-19 15:38:59 -0600 | [diff] [blame] | 1730 | } |
| 1731 | |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 1732 | // Extent height must be a multiple of block height, or dst_copy_extent+offset height must equal subresource height |
| 1733 | if ((SafeModulo(dst_copy_extent.height, block_size.height) != 0) && |
| 1734 | (dst_copy_extent.height + region.dstOffset.y != mip_extent.height)) { |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 1735 | UNIQUE_VALIDATION_ERROR_CODE vuid = ext_ycbcr ? VALIDATION_ERROR_09c00d8a : VALIDATION_ERROR_09c00148; |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 1736 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 1737 | HandleToUint64(dst_state->image), vuid, |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 1738 | "vkCmdCopyImage(): pRegion[%d] dst_copy_extent height (%d) must be a multiple of the compressed " |
| 1739 | "texture block height (%d), or when added to dstOffset.y (%d) must equal the image subresource " |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 1740 | "height (%d).", |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 1741 | i, dst_copy_extent.height, block_size.height, region.dstOffset.y, mip_extent.height); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1742 | } |
| 1743 | |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 1744 | // Extent depth must be a multiple of block depth, or dst_copy_extent+offset depth must equal subresource depth |
| 1745 | uint32_t copy_depth = (slice_override ? depth_slices : dst_copy_extent.depth); |
| 1746 | if ((SafeModulo(copy_depth, block_size.depth) != 0) && (copy_depth + region.dstOffset.z != mip_extent.depth)) { |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 1747 | UNIQUE_VALIDATION_ERROR_CODE vuid = ext_ycbcr ? VALIDATION_ERROR_09c00d8c : VALIDATION_ERROR_09c0014a; |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 1748 | skip |= |
| 1749 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 1750 | HandleToUint64(dst_state->image), vuid, |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 1751 | "vkCmdCopyImage(): pRegion[%d] dst_copy_extent width (%d) must be a multiple of the compressed texture " |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 1752 | "block depth (%d), or when added to dstOffset.z (%d) must equal the image subresource depth (%d).", |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 1753 | i, dst_copy_extent.depth, block_size.depth, region.dstOffset.z, mip_extent.depth); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1754 | } |
| 1755 | } // Compressed |
| 1756 | } |
| 1757 | return skip; |
| 1758 | } |
| 1759 | |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 1760 | // vkCmdCopyImage checks that only apply if the multiplane extension is enabled |
| 1761 | bool CopyImageMultiplaneValidation(const layer_data *dev_data, VkCommandBuffer command_buffer, const IMAGE_STATE *src_image_state, |
| 1762 | const IMAGE_STATE *dst_image_state, const VkImageCopy region) { |
| 1763 | bool skip = false; |
| 1764 | const debug_report_data *report_data = core_validation::GetReportData(dev_data); |
| 1765 | |
| 1766 | // Neither image is multiplane |
| 1767 | if ((!FormatIsMultiplane(src_image_state->createInfo.format)) && (!FormatIsMultiplane(dst_image_state->createInfo.format))) { |
| 1768 | // If neither image is multi-plane the aspectMask member of src and dst must match |
| 1769 | if (region.srcSubresource.aspectMask != region.dstSubresource.aspectMask) { |
| 1770 | std::stringstream ss; |
| 1771 | ss << "vkCmdCopyImage: Copy between non-multiplane images with differing aspectMasks ( 0x" << std::hex |
| 1772 | << region.srcSubresource.aspectMask << " and 0x" << region.dstSubresource.aspectMask << " )"; |
| 1773 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1774 | HandleToUint64(command_buffer), VALIDATION_ERROR_09c00c1e, "%s.", ss.str().c_str()); |
| 1775 | } |
| 1776 | } else { |
| 1777 | // Source image multiplane checks |
| 1778 | uint32_t planes = FormatPlaneCount(src_image_state->createInfo.format); |
| 1779 | VkImageAspectFlags aspect = region.srcSubresource.aspectMask; |
| 1780 | if ((2 == planes) && (aspect != VK_IMAGE_ASPECT_PLANE_0_BIT_KHR) && (aspect != VK_IMAGE_ASPECT_PLANE_1_BIT_KHR)) { |
| 1781 | std::stringstream ss; |
| 1782 | ss << "vkCmdCopyImage: Source image aspect mask (0x" << std::hex << aspect << ") is invalid for 2-plane format"; |
| 1783 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1784 | HandleToUint64(command_buffer), VALIDATION_ERROR_09c00c20, "%s.", ss.str().c_str()); |
| 1785 | } |
| 1786 | if ((3 == planes) && (aspect != VK_IMAGE_ASPECT_PLANE_0_BIT_KHR) && (aspect != VK_IMAGE_ASPECT_PLANE_1_BIT_KHR) && |
| 1787 | (aspect != VK_IMAGE_ASPECT_PLANE_2_BIT_KHR)) { |
| 1788 | std::stringstream ss; |
| 1789 | ss << "vkCmdCopyImage: Source image aspect mask (0x" << std::hex << aspect << ") is invalid for 3-plane format"; |
| 1790 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1791 | HandleToUint64(command_buffer), VALIDATION_ERROR_09c00c22, "%s.", ss.str().c_str()); |
| 1792 | } |
| 1793 | // Single-plane to multi-plane |
| 1794 | if ((!FormatIsMultiplane(src_image_state->createInfo.format)) && (FormatIsMultiplane(dst_image_state->createInfo.format)) && |
| 1795 | (VK_IMAGE_ASPECT_COLOR_BIT != aspect)) { |
| 1796 | std::stringstream ss; |
| 1797 | ss << "vkCmdCopyImage: Source image aspect mask (0x" << std::hex << aspect << ") is not VK_IMAGE_ASPECT_COLOR_BIT"; |
| 1798 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1799 | HandleToUint64(command_buffer), VALIDATION_ERROR_09c00c2a, "%s.", ss.str().c_str()); |
| 1800 | } |
| 1801 | |
| 1802 | // Dest image multiplane checks |
| 1803 | planes = FormatPlaneCount(dst_image_state->createInfo.format); |
| 1804 | aspect = region.dstSubresource.aspectMask; |
| 1805 | if ((2 == planes) && (aspect != VK_IMAGE_ASPECT_PLANE_0_BIT_KHR) && (aspect != VK_IMAGE_ASPECT_PLANE_1_BIT_KHR)) { |
| 1806 | std::stringstream ss; |
| 1807 | ss << "vkCmdCopyImage: Dest image aspect mask (0x" << std::hex << aspect << ") is invalid for 2-plane format"; |
| 1808 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1809 | HandleToUint64(command_buffer), VALIDATION_ERROR_09c00c24, "%s.", ss.str().c_str()); |
| 1810 | } |
| 1811 | if ((3 == planes) && (aspect != VK_IMAGE_ASPECT_PLANE_0_BIT_KHR) && (aspect != VK_IMAGE_ASPECT_PLANE_1_BIT_KHR) && |
| 1812 | (aspect != VK_IMAGE_ASPECT_PLANE_2_BIT_KHR)) { |
| 1813 | std::stringstream ss; |
| 1814 | ss << "vkCmdCopyImage: Dest image aspect mask (0x" << std::hex << aspect << ") is invalid for 3-plane format"; |
| 1815 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1816 | HandleToUint64(command_buffer), VALIDATION_ERROR_09c00c26, "%s.", ss.str().c_str()); |
| 1817 | } |
| 1818 | // Multi-plane to single-plane |
| 1819 | if ((FormatIsMultiplane(src_image_state->createInfo.format)) && (!FormatIsMultiplane(dst_image_state->createInfo.format)) && |
| 1820 | (VK_IMAGE_ASPECT_COLOR_BIT != aspect)) { |
| 1821 | std::stringstream ss; |
| 1822 | ss << "vkCmdCopyImage: Dest image aspect mask (0x" << std::hex << aspect << ") is not VK_IMAGE_ASPECT_COLOR_BIT"; |
| 1823 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1824 | HandleToUint64(command_buffer), VALIDATION_ERROR_09c00c28, "%s.", ss.str().c_str()); |
| 1825 | } |
| 1826 | } |
| 1827 | |
| 1828 | return skip; |
| 1829 | } |
| 1830 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 1831 | 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] | 1832 | IMAGE_STATE *dst_image_state, uint32_t region_count, const VkImageCopy *regions, |
| 1833 | VkImageLayout src_image_layout, VkImageLayout dst_image_layout) { |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1834 | bool skip = false; |
| 1835 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1836 | skip = ValidateImageCopyData(device_data, report_data, region_count, regions, src_image_state, dst_image_state); |
| 1837 | |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1838 | VkCommandBuffer command_buffer = cb_node->commandBuffer; |
| 1839 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1840 | for (uint32_t i = 0; i < region_count; i++) { |
Dave Houlton | 94a0037 | 2017-12-14 15:08:47 -0700 | [diff] [blame] | 1841 | const VkImageCopy region = regions[i]; |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 1842 | |
| 1843 | // For comp/uncomp copies, the copy extent for the dest image must be adjusted |
| 1844 | VkExtent3D src_copy_extent = region.extent; |
| 1845 | VkExtent3D dst_copy_extent = |
| 1846 | GetAdjustedDestImageExtent(src_image_state->createInfo.format, dst_image_state->createInfo.format, region.extent); |
| 1847 | |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1848 | bool slice_override = false; |
| 1849 | uint32_t depth_slices = 0; |
| 1850 | |
| 1851 | // Special case for copying between a 1D/2D array and a 3D image |
| 1852 | // TBD: This seems like the only way to reconcile 3 mutually-exclusive VU checks for 2D/3D copies. Heads up. |
| 1853 | if ((VK_IMAGE_TYPE_3D == src_image_state->createInfo.imageType) && |
| 1854 | (VK_IMAGE_TYPE_3D != dst_image_state->createInfo.imageType)) { |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 1855 | depth_slices = region.dstSubresource.layerCount; // Slice count from 2D subresource |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1856 | slice_override = (depth_slices != 1); |
| 1857 | } else if ((VK_IMAGE_TYPE_3D == dst_image_state->createInfo.imageType) && |
| 1858 | (VK_IMAGE_TYPE_3D != src_image_state->createInfo.imageType)) { |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 1859 | depth_slices = region.srcSubresource.layerCount; // Slice count from 2D subresource |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1860 | slice_override = (depth_slices != 1); |
| 1861 | } |
| 1862 | |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 1863 | if (region.srcSubresource.layerCount == 0) { |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1864 | std::stringstream ss; |
| 1865 | ss << "vkCmdCopyImage: number of layers in pRegions[" << i << "] srcSubresource is zero"; |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 1866 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 1867 | HandleToUint64(command_buffer), DRAWSTATE_INVALID_IMAGE_ASPECT, "%s", ss.str().c_str()); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1868 | } |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1869 | |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 1870 | if (region.dstSubresource.layerCount == 0) { |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1871 | std::stringstream ss; |
| 1872 | ss << "vkCmdCopyImage: number of layers in pRegions[" << i << "] dstSubresource is zero"; |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 1873 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 1874 | HandleToUint64(command_buffer), DRAWSTATE_INVALID_IMAGE_ASPECT, "%s", ss.str().c_str()); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1875 | } |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1876 | |
Mark Lobodzinski | 28426ae | 2017-06-01 07:56:38 -0600 | [diff] [blame] | 1877 | if (GetDeviceExtensions(device_data)->vk_khr_maintenance1) { |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1878 | // No chance of mismatch if we're overriding depth slice count |
| 1879 | if (!slice_override) { |
| 1880 | // The number of depth slices in srcSubresource and dstSubresource must match |
| 1881 | // Depth comes from layerCount for 1D,2D resources, from extent.depth for 3D |
| 1882 | uint32_t src_slices = |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 1883 | (VK_IMAGE_TYPE_3D == src_image_state->createInfo.imageType ? src_copy_extent.depth |
| 1884 | : region.srcSubresource.layerCount); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1885 | uint32_t dst_slices = |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 1886 | (VK_IMAGE_TYPE_3D == dst_image_state->createInfo.imageType ? dst_copy_extent.depth |
| 1887 | : region.dstSubresource.layerCount); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1888 | if (src_slices != dst_slices) { |
| 1889 | std::stringstream ss; |
| 1890 | ss << "vkCmdCopyImage: number of depth slices in source and destination subresources for pRegions[" << i |
| 1891 | << "] do not match"; |
| 1892 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 1893 | HandleToUint64(command_buffer), VALIDATION_ERROR_09c00118, "%s.", ss.str().c_str()); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1894 | } |
| 1895 | } |
| 1896 | } else { |
Mike Schuchardt | 64b5bb7 | 2017-03-21 16:33:26 -0600 | [diff] [blame] | 1897 | // For each region the layerCount member of srcSubresource and dstSubresource must match |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 1898 | if (region.srcSubresource.layerCount != region.dstSubresource.layerCount) { |
Mike Schuchardt | 64b5bb7 | 2017-03-21 16:33:26 -0600 | [diff] [blame] | 1899 | std::stringstream ss; |
| 1900 | ss << "vkCmdCopyImage: number of layers in source and destination subresources for pRegions[" << i |
| 1901 | << "] do not match"; |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 1902 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 1903 | HandleToUint64(command_buffer), VALIDATION_ERROR_09c00118, "%s.", ss.str().c_str()); |
Mike Schuchardt | 64b5bb7 | 2017-03-21 16:33:26 -0600 | [diff] [blame] | 1904 | } |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1905 | } |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1906 | |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 1907 | // Do multiplane-specific checks, if extension enabled |
| 1908 | if (GetDeviceExtensions(device_data)->vk_khr_sampler_ycbcr_conversion) { |
| 1909 | skip |= CopyImageMultiplaneValidation(device_data, command_buffer, src_image_state, dst_image_state, region); |
| 1910 | } |
| 1911 | |
Dave Houlton | f521761 | 2018-02-02 16:18:52 -0700 | [diff] [blame] | 1912 | if (!GetDeviceExtensions(device_data)->vk_khr_sampler_ycbcr_conversion) { |
| 1913 | // not multi-plane, the aspectMask member of srcSubresource and dstSubresource must match |
| 1914 | if (region.srcSubresource.aspectMask != region.dstSubresource.aspectMask) { |
| 1915 | char const str[] = "vkCmdCopyImage: Src and dest aspectMasks for each region must match"; |
| 1916 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 1917 | HandleToUint64(command_buffer), VALIDATION_ERROR_09c00112, "%s.", str); |
Dave Houlton | f521761 | 2018-02-02 16:18:52 -0700 | [diff] [blame] | 1918 | } |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1919 | } |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1920 | |
Dave Houlton | 4eaaf3a | 2017-03-14 11:31:20 -0600 | [diff] [blame] | 1921 | // For each region, the aspectMask member of srcSubresource must be present in the source image |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 1922 | if (!VerifyAspectsPresent(region.srcSubresource.aspectMask, src_image_state->createInfo.format)) { |
Dave Houlton | 4eaaf3a | 2017-03-14 11:31:20 -0600 | [diff] [blame] | 1923 | std::stringstream ss; |
| 1924 | ss << "vkCmdCopyImage: pRegion[" << i |
| 1925 | << "] srcSubresource.aspectMask cannot specify aspects not present in source image"; |
| 1926 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 1927 | HandleToUint64(command_buffer), VALIDATION_ERROR_09c0011c, "%s.", ss.str().c_str()); |
Dave Houlton | 4eaaf3a | 2017-03-14 11:31:20 -0600 | [diff] [blame] | 1928 | } |
| 1929 | |
| 1930 | // For each region, the aspectMask member of dstSubresource must be present in the destination image |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 1931 | if (!VerifyAspectsPresent(region.dstSubresource.aspectMask, dst_image_state->createInfo.format)) { |
Dave Houlton | 4eaaf3a | 2017-03-14 11:31:20 -0600 | [diff] [blame] | 1932 | std::stringstream ss; |
| 1933 | ss << "vkCmdCopyImage: pRegion[" << i << "] dstSubresource.aspectMask cannot specify aspects not present in dest image"; |
| 1934 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 1935 | HandleToUint64(command_buffer), VALIDATION_ERROR_09c0011e, "%s.", ss.str().c_str()); |
Dave Houlton | 4eaaf3a | 2017-03-14 11:31:20 -0600 | [diff] [blame] | 1936 | } |
| 1937 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1938 | // AspectMask must not contain VK_IMAGE_ASPECT_METADATA_BIT |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 1939 | if ((region.srcSubresource.aspectMask & VK_IMAGE_ASPECT_METADATA_BIT) || |
| 1940 | (region.dstSubresource.aspectMask & VK_IMAGE_ASPECT_METADATA_BIT)) { |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1941 | std::stringstream ss; |
| 1942 | ss << "vkCmdCopyImage: pRegions[" << i << "] may not specify aspectMask containing VK_IMAGE_ASPECT_METADATA_BIT"; |
| 1943 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 1944 | HandleToUint64(command_buffer), VALIDATION_ERROR_0a600150, "%s.", ss.str().c_str()); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1945 | } |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1946 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1947 | // For each region, if aspectMask contains VK_IMAGE_ASPECT_COLOR_BIT, it must not contain either of |
| 1948 | // VK_IMAGE_ASPECT_DEPTH_BIT or VK_IMAGE_ASPECT_STENCIL_BIT |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 1949 | if ((region.srcSubresource.aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) && |
| 1950 | (region.srcSubresource.aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT))) { |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1951 | char const str[] = "vkCmdCopyImage aspectMask cannot specify both COLOR and DEPTH/STENCIL aspects"; |
| 1952 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 1953 | HandleToUint64(command_buffer), VALIDATION_ERROR_0a60014e, "%s.", str); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1954 | } |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1955 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1956 | // MipLevel must be less than the mipLevels specified in VkImageCreateInfo when the image was created |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 1957 | if (region.srcSubresource.mipLevel >= src_image_state->createInfo.mipLevels) { |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1958 | std::stringstream ss; |
| 1959 | ss << "vkCmdCopyImage: pRegions[" << i |
| 1960 | << "] specifies a src mipLevel greater than the number specified when the srcImage was created."; |
| 1961 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 1962 | HandleToUint64(command_buffer), VALIDATION_ERROR_19000d40, "%s.", ss.str().c_str()); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1963 | } |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 1964 | if (region.dstSubresource.mipLevel >= dst_image_state->createInfo.mipLevels) { |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1965 | std::stringstream ss; |
| 1966 | ss << "vkCmdCopyImage: pRegions[" << i |
| 1967 | << "] specifies a dst mipLevel greater than the number specified when the dstImage was created."; |
| 1968 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 1969 | HandleToUint64(command_buffer), VALIDATION_ERROR_19000d42, "%s.", ss.str().c_str()); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1970 | } |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1971 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1972 | // (baseArrayLayer + layerCount) must be less than or equal to the arrayLayers specified in VkImageCreateInfo when the |
| 1973 | // image was created |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 1974 | if ((region.srcSubresource.baseArrayLayer + region.srcSubresource.layerCount) > src_image_state->createInfo.arrayLayers) { |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1975 | std::stringstream ss; |
| 1976 | ss << "vkCmdCopyImage: srcImage arrayLayers was " << src_image_state->createInfo.arrayLayers << " but subRegion[" << i |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 1977 | << "] baseArrayLayer + layerCount is " << (region.srcSubresource.baseArrayLayer + region.srcSubresource.layerCount); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1978 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 1979 | HandleToUint64(command_buffer), VALIDATION_ERROR_19000d44, "%s.", ss.str().c_str()); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1980 | } |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 1981 | if ((region.dstSubresource.baseArrayLayer + region.dstSubresource.layerCount) > dst_image_state->createInfo.arrayLayers) { |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1982 | std::stringstream ss; |
| 1983 | ss << "vkCmdCopyImage: dstImage arrayLayers was " << dst_image_state->createInfo.arrayLayers << " but subRegion[" << i |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 1984 | << "] baseArrayLayer + layerCount is " << (region.dstSubresource.baseArrayLayer + region.dstSubresource.layerCount); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1985 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 1986 | HandleToUint64(command_buffer), VALIDATION_ERROR_19000d46, "%s.", ss.str().c_str()); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1987 | } |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1988 | |
Mike Schuchardt | 64b5bb7 | 2017-03-21 16:33:26 -0600 | [diff] [blame] | 1989 | // Check region extents for 1D-1D, 2D-2D, and 3D-3D copies |
| 1990 | if (src_image_state->createInfo.imageType == dst_image_state->createInfo.imageType) { |
| 1991 | // The source region specified by a given element of regions must be a region that is contained within srcImage |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 1992 | VkExtent3D img_extent = GetImageSubresourceExtent(src_image_state, &(region.srcSubresource)); |
| 1993 | if (0 != ExceedsBounds(®ion.srcOffset, &src_copy_extent, &img_extent)) { |
Mike Schuchardt | 64b5bb7 | 2017-03-21 16:33:26 -0600 | [diff] [blame] | 1994 | std::stringstream ss; |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 1995 | ss << "vkCmdCopyImage: Source pRegion[" << i << "] with mipLevel [ " << region.srcSubresource.mipLevel |
| 1996 | << " ], offset [ " << region.srcOffset.x << ", " << region.srcOffset.y << ", " << region.srcOffset.z |
| 1997 | << " ], extent [ " << src_copy_extent.width << ", " << src_copy_extent.height << ", " << src_copy_extent.depth |
| 1998 | << " ] exceeds the source image dimensions"; |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 1999 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2000 | HandleToUint64(command_buffer), VALIDATION_ERROR_190000f4, "%s.", ss.str().c_str()); |
Mike Schuchardt | 64b5bb7 | 2017-03-21 16:33:26 -0600 | [diff] [blame] | 2001 | } |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 2002 | |
Mike Schuchardt | 64b5bb7 | 2017-03-21 16:33:26 -0600 | [diff] [blame] | 2003 | // The destination region specified by a given element of regions must be a region that is contained within dst_image |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 2004 | img_extent = GetImageSubresourceExtent(dst_image_state, &(region.dstSubresource)); |
| 2005 | if (0 != ExceedsBounds(®ion.dstOffset, &dst_copy_extent, &img_extent)) { |
Mike Schuchardt | 64b5bb7 | 2017-03-21 16:33:26 -0600 | [diff] [blame] | 2006 | std::stringstream ss; |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 2007 | ss << "vkCmdCopyImage: Dest pRegion[" << i << "] with mipLevel [ " << region.dstSubresource.mipLevel |
| 2008 | << " ], offset [ " << region.dstOffset.x << ", " << region.dstOffset.y << ", " << region.dstOffset.z |
| 2009 | << " ], extent [ " << dst_copy_extent.width << ", " << dst_copy_extent.height << ", " << dst_copy_extent.depth |
| 2010 | << " ] exceeds the destination image dimensions"; |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 2011 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2012 | HandleToUint64(command_buffer), VALIDATION_ERROR_190000f6, "%s.", ss.str().c_str()); |
Mike Schuchardt | 64b5bb7 | 2017-03-21 16:33:26 -0600 | [diff] [blame] | 2013 | } |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 2014 | } |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 2015 | |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 2016 | // Each dimension offset + extent limits must fall with image subresource extent |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 2017 | VkExtent3D subresource_extent = GetImageSubresourceExtent(src_image_state, &(region.srcSubresource)); |
| 2018 | if (slice_override) src_copy_extent.depth = depth_slices; |
| 2019 | uint32_t extent_check = ExceedsBounds(&(region.srcOffset), &src_copy_extent, &subresource_extent); |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 2020 | if (extent_check & x_bit) { |
| 2021 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2022 | HandleToUint64(command_buffer), VALIDATION_ERROR_09c00120, |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 2023 | "vkCmdCopyImage: Source image pRegion %1d x-dimension offset [%1d] + extent [%1d] exceeds subResource " |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2024 | "width [%1d].", |
| 2025 | i, region.srcOffset.x, src_copy_extent.width, subresource_extent.width); |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 2026 | } |
| 2027 | |
| 2028 | if (extent_check & y_bit) { |
| 2029 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2030 | HandleToUint64(command_buffer), VALIDATION_ERROR_09c00122, |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 2031 | "vkCmdCopyImage: Source image pRegion %1d y-dimension offset [%1d] + extent [%1d] exceeds subResource " |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2032 | "height [%1d].", |
| 2033 | i, region.srcOffset.y, src_copy_extent.height, subresource_extent.height); |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 2034 | } |
| 2035 | if (extent_check & z_bit) { |
| 2036 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2037 | HandleToUint64(command_buffer), VALIDATION_ERROR_09c00126, |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 2038 | "vkCmdCopyImage: Source image pRegion %1d z-dimension offset [%1d] + extent [%1d] exceeds subResource " |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2039 | "depth [%1d].", |
| 2040 | i, region.srcOffset.z, src_copy_extent.depth, subresource_extent.depth); |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 2041 | } |
| 2042 | |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 2043 | // Adjust dest extent if necessary |
| 2044 | subresource_extent = GetImageSubresourceExtent(dst_image_state, &(region.dstSubresource)); |
| 2045 | if (slice_override) dst_copy_extent.depth = depth_slices; |
| 2046 | |
| 2047 | extent_check = ExceedsBounds(&(region.dstOffset), &dst_copy_extent, &subresource_extent); |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 2048 | if (extent_check & x_bit) { |
| 2049 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2050 | HandleToUint64(command_buffer), VALIDATION_ERROR_09c0012c, |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 2051 | "vkCmdCopyImage: Dest image pRegion %1d x-dimension offset [%1d] + extent [%1d] exceeds subResource " |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2052 | "width [%1d].", |
| 2053 | i, region.dstOffset.x, dst_copy_extent.width, subresource_extent.width); |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 2054 | } |
| 2055 | if (extent_check & y_bit) { |
| 2056 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2057 | HandleToUint64(command_buffer), VALIDATION_ERROR_09c0012e, |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 2058 | "vkCmdCopyImage: Dest image pRegion %1d y-dimension offset [%1d] + extent [%1d] exceeds subResource " |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2059 | "height [%1d].", |
| 2060 | i, region.dstOffset.y, dst_copy_extent.height, subresource_extent.height); |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 2061 | } |
| 2062 | if (extent_check & z_bit) { |
| 2063 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2064 | HandleToUint64(command_buffer), VALIDATION_ERROR_09c00132, |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 2065 | "vkCmdCopyImage: Dest image pRegion %1d z-dimension offset [%1d] + extent [%1d] exceeds subResource " |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2066 | "depth [%1d].", |
| 2067 | i, region.dstOffset.z, dst_copy_extent.depth, subresource_extent.depth); |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 2068 | } |
| 2069 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 2070 | // The union of all source regions, and the union of all destination regions, specified by the elements of regions, |
| 2071 | // must not overlap in memory |
| 2072 | if (src_image_state->image == dst_image_state->image) { |
| 2073 | for (uint32_t j = 0; j < region_count; j++) { |
Dave Houlton | f521761 | 2018-02-02 16:18:52 -0700 | [diff] [blame] | 2074 | if (RegionIntersects(®ion, ®ions[j], src_image_state->createInfo.imageType, |
| 2075 | FormatIsMultiplane(src_image_state->createInfo.format))) { |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 2076 | std::stringstream ss; |
| 2077 | ss << "vkCmdCopyImage: pRegions[" << i << "] src overlaps with pRegions[" << j << "]."; |
| 2078 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2079 | HandleToUint64(command_buffer), VALIDATION_ERROR_190000f8, "%s.", ss.str().c_str()); |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 2080 | } |
| 2081 | } |
| 2082 | } |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 2083 | } |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 2084 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 2085 | // The formats of src_image and dst_image must be compatible. Formats are considered compatible if their texel size in bytes |
| 2086 | // is the same between both formats. For example, VK_FORMAT_R8G8B8A8_UNORM is compatible with VK_FORMAT_R32_UINT because |
| 2087 | // 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] | 2088 | 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] | 2089 | if (src_image_state->createInfo.format != dst_image_state->createInfo.format) { |
| 2090 | 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] | 2091 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2092 | HandleToUint64(command_buffer), DRAWSTATE_MISMATCHED_IMAGE_FORMAT, str); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 2093 | } |
| 2094 | } else { |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 2095 | size_t srcSize = FormatSize(src_image_state->createInfo.format); |
| 2096 | size_t destSize = FormatSize(dst_image_state->createInfo.format); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 2097 | if (srcSize != destSize) { |
| 2098 | char const str[] = "vkCmdCopyImage called with unmatched source and dest image format sizes."; |
| 2099 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2100 | HandleToUint64(command_buffer), VALIDATION_ERROR_1900010e, "%s.", str); |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 2101 | } |
| 2102 | } |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 2103 | |
Dave Houlton | 33c22b7 | 2017-02-28 13:16:02 -0700 | [diff] [blame] | 2104 | // Source and dest image sample counts must match |
| 2105 | if (src_image_state->createInfo.samples != dst_image_state->createInfo.samples) { |
| 2106 | char const str[] = "vkCmdCopyImage() called on image pair with non-identical sample counts."; |
| 2107 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2108 | HandleToUint64(command_buffer), VALIDATION_ERROR_19000110, "%s", str); |
Dave Houlton | 33c22b7 | 2017-02-28 13:16:02 -0700 | [diff] [blame] | 2109 | } |
| 2110 | |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 2111 | skip |= ValidateMemoryIsBoundToImage(device_data, src_image_state, "vkCmdCopyImage()", VALIDATION_ERROR_190000fe); |
| 2112 | skip |= ValidateMemoryIsBoundToImage(device_data, dst_image_state, "vkCmdCopyImage()", VALIDATION_ERROR_19000108); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 2113 | // Validate that SRC & DST images have correct usage flags set |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 2114 | 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] | 2115 | "vkCmdCopyImage()", "VK_IMAGE_USAGE_TRANSFER_SRC_BIT"); |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 2116 | 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] | 2117 | "vkCmdCopyImage()", "VK_IMAGE_USAGE_TRANSFER_DST_BIT"); |
Mike Schuchardt | 9c58240 | 2017-02-23 15:57:37 -0700 | [diff] [blame] | 2118 | skip |= ValidateCmdQueueFlags(device_data, cb_node, "vkCmdCopyImage()", |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 2119 | 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] | 2120 | skip |= ValidateCmd(device_data, cb_node, CMD_COPYIMAGE, "vkCmdCopyImage()"); |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 2121 | skip |= insideRenderPass(device_data, cb_node, "vkCmdCopyImage()", VALIDATION_ERROR_19000017); |
Tobin Ehlis | c826645 | 2017-04-07 12:20:30 -0600 | [diff] [blame] | 2122 | bool hit_error = false; |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 2123 | for (uint32_t i = 0; i < region_count; ++i) { |
Tobin Ehlis | 2d85ec6 | 2017-03-14 15:38:48 -0600 | [diff] [blame] | 2124 | 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] | 2125 | VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, "vkCmdCopyImage()", VALIDATION_ERROR_19000102, &hit_error); |
Tobin Ehlis | 2d85ec6 | 2017-03-14 15:38:48 -0600 | [diff] [blame] | 2126 | 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] | 2127 | VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, "vkCmdCopyImage()", VALIDATION_ERROR_1900010c, &hit_error); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 2128 | skip |= ValidateCopyImageTransferGranularityRequirements(device_data, cb_node, src_image_state, dst_image_state, |
| 2129 | ®ions[i], i, "vkCmdCopyImage()"); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 2130 | } |
| 2131 | |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 2132 | return skip; |
| 2133 | } |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 2134 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 2135 | 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] | 2136 | IMAGE_STATE *dst_image_state, uint32_t region_count, const VkImageCopy *regions, |
| 2137 | VkImageLayout src_image_layout, VkImageLayout dst_image_layout) { |
| 2138 | // Make sure that all image slices are updated to correct layout |
| 2139 | for (uint32_t i = 0; i < region_count; ++i) { |
| 2140 | SetImageLayout(device_data, cb_node, src_image_state, regions[i].srcSubresource, src_image_layout); |
| 2141 | SetImageLayout(device_data, cb_node, dst_image_state, regions[i].dstSubresource, dst_image_layout); |
| 2142 | } |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 2143 | // Update bindings between images and cmd buffer |
| 2144 | AddCommandBufferBindingImage(device_data, cb_node, src_image_state); |
| 2145 | AddCommandBufferBindingImage(device_data, cb_node, dst_image_state); |
Dave Houlton | eba86e2 | 2017-03-02 14:56:23 -0700 | [diff] [blame] | 2146 | std::function<bool()> function = [=]() { return ValidateImageMemoryIsValid(device_data, src_image_state, "vkCmdCopyImage()"); }; |
Tobin Ehlis | a17a529 | 2017-07-28 12:11:30 -0600 | [diff] [blame] | 2147 | cb_node->queue_submit_functions.push_back(function); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 2148 | function = [=]() { |
| 2149 | SetImageMemoryValid(device_data, dst_image_state, true); |
| 2150 | return false; |
| 2151 | }; |
Tobin Ehlis | a17a529 | 2017-07-28 12:11:30 -0600 | [diff] [blame] | 2152 | cb_node->queue_submit_functions.push_back(function); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 2153 | } |
| 2154 | |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 2155 | // Returns true if sub_rect is entirely contained within rect |
| 2156 | static inline bool ContainsRect(VkRect2D rect, VkRect2D sub_rect) { |
| 2157 | if ((sub_rect.offset.x < rect.offset.x) || (sub_rect.offset.x + sub_rect.extent.width > rect.offset.x + rect.extent.width) || |
| 2158 | (sub_rect.offset.y < rect.offset.y) || (sub_rect.offset.y + sub_rect.extent.height > rect.offset.y + rect.extent.height)) |
| 2159 | return false; |
| 2160 | return true; |
| 2161 | } |
| 2162 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 2163 | bool PreCallValidateCmdClearAttachments(layer_data *device_data, VkCommandBuffer commandBuffer, uint32_t attachmentCount, |
| 2164 | const VkClearAttachment *pAttachments, uint32_t rectCount, const VkClearRect *pRects) { |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 2165 | GLOBAL_CB_NODE *cb_node = GetCBNode(device_data, commandBuffer); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 2166 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 2167 | |
| 2168 | bool skip = false; |
| 2169 | if (cb_node) { |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 2170 | skip |= ValidateCmdQueueFlags(device_data, cb_node, "vkCmdClearAttachments()", VK_QUEUE_GRAPHICS_BIT, |
| 2171 | VALIDATION_ERROR_18602415); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 2172 | skip |= ValidateCmd(device_data, cb_node, CMD_CLEARATTACHMENTS, "vkCmdClearAttachments()"); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 2173 | // 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] | 2174 | 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] | 2175 | (cb_node->activeRenderPassBeginInfo.renderArea.extent.height == pRects[0].rect.extent.height)) { |
| 2176 | // 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] | 2177 | // This warning should be made more specific. It'd be best to avoid triggering this test if it's a use that must call |
| 2178 | // CmdClearAttachments. |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 2179 | skip |= log_msg( |
| 2180 | report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2181 | HandleToUint64(commandBuffer), DRAWSTATE_CLEAR_CMD_BEFORE_DRAW, |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 2182 | "vkCmdClearAttachments() issued on command buffer object 0x%" PRIx64 |
| 2183 | " prior to any Draw Cmds. It is recommended you use RenderPass LOAD_OP_CLEAR on Attachments prior to any Draw.", |
| 2184 | HandleToUint64(commandBuffer)); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 2185 | } |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 2186 | skip |= outsideRenderPass(device_data, cb_node, "vkCmdClearAttachments()", VALIDATION_ERROR_18600017); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 2187 | } |
| 2188 | |
| 2189 | // Validate that attachment is in reference list of active subpass |
| 2190 | if (cb_node->activeRenderPass) { |
| 2191 | const VkRenderPassCreateInfo *renderpass_create_info = cb_node->activeRenderPass->createInfo.ptr(); |
| 2192 | const VkSubpassDescription *subpass_desc = &renderpass_create_info->pSubpasses[cb_node->activeSubpass]; |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 2193 | auto framebuffer = GetFramebufferState(device_data, cb_node->activeFramebuffer); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 2194 | |
| 2195 | for (uint32_t i = 0; i < attachmentCount; i++) { |
| 2196 | auto clear_desc = &pAttachments[i]; |
| 2197 | VkImageView image_view = VK_NULL_HANDLE; |
| 2198 | |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 2199 | if (0 == clear_desc->aspectMask) { |
| 2200 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2201 | HandleToUint64(commandBuffer), VALIDATION_ERROR_01c00c03, " "); |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 2202 | } else if (clear_desc->aspectMask & VK_IMAGE_ASPECT_METADATA_BIT) { |
| 2203 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2204 | HandleToUint64(commandBuffer), VALIDATION_ERROR_01c00028, " "); |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 2205 | } else if (clear_desc->aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) { |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 2206 | if (clear_desc->colorAttachment >= subpass_desc->colorAttachmentCount) { |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 2207 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2208 | HandleToUint64(commandBuffer), VALIDATION_ERROR_1860001e, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2209 | "vkCmdClearAttachments() color attachment index %d out of range for active subpass %d.", |
| 2210 | clear_desc->colorAttachment, cb_node->activeSubpass); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 2211 | } else if (subpass_desc->pColorAttachments[clear_desc->colorAttachment].attachment == VK_ATTACHMENT_UNUSED) { |
| 2212 | skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 2213 | VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, HandleToUint64(commandBuffer), |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2214 | DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 2215 | "vkCmdClearAttachments() color attachment index %d is VK_ATTACHMENT_UNUSED; ignored.", |
| 2216 | clear_desc->colorAttachment); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 2217 | } else { |
| 2218 | image_view = framebuffer->createInfo |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 2219 | .pAttachments[subpass_desc->pColorAttachments[clear_desc->colorAttachment].attachment]; |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 2220 | } |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 2221 | if ((clear_desc->aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) || |
| 2222 | (clear_desc->aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT)) { |
| 2223 | char const str[] = |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2224 | "vkCmdClearAttachments() aspectMask [%d] must set only VK_IMAGE_ASPECT_COLOR_BIT of a color attachment."; |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 2225 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2226 | HandleToUint64(commandBuffer), VALIDATION_ERROR_01c00026, str, i); |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 2227 | } |
| 2228 | } else { // Must be depth and/or stencil |
| 2229 | if (((clear_desc->aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) != VK_IMAGE_ASPECT_DEPTH_BIT) && |
| 2230 | ((clear_desc->aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) != VK_IMAGE_ASPECT_STENCIL_BIT)) { |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2231 | char const str[] = "vkCmdClearAttachments() aspectMask [%d] is not a valid combination of bits."; |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 2232 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2233 | HandleToUint64(commandBuffer), VALIDATION_ERROR_01c00c01, str, i); |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 2234 | } |
| 2235 | if (!subpass_desc->pDepthStencilAttachment || |
| 2236 | (subpass_desc->pDepthStencilAttachment->attachment == VK_ATTACHMENT_UNUSED)) { |
| 2237 | skip |= log_msg( |
| 2238 | report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2239 | HandleToUint64(commandBuffer), DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 2240 | "vkCmdClearAttachments() depth/stencil clear with no depth/stencil attachment in subpass; ignored"); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 2241 | } else { |
| 2242 | image_view = framebuffer->createInfo.pAttachments[subpass_desc->pDepthStencilAttachment->attachment]; |
| 2243 | } |
| 2244 | } |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 2245 | if (image_view) { |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 2246 | auto image_view_state = GetImageViewState(device_data, image_view); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 2247 | for (uint32_t j = 0; j < rectCount; j++) { |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 2248 | // The rectangular region specified by a given element of pRects must be contained within the render area of |
| 2249 | // the current render pass instance |
Tobin Ehlis | 37ec75a | 2018-03-12 11:26:39 -0600 | [diff] [blame] | 2250 | if (cb_node->createInfo.level == VK_COMMAND_BUFFER_LEVEL_PRIMARY) { |
| 2251 | if (false == ContainsRect(cb_node->activeRenderPassBeginInfo.renderArea, pRects[j].rect)) { |
| 2252 | skip |= |
| 2253 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2254 | HandleToUint64(commandBuffer), VALIDATION_ERROR_18600020, |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 2255 | "vkCmdClearAttachments(): The area defined by pRects[%d] is not contained in the area of " |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2256 | "the current render pass instance.", |
| 2257 | j); |
Tobin Ehlis | 37ec75a | 2018-03-12 11:26:39 -0600 | [diff] [blame] | 2258 | } |
| 2259 | } else { |
| 2260 | cb_node->cmd_execute_commands_functions.emplace_back([=](GLOBAL_CB_NODE *prim_cb, VkFramebuffer fb) { |
| 2261 | if (false == ContainsRect(prim_cb->activeRenderPassBeginInfo.renderArea, pRects[j].rect)) { |
| 2262 | return log_msg( |
| 2263 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2264 | HandleToUint64(commandBuffer), VALIDATION_ERROR_18600020, |
Tobin Ehlis | 37ec75a | 2018-03-12 11:26:39 -0600 | [diff] [blame] | 2265 | "vkCmdClearAttachments(): The area defined by pRects[%d] is not contained in the area of " |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2266 | "the current render pass instance.", |
| 2267 | j); |
Tobin Ehlis | 37ec75a | 2018-03-12 11:26:39 -0600 | [diff] [blame] | 2268 | } |
| 2269 | return false; |
| 2270 | }); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 2271 | } |
| 2272 | // The layers specified by a given element of pRects must be contained within every attachment that |
| 2273 | // pAttachments refers to |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 2274 | auto attachment_layer_count = image_view_state->create_info.subresourceRange.layerCount; |
Dave Houlton | 8e15703 | 2017-05-22 16:16:27 -0600 | [diff] [blame] | 2275 | if ((pRects[j].baseArrayLayer >= attachment_layer_count) || |
| 2276 | (pRects[j].baseArrayLayer + pRects[j].layerCount > attachment_layer_count)) { |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 2277 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2278 | HandleToUint64(commandBuffer), VALIDATION_ERROR_18600022, |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 2279 | "vkCmdClearAttachments(): The layers defined in pRects[%d] are not contained in the layers " |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2280 | "of pAttachment[%d].", |
| 2281 | j, i); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 2282 | } |
| 2283 | } |
| 2284 | } |
| 2285 | } |
| 2286 | } |
| 2287 | return skip; |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 2288 | } |
| 2289 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 2290 | 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] | 2291 | IMAGE_STATE *dst_image_state, uint32_t regionCount, const VkImageResolve *pRegions) { |
Mark Lobodzinski | 2a3368e | 2017-02-06 15:29:37 -0700 | [diff] [blame] | 2292 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 2293 | bool skip = false; |
| 2294 | if (cb_node && src_image_state && dst_image_state) { |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 2295 | skip |= ValidateMemoryIsBoundToImage(device_data, src_image_state, "vkCmdResolveImage()", VALIDATION_ERROR_1c800200); |
| 2296 | skip |= ValidateMemoryIsBoundToImage(device_data, dst_image_state, "vkCmdResolveImage()", VALIDATION_ERROR_1c800204); |
| 2297 | skip |= |
| 2298 | 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] | 2299 | skip |= ValidateCmd(device_data, cb_node, CMD_RESOLVEIMAGE, "vkCmdResolveImage()"); |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 2300 | skip |= insideRenderPass(device_data, cb_node, "vkCmdResolveImage()", VALIDATION_ERROR_1c800017); |
Mark Lobodzinski | 2a3368e | 2017-02-06 15:29:37 -0700 | [diff] [blame] | 2301 | |
| 2302 | // For each region, the number of layers in the image subresource should not be zero |
| 2303 | // For each region, src and dest image aspect must be color only |
| 2304 | for (uint32_t i = 0; i < regionCount; i++) { |
| 2305 | if (pRegions[i].srcSubresource.layerCount == 0) { |
| 2306 | char const str[] = "vkCmdResolveImage: number of layers in source subresource is zero"; |
Mark Lobodzinski | 50fbef1 | 2017-02-06 15:31:33 -0700 | [diff] [blame] | 2307 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2308 | HandleToUint64(cb_node->commandBuffer), DRAWSTATE_MISMATCHED_IMAGE_ASPECT, str); |
Mark Lobodzinski | 2a3368e | 2017-02-06 15:29:37 -0700 | [diff] [blame] | 2309 | } |
Mark Lobodzinski | 2a3368e | 2017-02-06 15:29:37 -0700 | [diff] [blame] | 2310 | if (pRegions[i].dstSubresource.layerCount == 0) { |
| 2311 | char const str[] = "vkCmdResolveImage: number of layers in destination subresource is zero"; |
Mark Lobodzinski | 50fbef1 | 2017-02-06 15:31:33 -0700 | [diff] [blame] | 2312 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2313 | HandleToUint64(cb_node->commandBuffer), DRAWSTATE_MISMATCHED_IMAGE_ASPECT, str); |
Mark Lobodzinski | 2a3368e | 2017-02-06 15:29:37 -0700 | [diff] [blame] | 2314 | } |
Mark Lobodzinski | 50fbef1 | 2017-02-06 15:31:33 -0700 | [diff] [blame] | 2315 | if (pRegions[i].srcSubresource.layerCount != pRegions[i].dstSubresource.layerCount) { |
| 2316 | skip |= log_msg( |
| 2317 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2318 | HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_0a200216, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2319 | "vkCmdResolveImage: layerCount in source and destination subresource of pRegions[%d] does not match.", i); |
Mark Lobodzinski | 50fbef1 | 2017-02-06 15:31:33 -0700 | [diff] [blame] | 2320 | } |
Mark Lobodzinski | 2a3368e | 2017-02-06 15:29:37 -0700 | [diff] [blame] | 2321 | if ((pRegions[i].srcSubresource.aspectMask != VK_IMAGE_ASPECT_COLOR_BIT) || |
| 2322 | (pRegions[i].dstSubresource.aspectMask != VK_IMAGE_ASPECT_COLOR_BIT)) { |
| 2323 | char const str[] = |
| 2324 | "vkCmdResolveImage: src and dest aspectMasks for each region must specify only VK_IMAGE_ASPECT_COLOR_BIT"; |
| 2325 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2326 | HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_0a200214, "%s.", str); |
Mark Lobodzinski | 2a3368e | 2017-02-06 15:29:37 -0700 | [diff] [blame] | 2327 | } |
| 2328 | } |
| 2329 | |
| 2330 | if (src_image_state->createInfo.format != dst_image_state->createInfo.format) { |
| 2331 | char const str[] = "vkCmdResolveImage called with unmatched source and dest formats."; |
Mark Lobodzinski | 50fbef1 | 2017-02-06 15:31:33 -0700 | [diff] [blame] | 2332 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2333 | HandleToUint64(cb_node->commandBuffer), DRAWSTATE_MISMATCHED_IMAGE_FORMAT, str); |
Mark Lobodzinski | 2a3368e | 2017-02-06 15:29:37 -0700 | [diff] [blame] | 2334 | } |
| 2335 | if (src_image_state->createInfo.imageType != dst_image_state->createInfo.imageType) { |
| 2336 | char const str[] = "vkCmdResolveImage called with unmatched source and dest image types."; |
Mark Lobodzinski | 50fbef1 | 2017-02-06 15:31:33 -0700 | [diff] [blame] | 2337 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2338 | HandleToUint64(cb_node->commandBuffer), DRAWSTATE_MISMATCHED_IMAGE_TYPE, str); |
Mark Lobodzinski | 2a3368e | 2017-02-06 15:29:37 -0700 | [diff] [blame] | 2339 | } |
| 2340 | if (src_image_state->createInfo.samples == VK_SAMPLE_COUNT_1_BIT) { |
| 2341 | char const str[] = "vkCmdResolveImage called with source sample count less than 2."; |
| 2342 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2343 | HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_1c800202, "%s.", str); |
Mark Lobodzinski | 2a3368e | 2017-02-06 15:29:37 -0700 | [diff] [blame] | 2344 | } |
| 2345 | if (dst_image_state->createInfo.samples != VK_SAMPLE_COUNT_1_BIT) { |
| 2346 | char const str[] = "vkCmdResolveImage called with dest sample count greater than 1."; |
| 2347 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2348 | HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_1c800206, "%s.", str); |
Mark Lobodzinski | 2a3368e | 2017-02-06 15:29:37 -0700 | [diff] [blame] | 2349 | } |
Tobin Ehlis | bb03e5f | 2017-05-11 08:52:51 -0600 | [diff] [blame] | 2350 | // 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] | 2351 | } else { |
| 2352 | assert(0); |
| 2353 | } |
| 2354 | return skip; |
| 2355 | } |
| 2356 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 2357 | void PreCallRecordCmdResolveImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state, |
| 2358 | IMAGE_STATE *dst_image_state) { |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 2359 | // Update bindings between images and cmd buffer |
| 2360 | AddCommandBufferBindingImage(device_data, cb_node, src_image_state); |
| 2361 | AddCommandBufferBindingImage(device_data, cb_node, dst_image_state); |
| 2362 | |
| 2363 | std::function<bool()> function = [=]() { |
| 2364 | return ValidateImageMemoryIsValid(device_data, src_image_state, "vkCmdResolveImage()"); |
| 2365 | }; |
Tobin Ehlis | a17a529 | 2017-07-28 12:11:30 -0600 | [diff] [blame] | 2366 | cb_node->queue_submit_functions.push_back(function); |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 2367 | function = [=]() { |
| 2368 | SetImageMemoryValid(device_data, dst_image_state, true); |
| 2369 | return false; |
| 2370 | }; |
Tobin Ehlis | a17a529 | 2017-07-28 12:11:30 -0600 | [diff] [blame] | 2371 | cb_node->queue_submit_functions.push_back(function); |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 2372 | } |
| 2373 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 2374 | bool PreCallValidateCmdBlitImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state, |
Norbert Garnys | 7bd4c2c | 2017-11-16 10:58:04 +0100 | [diff] [blame] | 2375 | IMAGE_STATE *dst_image_state, uint32_t region_count, const VkImageBlit *regions, |
| 2376 | VkImageLayout src_image_layout, VkImageLayout dst_image_layout, VkFilter filter) { |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 2377 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 2378 | |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 2379 | bool skip = false; |
John Zulauf | 5c2750c | 2018-01-30 15:04:56 -0700 | [diff] [blame] | 2380 | if (cb_node) { |
| 2381 | skip |= ValidateCmd(device_data, cb_node, CMD_BLITIMAGE, "vkCmdBlitImage()"); |
| 2382 | } |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 2383 | if (cb_node && src_image_state && dst_image_state) { |
| 2384 | 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] | 2385 | VALIDATION_ERROR_184001d2); |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 2386 | 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] | 2387 | VALIDATION_ERROR_184001d4); |
| 2388 | skip |= ValidateMemoryIsBoundToImage(device_data, src_image_state, "vkCmdBlitImage()", VALIDATION_ERROR_184001b8); |
| 2389 | skip |= ValidateMemoryIsBoundToImage(device_data, dst_image_state, "vkCmdBlitImage()", VALIDATION_ERROR_184001c2); |
| 2390 | skip |= ValidateImageUsageFlags(device_data, src_image_state, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, true, |
| 2391 | VALIDATION_ERROR_184001b6, "vkCmdBlitImage()", "VK_IMAGE_USAGE_TRANSFER_SRC_BIT"); |
| 2392 | skip |= ValidateImageUsageFlags(device_data, dst_image_state, VK_IMAGE_USAGE_TRANSFER_DST_BIT, true, |
| 2393 | VALIDATION_ERROR_184001c0, "vkCmdBlitImage()", "VK_IMAGE_USAGE_TRANSFER_DST_BIT"); |
| 2394 | 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] | 2395 | skip |= ValidateCmd(device_data, cb_node, CMD_BLITIMAGE, "vkCmdBlitImage()"); |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 2396 | skip |= insideRenderPass(device_data, cb_node, "vkCmdBlitImage()", VALIDATION_ERROR_18400017); |
Tobin Ehlis | bb03e5f | 2017-05-11 08:52:51 -0600 | [diff] [blame] | 2397 | // 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] | 2398 | |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2399 | VkFormat src_format = src_image_state->createInfo.format; |
| 2400 | VkFormat dst_format = dst_image_state->createInfo.format; |
| 2401 | VkImageType src_type = src_image_state->createInfo.imageType; |
| 2402 | VkImageType dst_type = dst_image_state->createInfo.imageType; |
| 2403 | |
Jeremy Kniager | 7ec550f | 2017-08-16 14:57:42 -0600 | [diff] [blame] | 2404 | VkFormatProperties props = GetFormatProperties(device_data, src_format); |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2405 | VkImageTiling tiling = src_image_state->createInfo.tiling; |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 2406 | VkFormatFeatureFlags flags = (tiling == VK_IMAGE_TILING_LINEAR ? props.linearTilingFeatures : props.optimalTilingFeatures); |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2407 | if (VK_FORMAT_FEATURE_BLIT_SRC_BIT != (flags & VK_FORMAT_FEATURE_BLIT_SRC_BIT)) { |
| 2408 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2409 | HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_184001b4, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2410 | "vkCmdBlitImage: source image format %s does not support VK_FORMAT_FEATURE_BLIT_SRC_BIT feature.", |
| 2411 | string_VkFormat(src_format)); |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2412 | } |
| 2413 | |
| 2414 | if ((VK_FILTER_LINEAR == filter) && |
| 2415 | (VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT != (flags & VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT))) { |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2416 | skip |= |
| 2417 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2418 | HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_184001d6, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2419 | "vkCmdBlitImage: source image format %s does not support linear filtering.", string_VkFormat(src_format)); |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2420 | } |
| 2421 | |
| 2422 | if ((VK_FILTER_CUBIC_IMG == filter) && (VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_CUBIC_BIT_IMG != |
| 2423 | (flags & VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_CUBIC_BIT_IMG))) { |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2424 | skip |= |
| 2425 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2426 | HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_184001d8, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2427 | "vkCmdBlitImage: source image format %s does not support cubic filtering.", string_VkFormat(src_format)); |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2428 | } |
| 2429 | |
| 2430 | if ((VK_FILTER_CUBIC_IMG == filter) && (VK_IMAGE_TYPE_3D != src_type)) { |
| 2431 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2432 | HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_184001da, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2433 | "vkCmdBlitImage: source image type must be VK_IMAGE_TYPE_3D when cubic filtering is specified."); |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2434 | } |
| 2435 | |
| 2436 | props = GetFormatProperties(device_data, dst_format); |
| 2437 | tiling = dst_image_state->createInfo.tiling; |
Jeremy Kniager | 7ec550f | 2017-08-16 14:57:42 -0600 | [diff] [blame] | 2438 | flags = (tiling == VK_IMAGE_TILING_LINEAR ? props.linearTilingFeatures : props.optimalTilingFeatures); |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2439 | if (VK_FORMAT_FEATURE_BLIT_DST_BIT != (flags & VK_FORMAT_FEATURE_BLIT_DST_BIT)) { |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2440 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2441 | HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_184001be, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2442 | "vkCmdBlitImage: destination image format %s does not support VK_FORMAT_FEATURE_BLIT_DST_BIT feature.", |
| 2443 | string_VkFormat(dst_format)); |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2444 | } |
| 2445 | |
| 2446 | if ((VK_SAMPLE_COUNT_1_BIT != src_image_state->createInfo.samples) || |
| 2447 | (VK_SAMPLE_COUNT_1_BIT != dst_image_state->createInfo.samples)) { |
| 2448 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2449 | HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_184001c8, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2450 | "vkCmdBlitImage: source or dest image has sample count other than VK_SAMPLE_COUNT_1_BIT."); |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2451 | } |
| 2452 | |
| 2453 | // Validate consistency for unsigned formats |
| 2454 | if (FormatIsUInt(src_format) != FormatIsUInt(dst_format)) { |
| 2455 | std::stringstream ss; |
| 2456 | ss << "vkCmdBlitImage: If one of srcImage and dstImage images has unsigned integer format, " |
| 2457 | << "the other one must also have unsigned integer format. " |
| 2458 | << "Source format is " << string_VkFormat(src_format) << " Destination format is " << string_VkFormat(dst_format); |
| 2459 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2460 | HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_184001cc, "%s.", ss.str().c_str()); |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2461 | } |
| 2462 | |
| 2463 | // Validate consistency for signed formats |
| 2464 | if (FormatIsSInt(src_format) != FormatIsSInt(dst_format)) { |
| 2465 | std::stringstream ss; |
| 2466 | ss << "vkCmdBlitImage: If one of srcImage and dstImage images has signed integer format, " |
| 2467 | << "the other one must also have signed integer format. " |
| 2468 | << "Source format is " << string_VkFormat(src_format) << " Destination format is " << string_VkFormat(dst_format); |
| 2469 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2470 | HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_184001ca, "%s.", ss.str().c_str()); |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2471 | } |
| 2472 | |
| 2473 | // Validate filter for Depth/Stencil formats |
| 2474 | if (FormatIsDepthOrStencil(src_format) && (filter != VK_FILTER_NEAREST)) { |
| 2475 | std::stringstream ss; |
| 2476 | ss << "vkCmdBlitImage: If the format of srcImage is a depth, stencil, or depth stencil " |
| 2477 | << "then filter must be VK_FILTER_NEAREST."; |
| 2478 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2479 | HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_184001d0, "%s.", ss.str().c_str()); |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2480 | } |
| 2481 | |
| 2482 | // Validate aspect bits and formats for depth/stencil images |
| 2483 | if (FormatIsDepthOrStencil(src_format) || FormatIsDepthOrStencil(dst_format)) { |
| 2484 | if (src_format != dst_format) { |
| 2485 | std::stringstream ss; |
| 2486 | ss << "vkCmdBlitImage: If one of srcImage and dstImage images has a format of depth, stencil or depth " |
| 2487 | << "stencil, the other one must have exactly the same format. " |
| 2488 | << "Source format is " << string_VkFormat(src_format) << " Destination format is " |
| 2489 | << string_VkFormat(dst_format); |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 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), VALIDATION_ERROR_184001ce, "%s.", ss.str().c_str()); |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2492 | } |
| 2493 | |
| 2494 | #if 0 // TODO: Cannot find VU statements or spec language for these in CmdBlitImage. Verify or remove. |
| 2495 | for (uint32_t i = 0; i < regionCount; i++) { |
| 2496 | VkImageAspectFlags srcAspect = pRegions[i].srcSubresource.aspectMask; |
| 2497 | |
| 2498 | if (FormatIsDepthAndStencil(src_format)) { |
| 2499 | if ((srcAspect != VK_IMAGE_ASPECT_DEPTH_BIT) && (srcAspect != VK_IMAGE_ASPECT_STENCIL_BIT)) { |
| 2500 | std::stringstream ss; |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 2501 | ss << "vkCmdBlitImage: Combination depth/stencil image formats must have only one of VK_IMAGE_ASPECT_DEPTH_BIT " |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2502 | << "and VK_IMAGE_ASPECT_STENCIL_BIT set in srcImage and dstImage"; |
| 2503 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2504 | HandleToUint64(cb_node->commandBuffer), DRAWSTATE_INVALID_IMAGE_ASPECT, |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2505 | "%s", ss.str().c_str()); |
| 2506 | } |
| 2507 | } |
| 2508 | else if (FormatIsStencilOnly(src_format)) { |
| 2509 | if (srcAspect != VK_IMAGE_ASPECT_STENCIL_BIT) { |
| 2510 | std::stringstream ss; |
| 2511 | ss << "vkCmdBlitImage: Stencil-only image formats must have only the VK_IMAGE_ASPECT_STENCIL_BIT " |
| 2512 | << "set in both the srcImage and dstImage"; |
| 2513 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2514 | HandleToUint64(cb_node->commandBuffer), DRAWSTATE_INVALID_IMAGE_ASPECT, |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2515 | "%s", ss.str().c_str()); |
| 2516 | } |
| 2517 | } |
| 2518 | else if (FormatIsDepthOnly(src_format)) { |
| 2519 | if (srcAspect != VK_IMAGE_ASPECT_DEPTH_BIT) { |
| 2520 | std::stringstream ss; |
| 2521 | ss << "vkCmdBlitImage: Depth-only image formats must have only the VK_IMAGE_ASPECT_DEPTH " |
| 2522 | << "set in both the srcImage and dstImage"; |
| 2523 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2524 | HandleToUint64(cb_node->commandBuffer), DRAWSTATE_INVALID_IMAGE_ASPECT, |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2525 | "%s", ss.str().c_str()); |
| 2526 | } |
| 2527 | } |
| 2528 | } |
| 2529 | #endif |
| 2530 | } // Depth or Stencil |
| 2531 | |
| 2532 | // Do per-region checks |
Norbert Garnys | 7bd4c2c | 2017-11-16 10:58:04 +0100 | [diff] [blame] | 2533 | for (uint32_t i = 0; i < region_count; i++) { |
| 2534 | const VkImageBlit rgn = regions[i]; |
| 2535 | bool hit_error = false; |
| 2536 | skip |= |
| 2537 | VerifyImageLayout(device_data, cb_node, src_image_state, rgn.srcSubresource, src_image_layout, |
| 2538 | VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, "vkCmdBlitImage()", VALIDATION_ERROR_184001bc, &hit_error); |
| 2539 | skip |= |
| 2540 | VerifyImageLayout(device_data, cb_node, dst_image_state, rgn.dstSubresource, dst_image_layout, |
| 2541 | VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, "vkCmdBlitImage()", VALIDATION_ERROR_184001c6, &hit_error); |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 2542 | |
Mark Lobodzinski | 23c8114 | 2017-02-06 15:04:23 -0700 | [diff] [blame] | 2543 | // Warn for zero-sized regions |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 2544 | if ((rgn.srcOffsets[0].x == rgn.srcOffsets[1].x) || (rgn.srcOffsets[0].y == rgn.srcOffsets[1].y) || |
| 2545 | (rgn.srcOffsets[0].z == rgn.srcOffsets[1].z)) { |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 2546 | std::stringstream ss; |
| 2547 | ss << "vkCmdBlitImage: pRegions[" << i << "].srcOffsets specify a zero-volume area."; |
| 2548 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2549 | HandleToUint64(cb_node->commandBuffer), DRAWSTATE_INVALID_EXTENTS, "%s", ss.str().c_str()); |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 2550 | } |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 2551 | if ((rgn.dstOffsets[0].x == rgn.dstOffsets[1].x) || (rgn.dstOffsets[0].y == rgn.dstOffsets[1].y) || |
| 2552 | (rgn.dstOffsets[0].z == rgn.dstOffsets[1].z)) { |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 2553 | std::stringstream ss; |
| 2554 | ss << "vkCmdBlitImage: pRegions[" << i << "].dstOffsets specify a zero-volume area."; |
| 2555 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2556 | HandleToUint64(cb_node->commandBuffer), DRAWSTATE_INVALID_EXTENTS, "%s", ss.str().c_str()); |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 2557 | } |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 2558 | if (rgn.srcSubresource.layerCount == 0) { |
Mark Lobodzinski | 23c8114 | 2017-02-06 15:04:23 -0700 | [diff] [blame] | 2559 | char const str[] = "vkCmdBlitImage: number of layers in source subresource is zero"; |
| 2560 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2561 | HandleToUint64(cb_node->commandBuffer), DRAWSTATE_MISMATCHED_IMAGE_ASPECT, str); |
Mark Lobodzinski | 23c8114 | 2017-02-06 15:04:23 -0700 | [diff] [blame] | 2562 | } |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 2563 | if (rgn.dstSubresource.layerCount == 0) { |
Mark Lobodzinski | 23c8114 | 2017-02-06 15:04:23 -0700 | [diff] [blame] | 2564 | char const str[] = "vkCmdBlitImage: number of layers in destination subresource is zero"; |
| 2565 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2566 | HandleToUint64(cb_node->commandBuffer), DRAWSTATE_MISMATCHED_IMAGE_ASPECT, str); |
Mark Lobodzinski | 23c8114 | 2017-02-06 15:04:23 -0700 | [diff] [blame] | 2567 | } |
| 2568 | |
| 2569 | // Check that src/dst layercounts match |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 2570 | if (rgn.srcSubresource.layerCount != rgn.dstSubresource.layerCount) { |
Mark Lobodzinski | 23c8114 | 2017-02-06 15:04:23 -0700 | [diff] [blame] | 2571 | skip |= |
| 2572 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2573 | HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_09a001de, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2574 | "vkCmdBlitImage: layerCount in source and destination subresource of pRegions[%d] does not match.", i); |
Mark Lobodzinski | 23c8114 | 2017-02-06 15:04:23 -0700 | [diff] [blame] | 2575 | } |
Mark Lobodzinski | e7e85fd | 2017-02-07 13:44:57 -0700 | [diff] [blame] | 2576 | |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 2577 | if (rgn.srcSubresource.aspectMask != rgn.dstSubresource.aspectMask) { |
Mark Lobodzinski | e7e85fd | 2017-02-07 13:44:57 -0700 | [diff] [blame] | 2578 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2579 | HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_09a001dc, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2580 | "vkCmdBlitImage: aspectMask members for pRegion[%d] do not match.", i); |
Mark Lobodzinski | e7e85fd | 2017-02-07 13:44:57 -0700 | [diff] [blame] | 2581 | } |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 2582 | |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2583 | if (!VerifyAspectsPresent(rgn.srcSubresource.aspectMask, src_format)) { |
| 2584 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2585 | HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_09a001e2, |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2586 | "vkCmdBlitImage: region [%d] source aspectMask (0x%x) specifies aspects not present in source " |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2587 | "image format %s.", |
| 2588 | i, rgn.srcSubresource.aspectMask, string_VkFormat(src_format)); |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2589 | } |
| 2590 | |
| 2591 | if (!VerifyAspectsPresent(rgn.dstSubresource.aspectMask, dst_format)) { |
| 2592 | skip |= log_msg( |
| 2593 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2594 | HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_09a001e4, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2595 | "vkCmdBlitImage: region [%d] dest aspectMask (0x%x) specifies aspects not present in dest image format %s.", i, |
| 2596 | rgn.dstSubresource.aspectMask, string_VkFormat(dst_format)); |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2597 | } |
| 2598 | |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 2599 | // Validate source image offsets |
| 2600 | VkExtent3D src_extent = GetImageSubresourceExtent(src_image_state, &(rgn.srcSubresource)); |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2601 | if (VK_IMAGE_TYPE_1D == src_type) { |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 2602 | if ((0 != rgn.srcOffsets[0].y) || (1 != rgn.srcOffsets[1].y)) { |
| 2603 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2604 | HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_09a001ea, |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 2605 | "vkCmdBlitImage: region [%d], source image of type VK_IMAGE_TYPE_1D with srcOffset[].y values " |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2606 | "of (%1d, %1d). These must be (0, 1).", |
| 2607 | i, rgn.srcOffsets[0].y, rgn.srcOffsets[1].y); |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 2608 | } |
| 2609 | } |
| 2610 | |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2611 | 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] | 2612 | if ((0 != rgn.srcOffsets[0].z) || (1 != rgn.srcOffsets[1].z)) { |
| 2613 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2614 | HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_09a001ee, |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 2615 | "vkCmdBlitImage: region [%d], source image of type VK_IMAGE_TYPE_1D or VK_IMAGE_TYPE_2D with " |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2616 | "srcOffset[].z values of (%1d, %1d). These must be (0, 1).", |
| 2617 | i, rgn.srcOffsets[0].z, rgn.srcOffsets[1].z); |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 2618 | } |
| 2619 | } |
| 2620 | |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2621 | bool oob = false; |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 2622 | if ((rgn.srcOffsets[0].x < 0) || (rgn.srcOffsets[0].x > static_cast<int32_t>(src_extent.width)) || |
| 2623 | (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] | 2624 | oob = true; |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2625 | skip |= |
| 2626 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2627 | HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_09a001e6, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2628 | "vkCmdBlitImage: region [%d] srcOffset[].x values (%1d, %1d) exceed srcSubresource width extent (%1d).", |
| 2629 | i, rgn.srcOffsets[0].x, rgn.srcOffsets[1].x, src_extent.width); |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 2630 | } |
| 2631 | if ((rgn.srcOffsets[0].y < 0) || (rgn.srcOffsets[0].y > static_cast<int32_t>(src_extent.height)) || |
| 2632 | (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] | 2633 | oob = true; |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 2634 | skip |= log_msg( |
| 2635 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2636 | HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_09a001e8, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2637 | "vkCmdBlitImage: region [%d] srcOffset[].y values (%1d, %1d) exceed srcSubresource height extent (%1d).", i, |
| 2638 | rgn.srcOffsets[0].y, rgn.srcOffsets[1].y, src_extent.height); |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 2639 | } |
| 2640 | if ((rgn.srcOffsets[0].z < 0) || (rgn.srcOffsets[0].z > static_cast<int32_t>(src_extent.depth)) || |
| 2641 | (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] | 2642 | oob = true; |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2643 | skip |= |
| 2644 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2645 | HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_09a001ec, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2646 | "vkCmdBlitImage: region [%d] srcOffset[].z values (%1d, %1d) exceed srcSubresource depth extent (%1d).", |
| 2647 | i, rgn.srcOffsets[0].z, rgn.srcOffsets[1].z, src_extent.depth); |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 2648 | } |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2649 | if (rgn.srcSubresource.mipLevel >= src_image_state->createInfo.mipLevels) { |
| 2650 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2651 | HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_184001ae, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2652 | "vkCmdBlitImage: region [%d] source image, attempt to access a non-existant mip level %1d.", i, |
| 2653 | rgn.srcSubresource.mipLevel); |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2654 | } else if (oob) { |
| 2655 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2656 | HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_184001ae, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2657 | "vkCmdBlitImage: region [%d] source image blit region exceeds image dimensions.", i); |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2658 | } |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 2659 | |
| 2660 | // Validate dest image offsets |
| 2661 | VkExtent3D dst_extent = GetImageSubresourceExtent(dst_image_state, &(rgn.dstSubresource)); |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2662 | if (VK_IMAGE_TYPE_1D == dst_type) { |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 2663 | if ((0 != rgn.dstOffsets[0].y) || (1 != rgn.dstOffsets[1].y)) { |
| 2664 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2665 | HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_09a001f4, |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 2666 | "vkCmdBlitImage: region [%d], dest image of type VK_IMAGE_TYPE_1D with dstOffset[].y values of " |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2667 | "(%1d, %1d). These must be (0, 1).", |
| 2668 | i, rgn.dstOffsets[0].y, rgn.dstOffsets[1].y); |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 2669 | } |
| 2670 | } |
| 2671 | |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2672 | 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] | 2673 | if ((0 != rgn.dstOffsets[0].z) || (1 != rgn.dstOffsets[1].z)) { |
| 2674 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2675 | HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_09a001f8, |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 2676 | "vkCmdBlitImage: region [%d], dest image of type VK_IMAGE_TYPE_1D or VK_IMAGE_TYPE_2D with " |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2677 | "dstOffset[].z values of (%1d, %1d). These must be (0, 1).", |
| 2678 | i, rgn.dstOffsets[0].z, rgn.dstOffsets[1].z); |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 2679 | } |
| 2680 | } |
| 2681 | |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2682 | oob = false; |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 2683 | if ((rgn.dstOffsets[0].x < 0) || (rgn.dstOffsets[0].x > static_cast<int32_t>(dst_extent.width)) || |
| 2684 | (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] | 2685 | oob = true; |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2686 | skip |= |
| 2687 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2688 | HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_09a001f0, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2689 | "vkCmdBlitImage: region [%d] dstOffset[].x values (%1d, %1d) exceed dstSubresource width extent (%1d).", |
| 2690 | i, rgn.dstOffsets[0].x, rgn.dstOffsets[1].x, dst_extent.width); |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 2691 | } |
| 2692 | if ((rgn.dstOffsets[0].y < 0) || (rgn.dstOffsets[0].y > static_cast<int32_t>(dst_extent.height)) || |
| 2693 | (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] | 2694 | oob = true; |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 2695 | skip |= log_msg( |
| 2696 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2697 | HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_09a001f2, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2698 | "vkCmdBlitImage: region [%d] dstOffset[].y values (%1d, %1d) exceed dstSubresource height extent (%1d).", i, |
| 2699 | rgn.dstOffsets[0].y, rgn.dstOffsets[1].y, dst_extent.height); |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 2700 | } |
| 2701 | if ((rgn.dstOffsets[0].z < 0) || (rgn.dstOffsets[0].z > static_cast<int32_t>(dst_extent.depth)) || |
| 2702 | (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] | 2703 | oob = true; |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2704 | skip |= |
| 2705 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2706 | HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_09a001f6, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2707 | "vkCmdBlitImage: region [%d] dstOffset[].z values (%1d, %1d) exceed dstSubresource depth extent (%1d).", |
| 2708 | i, rgn.dstOffsets[0].z, rgn.dstOffsets[1].z, dst_extent.depth); |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 2709 | } |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2710 | if (rgn.dstSubresource.mipLevel >= dst_image_state->createInfo.mipLevels) { |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 2711 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2712 | HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_184001b0, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2713 | "vkCmdBlitImage: region [%d] destination image, attempt to access a non-existant mip level %1d.", i, |
| 2714 | rgn.dstSubresource.mipLevel); |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2715 | } else if (oob) { |
| 2716 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2717 | HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_184001b0, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2718 | "vkCmdBlitImage: region [%d] destination image blit region exceeds image dimensions.", i); |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 2719 | } |
| 2720 | |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2721 | if ((VK_IMAGE_TYPE_3D == src_type) || (VK_IMAGE_TYPE_3D == dst_type)) { |
| 2722 | if ((0 != rgn.srcSubresource.baseArrayLayer) || (1 != rgn.srcSubresource.layerCount) || |
| 2723 | (0 != rgn.dstSubresource.baseArrayLayer) || (1 != rgn.dstSubresource.layerCount)) { |
| 2724 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2725 | HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_09a001e0, |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2726 | "vkCmdBlitImage: region [%d] blit to/from a 3D image type with a non-zero baseArrayLayer, or a " |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2727 | "layerCount other than 1.", |
| 2728 | i); |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 2729 | } |
| 2730 | } |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2731 | } // per-region checks |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 2732 | } else { |
| 2733 | assert(0); |
| 2734 | } |
| 2735 | return skip; |
| 2736 | } |
| 2737 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 2738 | void PreCallRecordCmdBlitImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state, |
Norbert Garnys | 7bd4c2c | 2017-11-16 10:58:04 +0100 | [diff] [blame] | 2739 | IMAGE_STATE *dst_image_state, uint32_t region_count, const VkImageBlit *regions, |
| 2740 | VkImageLayout src_image_layout, VkImageLayout dst_image_layout) { |
| 2741 | // Make sure that all image slices are updated to correct layout |
| 2742 | for (uint32_t i = 0; i < region_count; ++i) { |
| 2743 | SetImageLayout(device_data, cb_node, src_image_state, regions[i].srcSubresource, src_image_layout); |
| 2744 | SetImageLayout(device_data, cb_node, dst_image_state, regions[i].dstSubresource, dst_image_layout); |
| 2745 | } |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 2746 | // Update bindings between images and cmd buffer |
| 2747 | AddCommandBufferBindingImage(device_data, cb_node, src_image_state); |
| 2748 | AddCommandBufferBindingImage(device_data, cb_node, dst_image_state); |
| 2749 | |
| 2750 | std::function<bool()> function = [=]() { return ValidateImageMemoryIsValid(device_data, src_image_state, "vkCmdBlitImage()"); }; |
Tobin Ehlis | a17a529 | 2017-07-28 12:11:30 -0600 | [diff] [blame] | 2751 | cb_node->queue_submit_functions.push_back(function); |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 2752 | function = [=]() { |
| 2753 | SetImageMemoryValid(device_data, dst_image_state, true); |
| 2754 | return false; |
| 2755 | }; |
Tobin Ehlis | a17a529 | 2017-07-28 12:11:30 -0600 | [diff] [blame] | 2756 | cb_node->queue_submit_functions.push_back(function); |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 2757 | } |
| 2758 | |
Tony Barbour | df013b9 | 2017-01-25 12:53:48 -0700 | [diff] [blame] | 2759 | // This validates that the initial layout specified in the command buffer for |
| 2760 | // the IMAGE is the same |
| 2761 | // as the global IMAGE layout |
Tony Barbour | e0c5cc9 | 2017-02-08 13:53:39 -0700 | [diff] [blame] | 2762 | bool ValidateCmdBufImageLayouts(layer_data *device_data, GLOBAL_CB_NODE *pCB, |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 2763 | std::unordered_map<ImageSubresourcePair, IMAGE_LAYOUT_NODE> const &globalImageLayoutMap, |
| 2764 | std::unordered_map<ImageSubresourcePair, IMAGE_LAYOUT_NODE> &overlayLayoutMap) { |
Mark Lobodzinski | b0dd947 | 2017-02-07 16:38:17 -0700 | [diff] [blame] | 2765 | bool skip = false; |
Tony Barbour | df013b9 | 2017-01-25 12:53:48 -0700 | [diff] [blame] | 2766 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
Mark Lobodzinski | 4a3065e | 2017-02-07 16:36:03 -0700 | [diff] [blame] | 2767 | for (auto cb_image_data : pCB->imageLayoutMap) { |
| 2768 | VkImageLayout imageLayout; |
Tony Barbour | df013b9 | 2017-01-25 12:53:48 -0700 | [diff] [blame] | 2769 | |
Dave Houlton | b3f4b28 | 2018-02-22 16:25:16 -0700 | [diff] [blame] | 2770 | if (FindLayout(device_data, overlayLayoutMap, cb_image_data.first, imageLayout) || |
| 2771 | FindLayout(device_data, globalImageLayoutMap, cb_image_data.first, imageLayout)) { |
Mark Lobodzinski | 4a3065e | 2017-02-07 16:36:03 -0700 | [diff] [blame] | 2772 | if (cb_image_data.second.initialLayout == VK_IMAGE_LAYOUT_UNDEFINED) { |
| 2773 | // TODO: Set memory invalid which is in mem_tracker currently |
| 2774 | } else if (imageLayout != cb_image_data.second.initialLayout) { |
| 2775 | if (cb_image_data.first.hasSubresource) { |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 2776 | skip |= log_msg( |
| 2777 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2778 | HandleToUint64(pCB->commandBuffer), DRAWSTATE_INVALID_IMAGE_LAYOUT, |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 2779 | "Cannot submit cmd buffer using image (0x%" PRIx64 |
| 2780 | ") [sub-resource: aspectMask 0x%X array layer %u, mip level %u], with layout %s when first use is %s.", |
| 2781 | HandleToUint64(cb_image_data.first.image), cb_image_data.first.subresource.aspectMask, |
| 2782 | cb_image_data.first.subresource.arrayLayer, cb_image_data.first.subresource.mipLevel, |
| 2783 | string_VkImageLayout(imageLayout), string_VkImageLayout(cb_image_data.second.initialLayout)); |
Mark Lobodzinski | 4a3065e | 2017-02-07 16:36:03 -0700 | [diff] [blame] | 2784 | } else { |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 2785 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2786 | HandleToUint64(pCB->commandBuffer), DRAWSTATE_INVALID_IMAGE_LAYOUT, |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 2787 | "Cannot submit cmd buffer using image (0x%" PRIx64 ") with layout %s when first use is %s.", |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 2788 | HandleToUint64(cb_image_data.first.image), string_VkImageLayout(imageLayout), |
| 2789 | string_VkImageLayout(cb_image_data.second.initialLayout)); |
Mark Lobodzinski | 4a3065e | 2017-02-07 16:36:03 -0700 | [diff] [blame] | 2790 | } |
| 2791 | } |
Chris Forbes | f9d7acd | 2017-06-26 17:57:39 -0700 | [diff] [blame] | 2792 | SetLayout(overlayLayoutMap, cb_image_data.first, cb_image_data.second.layout); |
Mark Lobodzinski | 4a3065e | 2017-02-07 16:36:03 -0700 | [diff] [blame] | 2793 | } |
| 2794 | } |
Mark Lobodzinski | b0dd947 | 2017-02-07 16:38:17 -0700 | [diff] [blame] | 2795 | return skip; |
Mark Lobodzinski | 4a3065e | 2017-02-07 16:36:03 -0700 | [diff] [blame] | 2796 | } |
Mark Lobodzinski | b3829a5 | 2017-02-07 16:55:53 -0700 | [diff] [blame] | 2797 | |
Tony Barbour | df013b9 | 2017-01-25 12:53:48 -0700 | [diff] [blame] | 2798 | void UpdateCmdBufImageLayouts(layer_data *device_data, GLOBAL_CB_NODE *pCB) { |
| 2799 | for (auto cb_image_data : pCB->imageLayoutMap) { |
| 2800 | VkImageLayout imageLayout; |
| 2801 | FindGlobalLayout(device_data, cb_image_data.first, imageLayout); |
| 2802 | SetGlobalLayout(device_data, cb_image_data.first, cb_image_data.second.layout); |
| 2803 | } |
| 2804 | } |
| 2805 | |
Mark Lobodzinski | b3829a5 | 2017-02-07 16:55:53 -0700 | [diff] [blame] | 2806 | // Print readable FlagBits in FlagMask |
| 2807 | static std::string string_VkAccessFlags(VkAccessFlags accessMask) { |
| 2808 | std::string result; |
| 2809 | std::string separator; |
| 2810 | |
| 2811 | if (accessMask == 0) { |
| 2812 | result = "[None]"; |
| 2813 | } else { |
| 2814 | result = "["; |
| 2815 | for (auto i = 0; i < 32; i++) { |
| 2816 | if (accessMask & (1 << i)) { |
| 2817 | result = result + separator + string_VkAccessFlagBits((VkAccessFlagBits)(1 << i)); |
| 2818 | separator = " | "; |
| 2819 | } |
| 2820 | } |
| 2821 | result = result + "]"; |
| 2822 | } |
| 2823 | return result; |
| 2824 | } |
| 2825 | |
Mark Lobodzinski | 9a8d40f | 2017-02-07 17:00:12 -0700 | [diff] [blame] | 2826 | // AccessFlags MUST have 'required_bit' set, and may have one or more of 'optional_bits' set. If required_bit is zero, accessMask |
| 2827 | // must have at least one of 'optional_bits' set |
Mark Lobodzinski | b3829a5 | 2017-02-07 16:55:53 -0700 | [diff] [blame] | 2828 | // 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] | 2829 | static bool ValidateMaskBits(core_validation::layer_data *device_data, VkCommandBuffer cmdBuffer, const VkAccessFlags &accessMask, |
| 2830 | const VkImageLayout &layout, VkAccessFlags required_bit, VkAccessFlags optional_bits, |
| 2831 | const char *type) { |
| 2832 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 2833 | bool skip = false; |
Mark Lobodzinski | b3829a5 | 2017-02-07 16:55:53 -0700 | [diff] [blame] | 2834 | |
| 2835 | if ((accessMask & required_bit) || (!required_bit && (accessMask & optional_bits))) { |
| 2836 | if (accessMask & ~(required_bit | optional_bits)) { |
| 2837 | // TODO: Verify against Valid Use |
Mark Lobodzinski | 0827aec | 2017-03-21 16:41:45 -0600 | [diff] [blame] | 2838 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2839 | HandleToUint64(cmdBuffer), DRAWSTATE_INVALID_BARRIER, |
Mark Lobodzinski | 9a8d40f | 2017-02-07 17:00:12 -0700 | [diff] [blame] | 2840 | "Additional bits in %s accessMask 0x%X %s are specified when layout is %s.", type, accessMask, |
| 2841 | string_VkAccessFlags(accessMask).c_str(), string_VkImageLayout(layout)); |
Mark Lobodzinski | b3829a5 | 2017-02-07 16:55:53 -0700 | [diff] [blame] | 2842 | } |
| 2843 | } else { |
| 2844 | if (!required_bit) { |
Mark Lobodzinski | 0827aec | 2017-03-21 16:41:45 -0600 | [diff] [blame] | 2845 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2846 | HandleToUint64(cmdBuffer), DRAWSTATE_INVALID_BARRIER, |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 2847 | "%s AccessMask %d %s must contain at least one of access bits %d %s when layout is %s, unless the app " |
| 2848 | "has previously added a barrier for this transition.", |
Mark Lobodzinski | 9a8d40f | 2017-02-07 17:00:12 -0700 | [diff] [blame] | 2849 | type, accessMask, string_VkAccessFlags(accessMask).c_str(), optional_bits, |
| 2850 | string_VkAccessFlags(optional_bits).c_str(), string_VkImageLayout(layout)); |
Mark Lobodzinski | b3829a5 | 2017-02-07 16:55:53 -0700 | [diff] [blame] | 2851 | } else { |
| 2852 | std::string opt_bits; |
| 2853 | if (optional_bits != 0) { |
| 2854 | std::stringstream ss; |
| 2855 | ss << optional_bits; |
| 2856 | opt_bits = "and may have optional bits " + ss.str() + ' ' + string_VkAccessFlags(optional_bits); |
| 2857 | } |
Mark Lobodzinski | 0827aec | 2017-03-21 16:41:45 -0600 | [diff] [blame] | 2858 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2859 | HandleToUint64(cmdBuffer), DRAWSTATE_INVALID_BARRIER, |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 2860 | "%s AccessMask %d %s must have required access bit %d %s %s when layout is %s, unless the app has " |
| 2861 | "previously added a barrier for this transition.", |
Mark Lobodzinski | 9a8d40f | 2017-02-07 17:00:12 -0700 | [diff] [blame] | 2862 | type, accessMask, string_VkAccessFlags(accessMask).c_str(), required_bit, |
| 2863 | 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] | 2864 | } |
| 2865 | } |
Mark Lobodzinski | 9a8d40f | 2017-02-07 17:00:12 -0700 | [diff] [blame] | 2866 | return skip; |
Mark Lobodzinski | b3829a5 | 2017-02-07 16:55:53 -0700 | [diff] [blame] | 2867 | } |
| 2868 | |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 2869 | // 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] | 2870 | // VkAttachmentDescription structs that are used by the sub-passes of a renderpass. Initial check is to make sure that READ_ONLY |
| 2871 | // layout attachments don't have CLEAR as their loadOp. |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 2872 | bool ValidateLayoutVsAttachmentDescription(const debug_report_data *report_data, const VkImageLayout first_layout, |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 2873 | const uint32_t attachment, const VkAttachmentDescription &attachment_description) { |
| 2874 | bool skip = false; |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 2875 | // Verify that initial loadOp on READ_ONLY attachments is not CLEAR |
| 2876 | if (attachment_description.loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR) { |
| 2877 | if ((first_layout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL) || |
| 2878 | (first_layout == VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL)) { |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 2879 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2880 | VALIDATION_ERROR_12200688, "Cannot clear attachment %d with invalid first layout %s.", attachment, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2881 | string_VkImageLayout(first_layout)); |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 2882 | } |
| 2883 | } |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 2884 | return skip; |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 2885 | } |
| 2886 | |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 2887 | bool ValidateLayouts(core_validation::layer_data *device_data, VkDevice device, const VkRenderPassCreateInfo *pCreateInfo) { |
| 2888 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 2889 | bool skip = false; |
| 2890 | |
Jason Ekstrand | a190630 | 2017-12-03 20:16:32 -0800 | [diff] [blame] | 2891 | for (uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) { |
| 2892 | VkFormat format = pCreateInfo->pAttachments[i].format; |
| 2893 | if (pCreateInfo->pAttachments[i].initialLayout == VK_IMAGE_LAYOUT_UNDEFINED) { |
| 2894 | if ((FormatIsColor(format) || FormatHasDepth(format)) && |
| 2895 | pCreateInfo->pAttachments[i].loadOp == VK_ATTACHMENT_LOAD_OP_LOAD) { |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 2896 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2897 | DRAWSTATE_INVALID_RENDERPASS, |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 2898 | "Render pass has an attachment with loadOp == VK_ATTACHMENT_LOAD_OP_LOAD and initialLayout == " |
| 2899 | "VK_IMAGE_LAYOUT_UNDEFINED. This is probably not what you intended. Consider using " |
| 2900 | "VK_ATTACHMENT_LOAD_OP_DONT_CARE instead if the image truely is undefined at the start of the " |
| 2901 | "render pass."); |
Jason Ekstrand | a190630 | 2017-12-03 20:16:32 -0800 | [diff] [blame] | 2902 | } |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 2903 | if (FormatHasStencil(format) && pCreateInfo->pAttachments[i].stencilLoadOp == VK_ATTACHMENT_LOAD_OP_LOAD) { |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 2904 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2905 | DRAWSTATE_INVALID_RENDERPASS, |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 2906 | "Render pass has an attachment with stencilLoadOp == VK_ATTACHMENT_LOAD_OP_LOAD and initialLayout " |
| 2907 | "== VK_IMAGE_LAYOUT_UNDEFINED. This is probably not what you intended. Consider using " |
| 2908 | "VK_ATTACHMENT_LOAD_OP_DONT_CARE instead if the image truely is undefined at the start of the " |
| 2909 | "render pass."); |
Jason Ekstrand | a190630 | 2017-12-03 20:16:32 -0800 | [diff] [blame] | 2910 | } |
| 2911 | } |
| 2912 | } |
| 2913 | |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 2914 | // Track when we're observing the first use of an attachment |
| 2915 | std::vector<bool> attach_first_use(pCreateInfo->attachmentCount, true); |
| 2916 | for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) { |
| 2917 | const VkSubpassDescription &subpass = pCreateInfo->pSubpasses[i]; |
Cort Stratton | 7547f77 | 2017-05-04 15:18:52 -0700 | [diff] [blame] | 2918 | |
| 2919 | // Check input attachments first, so we can detect first-use-as-input for VU #00349 |
| 2920 | for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) { |
| 2921 | auto attach_index = subpass.pInputAttachments[j].attachment; |
| 2922 | if (attach_index == VK_ATTACHMENT_UNUSED) continue; |
| 2923 | |
| 2924 | switch (subpass.pInputAttachments[j].layout) { |
| 2925 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: |
| 2926 | case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: |
| 2927 | // These are ideal. |
| 2928 | break; |
| 2929 | |
| 2930 | case VK_IMAGE_LAYOUT_GENERAL: |
| 2931 | // May not be optimal. TODO: reconsider this warning based on other constraints. |
| 2932 | skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2933 | VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, DRAWSTATE_INVALID_IMAGE_LAYOUT, |
Cort Stratton | 7547f77 | 2017-05-04 15:18:52 -0700 | [diff] [blame] | 2934 | "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL."); |
| 2935 | break; |
| 2936 | |
| 2937 | default: |
| 2938 | // No other layouts are acceptable |
| 2939 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2940 | DRAWSTATE_INVALID_IMAGE_LAYOUT, |
Cort Stratton | 7547f77 | 2017-05-04 15:18:52 -0700 | [diff] [blame] | 2941 | "Layout for input attachment is %s but can only be READ_ONLY_OPTIMAL or GENERAL.", |
| 2942 | string_VkImageLayout(subpass.pInputAttachments[j].layout)); |
| 2943 | } |
| 2944 | |
| 2945 | VkImageLayout layout = subpass.pInputAttachments[j].layout; |
| 2946 | bool found_layout_mismatch = subpass.pDepthStencilAttachment && |
| 2947 | subpass.pDepthStencilAttachment->attachment == attach_index && |
| 2948 | subpass.pDepthStencilAttachment->layout != layout; |
| 2949 | for (uint32_t c = 0; !found_layout_mismatch && c < subpass.colorAttachmentCount; ++c) { |
| 2950 | found_layout_mismatch = |
| 2951 | (subpass.pColorAttachments[c].attachment == attach_index && subpass.pColorAttachments[c].layout != layout); |
| 2952 | } |
| 2953 | if (found_layout_mismatch) { |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 2954 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2955 | VALIDATION_ERROR_140006ae, |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 2956 | "CreateRenderPass: Subpass %u pInputAttachments[%u] (%u) has layout %u, but is also used as a " |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2957 | "depth/color attachment with a different layout.", |
| 2958 | i, j, attach_index, layout); |
Cort Stratton | 7547f77 | 2017-05-04 15:18:52 -0700 | [diff] [blame] | 2959 | } |
| 2960 | |
| 2961 | if (attach_first_use[attach_index]) { |
| 2962 | skip |= ValidateLayoutVsAttachmentDescription(report_data, subpass.pInputAttachments[j].layout, attach_index, |
| 2963 | pCreateInfo->pAttachments[attach_index]); |
| 2964 | |
| 2965 | bool used_as_depth = |
| 2966 | (subpass.pDepthStencilAttachment != NULL && subpass.pDepthStencilAttachment->attachment == attach_index); |
| 2967 | bool used_as_color = false; |
| 2968 | for (uint32_t k = 0; !used_as_depth && !used_as_color && k < subpass.colorAttachmentCount; ++k) { |
| 2969 | used_as_color = (subpass.pColorAttachments[k].attachment == attach_index); |
| 2970 | } |
| 2971 | if (!used_as_depth && !used_as_color && |
| 2972 | pCreateInfo->pAttachments[attach_index].loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR) { |
| 2973 | skip |= log_msg( |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 2974 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2975 | VALIDATION_ERROR_1400069c, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2976 | "CreateRenderPass: attachment %u is first used as an input attachment in subpass %u with loadOp=CLEAR.", |
| 2977 | attach_index, attach_index); |
Cort Stratton | 7547f77 | 2017-05-04 15:18:52 -0700 | [diff] [blame] | 2978 | } |
| 2979 | } |
| 2980 | attach_first_use[attach_index] = false; |
| 2981 | } |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 2982 | for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) { |
| 2983 | auto attach_index = subpass.pColorAttachments[j].attachment; |
| 2984 | if (attach_index == VK_ATTACHMENT_UNUSED) continue; |
| 2985 | |
Tobin Ehlis | bb03e5f | 2017-05-11 08:52:51 -0600 | [diff] [blame] | 2986 | // TODO: Need a way to validate shared presentable images here, currently just allowing |
| 2987 | // VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR |
| 2988 | // 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] | 2989 | switch (subpass.pColorAttachments[j].layout) { |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 2990 | case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2991 | // This is ideal. |
Tobin Ehlis | bb03e5f | 2017-05-11 08:52:51 -0600 | [diff] [blame] | 2992 | case VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR: |
| 2993 | // 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] | 2994 | break; |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 2995 | |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 2996 | case VK_IMAGE_LAYOUT_GENERAL: |
| 2997 | // May not be optimal; TODO: reconsider this warning based on other constraints? |
| 2998 | skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 2999 | VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, DRAWSTATE_INVALID_IMAGE_LAYOUT, |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 3000 | "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL."); |
| 3001 | break; |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 3002 | |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 3003 | default: |
| 3004 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3005 | DRAWSTATE_INVALID_IMAGE_LAYOUT, |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 3006 | "Layout for color attachment is %s but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.", |
| 3007 | string_VkImageLayout(subpass.pColorAttachments[j].layout)); |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 3008 | } |
| 3009 | |
| 3010 | if (attach_first_use[attach_index]) { |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 3011 | skip |= ValidateLayoutVsAttachmentDescription(report_data, subpass.pColorAttachments[j].layout, attach_index, |
| 3012 | pCreateInfo->pAttachments[attach_index]); |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 3013 | } |
| 3014 | attach_first_use[attach_index] = false; |
| 3015 | } |
Lenny Komow | b79f04a | 2017-09-18 17:07:00 -0600 | [diff] [blame] | 3016 | |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 3017 | if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) { |
| 3018 | switch (subpass.pDepthStencilAttachment->layout) { |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 3019 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: |
| 3020 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: |
| 3021 | // These are ideal. |
Lenny Komow | b79f04a | 2017-09-18 17:07:00 -0600 | [diff] [blame] | 3022 | break; |
Lenny Komow | b79f04a | 2017-09-18 17:07:00 -0600 | [diff] [blame] | 3023 | |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 3024 | case VK_IMAGE_LAYOUT_GENERAL: |
| 3025 | // May not be optimal; TODO: reconsider this warning based on other constraints? GENERAL can be better than |
| 3026 | // doing a bunch of transitions. |
| 3027 | skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3028 | VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, DRAWSTATE_INVALID_IMAGE_LAYOUT, |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 3029 | "GENERAL layout for depth attachment may not give optimal performance."); |
| 3030 | break; |
| 3031 | |
| 3032 | case VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL_KHR: |
| 3033 | case VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL_KHR: |
| 3034 | if (GetDeviceExtensions(device_data)->vk_khr_maintenance2) { |
| 3035 | break; |
| 3036 | } else { |
| 3037 | // Intentionally fall through to generic error message |
| 3038 | } |
| 3039 | |
| 3040 | default: |
| 3041 | // No other layouts are acceptable |
| 3042 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3043 | DRAWSTATE_INVALID_IMAGE_LAYOUT, |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 3044 | "Layout for depth attachment is %s but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL, " |
| 3045 | "DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.", |
| 3046 | string_VkImageLayout(subpass.pDepthStencilAttachment->layout)); |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 3047 | } |
| 3048 | |
| 3049 | auto attach_index = subpass.pDepthStencilAttachment->attachment; |
| 3050 | if (attach_first_use[attach_index]) { |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 3051 | skip |= ValidateLayoutVsAttachmentDescription(report_data, subpass.pDepthStencilAttachment->layout, attach_index, |
| 3052 | pCreateInfo->pAttachments[attach_index]); |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 3053 | } |
| 3054 | attach_first_use[attach_index] = false; |
| 3055 | } |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 3056 | } |
| 3057 | return skip; |
| 3058 | } |
Mark Lobodzinski | 08f14fa | 2017-02-07 17:20:06 -0700 | [diff] [blame] | 3059 | |
| 3060 | // 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] | 3061 | bool ValidateMapImageLayouts(core_validation::layer_data *device_data, VkDevice device, DEVICE_MEM_INFO const *mem_info, |
| 3062 | VkDeviceSize offset, VkDeviceSize end_offset) { |
| 3063 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 3064 | bool skip = false; |
| 3065 | // Iterate over all bound image ranges and verify that for any that overlap the map ranges, the layouts are |
| 3066 | // VK_IMAGE_LAYOUT_PREINITIALIZED or VK_IMAGE_LAYOUT_GENERAL |
Mark Lobodzinski | 08f14fa | 2017-02-07 17:20:06 -0700 | [diff] [blame] | 3067 | // TODO : This can be optimized if we store ranges based on starting address and early exit when we pass our range |
| 3068 | for (auto image_handle : mem_info->bound_images) { |
| 3069 | auto img_it = mem_info->bound_ranges.find(image_handle); |
| 3070 | if (img_it != mem_info->bound_ranges.end()) { |
Mark Lobodzinski | ac23ec8 | 2017-02-07 17:21:55 -0700 | [diff] [blame] | 3071 | if (rangesIntersect(device_data, &img_it->second, offset, end_offset)) { |
Mark Lobodzinski | 08f14fa | 2017-02-07 17:20:06 -0700 | [diff] [blame] | 3072 | std::vector<VkImageLayout> layouts; |
Mark Lobodzinski | ac23ec8 | 2017-02-07 17:21:55 -0700 | [diff] [blame] | 3073 | if (FindLayouts(device_data, VkImage(image_handle), layouts)) { |
Mark Lobodzinski | 08f14fa | 2017-02-07 17:20:06 -0700 | [diff] [blame] | 3074 | for (auto layout : layouts) { |
| 3075 | if (layout != VK_IMAGE_LAYOUT_PREINITIALIZED && layout != VK_IMAGE_LAYOUT_GENERAL) { |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 3076 | skip |= |
| 3077 | log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_MEMORY_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3078 | HandleToUint64(mem_info->mem), DRAWSTATE_INVALID_IMAGE_LAYOUT, |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 3079 | "Mapping an image with layout %s can result in undefined behavior if this memory is used " |
| 3080 | "by the device. Only GENERAL or PREINITIALIZED should be used.", |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 3081 | string_VkImageLayout(layout)); |
Mark Lobodzinski | 08f14fa | 2017-02-07 17:20:06 -0700 | [diff] [blame] | 3082 | } |
| 3083 | } |
| 3084 | } |
| 3085 | } |
| 3086 | } |
| 3087 | } |
Mark Lobodzinski | ac23ec8 | 2017-02-07 17:21:55 -0700 | [diff] [blame] | 3088 | return skip; |
Mark Lobodzinski | 08f14fa | 2017-02-07 17:20:06 -0700 | [diff] [blame] | 3089 | } |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 3090 | |
| 3091 | // Helper function to validate correct usage bits set for buffers or images. Verify that (actual & desired) flags != 0 or, if strict |
| 3092 | // is true, verify that (actual & desired) flags == desired |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 3093 | 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] | 3094 | 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] | 3095 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 3096 | |
| 3097 | bool correct_usage = false; |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 3098 | bool skip = false; |
Mark Lobodzinski | 3382637 | 2017-04-13 11:10:11 -0600 | [diff] [blame] | 3099 | const char *type_str = object_string[obj_type]; |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 3100 | if (strict) { |
| 3101 | correct_usage = ((actual & desired) == desired); |
| 3102 | } else { |
| 3103 | correct_usage = ((actual & desired) != 0); |
| 3104 | } |
| 3105 | if (!correct_usage) { |
| 3106 | if (msgCode == -1) { |
| 3107 | // TODO: Fix callers with msgCode == -1 to use correct validation checks. |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 3108 | skip = |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 3109 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, get_debug_report_enum[obj_type], obj_handle, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3110 | MEMTRACK_INVALID_USAGE_FLAG, |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 3111 | "Invalid usage flag for %s 0x%" PRIx64 " used by %s. In this case, %s should have %s set during creation.", |
| 3112 | type_str, obj_handle, func_name, type_str, usage_str); |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 3113 | } else { |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 3114 | skip = |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3115 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, get_debug_report_enum[obj_type], obj_handle, msgCode, |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 3116 | "Invalid usage flag for %s 0x%" PRIx64 " used by %s. In this case, %s should have %s set during creation.", |
| 3117 | type_str, obj_handle, func_name, type_str, usage_str); |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 3118 | } |
| 3119 | } |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 3120 | return skip; |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 3121 | } |
| 3122 | |
| 3123 | // Helper function to validate usage flags for buffers. For given buffer_state send actual vs. desired usage off to helper above |
| 3124 | // where an error will be flagged if usage is not correct |
Chris Forbes | 8fdba30 | 2017-04-24 18:34:28 -0700 | [diff] [blame] | 3125 | 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] | 3126 | int32_t const msgCode, char const *func_name, char const *usage_string) { |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 3127 | return validate_usage_flags(device_data, image_state->createInfo.usage, desired, strict, HandleToUint64(image_state->image), |
| 3128 | kVulkanObjectTypeImage, msgCode, func_name, usage_string); |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 3129 | } |
| 3130 | |
| 3131 | // Helper function to validate usage flags for buffers. For given buffer_state send actual vs. desired usage off to helper above |
| 3132 | // where an error will be flagged if usage is not correct |
Chris Forbes | 8fdba30 | 2017-04-24 18:34:28 -0700 | [diff] [blame] | 3133 | 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] | 3134 | int32_t const msgCode, char const *func_name, char const *usage_string) { |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 3135 | return validate_usage_flags(device_data, buffer_state->createInfo.usage, desired, strict, HandleToUint64(buffer_state->buffer), |
| 3136 | kVulkanObjectTypeBuffer, msgCode, func_name, usage_string); |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 3137 | } |
| 3138 | |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 3139 | bool PreCallValidateCreateBuffer(layer_data *device_data, const VkBufferCreateInfo *pCreateInfo) { |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 3140 | bool skip = false; |
Mark Lobodzinski | 847b60c | 2017-03-13 09:32:45 -0600 | [diff] [blame] | 3141 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 3142 | |
Chris Forbes | e0f511c | 2017-06-14 12:38:01 -0700 | [diff] [blame] | 3143 | // TODO: Add check for VALIDATION_ERROR_1ec0071e (sparse address space accounting) |
Mark Lobodzinski | 847b60c | 2017-03-13 09:32:45 -0600 | [diff] [blame] | 3144 | |
| 3145 | if ((pCreateInfo->flags & VK_BUFFER_CREATE_SPARSE_BINDING_BIT) && (!GetEnabledFeatures(device_data)->sparseBinding)) { |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 3146 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3147 | VALIDATION_ERROR_01400726, |
Mark Lobodzinski | 847b60c | 2017-03-13 09:32:45 -0600 | [diff] [blame] | 3148 | "vkCreateBuffer(): the sparseBinding device feature is disabled: Buffers cannot be created with the " |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3149 | "VK_BUFFER_CREATE_SPARSE_BINDING_BIT set."); |
Mark Lobodzinski | 847b60c | 2017-03-13 09:32:45 -0600 | [diff] [blame] | 3150 | } |
Mark Lobodzinski | af35506 | 2017-03-13 09:35:01 -0600 | [diff] [blame] | 3151 | |
| 3152 | if ((pCreateInfo->flags & VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT) && (!GetEnabledFeatures(device_data)->sparseResidencyBuffer)) { |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 3153 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3154 | VALIDATION_ERROR_01400728, |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 3155 | "vkCreateBuffer(): the sparseResidencyBuffer device feature is disabled: Buffers cannot be created with " |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3156 | "the VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT set."); |
Mark Lobodzinski | af35506 | 2017-03-13 09:35:01 -0600 | [diff] [blame] | 3157 | } |
Mark Lobodzinski | 035a4cf | 2017-03-13 09:45:07 -0600 | [diff] [blame] | 3158 | |
| 3159 | if ((pCreateInfo->flags & VK_BUFFER_CREATE_SPARSE_ALIASED_BIT) && (!GetEnabledFeatures(device_data)->sparseResidencyAliased)) { |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 3160 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3161 | VALIDATION_ERROR_0140072a, |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 3162 | "vkCreateBuffer(): the sparseResidencyAliased device feature is disabled: Buffers cannot be created with " |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3163 | "the VK_BUFFER_CREATE_SPARSE_ALIASED_BIT set."); |
Mark Lobodzinski | 035a4cf | 2017-03-13 09:45:07 -0600 | [diff] [blame] | 3164 | } |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 3165 | return skip; |
| 3166 | } |
| 3167 | |
| 3168 | void PostCallRecordCreateBuffer(layer_data *device_data, const VkBufferCreateInfo *pCreateInfo, VkBuffer *pBuffer) { |
| 3169 | // TODO : This doesn't create deep copy of pQueueFamilyIndices so need to fix that if/when we want that data to be valid |
| 3170 | GetBufferMap(device_data) |
| 3171 | ->insert(std::make_pair(*pBuffer, std::unique_ptr<BUFFER_STATE>(new BUFFER_STATE(*pBuffer, pCreateInfo)))); |
| 3172 | } |
| 3173 | |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 3174 | bool PreCallValidateCreateBufferView(layer_data *device_data, const VkBufferViewCreateInfo *pCreateInfo) { |
| 3175 | bool skip = false; |
| 3176 | BUFFER_STATE *buffer_state = GetBufferState(device_data, pCreateInfo->buffer); |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 3177 | // If this isn't a sparse buffer, it needs to have memory backing it at CreateBufferView time |
| 3178 | if (buffer_state) { |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3179 | skip |= ValidateMemoryIsBoundToBuffer(device_data, buffer_state, "vkCreateBufferView()", VALIDATION_ERROR_01a0074e); |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 3180 | // In order to create a valid buffer view, the buffer must have been created with at least one of the following flags: |
| 3181 | // UNIFORM_TEXEL_BUFFER_BIT or STORAGE_TEXEL_BUFFER_BIT |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 3182 | skip |= ValidateBufferUsageFlags( |
| 3183 | 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] | 3184 | VALIDATION_ERROR_01a00748, "vkCreateBufferView()", "VK_BUFFER_USAGE_[STORAGE|UNIFORM]_TEXEL_BUFFER_BIT"); |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 3185 | } |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 3186 | return skip; |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 3187 | } |
| 3188 | |
| 3189 | void PostCallRecordCreateBufferView(layer_data *device_data, const VkBufferViewCreateInfo *pCreateInfo, VkBufferView *pView) { |
| 3190 | (*GetBufferViewMap(device_data))[*pView] = std::unique_ptr<BUFFER_VIEW_STATE>(new BUFFER_VIEW_STATE(*pView, pCreateInfo)); |
| 3191 | } |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3192 | |
| 3193 | // For the given format verify that the aspect masks make sense |
| 3194 | bool ValidateImageAspectMask(layer_data *device_data, VkImage image, VkFormat format, VkImageAspectFlags aspect_mask, |
| 3195 | const char *func_name) { |
| 3196 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 3197 | bool skip = false; |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 3198 | if (FormatIsColor(format)) { |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3199 | 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] | 3200 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3201 | HandleToUint64(image), VALIDATION_ERROR_0a400c01, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3202 | "%s: Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.", func_name); |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3203 | } else if ((aspect_mask & VK_IMAGE_ASPECT_COLOR_BIT) != aspect_mask) { |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 3204 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3205 | HandleToUint64(image), VALIDATION_ERROR_0a400c01, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3206 | "%s: Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.", func_name); |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3207 | } |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 3208 | } else if (FormatIsDepthAndStencil(format)) { |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3209 | 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] | 3210 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3211 | HandleToUint64(image), VALIDATION_ERROR_0a400c01, |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 3212 | "%s: Depth/stencil image formats must have at least one of VK_IMAGE_ASPECT_DEPTH_BIT and " |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3213 | "VK_IMAGE_ASPECT_STENCIL_BIT set.", |
| 3214 | func_name); |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3215 | } 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] | 3216 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3217 | HandleToUint64(image), VALIDATION_ERROR_0a400c01, |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3218 | "%s: Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and " |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3219 | "VK_IMAGE_ASPECT_STENCIL_BIT set.", |
| 3220 | func_name); |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3221 | } |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 3222 | } else if (FormatIsDepthOnly(format)) { |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3223 | 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] | 3224 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3225 | HandleToUint64(image), VALIDATION_ERROR_0a400c01, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3226 | "%s: Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.", func_name); |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3227 | } else if ((aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) != aspect_mask) { |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 3228 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3229 | HandleToUint64(image), VALIDATION_ERROR_0a400c01, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3230 | "%s: Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.", func_name); |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3231 | } |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 3232 | } else if (FormatIsStencilOnly(format)) { |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3233 | 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] | 3234 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3235 | HandleToUint64(image), VALIDATION_ERROR_0a400c01, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3236 | "%s: Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.", func_name); |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3237 | } else if ((aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) != aspect_mask) { |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 3238 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3239 | HandleToUint64(image), VALIDATION_ERROR_0a400c01, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3240 | "%s: Stencil-only image formats can have only the VK_IMAGE_ASPECT_STENCIL_BIT set.", func_name); |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3241 | } |
Dave Houlton | 501b15b | 2018-03-30 15:07:41 -0600 | [diff] [blame] | 3242 | } else if (FormatIsMultiplane(format)) { |
| 3243 | VkImageAspectFlags valid_flags = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_PLANE_0_BIT | VK_IMAGE_ASPECT_PLANE_1_BIT; |
| 3244 | if (3 == FormatPlaneCount(format)) { |
| 3245 | valid_flags = valid_flags | VK_IMAGE_ASPECT_PLANE_2_BIT; |
| 3246 | } |
| 3247 | if ((aspect_mask & valid_flags) != aspect_mask) { |
| 3248 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 3249 | HandleToUint64(image), VALIDATION_ERROR_0a400c01, |
| 3250 | "%s: Multi-plane image formats may have only VK_IMAGE_ASPECT_COLOR_BIT or VK_IMAGE_ASPECT_PLANE_n_BITs " |
| 3251 | "set, where n = [0, 1, 2].", |
| 3252 | func_name); |
| 3253 | } |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3254 | } |
| 3255 | return skip; |
| 3256 | } |
| 3257 | |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 3258 | struct SubresourceRangeErrorCodes { |
| 3259 | UNIQUE_VALIDATION_ERROR_CODE base_mip_err, mip_count_err, base_layer_err, layer_count_err; |
| 3260 | }; |
| 3261 | |
| 3262 | bool ValidateImageSubresourceRange(const layer_data *device_data, const uint32_t image_mip_count, const uint32_t image_layer_count, |
| 3263 | const VkImageSubresourceRange &subresourceRange, const char *cmd_name, const char *param_name, |
| 3264 | const char *image_layer_count_var_name, const uint64_t image_handle, |
| 3265 | SubresourceRangeErrorCodes errorCodes) { |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3266 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 3267 | bool skip = false; |
Petr Kraus | 4d71868 | 2017-05-18 03:38:41 +0200 | [diff] [blame] | 3268 | |
| 3269 | // Validate mip levels |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 3270 | if (subresourceRange.baseMipLevel >= image_mip_count) { |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 3271 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, image_handle, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3272 | errorCodes.base_mip_err, |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 3273 | "%s: %s.baseMipLevel (= %" PRIu32 |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3274 | ") is greater or equal to the mip level count of the image (i.e. greater or equal to %" PRIu32 ").", |
| 3275 | cmd_name, param_name, subresourceRange.baseMipLevel, image_mip_count); |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 3276 | } |
Petr Kraus | 4d71868 | 2017-05-18 03:38:41 +0200 | [diff] [blame] | 3277 | |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 3278 | if (subresourceRange.levelCount != VK_REMAINING_MIP_LEVELS) { |
| 3279 | if (subresourceRange.levelCount == 0) { |
| 3280 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, image_handle, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3281 | errorCodes.mip_count_err, "%s: %s.levelCount is 0.", cmd_name, param_name); |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 3282 | } else { |
| 3283 | const uint64_t necessary_mip_count = uint64_t{subresourceRange.baseMipLevel} + uint64_t{subresourceRange.levelCount}; |
Petr Kraus | 4d71868 | 2017-05-18 03:38:41 +0200 | [diff] [blame] | 3284 | |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 3285 | if (necessary_mip_count > image_mip_count) { |
| 3286 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, image_handle, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3287 | errorCodes.mip_count_err, |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 3288 | "%s: %s.baseMipLevel + .levelCount (= %" PRIu32 " + %" PRIu32 " = %" PRIu64 |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3289 | ") is greater than the mip level count of the image (i.e. greater than %" PRIu32 ").", |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 3290 | cmd_name, param_name, subresourceRange.baseMipLevel, subresourceRange.levelCount, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3291 | necessary_mip_count, image_mip_count); |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 3292 | } |
Petr Kraus | 4d71868 | 2017-05-18 03:38:41 +0200 | [diff] [blame] | 3293 | } |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3294 | } |
Petr Kraus | 4d71868 | 2017-05-18 03:38:41 +0200 | [diff] [blame] | 3295 | |
| 3296 | // Validate array layers |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 3297 | if (subresourceRange.baseArrayLayer >= image_layer_count) { |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 3298 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, image_handle, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3299 | errorCodes.base_layer_err, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3300 | "%s: %s.baseArrayLayer (= %" PRIu32 |
| 3301 | ") is greater or equal to the %s of the image when it was created (i.e. greater or equal to %" PRIu32 ").", |
| 3302 | cmd_name, param_name, subresourceRange.baseArrayLayer, image_layer_count_var_name, image_layer_count); |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 3303 | } |
Petr Kraus | 4d71868 | 2017-05-18 03:38:41 +0200 | [diff] [blame] | 3304 | |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 3305 | if (subresourceRange.layerCount != VK_REMAINING_ARRAY_LAYERS) { |
| 3306 | if (subresourceRange.layerCount == 0) { |
| 3307 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, image_handle, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3308 | errorCodes.layer_count_err, "%s: %s.layerCount is 0.", cmd_name, param_name); |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 3309 | } else { |
| 3310 | const uint64_t necessary_layer_count = |
| 3311 | uint64_t{subresourceRange.baseArrayLayer} + uint64_t{subresourceRange.layerCount}; |
Petr Kraus | 8423f15 | 2017-05-26 01:20:04 +0200 | [diff] [blame] | 3312 | |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 3313 | if (necessary_layer_count > image_layer_count) { |
| 3314 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, image_handle, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3315 | errorCodes.layer_count_err, |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 3316 | "%s: %s.baseArrayLayer + .layerCount (= %" PRIu32 " + %" PRIu32 " = %" PRIu64 |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3317 | ") is greater than the %s of the image when it was created (i.e. greater than %" PRIu32 ").", |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 3318 | cmd_name, param_name, subresourceRange.baseArrayLayer, subresourceRange.layerCount, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3319 | necessary_layer_count, image_layer_count_var_name, image_layer_count); |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 3320 | } |
Petr Kraus | 4d71868 | 2017-05-18 03:38:41 +0200 | [diff] [blame] | 3321 | } |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3322 | } |
Petr Kraus | 4d71868 | 2017-05-18 03:38:41 +0200 | [diff] [blame] | 3323 | |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3324 | return skip; |
| 3325 | } |
| 3326 | |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 3327 | bool ValidateCreateImageViewSubresourceRange(const layer_data *device_data, const IMAGE_STATE *image_state, |
| 3328 | bool is_imageview_2d_type, const VkImageSubresourceRange &subresourceRange) { |
| 3329 | bool is_khr_maintenance1 = GetDeviceExtensions(device_data)->vk_khr_maintenance1; |
| 3330 | bool is_image_slicable = image_state->createInfo.imageType == VK_IMAGE_TYPE_3D && |
| 3331 | (image_state->createInfo.flags & VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT_KHR); |
| 3332 | bool is_3D_to_2D_map = is_khr_maintenance1 && is_image_slicable && is_imageview_2d_type; |
| 3333 | |
| 3334 | const auto image_layer_count = is_3D_to_2D_map ? image_state->createInfo.extent.depth : image_state->createInfo.arrayLayers; |
| 3335 | const auto image_layer_count_var_name = is_3D_to_2D_map ? "extent.depth" : "arrayLayers"; |
| 3336 | |
| 3337 | SubresourceRangeErrorCodes subresourceRangeErrorCodes = {}; |
| 3338 | subresourceRangeErrorCodes.base_mip_err = VALIDATION_ERROR_0ac00b8c; |
Mike Schuchardt | 8da1bb5 | 2018-02-22 10:46:31 -0700 | [diff] [blame] | 3339 | subresourceRangeErrorCodes.mip_count_err = VALIDATION_ERROR_0ac00d6c; |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 3340 | subresourceRangeErrorCodes.base_layer_err = |
| 3341 | is_khr_maintenance1 ? (is_3D_to_2D_map ? VALIDATION_ERROR_0ac00b98 : VALIDATION_ERROR_0ac00b94) : VALIDATION_ERROR_0ac00b90; |
| 3342 | subresourceRangeErrorCodes.layer_count_err = |
Mike Schuchardt | 8da1bb5 | 2018-02-22 10:46:31 -0700 | [diff] [blame] | 3343 | is_khr_maintenance1 ? (is_3D_to_2D_map ? VALIDATION_ERROR_0ac00b9a : VALIDATION_ERROR_0ac00b96) : VALIDATION_ERROR_0ac00d6e; |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 3344 | |
| 3345 | return ValidateImageSubresourceRange(device_data, image_state->createInfo.mipLevels, image_layer_count, subresourceRange, |
| 3346 | "vkCreateImageView", "pCreateInfo->subresourceRange", image_layer_count_var_name, |
| 3347 | HandleToUint64(image_state->image), subresourceRangeErrorCodes); |
| 3348 | } |
| 3349 | |
| 3350 | bool ValidateCmdClearColorSubresourceRange(const layer_data *device_data, const IMAGE_STATE *image_state, |
| 3351 | const VkImageSubresourceRange &subresourceRange, const char *param_name) { |
| 3352 | SubresourceRangeErrorCodes subresourceRangeErrorCodes = {}; |
| 3353 | subresourceRangeErrorCodes.base_mip_err = VALIDATION_ERROR_18800b7c; |
Mike Schuchardt | 8da1bb5 | 2018-02-22 10:46:31 -0700 | [diff] [blame] | 3354 | subresourceRangeErrorCodes.mip_count_err = VALIDATION_ERROR_18800d38; |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 3355 | subresourceRangeErrorCodes.base_layer_err = VALIDATION_ERROR_18800b80; |
Mike Schuchardt | 8da1bb5 | 2018-02-22 10:46:31 -0700 | [diff] [blame] | 3356 | subresourceRangeErrorCodes.layer_count_err = VALIDATION_ERROR_18800d3a; |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 3357 | |
| 3358 | return ValidateImageSubresourceRange(device_data, image_state->createInfo.mipLevels, image_state->createInfo.arrayLayers, |
| 3359 | subresourceRange, "vkCmdClearColorImage", param_name, "arrayLayers", |
| 3360 | HandleToUint64(image_state->image), subresourceRangeErrorCodes); |
| 3361 | } |
| 3362 | |
| 3363 | bool ValidateCmdClearDepthSubresourceRange(const layer_data *device_data, const IMAGE_STATE *image_state, |
| 3364 | const VkImageSubresourceRange &subresourceRange, const char *param_name) { |
| 3365 | SubresourceRangeErrorCodes subresourceRangeErrorCodes = {}; |
| 3366 | subresourceRangeErrorCodes.base_mip_err = VALIDATION_ERROR_18a00b84; |
Mike Schuchardt | 8da1bb5 | 2018-02-22 10:46:31 -0700 | [diff] [blame] | 3367 | subresourceRangeErrorCodes.mip_count_err = VALIDATION_ERROR_18a00d3c; |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 3368 | subresourceRangeErrorCodes.base_layer_err = VALIDATION_ERROR_18a00b88; |
Mike Schuchardt | 8da1bb5 | 2018-02-22 10:46:31 -0700 | [diff] [blame] | 3369 | subresourceRangeErrorCodes.layer_count_err = VALIDATION_ERROR_18a00d3e; |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 3370 | |
| 3371 | return ValidateImageSubresourceRange(device_data, image_state->createInfo.mipLevels, image_state->createInfo.arrayLayers, |
| 3372 | subresourceRange, "vkCmdClearDepthStencilImage", param_name, "arrayLayers", |
| 3373 | HandleToUint64(image_state->image), subresourceRangeErrorCodes); |
| 3374 | } |
| 3375 | |
| 3376 | bool ValidateImageBarrierSubresourceRange(const layer_data *device_data, const IMAGE_STATE *image_state, |
| 3377 | const VkImageSubresourceRange &subresourceRange, const char *cmd_name, |
| 3378 | const char *param_name) { |
| 3379 | SubresourceRangeErrorCodes subresourceRangeErrorCodes = {}; |
| 3380 | subresourceRangeErrorCodes.base_mip_err = VALIDATION_ERROR_0a000b9c; |
Mike Schuchardt | 8da1bb5 | 2018-02-22 10:46:31 -0700 | [diff] [blame] | 3381 | subresourceRangeErrorCodes.mip_count_err = VALIDATION_ERROR_0a000d78; |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 3382 | subresourceRangeErrorCodes.base_layer_err = VALIDATION_ERROR_0a000ba0; |
Mike Schuchardt | 8da1bb5 | 2018-02-22 10:46:31 -0700 | [diff] [blame] | 3383 | subresourceRangeErrorCodes.layer_count_err = VALIDATION_ERROR_0a000d7a; |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 3384 | |
| 3385 | return ValidateImageSubresourceRange(device_data, image_state->createInfo.mipLevels, image_state->createInfo.arrayLayers, |
| 3386 | subresourceRange, cmd_name, param_name, "arrayLayers", HandleToUint64(image_state->image), |
| 3387 | subresourceRangeErrorCodes); |
| 3388 | } |
| 3389 | |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3390 | bool PreCallValidateCreateImageView(layer_data *device_data, const VkImageViewCreateInfo *create_info) { |
| 3391 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 3392 | bool skip = false; |
| 3393 | IMAGE_STATE *image_state = GetImageState(device_data, create_info->image); |
| 3394 | if (image_state) { |
| 3395 | skip |= ValidateImageUsageFlags( |
| 3396 | device_data, image_state, |
| 3397 | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT | |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 3398 | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3399 | false, -1, "vkCreateImageView()", |
| 3400 | "VK_IMAGE_USAGE_[SAMPLED|STORAGE|COLOR_ATTACHMENT|DEPTH_STENCIL_ATTACHMENT|INPUT_ATTACHMENT]_BIT"); |
| 3401 | // 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] | 3402 | skip |= ValidateMemoryIsBoundToImage(device_data, image_state, "vkCreateImageView()", VALIDATION_ERROR_0ac007f8); |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3403 | // Checks imported from image layer |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 3404 | skip |= ValidateCreateImageViewSubresourceRange( |
| 3405 | device_data, image_state, |
| 3406 | create_info->viewType == VK_IMAGE_VIEW_TYPE_2D || create_info->viewType == VK_IMAGE_VIEW_TYPE_2D_ARRAY, |
| 3407 | create_info->subresourceRange); |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3408 | |
| 3409 | VkImageCreateFlags image_flags = image_state->createInfo.flags; |
| 3410 | VkFormat image_format = image_state->createInfo.format; |
Jeremy Kniager | cef491c | 2017-07-18 11:10:28 -0600 | [diff] [blame] | 3411 | VkImageUsageFlags image_usage = image_state->createInfo.usage; |
| 3412 | VkImageTiling image_tiling = image_state->createInfo.tiling; |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3413 | VkFormat view_format = create_info->format; |
| 3414 | VkImageAspectFlags aspect_mask = create_info->subresourceRange.aspectMask; |
Jeremy Kniager | 846ab73 | 2017-07-10 13:12:04 -0600 | [diff] [blame] | 3415 | VkImageType image_type = image_state->createInfo.imageType; |
| 3416 | VkImageViewType view_type = create_info->viewType; |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3417 | |
Dave Houlton | bd2e262 | 2018-04-10 16:41:14 -0600 | [diff] [blame] | 3418 | // If there's a chained VkImageViewUsageCreateInfo struct, modify image_usage to match |
| 3419 | auto chained_ivuci_struct = lvl_find_in_chain<VkImageViewUsageCreateInfoKHR>(create_info->pNext); |
| 3420 | if (chained_ivuci_struct) { |
| 3421 | if (chained_ivuci_struct->usage & ~image_usage) { |
| 3422 | std::stringstream ss; |
| 3423 | ss << "vkCreateImageView(): Chained VkImageViewUsageCreateInfo usage field (0x" << std::hex |
Dave Houlton | 0f3795b | 2018-04-13 15:04:35 -0600 | [diff] [blame^] | 3424 | << chained_ivuci_struct->usage << ") must not include flags not present in underlying image's usage (0x" |
Dave Houlton | bd2e262 | 2018-04-10 16:41:14 -0600 | [diff] [blame] | 3425 | << image_usage << ")."; |
| 3426 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 3427 | VALIDATION_ERROR_3f200c66, "%s", ss.str().c_str()); |
| 3428 | } |
| 3429 | |
| 3430 | image_usage = chained_ivuci_struct->usage; |
| 3431 | } |
| 3432 | |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3433 | // Validate VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT state |
| 3434 | if (image_flags & VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT) { |
Lenny Komow | b79f04a | 2017-09-18 17:07:00 -0600 | [diff] [blame] | 3435 | if ((!GetDeviceExtensions(device_data)->vk_khr_maintenance2 || |
| 3436 | !(image_flags & VK_IMAGE_CREATE_BLOCK_TEXEL_VIEW_COMPATIBLE_BIT_KHR))) { |
| 3437 | // Format MUST be compatible (in the same format compatibility class) as the format the image was created with |
| 3438 | if (FormatCompatibilityClass(image_format) != FormatCompatibilityClass(view_format)) { |
| 3439 | std::stringstream ss; |
| 3440 | ss << "vkCreateImageView(): ImageView format " << string_VkFormat(view_format) |
| 3441 | << " is not in the same format compatibility class as image (" << HandleToUint64(create_info->image) |
| 3442 | << ") format " << string_VkFormat(image_format) |
| 3443 | << ". Images created with the VK_IMAGE_CREATE_MUTABLE_FORMAT BIT " |
| 3444 | << "can support ImageViews with differing formats but they must be in the same compatibility class."; |
| 3445 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3446 | VALIDATION_ERROR_0ac007f4, "%s", ss.str().c_str()); |
Lenny Komow | b79f04a | 2017-09-18 17:07:00 -0600 | [diff] [blame] | 3447 | } |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3448 | } |
| 3449 | } else { |
| 3450 | // Format MUST be IDENTICAL to the format the image was created with |
| 3451 | if (image_format != view_format) { |
| 3452 | std::stringstream ss; |
| 3453 | ss << "vkCreateImageView() format " << string_VkFormat(view_format) << " differs from image " |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 3454 | << HandleToUint64(create_info->image) << " format " << string_VkFormat(image_format) |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3455 | << ". Formats MUST be IDENTICAL unless VK_IMAGE_CREATE_MUTABLE_FORMAT BIT was set on image creation."; |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 3456 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3457 | VALIDATION_ERROR_0ac007f6, "%s", ss.str().c_str()); |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3458 | } |
| 3459 | } |
| 3460 | |
| 3461 | // Validate correct image aspect bits for desired formats and format consistency |
| 3462 | skip |= ValidateImageAspectMask(device_data, image_state->image, image_format, aspect_mask, "vkCreateImageView()"); |
Jeremy Kniager | 846ab73 | 2017-07-10 13:12:04 -0600 | [diff] [blame] | 3463 | |
| 3464 | switch (image_type) { |
| 3465 | case VK_IMAGE_TYPE_1D: |
| 3466 | if (view_type != VK_IMAGE_VIEW_TYPE_1D && view_type != VK_IMAGE_VIEW_TYPE_1D_ARRAY) { |
| 3467 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3468 | VALIDATION_ERROR_0ac007fa, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3469 | "vkCreateImageView(): pCreateInfo->viewType %s is not compatible with image type %s.", |
| 3470 | string_VkImageViewType(view_type), string_VkImageType(image_type)); |
Jeremy Kniager | 846ab73 | 2017-07-10 13:12:04 -0600 | [diff] [blame] | 3471 | } |
| 3472 | break; |
| 3473 | case VK_IMAGE_TYPE_2D: |
| 3474 | if (view_type != VK_IMAGE_VIEW_TYPE_2D && view_type != VK_IMAGE_VIEW_TYPE_2D_ARRAY) { |
| 3475 | if ((view_type == VK_IMAGE_VIEW_TYPE_CUBE || view_type == VK_IMAGE_VIEW_TYPE_CUBE_ARRAY) && |
| 3476 | !(image_flags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT)) { |
| 3477 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3478 | VALIDATION_ERROR_0ac007d6, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3479 | "vkCreateImageView(): pCreateInfo->viewType %s is not compatible with image type %s.", |
| 3480 | string_VkImageViewType(view_type), string_VkImageType(image_type)); |
Jeremy Kniager | 846ab73 | 2017-07-10 13:12:04 -0600 | [diff] [blame] | 3481 | } else if (view_type != VK_IMAGE_VIEW_TYPE_CUBE && view_type != VK_IMAGE_VIEW_TYPE_CUBE_ARRAY) { |
| 3482 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3483 | VALIDATION_ERROR_0ac007fa, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3484 | "vkCreateImageView(): pCreateInfo->viewType %s is not compatible with image type %s.", |
| 3485 | string_VkImageViewType(view_type), string_VkImageType(image_type)); |
Jeremy Kniager | 846ab73 | 2017-07-10 13:12:04 -0600 | [diff] [blame] | 3486 | } |
| 3487 | } |
| 3488 | break; |
| 3489 | case VK_IMAGE_TYPE_3D: |
| 3490 | if (GetDeviceExtensions(device_data)->vk_khr_maintenance1) { |
| 3491 | if (view_type != VK_IMAGE_VIEW_TYPE_3D) { |
| 3492 | if ((view_type == VK_IMAGE_VIEW_TYPE_2D || view_type == VK_IMAGE_VIEW_TYPE_2D_ARRAY)) { |
| 3493 | if (!(image_flags & VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT_KHR)) { |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3494 | skip |= |
| 3495 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3496 | VALIDATION_ERROR_0ac007da, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3497 | "vkCreateImageView(): pCreateInfo->viewType %s is not compatible with image type %s.", |
| 3498 | string_VkImageViewType(view_type), string_VkImageType(image_type)); |
Jeremy Kniager | 846ab73 | 2017-07-10 13:12:04 -0600 | [diff] [blame] | 3499 | } else if ((image_flags & (VK_IMAGE_CREATE_SPARSE_BINDING_BIT | VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | |
| 3500 | VK_IMAGE_CREATE_SPARSE_ALIASED_BIT))) { |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 3501 | skip |= |
| 3502 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3503 | VALIDATION_ERROR_0ac007fa, |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 3504 | "vkCreateImageView(): pCreateInfo->viewType %s is not compatible with image type %s " |
| 3505 | "when the VK_IMAGE_CREATE_SPARSE_BINDING_BIT, VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT, or " |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3506 | "VK_IMAGE_CREATE_SPARSE_ALIASED_BIT flags are enabled.", |
| 3507 | string_VkImageViewType(view_type), string_VkImageType(image_type)); |
Jeremy Kniager | 846ab73 | 2017-07-10 13:12:04 -0600 | [diff] [blame] | 3508 | } |
| 3509 | } else { |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3510 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3511 | VALIDATION_ERROR_0ac007fa, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3512 | "vkCreateImageView(): pCreateInfo->viewType %s is not compatible with image type %s.", |
| 3513 | string_VkImageViewType(view_type), string_VkImageType(image_type)); |
Jeremy Kniager | 846ab73 | 2017-07-10 13:12:04 -0600 | [diff] [blame] | 3514 | } |
| 3515 | } |
| 3516 | } else { |
| 3517 | if (view_type != VK_IMAGE_VIEW_TYPE_3D) { |
| 3518 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3519 | VALIDATION_ERROR_0ac007fa, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3520 | "vkCreateImageView(): pCreateInfo->viewType %s is not compatible with image type %s.", |
| 3521 | string_VkImageViewType(view_type), string_VkImageType(image_type)); |
Jeremy Kniager | 846ab73 | 2017-07-10 13:12:04 -0600 | [diff] [blame] | 3522 | } |
| 3523 | } |
| 3524 | break; |
| 3525 | default: |
| 3526 | break; |
| 3527 | } |
Jeremy Kniager | cef491c | 2017-07-18 11:10:28 -0600 | [diff] [blame] | 3528 | |
Jeremy Kniager | 7ec550f | 2017-08-16 14:57:42 -0600 | [diff] [blame] | 3529 | VkFormatProperties format_properties = GetFormatProperties(device_data, view_format); |
Jeremy Kniager | cef491c | 2017-07-18 11:10:28 -0600 | [diff] [blame] | 3530 | bool check_tiling_features = false; |
| 3531 | VkFormatFeatureFlags tiling_features = 0; |
| 3532 | UNIQUE_VALIDATION_ERROR_CODE linear_error_codes[] = { |
| 3533 | VALIDATION_ERROR_0ac007dc, VALIDATION_ERROR_0ac007e0, VALIDATION_ERROR_0ac007e2, |
| 3534 | VALIDATION_ERROR_0ac007e4, VALIDATION_ERROR_0ac007e6, |
| 3535 | }; |
| 3536 | UNIQUE_VALIDATION_ERROR_CODE optimal_error_codes[] = { |
| 3537 | VALIDATION_ERROR_0ac007e8, VALIDATION_ERROR_0ac007ea, VALIDATION_ERROR_0ac007ec, |
| 3538 | VALIDATION_ERROR_0ac007ee, VALIDATION_ERROR_0ac007f0, |
| 3539 | }; |
| 3540 | UNIQUE_VALIDATION_ERROR_CODE *error_codes = nullptr; |
| 3541 | if (image_tiling == VK_IMAGE_TILING_LINEAR) { |
Jeremy Kniager | 7ec550f | 2017-08-16 14:57:42 -0600 | [diff] [blame] | 3542 | tiling_features = format_properties.linearTilingFeatures; |
Jeremy Kniager | cef491c | 2017-07-18 11:10:28 -0600 | [diff] [blame] | 3543 | error_codes = linear_error_codes; |
| 3544 | check_tiling_features = true; |
| 3545 | } else if (image_tiling == VK_IMAGE_TILING_OPTIMAL) { |
Jeremy Kniager | 7ec550f | 2017-08-16 14:57:42 -0600 | [diff] [blame] | 3546 | tiling_features = format_properties.optimalTilingFeatures; |
Jeremy Kniager | cef491c | 2017-07-18 11:10:28 -0600 | [diff] [blame] | 3547 | error_codes = optimal_error_codes; |
| 3548 | check_tiling_features = true; |
| 3549 | } |
| 3550 | |
| 3551 | if (check_tiling_features) { |
| 3552 | if (tiling_features == 0) { |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3553 | skip |= |
| 3554 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, error_codes[0], |
| 3555 | "vkCreateImageView() pCreateInfo->format %s cannot be used with an image having the %s flag set.", |
| 3556 | string_VkFormat(view_format), string_VkImageTiling(image_tiling)); |
Jeremy Kniager | cef491c | 2017-07-18 11:10:28 -0600 | [diff] [blame] | 3557 | } else if ((image_usage & VK_IMAGE_USAGE_SAMPLED_BIT) && !(tiling_features & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) { |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3558 | skip |= |
| 3559 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, error_codes[1], |
| 3560 | "vkCreateImageView() pCreateInfo->format %s cannot be used with an image having the %s and " |
| 3561 | "VK_IMAGE_USAGE_SAMPLED_BIT flags set.", |
| 3562 | string_VkFormat(view_format), string_VkImageTiling(image_tiling)); |
Jeremy Kniager | cef491c | 2017-07-18 11:10:28 -0600 | [diff] [blame] | 3563 | } else if ((image_usage & VK_IMAGE_USAGE_STORAGE_BIT) && !(tiling_features & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT)) { |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3564 | skip |= |
| 3565 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, error_codes[2], |
| 3566 | "vkCreateImageView() pCreateInfo->format %s cannot be used with an image having the %s and " |
| 3567 | "VK_IMAGE_USAGE_STORAGE_BIT flags set.", |
| 3568 | string_VkFormat(view_format), string_VkImageTiling(image_tiling)); |
Jeremy Kniager | cef491c | 2017-07-18 11:10:28 -0600 | [diff] [blame] | 3569 | } else if ((image_usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) && |
| 3570 | !(tiling_features & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT)) { |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3571 | skip |= |
| 3572 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, error_codes[3], |
| 3573 | "vkCreateImageView() pCreateInfo->format %s cannot be used with an image having the %s and " |
| 3574 | "VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT flags set.", |
| 3575 | string_VkFormat(view_format), string_VkImageTiling(image_tiling)); |
Jeremy Kniager | cef491c | 2017-07-18 11:10:28 -0600 | [diff] [blame] | 3576 | } else if ((image_usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) && |
| 3577 | !(tiling_features & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)) { |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3578 | skip |= |
| 3579 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, error_codes[4], |
| 3580 | "vkCreateImageView() pCreateInfo->format %s cannot be used with an image having the %s and " |
| 3581 | "VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT flags set.", |
| 3582 | string_VkFormat(view_format), string_VkImageTiling(image_tiling)); |
Jeremy Kniager | cef491c | 2017-07-18 11:10:28 -0600 | [diff] [blame] | 3583 | } |
| 3584 | } |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3585 | } |
| 3586 | return skip; |
| 3587 | } |
| 3588 | |
Mark Lobodzinski | efd933b | 2017-02-10 12:09:23 -0700 | [diff] [blame] | 3589 | void PostCallRecordCreateImageView(layer_data *device_data, const VkImageViewCreateInfo *create_info, VkImageView view) { |
| 3590 | auto image_view_map = GetImageViewMap(device_data); |
| 3591 | (*image_view_map)[view] = std::unique_ptr<IMAGE_VIEW_STATE>(new IMAGE_VIEW_STATE(view, create_info)); |
| 3592 | |
| 3593 | auto image_state = GetImageState(device_data, create_info->image); |
Dave Houlton | 4eaaf3a | 2017-03-14 11:31:20 -0600 | [diff] [blame] | 3594 | auto &sub_res_range = (*image_view_map)[view].get()->create_info.subresourceRange; |
Mark Lobodzinski | 903e5ff | 2017-03-23 09:43:35 -0600 | [diff] [blame] | 3595 | sub_res_range.levelCount = ResolveRemainingLevels(&sub_res_range, image_state->createInfo.mipLevels); |
| 3596 | sub_res_range.layerCount = ResolveRemainingLayers(&sub_res_range, image_state->createInfo.arrayLayers); |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3597 | } |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 3598 | |
Mark Lobodzinski | 680421d | 2017-02-09 13:06:56 -0700 | [diff] [blame] | 3599 | bool PreCallValidateCmdCopyBuffer(layer_data *device_data, GLOBAL_CB_NODE *cb_node, BUFFER_STATE *src_buffer_state, |
| 3600 | BUFFER_STATE *dst_buffer_state) { |
| 3601 | bool skip = false; |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3602 | skip |= ValidateMemoryIsBoundToBuffer(device_data, src_buffer_state, "vkCmdCopyBuffer()", VALIDATION_ERROR_18c000ee); |
| 3603 | skip |= ValidateMemoryIsBoundToBuffer(device_data, dst_buffer_state, "vkCmdCopyBuffer()", VALIDATION_ERROR_18c000f2); |
Mark Lobodzinski | 680421d | 2017-02-09 13:06:56 -0700 | [diff] [blame] | 3604 | // Validate that SRC & DST buffers have correct usage flags set |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3605 | skip |= ValidateBufferUsageFlags(device_data, src_buffer_state, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, true, |
| 3606 | VALIDATION_ERROR_18c000ec, "vkCmdCopyBuffer()", "VK_BUFFER_USAGE_TRANSFER_SRC_BIT"); |
| 3607 | skip |= ValidateBufferUsageFlags(device_data, dst_buffer_state, VK_BUFFER_USAGE_TRANSFER_DST_BIT, true, |
| 3608 | VALIDATION_ERROR_18c000f0, "vkCmdCopyBuffer()", "VK_BUFFER_USAGE_TRANSFER_DST_BIT"); |
Mike Schuchardt | 9c58240 | 2017-02-23 15:57:37 -0700 | [diff] [blame] | 3609 | skip |= ValidateCmdQueueFlags(device_data, cb_node, "vkCmdCopyBuffer()", |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3610 | 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] | 3611 | skip |= ValidateCmd(device_data, cb_node, CMD_COPYBUFFER, "vkCmdCopyBuffer()"); |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3612 | skip |= insideRenderPass(device_data, cb_node, "vkCmdCopyBuffer()", VALIDATION_ERROR_18c00017); |
Mark Lobodzinski | 680421d | 2017-02-09 13:06:56 -0700 | [diff] [blame] | 3613 | return skip; |
| 3614 | } |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 3615 | |
Mark Lobodzinski | 680421d | 2017-02-09 13:06:56 -0700 | [diff] [blame] | 3616 | void PreCallRecordCmdCopyBuffer(layer_data *device_data, GLOBAL_CB_NODE *cb_node, BUFFER_STATE *src_buffer_state, |
| 3617 | BUFFER_STATE *dst_buffer_state) { |
| 3618 | // Update bindings between buffers and cmd buffer |
| 3619 | AddCommandBufferBindingBuffer(device_data, cb_node, src_buffer_state); |
| 3620 | AddCommandBufferBindingBuffer(device_data, cb_node, dst_buffer_state); |
| 3621 | |
| 3622 | std::function<bool()> function = [=]() { |
| 3623 | return ValidateBufferMemoryIsValid(device_data, src_buffer_state, "vkCmdCopyBuffer()"); |
| 3624 | }; |
Tobin Ehlis | a17a529 | 2017-07-28 12:11:30 -0600 | [diff] [blame] | 3625 | cb_node->queue_submit_functions.push_back(function); |
Mark Lobodzinski | 680421d | 2017-02-09 13:06:56 -0700 | [diff] [blame] | 3626 | function = [=]() { |
| 3627 | SetBufferMemoryValid(device_data, dst_buffer_state, true); |
| 3628 | return false; |
| 3629 | }; |
Tobin Ehlis | a17a529 | 2017-07-28 12:11:30 -0600 | [diff] [blame] | 3630 | cb_node->queue_submit_functions.push_back(function); |
Mark Lobodzinski | 680421d | 2017-02-09 13:06:56 -0700 | [diff] [blame] | 3631 | } |
Mark Lobodzinski | 306441e | 2017-02-10 13:48:38 -0700 | [diff] [blame] | 3632 | |
| 3633 | static bool validateIdleBuffer(layer_data *device_data, VkBuffer buffer) { |
| 3634 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 3635 | bool skip = false; |
| 3636 | auto buffer_state = GetBufferState(device_data, buffer); |
| 3637 | if (!buffer_state) { |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 3638 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, HandleToUint64(buffer), |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3639 | DRAWSTATE_DOUBLE_DESTROY, "Cannot free buffer 0x%" PRIx64 " that has not been allocated.", |
Petr Kraus | 13c98a6 | 2017-12-09 00:22:39 +0100 | [diff] [blame] | 3640 | HandleToUint64(buffer)); |
Mark Lobodzinski | 306441e | 2017-02-10 13:48:38 -0700 | [diff] [blame] | 3641 | } else { |
| 3642 | if (buffer_state->in_use.load()) { |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 3643 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3644 | HandleToUint64(buffer), VALIDATION_ERROR_23c00734, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3645 | "Cannot free buffer 0x%" PRIx64 " that is in use by a command buffer.", HandleToUint64(buffer)); |
Mark Lobodzinski | 306441e | 2017-02-10 13:48:38 -0700 | [diff] [blame] | 3646 | } |
| 3647 | } |
| 3648 | return skip; |
| 3649 | } |
| 3650 | |
| 3651 | bool PreCallValidateDestroyImageView(layer_data *device_data, VkImageView image_view, IMAGE_VIEW_STATE **image_view_state, |
| 3652 | VK_OBJECT *obj_struct) { |
| 3653 | *image_view_state = GetImageViewState(device_data, image_view); |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 3654 | *obj_struct = {HandleToUint64(image_view), kVulkanObjectTypeImageView}; |
Mark Lobodzinski | 306441e | 2017-02-10 13:48:38 -0700 | [diff] [blame] | 3655 | if (GetDisables(device_data)->destroy_image_view) return false; |
| 3656 | bool skip = false; |
| 3657 | if (*image_view_state) { |
Mike Schuchardt | a502565 | 2017-09-27 14:56:21 -0600 | [diff] [blame] | 3658 | skip |= |
| 3659 | ValidateObjectNotInUse(device_data, *image_view_state, *obj_struct, "vkDestroyImageView", VALIDATION_ERROR_25400804); |
Mark Lobodzinski | 306441e | 2017-02-10 13:48:38 -0700 | [diff] [blame] | 3660 | } |
| 3661 | return skip; |
| 3662 | } |
| 3663 | |
| 3664 | void PostCallRecordDestroyImageView(layer_data *device_data, VkImageView image_view, IMAGE_VIEW_STATE *image_view_state, |
| 3665 | VK_OBJECT obj_struct) { |
| 3666 | // Any bound cmd buffers are now invalid |
| 3667 | invalidateCommandBuffers(device_data, image_view_state->cb_bindings, obj_struct); |
| 3668 | (*GetImageViewMap(device_data)).erase(image_view); |
| 3669 | } |
| 3670 | |
| 3671 | bool PreCallValidateDestroyBuffer(layer_data *device_data, VkBuffer buffer, BUFFER_STATE **buffer_state, VK_OBJECT *obj_struct) { |
| 3672 | *buffer_state = GetBufferState(device_data, buffer); |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 3673 | *obj_struct = {HandleToUint64(buffer), kVulkanObjectTypeBuffer}; |
Mark Lobodzinski | 306441e | 2017-02-10 13:48:38 -0700 | [diff] [blame] | 3674 | if (GetDisables(device_data)->destroy_buffer) return false; |
| 3675 | bool skip = false; |
| 3676 | if (*buffer_state) { |
| 3677 | skip |= validateIdleBuffer(device_data, buffer); |
| 3678 | } |
| 3679 | return skip; |
| 3680 | } |
| 3681 | |
| 3682 | void PostCallRecordDestroyBuffer(layer_data *device_data, VkBuffer buffer, BUFFER_STATE *buffer_state, VK_OBJECT obj_struct) { |
| 3683 | invalidateCommandBuffers(device_data, buffer_state->cb_bindings, obj_struct); |
| 3684 | for (auto mem_binding : buffer_state->GetBoundMemory()) { |
| 3685 | auto mem_info = GetMemObjInfo(device_data, mem_binding); |
| 3686 | if (mem_info) { |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 3687 | core_validation::RemoveBufferMemoryRange(HandleToUint64(buffer), mem_info); |
Mark Lobodzinski | 306441e | 2017-02-10 13:48:38 -0700 | [diff] [blame] | 3688 | } |
| 3689 | } |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 3690 | ClearMemoryObjectBindings(device_data, HandleToUint64(buffer), kVulkanObjectTypeBuffer); |
Mark Lobodzinski | 306441e | 2017-02-10 13:48:38 -0700 | [diff] [blame] | 3691 | GetBufferMap(device_data)->erase(buffer_state->buffer); |
| 3692 | } |
| 3693 | |
| 3694 | bool PreCallValidateDestroyBufferView(layer_data *device_data, VkBufferView buffer_view, BUFFER_VIEW_STATE **buffer_view_state, |
| 3695 | VK_OBJECT *obj_struct) { |
| 3696 | *buffer_view_state = GetBufferViewState(device_data, buffer_view); |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 3697 | *obj_struct = {HandleToUint64(buffer_view), kVulkanObjectTypeBufferView}; |
Mark Lobodzinski | 306441e | 2017-02-10 13:48:38 -0700 | [diff] [blame] | 3698 | if (GetDisables(device_data)->destroy_buffer_view) return false; |
| 3699 | bool skip = false; |
| 3700 | if (*buffer_view_state) { |
Mike Schuchardt | a502565 | 2017-09-27 14:56:21 -0600 | [diff] [blame] | 3701 | skip |= |
| 3702 | ValidateObjectNotInUse(device_data, *buffer_view_state, *obj_struct, "vkDestroyBufferView", VALIDATION_ERROR_23e00750); |
Mark Lobodzinski | 306441e | 2017-02-10 13:48:38 -0700 | [diff] [blame] | 3703 | } |
| 3704 | return skip; |
| 3705 | } |
| 3706 | |
| 3707 | void PostCallRecordDestroyBufferView(layer_data *device_data, VkBufferView buffer_view, BUFFER_VIEW_STATE *buffer_view_state, |
| 3708 | VK_OBJECT obj_struct) { |
| 3709 | // Any bound cmd buffers are now invalid |
| 3710 | invalidateCommandBuffers(device_data, buffer_view_state->cb_bindings, obj_struct); |
| 3711 | GetBufferViewMap(device_data)->erase(buffer_view); |
| 3712 | } |
Mark Lobodzinski | df0acbf | 2017-02-10 14:01:27 -0700 | [diff] [blame] | 3713 | |
| 3714 | bool PreCallValidateCmdFillBuffer(layer_data *device_data, GLOBAL_CB_NODE *cb_node, BUFFER_STATE *buffer_state) { |
| 3715 | bool skip = false; |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3716 | skip |= ValidateMemoryIsBoundToBuffer(device_data, buffer_state, "vkCmdFillBuffer()", VALIDATION_ERROR_1b40003e); |
Mike Schuchardt | 9c58240 | 2017-02-23 15:57:37 -0700 | [diff] [blame] | 3717 | skip |= ValidateCmdQueueFlags(device_data, cb_node, "vkCmdFillBuffer()", |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3718 | 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] | 3719 | skip |= ValidateCmd(device_data, cb_node, CMD_FILLBUFFER, "vkCmdFillBuffer()"); |
| 3720 | // Validate that DST buffer has correct usage flags set |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3721 | 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] | 3722 | "vkCmdFillBuffer()", "VK_BUFFER_USAGE_TRANSFER_DST_BIT"); |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 3723 | skip |= insideRenderPass(device_data, cb_node, "vkCmdFillBuffer()", VALIDATION_ERROR_1b400017); |
Mark Lobodzinski | df0acbf | 2017-02-10 14:01:27 -0700 | [diff] [blame] | 3724 | return skip; |
| 3725 | } |
| 3726 | |
| 3727 | void PreCallRecordCmdFillBuffer(layer_data *device_data, GLOBAL_CB_NODE *cb_node, BUFFER_STATE *buffer_state) { |
| 3728 | std::function<bool()> function = [=]() { |
| 3729 | SetBufferMemoryValid(device_data, buffer_state, true); |
| 3730 | return false; |
| 3731 | }; |
Tobin Ehlis | a17a529 | 2017-07-28 12:11:30 -0600 | [diff] [blame] | 3732 | cb_node->queue_submit_functions.push_back(function); |
Mark Lobodzinski | df0acbf | 2017-02-10 14:01:27 -0700 | [diff] [blame] | 3733 | // Update bindings between buffer and cmd buffer |
| 3734 | AddCommandBufferBindingBuffer(device_data, cb_node, buffer_state); |
Mark Lobodzinski | df0acbf | 2017-02-10 14:01:27 -0700 | [diff] [blame] | 3735 | } |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 3736 | |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 3737 | bool ValidateBufferImageCopyData(const debug_report_data *report_data, uint32_t regionCount, const VkBufferImageCopy *pRegions, |
| 3738 | IMAGE_STATE *image_state, const char *function) { |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 3739 | bool skip = false; |
| 3740 | |
| 3741 | for (uint32_t i = 0; i < regionCount; i++) { |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3742 | if (image_state->createInfo.imageType == VK_IMAGE_TYPE_1D) { |
| 3743 | if ((pRegions[i].imageOffset.y != 0) || (pRegions[i].imageExtent.height != 1)) { |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 3744 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3745 | HandleToUint64(image_state->image), VALIDATION_ERROR_0160018e, |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 3746 | "%s(): pRegion[%d] imageOffset.y is %d and imageExtent.height is %d. For 1D images these must be 0 " |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3747 | "and 1, respectively.", |
| 3748 | function, i, pRegions[i].imageOffset.y, pRegions[i].imageExtent.height); |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 3749 | } |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3750 | } |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 3751 | |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3752 | if ((image_state->createInfo.imageType == VK_IMAGE_TYPE_1D) || (image_state->createInfo.imageType == VK_IMAGE_TYPE_2D)) { |
| 3753 | if ((pRegions[i].imageOffset.z != 0) || (pRegions[i].imageExtent.depth != 1)) { |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 3754 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3755 | HandleToUint64(image_state->image), VALIDATION_ERROR_01600192, |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3756 | "%s(): pRegion[%d] imageOffset.z is %d and imageExtent.depth is %d. For 1D and 2D images these " |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3757 | "must be 0 and 1, respectively.", |
| 3758 | function, i, pRegions[i].imageOffset.z, pRegions[i].imageExtent.depth); |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 3759 | } |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3760 | } |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 3761 | |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3762 | if (image_state->createInfo.imageType == VK_IMAGE_TYPE_3D) { |
| 3763 | if ((0 != pRegions[i].imageSubresource.baseArrayLayer) || (1 != pRegions[i].imageSubresource.layerCount)) { |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 3764 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3765 | HandleToUint64(image_state->image), VALIDATION_ERROR_016001aa, |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 3766 | "%s(): pRegion[%d] imageSubresource.baseArrayLayer is %d and imageSubresource.layerCount is %d. " |
| 3767 | "For 3D images these must be 0 and 1, respectively.", |
| 3768 | function, i, pRegions[i].imageSubresource.baseArrayLayer, pRegions[i].imageSubresource.layerCount); |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3769 | } |
| 3770 | } |
| 3771 | |
| 3772 | // If the the calling command's VkImage parameter's format is not a depth/stencil format, |
| 3773 | // 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] | 3774 | auto texel_size = FormatSize(image_state->createInfo.format); |
Dave Houlton | 1150cf5 | 2017-04-27 14:38:11 -0600 | [diff] [blame] | 3775 | 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] | 3776 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3777 | HandleToUint64(image_state->image), VALIDATION_ERROR_01600182, |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3778 | "%s(): pRegion[%d] bufferOffset 0x%" PRIxLEAST64 |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3779 | " must be a multiple of this format's texel size (" PRINTF_SIZE_T_SPECIFIER ").", |
| 3780 | function, i, pRegions[i].bufferOffset, texel_size); |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3781 | } |
| 3782 | |
| 3783 | // BufferOffset must be a multiple of 4 |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 3784 | if (SafeModulo(pRegions[i].bufferOffset, 4) != 0) { |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3785 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3786 | HandleToUint64(image_state->image), VALIDATION_ERROR_01600184, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3787 | "%s(): pRegion[%d] bufferOffset 0x%" PRIxLEAST64 " must be a multiple of 4.", function, i, |
| 3788 | pRegions[i].bufferOffset); |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3789 | } |
| 3790 | |
| 3791 | // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent |
| 3792 | if ((pRegions[i].bufferRowLength != 0) && (pRegions[i].bufferRowLength < pRegions[i].imageExtent.width)) { |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3793 | skip |= |
| 3794 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3795 | HandleToUint64(image_state->image), VALIDATION_ERROR_01600186, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3796 | "%s(): pRegion[%d] bufferRowLength (%d) must be zero or greater-than-or-equal-to imageExtent.width (%d).", |
| 3797 | function, i, pRegions[i].bufferRowLength, pRegions[i].imageExtent.width); |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3798 | } |
| 3799 | |
| 3800 | // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent |
| 3801 | if ((pRegions[i].bufferImageHeight != 0) && (pRegions[i].bufferImageHeight < pRegions[i].imageExtent.height)) { |
| 3802 | skip |= log_msg( |
| 3803 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3804 | HandleToUint64(image_state->image), VALIDATION_ERROR_01600188, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3805 | "%s(): pRegion[%d] bufferImageHeight (%d) must be zero or greater-than-or-equal-to imageExtent.height (%d).", |
| 3806 | function, i, pRegions[i].bufferImageHeight, pRegions[i].imageExtent.height); |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3807 | } |
| 3808 | |
| 3809 | // subresource aspectMask must have exactly 1 bit set |
| 3810 | const int num_bits = sizeof(VkFlags) * CHAR_BIT; |
| 3811 | std::bitset<num_bits> aspect_mask_bits(pRegions[i].imageSubresource.aspectMask); |
| 3812 | if (aspect_mask_bits.count() != 1) { |
| 3813 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3814 | HandleToUint64(image_state->image), VALIDATION_ERROR_016001a8, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3815 | "%s: aspectMasks for imageSubresource in each region must have only a single bit set.", function); |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3816 | } |
| 3817 | |
| 3818 | // image subresource aspect bit must match format |
Dave Houlton | 4eaaf3a | 2017-03-14 11:31:20 -0600 | [diff] [blame] | 3819 | if (!VerifyAspectsPresent(pRegions[i].imageSubresource.aspectMask, image_state->createInfo.format)) { |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3820 | skip |= log_msg( |
| 3821 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3822 | HandleToUint64(image_state->image), VALIDATION_ERROR_016001a6, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3823 | "%s(): pRegion[%d] subresource aspectMask 0x%x specifies aspects that are not present in image format 0x%x.", |
| 3824 | function, i, pRegions[i].imageSubresource.aspectMask, image_state->createInfo.format); |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3825 | } |
| 3826 | |
| 3827 | // Checks that apply only to compressed images |
| 3828 | // TODO: there is a comment in ValidateCopyBufferImageTransferGranularityRequirements() in core_validation.cpp that |
| 3829 | // reserves a place for these compressed image checks. This block of code could move there once the image |
| 3830 | // stuff is moved into core validation. |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 3831 | if (FormatIsCompressed(image_state->createInfo.format)) { |
| 3832 | auto block_size = FormatCompressedTexelBlockExtent(image_state->createInfo.format); |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3833 | |
| 3834 | // BufferRowLength must be a multiple of block width |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 3835 | if (SafeModulo(pRegions[i].bufferRowLength, block_size.width) != 0) { |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 3836 | skip |= log_msg( |
| 3837 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3838 | HandleToUint64(image_state->image), VALIDATION_ERROR_01600196, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3839 | "%s(): pRegion[%d] bufferRowLength (%d) must be a multiple of the compressed image's texel width (%d)..", |
| 3840 | function, i, pRegions[i].bufferRowLength, block_size.width); |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 3841 | } |
| 3842 | |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3843 | // BufferRowHeight must be a multiple of block height |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 3844 | if (SafeModulo(pRegions[i].bufferImageHeight, block_size.height) != 0) { |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 3845 | skip |= log_msg( |
| 3846 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3847 | HandleToUint64(image_state->image), VALIDATION_ERROR_01600198, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3848 | "%s(): pRegion[%d] bufferImageHeight (%d) must be a multiple of the compressed image's texel height (%d)..", |
| 3849 | function, i, pRegions[i].bufferImageHeight, block_size.height); |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 3850 | } |
| 3851 | |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3852 | // image offsets must be multiples of block dimensions |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 3853 | if ((SafeModulo(pRegions[i].imageOffset.x, block_size.width) != 0) || |
| 3854 | (SafeModulo(pRegions[i].imageOffset.y, block_size.height) != 0) || |
| 3855 | (SafeModulo(pRegions[i].imageOffset.z, block_size.depth) != 0)) { |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3856 | skip |= |
| 3857 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3858 | HandleToUint64(image_state->image), VALIDATION_ERROR_0160019a, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3859 | "%s(): pRegion[%d] imageOffset(x,y) (%d, %d) must be multiples of the compressed image's texel " |
| 3860 | "width & height (%d, %d)..", |
| 3861 | function, i, pRegions[i].imageOffset.x, pRegions[i].imageOffset.y, block_size.width, block_size.height); |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 3862 | } |
| 3863 | |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3864 | // bufferOffset must be a multiple of block size (linear bytes) |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 3865 | size_t block_size_in_bytes = FormatSize(image_state->createInfo.format); |
| 3866 | if (SafeModulo(pRegions[i].bufferOffset, block_size_in_bytes) != 0) { |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3867 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3868 | HandleToUint64(image_state->image), VALIDATION_ERROR_0160019c, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3869 | "%s(): pRegion[%d] bufferOffset (0x%" PRIxLEAST64 |
| 3870 | ") must be a multiple of the compressed image's texel block size (" PRINTF_SIZE_T_SPECIFIER ")..", |
| 3871 | function, i, pRegions[i].bufferOffset, block_size_in_bytes); |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 3872 | } |
Dave Houlton | 67e9b53 | 2017-03-02 17:00:10 -0700 | [diff] [blame] | 3873 | |
| 3874 | // 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] | 3875 | VkExtent3D mip_extent = GetImageSubresourceExtent(image_state, &(pRegions[i].imageSubresource)); |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 3876 | if ((SafeModulo(pRegions[i].imageExtent.width, block_size.width) != 0) && |
Dave Houlton | 75967fc | 2017-03-06 17:21:16 -0700 | [diff] [blame] | 3877 | (pRegions[i].imageExtent.width + pRegions[i].imageOffset.x != mip_extent.width)) { |
| 3878 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3879 | HandleToUint64(image_state->image), VALIDATION_ERROR_0160019e, |
Dave Houlton | 75967fc | 2017-03-06 17:21:16 -0700 | [diff] [blame] | 3880 | "%s(): pRegion[%d] extent width (%d) must be a multiple of the compressed texture block width " |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3881 | "(%d), or when added to offset.x (%d) must equal the image subresource width (%d)..", |
Dave Houlton | 75967fc | 2017-03-06 17:21:16 -0700 | [diff] [blame] | 3882 | function, i, pRegions[i].imageExtent.width, block_size.width, pRegions[i].imageOffset.x, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3883 | mip_extent.width); |
Dave Houlton | 67e9b53 | 2017-03-02 17:00:10 -0700 | [diff] [blame] | 3884 | } |
| 3885 | |
| 3886 | // 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] | 3887 | if ((SafeModulo(pRegions[i].imageExtent.height, block_size.height) != 0) && |
Dave Houlton | 75967fc | 2017-03-06 17:21:16 -0700 | [diff] [blame] | 3888 | (pRegions[i].imageExtent.height + pRegions[i].imageOffset.y != mip_extent.height)) { |
| 3889 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3890 | HandleToUint64(image_state->image), VALIDATION_ERROR_016001a0, |
Dave Houlton | 75967fc | 2017-03-06 17:21:16 -0700 | [diff] [blame] | 3891 | "%s(): pRegion[%d] extent height (%d) must be a multiple of the compressed texture block height " |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3892 | "(%d), or when added to offset.y (%d) must equal the image subresource height (%d)..", |
Dave Houlton | 75967fc | 2017-03-06 17:21:16 -0700 | [diff] [blame] | 3893 | function, i, pRegions[i].imageExtent.height, block_size.height, pRegions[i].imageOffset.y, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3894 | mip_extent.height); |
Dave Houlton | 67e9b53 | 2017-03-02 17:00:10 -0700 | [diff] [blame] | 3895 | } |
| 3896 | |
| 3897 | // 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] | 3898 | if ((SafeModulo(pRegions[i].imageExtent.depth, block_size.depth) != 0) && |
Dave Houlton | 75967fc | 2017-03-06 17:21:16 -0700 | [diff] [blame] | 3899 | (pRegions[i].imageExtent.depth + pRegions[i].imageOffset.z != mip_extent.depth)) { |
| 3900 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3901 | HandleToUint64(image_state->image), VALIDATION_ERROR_016001a2, |
Dave Houlton | 75967fc | 2017-03-06 17:21:16 -0700 | [diff] [blame] | 3902 | "%s(): pRegion[%d] extent width (%d) must be a multiple of the compressed texture block depth " |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3903 | "(%d), or when added to offset.z (%d) must equal the image subresource depth (%d)..", |
Dave Houlton | 75967fc | 2017-03-06 17:21:16 -0700 | [diff] [blame] | 3904 | function, i, pRegions[i].imageExtent.depth, block_size.depth, pRegions[i].imageOffset.z, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3905 | mip_extent.depth); |
Dave Houlton | 67e9b53 | 2017-03-02 17:00:10 -0700 | [diff] [blame] | 3906 | } |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3907 | } |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 3908 | } |
| 3909 | |
| 3910 | return skip; |
| 3911 | } |
| 3912 | |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3913 | static bool ValidateImageBounds(const debug_report_data *report_data, const IMAGE_STATE *image_state, const uint32_t regionCount, |
| 3914 | 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] | 3915 | bool skip = false; |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3916 | const VkImageCreateInfo *image_info = &(image_state->createInfo); |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 3917 | |
| 3918 | for (uint32_t i = 0; i < regionCount; i++) { |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 3919 | VkExtent3D extent = pRegions[i].imageExtent; |
| 3920 | VkOffset3D offset = pRegions[i].imageOffset; |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 3921 | |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3922 | if (IsExtentSizeZero(&extent)) // Warn on zero area subresource |
| 3923 | { |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3924 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 3925 | (uint64_t)0, IMAGE_ZERO_AREA_SUBREGION, "%s: pRegion[%d] imageExtent of {%1d, %1d, %1d} has zero area", |
| 3926 | func_name, i, extent.width, extent.height, extent.depth); |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3927 | } |
| 3928 | |
| 3929 | VkExtent3D image_extent = GetImageSubresourceExtent(image_state, &(pRegions[i].imageSubresource)); |
| 3930 | |
| 3931 | // 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] | 3932 | if (FormatIsCompressed(image_info->format)) { |
| 3933 | auto block_extent = FormatCompressedTexelBlockExtent(image_info->format); |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3934 | if (image_extent.width % block_extent.width) { |
| 3935 | image_extent.width += (block_extent.width - (image_extent.width % block_extent.width)); |
| 3936 | } |
| 3937 | if (image_extent.height % block_extent.height) { |
| 3938 | image_extent.height += (block_extent.height - (image_extent.height % block_extent.height)); |
| 3939 | } |
| 3940 | if (image_extent.depth % block_extent.depth) { |
| 3941 | image_extent.depth += (block_extent.depth - (image_extent.depth % block_extent.depth)); |
| 3942 | } |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 3943 | } |
| 3944 | |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 3945 | if (0 != ExceedsBounds(&offset, &extent, &image_extent)) { |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 3946 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)0, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3947 | msg_code, "%s: pRegion[%d] exceeds image bounds..", func_name, i); |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 3948 | } |
| 3949 | } |
| 3950 | |
| 3951 | return skip; |
| 3952 | } |
| 3953 | |
Chris Forbes | e8ba09a | 2017-06-01 17:39:02 -0700 | [diff] [blame] | 3954 | 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] | 3955 | uint32_t regionCount, const VkBufferImageCopy *pRegions, const char *func_name, |
| 3956 | UNIQUE_VALIDATION_ERROR_CODE msg_code) { |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 3957 | bool skip = false; |
| 3958 | |
| 3959 | VkDeviceSize buffer_size = buff_state->createInfo.size; |
| 3960 | |
| 3961 | for (uint32_t i = 0; i < regionCount; i++) { |
| 3962 | VkExtent3D copy_extent = pRegions[i].imageExtent; |
| 3963 | |
| 3964 | VkDeviceSize buffer_width = (0 == pRegions[i].bufferRowLength ? copy_extent.width : pRegions[i].bufferRowLength); |
| 3965 | 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] | 3966 | 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] | 3967 | |
Dave Houlton | f3229d5 | 2017-02-21 15:59:08 -0700 | [diff] [blame] | 3968 | // Handle special buffer packing rules for specific depth/stencil formats |
| 3969 | if (pRegions[i].imageSubresource.aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) { |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 3970 | unit_size = FormatSize(VK_FORMAT_S8_UINT); |
Dave Houlton | f3229d5 | 2017-02-21 15:59:08 -0700 | [diff] [blame] | 3971 | } else if (pRegions[i].imageSubresource.aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) { |
| 3972 | switch (image_state->createInfo.format) { |
| 3973 | case VK_FORMAT_D16_UNORM_S8_UINT: |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 3974 | unit_size = FormatSize(VK_FORMAT_D16_UNORM); |
Dave Houlton | f3229d5 | 2017-02-21 15:59:08 -0700 | [diff] [blame] | 3975 | break; |
| 3976 | case VK_FORMAT_D32_SFLOAT_S8_UINT: |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 3977 | unit_size = FormatSize(VK_FORMAT_D32_SFLOAT); |
Dave Houlton | f3229d5 | 2017-02-21 15:59:08 -0700 | [diff] [blame] | 3978 | break; |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3979 | case VK_FORMAT_X8_D24_UNORM_PACK32: // Fall through |
Dave Houlton | f3229d5 | 2017-02-21 15:59:08 -0700 | [diff] [blame] | 3980 | case VK_FORMAT_D24_UNORM_S8_UINT: |
| 3981 | unit_size = 4; |
| 3982 | break; |
| 3983 | default: |
| 3984 | break; |
| 3985 | } |
| 3986 | } |
| 3987 | |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 3988 | if (FormatIsCompressed(image_state->createInfo.format)) { |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3989 | // Switch to texel block units, rounding up for any partially-used blocks |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 3990 | auto block_dim = FormatCompressedTexelBlockExtent(image_state->createInfo.format); |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3991 | buffer_width = (buffer_width + block_dim.width - 1) / block_dim.width; |
| 3992 | buffer_height = (buffer_height + block_dim.height - 1) / block_dim.height; |
| 3993 | |
| 3994 | copy_extent.width = (copy_extent.width + block_dim.width - 1) / block_dim.width; |
| 3995 | copy_extent.height = (copy_extent.height + block_dim.height - 1) / block_dim.height; |
| 3996 | 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] | 3997 | } |
| 3998 | |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 3999 | // Either depth or layerCount may be greater than 1 (not both). This is the number of 'slices' to copy |
| 4000 | uint32_t z_copies = std::max(copy_extent.depth, pRegions[i].imageSubresource.layerCount); |
| 4001 | if (IsExtentSizeZero(©_extent) || (0 == z_copies)) { |
Chris Forbes | e8ba09a | 2017-06-01 17:39:02 -0700 | [diff] [blame] | 4002 | // TODO: Issue warning here? Already warned in ValidateImageBounds()... |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 4003 | } else { |
| 4004 | // Calculate buffer offset of final copied byte, + 1. |
| 4005 | VkDeviceSize max_buffer_offset = (z_copies - 1) * buffer_height * buffer_width; // offset to slice |
| 4006 | max_buffer_offset += ((copy_extent.height - 1) * buffer_width) + copy_extent.width; // add row,col |
| 4007 | max_buffer_offset *= unit_size; // convert to bytes |
| 4008 | max_buffer_offset += pRegions[i].bufferOffset; // add initial offset (bytes) |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 4009 | |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 4010 | if (buffer_size < max_buffer_offset) { |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 4011 | skip |= |
| 4012 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)0, |
| 4013 | msg_code, "%s: pRegion[%d] exceeds buffer size of %" PRIu64 " bytes..", func_name, i, buffer_size); |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 4014 | } |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 4015 | } |
| 4016 | } |
| 4017 | |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 4018 | return skip; |
| 4019 | } |
| 4020 | |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 4021 | 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] | 4022 | 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] | 4023 | const VkBufferImageCopy *pRegions, const char *func_name) { |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 4024 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 4025 | bool skip = ValidateBufferImageCopyData(report_data, regionCount, pRegions, src_image_state, "vkCmdCopyImageToBuffer"); |
| 4026 | |
| 4027 | // Validate command buffer state |
John Zulauf | 5c2750c | 2018-01-30 15:04:56 -0700 | [diff] [blame] | 4028 | skip |= ValidateCmd(device_data, cb_node, CMD_COPYIMAGETOBUFFER, "vkCmdCopyImageToBuffer()"); |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 4029 | |
| 4030 | // Command pool must support graphics, compute, or transfer operations |
| 4031 | auto pPool = GetCommandPoolNode(device_data, cb_node->createInfo.commandPool); |
| 4032 | |
| 4033 | VkQueueFlags queue_flags = GetPhysDevProperties(device_data)->queue_family_properties[pPool->queueFamilyIndex].queueFlags; |
| 4034 | if (0 == (queue_flags & (VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT | VK_QUEUE_TRANSFER_BIT))) { |
| 4035 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 4036 | HandleToUint64(cb_node->createInfo.commandPool), VALIDATION_ERROR_19202415, |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 4037 | "Cannot call vkCmdCopyImageToBuffer() on a command buffer allocated from a pool without graphics, compute, " |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 4038 | "or transfer capabilities.."); |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 4039 | } |
Dave Houlton | 0ef2749 | 2018-04-04 11:41:48 -0600 | [diff] [blame] | 4040 | skip |= ValidateImageBounds(report_data, src_image_state, regionCount, pRegions, "vkCmdCopyImageToBuffer()", |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 4041 | VALIDATION_ERROR_1920016c); |
Chris Forbes | e8ba09a | 2017-06-01 17:39:02 -0700 | [diff] [blame] | 4042 | 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] | 4043 | VALIDATION_ERROR_1920016e); |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 4044 | |
| 4045 | 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] | 4046 | VALIDATION_ERROR_19200178); |
| 4047 | skip |= ValidateMemoryIsBoundToImage(device_data, src_image_state, "vkCmdCopyImageToBuffer()", VALIDATION_ERROR_19200176); |
| 4048 | skip |= ValidateMemoryIsBoundToBuffer(device_data, dst_buffer_state, "vkCmdCopyImageToBuffer()", VALIDATION_ERROR_19200180); |
Mark Lobodzinski | 033c90b | 2017-02-15 13:58:23 -0700 | [diff] [blame] | 4049 | |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 4050 | // Validate that SRC image & DST buffer have correct usage flags set |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 4051 | 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] | 4052 | "vkCmdCopyImageToBuffer()", "VK_IMAGE_USAGE_TRANSFER_SRC_BIT"); |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 4053 | skip |= ValidateBufferUsageFlags(device_data, dst_buffer_state, VK_BUFFER_USAGE_TRANSFER_DST_BIT, true, |
| 4054 | VALIDATION_ERROR_1920017e, "vkCmdCopyImageToBuffer()", "VK_BUFFER_USAGE_TRANSFER_DST_BIT"); |
| 4055 | skip |= insideRenderPass(device_data, cb_node, "vkCmdCopyImageToBuffer()", VALIDATION_ERROR_19200017); |
Tobin Ehlis | c826645 | 2017-04-07 12:20:30 -0600 | [diff] [blame] | 4056 | bool hit_error = false; |
Mark Lobodzinski | 033c90b | 2017-02-15 13:58:23 -0700 | [diff] [blame] | 4057 | for (uint32_t i = 0; i < regionCount; ++i) { |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 4058 | skip |= VerifyImageLayout(device_data, cb_node, src_image_state, pRegions[i].imageSubresource, srcImageLayout, |
| 4059 | VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, "vkCmdCopyImageToBuffer()", VALIDATION_ERROR_1920017c, |
| 4060 | &hit_error); |
Mark Lobodzinski | 033c90b | 2017-02-15 13:58:23 -0700 | [diff] [blame] | 4061 | skip |= ValidateCopyBufferImageTransferGranularityRequirements(device_data, cb_node, src_image_state, &pRegions[i], i, |
Tobin Ehlis | 2d85ec6 | 2017-03-14 15:38:48 -0600 | [diff] [blame] | 4062 | "vkCmdCopyImageToBuffer()"); |
Mark Lobodzinski | 033c90b | 2017-02-15 13:58:23 -0700 | [diff] [blame] | 4063 | } |
| 4064 | return skip; |
| 4065 | } |
| 4066 | |
| 4067 | 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] | 4068 | BUFFER_STATE *dst_buffer_state, uint32_t region_count, const VkBufferImageCopy *regions, |
| 4069 | VkImageLayout src_image_layout) { |
| 4070 | // Make sure that all image slices are updated to correct layout |
| 4071 | for (uint32_t i = 0; i < region_count; ++i) { |
| 4072 | SetImageLayout(device_data, cb_node, src_image_state, regions[i].imageSubresource, src_image_layout); |
| 4073 | } |
Mark Lobodzinski | 033c90b | 2017-02-15 13:58:23 -0700 | [diff] [blame] | 4074 | // Update bindings between buffer/image and cmd buffer |
| 4075 | AddCommandBufferBindingImage(device_data, cb_node, src_image_state); |
Mark Lobodzinski | 1fe9b00 | 2017-02-15 14:11:12 -0700 | [diff] [blame] | 4076 | AddCommandBufferBindingBuffer(device_data, cb_node, dst_buffer_state); |
Mark Lobodzinski | 033c90b | 2017-02-15 13:58:23 -0700 | [diff] [blame] | 4077 | |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 4078 | std::function<bool()> function = [=]() { |
| 4079 | return ValidateImageMemoryIsValid(device_data, src_image_state, "vkCmdCopyImageToBuffer()"); |
| 4080 | }; |
Tobin Ehlis | a17a529 | 2017-07-28 12:11:30 -0600 | [diff] [blame] | 4081 | cb_node->queue_submit_functions.push_back(function); |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 4082 | function = [=]() { |
Mark Lobodzinski | 1fe9b00 | 2017-02-15 14:11:12 -0700 | [diff] [blame] | 4083 | SetBufferMemoryValid(device_data, dst_buffer_state, true); |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 4084 | return false; |
| 4085 | }; |
Tobin Ehlis | a17a529 | 2017-07-28 12:11:30 -0600 | [diff] [blame] | 4086 | cb_node->queue_submit_functions.push_back(function); |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 4087 | } |
| 4088 | |
| 4089 | 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] | 4090 | 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] | 4091 | const VkBufferImageCopy *pRegions, const char *func_name) { |
| 4092 | const debug_report_data *report_data = core_validation::GetReportData(device_data); |
| 4093 | bool skip = ValidateBufferImageCopyData(report_data, regionCount, pRegions, dst_image_state, "vkCmdCopyBufferToImage"); |
| 4094 | |
| 4095 | // Validate command buffer state |
John Zulauf | 5c2750c | 2018-01-30 15:04:56 -0700 | [diff] [blame] | 4096 | skip |= ValidateCmd(device_data, cb_node, CMD_COPYBUFFERTOIMAGE, "vkCmdCopyBufferToImage()"); |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 4097 | |
| 4098 | // Command pool must support graphics, compute, or transfer operations |
| 4099 | auto pPool = GetCommandPoolNode(device_data, cb_node->createInfo.commandPool); |
| 4100 | VkQueueFlags queue_flags = GetPhysDevProperties(device_data)->queue_family_properties[pPool->queueFamilyIndex].queueFlags; |
| 4101 | if (0 == (queue_flags & (VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT | VK_QUEUE_TRANSFER_BIT))) { |
| 4102 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 4103 | HandleToUint64(cb_node->createInfo.commandPool), VALIDATION_ERROR_18e02415, |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 4104 | "Cannot call vkCmdCopyBufferToImage() on a command buffer allocated from a pool without graphics, compute, " |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 4105 | "or transfer capabilities.."); |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 4106 | } |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 4107 | skip |= ValidateImageBounds(report_data, dst_image_state, regionCount, pRegions, "vkCmdCopyBufferToImage()", |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 4108 | VALIDATION_ERROR_18e00158); |
Chris Forbes | e8ba09a | 2017-06-01 17:39:02 -0700 | [diff] [blame] | 4109 | 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] | 4110 | VALIDATION_ERROR_18e00156); |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 4111 | 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] | 4112 | VALIDATION_ERROR_18e00166); |
| 4113 | skip |= ValidateMemoryIsBoundToBuffer(device_data, src_buffer_state, "vkCmdCopyBufferToImage()", VALIDATION_ERROR_18e00160); |
| 4114 | skip |= ValidateMemoryIsBoundToImage(device_data, dst_image_state, "vkCmdCopyBufferToImage()", VALIDATION_ERROR_18e00164); |
| 4115 | skip |= ValidateBufferUsageFlags(device_data, src_buffer_state, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, true, |
| 4116 | VALIDATION_ERROR_18e0015c, "vkCmdCopyBufferToImage()", "VK_BUFFER_USAGE_TRANSFER_SRC_BIT"); |
| 4117 | 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] | 4118 | "vkCmdCopyBufferToImage()", "VK_IMAGE_USAGE_TRANSFER_DST_BIT"); |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 4119 | skip |= insideRenderPass(device_data, cb_node, "vkCmdCopyBufferToImage()", VALIDATION_ERROR_18e00017); |
Tobin Ehlis | c826645 | 2017-04-07 12:20:30 -0600 | [diff] [blame] | 4120 | bool hit_error = false; |
Mark Lobodzinski | 033c90b | 2017-02-15 13:58:23 -0700 | [diff] [blame] | 4121 | for (uint32_t i = 0; i < regionCount; ++i) { |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 4122 | skip |= VerifyImageLayout(device_data, cb_node, dst_image_state, pRegions[i].imageSubresource, dstImageLayout, |
| 4123 | VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, "vkCmdCopyBufferToImage()", VALIDATION_ERROR_18e0016a, |
| 4124 | &hit_error); |
Mark Lobodzinski | 033c90b | 2017-02-15 13:58:23 -0700 | [diff] [blame] | 4125 | skip |= ValidateCopyBufferImageTransferGranularityRequirements(device_data, cb_node, dst_image_state, &pRegions[i], i, |
| 4126 | "vkCmdCopyBufferToImage()"); |
| 4127 | } |
| 4128 | return skip; |
| 4129 | } |
| 4130 | |
Mark Lobodzinski | 1fe9b00 | 2017-02-15 14:11:12 -0700 | [diff] [blame] | 4131 | 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] | 4132 | IMAGE_STATE *dst_image_state, uint32_t region_count, const VkBufferImageCopy *regions, |
| 4133 | VkImageLayout dst_image_layout) { |
| 4134 | // Make sure that all image slices are updated to correct layout |
| 4135 | for (uint32_t i = 0; i < region_count; ++i) { |
| 4136 | SetImageLayout(device_data, cb_node, dst_image_state, regions[i].imageSubresource, dst_image_layout); |
| 4137 | } |
Mark Lobodzinski | 1fe9b00 | 2017-02-15 14:11:12 -0700 | [diff] [blame] | 4138 | AddCommandBufferBindingBuffer(device_data, cb_node, src_buffer_state); |
Mark Lobodzinski | 033c90b | 2017-02-15 13:58:23 -0700 | [diff] [blame] | 4139 | AddCommandBufferBindingImage(device_data, cb_node, dst_image_state); |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 4140 | std::function<bool()> function = [=]() { |
| 4141 | SetImageMemoryValid(device_data, dst_image_state, true); |
| 4142 | return false; |
| 4143 | }; |
Tobin Ehlis | a17a529 | 2017-07-28 12:11:30 -0600 | [diff] [blame] | 4144 | cb_node->queue_submit_functions.push_back(function); |
Mark Lobodzinski | 1fe9b00 | 2017-02-15 14:11:12 -0700 | [diff] [blame] | 4145 | function = [=]() { return ValidateBufferMemoryIsValid(device_data, src_buffer_state, "vkCmdCopyBufferToImage()"); }; |
Tobin Ehlis | a17a529 | 2017-07-28 12:11:30 -0600 | [diff] [blame] | 4146 | cb_node->queue_submit_functions.push_back(function); |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 4147 | } |
Mike Weiblen | 672b58b | 2017-02-21 14:32:53 -0700 | [diff] [blame] | 4148 | |
| 4149 | bool PreCallValidateGetImageSubresourceLayout(layer_data *device_data, VkImage image, const VkImageSubresource *pSubresource) { |
| 4150 | const auto report_data = core_validation::GetReportData(device_data); |
| 4151 | bool skip = false; |
| 4152 | const VkImageAspectFlags sub_aspect = pSubresource->aspectMask; |
| 4153 | |
Dave Houlton | 1d960ff | 2018-01-19 12:17:05 -0700 | [diff] [blame] | 4154 | // The aspectMask member of pSubresource must only have a single bit set |
Mike Weiblen | 672b58b | 2017-02-21 14:32:53 -0700 | [diff] [blame] | 4155 | const int num_bits = sizeof(sub_aspect) * CHAR_BIT; |
| 4156 | std::bitset<num_bits> aspect_mask_bits(sub_aspect); |
| 4157 | if (aspect_mask_bits.count() != 1) { |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 4158 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, HandleToUint64(image), |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 4159 | VALIDATION_ERROR_2a6007ca, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 4160 | "vkGetImageSubresourceLayout(): VkImageSubresource.aspectMask must have exactly 1 bit set."); |
Mike Weiblen | 672b58b | 2017-02-21 14:32:53 -0700 | [diff] [blame] | 4161 | } |
| 4162 | |
| 4163 | IMAGE_STATE *image_entry = GetImageState(device_data, image); |
| 4164 | if (!image_entry) { |
| 4165 | return skip; |
| 4166 | } |
| 4167 | |
Dave Houlton | 1d960ff | 2018-01-19 12:17:05 -0700 | [diff] [blame] | 4168 | // image must have been created with tiling equal to VK_IMAGE_TILING_LINEAR |
Mike Weiblen | 672b58b | 2017-02-21 14:32:53 -0700 | [diff] [blame] | 4169 | if (image_entry->createInfo.tiling != VK_IMAGE_TILING_LINEAR) { |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 4170 | skip |= |
| 4171 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, HandleToUint64(image), |
| 4172 | VALIDATION_ERROR_2a6007c8, "vkGetImageSubresourceLayout(): Image must have tiling of VK_IMAGE_TILING_LINEAR."); |
Mike Weiblen | 672b58b | 2017-02-21 14:32:53 -0700 | [diff] [blame] | 4173 | } |
| 4174 | |
Dave Houlton | 1d960ff | 2018-01-19 12:17:05 -0700 | [diff] [blame] | 4175 | // mipLevel must be less than the mipLevels specified in VkImageCreateInfo when the image was created |
Mike Weiblen | 672b58b | 2017-02-21 14:32:53 -0700 | [diff] [blame] | 4176 | if (pSubresource->mipLevel >= image_entry->createInfo.mipLevels) { |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 4177 | skip |= |
| 4178 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, HandleToUint64(image), |
| 4179 | VALIDATION_ERROR_2a600d68, "vkGetImageSubresourceLayout(): pSubresource.mipLevel (%d) must be less than %d.", |
| 4180 | pSubresource->mipLevel, image_entry->createInfo.mipLevels); |
Mike Weiblen | 672b58b | 2017-02-21 14:32:53 -0700 | [diff] [blame] | 4181 | } |
| 4182 | |
Dave Houlton | 1d960ff | 2018-01-19 12:17:05 -0700 | [diff] [blame] | 4183 | // arrayLayer must be less than the arrayLayers specified in VkImageCreateInfo when the image was created |
Mike Weiblen | 672b58b | 2017-02-21 14:32:53 -0700 | [diff] [blame] | 4184 | if (pSubresource->arrayLayer >= image_entry->createInfo.arrayLayers) { |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 4185 | skip |= |
| 4186 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, HandleToUint64(image), |
| 4187 | VALIDATION_ERROR_2a600d6a, "vkGetImageSubresourceLayout(): pSubresource.arrayLayer (%d) must be less than %d.", |
| 4188 | pSubresource->arrayLayer, image_entry->createInfo.arrayLayers); |
Mike Weiblen | 672b58b | 2017-02-21 14:32:53 -0700 | [diff] [blame] | 4189 | } |
| 4190 | |
Dave Houlton | 1d960ff | 2018-01-19 12:17:05 -0700 | [diff] [blame] | 4191 | // subresource's aspect must be compatible with image's format. |
Mike Weiblen | 672b58b | 2017-02-21 14:32:53 -0700 | [diff] [blame] | 4192 | const VkFormat img_format = image_entry->createInfo.format; |
Dave Houlton | 1d960ff | 2018-01-19 12:17:05 -0700 | [diff] [blame] | 4193 | if (FormatIsMultiplane(img_format)) { |
| 4194 | VkImageAspectFlags allowed_flags = (VK_IMAGE_ASPECT_PLANE_0_BIT_KHR | VK_IMAGE_ASPECT_PLANE_1_BIT_KHR); |
| 4195 | UNIQUE_VALIDATION_ERROR_CODE vuid = VALIDATION_ERROR_2a600c5a; // 2-plane version |
| 4196 | if (FormatPlaneCount(img_format) > 2u) { |
| 4197 | allowed_flags |= VK_IMAGE_ASPECT_PLANE_2_BIT_KHR; |
| 4198 | vuid = VALIDATION_ERROR_2a600c5c; // 3-plane version |
| 4199 | } |
| 4200 | if (sub_aspect != (sub_aspect & allowed_flags)) { |
| 4201 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 4202 | HandleToUint64(image), vuid, |
Dave Houlton | 1d960ff | 2018-01-19 12:17:05 -0700 | [diff] [blame] | 4203 | "vkGetImageSubresourceLayout(): For multi-planar images, VkImageSubresource.aspectMask (0x%" PRIx32 |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 4204 | ") must be a single-plane specifier flag.", |
| 4205 | sub_aspect); |
Dave Houlton | 1d960ff | 2018-01-19 12:17:05 -0700 | [diff] [blame] | 4206 | } |
| 4207 | } else if (FormatIsColor(img_format)) { |
Mike Weiblen | 672b58b | 2017-02-21 14:32:53 -0700 | [diff] [blame] | 4208 | if (sub_aspect != VK_IMAGE_ASPECT_COLOR_BIT) { |
Dave Houlton | 852287e | 2018-01-19 15:11:51 -0700 | [diff] [blame] | 4209 | skip |= log_msg( |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 4210 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, HandleToUint64(image), |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 4211 | VALIDATION_ERROR_0a400c01, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 4212 | "vkGetImageSubresourceLayout(): For color formats, VkImageSubresource.aspectMask must be VK_IMAGE_ASPECT_COLOR."); |
Mike Weiblen | 672b58b | 2017-02-21 14:32:53 -0700 | [diff] [blame] | 4213 | } |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 4214 | } else if (FormatIsDepthOrStencil(img_format)) { |
Mike Weiblen | 672b58b | 2017-02-21 14:32:53 -0700 | [diff] [blame] | 4215 | 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] | 4216 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 4217 | HandleToUint64(image), VALIDATION_ERROR_0a400c01, |
Mike Weiblen | 672b58b | 2017-02-21 14:32:53 -0700 | [diff] [blame] | 4218 | "vkGetImageSubresourceLayout(): For depth/stencil formats, VkImageSubresource.aspectMask must be " |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 4219 | "either VK_IMAGE_ASPECT_DEPTH_BIT or VK_IMAGE_ASPECT_STENCIL_BIT."); |
Mike Weiblen | 672b58b | 2017-02-21 14:32:53 -0700 | [diff] [blame] | 4220 | } |
| 4221 | } |
| 4222 | return skip; |
| 4223 | } |