blob: 1a1f7dc899086e59032f6e46deb172b505f7c8b0 [file] [log] [blame]
Mark Lobodzinskid42e4d22017-01-17 14:14:22 -07001/* Copyright (c) 2015-2017 The Khronos Group Inc.
2 * Copyright (c) 2015-2017 Valve Corporation
3 * Copyright (c) 2015-2017 LunarG, Inc.
4 * Copyright (C) 2015-2017 Google Inc.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 * Author: Mark Lobodzinski <mark@lunarg.com>
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060019 * Author: Dave Houlton <daveh@lunarg.com>
Mark Lobodzinskid42e4d22017-01-17 14:14:22 -070020 */
21
22// Allow use of STL min and max functions in Windows
23#define NOMINMAX
24
Mark Lobodzinski90224de2017-01-26 15:23:11 -070025#include <sstream>
Petr Kraus4d718682017-05-18 03:38:41 +020026#include <string>
Mark Lobodzinski90224de2017-01-26 15:23:11 -070027
28#include "vk_enum_string_helper.h"
29#include "vk_layer_data.h"
30#include "vk_layer_utils.h"
31#include "vk_layer_logging.h"
32
Mark Lobodzinskid42e4d22017-01-17 14:14:22 -070033#include "buffer_validation.h"
Mark Lobodzinski42fe5f72017-01-11 11:36:16 -070034
Tobin Ehlis58c884f2017-02-08 12:15:27 -070035void SetLayout(layer_data *device_data, GLOBAL_CB_NODE *pCB, ImageSubresourcePair imgpair, const VkImageLayout &layout) {
Dave Houltonb3f4b282018-02-22 16:25:16 -070036 auto it = pCB->imageLayoutMap.find(imgpair);
37 if (it != pCB->imageLayoutMap.end()) {
38 it->second.layout = layout;
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -070039 } else {
40 assert(imgpair.hasSubresource);
41 IMAGE_CMD_BUF_LAYOUT_NODE node;
42 if (!FindCmdBufLayout(device_data, pCB, imgpair.image, imgpair.subresource, node)) {
43 node.initialLayout = layout;
44 }
45 SetLayout(device_data, pCB, imgpair, {node.initialLayout, layout});
46 }
47}
48template <class OBJECT, class LAYOUT>
Tobin Ehlis58c884f2017-02-08 12:15:27 -070049void SetLayout(layer_data *device_data, OBJECT *pObject, VkImage image, VkImageSubresource range, const LAYOUT &layout) {
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -070050 ImageSubresourcePair imgpair = {image, true, range};
51 SetLayout(device_data, pObject, imgpair, layout, VK_IMAGE_ASPECT_COLOR_BIT);
52 SetLayout(device_data, pObject, imgpair, layout, VK_IMAGE_ASPECT_DEPTH_BIT);
53 SetLayout(device_data, pObject, imgpair, layout, VK_IMAGE_ASPECT_STENCIL_BIT);
54 SetLayout(device_data, pObject, imgpair, layout, VK_IMAGE_ASPECT_METADATA_BIT);
Dave Houltonb3f4b282018-02-22 16:25:16 -070055 if (GetDeviceExtensions(device_data)->vk_khr_sampler_ycbcr_conversion) {
56 SetLayout(device_data, pObject, imgpair, layout, VK_IMAGE_ASPECT_PLANE_0_BIT_KHR);
57 SetLayout(device_data, pObject, imgpair, layout, VK_IMAGE_ASPECT_PLANE_1_BIT_KHR);
58 SetLayout(device_data, pObject, imgpair, layout, VK_IMAGE_ASPECT_PLANE_2_BIT_KHR);
59 }
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -070060}
61
62template <class OBJECT, class LAYOUT>
Tobin Ehlis58c884f2017-02-08 12:15:27 -070063void SetLayout(layer_data *device_data, OBJECT *pObject, ImageSubresourcePair imgpair, const LAYOUT &layout,
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -070064 VkImageAspectFlags aspectMask) {
65 if (imgpair.subresource.aspectMask & aspectMask) {
66 imgpair.subresource.aspectMask = aspectMask;
67 SetLayout(device_data, pObject, imgpair, layout);
68 }
69}
70
Tony Barbourdf013b92017-01-25 12:53:48 -070071// Set the layout in supplied map
Tony Barboure0c5cc92017-02-08 13:53:39 -070072void SetLayout(std::unordered_map<ImageSubresourcePair, IMAGE_LAYOUT_NODE> &imageLayoutMap, ImageSubresourcePair imgpair,
73 VkImageLayout layout) {
Dave Houltonb3f4b282018-02-22 16:25:16 -070074 auto it = imageLayoutMap.find(imgpair);
75 if (it != imageLayoutMap.end()) {
76 it->second.layout = layout; // Update
77 } else {
78 imageLayoutMap[imgpair].layout = layout; // Insert
79 }
Tony Barbourdf013b92017-01-25 12:53:48 -070080}
81
Tobin Ehlisc8266452017-04-07 12:20:30 -060082bool FindLayoutVerifyNode(layer_data const *device_data, GLOBAL_CB_NODE const *pCB, ImageSubresourcePair imgpair,
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -070083 IMAGE_CMD_BUF_LAYOUT_NODE &node, const VkImageAspectFlags aspectMask) {
84 const debug_report_data *report_data = core_validation::GetReportData(device_data);
85
86 if (!(imgpair.subresource.aspectMask & aspectMask)) {
87 return false;
88 }
89 VkImageAspectFlags oldAspectMask = imgpair.subresource.aspectMask;
90 imgpair.subresource.aspectMask = aspectMask;
91 auto imgsubIt = pCB->imageLayoutMap.find(imgpair);
92 if (imgsubIt == pCB->imageLayoutMap.end()) {
93 return false;
94 }
95 if (node.layout != VK_IMAGE_LAYOUT_MAX_ENUM && node.layout != imgsubIt->second.layout) {
Petr Krausbc7f5442017-05-14 23:43:38 +020096 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, HandleToUint64(imgpair.image),
Mark Lobodzinski88529492018-04-01 10:38:15 -060097 DRAWSTATE_INVALID_LAYOUT,
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -070098 "Cannot query for VkImage 0x%" PRIx64 " layout when combined aspect mask %d has multiple layout types: %s and %s",
Petr Krausbc7f5442017-05-14 23:43:38 +020099 HandleToUint64(imgpair.image), oldAspectMask, string_VkImageLayout(node.layout),
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700100 string_VkImageLayout(imgsubIt->second.layout));
101 }
102 if (node.initialLayout != VK_IMAGE_LAYOUT_MAX_ENUM && node.initialLayout != imgsubIt->second.initialLayout) {
Petr Krausbc7f5442017-05-14 23:43:38 +0200103 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, HandleToUint64(imgpair.image),
Mark Lobodzinski88529492018-04-01 10:38:15 -0600104 DRAWSTATE_INVALID_LAYOUT,
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700105 "Cannot query for VkImage 0x%" PRIx64
106 " layout when combined aspect mask %d has multiple initial layout types: %s and %s",
Petr Krausbc7f5442017-05-14 23:43:38 +0200107 HandleToUint64(imgpair.image), oldAspectMask, string_VkImageLayout(node.initialLayout),
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700108 string_VkImageLayout(imgsubIt->second.initialLayout));
109 }
110 node = imgsubIt->second;
111 return true;
112}
113
Tobin Ehlisc8266452017-04-07 12:20:30 -0600114bool FindLayoutVerifyLayout(layer_data const *device_data, ImageSubresourcePair imgpair, VkImageLayout &layout,
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700115 const VkImageAspectFlags aspectMask) {
116 if (!(imgpair.subresource.aspectMask & aspectMask)) {
117 return false;
118 }
119 const debug_report_data *report_data = core_validation::GetReportData(device_data);
120 VkImageAspectFlags oldAspectMask = imgpair.subresource.aspectMask;
121 imgpair.subresource.aspectMask = aspectMask;
122 auto imgsubIt = (*core_validation::GetImageLayoutMap(device_data)).find(imgpair);
123 if (imgsubIt == (*core_validation::GetImageLayoutMap(device_data)).end()) {
124 return false;
125 }
126 if (layout != VK_IMAGE_LAYOUT_MAX_ENUM && layout != imgsubIt->second.layout) {
Petr Krausbc7f5442017-05-14 23:43:38 +0200127 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, HandleToUint64(imgpair.image),
Mark Lobodzinski88529492018-04-01 10:38:15 -0600128 DRAWSTATE_INVALID_LAYOUT,
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700129 "Cannot query for VkImage 0x%" PRIx64 " layout when combined aspect mask %d has multiple layout types: %s and %s",
Petr Krausbc7f5442017-05-14 23:43:38 +0200130 HandleToUint64(imgpair.image), oldAspectMask, string_VkImageLayout(layout),
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700131 string_VkImageLayout(imgsubIt->second.layout));
132 }
133 layout = imgsubIt->second.layout;
134 return true;
135}
136
137// Find layout(s) on the command buffer level
Tobin Ehlisc8266452017-04-07 12:20:30 -0600138bool FindCmdBufLayout(layer_data const *device_data, GLOBAL_CB_NODE const *pCB, VkImage image, VkImageSubresource range,
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700139 IMAGE_CMD_BUF_LAYOUT_NODE &node) {
140 ImageSubresourcePair imgpair = {image, true, range};
141 node = IMAGE_CMD_BUF_LAYOUT_NODE(VK_IMAGE_LAYOUT_MAX_ENUM, VK_IMAGE_LAYOUT_MAX_ENUM);
142 FindLayoutVerifyNode(device_data, pCB, imgpair, node, VK_IMAGE_ASPECT_COLOR_BIT);
143 FindLayoutVerifyNode(device_data, pCB, imgpair, node, VK_IMAGE_ASPECT_DEPTH_BIT);
144 FindLayoutVerifyNode(device_data, pCB, imgpair, node, VK_IMAGE_ASPECT_STENCIL_BIT);
145 FindLayoutVerifyNode(device_data, pCB, imgpair, node, VK_IMAGE_ASPECT_METADATA_BIT);
Dave Houltonb3f4b282018-02-22 16:25:16 -0700146 if (GetDeviceExtensions(device_data)->vk_khr_sampler_ycbcr_conversion) {
147 FindLayoutVerifyNode(device_data, pCB, imgpair, node, VK_IMAGE_ASPECT_PLANE_0_BIT_KHR);
148 FindLayoutVerifyNode(device_data, pCB, imgpair, node, VK_IMAGE_ASPECT_PLANE_1_BIT_KHR);
149 FindLayoutVerifyNode(device_data, pCB, imgpair, node, VK_IMAGE_ASPECT_PLANE_2_BIT_KHR);
150 }
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700151 if (node.layout == VK_IMAGE_LAYOUT_MAX_ENUM) {
152 imgpair = {image, false, VkImageSubresource()};
153 auto imgsubIt = pCB->imageLayoutMap.find(imgpair);
154 if (imgsubIt == pCB->imageLayoutMap.end()) return false;
155 // TODO: This is ostensibly a find function but it changes state here
156 node = imgsubIt->second;
157 }
158 return true;
159}
160
161// Find layout(s) on the global level
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700162bool FindGlobalLayout(layer_data *device_data, ImageSubresourcePair imgpair, VkImageLayout &layout) {
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700163 layout = VK_IMAGE_LAYOUT_MAX_ENUM;
164 FindLayoutVerifyLayout(device_data, imgpair, layout, VK_IMAGE_ASPECT_COLOR_BIT);
165 FindLayoutVerifyLayout(device_data, imgpair, layout, VK_IMAGE_ASPECT_DEPTH_BIT);
166 FindLayoutVerifyLayout(device_data, imgpair, layout, VK_IMAGE_ASPECT_STENCIL_BIT);
167 FindLayoutVerifyLayout(device_data, imgpair, layout, VK_IMAGE_ASPECT_METADATA_BIT);
Dave Houltonb3f4b282018-02-22 16:25:16 -0700168 if (GetDeviceExtensions(device_data)->vk_khr_sampler_ycbcr_conversion) {
169 FindLayoutVerifyLayout(device_data, imgpair, layout, VK_IMAGE_ASPECT_PLANE_0_BIT_KHR);
170 FindLayoutVerifyLayout(device_data, imgpair, layout, VK_IMAGE_ASPECT_PLANE_1_BIT_KHR);
171 FindLayoutVerifyLayout(device_data, imgpair, layout, VK_IMAGE_ASPECT_PLANE_2_BIT_KHR);
172 }
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700173 if (layout == VK_IMAGE_LAYOUT_MAX_ENUM) {
174 imgpair = {imgpair.image, false, VkImageSubresource()};
175 auto imgsubIt = (*core_validation::GetImageLayoutMap(device_data)).find(imgpair);
176 if (imgsubIt == (*core_validation::GetImageLayoutMap(device_data)).end()) return false;
177 layout = imgsubIt->second.layout;
178 }
179 return true;
180}
181
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700182bool FindLayouts(layer_data *device_data, VkImage image, std::vector<VkImageLayout> &layouts) {
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700183 auto sub_data = (*core_validation::GetImageSubresourceMap(device_data)).find(image);
184 if (sub_data == (*core_validation::GetImageSubresourceMap(device_data)).end()) return false;
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -0700185 auto image_state = GetImageState(device_data, image);
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700186 if (!image_state) return false;
187 bool ignoreGlobal = false;
188 // TODO: Make this robust for >1 aspect mask. Now it will just say ignore potential errors in this case.
189 if (sub_data->second.size() >= (image_state->createInfo.arrayLayers * image_state->createInfo.mipLevels + 1)) {
190 ignoreGlobal = true;
191 }
192 for (auto imgsubpair : sub_data->second) {
193 if (ignoreGlobal && !imgsubpair.hasSubresource) continue;
194 auto img_data = (*core_validation::GetImageLayoutMap(device_data)).find(imgsubpair);
195 if (img_data != (*core_validation::GetImageLayoutMap(device_data)).end()) {
196 layouts.push_back(img_data->second.layout);
197 }
198 }
199 return true;
200}
Tony Barboure0c5cc92017-02-08 13:53:39 -0700201bool FindLayout(const std::unordered_map<ImageSubresourcePair, IMAGE_LAYOUT_NODE> &imageLayoutMap, ImageSubresourcePair imgpair,
202 VkImageLayout &layout, const VkImageAspectFlags aspectMask) {
Tony Barbourdf013b92017-01-25 12:53:48 -0700203 if (!(imgpair.subresource.aspectMask & aspectMask)) {
204 return false;
205 }
206 imgpair.subresource.aspectMask = aspectMask;
207 auto imgsubIt = imageLayoutMap.find(imgpair);
208 if (imgsubIt == imageLayoutMap.end()) {
209 return false;
210 }
211 layout = imgsubIt->second.layout;
212 return true;
Tony Barboure0c5cc92017-02-08 13:53:39 -0700213}
Tony Barbourdf013b92017-01-25 12:53:48 -0700214
215// find layout in supplied map
Dave Houltonb3f4b282018-02-22 16:25:16 -0700216bool FindLayout(layer_data *device_data, const std::unordered_map<ImageSubresourcePair, IMAGE_LAYOUT_NODE> &imageLayoutMap,
217 ImageSubresourcePair imgpair, VkImageLayout &layout) {
Tony Barbourdf013b92017-01-25 12:53:48 -0700218 layout = VK_IMAGE_LAYOUT_MAX_ENUM;
219 FindLayout(imageLayoutMap, imgpair, layout, VK_IMAGE_ASPECT_COLOR_BIT);
220 FindLayout(imageLayoutMap, imgpair, layout, VK_IMAGE_ASPECT_DEPTH_BIT);
221 FindLayout(imageLayoutMap, imgpair, layout, VK_IMAGE_ASPECT_STENCIL_BIT);
222 FindLayout(imageLayoutMap, imgpair, layout, VK_IMAGE_ASPECT_METADATA_BIT);
Dave Houltonb3f4b282018-02-22 16:25:16 -0700223 if (GetDeviceExtensions(device_data)->vk_khr_sampler_ycbcr_conversion) {
224 FindLayout(imageLayoutMap, imgpair, layout, VK_IMAGE_ASPECT_PLANE_0_BIT_KHR);
225 FindLayout(imageLayoutMap, imgpair, layout, VK_IMAGE_ASPECT_PLANE_1_BIT_KHR);
226 FindLayout(imageLayoutMap, imgpair, layout, VK_IMAGE_ASPECT_PLANE_2_BIT_KHR);
227 }
228 // Image+subresource not found, look for image handle w/o subresource
Tony Barbourdf013b92017-01-25 12:53:48 -0700229 if (layout == VK_IMAGE_LAYOUT_MAX_ENUM) {
230 imgpair = {imgpair.image, false, VkImageSubresource()};
231 auto imgsubIt = imageLayoutMap.find(imgpair);
232 if (imgsubIt == imageLayoutMap.end()) return false;
233 layout = imgsubIt->second.layout;
234 }
235 return true;
236}
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700237
238// Set the layout on the global level
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700239void SetGlobalLayout(layer_data *device_data, ImageSubresourcePair imgpair, const VkImageLayout &layout) {
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700240 VkImage &image = imgpair.image;
Dave Houltonb3f4b282018-02-22 16:25:16 -0700241 auto &lmap = (*core_validation::GetImageLayoutMap(device_data));
242 auto data = lmap.find(imgpair);
243 if (data != lmap.end()) {
244 data->second.layout = layout; // Update
245 } else {
246 lmap[imgpair].layout = layout; // Insert
247 }
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700248 auto &image_subresources = (*core_validation::GetImageSubresourceMap(device_data))[image];
249 auto subresource = std::find(image_subresources.begin(), image_subresources.end(), imgpair);
250 if (subresource == image_subresources.end()) {
251 image_subresources.push_back(imgpair);
252 }
253}
254
255// Set the layout on the cmdbuf level
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700256void SetLayout(layer_data *device_data, GLOBAL_CB_NODE *pCB, ImageSubresourcePair imgpair, const IMAGE_CMD_BUF_LAYOUT_NODE &node) {
Dave Houltonb3f4b282018-02-22 16:25:16 -0700257 auto it = pCB->imageLayoutMap.find(imgpair);
258 if (it != pCB->imageLayoutMap.end()) {
259 it->second = node; // Update
260 } else {
261 pCB->imageLayoutMap[imgpair] = node; // Insert
262 }
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700263}
Tobin Ehlise35b66a2017-03-15 12:18:31 -0600264// Set image layout for given VkImageSubresourceRange struct
265void SetImageLayout(layer_data *device_data, GLOBAL_CB_NODE *cb_node, const IMAGE_STATE *image_state,
266 VkImageSubresourceRange image_subresource_range, const VkImageLayout &layout) {
267 assert(image_state);
John Zulauf48a6a702017-12-22 17:14:54 -0700268 cb_node->image_layout_change_count++; // Change the version of this data to force revalidation
Tobin Ehlise35b66a2017-03-15 12:18:31 -0600269 for (uint32_t level_index = 0; level_index < image_subresource_range.levelCount; ++level_index) {
270 uint32_t level = image_subresource_range.baseMipLevel + level_index;
271 for (uint32_t layer_index = 0; layer_index < image_subresource_range.layerCount; layer_index++) {
272 uint32_t layer = image_subresource_range.baseArrayLayer + layer_index;
273 VkImageSubresource sub = {image_subresource_range.aspectMask, level, layer};
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700274 // TODO: If ImageView was created with depth or stencil, transition both layouts as the aspectMask is ignored and both
275 // are used. Verify that the extra implicit layout is OK for descriptor set layout validation
Tobin Ehlise35b66a2017-03-15 12:18:31 -0600276 if (image_subresource_range.aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) {
Dave Houlton1d2022c2017-03-29 11:43:58 -0600277 if (FormatIsDepthAndStencil(image_state->createInfo.format)) {
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700278 sub.aspectMask |= (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT);
279 }
280 }
Tobin Ehlise35b66a2017-03-15 12:18:31 -0600281 SetLayout(device_data, cb_node, image_state->image, sub, layout);
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700282 }
283 }
284}
Tobin Ehlise35b66a2017-03-15 12:18:31 -0600285// Set image layout for given VkImageSubresourceLayers struct
286void SetImageLayout(layer_data *device_data, GLOBAL_CB_NODE *cb_node, const IMAGE_STATE *image_state,
287 VkImageSubresourceLayers image_subresource_layers, const VkImageLayout &layout) {
288 // Transfer VkImageSubresourceLayers into VkImageSubresourceRange struct
289 VkImageSubresourceRange image_subresource_range;
290 image_subresource_range.aspectMask = image_subresource_layers.aspectMask;
291 image_subresource_range.baseArrayLayer = image_subresource_layers.baseArrayLayer;
292 image_subresource_range.layerCount = image_subresource_layers.layerCount;
293 image_subresource_range.baseMipLevel = image_subresource_layers.mipLevel;
294 image_subresource_range.levelCount = 1;
295 SetImageLayout(device_data, cb_node, image_state, image_subresource_range, layout);
296}
297// Set image layout for all slices of an image view
298void SetImageViewLayout(layer_data *device_data, GLOBAL_CB_NODE *cb_node, VkImageView imageView, const VkImageLayout &layout) {
299 auto view_state = GetImageViewState(device_data, imageView);
300 assert(view_state);
301
302 SetImageLayout(device_data, cb_node, GetImageState(device_data, view_state->create_info.image),
303 view_state->create_info.subresourceRange, layout);
304}
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700305
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700306bool VerifyFramebufferAndRenderPassLayouts(layer_data *device_data, GLOBAL_CB_NODE *pCB,
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700307 const VkRenderPassBeginInfo *pRenderPassBegin,
308 const FRAMEBUFFER_STATE *framebuffer_state) {
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600309 bool skip = false;
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -0700310 auto const pRenderPassInfo = GetRenderPassState(device_data, pRenderPassBegin->renderPass)->createInfo.ptr();
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700311 auto const &framebufferInfo = framebuffer_state->createInfo;
312 const auto report_data = core_validation::GetReportData(device_data);
313 if (pRenderPassInfo->attachmentCount != framebufferInfo.attachmentCount) {
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600314 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -0600315 HandleToUint64(pCB->commandBuffer), DRAWSTATE_INVALID_RENDERPASS,
Dave Houltona9df0ce2018-02-07 10:51:23 -0700316 "You cannot start a render pass using a framebuffer with a different number of attachments.");
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700317 }
318 for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) {
319 const VkImageView &image_view = framebufferInfo.pAttachments[i];
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -0700320 auto view_state = GetImageViewState(device_data, image_view);
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700321 assert(view_state);
322 const VkImage &image = view_state->create_info.image;
323 const VkImageSubresourceRange &subRange = view_state->create_info.subresourceRange;
Tobin Ehlis0d4274b2017-02-17 15:17:04 -0700324 auto initial_layout = pRenderPassInfo->pAttachments[i].initialLayout;
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700325 // TODO: Do not iterate over every possibility - consolidate where possible
326 for (uint32_t j = 0; j < subRange.levelCount; j++) {
327 uint32_t level = subRange.baseMipLevel + j;
328 for (uint32_t k = 0; k < subRange.layerCount; k++) {
329 uint32_t layer = subRange.baseArrayLayer + k;
330 VkImageSubresource sub = {subRange.aspectMask, level, layer};
331 IMAGE_CMD_BUF_LAYOUT_NODE node;
332 if (!FindCmdBufLayout(device_data, pCB, image, sub, node)) {
Tobin Ehlis0d4274b2017-02-17 15:17:04 -0700333 // Missing layouts will be added during state update
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700334 continue;
335 }
Tobin Ehlis0d4274b2017-02-17 15:17:04 -0700336 if (initial_layout != VK_IMAGE_LAYOUT_UNDEFINED && initial_layout != node.layout) {
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600337 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
Mark Lobodzinski88529492018-04-01 10:38:15 -0600338 DRAWSTATE_INVALID_RENDERPASS,
Dave Houltona9df0ce2018-02-07 10:51:23 -0700339 "You cannot start a render pass using attachment %u where the render pass initial layout is %s "
340 "and the previous known layout of the attachment is %s. The layouts must match, or the render "
341 "pass initial layout for the attachment must be VK_IMAGE_LAYOUT_UNDEFINED",
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600342 i, string_VkImageLayout(initial_layout), string_VkImageLayout(node.layout));
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700343 }
344 }
345 }
346 }
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600347 return skip;
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700348}
349
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700350void TransitionAttachmentRefLayout(layer_data *device_data, GLOBAL_CB_NODE *pCB, FRAMEBUFFER_STATE *pFramebuffer,
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700351 VkAttachmentReference ref) {
352 if (ref.attachment != VK_ATTACHMENT_UNUSED) {
353 auto image_view = pFramebuffer->createInfo.pAttachments[ref.attachment];
354 SetImageViewLayout(device_data, pCB, image_view, ref.layout);
355 }
356}
357
Tobin Ehlis0d4274b2017-02-17 15:17:04 -0700358void TransitionSubpassLayouts(layer_data *device_data, GLOBAL_CB_NODE *pCB, const RENDER_PASS_STATE *render_pass_state,
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700359 const int subpass_index, FRAMEBUFFER_STATE *framebuffer_state) {
Tobin Ehlis0d4274b2017-02-17 15:17:04 -0700360 assert(render_pass_state);
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700361
362 if (framebuffer_state) {
Tobin Ehlis0d4274b2017-02-17 15:17:04 -0700363 auto const &subpass = render_pass_state->createInfo.pSubpasses[subpass_index];
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700364 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
365 TransitionAttachmentRefLayout(device_data, pCB, framebuffer_state, subpass.pInputAttachments[j]);
366 }
367 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
368 TransitionAttachmentRefLayout(device_data, pCB, framebuffer_state, subpass.pColorAttachments[j]);
369 }
370 if (subpass.pDepthStencilAttachment) {
371 TransitionAttachmentRefLayout(device_data, pCB, framebuffer_state, *subpass.pDepthStencilAttachment);
372 }
373 }
374}
375
Tobin Ehlis9c0df962017-07-17 10:14:27 -0600376bool ValidateImageAspectLayout(layer_data *device_data, GLOBAL_CB_NODE const *pCB, const VkImageMemoryBarrier *mem_barrier,
Mark Lobodzinski6b6c50a2017-02-27 12:56:14 -0700377 uint32_t level, uint32_t layer, VkImageAspectFlags aspect) {
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700378 if (!(mem_barrier->subresourceRange.aspectMask & aspect)) {
379 return false;
380 }
381 VkImageSubresource sub = {aspect, level, layer};
382 IMAGE_CMD_BUF_LAYOUT_NODE node;
383 if (!FindCmdBufLayout(device_data, pCB, mem_barrier->image, sub, node)) {
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700384 return false;
385 }
386 bool skip = false;
387 if (mem_barrier->oldLayout == VK_IMAGE_LAYOUT_UNDEFINED) {
388 // TODO: Set memory invalid which is in mem_tracker currently
389 } else if (node.layout != mem_barrier->oldLayout) {
Petr Kraus13c98a62017-12-09 00:22:39 +0100390 skip |= log_msg(core_validation::GetReportData(device_data), VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskib1fd9d12018-03-30 14:26:00 -0600391 VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, HandleToUint64(pCB->commandBuffer),
Mark Lobodzinski88529492018-04-01 10:38:15 -0600392 DRAWSTATE_INVALID_IMAGE_LAYOUT,
Petr Kraus13c98a62017-12-09 00:22:39 +0100393 "For image 0x%" PRIx64 " you cannot transition the layout of aspect %d from %s when current layout is %s.",
394 HandleToUint64(mem_barrier->image), aspect, string_VkImageLayout(mem_barrier->oldLayout),
395 string_VkImageLayout(node.layout));
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700396 }
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700397 return skip;
398}
399
Tobin Ehlis0d4274b2017-02-17 15:17:04 -0700400// Transition the layout state for renderpass attachments based on the BeginRenderPass() call. This includes:
401// 1. Transition into initialLayout state
402// 2. Transition from initialLayout to layout used in subpass 0
403void TransitionBeginRenderPassLayouts(layer_data *device_data, GLOBAL_CB_NODE *cb_state, const RENDER_PASS_STATE *render_pass_state,
404 FRAMEBUFFER_STATE *framebuffer_state) {
405 // First transition into initialLayout
406 auto const rpci = render_pass_state->createInfo.ptr();
407 for (uint32_t i = 0; i < rpci->attachmentCount; ++i) {
408 VkImageView image_view = framebuffer_state->createInfo.pAttachments[i];
409 SetImageViewLayout(device_data, cb_state, image_view, rpci->pAttachments[i].initialLayout);
410 }
411 // Now transition for first subpass (index 0)
412 TransitionSubpassLayouts(device_data, cb_state, render_pass_state, 0, framebuffer_state);
413}
414
Mark Lobodzinski6b6c50a2017-02-27 12:56:14 -0700415void TransitionImageAspectLayout(layer_data *device_data, GLOBAL_CB_NODE *pCB, const VkImageMemoryBarrier *mem_barrier,
416 uint32_t level, uint32_t layer, VkImageAspectFlags aspect) {
417 if (!(mem_barrier->subresourceRange.aspectMask & aspect)) {
418 return;
419 }
420 VkImageSubresource sub = {aspect, level, layer};
421 IMAGE_CMD_BUF_LAYOUT_NODE node;
422 if (!FindCmdBufLayout(device_data, pCB, mem_barrier->image, sub, node)) {
John Zulauf48a6a702017-12-22 17:14:54 -0700423 pCB->image_layout_change_count++; // Change the version of this data to force revalidation
Mark Lobodzinski6b6c50a2017-02-27 12:56:14 -0700424 SetLayout(device_data, pCB, mem_barrier->image, sub,
425 IMAGE_CMD_BUF_LAYOUT_NODE(mem_barrier->oldLayout, mem_barrier->newLayout));
426 return;
427 }
428 if (mem_barrier->oldLayout == VK_IMAGE_LAYOUT_UNDEFINED) {
429 // TODO: Set memory invalid
430 }
431 SetLayout(device_data, pCB, mem_barrier->image, sub, mem_barrier->newLayout);
432}
433
Dave Houlton10b39482017-03-16 13:18:15 -0600434bool VerifyAspectsPresent(VkImageAspectFlags aspect_mask, VkFormat format) {
Dave Houlton4eaaf3a2017-03-14 11:31:20 -0600435 if ((aspect_mask & VK_IMAGE_ASPECT_COLOR_BIT) != 0) {
Dave Houlton1d2022c2017-03-29 11:43:58 -0600436 if (!FormatIsColor(format)) return false;
Dave Houlton4eaaf3a2017-03-14 11:31:20 -0600437 }
438 if ((aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) != 0) {
Dave Houlton1d2022c2017-03-29 11:43:58 -0600439 if (!FormatHasDepth(format)) return false;
Dave Houlton4eaaf3a2017-03-14 11:31:20 -0600440 }
441 if ((aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) != 0) {
Dave Houlton1d2022c2017-03-29 11:43:58 -0600442 if (!FormatHasStencil(format)) return false;
Dave Houlton4eaaf3a2017-03-14 11:31:20 -0600443 }
Dave Houltonb3f4b282018-02-22 16:25:16 -0700444 if (0 !=
445 (aspect_mask & (VK_IMAGE_ASPECT_PLANE_0_BIT_KHR | VK_IMAGE_ASPECT_PLANE_1_BIT_KHR | VK_IMAGE_ASPECT_PLANE_2_BIT_KHR))) {
446 if (FormatPlaneCount(format) == 1) return false;
447 }
Dave Houlton4eaaf3a2017-03-14 11:31:20 -0600448 return true;
449}
450
Mike Weiblen62d08a32017-03-07 22:18:27 -0700451// Verify an ImageMemoryBarrier's old/new ImageLayouts are compatible with the Image's ImageUsageFlags.
452bool ValidateBarrierLayoutToImageUsage(layer_data *device_data, const VkImageMemoryBarrier *img_barrier, bool new_not_old,
453 VkImageUsageFlags usage_flags, const char *func_name) {
454 const auto report_data = core_validation::GetReportData(device_data);
455 bool skip = false;
456 const VkImageLayout layout = (new_not_old) ? img_barrier->newLayout : img_barrier->oldLayout;
457 UNIQUE_VALIDATION_ERROR_CODE msg_code = VALIDATION_ERROR_UNDEFINED; // sentinel value meaning "no error"
458
459 switch (layout) {
460 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL:
461 if ((usage_flags & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) == 0) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -0600462 msg_code = VALIDATION_ERROR_0a000970;
Mike Weiblen62d08a32017-03-07 22:18:27 -0700463 }
464 break;
465 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
466 if ((usage_flags & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) == 0) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -0600467 msg_code = VALIDATION_ERROR_0a000972;
Mike Weiblen62d08a32017-03-07 22:18:27 -0700468 }
469 break;
470 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL:
471 if ((usage_flags & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) == 0) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -0600472 msg_code = VALIDATION_ERROR_0a000974;
Mike Weiblen62d08a32017-03-07 22:18:27 -0700473 }
474 break;
475 case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL:
476 if ((usage_flags & (VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT)) == 0) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -0600477 msg_code = VALIDATION_ERROR_0a000976;
Mike Weiblen62d08a32017-03-07 22:18:27 -0700478 }
479 break;
480 case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL:
481 if ((usage_flags & VK_IMAGE_USAGE_TRANSFER_SRC_BIT) == 0) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -0600482 msg_code = VALIDATION_ERROR_0a000978;
Mike Weiblen62d08a32017-03-07 22:18:27 -0700483 }
484 break;
485 case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL:
486 if ((usage_flags & VK_IMAGE_USAGE_TRANSFER_DST_BIT) == 0) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -0600487 msg_code = VALIDATION_ERROR_0a00097a;
Mike Weiblen62d08a32017-03-07 22:18:27 -0700488 }
489 break;
490 default:
491 // Other VkImageLayout values do not have VUs defined in this context.
492 break;
493 }
494
495 if (msg_code != VALIDATION_ERROR_UNDEFINED) {
Mark Lobodzinski487a0d12018-03-30 10:09:03 -0600496 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -0600497 HandleToUint64(img_barrier->image), msg_code,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -0600498 "%s: Image barrier 0x%p %sLayout=%s is not compatible with image 0x%" PRIx64 " usage flags 0x%" PRIx32 ".",
499 func_name, static_cast<const void *>(img_barrier), ((new_not_old) ? "new" : "old"),
500 string_VkImageLayout(layout), HandleToUint64(img_barrier->image), usage_flags);
Mike Weiblen62d08a32017-03-07 22:18:27 -0700501 }
502 return skip;
503}
504
505// Verify image barriers are compatible with the images they reference.
Tobin Ehlis9c0df962017-07-17 10:14:27 -0600506bool ValidateBarriersToImages(layer_data *device_data, GLOBAL_CB_NODE const *cb_state, uint32_t imageMemoryBarrierCount,
Mike Weiblen62d08a32017-03-07 22:18:27 -0700507 const VkImageMemoryBarrier *pImageMemoryBarriers, const char *func_name) {
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700508 bool skip = false;
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700509
Mike Weiblen62d08a32017-03-07 22:18:27 -0700510 for (uint32_t i = 0; i < imageMemoryBarrierCount; ++i) {
511 auto img_barrier = &pImageMemoryBarriers[i];
512 if (!img_barrier) continue;
513
Tobin Ehlisbb03e5f2017-05-11 08:52:51 -0600514 auto image_state = GetImageState(device_data, img_barrier->image);
515 if (image_state) {
516 VkImageUsageFlags usage_flags = image_state->createInfo.usage;
517 skip |= ValidateBarrierLayoutToImageUsage(device_data, img_barrier, false, usage_flags, func_name);
518 skip |= ValidateBarrierLayoutToImageUsage(device_data, img_barrier, true, usage_flags, func_name);
519
520 // Make sure layout is able to be transitioned, currently only presented shared presentable images are locked
521 if (image_state->layout_locked) {
522 // TODO: Add unique id for error when available
Dave Houlton33c2d252017-06-09 17:08:32 -0600523 skip |= log_msg(
524 core_validation::GetReportData(device_data), VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -0600525 VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, 0,
Petr Kraus13c98a62017-12-09 00:22:39 +0100526 "Attempting to transition shared presentable image 0x%" PRIx64
Tobin Ehlisbb03e5f2017-05-11 08:52:51 -0600527 " from layout %s to layout %s, but image has already been presented and cannot have its layout transitioned.",
Petr Kraus13c98a62017-12-09 00:22:39 +0100528 HandleToUint64(img_barrier->image), string_VkImageLayout(img_barrier->oldLayout),
Tobin Ehlisbb03e5f2017-05-11 08:52:51 -0600529 string_VkImageLayout(img_barrier->newLayout));
530 }
531 }
532
Mark Lobodzinski903e5ff2017-03-23 09:43:35 -0600533 VkImageCreateInfo *image_create_info = &(GetImageState(device_data, img_barrier->image)->createInfo);
Tobin Ehlis7ee9cbd2017-04-26 16:51:48 -0600534 // For a Depth/Stencil image both aspects MUST be set
535 if (FormatIsDepthAndStencil(image_create_info->format)) {
536 auto const aspect_mask = img_barrier->subresourceRange.aspectMask;
537 auto const ds_mask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
538 if ((aspect_mask & ds_mask) != (ds_mask)) {
Mark Lobodzinski88529492018-04-01 10:38:15 -0600539 skip |=
540 log_msg(core_validation::GetReportData(device_data), VK_DEBUG_REPORT_ERROR_BIT_EXT,
541 VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, HandleToUint64(img_barrier->image), VALIDATION_ERROR_0a00096e,
542 "%s: Image barrier 0x%p references image 0x%" PRIx64
543 " of format %s that must have the depth and stencil aspects set, but its aspectMask is 0x%" PRIx32 ".",
544 func_name, static_cast<const void *>(img_barrier), HandleToUint64(img_barrier->image),
545 string_VkFormat(image_create_info->format), aspect_mask);
Tobin Ehlis7ee9cbd2017-04-26 16:51:48 -0600546 }
547 }
Mark Lobodzinski903e5ff2017-03-23 09:43:35 -0600548 uint32_t level_count = ResolveRemainingLevels(&img_barrier->subresourceRange, image_create_info->mipLevels);
549 uint32_t layer_count = ResolveRemainingLayers(&img_barrier->subresourceRange, image_create_info->arrayLayers);
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700550
Mike Weiblen62d08a32017-03-07 22:18:27 -0700551 for (uint32_t j = 0; j < level_count; j++) {
552 uint32_t level = img_barrier->subresourceRange.baseMipLevel + j;
553 for (uint32_t k = 0; k < layer_count; k++) {
554 uint32_t layer = img_barrier->subresourceRange.baseArrayLayer + k;
Tobin Ehlis9c0df962017-07-17 10:14:27 -0600555 skip |= ValidateImageAspectLayout(device_data, cb_state, img_barrier, level, layer, VK_IMAGE_ASPECT_COLOR_BIT);
556 skip |= ValidateImageAspectLayout(device_data, cb_state, img_barrier, level, layer, VK_IMAGE_ASPECT_DEPTH_BIT);
557 skip |= ValidateImageAspectLayout(device_data, cb_state, img_barrier, level, layer, VK_IMAGE_ASPECT_STENCIL_BIT);
558 skip |= ValidateImageAspectLayout(device_data, cb_state, img_barrier, level, layer, VK_IMAGE_ASPECT_METADATA_BIT);
Dave Houltonb3f4b282018-02-22 16:25:16 -0700559 if (GetDeviceExtensions(device_data)->vk_khr_sampler_ycbcr_conversion) {
560 skip |= ValidateImageAspectLayout(device_data, cb_state, img_barrier, level, layer,
561 VK_IMAGE_ASPECT_PLANE_0_BIT_KHR);
562 skip |= ValidateImageAspectLayout(device_data, cb_state, img_barrier, level, layer,
563 VK_IMAGE_ASPECT_PLANE_1_BIT_KHR);
564 skip |= ValidateImageAspectLayout(device_data, cb_state, img_barrier, level, layer,
565 VK_IMAGE_ASPECT_PLANE_2_BIT_KHR);
566 }
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700567 }
568 }
569 }
570 return skip;
571}
572
Chris Forbes4de4b132017-08-21 11:27:08 -0700573static bool IsReleaseOp(layer_data *device_data, GLOBAL_CB_NODE *cb_state, VkImageMemoryBarrier const *barrier) {
John Zulauf1b33d5a2018-03-24 19:52:19 -0600574 if (!IsTransferOp(barrier)) return false;
Chris Forbes4de4b132017-08-21 11:27:08 -0700575
576 auto pool = GetCommandPoolNode(device_data, cb_state->createInfo.commandPool);
John Zulauf1b33d5a2018-03-24 19:52:19 -0600577 return pool && IsReleaseOp<VkImageMemoryBarrier, true>(pool, barrier);
Chris Forbes4de4b132017-08-21 11:27:08 -0700578}
579
Chris Forbes399a6782017-08-18 15:00:48 -0700580void TransitionImageLayouts(layer_data *device_data, GLOBAL_CB_NODE *cb_state, uint32_t memBarrierCount,
Mark Lobodzinski6b6c50a2017-02-27 12:56:14 -0700581 const VkImageMemoryBarrier *pImgMemBarriers) {
Mark Lobodzinski6b6c50a2017-02-27 12:56:14 -0700582 for (uint32_t i = 0; i < memBarrierCount; ++i) {
583 auto mem_barrier = &pImgMemBarriers[i];
584 if (!mem_barrier) continue;
Mark Lobodzinski6b6c50a2017-02-27 12:56:14 -0700585
Chris Forbes4de4b132017-08-21 11:27:08 -0700586 // For ownership transfers, the barrier is specified twice; as a release
587 // operation on the yielding queue family, and as an acquire operation
588 // on the acquiring queue family. This barrier may also include a layout
589 // transition, which occurs 'between' the two operations. For validation
590 // purposes it doesn't seem important which side performs the layout
591 // transition, but it must not be performed twice. We'll arbitrarily
592 // choose to perform it as part of the acquire operation.
593 if (IsReleaseOp(device_data, cb_state, mem_barrier)) {
594 continue;
595 }
596
Mark Lobodzinski903e5ff2017-03-23 09:43:35 -0600597 VkImageCreateInfo *image_create_info = &(GetImageState(device_data, mem_barrier->image)->createInfo);
598 uint32_t level_count = ResolveRemainingLevels(&mem_barrier->subresourceRange, image_create_info->mipLevels);
599 uint32_t layer_count = ResolveRemainingLayers(&mem_barrier->subresourceRange, image_create_info->arrayLayers);
600
Dave Houltonb3f4b282018-02-22 16:25:16 -0700601 // Special case for 3D images with VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT_KHR flag bit, where <extent.depth> and
602 // <arrayLayers> can potentially alias. When recording layout for the entire image, pre-emptively record layouts
603 // for all (potential) layer sub_resources.
604 if ((0 != (image_create_info->flags & VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT_KHR)) &&
605 (mem_barrier->subresourceRange.baseArrayLayer == 0) && (layer_count == 1)) {
606 layer_count = image_create_info->extent.depth; // Treat each depth slice as a layer subresource
607 }
608
Mark Lobodzinski903e5ff2017-03-23 09:43:35 -0600609 for (uint32_t j = 0; j < level_count; j++) {
Mark Lobodzinski6b6c50a2017-02-27 12:56:14 -0700610 uint32_t level = mem_barrier->subresourceRange.baseMipLevel + j;
Mark Lobodzinski903e5ff2017-03-23 09:43:35 -0600611 for (uint32_t k = 0; k < layer_count; k++) {
Mark Lobodzinski6b6c50a2017-02-27 12:56:14 -0700612 uint32_t layer = mem_barrier->subresourceRange.baseArrayLayer + k;
Chris Forbes399a6782017-08-18 15:00:48 -0700613 TransitionImageAspectLayout(device_data, cb_state, mem_barrier, level, layer, VK_IMAGE_ASPECT_COLOR_BIT);
614 TransitionImageAspectLayout(device_data, cb_state, mem_barrier, level, layer, VK_IMAGE_ASPECT_DEPTH_BIT);
615 TransitionImageAspectLayout(device_data, cb_state, mem_barrier, level, layer, VK_IMAGE_ASPECT_STENCIL_BIT);
616 TransitionImageAspectLayout(device_data, cb_state, mem_barrier, level, layer, VK_IMAGE_ASPECT_METADATA_BIT);
Dave Houltonb3f4b282018-02-22 16:25:16 -0700617 if (GetDeviceExtensions(device_data)->vk_khr_sampler_ycbcr_conversion) {
Chris Forbes399a6782017-08-18 15:00:48 -0700618 TransitionImageAspectLayout(device_data, cb_state, mem_barrier, level, layer, VK_IMAGE_ASPECT_PLANE_0_BIT_KHR);
619 TransitionImageAspectLayout(device_data, cb_state, mem_barrier, level, layer, VK_IMAGE_ASPECT_PLANE_1_BIT_KHR);
620 TransitionImageAspectLayout(device_data, cb_state, mem_barrier, level, layer, VK_IMAGE_ASPECT_PLANE_2_BIT_KHR);
Dave Houltonb3f4b282018-02-22 16:25:16 -0700621 }
Mark Lobodzinski6b6c50a2017-02-27 12:56:14 -0700622 }
623 }
624 }
625}
626
Tobin Ehlisc8266452017-04-07 12:20:30 -0600627bool VerifyImageLayout(layer_data const *device_data, GLOBAL_CB_NODE const *cb_node, IMAGE_STATE *image_state,
Tobin Ehlis2d85ec62017-03-14 15:38:48 -0600628 VkImageSubresourceLayers subLayers, VkImageLayout explicit_layout, VkImageLayout optimal_layout,
Tobin Ehlisc8266452017-04-07 12:20:30 -0600629 const char *caller, UNIQUE_VALIDATION_ERROR_CODE msg_code, bool *error) {
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700630 const auto report_data = core_validation::GetReportData(device_data);
Tobin Ehlis2d85ec62017-03-14 15:38:48 -0600631 const auto image = image_state->image;
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600632 bool skip = false;
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700633
634 for (uint32_t i = 0; i < subLayers.layerCount; ++i) {
635 uint32_t layer = i + subLayers.baseArrayLayer;
636 VkImageSubresource sub = {subLayers.aspectMask, subLayers.mipLevel, layer};
637 IMAGE_CMD_BUF_LAYOUT_NODE node;
Tobin Ehlise35b66a2017-03-15 12:18:31 -0600638 if (FindCmdBufLayout(device_data, cb_node, image, sub, node)) {
639 if (node.layout != explicit_layout) {
Tobin Ehlisc8266452017-04-07 12:20:30 -0600640 *error = true;
Tobin Ehlise35b66a2017-03-15 12:18:31 -0600641 // TODO: Improve log message in the next pass
Petr Kraus13c98a62017-12-09 00:22:39 +0100642 skip |= log_msg(
643 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -0600644 HandleToUint64(cb_node->commandBuffer), DRAWSTATE_INVALID_IMAGE_LAYOUT,
Petr Kraus13c98a62017-12-09 00:22:39 +0100645 "%s: Cannot use image 0x%" PRIx64 " with specific layout %s that doesn't match the actual current layout %s.",
646 caller, HandleToUint64(image), string_VkImageLayout(explicit_layout), string_VkImageLayout(node.layout));
Tobin Ehlise35b66a2017-03-15 12:18:31 -0600647 }
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700648 }
649 }
Tobin Ehlis2d85ec62017-03-14 15:38:48 -0600650 // If optimal_layout is not UNDEFINED, check that layout matches optimal for this case
651 if ((VK_IMAGE_LAYOUT_UNDEFINED != optimal_layout) && (explicit_layout != optimal_layout)) {
652 if (VK_IMAGE_LAYOUT_GENERAL == explicit_layout) {
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700653 if (image_state->createInfo.tiling != VK_IMAGE_TILING_LINEAR) {
654 // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning.
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600655 skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinskib1fd9d12018-03-30 14:26:00 -0600656 VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, HandleToUint64(cb_node->commandBuffer),
Mark Lobodzinski88529492018-04-01 10:38:15 -0600657 DRAWSTATE_INVALID_IMAGE_LAYOUT,
Petr Kraus13c98a62017-12-09 00:22:39 +0100658 "%s: For optimal performance image 0x%" PRIx64 " layout should be %s instead of GENERAL.", caller,
659 HandleToUint64(image), string_VkImageLayout(optimal_layout));
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700660 }
Mark Lobodzinski28426ae2017-06-01 07:56:38 -0600661 } else if (GetDeviceExtensions(device_data)->vk_khr_shared_presentable_image) {
Mark Lobodzinski087380c2017-05-16 14:42:25 -0600662 if (image_state->shared_presentable) {
663 if (VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR != explicit_layout) {
664 // TODO: Add unique error id when available.
Mark Lobodzinskib1fd9d12018-03-30 14:26:00 -0600665 skip |=
666 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, msg_code,
Mark Lobodzinski88529492018-04-01 10:38:15 -0600667 "Layout for shared presentable image is %s but must be VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR.",
Mark Lobodzinskib1fd9d12018-03-30 14:26:00 -0600668 string_VkImageLayout(optimal_layout));
Mark Lobodzinski087380c2017-05-16 14:42:25 -0600669 }
Tobin Ehlisbb03e5f2017-05-11 08:52:51 -0600670 }
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700671 } else {
Tobin Ehlisc8266452017-04-07 12:20:30 -0600672 *error = true;
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600673 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -0600674 HandleToUint64(cb_node->commandBuffer), msg_code,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -0600675 "%s: Layout for image 0x%" PRIx64 " is %s but can only be %s or VK_IMAGE_LAYOUT_GENERAL.", caller,
676 HandleToUint64(image), string_VkImageLayout(explicit_layout), string_VkImageLayout(optimal_layout));
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700677 }
678 }
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600679 return skip;
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700680}
681
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700682void TransitionFinalSubpassLayouts(layer_data *device_data, GLOBAL_CB_NODE *pCB, const VkRenderPassBeginInfo *pRenderPassBegin,
683 FRAMEBUFFER_STATE *framebuffer_state) {
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -0700684 auto renderPass = GetRenderPassState(device_data, pRenderPassBegin->renderPass);
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700685 if (!renderPass) return;
686
687 const VkRenderPassCreateInfo *pRenderPassInfo = renderPass->createInfo.ptr();
688 if (framebuffer_state) {
689 for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) {
690 auto image_view = framebuffer_state->createInfo.pAttachments[i];
691 SetImageViewLayout(device_data, pCB, image_view, pRenderPassInfo->pAttachments[i].finalLayout);
692 }
693 }
694}
Dave Houltone19e20d2018-02-02 16:32:41 -0700695
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700696bool PreCallValidateCreateImage(layer_data *device_data, const VkImageCreateInfo *pCreateInfo,
Mark Lobodzinski90224de2017-01-26 15:23:11 -0700697 const VkAllocationCallbacks *pAllocator, VkImage *pImage) {
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600698 bool skip = false;
Mark Lobodzinski90224de2017-01-26 15:23:11 -0700699 const debug_report_data *report_data = core_validation::GetReportData(device_data);
700
Jeremy Hayes96dcd812017-03-14 14:04:19 -0600701 if (pCreateInfo->format == VK_FORMAT_UNDEFINED) {
Mark Lobodzinskib1fd9d12018-03-30 14:26:00 -0600702 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
Mark Lobodzinski88529492018-04-01 10:38:15 -0600703 VALIDATION_ERROR_09e0075e, "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED.");
Jeremy Hayes96dcd812017-03-14 14:04:19 -0600704
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600705 return skip;
Jeremy Hayes96dcd812017-03-14 14:04:19 -0600706 }
707
Dave Houlton130c0212018-01-29 13:39:56 -0700708 bool optimal_tiling = (VK_IMAGE_TILING_OPTIMAL == pCreateInfo->tiling);
709 const char *tiling_string = string_VkImageTiling(pCreateInfo->tiling);
710 const char *format_string = string_VkFormat(pCreateInfo->format);
Jeremy Kniager7ec550f2017-08-16 14:57:42 -0600711 VkFormatProperties properties = GetFormatProperties(device_data, pCreateInfo->format);
Dave Houlton130c0212018-01-29 13:39:56 -0700712 VkFormatFeatureFlags features = (optimal_tiling ? properties.optimalTilingFeatures : properties.linearTilingFeatures);
Jeremy Hayes96dcd812017-03-14 14:04:19 -0600713
Dave Houlton130c0212018-01-29 13:39:56 -0700714 if (0 == features) {
Jeremy Hayes96dcd812017-03-14 14:04:19 -0600715 std::stringstream ss;
Dave Houlton130c0212018-01-29 13:39:56 -0700716 UNIQUE_VALIDATION_ERROR_CODE vuid = (optimal_tiling ? VALIDATION_ERROR_09e007ac : VALIDATION_ERROR_09e007a2);
717 ss << "vkCreateImage format parameter " << format_string << " is an unsupported format";
Mark Lobodzinski88529492018-04-01 10:38:15 -0600718 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, vuid, "%s.",
719 ss.str().c_str());
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600720 return skip;
Jeremy Hayes96dcd812017-03-14 14:04:19 -0600721 }
722
Dave Houlton130c0212018-01-29 13:39:56 -0700723 if ((pCreateInfo->usage & VK_IMAGE_USAGE_SAMPLED_BIT) && !(features & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Jeremy Hayes96dcd812017-03-14 14:04:19 -0600724 std::stringstream ss;
Dave Houlton130c0212018-01-29 13:39:56 -0700725 UNIQUE_VALIDATION_ERROR_CODE vuid = (optimal_tiling ? VALIDATION_ERROR_09e007ae : VALIDATION_ERROR_09e007a4);
726 ss << "vkCreateImage: usage bit VK_IMAGE_USAGE_SAMPLED_BIT is not supported for format " << format_string << " with tiling "
727 << tiling_string;
Mark Lobodzinski88529492018-04-01 10:38:15 -0600728 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, vuid, "%s.",
729 ss.str().c_str());
Dave Houlton130c0212018-01-29 13:39:56 -0700730 }
Jeremy Hayes96dcd812017-03-14 14:04:19 -0600731
Dave Houlton130c0212018-01-29 13:39:56 -0700732 if ((pCreateInfo->usage & VK_IMAGE_USAGE_STORAGE_BIT) && !(features & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT)) {
733 std::stringstream ss;
734 UNIQUE_VALIDATION_ERROR_CODE vuid = (optimal_tiling ? VALIDATION_ERROR_09e007b0 : VALIDATION_ERROR_09e007a6);
735 ss << "vkCreateImage: usage bit VK_IMAGE_USAGE_STORAGE_BIT is not supported for format " << format_string << " with tiling "
736 << tiling_string;
Mark Lobodzinski88529492018-04-01 10:38:15 -0600737 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, vuid, "%s.",
738 ss.str().c_str());
Jeremy Hayes96dcd812017-03-14 14:04:19 -0600739 }
740
Lenny Komowb79f04a2017-09-18 17:07:00 -0600741 // TODO: Add checks for EXTENDED_USAGE images to validate images are compatible
742 // For EXTENDED_USAGE images, format can match any image COMPATIBLE with original image
743 if (!GetDeviceExtensions(device_data)->vk_khr_maintenance2 || !(pCreateInfo->flags & VK_IMAGE_CREATE_EXTENDED_USAGE_BIT_KHR)) {
744 // Validate that format supports usage as color attachment
Dave Houlton130c0212018-01-29 13:39:56 -0700745 if ((pCreateInfo->usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) &&
746 (0 == (features & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT))) {
747 UNIQUE_VALIDATION_ERROR_CODE vuid = (optimal_tiling ? VALIDATION_ERROR_09e007b2 : VALIDATION_ERROR_09e007a8);
748 std::stringstream ss;
749 ss << "vkCreateImage: usage bit VK_IMAGE_USAGE_COLOR_ATTACHMENT is not supported for format " << format_string
750 << " with tiling " << tiling_string;
Mark Lobodzinski88529492018-04-01 10:38:15 -0600751 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, vuid, "%s.",
752 ss.str().c_str());
Jeremy Hayes96dcd812017-03-14 14:04:19 -0600753 }
Jeremy Hayes96dcd812017-03-14 14:04:19 -0600754
Lenny Komowb79f04a2017-09-18 17:07:00 -0600755 // Validate that format supports usage as depth/stencil attachment
Dave Houlton130c0212018-01-29 13:39:56 -0700756 if ((pCreateInfo->usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) &&
757 (0 == (features & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT))) {
758 UNIQUE_VALIDATION_ERROR_CODE vuid = (optimal_tiling ? VALIDATION_ERROR_09e007b4 : VALIDATION_ERROR_09e007aa);
759 std::stringstream ss;
760 ss << "vkCreateImage: usage bit VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT is not supported for format " << format_string
761 << " with tiling " << tiling_string;
Mark Lobodzinski88529492018-04-01 10:38:15 -0600762 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, vuid, "%s.",
763 ss.str().c_str());
Dave Houlton130c0212018-01-29 13:39:56 -0700764 }
765 }
766
767 if ((pCreateInfo->flags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT) && (VK_IMAGE_TYPE_2D != pCreateInfo->imageType)) {
768 std::stringstream ss;
769 ss << "vkCreateImage: Image type must be VK_IMAGE_TYPE_2D when VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT flag bit is set";
Mark Lobodzinskib1fd9d12018-03-30 14:26:00 -0600770 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
Mark Lobodzinski88529492018-04-01 10:38:15 -0600771 VALIDATION_ERROR_09e0076a, "%s.", ss.str().c_str());
Dave Houlton130c0212018-01-29 13:39:56 -0700772 }
773
774 const VkPhysicalDeviceLimits *device_limits = &(GetPhysicalDeviceProperties(device_data)->limits);
775 VkImageFormatProperties format_limits; // Format limits may exceed general device limits
776 VkResult err = GetImageFormatProperties(device_data, pCreateInfo, &format_limits);
777 if (VK_SUCCESS != err) {
778 std::stringstream ss;
779 ss << "vkCreateImage: The combination of format, type, tiling, usage and flags supplied in the VkImageCreateInfo struct is "
780 "reported by vkGetPhysicalDeviceImageFormatProperties() as unsupported";
Mark Lobodzinskib1fd9d12018-03-30 14:26:00 -0600781 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
Mark Lobodzinski88529492018-04-01 10:38:15 -0600782 VALIDATION_ERROR_09e00758, "%s.", ss.str().c_str());
Dave Houlton130c0212018-01-29 13:39:56 -0700783 return skip;
784 }
785
786 if ((VK_IMAGE_TYPE_1D == pCreateInfo->imageType) &&
787 (pCreateInfo->extent.width > std::max(device_limits->maxImageDimension1D, format_limits.maxExtent.width))) {
788 std::stringstream ss;
789 ss << "vkCreateImage: 1D image width exceeds maximum supported width for format " << format_string;
Mark Lobodzinskib1fd9d12018-03-30 14:26:00 -0600790 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
Mark Lobodzinski88529492018-04-01 10:38:15 -0600791 VALIDATION_ERROR_09e0076e, "%s.", ss.str().c_str());
Dave Houlton130c0212018-01-29 13:39:56 -0700792 }
793
794 if (VK_IMAGE_TYPE_2D == pCreateInfo->imageType) {
795 if (0 == (pCreateInfo->flags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT)) {
796 if (pCreateInfo->extent.width > std::max(device_limits->maxImageDimension2D, format_limits.maxExtent.width) ||
797 pCreateInfo->extent.height > std::max(device_limits->maxImageDimension2D, format_limits.maxExtent.height)) {
Lenny Komowb79f04a2017-09-18 17:07:00 -0600798 std::stringstream ss;
Dave Houlton130c0212018-01-29 13:39:56 -0700799 ss << "vkCreateImage: 2D image extent exceeds maximum supported width or height for format " << format_string;
Mark Lobodzinskib1fd9d12018-03-30 14:26:00 -0600800 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
Mark Lobodzinski88529492018-04-01 10:38:15 -0600801 VALIDATION_ERROR_09e00770, "%s.", ss.str().c_str());
Lenny Komowb79f04a2017-09-18 17:07:00 -0600802 }
Dave Houlton130c0212018-01-29 13:39:56 -0700803 } else {
804 if (pCreateInfo->extent.width > std::max(device_limits->maxImageDimensionCube, format_limits.maxExtent.width) ||
805 pCreateInfo->extent.height > std::max(device_limits->maxImageDimensionCube, format_limits.maxExtent.height)) {
Lenny Komowb79f04a2017-09-18 17:07:00 -0600806 std::stringstream ss;
Dave Houlton130c0212018-01-29 13:39:56 -0700807 ss << "vkCreateImage: 2D image extent exceeds maximum supported width or height for cube-compatible images with "
808 "format "
809 << format_string;
Mark Lobodzinskib1fd9d12018-03-30 14:26:00 -0600810 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
Mark Lobodzinski88529492018-04-01 10:38:15 -0600811 VALIDATION_ERROR_09e00772, "%s.", ss.str().c_str());
Lenny Komowb79f04a2017-09-18 17:07:00 -0600812 }
Jeremy Hayes96dcd812017-03-14 14:04:19 -0600813 }
Mark Lobodzinski90224de2017-01-26 15:23:11 -0700814 }
815
Dave Houlton130c0212018-01-29 13:39:56 -0700816 if (VK_IMAGE_TYPE_3D == pCreateInfo->imageType) {
817 if ((pCreateInfo->extent.width > std::max(device_limits->maxImageDimension3D, format_limits.maxExtent.width)) ||
818 (pCreateInfo->extent.height > std::max(device_limits->maxImageDimension3D, format_limits.maxExtent.height)) ||
819 (pCreateInfo->extent.depth > std::max(device_limits->maxImageDimension3D, format_limits.maxExtent.depth))) {
820 std::stringstream ss;
821 ss << "vkCreateImage: 3D image extent exceeds maximum supported width, height, or depth for format " << format_string;
Mark Lobodzinskib1fd9d12018-03-30 14:26:00 -0600822 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
Mark Lobodzinski88529492018-04-01 10:38:15 -0600823 VALIDATION_ERROR_09e00776, "%s.", ss.str().c_str());
Dave Houlton130c0212018-01-29 13:39:56 -0700824 }
Mark Lobodzinski90224de2017-01-26 15:23:11 -0700825 }
826
Dave Houlton130c0212018-01-29 13:39:56 -0700827 // NOTE: As of 1/30/2018 the spec VU language is as in the commented code below. I believe this is an
Dave Houltone19e20d2018-02-02 16:32:41 -0700828 // error in the spec, and have submitted Gitlab Vulkan issue #1151 to have it changed to match the
Dave Houlton130c0212018-01-29 13:39:56 -0700829 // implementation shown. DJH
830 //
831 // if ((pCreateInfo->mipLevels > format_limits.maxMipLevels) &&
832 // (std::max({ pCreateInfo->extent.width, pCreateInfo->extent.height, pCreateInfo->extent.depth }) >
833 // device_limits->maxImageDimension3D)) {
834 if (pCreateInfo->mipLevels > format_limits.maxMipLevels) {
835 std::stringstream ss;
836 ss << "vkCreateImage: Image mip levels exceed image format maxMipLevels for format " << format_string;
Mark Lobodzinskib1fd9d12018-03-30 14:26:00 -0600837 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
Mark Lobodzinski88529492018-04-01 10:38:15 -0600838 VALIDATION_ERROR_09e0077e, "%s.", ss.str().c_str());
Dave Houlton130c0212018-01-29 13:39:56 -0700839 }
Mark Lobodzinski90224de2017-01-26 15:23:11 -0700840
Dave Houlton130c0212018-01-29 13:39:56 -0700841 VkImageUsageFlags attach_flags = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT |
842 VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT;
843 if ((pCreateInfo->usage & attach_flags) && (pCreateInfo->extent.width > device_limits->maxFramebufferWidth)) {
844 std::stringstream ss;
845 ss << "vkCreateImage: Image usage flags include a frame buffer attachment bit and image width exceeds device "
846 "maxFramebufferWidth";
Mark Lobodzinskib1fd9d12018-03-30 14:26:00 -0600847 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
Mark Lobodzinski88529492018-04-01 10:38:15 -0600848 VALIDATION_ERROR_09e00788, "%s.", ss.str().c_str());
Dave Houlton130c0212018-01-29 13:39:56 -0700849 }
850
851 if ((pCreateInfo->usage & attach_flags) && (pCreateInfo->extent.height > device_limits->maxFramebufferHeight)) {
852 std::stringstream ss;
853 ss << "vkCreateImage: Image usage flags include a frame buffer attachment bit and image height exceeds device "
854 "maxFramebufferHeight";
Mark Lobodzinskib1fd9d12018-03-30 14:26:00 -0600855 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
Mark Lobodzinski88529492018-04-01 10:38:15 -0600856 VALIDATION_ERROR_09e0078a, "%s.", ss.str().c_str());
Dave Houlton130c0212018-01-29 13:39:56 -0700857 }
858
859 uint64_t total_size = (uint64_t)pCreateInfo->extent.width * (uint64_t)pCreateInfo->extent.height *
860 (uint64_t)pCreateInfo->extent.depth * (uint64_t)pCreateInfo->arrayLayers *
861 (uint64_t)pCreateInfo->samples * (uint64_t)FormatSize(pCreateInfo->format);
862
863 // Round up to imageGranularity boundary
864 VkDeviceSize imageGranularity = GetPhysicalDeviceProperties(device_data)->limits.bufferImageGranularity;
865 uint64_t ig_mask = imageGranularity - 1;
866 total_size = (total_size + ig_mask) & ~ig_mask;
867
868 if (total_size > format_limits.maxResourceSize) {
Mark Lobodzinskib1fd9d12018-03-30 14:26:00 -0600869 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0,
Mark Lobodzinski88529492018-04-01 10:38:15 -0600870 IMAGE_INVALID_FORMAT_LIMITS_VIOLATION,
Dave Houltona9df0ce2018-02-07 10:51:23 -0700871 "CreateImage resource size exceeds allowable maximum Image resource size = 0x%" PRIxLEAST64
872 ", maximum resource size = 0x%" PRIxLEAST64 " ",
Dave Houlton130c0212018-01-29 13:39:56 -0700873 total_size, format_limits.maxResourceSize);
Mark Lobodzinski90224de2017-01-26 15:23:11 -0700874 }
875
Dave Houlton130c0212018-01-29 13:39:56 -0700876 if (pCreateInfo->arrayLayers > format_limits.maxArrayLayers) {
Mark Lobodzinskib1fd9d12018-03-30 14:26:00 -0600877 skip |=
878 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, VALIDATION_ERROR_09e00780,
Mark Lobodzinski88529492018-04-01 10:38:15 -0600879 "CreateImage arrayLayers=%d exceeds allowable maximum supported by format of %d.", pCreateInfo->arrayLayers,
880 format_limits.maxArrayLayers);
Mark Lobodzinski90224de2017-01-26 15:23:11 -0700881 }
882
Dave Houlton130c0212018-01-29 13:39:56 -0700883 if ((pCreateInfo->samples & format_limits.sampleCounts) == 0) {
Mark Lobodzinskib1fd9d12018-03-30 14:26:00 -0600884 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0,
Mark Lobodzinski88529492018-04-01 10:38:15 -0600885 VALIDATION_ERROR_09e0078e, "CreateImage samples %s is not supported by format 0x%.8X.",
Mark Lobodzinski487a0d12018-03-30 10:09:03 -0600886 string_VkSampleCountFlagBits(pCreateInfo->samples), format_limits.sampleCounts);
Mark Lobodzinski90224de2017-01-26 15:23:11 -0700887 }
888
Mark Lobodzinski035a4cf2017-03-13 09:45:07 -0600889 if ((pCreateInfo->flags & VK_IMAGE_CREATE_SPARSE_ALIASED_BIT) && (!GetEnabledFeatures(device_data)->sparseResidencyAliased)) {
Mark Lobodzinskib1fd9d12018-03-30 14:26:00 -0600890 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
Mark Lobodzinski88529492018-04-01 10:38:15 -0600891 DRAWSTATE_INVALID_FEATURE,
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600892 "vkCreateImage(): the sparseResidencyAliased device feature is disabled: Images cannot be created with the "
893 "VK_IMAGE_CREATE_SPARSE_ALIASED_BIT set.");
Mark Lobodzinski035a4cf2017-03-13 09:45:07 -0600894 }
895
Lenny Komowb79f04a2017-09-18 17:07:00 -0600896 if (GetDeviceExtensions(device_data)->vk_khr_maintenance2) {
897 if (pCreateInfo->flags & VK_IMAGE_CREATE_BLOCK_TEXEL_VIEW_COMPATIBLE_BIT_KHR) {
898 if (!(FormatIsCompressed_BC(pCreateInfo->format) || FormatIsCompressed_ASTC_LDR(pCreateInfo->format) ||
899 FormatIsCompressed_ETC2_EAC(pCreateInfo->format))) {
900 // TODO: Add Maintenance2 VUID
901 skip |=
Mark Lobodzinskib1fd9d12018-03-30 14:26:00 -0600902 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
Mark Lobodzinski88529492018-04-01 10:38:15 -0600903 VALIDATION_ERROR_UNDEFINED,
Lenny Komowb79f04a2017-09-18 17:07:00 -0600904 "vkCreateImage(): If pCreateInfo->flags contains VK_IMAGE_CREATE_BLOCK_TEXEL_VIEW_COMPATIBLE_BIT_KHR, "
905 "format must be block, ETC or ASTC compressed, but is %s",
906 string_VkFormat(pCreateInfo->format));
907 }
908 if (!(pCreateInfo->flags & VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT)) {
909 // TODO: Add Maintenance2 VUID
910 skip |=
Mark Lobodzinskib1fd9d12018-03-30 14:26:00 -0600911 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
Mark Lobodzinski88529492018-04-01 10:38:15 -0600912 VALIDATION_ERROR_UNDEFINED,
Lenny Komowb79f04a2017-09-18 17:07:00 -0600913 "vkCreateImage(): If pCreateInfo->flags contains VK_IMAGE_CREATE_BLOCK_TEXEL_VIEW_COMPATIBLE_BIT_KHR, "
914 "flags must also contain VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT.");
915 }
916 }
917 }
918
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600919 return skip;
Mark Lobodzinski90224de2017-01-26 15:23:11 -0700920}
921
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700922void PostCallRecordCreateImage(layer_data *device_data, const VkImageCreateInfo *pCreateInfo, VkImage *pImage) {
Mark Lobodzinski42fe5f72017-01-11 11:36:16 -0700923 IMAGE_LAYOUT_NODE image_state;
924 image_state.layout = pCreateInfo->initialLayout;
925 image_state.format = pCreateInfo->format;
Mark Lobodzinski214144a2017-01-27 14:25:32 -0700926 GetImageMap(device_data)->insert(std::make_pair(*pImage, std::unique_ptr<IMAGE_STATE>(new IMAGE_STATE(*pImage, pCreateInfo))));
Mark Lobodzinski42fe5f72017-01-11 11:36:16 -0700927 ImageSubresourcePair subpair{*pImage, false, VkImageSubresource()};
Mark Lobodzinski214144a2017-01-27 14:25:32 -0700928 (*core_validation::GetImageSubresourceMap(device_data))[*pImage].push_back(subpair);
929 (*core_validation::GetImageLayoutMap(device_data))[subpair] = image_state;
Mark Lobodzinski42fe5f72017-01-11 11:36:16 -0700930}
Mark Lobodzinski9ef5d562017-01-27 12:28:30 -0700931
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700932bool PreCallValidateDestroyImage(layer_data *device_data, VkImage image, IMAGE_STATE **image_state, VK_OBJECT *obj_struct) {
Mark Lobodzinski9ef5d562017-01-27 12:28:30 -0700933 const CHECK_DISABLED *disabled = core_validation::GetDisables(device_data);
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -0700934 *image_state = core_validation::GetImageState(device_data, image);
Petr Krausbc7f5442017-05-14 23:43:38 +0200935 *obj_struct = {HandleToUint64(image), kVulkanObjectTypeImage};
Mark Lobodzinski9ef5d562017-01-27 12:28:30 -0700936 if (disabled->destroy_image) return false;
937 bool skip = false;
938 if (*image_state) {
Mike Schuchardta5025652017-09-27 14:56:21 -0600939 skip |= core_validation::ValidateObjectNotInUse(device_data, *image_state, *obj_struct, "vkDestroyImage",
940 VALIDATION_ERROR_252007d0);
Mark Lobodzinski9ef5d562017-01-27 12:28:30 -0700941 }
942 return skip;
943}
944
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700945void PostCallRecordDestroyImage(layer_data *device_data, VkImage image, IMAGE_STATE *image_state, VK_OBJECT obj_struct) {
Mark Lobodzinski9ef5d562017-01-27 12:28:30 -0700946 core_validation::invalidateCommandBuffers(device_data, image_state->cb_bindings, obj_struct);
947 // Clean up memory mapping, bindings and range references for image
948 for (auto mem_binding : image_state->GetBoundMemory()) {
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -0700949 auto mem_info = core_validation::GetMemObjInfo(device_data, mem_binding);
Mark Lobodzinski9ef5d562017-01-27 12:28:30 -0700950 if (mem_info) {
951 core_validation::RemoveImageMemoryRange(obj_struct.handle, mem_info);
952 }
953 }
Mark Lobodzinski33826372017-04-13 11:10:11 -0600954 core_validation::ClearMemoryObjectBindings(device_data, obj_struct.handle, kVulkanObjectTypeImage);
Mark Lobodzinski9ef5d562017-01-27 12:28:30 -0700955 // Remove image from imageMap
956 core_validation::GetImageMap(device_data)->erase(image);
957 std::unordered_map<VkImage, std::vector<ImageSubresourcePair>> *imageSubresourceMap =
958 core_validation::GetImageSubresourceMap(device_data);
959
960 const auto &sub_entry = imageSubresourceMap->find(image);
961 if (sub_entry != imageSubresourceMap->end()) {
962 for (const auto &pair : sub_entry->second) {
963 core_validation::GetImageLayoutMap(device_data)->erase(pair);
964 }
965 imageSubresourceMap->erase(sub_entry);
966 }
967}
Mark Lobodzinskic409a582017-01-27 15:16:01 -0700968
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700969bool ValidateImageAttributes(layer_data *device_data, IMAGE_STATE *image_state, VkImageSubresourceRange range) {
Mark Lobodzinskic409a582017-01-27 15:16:01 -0700970 bool skip = false;
971 const debug_report_data *report_data = core_validation::GetReportData(device_data);
972
973 if (range.aspectMask != VK_IMAGE_ASPECT_COLOR_BIT) {
974 char const str[] = "vkCmdClearColorImage aspectMasks for all subresource ranges must be set to VK_IMAGE_ASPECT_COLOR_BIT";
975 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -0600976 HandleToUint64(image_state->image), DRAWSTATE_INVALID_IMAGE_ASPECT, str);
Mark Lobodzinskic409a582017-01-27 15:16:01 -0700977 }
978
Dave Houlton1d2022c2017-03-29 11:43:58 -0600979 if (FormatIsDepthOrStencil(image_state->createInfo.format)) {
Mark Lobodzinskic409a582017-01-27 15:16:01 -0700980 char const str[] = "vkCmdClearColorImage called with depth/stencil image.";
981 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -0600982 HandleToUint64(image_state->image), VALIDATION_ERROR_1880000e, "%s.", str);
Dave Houlton1d2022c2017-03-29 11:43:58 -0600983 } else if (FormatIsCompressed(image_state->createInfo.format)) {
Mark Lobodzinskic409a582017-01-27 15:16:01 -0700984 char const str[] = "vkCmdClearColorImage called with compressed image.";
985 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -0600986 HandleToUint64(image_state->image), VALIDATION_ERROR_1880000e, "%s.", str);
Mark Lobodzinskic409a582017-01-27 15:16:01 -0700987 }
988
989 if (!(image_state->createInfo.usage & VK_IMAGE_USAGE_TRANSFER_DST_BIT)) {
990 char const str[] = "vkCmdClearColorImage called with image created without VK_IMAGE_USAGE_TRANSFER_DST_BIT.";
991 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -0600992 HandleToUint64(image_state->image), VALIDATION_ERROR_18800004, "%s.", str);
Mark Lobodzinskic409a582017-01-27 15:16:01 -0700993 }
994 return skip;
995}
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700996
Mark Lobodzinski903e5ff2017-03-23 09:43:35 -0600997uint32_t ResolveRemainingLevels(const VkImageSubresourceRange *range, uint32_t mip_levels) {
998 // Return correct number of mip levels taking into account VK_REMAINING_MIP_LEVELS
999 uint32_t mip_level_count = range->levelCount;
Mark Lobodzinski9c93dbd2017-02-02 08:31:18 -07001000 if (range->levelCount == VK_REMAINING_MIP_LEVELS) {
Mark Lobodzinski903e5ff2017-03-23 09:43:35 -06001001 mip_level_count = mip_levels - range->baseMipLevel;
Mark Lobodzinski9c93dbd2017-02-02 08:31:18 -07001002 }
Mark Lobodzinski903e5ff2017-03-23 09:43:35 -06001003 return mip_level_count;
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001004}
1005
Mark Lobodzinski903e5ff2017-03-23 09:43:35 -06001006uint32_t ResolveRemainingLayers(const VkImageSubresourceRange *range, uint32_t layers) {
1007 // Return correct number of layers taking into account VK_REMAINING_ARRAY_LAYERS
1008 uint32_t array_layer_count = range->layerCount;
1009 if (range->layerCount == VK_REMAINING_ARRAY_LAYERS) {
1010 array_layer_count = layers - range->baseArrayLayer;
Mark Lobodzinski9c93dbd2017-02-02 08:31:18 -07001011 }
Mark Lobodzinski903e5ff2017-03-23 09:43:35 -06001012 return array_layer_count;
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001013}
1014
Tobin Ehlis58c884f2017-02-08 12:15:27 -07001015bool VerifyClearImageLayout(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *image_state,
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001016 VkImageSubresourceRange range, VkImageLayout dest_image_layout, const char *func_name) {
1017 bool skip = false;
1018 const debug_report_data *report_data = core_validation::GetReportData(device_data);
1019
Mark Lobodzinski903e5ff2017-03-23 09:43:35 -06001020 uint32_t level_count = ResolveRemainingLevels(&range, image_state->createInfo.mipLevels);
1021 uint32_t layer_count = ResolveRemainingLayers(&range, image_state->createInfo.arrayLayers);
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001022
1023 if (dest_image_layout != VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) {
1024 if (dest_image_layout == VK_IMAGE_LAYOUT_GENERAL) {
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001025 if (image_state->createInfo.tiling != VK_IMAGE_TILING_LINEAR) {
1026 // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning.
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06001027 skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06001028 HandleToUint64(image_state->image), DRAWSTATE_INVALID_IMAGE_LAYOUT,
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001029 "%s: Layout for cleared image should be TRANSFER_DST_OPTIMAL instead of GENERAL.", func_name);
1030 }
Mark Lobodzinski087380c2017-05-16 14:42:25 -06001031 } else if (VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR == dest_image_layout) {
Mark Lobodzinski28426ae2017-06-01 07:56:38 -06001032 if (!GetDeviceExtensions(device_data)->vk_khr_shared_presentable_image) {
Tobin Ehlisfb0661c2017-05-11 08:52:51 -06001033 // TODO: Add unique error id when available.
Mark Lobodzinski087380c2017-05-16 14:42:25 -06001034 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06001035 HandleToUint64(image_state->image), 0,
Dave Houlton33c2d252017-06-09 17:08:32 -06001036 "Must enable VK_KHR_shared_presentable_image extension before creating images with a layout type "
1037 "of VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR.");
Mark Lobodzinski087380c2017-05-16 14:42:25 -06001038
1039 } else {
1040 if (image_state->shared_presentable) {
1041 skip |= log_msg(
1042 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06001043 HandleToUint64(image_state->image), 0,
Mark Lobodzinski087380c2017-05-16 14:42:25 -06001044 "Layout for shared presentable cleared image is %s but can only be VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR.",
1045 string_VkImageLayout(dest_image_layout));
1046 }
Tobin Ehlisbb03e5f2017-05-11 08:52:51 -06001047 }
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001048 } else {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001049 UNIQUE_VALIDATION_ERROR_CODE error_code = VALIDATION_ERROR_1880000a;
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001050 if (strcmp(func_name, "vkCmdClearDepthStencilImage()") == 0) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001051 error_code = VALIDATION_ERROR_18a00018;
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001052 } else {
1053 assert(strcmp(func_name, "vkCmdClearColorImage()") == 0);
1054 }
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06001055 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06001056 HandleToUint64(image_state->image), error_code,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06001057 "%s: Layout for cleared image is %s but can only be TRANSFER_DST_OPTIMAL or GENERAL.", func_name,
1058 string_VkImageLayout(dest_image_layout));
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001059 }
1060 }
1061
Mark Lobodzinski903e5ff2017-03-23 09:43:35 -06001062 for (uint32_t level_index = 0; level_index < level_count; ++level_index) {
1063 uint32_t level = level_index + range.baseMipLevel;
1064 for (uint32_t layer_index = 0; layer_index < layer_count; ++layer_index) {
1065 uint32_t layer = layer_index + range.baseArrayLayer;
1066 VkImageSubresource sub = {range.aspectMask, level, layer};
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001067 IMAGE_CMD_BUF_LAYOUT_NODE node;
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -07001068 if (FindCmdBufLayout(device_data, cb_node, image_state->image, sub, node)) {
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001069 if (node.layout != dest_image_layout) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001070 UNIQUE_VALIDATION_ERROR_CODE error_code = VALIDATION_ERROR_18800008;
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001071 if (strcmp(func_name, "vkCmdClearDepthStencilImage()") == 0) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001072 error_code = VALIDATION_ERROR_18a00016;
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001073 } else {
1074 assert(strcmp(func_name, "vkCmdClearColorImage()") == 0);
1075 }
Mark Lobodzinski88529492018-04-01 10:38:15 -06001076 skip |=
1077 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0,
1078 error_code, "%s: Cannot clear an image whose layout is %s and doesn't match the current layout %s.",
1079 func_name, string_VkImageLayout(dest_image_layout), string_VkImageLayout(node.layout));
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001080 }
1081 }
1082 }
1083 }
1084
1085 return skip;
1086}
1087
Tobin Ehlis58c884f2017-02-08 12:15:27 -07001088void RecordClearImageLayout(layer_data *device_data, GLOBAL_CB_NODE *cb_node, VkImage image, VkImageSubresourceRange range,
1089 VkImageLayout dest_image_layout) {
Mark Lobodzinski903e5ff2017-03-23 09:43:35 -06001090 VkImageCreateInfo *image_create_info = &(GetImageState(device_data, image)->createInfo);
1091 uint32_t level_count = ResolveRemainingLevels(&range, image_create_info->mipLevels);
1092 uint32_t layer_count = ResolveRemainingLayers(&range, image_create_info->arrayLayers);
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001093
Mark Lobodzinski903e5ff2017-03-23 09:43:35 -06001094 for (uint32_t level_index = 0; level_index < level_count; ++level_index) {
1095 uint32_t level = level_index + range.baseMipLevel;
1096 for (uint32_t layer_index = 0; layer_index < layer_count; ++layer_index) {
1097 uint32_t layer = layer_index + range.baseArrayLayer;
1098 VkImageSubresource sub = {range.aspectMask, level, layer};
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001099 IMAGE_CMD_BUF_LAYOUT_NODE node;
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -07001100 if (!FindCmdBufLayout(device_data, cb_node, image, sub, node)) {
1101 SetLayout(device_data, cb_node, image, sub, IMAGE_CMD_BUF_LAYOUT_NODE(dest_image_layout, dest_image_layout));
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001102 }
1103 }
1104 }
1105}
1106
Tobin Ehlis58c884f2017-02-08 12:15:27 -07001107bool PreCallValidateCmdClearColorImage(layer_data *dev_data, VkCommandBuffer commandBuffer, VkImage image,
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001108 VkImageLayout imageLayout, uint32_t rangeCount, const VkImageSubresourceRange *pRanges) {
1109 bool skip = false;
1110 // TODO : Verify memory is in VK_IMAGE_STATE_CLEAR state
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07001111 auto cb_node = GetCBNode(dev_data, commandBuffer);
1112 auto image_state = GetImageState(dev_data, image);
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001113 if (cb_node && image_state) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001114 skip |= ValidateMemoryIsBoundToImage(dev_data, image_state, "vkCmdClearColorImage()", VALIDATION_ERROR_18800006);
Mike Schuchardt9c582402017-02-23 15:57:37 -07001115 skip |= ValidateCmdQueueFlags(dev_data, cb_node, "vkCmdClearColorImage()", VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001116 VALIDATION_ERROR_18802415);
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001117 skip |= ValidateCmd(dev_data, cb_node, CMD_CLEARCOLORIMAGE, "vkCmdClearColorImage()");
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001118 skip |= insideRenderPass(dev_data, cb_node, "vkCmdClearColorImage()", VALIDATION_ERROR_18800017);
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001119 for (uint32_t i = 0; i < rangeCount; ++i) {
Petr Kraus4d718682017-05-18 03:38:41 +02001120 std::string param_name = "pRanges[" + std::to_string(i) + "]";
Petr Krausffa94af2017-08-08 21:46:02 +02001121 skip |= ValidateCmdClearColorSubresourceRange(dev_data, image_state, pRanges[i], param_name.c_str());
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001122 skip |= ValidateImageAttributes(dev_data, image_state, pRanges[i]);
Mark Lobodzinski9c93dbd2017-02-02 08:31:18 -07001123 skip |= VerifyClearImageLayout(dev_data, cb_node, image_state, pRanges[i], imageLayout, "vkCmdClearColorImage()");
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001124 }
1125 }
1126 return skip;
1127}
1128
1129// This state recording routine is shared between ClearColorImage and ClearDepthStencilImage
Tobin Ehlis58c884f2017-02-08 12:15:27 -07001130void PreCallRecordCmdClearImage(layer_data *dev_data, VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout,
Chris Forbes38c2e792017-06-16 16:42:35 -07001131 uint32_t rangeCount, const VkImageSubresourceRange *pRanges) {
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07001132 auto cb_node = GetCBNode(dev_data, commandBuffer);
1133 auto image_state = GetImageState(dev_data, image);
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001134 if (cb_node && image_state) {
1135 AddCommandBufferBindingImage(dev_data, cb_node, image_state);
1136 std::function<bool()> function = [=]() {
1137 SetImageMemoryValid(dev_data, image_state, true);
1138 return false;
1139 };
Tobin Ehlisa17a5292017-07-28 12:11:30 -06001140 cb_node->queue_submit_functions.push_back(function);
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001141 for (uint32_t i = 0; i < rangeCount; ++i) {
1142 RecordClearImageLayout(dev_data, cb_node, image, pRanges[i], imageLayout);
1143 }
1144 }
1145}
1146
Tobin Ehlis58c884f2017-02-08 12:15:27 -07001147bool PreCallValidateCmdClearDepthStencilImage(layer_data *device_data, VkCommandBuffer commandBuffer, VkImage image,
1148 VkImageLayout imageLayout, uint32_t rangeCount,
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001149 const VkImageSubresourceRange *pRanges) {
1150 bool skip = false;
Mark Lobodzinski1241a312017-02-01 10:57:21 -07001151 const debug_report_data *report_data = core_validation::GetReportData(device_data);
1152
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001153 // TODO : Verify memory is in VK_IMAGE_STATE_CLEAR state
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07001154 auto cb_node = GetCBNode(device_data, commandBuffer);
1155 auto image_state = GetImageState(device_data, image);
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001156 if (cb_node && image_state) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001157 skip |= ValidateMemoryIsBoundToImage(device_data, image_state, "vkCmdClearDepthStencilImage()", VALIDATION_ERROR_18a00014);
Mike Schuchardt9c582402017-02-23 15:57:37 -07001158 skip |= ValidateCmdQueueFlags(device_data, cb_node, "vkCmdClearDepthStencilImage()", VK_QUEUE_GRAPHICS_BIT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001159 VALIDATION_ERROR_18a02415);
Mark Lobodzinski1241a312017-02-01 10:57:21 -07001160 skip |= ValidateCmd(device_data, cb_node, CMD_CLEARDEPTHSTENCILIMAGE, "vkCmdClearDepthStencilImage()");
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001161 skip |= insideRenderPass(device_data, cb_node, "vkCmdClearDepthStencilImage()", VALIDATION_ERROR_18a00017);
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001162 for (uint32_t i = 0; i < rangeCount; ++i) {
Petr Kraus4d718682017-05-18 03:38:41 +02001163 std::string param_name = "pRanges[" + std::to_string(i) + "]";
Petr Krausffa94af2017-08-08 21:46:02 +02001164 skip |= ValidateCmdClearDepthSubresourceRange(device_data, image_state, pRanges[i], param_name.c_str());
Mark Lobodzinski9c93dbd2017-02-02 08:31:18 -07001165 skip |=
1166 VerifyClearImageLayout(device_data, cb_node, image_state, pRanges[i], imageLayout, "vkCmdClearDepthStencilImage()");
Mark Lobodzinski1241a312017-02-01 10:57:21 -07001167 // Image aspect must be depth or stencil or both
1168 if (((pRanges[i].aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) != VK_IMAGE_ASPECT_DEPTH_BIT) &&
1169 ((pRanges[i].aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) != VK_IMAGE_ASPECT_STENCIL_BIT)) {
1170 char const str[] =
Dave Houltona9df0ce2018-02-07 10:51:23 -07001171 "vkCmdClearDepthStencilImage aspectMasks for all subresource ranges must be set to VK_IMAGE_ASPECT_DEPTH_BIT "
1172 "and/or VK_IMAGE_ASPECT_STENCIL_BIT";
Mark Lobodzinski1241a312017-02-01 10:57:21 -07001173 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06001174 HandleToUint64(commandBuffer), DRAWSTATE_INVALID_IMAGE_ASPECT, str);
Mark Lobodzinski1241a312017-02-01 10:57:21 -07001175 }
1176 }
Dave Houlton1d2022c2017-03-29 11:43:58 -06001177 if (image_state && !FormatIsDepthOrStencil(image_state->createInfo.format)) {
Mark Lobodzinski1241a312017-02-01 10:57:21 -07001178 char const str[] = "vkCmdClearDepthStencilImage called without a depth/stencil image.";
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001179 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06001180 HandleToUint64(image), VALIDATION_ERROR_18a0001c, "%s.", str);
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001181 }
Tobin Ehlis4af8c242017-11-30 13:47:11 -07001182 if (VK_IMAGE_USAGE_TRANSFER_DST_BIT != (VK_IMAGE_USAGE_TRANSFER_DST_BIT & image_state->createInfo.usage)) {
1183 char const str[] =
1184 "vkCmdClearDepthStencilImage() called with an image that was not created with the VK_IMAGE_USAGE_TRANSFER_DST_BIT "
1185 "set.";
1186 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06001187 HandleToUint64(image), VALIDATION_ERROR_18a00012, "%s.", str);
Tobin Ehlis4af8c242017-11-30 13:47:11 -07001188 }
1189 VkFormatProperties props = GetFormatProperties(device_data, image_state->createInfo.format);
1190 VkImageTiling tiling = image_state->createInfo.tiling;
1191 VkFormatFeatureFlags flags = (tiling == VK_IMAGE_TILING_LINEAR ? props.linearTilingFeatures : props.optimalTilingFeatures);
1192 if ((GetDeviceExtensions(device_data)->vk_khr_maintenance1) &&
1193 (VK_FORMAT_FEATURE_TRANSFER_DST_BIT_KHR != (flags & VK_FORMAT_FEATURE_TRANSFER_DST_BIT_KHR))) {
Mark Lobodzinskib1fd9d12018-03-30 14:26:00 -06001194 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06001195 HandleToUint64(image), VALIDATION_ERROR_18a00010,
Mark Lobodzinskib1fd9d12018-03-30 14:26:00 -06001196 "vkCmdClearDepthStencilImage() called with an image of format %s and tiling %s that does not support "
1197 "VK_FORMAT_FEATURE_TRANSFER_DST_BIT_KHR.",
1198 string_VkFormat(image_state->createInfo.format), string_VkImageTiling(image_state->createInfo.tiling));
Tobin Ehlis4af8c242017-11-30 13:47:11 -07001199 }
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001200 }
1201 return skip;
1202}
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001203
1204// Returns true if [x, xoffset] and [y, yoffset] overlap
1205static bool RangesIntersect(int32_t start, uint32_t start_offset, int32_t end, uint32_t end_offset) {
1206 bool result = false;
1207 uint32_t intersection_min = std::max(static_cast<uint32_t>(start), static_cast<uint32_t>(end));
1208 uint32_t intersection_max = std::min(static_cast<uint32_t>(start) + start_offset, static_cast<uint32_t>(end) + end_offset);
1209
1210 if (intersection_max > intersection_min) {
1211 result = true;
1212 }
1213 return result;
1214}
1215
1216// Returns true if two VkImageCopy structures overlap
Dave Houltonf5217612018-02-02 16:18:52 -07001217static bool RegionIntersects(const VkImageCopy *src, const VkImageCopy *dst, VkImageType type, bool is_multiplane) {
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001218 bool result = false;
Dave Houltonf5217612018-02-02 16:18:52 -07001219
1220 if (is_multiplane && (src->srcSubresource.aspectMask != dst->dstSubresource.aspectMask)) {
1221 return result;
1222 }
1223
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001224 if ((src->srcSubresource.mipLevel == dst->dstSubresource.mipLevel) &&
1225 (RangesIntersect(src->srcSubresource.baseArrayLayer, src->srcSubresource.layerCount, dst->dstSubresource.baseArrayLayer,
1226 dst->dstSubresource.layerCount))) {
1227 result = true;
1228 switch (type) {
1229 case VK_IMAGE_TYPE_3D:
1230 result &= RangesIntersect(src->srcOffset.z, src->extent.depth, dst->dstOffset.z, dst->extent.depth);
1231 // Intentionally fall through to 2D case
1232 case VK_IMAGE_TYPE_2D:
1233 result &= RangesIntersect(src->srcOffset.y, src->extent.height, dst->dstOffset.y, dst->extent.height);
1234 // Intentionally fall through to 1D case
1235 case VK_IMAGE_TYPE_1D:
1236 result &= RangesIntersect(src->srcOffset.x, src->extent.width, dst->dstOffset.x, dst->extent.width);
1237 break;
1238 default:
1239 // Unrecognized or new IMAGE_TYPE enums will be caught in parameter_validation
1240 assert(false);
1241 }
1242 }
1243 return result;
1244}
1245
Dave Houltonfc1a4052017-04-27 14:32:45 -06001246// Returns non-zero if offset and extent exceed image extents
1247static const uint32_t x_bit = 1;
1248static const uint32_t y_bit = 2;
1249static const uint32_t z_bit = 4;
Dave Houlton1150cf52017-04-27 14:38:11 -06001250static uint32_t ExceedsBounds(const VkOffset3D *offset, const VkExtent3D *extent, const VkExtent3D *image_extent) {
Dave Houltonfc1a4052017-04-27 14:32:45 -06001251 uint32_t result = 0;
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001252 // Extents/depths cannot be negative but checks left in for clarity
Dave Houlton9dae7ec2017-03-01 16:23:25 -07001253 if ((offset->z + extent->depth > image_extent->depth) || (offset->z < 0) ||
1254 ((offset->z + static_cast<int32_t>(extent->depth)) < 0)) {
Dave Houltonfc1a4052017-04-27 14:32:45 -06001255 result |= z_bit;
Dave Houlton9dae7ec2017-03-01 16:23:25 -07001256 }
1257 if ((offset->y + extent->height > image_extent->height) || (offset->y < 0) ||
1258 ((offset->y + static_cast<int32_t>(extent->height)) < 0)) {
Dave Houltonfc1a4052017-04-27 14:32:45 -06001259 result |= y_bit;
Dave Houlton9dae7ec2017-03-01 16:23:25 -07001260 }
1261 if ((offset->x + extent->width > image_extent->width) || (offset->x < 0) ||
1262 ((offset->x + static_cast<int32_t>(extent->width)) < 0)) {
Dave Houltonfc1a4052017-04-27 14:32:45 -06001263 result |= x_bit;
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001264 }
1265 return result;
1266}
1267
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001268// Test if two VkExtent3D structs are equivalent
1269static inline bool IsExtentEqual(const VkExtent3D *extent, const VkExtent3D *other_extent) {
1270 bool result = true;
1271 if ((extent->width != other_extent->width) || (extent->height != other_extent->height) ||
1272 (extent->depth != other_extent->depth)) {
1273 result = false;
1274 }
1275 return result;
1276}
1277
Dave Houltonee281a52017-12-08 13:51:02 -07001278// For image copies between compressed/uncompressed formats, the extent is provided in source image texels
1279// Destination image texel extents must be adjusted by block size for the dest validation checks
1280VkExtent3D GetAdjustedDestImageExtent(VkFormat src_format, VkFormat dst_format, VkExtent3D extent) {
1281 VkExtent3D adjusted_extent = extent;
1282 if ((FormatIsCompressed(src_format) && (!FormatIsCompressed(dst_format)))) {
1283 VkExtent3D block_size = FormatCompressedTexelBlockExtent(src_format);
1284 adjusted_extent.width /= block_size.width;
1285 adjusted_extent.height /= block_size.height;
1286 adjusted_extent.depth /= block_size.depth;
1287 } else if ((!FormatIsCompressed(src_format) && (FormatIsCompressed(dst_format)))) {
1288 VkExtent3D block_size = FormatCompressedTexelBlockExtent(dst_format);
1289 adjusted_extent.width *= block_size.width;
1290 adjusted_extent.height *= block_size.height;
1291 adjusted_extent.depth *= block_size.depth;
1292 }
1293 return adjusted_extent;
1294}
1295
Dave Houlton6f9059e2017-05-02 17:15:13 -06001296// Returns the effective extent of an image subresource, adjusted for mip level and array depth.
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001297static inline VkExtent3D GetImageSubresourceExtent(const IMAGE_STATE *img, const VkImageSubresourceLayers *subresource) {
1298 const uint32_t mip = subresource->mipLevel;
Dave Houltonfc1a4052017-04-27 14:32:45 -06001299
1300 // Return zero extent if mip level doesn't exist
Dave Houlton1150cf52017-04-27 14:38:11 -06001301 if (mip >= img->createInfo.mipLevels) {
1302 return VkExtent3D{0, 0, 0};
Dave Houltonfc1a4052017-04-27 14:32:45 -06001303 }
Dave Houlton1150cf52017-04-27 14:38:11 -06001304
Dave Houlton9dae7ec2017-03-01 16:23:25 -07001305 // Don't allow mip adjustment to create 0 dim, but pass along a 0 if that's what subresource specified
Dave Houltonfc1a4052017-04-27 14:32:45 -06001306 VkExtent3D extent = img->createInfo.extent;
Dave Houlton9dae7ec2017-03-01 16:23:25 -07001307 extent.width = (0 == extent.width ? 0 : std::max(1U, extent.width >> mip));
1308 extent.height = (0 == extent.height ? 0 : std::max(1U, extent.height >> mip));
1309 extent.depth = (0 == extent.depth ? 0 : std::max(1U, extent.depth >> mip));
Dave Houltonfc1a4052017-04-27 14:32:45 -06001310
Dave Houlton6f9059e2017-05-02 17:15:13 -06001311 // Image arrays have an effective z extent that isn't diminished by mip level
1312 if (VK_IMAGE_TYPE_3D != img->createInfo.imageType) {
Dave Houltonfc1a4052017-04-27 14:32:45 -06001313 extent.depth = img->createInfo.arrayLayers;
1314 }
1315
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001316 return extent;
1317}
1318
1319// Test if the extent argument has all dimensions set to 0.
Dave Houlton9dae7ec2017-03-01 16:23:25 -07001320static inline bool IsExtentAllZeroes(const VkExtent3D *extent) {
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001321 return ((extent->width == 0) && (extent->height == 0) && (extent->depth == 0));
1322}
1323
Dave Houlton9dae7ec2017-03-01 16:23:25 -07001324// Test if the extent argument has any dimensions set to 0.
1325static inline bool IsExtentSizeZero(const VkExtent3D *extent) {
1326 return ((extent->width == 0) || (extent->height == 0) || (extent->depth == 0));
1327}
1328
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001329// Returns the image transfer granularity for a specific image scaled by compressed block size if necessary.
1330static inline VkExtent3D GetScaledItg(layer_data *device_data, const GLOBAL_CB_NODE *cb_node, const IMAGE_STATE *img) {
1331 // Default to (0, 0, 0) granularity in case we can't find the real granularity for the physical device.
1332 VkExtent3D granularity = {0, 0, 0};
1333 auto pPool = GetCommandPoolNode(device_data, cb_node->createInfo.commandPool);
1334 if (pPool) {
1335 granularity =
1336 GetPhysDevProperties(device_data)->queue_family_properties[pPool->queueFamilyIndex].minImageTransferGranularity;
Dave Houlton1d2022c2017-03-29 11:43:58 -06001337 if (FormatIsCompressed(img->createInfo.format)) {
1338 auto block_size = FormatCompressedTexelBlockExtent(img->createInfo.format);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001339 granularity.width *= block_size.width;
1340 granularity.height *= block_size.height;
1341 }
1342 }
1343 return granularity;
1344}
1345
1346// Test elements of a VkExtent3D structure against alignment constraints contained in another VkExtent3D structure
1347static inline bool IsExtentAligned(const VkExtent3D *extent, const VkExtent3D *granularity) {
1348 bool valid = true;
Dave Houlton1d2022c2017-03-29 11:43:58 -06001349 if ((SafeModulo(extent->depth, granularity->depth) != 0) || (SafeModulo(extent->width, granularity->width) != 0) ||
1350 (SafeModulo(extent->height, granularity->height) != 0)) {
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001351 valid = false;
1352 }
1353 return valid;
1354}
1355
1356// Check elements of a VkOffset3D structure against a queue family's Image Transfer Granularity values
1357static inline bool CheckItgOffset(layer_data *device_data, const GLOBAL_CB_NODE *cb_node, const VkOffset3D *offset,
1358 const VkExtent3D *granularity, const uint32_t i, const char *function, const char *member) {
1359 const debug_report_data *report_data = core_validation::GetReportData(device_data);
1360 bool skip = false;
1361 VkExtent3D offset_extent = {};
1362 offset_extent.width = static_cast<uint32_t>(abs(offset->x));
1363 offset_extent.height = static_cast<uint32_t>(abs(offset->y));
1364 offset_extent.depth = static_cast<uint32_t>(abs(offset->z));
Dave Houlton9dae7ec2017-03-01 16:23:25 -07001365 if (IsExtentAllZeroes(granularity)) {
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001366 // If the queue family image transfer granularity is (0, 0, 0), then the offset must always be (0, 0, 0)
Dave Houlton9dae7ec2017-03-01 16:23:25 -07001367 if (IsExtentAllZeroes(&offset_extent) == false) {
Petr Krausbc7f5442017-05-14 23:43:38 +02001368 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06001369 HandleToUint64(cb_node->commandBuffer), DRAWSTATE_IMAGE_TRANSFER_GRANULARITY,
Dave Houltona9df0ce2018-02-07 10:51:23 -07001370 "%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 "
1371 "image transfer granularity is (w=0, h=0, d=0).",
Petr Krausbc7f5442017-05-14 23:43:38 +02001372 function, i, member, offset->x, offset->y, offset->z);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001373 }
1374 } else {
1375 // If the queue family image transfer granularity is not (0, 0, 0), then the offset dimensions must always be even
1376 // integer multiples of the image transfer granularity.
1377 if (IsExtentAligned(&offset_extent, granularity) == false) {
Petr Krausbc7f5442017-05-14 23:43:38 +02001378 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06001379 HandleToUint64(cb_node->commandBuffer), DRAWSTATE_IMAGE_TRANSFER_GRANULARITY,
Dave Houltona9df0ce2018-02-07 10:51:23 -07001380 "%s: pRegion[%d].%s (x=%d, y=%d, z=%d) dimensions must be even integer multiples of this command "
1381 "buffer's queue family image transfer granularity (w=%d, h=%d, d=%d).",
Petr Krausbc7f5442017-05-14 23:43:38 +02001382 function, i, member, offset->x, offset->y, offset->z, granularity->width, granularity->height,
1383 granularity->depth);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001384 }
1385 }
1386 return skip;
1387}
1388
1389// Check elements of a VkExtent3D structure against a queue family's Image Transfer Granularity values
1390static inline bool CheckItgExtent(layer_data *device_data, const GLOBAL_CB_NODE *cb_node, const VkExtent3D *extent,
1391 const VkOffset3D *offset, const VkExtent3D *granularity, const VkExtent3D *subresource_extent,
Mark Lobodzinski283ade62017-10-09 16:36:49 -06001392 const VkImageType image_type, const uint32_t i, const char *function, const char *member) {
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001393 const debug_report_data *report_data = core_validation::GetReportData(device_data);
1394 bool skip = false;
Dave Houlton9dae7ec2017-03-01 16:23:25 -07001395 if (IsExtentAllZeroes(granularity)) {
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001396 // If the queue family image transfer granularity is (0, 0, 0), then the extent must always match the image
1397 // subresource extent.
1398 if (IsExtentEqual(extent, subresource_extent) == false) {
Petr Krausbc7f5442017-05-14 23:43:38 +02001399 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06001400 HandleToUint64(cb_node->commandBuffer), DRAWSTATE_IMAGE_TRANSFER_GRANULARITY,
Petr Krausbc7f5442017-05-14 23:43:38 +02001401 "%s: pRegion[%d].%s (w=%d, h=%d, d=%d) must match the image subresource extents (w=%d, h=%d, d=%d) "
1402 "when the command buffer's queue family image transfer granularity is (w=0, h=0, d=0).",
1403 function, i, member, extent->width, extent->height, extent->depth, subresource_extent->width,
1404 subresource_extent->height, subresource_extent->depth);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001405 }
1406 } else {
1407 // If the queue family image transfer granularity is not (0, 0, 0), then the extent dimensions must always be even
1408 // integer multiples of the image transfer granularity or the offset + extent dimensions must always match the image
1409 // subresource extent dimensions.
1410 VkExtent3D offset_extent_sum = {};
1411 offset_extent_sum.width = static_cast<uint32_t>(abs(offset->x)) + extent->width;
1412 offset_extent_sum.height = static_cast<uint32_t>(abs(offset->y)) + extent->height;
1413 offset_extent_sum.depth = static_cast<uint32_t>(abs(offset->z)) + extent->depth;
Mark Lobodzinski283ade62017-10-09 16:36:49 -06001414 bool x_ok = true;
1415 bool y_ok = true;
1416 bool z_ok = true;
1417 switch (image_type) {
1418 case VK_IMAGE_TYPE_3D:
1419 z_ok = ((0 == SafeModulo(extent->depth, granularity->depth)) ||
1420 (subresource_extent->depth == offset_extent_sum.depth));
1421 // Intentionally fall through to 2D case
1422 case VK_IMAGE_TYPE_2D:
1423 y_ok = ((0 == SafeModulo(extent->height, granularity->height)) ||
1424 (subresource_extent->height == offset_extent_sum.height));
1425 // Intentionally fall through to 1D case
1426 case VK_IMAGE_TYPE_1D:
1427 x_ok = ((0 == SafeModulo(extent->width, granularity->width)) ||
1428 (subresource_extent->width == offset_extent_sum.width));
1429 break;
1430 default:
1431 // Unrecognized or new IMAGE_TYPE enums will be caught in parameter_validation
1432 assert(false);
1433 }
Dave Houlton6f9059e2017-05-02 17:15:13 -06001434 if (!(x_ok && y_ok && z_ok)) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07001435 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06001436 HandleToUint64(cb_node->commandBuffer), DRAWSTATE_IMAGE_TRANSFER_GRANULARITY,
Dave Houltona9df0ce2018-02-07 10:51:23 -07001437 "%s: pRegion[%d].%s (w=%d, h=%d, d=%d) dimensions must be even integer multiples of this command "
1438 "buffer's queue family image transfer granularity (w=%d, h=%d, d=%d) or offset (x=%d, y=%d, z=%d) + "
1439 "extent (w=%d, h=%d, d=%d) must match the image subresource extents (w=%d, h=%d, d=%d).",
1440 function, i, member, extent->width, extent->height, extent->depth, granularity->width,
1441 granularity->height, granularity->depth, offset->x, offset->y, offset->z, extent->width, extent->height,
1442 extent->depth, subresource_extent->width, subresource_extent->height, subresource_extent->depth);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001443 }
1444 }
1445 return skip;
1446}
1447
Mark Lobodzinskibf0042d2018-02-26 16:01:22 -07001448// Check valid usage Image Transfer Granularity requirements for elements of a VkBufferImageCopy structure
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001449bool ValidateCopyBufferImageTransferGranularityRequirements(layer_data *device_data, const GLOBAL_CB_NODE *cb_node,
1450 const IMAGE_STATE *img, const VkBufferImageCopy *region,
1451 const uint32_t i, const char *function) {
1452 bool skip = false;
Dave Houlton1d2022c2017-03-29 11:43:58 -06001453 if (FormatIsCompressed(img->createInfo.format) == true) {
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001454 // TODO: Add granularity checking for compressed formats
1455
1456 // bufferRowLength must be a multiple of the compressed texel block width
1457 // bufferImageHeight must be a multiple of the compressed texel block height
1458 // all members of imageOffset must be a multiple of the corresponding dimensions of the compressed texel block
1459 // bufferOffset must be a multiple of the compressed texel block size in bytes
1460 // imageExtent.width must be a multiple of the compressed texel block width or (imageExtent.width + imageOffset.x)
1461 // must equal the image subresource width
1462 // imageExtent.height must be a multiple of the compressed texel block height or (imageExtent.height + imageOffset.y)
1463 // must equal the image subresource height
1464 // imageExtent.depth must be a multiple of the compressed texel block depth or (imageExtent.depth + imageOffset.z)
1465 // must equal the image subresource depth
1466 } else {
1467 VkExtent3D granularity = GetScaledItg(device_data, cb_node, img);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001468 skip |= CheckItgOffset(device_data, cb_node, &region->imageOffset, &granularity, i, function, "imageOffset");
1469 VkExtent3D subresource_extent = GetImageSubresourceExtent(img, &region->imageSubresource);
1470 skip |= CheckItgExtent(device_data, cb_node, &region->imageExtent, &region->imageOffset, &granularity, &subresource_extent,
Mark Lobodzinski283ade62017-10-09 16:36:49 -06001471 img->createInfo.imageType, i, function, "imageExtent");
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001472 }
1473 return skip;
1474}
1475
Mark Lobodzinskibf0042d2018-02-26 16:01:22 -07001476// Check valid usage Image Transfer Granularity requirements for elements of a VkImageCopy structure
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001477bool ValidateCopyImageTransferGranularityRequirements(layer_data *device_data, const GLOBAL_CB_NODE *cb_node,
Dave Houlton6f9059e2017-05-02 17:15:13 -06001478 const IMAGE_STATE *src_img, const IMAGE_STATE *dst_img,
1479 const VkImageCopy *region, const uint32_t i, const char *function) {
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001480 bool skip = false;
Mark Lobodzinskid0788802017-10-19 15:38:59 -06001481 // Source image checks
Dave Houlton6f9059e2017-05-02 17:15:13 -06001482 VkExtent3D granularity = GetScaledItg(device_data, cb_node, src_img);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001483 skip |= CheckItgOffset(device_data, cb_node, &region->srcOffset, &granularity, i, function, "srcOffset");
Dave Houlton6f9059e2017-05-02 17:15:13 -06001484 VkExtent3D subresource_extent = GetImageSubresourceExtent(src_img, &region->srcSubresource);
Dave Houlton94a00372017-12-14 15:08:47 -07001485 const VkExtent3D extent = region->extent;
Mark Lobodzinskid0788802017-10-19 15:38:59 -06001486 skip |= CheckItgExtent(device_data, cb_node, &extent, &region->srcOffset, &granularity, &subresource_extent,
Mark Lobodzinski283ade62017-10-09 16:36:49 -06001487 src_img->createInfo.imageType, i, function, "extent");
Dave Houlton6f9059e2017-05-02 17:15:13 -06001488
Mark Lobodzinskid0788802017-10-19 15:38:59 -06001489 // Destination image checks
Dave Houlton6f9059e2017-05-02 17:15:13 -06001490 granularity = GetScaledItg(device_data, cb_node, dst_img);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001491 skip |= CheckItgOffset(device_data, cb_node, &region->dstOffset, &granularity, i, function, "dstOffset");
Dave Houltonee281a52017-12-08 13:51:02 -07001492 // Adjust dest extent, if necessary
Dave Houlton94a00372017-12-14 15:08:47 -07001493 const VkExtent3D dest_effective_extent =
1494 GetAdjustedDestImageExtent(src_img->createInfo.format, dst_img->createInfo.format, extent);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001495 subresource_extent = GetImageSubresourceExtent(dst_img, &region->dstSubresource);
Dave Houltonee281a52017-12-08 13:51:02 -07001496 skip |= CheckItgExtent(device_data, cb_node, &dest_effective_extent, &region->dstOffset, &granularity, &subresource_extent,
Mark Lobodzinski283ade62017-10-09 16:36:49 -06001497 dst_img->createInfo.imageType, i, function, "extent");
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001498 return skip;
1499}
1500
Dave Houlton6f9059e2017-05-02 17:15:13 -06001501// Validate contents of a VkImageCopy struct
1502bool ValidateImageCopyData(const layer_data *device_data, const debug_report_data *report_data, const uint32_t regionCount,
1503 const VkImageCopy *ic_regions, const IMAGE_STATE *src_state, const IMAGE_STATE *dst_state) {
1504 bool skip = false;
1505
1506 for (uint32_t i = 0; i < regionCount; i++) {
Dave Houlton94a00372017-12-14 15:08:47 -07001507 const VkImageCopy region = ic_regions[i];
Dave Houltonee281a52017-12-08 13:51:02 -07001508
1509 // For comp<->uncomp copies, the copy extent for the dest image must be adjusted
Dave Houlton94a00372017-12-14 15:08:47 -07001510 const VkExtent3D src_copy_extent = region.extent;
1511 const VkExtent3D dst_copy_extent =
Dave Houltonee281a52017-12-08 13:51:02 -07001512 GetAdjustedDestImageExtent(src_state->createInfo.format, dst_state->createInfo.format, region.extent);
1513
Dave Houlton6f9059e2017-05-02 17:15:13 -06001514 bool slice_override = false;
1515 uint32_t depth_slices = 0;
1516
1517 // Special case for copying between a 1D/2D array and a 3D image
1518 // TBD: This seems like the only way to reconcile 3 mutually-exclusive VU checks for 2D/3D copies. Heads up.
1519 if ((VK_IMAGE_TYPE_3D == src_state->createInfo.imageType) && (VK_IMAGE_TYPE_3D != dst_state->createInfo.imageType)) {
Dave Houltonee281a52017-12-08 13:51:02 -07001520 depth_slices = region.dstSubresource.layerCount; // Slice count from 2D subresource
Dave Houlton6f9059e2017-05-02 17:15:13 -06001521 slice_override = (depth_slices != 1);
1522 } else if ((VK_IMAGE_TYPE_3D == dst_state->createInfo.imageType) && (VK_IMAGE_TYPE_3D != src_state->createInfo.imageType)) {
Dave Houltonee281a52017-12-08 13:51:02 -07001523 depth_slices = region.srcSubresource.layerCount; // Slice count from 2D subresource
Dave Houlton6f9059e2017-05-02 17:15:13 -06001524 slice_override = (depth_slices != 1);
1525 }
1526
1527 // Do all checks on source image
1528 //
1529 if (src_state->createInfo.imageType == VK_IMAGE_TYPE_1D) {
Dave Houltonee281a52017-12-08 13:51:02 -07001530 if ((0 != region.srcOffset.y) || (1 != src_copy_extent.height)) {
1531 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06001532 HandleToUint64(src_state->image), VALIDATION_ERROR_09c00124,
Dave Houltonee281a52017-12-08 13:51:02 -07001533 "vkCmdCopyImage(): pRegion[%d] srcOffset.y is %d and extent.height is %d. For 1D images these must "
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06001534 "be 0 and 1, respectively.",
1535 i, region.srcOffset.y, src_copy_extent.height);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001536 }
1537 }
1538
Dave Houlton533be9f2018-03-26 17:08:30 -06001539 // VUID-VkImageCopy-srcImage-01785
1540 if ((src_state->createInfo.imageType == VK_IMAGE_TYPE_1D) && ((0 != region.srcOffset.z) || (1 != src_copy_extent.depth))) {
1541 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06001542 HandleToUint64(src_state->image), VALIDATION_ERROR_09c00df2,
Dave Houlton533be9f2018-03-26 17:08:30 -06001543 "vkCmdCopyImage(): pRegion[%d] srcOffset.z is %d and extent.depth is %d. For 1D images "
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06001544 "these must be 0 and 1, respectively.",
1545 i, region.srcOffset.z, src_copy_extent.depth);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001546 }
1547
Dave Houlton533be9f2018-03-26 17:08:30 -06001548 // VUID-VkImageCopy-srcImage-01787
1549 if ((src_state->createInfo.imageType == VK_IMAGE_TYPE_2D) && (0 != region.srcOffset.z)) {
1550 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06001551 HandleToUint64(src_state->image), VALIDATION_ERROR_09c00df6,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06001552 "vkCmdCopyImage(): pRegion[%d] srcOffset.z is %d. For 2D images the z-offset must be 0.", i,
1553 region.srcOffset.z);
Dave Houlton533be9f2018-03-26 17:08:30 -06001554 }
1555
Mark Lobodzinski28426ae2017-06-01 07:56:38 -06001556 if (GetDeviceExtensions(device_data)->vk_khr_maintenance1) {
Dave Houlton6f9059e2017-05-02 17:15:13 -06001557 if (src_state->createInfo.imageType == VK_IMAGE_TYPE_3D) {
Dave Houltonee281a52017-12-08 13:51:02 -07001558 if ((0 != region.srcSubresource.baseArrayLayer) || (1 != region.srcSubresource.layerCount)) {
Dave Houlton6f9059e2017-05-02 17:15:13 -06001559 skip |=
1560 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06001561 HandleToUint64(src_state->image), VALIDATION_ERROR_09c0011a,
Dave Houlton6f9059e2017-05-02 17:15:13 -06001562 "vkCmdCopyImage(): pRegion[%d] srcSubresource.baseArrayLayer is %d and srcSubresource.layerCount "
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06001563 "is %d. For VK_IMAGE_TYPE_3D images these must be 0 and 1, respectively.",
1564 i, region.srcSubresource.baseArrayLayer, region.srcSubresource.layerCount);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001565 }
1566 }
1567 } else { // Pre maint 1
1568 if (src_state->createInfo.imageType == VK_IMAGE_TYPE_3D || dst_state->createInfo.imageType == VK_IMAGE_TYPE_3D) {
Dave Houltonee281a52017-12-08 13:51:02 -07001569 if ((0 != region.srcSubresource.baseArrayLayer) || (1 != region.srcSubresource.layerCount)) {
Petr Kraus13c98a62017-12-09 00:22:39 +01001570 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06001571 HandleToUint64(src_state->image), VALIDATION_ERROR_09c0011a,
Petr Kraus13c98a62017-12-09 00:22:39 +01001572 "vkCmdCopyImage(): pRegion[%d] srcSubresource.baseArrayLayer is %d and "
1573 "srcSubresource.layerCount is %d. For copies with either source or dest of type "
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06001574 "VK_IMAGE_TYPE_3D, these must be 0 and 1, respectively.",
1575 i, region.srcSubresource.baseArrayLayer, region.srcSubresource.layerCount);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001576 }
1577 }
1578 }
1579
Dave Houlton6f9059e2017-05-02 17:15:13 -06001580 // Checks that apply only to compressed images
1581 if (FormatIsCompressed(src_state->createInfo.format)) {
Dave Houlton94a00372017-12-14 15:08:47 -07001582 const VkExtent3D block_size = FormatCompressedTexelBlockExtent(src_state->createInfo.format);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001583
1584 // image offsets must be multiples of block dimensions
Dave Houltonee281a52017-12-08 13:51:02 -07001585 if ((SafeModulo(region.srcOffset.x, block_size.width) != 0) ||
1586 (SafeModulo(region.srcOffset.y, block_size.height) != 0) ||
1587 (SafeModulo(region.srcOffset.z, block_size.depth) != 0)) {
Dave Houlton6f9059e2017-05-02 17:15:13 -06001588 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06001589 HandleToUint64(src_state->image), VALIDATION_ERROR_09c0013a,
Dave Houlton6f9059e2017-05-02 17:15:13 -06001590 "vkCmdCopyImage(): pRegion[%d] srcOffset (%d, %d) must be multiples of the compressed image's "
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06001591 "texel width & height (%d, %d)..",
1592 i, region.srcOffset.x, region.srcOffset.y, block_size.width, block_size.height);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001593 }
1594
Dave Houlton94a00372017-12-14 15:08:47 -07001595 const VkExtent3D mip_extent = GetImageSubresourceExtent(src_state, &(region.srcSubresource));
Dave Houltonee281a52017-12-08 13:51:02 -07001596 if ((SafeModulo(src_copy_extent.width, block_size.width) != 0) &&
1597 (src_copy_extent.width + region.srcOffset.x != mip_extent.width)) {
Dave Houlton6f9059e2017-05-02 17:15:13 -06001598 skip |=
1599 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06001600 HandleToUint64(src_state->image), VALIDATION_ERROR_09c0013c,
Dave Houlton6f9059e2017-05-02 17:15:13 -06001601 "vkCmdCopyImage(): pRegion[%d] extent width (%d) must be a multiple of the compressed texture block "
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06001602 "width (%d), or when added to srcOffset.x (%d) must equal the image subresource width (%d)..",
1603 i, src_copy_extent.width, block_size.width, region.srcOffset.x, mip_extent.width);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001604 }
1605
Mark Lobodzinskid0788802017-10-19 15:38:59 -06001606 // Extent height must be a multiple of block height, or extent+offset height must equal subresource height
Dave Houltonee281a52017-12-08 13:51:02 -07001607 if ((SafeModulo(src_copy_extent.height, block_size.height) != 0) &&
1608 (src_copy_extent.height + region.srcOffset.y != mip_extent.height)) {
Dave Houlton6f9059e2017-05-02 17:15:13 -06001609 skip |=
1610 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06001611 HandleToUint64(src_state->image), VALIDATION_ERROR_09c0013e,
Dave Houlton6f9059e2017-05-02 17:15:13 -06001612 "vkCmdCopyImage(): pRegion[%d] extent height (%d) must be a multiple of the compressed texture block "
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06001613 "height (%d), or when added to srcOffset.y (%d) must equal the image subresource height (%d)..",
1614 i, src_copy_extent.height, block_size.height, region.srcOffset.y, mip_extent.height);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001615 }
1616
Mark Lobodzinskid0788802017-10-19 15:38:59 -06001617 // Extent depth must be a multiple of block depth, or extent+offset depth must equal subresource depth
Dave Houltonee281a52017-12-08 13:51:02 -07001618 uint32_t copy_depth = (slice_override ? depth_slices : src_copy_extent.depth);
1619 if ((SafeModulo(copy_depth, block_size.depth) != 0) && (copy_depth + region.srcOffset.z != mip_extent.depth)) {
Dave Houlton6f9059e2017-05-02 17:15:13 -06001620 skip |=
1621 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06001622 HandleToUint64(src_state->image), VALIDATION_ERROR_09c00140,
Dave Houlton6f9059e2017-05-02 17:15:13 -06001623 "vkCmdCopyImage(): pRegion[%d] extent width (%d) must be a multiple of the compressed texture block "
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06001624 "depth (%d), or when added to srcOffset.z (%d) must equal the image subresource depth (%d)..",
1625 i, src_copy_extent.depth, block_size.depth, region.srcOffset.z, mip_extent.depth);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001626 }
1627 } // Compressed
1628
1629 // Do all checks on dest image
1630 //
1631 if (dst_state->createInfo.imageType == VK_IMAGE_TYPE_1D) {
Dave Houltonee281a52017-12-08 13:51:02 -07001632 if ((0 != region.dstOffset.y) || (1 != dst_copy_extent.height)) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07001633 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06001634 HandleToUint64(dst_state->image), VALIDATION_ERROR_09c00130,
Dave Houltona9df0ce2018-02-07 10:51:23 -07001635 "vkCmdCopyImage(): pRegion[%d] dstOffset.y is %d and dst_copy_extent.height is %d. For 1D images "
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06001636 "these must be 0 and 1, respectively.",
1637 i, region.dstOffset.y, dst_copy_extent.height);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001638 }
1639 }
1640
Dave Houlton533be9f2018-03-26 17:08:30 -06001641 // VUID-VkImageCopy-dstImage-01786
1642 if ((dst_state->createInfo.imageType == VK_IMAGE_TYPE_1D) && ((0 != region.dstOffset.z) || (1 != dst_copy_extent.depth))) {
1643 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06001644 HandleToUint64(dst_state->image), VALIDATION_ERROR_09c00df4,
Dave Houlton533be9f2018-03-26 17:08:30 -06001645 "vkCmdCopyImage(): pRegion[%d] dstOffset.z is %d and extent.depth is %d. For 1D images these must be 0 "
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06001646 "and 1, respectively.",
1647 i, region.dstOffset.z, dst_copy_extent.depth);
Dave Houlton533be9f2018-03-26 17:08:30 -06001648 }
1649
1650 // VUID-VkImageCopy-dstImage-01788
1651 if ((dst_state->createInfo.imageType == VK_IMAGE_TYPE_2D) && (0 != region.dstOffset.z)) {
1652 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06001653 HandleToUint64(dst_state->image), VALIDATION_ERROR_09c00df8,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06001654 "vkCmdCopyImage(): pRegion[%d] dstOffset.z is %d. For 2D images the z-offset must be 0.", i,
1655 region.dstOffset.z);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001656 }
1657
1658 if (dst_state->createInfo.imageType == VK_IMAGE_TYPE_3D) {
Dave Houltonee281a52017-12-08 13:51:02 -07001659 if ((0 != region.dstSubresource.baseArrayLayer) || (1 != region.dstSubresource.layerCount)) {
Dave Houlton6f9059e2017-05-02 17:15:13 -06001660 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06001661 HandleToUint64(dst_state->image), VALIDATION_ERROR_09c0011a,
Dave Houlton6f9059e2017-05-02 17:15:13 -06001662 "vkCmdCopyImage(): pRegion[%d] dstSubresource.baseArrayLayer is %d and dstSubresource.layerCount "
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06001663 "is %d. For VK_IMAGE_TYPE_3D images these must be 0 and 1, respectively.",
1664 i, region.dstSubresource.baseArrayLayer, region.dstSubresource.layerCount);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001665 }
1666 }
1667 // VU01199 changed with mnt1
Mark Lobodzinski28426ae2017-06-01 07:56:38 -06001668 if (GetDeviceExtensions(device_data)->vk_khr_maintenance1) {
Dave Houlton6f9059e2017-05-02 17:15:13 -06001669 if (dst_state->createInfo.imageType == VK_IMAGE_TYPE_3D) {
Dave Houltonee281a52017-12-08 13:51:02 -07001670 if ((0 != region.dstSubresource.baseArrayLayer) || (1 != region.dstSubresource.layerCount)) {
Dave Houlton6f9059e2017-05-02 17:15:13 -06001671 skip |=
1672 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06001673 HandleToUint64(dst_state->image), VALIDATION_ERROR_09c0011a,
Dave Houlton6f9059e2017-05-02 17:15:13 -06001674 "vkCmdCopyImage(): pRegion[%d] dstSubresource.baseArrayLayer is %d and dstSubresource.layerCount "
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06001675 "is %d. For VK_IMAGE_TYPE_3D images these must be 0 and 1, respectively.",
1676 i, region.dstSubresource.baseArrayLayer, region.dstSubresource.layerCount);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001677 }
1678 }
1679 } else { // Pre maint 1
1680 if (src_state->createInfo.imageType == VK_IMAGE_TYPE_3D || dst_state->createInfo.imageType == VK_IMAGE_TYPE_3D) {
Dave Houltonee281a52017-12-08 13:51:02 -07001681 if ((0 != region.dstSubresource.baseArrayLayer) || (1 != region.dstSubresource.layerCount)) {
Petr Kraus13c98a62017-12-09 00:22:39 +01001682 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06001683 HandleToUint64(dst_state->image), VALIDATION_ERROR_09c0011a,
Petr Kraus13c98a62017-12-09 00:22:39 +01001684 "vkCmdCopyImage(): pRegion[%d] dstSubresource.baseArrayLayer is %d and "
1685 "dstSubresource.layerCount is %d. For copies with either source or dest of type "
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06001686 "VK_IMAGE_TYPE_3D, these must be 0 and 1, respectively.",
1687 i, region.dstSubresource.baseArrayLayer, region.dstSubresource.layerCount);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001688 }
1689 }
1690 }
1691
Dave Houlton6f9059e2017-05-02 17:15:13 -06001692 // Checks that apply only to compressed images
1693 if (FormatIsCompressed(dst_state->createInfo.format)) {
Dave Houlton94a00372017-12-14 15:08:47 -07001694 const VkExtent3D block_size = FormatCompressedTexelBlockExtent(dst_state->createInfo.format);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001695
1696 // image offsets must be multiples of block dimensions
Dave Houltonee281a52017-12-08 13:51:02 -07001697 if ((SafeModulo(region.dstOffset.x, block_size.width) != 0) ||
1698 (SafeModulo(region.dstOffset.y, block_size.height) != 0) ||
1699 (SafeModulo(region.dstOffset.z, block_size.depth) != 0)) {
Dave Houlton6f9059e2017-05-02 17:15:13 -06001700 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06001701 HandleToUint64(dst_state->image), VALIDATION_ERROR_09c00144,
Dave Houlton6f9059e2017-05-02 17:15:13 -06001702 "vkCmdCopyImage(): pRegion[%d] dstOffset (%d, %d) must be multiples of the compressed image's "
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06001703 "texel width & height (%d, %d)..",
1704 i, region.dstOffset.x, region.dstOffset.y, block_size.width, block_size.height);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001705 }
1706
Dave Houlton94a00372017-12-14 15:08:47 -07001707 const VkExtent3D mip_extent = GetImageSubresourceExtent(dst_state, &(region.dstSubresource));
Dave Houltonee281a52017-12-08 13:51:02 -07001708 if ((SafeModulo(dst_copy_extent.width, block_size.width) != 0) &&
1709 (dst_copy_extent.width + region.dstOffset.x != mip_extent.width)) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07001710 skip |=
1711 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06001712 HandleToUint64(dst_state->image), VALIDATION_ERROR_09c00146,
Dave Houltona9df0ce2018-02-07 10:51:23 -07001713 "vkCmdCopyImage(): pRegion[%d] dst_copy_extent width (%d) must be a multiple of the compressed texture "
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06001714 "block width (%d), or when added to dstOffset.x (%d) must equal the image subresource width (%d)..",
1715 i, dst_copy_extent.width, block_size.width, region.dstOffset.x, mip_extent.width);
Mark Lobodzinskid0788802017-10-19 15:38:59 -06001716 }
1717
Dave Houltonee281a52017-12-08 13:51:02 -07001718 // Extent height must be a multiple of block height, or dst_copy_extent+offset height must equal subresource height
1719 if ((SafeModulo(dst_copy_extent.height, block_size.height) != 0) &&
1720 (dst_copy_extent.height + region.dstOffset.y != mip_extent.height)) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07001721 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06001722 HandleToUint64(dst_state->image), VALIDATION_ERROR_09c00148,
Dave Houltona9df0ce2018-02-07 10:51:23 -07001723 "vkCmdCopyImage(): pRegion[%d] dst_copy_extent height (%d) must be a multiple of the compressed "
1724 "texture block height (%d), or when added to dstOffset.y (%d) must equal the image subresource "
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06001725 "height (%d)..",
1726 i, dst_copy_extent.height, block_size.height, region.dstOffset.y, mip_extent.height);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001727 }
1728
Dave Houltonee281a52017-12-08 13:51:02 -07001729 // Extent depth must be a multiple of block depth, or dst_copy_extent+offset depth must equal subresource depth
1730 uint32_t copy_depth = (slice_override ? depth_slices : dst_copy_extent.depth);
1731 if ((SafeModulo(copy_depth, block_size.depth) != 0) && (copy_depth + region.dstOffset.z != mip_extent.depth)) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07001732 skip |=
1733 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06001734 HandleToUint64(dst_state->image), VALIDATION_ERROR_09c0014a,
Dave Houltona9df0ce2018-02-07 10:51:23 -07001735 "vkCmdCopyImage(): pRegion[%d] dst_copy_extent width (%d) must be a multiple of the compressed texture "
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06001736 "block depth (%d), or when added to dstOffset.z (%d) must equal the image subresource depth (%d)..",
1737 i, dst_copy_extent.depth, block_size.depth, region.dstOffset.z, mip_extent.depth);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001738 }
1739 } // Compressed
1740 }
1741 return skip;
1742}
1743
Tobin Ehlis58c884f2017-02-08 12:15:27 -07001744bool PreCallValidateCmdCopyImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state,
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001745 IMAGE_STATE *dst_image_state, uint32_t region_count, const VkImageCopy *regions,
1746 VkImageLayout src_image_layout, VkImageLayout dst_image_layout) {
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001747 bool skip = false;
1748 const debug_report_data *report_data = core_validation::GetReportData(device_data);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001749 skip = ValidateImageCopyData(device_data, report_data, region_count, regions, src_image_state, dst_image_state);
1750
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001751 VkCommandBuffer command_buffer = cb_node->commandBuffer;
1752
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001753 for (uint32_t i = 0; i < region_count; i++) {
Dave Houlton94a00372017-12-14 15:08:47 -07001754 const VkImageCopy region = regions[i];
Dave Houltonee281a52017-12-08 13:51:02 -07001755
1756 // For comp/uncomp copies, the copy extent for the dest image must be adjusted
1757 VkExtent3D src_copy_extent = region.extent;
1758 VkExtent3D dst_copy_extent =
1759 GetAdjustedDestImageExtent(src_image_state->createInfo.format, dst_image_state->createInfo.format, region.extent);
1760
Dave Houlton6f9059e2017-05-02 17:15:13 -06001761 bool slice_override = false;
1762 uint32_t depth_slices = 0;
1763
1764 // Special case for copying between a 1D/2D array and a 3D image
1765 // TBD: This seems like the only way to reconcile 3 mutually-exclusive VU checks for 2D/3D copies. Heads up.
1766 if ((VK_IMAGE_TYPE_3D == src_image_state->createInfo.imageType) &&
1767 (VK_IMAGE_TYPE_3D != dst_image_state->createInfo.imageType)) {
Dave Houltonee281a52017-12-08 13:51:02 -07001768 depth_slices = region.dstSubresource.layerCount; // Slice count from 2D subresource
Dave Houlton6f9059e2017-05-02 17:15:13 -06001769 slice_override = (depth_slices != 1);
1770 } else if ((VK_IMAGE_TYPE_3D == dst_image_state->createInfo.imageType) &&
1771 (VK_IMAGE_TYPE_3D != src_image_state->createInfo.imageType)) {
Dave Houltonee281a52017-12-08 13:51:02 -07001772 depth_slices = region.srcSubresource.layerCount; // Slice count from 2D subresource
Dave Houlton6f9059e2017-05-02 17:15:13 -06001773 slice_override = (depth_slices != 1);
1774 }
1775
Dave Houltonee281a52017-12-08 13:51:02 -07001776 if (region.srcSubresource.layerCount == 0) {
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001777 std::stringstream ss;
1778 ss << "vkCmdCopyImage: number of layers in pRegions[" << i << "] srcSubresource is zero";
Mark Lobodzinskib1fd9d12018-03-30 14:26:00 -06001779 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06001780 HandleToUint64(command_buffer), DRAWSTATE_INVALID_IMAGE_ASPECT, "%s", ss.str().c_str());
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001781 }
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001782
Dave Houltonee281a52017-12-08 13:51:02 -07001783 if (region.dstSubresource.layerCount == 0) {
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001784 std::stringstream ss;
1785 ss << "vkCmdCopyImage: number of layers in pRegions[" << i << "] dstSubresource is zero";
Mark Lobodzinskib1fd9d12018-03-30 14:26:00 -06001786 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06001787 HandleToUint64(command_buffer), DRAWSTATE_INVALID_IMAGE_ASPECT, "%s", ss.str().c_str());
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001788 }
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001789
Mark Lobodzinski28426ae2017-06-01 07:56:38 -06001790 if (GetDeviceExtensions(device_data)->vk_khr_maintenance1) {
Dave Houlton6f9059e2017-05-02 17:15:13 -06001791 // No chance of mismatch if we're overriding depth slice count
1792 if (!slice_override) {
1793 // The number of depth slices in srcSubresource and dstSubresource must match
1794 // Depth comes from layerCount for 1D,2D resources, from extent.depth for 3D
1795 uint32_t src_slices =
Dave Houltonee281a52017-12-08 13:51:02 -07001796 (VK_IMAGE_TYPE_3D == src_image_state->createInfo.imageType ? src_copy_extent.depth
1797 : region.srcSubresource.layerCount);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001798 uint32_t dst_slices =
Dave Houltonee281a52017-12-08 13:51:02 -07001799 (VK_IMAGE_TYPE_3D == dst_image_state->createInfo.imageType ? dst_copy_extent.depth
1800 : region.dstSubresource.layerCount);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001801 if (src_slices != dst_slices) {
1802 std::stringstream ss;
1803 ss << "vkCmdCopyImage: number of depth slices in source and destination subresources for pRegions[" << i
1804 << "] do not match";
1805 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06001806 HandleToUint64(command_buffer), VALIDATION_ERROR_09c00118, "%s.", ss.str().c_str());
Dave Houlton6f9059e2017-05-02 17:15:13 -06001807 }
1808 }
1809 } else {
Mike Schuchardt64b5bb72017-03-21 16:33:26 -06001810 // For each region the layerCount member of srcSubresource and dstSubresource must match
Dave Houltonee281a52017-12-08 13:51:02 -07001811 if (region.srcSubresource.layerCount != region.dstSubresource.layerCount) {
Mike Schuchardt64b5bb72017-03-21 16:33:26 -06001812 std::stringstream ss;
1813 ss << "vkCmdCopyImage: number of layers in source and destination subresources for pRegions[" << i
1814 << "] do not match";
Mark Lobodzinskib1fd9d12018-03-30 14:26:00 -06001815 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06001816 HandleToUint64(command_buffer), VALIDATION_ERROR_09c00118, "%s.", ss.str().c_str());
Mike Schuchardt64b5bb72017-03-21 16:33:26 -06001817 }
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001818 }
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001819
Dave Houltonf5217612018-02-02 16:18:52 -07001820 if (!GetDeviceExtensions(device_data)->vk_khr_sampler_ycbcr_conversion) {
1821 // not multi-plane, the aspectMask member of srcSubresource and dstSubresource must match
1822 if (region.srcSubresource.aspectMask != region.dstSubresource.aspectMask) {
1823 char const str[] = "vkCmdCopyImage: Src and dest aspectMasks for each region must match";
1824 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06001825 HandleToUint64(command_buffer), VALIDATION_ERROR_09c00112, "%s.", str);
Dave Houltonf5217612018-02-02 16:18:52 -07001826 }
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001827 }
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001828
Dave Houlton4eaaf3a2017-03-14 11:31:20 -06001829 // For each region, the aspectMask member of srcSubresource must be present in the source image
Dave Houltonee281a52017-12-08 13:51:02 -07001830 if (!VerifyAspectsPresent(region.srcSubresource.aspectMask, src_image_state->createInfo.format)) {
Dave Houlton4eaaf3a2017-03-14 11:31:20 -06001831 std::stringstream ss;
1832 ss << "vkCmdCopyImage: pRegion[" << i
1833 << "] srcSubresource.aspectMask cannot specify aspects not present in source image";
1834 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06001835 HandleToUint64(command_buffer), VALIDATION_ERROR_09c0011c, "%s.", ss.str().c_str());
Dave Houlton4eaaf3a2017-03-14 11:31:20 -06001836 }
1837
1838 // For each region, the aspectMask member of dstSubresource must be present in the destination image
Dave Houltonee281a52017-12-08 13:51:02 -07001839 if (!VerifyAspectsPresent(region.dstSubresource.aspectMask, dst_image_state->createInfo.format)) {
Dave Houlton4eaaf3a2017-03-14 11:31:20 -06001840 std::stringstream ss;
1841 ss << "vkCmdCopyImage: pRegion[" << i << "] dstSubresource.aspectMask cannot specify aspects not present in dest image";
1842 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06001843 HandleToUint64(command_buffer), VALIDATION_ERROR_09c0011e, "%s.", ss.str().c_str());
Dave Houlton4eaaf3a2017-03-14 11:31:20 -06001844 }
1845
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001846 // AspectMask must not contain VK_IMAGE_ASPECT_METADATA_BIT
Dave Houltonee281a52017-12-08 13:51:02 -07001847 if ((region.srcSubresource.aspectMask & VK_IMAGE_ASPECT_METADATA_BIT) ||
1848 (region.dstSubresource.aspectMask & VK_IMAGE_ASPECT_METADATA_BIT)) {
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001849 std::stringstream ss;
1850 ss << "vkCmdCopyImage: pRegions[" << i << "] may not specify aspectMask containing VK_IMAGE_ASPECT_METADATA_BIT";
1851 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06001852 HandleToUint64(command_buffer), VALIDATION_ERROR_0a600150, "%s.", ss.str().c_str());
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001853 }
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001854
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001855 // For each region, if aspectMask contains VK_IMAGE_ASPECT_COLOR_BIT, it must not contain either of
1856 // VK_IMAGE_ASPECT_DEPTH_BIT or VK_IMAGE_ASPECT_STENCIL_BIT
Dave Houltonee281a52017-12-08 13:51:02 -07001857 if ((region.srcSubresource.aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) &&
1858 (region.srcSubresource.aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT))) {
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001859 char const str[] = "vkCmdCopyImage aspectMask cannot specify both COLOR and DEPTH/STENCIL aspects";
1860 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06001861 HandleToUint64(command_buffer), VALIDATION_ERROR_0a60014e, "%s.", str);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001862 }
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001863
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001864 // MipLevel must be less than the mipLevels specified in VkImageCreateInfo when the image was created
Dave Houltonee281a52017-12-08 13:51:02 -07001865 if (region.srcSubresource.mipLevel >= src_image_state->createInfo.mipLevels) {
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001866 std::stringstream ss;
1867 ss << "vkCmdCopyImage: pRegions[" << i
1868 << "] specifies a src mipLevel greater than the number specified when the srcImage was created.";
1869 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06001870 HandleToUint64(command_buffer), VALIDATION_ERROR_19000d40, "%s.", ss.str().c_str());
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001871 }
Dave Houltonee281a52017-12-08 13:51:02 -07001872 if (region.dstSubresource.mipLevel >= dst_image_state->createInfo.mipLevels) {
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001873 std::stringstream ss;
1874 ss << "vkCmdCopyImage: pRegions[" << i
1875 << "] specifies a dst mipLevel greater than the number specified when the dstImage was created.";
1876 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06001877 HandleToUint64(command_buffer), VALIDATION_ERROR_19000d42, "%s.", ss.str().c_str());
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001878 }
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001879
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001880 // (baseArrayLayer + layerCount) must be less than or equal to the arrayLayers specified in VkImageCreateInfo when the
1881 // image was created
Dave Houltonee281a52017-12-08 13:51:02 -07001882 if ((region.srcSubresource.baseArrayLayer + region.srcSubresource.layerCount) > src_image_state->createInfo.arrayLayers) {
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001883 std::stringstream ss;
1884 ss << "vkCmdCopyImage: srcImage arrayLayers was " << src_image_state->createInfo.arrayLayers << " but subRegion[" << i
Dave Houltonee281a52017-12-08 13:51:02 -07001885 << "] baseArrayLayer + layerCount is " << (region.srcSubresource.baseArrayLayer + region.srcSubresource.layerCount);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001886 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06001887 HandleToUint64(command_buffer), VALIDATION_ERROR_19000d44, "%s.", ss.str().c_str());
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001888 }
Dave Houltonee281a52017-12-08 13:51:02 -07001889 if ((region.dstSubresource.baseArrayLayer + region.dstSubresource.layerCount) > dst_image_state->createInfo.arrayLayers) {
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001890 std::stringstream ss;
1891 ss << "vkCmdCopyImage: dstImage arrayLayers was " << dst_image_state->createInfo.arrayLayers << " but subRegion[" << i
Dave Houltonee281a52017-12-08 13:51:02 -07001892 << "] baseArrayLayer + layerCount is " << (region.dstSubresource.baseArrayLayer + region.dstSubresource.layerCount);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001893 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06001894 HandleToUint64(command_buffer), VALIDATION_ERROR_19000d46, "%s.", ss.str().c_str());
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001895 }
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001896
Mike Schuchardt64b5bb72017-03-21 16:33:26 -06001897 // Check region extents for 1D-1D, 2D-2D, and 3D-3D copies
1898 if (src_image_state->createInfo.imageType == dst_image_state->createInfo.imageType) {
1899 // The source region specified by a given element of regions must be a region that is contained within srcImage
Dave Houltonee281a52017-12-08 13:51:02 -07001900 VkExtent3D img_extent = GetImageSubresourceExtent(src_image_state, &(region.srcSubresource));
1901 if (0 != ExceedsBounds(&region.srcOffset, &src_copy_extent, &img_extent)) {
Mike Schuchardt64b5bb72017-03-21 16:33:26 -06001902 std::stringstream ss;
Dave Houltonee281a52017-12-08 13:51:02 -07001903 ss << "vkCmdCopyImage: Source pRegion[" << i << "] with mipLevel [ " << region.srcSubresource.mipLevel
1904 << " ], offset [ " << region.srcOffset.x << ", " << region.srcOffset.y << ", " << region.srcOffset.z
1905 << " ], extent [ " << src_copy_extent.width << ", " << src_copy_extent.height << ", " << src_copy_extent.depth
1906 << " ] exceeds the source image dimensions";
Mark Lobodzinskib1fd9d12018-03-30 14:26:00 -06001907 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06001908 HandleToUint64(command_buffer), VALIDATION_ERROR_190000f4, "%s.", ss.str().c_str());
Mike Schuchardt64b5bb72017-03-21 16:33:26 -06001909 }
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001910
Mike Schuchardt64b5bb72017-03-21 16:33:26 -06001911 // The destination region specified by a given element of regions must be a region that is contained within dst_image
Dave Houltonee281a52017-12-08 13:51:02 -07001912 img_extent = GetImageSubresourceExtent(dst_image_state, &(region.dstSubresource));
1913 if (0 != ExceedsBounds(&region.dstOffset, &dst_copy_extent, &img_extent)) {
Mike Schuchardt64b5bb72017-03-21 16:33:26 -06001914 std::stringstream ss;
Dave Houltonee281a52017-12-08 13:51:02 -07001915 ss << "vkCmdCopyImage: Dest pRegion[" << i << "] with mipLevel [ " << region.dstSubresource.mipLevel
1916 << " ], offset [ " << region.dstOffset.x << ", " << region.dstOffset.y << ", " << region.dstOffset.z
1917 << " ], extent [ " << dst_copy_extent.width << ", " << dst_copy_extent.height << ", " << dst_copy_extent.depth
1918 << " ] exceeds the destination image dimensions";
Mark Lobodzinskib1fd9d12018-03-30 14:26:00 -06001919 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06001920 HandleToUint64(command_buffer), VALIDATION_ERROR_190000f6, "%s.", ss.str().c_str());
Mike Schuchardt64b5bb72017-03-21 16:33:26 -06001921 }
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001922 }
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001923
Dave Houltonfc1a4052017-04-27 14:32:45 -06001924 // Each dimension offset + extent limits must fall with image subresource extent
Dave Houltonee281a52017-12-08 13:51:02 -07001925 VkExtent3D subresource_extent = GetImageSubresourceExtent(src_image_state, &(region.srcSubresource));
1926 if (slice_override) src_copy_extent.depth = depth_slices;
1927 uint32_t extent_check = ExceedsBounds(&(region.srcOffset), &src_copy_extent, &subresource_extent);
Dave Houltonfc1a4052017-04-27 14:32:45 -06001928 if (extent_check & x_bit) {
1929 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06001930 HandleToUint64(command_buffer), VALIDATION_ERROR_09c00120,
Dave Houltonfc1a4052017-04-27 14:32:45 -06001931 "vkCmdCopyImage: Source image pRegion %1d x-dimension offset [%1d] + extent [%1d] exceeds subResource "
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06001932 "width [%1d].",
1933 i, region.srcOffset.x, src_copy_extent.width, subresource_extent.width);
Dave Houltonfc1a4052017-04-27 14:32:45 -06001934 }
1935
1936 if (extent_check & y_bit) {
1937 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06001938 HandleToUint64(command_buffer), VALIDATION_ERROR_09c00122,
Dave Houltonfc1a4052017-04-27 14:32:45 -06001939 "vkCmdCopyImage: Source image pRegion %1d y-dimension offset [%1d] + extent [%1d] exceeds subResource "
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06001940 "height [%1d].",
1941 i, region.srcOffset.y, src_copy_extent.height, subresource_extent.height);
Dave Houltonfc1a4052017-04-27 14:32:45 -06001942 }
1943 if (extent_check & z_bit) {
1944 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06001945 HandleToUint64(command_buffer), VALIDATION_ERROR_09c00126,
Dave Houltonfc1a4052017-04-27 14:32:45 -06001946 "vkCmdCopyImage: Source image pRegion %1d z-dimension offset [%1d] + extent [%1d] exceeds subResource "
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06001947 "depth [%1d].",
1948 i, region.srcOffset.z, src_copy_extent.depth, subresource_extent.depth);
Dave Houltonfc1a4052017-04-27 14:32:45 -06001949 }
1950
Dave Houltonee281a52017-12-08 13:51:02 -07001951 // Adjust dest extent if necessary
1952 subresource_extent = GetImageSubresourceExtent(dst_image_state, &(region.dstSubresource));
1953 if (slice_override) dst_copy_extent.depth = depth_slices;
1954
1955 extent_check = ExceedsBounds(&(region.dstOffset), &dst_copy_extent, &subresource_extent);
Dave Houltonfc1a4052017-04-27 14:32:45 -06001956 if (extent_check & x_bit) {
1957 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06001958 HandleToUint64(command_buffer), VALIDATION_ERROR_09c0012c,
Dave Houltonfc1a4052017-04-27 14:32:45 -06001959 "vkCmdCopyImage: Dest image pRegion %1d x-dimension offset [%1d] + extent [%1d] exceeds subResource "
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06001960 "width [%1d].",
1961 i, region.dstOffset.x, dst_copy_extent.width, subresource_extent.width);
Dave Houltonfc1a4052017-04-27 14:32:45 -06001962 }
1963 if (extent_check & y_bit) {
1964 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06001965 HandleToUint64(command_buffer), VALIDATION_ERROR_09c0012e,
Dave Houltonfc1a4052017-04-27 14:32:45 -06001966 "vkCmdCopyImage: Dest image pRegion %1d y-dimension offset [%1d] + extent [%1d] exceeds subResource "
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06001967 "height [%1d].",
1968 i, region.dstOffset.y, dst_copy_extent.height, subresource_extent.height);
Dave Houltonfc1a4052017-04-27 14:32:45 -06001969 }
1970 if (extent_check & z_bit) {
1971 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06001972 HandleToUint64(command_buffer), VALIDATION_ERROR_09c00132,
Dave Houltonfc1a4052017-04-27 14:32:45 -06001973 "vkCmdCopyImage: Dest image pRegion %1d z-dimension offset [%1d] + extent [%1d] exceeds subResource "
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06001974 "depth [%1d].",
1975 i, region.dstOffset.z, dst_copy_extent.depth, subresource_extent.depth);
Dave Houltonfc1a4052017-04-27 14:32:45 -06001976 }
1977
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001978 // The union of all source regions, and the union of all destination regions, specified by the elements of regions,
1979 // must not overlap in memory
1980 if (src_image_state->image == dst_image_state->image) {
1981 for (uint32_t j = 0; j < region_count; j++) {
Dave Houltonf5217612018-02-02 16:18:52 -07001982 if (RegionIntersects(&region, &regions[j], src_image_state->createInfo.imageType,
1983 FormatIsMultiplane(src_image_state->createInfo.format))) {
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001984 std::stringstream ss;
1985 ss << "vkCmdCopyImage: pRegions[" << i << "] src overlaps with pRegions[" << j << "].";
1986 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06001987 HandleToUint64(command_buffer), VALIDATION_ERROR_190000f8, "%s.", ss.str().c_str());
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001988 }
1989 }
1990 }
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001991 }
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001992
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001993 // The formats of src_image and dst_image must be compatible. Formats are considered compatible if their texel size in bytes
1994 // is the same between both formats. For example, VK_FORMAT_R8G8B8A8_UNORM is compatible with VK_FORMAT_R32_UINT because
1995 // because both texels are 4 bytes in size. Depth/stencil formats must match exactly.
Dave Houlton1150cf52017-04-27 14:38:11 -06001996 if (FormatIsDepthOrStencil(src_image_state->createInfo.format) || FormatIsDepthOrStencil(dst_image_state->createInfo.format)) {
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001997 if (src_image_state->createInfo.format != dst_image_state->createInfo.format) {
1998 char const str[] = "vkCmdCopyImage called with unmatched source and dest image depth/stencil formats.";
Petr Krausbc7f5442017-05-14 23:43:38 +02001999 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002000 HandleToUint64(command_buffer), DRAWSTATE_MISMATCHED_IMAGE_FORMAT, str);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07002001 }
2002 } else {
Dave Houlton1d2022c2017-03-29 11:43:58 -06002003 size_t srcSize = FormatSize(src_image_state->createInfo.format);
2004 size_t destSize = FormatSize(dst_image_state->createInfo.format);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07002005 if (srcSize != destSize) {
2006 char const str[] = "vkCmdCopyImage called with unmatched source and dest image format sizes.";
2007 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002008 HandleToUint64(command_buffer), VALIDATION_ERROR_1900010e, "%s.", str);
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07002009 }
2010 }
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07002011
Dave Houlton33c22b72017-02-28 13:16:02 -07002012 // Source and dest image sample counts must match
2013 if (src_image_state->createInfo.samples != dst_image_state->createInfo.samples) {
2014 char const str[] = "vkCmdCopyImage() called on image pair with non-identical sample counts.";
2015 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002016 HandleToUint64(command_buffer), VALIDATION_ERROR_19000110, "%s", str);
Dave Houlton33c22b72017-02-28 13:16:02 -07002017 }
2018
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002019 skip |= ValidateMemoryIsBoundToImage(device_data, src_image_state, "vkCmdCopyImage()", VALIDATION_ERROR_190000fe);
2020 skip |= ValidateMemoryIsBoundToImage(device_data, dst_image_state, "vkCmdCopyImage()", VALIDATION_ERROR_19000108);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07002021 // Validate that SRC & DST images have correct usage flags set
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002022 skip |= ValidateImageUsageFlags(device_data, src_image_state, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, true, VALIDATION_ERROR_190000fc,
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07002023 "vkCmdCopyImage()", "VK_IMAGE_USAGE_TRANSFER_SRC_BIT");
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002024 skip |= ValidateImageUsageFlags(device_data, dst_image_state, VK_IMAGE_USAGE_TRANSFER_DST_BIT, true, VALIDATION_ERROR_19000106,
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07002025 "vkCmdCopyImage()", "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Mike Schuchardt9c582402017-02-23 15:57:37 -07002026 skip |= ValidateCmdQueueFlags(device_data, cb_node, "vkCmdCopyImage()",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002027 VK_QUEUE_TRANSFER_BIT | VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT, VALIDATION_ERROR_19002415);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07002028 skip |= ValidateCmd(device_data, cb_node, CMD_COPYIMAGE, "vkCmdCopyImage()");
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002029 skip |= insideRenderPass(device_data, cb_node, "vkCmdCopyImage()", VALIDATION_ERROR_19000017);
Tobin Ehlisc8266452017-04-07 12:20:30 -06002030 bool hit_error = false;
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07002031 for (uint32_t i = 0; i < region_count; ++i) {
Tobin Ehlis2d85ec62017-03-14 15:38:48 -06002032 skip |= VerifyImageLayout(device_data, cb_node, src_image_state, regions[i].srcSubresource, src_image_layout,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002033 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, "vkCmdCopyImage()", VALIDATION_ERROR_19000102, &hit_error);
Tobin Ehlis2d85ec62017-03-14 15:38:48 -06002034 skip |= VerifyImageLayout(device_data, cb_node, dst_image_state, regions[i].dstSubresource, dst_image_layout,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002035 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, "vkCmdCopyImage()", VALIDATION_ERROR_1900010c, &hit_error);
Dave Houlton6f9059e2017-05-02 17:15:13 -06002036 skip |= ValidateCopyImageTransferGranularityRequirements(device_data, cb_node, src_image_state, dst_image_state,
2037 &regions[i], i, "vkCmdCopyImage()");
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07002038 }
2039
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07002040 return skip;
2041}
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002042
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07002043void PreCallRecordCmdCopyImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state,
Tobin Ehlise35b66a2017-03-15 12:18:31 -06002044 IMAGE_STATE *dst_image_state, uint32_t region_count, const VkImageCopy *regions,
2045 VkImageLayout src_image_layout, VkImageLayout dst_image_layout) {
2046 // Make sure that all image slices are updated to correct layout
2047 for (uint32_t i = 0; i < region_count; ++i) {
2048 SetImageLayout(device_data, cb_node, src_image_state, regions[i].srcSubresource, src_image_layout);
2049 SetImageLayout(device_data, cb_node, dst_image_state, regions[i].dstSubresource, dst_image_layout);
2050 }
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07002051 // Update bindings between images and cmd buffer
2052 AddCommandBufferBindingImage(device_data, cb_node, src_image_state);
2053 AddCommandBufferBindingImage(device_data, cb_node, dst_image_state);
Dave Houltoneba86e22017-03-02 14:56:23 -07002054 std::function<bool()> function = [=]() { return ValidateImageMemoryIsValid(device_data, src_image_state, "vkCmdCopyImage()"); };
Tobin Ehlisa17a5292017-07-28 12:11:30 -06002055 cb_node->queue_submit_functions.push_back(function);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07002056 function = [=]() {
2057 SetImageMemoryValid(device_data, dst_image_state, true);
2058 return false;
2059 };
Tobin Ehlisa17a5292017-07-28 12:11:30 -06002060 cb_node->queue_submit_functions.push_back(function);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07002061}
2062
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002063// Returns true if sub_rect is entirely contained within rect
2064static inline bool ContainsRect(VkRect2D rect, VkRect2D sub_rect) {
2065 if ((sub_rect.offset.x < rect.offset.x) || (sub_rect.offset.x + sub_rect.extent.width > rect.offset.x + rect.extent.width) ||
2066 (sub_rect.offset.y < rect.offset.y) || (sub_rect.offset.y + sub_rect.extent.height > rect.offset.y + rect.extent.height))
2067 return false;
2068 return true;
2069}
2070
Tobin Ehlis58c884f2017-02-08 12:15:27 -07002071bool PreCallValidateCmdClearAttachments(layer_data *device_data, VkCommandBuffer commandBuffer, uint32_t attachmentCount,
2072 const VkClearAttachment *pAttachments, uint32_t rectCount, const VkClearRect *pRects) {
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07002073 GLOBAL_CB_NODE *cb_node = GetCBNode(device_data, commandBuffer);
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002074 const debug_report_data *report_data = core_validation::GetReportData(device_data);
2075
2076 bool skip = false;
2077 if (cb_node) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002078 skip |= ValidateCmdQueueFlags(device_data, cb_node, "vkCmdClearAttachments()", VK_QUEUE_GRAPHICS_BIT,
2079 VALIDATION_ERROR_18602415);
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002080 skip |= ValidateCmd(device_data, cb_node, CMD_CLEARATTACHMENTS, "vkCmdClearAttachments()");
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002081 // Warn if this is issued prior to Draw Cmd and clearing the entire attachment
Chris Forbes05375e72017-04-21 13:15:15 -07002082 if (!cb_node->hasDrawCmd && (cb_node->activeRenderPassBeginInfo.renderArea.extent.width == pRects[0].rect.extent.width) &&
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002083 (cb_node->activeRenderPassBeginInfo.renderArea.extent.height == pRects[0].rect.extent.height)) {
2084 // There are times where app needs to use ClearAttachments (generally when reusing a buffer inside of a render pass)
Mark Lobodzinskid833bb72017-02-22 10:55:30 -07002085 // This warning should be made more specific. It'd be best to avoid triggering this test if it's a use that must call
2086 // CmdClearAttachments.
Dave Houltona9df0ce2018-02-07 10:51:23 -07002087 skip |= log_msg(
2088 report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002089 HandleToUint64(commandBuffer), DRAWSTATE_CLEAR_CMD_BEFORE_DRAW,
Dave Houltona9df0ce2018-02-07 10:51:23 -07002090 "vkCmdClearAttachments() issued on command buffer object 0x%" PRIx64
2091 " prior to any Draw Cmds. It is recommended you use RenderPass LOAD_OP_CLEAR on Attachments prior to any Draw.",
2092 HandleToUint64(commandBuffer));
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002093 }
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002094 skip |= outsideRenderPass(device_data, cb_node, "vkCmdClearAttachments()", VALIDATION_ERROR_18600017);
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002095 }
2096
2097 // Validate that attachment is in reference list of active subpass
2098 if (cb_node->activeRenderPass) {
2099 const VkRenderPassCreateInfo *renderpass_create_info = cb_node->activeRenderPass->createInfo.ptr();
2100 const VkSubpassDescription *subpass_desc = &renderpass_create_info->pSubpasses[cb_node->activeSubpass];
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07002101 auto framebuffer = GetFramebufferState(device_data, cb_node->activeFramebuffer);
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002102
2103 for (uint32_t i = 0; i < attachmentCount; i++) {
2104 auto clear_desc = &pAttachments[i];
2105 VkImageView image_view = VK_NULL_HANDLE;
2106
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07002107 if (0 == clear_desc->aspectMask) {
2108 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002109 HandleToUint64(commandBuffer), VALIDATION_ERROR_01c00c03, " ");
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07002110 } else if (clear_desc->aspectMask & VK_IMAGE_ASPECT_METADATA_BIT) {
2111 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002112 HandleToUint64(commandBuffer), VALIDATION_ERROR_01c00028, " ");
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07002113 } else if (clear_desc->aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) {
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002114 if (clear_desc->colorAttachment >= subpass_desc->colorAttachmentCount) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002115 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002116 HandleToUint64(commandBuffer), VALIDATION_ERROR_1860001e,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06002117 "vkCmdClearAttachments() color attachment index %d out of range for active subpass %d.",
2118 clear_desc->colorAttachment, cb_node->activeSubpass);
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002119 } else if (subpass_desc->pColorAttachments[clear_desc->colorAttachment].attachment == VK_ATTACHMENT_UNUSED) {
2120 skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinskib1fd9d12018-03-30 14:26:00 -06002121 VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, HandleToUint64(commandBuffer),
Mark Lobodzinski88529492018-04-01 10:38:15 -06002122 DRAWSTATE_MISSING_ATTACHMENT_REFERENCE,
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07002123 "vkCmdClearAttachments() color attachment index %d is VK_ATTACHMENT_UNUSED; ignored.",
2124 clear_desc->colorAttachment);
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002125 } else {
2126 image_view = framebuffer->createInfo
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07002127 .pAttachments[subpass_desc->pColorAttachments[clear_desc->colorAttachment].attachment];
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002128 }
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07002129 if ((clear_desc->aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) ||
2130 (clear_desc->aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT)) {
2131 char const str[] =
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06002132 "vkCmdClearAttachments() aspectMask [%d] must set only VK_IMAGE_ASPECT_COLOR_BIT of a color attachment.";
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07002133 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002134 HandleToUint64(commandBuffer), VALIDATION_ERROR_01c00026, str, i);
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07002135 }
2136 } else { // Must be depth and/or stencil
2137 if (((clear_desc->aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) != VK_IMAGE_ASPECT_DEPTH_BIT) &&
2138 ((clear_desc->aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) != VK_IMAGE_ASPECT_STENCIL_BIT)) {
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06002139 char const str[] = "vkCmdClearAttachments() aspectMask [%d] is not a valid combination of bits.";
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07002140 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002141 HandleToUint64(commandBuffer), VALIDATION_ERROR_01c00c01, str, i);
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07002142 }
2143 if (!subpass_desc->pDepthStencilAttachment ||
2144 (subpass_desc->pDepthStencilAttachment->attachment == VK_ATTACHMENT_UNUSED)) {
2145 skip |= log_msg(
2146 report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002147 HandleToUint64(commandBuffer), DRAWSTATE_MISSING_ATTACHMENT_REFERENCE,
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07002148 "vkCmdClearAttachments() depth/stencil clear with no depth/stencil attachment in subpass; ignored");
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002149 } else {
2150 image_view = framebuffer->createInfo.pAttachments[subpass_desc->pDepthStencilAttachment->attachment];
2151 }
2152 }
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002153 if (image_view) {
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07002154 auto image_view_state = GetImageViewState(device_data, image_view);
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002155 for (uint32_t j = 0; j < rectCount; j++) {
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07002156 // The rectangular region specified by a given element of pRects must be contained within the render area of
2157 // the current render pass instance
Tobin Ehlis37ec75a2018-03-12 11:26:39 -06002158 if (cb_node->createInfo.level == VK_COMMAND_BUFFER_LEVEL_PRIMARY) {
2159 if (false == ContainsRect(cb_node->activeRenderPassBeginInfo.renderArea, pRects[j].rect)) {
2160 skip |=
2161 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002162 HandleToUint64(commandBuffer), VALIDATION_ERROR_18600020,
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07002163 "vkCmdClearAttachments(): The area defined by pRects[%d] is not contained in the area of "
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06002164 "the current render pass instance.",
2165 j);
Tobin Ehlis37ec75a2018-03-12 11:26:39 -06002166 }
2167 } else {
2168 cb_node->cmd_execute_commands_functions.emplace_back([=](GLOBAL_CB_NODE *prim_cb, VkFramebuffer fb) {
2169 if (false == ContainsRect(prim_cb->activeRenderPassBeginInfo.renderArea, pRects[j].rect)) {
2170 return log_msg(
2171 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002172 HandleToUint64(commandBuffer), VALIDATION_ERROR_18600020,
Tobin Ehlis37ec75a2018-03-12 11:26:39 -06002173 "vkCmdClearAttachments(): The area defined by pRects[%d] is not contained in the area of "
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06002174 "the current render pass instance.",
2175 j);
Tobin Ehlis37ec75a2018-03-12 11:26:39 -06002176 }
2177 return false;
2178 });
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002179 }
2180 // The layers specified by a given element of pRects must be contained within every attachment that
2181 // pAttachments refers to
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002182 auto attachment_layer_count = image_view_state->create_info.subresourceRange.layerCount;
Dave Houlton8e157032017-05-22 16:16:27 -06002183 if ((pRects[j].baseArrayLayer >= attachment_layer_count) ||
2184 (pRects[j].baseArrayLayer + pRects[j].layerCount > attachment_layer_count)) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07002185 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002186 HandleToUint64(commandBuffer), VALIDATION_ERROR_18600022,
Dave Houltona9df0ce2018-02-07 10:51:23 -07002187 "vkCmdClearAttachments(): The layers defined in pRects[%d] are not contained in the layers "
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06002188 "of pAttachment[%d].",
2189 j, i);
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002190 }
2191 }
2192 }
2193 }
2194 }
2195 return skip;
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07002196}
2197
Tobin Ehlis58c884f2017-02-08 12:15:27 -07002198bool PreCallValidateCmdResolveImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state,
Mark Lobodzinski50fbef12017-02-06 15:31:33 -07002199 IMAGE_STATE *dst_image_state, uint32_t regionCount, const VkImageResolve *pRegions) {
Mark Lobodzinski2a3368e2017-02-06 15:29:37 -07002200 const debug_report_data *report_data = core_validation::GetReportData(device_data);
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07002201 bool skip = false;
2202 if (cb_node && src_image_state && dst_image_state) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002203 skip |= ValidateMemoryIsBoundToImage(device_data, src_image_state, "vkCmdResolveImage()", VALIDATION_ERROR_1c800200);
2204 skip |= ValidateMemoryIsBoundToImage(device_data, dst_image_state, "vkCmdResolveImage()", VALIDATION_ERROR_1c800204);
2205 skip |=
2206 ValidateCmdQueueFlags(device_data, cb_node, "vkCmdResolveImage()", VK_QUEUE_GRAPHICS_BIT, VALIDATION_ERROR_1c802415);
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07002207 skip |= ValidateCmd(device_data, cb_node, CMD_RESOLVEIMAGE, "vkCmdResolveImage()");
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002208 skip |= insideRenderPass(device_data, cb_node, "vkCmdResolveImage()", VALIDATION_ERROR_1c800017);
Mark Lobodzinski2a3368e2017-02-06 15:29:37 -07002209
2210 // For each region, the number of layers in the image subresource should not be zero
2211 // For each region, src and dest image aspect must be color only
2212 for (uint32_t i = 0; i < regionCount; i++) {
2213 if (pRegions[i].srcSubresource.layerCount == 0) {
2214 char const str[] = "vkCmdResolveImage: number of layers in source subresource is zero";
Mark Lobodzinski50fbef12017-02-06 15:31:33 -07002215 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002216 HandleToUint64(cb_node->commandBuffer), DRAWSTATE_MISMATCHED_IMAGE_ASPECT, str);
Mark Lobodzinski2a3368e2017-02-06 15:29:37 -07002217 }
Mark Lobodzinski2a3368e2017-02-06 15:29:37 -07002218 if (pRegions[i].dstSubresource.layerCount == 0) {
2219 char const str[] = "vkCmdResolveImage: number of layers in destination subresource is zero";
Mark Lobodzinski50fbef12017-02-06 15:31:33 -07002220 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002221 HandleToUint64(cb_node->commandBuffer), DRAWSTATE_MISMATCHED_IMAGE_ASPECT, str);
Mark Lobodzinski2a3368e2017-02-06 15:29:37 -07002222 }
Mark Lobodzinski50fbef12017-02-06 15:31:33 -07002223 if (pRegions[i].srcSubresource.layerCount != pRegions[i].dstSubresource.layerCount) {
2224 skip |= log_msg(
2225 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002226 HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_0a200216,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06002227 "vkCmdResolveImage: layerCount in source and destination subresource of pRegions[%d] does not match.", i);
Mark Lobodzinski50fbef12017-02-06 15:31:33 -07002228 }
Mark Lobodzinski2a3368e2017-02-06 15:29:37 -07002229 if ((pRegions[i].srcSubresource.aspectMask != VK_IMAGE_ASPECT_COLOR_BIT) ||
2230 (pRegions[i].dstSubresource.aspectMask != VK_IMAGE_ASPECT_COLOR_BIT)) {
2231 char const str[] =
2232 "vkCmdResolveImage: src and dest aspectMasks for each region must specify only VK_IMAGE_ASPECT_COLOR_BIT";
2233 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002234 HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_0a200214, "%s.", str);
Mark Lobodzinski2a3368e2017-02-06 15:29:37 -07002235 }
2236 }
2237
2238 if (src_image_state->createInfo.format != dst_image_state->createInfo.format) {
2239 char const str[] = "vkCmdResolveImage called with unmatched source and dest formats.";
Mark Lobodzinski50fbef12017-02-06 15:31:33 -07002240 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002241 HandleToUint64(cb_node->commandBuffer), DRAWSTATE_MISMATCHED_IMAGE_FORMAT, str);
Mark Lobodzinski2a3368e2017-02-06 15:29:37 -07002242 }
2243 if (src_image_state->createInfo.imageType != dst_image_state->createInfo.imageType) {
2244 char const str[] = "vkCmdResolveImage called with unmatched source and dest image types.";
Mark Lobodzinski50fbef12017-02-06 15:31:33 -07002245 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002246 HandleToUint64(cb_node->commandBuffer), DRAWSTATE_MISMATCHED_IMAGE_TYPE, str);
Mark Lobodzinski2a3368e2017-02-06 15:29:37 -07002247 }
2248 if (src_image_state->createInfo.samples == VK_SAMPLE_COUNT_1_BIT) {
2249 char const str[] = "vkCmdResolveImage called with source sample count less than 2.";
2250 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002251 HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_1c800202, "%s.", str);
Mark Lobodzinski2a3368e2017-02-06 15:29:37 -07002252 }
2253 if (dst_image_state->createInfo.samples != VK_SAMPLE_COUNT_1_BIT) {
2254 char const str[] = "vkCmdResolveImage called with dest sample count greater than 1.";
2255 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002256 HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_1c800206, "%s.", str);
Mark Lobodzinski2a3368e2017-02-06 15:29:37 -07002257 }
Tobin Ehlisbb03e5f2017-05-11 08:52:51 -06002258 // TODO: Need to validate image layouts, which will include layout validation for shared presentable images
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07002259 } else {
2260 assert(0);
2261 }
2262 return skip;
2263}
2264
Tobin Ehlis58c884f2017-02-08 12:15:27 -07002265void PreCallRecordCmdResolveImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state,
2266 IMAGE_STATE *dst_image_state) {
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07002267 // Update bindings between images and cmd buffer
2268 AddCommandBufferBindingImage(device_data, cb_node, src_image_state);
2269 AddCommandBufferBindingImage(device_data, cb_node, dst_image_state);
2270
2271 std::function<bool()> function = [=]() {
2272 return ValidateImageMemoryIsValid(device_data, src_image_state, "vkCmdResolveImage()");
2273 };
Tobin Ehlisa17a5292017-07-28 12:11:30 -06002274 cb_node->queue_submit_functions.push_back(function);
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07002275 function = [=]() {
2276 SetImageMemoryValid(device_data, dst_image_state, true);
2277 return false;
2278 };
Tobin Ehlisa17a5292017-07-28 12:11:30 -06002279 cb_node->queue_submit_functions.push_back(function);
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07002280}
2281
Tobin Ehlis58c884f2017-02-08 12:15:27 -07002282bool PreCallValidateCmdBlitImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state,
Norbert Garnys7bd4c2c2017-11-16 10:58:04 +01002283 IMAGE_STATE *dst_image_state, uint32_t region_count, const VkImageBlit *regions,
2284 VkImageLayout src_image_layout, VkImageLayout dst_image_layout, VkFilter filter) {
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002285 const debug_report_data *report_data = core_validation::GetReportData(device_data);
2286
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07002287 bool skip = false;
John Zulauf5c2750c2018-01-30 15:04:56 -07002288 if (cb_node) {
2289 skip |= ValidateCmd(device_data, cb_node, CMD_BLITIMAGE, "vkCmdBlitImage()");
2290 }
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07002291 if (cb_node && src_image_state && dst_image_state) {
2292 skip |= ValidateImageSampleCount(device_data, src_image_state, VK_SAMPLE_COUNT_1_BIT, "vkCmdBlitImage(): srcImage",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002293 VALIDATION_ERROR_184001d2);
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07002294 skip |= ValidateImageSampleCount(device_data, dst_image_state, VK_SAMPLE_COUNT_1_BIT, "vkCmdBlitImage(): dstImage",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002295 VALIDATION_ERROR_184001d4);
2296 skip |= ValidateMemoryIsBoundToImage(device_data, src_image_state, "vkCmdBlitImage()", VALIDATION_ERROR_184001b8);
2297 skip |= ValidateMemoryIsBoundToImage(device_data, dst_image_state, "vkCmdBlitImage()", VALIDATION_ERROR_184001c2);
2298 skip |= ValidateImageUsageFlags(device_data, src_image_state, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, true,
2299 VALIDATION_ERROR_184001b6, "vkCmdBlitImage()", "VK_IMAGE_USAGE_TRANSFER_SRC_BIT");
2300 skip |= ValidateImageUsageFlags(device_data, dst_image_state, VK_IMAGE_USAGE_TRANSFER_DST_BIT, true,
2301 VALIDATION_ERROR_184001c0, "vkCmdBlitImage()", "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
2302 skip |= ValidateCmdQueueFlags(device_data, cb_node, "vkCmdBlitImage()", VK_QUEUE_GRAPHICS_BIT, VALIDATION_ERROR_18402415);
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07002303 skip |= ValidateCmd(device_data, cb_node, CMD_BLITIMAGE, "vkCmdBlitImage()");
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002304 skip |= insideRenderPass(device_data, cb_node, "vkCmdBlitImage()", VALIDATION_ERROR_18400017);
Tobin Ehlisbb03e5f2017-05-11 08:52:51 -06002305 // TODO: Need to validate image layouts, which will include layout validation for shared presentable images
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002306
Dave Houlton33c2d252017-06-09 17:08:32 -06002307 VkFormat src_format = src_image_state->createInfo.format;
2308 VkFormat dst_format = dst_image_state->createInfo.format;
2309 VkImageType src_type = src_image_state->createInfo.imageType;
2310 VkImageType dst_type = dst_image_state->createInfo.imageType;
2311
Jeremy Kniager7ec550f2017-08-16 14:57:42 -06002312 VkFormatProperties props = GetFormatProperties(device_data, src_format);
Dave Houlton33c2d252017-06-09 17:08:32 -06002313 VkImageTiling tiling = src_image_state->createInfo.tiling;
Dave Houltona9df0ce2018-02-07 10:51:23 -07002314 VkFormatFeatureFlags flags = (tiling == VK_IMAGE_TILING_LINEAR ? props.linearTilingFeatures : props.optimalTilingFeatures);
Dave Houlton33c2d252017-06-09 17:08:32 -06002315 if (VK_FORMAT_FEATURE_BLIT_SRC_BIT != (flags & VK_FORMAT_FEATURE_BLIT_SRC_BIT)) {
2316 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002317 HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_184001b4,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06002318 "vkCmdBlitImage: source image format %s does not support VK_FORMAT_FEATURE_BLIT_SRC_BIT feature.",
2319 string_VkFormat(src_format));
Dave Houlton33c2d252017-06-09 17:08:32 -06002320 }
2321
2322 if ((VK_FILTER_LINEAR == filter) &&
2323 (VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT != (flags & VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT))) {
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06002324 skip |=
2325 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002326 HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_184001d6,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06002327 "vkCmdBlitImage: source image format %s does not support linear filtering.", string_VkFormat(src_format));
Dave Houlton33c2d252017-06-09 17:08:32 -06002328 }
2329
2330 if ((VK_FILTER_CUBIC_IMG == filter) && (VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_CUBIC_BIT_IMG !=
2331 (flags & VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_CUBIC_BIT_IMG))) {
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06002332 skip |=
2333 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002334 HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_184001d8,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06002335 "vkCmdBlitImage: source image format %s does not support cubic filtering.", string_VkFormat(src_format));
Dave Houlton33c2d252017-06-09 17:08:32 -06002336 }
2337
2338 if ((VK_FILTER_CUBIC_IMG == filter) && (VK_IMAGE_TYPE_3D != src_type)) {
2339 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002340 HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_184001da,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06002341 "vkCmdBlitImage: source image type must be VK_IMAGE_TYPE_3D when cubic filtering is specified.");
Dave Houlton33c2d252017-06-09 17:08:32 -06002342 }
2343
2344 props = GetFormatProperties(device_data, dst_format);
2345 tiling = dst_image_state->createInfo.tiling;
Jeremy Kniager7ec550f2017-08-16 14:57:42 -06002346 flags = (tiling == VK_IMAGE_TILING_LINEAR ? props.linearTilingFeatures : props.optimalTilingFeatures);
Dave Houlton33c2d252017-06-09 17:08:32 -06002347 if (VK_FORMAT_FEATURE_BLIT_DST_BIT != (flags & VK_FORMAT_FEATURE_BLIT_DST_BIT)) {
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06002348 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002349 HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_184001be,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06002350 "vkCmdBlitImage: destination image format %s does not support VK_FORMAT_FEATURE_BLIT_DST_BIT feature.",
2351 string_VkFormat(dst_format));
Dave Houlton33c2d252017-06-09 17:08:32 -06002352 }
2353
2354 if ((VK_SAMPLE_COUNT_1_BIT != src_image_state->createInfo.samples) ||
2355 (VK_SAMPLE_COUNT_1_BIT != dst_image_state->createInfo.samples)) {
2356 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002357 HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_184001c8,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06002358 "vkCmdBlitImage: source or dest image has sample count other than VK_SAMPLE_COUNT_1_BIT.");
Dave Houlton33c2d252017-06-09 17:08:32 -06002359 }
2360
2361 // Validate consistency for unsigned formats
2362 if (FormatIsUInt(src_format) != FormatIsUInt(dst_format)) {
2363 std::stringstream ss;
2364 ss << "vkCmdBlitImage: If one of srcImage and dstImage images has unsigned integer format, "
2365 << "the other one must also have unsigned integer format. "
2366 << "Source format is " << string_VkFormat(src_format) << " Destination format is " << string_VkFormat(dst_format);
2367 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002368 HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_184001cc, "%s.", ss.str().c_str());
Dave Houlton33c2d252017-06-09 17:08:32 -06002369 }
2370
2371 // Validate consistency for signed formats
2372 if (FormatIsSInt(src_format) != FormatIsSInt(dst_format)) {
2373 std::stringstream ss;
2374 ss << "vkCmdBlitImage: If one of srcImage and dstImage images has signed integer format, "
2375 << "the other one must also have signed integer format. "
2376 << "Source format is " << string_VkFormat(src_format) << " Destination format is " << string_VkFormat(dst_format);
2377 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002378 HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_184001ca, "%s.", ss.str().c_str());
Dave Houlton33c2d252017-06-09 17:08:32 -06002379 }
2380
2381 // Validate filter for Depth/Stencil formats
2382 if (FormatIsDepthOrStencil(src_format) && (filter != VK_FILTER_NEAREST)) {
2383 std::stringstream ss;
2384 ss << "vkCmdBlitImage: If the format of srcImage is a depth, stencil, or depth stencil "
2385 << "then filter must be VK_FILTER_NEAREST.";
2386 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002387 HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_184001d0, "%s.", ss.str().c_str());
Dave Houlton33c2d252017-06-09 17:08:32 -06002388 }
2389
2390 // Validate aspect bits and formats for depth/stencil images
2391 if (FormatIsDepthOrStencil(src_format) || FormatIsDepthOrStencil(dst_format)) {
2392 if (src_format != dst_format) {
2393 std::stringstream ss;
2394 ss << "vkCmdBlitImage: If one of srcImage and dstImage images has a format of depth, stencil or depth "
2395 << "stencil, the other one must have exactly the same format. "
2396 << "Source format is " << string_VkFormat(src_format) << " Destination format is "
2397 << string_VkFormat(dst_format);
Mark Lobodzinski88529492018-04-01 10:38:15 -06002398 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2399 HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_184001ce, "%s.", ss.str().c_str());
Dave Houlton33c2d252017-06-09 17:08:32 -06002400 }
2401
2402#if 0 // TODO: Cannot find VU statements or spec language for these in CmdBlitImage. Verify or remove.
2403 for (uint32_t i = 0; i < regionCount; i++) {
2404 VkImageAspectFlags srcAspect = pRegions[i].srcSubresource.aspectMask;
2405
2406 if (FormatIsDepthAndStencil(src_format)) {
2407 if ((srcAspect != VK_IMAGE_ASPECT_DEPTH_BIT) && (srcAspect != VK_IMAGE_ASPECT_STENCIL_BIT)) {
2408 std::stringstream ss;
Dave Houltona9df0ce2018-02-07 10:51:23 -07002409 ss << "vkCmdBlitImage: Combination depth/stencil image formats must have only one of VK_IMAGE_ASPECT_DEPTH_BIT "
Dave Houlton33c2d252017-06-09 17:08:32 -06002410 << "and VK_IMAGE_ASPECT_STENCIL_BIT set in srcImage and dstImage";
2411 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002412 HandleToUint64(cb_node->commandBuffer), DRAWSTATE_INVALID_IMAGE_ASPECT,
Dave Houlton33c2d252017-06-09 17:08:32 -06002413 "%s", ss.str().c_str());
2414 }
2415 }
2416 else if (FormatIsStencilOnly(src_format)) {
2417 if (srcAspect != VK_IMAGE_ASPECT_STENCIL_BIT) {
2418 std::stringstream ss;
2419 ss << "vkCmdBlitImage: Stencil-only image formats must have only the VK_IMAGE_ASPECT_STENCIL_BIT "
2420 << "set in both the srcImage and dstImage";
2421 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002422 HandleToUint64(cb_node->commandBuffer), DRAWSTATE_INVALID_IMAGE_ASPECT,
Dave Houlton33c2d252017-06-09 17:08:32 -06002423 "%s", ss.str().c_str());
2424 }
2425 }
2426 else if (FormatIsDepthOnly(src_format)) {
2427 if (srcAspect != VK_IMAGE_ASPECT_DEPTH_BIT) {
2428 std::stringstream ss;
2429 ss << "vkCmdBlitImage: Depth-only image formats must have only the VK_IMAGE_ASPECT_DEPTH "
2430 << "set in both the srcImage and dstImage";
2431 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002432 HandleToUint64(cb_node->commandBuffer), DRAWSTATE_INVALID_IMAGE_ASPECT,
Dave Houlton33c2d252017-06-09 17:08:32 -06002433 "%s", ss.str().c_str());
2434 }
2435 }
2436 }
2437#endif
2438 } // Depth or Stencil
2439
2440 // Do per-region checks
Norbert Garnys7bd4c2c2017-11-16 10:58:04 +01002441 for (uint32_t i = 0; i < region_count; i++) {
2442 const VkImageBlit rgn = regions[i];
2443 bool hit_error = false;
2444 skip |=
2445 VerifyImageLayout(device_data, cb_node, src_image_state, rgn.srcSubresource, src_image_layout,
2446 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, "vkCmdBlitImage()", VALIDATION_ERROR_184001bc, &hit_error);
2447 skip |=
2448 VerifyImageLayout(device_data, cb_node, dst_image_state, rgn.dstSubresource, dst_image_layout,
2449 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, "vkCmdBlitImage()", VALIDATION_ERROR_184001c6, &hit_error);
Dave Houlton48989f32017-05-26 15:01:46 -06002450
Mark Lobodzinski23c81142017-02-06 15:04:23 -07002451 // Warn for zero-sized regions
Dave Houlton48989f32017-05-26 15:01:46 -06002452 if ((rgn.srcOffsets[0].x == rgn.srcOffsets[1].x) || (rgn.srcOffsets[0].y == rgn.srcOffsets[1].y) ||
2453 (rgn.srcOffsets[0].z == rgn.srcOffsets[1].z)) {
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002454 std::stringstream ss;
2455 ss << "vkCmdBlitImage: pRegions[" << i << "].srcOffsets specify a zero-volume area.";
2456 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002457 HandleToUint64(cb_node->commandBuffer), DRAWSTATE_INVALID_EXTENTS, "%s", ss.str().c_str());
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002458 }
Dave Houlton48989f32017-05-26 15:01:46 -06002459 if ((rgn.dstOffsets[0].x == rgn.dstOffsets[1].x) || (rgn.dstOffsets[0].y == rgn.dstOffsets[1].y) ||
2460 (rgn.dstOffsets[0].z == rgn.dstOffsets[1].z)) {
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002461 std::stringstream ss;
2462 ss << "vkCmdBlitImage: pRegions[" << i << "].dstOffsets specify a zero-volume area.";
2463 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002464 HandleToUint64(cb_node->commandBuffer), DRAWSTATE_INVALID_EXTENTS, "%s", ss.str().c_str());
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002465 }
Dave Houlton48989f32017-05-26 15:01:46 -06002466 if (rgn.srcSubresource.layerCount == 0) {
Mark Lobodzinski23c81142017-02-06 15:04:23 -07002467 char const str[] = "vkCmdBlitImage: number of layers in source subresource is zero";
2468 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002469 HandleToUint64(cb_node->commandBuffer), DRAWSTATE_MISMATCHED_IMAGE_ASPECT, str);
Mark Lobodzinski23c81142017-02-06 15:04:23 -07002470 }
Dave Houlton48989f32017-05-26 15:01:46 -06002471 if (rgn.dstSubresource.layerCount == 0) {
Mark Lobodzinski23c81142017-02-06 15:04:23 -07002472 char const str[] = "vkCmdBlitImage: number of layers in destination subresource is zero";
2473 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002474 HandleToUint64(cb_node->commandBuffer), DRAWSTATE_MISMATCHED_IMAGE_ASPECT, str);
Mark Lobodzinski23c81142017-02-06 15:04:23 -07002475 }
2476
2477 // Check that src/dst layercounts match
Dave Houlton48989f32017-05-26 15:01:46 -06002478 if (rgn.srcSubresource.layerCount != rgn.dstSubresource.layerCount) {
Mark Lobodzinski23c81142017-02-06 15:04:23 -07002479 skip |=
2480 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002481 HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_09a001de,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06002482 "vkCmdBlitImage: layerCount in source and destination subresource of pRegions[%d] does not match.", i);
Mark Lobodzinski23c81142017-02-06 15:04:23 -07002483 }
Mark Lobodzinskie7e85fd2017-02-07 13:44:57 -07002484
Dave Houlton48989f32017-05-26 15:01:46 -06002485 if (rgn.srcSubresource.aspectMask != rgn.dstSubresource.aspectMask) {
Mark Lobodzinskie7e85fd2017-02-07 13:44:57 -07002486 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002487 HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_09a001dc,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06002488 "vkCmdBlitImage: aspectMask members for pRegion[%d] do not match.", i);
Mark Lobodzinskie7e85fd2017-02-07 13:44:57 -07002489 }
Dave Houlton48989f32017-05-26 15:01:46 -06002490
Dave Houlton33c2d252017-06-09 17:08:32 -06002491 if (!VerifyAspectsPresent(rgn.srcSubresource.aspectMask, src_format)) {
2492 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002493 HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_09a001e2,
Dave Houlton33c2d252017-06-09 17:08:32 -06002494 "vkCmdBlitImage: region [%d] source aspectMask (0x%x) specifies aspects not present in source "
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06002495 "image format %s.",
2496 i, rgn.srcSubresource.aspectMask, string_VkFormat(src_format));
Dave Houlton33c2d252017-06-09 17:08:32 -06002497 }
2498
2499 if (!VerifyAspectsPresent(rgn.dstSubresource.aspectMask, dst_format)) {
2500 skip |= log_msg(
2501 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002502 HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_09a001e4,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06002503 "vkCmdBlitImage: region [%d] dest aspectMask (0x%x) specifies aspects not present in dest image format %s.", i,
2504 rgn.dstSubresource.aspectMask, string_VkFormat(dst_format));
Dave Houlton33c2d252017-06-09 17:08:32 -06002505 }
2506
Dave Houlton48989f32017-05-26 15:01:46 -06002507 // Validate source image offsets
2508 VkExtent3D src_extent = GetImageSubresourceExtent(src_image_state, &(rgn.srcSubresource));
Dave Houlton33c2d252017-06-09 17:08:32 -06002509 if (VK_IMAGE_TYPE_1D == src_type) {
Dave Houlton48989f32017-05-26 15:01:46 -06002510 if ((0 != rgn.srcOffsets[0].y) || (1 != rgn.srcOffsets[1].y)) {
2511 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002512 HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_09a001ea,
Dave Houlton48989f32017-05-26 15:01:46 -06002513 "vkCmdBlitImage: region [%d], source image of type VK_IMAGE_TYPE_1D with srcOffset[].y values "
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06002514 "of (%1d, %1d). These must be (0, 1).",
2515 i, rgn.srcOffsets[0].y, rgn.srcOffsets[1].y);
Dave Houlton48989f32017-05-26 15:01:46 -06002516 }
2517 }
2518
Dave Houlton33c2d252017-06-09 17:08:32 -06002519 if ((VK_IMAGE_TYPE_1D == src_type) || (VK_IMAGE_TYPE_2D == src_type)) {
Dave Houlton48989f32017-05-26 15:01:46 -06002520 if ((0 != rgn.srcOffsets[0].z) || (1 != rgn.srcOffsets[1].z)) {
2521 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002522 HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_09a001ee,
Dave Houlton48989f32017-05-26 15:01:46 -06002523 "vkCmdBlitImage: region [%d], source image of type VK_IMAGE_TYPE_1D or VK_IMAGE_TYPE_2D with "
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06002524 "srcOffset[].z values of (%1d, %1d). These must be (0, 1).",
2525 i, rgn.srcOffsets[0].z, rgn.srcOffsets[1].z);
Dave Houlton48989f32017-05-26 15:01:46 -06002526 }
2527 }
2528
Dave Houlton33c2d252017-06-09 17:08:32 -06002529 bool oob = false;
Dave Houlton48989f32017-05-26 15:01:46 -06002530 if ((rgn.srcOffsets[0].x < 0) || (rgn.srcOffsets[0].x > static_cast<int32_t>(src_extent.width)) ||
2531 (rgn.srcOffsets[1].x < 0) || (rgn.srcOffsets[1].x > static_cast<int32_t>(src_extent.width))) {
Dave Houlton33c2d252017-06-09 17:08:32 -06002532 oob = true;
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06002533 skip |=
2534 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002535 HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_09a001e6,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06002536 "vkCmdBlitImage: region [%d] srcOffset[].x values (%1d, %1d) exceed srcSubresource width extent (%1d).",
2537 i, rgn.srcOffsets[0].x, rgn.srcOffsets[1].x, src_extent.width);
Dave Houlton48989f32017-05-26 15:01:46 -06002538 }
2539 if ((rgn.srcOffsets[0].y < 0) || (rgn.srcOffsets[0].y > static_cast<int32_t>(src_extent.height)) ||
2540 (rgn.srcOffsets[1].y < 0) || (rgn.srcOffsets[1].y > static_cast<int32_t>(src_extent.height))) {
Dave Houlton33c2d252017-06-09 17:08:32 -06002541 oob = true;
Dave Houlton48989f32017-05-26 15:01:46 -06002542 skip |= log_msg(
2543 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002544 HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_09a001e8,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06002545 "vkCmdBlitImage: region [%d] srcOffset[].y values (%1d, %1d) exceed srcSubresource height extent (%1d).", i,
2546 rgn.srcOffsets[0].y, rgn.srcOffsets[1].y, src_extent.height);
Dave Houlton48989f32017-05-26 15:01:46 -06002547 }
2548 if ((rgn.srcOffsets[0].z < 0) || (rgn.srcOffsets[0].z > static_cast<int32_t>(src_extent.depth)) ||
2549 (rgn.srcOffsets[1].z < 0) || (rgn.srcOffsets[1].z > static_cast<int32_t>(src_extent.depth))) {
Dave Houlton33c2d252017-06-09 17:08:32 -06002550 oob = true;
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06002551 skip |=
2552 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002553 HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_09a001ec,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06002554 "vkCmdBlitImage: region [%d] srcOffset[].z values (%1d, %1d) exceed srcSubresource depth extent (%1d).",
2555 i, rgn.srcOffsets[0].z, rgn.srcOffsets[1].z, src_extent.depth);
Dave Houlton48989f32017-05-26 15:01:46 -06002556 }
Dave Houlton33c2d252017-06-09 17:08:32 -06002557 if (rgn.srcSubresource.mipLevel >= src_image_state->createInfo.mipLevels) {
2558 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002559 HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_184001ae,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06002560 "vkCmdBlitImage: region [%d] source image, attempt to access a non-existant mip level %1d.", i,
2561 rgn.srcSubresource.mipLevel);
Dave Houlton33c2d252017-06-09 17:08:32 -06002562 } else if (oob) {
2563 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002564 HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_184001ae,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06002565 "vkCmdBlitImage: region [%d] source image blit region exceeds image dimensions.", i);
Dave Houlton33c2d252017-06-09 17:08:32 -06002566 }
Dave Houlton48989f32017-05-26 15:01:46 -06002567
2568 // Validate dest image offsets
2569 VkExtent3D dst_extent = GetImageSubresourceExtent(dst_image_state, &(rgn.dstSubresource));
Dave Houlton33c2d252017-06-09 17:08:32 -06002570 if (VK_IMAGE_TYPE_1D == dst_type) {
Dave Houlton48989f32017-05-26 15:01:46 -06002571 if ((0 != rgn.dstOffsets[0].y) || (1 != rgn.dstOffsets[1].y)) {
2572 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002573 HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_09a001f4,
Dave Houlton48989f32017-05-26 15:01:46 -06002574 "vkCmdBlitImage: region [%d], dest image of type VK_IMAGE_TYPE_1D with dstOffset[].y values of "
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06002575 "(%1d, %1d). These must be (0, 1).",
2576 i, rgn.dstOffsets[0].y, rgn.dstOffsets[1].y);
Dave Houlton48989f32017-05-26 15:01:46 -06002577 }
2578 }
2579
Dave Houlton33c2d252017-06-09 17:08:32 -06002580 if ((VK_IMAGE_TYPE_1D == dst_type) || (VK_IMAGE_TYPE_2D == dst_type)) {
Dave Houlton48989f32017-05-26 15:01:46 -06002581 if ((0 != rgn.dstOffsets[0].z) || (1 != rgn.dstOffsets[1].z)) {
2582 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002583 HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_09a001f8,
Dave Houlton48989f32017-05-26 15:01:46 -06002584 "vkCmdBlitImage: region [%d], dest image of type VK_IMAGE_TYPE_1D or VK_IMAGE_TYPE_2D with "
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06002585 "dstOffset[].z values of (%1d, %1d). These must be (0, 1).",
2586 i, rgn.dstOffsets[0].z, rgn.dstOffsets[1].z);
Dave Houlton48989f32017-05-26 15:01:46 -06002587 }
2588 }
2589
Dave Houlton33c2d252017-06-09 17:08:32 -06002590 oob = false;
Dave Houlton48989f32017-05-26 15:01:46 -06002591 if ((rgn.dstOffsets[0].x < 0) || (rgn.dstOffsets[0].x > static_cast<int32_t>(dst_extent.width)) ||
2592 (rgn.dstOffsets[1].x < 0) || (rgn.dstOffsets[1].x > static_cast<int32_t>(dst_extent.width))) {
Dave Houlton33c2d252017-06-09 17:08:32 -06002593 oob = true;
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06002594 skip |=
2595 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002596 HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_09a001f0,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06002597 "vkCmdBlitImage: region [%d] dstOffset[].x values (%1d, %1d) exceed dstSubresource width extent (%1d).",
2598 i, rgn.dstOffsets[0].x, rgn.dstOffsets[1].x, dst_extent.width);
Dave Houlton48989f32017-05-26 15:01:46 -06002599 }
2600 if ((rgn.dstOffsets[0].y < 0) || (rgn.dstOffsets[0].y > static_cast<int32_t>(dst_extent.height)) ||
2601 (rgn.dstOffsets[1].y < 0) || (rgn.dstOffsets[1].y > static_cast<int32_t>(dst_extent.height))) {
Dave Houlton33c2d252017-06-09 17:08:32 -06002602 oob = true;
Dave Houlton48989f32017-05-26 15:01:46 -06002603 skip |= log_msg(
2604 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002605 HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_09a001f2,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06002606 "vkCmdBlitImage: region [%d] dstOffset[].y values (%1d, %1d) exceed dstSubresource height extent (%1d).", i,
2607 rgn.dstOffsets[0].y, rgn.dstOffsets[1].y, dst_extent.height);
Dave Houlton48989f32017-05-26 15:01:46 -06002608 }
2609 if ((rgn.dstOffsets[0].z < 0) || (rgn.dstOffsets[0].z > static_cast<int32_t>(dst_extent.depth)) ||
2610 (rgn.dstOffsets[1].z < 0) || (rgn.dstOffsets[1].z > static_cast<int32_t>(dst_extent.depth))) {
Dave Houlton33c2d252017-06-09 17:08:32 -06002611 oob = true;
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06002612 skip |=
2613 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002614 HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_09a001f6,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06002615 "vkCmdBlitImage: region [%d] dstOffset[].z values (%1d, %1d) exceed dstSubresource depth extent (%1d).",
2616 i, rgn.dstOffsets[0].z, rgn.dstOffsets[1].z, dst_extent.depth);
Dave Houlton48989f32017-05-26 15:01:46 -06002617 }
Dave Houlton33c2d252017-06-09 17:08:32 -06002618 if (rgn.dstSubresource.mipLevel >= dst_image_state->createInfo.mipLevels) {
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002619 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002620 HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_184001b0,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06002621 "vkCmdBlitImage: region [%d] destination image, attempt to access a non-existant mip level %1d.", i,
2622 rgn.dstSubresource.mipLevel);
Dave Houlton33c2d252017-06-09 17:08:32 -06002623 } else if (oob) {
2624 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002625 HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_184001b0,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06002626 "vkCmdBlitImage: region [%d] destination image blit region exceeds image dimensions.", i);
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002627 }
2628
Dave Houlton33c2d252017-06-09 17:08:32 -06002629 if ((VK_IMAGE_TYPE_3D == src_type) || (VK_IMAGE_TYPE_3D == dst_type)) {
2630 if ((0 != rgn.srcSubresource.baseArrayLayer) || (1 != rgn.srcSubresource.layerCount) ||
2631 (0 != rgn.dstSubresource.baseArrayLayer) || (1 != rgn.dstSubresource.layerCount)) {
2632 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002633 HandleToUint64(cb_node->commandBuffer), VALIDATION_ERROR_09a001e0,
Dave Houlton33c2d252017-06-09 17:08:32 -06002634 "vkCmdBlitImage: region [%d] blit to/from a 3D image type with a non-zero baseArrayLayer, or a "
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06002635 "layerCount other than 1.",
2636 i);
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002637 }
2638 }
Dave Houlton33c2d252017-06-09 17:08:32 -06002639 } // per-region checks
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07002640 } else {
2641 assert(0);
2642 }
2643 return skip;
2644}
2645
Tobin Ehlis58c884f2017-02-08 12:15:27 -07002646void PreCallRecordCmdBlitImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state,
Norbert Garnys7bd4c2c2017-11-16 10:58:04 +01002647 IMAGE_STATE *dst_image_state, uint32_t region_count, const VkImageBlit *regions,
2648 VkImageLayout src_image_layout, VkImageLayout dst_image_layout) {
2649 // Make sure that all image slices are updated to correct layout
2650 for (uint32_t i = 0; i < region_count; ++i) {
2651 SetImageLayout(device_data, cb_node, src_image_state, regions[i].srcSubresource, src_image_layout);
2652 SetImageLayout(device_data, cb_node, dst_image_state, regions[i].dstSubresource, dst_image_layout);
2653 }
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07002654 // Update bindings between images and cmd buffer
2655 AddCommandBufferBindingImage(device_data, cb_node, src_image_state);
2656 AddCommandBufferBindingImage(device_data, cb_node, dst_image_state);
2657
2658 std::function<bool()> function = [=]() { return ValidateImageMemoryIsValid(device_data, src_image_state, "vkCmdBlitImage()"); };
Tobin Ehlisa17a5292017-07-28 12:11:30 -06002659 cb_node->queue_submit_functions.push_back(function);
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07002660 function = [=]() {
2661 SetImageMemoryValid(device_data, dst_image_state, true);
2662 return false;
2663 };
Tobin Ehlisa17a5292017-07-28 12:11:30 -06002664 cb_node->queue_submit_functions.push_back(function);
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07002665}
2666
Tony Barbourdf013b92017-01-25 12:53:48 -07002667// This validates that the initial layout specified in the command buffer for
2668// the IMAGE is the same
2669// as the global IMAGE layout
Tony Barboure0c5cc92017-02-08 13:53:39 -07002670bool ValidateCmdBufImageLayouts(layer_data *device_data, GLOBAL_CB_NODE *pCB,
Dave Houltona9df0ce2018-02-07 10:51:23 -07002671 std::unordered_map<ImageSubresourcePair, IMAGE_LAYOUT_NODE> const &globalImageLayoutMap,
2672 std::unordered_map<ImageSubresourcePair, IMAGE_LAYOUT_NODE> &overlayLayoutMap) {
Mark Lobodzinskib0dd9472017-02-07 16:38:17 -07002673 bool skip = false;
Tony Barbourdf013b92017-01-25 12:53:48 -07002674 const debug_report_data *report_data = core_validation::GetReportData(device_data);
Mark Lobodzinski4a3065e2017-02-07 16:36:03 -07002675 for (auto cb_image_data : pCB->imageLayoutMap) {
2676 VkImageLayout imageLayout;
Tony Barbourdf013b92017-01-25 12:53:48 -07002677
Dave Houltonb3f4b282018-02-22 16:25:16 -07002678 if (FindLayout(device_data, overlayLayoutMap, cb_image_data.first, imageLayout) ||
2679 FindLayout(device_data, globalImageLayoutMap, cb_image_data.first, imageLayout)) {
Mark Lobodzinski4a3065e2017-02-07 16:36:03 -07002680 if (cb_image_data.second.initialLayout == VK_IMAGE_LAYOUT_UNDEFINED) {
2681 // TODO: Set memory invalid which is in mem_tracker currently
2682 } else if (imageLayout != cb_image_data.second.initialLayout) {
2683 if (cb_image_data.first.hasSubresource) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07002684 skip |= log_msg(
2685 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002686 HandleToUint64(pCB->commandBuffer), DRAWSTATE_INVALID_IMAGE_LAYOUT,
Dave Houltona9df0ce2018-02-07 10:51:23 -07002687 "Cannot submit cmd buffer using image (0x%" PRIx64
2688 ") [sub-resource: aspectMask 0x%X array layer %u, mip level %u], with layout %s when first use is %s.",
2689 HandleToUint64(cb_image_data.first.image), cb_image_data.first.subresource.aspectMask,
2690 cb_image_data.first.subresource.arrayLayer, cb_image_data.first.subresource.mipLevel,
2691 string_VkImageLayout(imageLayout), string_VkImageLayout(cb_image_data.second.initialLayout));
Mark Lobodzinski4a3065e2017-02-07 16:36:03 -07002692 } else {
Petr Krausbc7f5442017-05-14 23:43:38 +02002693 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002694 HandleToUint64(pCB->commandBuffer), DRAWSTATE_INVALID_IMAGE_LAYOUT,
Dave Houltona9df0ce2018-02-07 10:51:23 -07002695 "Cannot submit cmd buffer using image (0x%" PRIx64 ") with layout %s when first use is %s.",
Petr Krausbc7f5442017-05-14 23:43:38 +02002696 HandleToUint64(cb_image_data.first.image), string_VkImageLayout(imageLayout),
2697 string_VkImageLayout(cb_image_data.second.initialLayout));
Mark Lobodzinski4a3065e2017-02-07 16:36:03 -07002698 }
2699 }
Chris Forbesf9d7acd2017-06-26 17:57:39 -07002700 SetLayout(overlayLayoutMap, cb_image_data.first, cb_image_data.second.layout);
Mark Lobodzinski4a3065e2017-02-07 16:36:03 -07002701 }
2702 }
Mark Lobodzinskib0dd9472017-02-07 16:38:17 -07002703 return skip;
Mark Lobodzinski4a3065e2017-02-07 16:36:03 -07002704}
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002705
Tony Barbourdf013b92017-01-25 12:53:48 -07002706void UpdateCmdBufImageLayouts(layer_data *device_data, GLOBAL_CB_NODE *pCB) {
2707 for (auto cb_image_data : pCB->imageLayoutMap) {
2708 VkImageLayout imageLayout;
2709 FindGlobalLayout(device_data, cb_image_data.first, imageLayout);
2710 SetGlobalLayout(device_data, cb_image_data.first, cb_image_data.second.layout);
2711 }
2712}
2713
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002714// Print readable FlagBits in FlagMask
2715static std::string string_VkAccessFlags(VkAccessFlags accessMask) {
2716 std::string result;
2717 std::string separator;
2718
2719 if (accessMask == 0) {
2720 result = "[None]";
2721 } else {
2722 result = "[";
2723 for (auto i = 0; i < 32; i++) {
2724 if (accessMask & (1 << i)) {
2725 result = result + separator + string_VkAccessFlagBits((VkAccessFlagBits)(1 << i));
2726 separator = " | ";
2727 }
2728 }
2729 result = result + "]";
2730 }
2731 return result;
2732}
2733
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002734// AccessFlags MUST have 'required_bit' set, and may have one or more of 'optional_bits' set. If required_bit is zero, accessMask
2735// must have at least one of 'optional_bits' set
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002736// TODO: Add tracking to ensure that at least one barrier has been set for these layout transitions
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002737static bool ValidateMaskBits(core_validation::layer_data *device_data, VkCommandBuffer cmdBuffer, const VkAccessFlags &accessMask,
2738 const VkImageLayout &layout, VkAccessFlags required_bit, VkAccessFlags optional_bits,
2739 const char *type) {
2740 const debug_report_data *report_data = core_validation::GetReportData(device_data);
2741 bool skip = false;
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002742
2743 if ((accessMask & required_bit) || (!required_bit && (accessMask & optional_bits))) {
2744 if (accessMask & ~(required_bit | optional_bits)) {
2745 // TODO: Verify against Valid Use
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06002746 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002747 HandleToUint64(cmdBuffer), DRAWSTATE_INVALID_BARRIER,
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002748 "Additional bits in %s accessMask 0x%X %s are specified when layout is %s.", type, accessMask,
2749 string_VkAccessFlags(accessMask).c_str(), string_VkImageLayout(layout));
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002750 }
2751 } else {
2752 if (!required_bit) {
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06002753 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002754 HandleToUint64(cmdBuffer), DRAWSTATE_INVALID_BARRIER,
Dave Houltona9df0ce2018-02-07 10:51:23 -07002755 "%s AccessMask %d %s must contain at least one of access bits %d %s when layout is %s, unless the app "
2756 "has previously added a barrier for this transition.",
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002757 type, accessMask, string_VkAccessFlags(accessMask).c_str(), optional_bits,
2758 string_VkAccessFlags(optional_bits).c_str(), string_VkImageLayout(layout));
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002759 } else {
2760 std::string opt_bits;
2761 if (optional_bits != 0) {
2762 std::stringstream ss;
2763 ss << optional_bits;
2764 opt_bits = "and may have optional bits " + ss.str() + ' ' + string_VkAccessFlags(optional_bits);
2765 }
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06002766 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002767 HandleToUint64(cmdBuffer), DRAWSTATE_INVALID_BARRIER,
Dave Houltona9df0ce2018-02-07 10:51:23 -07002768 "%s AccessMask %d %s must have required access bit %d %s %s when layout is %s, unless the app has "
2769 "previously added a barrier for this transition.",
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002770 type, accessMask, string_VkAccessFlags(accessMask).c_str(), required_bit,
2771 string_VkAccessFlags(required_bit).c_str(), opt_bits.c_str(), string_VkImageLayout(layout));
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002772 }
2773 }
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002774 return skip;
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002775}
2776
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002777// ValidateLayoutVsAttachmentDescription is a general function where we can validate various state associated with the
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002778// VkAttachmentDescription structs that are used by the sub-passes of a renderpass. Initial check is to make sure that READ_ONLY
2779// layout attachments don't have CLEAR as their loadOp.
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002780bool ValidateLayoutVsAttachmentDescription(const debug_report_data *report_data, const VkImageLayout first_layout,
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002781 const uint32_t attachment, const VkAttachmentDescription &attachment_description) {
2782 bool skip = false;
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002783 // Verify that initial loadOp on READ_ONLY attachments is not CLEAR
2784 if (attachment_description.loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR) {
2785 if ((first_layout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL) ||
2786 (first_layout == VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL)) {
Mark Lobodzinskib1fd9d12018-03-30 14:26:00 -06002787 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002788 VALIDATION_ERROR_12200688, "Cannot clear attachment %d with invalid first layout %s.", attachment,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06002789 string_VkImageLayout(first_layout));
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002790 }
2791 }
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002792 return skip;
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002793}
2794
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002795bool ValidateLayouts(core_validation::layer_data *device_data, VkDevice device, const VkRenderPassCreateInfo *pCreateInfo) {
2796 const debug_report_data *report_data = core_validation::GetReportData(device_data);
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002797 bool skip = false;
2798
Jason Ekstranda1906302017-12-03 20:16:32 -08002799 for (uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) {
2800 VkFormat format = pCreateInfo->pAttachments[i].format;
2801 if (pCreateInfo->pAttachments[i].initialLayout == VK_IMAGE_LAYOUT_UNDEFINED) {
2802 if ((FormatIsColor(format) || FormatHasDepth(format)) &&
2803 pCreateInfo->pAttachments[i].loadOp == VK_ATTACHMENT_LOAD_OP_LOAD) {
Mark Lobodzinskib1fd9d12018-03-30 14:26:00 -06002804 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002805 DRAWSTATE_INVALID_RENDERPASS,
Dave Houltona9df0ce2018-02-07 10:51:23 -07002806 "Render pass has an attachment with loadOp == VK_ATTACHMENT_LOAD_OP_LOAD and initialLayout == "
2807 "VK_IMAGE_LAYOUT_UNDEFINED. This is probably not what you intended. Consider using "
2808 "VK_ATTACHMENT_LOAD_OP_DONT_CARE instead if the image truely is undefined at the start of the "
2809 "render pass.");
Jason Ekstranda1906302017-12-03 20:16:32 -08002810 }
Dave Houltona9df0ce2018-02-07 10:51:23 -07002811 if (FormatHasStencil(format) && pCreateInfo->pAttachments[i].stencilLoadOp == VK_ATTACHMENT_LOAD_OP_LOAD) {
Mark Lobodzinskib1fd9d12018-03-30 14:26:00 -06002812 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002813 DRAWSTATE_INVALID_RENDERPASS,
Dave Houltona9df0ce2018-02-07 10:51:23 -07002814 "Render pass has an attachment with stencilLoadOp == VK_ATTACHMENT_LOAD_OP_LOAD and initialLayout "
2815 "== VK_IMAGE_LAYOUT_UNDEFINED. This is probably not what you intended. Consider using "
2816 "VK_ATTACHMENT_LOAD_OP_DONT_CARE instead if the image truely is undefined at the start of the "
2817 "render pass.");
Jason Ekstranda1906302017-12-03 20:16:32 -08002818 }
2819 }
2820 }
2821
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002822 // Track when we're observing the first use of an attachment
2823 std::vector<bool> attach_first_use(pCreateInfo->attachmentCount, true);
2824 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
2825 const VkSubpassDescription &subpass = pCreateInfo->pSubpasses[i];
Cort Stratton7547f772017-05-04 15:18:52 -07002826
2827 // Check input attachments first, so we can detect first-use-as-input for VU #00349
2828 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
2829 auto attach_index = subpass.pInputAttachments[j].attachment;
2830 if (attach_index == VK_ATTACHMENT_UNUSED) continue;
2831
2832 switch (subpass.pInputAttachments[j].layout) {
2833 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL:
2834 case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL:
2835 // These are ideal.
2836 break;
2837
2838 case VK_IMAGE_LAYOUT_GENERAL:
2839 // May not be optimal. TODO: reconsider this warning based on other constraints.
2840 skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002841 VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, DRAWSTATE_INVALID_IMAGE_LAYOUT,
Cort Stratton7547f772017-05-04 15:18:52 -07002842 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
2843 break;
2844
2845 default:
2846 // No other layouts are acceptable
2847 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002848 DRAWSTATE_INVALID_IMAGE_LAYOUT,
Cort Stratton7547f772017-05-04 15:18:52 -07002849 "Layout for input attachment is %s but can only be READ_ONLY_OPTIMAL or GENERAL.",
2850 string_VkImageLayout(subpass.pInputAttachments[j].layout));
2851 }
2852
2853 VkImageLayout layout = subpass.pInputAttachments[j].layout;
2854 bool found_layout_mismatch = subpass.pDepthStencilAttachment &&
2855 subpass.pDepthStencilAttachment->attachment == attach_index &&
2856 subpass.pDepthStencilAttachment->layout != layout;
2857 for (uint32_t c = 0; !found_layout_mismatch && c < subpass.colorAttachmentCount; ++c) {
2858 found_layout_mismatch =
2859 (subpass.pColorAttachments[c].attachment == attach_index && subpass.pColorAttachments[c].layout != layout);
2860 }
2861 if (found_layout_mismatch) {
Mark Lobodzinskib1fd9d12018-03-30 14:26:00 -06002862 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002863 VALIDATION_ERROR_140006ae,
Dave Houltona9df0ce2018-02-07 10:51:23 -07002864 "CreateRenderPass: Subpass %u pInputAttachments[%u] (%u) has layout %u, but is also used as a "
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06002865 "depth/color attachment with a different layout.",
2866 i, j, attach_index, layout);
Cort Stratton7547f772017-05-04 15:18:52 -07002867 }
2868
2869 if (attach_first_use[attach_index]) {
2870 skip |= ValidateLayoutVsAttachmentDescription(report_data, subpass.pInputAttachments[j].layout, attach_index,
2871 pCreateInfo->pAttachments[attach_index]);
2872
2873 bool used_as_depth =
2874 (subpass.pDepthStencilAttachment != NULL && subpass.pDepthStencilAttachment->attachment == attach_index);
2875 bool used_as_color = false;
2876 for (uint32_t k = 0; !used_as_depth && !used_as_color && k < subpass.colorAttachmentCount; ++k) {
2877 used_as_color = (subpass.pColorAttachments[k].attachment == attach_index);
2878 }
2879 if (!used_as_depth && !used_as_color &&
2880 pCreateInfo->pAttachments[attach_index].loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR) {
2881 skip |= log_msg(
Mark Lobodzinskib1fd9d12018-03-30 14:26:00 -06002882 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002883 VALIDATION_ERROR_1400069c,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06002884 "CreateRenderPass: attachment %u is first used as an input attachment in subpass %u with loadOp=CLEAR.",
2885 attach_index, attach_index);
Cort Stratton7547f772017-05-04 15:18:52 -07002886 }
2887 }
2888 attach_first_use[attach_index] = false;
2889 }
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002890 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
2891 auto attach_index = subpass.pColorAttachments[j].attachment;
2892 if (attach_index == VK_ATTACHMENT_UNUSED) continue;
2893
Tobin Ehlisbb03e5f2017-05-11 08:52:51 -06002894 // TODO: Need a way to validate shared presentable images here, currently just allowing
2895 // VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR
2896 // as an acceptable layout, but need to make sure shared presentable images ONLY use that layout
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002897 switch (subpass.pColorAttachments[j].layout) {
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002898 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL:
Dave Houlton33c2d252017-06-09 17:08:32 -06002899 // This is ideal.
Tobin Ehlisbb03e5f2017-05-11 08:52:51 -06002900 case VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR:
2901 // TODO: See note above, just assuming that attachment is shared presentable and allowing this for now.
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002902 break;
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002903
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002904 case VK_IMAGE_LAYOUT_GENERAL:
2905 // May not be optimal; TODO: reconsider this warning based on other constraints?
2906 skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002907 VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, DRAWSTATE_INVALID_IMAGE_LAYOUT,
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002908 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
2909 break;
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002910
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002911 default:
2912 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002913 DRAWSTATE_INVALID_IMAGE_LAYOUT,
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002914 "Layout for color attachment is %s but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.",
2915 string_VkImageLayout(subpass.pColorAttachments[j].layout));
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002916 }
2917
2918 if (attach_first_use[attach_index]) {
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002919 skip |= ValidateLayoutVsAttachmentDescription(report_data, subpass.pColorAttachments[j].layout, attach_index,
2920 pCreateInfo->pAttachments[attach_index]);
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002921 }
2922 attach_first_use[attach_index] = false;
2923 }
Lenny Komowb79f04a2017-09-18 17:07:00 -06002924
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002925 if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
2926 switch (subpass.pDepthStencilAttachment->layout) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07002927 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
2928 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL:
2929 // These are ideal.
Lenny Komowb79f04a2017-09-18 17:07:00 -06002930 break;
Lenny Komowb79f04a2017-09-18 17:07:00 -06002931
Dave Houltona9df0ce2018-02-07 10:51:23 -07002932 case VK_IMAGE_LAYOUT_GENERAL:
2933 // May not be optimal; TODO: reconsider this warning based on other constraints? GENERAL can be better than
2934 // doing a bunch of transitions.
2935 skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002936 VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, DRAWSTATE_INVALID_IMAGE_LAYOUT,
Dave Houltona9df0ce2018-02-07 10:51:23 -07002937 "GENERAL layout for depth attachment may not give optimal performance.");
2938 break;
2939
2940 case VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL_KHR:
2941 case VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL_KHR:
2942 if (GetDeviceExtensions(device_data)->vk_khr_maintenance2) {
2943 break;
2944 } else {
2945 // Intentionally fall through to generic error message
2946 }
2947
2948 default:
2949 // No other layouts are acceptable
2950 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002951 DRAWSTATE_INVALID_IMAGE_LAYOUT,
Dave Houltona9df0ce2018-02-07 10:51:23 -07002952 "Layout for depth attachment is %s but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL, "
2953 "DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.",
2954 string_VkImageLayout(subpass.pDepthStencilAttachment->layout));
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002955 }
2956
2957 auto attach_index = subpass.pDepthStencilAttachment->attachment;
2958 if (attach_first_use[attach_index]) {
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002959 skip |= ValidateLayoutVsAttachmentDescription(report_data, subpass.pDepthStencilAttachment->layout, attach_index,
2960 pCreateInfo->pAttachments[attach_index]);
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002961 }
2962 attach_first_use[attach_index] = false;
2963 }
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002964 }
2965 return skip;
2966}
Mark Lobodzinski08f14fa2017-02-07 17:20:06 -07002967
2968// For any image objects that overlap mapped memory, verify that their layouts are PREINIT or GENERAL
Mark Lobodzinskiac23ec82017-02-07 17:21:55 -07002969bool ValidateMapImageLayouts(core_validation::layer_data *device_data, VkDevice device, DEVICE_MEM_INFO const *mem_info,
2970 VkDeviceSize offset, VkDeviceSize end_offset) {
2971 const debug_report_data *report_data = core_validation::GetReportData(device_data);
2972 bool skip = false;
2973 // Iterate over all bound image ranges and verify that for any that overlap the map ranges, the layouts are
2974 // VK_IMAGE_LAYOUT_PREINITIALIZED or VK_IMAGE_LAYOUT_GENERAL
Mark Lobodzinski08f14fa2017-02-07 17:20:06 -07002975 // TODO : This can be optimized if we store ranges based on starting address and early exit when we pass our range
2976 for (auto image_handle : mem_info->bound_images) {
2977 auto img_it = mem_info->bound_ranges.find(image_handle);
2978 if (img_it != mem_info->bound_ranges.end()) {
Mark Lobodzinskiac23ec82017-02-07 17:21:55 -07002979 if (rangesIntersect(device_data, &img_it->second, offset, end_offset)) {
Mark Lobodzinski08f14fa2017-02-07 17:20:06 -07002980 std::vector<VkImageLayout> layouts;
Mark Lobodzinskiac23ec82017-02-07 17:21:55 -07002981 if (FindLayouts(device_data, VkImage(image_handle), layouts)) {
Mark Lobodzinski08f14fa2017-02-07 17:20:06 -07002982 for (auto layout : layouts) {
2983 if (layout != VK_IMAGE_LAYOUT_PREINITIALIZED && layout != VK_IMAGE_LAYOUT_GENERAL) {
Petr Krausbc7f5442017-05-14 23:43:38 +02002984 skip |=
2985 log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_MEMORY_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06002986 HandleToUint64(mem_info->mem), DRAWSTATE_INVALID_IMAGE_LAYOUT,
Dave Houltona9df0ce2018-02-07 10:51:23 -07002987 "Mapping an image with layout %s can result in undefined behavior if this memory is used "
2988 "by the device. Only GENERAL or PREINITIALIZED should be used.",
Petr Krausbc7f5442017-05-14 23:43:38 +02002989 string_VkImageLayout(layout));
Mark Lobodzinski08f14fa2017-02-07 17:20:06 -07002990 }
2991 }
2992 }
2993 }
2994 }
2995 }
Mark Lobodzinskiac23ec82017-02-07 17:21:55 -07002996 return skip;
Mark Lobodzinski08f14fa2017-02-07 17:20:06 -07002997}
Mark Lobodzinski96210742017-02-09 10:33:46 -07002998
2999// Helper function to validate correct usage bits set for buffers or images. Verify that (actual & desired) flags != 0 or, if strict
3000// is true, verify that (actual & desired) flags == desired
Mark Lobodzinski95dbbe52017-02-09 10:40:41 -07003001static bool validate_usage_flags(layer_data *device_data, VkFlags actual, VkFlags desired, VkBool32 strict, uint64_t obj_handle,
Mark Lobodzinski33826372017-04-13 11:10:11 -06003002 VulkanObjectType obj_type, int32_t const msgCode, char const *func_name, char const *usage_str) {
Mark Lobodzinski95dbbe52017-02-09 10:40:41 -07003003 const debug_report_data *report_data = core_validation::GetReportData(device_data);
Mark Lobodzinski96210742017-02-09 10:33:46 -07003004
3005 bool correct_usage = false;
Mark Lobodzinski95dbbe52017-02-09 10:40:41 -07003006 bool skip = false;
Mark Lobodzinski33826372017-04-13 11:10:11 -06003007 const char *type_str = object_string[obj_type];
Mark Lobodzinski96210742017-02-09 10:33:46 -07003008 if (strict) {
3009 correct_usage = ((actual & desired) == desired);
3010 } else {
3011 correct_usage = ((actual & desired) != 0);
3012 }
3013 if (!correct_usage) {
3014 if (msgCode == -1) {
3015 // TODO: Fix callers with msgCode == -1 to use correct validation checks.
Dave Houltona9df0ce2018-02-07 10:51:23 -07003016 skip =
Mark Lobodzinskib1fd9d12018-03-30 14:26:00 -06003017 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, get_debug_report_enum[obj_type], obj_handle,
Mark Lobodzinski88529492018-04-01 10:38:15 -06003018 MEMTRACK_INVALID_USAGE_FLAG,
Dave Houltona9df0ce2018-02-07 10:51:23 -07003019 "Invalid usage flag for %s 0x%" PRIx64 " used by %s. In this case, %s should have %s set during creation.",
3020 type_str, obj_handle, func_name, type_str, usage_str);
Mark Lobodzinski96210742017-02-09 10:33:46 -07003021 } else {
Mark Lobodzinskib1fd9d12018-03-30 14:26:00 -06003022 skip =
Mark Lobodzinski88529492018-04-01 10:38:15 -06003023 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, get_debug_report_enum[obj_type], obj_handle, msgCode,
Mark Lobodzinskib1fd9d12018-03-30 14:26:00 -06003024 "Invalid usage flag for %s 0x%" PRIx64 " used by %s. In this case, %s should have %s set during creation.",
3025 type_str, obj_handle, func_name, type_str, usage_str);
Mark Lobodzinski96210742017-02-09 10:33:46 -07003026 }
3027 }
Mark Lobodzinski95dbbe52017-02-09 10:40:41 -07003028 return skip;
Mark Lobodzinski96210742017-02-09 10:33:46 -07003029}
3030
3031// Helper function to validate usage flags for buffers. For given buffer_state send actual vs. desired usage off to helper above
3032// where an error will be flagged if usage is not correct
Chris Forbes8fdba302017-04-24 18:34:28 -07003033bool ValidateImageUsageFlags(layer_data *device_data, IMAGE_STATE const *image_state, VkFlags desired, bool strict,
Mark Lobodzinski96210742017-02-09 10:33:46 -07003034 int32_t const msgCode, char const *func_name, char const *usage_string) {
Petr Krausbc7f5442017-05-14 23:43:38 +02003035 return validate_usage_flags(device_data, image_state->createInfo.usage, desired, strict, HandleToUint64(image_state->image),
3036 kVulkanObjectTypeImage, msgCode, func_name, usage_string);
Mark Lobodzinski96210742017-02-09 10:33:46 -07003037}
3038
3039// Helper function to validate usage flags for buffers. For given buffer_state send actual vs. desired usage off to helper above
3040// where an error will be flagged if usage is not correct
Chris Forbes8fdba302017-04-24 18:34:28 -07003041bool ValidateBufferUsageFlags(layer_data *device_data, BUFFER_STATE const *buffer_state, VkFlags desired, bool strict,
Mark Lobodzinski96210742017-02-09 10:33:46 -07003042 int32_t const msgCode, char const *func_name, char const *usage_string) {
Petr Krausbc7f5442017-05-14 23:43:38 +02003043 return validate_usage_flags(device_data, buffer_state->createInfo.usage, desired, strict, HandleToUint64(buffer_state->buffer),
3044 kVulkanObjectTypeBuffer, msgCode, func_name, usage_string);
Mark Lobodzinski96210742017-02-09 10:33:46 -07003045}
3046
Mark Lobodzinski95dbbe52017-02-09 10:40:41 -07003047bool PreCallValidateCreateBuffer(layer_data *device_data, const VkBufferCreateInfo *pCreateInfo) {
Mark Lobodzinski96210742017-02-09 10:33:46 -07003048 bool skip = false;
Mark Lobodzinski847b60c2017-03-13 09:32:45 -06003049 const debug_report_data *report_data = core_validation::GetReportData(device_data);
3050
Chris Forbese0f511c2017-06-14 12:38:01 -07003051 // TODO: Add check for VALIDATION_ERROR_1ec0071e (sparse address space accounting)
Mark Lobodzinski847b60c2017-03-13 09:32:45 -06003052
3053 if ((pCreateInfo->flags & VK_BUFFER_CREATE_SPARSE_BINDING_BIT) && (!GetEnabledFeatures(device_data)->sparseBinding)) {
Mark Lobodzinskib1fd9d12018-03-30 14:26:00 -06003054 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
Mark Lobodzinski88529492018-04-01 10:38:15 -06003055 VALIDATION_ERROR_01400726,
Mark Lobodzinski847b60c2017-03-13 09:32:45 -06003056 "vkCreateBuffer(): the sparseBinding device feature is disabled: Buffers cannot be created with the "
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06003057 "VK_BUFFER_CREATE_SPARSE_BINDING_BIT set.");
Mark Lobodzinski847b60c2017-03-13 09:32:45 -06003058 }
Mark Lobodzinskiaf355062017-03-13 09:35:01 -06003059
3060 if ((pCreateInfo->flags & VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT) && (!GetEnabledFeatures(device_data)->sparseResidencyBuffer)) {
Mark Lobodzinskib1fd9d12018-03-30 14:26:00 -06003061 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
Mark Lobodzinski88529492018-04-01 10:38:15 -06003062 VALIDATION_ERROR_01400728,
Dave Houltona9df0ce2018-02-07 10:51:23 -07003063 "vkCreateBuffer(): the sparseResidencyBuffer device feature is disabled: Buffers cannot be created with "
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06003064 "the VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT set.");
Mark Lobodzinskiaf355062017-03-13 09:35:01 -06003065 }
Mark Lobodzinski035a4cf2017-03-13 09:45:07 -06003066
3067 if ((pCreateInfo->flags & VK_BUFFER_CREATE_SPARSE_ALIASED_BIT) && (!GetEnabledFeatures(device_data)->sparseResidencyAliased)) {
Mark Lobodzinskib1fd9d12018-03-30 14:26:00 -06003068 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
Mark Lobodzinski88529492018-04-01 10:38:15 -06003069 VALIDATION_ERROR_0140072a,
Dave Houltona9df0ce2018-02-07 10:51:23 -07003070 "vkCreateBuffer(): the sparseResidencyAliased device feature is disabled: Buffers cannot be created with "
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06003071 "the VK_BUFFER_CREATE_SPARSE_ALIASED_BIT set.");
Mark Lobodzinski035a4cf2017-03-13 09:45:07 -06003072 }
Mark Lobodzinski96210742017-02-09 10:33:46 -07003073 return skip;
3074}
3075
3076void PostCallRecordCreateBuffer(layer_data *device_data, const VkBufferCreateInfo *pCreateInfo, VkBuffer *pBuffer) {
3077 // TODO : This doesn't create deep copy of pQueueFamilyIndices so need to fix that if/when we want that data to be valid
3078 GetBufferMap(device_data)
3079 ->insert(std::make_pair(*pBuffer, std::unique_ptr<BUFFER_STATE>(new BUFFER_STATE(*pBuffer, pCreateInfo))));
3080}
3081
Mark Lobodzinski95dbbe52017-02-09 10:40:41 -07003082bool PreCallValidateCreateBufferView(layer_data *device_data, const VkBufferViewCreateInfo *pCreateInfo) {
3083 bool skip = false;
3084 BUFFER_STATE *buffer_state = GetBufferState(device_data, pCreateInfo->buffer);
Mark Lobodzinski96210742017-02-09 10:33:46 -07003085 // If this isn't a sparse buffer, it needs to have memory backing it at CreateBufferView time
3086 if (buffer_state) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003087 skip |= ValidateMemoryIsBoundToBuffer(device_data, buffer_state, "vkCreateBufferView()", VALIDATION_ERROR_01a0074e);
Mark Lobodzinski96210742017-02-09 10:33:46 -07003088 // In order to create a valid buffer view, the buffer must have been created with at least one of the following flags:
3089 // UNIFORM_TEXEL_BUFFER_BIT or STORAGE_TEXEL_BUFFER_BIT
Mark Lobodzinski95dbbe52017-02-09 10:40:41 -07003090 skip |= ValidateBufferUsageFlags(
3091 device_data, buffer_state, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT, false,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003092 VALIDATION_ERROR_01a00748, "vkCreateBufferView()", "VK_BUFFER_USAGE_[STORAGE|UNIFORM]_TEXEL_BUFFER_BIT");
Mark Lobodzinski96210742017-02-09 10:33:46 -07003093 }
Mark Lobodzinski95dbbe52017-02-09 10:40:41 -07003094 return skip;
Mark Lobodzinski96210742017-02-09 10:33:46 -07003095}
3096
3097void PostCallRecordCreateBufferView(layer_data *device_data, const VkBufferViewCreateInfo *pCreateInfo, VkBufferView *pView) {
3098 (*GetBufferViewMap(device_data))[*pView] = std::unique_ptr<BUFFER_VIEW_STATE>(new BUFFER_VIEW_STATE(*pView, pCreateInfo));
3099}
Mark Lobodzinski602de982017-02-09 11:01:33 -07003100
3101// For the given format verify that the aspect masks make sense
3102bool ValidateImageAspectMask(layer_data *device_data, VkImage image, VkFormat format, VkImageAspectFlags aspect_mask,
3103 const char *func_name) {
3104 const debug_report_data *report_data = core_validation::GetReportData(device_data);
3105 bool skip = false;
Dave Houlton1d2022c2017-03-29 11:43:58 -06003106 if (FormatIsColor(format)) {
Mark Lobodzinski602de982017-02-09 11:01:33 -07003107 if ((aspect_mask & VK_IMAGE_ASPECT_COLOR_BIT) != VK_IMAGE_ASPECT_COLOR_BIT) {
Petr Krausbc7f5442017-05-14 23:43:38 +02003108 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06003109 HandleToUint64(image), VALIDATION_ERROR_0a400c01,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06003110 "%s: Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.", func_name);
Mark Lobodzinski602de982017-02-09 11:01:33 -07003111 } else if ((aspect_mask & VK_IMAGE_ASPECT_COLOR_BIT) != aspect_mask) {
Petr Krausbc7f5442017-05-14 23:43:38 +02003112 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06003113 HandleToUint64(image), VALIDATION_ERROR_0a400c01,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06003114 "%s: Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.", func_name);
Mark Lobodzinski602de982017-02-09 11:01:33 -07003115 }
Dave Houlton1d2022c2017-03-29 11:43:58 -06003116 } else if (FormatIsDepthAndStencil(format)) {
Mark Lobodzinski602de982017-02-09 11:01:33 -07003117 if ((aspect_mask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) == 0) {
Petr Krausbc7f5442017-05-14 23:43:38 +02003118 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06003119 HandleToUint64(image), VALIDATION_ERROR_0a400c01,
Dave Houltona9df0ce2018-02-07 10:51:23 -07003120 "%s: Depth/stencil image formats must have at least one of VK_IMAGE_ASPECT_DEPTH_BIT and "
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06003121 "VK_IMAGE_ASPECT_STENCIL_BIT set.",
3122 func_name);
Mark Lobodzinski602de982017-02-09 11:01:33 -07003123 } else if ((aspect_mask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) != aspect_mask) {
Petr Krausbc7f5442017-05-14 23:43:38 +02003124 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06003125 HandleToUint64(image), VALIDATION_ERROR_0a400c01,
Mark Lobodzinski602de982017-02-09 11:01:33 -07003126 "%s: Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and "
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06003127 "VK_IMAGE_ASPECT_STENCIL_BIT set.",
3128 func_name);
Mark Lobodzinski602de982017-02-09 11:01:33 -07003129 }
Dave Houlton1d2022c2017-03-29 11:43:58 -06003130 } else if (FormatIsDepthOnly(format)) {
Mark Lobodzinski602de982017-02-09 11:01:33 -07003131 if ((aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) != VK_IMAGE_ASPECT_DEPTH_BIT) {
Petr Krausbc7f5442017-05-14 23:43:38 +02003132 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06003133 HandleToUint64(image), VALIDATION_ERROR_0a400c01,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06003134 "%s: Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.", func_name);
Mark Lobodzinski602de982017-02-09 11:01:33 -07003135 } else if ((aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) != aspect_mask) {
Petr Krausbc7f5442017-05-14 23:43:38 +02003136 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06003137 HandleToUint64(image), VALIDATION_ERROR_0a400c01,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06003138 "%s: Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.", func_name);
Mark Lobodzinski602de982017-02-09 11:01:33 -07003139 }
Dave Houlton1d2022c2017-03-29 11:43:58 -06003140 } else if (FormatIsStencilOnly(format)) {
Mark Lobodzinski602de982017-02-09 11:01:33 -07003141 if ((aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) != VK_IMAGE_ASPECT_STENCIL_BIT) {
Petr Krausbc7f5442017-05-14 23:43:38 +02003142 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06003143 HandleToUint64(image), VALIDATION_ERROR_0a400c01,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06003144 "%s: Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.", func_name);
Mark Lobodzinski602de982017-02-09 11:01:33 -07003145 } else if ((aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) != aspect_mask) {
Petr Krausbc7f5442017-05-14 23:43:38 +02003146 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06003147 HandleToUint64(image), VALIDATION_ERROR_0a400c01,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06003148 "%s: Stencil-only image formats can have only the VK_IMAGE_ASPECT_STENCIL_BIT set.", func_name);
Mark Lobodzinski602de982017-02-09 11:01:33 -07003149 }
3150 }
3151 return skip;
3152}
3153
Petr Krausffa94af2017-08-08 21:46:02 +02003154struct SubresourceRangeErrorCodes {
3155 UNIQUE_VALIDATION_ERROR_CODE base_mip_err, mip_count_err, base_layer_err, layer_count_err;
3156};
3157
3158bool ValidateImageSubresourceRange(const layer_data *device_data, const uint32_t image_mip_count, const uint32_t image_layer_count,
3159 const VkImageSubresourceRange &subresourceRange, const char *cmd_name, const char *param_name,
3160 const char *image_layer_count_var_name, const uint64_t image_handle,
3161 SubresourceRangeErrorCodes errorCodes) {
Mark Lobodzinski602de982017-02-09 11:01:33 -07003162 const debug_report_data *report_data = core_validation::GetReportData(device_data);
3163 bool skip = false;
Petr Kraus4d718682017-05-18 03:38:41 +02003164
3165 // Validate mip levels
Petr Krausffa94af2017-08-08 21:46:02 +02003166 if (subresourceRange.baseMipLevel >= image_mip_count) {
Mark Lobodzinskib1fd9d12018-03-30 14:26:00 -06003167 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, image_handle,
Mark Lobodzinski88529492018-04-01 10:38:15 -06003168 errorCodes.base_mip_err,
Petr Krausffa94af2017-08-08 21:46:02 +02003169 "%s: %s.baseMipLevel (= %" PRIu32
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06003170 ") is greater or equal to the mip level count of the image (i.e. greater or equal to %" PRIu32 ").",
3171 cmd_name, param_name, subresourceRange.baseMipLevel, image_mip_count);
Petr Krausffa94af2017-08-08 21:46:02 +02003172 }
Petr Kraus4d718682017-05-18 03:38:41 +02003173
Petr Krausffa94af2017-08-08 21:46:02 +02003174 if (subresourceRange.levelCount != VK_REMAINING_MIP_LEVELS) {
3175 if (subresourceRange.levelCount == 0) {
3176 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, image_handle,
Mark Lobodzinski88529492018-04-01 10:38:15 -06003177 errorCodes.mip_count_err, "%s: %s.levelCount is 0.", cmd_name, param_name);
Petr Krausffa94af2017-08-08 21:46:02 +02003178 } else {
3179 const uint64_t necessary_mip_count = uint64_t{subresourceRange.baseMipLevel} + uint64_t{subresourceRange.levelCount};
Petr Kraus4d718682017-05-18 03:38:41 +02003180
Petr Krausffa94af2017-08-08 21:46:02 +02003181 if (necessary_mip_count > image_mip_count) {
3182 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, image_handle,
Mark Lobodzinski88529492018-04-01 10:38:15 -06003183 errorCodes.mip_count_err,
Petr Krausffa94af2017-08-08 21:46:02 +02003184 "%s: %s.baseMipLevel + .levelCount (= %" PRIu32 " + %" PRIu32 " = %" PRIu64
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06003185 ") is greater than the mip level count of the image (i.e. greater than %" PRIu32 ").",
Petr Krausffa94af2017-08-08 21:46:02 +02003186 cmd_name, param_name, subresourceRange.baseMipLevel, subresourceRange.levelCount,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06003187 necessary_mip_count, image_mip_count);
Petr Krausffa94af2017-08-08 21:46:02 +02003188 }
Petr Kraus4d718682017-05-18 03:38:41 +02003189 }
Mark Lobodzinski602de982017-02-09 11:01:33 -07003190 }
Petr Kraus4d718682017-05-18 03:38:41 +02003191
3192 // Validate array layers
Petr Krausffa94af2017-08-08 21:46:02 +02003193 if (subresourceRange.baseArrayLayer >= image_layer_count) {
Mark Lobodzinskib1fd9d12018-03-30 14:26:00 -06003194 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, image_handle,
Mark Lobodzinski88529492018-04-01 10:38:15 -06003195 errorCodes.base_layer_err,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06003196 "%s: %s.baseArrayLayer (= %" PRIu32
3197 ") is greater or equal to the %s of the image when it was created (i.e. greater or equal to %" PRIu32 ").",
3198 cmd_name, param_name, subresourceRange.baseArrayLayer, image_layer_count_var_name, image_layer_count);
Petr Krausffa94af2017-08-08 21:46:02 +02003199 }
Petr Kraus4d718682017-05-18 03:38:41 +02003200
Petr Krausffa94af2017-08-08 21:46:02 +02003201 if (subresourceRange.layerCount != VK_REMAINING_ARRAY_LAYERS) {
3202 if (subresourceRange.layerCount == 0) {
3203 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, image_handle,
Mark Lobodzinski88529492018-04-01 10:38:15 -06003204 errorCodes.layer_count_err, "%s: %s.layerCount is 0.", cmd_name, param_name);
Petr Krausffa94af2017-08-08 21:46:02 +02003205 } else {
3206 const uint64_t necessary_layer_count =
3207 uint64_t{subresourceRange.baseArrayLayer} + uint64_t{subresourceRange.layerCount};
Petr Kraus8423f152017-05-26 01:20:04 +02003208
Petr Krausffa94af2017-08-08 21:46:02 +02003209 if (necessary_layer_count > image_layer_count) {
3210 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, image_handle,
Mark Lobodzinski88529492018-04-01 10:38:15 -06003211 errorCodes.layer_count_err,
Petr Krausffa94af2017-08-08 21:46:02 +02003212 "%s: %s.baseArrayLayer + .layerCount (= %" PRIu32 " + %" PRIu32 " = %" PRIu64
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06003213 ") is greater than the %s of the image when it was created (i.e. greater than %" PRIu32 ").",
Petr Krausffa94af2017-08-08 21:46:02 +02003214 cmd_name, param_name, subresourceRange.baseArrayLayer, subresourceRange.layerCount,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06003215 necessary_layer_count, image_layer_count_var_name, image_layer_count);
Petr Krausffa94af2017-08-08 21:46:02 +02003216 }
Petr Kraus4d718682017-05-18 03:38:41 +02003217 }
Mark Lobodzinski602de982017-02-09 11:01:33 -07003218 }
Petr Kraus4d718682017-05-18 03:38:41 +02003219
Mark Lobodzinski602de982017-02-09 11:01:33 -07003220 return skip;
3221}
3222
Petr Krausffa94af2017-08-08 21:46:02 +02003223bool ValidateCreateImageViewSubresourceRange(const layer_data *device_data, const IMAGE_STATE *image_state,
3224 bool is_imageview_2d_type, const VkImageSubresourceRange &subresourceRange) {
3225 bool is_khr_maintenance1 = GetDeviceExtensions(device_data)->vk_khr_maintenance1;
3226 bool is_image_slicable = image_state->createInfo.imageType == VK_IMAGE_TYPE_3D &&
3227 (image_state->createInfo.flags & VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT_KHR);
3228 bool is_3D_to_2D_map = is_khr_maintenance1 && is_image_slicable && is_imageview_2d_type;
3229
3230 const auto image_layer_count = is_3D_to_2D_map ? image_state->createInfo.extent.depth : image_state->createInfo.arrayLayers;
3231 const auto image_layer_count_var_name = is_3D_to_2D_map ? "extent.depth" : "arrayLayers";
3232
3233 SubresourceRangeErrorCodes subresourceRangeErrorCodes = {};
3234 subresourceRangeErrorCodes.base_mip_err = VALIDATION_ERROR_0ac00b8c;
Mike Schuchardt8da1bb52018-02-22 10:46:31 -07003235 subresourceRangeErrorCodes.mip_count_err = VALIDATION_ERROR_0ac00d6c;
Petr Krausffa94af2017-08-08 21:46:02 +02003236 subresourceRangeErrorCodes.base_layer_err =
3237 is_khr_maintenance1 ? (is_3D_to_2D_map ? VALIDATION_ERROR_0ac00b98 : VALIDATION_ERROR_0ac00b94) : VALIDATION_ERROR_0ac00b90;
3238 subresourceRangeErrorCodes.layer_count_err =
Mike Schuchardt8da1bb52018-02-22 10:46:31 -07003239 is_khr_maintenance1 ? (is_3D_to_2D_map ? VALIDATION_ERROR_0ac00b9a : VALIDATION_ERROR_0ac00b96) : VALIDATION_ERROR_0ac00d6e;
Petr Krausffa94af2017-08-08 21:46:02 +02003240
3241 return ValidateImageSubresourceRange(device_data, image_state->createInfo.mipLevels, image_layer_count, subresourceRange,
3242 "vkCreateImageView", "pCreateInfo->subresourceRange", image_layer_count_var_name,
3243 HandleToUint64(image_state->image), subresourceRangeErrorCodes);
3244}
3245
3246bool ValidateCmdClearColorSubresourceRange(const layer_data *device_data, const IMAGE_STATE *image_state,
3247 const VkImageSubresourceRange &subresourceRange, const char *param_name) {
3248 SubresourceRangeErrorCodes subresourceRangeErrorCodes = {};
3249 subresourceRangeErrorCodes.base_mip_err = VALIDATION_ERROR_18800b7c;
Mike Schuchardt8da1bb52018-02-22 10:46:31 -07003250 subresourceRangeErrorCodes.mip_count_err = VALIDATION_ERROR_18800d38;
Petr Krausffa94af2017-08-08 21:46:02 +02003251 subresourceRangeErrorCodes.base_layer_err = VALIDATION_ERROR_18800b80;
Mike Schuchardt8da1bb52018-02-22 10:46:31 -07003252 subresourceRangeErrorCodes.layer_count_err = VALIDATION_ERROR_18800d3a;
Petr Krausffa94af2017-08-08 21:46:02 +02003253
3254 return ValidateImageSubresourceRange(device_data, image_state->createInfo.mipLevels, image_state->createInfo.arrayLayers,
3255 subresourceRange, "vkCmdClearColorImage", param_name, "arrayLayers",
3256 HandleToUint64(image_state->image), subresourceRangeErrorCodes);
3257}
3258
3259bool ValidateCmdClearDepthSubresourceRange(const layer_data *device_data, const IMAGE_STATE *image_state,
3260 const VkImageSubresourceRange &subresourceRange, const char *param_name) {
3261 SubresourceRangeErrorCodes subresourceRangeErrorCodes = {};
3262 subresourceRangeErrorCodes.base_mip_err = VALIDATION_ERROR_18a00b84;
Mike Schuchardt8da1bb52018-02-22 10:46:31 -07003263 subresourceRangeErrorCodes.mip_count_err = VALIDATION_ERROR_18a00d3c;
Petr Krausffa94af2017-08-08 21:46:02 +02003264 subresourceRangeErrorCodes.base_layer_err = VALIDATION_ERROR_18a00b88;
Mike Schuchardt8da1bb52018-02-22 10:46:31 -07003265 subresourceRangeErrorCodes.layer_count_err = VALIDATION_ERROR_18a00d3e;
Petr Krausffa94af2017-08-08 21:46:02 +02003266
3267 return ValidateImageSubresourceRange(device_data, image_state->createInfo.mipLevels, image_state->createInfo.arrayLayers,
3268 subresourceRange, "vkCmdClearDepthStencilImage", param_name, "arrayLayers",
3269 HandleToUint64(image_state->image), subresourceRangeErrorCodes);
3270}
3271
3272bool ValidateImageBarrierSubresourceRange(const layer_data *device_data, const IMAGE_STATE *image_state,
3273 const VkImageSubresourceRange &subresourceRange, const char *cmd_name,
3274 const char *param_name) {
3275 SubresourceRangeErrorCodes subresourceRangeErrorCodes = {};
3276 subresourceRangeErrorCodes.base_mip_err = VALIDATION_ERROR_0a000b9c;
Mike Schuchardt8da1bb52018-02-22 10:46:31 -07003277 subresourceRangeErrorCodes.mip_count_err = VALIDATION_ERROR_0a000d78;
Petr Krausffa94af2017-08-08 21:46:02 +02003278 subresourceRangeErrorCodes.base_layer_err = VALIDATION_ERROR_0a000ba0;
Mike Schuchardt8da1bb52018-02-22 10:46:31 -07003279 subresourceRangeErrorCodes.layer_count_err = VALIDATION_ERROR_0a000d7a;
Petr Krausffa94af2017-08-08 21:46:02 +02003280
3281 return ValidateImageSubresourceRange(device_data, image_state->createInfo.mipLevels, image_state->createInfo.arrayLayers,
3282 subresourceRange, cmd_name, param_name, "arrayLayers", HandleToUint64(image_state->image),
3283 subresourceRangeErrorCodes);
3284}
3285
Mark Lobodzinski602de982017-02-09 11:01:33 -07003286bool PreCallValidateCreateImageView(layer_data *device_data, const VkImageViewCreateInfo *create_info) {
3287 const debug_report_data *report_data = core_validation::GetReportData(device_data);
3288 bool skip = false;
3289 IMAGE_STATE *image_state = GetImageState(device_data, create_info->image);
3290 if (image_state) {
3291 skip |= ValidateImageUsageFlags(
3292 device_data, image_state,
3293 VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT |
Dave Houltona9df0ce2018-02-07 10:51:23 -07003294 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
Mark Lobodzinski602de982017-02-09 11:01:33 -07003295 false, -1, "vkCreateImageView()",
3296 "VK_IMAGE_USAGE_[SAMPLED|STORAGE|COLOR_ATTACHMENT|DEPTH_STENCIL_ATTACHMENT|INPUT_ATTACHMENT]_BIT");
3297 // If this isn't a sparse image, it needs to have memory backing it at CreateImageView time
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003298 skip |= ValidateMemoryIsBoundToImage(device_data, image_state, "vkCreateImageView()", VALIDATION_ERROR_0ac007f8);
Mark Lobodzinski602de982017-02-09 11:01:33 -07003299 // Checks imported from image layer
Petr Krausffa94af2017-08-08 21:46:02 +02003300 skip |= ValidateCreateImageViewSubresourceRange(
3301 device_data, image_state,
3302 create_info->viewType == VK_IMAGE_VIEW_TYPE_2D || create_info->viewType == VK_IMAGE_VIEW_TYPE_2D_ARRAY,
3303 create_info->subresourceRange);
Mark Lobodzinski602de982017-02-09 11:01:33 -07003304
3305 VkImageCreateFlags image_flags = image_state->createInfo.flags;
3306 VkFormat image_format = image_state->createInfo.format;
Jeremy Kniagercef491c2017-07-18 11:10:28 -06003307 VkImageUsageFlags image_usage = image_state->createInfo.usage;
3308 VkImageTiling image_tiling = image_state->createInfo.tiling;
Mark Lobodzinski602de982017-02-09 11:01:33 -07003309 VkFormat view_format = create_info->format;
3310 VkImageAspectFlags aspect_mask = create_info->subresourceRange.aspectMask;
Jeremy Kniager846ab732017-07-10 13:12:04 -06003311 VkImageType image_type = image_state->createInfo.imageType;
3312 VkImageViewType view_type = create_info->viewType;
Mark Lobodzinski602de982017-02-09 11:01:33 -07003313
3314 // Validate VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT state
3315 if (image_flags & VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT) {
Lenny Komowb79f04a2017-09-18 17:07:00 -06003316 if ((!GetDeviceExtensions(device_data)->vk_khr_maintenance2 ||
3317 !(image_flags & VK_IMAGE_CREATE_BLOCK_TEXEL_VIEW_COMPATIBLE_BIT_KHR))) {
3318 // Format MUST be compatible (in the same format compatibility class) as the format the image was created with
3319 if (FormatCompatibilityClass(image_format) != FormatCompatibilityClass(view_format)) {
3320 std::stringstream ss;
3321 ss << "vkCreateImageView(): ImageView format " << string_VkFormat(view_format)
3322 << " is not in the same format compatibility class as image (" << HandleToUint64(create_info->image)
3323 << ") format " << string_VkFormat(image_format)
3324 << ". Images created with the VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
3325 << "can support ImageViews with differing formats but they must be in the same compatibility class.";
3326 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
Mark Lobodzinski88529492018-04-01 10:38:15 -06003327 VALIDATION_ERROR_0ac007f4, "%s", ss.str().c_str());
Lenny Komowb79f04a2017-09-18 17:07:00 -06003328 }
Mark Lobodzinski602de982017-02-09 11:01:33 -07003329 }
3330 } else {
3331 // Format MUST be IDENTICAL to the format the image was created with
3332 if (image_format != view_format) {
3333 std::stringstream ss;
3334 ss << "vkCreateImageView() format " << string_VkFormat(view_format) << " differs from image "
Petr Krausbc7f5442017-05-14 23:43:38 +02003335 << HandleToUint64(create_info->image) << " format " << string_VkFormat(image_format)
Mark Lobodzinski602de982017-02-09 11:01:33 -07003336 << ". Formats MUST be IDENTICAL unless VK_IMAGE_CREATE_MUTABLE_FORMAT BIT was set on image creation.";
Mark Lobodzinskib1fd9d12018-03-30 14:26:00 -06003337 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
Mark Lobodzinski88529492018-04-01 10:38:15 -06003338 VALIDATION_ERROR_0ac007f6, "%s", ss.str().c_str());
Mark Lobodzinski602de982017-02-09 11:01:33 -07003339 }
3340 }
3341
3342 // Validate correct image aspect bits for desired formats and format consistency
3343 skip |= ValidateImageAspectMask(device_data, image_state->image, image_format, aspect_mask, "vkCreateImageView()");
Jeremy Kniager846ab732017-07-10 13:12:04 -06003344
3345 switch (image_type) {
3346 case VK_IMAGE_TYPE_1D:
3347 if (view_type != VK_IMAGE_VIEW_TYPE_1D && view_type != VK_IMAGE_VIEW_TYPE_1D_ARRAY) {
3348 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
Mark Lobodzinski88529492018-04-01 10:38:15 -06003349 VALIDATION_ERROR_0ac007fa,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06003350 "vkCreateImageView(): pCreateInfo->viewType %s is not compatible with image type %s.",
3351 string_VkImageViewType(view_type), string_VkImageType(image_type));
Jeremy Kniager846ab732017-07-10 13:12:04 -06003352 }
3353 break;
3354 case VK_IMAGE_TYPE_2D:
3355 if (view_type != VK_IMAGE_VIEW_TYPE_2D && view_type != VK_IMAGE_VIEW_TYPE_2D_ARRAY) {
3356 if ((view_type == VK_IMAGE_VIEW_TYPE_CUBE || view_type == VK_IMAGE_VIEW_TYPE_CUBE_ARRAY) &&
3357 !(image_flags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT)) {
3358 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
Mark Lobodzinski88529492018-04-01 10:38:15 -06003359 VALIDATION_ERROR_0ac007d6,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06003360 "vkCreateImageView(): pCreateInfo->viewType %s is not compatible with image type %s.",
3361 string_VkImageViewType(view_type), string_VkImageType(image_type));
Jeremy Kniager846ab732017-07-10 13:12:04 -06003362 } else if (view_type != VK_IMAGE_VIEW_TYPE_CUBE && view_type != VK_IMAGE_VIEW_TYPE_CUBE_ARRAY) {
3363 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
Mark Lobodzinski88529492018-04-01 10:38:15 -06003364 VALIDATION_ERROR_0ac007fa,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06003365 "vkCreateImageView(): pCreateInfo->viewType %s is not compatible with image type %s.",
3366 string_VkImageViewType(view_type), string_VkImageType(image_type));
Jeremy Kniager846ab732017-07-10 13:12:04 -06003367 }
3368 }
3369 break;
3370 case VK_IMAGE_TYPE_3D:
3371 if (GetDeviceExtensions(device_data)->vk_khr_maintenance1) {
3372 if (view_type != VK_IMAGE_VIEW_TYPE_3D) {
3373 if ((view_type == VK_IMAGE_VIEW_TYPE_2D || view_type == VK_IMAGE_VIEW_TYPE_2D_ARRAY)) {
3374 if (!(image_flags & VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT_KHR)) {
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06003375 skip |=
3376 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
Mark Lobodzinski88529492018-04-01 10:38:15 -06003377 VALIDATION_ERROR_0ac007da,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06003378 "vkCreateImageView(): pCreateInfo->viewType %s is not compatible with image type %s.",
3379 string_VkImageViewType(view_type), string_VkImageType(image_type));
Jeremy Kniager846ab732017-07-10 13:12:04 -06003380 } else if ((image_flags & (VK_IMAGE_CREATE_SPARSE_BINDING_BIT | VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT |
3381 VK_IMAGE_CREATE_SPARSE_ALIASED_BIT))) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07003382 skip |=
3383 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
Mark Lobodzinski88529492018-04-01 10:38:15 -06003384 VALIDATION_ERROR_0ac007fa,
Dave Houltona9df0ce2018-02-07 10:51:23 -07003385 "vkCreateImageView(): pCreateInfo->viewType %s is not compatible with image type %s "
3386 "when the VK_IMAGE_CREATE_SPARSE_BINDING_BIT, VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT, or "
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06003387 "VK_IMAGE_CREATE_SPARSE_ALIASED_BIT flags are enabled.",
3388 string_VkImageViewType(view_type), string_VkImageType(image_type));
Jeremy Kniager846ab732017-07-10 13:12:04 -06003389 }
3390 } else {
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06003391 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
Mark Lobodzinski88529492018-04-01 10:38:15 -06003392 VALIDATION_ERROR_0ac007fa,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06003393 "vkCreateImageView(): pCreateInfo->viewType %s is not compatible with image type %s.",
3394 string_VkImageViewType(view_type), string_VkImageType(image_type));
Jeremy Kniager846ab732017-07-10 13:12:04 -06003395 }
3396 }
3397 } else {
3398 if (view_type != VK_IMAGE_VIEW_TYPE_3D) {
3399 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
Mark Lobodzinski88529492018-04-01 10:38:15 -06003400 VALIDATION_ERROR_0ac007fa,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06003401 "vkCreateImageView(): pCreateInfo->viewType %s is not compatible with image type %s.",
3402 string_VkImageViewType(view_type), string_VkImageType(image_type));
Jeremy Kniager846ab732017-07-10 13:12:04 -06003403 }
3404 }
3405 break;
3406 default:
3407 break;
3408 }
Jeremy Kniagercef491c2017-07-18 11:10:28 -06003409
Jeremy Kniager7ec550f2017-08-16 14:57:42 -06003410 VkFormatProperties format_properties = GetFormatProperties(device_data, view_format);
Jeremy Kniagercef491c2017-07-18 11:10:28 -06003411 bool check_tiling_features = false;
3412 VkFormatFeatureFlags tiling_features = 0;
3413 UNIQUE_VALIDATION_ERROR_CODE linear_error_codes[] = {
3414 VALIDATION_ERROR_0ac007dc, VALIDATION_ERROR_0ac007e0, VALIDATION_ERROR_0ac007e2,
3415 VALIDATION_ERROR_0ac007e4, VALIDATION_ERROR_0ac007e6,
3416 };
3417 UNIQUE_VALIDATION_ERROR_CODE optimal_error_codes[] = {
3418 VALIDATION_ERROR_0ac007e8, VALIDATION_ERROR_0ac007ea, VALIDATION_ERROR_0ac007ec,
3419 VALIDATION_ERROR_0ac007ee, VALIDATION_ERROR_0ac007f0,
3420 };
3421 UNIQUE_VALIDATION_ERROR_CODE *error_codes = nullptr;
3422 if (image_tiling == VK_IMAGE_TILING_LINEAR) {
Jeremy Kniager7ec550f2017-08-16 14:57:42 -06003423 tiling_features = format_properties.linearTilingFeatures;
Jeremy Kniagercef491c2017-07-18 11:10:28 -06003424 error_codes = linear_error_codes;
3425 check_tiling_features = true;
3426 } else if (image_tiling == VK_IMAGE_TILING_OPTIMAL) {
Jeremy Kniager7ec550f2017-08-16 14:57:42 -06003427 tiling_features = format_properties.optimalTilingFeatures;
Jeremy Kniagercef491c2017-07-18 11:10:28 -06003428 error_codes = optimal_error_codes;
3429 check_tiling_features = true;
3430 }
3431
3432 if (check_tiling_features) {
3433 if (tiling_features == 0) {
Mark Lobodzinski88529492018-04-01 10:38:15 -06003434 skip |=
3435 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, error_codes[0],
3436 "vkCreateImageView() pCreateInfo->format %s cannot be used with an image having the %s flag set.",
3437 string_VkFormat(view_format), string_VkImageTiling(image_tiling));
Jeremy Kniagercef491c2017-07-18 11:10:28 -06003438 } else if ((image_usage & VK_IMAGE_USAGE_SAMPLED_BIT) && !(tiling_features & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Mark Lobodzinski88529492018-04-01 10:38:15 -06003439 skip |=
3440 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, error_codes[1],
3441 "vkCreateImageView() pCreateInfo->format %s cannot be used with an image having the %s and "
3442 "VK_IMAGE_USAGE_SAMPLED_BIT flags set.",
3443 string_VkFormat(view_format), string_VkImageTiling(image_tiling));
Jeremy Kniagercef491c2017-07-18 11:10:28 -06003444 } else if ((image_usage & VK_IMAGE_USAGE_STORAGE_BIT) && !(tiling_features & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT)) {
Mark Lobodzinski88529492018-04-01 10:38:15 -06003445 skip |=
3446 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, error_codes[2],
3447 "vkCreateImageView() pCreateInfo->format %s cannot be used with an image having the %s and "
3448 "VK_IMAGE_USAGE_STORAGE_BIT flags set.",
3449 string_VkFormat(view_format), string_VkImageTiling(image_tiling));
Jeremy Kniagercef491c2017-07-18 11:10:28 -06003450 } else if ((image_usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) &&
3451 !(tiling_features & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT)) {
Mark Lobodzinski88529492018-04-01 10:38:15 -06003452 skip |=
3453 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, error_codes[3],
3454 "vkCreateImageView() pCreateInfo->format %s cannot be used with an image having the %s and "
3455 "VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT flags set.",
3456 string_VkFormat(view_format), string_VkImageTiling(image_tiling));
Jeremy Kniagercef491c2017-07-18 11:10:28 -06003457 } else if ((image_usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) &&
3458 !(tiling_features & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)) {
Mark Lobodzinski88529492018-04-01 10:38:15 -06003459 skip |=
3460 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, error_codes[4],
3461 "vkCreateImageView() pCreateInfo->format %s cannot be used with an image having the %s and "
3462 "VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT flags set.",
3463 string_VkFormat(view_format), string_VkImageTiling(image_tiling));
Jeremy Kniagercef491c2017-07-18 11:10:28 -06003464 }
3465 }
Mark Lobodzinski602de982017-02-09 11:01:33 -07003466 }
3467 return skip;
3468}
3469
Mark Lobodzinskiefd933b2017-02-10 12:09:23 -07003470void PostCallRecordCreateImageView(layer_data *device_data, const VkImageViewCreateInfo *create_info, VkImageView view) {
3471 auto image_view_map = GetImageViewMap(device_data);
3472 (*image_view_map)[view] = std::unique_ptr<IMAGE_VIEW_STATE>(new IMAGE_VIEW_STATE(view, create_info));
3473
3474 auto image_state = GetImageState(device_data, create_info->image);
Dave Houlton4eaaf3a2017-03-14 11:31:20 -06003475 auto &sub_res_range = (*image_view_map)[view].get()->create_info.subresourceRange;
Mark Lobodzinski903e5ff2017-03-23 09:43:35 -06003476 sub_res_range.levelCount = ResolveRemainingLevels(&sub_res_range, image_state->createInfo.mipLevels);
3477 sub_res_range.layerCount = ResolveRemainingLayers(&sub_res_range, image_state->createInfo.arrayLayers);
Mark Lobodzinski602de982017-02-09 11:01:33 -07003478}
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07003479
Mark Lobodzinski680421d2017-02-09 13:06:56 -07003480bool PreCallValidateCmdCopyBuffer(layer_data *device_data, GLOBAL_CB_NODE *cb_node, BUFFER_STATE *src_buffer_state,
3481 BUFFER_STATE *dst_buffer_state) {
3482 bool skip = false;
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003483 skip |= ValidateMemoryIsBoundToBuffer(device_data, src_buffer_state, "vkCmdCopyBuffer()", VALIDATION_ERROR_18c000ee);
3484 skip |= ValidateMemoryIsBoundToBuffer(device_data, dst_buffer_state, "vkCmdCopyBuffer()", VALIDATION_ERROR_18c000f2);
Mark Lobodzinski680421d2017-02-09 13:06:56 -07003485 // Validate that SRC & DST buffers have correct usage flags set
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003486 skip |= ValidateBufferUsageFlags(device_data, src_buffer_state, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, true,
3487 VALIDATION_ERROR_18c000ec, "vkCmdCopyBuffer()", "VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
3488 skip |= ValidateBufferUsageFlags(device_data, dst_buffer_state, VK_BUFFER_USAGE_TRANSFER_DST_BIT, true,
3489 VALIDATION_ERROR_18c000f0, "vkCmdCopyBuffer()", "VK_BUFFER_USAGE_TRANSFER_DST_BIT");
Mike Schuchardt9c582402017-02-23 15:57:37 -07003490 skip |= ValidateCmdQueueFlags(device_data, cb_node, "vkCmdCopyBuffer()",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003491 VK_QUEUE_TRANSFER_BIT | VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT, VALIDATION_ERROR_18c02415);
Mark Lobodzinski680421d2017-02-09 13:06:56 -07003492 skip |= ValidateCmd(device_data, cb_node, CMD_COPYBUFFER, "vkCmdCopyBuffer()");
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003493 skip |= insideRenderPass(device_data, cb_node, "vkCmdCopyBuffer()", VALIDATION_ERROR_18c00017);
Mark Lobodzinski680421d2017-02-09 13:06:56 -07003494 return skip;
3495}
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07003496
Mark Lobodzinski680421d2017-02-09 13:06:56 -07003497void PreCallRecordCmdCopyBuffer(layer_data *device_data, GLOBAL_CB_NODE *cb_node, BUFFER_STATE *src_buffer_state,
3498 BUFFER_STATE *dst_buffer_state) {
3499 // Update bindings between buffers and cmd buffer
3500 AddCommandBufferBindingBuffer(device_data, cb_node, src_buffer_state);
3501 AddCommandBufferBindingBuffer(device_data, cb_node, dst_buffer_state);
3502
3503 std::function<bool()> function = [=]() {
3504 return ValidateBufferMemoryIsValid(device_data, src_buffer_state, "vkCmdCopyBuffer()");
3505 };
Tobin Ehlisa17a5292017-07-28 12:11:30 -06003506 cb_node->queue_submit_functions.push_back(function);
Mark Lobodzinski680421d2017-02-09 13:06:56 -07003507 function = [=]() {
3508 SetBufferMemoryValid(device_data, dst_buffer_state, true);
3509 return false;
3510 };
Tobin Ehlisa17a5292017-07-28 12:11:30 -06003511 cb_node->queue_submit_functions.push_back(function);
Mark Lobodzinski680421d2017-02-09 13:06:56 -07003512}
Mark Lobodzinski306441e2017-02-10 13:48:38 -07003513
3514static bool validateIdleBuffer(layer_data *device_data, VkBuffer buffer) {
3515 const debug_report_data *report_data = core_validation::GetReportData(device_data);
3516 bool skip = false;
3517 auto buffer_state = GetBufferState(device_data, buffer);
3518 if (!buffer_state) {
Petr Krausbc7f5442017-05-14 23:43:38 +02003519 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, HandleToUint64(buffer),
Mark Lobodzinski88529492018-04-01 10:38:15 -06003520 DRAWSTATE_DOUBLE_DESTROY, "Cannot free buffer 0x%" PRIx64 " that has not been allocated.",
Petr Kraus13c98a62017-12-09 00:22:39 +01003521 HandleToUint64(buffer));
Mark Lobodzinski306441e2017-02-10 13:48:38 -07003522 } else {
3523 if (buffer_state->in_use.load()) {
Petr Krausbc7f5442017-05-14 23:43:38 +02003524 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06003525 HandleToUint64(buffer), VALIDATION_ERROR_23c00734,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06003526 "Cannot free buffer 0x%" PRIx64 " that is in use by a command buffer.", HandleToUint64(buffer));
Mark Lobodzinski306441e2017-02-10 13:48:38 -07003527 }
3528 }
3529 return skip;
3530}
3531
3532bool PreCallValidateDestroyImageView(layer_data *device_data, VkImageView image_view, IMAGE_VIEW_STATE **image_view_state,
3533 VK_OBJECT *obj_struct) {
3534 *image_view_state = GetImageViewState(device_data, image_view);
Petr Krausbc7f5442017-05-14 23:43:38 +02003535 *obj_struct = {HandleToUint64(image_view), kVulkanObjectTypeImageView};
Mark Lobodzinski306441e2017-02-10 13:48:38 -07003536 if (GetDisables(device_data)->destroy_image_view) return false;
3537 bool skip = false;
3538 if (*image_view_state) {
Mike Schuchardta5025652017-09-27 14:56:21 -06003539 skip |=
3540 ValidateObjectNotInUse(device_data, *image_view_state, *obj_struct, "vkDestroyImageView", VALIDATION_ERROR_25400804);
Mark Lobodzinski306441e2017-02-10 13:48:38 -07003541 }
3542 return skip;
3543}
3544
3545void PostCallRecordDestroyImageView(layer_data *device_data, VkImageView image_view, IMAGE_VIEW_STATE *image_view_state,
3546 VK_OBJECT obj_struct) {
3547 // Any bound cmd buffers are now invalid
3548 invalidateCommandBuffers(device_data, image_view_state->cb_bindings, obj_struct);
3549 (*GetImageViewMap(device_data)).erase(image_view);
3550}
3551
3552bool PreCallValidateDestroyBuffer(layer_data *device_data, VkBuffer buffer, BUFFER_STATE **buffer_state, VK_OBJECT *obj_struct) {
3553 *buffer_state = GetBufferState(device_data, buffer);
Petr Krausbc7f5442017-05-14 23:43:38 +02003554 *obj_struct = {HandleToUint64(buffer), kVulkanObjectTypeBuffer};
Mark Lobodzinski306441e2017-02-10 13:48:38 -07003555 if (GetDisables(device_data)->destroy_buffer) return false;
3556 bool skip = false;
3557 if (*buffer_state) {
3558 skip |= validateIdleBuffer(device_data, buffer);
3559 }
3560 return skip;
3561}
3562
3563void PostCallRecordDestroyBuffer(layer_data *device_data, VkBuffer buffer, BUFFER_STATE *buffer_state, VK_OBJECT obj_struct) {
3564 invalidateCommandBuffers(device_data, buffer_state->cb_bindings, obj_struct);
3565 for (auto mem_binding : buffer_state->GetBoundMemory()) {
3566 auto mem_info = GetMemObjInfo(device_data, mem_binding);
3567 if (mem_info) {
Petr Krausbc7f5442017-05-14 23:43:38 +02003568 core_validation::RemoveBufferMemoryRange(HandleToUint64(buffer), mem_info);
Mark Lobodzinski306441e2017-02-10 13:48:38 -07003569 }
3570 }
Petr Krausbc7f5442017-05-14 23:43:38 +02003571 ClearMemoryObjectBindings(device_data, HandleToUint64(buffer), kVulkanObjectTypeBuffer);
Mark Lobodzinski306441e2017-02-10 13:48:38 -07003572 GetBufferMap(device_data)->erase(buffer_state->buffer);
3573}
3574
3575bool PreCallValidateDestroyBufferView(layer_data *device_data, VkBufferView buffer_view, BUFFER_VIEW_STATE **buffer_view_state,
3576 VK_OBJECT *obj_struct) {
3577 *buffer_view_state = GetBufferViewState(device_data, buffer_view);
Petr Krausbc7f5442017-05-14 23:43:38 +02003578 *obj_struct = {HandleToUint64(buffer_view), kVulkanObjectTypeBufferView};
Mark Lobodzinski306441e2017-02-10 13:48:38 -07003579 if (GetDisables(device_data)->destroy_buffer_view) return false;
3580 bool skip = false;
3581 if (*buffer_view_state) {
Mike Schuchardta5025652017-09-27 14:56:21 -06003582 skip |=
3583 ValidateObjectNotInUse(device_data, *buffer_view_state, *obj_struct, "vkDestroyBufferView", VALIDATION_ERROR_23e00750);
Mark Lobodzinski306441e2017-02-10 13:48:38 -07003584 }
3585 return skip;
3586}
3587
3588void PostCallRecordDestroyBufferView(layer_data *device_data, VkBufferView buffer_view, BUFFER_VIEW_STATE *buffer_view_state,
3589 VK_OBJECT obj_struct) {
3590 // Any bound cmd buffers are now invalid
3591 invalidateCommandBuffers(device_data, buffer_view_state->cb_bindings, obj_struct);
3592 GetBufferViewMap(device_data)->erase(buffer_view);
3593}
Mark Lobodzinskidf0acbf2017-02-10 14:01:27 -07003594
3595bool PreCallValidateCmdFillBuffer(layer_data *device_data, GLOBAL_CB_NODE *cb_node, BUFFER_STATE *buffer_state) {
3596 bool skip = false;
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003597 skip |= ValidateMemoryIsBoundToBuffer(device_data, buffer_state, "vkCmdFillBuffer()", VALIDATION_ERROR_1b40003e);
Mike Schuchardt9c582402017-02-23 15:57:37 -07003598 skip |= ValidateCmdQueueFlags(device_data, cb_node, "vkCmdFillBuffer()",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003599 VK_QUEUE_TRANSFER_BIT | VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT, VALIDATION_ERROR_1b402415);
Mark Lobodzinskidf0acbf2017-02-10 14:01:27 -07003600 skip |= ValidateCmd(device_data, cb_node, CMD_FILLBUFFER, "vkCmdFillBuffer()");
3601 // Validate that DST buffer has correct usage flags set
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003602 skip |= ValidateBufferUsageFlags(device_data, buffer_state, VK_BUFFER_USAGE_TRANSFER_DST_BIT, true, VALIDATION_ERROR_1b40003a,
Mark Lobodzinskidf0acbf2017-02-10 14:01:27 -07003603 "vkCmdFillBuffer()", "VK_BUFFER_USAGE_TRANSFER_DST_BIT");
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003604 skip |= insideRenderPass(device_data, cb_node, "vkCmdFillBuffer()", VALIDATION_ERROR_1b400017);
Mark Lobodzinskidf0acbf2017-02-10 14:01:27 -07003605 return skip;
3606}
3607
3608void PreCallRecordCmdFillBuffer(layer_data *device_data, GLOBAL_CB_NODE *cb_node, BUFFER_STATE *buffer_state) {
3609 std::function<bool()> function = [=]() {
3610 SetBufferMemoryValid(device_data, buffer_state, true);
3611 return false;
3612 };
Tobin Ehlisa17a5292017-07-28 12:11:30 -06003613 cb_node->queue_submit_functions.push_back(function);
Mark Lobodzinskidf0acbf2017-02-10 14:01:27 -07003614 // Update bindings between buffer and cmd buffer
3615 AddCommandBufferBindingBuffer(device_data, cb_node, buffer_state);
Mark Lobodzinskidf0acbf2017-02-10 14:01:27 -07003616}
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003617
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003618bool ValidateBufferImageCopyData(const debug_report_data *report_data, uint32_t regionCount, const VkBufferImageCopy *pRegions,
3619 IMAGE_STATE *image_state, const char *function) {
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003620 bool skip = false;
3621
3622 for (uint32_t i = 0; i < regionCount; i++) {
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003623 if (image_state->createInfo.imageType == VK_IMAGE_TYPE_1D) {
3624 if ((pRegions[i].imageOffset.y != 0) || (pRegions[i].imageExtent.height != 1)) {
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003625 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06003626 HandleToUint64(image_state->image), VALIDATION_ERROR_0160018e,
Dave Houltona9df0ce2018-02-07 10:51:23 -07003627 "%s(): pRegion[%d] imageOffset.y is %d and imageExtent.height is %d. For 1D images these must be 0 "
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06003628 "and 1, respectively.",
3629 function, i, pRegions[i].imageOffset.y, pRegions[i].imageExtent.height);
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003630 }
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003631 }
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003632
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003633 if ((image_state->createInfo.imageType == VK_IMAGE_TYPE_1D) || (image_state->createInfo.imageType == VK_IMAGE_TYPE_2D)) {
3634 if ((pRegions[i].imageOffset.z != 0) || (pRegions[i].imageExtent.depth != 1)) {
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003635 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06003636 HandleToUint64(image_state->image), VALIDATION_ERROR_01600192,
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003637 "%s(): pRegion[%d] imageOffset.z is %d and imageExtent.depth is %d. For 1D and 2D images these "
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06003638 "must be 0 and 1, respectively.",
3639 function, i, pRegions[i].imageOffset.z, pRegions[i].imageExtent.depth);
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003640 }
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003641 }
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003642
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003643 if (image_state->createInfo.imageType == VK_IMAGE_TYPE_3D) {
3644 if ((0 != pRegions[i].imageSubresource.baseArrayLayer) || (1 != pRegions[i].imageSubresource.layerCount)) {
Mark Lobodzinskib1fd9d12018-03-30 14:26:00 -06003645 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06003646 HandleToUint64(image_state->image), VALIDATION_ERROR_016001aa,
Mark Lobodzinskib1fd9d12018-03-30 14:26:00 -06003647 "%s(): pRegion[%d] imageSubresource.baseArrayLayer is %d and imageSubresource.layerCount is %d. "
3648 "For 3D images these must be 0 and 1, respectively.",
3649 function, i, pRegions[i].imageSubresource.baseArrayLayer, pRegions[i].imageSubresource.layerCount);
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003650 }
3651 }
3652
3653 // If the the calling command's VkImage parameter's format is not a depth/stencil format,
3654 // then bufferOffset must be a multiple of the calling command's VkImage parameter's texel size
Dave Houlton1d2022c2017-03-29 11:43:58 -06003655 auto texel_size = FormatSize(image_state->createInfo.format);
Dave Houlton1150cf52017-04-27 14:38:11 -06003656 if (!FormatIsDepthAndStencil(image_state->createInfo.format) && SafeModulo(pRegions[i].bufferOffset, texel_size) != 0) {
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003657 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06003658 HandleToUint64(image_state->image), VALIDATION_ERROR_01600182,
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003659 "%s(): pRegion[%d] bufferOffset 0x%" PRIxLEAST64
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06003660 " must be a multiple of this format's texel size (" PRINTF_SIZE_T_SPECIFIER ").",
3661 function, i, pRegions[i].bufferOffset, texel_size);
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003662 }
3663
3664 // BufferOffset must be a multiple of 4
Dave Houlton1d2022c2017-03-29 11:43:58 -06003665 if (SafeModulo(pRegions[i].bufferOffset, 4) != 0) {
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003666 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06003667 HandleToUint64(image_state->image), VALIDATION_ERROR_01600184,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06003668 "%s(): pRegion[%d] bufferOffset 0x%" PRIxLEAST64 " must be a multiple of 4.", function, i,
3669 pRegions[i].bufferOffset);
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003670 }
3671
3672 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
3673 if ((pRegions[i].bufferRowLength != 0) && (pRegions[i].bufferRowLength < pRegions[i].imageExtent.width)) {
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06003674 skip |=
3675 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06003676 HandleToUint64(image_state->image), VALIDATION_ERROR_01600186,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06003677 "%s(): pRegion[%d] bufferRowLength (%d) must be zero or greater-than-or-equal-to imageExtent.width (%d).",
3678 function, i, pRegions[i].bufferRowLength, pRegions[i].imageExtent.width);
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003679 }
3680
3681 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
3682 if ((pRegions[i].bufferImageHeight != 0) && (pRegions[i].bufferImageHeight < pRegions[i].imageExtent.height)) {
3683 skip |= log_msg(
3684 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06003685 HandleToUint64(image_state->image), VALIDATION_ERROR_01600188,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06003686 "%s(): pRegion[%d] bufferImageHeight (%d) must be zero or greater-than-or-equal-to imageExtent.height (%d).",
3687 function, i, pRegions[i].bufferImageHeight, pRegions[i].imageExtent.height);
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003688 }
3689
3690 // subresource aspectMask must have exactly 1 bit set
3691 const int num_bits = sizeof(VkFlags) * CHAR_BIT;
3692 std::bitset<num_bits> aspect_mask_bits(pRegions[i].imageSubresource.aspectMask);
3693 if (aspect_mask_bits.count() != 1) {
3694 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06003695 HandleToUint64(image_state->image), VALIDATION_ERROR_016001a8,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06003696 "%s: aspectMasks for imageSubresource in each region must have only a single bit set.", function);
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003697 }
3698
3699 // image subresource aspect bit must match format
Dave Houlton4eaaf3a2017-03-14 11:31:20 -06003700 if (!VerifyAspectsPresent(pRegions[i].imageSubresource.aspectMask, image_state->createInfo.format)) {
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003701 skip |= log_msg(
3702 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06003703 HandleToUint64(image_state->image), VALIDATION_ERROR_016001a6,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06003704 "%s(): pRegion[%d] subresource aspectMask 0x%x specifies aspects that are not present in image format 0x%x.",
3705 function, i, pRegions[i].imageSubresource.aspectMask, image_state->createInfo.format);
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003706 }
3707
3708 // Checks that apply only to compressed images
3709 // TODO: there is a comment in ValidateCopyBufferImageTransferGranularityRequirements() in core_validation.cpp that
3710 // reserves a place for these compressed image checks. This block of code could move there once the image
3711 // stuff is moved into core validation.
Dave Houlton1d2022c2017-03-29 11:43:58 -06003712 if (FormatIsCompressed(image_state->createInfo.format)) {
3713 auto block_size = FormatCompressedTexelBlockExtent(image_state->createInfo.format);
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003714
3715 // BufferRowLength must be a multiple of block width
Dave Houlton1d2022c2017-03-29 11:43:58 -06003716 if (SafeModulo(pRegions[i].bufferRowLength, block_size.width) != 0) {
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003717 skip |= log_msg(
3718 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06003719 HandleToUint64(image_state->image), VALIDATION_ERROR_01600196,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06003720 "%s(): pRegion[%d] bufferRowLength (%d) must be a multiple of the compressed image's texel width (%d)..",
3721 function, i, pRegions[i].bufferRowLength, block_size.width);
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003722 }
3723
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003724 // BufferRowHeight must be a multiple of block height
Dave Houlton1d2022c2017-03-29 11:43:58 -06003725 if (SafeModulo(pRegions[i].bufferImageHeight, block_size.height) != 0) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07003726 skip |= log_msg(
3727 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06003728 HandleToUint64(image_state->image), VALIDATION_ERROR_01600198,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06003729 "%s(): pRegion[%d] bufferImageHeight (%d) must be a multiple of the compressed image's texel height (%d)..",
3730 function, i, pRegions[i].bufferImageHeight, block_size.height);
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003731 }
3732
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003733 // image offsets must be multiples of block dimensions
Dave Houlton1d2022c2017-03-29 11:43:58 -06003734 if ((SafeModulo(pRegions[i].imageOffset.x, block_size.width) != 0) ||
3735 (SafeModulo(pRegions[i].imageOffset.y, block_size.height) != 0) ||
3736 (SafeModulo(pRegions[i].imageOffset.z, block_size.depth) != 0)) {
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06003737 skip |=
3738 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06003739 HandleToUint64(image_state->image), VALIDATION_ERROR_0160019a,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06003740 "%s(): pRegion[%d] imageOffset(x,y) (%d, %d) must be multiples of the compressed image's texel "
3741 "width & height (%d, %d)..",
3742 function, i, pRegions[i].imageOffset.x, pRegions[i].imageOffset.y, block_size.width, block_size.height);
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003743 }
3744
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003745 // bufferOffset must be a multiple of block size (linear bytes)
Dave Houlton1d2022c2017-03-29 11:43:58 -06003746 size_t block_size_in_bytes = FormatSize(image_state->createInfo.format);
3747 if (SafeModulo(pRegions[i].bufferOffset, block_size_in_bytes) != 0) {
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06003748 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06003749 HandleToUint64(image_state->image), VALIDATION_ERROR_0160019c,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06003750 "%s(): pRegion[%d] bufferOffset (0x%" PRIxLEAST64
3751 ") must be a multiple of the compressed image's texel block size (" PRINTF_SIZE_T_SPECIFIER ")..",
3752 function, i, pRegions[i].bufferOffset, block_size_in_bytes);
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003753 }
Dave Houlton67e9b532017-03-02 17:00:10 -07003754
3755 // imageExtent width must be a multiple of block width, or extent+offset width must equal subresource width
Dave Houlton75967fc2017-03-06 17:21:16 -07003756 VkExtent3D mip_extent = GetImageSubresourceExtent(image_state, &(pRegions[i].imageSubresource));
Dave Houlton1d2022c2017-03-29 11:43:58 -06003757 if ((SafeModulo(pRegions[i].imageExtent.width, block_size.width) != 0) &&
Dave Houlton75967fc2017-03-06 17:21:16 -07003758 (pRegions[i].imageExtent.width + pRegions[i].imageOffset.x != mip_extent.width)) {
3759 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06003760 HandleToUint64(image_state->image), VALIDATION_ERROR_0160019e,
Dave Houlton75967fc2017-03-06 17:21:16 -07003761 "%s(): pRegion[%d] extent width (%d) must be a multiple of the compressed texture block width "
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06003762 "(%d), or when added to offset.x (%d) must equal the image subresource width (%d)..",
Dave Houlton75967fc2017-03-06 17:21:16 -07003763 function, i, pRegions[i].imageExtent.width, block_size.width, pRegions[i].imageOffset.x,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06003764 mip_extent.width);
Dave Houlton67e9b532017-03-02 17:00:10 -07003765 }
3766
3767 // imageExtent height must be a multiple of block height, or extent+offset height must equal subresource height
Dave Houlton1d2022c2017-03-29 11:43:58 -06003768 if ((SafeModulo(pRegions[i].imageExtent.height, block_size.height) != 0) &&
Dave Houlton75967fc2017-03-06 17:21:16 -07003769 (pRegions[i].imageExtent.height + pRegions[i].imageOffset.y != mip_extent.height)) {
3770 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06003771 HandleToUint64(image_state->image), VALIDATION_ERROR_016001a0,
Dave Houlton75967fc2017-03-06 17:21:16 -07003772 "%s(): pRegion[%d] extent height (%d) must be a multiple of the compressed texture block height "
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06003773 "(%d), or when added to offset.y (%d) must equal the image subresource height (%d)..",
Dave Houlton75967fc2017-03-06 17:21:16 -07003774 function, i, pRegions[i].imageExtent.height, block_size.height, pRegions[i].imageOffset.y,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06003775 mip_extent.height);
Dave Houlton67e9b532017-03-02 17:00:10 -07003776 }
3777
3778 // imageExtent depth must be a multiple of block depth, or extent+offset depth must equal subresource depth
Dave Houlton1d2022c2017-03-29 11:43:58 -06003779 if ((SafeModulo(pRegions[i].imageExtent.depth, block_size.depth) != 0) &&
Dave Houlton75967fc2017-03-06 17:21:16 -07003780 (pRegions[i].imageExtent.depth + pRegions[i].imageOffset.z != mip_extent.depth)) {
3781 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06003782 HandleToUint64(image_state->image), VALIDATION_ERROR_016001a2,
Dave Houlton75967fc2017-03-06 17:21:16 -07003783 "%s(): pRegion[%d] extent width (%d) must be a multiple of the compressed texture block depth "
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06003784 "(%d), or when added to offset.z (%d) must equal the image subresource depth (%d)..",
Dave Houlton75967fc2017-03-06 17:21:16 -07003785 function, i, pRegions[i].imageExtent.depth, block_size.depth, pRegions[i].imageOffset.z,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06003786 mip_extent.depth);
Dave Houlton67e9b532017-03-02 17:00:10 -07003787 }
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003788 }
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003789 }
3790
3791 return skip;
3792}
3793
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003794static bool ValidateImageBounds(const debug_report_data *report_data, const IMAGE_STATE *image_state, const uint32_t regionCount,
3795 const VkBufferImageCopy *pRegions, const char *func_name, UNIQUE_VALIDATION_ERROR_CODE msg_code) {
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003796 bool skip = false;
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003797 const VkImageCreateInfo *image_info = &(image_state->createInfo);
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003798
3799 for (uint32_t i = 0; i < regionCount; i++) {
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003800 VkExtent3D extent = pRegions[i].imageExtent;
3801 VkOffset3D offset = pRegions[i].imageOffset;
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003802
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003803 if (IsExtentSizeZero(&extent)) // Warn on zero area subresource
3804 {
Mark Lobodzinski88529492018-04-01 10:38:15 -06003805 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
3806 (uint64_t)0, IMAGE_ZERO_AREA_SUBREGION, "%s: pRegion[%d] imageExtent of {%1d, %1d, %1d} has zero area",
3807 func_name, i, extent.width, extent.height, extent.depth);
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003808 }
3809
3810 VkExtent3D image_extent = GetImageSubresourceExtent(image_state, &(pRegions[i].imageSubresource));
3811
3812 // If we're using a compressed format, valid extent is rounded up to multiple of block size (per 18.1)
Dave Houlton1d2022c2017-03-29 11:43:58 -06003813 if (FormatIsCompressed(image_info->format)) {
3814 auto block_extent = FormatCompressedTexelBlockExtent(image_info->format);
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003815 if (image_extent.width % block_extent.width) {
3816 image_extent.width += (block_extent.width - (image_extent.width % block_extent.width));
3817 }
3818 if (image_extent.height % block_extent.height) {
3819 image_extent.height += (block_extent.height - (image_extent.height % block_extent.height));
3820 }
3821 if (image_extent.depth % block_extent.depth) {
3822 image_extent.depth += (block_extent.depth - (image_extent.depth % block_extent.depth));
3823 }
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003824 }
3825
Dave Houltonfc1a4052017-04-27 14:32:45 -06003826 if (0 != ExceedsBounds(&offset, &extent, &image_extent)) {
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003827 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)0,
Mark Lobodzinski88529492018-04-01 10:38:15 -06003828 msg_code, "%s: pRegion[%d] exceeds image bounds..", func_name, i);
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003829 }
3830 }
3831
3832 return skip;
3833}
3834
Chris Forbese8ba09a2017-06-01 17:39:02 -07003835static inline bool ValidateBufferBounds(const debug_report_data *report_data, IMAGE_STATE *image_state, BUFFER_STATE *buff_state,
Dave Houlton33c2d252017-06-09 17:08:32 -06003836 uint32_t regionCount, const VkBufferImageCopy *pRegions, const char *func_name,
3837 UNIQUE_VALIDATION_ERROR_CODE msg_code) {
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003838 bool skip = false;
3839
3840 VkDeviceSize buffer_size = buff_state->createInfo.size;
3841
3842 for (uint32_t i = 0; i < regionCount; i++) {
3843 VkExtent3D copy_extent = pRegions[i].imageExtent;
3844
3845 VkDeviceSize buffer_width = (0 == pRegions[i].bufferRowLength ? copy_extent.width : pRegions[i].bufferRowLength);
3846 VkDeviceSize buffer_height = (0 == pRegions[i].bufferImageHeight ? copy_extent.height : pRegions[i].bufferImageHeight);
Dave Houlton1d2022c2017-03-29 11:43:58 -06003847 VkDeviceSize unit_size = FormatSize(image_state->createInfo.format); // size (bytes) of texel or block
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003848
Dave Houltonf3229d52017-02-21 15:59:08 -07003849 // Handle special buffer packing rules for specific depth/stencil formats
3850 if (pRegions[i].imageSubresource.aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) {
Dave Houlton1d2022c2017-03-29 11:43:58 -06003851 unit_size = FormatSize(VK_FORMAT_S8_UINT);
Dave Houltonf3229d52017-02-21 15:59:08 -07003852 } else if (pRegions[i].imageSubresource.aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) {
3853 switch (image_state->createInfo.format) {
3854 case VK_FORMAT_D16_UNORM_S8_UINT:
Dave Houlton1d2022c2017-03-29 11:43:58 -06003855 unit_size = FormatSize(VK_FORMAT_D16_UNORM);
Dave Houltonf3229d52017-02-21 15:59:08 -07003856 break;
3857 case VK_FORMAT_D32_SFLOAT_S8_UINT:
Dave Houlton1d2022c2017-03-29 11:43:58 -06003858 unit_size = FormatSize(VK_FORMAT_D32_SFLOAT);
Dave Houltonf3229d52017-02-21 15:59:08 -07003859 break;
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003860 case VK_FORMAT_X8_D24_UNORM_PACK32: // Fall through
Dave Houltonf3229d52017-02-21 15:59:08 -07003861 case VK_FORMAT_D24_UNORM_S8_UINT:
3862 unit_size = 4;
3863 break;
3864 default:
3865 break;
3866 }
3867 }
3868
Dave Houlton1d2022c2017-03-29 11:43:58 -06003869 if (FormatIsCompressed(image_state->createInfo.format)) {
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003870 // Switch to texel block units, rounding up for any partially-used blocks
Dave Houlton1d2022c2017-03-29 11:43:58 -06003871 auto block_dim = FormatCompressedTexelBlockExtent(image_state->createInfo.format);
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003872 buffer_width = (buffer_width + block_dim.width - 1) / block_dim.width;
3873 buffer_height = (buffer_height + block_dim.height - 1) / block_dim.height;
3874
3875 copy_extent.width = (copy_extent.width + block_dim.width - 1) / block_dim.width;
3876 copy_extent.height = (copy_extent.height + block_dim.height - 1) / block_dim.height;
3877 copy_extent.depth = (copy_extent.depth + block_dim.depth - 1) / block_dim.depth;
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003878 }
3879
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003880 // Either depth or layerCount may be greater than 1 (not both). This is the number of 'slices' to copy
3881 uint32_t z_copies = std::max(copy_extent.depth, pRegions[i].imageSubresource.layerCount);
3882 if (IsExtentSizeZero(&copy_extent) || (0 == z_copies)) {
Chris Forbese8ba09a2017-06-01 17:39:02 -07003883 // TODO: Issue warning here? Already warned in ValidateImageBounds()...
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003884 } else {
3885 // Calculate buffer offset of final copied byte, + 1.
3886 VkDeviceSize max_buffer_offset = (z_copies - 1) * buffer_height * buffer_width; // offset to slice
3887 max_buffer_offset += ((copy_extent.height - 1) * buffer_width) + copy_extent.width; // add row,col
3888 max_buffer_offset *= unit_size; // convert to bytes
3889 max_buffer_offset += pRegions[i].bufferOffset; // add initial offset (bytes)
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003890
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003891 if (buffer_size < max_buffer_offset) {
Mark Lobodzinski88529492018-04-01 10:38:15 -06003892 skip |=
3893 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)0,
3894 msg_code, "%s: pRegion[%d] exceeds buffer size of %" PRIu64 " bytes..", func_name, i, buffer_size);
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003895 }
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003896 }
3897 }
3898
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003899 return skip;
3900}
3901
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003902bool PreCallValidateCmdCopyImageToBuffer(layer_data *device_data, VkImageLayout srcImageLayout, GLOBAL_CB_NODE *cb_node,
Mark Lobodzinski1fe9b002017-02-15 14:11:12 -07003903 IMAGE_STATE *src_image_state, BUFFER_STATE *dst_buffer_state, uint32_t regionCount,
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003904 const VkBufferImageCopy *pRegions, const char *func_name) {
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003905 const debug_report_data *report_data = core_validation::GetReportData(device_data);
3906 bool skip = ValidateBufferImageCopyData(report_data, regionCount, pRegions, src_image_state, "vkCmdCopyImageToBuffer");
3907
3908 // Validate command buffer state
John Zulauf5c2750c2018-01-30 15:04:56 -07003909 skip |= ValidateCmd(device_data, cb_node, CMD_COPYIMAGETOBUFFER, "vkCmdCopyImageToBuffer()");
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003910
3911 // Command pool must support graphics, compute, or transfer operations
3912 auto pPool = GetCommandPoolNode(device_data, cb_node->createInfo.commandPool);
3913
3914 VkQueueFlags queue_flags = GetPhysDevProperties(device_data)->queue_family_properties[pPool->queueFamilyIndex].queueFlags;
3915 if (0 == (queue_flags & (VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT | VK_QUEUE_TRANSFER_BIT))) {
3916 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06003917 HandleToUint64(cb_node->createInfo.commandPool), VALIDATION_ERROR_19202415,
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003918 "Cannot call vkCmdCopyImageToBuffer() on a command buffer allocated from a pool without graphics, compute, "
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06003919 "or transfer capabilities..");
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003920 }
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003921 skip |= ValidateImageBounds(report_data, src_image_state, regionCount, pRegions, "vkCmdCopyBufferToImage()",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003922 VALIDATION_ERROR_1920016c);
Chris Forbese8ba09a2017-06-01 17:39:02 -07003923 skip |= ValidateBufferBounds(report_data, src_image_state, dst_buffer_state, regionCount, pRegions, "vkCmdCopyImageToBuffer()",
Dave Houlton33c2d252017-06-09 17:08:32 -06003924 VALIDATION_ERROR_1920016e);
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003925
3926 skip |= ValidateImageSampleCount(device_data, src_image_state, VK_SAMPLE_COUNT_1_BIT, "vkCmdCopyImageToBuffer(): srcImage",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003927 VALIDATION_ERROR_19200178);
3928 skip |= ValidateMemoryIsBoundToImage(device_data, src_image_state, "vkCmdCopyImageToBuffer()", VALIDATION_ERROR_19200176);
3929 skip |= ValidateMemoryIsBoundToBuffer(device_data, dst_buffer_state, "vkCmdCopyImageToBuffer()", VALIDATION_ERROR_19200180);
Mark Lobodzinski033c90b2017-02-15 13:58:23 -07003930
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003931 // Validate that SRC image & DST buffer have correct usage flags set
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003932 skip |= ValidateImageUsageFlags(device_data, src_image_state, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, true, VALIDATION_ERROR_19200174,
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003933 "vkCmdCopyImageToBuffer()", "VK_IMAGE_USAGE_TRANSFER_SRC_BIT");
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003934 skip |= ValidateBufferUsageFlags(device_data, dst_buffer_state, VK_BUFFER_USAGE_TRANSFER_DST_BIT, true,
3935 VALIDATION_ERROR_1920017e, "vkCmdCopyImageToBuffer()", "VK_BUFFER_USAGE_TRANSFER_DST_BIT");
3936 skip |= insideRenderPass(device_data, cb_node, "vkCmdCopyImageToBuffer()", VALIDATION_ERROR_19200017);
Tobin Ehlisc8266452017-04-07 12:20:30 -06003937 bool hit_error = false;
Mark Lobodzinski033c90b2017-02-15 13:58:23 -07003938 for (uint32_t i = 0; i < regionCount; ++i) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003939 skip |= VerifyImageLayout(device_data, cb_node, src_image_state, pRegions[i].imageSubresource, srcImageLayout,
3940 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, "vkCmdCopyImageToBuffer()", VALIDATION_ERROR_1920017c,
3941 &hit_error);
Mark Lobodzinski033c90b2017-02-15 13:58:23 -07003942 skip |= ValidateCopyBufferImageTransferGranularityRequirements(device_data, cb_node, src_image_state, &pRegions[i], i,
Tobin Ehlis2d85ec62017-03-14 15:38:48 -06003943 "vkCmdCopyImageToBuffer()");
Mark Lobodzinski033c90b2017-02-15 13:58:23 -07003944 }
3945 return skip;
3946}
3947
3948void PreCallRecordCmdCopyImageToBuffer(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state,
Tobin Ehlise35b66a2017-03-15 12:18:31 -06003949 BUFFER_STATE *dst_buffer_state, uint32_t region_count, const VkBufferImageCopy *regions,
3950 VkImageLayout src_image_layout) {
3951 // Make sure that all image slices are updated to correct layout
3952 for (uint32_t i = 0; i < region_count; ++i) {
3953 SetImageLayout(device_data, cb_node, src_image_state, regions[i].imageSubresource, src_image_layout);
3954 }
Mark Lobodzinski033c90b2017-02-15 13:58:23 -07003955 // Update bindings between buffer/image and cmd buffer
3956 AddCommandBufferBindingImage(device_data, cb_node, src_image_state);
Mark Lobodzinski1fe9b002017-02-15 14:11:12 -07003957 AddCommandBufferBindingBuffer(device_data, cb_node, dst_buffer_state);
Mark Lobodzinski033c90b2017-02-15 13:58:23 -07003958
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003959 std::function<bool()> function = [=]() {
3960 return ValidateImageMemoryIsValid(device_data, src_image_state, "vkCmdCopyImageToBuffer()");
3961 };
Tobin Ehlisa17a5292017-07-28 12:11:30 -06003962 cb_node->queue_submit_functions.push_back(function);
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003963 function = [=]() {
Mark Lobodzinski1fe9b002017-02-15 14:11:12 -07003964 SetBufferMemoryValid(device_data, dst_buffer_state, true);
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003965 return false;
3966 };
Tobin Ehlisa17a5292017-07-28 12:11:30 -06003967 cb_node->queue_submit_functions.push_back(function);
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003968}
3969
3970bool PreCallValidateCmdCopyBufferToImage(layer_data *device_data, VkImageLayout dstImageLayout, GLOBAL_CB_NODE *cb_node,
Mark Lobodzinski1fe9b002017-02-15 14:11:12 -07003971 BUFFER_STATE *src_buffer_state, IMAGE_STATE *dst_image_state, uint32_t regionCount,
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003972 const VkBufferImageCopy *pRegions, const char *func_name) {
3973 const debug_report_data *report_data = core_validation::GetReportData(device_data);
3974 bool skip = ValidateBufferImageCopyData(report_data, regionCount, pRegions, dst_image_state, "vkCmdCopyBufferToImage");
3975
3976 // Validate command buffer state
John Zulauf5c2750c2018-01-30 15:04:56 -07003977 skip |= ValidateCmd(device_data, cb_node, CMD_COPYBUFFERTOIMAGE, "vkCmdCopyBufferToImage()");
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003978
3979 // Command pool must support graphics, compute, or transfer operations
3980 auto pPool = GetCommandPoolNode(device_data, cb_node->createInfo.commandPool);
3981 VkQueueFlags queue_flags = GetPhysDevProperties(device_data)->queue_family_properties[pPool->queueFamilyIndex].queueFlags;
3982 if (0 == (queue_flags & (VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT | VK_QUEUE_TRANSFER_BIT))) {
3983 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06003984 HandleToUint64(cb_node->createInfo.commandPool), VALIDATION_ERROR_18e02415,
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003985 "Cannot call vkCmdCopyBufferToImage() on a command buffer allocated from a pool without graphics, compute, "
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06003986 "or transfer capabilities..");
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003987 }
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003988 skip |= ValidateImageBounds(report_data, dst_image_state, regionCount, pRegions, "vkCmdCopyBufferToImage()",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003989 VALIDATION_ERROR_18e00158);
Chris Forbese8ba09a2017-06-01 17:39:02 -07003990 skip |= ValidateBufferBounds(report_data, dst_image_state, src_buffer_state, regionCount, pRegions, "vkCmdCopyBufferToImage()",
Dave Houlton33c2d252017-06-09 17:08:32 -06003991 VALIDATION_ERROR_18e00156);
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003992 skip |= ValidateImageSampleCount(device_data, dst_image_state, VK_SAMPLE_COUNT_1_BIT, "vkCmdCopyBufferToImage(): dstImage",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003993 VALIDATION_ERROR_18e00166);
3994 skip |= ValidateMemoryIsBoundToBuffer(device_data, src_buffer_state, "vkCmdCopyBufferToImage()", VALIDATION_ERROR_18e00160);
3995 skip |= ValidateMemoryIsBoundToImage(device_data, dst_image_state, "vkCmdCopyBufferToImage()", VALIDATION_ERROR_18e00164);
3996 skip |= ValidateBufferUsageFlags(device_data, src_buffer_state, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, true,
3997 VALIDATION_ERROR_18e0015c, "vkCmdCopyBufferToImage()", "VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
3998 skip |= ValidateImageUsageFlags(device_data, dst_image_state, VK_IMAGE_USAGE_TRANSFER_DST_BIT, true, VALIDATION_ERROR_18e00162,
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003999 "vkCmdCopyBufferToImage()", "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06004000 skip |= insideRenderPass(device_data, cb_node, "vkCmdCopyBufferToImage()", VALIDATION_ERROR_18e00017);
Tobin Ehlisc8266452017-04-07 12:20:30 -06004001 bool hit_error = false;
Mark Lobodzinski033c90b2017-02-15 13:58:23 -07004002 for (uint32_t i = 0; i < regionCount; ++i) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06004003 skip |= VerifyImageLayout(device_data, cb_node, dst_image_state, pRegions[i].imageSubresource, dstImageLayout,
4004 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, "vkCmdCopyBufferToImage()", VALIDATION_ERROR_18e0016a,
4005 &hit_error);
Mark Lobodzinski033c90b2017-02-15 13:58:23 -07004006 skip |= ValidateCopyBufferImageTransferGranularityRequirements(device_data, cb_node, dst_image_state, &pRegions[i], i,
4007 "vkCmdCopyBufferToImage()");
4008 }
4009 return skip;
4010}
4011
Mark Lobodzinski1fe9b002017-02-15 14:11:12 -07004012void PreCallRecordCmdCopyBufferToImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, BUFFER_STATE *src_buffer_state,
Tobin Ehlise35b66a2017-03-15 12:18:31 -06004013 IMAGE_STATE *dst_image_state, uint32_t region_count, const VkBufferImageCopy *regions,
4014 VkImageLayout dst_image_layout) {
4015 // Make sure that all image slices are updated to correct layout
4016 for (uint32_t i = 0; i < region_count; ++i) {
4017 SetImageLayout(device_data, cb_node, dst_image_state, regions[i].imageSubresource, dst_image_layout);
4018 }
Mark Lobodzinski1fe9b002017-02-15 14:11:12 -07004019 AddCommandBufferBindingBuffer(device_data, cb_node, src_buffer_state);
Mark Lobodzinski033c90b2017-02-15 13:58:23 -07004020 AddCommandBufferBindingImage(device_data, cb_node, dst_image_state);
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07004021 std::function<bool()> function = [=]() {
4022 SetImageMemoryValid(device_data, dst_image_state, true);
4023 return false;
4024 };
Tobin Ehlisa17a5292017-07-28 12:11:30 -06004025 cb_node->queue_submit_functions.push_back(function);
Mark Lobodzinski1fe9b002017-02-15 14:11:12 -07004026 function = [=]() { return ValidateBufferMemoryIsValid(device_data, src_buffer_state, "vkCmdCopyBufferToImage()"); };
Tobin Ehlisa17a5292017-07-28 12:11:30 -06004027 cb_node->queue_submit_functions.push_back(function);
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07004028}
Mike Weiblen672b58b2017-02-21 14:32:53 -07004029
4030bool PreCallValidateGetImageSubresourceLayout(layer_data *device_data, VkImage image, const VkImageSubresource *pSubresource) {
4031 const auto report_data = core_validation::GetReportData(device_data);
4032 bool skip = false;
4033 const VkImageAspectFlags sub_aspect = pSubresource->aspectMask;
4034
Dave Houlton1d960ff2018-01-19 12:17:05 -07004035 // The aspectMask member of pSubresource must only have a single bit set
Mike Weiblen672b58b2017-02-21 14:32:53 -07004036 const int num_bits = sizeof(sub_aspect) * CHAR_BIT;
4037 std::bitset<num_bits> aspect_mask_bits(sub_aspect);
4038 if (aspect_mask_bits.count() != 1) {
Petr Krausbc7f5442017-05-14 23:43:38 +02004039 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, HandleToUint64(image),
Mark Lobodzinski88529492018-04-01 10:38:15 -06004040 VALIDATION_ERROR_2a6007ca,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06004041 "vkGetImageSubresourceLayout(): VkImageSubresource.aspectMask must have exactly 1 bit set.");
Mike Weiblen672b58b2017-02-21 14:32:53 -07004042 }
4043
4044 IMAGE_STATE *image_entry = GetImageState(device_data, image);
4045 if (!image_entry) {
4046 return skip;
4047 }
4048
Dave Houlton1d960ff2018-01-19 12:17:05 -07004049 // image must have been created with tiling equal to VK_IMAGE_TILING_LINEAR
Mike Weiblen672b58b2017-02-21 14:32:53 -07004050 if (image_entry->createInfo.tiling != VK_IMAGE_TILING_LINEAR) {
Mark Lobodzinski88529492018-04-01 10:38:15 -06004051 skip |=
4052 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, HandleToUint64(image),
4053 VALIDATION_ERROR_2a6007c8, "vkGetImageSubresourceLayout(): Image must have tiling of VK_IMAGE_TILING_LINEAR.");
Mike Weiblen672b58b2017-02-21 14:32:53 -07004054 }
4055
Dave Houlton1d960ff2018-01-19 12:17:05 -07004056 // mipLevel must be less than the mipLevels specified in VkImageCreateInfo when the image was created
Mike Weiblen672b58b2017-02-21 14:32:53 -07004057 if (pSubresource->mipLevel >= image_entry->createInfo.mipLevels) {
Mark Lobodzinski88529492018-04-01 10:38:15 -06004058 skip |=
4059 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, HandleToUint64(image),
4060 VALIDATION_ERROR_2a600d68, "vkGetImageSubresourceLayout(): pSubresource.mipLevel (%d) must be less than %d.",
4061 pSubresource->mipLevel, image_entry->createInfo.mipLevels);
Mike Weiblen672b58b2017-02-21 14:32:53 -07004062 }
4063
Dave Houlton1d960ff2018-01-19 12:17:05 -07004064 // arrayLayer must be less than the arrayLayers specified in VkImageCreateInfo when the image was created
Mike Weiblen672b58b2017-02-21 14:32:53 -07004065 if (pSubresource->arrayLayer >= image_entry->createInfo.arrayLayers) {
Mark Lobodzinski88529492018-04-01 10:38:15 -06004066 skip |=
4067 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, HandleToUint64(image),
4068 VALIDATION_ERROR_2a600d6a, "vkGetImageSubresourceLayout(): pSubresource.arrayLayer (%d) must be less than %d.",
4069 pSubresource->arrayLayer, image_entry->createInfo.arrayLayers);
Mike Weiblen672b58b2017-02-21 14:32:53 -07004070 }
4071
Dave Houlton1d960ff2018-01-19 12:17:05 -07004072 // subresource's aspect must be compatible with image's format.
Mike Weiblen672b58b2017-02-21 14:32:53 -07004073 const VkFormat img_format = image_entry->createInfo.format;
Dave Houlton1d960ff2018-01-19 12:17:05 -07004074 if (FormatIsMultiplane(img_format)) {
4075 VkImageAspectFlags allowed_flags = (VK_IMAGE_ASPECT_PLANE_0_BIT_KHR | VK_IMAGE_ASPECT_PLANE_1_BIT_KHR);
4076 UNIQUE_VALIDATION_ERROR_CODE vuid = VALIDATION_ERROR_2a600c5a; // 2-plane version
4077 if (FormatPlaneCount(img_format) > 2u) {
4078 allowed_flags |= VK_IMAGE_ASPECT_PLANE_2_BIT_KHR;
4079 vuid = VALIDATION_ERROR_2a600c5c; // 3-plane version
4080 }
4081 if (sub_aspect != (sub_aspect & allowed_flags)) {
4082 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06004083 HandleToUint64(image), vuid,
Dave Houlton1d960ff2018-01-19 12:17:05 -07004084 "vkGetImageSubresourceLayout(): For multi-planar images, VkImageSubresource.aspectMask (0x%" PRIx32
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06004085 ") must be a single-plane specifier flag.",
4086 sub_aspect);
Dave Houlton1d960ff2018-01-19 12:17:05 -07004087 }
4088 } else if (FormatIsColor(img_format)) {
Mike Weiblen672b58b2017-02-21 14:32:53 -07004089 if (sub_aspect != VK_IMAGE_ASPECT_COLOR_BIT) {
Dave Houlton852287e2018-01-19 15:11:51 -07004090 skip |= log_msg(
Mark Lobodzinskib1fd9d12018-03-30 14:26:00 -06004091 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, HandleToUint64(image),
Mark Lobodzinski88529492018-04-01 10:38:15 -06004092 VALIDATION_ERROR_0a400c01,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06004093 "vkGetImageSubresourceLayout(): For color formats, VkImageSubresource.aspectMask must be VK_IMAGE_ASPECT_COLOR.");
Mike Weiblen672b58b2017-02-21 14:32:53 -07004094 }
Dave Houlton1d2022c2017-03-29 11:43:58 -06004095 } else if (FormatIsDepthOrStencil(img_format)) {
Mike Weiblen672b58b2017-02-21 14:32:53 -07004096 if ((sub_aspect != VK_IMAGE_ASPECT_DEPTH_BIT) && (sub_aspect != VK_IMAGE_ASPECT_STENCIL_BIT)) {
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06004097 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06004098 HandleToUint64(image), VALIDATION_ERROR_0a400c01,
Mike Weiblen672b58b2017-02-21 14:32:53 -07004099 "vkGetImageSubresourceLayout(): For depth/stencil formats, VkImageSubresource.aspectMask must be "
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06004100 "either VK_IMAGE_ASPECT_DEPTH_BIT or VK_IMAGE_ASPECT_STENCIL_BIT.");
Mike Weiblen672b58b2017-02-21 14:32:53 -07004101 }
4102 }
4103 return skip;
4104}