blob: a6903dfa41c424364e786599c2b20773aae8bcf9 [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
Petr Kraus4d718682017-05-18 03:38:41 +020025#include <inttypes.h>
Mark Lobodzinski90224de2017-01-26 15:23:11 -070026#include <sstream>
Petr Kraus4d718682017-05-18 03:38:41 +020027#include <string>
Mark Lobodzinski90224de2017-01-26 15:23:11 -070028
29#include "vk_enum_string_helper.h"
30#include "vk_layer_data.h"
31#include "vk_layer_utils.h"
32#include "vk_layer_logging.h"
33
Mark Lobodzinskid42e4d22017-01-17 14:14:22 -070034#include "buffer_validation.h"
Mark Lobodzinski42fe5f72017-01-11 11:36:16 -070035
Petr Kraus4d718682017-05-18 03:38:41 +020036// TODO: remove on NDK update (r15 will probably have proper STL impl)
37#ifdef __ANDROID__
38namespace std {
39
40template <typename T>
41std::string to_string(T var) {
42 std::ostringstream ss;
43 ss << var;
44 return ss.str();
45}
46}
47#endif
48
Tobin Ehlis58c884f2017-02-08 12:15:27 -070049void SetLayout(layer_data *device_data, GLOBAL_CB_NODE *pCB, ImageSubresourcePair imgpair, const VkImageLayout &layout) {
Chris Forbes4eab4b02017-04-26 10:21:20 -070050 if (pCB->imageLayoutMap.find(imgpair) != pCB->imageLayoutMap.end()) {
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -070051 pCB->imageLayoutMap[imgpair].layout = layout;
52 } else {
53 assert(imgpair.hasSubresource);
54 IMAGE_CMD_BUF_LAYOUT_NODE node;
55 if (!FindCmdBufLayout(device_data, pCB, imgpair.image, imgpair.subresource, node)) {
56 node.initialLayout = layout;
57 }
58 SetLayout(device_data, pCB, imgpair, {node.initialLayout, layout});
59 }
60}
61template <class OBJECT, class LAYOUT>
Tobin Ehlis58c884f2017-02-08 12:15:27 -070062void SetLayout(layer_data *device_data, OBJECT *pObject, VkImage image, VkImageSubresource range, const LAYOUT &layout) {
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -070063 ImageSubresourcePair imgpair = {image, true, range};
64 SetLayout(device_data, pObject, imgpair, layout, VK_IMAGE_ASPECT_COLOR_BIT);
65 SetLayout(device_data, pObject, imgpair, layout, VK_IMAGE_ASPECT_DEPTH_BIT);
66 SetLayout(device_data, pObject, imgpair, layout, VK_IMAGE_ASPECT_STENCIL_BIT);
67 SetLayout(device_data, pObject, imgpair, layout, VK_IMAGE_ASPECT_METADATA_BIT);
68}
69
70template <class OBJECT, class LAYOUT>
Tobin Ehlis58c884f2017-02-08 12:15:27 -070071void SetLayout(layer_data *device_data, OBJECT *pObject, ImageSubresourcePair imgpair, const LAYOUT &layout,
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -070072 VkImageAspectFlags aspectMask) {
73 if (imgpair.subresource.aspectMask & aspectMask) {
74 imgpair.subresource.aspectMask = aspectMask;
75 SetLayout(device_data, pObject, imgpair, layout);
76 }
77}
78
Tony Barbourdf013b92017-01-25 12:53:48 -070079// Set the layout in supplied map
Tony Barboure0c5cc92017-02-08 13:53:39 -070080void SetLayout(std::unordered_map<ImageSubresourcePair, IMAGE_LAYOUT_NODE> &imageLayoutMap, ImageSubresourcePair imgpair,
81 VkImageLayout layout) {
Tony Barbourdf013b92017-01-25 12:53:48 -070082 imageLayoutMap[imgpair].layout = layout;
83}
84
Tobin Ehlisc8266452017-04-07 12:20:30 -060085bool FindLayoutVerifyNode(layer_data const *device_data, GLOBAL_CB_NODE const *pCB, ImageSubresourcePair imgpair,
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -070086 IMAGE_CMD_BUF_LAYOUT_NODE &node, const VkImageAspectFlags aspectMask) {
87 const debug_report_data *report_data = core_validation::GetReportData(device_data);
88
89 if (!(imgpair.subresource.aspectMask & aspectMask)) {
90 return false;
91 }
92 VkImageAspectFlags oldAspectMask = imgpair.subresource.aspectMask;
93 imgpair.subresource.aspectMask = aspectMask;
94 auto imgsubIt = pCB->imageLayoutMap.find(imgpair);
95 if (imgsubIt == pCB->imageLayoutMap.end()) {
96 return false;
97 }
98 if (node.layout != VK_IMAGE_LAYOUT_MAX_ENUM && node.layout != imgsubIt->second.layout) {
Petr Krausbc7f5442017-05-14 23:43:38 +020099 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, HandleToUint64(imgpair.image),
100 __LINE__, DRAWSTATE_INVALID_LAYOUT, "DS",
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700101 "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 +0200102 HandleToUint64(imgpair.image), oldAspectMask, string_VkImageLayout(node.layout),
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700103 string_VkImageLayout(imgsubIt->second.layout));
104 }
105 if (node.initialLayout != VK_IMAGE_LAYOUT_MAX_ENUM && node.initialLayout != imgsubIt->second.initialLayout) {
Petr Krausbc7f5442017-05-14 23:43:38 +0200106 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, HandleToUint64(imgpair.image),
107 __LINE__, DRAWSTATE_INVALID_LAYOUT, "DS",
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700108 "Cannot query for VkImage 0x%" PRIx64
109 " layout when combined aspect mask %d has multiple initial layout types: %s and %s",
Petr Krausbc7f5442017-05-14 23:43:38 +0200110 HandleToUint64(imgpair.image), oldAspectMask, string_VkImageLayout(node.initialLayout),
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700111 string_VkImageLayout(imgsubIt->second.initialLayout));
112 }
113 node = imgsubIt->second;
114 return true;
115}
116
Tobin Ehlisc8266452017-04-07 12:20:30 -0600117bool FindLayoutVerifyLayout(layer_data const *device_data, ImageSubresourcePair imgpair, VkImageLayout &layout,
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700118 const VkImageAspectFlags aspectMask) {
119 if (!(imgpair.subresource.aspectMask & aspectMask)) {
120 return false;
121 }
122 const debug_report_data *report_data = core_validation::GetReportData(device_data);
123 VkImageAspectFlags oldAspectMask = imgpair.subresource.aspectMask;
124 imgpair.subresource.aspectMask = aspectMask;
125 auto imgsubIt = (*core_validation::GetImageLayoutMap(device_data)).find(imgpair);
126 if (imgsubIt == (*core_validation::GetImageLayoutMap(device_data)).end()) {
127 return false;
128 }
129 if (layout != VK_IMAGE_LAYOUT_MAX_ENUM && layout != imgsubIt->second.layout) {
Petr Krausbc7f5442017-05-14 23:43:38 +0200130 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, HandleToUint64(imgpair.image),
131 __LINE__, DRAWSTATE_INVALID_LAYOUT, "DS",
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700132 "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 +0200133 HandleToUint64(imgpair.image), oldAspectMask, string_VkImageLayout(layout),
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700134 string_VkImageLayout(imgsubIt->second.layout));
135 }
136 layout = imgsubIt->second.layout;
137 return true;
138}
139
140// Find layout(s) on the command buffer level
Tobin Ehlisc8266452017-04-07 12:20:30 -0600141bool FindCmdBufLayout(layer_data const *device_data, GLOBAL_CB_NODE const *pCB, VkImage image, VkImageSubresource range,
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700142 IMAGE_CMD_BUF_LAYOUT_NODE &node) {
143 ImageSubresourcePair imgpair = {image, true, range};
144 node = IMAGE_CMD_BUF_LAYOUT_NODE(VK_IMAGE_LAYOUT_MAX_ENUM, VK_IMAGE_LAYOUT_MAX_ENUM);
145 FindLayoutVerifyNode(device_data, pCB, imgpair, node, VK_IMAGE_ASPECT_COLOR_BIT);
146 FindLayoutVerifyNode(device_data, pCB, imgpair, node, VK_IMAGE_ASPECT_DEPTH_BIT);
147 FindLayoutVerifyNode(device_data, pCB, imgpair, node, VK_IMAGE_ASPECT_STENCIL_BIT);
148 FindLayoutVerifyNode(device_data, pCB, imgpair, node, VK_IMAGE_ASPECT_METADATA_BIT);
149 if (node.layout == VK_IMAGE_LAYOUT_MAX_ENUM) {
150 imgpair = {image, false, VkImageSubresource()};
151 auto imgsubIt = pCB->imageLayoutMap.find(imgpair);
152 if (imgsubIt == pCB->imageLayoutMap.end()) return false;
153 // TODO: This is ostensibly a find function but it changes state here
154 node = imgsubIt->second;
155 }
156 return true;
157}
158
159// Find layout(s) on the global level
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700160bool FindGlobalLayout(layer_data *device_data, ImageSubresourcePair imgpair, VkImageLayout &layout) {
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700161 layout = VK_IMAGE_LAYOUT_MAX_ENUM;
162 FindLayoutVerifyLayout(device_data, imgpair, layout, VK_IMAGE_ASPECT_COLOR_BIT);
163 FindLayoutVerifyLayout(device_data, imgpair, layout, VK_IMAGE_ASPECT_DEPTH_BIT);
164 FindLayoutVerifyLayout(device_data, imgpair, layout, VK_IMAGE_ASPECT_STENCIL_BIT);
165 FindLayoutVerifyLayout(device_data, imgpair, layout, VK_IMAGE_ASPECT_METADATA_BIT);
166 if (layout == VK_IMAGE_LAYOUT_MAX_ENUM) {
167 imgpair = {imgpair.image, false, VkImageSubresource()};
168 auto imgsubIt = (*core_validation::GetImageLayoutMap(device_data)).find(imgpair);
169 if (imgsubIt == (*core_validation::GetImageLayoutMap(device_data)).end()) return false;
170 layout = imgsubIt->second.layout;
171 }
172 return true;
173}
174
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700175bool FindLayouts(layer_data *device_data, VkImage image, std::vector<VkImageLayout> &layouts) {
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700176 auto sub_data = (*core_validation::GetImageSubresourceMap(device_data)).find(image);
177 if (sub_data == (*core_validation::GetImageSubresourceMap(device_data)).end()) return false;
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -0700178 auto image_state = GetImageState(device_data, image);
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700179 if (!image_state) return false;
180 bool ignoreGlobal = false;
181 // TODO: Make this robust for >1 aspect mask. Now it will just say ignore potential errors in this case.
182 if (sub_data->second.size() >= (image_state->createInfo.arrayLayers * image_state->createInfo.mipLevels + 1)) {
183 ignoreGlobal = true;
184 }
185 for (auto imgsubpair : sub_data->second) {
186 if (ignoreGlobal && !imgsubpair.hasSubresource) continue;
187 auto img_data = (*core_validation::GetImageLayoutMap(device_data)).find(imgsubpair);
188 if (img_data != (*core_validation::GetImageLayoutMap(device_data)).end()) {
189 layouts.push_back(img_data->second.layout);
190 }
191 }
192 return true;
193}
Tony Barboure0c5cc92017-02-08 13:53:39 -0700194bool FindLayout(const std::unordered_map<ImageSubresourcePair, IMAGE_LAYOUT_NODE> &imageLayoutMap, ImageSubresourcePair imgpair,
195 VkImageLayout &layout, const VkImageAspectFlags aspectMask) {
Tony Barbourdf013b92017-01-25 12:53:48 -0700196 if (!(imgpair.subresource.aspectMask & aspectMask)) {
197 return false;
198 }
199 imgpair.subresource.aspectMask = aspectMask;
200 auto imgsubIt = imageLayoutMap.find(imgpair);
201 if (imgsubIt == imageLayoutMap.end()) {
202 return false;
203 }
204 layout = imgsubIt->second.layout;
205 return true;
Tony Barboure0c5cc92017-02-08 13:53:39 -0700206}
Tony Barbourdf013b92017-01-25 12:53:48 -0700207
208// find layout in supplied map
Tony Barboure0c5cc92017-02-08 13:53:39 -0700209bool FindLayout(const std::unordered_map<ImageSubresourcePair, IMAGE_LAYOUT_NODE> &imageLayoutMap, ImageSubresourcePair imgpair,
210 VkImageLayout &layout) {
Tony Barbourdf013b92017-01-25 12:53:48 -0700211 layout = VK_IMAGE_LAYOUT_MAX_ENUM;
212 FindLayout(imageLayoutMap, imgpair, layout, VK_IMAGE_ASPECT_COLOR_BIT);
213 FindLayout(imageLayoutMap, imgpair, layout, VK_IMAGE_ASPECT_DEPTH_BIT);
214 FindLayout(imageLayoutMap, imgpair, layout, VK_IMAGE_ASPECT_STENCIL_BIT);
215 FindLayout(imageLayoutMap, imgpair, layout, VK_IMAGE_ASPECT_METADATA_BIT);
216 if (layout == VK_IMAGE_LAYOUT_MAX_ENUM) {
217 imgpair = {imgpair.image, false, VkImageSubresource()};
218 auto imgsubIt = imageLayoutMap.find(imgpair);
219 if (imgsubIt == imageLayoutMap.end()) return false;
220 layout = imgsubIt->second.layout;
221 }
222 return true;
223}
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700224
225// Set the layout on the global level
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700226void SetGlobalLayout(layer_data *device_data, ImageSubresourcePair imgpair, const VkImageLayout &layout) {
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700227 VkImage &image = imgpair.image;
228 (*core_validation::GetImageLayoutMap(device_data))[imgpair].layout = layout;
229 auto &image_subresources = (*core_validation::GetImageSubresourceMap(device_data))[image];
230 auto subresource = std::find(image_subresources.begin(), image_subresources.end(), imgpair);
231 if (subresource == image_subresources.end()) {
232 image_subresources.push_back(imgpair);
233 }
234}
235
236// Set the layout on the cmdbuf level
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700237void SetLayout(layer_data *device_data, GLOBAL_CB_NODE *pCB, ImageSubresourcePair imgpair, const IMAGE_CMD_BUF_LAYOUT_NODE &node) {
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700238 pCB->imageLayoutMap[imgpair] = node;
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700239}
Tobin Ehlise35b66a2017-03-15 12:18:31 -0600240// Set image layout for given VkImageSubresourceRange struct
241void SetImageLayout(layer_data *device_data, GLOBAL_CB_NODE *cb_node, const IMAGE_STATE *image_state,
242 VkImageSubresourceRange image_subresource_range, const VkImageLayout &layout) {
243 assert(image_state);
244 for (uint32_t level_index = 0; level_index < image_subresource_range.levelCount; ++level_index) {
245 uint32_t level = image_subresource_range.baseMipLevel + level_index;
246 for (uint32_t layer_index = 0; layer_index < image_subresource_range.layerCount; layer_index++) {
247 uint32_t layer = image_subresource_range.baseArrayLayer + layer_index;
248 VkImageSubresource sub = {image_subresource_range.aspectMask, level, layer};
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700249 // TODO: If ImageView was created with depth or stencil, transition both layouts as the aspectMask is ignored and both
250 // are used. Verify that the extra implicit layout is OK for descriptor set layout validation
Tobin Ehlise35b66a2017-03-15 12:18:31 -0600251 if (image_subresource_range.aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) {
Dave Houlton1d2022c2017-03-29 11:43:58 -0600252 if (FormatIsDepthAndStencil(image_state->createInfo.format)) {
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700253 sub.aspectMask |= (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT);
254 }
255 }
Tobin Ehlise35b66a2017-03-15 12:18:31 -0600256 SetLayout(device_data, cb_node, image_state->image, sub, layout);
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700257 }
258 }
259}
Tobin Ehlise35b66a2017-03-15 12:18:31 -0600260// Set image layout for given VkImageSubresourceLayers struct
261void SetImageLayout(layer_data *device_data, GLOBAL_CB_NODE *cb_node, const IMAGE_STATE *image_state,
262 VkImageSubresourceLayers image_subresource_layers, const VkImageLayout &layout) {
263 // Transfer VkImageSubresourceLayers into VkImageSubresourceRange struct
264 VkImageSubresourceRange image_subresource_range;
265 image_subresource_range.aspectMask = image_subresource_layers.aspectMask;
266 image_subresource_range.baseArrayLayer = image_subresource_layers.baseArrayLayer;
267 image_subresource_range.layerCount = image_subresource_layers.layerCount;
268 image_subresource_range.baseMipLevel = image_subresource_layers.mipLevel;
269 image_subresource_range.levelCount = 1;
270 SetImageLayout(device_data, cb_node, image_state, image_subresource_range, layout);
271}
272// Set image layout for all slices of an image view
273void SetImageViewLayout(layer_data *device_data, GLOBAL_CB_NODE *cb_node, VkImageView imageView, const VkImageLayout &layout) {
274 auto view_state = GetImageViewState(device_data, imageView);
275 assert(view_state);
276
277 SetImageLayout(device_data, cb_node, GetImageState(device_data, view_state->create_info.image),
278 view_state->create_info.subresourceRange, layout);
279}
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700280
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700281bool VerifyFramebufferAndRenderPassLayouts(layer_data *device_data, GLOBAL_CB_NODE *pCB,
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700282 const VkRenderPassBeginInfo *pRenderPassBegin,
283 const FRAMEBUFFER_STATE *framebuffer_state) {
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600284 bool skip = false;
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -0700285 auto const pRenderPassInfo = GetRenderPassState(device_data, pRenderPassBegin->renderPass)->createInfo.ptr();
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700286 auto const &framebufferInfo = framebuffer_state->createInfo;
287 const auto report_data = core_validation::GetReportData(device_data);
288 if (pRenderPassInfo->attachmentCount != framebufferInfo.attachmentCount) {
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600289 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +0200290 HandleToUint64(pCB->commandBuffer), __LINE__, DRAWSTATE_INVALID_RENDERPASS, "DS",
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600291 "You cannot start a render pass using a framebuffer "
292 "with a different number of attachments.");
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700293 }
294 for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) {
295 const VkImageView &image_view = framebufferInfo.pAttachments[i];
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -0700296 auto view_state = GetImageViewState(device_data, image_view);
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700297 assert(view_state);
298 const VkImage &image = view_state->create_info.image;
299 const VkImageSubresourceRange &subRange = view_state->create_info.subresourceRange;
Tobin Ehlis0d4274b2017-02-17 15:17:04 -0700300 auto initial_layout = pRenderPassInfo->pAttachments[i].initialLayout;
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700301 // TODO: Do not iterate over every possibility - consolidate where possible
302 for (uint32_t j = 0; j < subRange.levelCount; j++) {
303 uint32_t level = subRange.baseMipLevel + j;
304 for (uint32_t k = 0; k < subRange.layerCount; k++) {
305 uint32_t layer = subRange.baseArrayLayer + k;
306 VkImageSubresource sub = {subRange.aspectMask, level, layer};
307 IMAGE_CMD_BUF_LAYOUT_NODE node;
308 if (!FindCmdBufLayout(device_data, pCB, image, sub, node)) {
Tobin Ehlis0d4274b2017-02-17 15:17:04 -0700309 // Missing layouts will be added during state update
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700310 continue;
311 }
Tobin Ehlis0d4274b2017-02-17 15:17:04 -0700312 if (initial_layout != VK_IMAGE_LAYOUT_UNDEFINED && initial_layout != node.layout) {
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600313 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
314 __LINE__, DRAWSTATE_INVALID_RENDERPASS, "DS",
315 "You cannot start a render pass using attachment %u "
316 "where the render pass initial layout is %s and the previous "
317 "known layout of the attachment is %s. The layouts must match, or "
318 "the render pass initial layout for the attachment must be "
319 "VK_IMAGE_LAYOUT_UNDEFINED",
320 i, string_VkImageLayout(initial_layout), string_VkImageLayout(node.layout));
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700321 }
322 }
323 }
324 }
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600325 return skip;
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700326}
327
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700328void TransitionAttachmentRefLayout(layer_data *device_data, GLOBAL_CB_NODE *pCB, FRAMEBUFFER_STATE *pFramebuffer,
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700329 VkAttachmentReference ref) {
330 if (ref.attachment != VK_ATTACHMENT_UNUSED) {
331 auto image_view = pFramebuffer->createInfo.pAttachments[ref.attachment];
332 SetImageViewLayout(device_data, pCB, image_view, ref.layout);
333 }
334}
335
Tobin Ehlis0d4274b2017-02-17 15:17:04 -0700336void TransitionSubpassLayouts(layer_data *device_data, GLOBAL_CB_NODE *pCB, const RENDER_PASS_STATE *render_pass_state,
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700337 const int subpass_index, FRAMEBUFFER_STATE *framebuffer_state) {
Tobin Ehlis0d4274b2017-02-17 15:17:04 -0700338 assert(render_pass_state);
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700339
340 if (framebuffer_state) {
Tobin Ehlis0d4274b2017-02-17 15:17:04 -0700341 auto const &subpass = render_pass_state->createInfo.pSubpasses[subpass_index];
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700342 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
343 TransitionAttachmentRefLayout(device_data, pCB, framebuffer_state, subpass.pInputAttachments[j]);
344 }
345 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
346 TransitionAttachmentRefLayout(device_data, pCB, framebuffer_state, subpass.pColorAttachments[j]);
347 }
348 if (subpass.pDepthStencilAttachment) {
349 TransitionAttachmentRefLayout(device_data, pCB, framebuffer_state, *subpass.pDepthStencilAttachment);
350 }
351 }
352}
353
Mark Lobodzinski6b6c50a2017-02-27 12:56:14 -0700354bool ValidateImageAspectLayout(layer_data *device_data, GLOBAL_CB_NODE *pCB, const VkImageMemoryBarrier *mem_barrier,
355 uint32_t level, uint32_t layer, VkImageAspectFlags aspect) {
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700356 if (!(mem_barrier->subresourceRange.aspectMask & aspect)) {
357 return false;
358 }
359 VkImageSubresource sub = {aspect, level, layer};
360 IMAGE_CMD_BUF_LAYOUT_NODE node;
361 if (!FindCmdBufLayout(device_data, pCB, mem_barrier->image, sub, node)) {
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700362 return false;
363 }
364 bool skip = false;
365 if (mem_barrier->oldLayout == VK_IMAGE_LAYOUT_UNDEFINED) {
366 // TODO: Set memory invalid which is in mem_tracker currently
367 } else if (node.layout != mem_barrier->oldLayout) {
Mark Lobodzinski91c28262017-03-22 13:06:12 -0600368 skip |=
369 log_msg(core_validation::GetReportData(device_data), VK_DEBUG_REPORT_ERROR_BIT_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +0200370 VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, HandleToUint64(pCB->commandBuffer), __LINE__,
Mark Lobodzinski91c28262017-03-22 13:06:12 -0600371 DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
372 "For image 0x%" PRIxLEAST64 " you cannot transition the layout of aspect %d from %s when current layout is %s.",
Petr Krausbc7f5442017-05-14 23:43:38 +0200373 HandleToUint64(mem_barrier->image), aspect, string_VkImageLayout(mem_barrier->oldLayout),
Mark Lobodzinski91c28262017-03-22 13:06:12 -0600374 string_VkImageLayout(node.layout));
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700375 }
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700376 return skip;
377}
378
Tobin Ehlis0d4274b2017-02-17 15:17:04 -0700379// Transition the layout state for renderpass attachments based on the BeginRenderPass() call. This includes:
380// 1. Transition into initialLayout state
381// 2. Transition from initialLayout to layout used in subpass 0
382void TransitionBeginRenderPassLayouts(layer_data *device_data, GLOBAL_CB_NODE *cb_state, const RENDER_PASS_STATE *render_pass_state,
383 FRAMEBUFFER_STATE *framebuffer_state) {
384 // First transition into initialLayout
385 auto const rpci = render_pass_state->createInfo.ptr();
386 for (uint32_t i = 0; i < rpci->attachmentCount; ++i) {
387 VkImageView image_view = framebuffer_state->createInfo.pAttachments[i];
388 SetImageViewLayout(device_data, cb_state, image_view, rpci->pAttachments[i].initialLayout);
389 }
390 // Now transition for first subpass (index 0)
391 TransitionSubpassLayouts(device_data, cb_state, render_pass_state, 0, framebuffer_state);
392}
393
Mark Lobodzinski6b6c50a2017-02-27 12:56:14 -0700394void TransitionImageAspectLayout(layer_data *device_data, GLOBAL_CB_NODE *pCB, const VkImageMemoryBarrier *mem_barrier,
395 uint32_t level, uint32_t layer, VkImageAspectFlags aspect) {
396 if (!(mem_barrier->subresourceRange.aspectMask & aspect)) {
397 return;
398 }
399 VkImageSubresource sub = {aspect, level, layer};
400 IMAGE_CMD_BUF_LAYOUT_NODE node;
401 if (!FindCmdBufLayout(device_data, pCB, mem_barrier->image, sub, node)) {
402 SetLayout(device_data, pCB, mem_barrier->image, sub,
403 IMAGE_CMD_BUF_LAYOUT_NODE(mem_barrier->oldLayout, mem_barrier->newLayout));
404 return;
405 }
406 if (mem_barrier->oldLayout == VK_IMAGE_LAYOUT_UNDEFINED) {
407 // TODO: Set memory invalid
408 }
409 SetLayout(device_data, pCB, mem_barrier->image, sub, mem_barrier->newLayout);
410}
411
Dave Houlton10b39482017-03-16 13:18:15 -0600412bool VerifyAspectsPresent(VkImageAspectFlags aspect_mask, VkFormat format) {
Dave Houlton4eaaf3a2017-03-14 11:31:20 -0600413 if ((aspect_mask & VK_IMAGE_ASPECT_COLOR_BIT) != 0) {
Dave Houlton1d2022c2017-03-29 11:43:58 -0600414 if (!FormatIsColor(format)) return false;
Dave Houlton4eaaf3a2017-03-14 11:31:20 -0600415 }
416 if ((aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) != 0) {
Dave Houlton1d2022c2017-03-29 11:43:58 -0600417 if (!FormatHasDepth(format)) return false;
Dave Houlton4eaaf3a2017-03-14 11:31:20 -0600418 }
419 if ((aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) != 0) {
Dave Houlton1d2022c2017-03-29 11:43:58 -0600420 if (!FormatHasStencil(format)) return false;
Dave Houlton4eaaf3a2017-03-14 11:31:20 -0600421 }
422 return true;
423}
424
Mike Weiblen62d08a32017-03-07 22:18:27 -0700425// Verify an ImageMemoryBarrier's old/new ImageLayouts are compatible with the Image's ImageUsageFlags.
426bool ValidateBarrierLayoutToImageUsage(layer_data *device_data, const VkImageMemoryBarrier *img_barrier, bool new_not_old,
427 VkImageUsageFlags usage_flags, const char *func_name) {
428 const auto report_data = core_validation::GetReportData(device_data);
429 bool skip = false;
430 const VkImageLayout layout = (new_not_old) ? img_barrier->newLayout : img_barrier->oldLayout;
431 UNIQUE_VALIDATION_ERROR_CODE msg_code = VALIDATION_ERROR_UNDEFINED; // sentinel value meaning "no error"
432
433 switch (layout) {
434 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL:
435 if ((usage_flags & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) == 0) {
436 msg_code = VALIDATION_ERROR_00303;
437 }
438 break;
439 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
440 if ((usage_flags & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) == 0) {
441 msg_code = VALIDATION_ERROR_00304;
442 }
443 break;
444 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL:
445 if ((usage_flags & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) == 0) {
446 msg_code = VALIDATION_ERROR_00305;
447 }
448 break;
449 case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL:
450 if ((usage_flags & (VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT)) == 0) {
451 msg_code = VALIDATION_ERROR_00306;
452 }
453 break;
454 case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL:
455 if ((usage_flags & VK_IMAGE_USAGE_TRANSFER_SRC_BIT) == 0) {
456 msg_code = VALIDATION_ERROR_00307;
457 }
458 break;
459 case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL:
460 if ((usage_flags & VK_IMAGE_USAGE_TRANSFER_DST_BIT) == 0) {
461 msg_code = VALIDATION_ERROR_00308;
462 }
463 break;
464 default:
465 // Other VkImageLayout values do not have VUs defined in this context.
466 break;
467 }
468
469 if (msg_code != VALIDATION_ERROR_UNDEFINED) {
Mark Lobodzinski0827aec2017-03-21 16:41:45 -0600470 skip |=
471 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +0200472 HandleToUint64(img_barrier->image), __LINE__, msg_code, "DS",
Mark Lobodzinski0827aec2017-03-21 16:41:45 -0600473 "%s: Image barrier 0x%p %sLayout=%s is not compatible with image 0x%" PRIx64 " usage flags 0x%" PRIx32 ". %s",
474 func_name, img_barrier, ((new_not_old) ? "new" : "old"), string_VkImageLayout(layout),
Petr Krausbc7f5442017-05-14 23:43:38 +0200475 HandleToUint64(img_barrier->image), usage_flags, validation_error_map[msg_code]);
Mike Weiblen62d08a32017-03-07 22:18:27 -0700476 }
477 return skip;
478}
479
480// Verify image barriers are compatible with the images they reference.
481bool ValidateBarriersToImages(layer_data *device_data, VkCommandBuffer cmdBuffer, uint32_t imageMemoryBarrierCount,
482 const VkImageMemoryBarrier *pImageMemoryBarriers, const char *func_name) {
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -0700483 GLOBAL_CB_NODE *pCB = GetCBNode(device_data, cmdBuffer);
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700484 bool skip = false;
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700485
Mike Weiblen62d08a32017-03-07 22:18:27 -0700486 for (uint32_t i = 0; i < imageMemoryBarrierCount; ++i) {
487 auto img_barrier = &pImageMemoryBarriers[i];
488 if (!img_barrier) continue;
489
Tobin Ehlisbb03e5f2017-05-11 08:52:51 -0600490 auto image_state = GetImageState(device_data, img_barrier->image);
491 if (image_state) {
492 VkImageUsageFlags usage_flags = image_state->createInfo.usage;
493 skip |= ValidateBarrierLayoutToImageUsage(device_data, img_barrier, false, usage_flags, func_name);
494 skip |= ValidateBarrierLayoutToImageUsage(device_data, img_barrier, true, usage_flags, func_name);
495
496 // Make sure layout is able to be transitioned, currently only presented shared presentable images are locked
497 if (image_state->layout_locked) {
498 // TODO: Add unique id for error when available
499 skip |= log_msg(core_validation::GetReportData(device_data), VK_DEBUG_REPORT_ERROR_BIT_EXT,
500 VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, 0, "DS",
501 "Attempting to transition shared presentable image 0x%" PRIxLEAST64
502 " from layout %s to layout %s, but image has already been presented and cannot have its layout transitioned.",
503 reinterpret_cast<const uint64_t &>(img_barrier->image), string_VkImageLayout(img_barrier->oldLayout),
504 string_VkImageLayout(img_barrier->newLayout));
505 }
506 }
507
Mark Lobodzinski903e5ff2017-03-23 09:43:35 -0600508 VkImageCreateInfo *image_create_info = &(GetImageState(device_data, img_barrier->image)->createInfo);
Tobin Ehlis7ee9cbd2017-04-26 16:51:48 -0600509 // For a Depth/Stencil image both aspects MUST be set
510 if (FormatIsDepthAndStencil(image_create_info->format)) {
511 auto const aspect_mask = img_barrier->subresourceRange.aspectMask;
512 auto const ds_mask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
513 if ((aspect_mask & ds_mask) != (ds_mask)) {
514 skip |=
515 log_msg(core_validation::GetReportData(device_data), VK_DEBUG_REPORT_ERROR_BIT_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +0200516 VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, HandleToUint64(img_barrier->image), __LINE__,
517 VALIDATION_ERROR_00302, "DS", "%s: Image barrier 0x%p references image 0x%" PRIx64
518 " of format %s that must have the depth and stencil aspects set, but its "
519 "aspectMask is 0x%" PRIx32 ". %s",
520 func_name, img_barrier, HandleToUint64(img_barrier->image), string_VkFormat(image_create_info->format),
521 aspect_mask, validation_error_map[VALIDATION_ERROR_00302]);
Tobin Ehlis7ee9cbd2017-04-26 16:51:48 -0600522 }
523 }
Mark Lobodzinski903e5ff2017-03-23 09:43:35 -0600524 uint32_t level_count = ResolveRemainingLevels(&img_barrier->subresourceRange, image_create_info->mipLevels);
525 uint32_t layer_count = ResolveRemainingLayers(&img_barrier->subresourceRange, image_create_info->arrayLayers);
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700526
Mike Weiblen62d08a32017-03-07 22:18:27 -0700527 for (uint32_t j = 0; j < level_count; j++) {
528 uint32_t level = img_barrier->subresourceRange.baseMipLevel + j;
529 for (uint32_t k = 0; k < layer_count; k++) {
530 uint32_t layer = img_barrier->subresourceRange.baseArrayLayer + k;
531 skip |= ValidateImageAspectLayout(device_data, pCB, img_barrier, level, layer, VK_IMAGE_ASPECT_COLOR_BIT);
532 skip |= ValidateImageAspectLayout(device_data, pCB, img_barrier, level, layer, VK_IMAGE_ASPECT_DEPTH_BIT);
533 skip |= ValidateImageAspectLayout(device_data, pCB, img_barrier, level, layer, VK_IMAGE_ASPECT_STENCIL_BIT);
534 skip |= ValidateImageAspectLayout(device_data, pCB, img_barrier, level, layer, VK_IMAGE_ASPECT_METADATA_BIT);
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700535 }
536 }
537 }
538 return skip;
539}
540
Mark Lobodzinski6b6c50a2017-02-27 12:56:14 -0700541void TransitionImageLayouts(layer_data *device_data, VkCommandBuffer cmdBuffer, uint32_t memBarrierCount,
542 const VkImageMemoryBarrier *pImgMemBarriers) {
543 GLOBAL_CB_NODE *pCB = GetCBNode(device_data, cmdBuffer);
Mark Lobodzinski6b6c50a2017-02-27 12:56:14 -0700544
545 for (uint32_t i = 0; i < memBarrierCount; ++i) {
546 auto mem_barrier = &pImgMemBarriers[i];
547 if (!mem_barrier) continue;
Mark Lobodzinski6b6c50a2017-02-27 12:56:14 -0700548
Mark Lobodzinski903e5ff2017-03-23 09:43:35 -0600549 VkImageCreateInfo *image_create_info = &(GetImageState(device_data, mem_barrier->image)->createInfo);
550 uint32_t level_count = ResolveRemainingLevels(&mem_barrier->subresourceRange, image_create_info->mipLevels);
551 uint32_t layer_count = ResolveRemainingLayers(&mem_barrier->subresourceRange, image_create_info->arrayLayers);
552
553 for (uint32_t j = 0; j < level_count; j++) {
Mark Lobodzinski6b6c50a2017-02-27 12:56:14 -0700554 uint32_t level = mem_barrier->subresourceRange.baseMipLevel + j;
Mark Lobodzinski903e5ff2017-03-23 09:43:35 -0600555 for (uint32_t k = 0; k < layer_count; k++) {
Mark Lobodzinski6b6c50a2017-02-27 12:56:14 -0700556 uint32_t layer = mem_barrier->subresourceRange.baseArrayLayer + k;
557 TransitionImageAspectLayout(device_data, pCB, mem_barrier, level, layer, VK_IMAGE_ASPECT_COLOR_BIT);
558 TransitionImageAspectLayout(device_data, pCB, mem_barrier, level, layer, VK_IMAGE_ASPECT_DEPTH_BIT);
559 TransitionImageAspectLayout(device_data, pCB, mem_barrier, level, layer, VK_IMAGE_ASPECT_STENCIL_BIT);
560 TransitionImageAspectLayout(device_data, pCB, mem_barrier, level, layer, VK_IMAGE_ASPECT_METADATA_BIT);
561 }
562 }
563 }
564}
565
Tobin Ehlisc8266452017-04-07 12:20:30 -0600566bool VerifyImageLayout(layer_data const *device_data, GLOBAL_CB_NODE const *cb_node, IMAGE_STATE *image_state,
Tobin Ehlis2d85ec62017-03-14 15:38:48 -0600567 VkImageSubresourceLayers subLayers, VkImageLayout explicit_layout, VkImageLayout optimal_layout,
Tobin Ehlisc8266452017-04-07 12:20:30 -0600568 const char *caller, UNIQUE_VALIDATION_ERROR_CODE msg_code, bool *error) {
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700569 const auto report_data = core_validation::GetReportData(device_data);
Tobin Ehlis2d85ec62017-03-14 15:38:48 -0600570 const auto image = image_state->image;
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600571 bool skip = false;
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700572
573 for (uint32_t i = 0; i < subLayers.layerCount; ++i) {
574 uint32_t layer = i + subLayers.baseArrayLayer;
575 VkImageSubresource sub = {subLayers.aspectMask, subLayers.mipLevel, layer};
576 IMAGE_CMD_BUF_LAYOUT_NODE node;
Tobin Ehlise35b66a2017-03-15 12:18:31 -0600577 if (FindCmdBufLayout(device_data, cb_node, image, sub, node)) {
578 if (node.layout != explicit_layout) {
Tobin Ehlisc8266452017-04-07 12:20:30 -0600579 *error = true;
Tobin Ehlise35b66a2017-03-15 12:18:31 -0600580 // TODO: Improve log message in the next pass
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600581 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +0200582 HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600583 "%s: Cannot use image 0x%" PRIxLEAST64
584 " with specific layout %s that doesn't match the actual current layout %s.",
Petr Krausbc7f5442017-05-14 23:43:38 +0200585 caller, HandleToUint64(image), string_VkImageLayout(explicit_layout),
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600586 string_VkImageLayout(node.layout));
Tobin Ehlise35b66a2017-03-15 12:18:31 -0600587 }
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700588 }
589 }
Tobin Ehlis2d85ec62017-03-14 15:38:48 -0600590 // If optimal_layout is not UNDEFINED, check that layout matches optimal for this case
591 if ((VK_IMAGE_LAYOUT_UNDEFINED != optimal_layout) && (explicit_layout != optimal_layout)) {
592 if (VK_IMAGE_LAYOUT_GENERAL == explicit_layout) {
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700593 if (image_state->createInfo.tiling != VK_IMAGE_TILING_LINEAR) {
594 // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning.
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600595 skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +0200596 VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, HandleToUint64(cb_node->commandBuffer), __LINE__,
597 DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600598 "%s: For optimal performance image 0x%" PRIxLEAST64 " layout should be %s instead of GENERAL.",
Petr Krausbc7f5442017-05-14 23:43:38 +0200599 caller, HandleToUint64(image), string_VkImageLayout(optimal_layout));
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700600 }
Mark Lobodzinski087380c2017-05-16 14:42:25 -0600601 } else if (GetDeviceExtensions(device_data)->khr_shared_presentable_image) {
602 if (image_state->shared_presentable) {
603 if (VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR != explicit_layout) {
604 // TODO: Add unique error id when available.
605 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
606 __LINE__, msg_code, "DS",
607 "Layout for shared presentable image is %s but must be VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR.",
608 string_VkImageLayout(optimal_layout));
609 }
Tobin Ehlisbb03e5f2017-05-11 08:52:51 -0600610 }
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700611 } else {
Tobin Ehlisc8266452017-04-07 12:20:30 -0600612 *error = true;
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600613 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +0200614 HandleToUint64(cb_node->commandBuffer), __LINE__, msg_code, "DS",
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600615 "%s: Layout for image 0x%" PRIxLEAST64 " is %s but can only be %s or VK_IMAGE_LAYOUT_GENERAL. %s",
Petr Krausbc7f5442017-05-14 23:43:38 +0200616 caller, HandleToUint64(image), string_VkImageLayout(explicit_layout),
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600617 string_VkImageLayout(optimal_layout), validation_error_map[msg_code]);
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700618 }
619 }
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600620 return skip;
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700621}
622
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700623void TransitionFinalSubpassLayouts(layer_data *device_data, GLOBAL_CB_NODE *pCB, const VkRenderPassBeginInfo *pRenderPassBegin,
624 FRAMEBUFFER_STATE *framebuffer_state) {
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -0700625 auto renderPass = GetRenderPassState(device_data, pRenderPassBegin->renderPass);
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700626 if (!renderPass) return;
627
628 const VkRenderPassCreateInfo *pRenderPassInfo = renderPass->createInfo.ptr();
629 if (framebuffer_state) {
630 for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) {
631 auto image_view = framebuffer_state->createInfo.pAttachments[i];
632 SetImageViewLayout(device_data, pCB, image_view, pRenderPassInfo->pAttachments[i].finalLayout);
633 }
634 }
635}
636
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700637bool PreCallValidateCreateImage(layer_data *device_data, const VkImageCreateInfo *pCreateInfo,
Mark Lobodzinski90224de2017-01-26 15:23:11 -0700638 const VkAllocationCallbacks *pAllocator, VkImage *pImage) {
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600639 bool skip = false;
Mark Lobodzinski90224de2017-01-26 15:23:11 -0700640 const debug_report_data *report_data = core_validation::GetReportData(device_data);
641
Jeremy Hayes96dcd812017-03-14 14:04:19 -0600642 if (pCreateInfo->format == VK_FORMAT_UNDEFINED) {
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600643 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
644 VALIDATION_ERROR_00715, "IMAGE", "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED. %s",
645 validation_error_map[VALIDATION_ERROR_00715]);
Jeremy Hayes96dcd812017-03-14 14:04:19 -0600646
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600647 return skip;
Jeremy Hayes96dcd812017-03-14 14:04:19 -0600648 }
649
650 const VkFormatProperties *properties = GetFormatProperties(device_data, pCreateInfo->format);
651
652 if ((pCreateInfo->tiling == VK_IMAGE_TILING_LINEAR) && (properties->linearTilingFeatures == 0)) {
653 std::stringstream ss;
654 ss << "vkCreateImage format parameter (" << string_VkFormat(pCreateInfo->format) << ") is an unsupported format";
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600655 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
656 VALIDATION_ERROR_02150, "IMAGE", "%s. %s", ss.str().c_str(), validation_error_map[VALIDATION_ERROR_02150]);
Jeremy Hayes96dcd812017-03-14 14:04:19 -0600657
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600658 return skip;
Jeremy Hayes96dcd812017-03-14 14:04:19 -0600659 }
660
661 if ((pCreateInfo->tiling == VK_IMAGE_TILING_OPTIMAL) && (properties->optimalTilingFeatures == 0)) {
662 std::stringstream ss;
663 ss << "vkCreateImage format parameter (" << string_VkFormat(pCreateInfo->format) << ") is an unsupported format";
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600664 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
665 VALIDATION_ERROR_02155, "IMAGE", "%s. %s", ss.str().c_str(), validation_error_map[VALIDATION_ERROR_02155]);
Jeremy Hayes96dcd812017-03-14 14:04:19 -0600666
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600667 return skip;
Jeremy Hayes96dcd812017-03-14 14:04:19 -0600668 }
669
670 // Validate that format supports usage as color attachment
671 if (pCreateInfo->usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) {
672 if ((pCreateInfo->tiling == VK_IMAGE_TILING_OPTIMAL) &&
673 ((properties->optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) == 0)) {
674 std::stringstream ss;
675 ss << "vkCreateImage: VkFormat for TILING_OPTIMAL image (" << string_VkFormat(pCreateInfo->format)
676 << ") does not support requested Image usage type VK_IMAGE_USAGE_COLOR_ATTACHMENT";
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600677 skip |=
Jeremy Hayes96dcd812017-03-14 14:04:19 -0600678 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
679 VALIDATION_ERROR_02158, "IMAGE", "%s. %s", ss.str().c_str(), validation_error_map[VALIDATION_ERROR_02158]);
680 }
681 if ((pCreateInfo->tiling == VK_IMAGE_TILING_LINEAR) &&
682 ((properties->linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) == 0)) {
683 std::stringstream ss;
684 ss << "vkCreateImage: VkFormat for TILING_LINEAR image (" << string_VkFormat(pCreateInfo->format)
685 << ") does not support requested Image usage type VK_IMAGE_USAGE_COLOR_ATTACHMENT";
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600686 skip |=
Jeremy Hayes96dcd812017-03-14 14:04:19 -0600687 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
688 VALIDATION_ERROR_02153, "IMAGE", "%s. %s", ss.str().c_str(), validation_error_map[VALIDATION_ERROR_02153]);
689 }
690 }
691
692 // Validate that format supports usage as depth/stencil attachment
693 if (pCreateInfo->usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) {
694 if ((pCreateInfo->tiling == VK_IMAGE_TILING_OPTIMAL) &&
695 ((properties->optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) == 0)) {
696 std::stringstream ss;
697 ss << "vkCreateImage: VkFormat for TILING_OPTIMAL image (" << string_VkFormat(pCreateInfo->format)
698 << ") does not support requested Image usage type VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT";
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600699 skip |=
Jeremy Hayes96dcd812017-03-14 14:04:19 -0600700 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
701 VALIDATION_ERROR_02159, "IMAGE", "%s. %s", ss.str().c_str(), validation_error_map[VALIDATION_ERROR_02159]);
702 }
703 if ((pCreateInfo->tiling == VK_IMAGE_TILING_LINEAR) &&
704 ((properties->linearTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) == 0)) {
705 std::stringstream ss;
706 ss << "vkCreateImage: VkFormat for TILING_LINEAR image (" << string_VkFormat(pCreateInfo->format)
707 << ") does not support requested Image usage type VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT";
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600708 skip |=
Jeremy Hayes96dcd812017-03-14 14:04:19 -0600709 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
710 VALIDATION_ERROR_02154, "IMAGE", "%s. %s", ss.str().c_str(), validation_error_map[VALIDATION_ERROR_02154]);
711 }
Mark Lobodzinski90224de2017-01-26 15:23:11 -0700712 }
713
Mark Lobodzinskiefd933b2017-02-10 12:09:23 -0700714 const VkImageFormatProperties *ImageFormatProperties = GetImageFormatProperties(
715 device_data, pCreateInfo->format, pCreateInfo->imageType, pCreateInfo->tiling, pCreateInfo->usage, pCreateInfo->flags);
Mark Lobodzinski90224de2017-01-26 15:23:11 -0700716
Mark Lobodzinskiefd933b2017-02-10 12:09:23 -0700717 VkDeviceSize imageGranularity = GetPhysicalDeviceProperties(device_data)->limits.bufferImageGranularity;
Mark Lobodzinski90224de2017-01-26 15:23:11 -0700718 imageGranularity = imageGranularity == 1 ? 0 : imageGranularity;
Tobin Ehlisa55b1d42017-04-04 12:23:48 -0600719 // TODO : This is also covering 2918 & 2919. Break out into separate checks
Mark Lobodzinski688ed322017-01-27 11:13:21 -0700720 if ((pCreateInfo->extent.width <= 0) || (pCreateInfo->extent.height <= 0) || (pCreateInfo->extent.depth <= 0)) {
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600721 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__,
722 VALIDATION_ERROR_02917, "Image",
723 "CreateImage extent is 0 for at least one required dimension for image: "
724 "Width = %d Height = %d Depth = %d. %s",
725 pCreateInfo->extent.width, pCreateInfo->extent.height, pCreateInfo->extent.depth,
726 validation_error_map[VALIDATION_ERROR_02917]);
Mark Lobodzinski90224de2017-01-26 15:23:11 -0700727 }
728
729 // TODO: VALIDATION_ERROR_02125 VALIDATION_ERROR_02126 VALIDATION_ERROR_02128 VALIDATION_ERROR_00720
730 // All these extent-related VUs should be checked here
Mark Lobodzinskiefd933b2017-02-10 12:09:23 -0700731 if ((pCreateInfo->extent.depth > ImageFormatProperties->maxExtent.depth) ||
732 (pCreateInfo->extent.width > ImageFormatProperties->maxExtent.width) ||
733 (pCreateInfo->extent.height > ImageFormatProperties->maxExtent.height)) {
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600734 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__,
735 IMAGE_INVALID_FORMAT_LIMITS_VIOLATION, "Image",
736 "CreateImage extents exceed allowable limits for format: "
737 "Width = %d Height = %d Depth = %d: Limits for Width = %d Height = %d Depth = %d for format %s.",
738 pCreateInfo->extent.width, pCreateInfo->extent.height, pCreateInfo->extent.depth,
739 ImageFormatProperties->maxExtent.width, ImageFormatProperties->maxExtent.height,
740 ImageFormatProperties->maxExtent.depth, string_VkFormat(pCreateInfo->format));
Mark Lobodzinski90224de2017-01-26 15:23:11 -0700741 }
742
Dave Houlton1150cf52017-04-27 14:38:11 -0600743 uint64_t totalSize =
744 ((uint64_t)pCreateInfo->extent.width * (uint64_t)pCreateInfo->extent.height * (uint64_t)pCreateInfo->extent.depth *
745 (uint64_t)pCreateInfo->arrayLayers * (uint64_t)pCreateInfo->samples * (uint64_t)FormatSize(pCreateInfo->format) +
746 (uint64_t)imageGranularity) &
747 ~(uint64_t)imageGranularity;
Mark Lobodzinski90224de2017-01-26 15:23:11 -0700748
Mark Lobodzinskiefd933b2017-02-10 12:09:23 -0700749 if (totalSize > ImageFormatProperties->maxResourceSize) {
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600750 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__,
751 IMAGE_INVALID_FORMAT_LIMITS_VIOLATION, "Image",
752 "CreateImage resource size exceeds allowable maximum "
753 "Image resource size = 0x%" PRIxLEAST64 ", maximum resource size = 0x%" PRIxLEAST64 " ",
754 totalSize, ImageFormatProperties->maxResourceSize);
Mark Lobodzinski90224de2017-01-26 15:23:11 -0700755 }
756
757 // TODO: VALIDATION_ERROR_02132
Mark Lobodzinskiefd933b2017-02-10 12:09:23 -0700758 if (pCreateInfo->mipLevels > ImageFormatProperties->maxMipLevels) {
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600759 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__,
760 IMAGE_INVALID_FORMAT_LIMITS_VIOLATION, "Image",
761 "CreateImage mipLevels=%d exceeds allowable maximum supported by format of %d", pCreateInfo->mipLevels,
762 ImageFormatProperties->maxMipLevels);
Mark Lobodzinski90224de2017-01-26 15:23:11 -0700763 }
764
Mark Lobodzinskiefd933b2017-02-10 12:09:23 -0700765 if (pCreateInfo->arrayLayers > ImageFormatProperties->maxArrayLayers) {
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600766 skip |= log_msg(
Mark Lobodzinski90224de2017-01-26 15:23:11 -0700767 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__, VALIDATION_ERROR_02133,
768 "Image", "CreateImage arrayLayers=%d exceeds allowable maximum supported by format of %d. %s", pCreateInfo->arrayLayers,
Mark Lobodzinskiefd933b2017-02-10 12:09:23 -0700769 ImageFormatProperties->maxArrayLayers, validation_error_map[VALIDATION_ERROR_02133]);
Mark Lobodzinski90224de2017-01-26 15:23:11 -0700770 }
771
Mark Lobodzinskiefd933b2017-02-10 12:09:23 -0700772 if ((pCreateInfo->samples & ImageFormatProperties->sampleCounts) == 0) {
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600773 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__,
774 VALIDATION_ERROR_02138, "Image", "CreateImage samples %s is not supported by format 0x%.8X. %s",
775 string_VkSampleCountFlagBits(pCreateInfo->samples), ImageFormatProperties->sampleCounts,
776 validation_error_map[VALIDATION_ERROR_02138]);
Mark Lobodzinski90224de2017-01-26 15:23:11 -0700777 }
778
779 if (pCreateInfo->initialLayout != VK_IMAGE_LAYOUT_UNDEFINED && pCreateInfo->initialLayout != VK_IMAGE_LAYOUT_PREINITIALIZED) {
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600780 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__,
781 VALIDATION_ERROR_00731, "Image",
782 "vkCreateImage parameter, pCreateInfo->initialLayout, must be VK_IMAGE_LAYOUT_UNDEFINED or "
783 "VK_IMAGE_LAYOUT_PREINITIALIZED. %s",
784 validation_error_map[VALIDATION_ERROR_00731]);
Mark Lobodzinski90224de2017-01-26 15:23:11 -0700785 }
786
Mark Lobodzinski847b60c2017-03-13 09:32:45 -0600787 if ((pCreateInfo->flags & VK_IMAGE_CREATE_SPARSE_BINDING_BIT) && (!GetEnabledFeatures(device_data)->sparseBinding)) {
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600788 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
789 VALIDATION_ERROR_02143, "DS",
790 "vkCreateImage(): the sparseBinding device feature is disabled: Images cannot be created with the "
791 "VK_IMAGE_CREATE_SPARSE_BINDING_BIT set. %s",
792 validation_error_map[VALIDATION_ERROR_02143]);
Mark Lobodzinski847b60c2017-03-13 09:32:45 -0600793 }
794
Mark Lobodzinski035a4cf2017-03-13 09:45:07 -0600795 if ((pCreateInfo->flags & VK_IMAGE_CREATE_SPARSE_ALIASED_BIT) && (!GetEnabledFeatures(device_data)->sparseResidencyAliased)) {
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600796 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
797 DRAWSTATE_INVALID_FEATURE, "DS",
798 "vkCreateImage(): the sparseResidencyAliased device feature is disabled: Images cannot be created with the "
799 "VK_IMAGE_CREATE_SPARSE_ALIASED_BIT set.");
Mark Lobodzinski035a4cf2017-03-13 09:45:07 -0600800 }
801
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600802 return skip;
Mark Lobodzinski90224de2017-01-26 15:23:11 -0700803}
804
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700805void PostCallRecordCreateImage(layer_data *device_data, const VkImageCreateInfo *pCreateInfo, VkImage *pImage) {
Mark Lobodzinski42fe5f72017-01-11 11:36:16 -0700806 IMAGE_LAYOUT_NODE image_state;
807 image_state.layout = pCreateInfo->initialLayout;
808 image_state.format = pCreateInfo->format;
Mark Lobodzinski214144a2017-01-27 14:25:32 -0700809 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 -0700810 ImageSubresourcePair subpair{*pImage, false, VkImageSubresource()};
Mark Lobodzinski214144a2017-01-27 14:25:32 -0700811 (*core_validation::GetImageSubresourceMap(device_data))[*pImage].push_back(subpair);
812 (*core_validation::GetImageLayoutMap(device_data))[subpair] = image_state;
Mark Lobodzinski42fe5f72017-01-11 11:36:16 -0700813}
Mark Lobodzinski9ef5d562017-01-27 12:28:30 -0700814
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700815bool PreCallValidateDestroyImage(layer_data *device_data, VkImage image, IMAGE_STATE **image_state, VK_OBJECT *obj_struct) {
Mark Lobodzinski9ef5d562017-01-27 12:28:30 -0700816 const CHECK_DISABLED *disabled = core_validation::GetDisables(device_data);
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -0700817 *image_state = core_validation::GetImageState(device_data, image);
Petr Krausbc7f5442017-05-14 23:43:38 +0200818 *obj_struct = {HandleToUint64(image), kVulkanObjectTypeImage};
Mark Lobodzinski9ef5d562017-01-27 12:28:30 -0700819 if (disabled->destroy_image) return false;
820 bool skip = false;
821 if (*image_state) {
822 skip |= core_validation::ValidateObjectNotInUse(device_data, *image_state, *obj_struct, VALIDATION_ERROR_00743);
823 }
824 return skip;
825}
826
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700827void PostCallRecordDestroyImage(layer_data *device_data, VkImage image, IMAGE_STATE *image_state, VK_OBJECT obj_struct) {
Mark Lobodzinski9ef5d562017-01-27 12:28:30 -0700828 core_validation::invalidateCommandBuffers(device_data, image_state->cb_bindings, obj_struct);
829 // Clean up memory mapping, bindings and range references for image
830 for (auto mem_binding : image_state->GetBoundMemory()) {
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -0700831 auto mem_info = core_validation::GetMemObjInfo(device_data, mem_binding);
Mark Lobodzinski9ef5d562017-01-27 12:28:30 -0700832 if (mem_info) {
833 core_validation::RemoveImageMemoryRange(obj_struct.handle, mem_info);
834 }
835 }
Mark Lobodzinski33826372017-04-13 11:10:11 -0600836 core_validation::ClearMemoryObjectBindings(device_data, obj_struct.handle, kVulkanObjectTypeImage);
Mark Lobodzinski9ef5d562017-01-27 12:28:30 -0700837 // Remove image from imageMap
838 core_validation::GetImageMap(device_data)->erase(image);
839 std::unordered_map<VkImage, std::vector<ImageSubresourcePair>> *imageSubresourceMap =
840 core_validation::GetImageSubresourceMap(device_data);
841
842 const auto &sub_entry = imageSubresourceMap->find(image);
843 if (sub_entry != imageSubresourceMap->end()) {
844 for (const auto &pair : sub_entry->second) {
845 core_validation::GetImageLayoutMap(device_data)->erase(pair);
846 }
847 imageSubresourceMap->erase(sub_entry);
848 }
849}
Mark Lobodzinskic409a582017-01-27 15:16:01 -0700850
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700851bool ValidateImageAttributes(layer_data *device_data, IMAGE_STATE *image_state, VkImageSubresourceRange range) {
Mark Lobodzinskic409a582017-01-27 15:16:01 -0700852 bool skip = false;
853 const debug_report_data *report_data = core_validation::GetReportData(device_data);
854
855 if (range.aspectMask != VK_IMAGE_ASPECT_COLOR_BIT) {
856 char const str[] = "vkCmdClearColorImage aspectMasks for all subresource ranges must be set to VK_IMAGE_ASPECT_COLOR_BIT";
857 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +0200858 HandleToUint64(image_state->image), __LINE__, DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", str);
Mark Lobodzinskic409a582017-01-27 15:16:01 -0700859 }
860
Dave Houlton1d2022c2017-03-29 11:43:58 -0600861 if (FormatIsDepthOrStencil(image_state->createInfo.format)) {
Mark Lobodzinskic409a582017-01-27 15:16:01 -0700862 char const str[] = "vkCmdClearColorImage called with depth/stencil image.";
863 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +0200864 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_01088, "IMAGE", "%s. %s", str,
Mark Lobodzinskic409a582017-01-27 15:16:01 -0700865 validation_error_map[VALIDATION_ERROR_01088]);
Dave Houlton1d2022c2017-03-29 11:43:58 -0600866 } else if (FormatIsCompressed(image_state->createInfo.format)) {
Mark Lobodzinskic409a582017-01-27 15:16:01 -0700867 char const str[] = "vkCmdClearColorImage called with compressed image.";
868 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +0200869 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_01088, "IMAGE", "%s. %s", str,
Mark Lobodzinskic409a582017-01-27 15:16:01 -0700870 validation_error_map[VALIDATION_ERROR_01088]);
871 }
872
873 if (!(image_state->createInfo.usage & VK_IMAGE_USAGE_TRANSFER_DST_BIT)) {
874 char const str[] = "vkCmdClearColorImage called with image created without VK_IMAGE_USAGE_TRANSFER_DST_BIT.";
875 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +0200876 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_01084, "IMAGE", "%s. %s", str,
Mark Lobodzinskic409a582017-01-27 15:16:01 -0700877 validation_error_map[VALIDATION_ERROR_01084]);
878 }
879 return skip;
880}
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700881
Mark Lobodzinski903e5ff2017-03-23 09:43:35 -0600882uint32_t ResolveRemainingLevels(const VkImageSubresourceRange *range, uint32_t mip_levels) {
883 // Return correct number of mip levels taking into account VK_REMAINING_MIP_LEVELS
884 uint32_t mip_level_count = range->levelCount;
Mark Lobodzinski9c93dbd2017-02-02 08:31:18 -0700885 if (range->levelCount == VK_REMAINING_MIP_LEVELS) {
Mark Lobodzinski903e5ff2017-03-23 09:43:35 -0600886 mip_level_count = mip_levels - range->baseMipLevel;
Mark Lobodzinski9c93dbd2017-02-02 08:31:18 -0700887 }
Mark Lobodzinski903e5ff2017-03-23 09:43:35 -0600888 return mip_level_count;
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700889}
890
Mark Lobodzinski903e5ff2017-03-23 09:43:35 -0600891uint32_t ResolveRemainingLayers(const VkImageSubresourceRange *range, uint32_t layers) {
892 // Return correct number of layers taking into account VK_REMAINING_ARRAY_LAYERS
893 uint32_t array_layer_count = range->layerCount;
894 if (range->layerCount == VK_REMAINING_ARRAY_LAYERS) {
895 array_layer_count = layers - range->baseArrayLayer;
Mark Lobodzinski9c93dbd2017-02-02 08:31:18 -0700896 }
Mark Lobodzinski903e5ff2017-03-23 09:43:35 -0600897 return array_layer_count;
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700898}
899
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700900bool VerifyClearImageLayout(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *image_state,
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700901 VkImageSubresourceRange range, VkImageLayout dest_image_layout, const char *func_name) {
902 bool skip = false;
903 const debug_report_data *report_data = core_validation::GetReportData(device_data);
904
Mark Lobodzinski903e5ff2017-03-23 09:43:35 -0600905 uint32_t level_count = ResolveRemainingLevels(&range, image_state->createInfo.mipLevels);
906 uint32_t layer_count = ResolveRemainingLayers(&range, image_state->createInfo.arrayLayers);
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700907
908 if (dest_image_layout != VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) {
909 if (dest_image_layout == VK_IMAGE_LAYOUT_GENERAL) {
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700910 if (image_state->createInfo.tiling != VK_IMAGE_TILING_LINEAR) {
911 // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning.
Mark Lobodzinski0827aec2017-03-21 16:41:45 -0600912 skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +0200913 HandleToUint64(image_state->image), __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700914 "%s: Layout for cleared image should be TRANSFER_DST_OPTIMAL instead of GENERAL.", func_name);
915 }
Mark Lobodzinski087380c2017-05-16 14:42:25 -0600916 } else if (VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR == dest_image_layout) {
917 if (!GetDeviceExtensions(device_data)->khr_shared_presentable_image) {
Tobin Ehlisfb0661c2017-05-11 08:52:51 -0600918 // TODO: Add unique error id when available.
Mark Lobodzinski087380c2017-05-16 14:42:25 -0600919 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Tobin Ehlisfb0661c2017-05-11 08:52:51 -0600920 HandleToUint64(image_state->image), __LINE__, 0, "DS",
Mark Lobodzinski087380c2017-05-16 14:42:25 -0600921 "Must enable VK_KHR_shared_presentable_image extension before creating images with a layout type "
922 "of VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR.");
923
924 } else {
925 if (image_state->shared_presentable) {
926 skip |= log_msg(
927 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Tobin Ehlisfb0661c2017-05-11 08:52:51 -0600928 HandleToUint64(image_state->image), __LINE__, 0, "DS",
Mark Lobodzinski087380c2017-05-16 14:42:25 -0600929 "Layout for shared presentable cleared image is %s but can only be VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR.",
930 string_VkImageLayout(dest_image_layout));
931 }
Tobin Ehlisbb03e5f2017-05-11 08:52:51 -0600932 }
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700933 } else {
934 UNIQUE_VALIDATION_ERROR_CODE error_code = VALIDATION_ERROR_01086;
935 if (strcmp(func_name, "vkCmdClearDepthStencilImage()") == 0) {
936 error_code = VALIDATION_ERROR_01101;
937 } else {
938 assert(strcmp(func_name, "vkCmdClearColorImage()") == 0);
939 }
Mark Lobodzinski0827aec2017-03-21 16:41:45 -0600940 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +0200941 HandleToUint64(image_state->image), __LINE__, error_code, "DS",
Mark Lobodzinski0827aec2017-03-21 16:41:45 -0600942 "%s: Layout for cleared image is %s but can only be "
943 "TRANSFER_DST_OPTIMAL or GENERAL. %s",
944 func_name, string_VkImageLayout(dest_image_layout), validation_error_map[error_code]);
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700945 }
946 }
947
Mark Lobodzinski903e5ff2017-03-23 09:43:35 -0600948 for (uint32_t level_index = 0; level_index < level_count; ++level_index) {
949 uint32_t level = level_index + range.baseMipLevel;
950 for (uint32_t layer_index = 0; layer_index < layer_count; ++layer_index) {
951 uint32_t layer = layer_index + range.baseArrayLayer;
952 VkImageSubresource sub = {range.aspectMask, level, layer};
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700953 IMAGE_CMD_BUF_LAYOUT_NODE node;
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700954 if (FindCmdBufLayout(device_data, cb_node, image_state->image, sub, node)) {
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700955 if (node.layout != dest_image_layout) {
956 UNIQUE_VALIDATION_ERROR_CODE error_code = VALIDATION_ERROR_01085;
957 if (strcmp(func_name, "vkCmdClearDepthStencilImage()") == 0) {
958 error_code = VALIDATION_ERROR_01100;
959 } else {
960 assert(strcmp(func_name, "vkCmdClearColorImage()") == 0);
961 }
962 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0,
963 __LINE__, error_code, "DS",
964 "%s: Cannot clear an image whose layout is %s and "
965 "doesn't match the current layout %s. %s",
966 func_name, string_VkImageLayout(dest_image_layout), string_VkImageLayout(node.layout),
967 validation_error_map[error_code]);
968 }
969 }
970 }
971 }
972
973 return skip;
974}
975
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700976void RecordClearImageLayout(layer_data *device_data, GLOBAL_CB_NODE *cb_node, VkImage image, VkImageSubresourceRange range,
977 VkImageLayout dest_image_layout) {
Mark Lobodzinski903e5ff2017-03-23 09:43:35 -0600978 VkImageCreateInfo *image_create_info = &(GetImageState(device_data, image)->createInfo);
979 uint32_t level_count = ResolveRemainingLevels(&range, image_create_info->mipLevels);
980 uint32_t layer_count = ResolveRemainingLayers(&range, image_create_info->arrayLayers);
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700981
Mark Lobodzinski903e5ff2017-03-23 09:43:35 -0600982 for (uint32_t level_index = 0; level_index < level_count; ++level_index) {
983 uint32_t level = level_index + range.baseMipLevel;
984 for (uint32_t layer_index = 0; layer_index < layer_count; ++layer_index) {
985 uint32_t layer = layer_index + range.baseArrayLayer;
986 VkImageSubresource sub = {range.aspectMask, level, layer};
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700987 IMAGE_CMD_BUF_LAYOUT_NODE node;
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700988 if (!FindCmdBufLayout(device_data, cb_node, image, sub, node)) {
989 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 -0700990 }
991 }
992 }
993}
994
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700995bool PreCallValidateCmdClearColorImage(layer_data *dev_data, VkCommandBuffer commandBuffer, VkImage image,
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700996 VkImageLayout imageLayout, uint32_t rangeCount, const VkImageSubresourceRange *pRanges) {
997 bool skip = false;
998 // TODO : Verify memory is in VK_IMAGE_STATE_CLEAR state
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -0700999 auto cb_node = GetCBNode(dev_data, commandBuffer);
1000 auto image_state = GetImageState(dev_data, image);
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001001 if (cb_node && image_state) {
1002 skip |= ValidateMemoryIsBoundToImage(dev_data, image_state, "vkCmdClearColorImage()", VALIDATION_ERROR_02527);
Mike Schuchardt9c582402017-02-23 15:57:37 -07001003 skip |= ValidateCmdQueueFlags(dev_data, cb_node, "vkCmdClearColorImage()", VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT,
1004 VALIDATION_ERROR_01095);
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001005 skip |= ValidateCmd(dev_data, cb_node, CMD_CLEARCOLORIMAGE, "vkCmdClearColorImage()");
1006 skip |= insideRenderPass(dev_data, cb_node, "vkCmdClearColorImage()", VALIDATION_ERROR_01096);
1007 for (uint32_t i = 0; i < rangeCount; ++i) {
Petr Kraus4d718682017-05-18 03:38:41 +02001008 std::string param_name = "pRanges[" + std::to_string(i) + "]";
1009 skip |= ValidateImageSubresourceRange(dev_data, image_state, nullptr, pRanges[i], "vkCmdClearColorImage",
1010 param_name.c_str());
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001011 skip |= ValidateImageAttributes(dev_data, image_state, pRanges[i]);
Mark Lobodzinski9c93dbd2017-02-02 08:31:18 -07001012 skip |= VerifyClearImageLayout(dev_data, cb_node, image_state, pRanges[i], imageLayout, "vkCmdClearColorImage()");
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001013 }
1014 }
1015 return skip;
1016}
1017
1018// This state recording routine is shared between ClearColorImage and ClearDepthStencilImage
Tobin Ehlis58c884f2017-02-08 12:15:27 -07001019void PreCallRecordCmdClearImage(layer_data *dev_data, VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout,
1020 uint32_t rangeCount, const VkImageSubresourceRange *pRanges, CMD_TYPE cmd_type) {
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07001021 auto cb_node = GetCBNode(dev_data, commandBuffer);
1022 auto image_state = GetImageState(dev_data, image);
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001023 if (cb_node && image_state) {
1024 AddCommandBufferBindingImage(dev_data, cb_node, image_state);
1025 std::function<bool()> function = [=]() {
1026 SetImageMemoryValid(dev_data, image_state, true);
1027 return false;
1028 };
1029 cb_node->validate_functions.push_back(function);
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07001030 core_validation::UpdateCmdBufferLastCmd(cb_node, cmd_type);
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001031 for (uint32_t i = 0; i < rangeCount; ++i) {
1032 RecordClearImageLayout(dev_data, cb_node, image, pRanges[i], imageLayout);
1033 }
1034 }
1035}
1036
Tobin Ehlis58c884f2017-02-08 12:15:27 -07001037bool PreCallValidateCmdClearDepthStencilImage(layer_data *device_data, VkCommandBuffer commandBuffer, VkImage image,
1038 VkImageLayout imageLayout, uint32_t rangeCount,
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001039 const VkImageSubresourceRange *pRanges) {
1040 bool skip = false;
Mark Lobodzinski1241a312017-02-01 10:57:21 -07001041 const debug_report_data *report_data = core_validation::GetReportData(device_data);
1042
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001043 // TODO : Verify memory is in VK_IMAGE_STATE_CLEAR state
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07001044 auto cb_node = GetCBNode(device_data, commandBuffer);
1045 auto image_state = GetImageState(device_data, image);
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001046 if (cb_node && image_state) {
Mark Lobodzinski1241a312017-02-01 10:57:21 -07001047 skip |= ValidateMemoryIsBoundToImage(device_data, image_state, "vkCmdClearDepthStencilImage()", VALIDATION_ERROR_02528);
Mike Schuchardt9c582402017-02-23 15:57:37 -07001048 skip |= ValidateCmdQueueFlags(device_data, cb_node, "vkCmdClearDepthStencilImage()", VK_QUEUE_GRAPHICS_BIT,
1049 VALIDATION_ERROR_01110);
Mark Lobodzinski1241a312017-02-01 10:57:21 -07001050 skip |= ValidateCmd(device_data, cb_node, CMD_CLEARDEPTHSTENCILIMAGE, "vkCmdClearDepthStencilImage()");
1051 skip |= insideRenderPass(device_data, cb_node, "vkCmdClearDepthStencilImage()", VALIDATION_ERROR_01111);
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001052 for (uint32_t i = 0; i < rangeCount; ++i) {
Petr Kraus4d718682017-05-18 03:38:41 +02001053 std::string param_name = "pRanges[" + std::to_string(i) + "]";
1054 skip |= ValidateImageSubresourceRange(device_data, image_state, nullptr, pRanges[i], "vkCmdClearDepthStencilImage",
1055 param_name.c_str());
Mark Lobodzinski9c93dbd2017-02-02 08:31:18 -07001056 skip |=
1057 VerifyClearImageLayout(device_data, cb_node, image_state, pRanges[i], imageLayout, "vkCmdClearDepthStencilImage()");
Mark Lobodzinski1241a312017-02-01 10:57:21 -07001058 // Image aspect must be depth or stencil or both
1059 if (((pRanges[i].aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) != VK_IMAGE_ASPECT_DEPTH_BIT) &&
1060 ((pRanges[i].aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) != VK_IMAGE_ASPECT_STENCIL_BIT)) {
1061 char const str[] =
1062 "vkCmdClearDepthStencilImage aspectMasks for all subresource ranges must be "
1063 "set to VK_IMAGE_ASPECT_DEPTH_BIT and/or VK_IMAGE_ASPECT_STENCIL_BIT";
1064 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02001065 HandleToUint64(commandBuffer), __LINE__, DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", str);
Mark Lobodzinski1241a312017-02-01 10:57:21 -07001066 }
1067 }
Dave Houlton1d2022c2017-03-29 11:43:58 -06001068 if (image_state && !FormatIsDepthOrStencil(image_state->createInfo.format)) {
Mark Lobodzinski1241a312017-02-01 10:57:21 -07001069 char const str[] = "vkCmdClearDepthStencilImage called without a depth/stencil image.";
Petr Krausbc7f5442017-05-14 23:43:38 +02001070 skip |=
1071 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, HandleToUint64(image),
1072 __LINE__, VALIDATION_ERROR_01103, "IMAGE", "%s. %s", str, validation_error_map[VALIDATION_ERROR_01103]);
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001073 }
1074 }
1075 return skip;
1076}
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001077
1078// Returns true if [x, xoffset] and [y, yoffset] overlap
1079static bool RangesIntersect(int32_t start, uint32_t start_offset, int32_t end, uint32_t end_offset) {
1080 bool result = false;
1081 uint32_t intersection_min = std::max(static_cast<uint32_t>(start), static_cast<uint32_t>(end));
1082 uint32_t intersection_max = std::min(static_cast<uint32_t>(start) + start_offset, static_cast<uint32_t>(end) + end_offset);
1083
1084 if (intersection_max > intersection_min) {
1085 result = true;
1086 }
1087 return result;
1088}
1089
1090// Returns true if two VkImageCopy structures overlap
1091static bool RegionIntersects(const VkImageCopy *src, const VkImageCopy *dst, VkImageType type) {
1092 bool result = false;
1093 if ((src->srcSubresource.mipLevel == dst->dstSubresource.mipLevel) &&
1094 (RangesIntersect(src->srcSubresource.baseArrayLayer, src->srcSubresource.layerCount, dst->dstSubresource.baseArrayLayer,
1095 dst->dstSubresource.layerCount))) {
1096 result = true;
1097 switch (type) {
1098 case VK_IMAGE_TYPE_3D:
1099 result &= RangesIntersect(src->srcOffset.z, src->extent.depth, dst->dstOffset.z, dst->extent.depth);
1100 // Intentionally fall through to 2D case
1101 case VK_IMAGE_TYPE_2D:
1102 result &= RangesIntersect(src->srcOffset.y, src->extent.height, dst->dstOffset.y, dst->extent.height);
1103 // Intentionally fall through to 1D case
1104 case VK_IMAGE_TYPE_1D:
1105 result &= RangesIntersect(src->srcOffset.x, src->extent.width, dst->dstOffset.x, dst->extent.width);
1106 break;
1107 default:
1108 // Unrecognized or new IMAGE_TYPE enums will be caught in parameter_validation
1109 assert(false);
1110 }
1111 }
1112 return result;
1113}
1114
Dave Houltonfc1a4052017-04-27 14:32:45 -06001115// Returns non-zero if offset and extent exceed image extents
1116static const uint32_t x_bit = 1;
1117static const uint32_t y_bit = 2;
1118static const uint32_t z_bit = 4;
Dave Houlton1150cf52017-04-27 14:38:11 -06001119static uint32_t ExceedsBounds(const VkOffset3D *offset, const VkExtent3D *extent, const VkExtent3D *image_extent) {
Dave Houltonfc1a4052017-04-27 14:32:45 -06001120 uint32_t result = 0;
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001121 // Extents/depths cannot be negative but checks left in for clarity
Dave Houlton9dae7ec2017-03-01 16:23:25 -07001122 if ((offset->z + extent->depth > image_extent->depth) || (offset->z < 0) ||
1123 ((offset->z + static_cast<int32_t>(extent->depth)) < 0)) {
Dave Houltonfc1a4052017-04-27 14:32:45 -06001124 result |= z_bit;
Dave Houlton9dae7ec2017-03-01 16:23:25 -07001125 }
1126 if ((offset->y + extent->height > image_extent->height) || (offset->y < 0) ||
1127 ((offset->y + static_cast<int32_t>(extent->height)) < 0)) {
Dave Houltonfc1a4052017-04-27 14:32:45 -06001128 result |= y_bit;
Dave Houlton9dae7ec2017-03-01 16:23:25 -07001129 }
1130 if ((offset->x + extent->width > image_extent->width) || (offset->x < 0) ||
1131 ((offset->x + static_cast<int32_t>(extent->width)) < 0)) {
Dave Houltonfc1a4052017-04-27 14:32:45 -06001132 result |= x_bit;
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001133 }
1134 return result;
1135}
1136
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001137// Test if two VkExtent3D structs are equivalent
1138static inline bool IsExtentEqual(const VkExtent3D *extent, const VkExtent3D *other_extent) {
1139 bool result = true;
1140 if ((extent->width != other_extent->width) || (extent->height != other_extent->height) ||
1141 (extent->depth != other_extent->depth)) {
1142 result = false;
1143 }
1144 return result;
1145}
1146
Dave Houlton6f9059e2017-05-02 17:15:13 -06001147// Returns the effective extent of an image subresource, adjusted for mip level and array depth.
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001148static inline VkExtent3D GetImageSubresourceExtent(const IMAGE_STATE *img, const VkImageSubresourceLayers *subresource) {
1149 const uint32_t mip = subresource->mipLevel;
Dave Houltonfc1a4052017-04-27 14:32:45 -06001150
1151 // Return zero extent if mip level doesn't exist
Dave Houlton1150cf52017-04-27 14:38:11 -06001152 if (mip >= img->createInfo.mipLevels) {
1153 return VkExtent3D{0, 0, 0};
Dave Houltonfc1a4052017-04-27 14:32:45 -06001154 }
Dave Houlton1150cf52017-04-27 14:38:11 -06001155
Dave Houlton9dae7ec2017-03-01 16:23:25 -07001156 // 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 -06001157 VkExtent3D extent = img->createInfo.extent;
Dave Houlton9dae7ec2017-03-01 16:23:25 -07001158 extent.width = (0 == extent.width ? 0 : std::max(1U, extent.width >> mip));
1159 extent.height = (0 == extent.height ? 0 : std::max(1U, extent.height >> mip));
1160 extent.depth = (0 == extent.depth ? 0 : std::max(1U, extent.depth >> mip));
Dave Houltonfc1a4052017-04-27 14:32:45 -06001161
Dave Houlton6f9059e2017-05-02 17:15:13 -06001162 // Image arrays have an effective z extent that isn't diminished by mip level
1163 if (VK_IMAGE_TYPE_3D != img->createInfo.imageType) {
Dave Houltonfc1a4052017-04-27 14:32:45 -06001164 extent.depth = img->createInfo.arrayLayers;
1165 }
1166
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001167 return extent;
1168}
1169
1170// Test if the extent argument has all dimensions set to 0.
Dave Houlton9dae7ec2017-03-01 16:23:25 -07001171static inline bool IsExtentAllZeroes(const VkExtent3D *extent) {
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001172 return ((extent->width == 0) && (extent->height == 0) && (extent->depth == 0));
1173}
1174
Dave Houlton9dae7ec2017-03-01 16:23:25 -07001175// Test if the extent argument has any dimensions set to 0.
1176static inline bool IsExtentSizeZero(const VkExtent3D *extent) {
1177 return ((extent->width == 0) || (extent->height == 0) || (extent->depth == 0));
1178}
1179
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001180// Returns the image transfer granularity for a specific image scaled by compressed block size if necessary.
1181static inline VkExtent3D GetScaledItg(layer_data *device_data, const GLOBAL_CB_NODE *cb_node, const IMAGE_STATE *img) {
1182 // Default to (0, 0, 0) granularity in case we can't find the real granularity for the physical device.
1183 VkExtent3D granularity = {0, 0, 0};
1184 auto pPool = GetCommandPoolNode(device_data, cb_node->createInfo.commandPool);
1185 if (pPool) {
1186 granularity =
1187 GetPhysDevProperties(device_data)->queue_family_properties[pPool->queueFamilyIndex].minImageTransferGranularity;
Dave Houlton1d2022c2017-03-29 11:43:58 -06001188 if (FormatIsCompressed(img->createInfo.format)) {
1189 auto block_size = FormatCompressedTexelBlockExtent(img->createInfo.format);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001190 granularity.width *= block_size.width;
1191 granularity.height *= block_size.height;
1192 }
1193 }
1194 return granularity;
1195}
1196
1197// Test elements of a VkExtent3D structure against alignment constraints contained in another VkExtent3D structure
1198static inline bool IsExtentAligned(const VkExtent3D *extent, const VkExtent3D *granularity) {
1199 bool valid = true;
Dave Houlton1d2022c2017-03-29 11:43:58 -06001200 if ((SafeModulo(extent->depth, granularity->depth) != 0) || (SafeModulo(extent->width, granularity->width) != 0) ||
1201 (SafeModulo(extent->height, granularity->height) != 0)) {
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001202 valid = false;
1203 }
1204 return valid;
1205}
1206
1207// Check elements of a VkOffset3D structure against a queue family's Image Transfer Granularity values
1208static inline bool CheckItgOffset(layer_data *device_data, const GLOBAL_CB_NODE *cb_node, const VkOffset3D *offset,
1209 const VkExtent3D *granularity, const uint32_t i, const char *function, const char *member) {
1210 const debug_report_data *report_data = core_validation::GetReportData(device_data);
1211 bool skip = false;
1212 VkExtent3D offset_extent = {};
1213 offset_extent.width = static_cast<uint32_t>(abs(offset->x));
1214 offset_extent.height = static_cast<uint32_t>(abs(offset->y));
1215 offset_extent.depth = static_cast<uint32_t>(abs(offset->z));
Dave Houlton9dae7ec2017-03-01 16:23:25 -07001216 if (IsExtentAllZeroes(granularity)) {
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001217 // 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 -07001218 if (IsExtentAllZeroes(&offset_extent) == false) {
Petr Krausbc7f5442017-05-14 23:43:38 +02001219 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1220 HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_IMAGE_TRANSFER_GRANULARITY, "DS",
1221 "%s: pRegion[%d].%s (x=%d, y=%d, z=%d) must be (x=0, y=0, z=0) "
1222 "when the command buffer's queue family image transfer granularity is (w=0, h=0, d=0).",
1223 function, i, member, offset->x, offset->y, offset->z);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001224 }
1225 } else {
1226 // If the queue family image transfer granularity is not (0, 0, 0), then the offset dimensions must always be even
1227 // integer multiples of the image transfer granularity.
1228 if (IsExtentAligned(&offset_extent, granularity) == false) {
Petr Krausbc7f5442017-05-14 23:43:38 +02001229 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1230 HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_IMAGE_TRANSFER_GRANULARITY, "DS",
1231 "%s: pRegion[%d].%s (x=%d, y=%d, z=%d) dimensions must be even integer "
1232 "multiples of this command buffer's queue family image transfer granularity (w=%d, h=%d, d=%d).",
1233 function, i, member, offset->x, offset->y, offset->z, granularity->width, granularity->height,
1234 granularity->depth);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001235 }
1236 }
1237 return skip;
1238}
1239
1240// Check elements of a VkExtent3D structure against a queue family's Image Transfer Granularity values
1241static inline bool CheckItgExtent(layer_data *device_data, const GLOBAL_CB_NODE *cb_node, const VkExtent3D *extent,
1242 const VkOffset3D *offset, const VkExtent3D *granularity, const VkExtent3D *subresource_extent,
1243 const uint32_t i, const char *function, const char *member) {
1244 const debug_report_data *report_data = core_validation::GetReportData(device_data);
1245 bool skip = false;
Dave Houlton9dae7ec2017-03-01 16:23:25 -07001246 if (IsExtentAllZeroes(granularity)) {
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001247 // If the queue family image transfer granularity is (0, 0, 0), then the extent must always match the image
1248 // subresource extent.
1249 if (IsExtentEqual(extent, subresource_extent) == false) {
Petr Krausbc7f5442017-05-14 23:43:38 +02001250 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1251 HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_IMAGE_TRANSFER_GRANULARITY, "DS",
1252 "%s: pRegion[%d].%s (w=%d, h=%d, d=%d) must match the image subresource extents (w=%d, h=%d, d=%d) "
1253 "when the command buffer's queue family image transfer granularity is (w=0, h=0, d=0).",
1254 function, i, member, extent->width, extent->height, extent->depth, subresource_extent->width,
1255 subresource_extent->height, subresource_extent->depth);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001256 }
1257 } else {
1258 // If the queue family image transfer granularity is not (0, 0, 0), then the extent dimensions must always be even
1259 // integer multiples of the image transfer granularity or the offset + extent dimensions must always match the image
1260 // subresource extent dimensions.
1261 VkExtent3D offset_extent_sum = {};
1262 offset_extent_sum.width = static_cast<uint32_t>(abs(offset->x)) + extent->width;
1263 offset_extent_sum.height = static_cast<uint32_t>(abs(offset->y)) + extent->height;
1264 offset_extent_sum.depth = static_cast<uint32_t>(abs(offset->z)) + extent->depth;
Dave Houlton6f9059e2017-05-02 17:15:13 -06001265
1266 bool x_ok =
1267 ((0 == SafeModulo(extent->width, granularity->width)) || (subresource_extent->width == offset_extent_sum.width));
1268 bool y_ok =
1269 ((0 == SafeModulo(extent->height, granularity->height)) || (subresource_extent->height == offset_extent_sum.height));
1270 bool z_ok =
1271 ((0 == SafeModulo(extent->depth, granularity->depth)) || (subresource_extent->depth == offset_extent_sum.depth));
1272
1273 if (!(x_ok && y_ok && z_ok)) {
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001274 skip |=
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06001275 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02001276 HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_IMAGE_TRANSFER_GRANULARITY, "DS",
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001277 "%s: pRegion[%d].%s (w=%d, h=%d, d=%d) dimensions must be even integer multiples of this command buffer's "
1278 "queue family image transfer granularity (w=%d, h=%d, d=%d) or offset (x=%d, y=%d, z=%d) + "
1279 "extent (w=%d, h=%d, d=%d) must match the image subresource extents (w=%d, h=%d, d=%d).",
1280 function, i, member, extent->width, extent->height, extent->depth, granularity->width, granularity->height,
1281 granularity->depth, offset->x, offset->y, offset->z, extent->width, extent->height, extent->depth,
1282 subresource_extent->width, subresource_extent->height, subresource_extent->depth);
1283 }
1284 }
1285 return skip;
1286}
1287
1288// Check a uint32_t width or stride value against a queue family's Image Transfer Granularity width value
1289static inline bool CheckItgInt(layer_data *device_data, const GLOBAL_CB_NODE *cb_node, const uint32_t value,
1290 const uint32_t granularity, const uint32_t i, const char *function, const char *member) {
1291 const debug_report_data *report_data = core_validation::GetReportData(device_data);
1292
1293 bool skip = false;
Dave Houlton1d2022c2017-03-29 11:43:58 -06001294 if (SafeModulo(value, granularity) != 0) {
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06001295 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02001296 HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_IMAGE_TRANSFER_GRANULARITY, "DS",
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001297 "%s: pRegion[%d].%s (%d) must be an even integer multiple of this command buffer's queue family image "
1298 "transfer granularity width (%d).",
1299 function, i, member, value, granularity);
1300 }
1301 return skip;
1302}
1303
1304// Check a VkDeviceSize value against a queue family's Image Transfer Granularity width value
1305static inline bool CheckItgSize(layer_data *device_data, const GLOBAL_CB_NODE *cb_node, const VkDeviceSize value,
1306 const uint32_t granularity, const uint32_t i, const char *function, const char *member) {
1307 const debug_report_data *report_data = core_validation::GetReportData(device_data);
1308 bool skip = false;
Dave Houlton1d2022c2017-03-29 11:43:58 -06001309 if (SafeModulo(value, granularity) != 0) {
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06001310 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02001311 HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_IMAGE_TRANSFER_GRANULARITY, "DS",
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001312 "%s: pRegion[%d].%s (%" PRIdLEAST64
1313 ") must be an even integer multiple of this command buffer's queue family image transfer "
1314 "granularity width (%d).",
1315 function, i, member, value, granularity);
1316 }
1317 return skip;
1318}
1319
1320// Check valid usage Image Tranfer Granularity requirements for elements of a VkBufferImageCopy structure
1321bool ValidateCopyBufferImageTransferGranularityRequirements(layer_data *device_data, const GLOBAL_CB_NODE *cb_node,
1322 const IMAGE_STATE *img, const VkBufferImageCopy *region,
1323 const uint32_t i, const char *function) {
1324 bool skip = false;
Dave Houlton1d2022c2017-03-29 11:43:58 -06001325 if (FormatIsCompressed(img->createInfo.format) == true) {
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001326 // TODO: Add granularity checking for compressed formats
1327
1328 // bufferRowLength must be a multiple of the compressed texel block width
1329 // bufferImageHeight must be a multiple of the compressed texel block height
1330 // all members of imageOffset must be a multiple of the corresponding dimensions of the compressed texel block
1331 // bufferOffset must be a multiple of the compressed texel block size in bytes
1332 // imageExtent.width must be a multiple of the compressed texel block width or (imageExtent.width + imageOffset.x)
1333 // must equal the image subresource width
1334 // imageExtent.height must be a multiple of the compressed texel block height or (imageExtent.height + imageOffset.y)
1335 // must equal the image subresource height
1336 // imageExtent.depth must be a multiple of the compressed texel block depth or (imageExtent.depth + imageOffset.z)
1337 // must equal the image subresource depth
1338 } else {
1339 VkExtent3D granularity = GetScaledItg(device_data, cb_node, img);
1340 skip |= CheckItgSize(device_data, cb_node, region->bufferOffset, granularity.width, i, function, "bufferOffset");
1341 skip |= CheckItgInt(device_data, cb_node, region->bufferRowLength, granularity.width, i, function, "bufferRowLength");
1342 skip |= CheckItgInt(device_data, cb_node, region->bufferImageHeight, granularity.width, i, function, "bufferImageHeight");
1343 skip |= CheckItgOffset(device_data, cb_node, &region->imageOffset, &granularity, i, function, "imageOffset");
1344 VkExtent3D subresource_extent = GetImageSubresourceExtent(img, &region->imageSubresource);
1345 skip |= CheckItgExtent(device_data, cb_node, &region->imageExtent, &region->imageOffset, &granularity, &subresource_extent,
1346 i, function, "imageExtent");
1347 }
1348 return skip;
1349}
1350
1351// Check valid usage Image Tranfer Granularity requirements for elements of a VkImageCopy structure
1352bool ValidateCopyImageTransferGranularityRequirements(layer_data *device_data, const GLOBAL_CB_NODE *cb_node,
Dave Houlton6f9059e2017-05-02 17:15:13 -06001353 const IMAGE_STATE *src_img, const IMAGE_STATE *dst_img,
1354 const VkImageCopy *region, const uint32_t i, const char *function) {
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001355 bool skip = false;
Dave Houlton6f9059e2017-05-02 17:15:13 -06001356 VkExtent3D granularity = GetScaledItg(device_data, cb_node, src_img);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001357 skip |= CheckItgOffset(device_data, cb_node, &region->srcOffset, &granularity, i, function, "srcOffset");
Dave Houlton6f9059e2017-05-02 17:15:13 -06001358 VkExtent3D subresource_extent = GetImageSubresourceExtent(src_img, &region->srcSubresource);
1359 skip |= CheckItgExtent(device_data, cb_node, &region->extent, &region->srcOffset, &granularity, &subresource_extent, i,
1360 function, "extent");
1361
1362 granularity = GetScaledItg(device_data, cb_node, dst_img);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001363 skip |= CheckItgOffset(device_data, cb_node, &region->dstOffset, &granularity, i, function, "dstOffset");
Dave Houlton6f9059e2017-05-02 17:15:13 -06001364 subresource_extent = GetImageSubresourceExtent(dst_img, &region->dstSubresource);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001365 skip |= CheckItgExtent(device_data, cb_node, &region->extent, &region->dstOffset, &granularity, &subresource_extent, i,
1366 function, "extent");
1367 return skip;
1368}
1369
Dave Houlton6f9059e2017-05-02 17:15:13 -06001370// Validate contents of a VkImageCopy struct
1371bool ValidateImageCopyData(const layer_data *device_data, const debug_report_data *report_data, const uint32_t regionCount,
1372 const VkImageCopy *ic_regions, const IMAGE_STATE *src_state, const IMAGE_STATE *dst_state) {
1373 bool skip = false;
1374
1375 for (uint32_t i = 0; i < regionCount; i++) {
1376 VkImageCopy image_copy = ic_regions[i];
1377 bool slice_override = false;
1378 uint32_t depth_slices = 0;
1379
1380 // Special case for copying between a 1D/2D array and a 3D image
1381 // TBD: This seems like the only way to reconcile 3 mutually-exclusive VU checks for 2D/3D copies. Heads up.
1382 if ((VK_IMAGE_TYPE_3D == src_state->createInfo.imageType) && (VK_IMAGE_TYPE_3D != dst_state->createInfo.imageType)) {
1383 depth_slices = image_copy.dstSubresource.layerCount; // Slice count from 2D subresource
1384 slice_override = (depth_slices != 1);
1385 } else if ((VK_IMAGE_TYPE_3D == dst_state->createInfo.imageType) && (VK_IMAGE_TYPE_3D != src_state->createInfo.imageType)) {
1386 depth_slices = image_copy.srcSubresource.layerCount; // Slice count from 2D subresource
1387 slice_override = (depth_slices != 1);
1388 }
1389
1390 // Do all checks on source image
1391 //
1392 if (src_state->createInfo.imageType == VK_IMAGE_TYPE_1D) {
1393 if ((0 != image_copy.srcOffset.y) || (1 != image_copy.extent.height)) {
1394 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
1395 reinterpret_cast<const uint64_t &>(src_state->image), __LINE__, VALIDATION_ERROR_01742, "IMAGE",
1396 "vkCmdCopyImage(): pRegion[%d] srcOffset.y is %d and extent.height is %d. For 1D images these must "
1397 "be 0 and 1, respectively. %s",
1398 i, image_copy.srcOffset.y, image_copy.extent.height, validation_error_map[VALIDATION_ERROR_01742]);
1399 }
1400 }
1401
1402 if ((src_state->createInfo.imageType == VK_IMAGE_TYPE_1D) || (src_state->createInfo.imageType == VK_IMAGE_TYPE_2D)) {
1403 if ((0 != image_copy.srcOffset.z) || (1 != image_copy.extent.depth)) {
1404 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
1405 reinterpret_cast<const uint64_t &>(src_state->image), __LINE__, VALIDATION_ERROR_01743, "IMAGE",
1406 "vkCmdCopyImage(): pRegion[%d] srcOffset.z is %d and extent.depth is %d. For 1D and 2D images "
1407 "these must be 0 and 1, respectively. %s",
1408 i, image_copy.srcOffset.z, image_copy.extent.depth, validation_error_map[VALIDATION_ERROR_01743]);
1409 }
1410 }
1411
1412 // VU01199 changed with mnt1
1413 if (GetDeviceExtensions(device_data)->khr_maintenance1) {
1414 if (src_state->createInfo.imageType == VK_IMAGE_TYPE_3D) {
1415 if ((0 != image_copy.srcSubresource.baseArrayLayer) || (1 != image_copy.srcSubresource.layerCount)) {
1416 skip |=
1417 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
1418 reinterpret_cast<const uint64_t &>(src_state->image), __LINE__, VALIDATION_ERROR_01199, "IMAGE",
1419 "vkCmdCopyImage(): pRegion[%d] srcSubresource.baseArrayLayer is %d and srcSubresource.layerCount "
1420 "is %d. For VK_IMAGE_TYPE_3D images these must be 0 and 1, respectively. %s",
1421 i, image_copy.srcSubresource.baseArrayLayer, image_copy.srcSubresource.layerCount,
1422 validation_error_map[VALIDATION_ERROR_01199]);
1423 }
1424 }
1425 } else { // Pre maint 1
1426 if (src_state->createInfo.imageType == VK_IMAGE_TYPE_3D || dst_state->createInfo.imageType == VK_IMAGE_TYPE_3D) {
1427 if ((0 != image_copy.srcSubresource.baseArrayLayer) || (1 != image_copy.srcSubresource.layerCount)) {
1428 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
1429 reinterpret_cast<const uint64_t &>(src_state->image), __LINE__, VALIDATION_ERROR_01199, "IMAGE",
1430 "vkCmdCopyImage(): pRegion[%d] srcSubresource.baseArrayLayer is %d and "
1431 "srcSubresource.layerCount is %d. For copies with either source or dest of type "
1432 "VK_IMAGE_TYPE_3D, these must be 0 and 1, respectively. %s",
1433 i, image_copy.srcSubresource.baseArrayLayer, image_copy.srcSubresource.layerCount,
1434 validation_error_map[VALIDATION_ERROR_01199]);
1435 }
1436 }
1437 }
1438
1439 // TODO: this VU is redundant with VU01224. Gitlab issue 812 submitted to get it removed from the spec.
1440 if ((image_copy.srcSubresource.baseArrayLayer >= src_state->createInfo.arrayLayers) ||
1441 (image_copy.srcSubresource.baseArrayLayer + image_copy.srcSubresource.layerCount > src_state->createInfo.arrayLayers)) {
1442 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
1443 reinterpret_cast<const uint64_t &>(src_state->image), __LINE__, VALIDATION_ERROR_02603, "IMAGE",
1444 "vkCmdCopyImage(): pRegion[%d] srcSubresource.baseArrayLayer (%d) must be less than the source image's "
1445 "arrayLayers (%d), and the sum of baseArrayLayer and srcSubresource.layerCount (%d) must be less than "
1446 "or equal to the source image's arrayLayers. %s",
1447 i, image_copy.srcSubresource.baseArrayLayer, src_state->createInfo.arrayLayers,
1448 image_copy.srcSubresource.layerCount, validation_error_map[VALIDATION_ERROR_02603]);
1449 }
1450
1451 // Checks that apply only to compressed images
1452 if (FormatIsCompressed(src_state->createInfo.format)) {
1453 VkExtent3D block_size = FormatCompressedTexelBlockExtent(src_state->createInfo.format);
1454
1455 // image offsets must be multiples of block dimensions
1456 if ((SafeModulo(image_copy.srcOffset.x, block_size.width) != 0) ||
1457 (SafeModulo(image_copy.srcOffset.y, block_size.height) != 0) ||
1458 (SafeModulo(image_copy.srcOffset.z, block_size.depth) != 0)) {
1459 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
1460 reinterpret_cast<const uint64_t &>(src_state->image), __LINE__, VALIDATION_ERROR_01209, "IMAGE",
1461 "vkCmdCopyImage(): pRegion[%d] srcOffset (%d, %d) must be multiples of the compressed image's "
1462 "texel width & height (%d, %d). %s.",
1463 i, image_copy.srcOffset.x, image_copy.srcOffset.y, block_size.width, block_size.height,
1464 validation_error_map[VALIDATION_ERROR_01209]);
1465 }
1466
1467 // extent width must be a multiple of block width, or extent+offset width must equal subresource width
1468 VkExtent3D mip_extent = GetImageSubresourceExtent(src_state, &(image_copy.srcSubresource));
1469 if ((SafeModulo(image_copy.extent.width, block_size.width) != 0) &&
1470 (image_copy.extent.width + image_copy.srcOffset.x != mip_extent.width)) {
1471 skip |=
1472 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
1473 reinterpret_cast<const uint64_t &>(src_state->image), __LINE__, VALIDATION_ERROR_01210, "IMAGE",
1474 "vkCmdCopyImage(): pRegion[%d] extent width (%d) must be a multiple of the compressed texture block "
1475 "width (%d), or when added to srcOffset.x (%d) must equal the image subresource width (%d). %s.",
1476 i, image_copy.extent.width, block_size.width, image_copy.srcOffset.x, mip_extent.width,
1477 validation_error_map[VALIDATION_ERROR_01210]);
1478 }
1479
1480 // extent height must be a multiple of block height, or extent+offset height must equal subresource height
1481 if ((SafeModulo(image_copy.extent.height, block_size.height) != 0) &&
1482 (image_copy.extent.height + image_copy.srcOffset.y != mip_extent.height)) {
1483 skip |=
1484 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
1485 reinterpret_cast<const uint64_t &>(src_state->image), __LINE__, VALIDATION_ERROR_01211, "IMAGE",
1486 "vkCmdCopyImage(): pRegion[%d] extent height (%d) must be a multiple of the compressed texture block "
1487 "height (%d), or when added to srcOffset.y (%d) must equal the image subresource height (%d). %s.",
1488 i, image_copy.extent.height, block_size.height, image_copy.srcOffset.y, mip_extent.height,
1489 validation_error_map[VALIDATION_ERROR_01211]);
1490 }
1491
1492 // extent depth must be a multiple of block depth, or extent+offset depth must equal subresource depth
1493 uint32_t copy_depth = (slice_override ? depth_slices : image_copy.extent.depth);
1494 if ((SafeModulo(copy_depth, block_size.depth) != 0) && (copy_depth + image_copy.srcOffset.z != mip_extent.depth)) {
1495 skip |=
1496 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
1497 reinterpret_cast<const uint64_t &>(src_state->image), __LINE__, VALIDATION_ERROR_01212, "IMAGE",
1498 "vkCmdCopyImage(): pRegion[%d] extent width (%d) must be a multiple of the compressed texture block "
1499 "depth (%d), or when added to srcOffset.z (%d) must equal the image subresource depth (%d). %s.",
1500 i, image_copy.extent.depth, block_size.depth, image_copy.srcOffset.z, mip_extent.depth,
1501 validation_error_map[VALIDATION_ERROR_01212]);
1502 }
1503 } // Compressed
1504
1505 // Do all checks on dest image
1506 //
1507 if (dst_state->createInfo.imageType == VK_IMAGE_TYPE_1D) {
1508 if ((0 != image_copy.dstOffset.y) || (1 != image_copy.extent.height)) {
1509 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
1510 reinterpret_cast<const uint64_t &>(dst_state->image), __LINE__, VALIDATION_ERROR_01744, "IMAGE",
1511 "vkCmdCopyImage(): pRegion[%d] dstOffset.y is %d and extent.height is %d. For 1D images these must "
1512 "be 0 and 1, respectively. %s",
1513 i, image_copy.dstOffset.y, image_copy.extent.height, validation_error_map[VALIDATION_ERROR_01744]);
1514 }
1515 }
1516
1517 if ((dst_state->createInfo.imageType == VK_IMAGE_TYPE_1D) || (dst_state->createInfo.imageType == VK_IMAGE_TYPE_2D)) {
1518 if ((0 != image_copy.dstOffset.z) || (1 != image_copy.extent.depth)) {
1519 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
1520 reinterpret_cast<const uint64_t &>(dst_state->image), __LINE__, VALIDATION_ERROR_01745, "IMAGE",
1521 "vkCmdCopyImage(): pRegion[%d] dstOffset.z is %d and extent.depth is %d. For 1D and 2D images "
1522 "these must be 0 and 1, respectively. %s",
1523 i, image_copy.dstOffset.z, image_copy.extent.depth, validation_error_map[VALIDATION_ERROR_01745]);
1524 }
1525 }
1526
1527 if (dst_state->createInfo.imageType == VK_IMAGE_TYPE_3D) {
1528 if ((0 != image_copy.dstSubresource.baseArrayLayer) || (1 != image_copy.dstSubresource.layerCount)) {
1529 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
1530 reinterpret_cast<const uint64_t &>(dst_state->image), __LINE__, VALIDATION_ERROR_01199, "IMAGE",
1531 "vkCmdCopyImage(): pRegion[%d] dstSubresource.baseArrayLayer is %d and dstSubresource.layerCount "
1532 "is %d. For VK_IMAGE_TYPE_3D images these must be 0 and 1, respectively. %s",
1533 i, image_copy.dstSubresource.baseArrayLayer, image_copy.dstSubresource.layerCount,
1534 validation_error_map[VALIDATION_ERROR_01199]);
1535 }
1536 }
1537 // VU01199 changed with mnt1
1538 if (GetDeviceExtensions(device_data)->khr_maintenance1) {
1539 if (dst_state->createInfo.imageType == VK_IMAGE_TYPE_3D) {
1540 if ((0 != image_copy.dstSubresource.baseArrayLayer) || (1 != image_copy.dstSubresource.layerCount)) {
1541 skip |=
1542 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
1543 reinterpret_cast<const uint64_t &>(dst_state->image), __LINE__, VALIDATION_ERROR_01199, "IMAGE",
1544 "vkCmdCopyImage(): pRegion[%d] dstSubresource.baseArrayLayer is %d and dstSubresource.layerCount "
1545 "is %d. For VK_IMAGE_TYPE_3D images these must be 0 and 1, respectively. %s",
1546 i, image_copy.dstSubresource.baseArrayLayer, image_copy.dstSubresource.layerCount,
1547 validation_error_map[VALIDATION_ERROR_01199]);
1548 }
1549 }
1550 } else { // Pre maint 1
1551 if (src_state->createInfo.imageType == VK_IMAGE_TYPE_3D || dst_state->createInfo.imageType == VK_IMAGE_TYPE_3D) {
1552 if ((0 != image_copy.dstSubresource.baseArrayLayer) || (1 != image_copy.dstSubresource.layerCount)) {
1553 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
1554 reinterpret_cast<const uint64_t &>(dst_state->image), __LINE__, VALIDATION_ERROR_01199, "IMAGE",
1555 "vkCmdCopyImage(): pRegion[%d] dstSubresource.baseArrayLayer is %d and "
1556 "dstSubresource.layerCount is %d. For copies with either source or dest of type "
1557 "VK_IMAGE_TYPE_3D, these must be 0 and 1, respectively. %s",
1558 i, image_copy.dstSubresource.baseArrayLayer, image_copy.dstSubresource.layerCount,
1559 validation_error_map[VALIDATION_ERROR_01199]);
1560 }
1561 }
1562 }
1563
1564 // TODO: this VU is redundant with VU01224. Gitlab issue 812 submitted to get it removed from the spec.
1565 if ((image_copy.dstSubresource.baseArrayLayer >= dst_state->createInfo.arrayLayers) ||
1566 (image_copy.dstSubresource.baseArrayLayer + image_copy.dstSubresource.layerCount > dst_state->createInfo.arrayLayers)) {
1567 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
1568 reinterpret_cast<const uint64_t &>(dst_state->image), __LINE__, VALIDATION_ERROR_02604, "IMAGE",
1569 "vkCmdCopyImage(): pRegion[%d] dstSubresource.baseArrayLayer (%d) must be less than the dest image's "
1570 "arrayLayers (%d), and the sum of baseArrayLayer and dstSubresource.layerCount (%d) must be less than "
1571 "or equal to the dest image's arrayLayers. %s",
1572 i, image_copy.dstSubresource.baseArrayLayer, dst_state->createInfo.arrayLayers,
1573 image_copy.dstSubresource.layerCount, validation_error_map[VALIDATION_ERROR_02604]);
1574 }
1575
1576 // Checks that apply only to compressed images
1577 if (FormatIsCompressed(dst_state->createInfo.format)) {
1578 VkExtent3D block_size = FormatCompressedTexelBlockExtent(dst_state->createInfo.format);
1579
1580 // image offsets must be multiples of block dimensions
1581 if ((SafeModulo(image_copy.dstOffset.x, block_size.width) != 0) ||
1582 (SafeModulo(image_copy.dstOffset.y, block_size.height) != 0) ||
1583 (SafeModulo(image_copy.dstOffset.z, block_size.depth) != 0)) {
1584 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
1585 reinterpret_cast<const uint64_t &>(dst_state->image), __LINE__, VALIDATION_ERROR_01214, "IMAGE",
1586 "vkCmdCopyImage(): pRegion[%d] dstOffset (%d, %d) must be multiples of the compressed image's "
1587 "texel width & height (%d, %d). %s.",
1588 i, image_copy.dstOffset.x, image_copy.dstOffset.y, block_size.width, block_size.height,
1589 validation_error_map[VALIDATION_ERROR_01214]);
1590 }
1591
1592 // extent width must be a multiple of block width, or extent+offset width must equal subresource width
1593 VkExtent3D mip_extent = GetImageSubresourceExtent(dst_state, &(image_copy.dstSubresource));
1594 if ((SafeModulo(image_copy.extent.width, block_size.width) != 0) &&
1595 (image_copy.extent.width + image_copy.dstOffset.x != mip_extent.width)) {
1596 skip |=
1597 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
1598 reinterpret_cast<const uint64_t &>(dst_state->image), __LINE__, VALIDATION_ERROR_01215, "IMAGE",
1599 "vkCmdCopyImage(): pRegion[%d] extent width (%d) must be a multiple of the compressed texture block "
1600 "width (%d), or when added to dstOffset.x (%d) must equal the image subresource width (%d). %s.",
1601 i, image_copy.extent.width, block_size.width, image_copy.dstOffset.x, mip_extent.width,
1602 validation_error_map[VALIDATION_ERROR_01215]);
1603 }
1604
1605 // extent height must be a multiple of block height, or extent+offset height must equal subresource height
1606 if ((SafeModulo(image_copy.extent.height, block_size.height) != 0) &&
1607 (image_copy.extent.height + image_copy.dstOffset.y != mip_extent.height)) {
1608 skip |=
1609 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
1610 reinterpret_cast<const uint64_t &>(dst_state->image), __LINE__, VALIDATION_ERROR_01216, "IMAGE",
1611 "vkCmdCopyImage(): pRegion[%d] extent height (%d) must be a multiple of the compressed texture block "
1612 "height (%d), or when added to dstOffset.y (%d) must equal the image subresource height (%d). %s.",
1613 i, image_copy.extent.height, block_size.height, image_copy.dstOffset.y, mip_extent.height,
1614 validation_error_map[VALIDATION_ERROR_01216]);
1615 }
1616
1617 // extent depth must be a multiple of block depth, or extent+offset depth must equal subresource depth
1618 uint32_t copy_depth = (slice_override ? depth_slices : image_copy.extent.depth);
1619 if ((SafeModulo(copy_depth, block_size.depth) != 0) && (copy_depth + image_copy.dstOffset.z != mip_extent.depth)) {
1620 skip |=
1621 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
1622 reinterpret_cast<const uint64_t &>(dst_state->image), __LINE__, VALIDATION_ERROR_01217, "IMAGE",
1623 "vkCmdCopyImage(): pRegion[%d] extent width (%d) must be a multiple of the compressed texture block "
1624 "depth (%d), or when added to dstOffset.z (%d) must equal the image subresource depth (%d). %s.",
1625 i, image_copy.extent.depth, block_size.depth, image_copy.dstOffset.z, mip_extent.depth,
1626 validation_error_map[VALIDATION_ERROR_01217]);
1627 }
1628 } // Compressed
1629 }
1630 return skip;
1631}
1632
Tobin Ehlis58c884f2017-02-08 12:15:27 -07001633bool PreCallValidateCmdCopyImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state,
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001634 IMAGE_STATE *dst_image_state, uint32_t region_count, const VkImageCopy *regions,
1635 VkImageLayout src_image_layout, VkImageLayout dst_image_layout) {
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001636 bool skip = false;
1637 const debug_report_data *report_data = core_validation::GetReportData(device_data);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001638 skip = ValidateImageCopyData(device_data, report_data, region_count, regions, src_image_state, dst_image_state);
1639
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001640 VkCommandBuffer command_buffer = cb_node->commandBuffer;
1641
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001642 for (uint32_t i = 0; i < region_count; i++) {
Dave Houlton6f9059e2017-05-02 17:15:13 -06001643 bool slice_override = false;
1644 uint32_t depth_slices = 0;
1645
1646 // Special case for copying between a 1D/2D array and a 3D image
1647 // TBD: This seems like the only way to reconcile 3 mutually-exclusive VU checks for 2D/3D copies. Heads up.
1648 if ((VK_IMAGE_TYPE_3D == src_image_state->createInfo.imageType) &&
1649 (VK_IMAGE_TYPE_3D != dst_image_state->createInfo.imageType)) {
1650 depth_slices = regions[i].dstSubresource.layerCount; // Slice count from 2D subresource
1651 slice_override = (depth_slices != 1);
1652 } else if ((VK_IMAGE_TYPE_3D == dst_image_state->createInfo.imageType) &&
1653 (VK_IMAGE_TYPE_3D != src_image_state->createInfo.imageType)) {
1654 depth_slices = regions[i].srcSubresource.layerCount; // Slice count from 2D subresource
1655 slice_override = (depth_slices != 1);
1656 }
1657
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001658 if (regions[i].srcSubresource.layerCount == 0) {
1659 std::stringstream ss;
1660 ss << "vkCmdCopyImage: number of layers in pRegions[" << i << "] srcSubresource is zero";
Petr Krausbc7f5442017-05-14 23:43:38 +02001661 skip |=
1662 log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1663 HandleToUint64(command_buffer), __LINE__, DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", "%s", ss.str().c_str());
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001664 }
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001665
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001666 if (regions[i].dstSubresource.layerCount == 0) {
1667 std::stringstream ss;
1668 ss << "vkCmdCopyImage: number of layers in pRegions[" << i << "] dstSubresource is zero";
Petr Krausbc7f5442017-05-14 23:43:38 +02001669 skip |=
1670 log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1671 HandleToUint64(command_buffer), __LINE__, DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", "%s", ss.str().c_str());
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001672 }
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001673
Dave Houlton6f9059e2017-05-02 17:15:13 -06001674 if (GetDeviceExtensions(device_data)->khr_maintenance1) {
1675 // No chance of mismatch if we're overriding depth slice count
1676 if (!slice_override) {
1677 // The number of depth slices in srcSubresource and dstSubresource must match
1678 // Depth comes from layerCount for 1D,2D resources, from extent.depth for 3D
1679 uint32_t src_slices =
1680 (VK_IMAGE_TYPE_3D == src_image_state->createInfo.imageType ? regions[i].extent.depth
1681 : regions[i].srcSubresource.layerCount);
1682 uint32_t dst_slices =
1683 (VK_IMAGE_TYPE_3D == dst_image_state->createInfo.imageType ? regions[i].extent.depth
1684 : regions[i].dstSubresource.layerCount);
1685 if (src_slices != dst_slices) {
1686 std::stringstream ss;
1687 ss << "vkCmdCopyImage: number of depth slices in source and destination subresources for pRegions[" << i
1688 << "] do not match";
1689 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1690 reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01198, "IMAGE",
1691 "%s. %s", ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01198]);
1692 }
1693 }
1694 } else {
Mike Schuchardt64b5bb72017-03-21 16:33:26 -06001695 // For each region the layerCount member of srcSubresource and dstSubresource must match
1696 if (regions[i].srcSubresource.layerCount != regions[i].dstSubresource.layerCount) {
1697 std::stringstream ss;
1698 ss << "vkCmdCopyImage: number of layers in source and destination subresources for pRegions[" << i
1699 << "] do not match";
1700 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02001701 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_01198, "IMAGE", "%s. %s",
Mike Schuchardt64b5bb72017-03-21 16:33:26 -06001702 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01198]);
1703 }
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001704 }
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001705
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001706 // For each region, the aspectMask member of srcSubresource and dstSubresource must match
1707 if (regions[i].srcSubresource.aspectMask != regions[i].dstSubresource.aspectMask) {
1708 char const str[] = "vkCmdCopyImage: Src and dest aspectMasks for each region must match";
1709 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02001710 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_01197, "IMAGE", "%s. %s", str,
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001711 validation_error_map[VALIDATION_ERROR_01197]);
1712 }
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001713
Dave Houlton4eaaf3a2017-03-14 11:31:20 -06001714 // For each region, the aspectMask member of srcSubresource must be present in the source image
1715 if (!VerifyAspectsPresent(regions[i].srcSubresource.aspectMask, src_image_state->createInfo.format)) {
1716 std::stringstream ss;
1717 ss << "vkCmdCopyImage: pRegion[" << i
1718 << "] srcSubresource.aspectMask cannot specify aspects not present in source image";
1719 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02001720 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_01200, "IMAGE", "%s. %s", ss.str().c_str(),
1721 validation_error_map[VALIDATION_ERROR_01200]);
Dave Houlton4eaaf3a2017-03-14 11:31:20 -06001722 }
1723
1724 // For each region, the aspectMask member of dstSubresource must be present in the destination image
1725 if (!VerifyAspectsPresent(regions[i].dstSubresource.aspectMask, dst_image_state->createInfo.format)) {
1726 std::stringstream ss;
1727 ss << "vkCmdCopyImage: pRegion[" << i << "] dstSubresource.aspectMask cannot specify aspects not present in dest image";
1728 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02001729 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_01201, "IMAGE", "%s. %s", ss.str().c_str(),
1730 validation_error_map[VALIDATION_ERROR_01201]);
Dave Houlton4eaaf3a2017-03-14 11:31:20 -06001731 }
1732
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001733 // AspectMask must not contain VK_IMAGE_ASPECT_METADATA_BIT
1734 if ((regions[i].srcSubresource.aspectMask & VK_IMAGE_ASPECT_METADATA_BIT) ||
1735 (regions[i].dstSubresource.aspectMask & VK_IMAGE_ASPECT_METADATA_BIT)) {
1736 std::stringstream ss;
1737 ss << "vkCmdCopyImage: pRegions[" << i << "] may not specify aspectMask containing VK_IMAGE_ASPECT_METADATA_BIT";
1738 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02001739 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_01222, "IMAGE", "%s. %s", ss.str().c_str(),
1740 validation_error_map[VALIDATION_ERROR_01222]);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001741 }
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001742
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001743 // For each region, if aspectMask contains VK_IMAGE_ASPECT_COLOR_BIT, it must not contain either of
1744 // VK_IMAGE_ASPECT_DEPTH_BIT or VK_IMAGE_ASPECT_STENCIL_BIT
1745 if ((regions[i].srcSubresource.aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) &&
1746 (regions[i].srcSubresource.aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT))) {
1747 char const str[] = "vkCmdCopyImage aspectMask cannot specify both COLOR and DEPTH/STENCIL aspects";
1748 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02001749 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_01221, "IMAGE", "%s. %s", str,
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001750 validation_error_map[VALIDATION_ERROR_01221]);
1751 }
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001752
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001753 // MipLevel must be less than the mipLevels specified in VkImageCreateInfo when the image was created
1754 if (regions[i].srcSubresource.mipLevel >= src_image_state->createInfo.mipLevels) {
1755 std::stringstream ss;
1756 ss << "vkCmdCopyImage: pRegions[" << i
1757 << "] specifies a src mipLevel greater than the number specified when the srcImage was created.";
1758 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02001759 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_01223, "IMAGE", "%s. %s", ss.str().c_str(),
1760 validation_error_map[VALIDATION_ERROR_01223]);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001761 }
1762 if (regions[i].dstSubresource.mipLevel >= dst_image_state->createInfo.mipLevels) {
1763 std::stringstream ss;
1764 ss << "vkCmdCopyImage: pRegions[" << i
1765 << "] specifies a dst mipLevel greater than the number specified when the dstImage was created.";
1766 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02001767 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_01223, "IMAGE", "%s. %s", ss.str().c_str(),
1768 validation_error_map[VALIDATION_ERROR_01223]);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001769 }
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001770
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001771 // (baseArrayLayer + layerCount) must be less than or equal to the arrayLayers specified in VkImageCreateInfo when the
1772 // image was created
1773 if ((regions[i].srcSubresource.baseArrayLayer + regions[i].srcSubresource.layerCount) >
1774 src_image_state->createInfo.arrayLayers) {
1775 std::stringstream ss;
1776 ss << "vkCmdCopyImage: srcImage arrayLayers was " << src_image_state->createInfo.arrayLayers << " but subRegion[" << i
1777 << "] baseArrayLayer + layerCount is "
1778 << (regions[i].srcSubresource.baseArrayLayer + regions[i].srcSubresource.layerCount);
1779 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02001780 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_01224, "IMAGE", "%s. %s", ss.str().c_str(),
1781 validation_error_map[VALIDATION_ERROR_01224]);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001782 }
1783 if ((regions[i].dstSubresource.baseArrayLayer + regions[i].dstSubresource.layerCount) >
1784 dst_image_state->createInfo.arrayLayers) {
1785 std::stringstream ss;
1786 ss << "vkCmdCopyImage: dstImage arrayLayers was " << dst_image_state->createInfo.arrayLayers << " but subRegion[" << i
1787 << "] baseArrayLayer + layerCount is "
1788 << (regions[i].dstSubresource.baseArrayLayer + regions[i].dstSubresource.layerCount);
1789 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02001790 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_01224, "IMAGE", "%s. %s", ss.str().c_str(),
1791 validation_error_map[VALIDATION_ERROR_01224]);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001792 }
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001793
Mike Schuchardt64b5bb72017-03-21 16:33:26 -06001794 // Check region extents for 1D-1D, 2D-2D, and 3D-3D copies
1795 if (src_image_state->createInfo.imageType == dst_image_state->createInfo.imageType) {
1796 // The source region specified by a given element of regions must be a region that is contained within srcImage
Dave Houltonfc1a4052017-04-27 14:32:45 -06001797 VkExtent3D img_extent = GetImageSubresourceExtent(src_image_state, &(regions[i].srcSubresource));
1798 if (0 != ExceedsBounds(&regions[i].srcOffset, &regions[i].extent, &img_extent)) {
Mike Schuchardt64b5bb72017-03-21 16:33:26 -06001799 std::stringstream ss;
Dave Houltonfc1a4052017-04-27 14:32:45 -06001800 ss << "vkCmdCopyImage: Source pRegion[" << i << "] with mipLevel [ " << regions[i].srcSubresource.mipLevel
1801 << " ], offset [ " << regions[i].srcOffset.x << ", " << regions[i].srcOffset.y << ", " << regions[i].srcOffset.z
1802 << " ], extent [ " << regions[i].extent.width << ", " << regions[i].extent.height << ", "
1803 << regions[i].extent.depth << " ] exceeds the source image dimensions";
Mike Schuchardt64b5bb72017-03-21 16:33:26 -06001804 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02001805 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_01175, "IMAGE", "%s. %s",
Mike Schuchardt64b5bb72017-03-21 16:33:26 -06001806 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01175]);
1807 }
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001808
Mike Schuchardt64b5bb72017-03-21 16:33:26 -06001809 // The destination region specified by a given element of regions must be a region that is contained within dst_image
Dave Houltonfc1a4052017-04-27 14:32:45 -06001810 img_extent = GetImageSubresourceExtent(dst_image_state, &(regions[i].dstSubresource));
1811 if (0 != ExceedsBounds(&regions[i].dstOffset, &regions[i].extent, &img_extent)) {
Mike Schuchardt64b5bb72017-03-21 16:33:26 -06001812 std::stringstream ss;
Dave Houltonfc1a4052017-04-27 14:32:45 -06001813 ss << "vkCmdCopyImage: Dest pRegion[" << i << "] with mipLevel [ " << regions[i].dstSubresource.mipLevel
1814 << " ], offset [ " << regions[i].dstOffset.x << ", " << regions[i].dstOffset.y << ", " << regions[i].dstOffset.z
1815 << " ], extent [ " << regions[i].extent.width << ", " << regions[i].extent.height << ", "
1816 << regions[i].extent.depth << " ] exceeds the destination image dimensions";
Mike Schuchardt64b5bb72017-03-21 16:33:26 -06001817 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02001818 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_01176, "IMAGE", "%s. %s",
Mike Schuchardt64b5bb72017-03-21 16:33:26 -06001819 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01176]);
1820 }
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001821 }
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001822
Dave Houltonfc1a4052017-04-27 14:32:45 -06001823 // Each dimension offset + extent limits must fall with image subresource extent
1824 VkExtent3D subresource_extent = GetImageSubresourceExtent(src_image_state, &(regions[i].srcSubresource));
Dave Houlton6f9059e2017-05-02 17:15:13 -06001825 VkExtent3D copy_extent = regions[i].extent;
1826 if (slice_override) copy_extent.depth = depth_slices;
1827 uint32_t extent_check = ExceedsBounds(&(regions[i].srcOffset), &copy_extent, &subresource_extent);
Dave Houltonfc1a4052017-04-27 14:32:45 -06001828 if (extent_check & x_bit) {
1829 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02001830 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_01202, "IMAGE",
Dave Houltonfc1a4052017-04-27 14:32:45 -06001831 "vkCmdCopyImage: Source image pRegion %1d x-dimension offset [%1d] + extent [%1d] exceeds subResource "
1832 "width [%1d]. %s",
1833 i, regions[i].srcOffset.x, regions[i].extent.width, subresource_extent.width,
1834 validation_error_map[VALIDATION_ERROR_01202]);
1835 }
1836
1837 if (extent_check & y_bit) {
1838 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02001839 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_01203, "IMAGE",
Dave Houltonfc1a4052017-04-27 14:32:45 -06001840 "vkCmdCopyImage: Source image pRegion %1d y-dimension offset [%1d] + extent [%1d] exceeds subResource "
1841 "height [%1d]. %s",
1842 i, regions[i].srcOffset.y, regions[i].extent.height, subresource_extent.height,
1843 validation_error_map[VALIDATION_ERROR_01203]);
1844 }
1845 if (extent_check & z_bit) {
1846 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02001847 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_01204, "IMAGE",
Dave Houltonfc1a4052017-04-27 14:32:45 -06001848 "vkCmdCopyImage: Source image pRegion %1d z-dimension offset [%1d] + extent [%1d] exceeds subResource "
1849 "depth [%1d]. %s",
Dave Houlton6f9059e2017-05-02 17:15:13 -06001850 i, regions[i].srcOffset.z, copy_extent.depth, subresource_extent.depth,
Dave Houltonfc1a4052017-04-27 14:32:45 -06001851 validation_error_map[VALIDATION_ERROR_01204]);
1852 }
1853
1854 subresource_extent = GetImageSubresourceExtent(dst_image_state, &(regions[i].dstSubresource));
Dave Houlton6f9059e2017-05-02 17:15:13 -06001855 copy_extent = regions[i].extent;
1856 if (slice_override) copy_extent.depth = depth_slices;
1857 extent_check = ExceedsBounds(&(regions[i].dstOffset), &copy_extent, &subresource_extent);
Dave Houltonfc1a4052017-04-27 14:32:45 -06001858 if (extent_check & x_bit) {
1859 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02001860 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_01205, "IMAGE",
Dave Houltonfc1a4052017-04-27 14:32:45 -06001861 "vkCmdCopyImage: Dest image pRegion %1d x-dimension offset [%1d] + extent [%1d] exceeds subResource "
1862 "width [%1d]. %s",
1863 i, regions[i].dstOffset.x, regions[i].extent.width, subresource_extent.width,
1864 validation_error_map[VALIDATION_ERROR_01205]);
1865 }
1866 if (extent_check & y_bit) {
1867 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02001868 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_01206, "IMAGE",
Dave Houltonfc1a4052017-04-27 14:32:45 -06001869 "vkCmdCopyImage: Dest image pRegion %1d y-dimension offset [%1d] + extent [%1d] exceeds subResource "
1870 "height [%1d]. %s",
1871 i, regions[i].dstOffset.y, regions[i].extent.height, subresource_extent.height,
1872 validation_error_map[VALIDATION_ERROR_01206]);
1873 }
1874 if (extent_check & z_bit) {
1875 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02001876 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_01207, "IMAGE",
Dave Houltonfc1a4052017-04-27 14:32:45 -06001877 "vkCmdCopyImage: Dest image pRegion %1d z-dimension offset [%1d] + extent [%1d] exceeds subResource "
1878 "depth [%1d]. %s",
Dave Houlton6f9059e2017-05-02 17:15:13 -06001879 i, regions[i].dstOffset.z, copy_extent.depth, subresource_extent.depth,
Dave Houltonfc1a4052017-04-27 14:32:45 -06001880 validation_error_map[VALIDATION_ERROR_01207]);
1881 }
1882
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001883 // The union of all source regions, and the union of all destination regions, specified by the elements of regions,
1884 // must not overlap in memory
1885 if (src_image_state->image == dst_image_state->image) {
1886 for (uint32_t j = 0; j < region_count; j++) {
1887 if (RegionIntersects(&regions[i], &regions[j], src_image_state->createInfo.imageType)) {
1888 std::stringstream ss;
1889 ss << "vkCmdCopyImage: pRegions[" << i << "] src overlaps with pRegions[" << j << "].";
1890 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02001891 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_01177, "IMAGE", "%s. %s",
1892 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01177]);
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001893 }
1894 }
1895 }
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001896 }
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001897
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001898 // The formats of src_image and dst_image must be compatible. Formats are considered compatible if their texel size in bytes
1899 // is the same between both formats. For example, VK_FORMAT_R8G8B8A8_UNORM is compatible with VK_FORMAT_R32_UINT because
1900 // because both texels are 4 bytes in size. Depth/stencil formats must match exactly.
Dave Houlton1150cf52017-04-27 14:38:11 -06001901 if (FormatIsDepthOrStencil(src_image_state->createInfo.format) || FormatIsDepthOrStencil(dst_image_state->createInfo.format)) {
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001902 if (src_image_state->createInfo.format != dst_image_state->createInfo.format) {
1903 char const str[] = "vkCmdCopyImage called with unmatched source and dest image depth/stencil formats.";
Petr Krausbc7f5442017-05-14 23:43:38 +02001904 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1905 HandleToUint64(command_buffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_FORMAT, "IMAGE", str);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001906 }
1907 } else {
Dave Houlton1d2022c2017-03-29 11:43:58 -06001908 size_t srcSize = FormatSize(src_image_state->createInfo.format);
1909 size_t destSize = FormatSize(dst_image_state->createInfo.format);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001910 if (srcSize != destSize) {
1911 char const str[] = "vkCmdCopyImage called with unmatched source and dest image format sizes.";
1912 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02001913 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_01184, "IMAGE", "%s. %s", str,
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001914 validation_error_map[VALIDATION_ERROR_01184]);
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001915 }
1916 }
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001917
Dave Houlton33c22b72017-02-28 13:16:02 -07001918 // Source and dest image sample counts must match
1919 if (src_image_state->createInfo.samples != dst_image_state->createInfo.samples) {
1920 char const str[] = "vkCmdCopyImage() called on image pair with non-identical sample counts.";
1921 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02001922 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_01185, "IMAGE", "%s %s", str,
Dave Houlton4eaaf3a2017-03-14 11:31:20 -06001923 validation_error_map[VALIDATION_ERROR_01185]);
Dave Houlton33c22b72017-02-28 13:16:02 -07001924 }
1925
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001926 skip |= ValidateMemoryIsBoundToImage(device_data, src_image_state, "vkCmdCopyImage()", VALIDATION_ERROR_02533);
1927 skip |= ValidateMemoryIsBoundToImage(device_data, dst_image_state, "vkCmdCopyImage()", VALIDATION_ERROR_02534);
1928 // Validate that SRC & DST images have correct usage flags set
1929 skip |= ValidateImageUsageFlags(device_data, src_image_state, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, true, VALIDATION_ERROR_01178,
1930 "vkCmdCopyImage()", "VK_IMAGE_USAGE_TRANSFER_SRC_BIT");
1931 skip |= ValidateImageUsageFlags(device_data, dst_image_state, VK_IMAGE_USAGE_TRANSFER_DST_BIT, true, VALIDATION_ERROR_01181,
1932 "vkCmdCopyImage()", "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Mike Schuchardt9c582402017-02-23 15:57:37 -07001933 skip |= ValidateCmdQueueFlags(device_data, cb_node, "vkCmdCopyImage()",
1934 VK_QUEUE_TRANSFER_BIT | VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT, VALIDATION_ERROR_01193);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001935 skip |= ValidateCmd(device_data, cb_node, CMD_COPYIMAGE, "vkCmdCopyImage()");
1936 skip |= insideRenderPass(device_data, cb_node, "vkCmdCopyImage()", VALIDATION_ERROR_01194);
Tobin Ehlisc8266452017-04-07 12:20:30 -06001937 bool hit_error = false;
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001938 for (uint32_t i = 0; i < region_count; ++i) {
Tobin Ehlis2d85ec62017-03-14 15:38:48 -06001939 skip |= VerifyImageLayout(device_data, cb_node, src_image_state, regions[i].srcSubresource, src_image_layout,
Tobin Ehlisc8266452017-04-07 12:20:30 -06001940 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, "vkCmdCopyImage()", VALIDATION_ERROR_01180, &hit_error);
Tobin Ehlis2d85ec62017-03-14 15:38:48 -06001941 skip |= VerifyImageLayout(device_data, cb_node, dst_image_state, regions[i].dstSubresource, dst_image_layout,
Tobin Ehlisc8266452017-04-07 12:20:30 -06001942 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, "vkCmdCopyImage()", VALIDATION_ERROR_01183, &hit_error);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001943 skip |= ValidateCopyImageTransferGranularityRequirements(device_data, cb_node, src_image_state, dst_image_state,
1944 &regions[i], i, "vkCmdCopyImage()");
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001945 }
1946
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001947 return skip;
1948}
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07001949
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001950void PreCallRecordCmdCopyImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state,
Tobin Ehlise35b66a2017-03-15 12:18:31 -06001951 IMAGE_STATE *dst_image_state, uint32_t region_count, const VkImageCopy *regions,
1952 VkImageLayout src_image_layout, VkImageLayout dst_image_layout) {
1953 // Make sure that all image slices are updated to correct layout
1954 for (uint32_t i = 0; i < region_count; ++i) {
1955 SetImageLayout(device_data, cb_node, src_image_state, regions[i].srcSubresource, src_image_layout);
1956 SetImageLayout(device_data, cb_node, dst_image_state, regions[i].dstSubresource, dst_image_layout);
1957 }
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001958 // Update bindings between images and cmd buffer
1959 AddCommandBufferBindingImage(device_data, cb_node, src_image_state);
1960 AddCommandBufferBindingImage(device_data, cb_node, dst_image_state);
Dave Houltoneba86e22017-03-02 14:56:23 -07001961 std::function<bool()> function = [=]() { return ValidateImageMemoryIsValid(device_data, src_image_state, "vkCmdCopyImage()"); };
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001962 cb_node->validate_functions.push_back(function);
1963 function = [=]() {
1964 SetImageMemoryValid(device_data, dst_image_state, true);
1965 return false;
1966 };
1967 cb_node->validate_functions.push_back(function);
1968 core_validation::UpdateCmdBufferLastCmd(cb_node, CMD_COPYIMAGE);
1969}
1970
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07001971// Returns true if sub_rect is entirely contained within rect
1972static inline bool ContainsRect(VkRect2D rect, VkRect2D sub_rect) {
1973 if ((sub_rect.offset.x < rect.offset.x) || (sub_rect.offset.x + sub_rect.extent.width > rect.offset.x + rect.extent.width) ||
1974 (sub_rect.offset.y < rect.offset.y) || (sub_rect.offset.y + sub_rect.extent.height > rect.offset.y + rect.extent.height))
1975 return false;
1976 return true;
1977}
1978
Tobin Ehlis58c884f2017-02-08 12:15:27 -07001979bool PreCallValidateCmdClearAttachments(layer_data *device_data, VkCommandBuffer commandBuffer, uint32_t attachmentCount,
1980 const VkClearAttachment *pAttachments, uint32_t rectCount, const VkClearRect *pRects) {
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07001981 GLOBAL_CB_NODE *cb_node = GetCBNode(device_data, commandBuffer);
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07001982 const debug_report_data *report_data = core_validation::GetReportData(device_data);
1983
1984 bool skip = false;
1985 if (cb_node) {
Mike Schuchardt9c582402017-02-23 15:57:37 -07001986 skip |=
1987 ValidateCmdQueueFlags(device_data, cb_node, "vkCmdClearAttachments()", VK_QUEUE_GRAPHICS_BIT, VALIDATION_ERROR_01121);
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07001988 skip |= ValidateCmd(device_data, cb_node, CMD_CLEARATTACHMENTS, "vkCmdClearAttachments()");
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07001989 core_validation::UpdateCmdBufferLastCmd(cb_node, CMD_CLEARATTACHMENTS);
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07001990 // Warn if this is issued prior to Draw Cmd and clearing the entire attachment
Chris Forbes05375e72017-04-21 13:15:15 -07001991 if (!cb_node->hasDrawCmd && (cb_node->activeRenderPassBeginInfo.renderArea.extent.width == pRects[0].rect.extent.width) &&
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07001992 (cb_node->activeRenderPassBeginInfo.renderArea.extent.height == pRects[0].rect.extent.height)) {
1993 // 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 -07001994 // This warning should be made more specific. It'd be best to avoid triggering this test if it's a use that must call
1995 // CmdClearAttachments.
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07001996 skip |=
1997 log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02001998 HandleToUint64(commandBuffer), 0, DRAWSTATE_CLEAR_CMD_BEFORE_DRAW, "DS",
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07001999 "vkCmdClearAttachments() issued on command buffer object 0x%p prior to any Draw Cmds."
2000 " It is recommended you use RenderPass LOAD_OP_CLEAR on Attachments prior to any Draw.",
2001 commandBuffer);
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002002 }
2003 skip |= outsideRenderPass(device_data, cb_node, "vkCmdClearAttachments()", VALIDATION_ERROR_01122);
2004 }
2005
2006 // Validate that attachment is in reference list of active subpass
2007 if (cb_node->activeRenderPass) {
2008 const VkRenderPassCreateInfo *renderpass_create_info = cb_node->activeRenderPass->createInfo.ptr();
2009 const VkSubpassDescription *subpass_desc = &renderpass_create_info->pSubpasses[cb_node->activeSubpass];
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07002010 auto framebuffer = GetFramebufferState(device_data, cb_node->activeFramebuffer);
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002011
2012 for (uint32_t i = 0; i < attachmentCount; i++) {
2013 auto clear_desc = &pAttachments[i];
2014 VkImageView image_view = VK_NULL_HANDLE;
2015
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07002016 if (0 == clear_desc->aspectMask) {
2017 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02002018 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_01128, "IMAGE", "%s",
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07002019 validation_error_map[VALIDATION_ERROR_01128]);
2020 } else if (clear_desc->aspectMask & VK_IMAGE_ASPECT_METADATA_BIT) {
2021 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02002022 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_01126, "IMAGE", "%s",
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07002023 validation_error_map[VALIDATION_ERROR_01126]);
2024 } else if (clear_desc->aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) {
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002025 if (clear_desc->colorAttachment >= subpass_desc->colorAttachmentCount) {
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07002026 skip |=
2027 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02002028 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_01114, "DS",
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07002029 "vkCmdClearAttachments() color attachment index %d out of range for active subpass %d. %s",
2030 clear_desc->colorAttachment, cb_node->activeSubpass, validation_error_map[VALIDATION_ERROR_01114]);
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002031 } else if (subpass_desc->pColorAttachments[clear_desc->colorAttachment].attachment == VK_ATTACHMENT_UNUSED) {
2032 skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02002033 VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, HandleToUint64(commandBuffer), __LINE__,
2034 DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS",
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07002035 "vkCmdClearAttachments() color attachment index %d is VK_ATTACHMENT_UNUSED; ignored.",
2036 clear_desc->colorAttachment);
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002037 } else {
2038 image_view = framebuffer->createInfo
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07002039 .pAttachments[subpass_desc->pColorAttachments[clear_desc->colorAttachment].attachment];
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002040 }
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07002041 if ((clear_desc->aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) ||
2042 (clear_desc->aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT)) {
2043 char const str[] =
2044 "vkCmdClearAttachments aspectMask [%d] must set only VK_IMAGE_ASPECT_COLOR_BIT of a color attachment. %s";
2045 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02002046 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_01125, "IMAGE", str, i,
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07002047 validation_error_map[VALIDATION_ERROR_01125]);
2048 }
2049 } else { // Must be depth and/or stencil
2050 if (((clear_desc->aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) != VK_IMAGE_ASPECT_DEPTH_BIT) &&
2051 ((clear_desc->aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) != VK_IMAGE_ASPECT_STENCIL_BIT)) {
2052 char const str[] = "vkCmdClearAttachments aspectMask [%d] is not a valid combination of bits. %s";
2053 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02002054 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_01127, "IMAGE", str, i,
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07002055 validation_error_map[VALIDATION_ERROR_01127]);
2056 }
2057 if (!subpass_desc->pDepthStencilAttachment ||
2058 (subpass_desc->pDepthStencilAttachment->attachment == VK_ATTACHMENT_UNUSED)) {
2059 skip |= log_msg(
2060 report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02002061 HandleToUint64(commandBuffer), __LINE__, DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS",
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07002062 "vkCmdClearAttachments() depth/stencil clear with no depth/stencil attachment in subpass; ignored");
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002063 } else {
2064 image_view = framebuffer->createInfo.pAttachments[subpass_desc->pDepthStencilAttachment->attachment];
2065 }
2066 }
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002067 if (image_view) {
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07002068 auto image_view_state = GetImageViewState(device_data, image_view);
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002069 for (uint32_t j = 0; j < rectCount; j++) {
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07002070 // The rectangular region specified by a given element of pRects must be contained within the render area of
2071 // the current render pass instance
Mark Lobodzinskid833bb72017-02-22 10:55:30 -07002072 // TODO: This check should be moved to CmdExecuteCommands or QueueSubmit to cover secondary CB cases
2073 if ((cb_node->createInfo.level == VK_COMMAND_BUFFER_LEVEL_PRIMARY) &&
2074 (false == ContainsRect(cb_node->activeRenderPassBeginInfo.renderArea, pRects[j].rect))) {
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06002075 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02002076 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_01115, "DS",
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07002077 "vkCmdClearAttachments(): The area defined by pRects[%d] is not contained in the area of "
2078 "the current render pass instance. %s",
2079 j, validation_error_map[VALIDATION_ERROR_01115]);
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002080 }
2081 // The layers specified by a given element of pRects must be contained within every attachment that
2082 // pAttachments refers to
2083 auto attachment_base_array_layer = image_view_state->create_info.subresourceRange.baseArrayLayer;
2084 auto attachment_layer_count = image_view_state->create_info.subresourceRange.layerCount;
2085 if ((pRects[j].baseArrayLayer < attachment_base_array_layer) || pRects[j].layerCount > attachment_layer_count) {
2086 skip |=
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06002087 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02002088 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_01116, "DS",
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07002089 "vkCmdClearAttachments(): The layers defined in pRects[%d] are not contained in the layers of "
2090 "pAttachment[%d]. %s",
2091 j, i, validation_error_map[VALIDATION_ERROR_01116]);
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002092 }
2093 }
2094 }
2095 }
2096 }
2097 return skip;
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07002098}
2099
Tobin Ehlis58c884f2017-02-08 12:15:27 -07002100bool PreCallValidateCmdResolveImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state,
Mark Lobodzinski50fbef12017-02-06 15:31:33 -07002101 IMAGE_STATE *dst_image_state, uint32_t regionCount, const VkImageResolve *pRegions) {
Mark Lobodzinski2a3368e2017-02-06 15:29:37 -07002102 const debug_report_data *report_data = core_validation::GetReportData(device_data);
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07002103 bool skip = false;
2104 if (cb_node && src_image_state && dst_image_state) {
2105 skip |= ValidateMemoryIsBoundToImage(device_data, src_image_state, "vkCmdResolveImage()", VALIDATION_ERROR_02541);
2106 skip |= ValidateMemoryIsBoundToImage(device_data, dst_image_state, "vkCmdResolveImage()", VALIDATION_ERROR_02542);
Mike Schuchardt9c582402017-02-23 15:57:37 -07002107 skip |= ValidateCmdQueueFlags(device_data, cb_node, "vkCmdResolveImage()", VK_QUEUE_GRAPHICS_BIT, VALIDATION_ERROR_01334);
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07002108 skip |= ValidateCmd(device_data, cb_node, CMD_RESOLVEIMAGE, "vkCmdResolveImage()");
2109 skip |= insideRenderPass(device_data, cb_node, "vkCmdResolveImage()", VALIDATION_ERROR_01335);
Mark Lobodzinski2a3368e2017-02-06 15:29:37 -07002110
2111 // For each region, the number of layers in the image subresource should not be zero
2112 // For each region, src and dest image aspect must be color only
2113 for (uint32_t i = 0; i < regionCount; i++) {
2114 if (pRegions[i].srcSubresource.layerCount == 0) {
2115 char const str[] = "vkCmdResolveImage: number of layers in source subresource is zero";
Mark Lobodzinski50fbef12017-02-06 15:31:33 -07002116 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02002117 HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_ASPECT, "IMAGE", str);
Mark Lobodzinski2a3368e2017-02-06 15:29:37 -07002118 }
Mark Lobodzinski2a3368e2017-02-06 15:29:37 -07002119 if (pRegions[i].dstSubresource.layerCount == 0) {
2120 char const str[] = "vkCmdResolveImage: number of layers in destination subresource is zero";
Mark Lobodzinski50fbef12017-02-06 15:31:33 -07002121 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02002122 HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_ASPECT, "IMAGE", str);
Mark Lobodzinski2a3368e2017-02-06 15:29:37 -07002123 }
Mark Lobodzinski50fbef12017-02-06 15:31:33 -07002124 if (pRegions[i].srcSubresource.layerCount != pRegions[i].dstSubresource.layerCount) {
2125 skip |= log_msg(
2126 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02002127 HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_01339, "IMAGE",
Mark Lobodzinski50fbef12017-02-06 15:31:33 -07002128 "vkCmdResolveImage: layerCount in source and destination subresource of pRegions[%d] does not match. %s", i,
2129 validation_error_map[VALIDATION_ERROR_01339]);
2130 }
Mark Lobodzinski2a3368e2017-02-06 15:29:37 -07002131 if ((pRegions[i].srcSubresource.aspectMask != VK_IMAGE_ASPECT_COLOR_BIT) ||
2132 (pRegions[i].dstSubresource.aspectMask != VK_IMAGE_ASPECT_COLOR_BIT)) {
2133 char const str[] =
2134 "vkCmdResolveImage: src and dest aspectMasks for each region must specify only VK_IMAGE_ASPECT_COLOR_BIT";
2135 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02002136 HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_01338, "IMAGE", "%s. %s", str,
2137 validation_error_map[VALIDATION_ERROR_01338]);
Mark Lobodzinski2a3368e2017-02-06 15:29:37 -07002138 }
2139 }
2140
2141 if (src_image_state->createInfo.format != dst_image_state->createInfo.format) {
2142 char const str[] = "vkCmdResolveImage called with unmatched source and dest formats.";
Mark Lobodzinski50fbef12017-02-06 15:31:33 -07002143 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02002144 HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_FORMAT, "IMAGE", str);
Mark Lobodzinski2a3368e2017-02-06 15:29:37 -07002145 }
2146 if (src_image_state->createInfo.imageType != dst_image_state->createInfo.imageType) {
2147 char const str[] = "vkCmdResolveImage called with unmatched source and dest image types.";
Mark Lobodzinski50fbef12017-02-06 15:31:33 -07002148 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02002149 HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_TYPE, "IMAGE", str);
Mark Lobodzinski2a3368e2017-02-06 15:29:37 -07002150 }
2151 if (src_image_state->createInfo.samples == VK_SAMPLE_COUNT_1_BIT) {
2152 char const str[] = "vkCmdResolveImage called with source sample count less than 2.";
2153 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02002154 HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_01320, "IMAGE", "%s. %s", str,
2155 validation_error_map[VALIDATION_ERROR_01320]);
Mark Lobodzinski2a3368e2017-02-06 15:29:37 -07002156 }
2157 if (dst_image_state->createInfo.samples != VK_SAMPLE_COUNT_1_BIT) {
2158 char const str[] = "vkCmdResolveImage called with dest sample count greater than 1.";
2159 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02002160 HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_01321, "IMAGE", "%s. %s", str,
2161 validation_error_map[VALIDATION_ERROR_01321]);
Mark Lobodzinski2a3368e2017-02-06 15:29:37 -07002162 }
Tobin Ehlisbb03e5f2017-05-11 08:52:51 -06002163 // TODO: Need to validate image layouts, which will include layout validation for shared presentable images
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07002164 } else {
2165 assert(0);
2166 }
2167 return skip;
2168}
2169
Tobin Ehlis58c884f2017-02-08 12:15:27 -07002170void PreCallRecordCmdResolveImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state,
2171 IMAGE_STATE *dst_image_state) {
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07002172 // Update bindings between images and cmd buffer
2173 AddCommandBufferBindingImage(device_data, cb_node, src_image_state);
2174 AddCommandBufferBindingImage(device_data, cb_node, dst_image_state);
2175
2176 std::function<bool()> function = [=]() {
2177 return ValidateImageMemoryIsValid(device_data, src_image_state, "vkCmdResolveImage()");
2178 };
2179 cb_node->validate_functions.push_back(function);
2180 function = [=]() {
2181 SetImageMemoryValid(device_data, dst_image_state, true);
2182 return false;
2183 };
2184 cb_node->validate_functions.push_back(function);
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07002185 core_validation::UpdateCmdBufferLastCmd(cb_node, CMD_RESOLVEIMAGE);
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07002186}
2187
Tobin Ehlis58c884f2017-02-08 12:15:27 -07002188bool PreCallValidateCmdBlitImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state,
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002189 IMAGE_STATE *dst_image_state, uint32_t regionCount, const VkImageBlit *pRegions, VkFilter filter) {
2190 const debug_report_data *report_data = core_validation::GetReportData(device_data);
2191
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07002192 bool skip = false;
2193 if (cb_node && src_image_state && dst_image_state) {
2194 skip |= ValidateImageSampleCount(device_data, src_image_state, VK_SAMPLE_COUNT_1_BIT, "vkCmdBlitImage(): srcImage",
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002195 VALIDATION_ERROR_02194);
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07002196 skip |= ValidateImageSampleCount(device_data, dst_image_state, VK_SAMPLE_COUNT_1_BIT, "vkCmdBlitImage(): dstImage",
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002197 VALIDATION_ERROR_02195);
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07002198 skip |= ValidateMemoryIsBoundToImage(device_data, src_image_state, "vkCmdBlitImage()", VALIDATION_ERROR_02539);
2199 skip |= ValidateMemoryIsBoundToImage(device_data, dst_image_state, "vkCmdBlitImage()", VALIDATION_ERROR_02540);
2200 skip |= ValidateImageUsageFlags(device_data, src_image_state, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, true, VALIDATION_ERROR_02182,
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002201 "vkCmdBlitImage()", "VK_IMAGE_USAGE_TRANSFER_SRC_BIT");
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07002202 skip |= ValidateImageUsageFlags(device_data, dst_image_state, VK_IMAGE_USAGE_TRANSFER_DST_BIT, true, VALIDATION_ERROR_02186,
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002203 "vkCmdBlitImage()", "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Mike Schuchardt9c582402017-02-23 15:57:37 -07002204 skip |= ValidateCmdQueueFlags(device_data, cb_node, "vkCmdBlitImage()", VK_QUEUE_GRAPHICS_BIT, VALIDATION_ERROR_01299);
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07002205 skip |= ValidateCmd(device_data, cb_node, CMD_BLITIMAGE, "vkCmdBlitImage()");
2206 skip |= insideRenderPass(device_data, cb_node, "vkCmdBlitImage()", VALIDATION_ERROR_01300);
Tobin Ehlisbb03e5f2017-05-11 08:52:51 -06002207 // TODO: Need to validate image layouts, which will include layout validation for shared presentable images
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002208
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002209 for (uint32_t i = 0; i < regionCount; i++) {
Mark Lobodzinski23c81142017-02-06 15:04:23 -07002210 // Warn for zero-sized regions
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002211 if ((pRegions[i].srcOffsets[0].x == pRegions[i].srcOffsets[1].x) ||
2212 (pRegions[i].srcOffsets[0].y == pRegions[i].srcOffsets[1].y) ||
2213 (pRegions[i].srcOffsets[0].z == pRegions[i].srcOffsets[1].z)) {
2214 std::stringstream ss;
2215 ss << "vkCmdBlitImage: pRegions[" << i << "].srcOffsets specify a zero-volume area.";
2216 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02002217 HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_INVALID_EXTENTS, "IMAGE", "%s",
2218 ss.str().c_str());
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002219 }
2220 if ((pRegions[i].dstOffsets[0].x == pRegions[i].dstOffsets[1].x) ||
2221 (pRegions[i].dstOffsets[0].y == pRegions[i].dstOffsets[1].y) ||
2222 (pRegions[i].dstOffsets[0].z == pRegions[i].dstOffsets[1].z)) {
2223 std::stringstream ss;
2224 ss << "vkCmdBlitImage: pRegions[" << i << "].dstOffsets specify a zero-volume area.";
2225 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02002226 HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_INVALID_EXTENTS, "IMAGE", "%s",
2227 ss.str().c_str());
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002228 }
Mark Lobodzinski23c81142017-02-06 15:04:23 -07002229 if (pRegions[i].srcSubresource.layerCount == 0) {
2230 char const str[] = "vkCmdBlitImage: number of layers in source subresource is zero";
2231 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02002232 HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_ASPECT, "IMAGE", str);
Mark Lobodzinski23c81142017-02-06 15:04:23 -07002233 }
2234 if (pRegions[i].dstSubresource.layerCount == 0) {
2235 char const str[] = "vkCmdBlitImage: number of layers in destination subresource is zero";
2236 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02002237 HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_ASPECT, "IMAGE", str);
Mark Lobodzinski23c81142017-02-06 15:04:23 -07002238 }
2239
2240 // Check that src/dst layercounts match
2241 if (pRegions[i].srcSubresource.layerCount != pRegions[i].dstSubresource.layerCount) {
2242 skip |=
2243 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02002244 HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_01304, "IMAGE",
Mark Lobodzinski23c81142017-02-06 15:04:23 -07002245 "vkCmdBlitImage: layerCount in source and destination subresource of pRegions[%d] does not match. %s",
2246 i, validation_error_map[VALIDATION_ERROR_01304]);
2247 }
Mark Lobodzinskie7e85fd2017-02-07 13:44:57 -07002248
2249 if (pRegions[i].srcSubresource.aspectMask != pRegions[i].dstSubresource.aspectMask) {
2250 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02002251 HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_01303, "IMAGE",
Mark Lobodzinskie7e85fd2017-02-07 13:44:57 -07002252 "vkCmdBlitImage: aspectMask members for pRegion[%d] do not match. %s", i,
2253 validation_error_map[VALIDATION_ERROR_01303]);
2254 }
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002255 }
2256
2257 VkFormat src_format = src_image_state->createInfo.format;
2258 VkFormat dst_format = dst_image_state->createInfo.format;
2259
2260 // Validate consistency for unsigned formats
Dave Houlton1d2022c2017-03-29 11:43:58 -06002261 if (FormatIsUInt(src_format) != FormatIsUInt(dst_format)) {
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002262 std::stringstream ss;
2263 ss << "vkCmdBlitImage: If one of srcImage and dstImage images has unsigned integer format, "
2264 << "the other one must also have unsigned integer format. "
2265 << "Source format is " << string_VkFormat(src_format) << " Destination format is " << string_VkFormat(dst_format);
2266 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02002267 HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_02191, "IMAGE", "%s. %s",
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002268 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_02191]);
2269 }
2270
2271 // Validate consistency for signed formats
Dave Houlton1d2022c2017-03-29 11:43:58 -06002272 if (FormatIsSInt(src_format) != FormatIsSInt(dst_format)) {
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002273 std::stringstream ss;
2274 ss << "vkCmdBlitImage: If one of srcImage and dstImage images has signed integer format, "
2275 << "the other one must also have signed integer format. "
2276 << "Source format is " << string_VkFormat(src_format) << " Destination format is " << string_VkFormat(dst_format);
2277 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02002278 HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_02190, "IMAGE", "%s. %s",
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002279 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_02190]);
2280 }
2281
2282 // Validate aspect bits and formats for depth/stencil images
Dave Houlton1d2022c2017-03-29 11:43:58 -06002283 if (FormatIsDepthOrStencil(src_format) || FormatIsDepthOrStencil(dst_format)) {
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002284 if (src_format != dst_format) {
2285 std::stringstream ss;
2286 ss << "vkCmdBlitImage: If one of srcImage and dstImage images has a format of depth, stencil or depth "
2287 << "stencil, the other one must have exactly the same format. "
2288 << "Source format is " << string_VkFormat(src_format) << " Destination format is "
2289 << string_VkFormat(dst_format);
2290 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02002291 HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_02192, "IMAGE", "%s. %s",
2292 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_02192]);
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002293 }
2294
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002295 for (uint32_t i = 0; i < regionCount; i++) {
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002296 VkImageAspectFlags srcAspect = pRegions[i].srcSubresource.aspectMask;
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002297
Dave Houlton1d2022c2017-03-29 11:43:58 -06002298 if (FormatIsDepthAndStencil(src_format)) {
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002299 if ((srcAspect != VK_IMAGE_ASPECT_DEPTH_BIT) && (srcAspect != VK_IMAGE_ASPECT_STENCIL_BIT)) {
2300 std::stringstream ss;
2301 ss << "vkCmdBlitImage: Combination depth/stencil image formats must have only one of "
2302 "VK_IMAGE_ASPECT_DEPTH_BIT "
2303 << "and VK_IMAGE_ASPECT_STENCIL_BIT set in srcImage and dstImage";
2304 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02002305 HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE",
2306 "%s", ss.str().c_str());
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002307 }
Dave Houlton1d2022c2017-03-29 11:43:58 -06002308 } else if (FormatIsStencilOnly(src_format)) {
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002309 if (srcAspect != VK_IMAGE_ASPECT_STENCIL_BIT) {
2310 std::stringstream ss;
2311 ss << "vkCmdBlitImage: Stencil-only image formats must have only the VK_IMAGE_ASPECT_STENCIL_BIT "
2312 << "set in both the srcImage and dstImage";
2313 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02002314 HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE",
2315 "%s", ss.str().c_str());
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002316 }
Dave Houlton1d2022c2017-03-29 11:43:58 -06002317 } else if (FormatIsDepthOnly(src_format)) {
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002318 if (srcAspect != VK_IMAGE_ASPECT_DEPTH_BIT) {
2319 std::stringstream ss;
2320 ss << "vkCmdBlitImage: Depth-only image formats must have only the VK_IMAGE_ASPECT_DEPTH "
2321 << "set in both the srcImage and dstImage";
2322 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02002323 HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE",
2324 "%s", ss.str().c_str());
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002325 }
2326 }
2327 }
2328 }
2329
2330 // Validate filter
Dave Houlton1d2022c2017-03-29 11:43:58 -06002331 if (FormatIsDepthOrStencil(src_format) && (filter != VK_FILTER_NEAREST)) {
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002332 std::stringstream ss;
2333 ss << "vkCmdBlitImage: If the format of srcImage is a depth, stencil, or depth stencil "
2334 << "then filter must be VK_FILTER_NEAREST.";
2335 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02002336 HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_02193, "IMAGE", "%s. %s",
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002337 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_02193]);
2338 }
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07002339 } else {
2340 assert(0);
2341 }
2342 return skip;
2343}
2344
Tobin Ehlis58c884f2017-02-08 12:15:27 -07002345void PreCallRecordCmdBlitImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state,
2346 IMAGE_STATE *dst_image_state) {
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07002347 // Update bindings between images and cmd buffer
2348 AddCommandBufferBindingImage(device_data, cb_node, src_image_state);
2349 AddCommandBufferBindingImage(device_data, cb_node, dst_image_state);
2350
2351 std::function<bool()> function = [=]() { return ValidateImageMemoryIsValid(device_data, src_image_state, "vkCmdBlitImage()"); };
2352 cb_node->validate_functions.push_back(function);
2353 function = [=]() {
2354 SetImageMemoryValid(device_data, dst_image_state, true);
2355 return false;
2356 };
2357 cb_node->validate_functions.push_back(function);
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07002358 core_validation::UpdateCmdBufferLastCmd(cb_node, CMD_BLITIMAGE);
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07002359}
2360
Tony Barbourdf013b92017-01-25 12:53:48 -07002361// This validates that the initial layout specified in the command buffer for
2362// the IMAGE is the same
2363// as the global IMAGE layout
Tony Barboure0c5cc92017-02-08 13:53:39 -07002364bool ValidateCmdBufImageLayouts(layer_data *device_data, GLOBAL_CB_NODE *pCB,
2365 std::unordered_map<ImageSubresourcePair, IMAGE_LAYOUT_NODE> &imageLayoutMap) {
Mark Lobodzinskib0dd9472017-02-07 16:38:17 -07002366 bool skip = false;
Tony Barbourdf013b92017-01-25 12:53:48 -07002367 const debug_report_data *report_data = core_validation::GetReportData(device_data);
Mark Lobodzinski4a3065e2017-02-07 16:36:03 -07002368 for (auto cb_image_data : pCB->imageLayoutMap) {
2369 VkImageLayout imageLayout;
Tony Barbourdf013b92017-01-25 12:53:48 -07002370
Jeremy Hayes55b6c292017-02-28 09:44:45 -07002371 if (FindLayout(imageLayoutMap, cb_image_data.first, imageLayout)) {
Mark Lobodzinski4a3065e2017-02-07 16:36:03 -07002372 if (cb_image_data.second.initialLayout == VK_IMAGE_LAYOUT_UNDEFINED) {
2373 // TODO: Set memory invalid which is in mem_tracker currently
2374 } else if (imageLayout != cb_image_data.second.initialLayout) {
2375 if (cb_image_data.first.hasSubresource) {
Petr Krausbc7f5442017-05-14 23:43:38 +02002376 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2377 HandleToUint64(pCB->commandBuffer), __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
2378 "Cannot submit cmd buffer using image (0x%" PRIx64
2379 ") [sub-resource: aspectMask 0x%X array layer %u, mip level %u], "
2380 "with layout %s when first use is %s.",
2381 HandleToUint64(cb_image_data.first.image), cb_image_data.first.subresource.aspectMask,
2382 cb_image_data.first.subresource.arrayLayer, cb_image_data.first.subresource.mipLevel,
2383 string_VkImageLayout(imageLayout), string_VkImageLayout(cb_image_data.second.initialLayout));
Mark Lobodzinski4a3065e2017-02-07 16:36:03 -07002384 } else {
Petr Krausbc7f5442017-05-14 23:43:38 +02002385 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2386 HandleToUint64(pCB->commandBuffer), __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
2387 "Cannot submit cmd buffer using image (0x%" PRIx64
2388 ") with layout %s when "
2389 "first use is %s.",
2390 HandleToUint64(cb_image_data.first.image), string_VkImageLayout(imageLayout),
2391 string_VkImageLayout(cb_image_data.second.initialLayout));
Mark Lobodzinski4a3065e2017-02-07 16:36:03 -07002392 }
2393 }
Tony Barbourdf013b92017-01-25 12:53:48 -07002394 SetLayout(imageLayoutMap, cb_image_data.first, cb_image_data.second.layout);
Mark Lobodzinski4a3065e2017-02-07 16:36:03 -07002395 }
2396 }
Mark Lobodzinskib0dd9472017-02-07 16:38:17 -07002397 return skip;
Mark Lobodzinski4a3065e2017-02-07 16:36:03 -07002398}
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002399
Tony Barbourdf013b92017-01-25 12:53:48 -07002400void UpdateCmdBufImageLayouts(layer_data *device_data, GLOBAL_CB_NODE *pCB) {
2401 for (auto cb_image_data : pCB->imageLayoutMap) {
2402 VkImageLayout imageLayout;
2403 FindGlobalLayout(device_data, cb_image_data.first, imageLayout);
2404 SetGlobalLayout(device_data, cb_image_data.first, cb_image_data.second.layout);
2405 }
2406}
2407
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002408// Print readable FlagBits in FlagMask
2409static std::string string_VkAccessFlags(VkAccessFlags accessMask) {
2410 std::string result;
2411 std::string separator;
2412
2413 if (accessMask == 0) {
2414 result = "[None]";
2415 } else {
2416 result = "[";
2417 for (auto i = 0; i < 32; i++) {
2418 if (accessMask & (1 << i)) {
2419 result = result + separator + string_VkAccessFlagBits((VkAccessFlagBits)(1 << i));
2420 separator = " | ";
2421 }
2422 }
2423 result = result + "]";
2424 }
2425 return result;
2426}
2427
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002428// AccessFlags MUST have 'required_bit' set, and may have one or more of 'optional_bits' set. If required_bit is zero, accessMask
2429// must have at least one of 'optional_bits' set
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002430// TODO: Add tracking to ensure that at least one barrier has been set for these layout transitions
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002431static bool ValidateMaskBits(core_validation::layer_data *device_data, VkCommandBuffer cmdBuffer, const VkAccessFlags &accessMask,
2432 const VkImageLayout &layout, VkAccessFlags required_bit, VkAccessFlags optional_bits,
2433 const char *type) {
2434 const debug_report_data *report_data = core_validation::GetReportData(device_data);
2435 bool skip = false;
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002436
2437 if ((accessMask & required_bit) || (!required_bit && (accessMask & optional_bits))) {
2438 if (accessMask & ~(required_bit | optional_bits)) {
2439 // TODO: Verify against Valid Use
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06002440 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02002441 HandleToUint64(cmdBuffer), __LINE__, DRAWSTATE_INVALID_BARRIER, "DS",
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002442 "Additional bits in %s accessMask 0x%X %s are specified when layout is %s.", type, accessMask,
2443 string_VkAccessFlags(accessMask).c_str(), string_VkImageLayout(layout));
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002444 }
2445 } else {
2446 if (!required_bit) {
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06002447 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02002448 HandleToUint64(cmdBuffer), __LINE__, DRAWSTATE_INVALID_BARRIER, "DS",
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002449 "%s AccessMask %d %s must contain at least one of access bits %d "
2450 "%s when layout is %s, unless the app has previously added a "
2451 "barrier for this transition.",
2452 type, accessMask, string_VkAccessFlags(accessMask).c_str(), optional_bits,
2453 string_VkAccessFlags(optional_bits).c_str(), string_VkImageLayout(layout));
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002454 } else {
2455 std::string opt_bits;
2456 if (optional_bits != 0) {
2457 std::stringstream ss;
2458 ss << optional_bits;
2459 opt_bits = "and may have optional bits " + ss.str() + ' ' + string_VkAccessFlags(optional_bits);
2460 }
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06002461 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02002462 HandleToUint64(cmdBuffer), __LINE__, DRAWSTATE_INVALID_BARRIER, "DS",
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002463 "%s AccessMask %d %s must have required access bit %d %s %s when "
2464 "layout is %s, unless the app has previously added a barrier for "
2465 "this transition.",
2466 type, accessMask, string_VkAccessFlags(accessMask).c_str(), required_bit,
2467 string_VkAccessFlags(required_bit).c_str(), opt_bits.c_str(), string_VkImageLayout(layout));
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002468 }
2469 }
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002470 return skip;
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002471}
2472
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002473bool ValidateMaskBitsFromLayouts(core_validation::layer_data *device_data, VkCommandBuffer cmdBuffer,
2474 const VkAccessFlags &accessMask, const VkImageLayout &layout, const char *type) {
2475 const debug_report_data *report_data = core_validation::GetReportData(device_data);
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002476
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002477 bool skip = false;
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002478 switch (layout) {
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002479 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: {
2480 skip |= ValidateMaskBits(device_data, cmdBuffer, accessMask, layout, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2481 VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT, type);
2482 break;
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002483 }
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002484 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: {
2485 skip |= ValidateMaskBits(device_data, cmdBuffer, accessMask, layout, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
2486 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT, type);
2487 break;
2488 }
2489 case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL: {
2490 skip |= ValidateMaskBits(device_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_WRITE_BIT, 0, type);
2491 break;
2492 }
2493 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: {
2494 skip |= ValidateMaskBits(
2495 device_data, cmdBuffer, accessMask, layout, 0,
2496 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
2497 type);
2498 break;
2499 }
2500 case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: {
2501 skip |= ValidateMaskBits(device_data, cmdBuffer, accessMask, layout, 0,
2502 VK_ACCESS_INPUT_ATTACHMENT_READ_BIT | VK_ACCESS_SHADER_READ_BIT, type);
2503 break;
2504 }
2505 case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL: {
2506 skip |= ValidateMaskBits(device_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_READ_BIT, 0, type);
2507 break;
2508 }
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002509 case VK_IMAGE_LAYOUT_UNDEFINED: {
2510 if (accessMask != 0) {
2511 // TODO: Verify against Valid Use section spec
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06002512 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02002513 HandleToUint64(cmdBuffer), __LINE__, DRAWSTATE_INVALID_BARRIER, "DS",
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002514 "Additional bits in %s accessMask 0x%X %s are specified when layout is %s.", type, accessMask,
2515 string_VkAccessFlags(accessMask).c_str(), string_VkImageLayout(layout));
2516 }
2517 break;
2518 }
Chris Forbesbfd831d2017-04-28 17:29:10 -07002519 case VK_IMAGE_LAYOUT_PRESENT_SRC_KHR:
Dave Houlton1150cf52017-04-27 14:38:11 -06002520 // Notes: QueuePresentKHR performs automatic visibility operations,
2521 // so the app is /NOT/ required to include VK_ACCESS_MEMORY_READ_BIT
2522 // when transitioning to this layout.
2523 //
2524 // When transitioning /from/ this layout, the application needs to
2525 // avoid only a WAR hazard -- any writes need to be ordered after
2526 // the PE's reads. There is no need for a memory dependency for this
2527 // case.
Mark Lobodzinski087380c2017-05-16 14:42:25 -06002528 // Intentionally fall through
2529
2530 case VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR:
2531 // Todo -- shouldn't be valid unless extension is enabled
2532 // Intentionally fall through
Chris Forbesbfd831d2017-04-28 17:29:10 -07002533
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002534 case VK_IMAGE_LAYOUT_GENERAL:
2535 default: { break; }
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002536 }
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002537 return skip;
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002538}
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002539
2540// ValidateLayoutVsAttachmentDescription is a general function where we can validate various state associated with the
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002541// VkAttachmentDescription structs that are used by the sub-passes of a renderpass. Initial check is to make sure that READ_ONLY
2542// layout attachments don't have CLEAR as their loadOp.
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002543bool ValidateLayoutVsAttachmentDescription(const debug_report_data *report_data, const VkImageLayout first_layout,
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002544 const uint32_t attachment, const VkAttachmentDescription &attachment_description) {
2545 bool skip = false;
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002546 // Verify that initial loadOp on READ_ONLY attachments is not CLEAR
2547 if (attachment_description.loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR) {
2548 if ((first_layout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL) ||
2549 (first_layout == VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL)) {
Mark Lobodzinskieb9e73f2017-04-13 10:06:48 -06002550 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2551 VALIDATION_ERROR_02351, "DS", "Cannot clear attachment %d with invalid first layout %s. %s", attachment,
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002552 string_VkImageLayout(first_layout), validation_error_map[VALIDATION_ERROR_02351]);
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002553 }
2554 }
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002555 return skip;
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002556}
2557
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002558bool ValidateLayouts(core_validation::layer_data *device_data, VkDevice device, const VkRenderPassCreateInfo *pCreateInfo) {
2559 const debug_report_data *report_data = core_validation::GetReportData(device_data);
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002560 bool skip = false;
2561
2562 // Track when we're observing the first use of an attachment
2563 std::vector<bool> attach_first_use(pCreateInfo->attachmentCount, true);
2564 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
2565 const VkSubpassDescription &subpass = pCreateInfo->pSubpasses[i];
Cort Stratton7547f772017-05-04 15:18:52 -07002566
2567 // Check input attachments first, so we can detect first-use-as-input for VU #00349
2568 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
2569 auto attach_index = subpass.pInputAttachments[j].attachment;
2570 if (attach_index == VK_ATTACHMENT_UNUSED) continue;
2571
2572 switch (subpass.pInputAttachments[j].layout) {
2573 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL:
2574 case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL:
2575 // These are ideal.
2576 break;
2577
2578 case VK_IMAGE_LAYOUT_GENERAL:
2579 // May not be optimal. TODO: reconsider this warning based on other constraints.
2580 skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
2581 VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
2582 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
2583 break;
2584
2585 default:
2586 // No other layouts are acceptable
2587 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2588 __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
2589 "Layout for input attachment is %s but can only be READ_ONLY_OPTIMAL or GENERAL.",
2590 string_VkImageLayout(subpass.pInputAttachments[j].layout));
2591 }
2592
2593 VkImageLayout layout = subpass.pInputAttachments[j].layout;
2594 bool found_layout_mismatch = subpass.pDepthStencilAttachment &&
2595 subpass.pDepthStencilAttachment->attachment == attach_index &&
2596 subpass.pDepthStencilAttachment->layout != layout;
2597 for (uint32_t c = 0; !found_layout_mismatch && c < subpass.colorAttachmentCount; ++c) {
2598 found_layout_mismatch =
2599 (subpass.pColorAttachments[c].attachment == attach_index && subpass.pColorAttachments[c].layout != layout);
2600 }
2601 if (found_layout_mismatch) {
2602 skip |= log_msg(
2603 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2604 VALIDATION_ERROR_00358, "DS",
2605 "CreateRenderPass: Subpass %u pInputAttachments[%u] (%u) has layout %u, but is also used as a depth/color "
2606 "attachment with a different layout. %s",
2607 i, j, attach_index, layout, validation_error_map[VALIDATION_ERROR_00358]);
2608 }
2609
2610 if (attach_first_use[attach_index]) {
2611 skip |= ValidateLayoutVsAttachmentDescription(report_data, subpass.pInputAttachments[j].layout, attach_index,
2612 pCreateInfo->pAttachments[attach_index]);
2613
2614 bool used_as_depth =
2615 (subpass.pDepthStencilAttachment != NULL && subpass.pDepthStencilAttachment->attachment == attach_index);
2616 bool used_as_color = false;
2617 for (uint32_t k = 0; !used_as_depth && !used_as_color && k < subpass.colorAttachmentCount; ++k) {
2618 used_as_color = (subpass.pColorAttachments[k].attachment == attach_index);
2619 }
2620 if (!used_as_depth && !used_as_color &&
2621 pCreateInfo->pAttachments[attach_index].loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR) {
2622 skip |= log_msg(
2623 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2624 VALIDATION_ERROR_00349, "DS",
2625 "CreateRenderPass: attachment %u is first used as an input attachment in subpass %u with loadOp=CLEAR. %s",
2626 attach_index, attach_index, validation_error_map[VALIDATION_ERROR_00349]);
2627 }
2628 }
2629 attach_first_use[attach_index] = false;
2630 }
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002631 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
2632 auto attach_index = subpass.pColorAttachments[j].attachment;
2633 if (attach_index == VK_ATTACHMENT_UNUSED) continue;
2634
Tobin Ehlisbb03e5f2017-05-11 08:52:51 -06002635 // TODO: Need a way to validate shared presentable images here, currently just allowing
2636 // VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR
2637 // as an acceptable layout, but need to make sure shared presentable images ONLY use that layout
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002638 switch (subpass.pColorAttachments[j].layout) {
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002639 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL:
2640 // This is ideal.
Tobin Ehlisbb03e5f2017-05-11 08:52:51 -06002641 case VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR:
2642 // TODO: See note above, just assuming that attachment is shared presentable and allowing this for now.
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002643 break;
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002644
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002645 case VK_IMAGE_LAYOUT_GENERAL:
2646 // May not be optimal; TODO: reconsider this warning based on other constraints?
2647 skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
2648 VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
2649 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
2650 break;
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002651
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002652 default:
2653 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2654 __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
2655 "Layout for color attachment is %s but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.",
2656 string_VkImageLayout(subpass.pColorAttachments[j].layout));
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002657 }
2658
2659 if (attach_first_use[attach_index]) {
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002660 skip |= ValidateLayoutVsAttachmentDescription(report_data, subpass.pColorAttachments[j].layout, attach_index,
2661 pCreateInfo->pAttachments[attach_index]);
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002662 }
2663 attach_first_use[attach_index] = false;
2664 }
2665 if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
2666 switch (subpass.pDepthStencilAttachment->layout) {
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002667 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
2668 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL:
2669 // These are ideal.
2670 break;
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002671
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002672 case VK_IMAGE_LAYOUT_GENERAL:
2673 // May not be optimal; TODO: reconsider this warning based on other constraints? GENERAL can be better than
2674 // doing a bunch of transitions.
2675 skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
2676 VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
2677 "GENERAL layout for depth attachment may not give optimal performance.");
2678 break;
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002679
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002680 default:
2681 // No other layouts are acceptable
2682 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2683 __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
2684 "Layout for depth attachment is %s but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL, "
2685 "DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.",
2686 string_VkImageLayout(subpass.pDepthStencilAttachment->layout));
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002687 }
2688
2689 auto attach_index = subpass.pDepthStencilAttachment->attachment;
2690 if (attach_first_use[attach_index]) {
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002691 skip |= ValidateLayoutVsAttachmentDescription(report_data, subpass.pDepthStencilAttachment->layout, attach_index,
2692 pCreateInfo->pAttachments[attach_index]);
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002693 }
2694 attach_first_use[attach_index] = false;
2695 }
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002696 }
2697 return skip;
2698}
Mark Lobodzinski08f14fa2017-02-07 17:20:06 -07002699
2700// For any image objects that overlap mapped memory, verify that their layouts are PREINIT or GENERAL
Mark Lobodzinskiac23ec82017-02-07 17:21:55 -07002701bool ValidateMapImageLayouts(core_validation::layer_data *device_data, VkDevice device, DEVICE_MEM_INFO const *mem_info,
2702 VkDeviceSize offset, VkDeviceSize end_offset) {
2703 const debug_report_data *report_data = core_validation::GetReportData(device_data);
2704 bool skip = false;
2705 // Iterate over all bound image ranges and verify that for any that overlap the map ranges, the layouts are
2706 // VK_IMAGE_LAYOUT_PREINITIALIZED or VK_IMAGE_LAYOUT_GENERAL
Mark Lobodzinski08f14fa2017-02-07 17:20:06 -07002707 // TODO : This can be optimized if we store ranges based on starting address and early exit when we pass our range
2708 for (auto image_handle : mem_info->bound_images) {
2709 auto img_it = mem_info->bound_ranges.find(image_handle);
2710 if (img_it != mem_info->bound_ranges.end()) {
Mark Lobodzinskiac23ec82017-02-07 17:21:55 -07002711 if (rangesIntersect(device_data, &img_it->second, offset, end_offset)) {
Mark Lobodzinski08f14fa2017-02-07 17:20:06 -07002712 std::vector<VkImageLayout> layouts;
Mark Lobodzinskiac23ec82017-02-07 17:21:55 -07002713 if (FindLayouts(device_data, VkImage(image_handle), layouts)) {
Mark Lobodzinski08f14fa2017-02-07 17:20:06 -07002714 for (auto layout : layouts) {
2715 if (layout != VK_IMAGE_LAYOUT_PREINITIALIZED && layout != VK_IMAGE_LAYOUT_GENERAL) {
Petr Krausbc7f5442017-05-14 23:43:38 +02002716 skip |=
2717 log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_MEMORY_EXT,
2718 HandleToUint64(mem_info->mem), __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
2719 "Mapping an image with layout %s can result in undefined behavior if this memory is "
2720 "used by the device. Only GENERAL or PREINITIALIZED should be used.",
2721 string_VkImageLayout(layout));
Mark Lobodzinski08f14fa2017-02-07 17:20:06 -07002722 }
2723 }
2724 }
2725 }
2726 }
2727 }
Mark Lobodzinskiac23ec82017-02-07 17:21:55 -07002728 return skip;
Mark Lobodzinski08f14fa2017-02-07 17:20:06 -07002729}
Mark Lobodzinski96210742017-02-09 10:33:46 -07002730
2731// Helper function to validate correct usage bits set for buffers or images. Verify that (actual & desired) flags != 0 or, if strict
2732// is true, verify that (actual & desired) flags == desired
Mark Lobodzinski95dbbe52017-02-09 10:40:41 -07002733static 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 -06002734 VulkanObjectType obj_type, int32_t const msgCode, char const *func_name, char const *usage_str) {
Mark Lobodzinski95dbbe52017-02-09 10:40:41 -07002735 const debug_report_data *report_data = core_validation::GetReportData(device_data);
Mark Lobodzinski96210742017-02-09 10:33:46 -07002736
2737 bool correct_usage = false;
Mark Lobodzinski95dbbe52017-02-09 10:40:41 -07002738 bool skip = false;
Mark Lobodzinski33826372017-04-13 11:10:11 -06002739 const char *type_str = object_string[obj_type];
Mark Lobodzinski96210742017-02-09 10:33:46 -07002740 if (strict) {
2741 correct_usage = ((actual & desired) == desired);
2742 } else {
2743 correct_usage = ((actual & desired) != 0);
2744 }
2745 if (!correct_usage) {
2746 if (msgCode == -1) {
2747 // TODO: Fix callers with msgCode == -1 to use correct validation checks.
Mark Lobodzinskic51dbb72017-04-13 14:25:39 -06002748 skip = log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, get_debug_report_enum[obj_type], obj_handle, __LINE__,
Mark Lobodzinski33826372017-04-13 11:10:11 -06002749 MEMTRACK_INVALID_USAGE_FLAG, "MEM",
2750 "Invalid usage flag for %s 0x%" PRIxLEAST64
2751 " used by %s. In this case, %s should have %s set during creation.",
2752 type_str, obj_handle, func_name, type_str, usage_str);
Mark Lobodzinski96210742017-02-09 10:33:46 -07002753 } else {
2754 const char *valid_usage = (msgCode == -1) ? "" : validation_error_map[msgCode];
Mark Lobodzinski33826372017-04-13 11:10:11 -06002755 skip = log_msg(
Mark Lobodzinskic51dbb72017-04-13 14:25:39 -06002756 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, get_debug_report_enum[obj_type], obj_handle, __LINE__, msgCode, "MEM",
Mark Lobodzinski33826372017-04-13 11:10:11 -06002757 "Invalid usage flag for %s 0x%" PRIxLEAST64 " used by %s. In this case, %s should have %s set during creation. %s",
2758 type_str, obj_handle, func_name, type_str, usage_str, valid_usage);
Mark Lobodzinski96210742017-02-09 10:33:46 -07002759 }
2760 }
Mark Lobodzinski95dbbe52017-02-09 10:40:41 -07002761 return skip;
Mark Lobodzinski96210742017-02-09 10:33:46 -07002762}
2763
2764// Helper function to validate usage flags for buffers. For given buffer_state send actual vs. desired usage off to helper above
2765// where an error will be flagged if usage is not correct
Chris Forbes8fdba302017-04-24 18:34:28 -07002766bool ValidateImageUsageFlags(layer_data *device_data, IMAGE_STATE const *image_state, VkFlags desired, bool strict,
Mark Lobodzinski96210742017-02-09 10:33:46 -07002767 int32_t const msgCode, char const *func_name, char const *usage_string) {
Petr Krausbc7f5442017-05-14 23:43:38 +02002768 return validate_usage_flags(device_data, image_state->createInfo.usage, desired, strict, HandleToUint64(image_state->image),
2769 kVulkanObjectTypeImage, msgCode, func_name, usage_string);
Mark Lobodzinski96210742017-02-09 10:33:46 -07002770}
2771
2772// Helper function to validate usage flags for buffers. For given buffer_state send actual vs. desired usage off to helper above
2773// where an error will be flagged if usage is not correct
Chris Forbes8fdba302017-04-24 18:34:28 -07002774bool ValidateBufferUsageFlags(layer_data *device_data, BUFFER_STATE const *buffer_state, VkFlags desired, bool strict,
Mark Lobodzinski96210742017-02-09 10:33:46 -07002775 int32_t const msgCode, char const *func_name, char const *usage_string) {
Petr Krausbc7f5442017-05-14 23:43:38 +02002776 return validate_usage_flags(device_data, buffer_state->createInfo.usage, desired, strict, HandleToUint64(buffer_state->buffer),
2777 kVulkanObjectTypeBuffer, msgCode, func_name, usage_string);
Mark Lobodzinski96210742017-02-09 10:33:46 -07002778}
2779
Mark Lobodzinski95dbbe52017-02-09 10:40:41 -07002780bool PreCallValidateCreateBuffer(layer_data *device_data, const VkBufferCreateInfo *pCreateInfo) {
Mark Lobodzinski96210742017-02-09 10:33:46 -07002781 bool skip = false;
Mark Lobodzinski847b60c2017-03-13 09:32:45 -06002782 const debug_report_data *report_data = core_validation::GetReportData(device_data);
2783
Mark Lobodzinski96210742017-02-09 10:33:46 -07002784 // TODO: Add check for VALIDATION_ERROR_00658
Mark Lobodzinski96210742017-02-09 10:33:46 -07002785 // TODO: Add check for VALIDATION_ERROR_00667
2786 // TODO: Add check for VALIDATION_ERROR_00668
2787 // TODO: Add check for VALIDATION_ERROR_00669
Mark Lobodzinski847b60c2017-03-13 09:32:45 -06002788
2789 if ((pCreateInfo->flags & VK_BUFFER_CREATE_SPARSE_BINDING_BIT) && (!GetEnabledFeatures(device_data)->sparseBinding)) {
2790 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2791 VALIDATION_ERROR_00666, "DS",
2792 "vkCreateBuffer(): the sparseBinding device feature is disabled: Buffers cannot be created with the "
2793 "VK_BUFFER_CREATE_SPARSE_BINDING_BIT set. %s",
2794 validation_error_map[VALIDATION_ERROR_00666]);
2795 }
Mark Lobodzinskiaf355062017-03-13 09:35:01 -06002796
2797 if ((pCreateInfo->flags & VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT) && (!GetEnabledFeatures(device_data)->sparseResidencyBuffer)) {
2798 skip |=
2799 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2800 DRAWSTATE_INVALID_FEATURE, "DS",
2801 "vkCreateBuffer(): the sparseResidencyBuffer device feature is disabled: Buffers cannot be created with the "
2802 "VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT set.");
2803 }
Mark Lobodzinski035a4cf2017-03-13 09:45:07 -06002804
2805 if ((pCreateInfo->flags & VK_BUFFER_CREATE_SPARSE_ALIASED_BIT) && (!GetEnabledFeatures(device_data)->sparseResidencyAliased)) {
2806 skip |=
2807 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2808 DRAWSTATE_INVALID_FEATURE, "DS",
2809 "vkCreateBuffer(): the sparseResidencyAliased device feature is disabled: Buffers cannot be created with the "
2810 "VK_BUFFER_CREATE_SPARSE_ALIASED_BIT set.");
2811 }
Mark Lobodzinski96210742017-02-09 10:33:46 -07002812 return skip;
2813}
2814
2815void PostCallRecordCreateBuffer(layer_data *device_data, const VkBufferCreateInfo *pCreateInfo, VkBuffer *pBuffer) {
2816 // TODO : This doesn't create deep copy of pQueueFamilyIndices so need to fix that if/when we want that data to be valid
2817 GetBufferMap(device_data)
2818 ->insert(std::make_pair(*pBuffer, std::unique_ptr<BUFFER_STATE>(new BUFFER_STATE(*pBuffer, pCreateInfo))));
2819}
2820
Mark Lobodzinski95dbbe52017-02-09 10:40:41 -07002821bool PreCallValidateCreateBufferView(layer_data *device_data, const VkBufferViewCreateInfo *pCreateInfo) {
2822 bool skip = false;
2823 BUFFER_STATE *buffer_state = GetBufferState(device_data, pCreateInfo->buffer);
Mark Lobodzinski96210742017-02-09 10:33:46 -07002824 // If this isn't a sparse buffer, it needs to have memory backing it at CreateBufferView time
2825 if (buffer_state) {
Mark Lobodzinski95dbbe52017-02-09 10:40:41 -07002826 skip |= ValidateMemoryIsBoundToBuffer(device_data, buffer_state, "vkCreateBufferView()", VALIDATION_ERROR_02522);
Mark Lobodzinski96210742017-02-09 10:33:46 -07002827 // In order to create a valid buffer view, the buffer must have been created with at least one of the following flags:
2828 // UNIFORM_TEXEL_BUFFER_BIT or STORAGE_TEXEL_BUFFER_BIT
Mark Lobodzinski95dbbe52017-02-09 10:40:41 -07002829 skip |= ValidateBufferUsageFlags(
2830 device_data, buffer_state, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT, false,
Mark Lobodzinski96210742017-02-09 10:33:46 -07002831 VALIDATION_ERROR_00694, "vkCreateBufferView()", "VK_BUFFER_USAGE_[STORAGE|UNIFORM]_TEXEL_BUFFER_BIT");
2832 }
Mark Lobodzinski95dbbe52017-02-09 10:40:41 -07002833 return skip;
Mark Lobodzinski96210742017-02-09 10:33:46 -07002834}
2835
2836void PostCallRecordCreateBufferView(layer_data *device_data, const VkBufferViewCreateInfo *pCreateInfo, VkBufferView *pView) {
2837 (*GetBufferViewMap(device_data))[*pView] = std::unique_ptr<BUFFER_VIEW_STATE>(new BUFFER_VIEW_STATE(*pView, pCreateInfo));
2838}
Mark Lobodzinski602de982017-02-09 11:01:33 -07002839
2840// For the given format verify that the aspect masks make sense
2841bool ValidateImageAspectMask(layer_data *device_data, VkImage image, VkFormat format, VkImageAspectFlags aspect_mask,
2842 const char *func_name) {
2843 const debug_report_data *report_data = core_validation::GetReportData(device_data);
2844 bool skip = false;
Dave Houlton1d2022c2017-03-29 11:43:58 -06002845 if (FormatIsColor(format)) {
Mark Lobodzinski602de982017-02-09 11:01:33 -07002846 if ((aspect_mask & VK_IMAGE_ASPECT_COLOR_BIT) != VK_IMAGE_ASPECT_COLOR_BIT) {
Petr Krausbc7f5442017-05-14 23:43:38 +02002847 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
2848 HandleToUint64(image), __LINE__, VALIDATION_ERROR_00741, "IMAGE",
Mark Lobodzinski602de982017-02-09 11:01:33 -07002849 "%s: Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set. %s", func_name,
2850 validation_error_map[VALIDATION_ERROR_00741]);
2851 } else if ((aspect_mask & VK_IMAGE_ASPECT_COLOR_BIT) != aspect_mask) {
Petr Krausbc7f5442017-05-14 23:43:38 +02002852 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
2853 HandleToUint64(image), __LINE__, VALIDATION_ERROR_00741, "IMAGE",
Mark Lobodzinski602de982017-02-09 11:01:33 -07002854 "%s: Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set. %s", func_name,
2855 validation_error_map[VALIDATION_ERROR_00741]);
2856 }
Dave Houlton1d2022c2017-03-29 11:43:58 -06002857 } else if (FormatIsDepthAndStencil(format)) {
Mark Lobodzinski602de982017-02-09 11:01:33 -07002858 if ((aspect_mask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) == 0) {
Petr Krausbc7f5442017-05-14 23:43:38 +02002859 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
2860 HandleToUint64(image), __LINE__, VALIDATION_ERROR_00741, "IMAGE",
Mark Lobodzinski602de982017-02-09 11:01:33 -07002861 "%s: Depth/stencil image formats must have "
2862 "at least one of VK_IMAGE_ASPECT_DEPTH_BIT "
2863 "and VK_IMAGE_ASPECT_STENCIL_BIT set. %s",
2864 func_name, validation_error_map[VALIDATION_ERROR_00741]);
2865 } else if ((aspect_mask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) != aspect_mask) {
Petr Krausbc7f5442017-05-14 23:43:38 +02002866 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
2867 HandleToUint64(image), __LINE__, VALIDATION_ERROR_00741, "IMAGE",
Mark Lobodzinski602de982017-02-09 11:01:33 -07002868 "%s: Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and "
2869 "VK_IMAGE_ASPECT_STENCIL_BIT set. %s",
2870 func_name, validation_error_map[VALIDATION_ERROR_00741]);
2871 }
Dave Houlton1d2022c2017-03-29 11:43:58 -06002872 } else if (FormatIsDepthOnly(format)) {
Mark Lobodzinski602de982017-02-09 11:01:33 -07002873 if ((aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) != VK_IMAGE_ASPECT_DEPTH_BIT) {
Petr Krausbc7f5442017-05-14 23:43:38 +02002874 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
2875 HandleToUint64(image), __LINE__, VALIDATION_ERROR_00741, "IMAGE",
Mark Lobodzinski602de982017-02-09 11:01:33 -07002876 "%s: Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set. %s", func_name,
2877 validation_error_map[VALIDATION_ERROR_00741]);
2878 } else if ((aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) != aspect_mask) {
Petr Krausbc7f5442017-05-14 23:43:38 +02002879 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
2880 HandleToUint64(image), __LINE__, VALIDATION_ERROR_00741, "IMAGE",
Mark Lobodzinski602de982017-02-09 11:01:33 -07002881 "%s: Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set. %s", func_name,
2882 validation_error_map[VALIDATION_ERROR_00741]);
2883 }
Dave Houlton1d2022c2017-03-29 11:43:58 -06002884 } else if (FormatIsStencilOnly(format)) {
Mark Lobodzinski602de982017-02-09 11:01:33 -07002885 if ((aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) != VK_IMAGE_ASPECT_STENCIL_BIT) {
Petr Krausbc7f5442017-05-14 23:43:38 +02002886 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
2887 HandleToUint64(image), __LINE__, VALIDATION_ERROR_00741, "IMAGE",
Mark Lobodzinski602de982017-02-09 11:01:33 -07002888 "%s: Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set. %s", func_name,
2889 validation_error_map[VALIDATION_ERROR_00741]);
2890 } else if ((aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) != aspect_mask) {
Petr Krausbc7f5442017-05-14 23:43:38 +02002891 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
2892 HandleToUint64(image), __LINE__, VALIDATION_ERROR_00741, "IMAGE",
Mark Lobodzinski602de982017-02-09 11:01:33 -07002893 "%s: Stencil-only image formats can have only the VK_IMAGE_ASPECT_STENCIL_BIT set. %s", func_name,
2894 validation_error_map[VALIDATION_ERROR_00741]);
2895 }
2896 }
2897 return skip;
2898}
2899
Petr Kraus4d718682017-05-18 03:38:41 +02002900bool ValidateImageSubresourceRange(const layer_data *device_data, const IMAGE_STATE *image_state,
2901 const VkImageViewCreateInfo *image_view_create_info,
2902 const VkImageSubresourceRange &subresourceRange, const char *cmd_name, const char *param_name) {
Mark Lobodzinski602de982017-02-09 11:01:33 -07002903 const debug_report_data *report_data = core_validation::GetReportData(device_data);
2904 bool skip = false;
Petr Kraus4d718682017-05-18 03:38:41 +02002905
2906 // Validate mip levels
2907 const auto image_mip_count = image_state->createInfo.mipLevels;
2908
Mark Lobodzinski602de982017-02-09 11:01:33 -07002909 if (subresourceRange.levelCount == 0) {
Petr Kraus4d718682017-05-18 03:38:41 +02002910 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
2911 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_00768, "IMAGE", "%s: %s.levelCount is 0. %s",
2912 cmd_name, param_name, validation_error_map[VALIDATION_ERROR_00768]);
2913 } else if (subresourceRange.levelCount == VK_REMAINING_MIP_LEVELS) {
2914 // TODO: Not in the spec VUs. Probably missing -- KhronosGroup/Vulkan-Docs#416
2915 if (subresourceRange.baseMipLevel >= image_mip_count) {
2916 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
2917 HandleToUint64(image_state->image), __LINE__, DRAWSTATE_INVALID_IMAGE_SUBRANGE, "IMAGE",
2918 "%s: %s.baseMipLevel (= %" PRIu32 ") is greater or equal to the mip level count of the image (i.e. "
2919 "greater or equal to %" PRIu32 ").",
2920 cmd_name, param_name, subresourceRange.baseMipLevel, image_mip_count);
2921 }
2922 } else {
2923 const uint64_t necessary_mip_count = uint64_t{subresourceRange.baseMipLevel} + uint64_t{subresourceRange.levelCount};
2924
2925 if (necessary_mip_count > image_mip_count) {
2926 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
2927 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_00768, "IMAGE",
2928 "%s: %s.baseMipLevel + .levelCount (= %" PRIu32 " + %" PRIu32 " = %" PRIu64 ") is greater than the "
2929 "mip level count of the image (i.e. greater than %" PRIu32 "). %s",
2930 cmd_name, param_name, subresourceRange.baseMipLevel, subresourceRange.levelCount, necessary_mip_count,
2931 image_mip_count, validation_error_map[VALIDATION_ERROR_00768]);
2932 }
Mark Lobodzinski602de982017-02-09 11:01:33 -07002933 }
Petr Kraus4d718682017-05-18 03:38:41 +02002934
2935 // Validate array layers
2936 bool is_3D_to_2D_map = image_view_create_info && GetDeviceExtensions(device_data)->khr_maintenance1 &&
2937 image_state->createInfo.imageType == VK_IMAGE_TYPE_3D &&
2938 image_view_create_info->viewType == VK_IMAGE_VIEW_TYPE_2D_ARRAY;
2939
2940 const auto image_layer_count = is_3D_to_2D_map ? image_state->createInfo.extent.depth : image_state->createInfo.arrayLayers;
2941 const auto image_layer_count_var_name = is_3D_to_2D_map ? "extent.depth" : "arrayLayers";
2942 const auto invalid_layer_code = is_3D_to_2D_map ? VALIDATION_ERROR_00769 : VALIDATION_ERROR_02931;
2943
Mark Lobodzinski602de982017-02-09 11:01:33 -07002944 if (subresourceRange.layerCount == 0) {
Petr Kraus4d718682017-05-18 03:38:41 +02002945 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
2946 HandleToUint64(image_state->image), __LINE__, invalid_layer_code, "IMAGE", "%s: %s.layerCount is 0. %s",
2947 cmd_name, param_name, validation_error_map[invalid_layer_code]);
2948 } else if (subresourceRange.layerCount == VK_REMAINING_ARRAY_LAYERS) {
2949 // TODO: Not in the spec VUs. Probably missing -- KhronosGroup/Vulkan-Docs#416
2950 if (subresourceRange.baseArrayLayer >= image_layer_count) {
2951 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
2952 HandleToUint64(image_state->image), __LINE__, DRAWSTATE_INVALID_IMAGE_SUBRANGE, "IMAGE",
2953 "%s: %s.baseArrayLayer (= %" PRIu32 ") is greater or equal to the %s of the image when it was created "
2954 "(i.e. greater or equal to %" PRIu32 ").",
2955 cmd_name, param_name, subresourceRange.baseArrayLayer, image_layer_count_var_name, image_layer_count);
2956 }
2957 } else {
2958 const uint64_t necessary_layer_count = uint64_t{subresourceRange.baseArrayLayer} + uint64_t{subresourceRange.layerCount};
2959
2960 if (necessary_layer_count > image_layer_count) {
2961 skip |=
2962 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
2963 HandleToUint64(image_state->image), __LINE__, invalid_layer_code, "IMAGE",
2964 "%s: %s.baseArrayLayer + .layerCount (= %" PRIu32 " + %" PRIu32 " = %" PRIu64 ") is greater than the "
2965 "%s of the image when it was created (i.e. greater than %" PRIu32 "). %s",
2966 cmd_name, param_name, subresourceRange.baseArrayLayer, subresourceRange.layerCount, necessary_layer_count,
2967 image_layer_count_var_name, image_layer_count, validation_error_map[invalid_layer_code]);
2968 }
Mark Lobodzinski602de982017-02-09 11:01:33 -07002969 }
Petr Kraus4d718682017-05-18 03:38:41 +02002970
Mark Lobodzinski602de982017-02-09 11:01:33 -07002971 return skip;
2972}
2973
2974bool PreCallValidateCreateImageView(layer_data *device_data, const VkImageViewCreateInfo *create_info) {
2975 const debug_report_data *report_data = core_validation::GetReportData(device_data);
2976 bool skip = false;
2977 IMAGE_STATE *image_state = GetImageState(device_data, create_info->image);
2978 if (image_state) {
2979 skip |= ValidateImageUsageFlags(
2980 device_data, image_state,
2981 VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT |
2982 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
2983 false, -1, "vkCreateImageView()",
2984 "VK_IMAGE_USAGE_[SAMPLED|STORAGE|COLOR_ATTACHMENT|DEPTH_STENCIL_ATTACHMENT|INPUT_ATTACHMENT]_BIT");
2985 // If this isn't a sparse image, it needs to have memory backing it at CreateImageView time
2986 skip |= ValidateMemoryIsBoundToImage(device_data, image_state, "vkCreateImageView()", VALIDATION_ERROR_02524);
2987 // Checks imported from image layer
Petr Kraus4d718682017-05-18 03:38:41 +02002988 skip |= ValidateImageSubresourceRange(device_data, image_state, create_info, create_info->subresourceRange,
2989 "vkCreateImageView", "pCreateInfo->subresourceRange");
Mark Lobodzinski602de982017-02-09 11:01:33 -07002990
2991 VkImageCreateFlags image_flags = image_state->createInfo.flags;
2992 VkFormat image_format = image_state->createInfo.format;
2993 VkFormat view_format = create_info->format;
2994 VkImageAspectFlags aspect_mask = create_info->subresourceRange.aspectMask;
2995
2996 // Validate VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT state
2997 if (image_flags & VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT) {
2998 // Format MUST be compatible (in the same format compatibility class) as the format the image was created with
Dave Houlton1d2022c2017-03-29 11:43:58 -06002999 if (FormatCompatibilityClass(image_format) != FormatCompatibilityClass(view_format)) {
Mark Lobodzinski602de982017-02-09 11:01:33 -07003000 std::stringstream ss;
3001 ss << "vkCreateImageView(): ImageView format " << string_VkFormat(view_format)
Petr Krausbc7f5442017-05-14 23:43:38 +02003002 << " is not in the same format compatibility class as image (" << HandleToUint64(create_info->image)
3003 << ") format " << string_VkFormat(image_format)
3004 << ". Images created with the VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
Mark Lobodzinski602de982017-02-09 11:01:33 -07003005 << "can support ImageViews with differing formats but they must be in the same compatibility class.";
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06003006 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
Mark Lobodzinski602de982017-02-09 11:01:33 -07003007 VALIDATION_ERROR_02171, "IMAGE", "%s %s", ss.str().c_str(),
3008 validation_error_map[VALIDATION_ERROR_02171]);
3009 }
3010 } else {
3011 // Format MUST be IDENTICAL to the format the image was created with
3012 if (image_format != view_format) {
3013 std::stringstream ss;
3014 ss << "vkCreateImageView() format " << string_VkFormat(view_format) << " differs from image "
Petr Krausbc7f5442017-05-14 23:43:38 +02003015 << HandleToUint64(create_info->image) << " format " << string_VkFormat(image_format)
Mark Lobodzinski602de982017-02-09 11:01:33 -07003016 << ". Formats MUST be IDENTICAL unless VK_IMAGE_CREATE_MUTABLE_FORMAT BIT was set on image creation.";
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06003017 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
Mark Lobodzinski602de982017-02-09 11:01:33 -07003018 VALIDATION_ERROR_02172, "IMAGE", "%s %s", ss.str().c_str(),
3019 validation_error_map[VALIDATION_ERROR_02172]);
3020 }
3021 }
3022
3023 // Validate correct image aspect bits for desired formats and format consistency
3024 skip |= ValidateImageAspectMask(device_data, image_state->image, image_format, aspect_mask, "vkCreateImageView()");
3025 }
3026 return skip;
3027}
3028
Mark Lobodzinskiefd933b2017-02-10 12:09:23 -07003029void PostCallRecordCreateImageView(layer_data *device_data, const VkImageViewCreateInfo *create_info, VkImageView view) {
3030 auto image_view_map = GetImageViewMap(device_data);
3031 (*image_view_map)[view] = std::unique_ptr<IMAGE_VIEW_STATE>(new IMAGE_VIEW_STATE(view, create_info));
3032
3033 auto image_state = GetImageState(device_data, create_info->image);
Dave Houlton4eaaf3a2017-03-14 11:31:20 -06003034 auto &sub_res_range = (*image_view_map)[view].get()->create_info.subresourceRange;
Mark Lobodzinski903e5ff2017-03-23 09:43:35 -06003035 sub_res_range.levelCount = ResolveRemainingLevels(&sub_res_range, image_state->createInfo.mipLevels);
3036 sub_res_range.layerCount = ResolveRemainingLayers(&sub_res_range, image_state->createInfo.arrayLayers);
Mark Lobodzinski602de982017-02-09 11:01:33 -07003037}
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07003038
Mark Lobodzinski680421d2017-02-09 13:06:56 -07003039bool PreCallValidateCmdCopyBuffer(layer_data *device_data, GLOBAL_CB_NODE *cb_node, BUFFER_STATE *src_buffer_state,
3040 BUFFER_STATE *dst_buffer_state) {
3041 bool skip = false;
3042 skip |= ValidateMemoryIsBoundToBuffer(device_data, src_buffer_state, "vkCmdCopyBuffer()", VALIDATION_ERROR_02531);
3043 skip |= ValidateMemoryIsBoundToBuffer(device_data, dst_buffer_state, "vkCmdCopyBuffer()", VALIDATION_ERROR_02532);
3044 // Validate that SRC & DST buffers have correct usage flags set
3045 skip |= ValidateBufferUsageFlags(device_data, src_buffer_state, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, true, VALIDATION_ERROR_01164,
3046 "vkCmdCopyBuffer()", "VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
3047 skip |= ValidateBufferUsageFlags(device_data, dst_buffer_state, VK_BUFFER_USAGE_TRANSFER_DST_BIT, true, VALIDATION_ERROR_01165,
3048 "vkCmdCopyBuffer()", "VK_BUFFER_USAGE_TRANSFER_DST_BIT");
Mike Schuchardt9c582402017-02-23 15:57:37 -07003049 skip |= ValidateCmdQueueFlags(device_data, cb_node, "vkCmdCopyBuffer()",
3050 VK_QUEUE_TRANSFER_BIT | VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT, VALIDATION_ERROR_01171);
Mark Lobodzinski680421d2017-02-09 13:06:56 -07003051 skip |= ValidateCmd(device_data, cb_node, CMD_COPYBUFFER, "vkCmdCopyBuffer()");
3052 skip |= insideRenderPass(device_data, cb_node, "vkCmdCopyBuffer()", VALIDATION_ERROR_01172);
3053 return skip;
3054}
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07003055
Mark Lobodzinski680421d2017-02-09 13:06:56 -07003056void PreCallRecordCmdCopyBuffer(layer_data *device_data, GLOBAL_CB_NODE *cb_node, BUFFER_STATE *src_buffer_state,
3057 BUFFER_STATE *dst_buffer_state) {
3058 // Update bindings between buffers and cmd buffer
3059 AddCommandBufferBindingBuffer(device_data, cb_node, src_buffer_state);
3060 AddCommandBufferBindingBuffer(device_data, cb_node, dst_buffer_state);
3061
3062 std::function<bool()> function = [=]() {
3063 return ValidateBufferMemoryIsValid(device_data, src_buffer_state, "vkCmdCopyBuffer()");
3064 };
3065 cb_node->validate_functions.push_back(function);
3066 function = [=]() {
3067 SetBufferMemoryValid(device_data, dst_buffer_state, true);
3068 return false;
3069 };
3070 cb_node->validate_functions.push_back(function);
3071 core_validation::UpdateCmdBufferLastCmd(cb_node, CMD_COPYBUFFER);
3072}
Mark Lobodzinski306441e2017-02-10 13:48:38 -07003073
3074static bool validateIdleBuffer(layer_data *device_data, VkBuffer buffer) {
3075 const debug_report_data *report_data = core_validation::GetReportData(device_data);
3076 bool skip = false;
3077 auto buffer_state = GetBufferState(device_data, buffer);
3078 if (!buffer_state) {
Petr Krausbc7f5442017-05-14 23:43:38 +02003079 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, HandleToUint64(buffer),
Mark Lobodzinski306441e2017-02-10 13:48:38 -07003080 __LINE__, DRAWSTATE_DOUBLE_DESTROY, "DS",
Petr Krausbc7f5442017-05-14 23:43:38 +02003081 "Cannot free buffer 0x%" PRIxLEAST64 " that has not been allocated.", HandleToUint64(buffer));
Mark Lobodzinski306441e2017-02-10 13:48:38 -07003082 } else {
3083 if (buffer_state->in_use.load()) {
Petr Krausbc7f5442017-05-14 23:43:38 +02003084 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT,
3085 HandleToUint64(buffer), __LINE__, VALIDATION_ERROR_00676, "DS",
3086 "Cannot free buffer 0x%" PRIxLEAST64 " that is in use by a command buffer. %s", HandleToUint64(buffer),
Mark Lobodzinski306441e2017-02-10 13:48:38 -07003087 validation_error_map[VALIDATION_ERROR_00676]);
3088 }
3089 }
3090 return skip;
3091}
3092
3093bool PreCallValidateDestroyImageView(layer_data *device_data, VkImageView image_view, IMAGE_VIEW_STATE **image_view_state,
3094 VK_OBJECT *obj_struct) {
3095 *image_view_state = GetImageViewState(device_data, image_view);
Petr Krausbc7f5442017-05-14 23:43:38 +02003096 *obj_struct = {HandleToUint64(image_view), kVulkanObjectTypeImageView};
Mark Lobodzinski306441e2017-02-10 13:48:38 -07003097 if (GetDisables(device_data)->destroy_image_view) return false;
3098 bool skip = false;
3099 if (*image_view_state) {
3100 skip |= ValidateObjectNotInUse(device_data, *image_view_state, *obj_struct, VALIDATION_ERROR_00776);
3101 }
3102 return skip;
3103}
3104
3105void PostCallRecordDestroyImageView(layer_data *device_data, VkImageView image_view, IMAGE_VIEW_STATE *image_view_state,
3106 VK_OBJECT obj_struct) {
3107 // Any bound cmd buffers are now invalid
3108 invalidateCommandBuffers(device_data, image_view_state->cb_bindings, obj_struct);
3109 (*GetImageViewMap(device_data)).erase(image_view);
3110}
3111
3112bool PreCallValidateDestroyBuffer(layer_data *device_data, VkBuffer buffer, BUFFER_STATE **buffer_state, VK_OBJECT *obj_struct) {
3113 *buffer_state = GetBufferState(device_data, buffer);
Petr Krausbc7f5442017-05-14 23:43:38 +02003114 *obj_struct = {HandleToUint64(buffer), kVulkanObjectTypeBuffer};
Mark Lobodzinski306441e2017-02-10 13:48:38 -07003115 if (GetDisables(device_data)->destroy_buffer) return false;
3116 bool skip = false;
3117 if (*buffer_state) {
3118 skip |= validateIdleBuffer(device_data, buffer);
3119 }
3120 return skip;
3121}
3122
3123void PostCallRecordDestroyBuffer(layer_data *device_data, VkBuffer buffer, BUFFER_STATE *buffer_state, VK_OBJECT obj_struct) {
3124 invalidateCommandBuffers(device_data, buffer_state->cb_bindings, obj_struct);
3125 for (auto mem_binding : buffer_state->GetBoundMemory()) {
3126 auto mem_info = GetMemObjInfo(device_data, mem_binding);
3127 if (mem_info) {
Petr Krausbc7f5442017-05-14 23:43:38 +02003128 core_validation::RemoveBufferMemoryRange(HandleToUint64(buffer), mem_info);
Mark Lobodzinski306441e2017-02-10 13:48:38 -07003129 }
3130 }
Petr Krausbc7f5442017-05-14 23:43:38 +02003131 ClearMemoryObjectBindings(device_data, HandleToUint64(buffer), kVulkanObjectTypeBuffer);
Mark Lobodzinski306441e2017-02-10 13:48:38 -07003132 GetBufferMap(device_data)->erase(buffer_state->buffer);
3133}
3134
3135bool PreCallValidateDestroyBufferView(layer_data *device_data, VkBufferView buffer_view, BUFFER_VIEW_STATE **buffer_view_state,
3136 VK_OBJECT *obj_struct) {
3137 *buffer_view_state = GetBufferViewState(device_data, buffer_view);
Petr Krausbc7f5442017-05-14 23:43:38 +02003138 *obj_struct = {HandleToUint64(buffer_view), kVulkanObjectTypeBufferView};
Mark Lobodzinski306441e2017-02-10 13:48:38 -07003139 if (GetDisables(device_data)->destroy_buffer_view) return false;
3140 bool skip = false;
3141 if (*buffer_view_state) {
3142 skip |= ValidateObjectNotInUse(device_data, *buffer_view_state, *obj_struct, VALIDATION_ERROR_00701);
3143 }
3144 return skip;
3145}
3146
3147void PostCallRecordDestroyBufferView(layer_data *device_data, VkBufferView buffer_view, BUFFER_VIEW_STATE *buffer_view_state,
3148 VK_OBJECT obj_struct) {
3149 // Any bound cmd buffers are now invalid
3150 invalidateCommandBuffers(device_data, buffer_view_state->cb_bindings, obj_struct);
3151 GetBufferViewMap(device_data)->erase(buffer_view);
3152}
Mark Lobodzinskidf0acbf2017-02-10 14:01:27 -07003153
3154bool PreCallValidateCmdFillBuffer(layer_data *device_data, GLOBAL_CB_NODE *cb_node, BUFFER_STATE *buffer_state) {
3155 bool skip = false;
3156 skip |= ValidateMemoryIsBoundToBuffer(device_data, buffer_state, "vkCmdFillBuffer()", VALIDATION_ERROR_02529);
Mike Schuchardt9c582402017-02-23 15:57:37 -07003157 skip |= ValidateCmdQueueFlags(device_data, cb_node, "vkCmdFillBuffer()",
3158 VK_QUEUE_TRANSFER_BIT | VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT, VALIDATION_ERROR_01141);
Mark Lobodzinskidf0acbf2017-02-10 14:01:27 -07003159 skip |= ValidateCmd(device_data, cb_node, CMD_FILLBUFFER, "vkCmdFillBuffer()");
3160 // Validate that DST buffer has correct usage flags set
3161 skip |= ValidateBufferUsageFlags(device_data, buffer_state, VK_BUFFER_USAGE_TRANSFER_DST_BIT, true, VALIDATION_ERROR_01137,
3162 "vkCmdFillBuffer()", "VK_BUFFER_USAGE_TRANSFER_DST_BIT");
3163 skip |= insideRenderPass(device_data, cb_node, "vkCmdFillBuffer()", VALIDATION_ERROR_01142);
3164 return skip;
3165}
3166
3167void PreCallRecordCmdFillBuffer(layer_data *device_data, GLOBAL_CB_NODE *cb_node, BUFFER_STATE *buffer_state) {
3168 std::function<bool()> function = [=]() {
3169 SetBufferMemoryValid(device_data, buffer_state, true);
3170 return false;
3171 };
3172 cb_node->validate_functions.push_back(function);
3173 // Update bindings between buffer and cmd buffer
3174 AddCommandBufferBindingBuffer(device_data, cb_node, buffer_state);
3175 core_validation::UpdateCmdBufferLastCmd(cb_node, CMD_FILLBUFFER);
3176}
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003177
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003178bool ValidateBufferImageCopyData(const debug_report_data *report_data, uint32_t regionCount, const VkBufferImageCopy *pRegions,
3179 IMAGE_STATE *image_state, const char *function) {
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003180 bool skip = false;
3181
3182 for (uint32_t i = 0; i < regionCount; i++) {
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003183 if (image_state->createInfo.imageType == VK_IMAGE_TYPE_1D) {
3184 if ((pRegions[i].imageOffset.y != 0) || (pRegions[i].imageExtent.height != 1)) {
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003185 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02003186 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_01746, "IMAGE",
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003187 "%s(): pRegion[%d] imageOffset.y is %d and imageExtent.height is %d. For 1D images these "
3188 "must be 0 and 1, respectively. %s",
3189 function, i, pRegions[i].imageOffset.y, pRegions[i].imageExtent.height,
3190 validation_error_map[VALIDATION_ERROR_01746]);
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003191 }
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003192 }
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003193
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003194 if ((image_state->createInfo.imageType == VK_IMAGE_TYPE_1D) || (image_state->createInfo.imageType == VK_IMAGE_TYPE_2D)) {
3195 if ((pRegions[i].imageOffset.z != 0) || (pRegions[i].imageExtent.depth != 1)) {
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003196 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02003197 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_01747, "IMAGE",
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003198 "%s(): pRegion[%d] imageOffset.z is %d and imageExtent.depth is %d. For 1D and 2D images these "
3199 "must be 0 and 1, respectively. %s",
3200 function, i, pRegions[i].imageOffset.z, pRegions[i].imageExtent.depth,
3201 validation_error_map[VALIDATION_ERROR_01747]);
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003202 }
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003203 }
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003204
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003205 if (image_state->createInfo.imageType == VK_IMAGE_TYPE_3D) {
3206 if ((0 != pRegions[i].imageSubresource.baseArrayLayer) || (1 != pRegions[i].imageSubresource.layerCount)) {
3207 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02003208 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_01281, "IMAGE",
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003209 "%s(): pRegion[%d] imageSubresource.baseArrayLayer is %d and imageSubresource.layerCount is "
3210 "%d. For 3D images these must be 0 and 1, respectively. %s",
3211 function, i, pRegions[i].imageSubresource.baseArrayLayer, pRegions[i].imageSubresource.layerCount,
3212 validation_error_map[VALIDATION_ERROR_01281]);
3213 }
3214 }
3215
3216 // If the the calling command's VkImage parameter's format is not a depth/stencil format,
3217 // then bufferOffset must be a multiple of the calling command's VkImage parameter's texel size
Dave Houlton1d2022c2017-03-29 11:43:58 -06003218 auto texel_size = FormatSize(image_state->createInfo.format);
Dave Houlton1150cf52017-04-27 14:38:11 -06003219 if (!FormatIsDepthAndStencil(image_state->createInfo.format) && SafeModulo(pRegions[i].bufferOffset, texel_size) != 0) {
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003220 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02003221 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_01263, "IMAGE",
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003222 "%s(): pRegion[%d] bufferOffset 0x%" PRIxLEAST64
3223 " must be a multiple of this format's texel size (" PRINTF_SIZE_T_SPECIFIER "). %s",
3224 function, i, pRegions[i].bufferOffset, texel_size, validation_error_map[VALIDATION_ERROR_01263]);
3225 }
3226
3227 // BufferOffset must be a multiple of 4
Dave Houlton1d2022c2017-03-29 11:43:58 -06003228 if (SafeModulo(pRegions[i].bufferOffset, 4) != 0) {
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003229 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02003230 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_01264, "IMAGE",
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003231 "%s(): pRegion[%d] bufferOffset 0x%" PRIxLEAST64 " must be a multiple of 4. %s", function, i,
3232 pRegions[i].bufferOffset, validation_error_map[VALIDATION_ERROR_01264]);
3233 }
3234
3235 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
3236 if ((pRegions[i].bufferRowLength != 0) && (pRegions[i].bufferRowLength < pRegions[i].imageExtent.width)) {
3237 skip |= log_msg(
3238 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02003239 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_01265, "IMAGE",
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003240 "%s(): pRegion[%d] bufferRowLength (%d) must be zero or greater-than-or-equal-to imageExtent.width (%d). %s",
3241 function, i, pRegions[i].bufferRowLength, pRegions[i].imageExtent.width,
3242 validation_error_map[VALIDATION_ERROR_01265]);
3243 }
3244
3245 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
3246 if ((pRegions[i].bufferImageHeight != 0) && (pRegions[i].bufferImageHeight < pRegions[i].imageExtent.height)) {
3247 skip |= log_msg(
3248 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02003249 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_01266, "IMAGE",
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003250 "%s(): pRegion[%d] bufferImageHeight (%d) must be zero or greater-than-or-equal-to imageExtent.height (%d). %s",
3251 function, i, pRegions[i].bufferImageHeight, pRegions[i].imageExtent.height,
3252 validation_error_map[VALIDATION_ERROR_01266]);
3253 }
3254
3255 // subresource aspectMask must have exactly 1 bit set
3256 const int num_bits = sizeof(VkFlags) * CHAR_BIT;
3257 std::bitset<num_bits> aspect_mask_bits(pRegions[i].imageSubresource.aspectMask);
3258 if (aspect_mask_bits.count() != 1) {
3259 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02003260 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_01280, "IMAGE",
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003261 "%s: aspectMasks for imageSubresource in each region must have only a single bit set. %s", function,
3262 validation_error_map[VALIDATION_ERROR_01280]);
3263 }
3264
3265 // image subresource aspect bit must match format
Dave Houlton4eaaf3a2017-03-14 11:31:20 -06003266 if (!VerifyAspectsPresent(pRegions[i].imageSubresource.aspectMask, image_state->createInfo.format)) {
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003267 skip |= log_msg(
3268 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02003269 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_01279, "IMAGE",
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003270 "%s(): pRegion[%d] subresource aspectMask 0x%x specifies aspects that are not present in image format 0x%x. %s",
3271 function, i, pRegions[i].imageSubresource.aspectMask, image_state->createInfo.format,
3272 validation_error_map[VALIDATION_ERROR_01279]);
3273 }
3274
3275 // Checks that apply only to compressed images
3276 // TODO: there is a comment in ValidateCopyBufferImageTransferGranularityRequirements() in core_validation.cpp that
3277 // reserves a place for these compressed image checks. This block of code could move there once the image
3278 // stuff is moved into core validation.
Dave Houlton1d2022c2017-03-29 11:43:58 -06003279 if (FormatIsCompressed(image_state->createInfo.format)) {
3280 auto block_size = FormatCompressedTexelBlockExtent(image_state->createInfo.format);
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003281
3282 // BufferRowLength must be a multiple of block width
Dave Houlton1d2022c2017-03-29 11:43:58 -06003283 if (SafeModulo(pRegions[i].bufferRowLength, block_size.width) != 0) {
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003284 skip |= log_msg(
3285 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02003286 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_01271, "IMAGE",
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003287 "%s(): pRegion[%d] bufferRowLength (%d) must be a multiple of the compressed image's texel width (%d). %s.",
3288 function, i, pRegions[i].bufferRowLength, block_size.width, validation_error_map[VALIDATION_ERROR_01271]);
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003289 }
3290
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003291 // BufferRowHeight must be a multiple of block height
Dave Houlton1d2022c2017-03-29 11:43:58 -06003292 if (SafeModulo(pRegions[i].bufferImageHeight, block_size.height) != 0) {
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003293 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02003294 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_01272, "IMAGE",
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003295 "%s(): pRegion[%d] bufferImageHeight (%d) must be a multiple of the compressed image's texel "
3296 "height (%d). %s.",
3297 function, i, pRegions[i].bufferImageHeight, block_size.height,
3298 validation_error_map[VALIDATION_ERROR_01272]);
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003299 }
3300
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003301 // image offsets must be multiples of block dimensions
Dave Houlton1d2022c2017-03-29 11:43:58 -06003302 if ((SafeModulo(pRegions[i].imageOffset.x, block_size.width) != 0) ||
3303 (SafeModulo(pRegions[i].imageOffset.y, block_size.height) != 0) ||
3304 (SafeModulo(pRegions[i].imageOffset.z, block_size.depth) != 0)) {
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003305 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02003306 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_01273, "IMAGE",
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003307 "%s(): pRegion[%d] imageOffset(x,y) (%d, %d) must be multiples of the compressed image's texel "
3308 "width & height (%d, %d). %s.",
3309 function, i, pRegions[i].imageOffset.x, pRegions[i].imageOffset.y, block_size.width,
3310 block_size.height, validation_error_map[VALIDATION_ERROR_01273]);
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003311 }
3312
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003313 // bufferOffset must be a multiple of block size (linear bytes)
Dave Houlton1d2022c2017-03-29 11:43:58 -06003314 size_t block_size_in_bytes = FormatSize(image_state->createInfo.format);
3315 if (SafeModulo(pRegions[i].bufferOffset, block_size_in_bytes) != 0) {
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003316 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02003317 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_01274, "IMAGE",
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003318 "%s(): pRegion[%d] bufferOffset (0x%" PRIxLEAST64
3319 ") must be a multiple of the compressed image's texel block "
3320 "size (" PRINTF_SIZE_T_SPECIFIER "). %s.",
3321 function, i, pRegions[i].bufferOffset, block_size_in_bytes,
3322 validation_error_map[VALIDATION_ERROR_01274]);
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003323 }
Dave Houlton67e9b532017-03-02 17:00:10 -07003324
3325 // imageExtent width must be a multiple of block width, or extent+offset width must equal subresource width
Dave Houlton75967fc2017-03-06 17:21:16 -07003326 VkExtent3D mip_extent = GetImageSubresourceExtent(image_state, &(pRegions[i].imageSubresource));
Dave Houlton1d2022c2017-03-29 11:43:58 -06003327 if ((SafeModulo(pRegions[i].imageExtent.width, block_size.width) != 0) &&
Dave Houlton75967fc2017-03-06 17:21:16 -07003328 (pRegions[i].imageExtent.width + pRegions[i].imageOffset.x != mip_extent.width)) {
3329 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02003330 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_01275, "IMAGE",
Dave Houlton75967fc2017-03-06 17:21:16 -07003331 "%s(): pRegion[%d] extent width (%d) must be a multiple of the compressed texture block width "
3332 "(%d), or when added to offset.x (%d) must equal the image subresource width (%d). %s.",
3333 function, i, pRegions[i].imageExtent.width, block_size.width, pRegions[i].imageOffset.x,
3334 mip_extent.width, validation_error_map[VALIDATION_ERROR_01275]);
Dave Houlton67e9b532017-03-02 17:00:10 -07003335 }
3336
3337 // imageExtent height must be a multiple of block height, or extent+offset height must equal subresource height
Dave Houlton1d2022c2017-03-29 11:43:58 -06003338 if ((SafeModulo(pRegions[i].imageExtent.height, block_size.height) != 0) &&
Dave Houlton75967fc2017-03-06 17:21:16 -07003339 (pRegions[i].imageExtent.height + pRegions[i].imageOffset.y != mip_extent.height)) {
3340 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02003341 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_01276, "IMAGE",
Dave Houlton75967fc2017-03-06 17:21:16 -07003342 "%s(): pRegion[%d] extent height (%d) must be a multiple of the compressed texture block height "
3343 "(%d), or when added to offset.y (%d) must equal the image subresource height (%d). %s.",
3344 function, i, pRegions[i].imageExtent.height, block_size.height, pRegions[i].imageOffset.y,
3345 mip_extent.height, validation_error_map[VALIDATION_ERROR_01276]);
Dave Houlton67e9b532017-03-02 17:00:10 -07003346 }
3347
3348 // imageExtent depth must be a multiple of block depth, or extent+offset depth must equal subresource depth
Dave Houlton1d2022c2017-03-29 11:43:58 -06003349 if ((SafeModulo(pRegions[i].imageExtent.depth, block_size.depth) != 0) &&
Dave Houlton75967fc2017-03-06 17:21:16 -07003350 (pRegions[i].imageExtent.depth + pRegions[i].imageOffset.z != mip_extent.depth)) {
3351 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02003352 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_01277, "IMAGE",
Dave Houlton75967fc2017-03-06 17:21:16 -07003353 "%s(): pRegion[%d] extent width (%d) must be a multiple of the compressed texture block depth "
3354 "(%d), or when added to offset.z (%d) must equal the image subresource depth (%d). %s.",
3355 function, i, pRegions[i].imageExtent.depth, block_size.depth, pRegions[i].imageOffset.z,
3356 mip_extent.depth, validation_error_map[VALIDATION_ERROR_01277]);
Dave Houlton67e9b532017-03-02 17:00:10 -07003357 }
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003358 }
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003359 }
3360
3361 return skip;
3362}
3363
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003364static bool ValidateImageBounds(const debug_report_data *report_data, const IMAGE_STATE *image_state, const uint32_t regionCount,
3365 const VkBufferImageCopy *pRegions, const char *func_name, UNIQUE_VALIDATION_ERROR_CODE msg_code) {
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003366 bool skip = false;
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003367 const VkImageCreateInfo *image_info = &(image_state->createInfo);
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003368
3369 for (uint32_t i = 0; i < regionCount; i++) {
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003370 VkExtent3D extent = pRegions[i].imageExtent;
3371 VkOffset3D offset = pRegions[i].imageOffset;
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003372
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003373 if (IsExtentSizeZero(&extent)) // Warn on zero area subresource
3374 {
3375 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
3376 (uint64_t)0, __LINE__, IMAGE_ZERO_AREA_SUBREGION, "IMAGE",
3377 "%s: pRegion[%d] imageExtent of {%1d, %1d, %1d} has zero area", func_name, i, extent.width,
3378 extent.height, extent.depth);
3379 }
3380
3381 VkExtent3D image_extent = GetImageSubresourceExtent(image_state, &(pRegions[i].imageSubresource));
3382
3383 // 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 -06003384 if (FormatIsCompressed(image_info->format)) {
3385 auto block_extent = FormatCompressedTexelBlockExtent(image_info->format);
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003386 if (image_extent.width % block_extent.width) {
3387 image_extent.width += (block_extent.width - (image_extent.width % block_extent.width));
3388 }
3389 if (image_extent.height % block_extent.height) {
3390 image_extent.height += (block_extent.height - (image_extent.height % block_extent.height));
3391 }
3392 if (image_extent.depth % block_extent.depth) {
3393 image_extent.depth += (block_extent.depth - (image_extent.depth % block_extent.depth));
3394 }
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003395 }
3396
Dave Houltonfc1a4052017-04-27 14:32:45 -06003397 if (0 != ExceedsBounds(&offset, &extent, &image_extent)) {
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003398 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)0,
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003399 __LINE__, msg_code, "IMAGE", "%s: pRegion[%d] exceeds image bounds. %s.", func_name, i,
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003400 validation_error_map[msg_code]);
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003401 }
3402 }
3403
3404 return skip;
3405}
3406
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003407static inline bool ValidtateBufferBounds(const debug_report_data *report_data, IMAGE_STATE *image_state, BUFFER_STATE *buff_state,
3408 uint32_t regionCount, const VkBufferImageCopy *pRegions, const char *func_name,
3409 UNIQUE_VALIDATION_ERROR_CODE msg_code) {
3410 bool skip = false;
3411
3412 VkDeviceSize buffer_size = buff_state->createInfo.size;
3413
3414 for (uint32_t i = 0; i < regionCount; i++) {
3415 VkExtent3D copy_extent = pRegions[i].imageExtent;
3416
3417 VkDeviceSize buffer_width = (0 == pRegions[i].bufferRowLength ? copy_extent.width : pRegions[i].bufferRowLength);
3418 VkDeviceSize buffer_height = (0 == pRegions[i].bufferImageHeight ? copy_extent.height : pRegions[i].bufferImageHeight);
Dave Houlton1d2022c2017-03-29 11:43:58 -06003419 VkDeviceSize unit_size = FormatSize(image_state->createInfo.format); // size (bytes) of texel or block
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003420
Dave Houltonf3229d52017-02-21 15:59:08 -07003421 // Handle special buffer packing rules for specific depth/stencil formats
3422 if (pRegions[i].imageSubresource.aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) {
Dave Houlton1d2022c2017-03-29 11:43:58 -06003423 unit_size = FormatSize(VK_FORMAT_S8_UINT);
Dave Houltonf3229d52017-02-21 15:59:08 -07003424 } else if (pRegions[i].imageSubresource.aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) {
3425 switch (image_state->createInfo.format) {
3426 case VK_FORMAT_D16_UNORM_S8_UINT:
Dave Houlton1d2022c2017-03-29 11:43:58 -06003427 unit_size = FormatSize(VK_FORMAT_D16_UNORM);
Dave Houltonf3229d52017-02-21 15:59:08 -07003428 break;
3429 case VK_FORMAT_D32_SFLOAT_S8_UINT:
Dave Houlton1d2022c2017-03-29 11:43:58 -06003430 unit_size = FormatSize(VK_FORMAT_D32_SFLOAT);
Dave Houltonf3229d52017-02-21 15:59:08 -07003431 break;
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003432 case VK_FORMAT_X8_D24_UNORM_PACK32: // Fall through
Dave Houltonf3229d52017-02-21 15:59:08 -07003433 case VK_FORMAT_D24_UNORM_S8_UINT:
3434 unit_size = 4;
3435 break;
3436 default:
3437 break;
3438 }
3439 }
3440
Dave Houlton1d2022c2017-03-29 11:43:58 -06003441 if (FormatIsCompressed(image_state->createInfo.format)) {
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003442 // Switch to texel block units, rounding up for any partially-used blocks
Dave Houlton1d2022c2017-03-29 11:43:58 -06003443 auto block_dim = FormatCompressedTexelBlockExtent(image_state->createInfo.format);
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003444 buffer_width = (buffer_width + block_dim.width - 1) / block_dim.width;
3445 buffer_height = (buffer_height + block_dim.height - 1) / block_dim.height;
3446
3447 copy_extent.width = (copy_extent.width + block_dim.width - 1) / block_dim.width;
3448 copy_extent.height = (copy_extent.height + block_dim.height - 1) / block_dim.height;
3449 copy_extent.depth = (copy_extent.depth + block_dim.depth - 1) / block_dim.depth;
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003450 }
3451
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003452 // Either depth or layerCount may be greater than 1 (not both). This is the number of 'slices' to copy
3453 uint32_t z_copies = std::max(copy_extent.depth, pRegions[i].imageSubresource.layerCount);
3454 if (IsExtentSizeZero(&copy_extent) || (0 == z_copies)) {
3455 // TODO: Issure warning here? Already warned in ValidateImageBounds()...
3456 } else {
3457 // Calculate buffer offset of final copied byte, + 1.
3458 VkDeviceSize max_buffer_offset = (z_copies - 1) * buffer_height * buffer_width; // offset to slice
3459 max_buffer_offset += ((copy_extent.height - 1) * buffer_width) + copy_extent.width; // add row,col
3460 max_buffer_offset *= unit_size; // convert to bytes
3461 max_buffer_offset += pRegions[i].bufferOffset; // add initial offset (bytes)
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003462
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003463 if (buffer_size < max_buffer_offset) {
3464 skip |=
3465 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)0,
3466 __LINE__, msg_code, "IMAGE", "%s: pRegion[%d] exceeds buffer size of %" PRIu64 " bytes. %s.", func_name,
3467 i, buffer_size, validation_error_map[msg_code]);
3468 }
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003469 }
3470 }
3471
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003472 return skip;
3473}
3474
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003475bool PreCallValidateCmdCopyImageToBuffer(layer_data *device_data, VkImageLayout srcImageLayout, GLOBAL_CB_NODE *cb_node,
Mark Lobodzinski1fe9b002017-02-15 14:11:12 -07003476 IMAGE_STATE *src_image_state, BUFFER_STATE *dst_buffer_state, uint32_t regionCount,
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003477 const VkBufferImageCopy *pRegions, const char *func_name) {
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003478 const debug_report_data *report_data = core_validation::GetReportData(device_data);
3479 bool skip = ValidateBufferImageCopyData(report_data, regionCount, pRegions, src_image_state, "vkCmdCopyImageToBuffer");
3480
3481 // Validate command buffer state
3482 if (CB_RECORDING != cb_node->state) {
3483 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02003484 HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_01258, "DS",
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003485 "Cannot call vkCmdCopyImageToBuffer() on command buffer which is not in recording state. %s.",
3486 validation_error_map[VALIDATION_ERROR_01258]);
3487 } else {
3488 skip |= ValidateCmdSubpassState(device_data, cb_node, CMD_COPYIMAGETOBUFFER);
3489 }
3490
3491 // Command pool must support graphics, compute, or transfer operations
3492 auto pPool = GetCommandPoolNode(device_data, cb_node->createInfo.commandPool);
3493
3494 VkQueueFlags queue_flags = GetPhysDevProperties(device_data)->queue_family_properties[pPool->queueFamilyIndex].queueFlags;
3495 if (0 == (queue_flags & (VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT | VK_QUEUE_TRANSFER_BIT))) {
3496 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02003497 HandleToUint64(cb_node->createInfo.commandPool), __LINE__, VALIDATION_ERROR_01259, "DS",
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003498 "Cannot call vkCmdCopyImageToBuffer() on a command buffer allocated from a pool without graphics, compute, "
3499 "or transfer capabilities. %s.",
3500 validation_error_map[VALIDATION_ERROR_01259]);
3501 }
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003502 skip |= ValidateImageBounds(report_data, src_image_state, regionCount, pRegions, "vkCmdCopyBufferToImage()",
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003503 VALIDATION_ERROR_01245);
Mark Lobodzinski1fe9b002017-02-15 14:11:12 -07003504 skip |= ValidtateBufferBounds(report_data, src_image_state, dst_buffer_state, regionCount, pRegions, "vkCmdCopyImageToBuffer()",
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003505 VALIDATION_ERROR_01246);
3506
3507 skip |= ValidateImageSampleCount(device_data, src_image_state, VK_SAMPLE_COUNT_1_BIT, "vkCmdCopyImageToBuffer(): srcImage",
3508 VALIDATION_ERROR_01249);
3509 skip |= ValidateMemoryIsBoundToImage(device_data, src_image_state, "vkCmdCopyImageToBuffer()", VALIDATION_ERROR_02537);
Mark Lobodzinski1fe9b002017-02-15 14:11:12 -07003510 skip |= ValidateMemoryIsBoundToBuffer(device_data, dst_buffer_state, "vkCmdCopyImageToBuffer()", VALIDATION_ERROR_02538);
Mark Lobodzinski033c90b2017-02-15 13:58:23 -07003511
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003512 // Validate that SRC image & DST buffer have correct usage flags set
3513 skip |= ValidateImageUsageFlags(device_data, src_image_state, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, true, VALIDATION_ERROR_01248,
3514 "vkCmdCopyImageToBuffer()", "VK_IMAGE_USAGE_TRANSFER_SRC_BIT");
Mark Lobodzinski1fe9b002017-02-15 14:11:12 -07003515 skip |= ValidateBufferUsageFlags(device_data, dst_buffer_state, VK_BUFFER_USAGE_TRANSFER_DST_BIT, true, VALIDATION_ERROR_01252,
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003516 "vkCmdCopyImageToBuffer()", "VK_BUFFER_USAGE_TRANSFER_DST_BIT");
Mark Lobodzinski033c90b2017-02-15 13:58:23 -07003517 skip |= insideRenderPass(device_data, cb_node, "vkCmdCopyImageToBuffer()", VALIDATION_ERROR_01260);
Tobin Ehlisc8266452017-04-07 12:20:30 -06003518 bool hit_error = false;
Mark Lobodzinski033c90b2017-02-15 13:58:23 -07003519 for (uint32_t i = 0; i < regionCount; ++i) {
Tobin Ehlisc8266452017-04-07 12:20:30 -06003520 skip |=
3521 VerifyImageLayout(device_data, cb_node, src_image_state, pRegions[i].imageSubresource, srcImageLayout,
3522 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, "vkCmdCopyImageToBuffer()", VALIDATION_ERROR_01251, &hit_error);
Mark Lobodzinski033c90b2017-02-15 13:58:23 -07003523 skip |= ValidateCopyBufferImageTransferGranularityRequirements(device_data, cb_node, src_image_state, &pRegions[i], i,
Tobin Ehlis2d85ec62017-03-14 15:38:48 -06003524 "vkCmdCopyImageToBuffer()");
Mark Lobodzinski033c90b2017-02-15 13:58:23 -07003525 }
3526 return skip;
3527}
3528
3529void PreCallRecordCmdCopyImageToBuffer(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state,
Tobin Ehlise35b66a2017-03-15 12:18:31 -06003530 BUFFER_STATE *dst_buffer_state, uint32_t region_count, const VkBufferImageCopy *regions,
3531 VkImageLayout src_image_layout) {
3532 // Make sure that all image slices are updated to correct layout
3533 for (uint32_t i = 0; i < region_count; ++i) {
3534 SetImageLayout(device_data, cb_node, src_image_state, regions[i].imageSubresource, src_image_layout);
3535 }
Mark Lobodzinski033c90b2017-02-15 13:58:23 -07003536 // Update bindings between buffer/image and cmd buffer
3537 AddCommandBufferBindingImage(device_data, cb_node, src_image_state);
Mark Lobodzinski1fe9b002017-02-15 14:11:12 -07003538 AddCommandBufferBindingBuffer(device_data, cb_node, dst_buffer_state);
Mark Lobodzinski033c90b2017-02-15 13:58:23 -07003539
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003540 std::function<bool()> function = [=]() {
3541 return ValidateImageMemoryIsValid(device_data, src_image_state, "vkCmdCopyImageToBuffer()");
3542 };
3543 cb_node->validate_functions.push_back(function);
3544 function = [=]() {
Mark Lobodzinski1fe9b002017-02-15 14:11:12 -07003545 SetBufferMemoryValid(device_data, dst_buffer_state, true);
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003546 return false;
3547 };
3548 cb_node->validate_functions.push_back(function);
3549
3550 core_validation::UpdateCmdBufferLastCmd(cb_node, CMD_COPYIMAGETOBUFFER);
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003551}
3552
3553bool PreCallValidateCmdCopyBufferToImage(layer_data *device_data, VkImageLayout dstImageLayout, GLOBAL_CB_NODE *cb_node,
Mark Lobodzinski1fe9b002017-02-15 14:11:12 -07003554 BUFFER_STATE *src_buffer_state, IMAGE_STATE *dst_image_state, uint32_t regionCount,
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003555 const VkBufferImageCopy *pRegions, const char *func_name) {
3556 const debug_report_data *report_data = core_validation::GetReportData(device_data);
3557 bool skip = ValidateBufferImageCopyData(report_data, regionCount, pRegions, dst_image_state, "vkCmdCopyBufferToImage");
3558
3559 // Validate command buffer state
3560 if (CB_RECORDING != cb_node->state) {
3561 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02003562 HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_01240, "DS",
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003563 "Cannot call vkCmdCopyBufferToImage() on command buffer which is not in recording state. %s.",
3564 validation_error_map[VALIDATION_ERROR_01240]);
3565 } else {
3566 skip |= ValidateCmdSubpassState(device_data, cb_node, CMD_COPYBUFFERTOIMAGE);
3567 }
3568
3569 // Command pool must support graphics, compute, or transfer operations
3570 auto pPool = GetCommandPoolNode(device_data, cb_node->createInfo.commandPool);
3571 VkQueueFlags queue_flags = GetPhysDevProperties(device_data)->queue_family_properties[pPool->queueFamilyIndex].queueFlags;
3572 if (0 == (queue_flags & (VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT | VK_QUEUE_TRANSFER_BIT))) {
3573 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02003574 HandleToUint64(cb_node->createInfo.commandPool), __LINE__, VALIDATION_ERROR_01241, "DS",
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003575 "Cannot call vkCmdCopyBufferToImage() on a command buffer allocated from a pool without graphics, compute, "
3576 "or transfer capabilities. %s.",
3577 validation_error_map[VALIDATION_ERROR_01241]);
3578 }
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003579 skip |= ValidateImageBounds(report_data, dst_image_state, regionCount, pRegions, "vkCmdCopyBufferToImage()",
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003580 VALIDATION_ERROR_01228);
Mark Lobodzinski1fe9b002017-02-15 14:11:12 -07003581 skip |= ValidtateBufferBounds(report_data, dst_image_state, src_buffer_state, regionCount, pRegions, "vkCmdCopyBufferToImage()",
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003582 VALIDATION_ERROR_01227);
3583 skip |= ValidateImageSampleCount(device_data, dst_image_state, VK_SAMPLE_COUNT_1_BIT, "vkCmdCopyBufferToImage(): dstImage",
3584 VALIDATION_ERROR_01232);
Mark Lobodzinski1fe9b002017-02-15 14:11:12 -07003585 skip |= ValidateMemoryIsBoundToBuffer(device_data, src_buffer_state, "vkCmdCopyBufferToImage()", VALIDATION_ERROR_02535);
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003586 skip |= ValidateMemoryIsBoundToImage(device_data, dst_image_state, "vkCmdCopyBufferToImage()", VALIDATION_ERROR_02536);
Mark Lobodzinski1fe9b002017-02-15 14:11:12 -07003587 skip |= ValidateBufferUsageFlags(device_data, src_buffer_state, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, true, VALIDATION_ERROR_01230,
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003588 "vkCmdCopyBufferToImage()", "VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
3589 skip |= ValidateImageUsageFlags(device_data, dst_image_state, VK_IMAGE_USAGE_TRANSFER_DST_BIT, true, VALIDATION_ERROR_01231,
3590 "vkCmdCopyBufferToImage()", "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Mark Lobodzinski033c90b2017-02-15 13:58:23 -07003591 skip |= insideRenderPass(device_data, cb_node, "vkCmdCopyBufferToImage()", VALIDATION_ERROR_01242);
Tobin Ehlisc8266452017-04-07 12:20:30 -06003592 bool hit_error = false;
Mark Lobodzinski033c90b2017-02-15 13:58:23 -07003593 for (uint32_t i = 0; i < regionCount; ++i) {
Tobin Ehlisc8266452017-04-07 12:20:30 -06003594 skip |=
3595 VerifyImageLayout(device_data, cb_node, dst_image_state, pRegions[i].imageSubresource, dstImageLayout,
3596 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, "vkCmdCopyBufferToImage()", VALIDATION_ERROR_01234, &hit_error);
Mark Lobodzinski033c90b2017-02-15 13:58:23 -07003597 skip |= ValidateCopyBufferImageTransferGranularityRequirements(device_data, cb_node, dst_image_state, &pRegions[i], i,
3598 "vkCmdCopyBufferToImage()");
3599 }
3600 return skip;
3601}
3602
Mark Lobodzinski1fe9b002017-02-15 14:11:12 -07003603void PreCallRecordCmdCopyBufferToImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, BUFFER_STATE *src_buffer_state,
Tobin Ehlise35b66a2017-03-15 12:18:31 -06003604 IMAGE_STATE *dst_image_state, uint32_t region_count, const VkBufferImageCopy *regions,
3605 VkImageLayout dst_image_layout) {
3606 // Make sure that all image slices are updated to correct layout
3607 for (uint32_t i = 0; i < region_count; ++i) {
3608 SetImageLayout(device_data, cb_node, dst_image_state, regions[i].imageSubresource, dst_image_layout);
3609 }
Mark Lobodzinski1fe9b002017-02-15 14:11:12 -07003610 AddCommandBufferBindingBuffer(device_data, cb_node, src_buffer_state);
Mark Lobodzinski033c90b2017-02-15 13:58:23 -07003611 AddCommandBufferBindingImage(device_data, cb_node, dst_image_state);
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003612 std::function<bool()> function = [=]() {
3613 SetImageMemoryValid(device_data, dst_image_state, true);
3614 return false;
3615 };
3616 cb_node->validate_functions.push_back(function);
Mark Lobodzinski1fe9b002017-02-15 14:11:12 -07003617 function = [=]() { return ValidateBufferMemoryIsValid(device_data, src_buffer_state, "vkCmdCopyBufferToImage()"); };
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003618 cb_node->validate_functions.push_back(function);
3619
3620 core_validation::UpdateCmdBufferLastCmd(cb_node, CMD_COPYBUFFERTOIMAGE);
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003621}
Mike Weiblen672b58b2017-02-21 14:32:53 -07003622
3623bool PreCallValidateGetImageSubresourceLayout(layer_data *device_data, VkImage image, const VkImageSubresource *pSubresource) {
3624 const auto report_data = core_validation::GetReportData(device_data);
3625 bool skip = false;
3626 const VkImageAspectFlags sub_aspect = pSubresource->aspectMask;
3627
3628 // VU 00733: The aspectMask member of pSubresource must only have a single bit set
3629 const int num_bits = sizeof(sub_aspect) * CHAR_BIT;
3630 std::bitset<num_bits> aspect_mask_bits(sub_aspect);
3631 if (aspect_mask_bits.count() != 1) {
Petr Krausbc7f5442017-05-14 23:43:38 +02003632 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, HandleToUint64(image),
3633 __LINE__, VALIDATION_ERROR_00733, "IMAGE",
Mike Weiblen672b58b2017-02-21 14:32:53 -07003634 "vkGetImageSubresourceLayout(): VkImageSubresource.aspectMask must have exactly 1 bit set. %s",
3635 validation_error_map[VALIDATION_ERROR_00733]);
3636 }
3637
3638 IMAGE_STATE *image_entry = GetImageState(device_data, image);
3639 if (!image_entry) {
3640 return skip;
3641 }
3642
3643 // VU 00732: image must have been created with tiling equal to VK_IMAGE_TILING_LINEAR
3644 if (image_entry->createInfo.tiling != VK_IMAGE_TILING_LINEAR) {
Petr Krausbc7f5442017-05-14 23:43:38 +02003645 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, HandleToUint64(image),
3646 __LINE__, VALIDATION_ERROR_00732, "IMAGE",
Mike Weiblen672b58b2017-02-21 14:32:53 -07003647 "vkGetImageSubresourceLayout(): Image must have tiling of VK_IMAGE_TILING_LINEAR. %s",
3648 validation_error_map[VALIDATION_ERROR_00732]);
3649 }
3650
3651 // VU 00739: mipLevel must be less than the mipLevels specified in VkImageCreateInfo when the image was created
3652 if (pSubresource->mipLevel >= image_entry->createInfo.mipLevels) {
Petr Krausbc7f5442017-05-14 23:43:38 +02003653 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, HandleToUint64(image),
3654 __LINE__, VALIDATION_ERROR_00739, "IMAGE",
Mike Weiblen672b58b2017-02-21 14:32:53 -07003655 "vkGetImageSubresourceLayout(): pSubresource.mipLevel (%d) must be less than %d. %s",
3656 pSubresource->mipLevel, image_entry->createInfo.mipLevels, validation_error_map[VALIDATION_ERROR_00739]);
3657 }
3658
3659 // VU 00740: arrayLayer must be less than the arrayLayers specified in VkImageCreateInfo when the image was created
3660 if (pSubresource->arrayLayer >= image_entry->createInfo.arrayLayers) {
Petr Krausbc7f5442017-05-14 23:43:38 +02003661 skip |= log_msg(
3662 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, HandleToUint64(image), __LINE__,
3663 VALIDATION_ERROR_00740, "IMAGE", "vkGetImageSubresourceLayout(): pSubresource.arrayLayer (%d) must be less than %d. %s",
3664 pSubresource->arrayLayer, image_entry->createInfo.arrayLayers, validation_error_map[VALIDATION_ERROR_00740]);
Mike Weiblen672b58b2017-02-21 14:32:53 -07003665 }
3666
3667 // VU 00741: subresource's aspect must be compatible with image's format.
3668 const VkFormat img_format = image_entry->createInfo.format;
Dave Houlton1d2022c2017-03-29 11:43:58 -06003669 if (FormatIsColor(img_format)) {
Mike Weiblen672b58b2017-02-21 14:32:53 -07003670 if (sub_aspect != VK_IMAGE_ASPECT_COLOR_BIT) {
3671 skip |= log_msg(
Petr Krausbc7f5442017-05-14 23:43:38 +02003672 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, HandleToUint64(image), __LINE__,
3673 VALIDATION_ERROR_00741, "IMAGE",
Mike Weiblen672b58b2017-02-21 14:32:53 -07003674 "vkGetImageSubresourceLayout(): For color formats, VkImageSubresource.aspectMask must be VK_IMAGE_ASPECT_COLOR. %s",
3675 validation_error_map[VALIDATION_ERROR_00741]);
3676 }
Dave Houlton1d2022c2017-03-29 11:43:58 -06003677 } else if (FormatIsDepthOrStencil(img_format)) {
Mike Weiblen672b58b2017-02-21 14:32:53 -07003678 if ((sub_aspect != VK_IMAGE_ASPECT_DEPTH_BIT) && (sub_aspect != VK_IMAGE_ASPECT_STENCIL_BIT)) {
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06003679 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02003680 HandleToUint64(image), __LINE__, VALIDATION_ERROR_00741, "IMAGE",
Mike Weiblen672b58b2017-02-21 14:32:53 -07003681 "vkGetImageSubresourceLayout(): For depth/stencil formats, VkImageSubresource.aspectMask must be "
3682 "either VK_IMAGE_ASPECT_DEPTH_BIT or VK_IMAGE_ASPECT_STENCIL_BIT. %s",
3683 validation_error_map[VALIDATION_ERROR_00741]);
3684 }
3685 }
3686 return skip;
3687}