Jeff Bolz | 8769753 | 2019-01-11 22:54:00 -0600 | [diff] [blame] | 1 | /* Copyright (c) 2015-2019 The Khronos Group Inc. |
| 2 | * Copyright (c) 2015-2019 Valve Corporation |
| 3 | * Copyright (c) 2015-2019 LunarG, Inc. |
| 4 | * Copyright (C) 2015-2019 Google Inc. |
Mark Lobodzinski | d42e4d2 | 2017-01-17 14:14:22 -0700 | [diff] [blame] | 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> |
Shannon McPherson | 3ea6513 | 2018-12-05 10:37:39 -0700 | [diff] [blame] | 20 | * Shannon McPherson <shannon@lunarg.com> |
Mark Lobodzinski | d42e4d2 | 2017-01-17 14:14:22 -0700 | [diff] [blame] | 21 | */ |
| 22 | |
| 23 | // Allow use of STL min and max functions in Windows |
| 24 | #define NOMINMAX |
| 25 | |
Dave Houlton | 0d4ad6f | 2018-09-05 14:53:34 -0600 | [diff] [blame] | 26 | #include <cmath> |
| 27 | #include <set> |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 28 | #include <sstream> |
Petr Kraus | 4d71868 | 2017-05-18 03:38:41 +0200 | [diff] [blame] | 29 | #include <string> |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 30 | |
| 31 | #include "vk_enum_string_helper.h" |
| 32 | #include "vk_layer_data.h" |
| 33 | #include "vk_layer_utils.h" |
| 34 | #include "vk_layer_logging.h" |
Dave Houlton | bd2e262 | 2018-04-10 16:41:14 -0600 | [diff] [blame] | 35 | #include "vk_typemap_helper.h" |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 36 | |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 37 | #include "chassis.h" |
Mark Lobodzinski | 76d7666 | 2019-02-14 14:38:21 -0700 | [diff] [blame] | 38 | #include "core_validation.h" |
| 39 | #include "shader_validation.h" |
| 40 | #include "descriptor_sets.h" |
Mark Lobodzinski | d42e4d2 | 2017-01-17 14:14:22 -0700 | [diff] [blame] | 41 | #include "buffer_validation.h" |
Mark Lobodzinski | 42fe5f7 | 2017-01-11 11:36:16 -0700 | [diff] [blame] | 42 | |
John Zulauf | f660ad6 | 2019-03-23 07:16:05 -0600 | [diff] [blame] | 43 | // Transfer VkImageSubresourceLayers into VkImageSubresourceRange struct |
| 44 | static VkImageSubresourceRange RangeFromLayers(const VkImageSubresourceLayers &subresource_layers) { |
| 45 | VkImageSubresourceRange subresource_range; |
| 46 | subresource_range.aspectMask = subresource_layers.aspectMask; |
| 47 | subresource_range.baseArrayLayer = subresource_layers.baseArrayLayer; |
| 48 | subresource_range.layerCount = subresource_layers.layerCount; |
| 49 | subresource_range.baseMipLevel = subresource_layers.mipLevel; |
| 50 | subresource_range.levelCount = 1; |
| 51 | return subresource_range; |
| 52 | } |
| 53 | |
| 54 | IMAGE_STATE::IMAGE_STATE(VkImage img, const VkImageCreateInfo *pCreateInfo) |
| 55 | : image(img), |
| 56 | createInfo(*pCreateInfo), |
| 57 | valid(false), |
| 58 | acquired(false), |
| 59 | shared_presentable(false), |
| 60 | layout_locked(false), |
| 61 | get_sparse_reqs_called(false), |
| 62 | sparse_metadata_required(false), |
| 63 | sparse_metadata_bound(false), |
| 64 | imported_ahb(false), |
| 65 | has_ahb_format(false), |
| 66 | ahb_format(0), |
| 67 | full_range{}, |
| 68 | sparse_requirements{} { |
| 69 | if ((createInfo.sharingMode == VK_SHARING_MODE_CONCURRENT) && (createInfo.queueFamilyIndexCount > 0)) { |
| 70 | uint32_t *pQueueFamilyIndices = new uint32_t[createInfo.queueFamilyIndexCount]; |
| 71 | for (uint32_t i = 0; i < createInfo.queueFamilyIndexCount; i++) { |
| 72 | pQueueFamilyIndices[i] = pCreateInfo->pQueueFamilyIndices[i]; |
| 73 | } |
| 74 | createInfo.pQueueFamilyIndices = pQueueFamilyIndices; |
| 75 | } |
| 76 | |
| 77 | if (createInfo.flags & VK_IMAGE_CREATE_SPARSE_BINDING_BIT) { |
| 78 | sparse = true; |
| 79 | } |
| 80 | const auto format = createInfo.format; |
| 81 | VkImageSubresourceRange init_range{0, 0, VK_REMAINING_MIP_LEVELS, 0, VK_REMAINING_ARRAY_LAYERS}; |
| 82 | if (FormatIsColor(format) || FormatIsMultiplane(format)) { |
| 83 | init_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; // Normalization will expand this for multiplane |
| 84 | } else { |
| 85 | init_range.aspectMask = |
| 86 | (FormatHasDepth(format) ? VK_IMAGE_ASPECT_DEPTH_BIT : 0) | (FormatHasStencil(format) ? VK_IMAGE_ASPECT_STENCIL_BIT : 0); |
| 87 | } |
| 88 | full_range = NormalizeSubresourceRange(*this, init_range); |
| 89 | } |
| 90 | |
| 91 | IMAGE_VIEW_STATE::IMAGE_VIEW_STATE(const IMAGE_STATE *image_state, VkImageView iv, const VkImageViewCreateInfo *ci) |
| 92 | : image_view(iv), create_info(*ci), normalized_subresource_range(ci->subresourceRange), samplerConversion(VK_NULL_HANDLE) { |
| 93 | auto *conversionInfo = lvl_find_in_chain<VkSamplerYcbcrConversionInfo>(create_info.pNext); |
| 94 | if (conversionInfo) samplerConversion = conversionInfo->conversion; |
| 95 | if (image_state) { |
| 96 | // A light normalization of the createInfo range |
| 97 | auto &sub_res_range = create_info.subresourceRange; |
| 98 | sub_res_range.levelCount = ResolveRemainingLevels(&sub_res_range, image_state->createInfo.mipLevels); |
| 99 | sub_res_range.layerCount = ResolveRemainingLayers(&sub_res_range, image_state->createInfo.arrayLayers); |
| 100 | |
| 101 | // Cache a full normalization (for "full image/whole image" comparisons) |
| 102 | normalized_subresource_range = NormalizeSubresourceRange(*image_state, ci->subresourceRange); |
| 103 | } |
| 104 | } |
| 105 | |
Dave Houlton | d961131 | 2018-11-19 17:03:36 -0700 | [diff] [blame] | 106 | uint32_t FullMipChainLevels(uint32_t height, uint32_t width, uint32_t depth) { |
| 107 | // uint cast applies floor() |
| 108 | return 1u + (uint32_t)log2(std::max({height, width, depth})); |
| 109 | } |
| 110 | |
| 111 | uint32_t FullMipChainLevels(VkExtent3D extent) { return FullMipChainLevels(extent.height, extent.width, extent.depth); } |
| 112 | |
| 113 | uint32_t FullMipChainLevels(VkExtent2D extent) { return FullMipChainLevels(extent.height, extent.width); } |
| 114 | |
John Zulauf | f660ad6 | 2019-03-23 07:16:05 -0600 | [diff] [blame] | 115 | VkImageSubresourceRange NormalizeSubresourceRange(const IMAGE_STATE &image_state, const VkImageSubresourceRange &range) { |
| 116 | const VkImageCreateInfo &image_create_info = image_state.createInfo; |
| 117 | VkImageSubresourceRange norm = range; |
| 118 | norm.levelCount = ResolveRemainingLevels(&range, image_create_info.mipLevels); |
| 119 | |
| 120 | // Special case for 3D images with VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT_KHR flag bit, where <extent.depth> and |
| 121 | // <arrayLayers> can potentially alias. |
| 122 | uint32_t layer_limit = (0 != (image_create_info.flags & VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT_KHR)) |
| 123 | ? image_create_info.extent.depth |
| 124 | : image_create_info.arrayLayers; |
| 125 | norm.layerCount = ResolveRemainingLayers(&range, layer_limit); |
| 126 | |
| 127 | // For multiplanar formats, IMAGE_ASPECT_COLOR is equivalent to adding the aspect of the individual planes |
| 128 | VkImageAspectFlags &aspect_mask = norm.aspectMask; |
| 129 | if (FormatIsMultiplane(image_create_info.format)) { |
| 130 | if (aspect_mask & VK_IMAGE_ASPECT_COLOR_BIT) { |
| 131 | aspect_mask &= ~VK_IMAGE_ASPECT_COLOR_BIT; |
| 132 | aspect_mask |= (VK_IMAGE_ASPECT_PLANE_0_BIT | VK_IMAGE_ASPECT_PLANE_1_BIT); |
| 133 | if (FormatPlaneCount(image_create_info.format) > 2) { |
| 134 | aspect_mask |= VK_IMAGE_ASPECT_PLANE_2_BIT; |
| 135 | } |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 136 | } |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 137 | } |
John Zulauf | f660ad6 | 2019-03-23 07:16:05 -0600 | [diff] [blame] | 138 | return norm; |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 139 | } |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 140 | |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 141 | template <class OBJECT, class LAYOUT> |
Mark Lobodzinski | 8564e44 | 2019-03-07 12:49:41 -0700 | [diff] [blame] | 142 | void CoreChecks::SetLayout(OBJECT *pObject, VkImage image, VkImageSubresource range, const LAYOUT &layout) { |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 143 | ImageSubresourcePair imgpair = {image, true, range}; |
Mark Lobodzinski | 8564e44 | 2019-03-07 12:49:41 -0700 | [diff] [blame] | 144 | SetLayout(pObject, imgpair, layout, VK_IMAGE_ASPECT_COLOR_BIT); |
| 145 | SetLayout(pObject, imgpair, layout, VK_IMAGE_ASPECT_DEPTH_BIT); |
| 146 | SetLayout(pObject, imgpair, layout, VK_IMAGE_ASPECT_STENCIL_BIT); |
| 147 | SetLayout(pObject, imgpair, layout, VK_IMAGE_ASPECT_METADATA_BIT); |
Mark Lobodzinski | 60e7903 | 2019-03-07 10:22:31 -0700 | [diff] [blame] | 148 | if (GetDeviceExtensions()->vk_khr_sampler_ycbcr_conversion) { |
Mark Lobodzinski | 8564e44 | 2019-03-07 12:49:41 -0700 | [diff] [blame] | 149 | SetLayout(pObject, imgpair, layout, VK_IMAGE_ASPECT_PLANE_0_BIT_KHR); |
| 150 | SetLayout(pObject, imgpair, layout, VK_IMAGE_ASPECT_PLANE_1_BIT_KHR); |
| 151 | SetLayout(pObject, imgpair, layout, VK_IMAGE_ASPECT_PLANE_2_BIT_KHR); |
Dave Houlton | b3f4b28 | 2018-02-22 16:25:16 -0700 | [diff] [blame] | 152 | } |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | template <class OBJECT, class LAYOUT> |
Mark Lobodzinski | 8564e44 | 2019-03-07 12:49:41 -0700 | [diff] [blame] | 156 | void CoreChecks::SetLayout(OBJECT *pObject, ImageSubresourcePair imgpair, const LAYOUT &layout, VkImageAspectFlags aspectMask) { |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 157 | if (imgpair.subresource.aspectMask & aspectMask) { |
| 158 | imgpair.subresource.aspectMask = aspectMask; |
Mark Lobodzinski | 8564e44 | 2019-03-07 12:49:41 -0700 | [diff] [blame] | 159 | SetLayout(pObject, imgpair, layout); |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 160 | } |
| 161 | } |
| 162 | |
Tony Barbour | df013b9 | 2017-01-25 12:53:48 -0700 | [diff] [blame] | 163 | // Set the layout in supplied map |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 164 | void CoreChecks::SetLayout(std::unordered_map<ImageSubresourcePair, IMAGE_LAYOUT_NODE> &imageLayoutMap, |
| 165 | ImageSubresourcePair imgpair, VkImageLayout layout) { |
Dave Houlton | b3f4b28 | 2018-02-22 16:25:16 -0700 | [diff] [blame] | 166 | auto it = imageLayoutMap.find(imgpair); |
| 167 | if (it != imageLayoutMap.end()) { |
| 168 | it->second.layout = layout; // Update |
| 169 | } else { |
| 170 | imageLayoutMap[imgpair].layout = layout; // Insert |
| 171 | } |
Tony Barbour | df013b9 | 2017-01-25 12:53:48 -0700 | [diff] [blame] | 172 | } |
| 173 | |
Mark Lobodzinski | ef4ab2e | 2019-03-07 13:23:36 -0700 | [diff] [blame] | 174 | bool CoreChecks::FindLayoutVerifyLayout(ImageSubresourcePair imgpair, VkImageLayout &layout, const VkImageAspectFlags aspectMask) { |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 175 | if (!(imgpair.subresource.aspectMask & aspectMask)) { |
| 176 | return false; |
| 177 | } |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 178 | VkImageAspectFlags oldAspectMask = imgpair.subresource.aspectMask; |
| 179 | imgpair.subresource.aspectMask = aspectMask; |
Mark Lobodzinski | 44d46d5 | 2019-03-07 11:04:06 -0700 | [diff] [blame] | 180 | auto imgsubIt = (*GetImageLayoutMap()).find(imgpair); |
| 181 | if (imgsubIt == (*GetImageLayoutMap()).end()) { |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 182 | return false; |
| 183 | } |
| 184 | if (layout != VK_IMAGE_LAYOUT_MAX_ENUM && layout != imgsubIt->second.layout) { |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 185 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, HandleToUint64(imgpair.image), |
Dave Houlton | 5165390 | 2018-06-22 17:32:13 -0600 | [diff] [blame] | 186 | kVUID_Core_DrawState_InvalidLayout, |
Locke | e9aeebf | 2019-03-03 23:50:08 -0700 | [diff] [blame] | 187 | "Cannot query for VkImage %s layout when combined aspect mask %d has multiple layout types: %s and %s", |
| 188 | report_data->FormatHandle(imgpair.image).c_str(), oldAspectMask, string_VkImageLayout(layout), |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 189 | string_VkImageLayout(imgsubIt->second.layout)); |
| 190 | } |
| 191 | layout = imgsubIt->second.layout; |
| 192 | return true; |
| 193 | } |
| 194 | |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 195 | // Find layout(s) on the global level |
Mark Lobodzinski | ef4ab2e | 2019-03-07 13:23:36 -0700 | [diff] [blame] | 196 | bool CoreChecks::FindGlobalLayout(ImageSubresourcePair imgpair, VkImageLayout &layout) { |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 197 | layout = VK_IMAGE_LAYOUT_MAX_ENUM; |
Mark Lobodzinski | ef4ab2e | 2019-03-07 13:23:36 -0700 | [diff] [blame] | 198 | FindLayoutVerifyLayout(imgpair, layout, VK_IMAGE_ASPECT_COLOR_BIT); |
| 199 | FindLayoutVerifyLayout(imgpair, layout, VK_IMAGE_ASPECT_DEPTH_BIT); |
| 200 | FindLayoutVerifyLayout(imgpair, layout, VK_IMAGE_ASPECT_STENCIL_BIT); |
| 201 | FindLayoutVerifyLayout(imgpair, layout, VK_IMAGE_ASPECT_METADATA_BIT); |
Mark Lobodzinski | 60e7903 | 2019-03-07 10:22:31 -0700 | [diff] [blame] | 202 | if (GetDeviceExtensions()->vk_khr_sampler_ycbcr_conversion) { |
Mark Lobodzinski | ef4ab2e | 2019-03-07 13:23:36 -0700 | [diff] [blame] | 203 | FindLayoutVerifyLayout(imgpair, layout, VK_IMAGE_ASPECT_PLANE_0_BIT_KHR); |
| 204 | FindLayoutVerifyLayout(imgpair, layout, VK_IMAGE_ASPECT_PLANE_1_BIT_KHR); |
| 205 | FindLayoutVerifyLayout(imgpair, layout, VK_IMAGE_ASPECT_PLANE_2_BIT_KHR); |
Dave Houlton | b3f4b28 | 2018-02-22 16:25:16 -0700 | [diff] [blame] | 206 | } |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 207 | if (layout == VK_IMAGE_LAYOUT_MAX_ENUM) { |
| 208 | imgpair = {imgpair.image, false, VkImageSubresource()}; |
Mark Lobodzinski | 44d46d5 | 2019-03-07 11:04:06 -0700 | [diff] [blame] | 209 | auto imgsubIt = (*GetImageLayoutMap()).find(imgpair); |
| 210 | if (imgsubIt == (*GetImageLayoutMap()).end()) return false; |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 211 | layout = imgsubIt->second.layout; |
| 212 | } |
| 213 | return true; |
| 214 | } |
| 215 | |
Mark Lobodzinski | ef4ab2e | 2019-03-07 13:23:36 -0700 | [diff] [blame] | 216 | bool CoreChecks::FindLayouts(VkImage image, std::vector<VkImageLayout> &layouts) { |
Mark Lobodzinski | 2a8d840 | 2019-04-19 13:41:41 -0600 | [diff] [blame^] | 217 | auto sub_data = imageSubresourceMap.find(image); |
| 218 | if (sub_data == imageSubresourceMap.end()) return false; |
Mark Lobodzinski | 8ddc23f | 2019-03-06 11:48:49 -0700 | [diff] [blame] | 219 | auto image_state = GetImageState(image); |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 220 | if (!image_state) return false; |
| 221 | bool ignoreGlobal = false; |
| 222 | // TODO: Make this robust for >1 aspect mask. Now it will just say ignore potential errors in this case. |
| 223 | if (sub_data->second.size() >= (image_state->createInfo.arrayLayers * image_state->createInfo.mipLevels + 1)) { |
| 224 | ignoreGlobal = true; |
| 225 | } |
| 226 | for (auto imgsubpair : sub_data->second) { |
| 227 | if (ignoreGlobal && !imgsubpair.hasSubresource) continue; |
Mark Lobodzinski | 44d46d5 | 2019-03-07 11:04:06 -0700 | [diff] [blame] | 228 | auto img_data = (*GetImageLayoutMap()).find(imgsubpair); |
| 229 | if (img_data != (*GetImageLayoutMap()).end()) { |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 230 | layouts.push_back(img_data->second.layout); |
| 231 | } |
| 232 | } |
| 233 | return true; |
| 234 | } |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 235 | |
| 236 | bool CoreChecks::FindLayout(const std::unordered_map<ImageSubresourcePair, IMAGE_LAYOUT_NODE> &imageLayoutMap, |
| 237 | ImageSubresourcePair imgpair, VkImageLayout &layout, const VkImageAspectFlags aspectMask) { |
Tony Barbour | df013b9 | 2017-01-25 12:53:48 -0700 | [diff] [blame] | 238 | if (!(imgpair.subresource.aspectMask & aspectMask)) { |
| 239 | return false; |
| 240 | } |
| 241 | imgpair.subresource.aspectMask = aspectMask; |
| 242 | auto imgsubIt = imageLayoutMap.find(imgpair); |
| 243 | if (imgsubIt == imageLayoutMap.end()) { |
| 244 | return false; |
| 245 | } |
| 246 | layout = imgsubIt->second.layout; |
| 247 | return true; |
Tony Barbour | e0c5cc9 | 2017-02-08 13:53:39 -0700 | [diff] [blame] | 248 | } |
Tony Barbour | df013b9 | 2017-01-25 12:53:48 -0700 | [diff] [blame] | 249 | |
| 250 | // find layout in supplied map |
Mark Lobodzinski | ef4ab2e | 2019-03-07 13:23:36 -0700 | [diff] [blame] | 251 | bool CoreChecks::FindLayout(const std::unordered_map<ImageSubresourcePair, IMAGE_LAYOUT_NODE> &imageLayoutMap, |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 252 | ImageSubresourcePair imgpair, VkImageLayout &layout) { |
Tony Barbour | df013b9 | 2017-01-25 12:53:48 -0700 | [diff] [blame] | 253 | layout = VK_IMAGE_LAYOUT_MAX_ENUM; |
| 254 | FindLayout(imageLayoutMap, imgpair, layout, VK_IMAGE_ASPECT_COLOR_BIT); |
| 255 | FindLayout(imageLayoutMap, imgpair, layout, VK_IMAGE_ASPECT_DEPTH_BIT); |
| 256 | FindLayout(imageLayoutMap, imgpair, layout, VK_IMAGE_ASPECT_STENCIL_BIT); |
| 257 | FindLayout(imageLayoutMap, imgpair, layout, VK_IMAGE_ASPECT_METADATA_BIT); |
Mark Lobodzinski | 60e7903 | 2019-03-07 10:22:31 -0700 | [diff] [blame] | 258 | if (GetDeviceExtensions()->vk_khr_sampler_ycbcr_conversion) { |
Dave Houlton | b3f4b28 | 2018-02-22 16:25:16 -0700 | [diff] [blame] | 259 | FindLayout(imageLayoutMap, imgpair, layout, VK_IMAGE_ASPECT_PLANE_0_BIT_KHR); |
| 260 | FindLayout(imageLayoutMap, imgpair, layout, VK_IMAGE_ASPECT_PLANE_1_BIT_KHR); |
| 261 | FindLayout(imageLayoutMap, imgpair, layout, VK_IMAGE_ASPECT_PLANE_2_BIT_KHR); |
| 262 | } |
| 263 | // Image+subresource not found, look for image handle w/o subresource |
Tony Barbour | df013b9 | 2017-01-25 12:53:48 -0700 | [diff] [blame] | 264 | if (layout == VK_IMAGE_LAYOUT_MAX_ENUM) { |
| 265 | imgpair = {imgpair.image, false, VkImageSubresource()}; |
| 266 | auto imgsubIt = imageLayoutMap.find(imgpair); |
| 267 | if (imgsubIt == imageLayoutMap.end()) return false; |
| 268 | layout = imgsubIt->second.layout; |
| 269 | } |
| 270 | return true; |
| 271 | } |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 272 | |
| 273 | // Set the layout on the global level |
Mark Lobodzinski | 8564e44 | 2019-03-07 12:49:41 -0700 | [diff] [blame] | 274 | void CoreChecks::SetGlobalLayout(ImageSubresourcePair imgpair, const VkImageLayout &layout) { |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 275 | VkImage &image = imgpair.image; |
Mark Lobodzinski | 44d46d5 | 2019-03-07 11:04:06 -0700 | [diff] [blame] | 276 | auto &lmap = (*GetImageLayoutMap()); |
Dave Houlton | b3f4b28 | 2018-02-22 16:25:16 -0700 | [diff] [blame] | 277 | auto data = lmap.find(imgpair); |
| 278 | if (data != lmap.end()) { |
| 279 | data->second.layout = layout; // Update |
| 280 | } else { |
| 281 | lmap[imgpair].layout = layout; // Insert |
| 282 | } |
Mark Lobodzinski | 2a8d840 | 2019-04-19 13:41:41 -0600 | [diff] [blame^] | 283 | auto &image_subresources = imageSubresourceMap[image]; |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 284 | auto subresource = std::find(image_subresources.begin(), image_subresources.end(), imgpair); |
| 285 | if (subresource == image_subresources.end()) { |
| 286 | image_subresources.push_back(imgpair); |
| 287 | } |
| 288 | } |
| 289 | |
Tobin Ehlis | e35b66a | 2017-03-15 12:18:31 -0600 | [diff] [blame] | 290 | // Set image layout for given VkImageSubresourceRange struct |
John Zulauf | f660ad6 | 2019-03-23 07:16:05 -0600 | [diff] [blame] | 291 | void CoreChecks::SetImageLayout(GLOBAL_CB_NODE *cb_node, const IMAGE_STATE &image_state, |
| 292 | const VkImageSubresourceRange &image_subresource_range, VkImageLayout layout, |
| 293 | VkImageLayout expected_layout) { |
| 294 | auto *subresource_map = GetImageSubresourceLayoutMap(cb_node, image_state); |
| 295 | assert(subresource_map); // the non-const getter must return a valid pointer |
| 296 | if (subresource_map->SetSubresourceRangeLayout(image_subresource_range, layout, expected_layout)) { |
| 297 | cb_node->image_layout_change_count++; // Change the version of this data to force revalidation |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 298 | } |
| 299 | } |
John Zulauf | f660ad6 | 2019-03-23 07:16:05 -0600 | [diff] [blame] | 300 | |
| 301 | // Set the initial image layout for all slices of an image view |
| 302 | void CoreChecks::SetImageViewInitialLayout(GLOBAL_CB_NODE *cb_node, const IMAGE_VIEW_STATE &view_state, VkImageLayout layout) { |
| 303 | IMAGE_STATE *image_state = GetImageState(view_state.create_info.image); |
| 304 | if (image_state) { |
| 305 | auto *subresource_map = GetImageSubresourceLayoutMap(cb_node, *image_state); |
John Zulauf | b61ed97 | 2019-04-09 16:12:35 -0600 | [diff] [blame] | 306 | subresource_map->SetSubresourceRangeInitialLayout(view_state.normalized_subresource_range, layout, *cb_node, &view_state); |
John Zulauf | f660ad6 | 2019-03-23 07:16:05 -0600 | [diff] [blame] | 307 | } |
| 308 | } |
| 309 | |
| 310 | // Set the initial image layout for a passed non-normalized subresource range |
| 311 | void CoreChecks::SetImageInitialLayout(GLOBAL_CB_NODE *cb_node, const IMAGE_STATE &image_state, |
| 312 | const VkImageSubresourceRange &range, VkImageLayout layout) { |
| 313 | auto *subresource_map = GetImageSubresourceLayoutMap(cb_node, image_state); |
| 314 | assert(subresource_map); |
John Zulauf | b61ed97 | 2019-04-09 16:12:35 -0600 | [diff] [blame] | 315 | subresource_map->SetSubresourceRangeInitialLayout(NormalizeSubresourceRange(image_state, range), layout, *cb_node); |
John Zulauf | f660ad6 | 2019-03-23 07:16:05 -0600 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | void CoreChecks::SetImageInitialLayout(GLOBAL_CB_NODE *cb_node, VkImage image, const VkImageSubresourceRange &range, |
| 319 | VkImageLayout layout) { |
| 320 | const IMAGE_STATE *image_state = GetImageState(image); |
| 321 | if (!image_state) return; |
| 322 | SetImageInitialLayout(cb_node, *image_state, range, layout); |
| 323 | }; |
| 324 | |
| 325 | void CoreChecks::SetImageInitialLayout(GLOBAL_CB_NODE *cb_node, const IMAGE_STATE &image_state, |
| 326 | const VkImageSubresourceLayers &layers, VkImageLayout layout) { |
| 327 | SetImageInitialLayout(cb_node, image_state, RangeFromLayers(layers), layout); |
Tobin Ehlis | e35b66a | 2017-03-15 12:18:31 -0600 | [diff] [blame] | 328 | } |
Dave Houlton | ddd65c5 | 2018-05-08 14:58:01 -0600 | [diff] [blame] | 329 | |
Tobin Ehlis | e35b66a | 2017-03-15 12:18:31 -0600 | [diff] [blame] | 330 | // Set image layout for all slices of an image view |
John Zulauf | f660ad6 | 2019-03-23 07:16:05 -0600 | [diff] [blame] | 331 | void CoreChecks::SetImageViewLayout(GLOBAL_CB_NODE *cb_node, const IMAGE_VIEW_STATE &view_state, VkImageLayout layout) { |
| 332 | IMAGE_STATE *image_state = GetImageState(view_state.create_info.image); |
| 333 | if (!image_state) return; // TODO: track/report stale image references |
Tobin Ehlis | e35b66a | 2017-03-15 12:18:31 -0600 | [diff] [blame] | 334 | |
John Zulauf | f660ad6 | 2019-03-23 07:16:05 -0600 | [diff] [blame] | 335 | VkImageSubresourceRange sub_range = view_state.normalized_subresource_range; |
Dave Houlton | ddd65c5 | 2018-05-08 14:58:01 -0600 | [diff] [blame] | 336 | // When changing the layout of a 3D image subresource via a 2D or 2D_ARRRAY image view, all depth slices of |
| 337 | // the subresource mip level(s) are transitioned, ignoring any layers restriction in the subresource info. |
John Zulauf | f660ad6 | 2019-03-23 07:16:05 -0600 | [diff] [blame] | 338 | if ((image_state->createInfo.imageType == VK_IMAGE_TYPE_3D) && (view_state.create_info.viewType != VK_IMAGE_VIEW_TYPE_3D)) { |
Dave Houlton | ddd65c5 | 2018-05-08 14:58:01 -0600 | [diff] [blame] | 339 | sub_range.baseArrayLayer = 0; |
| 340 | sub_range.layerCount = image_state->createInfo.extent.depth; |
| 341 | } |
| 342 | |
John Zulauf | f660ad6 | 2019-03-23 07:16:05 -0600 | [diff] [blame] | 343 | SetImageLayout(cb_node, *image_state, sub_range, layout); |
John Zulauf | 4ccf5c0 | 2018-09-21 11:46:18 -0600 | [diff] [blame] | 344 | } |
| 345 | |
Mark Lobodzinski | ef4ab2e | 2019-03-07 13:23:36 -0700 | [diff] [blame] | 346 | bool CoreChecks::ValidateRenderPassLayoutAgainstFramebufferImageUsage(RenderPassCreateVersion rp_version, VkImageLayout layout, |
| 347 | VkImage image, VkImageView image_view, |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 348 | VkFramebuffer framebuffer, VkRenderPass renderpass, |
| 349 | uint32_t attachment_index, const char *variable_name) { |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 350 | bool skip = false; |
Mark Lobodzinski | 8ddc23f | 2019-03-06 11:48:49 -0700 | [diff] [blame] | 351 | auto image_state = GetImageState(image); |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 352 | const char *vuid; |
| 353 | const bool use_rp2 = (rp_version == RENDER_PASS_VERSION_2); |
| 354 | |
| 355 | if (!image_state) { |
| 356 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, HandleToUint64(image), |
| 357 | "VUID-VkRenderPassBeginInfo-framebuffer-parameter", |
Locke | e9aeebf | 2019-03-03 23:50:08 -0700 | [diff] [blame] | 358 | "Render Pass begin with renderpass %s uses framebuffer %s where pAttachments[%" PRIu32 |
| 359 | "] = image view %s, which refers to an invalid image", |
| 360 | report_data->FormatHandle(renderpass).c_str(), report_data->FormatHandle(framebuffer).c_str(), |
| 361 | attachment_index, report_data->FormatHandle(image_view).c_str()); |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 362 | return skip; |
| 363 | } |
| 364 | |
| 365 | auto image_usage = image_state->createInfo.usage; |
| 366 | |
| 367 | // Check for layouts that mismatch image usages in the framebuffer |
| 368 | if (layout == VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL && !(image_usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT)) { |
| 369 | vuid = use_rp2 ? "VUID-vkCmdBeginRenderPass2KHR-initialLayout-03094" : "VUID-vkCmdBeginRenderPass-initialLayout-00895"; |
| 370 | skip |= |
| 371 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, HandleToUint64(image), vuid, |
Locke | e9aeebf | 2019-03-03 23:50:08 -0700 | [diff] [blame] | 372 | "Layout/usage mismatch for attachment %u in render pass %s" |
| 373 | " - the %s is %s but the image attached to framebuffer %s via image view %s" |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 374 | " was not created with VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT", |
Locke | 7b4f9ac | 2019-04-01 10:58:17 -0600 | [diff] [blame] | 375 | attachment_index, report_data->FormatHandle(renderpass).c_str(), variable_name, string_VkImageLayout(layout), |
| 376 | report_data->FormatHandle(framebuffer).c_str(), report_data->FormatHandle(image_view).c_str()); |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | if (layout == VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL && |
| 380 | !(image_usage & (VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT))) { |
| 381 | vuid = use_rp2 ? "VUID-vkCmdBeginRenderPass2KHR-initialLayout-03097" : "VUID-vkCmdBeginRenderPass-initialLayout-00897"; |
| 382 | skip |= |
| 383 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, HandleToUint64(image), vuid, |
Locke | e9aeebf | 2019-03-03 23:50:08 -0700 | [diff] [blame] | 384 | "Layout/usage mismatch for attachment %u in render pass %s" |
| 385 | " - the %s is %s but the image attached to framebuffer %s via image view %s" |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 386 | " was not created with VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT or VK_IMAGE_USAGE_SAMPLED_BIT", |
Locke | 7b4f9ac | 2019-04-01 10:58:17 -0600 | [diff] [blame] | 387 | attachment_index, report_data->FormatHandle(renderpass).c_str(), variable_name, string_VkImageLayout(layout), |
| 388 | report_data->FormatHandle(framebuffer).c_str(), report_data->FormatHandle(image_view).c_str()); |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | if (layout == VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL && !(image_usage & VK_IMAGE_USAGE_TRANSFER_SRC_BIT)) { |
| 392 | vuid = use_rp2 ? "VUID-vkCmdBeginRenderPass2KHR-initialLayout-03098" : "VUID-vkCmdBeginRenderPass-initialLayout-00898"; |
| 393 | skip |= |
| 394 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, HandleToUint64(image), vuid, |
Locke | e9aeebf | 2019-03-03 23:50:08 -0700 | [diff] [blame] | 395 | "Layout/usage mismatch for attachment %u in render pass %s" |
| 396 | " - the %s is %s but the image attached to framebuffer %s via image view %s" |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 397 | " was not created with VK_IMAGE_USAGE_TRANSFER_SRC_BIT", |
Locke | 7b4f9ac | 2019-04-01 10:58:17 -0600 | [diff] [blame] | 398 | attachment_index, report_data->FormatHandle(renderpass).c_str(), variable_name, string_VkImageLayout(layout), |
| 399 | report_data->FormatHandle(framebuffer).c_str(), report_data->FormatHandle(image_view).c_str()); |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | if (layout == VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL && !(image_usage & VK_IMAGE_USAGE_TRANSFER_DST_BIT)) { |
| 403 | vuid = use_rp2 ? "VUID-vkCmdBeginRenderPass2KHR-initialLayout-03099" : "VUID-vkCmdBeginRenderPass-initialLayout-00899"; |
| 404 | skip |= |
| 405 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, HandleToUint64(image), vuid, |
Locke | e9aeebf | 2019-03-03 23:50:08 -0700 | [diff] [blame] | 406 | "Layout/usage mismatch for attachment %u in render pass %s" |
| 407 | " - the %s is %s but the image attached to framebuffer %s via image view %s" |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 408 | " was not created with VK_IMAGE_USAGE_TRANSFER_DST_BIT", |
Locke | 7b4f9ac | 2019-04-01 10:58:17 -0600 | [diff] [blame] | 409 | attachment_index, report_data->FormatHandle(renderpass).c_str(), variable_name, string_VkImageLayout(layout), |
| 410 | report_data->FormatHandle(framebuffer).c_str(), report_data->FormatHandle(image_view).c_str()); |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 411 | } |
| 412 | |
Mark Lobodzinski | 60e7903 | 2019-03-07 10:22:31 -0700 | [diff] [blame] | 413 | if (GetDeviceExtensions()->vk_khr_maintenance2) { |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 414 | if ((layout == VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL || |
| 415 | layout == VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL || |
| 416 | layout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL || |
| 417 | layout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL) && |
| 418 | !(image_usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)) { |
| 419 | vuid = use_rp2 ? "VUID-vkCmdBeginRenderPass2KHR-initialLayout-03096" : "VUID-vkCmdBeginRenderPass-initialLayout-01758"; |
Locke | e9aeebf | 2019-03-03 23:50:08 -0700 | [diff] [blame] | 420 | skip |= log_msg( |
| 421 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, HandleToUint64(image), vuid, |
| 422 | "Layout/usage mismatch for attachment %u in render pass %s" |
| 423 | " - the %s is %s but the image attached to framebuffer %s via image view %s" |
| 424 | " was not created with VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT", |
Locke | 7b4f9ac | 2019-04-01 10:58:17 -0600 | [diff] [blame] | 425 | attachment_index, report_data->FormatHandle(renderpass).c_str(), variable_name, string_VkImageLayout(layout), |
| 426 | report_data->FormatHandle(framebuffer).c_str(), report_data->FormatHandle(image_view).c_str()); |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 427 | } |
| 428 | } else { |
| 429 | // The create render pass 2 extension requires maintenance 2 (the previous branch), so no vuid switch needed here. |
| 430 | if ((layout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL || |
| 431 | layout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL) && |
| 432 | !(image_usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)) { |
| 433 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 434 | HandleToUint64(image), "VUID-vkCmdBeginRenderPass-initialLayout-00896", |
Locke | e9aeebf | 2019-03-03 23:50:08 -0700 | [diff] [blame] | 435 | "Layout/usage mismatch for attachment %u in render pass %s" |
| 436 | " - the %s is %s but the image attached to framebuffer %s via image view %s" |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 437 | " was not created with VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT", |
Locke | 7b4f9ac | 2019-04-01 10:58:17 -0600 | [diff] [blame] | 438 | attachment_index, report_data->FormatHandle(renderpass).c_str(), variable_name, |
| 439 | string_VkImageLayout(layout), report_data->FormatHandle(framebuffer).c_str(), |
Locke | e9aeebf | 2019-03-03 23:50:08 -0700 | [diff] [blame] | 440 | report_data->FormatHandle(image_view).c_str()); |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 441 | } |
| 442 | } |
| 443 | return skip; |
| 444 | } |
| 445 | |
Mark Lobodzinski | ef4ab2e | 2019-03-07 13:23:36 -0700 | [diff] [blame] | 446 | bool CoreChecks::VerifyFramebufferAndRenderPassLayouts(RenderPassCreateVersion rp_version, GLOBAL_CB_NODE *pCB, |
| 447 | const VkRenderPassBeginInfo *pRenderPassBegin, |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 448 | const FRAMEBUFFER_STATE *framebuffer_state) { |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 449 | bool skip = false; |
Mark Lobodzinski | 2e49588 | 2019-03-06 16:11:56 -0700 | [diff] [blame] | 450 | auto const pRenderPassInfo = GetRenderPassState(pRenderPassBegin->renderPass)->createInfo.ptr(); |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 451 | auto const &framebufferInfo = framebuffer_state->createInfo; |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 452 | |
Mark Lobodzinski | 2e49588 | 2019-03-06 16:11:56 -0700 | [diff] [blame] | 453 | auto render_pass = GetRenderPassState(pRenderPassBegin->renderPass)->renderPass; |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 454 | auto framebuffer = framebuffer_state->framebuffer; |
| 455 | |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 456 | if (pRenderPassInfo->attachmentCount != framebufferInfo.attachmentCount) { |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 457 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Dave Houlton | 5165390 | 2018-06-22 17:32:13 -0600 | [diff] [blame] | 458 | HandleToUint64(pCB->commandBuffer), kVUID_Core_DrawState_InvalidRenderpass, |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 459 | "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] | 460 | } |
John Zulauf | f660ad6 | 2019-03-23 07:16:05 -0600 | [diff] [blame] | 461 | const auto *const_pCB = static_cast<const GLOBAL_CB_NODE *>(pCB); |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 462 | for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) { |
| 463 | const VkImageView &image_view = framebufferInfo.pAttachments[i]; |
Mark Lobodzinski | a3a230b | 2019-03-06 15:35:13 -0700 | [diff] [blame] | 464 | auto view_state = GetImageViewState(image_view); |
John Zulauf | 8e30829 | 2018-09-21 11:34:37 -0600 | [diff] [blame] | 465 | |
| 466 | if (!view_state) { |
Locke | e9aeebf | 2019-03-03 23:50:08 -0700 | [diff] [blame] | 467 | skip |= |
| 468 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_RENDER_PASS_EXT, |
| 469 | HandleToUint64(pRenderPassBegin->renderPass), "VUID-VkRenderPassBeginInfo-framebuffer-parameter", |
| 470 | "vkCmdBeginRenderPass(): framebuffer %s pAttachments[%" PRIu32 "] = %s is not a valid VkImageView handle", |
| 471 | report_data->FormatHandle(framebuffer_state->framebuffer).c_str(), i, |
| 472 | report_data->FormatHandle(image_view).c_str()); |
John Zulauf | 8e30829 | 2018-09-21 11:34:37 -0600 | [diff] [blame] | 473 | continue; |
| 474 | } |
| 475 | |
John Zulauf | f660ad6 | 2019-03-23 07:16:05 -0600 | [diff] [blame] | 476 | const VkImage image = view_state->create_info.image; |
| 477 | const IMAGE_STATE *image_state = GetImageState(image); |
| 478 | |
| 479 | if (!image_state) { |
| 480 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_RENDER_PASS_EXT, |
| 481 | HandleToUint64(pRenderPassBegin->renderPass), "VUID-VkRenderPassBeginInfo-framebuffer-parameter", |
| 482 | "vkCmdBeginRenderPass(): framebuffer %s pAttachments[%" PRIu32 |
| 483 | "] = VkImageView %s references non-extant VkImage %s.", |
| 484 | report_data->FormatHandle(framebuffer_state->framebuffer).c_str(), i, |
| 485 | report_data->FormatHandle(image_view).c_str(), report_data->FormatHandle(image).c_str()); |
| 486 | continue; |
| 487 | } |
| 488 | auto attachment_initial_layout = pRenderPassInfo->pAttachments[i].initialLayout; |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 489 | auto final_layout = pRenderPassInfo->pAttachments[i].finalLayout; |
| 490 | |
John Zulauf | f660ad6 | 2019-03-23 07:16:05 -0600 | [diff] [blame] | 491 | // Cast pCB to const because we don't want to create entries that don't exist here (in case the key changes to something |
| 492 | // in common with the non-const version.) |
| 493 | const ImageSubresourceLayoutMap *subresource_map = |
| 494 | (attachment_initial_layout != VK_IMAGE_LAYOUT_UNDEFINED) ? GetImageSubresourceLayoutMap(const_pCB, image) : nullptr; |
| 495 | |
| 496 | if (subresource_map) { // If no layout information for image yet, will be checked at QueueSubmit time |
| 497 | bool subres_skip = false; |
| 498 | auto subresource_cb = [this, i, attachment_initial_layout, &subres_skip]( |
| 499 | const VkImageSubresource &subres, VkImageLayout layout, VkImageLayout initial_layout) { |
| 500 | LayoutUseCheckAndMessage layout_check(attachment_initial_layout, layout, initial_layout); |
| 501 | if (layout_check.CheckFailed()) { |
| 502 | subres_skip |= |
| 503 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 504 | kVUID_Core_DrawState_InvalidRenderpass, |
| 505 | "You cannot start a render pass using attachment %u where the render pass initial layout is %s " |
| 506 | "and the %s layout of the attachment is %s. The layouts must match, or the render " |
| 507 | "pass initial layout for the attachment must be VK_IMAGE_LAYOUT_UNDEFINED", |
| 508 | i, string_VkImageLayout(attachment_initial_layout), layout_check.message, |
| 509 | string_VkImageLayout(layout_check.layout)); |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 510 | } |
John Zulauf | f660ad6 | 2019-03-23 07:16:05 -0600 | [diff] [blame] | 511 | return !subres_skip; // quit checking subresources once we fail once |
| 512 | }; |
| 513 | |
| 514 | subresource_map->ForRange(view_state->normalized_subresource_range, subresource_cb); |
| 515 | skip |= subres_skip; |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 516 | } |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 517 | |
John Zulauf | f660ad6 | 2019-03-23 07:16:05 -0600 | [diff] [blame] | 518 | ValidateRenderPassLayoutAgainstFramebufferImageUsage(rp_version, attachment_initial_layout, image, image_view, framebuffer, |
Mark Lobodzinski | ef4ab2e | 2019-03-07 13:23:36 -0700 | [diff] [blame] | 519 | render_pass, i, "initial layout"); |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 520 | |
Mark Lobodzinski | ef4ab2e | 2019-03-07 13:23:36 -0700 | [diff] [blame] | 521 | ValidateRenderPassLayoutAgainstFramebufferImageUsage(rp_version, final_layout, image, image_view, framebuffer, render_pass, |
| 522 | i, "final layout"); |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | for (uint32_t j = 0; j < pRenderPassInfo->subpassCount; ++j) { |
| 526 | auto &subpass = pRenderPassInfo->pSubpasses[j]; |
| 527 | for (uint32_t k = 0; k < pRenderPassInfo->pSubpasses[j].inputAttachmentCount; ++k) { |
| 528 | auto &attachment_ref = subpass.pInputAttachments[k]; |
| 529 | if (attachment_ref.attachment != VK_ATTACHMENT_UNUSED) { |
| 530 | auto image_view = framebufferInfo.pAttachments[attachment_ref.attachment]; |
Mark Lobodzinski | a3a230b | 2019-03-06 15:35:13 -0700 | [diff] [blame] | 531 | auto view_state = GetImageViewState(image_view); |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 532 | |
| 533 | if (view_state) { |
| 534 | auto image = view_state->create_info.image; |
Mark Lobodzinski | ef4ab2e | 2019-03-07 13:23:36 -0700 | [diff] [blame] | 535 | ValidateRenderPassLayoutAgainstFramebufferImageUsage(rp_version, attachment_ref.layout, image, image_view, |
| 536 | framebuffer, render_pass, attachment_ref.attachment, |
| 537 | "input attachment layout"); |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 538 | } |
| 539 | } |
| 540 | } |
| 541 | |
| 542 | for (uint32_t k = 0; k < pRenderPassInfo->pSubpasses[j].colorAttachmentCount; ++k) { |
| 543 | auto &attachment_ref = subpass.pColorAttachments[k]; |
| 544 | if (attachment_ref.attachment != VK_ATTACHMENT_UNUSED) { |
| 545 | auto image_view = framebufferInfo.pAttachments[attachment_ref.attachment]; |
Mark Lobodzinski | a3a230b | 2019-03-06 15:35:13 -0700 | [diff] [blame] | 546 | auto view_state = GetImageViewState(image_view); |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 547 | |
| 548 | if (view_state) { |
| 549 | auto image = view_state->create_info.image; |
Mark Lobodzinski | ef4ab2e | 2019-03-07 13:23:36 -0700 | [diff] [blame] | 550 | ValidateRenderPassLayoutAgainstFramebufferImageUsage(rp_version, attachment_ref.layout, image, image_view, |
| 551 | framebuffer, render_pass, attachment_ref.attachment, |
| 552 | "color attachment layout"); |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 553 | if (subpass.pResolveAttachments) { |
Mark Lobodzinski | ef4ab2e | 2019-03-07 13:23:36 -0700 | [diff] [blame] | 554 | ValidateRenderPassLayoutAgainstFramebufferImageUsage(rp_version, attachment_ref.layout, image, image_view, |
| 555 | framebuffer, render_pass, attachment_ref.attachment, |
| 556 | "resolve attachment layout"); |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 557 | } |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | if (pRenderPassInfo->pSubpasses[j].pDepthStencilAttachment) { |
| 563 | auto &attachment_ref = *subpass.pDepthStencilAttachment; |
| 564 | if (attachment_ref.attachment != VK_ATTACHMENT_UNUSED) { |
| 565 | auto image_view = framebufferInfo.pAttachments[attachment_ref.attachment]; |
Mark Lobodzinski | a3a230b | 2019-03-06 15:35:13 -0700 | [diff] [blame] | 566 | auto view_state = GetImageViewState(image_view); |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 567 | |
| 568 | if (view_state) { |
| 569 | auto image = view_state->create_info.image; |
Mark Lobodzinski | ef4ab2e | 2019-03-07 13:23:36 -0700 | [diff] [blame] | 570 | ValidateRenderPassLayoutAgainstFramebufferImageUsage(rp_version, attachment_ref.layout, image, image_view, |
| 571 | framebuffer, render_pass, attachment_ref.attachment, |
| 572 | "input attachment layout"); |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 573 | } |
| 574 | } |
| 575 | } |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 576 | } |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 577 | return skip; |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 578 | } |
| 579 | |
Mark Lobodzinski | 8564e44 | 2019-03-07 12:49:41 -0700 | [diff] [blame] | 580 | void CoreChecks::TransitionAttachmentRefLayout(GLOBAL_CB_NODE *pCB, FRAMEBUFFER_STATE *pFramebuffer, |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 581 | const safe_VkAttachmentReference2KHR &ref) { |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 582 | if (ref.attachment != VK_ATTACHMENT_UNUSED) { |
Mark Lobodzinski | a3a230b | 2019-03-06 15:35:13 -0700 | [diff] [blame] | 583 | auto image_view = GetAttachmentImageViewState(pFramebuffer, ref.attachment); |
John Zulauf | 8e30829 | 2018-09-21 11:34:37 -0600 | [diff] [blame] | 584 | if (image_view) { |
John Zulauf | f660ad6 | 2019-03-23 07:16:05 -0600 | [diff] [blame] | 585 | SetImageViewLayout(pCB, *image_view, ref.layout); |
John Zulauf | 8e30829 | 2018-09-21 11:34:37 -0600 | [diff] [blame] | 586 | } |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 587 | } |
| 588 | } |
| 589 | |
Mark Lobodzinski | 8564e44 | 2019-03-07 12:49:41 -0700 | [diff] [blame] | 590 | void CoreChecks::TransitionSubpassLayouts(GLOBAL_CB_NODE *pCB, const RENDER_PASS_STATE *render_pass_state, const int subpass_index, |
| 591 | FRAMEBUFFER_STATE *framebuffer_state) { |
Tobin Ehlis | 0d4274b | 2017-02-17 15:17:04 -0700 | [diff] [blame] | 592 | assert(render_pass_state); |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 593 | |
| 594 | if (framebuffer_state) { |
Tobin Ehlis | 0d4274b | 2017-02-17 15:17:04 -0700 | [diff] [blame] | 595 | auto const &subpass = render_pass_state->createInfo.pSubpasses[subpass_index]; |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 596 | for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) { |
Mark Lobodzinski | 8564e44 | 2019-03-07 12:49:41 -0700 | [diff] [blame] | 597 | TransitionAttachmentRefLayout(pCB, framebuffer_state, subpass.pInputAttachments[j]); |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 598 | } |
| 599 | for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) { |
Mark Lobodzinski | 8564e44 | 2019-03-07 12:49:41 -0700 | [diff] [blame] | 600 | TransitionAttachmentRefLayout(pCB, framebuffer_state, subpass.pColorAttachments[j]); |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 601 | } |
| 602 | if (subpass.pDepthStencilAttachment) { |
Mark Lobodzinski | 8564e44 | 2019-03-07 12:49:41 -0700 | [diff] [blame] | 603 | TransitionAttachmentRefLayout(pCB, framebuffer_state, *subpass.pDepthStencilAttachment); |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 604 | } |
| 605 | } |
| 606 | } |
| 607 | |
Tobin Ehlis | 0d4274b | 2017-02-17 15:17:04 -0700 | [diff] [blame] | 608 | // Transition the layout state for renderpass attachments based on the BeginRenderPass() call. This includes: |
| 609 | // 1. Transition into initialLayout state |
| 610 | // 2. Transition from initialLayout to layout used in subpass 0 |
Mark Lobodzinski | 8564e44 | 2019-03-07 12:49:41 -0700 | [diff] [blame] | 611 | void CoreChecks::TransitionBeginRenderPassLayouts(GLOBAL_CB_NODE *cb_state, const RENDER_PASS_STATE *render_pass_state, |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 612 | FRAMEBUFFER_STATE *framebuffer_state) { |
Tobin Ehlis | 0d4274b | 2017-02-17 15:17:04 -0700 | [diff] [blame] | 613 | // First transition into initialLayout |
| 614 | auto const rpci = render_pass_state->createInfo.ptr(); |
| 615 | for (uint32_t i = 0; i < rpci->attachmentCount; ++i) { |
Mark Lobodzinski | a3a230b | 2019-03-06 15:35:13 -0700 | [diff] [blame] | 616 | auto view_state = GetAttachmentImageViewState(framebuffer_state, i); |
John Zulauf | 8e30829 | 2018-09-21 11:34:37 -0600 | [diff] [blame] | 617 | if (view_state) { |
John Zulauf | f660ad6 | 2019-03-23 07:16:05 -0600 | [diff] [blame] | 618 | SetImageViewLayout(cb_state, *view_state, rpci->pAttachments[i].initialLayout); |
John Zulauf | 8e30829 | 2018-09-21 11:34:37 -0600 | [diff] [blame] | 619 | } |
Tobin Ehlis | 0d4274b | 2017-02-17 15:17:04 -0700 | [diff] [blame] | 620 | } |
| 621 | // Now transition for first subpass (index 0) |
Mark Lobodzinski | 8564e44 | 2019-03-07 12:49:41 -0700 | [diff] [blame] | 622 | TransitionSubpassLayouts(cb_state, render_pass_state, 0, framebuffer_state); |
Tobin Ehlis | 0d4274b | 2017-02-17 15:17:04 -0700 | [diff] [blame] | 623 | } |
| 624 | |
Dave Houlton | 10b3948 | 2017-03-16 13:18:15 -0600 | [diff] [blame] | 625 | bool VerifyAspectsPresent(VkImageAspectFlags aspect_mask, VkFormat format) { |
Dave Houlton | 4eaaf3a | 2017-03-14 11:31:20 -0600 | [diff] [blame] | 626 | if ((aspect_mask & VK_IMAGE_ASPECT_COLOR_BIT) != 0) { |
Dave Houlton | e2fca55 | 2018-04-05 16:20:33 -0600 | [diff] [blame] | 627 | if (!(FormatIsColor(format) || FormatIsMultiplane(format))) return false; |
Dave Houlton | 4eaaf3a | 2017-03-14 11:31:20 -0600 | [diff] [blame] | 628 | } |
| 629 | if ((aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) != 0) { |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 630 | if (!FormatHasDepth(format)) return false; |
Dave Houlton | 4eaaf3a | 2017-03-14 11:31:20 -0600 | [diff] [blame] | 631 | } |
| 632 | if ((aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) != 0) { |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 633 | if (!FormatHasStencil(format)) return false; |
Dave Houlton | 4eaaf3a | 2017-03-14 11:31:20 -0600 | [diff] [blame] | 634 | } |
Dave Houlton | b3f4b28 | 2018-02-22 16:25:16 -0700 | [diff] [blame] | 635 | if (0 != |
| 636 | (aspect_mask & (VK_IMAGE_ASPECT_PLANE_0_BIT_KHR | VK_IMAGE_ASPECT_PLANE_1_BIT_KHR | VK_IMAGE_ASPECT_PLANE_2_BIT_KHR))) { |
| 637 | if (FormatPlaneCount(format) == 1) return false; |
| 638 | } |
Dave Houlton | 4eaaf3a | 2017-03-14 11:31:20 -0600 | [diff] [blame] | 639 | return true; |
| 640 | } |
| 641 | |
Mike Weiblen | 62d08a3 | 2017-03-07 22:18:27 -0700 | [diff] [blame] | 642 | // Verify an ImageMemoryBarrier's old/new ImageLayouts are compatible with the Image's ImageUsageFlags. |
Mark Lobodzinski | ef4ab2e | 2019-03-07 13:23:36 -0700 | [diff] [blame] | 643 | bool CoreChecks::ValidateBarrierLayoutToImageUsage(const VkImageMemoryBarrier *img_barrier, bool new_not_old, |
| 644 | VkImageUsageFlags usage_flags, const char *func_name) { |
Mike Weiblen | 62d08a3 | 2017-03-07 22:18:27 -0700 | [diff] [blame] | 645 | bool skip = false; |
| 646 | const VkImageLayout layout = (new_not_old) ? img_barrier->newLayout : img_barrier->oldLayout; |
Jeff Bolz | 6d3beaa | 2019-02-09 21:00:05 -0600 | [diff] [blame] | 647 | const char *msg_code = kVUIDUndefined; // sentinel value meaning "no error" |
Mike Weiblen | 62d08a3 | 2017-03-07 22:18:27 -0700 | [diff] [blame] | 648 | |
| 649 | switch (layout) { |
| 650 | case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: |
| 651 | if ((usage_flags & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) == 0) { |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 652 | msg_code = "VUID-VkImageMemoryBarrier-oldLayout-01208"; |
Mike Weiblen | 62d08a3 | 2017-03-07 22:18:27 -0700 | [diff] [blame] | 653 | } |
| 654 | break; |
| 655 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: |
| 656 | if ((usage_flags & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) == 0) { |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 657 | msg_code = "VUID-VkImageMemoryBarrier-oldLayout-01209"; |
Mike Weiblen | 62d08a3 | 2017-03-07 22:18:27 -0700 | [diff] [blame] | 658 | } |
| 659 | break; |
| 660 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: |
| 661 | if ((usage_flags & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) == 0) { |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 662 | msg_code = "VUID-VkImageMemoryBarrier-oldLayout-01210"; |
Mike Weiblen | 62d08a3 | 2017-03-07 22:18:27 -0700 | [diff] [blame] | 663 | } |
| 664 | break; |
| 665 | case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: |
| 666 | if ((usage_flags & (VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT)) == 0) { |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 667 | msg_code = "VUID-VkImageMemoryBarrier-oldLayout-01211"; |
Mike Weiblen | 62d08a3 | 2017-03-07 22:18:27 -0700 | [diff] [blame] | 668 | } |
| 669 | break; |
| 670 | case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL: |
| 671 | if ((usage_flags & VK_IMAGE_USAGE_TRANSFER_SRC_BIT) == 0) { |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 672 | msg_code = "VUID-VkImageMemoryBarrier-oldLayout-01212"; |
Mike Weiblen | 62d08a3 | 2017-03-07 22:18:27 -0700 | [diff] [blame] | 673 | } |
| 674 | break; |
| 675 | case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL: |
| 676 | if ((usage_flags & VK_IMAGE_USAGE_TRANSFER_DST_BIT) == 0) { |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 677 | msg_code = "VUID-VkImageMemoryBarrier-oldLayout-01213"; |
Mike Weiblen | 62d08a3 | 2017-03-07 22:18:27 -0700 | [diff] [blame] | 678 | } |
| 679 | break; |
Dave Houlton | 142c4cb | 2018-10-17 15:04:41 -0600 | [diff] [blame] | 680 | case VK_IMAGE_LAYOUT_SHADING_RATE_OPTIMAL_NV: |
Jeff Bolz | 9af91c5 | 2018-09-01 21:53:57 -0500 | [diff] [blame] | 681 | if ((usage_flags & VK_IMAGE_USAGE_SHADING_RATE_IMAGE_BIT_NV) == 0) { |
| 682 | msg_code = "VUID-VkImageMemoryBarrier-oldLayout-02088"; |
| 683 | } |
| 684 | break; |
Mike Weiblen | 62d08a3 | 2017-03-07 22:18:27 -0700 | [diff] [blame] | 685 | default: |
| 686 | // Other VkImageLayout values do not have VUs defined in this context. |
| 687 | break; |
| 688 | } |
| 689 | |
Dave Houlton | 8e9f654 | 2018-05-18 12:18:22 -0600 | [diff] [blame] | 690 | if (msg_code != kVUIDUndefined) { |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 691 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 692 | HandleToUint64(img_barrier->image), msg_code, |
John Zulauf | f660ad6 | 2019-03-23 07:16:05 -0600 | [diff] [blame] | 693 | "%s: Image barrier 0x%p %s Layout=%s is not compatible with image %s usage flags 0x%" PRIx32 ".", func_name, |
Locke | e9aeebf | 2019-03-03 23:50:08 -0700 | [diff] [blame] | 694 | static_cast<const void *>(img_barrier), ((new_not_old) ? "new" : "old"), string_VkImageLayout(layout), |
| 695 | report_data->FormatHandle(img_barrier->image).c_str(), usage_flags); |
Mike Weiblen | 62d08a3 | 2017-03-07 22:18:27 -0700 | [diff] [blame] | 696 | } |
| 697 | return skip; |
| 698 | } |
| 699 | |
John Zulauf | 463c51e | 2018-05-31 13:29:20 -0600 | [diff] [blame] | 700 | // Scoreboard for checking for duplicate and inconsistent barriers to images |
| 701 | struct ImageBarrierScoreboardEntry { |
| 702 | uint32_t index; |
| 703 | // This is designed for temporary storage within the scope of the API call. If retained storage of the barriers is |
| 704 | // required, copies should be made and smart or unique pointers used in some other stucture (or this one refactored) |
| 705 | const VkImageMemoryBarrier *barrier; |
| 706 | }; |
| 707 | using ImageBarrierScoreboardSubresMap = std::unordered_map<VkImageSubresourceRange, ImageBarrierScoreboardEntry>; |
| 708 | using ImageBarrierScoreboardImageMap = std::unordered_map<VkImage, ImageBarrierScoreboardSubresMap>; |
| 709 | |
Mike Weiblen | 62d08a3 | 2017-03-07 22:18:27 -0700 | [diff] [blame] | 710 | // Verify image barriers are compatible with the images they reference. |
Mark Lobodzinski | ef4ab2e | 2019-03-07 13:23:36 -0700 | [diff] [blame] | 711 | bool CoreChecks::ValidateBarriersToImages(GLOBAL_CB_NODE const *cb_state, uint32_t imageMemoryBarrierCount, |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 712 | const VkImageMemoryBarrier *pImageMemoryBarriers, const char *func_name) { |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 713 | bool skip = false; |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 714 | |
John Zulauf | 463c51e | 2018-05-31 13:29:20 -0600 | [diff] [blame] | 715 | // Scoreboard for duplicate layout transition barriers within the list |
| 716 | // Pointers retained in the scoreboard only have the lifetime of *this* call (i.e. within the scope of the API call) |
| 717 | ImageBarrierScoreboardImageMap layout_transitions; |
| 718 | |
Mike Weiblen | 62d08a3 | 2017-03-07 22:18:27 -0700 | [diff] [blame] | 719 | for (uint32_t i = 0; i < imageMemoryBarrierCount; ++i) { |
| 720 | auto img_barrier = &pImageMemoryBarriers[i]; |
| 721 | if (!img_barrier) continue; |
| 722 | |
John Zulauf | 463c51e | 2018-05-31 13:29:20 -0600 | [diff] [blame] | 723 | // Update the scoreboard of layout transitions and check for barriers affecting the same image and subresource |
| 724 | // TODO: a higher precision could be gained by adapting the command_buffer image_layout_map logic looking for conflicts |
| 725 | // at a per sub-resource level |
| 726 | if (img_barrier->oldLayout != img_barrier->newLayout) { |
| 727 | ImageBarrierScoreboardEntry new_entry{i, img_barrier}; |
| 728 | auto image_it = layout_transitions.find(img_barrier->image); |
| 729 | if (image_it != layout_transitions.end()) { |
| 730 | auto &subres_map = image_it->second; |
| 731 | auto subres_it = subres_map.find(img_barrier->subresourceRange); |
| 732 | if (subres_it != subres_map.end()) { |
| 733 | auto &entry = subres_it->second; |
| 734 | if ((entry.barrier->newLayout != img_barrier->oldLayout) && |
| 735 | (img_barrier->oldLayout != VK_IMAGE_LAYOUT_UNDEFINED)) { |
| 736 | const VkImageSubresourceRange &range = img_barrier->subresourceRange; |
| 737 | skip = log_msg( |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 738 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 739 | HandleToUint64(cb_state->commandBuffer), "VUID-VkImageMemoryBarrier-oldLayout-01197", |
Locke | e9aeebf | 2019-03-03 23:50:08 -0700 | [diff] [blame] | 740 | "%s: pImageMemoryBarrier[%u] conflicts with earlier entry pImageMemoryBarrier[%u]. Image %s" |
John Zulauf | 463c51e | 2018-05-31 13:29:20 -0600 | [diff] [blame] | 741 | " subresourceRange: aspectMask=%u baseMipLevel=%u levelCount=%u, baseArrayLayer=%u, layerCount=%u; " |
| 742 | "conflicting barrier transitions image layout from %s when earlier barrier transitioned to layout %s.", |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 743 | func_name, i, entry.index, report_data->FormatHandle(img_barrier->image).c_str(), range.aspectMask, |
Locke | e9aeebf | 2019-03-03 23:50:08 -0700 | [diff] [blame] | 744 | range.baseMipLevel, range.levelCount, range.baseArrayLayer, range.layerCount, |
| 745 | string_VkImageLayout(img_barrier->oldLayout), string_VkImageLayout(entry.barrier->newLayout)); |
John Zulauf | 463c51e | 2018-05-31 13:29:20 -0600 | [diff] [blame] | 746 | } |
| 747 | entry = new_entry; |
| 748 | } else { |
| 749 | subres_map[img_barrier->subresourceRange] = new_entry; |
| 750 | } |
| 751 | } else { |
| 752 | layout_transitions[img_barrier->image][img_barrier->subresourceRange] = new_entry; |
| 753 | } |
| 754 | } |
| 755 | |
Mark Lobodzinski | 8ddc23f | 2019-03-06 11:48:49 -0700 | [diff] [blame] | 756 | auto image_state = GetImageState(img_barrier->image); |
Tobin Ehlis | bb03e5f | 2017-05-11 08:52:51 -0600 | [diff] [blame] | 757 | if (image_state) { |
| 758 | VkImageUsageFlags usage_flags = image_state->createInfo.usage; |
Mark Lobodzinski | ef4ab2e | 2019-03-07 13:23:36 -0700 | [diff] [blame] | 759 | skip |= ValidateBarrierLayoutToImageUsage(img_barrier, false, usage_flags, func_name); |
| 760 | skip |= ValidateBarrierLayoutToImageUsage(img_barrier, true, usage_flags, func_name); |
Tobin Ehlis | bb03e5f | 2017-05-11 08:52:51 -0600 | [diff] [blame] | 761 | |
| 762 | // Make sure layout is able to be transitioned, currently only presented shared presentable images are locked |
| 763 | if (image_state->layout_locked) { |
| 764 | // TODO: Add unique id for error when available |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 765 | skip |= log_msg( |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 766 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 767 | HandleToUint64(img_barrier->image), 0, |
Locke | e9aeebf | 2019-03-03 23:50:08 -0700 | [diff] [blame] | 768 | "Attempting to transition shared presentable image %s" |
Tobin Ehlis | bb03e5f | 2017-05-11 08:52:51 -0600 | [diff] [blame] | 769 | " from layout %s to layout %s, but image has already been presented and cannot have its layout transitioned.", |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 770 | report_data->FormatHandle(img_barrier->image).c_str(), string_VkImageLayout(img_barrier->oldLayout), |
| 771 | string_VkImageLayout(img_barrier->newLayout)); |
Tobin Ehlis | bb03e5f | 2017-05-11 08:52:51 -0600 | [diff] [blame] | 772 | } |
Tobin Ehlis | bb03e5f | 2017-05-11 08:52:51 -0600 | [diff] [blame] | 773 | |
John Zulauf | f660ad6 | 2019-03-23 07:16:05 -0600 | [diff] [blame] | 774 | VkImageCreateInfo *image_create_info = &image_state->createInfo; |
| 775 | // For a Depth/Stencil image both aspects MUST be set |
| 776 | if (FormatIsDepthAndStencil(image_create_info->format)) { |
| 777 | auto const aspect_mask = img_barrier->subresourceRange.aspectMask; |
| 778 | auto const ds_mask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
| 779 | if ((aspect_mask & ds_mask) != (ds_mask)) { |
| 780 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 781 | HandleToUint64(img_barrier->image), "VUID-VkImageMemoryBarrier-image-01207", |
| 782 | "%s: Image barrier 0x%p references image %s of format %s that must have the depth and stencil " |
| 783 | "aspects set, but its aspectMask is 0x%" PRIx32 ".", |
| 784 | func_name, static_cast<const void *>(img_barrier), |
| 785 | report_data->FormatHandle(img_barrier->image).c_str(), |
| 786 | string_VkFormat(image_create_info->format), aspect_mask); |
Dave Houlton | b3f4b28 | 2018-02-22 16:25:16 -0700 | [diff] [blame] | 787 | } |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 788 | } |
John Zulauf | f660ad6 | 2019-03-23 07:16:05 -0600 | [diff] [blame] | 789 | |
| 790 | const auto *subresource_map = GetImageSubresourceLayoutMap(cb_state, img_barrier->image); |
| 791 | if (img_barrier->oldLayout == VK_IMAGE_LAYOUT_UNDEFINED) { |
| 792 | // TODO: Set memory invalid which is in mem_tracker currently |
| 793 | // Not sure if this needs to be in the ForRange traversal, pulling it out as it is currently invariant with |
| 794 | // subresource. |
| 795 | } else if (subresource_map) { |
| 796 | bool subres_skip = false; |
| 797 | VkImageSubresourceRange normalized_isr = NormalizeSubresourceRange(*image_state, img_barrier->subresourceRange); |
| 798 | auto subres_callback = [this, img_barrier, cb_state, &subres_skip]( |
| 799 | const VkImageSubresource &subres, VkImageLayout layout, VkImageLayout initial_layout) { |
| 800 | LayoutUseCheckAndMessage layout_check(img_barrier->oldLayout, layout, initial_layout); |
| 801 | if (layout_check.CheckFailed()) { |
| 802 | subres_skip = |
| 803 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 804 | HandleToUint64(cb_state->commandBuffer), "VUID-VkImageMemoryBarrier-oldLayout-01197", |
| 805 | "For image %s you cannot transition the layout of aspect=%d level=%d layer=%d from %s when the " |
| 806 | "%s layout is %s.", |
| 807 | report_data->FormatHandle(img_barrier->image).c_str(), subres.aspectMask, subres.mipLevel, |
| 808 | subres.arrayLayer, string_VkImageLayout(img_barrier->oldLayout), layout_check.message, |
| 809 | string_VkImageLayout(layout_check.layout)); |
| 810 | } |
| 811 | return !subres_skip; |
| 812 | }; |
| 813 | subresource_map->ForRange(normalized_isr, subres_callback); |
| 814 | skip |= subres_skip; |
| 815 | } |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 816 | } |
| 817 | } |
| 818 | return skip; |
| 819 | } |
| 820 | |
Mark Lobodzinski | 8deebf1 | 2019-03-07 11:38:38 -0700 | [diff] [blame] | 821 | bool CoreChecks::IsReleaseOp(GLOBAL_CB_NODE *cb_state, VkImageMemoryBarrier const *barrier) { |
John Zulauf | 1b33d5a | 2018-03-24 19:52:19 -0600 | [diff] [blame] | 822 | if (!IsTransferOp(barrier)) return false; |
Chris Forbes | 4de4b13 | 2017-08-21 11:27:08 -0700 | [diff] [blame] | 823 | |
Mark Lobodzinski | 8b0a7b8 | 2019-03-06 16:17:45 -0700 | [diff] [blame] | 824 | auto pool = GetCommandPoolNode(cb_state->createInfo.commandPool); |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 825 | return pool && TempIsReleaseOp<VkImageMemoryBarrier, true>(pool, barrier); |
Chris Forbes | 4de4b13 | 2017-08-21 11:27:08 -0700 | [diff] [blame] | 826 | } |
| 827 | |
John Zulauf | 6b4aae8 | 2018-05-09 13:03:36 -0600 | [diff] [blame] | 828 | template <typename Barrier> |
Mark Lobodzinski | daea591 | 2019-03-07 14:47:09 -0700 | [diff] [blame] | 829 | bool CoreChecks::ValidateQFOTransferBarrierUniqueness(const char *func_name, GLOBAL_CB_NODE *cb_state, uint32_t barrier_count, |
| 830 | const Barrier *barriers) { |
John Zulauf | 6b4aae8 | 2018-05-09 13:03:36 -0600 | [diff] [blame] | 831 | using BarrierRecord = QFOTransferBarrier<Barrier>; |
| 832 | bool skip = false; |
Mark Lobodzinski | 8b0a7b8 | 2019-03-06 16:17:45 -0700 | [diff] [blame] | 833 | auto pool = GetCommandPoolNode(cb_state->createInfo.commandPool); |
John Zulauf | 6b4aae8 | 2018-05-09 13:03:36 -0600 | [diff] [blame] | 834 | auto &barrier_sets = GetQFOBarrierSets(cb_state, typename BarrierRecord::Tag()); |
| 835 | const char *barrier_name = BarrierRecord::BarrierName(); |
| 836 | const char *handle_name = BarrierRecord::HandleName(); |
| 837 | const char *transfer_type = nullptr; |
| 838 | for (uint32_t b = 0; b < barrier_count; b++) { |
| 839 | if (!IsTransferOp(&barriers[b])) continue; |
| 840 | const BarrierRecord *barrier_record = nullptr; |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 841 | if (TempIsReleaseOp<Barrier, true /* Assume IsTransfer */>(pool, &barriers[b]) && |
| 842 | !IsSpecial(barriers[b].dstQueueFamilyIndex)) { |
John Zulauf | 6b4aae8 | 2018-05-09 13:03:36 -0600 | [diff] [blame] | 843 | const auto found = barrier_sets.release.find(barriers[b]); |
| 844 | if (found != barrier_sets.release.cend()) { |
| 845 | barrier_record = &(*found); |
| 846 | transfer_type = "releasing"; |
| 847 | } |
Shannon McPherson | ed2f009 | 2018-08-30 17:18:04 -0600 | [diff] [blame] | 848 | } else if (IsAcquireOp<Barrier, true /*Assume IsTransfer */>(pool, &barriers[b]) && |
| 849 | !IsSpecial(barriers[b].srcQueueFamilyIndex)) { |
John Zulauf | 6b4aae8 | 2018-05-09 13:03:36 -0600 | [diff] [blame] | 850 | const auto found = barrier_sets.acquire.find(barriers[b]); |
| 851 | if (found != barrier_sets.acquire.cend()) { |
| 852 | barrier_record = &(*found); |
| 853 | transfer_type = "acquiring"; |
| 854 | } |
| 855 | } |
| 856 | if (barrier_record != nullptr) { |
Locke | e9aeebf | 2019-03-03 23:50:08 -0700 | [diff] [blame] | 857 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 858 | HandleToUint64(cb_state->commandBuffer), BarrierRecord::ErrMsgDuplicateQFOInCB(), |
| 859 | "%s: %s at index %" PRIu32 " %s queue ownership of %s (%s), from srcQueueFamilyIndex %" PRIu32 |
| 860 | " to dstQueueFamilyIndex %" PRIu32 " duplicates existing barrier recorded in this command buffer.", |
| 861 | func_name, barrier_name, b, transfer_type, handle_name, |
| 862 | report_data->FormatHandle(barrier_record->handle).c_str(), barrier_record->srcQueueFamilyIndex, |
| 863 | barrier_record->dstQueueFamilyIndex); |
John Zulauf | 6b4aae8 | 2018-05-09 13:03:36 -0600 | [diff] [blame] | 864 | } |
| 865 | } |
| 866 | return skip; |
| 867 | } |
| 868 | |
| 869 | template <typename Barrier> |
Mark Lobodzinski | daea591 | 2019-03-07 14:47:09 -0700 | [diff] [blame] | 870 | void CoreChecks::RecordQFOTransferBarriers(GLOBAL_CB_NODE *cb_state, uint32_t barrier_count, const Barrier *barriers) { |
Mark Lobodzinski | 8b0a7b8 | 2019-03-06 16:17:45 -0700 | [diff] [blame] | 871 | auto pool = GetCommandPoolNode(cb_state->createInfo.commandPool); |
John Zulauf | 6b4aae8 | 2018-05-09 13:03:36 -0600 | [diff] [blame] | 872 | auto &barrier_sets = GetQFOBarrierSets(cb_state, typename QFOTransferBarrier<Barrier>::Tag()); |
| 873 | for (uint32_t b = 0; b < barrier_count; b++) { |
| 874 | if (!IsTransferOp(&barriers[b])) continue; |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 875 | if (TempIsReleaseOp<Barrier, true /* Assume IsTransfer*/>(pool, &barriers[b]) && |
| 876 | !IsSpecial(barriers[b].dstQueueFamilyIndex)) { |
John Zulauf | 6b4aae8 | 2018-05-09 13:03:36 -0600 | [diff] [blame] | 877 | barrier_sets.release.emplace(barriers[b]); |
Shannon McPherson | ed2f009 | 2018-08-30 17:18:04 -0600 | [diff] [blame] | 878 | } else if (IsAcquireOp<Barrier, true /*Assume IsTransfer */>(pool, &barriers[b]) && |
| 879 | !IsSpecial(barriers[b].srcQueueFamilyIndex)) { |
John Zulauf | 6b4aae8 | 2018-05-09 13:03:36 -0600 | [diff] [blame] | 880 | barrier_sets.acquire.emplace(barriers[b]); |
| 881 | } |
| 882 | } |
| 883 | } |
| 884 | |
Mark Lobodzinski | daea591 | 2019-03-07 14:47:09 -0700 | [diff] [blame] | 885 | bool CoreChecks::ValidateBarriersQFOTransferUniqueness(const char *func_name, GLOBAL_CB_NODE *cb_state, uint32_t bufferBarrierCount, |
| 886 | const VkBufferMemoryBarrier *pBufferMemBarriers, |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 887 | uint32_t imageMemBarrierCount, |
| 888 | const VkImageMemoryBarrier *pImageMemBarriers) { |
John Zulauf | 6b4aae8 | 2018-05-09 13:03:36 -0600 | [diff] [blame] | 889 | bool skip = false; |
Mark Lobodzinski | daea591 | 2019-03-07 14:47:09 -0700 | [diff] [blame] | 890 | skip |= ValidateQFOTransferBarrierUniqueness(func_name, cb_state, bufferBarrierCount, pBufferMemBarriers); |
| 891 | skip |= ValidateQFOTransferBarrierUniqueness(func_name, cb_state, imageMemBarrierCount, pImageMemBarriers); |
John Zulauf | 6b4aae8 | 2018-05-09 13:03:36 -0600 | [diff] [blame] | 892 | return skip; |
| 893 | } |
| 894 | |
Mark Lobodzinski | daea591 | 2019-03-07 14:47:09 -0700 | [diff] [blame] | 895 | void CoreChecks::RecordBarriersQFOTransfers(GLOBAL_CB_NODE *cb_state, uint32_t bufferBarrierCount, |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 896 | const VkBufferMemoryBarrier *pBufferMemBarriers, uint32_t imageMemBarrierCount, |
| 897 | const VkImageMemoryBarrier *pImageMemBarriers) { |
Mark Lobodzinski | daea591 | 2019-03-07 14:47:09 -0700 | [diff] [blame] | 898 | RecordQFOTransferBarriers(cb_state, bufferBarrierCount, pBufferMemBarriers); |
| 899 | RecordQFOTransferBarriers(cb_state, imageMemBarrierCount, pImageMemBarriers); |
John Zulauf | 6b4aae8 | 2018-05-09 13:03:36 -0600 | [diff] [blame] | 900 | } |
| 901 | |
| 902 | template <typename BarrierRecord, typename Scoreboard> |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 903 | bool CoreChecks::ValidateAndUpdateQFOScoreboard(const debug_report_data *report_data, const GLOBAL_CB_NODE *cb_state, |
| 904 | const char *operation, const BarrierRecord &barrier, Scoreboard *scoreboard) { |
John Zulauf | 6b4aae8 | 2018-05-09 13:03:36 -0600 | [diff] [blame] | 905 | // Record to the scoreboard or report that we have a duplication |
| 906 | bool skip = false; |
| 907 | auto inserted = scoreboard->insert(std::make_pair(barrier, cb_state)); |
| 908 | if (!inserted.second && inserted.first->second != cb_state) { |
| 909 | // This is a duplication (but don't report duplicates from the same CB, as we do that at record time |
Locke | e9aeebf | 2019-03-03 23:50:08 -0700 | [diff] [blame] | 910 | skip = log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 911 | HandleToUint64(cb_state->commandBuffer), BarrierRecord::ErrMsgDuplicateQFOInSubmit(), |
| 912 | "%s: %s %s queue ownership of %s (%s), from srcQueueFamilyIndex %" PRIu32 " to dstQueueFamilyIndex %" PRIu32 |
| 913 | " duplicates existing barrier submitted in this batch from command buffer %s.", |
| 914 | "vkQueueSubmit()", BarrierRecord::BarrierName(), operation, BarrierRecord::HandleName(), |
| 915 | report_data->FormatHandle(barrier.handle).c_str(), barrier.srcQueueFamilyIndex, barrier.dstQueueFamilyIndex, |
John Zulauf | 7eb9482 | 2019-04-05 09:38:46 -0600 | [diff] [blame] | 916 | report_data->FormatHandle(inserted.first->second->commandBuffer).c_str()); |
John Zulauf | 6b4aae8 | 2018-05-09 13:03:36 -0600 | [diff] [blame] | 917 | } |
| 918 | return skip; |
| 919 | } |
| 920 | |
| 921 | template <typename Barrier> |
Mark Lobodzinski | daea591 | 2019-03-07 14:47:09 -0700 | [diff] [blame] | 922 | bool CoreChecks::ValidateQueuedQFOTransferBarriers(GLOBAL_CB_NODE *cb_state, QFOTransferCBScoreboards<Barrier> *scoreboards) { |
John Zulauf | 6b4aae8 | 2018-05-09 13:03:36 -0600 | [diff] [blame] | 923 | using BarrierRecord = QFOTransferBarrier<Barrier>; |
| 924 | using TypeTag = typename BarrierRecord::Tag; |
| 925 | bool skip = false; |
John Zulauf | 6b4aae8 | 2018-05-09 13:03:36 -0600 | [diff] [blame] | 926 | const auto &cb_barriers = GetQFOBarrierSets(cb_state, TypeTag()); |
Mark Lobodzinski | 8deebf1 | 2019-03-07 11:38:38 -0700 | [diff] [blame] | 927 | const GlobalQFOTransferBarrierMap<Barrier> &global_release_barriers = GetGlobalQFOReleaseBarrierMap(TypeTag()); |
John Zulauf | 6b4aae8 | 2018-05-09 13:03:36 -0600 | [diff] [blame] | 928 | const char *barrier_name = BarrierRecord::BarrierName(); |
| 929 | const char *handle_name = BarrierRecord::HandleName(); |
| 930 | // No release should have an extant duplicate (WARNING) |
| 931 | for (const auto &release : cb_barriers.release) { |
| 932 | // Check the global pending release barriers |
| 933 | const auto set_it = global_release_barriers.find(release.handle); |
| 934 | if (set_it != global_release_barriers.cend()) { |
| 935 | const QFOTransferBarrierSet<Barrier> &set_for_handle = set_it->second; |
| 936 | const auto found = set_for_handle.find(release); |
| 937 | if (found != set_for_handle.cend()) { |
| 938 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 939 | HandleToUint64(cb_state->commandBuffer), BarrierRecord::ErrMsgDuplicateQFOSubmitted(), |
Locke | e9aeebf | 2019-03-03 23:50:08 -0700 | [diff] [blame] | 940 | "%s: %s releasing queue ownership of %s (%s), from srcQueueFamilyIndex %" PRIu32 |
John Zulauf | 6b4aae8 | 2018-05-09 13:03:36 -0600 | [diff] [blame] | 941 | " to dstQueueFamilyIndex %" PRIu32 |
| 942 | " duplicates existing barrier queued for execution, without intervening acquire operation.", |
Locke | e9aeebf | 2019-03-03 23:50:08 -0700 | [diff] [blame] | 943 | "vkQueueSubmit()", barrier_name, handle_name, report_data->FormatHandle(found->handle).c_str(), |
John Zulauf | 6b4aae8 | 2018-05-09 13:03:36 -0600 | [diff] [blame] | 944 | found->srcQueueFamilyIndex, found->dstQueueFamilyIndex); |
| 945 | } |
| 946 | } |
| 947 | skip |= ValidateAndUpdateQFOScoreboard(report_data, cb_state, "releasing", release, &scoreboards->release); |
| 948 | } |
| 949 | // Each acquire must have a matching release (ERROR) |
| 950 | for (const auto &acquire : cb_barriers.acquire) { |
| 951 | const auto set_it = global_release_barriers.find(acquire.handle); |
| 952 | bool matching_release_found = false; |
| 953 | if (set_it != global_release_barriers.cend()) { |
| 954 | const QFOTransferBarrierSet<Barrier> &set_for_handle = set_it->second; |
| 955 | matching_release_found = set_for_handle.find(acquire) != set_for_handle.cend(); |
| 956 | } |
| 957 | if (!matching_release_found) { |
| 958 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 959 | HandleToUint64(cb_state->commandBuffer), BarrierRecord::ErrMsgMissingQFOReleaseInSubmit(), |
Locke | e9aeebf | 2019-03-03 23:50:08 -0700 | [diff] [blame] | 960 | "%s: in submitted command buffer %s acquiring ownership of %s (%s), from srcQueueFamilyIndex %" PRIu32 |
| 961 | " to dstQueueFamilyIndex %" PRIu32 " has no matching release barrier queued for execution.", |
| 962 | "vkQueueSubmit()", barrier_name, handle_name, report_data->FormatHandle(acquire.handle).c_str(), |
John Zulauf | 6b4aae8 | 2018-05-09 13:03:36 -0600 | [diff] [blame] | 963 | acquire.srcQueueFamilyIndex, acquire.dstQueueFamilyIndex); |
| 964 | } |
| 965 | skip |= ValidateAndUpdateQFOScoreboard(report_data, cb_state, "acquiring", acquire, &scoreboards->acquire); |
| 966 | } |
| 967 | return skip; |
| 968 | } |
| 969 | |
Mark Lobodzinski | daea591 | 2019-03-07 14:47:09 -0700 | [diff] [blame] | 970 | bool CoreChecks::ValidateQueuedQFOTransfers(GLOBAL_CB_NODE *cb_state, |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 971 | QFOTransferCBScoreboards<VkImageMemoryBarrier> *qfo_image_scoreboards, |
| 972 | QFOTransferCBScoreboards<VkBufferMemoryBarrier> *qfo_buffer_scoreboards) { |
John Zulauf | 6b4aae8 | 2018-05-09 13:03:36 -0600 | [diff] [blame] | 973 | bool skip = false; |
Mark Lobodzinski | daea591 | 2019-03-07 14:47:09 -0700 | [diff] [blame] | 974 | skip |= ValidateQueuedQFOTransferBarriers<VkImageMemoryBarrier>(cb_state, qfo_image_scoreboards); |
| 975 | skip |= ValidateQueuedQFOTransferBarriers<VkBufferMemoryBarrier>(cb_state, qfo_buffer_scoreboards); |
John Zulauf | 6b4aae8 | 2018-05-09 13:03:36 -0600 | [diff] [blame] | 976 | return skip; |
| 977 | } |
| 978 | |
| 979 | template <typename Barrier> |
Mark Lobodzinski | daea591 | 2019-03-07 14:47:09 -0700 | [diff] [blame] | 980 | void CoreChecks::RecordQueuedQFOTransferBarriers(GLOBAL_CB_NODE *cb_state) { |
John Zulauf | 6b4aae8 | 2018-05-09 13:03:36 -0600 | [diff] [blame] | 981 | using BarrierRecord = QFOTransferBarrier<Barrier>; |
| 982 | using TypeTag = typename BarrierRecord::Tag; |
| 983 | const auto &cb_barriers = GetQFOBarrierSets(cb_state, TypeTag()); |
Mark Lobodzinski | 8deebf1 | 2019-03-07 11:38:38 -0700 | [diff] [blame] | 984 | GlobalQFOTransferBarrierMap<Barrier> &global_release_barriers = GetGlobalQFOReleaseBarrierMap(TypeTag()); |
John Zulauf | 6b4aae8 | 2018-05-09 13:03:36 -0600 | [diff] [blame] | 985 | |
| 986 | // Add release barriers from this submit to the global map |
| 987 | for (const auto &release : cb_barriers.release) { |
| 988 | // the global barrier list is mapped by resource handle to allow cleanup on resource destruction |
| 989 | // NOTE: We're using [] because creation of a Set is a needed side effect for new handles |
| 990 | global_release_barriers[release.handle].insert(release); |
| 991 | } |
| 992 | |
| 993 | // Erase acquired barriers from this submit from the global map -- essentially marking releases as consumed |
| 994 | for (const auto &acquire : cb_barriers.acquire) { |
| 995 | // NOTE: We're not using [] because we don't want to create entries for missing releases |
| 996 | auto set_it = global_release_barriers.find(acquire.handle); |
| 997 | if (set_it != global_release_barriers.end()) { |
| 998 | QFOTransferBarrierSet<Barrier> &set_for_handle = set_it->second; |
| 999 | set_for_handle.erase(acquire); |
| 1000 | if (set_for_handle.size() == 0) { // Clean up empty sets |
| 1001 | global_release_barriers.erase(set_it); |
| 1002 | } |
| 1003 | } |
| 1004 | } |
| 1005 | } |
| 1006 | |
Mark Lobodzinski | daea591 | 2019-03-07 14:47:09 -0700 | [diff] [blame] | 1007 | void CoreChecks::RecordQueuedQFOTransfers(GLOBAL_CB_NODE *cb_state) { |
| 1008 | RecordQueuedQFOTransferBarriers<VkImageMemoryBarrier>(cb_state); |
| 1009 | RecordQueuedQFOTransferBarriers<VkBufferMemoryBarrier>(cb_state); |
John Zulauf | 6b4aae8 | 2018-05-09 13:03:36 -0600 | [diff] [blame] | 1010 | } |
| 1011 | |
John Zulauf | 6b4aae8 | 2018-05-09 13:03:36 -0600 | [diff] [blame] | 1012 | // Avoid making the template globally visible by exporting the one instance of it we need. |
Mark Lobodzinski | daea591 | 2019-03-07 14:47:09 -0700 | [diff] [blame] | 1013 | void CoreChecks::EraseQFOImageRelaseBarriers(const VkImage &image) { EraseQFOReleaseBarriers<VkImageMemoryBarrier>(image); } |
John Zulauf | 6b4aae8 | 2018-05-09 13:03:36 -0600 | [diff] [blame] | 1014 | |
Mark Lobodzinski | 8564e44 | 2019-03-07 12:49:41 -0700 | [diff] [blame] | 1015 | void CoreChecks::TransitionImageLayouts(GLOBAL_CB_NODE *cb_state, uint32_t memBarrierCount, |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 1016 | const VkImageMemoryBarrier *pImgMemBarriers) { |
Mark Lobodzinski | 6b6c50a | 2017-02-27 12:56:14 -0700 | [diff] [blame] | 1017 | for (uint32_t i = 0; i < memBarrierCount; ++i) { |
| 1018 | auto mem_barrier = &pImgMemBarriers[i]; |
| 1019 | if (!mem_barrier) continue; |
Mark Lobodzinski | 6b6c50a | 2017-02-27 12:56:14 -0700 | [diff] [blame] | 1020 | |
Chris Forbes | 4de4b13 | 2017-08-21 11:27:08 -0700 | [diff] [blame] | 1021 | // For ownership transfers, the barrier is specified twice; as a release |
| 1022 | // operation on the yielding queue family, and as an acquire operation |
| 1023 | // on the acquiring queue family. This barrier may also include a layout |
| 1024 | // transition, which occurs 'between' the two operations. For validation |
| 1025 | // purposes it doesn't seem important which side performs the layout |
| 1026 | // transition, but it must not be performed twice. We'll arbitrarily |
| 1027 | // choose to perform it as part of the acquire operation. |
Mark Lobodzinski | 8deebf1 | 2019-03-07 11:38:38 -0700 | [diff] [blame] | 1028 | if (IsReleaseOp(cb_state, mem_barrier)) { |
Chris Forbes | 4de4b13 | 2017-08-21 11:27:08 -0700 | [diff] [blame] | 1029 | continue; |
| 1030 | } |
| 1031 | |
John Zulauf | f660ad6 | 2019-03-23 07:16:05 -0600 | [diff] [blame] | 1032 | auto *image_state = GetImageState(mem_barrier->image); |
| 1033 | if (!image_state) continue; |
| 1034 | |
| 1035 | VkImageSubresourceRange normalized_isr = NormalizeSubresourceRange(*image_state, mem_barrier->subresourceRange); |
| 1036 | const auto &image_create_info = image_state->createInfo; |
Mark Lobodzinski | 903e5ff | 2017-03-23 09:43:35 -0600 | [diff] [blame] | 1037 | |
Dave Houlton | b3f4b28 | 2018-02-22 16:25:16 -0700 | [diff] [blame] | 1038 | // Special case for 3D images with VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT_KHR flag bit, where <extent.depth> and |
| 1039 | // <arrayLayers> can potentially alias. When recording layout for the entire image, pre-emptively record layouts |
| 1040 | // for all (potential) layer sub_resources. |
John Zulauf | f660ad6 | 2019-03-23 07:16:05 -0600 | [diff] [blame] | 1041 | if (0 != (image_create_info.flags & VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT_KHR)) { |
| 1042 | normalized_isr.baseArrayLayer = 0; |
| 1043 | normalized_isr.layerCount = image_create_info.extent.depth; // Treat each depth slice as a layer subresource |
Dave Houlton | b3f4b28 | 2018-02-22 16:25:16 -0700 | [diff] [blame] | 1044 | } |
| 1045 | |
John Zulauf | f660ad6 | 2019-03-23 07:16:05 -0600 | [diff] [blame] | 1046 | SetImageLayout(cb_state, *image_state, normalized_isr, mem_barrier->newLayout, mem_barrier->oldLayout); |
Mark Lobodzinski | 6b6c50a | 2017-02-27 12:56:14 -0700 | [diff] [blame] | 1047 | } |
| 1048 | } |
| 1049 | |
John Zulauf | f660ad6 | 2019-03-23 07:16:05 -0600 | [diff] [blame] | 1050 | bool CoreChecks::VerifyImageLayout(GLOBAL_CB_NODE const *cb_node, IMAGE_STATE *image_state, const VkImageSubresourceRange &range, |
John Zulauf | abcc829 | 2019-04-08 18:07:44 -0600 | [diff] [blame] | 1051 | VkImageAspectFlags aspect_mask, VkImageLayout explicit_layout, VkImageLayout optimal_layout, |
| 1052 | const char *caller, const char *layout_invalid_msg_code, const char *layout_mismatch_msg_code, |
| 1053 | bool *error) { |
John Zulauf | f660ad6 | 2019-03-23 07:16:05 -0600 | [diff] [blame] | 1054 | assert(cb_node); |
| 1055 | assert(image_state); |
Tobin Ehlis | 2d85ec6 | 2017-03-14 15:38:48 -0600 | [diff] [blame] | 1056 | const auto image = image_state->image; |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 1057 | bool skip = false; |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 1058 | |
John Zulauf | f660ad6 | 2019-03-23 07:16:05 -0600 | [diff] [blame] | 1059 | const auto *subresource_map = GetImageSubresourceLayoutMap(cb_node, image); |
| 1060 | if (subresource_map) { |
| 1061 | bool subres_skip = false; |
John Zulauf | abcc829 | 2019-04-08 18:07:44 -0600 | [diff] [blame] | 1062 | auto subresource_cb = [this, explicit_layout, cb_node, layout_mismatch_msg_code, caller, image, aspect_mask, &error, |
| 1063 | &subres_skip](const VkImageSubresource &subres, VkImageLayout layout, VkImageLayout initial_layout) { |
| 1064 | LayoutUseCheckAndMessage layout_check(explicit_layout, layout, initial_layout, aspect_mask); |
John Zulauf | f660ad6 | 2019-03-23 07:16:05 -0600 | [diff] [blame] | 1065 | if (layout_check.CheckFailed()) { |
Tobin Ehlis | c826645 | 2017-04-07 12:20:30 -0600 | [diff] [blame] | 1066 | *error = true; |
John Zulauf | f660ad6 | 2019-03-23 07:16:05 -0600 | [diff] [blame] | 1067 | subres_skip |= |
| 1068 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1069 | HandleToUint64(cb_node->commandBuffer), layout_mismatch_msg_code, |
| 1070 | "%s: Cannot use image %s (layer=%u mip=%u) with specific layout %s that doesn't match the " |
| 1071 | "%s layout %s.", |
| 1072 | caller, report_data->FormatHandle(image).c_str(), subres.arrayLayer, subres.mipLevel, |
| 1073 | string_VkImageLayout(explicit_layout), layout_check.message, string_VkImageLayout(layout_check.layout)); |
Tobin Ehlis | e35b66a | 2017-03-15 12:18:31 -0600 | [diff] [blame] | 1074 | } |
John Zulauf | f660ad6 | 2019-03-23 07:16:05 -0600 | [diff] [blame] | 1075 | return !subres_skip; |
| 1076 | }; |
| 1077 | subresource_map->ForRange(range, subresource_cb); |
| 1078 | skip |= subres_skip; |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 1079 | } |
John Zulauf | f660ad6 | 2019-03-23 07:16:05 -0600 | [diff] [blame] | 1080 | |
Tobin Ehlis | 2d85ec6 | 2017-03-14 15:38:48 -0600 | [diff] [blame] | 1081 | // If optimal_layout is not UNDEFINED, check that layout matches optimal for this case |
| 1082 | if ((VK_IMAGE_LAYOUT_UNDEFINED != optimal_layout) && (explicit_layout != optimal_layout)) { |
| 1083 | if (VK_IMAGE_LAYOUT_GENERAL == explicit_layout) { |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 1084 | if (image_state->createInfo.tiling != VK_IMAGE_TILING_LINEAR) { |
| 1085 | // 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] | 1086 | skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 1087 | VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, HandleToUint64(cb_node->commandBuffer), |
Dave Houlton | 5165390 | 2018-06-22 17:32:13 -0600 | [diff] [blame] | 1088 | kVUID_Core_DrawState_InvalidImageLayout, |
Locke | e9aeebf | 2019-03-03 23:50:08 -0700 | [diff] [blame] | 1089 | "%s: For optimal performance image %s layout should be %s instead of GENERAL.", caller, |
| 1090 | report_data->FormatHandle(image).c_str(), string_VkImageLayout(optimal_layout)); |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 1091 | } |
Mark Lobodzinski | 60e7903 | 2019-03-07 10:22:31 -0700 | [diff] [blame] | 1092 | } else if (GetDeviceExtensions()->vk_khr_shared_presentable_image) { |
Mark Lobodzinski | 087380c | 2017-05-16 14:42:25 -0600 | [diff] [blame] | 1093 | if (image_state->shared_presentable) { |
| 1094 | if (VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR != explicit_layout) { |
Cort Stratton | 7df3096 | 2018-05-17 19:45:57 -0700 | [diff] [blame] | 1095 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 1096 | layout_invalid_msg_code, |
| 1097 | "Layout for shared presentable image is %s but must be VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR.", |
| 1098 | string_VkImageLayout(optimal_layout)); |
Mark Lobodzinski | 087380c | 2017-05-16 14:42:25 -0600 | [diff] [blame] | 1099 | } |
Tobin Ehlis | bb03e5f | 2017-05-11 08:52:51 -0600 | [diff] [blame] | 1100 | } |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 1101 | } else { |
Tobin Ehlis | c826645 | 2017-04-07 12:20:30 -0600 | [diff] [blame] | 1102 | *error = true; |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 1103 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Cort Stratton | 7df3096 | 2018-05-17 19:45:57 -0700 | [diff] [blame] | 1104 | HandleToUint64(cb_node->commandBuffer), layout_invalid_msg_code, |
Locke | e9aeebf | 2019-03-03 23:50:08 -0700 | [diff] [blame] | 1105 | "%s: Layout for image %s is %s but can only be %s or VK_IMAGE_LAYOUT_GENERAL.", caller, |
| 1106 | report_data->FormatHandle(image).c_str(), string_VkImageLayout(explicit_layout), |
| 1107 | string_VkImageLayout(optimal_layout)); |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 1108 | } |
| 1109 | } |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 1110 | return skip; |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 1111 | } |
John Zulauf | f660ad6 | 2019-03-23 07:16:05 -0600 | [diff] [blame] | 1112 | bool CoreChecks::VerifyImageLayout(GLOBAL_CB_NODE const *cb_node, IMAGE_STATE *image_state, |
| 1113 | const VkImageSubresourceLayers &subLayers, VkImageLayout explicit_layout, |
| 1114 | VkImageLayout optimal_layout, const char *caller, const char *layout_invalid_msg_code, |
| 1115 | const char *layout_mismatch_msg_code, bool *error) { |
| 1116 | return VerifyImageLayout(cb_node, image_state, RangeFromLayers(subLayers), explicit_layout, optimal_layout, caller, |
| 1117 | layout_invalid_msg_code, layout_mismatch_msg_code, error); |
| 1118 | } |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 1119 | |
Mark Lobodzinski | 8564e44 | 2019-03-07 12:49:41 -0700 | [diff] [blame] | 1120 | void CoreChecks::TransitionFinalSubpassLayouts(GLOBAL_CB_NODE *pCB, const VkRenderPassBeginInfo *pRenderPassBegin, |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 1121 | FRAMEBUFFER_STATE *framebuffer_state) { |
Mark Lobodzinski | 2e49588 | 2019-03-06 16:11:56 -0700 | [diff] [blame] | 1122 | auto renderPass = GetRenderPassState(pRenderPassBegin->renderPass); |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 1123 | if (!renderPass) return; |
| 1124 | |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 1125 | const VkRenderPassCreateInfo2KHR *pRenderPassInfo = renderPass->createInfo.ptr(); |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 1126 | if (framebuffer_state) { |
| 1127 | for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) { |
Mark Lobodzinski | a3a230b | 2019-03-06 15:35:13 -0700 | [diff] [blame] | 1128 | auto view_state = GetAttachmentImageViewState(framebuffer_state, i); |
John Zulauf | 8e30829 | 2018-09-21 11:34:37 -0600 | [diff] [blame] | 1129 | if (view_state) { |
John Zulauf | f660ad6 | 2019-03-23 07:16:05 -0600 | [diff] [blame] | 1130 | SetImageViewLayout(pCB, *view_state, pRenderPassInfo->pAttachments[i].finalLayout); |
John Zulauf | 8e30829 | 2018-09-21 11:34:37 -0600 | [diff] [blame] | 1131 | } |
Mark Lobodzinski | 3c0f636 | 2017-02-01 13:35:48 -0700 | [diff] [blame] | 1132 | } |
| 1133 | } |
| 1134 | } |
Dave Houlton | e19e20d | 2018-02-02 16:32:41 -0700 | [diff] [blame] | 1135 | |
Dave Houlton | 0d4ad6f | 2018-09-05 14:53:34 -0600 | [diff] [blame] | 1136 | #ifdef VK_USE_PLATFORM_ANDROID_KHR |
| 1137 | // Android-specific validation that uses types defined only with VK_USE_PLATFORM_ANDROID_KHR |
| 1138 | // This could also move into a seperate core_validation_android.cpp file... ? |
| 1139 | |
| 1140 | // |
| 1141 | // AHB-specific validation within non-AHB APIs |
| 1142 | // |
Mark Lobodzinski | e9b9979 | 2019-03-07 16:34:29 -0700 | [diff] [blame] | 1143 | bool CoreChecks::ValidateCreateImageANDROID(const debug_report_data *report_data, const VkImageCreateInfo *create_info) { |
Dave Houlton | 0d4ad6f | 2018-09-05 14:53:34 -0600 | [diff] [blame] | 1144 | bool skip = false; |
| 1145 | |
| 1146 | const VkExternalFormatANDROID *ext_fmt_android = lvl_find_in_chain<VkExternalFormatANDROID>(create_info->pNext); |
| 1147 | if (ext_fmt_android) { |
Dave Houlton | d961131 | 2018-11-19 17:03:36 -0700 | [diff] [blame] | 1148 | if (0 != ext_fmt_android->externalFormat) { |
| 1149 | if (VK_FORMAT_UNDEFINED != create_info->format) { |
| 1150 | skip |= |
| 1151 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 1152 | "VUID-VkImageCreateInfo-pNext-01974", |
Graeme Leese | 2cd2a1f | 2018-11-19 15:11:45 +0000 | [diff] [blame] | 1153 | "vkCreateImage(): VkImageCreateInfo struct has a chained VkExternalFormatANDROID struct with non-zero " |
Dave Houlton | d961131 | 2018-11-19 17:03:36 -0700 | [diff] [blame] | 1154 | "externalFormat, but the VkImageCreateInfo's format is not VK_FORMAT_UNDEFINED."); |
| 1155 | } |
| 1156 | |
| 1157 | if (0 != (VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT & create_info->flags)) { |
| 1158 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 1159 | "VUID-VkImageCreateInfo-pNext-02396", |
Graeme Leese | 2cd2a1f | 2018-11-19 15:11:45 +0000 | [diff] [blame] | 1160 | "vkCreateImage(): VkImageCreateInfo struct has a chained VkExternalFormatANDROID struct with " |
Dave Houlton | d961131 | 2018-11-19 17:03:36 -0700 | [diff] [blame] | 1161 | "non-zero externalFormat, but flags include VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT."); |
| 1162 | } |
| 1163 | |
| 1164 | if (0 != (~VK_IMAGE_USAGE_SAMPLED_BIT & create_info->usage)) { |
| 1165 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 1166 | "VUID-VkImageCreateInfo-pNext-02397", |
Graeme Leese | 2cd2a1f | 2018-11-19 15:11:45 +0000 | [diff] [blame] | 1167 | "vkCreateImage(): VkImageCreateInfo struct has a chained VkExternalFormatANDROID struct with " |
Dave Houlton | d961131 | 2018-11-19 17:03:36 -0700 | [diff] [blame] | 1168 | "non-zero externalFormat, but usage includes bits other than VK_IMAGE_USAGE_SAMPLED_BIT."); |
| 1169 | } |
| 1170 | |
| 1171 | if (VK_IMAGE_TILING_OPTIMAL != create_info->tiling) { |
| 1172 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 1173 | "VUID-VkImageCreateInfo-pNext-02398", |
Graeme Leese | 2cd2a1f | 2018-11-19 15:11:45 +0000 | [diff] [blame] | 1174 | "vkCreateImage(): VkImageCreateInfo struct has a chained VkExternalFormatANDROID struct with " |
Dave Houlton | d961131 | 2018-11-19 17:03:36 -0700 | [diff] [blame] | 1175 | "non-zero externalFormat, but layout is not VK_IMAGE_TILING_OPTIMAL."); |
| 1176 | } |
| 1177 | } |
| 1178 | |
Mark Lobodzinski | eb8654d | 2019-03-07 11:14:47 -0700 | [diff] [blame] | 1179 | auto ahb_formats = GetAHBExternalFormatsSet(); |
Dave Houlton | 0d4ad6f | 2018-09-05 14:53:34 -0600 | [diff] [blame] | 1180 | if ((0 != ext_fmt_android->externalFormat) && (0 == ahb_formats->count(ext_fmt_android->externalFormat))) { |
| 1181 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 1182 | "VUID-VkExternalFormatANDROID-externalFormat-01894", |
Graeme Leese | 2cd2a1f | 2018-11-19 15:11:45 +0000 | [diff] [blame] | 1183 | "vkCreateImage(): Chained VkExternalFormatANDROID struct contains a non-zero externalFormat which has " |
Dave Houlton | 0d4ad6f | 2018-09-05 14:53:34 -0600 | [diff] [blame] | 1184 | "not been previously retrieved by vkGetAndroidHardwareBufferPropertiesANDROID()."); |
| 1185 | } |
| 1186 | } |
| 1187 | |
Dave Houlton | d961131 | 2018-11-19 17:03:36 -0700 | [diff] [blame] | 1188 | if ((nullptr == ext_fmt_android) || (0 == ext_fmt_android->externalFormat)) { |
Dave Houlton | 0d4ad6f | 2018-09-05 14:53:34 -0600 | [diff] [blame] | 1189 | if (VK_FORMAT_UNDEFINED == create_info->format) { |
| 1190 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 1191 | "VUID-VkImageCreateInfo-pNext-01975", |
Graeme Leese | 2cd2a1f | 2018-11-19 15:11:45 +0000 | [diff] [blame] | 1192 | "vkCreateImage(): VkImageCreateInfo struct's format is VK_FORMAT_UNDEFINED, but either does not have a " |
Dave Houlton | d961131 | 2018-11-19 17:03:36 -0700 | [diff] [blame] | 1193 | "chained VkExternalFormatANDROID struct or the struct exists but has an externalFormat of 0."); |
| 1194 | } |
| 1195 | } |
| 1196 | |
| 1197 | const VkExternalMemoryImageCreateInfo *emici = lvl_find_in_chain<VkExternalMemoryImageCreateInfo>(create_info->pNext); |
| 1198 | if (emici && (emici->handleTypes & VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID)) { |
| 1199 | if (create_info->imageType != VK_IMAGE_TYPE_2D) { |
Graeme Leese | 2cd2a1f | 2018-11-19 15:11:45 +0000 | [diff] [blame] | 1200 | skip |= |
| 1201 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 1202 | "VUID-VkImageCreateInfo-pNext-02393", |
| 1203 | "vkCreateImage(): VkImageCreateInfo struct with imageType %s has chained VkExternalMemoryImageCreateInfo " |
| 1204 | "struct with handleType VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID.", |
| 1205 | string_VkImageType(create_info->imageType)); |
Dave Houlton | d961131 | 2018-11-19 17:03:36 -0700 | [diff] [blame] | 1206 | } |
| 1207 | |
| 1208 | if ((create_info->mipLevels != 1) && (create_info->mipLevels != FullMipChainLevels(create_info->extent))) { |
| 1209 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 1210 | "VUID-VkImageCreateInfo-pNext-02394", |
Graeme Leese | 2cd2a1f | 2018-11-19 15:11:45 +0000 | [diff] [blame] | 1211 | "vkCreateImage(): VkImageCreateInfo struct with chained VkExternalMemoryImageCreateInfo struct of " |
Dave Houlton | d961131 | 2018-11-19 17:03:36 -0700 | [diff] [blame] | 1212 | "handleType VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID " |
| 1213 | "specifies mipLevels = %" PRId32 " (full chain mipLevels are %" PRId32 ").", |
| 1214 | create_info->mipLevels, FullMipChainLevels(create_info->extent)); |
| 1215 | } |
Dave Houlton | 0d4ad6f | 2018-09-05 14:53:34 -0600 | [diff] [blame] | 1216 | } |
| 1217 | |
| 1218 | return skip; |
| 1219 | } |
| 1220 | |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 1221 | void CoreChecks::RecordCreateImageANDROID(const VkImageCreateInfo *create_info, IMAGE_STATE *is_node) { |
Dave Houlton | 0d4ad6f | 2018-09-05 14:53:34 -0600 | [diff] [blame] | 1222 | const VkExternalMemoryImageCreateInfo *emici = lvl_find_in_chain<VkExternalMemoryImageCreateInfo>(create_info->pNext); |
| 1223 | if (emici && (emici->handleTypes & VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID)) { |
| 1224 | is_node->imported_ahb = true; |
| 1225 | } |
Dave Houlton | d3e046d | 2018-11-28 13:08:09 -0700 | [diff] [blame] | 1226 | const VkExternalFormatANDROID *ext_fmt_android = lvl_find_in_chain<VkExternalFormatANDROID>(create_info->pNext); |
egdaniel | 1f4d2a4 | 2019-02-04 10:25:38 -0500 | [diff] [blame] | 1227 | if (ext_fmt_android && (0 != ext_fmt_android->externalFormat)) { |
Dave Houlton | d3e046d | 2018-11-28 13:08:09 -0700 | [diff] [blame] | 1228 | is_node->has_ahb_format = true; |
| 1229 | is_node->ahb_format = ext_fmt_android->externalFormat; |
| 1230 | } |
Dave Houlton | 0d4ad6f | 2018-09-05 14:53:34 -0600 | [diff] [blame] | 1231 | } |
| 1232 | |
Mark Lobodzinski | e9b9979 | 2019-03-07 16:34:29 -0700 | [diff] [blame] | 1233 | bool CoreChecks::ValidateCreateImageViewANDROID(const VkImageViewCreateInfo *create_info) { |
Dave Houlton | 0d4ad6f | 2018-09-05 14:53:34 -0600 | [diff] [blame] | 1234 | bool skip = false; |
Mark Lobodzinski | 8ddc23f | 2019-03-06 11:48:49 -0700 | [diff] [blame] | 1235 | IMAGE_STATE *image_state = GetImageState(create_info->image); |
Dave Houlton | d3e046d | 2018-11-28 13:08:09 -0700 | [diff] [blame] | 1236 | |
| 1237 | if (image_state->has_ahb_format) { |
Dave Houlton | d961131 | 2018-11-19 17:03:36 -0700 | [diff] [blame] | 1238 | if (VK_FORMAT_UNDEFINED != create_info->format) { |
| 1239 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 1240 | HandleToUint64(create_info->image), "VUID-VkImageViewCreateInfo-image-02399", |
| 1241 | "vkCreateImageView(): VkImageViewCreateInfo struct has a chained VkExternalFormatANDROID struct, but " |
| 1242 | "format member is %s.", |
| 1243 | string_VkFormat(create_info->format)); |
| 1244 | } |
Dave Houlton | 0d4ad6f | 2018-09-05 14:53:34 -0600 | [diff] [blame] | 1245 | |
Dave Houlton | d961131 | 2018-11-19 17:03:36 -0700 | [diff] [blame] | 1246 | // Chain must include a compatible ycbcr conversion |
| 1247 | bool conv_found = false; |
| 1248 | uint64_t external_format = 0; |
| 1249 | const VkSamplerYcbcrConversionInfo *ycbcr_conv_info = lvl_find_in_chain<VkSamplerYcbcrConversionInfo>(create_info->pNext); |
| 1250 | if (ycbcr_conv_info != nullptr) { |
Dave Houlton | 0d4ad6f | 2018-09-05 14:53:34 -0600 | [diff] [blame] | 1251 | VkSamplerYcbcrConversion conv_handle = ycbcr_conv_info->conversion; |
Mark Lobodzinski | eb8654d | 2019-03-07 11:14:47 -0700 | [diff] [blame] | 1252 | auto fmap = GetYcbcrConversionFormatMap(); |
Dave Houlton | d961131 | 2018-11-19 17:03:36 -0700 | [diff] [blame] | 1253 | if (fmap->find(conv_handle) != fmap->end()) { |
| 1254 | conv_found = true; |
| 1255 | external_format = fmap->at(conv_handle); |
Dave Houlton | 0d4ad6f | 2018-09-05 14:53:34 -0600 | [diff] [blame] | 1256 | } |
Dave Houlton | d961131 | 2018-11-19 17:03:36 -0700 | [diff] [blame] | 1257 | } |
Dave Houlton | d3e046d | 2018-11-28 13:08:09 -0700 | [diff] [blame] | 1258 | if ((!conv_found) || (external_format != image_state->ahb_format)) { |
Dave Houlton | 0d4ad6f | 2018-09-05 14:53:34 -0600 | [diff] [blame] | 1259 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | d961131 | 2018-11-19 17:03:36 -0700 | [diff] [blame] | 1260 | HandleToUint64(create_info->image), "VUID-VkImageViewCreateInfo-image-02400", |
| 1261 | "vkCreateImageView(): VkImageViewCreateInfo struct has a chained VkExternalFormatANDROID struct, but " |
| 1262 | "without a chained VkSamplerYcbcrConversionInfo struct with the same external format."); |
| 1263 | } |
| 1264 | |
| 1265 | // Errors in create_info swizzles |
| 1266 | if ((create_info->components.r != VK_COMPONENT_SWIZZLE_IDENTITY) || |
| 1267 | (create_info->components.g != VK_COMPONENT_SWIZZLE_IDENTITY) || |
| 1268 | (create_info->components.b != VK_COMPONENT_SWIZZLE_IDENTITY) || |
| 1269 | (create_info->components.a != VK_COMPONENT_SWIZZLE_IDENTITY)) { |
| 1270 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 1271 | HandleToUint64(create_info->image), "VUID-VkImageViewCreateInfo-image-02401", |
| 1272 | "vkCreateImageView(): VkImageViewCreateInfo struct has a chained VkExternalFormatANDROID struct, but " |
| 1273 | "includes one or more non-identity component swizzles."); |
Dave Houlton | 0d4ad6f | 2018-09-05 14:53:34 -0600 | [diff] [blame] | 1274 | } |
| 1275 | } |
Dave Houlton | d961131 | 2018-11-19 17:03:36 -0700 | [diff] [blame] | 1276 | |
Dave Houlton | 0d4ad6f | 2018-09-05 14:53:34 -0600 | [diff] [blame] | 1277 | return skip; |
| 1278 | } |
| 1279 | |
Mark Lobodzinski | e9b9979 | 2019-03-07 16:34:29 -0700 | [diff] [blame] | 1280 | bool CoreChecks::ValidateGetImageSubresourceLayoutANDROID(const VkImage image) { |
Dave Houlton | 0d4ad6f | 2018-09-05 14:53:34 -0600 | [diff] [blame] | 1281 | bool skip = false; |
Dave Houlton | 0d4ad6f | 2018-09-05 14:53:34 -0600 | [diff] [blame] | 1282 | |
Mark Lobodzinski | 8ddc23f | 2019-03-06 11:48:49 -0700 | [diff] [blame] | 1283 | IMAGE_STATE *image_state = GetImageState(image); |
Dave Houlton | 0d4ad6f | 2018-09-05 14:53:34 -0600 | [diff] [blame] | 1284 | if (image_state->imported_ahb && (0 == image_state->GetBoundMemory().size())) { |
| 1285 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, HandleToUint64(image), |
| 1286 | "VUID-vkGetImageSubresourceLayout-image-01895", |
Graeme Leese | 79b60cb | 2018-11-28 11:51:20 +0000 | [diff] [blame] | 1287 | "vkGetImageSubresourceLayout(): Attempt to query layout from an image created with " |
Dave Houlton | 0d4ad6f | 2018-09-05 14:53:34 -0600 | [diff] [blame] | 1288 | "VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID handleType which has not yet been " |
| 1289 | "bound to memory."); |
| 1290 | } |
| 1291 | return skip; |
| 1292 | } |
| 1293 | |
| 1294 | #else |
| 1295 | |
Mark Lobodzinski | e9b9979 | 2019-03-07 16:34:29 -0700 | [diff] [blame] | 1296 | bool CoreChecks::ValidateCreateImageANDROID(const debug_report_data *report_data, const VkImageCreateInfo *create_info) { |
Dave Houlton | 0d4ad6f | 2018-09-05 14:53:34 -0600 | [diff] [blame] | 1297 | return false; |
| 1298 | } |
| 1299 | |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 1300 | void CoreChecks::RecordCreateImageANDROID(const VkImageCreateInfo *create_info, IMAGE_STATE *is_node) {} |
Dave Houlton | 0d4ad6f | 2018-09-05 14:53:34 -0600 | [diff] [blame] | 1301 | |
Mark Lobodzinski | e9b9979 | 2019-03-07 16:34:29 -0700 | [diff] [blame] | 1302 | bool CoreChecks::ValidateCreateImageViewANDROID(const VkImageViewCreateInfo *create_info) { return false; } |
Dave Houlton | 0d4ad6f | 2018-09-05 14:53:34 -0600 | [diff] [blame] | 1303 | |
Mark Lobodzinski | e9b9979 | 2019-03-07 16:34:29 -0700 | [diff] [blame] | 1304 | bool CoreChecks::ValidateGetImageSubresourceLayoutANDROID(const VkImage image) { return false; } |
Dave Houlton | 0d4ad6f | 2018-09-05 14:53:34 -0600 | [diff] [blame] | 1305 | |
| 1306 | #endif // VK_USE_PLATFORM_ANDROID_KHR |
| 1307 | |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 1308 | bool CoreChecks::PreCallValidateCreateImage(VkDevice device, const VkImageCreateInfo *pCreateInfo, |
| 1309 | const VkAllocationCallbacks *pAllocator, VkImage *pImage) { |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 1310 | bool skip = false; |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 1311 | |
Mark Lobodzinski | 60e7903 | 2019-03-07 10:22:31 -0700 | [diff] [blame] | 1312 | if (GetDeviceExtensions()->vk_android_external_memory_android_hardware_buffer) { |
Mark Lobodzinski | e9b9979 | 2019-03-07 16:34:29 -0700 | [diff] [blame] | 1313 | skip |= ValidateCreateImageANDROID(report_data, pCreateInfo); |
Dave Houlton | 0d4ad6f | 2018-09-05 14:53:34 -0600 | [diff] [blame] | 1314 | } else { // These checks are omitted or replaced when Android HW Buffer extension is active |
| 1315 | if (pCreateInfo->format == VK_FORMAT_UNDEFINED) { |
| 1316 | return log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 1317 | "VUID-VkImageCreateInfo-format-00943", |
Graeme Leese | 2cd2a1f | 2018-11-19 15:11:45 +0000 | [diff] [blame] | 1318 | "vkCreateImage(): VkFormat for image must not be VK_FORMAT_UNDEFINED."); |
Dave Houlton | 0d4ad6f | 2018-09-05 14:53:34 -0600 | [diff] [blame] | 1319 | } |
Jeremy Hayes | 96dcd81 | 2017-03-14 14:04:19 -0600 | [diff] [blame] | 1320 | } |
| 1321 | |
Dave Houlton | 130c021 | 2018-01-29 13:39:56 -0700 | [diff] [blame] | 1322 | if ((pCreateInfo->flags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT) && (VK_IMAGE_TYPE_2D != pCreateInfo->imageType)) { |
Graeme Leese | 2cd2a1f | 2018-11-19 15:11:45 +0000 | [diff] [blame] | 1323 | skip |= log_msg( |
| 1324 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 1325 | "VUID-VkImageCreateInfo-flags-00949", |
| 1326 | "vkCreateImage(): Image type must be VK_IMAGE_TYPE_2D when VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT flag bit is set"); |
Dave Houlton | 130c021 | 2018-01-29 13:39:56 -0700 | [diff] [blame] | 1327 | } |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 1328 | |
Mark Lobodzinski | 79b5d5b | 2019-04-19 12:27:10 -0600 | [diff] [blame] | 1329 | const VkPhysicalDeviceLimits *device_limits = &phys_dev_props.limits; |
Dave Houlton | 130c021 | 2018-01-29 13:39:56 -0700 | [diff] [blame] | 1330 | VkImageUsageFlags attach_flags = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 1331 | VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT; |
| 1332 | if ((pCreateInfo->usage & attach_flags) && (pCreateInfo->extent.width > device_limits->maxFramebufferWidth)) { |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 1333 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Graeme Leese | 2cd2a1f | 2018-11-19 15:11:45 +0000 | [diff] [blame] | 1334 | "VUID-VkImageCreateInfo-usage-00964", |
| 1335 | "vkCreateImage(): Image usage flags include a frame buffer attachment bit and image width exceeds device " |
| 1336 | "maxFramebufferWidth."); |
Dave Houlton | 130c021 | 2018-01-29 13:39:56 -0700 | [diff] [blame] | 1337 | } |
| 1338 | |
| 1339 | if ((pCreateInfo->usage & attach_flags) && (pCreateInfo->extent.height > device_limits->maxFramebufferHeight)) { |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 1340 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Graeme Leese | 2cd2a1f | 2018-11-19 15:11:45 +0000 | [diff] [blame] | 1341 | "VUID-VkImageCreateInfo-usage-00965", |
| 1342 | "vkCreateImage(): Image usage flags include a frame buffer attachment bit and image height exceeds device " |
| 1343 | "maxFramebufferHeight"); |
Dave Houlton | 130c021 | 2018-01-29 13:39:56 -0700 | [diff] [blame] | 1344 | } |
| 1345 | |
Graeme Leese | 2cd2a1f | 2018-11-19 15:11:45 +0000 | [diff] [blame] | 1346 | VkImageFormatProperties format_limits = {}; |
Mark Lobodzinski | 5c04880 | 2019-03-07 10:47:31 -0700 | [diff] [blame] | 1347 | VkResult res = GetPDImageFormatProperties(pCreateInfo, &format_limits); |
Graeme Leese | 2cd2a1f | 2018-11-19 15:11:45 +0000 | [diff] [blame] | 1348 | if (res == VK_ERROR_FORMAT_NOT_SUPPORTED) { |
| 1349 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, kVUIDUndefined, |
| 1350 | "vkCreateImage(): Format %s is not supported for this combination of parameters.", |
| 1351 | string_VkFormat(pCreateInfo->format)); |
| 1352 | } else { |
| 1353 | if (pCreateInfo->mipLevels > format_limits.maxMipLevels) { |
| 1354 | const char *format_string = string_VkFormat(pCreateInfo->format); |
| 1355 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 1356 | "VUID-VkImageCreateInfo-mipLevels-02255", |
| 1357 | "vkCreateImage(): Image mip levels=%d exceed image format maxMipLevels=%d for format %s.", |
| 1358 | pCreateInfo->mipLevels, format_limits.maxMipLevels, format_string); |
| 1359 | } |
Dave Houlton | 130c021 | 2018-01-29 13:39:56 -0700 | [diff] [blame] | 1360 | |
Dave Houlton | a585d13 | 2019-01-18 13:05:42 -0700 | [diff] [blame] | 1361 | uint64_t texel_count = (uint64_t)pCreateInfo->extent.width * (uint64_t)pCreateInfo->extent.height * |
| 1362 | (uint64_t)pCreateInfo->extent.depth * (uint64_t)pCreateInfo->arrayLayers * |
| 1363 | (uint64_t)pCreateInfo->samples; |
| 1364 | uint64_t total_size = (uint64_t)std::ceil(FormatTexelSize(pCreateInfo->format) * texel_count); |
Dave Houlton | 130c021 | 2018-01-29 13:39:56 -0700 | [diff] [blame] | 1365 | |
Graeme Leese | 2cd2a1f | 2018-11-19 15:11:45 +0000 | [diff] [blame] | 1366 | // Round up to imageGranularity boundary |
Mark Lobodzinski | 79b5d5b | 2019-04-19 12:27:10 -0600 | [diff] [blame] | 1367 | VkDeviceSize imageGranularity = phys_dev_props.limits.bufferImageGranularity; |
Graeme Leese | 2cd2a1f | 2018-11-19 15:11:45 +0000 | [diff] [blame] | 1368 | uint64_t ig_mask = imageGranularity - 1; |
| 1369 | total_size = (total_size + ig_mask) & ~ig_mask; |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 1370 | |
Graeme Leese | 2cd2a1f | 2018-11-19 15:11:45 +0000 | [diff] [blame] | 1371 | if (total_size > format_limits.maxResourceSize) { |
| 1372 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, |
| 1373 | kVUID_Core_Image_InvalidFormatLimitsViolation, |
| 1374 | "vkCreateImage(): resource size exceeds allowable maximum Image resource size = 0x%" PRIxLEAST64 |
| 1375 | ", maximum resource size = 0x%" PRIxLEAST64 " ", |
| 1376 | total_size, format_limits.maxResourceSize); |
| 1377 | } |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 1378 | |
Graeme Leese | 2cd2a1f | 2018-11-19 15:11:45 +0000 | [diff] [blame] | 1379 | if (pCreateInfo->arrayLayers > format_limits.maxArrayLayers) { |
| 1380 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, |
| 1381 | "VUID-VkImageCreateInfo-arrayLayers-02256", |
| 1382 | "vkCreateImage(): arrayLayers=%d exceeds allowable maximum supported by format of %d.", |
| 1383 | pCreateInfo->arrayLayers, format_limits.maxArrayLayers); |
| 1384 | } |
| 1385 | |
Piers Daniell | 10a5c76 | 2019-03-11 12:44:50 -0600 | [diff] [blame] | 1386 | if (GetDeviceExtensions()->vk_khr_sampler_ycbcr_conversion && FormatRequiresYcbcrConversion(pCreateInfo->format) && |
| 1387 | !GetDeviceExtensions()->vk_ext_ycbcr_image_arrays && pCreateInfo->arrayLayers > 1) { |
| 1388 | skip |= log_msg( |
| 1389 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, |
| 1390 | "VUID-VkImageCreateInfo-format-02653", |
| 1391 | "vkCreateImage(): arrayLayers=%d exceeds the maximum allowed of 1 for formats requiring sampler ycbcr conversion", |
| 1392 | pCreateInfo->arrayLayers); |
| 1393 | } |
| 1394 | |
Graeme Leese | 2cd2a1f | 2018-11-19 15:11:45 +0000 | [diff] [blame] | 1395 | if ((pCreateInfo->samples & format_limits.sampleCounts) == 0) { |
| 1396 | skip |= |
| 1397 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, |
| 1398 | "VUID-VkImageCreateInfo-samples-02258", "vkCreateImage(): samples %s is not supported by format 0x%.8X.", |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 1399 | string_VkSampleCountFlagBits(pCreateInfo->samples), format_limits.sampleCounts); |
Graeme Leese | 2cd2a1f | 2018-11-19 15:11:45 +0000 | [diff] [blame] | 1400 | } |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 1401 | } |
| 1402 | |
Mark Lobodzinski | 60e7903 | 2019-03-07 10:22:31 -0700 | [diff] [blame] | 1403 | if ((pCreateInfo->flags & VK_IMAGE_CREATE_SPARSE_ALIASED_BIT) && (!GetEnabledFeatures()->core.sparseResidencyAliased)) { |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 1404 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Dave Houlton | 12befb9 | 2018-06-26 17:16:46 -0600 | [diff] [blame] | 1405 | "VUID-VkImageCreateInfo-flags-01924", |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 1406 | "vkCreateImage(): the sparseResidencyAliased device feature is disabled: Images cannot be created with the " |
| 1407 | "VK_IMAGE_CREATE_SPARSE_ALIASED_BIT set."); |
Mark Lobodzinski | 035a4cf | 2017-03-13 09:45:07 -0600 | [diff] [blame] | 1408 | } |
| 1409 | |
Mark Lobodzinski | 60e7903 | 2019-03-07 10:22:31 -0700 | [diff] [blame] | 1410 | if (GetDeviceExtensions()->vk_khr_maintenance2) { |
Lenny Komow | b79f04a | 2017-09-18 17:07:00 -0600 | [diff] [blame] | 1411 | if (pCreateInfo->flags & VK_IMAGE_CREATE_BLOCK_TEXEL_VIEW_COMPATIBLE_BIT_KHR) { |
| 1412 | if (!(FormatIsCompressed_BC(pCreateInfo->format) || FormatIsCompressed_ASTC_LDR(pCreateInfo->format) || |
| 1413 | FormatIsCompressed_ETC2_EAC(pCreateInfo->format))) { |
| 1414 | // TODO: Add Maintenance2 VUID |
Dave Houlton | 8e9f654 | 2018-05-18 12:18:22 -0600 | [diff] [blame] | 1415 | skip |= |
| 1416 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, kVUIDUndefined, |
| 1417 | "vkCreateImage(): If pCreateInfo->flags contains VK_IMAGE_CREATE_BLOCK_TEXEL_VIEW_COMPATIBLE_BIT_KHR, " |
| 1418 | "format must be block, ETC or ASTC compressed, but is %s", |
| 1419 | string_VkFormat(pCreateInfo->format)); |
Lenny Komow | b79f04a | 2017-09-18 17:07:00 -0600 | [diff] [blame] | 1420 | } |
| 1421 | if (!(pCreateInfo->flags & VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT)) { |
| 1422 | // TODO: Add Maintenance2 VUID |
Dave Houlton | 8e9f654 | 2018-05-18 12:18:22 -0600 | [diff] [blame] | 1423 | skip |= |
| 1424 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, kVUIDUndefined, |
| 1425 | "vkCreateImage(): If pCreateInfo->flags contains VK_IMAGE_CREATE_BLOCK_TEXEL_VIEW_COMPATIBLE_BIT_KHR, " |
| 1426 | "flags must also contain VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT."); |
Lenny Komow | b79f04a | 2017-09-18 17:07:00 -0600 | [diff] [blame] | 1427 | } |
| 1428 | } |
| 1429 | } |
| 1430 | |
Mark Lobodzinski | 08ee03c | 2019-02-04 10:57:47 -0700 | [diff] [blame] | 1431 | if (pCreateInfo->sharingMode == VK_SHARING_MODE_CONCURRENT && pCreateInfo->pQueueFamilyIndices) { |
Mark Lobodzinski | daea591 | 2019-03-07 14:47:09 -0700 | [diff] [blame] | 1432 | skip |= ValidateQueueFamilies(pCreateInfo->queueFamilyIndexCount, pCreateInfo->pQueueFamilyIndices, "vkCreateImage", |
| 1433 | "pCreateInfo->pQueueFamilyIndices", "VUID-VkImageCreateInfo-sharingMode-01420", |
| 1434 | "VUID-VkImageCreateInfo-sharingMode-01420", false); |
Mark Lobodzinski | 08ee03c | 2019-02-04 10:57:47 -0700 | [diff] [blame] | 1435 | } |
| 1436 | |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 1437 | return skip; |
Mark Lobodzinski | 90224de | 2017-01-26 15:23:11 -0700 | [diff] [blame] | 1438 | } |
| 1439 | |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 1440 | void CoreChecks::PostCallRecordCreateImage(VkDevice device, const VkImageCreateInfo *pCreateInfo, |
| 1441 | const VkAllocationCallbacks *pAllocator, VkImage *pImage, VkResult result) { |
Mark Lobodzinski | 701507e | 2019-01-18 14:31:53 -0700 | [diff] [blame] | 1442 | if (VK_SUCCESS != result) return; |
Mark Lobodzinski | 42fe5f7 | 2017-01-11 11:36:16 -0700 | [diff] [blame] | 1443 | IMAGE_LAYOUT_NODE image_state; |
| 1444 | image_state.layout = pCreateInfo->initialLayout; |
| 1445 | image_state.format = pCreateInfo->format; |
Dave Houlton | 0d4ad6f | 2018-09-05 14:53:34 -0600 | [diff] [blame] | 1446 | IMAGE_STATE *is_node = new IMAGE_STATE(*pImage, pCreateInfo); |
Mark Lobodzinski | 60e7903 | 2019-03-07 10:22:31 -0700 | [diff] [blame] | 1447 | if (GetDeviceExtensions()->vk_android_external_memory_android_hardware_buffer) { |
Dave Houlton | 0d4ad6f | 2018-09-05 14:53:34 -0600 | [diff] [blame] | 1448 | RecordCreateImageANDROID(pCreateInfo, is_node); |
| 1449 | } |
Mark Lobodzinski | 34e04bf | 2019-04-19 13:31:53 -0600 | [diff] [blame] | 1450 | imageMap.insert(std::make_pair(*pImage, std::unique_ptr<IMAGE_STATE>(is_node))); |
Mark Lobodzinski | 42fe5f7 | 2017-01-11 11:36:16 -0700 | [diff] [blame] | 1451 | ImageSubresourcePair subpair{*pImage, false, VkImageSubresource()}; |
Mark Lobodzinski | 2a8d840 | 2019-04-19 13:41:41 -0600 | [diff] [blame^] | 1452 | imageSubresourceMap[*pImage].push_back(subpair); |
Mark Lobodzinski | 44d46d5 | 2019-03-07 11:04:06 -0700 | [diff] [blame] | 1453 | (*GetImageLayoutMap())[subpair] = image_state; |
Mark Lobodzinski | 9ddb718 | 2019-03-08 17:31:09 -0700 | [diff] [blame] | 1454 | (*GetImageLayoutMap())[subpair] = image_state; |
Mark Lobodzinski | 42fe5f7 | 2017-01-11 11:36:16 -0700 | [diff] [blame] | 1455 | } |
Mark Lobodzinski | 9ef5d56 | 2017-01-27 12:28:30 -0700 | [diff] [blame] | 1456 | |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 1457 | bool CoreChecks::PreCallValidateDestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks *pAllocator) { |
Mark Lobodzinski | 8ddc23f | 2019-03-06 11:48:49 -0700 | [diff] [blame] | 1458 | IMAGE_STATE *image_state = GetImageState(image); |
Mark Lobodzinski | 6b35c8a | 2019-01-10 10:57:27 -0700 | [diff] [blame] | 1459 | const VK_OBJECT obj_struct = {HandleToUint64(image), kVulkanObjectTypeImage}; |
Mark Lobodzinski | 9ef5d56 | 2017-01-27 12:28:30 -0700 | [diff] [blame] | 1460 | bool skip = false; |
Mark Lobodzinski | 6b35c8a | 2019-01-10 10:57:27 -0700 | [diff] [blame] | 1461 | if (image_state) { |
Mark Lobodzinski | 9ddb718 | 2019-03-08 17:31:09 -0700 | [diff] [blame] | 1462 | skip |= ValidateObjectNotInUse(image_state, obj_struct, "vkDestroyImage", "VUID-vkDestroyImage-image-01000"); |
Mark Lobodzinski | 9ef5d56 | 2017-01-27 12:28:30 -0700 | [diff] [blame] | 1463 | } |
| 1464 | return skip; |
| 1465 | } |
| 1466 | |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 1467 | void CoreChecks::PreCallRecordDestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks *pAllocator) { |
Mark Lobodzinski | dfa6411 | 2019-03-04 12:17:24 -0700 | [diff] [blame] | 1468 | if (!image) return; |
Mark Lobodzinski | 8ddc23f | 2019-03-06 11:48:49 -0700 | [diff] [blame] | 1469 | IMAGE_STATE *image_state = GetImageState(image); |
Mark Lobodzinski | 6b35c8a | 2019-01-10 10:57:27 -0700 | [diff] [blame] | 1470 | VK_OBJECT obj_struct = {HandleToUint64(image), kVulkanObjectTypeImage}; |
Mark Lobodzinski | 9ddb718 | 2019-03-08 17:31:09 -0700 | [diff] [blame] | 1471 | InvalidateCommandBuffers(image_state->cb_bindings, obj_struct); |
Mark Lobodzinski | 9ef5d56 | 2017-01-27 12:28:30 -0700 | [diff] [blame] | 1472 | // Clean up memory mapping, bindings and range references for image |
| 1473 | for (auto mem_binding : image_state->GetBoundMemory()) { |
Mark Lobodzinski | 97f83f7 | 2019-03-07 10:01:52 -0700 | [diff] [blame] | 1474 | auto mem_info = GetMemObjInfo(mem_binding); |
Mark Lobodzinski | 9ef5d56 | 2017-01-27 12:28:30 -0700 | [diff] [blame] | 1475 | if (mem_info) { |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 1476 | RemoveImageMemoryRange(obj_struct.handle, mem_info); |
Mark Lobodzinski | 9ef5d56 | 2017-01-27 12:28:30 -0700 | [diff] [blame] | 1477 | } |
| 1478 | } |
Mark Lobodzinski | 97f83f7 | 2019-03-07 10:01:52 -0700 | [diff] [blame] | 1479 | ClearMemoryObjectBindings(obj_struct.handle, kVulkanObjectTypeImage); |
Mark Lobodzinski | daea591 | 2019-03-07 14:47:09 -0700 | [diff] [blame] | 1480 | EraseQFOReleaseBarriers<VkImageMemoryBarrier>(image); |
Mark Lobodzinski | 9ef5d56 | 2017-01-27 12:28:30 -0700 | [diff] [blame] | 1481 | // Remove image from imageMap |
Mark Lobodzinski | 34e04bf | 2019-04-19 13:31:53 -0600 | [diff] [blame] | 1482 | imageMap.erase(image); |
Mark Lobodzinski | 9ef5d56 | 2017-01-27 12:28:30 -0700 | [diff] [blame] | 1483 | |
Mark Lobodzinski | 2a8d840 | 2019-04-19 13:41:41 -0600 | [diff] [blame^] | 1484 | const auto &sub_entry = imageSubresourceMap.find(image); |
| 1485 | if (sub_entry != imageSubresourceMap.end()) { |
Mark Lobodzinski | 9ef5d56 | 2017-01-27 12:28:30 -0700 | [diff] [blame] | 1486 | for (const auto &pair : sub_entry->second) { |
Mark Lobodzinski | 44d46d5 | 2019-03-07 11:04:06 -0700 | [diff] [blame] | 1487 | GetImageLayoutMap()->erase(pair); |
Mark Lobodzinski | 9ef5d56 | 2017-01-27 12:28:30 -0700 | [diff] [blame] | 1488 | } |
Mark Lobodzinski | 2a8d840 | 2019-04-19 13:41:41 -0600 | [diff] [blame^] | 1489 | imageSubresourceMap.erase(sub_entry); |
Mark Lobodzinski | 9ef5d56 | 2017-01-27 12:28:30 -0700 | [diff] [blame] | 1490 | } |
| 1491 | } |
Mark Lobodzinski | c409a58 | 2017-01-27 15:16:01 -0700 | [diff] [blame] | 1492 | |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 1493 | bool CoreChecks::ValidateImageAttributes(IMAGE_STATE *image_state, VkImageSubresourceRange range) { |
Mark Lobodzinski | c409a58 | 2017-01-27 15:16:01 -0700 | [diff] [blame] | 1494 | bool skip = false; |
Mark Lobodzinski | c409a58 | 2017-01-27 15:16:01 -0700 | [diff] [blame] | 1495 | |
| 1496 | if (range.aspectMask != VK_IMAGE_ASPECT_COLOR_BIT) { |
| 1497 | char const str[] = "vkCmdClearColorImage aspectMasks for all subresource ranges must be set to VK_IMAGE_ASPECT_COLOR_BIT"; |
| 1498 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | 5165390 | 2018-06-22 17:32:13 -0600 | [diff] [blame] | 1499 | HandleToUint64(image_state->image), kVUID_Core_DrawState_InvalidImageAspect, str); |
Mark Lobodzinski | c409a58 | 2017-01-27 15:16:01 -0700 | [diff] [blame] | 1500 | } |
| 1501 | |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 1502 | if (FormatIsDepthOrStencil(image_state->createInfo.format)) { |
Mark Lobodzinski | c409a58 | 2017-01-27 15:16:01 -0700 | [diff] [blame] | 1503 | char const str[] = "vkCmdClearColorImage called with depth/stencil image."; |
| 1504 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 1505 | HandleToUint64(image_state->image), "VUID-vkCmdClearColorImage-image-00007", "%s.", str); |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 1506 | } else if (FormatIsCompressed(image_state->createInfo.format)) { |
Mark Lobodzinski | c409a58 | 2017-01-27 15:16:01 -0700 | [diff] [blame] | 1507 | char const str[] = "vkCmdClearColorImage called with compressed image."; |
| 1508 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 1509 | HandleToUint64(image_state->image), "VUID-vkCmdClearColorImage-image-00007", "%s.", str); |
Mark Lobodzinski | c409a58 | 2017-01-27 15:16:01 -0700 | [diff] [blame] | 1510 | } |
| 1511 | |
| 1512 | if (!(image_state->createInfo.usage & VK_IMAGE_USAGE_TRANSFER_DST_BIT)) { |
| 1513 | char const str[] = "vkCmdClearColorImage called with image created without VK_IMAGE_USAGE_TRANSFER_DST_BIT."; |
| 1514 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 1515 | HandleToUint64(image_state->image), "VUID-vkCmdClearColorImage-image-00002", "%s.", str); |
Mark Lobodzinski | c409a58 | 2017-01-27 15:16:01 -0700 | [diff] [blame] | 1516 | } |
| 1517 | return skip; |
| 1518 | } |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1519 | |
Mark Lobodzinski | 903e5ff | 2017-03-23 09:43:35 -0600 | [diff] [blame] | 1520 | uint32_t ResolveRemainingLevels(const VkImageSubresourceRange *range, uint32_t mip_levels) { |
| 1521 | // Return correct number of mip levels taking into account VK_REMAINING_MIP_LEVELS |
| 1522 | uint32_t mip_level_count = range->levelCount; |
Mark Lobodzinski | 9c93dbd | 2017-02-02 08:31:18 -0700 | [diff] [blame] | 1523 | if (range->levelCount == VK_REMAINING_MIP_LEVELS) { |
Mark Lobodzinski | 903e5ff | 2017-03-23 09:43:35 -0600 | [diff] [blame] | 1524 | mip_level_count = mip_levels - range->baseMipLevel; |
Mark Lobodzinski | 9c93dbd | 2017-02-02 08:31:18 -0700 | [diff] [blame] | 1525 | } |
Mark Lobodzinski | 903e5ff | 2017-03-23 09:43:35 -0600 | [diff] [blame] | 1526 | return mip_level_count; |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1527 | } |
| 1528 | |
Mark Lobodzinski | 903e5ff | 2017-03-23 09:43:35 -0600 | [diff] [blame] | 1529 | uint32_t ResolveRemainingLayers(const VkImageSubresourceRange *range, uint32_t layers) { |
| 1530 | // Return correct number of layers taking into account VK_REMAINING_ARRAY_LAYERS |
| 1531 | uint32_t array_layer_count = range->layerCount; |
| 1532 | if (range->layerCount == VK_REMAINING_ARRAY_LAYERS) { |
| 1533 | array_layer_count = layers - range->baseArrayLayer; |
Mark Lobodzinski | 9c93dbd | 2017-02-02 08:31:18 -0700 | [diff] [blame] | 1534 | } |
Mark Lobodzinski | 903e5ff | 2017-03-23 09:43:35 -0600 | [diff] [blame] | 1535 | return array_layer_count; |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1536 | } |
| 1537 | |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 1538 | bool CoreChecks::VerifyClearImageLayout(GLOBAL_CB_NODE *cb_node, IMAGE_STATE *image_state, VkImageSubresourceRange range, |
| 1539 | VkImageLayout dest_image_layout, const char *func_name) { |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1540 | bool skip = false; |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1541 | |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1542 | if (dest_image_layout != VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) { |
| 1543 | if (dest_image_layout == VK_IMAGE_LAYOUT_GENERAL) { |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1544 | if (image_state->createInfo.tiling != VK_IMAGE_TILING_LINEAR) { |
| 1545 | // 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] | 1546 | skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | 5165390 | 2018-06-22 17:32:13 -0600 | [diff] [blame] | 1547 | HandleToUint64(image_state->image), kVUID_Core_DrawState_InvalidImageLayout, |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1548 | "%s: Layout for cleared image should be TRANSFER_DST_OPTIMAL instead of GENERAL.", func_name); |
| 1549 | } |
Mark Lobodzinski | 087380c | 2017-05-16 14:42:25 -0600 | [diff] [blame] | 1550 | } else if (VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR == dest_image_layout) { |
Mark Lobodzinski | 60e7903 | 2019-03-07 10:22:31 -0700 | [diff] [blame] | 1551 | if (!GetDeviceExtensions()->vk_khr_shared_presentable_image) { |
Tobin Ehlis | fb0661c | 2017-05-11 08:52:51 -0600 | [diff] [blame] | 1552 | // TODO: Add unique error id when available. |
Mark Lobodzinski | 087380c | 2017-05-16 14:42:25 -0600 | [diff] [blame] | 1553 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 1554 | HandleToUint64(image_state->image), 0, |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 1555 | "Must enable VK_KHR_shared_presentable_image extension before creating images with a layout type " |
| 1556 | "of VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR."); |
Mark Lobodzinski | 087380c | 2017-05-16 14:42:25 -0600 | [diff] [blame] | 1557 | |
| 1558 | } else { |
| 1559 | if (image_state->shared_presentable) { |
| 1560 | skip |= log_msg( |
| 1561 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 1562 | HandleToUint64(image_state->image), 0, |
Mark Lobodzinski | 087380c | 2017-05-16 14:42:25 -0600 | [diff] [blame] | 1563 | "Layout for shared presentable cleared image is %s but can only be VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR.", |
| 1564 | string_VkImageLayout(dest_image_layout)); |
| 1565 | } |
Tobin Ehlis | bb03e5f | 2017-05-11 08:52:51 -0600 | [diff] [blame] | 1566 | } |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1567 | } else { |
Jeff Bolz | 6d3beaa | 2019-02-09 21:00:05 -0600 | [diff] [blame] | 1568 | const char *error_code = "VUID-vkCmdClearColorImage-imageLayout-00005"; |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1569 | if (strcmp(func_name, "vkCmdClearDepthStencilImage()") == 0) { |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 1570 | error_code = "VUID-vkCmdClearDepthStencilImage-imageLayout-00012"; |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1571 | } else { |
| 1572 | assert(strcmp(func_name, "vkCmdClearColorImage()") == 0); |
| 1573 | } |
Mark Lobodzinski | 0827aec | 2017-03-21 16:41:45 -0600 | [diff] [blame] | 1574 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 1575 | HandleToUint64(image_state->image), error_code, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 1576 | "%s: Layout for cleared image is %s but can only be TRANSFER_DST_OPTIMAL or GENERAL.", func_name, |
| 1577 | string_VkImageLayout(dest_image_layout)); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1578 | } |
| 1579 | } |
| 1580 | |
John Zulauf | f660ad6 | 2019-03-23 07:16:05 -0600 | [diff] [blame] | 1581 | // Cast to const to prevent creation at validate time. |
| 1582 | const auto *subresource_map = GetImageSubresourceLayoutMap(static_cast<const GLOBAL_CB_NODE *>(cb_node), image_state->image); |
| 1583 | if (subresource_map) { |
| 1584 | bool subres_skip = false; |
| 1585 | VkImageSubresourceRange normalized_isr = NormalizeSubresourceRange(*image_state, range); |
| 1586 | auto subres_callback = [this, cb_node, dest_image_layout, func_name, &subres_skip]( |
| 1587 | const VkImageSubresource &subres, VkImageLayout layout, VkImageLayout initial_layout) { |
| 1588 | LayoutUseCheckAndMessage layout_check(dest_image_layout, layout, initial_layout); |
| 1589 | if (layout_check.CheckFailed()) { |
| 1590 | const char *error_code = "VUID-vkCmdClearColorImage-imageLayout-00004"; |
| 1591 | if (strcmp(func_name, "vkCmdClearDepthStencilImage()") == 0) { |
| 1592 | error_code = "VUID-vkCmdClearDepthStencilImage-imageLayout-00011"; |
| 1593 | } else { |
| 1594 | assert(strcmp(func_name, "vkCmdClearColorImage()") == 0); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1595 | } |
John Zulauf | f660ad6 | 2019-03-23 07:16:05 -0600 | [diff] [blame] | 1596 | subres_skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1597 | HandleToUint64(cb_node->commandBuffer), error_code, |
| 1598 | "%s: Cannot clear an image whose layout is %s and doesn't match the %s layout %s.", |
| 1599 | func_name, string_VkImageLayout(dest_image_layout), layout_check.message, |
| 1600 | string_VkImageLayout(layout_check.layout)); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1601 | } |
John Zulauf | f660ad6 | 2019-03-23 07:16:05 -0600 | [diff] [blame] | 1602 | return !subres_skip; |
| 1603 | }; |
| 1604 | subresource_map->ForRange(normalized_isr, subres_callback); |
| 1605 | skip |= subres_skip; |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1606 | } |
| 1607 | |
| 1608 | return skip; |
| 1609 | } |
| 1610 | |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 1611 | bool CoreChecks::PreCallValidateCmdClearColorImage(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, |
| 1612 | const VkClearColorValue *pColor, uint32_t rangeCount, |
| 1613 | const VkImageSubresourceRange *pRanges) { |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1614 | bool skip = false; |
| 1615 | // TODO : Verify memory is in VK_IMAGE_STATE_CLEAR state |
Mark Lobodzinski | 1b3a971 | 2019-03-06 15:51:47 -0700 | [diff] [blame] | 1616 | auto cb_node = GetCBNode(commandBuffer); |
Mark Lobodzinski | 8ddc23f | 2019-03-06 11:48:49 -0700 | [diff] [blame] | 1617 | auto image_state = GetImageState(image); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1618 | if (cb_node && image_state) { |
Mark Lobodzinski | 0ebe971 | 2019-03-07 13:39:07 -0700 | [diff] [blame] | 1619 | skip |= ValidateMemoryIsBoundToImage(image_state, "vkCmdClearColorImage()", "VUID-vkCmdClearColorImage-image-00003"); |
Mark Lobodzinski | daea591 | 2019-03-07 14:47:09 -0700 | [diff] [blame] | 1620 | skip |= ValidateCmdQueueFlags(cb_node, "vkCmdClearColorImage()", VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 1621 | "VUID-vkCmdClearColorImage-commandBuffer-cmdpool"); |
Mark Lobodzinski | fae179e | 2019-03-08 16:47:08 -0700 | [diff] [blame] | 1622 | skip |= ValidateCmd(cb_node, CMD_CLEARCOLORIMAGE, "vkCmdClearColorImage()"); |
Mark Lobodzinski | 96d5c6e | 2019-03-07 11:28:21 -0700 | [diff] [blame] | 1623 | if (GetApiVersion() >= VK_API_VERSION_1_1 || GetDeviceExtensions()->vk_khr_maintenance1) { |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 1624 | skip |= |
| 1625 | ValidateImageFormatFeatureFlags(image_state, VK_FORMAT_FEATURE_TRANSFER_DST_BIT, "vkCmdClearColorImage", |
| 1626 | "VUID-vkCmdClearColorImage-image-01993", "VUID-vkCmdClearColorImage-image-01993"); |
Cort Stratton | 186b1a2 | 2018-05-01 20:18:06 -0400 | [diff] [blame] | 1627 | } |
Mark Lobodzinski | fae179e | 2019-03-08 16:47:08 -0700 | [diff] [blame] | 1628 | skip |= InsideRenderPass(cb_node, "vkCmdClearColorImage()", "VUID-vkCmdClearColorImage-renderpass"); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1629 | for (uint32_t i = 0; i < rangeCount; ++i) { |
Petr Kraus | 4d71868 | 2017-05-18 03:38:41 +0200 | [diff] [blame] | 1630 | std::string param_name = "pRanges[" + std::to_string(i) + "]"; |
Mark Lobodzinski | 9ddb718 | 2019-03-08 17:31:09 -0700 | [diff] [blame] | 1631 | skip |= ValidateCmdClearColorSubresourceRange(image_state, pRanges[i], param_name.c_str()); |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 1632 | skip |= ValidateImageAttributes(image_state, pRanges[i]); |
| 1633 | skip |= VerifyClearImageLayout(cb_node, image_state, pRanges[i], imageLayout, "vkCmdClearColorImage()"); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1634 | } |
| 1635 | } |
| 1636 | return skip; |
| 1637 | } |
| 1638 | |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 1639 | void CoreChecks::PreCallRecordCmdClearColorImage(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, |
| 1640 | const VkClearColorValue *pColor, uint32_t rangeCount, |
| 1641 | const VkImageSubresourceRange *pRanges) { |
Mark Lobodzinski | 1b3a971 | 2019-03-06 15:51:47 -0700 | [diff] [blame] | 1642 | auto cb_node = GetCBNode(commandBuffer); |
Mark Lobodzinski | 8ddc23f | 2019-03-06 11:48:49 -0700 | [diff] [blame] | 1643 | auto image_state = GetImageState(image); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1644 | if (cb_node && image_state) { |
Mark Lobodzinski | fae179e | 2019-03-08 16:47:08 -0700 | [diff] [blame] | 1645 | AddCommandBufferBindingImage(cb_node, image_state); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1646 | for (uint32_t i = 0; i < rangeCount; ++i) { |
John Zulauf | f660ad6 | 2019-03-23 07:16:05 -0600 | [diff] [blame] | 1647 | SetImageInitialLayout(cb_node, image, pRanges[i], imageLayout); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1648 | } |
| 1649 | } |
| 1650 | } |
| 1651 | |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 1652 | bool CoreChecks::PreCallValidateCmdClearDepthStencilImage(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, |
| 1653 | const VkClearDepthStencilValue *pDepthStencil, uint32_t rangeCount, |
| 1654 | const VkImageSubresourceRange *pRanges) { |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1655 | bool skip = false; |
Mark Lobodzinski | 1241a31 | 2017-02-01 10:57:21 -0700 | [diff] [blame] | 1656 | |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1657 | // TODO : Verify memory is in VK_IMAGE_STATE_CLEAR state |
Mark Lobodzinski | 1b3a971 | 2019-03-06 15:51:47 -0700 | [diff] [blame] | 1658 | auto cb_node = GetCBNode(commandBuffer); |
Mark Lobodzinski | 8ddc23f | 2019-03-06 11:48:49 -0700 | [diff] [blame] | 1659 | auto image_state = GetImageState(image); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1660 | if (cb_node && image_state) { |
Mark Lobodzinski | 0ebe971 | 2019-03-07 13:39:07 -0700 | [diff] [blame] | 1661 | skip |= ValidateMemoryIsBoundToImage(image_state, "vkCmdClearDepthStencilImage()", |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 1662 | "VUID-vkCmdClearDepthStencilImage-image-00010"); |
Mark Lobodzinski | daea591 | 2019-03-07 14:47:09 -0700 | [diff] [blame] | 1663 | skip |= ValidateCmdQueueFlags(cb_node, "vkCmdClearDepthStencilImage()", VK_QUEUE_GRAPHICS_BIT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 1664 | "VUID-vkCmdClearDepthStencilImage-commandBuffer-cmdpool"); |
Mark Lobodzinski | fae179e | 2019-03-08 16:47:08 -0700 | [diff] [blame] | 1665 | skip |= ValidateCmd(cb_node, CMD_CLEARDEPTHSTENCILIMAGE, "vkCmdClearDepthStencilImage()"); |
Mark Lobodzinski | 96d5c6e | 2019-03-07 11:28:21 -0700 | [diff] [blame] | 1666 | if (GetApiVersion() >= VK_API_VERSION_1_1 || GetDeviceExtensions()->vk_khr_maintenance1) { |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 1667 | skip |= ValidateImageFormatFeatureFlags(image_state, VK_FORMAT_FEATURE_TRANSFER_DST_BIT, "vkCmdClearDepthStencilImage", |
| 1668 | "VUID-vkCmdClearDepthStencilImage-image-01994", |
Shannon McPherson | 40c0cba | 2018-08-07 13:39:13 -0600 | [diff] [blame] | 1669 | "VUID-vkCmdClearDepthStencilImage-image-01994"); |
Cort Stratton | 186b1a2 | 2018-05-01 20:18:06 -0400 | [diff] [blame] | 1670 | } |
Mark Lobodzinski | fae179e | 2019-03-08 16:47:08 -0700 | [diff] [blame] | 1671 | skip |= InsideRenderPass(cb_node, "vkCmdClearDepthStencilImage()", "VUID-vkCmdClearDepthStencilImage-renderpass"); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1672 | for (uint32_t i = 0; i < rangeCount; ++i) { |
Petr Kraus | 4d71868 | 2017-05-18 03:38:41 +0200 | [diff] [blame] | 1673 | std::string param_name = "pRanges[" + std::to_string(i) + "]"; |
Mark Lobodzinski | 9ddb718 | 2019-03-08 17:31:09 -0700 | [diff] [blame] | 1674 | skip |= ValidateCmdClearDepthSubresourceRange(image_state, pRanges[i], param_name.c_str()); |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 1675 | skip |= VerifyClearImageLayout(cb_node, image_state, pRanges[i], imageLayout, "vkCmdClearDepthStencilImage()"); |
Mark Lobodzinski | 1241a31 | 2017-02-01 10:57:21 -0700 | [diff] [blame] | 1676 | // Image aspect must be depth or stencil or both |
Dave Houlton | 12befb9 | 2018-06-26 17:16:46 -0600 | [diff] [blame] | 1677 | VkImageAspectFlags valid_aspects = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
| 1678 | if (((pRanges[i].aspectMask & valid_aspects) == 0) || ((pRanges[i].aspectMask & ~valid_aspects) != 0)) { |
Mark Lobodzinski | 1241a31 | 2017-02-01 10:57:21 -0700 | [diff] [blame] | 1679 | char const str[] = |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 1680 | "vkCmdClearDepthStencilImage aspectMasks for all subresource ranges must be set to VK_IMAGE_ASPECT_DEPTH_BIT " |
| 1681 | "and/or VK_IMAGE_ASPECT_STENCIL_BIT"; |
Mark Lobodzinski | 1241a31 | 2017-02-01 10:57:21 -0700 | [diff] [blame] | 1682 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Dave Houlton | 5165390 | 2018-06-22 17:32:13 -0600 | [diff] [blame] | 1683 | HandleToUint64(commandBuffer), kVUID_Core_DrawState_InvalidImageAspect, str); |
Mark Lobodzinski | 1241a31 | 2017-02-01 10:57:21 -0700 | [diff] [blame] | 1684 | } |
| 1685 | } |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 1686 | if (image_state && !FormatIsDepthOrStencil(image_state->createInfo.format)) { |
Mark Lobodzinski | 1241a31 | 2017-02-01 10:57:21 -0700 | [diff] [blame] | 1687 | char const str[] = "vkCmdClearDepthStencilImage called without a depth/stencil image."; |
Tobin Ehlis | 3c37fb3 | 2017-05-24 09:31:13 -0600 | [diff] [blame] | 1688 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 1689 | HandleToUint64(image), "VUID-vkCmdClearDepthStencilImage-image-00014", "%s.", str); |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1690 | } |
Tobin Ehlis | 4af8c24 | 2017-11-30 13:47:11 -0700 | [diff] [blame] | 1691 | if (VK_IMAGE_USAGE_TRANSFER_DST_BIT != (VK_IMAGE_USAGE_TRANSFER_DST_BIT & image_state->createInfo.usage)) { |
| 1692 | char const str[] = |
| 1693 | "vkCmdClearDepthStencilImage() called with an image that was not created with the VK_IMAGE_USAGE_TRANSFER_DST_BIT " |
| 1694 | "set."; |
| 1695 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 1696 | HandleToUint64(image), "VUID-vkCmdClearDepthStencilImage-image-00009", "%s.", str); |
Tobin Ehlis | 4af8c24 | 2017-11-30 13:47:11 -0700 | [diff] [blame] | 1697 | } |
Mark Lobodzinski | d81d101 | 2017-02-01 09:03:06 -0700 | [diff] [blame] | 1698 | } |
| 1699 | return skip; |
| 1700 | } |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1701 | |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 1702 | void CoreChecks::PreCallRecordCmdClearDepthStencilImage(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, |
| 1703 | const VkClearDepthStencilValue *pDepthStencil, uint32_t rangeCount, |
| 1704 | const VkImageSubresourceRange *pRanges) { |
Mark Lobodzinski | 1b3a971 | 2019-03-06 15:51:47 -0700 | [diff] [blame] | 1705 | auto cb_node = GetCBNode(commandBuffer); |
Mark Lobodzinski | 8ddc23f | 2019-03-06 11:48:49 -0700 | [diff] [blame] | 1706 | auto image_state = GetImageState(image); |
Mark Lobodzinski | 9a075c2 | 2019-01-10 14:30:39 -0700 | [diff] [blame] | 1707 | if (cb_node && image_state) { |
Mark Lobodzinski | fae179e | 2019-03-08 16:47:08 -0700 | [diff] [blame] | 1708 | AddCommandBufferBindingImage(cb_node, image_state); |
Mark Lobodzinski | 9a075c2 | 2019-01-10 14:30:39 -0700 | [diff] [blame] | 1709 | for (uint32_t i = 0; i < rangeCount; ++i) { |
John Zulauf | f660ad6 | 2019-03-23 07:16:05 -0600 | [diff] [blame] | 1710 | SetImageInitialLayout(cb_node, image, pRanges[i], imageLayout); |
Mark Lobodzinski | 9a075c2 | 2019-01-10 14:30:39 -0700 | [diff] [blame] | 1711 | } |
| 1712 | } |
| 1713 | } |
| 1714 | |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1715 | // Returns true if [x, xoffset] and [y, yoffset] overlap |
| 1716 | static bool RangesIntersect(int32_t start, uint32_t start_offset, int32_t end, uint32_t end_offset) { |
| 1717 | bool result = false; |
| 1718 | uint32_t intersection_min = std::max(static_cast<uint32_t>(start), static_cast<uint32_t>(end)); |
| 1719 | uint32_t intersection_max = std::min(static_cast<uint32_t>(start) + start_offset, static_cast<uint32_t>(end) + end_offset); |
| 1720 | |
| 1721 | if (intersection_max > intersection_min) { |
| 1722 | result = true; |
| 1723 | } |
| 1724 | return result; |
| 1725 | } |
| 1726 | |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 1727 | // Returns true if source area of first copy region intersects dest area of second region |
| 1728 | // It is assumed that these are copy regions within a single image (otherwise no possibility of collision) |
| 1729 | static bool RegionIntersects(const VkImageCopy *rgn0, const VkImageCopy *rgn1, VkImageType type, bool is_multiplane) { |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1730 | bool result = false; |
Dave Houlton | f521761 | 2018-02-02 16:18:52 -0700 | [diff] [blame] | 1731 | |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 1732 | // Separate planes within a multiplane image cannot intersect |
| 1733 | if (is_multiplane && (rgn0->srcSubresource.aspectMask != rgn1->dstSubresource.aspectMask)) { |
Dave Houlton | f521761 | 2018-02-02 16:18:52 -0700 | [diff] [blame] | 1734 | return result; |
| 1735 | } |
| 1736 | |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 1737 | if ((rgn0->srcSubresource.mipLevel == rgn1->dstSubresource.mipLevel) && |
| 1738 | (RangesIntersect(rgn0->srcSubresource.baseArrayLayer, rgn0->srcSubresource.layerCount, rgn1->dstSubresource.baseArrayLayer, |
| 1739 | rgn1->dstSubresource.layerCount))) { |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1740 | result = true; |
| 1741 | switch (type) { |
| 1742 | case VK_IMAGE_TYPE_3D: |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 1743 | result &= RangesIntersect(rgn0->srcOffset.z, rgn0->extent.depth, rgn1->dstOffset.z, rgn1->extent.depth); |
Tobin Ehlis | 648b1cf | 2018-04-13 15:24:13 -0600 | [diff] [blame] | 1744 | // fall through |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1745 | case VK_IMAGE_TYPE_2D: |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 1746 | result &= RangesIntersect(rgn0->srcOffset.y, rgn0->extent.height, rgn1->dstOffset.y, rgn1->extent.height); |
Tobin Ehlis | 648b1cf | 2018-04-13 15:24:13 -0600 | [diff] [blame] | 1747 | // fall through |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1748 | case VK_IMAGE_TYPE_1D: |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 1749 | result &= RangesIntersect(rgn0->srcOffset.x, rgn0->extent.width, rgn1->dstOffset.x, rgn1->extent.width); |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1750 | break; |
| 1751 | default: |
| 1752 | // Unrecognized or new IMAGE_TYPE enums will be caught in parameter_validation |
| 1753 | assert(false); |
| 1754 | } |
| 1755 | } |
| 1756 | return result; |
| 1757 | } |
| 1758 | |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 1759 | // Returns non-zero if offset and extent exceed image extents |
| 1760 | static const uint32_t x_bit = 1; |
| 1761 | static const uint32_t y_bit = 2; |
| 1762 | static const uint32_t z_bit = 4; |
Dave Houlton | 1150cf5 | 2017-04-27 14:38:11 -0600 | [diff] [blame] | 1763 | 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] | 1764 | uint32_t result = 0; |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1765 | // Extents/depths cannot be negative but checks left in for clarity |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 1766 | if ((offset->z + extent->depth > image_extent->depth) || (offset->z < 0) || |
| 1767 | ((offset->z + static_cast<int32_t>(extent->depth)) < 0)) { |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 1768 | result |= z_bit; |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 1769 | } |
| 1770 | if ((offset->y + extent->height > image_extent->height) || (offset->y < 0) || |
| 1771 | ((offset->y + static_cast<int32_t>(extent->height)) < 0)) { |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 1772 | result |= y_bit; |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 1773 | } |
| 1774 | if ((offset->x + extent->width > image_extent->width) || (offset->x < 0) || |
| 1775 | ((offset->x + static_cast<int32_t>(extent->width)) < 0)) { |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 1776 | result |= x_bit; |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 1777 | } |
| 1778 | return result; |
| 1779 | } |
| 1780 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1781 | // Test if two VkExtent3D structs are equivalent |
| 1782 | static inline bool IsExtentEqual(const VkExtent3D *extent, const VkExtent3D *other_extent) { |
| 1783 | bool result = true; |
| 1784 | if ((extent->width != other_extent->width) || (extent->height != other_extent->height) || |
| 1785 | (extent->depth != other_extent->depth)) { |
| 1786 | result = false; |
| 1787 | } |
| 1788 | return result; |
| 1789 | } |
| 1790 | |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 1791 | // For image copies between compressed/uncompressed formats, the extent is provided in source image texels |
| 1792 | // Destination image texel extents must be adjusted by block size for the dest validation checks |
| 1793 | VkExtent3D GetAdjustedDestImageExtent(VkFormat src_format, VkFormat dst_format, VkExtent3D extent) { |
| 1794 | VkExtent3D adjusted_extent = extent; |
| 1795 | if ((FormatIsCompressed(src_format) && (!FormatIsCompressed(dst_format)))) { |
Dave Houlton | a585d13 | 2019-01-18 13:05:42 -0700 | [diff] [blame] | 1796 | VkExtent3D block_size = FormatTexelBlockExtent(src_format); |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 1797 | adjusted_extent.width /= block_size.width; |
| 1798 | adjusted_extent.height /= block_size.height; |
| 1799 | adjusted_extent.depth /= block_size.depth; |
| 1800 | } else if ((!FormatIsCompressed(src_format) && (FormatIsCompressed(dst_format)))) { |
Dave Houlton | a585d13 | 2019-01-18 13:05:42 -0700 | [diff] [blame] | 1801 | VkExtent3D block_size = FormatTexelBlockExtent(dst_format); |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 1802 | adjusted_extent.width *= block_size.width; |
| 1803 | adjusted_extent.height *= block_size.height; |
| 1804 | adjusted_extent.depth *= block_size.depth; |
| 1805 | } |
| 1806 | return adjusted_extent; |
| 1807 | } |
| 1808 | |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1809 | // 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] | 1810 | static inline VkExtent3D GetImageSubresourceExtent(const IMAGE_STATE *img, const VkImageSubresourceLayers *subresource) { |
| 1811 | const uint32_t mip = subresource->mipLevel; |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 1812 | |
| 1813 | // Return zero extent if mip level doesn't exist |
Dave Houlton | 1150cf5 | 2017-04-27 14:38:11 -0600 | [diff] [blame] | 1814 | if (mip >= img->createInfo.mipLevels) { |
| 1815 | return VkExtent3D{0, 0, 0}; |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 1816 | } |
Dave Houlton | 1150cf5 | 2017-04-27 14:38:11 -0600 | [diff] [blame] | 1817 | |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 1818 | // 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] | 1819 | VkExtent3D extent = img->createInfo.extent; |
Jeff Bolz | ef40fec | 2018-09-01 22:04:34 -0500 | [diff] [blame] | 1820 | |
Dave Houlton | e48cd11 | 2019-01-03 17:01:18 -0700 | [diff] [blame] | 1821 | // If multi-plane, adjust per-plane extent |
| 1822 | if (FormatIsMultiplane(img->createInfo.format)) { |
| 1823 | VkExtent2D divisors = FindMultiplaneExtentDivisors(img->createInfo.format, subresource->aspectMask); |
| 1824 | extent.width /= divisors.width; |
| 1825 | extent.height /= divisors.height; |
| 1826 | } |
| 1827 | |
Jeff Bolz | ef40fec | 2018-09-01 22:04:34 -0500 | [diff] [blame] | 1828 | if (img->createInfo.flags & VK_IMAGE_CREATE_CORNER_SAMPLED_BIT_NV) { |
| 1829 | extent.width = (0 == extent.width ? 0 : std::max(2U, 1 + ((extent.width - 1) >> mip))); |
Dave Houlton | 142c4cb | 2018-10-17 15:04:41 -0600 | [diff] [blame] | 1830 | extent.height = (0 == extent.height ? 0 : std::max(2U, 1 + ((extent.height - 1) >> mip))); |
Jeff Bolz | ef40fec | 2018-09-01 22:04:34 -0500 | [diff] [blame] | 1831 | extent.depth = (0 == extent.depth ? 0 : std::max(2U, 1 + ((extent.depth - 1) >> mip))); |
| 1832 | } else { |
| 1833 | extent.width = (0 == extent.width ? 0 : std::max(1U, extent.width >> mip)); |
| 1834 | extent.height = (0 == extent.height ? 0 : std::max(1U, extent.height >> mip)); |
| 1835 | extent.depth = (0 == extent.depth ? 0 : std::max(1U, extent.depth >> mip)); |
| 1836 | } |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 1837 | |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1838 | // Image arrays have an effective z extent that isn't diminished by mip level |
| 1839 | if (VK_IMAGE_TYPE_3D != img->createInfo.imageType) { |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 1840 | extent.depth = img->createInfo.arrayLayers; |
| 1841 | } |
| 1842 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1843 | return extent; |
| 1844 | } |
| 1845 | |
| 1846 | // Test if the extent argument has all dimensions set to 0. |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 1847 | static inline bool IsExtentAllZeroes(const VkExtent3D *extent) { |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1848 | return ((extent->width == 0) && (extent->height == 0) && (extent->depth == 0)); |
| 1849 | } |
| 1850 | |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 1851 | // Test if the extent argument has any dimensions set to 0. |
| 1852 | static inline bool IsExtentSizeZero(const VkExtent3D *extent) { |
| 1853 | return ((extent->width == 0) || (extent->height == 0) || (extent->depth == 0)); |
| 1854 | } |
| 1855 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1856 | // Returns the image transfer granularity for a specific image scaled by compressed block size if necessary. |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 1857 | VkExtent3D CoreChecks::GetScaledItg(const GLOBAL_CB_NODE *cb_node, const IMAGE_STATE *img) { |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1858 | // Default to (0, 0, 0) granularity in case we can't find the real granularity for the physical device. |
| 1859 | VkExtent3D granularity = {0, 0, 0}; |
Mark Lobodzinski | 8b0a7b8 | 2019-03-06 16:17:45 -0700 | [diff] [blame] | 1860 | auto pPool = GetCommandPoolNode(cb_node->createInfo.commandPool); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1861 | if (pPool) { |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 1862 | granularity = GetPhysicalDeviceState()->queue_family_properties[pPool->queueFamilyIndex].minImageTransferGranularity; |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 1863 | if (FormatIsCompressed(img->createInfo.format)) { |
Dave Houlton | a585d13 | 2019-01-18 13:05:42 -0700 | [diff] [blame] | 1864 | auto block_size = FormatTexelBlockExtent(img->createInfo.format); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1865 | granularity.width *= block_size.width; |
| 1866 | granularity.height *= block_size.height; |
| 1867 | } |
| 1868 | } |
| 1869 | return granularity; |
| 1870 | } |
| 1871 | |
| 1872 | // Test elements of a VkExtent3D structure against alignment constraints contained in another VkExtent3D structure |
| 1873 | static inline bool IsExtentAligned(const VkExtent3D *extent, const VkExtent3D *granularity) { |
| 1874 | bool valid = true; |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 1875 | if ((SafeModulo(extent->depth, granularity->depth) != 0) || (SafeModulo(extent->width, granularity->width) != 0) || |
| 1876 | (SafeModulo(extent->height, granularity->height) != 0)) { |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1877 | valid = false; |
| 1878 | } |
| 1879 | return valid; |
| 1880 | } |
| 1881 | |
| 1882 | // Check elements of a VkOffset3D structure against a queue family's Image Transfer Granularity values |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 1883 | bool CoreChecks::CheckItgOffset(const GLOBAL_CB_NODE *cb_node, const VkOffset3D *offset, const VkExtent3D *granularity, |
| 1884 | const uint32_t i, const char *function, const char *member, const char *vuid) { |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1885 | bool skip = false; |
| 1886 | VkExtent3D offset_extent = {}; |
| 1887 | offset_extent.width = static_cast<uint32_t>(abs(offset->x)); |
| 1888 | offset_extent.height = static_cast<uint32_t>(abs(offset->y)); |
| 1889 | offset_extent.depth = static_cast<uint32_t>(abs(offset->z)); |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 1890 | if (IsExtentAllZeroes(granularity)) { |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1891 | // 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] | 1892 | if (IsExtentAllZeroes(&offset_extent) == false) { |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 1893 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Cort Stratton | 420ebd4 | 2018-05-04 01:12:23 -0400 | [diff] [blame] | 1894 | HandleToUint64(cb_node->commandBuffer), vuid, |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 1895 | "%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 " |
| 1896 | "image transfer granularity is (w=0, h=0, d=0).", |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 1897 | function, i, member, offset->x, offset->y, offset->z); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1898 | } |
| 1899 | } else { |
| 1900 | // If the queue family image transfer granularity is not (0, 0, 0), then the offset dimensions must always be even |
| 1901 | // integer multiples of the image transfer granularity. |
| 1902 | if (IsExtentAligned(&offset_extent, granularity) == false) { |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 1903 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Cort Stratton | 420ebd4 | 2018-05-04 01:12:23 -0400 | [diff] [blame] | 1904 | HandleToUint64(cb_node->commandBuffer), vuid, |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 1905 | "%s: pRegion[%d].%s (x=%d, y=%d, z=%d) dimensions must be even integer multiples of this command " |
| 1906 | "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] | 1907 | function, i, member, offset->x, offset->y, offset->z, granularity->width, granularity->height, |
| 1908 | granularity->depth); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1909 | } |
| 1910 | } |
| 1911 | return skip; |
| 1912 | } |
| 1913 | |
| 1914 | // Check elements of a VkExtent3D structure against a queue family's Image Transfer Granularity values |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 1915 | bool CoreChecks::CheckItgExtent(const GLOBAL_CB_NODE *cb_node, const VkExtent3D *extent, const VkOffset3D *offset, |
| 1916 | const VkExtent3D *granularity, const VkExtent3D *subresource_extent, const VkImageType image_type, |
| 1917 | const uint32_t i, const char *function, const char *member, const char *vuid) { |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1918 | bool skip = false; |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 1919 | if (IsExtentAllZeroes(granularity)) { |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1920 | // If the queue family image transfer granularity is (0, 0, 0), then the extent must always match the image |
| 1921 | // subresource extent. |
| 1922 | if (IsExtentEqual(extent, subresource_extent) == false) { |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 1923 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Cort Stratton | 420ebd4 | 2018-05-04 01:12:23 -0400 | [diff] [blame] | 1924 | HandleToUint64(cb_node->commandBuffer), vuid, |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 1925 | "%s: pRegion[%d].%s (w=%d, h=%d, d=%d) must match the image subresource extents (w=%d, h=%d, d=%d) " |
| 1926 | "when the command buffer's queue family image transfer granularity is (w=0, h=0, d=0).", |
| 1927 | function, i, member, extent->width, extent->height, extent->depth, subresource_extent->width, |
| 1928 | subresource_extent->height, subresource_extent->depth); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1929 | } |
| 1930 | } else { |
| 1931 | // If the queue family image transfer granularity is not (0, 0, 0), then the extent dimensions must always be even |
| 1932 | // integer multiples of the image transfer granularity or the offset + extent dimensions must always match the image |
| 1933 | // subresource extent dimensions. |
| 1934 | VkExtent3D offset_extent_sum = {}; |
| 1935 | offset_extent_sum.width = static_cast<uint32_t>(abs(offset->x)) + extent->width; |
| 1936 | offset_extent_sum.height = static_cast<uint32_t>(abs(offset->y)) + extent->height; |
| 1937 | 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] | 1938 | bool x_ok = true; |
| 1939 | bool y_ok = true; |
| 1940 | bool z_ok = true; |
| 1941 | switch (image_type) { |
| 1942 | case VK_IMAGE_TYPE_3D: |
| 1943 | z_ok = ((0 == SafeModulo(extent->depth, granularity->depth)) || |
| 1944 | (subresource_extent->depth == offset_extent_sum.depth)); |
Tobin Ehlis | 648b1cf | 2018-04-13 15:24:13 -0600 | [diff] [blame] | 1945 | // fall through |
Mark Lobodzinski | 283ade6 | 2017-10-09 16:36:49 -0600 | [diff] [blame] | 1946 | case VK_IMAGE_TYPE_2D: |
| 1947 | y_ok = ((0 == SafeModulo(extent->height, granularity->height)) || |
| 1948 | (subresource_extent->height == offset_extent_sum.height)); |
Tobin Ehlis | 648b1cf | 2018-04-13 15:24:13 -0600 | [diff] [blame] | 1949 | // fall through |
Mark Lobodzinski | 283ade6 | 2017-10-09 16:36:49 -0600 | [diff] [blame] | 1950 | case VK_IMAGE_TYPE_1D: |
| 1951 | x_ok = ((0 == SafeModulo(extent->width, granularity->width)) || |
| 1952 | (subresource_extent->width == offset_extent_sum.width)); |
| 1953 | break; |
| 1954 | default: |
| 1955 | // Unrecognized or new IMAGE_TYPE enums will be caught in parameter_validation |
| 1956 | assert(false); |
| 1957 | } |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 1958 | if (!(x_ok && y_ok && z_ok)) { |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 1959 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Cort Stratton | 420ebd4 | 2018-05-04 01:12:23 -0400 | [diff] [blame] | 1960 | HandleToUint64(cb_node->commandBuffer), vuid, |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 1961 | "%s: pRegion[%d].%s (w=%d, h=%d, d=%d) dimensions must be even integer multiples of this command " |
| 1962 | "buffer's queue family image transfer granularity (w=%d, h=%d, d=%d) or offset (x=%d, y=%d, z=%d) + " |
| 1963 | "extent (w=%d, h=%d, d=%d) must match the image subresource extents (w=%d, h=%d, d=%d).", |
| 1964 | function, i, member, extent->width, extent->height, extent->depth, granularity->width, |
| 1965 | granularity->height, granularity->depth, offset->x, offset->y, offset->z, extent->width, extent->height, |
| 1966 | extent->depth, subresource_extent->width, subresource_extent->height, subresource_extent->depth); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 1967 | } |
| 1968 | } |
| 1969 | return skip; |
| 1970 | } |
| 1971 | |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 1972 | bool CoreChecks::ValidateImageMipLevel(const GLOBAL_CB_NODE *cb_node, const IMAGE_STATE *img, uint32_t mip_level, const uint32_t i, |
| 1973 | const char *function, const char *member, const char *vuid) { |
Cort Stratton | ff1542a | 2018-05-27 10:49:28 -0700 | [diff] [blame] | 1974 | bool skip = false; |
| 1975 | if (mip_level >= img->createInfo.mipLevels) { |
| 1976 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1977 | HandleToUint64(cb_node->commandBuffer), vuid, |
Locke | e9aeebf | 2019-03-03 23:50:08 -0700 | [diff] [blame] | 1978 | "In %s, pRegions[%u].%s.mipLevel is %u, but provided image %s has %u mip levels.", function, i, member, |
| 1979 | mip_level, report_data->FormatHandle(img->image).c_str(), img->createInfo.mipLevels); |
Cort Stratton | ff1542a | 2018-05-27 10:49:28 -0700 | [diff] [blame] | 1980 | } |
| 1981 | return skip; |
| 1982 | } |
| 1983 | |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 1984 | bool CoreChecks::ValidateImageArrayLayerRange(const GLOBAL_CB_NODE *cb_node, const IMAGE_STATE *img, const uint32_t base_layer, |
| 1985 | const uint32_t layer_count, const uint32_t i, const char *function, |
| 1986 | const char *member, const char *vuid) { |
Cort Stratton | ff1542a | 2018-05-27 10:49:28 -0700 | [diff] [blame] | 1987 | bool skip = false; |
| 1988 | if (base_layer >= img->createInfo.arrayLayers || layer_count > img->createInfo.arrayLayers || |
| 1989 | (base_layer + layer_count) > img->createInfo.arrayLayers) { |
| 1990 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 1991 | HandleToUint64(cb_node->commandBuffer), vuid, |
| 1992 | "In %s, pRegions[%u].%s.baseArrayLayer is %u and .layerCount is " |
Locke | e9aeebf | 2019-03-03 23:50:08 -0700 | [diff] [blame] | 1993 | "%u, but provided image %s has %u array layers.", |
| 1994 | function, i, member, base_layer, layer_count, report_data->FormatHandle(img->image).c_str(), |
| 1995 | img->createInfo.arrayLayers); |
Cort Stratton | ff1542a | 2018-05-27 10:49:28 -0700 | [diff] [blame] | 1996 | } |
| 1997 | return skip; |
| 1998 | } |
| 1999 | |
Mark Lobodzinski | bf0042d | 2018-02-26 16:01:22 -0700 | [diff] [blame] | 2000 | // Check valid usage Image Transfer Granularity requirements for elements of a VkBufferImageCopy structure |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 2001 | bool CoreChecks::ValidateCopyBufferImageTransferGranularityRequirements(const GLOBAL_CB_NODE *cb_node, const IMAGE_STATE *img, |
| 2002 | const VkBufferImageCopy *region, const uint32_t i, |
| 2003 | const char *function, const char *vuid) { |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 2004 | bool skip = false; |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 2005 | VkExtent3D granularity = GetScaledItg(cb_node, img); |
| 2006 | skip |= CheckItgOffset(cb_node, ®ion->imageOffset, &granularity, i, function, "imageOffset", vuid); |
Cort Stratton | 420ebd4 | 2018-05-04 01:12:23 -0400 | [diff] [blame] | 2007 | VkExtent3D subresource_extent = GetImageSubresourceExtent(img, ®ion->imageSubresource); |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 2008 | skip |= CheckItgExtent(cb_node, ®ion->imageExtent, ®ion->imageOffset, &granularity, &subresource_extent, |
Cort Stratton | 420ebd4 | 2018-05-04 01:12:23 -0400 | [diff] [blame] | 2009 | img->createInfo.imageType, i, function, "imageExtent", vuid); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 2010 | return skip; |
| 2011 | } |
| 2012 | |
Mark Lobodzinski | bf0042d | 2018-02-26 16:01:22 -0700 | [diff] [blame] | 2013 | // Check valid usage Image Transfer Granularity requirements for elements of a VkImageCopy structure |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 2014 | bool CoreChecks::ValidateCopyImageTransferGranularityRequirements(const GLOBAL_CB_NODE *cb_node, const IMAGE_STATE *src_img, |
| 2015 | const IMAGE_STATE *dst_img, const VkImageCopy *region, |
| 2016 | const uint32_t i, const char *function) { |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 2017 | bool skip = false; |
Mark Lobodzinski | d078880 | 2017-10-19 15:38:59 -0600 | [diff] [blame] | 2018 | // Source image checks |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 2019 | VkExtent3D granularity = GetScaledItg(cb_node, src_img); |
| 2020 | skip |= |
| 2021 | CheckItgOffset(cb_node, ®ion->srcOffset, &granularity, i, function, "srcOffset", "VUID-vkCmdCopyImage-srcOffset-01783"); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 2022 | VkExtent3D subresource_extent = GetImageSubresourceExtent(src_img, ®ion->srcSubresource); |
Dave Houlton | 94a0037 | 2017-12-14 15:08:47 -0700 | [diff] [blame] | 2023 | const VkExtent3D extent = region->extent; |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 2024 | skip |= CheckItgExtent(cb_node, &extent, ®ion->srcOffset, &granularity, &subresource_extent, src_img->createInfo.imageType, |
| 2025 | i, function, "extent", "VUID-vkCmdCopyImage-srcOffset-01783"); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 2026 | |
Mark Lobodzinski | d078880 | 2017-10-19 15:38:59 -0600 | [diff] [blame] | 2027 | // Destination image checks |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 2028 | granularity = GetScaledItg(cb_node, dst_img); |
| 2029 | skip |= |
| 2030 | CheckItgOffset(cb_node, ®ion->dstOffset, &granularity, i, function, "dstOffset", "VUID-vkCmdCopyImage-dstOffset-01784"); |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 2031 | // Adjust dest extent, if necessary |
Dave Houlton | 94a0037 | 2017-12-14 15:08:47 -0700 | [diff] [blame] | 2032 | const VkExtent3D dest_effective_extent = |
| 2033 | GetAdjustedDestImageExtent(src_img->createInfo.format, dst_img->createInfo.format, extent); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 2034 | subresource_extent = GetImageSubresourceExtent(dst_img, ®ion->dstSubresource); |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 2035 | skip |= CheckItgExtent(cb_node, &dest_effective_extent, ®ion->dstOffset, &granularity, &subresource_extent, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 2036 | dst_img->createInfo.imageType, i, function, "extent", "VUID-vkCmdCopyImage-dstOffset-01784"); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 2037 | return skip; |
| 2038 | } |
| 2039 | |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 2040 | // Validate contents of a VkImageCopy struct |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 2041 | bool CoreChecks::ValidateImageCopyData(const uint32_t regionCount, const VkImageCopy *ic_regions, const IMAGE_STATE *src_state, |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 2042 | const IMAGE_STATE *dst_state) { |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 2043 | bool skip = false; |
| 2044 | |
| 2045 | for (uint32_t i = 0; i < regionCount; i++) { |
Dave Houlton | 94a0037 | 2017-12-14 15:08:47 -0700 | [diff] [blame] | 2046 | const VkImageCopy region = ic_regions[i]; |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 2047 | |
| 2048 | // 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] | 2049 | const VkExtent3D src_copy_extent = region.extent; |
| 2050 | const VkExtent3D dst_copy_extent = |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 2051 | GetAdjustedDestImageExtent(src_state->createInfo.format, dst_state->createInfo.format, region.extent); |
| 2052 | |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 2053 | bool slice_override = false; |
| 2054 | uint32_t depth_slices = 0; |
| 2055 | |
| 2056 | // Special case for copying between a 1D/2D array and a 3D image |
| 2057 | // TBD: This seems like the only way to reconcile 3 mutually-exclusive VU checks for 2D/3D copies. Heads up. |
| 2058 | 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] | 2059 | depth_slices = region.dstSubresource.layerCount; // Slice count from 2D subresource |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 2060 | slice_override = (depth_slices != 1); |
| 2061 | } 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] | 2062 | depth_slices = region.srcSubresource.layerCount; // Slice count from 2D subresource |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 2063 | slice_override = (depth_slices != 1); |
| 2064 | } |
| 2065 | |
| 2066 | // Do all checks on source image |
| 2067 | // |
| 2068 | if (src_state->createInfo.imageType == VK_IMAGE_TYPE_1D) { |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 2069 | if ((0 != region.srcOffset.y) || (1 != src_copy_extent.height)) { |
| 2070 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 2071 | HandleToUint64(src_state->image), "VUID-VkImageCopy-srcImage-00146", |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 2072 | "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] | 2073 | "be 0 and 1, respectively.", |
| 2074 | i, region.srcOffset.y, src_copy_extent.height); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 2075 | } |
| 2076 | } |
| 2077 | |
Dave Houlton | 533be9f | 2018-03-26 17:08:30 -0600 | [diff] [blame] | 2078 | // VUID-VkImageCopy-srcImage-01785 |
| 2079 | if ((src_state->createInfo.imageType == VK_IMAGE_TYPE_1D) && ((0 != region.srcOffset.z) || (1 != src_copy_extent.depth))) { |
| 2080 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 2081 | HandleToUint64(src_state->image), "VUID-VkImageCopy-srcImage-01785", |
Dave Houlton | 533be9f | 2018-03-26 17:08:30 -0600 | [diff] [blame] | 2082 | "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] | 2083 | "these must be 0 and 1, respectively.", |
| 2084 | i, region.srcOffset.z, src_copy_extent.depth); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 2085 | } |
| 2086 | |
Dave Houlton | 533be9f | 2018-03-26 17:08:30 -0600 | [diff] [blame] | 2087 | // VUID-VkImageCopy-srcImage-01787 |
| 2088 | if ((src_state->createInfo.imageType == VK_IMAGE_TYPE_2D) && (0 != region.srcOffset.z)) { |
| 2089 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 2090 | HandleToUint64(src_state->image), "VUID-VkImageCopy-srcImage-01787", |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2091 | "vkCmdCopyImage(): pRegion[%d] srcOffset.z is %d. For 2D images the z-offset must be 0.", i, |
| 2092 | region.srcOffset.z); |
Dave Houlton | 533be9f | 2018-03-26 17:08:30 -0600 | [diff] [blame] | 2093 | } |
| 2094 | |
Mark Lobodzinski | 60e7903 | 2019-03-07 10:22:31 -0700 | [diff] [blame] | 2095 | if (GetDeviceExtensions()->vk_khr_maintenance1) { |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 2096 | if (src_state->createInfo.imageType == VK_IMAGE_TYPE_3D) { |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 2097 | if ((0 != region.srcSubresource.baseArrayLayer) || (1 != region.srcSubresource.layerCount)) { |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 2098 | skip |= |
| 2099 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 2100 | HandleToUint64(src_state->image), "VUID-VkImageCopy-srcImage-00141", |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 2101 | "vkCmdCopyImage(): pRegion[%d] srcSubresource.baseArrayLayer is %d and srcSubresource.layerCount " |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2102 | "is %d. For VK_IMAGE_TYPE_3D images these must be 0 and 1, respectively.", |
| 2103 | i, region.srcSubresource.baseArrayLayer, region.srcSubresource.layerCount); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 2104 | } |
| 2105 | } |
| 2106 | } else { // Pre maint 1 |
| 2107 | 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] | 2108 | if ((0 != region.srcSubresource.baseArrayLayer) || (1 != region.srcSubresource.layerCount)) { |
Petr Kraus | 13c98a6 | 2017-12-09 00:22:39 +0100 | [diff] [blame] | 2109 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 2110 | HandleToUint64(src_state->image), "VUID-VkImageCopy-srcImage-00141", |
Petr Kraus | 13c98a6 | 2017-12-09 00:22:39 +0100 | [diff] [blame] | 2111 | "vkCmdCopyImage(): pRegion[%d] srcSubresource.baseArrayLayer is %d and " |
| 2112 | "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] | 2113 | "VK_IMAGE_TYPE_3D, these must be 0 and 1, respectively.", |
| 2114 | i, region.srcSubresource.baseArrayLayer, region.srcSubresource.layerCount); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 2115 | } |
| 2116 | } |
| 2117 | } |
| 2118 | |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 2119 | // Source checks that apply only to compressed images (or to _422 images if ycbcr enabled) |
Mark Lobodzinski | 60e7903 | 2019-03-07 10:22:31 -0700 | [diff] [blame] | 2120 | bool ext_ycbcr = GetDeviceExtensions()->vk_khr_sampler_ycbcr_conversion; |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 2121 | if (FormatIsCompressed(src_state->createInfo.format) || |
| 2122 | (ext_ycbcr && FormatIsSinglePlane_422(src_state->createInfo.format))) { |
Dave Houlton | a585d13 | 2019-01-18 13:05:42 -0700 | [diff] [blame] | 2123 | const VkExtent3D block_size = FormatTexelBlockExtent(src_state->createInfo.format); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 2124 | // image offsets must be multiples of block dimensions |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 2125 | if ((SafeModulo(region.srcOffset.x, block_size.width) != 0) || |
| 2126 | (SafeModulo(region.srcOffset.y, block_size.height) != 0) || |
| 2127 | (SafeModulo(region.srcOffset.z, block_size.depth) != 0)) { |
Jeff Bolz | 6d3beaa | 2019-02-09 21:00:05 -0600 | [diff] [blame] | 2128 | const char *vuid = ext_ycbcr ? "VUID-VkImageCopy-srcImage-01727" : "VUID-VkImageCopy-srcOffset-00157"; |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 2129 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 2130 | HandleToUint64(src_state->image), vuid, |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 2131 | "vkCmdCopyImage(): pRegion[%d] srcOffset (%d, %d) must be multiples of the compressed image's " |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 2132 | "texel width & height (%d, %d).", |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2133 | 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] | 2134 | } |
| 2135 | |
Dave Houlton | 94a0037 | 2017-12-14 15:08:47 -0700 | [diff] [blame] | 2136 | const VkExtent3D mip_extent = GetImageSubresourceExtent(src_state, &(region.srcSubresource)); |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 2137 | if ((SafeModulo(src_copy_extent.width, block_size.width) != 0) && |
| 2138 | (src_copy_extent.width + region.srcOffset.x != mip_extent.width)) { |
Jeff Bolz | 6d3beaa | 2019-02-09 21:00:05 -0600 | [diff] [blame] | 2139 | const char *vuid = ext_ycbcr ? "VUID-VkImageCopy-srcImage-01728" : "VUID-VkImageCopy-extent-00158"; |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 2140 | skip |= |
| 2141 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 2142 | HandleToUint64(src_state->image), vuid, |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 2143 | "vkCmdCopyImage(): pRegion[%d] extent width (%d) must be a multiple of the compressed texture block " |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 2144 | "width (%d), or when added to srcOffset.x (%d) must equal the image subresource width (%d).", |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2145 | 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] | 2146 | } |
| 2147 | |
Mark Lobodzinski | d078880 | 2017-10-19 15:38:59 -0600 | [diff] [blame] | 2148 | // 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] | 2149 | if ((SafeModulo(src_copy_extent.height, block_size.height) != 0) && |
| 2150 | (src_copy_extent.height + region.srcOffset.y != mip_extent.height)) { |
Jeff Bolz | 6d3beaa | 2019-02-09 21:00:05 -0600 | [diff] [blame] | 2151 | const char *vuid = ext_ycbcr ? "VUID-VkImageCopy-srcImage-01729" : "VUID-VkImageCopy-extent-00159"; |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 2152 | skip |= |
| 2153 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 2154 | HandleToUint64(src_state->image), vuid, |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 2155 | "vkCmdCopyImage(): pRegion[%d] extent height (%d) must be a multiple of the compressed texture block " |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 2156 | "height (%d), or when added to srcOffset.y (%d) must equal the image subresource height (%d).", |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2157 | 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] | 2158 | } |
| 2159 | |
Mark Lobodzinski | d078880 | 2017-10-19 15:38:59 -0600 | [diff] [blame] | 2160 | // 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] | 2161 | uint32_t copy_depth = (slice_override ? depth_slices : src_copy_extent.depth); |
| 2162 | if ((SafeModulo(copy_depth, block_size.depth) != 0) && (copy_depth + region.srcOffset.z != mip_extent.depth)) { |
Jeff Bolz | 6d3beaa | 2019-02-09 21:00:05 -0600 | [diff] [blame] | 2163 | const char *vuid = ext_ycbcr ? "VUID-VkImageCopy-srcImage-01730" : "VUID-VkImageCopy-extent-00160"; |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 2164 | skip |= |
| 2165 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 2166 | HandleToUint64(src_state->image), vuid, |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 2167 | "vkCmdCopyImage(): pRegion[%d] extent width (%d) must be a multiple of the compressed texture block " |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 2168 | "depth (%d), or when added to srcOffset.z (%d) must equal the image subresource depth (%d).", |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2169 | 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] | 2170 | } |
| 2171 | } // Compressed |
| 2172 | |
| 2173 | // Do all checks on dest image |
| 2174 | // |
| 2175 | if (dst_state->createInfo.imageType == VK_IMAGE_TYPE_1D) { |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 2176 | if ((0 != region.dstOffset.y) || (1 != dst_copy_extent.height)) { |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 2177 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 2178 | HandleToUint64(dst_state->image), "VUID-VkImageCopy-dstImage-00152", |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 2179 | "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] | 2180 | "these must be 0 and 1, respectively.", |
| 2181 | i, region.dstOffset.y, dst_copy_extent.height); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 2182 | } |
| 2183 | } |
| 2184 | |
Dave Houlton | 533be9f | 2018-03-26 17:08:30 -0600 | [diff] [blame] | 2185 | // VUID-VkImageCopy-dstImage-01786 |
| 2186 | if ((dst_state->createInfo.imageType == VK_IMAGE_TYPE_1D) && ((0 != region.dstOffset.z) || (1 != dst_copy_extent.depth))) { |
| 2187 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 2188 | HandleToUint64(dst_state->image), "VUID-VkImageCopy-dstImage-01786", |
Dave Houlton | 533be9f | 2018-03-26 17:08:30 -0600 | [diff] [blame] | 2189 | "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] | 2190 | "and 1, respectively.", |
| 2191 | i, region.dstOffset.z, dst_copy_extent.depth); |
Dave Houlton | 533be9f | 2018-03-26 17:08:30 -0600 | [diff] [blame] | 2192 | } |
| 2193 | |
| 2194 | // VUID-VkImageCopy-dstImage-01788 |
| 2195 | if ((dst_state->createInfo.imageType == VK_IMAGE_TYPE_2D) && (0 != region.dstOffset.z)) { |
| 2196 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 2197 | HandleToUint64(dst_state->image), "VUID-VkImageCopy-dstImage-01788", |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2198 | "vkCmdCopyImage(): pRegion[%d] dstOffset.z is %d. For 2D images the z-offset must be 0.", i, |
| 2199 | region.dstOffset.z); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 2200 | } |
| 2201 | |
| 2202 | if (dst_state->createInfo.imageType == VK_IMAGE_TYPE_3D) { |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 2203 | if ((0 != region.dstSubresource.baseArrayLayer) || (1 != region.dstSubresource.layerCount)) { |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 2204 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 2205 | HandleToUint64(dst_state->image), "VUID-VkImageCopy-srcImage-00141", |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 2206 | "vkCmdCopyImage(): pRegion[%d] dstSubresource.baseArrayLayer is %d and dstSubresource.layerCount " |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2207 | "is %d. For VK_IMAGE_TYPE_3D images these must be 0 and 1, respectively.", |
| 2208 | i, region.dstSubresource.baseArrayLayer, region.dstSubresource.layerCount); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 2209 | } |
| 2210 | } |
| 2211 | // VU01199 changed with mnt1 |
Mark Lobodzinski | 60e7903 | 2019-03-07 10:22:31 -0700 | [diff] [blame] | 2212 | if (GetDeviceExtensions()->vk_khr_maintenance1) { |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 2213 | if (dst_state->createInfo.imageType == VK_IMAGE_TYPE_3D) { |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 2214 | if ((0 != region.dstSubresource.baseArrayLayer) || (1 != region.dstSubresource.layerCount)) { |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 2215 | skip |= |
| 2216 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 2217 | HandleToUint64(dst_state->image), "VUID-VkImageCopy-srcImage-00141", |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 2218 | "vkCmdCopyImage(): pRegion[%d] dstSubresource.baseArrayLayer is %d and dstSubresource.layerCount " |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2219 | "is %d. For VK_IMAGE_TYPE_3D images these must be 0 and 1, respectively.", |
| 2220 | i, region.dstSubresource.baseArrayLayer, region.dstSubresource.layerCount); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 2221 | } |
| 2222 | } |
| 2223 | } else { // Pre maint 1 |
| 2224 | 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] | 2225 | if ((0 != region.dstSubresource.baseArrayLayer) || (1 != region.dstSubresource.layerCount)) { |
Petr Kraus | 13c98a6 | 2017-12-09 00:22:39 +0100 | [diff] [blame] | 2226 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 2227 | HandleToUint64(dst_state->image), "VUID-VkImageCopy-srcImage-00141", |
Petr Kraus | 13c98a6 | 2017-12-09 00:22:39 +0100 | [diff] [blame] | 2228 | "vkCmdCopyImage(): pRegion[%d] dstSubresource.baseArrayLayer is %d and " |
| 2229 | "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] | 2230 | "VK_IMAGE_TYPE_3D, these must be 0 and 1, respectively.", |
| 2231 | i, region.dstSubresource.baseArrayLayer, region.dstSubresource.layerCount); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 2232 | } |
| 2233 | } |
| 2234 | } |
| 2235 | |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 2236 | // Dest checks that apply only to compressed images (or to _422 images if ycbcr enabled) |
| 2237 | if (FormatIsCompressed(dst_state->createInfo.format) || |
| 2238 | (ext_ycbcr && FormatIsSinglePlane_422(dst_state->createInfo.format))) { |
Dave Houlton | a585d13 | 2019-01-18 13:05:42 -0700 | [diff] [blame] | 2239 | const VkExtent3D block_size = FormatTexelBlockExtent(dst_state->createInfo.format); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 2240 | |
| 2241 | // image offsets must be multiples of block dimensions |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 2242 | if ((SafeModulo(region.dstOffset.x, block_size.width) != 0) || |
| 2243 | (SafeModulo(region.dstOffset.y, block_size.height) != 0) || |
| 2244 | (SafeModulo(region.dstOffset.z, block_size.depth) != 0)) { |
Jeff Bolz | 6d3beaa | 2019-02-09 21:00:05 -0600 | [diff] [blame] | 2245 | const char *vuid = ext_ycbcr ? "VUID-VkImageCopy-dstImage-01731" : "VUID-VkImageCopy-dstOffset-00162"; |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 2246 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 2247 | HandleToUint64(dst_state->image), vuid, |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 2248 | "vkCmdCopyImage(): pRegion[%d] dstOffset (%d, %d) must be multiples of the compressed image's " |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 2249 | "texel width & height (%d, %d).", |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2250 | 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] | 2251 | } |
| 2252 | |
Dave Houlton | 94a0037 | 2017-12-14 15:08:47 -0700 | [diff] [blame] | 2253 | const VkExtent3D mip_extent = GetImageSubresourceExtent(dst_state, &(region.dstSubresource)); |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 2254 | if ((SafeModulo(dst_copy_extent.width, block_size.width) != 0) && |
| 2255 | (dst_copy_extent.width + region.dstOffset.x != mip_extent.width)) { |
Jeff Bolz | 6d3beaa | 2019-02-09 21:00:05 -0600 | [diff] [blame] | 2256 | const char *vuid = ext_ycbcr ? "VUID-VkImageCopy-dstImage-01732" : "VUID-VkImageCopy-extent-00163"; |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 2257 | skip |= |
| 2258 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 2259 | HandleToUint64(dst_state->image), vuid, |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 2260 | "vkCmdCopyImage(): pRegion[%d] dst_copy_extent width (%d) must be a multiple of the compressed texture " |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 2261 | "block width (%d), or when added to dstOffset.x (%d) must equal the image subresource width (%d).", |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2262 | 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] | 2263 | } |
| 2264 | |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 2265 | // Extent height must be a multiple of block height, or dst_copy_extent+offset height must equal subresource height |
| 2266 | if ((SafeModulo(dst_copy_extent.height, block_size.height) != 0) && |
| 2267 | (dst_copy_extent.height + region.dstOffset.y != mip_extent.height)) { |
Jeff Bolz | 6d3beaa | 2019-02-09 21:00:05 -0600 | [diff] [blame] | 2268 | const char *vuid = ext_ycbcr ? "VUID-VkImageCopy-dstImage-01733" : "VUID-VkImageCopy-extent-00164"; |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 2269 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 2270 | HandleToUint64(dst_state->image), vuid, |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 2271 | "vkCmdCopyImage(): pRegion[%d] dst_copy_extent height (%d) must be a multiple of the compressed " |
| 2272 | "texture block height (%d), or when added to dstOffset.y (%d) must equal the image subresource " |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 2273 | "height (%d).", |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2274 | 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] | 2275 | } |
| 2276 | |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 2277 | // Extent depth must be a multiple of block depth, or dst_copy_extent+offset depth must equal subresource depth |
| 2278 | uint32_t copy_depth = (slice_override ? depth_slices : dst_copy_extent.depth); |
| 2279 | if ((SafeModulo(copy_depth, block_size.depth) != 0) && (copy_depth + region.dstOffset.z != mip_extent.depth)) { |
Jeff Bolz | 6d3beaa | 2019-02-09 21:00:05 -0600 | [diff] [blame] | 2280 | const char *vuid = ext_ycbcr ? "VUID-VkImageCopy-dstImage-01734" : "VUID-VkImageCopy-extent-00165"; |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 2281 | skip |= |
| 2282 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 2283 | HandleToUint64(dst_state->image), vuid, |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 2284 | "vkCmdCopyImage(): pRegion[%d] dst_copy_extent width (%d) must be a multiple of the compressed texture " |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 2285 | "block depth (%d), or when added to dstOffset.z (%d) must equal the image subresource depth (%d).", |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2286 | 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] | 2287 | } |
| 2288 | } // Compressed |
| 2289 | } |
| 2290 | return skip; |
| 2291 | } |
| 2292 | |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 2293 | // vkCmdCopyImage checks that only apply if the multiplane extension is enabled |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 2294 | bool CoreChecks::CopyImageMultiplaneValidation(VkCommandBuffer command_buffer, const IMAGE_STATE *src_image_state, |
| 2295 | const IMAGE_STATE *dst_image_state, const VkImageCopy region) { |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 2296 | bool skip = false; |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 2297 | |
| 2298 | // Neither image is multiplane |
| 2299 | if ((!FormatIsMultiplane(src_image_state->createInfo.format)) && (!FormatIsMultiplane(dst_image_state->createInfo.format))) { |
| 2300 | // If neither image is multi-plane the aspectMask member of src and dst must match |
| 2301 | if (region.srcSubresource.aspectMask != region.dstSubresource.aspectMask) { |
| 2302 | std::stringstream ss; |
Graeme Leese | 79b60cb | 2018-11-28 11:51:20 +0000 | [diff] [blame] | 2303 | ss << "vkCmdCopyImage(): Copy between non-multiplane images with differing aspectMasks ( 0x" << std::hex |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 2304 | << region.srcSubresource.aspectMask << " and 0x" << region.dstSubresource.aspectMask << " )"; |
| 2305 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 2306 | HandleToUint64(command_buffer), "VUID-VkImageCopy-srcImage-01551", "%s.", ss.str().c_str()); |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 2307 | } |
| 2308 | } else { |
| 2309 | // Source image multiplane checks |
| 2310 | uint32_t planes = FormatPlaneCount(src_image_state->createInfo.format); |
| 2311 | VkImageAspectFlags aspect = region.srcSubresource.aspectMask; |
| 2312 | if ((2 == planes) && (aspect != VK_IMAGE_ASPECT_PLANE_0_BIT_KHR) && (aspect != VK_IMAGE_ASPECT_PLANE_1_BIT_KHR)) { |
| 2313 | std::stringstream ss; |
Graeme Leese | 79b60cb | 2018-11-28 11:51:20 +0000 | [diff] [blame] | 2314 | ss << "vkCmdCopyImage(): Source image aspect mask (0x" << std::hex << aspect << ") is invalid for 2-plane format"; |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 2315 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 2316 | HandleToUint64(command_buffer), "VUID-VkImageCopy-srcImage-01552", "%s.", ss.str().c_str()); |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 2317 | } |
| 2318 | if ((3 == planes) && (aspect != VK_IMAGE_ASPECT_PLANE_0_BIT_KHR) && (aspect != VK_IMAGE_ASPECT_PLANE_1_BIT_KHR) && |
| 2319 | (aspect != VK_IMAGE_ASPECT_PLANE_2_BIT_KHR)) { |
| 2320 | std::stringstream ss; |
Graeme Leese | 79b60cb | 2018-11-28 11:51:20 +0000 | [diff] [blame] | 2321 | ss << "vkCmdCopyImage(): Source image aspect mask (0x" << std::hex << aspect << ") is invalid for 3-plane format"; |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 2322 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 2323 | HandleToUint64(command_buffer), "VUID-VkImageCopy-srcImage-01553", "%s.", ss.str().c_str()); |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 2324 | } |
| 2325 | // Single-plane to multi-plane |
| 2326 | if ((!FormatIsMultiplane(src_image_state->createInfo.format)) && (FormatIsMultiplane(dst_image_state->createInfo.format)) && |
| 2327 | (VK_IMAGE_ASPECT_COLOR_BIT != aspect)) { |
| 2328 | std::stringstream ss; |
Graeme Leese | 79b60cb | 2018-11-28 11:51:20 +0000 | [diff] [blame] | 2329 | ss << "vkCmdCopyImage(): Source image aspect mask (0x" << std::hex << aspect << ") is not VK_IMAGE_ASPECT_COLOR_BIT"; |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 2330 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 2331 | HandleToUint64(command_buffer), "VUID-VkImageCopy-dstImage-01557", "%s.", ss.str().c_str()); |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 2332 | } |
| 2333 | |
| 2334 | // Dest image multiplane checks |
| 2335 | planes = FormatPlaneCount(dst_image_state->createInfo.format); |
| 2336 | aspect = region.dstSubresource.aspectMask; |
| 2337 | if ((2 == planes) && (aspect != VK_IMAGE_ASPECT_PLANE_0_BIT_KHR) && (aspect != VK_IMAGE_ASPECT_PLANE_1_BIT_KHR)) { |
| 2338 | std::stringstream ss; |
Graeme Leese | 79b60cb | 2018-11-28 11:51:20 +0000 | [diff] [blame] | 2339 | ss << "vkCmdCopyImage(): Dest image aspect mask (0x" << std::hex << aspect << ") is invalid for 2-plane format"; |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 2340 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 2341 | HandleToUint64(command_buffer), "VUID-VkImageCopy-dstImage-01554", "%s.", ss.str().c_str()); |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 2342 | } |
| 2343 | if ((3 == planes) && (aspect != VK_IMAGE_ASPECT_PLANE_0_BIT_KHR) && (aspect != VK_IMAGE_ASPECT_PLANE_1_BIT_KHR) && |
| 2344 | (aspect != VK_IMAGE_ASPECT_PLANE_2_BIT_KHR)) { |
| 2345 | std::stringstream ss; |
Graeme Leese | 79b60cb | 2018-11-28 11:51:20 +0000 | [diff] [blame] | 2346 | ss << "vkCmdCopyImage(): Dest image aspect mask (0x" << std::hex << aspect << ") is invalid for 3-plane format"; |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 2347 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 2348 | HandleToUint64(command_buffer), "VUID-VkImageCopy-dstImage-01555", "%s.", ss.str().c_str()); |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 2349 | } |
| 2350 | // Multi-plane to single-plane |
| 2351 | if ((FormatIsMultiplane(src_image_state->createInfo.format)) && (!FormatIsMultiplane(dst_image_state->createInfo.format)) && |
| 2352 | (VK_IMAGE_ASPECT_COLOR_BIT != aspect)) { |
| 2353 | std::stringstream ss; |
Graeme Leese | 79b60cb | 2018-11-28 11:51:20 +0000 | [diff] [blame] | 2354 | ss << "vkCmdCopyImage(): Dest image aspect mask (0x" << std::hex << aspect << ") is not VK_IMAGE_ASPECT_COLOR_BIT"; |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 2355 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 2356 | HandleToUint64(command_buffer), "VUID-VkImageCopy-srcImage-01556", "%s.", ss.str().c_str()); |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 2357 | } |
| 2358 | } |
| 2359 | |
| 2360 | return skip; |
| 2361 | } |
| 2362 | |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 2363 | bool CoreChecks::PreCallValidateCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 2364 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 2365 | const VkImageCopy *pRegions) { |
Mark Lobodzinski | 1b3a971 | 2019-03-06 15:51:47 -0700 | [diff] [blame] | 2366 | auto cb_node = GetCBNode(commandBuffer); |
Mark Lobodzinski | 8ddc23f | 2019-03-06 11:48:49 -0700 | [diff] [blame] | 2367 | auto src_image_state = GetImageState(srcImage); |
| 2368 | auto dst_image_state = GetImageState(dstImage); |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 2369 | bool skip = false; |
Mark Lobodzinski | b7eafbe | 2019-01-10 13:40:39 -0700 | [diff] [blame] | 2370 | |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 2371 | skip = ValidateImageCopyData(regionCount, pRegions, src_image_state, dst_image_state); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 2372 | |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 2373 | VkCommandBuffer command_buffer = cb_node->commandBuffer; |
| 2374 | |
Mark Lobodzinski | b7eafbe | 2019-01-10 13:40:39 -0700 | [diff] [blame] | 2375 | for (uint32_t i = 0; i < regionCount; i++) { |
| 2376 | const VkImageCopy region = pRegions[i]; |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 2377 | |
| 2378 | // For comp/uncomp copies, the copy extent for the dest image must be adjusted |
| 2379 | VkExtent3D src_copy_extent = region.extent; |
| 2380 | VkExtent3D dst_copy_extent = |
| 2381 | GetAdjustedDestImageExtent(src_image_state->createInfo.format, dst_image_state->createInfo.format, region.extent); |
| 2382 | |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 2383 | bool slice_override = false; |
| 2384 | uint32_t depth_slices = 0; |
| 2385 | |
| 2386 | // Special case for copying between a 1D/2D array and a 3D image |
| 2387 | // TBD: This seems like the only way to reconcile 3 mutually-exclusive VU checks for 2D/3D copies. Heads up. |
| 2388 | if ((VK_IMAGE_TYPE_3D == src_image_state->createInfo.imageType) && |
| 2389 | (VK_IMAGE_TYPE_3D != dst_image_state->createInfo.imageType)) { |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 2390 | depth_slices = region.dstSubresource.layerCount; // Slice count from 2D subresource |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 2391 | slice_override = (depth_slices != 1); |
| 2392 | } else if ((VK_IMAGE_TYPE_3D == dst_image_state->createInfo.imageType) && |
| 2393 | (VK_IMAGE_TYPE_3D != src_image_state->createInfo.imageType)) { |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 2394 | depth_slices = region.srcSubresource.layerCount; // Slice count from 2D subresource |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 2395 | slice_override = (depth_slices != 1); |
| 2396 | } |
| 2397 | |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 2398 | skip |= ValidateImageSubresourceLayers(cb_node, ®ion.srcSubresource, "vkCmdCopyImage", "srcSubresource", i); |
| 2399 | skip |= ValidateImageSubresourceLayers(cb_node, ®ion.dstSubresource, "vkCmdCopyImage", "dstSubresource", i); |
| 2400 | skip |= ValidateImageMipLevel(cb_node, src_image_state, region.srcSubresource.mipLevel, i, "vkCmdCopyImage", |
Cort Stratton | ff1542a | 2018-05-27 10:49:28 -0700 | [diff] [blame] | 2401 | "srcSubresource", "VUID-vkCmdCopyImage-srcSubresource-01696"); |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 2402 | skip |= ValidateImageMipLevel(cb_node, dst_image_state, region.dstSubresource.mipLevel, i, "vkCmdCopyImage", |
Cort Stratton | ff1542a | 2018-05-27 10:49:28 -0700 | [diff] [blame] | 2403 | "dstSubresource", "VUID-vkCmdCopyImage-dstSubresource-01697"); |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 2404 | skip |= ValidateImageArrayLayerRange(cb_node, src_image_state, region.srcSubresource.baseArrayLayer, |
Cort Stratton | ff1542a | 2018-05-27 10:49:28 -0700 | [diff] [blame] | 2405 | region.srcSubresource.layerCount, i, "vkCmdCopyImage", "srcSubresource", |
| 2406 | "VUID-vkCmdCopyImage-srcSubresource-01698"); |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 2407 | skip |= ValidateImageArrayLayerRange(cb_node, dst_image_state, region.dstSubresource.baseArrayLayer, |
Cort Stratton | ff1542a | 2018-05-27 10:49:28 -0700 | [diff] [blame] | 2408 | region.dstSubresource.layerCount, i, "vkCmdCopyImage", "dstSubresource", |
| 2409 | "VUID-vkCmdCopyImage-dstSubresource-01699"); |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 2410 | |
Mark Lobodzinski | 60e7903 | 2019-03-07 10:22:31 -0700 | [diff] [blame] | 2411 | if (GetDeviceExtensions()->vk_khr_maintenance1) { |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 2412 | // No chance of mismatch if we're overriding depth slice count |
| 2413 | if (!slice_override) { |
| 2414 | // The number of depth slices in srcSubresource and dstSubresource must match |
| 2415 | // Depth comes from layerCount for 1D,2D resources, from extent.depth for 3D |
| 2416 | uint32_t src_slices = |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 2417 | (VK_IMAGE_TYPE_3D == src_image_state->createInfo.imageType ? src_copy_extent.depth |
| 2418 | : region.srcSubresource.layerCount); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 2419 | uint32_t dst_slices = |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 2420 | (VK_IMAGE_TYPE_3D == dst_image_state->createInfo.imageType ? dst_copy_extent.depth |
| 2421 | : region.dstSubresource.layerCount); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 2422 | if (src_slices != dst_slices) { |
| 2423 | std::stringstream ss; |
Graeme Leese | 79b60cb | 2018-11-28 11:51:20 +0000 | [diff] [blame] | 2424 | ss << "vkCmdCopyImage(): number of depth slices in source and destination subresources for pRegions[" << i |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 2425 | << "] do not match"; |
| 2426 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 2427 | HandleToUint64(command_buffer), "VUID-VkImageCopy-extent-00140", "%s.", ss.str().c_str()); |
Dave Houlton | 6f9059e | 2017-05-02 17:15:13 -0600 | [diff] [blame] | 2428 | } |
| 2429 | } |
| 2430 | } else { |
Mike Schuchardt | 64b5bb7 | 2017-03-21 16:33:26 -0600 | [diff] [blame] | 2431 | // For each region the layerCount member of srcSubresource and dstSubresource must match |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 2432 | if (region.srcSubresource.layerCount != region.dstSubresource.layerCount) { |
Mike Schuchardt | 64b5bb7 | 2017-03-21 16:33:26 -0600 | [diff] [blame] | 2433 | std::stringstream ss; |
Graeme Leese | 79b60cb | 2018-11-28 11:51:20 +0000 | [diff] [blame] | 2434 | ss << "vkCmdCopyImage(): number of layers in source and destination subresources for pRegions[" << i |
Mike Schuchardt | 64b5bb7 | 2017-03-21 16:33:26 -0600 | [diff] [blame] | 2435 | << "] do not match"; |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 2436 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 2437 | HandleToUint64(command_buffer), "VUID-VkImageCopy-extent-00140", "%s.", ss.str().c_str()); |
Mike Schuchardt | 64b5bb7 | 2017-03-21 16:33:26 -0600 | [diff] [blame] | 2438 | } |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 2439 | } |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 2440 | |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 2441 | // Do multiplane-specific checks, if extension enabled |
Mark Lobodzinski | 60e7903 | 2019-03-07 10:22:31 -0700 | [diff] [blame] | 2442 | if (GetDeviceExtensions()->vk_khr_sampler_ycbcr_conversion) { |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 2443 | skip |= CopyImageMultiplaneValidation(command_buffer, src_image_state, dst_image_state, region); |
Dave Houlton | c991cc9 | 2018-03-06 11:08:51 -0700 | [diff] [blame] | 2444 | } |
| 2445 | |
Mark Lobodzinski | 60e7903 | 2019-03-07 10:22:31 -0700 | [diff] [blame] | 2446 | if (!GetDeviceExtensions()->vk_khr_sampler_ycbcr_conversion) { |
Dave Houlton | f521761 | 2018-02-02 16:18:52 -0700 | [diff] [blame] | 2447 | // not multi-plane, the aspectMask member of srcSubresource and dstSubresource must match |
| 2448 | if (region.srcSubresource.aspectMask != region.dstSubresource.aspectMask) { |
Graeme Leese | 79b60cb | 2018-11-28 11:51:20 +0000 | [diff] [blame] | 2449 | char const str[] = "vkCmdCopyImage(): Src and dest aspectMasks for each region must match"; |
Dave Houlton | f521761 | 2018-02-02 16:18:52 -0700 | [diff] [blame] | 2450 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 2451 | HandleToUint64(command_buffer), "VUID-VkImageCopy-aspectMask-00137", "%s.", str); |
Dave Houlton | f521761 | 2018-02-02 16:18:52 -0700 | [diff] [blame] | 2452 | } |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 2453 | } |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 2454 | |
Dave Houlton | 4eaaf3a | 2017-03-14 11:31:20 -0600 | [diff] [blame] | 2455 | // 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] | 2456 | if (!VerifyAspectsPresent(region.srcSubresource.aspectMask, src_image_state->createInfo.format)) { |
Dave Houlton | 4eaaf3a | 2017-03-14 11:31:20 -0600 | [diff] [blame] | 2457 | std::stringstream ss; |
Graeme Leese | 79b60cb | 2018-11-28 11:51:20 +0000 | [diff] [blame] | 2458 | ss << "vkCmdCopyImage(): pRegion[" << i |
Dave Houlton | 4eaaf3a | 2017-03-14 11:31:20 -0600 | [diff] [blame] | 2459 | << "] srcSubresource.aspectMask cannot specify aspects not present in source image"; |
| 2460 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 2461 | HandleToUint64(command_buffer), "VUID-VkImageCopy-aspectMask-00142", "%s.", ss.str().c_str()); |
Dave Houlton | 4eaaf3a | 2017-03-14 11:31:20 -0600 | [diff] [blame] | 2462 | } |
| 2463 | |
| 2464 | // 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] | 2465 | if (!VerifyAspectsPresent(region.dstSubresource.aspectMask, dst_image_state->createInfo.format)) { |
Dave Houlton | 4eaaf3a | 2017-03-14 11:31:20 -0600 | [diff] [blame] | 2466 | std::stringstream ss; |
Graeme Leese | 79b60cb | 2018-11-28 11:51:20 +0000 | [diff] [blame] | 2467 | ss << "vkCmdCopyImage(): pRegion[" << i |
| 2468 | << "] dstSubresource.aspectMask cannot specify aspects not present in dest image"; |
Dave Houlton | 4eaaf3a | 2017-03-14 11:31:20 -0600 | [diff] [blame] | 2469 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 2470 | HandleToUint64(command_buffer), "VUID-VkImageCopy-aspectMask-00143", "%s.", ss.str().c_str()); |
Dave Houlton | 4eaaf3a | 2017-03-14 11:31:20 -0600 | [diff] [blame] | 2471 | } |
| 2472 | |
Mike Schuchardt | 64b5bb7 | 2017-03-21 16:33:26 -0600 | [diff] [blame] | 2473 | // Check region extents for 1D-1D, 2D-2D, and 3D-3D copies |
| 2474 | if (src_image_state->createInfo.imageType == dst_image_state->createInfo.imageType) { |
| 2475 | // 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] | 2476 | VkExtent3D img_extent = GetImageSubresourceExtent(src_image_state, &(region.srcSubresource)); |
| 2477 | if (0 != ExceedsBounds(®ion.srcOffset, &src_copy_extent, &img_extent)) { |
Mike Schuchardt | 64b5bb7 | 2017-03-21 16:33:26 -0600 | [diff] [blame] | 2478 | std::stringstream ss; |
Graeme Leese | 79b60cb | 2018-11-28 11:51:20 +0000 | [diff] [blame] | 2479 | ss << "vkCmdCopyImage(): Source pRegion[" << i << "] with mipLevel [ " << region.srcSubresource.mipLevel |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 2480 | << " ], offset [ " << region.srcOffset.x << ", " << region.srcOffset.y << ", " << region.srcOffset.z |
| 2481 | << " ], extent [ " << src_copy_extent.width << ", " << src_copy_extent.height << ", " << src_copy_extent.depth |
| 2482 | << " ] exceeds the source image dimensions"; |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 2483 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 2484 | HandleToUint64(command_buffer), "VUID-vkCmdCopyImage-pRegions-00122", "%s.", ss.str().c_str()); |
Mike Schuchardt | 64b5bb7 | 2017-03-21 16:33:26 -0600 | [diff] [blame] | 2485 | } |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 2486 | |
Mike Schuchardt | 64b5bb7 | 2017-03-21 16:33:26 -0600 | [diff] [blame] | 2487 | // 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] | 2488 | img_extent = GetImageSubresourceExtent(dst_image_state, &(region.dstSubresource)); |
| 2489 | if (0 != ExceedsBounds(®ion.dstOffset, &dst_copy_extent, &img_extent)) { |
Mike Schuchardt | 64b5bb7 | 2017-03-21 16:33:26 -0600 | [diff] [blame] | 2490 | std::stringstream ss; |
Graeme Leese | 79b60cb | 2018-11-28 11:51:20 +0000 | [diff] [blame] | 2491 | ss << "vkCmdCopyImage(): Dest pRegion[" << i << "] with mipLevel [ " << region.dstSubresource.mipLevel |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 2492 | << " ], offset [ " << region.dstOffset.x << ", " << region.dstOffset.y << ", " << region.dstOffset.z |
| 2493 | << " ], extent [ " << dst_copy_extent.width << ", " << dst_copy_extent.height << ", " << dst_copy_extent.depth |
| 2494 | << " ] exceeds the destination image dimensions"; |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 2495 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 2496 | HandleToUint64(command_buffer), "VUID-vkCmdCopyImage-pRegions-00123", "%s.", ss.str().c_str()); |
Mike Schuchardt | 64b5bb7 | 2017-03-21 16:33:26 -0600 | [diff] [blame] | 2497 | } |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 2498 | } |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 2499 | |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 2500 | // Each dimension offset + extent limits must fall with image subresource extent |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 2501 | VkExtent3D subresource_extent = GetImageSubresourceExtent(src_image_state, &(region.srcSubresource)); |
| 2502 | if (slice_override) src_copy_extent.depth = depth_slices; |
| 2503 | uint32_t extent_check = ExceedsBounds(&(region.srcOffset), &src_copy_extent, &subresource_extent); |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 2504 | if (extent_check & x_bit) { |
Graeme Leese | 79b60cb | 2018-11-28 11:51:20 +0000 | [diff] [blame] | 2505 | skip |= |
| 2506 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 2507 | HandleToUint64(command_buffer), "VUID-VkImageCopy-srcOffset-00144", |
| 2508 | "vkCmdCopyImage(): Source image pRegion %1d x-dimension offset [%1d] + extent [%1d] exceeds subResource " |
| 2509 | "width [%1d].", |
| 2510 | i, region.srcOffset.x, src_copy_extent.width, subresource_extent.width); |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 2511 | } |
| 2512 | |
| 2513 | if (extent_check & y_bit) { |
Graeme Leese | 79b60cb | 2018-11-28 11:51:20 +0000 | [diff] [blame] | 2514 | skip |= |
| 2515 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 2516 | HandleToUint64(command_buffer), "VUID-VkImageCopy-srcOffset-00145", |
| 2517 | "vkCmdCopyImage(): Source image pRegion %1d y-dimension offset [%1d] + extent [%1d] exceeds subResource " |
| 2518 | "height [%1d].", |
| 2519 | i, region.srcOffset.y, src_copy_extent.height, subresource_extent.height); |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 2520 | } |
| 2521 | if (extent_check & z_bit) { |
Graeme Leese | 79b60cb | 2018-11-28 11:51:20 +0000 | [diff] [blame] | 2522 | skip |= |
| 2523 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 2524 | HandleToUint64(command_buffer), "VUID-VkImageCopy-srcOffset-00147", |
| 2525 | "vkCmdCopyImage(): Source image pRegion %1d z-dimension offset [%1d] + extent [%1d] exceeds subResource " |
| 2526 | "depth [%1d].", |
| 2527 | i, region.srcOffset.z, src_copy_extent.depth, subresource_extent.depth); |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 2528 | } |
| 2529 | |
Dave Houlton | ee281a5 | 2017-12-08 13:51:02 -0700 | [diff] [blame] | 2530 | // Adjust dest extent if necessary |
| 2531 | subresource_extent = GetImageSubresourceExtent(dst_image_state, &(region.dstSubresource)); |
| 2532 | if (slice_override) dst_copy_extent.depth = depth_slices; |
| 2533 | |
| 2534 | extent_check = ExceedsBounds(&(region.dstOffset), &dst_copy_extent, &subresource_extent); |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 2535 | if (extent_check & x_bit) { |
| 2536 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 2537 | HandleToUint64(command_buffer), "VUID-VkImageCopy-dstOffset-00150", |
Graeme Leese | 79b60cb | 2018-11-28 11:51:20 +0000 | [diff] [blame] | 2538 | "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] | 2539 | "width [%1d].", |
| 2540 | i, region.dstOffset.x, dst_copy_extent.width, subresource_extent.width); |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 2541 | } |
| 2542 | if (extent_check & y_bit) { |
| 2543 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 2544 | HandleToUint64(command_buffer), "VUID-VkImageCopy-dstOffset-00151", |
Graeme Leese | 79b60cb | 2018-11-28 11:51:20 +0000 | [diff] [blame] | 2545 | "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] | 2546 | "height [%1d].", |
| 2547 | i, region.dstOffset.y, dst_copy_extent.height, subresource_extent.height); |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 2548 | } |
| 2549 | if (extent_check & z_bit) { |
| 2550 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 2551 | HandleToUint64(command_buffer), "VUID-VkImageCopy-dstOffset-00153", |
Graeme Leese | 79b60cb | 2018-11-28 11:51:20 +0000 | [diff] [blame] | 2552 | "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] | 2553 | "depth [%1d].", |
| 2554 | i, region.dstOffset.z, dst_copy_extent.depth, subresource_extent.depth); |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 2555 | } |
| 2556 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 2557 | // The union of all source regions, and the union of all destination regions, specified by the elements of regions, |
| 2558 | // must not overlap in memory |
| 2559 | if (src_image_state->image == dst_image_state->image) { |
Mark Lobodzinski | b7eafbe | 2019-01-10 13:40:39 -0700 | [diff] [blame] | 2560 | for (uint32_t j = 0; j < regionCount; j++) { |
| 2561 | if (RegionIntersects(®ion, &pRegions[j], src_image_state->createInfo.imageType, |
Dave Houlton | f521761 | 2018-02-02 16:18:52 -0700 | [diff] [blame] | 2562 | FormatIsMultiplane(src_image_state->createInfo.format))) { |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 2563 | std::stringstream ss; |
Graeme Leese | 79b60cb | 2018-11-28 11:51:20 +0000 | [diff] [blame] | 2564 | ss << "vkCmdCopyImage(): pRegions[" << i << "] src overlaps with pRegions[" << j << "]."; |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 2565 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 2566 | HandleToUint64(command_buffer), "VUID-vkCmdCopyImage-pRegions-00124", "%s.", ss.str().c_str()); |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 2567 | } |
| 2568 | } |
| 2569 | } |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 2570 | } |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 2571 | |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 2572 | // The formats of src_image and dst_image must be compatible. Formats are considered compatible if their texel size in bytes |
| 2573 | // is the same between both formats. For example, VK_FORMAT_R8G8B8A8_UNORM is compatible with VK_FORMAT_R32_UINT because |
| 2574 | // 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] | 2575 | 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] | 2576 | if (src_image_state->createInfo.format != dst_image_state->createInfo.format) { |
| 2577 | 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] | 2578 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Dave Houlton | 5165390 | 2018-06-22 17:32:13 -0600 | [diff] [blame] | 2579 | HandleToUint64(command_buffer), kVUID_Core_DrawState_MismatchedImageFormat, str); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 2580 | } |
| 2581 | } else { |
Mark Lobodzinski | b7eafbe | 2019-01-10 13:40:39 -0700 | [diff] [blame] | 2582 | if (!FormatSizesAreEqual(src_image_state->createInfo.format, dst_image_state->createInfo.format, regionCount, pRegions)) { |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 2583 | char const str[] = "vkCmdCopyImage called with unmatched source and dest image format sizes."; |
| 2584 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 2585 | HandleToUint64(command_buffer), "VUID-vkCmdCopyImage-srcImage-00135", "%s.", str); |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 2586 | } |
| 2587 | } |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 2588 | |
Dave Houlton | 33c22b7 | 2017-02-28 13:16:02 -0700 | [diff] [blame] | 2589 | // Source and dest image sample counts must match |
| 2590 | if (src_image_state->createInfo.samples != dst_image_state->createInfo.samples) { |
| 2591 | char const str[] = "vkCmdCopyImage() called on image pair with non-identical sample counts."; |
| 2592 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 2593 | HandleToUint64(command_buffer), "VUID-vkCmdCopyImage-srcImage-00136", "%s", str); |
Dave Houlton | 33c22b7 | 2017-02-28 13:16:02 -0700 | [diff] [blame] | 2594 | } |
| 2595 | |
Mark Lobodzinski | 0ebe971 | 2019-03-07 13:39:07 -0700 | [diff] [blame] | 2596 | skip |= ValidateMemoryIsBoundToImage(src_image_state, "vkCmdCopyImage()", "VUID-vkCmdCopyImage-srcImage-00127"); |
| 2597 | skip |= ValidateMemoryIsBoundToImage(dst_image_state, "vkCmdCopyImage()", "VUID-vkCmdCopyImage-dstImage-00132"); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 2598 | // Validate that SRC & DST images have correct usage flags set |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 2599 | skip |= ValidateImageUsageFlags(src_image_state, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, true, "VUID-vkCmdCopyImage-srcImage-00126", |
| 2600 | "vkCmdCopyImage()", "VK_IMAGE_USAGE_TRANSFER_SRC_BIT"); |
| 2601 | skip |= ValidateImageUsageFlags(dst_image_state, VK_IMAGE_USAGE_TRANSFER_DST_BIT, true, "VUID-vkCmdCopyImage-dstImage-00131", |
| 2602 | "vkCmdCopyImage()", "VK_IMAGE_USAGE_TRANSFER_DST_BIT"); |
Mark Lobodzinski | 96d5c6e | 2019-03-07 11:28:21 -0700 | [diff] [blame] | 2603 | if (GetApiVersion() >= VK_API_VERSION_1_1 || GetDeviceExtensions()->vk_khr_maintenance1) { |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 2604 | skip |= ValidateImageFormatFeatureFlags(src_image_state, VK_FORMAT_FEATURE_TRANSFER_SRC_BIT, "vkCmdCopyImage()", |
| 2605 | "VUID-vkCmdCopyImage-srcImage-01995", "VUID-vkCmdCopyImage-srcImage-01995"); |
| 2606 | skip |= ValidateImageFormatFeatureFlags(dst_image_state, VK_FORMAT_FEATURE_TRANSFER_DST_BIT, "vkCmdCopyImage()", |
| 2607 | "VUID-vkCmdCopyImage-dstImage-01996", "VUID-vkCmdCopyImage-dstImage-01996"); |
Cort Stratton | 186b1a2 | 2018-05-01 20:18:06 -0400 | [diff] [blame] | 2608 | } |
Mark Lobodzinski | daea591 | 2019-03-07 14:47:09 -0700 | [diff] [blame] | 2609 | skip |= ValidateCmdQueueFlags(cb_node, "vkCmdCopyImage()", VK_QUEUE_TRANSFER_BIT | VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 2610 | "VUID-vkCmdCopyImage-commandBuffer-cmdpool"); |
Mark Lobodzinski | fae179e | 2019-03-08 16:47:08 -0700 | [diff] [blame] | 2611 | skip |= ValidateCmd(cb_node, CMD_COPYIMAGE, "vkCmdCopyImage()"); |
| 2612 | skip |= InsideRenderPass(cb_node, "vkCmdCopyImage()", "VUID-vkCmdCopyImage-renderpass"); |
Tobin Ehlis | c826645 | 2017-04-07 12:20:30 -0600 | [diff] [blame] | 2613 | bool hit_error = false; |
Jeff Bolz | fdd0d85 | 2019-02-03 21:55:12 -0600 | [diff] [blame] | 2614 | const char *invalid_src_layout_vuid = |
Mark Lobodzinski | 60e7903 | 2019-03-07 10:22:31 -0700 | [diff] [blame] | 2615 | (src_image_state->shared_presentable && GetDeviceExtensions()->vk_khr_shared_presentable_image) |
Cort Stratton | 7df3096 | 2018-05-17 19:45:57 -0700 | [diff] [blame] | 2616 | ? "VUID-vkCmdCopyImage-srcImageLayout-01917" |
| 2617 | : "VUID-vkCmdCopyImage-srcImageLayout-00129"; |
Jeff Bolz | fdd0d85 | 2019-02-03 21:55:12 -0600 | [diff] [blame] | 2618 | const char *invalid_dst_layout_vuid = |
Mark Lobodzinski | 60e7903 | 2019-03-07 10:22:31 -0700 | [diff] [blame] | 2619 | (dst_image_state->shared_presentable && GetDeviceExtensions()->vk_khr_shared_presentable_image) |
Cort Stratton | 7df3096 | 2018-05-17 19:45:57 -0700 | [diff] [blame] | 2620 | ? "VUID-vkCmdCopyImage-dstImageLayout-01395" |
| 2621 | : "VUID-vkCmdCopyImage-dstImageLayout-00134"; |
Mark Lobodzinski | b7eafbe | 2019-01-10 13:40:39 -0700 | [diff] [blame] | 2622 | for (uint32_t i = 0; i < regionCount; ++i) { |
Mark Lobodzinski | 8564e44 | 2019-03-07 12:49:41 -0700 | [diff] [blame] | 2623 | skip |= VerifyImageLayout(cb_node, src_image_state, pRegions[i].srcSubresource, srcImageLayout, |
Cort Stratton | 7df3096 | 2018-05-17 19:45:57 -0700 | [diff] [blame] | 2624 | VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, "vkCmdCopyImage()", invalid_src_layout_vuid, |
| 2625 | "VUID-vkCmdCopyImage-srcImageLayout-00128", &hit_error); |
Mark Lobodzinski | 8564e44 | 2019-03-07 12:49:41 -0700 | [diff] [blame] | 2626 | skip |= VerifyImageLayout(cb_node, dst_image_state, pRegions[i].dstSubresource, dstImageLayout, |
Cort Stratton | 7df3096 | 2018-05-17 19:45:57 -0700 | [diff] [blame] | 2627 | VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, "vkCmdCopyImage()", invalid_dst_layout_vuid, |
| 2628 | "VUID-vkCmdCopyImage-dstImageLayout-00133", &hit_error); |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 2629 | skip |= ValidateCopyImageTransferGranularityRequirements(cb_node, src_image_state, dst_image_state, &pRegions[i], i, |
| 2630 | "vkCmdCopyImage()"); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 2631 | } |
| 2632 | |
Mark Lobodzinski | b39d2ec | 2017-02-02 14:38:47 -0700 | [diff] [blame] | 2633 | return skip; |
| 2634 | } |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 2635 | |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 2636 | void CoreChecks::PreCallRecordCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 2637 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 2638 | const VkImageCopy *pRegions) { |
Mark Lobodzinski | 1b3a971 | 2019-03-06 15:51:47 -0700 | [diff] [blame] | 2639 | auto cb_node = GetCBNode(commandBuffer); |
Mark Lobodzinski | 8ddc23f | 2019-03-06 11:48:49 -0700 | [diff] [blame] | 2640 | auto src_image_state = GetImageState(srcImage); |
| 2641 | auto dst_image_state = GetImageState(dstImage); |
Mark Lobodzinski | b7eafbe | 2019-01-10 13:40:39 -0700 | [diff] [blame] | 2642 | |
Tobin Ehlis | e35b66a | 2017-03-15 12:18:31 -0600 | [diff] [blame] | 2643 | // Make sure that all image slices are updated to correct layout |
Mark Lobodzinski | b7eafbe | 2019-01-10 13:40:39 -0700 | [diff] [blame] | 2644 | for (uint32_t i = 0; i < regionCount; ++i) { |
John Zulauf | f660ad6 | 2019-03-23 07:16:05 -0600 | [diff] [blame] | 2645 | SetImageInitialLayout(cb_node, *src_image_state, pRegions[i].srcSubresource, srcImageLayout); |
| 2646 | SetImageInitialLayout(cb_node, *dst_image_state, pRegions[i].dstSubresource, dstImageLayout); |
Tobin Ehlis | e35b66a | 2017-03-15 12:18:31 -0600 | [diff] [blame] | 2647 | } |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 2648 | // Update bindings between images and cmd buffer |
Mark Lobodzinski | fae179e | 2019-03-08 16:47:08 -0700 | [diff] [blame] | 2649 | AddCommandBufferBindingImage(cb_node, src_image_state); |
| 2650 | AddCommandBufferBindingImage(cb_node, dst_image_state); |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 2651 | } |
| 2652 | |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 2653 | // Returns true if sub_rect is entirely contained within rect |
| 2654 | static inline bool ContainsRect(VkRect2D rect, VkRect2D sub_rect) { |
| 2655 | if ((sub_rect.offset.x < rect.offset.x) || (sub_rect.offset.x + sub_rect.extent.width > rect.offset.x + rect.extent.width) || |
| 2656 | (sub_rect.offset.y < rect.offset.y) || (sub_rect.offset.y + sub_rect.extent.height > rect.offset.y + rect.extent.height)) |
| 2657 | return false; |
| 2658 | return true; |
| 2659 | } |
| 2660 | |
Mark Lobodzinski | f933db9 | 2019-03-09 12:58:03 -0700 | [diff] [blame] | 2661 | bool CoreChecks::ValidateClearAttachmentExtent(VkCommandBuffer command_buffer, uint32_t attachment_index, |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 2662 | FRAMEBUFFER_STATE *framebuffer, uint32_t fb_attachment, const VkRect2D &render_area, |
| 2663 | uint32_t rect_count, const VkClearRect *clear_rects) { |
John Zulauf | 3a548ef | 2019-02-01 16:14:07 -0700 | [diff] [blame] | 2664 | bool skip = false; |
John Zulauf | f258297 | 2019-02-09 14:53:30 -0700 | [diff] [blame] | 2665 | const IMAGE_VIEW_STATE *image_view_state = nullptr; |
| 2666 | if (framebuffer && (fb_attachment != VK_ATTACHMENT_UNUSED) && (fb_attachment < framebuffer->createInfo.attachmentCount)) { |
Mark Lobodzinski | a3a230b | 2019-03-06 15:35:13 -0700 | [diff] [blame] | 2667 | image_view_state = GetImageViewState(framebuffer->createInfo.pAttachments[fb_attachment]); |
John Zulauf | f258297 | 2019-02-09 14:53:30 -0700 | [diff] [blame] | 2668 | } |
John Zulauf | 3a548ef | 2019-02-01 16:14:07 -0700 | [diff] [blame] | 2669 | |
| 2670 | for (uint32_t j = 0; j < rect_count; j++) { |
| 2671 | if (!ContainsRect(render_area, clear_rects[j].rect)) { |
Mark Lobodzinski | f933db9 | 2019-03-09 12:58:03 -0700 | [diff] [blame] | 2672 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
John Zulauf | 3a548ef | 2019-02-01 16:14:07 -0700 | [diff] [blame] | 2673 | HandleToUint64(command_buffer), "VUID-vkCmdClearAttachments-pRects-00016", |
| 2674 | "vkCmdClearAttachments(): The area defined by pRects[%d] is not contained in the area of " |
| 2675 | "the current render pass instance.", |
| 2676 | j); |
| 2677 | } |
| 2678 | |
| 2679 | if (image_view_state) { |
| 2680 | // The layers specified by a given element of pRects must be contained within every attachment that |
| 2681 | // pAttachments refers to |
| 2682 | const auto attachment_layer_count = image_view_state->create_info.subresourceRange.layerCount; |
| 2683 | if ((clear_rects[j].baseArrayLayer >= attachment_layer_count) || |
| 2684 | (clear_rects[j].baseArrayLayer + clear_rects[j].layerCount > attachment_layer_count)) { |
Mark Lobodzinski | f933db9 | 2019-03-09 12:58:03 -0700 | [diff] [blame] | 2685 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 2686 | HandleToUint64(command_buffer), "VUID-vkCmdClearAttachments-pRects-00017", |
| 2687 | "vkCmdClearAttachments(): The layers defined in pRects[%d] are not contained in the layers " |
| 2688 | "of pAttachment[%d].", |
| 2689 | j, attachment_index); |
John Zulauf | 3a548ef | 2019-02-01 16:14:07 -0700 | [diff] [blame] | 2690 | } |
| 2691 | } |
| 2692 | } |
| 2693 | return skip; |
| 2694 | } |
| 2695 | |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 2696 | bool CoreChecks::PreCallValidateCmdClearAttachments(VkCommandBuffer commandBuffer, uint32_t attachmentCount, |
| 2697 | const VkClearAttachment *pAttachments, uint32_t rectCount, |
| 2698 | const VkClearRect *pRects) { |
Mark Lobodzinski | 1b3a971 | 2019-03-06 15:51:47 -0700 | [diff] [blame] | 2699 | GLOBAL_CB_NODE *cb_node = GetCBNode(commandBuffer); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 2700 | |
| 2701 | bool skip = false; |
| 2702 | if (cb_node) { |
Mark Lobodzinski | daea591 | 2019-03-07 14:47:09 -0700 | [diff] [blame] | 2703 | skip |= ValidateCmdQueueFlags(cb_node, "vkCmdClearAttachments()", VK_QUEUE_GRAPHICS_BIT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 2704 | "VUID-vkCmdClearAttachments-commandBuffer-cmdpool"); |
Mark Lobodzinski | fae179e | 2019-03-08 16:47:08 -0700 | [diff] [blame] | 2705 | skip |= ValidateCmd(cb_node, CMD_CLEARATTACHMENTS, "vkCmdClearAttachments()"); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 2706 | // 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] | 2707 | 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] | 2708 | (cb_node->activeRenderPassBeginInfo.renderArea.extent.height == pRects[0].rect.extent.height)) { |
| 2709 | // 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] | 2710 | // This warning should be made more specific. It'd be best to avoid triggering this test if it's a use that must call |
| 2711 | // CmdClearAttachments. |
Locke | e9aeebf | 2019-03-03 23:50:08 -0700 | [diff] [blame] | 2712 | skip |= |
| 2713 | log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 2714 | HandleToUint64(commandBuffer), kVUID_Core_DrawState_ClearCmdBeforeDraw, |
| 2715 | "vkCmdClearAttachments() issued on command buffer object %s prior to any Draw Cmds. It is recommended you " |
| 2716 | "use RenderPass LOAD_OP_CLEAR on Attachments prior to any Draw.", |
| 2717 | report_data->FormatHandle(commandBuffer).c_str()); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 2718 | } |
Mark Lobodzinski | fae179e | 2019-03-08 16:47:08 -0700 | [diff] [blame] | 2719 | skip |= OutsideRenderPass(cb_node, "vkCmdClearAttachments()", "VUID-vkCmdClearAttachments-renderpass"); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 2720 | } |
| 2721 | |
| 2722 | // Validate that attachment is in reference list of active subpass |
| 2723 | if (cb_node->activeRenderPass) { |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 2724 | const VkRenderPassCreateInfo2KHR *renderpass_create_info = cb_node->activeRenderPass->createInfo.ptr(); |
John Zulauf | f258297 | 2019-02-09 14:53:30 -0700 | [diff] [blame] | 2725 | const uint32_t renderpass_attachment_count = renderpass_create_info->attachmentCount; |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 2726 | const VkSubpassDescription2KHR *subpass_desc = &renderpass_create_info->pSubpasses[cb_node->activeSubpass]; |
Mark Lobodzinski | 74772ca | 2019-03-06 16:15:06 -0700 | [diff] [blame] | 2727 | auto framebuffer = GetFramebufferState(cb_node->activeFramebuffer); |
John Zulauf | 3a548ef | 2019-02-01 16:14:07 -0700 | [diff] [blame] | 2728 | const auto &render_area = cb_node->activeRenderPassBeginInfo.renderArea; |
| 2729 | std::shared_ptr<std::vector<VkClearRect>> clear_rect_copy; |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 2730 | |
John Zulauf | 3a548ef | 2019-02-01 16:14:07 -0700 | [diff] [blame] | 2731 | for (uint32_t attachment_index = 0; attachment_index < attachmentCount; attachment_index++) { |
| 2732 | auto clear_desc = &pAttachments[attachment_index]; |
| 2733 | uint32_t fb_attachment = VK_ATTACHMENT_UNUSED; |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 2734 | |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 2735 | if (0 == clear_desc->aspectMask) { |
| 2736 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 2737 | HandleToUint64(commandBuffer), "VUID-VkClearAttachment-aspectMask-requiredbitmask", " "); |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 2738 | } else if (clear_desc->aspectMask & VK_IMAGE_ASPECT_METADATA_BIT) { |
| 2739 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 2740 | HandleToUint64(commandBuffer), "VUID-VkClearAttachment-aspectMask-00020", " "); |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 2741 | } else if (clear_desc->aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) { |
John Zulauf | f258297 | 2019-02-09 14:53:30 -0700 | [diff] [blame] | 2742 | uint32_t color_attachment = VK_ATTACHMENT_UNUSED; |
| 2743 | if (clear_desc->colorAttachment < subpass_desc->colorAttachmentCount) { |
| 2744 | color_attachment = subpass_desc->pColorAttachments[clear_desc->colorAttachment].attachment; |
| 2745 | if ((color_attachment != VK_ATTACHMENT_UNUSED) && (color_attachment >= renderpass_attachment_count)) { |
Locke | e9aeebf | 2019-03-03 23:50:08 -0700 | [diff] [blame] | 2746 | skip |= log_msg( |
| 2747 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 2748 | HandleToUint64(commandBuffer), "VUID-vkCmdClearAttachments-aspectMask-02501", |
| 2749 | "vkCmdClearAttachments() pAttachments[%u].colorAttachment=%u is not VK_ATTACHMENT_UNUSED " |
| 2750 | "and not a valid attachment for render pass %s attachmentCount=%u. Subpass %u pColorAttachment[%u]=%u.", |
| 2751 | attachment_index, clear_desc->colorAttachment, |
| 2752 | report_data->FormatHandle(cb_node->activeRenderPass->renderPass).c_str(), cb_node->activeSubpass, |
| 2753 | clear_desc->colorAttachment, color_attachment, renderpass_attachment_count); |
| 2754 | |
John Zulauf | f258297 | 2019-02-09 14:53:30 -0700 | [diff] [blame] | 2755 | color_attachment = VK_ATTACHMENT_UNUSED; // Defensive, prevent lookup past end of renderpass attachment |
| 2756 | } |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 2757 | } else { |
Locke | e9aeebf | 2019-03-03 23:50:08 -0700 | [diff] [blame] | 2758 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 2759 | HandleToUint64(commandBuffer), "VUID-vkCmdClearAttachments-aspectMask-02501", |
| 2760 | "vkCmdClearAttachments() pAttachments[%u].colorAttachment=%u out of range for render pass %s" |
| 2761 | " subpass %u. colorAttachmentCount=%u", |
| 2762 | attachment_index, clear_desc->colorAttachment, |
| 2763 | report_data->FormatHandle(cb_node->activeRenderPass->renderPass).c_str(), |
| 2764 | cb_node->activeSubpass, subpass_desc->colorAttachmentCount); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 2765 | } |
John Zulauf | f258297 | 2019-02-09 14:53:30 -0700 | [diff] [blame] | 2766 | fb_attachment = color_attachment; |
| 2767 | |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 2768 | if ((clear_desc->aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) || |
| 2769 | (clear_desc->aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT)) { |
| 2770 | char const str[] = |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2771 | "vkCmdClearAttachments() aspectMask [%d] must set only VK_IMAGE_ASPECT_COLOR_BIT of a color attachment."; |
John Zulauf | 3a548ef | 2019-02-01 16:14:07 -0700 | [diff] [blame] | 2772 | skip |= |
| 2773 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 2774 | HandleToUint64(commandBuffer), "VUID-VkClearAttachment-aspectMask-00019", str, attachment_index); |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 2775 | } |
| 2776 | } else { // Must be depth and/or stencil |
| 2777 | if (((clear_desc->aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) != VK_IMAGE_ASPECT_DEPTH_BIT) && |
| 2778 | ((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] | 2779 | 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] | 2780 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
John Zulauf | 3a548ef | 2019-02-01 16:14:07 -0700 | [diff] [blame] | 2781 | HandleToUint64(commandBuffer), "VUID-VkClearAttachment-aspectMask-parameter", str, |
| 2782 | attachment_index); |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 2783 | } |
| 2784 | if (!subpass_desc->pDepthStencilAttachment || |
| 2785 | (subpass_desc->pDepthStencilAttachment->attachment == VK_ATTACHMENT_UNUSED)) { |
| 2786 | skip |= log_msg( |
| 2787 | report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Dave Houlton | 5165390 | 2018-06-22 17:32:13 -0600 | [diff] [blame] | 2788 | HandleToUint64(commandBuffer), kVUID_Core_DrawState_MissingAttachmentReference, |
Mark Lobodzinski | ac7e51e | 2017-02-02 15:50:27 -0700 | [diff] [blame] | 2789 | "vkCmdClearAttachments() depth/stencil clear with no depth/stencil attachment in subpass; ignored"); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 2790 | } else { |
John Zulauf | 3a548ef | 2019-02-01 16:14:07 -0700 | [diff] [blame] | 2791 | fb_attachment = subpass_desc->pDepthStencilAttachment->attachment; |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 2792 | } |
| 2793 | } |
John Zulauf | 3a548ef | 2019-02-01 16:14:07 -0700 | [diff] [blame] | 2794 | if (cb_node->createInfo.level == VK_COMMAND_BUFFER_LEVEL_PRIMARY) { |
Mark Lobodzinski | f933db9 | 2019-03-09 12:58:03 -0700 | [diff] [blame] | 2795 | skip |= ValidateClearAttachmentExtent(commandBuffer, attachment_index, framebuffer, fb_attachment, render_area, |
| 2796 | rectCount, pRects); |
John Zulauf | 3a548ef | 2019-02-01 16:14:07 -0700 | [diff] [blame] | 2797 | } else { |
| 2798 | // if a secondary level command buffer inherits the framebuffer from the primary command buffer |
| 2799 | // (see VkCommandBufferInheritanceInfo), this validation must be deferred until queue submit time |
| 2800 | if (!clear_rect_copy) { |
| 2801 | // We need a copy of the clear rectangles that will persist until the last lambda executes |
| 2802 | // but we want to create it as lazily as possible |
| 2803 | clear_rect_copy.reset(new std::vector<VkClearRect>(pRects, pRects + rectCount)); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 2804 | } |
John Zulauf | 3a548ef | 2019-02-01 16:14:07 -0700 | [diff] [blame] | 2805 | |
Mark Lobodzinski | f933db9 | 2019-03-09 12:58:03 -0700 | [diff] [blame] | 2806 | auto val_fn = [this, commandBuffer, attachment_index, fb_attachment, rectCount, clear_rect_copy]( |
John Zulauf | 3a548ef | 2019-02-01 16:14:07 -0700 | [diff] [blame] | 2807 | GLOBAL_CB_NODE *prim_cb, VkFramebuffer fb) { |
| 2808 | assert(rectCount == clear_rect_copy->size()); |
Mark Lobodzinski | f933db9 | 2019-03-09 12:58:03 -0700 | [diff] [blame] | 2809 | FRAMEBUFFER_STATE *framebuffer = GetFramebufferState(fb); |
John Zulauf | 3a548ef | 2019-02-01 16:14:07 -0700 | [diff] [blame] | 2810 | const auto &render_area = prim_cb->activeRenderPassBeginInfo.renderArea; |
| 2811 | bool skip = false; |
Mark Lobodzinski | f933db9 | 2019-03-09 12:58:03 -0700 | [diff] [blame] | 2812 | skip = ValidateClearAttachmentExtent(commandBuffer, attachment_index, framebuffer, fb_attachment, render_area, |
| 2813 | rectCount, clear_rect_copy->data()); |
John Zulauf | 3a548ef | 2019-02-01 16:14:07 -0700 | [diff] [blame] | 2814 | return skip; |
| 2815 | }; |
| 2816 | cb_node->cmd_execute_commands_functions.emplace_back(val_fn); |
Mark Lobodzinski | 2def2bf | 2017-02-02 15:22:50 -0700 | [diff] [blame] | 2817 | } |
| 2818 | } |
| 2819 | } |
| 2820 | return skip; |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 2821 | } |
| 2822 | |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 2823 | bool CoreChecks::PreCallValidateCmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 2824 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 2825 | const VkImageResolve *pRegions) { |
Mark Lobodzinski | 1b3a971 | 2019-03-06 15:51:47 -0700 | [diff] [blame] | 2826 | auto cb_node = GetCBNode(commandBuffer); |
Mark Lobodzinski | 8ddc23f | 2019-03-06 11:48:49 -0700 | [diff] [blame] | 2827 | auto src_image_state = GetImageState(srcImage); |
| 2828 | auto dst_image_state = GetImageState(dstImage); |
Mark Lobodzinski | 9a075c2 | 2019-01-10 14:30:39 -0700 | [diff] [blame] | 2829 | |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 2830 | bool skip = false; |
| 2831 | if (cb_node && src_image_state && dst_image_state) { |
Mark Lobodzinski | 0ebe971 | 2019-03-07 13:39:07 -0700 | [diff] [blame] | 2832 | skip |= ValidateMemoryIsBoundToImage(src_image_state, "vkCmdResolveImage()", "VUID-vkCmdResolveImage-srcImage-00256"); |
| 2833 | skip |= ValidateMemoryIsBoundToImage(dst_image_state, "vkCmdResolveImage()", "VUID-vkCmdResolveImage-dstImage-00258"); |
Mark Lobodzinski | daea591 | 2019-03-07 14:47:09 -0700 | [diff] [blame] | 2834 | skip |= ValidateCmdQueueFlags(cb_node, "vkCmdResolveImage()", VK_QUEUE_GRAPHICS_BIT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 2835 | "VUID-vkCmdResolveImage-commandBuffer-cmdpool"); |
Mark Lobodzinski | fae179e | 2019-03-08 16:47:08 -0700 | [diff] [blame] | 2836 | skip |= ValidateCmd(cb_node, CMD_RESOLVEIMAGE, "vkCmdResolveImage()"); |
| 2837 | skip |= InsideRenderPass(cb_node, "vkCmdResolveImage()", "VUID-vkCmdResolveImage-renderpass"); |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 2838 | skip |= ValidateImageFormatFeatureFlags(dst_image_state, VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT, "vkCmdResolveImage()", |
| 2839 | "VUID-vkCmdResolveImage-dstImage-02003", "VUID-vkCmdResolveImage-dstImage-02003"); |
Mark Lobodzinski | 2a3368e | 2017-02-06 15:29:37 -0700 | [diff] [blame] | 2840 | |
Cort Stratton | 7df3096 | 2018-05-17 19:45:57 -0700 | [diff] [blame] | 2841 | bool hit_error = false; |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 2842 | const char *invalid_src_layout_vuid = |
Mark Lobodzinski | 60e7903 | 2019-03-07 10:22:31 -0700 | [diff] [blame] | 2843 | (src_image_state->shared_presentable && GetDeviceExtensions()->vk_khr_shared_presentable_image) |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 2844 | ? "VUID-vkCmdResolveImage-srcImageLayout-01400" |
| 2845 | : "VUID-vkCmdResolveImage-srcImageLayout-00261"; |
| 2846 | const char *invalid_dst_layout_vuid = |
Mark Lobodzinski | 60e7903 | 2019-03-07 10:22:31 -0700 | [diff] [blame] | 2847 | (dst_image_state->shared_presentable && GetDeviceExtensions()->vk_khr_shared_presentable_image) |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 2848 | ? "VUID-vkCmdResolveImage-dstImageLayout-01401" |
| 2849 | : "VUID-vkCmdResolveImage-dstImageLayout-00263"; |
Mark Lobodzinski | 2a3368e | 2017-02-06 15:29:37 -0700 | [diff] [blame] | 2850 | // For each region, the number of layers in the image subresource should not be zero |
| 2851 | // For each region, src and dest image aspect must be color only |
| 2852 | for (uint32_t i = 0; i < regionCount; i++) { |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 2853 | skip |= |
| 2854 | ValidateImageSubresourceLayers(cb_node, &pRegions[i].srcSubresource, "vkCmdResolveImage()", "srcSubresource", i); |
| 2855 | skip |= |
| 2856 | ValidateImageSubresourceLayers(cb_node, &pRegions[i].dstSubresource, "vkCmdResolveImage()", "dstSubresource", i); |
Mark Lobodzinski | 8564e44 | 2019-03-07 12:49:41 -0700 | [diff] [blame] | 2857 | skip |= VerifyImageLayout(cb_node, src_image_state, pRegions[i].srcSubresource, srcImageLayout, |
Cort Stratton | 7df3096 | 2018-05-17 19:45:57 -0700 | [diff] [blame] | 2858 | VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, "vkCmdResolveImage()", invalid_src_layout_vuid, |
| 2859 | "VUID-vkCmdResolveImage-srcImageLayout-00260", &hit_error); |
Mark Lobodzinski | 8564e44 | 2019-03-07 12:49:41 -0700 | [diff] [blame] | 2860 | skip |= VerifyImageLayout(cb_node, dst_image_state, pRegions[i].dstSubresource, dstImageLayout, |
Cort Stratton | 7df3096 | 2018-05-17 19:45:57 -0700 | [diff] [blame] | 2861 | VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, "vkCmdResolveImage()", invalid_dst_layout_vuid, |
| 2862 | "VUID-vkCmdResolveImage-dstImageLayout-00262", &hit_error); |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 2863 | skip |= ValidateImageMipLevel(cb_node, src_image_state, pRegions[i].srcSubresource.mipLevel, i, "vkCmdResolveImage()", |
| 2864 | "srcSubresource", "VUID-vkCmdResolveImage-srcSubresource-01709"); |
| 2865 | skip |= ValidateImageMipLevel(cb_node, dst_image_state, pRegions[i].dstSubresource.mipLevel, i, "vkCmdResolveImage()", |
| 2866 | "dstSubresource", "VUID-vkCmdResolveImage-dstSubresource-01710"); |
| 2867 | skip |= ValidateImageArrayLayerRange(cb_node, src_image_state, pRegions[i].srcSubresource.baseArrayLayer, |
Cort Stratton | ff1542a | 2018-05-27 10:49:28 -0700 | [diff] [blame] | 2868 | pRegions[i].srcSubresource.layerCount, i, "vkCmdResolveImage()", "srcSubresource", |
| 2869 | "VUID-vkCmdResolveImage-srcSubresource-01711"); |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 2870 | skip |= ValidateImageArrayLayerRange(cb_node, dst_image_state, pRegions[i].dstSubresource.baseArrayLayer, |
Cort Stratton | ff1542a | 2018-05-27 10:49:28 -0700 | [diff] [blame] | 2871 | pRegions[i].dstSubresource.layerCount, i, "vkCmdResolveImage()", "srcSubresource", |
| 2872 | "VUID-vkCmdResolveImage-dstSubresource-01712"); |
Cort Stratton | 7df3096 | 2018-05-17 19:45:57 -0700 | [diff] [blame] | 2873 | |
| 2874 | // layer counts must match |
Mark Lobodzinski | 50fbef1 | 2017-02-06 15:31:33 -0700 | [diff] [blame] | 2875 | if (pRegions[i].srcSubresource.layerCount != pRegions[i].dstSubresource.layerCount) { |
| 2876 | skip |= log_msg( |
| 2877 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 2878 | HandleToUint64(cb_node->commandBuffer), "VUID-VkImageResolve-layerCount-00267", |
Graeme Leese | 79b60cb | 2018-11-28 11:51:20 +0000 | [diff] [blame] | 2879 | "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] | 2880 | } |
Cort Stratton | 7df3096 | 2018-05-17 19:45:57 -0700 | [diff] [blame] | 2881 | // For each region, src and dest image aspect must be color only |
Mark Lobodzinski | 2a3368e | 2017-02-06 15:29:37 -0700 | [diff] [blame] | 2882 | if ((pRegions[i].srcSubresource.aspectMask != VK_IMAGE_ASPECT_COLOR_BIT) || |
| 2883 | (pRegions[i].dstSubresource.aspectMask != VK_IMAGE_ASPECT_COLOR_BIT)) { |
| 2884 | char const str[] = |
Graeme Leese | 79b60cb | 2018-11-28 11:51:20 +0000 | [diff] [blame] | 2885 | "vkCmdResolveImage(): src and dest aspectMasks for each region must specify only VK_IMAGE_ASPECT_COLOR_BIT"; |
Mark Lobodzinski | 2a3368e | 2017-02-06 15:29:37 -0700 | [diff] [blame] | 2886 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 2887 | HandleToUint64(cb_node->commandBuffer), "VUID-VkImageResolve-aspectMask-00266", "%s.", str); |
Mark Lobodzinski | 2a3368e | 2017-02-06 15:29:37 -0700 | [diff] [blame] | 2888 | } |
| 2889 | } |
| 2890 | |
| 2891 | if (src_image_state->createInfo.format != dst_image_state->createInfo.format) { |
| 2892 | char const str[] = "vkCmdResolveImage called with unmatched source and dest formats."; |
Mark Lobodzinski | 50fbef1 | 2017-02-06 15:31:33 -0700 | [diff] [blame] | 2893 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Dave Houlton | 5165390 | 2018-06-22 17:32:13 -0600 | [diff] [blame] | 2894 | HandleToUint64(cb_node->commandBuffer), kVUID_Core_DrawState_MismatchedImageFormat, str); |
Mark Lobodzinski | 2a3368e | 2017-02-06 15:29:37 -0700 | [diff] [blame] | 2895 | } |
| 2896 | if (src_image_state->createInfo.imageType != dst_image_state->createInfo.imageType) { |
| 2897 | char const str[] = "vkCmdResolveImage called with unmatched source and dest image types."; |
Mark Lobodzinski | 50fbef1 | 2017-02-06 15:31:33 -0700 | [diff] [blame] | 2898 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Dave Houlton | 5165390 | 2018-06-22 17:32:13 -0600 | [diff] [blame] | 2899 | HandleToUint64(cb_node->commandBuffer), kVUID_Core_DrawState_MismatchedImageType, str); |
Mark Lobodzinski | 2a3368e | 2017-02-06 15:29:37 -0700 | [diff] [blame] | 2900 | } |
| 2901 | if (src_image_state->createInfo.samples == VK_SAMPLE_COUNT_1_BIT) { |
| 2902 | char const str[] = "vkCmdResolveImage called with source sample count less than 2."; |
| 2903 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 2904 | HandleToUint64(cb_node->commandBuffer), "VUID-vkCmdResolveImage-srcImage-00257", "%s.", str); |
Mark Lobodzinski | 2a3368e | 2017-02-06 15:29:37 -0700 | [diff] [blame] | 2905 | } |
| 2906 | if (dst_image_state->createInfo.samples != VK_SAMPLE_COUNT_1_BIT) { |
| 2907 | char const str[] = "vkCmdResolveImage called with dest sample count greater than 1."; |
| 2908 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 2909 | HandleToUint64(cb_node->commandBuffer), "VUID-vkCmdResolveImage-dstImage-00259", "%s.", str); |
Mark Lobodzinski | 2a3368e | 2017-02-06 15:29:37 -0700 | [diff] [blame] | 2910 | } |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 2911 | } else { |
| 2912 | assert(0); |
| 2913 | } |
| 2914 | return skip; |
| 2915 | } |
| 2916 | |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 2917 | void CoreChecks::PreCallRecordCmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 2918 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 2919 | const VkImageResolve *pRegions) { |
Mark Lobodzinski | 1b3a971 | 2019-03-06 15:51:47 -0700 | [diff] [blame] | 2920 | auto cb_node = GetCBNode(commandBuffer); |
Mark Lobodzinski | 8ddc23f | 2019-03-06 11:48:49 -0700 | [diff] [blame] | 2921 | auto src_image_state = GetImageState(srcImage); |
| 2922 | auto dst_image_state = GetImageState(dstImage); |
Mark Lobodzinski | 9a075c2 | 2019-01-10 14:30:39 -0700 | [diff] [blame] | 2923 | |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 2924 | // Update bindings between images and cmd buffer |
Mark Lobodzinski | fae179e | 2019-03-08 16:47:08 -0700 | [diff] [blame] | 2925 | AddCommandBufferBindingImage(cb_node, src_image_state); |
| 2926 | AddCommandBufferBindingImage(cb_node, dst_image_state); |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 2927 | } |
| 2928 | |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 2929 | bool CoreChecks::PreCallValidateCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 2930 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 2931 | const VkImageBlit *pRegions, VkFilter filter) { |
Mark Lobodzinski | 1b3a971 | 2019-03-06 15:51:47 -0700 | [diff] [blame] | 2932 | auto cb_node = GetCBNode(commandBuffer); |
Mark Lobodzinski | 8ddc23f | 2019-03-06 11:48:49 -0700 | [diff] [blame] | 2933 | auto src_image_state = GetImageState(srcImage); |
| 2934 | auto dst_image_state = GetImageState(dstImage); |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 2935 | |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 2936 | bool skip = false; |
John Zulauf | 5c2750c | 2018-01-30 15:04:56 -0700 | [diff] [blame] | 2937 | if (cb_node) { |
Mark Lobodzinski | fae179e | 2019-03-08 16:47:08 -0700 | [diff] [blame] | 2938 | skip |= ValidateCmd(cb_node, CMD_BLITIMAGE, "vkCmdBlitImage()"); |
John Zulauf | 5c2750c | 2018-01-30 15:04:56 -0700 | [diff] [blame] | 2939 | } |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 2940 | if (cb_node && src_image_state && dst_image_state) { |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 2941 | skip |= ValidateImageSampleCount(src_image_state, VK_SAMPLE_COUNT_1_BIT, "vkCmdBlitImage(): srcImage", |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 2942 | "VUID-vkCmdBlitImage-srcImage-00233"); |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 2943 | skip |= ValidateImageSampleCount(dst_image_state, VK_SAMPLE_COUNT_1_BIT, "vkCmdBlitImage(): dstImage", |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 2944 | "VUID-vkCmdBlitImage-dstImage-00234"); |
Mark Lobodzinski | 0ebe971 | 2019-03-07 13:39:07 -0700 | [diff] [blame] | 2945 | skip |= ValidateMemoryIsBoundToImage(src_image_state, "vkCmdBlitImage()", "VUID-vkCmdBlitImage-srcImage-00220"); |
| 2946 | skip |= ValidateMemoryIsBoundToImage(dst_image_state, "vkCmdBlitImage()", "VUID-vkCmdBlitImage-dstImage-00225"); |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 2947 | skip |= |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 2948 | ValidateImageUsageFlags(src_image_state, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, true, "VUID-vkCmdBlitImage-srcImage-00219", |
| 2949 | "vkCmdBlitImage()", "VK_IMAGE_USAGE_TRANSFER_SRC_BIT"); |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 2950 | skip |= |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 2951 | ValidateImageUsageFlags(dst_image_state, VK_IMAGE_USAGE_TRANSFER_DST_BIT, true, "VUID-vkCmdBlitImage-dstImage-00224", |
| 2952 | "vkCmdBlitImage()", "VK_IMAGE_USAGE_TRANSFER_DST_BIT"); |
Mark Lobodzinski | daea591 | 2019-03-07 14:47:09 -0700 | [diff] [blame] | 2953 | skip |= |
| 2954 | ValidateCmdQueueFlags(cb_node, "vkCmdBlitImage()", VK_QUEUE_GRAPHICS_BIT, "VUID-vkCmdBlitImage-commandBuffer-cmdpool"); |
Mark Lobodzinski | fae179e | 2019-03-08 16:47:08 -0700 | [diff] [blame] | 2955 | skip |= ValidateCmd(cb_node, CMD_BLITIMAGE, "vkCmdBlitImage()"); |
| 2956 | skip |= InsideRenderPass(cb_node, "vkCmdBlitImage()", "VUID-vkCmdBlitImage-renderpass"); |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 2957 | skip |= ValidateImageFormatFeatureFlags(src_image_state, VK_FORMAT_FEATURE_BLIT_SRC_BIT, "vkCmdBlitImage()", |
Shannon McPherson | 40c0cba | 2018-08-07 13:39:13 -0600 | [diff] [blame] | 2958 | "VUID-vkCmdBlitImage-srcImage-01999", "VUID-vkCmdBlitImage-srcImage-01999"); |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 2959 | skip |= ValidateImageFormatFeatureFlags(dst_image_state, VK_FORMAT_FEATURE_BLIT_DST_BIT, "vkCmdBlitImage()", |
Shannon McPherson | 40c0cba | 2018-08-07 13:39:13 -0600 | [diff] [blame] | 2960 | "VUID-vkCmdBlitImage-dstImage-02000", "VUID-vkCmdBlitImage-dstImage-02000"); |
Cort Stratton | 186b1a2 | 2018-05-01 20:18:06 -0400 | [diff] [blame] | 2961 | |
Tobin Ehlis | bb03e5f | 2017-05-11 08:52:51 -0600 | [diff] [blame] | 2962 | // 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] | 2963 | |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2964 | VkFormat src_format = src_image_state->createInfo.format; |
| 2965 | VkFormat dst_format = dst_image_state->createInfo.format; |
| 2966 | VkImageType src_type = src_image_state->createInfo.imageType; |
| 2967 | VkImageType dst_type = dst_image_state->createInfo.imageType; |
| 2968 | |
Cort Stratton | 186b1a2 | 2018-05-01 20:18:06 -0400 | [diff] [blame] | 2969 | if (VK_FILTER_LINEAR == filter) { |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 2970 | skip |= ValidateImageFormatFeatureFlags(src_image_state, VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT, |
Shannon McPherson | 40c0cba | 2018-08-07 13:39:13 -0600 | [diff] [blame] | 2971 | "vkCmdBlitImage()", "VUID-vkCmdBlitImage-filter-02001", |
| 2972 | "VUID-vkCmdBlitImage-filter-02001"); |
Cort Stratton | 186b1a2 | 2018-05-01 20:18:06 -0400 | [diff] [blame] | 2973 | } else if (VK_FILTER_CUBIC_IMG == filter) { |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 2974 | skip |= ValidateImageFormatFeatureFlags(src_image_state, VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_CUBIC_BIT_IMG, |
| 2975 | "vkCmdBlitImage()", "VUID-vkCmdBlitImage-filter-02002", |
| 2976 | "VUID-vkCmdBlitImage-filter-02002"); |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2977 | } |
| 2978 | |
| 2979 | if ((VK_FILTER_CUBIC_IMG == filter) && (VK_IMAGE_TYPE_3D != src_type)) { |
| 2980 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 2981 | HandleToUint64(cb_node->commandBuffer), "VUID-vkCmdBlitImage-filter-00237", |
Graeme Leese | 79b60cb | 2018-11-28 11:51:20 +0000 | [diff] [blame] | 2982 | "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] | 2983 | } |
| 2984 | |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2985 | if ((VK_SAMPLE_COUNT_1_BIT != src_image_state->createInfo.samples) || |
| 2986 | (VK_SAMPLE_COUNT_1_BIT != dst_image_state->createInfo.samples)) { |
| 2987 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 2988 | HandleToUint64(cb_node->commandBuffer), "VUID-vkCmdBlitImage-srcImage-00228", |
Graeme Leese | 79b60cb | 2018-11-28 11:51:20 +0000 | [diff] [blame] | 2989 | "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] | 2990 | } |
| 2991 | |
| 2992 | // Validate consistency for unsigned formats |
| 2993 | if (FormatIsUInt(src_format) != FormatIsUInt(dst_format)) { |
| 2994 | std::stringstream ss; |
Graeme Leese | 79b60cb | 2018-11-28 11:51:20 +0000 | [diff] [blame] | 2995 | ss << "vkCmdBlitImage(): If one of srcImage and dstImage images has unsigned integer format, " |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 2996 | << "the other one must also have unsigned integer format. " |
| 2997 | << "Source format is " << string_VkFormat(src_format) << " Destination format is " << string_VkFormat(dst_format); |
| 2998 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 2999 | HandleToUint64(cb_node->commandBuffer), "VUID-vkCmdBlitImage-srcImage-00230", "%s.", ss.str().c_str()); |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 3000 | } |
| 3001 | |
| 3002 | // Validate consistency for signed formats |
| 3003 | if (FormatIsSInt(src_format) != FormatIsSInt(dst_format)) { |
| 3004 | std::stringstream ss; |
Graeme Leese | 79b60cb | 2018-11-28 11:51:20 +0000 | [diff] [blame] | 3005 | ss << "vkCmdBlitImage(): If one of srcImage and dstImage images has signed integer format, " |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 3006 | << "the other one must also have signed integer format. " |
| 3007 | << "Source format is " << string_VkFormat(src_format) << " Destination format is " << string_VkFormat(dst_format); |
| 3008 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 3009 | HandleToUint64(cb_node->commandBuffer), "VUID-vkCmdBlitImage-srcImage-00229", "%s.", ss.str().c_str()); |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 3010 | } |
| 3011 | |
| 3012 | // Validate filter for Depth/Stencil formats |
| 3013 | if (FormatIsDepthOrStencil(src_format) && (filter != VK_FILTER_NEAREST)) { |
| 3014 | std::stringstream ss; |
Graeme Leese | 79b60cb | 2018-11-28 11:51:20 +0000 | [diff] [blame] | 3015 | ss << "vkCmdBlitImage(): If the format of srcImage is a depth, stencil, or depth stencil " |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 3016 | << "then filter must be VK_FILTER_NEAREST."; |
| 3017 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 3018 | HandleToUint64(cb_node->commandBuffer), "VUID-vkCmdBlitImage-srcImage-00232", "%s.", ss.str().c_str()); |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 3019 | } |
| 3020 | |
| 3021 | // Validate aspect bits and formats for depth/stencil images |
| 3022 | if (FormatIsDepthOrStencil(src_format) || FormatIsDepthOrStencil(dst_format)) { |
| 3023 | if (src_format != dst_format) { |
| 3024 | std::stringstream ss; |
Graeme Leese | 79b60cb | 2018-11-28 11:51:20 +0000 | [diff] [blame] | 3025 | ss << "vkCmdBlitImage(): If one of srcImage and dstImage images has a format of depth, stencil or depth " |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 3026 | << "stencil, the other one must have exactly the same format. " |
| 3027 | << "Source format is " << string_VkFormat(src_format) << " Destination format is " |
| 3028 | << string_VkFormat(dst_format); |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 3029 | skip |= |
| 3030 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 3031 | HandleToUint64(cb_node->commandBuffer), "VUID-vkCmdBlitImage-srcImage-00231", "%s.", ss.str().c_str()); |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 3032 | } |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 3033 | } // Depth or Stencil |
| 3034 | |
| 3035 | // Do per-region checks |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 3036 | const char *invalid_src_layout_vuid = |
Mark Lobodzinski | 60e7903 | 2019-03-07 10:22:31 -0700 | [diff] [blame] | 3037 | (src_image_state->shared_presentable && GetDeviceExtensions()->vk_khr_shared_presentable_image) |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 3038 | ? "VUID-vkCmdBlitImage-srcImageLayout-01398" |
| 3039 | : "VUID-vkCmdBlitImage-srcImageLayout-00222"; |
| 3040 | const char *invalid_dst_layout_vuid = |
Mark Lobodzinski | 60e7903 | 2019-03-07 10:22:31 -0700 | [diff] [blame] | 3041 | (dst_image_state->shared_presentable && GetDeviceExtensions()->vk_khr_shared_presentable_image) |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 3042 | ? "VUID-vkCmdBlitImage-dstImageLayout-01399" |
| 3043 | : "VUID-vkCmdBlitImage-dstImageLayout-00227"; |
Mark Lobodzinski | 9a075c2 | 2019-01-10 14:30:39 -0700 | [diff] [blame] | 3044 | for (uint32_t i = 0; i < regionCount; i++) { |
| 3045 | const VkImageBlit rgn = pRegions[i]; |
Norbert Garnys | 7bd4c2c | 2017-11-16 10:58:04 +0100 | [diff] [blame] | 3046 | bool hit_error = false; |
Mark Lobodzinski | 8564e44 | 2019-03-07 12:49:41 -0700 | [diff] [blame] | 3047 | skip |= VerifyImageLayout(cb_node, src_image_state, rgn.srcSubresource, srcImageLayout, |
Cort Stratton | 7df3096 | 2018-05-17 19:45:57 -0700 | [diff] [blame] | 3048 | VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, "vkCmdBlitImage()", invalid_src_layout_vuid, |
| 3049 | "VUID-vkCmdBlitImage-srcImageLayout-00221", &hit_error); |
Mark Lobodzinski | 8564e44 | 2019-03-07 12:49:41 -0700 | [diff] [blame] | 3050 | skip |= VerifyImageLayout(cb_node, dst_image_state, rgn.dstSubresource, dstImageLayout, |
Cort Stratton | 7df3096 | 2018-05-17 19:45:57 -0700 | [diff] [blame] | 3051 | VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, "vkCmdBlitImage()", invalid_dst_layout_vuid, |
| 3052 | "VUID-vkCmdBlitImage-dstImageLayout-00226", &hit_error); |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 3053 | skip |= ValidateImageSubresourceLayers(cb_node, &rgn.srcSubresource, "vkCmdBlitImage()", "srcSubresource", i); |
| 3054 | skip |= ValidateImageSubresourceLayers(cb_node, &rgn.dstSubresource, "vkCmdBlitImage()", "dstSubresource", i); |
| 3055 | skip |= ValidateImageMipLevel(cb_node, src_image_state, rgn.srcSubresource.mipLevel, i, "vkCmdBlitImage()", |
Cort Stratton | ff1542a | 2018-05-27 10:49:28 -0700 | [diff] [blame] | 3056 | "srcSubresource", "VUID-vkCmdBlitImage-srcSubresource-01705"); |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 3057 | skip |= ValidateImageMipLevel(cb_node, dst_image_state, rgn.dstSubresource.mipLevel, i, "vkCmdBlitImage()", |
Cort Stratton | ff1542a | 2018-05-27 10:49:28 -0700 | [diff] [blame] | 3058 | "dstSubresource", "VUID-vkCmdBlitImage-dstSubresource-01706"); |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 3059 | skip |= ValidateImageArrayLayerRange(cb_node, src_image_state, rgn.srcSubresource.baseArrayLayer, |
Cort Stratton | ff1542a | 2018-05-27 10:49:28 -0700 | [diff] [blame] | 3060 | rgn.srcSubresource.layerCount, i, "vkCmdBlitImage()", "srcSubresource", |
| 3061 | "VUID-vkCmdBlitImage-srcSubresource-01707"); |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 3062 | skip |= ValidateImageArrayLayerRange(cb_node, dst_image_state, rgn.dstSubresource.baseArrayLayer, |
Cort Stratton | ff1542a | 2018-05-27 10:49:28 -0700 | [diff] [blame] | 3063 | rgn.dstSubresource.layerCount, i, "vkCmdBlitImage()", "dstSubresource", |
| 3064 | "VUID-vkCmdBlitImage-dstSubresource-01708"); |
Mark Lobodzinski | 23c8114 | 2017-02-06 15:04:23 -0700 | [diff] [blame] | 3065 | // Warn for zero-sized regions |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 3066 | if ((rgn.srcOffsets[0].x == rgn.srcOffsets[1].x) || (rgn.srcOffsets[0].y == rgn.srcOffsets[1].y) || |
| 3067 | (rgn.srcOffsets[0].z == rgn.srcOffsets[1].z)) { |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 3068 | std::stringstream ss; |
Graeme Leese | 79b60cb | 2018-11-28 11:51:20 +0000 | [diff] [blame] | 3069 | ss << "vkCmdBlitImage(): pRegions[" << i << "].srcOffsets specify a zero-volume area."; |
Dave Houlton | 5165390 | 2018-06-22 17:32:13 -0600 | [diff] [blame] | 3070 | skip |= |
| 3071 | log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 3072 | HandleToUint64(cb_node->commandBuffer), kVUID_Core_DrawState_InvalidExtents, "%s", ss.str().c_str()); |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 3073 | } |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 3074 | if ((rgn.dstOffsets[0].x == rgn.dstOffsets[1].x) || (rgn.dstOffsets[0].y == rgn.dstOffsets[1].y) || |
| 3075 | (rgn.dstOffsets[0].z == rgn.dstOffsets[1].z)) { |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 3076 | std::stringstream ss; |
Graeme Leese | 79b60cb | 2018-11-28 11:51:20 +0000 | [diff] [blame] | 3077 | ss << "vkCmdBlitImage(): pRegions[" << i << "].dstOffsets specify a zero-volume area."; |
Dave Houlton | 5165390 | 2018-06-22 17:32:13 -0600 | [diff] [blame] | 3078 | skip |= |
| 3079 | log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 3080 | HandleToUint64(cb_node->commandBuffer), kVUID_Core_DrawState_InvalidExtents, "%s", ss.str().c_str()); |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 3081 | } |
Mark Lobodzinski | 23c8114 | 2017-02-06 15:04:23 -0700 | [diff] [blame] | 3082 | |
| 3083 | // Check that src/dst layercounts match |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 3084 | if (rgn.srcSubresource.layerCount != rgn.dstSubresource.layerCount) { |
Graeme Leese | 79b60cb | 2018-11-28 11:51:20 +0000 | [diff] [blame] | 3085 | skip |= log_msg( |
| 3086 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 3087 | HandleToUint64(cb_node->commandBuffer), "VUID-VkImageBlit-layerCount-00239", |
| 3088 | "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] | 3089 | } |
Mark Lobodzinski | e7e85fd | 2017-02-07 13:44:57 -0700 | [diff] [blame] | 3090 | |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 3091 | if (rgn.srcSubresource.aspectMask != rgn.dstSubresource.aspectMask) { |
Mark Lobodzinski | e7e85fd | 2017-02-07 13:44:57 -0700 | [diff] [blame] | 3092 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 3093 | HandleToUint64(cb_node->commandBuffer), "VUID-VkImageBlit-aspectMask-00238", |
Graeme Leese | 79b60cb | 2018-11-28 11:51:20 +0000 | [diff] [blame] | 3094 | "vkCmdBlitImage(): aspectMask members for pRegion[%d] do not match.", i); |
Mark Lobodzinski | e7e85fd | 2017-02-07 13:44:57 -0700 | [diff] [blame] | 3095 | } |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 3096 | |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 3097 | if (!VerifyAspectsPresent(rgn.srcSubresource.aspectMask, src_format)) { |
| 3098 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 3099 | HandleToUint64(cb_node->commandBuffer), "VUID-VkImageBlit-aspectMask-00241", |
Graeme Leese | 79b60cb | 2018-11-28 11:51:20 +0000 | [diff] [blame] | 3100 | "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] | 3101 | "image format %s.", |
| 3102 | i, rgn.srcSubresource.aspectMask, string_VkFormat(src_format)); |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 3103 | } |
| 3104 | |
| 3105 | if (!VerifyAspectsPresent(rgn.dstSubresource.aspectMask, dst_format)) { |
| 3106 | skip |= log_msg( |
| 3107 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 3108 | HandleToUint64(cb_node->commandBuffer), "VUID-VkImageBlit-aspectMask-00242", |
Graeme Leese | 79b60cb | 2018-11-28 11:51:20 +0000 | [diff] [blame] | 3109 | "vkCmdBlitImage(): region [%d] dest aspectMask (0x%x) specifies aspects not present in dest image format %s.", |
| 3110 | i, rgn.dstSubresource.aspectMask, string_VkFormat(dst_format)); |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 3111 | } |
| 3112 | |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 3113 | // Validate source image offsets |
| 3114 | VkExtent3D src_extent = GetImageSubresourceExtent(src_image_state, &(rgn.srcSubresource)); |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 3115 | if (VK_IMAGE_TYPE_1D == src_type) { |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 3116 | if ((0 != rgn.srcOffsets[0].y) || (1 != rgn.srcOffsets[1].y)) { |
Graeme Leese | 79b60cb | 2018-11-28 11:51:20 +0000 | [diff] [blame] | 3117 | skip |= |
| 3118 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 3119 | HandleToUint64(cb_node->commandBuffer), "VUID-VkImageBlit-srcImage-00245", |
| 3120 | "vkCmdBlitImage(): region [%d], source image of type VK_IMAGE_TYPE_1D with srcOffset[].y values " |
| 3121 | "of (%1d, %1d). These must be (0, 1).", |
| 3122 | i, rgn.srcOffsets[0].y, rgn.srcOffsets[1].y); |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 3123 | } |
| 3124 | } |
| 3125 | |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 3126 | 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] | 3127 | if ((0 != rgn.srcOffsets[0].z) || (1 != rgn.srcOffsets[1].z)) { |
| 3128 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 3129 | HandleToUint64(cb_node->commandBuffer), "VUID-VkImageBlit-srcImage-00247", |
Graeme Leese | 79b60cb | 2018-11-28 11:51:20 +0000 | [diff] [blame] | 3130 | "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] | 3131 | "srcOffset[].z values of (%1d, %1d). These must be (0, 1).", |
| 3132 | i, rgn.srcOffsets[0].z, rgn.srcOffsets[1].z); |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 3133 | } |
| 3134 | } |
| 3135 | |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 3136 | bool oob = false; |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 3137 | if ((rgn.srcOffsets[0].x < 0) || (rgn.srcOffsets[0].x > static_cast<int32_t>(src_extent.width)) || |
| 3138 | (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] | 3139 | oob = true; |
Graeme Leese | 79b60cb | 2018-11-28 11:51:20 +0000 | [diff] [blame] | 3140 | skip |= log_msg( |
| 3141 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 3142 | HandleToUint64(cb_node->commandBuffer), "VUID-VkImageBlit-srcOffset-00243", |
| 3143 | "vkCmdBlitImage(): region [%d] srcOffset[].x values (%1d, %1d) exceed srcSubresource width extent (%1d).", i, |
| 3144 | rgn.srcOffsets[0].x, rgn.srcOffsets[1].x, src_extent.width); |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 3145 | } |
| 3146 | if ((rgn.srcOffsets[0].y < 0) || (rgn.srcOffsets[0].y > static_cast<int32_t>(src_extent.height)) || |
| 3147 | (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] | 3148 | oob = true; |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 3149 | skip |= log_msg( |
| 3150 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 3151 | HandleToUint64(cb_node->commandBuffer), "VUID-VkImageBlit-srcOffset-00244", |
Graeme Leese | 79b60cb | 2018-11-28 11:51:20 +0000 | [diff] [blame] | 3152 | "vkCmdBlitImage(): region [%d] srcOffset[].y values (%1d, %1d) exceed srcSubresource height extent (%1d).", i, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3153 | rgn.srcOffsets[0].y, rgn.srcOffsets[1].y, src_extent.height); |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 3154 | } |
| 3155 | if ((rgn.srcOffsets[0].z < 0) || (rgn.srcOffsets[0].z > static_cast<int32_t>(src_extent.depth)) || |
| 3156 | (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] | 3157 | oob = true; |
Graeme Leese | 79b60cb | 2018-11-28 11:51:20 +0000 | [diff] [blame] | 3158 | skip |= log_msg( |
| 3159 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 3160 | HandleToUint64(cb_node->commandBuffer), "VUID-VkImageBlit-srcOffset-00246", |
| 3161 | "vkCmdBlitImage(): region [%d] srcOffset[].z values (%1d, %1d) exceed srcSubresource depth extent (%1d).", i, |
| 3162 | rgn.srcOffsets[0].z, rgn.srcOffsets[1].z, src_extent.depth); |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 3163 | } |
Cort Stratton | ff1542a | 2018-05-27 10:49:28 -0700 | [diff] [blame] | 3164 | if (oob) { |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 3165 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 3166 | HandleToUint64(cb_node->commandBuffer), "VUID-vkCmdBlitImage-pRegions-00215", |
Graeme Leese | 79b60cb | 2018-11-28 11:51:20 +0000 | [diff] [blame] | 3167 | "vkCmdBlitImage(): region [%d] source image blit region exceeds image dimensions.", i); |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 3168 | } |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 3169 | |
| 3170 | // Validate dest image offsets |
| 3171 | VkExtent3D dst_extent = GetImageSubresourceExtent(dst_image_state, &(rgn.dstSubresource)); |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 3172 | if (VK_IMAGE_TYPE_1D == dst_type) { |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 3173 | if ((0 != rgn.dstOffsets[0].y) || (1 != rgn.dstOffsets[1].y)) { |
Graeme Leese | 79b60cb | 2018-11-28 11:51:20 +0000 | [diff] [blame] | 3174 | skip |= |
| 3175 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 3176 | HandleToUint64(cb_node->commandBuffer), "VUID-VkImageBlit-dstImage-00250", |
| 3177 | "vkCmdBlitImage(): region [%d], dest image of type VK_IMAGE_TYPE_1D with dstOffset[].y values of " |
| 3178 | "(%1d, %1d). These must be (0, 1).", |
| 3179 | i, rgn.dstOffsets[0].y, rgn.dstOffsets[1].y); |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 3180 | } |
| 3181 | } |
| 3182 | |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 3183 | 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] | 3184 | if ((0 != rgn.dstOffsets[0].z) || (1 != rgn.dstOffsets[1].z)) { |
| 3185 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 3186 | HandleToUint64(cb_node->commandBuffer), "VUID-VkImageBlit-dstImage-00252", |
Graeme Leese | 79b60cb | 2018-11-28 11:51:20 +0000 | [diff] [blame] | 3187 | "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] | 3188 | "dstOffset[].z values of (%1d, %1d). These must be (0, 1).", |
| 3189 | i, rgn.dstOffsets[0].z, rgn.dstOffsets[1].z); |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 3190 | } |
| 3191 | } |
| 3192 | |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 3193 | oob = false; |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 3194 | if ((rgn.dstOffsets[0].x < 0) || (rgn.dstOffsets[0].x > static_cast<int32_t>(dst_extent.width)) || |
| 3195 | (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] | 3196 | oob = true; |
Graeme Leese | 79b60cb | 2018-11-28 11:51:20 +0000 | [diff] [blame] | 3197 | skip |= log_msg( |
| 3198 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 3199 | HandleToUint64(cb_node->commandBuffer), "VUID-VkImageBlit-dstOffset-00248", |
| 3200 | "vkCmdBlitImage(): region [%d] dstOffset[].x values (%1d, %1d) exceed dstSubresource width extent (%1d).", i, |
| 3201 | rgn.dstOffsets[0].x, rgn.dstOffsets[1].x, dst_extent.width); |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 3202 | } |
| 3203 | if ((rgn.dstOffsets[0].y < 0) || (rgn.dstOffsets[0].y > static_cast<int32_t>(dst_extent.height)) || |
| 3204 | (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] | 3205 | oob = true; |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 3206 | skip |= log_msg( |
| 3207 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 3208 | HandleToUint64(cb_node->commandBuffer), "VUID-VkImageBlit-dstOffset-00249", |
Graeme Leese | 79b60cb | 2018-11-28 11:51:20 +0000 | [diff] [blame] | 3209 | "vkCmdBlitImage(): region [%d] dstOffset[].y values (%1d, %1d) exceed dstSubresource height extent (%1d).", i, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3210 | rgn.dstOffsets[0].y, rgn.dstOffsets[1].y, dst_extent.height); |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 3211 | } |
| 3212 | if ((rgn.dstOffsets[0].z < 0) || (rgn.dstOffsets[0].z > static_cast<int32_t>(dst_extent.depth)) || |
| 3213 | (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] | 3214 | oob = true; |
Graeme Leese | 79b60cb | 2018-11-28 11:51:20 +0000 | [diff] [blame] | 3215 | skip |= log_msg( |
| 3216 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 3217 | HandleToUint64(cb_node->commandBuffer), "VUID-VkImageBlit-dstOffset-00251", |
| 3218 | "vkCmdBlitImage(): region [%d] dstOffset[].z values (%1d, %1d) exceed dstSubresource depth extent (%1d).", i, |
| 3219 | rgn.dstOffsets[0].z, rgn.dstOffsets[1].z, dst_extent.depth); |
Dave Houlton | 48989f3 | 2017-05-26 15:01:46 -0600 | [diff] [blame] | 3220 | } |
Cort Stratton | ff1542a | 2018-05-27 10:49:28 -0700 | [diff] [blame] | 3221 | if (oob) { |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 3222 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 3223 | HandleToUint64(cb_node->commandBuffer), "VUID-vkCmdBlitImage-pRegions-00216", |
Graeme Leese | 79b60cb | 2018-11-28 11:51:20 +0000 | [diff] [blame] | 3224 | "vkCmdBlitImage(): region [%d] destination image blit region exceeds image dimensions.", i); |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 3225 | } |
| 3226 | |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 3227 | if ((VK_IMAGE_TYPE_3D == src_type) || (VK_IMAGE_TYPE_3D == dst_type)) { |
| 3228 | if ((0 != rgn.srcSubresource.baseArrayLayer) || (1 != rgn.srcSubresource.layerCount) || |
| 3229 | (0 != rgn.dstSubresource.baseArrayLayer) || (1 != rgn.dstSubresource.layerCount)) { |
Graeme Leese | 79b60cb | 2018-11-28 11:51:20 +0000 | [diff] [blame] | 3230 | skip |= |
| 3231 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 3232 | HandleToUint64(cb_node->commandBuffer), "VUID-VkImageBlit-srcImage-00240", |
| 3233 | "vkCmdBlitImage(): region [%d] blit to/from a 3D image type with a non-zero baseArrayLayer, or a " |
| 3234 | "layerCount other than 1.", |
| 3235 | i); |
Mark Lobodzinski | 9ad9658 | 2017-02-06 14:01:54 -0700 | [diff] [blame] | 3236 | } |
| 3237 | } |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 3238 | } // per-region checks |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 3239 | } else { |
| 3240 | assert(0); |
| 3241 | } |
| 3242 | return skip; |
| 3243 | } |
| 3244 | |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 3245 | void CoreChecks::PreCallRecordCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 3246 | VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, |
| 3247 | const VkImageBlit *pRegions, VkFilter filter) { |
Mark Lobodzinski | 1b3a971 | 2019-03-06 15:51:47 -0700 | [diff] [blame] | 3248 | auto cb_node = GetCBNode(commandBuffer); |
Mark Lobodzinski | 8ddc23f | 2019-03-06 11:48:49 -0700 | [diff] [blame] | 3249 | auto src_image_state = GetImageState(srcImage); |
| 3250 | auto dst_image_state = GetImageState(dstImage); |
Mark Lobodzinski | 9a075c2 | 2019-01-10 14:30:39 -0700 | [diff] [blame] | 3251 | |
Norbert Garnys | 7bd4c2c | 2017-11-16 10:58:04 +0100 | [diff] [blame] | 3252 | // Make sure that all image slices are updated to correct layout |
Mark Lobodzinski | 9a075c2 | 2019-01-10 14:30:39 -0700 | [diff] [blame] | 3253 | for (uint32_t i = 0; i < regionCount; ++i) { |
John Zulauf | f660ad6 | 2019-03-23 07:16:05 -0600 | [diff] [blame] | 3254 | SetImageInitialLayout(cb_node, *src_image_state, pRegions[i].srcSubresource, srcImageLayout); |
| 3255 | SetImageInitialLayout(cb_node, *dst_image_state, pRegions[i].dstSubresource, dstImageLayout); |
Norbert Garnys | 7bd4c2c | 2017-11-16 10:58:04 +0100 | [diff] [blame] | 3256 | } |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 3257 | // Update bindings between images and cmd buffer |
Mark Lobodzinski | fae179e | 2019-03-08 16:47:08 -0700 | [diff] [blame] | 3258 | AddCommandBufferBindingImage(cb_node, src_image_state); |
| 3259 | AddCommandBufferBindingImage(cb_node, dst_image_state); |
Mark Lobodzinski | 8e0c0bf | 2017-02-06 11:06:26 -0700 | [diff] [blame] | 3260 | } |
| 3261 | |
Shannon McPherson | 449fa9c | 2018-10-25 11:51:07 -0600 | [diff] [blame] | 3262 | // This validates that the initial layout specified in the command buffer for the IMAGE is the same as the global IMAGE layout |
Mark Lobodzinski | ef4ab2e | 2019-03-07 13:23:36 -0700 | [diff] [blame] | 3263 | bool CoreChecks::ValidateCmdBufImageLayouts(GLOBAL_CB_NODE *pCB, |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 3264 | std::unordered_map<ImageSubresourcePair, IMAGE_LAYOUT_NODE> const &globalImageLayoutMap, |
| 3265 | std::unordered_map<ImageSubresourcePair, IMAGE_LAYOUT_NODE> &overlayLayoutMap) { |
Mark Lobodzinski | b0dd947 | 2017-02-07 16:38:17 -0700 | [diff] [blame] | 3266 | bool skip = false; |
John Zulauf | f660ad6 | 2019-03-23 07:16:05 -0600 | [diff] [blame] | 3267 | // Iterate over the layout maps for each referenced image |
| 3268 | for (const auto &layout_map_entry : pCB->image_layout_map) { |
| 3269 | const auto image = layout_map_entry.first; |
| 3270 | const auto *image_state = GetImageState(image); |
| 3271 | if (!image_state) continue; // Can't check layouts of a dead image |
| 3272 | const auto &subres_map = layout_map_entry.second; |
| 3273 | ImageSubresourcePair isr_pair; |
| 3274 | isr_pair.image = image; |
| 3275 | isr_pair.hasSubresource = true; |
Tony Barbour | df013b9 | 2017-01-25 12:53:48 -0700 | [diff] [blame] | 3276 | |
John Zulauf | f660ad6 | 2019-03-23 07:16:05 -0600 | [diff] [blame] | 3277 | // Validate the initial_uses for each subresource referenced |
| 3278 | for (auto it_init = subres_map->BeginInitialUse(); !it_init.AtEnd(); ++it_init) { |
| 3279 | isr_pair.subresource = (*it_init).subresource; |
| 3280 | VkImageLayout initial_layout = (*it_init).layout; |
| 3281 | VkImageLayout image_layout; |
| 3282 | if (FindLayout(overlayLayoutMap, isr_pair, image_layout) || FindLayout(globalImageLayoutMap, isr_pair, image_layout)) { |
| 3283 | if (initial_layout == VK_IMAGE_LAYOUT_UNDEFINED) { |
| 3284 | // TODO: Set memory invalid which is in mem_tracker currently |
| 3285 | } else if (image_layout != initial_layout) { |
John Zulauf | b61ed97 | 2019-04-09 16:12:35 -0600 | [diff] [blame] | 3286 | // Need to look up the inital layout *state* to get a bit more information |
| 3287 | const auto *initial_layout_state = subres_map->GetSubresourceInitialLayoutState(isr_pair.subresource); |
| 3288 | assert(initial_layout_state); // There's no way we should have an initial layout without matching state... |
| 3289 | bool matches = ImageLayoutMatches(initial_layout_state->aspect_mask, image_layout, initial_layout); |
| 3290 | if (!matches) { |
| 3291 | std::string formatted_label = FormatDebugLabel(" ", pCB->debug_label); |
| 3292 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 3293 | HandleToUint64(pCB->commandBuffer), kVUID_Core_DrawState_InvalidImageLayout, |
| 3294 | "Submitted command buffer expects image %s (subresource: aspectMask 0x%X array layer %u, " |
| 3295 | "mip level %u) " |
| 3296 | "to be in layout %s--instead, current layout is %s.%s", |
| 3297 | report_data->FormatHandle(image).c_str(), isr_pair.subresource.aspectMask, |
| 3298 | isr_pair.subresource.arrayLayer, isr_pair.subresource.mipLevel, |
| 3299 | string_VkImageLayout(initial_layout), string_VkImageLayout(image_layout), |
| 3300 | formatted_label.c_str()); |
| 3301 | } |
Mark Lobodzinski | 4a3065e | 2017-02-07 16:36:03 -0700 | [diff] [blame] | 3302 | } |
| 3303 | } |
John Zulauf | f660ad6 | 2019-03-23 07:16:05 -0600 | [diff] [blame] | 3304 | } |
| 3305 | |
| 3306 | // Update all layout set operations (which will be a subset of the initial_layouts |
| 3307 | for (auto it_set = subres_map->BeginSetLayout(); !it_set.AtEnd(); ++it_set) { |
| 3308 | VkImageLayout layout = (*it_set).layout; |
| 3309 | isr_pair.subresource = (*it_set).subresource; |
| 3310 | SetLayout(overlayLayoutMap, isr_pair, layout); |
Mark Lobodzinski | 4a3065e | 2017-02-07 16:36:03 -0700 | [diff] [blame] | 3311 | } |
| 3312 | } |
John Zulauf | f660ad6 | 2019-03-23 07:16:05 -0600 | [diff] [blame] | 3313 | |
Mark Lobodzinski | b0dd947 | 2017-02-07 16:38:17 -0700 | [diff] [blame] | 3314 | return skip; |
Mark Lobodzinski | 4a3065e | 2017-02-07 16:36:03 -0700 | [diff] [blame] | 3315 | } |
Mark Lobodzinski | b3829a5 | 2017-02-07 16:55:53 -0700 | [diff] [blame] | 3316 | |
Mark Lobodzinski | ef4ab2e | 2019-03-07 13:23:36 -0700 | [diff] [blame] | 3317 | void CoreChecks::UpdateCmdBufImageLayouts(GLOBAL_CB_NODE *pCB) { |
John Zulauf | f660ad6 | 2019-03-23 07:16:05 -0600 | [diff] [blame] | 3318 | for (const auto &layout_map_entry : pCB->image_layout_map) { |
| 3319 | const auto image = layout_map_entry.first; |
| 3320 | const auto *image_state = GetImageState(image); |
| 3321 | if (!image_state) continue; // Can't set layouts of a dead image |
| 3322 | const auto &subres_map = layout_map_entry.second; |
| 3323 | ImageSubresourcePair isr_pair; |
| 3324 | isr_pair.image = image; |
| 3325 | isr_pair.hasSubresource = true; |
| 3326 | |
| 3327 | // Update all layout set operations (which will be a subset of the initial_layouts |
| 3328 | for (auto it_set = subres_map->BeginSetLayout(); !it_set.AtEnd(); ++it_set) { |
| 3329 | VkImageLayout layout = (*it_set).layout; |
| 3330 | isr_pair.subresource = (*it_set).subresource; |
| 3331 | SetGlobalLayout(isr_pair, layout); |
| 3332 | } |
Tony Barbour | df013b9 | 2017-01-25 12:53:48 -0700 | [diff] [blame] | 3333 | } |
| 3334 | } |
| 3335 | |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 3336 | // 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] | 3337 | // VkAttachmentDescription structs that are used by the sub-passes of a renderpass. Initial check is to make sure that READ_ONLY |
| 3338 | // layout attachments don't have CLEAR as their loadOp. |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 3339 | bool CoreChecks::ValidateLayoutVsAttachmentDescription(const debug_report_data *report_data, RenderPassCreateVersion rp_version, |
| 3340 | const VkImageLayout first_layout, const uint32_t attachment, |
| 3341 | const VkAttachmentDescription2KHR &attachment_description) { |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 3342 | bool skip = false; |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 3343 | const char *vuid; |
| 3344 | const bool use_rp2 = (rp_version == RENDER_PASS_VERSION_2); |
| 3345 | |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 3346 | // Verify that initial loadOp on READ_ONLY attachments is not CLEAR |
| 3347 | if (attachment_description.loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR) { |
Shannon McPherson | 3ea6513 | 2018-12-05 10:37:39 -0700 | [diff] [blame] | 3348 | if (use_rp2 && ((first_layout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL) || |
| 3349 | (first_layout == VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) || |
| 3350 | (first_layout == VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL))) { |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 3351 | skip |= |
Shannon McPherson | 3ea6513 | 2018-12-05 10:37:39 -0700 | [diff] [blame] | 3352 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 3353 | "VUID-VkRenderPassCreateInfo2KHR-pAttachments-02522", |
| 3354 | "Cannot clear attachment %d with invalid first layout %s.", attachment, string_VkImageLayout(first_layout)); |
| 3355 | } else if (!use_rp2 && ((first_layout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL) || |
| 3356 | (first_layout == VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL))) { |
| 3357 | skip |= |
| 3358 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 3359 | "VUID-VkRenderPassCreateInfo-pAttachments-00836", |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 3360 | "Cannot clear attachment %d with invalid first layout %s.", attachment, string_VkImageLayout(first_layout)); |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 3361 | } |
| 3362 | } |
Slawomir Cygan | adf2b55 | 2018-04-24 17:18:26 +0200 | [diff] [blame] | 3363 | if (attachment_description.loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR) { |
| 3364 | if (first_layout == VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL) { |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 3365 | vuid = use_rp2 ? kVUID_Core_DrawState_InvalidRenderpass : "VUID-VkRenderPassCreateInfo-pAttachments-01566"; |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 3366 | skip |= |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 3367 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, vuid, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 3368 | "Cannot clear attachment %d with invalid first layout %s.", attachment, string_VkImageLayout(first_layout)); |
Slawomir Cygan | adf2b55 | 2018-04-24 17:18:26 +0200 | [diff] [blame] | 3369 | } |
| 3370 | } |
| 3371 | |
| 3372 | if (attachment_description.stencilLoadOp == VK_ATTACHMENT_LOAD_OP_CLEAR) { |
| 3373 | if (first_layout == VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL) { |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 3374 | vuid = use_rp2 ? kVUID_Core_DrawState_InvalidRenderpass : "VUID-VkRenderPassCreateInfo-pAttachments-01567"; |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 3375 | skip |= |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 3376 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, vuid, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 3377 | "Cannot clear attachment %d with invalid first layout %s.", attachment, string_VkImageLayout(first_layout)); |
Slawomir Cygan | adf2b55 | 2018-04-24 17:18:26 +0200 | [diff] [blame] | 3378 | } |
| 3379 | } |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 3380 | return skip; |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 3381 | } |
| 3382 | |
Mark Lobodzinski | ef4ab2e | 2019-03-07 13:23:36 -0700 | [diff] [blame] | 3383 | bool CoreChecks::ValidateLayouts(RenderPassCreateVersion rp_version, VkDevice device, |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 3384 | const VkRenderPassCreateInfo2KHR *pCreateInfo) { |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 3385 | bool skip = false; |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 3386 | const char *vuid; |
| 3387 | const bool use_rp2 = (rp_version == RENDER_PASS_VERSION_2); |
| 3388 | const char *const function_name = use_rp2 ? "vkCreateRenderPass2KHR()" : "vkCreateRenderPass()"; |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 3389 | |
Jason Ekstrand | a190630 | 2017-12-03 20:16:32 -0800 | [diff] [blame] | 3390 | for (uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) { |
| 3391 | VkFormat format = pCreateInfo->pAttachments[i].format; |
| 3392 | if (pCreateInfo->pAttachments[i].initialLayout == VK_IMAGE_LAYOUT_UNDEFINED) { |
| 3393 | if ((FormatIsColor(format) || FormatHasDepth(format)) && |
| 3394 | pCreateInfo->pAttachments[i].loadOp == VK_ATTACHMENT_LOAD_OP_LOAD) { |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 3395 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Dave Houlton | 5165390 | 2018-06-22 17:32:13 -0600 | [diff] [blame] | 3396 | kVUID_Core_DrawState_InvalidRenderpass, |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 3397 | "Render pass has an attachment with loadOp == VK_ATTACHMENT_LOAD_OP_LOAD and initialLayout == " |
| 3398 | "VK_IMAGE_LAYOUT_UNDEFINED. This is probably not what you intended. Consider using " |
| 3399 | "VK_ATTACHMENT_LOAD_OP_DONT_CARE instead if the image truely is undefined at the start of the " |
| 3400 | "render pass."); |
Jason Ekstrand | a190630 | 2017-12-03 20:16:32 -0800 | [diff] [blame] | 3401 | } |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 3402 | if (FormatHasStencil(format) && pCreateInfo->pAttachments[i].stencilLoadOp == VK_ATTACHMENT_LOAD_OP_LOAD) { |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 3403 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Dave Houlton | 5165390 | 2018-06-22 17:32:13 -0600 | [diff] [blame] | 3404 | kVUID_Core_DrawState_InvalidRenderpass, |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 3405 | "Render pass has an attachment with stencilLoadOp == VK_ATTACHMENT_LOAD_OP_LOAD and initialLayout " |
| 3406 | "== VK_IMAGE_LAYOUT_UNDEFINED. This is probably not what you intended. Consider using " |
| 3407 | "VK_ATTACHMENT_LOAD_OP_DONT_CARE instead if the image truely is undefined at the start of the " |
| 3408 | "render pass."); |
Jason Ekstrand | a190630 | 2017-12-03 20:16:32 -0800 | [diff] [blame] | 3409 | } |
| 3410 | } |
| 3411 | } |
| 3412 | |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 3413 | // Track when we're observing the first use of an attachment |
| 3414 | std::vector<bool> attach_first_use(pCreateInfo->attachmentCount, true); |
| 3415 | for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) { |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 3416 | const VkSubpassDescription2KHR &subpass = pCreateInfo->pSubpasses[i]; |
Cort Stratton | 7547f77 | 2017-05-04 15:18:52 -0700 | [diff] [blame] | 3417 | |
| 3418 | // Check input attachments first, so we can detect first-use-as-input for VU #00349 |
| 3419 | for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) { |
| 3420 | auto attach_index = subpass.pInputAttachments[j].attachment; |
| 3421 | if (attach_index == VK_ATTACHMENT_UNUSED) continue; |
Cort Stratton | 7547f77 | 2017-05-04 15:18:52 -0700 | [diff] [blame] | 3422 | switch (subpass.pInputAttachments[j].layout) { |
| 3423 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: |
| 3424 | case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: |
| 3425 | // These are ideal. |
| 3426 | break; |
| 3427 | |
| 3428 | case VK_IMAGE_LAYOUT_GENERAL: |
| 3429 | // May not be optimal. TODO: reconsider this warning based on other constraints. |
| 3430 | skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Dave Houlton | 5165390 | 2018-06-22 17:32:13 -0600 | [diff] [blame] | 3431 | VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, kVUID_Core_DrawState_InvalidImageLayout, |
Cort Stratton | 7547f77 | 2017-05-04 15:18:52 -0700 | [diff] [blame] | 3432 | "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL."); |
| 3433 | break; |
| 3434 | |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 3435 | case VK_IMAGE_LAYOUT_UNDEFINED: |
| 3436 | case VK_IMAGE_LAYOUT_PREINITIALIZED: |
| 3437 | vuid = use_rp2 ? "VUID-VkAttachmentReference2KHR-layout-03077" : "VUID-VkAttachmentReference-layout-00857"; |
| 3438 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, vuid, |
| 3439 | "Layout for input attachment reference %u in subpass %u is %s but must be " |
| 3440 | "DEPTH_STENCIL_READ_ONLY, SHADER_READ_ONLY_OPTIMAL, or GENERAL.", |
| 3441 | j, i, string_VkImageLayout(subpass.pDepthStencilAttachment->layout)); |
| 3442 | break; |
| 3443 | |
Graeme Leese | 668a986 | 2018-10-08 10:40:02 +0100 | [diff] [blame] | 3444 | case VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL_KHR: |
| 3445 | case VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL_KHR: |
Mark Lobodzinski | 60e7903 | 2019-03-07 10:22:31 -0700 | [diff] [blame] | 3446 | if (GetDeviceExtensions()->vk_khr_maintenance2) { |
Graeme Leese | 668a986 | 2018-10-08 10:40:02 +0100 | [diff] [blame] | 3447 | break; |
| 3448 | } else { |
| 3449 | // Intentionally fall through to generic error message |
| 3450 | } |
| 3451 | // fall through |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 3452 | |
Cort Stratton | 7547f77 | 2017-05-04 15:18:52 -0700 | [diff] [blame] | 3453 | default: |
| 3454 | // No other layouts are acceptable |
| 3455 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Dave Houlton | 5165390 | 2018-06-22 17:32:13 -0600 | [diff] [blame] | 3456 | kVUID_Core_DrawState_InvalidImageLayout, |
Cort Stratton | 7547f77 | 2017-05-04 15:18:52 -0700 | [diff] [blame] | 3457 | "Layout for input attachment is %s but can only be READ_ONLY_OPTIMAL or GENERAL.", |
| 3458 | string_VkImageLayout(subpass.pInputAttachments[j].layout)); |
| 3459 | } |
| 3460 | |
Cort Stratton | 7547f77 | 2017-05-04 15:18:52 -0700 | [diff] [blame] | 3461 | if (attach_first_use[attach_index]) { |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 3462 | skip |= ValidateLayoutVsAttachmentDescription(report_data, rp_version, subpass.pInputAttachments[j].layout, |
| 3463 | attach_index, pCreateInfo->pAttachments[attach_index]); |
Cort Stratton | 7547f77 | 2017-05-04 15:18:52 -0700 | [diff] [blame] | 3464 | |
| 3465 | bool used_as_depth = |
| 3466 | (subpass.pDepthStencilAttachment != NULL && subpass.pDepthStencilAttachment->attachment == attach_index); |
| 3467 | bool used_as_color = false; |
| 3468 | for (uint32_t k = 0; !used_as_depth && !used_as_color && k < subpass.colorAttachmentCount; ++k) { |
| 3469 | used_as_color = (subpass.pColorAttachments[k].attachment == attach_index); |
| 3470 | } |
| 3471 | if (!used_as_depth && !used_as_color && |
| 3472 | pCreateInfo->pAttachments[attach_index].loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR) { |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 3473 | vuid = use_rp2 ? "VUID-VkSubpassDescription2KHR-loadOp-03064" : "VUID-VkSubpassDescription-loadOp-00846"; |
| 3474 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, vuid, |
| 3475 | "%s: attachment %u is first used as an input attachment in subpass %u with loadOp=CLEAR.", |
| 3476 | function_name, attach_index, attach_index); |
Cort Stratton | 7547f77 | 2017-05-04 15:18:52 -0700 | [diff] [blame] | 3477 | } |
| 3478 | } |
| 3479 | attach_first_use[attach_index] = false; |
| 3480 | } |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 3481 | |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 3482 | for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) { |
| 3483 | auto attach_index = subpass.pColorAttachments[j].attachment; |
| 3484 | if (attach_index == VK_ATTACHMENT_UNUSED) continue; |
| 3485 | |
Tobin Ehlis | bb03e5f | 2017-05-11 08:52:51 -0600 | [diff] [blame] | 3486 | // TODO: Need a way to validate shared presentable images here, currently just allowing |
| 3487 | // VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR |
| 3488 | // 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] | 3489 | switch (subpass.pColorAttachments[j].layout) { |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 3490 | case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: |
Dave Houlton | 33c2d25 | 2017-06-09 17:08:32 -0600 | [diff] [blame] | 3491 | // This is ideal. |
Tobin Ehlis | bb03e5f | 2017-05-11 08:52:51 -0600 | [diff] [blame] | 3492 | case VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR: |
| 3493 | // 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] | 3494 | break; |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 3495 | |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 3496 | case VK_IMAGE_LAYOUT_GENERAL: |
| 3497 | // May not be optimal; TODO: reconsider this warning based on other constraints? |
| 3498 | skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Dave Houlton | 5165390 | 2018-06-22 17:32:13 -0600 | [diff] [blame] | 3499 | VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, kVUID_Core_DrawState_InvalidImageLayout, |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 3500 | "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL."); |
| 3501 | break; |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 3502 | |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 3503 | case VK_IMAGE_LAYOUT_UNDEFINED: |
| 3504 | case VK_IMAGE_LAYOUT_PREINITIALIZED: |
| 3505 | vuid = use_rp2 ? "VUID-VkAttachmentReference2KHR-layout-03077" : "VUID-VkAttachmentReference-layout-00857"; |
| 3506 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, vuid, |
| 3507 | "Layout for color attachment reference %u in subpass %u is %s but should be " |
| 3508 | "COLOR_ATTACHMENT_OPTIMAL or GENERAL.", |
| 3509 | j, i, string_VkImageLayout(subpass.pColorAttachments[j].layout)); |
| 3510 | break; |
| 3511 | |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 3512 | default: |
| 3513 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Dave Houlton | 5165390 | 2018-06-22 17:32:13 -0600 | [diff] [blame] | 3514 | kVUID_Core_DrawState_InvalidImageLayout, |
Mark Lobodzinski | 552e440 | 2017-02-07 17:14:53 -0700 | [diff] [blame] | 3515 | "Layout for color attachment is %s but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.", |
| 3516 | string_VkImageLayout(subpass.pColorAttachments[j].layout)); |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 3517 | } |
| 3518 | |
John Zulauf | 4eee269 | 2019-02-09 16:14:25 -0700 | [diff] [blame] | 3519 | if (subpass.pResolveAttachments && (subpass.pResolveAttachments[j].attachment != VK_ATTACHMENT_UNUSED) && |
| 3520 | (subpass.pResolveAttachments[j].layout == VK_IMAGE_LAYOUT_UNDEFINED || |
| 3521 | subpass.pResolveAttachments[j].layout == VK_IMAGE_LAYOUT_PREINITIALIZED)) { |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 3522 | vuid = use_rp2 ? "VUID-VkAttachmentReference2KHR-layout-03077" : "VUID-VkAttachmentReference-layout-00857"; |
| 3523 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, vuid, |
John Zulauf | 4eee269 | 2019-02-09 16:14:25 -0700 | [diff] [blame] | 3524 | "Layout for resolve attachment reference %u in subpass %u is %s but should be " |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 3525 | "COLOR_ATTACHMENT_OPTIMAL or GENERAL.", |
John Zulauf | f0f8c2b | 2019-02-14 12:13:44 -0700 | [diff] [blame] | 3526 | j, i, string_VkImageLayout(subpass.pResolveAttachments[j].layout)); |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 3527 | } |
| 3528 | |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 3529 | if (attach_first_use[attach_index]) { |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 3530 | skip |= ValidateLayoutVsAttachmentDescription(report_data, rp_version, subpass.pColorAttachments[j].layout, |
| 3531 | attach_index, pCreateInfo->pAttachments[attach_index]); |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 3532 | } |
| 3533 | attach_first_use[attach_index] = false; |
| 3534 | } |
Lenny Komow | b79f04a | 2017-09-18 17:07:00 -0600 | [diff] [blame] | 3535 | |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 3536 | if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) { |
| 3537 | switch (subpass.pDepthStencilAttachment->layout) { |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 3538 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: |
| 3539 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: |
| 3540 | // These are ideal. |
Lenny Komow | b79f04a | 2017-09-18 17:07:00 -0600 | [diff] [blame] | 3541 | break; |
Lenny Komow | b79f04a | 2017-09-18 17:07:00 -0600 | [diff] [blame] | 3542 | |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 3543 | case VK_IMAGE_LAYOUT_GENERAL: |
| 3544 | // May not be optimal; TODO: reconsider this warning based on other constraints? GENERAL can be better than |
| 3545 | // doing a bunch of transitions. |
| 3546 | skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Dave Houlton | 5165390 | 2018-06-22 17:32:13 -0600 | [diff] [blame] | 3547 | VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, kVUID_Core_DrawState_InvalidImageLayout, |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 3548 | "GENERAL layout for depth attachment may not give optimal performance."); |
| 3549 | break; |
| 3550 | |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 3551 | case VK_IMAGE_LAYOUT_UNDEFINED: |
| 3552 | case VK_IMAGE_LAYOUT_PREINITIALIZED: |
| 3553 | vuid = use_rp2 ? "VUID-VkAttachmentReference2KHR-layout-03077" : "VUID-VkAttachmentReference-layout-00857"; |
| 3554 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, vuid, |
| 3555 | "Layout for depth attachment reference in subpass %u is %s but must be a valid depth/stencil " |
| 3556 | "layout or GENERAL.", |
| 3557 | i, string_VkImageLayout(subpass.pDepthStencilAttachment->layout)); |
| 3558 | break; |
| 3559 | |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 3560 | case VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL_KHR: |
| 3561 | case VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL_KHR: |
Mark Lobodzinski | 60e7903 | 2019-03-07 10:22:31 -0700 | [diff] [blame] | 3562 | if (GetDeviceExtensions()->vk_khr_maintenance2) { |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 3563 | break; |
| 3564 | } else { |
| 3565 | // Intentionally fall through to generic error message |
| 3566 | } |
Tobin Ehlis | 648b1cf | 2018-04-13 15:24:13 -0600 | [diff] [blame] | 3567 | // fall through |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 3568 | |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 3569 | default: |
| 3570 | // No other layouts are acceptable |
| 3571 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Dave Houlton | 5165390 | 2018-06-22 17:32:13 -0600 | [diff] [blame] | 3572 | kVUID_Core_DrawState_InvalidImageLayout, |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 3573 | "Layout for depth attachment is %s but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL, " |
| 3574 | "DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.", |
| 3575 | string_VkImageLayout(subpass.pDepthStencilAttachment->layout)); |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 3576 | } |
| 3577 | |
| 3578 | auto attach_index = subpass.pDepthStencilAttachment->attachment; |
| 3579 | if (attach_first_use[attach_index]) { |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 3580 | skip |= ValidateLayoutVsAttachmentDescription(report_data, rp_version, subpass.pDepthStencilAttachment->layout, |
| 3581 | attach_index, pCreateInfo->pAttachments[attach_index]); |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 3582 | } |
| 3583 | attach_first_use[attach_index] = false; |
| 3584 | } |
Mark Lobodzinski | c679b03 | 2017-02-07 17:11:55 -0700 | [diff] [blame] | 3585 | } |
| 3586 | return skip; |
| 3587 | } |
Mark Lobodzinski | 08f14fa | 2017-02-07 17:20:06 -0700 | [diff] [blame] | 3588 | |
| 3589 | // For any image objects that overlap mapped memory, verify that their layouts are PREINIT or GENERAL |
Mark Lobodzinski | ef4ab2e | 2019-03-07 13:23:36 -0700 | [diff] [blame] | 3590 | bool CoreChecks::ValidateMapImageLayouts(VkDevice device, DEVICE_MEM_INFO const *mem_info, VkDeviceSize offset, |
| 3591 | VkDeviceSize end_offset) { |
Mark Lobodzinski | ac23ec8 | 2017-02-07 17:21:55 -0700 | [diff] [blame] | 3592 | bool skip = false; |
| 3593 | // Iterate over all bound image ranges and verify that for any that overlap the map ranges, the layouts are |
| 3594 | // VK_IMAGE_LAYOUT_PREINITIALIZED or VK_IMAGE_LAYOUT_GENERAL |
Mark Lobodzinski | 08f14fa | 2017-02-07 17:20:06 -0700 | [diff] [blame] | 3595 | // TODO : This can be optimized if we store ranges based on starting address and early exit when we pass our range |
| 3596 | for (auto image_handle : mem_info->bound_images) { |
| 3597 | auto img_it = mem_info->bound_ranges.find(image_handle); |
| 3598 | if (img_it != mem_info->bound_ranges.end()) { |
Mark Lobodzinski | ef4ab2e | 2019-03-07 13:23:36 -0700 | [diff] [blame] | 3599 | if (RangesIntersect(&img_it->second, offset, end_offset)) { |
Mark Lobodzinski | 08f14fa | 2017-02-07 17:20:06 -0700 | [diff] [blame] | 3600 | std::vector<VkImageLayout> layouts; |
Mark Lobodzinski | ef4ab2e | 2019-03-07 13:23:36 -0700 | [diff] [blame] | 3601 | if (FindLayouts(VkImage(image_handle), layouts)) { |
Mark Lobodzinski | 08f14fa | 2017-02-07 17:20:06 -0700 | [diff] [blame] | 3602 | for (auto layout : layouts) { |
| 3603 | if (layout != VK_IMAGE_LAYOUT_PREINITIALIZED && layout != VK_IMAGE_LAYOUT_GENERAL) { |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 3604 | skip |= |
| 3605 | log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_MEMORY_EXT, |
Dave Houlton | 5165390 | 2018-06-22 17:32:13 -0600 | [diff] [blame] | 3606 | HandleToUint64(mem_info->mem), kVUID_Core_DrawState_InvalidImageLayout, |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 3607 | "Mapping an image with layout %s can result in undefined behavior if this memory is used " |
| 3608 | "by the device. Only GENERAL or PREINITIALIZED should be used.", |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 3609 | string_VkImageLayout(layout)); |
Mark Lobodzinski | 08f14fa | 2017-02-07 17:20:06 -0700 | [diff] [blame] | 3610 | } |
| 3611 | } |
| 3612 | } |
| 3613 | } |
| 3614 | } |
| 3615 | } |
Mark Lobodzinski | ac23ec8 | 2017-02-07 17:21:55 -0700 | [diff] [blame] | 3616 | return skip; |
Mark Lobodzinski | 08f14fa | 2017-02-07 17:20:06 -0700 | [diff] [blame] | 3617 | } |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 3618 | |
| 3619 | // Helper function to validate correct usage bits set for buffers or images. Verify that (actual & desired) flags != 0 or, if strict |
| 3620 | // is true, verify that (actual & desired) flags == desired |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 3621 | bool CoreChecks::ValidateUsageFlags(VkFlags actual, VkFlags desired, VkBool32 strict, uint64_t obj_handle, |
| 3622 | VulkanObjectType obj_type, const char *msgCode, char const *func_name, char const *usage_str) { |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 3623 | bool correct_usage = false; |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 3624 | bool skip = false; |
Mark Lobodzinski | 3382637 | 2017-04-13 11:10:11 -0600 | [diff] [blame] | 3625 | const char *type_str = object_string[obj_type]; |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 3626 | if (strict) { |
| 3627 | correct_usage = ((actual & desired) == desired); |
| 3628 | } else { |
| 3629 | correct_usage = ((actual & desired) != 0); |
| 3630 | } |
| 3631 | if (!correct_usage) { |
Dave Houlton | 8e9f654 | 2018-05-18 12:18:22 -0600 | [diff] [blame] | 3632 | if (msgCode == kVUIDUndefined) { |
Dave Houlton | 12befb9 | 2018-06-26 17:16:46 -0600 | [diff] [blame] | 3633 | // TODO: Fix callers with kVUIDUndefined to use correct validation checks. |
Locke | e9aeebf | 2019-03-03 23:50:08 -0700 | [diff] [blame] | 3634 | skip = log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, get_debug_report_enum[obj_type], obj_handle, |
| 3635 | kVUID_Core_MemTrack_InvalidUsageFlag, |
| 3636 | "Invalid usage flag for %s %s used by %s. In this case, %s should have %s set during creation.", |
| 3637 | type_str, report_data->FormatHandle(obj_handle).c_str(), func_name, type_str, usage_str); |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 3638 | } else { |
Locke | e9aeebf | 2019-03-03 23:50:08 -0700 | [diff] [blame] | 3639 | skip = log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, get_debug_report_enum[obj_type], obj_handle, msgCode, |
| 3640 | "Invalid usage flag for %s %s used by %s. In this case, %s should have %s set during creation.", |
| 3641 | type_str, report_data->FormatHandle(obj_handle).c_str(), func_name, type_str, usage_str); |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 3642 | } |
| 3643 | } |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 3644 | return skip; |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 3645 | } |
| 3646 | |
| 3647 | // Helper function to validate usage flags for buffers. For given buffer_state send actual vs. desired usage off to helper above |
| 3648 | // where an error will be flagged if usage is not correct |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 3649 | bool CoreChecks::ValidateImageUsageFlags(IMAGE_STATE const *image_state, VkFlags desired, bool strict, const char *msgCode, |
| 3650 | char const *func_name, char const *usage_string) { |
| 3651 | return ValidateUsageFlags(image_state->createInfo.usage, desired, strict, HandleToUint64(image_state->image), |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 3652 | kVulkanObjectTypeImage, msgCode, func_name, usage_string); |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 3653 | } |
| 3654 | |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 3655 | bool CoreChecks::ValidateImageFormatFeatureFlags(IMAGE_STATE const *image_state, VkFormatFeatureFlags desired, |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 3656 | char const *func_name, const char *linear_vuid, const char *optimal_vuid) { |
Mark Lobodzinski | 5c04880 | 2019-03-07 10:47:31 -0700 | [diff] [blame] | 3657 | VkFormatProperties format_properties = GetPDFormatProperties(image_state->createInfo.format); |
Cort Stratton | 186b1a2 | 2018-05-01 20:18:06 -0400 | [diff] [blame] | 3658 | bool skip = false; |
| 3659 | if (image_state->createInfo.tiling == VK_IMAGE_TILING_LINEAR) { |
| 3660 | if ((format_properties.linearTilingFeatures & desired) != desired) { |
Locke | e9aeebf | 2019-03-03 23:50:08 -0700 | [diff] [blame] | 3661 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 3662 | HandleToUint64(image_state->image), linear_vuid, |
| 3663 | "In %s, invalid linearTilingFeatures (0x%08X) for format %u used by image %s.", func_name, |
| 3664 | format_properties.linearTilingFeatures, image_state->createInfo.format, |
| 3665 | report_data->FormatHandle(image_state->image).c_str()); |
Cort Stratton | 186b1a2 | 2018-05-01 20:18:06 -0400 | [diff] [blame] | 3666 | } |
| 3667 | } else if (image_state->createInfo.tiling == VK_IMAGE_TILING_OPTIMAL) { |
| 3668 | if ((format_properties.optimalTilingFeatures & desired) != desired) { |
| 3669 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
| 3670 | HandleToUint64(image_state->image), optimal_vuid, |
Locke | e9aeebf | 2019-03-03 23:50:08 -0700 | [diff] [blame] | 3671 | "In %s, invalid optimalTilingFeatures (0x%08X) for format %u used by image %s.", func_name, |
Cort Stratton | 186b1a2 | 2018-05-01 20:18:06 -0400 | [diff] [blame] | 3672 | format_properties.optimalTilingFeatures, image_state->createInfo.format, |
Locke | e9aeebf | 2019-03-03 23:50:08 -0700 | [diff] [blame] | 3673 | report_data->FormatHandle(image_state->image).c_str()); |
Cort Stratton | 186b1a2 | 2018-05-01 20:18:06 -0400 | [diff] [blame] | 3674 | } |
| 3675 | } |
| 3676 | return skip; |
| 3677 | } |
| 3678 | |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 3679 | bool CoreChecks::ValidateImageSubresourceLayers(const GLOBAL_CB_NODE *cb_node, const VkImageSubresourceLayers *subresource_layers, |
| 3680 | char const *func_name, char const *member, uint32_t i) { |
Cort Stratton | d619a30 | 2018-05-17 19:46:32 -0700 | [diff] [blame] | 3681 | bool skip = false; |
Cort Stratton | d619a30 | 2018-05-17 19:46:32 -0700 | [diff] [blame] | 3682 | // layerCount must not be zero |
| 3683 | if (subresource_layers->layerCount == 0) { |
| 3684 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 3685 | HandleToUint64(cb_node->commandBuffer), "VUID-VkImageSubresourceLayers-layerCount-01700", |
| 3686 | "In %s, pRegions[%u].%s.layerCount must not be zero.", func_name, i, member); |
| 3687 | } |
| 3688 | // aspectMask must not contain VK_IMAGE_ASPECT_METADATA_BIT |
| 3689 | if (subresource_layers->aspectMask & VK_IMAGE_ASPECT_METADATA_BIT) { |
| 3690 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 3691 | HandleToUint64(cb_node->commandBuffer), "VUID-VkImageSubresourceLayers-aspectMask-00168", |
| 3692 | "In %s, pRegions[%u].%s.aspectMask has VK_IMAGE_ASPECT_METADATA_BIT set.", func_name, i, member); |
| 3693 | } |
| 3694 | // if aspectMask contains COLOR, it must not contain either DEPTH or STENCIL |
| 3695 | if ((subresource_layers->aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) && |
| 3696 | (subresource_layers->aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT))) { |
| 3697 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
| 3698 | HandleToUint64(cb_node->commandBuffer), "VUID-VkImageSubresourceLayers-aspectMask-00167", |
| 3699 | "In %s, pRegions[%u].%s.aspectMask has VK_IMAGE_ASPECT_COLOR_BIT and either VK_IMAGE_ASPECT_DEPTH_BIT or " |
| 3700 | "VK_IMAGE_ASPECT_STENCIL_BIT set.", |
| 3701 | func_name, i, member); |
| 3702 | } |
| 3703 | return skip; |
| 3704 | } |
| 3705 | |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 3706 | // Helper function to validate usage flags for buffers. For given buffer_state send actual vs. desired usage off to helper above |
| 3707 | // where an error will be flagged if usage is not correct |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 3708 | bool CoreChecks::ValidateBufferUsageFlags(BUFFER_STATE const *buffer_state, VkFlags desired, bool strict, const char *msgCode, |
| 3709 | char const *func_name, char const *usage_string) { |
| 3710 | return ValidateUsageFlags(buffer_state->createInfo.usage, desired, strict, HandleToUint64(buffer_state->buffer), |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 3711 | kVulkanObjectTypeBuffer, msgCode, func_name, usage_string); |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 3712 | } |
| 3713 | |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 3714 | bool CoreChecks::ValidateBufferViewRange(const BUFFER_STATE *buffer_state, const VkBufferViewCreateInfo *pCreateInfo, |
| 3715 | const VkPhysicalDeviceLimits *device_limits) { |
Shannon McPherson | 4c9505b | 2018-06-19 15:18:55 -0600 | [diff] [blame] | 3716 | bool skip = false; |
Shannon McPherson | 4c9505b | 2018-06-19 15:18:55 -0600 | [diff] [blame] | 3717 | |
| 3718 | const VkDeviceSize &range = pCreateInfo->range; |
| 3719 | if (range != VK_WHOLE_SIZE) { |
| 3720 | // Range must be greater than 0 |
| 3721 | if (range <= 0) { |
| 3722 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, |
| 3723 | HandleToUint64(buffer_state->buffer), "VUID-VkBufferViewCreateInfo-range-00928", |
| 3724 | "If VkBufferViewCreateInfo range (%" PRIuLEAST64 |
| 3725 | ") does not equal VK_WHOLE_SIZE, range must be greater than 0.", |
| 3726 | range); |
| 3727 | } |
| 3728 | // Range must be a multiple of the element size of format |
Dave Houlton | a585d13 | 2019-01-18 13:05:42 -0700 | [diff] [blame] | 3729 | const size_t format_size = FormatElementSize(pCreateInfo->format); |
Shannon McPherson | 4c9505b | 2018-06-19 15:18:55 -0600 | [diff] [blame] | 3730 | if (range % format_size != 0) { |
| 3731 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, |
| 3732 | HandleToUint64(buffer_state->buffer), "VUID-VkBufferViewCreateInfo-range-00929", |
| 3733 | "If VkBufferViewCreateInfo range (%" PRIuLEAST64 |
| 3734 | ") does not equal VK_WHOLE_SIZE, range must be a multiple of the element size of the format " |
| 3735 | "(" PRINTF_SIZE_T_SPECIFIER ").", |
| 3736 | range, format_size); |
| 3737 | } |
| 3738 | // Range divided by the element size of format must be less than or equal to VkPhysicalDeviceLimits::maxTexelBufferElements |
| 3739 | if (range / format_size > device_limits->maxTexelBufferElements) { |
| 3740 | skip |= |
| 3741 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, |
| 3742 | HandleToUint64(buffer_state->buffer), "VUID-VkBufferViewCreateInfo-range-00930", |
| 3743 | "If VkBufferViewCreateInfo range (%" PRIuLEAST64 |
| 3744 | ") does not equal VK_WHOLE_SIZE, range divided by the element size of the format (" PRINTF_SIZE_T_SPECIFIER |
| 3745 | ") must be less than or equal to VkPhysicalDeviceLimits::maxTexelBufferElements (%" PRIuLEAST32 ").", |
| 3746 | range, format_size, device_limits->maxTexelBufferElements); |
| 3747 | } |
| 3748 | // The sum of range and offset must be less than or equal to the size of buffer |
| 3749 | if (range + pCreateInfo->offset > buffer_state->createInfo.size) { |
| 3750 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, |
| 3751 | HandleToUint64(buffer_state->buffer), "VUID-VkBufferViewCreateInfo-offset-00931", |
| 3752 | "If VkBufferViewCreateInfo range (%" PRIuLEAST64 |
| 3753 | ") does not equal VK_WHOLE_SIZE, the sum of offset (%" PRIuLEAST64 |
| 3754 | ") and range must be less than or equal to the size of the buffer (%" PRIuLEAST64 ").", |
| 3755 | range, pCreateInfo->offset, buffer_state->createInfo.size); |
| 3756 | } |
| 3757 | } |
| 3758 | return skip; |
| 3759 | } |
| 3760 | |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 3761 | bool CoreChecks::ValidateBufferViewBuffer(const BUFFER_STATE *buffer_state, const VkBufferViewCreateInfo *pCreateInfo) { |
Shannon McPherson | 265383a | 2018-06-21 15:37:52 -0600 | [diff] [blame] | 3762 | bool skip = false; |
Mark Lobodzinski | 5c04880 | 2019-03-07 10:47:31 -0700 | [diff] [blame] | 3763 | const VkFormatProperties format_properties = GetPDFormatProperties(pCreateInfo->format); |
Shannon McPherson | 265383a | 2018-06-21 15:37:52 -0600 | [diff] [blame] | 3764 | if ((buffer_state->createInfo.usage & VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT) && |
| 3765 | !(format_properties.bufferFeatures & VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT)) { |
| 3766 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, |
| 3767 | HandleToUint64(buffer_state->buffer), "VUID-VkBufferViewCreateInfo-buffer-00933", |
| 3768 | "If buffer was created with `usage` containing VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, format must " |
| 3769 | "be supported for uniform texel buffers"); |
| 3770 | } |
| 3771 | if ((buffer_state->createInfo.usage & VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) && |
| 3772 | !(format_properties.bufferFeatures & VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT)) { |
| 3773 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, |
| 3774 | HandleToUint64(buffer_state->buffer), "VUID-VkBufferViewCreateInfo-buffer-00934", |
| 3775 | "If buffer was created with `usage` containing VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT, format must " |
| 3776 | "be supported for storage texel buffers"); |
| 3777 | } |
| 3778 | return skip; |
| 3779 | } |
| 3780 | |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 3781 | bool CoreChecks::PreCallValidateCreateBuffer(VkDevice device, const VkBufferCreateInfo *pCreateInfo, |
| 3782 | const VkAllocationCallbacks *pAllocator, VkBuffer *pBuffer) { |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 3783 | bool skip = false; |
Mark Lobodzinski | 847b60c | 2017-03-13 09:32:45 -0600 | [diff] [blame] | 3784 | |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 3785 | // TODO: Add check for "VUID-vkCreateBuffer-flags-00911" (sparse address space accounting) |
Mark Lobodzinski | 847b60c | 2017-03-13 09:32:45 -0600 | [diff] [blame] | 3786 | |
Mark Lobodzinski | 60e7903 | 2019-03-07 10:22:31 -0700 | [diff] [blame] | 3787 | if ((pCreateInfo->flags & VK_BUFFER_CREATE_SPARSE_BINDING_BIT) && (!GetEnabledFeatures()->core.sparseBinding)) { |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 3788 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 3789 | "VUID-VkBufferCreateInfo-flags-00915", |
Mark Lobodzinski | 847b60c | 2017-03-13 09:32:45 -0600 | [diff] [blame] | 3790 | "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] | 3791 | "VK_BUFFER_CREATE_SPARSE_BINDING_BIT set."); |
Mark Lobodzinski | 847b60c | 2017-03-13 09:32:45 -0600 | [diff] [blame] | 3792 | } |
Mark Lobodzinski | af35506 | 2017-03-13 09:35:01 -0600 | [diff] [blame] | 3793 | |
Mark Lobodzinski | 60e7903 | 2019-03-07 10:22:31 -0700 | [diff] [blame] | 3794 | if ((pCreateInfo->flags & VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT) && (!GetEnabledFeatures()->core.sparseResidencyBuffer)) { |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 3795 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 3796 | "VUID-VkBufferCreateInfo-flags-00916", |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 3797 | "vkCreateBuffer(): the sparseResidencyBuffer device feature is disabled: Buffers cannot be created with " |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3798 | "the VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT set."); |
Mark Lobodzinski | af35506 | 2017-03-13 09:35:01 -0600 | [diff] [blame] | 3799 | } |
Mark Lobodzinski | 035a4cf | 2017-03-13 09:45:07 -0600 | [diff] [blame] | 3800 | |
Mark Lobodzinski | 60e7903 | 2019-03-07 10:22:31 -0700 | [diff] [blame] | 3801 | if ((pCreateInfo->flags & VK_BUFFER_CREATE_SPARSE_ALIASED_BIT) && (!GetEnabledFeatures()->core.sparseResidencyAliased)) { |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 3802 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 3803 | "VUID-VkBufferCreateInfo-flags-00917", |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 3804 | "vkCreateBuffer(): the sparseResidencyAliased device feature is disabled: Buffers cannot be created with " |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3805 | "the VK_BUFFER_CREATE_SPARSE_ALIASED_BIT set."); |
Mark Lobodzinski | 035a4cf | 2017-03-13 09:45:07 -0600 | [diff] [blame] | 3806 | } |
Jeff Bolz | 8769753 | 2019-01-11 22:54:00 -0600 | [diff] [blame] | 3807 | |
| 3808 | auto chained_devaddr_struct = lvl_find_in_chain<VkBufferDeviceAddressCreateInfoEXT>(pCreateInfo->pNext); |
| 3809 | if (chained_devaddr_struct) { |
| 3810 | if (!(pCreateInfo->flags & VK_BUFFER_CREATE_DEVICE_ADDRESS_CAPTURE_REPLAY_BIT_EXT) && |
| 3811 | chained_devaddr_struct->deviceAddress != 0) { |
| 3812 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 3813 | "VUID-VkBufferCreateInfo-deviceAddress-02604", |
| 3814 | "vkCreateBuffer(): Non-zero VkBufferDeviceAddressCreateInfoEXT::deviceAddress " |
| 3815 | "requires VK_BUFFER_CREATE_DEVICE_ADDRESS_CAPTURE_REPLAY_BIT_EXT."); |
| 3816 | } |
| 3817 | } |
| 3818 | |
| 3819 | if ((pCreateInfo->flags & VK_BUFFER_CREATE_DEVICE_ADDRESS_CAPTURE_REPLAY_BIT_EXT) && |
Mark Lobodzinski | 60e7903 | 2019-03-07 10:22:31 -0700 | [diff] [blame] | 3820 | !GetEnabledFeatures()->buffer_address.bufferDeviceAddressCaptureReplay) { |
Jeff Bolz | 8769753 | 2019-01-11 22:54:00 -0600 | [diff] [blame] | 3821 | skip |= log_msg( |
| 3822 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 3823 | "VUID-VkBufferCreateInfo-flags-02605", |
| 3824 | "vkCreateBuffer(): the bufferDeviceAddressCaptureReplay device feature is disabled: Buffers cannot be created with " |
| 3825 | "the VK_BUFFER_CREATE_DEVICE_ADDRESS_CAPTURE_REPLAY_BIT_EXT set."); |
| 3826 | } |
| 3827 | |
| 3828 | if ((pCreateInfo->usage & VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT_EXT) && |
Mark Lobodzinski | 60e7903 | 2019-03-07 10:22:31 -0700 | [diff] [blame] | 3829 | !GetEnabledFeatures()->buffer_address.bufferDeviceAddress) { |
Jeff Bolz | 8769753 | 2019-01-11 22:54:00 -0600 | [diff] [blame] | 3830 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 3831 | "VUID-VkBufferCreateInfo-usage-02606", |
| 3832 | "vkCreateBuffer(): the bufferDeviceAddress device feature is disabled: Buffers cannot be created with " |
| 3833 | "the VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT_EXT set."); |
| 3834 | } |
| 3835 | |
Mark Lobodzinski | 08ee03c | 2019-02-04 10:57:47 -0700 | [diff] [blame] | 3836 | if (pCreateInfo->sharingMode == VK_SHARING_MODE_CONCURRENT && pCreateInfo->pQueueFamilyIndices) { |
Mark Lobodzinski | daea591 | 2019-03-07 14:47:09 -0700 | [diff] [blame] | 3837 | skip |= ValidateQueueFamilies(pCreateInfo->queueFamilyIndexCount, pCreateInfo->pQueueFamilyIndices, "vkCreateBuffer", |
| 3838 | "pCreateInfo->pQueueFamilyIndices", "VUID-VkBufferCreateInfo-sharingMode-01419", |
| 3839 | "VUID-VkBufferCreateInfo-sharingMode-01419", false); |
Mark Lobodzinski | 08ee03c | 2019-02-04 10:57:47 -0700 | [diff] [blame] | 3840 | } |
| 3841 | |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 3842 | return skip; |
| 3843 | } |
| 3844 | |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 3845 | void CoreChecks::PostCallRecordCreateBuffer(VkDevice device, const VkBufferCreateInfo *pCreateInfo, |
| 3846 | const VkAllocationCallbacks *pAllocator, VkBuffer *pBuffer, VkResult result) { |
Mark Lobodzinski | 701507e | 2019-01-18 14:31:53 -0700 | [diff] [blame] | 3847 | if (result != VK_SUCCESS) return; |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 3848 | // TODO : This doesn't create deep copy of pQueueFamilyIndices so need to fix that if/when we want that data to be valid |
Mark Lobodzinski | 1170cf2 | 2019-03-07 11:08:21 -0700 | [diff] [blame] | 3849 | GetBufferMap()->insert(std::make_pair(*pBuffer, std::unique_ptr<BUFFER_STATE>(new BUFFER_STATE(*pBuffer, pCreateInfo)))); |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 3850 | } |
| 3851 | |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 3852 | bool CoreChecks::PreCallValidateCreateBufferView(VkDevice device, const VkBufferViewCreateInfo *pCreateInfo, |
| 3853 | const VkAllocationCallbacks *pAllocator, VkBufferView *pView) { |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 3854 | bool skip = false; |
Mark Lobodzinski | 6ed7414 | 2019-03-06 11:35:39 -0700 | [diff] [blame] | 3855 | BUFFER_STATE *buffer_state = GetBufferState(pCreateInfo->buffer); |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 3856 | // If this isn't a sparse buffer, it needs to have memory backing it at CreateBufferView time |
| 3857 | if (buffer_state) { |
Mark Lobodzinski | 0ebe971 | 2019-03-07 13:39:07 -0700 | [diff] [blame] | 3858 | skip |= ValidateMemoryIsBoundToBuffer(buffer_state, "vkCreateBufferView()", "VUID-VkBufferViewCreateInfo-buffer-00935"); |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 3859 | // In order to create a valid buffer view, the buffer must have been created with at least one of the following flags: |
| 3860 | // UNIFORM_TEXEL_BUFFER_BIT or STORAGE_TEXEL_BUFFER_BIT |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 3861 | skip |= ValidateBufferUsageFlags(buffer_state, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 3862 | VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT, false, |
| 3863 | "VUID-VkBufferViewCreateInfo-buffer-00932", "vkCreateBufferView()", |
| 3864 | "VK_BUFFER_USAGE_[STORAGE|UNIFORM]_TEXEL_BUFFER_BIT"); |
Shannon McPherson | 883f609 | 2018-06-14 13:15:25 -0600 | [diff] [blame] | 3865 | |
Shannon McPherson | 0eb84f6 | 2018-06-18 16:32:40 -0600 | [diff] [blame] | 3866 | // Buffer view offset must be less than the size of buffer |
| 3867 | if (pCreateInfo->offset >= buffer_state->createInfo.size) { |
| 3868 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, |
| 3869 | HandleToUint64(buffer_state->buffer), "VUID-VkBufferViewCreateInfo-offset-00925", |
| 3870 | "VkBufferViewCreateInfo offset (%" PRIuLEAST64 |
| 3871 | ") must be less than the size of the buffer (%" PRIuLEAST64 ").", |
| 3872 | pCreateInfo->offset, buffer_state->createInfo.size); |
| 3873 | } |
| 3874 | |
Mark Lobodzinski | 79b5d5b | 2019-04-19 12:27:10 -0600 | [diff] [blame] | 3875 | const VkPhysicalDeviceLimits *device_limits = &phys_dev_props.limits; |
Shannon McPherson | 883f609 | 2018-06-14 13:15:25 -0600 | [diff] [blame] | 3876 | // Buffer view offset must be a multiple of VkPhysicalDeviceLimits::minTexelBufferOffsetAlignment |
| 3877 | if ((pCreateInfo->offset % device_limits->minTexelBufferOffsetAlignment) != 0) { |
| 3878 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, |
| 3879 | HandleToUint64(buffer_state->buffer), "VUID-VkBufferViewCreateInfo-offset-00926", |
| 3880 | "VkBufferViewCreateInfo offset (%" PRIuLEAST64 |
| 3881 | ") must be a multiple of VkPhysicalDeviceLimits::minTexelBufferOffsetAlignment (%" PRIuLEAST64 ").", |
| 3882 | pCreateInfo->offset, device_limits->minTexelBufferOffsetAlignment); |
| 3883 | } |
Shannon McPherson | 4c9505b | 2018-06-19 15:18:55 -0600 | [diff] [blame] | 3884 | |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 3885 | skip |= ValidateBufferViewRange(buffer_state, pCreateInfo, device_limits); |
Shannon McPherson | 265383a | 2018-06-21 15:37:52 -0600 | [diff] [blame] | 3886 | |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 3887 | skip |= ValidateBufferViewBuffer(buffer_state, pCreateInfo); |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 3888 | } |
Mark Lobodzinski | 95dbbe5 | 2017-02-09 10:40:41 -0700 | [diff] [blame] | 3889 | return skip; |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 3890 | } |
| 3891 | |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 3892 | void CoreChecks::PostCallRecordCreateBufferView(VkDevice device, const VkBufferViewCreateInfo *pCreateInfo, |
| 3893 | const VkAllocationCallbacks *pAllocator, VkBufferView *pView, VkResult result) { |
Mark Lobodzinski | 701507e | 2019-01-18 14:31:53 -0700 | [diff] [blame] | 3894 | if (result != VK_SUCCESS) return; |
Mark Lobodzinski | 1170cf2 | 2019-03-07 11:08:21 -0700 | [diff] [blame] | 3895 | (*GetBufferViewMap())[*pView] = std::unique_ptr<BUFFER_VIEW_STATE>(new BUFFER_VIEW_STATE(*pView, pCreateInfo)); |
Mark Lobodzinski | 9621074 | 2017-02-09 10:33:46 -0700 | [diff] [blame] | 3896 | } |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3897 | |
| 3898 | // For the given format verify that the aspect masks make sense |
Mark Lobodzinski | 9ddb718 | 2019-03-08 17:31:09 -0700 | [diff] [blame] | 3899 | bool CoreChecks::ValidateImageAspectMask(VkImage image, VkFormat format, VkImageAspectFlags aspect_mask, const char *func_name, |
| 3900 | const char *vuid) { |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3901 | bool skip = false; |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 3902 | VkDebugReportObjectTypeEXT objectType = VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT; |
| 3903 | if (image != VK_NULL_HANDLE) { |
| 3904 | objectType = VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT; |
| 3905 | } |
| 3906 | |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 3907 | if (FormatIsColor(format)) { |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3908 | if ((aspect_mask & VK_IMAGE_ASPECT_COLOR_BIT) != VK_IMAGE_ASPECT_COLOR_BIT) { |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 3909 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, objectType, HandleToUint64(image), vuid, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3910 | "%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] | 3911 | } else if ((aspect_mask & VK_IMAGE_ASPECT_COLOR_BIT) != aspect_mask) { |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 3912 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, objectType, HandleToUint64(image), vuid, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3913 | "%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] | 3914 | } |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 3915 | } else if (FormatIsDepthAndStencil(format)) { |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3916 | if ((aspect_mask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) == 0) { |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 3917 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, objectType, HandleToUint64(image), vuid, |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 3918 | "%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] | 3919 | "VK_IMAGE_ASPECT_STENCIL_BIT set.", |
| 3920 | func_name); |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3921 | } else if ((aspect_mask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) != aspect_mask) { |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 3922 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, objectType, HandleToUint64(image), vuid, |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3923 | "%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] | 3924 | "VK_IMAGE_ASPECT_STENCIL_BIT set.", |
| 3925 | func_name); |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3926 | } |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 3927 | } else if (FormatIsDepthOnly(format)) { |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3928 | if ((aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) != VK_IMAGE_ASPECT_DEPTH_BIT) { |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 3929 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, objectType, HandleToUint64(image), vuid, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3930 | "%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] | 3931 | } else if ((aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) != aspect_mask) { |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 3932 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, objectType, HandleToUint64(image), vuid, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3933 | "%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] | 3934 | } |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 3935 | } else if (FormatIsStencilOnly(format)) { |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3936 | if ((aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) != VK_IMAGE_ASPECT_STENCIL_BIT) { |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 3937 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, objectType, HandleToUint64(image), vuid, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3938 | "%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] | 3939 | } else if ((aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) != aspect_mask) { |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 3940 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, objectType, HandleToUint64(image), vuid, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3941 | "%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] | 3942 | } |
Dave Houlton | 501b15b | 2018-03-30 15:07:41 -0600 | [diff] [blame] | 3943 | } else if (FormatIsMultiplane(format)) { |
| 3944 | VkImageAspectFlags valid_flags = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_PLANE_0_BIT | VK_IMAGE_ASPECT_PLANE_1_BIT; |
| 3945 | if (3 == FormatPlaneCount(format)) { |
| 3946 | valid_flags = valid_flags | VK_IMAGE_ASPECT_PLANE_2_BIT; |
| 3947 | } |
| 3948 | if ((aspect_mask & valid_flags) != aspect_mask) { |
Tobias Hector | bbb1228 | 2018-10-22 15:17:59 +0100 | [diff] [blame] | 3949 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, objectType, HandleToUint64(image), vuid, |
Dave Houlton | 501b15b | 2018-03-30 15:07:41 -0600 | [diff] [blame] | 3950 | "%s: Multi-plane image formats may have only VK_IMAGE_ASPECT_COLOR_BIT or VK_IMAGE_ASPECT_PLANE_n_BITs " |
| 3951 | "set, where n = [0, 1, 2].", |
| 3952 | func_name); |
| 3953 | } |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3954 | } |
| 3955 | return skip; |
| 3956 | } |
| 3957 | |
Mark Lobodzinski | 9ddb718 | 2019-03-08 17:31:09 -0700 | [diff] [blame] | 3958 | bool CoreChecks::ValidateImageSubresourceRange(const uint32_t image_mip_count, const uint32_t image_layer_count, |
| 3959 | const VkImageSubresourceRange &subresourceRange, const char *cmd_name, |
| 3960 | const char *param_name, const char *image_layer_count_var_name, |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 3961 | const uint64_t image_handle, SubresourceRangeErrorCodes errorCodes) { |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3962 | bool skip = false; |
Petr Kraus | 4d71868 | 2017-05-18 03:38:41 +0200 | [diff] [blame] | 3963 | |
| 3964 | // Validate mip levels |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 3965 | if (subresourceRange.baseMipLevel >= image_mip_count) { |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 3966 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, image_handle, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3967 | errorCodes.base_mip_err, |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 3968 | "%s: %s.baseMipLevel (= %" PRIu32 |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3969 | ") is greater or equal to the mip level count of the image (i.e. greater or equal to %" PRIu32 ").", |
| 3970 | cmd_name, param_name, subresourceRange.baseMipLevel, image_mip_count); |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 3971 | } |
Petr Kraus | 4d71868 | 2017-05-18 03:38:41 +0200 | [diff] [blame] | 3972 | |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 3973 | if (subresourceRange.levelCount != VK_REMAINING_MIP_LEVELS) { |
| 3974 | if (subresourceRange.levelCount == 0) { |
| 3975 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, image_handle, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3976 | errorCodes.mip_count_err, "%s: %s.levelCount is 0.", cmd_name, param_name); |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 3977 | } else { |
| 3978 | 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] | 3979 | |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 3980 | if (necessary_mip_count > image_mip_count) { |
| 3981 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, image_handle, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3982 | errorCodes.mip_count_err, |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 3983 | "%s: %s.baseMipLevel + .levelCount (= %" PRIu32 " + %" PRIu32 " = %" PRIu64 |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3984 | ") 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] | 3985 | cmd_name, param_name, subresourceRange.baseMipLevel, subresourceRange.levelCount, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3986 | necessary_mip_count, image_mip_count); |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 3987 | } |
Petr Kraus | 4d71868 | 2017-05-18 03:38:41 +0200 | [diff] [blame] | 3988 | } |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 3989 | } |
Petr Kraus | 4d71868 | 2017-05-18 03:38:41 +0200 | [diff] [blame] | 3990 | |
| 3991 | // Validate array layers |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 3992 | if (subresourceRange.baseArrayLayer >= image_layer_count) { |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 3993 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, image_handle, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 3994 | errorCodes.base_layer_err, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 3995 | "%s: %s.baseArrayLayer (= %" PRIu32 |
| 3996 | ") is greater or equal to the %s of the image when it was created (i.e. greater or equal to %" PRIu32 ").", |
| 3997 | 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] | 3998 | } |
Petr Kraus | 4d71868 | 2017-05-18 03:38:41 +0200 | [diff] [blame] | 3999 | |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 4000 | if (subresourceRange.layerCount != VK_REMAINING_ARRAY_LAYERS) { |
| 4001 | if (subresourceRange.layerCount == 0) { |
| 4002 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, image_handle, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 4003 | errorCodes.layer_count_err, "%s: %s.layerCount is 0.", cmd_name, param_name); |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 4004 | } else { |
| 4005 | const uint64_t necessary_layer_count = |
| 4006 | uint64_t{subresourceRange.baseArrayLayer} + uint64_t{subresourceRange.layerCount}; |
Petr Kraus | 8423f15 | 2017-05-26 01:20:04 +0200 | [diff] [blame] | 4007 | |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 4008 | if (necessary_layer_count > image_layer_count) { |
| 4009 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, image_handle, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 4010 | errorCodes.layer_count_err, |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 4011 | "%s: %s.baseArrayLayer + .layerCount (= %" PRIu32 " + %" PRIu32 " = %" PRIu64 |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 4012 | ") 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] | 4013 | cmd_name, param_name, subresourceRange.baseArrayLayer, subresourceRange.layerCount, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 4014 | necessary_layer_count, image_layer_count_var_name, image_layer_count); |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 4015 | } |
Petr Kraus | 4d71868 | 2017-05-18 03:38:41 +0200 | [diff] [blame] | 4016 | } |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 4017 | } |
Petr Kraus | 4d71868 | 2017-05-18 03:38:41 +0200 | [diff] [blame] | 4018 | |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 4019 | return skip; |
| 4020 | } |
| 4021 | |
Mark Lobodzinski | 9ddb718 | 2019-03-08 17:31:09 -0700 | [diff] [blame] | 4022 | bool CoreChecks::ValidateCreateImageViewSubresourceRange(const IMAGE_STATE *image_state, bool is_imageview_2d_type, |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 4023 | const VkImageSubresourceRange &subresourceRange) { |
Mark Lobodzinski | 60e7903 | 2019-03-07 10:22:31 -0700 | [diff] [blame] | 4024 | bool is_khr_maintenance1 = GetDeviceExtensions()->vk_khr_maintenance1; |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 4025 | bool is_image_slicable = image_state->createInfo.imageType == VK_IMAGE_TYPE_3D && |
| 4026 | (image_state->createInfo.flags & VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT_KHR); |
| 4027 | bool is_3D_to_2D_map = is_khr_maintenance1 && is_image_slicable && is_imageview_2d_type; |
| 4028 | |
| 4029 | const auto image_layer_count = is_3D_to_2D_map ? image_state->createInfo.extent.depth : image_state->createInfo.arrayLayers; |
| 4030 | const auto image_layer_count_var_name = is_3D_to_2D_map ? "extent.depth" : "arrayLayers"; |
| 4031 | |
| 4032 | SubresourceRangeErrorCodes subresourceRangeErrorCodes = {}; |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 4033 | subresourceRangeErrorCodes.base_mip_err = "VUID-VkImageViewCreateInfo-subresourceRange-01478"; |
| 4034 | subresourceRangeErrorCodes.mip_count_err = "VUID-VkImageViewCreateInfo-subresourceRange-01718"; |
| 4035 | subresourceRangeErrorCodes.base_layer_err = is_khr_maintenance1 ? (is_3D_to_2D_map ? "VUID-VkImageViewCreateInfo-image-01484" |
| 4036 | : "VUID-VkImageViewCreateInfo-image-01482") |
| 4037 | : "VUID-VkImageViewCreateInfo-subresourceRange-01480"; |
| 4038 | subresourceRangeErrorCodes.layer_count_err = is_khr_maintenance1 |
| 4039 | ? (is_3D_to_2D_map ? "VUID-VkImageViewCreateInfo-subresourceRange-01485" |
| 4040 | : "VUID-VkImageViewCreateInfo-subresourceRange-01483") |
| 4041 | : "VUID-VkImageViewCreateInfo-subresourceRange-01719"; |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 4042 | |
Mark Lobodzinski | 9ddb718 | 2019-03-08 17:31:09 -0700 | [diff] [blame] | 4043 | return ValidateImageSubresourceRange(image_state->createInfo.mipLevels, image_layer_count, subresourceRange, |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 4044 | "vkCreateImageView", "pCreateInfo->subresourceRange", image_layer_count_var_name, |
| 4045 | HandleToUint64(image_state->image), subresourceRangeErrorCodes); |
| 4046 | } |
| 4047 | |
Mark Lobodzinski | 9ddb718 | 2019-03-08 17:31:09 -0700 | [diff] [blame] | 4048 | bool CoreChecks::ValidateCmdClearColorSubresourceRange(const IMAGE_STATE *image_state, |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 4049 | const VkImageSubresourceRange &subresourceRange, const char *param_name) { |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 4050 | SubresourceRangeErrorCodes subresourceRangeErrorCodes = {}; |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 4051 | subresourceRangeErrorCodes.base_mip_err = "VUID-vkCmdClearColorImage-baseMipLevel-01470"; |
| 4052 | subresourceRangeErrorCodes.mip_count_err = "VUID-vkCmdClearColorImage-pRanges-01692"; |
| 4053 | subresourceRangeErrorCodes.base_layer_err = "VUID-vkCmdClearColorImage-baseArrayLayer-01472"; |
| 4054 | subresourceRangeErrorCodes.layer_count_err = "VUID-vkCmdClearColorImage-pRanges-01693"; |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 4055 | |
Mark Lobodzinski | 9ddb718 | 2019-03-08 17:31:09 -0700 | [diff] [blame] | 4056 | return ValidateImageSubresourceRange(image_state->createInfo.mipLevels, image_state->createInfo.arrayLayers, subresourceRange, |
| 4057 | "vkCmdClearColorImage", param_name, "arrayLayers", HandleToUint64(image_state->image), |
| 4058 | subresourceRangeErrorCodes); |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 4059 | } |
| 4060 | |
Mark Lobodzinski | 9ddb718 | 2019-03-08 17:31:09 -0700 | [diff] [blame] | 4061 | bool CoreChecks::ValidateCmdClearDepthSubresourceRange(const IMAGE_STATE *image_state, |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 4062 | const VkImageSubresourceRange &subresourceRange, const char *param_name) { |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 4063 | SubresourceRangeErrorCodes subresourceRangeErrorCodes = {}; |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 4064 | subresourceRangeErrorCodes.base_mip_err = "VUID-vkCmdClearDepthStencilImage-baseMipLevel-01474"; |
| 4065 | subresourceRangeErrorCodes.mip_count_err = "VUID-vkCmdClearDepthStencilImage-pRanges-01694"; |
| 4066 | subresourceRangeErrorCodes.base_layer_err = "VUID-vkCmdClearDepthStencilImage-baseArrayLayer-01476"; |
| 4067 | subresourceRangeErrorCodes.layer_count_err = "VUID-vkCmdClearDepthStencilImage-pRanges-01695"; |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 4068 | |
Mark Lobodzinski | 9ddb718 | 2019-03-08 17:31:09 -0700 | [diff] [blame] | 4069 | return ValidateImageSubresourceRange(image_state->createInfo.mipLevels, image_state->createInfo.arrayLayers, subresourceRange, |
| 4070 | "vkCmdClearDepthStencilImage", param_name, "arrayLayers", |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 4071 | HandleToUint64(image_state->image), subresourceRangeErrorCodes); |
| 4072 | } |
| 4073 | |
Mark Lobodzinski | 9ddb718 | 2019-03-08 17:31:09 -0700 | [diff] [blame] | 4074 | bool CoreChecks::ValidateImageBarrierSubresourceRange(const IMAGE_STATE *image_state, |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 4075 | const VkImageSubresourceRange &subresourceRange, const char *cmd_name, |
| 4076 | const char *param_name) { |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 4077 | SubresourceRangeErrorCodes subresourceRangeErrorCodes = {}; |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 4078 | subresourceRangeErrorCodes.base_mip_err = "VUID-VkImageMemoryBarrier-subresourceRange-01486"; |
| 4079 | subresourceRangeErrorCodes.mip_count_err = "VUID-VkImageMemoryBarrier-subresourceRange-01724"; |
| 4080 | subresourceRangeErrorCodes.base_layer_err = "VUID-VkImageMemoryBarrier-subresourceRange-01488"; |
| 4081 | subresourceRangeErrorCodes.layer_count_err = "VUID-VkImageMemoryBarrier-subresourceRange-01725"; |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 4082 | |
Mark Lobodzinski | 9ddb718 | 2019-03-08 17:31:09 -0700 | [diff] [blame] | 4083 | return ValidateImageSubresourceRange(image_state->createInfo.mipLevels, image_state->createInfo.arrayLayers, subresourceRange, |
| 4084 | cmd_name, param_name, "arrayLayers", HandleToUint64(image_state->image), |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 4085 | subresourceRangeErrorCodes); |
| 4086 | } |
| 4087 | |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 4088 | bool CoreChecks::PreCallValidateCreateImageView(VkDevice device, const VkImageViewCreateInfo *pCreateInfo, |
| 4089 | const VkAllocationCallbacks *pAllocator, VkImageView *pView) { |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 4090 | bool skip = false; |
Mark Lobodzinski | 8ddc23f | 2019-03-06 11:48:49 -0700 | [diff] [blame] | 4091 | IMAGE_STATE *image_state = GetImageState(pCreateInfo->image); |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 4092 | if (image_state) { |
| 4093 | skip |= ValidateImageUsageFlags( |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 4094 | image_state, |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 4095 | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT | |
Dave Houlton | 142c4cb | 2018-10-17 15:04:41 -0600 | [diff] [blame] | 4096 | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
| 4097 | VK_IMAGE_USAGE_SHADING_RATE_IMAGE_BIT_NV, |
Dave Houlton | 8e9f654 | 2018-05-18 12:18:22 -0600 | [diff] [blame] | 4098 | false, kVUIDUndefined, "vkCreateImageView()", |
Jeff Bolz | 9af91c5 | 2018-09-01 21:53:57 -0500 | [diff] [blame] | 4099 | "VK_IMAGE_USAGE_[SAMPLED|STORAGE|COLOR_ATTACHMENT|DEPTH_STENCIL_ATTACHMENT|INPUT_ATTACHMENT|SHADING_RATE_IMAGE]_BIT"); |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 4100 | // If this isn't a sparse image, it needs to have memory backing it at CreateImageView time |
Mark Lobodzinski | 0ebe971 | 2019-03-07 13:39:07 -0700 | [diff] [blame] | 4101 | skip |= ValidateMemoryIsBoundToImage(image_state, "vkCreateImageView()", "VUID-VkImageViewCreateInfo-image-01020"); |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 4102 | // Checks imported from image layer |
Petr Kraus | ffa94af | 2017-08-08 21:46:02 +0200 | [diff] [blame] | 4103 | skip |= ValidateCreateImageViewSubresourceRange( |
Mark Lobodzinski | 9ddb718 | 2019-03-08 17:31:09 -0700 | [diff] [blame] | 4104 | image_state, pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_2D || pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_2D_ARRAY, |
Mark Lobodzinski | c8c8d0d | 2019-01-10 12:55:26 -0700 | [diff] [blame] | 4105 | pCreateInfo->subresourceRange); |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 4106 | |
| 4107 | VkImageCreateFlags image_flags = image_state->createInfo.flags; |
| 4108 | VkFormat image_format = image_state->createInfo.format; |
Jeremy Kniager | cef491c | 2017-07-18 11:10:28 -0600 | [diff] [blame] | 4109 | VkImageUsageFlags image_usage = image_state->createInfo.usage; |
| 4110 | VkImageTiling image_tiling = image_state->createInfo.tiling; |
Mark Lobodzinski | c8c8d0d | 2019-01-10 12:55:26 -0700 | [diff] [blame] | 4111 | VkFormat view_format = pCreateInfo->format; |
| 4112 | VkImageAspectFlags aspect_mask = pCreateInfo->subresourceRange.aspectMask; |
Jeremy Kniager | 846ab73 | 2017-07-10 13:12:04 -0600 | [diff] [blame] | 4113 | VkImageType image_type = image_state->createInfo.imageType; |
Mark Lobodzinski | c8c8d0d | 2019-01-10 12:55:26 -0700 | [diff] [blame] | 4114 | VkImageViewType view_type = pCreateInfo->viewType; |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 4115 | |
Dave Houlton | bd2e262 | 2018-04-10 16:41:14 -0600 | [diff] [blame] | 4116 | // If there's a chained VkImageViewUsageCreateInfo struct, modify image_usage to match |
Mark Lobodzinski | c8c8d0d | 2019-01-10 12:55:26 -0700 | [diff] [blame] | 4117 | auto chained_ivuci_struct = lvl_find_in_chain<VkImageViewUsageCreateInfoKHR>(pCreateInfo->pNext); |
Dave Houlton | bd2e262 | 2018-04-10 16:41:14 -0600 | [diff] [blame] | 4118 | if (chained_ivuci_struct) { |
Dave Houlton | bd2e262 | 2018-04-10 16:41:14 -0600 | [diff] [blame] | 4119 | image_usage = chained_ivuci_struct->usage; |
| 4120 | } |
| 4121 | |
Dave Houlton | 6f5f20a | 2018-05-04 12:37:44 -0600 | [diff] [blame] | 4122 | // Validate VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT state, if view/image formats differ |
| 4123 | if ((image_flags & VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT) && (image_format != view_format)) { |
Dave Houlton | c798807 | 2018-04-16 11:46:56 -0600 | [diff] [blame] | 4124 | if (FormatIsMultiplane(image_format)) { |
| 4125 | // View format must match the multiplane compatible format |
| 4126 | uint32_t plane = 3; // invalid |
| 4127 | switch (aspect_mask) { |
| 4128 | case VK_IMAGE_ASPECT_PLANE_0_BIT: |
| 4129 | plane = 0; |
| 4130 | break; |
| 4131 | case VK_IMAGE_ASPECT_PLANE_1_BIT: |
| 4132 | plane = 1; |
| 4133 | break; |
| 4134 | case VK_IMAGE_ASPECT_PLANE_2_BIT: |
| 4135 | plane = 2; |
| 4136 | break; |
| 4137 | default: |
| 4138 | break; |
| 4139 | } |
| 4140 | |
| 4141 | VkFormat compat_format = FindMultiplaneCompatibleFormat(image_format, plane); |
| 4142 | if (view_format != compat_format) { |
Lenny Komow | b79f04a | 2017-09-18 17:07:00 -0600 | [diff] [blame] | 4143 | std::stringstream ss; |
| 4144 | ss << "vkCreateImageView(): ImageView format " << string_VkFormat(view_format) |
Dave Houlton | c798807 | 2018-04-16 11:46:56 -0600 | [diff] [blame] | 4145 | << " is not compatible with plane " << plane << " of underlying image format " |
| 4146 | << string_VkFormat(image_format) << ", must be " << string_VkFormat(compat_format) << "."; |
Mark Young | 9d1ac31 | 2018-05-21 16:28:27 -0600 | [diff] [blame] | 4147 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | c8c8d0d | 2019-01-10 12:55:26 -0700 | [diff] [blame] | 4148 | HandleToUint64(pCreateInfo->image), "VUID-VkImageViewCreateInfo-image-01586", "%s", |
Mark Young | 9d1ac31 | 2018-05-21 16:28:27 -0600 | [diff] [blame] | 4149 | ss.str().c_str()); |
Dave Houlton | c798807 | 2018-04-16 11:46:56 -0600 | [diff] [blame] | 4150 | } |
| 4151 | } else { |
Mark Lobodzinski | 60e7903 | 2019-03-07 10:22:31 -0700 | [diff] [blame] | 4152 | if ((!GetDeviceExtensions()->vk_khr_maintenance2 || |
Dave Houlton | c798807 | 2018-04-16 11:46:56 -0600 | [diff] [blame] | 4153 | !(image_flags & VK_IMAGE_CREATE_BLOCK_TEXEL_VIEW_COMPATIBLE_BIT_KHR))) { |
| 4154 | // Format MUST be compatible (in the same format compatibility class) as the format the image was created with |
| 4155 | if (FormatCompatibilityClass(image_format) != FormatCompatibilityClass(view_format)) { |
| 4156 | std::stringstream ss; |
| 4157 | ss << "vkCreateImageView(): ImageView format " << string_VkFormat(view_format) |
Locke | e9aeebf | 2019-03-03 23:50:08 -0700 | [diff] [blame] | 4158 | << " is not in the same format compatibility class as image (" |
| 4159 | << report_data->FormatHandle(pCreateInfo->image).c_str() << ") format " << string_VkFormat(image_format) |
Dave Houlton | c798807 | 2018-04-16 11:46:56 -0600 | [diff] [blame] | 4160 | << ". Images created with the VK_IMAGE_CREATE_MUTABLE_FORMAT BIT " |
| 4161 | << "can support ImageViews with differing formats but they must be in the same compatibility class."; |
Mark Young | 9d1ac31 | 2018-05-21 16:28:27 -0600 | [diff] [blame] | 4162 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | c8c8d0d | 2019-01-10 12:55:26 -0700 | [diff] [blame] | 4163 | HandleToUint64(pCreateInfo->image), "VUID-VkImageViewCreateInfo-image-01018", "%s", |
Mark Young | 9d1ac31 | 2018-05-21 16:28:27 -0600 | [diff] [blame] | 4164 | ss.str().c_str()); |
Dave Houlton | c798807 | 2018-04-16 11:46:56 -0600 | [diff] [blame] | 4165 | } |
Lenny Komow | b79f04a | 2017-09-18 17:07:00 -0600 | [diff] [blame] | 4166 | } |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 4167 | } |
| 4168 | } else { |
| 4169 | // Format MUST be IDENTICAL to the format the image was created with |
| 4170 | if (image_format != view_format) { |
| 4171 | std::stringstream ss; |
| 4172 | ss << "vkCreateImageView() format " << string_VkFormat(view_format) << " differs from image " |
Locke | e9aeebf | 2019-03-03 23:50:08 -0700 | [diff] [blame] | 4173 | << report_data->FormatHandle(pCreateInfo->image).c_str() << " format " << string_VkFormat(image_format) |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 4174 | << ". Formats MUST be IDENTICAL unless VK_IMAGE_CREATE_MUTABLE_FORMAT BIT was set on image creation."; |
Mark Young | 9d1ac31 | 2018-05-21 16:28:27 -0600 | [diff] [blame] | 4175 | skip |= |
| 4176 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | c8c8d0d | 2019-01-10 12:55:26 -0700 | [diff] [blame] | 4177 | HandleToUint64(pCreateInfo->image), "VUID-VkImageViewCreateInfo-image-01019", "%s", ss.str().c_str()); |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 4178 | } |
| 4179 | } |
| 4180 | |
| 4181 | // Validate correct image aspect bits for desired formats and format consistency |
Mark Lobodzinski | 9ddb718 | 2019-03-08 17:31:09 -0700 | [diff] [blame] | 4182 | skip |= ValidateImageAspectMask(image_state->image, image_format, aspect_mask, "vkCreateImageView()"); |
Jeremy Kniager | 846ab73 | 2017-07-10 13:12:04 -0600 | [diff] [blame] | 4183 | |
| 4184 | switch (image_type) { |
| 4185 | case VK_IMAGE_TYPE_1D: |
| 4186 | if (view_type != VK_IMAGE_VIEW_TYPE_1D && view_type != VK_IMAGE_VIEW_TYPE_1D_ARRAY) { |
Mark Young | 9d1ac31 | 2018-05-21 16:28:27 -0600 | [diff] [blame] | 4187 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | c8c8d0d | 2019-01-10 12:55:26 -0700 | [diff] [blame] | 4188 | HandleToUint64(pCreateInfo->image), "VUID-VkImageViewCreateInfo-subResourceRange-01021", |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 4189 | "vkCreateImageView(): pCreateInfo->viewType %s is not compatible with image type %s.", |
| 4190 | string_VkImageViewType(view_type), string_VkImageType(image_type)); |
Jeremy Kniager | 846ab73 | 2017-07-10 13:12:04 -0600 | [diff] [blame] | 4191 | } |
| 4192 | break; |
| 4193 | case VK_IMAGE_TYPE_2D: |
| 4194 | if (view_type != VK_IMAGE_VIEW_TYPE_2D && view_type != VK_IMAGE_VIEW_TYPE_2D_ARRAY) { |
| 4195 | if ((view_type == VK_IMAGE_VIEW_TYPE_CUBE || view_type == VK_IMAGE_VIEW_TYPE_CUBE_ARRAY) && |
| 4196 | !(image_flags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT)) { |
Mark Young | 9d1ac31 | 2018-05-21 16:28:27 -0600 | [diff] [blame] | 4197 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | c8c8d0d | 2019-01-10 12:55:26 -0700 | [diff] [blame] | 4198 | HandleToUint64(pCreateInfo->image), "VUID-VkImageViewCreateInfo-image-01003", |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 4199 | "vkCreateImageView(): pCreateInfo->viewType %s is not compatible with image type %s.", |
| 4200 | string_VkImageViewType(view_type), string_VkImageType(image_type)); |
Jeremy Kniager | 846ab73 | 2017-07-10 13:12:04 -0600 | [diff] [blame] | 4201 | } else if (view_type != VK_IMAGE_VIEW_TYPE_CUBE && view_type != VK_IMAGE_VIEW_TYPE_CUBE_ARRAY) { |
Mark Young | 9d1ac31 | 2018-05-21 16:28:27 -0600 | [diff] [blame] | 4202 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | c8c8d0d | 2019-01-10 12:55:26 -0700 | [diff] [blame] | 4203 | HandleToUint64(pCreateInfo->image), "VUID-VkImageViewCreateInfo-subResourceRange-01021", |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 4204 | "vkCreateImageView(): pCreateInfo->viewType %s is not compatible with image type %s.", |
| 4205 | string_VkImageViewType(view_type), string_VkImageType(image_type)); |
Jeremy Kniager | 846ab73 | 2017-07-10 13:12:04 -0600 | [diff] [blame] | 4206 | } |
| 4207 | } |
| 4208 | break; |
| 4209 | case VK_IMAGE_TYPE_3D: |
Mark Lobodzinski | 60e7903 | 2019-03-07 10:22:31 -0700 | [diff] [blame] | 4210 | if (GetDeviceExtensions()->vk_khr_maintenance1) { |
Jeremy Kniager | 846ab73 | 2017-07-10 13:12:04 -0600 | [diff] [blame] | 4211 | if (view_type != VK_IMAGE_VIEW_TYPE_3D) { |
| 4212 | if ((view_type == VK_IMAGE_VIEW_TYPE_2D || view_type == VK_IMAGE_VIEW_TYPE_2D_ARRAY)) { |
| 4213 | if (!(image_flags & VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT_KHR)) { |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 4214 | skip |= |
Mark Young | 9d1ac31 | 2018-05-21 16:28:27 -0600 | [diff] [blame] | 4215 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | c8c8d0d | 2019-01-10 12:55:26 -0700 | [diff] [blame] | 4216 | HandleToUint64(pCreateInfo->image), "VUID-VkImageViewCreateInfo-image-01005", |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 4217 | "vkCreateImageView(): pCreateInfo->viewType %s is not compatible with image type %s.", |
| 4218 | string_VkImageViewType(view_type), string_VkImageType(image_type)); |
Jeremy Kniager | 846ab73 | 2017-07-10 13:12:04 -0600 | [diff] [blame] | 4219 | } else if ((image_flags & (VK_IMAGE_CREATE_SPARSE_BINDING_BIT | VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | |
| 4220 | VK_IMAGE_CREATE_SPARSE_ALIASED_BIT))) { |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 4221 | skip |= |
Mark Young | 9d1ac31 | 2018-05-21 16:28:27 -0600 | [diff] [blame] | 4222 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | c8c8d0d | 2019-01-10 12:55:26 -0700 | [diff] [blame] | 4223 | HandleToUint64(pCreateInfo->image), "VUID-VkImageViewCreateInfo-subResourceRange-01021", |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 4224 | "vkCreateImageView(): pCreateInfo->viewType %s is not compatible with image type %s " |
| 4225 | "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] | 4226 | "VK_IMAGE_CREATE_SPARSE_ALIASED_BIT flags are enabled.", |
| 4227 | string_VkImageViewType(view_type), string_VkImageType(image_type)); |
Jeremy Kniager | 846ab73 | 2017-07-10 13:12:04 -0600 | [diff] [blame] | 4228 | } |
| 4229 | } else { |
Mark Young | 9d1ac31 | 2018-05-21 16:28:27 -0600 | [diff] [blame] | 4230 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | c8c8d0d | 2019-01-10 12:55:26 -0700 | [diff] [blame] | 4231 | HandleToUint64(pCreateInfo->image), "VUID-VkImageViewCreateInfo-subResourceRange-01021", |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 4232 | "vkCreateImageView(): pCreateInfo->viewType %s is not compatible with image type %s.", |
| 4233 | string_VkImageViewType(view_type), string_VkImageType(image_type)); |
Jeremy Kniager | 846ab73 | 2017-07-10 13:12:04 -0600 | [diff] [blame] | 4234 | } |
| 4235 | } |
| 4236 | } else { |
| 4237 | if (view_type != VK_IMAGE_VIEW_TYPE_3D) { |
Mark Young | 9d1ac31 | 2018-05-21 16:28:27 -0600 | [diff] [blame] | 4238 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | c8c8d0d | 2019-01-10 12:55:26 -0700 | [diff] [blame] | 4239 | HandleToUint64(pCreateInfo->image), "VUID-VkImageViewCreateInfo-subResourceRange-01021", |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 4240 | "vkCreateImageView(): pCreateInfo->viewType %s is not compatible with image type %s.", |
| 4241 | string_VkImageViewType(view_type), string_VkImageType(image_type)); |
Jeremy Kniager | 846ab73 | 2017-07-10 13:12:04 -0600 | [diff] [blame] | 4242 | } |
| 4243 | } |
| 4244 | break; |
| 4245 | default: |
| 4246 | break; |
| 4247 | } |
Jeremy Kniager | cef491c | 2017-07-18 11:10:28 -0600 | [diff] [blame] | 4248 | |
Dave Houlton | 0d4ad6f | 2018-09-05 14:53:34 -0600 | [diff] [blame] | 4249 | // External format checks needed when VK_ANDROID_external_memory_android_hardware_buffer enabled |
Mark Lobodzinski | 60e7903 | 2019-03-07 10:22:31 -0700 | [diff] [blame] | 4250 | if (GetDeviceExtensions()->vk_android_external_memory_android_hardware_buffer) { |
Mark Lobodzinski | e9b9979 | 2019-03-07 16:34:29 -0700 | [diff] [blame] | 4251 | skip |= ValidateCreateImageViewANDROID(pCreateInfo); |
Jeremy Kniager | cef491c | 2017-07-18 11:10:28 -0600 | [diff] [blame] | 4252 | } |
| 4253 | |
Mark Lobodzinski | 5c04880 | 2019-03-07 10:47:31 -0700 | [diff] [blame] | 4254 | VkFormatProperties format_properties = GetPDFormatProperties(view_format); |
Dave Houlton | 0d4ad6f | 2018-09-05 14:53:34 -0600 | [diff] [blame] | 4255 | VkFormatFeatureFlags tiling_features = (image_tiling & VK_IMAGE_TILING_LINEAR) ? format_properties.linearTilingFeatures |
| 4256 | : format_properties.optimalTilingFeatures; |
| 4257 | |
| 4258 | if (tiling_features == 0) { |
| 4259 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | c8c8d0d | 2019-01-10 12:55:26 -0700 | [diff] [blame] | 4260 | HandleToUint64(pCreateInfo->image), "VUID-VkImageViewCreateInfo-None-02273", |
Dave Houlton | 0d4ad6f | 2018-09-05 14:53:34 -0600 | [diff] [blame] | 4261 | "vkCreateImageView(): pCreateInfo->format %s with tiling %s has no supported format features on this " |
| 4262 | "physical device.", |
| 4263 | string_VkFormat(view_format), string_VkImageTiling(image_tiling)); |
| 4264 | } else if ((image_usage & VK_IMAGE_USAGE_SAMPLED_BIT) && !(tiling_features & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) { |
| 4265 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | c8c8d0d | 2019-01-10 12:55:26 -0700 | [diff] [blame] | 4266 | HandleToUint64(pCreateInfo->image), "VUID-VkImageViewCreateInfo-usage-02274", |
Dave Houlton | 0d4ad6f | 2018-09-05 14:53:34 -0600 | [diff] [blame] | 4267 | "vkCreateImageView(): pCreateInfo->format %s with tiling %s does not support usage that includes " |
| 4268 | "VK_IMAGE_USAGE_SAMPLED_BIT.", |
| 4269 | string_VkFormat(view_format), string_VkImageTiling(image_tiling)); |
| 4270 | } else if ((image_usage & VK_IMAGE_USAGE_STORAGE_BIT) && !(tiling_features & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT)) { |
| 4271 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | c8c8d0d | 2019-01-10 12:55:26 -0700 | [diff] [blame] | 4272 | HandleToUint64(pCreateInfo->image), "VUID-VkImageViewCreateInfo-usage-02275", |
Dave Houlton | 0d4ad6f | 2018-09-05 14:53:34 -0600 | [diff] [blame] | 4273 | "vkCreateImageView(): pCreateInfo->format %s with tiling %s does not support usage that includes " |
| 4274 | "VK_IMAGE_USAGE_STORAGE_BIT.", |
| 4275 | string_VkFormat(view_format), string_VkImageTiling(image_tiling)); |
| 4276 | } else if ((image_usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) && |
| 4277 | !(tiling_features & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT)) { |
| 4278 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | c8c8d0d | 2019-01-10 12:55:26 -0700 | [diff] [blame] | 4279 | HandleToUint64(pCreateInfo->image), "VUID-VkImageViewCreateInfo-usage-02276", |
Dave Houlton | 0d4ad6f | 2018-09-05 14:53:34 -0600 | [diff] [blame] | 4280 | "vkCreateImageView(): pCreateInfo->format %s with tiling %s does not support usage that includes " |
| 4281 | "VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT.", |
| 4282 | string_VkFormat(view_format), string_VkImageTiling(image_tiling)); |
| 4283 | } else if ((image_usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) && |
| 4284 | !(tiling_features & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)) { |
| 4285 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | c8c8d0d | 2019-01-10 12:55:26 -0700 | [diff] [blame] | 4286 | HandleToUint64(pCreateInfo->image), "VUID-VkImageViewCreateInfo-usage-02277", |
Dave Houlton | 0d4ad6f | 2018-09-05 14:53:34 -0600 | [diff] [blame] | 4287 | "vkCreateImageView(): pCreateInfo->format %s with tiling %s does not support usage that includes " |
| 4288 | "VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT.", |
| 4289 | string_VkFormat(view_format), string_VkImageTiling(image_tiling)); |
Jeremy Kniager | cef491c | 2017-07-18 11:10:28 -0600 | [diff] [blame] | 4290 | } |
Dave Houlton | 0d4ad6f | 2018-09-05 14:53:34 -0600 | [diff] [blame] | 4291 | |
Jeff Bolz | 9af91c5 | 2018-09-01 21:53:57 -0500 | [diff] [blame] | 4292 | if (image_usage & VK_IMAGE_USAGE_SHADING_RATE_IMAGE_BIT_NV) { |
| 4293 | if (view_type != VK_IMAGE_VIEW_TYPE_2D && view_type != VK_IMAGE_VIEW_TYPE_2D_ARRAY) { |
| 4294 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | c8c8d0d | 2019-01-10 12:55:26 -0700 | [diff] [blame] | 4295 | HandleToUint64(pCreateInfo->image), "VUID-VkImageViewCreateInfo-image-02086", |
Jeff Bolz | 9af91c5 | 2018-09-01 21:53:57 -0500 | [diff] [blame] | 4296 | "vkCreateImageView() If image was created with usage containing " |
| 4297 | "VK_IMAGE_USAGE_SHADING_RATE_IMAGE_BIT_NV, viewType must be " |
| 4298 | "VK_IMAGE_VIEW_TYPE_2D or VK_IMAGE_VIEW_TYPE_2D_ARRAY."); |
| 4299 | } |
| 4300 | if (view_format != VK_FORMAT_R8_UINT) { |
| 4301 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | c8c8d0d | 2019-01-10 12:55:26 -0700 | [diff] [blame] | 4302 | HandleToUint64(pCreateInfo->image), "VUID-VkImageViewCreateInfo-image-02087", |
Jeff Bolz | 9af91c5 | 2018-09-01 21:53:57 -0500 | [diff] [blame] | 4303 | "vkCreateImageView() If image was created with usage containing " |
| 4304 | "VK_IMAGE_USAGE_SHADING_RATE_IMAGE_BIT_NV, format must be VK_FORMAT_R8_UINT."); |
| 4305 | } |
| 4306 | } |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 4307 | } |
| 4308 | return skip; |
| 4309 | } |
| 4310 | |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 4311 | void CoreChecks::PostCallRecordCreateImageView(VkDevice device, const VkImageViewCreateInfo *pCreateInfo, |
| 4312 | const VkAllocationCallbacks *pAllocator, VkImageView *pView, VkResult result) { |
Mark Lobodzinski | 701507e | 2019-01-18 14:31:53 -0700 | [diff] [blame] | 4313 | if (result != VK_SUCCESS) return; |
Mark Lobodzinski | 1170cf2 | 2019-03-07 11:08:21 -0700 | [diff] [blame] | 4314 | auto image_view_map = GetImageViewMap(); |
Mark Lobodzinski | 8ddc23f | 2019-03-06 11:48:49 -0700 | [diff] [blame] | 4315 | auto image_state = GetImageState(pCreateInfo->image); |
John Zulauf | f660ad6 | 2019-03-23 07:16:05 -0600 | [diff] [blame] | 4316 | (*image_view_map)[*pView] = std::unique_ptr<IMAGE_VIEW_STATE>(new IMAGE_VIEW_STATE(image_state, *pView, pCreateInfo)); |
Mark Lobodzinski | 602de98 | 2017-02-09 11:01:33 -0700 | [diff] [blame] | 4317 | } |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 4318 | |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 4319 | bool CoreChecks::PreCallValidateCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer, |
| 4320 | uint32_t regionCount, const VkBufferCopy *pRegions) { |
Mark Lobodzinski | 1b3a971 | 2019-03-06 15:51:47 -0700 | [diff] [blame] | 4321 | auto cb_node = GetCBNode(commandBuffer); |
Mark Lobodzinski | 6ed7414 | 2019-03-06 11:35:39 -0700 | [diff] [blame] | 4322 | auto src_buffer_state = GetBufferState(srcBuffer); |
| 4323 | auto dst_buffer_state = GetBufferState(dstBuffer); |
Mark Lobodzinski | b7eafbe | 2019-01-10 13:40:39 -0700 | [diff] [blame] | 4324 | |
Mark Lobodzinski | 680421d | 2017-02-09 13:06:56 -0700 | [diff] [blame] | 4325 | bool skip = false; |
Mark Lobodzinski | 0ebe971 | 2019-03-07 13:39:07 -0700 | [diff] [blame] | 4326 | skip |= ValidateMemoryIsBoundToBuffer(src_buffer_state, "vkCmdCopyBuffer()", "VUID-vkCmdCopyBuffer-srcBuffer-00119"); |
| 4327 | skip |= ValidateMemoryIsBoundToBuffer(dst_buffer_state, "vkCmdCopyBuffer()", "VUID-vkCmdCopyBuffer-dstBuffer-00121"); |
Mark Lobodzinski | 680421d | 2017-02-09 13:06:56 -0700 | [diff] [blame] | 4328 | // Validate that SRC & DST buffers have correct usage flags set |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 4329 | skip |= |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 4330 | ValidateBufferUsageFlags(src_buffer_state, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, true, "VUID-vkCmdCopyBuffer-srcBuffer-00118", |
| 4331 | "vkCmdCopyBuffer()", "VK_BUFFER_USAGE_TRANSFER_SRC_BIT"); |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 4332 | skip |= |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 4333 | ValidateBufferUsageFlags(dst_buffer_state, VK_BUFFER_USAGE_TRANSFER_DST_BIT, true, "VUID-vkCmdCopyBuffer-dstBuffer-00120", |
| 4334 | "vkCmdCopyBuffer()", "VK_BUFFER_USAGE_TRANSFER_DST_BIT"); |
Mark Lobodzinski | daea591 | 2019-03-07 14:47:09 -0700 | [diff] [blame] | 4335 | skip |= |
| 4336 | ValidateCmdQueueFlags(cb_node, "vkCmdCopyBuffer()", VK_QUEUE_TRANSFER_BIT | VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT, |
| 4337 | "VUID-vkCmdCopyBuffer-commandBuffer-cmdpool"); |
Mark Lobodzinski | fae179e | 2019-03-08 16:47:08 -0700 | [diff] [blame] | 4338 | skip |= ValidateCmd(cb_node, CMD_COPYBUFFER, "vkCmdCopyBuffer()"); |
| 4339 | skip |= InsideRenderPass(cb_node, "vkCmdCopyBuffer()", "VUID-vkCmdCopyBuffer-renderpass"); |
Mark Lobodzinski | 680421d | 2017-02-09 13:06:56 -0700 | [diff] [blame] | 4340 | return skip; |
| 4341 | } |
Mark Lobodzinski | ab9be28 | 2017-02-09 12:01:27 -0700 | [diff] [blame] | 4342 | |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 4343 | void CoreChecks::PreCallRecordCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer, |
| 4344 | uint32_t regionCount, const VkBufferCopy *pRegions) { |
Mark Lobodzinski | 1b3a971 | 2019-03-06 15:51:47 -0700 | [diff] [blame] | 4345 | auto cb_node = GetCBNode(commandBuffer); |
Mark Lobodzinski | 6ed7414 | 2019-03-06 11:35:39 -0700 | [diff] [blame] | 4346 | auto src_buffer_state = GetBufferState(srcBuffer); |
| 4347 | auto dst_buffer_state = GetBufferState(dstBuffer); |
Mark Lobodzinski | b7eafbe | 2019-01-10 13:40:39 -0700 | [diff] [blame] | 4348 | |
Mark Lobodzinski | 680421d | 2017-02-09 13:06:56 -0700 | [diff] [blame] | 4349 | // Update bindings between buffers and cmd buffer |
Mark Lobodzinski | fae179e | 2019-03-08 16:47:08 -0700 | [diff] [blame] | 4350 | AddCommandBufferBindingBuffer(cb_node, src_buffer_state); |
| 4351 | AddCommandBufferBindingBuffer(cb_node, dst_buffer_state); |
Mark Lobodzinski | 680421d | 2017-02-09 13:06:56 -0700 | [diff] [blame] | 4352 | } |
Mark Lobodzinski | 306441e | 2017-02-10 13:48:38 -0700 | [diff] [blame] | 4353 | |
Mark Lobodzinski | f933db9 | 2019-03-09 12:58:03 -0700 | [diff] [blame] | 4354 | bool CoreChecks::ValidateIdleBuffer(VkBuffer buffer) { |
Mark Lobodzinski | 306441e | 2017-02-10 13:48:38 -0700 | [diff] [blame] | 4355 | bool skip = false; |
Mark Lobodzinski | 6ed7414 | 2019-03-06 11:35:39 -0700 | [diff] [blame] | 4356 | auto buffer_state = GetBufferState(buffer); |
Mark Lobodzinski | 306441e | 2017-02-10 13:48:38 -0700 | [diff] [blame] | 4357 | if (!buffer_state) { |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 4358 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, HandleToUint64(buffer), |
Locke | e9aeebf | 2019-03-03 23:50:08 -0700 | [diff] [blame] | 4359 | kVUID_Core_DrawState_DoubleDestroy, "Cannot free buffer %s that has not been allocated.", |
| 4360 | report_data->FormatHandle(buffer).c_str()); |
Mark Lobodzinski | 306441e | 2017-02-10 13:48:38 -0700 | [diff] [blame] | 4361 | } else { |
| 4362 | if (buffer_state->in_use.load()) { |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 4363 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 4364 | HandleToUint64(buffer), "VUID-vkDestroyBuffer-buffer-00922", |
Locke | e9aeebf | 2019-03-03 23:50:08 -0700 | [diff] [blame] | 4365 | "Cannot free buffer %s that is in use by a command buffer.", report_data->FormatHandle(buffer).c_str()); |
Mark Lobodzinski | 306441e | 2017-02-10 13:48:38 -0700 | [diff] [blame] | 4366 | } |
| 4367 | } |
| 4368 | return skip; |
| 4369 | } |
| 4370 | |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 4371 | bool CoreChecks::PreCallValidateDestroyImageView(VkDevice device, VkImageView imageView, const VkAllocationCallbacks *pAllocator) { |
Mark Lobodzinski | a3a230b | 2019-03-06 15:35:13 -0700 | [diff] [blame] | 4372 | IMAGE_VIEW_STATE *image_view_state = GetImageViewState(imageView); |
Mark Lobodzinski | c8c8d0d | 2019-01-10 12:55:26 -0700 | [diff] [blame] | 4373 | VK_OBJECT obj_struct = {HandleToUint64(imageView), kVulkanObjectTypeImageView}; |
| 4374 | |
Mark Lobodzinski | 306441e | 2017-02-10 13:48:38 -0700 | [diff] [blame] | 4375 | bool skip = false; |
Mark Lobodzinski | c8c8d0d | 2019-01-10 12:55:26 -0700 | [diff] [blame] | 4376 | if (image_view_state) { |
Mark Lobodzinski | 9ddb718 | 2019-03-08 17:31:09 -0700 | [diff] [blame] | 4377 | skip |= |
| 4378 | ValidateObjectNotInUse(image_view_state, obj_struct, "vkDestroyImageView", "VUID-vkDestroyImageView-imageView-01026"); |
Mark Lobodzinski | 306441e | 2017-02-10 13:48:38 -0700 | [diff] [blame] | 4379 | } |
| 4380 | return skip; |
| 4381 | } |
| 4382 | |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 4383 | void CoreChecks::PreCallRecordDestroyImageView(VkDevice device, VkImageView imageView, const VkAllocationCallbacks *pAllocator) { |
Mark Lobodzinski | a3a230b | 2019-03-06 15:35:13 -0700 | [diff] [blame] | 4384 | IMAGE_VIEW_STATE *image_view_state = GetImageViewState(imageView); |
Mark Lobodzinski | c8c8d0d | 2019-01-10 12:55:26 -0700 | [diff] [blame] | 4385 | if (!image_view_state) return; |
| 4386 | VK_OBJECT obj_struct = {HandleToUint64(imageView), kVulkanObjectTypeImageView}; |
| 4387 | |
Mark Lobodzinski | 306441e | 2017-02-10 13:48:38 -0700 | [diff] [blame] | 4388 | // Any bound cmd buffers are now invalid |
Mark Lobodzinski | 9ddb718 | 2019-03-08 17:31:09 -0700 | [diff] [blame] | 4389 | InvalidateCommandBuffers(image_view_state->cb_bindings, obj_struct); |
Mark Lobodzinski | 1170cf2 | 2019-03-07 11:08:21 -0700 | [diff] [blame] | 4390 | (*GetImageViewMap()).erase(imageView); |
Mark Lobodzinski | 306441e | 2017-02-10 13:48:38 -0700 | [diff] [blame] | 4391 | } |
| 4392 | |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 4393 | bool CoreChecks::PreCallValidateDestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks *pAllocator) { |
Mark Lobodzinski | 6ed7414 | 2019-03-06 11:35:39 -0700 | [diff] [blame] | 4394 | auto buffer_state = GetBufferState(buffer); |
Mark Lobodzinski | dd995d2 | 2019-01-11 11:05:15 -0700 | [diff] [blame] | 4395 | |
Mark Lobodzinski | 306441e | 2017-02-10 13:48:38 -0700 | [diff] [blame] | 4396 | bool skip = false; |
Mark Lobodzinski | dd995d2 | 2019-01-11 11:05:15 -0700 | [diff] [blame] | 4397 | if (buffer_state) { |
Mark Lobodzinski | f933db9 | 2019-03-09 12:58:03 -0700 | [diff] [blame] | 4398 | skip |= ValidateIdleBuffer(buffer); |
Mark Lobodzinski | 306441e | 2017-02-10 13:48:38 -0700 | [diff] [blame] | 4399 | } |
| 4400 | return skip; |
| 4401 | } |
| 4402 | |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 4403 | void CoreChecks::PreCallRecordDestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks *pAllocator) { |
Mark Lobodzinski | dd995d2 | 2019-01-11 11:05:15 -0700 | [diff] [blame] | 4404 | if (!buffer) return; |
Mark Lobodzinski | 6ed7414 | 2019-03-06 11:35:39 -0700 | [diff] [blame] | 4405 | auto buffer_state = GetBufferState(buffer); |
Mark Lobodzinski | dd995d2 | 2019-01-11 11:05:15 -0700 | [diff] [blame] | 4406 | VK_OBJECT obj_struct = {HandleToUint64(buffer), kVulkanObjectTypeBuffer}; |
| 4407 | |
Mark Lobodzinski | 9ddb718 | 2019-03-08 17:31:09 -0700 | [diff] [blame] | 4408 | InvalidateCommandBuffers(buffer_state->cb_bindings, obj_struct); |
Mark Lobodzinski | 306441e | 2017-02-10 13:48:38 -0700 | [diff] [blame] | 4409 | for (auto mem_binding : buffer_state->GetBoundMemory()) { |
Mark Lobodzinski | 97f83f7 | 2019-03-07 10:01:52 -0700 | [diff] [blame] | 4410 | auto mem_info = GetMemObjInfo(mem_binding); |
Mark Lobodzinski | 306441e | 2017-02-10 13:48:38 -0700 | [diff] [blame] | 4411 | if (mem_info) { |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 4412 | RemoveBufferMemoryRange(HandleToUint64(buffer), mem_info); |
Mark Lobodzinski | 306441e | 2017-02-10 13:48:38 -0700 | [diff] [blame] | 4413 | } |
| 4414 | } |
Mark Lobodzinski | 97f83f7 | 2019-03-07 10:01:52 -0700 | [diff] [blame] | 4415 | ClearMemoryObjectBindings(HandleToUint64(buffer), kVulkanObjectTypeBuffer); |
Mark Lobodzinski | daea591 | 2019-03-07 14:47:09 -0700 | [diff] [blame] | 4416 | EraseQFOReleaseBarriers<VkBufferMemoryBarrier>(buffer); |
Mark Lobodzinski | 1170cf2 | 2019-03-07 11:08:21 -0700 | [diff] [blame] | 4417 | GetBufferMap()->erase(buffer_state->buffer); |
Mark Lobodzinski | 306441e | 2017-02-10 13:48:38 -0700 | [diff] [blame] | 4418 | } |
| 4419 | |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 4420 | bool CoreChecks::PreCallValidateDestroyBufferView(VkDevice device, VkBufferView bufferView, |
| 4421 | const VkAllocationCallbacks *pAllocator) { |
Mark Lobodzinski | 31aa9b0 | 2019-03-06 11:51:37 -0700 | [diff] [blame] | 4422 | auto buffer_view_state = GetBufferViewState(bufferView); |
Mark Lobodzinski | dd995d2 | 2019-01-11 11:05:15 -0700 | [diff] [blame] | 4423 | VK_OBJECT obj_struct = {HandleToUint64(bufferView), kVulkanObjectTypeBufferView}; |
Mark Lobodzinski | 306441e | 2017-02-10 13:48:38 -0700 | [diff] [blame] | 4424 | bool skip = false; |
Mark Lobodzinski | dd995d2 | 2019-01-11 11:05:15 -0700 | [diff] [blame] | 4425 | if (buffer_view_state) { |
Mark Lobodzinski | 9ddb718 | 2019-03-08 17:31:09 -0700 | [diff] [blame] | 4426 | skip |= ValidateObjectNotInUse(buffer_view_state, obj_struct, "vkDestroyBufferView", |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 4427 | "VUID-vkDestroyBufferView-bufferView-00936"); |
Mark Lobodzinski | 306441e | 2017-02-10 13:48:38 -0700 | [diff] [blame] | 4428 | } |
| 4429 | return skip; |
| 4430 | } |
| 4431 | |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 4432 | void CoreChecks::PreCallRecordDestroyBufferView(VkDevice device, VkBufferView bufferView, const VkAllocationCallbacks *pAllocator) { |
Mark Lobodzinski | dd995d2 | 2019-01-11 11:05:15 -0700 | [diff] [blame] | 4433 | if (!bufferView) return; |
Mark Lobodzinski | 31aa9b0 | 2019-03-06 11:51:37 -0700 | [diff] [blame] | 4434 | auto buffer_view_state = GetBufferViewState(bufferView); |
Mark Lobodzinski | dd995d2 | 2019-01-11 11:05:15 -0700 | [diff] [blame] | 4435 | VK_OBJECT obj_struct = {HandleToUint64(bufferView), kVulkanObjectTypeBufferView}; |
| 4436 | |
Mark Lobodzinski | 306441e | 2017-02-10 13:48:38 -0700 | [diff] [blame] | 4437 | // Any bound cmd buffers are now invalid |
Mark Lobodzinski | 9ddb718 | 2019-03-08 17:31:09 -0700 | [diff] [blame] | 4438 | InvalidateCommandBuffers(buffer_view_state->cb_bindings, obj_struct); |
Mark Lobodzinski | 1170cf2 | 2019-03-07 11:08:21 -0700 | [diff] [blame] | 4439 | GetBufferViewMap()->erase(bufferView); |
Mark Lobodzinski | 306441e | 2017-02-10 13:48:38 -0700 | [diff] [blame] | 4440 | } |
Mark Lobodzinski | df0acbf | 2017-02-10 14:01:27 -0700 | [diff] [blame] | 4441 | |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 4442 | bool CoreChecks::PreCallValidateCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 4443 | VkDeviceSize size, uint32_t data) { |
Mark Lobodzinski | 1b3a971 | 2019-03-06 15:51:47 -0700 | [diff] [blame] | 4444 | auto cb_node = GetCBNode(commandBuffer); |
Mark Lobodzinski | 6ed7414 | 2019-03-06 11:35:39 -0700 | [diff] [blame] | 4445 | auto buffer_state = GetBufferState(dstBuffer); |
Mark Lobodzinski | df0acbf | 2017-02-10 14:01:27 -0700 | [diff] [blame] | 4446 | bool skip = false; |
Mark Lobodzinski | 0ebe971 | 2019-03-07 13:39:07 -0700 | [diff] [blame] | 4447 | skip |= ValidateMemoryIsBoundToBuffer(buffer_state, "vkCmdFillBuffer()", "VUID-vkCmdFillBuffer-dstBuffer-00031"); |
Mark Lobodzinski | daea591 | 2019-03-07 14:47:09 -0700 | [diff] [blame] | 4448 | skip |= |
| 4449 | ValidateCmdQueueFlags(cb_node, "vkCmdFillBuffer()", VK_QUEUE_TRANSFER_BIT | VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT, |
| 4450 | "VUID-vkCmdFillBuffer-commandBuffer-cmdpool"); |
Mark Lobodzinski | fae179e | 2019-03-08 16:47:08 -0700 | [diff] [blame] | 4451 | skip |= ValidateCmd(cb_node, CMD_FILLBUFFER, "vkCmdFillBuffer()"); |
Mark Lobodzinski | df0acbf | 2017-02-10 14:01:27 -0700 | [diff] [blame] | 4452 | // Validate that DST buffer has correct usage flags set |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 4453 | skip |= ValidateBufferUsageFlags(buffer_state, VK_BUFFER_USAGE_TRANSFER_DST_BIT, true, "VUID-vkCmdFillBuffer-dstBuffer-00029", |
| 4454 | "vkCmdFillBuffer()", "VK_BUFFER_USAGE_TRANSFER_DST_BIT"); |
Mark Lobodzinski | fae179e | 2019-03-08 16:47:08 -0700 | [diff] [blame] | 4455 | skip |= InsideRenderPass(cb_node, "vkCmdFillBuffer()", "VUID-vkCmdFillBuffer-renderpass"); |
Mark Lobodzinski | df0acbf | 2017-02-10 14:01:27 -0700 | [diff] [blame] | 4456 | return skip; |
| 4457 | } |
| 4458 | |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 4459 | void CoreChecks::PreCallRecordCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, |
| 4460 | VkDeviceSize size, uint32_t data) { |
Mark Lobodzinski | 1b3a971 | 2019-03-06 15:51:47 -0700 | [diff] [blame] | 4461 | auto cb_node = GetCBNode(commandBuffer); |
Mark Lobodzinski | 6ed7414 | 2019-03-06 11:35:39 -0700 | [diff] [blame] | 4462 | auto buffer_state = GetBufferState(dstBuffer); |
Mark Lobodzinski | df0acbf | 2017-02-10 14:01:27 -0700 | [diff] [blame] | 4463 | // Update bindings between buffer and cmd buffer |
Mark Lobodzinski | fae179e | 2019-03-08 16:47:08 -0700 | [diff] [blame] | 4464 | AddCommandBufferBindingBuffer(cb_node, buffer_state); |
Mark Lobodzinski | df0acbf | 2017-02-10 14:01:27 -0700 | [diff] [blame] | 4465 | } |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 4466 | |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 4467 | bool CoreChecks::ValidateBufferImageCopyData(uint32_t regionCount, const VkBufferImageCopy *pRegions, IMAGE_STATE *image_state, |
| 4468 | const char *function) { |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 4469 | bool skip = false; |
| 4470 | |
| 4471 | for (uint32_t i = 0; i < regionCount; i++) { |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 4472 | if (image_state->createInfo.imageType == VK_IMAGE_TYPE_1D) { |
| 4473 | if ((pRegions[i].imageOffset.y != 0) || (pRegions[i].imageExtent.height != 1)) { |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 4474 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 4475 | HandleToUint64(image_state->image), "VUID-VkBufferImageCopy-srcImage-00199", |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 4476 | "%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] | 4477 | "and 1, respectively.", |
| 4478 | function, i, pRegions[i].imageOffset.y, pRegions[i].imageExtent.height); |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 4479 | } |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 4480 | } |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 4481 | |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 4482 | if ((image_state->createInfo.imageType == VK_IMAGE_TYPE_1D) || (image_state->createInfo.imageType == VK_IMAGE_TYPE_2D)) { |
| 4483 | if ((pRegions[i].imageOffset.z != 0) || (pRegions[i].imageExtent.depth != 1)) { |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 4484 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 4485 | HandleToUint64(image_state->image), "VUID-VkBufferImageCopy-srcImage-00201", |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 4486 | "%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] | 4487 | "must be 0 and 1, respectively.", |
| 4488 | function, i, pRegions[i].imageOffset.z, pRegions[i].imageExtent.depth); |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 4489 | } |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 4490 | } |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 4491 | |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 4492 | if (image_state->createInfo.imageType == VK_IMAGE_TYPE_3D) { |
| 4493 | if ((0 != pRegions[i].imageSubresource.baseArrayLayer) || (1 != pRegions[i].imageSubresource.layerCount)) { |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 4494 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 4495 | HandleToUint64(image_state->image), "VUID-VkBufferImageCopy-baseArrayLayer-00213", |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 4496 | "%s(): pRegion[%d] imageSubresource.baseArrayLayer is %d and imageSubresource.layerCount is %d. " |
| 4497 | "For 3D images these must be 0 and 1, respectively.", |
| 4498 | function, i, pRegions[i].imageSubresource.baseArrayLayer, pRegions[i].imageSubresource.layerCount); |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 4499 | } |
| 4500 | } |
| 4501 | |
| 4502 | // If the the calling command's VkImage parameter's format is not a depth/stencil format, |
Dave Houlton | a585d13 | 2019-01-18 13:05:42 -0700 | [diff] [blame] | 4503 | // then bufferOffset must be a multiple of the calling command's VkImage parameter's element size |
Locke | 497739c | 2019-03-08 11:50:47 -0700 | [diff] [blame] | 4504 | uint32_t element_size = FormatElementSize(image_state->createInfo.format, pRegions[i].imageSubresource.aspectMask); |
| 4505 | |
Dave Houlton | a585d13 | 2019-01-18 13:05:42 -0700 | [diff] [blame] | 4506 | if (!FormatIsDepthAndStencil(image_state->createInfo.format) && SafeModulo(pRegions[i].bufferOffset, element_size) != 0) { |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 4507 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 4508 | HandleToUint64(image_state->image), "VUID-VkBufferImageCopy-bufferOffset-00193", |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 4509 | "%s(): pRegion[%d] bufferOffset 0x%" PRIxLEAST64 |
Dave Houlton | a585d13 | 2019-01-18 13:05:42 -0700 | [diff] [blame] | 4510 | " must be a multiple of this format's texel size (%" PRIu32 ").", |
| 4511 | function, i, pRegions[i].bufferOffset, element_size); |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 4512 | } |
| 4513 | |
| 4514 | // BufferOffset must be a multiple of 4 |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 4515 | if (SafeModulo(pRegions[i].bufferOffset, 4) != 0) { |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 4516 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 4517 | HandleToUint64(image_state->image), "VUID-VkBufferImageCopy-bufferOffset-00194", |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 4518 | "%s(): pRegion[%d] bufferOffset 0x%" PRIxLEAST64 " must be a multiple of 4.", function, i, |
| 4519 | pRegions[i].bufferOffset); |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 4520 | } |
| 4521 | |
| 4522 | // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent |
| 4523 | if ((pRegions[i].bufferRowLength != 0) && (pRegions[i].bufferRowLength < pRegions[i].imageExtent.width)) { |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 4524 | skip |= |
| 4525 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 4526 | HandleToUint64(image_state->image), "VUID-VkBufferImageCopy-bufferRowLength-00195", |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 4527 | "%s(): pRegion[%d] bufferRowLength (%d) must be zero or greater-than-or-equal-to imageExtent.width (%d).", |
| 4528 | function, i, pRegions[i].bufferRowLength, pRegions[i].imageExtent.width); |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 4529 | } |
| 4530 | |
| 4531 | // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent |
| 4532 | if ((pRegions[i].bufferImageHeight != 0) && (pRegions[i].bufferImageHeight < pRegions[i].imageExtent.height)) { |
| 4533 | skip |= log_msg( |
| 4534 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 4535 | HandleToUint64(image_state->image), "VUID-VkBufferImageCopy-bufferImageHeight-00196", |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 4536 | "%s(): pRegion[%d] bufferImageHeight (%d) must be zero or greater-than-or-equal-to imageExtent.height (%d).", |
| 4537 | function, i, pRegions[i].bufferImageHeight, pRegions[i].imageExtent.height); |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 4538 | } |
| 4539 | |
| 4540 | // subresource aspectMask must have exactly 1 bit set |
| 4541 | const int num_bits = sizeof(VkFlags) * CHAR_BIT; |
| 4542 | std::bitset<num_bits> aspect_mask_bits(pRegions[i].imageSubresource.aspectMask); |
| 4543 | if (aspect_mask_bits.count() != 1) { |
| 4544 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 4545 | HandleToUint64(image_state->image), "VUID-VkBufferImageCopy-aspectMask-00212", |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 4546 | "%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] | 4547 | } |
| 4548 | |
| 4549 | // image subresource aspect bit must match format |
Dave Houlton | 4eaaf3a | 2017-03-14 11:31:20 -0600 | [diff] [blame] | 4550 | if (!VerifyAspectsPresent(pRegions[i].imageSubresource.aspectMask, image_state->createInfo.format)) { |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 4551 | skip |= log_msg( |
| 4552 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 4553 | HandleToUint64(image_state->image), "VUID-VkBufferImageCopy-aspectMask-00211", |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 4554 | "%s(): pRegion[%d] subresource aspectMask 0x%x specifies aspects that are not present in image format 0x%x.", |
| 4555 | function, i, pRegions[i].imageSubresource.aspectMask, image_state->createInfo.format); |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 4556 | } |
| 4557 | |
| 4558 | // Checks that apply only to compressed images |
Cort Stratton | 420ebd4 | 2018-05-04 01:12:23 -0400 | [diff] [blame] | 4559 | if (FormatIsCompressed(image_state->createInfo.format) || FormatIsSinglePlane_422(image_state->createInfo.format)) { |
Dave Houlton | a585d13 | 2019-01-18 13:05:42 -0700 | [diff] [blame] | 4560 | auto block_size = FormatTexelBlockExtent(image_state->createInfo.format); |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 4561 | |
| 4562 | // BufferRowLength must be a multiple of block width |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 4563 | if (SafeModulo(pRegions[i].bufferRowLength, block_size.width) != 0) { |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 4564 | skip |= log_msg( |
| 4565 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 4566 | HandleToUint64(image_state->image), "VUID-VkBufferImageCopy-bufferRowLength-00203", |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 4567 | "%s(): pRegion[%d] bufferRowLength (%d) must be a multiple of the compressed image's texel width (%d)..", |
| 4568 | function, i, pRegions[i].bufferRowLength, block_size.width); |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 4569 | } |
| 4570 | |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 4571 | // BufferRowHeight must be a multiple of block height |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 4572 | if (SafeModulo(pRegions[i].bufferImageHeight, block_size.height) != 0) { |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 4573 | skip |= log_msg( |
| 4574 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 4575 | HandleToUint64(image_state->image), "VUID-VkBufferImageCopy-bufferImageHeight-00204", |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 4576 | "%s(): pRegion[%d] bufferImageHeight (%d) must be a multiple of the compressed image's texel height (%d)..", |
| 4577 | function, i, pRegions[i].bufferImageHeight, block_size.height); |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 4578 | } |
| 4579 | |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 4580 | // image offsets must be multiples of block dimensions |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 4581 | if ((SafeModulo(pRegions[i].imageOffset.x, block_size.width) != 0) || |
| 4582 | (SafeModulo(pRegions[i].imageOffset.y, block_size.height) != 0) || |
| 4583 | (SafeModulo(pRegions[i].imageOffset.z, block_size.depth) != 0)) { |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 4584 | skip |= |
| 4585 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 4586 | HandleToUint64(image_state->image), "VUID-VkBufferImageCopy-imageOffset-00205", |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 4587 | "%s(): pRegion[%d] imageOffset(x,y) (%d, %d) must be multiples of the compressed image's texel " |
| 4588 | "width & height (%d, %d)..", |
| 4589 | 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] | 4590 | } |
| 4591 | |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 4592 | // bufferOffset must be a multiple of block size (linear bytes) |
Dave Houlton | a585d13 | 2019-01-18 13:05:42 -0700 | [diff] [blame] | 4593 | uint32_t block_size_in_bytes = FormatElementSize(image_state->createInfo.format); |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 4594 | if (SafeModulo(pRegions[i].bufferOffset, block_size_in_bytes) != 0) { |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 4595 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 4596 | HandleToUint64(image_state->image), "VUID-VkBufferImageCopy-bufferOffset-00206", |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 4597 | "%s(): pRegion[%d] bufferOffset (0x%" PRIxLEAST64 |
Dave Houlton | a585d13 | 2019-01-18 13:05:42 -0700 | [diff] [blame] | 4598 | ") must be a multiple of the compressed image's texel block size (%" PRIu32 ")..", |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 4599 | function, i, pRegions[i].bufferOffset, block_size_in_bytes); |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 4600 | } |
Dave Houlton | 67e9b53 | 2017-03-02 17:00:10 -0700 | [diff] [blame] | 4601 | |
| 4602 | // 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] | 4603 | VkExtent3D mip_extent = GetImageSubresourceExtent(image_state, &(pRegions[i].imageSubresource)); |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 4604 | if ((SafeModulo(pRegions[i].imageExtent.width, block_size.width) != 0) && |
Dave Houlton | 75967fc | 2017-03-06 17:21:16 -0700 | [diff] [blame] | 4605 | (pRegions[i].imageExtent.width + pRegions[i].imageOffset.x != mip_extent.width)) { |
| 4606 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 4607 | HandleToUint64(image_state->image), "VUID-VkBufferImageCopy-imageExtent-00207", |
Dave Houlton | 75967fc | 2017-03-06 17:21:16 -0700 | [diff] [blame] | 4608 | "%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] | 4609 | "(%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] | 4610 | 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] | 4611 | mip_extent.width); |
Dave Houlton | 67e9b53 | 2017-03-02 17:00:10 -0700 | [diff] [blame] | 4612 | } |
| 4613 | |
| 4614 | // 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] | 4615 | if ((SafeModulo(pRegions[i].imageExtent.height, block_size.height) != 0) && |
Dave Houlton | 75967fc | 2017-03-06 17:21:16 -0700 | [diff] [blame] | 4616 | (pRegions[i].imageExtent.height + pRegions[i].imageOffset.y != mip_extent.height)) { |
| 4617 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 4618 | HandleToUint64(image_state->image), "VUID-VkBufferImageCopy-imageExtent-00208", |
Dave Houlton | 75967fc | 2017-03-06 17:21:16 -0700 | [diff] [blame] | 4619 | "%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] | 4620 | "(%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] | 4621 | 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] | 4622 | mip_extent.height); |
Dave Houlton | 67e9b53 | 2017-03-02 17:00:10 -0700 | [diff] [blame] | 4623 | } |
| 4624 | |
| 4625 | // 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] | 4626 | if ((SafeModulo(pRegions[i].imageExtent.depth, block_size.depth) != 0) && |
Dave Houlton | 75967fc | 2017-03-06 17:21:16 -0700 | [diff] [blame] | 4627 | (pRegions[i].imageExtent.depth + pRegions[i].imageOffset.z != mip_extent.depth)) { |
| 4628 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 4629 | HandleToUint64(image_state->image), "VUID-VkBufferImageCopy-imageExtent-00209", |
Dave Houlton | 75967fc | 2017-03-06 17:21:16 -0700 | [diff] [blame] | 4630 | "%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] | 4631 | "(%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] | 4632 | 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] | 4633 | mip_extent.depth); |
Dave Houlton | 67e9b53 | 2017-03-02 17:00:10 -0700 | [diff] [blame] | 4634 | } |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 4635 | } |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 4636 | } |
| 4637 | |
| 4638 | return skip; |
| 4639 | } |
| 4640 | |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 4641 | static bool ValidateImageBounds(const debug_report_data *report_data, const IMAGE_STATE *image_state, const uint32_t regionCount, |
Jeff Bolz | 6d3beaa | 2019-02-09 21:00:05 -0600 | [diff] [blame] | 4642 | const VkBufferImageCopy *pRegions, const char *func_name, const char *msg_code) { |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 4643 | bool skip = false; |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 4644 | const VkImageCreateInfo *image_info = &(image_state->createInfo); |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 4645 | |
| 4646 | for (uint32_t i = 0; i < regionCount; i++) { |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 4647 | VkExtent3D extent = pRegions[i].imageExtent; |
| 4648 | VkOffset3D offset = pRegions[i].imageOffset; |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 4649 | |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 4650 | if (IsExtentSizeZero(&extent)) // Warn on zero area subresource |
| 4651 | { |
Dave Houlton | 5165390 | 2018-06-22 17:32:13 -0600 | [diff] [blame] | 4652 | skip |= |
| 4653 | log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)0, |
| 4654 | kVUID_Core_Image_ZeroAreaSubregion, "%s: pRegion[%d] imageExtent of {%1d, %1d, %1d} has zero area", |
| 4655 | func_name, i, extent.width, extent.height, extent.depth); |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 4656 | } |
| 4657 | |
| 4658 | VkExtent3D image_extent = GetImageSubresourceExtent(image_state, &(pRegions[i].imageSubresource)); |
| 4659 | |
| 4660 | // 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] | 4661 | if (FormatIsCompressed(image_info->format)) { |
Dave Houlton | a585d13 | 2019-01-18 13:05:42 -0700 | [diff] [blame] | 4662 | auto block_extent = FormatTexelBlockExtent(image_info->format); |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 4663 | if (image_extent.width % block_extent.width) { |
| 4664 | image_extent.width += (block_extent.width - (image_extent.width % block_extent.width)); |
| 4665 | } |
| 4666 | if (image_extent.height % block_extent.height) { |
| 4667 | image_extent.height += (block_extent.height - (image_extent.height % block_extent.height)); |
| 4668 | } |
| 4669 | if (image_extent.depth % block_extent.depth) { |
| 4670 | image_extent.depth += (block_extent.depth - (image_extent.depth % block_extent.depth)); |
| 4671 | } |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 4672 | } |
| 4673 | |
Dave Houlton | fc1a405 | 2017-04-27 14:32:45 -0600 | [diff] [blame] | 4674 | if (0 != ExceedsBounds(&offset, &extent, &image_extent)) { |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 4675 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)0, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 4676 | msg_code, "%s: pRegion[%d] exceeds image bounds..", func_name, i); |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 4677 | } |
| 4678 | } |
| 4679 | |
| 4680 | return skip; |
| 4681 | } |
| 4682 | |
Chris Forbes | e8ba09a | 2017-06-01 17:39:02 -0700 | [diff] [blame] | 4683 | 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] | 4684 | uint32_t regionCount, const VkBufferImageCopy *pRegions, const char *func_name, |
Jeff Bolz | 6d3beaa | 2019-02-09 21:00:05 -0600 | [diff] [blame] | 4685 | const char *msg_code) { |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 4686 | bool skip = false; |
| 4687 | |
| 4688 | VkDeviceSize buffer_size = buff_state->createInfo.size; |
| 4689 | |
| 4690 | for (uint32_t i = 0; i < regionCount; i++) { |
| 4691 | VkExtent3D copy_extent = pRegions[i].imageExtent; |
| 4692 | |
| 4693 | VkDeviceSize buffer_width = (0 == pRegions[i].bufferRowLength ? copy_extent.width : pRegions[i].bufferRowLength); |
| 4694 | VkDeviceSize buffer_height = (0 == pRegions[i].bufferImageHeight ? copy_extent.height : pRegions[i].bufferImageHeight); |
Locke | 497739c | 2019-03-08 11:50:47 -0700 | [diff] [blame] | 4695 | VkDeviceSize unit_size = FormatElementSize(image_state->createInfo.format, |
| 4696 | pRegions[i].imageSubresource.aspectMask); // size (bytes) of texel or block |
Dave Houlton | f3229d5 | 2017-02-21 15:59:08 -0700 | [diff] [blame] | 4697 | |
Tom Cooper | b2550c7 | 2018-10-15 13:08:41 +0100 | [diff] [blame] | 4698 | if (FormatIsCompressed(image_state->createInfo.format) || FormatIsSinglePlane_422(image_state->createInfo.format)) { |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 4699 | // Switch to texel block units, rounding up for any partially-used blocks |
Dave Houlton | a585d13 | 2019-01-18 13:05:42 -0700 | [diff] [blame] | 4700 | auto block_dim = FormatTexelBlockExtent(image_state->createInfo.format); |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 4701 | buffer_width = (buffer_width + block_dim.width - 1) / block_dim.width; |
| 4702 | buffer_height = (buffer_height + block_dim.height - 1) / block_dim.height; |
| 4703 | |
| 4704 | copy_extent.width = (copy_extent.width + block_dim.width - 1) / block_dim.width; |
| 4705 | copy_extent.height = (copy_extent.height + block_dim.height - 1) / block_dim.height; |
| 4706 | 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] | 4707 | } |
| 4708 | |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 4709 | // Either depth or layerCount may be greater than 1 (not both). This is the number of 'slices' to copy |
| 4710 | uint32_t z_copies = std::max(copy_extent.depth, pRegions[i].imageSubresource.layerCount); |
| 4711 | if (IsExtentSizeZero(©_extent) || (0 == z_copies)) { |
Chris Forbes | e8ba09a | 2017-06-01 17:39:02 -0700 | [diff] [blame] | 4712 | // TODO: Issue warning here? Already warned in ValidateImageBounds()... |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 4713 | } else { |
| 4714 | // Calculate buffer offset of final copied byte, + 1. |
| 4715 | VkDeviceSize max_buffer_offset = (z_copies - 1) * buffer_height * buffer_width; // offset to slice |
| 4716 | max_buffer_offset += ((copy_extent.height - 1) * buffer_width) + copy_extent.width; // add row,col |
| 4717 | max_buffer_offset *= unit_size; // convert to bytes |
| 4718 | max_buffer_offset += pRegions[i].bufferOffset; // add initial offset (bytes) |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 4719 | |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 4720 | if (buffer_size < max_buffer_offset) { |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 4721 | skip |= |
| 4722 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)0, |
| 4723 | msg_code, "%s: pRegion[%d] exceeds buffer size of %" PRIu64 " bytes..", func_name, i, buffer_size); |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 4724 | } |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 4725 | } |
| 4726 | } |
| 4727 | |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 4728 | return skip; |
| 4729 | } |
| 4730 | |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 4731 | bool CoreChecks::PreCallValidateCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 4732 | VkBuffer dstBuffer, uint32_t regionCount, const VkBufferImageCopy *pRegions) { |
Mark Lobodzinski | 1b3a971 | 2019-03-06 15:51:47 -0700 | [diff] [blame] | 4733 | auto cb_node = GetCBNode(commandBuffer); |
Mark Lobodzinski | 8ddc23f | 2019-03-06 11:48:49 -0700 | [diff] [blame] | 4734 | auto src_image_state = GetImageState(srcImage); |
Mark Lobodzinski | 6ed7414 | 2019-03-06 11:35:39 -0700 | [diff] [blame] | 4735 | auto dst_buffer_state = GetBufferState(dstBuffer); |
Mark Lobodzinski | b7eafbe | 2019-01-10 13:40:39 -0700 | [diff] [blame] | 4736 | |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 4737 | bool skip = ValidateBufferImageCopyData(regionCount, pRegions, src_image_state, "vkCmdCopyImageToBuffer"); |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 4738 | |
| 4739 | // Validate command buffer state |
Mark Lobodzinski | fae179e | 2019-03-08 16:47:08 -0700 | [diff] [blame] | 4740 | skip |= ValidateCmd(cb_node, CMD_COPYIMAGETOBUFFER, "vkCmdCopyImageToBuffer()"); |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 4741 | |
| 4742 | // Command pool must support graphics, compute, or transfer operations |
Mark Lobodzinski | 8b0a7b8 | 2019-03-06 16:17:45 -0700 | [diff] [blame] | 4743 | auto pPool = GetCommandPoolNode(cb_node->createInfo.commandPool); |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 4744 | |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 4745 | VkQueueFlags queue_flags = GetPhysicalDeviceState()->queue_family_properties[pPool->queueFamilyIndex].queueFlags; |
Mark Lobodzinski | f6dd376 | 2019-02-27 12:11:59 -0700 | [diff] [blame] | 4746 | |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 4747 | if (0 == (queue_flags & (VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT | VK_QUEUE_TRANSFER_BIT))) { |
| 4748 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 4749 | HandleToUint64(cb_node->createInfo.commandPool), "VUID-vkCmdCopyImageToBuffer-commandBuffer-cmdpool", |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 4750 | "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] | 4751 | "or transfer capabilities.."); |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 4752 | } |
Dave Houlton | 0ef2749 | 2018-04-04 11:41:48 -0600 | [diff] [blame] | 4753 | skip |= ValidateImageBounds(report_data, src_image_state, regionCount, pRegions, "vkCmdCopyImageToBuffer()", |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 4754 | "VUID-vkCmdCopyImageToBuffer-pRegions-00182"); |
Chris Forbes | e8ba09a | 2017-06-01 17:39:02 -0700 | [diff] [blame] | 4755 | skip |= ValidateBufferBounds(report_data, src_image_state, dst_buffer_state, regionCount, pRegions, "vkCmdCopyImageToBuffer()", |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 4756 | "VUID-vkCmdCopyImageToBuffer-pRegions-00183"); |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 4757 | |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 4758 | skip |= ValidateImageSampleCount(src_image_state, VK_SAMPLE_COUNT_1_BIT, "vkCmdCopyImageToBuffer(): srcImage", |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 4759 | "VUID-vkCmdCopyImageToBuffer-srcImage-00188"); |
Mark Lobodzinski | 0ebe971 | 2019-03-07 13:39:07 -0700 | [diff] [blame] | 4760 | skip |= ValidateMemoryIsBoundToImage(src_image_state, "vkCmdCopyImageToBuffer()", "VUID-vkCmdCopyImageToBuffer-srcImage-00187"); |
| 4761 | skip |= |
| 4762 | ValidateMemoryIsBoundToBuffer(dst_buffer_state, "vkCmdCopyImageToBuffer()", "VUID-vkCmdCopyImageToBuffer-dstBuffer-00192"); |
Mark Lobodzinski | 033c90b | 2017-02-15 13:58:23 -0700 | [diff] [blame] | 4763 | |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 4764 | // Validate that SRC image & DST buffer have correct usage flags set |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 4765 | skip |= ValidateImageUsageFlags(src_image_state, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, true, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 4766 | "VUID-vkCmdCopyImageToBuffer-srcImage-00186", "vkCmdCopyImageToBuffer()", |
| 4767 | "VK_IMAGE_USAGE_TRANSFER_SRC_BIT"); |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 4768 | skip |= ValidateBufferUsageFlags(dst_buffer_state, VK_BUFFER_USAGE_TRANSFER_DST_BIT, true, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 4769 | "VUID-vkCmdCopyImageToBuffer-dstBuffer-00191", "vkCmdCopyImageToBuffer()", |
| 4770 | "VK_BUFFER_USAGE_TRANSFER_DST_BIT"); |
Mark Lobodzinski | 96d5c6e | 2019-03-07 11:28:21 -0700 | [diff] [blame] | 4771 | if (GetApiVersion() >= VK_API_VERSION_1_1 || GetDeviceExtensions()->vk_khr_maintenance1) { |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 4772 | skip |= ValidateImageFormatFeatureFlags(src_image_state, VK_FORMAT_FEATURE_TRANSFER_SRC_BIT, "vkCmdCopyImageToBuffer()", |
| 4773 | "VUID-vkCmdCopyImageToBuffer-srcImage-01998", |
Shannon McPherson | 40c0cba | 2018-08-07 13:39:13 -0600 | [diff] [blame] | 4774 | "VUID-vkCmdCopyImageToBuffer-srcImage-01998"); |
Cort Stratton | 186b1a2 | 2018-05-01 20:18:06 -0400 | [diff] [blame] | 4775 | } |
Mark Lobodzinski | fae179e | 2019-03-08 16:47:08 -0700 | [diff] [blame] | 4776 | skip |= InsideRenderPass(cb_node, "vkCmdCopyImageToBuffer()", "VUID-vkCmdCopyImageToBuffer-renderpass"); |
Tobin Ehlis | c826645 | 2017-04-07 12:20:30 -0600 | [diff] [blame] | 4777 | bool hit_error = false; |
Jeff Bolz | fdd0d85 | 2019-02-03 21:55:12 -0600 | [diff] [blame] | 4778 | const char *src_invalid_layout_vuid = |
Mark Lobodzinski | 60e7903 | 2019-03-07 10:22:31 -0700 | [diff] [blame] | 4779 | (src_image_state->shared_presentable && GetDeviceExtensions()->vk_khr_shared_presentable_image) |
Cort Stratton | 7df3096 | 2018-05-17 19:45:57 -0700 | [diff] [blame] | 4780 | ? "VUID-vkCmdCopyImageToBuffer-srcImageLayout-01397" |
| 4781 | : "VUID-vkCmdCopyImageToBuffer-srcImageLayout-00190"; |
Mark Lobodzinski | 033c90b | 2017-02-15 13:58:23 -0700 | [diff] [blame] | 4782 | for (uint32_t i = 0; i < regionCount; ++i) { |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 4783 | skip |= ValidateImageSubresourceLayers(cb_node, &pRegions[i].imageSubresource, "vkCmdCopyImageToBuffer()", |
Cort Stratton | d619a30 | 2018-05-17 19:46:32 -0700 | [diff] [blame] | 4784 | "imageSubresource", i); |
Mark Lobodzinski | 8564e44 | 2019-03-07 12:49:41 -0700 | [diff] [blame] | 4785 | skip |= VerifyImageLayout(cb_node, src_image_state, pRegions[i].imageSubresource, srcImageLayout, |
Cort Stratton | 7df3096 | 2018-05-17 19:45:57 -0700 | [diff] [blame] | 4786 | VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, "vkCmdCopyImageToBuffer()", src_invalid_layout_vuid, |
| 4787 | "VUID-vkCmdCopyImageToBuffer-srcImageLayout-00189", &hit_error); |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 4788 | skip |= ValidateCopyBufferImageTransferGranularityRequirements( |
| 4789 | cb_node, src_image_state, &pRegions[i], i, "vkCmdCopyImageToBuffer()", "VUID-vkCmdCopyImageToBuffer-imageOffset-01794"); |
| 4790 | skip |= |
| 4791 | ValidateImageMipLevel(cb_node, src_image_state, pRegions[i].imageSubresource.mipLevel, i, "vkCmdCopyImageToBuffer()", |
| 4792 | "imageSubresource", "VUID-vkCmdCopyImageToBuffer-imageSubresource-01703"); |
| 4793 | skip |= ValidateImageArrayLayerRange(cb_node, src_image_state, pRegions[i].imageSubresource.baseArrayLayer, |
Cort Stratton | ff1542a | 2018-05-27 10:49:28 -0700 | [diff] [blame] | 4794 | pRegions[i].imageSubresource.layerCount, i, "vkCmdCopyImageToBuffer()", |
| 4795 | "imageSubresource", "VUID-vkCmdCopyImageToBuffer-imageSubresource-01704"); |
Mark Lobodzinski | 033c90b | 2017-02-15 13:58:23 -0700 | [diff] [blame] | 4796 | } |
| 4797 | return skip; |
| 4798 | } |
| 4799 | |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 4800 | void CoreChecks::PreCallRecordCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, |
| 4801 | VkBuffer dstBuffer, uint32_t regionCount, const VkBufferImageCopy *pRegions) { |
Mark Lobodzinski | 1b3a971 | 2019-03-06 15:51:47 -0700 | [diff] [blame] | 4802 | auto cb_node = GetCBNode(commandBuffer); |
Mark Lobodzinski | 8ddc23f | 2019-03-06 11:48:49 -0700 | [diff] [blame] | 4803 | auto src_image_state = GetImageState(srcImage); |
Mark Lobodzinski | 6ed7414 | 2019-03-06 11:35:39 -0700 | [diff] [blame] | 4804 | auto dst_buffer_state = GetBufferState(dstBuffer); |
Mark Lobodzinski | b7eafbe | 2019-01-10 13:40:39 -0700 | [diff] [blame] | 4805 | |
John Zulauf | f660ad6 | 2019-03-23 07:16:05 -0600 | [diff] [blame] | 4806 | // Make sure that all image slices record referenced layout |
Mark Lobodzinski | b7eafbe | 2019-01-10 13:40:39 -0700 | [diff] [blame] | 4807 | for (uint32_t i = 0; i < regionCount; ++i) { |
John Zulauf | f660ad6 | 2019-03-23 07:16:05 -0600 | [diff] [blame] | 4808 | SetImageInitialLayout(cb_node, *src_image_state, pRegions[i].imageSubresource, srcImageLayout); |
Tobin Ehlis | e35b66a | 2017-03-15 12:18:31 -0600 | [diff] [blame] | 4809 | } |
Mark Lobodzinski | 033c90b | 2017-02-15 13:58:23 -0700 | [diff] [blame] | 4810 | // Update bindings between buffer/image and cmd buffer |
Mark Lobodzinski | fae179e | 2019-03-08 16:47:08 -0700 | [diff] [blame] | 4811 | AddCommandBufferBindingImage(cb_node, src_image_state); |
| 4812 | AddCommandBufferBindingBuffer(cb_node, dst_buffer_state); |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 4813 | } |
| 4814 | |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 4815 | bool CoreChecks::PreCallValidateCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, |
| 4816 | VkImageLayout dstImageLayout, uint32_t regionCount, |
| 4817 | const VkBufferImageCopy *pRegions) { |
Mark Lobodzinski | 1b3a971 | 2019-03-06 15:51:47 -0700 | [diff] [blame] | 4818 | auto cb_node = GetCBNode(commandBuffer); |
Mark Lobodzinski | 6ed7414 | 2019-03-06 11:35:39 -0700 | [diff] [blame] | 4819 | auto src_buffer_state = GetBufferState(srcBuffer); |
Mark Lobodzinski | 8ddc23f | 2019-03-06 11:48:49 -0700 | [diff] [blame] | 4820 | auto dst_image_state = GetImageState(dstImage); |
Mark Lobodzinski | b7eafbe | 2019-01-10 13:40:39 -0700 | [diff] [blame] | 4821 | |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 4822 | bool skip = ValidateBufferImageCopyData(regionCount, pRegions, dst_image_state, "vkCmdCopyBufferToImage"); |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 4823 | |
| 4824 | // Validate command buffer state |
Mark Lobodzinski | fae179e | 2019-03-08 16:47:08 -0700 | [diff] [blame] | 4825 | skip |= ValidateCmd(cb_node, CMD_COPYBUFFERTOIMAGE, "vkCmdCopyBufferToImage()"); |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 4826 | |
| 4827 | // Command pool must support graphics, compute, or transfer operations |
Mark Lobodzinski | 8b0a7b8 | 2019-03-06 16:17:45 -0700 | [diff] [blame] | 4828 | auto pPool = GetCommandPoolNode(cb_node->createInfo.commandPool); |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 4829 | VkQueueFlags queue_flags = GetPhysicalDeviceState()->queue_family_properties[pPool->queueFamilyIndex].queueFlags; |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 4830 | if (0 == (queue_flags & (VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT | VK_QUEUE_TRANSFER_BIT))) { |
| 4831 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 4832 | HandleToUint64(cb_node->createInfo.commandPool), "VUID-vkCmdCopyBufferToImage-commandBuffer-cmdpool", |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 4833 | "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] | 4834 | "or transfer capabilities.."); |
Mark Lobodzinski | d2b2f61 | 2017-02-15 13:45:18 -0700 | [diff] [blame] | 4835 | } |
Dave Houlton | 9dae7ec | 2017-03-01 16:23:25 -0700 | [diff] [blame] | 4836 | skip |= ValidateImageBounds(report_data, dst_image_state, regionCount, pRegions, "vkCmdCopyBufferToImage()", |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 4837 | "VUID-vkCmdCopyBufferToImage-pRegions-00172"); |
Chris Forbes | e8ba09a | 2017-06-01 17:39:02 -0700 | [diff] [blame] | 4838 | skip |= ValidateBufferBounds(report_data, dst_image_state, src_buffer_state, regionCount, pRegions, "vkCmdCopyBufferToImage()", |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 4839 | "VUID-vkCmdCopyBufferToImage-pRegions-00171"); |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 4840 | skip |= ValidateImageSampleCount(dst_image_state, VK_SAMPLE_COUNT_1_BIT, "vkCmdCopyBufferToImage(): dstImage", |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 4841 | "VUID-vkCmdCopyBufferToImage-dstImage-00179"); |
Mark Lobodzinski | 0ebe971 | 2019-03-07 13:39:07 -0700 | [diff] [blame] | 4842 | skip |= |
| 4843 | ValidateMemoryIsBoundToBuffer(src_buffer_state, "vkCmdCopyBufferToImage()", "VUID-vkCmdCopyBufferToImage-srcBuffer-00176"); |
| 4844 | skip |= ValidateMemoryIsBoundToImage(dst_image_state, "vkCmdCopyBufferToImage()", "VUID-vkCmdCopyBufferToImage-dstImage-00178"); |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 4845 | skip |= ValidateBufferUsageFlags(src_buffer_state, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, true, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 4846 | "VUID-vkCmdCopyBufferToImage-srcBuffer-00174", "vkCmdCopyBufferToImage()", |
| 4847 | "VK_BUFFER_USAGE_TRANSFER_SRC_BIT"); |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 4848 | skip |= ValidateImageUsageFlags(dst_image_state, VK_IMAGE_USAGE_TRANSFER_DST_BIT, true, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 4849 | "VUID-vkCmdCopyBufferToImage-dstImage-00177", "vkCmdCopyBufferToImage()", |
| 4850 | "VK_IMAGE_USAGE_TRANSFER_DST_BIT"); |
Mark Lobodzinski | 96d5c6e | 2019-03-07 11:28:21 -0700 | [diff] [blame] | 4851 | if (GetApiVersion() >= VK_API_VERSION_1_1 || GetDeviceExtensions()->vk_khr_maintenance1) { |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 4852 | skip |= ValidateImageFormatFeatureFlags(dst_image_state, VK_FORMAT_FEATURE_TRANSFER_DST_BIT, "vkCmdCopyBufferToImage()", |
| 4853 | "VUID-vkCmdCopyBufferToImage-dstImage-01997", |
Shannon McPherson | 40c0cba | 2018-08-07 13:39:13 -0600 | [diff] [blame] | 4854 | "VUID-vkCmdCopyBufferToImage-dstImage-01997"); |
Cort Stratton | 186b1a2 | 2018-05-01 20:18:06 -0400 | [diff] [blame] | 4855 | } |
Mark Lobodzinski | fae179e | 2019-03-08 16:47:08 -0700 | [diff] [blame] | 4856 | skip |= InsideRenderPass(cb_node, "vkCmdCopyBufferToImage()", "VUID-vkCmdCopyBufferToImage-renderpass"); |
Tobin Ehlis | c826645 | 2017-04-07 12:20:30 -0600 | [diff] [blame] | 4857 | bool hit_error = false; |
Jeff Bolz | fdd0d85 | 2019-02-03 21:55:12 -0600 | [diff] [blame] | 4858 | const char *dst_invalid_layout_vuid = |
Mark Lobodzinski | 60e7903 | 2019-03-07 10:22:31 -0700 | [diff] [blame] | 4859 | (dst_image_state->shared_presentable && GetDeviceExtensions()->vk_khr_shared_presentable_image) |
Cort Stratton | 7df3096 | 2018-05-17 19:45:57 -0700 | [diff] [blame] | 4860 | ? "VUID-vkCmdCopyBufferToImage-dstImageLayout-01396" |
| 4861 | : "VUID-vkCmdCopyBufferToImage-dstImageLayout-00181"; |
Mark Lobodzinski | 033c90b | 2017-02-15 13:58:23 -0700 | [diff] [blame] | 4862 | for (uint32_t i = 0; i < regionCount; ++i) { |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 4863 | skip |= ValidateImageSubresourceLayers(cb_node, &pRegions[i].imageSubresource, "vkCmdCopyBufferToImage()", |
Cort Stratton | d619a30 | 2018-05-17 19:46:32 -0700 | [diff] [blame] | 4864 | "imageSubresource", i); |
Mark Lobodzinski | 8564e44 | 2019-03-07 12:49:41 -0700 | [diff] [blame] | 4865 | skip |= VerifyImageLayout(cb_node, dst_image_state, pRegions[i].imageSubresource, dstImageLayout, |
Cort Stratton | 7df3096 | 2018-05-17 19:45:57 -0700 | [diff] [blame] | 4866 | VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, "vkCmdCopyBufferToImage()", dst_invalid_layout_vuid, |
| 4867 | "VUID-vkCmdCopyBufferToImage-dstImageLayout-00180", &hit_error); |
Mark Lobodzinski | fbeb0ca | 2019-03-09 11:48:22 -0700 | [diff] [blame] | 4868 | skip |= ValidateCopyBufferImageTransferGranularityRequirements( |
| 4869 | cb_node, dst_image_state, &pRegions[i], i, "vkCmdCopyBufferToImage()", "VUID-vkCmdCopyBufferToImage-imageOffset-01793"); |
| 4870 | skip |= |
| 4871 | ValidateImageMipLevel(cb_node, dst_image_state, pRegions[i].imageSubresource.mipLevel, i, "vkCmdCopyBufferToImage()", |
| 4872 | "imageSubresource", "VUID-vkCmdCopyBufferToImage-imageSubresource-01701"); |
| 4873 | skip |= ValidateImageArrayLayerRange(cb_node, dst_image_state, pRegions[i].imageSubresource.baseArrayLayer, |
Cort Stratton | ff1542a | 2018-05-27 10:49:28 -0700 | [diff] [blame] | 4874 | pRegions[i].imageSubresource.layerCount, i, "vkCmdCopyBufferToImage()", |
| 4875 | "imageSubresource", "VUID-vkCmdCopyBufferToImage-imageSubresource-01702"); |
Mark Lobodzinski | 033c90b | 2017-02-15 13:58:23 -0700 | [diff] [blame] | 4876 | } |
| 4877 | return skip; |
| 4878 | } |
| 4879 | |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 4880 | void CoreChecks::PreCallRecordCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, |
| 4881 | VkImageLayout dstImageLayout, uint32_t regionCount, |
| 4882 | const VkBufferImageCopy *pRegions) { |
Mark Lobodzinski | 1b3a971 | 2019-03-06 15:51:47 -0700 | [diff] [blame] | 4883 | auto cb_node = GetCBNode(commandBuffer); |
Mark Lobodzinski | 6ed7414 | 2019-03-06 11:35:39 -0700 | [diff] [blame] | 4884 | auto src_buffer_state = GetBufferState(srcBuffer); |
Mark Lobodzinski | 8ddc23f | 2019-03-06 11:48:49 -0700 | [diff] [blame] | 4885 | auto dst_image_state = GetImageState(dstImage); |
Mark Lobodzinski | b7eafbe | 2019-01-10 13:40:39 -0700 | [diff] [blame] | 4886 | |
John Zulauf | f660ad6 | 2019-03-23 07:16:05 -0600 | [diff] [blame] | 4887 | // Make sure that all image slices are record referenced layout |
Mark Lobodzinski | b7eafbe | 2019-01-10 13:40:39 -0700 | [diff] [blame] | 4888 | for (uint32_t i = 0; i < regionCount; ++i) { |
John Zulauf | f660ad6 | 2019-03-23 07:16:05 -0600 | [diff] [blame] | 4889 | SetImageInitialLayout(cb_node, *dst_image_state, pRegions[i].imageSubresource, dstImageLayout); |
Tobin Ehlis | e35b66a | 2017-03-15 12:18:31 -0600 | [diff] [blame] | 4890 | } |
Mark Lobodzinski | fae179e | 2019-03-08 16:47:08 -0700 | [diff] [blame] | 4891 | AddCommandBufferBindingBuffer(cb_node, src_buffer_state); |
| 4892 | AddCommandBufferBindingImage(cb_node, dst_image_state); |
Mark Lobodzinski | ab9ea3e | 2017-02-15 12:59:00 -0700 | [diff] [blame] | 4893 | } |
Mike Weiblen | 672b58b | 2017-02-21 14:32:53 -0700 | [diff] [blame] | 4894 | |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 4895 | bool CoreChecks::PreCallValidateGetImageSubresourceLayout(VkDevice device, VkImage image, const VkImageSubresource *pSubresource, |
| 4896 | VkSubresourceLayout *pLayout) { |
Mike Weiblen | 672b58b | 2017-02-21 14:32:53 -0700 | [diff] [blame] | 4897 | bool skip = false; |
| 4898 | const VkImageAspectFlags sub_aspect = pSubresource->aspectMask; |
| 4899 | |
Dave Houlton | 1d960ff | 2018-01-19 12:17:05 -0700 | [diff] [blame] | 4900 | // The aspectMask member of pSubresource must only have a single bit set |
Mike Weiblen | 672b58b | 2017-02-21 14:32:53 -0700 | [diff] [blame] | 4901 | const int num_bits = sizeof(sub_aspect) * CHAR_BIT; |
| 4902 | std::bitset<num_bits> aspect_mask_bits(sub_aspect); |
| 4903 | if (aspect_mask_bits.count() != 1) { |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 4904 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, HandleToUint64(image), |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 4905 | "VUID-vkGetImageSubresourceLayout-aspectMask-00997", |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 4906 | "vkGetImageSubresourceLayout(): VkImageSubresource.aspectMask must have exactly 1 bit set."); |
Mike Weiblen | 672b58b | 2017-02-21 14:32:53 -0700 | [diff] [blame] | 4907 | } |
| 4908 | |
Mark Lobodzinski | 8ddc23f | 2019-03-06 11:48:49 -0700 | [diff] [blame] | 4909 | IMAGE_STATE *image_entry = GetImageState(image); |
Mike Weiblen | 672b58b | 2017-02-21 14:32:53 -0700 | [diff] [blame] | 4910 | if (!image_entry) { |
| 4911 | return skip; |
| 4912 | } |
| 4913 | |
Dave Houlton | 1d960ff | 2018-01-19 12:17:05 -0700 | [diff] [blame] | 4914 | // 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] | 4915 | if (image_entry->createInfo.tiling != VK_IMAGE_TILING_LINEAR) { |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 4916 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, HandleToUint64(image), |
| 4917 | "VUID-vkGetImageSubresourceLayout-image-00996", |
| 4918 | "vkGetImageSubresourceLayout(): Image must have tiling of VK_IMAGE_TILING_LINEAR."); |
Mike Weiblen | 672b58b | 2017-02-21 14:32:53 -0700 | [diff] [blame] | 4919 | } |
| 4920 | |
Dave Houlton | 1d960ff | 2018-01-19 12:17:05 -0700 | [diff] [blame] | 4921 | // 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] | 4922 | if (pSubresource->mipLevel >= image_entry->createInfo.mipLevels) { |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 4923 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, HandleToUint64(image), |
| 4924 | "VUID-vkGetImageSubresourceLayout-mipLevel-01716", |
| 4925 | "vkGetImageSubresourceLayout(): pSubresource.mipLevel (%d) must be less than %d.", pSubresource->mipLevel, |
| 4926 | image_entry->createInfo.mipLevels); |
Mike Weiblen | 672b58b | 2017-02-21 14:32:53 -0700 | [diff] [blame] | 4927 | } |
| 4928 | |
Dave Houlton | 1d960ff | 2018-01-19 12:17:05 -0700 | [diff] [blame] | 4929 | // 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] | 4930 | if (pSubresource->arrayLayer >= image_entry->createInfo.arrayLayers) { |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 4931 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, HandleToUint64(image), |
| 4932 | "VUID-vkGetImageSubresourceLayout-arrayLayer-01717", |
| 4933 | "vkGetImageSubresourceLayout(): pSubresource.arrayLayer (%d) must be less than %d.", |
| 4934 | pSubresource->arrayLayer, image_entry->createInfo.arrayLayers); |
Mike Weiblen | 672b58b | 2017-02-21 14:32:53 -0700 | [diff] [blame] | 4935 | } |
| 4936 | |
Dave Houlton | 1d960ff | 2018-01-19 12:17:05 -0700 | [diff] [blame] | 4937 | // subresource's aspect must be compatible with image's format. |
Mike Weiblen | 672b58b | 2017-02-21 14:32:53 -0700 | [diff] [blame] | 4938 | const VkFormat img_format = image_entry->createInfo.format; |
Dave Houlton | 1d960ff | 2018-01-19 12:17:05 -0700 | [diff] [blame] | 4939 | if (FormatIsMultiplane(img_format)) { |
| 4940 | VkImageAspectFlags allowed_flags = (VK_IMAGE_ASPECT_PLANE_0_BIT_KHR | VK_IMAGE_ASPECT_PLANE_1_BIT_KHR); |
Jeff Bolz | 6d3beaa | 2019-02-09 21:00:05 -0600 | [diff] [blame] | 4941 | const char *vuid = "VUID-vkGetImageSubresourceLayout-format-01581"; // 2-plane version |
Dave Houlton | 1d960ff | 2018-01-19 12:17:05 -0700 | [diff] [blame] | 4942 | if (FormatPlaneCount(img_format) > 2u) { |
| 4943 | allowed_flags |= VK_IMAGE_ASPECT_PLANE_2_BIT_KHR; |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 4944 | vuid = "VUID-vkGetImageSubresourceLayout-format-01582"; // 3-plane version |
Dave Houlton | 1d960ff | 2018-01-19 12:17:05 -0700 | [diff] [blame] | 4945 | } |
| 4946 | if (sub_aspect != (sub_aspect & allowed_flags)) { |
| 4947 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 4948 | HandleToUint64(image), vuid, |
Dave Houlton | 1d960ff | 2018-01-19 12:17:05 -0700 | [diff] [blame] | 4949 | "vkGetImageSubresourceLayout(): For multi-planar images, VkImageSubresource.aspectMask (0x%" PRIx32 |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 4950 | ") must be a single-plane specifier flag.", |
| 4951 | sub_aspect); |
Dave Houlton | 1d960ff | 2018-01-19 12:17:05 -0700 | [diff] [blame] | 4952 | } |
| 4953 | } else if (FormatIsColor(img_format)) { |
Mike Weiblen | 672b58b | 2017-02-21 14:32:53 -0700 | [diff] [blame] | 4954 | if (sub_aspect != VK_IMAGE_ASPECT_COLOR_BIT) { |
Dave Houlton | 852287e | 2018-01-19 15:11:51 -0700 | [diff] [blame] | 4955 | skip |= log_msg( |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 4956 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, HandleToUint64(image), |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 4957 | "VUID-VkImageSubresource-aspectMask-parameter", |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 4958 | "vkGetImageSubresourceLayout(): For color formats, VkImageSubresource.aspectMask must be VK_IMAGE_ASPECT_COLOR."); |
Mike Weiblen | 672b58b | 2017-02-21 14:32:53 -0700 | [diff] [blame] | 4959 | } |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 4960 | } else if (FormatIsDepthOrStencil(img_format)) { |
Mike Weiblen | 672b58b | 2017-02-21 14:32:53 -0700 | [diff] [blame] | 4961 | 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] | 4962 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 4963 | HandleToUint64(image), "VUID-VkImageSubresource-aspectMask-parameter", |
Mike Weiblen | 672b58b | 2017-02-21 14:32:53 -0700 | [diff] [blame] | 4964 | "vkGetImageSubresourceLayout(): For depth/stencil formats, VkImageSubresource.aspectMask must be " |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 4965 | "either VK_IMAGE_ASPECT_DEPTH_BIT or VK_IMAGE_ASPECT_STENCIL_BIT."); |
Mike Weiblen | 672b58b | 2017-02-21 14:32:53 -0700 | [diff] [blame] | 4966 | } |
| 4967 | } |
Dave Houlton | 0d4ad6f | 2018-09-05 14:53:34 -0600 | [diff] [blame] | 4968 | |
Mark Lobodzinski | 60e7903 | 2019-03-07 10:22:31 -0700 | [diff] [blame] | 4969 | if (GetDeviceExtensions()->vk_android_external_memory_android_hardware_buffer) { |
Mark Lobodzinski | e9b9979 | 2019-03-07 16:34:29 -0700 | [diff] [blame] | 4970 | skip |= ValidateGetImageSubresourceLayoutANDROID(image); |
Dave Houlton | 0d4ad6f | 2018-09-05 14:53:34 -0600 | [diff] [blame] | 4971 | } |
| 4972 | |
Mike Weiblen | 672b58b | 2017-02-21 14:32:53 -0700 | [diff] [blame] | 4973 | return skip; |
| 4974 | } |