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