blob: 7739fe08f8b7e7d6f4236e10037b959564f65dbc [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) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -0600436 msg_code = VALIDATION_ERROR_0a000970;
Mike Weiblen62d08a32017-03-07 22:18:27 -0700437 }
438 break;
439 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
440 if ((usage_flags & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) == 0) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -0600441 msg_code = VALIDATION_ERROR_0a000972;
Mike Weiblen62d08a32017-03-07 22:18:27 -0700442 }
443 break;
444 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL:
445 if ((usage_flags & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) == 0) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -0600446 msg_code = VALIDATION_ERROR_0a000974;
Mike Weiblen62d08a32017-03-07 22:18:27 -0700447 }
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) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -0600451 msg_code = VALIDATION_ERROR_0a000976;
Mike Weiblen62d08a32017-03-07 22:18:27 -0700452 }
453 break;
454 case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL:
455 if ((usage_flags & VK_IMAGE_USAGE_TRANSFER_SRC_BIT) == 0) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -0600456 msg_code = VALIDATION_ERROR_0a000978;
Mike Weiblen62d08a32017-03-07 22:18:27 -0700457 }
458 break;
459 case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL:
460 if ((usage_flags & VK_IMAGE_USAGE_TRANSFER_DST_BIT) == 0) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -0600461 msg_code = VALIDATION_ERROR_0a00097a;
Mike Weiblen62d08a32017-03-07 22:18:27 -0700462 }
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__,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -0600517 VALIDATION_ERROR_0a00096e, "DS",
518 "%s: Image barrier 0x%p references image 0x%" PRIx64
519 " of format %s that must have the depth and stencil aspects set, but its "
520 "aspectMask is 0x%" PRIx32 ". %s",
Petr Krausbc7f5442017-05-14 23:43:38 +0200521 func_name, img_barrier, HandleToUint64(img_barrier->image), string_VkFormat(image_create_info->format),
Tobin Ehlis3c37fb32017-05-24 09:31:13 -0600522 aspect_mask, validation_error_map[VALIDATION_ERROR_0a00096e]);
Tobin Ehlis7ee9cbd2017-04-26 16:51:48 -0600523 }
524 }
Mark Lobodzinski903e5ff2017-03-23 09:43:35 -0600525 uint32_t level_count = ResolveRemainingLevels(&img_barrier->subresourceRange, image_create_info->mipLevels);
526 uint32_t layer_count = ResolveRemainingLayers(&img_barrier->subresourceRange, image_create_info->arrayLayers);
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700527
Mike Weiblen62d08a32017-03-07 22:18:27 -0700528 for (uint32_t j = 0; j < level_count; j++) {
529 uint32_t level = img_barrier->subresourceRange.baseMipLevel + j;
530 for (uint32_t k = 0; k < layer_count; k++) {
531 uint32_t layer = img_barrier->subresourceRange.baseArrayLayer + k;
532 skip |= ValidateImageAspectLayout(device_data, pCB, img_barrier, level, layer, VK_IMAGE_ASPECT_COLOR_BIT);
533 skip |= ValidateImageAspectLayout(device_data, pCB, img_barrier, level, layer, VK_IMAGE_ASPECT_DEPTH_BIT);
534 skip |= ValidateImageAspectLayout(device_data, pCB, img_barrier, level, layer, VK_IMAGE_ASPECT_STENCIL_BIT);
535 skip |= ValidateImageAspectLayout(device_data, pCB, img_barrier, level, layer, VK_IMAGE_ASPECT_METADATA_BIT);
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700536 }
537 }
538 }
539 return skip;
540}
541
Mark Lobodzinski6b6c50a2017-02-27 12:56:14 -0700542void TransitionImageLayouts(layer_data *device_data, VkCommandBuffer cmdBuffer, uint32_t memBarrierCount,
543 const VkImageMemoryBarrier *pImgMemBarriers) {
544 GLOBAL_CB_NODE *pCB = GetCBNode(device_data, cmdBuffer);
Mark Lobodzinski6b6c50a2017-02-27 12:56:14 -0700545
546 for (uint32_t i = 0; i < memBarrierCount; ++i) {
547 auto mem_barrier = &pImgMemBarriers[i];
548 if (!mem_barrier) continue;
Mark Lobodzinski6b6c50a2017-02-27 12:56:14 -0700549
Mark Lobodzinski903e5ff2017-03-23 09:43:35 -0600550 VkImageCreateInfo *image_create_info = &(GetImageState(device_data, mem_barrier->image)->createInfo);
551 uint32_t level_count = ResolveRemainingLevels(&mem_barrier->subresourceRange, image_create_info->mipLevels);
552 uint32_t layer_count = ResolveRemainingLayers(&mem_barrier->subresourceRange, image_create_info->arrayLayers);
553
554 for (uint32_t j = 0; j < level_count; j++) {
Mark Lobodzinski6b6c50a2017-02-27 12:56:14 -0700555 uint32_t level = mem_barrier->subresourceRange.baseMipLevel + j;
Mark Lobodzinski903e5ff2017-03-23 09:43:35 -0600556 for (uint32_t k = 0; k < layer_count; k++) {
Mark Lobodzinski6b6c50a2017-02-27 12:56:14 -0700557 uint32_t layer = mem_barrier->subresourceRange.baseArrayLayer + k;
558 TransitionImageAspectLayout(device_data, pCB, mem_barrier, level, layer, VK_IMAGE_ASPECT_COLOR_BIT);
559 TransitionImageAspectLayout(device_data, pCB, mem_barrier, level, layer, VK_IMAGE_ASPECT_DEPTH_BIT);
560 TransitionImageAspectLayout(device_data, pCB, mem_barrier, level, layer, VK_IMAGE_ASPECT_STENCIL_BIT);
561 TransitionImageAspectLayout(device_data, pCB, mem_barrier, level, layer, VK_IMAGE_ASPECT_METADATA_BIT);
562 }
563 }
564 }
565}
566
Tobin Ehlisc8266452017-04-07 12:20:30 -0600567bool VerifyImageLayout(layer_data const *device_data, GLOBAL_CB_NODE const *cb_node, IMAGE_STATE *image_state,
Tobin Ehlis2d85ec62017-03-14 15:38:48 -0600568 VkImageSubresourceLayers subLayers, VkImageLayout explicit_layout, VkImageLayout optimal_layout,
Tobin Ehlisc8266452017-04-07 12:20:30 -0600569 const char *caller, UNIQUE_VALIDATION_ERROR_CODE msg_code, bool *error) {
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700570 const auto report_data = core_validation::GetReportData(device_data);
Tobin Ehlis2d85ec62017-03-14 15:38:48 -0600571 const auto image = image_state->image;
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600572 bool skip = false;
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700573
574 for (uint32_t i = 0; i < subLayers.layerCount; ++i) {
575 uint32_t layer = i + subLayers.baseArrayLayer;
576 VkImageSubresource sub = {subLayers.aspectMask, subLayers.mipLevel, layer};
577 IMAGE_CMD_BUF_LAYOUT_NODE node;
Tobin Ehlise35b66a2017-03-15 12:18:31 -0600578 if (FindCmdBufLayout(device_data, cb_node, image, sub, node)) {
579 if (node.layout != explicit_layout) {
Tobin Ehlisc8266452017-04-07 12:20:30 -0600580 *error = true;
Tobin Ehlise35b66a2017-03-15 12:18:31 -0600581 // TODO: Improve log message in the next pass
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600582 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 +0200583 HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600584 "%s: Cannot use image 0x%" PRIxLEAST64
585 " with specific layout %s that doesn't match the actual current layout %s.",
Petr Krausbc7f5442017-05-14 23:43:38 +0200586 caller, HandleToUint64(image), string_VkImageLayout(explicit_layout),
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600587 string_VkImageLayout(node.layout));
Tobin Ehlise35b66a2017-03-15 12:18:31 -0600588 }
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700589 }
590 }
Tobin Ehlis2d85ec62017-03-14 15:38:48 -0600591 // If optimal_layout is not UNDEFINED, check that layout matches optimal for this case
592 if ((VK_IMAGE_LAYOUT_UNDEFINED != optimal_layout) && (explicit_layout != optimal_layout)) {
593 if (VK_IMAGE_LAYOUT_GENERAL == explicit_layout) {
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700594 if (image_state->createInfo.tiling != VK_IMAGE_TILING_LINEAR) {
595 // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning.
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600596 skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +0200597 VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, HandleToUint64(cb_node->commandBuffer), __LINE__,
598 DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600599 "%s: For optimal performance image 0x%" PRIxLEAST64 " layout should be %s instead of GENERAL.",
Petr Krausbc7f5442017-05-14 23:43:38 +0200600 caller, HandleToUint64(image), string_VkImageLayout(optimal_layout));
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700601 }
Mark Lobodzinski28426ae2017-06-01 07:56:38 -0600602 } else if (GetDeviceExtensions(device_data)->vk_khr_shared_presentable_image) {
Mark Lobodzinski087380c2017-05-16 14:42:25 -0600603 if (image_state->shared_presentable) {
604 if (VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR != explicit_layout) {
605 // TODO: Add unique error id when available.
606 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
607 __LINE__, msg_code, "DS",
608 "Layout for shared presentable image is %s but must be VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR.",
609 string_VkImageLayout(optimal_layout));
610 }
Tobin Ehlisbb03e5f2017-05-11 08:52:51 -0600611 }
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700612 } else {
Tobin Ehlisc8266452017-04-07 12:20:30 -0600613 *error = true;
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600614 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 +0200615 HandleToUint64(cb_node->commandBuffer), __LINE__, msg_code, "DS",
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600616 "%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 +0200617 caller, HandleToUint64(image), string_VkImageLayout(explicit_layout),
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600618 string_VkImageLayout(optimal_layout), validation_error_map[msg_code]);
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700619 }
620 }
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600621 return skip;
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700622}
623
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700624void TransitionFinalSubpassLayouts(layer_data *device_data, GLOBAL_CB_NODE *pCB, const VkRenderPassBeginInfo *pRenderPassBegin,
625 FRAMEBUFFER_STATE *framebuffer_state) {
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -0700626 auto renderPass = GetRenderPassState(device_data, pRenderPassBegin->renderPass);
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700627 if (!renderPass) return;
628
629 const VkRenderPassCreateInfo *pRenderPassInfo = renderPass->createInfo.ptr();
630 if (framebuffer_state) {
631 for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) {
632 auto image_view = framebuffer_state->createInfo.pAttachments[i];
633 SetImageViewLayout(device_data, pCB, image_view, pRenderPassInfo->pAttachments[i].finalLayout);
634 }
635 }
636}
637
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700638bool PreCallValidateCreateImage(layer_data *device_data, const VkImageCreateInfo *pCreateInfo,
Mark Lobodzinski90224de2017-01-26 15:23:11 -0700639 const VkAllocationCallbacks *pAllocator, VkImage *pImage) {
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600640 bool skip = false;
Mark Lobodzinski90224de2017-01-26 15:23:11 -0700641 const debug_report_data *report_data = core_validation::GetReportData(device_data);
642
Jeremy Hayes96dcd812017-03-14 14:04:19 -0600643 if (pCreateInfo->format == VK_FORMAT_UNDEFINED) {
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600644 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -0600645 VALIDATION_ERROR_09e0075e, "IMAGE", "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED. %s",
646 validation_error_map[VALIDATION_ERROR_09e0075e]);
Jeremy Hayes96dcd812017-03-14 14:04:19 -0600647
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600648 return skip;
Jeremy Hayes96dcd812017-03-14 14:04:19 -0600649 }
650
651 const VkFormatProperties *properties = GetFormatProperties(device_data, pCreateInfo->format);
652
653 if ((pCreateInfo->tiling == VK_IMAGE_TILING_LINEAR) && (properties->linearTilingFeatures == 0)) {
654 std::stringstream ss;
655 ss << "vkCreateImage format parameter (" << string_VkFormat(pCreateInfo->format) << ") is an unsupported format";
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600656 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -0600657 VALIDATION_ERROR_09e007a2, "IMAGE", "%s. %s", ss.str().c_str(),
658 validation_error_map[VALIDATION_ERROR_09e007a2]);
Jeremy Hayes96dcd812017-03-14 14:04:19 -0600659
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600660 return skip;
Jeremy Hayes96dcd812017-03-14 14:04:19 -0600661 }
662
663 if ((pCreateInfo->tiling == VK_IMAGE_TILING_OPTIMAL) && (properties->optimalTilingFeatures == 0)) {
664 std::stringstream ss;
665 ss << "vkCreateImage format parameter (" << string_VkFormat(pCreateInfo->format) << ") is an unsupported format";
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600666 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -0600667 VALIDATION_ERROR_09e007ac, "IMAGE", "%s. %s", ss.str().c_str(),
668 validation_error_map[VALIDATION_ERROR_09e007ac]);
Jeremy Hayes96dcd812017-03-14 14:04:19 -0600669
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600670 return skip;
Jeremy Hayes96dcd812017-03-14 14:04:19 -0600671 }
672
673 // Validate that format supports usage as color attachment
674 if (pCreateInfo->usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) {
675 if ((pCreateInfo->tiling == VK_IMAGE_TILING_OPTIMAL) &&
676 ((properties->optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) == 0)) {
677 std::stringstream ss;
678 ss << "vkCreateImage: VkFormat for TILING_OPTIMAL image (" << string_VkFormat(pCreateInfo->format)
679 << ") does not support requested Image usage type VK_IMAGE_USAGE_COLOR_ATTACHMENT";
Tobin Ehlis3c37fb32017-05-24 09:31:13 -0600680 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
681 VALIDATION_ERROR_09e007b2, "IMAGE", "%s. %s", ss.str().c_str(),
682 validation_error_map[VALIDATION_ERROR_09e007b2]);
Jeremy Hayes96dcd812017-03-14 14:04:19 -0600683 }
684 if ((pCreateInfo->tiling == VK_IMAGE_TILING_LINEAR) &&
685 ((properties->linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) == 0)) {
686 std::stringstream ss;
687 ss << "vkCreateImage: VkFormat for TILING_LINEAR image (" << string_VkFormat(pCreateInfo->format)
688 << ") does not support requested Image usage type VK_IMAGE_USAGE_COLOR_ATTACHMENT";
Tobin Ehlis3c37fb32017-05-24 09:31:13 -0600689 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
690 VALIDATION_ERROR_09e007a8, "IMAGE", "%s. %s", ss.str().c_str(),
691 validation_error_map[VALIDATION_ERROR_09e007a8]);
Jeremy Hayes96dcd812017-03-14 14:04:19 -0600692 }
693 }
694
695 // Validate that format supports usage as depth/stencil attachment
696 if (pCreateInfo->usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) {
697 if ((pCreateInfo->tiling == VK_IMAGE_TILING_OPTIMAL) &&
698 ((properties->optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) == 0)) {
699 std::stringstream ss;
700 ss << "vkCreateImage: VkFormat for TILING_OPTIMAL image (" << string_VkFormat(pCreateInfo->format)
701 << ") does not support requested Image usage type VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT";
Tobin Ehlis3c37fb32017-05-24 09:31:13 -0600702 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
703 VALIDATION_ERROR_09e007b4, "IMAGE", "%s. %s", ss.str().c_str(),
704 validation_error_map[VALIDATION_ERROR_09e007b4]);
Jeremy Hayes96dcd812017-03-14 14:04:19 -0600705 }
706 if ((pCreateInfo->tiling == VK_IMAGE_TILING_LINEAR) &&
707 ((properties->linearTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) == 0)) {
708 std::stringstream ss;
709 ss << "vkCreateImage: VkFormat for TILING_LINEAR image (" << string_VkFormat(pCreateInfo->format)
710 << ") does not support requested Image usage type VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT";
Tobin Ehlis3c37fb32017-05-24 09:31:13 -0600711 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
712 VALIDATION_ERROR_09e007aa, "IMAGE", "%s. %s", ss.str().c_str(),
713 validation_error_map[VALIDATION_ERROR_09e007aa]);
Jeremy Hayes96dcd812017-03-14 14:04:19 -0600714 }
Mark Lobodzinski90224de2017-01-26 15:23:11 -0700715 }
716
Mark Lobodzinskiefd933b2017-02-10 12:09:23 -0700717 const VkImageFormatProperties *ImageFormatProperties = GetImageFormatProperties(
718 device_data, pCreateInfo->format, pCreateInfo->imageType, pCreateInfo->tiling, pCreateInfo->usage, pCreateInfo->flags);
Mark Lobodzinski90224de2017-01-26 15:23:11 -0700719
Mark Lobodzinskiefd933b2017-02-10 12:09:23 -0700720 VkDeviceSize imageGranularity = GetPhysicalDeviceProperties(device_data)->limits.bufferImageGranularity;
Mark Lobodzinski90224de2017-01-26 15:23:11 -0700721 imageGranularity = imageGranularity == 1 ? 0 : imageGranularity;
Tobin Ehlisa55b1d42017-04-04 12:23:48 -0600722 // TODO : This is also covering 2918 & 2919. Break out into separate checks
Mark Lobodzinski688ed322017-01-27 11:13:21 -0700723 if ((pCreateInfo->extent.width <= 0) || (pCreateInfo->extent.height <= 0) || (pCreateInfo->extent.depth <= 0)) {
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600724 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -0600725 VALIDATION_ERROR_09e007b8, "Image",
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600726 "CreateImage extent is 0 for at least one required dimension for image: "
727 "Width = %d Height = %d Depth = %d. %s",
728 pCreateInfo->extent.width, pCreateInfo->extent.height, pCreateInfo->extent.depth,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -0600729 validation_error_map[VALIDATION_ERROR_09e007b8]);
Mark Lobodzinski90224de2017-01-26 15:23:11 -0700730 }
731
Tobin Ehlis3c37fb32017-05-24 09:31:13 -0600732 // TODO: VALIDATION_ERROR_09e00770 VALIDATION_ERROR_09e00772 VALIDATION_ERROR_09e00776 VALIDATION_ERROR_09e0076e
Mark Lobodzinski90224de2017-01-26 15:23:11 -0700733 // All these extent-related VUs should be checked here
Mark Lobodzinskiefd933b2017-02-10 12:09:23 -0700734 if ((pCreateInfo->extent.depth > ImageFormatProperties->maxExtent.depth) ||
735 (pCreateInfo->extent.width > ImageFormatProperties->maxExtent.width) ||
736 (pCreateInfo->extent.height > ImageFormatProperties->maxExtent.height)) {
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600737 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__,
738 IMAGE_INVALID_FORMAT_LIMITS_VIOLATION, "Image",
739 "CreateImage extents exceed allowable limits for format: "
740 "Width = %d Height = %d Depth = %d: Limits for Width = %d Height = %d Depth = %d for format %s.",
741 pCreateInfo->extent.width, pCreateInfo->extent.height, pCreateInfo->extent.depth,
742 ImageFormatProperties->maxExtent.width, ImageFormatProperties->maxExtent.height,
743 ImageFormatProperties->maxExtent.depth, string_VkFormat(pCreateInfo->format));
Mark Lobodzinski90224de2017-01-26 15:23:11 -0700744 }
745
Dave Houlton1150cf52017-04-27 14:38:11 -0600746 uint64_t totalSize =
747 ((uint64_t)pCreateInfo->extent.width * (uint64_t)pCreateInfo->extent.height * (uint64_t)pCreateInfo->extent.depth *
748 (uint64_t)pCreateInfo->arrayLayers * (uint64_t)pCreateInfo->samples * (uint64_t)FormatSize(pCreateInfo->format) +
749 (uint64_t)imageGranularity) &
750 ~(uint64_t)imageGranularity;
Mark Lobodzinski90224de2017-01-26 15:23:11 -0700751
Mark Lobodzinskiefd933b2017-02-10 12:09:23 -0700752 if (totalSize > ImageFormatProperties->maxResourceSize) {
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600753 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__,
754 IMAGE_INVALID_FORMAT_LIMITS_VIOLATION, "Image",
755 "CreateImage resource size exceeds allowable maximum "
756 "Image resource size = 0x%" PRIxLEAST64 ", maximum resource size = 0x%" PRIxLEAST64 " ",
757 totalSize, ImageFormatProperties->maxResourceSize);
Mark Lobodzinski90224de2017-01-26 15:23:11 -0700758 }
759
Tobin Ehlis3c37fb32017-05-24 09:31:13 -0600760 // TODO: VALIDATION_ERROR_09e0077e
Mark Lobodzinskiefd933b2017-02-10 12:09:23 -0700761 if (pCreateInfo->mipLevels > ImageFormatProperties->maxMipLevels) {
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600762 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__,
763 IMAGE_INVALID_FORMAT_LIMITS_VIOLATION, "Image",
764 "CreateImage mipLevels=%d exceeds allowable maximum supported by format of %d", pCreateInfo->mipLevels,
765 ImageFormatProperties->maxMipLevels);
Mark Lobodzinski90224de2017-01-26 15:23:11 -0700766 }
767
Mark Lobodzinskiefd933b2017-02-10 12:09:23 -0700768 if (pCreateInfo->arrayLayers > ImageFormatProperties->maxArrayLayers) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -0600769 skip |=
770 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__,
771 VALIDATION_ERROR_09e00780, "Image",
772 "CreateImage arrayLayers=%d exceeds allowable maximum supported by format of %d. %s", pCreateInfo->arrayLayers,
773 ImageFormatProperties->maxArrayLayers, validation_error_map[VALIDATION_ERROR_09e00780]);
Mark Lobodzinski90224de2017-01-26 15:23:11 -0700774 }
775
Mark Lobodzinskiefd933b2017-02-10 12:09:23 -0700776 if ((pCreateInfo->samples & ImageFormatProperties->sampleCounts) == 0) {
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600777 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -0600778 VALIDATION_ERROR_09e0078e, "Image", "CreateImage samples %s is not supported by format 0x%.8X. %s",
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600779 string_VkSampleCountFlagBits(pCreateInfo->samples), ImageFormatProperties->sampleCounts,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -0600780 validation_error_map[VALIDATION_ERROR_09e0078e]);
Mark Lobodzinski90224de2017-01-26 15:23:11 -0700781 }
782
783 if (pCreateInfo->initialLayout != VK_IMAGE_LAYOUT_UNDEFINED && pCreateInfo->initialLayout != VK_IMAGE_LAYOUT_PREINITIALIZED) {
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600784 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -0600785 VALIDATION_ERROR_09e0b801, "Image",
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600786 "vkCreateImage parameter, pCreateInfo->initialLayout, must be VK_IMAGE_LAYOUT_UNDEFINED or "
787 "VK_IMAGE_LAYOUT_PREINITIALIZED. %s",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -0600788 validation_error_map[VALIDATION_ERROR_09e0b801]);
Mark Lobodzinski90224de2017-01-26 15:23:11 -0700789 }
790
Mark Lobodzinski847b60c2017-03-13 09:32:45 -0600791 if ((pCreateInfo->flags & VK_IMAGE_CREATE_SPARSE_BINDING_BIT) && (!GetEnabledFeatures(device_data)->sparseBinding)) {
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600792 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -0600793 VALIDATION_ERROR_09e00792, "DS",
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600794 "vkCreateImage(): the sparseBinding device feature is disabled: Images cannot be created with the "
795 "VK_IMAGE_CREATE_SPARSE_BINDING_BIT set. %s",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -0600796 validation_error_map[VALIDATION_ERROR_09e00792]);
Mark Lobodzinski847b60c2017-03-13 09:32:45 -0600797 }
798
Mark Lobodzinski035a4cf2017-03-13 09:45:07 -0600799 if ((pCreateInfo->flags & VK_IMAGE_CREATE_SPARSE_ALIASED_BIT) && (!GetEnabledFeatures(device_data)->sparseResidencyAliased)) {
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600800 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
801 DRAWSTATE_INVALID_FEATURE, "DS",
802 "vkCreateImage(): the sparseResidencyAliased device feature is disabled: Images cannot be created with the "
803 "VK_IMAGE_CREATE_SPARSE_ALIASED_BIT set.");
Mark Lobodzinski035a4cf2017-03-13 09:45:07 -0600804 }
805
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600806 return skip;
Mark Lobodzinski90224de2017-01-26 15:23:11 -0700807}
808
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700809void PostCallRecordCreateImage(layer_data *device_data, const VkImageCreateInfo *pCreateInfo, VkImage *pImage) {
Mark Lobodzinski42fe5f72017-01-11 11:36:16 -0700810 IMAGE_LAYOUT_NODE image_state;
811 image_state.layout = pCreateInfo->initialLayout;
812 image_state.format = pCreateInfo->format;
Mark Lobodzinski214144a2017-01-27 14:25:32 -0700813 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 -0700814 ImageSubresourcePair subpair{*pImage, false, VkImageSubresource()};
Mark Lobodzinski214144a2017-01-27 14:25:32 -0700815 (*core_validation::GetImageSubresourceMap(device_data))[*pImage].push_back(subpair);
816 (*core_validation::GetImageLayoutMap(device_data))[subpair] = image_state;
Mark Lobodzinski42fe5f72017-01-11 11:36:16 -0700817}
Mark Lobodzinski9ef5d562017-01-27 12:28:30 -0700818
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700819bool PreCallValidateDestroyImage(layer_data *device_data, VkImage image, IMAGE_STATE **image_state, VK_OBJECT *obj_struct) {
Mark Lobodzinski9ef5d562017-01-27 12:28:30 -0700820 const CHECK_DISABLED *disabled = core_validation::GetDisables(device_data);
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -0700821 *image_state = core_validation::GetImageState(device_data, image);
Petr Krausbc7f5442017-05-14 23:43:38 +0200822 *obj_struct = {HandleToUint64(image), kVulkanObjectTypeImage};
Mark Lobodzinski9ef5d562017-01-27 12:28:30 -0700823 if (disabled->destroy_image) return false;
824 bool skip = false;
825 if (*image_state) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -0600826 skip |= core_validation::ValidateObjectNotInUse(device_data, *image_state, *obj_struct, VALIDATION_ERROR_252007d0);
Mark Lobodzinski9ef5d562017-01-27 12:28:30 -0700827 }
828 return skip;
829}
830
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700831void PostCallRecordDestroyImage(layer_data *device_data, VkImage image, IMAGE_STATE *image_state, VK_OBJECT obj_struct) {
Mark Lobodzinski9ef5d562017-01-27 12:28:30 -0700832 core_validation::invalidateCommandBuffers(device_data, image_state->cb_bindings, obj_struct);
833 // Clean up memory mapping, bindings and range references for image
834 for (auto mem_binding : image_state->GetBoundMemory()) {
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -0700835 auto mem_info = core_validation::GetMemObjInfo(device_data, mem_binding);
Mark Lobodzinski9ef5d562017-01-27 12:28:30 -0700836 if (mem_info) {
837 core_validation::RemoveImageMemoryRange(obj_struct.handle, mem_info);
838 }
839 }
Mark Lobodzinski33826372017-04-13 11:10:11 -0600840 core_validation::ClearMemoryObjectBindings(device_data, obj_struct.handle, kVulkanObjectTypeImage);
Mark Lobodzinski9ef5d562017-01-27 12:28:30 -0700841 // Remove image from imageMap
842 core_validation::GetImageMap(device_data)->erase(image);
843 std::unordered_map<VkImage, std::vector<ImageSubresourcePair>> *imageSubresourceMap =
844 core_validation::GetImageSubresourceMap(device_data);
845
846 const auto &sub_entry = imageSubresourceMap->find(image);
847 if (sub_entry != imageSubresourceMap->end()) {
848 for (const auto &pair : sub_entry->second) {
849 core_validation::GetImageLayoutMap(device_data)->erase(pair);
850 }
851 imageSubresourceMap->erase(sub_entry);
852 }
853}
Mark Lobodzinskic409a582017-01-27 15:16:01 -0700854
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700855bool ValidateImageAttributes(layer_data *device_data, IMAGE_STATE *image_state, VkImageSubresourceRange range) {
Mark Lobodzinskic409a582017-01-27 15:16:01 -0700856 bool skip = false;
857 const debug_report_data *report_data = core_validation::GetReportData(device_data);
858
859 if (range.aspectMask != VK_IMAGE_ASPECT_COLOR_BIT) {
860 char const str[] = "vkCmdClearColorImage aspectMasks for all subresource ranges must be set to VK_IMAGE_ASPECT_COLOR_BIT";
861 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 +0200862 HandleToUint64(image_state->image), __LINE__, DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", str);
Mark Lobodzinskic409a582017-01-27 15:16:01 -0700863 }
864
Dave Houlton1d2022c2017-03-29 11:43:58 -0600865 if (FormatIsDepthOrStencil(image_state->createInfo.format)) {
Mark Lobodzinskic409a582017-01-27 15:16:01 -0700866 char const str[] = "vkCmdClearColorImage called with depth/stencil image.";
867 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -0600868 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_1880000e, "IMAGE", "%s. %s", str,
869 validation_error_map[VALIDATION_ERROR_1880000e]);
Dave Houlton1d2022c2017-03-29 11:43:58 -0600870 } else if (FormatIsCompressed(image_state->createInfo.format)) {
Mark Lobodzinskic409a582017-01-27 15:16:01 -0700871 char const str[] = "vkCmdClearColorImage called with compressed image.";
872 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -0600873 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_1880000e, "IMAGE", "%s. %s", str,
874 validation_error_map[VALIDATION_ERROR_1880000e]);
Mark Lobodzinskic409a582017-01-27 15:16:01 -0700875 }
876
877 if (!(image_state->createInfo.usage & VK_IMAGE_USAGE_TRANSFER_DST_BIT)) {
878 char const str[] = "vkCmdClearColorImage called with image created without VK_IMAGE_USAGE_TRANSFER_DST_BIT.";
879 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -0600880 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_18800004, "IMAGE", "%s. %s", str,
881 validation_error_map[VALIDATION_ERROR_18800004]);
Mark Lobodzinskic409a582017-01-27 15:16:01 -0700882 }
883 return skip;
884}
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700885
Mark Lobodzinski903e5ff2017-03-23 09:43:35 -0600886uint32_t ResolveRemainingLevels(const VkImageSubresourceRange *range, uint32_t mip_levels) {
887 // Return correct number of mip levels taking into account VK_REMAINING_MIP_LEVELS
888 uint32_t mip_level_count = range->levelCount;
Mark Lobodzinski9c93dbd2017-02-02 08:31:18 -0700889 if (range->levelCount == VK_REMAINING_MIP_LEVELS) {
Mark Lobodzinski903e5ff2017-03-23 09:43:35 -0600890 mip_level_count = mip_levels - range->baseMipLevel;
Mark Lobodzinski9c93dbd2017-02-02 08:31:18 -0700891 }
Mark Lobodzinski903e5ff2017-03-23 09:43:35 -0600892 return mip_level_count;
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700893}
894
Mark Lobodzinski903e5ff2017-03-23 09:43:35 -0600895uint32_t ResolveRemainingLayers(const VkImageSubresourceRange *range, uint32_t layers) {
896 // Return correct number of layers taking into account VK_REMAINING_ARRAY_LAYERS
897 uint32_t array_layer_count = range->layerCount;
898 if (range->layerCount == VK_REMAINING_ARRAY_LAYERS) {
899 array_layer_count = layers - range->baseArrayLayer;
Mark Lobodzinski9c93dbd2017-02-02 08:31:18 -0700900 }
Mark Lobodzinski903e5ff2017-03-23 09:43:35 -0600901 return array_layer_count;
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700902}
903
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700904bool VerifyClearImageLayout(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *image_state,
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700905 VkImageSubresourceRange range, VkImageLayout dest_image_layout, const char *func_name) {
906 bool skip = false;
907 const debug_report_data *report_data = core_validation::GetReportData(device_data);
908
Mark Lobodzinski903e5ff2017-03-23 09:43:35 -0600909 uint32_t level_count = ResolveRemainingLevels(&range, image_state->createInfo.mipLevels);
910 uint32_t layer_count = ResolveRemainingLayers(&range, image_state->createInfo.arrayLayers);
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700911
912 if (dest_image_layout != VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) {
913 if (dest_image_layout == VK_IMAGE_LAYOUT_GENERAL) {
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700914 if (image_state->createInfo.tiling != VK_IMAGE_TILING_LINEAR) {
915 // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning.
Mark Lobodzinski0827aec2017-03-21 16:41:45 -0600916 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 +0200917 HandleToUint64(image_state->image), __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700918 "%s: Layout for cleared image should be TRANSFER_DST_OPTIMAL instead of GENERAL.", func_name);
919 }
Mark Lobodzinski087380c2017-05-16 14:42:25 -0600920 } else if (VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR == dest_image_layout) {
Mark Lobodzinski28426ae2017-06-01 07:56:38 -0600921 if (!GetDeviceExtensions(device_data)->vk_khr_shared_presentable_image) {
Tobin Ehlisfb0661c2017-05-11 08:52:51 -0600922 // TODO: Add unique error id when available.
Mark Lobodzinski087380c2017-05-16 14:42:25 -0600923 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 -0600924 HandleToUint64(image_state->image), __LINE__, 0, "DS",
Mark Lobodzinski087380c2017-05-16 14:42:25 -0600925 "Must enable VK_KHR_shared_presentable_image extension before creating images with a layout type "
926 "of VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR.");
927
928 } else {
929 if (image_state->shared_presentable) {
930 skip |= log_msg(
931 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Tobin Ehlisfb0661c2017-05-11 08:52:51 -0600932 HandleToUint64(image_state->image), __LINE__, 0, "DS",
Mark Lobodzinski087380c2017-05-16 14:42:25 -0600933 "Layout for shared presentable cleared image is %s but can only be VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR.",
934 string_VkImageLayout(dest_image_layout));
935 }
Tobin Ehlisbb03e5f2017-05-11 08:52:51 -0600936 }
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700937 } else {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -0600938 UNIQUE_VALIDATION_ERROR_CODE error_code = VALIDATION_ERROR_1880000a;
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700939 if (strcmp(func_name, "vkCmdClearDepthStencilImage()") == 0) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -0600940 error_code = VALIDATION_ERROR_18a00018;
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700941 } else {
942 assert(strcmp(func_name, "vkCmdClearColorImage()") == 0);
943 }
Mark Lobodzinski0827aec2017-03-21 16:41:45 -0600944 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 +0200945 HandleToUint64(image_state->image), __LINE__, error_code, "DS",
Mark Lobodzinski0827aec2017-03-21 16:41:45 -0600946 "%s: Layout for cleared image is %s but can only be "
947 "TRANSFER_DST_OPTIMAL or GENERAL. %s",
948 func_name, string_VkImageLayout(dest_image_layout), validation_error_map[error_code]);
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700949 }
950 }
951
Mark Lobodzinski903e5ff2017-03-23 09:43:35 -0600952 for (uint32_t level_index = 0; level_index < level_count; ++level_index) {
953 uint32_t level = level_index + range.baseMipLevel;
954 for (uint32_t layer_index = 0; layer_index < layer_count; ++layer_index) {
955 uint32_t layer = layer_index + range.baseArrayLayer;
956 VkImageSubresource sub = {range.aspectMask, level, layer};
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700957 IMAGE_CMD_BUF_LAYOUT_NODE node;
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700958 if (FindCmdBufLayout(device_data, cb_node, image_state->image, sub, node)) {
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700959 if (node.layout != dest_image_layout) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -0600960 UNIQUE_VALIDATION_ERROR_CODE error_code = VALIDATION_ERROR_18800008;
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700961 if (strcmp(func_name, "vkCmdClearDepthStencilImage()") == 0) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -0600962 error_code = VALIDATION_ERROR_18a00016;
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700963 } else {
964 assert(strcmp(func_name, "vkCmdClearColorImage()") == 0);
965 }
966 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0,
967 __LINE__, error_code, "DS",
968 "%s: Cannot clear an image whose layout is %s and "
969 "doesn't match the current layout %s. %s",
970 func_name, string_VkImageLayout(dest_image_layout), string_VkImageLayout(node.layout),
971 validation_error_map[error_code]);
972 }
973 }
974 }
975 }
976
977 return skip;
978}
979
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700980void RecordClearImageLayout(layer_data *device_data, GLOBAL_CB_NODE *cb_node, VkImage image, VkImageSubresourceRange range,
981 VkImageLayout dest_image_layout) {
Mark Lobodzinski903e5ff2017-03-23 09:43:35 -0600982 VkImageCreateInfo *image_create_info = &(GetImageState(device_data, image)->createInfo);
983 uint32_t level_count = ResolveRemainingLevels(&range, image_create_info->mipLevels);
984 uint32_t layer_count = ResolveRemainingLayers(&range, image_create_info->arrayLayers);
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700985
Mark Lobodzinski903e5ff2017-03-23 09:43:35 -0600986 for (uint32_t level_index = 0; level_index < level_count; ++level_index) {
987 uint32_t level = level_index + range.baseMipLevel;
988 for (uint32_t layer_index = 0; layer_index < layer_count; ++layer_index) {
989 uint32_t layer = layer_index + range.baseArrayLayer;
990 VkImageSubresource sub = {range.aspectMask, level, layer};
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700991 IMAGE_CMD_BUF_LAYOUT_NODE node;
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700992 if (!FindCmdBufLayout(device_data, cb_node, image, sub, node)) {
993 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 -0700994 }
995 }
996 }
997}
998
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700999bool PreCallValidateCmdClearColorImage(layer_data *dev_data, VkCommandBuffer commandBuffer, VkImage image,
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001000 VkImageLayout imageLayout, uint32_t rangeCount, const VkImageSubresourceRange *pRanges) {
1001 bool skip = false;
1002 // TODO : Verify memory is in VK_IMAGE_STATE_CLEAR state
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07001003 auto cb_node = GetCBNode(dev_data, commandBuffer);
1004 auto image_state = GetImageState(dev_data, image);
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001005 if (cb_node && image_state) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001006 skip |= ValidateMemoryIsBoundToImage(dev_data, image_state, "vkCmdClearColorImage()", VALIDATION_ERROR_18800006);
Mike Schuchardt9c582402017-02-23 15:57:37 -07001007 skip |= ValidateCmdQueueFlags(dev_data, cb_node, "vkCmdClearColorImage()", VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001008 VALIDATION_ERROR_18802415);
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001009 skip |= ValidateCmd(dev_data, cb_node, CMD_CLEARCOLORIMAGE, "vkCmdClearColorImage()");
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001010 skip |= insideRenderPass(dev_data, cb_node, "vkCmdClearColorImage()", VALIDATION_ERROR_18800017);
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001011 for (uint32_t i = 0; i < rangeCount; ++i) {
Petr Kraus4d718682017-05-18 03:38:41 +02001012 std::string param_name = "pRanges[" + std::to_string(i) + "]";
Petr Kraus8423f152017-05-26 01:20:04 +02001013 skip |=
1014 ValidateImageSubresourceRange(dev_data, image_state, false, pRanges[i], "vkCmdClearColorImage", param_name.c_str());
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001015 skip |= ValidateImageAttributes(dev_data, image_state, pRanges[i]);
Mark Lobodzinski9c93dbd2017-02-02 08:31:18 -07001016 skip |= VerifyClearImageLayout(dev_data, cb_node, image_state, pRanges[i], imageLayout, "vkCmdClearColorImage()");
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001017 }
1018 }
1019 return skip;
1020}
1021
1022// This state recording routine is shared between ClearColorImage and ClearDepthStencilImage
Tobin Ehlis58c884f2017-02-08 12:15:27 -07001023void PreCallRecordCmdClearImage(layer_data *dev_data, VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout,
Chris Forbes38c2e792017-06-16 16:42:35 -07001024 uint32_t rangeCount, const VkImageSubresourceRange *pRanges) {
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07001025 auto cb_node = GetCBNode(dev_data, commandBuffer);
1026 auto image_state = GetImageState(dev_data, image);
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001027 if (cb_node && image_state) {
1028 AddCommandBufferBindingImage(dev_data, cb_node, image_state);
1029 std::function<bool()> function = [=]() {
1030 SetImageMemoryValid(dev_data, image_state, true);
1031 return false;
1032 };
1033 cb_node->validate_functions.push_back(function);
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001034 for (uint32_t i = 0; i < rangeCount; ++i) {
1035 RecordClearImageLayout(dev_data, cb_node, image, pRanges[i], imageLayout);
1036 }
1037 }
1038}
1039
Tobin Ehlis58c884f2017-02-08 12:15:27 -07001040bool PreCallValidateCmdClearDepthStencilImage(layer_data *device_data, VkCommandBuffer commandBuffer, VkImage image,
1041 VkImageLayout imageLayout, uint32_t rangeCount,
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001042 const VkImageSubresourceRange *pRanges) {
1043 bool skip = false;
Mark Lobodzinski1241a312017-02-01 10:57:21 -07001044 const debug_report_data *report_data = core_validation::GetReportData(device_data);
1045
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001046 // TODO : Verify memory is in VK_IMAGE_STATE_CLEAR state
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07001047 auto cb_node = GetCBNode(device_data, commandBuffer);
1048 auto image_state = GetImageState(device_data, image);
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001049 if (cb_node && image_state) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001050 skip |= ValidateMemoryIsBoundToImage(device_data, image_state, "vkCmdClearDepthStencilImage()", VALIDATION_ERROR_18a00014);
Mike Schuchardt9c582402017-02-23 15:57:37 -07001051 skip |= ValidateCmdQueueFlags(device_data, cb_node, "vkCmdClearDepthStencilImage()", VK_QUEUE_GRAPHICS_BIT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001052 VALIDATION_ERROR_18a02415);
Mark Lobodzinski1241a312017-02-01 10:57:21 -07001053 skip |= ValidateCmd(device_data, cb_node, CMD_CLEARDEPTHSTENCILIMAGE, "vkCmdClearDepthStencilImage()");
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001054 skip |= insideRenderPass(device_data, cb_node, "vkCmdClearDepthStencilImage()", VALIDATION_ERROR_18a00017);
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001055 for (uint32_t i = 0; i < rangeCount; ++i) {
Petr Kraus4d718682017-05-18 03:38:41 +02001056 std::string param_name = "pRanges[" + std::to_string(i) + "]";
Petr Kraus8423f152017-05-26 01:20:04 +02001057 skip |= ValidateImageSubresourceRange(device_data, image_state, false, pRanges[i], "vkCmdClearDepthStencilImage",
Petr Kraus4d718682017-05-18 03:38:41 +02001058 param_name.c_str());
Mark Lobodzinski9c93dbd2017-02-02 08:31:18 -07001059 skip |=
1060 VerifyClearImageLayout(device_data, cb_node, image_state, pRanges[i], imageLayout, "vkCmdClearDepthStencilImage()");
Mark Lobodzinski1241a312017-02-01 10:57:21 -07001061 // Image aspect must be depth or stencil or both
1062 if (((pRanges[i].aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) != VK_IMAGE_ASPECT_DEPTH_BIT) &&
1063 ((pRanges[i].aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) != VK_IMAGE_ASPECT_STENCIL_BIT)) {
1064 char const str[] =
1065 "vkCmdClearDepthStencilImage aspectMasks for all subresource ranges must be "
1066 "set to VK_IMAGE_ASPECT_DEPTH_BIT and/or VK_IMAGE_ASPECT_STENCIL_BIT";
1067 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 +02001068 HandleToUint64(commandBuffer), __LINE__, DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", str);
Mark Lobodzinski1241a312017-02-01 10:57:21 -07001069 }
1070 }
Dave Houlton1d2022c2017-03-29 11:43:58 -06001071 if (image_state && !FormatIsDepthOrStencil(image_state->createInfo.format)) {
Mark Lobodzinski1241a312017-02-01 10:57:21 -07001072 char const str[] = "vkCmdClearDepthStencilImage called without a depth/stencil image.";
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001073 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
1074 HandleToUint64(image), __LINE__, VALIDATION_ERROR_18a0001c, "IMAGE", "%s. %s", str,
1075 validation_error_map[VALIDATION_ERROR_18a0001c]);
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001076 }
1077 }
1078 return skip;
1079}
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001080
1081// Returns true if [x, xoffset] and [y, yoffset] overlap
1082static bool RangesIntersect(int32_t start, uint32_t start_offset, int32_t end, uint32_t end_offset) {
1083 bool result = false;
1084 uint32_t intersection_min = std::max(static_cast<uint32_t>(start), static_cast<uint32_t>(end));
1085 uint32_t intersection_max = std::min(static_cast<uint32_t>(start) + start_offset, static_cast<uint32_t>(end) + end_offset);
1086
1087 if (intersection_max > intersection_min) {
1088 result = true;
1089 }
1090 return result;
1091}
1092
1093// Returns true if two VkImageCopy structures overlap
1094static bool RegionIntersects(const VkImageCopy *src, const VkImageCopy *dst, VkImageType type) {
1095 bool result = false;
1096 if ((src->srcSubresource.mipLevel == dst->dstSubresource.mipLevel) &&
1097 (RangesIntersect(src->srcSubresource.baseArrayLayer, src->srcSubresource.layerCount, dst->dstSubresource.baseArrayLayer,
1098 dst->dstSubresource.layerCount))) {
1099 result = true;
1100 switch (type) {
1101 case VK_IMAGE_TYPE_3D:
1102 result &= RangesIntersect(src->srcOffset.z, src->extent.depth, dst->dstOffset.z, dst->extent.depth);
1103 // Intentionally fall through to 2D case
1104 case VK_IMAGE_TYPE_2D:
1105 result &= RangesIntersect(src->srcOffset.y, src->extent.height, dst->dstOffset.y, dst->extent.height);
1106 // Intentionally fall through to 1D case
1107 case VK_IMAGE_TYPE_1D:
1108 result &= RangesIntersect(src->srcOffset.x, src->extent.width, dst->dstOffset.x, dst->extent.width);
1109 break;
1110 default:
1111 // Unrecognized or new IMAGE_TYPE enums will be caught in parameter_validation
1112 assert(false);
1113 }
1114 }
1115 return result;
1116}
1117
Dave Houltonfc1a4052017-04-27 14:32:45 -06001118// Returns non-zero if offset and extent exceed image extents
1119static const uint32_t x_bit = 1;
1120static const uint32_t y_bit = 2;
1121static const uint32_t z_bit = 4;
Dave Houlton1150cf52017-04-27 14:38:11 -06001122static uint32_t ExceedsBounds(const VkOffset3D *offset, const VkExtent3D *extent, const VkExtent3D *image_extent) {
Dave Houltonfc1a4052017-04-27 14:32:45 -06001123 uint32_t result = 0;
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001124 // Extents/depths cannot be negative but checks left in for clarity
Dave Houlton9dae7ec2017-03-01 16:23:25 -07001125 if ((offset->z + extent->depth > image_extent->depth) || (offset->z < 0) ||
1126 ((offset->z + static_cast<int32_t>(extent->depth)) < 0)) {
Dave Houltonfc1a4052017-04-27 14:32:45 -06001127 result |= z_bit;
Dave Houlton9dae7ec2017-03-01 16:23:25 -07001128 }
1129 if ((offset->y + extent->height > image_extent->height) || (offset->y < 0) ||
1130 ((offset->y + static_cast<int32_t>(extent->height)) < 0)) {
Dave Houltonfc1a4052017-04-27 14:32:45 -06001131 result |= y_bit;
Dave Houlton9dae7ec2017-03-01 16:23:25 -07001132 }
1133 if ((offset->x + extent->width > image_extent->width) || (offset->x < 0) ||
1134 ((offset->x + static_cast<int32_t>(extent->width)) < 0)) {
Dave Houltonfc1a4052017-04-27 14:32:45 -06001135 result |= x_bit;
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001136 }
1137 return result;
1138}
1139
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001140// Test if two VkExtent3D structs are equivalent
1141static inline bool IsExtentEqual(const VkExtent3D *extent, const VkExtent3D *other_extent) {
1142 bool result = true;
1143 if ((extent->width != other_extent->width) || (extent->height != other_extent->height) ||
1144 (extent->depth != other_extent->depth)) {
1145 result = false;
1146 }
1147 return result;
1148}
1149
Dave Houlton6f9059e2017-05-02 17:15:13 -06001150// Returns the effective extent of an image subresource, adjusted for mip level and array depth.
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001151static inline VkExtent3D GetImageSubresourceExtent(const IMAGE_STATE *img, const VkImageSubresourceLayers *subresource) {
1152 const uint32_t mip = subresource->mipLevel;
Dave Houltonfc1a4052017-04-27 14:32:45 -06001153
1154 // Return zero extent if mip level doesn't exist
Dave Houlton1150cf52017-04-27 14:38:11 -06001155 if (mip >= img->createInfo.mipLevels) {
1156 return VkExtent3D{0, 0, 0};
Dave Houltonfc1a4052017-04-27 14:32:45 -06001157 }
Dave Houlton1150cf52017-04-27 14:38:11 -06001158
Dave Houlton9dae7ec2017-03-01 16:23:25 -07001159 // 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 -06001160 VkExtent3D extent = img->createInfo.extent;
Dave Houlton9dae7ec2017-03-01 16:23:25 -07001161 extent.width = (0 == extent.width ? 0 : std::max(1U, extent.width >> mip));
1162 extent.height = (0 == extent.height ? 0 : std::max(1U, extent.height >> mip));
1163 extent.depth = (0 == extent.depth ? 0 : std::max(1U, extent.depth >> mip));
Dave Houltonfc1a4052017-04-27 14:32:45 -06001164
Dave Houlton6f9059e2017-05-02 17:15:13 -06001165 // Image arrays have an effective z extent that isn't diminished by mip level
1166 if (VK_IMAGE_TYPE_3D != img->createInfo.imageType) {
Dave Houltonfc1a4052017-04-27 14:32:45 -06001167 extent.depth = img->createInfo.arrayLayers;
1168 }
1169
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001170 return extent;
1171}
1172
1173// Test if the extent argument has all dimensions set to 0.
Dave Houlton9dae7ec2017-03-01 16:23:25 -07001174static inline bool IsExtentAllZeroes(const VkExtent3D *extent) {
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001175 return ((extent->width == 0) && (extent->height == 0) && (extent->depth == 0));
1176}
1177
Dave Houlton9dae7ec2017-03-01 16:23:25 -07001178// Test if the extent argument has any dimensions set to 0.
1179static inline bool IsExtentSizeZero(const VkExtent3D *extent) {
1180 return ((extent->width == 0) || (extent->height == 0) || (extent->depth == 0));
1181}
1182
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001183// Returns the image transfer granularity for a specific image scaled by compressed block size if necessary.
1184static inline VkExtent3D GetScaledItg(layer_data *device_data, const GLOBAL_CB_NODE *cb_node, const IMAGE_STATE *img) {
1185 // Default to (0, 0, 0) granularity in case we can't find the real granularity for the physical device.
1186 VkExtent3D granularity = {0, 0, 0};
1187 auto pPool = GetCommandPoolNode(device_data, cb_node->createInfo.commandPool);
1188 if (pPool) {
1189 granularity =
1190 GetPhysDevProperties(device_data)->queue_family_properties[pPool->queueFamilyIndex].minImageTransferGranularity;
Dave Houlton1d2022c2017-03-29 11:43:58 -06001191 if (FormatIsCompressed(img->createInfo.format)) {
1192 auto block_size = FormatCompressedTexelBlockExtent(img->createInfo.format);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001193 granularity.width *= block_size.width;
1194 granularity.height *= block_size.height;
1195 }
1196 }
1197 return granularity;
1198}
1199
1200// Test elements of a VkExtent3D structure against alignment constraints contained in another VkExtent3D structure
1201static inline bool IsExtentAligned(const VkExtent3D *extent, const VkExtent3D *granularity) {
1202 bool valid = true;
Dave Houlton1d2022c2017-03-29 11:43:58 -06001203 if ((SafeModulo(extent->depth, granularity->depth) != 0) || (SafeModulo(extent->width, granularity->width) != 0) ||
1204 (SafeModulo(extent->height, granularity->height) != 0)) {
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001205 valid = false;
1206 }
1207 return valid;
1208}
1209
1210// Check elements of a VkOffset3D structure against a queue family's Image Transfer Granularity values
1211static inline bool CheckItgOffset(layer_data *device_data, const GLOBAL_CB_NODE *cb_node, const VkOffset3D *offset,
1212 const VkExtent3D *granularity, const uint32_t i, const char *function, const char *member) {
1213 const debug_report_data *report_data = core_validation::GetReportData(device_data);
1214 bool skip = false;
1215 VkExtent3D offset_extent = {};
1216 offset_extent.width = static_cast<uint32_t>(abs(offset->x));
1217 offset_extent.height = static_cast<uint32_t>(abs(offset->y));
1218 offset_extent.depth = static_cast<uint32_t>(abs(offset->z));
Dave Houlton9dae7ec2017-03-01 16:23:25 -07001219 if (IsExtentAllZeroes(granularity)) {
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001220 // 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 -07001221 if (IsExtentAllZeroes(&offset_extent) == false) {
Petr Krausbc7f5442017-05-14 23:43:38 +02001222 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1223 HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_IMAGE_TRANSFER_GRANULARITY, "DS",
1224 "%s: pRegion[%d].%s (x=%d, y=%d, z=%d) must be (x=0, y=0, z=0) "
1225 "when the command buffer's queue family image transfer granularity is (w=0, h=0, d=0).",
1226 function, i, member, offset->x, offset->y, offset->z);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001227 }
1228 } else {
1229 // If the queue family image transfer granularity is not (0, 0, 0), then the offset dimensions must always be even
1230 // integer multiples of the image transfer granularity.
1231 if (IsExtentAligned(&offset_extent, granularity) == false) {
Petr Krausbc7f5442017-05-14 23:43:38 +02001232 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1233 HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_IMAGE_TRANSFER_GRANULARITY, "DS",
1234 "%s: pRegion[%d].%s (x=%d, y=%d, z=%d) dimensions must be even integer "
1235 "multiples of this command buffer's queue family image transfer granularity (w=%d, h=%d, d=%d).",
1236 function, i, member, offset->x, offset->y, offset->z, granularity->width, granularity->height,
1237 granularity->depth);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001238 }
1239 }
1240 return skip;
1241}
1242
1243// Check elements of a VkExtent3D structure against a queue family's Image Transfer Granularity values
1244static inline bool CheckItgExtent(layer_data *device_data, const GLOBAL_CB_NODE *cb_node, const VkExtent3D *extent,
1245 const VkOffset3D *offset, const VkExtent3D *granularity, const VkExtent3D *subresource_extent,
1246 const uint32_t i, const char *function, const char *member) {
1247 const debug_report_data *report_data = core_validation::GetReportData(device_data);
1248 bool skip = false;
Dave Houlton9dae7ec2017-03-01 16:23:25 -07001249 if (IsExtentAllZeroes(granularity)) {
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001250 // If the queue family image transfer granularity is (0, 0, 0), then the extent must always match the image
1251 // subresource extent.
1252 if (IsExtentEqual(extent, subresource_extent) == false) {
Petr Krausbc7f5442017-05-14 23:43:38 +02001253 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1254 HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_IMAGE_TRANSFER_GRANULARITY, "DS",
1255 "%s: pRegion[%d].%s (w=%d, h=%d, d=%d) must match the image subresource extents (w=%d, h=%d, d=%d) "
1256 "when the command buffer's queue family image transfer granularity is (w=0, h=0, d=0).",
1257 function, i, member, extent->width, extent->height, extent->depth, subresource_extent->width,
1258 subresource_extent->height, subresource_extent->depth);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001259 }
1260 } else {
1261 // If the queue family image transfer granularity is not (0, 0, 0), then the extent dimensions must always be even
1262 // integer multiples of the image transfer granularity or the offset + extent dimensions must always match the image
1263 // subresource extent dimensions.
1264 VkExtent3D offset_extent_sum = {};
1265 offset_extent_sum.width = static_cast<uint32_t>(abs(offset->x)) + extent->width;
1266 offset_extent_sum.height = static_cast<uint32_t>(abs(offset->y)) + extent->height;
1267 offset_extent_sum.depth = static_cast<uint32_t>(abs(offset->z)) + extent->depth;
Dave Houlton6f9059e2017-05-02 17:15:13 -06001268
1269 bool x_ok =
1270 ((0 == SafeModulo(extent->width, granularity->width)) || (subresource_extent->width == offset_extent_sum.width));
1271 bool y_ok =
1272 ((0 == SafeModulo(extent->height, granularity->height)) || (subresource_extent->height == offset_extent_sum.height));
1273 bool z_ok =
1274 ((0 == SafeModulo(extent->depth, granularity->depth)) || (subresource_extent->depth == offset_extent_sum.depth));
1275
1276 if (!(x_ok && y_ok && z_ok)) {
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001277 skip |=
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06001278 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 +02001279 HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_IMAGE_TRANSFER_GRANULARITY, "DS",
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001280 "%s: pRegion[%d].%s (w=%d, h=%d, d=%d) dimensions must be even integer multiples of this command buffer's "
1281 "queue family image transfer granularity (w=%d, h=%d, d=%d) or offset (x=%d, y=%d, z=%d) + "
1282 "extent (w=%d, h=%d, d=%d) must match the image subresource extents (w=%d, h=%d, d=%d).",
1283 function, i, member, extent->width, extent->height, extent->depth, granularity->width, granularity->height,
1284 granularity->depth, offset->x, offset->y, offset->z, extent->width, extent->height, extent->depth,
1285 subresource_extent->width, subresource_extent->height, subresource_extent->depth);
1286 }
1287 }
1288 return skip;
1289}
1290
1291// Check a uint32_t width or stride value against a queue family's Image Transfer Granularity width value
1292static inline bool CheckItgInt(layer_data *device_data, const GLOBAL_CB_NODE *cb_node, const uint32_t value,
1293 const uint32_t granularity, const uint32_t i, const char *function, const char *member) {
1294 const debug_report_data *report_data = core_validation::GetReportData(device_data);
1295
1296 bool skip = false;
Dave Houlton1d2022c2017-03-29 11:43:58 -06001297 if (SafeModulo(value, granularity) != 0) {
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06001298 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 +02001299 HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_IMAGE_TRANSFER_GRANULARITY, "DS",
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001300 "%s: pRegion[%d].%s (%d) must be an even integer multiple of this command buffer's queue family image "
1301 "transfer granularity width (%d).",
1302 function, i, member, value, granularity);
1303 }
1304 return skip;
1305}
1306
1307// Check a VkDeviceSize value against a queue family's Image Transfer Granularity width value
1308static inline bool CheckItgSize(layer_data *device_data, const GLOBAL_CB_NODE *cb_node, const VkDeviceSize value,
1309 const uint32_t granularity, const uint32_t i, const char *function, const char *member) {
1310 const debug_report_data *report_data = core_validation::GetReportData(device_data);
1311 bool skip = false;
Dave Houlton1d2022c2017-03-29 11:43:58 -06001312 if (SafeModulo(value, granularity) != 0) {
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06001313 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 +02001314 HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_IMAGE_TRANSFER_GRANULARITY, "DS",
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001315 "%s: pRegion[%d].%s (%" PRIdLEAST64
1316 ") must be an even integer multiple of this command buffer's queue family image transfer "
1317 "granularity width (%d).",
1318 function, i, member, value, granularity);
1319 }
1320 return skip;
1321}
1322
1323// Check valid usage Image Tranfer Granularity requirements for elements of a VkBufferImageCopy structure
1324bool ValidateCopyBufferImageTransferGranularityRequirements(layer_data *device_data, const GLOBAL_CB_NODE *cb_node,
1325 const IMAGE_STATE *img, const VkBufferImageCopy *region,
1326 const uint32_t i, const char *function) {
1327 bool skip = false;
Dave Houlton1d2022c2017-03-29 11:43:58 -06001328 if (FormatIsCompressed(img->createInfo.format) == true) {
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001329 // TODO: Add granularity checking for compressed formats
1330
1331 // bufferRowLength must be a multiple of the compressed texel block width
1332 // bufferImageHeight must be a multiple of the compressed texel block height
1333 // all members of imageOffset must be a multiple of the corresponding dimensions of the compressed texel block
1334 // bufferOffset must be a multiple of the compressed texel block size in bytes
1335 // imageExtent.width must be a multiple of the compressed texel block width or (imageExtent.width + imageOffset.x)
1336 // must equal the image subresource width
1337 // imageExtent.height must be a multiple of the compressed texel block height or (imageExtent.height + imageOffset.y)
1338 // must equal the image subresource height
1339 // imageExtent.depth must be a multiple of the compressed texel block depth or (imageExtent.depth + imageOffset.z)
1340 // must equal the image subresource depth
1341 } else {
1342 VkExtent3D granularity = GetScaledItg(device_data, cb_node, img);
1343 skip |= CheckItgSize(device_data, cb_node, region->bufferOffset, granularity.width, i, function, "bufferOffset");
1344 skip |= CheckItgInt(device_data, cb_node, region->bufferRowLength, granularity.width, i, function, "bufferRowLength");
1345 skip |= CheckItgInt(device_data, cb_node, region->bufferImageHeight, granularity.width, i, function, "bufferImageHeight");
1346 skip |= CheckItgOffset(device_data, cb_node, &region->imageOffset, &granularity, i, function, "imageOffset");
1347 VkExtent3D subresource_extent = GetImageSubresourceExtent(img, &region->imageSubresource);
1348 skip |= CheckItgExtent(device_data, cb_node, &region->imageExtent, &region->imageOffset, &granularity, &subresource_extent,
1349 i, function, "imageExtent");
1350 }
1351 return skip;
1352}
1353
1354// Check valid usage Image Tranfer Granularity requirements for elements of a VkImageCopy structure
1355bool ValidateCopyImageTransferGranularityRequirements(layer_data *device_data, const GLOBAL_CB_NODE *cb_node,
Dave Houlton6f9059e2017-05-02 17:15:13 -06001356 const IMAGE_STATE *src_img, const IMAGE_STATE *dst_img,
1357 const VkImageCopy *region, const uint32_t i, const char *function) {
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001358 bool skip = false;
Dave Houlton6f9059e2017-05-02 17:15:13 -06001359 VkExtent3D granularity = GetScaledItg(device_data, cb_node, src_img);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001360 skip |= CheckItgOffset(device_data, cb_node, &region->srcOffset, &granularity, i, function, "srcOffset");
Dave Houlton6f9059e2017-05-02 17:15:13 -06001361 VkExtent3D subresource_extent = GetImageSubresourceExtent(src_img, &region->srcSubresource);
1362 skip |= CheckItgExtent(device_data, cb_node, &region->extent, &region->srcOffset, &granularity, &subresource_extent, i,
1363 function, "extent");
1364
1365 granularity = GetScaledItg(device_data, cb_node, dst_img);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001366 skip |= CheckItgOffset(device_data, cb_node, &region->dstOffset, &granularity, i, function, "dstOffset");
Dave Houlton6f9059e2017-05-02 17:15:13 -06001367 subresource_extent = GetImageSubresourceExtent(dst_img, &region->dstSubresource);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001368 skip |= CheckItgExtent(device_data, cb_node, &region->extent, &region->dstOffset, &granularity, &subresource_extent, i,
1369 function, "extent");
1370 return skip;
1371}
1372
Dave Houlton6f9059e2017-05-02 17:15:13 -06001373// Validate contents of a VkImageCopy struct
1374bool ValidateImageCopyData(const layer_data *device_data, const debug_report_data *report_data, const uint32_t regionCount,
1375 const VkImageCopy *ic_regions, const IMAGE_STATE *src_state, const IMAGE_STATE *dst_state) {
1376 bool skip = false;
1377
1378 for (uint32_t i = 0; i < regionCount; i++) {
1379 VkImageCopy image_copy = ic_regions[i];
1380 bool slice_override = false;
1381 uint32_t depth_slices = 0;
1382
1383 // Special case for copying between a 1D/2D array and a 3D image
1384 // TBD: This seems like the only way to reconcile 3 mutually-exclusive VU checks for 2D/3D copies. Heads up.
1385 if ((VK_IMAGE_TYPE_3D == src_state->createInfo.imageType) && (VK_IMAGE_TYPE_3D != dst_state->createInfo.imageType)) {
1386 depth_slices = image_copy.dstSubresource.layerCount; // Slice count from 2D subresource
1387 slice_override = (depth_slices != 1);
1388 } else if ((VK_IMAGE_TYPE_3D == dst_state->createInfo.imageType) && (VK_IMAGE_TYPE_3D != src_state->createInfo.imageType)) {
1389 depth_slices = image_copy.srcSubresource.layerCount; // Slice count from 2D subresource
1390 slice_override = (depth_slices != 1);
1391 }
1392
1393 // Do all checks on source image
1394 //
1395 if (src_state->createInfo.imageType == VK_IMAGE_TYPE_1D) {
1396 if ((0 != image_copy.srcOffset.y) || (1 != image_copy.extent.height)) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001397 skip |=
1398 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
1399 reinterpret_cast<const uint64_t &>(src_state->image), __LINE__, VALIDATION_ERROR_09c00124, "IMAGE",
1400 "vkCmdCopyImage(): pRegion[%d] srcOffset.y is %d and extent.height is %d. For 1D images these must "
1401 "be 0 and 1, respectively. %s",
1402 i, image_copy.srcOffset.y, image_copy.extent.height, validation_error_map[VALIDATION_ERROR_09c00124]);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001403 }
1404 }
1405
1406 if ((src_state->createInfo.imageType == VK_IMAGE_TYPE_1D) || (src_state->createInfo.imageType == VK_IMAGE_TYPE_2D)) {
1407 if ((0 != image_copy.srcOffset.z) || (1 != image_copy.extent.depth)) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001408 skip |=
1409 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
1410 reinterpret_cast<const uint64_t &>(src_state->image), __LINE__, VALIDATION_ERROR_09c00128, "IMAGE",
1411 "vkCmdCopyImage(): pRegion[%d] srcOffset.z is %d and extent.depth is %d. For 1D and 2D images "
1412 "these must be 0 and 1, respectively. %s",
1413 i, image_copy.srcOffset.z, image_copy.extent.depth, validation_error_map[VALIDATION_ERROR_09c00128]);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001414 }
1415 }
1416
1417 // VU01199 changed with mnt1
Mark Lobodzinski28426ae2017-06-01 07:56:38 -06001418 if (GetDeviceExtensions(device_data)->vk_khr_maintenance1) {
Dave Houlton6f9059e2017-05-02 17:15:13 -06001419 if (src_state->createInfo.imageType == VK_IMAGE_TYPE_3D) {
1420 if ((0 != image_copy.srcSubresource.baseArrayLayer) || (1 != image_copy.srcSubresource.layerCount)) {
1421 skip |=
1422 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001423 reinterpret_cast<const uint64_t &>(src_state->image), __LINE__, VALIDATION_ERROR_09c0011a, "IMAGE",
Dave Houlton6f9059e2017-05-02 17:15:13 -06001424 "vkCmdCopyImage(): pRegion[%d] srcSubresource.baseArrayLayer is %d and srcSubresource.layerCount "
1425 "is %d. For VK_IMAGE_TYPE_3D images these must be 0 and 1, respectively. %s",
1426 i, image_copy.srcSubresource.baseArrayLayer, image_copy.srcSubresource.layerCount,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001427 validation_error_map[VALIDATION_ERROR_09c0011a]);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001428 }
1429 }
1430 } else { // Pre maint 1
1431 if (src_state->createInfo.imageType == VK_IMAGE_TYPE_3D || dst_state->createInfo.imageType == VK_IMAGE_TYPE_3D) {
1432 if ((0 != image_copy.srcSubresource.baseArrayLayer) || (1 != image_copy.srcSubresource.layerCount)) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001433 skip |=
1434 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
1435 reinterpret_cast<const uint64_t &>(src_state->image), __LINE__, VALIDATION_ERROR_09c0011a, "IMAGE",
1436 "vkCmdCopyImage(): pRegion[%d] srcSubresource.baseArrayLayer is %d and "
1437 "srcSubresource.layerCount is %d. For copies with either source or dest of type "
1438 "VK_IMAGE_TYPE_3D, these must be 0 and 1, respectively. %s",
1439 i, image_copy.srcSubresource.baseArrayLayer, image_copy.srcSubresource.layerCount,
1440 validation_error_map[VALIDATION_ERROR_09c0011a]);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001441 }
1442 }
1443 }
1444
1445 // TODO: this VU is redundant with VU01224. Gitlab issue 812 submitted to get it removed from the spec.
1446 if ((image_copy.srcSubresource.baseArrayLayer >= src_state->createInfo.arrayLayers) ||
1447 (image_copy.srcSubresource.baseArrayLayer + image_copy.srcSubresource.layerCount > src_state->createInfo.arrayLayers)) {
1448 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001449 reinterpret_cast<const uint64_t &>(src_state->image), __LINE__, VALIDATION_ERROR_09c0012a, "IMAGE",
Dave Houlton6f9059e2017-05-02 17:15:13 -06001450 "vkCmdCopyImage(): pRegion[%d] srcSubresource.baseArrayLayer (%d) must be less than the source image's "
1451 "arrayLayers (%d), and the sum of baseArrayLayer and srcSubresource.layerCount (%d) must be less than "
1452 "or equal to the source image's arrayLayers. %s",
1453 i, image_copy.srcSubresource.baseArrayLayer, src_state->createInfo.arrayLayers,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001454 image_copy.srcSubresource.layerCount, validation_error_map[VALIDATION_ERROR_09c0012a]);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001455 }
1456
1457 // Checks that apply only to compressed images
1458 if (FormatIsCompressed(src_state->createInfo.format)) {
1459 VkExtent3D block_size = FormatCompressedTexelBlockExtent(src_state->createInfo.format);
1460
1461 // image offsets must be multiples of block dimensions
1462 if ((SafeModulo(image_copy.srcOffset.x, block_size.width) != 0) ||
1463 (SafeModulo(image_copy.srcOffset.y, block_size.height) != 0) ||
1464 (SafeModulo(image_copy.srcOffset.z, block_size.depth) != 0)) {
1465 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001466 reinterpret_cast<const uint64_t &>(src_state->image), __LINE__, VALIDATION_ERROR_09c0013a, "IMAGE",
Dave Houlton6f9059e2017-05-02 17:15:13 -06001467 "vkCmdCopyImage(): pRegion[%d] srcOffset (%d, %d) must be multiples of the compressed image's "
1468 "texel width & height (%d, %d). %s.",
1469 i, image_copy.srcOffset.x, image_copy.srcOffset.y, block_size.width, block_size.height,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001470 validation_error_map[VALIDATION_ERROR_09c0013a]);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001471 }
1472
1473 // extent width must be a multiple of block width, or extent+offset width must equal subresource width
1474 VkExtent3D mip_extent = GetImageSubresourceExtent(src_state, &(image_copy.srcSubresource));
1475 if ((SafeModulo(image_copy.extent.width, block_size.width) != 0) &&
1476 (image_copy.extent.width + image_copy.srcOffset.x != mip_extent.width)) {
1477 skip |=
1478 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001479 reinterpret_cast<const uint64_t &>(src_state->image), __LINE__, VALIDATION_ERROR_09c0013c, "IMAGE",
Dave Houlton6f9059e2017-05-02 17:15:13 -06001480 "vkCmdCopyImage(): pRegion[%d] extent width (%d) must be a multiple of the compressed texture block "
1481 "width (%d), or when added to srcOffset.x (%d) must equal the image subresource width (%d). %s.",
1482 i, image_copy.extent.width, block_size.width, image_copy.srcOffset.x, mip_extent.width,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001483 validation_error_map[VALIDATION_ERROR_09c0013c]);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001484 }
1485
1486 // extent height must be a multiple of block height, or extent+offset height must equal subresource height
1487 if ((SafeModulo(image_copy.extent.height, block_size.height) != 0) &&
1488 (image_copy.extent.height + image_copy.srcOffset.y != mip_extent.height)) {
1489 skip |=
1490 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001491 reinterpret_cast<const uint64_t &>(src_state->image), __LINE__, VALIDATION_ERROR_09c0013e, "IMAGE",
Dave Houlton6f9059e2017-05-02 17:15:13 -06001492 "vkCmdCopyImage(): pRegion[%d] extent height (%d) must be a multiple of the compressed texture block "
1493 "height (%d), or when added to srcOffset.y (%d) must equal the image subresource height (%d). %s.",
1494 i, image_copy.extent.height, block_size.height, image_copy.srcOffset.y, mip_extent.height,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001495 validation_error_map[VALIDATION_ERROR_09c0013e]);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001496 }
1497
1498 // extent depth must be a multiple of block depth, or extent+offset depth must equal subresource depth
1499 uint32_t copy_depth = (slice_override ? depth_slices : image_copy.extent.depth);
1500 if ((SafeModulo(copy_depth, block_size.depth) != 0) && (copy_depth + image_copy.srcOffset.z != mip_extent.depth)) {
1501 skip |=
1502 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001503 reinterpret_cast<const uint64_t &>(src_state->image), __LINE__, VALIDATION_ERROR_09c00140, "IMAGE",
Dave Houlton6f9059e2017-05-02 17:15:13 -06001504 "vkCmdCopyImage(): pRegion[%d] extent width (%d) must be a multiple of the compressed texture block "
1505 "depth (%d), or when added to srcOffset.z (%d) must equal the image subresource depth (%d). %s.",
1506 i, image_copy.extent.depth, block_size.depth, image_copy.srcOffset.z, mip_extent.depth,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001507 validation_error_map[VALIDATION_ERROR_09c00140]);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001508 }
1509 } // Compressed
1510
1511 // Do all checks on dest image
1512 //
1513 if (dst_state->createInfo.imageType == VK_IMAGE_TYPE_1D) {
1514 if ((0 != image_copy.dstOffset.y) || (1 != image_copy.extent.height)) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001515 skip |=
1516 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
1517 reinterpret_cast<const uint64_t &>(dst_state->image), __LINE__, VALIDATION_ERROR_09c00130, "IMAGE",
1518 "vkCmdCopyImage(): pRegion[%d] dstOffset.y is %d and extent.height is %d. For 1D images these must "
1519 "be 0 and 1, respectively. %s",
1520 i, image_copy.dstOffset.y, image_copy.extent.height, validation_error_map[VALIDATION_ERROR_09c00130]);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001521 }
1522 }
1523
1524 if ((dst_state->createInfo.imageType == VK_IMAGE_TYPE_1D) || (dst_state->createInfo.imageType == VK_IMAGE_TYPE_2D)) {
1525 if ((0 != image_copy.dstOffset.z) || (1 != image_copy.extent.depth)) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001526 skip |=
1527 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
1528 reinterpret_cast<const uint64_t &>(dst_state->image), __LINE__, VALIDATION_ERROR_09c00134, "IMAGE",
1529 "vkCmdCopyImage(): pRegion[%d] dstOffset.z is %d and extent.depth is %d. For 1D and 2D images "
1530 "these must be 0 and 1, respectively. %s",
1531 i, image_copy.dstOffset.z, image_copy.extent.depth, validation_error_map[VALIDATION_ERROR_09c00134]);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001532 }
1533 }
1534
1535 if (dst_state->createInfo.imageType == VK_IMAGE_TYPE_3D) {
1536 if ((0 != image_copy.dstSubresource.baseArrayLayer) || (1 != image_copy.dstSubresource.layerCount)) {
1537 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001538 reinterpret_cast<const uint64_t &>(dst_state->image), __LINE__, VALIDATION_ERROR_09c0011a, "IMAGE",
Dave Houlton6f9059e2017-05-02 17:15:13 -06001539 "vkCmdCopyImage(): pRegion[%d] dstSubresource.baseArrayLayer is %d and dstSubresource.layerCount "
1540 "is %d. For VK_IMAGE_TYPE_3D images these must be 0 and 1, respectively. %s",
1541 i, image_copy.dstSubresource.baseArrayLayer, image_copy.dstSubresource.layerCount,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001542 validation_error_map[VALIDATION_ERROR_09c0011a]);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001543 }
1544 }
1545 // VU01199 changed with mnt1
Mark Lobodzinski28426ae2017-06-01 07:56:38 -06001546 if (GetDeviceExtensions(device_data)->vk_khr_maintenance1) {
Dave Houlton6f9059e2017-05-02 17:15:13 -06001547 if (dst_state->createInfo.imageType == VK_IMAGE_TYPE_3D) {
1548 if ((0 != image_copy.dstSubresource.baseArrayLayer) || (1 != image_copy.dstSubresource.layerCount)) {
1549 skip |=
1550 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001551 reinterpret_cast<const uint64_t &>(dst_state->image), __LINE__, VALIDATION_ERROR_09c0011a, "IMAGE",
Dave Houlton6f9059e2017-05-02 17:15:13 -06001552 "vkCmdCopyImage(): pRegion[%d] dstSubresource.baseArrayLayer is %d and dstSubresource.layerCount "
1553 "is %d. For VK_IMAGE_TYPE_3D images these must be 0 and 1, respectively. %s",
1554 i, image_copy.dstSubresource.baseArrayLayer, image_copy.dstSubresource.layerCount,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001555 validation_error_map[VALIDATION_ERROR_09c0011a]);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001556 }
1557 }
1558 } else { // Pre maint 1
1559 if (src_state->createInfo.imageType == VK_IMAGE_TYPE_3D || dst_state->createInfo.imageType == VK_IMAGE_TYPE_3D) {
1560 if ((0 != image_copy.dstSubresource.baseArrayLayer) || (1 != image_copy.dstSubresource.layerCount)) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001561 skip |=
1562 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
1563 reinterpret_cast<const uint64_t &>(dst_state->image), __LINE__, VALIDATION_ERROR_09c0011a, "IMAGE",
1564 "vkCmdCopyImage(): pRegion[%d] dstSubresource.baseArrayLayer is %d and "
1565 "dstSubresource.layerCount is %d. For copies with either source or dest of type "
1566 "VK_IMAGE_TYPE_3D, these must be 0 and 1, respectively. %s",
1567 i, image_copy.dstSubresource.baseArrayLayer, image_copy.dstSubresource.layerCount,
1568 validation_error_map[VALIDATION_ERROR_09c0011a]);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001569 }
1570 }
1571 }
1572
1573 // TODO: this VU is redundant with VU01224. Gitlab issue 812 submitted to get it removed from the spec.
1574 if ((image_copy.dstSubresource.baseArrayLayer >= dst_state->createInfo.arrayLayers) ||
1575 (image_copy.dstSubresource.baseArrayLayer + image_copy.dstSubresource.layerCount > dst_state->createInfo.arrayLayers)) {
1576 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001577 reinterpret_cast<const uint64_t &>(dst_state->image), __LINE__, VALIDATION_ERROR_09c00136, "IMAGE",
Dave Houlton6f9059e2017-05-02 17:15:13 -06001578 "vkCmdCopyImage(): pRegion[%d] dstSubresource.baseArrayLayer (%d) must be less than the dest image's "
1579 "arrayLayers (%d), and the sum of baseArrayLayer and dstSubresource.layerCount (%d) must be less than "
1580 "or equal to the dest image's arrayLayers. %s",
1581 i, image_copy.dstSubresource.baseArrayLayer, dst_state->createInfo.arrayLayers,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001582 image_copy.dstSubresource.layerCount, validation_error_map[VALIDATION_ERROR_09c00136]);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001583 }
1584
1585 // Checks that apply only to compressed images
1586 if (FormatIsCompressed(dst_state->createInfo.format)) {
1587 VkExtent3D block_size = FormatCompressedTexelBlockExtent(dst_state->createInfo.format);
1588
1589 // image offsets must be multiples of block dimensions
1590 if ((SafeModulo(image_copy.dstOffset.x, block_size.width) != 0) ||
1591 (SafeModulo(image_copy.dstOffset.y, block_size.height) != 0) ||
1592 (SafeModulo(image_copy.dstOffset.z, block_size.depth) != 0)) {
1593 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001594 reinterpret_cast<const uint64_t &>(dst_state->image), __LINE__, VALIDATION_ERROR_09c00144, "IMAGE",
Dave Houlton6f9059e2017-05-02 17:15:13 -06001595 "vkCmdCopyImage(): pRegion[%d] dstOffset (%d, %d) must be multiples of the compressed image's "
1596 "texel width & height (%d, %d). %s.",
1597 i, image_copy.dstOffset.x, image_copy.dstOffset.y, block_size.width, block_size.height,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001598 validation_error_map[VALIDATION_ERROR_09c00144]);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001599 }
1600
1601 // extent width must be a multiple of block width, or extent+offset width must equal subresource width
1602 VkExtent3D mip_extent = GetImageSubresourceExtent(dst_state, &(image_copy.dstSubresource));
1603 if ((SafeModulo(image_copy.extent.width, block_size.width) != 0) &&
1604 (image_copy.extent.width + image_copy.dstOffset.x != mip_extent.width)) {
1605 skip |=
1606 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001607 reinterpret_cast<const uint64_t &>(dst_state->image), __LINE__, VALIDATION_ERROR_09c00146, "IMAGE",
Dave Houlton6f9059e2017-05-02 17:15:13 -06001608 "vkCmdCopyImage(): pRegion[%d] extent width (%d) must be a multiple of the compressed texture block "
1609 "width (%d), or when added to dstOffset.x (%d) must equal the image subresource width (%d). %s.",
1610 i, image_copy.extent.width, block_size.width, image_copy.dstOffset.x, mip_extent.width,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001611 validation_error_map[VALIDATION_ERROR_09c00146]);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001612 }
1613
1614 // extent height must be a multiple of block height, or extent+offset height must equal subresource height
1615 if ((SafeModulo(image_copy.extent.height, block_size.height) != 0) &&
1616 (image_copy.extent.height + image_copy.dstOffset.y != mip_extent.height)) {
1617 skip |=
1618 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001619 reinterpret_cast<const uint64_t &>(dst_state->image), __LINE__, VALIDATION_ERROR_09c00148, "IMAGE",
Dave Houlton6f9059e2017-05-02 17:15:13 -06001620 "vkCmdCopyImage(): pRegion[%d] extent height (%d) must be a multiple of the compressed texture block "
1621 "height (%d), or when added to dstOffset.y (%d) must equal the image subresource height (%d). %s.",
1622 i, image_copy.extent.height, block_size.height, image_copy.dstOffset.y, mip_extent.height,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001623 validation_error_map[VALIDATION_ERROR_09c00148]);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001624 }
1625
1626 // extent depth must be a multiple of block depth, or extent+offset depth must equal subresource depth
1627 uint32_t copy_depth = (slice_override ? depth_slices : image_copy.extent.depth);
1628 if ((SafeModulo(copy_depth, block_size.depth) != 0) && (copy_depth + image_copy.dstOffset.z != mip_extent.depth)) {
1629 skip |=
1630 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001631 reinterpret_cast<const uint64_t &>(dst_state->image), __LINE__, VALIDATION_ERROR_09c0014a, "IMAGE",
Dave Houlton6f9059e2017-05-02 17:15:13 -06001632 "vkCmdCopyImage(): pRegion[%d] extent width (%d) must be a multiple of the compressed texture block "
1633 "depth (%d), or when added to dstOffset.z (%d) must equal the image subresource depth (%d). %s.",
1634 i, image_copy.extent.depth, block_size.depth, image_copy.dstOffset.z, mip_extent.depth,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001635 validation_error_map[VALIDATION_ERROR_09c0014a]);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001636 }
1637 } // Compressed
1638 }
1639 return skip;
1640}
1641
Tobin Ehlis58c884f2017-02-08 12:15:27 -07001642bool PreCallValidateCmdCopyImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state,
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001643 IMAGE_STATE *dst_image_state, uint32_t region_count, const VkImageCopy *regions,
1644 VkImageLayout src_image_layout, VkImageLayout dst_image_layout) {
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001645 bool skip = false;
1646 const debug_report_data *report_data = core_validation::GetReportData(device_data);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001647 skip = ValidateImageCopyData(device_data, report_data, region_count, regions, src_image_state, dst_image_state);
1648
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001649 VkCommandBuffer command_buffer = cb_node->commandBuffer;
1650
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001651 for (uint32_t i = 0; i < region_count; i++) {
Dave Houlton6f9059e2017-05-02 17:15:13 -06001652 bool slice_override = false;
1653 uint32_t depth_slices = 0;
1654
1655 // Special case for copying between a 1D/2D array and a 3D image
1656 // TBD: This seems like the only way to reconcile 3 mutually-exclusive VU checks for 2D/3D copies. Heads up.
1657 if ((VK_IMAGE_TYPE_3D == src_image_state->createInfo.imageType) &&
1658 (VK_IMAGE_TYPE_3D != dst_image_state->createInfo.imageType)) {
1659 depth_slices = regions[i].dstSubresource.layerCount; // Slice count from 2D subresource
1660 slice_override = (depth_slices != 1);
1661 } else if ((VK_IMAGE_TYPE_3D == dst_image_state->createInfo.imageType) &&
1662 (VK_IMAGE_TYPE_3D != src_image_state->createInfo.imageType)) {
1663 depth_slices = regions[i].srcSubresource.layerCount; // Slice count from 2D subresource
1664 slice_override = (depth_slices != 1);
1665 }
1666
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001667 if (regions[i].srcSubresource.layerCount == 0) {
1668 std::stringstream ss;
1669 ss << "vkCmdCopyImage: number of layers in pRegions[" << i << "] srcSubresource is zero";
Petr Krausbc7f5442017-05-14 23:43:38 +02001670 skip |=
1671 log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1672 HandleToUint64(command_buffer), __LINE__, DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", "%s", ss.str().c_str());
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001673 }
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001674
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001675 if (regions[i].dstSubresource.layerCount == 0) {
1676 std::stringstream ss;
1677 ss << "vkCmdCopyImage: number of layers in pRegions[" << i << "] dstSubresource is zero";
Petr Krausbc7f5442017-05-14 23:43:38 +02001678 skip |=
1679 log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1680 HandleToUint64(command_buffer), __LINE__, DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", "%s", ss.str().c_str());
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001681 }
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001682
Mark Lobodzinski28426ae2017-06-01 07:56:38 -06001683 if (GetDeviceExtensions(device_data)->vk_khr_maintenance1) {
Dave Houlton6f9059e2017-05-02 17:15:13 -06001684 // No chance of mismatch if we're overriding depth slice count
1685 if (!slice_override) {
1686 // The number of depth slices in srcSubresource and dstSubresource must match
1687 // Depth comes from layerCount for 1D,2D resources, from extent.depth for 3D
1688 uint32_t src_slices =
1689 (VK_IMAGE_TYPE_3D == src_image_state->createInfo.imageType ? regions[i].extent.depth
1690 : regions[i].srcSubresource.layerCount);
1691 uint32_t dst_slices =
1692 (VK_IMAGE_TYPE_3D == dst_image_state->createInfo.imageType ? regions[i].extent.depth
1693 : regions[i].dstSubresource.layerCount);
1694 if (src_slices != dst_slices) {
1695 std::stringstream ss;
1696 ss << "vkCmdCopyImage: number of depth slices in source and destination subresources for pRegions[" << i
1697 << "] do not match";
1698 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001699 reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_09c00118, "IMAGE",
1700 "%s. %s", ss.str().c_str(), validation_error_map[VALIDATION_ERROR_09c00118]);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001701 }
1702 }
1703 } else {
Mike Schuchardt64b5bb72017-03-21 16:33:26 -06001704 // For each region the layerCount member of srcSubresource and dstSubresource must match
1705 if (regions[i].srcSubresource.layerCount != regions[i].dstSubresource.layerCount) {
1706 std::stringstream ss;
1707 ss << "vkCmdCopyImage: number of layers in source and destination subresources for pRegions[" << i
1708 << "] do not match";
1709 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001710 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_09c00118, "IMAGE", "%s. %s",
1711 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_09c00118]);
Mike Schuchardt64b5bb72017-03-21 16:33:26 -06001712 }
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001713 }
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001714
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001715 // For each region, the aspectMask member of srcSubresource and dstSubresource must match
1716 if (regions[i].srcSubresource.aspectMask != regions[i].dstSubresource.aspectMask) {
1717 char const str[] = "vkCmdCopyImage: Src and dest aspectMasks for each region must match";
1718 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001719 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_09c00112, "IMAGE", "%s. %s", str,
1720 validation_error_map[VALIDATION_ERROR_09c00112]);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001721 }
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001722
Dave Houlton4eaaf3a2017-03-14 11:31:20 -06001723 // For each region, the aspectMask member of srcSubresource must be present in the source image
1724 if (!VerifyAspectsPresent(regions[i].srcSubresource.aspectMask, src_image_state->createInfo.format)) {
1725 std::stringstream ss;
1726 ss << "vkCmdCopyImage: pRegion[" << i
1727 << "] srcSubresource.aspectMask cannot specify aspects not present in source image";
1728 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001729 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_09c0011c, "IMAGE", "%s. %s",
1730 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_09c0011c]);
Dave Houlton4eaaf3a2017-03-14 11:31:20 -06001731 }
1732
1733 // For each region, the aspectMask member of dstSubresource must be present in the destination image
1734 if (!VerifyAspectsPresent(regions[i].dstSubresource.aspectMask, dst_image_state->createInfo.format)) {
1735 std::stringstream ss;
1736 ss << "vkCmdCopyImage: pRegion[" << i << "] dstSubresource.aspectMask cannot specify aspects not present in dest image";
1737 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001738 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_09c0011e, "IMAGE", "%s. %s",
1739 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_09c0011e]);
Dave Houlton4eaaf3a2017-03-14 11:31:20 -06001740 }
1741
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001742 // AspectMask must not contain VK_IMAGE_ASPECT_METADATA_BIT
1743 if ((regions[i].srcSubresource.aspectMask & VK_IMAGE_ASPECT_METADATA_BIT) ||
1744 (regions[i].dstSubresource.aspectMask & VK_IMAGE_ASPECT_METADATA_BIT)) {
1745 std::stringstream ss;
1746 ss << "vkCmdCopyImage: pRegions[" << i << "] may not specify aspectMask containing VK_IMAGE_ASPECT_METADATA_BIT";
1747 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001748 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_0a600150, "IMAGE", "%s. %s",
1749 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_0a600150]);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001750 }
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001751
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001752 // For each region, if aspectMask contains VK_IMAGE_ASPECT_COLOR_BIT, it must not contain either of
1753 // VK_IMAGE_ASPECT_DEPTH_BIT or VK_IMAGE_ASPECT_STENCIL_BIT
1754 if ((regions[i].srcSubresource.aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) &&
1755 (regions[i].srcSubresource.aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT))) {
1756 char const str[] = "vkCmdCopyImage aspectMask cannot specify both COLOR and DEPTH/STENCIL aspects";
1757 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001758 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_0a60014e, "IMAGE", "%s. %s", str,
1759 validation_error_map[VALIDATION_ERROR_0a60014e]);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001760 }
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001761
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001762 // MipLevel must be less than the mipLevels specified in VkImageCreateInfo when the image was created
1763 if (regions[i].srcSubresource.mipLevel >= src_image_state->createInfo.mipLevels) {
1764 std::stringstream ss;
1765 ss << "vkCmdCopyImage: pRegions[" << i
1766 << "] specifies a src mipLevel greater than the number specified when the srcImage was created.";
1767 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001768 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_0a600152, "IMAGE", "%s. %s",
1769 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_0a600152]);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001770 }
1771 if (regions[i].dstSubresource.mipLevel >= dst_image_state->createInfo.mipLevels) {
1772 std::stringstream ss;
1773 ss << "vkCmdCopyImage: pRegions[" << i
1774 << "] specifies a dst mipLevel greater than the number specified when the dstImage was created.";
1775 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001776 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_0a600152, "IMAGE", "%s. %s",
1777 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_0a600152]);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001778 }
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001779
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001780 // (baseArrayLayer + layerCount) must be less than or equal to the arrayLayers specified in VkImageCreateInfo when the
1781 // image was created
1782 if ((regions[i].srcSubresource.baseArrayLayer + regions[i].srcSubresource.layerCount) >
1783 src_image_state->createInfo.arrayLayers) {
1784 std::stringstream ss;
1785 ss << "vkCmdCopyImage: srcImage arrayLayers was " << src_image_state->createInfo.arrayLayers << " but subRegion[" << i
1786 << "] baseArrayLayer + layerCount is "
1787 << (regions[i].srcSubresource.baseArrayLayer + regions[i].srcSubresource.layerCount);
1788 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001789 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_0a600154, "IMAGE", "%s. %s",
1790 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_0a600154]);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001791 }
1792 if ((regions[i].dstSubresource.baseArrayLayer + regions[i].dstSubresource.layerCount) >
1793 dst_image_state->createInfo.arrayLayers) {
1794 std::stringstream ss;
1795 ss << "vkCmdCopyImage: dstImage arrayLayers was " << dst_image_state->createInfo.arrayLayers << " but subRegion[" << i
1796 << "] baseArrayLayer + layerCount is "
1797 << (regions[i].dstSubresource.baseArrayLayer + regions[i].dstSubresource.layerCount);
1798 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001799 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_0a600154, "IMAGE", "%s. %s",
1800 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_0a600154]);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001801 }
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001802
Mike Schuchardt64b5bb72017-03-21 16:33:26 -06001803 // Check region extents for 1D-1D, 2D-2D, and 3D-3D copies
1804 if (src_image_state->createInfo.imageType == dst_image_state->createInfo.imageType) {
1805 // 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 -06001806 VkExtent3D img_extent = GetImageSubresourceExtent(src_image_state, &(regions[i].srcSubresource));
1807 if (0 != ExceedsBounds(&regions[i].srcOffset, &regions[i].extent, &img_extent)) {
Mike Schuchardt64b5bb72017-03-21 16:33:26 -06001808 std::stringstream ss;
Dave Houltonfc1a4052017-04-27 14:32:45 -06001809 ss << "vkCmdCopyImage: Source pRegion[" << i << "] with mipLevel [ " << regions[i].srcSubresource.mipLevel
1810 << " ], offset [ " << regions[i].srcOffset.x << ", " << regions[i].srcOffset.y << ", " << regions[i].srcOffset.z
1811 << " ], extent [ " << regions[i].extent.width << ", " << regions[i].extent.height << ", "
1812 << regions[i].extent.depth << " ] exceeds the source image dimensions";
Mike Schuchardt64b5bb72017-03-21 16:33:26 -06001813 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001814 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_190000f4, "IMAGE", "%s. %s",
1815 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_190000f4]);
Mike Schuchardt64b5bb72017-03-21 16:33:26 -06001816 }
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001817
Mike Schuchardt64b5bb72017-03-21 16:33:26 -06001818 // 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 -06001819 img_extent = GetImageSubresourceExtent(dst_image_state, &(regions[i].dstSubresource));
1820 if (0 != ExceedsBounds(&regions[i].dstOffset, &regions[i].extent, &img_extent)) {
Mike Schuchardt64b5bb72017-03-21 16:33:26 -06001821 std::stringstream ss;
Dave Houltonfc1a4052017-04-27 14:32:45 -06001822 ss << "vkCmdCopyImage: Dest pRegion[" << i << "] with mipLevel [ " << regions[i].dstSubresource.mipLevel
1823 << " ], offset [ " << regions[i].dstOffset.x << ", " << regions[i].dstOffset.y << ", " << regions[i].dstOffset.z
1824 << " ], extent [ " << regions[i].extent.width << ", " << regions[i].extent.height << ", "
1825 << regions[i].extent.depth << " ] exceeds the destination image dimensions";
Mike Schuchardt64b5bb72017-03-21 16:33:26 -06001826 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001827 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_190000f6, "IMAGE", "%s. %s",
1828 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_190000f6]);
Mike Schuchardt64b5bb72017-03-21 16:33:26 -06001829 }
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001830 }
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001831
Dave Houltonfc1a4052017-04-27 14:32:45 -06001832 // Each dimension offset + extent limits must fall with image subresource extent
1833 VkExtent3D subresource_extent = GetImageSubresourceExtent(src_image_state, &(regions[i].srcSubresource));
Dave Houlton6f9059e2017-05-02 17:15:13 -06001834 VkExtent3D copy_extent = regions[i].extent;
1835 if (slice_override) copy_extent.depth = depth_slices;
1836 uint32_t extent_check = ExceedsBounds(&(regions[i].srcOffset), &copy_extent, &subresource_extent);
Dave Houltonfc1a4052017-04-27 14:32:45 -06001837 if (extent_check & x_bit) {
1838 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001839 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_09c00120, "IMAGE",
Dave Houltonfc1a4052017-04-27 14:32:45 -06001840 "vkCmdCopyImage: Source image pRegion %1d x-dimension offset [%1d] + extent [%1d] exceeds subResource "
1841 "width [%1d]. %s",
1842 i, regions[i].srcOffset.x, regions[i].extent.width, subresource_extent.width,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001843 validation_error_map[VALIDATION_ERROR_09c00120]);
Dave Houltonfc1a4052017-04-27 14:32:45 -06001844 }
1845
1846 if (extent_check & y_bit) {
1847 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001848 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_09c00122, "IMAGE",
Dave Houltonfc1a4052017-04-27 14:32:45 -06001849 "vkCmdCopyImage: Source image pRegion %1d y-dimension offset [%1d] + extent [%1d] exceeds subResource "
1850 "height [%1d]. %s",
1851 i, regions[i].srcOffset.y, regions[i].extent.height, subresource_extent.height,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001852 validation_error_map[VALIDATION_ERROR_09c00122]);
Dave Houltonfc1a4052017-04-27 14:32:45 -06001853 }
1854 if (extent_check & z_bit) {
1855 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001856 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_09c00126, "IMAGE",
Dave Houltonfc1a4052017-04-27 14:32:45 -06001857 "vkCmdCopyImage: Source image pRegion %1d z-dimension offset [%1d] + extent [%1d] exceeds subResource "
1858 "depth [%1d]. %s",
Dave Houlton6f9059e2017-05-02 17:15:13 -06001859 i, regions[i].srcOffset.z, copy_extent.depth, subresource_extent.depth,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001860 validation_error_map[VALIDATION_ERROR_09c00126]);
Dave Houltonfc1a4052017-04-27 14:32:45 -06001861 }
1862
1863 subresource_extent = GetImageSubresourceExtent(dst_image_state, &(regions[i].dstSubresource));
Dave Houlton6f9059e2017-05-02 17:15:13 -06001864 copy_extent = regions[i].extent;
1865 if (slice_override) copy_extent.depth = depth_slices;
1866 extent_check = ExceedsBounds(&(regions[i].dstOffset), &copy_extent, &subresource_extent);
Dave Houltonfc1a4052017-04-27 14:32:45 -06001867 if (extent_check & x_bit) {
1868 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001869 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_09c0012c, "IMAGE",
Dave Houltonfc1a4052017-04-27 14:32:45 -06001870 "vkCmdCopyImage: Dest image pRegion %1d x-dimension offset [%1d] + extent [%1d] exceeds subResource "
1871 "width [%1d]. %s",
1872 i, regions[i].dstOffset.x, regions[i].extent.width, subresource_extent.width,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001873 validation_error_map[VALIDATION_ERROR_09c0012c]);
Dave Houltonfc1a4052017-04-27 14:32:45 -06001874 }
1875 if (extent_check & y_bit) {
1876 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001877 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_09c0012e, "IMAGE",
Dave Houltonfc1a4052017-04-27 14:32:45 -06001878 "vkCmdCopyImage: Dest image pRegion %1d y-dimension offset [%1d] + extent [%1d] exceeds subResource "
1879 "height [%1d]. %s",
1880 i, regions[i].dstOffset.y, regions[i].extent.height, subresource_extent.height,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001881 validation_error_map[VALIDATION_ERROR_09c0012e]);
Dave Houltonfc1a4052017-04-27 14:32:45 -06001882 }
1883 if (extent_check & z_bit) {
1884 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001885 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_09c00132, "IMAGE",
Dave Houltonfc1a4052017-04-27 14:32:45 -06001886 "vkCmdCopyImage: Dest image pRegion %1d z-dimension offset [%1d] + extent [%1d] exceeds subResource "
1887 "depth [%1d]. %s",
Dave Houlton6f9059e2017-05-02 17:15:13 -06001888 i, regions[i].dstOffset.z, copy_extent.depth, subresource_extent.depth,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001889 validation_error_map[VALIDATION_ERROR_09c00132]);
Dave Houltonfc1a4052017-04-27 14:32:45 -06001890 }
1891
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001892 // The union of all source regions, and the union of all destination regions, specified by the elements of regions,
1893 // must not overlap in memory
1894 if (src_image_state->image == dst_image_state->image) {
1895 for (uint32_t j = 0; j < region_count; j++) {
1896 if (RegionIntersects(&regions[i], &regions[j], src_image_state->createInfo.imageType)) {
1897 std::stringstream ss;
1898 ss << "vkCmdCopyImage: pRegions[" << i << "] src overlaps with pRegions[" << j << "].";
1899 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001900 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_190000f8, "IMAGE", "%s. %s",
1901 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_190000f8]);
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001902 }
1903 }
1904 }
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001905 }
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001906
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001907 // The formats of src_image and dst_image must be compatible. Formats are considered compatible if their texel size in bytes
1908 // is the same between both formats. For example, VK_FORMAT_R8G8B8A8_UNORM is compatible with VK_FORMAT_R32_UINT because
1909 // because both texels are 4 bytes in size. Depth/stencil formats must match exactly.
Dave Houlton1150cf52017-04-27 14:38:11 -06001910 if (FormatIsDepthOrStencil(src_image_state->createInfo.format) || FormatIsDepthOrStencil(dst_image_state->createInfo.format)) {
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001911 if (src_image_state->createInfo.format != dst_image_state->createInfo.format) {
1912 char const str[] = "vkCmdCopyImage called with unmatched source and dest image depth/stencil formats.";
Petr Krausbc7f5442017-05-14 23:43:38 +02001913 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1914 HandleToUint64(command_buffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_FORMAT, "IMAGE", str);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001915 }
1916 } else {
Dave Houlton1d2022c2017-03-29 11:43:58 -06001917 size_t srcSize = FormatSize(src_image_state->createInfo.format);
1918 size_t destSize = FormatSize(dst_image_state->createInfo.format);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001919 if (srcSize != destSize) {
1920 char const str[] = "vkCmdCopyImage called with unmatched source and dest image format sizes.";
1921 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001922 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_1900010e, "IMAGE", "%s. %s", str,
1923 validation_error_map[VALIDATION_ERROR_1900010e]);
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001924 }
1925 }
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001926
Dave Houlton33c22b72017-02-28 13:16:02 -07001927 // Source and dest image sample counts must match
1928 if (src_image_state->createInfo.samples != dst_image_state->createInfo.samples) {
1929 char const str[] = "vkCmdCopyImage() called on image pair with non-identical sample counts.";
1930 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001931 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_19000110, "IMAGE", "%s %s", str,
1932 validation_error_map[VALIDATION_ERROR_19000110]);
Dave Houlton33c22b72017-02-28 13:16:02 -07001933 }
1934
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001935 skip |= ValidateMemoryIsBoundToImage(device_data, src_image_state, "vkCmdCopyImage()", VALIDATION_ERROR_190000fe);
1936 skip |= ValidateMemoryIsBoundToImage(device_data, dst_image_state, "vkCmdCopyImage()", VALIDATION_ERROR_19000108);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001937 // Validate that SRC & DST images have correct usage flags set
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001938 skip |= ValidateImageUsageFlags(device_data, src_image_state, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, true, VALIDATION_ERROR_190000fc,
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001939 "vkCmdCopyImage()", "VK_IMAGE_USAGE_TRANSFER_SRC_BIT");
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001940 skip |= ValidateImageUsageFlags(device_data, dst_image_state, VK_IMAGE_USAGE_TRANSFER_DST_BIT, true, VALIDATION_ERROR_19000106,
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001941 "vkCmdCopyImage()", "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Mike Schuchardt9c582402017-02-23 15:57:37 -07001942 skip |= ValidateCmdQueueFlags(device_data, cb_node, "vkCmdCopyImage()",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001943 VK_QUEUE_TRANSFER_BIT | VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT, VALIDATION_ERROR_19002415);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001944 skip |= ValidateCmd(device_data, cb_node, CMD_COPYIMAGE, "vkCmdCopyImage()");
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001945 skip |= insideRenderPass(device_data, cb_node, "vkCmdCopyImage()", VALIDATION_ERROR_19000017);
Tobin Ehlisc8266452017-04-07 12:20:30 -06001946 bool hit_error = false;
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001947 for (uint32_t i = 0; i < region_count; ++i) {
Tobin Ehlis2d85ec62017-03-14 15:38:48 -06001948 skip |= VerifyImageLayout(device_data, cb_node, src_image_state, regions[i].srcSubresource, src_image_layout,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001949 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, "vkCmdCopyImage()", VALIDATION_ERROR_19000102, &hit_error);
Tobin Ehlis2d85ec62017-03-14 15:38:48 -06001950 skip |= VerifyImageLayout(device_data, cb_node, dst_image_state, regions[i].dstSubresource, dst_image_layout,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001951 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, "vkCmdCopyImage()", VALIDATION_ERROR_1900010c, &hit_error);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001952 skip |= ValidateCopyImageTransferGranularityRequirements(device_data, cb_node, src_image_state, dst_image_state,
1953 &regions[i], i, "vkCmdCopyImage()");
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001954 }
1955
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001956 return skip;
1957}
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07001958
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001959void PreCallRecordCmdCopyImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state,
Tobin Ehlise35b66a2017-03-15 12:18:31 -06001960 IMAGE_STATE *dst_image_state, uint32_t region_count, const VkImageCopy *regions,
1961 VkImageLayout src_image_layout, VkImageLayout dst_image_layout) {
1962 // Make sure that all image slices are updated to correct layout
1963 for (uint32_t i = 0; i < region_count; ++i) {
1964 SetImageLayout(device_data, cb_node, src_image_state, regions[i].srcSubresource, src_image_layout);
1965 SetImageLayout(device_data, cb_node, dst_image_state, regions[i].dstSubresource, dst_image_layout);
1966 }
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001967 // Update bindings between images and cmd buffer
1968 AddCommandBufferBindingImage(device_data, cb_node, src_image_state);
1969 AddCommandBufferBindingImage(device_data, cb_node, dst_image_state);
Dave Houltoneba86e22017-03-02 14:56:23 -07001970 std::function<bool()> function = [=]() { return ValidateImageMemoryIsValid(device_data, src_image_state, "vkCmdCopyImage()"); };
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001971 cb_node->validate_functions.push_back(function);
1972 function = [=]() {
1973 SetImageMemoryValid(device_data, dst_image_state, true);
1974 return false;
1975 };
1976 cb_node->validate_functions.push_back(function);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001977}
1978
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07001979// Returns true if sub_rect is entirely contained within rect
1980static inline bool ContainsRect(VkRect2D rect, VkRect2D sub_rect) {
1981 if ((sub_rect.offset.x < rect.offset.x) || (sub_rect.offset.x + sub_rect.extent.width > rect.offset.x + rect.extent.width) ||
1982 (sub_rect.offset.y < rect.offset.y) || (sub_rect.offset.y + sub_rect.extent.height > rect.offset.y + rect.extent.height))
1983 return false;
1984 return true;
1985}
1986
Tobin Ehlis58c884f2017-02-08 12:15:27 -07001987bool PreCallValidateCmdClearAttachments(layer_data *device_data, VkCommandBuffer commandBuffer, uint32_t attachmentCount,
1988 const VkClearAttachment *pAttachments, uint32_t rectCount, const VkClearRect *pRects) {
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07001989 GLOBAL_CB_NODE *cb_node = GetCBNode(device_data, commandBuffer);
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07001990 const debug_report_data *report_data = core_validation::GetReportData(device_data);
1991
1992 bool skip = false;
1993 if (cb_node) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001994 skip |= ValidateCmdQueueFlags(device_data, cb_node, "vkCmdClearAttachments()", VK_QUEUE_GRAPHICS_BIT,
1995 VALIDATION_ERROR_18602415);
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07001996 skip |= ValidateCmd(device_data, cb_node, CMD_CLEARATTACHMENTS, "vkCmdClearAttachments()");
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07001997 // Warn if this is issued prior to Draw Cmd and clearing the entire attachment
Chris Forbes05375e72017-04-21 13:15:15 -07001998 if (!cb_node->hasDrawCmd && (cb_node->activeRenderPassBeginInfo.renderArea.extent.width == pRects[0].rect.extent.width) &&
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07001999 (cb_node->activeRenderPassBeginInfo.renderArea.extent.height == pRects[0].rect.extent.height)) {
2000 // 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 -07002001 // This warning should be made more specific. It'd be best to avoid triggering this test if it's a use that must call
2002 // CmdClearAttachments.
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07002003 skip |=
2004 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 +02002005 HandleToUint64(commandBuffer), 0, DRAWSTATE_CLEAR_CMD_BEFORE_DRAW, "DS",
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07002006 "vkCmdClearAttachments() issued on command buffer object 0x%p prior to any Draw Cmds."
2007 " It is recommended you use RenderPass LOAD_OP_CLEAR on Attachments prior to any Draw.",
2008 commandBuffer);
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002009 }
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002010 skip |= outsideRenderPass(device_data, cb_node, "vkCmdClearAttachments()", VALIDATION_ERROR_18600017);
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002011 }
2012
2013 // Validate that attachment is in reference list of active subpass
2014 if (cb_node->activeRenderPass) {
2015 const VkRenderPassCreateInfo *renderpass_create_info = cb_node->activeRenderPass->createInfo.ptr();
2016 const VkSubpassDescription *subpass_desc = &renderpass_create_info->pSubpasses[cb_node->activeSubpass];
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07002017 auto framebuffer = GetFramebufferState(device_data, cb_node->activeFramebuffer);
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002018
2019 for (uint32_t i = 0; i < attachmentCount; i++) {
2020 auto clear_desc = &pAttachments[i];
2021 VkImageView image_view = VK_NULL_HANDLE;
2022
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07002023 if (0 == clear_desc->aspectMask) {
2024 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002025 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_01c00c03, "IMAGE", "%s",
2026 validation_error_map[VALIDATION_ERROR_01c00c03]);
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07002027 } else if (clear_desc->aspectMask & VK_IMAGE_ASPECT_METADATA_BIT) {
2028 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002029 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_01c00028, "IMAGE", "%s",
2030 validation_error_map[VALIDATION_ERROR_01c00028]);
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07002031 } else if (clear_desc->aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) {
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002032 if (clear_desc->colorAttachment >= subpass_desc->colorAttachmentCount) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002033 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2034 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1860001e, "DS",
2035 "vkCmdClearAttachments() color attachment index %d out of range for active subpass %d. %s",
2036 clear_desc->colorAttachment, cb_node->activeSubpass,
2037 validation_error_map[VALIDATION_ERROR_1860001e]);
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002038 } else if (subpass_desc->pColorAttachments[clear_desc->colorAttachment].attachment == VK_ATTACHMENT_UNUSED) {
2039 skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02002040 VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, HandleToUint64(commandBuffer), __LINE__,
2041 DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS",
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07002042 "vkCmdClearAttachments() color attachment index %d is VK_ATTACHMENT_UNUSED; ignored.",
2043 clear_desc->colorAttachment);
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002044 } else {
2045 image_view = framebuffer->createInfo
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07002046 .pAttachments[subpass_desc->pColorAttachments[clear_desc->colorAttachment].attachment];
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002047 }
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07002048 if ((clear_desc->aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) ||
2049 (clear_desc->aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT)) {
2050 char const str[] =
2051 "vkCmdClearAttachments aspectMask [%d] must set only VK_IMAGE_ASPECT_COLOR_BIT of a color attachment. %s";
2052 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002053 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_01c00026, "IMAGE", str, i,
2054 validation_error_map[VALIDATION_ERROR_01c00026]);
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07002055 }
2056 } else { // Must be depth and/or stencil
2057 if (((clear_desc->aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) != VK_IMAGE_ASPECT_DEPTH_BIT) &&
2058 ((clear_desc->aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) != VK_IMAGE_ASPECT_STENCIL_BIT)) {
2059 char const str[] = "vkCmdClearAttachments aspectMask [%d] is not a valid combination of bits. %s";
2060 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002061 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_01c00c01, "IMAGE", str, i,
2062 validation_error_map[VALIDATION_ERROR_01c00c01]);
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07002063 }
2064 if (!subpass_desc->pDepthStencilAttachment ||
2065 (subpass_desc->pDepthStencilAttachment->attachment == VK_ATTACHMENT_UNUSED)) {
2066 skip |= log_msg(
2067 report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02002068 HandleToUint64(commandBuffer), __LINE__, DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS",
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07002069 "vkCmdClearAttachments() depth/stencil clear with no depth/stencil attachment in subpass; ignored");
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002070 } else {
2071 image_view = framebuffer->createInfo.pAttachments[subpass_desc->pDepthStencilAttachment->attachment];
2072 }
2073 }
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002074 if (image_view) {
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07002075 auto image_view_state = GetImageViewState(device_data, image_view);
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002076 for (uint32_t j = 0; j < rectCount; j++) {
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07002077 // The rectangular region specified by a given element of pRects must be contained within the render area of
2078 // the current render pass instance
Mark Lobodzinskid833bb72017-02-22 10:55:30 -07002079 // TODO: This check should be moved to CmdExecuteCommands or QueueSubmit to cover secondary CB cases
2080 if ((cb_node->createInfo.level == VK_COMMAND_BUFFER_LEVEL_PRIMARY) &&
2081 (false == ContainsRect(cb_node->activeRenderPassBeginInfo.renderArea, pRects[j].rect))) {
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06002082 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002083 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_18600020, "DS",
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07002084 "vkCmdClearAttachments(): The area defined by pRects[%d] is not contained in the area of "
2085 "the current render pass instance. %s",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002086 j, validation_error_map[VALIDATION_ERROR_18600020]);
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002087 }
2088 // The layers specified by a given element of pRects must be contained within every attachment that
2089 // pAttachments refers to
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002090 auto attachment_layer_count = image_view_state->create_info.subresourceRange.layerCount;
Dave Houlton8e157032017-05-22 16:16:27 -06002091 if ((pRects[j].baseArrayLayer >= attachment_layer_count) ||
2092 (pRects[j].baseArrayLayer + pRects[j].layerCount > attachment_layer_count)) {
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002093 skip |=
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06002094 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002095 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_18600022, "DS",
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07002096 "vkCmdClearAttachments(): The layers defined in pRects[%d] are not contained in the layers of "
2097 "pAttachment[%d]. %s",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002098 j, i, validation_error_map[VALIDATION_ERROR_18600022]);
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002099 }
2100 }
2101 }
2102 }
2103 }
2104 return skip;
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07002105}
2106
Tobin Ehlis58c884f2017-02-08 12:15:27 -07002107bool PreCallValidateCmdResolveImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state,
Mark Lobodzinski50fbef12017-02-06 15:31:33 -07002108 IMAGE_STATE *dst_image_state, uint32_t regionCount, const VkImageResolve *pRegions) {
Mark Lobodzinski2a3368e2017-02-06 15:29:37 -07002109 const debug_report_data *report_data = core_validation::GetReportData(device_data);
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07002110 bool skip = false;
2111 if (cb_node && src_image_state && dst_image_state) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002112 skip |= ValidateMemoryIsBoundToImage(device_data, src_image_state, "vkCmdResolveImage()", VALIDATION_ERROR_1c800200);
2113 skip |= ValidateMemoryIsBoundToImage(device_data, dst_image_state, "vkCmdResolveImage()", VALIDATION_ERROR_1c800204);
2114 skip |=
2115 ValidateCmdQueueFlags(device_data, cb_node, "vkCmdResolveImage()", VK_QUEUE_GRAPHICS_BIT, VALIDATION_ERROR_1c802415);
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07002116 skip |= ValidateCmd(device_data, cb_node, CMD_RESOLVEIMAGE, "vkCmdResolveImage()");
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002117 skip |= insideRenderPass(device_data, cb_node, "vkCmdResolveImage()", VALIDATION_ERROR_1c800017);
Mark Lobodzinski2a3368e2017-02-06 15:29:37 -07002118
2119 // For each region, the number of layers in the image subresource should not be zero
2120 // For each region, src and dest image aspect must be color only
2121 for (uint32_t i = 0; i < regionCount; i++) {
2122 if (pRegions[i].srcSubresource.layerCount == 0) {
2123 char const str[] = "vkCmdResolveImage: number of layers in source subresource is zero";
Mark Lobodzinski50fbef12017-02-06 15:31:33 -07002124 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 +02002125 HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_ASPECT, "IMAGE", str);
Mark Lobodzinski2a3368e2017-02-06 15:29:37 -07002126 }
Mark Lobodzinski2a3368e2017-02-06 15:29:37 -07002127 if (pRegions[i].dstSubresource.layerCount == 0) {
2128 char const str[] = "vkCmdResolveImage: number of layers in destination subresource is zero";
Mark Lobodzinski50fbef12017-02-06 15:31:33 -07002129 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 +02002130 HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_ASPECT, "IMAGE", str);
Mark Lobodzinski2a3368e2017-02-06 15:29:37 -07002131 }
Mark Lobodzinski50fbef12017-02-06 15:31:33 -07002132 if (pRegions[i].srcSubresource.layerCount != pRegions[i].dstSubresource.layerCount) {
2133 skip |= log_msg(
2134 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002135 HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_0a200216, "IMAGE",
Mark Lobodzinski50fbef12017-02-06 15:31:33 -07002136 "vkCmdResolveImage: layerCount in source and destination subresource of pRegions[%d] does not match. %s", i,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002137 validation_error_map[VALIDATION_ERROR_0a200216]);
Mark Lobodzinski50fbef12017-02-06 15:31:33 -07002138 }
Mark Lobodzinski2a3368e2017-02-06 15:29:37 -07002139 if ((pRegions[i].srcSubresource.aspectMask != VK_IMAGE_ASPECT_COLOR_BIT) ||
2140 (pRegions[i].dstSubresource.aspectMask != VK_IMAGE_ASPECT_COLOR_BIT)) {
2141 char const str[] =
2142 "vkCmdResolveImage: src and dest aspectMasks for each region must specify only VK_IMAGE_ASPECT_COLOR_BIT";
2143 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002144 HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_0a200214, "IMAGE", "%s. %s", str,
2145 validation_error_map[VALIDATION_ERROR_0a200214]);
Mark Lobodzinski2a3368e2017-02-06 15:29:37 -07002146 }
2147 }
2148
2149 if (src_image_state->createInfo.format != dst_image_state->createInfo.format) {
2150 char const str[] = "vkCmdResolveImage called with unmatched source and dest formats.";
Mark Lobodzinski50fbef12017-02-06 15:31:33 -07002151 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 +02002152 HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_FORMAT, "IMAGE", str);
Mark Lobodzinski2a3368e2017-02-06 15:29:37 -07002153 }
2154 if (src_image_state->createInfo.imageType != dst_image_state->createInfo.imageType) {
2155 char const str[] = "vkCmdResolveImage called with unmatched source and dest image types.";
Mark Lobodzinski50fbef12017-02-06 15:31:33 -07002156 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 +02002157 HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_TYPE, "IMAGE", str);
Mark Lobodzinski2a3368e2017-02-06 15:29:37 -07002158 }
2159 if (src_image_state->createInfo.samples == VK_SAMPLE_COUNT_1_BIT) {
2160 char const str[] = "vkCmdResolveImage called with source sample count less than 2.";
2161 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002162 HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_1c800202, "IMAGE", "%s. %s", str,
2163 validation_error_map[VALIDATION_ERROR_1c800202]);
Mark Lobodzinski2a3368e2017-02-06 15:29:37 -07002164 }
2165 if (dst_image_state->createInfo.samples != VK_SAMPLE_COUNT_1_BIT) {
2166 char const str[] = "vkCmdResolveImage called with dest sample count greater than 1.";
2167 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002168 HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_1c800206, "IMAGE", "%s. %s", str,
2169 validation_error_map[VALIDATION_ERROR_1c800206]);
Mark Lobodzinski2a3368e2017-02-06 15:29:37 -07002170 }
Tobin Ehlisbb03e5f2017-05-11 08:52:51 -06002171 // TODO: Need to validate image layouts, which will include layout validation for shared presentable images
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07002172 } else {
2173 assert(0);
2174 }
2175 return skip;
2176}
2177
Tobin Ehlis58c884f2017-02-08 12:15:27 -07002178void PreCallRecordCmdResolveImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state,
2179 IMAGE_STATE *dst_image_state) {
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07002180 // Update bindings between images and cmd buffer
2181 AddCommandBufferBindingImage(device_data, cb_node, src_image_state);
2182 AddCommandBufferBindingImage(device_data, cb_node, dst_image_state);
2183
2184 std::function<bool()> function = [=]() {
2185 return ValidateImageMemoryIsValid(device_data, src_image_state, "vkCmdResolveImage()");
2186 };
2187 cb_node->validate_functions.push_back(function);
2188 function = [=]() {
2189 SetImageMemoryValid(device_data, dst_image_state, true);
2190 return false;
2191 };
2192 cb_node->validate_functions.push_back(function);
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07002193}
2194
Tobin Ehlis58c884f2017-02-08 12:15:27 -07002195bool PreCallValidateCmdBlitImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state,
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002196 IMAGE_STATE *dst_image_state, uint32_t regionCount, const VkImageBlit *pRegions, VkFilter filter) {
2197 const debug_report_data *report_data = core_validation::GetReportData(device_data);
2198
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07002199 bool skip = false;
2200 if (cb_node && src_image_state && dst_image_state) {
2201 skip |= ValidateImageSampleCount(device_data, src_image_state, VK_SAMPLE_COUNT_1_BIT, "vkCmdBlitImage(): srcImage",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002202 VALIDATION_ERROR_184001d2);
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07002203 skip |= ValidateImageSampleCount(device_data, dst_image_state, VK_SAMPLE_COUNT_1_BIT, "vkCmdBlitImage(): dstImage",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002204 VALIDATION_ERROR_184001d4);
2205 skip |= ValidateMemoryIsBoundToImage(device_data, src_image_state, "vkCmdBlitImage()", VALIDATION_ERROR_184001b8);
2206 skip |= ValidateMemoryIsBoundToImage(device_data, dst_image_state, "vkCmdBlitImage()", VALIDATION_ERROR_184001c2);
2207 skip |= ValidateImageUsageFlags(device_data, src_image_state, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, true,
2208 VALIDATION_ERROR_184001b6, "vkCmdBlitImage()", "VK_IMAGE_USAGE_TRANSFER_SRC_BIT");
2209 skip |= ValidateImageUsageFlags(device_data, dst_image_state, VK_IMAGE_USAGE_TRANSFER_DST_BIT, true,
2210 VALIDATION_ERROR_184001c0, "vkCmdBlitImage()", "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
2211 skip |= ValidateCmdQueueFlags(device_data, cb_node, "vkCmdBlitImage()", VK_QUEUE_GRAPHICS_BIT, VALIDATION_ERROR_18402415);
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07002212 skip |= ValidateCmd(device_data, cb_node, CMD_BLITIMAGE, "vkCmdBlitImage()");
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002213 skip |= insideRenderPass(device_data, cb_node, "vkCmdBlitImage()", VALIDATION_ERROR_18400017);
Tobin Ehlisbb03e5f2017-05-11 08:52:51 -06002214 // TODO: Need to validate image layouts, which will include layout validation for shared presentable images
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002215
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002216 for (uint32_t i = 0; i < regionCount; i++) {
Dave Houlton48989f32017-05-26 15:01:46 -06002217 VkImageBlit rgn = pRegions[i];
2218
Mark Lobodzinski23c81142017-02-06 15:04:23 -07002219 // Warn for zero-sized regions
Dave Houlton48989f32017-05-26 15:01:46 -06002220 if ((rgn.srcOffsets[0].x == rgn.srcOffsets[1].x) || (rgn.srcOffsets[0].y == rgn.srcOffsets[1].y) ||
2221 (rgn.srcOffsets[0].z == rgn.srcOffsets[1].z)) {
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002222 std::stringstream ss;
2223 ss << "vkCmdBlitImage: pRegions[" << i << "].srcOffsets specify a zero-volume area.";
2224 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 +02002225 HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_INVALID_EXTENTS, "IMAGE", "%s",
2226 ss.str().c_str());
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002227 }
Dave Houlton48989f32017-05-26 15:01:46 -06002228 if ((rgn.dstOffsets[0].x == rgn.dstOffsets[1].x) || (rgn.dstOffsets[0].y == rgn.dstOffsets[1].y) ||
2229 (rgn.dstOffsets[0].z == rgn.dstOffsets[1].z)) {
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002230 std::stringstream ss;
2231 ss << "vkCmdBlitImage: pRegions[" << i << "].dstOffsets specify a zero-volume area.";
2232 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 +02002233 HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_INVALID_EXTENTS, "IMAGE", "%s",
2234 ss.str().c_str());
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002235 }
Dave Houlton48989f32017-05-26 15:01:46 -06002236 if (rgn.srcSubresource.layerCount == 0) {
Mark Lobodzinski23c81142017-02-06 15:04:23 -07002237 char const str[] = "vkCmdBlitImage: number of layers in source subresource is zero";
2238 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 +02002239 HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_ASPECT, "IMAGE", str);
Mark Lobodzinski23c81142017-02-06 15:04:23 -07002240 }
Dave Houlton48989f32017-05-26 15:01:46 -06002241 if (rgn.dstSubresource.layerCount == 0) {
Mark Lobodzinski23c81142017-02-06 15:04:23 -07002242 char const str[] = "vkCmdBlitImage: number of layers in destination subresource is zero";
2243 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 +02002244 HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_ASPECT, "IMAGE", str);
Mark Lobodzinski23c81142017-02-06 15:04:23 -07002245 }
2246
2247 // Check that src/dst layercounts match
Dave Houlton48989f32017-05-26 15:01:46 -06002248 if (rgn.srcSubresource.layerCount != rgn.dstSubresource.layerCount) {
Mark Lobodzinski23c81142017-02-06 15:04:23 -07002249 skip |=
2250 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002251 HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_09a001de, "IMAGE",
Mark Lobodzinski23c81142017-02-06 15:04:23 -07002252 "vkCmdBlitImage: layerCount in source and destination subresource of pRegions[%d] does not match. %s",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002253 i, validation_error_map[VALIDATION_ERROR_09a001de]);
Mark Lobodzinski23c81142017-02-06 15:04:23 -07002254 }
Mark Lobodzinskie7e85fd2017-02-07 13:44:57 -07002255
Dave Houlton48989f32017-05-26 15:01:46 -06002256 if (rgn.srcSubresource.aspectMask != rgn.dstSubresource.aspectMask) {
Mark Lobodzinskie7e85fd2017-02-07 13:44:57 -07002257 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002258 HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_09a001dc, "IMAGE",
Mark Lobodzinskie7e85fd2017-02-07 13:44:57 -07002259 "vkCmdBlitImage: aspectMask members for pRegion[%d] do not match. %s", i,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002260 validation_error_map[VALIDATION_ERROR_09a001dc]);
Mark Lobodzinskie7e85fd2017-02-07 13:44:57 -07002261 }
Dave Houlton48989f32017-05-26 15:01:46 -06002262
2263 // Validate source image offsets
2264 VkExtent3D src_extent = GetImageSubresourceExtent(src_image_state, &(rgn.srcSubresource));
2265 if (VK_IMAGE_TYPE_1D == src_image_state->createInfo.imageType) {
2266 if ((0 != rgn.srcOffsets[0].y) || (1 != rgn.srcOffsets[1].y)) {
2267 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2268 HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_09a001ea, "IMAGE",
2269 "vkCmdBlitImage: region [%d], source image of type VK_IMAGE_TYPE_1D with srcOffset[].y values "
2270 "of (%1d, %1d). These must be (0, 1). %s",
2271 i, rgn.srcOffsets[0].y, rgn.srcOffsets[1].y, validation_error_map[VALIDATION_ERROR_09a001ea]);
2272 }
2273 }
2274
2275 if ((VK_IMAGE_TYPE_1D == src_image_state->createInfo.imageType) ||
2276 (VK_IMAGE_TYPE_2D == src_image_state->createInfo.imageType)) {
2277 if ((0 != rgn.srcOffsets[0].z) || (1 != rgn.srcOffsets[1].z)) {
2278 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2279 HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_09a001ee, "IMAGE",
2280 "vkCmdBlitImage: region [%d], source image of type VK_IMAGE_TYPE_1D or VK_IMAGE_TYPE_2D with "
2281 "srcOffset[].z values of (%1d, %1d). These must be (0, 1). %s",
2282 i, rgn.srcOffsets[0].z, rgn.srcOffsets[1].z, validation_error_map[VALIDATION_ERROR_09a001ee]);
2283 }
2284 }
2285
2286 if ((rgn.srcOffsets[0].x < 0) || (rgn.srcOffsets[0].x > static_cast<int32_t>(src_extent.width)) ||
2287 (rgn.srcOffsets[1].x < 0) || (rgn.srcOffsets[1].x > static_cast<int32_t>(src_extent.width))) {
2288 skip |= log_msg(
2289 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2290 HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_09a001e6, "IMAGE",
2291 "vkCmdBlitImage: region [%d] srcOffset[].x values (%1d, %1d) exceed srcSubresource width extent (%1d). %s", i,
2292 rgn.srcOffsets[0].x, rgn.srcOffsets[1].x, src_extent.width, validation_error_map[VALIDATION_ERROR_09a001e6]);
2293 }
2294 if ((rgn.srcOffsets[0].y < 0) || (rgn.srcOffsets[0].y > static_cast<int32_t>(src_extent.height)) ||
2295 (rgn.srcOffsets[1].y < 0) || (rgn.srcOffsets[1].y > static_cast<int32_t>(src_extent.height))) {
2296 skip |= log_msg(
2297 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2298 HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_09a001e8, "IMAGE",
2299 "vkCmdBlitImage: region [%d] srcOffset[].y values (%1d, %1d) exceed srcSubresource height extent (%1d). %s", i,
2300 rgn.srcOffsets[0].y, rgn.srcOffsets[1].y, src_extent.height, validation_error_map[VALIDATION_ERROR_09a001e8]);
2301 }
2302 if ((rgn.srcOffsets[0].z < 0) || (rgn.srcOffsets[0].z > static_cast<int32_t>(src_extent.depth)) ||
2303 (rgn.srcOffsets[1].z < 0) || (rgn.srcOffsets[1].z > static_cast<int32_t>(src_extent.depth))) {
2304 skip |= log_msg(
2305 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2306 HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_09a001ec, "IMAGE",
2307 "vkCmdBlitImage: region [%d] srcOffset[].z values (%1d, %1d) exceed srcSubresource depth extent (%1d). %s", i,
2308 rgn.srcOffsets[0].z, rgn.srcOffsets[1].z, src_extent.depth, validation_error_map[VALIDATION_ERROR_09a001ec]);
2309 }
2310
2311 // Validate dest image offsets
2312 VkExtent3D dst_extent = GetImageSubresourceExtent(dst_image_state, &(rgn.dstSubresource));
2313 if (VK_IMAGE_TYPE_1D == dst_image_state->createInfo.imageType) {
2314 if ((0 != rgn.dstOffsets[0].y) || (1 != rgn.dstOffsets[1].y)) {
2315 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2316 HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_09a001f4, "IMAGE",
2317 "vkCmdBlitImage: region [%d], dest image of type VK_IMAGE_TYPE_1D with dstOffset[].y values of "
2318 "(%1d, %1d). These must be (0, 1). %s",
2319 i, rgn.dstOffsets[0].y, rgn.dstOffsets[1].y, validation_error_map[VALIDATION_ERROR_09a001f4]);
2320 }
2321 }
2322
2323 if ((VK_IMAGE_TYPE_1D == dst_image_state->createInfo.imageType) ||
2324 (VK_IMAGE_TYPE_2D == dst_image_state->createInfo.imageType)) {
2325 if ((0 != rgn.dstOffsets[0].z) || (1 != rgn.dstOffsets[1].z)) {
2326 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2327 HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_09a001f8, "IMAGE",
2328 "vkCmdBlitImage: region [%d], dest image of type VK_IMAGE_TYPE_1D or VK_IMAGE_TYPE_2D with "
2329 "dstOffset[].z values of (%1d, %1d). These must be (0, 1). %s",
2330 i, rgn.dstOffsets[0].z, rgn.dstOffsets[1].z, validation_error_map[VALIDATION_ERROR_09a001f8]);
2331 }
2332 }
2333
2334 if ((rgn.dstOffsets[0].x < 0) || (rgn.dstOffsets[0].x > static_cast<int32_t>(dst_extent.width)) ||
2335 (rgn.dstOffsets[1].x < 0) || (rgn.dstOffsets[1].x > static_cast<int32_t>(dst_extent.width))) {
2336 skip |= log_msg(
2337 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2338 HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_09a001f0, "IMAGE",
2339 "vkCmdBlitImage: region [%d] dstOffset[].x values (%1d, %1d) exceed dstSubresource width extent (%1d). %s", i,
2340 rgn.dstOffsets[0].x, rgn.dstOffsets[1].x, dst_extent.width, validation_error_map[VALIDATION_ERROR_09a001f0]);
2341 }
2342 if ((rgn.dstOffsets[0].y < 0) || (rgn.dstOffsets[0].y > static_cast<int32_t>(dst_extent.height)) ||
2343 (rgn.dstOffsets[1].y < 0) || (rgn.dstOffsets[1].y > static_cast<int32_t>(dst_extent.height))) {
2344 skip |= log_msg(
2345 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2346 HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_09a001f2, "IMAGE",
2347 "vkCmdBlitImage: region [%d] dstOffset[].y values (%1d, %1d) exceed dstSubresource height extent (%1d). %s", i,
2348 rgn.dstOffsets[0].y, rgn.dstOffsets[1].y, dst_extent.height, validation_error_map[VALIDATION_ERROR_09a001f2]);
2349 }
2350 if ((rgn.dstOffsets[0].z < 0) || (rgn.dstOffsets[0].z > static_cast<int32_t>(dst_extent.depth)) ||
2351 (rgn.dstOffsets[1].z < 0) || (rgn.dstOffsets[1].z > static_cast<int32_t>(dst_extent.depth))) {
2352 skip |= log_msg(
2353 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2354 HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_09a001f6, "IMAGE",
2355 "vkCmdBlitImage: region [%d] dstOffset[].z values (%1d, %1d) exceed dstSubresource depth extent (%1d). %s", i,
2356 rgn.dstOffsets[0].z, rgn.dstOffsets[1].z, dst_extent.depth, validation_error_map[VALIDATION_ERROR_09a001f6]);
2357 }
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002358 }
2359
2360 VkFormat src_format = src_image_state->createInfo.format;
2361 VkFormat dst_format = dst_image_state->createInfo.format;
2362
2363 // Validate consistency for unsigned formats
Dave Houlton1d2022c2017-03-29 11:43:58 -06002364 if (FormatIsUInt(src_format) != FormatIsUInt(dst_format)) {
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002365 std::stringstream ss;
2366 ss << "vkCmdBlitImage: If one of srcImage and dstImage images has unsigned integer format, "
2367 << "the other one must also have unsigned integer format. "
2368 << "Source format is " << string_VkFormat(src_format) << " Destination format is " << string_VkFormat(dst_format);
2369 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002370 HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_184001cc, "IMAGE", "%s. %s",
2371 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_184001cc]);
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002372 }
2373
2374 // Validate consistency for signed formats
Dave Houlton1d2022c2017-03-29 11:43:58 -06002375 if (FormatIsSInt(src_format) != FormatIsSInt(dst_format)) {
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002376 std::stringstream ss;
2377 ss << "vkCmdBlitImage: If one of srcImage and dstImage images has signed integer format, "
2378 << "the other one must also have signed integer format. "
2379 << "Source format is " << string_VkFormat(src_format) << " Destination format is " << string_VkFormat(dst_format);
2380 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002381 HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_184001ca, "IMAGE", "%s. %s",
2382 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_184001ca]);
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002383 }
2384
2385 // Validate aspect bits and formats for depth/stencil images
Dave Houlton1d2022c2017-03-29 11:43:58 -06002386 if (FormatIsDepthOrStencil(src_format) || FormatIsDepthOrStencil(dst_format)) {
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002387 if (src_format != dst_format) {
2388 std::stringstream ss;
2389 ss << "vkCmdBlitImage: If one of srcImage and dstImage images has a format of depth, stencil or depth "
2390 << "stencil, the other one must have exactly the same format. "
2391 << "Source format is " << string_VkFormat(src_format) << " Destination format is "
2392 << string_VkFormat(dst_format);
2393 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002394 HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_184001ce, "IMAGE", "%s. %s",
2395 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_184001ce]);
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002396 }
2397
Dave Houlton48989f32017-05-26 15:01:46 -06002398#if 0 // TODO: Cannot find VU statements or spec language for these in CmdBlitImage. Verify or remove.
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002399 for (uint32_t i = 0; i < regionCount; i++) {
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002400 VkImageAspectFlags srcAspect = pRegions[i].srcSubresource.aspectMask;
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002401
Dave Houlton1d2022c2017-03-29 11:43:58 -06002402 if (FormatIsDepthAndStencil(src_format)) {
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002403 if ((srcAspect != VK_IMAGE_ASPECT_DEPTH_BIT) && (srcAspect != VK_IMAGE_ASPECT_STENCIL_BIT)) {
2404 std::stringstream ss;
2405 ss << "vkCmdBlitImage: Combination depth/stencil image formats must have only one of "
2406 "VK_IMAGE_ASPECT_DEPTH_BIT "
2407 << "and VK_IMAGE_ASPECT_STENCIL_BIT set in srcImage and dstImage";
2408 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 +02002409 HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE",
2410 "%s", ss.str().c_str());
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002411 }
Dave Houlton1d2022c2017-03-29 11:43:58 -06002412 } else if (FormatIsStencilOnly(src_format)) {
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002413 if (srcAspect != VK_IMAGE_ASPECT_STENCIL_BIT) {
2414 std::stringstream ss;
2415 ss << "vkCmdBlitImage: Stencil-only image formats must have only the VK_IMAGE_ASPECT_STENCIL_BIT "
2416 << "set in both the srcImage and dstImage";
2417 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 +02002418 HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE",
2419 "%s", ss.str().c_str());
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002420 }
Dave Houlton1d2022c2017-03-29 11:43:58 -06002421 } else if (FormatIsDepthOnly(src_format)) {
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002422 if (srcAspect != VK_IMAGE_ASPECT_DEPTH_BIT) {
2423 std::stringstream ss;
2424 ss << "vkCmdBlitImage: Depth-only image formats must have only the VK_IMAGE_ASPECT_DEPTH "
2425 << "set in both the srcImage and dstImage";
2426 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 +02002427 HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE",
2428 "%s", ss.str().c_str());
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002429 }
2430 }
2431 }
Dave Houlton48989f32017-05-26 15:01:46 -06002432#endif
2433 } // Depth/Stencil
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002434
2435 // Validate filter
Dave Houlton1d2022c2017-03-29 11:43:58 -06002436 if (FormatIsDepthOrStencil(src_format) && (filter != VK_FILTER_NEAREST)) {
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002437 std::stringstream ss;
2438 ss << "vkCmdBlitImage: If the format of srcImage is a depth, stencil, or depth stencil "
2439 << "then filter must be VK_FILTER_NEAREST.";
2440 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002441 HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_184001d0, "IMAGE", "%s. %s",
2442 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_184001d0]);
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002443 }
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07002444 } else {
2445 assert(0);
2446 }
2447 return skip;
2448}
2449
Tobin Ehlis58c884f2017-02-08 12:15:27 -07002450void PreCallRecordCmdBlitImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state,
2451 IMAGE_STATE *dst_image_state) {
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07002452 // Update bindings between images and cmd buffer
2453 AddCommandBufferBindingImage(device_data, cb_node, src_image_state);
2454 AddCommandBufferBindingImage(device_data, cb_node, dst_image_state);
2455
2456 std::function<bool()> function = [=]() { return ValidateImageMemoryIsValid(device_data, src_image_state, "vkCmdBlitImage()"); };
2457 cb_node->validate_functions.push_back(function);
2458 function = [=]() {
2459 SetImageMemoryValid(device_data, dst_image_state, true);
2460 return false;
2461 };
2462 cb_node->validate_functions.push_back(function);
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07002463}
2464
Tony Barbourdf013b92017-01-25 12:53:48 -07002465// This validates that the initial layout specified in the command buffer for
2466// the IMAGE is the same
2467// as the global IMAGE layout
Tony Barboure0c5cc92017-02-08 13:53:39 -07002468bool ValidateCmdBufImageLayouts(layer_data *device_data, GLOBAL_CB_NODE *pCB,
2469 std::unordered_map<ImageSubresourcePair, IMAGE_LAYOUT_NODE> &imageLayoutMap) {
Mark Lobodzinskib0dd9472017-02-07 16:38:17 -07002470 bool skip = false;
Tony Barbourdf013b92017-01-25 12:53:48 -07002471 const debug_report_data *report_data = core_validation::GetReportData(device_data);
Mark Lobodzinski4a3065e2017-02-07 16:36:03 -07002472 for (auto cb_image_data : pCB->imageLayoutMap) {
2473 VkImageLayout imageLayout;
Tony Barbourdf013b92017-01-25 12:53:48 -07002474
Jeremy Hayes55b6c292017-02-28 09:44:45 -07002475 if (FindLayout(imageLayoutMap, cb_image_data.first, imageLayout)) {
Mark Lobodzinski4a3065e2017-02-07 16:36:03 -07002476 if (cb_image_data.second.initialLayout == VK_IMAGE_LAYOUT_UNDEFINED) {
2477 // TODO: Set memory invalid which is in mem_tracker currently
2478 } else if (imageLayout != cb_image_data.second.initialLayout) {
2479 if (cb_image_data.first.hasSubresource) {
Petr Krausbc7f5442017-05-14 23:43:38 +02002480 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2481 HandleToUint64(pCB->commandBuffer), __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
2482 "Cannot submit cmd buffer using image (0x%" PRIx64
2483 ") [sub-resource: aspectMask 0x%X array layer %u, mip level %u], "
2484 "with layout %s when first use is %s.",
2485 HandleToUint64(cb_image_data.first.image), cb_image_data.first.subresource.aspectMask,
2486 cb_image_data.first.subresource.arrayLayer, cb_image_data.first.subresource.mipLevel,
2487 string_VkImageLayout(imageLayout), string_VkImageLayout(cb_image_data.second.initialLayout));
Mark Lobodzinski4a3065e2017-02-07 16:36:03 -07002488 } else {
Petr Krausbc7f5442017-05-14 23:43:38 +02002489 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2490 HandleToUint64(pCB->commandBuffer), __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
2491 "Cannot submit cmd buffer using image (0x%" PRIx64
2492 ") with layout %s when "
2493 "first use is %s.",
2494 HandleToUint64(cb_image_data.first.image), string_VkImageLayout(imageLayout),
2495 string_VkImageLayout(cb_image_data.second.initialLayout));
Mark Lobodzinski4a3065e2017-02-07 16:36:03 -07002496 }
2497 }
Tony Barbourdf013b92017-01-25 12:53:48 -07002498 SetLayout(imageLayoutMap, cb_image_data.first, cb_image_data.second.layout);
Mark Lobodzinski4a3065e2017-02-07 16:36:03 -07002499 }
2500 }
Mark Lobodzinskib0dd9472017-02-07 16:38:17 -07002501 return skip;
Mark Lobodzinski4a3065e2017-02-07 16:36:03 -07002502}
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002503
Tony Barbourdf013b92017-01-25 12:53:48 -07002504void UpdateCmdBufImageLayouts(layer_data *device_data, GLOBAL_CB_NODE *pCB) {
2505 for (auto cb_image_data : pCB->imageLayoutMap) {
2506 VkImageLayout imageLayout;
2507 FindGlobalLayout(device_data, cb_image_data.first, imageLayout);
2508 SetGlobalLayout(device_data, cb_image_data.first, cb_image_data.second.layout);
2509 }
2510}
2511
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002512// Print readable FlagBits in FlagMask
2513static std::string string_VkAccessFlags(VkAccessFlags accessMask) {
2514 std::string result;
2515 std::string separator;
2516
2517 if (accessMask == 0) {
2518 result = "[None]";
2519 } else {
2520 result = "[";
2521 for (auto i = 0; i < 32; i++) {
2522 if (accessMask & (1 << i)) {
2523 result = result + separator + string_VkAccessFlagBits((VkAccessFlagBits)(1 << i));
2524 separator = " | ";
2525 }
2526 }
2527 result = result + "]";
2528 }
2529 return result;
2530}
2531
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002532// AccessFlags MUST have 'required_bit' set, and may have one or more of 'optional_bits' set. If required_bit is zero, accessMask
2533// must have at least one of 'optional_bits' set
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002534// TODO: Add tracking to ensure that at least one barrier has been set for these layout transitions
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002535static bool ValidateMaskBits(core_validation::layer_data *device_data, VkCommandBuffer cmdBuffer, const VkAccessFlags &accessMask,
2536 const VkImageLayout &layout, VkAccessFlags required_bit, VkAccessFlags optional_bits,
2537 const char *type) {
2538 const debug_report_data *report_data = core_validation::GetReportData(device_data);
2539 bool skip = false;
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002540
2541 if ((accessMask & required_bit) || (!required_bit && (accessMask & optional_bits))) {
2542 if (accessMask & ~(required_bit | optional_bits)) {
2543 // TODO: Verify against Valid Use
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06002544 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 +02002545 HandleToUint64(cmdBuffer), __LINE__, DRAWSTATE_INVALID_BARRIER, "DS",
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002546 "Additional bits in %s accessMask 0x%X %s are specified when layout is %s.", type, accessMask,
2547 string_VkAccessFlags(accessMask).c_str(), string_VkImageLayout(layout));
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002548 }
2549 } else {
2550 if (!required_bit) {
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06002551 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 +02002552 HandleToUint64(cmdBuffer), __LINE__, DRAWSTATE_INVALID_BARRIER, "DS",
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002553 "%s AccessMask %d %s must contain at least one of access bits %d "
2554 "%s when layout is %s, unless the app has previously added a "
2555 "barrier for this transition.",
2556 type, accessMask, string_VkAccessFlags(accessMask).c_str(), optional_bits,
2557 string_VkAccessFlags(optional_bits).c_str(), string_VkImageLayout(layout));
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002558 } else {
2559 std::string opt_bits;
2560 if (optional_bits != 0) {
2561 std::stringstream ss;
2562 ss << optional_bits;
2563 opt_bits = "and may have optional bits " + ss.str() + ' ' + string_VkAccessFlags(optional_bits);
2564 }
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06002565 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 +02002566 HandleToUint64(cmdBuffer), __LINE__, DRAWSTATE_INVALID_BARRIER, "DS",
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002567 "%s AccessMask %d %s must have required access bit %d %s %s when "
2568 "layout is %s, unless the app has previously added a barrier for "
2569 "this transition.",
2570 type, accessMask, string_VkAccessFlags(accessMask).c_str(), required_bit,
2571 string_VkAccessFlags(required_bit).c_str(), opt_bits.c_str(), string_VkImageLayout(layout));
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002572 }
2573 }
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002574 return skip;
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002575}
2576
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002577bool ValidateMaskBitsFromLayouts(core_validation::layer_data *device_data, VkCommandBuffer cmdBuffer,
2578 const VkAccessFlags &accessMask, const VkImageLayout &layout, const char *type) {
2579 const debug_report_data *report_data = core_validation::GetReportData(device_data);
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002580
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002581 bool skip = false;
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002582 switch (layout) {
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002583 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: {
2584 skip |= ValidateMaskBits(device_data, cmdBuffer, accessMask, layout, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2585 VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT, type);
2586 break;
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002587 }
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002588 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: {
2589 skip |= ValidateMaskBits(device_data, cmdBuffer, accessMask, layout, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
2590 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT, type);
2591 break;
2592 }
2593 case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL: {
2594 skip |= ValidateMaskBits(device_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_WRITE_BIT, 0, type);
2595 break;
2596 }
2597 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: {
2598 skip |= ValidateMaskBits(
2599 device_data, cmdBuffer, accessMask, layout, 0,
2600 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
2601 type);
2602 break;
2603 }
2604 case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: {
2605 skip |= ValidateMaskBits(device_data, cmdBuffer, accessMask, layout, 0,
2606 VK_ACCESS_INPUT_ATTACHMENT_READ_BIT | VK_ACCESS_SHADER_READ_BIT, type);
2607 break;
2608 }
2609 case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL: {
2610 skip |= ValidateMaskBits(device_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_READ_BIT, 0, type);
2611 break;
2612 }
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002613 case VK_IMAGE_LAYOUT_UNDEFINED: {
2614 if (accessMask != 0) {
2615 // TODO: Verify against Valid Use section spec
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06002616 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 +02002617 HandleToUint64(cmdBuffer), __LINE__, DRAWSTATE_INVALID_BARRIER, "DS",
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002618 "Additional bits in %s accessMask 0x%X %s are specified when layout is %s.", type, accessMask,
2619 string_VkAccessFlags(accessMask).c_str(), string_VkImageLayout(layout));
2620 }
2621 break;
2622 }
Chris Forbesbfd831d2017-04-28 17:29:10 -07002623 case VK_IMAGE_LAYOUT_PRESENT_SRC_KHR:
Dave Houlton1150cf52017-04-27 14:38:11 -06002624 // Notes: QueuePresentKHR performs automatic visibility operations,
2625 // so the app is /NOT/ required to include VK_ACCESS_MEMORY_READ_BIT
2626 // when transitioning to this layout.
2627 //
2628 // When transitioning /from/ this layout, the application needs to
2629 // avoid only a WAR hazard -- any writes need to be ordered after
2630 // the PE's reads. There is no need for a memory dependency for this
2631 // case.
Mark Lobodzinski087380c2017-05-16 14:42:25 -06002632 // Intentionally fall through
2633
2634 case VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR:
2635 // Todo -- shouldn't be valid unless extension is enabled
2636 // Intentionally fall through
Chris Forbesbfd831d2017-04-28 17:29:10 -07002637
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002638 case VK_IMAGE_LAYOUT_GENERAL:
2639 default: { break; }
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002640 }
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002641 return skip;
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002642}
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002643
2644// ValidateLayoutVsAttachmentDescription is a general function where we can validate various state associated with the
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002645// VkAttachmentDescription structs that are used by the sub-passes of a renderpass. Initial check is to make sure that READ_ONLY
2646// layout attachments don't have CLEAR as their loadOp.
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002647bool ValidateLayoutVsAttachmentDescription(const debug_report_data *report_data, const VkImageLayout first_layout,
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002648 const uint32_t attachment, const VkAttachmentDescription &attachment_description) {
2649 bool skip = false;
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002650 // Verify that initial loadOp on READ_ONLY attachments is not CLEAR
2651 if (attachment_description.loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR) {
2652 if ((first_layout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL) ||
2653 (first_layout == VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL)) {
Mark Lobodzinskieb9e73f2017-04-13 10:06:48 -06002654 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002655 VALIDATION_ERROR_12200688, "DS", "Cannot clear attachment %d with invalid first layout %s. %s",
2656 attachment, string_VkImageLayout(first_layout), validation_error_map[VALIDATION_ERROR_12200688]);
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002657 }
2658 }
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002659 return skip;
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002660}
2661
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002662bool ValidateLayouts(core_validation::layer_data *device_data, VkDevice device, const VkRenderPassCreateInfo *pCreateInfo) {
2663 const debug_report_data *report_data = core_validation::GetReportData(device_data);
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002664 bool skip = false;
2665
2666 // Track when we're observing the first use of an attachment
2667 std::vector<bool> attach_first_use(pCreateInfo->attachmentCount, true);
2668 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
2669 const VkSubpassDescription &subpass = pCreateInfo->pSubpasses[i];
Cort Stratton7547f772017-05-04 15:18:52 -07002670
2671 // Check input attachments first, so we can detect first-use-as-input for VU #00349
2672 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
2673 auto attach_index = subpass.pInputAttachments[j].attachment;
2674 if (attach_index == VK_ATTACHMENT_UNUSED) continue;
2675
2676 switch (subpass.pInputAttachments[j].layout) {
2677 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL:
2678 case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL:
2679 // These are ideal.
2680 break;
2681
2682 case VK_IMAGE_LAYOUT_GENERAL:
2683 // May not be optimal. TODO: reconsider this warning based on other constraints.
2684 skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
2685 VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
2686 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
2687 break;
2688
2689 default:
2690 // No other layouts are acceptable
2691 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2692 __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
2693 "Layout for input attachment is %s but can only be READ_ONLY_OPTIMAL or GENERAL.",
2694 string_VkImageLayout(subpass.pInputAttachments[j].layout));
2695 }
2696
2697 VkImageLayout layout = subpass.pInputAttachments[j].layout;
2698 bool found_layout_mismatch = subpass.pDepthStencilAttachment &&
2699 subpass.pDepthStencilAttachment->attachment == attach_index &&
2700 subpass.pDepthStencilAttachment->layout != layout;
2701 for (uint32_t c = 0; !found_layout_mismatch && c < subpass.colorAttachmentCount; ++c) {
2702 found_layout_mismatch =
2703 (subpass.pColorAttachments[c].attachment == attach_index && subpass.pColorAttachments[c].layout != layout);
2704 }
2705 if (found_layout_mismatch) {
2706 skip |= log_msg(
2707 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002708 VALIDATION_ERROR_140006ae, "DS",
Cort Stratton7547f772017-05-04 15:18:52 -07002709 "CreateRenderPass: Subpass %u pInputAttachments[%u] (%u) has layout %u, but is also used as a depth/color "
2710 "attachment with a different layout. %s",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002711 i, j, attach_index, layout, validation_error_map[VALIDATION_ERROR_140006ae]);
Cort Stratton7547f772017-05-04 15:18:52 -07002712 }
2713
2714 if (attach_first_use[attach_index]) {
2715 skip |= ValidateLayoutVsAttachmentDescription(report_data, subpass.pInputAttachments[j].layout, attach_index,
2716 pCreateInfo->pAttachments[attach_index]);
2717
2718 bool used_as_depth =
2719 (subpass.pDepthStencilAttachment != NULL && subpass.pDepthStencilAttachment->attachment == attach_index);
2720 bool used_as_color = false;
2721 for (uint32_t k = 0; !used_as_depth && !used_as_color && k < subpass.colorAttachmentCount; ++k) {
2722 used_as_color = (subpass.pColorAttachments[k].attachment == attach_index);
2723 }
2724 if (!used_as_depth && !used_as_color &&
2725 pCreateInfo->pAttachments[attach_index].loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR) {
2726 skip |= log_msg(
2727 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002728 VALIDATION_ERROR_1400069c, "DS",
Cort Stratton7547f772017-05-04 15:18:52 -07002729 "CreateRenderPass: attachment %u is first used as an input attachment in subpass %u with loadOp=CLEAR. %s",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002730 attach_index, attach_index, validation_error_map[VALIDATION_ERROR_1400069c]);
Cort Stratton7547f772017-05-04 15:18:52 -07002731 }
2732 }
2733 attach_first_use[attach_index] = false;
2734 }
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002735 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
2736 auto attach_index = subpass.pColorAttachments[j].attachment;
2737 if (attach_index == VK_ATTACHMENT_UNUSED) continue;
2738
Tobin Ehlisbb03e5f2017-05-11 08:52:51 -06002739 // TODO: Need a way to validate shared presentable images here, currently just allowing
2740 // VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR
2741 // as an acceptable layout, but need to make sure shared presentable images ONLY use that layout
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002742 switch (subpass.pColorAttachments[j].layout) {
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002743 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL:
2744 // This is ideal.
Tobin Ehlisbb03e5f2017-05-11 08:52:51 -06002745 case VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR:
2746 // TODO: See note above, just assuming that attachment is shared presentable and allowing this for now.
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002747 break;
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002748
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002749 case VK_IMAGE_LAYOUT_GENERAL:
2750 // May not be optimal; TODO: reconsider this warning based on other constraints?
2751 skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
2752 VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
2753 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
2754 break;
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002755
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002756 default:
2757 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2758 __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
2759 "Layout for color attachment is %s but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.",
2760 string_VkImageLayout(subpass.pColorAttachments[j].layout));
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002761 }
2762
2763 if (attach_first_use[attach_index]) {
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002764 skip |= ValidateLayoutVsAttachmentDescription(report_data, subpass.pColorAttachments[j].layout, attach_index,
2765 pCreateInfo->pAttachments[attach_index]);
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002766 }
2767 attach_first_use[attach_index] = false;
2768 }
2769 if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
2770 switch (subpass.pDepthStencilAttachment->layout) {
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002771 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
2772 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL:
2773 // These are ideal.
2774 break;
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002775
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002776 case VK_IMAGE_LAYOUT_GENERAL:
2777 // May not be optimal; TODO: reconsider this warning based on other constraints? GENERAL can be better than
2778 // doing a bunch of transitions.
2779 skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
2780 VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
2781 "GENERAL layout for depth attachment may not give optimal performance.");
2782 break;
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002783
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002784 default:
2785 // No other layouts are acceptable
2786 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2787 __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
2788 "Layout for depth attachment is %s but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL, "
2789 "DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.",
2790 string_VkImageLayout(subpass.pDepthStencilAttachment->layout));
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002791 }
2792
2793 auto attach_index = subpass.pDepthStencilAttachment->attachment;
2794 if (attach_first_use[attach_index]) {
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002795 skip |= ValidateLayoutVsAttachmentDescription(report_data, subpass.pDepthStencilAttachment->layout, attach_index,
2796 pCreateInfo->pAttachments[attach_index]);
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002797 }
2798 attach_first_use[attach_index] = false;
2799 }
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002800 }
2801 return skip;
2802}
Mark Lobodzinski08f14fa2017-02-07 17:20:06 -07002803
2804// For any image objects that overlap mapped memory, verify that their layouts are PREINIT or GENERAL
Mark Lobodzinskiac23ec82017-02-07 17:21:55 -07002805bool ValidateMapImageLayouts(core_validation::layer_data *device_data, VkDevice device, DEVICE_MEM_INFO const *mem_info,
2806 VkDeviceSize offset, VkDeviceSize end_offset) {
2807 const debug_report_data *report_data = core_validation::GetReportData(device_data);
2808 bool skip = false;
2809 // Iterate over all bound image ranges and verify that for any that overlap the map ranges, the layouts are
2810 // VK_IMAGE_LAYOUT_PREINITIALIZED or VK_IMAGE_LAYOUT_GENERAL
Mark Lobodzinski08f14fa2017-02-07 17:20:06 -07002811 // TODO : This can be optimized if we store ranges based on starting address and early exit when we pass our range
2812 for (auto image_handle : mem_info->bound_images) {
2813 auto img_it = mem_info->bound_ranges.find(image_handle);
2814 if (img_it != mem_info->bound_ranges.end()) {
Mark Lobodzinskiac23ec82017-02-07 17:21:55 -07002815 if (rangesIntersect(device_data, &img_it->second, offset, end_offset)) {
Mark Lobodzinski08f14fa2017-02-07 17:20:06 -07002816 std::vector<VkImageLayout> layouts;
Mark Lobodzinskiac23ec82017-02-07 17:21:55 -07002817 if (FindLayouts(device_data, VkImage(image_handle), layouts)) {
Mark Lobodzinski08f14fa2017-02-07 17:20:06 -07002818 for (auto layout : layouts) {
2819 if (layout != VK_IMAGE_LAYOUT_PREINITIALIZED && layout != VK_IMAGE_LAYOUT_GENERAL) {
Petr Krausbc7f5442017-05-14 23:43:38 +02002820 skip |=
2821 log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_MEMORY_EXT,
2822 HandleToUint64(mem_info->mem), __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
2823 "Mapping an image with layout %s can result in undefined behavior if this memory is "
2824 "used by the device. Only GENERAL or PREINITIALIZED should be used.",
2825 string_VkImageLayout(layout));
Mark Lobodzinski08f14fa2017-02-07 17:20:06 -07002826 }
2827 }
2828 }
2829 }
2830 }
2831 }
Mark Lobodzinskiac23ec82017-02-07 17:21:55 -07002832 return skip;
Mark Lobodzinski08f14fa2017-02-07 17:20:06 -07002833}
Mark Lobodzinski96210742017-02-09 10:33:46 -07002834
2835// Helper function to validate correct usage bits set for buffers or images. Verify that (actual & desired) flags != 0 or, if strict
2836// is true, verify that (actual & desired) flags == desired
Mark Lobodzinski95dbbe52017-02-09 10:40:41 -07002837static 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 -06002838 VulkanObjectType obj_type, int32_t const msgCode, char const *func_name, char const *usage_str) {
Mark Lobodzinski95dbbe52017-02-09 10:40:41 -07002839 const debug_report_data *report_data = core_validation::GetReportData(device_data);
Mark Lobodzinski96210742017-02-09 10:33:46 -07002840
2841 bool correct_usage = false;
Mark Lobodzinski95dbbe52017-02-09 10:40:41 -07002842 bool skip = false;
Mark Lobodzinski33826372017-04-13 11:10:11 -06002843 const char *type_str = object_string[obj_type];
Mark Lobodzinski96210742017-02-09 10:33:46 -07002844 if (strict) {
2845 correct_usage = ((actual & desired) == desired);
2846 } else {
2847 correct_usage = ((actual & desired) != 0);
2848 }
2849 if (!correct_usage) {
2850 if (msgCode == -1) {
2851 // TODO: Fix callers with msgCode == -1 to use correct validation checks.
Mark Lobodzinskic51dbb72017-04-13 14:25:39 -06002852 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 -06002853 MEMTRACK_INVALID_USAGE_FLAG, "MEM",
2854 "Invalid usage flag for %s 0x%" PRIxLEAST64
2855 " used by %s. In this case, %s should have %s set during creation.",
2856 type_str, obj_handle, func_name, type_str, usage_str);
Mark Lobodzinski96210742017-02-09 10:33:46 -07002857 } else {
2858 const char *valid_usage = (msgCode == -1) ? "" : validation_error_map[msgCode];
Mark Lobodzinski33826372017-04-13 11:10:11 -06002859 skip = log_msg(
Mark Lobodzinskic51dbb72017-04-13 14:25:39 -06002860 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 -06002861 "Invalid usage flag for %s 0x%" PRIxLEAST64 " used by %s. In this case, %s should have %s set during creation. %s",
2862 type_str, obj_handle, func_name, type_str, usage_str, valid_usage);
Mark Lobodzinski96210742017-02-09 10:33:46 -07002863 }
2864 }
Mark Lobodzinski95dbbe52017-02-09 10:40:41 -07002865 return skip;
Mark Lobodzinski96210742017-02-09 10:33:46 -07002866}
2867
2868// Helper function to validate usage flags for buffers. For given buffer_state send actual vs. desired usage off to helper above
2869// where an error will be flagged if usage is not correct
Chris Forbes8fdba302017-04-24 18:34:28 -07002870bool ValidateImageUsageFlags(layer_data *device_data, IMAGE_STATE const *image_state, VkFlags desired, bool strict,
Mark Lobodzinski96210742017-02-09 10:33:46 -07002871 int32_t const msgCode, char const *func_name, char const *usage_string) {
Petr Krausbc7f5442017-05-14 23:43:38 +02002872 return validate_usage_flags(device_data, image_state->createInfo.usage, desired, strict, HandleToUint64(image_state->image),
2873 kVulkanObjectTypeImage, msgCode, func_name, usage_string);
Mark Lobodzinski96210742017-02-09 10:33:46 -07002874}
2875
2876// Helper function to validate usage flags for buffers. For given buffer_state send actual vs. desired usage off to helper above
2877// where an error will be flagged if usage is not correct
Chris Forbes8fdba302017-04-24 18:34:28 -07002878bool ValidateBufferUsageFlags(layer_data *device_data, BUFFER_STATE const *buffer_state, VkFlags desired, bool strict,
Mark Lobodzinski96210742017-02-09 10:33:46 -07002879 int32_t const msgCode, char const *func_name, char const *usage_string) {
Petr Krausbc7f5442017-05-14 23:43:38 +02002880 return validate_usage_flags(device_data, buffer_state->createInfo.usage, desired, strict, HandleToUint64(buffer_state->buffer),
2881 kVulkanObjectTypeBuffer, msgCode, func_name, usage_string);
Mark Lobodzinski96210742017-02-09 10:33:46 -07002882}
2883
Mark Lobodzinski95dbbe52017-02-09 10:40:41 -07002884bool PreCallValidateCreateBuffer(layer_data *device_data, const VkBufferCreateInfo *pCreateInfo) {
Mark Lobodzinski96210742017-02-09 10:33:46 -07002885 bool skip = false;
Mark Lobodzinski847b60c2017-03-13 09:32:45 -06002886 const debug_report_data *report_data = core_validation::GetReportData(device_data);
2887
Chris Forbese0f511c2017-06-14 12:38:01 -07002888 // TODO: Add check for VALIDATION_ERROR_1ec0071e (sparse address space accounting)
Mark Lobodzinski847b60c2017-03-13 09:32:45 -06002889
2890 if ((pCreateInfo->flags & VK_BUFFER_CREATE_SPARSE_BINDING_BIT) && (!GetEnabledFeatures(device_data)->sparseBinding)) {
2891 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002892 VALIDATION_ERROR_01400726, "DS",
Mark Lobodzinski847b60c2017-03-13 09:32:45 -06002893 "vkCreateBuffer(): the sparseBinding device feature is disabled: Buffers cannot be created with the "
2894 "VK_BUFFER_CREATE_SPARSE_BINDING_BIT set. %s",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002895 validation_error_map[VALIDATION_ERROR_01400726]);
Mark Lobodzinski847b60c2017-03-13 09:32:45 -06002896 }
Mark Lobodzinskiaf355062017-03-13 09:35:01 -06002897
2898 if ((pCreateInfo->flags & VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT) && (!GetEnabledFeatures(device_data)->sparseResidencyBuffer)) {
2899 skip |=
2900 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
Chris Forbese0f511c2017-06-14 12:38:01 -07002901 VALIDATION_ERROR_01400728, "DS",
Mark Lobodzinskiaf355062017-03-13 09:35:01 -06002902 "vkCreateBuffer(): the sparseResidencyBuffer device feature is disabled: Buffers cannot be created with the "
Chris Forbese0f511c2017-06-14 12:38:01 -07002903 "VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT set. %s",
2904 validation_error_map[VALIDATION_ERROR_01400728]);
Mark Lobodzinskiaf355062017-03-13 09:35:01 -06002905 }
Mark Lobodzinski035a4cf2017-03-13 09:45:07 -06002906
2907 if ((pCreateInfo->flags & VK_BUFFER_CREATE_SPARSE_ALIASED_BIT) && (!GetEnabledFeatures(device_data)->sparseResidencyAliased)) {
2908 skip |=
2909 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
Chris Forbese0f511c2017-06-14 12:38:01 -07002910 VALIDATION_ERROR_0140072a, "DS",
Mark Lobodzinski035a4cf2017-03-13 09:45:07 -06002911 "vkCreateBuffer(): the sparseResidencyAliased device feature is disabled: Buffers cannot be created with the "
Chris Forbese0f511c2017-06-14 12:38:01 -07002912 "VK_BUFFER_CREATE_SPARSE_ALIASED_BIT set. %s",
2913 validation_error_map[VALIDATION_ERROR_0140072a]);
Mark Lobodzinski035a4cf2017-03-13 09:45:07 -06002914 }
Mark Lobodzinski96210742017-02-09 10:33:46 -07002915 return skip;
2916}
2917
2918void PostCallRecordCreateBuffer(layer_data *device_data, const VkBufferCreateInfo *pCreateInfo, VkBuffer *pBuffer) {
2919 // TODO : This doesn't create deep copy of pQueueFamilyIndices so need to fix that if/when we want that data to be valid
2920 GetBufferMap(device_data)
2921 ->insert(std::make_pair(*pBuffer, std::unique_ptr<BUFFER_STATE>(new BUFFER_STATE(*pBuffer, pCreateInfo))));
2922}
2923
Mark Lobodzinski95dbbe52017-02-09 10:40:41 -07002924bool PreCallValidateCreateBufferView(layer_data *device_data, const VkBufferViewCreateInfo *pCreateInfo) {
2925 bool skip = false;
2926 BUFFER_STATE *buffer_state = GetBufferState(device_data, pCreateInfo->buffer);
Mark Lobodzinski96210742017-02-09 10:33:46 -07002927 // If this isn't a sparse buffer, it needs to have memory backing it at CreateBufferView time
2928 if (buffer_state) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002929 skip |= ValidateMemoryIsBoundToBuffer(device_data, buffer_state, "vkCreateBufferView()", VALIDATION_ERROR_01a0074e);
Mark Lobodzinski96210742017-02-09 10:33:46 -07002930 // In order to create a valid buffer view, the buffer must have been created with at least one of the following flags:
2931 // UNIFORM_TEXEL_BUFFER_BIT or STORAGE_TEXEL_BUFFER_BIT
Mark Lobodzinski95dbbe52017-02-09 10:40:41 -07002932 skip |= ValidateBufferUsageFlags(
2933 device_data, buffer_state, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT, false,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002934 VALIDATION_ERROR_01a00748, "vkCreateBufferView()", "VK_BUFFER_USAGE_[STORAGE|UNIFORM]_TEXEL_BUFFER_BIT");
Mark Lobodzinski96210742017-02-09 10:33:46 -07002935 }
Mark Lobodzinski95dbbe52017-02-09 10:40:41 -07002936 return skip;
Mark Lobodzinski96210742017-02-09 10:33:46 -07002937}
2938
2939void PostCallRecordCreateBufferView(layer_data *device_data, const VkBufferViewCreateInfo *pCreateInfo, VkBufferView *pView) {
2940 (*GetBufferViewMap(device_data))[*pView] = std::unique_ptr<BUFFER_VIEW_STATE>(new BUFFER_VIEW_STATE(*pView, pCreateInfo));
2941}
Mark Lobodzinski602de982017-02-09 11:01:33 -07002942
2943// For the given format verify that the aspect masks make sense
2944bool ValidateImageAspectMask(layer_data *device_data, VkImage image, VkFormat format, VkImageAspectFlags aspect_mask,
2945 const char *func_name) {
2946 const debug_report_data *report_data = core_validation::GetReportData(device_data);
2947 bool skip = false;
Dave Houlton1d2022c2017-03-29 11:43:58 -06002948 if (FormatIsColor(format)) {
Mark Lobodzinski602de982017-02-09 11:01:33 -07002949 if ((aspect_mask & VK_IMAGE_ASPECT_COLOR_BIT) != VK_IMAGE_ASPECT_COLOR_BIT) {
Petr Krausbc7f5442017-05-14 23:43:38 +02002950 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002951 HandleToUint64(image), __LINE__, VALIDATION_ERROR_0a400c01, "IMAGE",
Mark Lobodzinski602de982017-02-09 11:01:33 -07002952 "%s: Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set. %s", func_name,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002953 validation_error_map[VALIDATION_ERROR_0a400c01]);
Mark Lobodzinski602de982017-02-09 11:01:33 -07002954 } else if ((aspect_mask & VK_IMAGE_ASPECT_COLOR_BIT) != aspect_mask) {
Petr Krausbc7f5442017-05-14 23:43:38 +02002955 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002956 HandleToUint64(image), __LINE__, VALIDATION_ERROR_0a400c01, "IMAGE",
Mark Lobodzinski602de982017-02-09 11:01:33 -07002957 "%s: Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set. %s", func_name,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002958 validation_error_map[VALIDATION_ERROR_0a400c01]);
Mark Lobodzinski602de982017-02-09 11:01:33 -07002959 }
Dave Houlton1d2022c2017-03-29 11:43:58 -06002960 } else if (FormatIsDepthAndStencil(format)) {
Mark Lobodzinski602de982017-02-09 11:01:33 -07002961 if ((aspect_mask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) == 0) {
Petr Krausbc7f5442017-05-14 23:43:38 +02002962 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002963 HandleToUint64(image), __LINE__, VALIDATION_ERROR_0a400c01, "IMAGE",
Mark Lobodzinski602de982017-02-09 11:01:33 -07002964 "%s: Depth/stencil image formats must have "
2965 "at least one of VK_IMAGE_ASPECT_DEPTH_BIT "
2966 "and VK_IMAGE_ASPECT_STENCIL_BIT set. %s",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002967 func_name, validation_error_map[VALIDATION_ERROR_0a400c01]);
Mark Lobodzinski602de982017-02-09 11:01:33 -07002968 } else if ((aspect_mask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) != aspect_mask) {
Petr Krausbc7f5442017-05-14 23:43:38 +02002969 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002970 HandleToUint64(image), __LINE__, VALIDATION_ERROR_0a400c01, "IMAGE",
Mark Lobodzinski602de982017-02-09 11:01:33 -07002971 "%s: Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and "
2972 "VK_IMAGE_ASPECT_STENCIL_BIT set. %s",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002973 func_name, validation_error_map[VALIDATION_ERROR_0a400c01]);
Mark Lobodzinski602de982017-02-09 11:01:33 -07002974 }
Dave Houlton1d2022c2017-03-29 11:43:58 -06002975 } else if (FormatIsDepthOnly(format)) {
Mark Lobodzinski602de982017-02-09 11:01:33 -07002976 if ((aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) != VK_IMAGE_ASPECT_DEPTH_BIT) {
Petr Krausbc7f5442017-05-14 23:43:38 +02002977 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002978 HandleToUint64(image), __LINE__, VALIDATION_ERROR_0a400c01, "IMAGE",
Mark Lobodzinski602de982017-02-09 11:01:33 -07002979 "%s: Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set. %s", func_name,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002980 validation_error_map[VALIDATION_ERROR_0a400c01]);
Mark Lobodzinski602de982017-02-09 11:01:33 -07002981 } else if ((aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) != aspect_mask) {
Petr Krausbc7f5442017-05-14 23:43:38 +02002982 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002983 HandleToUint64(image), __LINE__, VALIDATION_ERROR_0a400c01, "IMAGE",
Mark Lobodzinski602de982017-02-09 11:01:33 -07002984 "%s: Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set. %s", func_name,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002985 validation_error_map[VALIDATION_ERROR_0a400c01]);
Mark Lobodzinski602de982017-02-09 11:01:33 -07002986 }
Dave Houlton1d2022c2017-03-29 11:43:58 -06002987 } else if (FormatIsStencilOnly(format)) {
Mark Lobodzinski602de982017-02-09 11:01:33 -07002988 if ((aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) != VK_IMAGE_ASPECT_STENCIL_BIT) {
Petr Krausbc7f5442017-05-14 23:43:38 +02002989 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002990 HandleToUint64(image), __LINE__, VALIDATION_ERROR_0a400c01, "IMAGE",
Mark Lobodzinski602de982017-02-09 11:01:33 -07002991 "%s: Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set. %s", func_name,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002992 validation_error_map[VALIDATION_ERROR_0a400c01]);
Mark Lobodzinski602de982017-02-09 11:01:33 -07002993 } else if ((aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) != aspect_mask) {
Petr Krausbc7f5442017-05-14 23:43:38 +02002994 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002995 HandleToUint64(image), __LINE__, VALIDATION_ERROR_0a400c01, "IMAGE",
Mark Lobodzinski602de982017-02-09 11:01:33 -07002996 "%s: Stencil-only image formats can have only the VK_IMAGE_ASPECT_STENCIL_BIT set. %s", func_name,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002997 validation_error_map[VALIDATION_ERROR_0a400c01]);
Mark Lobodzinski602de982017-02-09 11:01:33 -07002998 }
2999 }
3000 return skip;
3001}
3002
Petr Kraus8423f152017-05-26 01:20:04 +02003003bool ValidateImageSubresourceRange(const layer_data *device_data, const IMAGE_STATE *image_state, const bool is_imageview_2d_array,
Petr Kraus4d718682017-05-18 03:38:41 +02003004 const VkImageSubresourceRange &subresourceRange, const char *cmd_name, const char *param_name) {
Mark Lobodzinski602de982017-02-09 11:01:33 -07003005 const debug_report_data *report_data = core_validation::GetReportData(device_data);
3006 bool skip = false;
Petr Kraus4d718682017-05-18 03:38:41 +02003007
3008 // Validate mip levels
3009 const auto image_mip_count = image_state->createInfo.mipLevels;
3010
Mark Lobodzinski602de982017-02-09 11:01:33 -07003011 if (subresourceRange.levelCount == 0) {
Petr Kraus4d718682017-05-18 03:38:41 +02003012 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003013 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_0a8007fc, "IMAGE",
3014 "%s: %s.levelCount is 0. %s", cmd_name, param_name, validation_error_map[VALIDATION_ERROR_0a8007fc]);
Petr Kraus4d718682017-05-18 03:38:41 +02003015 } else if (subresourceRange.levelCount == VK_REMAINING_MIP_LEVELS) {
3016 // TODO: Not in the spec VUs. Probably missing -- KhronosGroup/Vulkan-Docs#416
3017 if (subresourceRange.baseMipLevel >= image_mip_count) {
3018 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
3019 HandleToUint64(image_state->image), __LINE__, DRAWSTATE_INVALID_IMAGE_SUBRANGE, "IMAGE",
3020 "%s: %s.baseMipLevel (= %" PRIu32 ") is greater or equal to the mip level count of the image (i.e. "
3021 "greater or equal to %" PRIu32 ").",
3022 cmd_name, param_name, subresourceRange.baseMipLevel, image_mip_count);
3023 }
3024 } else {
3025 const uint64_t necessary_mip_count = uint64_t{subresourceRange.baseMipLevel} + uint64_t{subresourceRange.levelCount};
3026
3027 if (necessary_mip_count > image_mip_count) {
3028 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003029 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_0a8007fc, "IMAGE",
3030 "%s: %s.baseMipLevel + .levelCount (= %" PRIu32 " + %" PRIu32 " = %" PRIu64
3031 ") is greater than the "
Petr Kraus4d718682017-05-18 03:38:41 +02003032 "mip level count of the image (i.e. greater than %" PRIu32 "). %s",
3033 cmd_name, param_name, subresourceRange.baseMipLevel, subresourceRange.levelCount, necessary_mip_count,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003034 image_mip_count, validation_error_map[VALIDATION_ERROR_0a8007fc]);
Petr Kraus4d718682017-05-18 03:38:41 +02003035 }
Mark Lobodzinski602de982017-02-09 11:01:33 -07003036 }
Petr Kraus4d718682017-05-18 03:38:41 +02003037
3038 // Validate array layers
Petr Kraus8423f152017-05-26 01:20:04 +02003039 bool is_khr_maintenance1 = GetDeviceExtensions(device_data)->vk_khr_maintenance1;
3040 bool is_3D_to_2D_map = is_khr_maintenance1 && image_state->createInfo.imageType == VK_IMAGE_TYPE_3D && is_imageview_2d_array;
Petr Kraus4d718682017-05-18 03:38:41 +02003041
3042 const auto image_layer_count = is_3D_to_2D_map ? image_state->createInfo.extent.depth : image_state->createInfo.arrayLayers;
3043 const auto image_layer_count_var_name = is_3D_to_2D_map ? "extent.depth" : "arrayLayers";
Petr Kraus8423f152017-05-26 01:20:04 +02003044
3045 const auto invalid_layer_code =
3046 is_khr_maintenance1 ? (is_3D_to_2D_map ? VALIDATION_ERROR_0a800800 : VALIDATION_ERROR_0a800802) : VALIDATION_ERROR_0a8007fe;
Petr Kraus4d718682017-05-18 03:38:41 +02003047
Mark Lobodzinski602de982017-02-09 11:01:33 -07003048 if (subresourceRange.layerCount == 0) {
Petr Kraus4d718682017-05-18 03:38:41 +02003049 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
3050 HandleToUint64(image_state->image), __LINE__, invalid_layer_code, "IMAGE", "%s: %s.layerCount is 0. %s",
3051 cmd_name, param_name, validation_error_map[invalid_layer_code]);
3052 } else if (subresourceRange.layerCount == VK_REMAINING_ARRAY_LAYERS) {
3053 // TODO: Not in the spec VUs. Probably missing -- KhronosGroup/Vulkan-Docs#416
3054 if (subresourceRange.baseArrayLayer >= image_layer_count) {
3055 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
3056 HandleToUint64(image_state->image), __LINE__, DRAWSTATE_INVALID_IMAGE_SUBRANGE, "IMAGE",
3057 "%s: %s.baseArrayLayer (= %" PRIu32 ") is greater or equal to the %s of the image when it was created "
3058 "(i.e. greater or equal to %" PRIu32 ").",
3059 cmd_name, param_name, subresourceRange.baseArrayLayer, image_layer_count_var_name, image_layer_count);
3060 }
3061 } else {
3062 const uint64_t necessary_layer_count = uint64_t{subresourceRange.baseArrayLayer} + uint64_t{subresourceRange.layerCount};
3063
3064 if (necessary_layer_count > image_layer_count) {
3065 skip |=
3066 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
3067 HandleToUint64(image_state->image), __LINE__, invalid_layer_code, "IMAGE",
3068 "%s: %s.baseArrayLayer + .layerCount (= %" PRIu32 " + %" PRIu32 " = %" PRIu64 ") is greater than the "
3069 "%s of the image when it was created (i.e. greater than %" PRIu32 "). %s",
3070 cmd_name, param_name, subresourceRange.baseArrayLayer, subresourceRange.layerCount, necessary_layer_count,
3071 image_layer_count_var_name, image_layer_count, validation_error_map[invalid_layer_code]);
3072 }
Mark Lobodzinski602de982017-02-09 11:01:33 -07003073 }
Petr Kraus4d718682017-05-18 03:38:41 +02003074
Mark Lobodzinski602de982017-02-09 11:01:33 -07003075 return skip;
3076}
3077
3078bool PreCallValidateCreateImageView(layer_data *device_data, const VkImageViewCreateInfo *create_info) {
3079 const debug_report_data *report_data = core_validation::GetReportData(device_data);
3080 bool skip = false;
3081 IMAGE_STATE *image_state = GetImageState(device_data, create_info->image);
3082 if (image_state) {
3083 skip |= ValidateImageUsageFlags(
3084 device_data, image_state,
3085 VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT |
3086 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
3087 false, -1, "vkCreateImageView()",
3088 "VK_IMAGE_USAGE_[SAMPLED|STORAGE|COLOR_ATTACHMENT|DEPTH_STENCIL_ATTACHMENT|INPUT_ATTACHMENT]_BIT");
3089 // If this isn't a sparse image, it needs to have memory backing it at CreateImageView time
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003090 skip |= ValidateMemoryIsBoundToImage(device_data, image_state, "vkCreateImageView()", VALIDATION_ERROR_0ac007f8);
Mark Lobodzinski602de982017-02-09 11:01:33 -07003091 // Checks imported from image layer
Petr Kraus8423f152017-05-26 01:20:04 +02003092 skip |= ValidateImageSubresourceRange(device_data, image_state, create_info->viewType == VK_IMAGE_VIEW_TYPE_2D_ARRAY,
3093 create_info->subresourceRange, "vkCreateImageView", "pCreateInfo->subresourceRange");
Mark Lobodzinski602de982017-02-09 11:01:33 -07003094
3095 VkImageCreateFlags image_flags = image_state->createInfo.flags;
3096 VkFormat image_format = image_state->createInfo.format;
3097 VkFormat view_format = create_info->format;
3098 VkImageAspectFlags aspect_mask = create_info->subresourceRange.aspectMask;
3099
3100 // Validate VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT state
3101 if (image_flags & VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT) {
3102 // 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 -06003103 if (FormatCompatibilityClass(image_format) != FormatCompatibilityClass(view_format)) {
Mark Lobodzinski602de982017-02-09 11:01:33 -07003104 std::stringstream ss;
3105 ss << "vkCreateImageView(): ImageView format " << string_VkFormat(view_format)
Petr Krausbc7f5442017-05-14 23:43:38 +02003106 << " is not in the same format compatibility class as image (" << HandleToUint64(create_info->image)
3107 << ") format " << string_VkFormat(image_format)
3108 << ". Images created with the VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
Mark Lobodzinski602de982017-02-09 11:01:33 -07003109 << "can support ImageViews with differing formats but they must be in the same compatibility class.";
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06003110 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003111 VALIDATION_ERROR_0ac007f4, "IMAGE", "%s %s", ss.str().c_str(),
3112 validation_error_map[VALIDATION_ERROR_0ac007f4]);
Mark Lobodzinski602de982017-02-09 11:01:33 -07003113 }
3114 } else {
3115 // Format MUST be IDENTICAL to the format the image was created with
3116 if (image_format != view_format) {
3117 std::stringstream ss;
3118 ss << "vkCreateImageView() format " << string_VkFormat(view_format) << " differs from image "
Petr Krausbc7f5442017-05-14 23:43:38 +02003119 << HandleToUint64(create_info->image) << " format " << string_VkFormat(image_format)
Mark Lobodzinski602de982017-02-09 11:01:33 -07003120 << ". Formats MUST be IDENTICAL unless VK_IMAGE_CREATE_MUTABLE_FORMAT BIT was set on image creation.";
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06003121 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003122 VALIDATION_ERROR_0ac007f6, "IMAGE", "%s %s", ss.str().c_str(),
3123 validation_error_map[VALIDATION_ERROR_0ac007f6]);
Mark Lobodzinski602de982017-02-09 11:01:33 -07003124 }
3125 }
3126
3127 // Validate correct image aspect bits for desired formats and format consistency
3128 skip |= ValidateImageAspectMask(device_data, image_state->image, image_format, aspect_mask, "vkCreateImageView()");
3129 }
3130 return skip;
3131}
3132
Mark Lobodzinskiefd933b2017-02-10 12:09:23 -07003133void PostCallRecordCreateImageView(layer_data *device_data, const VkImageViewCreateInfo *create_info, VkImageView view) {
3134 auto image_view_map = GetImageViewMap(device_data);
3135 (*image_view_map)[view] = std::unique_ptr<IMAGE_VIEW_STATE>(new IMAGE_VIEW_STATE(view, create_info));
3136
3137 auto image_state = GetImageState(device_data, create_info->image);
Dave Houlton4eaaf3a2017-03-14 11:31:20 -06003138 auto &sub_res_range = (*image_view_map)[view].get()->create_info.subresourceRange;
Mark Lobodzinski903e5ff2017-03-23 09:43:35 -06003139 sub_res_range.levelCount = ResolveRemainingLevels(&sub_res_range, image_state->createInfo.mipLevels);
3140 sub_res_range.layerCount = ResolveRemainingLayers(&sub_res_range, image_state->createInfo.arrayLayers);
Mark Lobodzinski602de982017-02-09 11:01:33 -07003141}
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07003142
Mark Lobodzinski680421d2017-02-09 13:06:56 -07003143bool PreCallValidateCmdCopyBuffer(layer_data *device_data, GLOBAL_CB_NODE *cb_node, BUFFER_STATE *src_buffer_state,
3144 BUFFER_STATE *dst_buffer_state) {
3145 bool skip = false;
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003146 skip |= ValidateMemoryIsBoundToBuffer(device_data, src_buffer_state, "vkCmdCopyBuffer()", VALIDATION_ERROR_18c000ee);
3147 skip |= ValidateMemoryIsBoundToBuffer(device_data, dst_buffer_state, "vkCmdCopyBuffer()", VALIDATION_ERROR_18c000f2);
Mark Lobodzinski680421d2017-02-09 13:06:56 -07003148 // Validate that SRC & DST buffers have correct usage flags set
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003149 skip |= ValidateBufferUsageFlags(device_data, src_buffer_state, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, true,
3150 VALIDATION_ERROR_18c000ec, "vkCmdCopyBuffer()", "VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
3151 skip |= ValidateBufferUsageFlags(device_data, dst_buffer_state, VK_BUFFER_USAGE_TRANSFER_DST_BIT, true,
3152 VALIDATION_ERROR_18c000f0, "vkCmdCopyBuffer()", "VK_BUFFER_USAGE_TRANSFER_DST_BIT");
Mike Schuchardt9c582402017-02-23 15:57:37 -07003153 skip |= ValidateCmdQueueFlags(device_data, cb_node, "vkCmdCopyBuffer()",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003154 VK_QUEUE_TRANSFER_BIT | VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT, VALIDATION_ERROR_18c02415);
Mark Lobodzinski680421d2017-02-09 13:06:56 -07003155 skip |= ValidateCmd(device_data, cb_node, CMD_COPYBUFFER, "vkCmdCopyBuffer()");
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003156 skip |= insideRenderPass(device_data, cb_node, "vkCmdCopyBuffer()", VALIDATION_ERROR_18c00017);
Mark Lobodzinski680421d2017-02-09 13:06:56 -07003157 return skip;
3158}
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07003159
Mark Lobodzinski680421d2017-02-09 13:06:56 -07003160void PreCallRecordCmdCopyBuffer(layer_data *device_data, GLOBAL_CB_NODE *cb_node, BUFFER_STATE *src_buffer_state,
3161 BUFFER_STATE *dst_buffer_state) {
3162 // Update bindings between buffers and cmd buffer
3163 AddCommandBufferBindingBuffer(device_data, cb_node, src_buffer_state);
3164 AddCommandBufferBindingBuffer(device_data, cb_node, dst_buffer_state);
3165
3166 std::function<bool()> function = [=]() {
3167 return ValidateBufferMemoryIsValid(device_data, src_buffer_state, "vkCmdCopyBuffer()");
3168 };
3169 cb_node->validate_functions.push_back(function);
3170 function = [=]() {
3171 SetBufferMemoryValid(device_data, dst_buffer_state, true);
3172 return false;
3173 };
3174 cb_node->validate_functions.push_back(function);
Mark Lobodzinski680421d2017-02-09 13:06:56 -07003175}
Mark Lobodzinski306441e2017-02-10 13:48:38 -07003176
3177static bool validateIdleBuffer(layer_data *device_data, VkBuffer buffer) {
3178 const debug_report_data *report_data = core_validation::GetReportData(device_data);
3179 bool skip = false;
3180 auto buffer_state = GetBufferState(device_data, buffer);
3181 if (!buffer_state) {
Petr Krausbc7f5442017-05-14 23:43:38 +02003182 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 -07003183 __LINE__, DRAWSTATE_DOUBLE_DESTROY, "DS",
Petr Krausbc7f5442017-05-14 23:43:38 +02003184 "Cannot free buffer 0x%" PRIxLEAST64 " that has not been allocated.", HandleToUint64(buffer));
Mark Lobodzinski306441e2017-02-10 13:48:38 -07003185 } else {
3186 if (buffer_state->in_use.load()) {
Petr Krausbc7f5442017-05-14 23:43:38 +02003187 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003188 HandleToUint64(buffer), __LINE__, VALIDATION_ERROR_23c00734, "DS",
Petr Krausbc7f5442017-05-14 23:43:38 +02003189 "Cannot free buffer 0x%" PRIxLEAST64 " that is in use by a command buffer. %s", HandleToUint64(buffer),
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003190 validation_error_map[VALIDATION_ERROR_23c00734]);
Mark Lobodzinski306441e2017-02-10 13:48:38 -07003191 }
3192 }
3193 return skip;
3194}
3195
3196bool PreCallValidateDestroyImageView(layer_data *device_data, VkImageView image_view, IMAGE_VIEW_STATE **image_view_state,
3197 VK_OBJECT *obj_struct) {
3198 *image_view_state = GetImageViewState(device_data, image_view);
Petr Krausbc7f5442017-05-14 23:43:38 +02003199 *obj_struct = {HandleToUint64(image_view), kVulkanObjectTypeImageView};
Mark Lobodzinski306441e2017-02-10 13:48:38 -07003200 if (GetDisables(device_data)->destroy_image_view) return false;
3201 bool skip = false;
3202 if (*image_view_state) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003203 skip |= ValidateObjectNotInUse(device_data, *image_view_state, *obj_struct, VALIDATION_ERROR_25400804);
Mark Lobodzinski306441e2017-02-10 13:48:38 -07003204 }
3205 return skip;
3206}
3207
3208void PostCallRecordDestroyImageView(layer_data *device_data, VkImageView image_view, IMAGE_VIEW_STATE *image_view_state,
3209 VK_OBJECT obj_struct) {
3210 // Any bound cmd buffers are now invalid
3211 invalidateCommandBuffers(device_data, image_view_state->cb_bindings, obj_struct);
3212 (*GetImageViewMap(device_data)).erase(image_view);
3213}
3214
3215bool PreCallValidateDestroyBuffer(layer_data *device_data, VkBuffer buffer, BUFFER_STATE **buffer_state, VK_OBJECT *obj_struct) {
3216 *buffer_state = GetBufferState(device_data, buffer);
Petr Krausbc7f5442017-05-14 23:43:38 +02003217 *obj_struct = {HandleToUint64(buffer), kVulkanObjectTypeBuffer};
Mark Lobodzinski306441e2017-02-10 13:48:38 -07003218 if (GetDisables(device_data)->destroy_buffer) return false;
3219 bool skip = false;
3220 if (*buffer_state) {
3221 skip |= validateIdleBuffer(device_data, buffer);
3222 }
3223 return skip;
3224}
3225
3226void PostCallRecordDestroyBuffer(layer_data *device_data, VkBuffer buffer, BUFFER_STATE *buffer_state, VK_OBJECT obj_struct) {
3227 invalidateCommandBuffers(device_data, buffer_state->cb_bindings, obj_struct);
3228 for (auto mem_binding : buffer_state->GetBoundMemory()) {
3229 auto mem_info = GetMemObjInfo(device_data, mem_binding);
3230 if (mem_info) {
Petr Krausbc7f5442017-05-14 23:43:38 +02003231 core_validation::RemoveBufferMemoryRange(HandleToUint64(buffer), mem_info);
Mark Lobodzinski306441e2017-02-10 13:48:38 -07003232 }
3233 }
Petr Krausbc7f5442017-05-14 23:43:38 +02003234 ClearMemoryObjectBindings(device_data, HandleToUint64(buffer), kVulkanObjectTypeBuffer);
Mark Lobodzinski306441e2017-02-10 13:48:38 -07003235 GetBufferMap(device_data)->erase(buffer_state->buffer);
3236}
3237
3238bool PreCallValidateDestroyBufferView(layer_data *device_data, VkBufferView buffer_view, BUFFER_VIEW_STATE **buffer_view_state,
3239 VK_OBJECT *obj_struct) {
3240 *buffer_view_state = GetBufferViewState(device_data, buffer_view);
Petr Krausbc7f5442017-05-14 23:43:38 +02003241 *obj_struct = {HandleToUint64(buffer_view), kVulkanObjectTypeBufferView};
Mark Lobodzinski306441e2017-02-10 13:48:38 -07003242 if (GetDisables(device_data)->destroy_buffer_view) return false;
3243 bool skip = false;
3244 if (*buffer_view_state) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003245 skip |= ValidateObjectNotInUse(device_data, *buffer_view_state, *obj_struct, VALIDATION_ERROR_23e00750);
Mark Lobodzinski306441e2017-02-10 13:48:38 -07003246 }
3247 return skip;
3248}
3249
3250void PostCallRecordDestroyBufferView(layer_data *device_data, VkBufferView buffer_view, BUFFER_VIEW_STATE *buffer_view_state,
3251 VK_OBJECT obj_struct) {
3252 // Any bound cmd buffers are now invalid
3253 invalidateCommandBuffers(device_data, buffer_view_state->cb_bindings, obj_struct);
3254 GetBufferViewMap(device_data)->erase(buffer_view);
3255}
Mark Lobodzinskidf0acbf2017-02-10 14:01:27 -07003256
3257bool PreCallValidateCmdFillBuffer(layer_data *device_data, GLOBAL_CB_NODE *cb_node, BUFFER_STATE *buffer_state) {
3258 bool skip = false;
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003259 skip |= ValidateMemoryIsBoundToBuffer(device_data, buffer_state, "vkCmdFillBuffer()", VALIDATION_ERROR_1b40003e);
Mike Schuchardt9c582402017-02-23 15:57:37 -07003260 skip |= ValidateCmdQueueFlags(device_data, cb_node, "vkCmdFillBuffer()",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003261 VK_QUEUE_TRANSFER_BIT | VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT, VALIDATION_ERROR_1b402415);
Mark Lobodzinskidf0acbf2017-02-10 14:01:27 -07003262 skip |= ValidateCmd(device_data, cb_node, CMD_FILLBUFFER, "vkCmdFillBuffer()");
3263 // Validate that DST buffer has correct usage flags set
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003264 skip |= ValidateBufferUsageFlags(device_data, buffer_state, VK_BUFFER_USAGE_TRANSFER_DST_BIT, true, VALIDATION_ERROR_1b40003a,
Mark Lobodzinskidf0acbf2017-02-10 14:01:27 -07003265 "vkCmdFillBuffer()", "VK_BUFFER_USAGE_TRANSFER_DST_BIT");
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003266 skip |= insideRenderPass(device_data, cb_node, "vkCmdFillBuffer()", VALIDATION_ERROR_1b400017);
Mark Lobodzinskidf0acbf2017-02-10 14:01:27 -07003267 return skip;
3268}
3269
3270void PreCallRecordCmdFillBuffer(layer_data *device_data, GLOBAL_CB_NODE *cb_node, BUFFER_STATE *buffer_state) {
3271 std::function<bool()> function = [=]() {
3272 SetBufferMemoryValid(device_data, buffer_state, true);
3273 return false;
3274 };
3275 cb_node->validate_functions.push_back(function);
3276 // Update bindings between buffer and cmd buffer
3277 AddCommandBufferBindingBuffer(device_data, cb_node, buffer_state);
Mark Lobodzinskidf0acbf2017-02-10 14:01:27 -07003278}
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003279
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003280bool ValidateBufferImageCopyData(const debug_report_data *report_data, uint32_t regionCount, const VkBufferImageCopy *pRegions,
3281 IMAGE_STATE *image_state, const char *function) {
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003282 bool skip = false;
3283
3284 for (uint32_t i = 0; i < regionCount; i++) {
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003285 if (image_state->createInfo.imageType == VK_IMAGE_TYPE_1D) {
3286 if ((pRegions[i].imageOffset.y != 0) || (pRegions[i].imageExtent.height != 1)) {
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003287 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003288 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_0160018e, "IMAGE",
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003289 "%s(): pRegion[%d] imageOffset.y is %d and imageExtent.height is %d. For 1D images these "
3290 "must be 0 and 1, respectively. %s",
3291 function, i, pRegions[i].imageOffset.y, pRegions[i].imageExtent.height,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003292 validation_error_map[VALIDATION_ERROR_0160018e]);
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003293 }
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003294 }
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003295
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003296 if ((image_state->createInfo.imageType == VK_IMAGE_TYPE_1D) || (image_state->createInfo.imageType == VK_IMAGE_TYPE_2D)) {
3297 if ((pRegions[i].imageOffset.z != 0) || (pRegions[i].imageExtent.depth != 1)) {
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003298 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003299 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_01600192, "IMAGE",
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003300 "%s(): pRegion[%d] imageOffset.z is %d and imageExtent.depth is %d. For 1D and 2D images these "
3301 "must be 0 and 1, respectively. %s",
3302 function, i, pRegions[i].imageOffset.z, pRegions[i].imageExtent.depth,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003303 validation_error_map[VALIDATION_ERROR_01600192]);
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003304 }
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003305 }
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003306
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003307 if (image_state->createInfo.imageType == VK_IMAGE_TYPE_3D) {
3308 if ((0 != pRegions[i].imageSubresource.baseArrayLayer) || (1 != pRegions[i].imageSubresource.layerCount)) {
3309 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003310 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_016001aa, "IMAGE",
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003311 "%s(): pRegion[%d] imageSubresource.baseArrayLayer is %d and imageSubresource.layerCount is "
3312 "%d. For 3D images these must be 0 and 1, respectively. %s",
3313 function, i, pRegions[i].imageSubresource.baseArrayLayer, pRegions[i].imageSubresource.layerCount,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003314 validation_error_map[VALIDATION_ERROR_016001aa]);
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003315 }
3316 }
3317
3318 // If the the calling command's VkImage parameter's format is not a depth/stencil format,
3319 // then bufferOffset must be a multiple of the calling command's VkImage parameter's texel size
Dave Houlton1d2022c2017-03-29 11:43:58 -06003320 auto texel_size = FormatSize(image_state->createInfo.format);
Dave Houlton1150cf52017-04-27 14:38:11 -06003321 if (!FormatIsDepthAndStencil(image_state->createInfo.format) && SafeModulo(pRegions[i].bufferOffset, texel_size) != 0) {
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003322 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003323 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_01600182, "IMAGE",
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003324 "%s(): pRegion[%d] bufferOffset 0x%" PRIxLEAST64
3325 " must be a multiple of this format's texel size (" PRINTF_SIZE_T_SPECIFIER "). %s",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003326 function, i, pRegions[i].bufferOffset, texel_size, validation_error_map[VALIDATION_ERROR_01600182]);
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003327 }
3328
3329 // BufferOffset must be a multiple of 4
Dave Houlton1d2022c2017-03-29 11:43:58 -06003330 if (SafeModulo(pRegions[i].bufferOffset, 4) != 0) {
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003331 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003332 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_01600184, "IMAGE",
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003333 "%s(): pRegion[%d] bufferOffset 0x%" PRIxLEAST64 " must be a multiple of 4. %s", function, i,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003334 pRegions[i].bufferOffset, validation_error_map[VALIDATION_ERROR_01600184]);
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003335 }
3336
3337 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
3338 if ((pRegions[i].bufferRowLength != 0) && (pRegions[i].bufferRowLength < pRegions[i].imageExtent.width)) {
3339 skip |= log_msg(
3340 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003341 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_01600186, "IMAGE",
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003342 "%s(): pRegion[%d] bufferRowLength (%d) must be zero or greater-than-or-equal-to imageExtent.width (%d). %s",
3343 function, i, pRegions[i].bufferRowLength, pRegions[i].imageExtent.width,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003344 validation_error_map[VALIDATION_ERROR_01600186]);
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003345 }
3346
3347 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
3348 if ((pRegions[i].bufferImageHeight != 0) && (pRegions[i].bufferImageHeight < pRegions[i].imageExtent.height)) {
3349 skip |= log_msg(
3350 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003351 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_01600188, "IMAGE",
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003352 "%s(): pRegion[%d] bufferImageHeight (%d) must be zero or greater-than-or-equal-to imageExtent.height (%d). %s",
3353 function, i, pRegions[i].bufferImageHeight, pRegions[i].imageExtent.height,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003354 validation_error_map[VALIDATION_ERROR_01600188]);
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003355 }
3356
3357 // subresource aspectMask must have exactly 1 bit set
3358 const int num_bits = sizeof(VkFlags) * CHAR_BIT;
3359 std::bitset<num_bits> aspect_mask_bits(pRegions[i].imageSubresource.aspectMask);
3360 if (aspect_mask_bits.count() != 1) {
3361 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003362 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_016001a8, "IMAGE",
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003363 "%s: aspectMasks for imageSubresource in each region must have only a single bit set. %s", function,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003364 validation_error_map[VALIDATION_ERROR_016001a8]);
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003365 }
3366
3367 // image subresource aspect bit must match format
Dave Houlton4eaaf3a2017-03-14 11:31:20 -06003368 if (!VerifyAspectsPresent(pRegions[i].imageSubresource.aspectMask, image_state->createInfo.format)) {
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003369 skip |= log_msg(
3370 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003371 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_016001a6, "IMAGE",
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003372 "%s(): pRegion[%d] subresource aspectMask 0x%x specifies aspects that are not present in image format 0x%x. %s",
3373 function, i, pRegions[i].imageSubresource.aspectMask, image_state->createInfo.format,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003374 validation_error_map[VALIDATION_ERROR_016001a6]);
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003375 }
3376
3377 // Checks that apply only to compressed images
3378 // TODO: there is a comment in ValidateCopyBufferImageTransferGranularityRequirements() in core_validation.cpp that
3379 // reserves a place for these compressed image checks. This block of code could move there once the image
3380 // stuff is moved into core validation.
Dave Houlton1d2022c2017-03-29 11:43:58 -06003381 if (FormatIsCompressed(image_state->createInfo.format)) {
3382 auto block_size = FormatCompressedTexelBlockExtent(image_state->createInfo.format);
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003383
3384 // BufferRowLength must be a multiple of block width
Dave Houlton1d2022c2017-03-29 11:43:58 -06003385 if (SafeModulo(pRegions[i].bufferRowLength, block_size.width) != 0) {
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003386 skip |= log_msg(
3387 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003388 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_01600196, "IMAGE",
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003389 "%s(): pRegion[%d] bufferRowLength (%d) must be a multiple of the compressed image's texel width (%d). %s.",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003390 function, i, pRegions[i].bufferRowLength, block_size.width, validation_error_map[VALIDATION_ERROR_01600196]);
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003391 }
3392
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003393 // BufferRowHeight must be a multiple of block height
Dave Houlton1d2022c2017-03-29 11:43:58 -06003394 if (SafeModulo(pRegions[i].bufferImageHeight, block_size.height) != 0) {
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003395 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003396 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_01600198, "IMAGE",
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003397 "%s(): pRegion[%d] bufferImageHeight (%d) must be a multiple of the compressed image's texel "
3398 "height (%d). %s.",
3399 function, i, pRegions[i].bufferImageHeight, block_size.height,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003400 validation_error_map[VALIDATION_ERROR_01600198]);
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003401 }
3402
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003403 // image offsets must be multiples of block dimensions
Dave Houlton1d2022c2017-03-29 11:43:58 -06003404 if ((SafeModulo(pRegions[i].imageOffset.x, block_size.width) != 0) ||
3405 (SafeModulo(pRegions[i].imageOffset.y, block_size.height) != 0) ||
3406 (SafeModulo(pRegions[i].imageOffset.z, block_size.depth) != 0)) {
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003407 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003408 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_0160019a, "IMAGE",
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003409 "%s(): pRegion[%d] imageOffset(x,y) (%d, %d) must be multiples of the compressed image's texel "
3410 "width & height (%d, %d). %s.",
3411 function, i, pRegions[i].imageOffset.x, pRegions[i].imageOffset.y, block_size.width,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003412 block_size.height, validation_error_map[VALIDATION_ERROR_0160019a]);
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003413 }
3414
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003415 // bufferOffset must be a multiple of block size (linear bytes)
Dave Houlton1d2022c2017-03-29 11:43:58 -06003416 size_t block_size_in_bytes = FormatSize(image_state->createInfo.format);
3417 if (SafeModulo(pRegions[i].bufferOffset, block_size_in_bytes) != 0) {
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003418 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003419 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_0160019c, "IMAGE",
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003420 "%s(): pRegion[%d] bufferOffset (0x%" PRIxLEAST64
3421 ") must be a multiple of the compressed image's texel block "
3422 "size (" PRINTF_SIZE_T_SPECIFIER "). %s.",
3423 function, i, pRegions[i].bufferOffset, block_size_in_bytes,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003424 validation_error_map[VALIDATION_ERROR_0160019c]);
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003425 }
Dave Houlton67e9b532017-03-02 17:00:10 -07003426
3427 // imageExtent width must be a multiple of block width, or extent+offset width must equal subresource width
Dave Houlton75967fc2017-03-06 17:21:16 -07003428 VkExtent3D mip_extent = GetImageSubresourceExtent(image_state, &(pRegions[i].imageSubresource));
Dave Houlton1d2022c2017-03-29 11:43:58 -06003429 if ((SafeModulo(pRegions[i].imageExtent.width, block_size.width) != 0) &&
Dave Houlton75967fc2017-03-06 17:21:16 -07003430 (pRegions[i].imageExtent.width + pRegions[i].imageOffset.x != mip_extent.width)) {
3431 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003432 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_0160019e, "IMAGE",
Dave Houlton75967fc2017-03-06 17:21:16 -07003433 "%s(): pRegion[%d] extent width (%d) must be a multiple of the compressed texture block width "
3434 "(%d), or when added to offset.x (%d) must equal the image subresource width (%d). %s.",
3435 function, i, pRegions[i].imageExtent.width, block_size.width, pRegions[i].imageOffset.x,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003436 mip_extent.width, validation_error_map[VALIDATION_ERROR_0160019e]);
Dave Houlton67e9b532017-03-02 17:00:10 -07003437 }
3438
3439 // imageExtent height must be a multiple of block height, or extent+offset height must equal subresource height
Dave Houlton1d2022c2017-03-29 11:43:58 -06003440 if ((SafeModulo(pRegions[i].imageExtent.height, block_size.height) != 0) &&
Dave Houlton75967fc2017-03-06 17:21:16 -07003441 (pRegions[i].imageExtent.height + pRegions[i].imageOffset.y != mip_extent.height)) {
3442 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003443 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_016001a0, "IMAGE",
Dave Houlton75967fc2017-03-06 17:21:16 -07003444 "%s(): pRegion[%d] extent height (%d) must be a multiple of the compressed texture block height "
3445 "(%d), or when added to offset.y (%d) must equal the image subresource height (%d). %s.",
3446 function, i, pRegions[i].imageExtent.height, block_size.height, pRegions[i].imageOffset.y,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003447 mip_extent.height, validation_error_map[VALIDATION_ERROR_016001a0]);
Dave Houlton67e9b532017-03-02 17:00:10 -07003448 }
3449
3450 // imageExtent depth must be a multiple of block depth, or extent+offset depth must equal subresource depth
Dave Houlton1d2022c2017-03-29 11:43:58 -06003451 if ((SafeModulo(pRegions[i].imageExtent.depth, block_size.depth) != 0) &&
Dave Houlton75967fc2017-03-06 17:21:16 -07003452 (pRegions[i].imageExtent.depth + pRegions[i].imageOffset.z != mip_extent.depth)) {
3453 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003454 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_016001a2, "IMAGE",
Dave Houlton75967fc2017-03-06 17:21:16 -07003455 "%s(): pRegion[%d] extent width (%d) must be a multiple of the compressed texture block depth "
3456 "(%d), or when added to offset.z (%d) must equal the image subresource depth (%d). %s.",
3457 function, i, pRegions[i].imageExtent.depth, block_size.depth, pRegions[i].imageOffset.z,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003458 mip_extent.depth, validation_error_map[VALIDATION_ERROR_016001a2]);
Dave Houlton67e9b532017-03-02 17:00:10 -07003459 }
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003460 }
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003461 }
3462
3463 return skip;
3464}
3465
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003466static bool ValidateImageBounds(const debug_report_data *report_data, const IMAGE_STATE *image_state, const uint32_t regionCount,
3467 const VkBufferImageCopy *pRegions, const char *func_name, UNIQUE_VALIDATION_ERROR_CODE msg_code) {
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003468 bool skip = false;
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003469 const VkImageCreateInfo *image_info = &(image_state->createInfo);
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003470
3471 for (uint32_t i = 0; i < regionCount; i++) {
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003472 VkExtent3D extent = pRegions[i].imageExtent;
3473 VkOffset3D offset = pRegions[i].imageOffset;
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003474
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003475 if (IsExtentSizeZero(&extent)) // Warn on zero area subresource
3476 {
3477 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
3478 (uint64_t)0, __LINE__, IMAGE_ZERO_AREA_SUBREGION, "IMAGE",
3479 "%s: pRegion[%d] imageExtent of {%1d, %1d, %1d} has zero area", func_name, i, extent.width,
3480 extent.height, extent.depth);
3481 }
3482
3483 VkExtent3D image_extent = GetImageSubresourceExtent(image_state, &(pRegions[i].imageSubresource));
3484
3485 // 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 -06003486 if (FormatIsCompressed(image_info->format)) {
3487 auto block_extent = FormatCompressedTexelBlockExtent(image_info->format);
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003488 if (image_extent.width % block_extent.width) {
3489 image_extent.width += (block_extent.width - (image_extent.width % block_extent.width));
3490 }
3491 if (image_extent.height % block_extent.height) {
3492 image_extent.height += (block_extent.height - (image_extent.height % block_extent.height));
3493 }
3494 if (image_extent.depth % block_extent.depth) {
3495 image_extent.depth += (block_extent.depth - (image_extent.depth % block_extent.depth));
3496 }
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003497 }
3498
Dave Houltonfc1a4052017-04-27 14:32:45 -06003499 if (0 != ExceedsBounds(&offset, &extent, &image_extent)) {
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003500 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 -07003501 __LINE__, msg_code, "IMAGE", "%s: pRegion[%d] exceeds image bounds. %s.", func_name, i,
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003502 validation_error_map[msg_code]);
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003503 }
3504 }
3505
3506 return skip;
3507}
3508
Chris Forbese8ba09a2017-06-01 17:39:02 -07003509static inline bool ValidateBufferBounds(const debug_report_data *report_data, IMAGE_STATE *image_state, BUFFER_STATE *buff_state,
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003510 uint32_t regionCount, const VkBufferImageCopy *pRegions, const char *func_name,
3511 UNIQUE_VALIDATION_ERROR_CODE msg_code) {
3512 bool skip = false;
3513
3514 VkDeviceSize buffer_size = buff_state->createInfo.size;
3515
3516 for (uint32_t i = 0; i < regionCount; i++) {
3517 VkExtent3D copy_extent = pRegions[i].imageExtent;
3518
3519 VkDeviceSize buffer_width = (0 == pRegions[i].bufferRowLength ? copy_extent.width : pRegions[i].bufferRowLength);
3520 VkDeviceSize buffer_height = (0 == pRegions[i].bufferImageHeight ? copy_extent.height : pRegions[i].bufferImageHeight);
Dave Houlton1d2022c2017-03-29 11:43:58 -06003521 VkDeviceSize unit_size = FormatSize(image_state->createInfo.format); // size (bytes) of texel or block
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003522
Dave Houltonf3229d52017-02-21 15:59:08 -07003523 // Handle special buffer packing rules for specific depth/stencil formats
3524 if (pRegions[i].imageSubresource.aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) {
Dave Houlton1d2022c2017-03-29 11:43:58 -06003525 unit_size = FormatSize(VK_FORMAT_S8_UINT);
Dave Houltonf3229d52017-02-21 15:59:08 -07003526 } else if (pRegions[i].imageSubresource.aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) {
3527 switch (image_state->createInfo.format) {
3528 case VK_FORMAT_D16_UNORM_S8_UINT:
Dave Houlton1d2022c2017-03-29 11:43:58 -06003529 unit_size = FormatSize(VK_FORMAT_D16_UNORM);
Dave Houltonf3229d52017-02-21 15:59:08 -07003530 break;
3531 case VK_FORMAT_D32_SFLOAT_S8_UINT:
Dave Houlton1d2022c2017-03-29 11:43:58 -06003532 unit_size = FormatSize(VK_FORMAT_D32_SFLOAT);
Dave Houltonf3229d52017-02-21 15:59:08 -07003533 break;
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003534 case VK_FORMAT_X8_D24_UNORM_PACK32: // Fall through
Dave Houltonf3229d52017-02-21 15:59:08 -07003535 case VK_FORMAT_D24_UNORM_S8_UINT:
3536 unit_size = 4;
3537 break;
3538 default:
3539 break;
3540 }
3541 }
3542
Dave Houlton1d2022c2017-03-29 11:43:58 -06003543 if (FormatIsCompressed(image_state->createInfo.format)) {
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003544 // Switch to texel block units, rounding up for any partially-used blocks
Dave Houlton1d2022c2017-03-29 11:43:58 -06003545 auto block_dim = FormatCompressedTexelBlockExtent(image_state->createInfo.format);
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003546 buffer_width = (buffer_width + block_dim.width - 1) / block_dim.width;
3547 buffer_height = (buffer_height + block_dim.height - 1) / block_dim.height;
3548
3549 copy_extent.width = (copy_extent.width + block_dim.width - 1) / block_dim.width;
3550 copy_extent.height = (copy_extent.height + block_dim.height - 1) / block_dim.height;
3551 copy_extent.depth = (copy_extent.depth + block_dim.depth - 1) / block_dim.depth;
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003552 }
3553
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003554 // Either depth or layerCount may be greater than 1 (not both). This is the number of 'slices' to copy
3555 uint32_t z_copies = std::max(copy_extent.depth, pRegions[i].imageSubresource.layerCount);
3556 if (IsExtentSizeZero(&copy_extent) || (0 == z_copies)) {
Chris Forbese8ba09a2017-06-01 17:39:02 -07003557 // TODO: Issue warning here? Already warned in ValidateImageBounds()...
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003558 } else {
3559 // Calculate buffer offset of final copied byte, + 1.
3560 VkDeviceSize max_buffer_offset = (z_copies - 1) * buffer_height * buffer_width; // offset to slice
3561 max_buffer_offset += ((copy_extent.height - 1) * buffer_width) + copy_extent.width; // add row,col
3562 max_buffer_offset *= unit_size; // convert to bytes
3563 max_buffer_offset += pRegions[i].bufferOffset; // add initial offset (bytes)
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003564
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003565 if (buffer_size < max_buffer_offset) {
3566 skip |=
3567 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)0,
3568 __LINE__, msg_code, "IMAGE", "%s: pRegion[%d] exceeds buffer size of %" PRIu64 " bytes. %s.", func_name,
3569 i, buffer_size, validation_error_map[msg_code]);
3570 }
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003571 }
3572 }
3573
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003574 return skip;
3575}
3576
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003577bool PreCallValidateCmdCopyImageToBuffer(layer_data *device_data, VkImageLayout srcImageLayout, GLOBAL_CB_NODE *cb_node,
Mark Lobodzinski1fe9b002017-02-15 14:11:12 -07003578 IMAGE_STATE *src_image_state, BUFFER_STATE *dst_buffer_state, uint32_t regionCount,
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003579 const VkBufferImageCopy *pRegions, const char *func_name) {
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003580 const debug_report_data *report_data = core_validation::GetReportData(device_data);
3581 bool skip = ValidateBufferImageCopyData(report_data, regionCount, pRegions, src_image_state, "vkCmdCopyImageToBuffer");
3582
3583 // Validate command buffer state
3584 if (CB_RECORDING != cb_node->state) {
3585 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003586 HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_19202413, "DS",
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003587 "Cannot call vkCmdCopyImageToBuffer() on command buffer which is not in recording state. %s.",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003588 validation_error_map[VALIDATION_ERROR_19202413]);
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003589 } else {
3590 skip |= ValidateCmdSubpassState(device_data, cb_node, CMD_COPYIMAGETOBUFFER);
3591 }
3592
3593 // Command pool must support graphics, compute, or transfer operations
3594 auto pPool = GetCommandPoolNode(device_data, cb_node->createInfo.commandPool);
3595
3596 VkQueueFlags queue_flags = GetPhysDevProperties(device_data)->queue_family_properties[pPool->queueFamilyIndex].queueFlags;
3597 if (0 == (queue_flags & (VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT | VK_QUEUE_TRANSFER_BIT))) {
3598 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003599 HandleToUint64(cb_node->createInfo.commandPool), __LINE__, VALIDATION_ERROR_19202415, "DS",
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003600 "Cannot call vkCmdCopyImageToBuffer() on a command buffer allocated from a pool without graphics, compute, "
3601 "or transfer capabilities. %s.",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003602 validation_error_map[VALIDATION_ERROR_19202415]);
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003603 }
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003604 skip |= ValidateImageBounds(report_data, src_image_state, regionCount, pRegions, "vkCmdCopyBufferToImage()",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003605 VALIDATION_ERROR_1920016c);
Chris Forbese8ba09a2017-06-01 17:39:02 -07003606 skip |= ValidateBufferBounds(report_data, src_image_state, dst_buffer_state, regionCount, pRegions, "vkCmdCopyImageToBuffer()",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003607 VALIDATION_ERROR_1920016e);
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003608
3609 skip |= ValidateImageSampleCount(device_data, src_image_state, VK_SAMPLE_COUNT_1_BIT, "vkCmdCopyImageToBuffer(): srcImage",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003610 VALIDATION_ERROR_19200178);
3611 skip |= ValidateMemoryIsBoundToImage(device_data, src_image_state, "vkCmdCopyImageToBuffer()", VALIDATION_ERROR_19200176);
3612 skip |= ValidateMemoryIsBoundToBuffer(device_data, dst_buffer_state, "vkCmdCopyImageToBuffer()", VALIDATION_ERROR_19200180);
Mark Lobodzinski033c90b2017-02-15 13:58:23 -07003613
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003614 // Validate that SRC image & DST buffer have correct usage flags set
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003615 skip |= ValidateImageUsageFlags(device_data, src_image_state, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, true, VALIDATION_ERROR_19200174,
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003616 "vkCmdCopyImageToBuffer()", "VK_IMAGE_USAGE_TRANSFER_SRC_BIT");
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003617 skip |= ValidateBufferUsageFlags(device_data, dst_buffer_state, VK_BUFFER_USAGE_TRANSFER_DST_BIT, true,
3618 VALIDATION_ERROR_1920017e, "vkCmdCopyImageToBuffer()", "VK_BUFFER_USAGE_TRANSFER_DST_BIT");
3619 skip |= insideRenderPass(device_data, cb_node, "vkCmdCopyImageToBuffer()", VALIDATION_ERROR_19200017);
Tobin Ehlisc8266452017-04-07 12:20:30 -06003620 bool hit_error = false;
Mark Lobodzinski033c90b2017-02-15 13:58:23 -07003621 for (uint32_t i = 0; i < regionCount; ++i) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003622 skip |= VerifyImageLayout(device_data, cb_node, src_image_state, pRegions[i].imageSubresource, srcImageLayout,
3623 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, "vkCmdCopyImageToBuffer()", VALIDATION_ERROR_1920017c,
3624 &hit_error);
Mark Lobodzinski033c90b2017-02-15 13:58:23 -07003625 skip |= ValidateCopyBufferImageTransferGranularityRequirements(device_data, cb_node, src_image_state, &pRegions[i], i,
Tobin Ehlis2d85ec62017-03-14 15:38:48 -06003626 "vkCmdCopyImageToBuffer()");
Mark Lobodzinski033c90b2017-02-15 13:58:23 -07003627 }
3628 return skip;
3629}
3630
3631void PreCallRecordCmdCopyImageToBuffer(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state,
Tobin Ehlise35b66a2017-03-15 12:18:31 -06003632 BUFFER_STATE *dst_buffer_state, uint32_t region_count, const VkBufferImageCopy *regions,
3633 VkImageLayout src_image_layout) {
3634 // Make sure that all image slices are updated to correct layout
3635 for (uint32_t i = 0; i < region_count; ++i) {
3636 SetImageLayout(device_data, cb_node, src_image_state, regions[i].imageSubresource, src_image_layout);
3637 }
Mark Lobodzinski033c90b2017-02-15 13:58:23 -07003638 // Update bindings between buffer/image and cmd buffer
3639 AddCommandBufferBindingImage(device_data, cb_node, src_image_state);
Mark Lobodzinski1fe9b002017-02-15 14:11:12 -07003640 AddCommandBufferBindingBuffer(device_data, cb_node, dst_buffer_state);
Mark Lobodzinski033c90b2017-02-15 13:58:23 -07003641
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003642 std::function<bool()> function = [=]() {
3643 return ValidateImageMemoryIsValid(device_data, src_image_state, "vkCmdCopyImageToBuffer()");
3644 };
3645 cb_node->validate_functions.push_back(function);
3646 function = [=]() {
Mark Lobodzinski1fe9b002017-02-15 14:11:12 -07003647 SetBufferMemoryValid(device_data, dst_buffer_state, true);
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003648 return false;
3649 };
3650 cb_node->validate_functions.push_back(function);
3651
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003652}
3653
3654bool PreCallValidateCmdCopyBufferToImage(layer_data *device_data, VkImageLayout dstImageLayout, GLOBAL_CB_NODE *cb_node,
Mark Lobodzinski1fe9b002017-02-15 14:11:12 -07003655 BUFFER_STATE *src_buffer_state, IMAGE_STATE *dst_image_state, uint32_t regionCount,
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003656 const VkBufferImageCopy *pRegions, const char *func_name) {
3657 const debug_report_data *report_data = core_validation::GetReportData(device_data);
3658 bool skip = ValidateBufferImageCopyData(report_data, regionCount, pRegions, dst_image_state, "vkCmdCopyBufferToImage");
3659
3660 // Validate command buffer state
3661 if (CB_RECORDING != cb_node->state) {
3662 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003663 HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_18e02413, "DS",
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003664 "Cannot call vkCmdCopyBufferToImage() on command buffer which is not in recording state. %s.",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003665 validation_error_map[VALIDATION_ERROR_18e02413]);
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003666 } else {
3667 skip |= ValidateCmdSubpassState(device_data, cb_node, CMD_COPYBUFFERTOIMAGE);
3668 }
3669
3670 // Command pool must support graphics, compute, or transfer operations
3671 auto pPool = GetCommandPoolNode(device_data, cb_node->createInfo.commandPool);
3672 VkQueueFlags queue_flags = GetPhysDevProperties(device_data)->queue_family_properties[pPool->queueFamilyIndex].queueFlags;
3673 if (0 == (queue_flags & (VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT | VK_QUEUE_TRANSFER_BIT))) {
3674 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003675 HandleToUint64(cb_node->createInfo.commandPool), __LINE__, VALIDATION_ERROR_18e02415, "DS",
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003676 "Cannot call vkCmdCopyBufferToImage() on a command buffer allocated from a pool without graphics, compute, "
3677 "or transfer capabilities. %s.",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003678 validation_error_map[VALIDATION_ERROR_18e02415]);
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003679 }
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003680 skip |= ValidateImageBounds(report_data, dst_image_state, regionCount, pRegions, "vkCmdCopyBufferToImage()",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003681 VALIDATION_ERROR_18e00158);
Chris Forbese8ba09a2017-06-01 17:39:02 -07003682 skip |= ValidateBufferBounds(report_data, dst_image_state, src_buffer_state, regionCount, pRegions, "vkCmdCopyBufferToImage()",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003683 VALIDATION_ERROR_18e00156);
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003684 skip |= ValidateImageSampleCount(device_data, dst_image_state, VK_SAMPLE_COUNT_1_BIT, "vkCmdCopyBufferToImage(): dstImage",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003685 VALIDATION_ERROR_18e00166);
3686 skip |= ValidateMemoryIsBoundToBuffer(device_data, src_buffer_state, "vkCmdCopyBufferToImage()", VALIDATION_ERROR_18e00160);
3687 skip |= ValidateMemoryIsBoundToImage(device_data, dst_image_state, "vkCmdCopyBufferToImage()", VALIDATION_ERROR_18e00164);
3688 skip |= ValidateBufferUsageFlags(device_data, src_buffer_state, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, true,
3689 VALIDATION_ERROR_18e0015c, "vkCmdCopyBufferToImage()", "VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
3690 skip |= ValidateImageUsageFlags(device_data, dst_image_state, VK_IMAGE_USAGE_TRANSFER_DST_BIT, true, VALIDATION_ERROR_18e00162,
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003691 "vkCmdCopyBufferToImage()", "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003692 skip |= insideRenderPass(device_data, cb_node, "vkCmdCopyBufferToImage()", VALIDATION_ERROR_18e00017);
Tobin Ehlisc8266452017-04-07 12:20:30 -06003693 bool hit_error = false;
Mark Lobodzinski033c90b2017-02-15 13:58:23 -07003694 for (uint32_t i = 0; i < regionCount; ++i) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003695 skip |= VerifyImageLayout(device_data, cb_node, dst_image_state, pRegions[i].imageSubresource, dstImageLayout,
3696 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, "vkCmdCopyBufferToImage()", VALIDATION_ERROR_18e0016a,
3697 &hit_error);
Mark Lobodzinski033c90b2017-02-15 13:58:23 -07003698 skip |= ValidateCopyBufferImageTransferGranularityRequirements(device_data, cb_node, dst_image_state, &pRegions[i], i,
3699 "vkCmdCopyBufferToImage()");
3700 }
3701 return skip;
3702}
3703
Mark Lobodzinski1fe9b002017-02-15 14:11:12 -07003704void PreCallRecordCmdCopyBufferToImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, BUFFER_STATE *src_buffer_state,
Tobin Ehlise35b66a2017-03-15 12:18:31 -06003705 IMAGE_STATE *dst_image_state, uint32_t region_count, const VkBufferImageCopy *regions,
3706 VkImageLayout dst_image_layout) {
3707 // Make sure that all image slices are updated to correct layout
3708 for (uint32_t i = 0; i < region_count; ++i) {
3709 SetImageLayout(device_data, cb_node, dst_image_state, regions[i].imageSubresource, dst_image_layout);
3710 }
Mark Lobodzinski1fe9b002017-02-15 14:11:12 -07003711 AddCommandBufferBindingBuffer(device_data, cb_node, src_buffer_state);
Mark Lobodzinski033c90b2017-02-15 13:58:23 -07003712 AddCommandBufferBindingImage(device_data, cb_node, dst_image_state);
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003713 std::function<bool()> function = [=]() {
3714 SetImageMemoryValid(device_data, dst_image_state, true);
3715 return false;
3716 };
3717 cb_node->validate_functions.push_back(function);
Mark Lobodzinski1fe9b002017-02-15 14:11:12 -07003718 function = [=]() { return ValidateBufferMemoryIsValid(device_data, src_buffer_state, "vkCmdCopyBufferToImage()"); };
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003719 cb_node->validate_functions.push_back(function);
3720
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003721}
Mike Weiblen672b58b2017-02-21 14:32:53 -07003722
3723bool PreCallValidateGetImageSubresourceLayout(layer_data *device_data, VkImage image, const VkImageSubresource *pSubresource) {
3724 const auto report_data = core_validation::GetReportData(device_data);
3725 bool skip = false;
3726 const VkImageAspectFlags sub_aspect = pSubresource->aspectMask;
3727
3728 // VU 00733: The aspectMask member of pSubresource must only have a single bit set
3729 const int num_bits = sizeof(sub_aspect) * CHAR_BIT;
3730 std::bitset<num_bits> aspect_mask_bits(sub_aspect);
3731 if (aspect_mask_bits.count() != 1) {
Petr Krausbc7f5442017-05-14 23:43:38 +02003732 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, HandleToUint64(image),
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003733 __LINE__, VALIDATION_ERROR_2a6007ca, "IMAGE",
Mike Weiblen672b58b2017-02-21 14:32:53 -07003734 "vkGetImageSubresourceLayout(): VkImageSubresource.aspectMask must have exactly 1 bit set. %s",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003735 validation_error_map[VALIDATION_ERROR_2a6007ca]);
Mike Weiblen672b58b2017-02-21 14:32:53 -07003736 }
3737
3738 IMAGE_STATE *image_entry = GetImageState(device_data, image);
3739 if (!image_entry) {
3740 return skip;
3741 }
3742
3743 // VU 00732: image must have been created with tiling equal to VK_IMAGE_TILING_LINEAR
3744 if (image_entry->createInfo.tiling != VK_IMAGE_TILING_LINEAR) {
Petr Krausbc7f5442017-05-14 23:43:38 +02003745 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, HandleToUint64(image),
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003746 __LINE__, VALIDATION_ERROR_2a6007c8, "IMAGE",
Mike Weiblen672b58b2017-02-21 14:32:53 -07003747 "vkGetImageSubresourceLayout(): Image must have tiling of VK_IMAGE_TILING_LINEAR. %s",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003748 validation_error_map[VALIDATION_ERROR_2a6007c8]);
Mike Weiblen672b58b2017-02-21 14:32:53 -07003749 }
3750
3751 // VU 00739: mipLevel must be less than the mipLevels specified in VkImageCreateInfo when the image was created
3752 if (pSubresource->mipLevel >= image_entry->createInfo.mipLevels) {
Petr Krausbc7f5442017-05-14 23:43:38 +02003753 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, HandleToUint64(image),
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003754 __LINE__, VALIDATION_ERROR_0a4007cc, "IMAGE",
Mike Weiblen672b58b2017-02-21 14:32:53 -07003755 "vkGetImageSubresourceLayout(): pSubresource.mipLevel (%d) must be less than %d. %s",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003756 pSubresource->mipLevel, image_entry->createInfo.mipLevels, validation_error_map[VALIDATION_ERROR_0a4007cc]);
Mike Weiblen672b58b2017-02-21 14:32:53 -07003757 }
3758
3759 // VU 00740: arrayLayer must be less than the arrayLayers specified in VkImageCreateInfo when the image was created
3760 if (pSubresource->arrayLayer >= image_entry->createInfo.arrayLayers) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003761 skip |=
3762 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, HandleToUint64(image),
3763 __LINE__, VALIDATION_ERROR_0a4007ce, "IMAGE",
3764 "vkGetImageSubresourceLayout(): pSubresource.arrayLayer (%d) must be less than %d. %s",
3765 pSubresource->arrayLayer, image_entry->createInfo.arrayLayers, validation_error_map[VALIDATION_ERROR_0a4007ce]);
Mike Weiblen672b58b2017-02-21 14:32:53 -07003766 }
3767
3768 // VU 00741: subresource's aspect must be compatible with image's format.
3769 const VkFormat img_format = image_entry->createInfo.format;
Dave Houlton1d2022c2017-03-29 11:43:58 -06003770 if (FormatIsColor(img_format)) {
Mike Weiblen672b58b2017-02-21 14:32:53 -07003771 if (sub_aspect != VK_IMAGE_ASPECT_COLOR_BIT) {
3772 skip |= log_msg(
Petr Krausbc7f5442017-05-14 23:43:38 +02003773 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, HandleToUint64(image), __LINE__,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003774 VALIDATION_ERROR_0a400c01, "IMAGE",
Mike Weiblen672b58b2017-02-21 14:32:53 -07003775 "vkGetImageSubresourceLayout(): For color formats, VkImageSubresource.aspectMask must be VK_IMAGE_ASPECT_COLOR. %s",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003776 validation_error_map[VALIDATION_ERROR_0a400c01]);
Mike Weiblen672b58b2017-02-21 14:32:53 -07003777 }
Dave Houlton1d2022c2017-03-29 11:43:58 -06003778 } else if (FormatIsDepthOrStencil(img_format)) {
Mike Weiblen672b58b2017-02-21 14:32:53 -07003779 if ((sub_aspect != VK_IMAGE_ASPECT_DEPTH_BIT) && (sub_aspect != VK_IMAGE_ASPECT_STENCIL_BIT)) {
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06003780 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003781 HandleToUint64(image), __LINE__, VALIDATION_ERROR_0a400c01, "IMAGE",
Mike Weiblen672b58b2017-02-21 14:32:53 -07003782 "vkGetImageSubresourceLayout(): For depth/stencil formats, VkImageSubresource.aspectMask must be "
3783 "either VK_IMAGE_ASPECT_DEPTH_BIT or VK_IMAGE_ASPECT_STENCIL_BIT. %s",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003784 validation_error_map[VALIDATION_ERROR_0a400c01]);
Mike Weiblen672b58b2017-02-21 14:32:53 -07003785 }
3786 }
3787 return skip;
3788}